Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

powerpc/powernv: Introduce pnv_pci_get_slot_id()

This introduces pnv_pci_get_slot_id() to get the hotpluggable PCI
slot ID from the corresponding device node. It will be used by
hotplug driver.

Requested-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>

authored by

Gavin Shan and committed by
Michael Ellerman
7e19bf32 9c0e1ecb

+40
+2
arch/powerpc/include/asm/pnv-pci.h
··· 17 17 #define PCI_SLOT_ID(phb_id, bdfn) \ 18 18 (PCI_SLOT_ID_PREFIX | ((uint64_t)(bdfn) << 16) | (phb_id)) 19 19 20 + extern int pnv_pci_get_slot_id(struct device_node *np, uint64_t *id); 21 + 20 22 int pnv_phb_to_cxl_mode(struct pci_dev *dev, uint64_t mode); 21 23 int pnv_cxl_ioda_msi_setup(struct pci_dev *dev, unsigned int hwirq, 22 24 unsigned int virq);
+38
arch/powerpc/platforms/powernv/pci.c
··· 26 26 #include <asm/machdep.h> 27 27 #include <asm/msi_bitmap.h> 28 28 #include <asm/ppc-pci.h> 29 + #include <asm/pnv-pci.h> 29 30 #include <asm/opal.h> 30 31 #include <asm/iommu.h> 31 32 #include <asm/tce.h> ··· 36 35 37 36 #include "powernv.h" 38 37 #include "pci.h" 38 + 39 + int pnv_pci_get_slot_id(struct device_node *np, uint64_t *id) 40 + { 41 + struct device_node *parent = np; 42 + u32 bdfn; 43 + u64 phbid; 44 + int ret; 45 + 46 + ret = of_property_read_u32(np, "reg", &bdfn); 47 + if (ret) 48 + return -ENXIO; 49 + 50 + bdfn = ((bdfn & 0x00ffff00) >> 8); 51 + while ((parent = of_get_parent(parent))) { 52 + if (!PCI_DN(parent)) { 53 + of_node_put(parent); 54 + break; 55 + } 56 + 57 + if (!of_device_is_compatible(parent, "ibm,ioda2-phb")) { 58 + of_node_put(parent); 59 + continue; 60 + } 61 + 62 + ret = of_property_read_u64(parent, "ibm,opal-phbid", &phbid); 63 + if (ret) { 64 + of_node_put(parent); 65 + return -ENXIO; 66 + } 67 + 68 + *id = PCI_SLOT_ID(phbid, bdfn); 69 + return 0; 70 + } 71 + 72 + return -ENODEV; 73 + } 74 + EXPORT_SYMBOL_GPL(pnv_pci_get_slot_id); 39 75 40 76 #ifdef CONFIG_PCI_MSI 41 77 int pnv_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type)