aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2009-06-18 15:14:09 +0200
committerAnthony Liguori <aliguori@us.ibm.com>2009-06-22 10:15:29 -0500
commit1f5f6638c063514f193ca447d49fa95f8a574a69 (patch)
treebbfca84f5610579dccbbc632e96888cc5ce6b23e
parent5607c38820366954c38dd702e979499486057481 (diff)
Make first argument of monitor command pci_add work
Simply pass the PCI address through qemu_pci_hot_add_nic() to pci_nic_init() and through qemu_pci_hot_add_storage() to pci_create(). Before, pci_device_hot_add() passed along the PCI bus to use, and ignored any user-specified slot. Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
-rw-r--r--hw/pci-hotplug.c51
-rw-r--r--hw/pci.c19
-rw-r--r--hw/pci.h2
3 files changed, 28 insertions, 44 deletions
diff --git a/hw/pci-hotplug.c b/hw/pci-hotplug.c
index e2b14caafa..031643e09f 100644
--- a/hw/pci-hotplug.c
+++ b/hw/pci-hotplug.c
@@ -33,7 +33,8 @@
#include "virtio-blk.h"
#if defined(TARGET_I386) || defined(TARGET_X86_64)
-static PCIDevice *qemu_pci_hot_add_nic(Monitor *mon, const char *opts)
+static PCIDevice *qemu_pci_hot_add_nic(Monitor *mon,
+ const char *devaddr, const char *opts)
{
int ret;
@@ -44,7 +45,7 @@ static PCIDevice *qemu_pci_hot_add_nic(Monitor *mon, const char *opts)
monitor_printf(mon, "Parameter addr not supported\n");
return NULL;
}
- return pci_nic_init(&nd_table[ret], "rtl8139", NULL);
+ return pci_nic_init(&nd_table[ret], "rtl8139", devaddr);
}
void drive_hot_add(Monitor *mon, const char *pci_addr, const char *opts)
@@ -89,10 +90,11 @@ void drive_hot_add(Monitor *mon, const char *pci_addr, const char *opts)
return;
}
-static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon, PCIBus *pci_bus,
+static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon,
+ const char *devaddr,
const char *opts)
{
- void *opaque = NULL;
+ PCIDevice *dev;
int type = -1, drive_idx = -1;
char buf[128];
@@ -103,63 +105,62 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon, PCIBus *pci_bus,
type = IF_VIRTIO;
} else {
monitor_printf(mon, "type %s not a hotpluggable PCI device.\n", buf);
- goto out;
+ return NULL;
}
} else {
monitor_printf(mon, "no if= specified\n");
- goto out;
+ return NULL;
}
if (get_param_value(buf, sizeof(buf), "file", opts)) {
drive_idx = add_init_drive(opts);
if (drive_idx < 0)
- goto out;
+ return NULL;
} else if (type == IF_VIRTIO) {
monitor_printf(mon, "virtio requires a backing file/device.\n");
- goto out;
+ return NULL;
}
switch (type) {
case IF_SCSI:
- opaque = pci_create_simple(pci_bus, -1, "lsi53c895a");
+ dev = pci_create("lsi53c895a", devaddr);
break;
case IF_VIRTIO:
- opaque = pci_create_simple(pci_bus, -1, "virtio-blk-pci");
+ dev = pci_create("virtio-blk-pci", devaddr);
break;
+ default:
+ dev = NULL;
}
-
-out:
- return opaque;
+ if (dev)
+ qdev_init(&dev->qdev);
+ return dev;
}
void pci_device_hot_add(Monitor *mon, const char *pci_addr, const char *type,
const char *opts)
{
PCIDevice *dev = NULL;
- PCIBus *pci_bus;
- int dom, bus;
- unsigned slot;
+ const char *devaddr = NULL;
+ char buf[32];
- if (pci_assign_devaddr(pci_addr, &dom, &bus, &slot)) {
+ if (!get_param_value(buf, sizeof(buf), "pci_addr", pci_addr)) {
monitor_printf(mon, "Invalid pci address\n");
return;
}
- pci_bus = pci_find_bus(bus);
- if (!pci_bus) {
- monitor_printf(mon, "Can't find pci_bus %d\n", bus);
- return;
- }
+ if (strcmp(buf, "auto"))
+ devaddr = buf;
if (strcmp(type, "nic") == 0)
- dev = qemu_pci_hot_add_nic(mon, opts);
+ dev = qemu_pci_hot_add_nic(mon, devaddr, opts);
else if (strcmp(type, "storage") == 0)
- dev = qemu_pci_hot_add_storage(mon, pci_bus, opts);
+ dev = qemu_pci_hot_add_storage(mon, devaddr, opts);
else
monitor_printf(mon, "invalid type: %s\n", type);
if (dev) {
- qemu_system_device_hot_add(bus, PCI_SLOT(dev->devfn), 1);
+ qemu_system_device_hot_add(pci_bus_num(dev->bus),
+ PCI_SLOT(dev->devfn), 1);
monitor_printf(mon, "OK domain %d, bus %d, slot %d, function %d\n",
0, pci_bus_num(dev->bus), PCI_SLOT(dev->devfn),
PCI_FUNC(dev->devfn));
diff --git a/hw/pci.c b/hw/pci.c
index 260f75e269..f2d7daf3e8 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -237,23 +237,6 @@ int pci_read_devaddr(const char *addr, int *domp, int *busp, unsigned *slotp)
return pci_parse_devaddr(devaddr, domp, busp, slotp);
}
-int pci_assign_devaddr(const char *addr, int *domp, int *busp, unsigned *slotp)
-{
- char devaddr[32];
-
- if (!get_param_value(devaddr, sizeof(devaddr), "pci_addr", addr))
- return -1;
-
- if (!strcmp(devaddr, "auto")) {
- *domp = *busp = 0;
- *slotp = -1;
- /* want to support dom/bus auto-assign at some point */
- return 0;
- }
-
- return pci_parse_devaddr(devaddr, domp, busp, slotp);
-}
-
static PCIBus *pci_get_bus_devfn(int *devfnp, const char *devaddr)
{
int dom, bus;
@@ -820,7 +803,7 @@ void pci_info(Monitor *mon)
pci_for_each_device(0, pci_info_device);
}
-static PCIDevice *pci_create(const char *name, const char *devaddr)
+PCIDevice *pci_create(const char *name, const char *devaddr)
{
PCIBus *bus;
int devfn;
diff --git a/hw/pci.h b/hw/pci.h
index 935de17da7..c8625def57 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -193,7 +193,6 @@ PCIBus *pci_find_bus(int bus_num);
PCIDevice *pci_find_device(int bus_num, int slot, int function);
int pci_read_devaddr(const char *addr, int *domp, int *busp, unsigned *slotp);
-int pci_assign_devaddr(const char *addr, int *domp, int *busp, unsigned *slotp);
void pci_info(Monitor *mon);
PCIBus *pci_bridge_init(PCIBus *bus, int devfn, uint16_t vid, uint16_t did,
@@ -220,6 +219,7 @@ pci_config_set_class(uint8_t *pci_config, uint16_t val)
typedef void (*pci_qdev_initfn)(PCIDevice *dev);
void pci_qdev_register(const char *name, int size, pci_qdev_initfn init);
+PCIDevice *pci_create(const char *name, const char *devaddr);
PCIDevice *pci_create_simple(PCIBus *bus, int devfn, const char *name);
/* lsi53c895a.c */