From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38058) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Um4vI-0003tD-Nz for qemu-devel@nongnu.org; Mon, 10 Jun 2013 12:26:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Um4vF-0007M4-5F for qemu-devel@nongnu.org; Mon, 10 Jun 2013 12:26:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:29555) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Um4vE-0007Lm-OT for qemu-devel@nongnu.org; Mon, 10 Jun 2013 12:26:21 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r5AGQJAk018838 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 10 Jun 2013 12:26:19 -0400 Received: from redhat.com (vpn1-6-190.ams2.redhat.com [10.36.6.190]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id r5AGQHOB004494 for ; Mon, 10 Jun 2013 12:26:18 -0400 Date: Mon, 10 Jun 2013 19:26:56 +0300 From: "Michael S. Tsirkin" Message-ID: <20130610162656.GA29685@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Subject: [Qemu-devel] [PATCH RFC] pci: add pci_for_each_bus List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org This will be useful for bridge ACPI hotplug. Signed-off-by: Michael S. Tsirkin --- hw/pci/pci.c | 17 +++++++++++++++++ include/hw/pci/pci.h | 4 ++++ 2 files changed, 21 insertions(+) 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); -- MST