Message ID | 20170429104937.31341-6-zxq_yx_007@163.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On 04/29/2017 07:49 AM, xiaoqiang zhao wrote: > * split the old SysBus init function into an instance_init > and a Device realize function > * use DeviceClass::realize instead of SysBusDeviceClass::init > > Signed-off-by: xiaoqiang zhao <zxq_yx_007@163.com> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> > --- > hw/timer/m48t59.c | 35 ++++++++++++++++++----------------- > 1 file changed, 18 insertions(+), 17 deletions(-) > > diff --git a/hw/timer/m48t59.c b/hw/timer/m48t59.c > index 474981a6ac..eff259ef96 100644 > --- a/hw/timer/m48t59.c > +++ b/hw/timer/m48t59.c > @@ -644,30 +644,31 @@ void m48t59_realize_common(M48t59State *s, Error **errp) > vmstate_register(NULL, -1, &vmstate_m48t59, s); > } > > -static int m48t59_init1(SysBusDevice *dev) > +static void m48t59_init1(Object *obj) > { > - M48txxSysBusDeviceClass *u = M48TXX_SYS_BUS_GET_CLASS(dev); > - M48txxSysBusState *d = M48TXX_SYS_BUS(dev); > - Object *o = OBJECT(dev); > + M48txxSysBusDeviceClass *u = M48TXX_SYS_BUS_GET_CLASS(obj); > + M48txxSysBusState *d = M48TXX_SYS_BUS(obj); > + SysBusDevice *dev = SYS_BUS_DEVICE(obj); > M48t59State *s = &d->state; > - Error *err = NULL; > > s->model = u->info.model; > s->size = u->info.size; > sysbus_init_irq(dev, &s->IRQ); > > - memory_region_init_io(&s->iomem, o, &nvram_ops, s, "m48t59.nvram", > + memory_region_init_io(&s->iomem, obj, &nvram_ops, s, "m48t59.nvram", > s->size); > - memory_region_init_io(&d->io, o, &m48t59_io_ops, s, "m48t59", 4); > - sysbus_init_mmio(dev, &s->iomem); > - sysbus_init_mmio(dev, &d->io); > - m48t59_realize_common(s, &err); > - if (err != NULL) { > - error_free(err); > - return -1; > - } > + memory_region_init_io(&d->io, obj, &m48t59_io_ops, s, "m48t59", 4); > +} > + > +static void m48t59_realize(DeviceState *dev, Error **errp) > +{ > + M48txxSysBusState *d = M48TXX_SYS_BUS(dev); > + M48t59State *s = &d->state; > + SysBusDevice *sbd = SYS_BUS_DEVICE(dev); > > - return 0; > + sysbus_init_mmio(sbd, &s->iomem); > + sysbus_init_mmio(sbd, &d->io); > + m48t59_realize_common(s, errp); > } > > static uint32_t m48txx_sysbus_read(Nvram *obj, uint32_t addr) > @@ -696,10 +697,9 @@ static Property m48t59_sysbus_properties[] = { > static void m48txx_sysbus_class_init(ObjectClass *klass, void *data) > { > DeviceClass *dc = DEVICE_CLASS(klass); > - SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); > NvramClass *nc = NVRAM_CLASS(klass); > > - k->init = m48t59_init1; > + dc->realize = m48t59_realize; > dc->reset = m48t59_reset_sysbus; > dc->props = m48t59_sysbus_properties; > nc->read = m48txx_sysbus_read; > @@ -725,6 +725,7 @@ static const TypeInfo m48txx_sysbus_type_info = { > .name = TYPE_M48TXX_SYS_BUS, > .parent = TYPE_SYS_BUS_DEVICE, > .instance_size = sizeof(M48txxSysBusState), > + .instance_init = m48t59_init1, > .abstract = true, > .class_init = m48txx_sysbus_class_init, > .interfaces = (InterfaceInfo[]) { >
diff --git a/hw/timer/m48t59.c b/hw/timer/m48t59.c index 474981a6ac..eff259ef96 100644 --- a/hw/timer/m48t59.c +++ b/hw/timer/m48t59.c @@ -644,30 +644,31 @@ void m48t59_realize_common(M48t59State *s, Error **errp) vmstate_register(NULL, -1, &vmstate_m48t59, s); } -static int m48t59_init1(SysBusDevice *dev) +static void m48t59_init1(Object *obj) { - M48txxSysBusDeviceClass *u = M48TXX_SYS_BUS_GET_CLASS(dev); - M48txxSysBusState *d = M48TXX_SYS_BUS(dev); - Object *o = OBJECT(dev); + M48txxSysBusDeviceClass *u = M48TXX_SYS_BUS_GET_CLASS(obj); + M48txxSysBusState *d = M48TXX_SYS_BUS(obj); + SysBusDevice *dev = SYS_BUS_DEVICE(obj); M48t59State *s = &d->state; - Error *err = NULL; s->model = u->info.model; s->size = u->info.size; sysbus_init_irq(dev, &s->IRQ); - memory_region_init_io(&s->iomem, o, &nvram_ops, s, "m48t59.nvram", + memory_region_init_io(&s->iomem, obj, &nvram_ops, s, "m48t59.nvram", s->size); - memory_region_init_io(&d->io, o, &m48t59_io_ops, s, "m48t59", 4); - sysbus_init_mmio(dev, &s->iomem); - sysbus_init_mmio(dev, &d->io); - m48t59_realize_common(s, &err); - if (err != NULL) { - error_free(err); - return -1; - } + memory_region_init_io(&d->io, obj, &m48t59_io_ops, s, "m48t59", 4); +} + +static void m48t59_realize(DeviceState *dev, Error **errp) +{ + M48txxSysBusState *d = M48TXX_SYS_BUS(dev); + M48t59State *s = &d->state; + SysBusDevice *sbd = SYS_BUS_DEVICE(dev); - return 0; + sysbus_init_mmio(sbd, &s->iomem); + sysbus_init_mmio(sbd, &d->io); + m48t59_realize_common(s, errp); } static uint32_t m48txx_sysbus_read(Nvram *obj, uint32_t addr) @@ -696,10 +697,9 @@ static Property m48t59_sysbus_properties[] = { static void m48txx_sysbus_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); NvramClass *nc = NVRAM_CLASS(klass); - k->init = m48t59_init1; + dc->realize = m48t59_realize; dc->reset = m48t59_reset_sysbus; dc->props = m48t59_sysbus_properties; nc->read = m48txx_sysbus_read; @@ -725,6 +725,7 @@ static const TypeInfo m48txx_sysbus_type_info = { .name = TYPE_M48TXX_SYS_BUS, .parent = TYPE_SYS_BUS_DEVICE, .instance_size = sizeof(M48txxSysBusState), + .instance_init = m48t59_init1, .abstract = true, .class_init = m48txx_sysbus_class_init, .interfaces = (InterfaceInfo[]) {
* split the old SysBus init function into an instance_init and a Device realize function * use DeviceClass::realize instead of SysBusDeviceClass::init Signed-off-by: xiaoqiang zhao <zxq_yx_007@163.com> --- hw/timer/m48t59.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-)