diff mbox series

[3/6] sparc32-espdma: use object_initialize_child() for esp child object

Message ID 20200920082018.16135-4-mark.cave-ayland@ilande.co.uk
State Superseded
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-espdma object rather than
using link properties.

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

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

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

> 

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

> index 84196afb95..2cbe331959 100644

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

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

> @@ -290,27 +290,26 @@ static const TypeInfo sparc32_dma_device_info = {

>  static void sparc32_espdma_device_init(Object *obj)

>  {

>      DMADeviceState *s = SPARC32_DMA_DEVICE(obj);

> +    ESPDMADeviceState *es = SPARC32_ESPDMA_DEVICE(obj);

>  

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

>                            "espdma-mmio", DMA_SIZE);

> +

> +    object_initialize_child(obj, "esp", &es->esp, TYPE_ESP);

>  }

>  

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

>  {

> -    DeviceState *d;

> -    SysBusESPState *sysbus;

> -    ESPState *esp;

> -

> -    d = qdev_new(TYPE_ESP);

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

> -    sysbus = ESP(d);

> -    esp = &sysbus->esp;

> +    ESPDMADeviceState *es = SPARC32_ESPDMA_DEVICE(dev);

> +    SysBusESPState *sysbus = ESP(&es->esp);

> +    ESPState *esp = &sysbus->esp;

> +

>      esp->dma_memory_read = espdma_memory_read;

>      esp->dma_memory_write = espdma_memory_write;

>      esp->dma_opaque = SPARC32_DMA_DEVICE(dev);

>      sysbus->it_shift = 2;

>      esp->dma_enabled = 1;

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

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

>  }

>  

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

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

> index f2bfe272ba..d40eca0cc8 100644

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

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

> @@ -32,7 +32,7 @@ DECLARE_INSTANCE_CHECKER(ESPDMADeviceState, SPARC32_ESPDMA_DEVICE,

>  struct ESPDMADeviceState {

>      DMADeviceState parent_obj;

>  

> -    SysBusESPState *esp;

> +    SysBusESPState esp;

>  };

>  

>  #define TYPE_SPARC32_LEDMA_DEVICE "sparc32-ledma"

>
diff mbox series

Patch

diff --git a/hw/dma/sparc32_dma.c b/hw/dma/sparc32_dma.c
index 84196afb95..2cbe331959 100644
--- a/hw/dma/sparc32_dma.c
+++ b/hw/dma/sparc32_dma.c
@@ -290,27 +290,26 @@  static const TypeInfo sparc32_dma_device_info = {
 static void sparc32_espdma_device_init(Object *obj)
 {
     DMADeviceState *s = SPARC32_DMA_DEVICE(obj);
+    ESPDMADeviceState *es = SPARC32_ESPDMA_DEVICE(obj);
 
     memory_region_init_io(&s->iomem, OBJECT(s), &dma_mem_ops, s,
                           "espdma-mmio", DMA_SIZE);
+
+    object_initialize_child(obj, "esp", &es->esp, TYPE_ESP);
 }
 
 static void sparc32_espdma_device_realize(DeviceState *dev, Error **errp)
 {
-    DeviceState *d;
-    SysBusESPState *sysbus;
-    ESPState *esp;
-
-    d = qdev_new(TYPE_ESP);
-    object_property_add_child(OBJECT(dev), "esp", OBJECT(d));
-    sysbus = ESP(d);
-    esp = &sysbus->esp;
+    ESPDMADeviceState *es = SPARC32_ESPDMA_DEVICE(dev);
+    SysBusESPState *sysbus = ESP(&es->esp);
+    ESPState *esp = &sysbus->esp;
+
     esp->dma_memory_read = espdma_memory_read;
     esp->dma_memory_write = espdma_memory_write;
     esp->dma_opaque = SPARC32_DMA_DEVICE(dev);
     sysbus->it_shift = 2;
     esp->dma_enabled = 1;
-    sysbus_realize_and_unref(SYS_BUS_DEVICE(d), &error_fatal);
+    sysbus_realize(SYS_BUS_DEVICE(sysbus), &error_fatal);
 }
 
 static void sparc32_espdma_device_class_init(ObjectClass *klass, void *data)
diff --git a/include/hw/sparc/sparc32_dma.h b/include/hw/sparc/sparc32_dma.h
index f2bfe272ba..d40eca0cc8 100644
--- a/include/hw/sparc/sparc32_dma.h
+++ b/include/hw/sparc/sparc32_dma.h
@@ -32,7 +32,7 @@  DECLARE_INSTANCE_CHECKER(ESPDMADeviceState, SPARC32_ESPDMA_DEVICE,
 struct ESPDMADeviceState {
     DMADeviceState parent_obj;
 
-    SysBusESPState *esp;
+    SysBusESPState esp;
 };
 
 #define TYPE_SPARC32_LEDMA_DEVICE "sparc32-ledma"