From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org
Cc: David Gibson <david@gibson.dropbear.id.au>
Subject: [Qemu-devel] [PATCH v3 16/18] pci: Simpler implementation of primary PCI bus
Date: Thu, 4 Jul 2013 12:13:30 +0300 [thread overview]
Message-ID: <1372928939-2712-17-git-send-email-mst@redhat.com> (raw)
In-Reply-To: <1372928939-2712-1-git-send-email-mst@redhat.com>
From: David Gibson <david@gibson.dropbear.id.au>
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 <david@gibson.dropbear.id.au>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
hw/pci/pci-hotplug-old.c | 26 ++++++++++++++++++++------
hw/pci/pci.c | 9 ++++++---
2 files changed, 26 insertions(+), 9 deletions(-)
diff --git a/hw/pci/pci-hotplug-old.c b/hw/pci/pci-hotplug-old.c
index 807260c..8077289 100644
--- a/hw/pci/pci-hotplug-old.c
+++ b/hw/pci/pci-hotplug-old.c
@@ -62,10 +62,17 @@ static PCIDevice *qemu_pci_hot_add_nic(Monitor *mon,
{
Error *local_err = NULL;
QemuOpts *opts;
+ PCIBus *root = pci_find_primary_bus();
PCIBus *bus;
int ret, devfn;
- bus = pci_get_bus_devfn(&devfn, pci_find_primary_bus(), devaddr);
+ if (!root) {
+ monitor_printf(mon, "no primary PCI bus (if there are multiple"
+ " PCI roots, you must use device_add instead)");
+ return NULL;
+ }
+
+ bus = pci_get_bus_devfn(&devfn, root, devaddr);
if (!bus) {
monitor_printf(mon, "Invalid PCI device address %s\n", devaddr);
return NULL;
@@ -92,8 +99,7 @@ static PCIDevice *qemu_pci_hot_add_nic(Monitor *mon,
monitor_printf(mon, "Parameter addr not supported\n");
return NULL;
}
- return pci_nic_init(&nd_table[ret], pci_find_primary_bus(),
- "rtl8139", devaddr);
+ return pci_nic_init(&nd_table[ret], root, "rtl8139", devaddr);
}
static int scsi_hot_add(Monitor *mon, DeviceState *adapter,
@@ -144,7 +150,8 @@ int pci_drive_hot_add(Monitor *mon, const QDict *qdict, DriveInfo *dinfo)
switch (dinfo->type) {
case IF_SCSI:
if (!root) {
- monitor_printf(mon, "no primary PCI bus\n");
+ monitor_printf(mon, "no primary PCI bus (if there are multiple"
+ " PCI roots, you must use device_add instead)");
goto err;
}
if (pci_read_devaddr(mon, pci_addr, &pci_bus, &slot)) {
@@ -177,6 +184,7 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon,
DriveInfo *dinfo = NULL;
int type = -1;
char buf[128];
+ PCIBus *root = pci_find_primary_bus();
PCIBus *bus;
int devfn;
@@ -206,7 +214,12 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon,
dinfo = NULL;
}
- bus = pci_get_bus_devfn(&devfn, pci_find_primary_bus(), devaddr);
+ if (!root) {
+ monitor_printf(mon, "no primary PCI bus (if there are multiple"
+ " PCI roots, you must use device_add instead)");
+ return NULL;
+ }
+ bus = pci_get_bus_devfn(&devfn, root, devaddr);
if (!bus) {
monitor_printf(mon, "Invalid PCI device address %s\n", devaddr);
return NULL;
@@ -293,7 +306,8 @@ static int pci_device_hot_remove(Monitor *mon, const char *pci_addr)
Error *local_err = NULL;
if (!root) {
- monitor_printf(mon, "no primary PCI bus\n");
+ monitor_printf(mon, "no primary PCI bus (if there are multiple"
+ " PCI roots, you must use device_del instead)");
return -1;
}
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)
--
MST
next prev parent reply other threads:[~2013-07-04 9:16 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-04 9:12 [Qemu-devel] [PULL v3 00/18] pci,misc enhancements Michael S. Tsirkin
2013-07-04 9:12 ` [Qemu-devel] [PATCH v3 01/18] range: add Range structure Michael S. Tsirkin
2013-07-04 9:12 ` [Qemu-devel] [PATCH v3 02/18] pci: store PCI hole ranges in guestinfo structure Michael S. Tsirkin
2013-07-04 9:12 ` [Qemu-devel] [PATCH v3 03/18] pc: pass PCI hole ranges to Guests Michael S. Tsirkin
2013-07-04 9:12 ` [Qemu-devel] [PATCH v3 04/18] pc_piix: cleanup init compat handling Michael S. Tsirkin
2013-07-04 9:12 ` [Qemu-devel] [PATCH v3 05/18] e1000: cleanup process_tx_desc Michael S. Tsirkin
2013-07-04 9:12 ` [Qemu-devel] [PATCH v3 06/18] MAINTAINERS: s/Marcelo/Paolo/ Michael S. Tsirkin
2013-07-04 9:12 ` [Qemu-devel] [PATCH v3 07/18] pvpanic: initialization cleanup Michael S. Tsirkin
2013-07-04 9:13 ` [Qemu-devel] [PATCH v3 08/18] pvpanic: fix fwcfg for big endian hosts Michael S. Tsirkin
2013-07-04 9:13 ` [Qemu-devel] [PATCH v3 09/18] pci: Cleanup configuration for pci-hotplug.c Michael S. Tsirkin
2013-07-04 9:13 ` [Qemu-devel] [PATCH v3 10/18] pci: Move pci_read_devaddr to pci-hotplug-old.c Michael S. Tsirkin
2013-07-04 9:13 ` [Qemu-devel] [PATCH v3 11/18] pci: Abolish pci_find_root_bus() Michael S. Tsirkin
2013-07-04 9:13 ` [Qemu-devel] [PATCH v3 12/18] pci: Use helper to find device's root bus in pci_find_domain() Michael S. Tsirkin
2013-07-04 9:13 ` [Qemu-devel] [PATCH v3 13/18] pci: Replace pci_find_domain() with more general pci_root_bus_path() Michael S. Tsirkin
2013-07-04 9:13 ` [Qemu-devel] [PATCH v3 14/18] pci: Add root bus argument to pci_get_bus_devfn() Michael S. Tsirkin
2013-07-04 9:13 ` [Qemu-devel] [PATCH v3 15/18] pci: Add root bus parameter to pci_nic_init() Michael S. Tsirkin
2013-07-04 9:13 ` Michael S. Tsirkin [this message]
2013-07-04 9:13 ` [Qemu-devel] [PATCH v3 17/18] pci: Remove domain from PCIHostBus Michael S. Tsirkin
2013-07-04 9:13 ` [Qemu-devel] [PATCH v3 18/18] pci: Fold host_buses list into PCIHostState functionality Michael S. Tsirkin
2013-07-07 16:27 ` [Qemu-devel] [PULL v3 00/18] pci,misc enhancements Anthony Liguori
2013-07-07 20:08 ` 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=1372928939-2712-17-git-send-email-mst@redhat.com \
--to=mst@redhat.com \
--cc=david@gibson.dropbear.id.au \
--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).