diff mbox

[06/14] hw/timmer: QOM'ify grlib_gptimer

Message ID 1453805753-27564-7-git-send-email-zxq_yx_007@163.com (mailing list archive)
State New, archived
Headers show

Commit Message

zhao xiao qiang Jan. 26, 2016, 10:55 a.m. UTC
* split grlib_gptimer_init into grlib_gptimer_info.instance_init and grlib_gptimer_realize
* use DeviceClass::realize instead of SysBusDeviceClass::init

Signed-off-by: xiaoqiang zhao <zxq_yx_007@163.com>
---
 hw/timer/grlib_gptimer.c | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)
diff mbox

Patch

diff --git a/hw/timer/grlib_gptimer.c b/hw/timer/grlib_gptimer.c
index d655bb2..0fa63ae 100644
--- a/hw/timer/grlib_gptimer.c
+++ b/hw/timer/grlib_gptimer.c
@@ -347,16 +347,29 @@  static void grlib_gptimer_reset(DeviceState *d)
     }
 }
 
-static int grlib_gptimer_init(SysBusDevice *dev)
+static void grlib_gptimer_init(Object *obj)
 {
-    GPTimerUnit  *unit = GRLIB_GPTIMER(dev);
-    unsigned int  i;
+    GPTimerUnit  *unit = GRLIB_GPTIMER(obj);
+    SysBusDevice *dev = SYS_BUS_DEVICE(obj);
 
     assert(unit->nr_timers > 0);
     assert(unit->nr_timers <= GPTIMER_MAX_TIMERS);
 
     unit->timers = g_malloc0(sizeof unit->timers[0] * unit->nr_timers);
 
+    memory_region_init_io(&unit->iomem, OBJECT(unit), &grlib_gptimer_ops,
+                          unit, "gptimer",
+                          UNIT_REG_SIZE + GPTIMER_REG_SIZE * unit->nr_timers);
+
+    sysbus_init_mmio(dev, &unit->iomem);
+}
+
+static void grlib_gptimer_realize(DeviceState *dev, Error *errp)
+{
+    GPTimerUnit  *unit = GRLIB_GPTIMER(dev);
+    SysBusDevice *dev = SYS_BUS_DEVICE(dev);
+    unsigned int  i;
+
     for (i = 0; i < unit->nr_timers; i++) {
         GPTimer *timer = &unit->timers[i];
 
@@ -370,13 +383,6 @@  static int grlib_gptimer_init(SysBusDevice *dev)
 
         ptimer_set_freq(timer->ptimer, unit->freq_hz);
     }
-
-    memory_region_init_io(&unit->iomem, OBJECT(unit), &grlib_gptimer_ops,
-                          unit, "gptimer",
-                          UNIT_REG_SIZE + GPTIMER_REG_SIZE * unit->nr_timers);
-
-    sysbus_init_mmio(dev, &unit->iomem);
-    return 0;
 }
 
 static Property grlib_gptimer_properties[] = {
@@ -389,9 +395,8 @@  static Property grlib_gptimer_properties[] = {
 static void grlib_gptimer_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
-    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
-    k->init = grlib_gptimer_init;
+    dc->realize = grlib_gptimer_realize;
     dc->reset = grlib_gptimer_reset;
     dc->props = grlib_gptimer_properties;
 }
@@ -400,6 +405,7 @@  static const TypeInfo grlib_gptimer_info = {
     .name          = TYPE_GRLIB_GPTIMER,
     .parent        = TYPE_SYS_BUS_DEVICE,
     .instance_size = sizeof(GPTimerUnit),
+    .instance_init = grlib_gptimer_init,
     .class_init    = grlib_gptimer_class_init,
 };