diff mbox

[1/2] intc/openpic: QOM'ify

Message ID 1371520688-24949-2-git-send-email-afaerber@suse.de
State New
Headers show

Commit Message

Andreas Färber June 18, 2013, 1:58 a.m. UTC
Introduce type constant and cast macro.

Signed-off-by: Andreas Färber <afaerber@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(-)

Comments

Peter Crosthwaite June 18, 2013, 3:18 a.m. UTC | #1
On Tue, Jun 18, 2013 at 11:58 AM, Andreas Färber <afaerber@suse.de> wrote:
> Introduce type constant and cast macro.
>
> Signed-off-by: Andreas Färber <afaerber@suse.de>

Reviewed-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>

> ---
>  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(-)
>
> diff --git a/hw/intc/openpic.c b/hw/intc/openpic.c
> index c788714..875c6b8 100644
> --- a/hw/intc/openpic.c
> +++ b/hw/intc/openpic.c
> @@ -255,8 +255,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 */
> @@ -537,7 +542,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;
> @@ -703,7 +708,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;
>      }
>
> @@ -1528,7 +1533,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[] = {
> @@ -1621,7 +1626,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);
> @@ -1647,7 +1652,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 c9ae512..4fdd88e 100644
> --- a/hw/ppc/e500.c
> +++ b/hw/ppc/e500.c
> @@ -565,7 +565,7 @@ void ppce500_init(PPCE500Params *params)
>
>      /* MPIC */
>      mpic = g_new(qemu_irq, 256);
> -    dev = qdev_create(NULL, "openpic");
> +    dev = qdev_create(NULL, TYPE_OPENPIC);
>      qdev_prop_set_uint32(dev, "nb_cpus", smp_cpus);
>      qdev_prop_set_uint32(dev, "model", params->mpic_version);
>      qdev_init_nofail(dev);
> 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 9dcaf0e..9874beb 100644
> --- a/include/hw/ppc/openpic.h
> +++ b/include/hw/ppc/openpic.h
> @@ -1,6 +1,8 @@
>  #if !defined(__OPENPIC_H__)
>  #define __OPENPIC_H__
>
> +#define TYPE_OPENPIC "openpic"
> +
>  /* OpenPIC have 5 outputs per CPU connected and one IRQ out single output */
>  enum {
>      OPENPIC_OUTPUT_INT = 0, /* IRQ                       */
> --
> 1.8.1.4
>
>
diff mbox

Patch

diff --git a/hw/intc/openpic.c b/hw/intc/openpic.c
index c788714..875c6b8 100644
--- a/hw/intc/openpic.c
+++ b/hw/intc/openpic.c
@@ -255,8 +255,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 */
@@ -537,7 +542,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;
@@ -703,7 +708,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;
     }
 
@@ -1528,7 +1533,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[] = {
@@ -1621,7 +1626,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);
@@ -1647,7 +1652,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 c9ae512..4fdd88e 100644
--- a/hw/ppc/e500.c
+++ b/hw/ppc/e500.c
@@ -565,7 +565,7 @@  void ppce500_init(PPCE500Params *params)
 
     /* MPIC */
     mpic = g_new(qemu_irq, 256);
-    dev = qdev_create(NULL, "openpic");
+    dev = qdev_create(NULL, TYPE_OPENPIC);
     qdev_prop_set_uint32(dev, "nb_cpus", smp_cpus);
     qdev_prop_set_uint32(dev, "model", params->mpic_version);
     qdev_init_nofail(dev);
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 9dcaf0e..9874beb 100644
--- a/include/hw/ppc/openpic.h
+++ b/include/hw/ppc/openpic.h
@@ -1,6 +1,8 @@ 
 #if !defined(__OPENPIC_H__)
 #define __OPENPIC_H__
 
+#define TYPE_OPENPIC "openpic"
+
 /* OpenPIC have 5 outputs per CPU connected and one IRQ out single output */
 enum {
     OPENPIC_OUTPUT_INT = 0, /* IRQ                       */