From eb0acfdde604930688c47fe1ba99bec2bd84b7ad Mon Sep 17 00:00:00 2001 From: "Michael S. Tsirkin" Date: Mon, 14 Oct 2013 18:01:07 +0300 Subject: pci: add pci_for_each_bus_depth_first Useful for ACPI hotplug. Signed-off-by: Michael S. Tsirkin --- hw/pci/pci.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'hw/pci') diff --git a/hw/pci/pci.c b/hw/pci/pci.c index aa2a395499..2aca8a4d7e 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -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); -- cgit v1.2.1