diff mbox

[RFC] pci: add pci_for_each_bus

Message ID 20130610162656.GA29685@redhat.com
State New
Headers show

Commit Message

Michael S. Tsirkin June 10, 2013, 4:26 p.m. UTC
This will be useful for bridge ACPI hotplug.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/pci/pci.c         | 17 +++++++++++++++++
 include/hw/pci/pci.h |  4 ++++
 2 files changed, 21 insertions(+)
diff mbox

Patch

diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index d5257ed..130b5ad 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -1677,6 +1677,23 @@  static PCIBus *pci_find_bus_nr(PCIBus *bus, int bus_num)
     return NULL;
 }
 
+void pci_for_each_bus(PCIBus *bus, 
+                      void (*fn)(PCIBus *bus, void *opaque),
+                      void *opaque)
+{
+    PCIBus *sec;
+
+    if (!bus) {
+        return;
+    }
+
+    fn(bus, opaque);
+
+    QLIST_FOREACH(sec, &bus->child, sibling) {
+        pci_for_each_bus(sec, fn, opaque);
+    }
+}
+
 PCIDevice *pci_find_device(PCIBus *bus, int bus_num, uint8_t devfn)
 {
     bus = pci_find_bus_nr(bus, bus_num);
diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
index 8d075ab..d6dc02f 100644
--- a/include/hw/pci/pci.h
+++ b/include/hw/pci/pci.h
@@ -390,6 +390,10 @@  int pci_bus_num(PCIBus *s);
 void pci_for_each_device(PCIBus *bus, int bus_num,
                          void (*fn)(PCIBus *bus, PCIDevice *d, void *opaque),
                          void *opaque);
+
+void pci_for_each_bus(PCIBus *bus, 
+                      void (*fn)(PCIBus *bus, void *opaque),
+                      void *opaque);
 PCIBus *pci_find_root_bus(int domain);
 int pci_find_domain(const PCIBus *bus);
 PCIDevice *pci_find_device(PCIBus *bus, int bus_num, uint8_t devfn);