[RFC PATCH v2 035/137] hw/dma: Give onboard devices a QOM parent

Alexander Graf <[email protected]>
Newsgroups org.nongnu.qemu-arm,org.nongnu.qemu-devel,org.nongnu.qemu-riscv
Message-ID <[email protected]>
Convert the *_orphan() device-creation calls in hw/dma to the new
parented API introduced earlier in this series, so every onboard
device gets a stable path in the composition tree instead of landing
in /machine/unattached with an unstable device[N] name.

The parent for each device is the object that owns its lifetime: the
machine for board-created devices, the containing device for
composite children.  Names follow existing QOM conventions.

Per-site rationale (reviewers: dispute the modeling here):

hw/dma/i8257.c:654 | isa_new | parent | "dma[*]" | helper already receives Object *parent; collapse existing add_child, keep name; drop _and_unref
hw/dma/i8257.c:663 | isa_new | parent | "dma[*]" | helper already receives Object *parent; collapse existing add_child, keep name; drop _and_unref
hw/dma/rc4030.c:750 | qdev_new | parent | "rc4030" | thread Object *parent from single caller mips_jazz_init(machine); update header + caller; drop _and_unref

Link: https://lore.kernel.org/qemu-devel/[email protected]/
AI-used-for: code (refactoring)
Signed-off-by: Alexander Graf <[email protected]>
---
 hw/dma/i8257.c         | 10 ++++------
 hw/dma/rc4030.c        |  7 ++++---
 hw/mips/jazz.c         |  2 +-
 include/hw/mips/mips.h |  3 ++-
 4 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/hw/dma/i8257.c b/hw/dma/i8257.c
index d1ab17b80d..735d7ca9a7 100644
--- a/hw/dma/i8257.c
+++ b/hw/dma/i8257.c
@@ -651,23 +651,21 @@ void i8257_dma_init(Object *parent, ISABus *bus, bool high_page_enable)
     ISADevice *isa1, *isa2;
     DeviceState *d;
 
-    isa1 = isa_new_orphan(TYPE_I8257);
-    object_property_add_child(parent, "dma[*]", OBJECT(isa1));
+    isa1 = isa_new(parent, "dma[*]", TYPE_I8257);
     d = DEVICE(isa1);
     qdev_prop_set_int32(d, "base", 0x00);
     qdev_prop_set_int32(d, "page-base", 0x80);
     qdev_prop_set_int32(d, "pageh-base", high_page_enable ? 0x480 : -1);
     qdev_prop_set_int32(d, "dshift", 0);
-    isa_realize_and_unref(isa1, bus, &error_fatal);
+    qdev_realize(d, BUS(bus), &error_fatal);
 
-    isa2 = isa_new_orphan(TYPE_I8257);
-    object_property_add_child(parent, "dma[*]", OBJECT(isa2));
+    isa2 = isa_new(parent, "dma[*]", TYPE_I8257);
     d = DEVICE(isa2);
     qdev_prop_set_int32(d, "base", 0xc0);
     qdev_prop_set_int32(d, "page-base", 0x88);
     qdev_prop_set_int32(d, "pageh-base", high_page_enable ? 0x488 : -1);
     qdev_prop_set_int32(d, "dshift", 1);
-    isa_realize_and_unref(isa2, bus, &error_fatal);
+    qdev_realize(d, BUS(bus), &error_fatal);
 
     isa_bus_dma(bus, ISADMA(isa1), ISADMA(isa2));
 }
diff --git a/hw/dma/rc4030.c b/hw/dma/rc4030.c
index ab8aaf7da4..800cdfb42d 100644
--- a/hw/dma/rc4030.c
+++ b/hw/dma/rc4030.c
@@ -743,12 +743,13 @@ static void rc4030_register_types(void)
 
 type_init(rc4030_register_types)
 
-DeviceState *rc4030_init(rc4030_dma **dmas, IOMMUMemoryRegion **dma_mr)
+DeviceState *rc4030_init(Object *parent, rc4030_dma **dmas,
+                         IOMMUMemoryRegion **dma_mr)
 {
     DeviceState *dev;
 
-    dev = qdev_new_orphan(TYPE_RC4030);
-    sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
+    dev = qdev_new(parent, "rc4030", TYPE_RC4030);
+    sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
 
     *dmas = rc4030_allocate_dmas(dev, 4);
     *dma_mr = &RC4030(dev)->dma_mr;
diff --git a/hw/mips/jazz.c b/hw/mips/jazz.c
index 5e34a6582d..62f2350d36 100644
--- a/hw/mips/jazz.c
+++ b/hw/mips/jazz.c
@@ -261,7 +261,7 @@ static void mips_jazz_init(MachineState *machine,
     cpu_mips_clock_init(cpu);
 
     /* Chipset */
-    rc4030 = rc4030_init(&dmas, &rc4030_dma_mr);
+    rc4030 = rc4030_init(OBJECT(machine), &dmas, &rc4030_dma_mr);
     sysbus = SYS_BUS_DEVICE(rc4030);
     sysbus_connect_irq(sysbus, 0, env->irq[6]);
     sysbus_connect_irq(sysbus, 1, env->irq[3]);
diff --git a/include/hw/mips/mips.h b/include/hw/mips/mips.h
index cd0ccb4e5d..7fa32eab38 100644
--- a/include/hw/mips/mips.h
+++ b/include/hw/mips/mips.h
@@ -17,6 +17,7 @@ typedef struct rc4030DMAState *rc4030_dma;
 void rc4030_dma_read(void *dma, uint8_t *buf, int len);
 void rc4030_dma_write(void *dma, uint8_t *buf, int len);
 
-DeviceState *rc4030_init(rc4030_dma **dmas, IOMMUMemoryRegion **dma_mr);
+DeviceState *rc4030_init(Object *parent, rc4030_dma **dmas,
+                         IOMMUMemoryRegion **dma_mr);
 
 #endif
-- 
2.47.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.