diff options
author | Hu Tao <hutao@cn.fujitsu.com> | 2013-07-01 18:18:25 +0800 |
---|---|---|
committer | Andreas Färber <afaerber@suse.de> | 2013-07-23 00:37:35 +0200 |
commit | 940194c2369e50d91d1abf6f36d43853eea5e539 (patch) | |
tree | 9dde6e18037396a222ca25c795efd9057839627b /hw | |
parent | 98bdc0d7ff93f2ab39c0634c744cc7f4a8ac7399 (diff) | |
download | hqemu-940194c2369e50d91d1abf6f36d43853eea5e539.zip hqemu-940194c2369e50d91d1abf6f36d43853eea5e539.tar.gz |
fdc: Use QOM realize for fdc
Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
[AF: Renamed SysBusDevice variable]
Signed-off-by: Andreas Färber <afaerber@suse.de>
Diffstat (limited to 'hw')
-rw-r--r-- | hw/block/fdc.c | 63 |
1 files changed, 41 insertions, 22 deletions
diff --git a/hw/block/fdc.c b/hw/block/fdc.c index e5242bf..9a983fb 100644 --- a/hw/block/fdc.c +++ b/hw/block/fdc.c @@ -2151,39 +2151,58 @@ static void isabus_fdc_realize(DeviceState *dev, Error **errp) add_boot_device_path(isa->bootindexB, dev, "/floppy@1"); } -static int sysbus_fdc_init1(SysBusDevice *dev) +static void sysbus_fdc_initfn(Object *obj) { - FDCtrlSysBus *sys = SYSBUS_FDC(dev); + FDCtrlSysBus *sys = SYSBUS_FDC(obj); FDCtrl *fdctrl = &sys->state; - int ret; - memory_region_init_io(&fdctrl->iomem, OBJECT(sys), &fdctrl_mem_ops, fdctrl, + memory_region_init_io(&fdctrl->iomem, obj, &fdctrl_mem_ops, fdctrl, "fdc", 0x08); - sysbus_init_mmio(dev, &fdctrl->iomem); - sysbus_init_irq(dev, &fdctrl->irq); - qdev_init_gpio_in(DEVICE(dev), fdctrl_handle_tc, 1); +} + +static void sysbus_fdc_realize(DeviceState *dev, Error **errp) +{ + FDCtrlSysBus *sys = SYSBUS_FDC(dev); + FDCtrl *fdctrl = &sys->state; + SysBusDevice *b = SYS_BUS_DEVICE(dev); + + sysbus_init_mmio(b, &fdctrl->iomem); + sysbus_init_irq(b, &fdctrl->irq); + qdev_init_gpio_in(dev, fdctrl_handle_tc, 1); fdctrl->dma_chann = -1; - qdev_set_legacy_instance_id(DEVICE(dev), 0 /* io */, 2); /* FIXME */ - ret = fdctrl_init_common(fdctrl); + qdev_set_legacy_instance_id(dev, 0 /* io */, 2); /* FIXME */ + if (fdctrl_init_common(fdctrl) < 0) { + error_setg(errp, "Floppy init failed."); + return; + } +} - return ret; +static void sun4m_fdc_initfn(Object *obj) +{ + FDCtrlSysBus *sys = SYSBUS_FDC(obj); + FDCtrl *fdctrl = &sys->state; + + memory_region_init_io(&fdctrl->iomem, obj, &fdctrl_mem_strict_ops, + fdctrl, "fdctrl", 0x08); } -static int sun4m_fdc_init1(SysBusDevice *dev) +static void sun4m_fdc_realize(DeviceState *dev, Error **errp) { FDCtrlSysBus *sys = SYSBUS_FDC(dev); FDCtrl *fdctrl = &sys->state; + SysBusDevice *sbd = SYS_BUS_DEVICE(dev); - memory_region_init_io(&fdctrl->iomem, OBJECT(dev), &fdctrl_mem_strict_ops, - fdctrl, "fdctrl", 0x08); - sysbus_init_mmio(dev, &fdctrl->iomem); - sysbus_init_irq(dev, &fdctrl->irq); - qdev_init_gpio_in(DEVICE(dev), fdctrl_handle_tc, 1); + sysbus_init_mmio(sbd, &fdctrl->iomem); + sysbus_init_irq(sbd, &fdctrl->irq); + qdev_init_gpio_in(dev, fdctrl_handle_tc, 1); fdctrl->sun4m = 1; - qdev_set_legacy_instance_id(DEVICE(dev), 0 /* io */, 2); /* FIXME */ - return fdctrl_init_common(fdctrl); + qdev_set_legacy_instance_id(dev, 0 /* io */, 2); /* FIXME */ + if (fdctrl_init_common(fdctrl) < 0) { + error_setg(errp, "Floppy init failed."); + return; + } } FDriveType isa_fdc_get_drive_type(ISADevice *fdc, int i) @@ -2254,9 +2273,8 @@ static Property sysbus_fdc_properties[] = { static void sysbus_fdc_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); - k->init = sysbus_fdc_init1; + dc->realize = sysbus_fdc_realize; dc->reset = fdctrl_external_reset_sysbus; dc->vmsd = &vmstate_sysbus_fdc; dc->props = sysbus_fdc_properties; @@ -2266,6 +2284,7 @@ static const TypeInfo sysbus_fdc_info = { .name = TYPE_SYSBUS_FDC, .parent = TYPE_SYS_BUS_DEVICE, .instance_size = sizeof(FDCtrlSysBus), + .instance_init = sysbus_fdc_initfn, .class_init = sysbus_fdc_class_init, }; @@ -2277,9 +2296,8 @@ static Property sun4m_fdc_properties[] = { static void sun4m_fdc_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); - k->init = sun4m_fdc_init1; + dc->realize = sun4m_fdc_realize; dc->reset = fdctrl_external_reset_sysbus; dc->vmsd = &vmstate_sysbus_fdc; dc->props = sun4m_fdc_properties; @@ -2289,6 +2307,7 @@ static const TypeInfo sun4m_fdc_info = { .name = "SUNW,fdtwo", .parent = TYPE_SYS_BUS_DEVICE, .instance_size = sizeof(FDCtrlSysBus), + .instance_init = sun4m_fdc_initfn, .class_init = sun4m_fdc_class_init, }; |