Convert the *_orphan() device-creation calls in hw/xtensa 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): file:line | parent | name | rationale sim.c:66 | OBJECT(machine) | "cpu[*]" | SMP CPUs created by board init(); machine owns them virt.c:64 | OBJECT(ms) | "pcie" | GPEX PCIe host is a fixed onboard device of the virt machine; create_pcie() already receives MachineState xtfpga.c:176 | OBJECT(machine) | "flash" | onboard CFI flash; thread an Object *parent argument through the static xtfpga_flash_init() helper from board init() xtfpga.c:253 | OBJECT(machine) | "cpu[*]" | SMP CPUs created by board init() Link: https://lore.kernel.org/qemu-devel/[email protected]/ Assisted-by: Kiro Signed-off-by: Alexander Graf <[email protected]> --- hw/xtensa/sim.c | 2 +- hw/xtensa/virt.c | 4 ++-- hw/xtensa/xtfpga.c | 13 ++++++++----- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/hw/xtensa/sim.c b/hw/xtensa/sim.c index 17245a0388..ad1439a0b4 100644 --- a/hw/xtensa/sim.c +++ b/hw/xtensa/sim.c @@ -63,7 +63,7 @@ XtensaCPU *xtensa_sim_common_init(MachineState *machine) int n; for (n = 0; n < machine->smp.cpus; n++) { - cpu = XTENSA_CPU(cpu_create_orphan(machine->cpu_type)); + cpu = XTENSA_CPU(cpu_create(OBJECT(machine), "cpu[*]", machine->cpu_type)); env = &cpu->env; env->sregs[PRID] = n; diff --git a/hw/xtensa/virt.c b/hw/xtensa/virt.c index e31b783b91..6b1271d0d5 100644 --- a/hw/xtensa/virt.c +++ b/hw/xtensa/virt.c @@ -61,8 +61,8 @@ static void create_pcie(MachineState *ms, CPUXtensaState *env, int irq_base, qemu_irq *extints; int i; - dev = qdev_new_orphan(TYPE_GPEX_HOST); - sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); + dev = qdev_new(OBJECT(ms), "pcie", TYPE_GPEX_HOST); + sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal); /* Map only the first size_ecam bytes of ECAM space. */ ecam_alias = g_new0(MemoryRegion, 1); diff --git a/hw/xtensa/xtfpga.c b/hw/xtensa/xtfpga.c index 0ee7350945..07b791b9bf 100644 --- a/hw/xtensa/xtfpga.c +++ b/hw/xtensa/xtfpga.c @@ -168,12 +168,13 @@ static void xtfpga_net_init(MemoryRegion *address_space, memory_region_add_subregion(address_space, buffers, ram); } -static PFlashCFI01 *xtfpga_flash_init(MemoryRegion *address_space, +static PFlashCFI01 *xtfpga_flash_init(Object *parent, + MemoryRegion *address_space, const XtfpgaBoardDesc *board, DriveInfo *dinfo, int be) { SysBusDevice *s; - DeviceState *dev = qdev_new_orphan(TYPE_PFLASH_CFI01); + DeviceState *dev = qdev_new(parent, "flash", TYPE_PFLASH_CFI01); qdev_prop_set_drive(dev, "drive", blk_by_legacy_dinfo(dinfo)); qdev_prop_set_uint32(dev, "num-blocks", @@ -183,7 +184,7 @@ static PFlashCFI01 *xtfpga_flash_init(MemoryRegion *address_space, qdev_prop_set_bit(dev, "big-endian", be); qdev_prop_set_string(dev, "name", "xtfpga.io.flash"); s = SYS_BUS_DEVICE(dev); - sysbus_realize_and_unref(s, &error_fatal); + sysbus_realize(s, &error_fatal); memory_region_add_subregion(address_space, board->flash->base, sysbus_mmio_get_region(s, 0)); return PFLASH_CFI01(dev); @@ -250,7 +251,8 @@ static void xtfpga_init(const XtfpgaBoardDesc *board, MachineState *machine) for (n = 0; n < smp_cpus; n++) { CPUXtensaState *cenv = NULL; - cpu = XTENSA_CPU(cpu_create_orphan(machine->cpu_type)); + cpu = XTENSA_CPU(cpu_create(OBJECT(machine), "cpu[*]", + machine->cpu_type)); cenv = &cpu->env; if (!env) { env = cenv; @@ -315,7 +317,8 @@ static void xtfpga_init(const XtfpgaBoardDesc *board, MachineState *machine) dinfo = drive_get(IF_PFLASH, 0, 0); if (dinfo) { - flash = xtfpga_flash_init(system_io, board, dinfo, TARGET_BIG_ENDIAN); + flash = xtfpga_flash_init(OBJECT(machine), system_io, board, dinfo, + TARGET_BIG_ENDIAN); } /* Use presence of kernel file name as 'boot from SRAM' switch. */ -- 2.47.1
