aboutsummaryrefslogtreecommitdiff
path: root/hw/pci.c
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
commit5607c38820366954c38dd702e979499486057481 (patch)
tree9d7f6624fc7b24c6eb887d4b634f57cb6f2b33f1 /hw/pci.c
parent07b7d05377a5e2b242ef0cce3d461d3284700fc0 (diff)
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/pci.c')
-rw-r--r--hw/pci.c48
1 files changed, 43 insertions, 5 deletions
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;
}
}