Signed-off-by: Hu Tao <hu...@cn.fujitsu.com> --- hw/timer/hpet.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-)
diff --git a/hw/timer/hpet.c b/hw/timer/hpet.c index af80e63..731fb92 100644 --- a/hw/timer/hpet.c +++ b/hw/timer/hpet.c @@ -683,7 +683,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 = HPET(obj); + + /* HPET Area */ + memory_region_init_io(&s->iomem, &hpet_ram_ops, s, "hpet", 0x400); + sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->iomem); +} + +static void hpet_realize(DeviceState *dev, Error **errp) { HPETState *s = HPET(dev); int i; @@ -695,14 +704,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) { @@ -722,13 +731,8 @@ 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); - - /* HPET Area */ - memory_region_init_io(&s->iomem, &hpet_ram_ops, s, "hpet", 0x400); - sysbus_init_mmio(dev, &s->iomem); - return 0; + qdev_init_gpio_in(dev, hpet_handle_legacy_irq, 2); + qdev_init_gpio_out(dev, &s->pit_enabled, 1); } static Property hpet_device_properties[] = { @@ -740,9 +744,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; @@ -753,6 +756,7 @@ static const TypeInfo hpet_device_info = { .name = TYPE_HPET, .parent = TYPE_SYS_BUS_DEVICE, .instance_size = sizeof(HPETState), + .instance_init = hpet_init, .class_init = hpet_device_class_init, }; -- 1.8.3.1