qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Anthony Liguori <aliguori@us.ibm.com>
To: qemu-devel@nongnu.org
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
	"Anthony Liguori" <aliguori@us.ibm.com>,
	"Markus Armbruster" <armbru@redhat.com>,
	"Andreas Färber" <afaerber@suse.de>
Subject: [Qemu-devel] [PATCH 22/30] ide: convert to QEMU Object Model
Date: Mon,  2 Jan 2012 18:52:11 -0600	[thread overview]
Message-ID: <1325551939-24749-23-git-send-email-aliguori@us.ibm.com> (raw)
In-Reply-To: <1325551939-24749-1-git-send-email-aliguori@us.ibm.com>

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
 hw/ide/internal.h |   20 ++++++---
 hw/ide/qdev.c     |  111 +++++++++++++++++++++++++++++++++--------------------
 2 files changed, 82 insertions(+), 49 deletions(-)

diff --git a/hw/ide/internal.h b/hw/ide/internal.h
index 00b28df..c808a0d 100644
--- a/hw/ide/internal.h
+++ b/hw/ide/internal.h
@@ -21,7 +21,6 @@
 
 typedef struct IDEBus IDEBus;
 typedef struct IDEDevice IDEDevice;
-typedef struct IDEDeviceInfo IDEDeviceInfo;
 typedef struct IDEState IDEState;
 typedef struct IDEDMA IDEDMA;
 typedef struct IDEDMAOps IDEDMAOps;
@@ -450,6 +449,19 @@ struct IDEBus {
     int error_status;
 };
 
