Add a function to just walk on the local bus.
Signed-off-by: Wei Yang <[email protected]>
---
drivers/pci/bus.c | 26 +++++++++++++++++++++-----
include/linux/pci.h | 2 ++
2 files changed, 23 insertions(+), 5 deletions(-)
diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c
index dd7cdbe..ccf4290 100644
--- a/drivers/pci/bus.c
+++ b/drivers/pci/bus.c
@@ -338,17 +338,19 @@ EXPORT_SYMBOL(pci_bus_add_devices);
* @top bus whose devices should be walked
* @cb callback to be called for each device found
* @userdata arbitrary pointer to be passed to callback.
+ * @local whether it just walk on the local bus
*
* Walk the given bus, including any bridged devices
- * on buses under this bus. Call the provided callback
- * on each device found.
+ * on buses under this bus if "local" is false.
+ * Call the provided callback on each device found.
*
* We check the return of @cb each time. If it returns anything
* other than 0, we break out.
*
*/
-void pci_walk_bus(struct pci_bus *top, int (*cb)(struct pci_dev *, void *),
- void *userdata)
+static void __pci_walk_bus(struct pci_bus *top,
+ int (*cb)(struct pci_dev *, void *),
+ void *userdata, bool local)
{
struct pci_dev *dev;
struct pci_bus *bus;
@@ -368,7 +370,7 @@ void pci_walk_bus(struct pci_bus *top, int (*cb)(struct
pci_dev *, void *),
continue;
}
dev = list_entry(next, struct pci_dev, bus_list);
- if (dev->subordinate) {
+ if (dev->subordinate && !local) {
/* this is a pci-pci bridge, do its devices next */
next = dev->subordinate->devices.next;
bus = dev->subordinate;
@@ -381,8 +383,22 @@ void pci_walk_bus(struct pci_bus *top, int (*cb)(struct
pci_dev *, void *),
}
up_read(&pci_bus_sem);
}
+
+void pci_walk_bus(struct pci_bus *top, int (*cb)(struct pci_dev *, void *),
+ void *userdata)
+{
+ __pci_walk_bus(top, cb, userdata, false);
+}
EXPORT_SYMBOL_GPL(pci_walk_bus);
+void pci_walk_bus_local(struct pci_bus *top,
+ int (*cb)(struct pci_dev *, void *),
+ void *userdata)
+{
+ __pci_walk_bus(top, cb, userdata, true);
+}
+EXPORT_SYMBOL_GPL(pci_walk_bus_local);
+
struct pci_bus *pci_bus_get(struct pci_bus *bus)
{
if (bus)
diff --git a/include/linux/pci.h b/include/linux/pci.h
index b67e4df..e43df8c 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -1224,6 +1224,8 @@ int pci_scan_bridge(struct pci_bus *bus, struct pci_dev
*dev, int max,
void pci_walk_bus(struct pci_bus *top, int (*cb)(struct pci_dev *, void *),
void *userdata);
+void pci_walk_bus_local(struct pci_bus *top,
+ int (*cb)(struct pci_dev *, void *), void *userdata);
int pci_cfg_space_size(struct pci_dev *dev);
unsigned char pci_bus_max_busnr(struct pci_bus *bus);
void pci_setup_bridge(struct pci_bus *bus);
--
2.5.0
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu