From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
Gerd Hoffmann <kraxel@redhat.com>,
Anthony Liguori <anthony@codemonkey.ws>,
Igor Mammedov <imammedo@redhat.com>,
Laszlo Ersek <lersek@redhat.com>,
afaerber@suse.de
Subject: [Qemu-devel] [PATCH v3 1/4] pci: add pci_for_each_bus_depth_first
Date: Mon, 7 Oct 2013 12:21:31 +0300 [thread overview]
Message-ID: <1381137467-6678-2-git-send-email-mst@redhat.com> (raw)
In-Reply-To: <1381137467-6678-1-git-send-email-mst@redhat.com>
Add a method to scan pci buses in a predictable order.
Useful for ACPI hotplug.
Document that order is not guaranteed for pci_for_each_device,
and re-implement using that.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
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 4b90e5d..6259e23 100644
--- a/include/hw/pci/pci.h
+++ b/include/hw/pci/pci.h
@@ -391,6 +391,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 c3fdff4..728f7b9 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -1682,6 +1682,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
next prev parent reply other threads:[~2013-10-07 9:19 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-07 9:21 [Qemu-devel] [PATCH v3 0/4] acpi hotplug of devices behind a pci bridge Michael S. Tsirkin
2013-10-07 9:21 ` Michael S. Tsirkin [this message]
2013-10-07 9:21 ` [Qemu-devel] [PATCH v3 2/4] pcihp: generalization of piix4 acpi Michael S. Tsirkin
2013-10-07 9:21 ` [Qemu-devel] [PATCH v3 3/4] piix4: add acpi pci hotplug support Michael S. Tsirkin
2013-10-07 9:21 ` [Qemu-devel] [PATCH v3 4/4] acpi-build: enable hotplug for PCI bridges Michael S. Tsirkin
2013-10-13 20:51 ` [Qemu-devel] [PATCH v3 0/4] acpi hotplug of devices behind a pci bridge Michael S. Tsirkin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1381137467-6678-2-git-send-email-mst@redhat.com \
--to=mst@redhat.com \
--cc=afaerber@suse.de \
--cc=anthony@codemonkey.ws \
--cc=imammedo@redhat.com \
--cc=kraxel@redhat.com \
--cc=lersek@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).