]> git.proxmox.com Git - mirror_qemu.git/commitdiff
pci: add pci_for_each_bus_depth_first
authorMichael S. Tsirkin <mst@redhat.com>
Mon, 14 Oct 2013 15:01:07 +0000 (18:01 +0300)
committerMichael S. Tsirkin <mst@redhat.com>
Sun, 26 Jan 2014 11:06:49 +0000 (13:06 +0200)
Useful for ACPI hotplug.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
hw/pci/pci.c
include/hw/pci/pci.h

index aa2a395499aac52ef6104d5f6d52b608e0d422e1..2aca8a4d7e91872ffbb448b0a45fdeb8162f8b93 100644 (file)
@@ -1704,6 +1704,34 @@ static PCIBus *pci_find_bus_nr(PCIBus *bus, int bus_num)
     return NULL;
 }
 
+void pci_for_each_bus_depth_first(PCIBus *bus,
+                                  void *(*begin)(PCIBus *bus, void *parent_state),
+                                  void (*end)(PCIBus *bus, void *state),
+                                  void *parent_state)
+{
+    PCIBus *sec;
+    void *state;
+
+    if (!bus) {
+        return;
+    }
+
+    if (begin) {
+        state = begin(bus, parent_state);
+    } else {
+        state = parent_state;
+    }
+
+    QLIST_FOREACH(sec, &bus->child, sibling) {
+        pci_for_each_bus_depth_first(sec, begin, end, state);
+    }
+
+    if (end) {
+        end(bus, state);
+    }
+}
+
+
 PCIDevice *pci_find_device(PCIBus *bus, int bus_num, uint8_t devfn)
 {
     bus = pci_find_bus_nr(bus, bus_num);
index 754b82de81b846966259e42331c46d4b697a28f5..52523467b61dda9d835f10ce059e1b8f6516360b 100644 (file)
@@ -387,6 +387,20 @@ 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_depth_first(PCIBus *bus,
+                                  void *(*begin)(PCIBus *bus, void *parent_state),
+                                  void (*end)(PCIBus *bus, void *state),
+                                  void *parent_state);
+
+/* Use this wrapper when specific scan order is not required. */
+static inline
+void pci_for_each_bus(PCIBus *bus,
+                      void (*fn)(PCIBus *bus, void *opaque),
+                      void *opaque)
+{
+    pci_for_each_bus_depth_first(bus, NULL, fn, opaque);
+}
+
 PCIBus *pci_find_primary_bus(void);
 PCIBus *pci_device_root_bus(const PCIDevice *d);
 const char *pci_root_bus_path(PCIDevice *dev);