summaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2009-06-18 15:14:08 +0200
committerAnthony Liguori <aliguori@us.ibm.com>2009-06-22 10:15:29 -0500
commit3e539956141f39533b9cddd69a4545a397f00237 (patch)
tree9d7f6624fc7b24c6eb887d4b634f57cb6f2b33f1 /hw
parentf250e7bbe01b53a88ce0bc3e446f00cb397d2461 (diff)
downloadqemu-3e539956141f39533b9cddd69a4545a397f00237.tar.gz
qemu-3e539956141f39533b9cddd69a4545a397f00237.tar.bz2
qemu-3e539956141f39533b9cddd69a4545a397f00237.zip
Support addr=... in option argument of -net nic
Make net_client_init() accept addr=, put the value into struct NICinfo. Use it in pci_nic_init(), and remove arguments bus and devfn. Don't support addr= in third argument of monitor command pci_add, because that clashes with its first argument. Admittedly unelegant. Machines "malta" and "r2d" have a default NIC with a well-known PCI address. Deal with that the same way as the NIC model: make pci_nic_init() take an optional default to be used when the user doesn't specify one. Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'hw')
-rw-r--r--hw/mips_malta.c10
-rw-r--r--hw/pc.c2
-rw-r--r--hw/pci-hotplug.c11
-rw-r--r--hw/pci.c48
-rw-r--r--hw/pci.h4
-rw-r--r--hw/ppc440_bamboo.c2
-rw-r--r--hw/ppc_newworld.c2
-rw-r--r--hw/ppc_oldworld.c2
-rw-r--r--hw/ppc_prep.c2
-rw-r--r--hw/ppce500_mpc8544ds.c2
-rw-r--r--hw/r2d.c2
-rw-r--r--hw/realview.c2
-rw-r--r--hw/versatilepb.c2
13 files changed, 66 insertions, 25 deletions
diff --git a/hw/mips_malta.c b/hw/mips_malta.c
index ed104f0742..e9164682a3 100644
--- a/hw/mips_malta.c
+++ b/hw/mips_malta.c
@@ -474,19 +474,19 @@ static void audio_init (PCIBus *pci_bus)
#endif
/* Network support */
-static void network_init (PCIBus *pci_bus)
+static void network_init(void)
{
int i;
for(i = 0; i < nb_nics; i++) {
NICInfo *nd = &nd_table[i];
- int devfn = -1;
+ const char *default_devaddr = NULL;
if (i == 0 && (!nd->model || strcmp(nd->model, "pcnet") == 0))
/* The malta board has a PCNet card using PCI SLOT 11 */
- devfn = 88;
+ default_devaddr = "0b";
- pci_nic_init(pci_bus, nd, devfn, "pcnet");
+ pci_nic_init(nd, "pcnet", default_devaddr);
}
}
@@ -943,7 +943,7 @@ void mips_malta_init (ram_addr_t ram_size,
#endif
/* Network card */
- network_init(pci_bus);
+ network_init();
/* Optional PCI video card */
if (cirrus_vga_enabled) {
diff --git a/hw/pc.c b/hw/pc.c
index 4515b024ca..d5c8c3c3b0 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -1078,7 +1078,7 @@ static void pc_init1(ram_addr_t ram_size,
if (!pci_enabled || (nd->model && strcmp(nd->model, "ne2k_isa") == 0))
pc_init_ne2k_isa(nd, i8259);
else
- pci_nic_init(pci_bus, nd, -1, "ne2k_pci");
+ pci_nic_init(nd, "ne2k_pci", NULL);
}
piix4_acpi_system_hot_add_init();
diff --git a/hw/pci-hotplug.c b/hw/pci-hotplug.c
index 4d49c29c42..e2b14caafa 100644
--- a/hw/pci-hotplug.c
+++ b/hw/pci-hotplug.c
@@ -33,15 +33,18 @@
#include "virtio-blk.h"
#if defined(TARGET_I386) || defined(TARGET_X86_64)
-static PCIDevice *qemu_pci_hot_add_nic(Monitor *mon, PCIBus *pci_bus,
- const char *opts)
+static PCIDevice *qemu_pci_hot_add_nic(Monitor *mon, const char *opts)
{
int ret;
ret = net_client_init(mon, "nic", opts);
if (ret < 0)
return NULL;
- return pci_nic_init(pci_bus, &nd_table[ret], -1, "rtl8139");
+ if (nd_table[ret].devaddr) {
+ monitor_printf(mon, "Parameter addr not supported\n");
+ return NULL;
+ }
+ return pci_nic_init(&nd_table[ret], "rtl8139", NULL);
}
void drive_hot_add(Monitor *mon, const char *pci_addr, const char *opts)
@@ -149,7 +152,7 @@ void pci_device_hot_add(Monitor *mon, const char *pci_addr, const char *type,
}
if (strcmp(type, "nic") == 0)
- dev = qemu_pci_hot_add_nic(mon, pci_bus, opts);
+ dev = qemu_pci_hot_add_nic(mon, opts);
else if (strcmp(type, "storage") == 0)
dev = qemu_pci_hot_add_storage(mon, pci_bus, opts);
else
diff --git a/hw/pci.c b/hw/pci.c
index da76ecd342..260f75e269 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -254,6 +254,24 @@ int pci_assign_devaddr(const char *addr, int *domp, int *busp, unsigned *slotp)
return pci_parse_devaddr(devaddr, domp, busp, slotp);
}
+static PCIBus *pci_get_bus_devfn(int *devfnp, const char *devaddr)
+{
+ int dom, bus;
+ unsigned slot;
+
+ if (!devaddr) {
+ *devfnp = -1;
+ return pci_find_bus(0);
+ }
+
+ if (pci_parse_devaddr(devaddr, &dom, &bus, &slot) < 0) {
+ return NULL;
+ }
+
+ *devfnp = slot << 3;
+ return pci_find_bus(bus);
+}
+
/* -1 for devfn means auto assign */
static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus,
const char *name, int devfn,
@@ -802,6 +820,24 @@ void pci_info(Monitor *mon)
pci_for_each_device(0, pci_info_device);
}
+static PCIDevice *pci_create(const char *name, const char *devaddr)
+{
+ PCIBus *bus;
+ int devfn;
+ DeviceState *dev;
+
+ bus = pci_get_bus_devfn(&devfn, devaddr);
+ if (!bus) {
+ fprintf(stderr, "Invalid PCI device address %s for device %s\n",
+ devaddr, name);
+ exit(1);
+ }
+
+ dev = qdev_create(&bus->qbus, name);
+ qdev_set_prop_int(dev, "devfn", devfn);
+ return (PCIDevice *)dev;
+}
+
static const char * const pci_nic_models[] = {
"ne2k_pci",
"i82551",
@@ -827,9 +863,11 @@ static const char * const pci_nic_names[] = {
};
/* Initialize a PCI NIC. */
-PCIDevice *pci_nic_init(PCIBus *bus, NICInfo *nd, int devfn,
- const char *default_model)
+PCIDevice *pci_nic_init(NICInfo *nd, const char *default_model,
+ const char *default_devaddr)
{
+ const char *devaddr = nd->devaddr ? nd->devaddr : default_devaddr;
+ PCIDevice *pci_dev;
DeviceState *dev;
int i;
@@ -837,12 +875,12 @@ PCIDevice *pci_nic_init(PCIBus *bus, NICInfo *nd, int devfn,
for (i = 0; pci_nic_models[i]; i++) {
if (strcmp(nd->model, pci_nic_models[i]) == 0) {
- dev = qdev_create(&bus->qbus, pci_nic_names[i]);
- qdev_set_prop_int(dev, "devfn", devfn);
+ pci_dev = pci_create(pci_nic_names[i], devaddr);
+ dev = &pci_dev->qdev;
qdev_set_netdev(dev, nd);
qdev_init(dev);
nd->private = dev;
- return (PCIDevice *)dev;
+ return pci_dev;
}
}
diff --git a/hw/pci.h b/hw/pci.h
index fcca526753..935de17da7 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -183,8 +183,8 @@ PCIBus *pci_register_bus(DeviceState *parent, const char *name,
pci_set_irq_fn set_irq, pci_map_irq_fn map_irq,
qemu_irq *pic, int devfn_min, int nirq);
-PCIDevice *pci_nic_init(PCIBus *bus, NICInfo *nd, int devfn,
- const char *default_model);
+PCIDevice *pci_nic_init(NICInfo *nd, const char *default_model,
+ const char *default_devaddr);
void pci_data_write(void *opaque, uint32_t addr, uint32_t val, int len);
uint32_t pci_data_read(void *opaque, uint32_t addr, int len);
int pci_bus_num(PCIBus *s);
diff --git a/hw/ppc440_bamboo.c b/hw/ppc440_bamboo.c
index 9882ea5230..f287ec79c2 100644
--- a/hw/ppc440_bamboo.c
+++ b/hw/ppc440_bamboo.c
@@ -125,7 +125,7 @@ static void bamboo_init(ram_addr_t ram_size,
for (i = 0; i < nb_nics; i++) {
/* There are no PCI NICs on the Bamboo board, but there are
* PCI slots, so we can pick whatever default model we want. */
- pci_nic_init(pcibus, &nd_table[i], -1, "e1000");
+ pci_nic_init(&nd_table[i], "e1000", NULL);
}
}
diff --git a/hw/ppc_newworld.c b/hw/ppc_newworld.c
index 22beedb87f..a1057b4d53 100644
--- a/hw/ppc_newworld.c
+++ b/hw/ppc_newworld.c
@@ -304,7 +304,7 @@ static void ppc_core99_init (ram_addr_t ram_size,
serial_hds[0], serial_hds[1], ESCC_CLOCK, 4);
for(i = 0; i < nb_nics; i++)
- pci_nic_init(pci_bus, &nd_table[i], -1, "ne2k_pci");
+ pci_nic_init(&nd_table[i], "ne2k_pci", NULL);
if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
fprintf(stderr, "qemu: too many IDE bus\n");
diff --git a/hw/ppc_oldworld.c b/hw/ppc_oldworld.c
index b2c329b74f..686e81f02f 100644
--- a/hw/ppc_oldworld.c
+++ b/hw/ppc_oldworld.c
@@ -315,7 +315,7 @@ static void ppc_heathrow_init (ram_addr_t ram_size,
serial_hds[1], ESCC_CLOCK, 4);
for(i = 0; i < nb_nics; i++)
- pci_nic_init(pci_bus, &nd_table[i], -1, "ne2k_pci");
+ pci_nic_init(&nd_table[i], "ne2k_pci", NULL);
if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
diff --git a/hw/ppc_prep.c b/hw/ppc_prep.c
index 83f2ecad62..b6f19a5551 100644
--- a/hw/ppc_prep.c
+++ b/hw/ppc_prep.c
@@ -680,7 +680,7 @@ static void ppc_prep_init (ram_addr_t ram_size,
if (strcmp(nd_table[i].model, "ne2k_isa") == 0) {
isa_ne2000_init(ne2000_io[i], i8259[ne2000_irq[i]], &nd_table[i]);
} else {
- pci_nic_init(pci_bus, &nd_table[i], -1, "ne2k_pci");
+ pci_nic_init(&nd_table[i], "ne2k_pci", NULL);
}
}
diff --git a/hw/ppce500_mpc8544ds.c b/hw/ppce500_mpc8544ds.c
index d9ed36ca59..aff3ae2356 100644
--- a/hw/ppce500_mpc8544ds.c
+++ b/hw/ppce500_mpc8544ds.c
@@ -225,7 +225,7 @@ static void mpc8544ds_init(ram_addr_t ram_size,
/* Register network interfaces. */
for (i = 0; i < nb_nics; i++) {
- pci_nic_init(pci_bus, &nd_table[i], -1, "virtio");
+ pci_nic_init(&nd_table[i], "virtio", NULL);
}
}
diff --git a/hw/r2d.c b/hw/r2d.c
index a529ab4a83..8ce68325c2 100644
--- a/hw/r2d.c
+++ b/hw/r2d.c
@@ -231,7 +231,7 @@ static void r2d_init(ram_addr_t ram_size,
/* NIC: rtl8139 on-board, and 2 slots. */
for (i = 0; i < nb_nics; i++)
- pci_nic_init(pci, &nd_table[i], (i==0)? 2<<3: -1, "rtl8139");
+ pci_nic_init(&nd_table[i], "rtl8139", i==0 ? "2" : NULL);
/* Todo: register on board registers */
if (kernel_filename) {
diff --git a/hw/realview.c b/hw/realview.c
index 62d8bf5030..8e176b9d5f 100644
--- a/hw/realview.c
+++ b/hw/realview.c
@@ -125,7 +125,7 @@ static void realview_init(ram_addr_t ram_size,
smc91c111_init(nd, 0x4e000000, pic[28]);
done_smc = 1;
} else {
- pci_nic_init(pci_bus, nd, -1, "rtl8139");
+ pci_nic_init(nd, "rtl8139", NULL);
}
}
diff --git a/hw/versatilepb.c b/hw/versatilepb.c
index 1f1b1bcca7..33711210ac 100644
--- a/hw/versatilepb.c
+++ b/hw/versatilepb.c
@@ -212,7 +212,7 @@ static void versatile_init(ram_addr_t ram_size,
smc91c111_init(nd, 0x10010000, sic[25]);
done_smc = 1;
} else {
- pci_nic_init(pci_bus, nd, -1, "rtl8139");
+ pci_nic_init(nd, "rtl8139", NULL);
}
}
if (usb_enabled) {