Patchwork [09/32] intc/openpic: QOM'ify

login
register
mail settings
Submitter Alexander Graf
Date June 30, 2013, 1:44 a.m.
Message ID <1372556709-23868-10-git-send-email-agraf@suse.de>
Download mbox | patch
Permalink /patch/255835/
State New
Headers show

Comments

Alexander Graf - June 30, 2013, 1:44 a.m.
From: Andreas Färber <afaerber@suse.de>

Introduce type constant and cast macro.

Signed-off-by: Andreas Färber <afaerber@suse.de>
Reviewed-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
Signed-off-by: Alexander Graf <agraf@suse.de>
---
 hw/intc/openpic.c        | 17 +++++++++++------
 hw/ppc/e500.c            |  2 +-
 hw/ppc/mac_newworld.c    |  2 +-
 include/hw/ppc/openpic.h |  2 ++
 4 files changed, 15 insertions(+), 8 deletions(-)

Patch

diff --git a/hw/intc/openpic.c b/hw/intc/openpic.c
index ae42149..fc2d104 100644
--- a/hw/intc/openpic.c
+++ b/hw/intc/openpic.c
@@ -251,8 +251,13 @@  typedef struct IRQDest {
     uint32_t outputs_active[OPENPIC_OUTPUT_NB];
 } IRQDest;
 
+#define OPENPIC(obj) OBJECT_CHECK(OpenPICState, (obj), TYPE_OPENPIC)
+
 typedef struct OpenPICState {
-    SysBusDevice busdev;
+    /*< private >*/
+    SysBusDevice parent_obj;
+    /*< public >*/
+
     MemoryRegion mem;
 
     /* Behavior control */
@@ -533,7 +538,7 @@  static void openpic_set_irq(void *opaque, int n_IRQ, int level)
 
 static void openpic_reset(DeviceState *d)
 {
-    OpenPICState *opp = FROM_SYSBUS(typeof(*opp), SYS_BUS_DEVICE(d));
+    OpenPICState *opp = OPENPIC(d);
     int i;
 
     opp->gcr = GCR_RESET;
@@ -699,7 +704,7 @@  static void openpic_gcr_write(OpenPICState *opp, uint64_t val)
     bool mpic_proxy = false;
 
     if (val & GCR_RESET) {
-        openpic_reset(&opp->busdev.qdev);
+        openpic_reset(DEVICE(opp));
         return;
     }
 
@@ -1524,7 +1529,7 @@  static void map_list(OpenPICState *opp, const MemReg *list, int *count)
 
 static int openpic_init(SysBusDevice *dev)
 {
-    OpenPICState *opp = FROM_SYSBUS(typeof (*opp), dev);
+    OpenPICState *opp = OPENPIC(dev);
     int i, j;
     int list_count = 0;
     static const MemReg list_le[] = {
@@ -1617,7 +1622,7 @@  static int openpic_init(SysBusDevice *dev)
         }
     }
 
-    register_savevm(&opp->busdev.qdev, "openpic", 0, 2,
+    register_savevm(DEVICE(opp), "openpic", 0, 2,
                     openpic_save, openpic_load, opp);
 
     sysbus_init_mmio(dev, &opp->mem);
@@ -1643,7 +1648,7 @@  static void openpic_class_init(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo openpic_info = {
-    .name          = "openpic",
+    .name          = TYPE_OPENPIC,
     .parent        = TYPE_SYS_BUS_DEVICE,
     .instance_size = sizeof(OpenPICState),
     .class_init    = openpic_class_init,
diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c
index d38a688..3797fbc 100644
--- a/hw/ppc/e500.c
+++ b/hw/ppc/e500.c
@@ -479,7 +479,7 @@  static DeviceState *ppce500_init_mpic_qemu(PPCE500Params *params,
     SysBusDevice *s;
     int i, j, k;
 
-    dev = qdev_create(NULL, "openpic");
+    dev = qdev_create(NULL, TYPE_OPENPIC);
     qdev_prop_set_uint32(dev, "model", params->mpic_version);
     qdev_prop_set_uint32(dev, "nb_cpus", smp_cpus);
 
diff --git a/hw/ppc/mac_newworld.c b/hw/ppc/mac_newworld.c
index ce44e95..61c25a4 100644
--- a/hw/ppc/mac_newworld.c
+++ b/hw/ppc/mac_newworld.c
@@ -329,7 +329,7 @@  static void ppc_core99_init(QEMUMachineInitArgs *args)
 
     pic = g_new(qemu_irq, 64);
 
-    dev = qdev_create(NULL, "openpic");
+    dev = qdev_create(NULL, TYPE_OPENPIC);
     qdev_prop_set_uint32(dev, "model", OPENPIC_MODEL_RAVEN);
     qdev_init_nofail(dev);
     s = SYS_BUS_DEVICE(dev);
diff --git a/include/hw/ppc/openpic.h b/include/hw/ppc/openpic.h
index 1fe4865..ef3f5c3 100644
--- a/include/hw/ppc/openpic.h
+++ b/include/hw/ppc/openpic.h
@@ -4,6 +4,8 @@ 
 #include "qemu-common.h"
 #include "hw/qdev.h"
 
+#define TYPE_OPENPIC "openpic"
+
 /* OpenPIC have 5 outputs per CPU connected and one IRQ out single output */
 enum {
     OPENPIC_OUTPUT_INT = 0, /* IRQ                       */