Commit 1f5f6638c063514f193ca447d49fa95f8a574a69
Committed by
Anthony Liguori
1 parent
5607c388
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>
Showing
3 changed files
with
28 additions
and
44 deletions
hw/pci-hotplug.c
| @@ -33,7 +33,8 @@ | @@ -33,7 +33,8 @@ | ||
| 33 | #include "virtio-blk.h" | 33 | #include "virtio-blk.h" |
| 34 | 34 | ||
| 35 | #if defined(TARGET_I386) || defined(TARGET_X86_64) | 35 | #if defined(TARGET_I386) || defined(TARGET_X86_64) |
| 36 | -static PCIDevice *qemu_pci_hot_add_nic(Monitor *mon, const char *opts) | 36 | +static PCIDevice *qemu_pci_hot_add_nic(Monitor *mon, |
| 37 | + const char *devaddr, const char *opts) | ||
| 37 | { | 38 | { |
| 38 | int ret; | 39 | int ret; |
| 39 | 40 | ||
| @@ -44,7 +45,7 @@ static PCIDevice *qemu_pci_hot_add_nic(Monitor *mon, const char *opts) | @@ -44,7 +45,7 @@ static PCIDevice *qemu_pci_hot_add_nic(Monitor *mon, const char *opts) | ||
| 44 | monitor_printf(mon, "Parameter addr not supported\n"); | 45 | monitor_printf(mon, "Parameter addr not supported\n"); |
| 45 | return NULL; | 46 | return NULL; |
| 46 | } | 47 | } |
| 47 | - return pci_nic_init(&nd_table[ret], "rtl8139", NULL); | 48 | + return pci_nic_init(&nd_table[ret], "rtl8139", devaddr); |
| 48 | } | 49 | } |
| 49 | 50 | ||
| 50 | void drive_hot_add(Monitor *mon, const char *pci_addr, const char *opts) | 51 | 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) | @@ -89,10 +90,11 @@ void drive_hot_add(Monitor *mon, const char *pci_addr, const char *opts) | ||
| 89 | return; | 90 | return; |
| 90 | } | 91 | } |
| 91 | 92 | ||
| 92 | -static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon, PCIBus *pci_bus, | 93 | +static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon, |
| 94 | + const char *devaddr, | ||
| 93 | const char *opts) | 95 | const char *opts) |
| 94 | { | 96 | { |
| 95 | - void *opaque = NULL; | 97 | + PCIDevice *dev; |
| 96 | int type = -1, drive_idx = -1; | 98 | int type = -1, drive_idx = -1; |
| 97 | char buf[128]; | 99 | char buf[128]; |
| 98 | 100 | ||
| @@ -103,63 +105,62 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon, PCIBus *pci_bus, | @@ -103,63 +105,62 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon, PCIBus *pci_bus, | ||
| 103 | type = IF_VIRTIO; | 105 | type = IF_VIRTIO; |
| 104 | } else { | 106 | } else { |
| 105 | monitor_printf(mon, "type %s not a hotpluggable PCI device.\n", buf); | 107 | monitor_printf(mon, "type %s not a hotpluggable PCI device.\n", buf); |
| 106 | - goto out; | 108 | + return NULL; |
| 107 | } | 109 | } |
| 108 | } else { | 110 | } else { |
| 109 | monitor_printf(mon, "no if= specified\n"); | 111 | monitor_printf(mon, "no if= specified\n"); |
| 110 | - goto out; | 112 | + return NULL; |
| 111 | } | 113 | } |
| 112 | 114 | ||
| 113 | if (get_param_value(buf, sizeof(buf), "file", opts)) { | 115 | if (get_param_value(buf, sizeof(buf), "file", opts)) { |
| 114 | drive_idx = add_init_drive(opts); | 116 | drive_idx = add_init_drive(opts); |
| 115 | if (drive_idx < 0) | 117 | if (drive_idx < 0) |
| 116 | - goto out; | 118 | + return NULL; |
| 117 | } else if (type == IF_VIRTIO) { | 119 | } else if (type == IF_VIRTIO) { |
| 118 | monitor_printf(mon, "virtio requires a backing file/device.\n"); | 120 | monitor_printf(mon, "virtio requires a backing file/device.\n"); |
| 119 | - goto out; | 121 | + return NULL; |
| 120 | } | 122 | } |
| 121 | 123 | ||
| 122 | switch (type) { | 124 | switch (type) { |
| 123 | case IF_SCSI: | 125 | case IF_SCSI: |
| 124 | - opaque = pci_create_simple(pci_bus, -1, "lsi53c895a"); | 126 | + dev = pci_create("lsi53c895a", devaddr); |
| 125 | break; | 127 | break; |
| 126 | case IF_VIRTIO: | 128 | case IF_VIRTIO: |
| 127 | - opaque = pci_create_simple(pci_bus, -1, "virtio-blk-pci"); | 129 | + dev = pci_create("virtio-blk-pci", devaddr); |
| 128 | break; | 130 | break; |
| 131 | + default: | ||
| 132 | + dev = NULL; | ||
| 129 | } | 133 | } |
| 130 | - | ||
| 131 | -out: | ||
| 132 | - return opaque; | 134 | + if (dev) |
| 135 | + qdev_init(&dev->qdev); | ||
| 136 | + return dev; | ||
| 133 | } | 137 | } |
| 134 | 138 | ||
| 135 | void pci_device_hot_add(Monitor *mon, const char *pci_addr, const char *type, | 139 | void pci_device_hot_add(Monitor *mon, const char *pci_addr, const char *type, |
| 136 | const char *opts) | 140 | const char *opts) |
| 137 | { | 141 | { |
| 138 | PCIDevice *dev = NULL; | 142 | PCIDevice *dev = NULL; |
| 139 | - PCIBus *pci_bus; | ||
| 140 | - int dom, bus; | ||
| 141 | - unsigned slot; | 143 | + const char *devaddr = NULL; |
| 144 | + char buf[32]; | ||
| 142 | 145 | ||
| 143 | - if (pci_assign_devaddr(pci_addr, &dom, &bus, &slot)) { | 146 | + if (!get_param_value(buf, sizeof(buf), "pci_addr", pci_addr)) { |
| 144 | monitor_printf(mon, "Invalid pci address\n"); | 147 | monitor_printf(mon, "Invalid pci address\n"); |
| 145 | return; | 148 | return; |
| 146 | } | 149 | } |
| 147 | 150 | ||
| 148 | - pci_bus = pci_find_bus(bus); | ||
| 149 | - if (!pci_bus) { | ||
| 150 | - monitor_printf(mon, "Can't find pci_bus %d\n", bus); | ||
| 151 | - return; | ||
| 152 | - } | 151 | + if (strcmp(buf, "auto")) |
| 152 | + devaddr = buf; | ||
| 153 | 153 | ||
| 154 | if (strcmp(type, "nic") == 0) | 154 | if (strcmp(type, "nic") == 0) |
| 155 | - dev = qemu_pci_hot_add_nic(mon, opts); | 155 | + dev = qemu_pci_hot_add_nic(mon, devaddr, opts); |
| 156 | else if (strcmp(type, "storage") == 0) | 156 | else if (strcmp(type, "storage") == 0) |
| 157 | - dev = qemu_pci_hot_add_storage(mon, pci_bus, opts); | 157 | + dev = qemu_pci_hot_add_storage(mon, devaddr, opts); |
| 158 | else | 158 | else |
| 159 | monitor_printf(mon, "invalid type: %s\n", type); | 159 | monitor_printf(mon, "invalid type: %s\n", type); |
| 160 | 160 | ||
| 161 | if (dev) { | 161 | if (dev) { |
| 162 | - qemu_system_device_hot_add(bus, PCI_SLOT(dev->devfn), 1); | 162 | + qemu_system_device_hot_add(pci_bus_num(dev->bus), |
| 163 | + PCI_SLOT(dev->devfn), 1); | ||
| 163 | monitor_printf(mon, "OK domain %d, bus %d, slot %d, function %d\n", | 164 | monitor_printf(mon, "OK domain %d, bus %d, slot %d, function %d\n", |
| 164 | 0, pci_bus_num(dev->bus), PCI_SLOT(dev->devfn), | 165 | 0, pci_bus_num(dev->bus), PCI_SLOT(dev->devfn), |
| 165 | PCI_FUNC(dev->devfn)); | 166 | PCI_FUNC(dev->devfn)); |
hw/pci.c
| @@ -237,23 +237,6 @@ int pci_read_devaddr(const char *addr, int *domp, int *busp, unsigned *slotp) | @@ -237,23 +237,6 @@ int pci_read_devaddr(const char *addr, int *domp, int *busp, unsigned *slotp) | ||
| 237 | return pci_parse_devaddr(devaddr, domp, busp, slotp); | 237 | return pci_parse_devaddr(devaddr, domp, busp, slotp); |
| 238 | } | 238 | } |
| 239 | 239 | ||
| 240 | -int pci_assign_devaddr(const char *addr, int *domp, int *busp, unsigned *slotp) | ||
| 241 | -{ | ||
| 242 | - char devaddr[32]; | ||
| 243 | - | ||
| 244 | - if (!get_param_value(devaddr, sizeof(devaddr), "pci_addr", addr)) | ||
| 245 | - return -1; | ||
| 246 | - | ||
| 247 | - if (!strcmp(devaddr, "auto")) { | ||
| 248 | - *domp = *busp = 0; | ||
| 249 | - *slotp = -1; | ||
| 250 | - /* want to support dom/bus auto-assign at some point */ | ||
| 251 | - return 0; | ||
| 252 | - } | ||
| 253 | - | ||
| 254 | - return pci_parse_devaddr(devaddr, domp, busp, slotp); | ||
| 255 | -} | ||
| 256 | - | ||
| 257 | static PCIBus *pci_get_bus_devfn(int *devfnp, const char *devaddr) | 240 | static PCIBus *pci_get_bus_devfn(int *devfnp, const char *devaddr) |
| 258 | { | 241 | { |
| 259 | int dom, bus; | 242 | int dom, bus; |
| @@ -820,7 +803,7 @@ void pci_info(Monitor *mon) | @@ -820,7 +803,7 @@ void pci_info(Monitor *mon) | ||
| 820 | pci_for_each_device(0, pci_info_device); | 803 | pci_for_each_device(0, pci_info_device); |
| 821 | } | 804 | } |
| 822 | 805 | ||
| 823 | -static PCIDevice *pci_create(const char *name, const char *devaddr) | 806 | +PCIDevice *pci_create(const char *name, const char *devaddr) |
| 824 | { | 807 | { |
| 825 | PCIBus *bus; | 808 | PCIBus *bus; |
| 826 | int devfn; | 809 | int devfn; |
hw/pci.h
| @@ -193,7 +193,6 @@ PCIBus *pci_find_bus(int bus_num); | @@ -193,7 +193,6 @@ PCIBus *pci_find_bus(int bus_num); | ||
| 193 | PCIDevice *pci_find_device(int bus_num, int slot, int function); | 193 | PCIDevice *pci_find_device(int bus_num, int slot, int function); |
| 194 | 194 | ||
| 195 | int pci_read_devaddr(const char *addr, int *domp, int *busp, unsigned *slotp); | 195 | int pci_read_devaddr(const char *addr, int *domp, int *busp, unsigned *slotp); |
| 196 | -int pci_assign_devaddr(const char *addr, int *domp, int *busp, unsigned *slotp); | ||
| 197 | 196 | ||
| 198 | void pci_info(Monitor *mon); | 197 | void pci_info(Monitor *mon); |
| 199 | PCIBus *pci_bridge_init(PCIBus *bus, int devfn, uint16_t vid, uint16_t did, | 198 | 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) | @@ -220,6 +219,7 @@ pci_config_set_class(uint8_t *pci_config, uint16_t val) | ||
| 220 | typedef void (*pci_qdev_initfn)(PCIDevice *dev); | 219 | typedef void (*pci_qdev_initfn)(PCIDevice *dev); |
| 221 | void pci_qdev_register(const char *name, int size, pci_qdev_initfn init); | 220 | void pci_qdev_register(const char *name, int size, pci_qdev_initfn init); |
| 222 | 221 | ||
| 222 | +PCIDevice *pci_create(const char *name, const char *devaddr); | ||
| 223 | PCIDevice *pci_create_simple(PCIBus *bus, int devfn, const char *name); | 223 | PCIDevice *pci_create_simple(PCIBus *bus, int devfn, const char *name); |
| 224 | 224 | ||
| 225 | /* lsi53c895a.c */ | 225 | /* lsi53c895a.c */ |