From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:35576) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UfTb8-0005mz-Gl for qemu-devel@nongnu.org; Thu, 23 May 2013 07:22:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UfTb2-0006ql-0x for qemu-devel@nongnu.org; Thu, 23 May 2013 07:22:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:27036) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UfTb1-0006qg-QD for qemu-devel@nongnu.org; Thu, 23 May 2013 07:22:11 -0400 Date: Thu, 23 May 2013 14:22:30 +0300 From: "Michael S. Tsirkin" Message-ID: <20130523112230.GE17480@redhat.com> References: <1368059472-25071-1-git-send-email-david@gibson.dropbear.id.au> <1368059472-25071-7-git-send-email-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1368059472-25071-7-git-send-email-david@gibson.dropbear.id.au> Subject: Re: [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: David Gibson Cc: aliguori@us.ibm.com, qemu-devel@nongnu.org On Thu, May 09, 2013 at 10:31:10AM +1000, David Gibson wrote: > 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 Or better: can we just fail if there is more than one root? > --- > 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