Convert the *_orphan() device-creation calls in hw/hexagon 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/hexagon/hexagon_dsp.c:134 | qdev_new | OBJECT(machine) | "global-regs" | 
board init helper; collapse existing object_property_add_child()
hw/hexagon/hexagon_dsp.c:141 | qdev_new | OBJECT(machine) | "tlb" | board init 
helper; collapse existing object_property_add_child()
hw/hexagon/virt.c:132 | qdev_new | OBJECT(vms) | "uart" | board-init helper 
receives HexagonVirtMachineState*; drop const on vms
hw/hexagon/virt.c:271 | qdev_new | OBJECT(ms) | "global-regs" | board init; 
collapse existing object_property_add_child()
hw/hexagon/virt.c:277 | qdev_new | OBJECT(ms) | "tlb" | board init; collapse 
existing object_property_add_child()

Link: https://lore.kernel.org/qemu-devel/[email protected]/
Assisted-by: Kiro
Signed-off-by: Alexander Graf <[email protected]>
---
 hw/hexagon/hexagon_dsp.c | 12 +++++-------
 hw/hexagon/virt.c        | 16 +++++++---------
 2 files changed, 12 insertions(+), 16 deletions(-)

diff --git a/hw/hexagon/hexagon_dsp.c b/hw/hexagon/hexagon_dsp.c
index 712749cda8..ccd9a06f51 100644
--- a/hw/hexagon/hexagon_dsp.c
+++ b/hw/hexagon/hexagon_dsp.c
@@ -131,18 +131,16 @@ static void hexagon_common_init(MachineState *machine, 
Rev_t rev,
                            machine->ram_size, &error_fatal);
     memory_region_add_subregion(address_space, 0x0, &hms->ram);
 
-    glob_regs_dev = qdev_new_orphan(TYPE_HEXAGON_GLOBALREG);
-    object_property_add_child(OBJECT(machine), "global-regs",
-                              OBJECT(glob_regs_dev));
+    glob_regs_dev = qdev_new(OBJECT(machine), "global-regs",
+                             TYPE_HEXAGON_GLOBALREG);
     qdev_prop_set_uint64(glob_regs_dev, "config-table-addr", m_cfg->cfgbase);
     qdev_prop_set_uint32(glob_regs_dev, "dsp-rev", rev);
-    sysbus_realize_and_unref(SYS_BUS_DEVICE(glob_regs_dev), &error_fatal);
+    sysbus_realize(SYS_BUS_DEVICE(glob_regs_dev), &error_fatal);
 
-    tlb_dev = qdev_new_orphan(TYPE_HEXAGON_TLB);
-    object_property_add_child(OBJECT(machine), "tlb", OBJECT(tlb_dev));
+    tlb_dev = qdev_new(OBJECT(machine), "tlb", TYPE_HEXAGON_TLB);
     qdev_prop_set_uint32(tlb_dev, "num-entries",
                          m_cfg->cfgtable.jtlb_size_entries);
-    sysbus_realize_and_unref(SYS_BUS_DEVICE(tlb_dev), &error_fatal);
+    sysbus_realize(SYS_BUS_DEVICE(tlb_dev), &error_fatal);
 
     for (int i = 0; i < machine->smp.cpus; i++) {
         HexagonCPU *cpu = HEXAGON_CPU(object_new(machine->cpu_type));
diff --git a/hw/hexagon/virt.c b/hw/hexagon/virt.c
index a7a6a8fbeb..0619f06c41 100644
--- a/hw/hexagon/virt.c
+++ b/hw/hexagon/virt.c
@@ -116,7 +116,7 @@ static int32_t fdt_add_clocks(const HexagonVirtMachineState 
*vms)
     return clk_phandle;
 }
 
-static void fdt_add_uart(const HexagonVirtMachineState *vms, int uart,
+static void fdt_add_uart(HexagonVirtMachineState *vms, int uart,
                          int32_t clk_phandle)
 {
     char *nodename;
@@ -129,11 +129,11 @@ static void fdt_add_uart(const HexagonVirtMachineState 
*vms, int uart,
     DeviceState *dev;
     SysBusDevice *s;
 
-    dev = qdev_new_orphan(TYPE_PL011);
+    dev = qdev_new(OBJECT(vms), "uart", TYPE_PL011);
     s = SYS_BUS_DEVICE(dev);
     qdev_prop_set_chr(dev, "chardev", serial_hd(0));
     qdev_connect_clock_in(dev, "clk", vms->apb_clk);
-    sysbus_realize_and_unref(s, &error_fatal);
+    sysbus_realize(s, &error_fatal);
     sysbus_mmio_map(s, 0, base);
 
     nodename = g_strdup_printf("/pl011@%" PRIx64, base);
@@ -268,17 +268,15 @@ static void virt_init(MachineState *ms)
                                 &vms->parent_obj.cfgtable_rom);
     fdt_add_hvx(vms, m_cfg);
 
-    gsregs_dev = qdev_new_orphan(TYPE_HEXAGON_GLOBALREG);
-    object_property_add_child(OBJECT(ms), "global-regs", OBJECT(gsregs_dev));
+    gsregs_dev = qdev_new(OBJECT(ms), "global-regs", TYPE_HEXAGON_GLOBALREG);
     qdev_prop_set_uint64(gsregs_dev, "config-table-addr", m_cfg->cfgbase);
     qdev_prop_set_uint32(gsregs_dev, "dsp-rev", v68_rev);
-    sysbus_realize_and_unref(SYS_BUS_DEVICE(gsregs_dev), &error_fatal);
+    sysbus_realize(SYS_BUS_DEVICE(gsregs_dev), &error_fatal);
 
-    tlb_dev = qdev_new_orphan(TYPE_HEXAGON_TLB);
-    object_property_add_child(OBJECT(ms), "tlb", OBJECT(tlb_dev));
+    tlb_dev = qdev_new(OBJECT(ms), "tlb", TYPE_HEXAGON_TLB);
     qdev_prop_set_uint32(tlb_dev, "num-entries",
                          m_cfg->cfgtable.jtlb_size_entries);
-    sysbus_realize_and_unref(SYS_BUS_DEVICE(tlb_dev), &error_fatal);
+    sysbus_realize(SYS_BUS_DEVICE(tlb_dev), &error_fatal);
 
     cpu0 = NULL;
     for (int i = 0; i < ms->smp.cpus; i++) {
-- 
2.47.1


Reply via email to