qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Andreas Färber" <afaerber@suse.de>
To: qemu-devel@nongnu.org
Cc: "Andreas Färber" <afaerber@suse.de>, anthony@codemonkey.ws
Subject: [Qemu-devel] [PATCH v2 09/12] i8259: Convert PICCommonState to use QOM realizefn
Date: Fri,  7 Jun 2013 14:58:17 +0200	[thread overview]
Message-ID: <1370609900-21998-10-git-send-email-afaerber@suse.de> (raw)
In-Reply-To: <1370609900-21998-1-git-send-email-afaerber@suse.de>

Instead of having the parent provide PICCommonClass::init,
let the children override DeviceClass::realize themselves.
This pushes the responsibility of saving and calling the parent's
realizefn to the children.

Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 hw/i386/kvm/i8259.c             | 26 ++++++++++++++++++++++++--
 hw/intc/i8259.c                 | 25 +++++++++++++++++++++----
 hw/intc/i8259_common.c          |  3 ---
 include/hw/isa/i8259_internal.h |  2 +-
 4 files changed, 46 insertions(+), 10 deletions(-)

diff --git a/hw/i386/kvm/i8259.c b/hw/i386/kvm/i8259.c
index 0bfbe34..1250224 100644
--- a/hw/i386/kvm/i8259.c
+++ b/hw/i386/kvm/i8259.c
@@ -14,6 +14,20 @@
 #include "sysemu/kvm.h"
 
 #define TYPE_KVM_I8259 "kvm-i8259"
+#define KVM_PIC_CLASS(class) \
+    OBJECT_CLASS_CHECK(KVMPICClass, (class), TYPE_KVM_I8259)
+#define KVM_PIC_GET_CLASS(obj) \
+    OBJECT_GET_CLASS(KVMPICClass, (obj), TYPE_KVM_I8259)
+
+/**
+ * KVMPICClass:
+ * @parent_realize: The parent's realizefn.
+ */
+typedef struct KVMPICClass {
+    PICCommonClass parent_class;
+
+    DeviceRealize parent_realize;
+} KVMPICClass;
 
 static void kvm_pic_get(PICCommonState *s)
 {
@@ -100,10 +114,15 @@ static void kvm_pic_set_irq(void *opaque, int irq, int level)
     apic_report_irq_delivered(delivered);
 }
 
-static void kvm_pic_init(PICCommonState *s)
+static void kvm_pic_realize(DeviceState *dev, Error **errp)
 {
+    PICCommonState *s = PIC_COMMON(dev);
+    KVMPICClass *kpc = KVM_PIC_GET_CLASS(dev);
+
     memory_region_init_reservation(&s->base_io, "kvm-pic", 2);
     memory_region_init_reservation(&s->elcr_io, "kvm-elcr", 1);
+
+    kpc->parent_realize(dev, errp);
 }
 
 qemu_irq *kvm_i8259_init(ISABus *bus)
@@ -116,11 +135,13 @@ qemu_irq *kvm_i8259_init(ISABus *bus)
 
 static void kvm_i8259_class_init(ObjectClass *klass, void *data)
 {
+    KVMPICClass *kpc = KVM_PIC_CLASS(klass);
     PICCommonClass *k = PIC_COMMON_CLASS(klass);
     DeviceClass *dc = DEVICE_CLASS(klass);
 
     dc->reset     = kvm_pic_reset;
-    k->init       = kvm_pic_init;
+    kpc->parent_realize = dc->realize;
+    dc->realize   = kvm_pic_realize;
     k->pre_save   = kvm_pic_get;
     k->post_load  = kvm_pic_put;
 }
@@ -130,6 +151,7 @@ static const TypeInfo kvm_i8259_info = {
     .parent = TYPE_PIC_COMMON,
     .instance_size = sizeof(PICCommonState),
     .class_init = kvm_i8259_class_init,
+    .class_size = sizeof(KVMPICClass),
 };
 
 static void kvm_pic_register_types(void)
diff --git a/hw/intc/i8259.c b/hw/intc/i8259.c
index 1b513ff..192a0ba 100644
--- a/hw/intc/i8259.c
+++ b/hw/intc/i8259.c
@@ -42,6 +42,18 @@
 //#define DEBUG_IRQ_COUNT
 
 #define TYPE_I8259 "isa-i8259"
+#define PIC_CLASS(class) OBJECT_CLASS_CHECK(PICClass, (class), TYPE_I8259)
+#define PIC_GET_CLASS(obj) OBJECT_GET_CLASS(PICClass, (obj), TYPE_I8259)
+
+/**
+ * PICClass:
+ * @parent_realize: The parent's realizefn.
+ */
+typedef struct PICClass {
+    PICCommonClass parent_class;
+
+    DeviceRealize parent_realize;
+} PICClass;
 
 #if defined(DEBUG_PIC) || defined(DEBUG_IRQ_COUNT)
 static int irq_level[16];
@@ -400,15 +412,18 @@ static const MemoryRegionOps pic_elcr_ioport_ops = {
     },
 };
 
