From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH 5/5] qdev/class: make pci_nic_init() use qdev's device list.
Date: Thu, 9 Jul 2009 15:02:24 +0200 [thread overview]
Message-ID: <1247144544-8885-6-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1247144544-8885-1-git-send-email-kraxel@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
hw/pci.c | 58 +++++++++++++++++++-----------------------------------
hw/virtio-pci.c | 1 +
2 files changed, 22 insertions(+), 37 deletions(-)
diff --git a/hw/pci.c b/hw/pci.c
index cc4882e..948611e 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -784,53 +784,37 @@ DeviceState *pci_create(const char *name, const char *devaddr)
return dev;
}
-static const char * const pci_nic_models[] = {
- "ne2k_pci",
- "i82551",
- "i82557b",
- "i82559er",
- "rtl8139",
- "e1000",
- "pcnet",
- "virtio",
- NULL
-};
-
-static const char * const pci_nic_names[] = {
- "ne2k_pci",
- "i82551",
- "i82557b",
- "i82559er",
- "rtl8139",
- "e1000",
- "pcnet",
- "virtio-net-pci",
- NULL
-};
-
/* Initialize a PCI NIC. */
PCIDevice *pci_nic_init(NICInfo *nd, const char *default_model,
const char *default_devaddr)
{
const char *devaddr = nd->devaddr ? nd->devaddr : default_devaddr;
+ char buf[256];
DeviceState *dev;
- int i;
+ DeviceInfo *info;
+ int ret = 0;
- qemu_check_nic_model_list(nd, pci_nic_models, default_model);
-
- for (i = 0; pci_nic_models[i]; i++) {
- if (strcmp(nd->model, pci_nic_models[i]) == 0) {
- dev = pci_create(pci_nic_names[i], devaddr);
- if (nd->id)
- snprintf(dev->id, sizeof(dev->id), "%s", nd->id);
- dev->nd = nd;
- qdev_init(dev);
- nd->private = dev;
- return DO_UPCAST(PCIDevice, qdev, dev);
+ if (!nd->model)
+ nd->model = strdup(default_model);
+
+ info = qdev_find_info(&pci_bus_info, nd->model, DEV_CLASS_NETWORK);
+ if (!info) {
+ if (strcmp(nd->model, "?") != 0) {
+ fprintf(stderr, "qemu: Unsupported NIC model: %s\n", nd->model);
+ ret = 1;
}
+ qdev_list_devices(&pci_bus_info, DEV_CLASS_NETWORK, buf, sizeof(buf));
+ fprintf(stderr, "qemu: Supported NIC models: %s\n", buf);
+ exit(ret);
}
- return NULL;
+ dev = pci_create(info->name, devaddr);
+ if (nd->id)
+ snprintf(dev->id, sizeof(dev->id), "%s", nd->id);
+ dev->nd = nd;
+ qdev_init(dev);
+ nd->private = dev;
+ return DO_UPCAST(PCIDevice, qdev, dev);
}
typedef struct {
diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index d28d7b3..0b3f41f 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -473,6 +473,7 @@ static PCIDeviceInfo virtio_info[] = {
.init = virtio_blk_init_pci,
},{
.qdev.name = "virtio-net-pci",
+ .qdev.alias = "virtio",
.qdev.size = sizeof(VirtIOPCIProxy),
.qdev.class = DEV_CLASS_NETWORK,
.init = virtio_net_init_pci,
--
1.6.2.5
next prev parent reply other threads:[~2009-07-09 13:02 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-09 13:02 [Qemu-devel] [PATCH 0/5] qdev: add driver class support Gerd Hoffmann
2009-07-09 13:02 ` [Qemu-devel] [PATCH 1/5] qdev/class: core Gerd Hoffmann
2009-07-09 13:02 ` [Qemu-devel] [PATCH 2/5] qdev/class: tag sound Gerd Hoffmann
2009-07-09 13:02 ` [Qemu-devel] [PATCH 3/5] qdev/class: tag network Gerd Hoffmann
2009-07-09 13:02 ` [Qemu-devel] [PATCH 4/5] qdev/class: helper function to get a list of drivers Gerd Hoffmann
2009-07-09 13:02 ` Gerd Hoffmann [this message]
2009-07-09 13:19 ` [Qemu-devel] [PATCH 0/5] qdev: add driver class support Paul Brook
2009-07-09 13:39 ` Gerd Hoffmann
2009-07-09 13:48 ` Paul Brook
2009-07-09 14:26 ` Gerd Hoffmann
2009-07-09 15:46 ` Anthony Liguori
2009-07-10 7:50 ` Gerd Hoffmann
2009-07-10 9:46 ` Paul Brook
2009-07-10 9:59 ` Gerd Hoffmann
2009-07-10 10:13 ` Paul Brook
2009-07-10 10:29 ` Gerd Hoffmann
2009-07-09 14:34 ` Filip Navara
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=1247144544-8885-6-git-send-email-kraxel@redhat.com \
--to=kraxel@redhat.com \
--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).