+#define TYPE_IDE_DEVICE "ide-device"
+#define IDE_DEVICE(obj) \
+     OBJECT_CHECK(IDEDevice, (obj), TYPE_IDE_DEVICE)
+#define IDE_DEVICE_CLASS(klass) \
+     OBJECT_CLASS_CHECK(IDEDeviceClass, (klass), TYPE_IDE_DEVICE)
+#define IDE_DEVICE_GET_CLASS(obj) \
+     OBJECT_GET_CLASS(IDEDeviceClass, (obj), TYPE_IDE_DEVICE)
+
+typedef struct IDEDeviceClass {
+    DeviceClass parent_class;
+    int (*init)(IDEDevice *dev);
+} IDEDeviceClass;
+
 struct IDEDevice {
     DeviceState qdev;
     uint32_t unit;
@@ -458,12 +470,6 @@ struct IDEDevice {
     char *serial;
 };
 
-typedef int (*ide_qdev_initfn)(IDEDevice *dev);
-struct IDEDeviceInfo {
-    DeviceInfo qdev;
-    ide_qdev_initfn init;
-};
-
 #define BM_STATUS_DMAING 0x01
 #define BM_STATUS_ERROR  0x02
 #define BM_STATUS_INT    0x04
diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c
index 4207127..b507e34 100644
--- a/hw/ide/qdev.c
+++ b/hw/ide/qdev.c
@@ -55,8 +55,8 @@ static char *idebus_get_fw_dev_path(DeviceState *dev)
 
 static int ide_qdev_init(DeviceState *qdev, DeviceInfo *base)
 {
-    IDEDevice *dev = DO_UPCAST(IDEDevice, qdev, qdev);
-    IDEDeviceInfo *info = DO_UPCAST(IDEDeviceInfo, qdev, base);
+    IDEDevice *dev = IDE_DEVICE(qdev);
+    IDEDeviceClass *dc = IDE_DEVICE_GET_CLASS(dev);
     IDEBus *bus = DO_UPCAST(IDEBus, qbus, qdev->parent_bus);
 
     if (!dev->conf.bs) {
@@ -85,17 +85,17 @@ static int ide_qdev_init(DeviceState *qdev, DeviceInfo *base)
         error_report("Invalid IDE unit %d", dev->unit);
         goto err;
     }
-    return info->init(dev);
+    return dc->init(dev);
 
 err:
     return -1;
 }
 
-static void ide_qdev_register(IDEDeviceInfo *info)
+static void ide_qdev_register(DeviceInfo *info)
 {
-    info->qdev.init = ide_qdev_init;
-    info->qdev.bus_info = &ide_bus_info;
-    qdev_register(&info->qdev);
+    info->init = ide_qdev_init;
+    info->bus_info = &ide_bus_info;
+    qdev_register_subclass(info, TYPE_IDE_DEVICE);
 }
 
 IDEDevice *ide_create_drive(IDEBus *bus, int unit, DriveInfo *drive)
@@ -182,46 +182,73 @@ static int ide_drive_initfn(IDEDevice *dev)
     DEFINE_PROP_STRING("ver",  IDEDrive, dev.version),  \
     DEFINE_PROP_STRING("serial",  IDEDrive, dev.serial)
 
-static IDEDeviceInfo ide_dev_info[] = {
-    {
-        .qdev.name    = "ide-hd",
-        .qdev.fw_name = "drive",
-        .qdev.desc    = "virtual IDE disk",
-        .qdev.size    = sizeof(IDEDrive),
-        .init         = ide_hd_initfn,
-        .qdev.props   = (Property[]) {
-            DEFINE_IDE_DEV_PROPERTIES(),
-            DEFINE_PROP_END_OF_LIST(),
-        }
-    },{
-        .qdev.name    = "ide-cd",
-        .qdev.fw_name = "drive",
-        .qdev.desc    = "virtual IDE CD-ROM",
-        .qdev.size    = sizeof(IDEDrive),
-        .init         = ide_cd_initfn,
-        .qdev.props   = (Property[]) {
-            DEFINE_IDE_DEV_PROPERTIES(),
-            DEFINE_PROP_END_OF_LIST(),
-        }
-    },{
-        .qdev.name    = "ide-drive", /* legacy -device ide-drive */
-        .qdev.fw_name = "drive",
-        .qdev.desc    = "virtual IDE disk or CD-ROM (legacy)",
-        .qdev.size    = sizeof(IDEDrive),
-        .init         = ide_drive_initfn,
-        .qdev.props   = (Property[]) {
-            DEFINE_IDE_DEV_PROPERTIES(),
-            DEFINE_PROP_END_OF_LIST(),
-        }
+static void ide_hd_class_init(ObjectClass *klass, void *data)
+{
+    IDEDeviceClass *k = IDE_DEVICE_CLASS(klass);
+    k->init = ide_hd_initfn;
+}
+
+static DeviceInfo ide_hd_info = {
+    .name    = "ide-hd",
+    .fw_name = "drive",
+    .desc    = "virtual IDE disk",
+    .size    = sizeof(IDEDrive),
+    .class_init = ide_hd_class_init,
+    .props   = (Property[]) {
+        DEFINE_IDE_DEV_PROPERTIES(),
+        DEFINE_PROP_END_OF_LIST(),
     }
 };
 
-static void ide_dev_register(void)
+static void ide_cd_class_init(ObjectClass *klass, void *data)
 {
-    int i;
+    IDEDeviceClass *k = IDE_DEVICE_CLASS(klass);
+    k->init = ide_cd_initfn;
+}
 
-    for (i = 0; i < ARRAY_SIZE(ide_dev_info); i++) {
-        ide_qdev_register(&ide_dev_info[i]);
+static DeviceInfo ide_cd_info = {
+    .name    = "ide-cd",
+    .fw_name = "drive",
+    .desc    = "virtual IDE CD-ROM",
+    .size    = sizeof(IDEDrive),
+    .class_init = ide_cd_class_init,
+    .props   = (Property[]) {
+        DEFINE_IDE_DEV_PROPERTIES(),
+        DEFINE_PROP_END_OF_LIST(),
     }
+};
+
+static void ide_drive_class_init(ObjectClass *klass, void *data)
+{
+    IDEDeviceClass *k = IDE_DEVICE_CLASS(klass);
+    k->init = ide_drive_initfn;
+}
+
+static DeviceInfo ide_drive_info = {
+    .name    = "ide-drive", /* legacy -device ide-drive */
+    .fw_name = "drive",
+    .desc    = "virtual IDE disk or CD-ROM (legacy)",
+    .size    = sizeof(IDEDrive),
+    .class_init = ide_drive_class_init,
+    .props   = (Property[]) {
+        DEFINE_IDE_DEV_PROPERTIES(),
+        DEFINE_PROP_END_OF_LIST(),
+    }
+};
+
+static TypeInfo ide_device_type_info = {
+    .name = TYPE_IDE_DEVICE,
+    .parent = TYPE_DEVICE,
+    .instance_size = sizeof(IDEDevice),
+    .abstract = true,
+    .class_size = sizeof(IDEDeviceClass),
+};
+
+static void ide_dev_register(void)
+{
+    ide_qdev_register(&ide_hd_info);
+    ide_qdev_register(&ide_cd_info);
+    ide_qdev_register(&ide_drive_info);
+    type_register_static(&ide_device_type_info);
 }
 device_init(ide_dev_register);
-- 
1.7.4.1

  parent reply	other threads:[~2012-01-03  0:53 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-03  0:51 [Qemu-devel] qom: add QEMU Object Model type hierarchy to qdev (v2) Anthony Liguori
2012-01-03  0:51 ` [Qemu-devel] [PATCH 01/30] macio: convert to qdev Anthony Liguori
2012-01-03  0:51 ` [Qemu-devel] [PATCH 02/30] openpic: remove dead code to make a PCI device version Anthony Liguori
2012-01-03  0:51 ` [Qemu-devel] [PATCH 03/30] ppc: remove ppc440 bamboo board support Anthony Liguori
2012-01-05 15:16   ` François Revol
2012-01-13 10:59   ` Benjamin Herrenschmidt
2012-01-13 11:04     ` Andreas Färber
2012-01-13 11:45       ` Paolo Bonzini
2012-01-13 12:30         ` Alexander Graf
2012-01-13 14:24           ` Andreas Färber
2012-01-13 14:29             ` Alexander Graf
2012-01-03  0:51 ` [Qemu-devel] [PATCH 04/30] ppc_prep: convert host bridge to qdev Anthony Liguori
2012-01-03 14:57   ` Andreas Färber
2012-01-07  0:11     ` Andreas Färber
2012-01-03  0:51 ` [Qemu-devel] [PATCH 05/30] pseries: Remove hcalls callback Anthony Liguori
2012-01-03  0:51 ` [Qemu-devel] [PATCH 06/30] pci: call reset unconditionally Anthony Liguori
2012-01-03  0:51 ` [Qemu-devel] [PATCH 07/30] qom: add the base Object class (v2) Anthony Liguori
2012-01-03  9:02   ` Paolo Bonzini
2012-01-03  0:51 ` [Qemu-devel] [PATCH 08/30] qdev: integrate with QEMU Object Model (v2) Anthony Liguori
2012-01-03  0:51 ` [Qemu-devel] [PATCH 09/30] qdev: move qdev->info to class Anthony Liguori
2012-01-08  2:27   ` Andreas Färber
2012-01-03  0:51 ` [Qemu-devel] [PATCH 10/30] qdev: don't access name through info Anthony Liguori
2012-01-03  9:06   ` Paolo Bonzini
2012-01-03 13:39     ` Anthony Liguori
2012-01-03 13:41       ` Paolo Bonzini
2012-01-03  0:52 ` [Qemu-devel] [PATCH 11/30] qdev: use a wrapper to access reset and promote reset to a class method Anthony Liguori
2012-01-03  0:52 ` [Qemu-devel] [PATCH 12/30] qdev: add a interface to register subclasses Anthony Liguori
2012-01-03  0:52 ` [Qemu-devel] [PATCH 13/30] qdev: add class_init to DeviceInfo Anthony Liguori
2012-01-03  0:52 ` [Qemu-devel] [PATCH 14/30] qdev: prepare source tree for code conversion Anthony Liguori
2012-01-04 14:07   ` Andreas Färber
2012-01-04 14:24     ` Anthony Liguori
2012-01-03  0:52 ` [Qemu-devel] [PATCH 15/30] isa: convert to QEMU Object Model Anthony Liguori
2012-01-03  0:52 ` [Qemu-devel] [PATCH 16/30] usb: " Anthony Liguori
2012-01-03  0:52 ` [Qemu-devel] [PATCH 17/30] ccid: " Anthony Liguori
2012-01-03  0:52 ` [Qemu-devel] [PATCH 18/30] ssi: " Anthony Liguori
2012-01-03  0:52 ` [Qemu-devel] [PATCH 19/30] i2c: rename i2c_slave -> I2CSlave Anthony Liguori
2012-01-03  0:52 ` [Qemu-devel] [PATCH 20/30] i2c: smbus: convert to QEMU Object Model Anthony Liguori
2012-01-03  0:52 ` [Qemu-devel] [PATCH 21/30] hda-codec: " Anthony Liguori
2012-01-03  0:52 ` Anthony Liguori [this message]
2012-01-03  0:52 ` [Qemu-devel] [PATCH 23/30] scsi: " Anthony Liguori
2012-01-03  0:52 ` [Qemu-devel] [PATCH 24/30] spapr: convert to QEMU Object Model (v2) Anthony Liguori
2012-01-03  0:52 ` [Qemu-devel] [PATCH 25/30] virtio-serial: convert to QEMU Object Model Anthony Liguori
2012-01-03  0:52 ` [Qemu-devel] [PATCH 26/30] grackle: remove broken pci device Anthony Liguori
2012-01-08  1:46   ` Aurelien Jarno
2012-01-08  1:55     ` Andreas Färber
2012-01-03  0:52 ` [Qemu-devel] [PATCH 27/30] unin_pci: remove phantom qdev devices in unin_pci Anthony Liguori
2012-01-08  2:04   ` Andreas Färber
2012-01-03  0:52 ` [Qemu-devel] [PATCH 28/30] pci: convert to QEMU Object Model Anthony Liguori
2012-01-03  0:52 ` [Qemu-devel] [PATCH 29/30] sysbus: " Anthony Liguori
2012-01-03  0:52 ` [Qemu-devel] [PATCH 30/30] virtio-s390: " Anthony Liguori

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=1325551939-24749-23-git-send-email-aliguori@us.ibm.com \
    --to=aliguori@us.ibm.com \
    --cc=afaerber@suse.de \
    --cc=armbru@redhat.com \
    --cc=pbonzini@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).