[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 40/43] pci: add pci_for_each_bus_depth_first
From: |
Michael S. Tsirkin |
Subject: |
[Qemu-devel] [PULL 40/43] pci: add pci_for_each_bus_depth_first |
Date: |
Mon, 14 Oct 2013 18:01:07 +0300 |
Useful for ACPI hotplug.
Signed-off-by: Michael S. Tsirkin <address@hidden>
---
include/hw/pci/pci.h | 14 ++++++++++++++
hw/pci/pci.c | 28 ++++++++++++++++++++++++++++
2 files changed, 42 insertions(+)
diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
index 37ffa53..3755b02 100644
--- a/include/hw/pci/pci.h
+++ b/include/hw/pci/pci.h
@@ -388,6 +388,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);
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index a98c8a0..d5c3a91 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -1724,6 +1724,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);
--
MST
- [Qemu-devel] [PULL 30/43] acpi/piix: add macros for acpi property names, (continued)
- [Qemu-devel] [PULL 30/43] acpi/piix: add macros for acpi property names, Michael S. Tsirkin, 2013/10/14
- [Qemu-devel] [PULL 31/43] piix: APIs for pc guest info, Michael S. Tsirkin, 2013/10/14
- [Qemu-devel] [PULL 32/43] ich9: APIs for pc guest info, Michael S. Tsirkin, 2013/10/14
- [Qemu-devel] [PULL 33/43] pvpanic: add API to access io port, Michael S. Tsirkin, 2013/10/14
- [Qemu-devel] [PULL 34/43] hpet: add API to find it, Michael S. Tsirkin, 2013/10/14
- [Qemu-devel] [PULL 35/43] acpi: add interface to access user-installed tables, Michael S. Tsirkin, 2013/10/14
- [Qemu-devel] [PULL 36/43] pc: use new api to add builtin tables, Michael S. Tsirkin, 2013/10/14
- [Qemu-devel] [PULL 37/43] i386: ACPI table generation code from seabios, Michael S. Tsirkin, 2013/10/14
- [Qemu-devel] [PULL 38/43] ssdt: fix PBLK length, Michael S. Tsirkin, 2013/10/14
- [Qemu-devel] [PULL 39/43] ssdt-proc: update generated file, Michael S. Tsirkin, 2013/10/14
- [Qemu-devel] [PULL 40/43] pci: add pci_for_each_bus_depth_first,
Michael S. Tsirkin <=
- [Qemu-devel] [PULL 41/43] pcihp: generalization of piix4 acpi, Michael S. Tsirkin, 2013/10/14
- [Qemu-devel] [PULL 43/43] acpi-build: enable hotplug for PCI bridges, Michael S. Tsirkin, 2013/10/14
- [Qemu-devel] [PULL 42/43] piix4: add acpi pci hotplug support, Michael S. Tsirkin, 2013/10/14