Skip to content

Commit 7e19bf3

Browse files
Gavin Shanmpe
authored andcommitted
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>
1 parent 9c0e1ec commit 7e19bf3

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

‎arch/powerpc/include/asm/pnv-pci.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#define PCI_SLOT_ID(phb_id, bdfn) \
1818
(PCI_SLOT_ID_PREFIX | ((uint64_t)(bdfn) << 16) | (phb_id))
1919

20+
extern int pnv_pci_get_slot_id(struct device_node *np, uint64_t *id);
21+
2022
int pnv_phb_to_cxl_mode(struct pci_dev *dev, uint64_t mode);
2123
int pnv_cxl_ioda_msi_setup(struct pci_dev *dev, unsigned int hwirq,
2224
unsigned int virq);

‎arch/powerpc/platforms/powernv/pci.c‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <asm/machdep.h>
2727
#include <asm/msi_bitmap.h>
2828
#include <asm/ppc-pci.h>
29+
#include <asm/pnv-pci.h>
2930
#include <asm/opal.h>
3031
#include <asm/iommu.h>
3132
#include <asm/tce.h>
@@ -36,6 +37,43 @@
3637
#include "powernv.h"
3738
#include "pci.h"
3839

40+
int pnv_pci_get_slot_id(struct device_node *np, uint64_t *id)
41+
{
42+
struct device_node *parent = np;
43+
u32 bdfn;
44+
u64 phbid;
45+
int ret;
46+
47+
ret = of_property_read_u32(np, "reg", &bdfn);
48+
if (ret)
49+
return -ENXIO;
50+
51+
bdfn = ((bdfn & 0x00ffff00) >> 8);
52+
while ((parent = of_get_parent(parent))) {
53+
if (!PCI_DN(parent)) {
54+
of_node_put(parent);
55+
break;
56+
}
57+
58+
if (!of_device_is_compatible(parent, "ibm,ioda2-phb")) {
59+
of_node_put(parent);
60+
continue;
61+
}
62+
63+
ret = of_property_read_u64(parent, "ibm,opal-phbid", &phbid);
64+
if (ret) {
65+
of_node_put(parent);
66+
return -ENXIO;
67+
}
68+
69+
*id = PCI_SLOT_ID(phbid, bdfn);
70+
return 0;
71+
}
72+
73+
return -ENODEV;
74+
}
75+
EXPORT_SYMBOL_GPL(pnv_pci_get_slot_id);
76+
3977
#ifdef CONFIG_PCI_MSI
4078
int pnv_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type)
4179
{

0 commit comments

Comments
 (0)