diff options
author | Hu Tao <hutao@cn.fujitsu.com> | 2013-07-01 18:18:37 +0800 |
---|---|---|
committer | Andreas Färber <afaerber@suse.de> | 2013-07-23 00:37:35 +0200 |
commit | 726887ef44d5a822cd76e4fedd269b038869b698 (patch) | |
tree | 8092d6550b0af30d208105d65f9eb449d94c8689 /hw/timer | |
parent | caad4eb345dc5119d326b8af08452cc0f90f8548 (diff) |
hpet: Use QOM realize for hpet
Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
[AF: Avoided SYS_BUS_DEVICE() in loop]
Signed-off-by: Andreas Färber <afaerber@suse.de>
Diffstat (limited to 'hw/timer')
-rw-r--r-- | hw/timer/hpet.c | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/hw/timer/hpet.c b/hw/timer/hpet.c index 228598f345..648b38362d 100644 --- a/hw/timer/hpet.c +++ b/hw/timer/hpet.c @@ -686,8 +686,19 @@ static void hpet_handle_legacy_irq(void *opaque, int n, int level) } } -static int hpet_init(SysBusDevice *dev) +static void hpet_init(Object *obj) { + SysBusDevice *sbd = SYS_BUS_DEVICE(obj); + HPETState *s = HPET(obj); + + /* HPET Area */ + memory_region_init_io(&s->iomem, obj, &hpet_ram_ops, s, "hpet", 0x400); + sysbus_init_mmio(sbd, &s->iomem); +} + +static void hpet_realize(DeviceState *dev, Error **errp) +{ + SysBusDevice *sbd = SYS_BUS_DEVICE(dev); HPETState *s = HPET(dev); int i; HPETTimer *timer; @@ -698,14 +709,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(sbd, &s->irqs[i]); } if (s->num_timers < HPET_MIN_TIMERS) { @@ -725,13 +736,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, OBJECT(s), &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[] = { @@ -743,9 +749,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; @@ -756,6 +761,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, }; |