From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:48970) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UaEmF-00008C-GY for qemu-devel@nongnu.org; Wed, 08 May 2013 20:32:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UaEmA-0006An-Di for qemu-devel@nongnu.org; Wed, 08 May 2013 20:32:07 -0400 Received: from ozlabs.org ([203.10.76.45]:48024) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UaEmA-0006AY-3A for qemu-devel@nongnu.org; Wed, 08 May 2013 20:32:02 -0400 From: David Gibson Date: Thu, 9 May 2013 10:31:10 +1000 Message-Id: <1368059472-25071-7-git-send-email-david@gibson.dropbear.id.au> In-Reply-To: <1368059472-25071-1-git-send-email-david@gibson.dropbear.id.au> References: <1368059472-25071-1-git-send-email-david@gibson.dropbear.id.au> Subject: [Qemu-devel] [PATCH 6/8] pci: Simpler implementation of primary PCI bus List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: aliguori@us.ibm.com, mst@redhat.com Cc: qemu-devel@nongnu.org, David Gibson Currently pci_get_primary_bus() searches the list of root buses for one with domain 0. But since host buses are always registered with domain 0, this just amounts to finding the only PCI host bus. This simplifies the implementation by defining the primary PCI bus to be the first one registered, using a global variable to track it. Signed-off-by: David Gibson --- hw/pci/pci.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index a3c192c..b25a1a1 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -96,6 +96,7 @@ struct PCIHostBus { QLIST_ENTRY(PCIHostBus) next; }; static QLIST_HEAD(, PCIHostBus) host_buses; +static PCIBus *pci_primary_bus; static const VMStateDescription vmstate_pcibus = { .name = "PCIBUS", @@ -241,6 +242,12 @@ static int pcibus_reset(BusState *qbus) static void pci_host_bus_register(int domain, PCIBus *bus) { struct PCIHostBus *host; + + /* If this is the first one, assume it's the primary bus */ + if (!pci_primary_bus) { + pci_primary_bus = bus; + } + host = g_malloc0(sizeof(*host)); host->domain = domain; host->bus = bus; @@ -249,15 +256,7 @@ static void pci_host_bus_register(int domain, PCIBus *bus) PCIBus *pci_get_primary_bus(void) { - struct PCIHostBus *host; - - QLIST_FOREACH(host, &host_buses, next) { - if (host->domain == 0) { - return host->bus; - } - } - - return NULL; + return pci_primary_bus; } PCIBus *pci_device_root_bus(const PCIDevice *d) @@ -300,6 +299,7 @@ static void pci_bus_init(PCIBus *bus, DeviceState *parent, /* host bridge */ QLIST_INIT(&bus->child); + pci_host_bus_register(0, bus); /* for now only pci domain 0 is supported */ vmstate_register(NULL, -1, &vmstate_pcibus, bus); -- 1.7.10.4