diff mbox

[RFC,06/15] timer/arm_mptimer: QOM cast cleanup

Message ID 1372626065-6043-7-git-send-email-afaerber@suse.de
State New
Headers show

Commit Message

Andreas Färber June 30, 2013, 9 p.m. UTC
From: Andreas Färber <andreas.faerber@web.de>

Introduce type constant and cast macro and rename
ARMMPTimerState::busdev to enforce its use.

Signed-off-by: Andreas Färber <andreas.faerber@web.de>
---
 hw/timer/arm_mptimer.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

Comments

Peter Crosthwaite July 1, 2013, 9:29 a.m. UTC | #1
On Mon, Jul 1, 2013 at 7:00 AM, Andreas Färber <afaerber@suse.de> wrote:
> From: Andreas Färber <andreas.faerber@web.de>
>
> Introduce type constant and cast macro and rename
> ARMMPTimerState::busdev to enforce its use.
>
> Signed-off-by: Andreas Färber <andreas.faerber@web.de>
> ---
>  hw/timer/arm_mptimer.c | 18 +++++++++++++-----
>  1 file changed, 13 insertions(+), 5 deletions(-)
>
> diff --git a/hw/timer/arm_mptimer.c b/hw/timer/arm_mptimer.c
> index 317f5e4..588e34b 100644
> --- a/hw/timer/arm_mptimer.c
> +++ b/hw/timer/arm_mptimer.c
> @@ -40,8 +40,15 @@ typedef struct {
>      MemoryRegion iomem;
>  } TimerBlock;
>
> +#define TYPE_ARM_MP_TIMER "arm_mptimer"

The _ in "MP_TIMER" seems inconsistent with the type string and
"A9MPCORE" as introduced in P1.

Regards,
Peter

> +#define ARM_MP_TIMER(obj) \
> +    OBJECT_CHECK(ARMMPTimerState, (obj), TYPE_ARM_MP_TIMER)
> +
>  typedef struct {
> -    SysBusDevice busdev;
> +    /*< private >*/
> +    SysBusDevice parent_obj;
> +    /*< public >*/
> +
>      uint32_t num_cpu;
>      TimerBlock timerblock[MAX_CPUS];
>      MemoryRegion iomem;
> @@ -211,9 +218,9 @@ static void timerblock_reset(TimerBlock *tb)
>
>  static void arm_mptimer_reset(DeviceState *dev)
>  {
> -    ARMMPTimerState *s =
> -        FROM_SYSBUS(ARMMPTimerState, SYS_BUS_DEVICE(dev));
> +    ARMMPTimerState *s = ARM_MP_TIMER(dev);
>      int i;
> +
>      for (i = 0; i < ARRAY_SIZE(s->timerblock); i++) {
>          timerblock_reset(&s->timerblock[i]);
>      }
> @@ -221,8 +228,9 @@ static void arm_mptimer_reset(DeviceState *dev)
>
>  static int arm_mptimer_init(SysBusDevice *dev)
>  {
> -    ARMMPTimerState *s = FROM_SYSBUS(ARMMPTimerState, dev);
> +    ARMMPTimerState *s = ARM_MP_TIMER(dev);
>      int i;
> +
>      if (s->num_cpu < 1 || s->num_cpu > MAX_CPUS) {
>          hw_error("%s: num-cpu must be between 1 and %d\n", __func__, MAX_CPUS);
>      }
> @@ -295,7 +303,7 @@ static void arm_mptimer_class_init(ObjectClass *klass, void *data)
>  }
>
>  static const TypeInfo arm_mptimer_info = {
> -    .name          = "arm_mptimer",
> +    .name          = TYPE_ARM_MP_TIMER,
>      .parent        = TYPE_SYS_BUS_DEVICE,
>      .instance_size = sizeof(ARMMPTimerState),
>      .class_init    = arm_mptimer_class_init,
> --
> 1.8.1.4
>
>
Andreas Färber July 6, 2013, 1:16 p.m. UTC | #2
Am 01.07.2013 11:29, schrieb Peter Crosthwaite:
> On Mon, Jul 1, 2013 at 7:00 AM, Andreas Färber <afaerber@suse.de> wrote:
>> From: Andreas Färber <andreas.faerber@web.de>
>>
>> Introduce type constant and cast macro and rename
>> ARMMPTimerState::busdev to enforce its use.
>>
>> Signed-off-by: Andreas Färber <andreas.faerber@web.de>
>> ---
>>  hw/timer/arm_mptimer.c | 18 +++++++++++++-----
>>  1 file changed, 13 insertions(+), 5 deletions(-)
>>
>> diff --git a/hw/timer/arm_mptimer.c b/hw/timer/arm_mptimer.c
>> index 317f5e4..588e34b 100644
>> --- a/hw/timer/arm_mptimer.c
>> +++ b/hw/timer/arm_mptimer.c
>> @@ -40,8 +40,15 @@ typedef struct {
>>      MemoryRegion iomem;
>>  } TimerBlock;
>>
>> +#define TYPE_ARM_MP_TIMER "arm_mptimer"
> 
> The _ in "MP_TIMER" seems inconsistent with the type string and
> "A9MPCORE" as introduced in P1.

It is consistent with "PC_NET" though. ;) I can surely change it to
"MPTIMER" if preferred.

Cheers,
Andreas
diff mbox

Patch

diff --git a/hw/timer/arm_mptimer.c b/hw/timer/arm_mptimer.c
index 317f5e4..588e34b 100644
--- a/hw/timer/arm_mptimer.c
+++ b/hw/timer/arm_mptimer.c
@@ -40,8 +40,15 @@  typedef struct {
     MemoryRegion iomem;
 } TimerBlock;
 
+#define TYPE_ARM_MP_TIMER "arm_mptimer"
+#define ARM_MP_TIMER(obj) \
+    OBJECT_CHECK(ARMMPTimerState, (obj), TYPE_ARM_MP_TIMER)
+
 typedef struct {
-    SysBusDevice busdev;
+    /*< private >*/
+    SysBusDevice parent_obj;
+    /*< public >*/
+
     uint32_t num_cpu;
     TimerBlock timerblock[MAX_CPUS];
     MemoryRegion iomem;
@@ -211,9 +218,9 @@  static void timerblock_reset(TimerBlock *tb)
 
 static void arm_mptimer_reset(DeviceState *dev)
 {
-    ARMMPTimerState *s =
-        FROM_SYSBUS(ARMMPTimerState, SYS_BUS_DEVICE(dev));
+    ARMMPTimerState *s = ARM_MP_TIMER(dev);
     int i;
+
     for (i = 0; i < ARRAY_SIZE(s->timerblock); i++) {
         timerblock_reset(&s->timerblock[i]);
     }
@@ -221,8 +228,9 @@  static void arm_mptimer_reset(DeviceState *dev)
 
 static int arm_mptimer_init(SysBusDevice *dev)
 {
-    ARMMPTimerState *s = FROM_SYSBUS(ARMMPTimerState, dev);
+    ARMMPTimerState *s = ARM_MP_TIMER(dev);
     int i;
+
     if (s->num_cpu < 1 || s->num_cpu > MAX_CPUS) {
         hw_error("%s: num-cpu must be between 1 and %d\n", __func__, MAX_CPUS);
     }
@@ -295,7 +303,7 @@  static void arm_mptimer_class_init(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo arm_mptimer_info = {
-    .name          = "arm_mptimer",
+    .name          = TYPE_ARM_MP_TIMER,
     .parent        = TYPE_SYS_BUS_DEVICE,
     .instance_size = sizeof(ARMMPTimerState),
     .class_init    = arm_mptimer_class_init,