diff options
author | Andreas Färber <afaerber@suse.de> | 2012-11-25 02:37:14 +0100 |
---|---|---|
committer | Andreas Färber <afaerber@suse.de> | 2013-06-07 12:14:45 +0200 |
commit | db895a1e6a97e919f9b86d60c969377357b05066 (patch) | |
tree | 72f6786abe90f7fa77d2f10416df73cb9d62e35a /hw/timer | |
parent | a3dcca567a1d4a5c79fb9c8fe2d9a21a4a7cebd5 (diff) |
isa: Use realizefn for ISADevice
Drop ISADeviceClass::init and the resulting no-op initfn and let
children implement their own realizefn. Adapt error handling.
Split off an instance_init where sensible.
Signed-off-by: Andreas Färber <afaerber@suse.de>
Diffstat (limited to 'hw/timer')
-rw-r--r-- | hw/timer/i8254_common.c | 15 | ||||
-rw-r--r-- | hw/timer/m48t59.c | 22 | ||||
-rw-r--r-- | hw/timer/mc146818rtc.c | 18 |
3 files changed, 29 insertions, 26 deletions
diff --git a/hw/timer/i8254_common.c b/hw/timer/i8254_common.c index 5342df4a34..36eed80ed0 100644 --- a/hw/timer/i8254_common.c +++ b/hw/timer/i8254_common.c @@ -166,22 +166,22 @@ void pit_reset_common(PITCommonState *pit) } } -static int pit_init_common(ISADevice *dev) +static void pit_common_realize(DeviceState *dev, Error **errp) { + ISADevice *isadev = ISA_DEVICE(dev); PITCommonState *pit = PIT_COMMON(dev); PITCommonClass *c = PIT_COMMON_GET_CLASS(pit); int ret; ret = c->init(pit); if (ret < 0) { - return ret; + error_setg(errp, "PIT init failed."); + return; } - isa_register_ioport(dev, &pit->ioports, pit->iobase); + isa_register_ioport(isadev, &pit->ioports, pit->iobase); - qdev_set_legacy_instance_id(&dev->qdev, pit->iobase, 2); - - return 0; + qdev_set_legacy_instance_id(dev, pit->iobase, 2); } static const VMStateDescription vmstate_pit_channel = { @@ -286,10 +286,9 @@ static const VMStateDescription vmstate_pit_common = { static void pit_common_class_init(ObjectClass *klass, void *data) { - ISADeviceClass *ic = ISA_DEVICE_CLASS(klass); DeviceClass *dc = DEVICE_CLASS(klass); - ic->init = pit_init_common; + dc->realize = pit_common_realize; dc->vmsd = &vmstate_pit_common; dc->no_user = 1; } diff --git a/hw/timer/m48t59.c b/hw/timer/m48t59.c index 45753d88c5..bf6c4c876c 100644 --- a/hw/timer/m48t59.c +++ b/hw/timer/m48t59.c @@ -691,7 +691,7 @@ M48t59State *m48t59_init_isa(ISABus *bus, uint32_t io_base, uint16_t size, return s; } -static void m48t59_init_common(M48t59State *s) +static void m48t59_realize_common(M48t59State *s, Error **errp) { s->buffer = g_malloc0(s->size); if (s->model == 59) { @@ -703,27 +703,31 @@ static void m48t59_init_common(M48t59State *s) vmstate_register(NULL, -1, &vmstate_m48t59, s); } -static int m48t59_init_isa1(ISADevice *dev) +static void m48t59_isa_realize(DeviceState *dev, Error **errp) { + ISADevice *isadev = ISA_DEVICE(dev); M48t59ISAState *d = ISA_M48T59(dev); M48t59State *s = &d->state; - isa_init_irq(dev, &s->IRQ, 8); - m48t59_init_common(s); - - return 0; + isa_init_irq(isadev, &s->IRQ, 8); + m48t59_realize_common(s, errp); } static int m48t59_init1(SysBusDevice *dev) { M48t59SysBusState *d = FROM_SYSBUS(M48t59SysBusState, dev); M48t59State *s = &d->state; + Error *err = NULL; sysbus_init_irq(dev, &s->IRQ); memory_region_init_io(&s->iomem, &nvram_ops, s, "m48t59.nvram", s->size); sysbus_init_mmio(dev, &s->iomem); - m48t59_init_common(s); + m48t59_realize_common(s, &err); + if (err != NULL) { + error_free(err); + return -1; + } return 0; } @@ -738,8 +742,8 @@ static Property m48t59_isa_properties[] = { static void m48t59_isa_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - ISADeviceClass *ic = ISA_DEVICE_CLASS(klass); - ic->init = m48t59_init_isa1; + + dc->realize = m48t59_isa_realize; dc->no_user = 1; dc->reset = m48t59_reset_isa; dc->props = m48t59_isa_properties; diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c index 481604de35..9c4a7bd074 100644 --- a/hw/timer/mc146818rtc.c +++ b/hw/timer/mc146818rtc.c @@ -814,8 +814,9 @@ static void rtc_get_date(Object *obj, Visitor *v, void *opaque, visit_end_struct(v, errp); } -static int rtc_initfn(ISADevice *dev) +static void rtc_realizefn(DeviceState *dev, Error **errp) { + ISADevice *isadev = ISA_DEVICE(dev); RTCState *s = MC146818_RTC(dev); int base = 0x70; @@ -836,7 +837,7 @@ static int rtc_initfn(ISADevice *dev) s->base_year = 0; } - rtc_set_date_from_host(dev); + rtc_set_date_from_host(isadev); #ifdef TARGET_I386 switch (s->lost_tick_policy) { @@ -847,7 +848,8 @@ static int rtc_initfn(ISADevice *dev) case LOST_TICK_DISCARD: break; default: - return -EINVAL; + error_setg(errp, "Invalid lost tick policy."); + return; } #endif @@ -862,15 +864,13 @@ static int rtc_initfn(ISADevice *dev) qemu_register_suspend_notifier(&s->suspend_notifier); memory_region_init_io(&s->io, &cmos_ops, s, "rtc", 2); - isa_register_ioport(dev, &s->io, base); + isa_register_ioport(isadev, &s->io, base); - qdev_set_legacy_instance_id(&dev->qdev, base, 3); + qdev_set_legacy_instance_id(dev, base, 3); qemu_register_reset(rtc_reset, s); object_property_add(OBJECT(s), "date", "struct tm", rtc_get_date, NULL, NULL, s, NULL); - - return 0; } ISADevice *rtc_init(ISABus *bus, int base_year, qemu_irq intercept_irq) @@ -902,8 +902,8 @@ static Property mc146818rtc_properties[] = { static void rtc_class_initfn(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - ISADeviceClass *ic = ISA_DEVICE_CLASS(klass); - ic->init = rtc_initfn; + + dc->realize = rtc_realizefn; dc->no_user = 1; dc->vmsd = &vmstate_rtc; dc->props = mc146818rtc_properties; |