-static void pic_init(PICCommonState *s)
+static void pic_realize(DeviceState *dev, Error **err)
 {
-    DeviceState *dev = DEVICE(s);
+    PICCommonState *s = PIC_COMMON(dev);
+    PICClass *pc = PIC_GET_CLASS(dev);
 
     memory_region_init_io(&s->base_io, &pic_base_ioport_ops, s, "pic", 2);
     memory_region_init_io(&s->elcr_io, &pic_elcr_ioport_ops, s, "elcr", 1);
 
     qdev_init_gpio_out(dev, s->int_out, ARRAY_SIZE(s->int_out));
     qdev_init_gpio_in(dev, pic_set_irq, 8);
+
+    pc->parent_realize(dev, err);
 }
 
 void pic_info(Monitor *mon, const QDict *qdict)
@@ -481,10 +496,11 @@ qemu_irq *i8259_init(ISABus *bus, qemu_irq parent_irq)
 
 static void i8259_class_init(ObjectClass *klass, void *data)
 {
-    PICCommonClass *k = PIC_COMMON_CLASS(klass);
+    PICClass *k = PIC_CLASS(klass);
     DeviceClass *dc = DEVICE_CLASS(klass);
 
-    k->init = pic_init;
+    k->parent_realize = dc->realize;
+    dc->realize = pic_realize;
     dc->reset = pic_reset;
 }
 
@@ -493,6 +509,7 @@ static const TypeInfo i8259_info = {
     .instance_size = sizeof(PICCommonState),
     .parent     = TYPE_PIC_COMMON,
     .class_init = i8259_class_init,
+    .class_size = sizeof(PICClass),
 };
 
 static void pic_register_types(void)
diff --git a/hw/intc/i8259_common.c b/hw/intc/i8259_common.c
index a3dee38..7613547 100644
--- a/hw/intc/i8259_common.c
+++ b/hw/intc/i8259_common.c
@@ -69,9 +69,6 @@ static int pic_dispatch_post_load(void *opaque, int version_id)
 static void pic_common_realize(DeviceState *dev, Error **errp)
 {
     PICCommonState *s = PIC_COMMON(dev);
-    PICCommonClass *info = PIC_COMMON_GET_CLASS(s);
-
-    info->init(s);
 
     isa_register_ioport(NULL, &s->base_io, s->iobase);
     if (s->elcr_addr != -1) {
diff --git a/include/hw/isa/i8259_internal.h b/include/hw/isa/i8259_internal.h
index b4e757a..cded509 100644
--- a/include/hw/isa/i8259_internal.h
+++ b/include/hw/isa/i8259_internal.h
@@ -42,7 +42,7 @@ typedef struct PICCommonState PICCommonState;
 typedef struct PICCommonClass
 {
     ISADeviceClass parent_class;
-    void (*init)(PICCommonState *s);
+
     void (*pre_save)(PICCommonState *s);
     void (*post_load)(PICCommonState *s);
 } PICCommonClass;
-- 
1.8.1.4

  parent reply	other threads:[~2013-06-07 12:58 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-07 12:58 [Qemu-devel] [PATCH v2 00/12] QOM realize for ISA, part 2 Andreas Färber
2013-06-07 12:58 ` [Qemu-devel] [PATCH v2 01/12] gus: QOM'ify some more Andreas Färber
2013-06-07 12:58 ` [Qemu-devel] [PATCH v2 02/12] cs4231a: " Andreas Färber
2013-06-07 12:58 ` [Qemu-devel] [PATCH v2 03/12] isa: Use realizefn for ISADevice Andreas Färber
2013-06-07 12:58 ` [Qemu-devel] [PATCH v2 04/12] i8254: QOM'ify some more Andreas Färber
2013-06-07 12:58 ` [Qemu-devel] [PATCH v2 05/12] kvm/i8254: " Andreas Färber
2013-06-10  1:37   ` li guang
2013-06-10  1:40     ` Andreas Färber
2013-06-10  1:43       ` li guang
2013-06-07 12:58 ` [Qemu-devel] [PATCH v2 06/12] i8254: Convert PITCommonState to QOM realizefn Andreas Färber
2013-06-07 12:58 ` [Qemu-devel] [PATCH v2 07/12] i8259: QOM'ify some more Andreas Färber
2013-06-07 12:58 ` [Qemu-devel] [PATCH v2 08/12] kvm/i8259: " Andreas Färber
2013-06-07 12:58 ` Andreas Färber [this message]
2013-06-07 12:58 ` [Qemu-devel] [PATCH v2 10/12] isa: QOM'ify ISABus Andreas Färber
2013-06-07 12:58 ` [Qemu-devel] [PATCH v2 11/12] isa: QOM'ify ISADevice Andreas Färber
2013-06-07 12:58 ` [Qemu-devel] [PATCH v2 12/12] qdev: Drop FROM_QBUS() macro Andreas Färber
2013-06-07 13:08 ` [Qemu-devel] [PATCH v2 00/12] QOM realize for ISA, part 2 Andreas Färber
2013-06-15 17:55 ` Blue Swirl

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=1370609900-21998-10-git-send-email-afaerber@suse.de \
    --to=afaerber@suse.de \
    --cc=anthony@codemonkey.ws \
    --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).