qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH 1/5] qdev/class: core
Date: Thu,  9 Jul 2009 15:02:20 +0200	[thread overview]
Message-ID: <1247144544-8885-2-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/qdev.c |   29 ++++++++++++++++++++++++-----
 hw/qdev.h |    9 +++++++++
 2 files changed, 33 insertions(+), 5 deletions(-)

diff --git a/hw/qdev.c b/hw/qdev.c
index 009e68d..67cca3b 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -46,7 +46,19 @@ void qdev_register(DeviceInfo *info)
     device_info_list = info;
 }
 
-static DeviceInfo *qdev_find_info(BusInfo *bus_info, const char *name)
+const char *qdev_class_name(DeviceClass class)
+{
+    static const char *names[] = {
+        [ DEV_CLASS_UNSPECIFIED ] = "<unspecified>",
+        [ DEV_CLASS_NETWORK ]     = "network",
+        [ DEV_CLASS_SOUND ]       = "sound",
+    };
+    if (class < ARRAY_SIZE(names))
+        return names[class];
+    return "<invalid>";
+}
+
+DeviceInfo *qdev_find_info(BusInfo *bus_info, const char *name, DeviceClass class)
 {
     DeviceInfo *info;
 
@@ -54,6 +66,8 @@ static DeviceInfo *qdev_find_info(BusInfo *bus_info, const char *name)
     for (info = device_info_list; info != NULL; info = info->next) {
         if (bus_info && info->bus_info != bus_info)
             continue;
+        if (class && info->class != class)
+            continue;
         if (strcmp(info->name, name) != 0)
             continue;
         return info;
@@ -63,6 +77,8 @@ static DeviceInfo *qdev_find_info(BusInfo *bus_info, const char *name)
     for (info = device_info_list; info != NULL; info = info->next) {
         if (bus_info && info->bus_info != bus_info)
             continue;
+        if (class && info->class != class)
+            continue;
         if (!info->alias)
             continue;
         if (strcmp(info->alias, name) != 0)
@@ -87,7 +103,7 @@ DeviceState *qdev_create(BusState *bus, const char *name)
         bus = main_system_bus;
     }
 
-    info = qdev_find_info(bus->info, name);
+    info = qdev_find_info(bus->info, name, 0);
     if (!info) {
         hw_error("Unknown device '%s' for bus '%s'\n", name, bus->info->name);
     }
@@ -121,6 +137,8 @@ DeviceState *qdev_device_add(const char *cmdline)
                 fprintf(stderr, ", alias \"%s\"", info->alias);
             if (info->desc)
                 fprintf(stderr, ", desc \"%s\"", info->desc);
+            if (info->class)
+                fprintf(stderr, ", class \"%s\"", qdev_class_name(info->class));
             if (info->no_user)
                 fprintf(stderr, ", no-user");
             fprintf(stderr, "\n");
@@ -131,7 +149,7 @@ DeviceState *qdev_device_add(const char *cmdline)
         params = cmdline + n;
         get_param_value(addr, sizeof(addr), "addr", params);
     }
-    info = qdev_find_info(NULL, driver);
+    info = qdev_find_info(NULL, driver, 0);
 
     if (!info) {
         fprintf(stderr, "Device \"%s\" not found.  Try -device '?' for a list.\n",
@@ -378,7 +396,8 @@ void do_info_qdrv(Monitor *mon)
     DeviceInfo *info;
 
     for (info = device_info_list; info != NULL; info = info->next) {
-        monitor_printf(mon, "name \"%s\", bus %s\n",
-                       info->name, info->bus_info->name);
+        monitor_printf(mon, "name \"%s\", bus %s, class %s\n",
+                       info->name, info->bus_info->name,
+                       qdev_class_name(info->class));
     }
 }
diff --git a/hw/qdev.h b/hw/qdev.h
index cf6083f..a35b712 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -79,10 +79,17 @@ typedef void (*qdev_initfn)(DeviceState *dev, DeviceInfo *info);
 typedef void (*SCSIAttachFn)(DeviceState *host, BlockDriverState *bdrv,
               int unit);
 
+typedef enum DeviceClass {
+    DEV_CLASS_UNSPECIFIED = 0,
+    DEV_CLASS_NETWORK,
+    DEV_CLASS_SOUND,
+} DeviceClass;
+
 struct DeviceInfo {
     const char *name;
     const char *alias;
     const char *desc;
+    DeviceClass class;
     size_t size;
     Property *props;
     int no_user;
@@ -94,6 +101,8 @@ struct DeviceInfo {
 };
 
 void qdev_register(DeviceInfo *info);
+const char *qdev_class_name(DeviceClass class);
+DeviceInfo *qdev_find_info(BusInfo *bus_info, const char *name, DeviceClass class);
 
 /* Register device properties.  */
 /* GPIO inputs also double as IRQ sinks.  */
-- 
1.6.2.5

  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 ` Gerd Hoffmann [this message]
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 ` [Qemu-devel] [PATCH 5/5] qdev/class: make pci_nic_init() use qdev's device list Gerd Hoffmann
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-2-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).