diff mbox

[v10,05/17] core/pci: Extend pci_walk_dev() for PCI slot

Message ID 1462251882-12762-6-git-send-email-gwshan@linux.vnet.ibm.com
State Changes Requested
Headers show

Commit Message

Gavin Shan May 3, 2016, 5:04 a.m. UTC
Currently, pci_walk_dev() iterates all PCI devices behind the
specified PHB. This extends the function to allow iteration
on PCI devices behind the specified PCI slot so that it can
be used by PCI hogplug logic in the subsequent patches.

Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
---
 core/pci.c    | 12 ++++++++----
 hw/npu.c      |  4 ++--
 include/pci.h |  1 +
 3 files changed, 11 insertions(+), 6 deletions(-)

Comments

Russell Currey May 6, 2016, 1:56 a.m. UTC | #1
On Tue, 2016-05-03 at 15:04 +1000, Gavin Shan wrote:
> Currently, pci_walk_dev() iterates all PCI devices behind the
> specified PHB. This extends the function to allow iteration
> on PCI devices behind the specified PCI slot so that it can
> be used by PCI hogplug logic in the subsequent patches.
s/hogplug/hotplug

> 
> Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>

Reviewed-by: Russell Currey <ruscur@russell.cc>
Gavin Shan May 13, 2016, 12:12 a.m. UTC | #2
On Fri, May 06, 2016 at 11:56:46AM +1000, Russell Currey wrote:
>On Tue, 2016-05-03 at 15:04 +1000, Gavin Shan wrote:
>> Currently, pci_walk_dev() iterates all PCI devices behind the
>> specified PHB. This extends the function to allow iteration
>> on PCI devices behind the specified PCI slot so that it can
>> be used by PCI hogplug logic in the subsequent patches.
>s/hogplug/hotplug
>

Thanks for review, Russell. It will be fixed in next revision.

Thanks,
Gavin

>> 
>> Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
>
>Reviewed-by: Russell Currey <ruscur@russell.cc>
>
diff mbox

Patch

diff --git a/core/pci.c b/core/pci.c
index 9b238d0..94e6995 100644
--- a/core/pci.c
+++ b/core/pci.c
@@ -788,9 +788,9 @@  static void pci_scan_phb(void *data)
 	pci_scan(phb, 0, 0xff, &phb->devices, NULL, has_link);
 
 	/* Configure MPS (Max Payload Size) for PCIe domain */
-	pci_walk_dev(phb, pci_get_mps, &mps);
+	pci_walk_dev(phb, NULL, pci_get_mps, &mps);
 	phb->mps = mps;
-	pci_walk_dev(phb, pci_configure_mps, NULL);
+	pci_walk_dev(phb, NULL, pci_configure_mps, NULL);
 }
 
 int64_t pci_register_phb(struct phb *phb, int opal_id)
@@ -1572,11 +1572,15 @@  static struct pci_device *__pci_walk_dev(struct phb *phb,
 }
 
 struct pci_device *pci_walk_dev(struct phb *phb,
+				struct pci_device *pd,
 				int (*cb)(struct phb *,
 					  struct pci_device *,
 					  void *),
 				void *userdata)
 {
+	if (pd)
+		return __pci_walk_dev(phb, &pd->children, cb, userdata);
+
 	return __pci_walk_dev(phb, &phb->devices, cb, userdata);
 }
 
@@ -1596,7 +1600,7 @@  static int __pci_find_dev(struct phb *phb,
 
 struct pci_device *pci_find_dev(struct phb *phb, uint16_t bdfn)
 {
-	return pci_walk_dev(phb, __pci_find_dev, &bdfn);
+	return pci_walk_dev(phb, NULL, __pci_find_dev, &bdfn);
 }
 
 static int __pci_restore_bridge_buses(struct phb *phb,
@@ -1617,7 +1621,7 @@  static int __pci_restore_bridge_buses(struct phb *phb,
 
 void pci_restore_bridge_buses(struct phb *phb)
 {
-	pci_walk_dev(phb, __pci_restore_bridge_buses, NULL);
+	pci_walk_dev(phb, NULL, __pci_restore_bridge_buses, NULL);
 }
 
 struct pci_cfg_reg_filter *pci_find_cfg_reg_filter(struct pci_device *pd,
diff --git a/hw/npu.c b/hw/npu.c
index 3e419c4..0889144 100644
--- a/hw/npu.c
+++ b/hw/npu.c
@@ -541,7 +541,7 @@  static void npu_dev_bind_pci_dev(struct npu_dev *dev)
 		if (!phb)
 			continue;
 
-		dev->pd = pci_walk_dev(phb, __npu_dev_bind_pci_dev, dev);
+		dev->pd = pci_walk_dev(phb, NULL, __npu_dev_bind_pci_dev, dev);
 		if (dev->pd) {
 			dev->phb = phb;
 			/* Found the device, set the bit in config space */
@@ -618,7 +618,7 @@  static int npu_dn_fixup(struct phb *phb,
 
 static void npu_phb_final_fixup(struct phb *phb)
 {
-	pci_walk_dev(phb, npu_dn_fixup, NULL);
+	pci_walk_dev(phb, NULL, npu_dn_fixup, NULL);
 }
 
 static void npu_ioda_init(struct npu *p)
diff --git a/include/pci.h b/include/pci.h
index aec4808..1f3237e 100644
--- a/include/pci.h
+++ b/include/pci.h
@@ -523,6 +523,7 @@  extern int64_t pci_find_ecap(struct phb *phb, uint16_t bdfn, uint16_t cap,
 			     uint8_t *version);
 extern void pci_device_init(struct phb *phb, struct pci_device *pd);
 extern struct pci_device *pci_walk_dev(struct phb *phb,
+				       struct pci_device *pd,
 				       int (*cb)(struct phb *,
 						 struct pci_device *,
 						 void *),