diff mbox series

[2/6] sparc32-ledma: use object_initialize_child() for lance child object

Message ID 20200920082018.16135-3-mark.cave-ayland@ilande.co.uk
State New
Headers show
Series QOM minor fixes | expand

Commit Message

Mark Cave-Ayland Sept. 20, 2020, 8:20 a.m. UTC
Store the child object directly within the sparc32-ledma object rather than
using link properties.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
 hw/dma/sparc32_dma.c           | 14 ++++++++------
 include/hw/sparc/sparc32_dma.h |  2 +-
 2 files changed, 9 insertions(+), 7 deletions(-)

Comments

Philippe Mathieu-Daudé Sept. 20, 2020, 10:49 a.m. UTC | #1
On 9/20/20 10:20 AM, Mark Cave-Ayland wrote:
> Store the child object directly within the sparc32-ledma object rather than

> using link properties.

> 

> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>


Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>


> ---

>  hw/dma/sparc32_dma.c           | 14 ++++++++------

>  include/hw/sparc/sparc32_dma.h |  2 +-

>  2 files changed, 9 insertions(+), 7 deletions(-)

> 

> diff --git a/hw/dma/sparc32_dma.c b/hw/dma/sparc32_dma.c

> index b25a212f7a..84196afb95 100644

> --- a/hw/dma/sparc32_dma.c

> +++ b/hw/dma/sparc32_dma.c

> @@ -331,24 +331,26 @@ static const TypeInfo sparc32_espdma_device_info = {

>  static void sparc32_ledma_device_init(Object *obj)

>  {

>      DMADeviceState *s = SPARC32_DMA_DEVICE(obj);

> +    LEDMADeviceState *ls = SPARC32_LEDMA_DEVICE(obj);

>  

>      memory_region_init_io(&s->iomem, OBJECT(s), &dma_mem_ops, s,

>                            "ledma-mmio", DMA_SIZE);

> +

> +    object_initialize_child(obj, "lance", &ls->lance, TYPE_LANCE);

>  }

>  

>  static void sparc32_ledma_device_realize(DeviceState *dev, Error **errp)

>  {

> -    DeviceState *d;

> +    LEDMADeviceState *s = SPARC32_LEDMA_DEVICE(dev);

> +    SysBusPCNetState *lance = SYSBUS_PCNET(&s->lance);

>      NICInfo *nd = &nd_table[0];

>  

>      /* FIXME use qdev NIC properties instead of nd_table[] */

>      qemu_check_nic_model(nd, TYPE_LANCE);

>  

> -    d = qdev_new(TYPE_LANCE);

> -    object_property_add_child(OBJECT(dev), "lance", OBJECT(d));

> -    qdev_set_nic_properties(d, nd);

> -    object_property_set_link(OBJECT(d), "dma", OBJECT(dev), &error_abort);

> -    sysbus_realize_and_unref(SYS_BUS_DEVICE(d), &error_fatal);

> +    qdev_set_nic_properties(DEVICE(lance), nd);

> +    object_property_set_link(OBJECT(lance), "dma", OBJECT(dev), &error_abort);

> +    sysbus_realize(SYS_BUS_DEVICE(lance), &error_fatal);

>  }

>  

>  static void sparc32_ledma_device_class_init(ObjectClass *klass, void *data)

> diff --git a/include/hw/sparc/sparc32_dma.h b/include/hw/sparc/sparc32_dma.h

> index a7b1dd8418..f2bfe272ba 100644

> --- a/include/hw/sparc/sparc32_dma.h

> +++ b/include/hw/sparc/sparc32_dma.h

> @@ -43,7 +43,7 @@ DECLARE_INSTANCE_CHECKER(LEDMADeviceState, SPARC32_LEDMA_DEVICE,

>  struct LEDMADeviceState {

>      DMADeviceState parent_obj;

>  

> -    SysBusPCNetState *lance;

> +    SysBusPCNetState lance;

>  };

>  

>  #define TYPE_SPARC32_DMA "sparc32-dma"

>
diff mbox series

Patch

diff --git a/hw/dma/sparc32_dma.c b/hw/dma/sparc32_dma.c
index b25a212f7a..84196afb95 100644
--- a/hw/dma/sparc32_dma.c
+++ b/hw/dma/sparc32_dma.c
@@ -331,24 +331,26 @@  static const TypeInfo sparc32_espdma_device_info = {
 static void sparc32_ledma_device_init(Object *obj)
 {
     DMADeviceState *s = SPARC32_DMA_DEVICE(obj);
+    LEDMADeviceState *ls = SPARC32_LEDMA_DEVICE(obj);
 
     memory_region_init_io(&s->iomem, OBJECT(s), &dma_mem_ops, s,
                           "ledma-mmio", DMA_SIZE);
+
+    object_initialize_child(obj, "lance", &ls->lance, TYPE_LANCE);
 }
 
 static void sparc32_ledma_device_realize(DeviceState *dev, Error **errp)
 {
-    DeviceState *d;
+    LEDMADeviceState *s = SPARC32_LEDMA_DEVICE(dev);
+    SysBusPCNetState *lance = SYSBUS_PCNET(&s->lance);
     NICInfo *nd = &nd_table[0];
 
     /* FIXME use qdev NIC properties instead of nd_table[] */
     qemu_check_nic_model(nd, TYPE_LANCE);
 
-    d = qdev_new(TYPE_LANCE);
-    object_property_add_child(OBJECT(dev), "lance", OBJECT(d));
-    qdev_set_nic_properties(d, nd);
-    object_property_set_link(OBJECT(d), "dma", OBJECT(dev), &error_abort);
-    sysbus_realize_and_unref(SYS_BUS_DEVICE(d), &error_fatal);
+    qdev_set_nic_properties(DEVICE(lance), nd);
+    object_property_set_link(OBJECT(lance), "dma", OBJECT(dev), &error_abort);
+    sysbus_realize(SYS_BUS_DEVICE(lance), &error_fatal);
 }
 
 static void sparc32_ledma_device_class_init(ObjectClass *klass, void *data)
diff --git a/include/hw/sparc/sparc32_dma.h b/include/hw/sparc/sparc32_dma.h
index a7b1dd8418..f2bfe272ba 100644
--- a/include/hw/sparc/sparc32_dma.h
+++ b/include/hw/sparc/sparc32_dma.h
@@ -43,7 +43,7 @@  DECLARE_INSTANCE_CHECKER(LEDMADeviceState, SPARC32_LEDMA_DEVICE,
 struct LEDMADeviceState {
     DMADeviceState parent_obj;
 
-    SysBusPCNetState *lance;
+    SysBusPCNetState lance;
 };
 
 #define TYPE_SPARC32_DMA "sparc32-dma"