diff mbox

[v2,07/14] hw/timer: QOM'ify lm32_timer

Message ID 1453863283-7562-8-git-send-email-zxq_yx_007@163.com (mailing list archive)
State New, archived
Headers show

Commit Message

zhao xiao qiang Jan. 27, 2016, 2:54 a.m. UTC
* split lm32_timer_init into lm32_timer_info.instance_init and lm32_timer_realize
* use DeviceClass::realize instead of SysBusDeviceClass::init

Signed-off-by: xiaoqiang zhao <zxq_yx_007@163.com>
---
 hw/timer/lm32_timer.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

Comments

Peter Maydell Feb. 15, 2016, 6:15 p.m. UTC | #1
On 27 January 2016 at 02:54, xiaoqiang zhao <zxq_yx_007@163.com> wrote:
> * split lm32_timer_init into lm32_timer_info.instance_init and lm32_timer_realize
> * use DeviceClass::realize instead of SysBusDeviceClass::init

Long lines again.

> Signed-off-by: xiaoqiang zhao <zxq_yx_007@163.com>
> ---
>  hw/timer/lm32_timer.c | 17 +++++++++++------
>  1 file changed, 11 insertions(+), 6 deletions(-)
>
> diff --git a/hw/timer/lm32_timer.c b/hw/timer/lm32_timer.c
> index d2ab1e7..4ee080a 100644
> --- a/hw/timer/lm32_timer.c
> +++ b/hw/timer/lm32_timer.c
> @@ -175,21 +175,26 @@ static void timer_reset(DeviceState *d)
>      ptimer_stop(s->ptimer);
>  }
>
> -static int lm32_timer_init(SysBusDevice *dev)
> +static void lm32_timer_init(Object *obj)
>  {
> -    LM32TimerState *s = LM32_TIMER(dev);
> +    LM32TimerState *s = LM32_TIMER(obj);
> +    SysBusDevice *dev = SYS_BUS_DEVICE(obj);
>
>      sysbus_init_irq(dev, &s->irq);
>
>      s->bh = qemu_bh_new(timer_hit, s);
>      s->ptimer = ptimer_init(s->bh);
> -    ptimer_set_freq(s->ptimer, s->freq_hz);
>
>      memory_region_init_io(&s->iomem, OBJECT(s), &timer_ops, s,
>                            "timer", R_MAX * 4);
>      sysbus_init_mmio(dev, &s->iomem);
> +}

You could avoid the OBJECT() cast here now.

Otherwise:
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM
diff mbox

Patch

diff --git a/hw/timer/lm32_timer.c b/hw/timer/lm32_timer.c
index d2ab1e7..4ee080a 100644
--- a/hw/timer/lm32_timer.c
+++ b/hw/timer/lm32_timer.c
@@ -175,21 +175,26 @@  static void timer_reset(DeviceState *d)
     ptimer_stop(s->ptimer);
 }
 
-static int lm32_timer_init(SysBusDevice *dev)
+static void lm32_timer_init(Object *obj)
 {
-    LM32TimerState *s = LM32_TIMER(dev);
+    LM32TimerState *s = LM32_TIMER(obj);
+    SysBusDevice *dev = SYS_BUS_DEVICE(obj);
 
     sysbus_init_irq(dev, &s->irq);
 
     s->bh = qemu_bh_new(timer_hit, s);
     s->ptimer = ptimer_init(s->bh);
-    ptimer_set_freq(s->ptimer, s->freq_hz);
 
     memory_region_init_io(&s->iomem, OBJECT(s), &timer_ops, s,
                           "timer", R_MAX * 4);
     sysbus_init_mmio(dev, &s->iomem);
+}
 
-    return 0;
+static void lm32_timer_realize(DeviceState *dev, Error **errp)
+{
+    LM32TimerState *s = LM32_TIMER(dev);
+
+    ptimer_set_freq(s->ptimer, s->freq_hz);
 }
 
 static const VMStateDescription vmstate_lm32_timer = {
@@ -212,9 +217,8 @@  static Property lm32_timer_properties[] = {
 static void lm32_timer_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
-    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
-    k->init = lm32_timer_init;
+    dc->realize = lm32_timer_realize;
     dc->reset = timer_reset;
     dc->vmsd = &vmstate_lm32_timer;
     dc->props = lm32_timer_properties;
@@ -224,6 +228,7 @@  static const TypeInfo lm32_timer_info = {
     .name          = TYPE_LM32_TIMER,
     .parent        = TYPE_SYS_BUS_DEVICE,
     .instance_size = sizeof(LM32TimerState),
+    .instance_init = lm32_timer_init,
     .class_init    = lm32_timer_class_init,
 };