qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 19/26] hpet: use realize for hpet


From: Hu Tao
Subject: [Qemu-devel] [PATCH 19/26] hpet: use realize for hpet
Date: Sat, 22 Jun 2013 16:50:31 +0800

Cc: Paolo Bonzini <address@hidden>
Cc: Anthony Liguori <address@hidden>
Cc: "Andreas Färber" <address@hidden>
Cc: Avi Kivity <address@hidden>
Signed-off-by: Hu Tao <address@hidden>
---
 hw/timer/hpet.c | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/hw/timer/hpet.c b/hw/timer/hpet.c
index 95dd01d..95aad3a 100644
--- a/hw/timer/hpet.c
+++ b/hw/timer/hpet.c
@@ -679,9 +679,16 @@ static void hpet_handle_legacy_irq(void *opaque, int n, 
int level)
     }
 }
 
-static int hpet_init(SysBusDevice *dev)
+static void hpet_init(Object *obj)
 {
-    HPETState *s = FROM_SYSBUS(HPETState, dev);
+    HPETState *s = DO_UPCAST(HPETState, busdev.qdev.parent_obj, obj);
+
+    memory_region_init_io(&s->iomem, &hpet_ram_ops, s, "hpet", 0x400);
+}
+
+static void hpet_realize(DeviceState *dev, Error **errp)
+{
+    HPETState *s = DO_UPCAST(HPETState, busdev.qdev, dev);
     int i;
     HPETTimer *timer;
 
@@ -691,14 +698,14 @@ static int hpet_init(SysBusDevice *dev)
     }
 
     if (hpet_cfg.count == 8) {
-        fprintf(stderr, "Only 8 instances of HPET is allowed\n");
-        return -1;
+        error_setg(errp, "Only 8 instances of HPET is allowed");
+        return;
     }
 
     s->hpet_id = hpet_cfg.count++;
 
     for (i = 0; i < HPET_NUM_IRQ_ROUTES; i++) {
-        sysbus_init_irq(dev, &s->irqs[i]);
+        sysbus_init_irq(SYS_BUS_DEVICE(dev), &s->irqs[i]);
     }
 
     if (s->num_timers < HPET_MIN_TIMERS) {
@@ -718,13 +725,11 @@ static int hpet_init(SysBusDevice *dev)
     s->capability |= (s->num_timers - 1) << HPET_ID_NUM_TIM_SHIFT;
     s->capability |= ((HPET_CLK_PERIOD) << 32);
 
-    qdev_init_gpio_in(&dev->qdev, hpet_handle_legacy_irq, 2);
-    qdev_init_gpio_out(&dev->qdev, &s->pit_enabled, 1);
+    qdev_init_gpio_in(dev, hpet_handle_legacy_irq, 2);
+    qdev_init_gpio_out(dev, &s->pit_enabled, 1);
 
     /* HPET Area */
-    memory_region_init_io(&s->iomem, &hpet_ram_ops, s, "hpet", 0x400);
-    sysbus_init_mmio(dev, &s->iomem);
-    return 0;
+    sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->iomem);
 }
 
 static Property hpet_device_properties[] = {
@@ -736,9 +741,8 @@ static Property hpet_device_properties[] = {
 static void hpet_device_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
-    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
-    k->init = hpet_init;
+    dc->realize = hpet_realize;
     dc->no_user = 1;
     dc->reset = hpet_reset;
     dc->vmsd = &vmstate_hpet;
@@ -749,6 +753,7 @@ static const TypeInfo hpet_device_info = {
     .name          = "hpet",
     .parent        = TYPE_SYS_BUS_DEVICE,
     .instance_size = sizeof(HPETState),
+    .instance_init = hpet_init,
     .class_init    = hpet_device_class_init,
 };
 
-- 
1.8.3.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]