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 03/10] qdev: remove DeviceType
Date: Wed, 17 Jun 2009 14:59:18 +0200	[thread overview]
Message-ID: <1245243565-24807-4-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1245243565-24807-1-git-send-email-kraxel@redhat.com>

The only purpose DeviceType serves is creating a linked list of
DeviceInfo structs.  This removes DeviceType and add a next field to
DeviceInfo instead, so the DeviceInfo structs can be changed that way.
Elimitates a pointless extra level of indirection.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/qdev.c |   37 ++++++++++++++-----------------------
 hw/qdev.h |    7 +++----
 2 files changed, 17 insertions(+), 27 deletions(-)

diff --git a/hw/qdev.c b/hw/qdev.c
index 93e417d..3dc7076 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -41,28 +41,19 @@ struct DeviceProperty {
     DeviceProperty *next;
 };
 
-struct DeviceType {
-    DeviceInfo *info;
-    DeviceType *next;
-};
-
 /* This is a nasty hack to allow passing a NULL bus to qdev_create.  */
 static BusState *main_system_bus;
 extern struct BusInfo system_bus_info;
 
-static DeviceType *device_type_list;
+static DeviceInfo *device_info_list;
 
 /* Register a new device type.  */
 void qdev_register(DeviceInfo *info)
 {
-    DeviceType *t;
-
     assert(info->size >= sizeof(DeviceState));
 
-    t = qemu_mallocz(sizeof(DeviceType));
-    t->next = device_type_list;
-    device_type_list = t;
-    t->info = info;
+    info->next = device_info_list;
+    device_info_list = info;
 }
 
 /* Create a new device.  This only initializes the device state structure
@@ -70,7 +61,7 @@ void qdev_register(DeviceInfo *info)
    initialize the actual device emulation.  */
 DeviceState *qdev_create(BusState *bus, const char *name)
 {
-    DeviceType *t;
+    DeviceInfo *info;
     DeviceState *dev;
 
     if (!bus) {
@@ -80,19 +71,19 @@ DeviceState *qdev_create(BusState *bus, const char *name)
         bus = main_system_bus;
     }
 
-    for (t = device_type_list; t; t = t->next) {
-        if (t->info->bus_info != bus->info)
+    for (info = device_info_list; info != NULL; info = info->next) {
+        if (info->bus_info != bus->info)
             continue;
-        if (strcmp(t->info->name, name) != 0)
+        if (strcmp(info->name, name) != 0)
             continue;
         break;
     }
-    if (!t) {
+    if (!info) {
         hw_error("Unknown device '%s' for bus '%s'\n", name, bus->info->name);
     }
 
-    dev = qemu_mallocz(t->info->size);
-    dev->type = t;
+    dev = qemu_mallocz(info->size);
+    dev->info = info;
     dev->parent_bus = bus;
     LIST_INSERT_HEAD(&bus->children, dev, sibling);
     return dev;
@@ -103,7 +94,7 @@ DeviceState *qdev_create(BusState *bus, const char *name)
    calling this function.  */
 void qdev_init(DeviceState *dev)
 {
-    dev->type->info->init(dev, dev->type->info);
+    dev->info->init(dev, dev->info);
 }
 
 /* Unlink device from bus and free the structure.  */
@@ -165,7 +156,7 @@ CharDriverState *qdev_init_chardev(DeviceState *dev)
     static int next_serial;
     static int next_virtconsole;
     /* FIXME: This is a nasty hack that needs to go away.  */
-    if (strncmp(dev->type->info->name, "virtio", 6) == 0) {
+    if (strncmp(dev->info->name, "virtio", 6) == 0) {
         return virtcon_hds[next_virtconsole++];
     } else {
         return serial_hds[next_serial++];
@@ -338,7 +329,7 @@ static void qdev_print(Monitor *mon, DeviceState *dev, int indent)
 {
     DeviceProperty *prop;
     BusState *child;
-    qdev_printf("dev: %s\n", dev->type->info->name);
+    qdev_printf("dev: %s\n", dev->info->name);
     indent += 2;
     if (dev->num_gpio_in) {
         qdev_printf("gpio-in %d\n", dev->num_gpio_in);
@@ -357,7 +348,7 @@ static void qdev_print(Monitor *mon, DeviceState *dev, int indent)
             break;
         case PROP_TYPE_DEV:
             qdev_printf("prop-dev %s %s\n", prop->name,
-                        ((DeviceState *)prop->value.ptr)->type->info->name);
+                        ((DeviceState *)prop->value.ptr)->info->name);
             break;
         default:
             qdev_printf("prop-unknown%d %s\n", prop->type, prop->name);
diff --git a/hw/qdev.h b/hw/qdev.h
index 8b238d5..18321b3 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -4,7 +4,7 @@
 #include "hw.h"
 #include "sys-queue.h"
 
-typedef struct DeviceType DeviceType;
+typedef struct DeviceInfo DeviceInfo;
 
 typedef struct DeviceProperty DeviceProperty;
 
@@ -15,7 +15,7 @@ typedef struct BusInfo BusInfo;
 /* This structure should not be accessed directly.  We declare it here
    so that it can be embedded in individual device state structures.  */
 struct DeviceState {
-    DeviceType *type;
+    DeviceInfo *info;
     BusState *parent_bus;
     DeviceProperty *props;
     int num_gpio_out;
@@ -72,8 +72,6 @@ typedef struct {
     DevicePropType type;
 } DevicePropList;
 
-typedef struct DeviceInfo DeviceInfo;
-
 typedef void (*qdev_initfn)(DeviceState *dev, DeviceInfo *info);
 typedef void (*SCSIAttachFn)(DeviceState *host, BlockDriverState *bdrv,
               int unit);
@@ -86,6 +84,7 @@ struct DeviceInfo {
     /* Private to qdev / bus.  */
     qdev_initfn init;
     BusInfo *bus_info;
+    struct DeviceInfo *next;
 };
 
 void qdev_register(DeviceInfo *info);
-- 
1.6.2.2

  parent reply	other threads:[~2009-06-17 12:59 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-17 12:59 [Qemu-devel] [PATCH 0/10] qdev patches Gerd Hoffmann
2009-06-17 12:59 ` [Qemu-devel] [PATCH 01/10] qdev: update pci device registration Gerd Hoffmann
2009-06-17 12:59 ` [Qemu-devel] [PATCH 02/10] qdev: replace bus_type enum with bus_info struct Gerd Hoffmann
2009-06-17 12:59 ` Gerd Hoffmann [this message]
2009-06-17 12:59 ` [Qemu-devel] [PATCH 04/10] qdev/pci: bus name Gerd Hoffmann
2009-06-17 12:59 ` [Qemu-devel] [PATCH 05/10] qdev: hook up i440fx Gerd Hoffmann
2009-06-17 12:59 ` [Qemu-devel] [PATCH 06/10] qdev: convert piix-ide, first step Gerd Hoffmann
2009-06-17 12:59 ` [Qemu-devel] [PATCH 07/10] qdev-ify: piix acpi Gerd Hoffmann
2009-06-17 12:59 ` [Qemu-devel] [PATCH 08/10] qdev-ify: uhci Gerd Hoffmann
2009-06-17 12:59 ` [Qemu-devel] [PATCH 09/10] qdev-ify: usb Gerd Hoffmann
2009-06-17 12:59 ` [Qemu-devel] [PATCH 10/10] qdev-ify: scsi Gerd Hoffmann
2009-06-18 14:39 ` [Qemu-devel] Re: [PATCH 0/10] qdev patches Gerd Hoffmann
2009-06-19 15:59   ` Gerd Hoffmann
2009-06-19 17:51     ` Paul Brook
2009-06-22  9:15       ` Gerd Hoffmann
2009-06-22  9:36         ` Avi Kivity
2009-06-22  9:57           ` Gerd Hoffmann
2009-06-22 11:25             ` Gerd Hoffmann
2009-06-22 11:29               ` Avi Kivity
2009-06-22 14:02         ` Gerd Hoffmann
2009-06-22 13:45       ` Gerd Hoffmann
2009-06-19 16:26 ` [Qemu-devel] " Paul Brook
2009-06-26 21:16   ` Markus Armbruster

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=1245243565-24807-4-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).