Message ID | 20170205133727.23424-3-zxq_yx_007@163.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On 02/05/2017 10:37 AM, xiaoqiang zhao wrote: > Drop the old SysBus init function and use instance_init > and an realize function > > Signed-off-by: xiaoqiang zhao <zxq_yx_007@163.com> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> > --- > hw/dma/sparc32_dma.c | 25 +++++++++++++++---------- > 1 file changed, 15 insertions(+), 10 deletions(-) > > diff --git a/hw/dma/sparc32_dma.c b/hw/dma/sparc32_dma.c > index 9d545e412e..ef4c6a93c8 100644 > --- a/hw/dma/sparc32_dma.c > +++ b/hw/dma/sparc32_dma.c > @@ -270,23 +270,28 @@ static const VMStateDescription vmstate_dma = { > } > }; > > -static int sparc32_dma_init1(SysBusDevice *sbd) > +static void sparc32_dma_init(Object *obj) > { > - DeviceState *dev = DEVICE(sbd); > - DMAState *s = SPARC32_DMA(dev); > - int reg_size; > + DeviceState *dev = DEVICE(obj); > + DMAState *s = SPARC32_DMA(obj); > + SysBusDevice *sbd = SYS_BUS_DEVICE(obj); > > sysbus_init_irq(sbd, &s->irq); > > - reg_size = s->is_ledma ? DMA_ETH_SIZE : DMA_SIZE; > - memory_region_init_io(&s->iomem, OBJECT(s), &dma_mem_ops, s, > - "dma", reg_size); > sysbus_init_mmio(sbd, &s->iomem); > > qdev_init_gpio_in(dev, dma_set_irq, 1); > qdev_init_gpio_out(dev, s->gpio, 2); > +} > > - return 0; > +static void sparc32_dma_realize(DeviceState *dev, Error **errp) > +{ > + DMAState *s = SPARC32_DMA(dev); > + int reg_size; > + > + reg_size = s->is_ledma ? DMA_ETH_SIZE : DMA_SIZE; > + memory_region_init_io(&s->iomem, OBJECT(dev), &dma_mem_ops, s, > + "dma", reg_size); > } > > static Property sparc32_dma_properties[] = { > @@ -298,12 +303,11 @@ static Property sparc32_dma_properties[] = { > static void sparc32_dma_class_init(ObjectClass *klass, void *data) > { > DeviceClass *dc = DEVICE_CLASS(klass); > - SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); > > - k->init = sparc32_dma_init1; > dc->reset = dma_reset; > dc->vmsd = &vmstate_dma; > dc->props = sparc32_dma_properties; > + dc->realize = sparc32_dma_realize; > /* Reason: pointer property "iommu_opaque" */ > dc->cannot_instantiate_with_device_add_yet = true; > } > @@ -312,6 +316,7 @@ static const TypeInfo sparc32_dma_info = { > .name = TYPE_SPARC32_DMA, > .parent = TYPE_SYS_BUS_DEVICE, > .instance_size = sizeof(DMAState), > + .instance_init = sparc32_dma_init, > .class_init = sparc32_dma_class_init, > }; > >
diff --git a/hw/dma/sparc32_dma.c b/hw/dma/sparc32_dma.c index 9d545e412e..ef4c6a93c8 100644 --- a/hw/dma/sparc32_dma.c +++ b/hw/dma/sparc32_dma.c @@ -270,23 +270,28 @@ static const VMStateDescription vmstate_dma = { } }; -static int sparc32_dma_init1(SysBusDevice *sbd) +static void sparc32_dma_init(Object *obj) { - DeviceState *dev = DEVICE(sbd); - DMAState *s = SPARC32_DMA(dev); - int reg_size; + DeviceState *dev = DEVICE(obj); + DMAState *s = SPARC32_DMA(obj); + SysBusDevice *sbd = SYS_BUS_DEVICE(obj); sysbus_init_irq(sbd, &s->irq); - reg_size = s->is_ledma ? DMA_ETH_SIZE : DMA_SIZE; - memory_region_init_io(&s->iomem, OBJECT(s), &dma_mem_ops, s, - "dma", reg_size); sysbus_init_mmio(sbd, &s->iomem); qdev_init_gpio_in(dev, dma_set_irq, 1); qdev_init_gpio_out(dev, s->gpio, 2); +} - return 0; +static void sparc32_dma_realize(DeviceState *dev, Error **errp) +{ + DMAState *s = SPARC32_DMA(dev); + int reg_size; + + reg_size = s->is_ledma ? DMA_ETH_SIZE : DMA_SIZE; + memory_region_init_io(&s->iomem, OBJECT(dev), &dma_mem_ops, s, + "dma", reg_size); } static Property sparc32_dma_properties[] = { @@ -298,12 +303,11 @@ static Property sparc32_dma_properties[] = { static void sparc32_dma_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); - k->init = sparc32_dma_init1; dc->reset = dma_reset; dc->vmsd = &vmstate_dma; dc->props = sparc32_dma_properties; + dc->realize = sparc32_dma_realize; /* Reason: pointer property "iommu_opaque" */ dc->cannot_instantiate_with_device_add_yet = true; } @@ -312,6 +316,7 @@ static const TypeInfo sparc32_dma_info = { .name = TYPE_SPARC32_DMA, .parent = TYPE_SYS_BUS_DEVICE, .instance_size = sizeof(DMAState), + .instance_init = sparc32_dma_init, .class_init = sparc32_dma_class_init, };
Drop the old SysBus init function and use instance_init and an realize function Signed-off-by: xiaoqiang zhao <zxq_yx_007@163.com> --- hw/dma/sparc32_dma.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-)