All of lore.kernel.org
 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>
Subject: [Qemu-devel] [PATCH 17/27] hda-codec: convert to QEMU Object Model
Date: Tue, 20 Dec 2011 10:51:46 -0600	[thread overview]
Message-ID: <1324399916-21315-18-git-send-email-aliguori@us.ibm.com> (raw)
In-Reply-To: <1324399916-21315-1-git-send-email-aliguori@us.ibm.com>

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
 hw/hda-audio.c |   58 ++++++++++++++++++++++++++++++++++---------------------
 hw/intel-hda.c |   31 +++++++++++++++++------------
 hw/intel-hda.h |   26 ++++++++++++++++--------
 3 files changed, 71 insertions(+), 44 deletions(-)

diff --git a/hw/hda-audio.c b/hw/hda-audio.c
index ffdd799..71831a3 100644
--- a/hw/hda-audio.c
+++ b/hw/hda-audio.c
@@ -906,33 +906,47 @@ static int hda_audio_init_duplex(HDACodecDevice *hda)
     return hda_audio_init(hda, &duplex);
 }
 
-static HDACodecDeviceInfo hda_audio_info_output = {
-    .qdev.name    = "hda-output",
-    .qdev.desc    = "HDA Audio Codec, output-only",
-    .qdev.size    = sizeof(HDAAudioState),
-    .qdev.vmsd    = &vmstate_hda_audio,
-    .qdev.props   = hda_audio_properties,
-    .init         = hda_audio_init_output,
-    .exit         = hda_audio_exit,
-    .command      = hda_audio_command,
-    .stream       = hda_audio_stream,
+static void hda_audio_output_class_init(ObjectClass *klass, void *data)
+{
+    HDACodecDeviceClass *k = HDA_CODEC_DEVICE_CLASS(klass);
+
+    k->init = hda_audio_init_output;
+    k->exit = hda_audio_exit;
+    k->command = hda_audio_command;
+    k->stream = hda_audio_stream;
+}
+
+static DeviceInfo hda_audio_output_info = {
+    .name = "hda-output",
+    .desc = "HDA Audio Codec, output-only",
+    .size = sizeof(HDAAudioState),
+    .vmsd = &vmstate_hda_audio,
+    .props = hda_audio_properties,
+    .class_init = hda_audio_output_class_init,
 };
 
-static HDACodecDeviceInfo hda_audio_info_duplex = {
-    .qdev.name    = "hda-duplex",
-    .qdev.desc    = "HDA Audio Codec, duplex",
-    .qdev.size    = sizeof(HDAAudioState),
-    .qdev.vmsd    = &vmstate_hda_audio,
-    .qdev.props   = hda_audio_properties,
-    .init         = hda_audio_init_duplex,
-    .exit         = hda_audio_exit,
-    .command      = hda_audio_command,
-    .stream       = hda_audio_stream,
+static void hda_audio_duplex_class_init(ObjectClass *klass, void *data)
+{
+    HDACodecDeviceClass *k = HDA_CODEC_DEVICE_CLASS(klass);
+
+    k->init = hda_audio_init_duplex;
+    k->exit = hda_audio_exit;
+    k->command = hda_audio_command;
+    k->stream = hda_audio_stream;
+}
+
+static DeviceInfo hda_audio_duplex_info = {
+    .name = "hda-duplex",
+    .desc = "HDA Audio Codec, duplex",
+    .size = sizeof(HDAAudioState),
+    .vmsd = &vmstate_hda_audio,
+    .props = hda_audio_properties,
+    .class_init = hda_audio_duplex_class_init,
 };
 
 static void hda_audio_register(void)
 {
-    hda_codec_register(&hda_audio_info_output);
-    hda_codec_register(&hda_audio_info_duplex);
+    hda_codec_register(&hda_audio_output_info);
+    hda_codec_register(&hda_audio_duplex_info);
 }
 device_init(hda_audio_register);
diff --git a/hw/intel-hda.c b/hw/intel-hda.c
index 09459b8..a18096d 100644
--- a/hw/intel-hda.c
+++ b/hw/intel-hda.c
@@ -51,9 +51,8 @@ static int hda_codec_dev_init(DeviceState *qdev, DeviceInfo *base)
 {
     HDACodecBus *bus = DO_UPCAST(HDACodecBus, qbus, qdev->parent_bus);
     HDACodecDevice *dev = DO_UPCAST(HDACodecDevice, qdev, qdev);
-    HDACodecDeviceInfo *info = DO_UPCAST(HDACodecDeviceInfo, qdev, base);
+    HDACodecDeviceClass *cdc = HDA_CODEC_DEVICE_GET_CLASS(dev);
 
-    dev->info = info;
     if (dev->cad == -1) {
         dev->cad = bus->next_cad;
     }
@@ -61,25 +60,26 @@ static int hda_codec_dev_init(DeviceState *qdev, DeviceInfo *base)
         return -1;
     }
     bus->next_cad = dev->cad + 1;
-    return info->init(dev);
+    return cdc->init(dev);
 }
 
 static int hda_codec_dev_exit(DeviceState *qdev)
 {
     HDACodecDevice *dev = DO_UPCAST(HDACodecDevice, qdev, qdev);
+    HDACodecDeviceClass *cdc = HDA_CODEC_DEVICE_GET_CLASS(dev);
 
-    if (dev->info->exit) {
-        dev->info->exit(dev);
+    if (cdc->exit) {
+        cdc->exit(dev);
     }
     return 0;
 }
 
-void hda_codec_register(HDACodecDeviceInfo *info)
+void hda_codec_register(DeviceInfo *info)
 {
-    info->qdev.init = hda_codec_dev_init;
-    info->qdev.exit = hda_codec_dev_exit;
-    info->qdev.bus_info = &hda_codec_bus_info;
-    qdev_register(&info->qdev);
+    info->init = hda_codec_dev_init;
+    info->exit = hda_codec_dev_exit;
+    info->bus_info = &hda_codec_bus_info;
+    qdev_register(info);
 }
 
 HDACodecDevice *hda_codec_find(HDACodecBus *bus, uint32_t cad)
@@ -283,6 +283,7 @@ static int intel_hda_send_command(IntelHDAState *d, uint32_t verb)
 {
     uint32_t cad, nid, data;
     HDACodecDevice *codec;
+    HDACodecDeviceClass *cdc;
 
     cad = (verb >> 28) & 0x0f;
     if (verb & (1 << 27)) {
@@ -298,7 +299,8 @@ static int intel_hda_send_command(IntelHDAState *d, uint32_t verb)
         dprint(d, 1, "%s: addressed non-existing codec\n", __FUNCTION__);
         return -1;
     }
-    codec->info->command(codec, nid, data);
+    cdc = HDA_CODEC_DEVICE_GET_CLASS(codec);
+    cdc->command(codec, nid, data);
     return 0;
 }
 
@@ -491,9 +493,12 @@ static void intel_hda_notify_codecs(IntelHDAState *d, uint32_t stream, bool runn
     HDACodecDevice *cdev;
 
     QTAILQ_FOREACH(qdev, &d->codecs.qbus.children, sibling) {
+        HDACodecDeviceClass *cdc;
+
         cdev = DO_UPCAST(HDACodecDevice, qdev, qdev);
-        if (cdev->info->stream) {
-            cdev->info->stream(cdev, stream, running, output);
+        cdc = HDA_CODEC_DEVICE_GET_CLASS(cdev);
+        if (cdc->stream) {
+            cdc->stream(cdev, stream, running, output);
         }
     }
 }
diff --git a/hw/intel-hda.h b/hw/intel-hda.h
index 65fd2a8..f523587 100644
--- a/hw/intel-hda.h
+++ b/hw/intel-hda.h
@@ -6,9 +6,16 @@
 /* --------------------------------------------------------------------- */
 /* hda bus                                                               */
 
+#define TYPE_HDA_CODEC_DEVICE "hda-codec"
+#define HDA_CODEC_DEVICE(obj) \
+     OBJECT_CHECK(HDACodecDevice, (obj), TYPE_HDA_CODEC_DEVICE)
+#define HDA_CODEC_DEVICE_CLASS(klass) \
+     OBJECT_CLASS_CHECK(HDACodecDeviceClass, (klass), TYPE_HDA_CODEC_DEVICE)
+#define HDA_CODEC_DEVICE_GET_CLASS(obj) \
+     OBJECT_GET_CLASS(HDACodecDeviceClass, (obj), TYPE_HDA_CODEC_DEVICE)
+
 typedef struct HDACodecBus HDACodecBus;
 typedef struct HDACodecDevice HDACodecDevice;
-typedef struct HDACodecDeviceInfo HDACodecDeviceInfo;
 
 typedef void (*hda_codec_response_func)(HDACodecDevice *dev,
                                         bool solicited, uint32_t response);
@@ -23,24 +30,25 @@ struct HDACodecBus {
     hda_codec_xfer_func xfer;
 };
 
-struct HDACodecDevice {
-    DeviceState         qdev;
-    HDACodecDeviceInfo  *info;
-    uint32_t            cad;    /* codec address */
-};
+typedef struct HDACodecDeviceClass
+{
+    DeviceClass parent_class;
 
-struct HDACodecDeviceInfo {
-    DeviceInfo qdev;
     int (*init)(HDACodecDevice *dev);
     int (*exit)(HDACodecDevice *dev);
     void (*command)(HDACodecDevice *dev, uint32_t nid, uint32_t data);
     void (*stream)(HDACodecDevice *dev, uint32_t stnr, bool running, bool output);
+} HDACodecDeviceClass;
+
+struct HDACodecDevice {
+    DeviceState         qdev;
+    uint32_t            cad;    /* codec address */
 };
 
 void hda_codec_bus_init(DeviceState *dev, HDACodecBus *bus,
                         hda_codec_response_func response,
                         hda_codec_xfer_func xfer);
-void hda_codec_register(HDACodecDeviceInfo *info);
+void hda_codec_register(DeviceInfo *info);
 HDACodecDevice *hda_codec_find(HDACodecBus *bus, uint32_t cad);
 
 void hda_codec_response(HDACodecDevice *dev, bool solicited, uint32_t response);
-- 
1.7.4.1

  parent reply	other threads:[~2011-12-20 16:52 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-20 16:51 [Qemu-devel] [PATCH 00/27] qom: add QEMU Object Model type hierarchy to qdev Anthony Liguori
2011-12-20 16:51 ` [Qemu-devel] [PATCH 01/27] qom: add the base Object class Anthony Liguori
2011-12-21 13:35   ` Paolo Bonzini
2011-12-21 14:35     ` Anthony Liguori
2011-12-21 15:28       ` Paolo Bonzini
2011-12-22 17:25       ` Kevin O'Connor
2011-12-22 17:41         ` Anthony Liguori
2011-12-22 18:00           ` Kevin O'Connor
2011-12-22 19:57             ` Anthony Liguori
2012-01-02 23:01               ` Andreas Färber
2012-01-03  0:56                 ` Anthony Liguori
2011-12-22 20:25         ` Paolo Bonzini
2012-01-02 17:59   ` Paolo Bonzini
2012-01-03  1:18     ` Anthony Liguori
2012-01-03  8:57       ` Paolo Bonzini
2011-12-20 16:51 ` [Qemu-devel] [PATCH 02/27] qdev: integrate with QEMU Object Model Anthony Liguori
2011-12-20 16:51 ` [Qemu-devel] [PATCH 03/27] qdev: move qdev->info to class Anthony Liguori
2011-12-20 16:51 ` [Qemu-devel] [PATCH 04/27] qdev: don't access name through info Anthony Liguori
2011-12-20 16:51 ` [Qemu-devel] [PATCH 05/27] qdev: use a wrapper to access reset and promote reset to a class method Anthony Liguori
2011-12-20 16:51 ` [Qemu-devel] [PATCH 06/27] pci: check for an initialized QOM object instead of looking for an info link Anthony Liguori
2011-12-20 16:51 ` [Qemu-devel] [PATCH 07/27] qdev: add a interface to register subclasses Anthony Liguori
2011-12-20 16:51 ` [Qemu-devel] [PATCH 08/27] qdev: add class_init to DeviceInfo Anthony Liguori
2011-12-20 16:51 ` [Qemu-devel] [PATCH 09/27] qdev: prepare source tree for code conversion Anthony Liguori
2011-12-20 16:51 ` [Qemu-devel] [PATCH 10/27] not-for-upstream: disable non-qdev pci devices Anthony Liguori
2012-01-02 22:55   ` Andreas Färber
2012-01-03  0:55     ` Anthony Liguori
2011-12-20 16:51 ` [Qemu-devel] [PATCH 11/27] isa: convert to QEMU Object Model Anthony Liguori
2011-12-20 16:51 ` [Qemu-devel] [PATCH 12/27] usb: " Anthony Liguori
2011-12-20 16:51 ` [Qemu-devel] [PATCH 13/27] ccid: " Anthony Liguori
2011-12-20 16:51 ` [Qemu-devel] [PATCH 14/27] ssi: " Anthony Liguori
2011-12-20 16:51 ` [Qemu-devel] [PATCH 15/27] i2c: rename i2c_slave -> I2CSlave Anthony Liguori
2011-12-20 16:51 ` [Qemu-devel] [PATCH 16/27] i2c: smbus: convert to QEMU Object Model Anthony Liguori
2011-12-20 16:51 ` Anthony Liguori [this message]
2011-12-20 16:51 ` [Qemu-devel] [PATCH 18/27] ide: " Anthony Liguori
2011-12-20 16:51 ` [Qemu-devel] [PATCH 19/27] scsi: " Anthony Liguori
2011-12-20 16:51 ` [Qemu-devel] [PATCH 20/27] not-for-upstream: spapr: break default console Anthony Liguori
2011-12-20 16:51 ` [Qemu-devel] [PATCH 21/27] spapr: convert to QEMU Object Model Anthony Liguori
2011-12-20 16:51 ` [Qemu-devel] [PATCH 22/27] not-for-upstream: virtio-serial: stub out a strange hack Anthony Liguori
2011-12-20 16:51 ` [Qemu-devel] [PATCH 23/27] virtio-serial: convert to QEMU Object Model Anthony Liguori
2011-12-20 16:51 ` [Qemu-devel] [PATCH 24/27] grackle: remove broken pci device Anthony Liguori
2012-01-02 22:41   ` Andreas Färber
2012-01-03  0:53     ` Anthony Liguori
2011-12-20 16:51 ` [Qemu-devel] [PATCH 25/27] unin_pci: remove phantom qdev devices in unin_pci Anthony Liguori
2012-01-02 22:44   ` Andreas Färber
2011-12-20 16:51 ` [Qemu-devel] [PATCH 26/27] pci: convert to QEMU Object Model Anthony Liguori
2011-12-20 16:51 ` [Qemu-devel] [PATCH 27/27] sysbus: " Anthony Liguori
2011-12-20 16:55 ` [Qemu-devel] [PATCH 00/27] qom: add QEMU Object Model type hierarchy to qdev 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=1324399916-21315-18-git-send-email-aliguori@us.ibm.com \
    --to=aliguori@us.ibm.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.