From 9bc473057db773dd24be381ccbde4c686595d2e7 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Thu, 6 Jun 2013 18:48:52 +1000 Subject: pci: Simpler implementation of primary PCI bus Currently pci_find_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. The only remaining users of pci_find_primary_bus() are in pci-hotplug-old.c, which implements the old style pci_add/pci_del commands. Therefore, this patch redefines pci_find_primary_bus() to find the only PCI root bus, returning an error if there are multiple roots. The callers in pci-hotplug-old.c are updated correspondingly, to produce sensible error messages. Signed-off-by: David Gibson Signed-off-by: Michael S. Tsirkin --- hw/pci/pci.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'hw/pci/pci.c') diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 2f2db0f..e0995aa 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -249,15 +249,18 @@ static void pci_host_bus_register(int domain, PCIBus *bus) PCIBus *pci_find_primary_bus(void) { + PCIBus *primary_bus = NULL; struct PCIHostBus *host; QLIST_FOREACH(host, &host_buses, next) { - if (host->domain == 0) { - return host->bus; + if (primary_bus) { + /* We have multiple root buses, refuse to select a primary */ + return NULL; } + primary_bus = host->bus; } - return NULL; + return primary_bus; } PCIBus *pci_device_root_bus(const PCIDevice *d) -- cgit v1.1