Skip to contentSkip to conversation

qom: Make composition-tree parenting mandatory

RFC PATCH Superseded Alexander Graf 9 participants 295 messages Jul 11 – Jul 20 Page 6 of 7

Subsystems (11)
lore
Share & tools
lore
#215 lore raw

RFC PATCH v2 58/137 hw/arm/sbsa-ref: Give onboard devices a QOM parent

In reply to Alexander Graf

Convert the *_orphan() device-creation calls in the hw/arm sbsa-ref board files 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 SoC device for composite children. Names follow existing QOM conventions.

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

hw/arm/sbsa-ref.c:299 | qdev_new | OBJECT(sms) | name | collapse existing object_property_add_child(OBJECT(sms), name, ...); keep existing name; sbsa_flash_map1 realize -> sysbus_realize
hw/arm/sbsa-ref.c:424 | qdev_new | OBJECT(sms) | "its" | helper receives SBSAMachineState* board pointer
hw/arm/sbsa-ref.c:443 | qdev_new | OBJECT(sms) | "gic" | helper receives SBSAMachineState* board pointer
hw/arm/sbsa-ref.c:525 | qdev_new | OBJECT(sms) | "uart[*]" | helper called 3x from board init -> auto-index; drop const
hw/arm/sbsa-ref.c:540 | sysbus_create_simple | OBJECT(sms) | "rtc" | helper receives SBSAMachineState*; drop const
hw/arm/sbsa-ref.c:547 | qdev_new | OBJECT(sms) | "wdt" | helper receives SBSAMachineState*; drop const
hw/arm/sbsa-ref.c:575 | sysbus_create_simple | OBJECT(sms) | "gpio" | helper receives SBSAMachineState*; drop const
hw/arm/sbsa-ref.c:578 | sysbus_create_simple | OBJECT(sms) | "gpio-key" | helper receives SBSAMachineState*
hw/arm/sbsa-ref.c:593 | qdev_new | OBJECT(sms) | "ahci" | helper receives SBSAMachineState*; drop const
hw/arm/sbsa-ref.c:608 | qdev_new | OBJECT(sms) | "xhci" | helper receives SBSAMachineState*; drop const
hw/arm/sbsa-ref.c:625 | qdev_new | OBJECT(sms) | "smmuv3" | helper receives SBSAMachineState*; drop const
hw/arm/sbsa-ref.c:661 | qdev_new | OBJECT(sms) | "pcie" | helper receives SBSAMachineState*
hw/arm/sbsa-ref.c:698 | pci_create_simple | OBJECT(sms) | "bochs-display" | board owns lifetime; bus is plug location not parent
hw/arm/sbsa-ref.c:715 | qdev_new | parent | "sbsa-ec" | helper lacks parent-capable pointer -> thread Object *parent from sbsa_ref_init

AI-used-for: code (refactoring)

---
 hw/arm/sbsa-ref.c | 82 +++++++++++++++++++++--------------------------
 1 file changed, 36 insertions(+), 46 deletions(-)
hw/arm/sbsa-ref.c +36 -46
index f9fb681d31..bb35de1616 100644
@@ -296,7 +296,7 @@ static PFlashCFI01 *sbsa_flash_create1(SBSAMachineState *sms,
      * Create a single flash device.  We use the same parameters as
      * the flash devices on the Versatile Express board.
      */
-    DeviceState *dev = qdev_new_orphan(TYPE_PFLASH_CFI01);
+    DeviceState *dev = qdev_new(OBJECT(sms), name, TYPE_PFLASH_CFI01);
 
     qdev_prop_set_uint64(dev, "sector-length", SBSA_FLASH_SECTOR_SIZE);
     qdev_prop_set_uint8(dev, "width", 4);
@@ -307,7 +307,6 @@ static PFlashCFI01 *sbsa_flash_create1(SBSAMachineState *sms,
     qdev_prop_set_uint16(dev, "id2", 0x00);
     qdev_prop_set_uint16(dev, "id3", 0x00);
     qdev_prop_set_string(dev, "name", name);
-    object_property_add_child(OBJECT(sms), name, OBJECT(dev));
     object_property_add_alias(OBJECT(sms), alias_prop_name,
                               OBJECT(dev), "drive");
     return PFLASH_CFI01(dev);
@@ -328,7 +327,7 @@ static void sbsa_flash_map1(PFlashCFI01 *flash,
     assert(QEMU_IS_ALIGNED(size, SBSA_FLASH_SECTOR_SIZE));
     assert(size / SBSA_FLASH_SECTOR_SIZE <= UINT32_MAX);
     qdev_prop_set_uint32(dev, "num-blocks", size / SBSA_FLASH_SECTOR_SIZE);
-    sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
+    sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
 
     memory_region_add_subregion(sysmem, base,
                                 sysbus_mmio_get_region(SYS_BUS_DEVICE(dev),
@@ -421,11 +420,11 @@ static void create_its(SBSAMachineState *sms)
     const char *itsclass = its_class_name();
     DeviceState *dev;
 
-    dev = qdev_new_orphan(itsclass);
+    dev = qdev_new(OBJECT(sms), "its", itsclass);
 
     object_property_set_link(OBJECT(dev), "parent-gicv3", OBJECT(sms->gic),
                              &error_abort);
-    sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
+    sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
     sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, sbsa_ref_memmap[SBSA_GIC_ITS].base);
 }
 
@@ -440,7 +439,7 @@ static void create_gic(SBSAMachineState *sms, MemoryRegion *mem)
 
     gictype = gicv3_class_name();
 
-    sms->gic = qdev_new_orphan(gictype);
+    sms->gic = qdev_new(OBJECT(sms), "gic", gictype);
     qdev_prop_set_uint32(sms->gic, "revision", 3);
     qdev_prop_set_uint32(sms->gic, "num-cpu", smp_cpus);
     /*
@@ -463,7 +462,7 @@ static void create_gic(SBSAMachineState *sms, MemoryRegion *mem)
     qdev_prop_set_bit(sms->gic, "has-lpi", true);
 
     gicbusdev = SYS_BUS_DEVICE(sms->gic);
-    sysbus_realize_and_unref(gicbusdev, &error_fatal);
+    sysbus_realize(gicbusdev, &error_fatal);
     sysbus_mmio_map(gicbusdev, 0, sbsa_ref_memmap[SBSA_GIC_DIST].base);
     sysbus_mmio_map(gicbusdev, 1, sbsa_ref_memmap[SBSA_GIC_REDIST].base);
 
@@ -517,39 +516,40 @@ static void create_gic(SBSAMachineState *sms, MemoryRegion *mem)
     create_its(sms);
 }
 
-static void create_uart(const SBSAMachineState *sms, int uart,
+static void create_uart(SBSAMachineState *sms, int uart,
                         MemoryRegion *mem, Chardev *chr)
 {
     hwaddr base = sbsa_ref_memmap[uart].base;
     int irq = sbsa_ref_irqmap[uart];
-    DeviceState *dev = qdev_new_orphan(TYPE_PL011);
+    DeviceState *dev = qdev_new(OBJECT(sms), "uart[*]", TYPE_PL011);
     SysBusDevice *s = SYS_BUS_DEVICE(dev);
 
     qdev_prop_set_chr(dev, "chardev", chr);
-    sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
+    sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
     memory_region_add_subregion(mem, base,
                                 sysbus_mmio_get_region(s, 0));
     sysbus_connect_irq(s, 0, qdev_get_gpio_in(sms->gic, irq));
 }
 
-static void create_rtc(const SBSAMachineState *sms)
+static void create_rtc(SBSAMachineState *sms)
 {
     hwaddr base = sbsa_ref_memmap[SBSA_RTC].base;
     int irq = sbsa_ref_irqmap[SBSA_RTC];
 
-    sysbus_create_simple_orphan("pl031", base, qdev_get_gpio_in(sms->gic, irq));
+    sysbus_create_simple(OBJECT(sms), "rtc", "pl031", base,
+                         qdev_get_gpio_in(sms->gic, irq));
 }
 
-static void create_wdt(const SBSAMachineState *sms)
+static void create_wdt(SBSAMachineState *sms)
 {
     hwaddr rbase = sbsa_ref_memmap[SBSA_GWDT_REFRESH].base;
     hwaddr cbase = sbsa_ref_memmap[SBSA_GWDT_CONTROL].base;
-    DeviceState *dev = qdev_new_orphan(TYPE_WDT_SBSA);
+    DeviceState *dev = qdev_new(OBJECT(sms), "wdt", TYPE_WDT_SBSA);
     SysBusDevice *s = SYS_BUS_DEVICE(dev);
     int irq = sbsa_ref_irqmap[SBSA_GWDT_WS0];
 
     qdev_prop_set_uint64(dev, "clock-frequency", SBSA_GTIMER_HZ);
-    sysbus_realize_and_unref(s, &error_fatal);
+    sysbus_realize(s, &error_fatal);
     sysbus_mmio_map(s, 0, rbase);
     sysbus_mmio_map(s, 1, cbase);
     sysbus_connect_irq(s, 0, qdev_get_gpio_in(sms->gic, irq));
@@ -566,23 +566,23 @@ static Notifier sbsa_ref_powerdown_notifier = {
     .notify = sbsa_ref_powerdown_req
 };
 
-static void create_gpio(const SBSAMachineState *sms)
+static void create_gpio(SBSAMachineState *sms)
 {
     DeviceState *pl061_dev;
     hwaddr base = sbsa_ref_memmap[SBSA_GPIO].base;
     int irq = sbsa_ref_irqmap[SBSA_GPIO];
 
-    pl061_dev = sysbus_create_simple_orphan("pl061", base,
+    pl061_dev = sysbus_create_simple(OBJECT(sms), "gpio", "pl061", base,
                                      qdev_get_gpio_in(sms->gic, irq));
 
-    gpio_key_dev = sysbus_create_simple_orphan("gpio-key", -1,
-                                        qdev_get_gpio_in(pl061_dev, 3));
+    gpio_key_dev = sysbus_create_simple(OBJECT(sms), "gpio-key", "gpio-key",
+                                        -1, qdev_get_gpio_in(pl061_dev, 3));
 
     /* connect powerdown request */
     qemu_register_powerdown_notifier(&sbsa_ref_powerdown_notifier);
 }
 
-static void create_ahci(const SBSAMachineState *sms)
+static void create_ahci(SBSAMachineState *sms)
 {
     hwaddr base = sbsa_ref_memmap[SBSA_AHCI].base;
     int irq = sbsa_ref_irqmap[SBSA_AHCI];
@@ -590,9 +590,9 @@ static void create_ahci(const SBSAMachineState *sms)
     DriveInfo *hd[NUM_SATA_PORTS];
     SysbusAHCIState *sysahci;
 
-    dev = qdev_new_orphan("sysbus-ahci");
+    dev = qdev_new(OBJECT(sms), "ahci", "sysbus-ahci");
     qdev_prop_set_uint32(dev, "num-ports", NUM_SATA_PORTS);
-    sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
+    sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
     sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);
     sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, qdev_get_gpio_in(sms->gic, irq));
 
@@ -601,19 +601,19 @@ static void create_ahci(const SBSAMachineState *sms)
     ahci_ide_create_devs(&sysahci->ahci, hd);
 }
 
-static void create_xhci(const SBSAMachineState *sms)
+static void create_xhci(SBSAMachineState *sms)
 {
     hwaddr base = sbsa_ref_memmap[SBSA_XHCI].base;
     int irq = sbsa_ref_irqmap[SBSA_XHCI];
-    DeviceState *dev = qdev_new_orphan(TYPE_XHCI_SYSBUS);
+    DeviceState *dev = qdev_new(OBJECT(sms), "xhci", TYPE_XHCI_SYSBUS);
     qdev_prop_set_uint32(dev, "slots", XHCI_MAXSLOTS);
 
-    sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
+    sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
     sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);
     sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, qdev_get_gpio_in(sms->gic, irq));
 }
 
-static void create_smmu(const SBSAMachineState *sms, PCIBus *bus,
+static void create_smmu(SBSAMachineState *sms, PCIBus *bus,
                         MemoryRegion *sysmem,
                         MemoryRegion *secure_sysmem)
 {
@@ -622,7 +622,7 @@ static void create_smmu(const SBSAMachineState *sms, PCIBus *bus,
     DeviceState *dev;
     int i;
 
-    dev = qdev_new_orphan(TYPE_ARM_SMMUV3);
+    dev = qdev_new(OBJECT(sms), "smmuv3", TYPE_ARM_SMMUV3);
 
     object_property_set_str(OBJECT(dev), "stage", "nested", &error_abort);
     object_property_set_link(OBJECT(dev), "primary-bus", OBJECT(bus),
@@ -631,7 +631,7 @@ static void create_smmu(const SBSAMachineState *sms, PCIBus *bus,
                              &error_abort);
     object_property_set_link(OBJECT(dev), "secure-memory", OBJECT(secure_sysmem),
                              &error_abort);
-    sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
+    sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
     sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);
     for (i = 0; i < NUM_SMMU_IRQS; i++) {
         sysbus_connect_irq(SYS_BUS_DEVICE(dev), i,
@@ -658,8 +658,8 @@ static void create_pcie(SBSAMachineState *sms,
     PCIHostState *pci;
     int i;
 
-    dev = qdev_new_orphan(TYPE_GPEX_HOST);
-    sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
+    dev = qdev_new(OBJECT(sms), "pcie", TYPE_GPEX_HOST);
+    sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
 
     /* Map ECAM space */
     ecam_alias = g_new0(MemoryRegion, 1);
@@ -695,7 +695,7 @@ static void create_pcie(SBSAMachineState *sms,
 
     pci_init_nic_devices(pci->bus, mc->default_nic);
 
-    pci_create_simple_orphan(pci->bus, -1, "bochs-display");
+    pci_create_simple(OBJECT(sms), "bochs-display", pci->bus, -1, "bochs-display");
 
     create_smmu(sms, pci->bus, sysmem, secure_sysmem);
 }
@@ -709,12 +709,14 @@ static void *sbsa_ref_dtb(const struct arm_boot_info *binfo, int *fdt_size)
     return board->fdt;
 }
 
-static void create_secure_ec(MemoryRegion *mem)
+static void create_secure_ec(Object *parent, MemoryRegion *mem)
 {
     hwaddr base = sbsa_ref_memmap[SBSA_SECURE_EC].base;
-    DeviceState *dev = qdev_new_orphan("sbsa-ec");
+    DeviceState *dev = qdev_new(parent, "sbsa-ec", "sbsa-ec");
     SysBusDevice *s = SYS_BUS_DEVICE(dev);
 
+    sysbus_realize(s, &error_fatal);
+
     memory_region_add_subregion(mem, base,
                                 sysbus_mmio_get_region(s, 0));
 }
@@ -835,7 +837,7 @@ static void sbsa_ref_init(MachineState *machine)
 
     create_pcie(sms, sysmem, secure_sysmem);
 
-    create_secure_ec(secure_sysmem);
+    create_secure_ec(OBJECT(sms), secure_sysmem);
 
     sms->bootinfo.ram_size = machine->ram_size;
     sms->bootinfo.board_id = -1;
@@ -892,17 +894,6 @@ static void sbsa_ref_instance_init(Object *obj)
     sbsa_flash_create(sms);
 }
 
-static void sbsa_ref_instance_finalize(Object *obj)
-{
-    SBSAMachineState *sms = SBSA_MACHINE(obj);
-
-    for (int i = 0; i < ARRAY_SIZE(sms->flash); i++) {
-        if (sms->flash[i] && !qdev_is_realized(DEVICE(sms->flash[i]))) {
-            object_unref(OBJECT(sms->flash[i]));
-        }
-    }
-}
-
 static void sbsa_ref_class_init(ObjectClass *oc, const void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
@@ -941,7 +932,6 @@ static const TypeInfo sbsa_ref_info = {
     .name          = TYPE_SBSA_MACHINE,
     .parent        = TYPE_MACHINE,
     .instance_init = sbsa_ref_instance_init,
-    .instance_finalize = sbsa_ref_instance_finalize,
     .class_init    = sbsa_ref_class_init,
     .instance_size = sizeof(SBSAMachineState),
     .interfaces    = aarch64_machine_interfaces,
Signature · 1 line
2.47.1
#216 lore raw

RFC PATCH v2 59/137 hw/arm/xilinx-zynq: Give onboard devices a QOM parent

In reply to Alexander Graf

Convert the *_orphan() device-creation calls in the hw/arm xilinx-zynq board files 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 SoC device for composite children. Names follow existing QOM conventions.

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

hw/arm/xilinx_zynq.c:113 | qdev_new | parent | "gem[*]" | thread Object *parent into gem_init(); board init callers pass OBJECT(machine); sysbus_realize
hw/arm/xilinx_zynq.c:134 | qdev_new | parent | is_qspi?"qspi":"spi[*]" | thread Object *parent into zynq_init_spi_flashes(); sysbus_realize
hw/arm/xilinx_zynq.c:155 | qdev_new | OBJECT(dev) | "flash[*]" | flash owned by SPI controller; qdev_realize
hw/arm/xilinx_zynq.c:198 | qdev_new | parent | "ddr-ctrl" | thread Object *parent into ddr_ctrl_init(); sysbus_realize
hw/arm/xilinx_zynq.c:259 | qdev_new | OBJECT(machine) | "slcr" | board init; sysbus_realize
hw/arm/xilinx_zynq.c:265 | qdev_new | OBJECT(machine) | "a9mpcore" | board init; sysbus_realize
hw/arm/xilinx_zynq.c:272 | sysbus_create_varargs | OBJECT(machine) | "l2x0" | board init; create_simple realizes internally
hw/arm/xilinx_zynq.c:290 | sysbus_create_simple | OBJECT(machine) | "usb[*]" | board init; two ChipIdea USB controllers
hw/arm/xilinx_zynq.c:291 | sysbus_create_simple | OBJECT(machine) | "usb[*]" | board init
hw/arm/xilinx_zynq.c:293 | qdev_new | OBJECT(machine) | "uart[*]" | board init; sysbus_realize
hw/arm/xilinx_zynq.c:301 | qdev_new | OBJECT(machine) | "uart[*]" | board init; sysbus_realize
hw/arm/xilinx_zynq.c:310 | sysbus_create_varargs | OBJECT(machine) | "ttc[*]" | board init; two Cadence TTCs
hw/arm/xilinx_zynq.c:312 | sysbus_create_varargs | OBJECT(machine) | "ttc[*]" | board init
hw/arm/xilinx_zynq.c:332 | qdev_new | OBJECT(machine) | "sdhci[*]" | board init loop; sysbus_realize
hw/arm/xilinx_zynq.c:341 | qdev_new | OBJECT(dev) | "sd-card" | card owned by its SDHCI controller; qdev_realize
hw/arm/xilinx_zynq.c:347 | qdev_new | OBJECT(machine) | "xadc" | board init; sysbus_realize
hw/arm/xilinx_zynq.c:352 | qdev_new | OBJECT(machine) | "dma" | board init pl330 DMA; sysbus_realize
hw/arm/xilinx_zynq.c:375 | qdev_new | OBJECT(machine) | "devcfg" | board init; sysbus_realize

AI-used-for: code (refactoring)

---
 hw/arm/xilinx_zynq.c | 92 ++++++++++++++++++++++++--------------------
 1 file changed, 50 insertions(+), 42 deletions(-)
hw/arm/xilinx_zynq.c +50 -42
index ba00c5a3aa..378ab532a3 100644
@@ -105,22 +105,23 @@ static void zynq_write_board_setup(ARMCPU *cpu,
 
 static struct arm_boot_info zynq_binfo = {};
 
-static void gem_init(uint32_t base, qemu_irq irq)
+static void gem_init(Object *parent, uint32_t base, qemu_irq irq)
 {
     DeviceState *dev;
     SysBusDevice *s;
 
-    dev = qdev_new_orphan(TYPE_CADENCE_GEM);
+    dev = qdev_new(parent, "gem[*]", TYPE_CADENCE_GEM);
     qemu_configure_nic_device(dev, true, NULL);
     object_property_set_int(OBJECT(dev), "phy-addr", 7, &error_abort);
     s = SYS_BUS_DEVICE(dev);
-    sysbus_realize_and_unref(s, &error_fatal);
+    sysbus_realize(s, &error_fatal);
     sysbus_mmio_map(s, 0, base);
     sysbus_connect_irq(s, 0, irq);
 }
 
-static inline int zynq_init_spi_flashes(uint32_t base_addr, qemu_irq irq,
-                                        bool is_qspi, int unit0)
+static inline int zynq_init_spi_flashes(Object *parent, uint32_t base_addr,
+                                        qemu_irq irq, bool is_qspi,
+                                        int unit0)
 {
     int unit = unit0;
     DeviceState *dev;
@@ -131,12 +132,13 @@ static inline int zynq_init_spi_flashes(uint32_t base_addr, qemu_irq irq,
     int num_busses =  is_qspi ? NUM_QSPI_BUSSES : 1;
     int num_ss = is_qspi ? NUM_QSPI_FLASHES : NUM_SPI_FLASHES;
 
-    dev = qdev_new_orphan(is_qspi ? "xlnx.ps7-qspi" : "xlnx.ps7-spi");
+    dev = qdev_new(parent, is_qspi ? "qspi" : "spi[*]",
+                   is_qspi ? "xlnx.ps7-qspi" : "xlnx.ps7-spi");
     qdev_prop_set_uint8(dev, "num-txrx-bytes", is_qspi ? 4 : 1);
     qdev_prop_set_uint8(dev, "num-ss-bits", num_ss);
     qdev_prop_set_uint8(dev, "num-busses", num_busses);
     busdev = SYS_BUS_DEVICE(dev);
-    sysbus_realize_and_unref(busdev, &error_fatal);
+    sysbus_realize(busdev, &error_fatal);
     sysbus_mmio_map(busdev, 0, base_addr);
     if (is_qspi) {
         sysbus_mmio_map(busdev, 1, 0xFC000000);
@@ -152,14 +154,14 @@ static inline int zynq_init_spi_flashes(uint32_t base_addr, qemu_irq irq,
 
         for (j = 0; j < num_ss; ++j) {
             DriveInfo *dinfo = drive_get(IF_MTD, 0, unit++);
-            flash_dev = qdev_new_orphan("n25q128");
+            flash_dev = qdev_new(OBJECT(dev), "flash[*]", "n25q128");
             if (dinfo) {
                 qdev_prop_set_drive_err(flash_dev, "drive",
                                         blk_by_legacy_dinfo(dinfo),
                                         &error_fatal);
             }
             qdev_prop_set_uint8(flash_dev, "cs", j);
-            qdev_realize_and_unref(flash_dev, BUS(spi), &error_fatal);
+            qdev_realize(flash_dev, BUS(spi), &error_fatal);
 
             cs_line = qdev_get_gpio_in_named(flash_dev, SSI_GPIO_CS, 0);
             sysbus_connect_irq(busdev, i * num_ss + j + 1, cs_line);
@@ -190,14 +192,14 @@ static void zynq_set_boot_mode(Object *obj, const char *str,
     m->boot_mode = mode;
 }
 
-static void ddr_ctrl_init(uint32_t base)
+static void ddr_ctrl_init(Object *parent, uint32_t base)
 {
     DeviceState *dev;
     SysBusDevice *busdev;
 
-    dev = qdev_new_orphan("zynq.ddr-ctlr");
+    dev = qdev_new(parent, "ddr-ctrl", "zynq.ddr-ctlr");
     busdev = SYS_BUS_DEVICE(dev);
-    sysbus_realize_and_unref(busdev, &error_fatal);
+    sysbus_realize(busdev, &error_fatal);
     sysbus_mmio_map(busdev, 0, base);
 }
 
@@ -256,20 +258,21 @@ static void zynq_init(MachineState *machine)
     clock_set_hz(zynq_machine->ps_clk, PS_CLK_FREQUENCY);
 
     /* Create slcr, keep a pointer to connect clocks */
-    slcr = qdev_new_orphan("xilinx-zynq_slcr");
+    slcr = qdev_new(OBJECT(machine), "slcr", "xilinx-zynq_slcr");
     qdev_connect_clock_in(slcr, "ps_clk", zynq_machine->ps_clk);
     qdev_prop_set_uint8(slcr, "boot-mode", zynq_machine->boot_mode);
-    sysbus_realize_and_unref(SYS_BUS_DEVICE(slcr), &error_fatal);
+    sysbus_realize(SYS_BUS_DEVICE(slcr), &error_fatal);
     sysbus_mmio_map(SYS_BUS_DEVICE(slcr), 0, 0xF8000000);
 
-    dev = qdev_new_orphan(TYPE_A9MPCORE_PRIV);
+    dev = qdev_new(OBJECT(machine), "a9mpcore", TYPE_A9MPCORE_PRIV);
     qdev_prop_set_uint32(dev, "num-cpu", smp_cpus);
     qdev_prop_set_uint32(dev, "num-irq", GIC_EXT_IRQS + GIC_INTERNAL);
     busdev = SYS_BUS_DEVICE(dev);
-    sysbus_realize_and_unref(busdev, &error_fatal);
+    sysbus_realize(busdev, &error_fatal);
     sysbus_mmio_map(busdev, 0, MPCORE_PERIPHBASE);
     zynq_binfo.gic_cpu_if_addr = MPCORE_PERIPHBASE + 0x100;
-    sysbus_create_varargs_orphan("l2x0", MPCORE_PERIPHBASE + 0x2000, NULL);
+    sysbus_create_varargs(OBJECT(machine), "l2x0", "l2x0",
+                          MPCORE_PERIPHBASE + 0x2000, NULL);
     for (n = 0; n < smp_cpus; n++) {
         /* See "hw/intc/arm_gic.h" for the IRQ line association */
         DeviceState *cpudev = DEVICE(zynq_machine->cpu[n]);
@@ -283,39 +286,44 @@ static void zynq_init(MachineState *machine)
         pic[n] = qdev_get_gpio_in(dev, n);
     }
 
-    n = zynq_init_spi_flashes(0xE0006000, pic[58 - GIC_INTERNAL], false, 0);
-    n = zynq_init_spi_flashes(0xE0007000, pic[81 - GIC_INTERNAL], false, n);
-    n = zynq_init_spi_flashes(0xE000D000, pic[51 - GIC_INTERNAL], true, n);
+    n = zynq_init_spi_flashes(OBJECT(machine), 0xE0006000,
+                              pic[58 - GIC_INTERNAL], false, 0);
+    n = zynq_init_spi_flashes(OBJECT(machine), 0xE0007000,
+                              pic[81 - GIC_INTERNAL], false, n);
+    n = zynq_init_spi_flashes(OBJECT(machine), 0xE000D000,
+                              pic[51 - GIC_INTERNAL], true, n);
 
-    sysbus_create_simple_orphan(TYPE_CHIPIDEA, 0xE0002000, pic[53 - GIC_INTERNAL]);
-    sysbus_create_simple_orphan(TYPE_CHIPIDEA, 0xE0003000, pic[76 - GIC_INTERNAL]);
+    sysbus_create_simple(OBJECT(machine), "usb[*]", TYPE_CHIPIDEA,
+                         0xE0002000, pic[53 - GIC_INTERNAL]);
+    sysbus_create_simple(OBJECT(machine), "usb[*]", TYPE_CHIPIDEA,
+                         0xE0003000, pic[76 - GIC_INTERNAL]);
 
-    dev = qdev_new_orphan(TYPE_CADENCE_UART);
+    dev = qdev_new(OBJECT(machine), "uart[*]", TYPE_CADENCE_UART);
     busdev = SYS_BUS_DEVICE(dev);
     qdev_prop_set_chr(dev, "chardev", serial_hd(0));
     qdev_connect_clock_in(dev, "refclk",
                           qdev_get_clock_out(slcr, "uart0_ref_clk"));
-    sysbus_realize_and_unref(busdev, &error_fatal);
+    sysbus_realize(busdev, &error_fatal);
     sysbus_mmio_map(busdev, 0, 0xE0000000);
     sysbus_connect_irq(busdev, 0, pic[59 - GIC_INTERNAL]);
-    dev = qdev_new_orphan(TYPE_CADENCE_UART);
+    dev = qdev_new(OBJECT(machine), "uart[*]", TYPE_CADENCE_UART);
     busdev = SYS_BUS_DEVICE(dev);
     qdev_prop_set_chr(dev, "chardev", serial_hd(1));
     qdev_connect_clock_in(dev, "refclk",
                           qdev_get_clock_out(slcr, "uart1_ref_clk"));
-    sysbus_realize_and_unref(busdev, &error_fatal);
+    sysbus_realize(busdev, &error_fatal);
     sysbus_mmio_map(busdev, 0, 0xE0001000);
     sysbus_connect_irq(busdev, 0, pic[82 - GIC_INTERNAL]);
 
-    sysbus_create_varargs_orphan("cadence_ttc", 0xF8001000,
+    sysbus_create_varargs(OBJECT(machine), "ttc[*]", "cadence_ttc", 0xF8001000,
             pic[42-GIC_INTERNAL], pic[43-GIC_INTERNAL], pic[44-GIC_INTERNAL], NULL);
-    sysbus_create_varargs_orphan("cadence_ttc", 0xF8002000,
+    sysbus_create_varargs(OBJECT(machine), "ttc[*]", "cadence_ttc", 0xF8002000,
             pic[69-GIC_INTERNAL], pic[70-GIC_INTERNAL], pic[71-GIC_INTERNAL], NULL);
 
-    ddr_ctrl_init(0xF8006000);
+    ddr_ctrl_init(OBJECT(machine), 0xF8006000);
 
-    gem_init(0xE000B000, pic[54 - GIC_INTERNAL]);
-    gem_init(0xE000C000, pic[77 - GIC_INTERNAL]);
+    gem_init(OBJECT(machine), 0xE000B000, pic[54 - GIC_INTERNAL]);
+    gem_init(OBJECT(machine), 0xE000C000, pic[77 - GIC_INTERNAL]);
 
     for (n = 0; n < 2; n++) {
         int hci_irq = n ? 79 : 56;
@@ -329,27 +337,27 @@ static void zynq_init(MachineState *machine)
          * - SDIO Specification Version 2.0
          * - MMC Specification Version 3.31
          */
-        dev = qdev_new_orphan(TYPE_SYSBUS_SDHCI);
+        dev = qdev_new(OBJECT(machine), "sdhci[*]", TYPE_SYSBUS_SDHCI);
         qdev_prop_set_uint8(dev, "sd-spec-version", 2);
         qdev_prop_set_uint64(dev, "capareg", ZYNQ_SDHCI_CAPABILITIES);
-        sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
+        sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
         sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, hci_addr);
         sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, pic[hci_irq - GIC_INTERNAL]);
 
         di = drive_get(IF_SD, 0, n);
         blk = di ? blk_by_legacy_dinfo(di) : NULL;
-        carddev = qdev_new_orphan(TYPE_SD_CARD);
+        carddev = qdev_new(OBJECT(dev), "sd-card", TYPE_SD_CARD);
         qdev_prop_set_drive_err(carddev, "drive", blk, &error_fatal);
-        qdev_realize_and_unref(carddev, qdev_get_child_bus(dev, "sd-bus"),
-                               &error_fatal);
+        qdev_realize(carddev, qdev_get_child_bus(dev, "sd-bus"),
+                     &error_fatal);
     }
 
-    dev = qdev_new_orphan(TYPE_ZYNQ_XADC);
-    sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
+    dev = qdev_new(OBJECT(machine), "xadc", TYPE_ZYNQ_XADC);
+    sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
     sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, 0xF8007100);
     sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, pic[39-GIC_INTERNAL]);
 
-    dev = qdev_new_orphan("pl330");
+    dev = qdev_new(OBJECT(machine), "dma", "pl330");
     object_property_set_link(OBJECT(dev), "memory",
                              OBJECT(address_space_mem),
                              &error_fatal);
@@ -365,16 +373,16 @@ static void zynq_init(MachineState *machine)
     qdev_prop_set_uint16(dev, "data_buffer_dep",  256);
 
     busdev = SYS_BUS_DEVICE(dev);
-    sysbus_realize_and_unref(busdev, &error_fatal);
+    sysbus_realize(busdev, &error_fatal);
     sysbus_mmio_map(busdev, 0, 0xF8003000);
     sysbus_connect_irq(busdev, 0, pic[45-GIC_INTERNAL]); /* abort irq line */
     for (n = 0; n < ARRAY_SIZE(dma_irqs); ++n) { /* event irqs */
         sysbus_connect_irq(busdev, n + 1, pic[dma_irqs[n] - GIC_INTERNAL]);
     }
 
-    dev = qdev_new_orphan("xlnx.ps7-dev-cfg");
+    dev = qdev_new(OBJECT(machine), "devcfg", "xlnx.ps7-dev-cfg");
     busdev = SYS_BUS_DEVICE(dev);
-    sysbus_realize_and_unref(busdev, &error_fatal);
+    sysbus_realize(busdev, &error_fatal);
     sysbus_connect_irq(busdev, 0, pic[40 - GIC_INTERNAL]);
     sysbus_mmio_map(busdev, 0, 0xF8007000);
 
Signature · 1 line
2.47.1
#217 lore raw

RFC PATCH v2 60/137 hw/arm/xlnx-versal, xlnx-zynqmp: Give onboard devices a QOM parent

In reply to Alexander Graf

Convert the *_orphan() device-creation calls in the hw/arm xlnx-versal, xlnx-zynqmp board files 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 SoC device for composite children. Names follow existing QOM conventions.

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

hw/arm/xlnx-versal.c:517 | qdev_new | container | name | SoC realize helper; collapse existing add_child(container,name); drop _and_unref
hw/arm/xlnx-versal.c:565 | qdev_new | container | name | SoC realize helper; collapse existing add_child(container,name); drop _and_unref
hw/arm/xlnx-versal.c:667 | qdev_new | parent | name | helper already receives parent+name; collapse add_child; drop _and_unref
hw/arm/xlnx-versal.c:716 | qdev_new | OBJECT(gic) | "its" | collapse existing add_child(gic,"its"); sysbus_realize
hw/arm/xlnx-versal.c:758 | qdev_new | OBJECT(s) | name | SoC realize; hoist name printf, collapse add_child; sysbus_realize
hw/arm/xlnx-versal.c:762 | qdev_new | OBJECT(s) | name | SoC realize; hoist name printf, collapse add_child; sysbus_realize
hw/arm/xlnx-versal.c:912 | qdev_new | OBJECT(qemu_cluster) | name | hoist name printf; collapse add_child; qdev_realize
hw/arm/xlnx-versal.c:963 | qdev_new | OBJECT(s) | name | hoist name printf; collapse add_child; qdev_realize
hw/arm/xlnx-versal.c:1031 | qdev_new | OBJECT(s) | "uart[*]" | collapse add_child; sysbus_realize
hw/arm/xlnx-versal.c:1070 | qdev_new | OBJECT(s) | "canfd[*]" | collapse add_child; sysbus_realize
hw/arm/xlnx-versal.c:1110 | qdev_new | OBJECT(s) | "usb[*]" | collapse add_child; sysbus_realize
hw/arm/xlnx-versal.c:1170 | qdev_new | OBJECT(s) | "gem[*]" | collapse add_child; sysbus_realize
hw/arm/xlnx-versal.c:1254 | qdev_new | OBJECT(s) | name | collapse add_child; sysbus_realize
hw/arm/xlnx-versal.c:1289 | qdev_new | OBJECT(s) | "sdhci[*]" | collapse add_child; sysbus_realize
hw/arm/xlnx-versal.c:1323 | qdev_new | OBJECT(s) | "rtc" | collapse add_child; sysbus_realize
hw/arm/xlnx-versal.c:1352 | qdev_new | OBJECT(s) | "trng" | collapse add_child; sysbus_realize
hw/arm/xlnx-versal.c:1373 | qdev_new | OBJECT(s) | "xram[*]" | collapse add_child; sysbus_realize
hw/arm/xlnx-versal.c:1395 | qdev_new | OBJECT(s) | "bbram" | collapse add_child; sysbus_realize
hw/arm/xlnx-versal.c:1418 | qdev_new | OBJECT(s) | "efuse-ctrl" | collapse add_child; sysbus_realize
hw/arm/xlnx-versal.c:1419 | qdev_new | OBJECT(s) | "efuse-cache" | collapse add_child; sysbus_realize
hw/arm/xlnx-versal.c:1420 | qdev_new | OBJECT(s) | "efuse" | collapse add_child; qdev_realize
hw/arm/xlnx-versal.c:1454 | qdev_new | OBJECT(s) | "pmc-iou-slcr" | collapse add_child; sysbus_realize
hw/arm/xlnx-versal.c:1476 | qdev_new | OBJECT(s) | "ospi" | collapse add_child; sysbus_realize
hw/arm/xlnx-versal.c:1485 | qdev_new | OBJECT(dev) | "dma-dst-dev" | collapse add_child under ospi; sysbus_realize
hw/arm/xlnx-versal.c:1497 | qdev_new | OBJECT(dev) | "dma-src-dev" | collapse add_child under ospi; sysbus_realize
hw/arm/xlnx-versal.c:1551 | qdev_new | container | "cfu-fdro" | collapse add_child; sysbus_realize
hw/arm/xlnx-versal.c:1560 | qdev_new | container | "cframe-bcast" | collapse add_child; sysbus_realize
hw/arm/xlnx-versal.c:1564 | qdev_new | container | "cfu-apb" | collapse add_child; sysbus_realize
hw/arm/xlnx-versal.c:1568 | qdev_new | container | "cframe-irq-or-gate" | collapse add_child; qdev_realize
hw/arm/xlnx-versal.c:1583 | qdev_new | container | "cframe[*]" | collapse add_child; sysbus_realize
hw/arm/xlnx-versal.c:1635 | qdev_new | container | "cfu-sfr" | collapse add_child; sysbus_realize
hw/arm/xlnx-versal.c:1679 | qdev_new | OBJECT(s) | "crl" | collapse add_child; sysbus_realize
hw/arm/xlnx-versal.c:1764 | qdev_new | OBJECT(s) | name | collapse add_child; sysbus_realize
hw/arm/xlnx-versal.c:1975 | qdev_new | OBJECT(sdhci) | "card[*]" | collapse add_child; qdev_realize
hw/arm/xlnx-versal.c:2018 | qdev_new | OBJECT(ospi) | "flash[*]" | flash on OSPI SPI bus; parent under ospi; qdev_realize
hw/arm/xlnx-versal-virt.c:146 | qdev_new | OBJECT(s) | "virtio-mmio[*]" | machine init helper; collapse add_child; sysbus_realize
hw/arm/xlnx-zcu102.c:190 | qdev_new | OBJECT(machine) | "sd-card[*]" | board init; qdev_realize
hw/arm/xlnx-zcu102.c:205 | qdev_new | OBJECT(machine) | "spi-flash[*]" | board init; qdev_realize
hw/arm/xlnx-zcu102.c:229 | qdev_new | OBJECT(machine) | "qspi-flash[*]" | board init; qdev_realize
hw/arm/xlnx-zynqmp.c:368 | qdev_new | OBJECT(s) | info->name | SoC realize; collapse add_child; sysbus_realize

AI-used-for: code (refactoring)

---
 hw/arm/xlnx-versal-virt.c |   5 +-
 hw/arm/xlnx-versal.c      | 197 ++++++++++++++++----------------------
 hw/arm/xlnx-zcu102.c      |  14 +--
 hw/arm/xlnx-zynqmp.c      |   6 +-
 4 files changed, 98 insertions(+), 124 deletions(-)
hw/arm/xlnx-versal-virt.c +2 -3
index 48f6e6d463..88bebf1f87 100644
@@ -143,9 +143,8 @@ static void create_virtio_regions(VersalVirt *s)
         qemu_irq pic_irq;
 
         pic_irq = versal_get_reserved_irq(&s->soc, i, &dtb_irq);
-        dev = qdev_new_orphan("virtio-mmio");
-        object_property_add_child(OBJECT(s), "virtio-mmio[*]", OBJECT(dev));
-        sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
+        dev = qdev_new(OBJECT(s), "virtio-mmio[*]", "virtio-mmio");
+        sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
         sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, pic_irq);
         mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 0);
         memory_region_add_subregion(&s->soc.mr_ps, base, mr);
hw/arm/xlnx-versal.c +85 -112

529 lines not on this page · raw message

hw/arm/xlnx-zcu102.c +8 -6
index adff52eaf6..473acad060 100644
@@ -187,9 +187,9 @@ static void xlnx_zcu102_init(MachineState *machine)
             error_report("No SD bus found for SD card %d", i);
             exit(1);
         }
-        carddev = qdev_new_orphan(TYPE_SD_CARD);
+        carddev = qdev_new(OBJECT(machine), "sd-card[*]", TYPE_SD_CARD);
         qdev_prop_set_drive_err(carddev, "drive", blk, &error_fatal);
-        qdev_realize_and_unref(carddev, bus, &error_fatal);
+        qdev_realize(carddev, bus, &error_fatal);
     }
 
     for (i = 0; i < XLNX_ZYNQMP_NUM_SPIS; i++) {
@@ -202,13 +202,14 @@ static void xlnx_zcu102_init(MachineState *machine)
         spi_bus = qdev_get_child_bus(DEVICE(&s->soc), bus_name);
         g_free(bus_name);
 
-        flash_dev = qdev_new_orphan("sst25wf080");
+        flash_dev = qdev_new(OBJECT(machine), "spi-flash[*]",
+                             "sst25wf080");
         if (dinfo) {
             qdev_prop_set_drive_err(flash_dev, "drive",
                                     blk_by_legacy_dinfo(dinfo), &error_fatal);
         }
         qdev_prop_set_uint8(flash_dev, "cs", i);
-        qdev_realize_and_unref(flash_dev, spi_bus, &error_fatal);
+        qdev_realize(flash_dev, spi_bus, &error_fatal);
 
         cs_line = qdev_get_gpio_in_named(flash_dev, SSI_GPIO_CS, 0);
 
@@ -226,13 +227,14 @@ static void xlnx_zcu102_init(MachineState *machine)
         spi_bus = qdev_get_child_bus(DEVICE(&s->soc), bus_name);
         g_free(bus_name);
 
-        flash_dev = qdev_new_orphan("n25q512a11");
+        flash_dev = qdev_new(OBJECT(machine), "qspi-flash[*]",
+                             "n25q512a11");
         if (dinfo) {
             qdev_prop_set_drive_err(flash_dev, "drive",
                                     blk_by_legacy_dinfo(dinfo), &error_fatal);
         }
         qdev_prop_set_uint8(flash_dev, "cs", i);
-        qdev_realize_and_unref(flash_dev, spi_bus, &error_fatal);
+        qdev_realize(flash_dev, spi_bus, &error_fatal);
 
         cs_line = qdev_get_gpio_in_named(flash_dev, SSI_GPIO_CS, 0);
 
hw/arm/xlnx-zynqmp.c +3 -3
index 861ee35839..e4a10861a8 100644
@@ -365,15 +365,15 @@ static void xlnx_zynqmp_create_unimp_mmio(XlnxZynqMPState *s)
 
     for (nr = 0; nr < ARRAY_SIZE(unimp_areas); nr++) {
         const struct UnimpInfo *info = &unimp_areas[nr];
-        DeviceState *dev = qdev_new_orphan(TYPE_UNIMPLEMENTED_DEVICE);
+        DeviceState *dev = qdev_new(OBJECT(s), info->name,
+                                    TYPE_UNIMPLEMENTED_DEVICE);
         SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
 
         assert(info->name && info->base && info->size > 0);
         qdev_prop_set_string(dev, "name", info->name);
         qdev_prop_set_uint64(dev, "size", info->size);
-        object_property_add_child(OBJECT(s), info->name, OBJECT(dev));
 
-        sysbus_realize_and_unref(sbd, &error_fatal);
+        sysbus_realize(sbd, &error_fatal);
         sysbus_mmio_map(sbd, 0, info->base);
     }
 }
Signature · 1 line
2.47.1
#218 lore raw

RFC PATCH v2 61/137 hw/arm/realview, integratorcp: Give onboard devices a QOM parent

In reply to Alexander Graf

Convert the *_orphan() device-creation calls in the hw/arm realview, integratorcp board files 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 SoC device for composite children. Names follow existing QOM conventions.

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

hw/arm/integratorcp.c:624 | qdev_new | OBJECT(machine) | "core" | board init; single core module
hw/arm/integratorcp.c:629 | sysbus_create_varargs | OBJECT(machine) | "pic" | board init; primary PIC
hw/arm/integratorcp.c:636 | sysbus_create_simple | OBJECT(machine) | "sic" | board init; secondary PIC
hw/arm/integratorcp.c:637 | sysbus_create_varargs | OBJECT(machine) | "pit" | board init; single PIT
hw/arm/integratorcp.c:639 | sysbus_create_simple | OBJECT(machine) | "rtc" | board init; single pl031 RTC
hw/arm/integratorcp.c:642 | sysbus_create_simple | OBJECT(machine) | "icp" | board init; ICP control regs
hw/arm/integratorcp.c:644 | sysbus_create_simple | OBJECT(machine) | "keyboard" | board init; pl050 KMI0
hw/arm/integratorcp.c:645 | sysbus_create_simple | OBJECT(machine) | "mouse" | board init; pl050 KMI1
hw/arm/integratorcp.c:646 | sysbus_create_simple | OBJECT(machine) | "debug" | board init; single debug LEDs
hw/arm/integratorcp.c:648 | sysbus_create_varargs | OBJECT(machine) | "mmc" | board init; single pl181 MMC
hw/arm/integratorcp.c:657 | qdev_new | OBJECT(machine) | "sd-card" | board init; single SD card
hw/arm/integratorcp.c:664 | qdev_new | OBJECT(machine) | "aaci" | board init; single pl041 audio
hw/arm/integratorcp.c:676 | qdev_new | OBJECT(machine) | "clcd" | board init; single pl110 CLCD
hw/arm/realview.c:64 | qdev_new | parent | "split-irq[*]" | helper: threaded Object *parent from board init; called twice → auto-index
hw/arm/realview.c:183 | qdev_new | OBJECT(machine) | "sysctl" | board init; single sysctl
hw/arm/realview.c:191 | qdev_new | OBJECT(machine) | "mpcore" | board init; A9 mpcore (excl. w/ 194,209)
hw/arm/realview.c:194 | qdev_new | OBJECT(machine) | "mpcore" | board init; 11MP mpcore (excl. w/ 191,209)
hw/arm/realview.c:203 | sysbus_create_varargs | OBJECT(machine) | "l2x0" | board init; single L2 cache ctlr
hw/arm/realview.c:209 | sysbus_create_simple | OBJECT(machine) | "gic" | board init; single GIC (excl. w/ 191,194)
hw/arm/realview.c:215 | qdev_new | OBJECT(machine) | "aaci" | board init; single pl041 audio
hw/arm/realview.c:224 | sysbus_create_simple | OBJECT(machine) | "keyboard" | board init; pl050 KMI0
hw/arm/realview.c:225 | sysbus_create_simple | OBJECT(machine) | "mouse" | board init; pl050 KMI1
hw/arm/realview.c:233 | qdev_new | OBJECT(machine) | "dma" | board init; single pl081 DMA
hw/arm/realview.c:241 | sysbus_create_simple | OBJECT(machine) | "timer[*]" | board init; 2× sp804 → auto-index
hw/arm/realview.c:242 | sysbus_create_simple | OBJECT(machine) | "timer[*]" | board init; 2× sp804 → auto-index
hw/arm/realview.c:244 | sysbus_create_simple | OBJECT(machine) | "gpio[*]" | board init; 3× pl061 → auto-index
hw/arm/realview.c:245 | sysbus_create_simple | OBJECT(machine) | "gpio[*]" | board init; 3× pl061 → auto-index
hw/arm/realview.c:246 | sysbus_create_simple | OBJECT(machine) | "gpio[*]" | board init; 3× pl061 → auto-index
hw/arm/realview.c:248 | qdev_new | OBJECT(machine) | "clcd" | board init; single pl111 CLCD
hw/arm/realview.c:255 | sysbus_create_varargs | OBJECT(machine) | "mmc" | board init; single pl181 MMC
hw/arm/realview.c:274 | qdev_new | OBJECT(machine) | "sd-card" | board init; single SD card
hw/arm/realview.c:281 | sysbus_create_simple | OBJECT(machine) | "rtc" | board init; single pl031 RTC
hw/arm/realview.c:284 | qdev_new | OBJECT(machine) | "pci-host" | board init; single PCI host bridge
hw/arm/realview.c:300 | pci_create_simple | OBJECT(machine) | "ohci" | board init; single OHCI USB
hw/arm/realview.c:304 | pci_create_simple | OBJECT(machine) | "scsi[*]" | board init; loop → auto-index
hw/arm/realview.c:322 | sysbus_create_simple | OBJECT(machine) | "i2c" | board init; single SBCon I2C
hw/arm/realview.c:324 | i2c_slave_create_simple | OBJECT(machine) | "ds1338" | board init; single DS1338 RTC

AI-used-for: code (refactoring)

---
 hw/arm/integratorcp.c | 45 ++++++++++++----------
 hw/arm/realview.c     | 87 +++++++++++++++++++++++++------------------
 2 files changed, 76 insertions(+), 56 deletions(-)
hw/arm/integratorcp.c +26 -19
index 7560ad5983..ed715a3eb8 100644
@@ -621,31 +621,38 @@ static void integratorcp_init(MachineState *machine)
                              0, ram_size);
     memory_region_add_subregion(address_space_mem, 0x80000000, ram_alias);
 
-    dev = qdev_new_orphan(TYPE_INTEGRATOR_CM);
+    dev = qdev_new(OBJECT(machine), "core", TYPE_INTEGRATOR_CM);
     qdev_prop_set_uint32(dev, "memsz", ram_size >> 20);
-    sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
+    sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
     sysbus_mmio_map((SysBusDevice *)dev, 0, 0x10000000);
 
-    dev = sysbus_create_varargs_orphan(TYPE_INTEGRATOR_PIC, 0x14000000,
+    dev = sysbus_create_varargs(OBJECT(machine), "pic",
+                                TYPE_INTEGRATOR_PIC, 0x14000000,
                                 qdev_get_gpio_in(DEVICE(cpu), ARM_CPU_IRQ),
                                 qdev_get_gpio_in(DEVICE(cpu), ARM_CPU_FIQ),
                                 NULL);
     for (i = 0; i < 32; i++) {
         pic[i] = qdev_get_gpio_in(dev, i);
     }
-    sic = sysbus_create_simple_orphan(TYPE_INTEGRATOR_PIC, 0xca000000, pic[26]);
-    sysbus_create_varargs_orphan("integrator_pit", 0x13000000,
+    sic = sysbus_create_simple(OBJECT(machine), "sic",
+                               TYPE_INTEGRATOR_PIC, 0xca000000, pic[26]);
+    sysbus_create_varargs(OBJECT(machine), "pit", "integrator_pit", 0x13000000,
                           pic[5], pic[6], pic[7], NULL);
-    sysbus_create_simple_orphan("pl031", 0x15000000, pic[8]);
+    sysbus_create_simple(OBJECT(machine), "rtc", "pl031", 0x15000000, pic[8]);
     pl011_create(OBJECT(machine), 0x16000000, pic[1], serial_hd(0));
     pl011_create(OBJECT(machine), 0x17000000, pic[2], serial_hd(1));
-    icp = sysbus_create_simple_orphan(TYPE_ICP_CONTROL_REGS, 0xcb000000,
+    icp = sysbus_create_simple(OBJECT(machine), "icp",
+                               TYPE_ICP_CONTROL_REGS, 0xcb000000,
                                qdev_get_gpio_in(sic, 3));
-    sysbus_create_simple_orphan("pl050_keyboard", 0x18000000, pic[3]);
-    sysbus_create_simple_orphan("pl050_mouse", 0x19000000, pic[4]);
-    sysbus_create_simple_orphan(TYPE_INTEGRATOR_DEBUG, 0x1a000000, 0);
-
-    dev = sysbus_create_varargs_orphan("pl181", 0x1c000000, pic[23], pic[24], NULL);
+    sysbus_create_simple(OBJECT(machine), "keyboard",
+                         "pl050_keyboard", 0x18000000, pic[3]);
+    sysbus_create_simple(OBJECT(machine), "mouse",
+                         "pl050_mouse", 0x19000000, pic[4]);
+    sysbus_create_simple(OBJECT(machine), "debug",
+                         TYPE_INTEGRATOR_DEBUG, 0x1a000000, 0);
+
+    dev = sysbus_create_varargs(OBJECT(machine), "mmc", "pl181",
+                                0x1c000000, pic[23], pic[24], NULL);
     qdev_connect_gpio_out_named(dev, "card-read-only", 0,
                           qdev_get_gpio_in_named(icp, ICP_GPIO_MMC_WPROT, 0));
     qdev_connect_gpio_out_named(dev, "card-inserted", 0,
@@ -654,18 +661,18 @@ static void integratorcp_init(MachineState *machine)
     if (dinfo) {
         DeviceState *card;
 
-        card = qdev_new_orphan(TYPE_SD_CARD);
+        card = qdev_new(OBJECT(machine), "sd-card", TYPE_SD_CARD);
         qdev_prop_set_drive_err(card, "drive", blk_by_legacy_dinfo(dinfo),
                                 &error_fatal);
-        qdev_realize_and_unref(card, qdev_get_child_bus(dev, "sd-bus"),
-                               &error_fatal);
+        qdev_realize(card, qdev_get_child_bus(dev, "sd-bus"),
+                     &error_fatal);
     }
 
-    dev = qdev_new_orphan("pl041");
+    dev = qdev_new(OBJECT(machine), "aaci", "pl041");
     if (machine->audiodev) {
         qdev_prop_set_string(dev, "audiodev", machine->audiodev);
     }
-    sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
+    sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
     sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, 0x1d000000);
     sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, pic[25]);
 
@@ -673,10 +680,10 @@ static void integratorcp_init(MachineState *machine)
         smc91c111_init(OBJECT(machine), 0xc8000000, pic[27]);
     }
 
-    dev = qdev_new_orphan("pl110");
+    dev = qdev_new(OBJECT(machine), "clcd", "pl110");
     object_property_set_link(OBJECT(dev), "framebuffer-memory",
                              OBJECT(address_space_mem), &error_fatal);
-    sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
+    sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
     sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, 0xc0000000);
     sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, pic[22]);
 
hw/arm/realview.c +50 -37

191 lines not on this page · raw message

Signature · 1 line
2.47.1
#219 lore raw

RFC PATCH v2 62/137 hw/arm/npcm: Give onboard devices a QOM parent

In reply to Alexander Graf

Convert the *_orphan() device-creation calls in the hw/arm npcm board files 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 SoC device for composite children. Names follow existing QOM conventions.

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

hw/arm/npcm7xx_boards.c:87 | qdev_new | parent | "flash[*]" | helper: threaded Object *parent from board init; multiple callers/CS → auto-index

hw/arm/npcm7xx_boards.c:116 | qdev_new | parent | "sd-card[*]" | helper: threaded Object *parent from board init; per-unit → auto-index
hw/arm/npcm7xx_boards.c:201 | i2c_slave_create_simple | parent | "tmp105[*]" | helper: threaded Object *parent from board init; 4× tmp105 → auto-index
hw/arm/npcm7xx_boards.c:203 | i2c_slave_create_simple | parent | "tmp105[*]" | helper from board init; auto-index
hw/arm/npcm7xx_boards.c:205 | i2c_slave_create_simple | parent | "tmp105[*]" | helper from board init; auto-index
hw/arm/npcm7xx_boards.c:207 | i2c_slave_create_simple | parent | "tmp105[*]" | helper from board init; auto-index
hw/arm/npcm7xx_boards.c:237 | i2c_slave_create_simple | parent | "tmp105[*]" | helper: threaded Object *parent from board init; 4× tmp105 → auto-index
hw/arm/npcm7xx_boards.c:238 | i2c_slave_create_simple | parent | "tmp105[*]" | helper from board init; auto-index
hw/arm/npcm7xx_boards.c:239 | i2c_slave_create_simple | parent | "tmp105[*]" | helper from board init; auto-index
hw/arm/npcm7xx_boards.c:240 | i2c_slave_create_simple | parent | "tmp105[*]" | helper from board init; auto-index
hw/arm/npcm7xx_boards.c:256 | i2c_slave_create_simple | parent | "pca9548" | helper from board init; single mux
hw/arm/npcm7xx_boards.c:336 | i2c_slave_create_simple | parent | "pca9548[*]" | helper: threaded Object *parent from board init; 4× pca9548 → auto-index
hw/arm/npcm7xx_boards.c:340 | i2c_slave_create_simple | parent | "tmp105[*]" | helper from board init; 8× tmp105 → auto-index
hw/arm/npcm7xx_boards.c:341 | i2c_slave_create_simple | parent | "tmp105[*]" | helper from board init; auto-index
hw/arm/npcm7xx_boards.c:342 | i2c_slave_create_simple | parent | "tmp105[*]" | helper from board init; auto-index
hw/arm/npcm7xx_boards.c:343 | i2c_slave_create_simple | parent | "tmp105[*]" | helper from board init; auto-index
hw/arm/npcm7xx_boards.c:345 | i2c_slave_create_simple | parent | "pca9548[*]" | helper from board init; auto-index
hw/arm/npcm7xx_boards.c:347 | i2c_slave_create_simple | parent | "pca9548[*]" | helper from board init; auto-index
hw/arm/npcm7xx_boards.c:351 | i2c_slave_create_simple | parent | "pca9548[*]" | helper from board init; auto-index
hw/arm/npcm7xx_boards.c:355 | i2c_slave_create_simple | parent | "tmp105[*]" | helper from board init; auto-index
hw/arm/npcm7xx_boards.c:356 | i2c_slave_create_simple | parent | "tmp105[*]" | helper from board init; auto-index
hw/arm/npcm7xx_boards.c:357 | i2c_slave_create_simple | parent | "tmp105[*]" | helper from board init; auto-index
hw/arm/npcm7xx_boards.c:358 | i2c_slave_create_simple | parent | "tmp105[*]" | helper from board init; auto-index

hw/arm/npcm7xx.c:524 | sysbus_create_simple | OBJECT(dev) | "l2x0" | SoC DeviceClass.realize(dev); single L2 cache ctlr hw/arm/npcm8xx_boards.c:64 | qdev_new | parent | "flash[*]" | helper: threaded Object *parent from board init; auto-index hw/arm/npcm8xx_boards.c:162 | i2c_slave_create_simple | parent | "tmp105" | helper: threaded Object *parent from board init; single tmp105

AI-used-for: code (refactoring)

---
 hw/arm/npcm7xx.c        |   2 +-
 hw/arm/npcm7xx_boards.c | 107 ++++++++++++++++++++++++----------------
 hw/arm/npcm8xx_boards.c |  19 ++++---
 3 files changed, 77 insertions(+), 51 deletions(-)
hw/arm/npcm7xx.c +1 -1
index 8363a04f10..a930f7843a 100644
@@ -521,7 +521,7 @@ static void npcm7xx_realize(DeviceState *dev, Error **errp)
     }
 
     /* L2 cache controller */
-    sysbus_create_simple_orphan("l2x0", NPCM7XX_L2C_BA, NULL);
+    sysbus_create_simple(OBJECT(dev), "l2x0", "l2x0", NPCM7XX_L2C_BA, NULL);
 
     /* System Global Control Registers (GCR). Can fail due to user input. */
     object_property_set_int(OBJECT(&s->gcr), "disabled-modules",
hw/arm/npcm7xx_boards.c +65 -42

215 lines not on this page · raw message

hw/arm/npcm8xx_boards.c +11 -8
index eb0248552f..ff2840b409 100644
@@ -55,17 +55,18 @@ static void npcm8xx_load_bootrom(MachineState *machine, NPCM8xxState *soc)
     }
 }
 
-static void npcm8xx_connect_flash(NPCM7xxFIUState *fiu, int cs_no,
-                                  const char *flash_type, DriveInfo *dinfo)
+static void npcm8xx_connect_flash(Object *parent, NPCM7xxFIUState *fiu,
+                                  int cs_no, const char *flash_type,
+                                  DriveInfo *dinfo)
 {
     DeviceState *flash;
     qemu_irq flash_cs;
 
-    flash = qdev_new_orphan(flash_type);
+    flash = qdev_new(parent, "flash[*]", flash_type);
     if (dinfo) {
         qdev_prop_set_drive(flash, "drive", blk_by_legacy_dinfo(dinfo));
     }
-    qdev_realize_and_unref(flash, BUS(fiu->spi), &error_fatal);
+    qdev_realize(flash, BUS(fiu->spi), &error_fatal);
 
     flash_cs = qdev_get_gpio_in_named(flash, SSI_GPIO_CS, 0);
     qdev_connect_gpio_out_named(DEVICE(fiu), "cs", cs_no, flash_cs);
@@ -156,10 +157,11 @@ static void npcm8xx_connect_pwm_fan(NPCM8xxState *soc, SplitIRQ *splitter,
     qdev_connect_gpio_out(DEVICE(splitter), output_no, fan_duty_gpio);
 }
 
-static void npcm845_evb_i2c_init(NPCM8xxState *soc)
+static void npcm845_evb_i2c_init(Object *parent, NPCM8xxState *soc)
 {
     /* tmp100 temperature sensor on SVB, tmp105 is compatible */
-    i2c_slave_create_simple_orphan(npcm8xx_i2c_get_bus(soc, 6), "tmp105", 0x48);
+    i2c_slave_create_simple(parent, "tmp105",
+                            npcm8xx_i2c_get_bus(soc, 6), "tmp105", 0x48);
 }
 
 static void npcm845_evb_fan_init(NPCM8xxMachine *machine, NPCM8xxState *soc)
@@ -195,8 +197,9 @@ static void npcm845_evb_init(MachineState *machine)
     qdev_realize(DEVICE(soc), NULL, &error_fatal);
 
     npcm8xx_load_bootrom(machine, soc);
-    npcm8xx_connect_flash(&soc->fiu[0], 0, "w25q256", drive_get(IF_MTD, 0, 0));
-    npcm845_evb_i2c_init(soc);
+    npcm8xx_connect_flash(OBJECT(machine), &soc->fiu[0], 0, "w25q256",
+                          drive_get(IF_MTD, 0, 0));
+    npcm845_evb_i2c_init(OBJECT(machine), soc);
     npcm845_evb_fan_init(NPCM8XX_MACHINE(machine), soc);
     npcm8xx_load_kernel(machine, soc);
 }
Signature · 1 line
2.47.1
#220 lore raw

RFC PATCH v2 63/137 hw/arm/versatile, vexpress: Give onboard devices a QOM parent

In reply to Alexander Graf

Convert the *_orphan() device-creation calls in the hw/arm versatile, vexpress board files 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 SoC device for composite children. Names follow existing QOM conventions.

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

hw/arm/versatilepb.c:229 | qdev_new | OBJECT(machine) | "sysctl" | board init(); machine owns onboard sysctl
hw/arm/versatilepb.c:235 | sysbus_create_varargs | OBJECT(machine) | "vic" | board init(); PL190 primary intc
hw/arm/versatilepb.c:242 | sysbus_create_simple | OBJECT(machine) | "sic" | board init(); secondary intc
hw/arm/versatilepb.c:248 | sysbus_create_simple | OBJECT(machine) | "keyboard" | board init(); single KMI kbd
hw/arm/versatilepb.c:249 | sysbus_create_simple | OBJECT(machine) | "mouse" | board init(); single KMI mouse
hw/arm/versatilepb.c:251 | qdev_new | OBJECT(machine) | "pci-host" | board init(); versatile PCI host bridge
hw/arm/versatilepb.c:273 | pci_create_simple | OBJECT(machine) | "usb" | board init(); optional OHCI on PCI bus
hw/arm/versatilepb.c:277 | pci_create_simple | OBJECT(machine) | "scsi[*]" | board init(); loop over IF_SCSI buses
hw/arm/versatilepb.c:287 | qdev_new | OBJECT(machine) | "dma" | board init(); PL080 DMA
hw/arm/versatilepb.c:295 | sysbus_create_simple | OBJECT(machine) | "timer[*]" | board init(); two SP804 blocks
hw/arm/versatilepb.c:296 | sysbus_create_simple | OBJECT(machine) | "timer[*]" | board init(); auto-index sibling
hw/arm/versatilepb.c:298 | sysbus_create_simple | OBJECT(machine) | "gpio[*]" | board init(); four PL061 ports
hw/arm/versatilepb.c:299 | sysbus_create_simple | OBJECT(machine) | "gpio[*]" | board init(); auto-index sibling
hw/arm/versatilepb.c:300 | sysbus_create_simple | OBJECT(machine) | "gpio[*]" | board init(); auto-index sibling
hw/arm/versatilepb.c:301 | sysbus_create_simple | OBJECT(machine) | "gpio[*]" | board init(); auto-index sibling
hw/arm/versatilepb.c:305 | qdev_new | OBJECT(machine) | "clcd" | board init(); PL110 display
hw/arm/versatilepb.c:315 | sysbus_create_varargs | OBJECT(machine) | "mmci[*]" | board init(); two PL181 MMCI
hw/arm/versatilepb.c:320 | qdev_new | OBJECT(machine) | "sd-card[*]" | board init(); removable card owned by machine
hw/arm/versatilepb.c:327 | sysbus_create_varargs | OBJECT(machine) | "mmci[*]" | board init(); auto-index sibling
hw/arm/versatilepb.c:332 | qdev_new | OBJECT(machine) | "sd-card[*]" | board init(); auto-index sibling
hw/arm/versatilepb.c:340 | sysbus_create_simple | OBJECT(machine) | "rtc" | board init(); PL031 RTC
hw/arm/versatilepb.c:342 | sysbus_create_simple | OBJECT(machine) | "i2c" | board init(); SBCon I2C bridge
hw/arm/versatilepb.c:344 | i2c_slave_create_simple | OBJECT(machine) | "ds1338" | board init(); onboard I2C RTC chip
hw/arm/versatilepb.c:347 | qdev_new | OBJECT(machine) | "aaci" | board init(); PL041 audio
hw/arm/vexpress.c:244 | qdev_new | OBJECT(ms) | "mpcore" | init_cpus() takes MachineState *ms; A9/A15 priv block
hw/arm/vexpress.c:304 | qdev_new | OBJECT(vms) | "db-clcd" | a9_daughterboard_init() has vms; distinct from motherboard clcd
hw/arm/vexpress.c:316 | sysbus_create_simple | OBJECT(vms) | "timer[*]" | a9 daughterboard SP804; auto-index shared with motherboard timers
hw/arm/vexpress.c:324 | sysbus_create_varargs | OBJECT(vms) | "l2x0" | a9 daughterboard L2 cache ctrl
hw/arm/vexpress.c:520 | qdev_new | parent | "flash[*]" | helper: thread Object *parent as first arg; two callers pass OBJECT(machine)
hw/arm/vexpress.c:595 | qdev_new | OBJECT(machine) | "sysctl" | vexpress_common_init(MachineState *machine)
hw/arm/vexpress.c:617 | qdev_new | OBJECT(machine) | "aaci" | board init(); PL041 audio
hw/arm/vexpress.c:626 | sysbus_create_varargs | OBJECT(machine) | "mmci" | board init(); single PL181
hw/arm/vexpress.c:636 | qdev_new | OBJECT(machine) | "sd-card" | board init(); single removable SD
hw/arm/vexpress.c:643 | sysbus_create_simple | OBJECT(machine) | "keyboard" | board init(); KMI0
hw/arm/vexpress.c:644 | sysbus_create_simple | OBJECT(machine) | "mouse" | board init(); KMI1
hw/arm/vexpress.c:651 | sysbus_create_simple | OBJECT(machine) | "timer[*]" | board init(); motherboard SP804
hw/arm/vexpress.c:652 | sysbus_create_simple | OBJECT(machine) | "timer[*]" | board init(); auto-index sibling
hw/arm/vexpress.c:654 | sysbus_create_simple | OBJECT(machine) | "i2c" | board init(); SBCon serial DVI I2C
hw/arm/vexpress.c:656 | i2c_slave_create_simple | OBJECT(machine) | "sii9022" | board init(); HDMI transmitter chip
hw/arm/vexpress.c:658 | sysbus_create_simple | OBJECT(machine) | "rtc" | board init(); PL031
hw/arm/vexpress.c:662 | qdev_new | OBJECT(machine) | "clcd" | board init(); motherboard PL111
hw/arm/vexpress.c:709 | sysbus_create_simple | OBJECT(machine) | "virtio-mmio[*]" | board init(); loop of transports

AI-used-for: code (refactoring)

---
 hw/arm/versatilepb.c | 70 +++++++++++++++++++++++---------------------
 hw/arm/vexpress.c    | 66 +++++++++++++++++++++--------------------
 2 files changed, 72 insertions(+), 64 deletions(-)
hw/arm/versatilepb.c +37 -33
index 6fb7223265..f68c4765c6 100644
@@ -226,31 +226,33 @@ static void versatile_init(MachineState *machine, int board_id)
     /* SDRAM at address zero.  */
     memory_region_add_subregion(sysmem, 0, machine->ram);
 
-    sysctl = qdev_new_orphan("realview_sysctl");
+    sysctl = qdev_new(OBJECT(machine), "sysctl", "realview_sysctl");
     qdev_prop_set_uint32(sysctl, "sys_id", 0x41007004);
     qdev_prop_set_uint32(sysctl, "proc_id", 0x02000000);
-    sysbus_realize_and_unref(SYS_BUS_DEVICE(sysctl), &error_fatal);
+    sysbus_realize(SYS_BUS_DEVICE(sysctl), &error_fatal);
     sysbus_mmio_map(SYS_BUS_DEVICE(sysctl), 0, 0x10000000);
 
-    dev = sysbus_create_varargs_orphan("pl190", 0x10140000,
+    dev = sysbus_create_varargs(OBJECT(machine), "vic", "pl190", 0x10140000,
                                 qdev_get_gpio_in(DEVICE(cpu), ARM_CPU_IRQ),
                                 qdev_get_gpio_in(DEVICE(cpu), ARM_CPU_FIQ),
                                 NULL);
     for (n = 0; n < 32; n++) {
         pic[n] = qdev_get_gpio_in(dev, n);
     }
-    dev = sysbus_create_simple_orphan(TYPE_VERSATILE_PB_SIC, 0x10003000, NULL);
+    dev = sysbus_create_simple(OBJECT(machine), "sic",
+                               TYPE_VERSATILE_PB_SIC, 0x10003000, NULL);
     for (n = 0; n < 32; n++) {
         sysbus_connect_irq(SYS_BUS_DEVICE(dev), n, pic[n]);
         sic[n] = qdev_get_gpio_in(dev, n);
     }
 
-    sysbus_create_simple_orphan("pl050_keyboard", 0x10006000, sic[3]);
-    sysbus_create_simple_orphan("pl050_mouse", 0x10007000, sic[4]);
+    sysbus_create_simple(OBJECT(machine), "keyboard", "pl050_keyboard",
+                         0x10006000, sic[3]);
+    sysbus_create_simple(OBJECT(machine), "mouse", "pl050_mouse", 0x10007000, sic[4]);
 
-    dev = qdev_new_orphan("versatile_pci");
+    dev = qdev_new(OBJECT(machine), "pci-host", "versatile_pci");
     busdev = SYS_BUS_DEVICE(dev);
-    sysbus_realize_and_unref(busdev, &error_fatal);
+    sysbus_realize(busdev, &error_fatal);
     sysbus_mmio_map(busdev, 0, 0x10001000); /* PCI controller regs */
     sysbus_mmio_map(busdev, 1, 0x41000000); /* PCI self-config */
     sysbus_mmio_map(busdev, 2, 0x42000000); /* PCI config */
@@ -270,11 +272,12 @@ static void versatile_init(MachineState *machine, int board_id)
     pci_init_nic_devices(pci_bus, "rtl8139");
 
     if (machine_usb(machine)) {
-        pci_create_simple_orphan(pci_bus, -1, "pci-ohci");
+        pci_create_simple(OBJECT(machine), "usb", pci_bus, -1, "pci-ohci");
     }
     n = drive_get_max_bus(IF_SCSI);
     while (n >= 0) {
-        dev = DEVICE(pci_create_simple_orphan(pci_bus, -1, "lsi53c895a"));
+        dev = DEVICE(pci_create_simple(OBJECT(machine), "scsi[*]",
+                                       pci_bus, -1, "lsi53c895a"));
         lsi53c8xx_handle_legacy_cmdline(dev);
         n--;
     }
@@ -284,72 +287,73 @@ static void versatile_init(MachineState *machine, int board_id)
     pl011_create(OBJECT(machine), 0x101f3000, pic[14], serial_hd(2));
     pl011_create(OBJECT(machine), 0x10009000, sic[6], serial_hd(3));
 
-    dev = qdev_new_orphan("pl080");
+    dev = qdev_new(OBJECT(machine), "dma", "pl080");
     object_property_set_link(OBJECT(dev), "downstream", OBJECT(sysmem),
                              &error_fatal);
     busdev = SYS_BUS_DEVICE(dev);
-    sysbus_realize_and_unref(busdev, &error_fatal);
+    sysbus_realize(busdev, &error_fatal);
     sysbus_mmio_map(busdev, 0, 0x10130000);
     sysbus_connect_irq(busdev, 0, pic[17]);
 
-    sysbus_create_simple_orphan("sp804", 0x101e2000, pic[4]);
-    sysbus_create_simple_orphan("sp804", 0x101e3000, pic[5]);
+    sysbus_create_simple(OBJECT(machine), "timer[*]", "sp804", 0x101e2000, pic[4]);
+    sysbus_create_simple(OBJECT(machine), "timer[*]", "sp804", 0x101e3000, pic[5]);
 
-    sysbus_create_simple_orphan("pl061", 0x101e4000, pic[6]);
-    sysbus_create_simple_orphan("pl061", 0x101e5000, pic[7]);
-    sysbus_create_simple_orphan("pl061", 0x101e6000, pic[8]);
-    sysbus_create_simple_orphan("pl061", 0x101e7000, pic[9]);
+    sysbus_create_simple(OBJECT(machine), "gpio[*]", "pl061", 0x101e4000, pic[6]);
+    sysbus_create_simple(OBJECT(machine), "gpio[*]", "pl061", 0x101e5000, pic[7]);
+    sysbus_create_simple(OBJECT(machine), "gpio[*]", "pl061", 0x101e6000, pic[8]);
+    sysbus_create_simple(OBJECT(machine), "gpio[*]", "pl061", 0x101e7000, pic[9]);
 
     /* The versatile/PB actually has a modified Color LCD controller
        that includes hardware cursor support from the PL111.  */
-    dev = qdev_new_orphan("pl110_versatile");
+    dev = qdev_new(OBJECT(machine), "clcd", "pl110_versatile");
     object_property_set_link(OBJECT(dev), "framebuffer-memory",
                              OBJECT(sysmem), &error_fatal);
-    sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
+    sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
     sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, 0x10120000);
     sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, pic[16]);
 
     /* Wire up the mux control signals from the SYS_CLCD register */
     qdev_connect_gpio_out(sysctl, 0, qdev_get_gpio_in(dev, 0));
 
-    dev = sysbus_create_varargs_orphan("pl181", 0x10005000, sic[22], sic[1], NULL);
+    dev = sysbus_create_varargs(OBJECT(machine), "mmci[*]", "pl181",
+                                0x10005000, sic[22], sic[1], NULL);
     dinfo = drive_get(IF_SD, 0, 0);
     if (dinfo) {
         DeviceState *card;
 
-        card = qdev_new_orphan(TYPE_SD_CARD);
+        card = qdev_new(OBJECT(machine), "sd-card[*]", TYPE_SD_CARD);
         qdev_prop_set_drive_err(card, "drive", blk_by_legacy_dinfo(dinfo),
                                 &error_fatal);
-        qdev_realize_and_unref(card, qdev_get_child_bus(dev, "sd-bus"),
-                               &error_fatal);
+        qdev_realize(card, qdev_get_child_bus(dev, "sd-bus"), &error_fatal);
     }
 
-    dev = sysbus_create_varargs_orphan("pl181", 0x1000b000, sic[23], sic[2], NULL);
+    dev = sysbus_create_varargs(OBJECT(machine), "mmci[*]", "pl181",
+                                0x1000b000, sic[23], sic[2], NULL);
     dinfo = drive_get(IF_SD, 0, 1);
     if (dinfo) {
         DeviceState *card;
 
-        card = qdev_new_orphan(TYPE_SD_CARD);
+        card = qdev_new(OBJECT(machine), "sd-card[*]", TYPE_SD_CARD);
         qdev_prop_set_drive_err(card, "drive", blk_by_legacy_dinfo(dinfo),
                                 &error_fatal);
-        qdev_realize_and_unref(card, qdev_get_child_bus(dev, "sd-bus"),
-                               &error_fatal);
+        qdev_realize(card, qdev_get_child_bus(dev, "sd-bus"), &error_fatal);
     }
 
     /* Add PL031 Real Time Clock. */
-    sysbus_create_simple_orphan("pl031", 0x101e8000, pic[10]);
+    sysbus_create_simple(OBJECT(machine), "rtc", "pl031", 0x101e8000, pic[10]);
 
-    dev = sysbus_create_simple_orphan(TYPE_ARM_SBCON_I2C, 0x10002000, NULL);
+    dev = sysbus_create_simple(OBJECT(machine), "i2c",
+                               TYPE_ARM_SBCON_I2C, 0x10002000, NULL);
     i2c = (I2CBus *)qdev_get_child_bus(dev, "i2c");
-    i2c_slave_create_simple_orphan(i2c, "ds1338", 0x68);
+    i2c_slave_create_simple(OBJECT(machine), "ds1338", i2c, "ds1338", 0x68);
 
     /* Add PL041 AACI Interface to the LM4549 codec */
-    pl041 = qdev_new_orphan("pl041");
+    pl041 = qdev_new(OBJECT(machine), "aaci", "pl041");
     qdev_prop_set_uint32(pl041, "nc_fifo_depth", 512);
     if (machine->audiodev) {
         qdev_prop_set_string(pl041, "audiodev", machine->audiodev);
     }
-    sysbus_realize_and_unref(SYS_BUS_DEVICE(pl041), &error_fatal);
+    sysbus_realize(SYS_BUS_DEVICE(pl041), &error_fatal);
     sysbus_mmio_map(SYS_BUS_DEVICE(pl041), 0, 0x10004000);
     sysbus_connect_irq(SYS_BUS_DEVICE(pl041), 0, sic[24]);
 
hw/arm/vexpress.c +35 -31

173 lines not on this page · raw message

Signature · 1 line
2.47.1
#221 lore raw

RFC PATCH v2 64/137 hw/arm/stellaris, musicpal: Give onboard devices a QOM parent

In reply to Alexander Graf

Convert the *_orphan() device-creation calls in the hw/arm stellaris, musicpal board files 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 SoC device for composite children. Names follow existing QOM conventions.

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

hw/arm/musicpal.c:1235 | cpu_create | OBJECT(machine) | "cpu" | musicpal_init(MachineState *machine); single CPU
hw/arm/musicpal.c:1243 | sysbus_create_simple | OBJECT(machine) | "pic" | board init(); primary intc
hw/arm/musicpal.c:1245 | sysbus_create_varargs | OBJECT(machine) | "pit" | board init(); MV88W8618 timer block
hw/arm/musicpal.c:1252 | qdev_new | OBJECT(machine) | "uart-orgate" | board init(); OR-IRQ combiner
hw/arm/musicpal.c:1290 | sysbus_create_simple | OBJECT(machine) | "flashcfg" | board init(); flash config regs
hw/arm/musicpal.c:1292 | qdev_new | OBJECT(machine) | "eth" | board init(); on-chip ethernet
hw/arm/musicpal.c:1301 | sysbus_create_simple | OBJECT(machine) | "wlan" | board init(); WLAN stub
hw/arm/musicpal.c:1303 | sysbus_create_simple | OBJECT(machine) | "misc" | board init(); misc regs
hw/arm/musicpal.c:1305 | sysbus_create_simple | OBJECT(machine) | "gpio" | board init(); GPIO block
hw/arm/musicpal.c:1307 | sysbus_create_simple | OBJECT(machine) | "i2c" | board init(); bit-bang GPIO I2C
hw/arm/musicpal.c:1310 | sysbus_create_simple | OBJECT(machine) | "lcd" | board init(); front-panel LCD
hw/arm/musicpal.c:1311 | sysbus_create_simple | OBJECT(machine) | "keys" | board init(); front-panel buttons
hw/arm/musicpal.c:1331 | i2c_slave_new | OBJECT(machine) | "wm8750" | board init(); audio codec on I2C bus
hw/arm/musicpal.c:1337 | qdev_new | OBJECT(machine) | "audio" | board init(); audio DMA controller
hw/arm/stellaris.c:1099 | qdev_new | soc_container | "sys" | collapse existing add_child; keep name
hw/arm/stellaris.c:1126 | qdev_new | soc_container | "v7m" | collapse existing add_child; keep name
hw/arm/stellaris.c:1146 | sysbus_create_varargs | soc_container | "adc" | board init(); on-SoC ADC
hw/arm/stellaris.c:1160 | qdev_new | soc_container | "gptm[*]" | collapse existing add_child; keep name
hw/arm/stellaris.c:1175 | qdev_new | soc_container | "wdg" | collapse existing add_child; keep name
hw/arm/stellaris.c:1192 | sysbus_create_simple | soc_container | "gpio[*]" | board init(); loop over PL061 ports
hw/arm/stellaris.c:1204 | sysbus_create_simple | soc_container | "i2c[*]" | board init(); loop over I2C blocks
hw/arm/stellaris.c:1212 | i2c_slave_create_simple | OBJECT(ms) | "oled-i2c" | board init(); external I2C OLED panel
hw/arm/stellaris.c:1219 | qdev_new | soc_container | "uart[*]" | collapse existing add_child; keep name
hw/arm/stellaris.c:1229 | sysbus_create_simple | soc_container | "ssi" | board init(); PL022 SPI
hw/arm/stellaris.c:1303 | ssi_create_peripheral | OBJECT(ms) | "ssi-sd" | board init(); external SD adapter on SSI bus
hw/arm/stellaris.c:1307 | qdev_new | OBJECT(ms) | "sd-card" | board init(); removable SD card
hw/arm/stellaris.c:1313 | qdev_new | OBJECT(ms) | "oled" | collapse existing add_child; keep name
hw/arm/stellaris.c:1318 | qdev_new | OBJECT(ms) | "splitter" | collapse existing add_child; keep name
hw/arm/stellaris.c:1340 | qdev_new | soc_container | "enet" | collapse existing add_child; keep name
hw/arm/stellaris.c:1360 | qdev_new | OBJECT(ms) | "gamepad" | collapse existing add_child; keep name

AI-used-for: code (refactoring)

---
 hw/arm/musicpal.c  | 41 ++++++++++++++++------------
 hw/arm/stellaris.c | 68 ++++++++++++++++++++--------------------------
 2 files changed, 53 insertions(+), 56 deletions(-)
hw/arm/musicpal.c +23 -18
index d9fe08d57b..86ea348d3d 100644
@@ -1232,7 +1232,7 @@ static void musicpal_init(MachineState *machine)
         exit(EXIT_FAILURE);
     }
 
-    cpu = ARM_CPU(cpu_create_orphan(machine->cpu_type));
+    cpu = ARM_CPU(cpu_create(OBJECT(machine), "cpu", machine->cpu_type));
 
     memory_region_add_subregion(address_space_mem, 0, machine->ram);
 
@@ -1240,18 +1240,20 @@ static void musicpal_init(MachineState *machine)
                            &error_fatal);
     memory_region_add_subregion(address_space_mem, MP_SRAM_BASE, sram);
 
-    pic = sysbus_create_simple_orphan(TYPE_MV88W8618_PIC, MP_PIC_BASE,
+    pic = sysbus_create_simple(OBJECT(machine), "pic",
+                               TYPE_MV88W8618_PIC, MP_PIC_BASE,
                                qdev_get_gpio_in(DEVICE(cpu), ARM_CPU_IRQ));
-    sysbus_create_varargs_orphan(TYPE_MV88W8618_PIT, MP_PIT_BASE,
+    sysbus_create_varargs(OBJECT(machine), "pit",
+                          TYPE_MV88W8618_PIT, MP_PIT_BASE,
                           qdev_get_gpio_in(pic, MP_TIMER1_IRQ),
                           qdev_get_gpio_in(pic, MP_TIMER2_IRQ),
                           qdev_get_gpio_in(pic, MP_TIMER3_IRQ),
                           qdev_get_gpio_in(pic, MP_TIMER4_IRQ), NULL);
 
     /* Logically OR both UART IRQs together */
-    uart_orgate = qdev_new_orphan(TYPE_OR_IRQ);
+    uart_orgate = qdev_new(OBJECT(machine), "uart-orgate", TYPE_OR_IRQ);
     object_property_set_int(OBJECT(uart_orgate), "num-lines", 2, &error_fatal);
-    qdev_realize_and_unref(uart_orgate, NULL, &error_fatal);
+    qdev_realize(uart_orgate, NULL, &error_fatal);
     qdev_connect_gpio_out(uart_orgate, 0,
                           qdev_get_gpio_in(pic, MP_UART_SHARED_IRQ));
 
@@ -1287,28 +1289,31 @@ static void musicpal_init(MachineState *machine)
                               2, 0x00BF, 0x236D, 0x0000, 0x0000,
                               0x5555, 0x2AAA, 0);
     }
-    sysbus_create_simple_orphan(TYPE_MV88W8618_FLASHCFG, MP_FLASHCFG_BASE, NULL);
+    sysbus_create_simple(OBJECT(machine), "flashcfg",
+                         TYPE_MV88W8618_FLASHCFG, MP_FLASHCFG_BASE, NULL);
 
-    dev = qdev_new_orphan(TYPE_MV88W8618_ETH);
+    dev = qdev_new(OBJECT(machine), "eth", TYPE_MV88W8618_ETH);
     qemu_configure_nic_device(dev, true, "mv88w8618");
     object_property_set_link(OBJECT(dev), "dma-memory",
                              OBJECT(get_system_memory()), &error_fatal);
-    sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
+    sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
     sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, MP_ETH_BASE);
     sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0,
                        qdev_get_gpio_in(pic, MP_ETH_IRQ));
 
-    sysbus_create_simple_orphan("mv88w8618_wlan", MP_WLAN_BASE, NULL);
+    sysbus_create_simple(OBJECT(machine), "wlan", "mv88w8618_wlan", MP_WLAN_BASE, NULL);
 
-    sysbus_create_simple_orphan(TYPE_MUSICPAL_MISC, MP_MISC_BASE, NULL);
+    sysbus_create_simple(OBJECT(machine), "misc", TYPE_MUSICPAL_MISC, MP_MISC_BASE, NULL);
 
-    dev = sysbus_create_simple_orphan(TYPE_MUSICPAL_GPIO, MP_GPIO_BASE,
+    dev = sysbus_create_simple(OBJECT(machine), "gpio",
+                               TYPE_MUSICPAL_GPIO, MP_GPIO_BASE,
                                qdev_get_gpio_in(pic, MP_GPIO_IRQ));
-    i2c_dev = sysbus_create_simple_orphan(TYPE_GPIO_I2C, -1, NULL);
+    i2c_dev = sysbus_create_simple(OBJECT(machine), "i2c", TYPE_GPIO_I2C, -1, NULL);
     i2c = (I2CBus *)qdev_get_child_bus(i2c_dev, "i2c");
 
-    lcd_dev = sysbus_create_simple_orphan(TYPE_MUSICPAL_LCD, MP_LCD_BASE, NULL);
-    key_dev = sysbus_create_simple_orphan(TYPE_MUSICPAL_KEY, -1, NULL);
+    lcd_dev = sysbus_create_simple(OBJECT(machine), "lcd",
+                                   TYPE_MUSICPAL_LCD, MP_LCD_BASE, NULL);
+    key_dev = sysbus_create_simple(OBJECT(machine), "keys", TYPE_MUSICPAL_KEY, -1, NULL);
 
     /* I2C read data */
     qdev_connect_gpio_out(i2c_dev, 0,
@@ -1328,17 +1333,17 @@ static void musicpal_init(MachineState *machine)
         qdev_connect_gpio_out(key_dev, i, qdev_get_gpio_in(dev, i + 15));
     }
 
-    wm8750_dev = i2c_slave_new_orphan(TYPE_WM8750, MP_WM_ADDR);
+    wm8750_dev = i2c_slave_new(OBJECT(machine), "wm8750", TYPE_WM8750, MP_WM_ADDR);
     if (machine->audiodev) {
         qdev_prop_set_string(DEVICE(wm8750_dev), "audiodev", machine->audiodev);
     }
-    i2c_slave_realize_and_unref(wm8750_dev, i2c, &error_abort);
+    qdev_realize(DEVICE(wm8750_dev), BUS(i2c), &error_abort);
 
-    dev = qdev_new_orphan(TYPE_MV88W8618_AUDIO);
+    dev = qdev_new(OBJECT(machine), "audio", TYPE_MV88W8618_AUDIO);
     s = SYS_BUS_DEVICE(dev);
     object_property_set_link(OBJECT(dev), "wm8750", OBJECT(wm8750_dev),
                              NULL);
-    sysbus_realize_and_unref(s, &error_fatal);
+    sysbus_realize(s, &error_fatal);
     sysbus_mmio_map(s, 0, MP_AUDIO_BASE);
     sysbus_connect_irq(s, 0, qdev_get_gpio_in(pic, MP_AUDIO_IRQ));
 
hw/arm/stellaris.c +30 -38

178 lines not on this page · raw message

Signature · 1 line
2.47.1
#222 lore raw

RFC PATCH v2 65/137 hw/arm/exynos: Give onboard devices a QOM parent

In reply to Alexander Graf

Convert the *_orphan() device-creation calls in the hw/arm exynos board files 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 SoC device for composite children. Names follow existing QOM conventions.

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

hw/arm/exynos4210.c:522 | qdev_new | parent (threaded) | "pl330[*]" | pl330_create() static helper: added Object *parent as first arg, threaded from exynos4210_realize() with OBJECT(s). Paired sysbus_realize_and_unref -> sysbus_realize.
hw/arm/exynos4210.c:603 | sysbus_create_simple | OBJECT(s) | "l2x0" | SoC realize(); s = Exynos4210State being realized.
hw/arm/exynos4210.c:670 | sysbus_create_simple | OBJECT(s) | "pmu" | SoC realize(); single instance.
hw/arm/exynos4210.c:672 | sysbus_create_simple | OBJECT(s) | "clk" | SoC realize(); single instance.
hw/arm/exynos4210.c:673 | sysbus_create_simple | OBJECT(s) | "rng" | SoC realize(); single instance.
hw/arm/exynos4210.c:676 | sysbus_create_varargs | OBJECT(s) | "pwm" | SoC realize(); single instance.
hw/arm/exynos4210.c:684 | sysbus_create_varargs | OBJECT(s) | "rtc" | SoC realize(); single instance.
hw/arm/exynos4210.c:690 | qdev_new | OBJECT(s) | "mct" | SoC realize(); paired sysbus_realize_and_unref -> sysbus_realize.
hw/arm/exynos4210.c:716 | qdev_new | OBJECT(s) | "i2c[*]" | SoC realize(); loop over EXYNOS4210_I2C_NUMBER, auto-index. Paired sysbus_realize_and_unref -> sysbus_realize.
hw/arm/exynos4210.c:760 | qdev_new | OBJECT(s) | "sdhci[*]" | SoC realize(); loop over EXYNOS4210_SDHCI_NUMBER. Paired sysbus_realize_and_unref -> sysbus_realize.
hw/arm/exynos4210.c:770 | qdev_new | OBJECT(s) | "sd-card[*]" | SoC realize(); SD cards owned by SoC (bus is not parent). Paired qdev_realize_and_unref -> qdev_realize.
hw/arm/exynos4210.c:777 | qdev_new | OBJECT(s) | "fimd" | SoC realize(); single instance. Paired sysbus_realize_and_unref -> sysbus_realize.
hw/arm/exynos4210.c:787 | sysbus_create_simple | OBJECT(s) | "ehci" | SoC realize(); single instance.

AI-used-for: code (refactoring)

---
 hw/arm/exynos4210.c | 60 +++++++++++++++++++++++++--------------------
 1 file changed, 34 insertions(+), 26 deletions(-)
hw/arm/exynos4210.c +34 -26
index 7d9d87d7ba..74ce36c1e6 100644
@@ -512,14 +512,15 @@ static uint64_t exynos4210_calc_affinity(int cpu)
     return (0x9 << ARM_AFF1_SHIFT) | cpu;
 }
 
-static DeviceState *pl330_create(uint32_t base, OrIRQState *orgate,
-                                 qemu_irq irq, int nreq, int nevents, int width)
+static DeviceState *pl330_create(Object *parent, uint32_t base,
+                                 OrIRQState *orgate, qemu_irq irq,
+                                 int nreq, int nevents, int width)
 {
     SysBusDevice *busdev;
     DeviceState *dev;
     int i;
 
-    dev = qdev_new_orphan("pl330");
+    dev = qdev_new(parent, "pl330[*]", "pl330");
     object_property_set_link(OBJECT(dev), "memory",
                              OBJECT(get_system_memory()),
                              &error_fatal);
@@ -534,7 +535,7 @@ static DeviceState *pl330_create(uint32_t base, OrIRQState *orgate,
     qdev_prop_set_uint8(dev, "data_width", width);
     qdev_prop_set_uint16(dev, "data_buffer_dep", width);
     busdev = SYS_BUS_DEVICE(dev);
-    sysbus_realize_and_unref(busdev, &error_fatal);
+    sysbus_realize(busdev, &error_fatal);
     sysbus_mmio_map(busdev, 0, base);
 
     object_property_set_int(OBJECT(orgate), "num-lines", nevents + 1,
@@ -600,7 +601,8 @@ static void exynos4210_realize(DeviceState *socdev, Error **errp)
     }
 
     /* Cache controller */
-    sysbus_create_simple_orphan("l2x0", EXYNOS4210_L2X0_BASE_ADDR, NULL);
+    sysbus_create_simple(OBJECT(s), "l2x0", "l2x0",
+                         EXYNOS4210_L2X0_BASE_ADDR, NULL);
 
     /* External GIC */
     qdev_prop_set_uint32(DEVICE(&s->ext_gic), "num-cpu", EXYNOS4210_NCPUS);
@@ -667,13 +669,17 @@ static void exynos4210_realize(DeviceState *socdev, Error **errp)
     * The only reason of existence at the moment is that secondary CPU boot
     * loader uses PMU INFORM5 register as a holding pen.
     */
-    sysbus_create_simple_orphan("exynos4210.pmu", EXYNOS4210_PMU_BASE_ADDR, NULL);
+    sysbus_create_simple(OBJECT(s), "pmu", "exynos4210.pmu",
+                         EXYNOS4210_PMU_BASE_ADDR, NULL);
 
-    sysbus_create_simple_orphan("exynos4210.clk", EXYNOS4210_CLK_BASE_ADDR, NULL);
-    sysbus_create_simple_orphan("exynos4210.rng", EXYNOS4210_RNG_BASE_ADDR, NULL);
+    sysbus_create_simple(OBJECT(s), "clk", "exynos4210.clk",
+                         EXYNOS4210_CLK_BASE_ADDR, NULL);
+    sysbus_create_simple(OBJECT(s), "rng", "exynos4210.rng",
+                         EXYNOS4210_RNG_BASE_ADDR, NULL);
 
     /* PWM */
-    sysbus_create_varargs_orphan("exynos4210.pwm", EXYNOS4210_PWM_BASE_ADDR,
+    sysbus_create_varargs(OBJECT(s), "pwm", "exynos4210.pwm",
+                          EXYNOS4210_PWM_BASE_ADDR,
                           s->irq_table[exynos4210_get_irq(22, 0)],
                           s->irq_table[exynos4210_get_irq(22, 1)],
                           s->irq_table[exynos4210_get_irq(22, 2)],
@@ -681,15 +687,16 @@ static void exynos4210_realize(DeviceState *socdev, Error **errp)
                           s->irq_table[exynos4210_get_irq(22, 4)],
                           NULL);
     /* RTC */
-    sysbus_create_varargs_orphan("exynos4210.rtc", EXYNOS4210_RTC_BASE_ADDR,
+    sysbus_create_varargs(OBJECT(s), "rtc", "exynos4210.rtc",
+                          EXYNOS4210_RTC_BASE_ADDR,
                           s->irq_table[exynos4210_get_irq(23, 0)],
                           s->irq_table[exynos4210_get_irq(23, 1)],
                           NULL);
 
     /* Multi Core Timer */
-    dev = qdev_new_orphan("exynos4210.mct");
+    dev = qdev_new(OBJECT(s), "mct", "exynos4210.mct");
     busdev = SYS_BUS_DEVICE(dev);
-    sysbus_realize_and_unref(busdev, &error_fatal);
+    sysbus_realize(busdev, &error_fatal);
     for (n = 0; n < 4; n++) {
         /* Connect global timer interrupts to Combiner gpio_in */
         sysbus_connect_irq(busdev, n,
@@ -713,9 +720,9 @@ static void exynos4210_realize(DeviceState *socdev, Error **errp)
             i2c_irq = s->irq_table[exynos4210_get_irq(EXYNOS4210_HDMI_INTG, 1)];
         }
 
-        dev = qdev_new_orphan("exynos4210.i2c");
+        dev = qdev_new(OBJECT(s), "i2c[*]", "exynos4210.i2c");
         busdev = SYS_BUS_DEVICE(dev);
-        sysbus_realize_and_unref(busdev, &error_fatal);
+        sysbus_realize(busdev, &error_fatal);
         sysbus_connect_irq(busdev, 0, i2c_irq);
         sysbus_mmio_map(busdev, 0, addr);
         s->i2c_if[n] = (I2CBus *)qdev_get_child_bus(dev, "i2c");
@@ -757,46 +764,47 @@ static void exynos4210_realize(DeviceState *socdev, Error **errp)
          * public datasheet which is very similar (implementing
          * MMC Specification Version 4.0 being the only difference noted)
          */
-        dev = qdev_new_orphan(TYPE_S3C_SDHCI);
+        dev = qdev_new(OBJECT(s), "sdhci[*]", TYPE_S3C_SDHCI);
         qdev_prop_set_uint64(dev, "capareg", EXYNOS4210_SDHCI_CAPABILITIES);
 
         busdev = SYS_BUS_DEVICE(dev);
-        sysbus_realize_and_unref(busdev, &error_fatal);
+        sysbus_realize(busdev, &error_fatal);
         sysbus_mmio_map(busdev, 0, EXYNOS4210_SDHCI_ADDR(n));
         sysbus_connect_irq(busdev, 0, s->irq_table[exynos4210_get_irq(29, n)]);
 
         di = drive_get(IF_SD, 0, n);
         blk = di ? blk_by_legacy_dinfo(di) : NULL;
-        carddev = qdev_new_orphan(TYPE_SD_CARD);
+        carddev = qdev_new(OBJECT(s), "sd-card[*]", TYPE_SD_CARD);
         qdev_prop_set_drive(carddev, "drive", blk);
-        qdev_realize_and_unref(carddev, qdev_get_child_bus(dev, "sd-bus"),
-                               &error_fatal);
+        qdev_realize(carddev, qdev_get_child_bus(dev, "sd-bus"),
+                     &error_fatal);
     }
 
     /*** Display controller (FIMD) ***/
-    dev = qdev_new_orphan("exynos4210.fimd");
+    dev = qdev_new(OBJECT(s), "fimd", "exynos4210.fimd");
     object_property_set_link(OBJECT(dev), "framebuffer-memory",
                              OBJECT(system_mem), &error_fatal);
     busdev = SYS_BUS_DEVICE(dev);
-    sysbus_realize_and_unref(busdev, &error_fatal);
+    sysbus_realize(busdev, &error_fatal);
     sysbus_mmio_map(busdev, 0, EXYNOS4210_FIMD0_BASE_ADDR);
     for (n = 0; n < 3; n++) {
         sysbus_connect_irq(busdev, n, s->irq_table[exynos4210_get_irq(11, n)]);
     }
 
-    sysbus_create_simple_orphan(TYPE_EXYNOS4210_EHCI, EXYNOS4210_EHCI_BASE_ADDR,
-            s->irq_table[exynos4210_get_irq(28, 3)]);
+    sysbus_create_simple(OBJECT(s), "ehci", TYPE_EXYNOS4210_EHCI,
+                         EXYNOS4210_EHCI_BASE_ADDR,
+                         s->irq_table[exynos4210_get_irq(28, 3)]);
 
     /*** DMA controllers ***/
-    pl330[0] = pl330_create(EXYNOS4210_PL330_BASE0_ADDR,
+    pl330[0] = pl330_create(OBJECT(s), EXYNOS4210_PL330_BASE0_ADDR,
                             &s->pl330_irq_orgate[0],
                             s->irq_table[exynos4210_get_irq(21, 0)],
                             32, 32, 32);
-    pl330[1] = pl330_create(EXYNOS4210_PL330_BASE1_ADDR,
+    pl330[1] = pl330_create(OBJECT(s), EXYNOS4210_PL330_BASE1_ADDR,
                             &s->pl330_irq_orgate[1],
                             s->irq_table[exynos4210_get_irq(21, 1)],
                             32, 32, 32);
-    pl330[2] = pl330_create(EXYNOS4210_PL330_BASE2_ADDR,
+    pl330[2] = pl330_create(OBJECT(s), EXYNOS4210_PL330_BASE2_ADDR,
                             &s->pl330_irq_orgate[2],
                             s->irq_table[exynos4210_get_irq(20, 1)],
                             1, 31, 64);
Signature · 1 line
2.47.1
#223 lore raw

RFC PATCH v2 66/137 hw/arm/allwinner: Give onboard devices a QOM parent

In reply to Alexander Graf

Convert the *_orphan() device-creation calls in the hw/arm allwinner board files 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 SoC device for composite children. Names follow existing QOM conventions.

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

hw/arm/allwinner-h3.c:382 | sysbus_create_simple | OBJECT(s) | "ehci[*]" | allwinner_h3_realize() SoC realize; 4 instances, auto-index.
hw/arm/allwinner-h3.c:385 | sysbus_create_simple | OBJECT(s) | "ehci[*]" | SoC realize; auto-index.
hw/arm/allwinner-h3.c:388 | sysbus_create_simple | OBJECT(s) | "ehci[*]" | SoC realize; auto-index.
hw/arm/allwinner-h3.c:391 | sysbus_create_simple | OBJECT(s) | "ehci[*]" | SoC realize; auto-index.
hw/arm/allwinner-h3.c:395 | sysbus_create_simple | OBJECT(s) | "ohci[*]" | SoC realize; 4 instances, auto-index.
hw/arm/allwinner-h3.c:398 | sysbus_create_simple | OBJECT(s) | "ohci[*]" | SoC realize; auto-index.
hw/arm/allwinner-h3.c:401 | sysbus_create_simple | OBJECT(s) | "ohci[*]" | SoC realize; auto-index.
hw/arm/allwinner-h3.c:404 | sysbus_create_simple | OBJECT(s) | "ohci[*]" | SoC realize; auto-index.

hw/arm/bananapi_m2u.c:53 | qdev_new | OBJECT(s) | "sd-card[*]" | mmc_attach_drive() helper receives AwR40State *s (SoC, itself child of machine); use it as parent. Multiple units -> auto-index. Paired qdev_realize_and_unref -> qdev_realize. hw/arm/bananapi_m2u.c:117 | i2c_slave_create_simple | OBJECT(machine) | "axp221" | Board init(); PMU is board-level peripheral on i2c bus.
hw/arm/cubieboard.c:84 | i2c_slave_create_simple | OBJECT(machine) | "axp209" | Board init(); PMU is board-level peripheral.
hw/arm/cubieboard.c:92 | qdev_new | OBJECT(machine) | "sd-card" | Board init(); single SD card. Paired qdev_realize_and_unref -> qdev_realize.
hw/arm/orangepi.c:88 | qdev_new | OBJECT(machine) | "sd-card" | Board init(); single SD card. Paired qdev_realize_and_unref -> qdev_realize.

AI-used-for: code (refactoring)

---
 hw/arm/allwinner-h3.c | 24 ++++++++++++++++--------
 hw/arm/bananapi_m2u.c |  6 +++---
 hw/arm/cubieboard.c   |  6 +++---
 hw/arm/orangepi.c     |  4 ++--
 4 files changed, 24 insertions(+), 16 deletions(-)
hw/arm/allwinner-h3.c +16 -8
index ce716d1687..6f9a07610f 100644
@@ -379,29 +379,37 @@ static void allwinner_h3_realize(DeviceState *dev, Error **errp)
                        qdev_get_gpio_in(DEVICE(&s->gic), AW_H3_GIC_SPI_EMAC));
 
     /* Universal Serial Bus */
-    sysbus_create_simple_orphan(TYPE_AW_H3_EHCI, s->memmap[AW_H3_DEV_EHCI0],
+    sysbus_create_simple(OBJECT(s), "ehci[*]", TYPE_AW_H3_EHCI,
+                         s->memmap[AW_H3_DEV_EHCI0],
                          qdev_get_gpio_in(DEVICE(&s->gic),
                                           AW_H3_GIC_SPI_EHCI0));
-    sysbus_create_simple_orphan(TYPE_AW_H3_EHCI, s->memmap[AW_H3_DEV_EHCI1],
+    sysbus_create_simple(OBJECT(s), "ehci[*]", TYPE_AW_H3_EHCI,
+                         s->memmap[AW_H3_DEV_EHCI1],
                          qdev_get_gpio_in(DEVICE(&s->gic),
                                           AW_H3_GIC_SPI_EHCI1));
-    sysbus_create_simple_orphan(TYPE_AW_H3_EHCI, s->memmap[AW_H3_DEV_EHCI2],
+    sysbus_create_simple(OBJECT(s), "ehci[*]", TYPE_AW_H3_EHCI,
+                         s->memmap[AW_H3_DEV_EHCI2],
                          qdev_get_gpio_in(DEVICE(&s->gic),
                                           AW_H3_GIC_SPI_EHCI2));
-    sysbus_create_simple_orphan(TYPE_AW_H3_EHCI, s->memmap[AW_H3_DEV_EHCI3],
+    sysbus_create_simple(OBJECT(s), "ehci[*]", TYPE_AW_H3_EHCI,
+                         s->memmap[AW_H3_DEV_EHCI3],
                          qdev_get_gpio_in(DEVICE(&s->gic),
                                           AW_H3_GIC_SPI_EHCI3));
 
-    sysbus_create_simple_orphan("sysbus-ohci", s->memmap[AW_H3_DEV_OHCI0],
+    sysbus_create_simple(OBJECT(s), "ohci[*]", "sysbus-ohci",
+                         s->memmap[AW_H3_DEV_OHCI0],
                          qdev_get_gpio_in(DEVICE(&s->gic),
                                           AW_H3_GIC_SPI_OHCI0));
-    sysbus_create_simple_orphan("sysbus-ohci", s->memmap[AW_H3_DEV_OHCI1],
+    sysbus_create_simple(OBJECT(s), "ohci[*]", "sysbus-ohci",
+                         s->memmap[AW_H3_DEV_OHCI1],
                          qdev_get_gpio_in(DEVICE(&s->gic),
                                           AW_H3_GIC_SPI_OHCI1));
-    sysbus_create_simple_orphan("sysbus-ohci", s->memmap[AW_H3_DEV_OHCI2],
+    sysbus_create_simple(OBJECT(s), "ohci[*]", "sysbus-ohci",
+                         s->memmap[AW_H3_DEV_OHCI2],
                          qdev_get_gpio_in(DEVICE(&s->gic),
                                           AW_H3_GIC_SPI_OHCI2));
-    sysbus_create_simple_orphan("sysbus-ohci", s->memmap[AW_H3_DEV_OHCI3],
+    sysbus_create_simple(OBJECT(s), "ohci[*]", "sysbus-ohci",
+                         s->memmap[AW_H3_DEV_OHCI3],
                          qdev_get_gpio_in(DEVICE(&s->gic),
                                           AW_H3_GIC_SPI_OHCI3));
 
hw/arm/bananapi_m2u.c +3 -3
index 809c8bbc43..ae2d8bd2f7 100644
@@ -50,9 +50,9 @@ static void mmc_attach_drive(AwR40State *s, AwSdHostState *mmc, int unit,
         exit(1);
     }
 
-    carddev = qdev_new_orphan(TYPE_SD_CARD);
+    carddev = qdev_new(OBJECT(s), "sd-card[*]", TYPE_SD_CARD);
     qdev_prop_set_drive_err(carddev, "drive", blk, &error_fatal);
-    qdev_realize_and_unref(carddev, bus, &error_fatal);
+    qdev_realize(carddev, bus, &error_fatal);
 
     if (load_bootroom && blk && blk_is_available(blk)) {
         /* Use Boot ROM to copy data from SD card to SRAM */
@@ -114,7 +114,7 @@ static void bpim2u_init(MachineState *machine)
 
     /* Connect AXP221 */
     i2c = I2C_BUS(qdev_get_child_bus(DEVICE(&r40->i2c0), "i2c"));
-    i2c_slave_create_simple_orphan(i2c, "axp221_pmu", 0x34);
+    i2c_slave_create_simple(OBJECT(machine), "axp221", i2c, "axp221_pmu", 0x34);
 
     /* SDRAM */
     memory_region_add_subregion(get_system_memory(),
hw/arm/cubieboard.c +3 -3
index 7ce5179345..fa5eaa5378 100644
@@ -81,7 +81,7 @@ static void cubieboard_init(MachineState *machine)
 
     /* Connect AXP 209 */
     i2c = I2C_BUS(qdev_get_child_bus(DEVICE(&a10->i2c0), "i2c"));
-    i2c_slave_create_simple_orphan(i2c, "axp209_pmu", 0x34);
+    i2c_slave_create_simple(OBJECT(machine), "axp209", i2c, "axp209_pmu", 0x34);
 
     /* Retrieve SD bus */
     di = drive_get(IF_SD, 0, 0);
@@ -89,9 +89,9 @@ static void cubieboard_init(MachineState *machine)
     bus = qdev_get_child_bus(DEVICE(a10), "sd-bus");
 
     /* Plug in SD card */
-    carddev = qdev_new_orphan(TYPE_SD_CARD);
+    carddev = qdev_new(OBJECT(machine), "sd-card", TYPE_SD_CARD);
     qdev_prop_set_drive_err(carddev, "drive", blk, &error_fatal);
-    qdev_realize_and_unref(carddev, bus, &error_fatal);
+    qdev_realize(carddev, bus, &error_fatal);
 
     memory_region_add_subregion(get_system_memory(), AW_A10_SDRAM_BASE,
                                 machine->ram);
hw/arm/orangepi.c +2 -2
index d705cc43b4..1a37c97eef 100644
@@ -85,9 +85,9 @@ static void orangepi_init(MachineState *machine)
     bus = qdev_get_child_bus(DEVICE(h3), "sd-bus");
 
     /* Plug in SD card */
-    carddev = qdev_new_orphan(TYPE_SD_CARD);
+    carddev = qdev_new(OBJECT(machine), "sd-card", TYPE_SD_CARD);
     qdev_prop_set_drive_err(carddev, "drive", blk, &error_fatal);
-    qdev_realize_and_unref(carddev, bus, &error_fatal);
+    qdev_realize(carddev, bus, &error_fatal);
 
     /* SDRAM */
     memory_region_add_subregion(get_system_memory(), h3->memmap[AW_H3_DEV_SDRAM],
Signature · 1 line
2.47.1
#224 lore raw

RFC PATCH v2 67/137 hw/arm/strongarm: Give onboard devices a QOM parent

In reply to Alexander Graf

Convert the *_orphan() device-creation calls in the hw/arm strongarm board files 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 SoC device for composite children. Names follow existing QOM conventions.

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

hw/arm/collie.c:67 | sysbus_create_simple | OBJECT(machine) | "scoop" | Board .init(MachineState *machine); single instance.
hw/arm/strongarm.c:649 | qdev_new | parent (threaded) | "gpio" | strongarm_gpio_init() static helper: added Object *parent as first arg, threaded from sa1110_init(). Paired sysbus_realize_and_unref -> sysbus_realize.

hw/arm/strongarm.c:1623 | cpu_create | parent (threaded) | "cpu" | sa1110_init() has no parent-capable pointer; added Object *parent as first arg (prototype in strongarm.h updated), threaded from collie_init() with OBJECT(machine).
hw/arm/strongarm.c:1625 | sysbus_create_varargs | parent | "pic" | sa1110_init(); single PIC.
hw/arm/strongarm.c:1630 | sysbus_create_varargs | parent | "timer" | sa1110_init(); single timer.
hw/arm/strongarm.c:1637 | sysbus_create_simple | parent | "rtc" | sa1110_init(); single RTC.
hw/arm/strongarm.c:1642 | sysbus_create_varargs | parent | "ppc" | sa1110_init(); single PPC.
hw/arm/strongarm.c:1645 | qdev_new | parent | "uart[*]" | sa1110_init(); loop over sa_serial[]. Paired sysbus_realize_and_unref -> sysbus_realize.
hw/arm/strongarm.c:1654 | sysbus_create_varargs | parent | "ssp" | sa1110_init(); single SSP.

AI-used-for: code (refactoring)

---
 hw/arm/collie.c    |  4 ++--
 hw/arm/strongarm.c | 27 ++++++++++++++-------------
 hw/arm/strongarm.h |  2 +-
 3 files changed, 17 insertions(+), 16 deletions(-)
hw/arm/collie.c +2 -2
index b3646daa3b..afd4e14315 100644
@@ -52,7 +52,7 @@ static void collie_init(MachineState *machine)
         exit(EXIT_FAILURE);
     }
 
-    cms->sa1110 = sa1110_init(machine->cpu_type);
+    cms->sa1110 = sa1110_init(OBJECT(machine), machine->cpu_type);
 
     memory_region_add_subregion(get_system_memory(), SA_SDCS0, machine->ram);
 
@@ -64,7 +64,7 @@ static void collie_init(MachineState *machine)
                               FLASH_SECTOR_SIZE, 4, 0x00, 0x00, 0x00, 0x00, 0);
     }
 
-    sysbus_create_simple_orphan("scoop", 0x40800000, NULL);
+    sysbus_create_simple(OBJECT(machine), "scoop", "scoop", 0x40800000, NULL);
 
     collie_binfo.board_id = 0x208;
     arm_load_kernel(cms->sa1110->cpu, machine, &collie_binfo);
hw/arm/strongarm.c +14 -13
index 1704db8baa..0b3b56218a 100644
@@ -640,14 +640,14 @@ static const MemoryRegionOps strongarm_gpio_ops = {
     .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
-static DeviceState *strongarm_gpio_init(hwaddr base,
+static DeviceState *strongarm_gpio_init(Object *parent, hwaddr base,
                 DeviceState *pic)
 {
     DeviceState *dev;
     int i;
 
-    dev = qdev_new_orphan(TYPE_STRONGARM_GPIO);
-    sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
+    dev = qdev_new(parent, "gpio", TYPE_STRONGARM_GPIO);
+    sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
 
     sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);
     for (i = 0; i < 12; i++)
@@ -1608,7 +1608,7 @@ static const TypeInfo strongarm_ssp_info = {
 };
 
 /* Main CPU functions */
-StrongARMState *sa1110_init(const char *cpu_type)
+StrongARMState *sa1110_init(Object *parent, const char *cpu_type)
 {
     StrongARMState *s;
     int i;
@@ -1620,38 +1620,39 @@ StrongARMState *sa1110_init(const char *cpu_type)
         exit(1);
     }
 
-    s->cpu = ARM_CPU(cpu_create_orphan(cpu_type));
+    s->cpu = ARM_CPU(cpu_create(parent, "cpu", cpu_type));
 
-    s->pic = sysbus_create_varargs_orphan("strongarm_pic", 0x90050000,
+    s->pic = sysbus_create_varargs(parent, "pic", "strongarm_pic", 0x90050000,
                     qdev_get_gpio_in(DEVICE(s->cpu), ARM_CPU_IRQ),
                     qdev_get_gpio_in(DEVICE(s->cpu), ARM_CPU_FIQ),
                     NULL);
 
-    sysbus_create_varargs_orphan("pxa25x-timer", 0x90000000,
+    sysbus_create_varargs(parent, "timer", "pxa25x-timer", 0x90000000,
                     qdev_get_gpio_in(s->pic, SA_PIC_OSTC0),
                     qdev_get_gpio_in(s->pic, SA_PIC_OSTC1),
                     qdev_get_gpio_in(s->pic, SA_PIC_OSTC2),
                     qdev_get_gpio_in(s->pic, SA_PIC_OSTC3),
                     NULL);
 
-    sysbus_create_simple_orphan(TYPE_STRONGARM_RTC, 0x90010000,
+    sysbus_create_simple(parent, "rtc", TYPE_STRONGARM_RTC, 0x90010000,
                     qdev_get_gpio_in(s->pic, SA_PIC_RTC_ALARM));
 
-    s->gpio = strongarm_gpio_init(0x90040000, s->pic);
+    s->gpio = strongarm_gpio_init(parent, 0x90040000, s->pic);
 
-    s->ppc = sysbus_create_varargs_orphan(TYPE_STRONGARM_PPC, 0x90060000, NULL);
+    s->ppc = sysbus_create_varargs(parent, "ppc", TYPE_STRONGARM_PPC,
+                                   0x90060000, NULL);
 
     for (i = 0; sa_serial[i].io_base; i++) {
-        DeviceState *dev = qdev_new_orphan(TYPE_STRONGARM_UART);
+        DeviceState *dev = qdev_new(parent, "uart[*]", TYPE_STRONGARM_UART);
         qdev_prop_set_chr(dev, "chardev", serial_hd(i));
-        sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
+        sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
         sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0,
                 sa_serial[i].io_base);
         sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0,
                 qdev_get_gpio_in(s->pic, sa_serial[i].irq));
     }
 
-    s->ssp = sysbus_create_varargs_orphan(TYPE_STRONGARM_SSP, 0x80070000,
+    s->ssp = sysbus_create_varargs(parent, "ssp", TYPE_STRONGARM_SSP, 0x80070000,
                 qdev_get_gpio_in(s->pic, SA_PIC_SSP), NULL);
     s->ssp_bus = (SSIBus *)qdev_get_child_bus(s->ssp, "ssi");
 
hw/arm/strongarm.h +1 -1
index b11b3a3379..72bb9e075c 100644
@@ -62,6 +62,6 @@ typedef struct {
     SSIBus *ssp_bus;
 } StrongARMState;
 
-StrongARMState *sa1110_init(const char *cpu_type);
+StrongARMState *sa1110_init(Object *parent, const char *cpu_type);
 
 #endif
Signature · 1 line
2.47.1
#225 lore raw

RFC PATCH v2 68/137 hw/arm/omap: Give onboard devices a QOM parent

In reply to Alexander Graf

Convert the *_orphan() device-creation calls in the hw/arm omap board files 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 SoC device for composite children. Names follow existing QOM conventions.

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

hw/arm/omap1.c:3752 | cpu_create | parent | "cpu" | omap310_mpu_init() already receives Object *parent; use it directly.
hw/arm/omap1.c:3766 | qdev_new | parent | "intc[0]" | Two interrupt controllers, explicit index. Paired sysbus_realize_and_unref -> sysbus_realize.
hw/arm/omap1.c:3776 | qdev_new | parent | "intc[1]" | Second intc. Paired sysbus_realize_and_unref -> sysbus_realize.
hw/arm/omap1.c:3879 | qdev_new | parent | "mmc" | Single MMC. Paired sysbus_realize_and_unref -> sysbus_realize.
hw/arm/omap1.c:3891 | qdev_new | parent | "sd-card" | Single SD card (bus is not parent). Paired qdev_realize_and_unref -> qdev_realize.
hw/arm/omap1.c:3903 | qdev_new | parent | "gpio" | Single GPIO. Paired sysbus_realize_and_unref -> sysbus_realize.
hw/arm/omap1.c:3920 | qdev_new | parent | "i2c" | Single i2c (only i2c[0] populated on omap1). Paired sysbus_realize_and_unref -> sysbus_realize.

AI-used-for: code (refactoring)

---
 hw/arm/omap1.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)
hw/arm/omap1.c +14 -14
index c86914a464..e5e092e074 100644
@@ -3749,7 +3749,7 @@ struct omap_mpu_state_s *omap310_mpu_init(Object *parent, MemoryRegion *dram,
     MemoryRegion *system_memory = get_system_memory();
 
     /* Core */
-    s->cpu = ARM_CPU(cpu_create_orphan(cpu_type));
+    s->cpu = ARM_CPU(cpu_create(parent, "cpu", cpu_type));
     s->sdram_size = memory_region_size(dram);
     s->sram_size = OMAP15XX_SRAM_SIZE;
 
@@ -3763,21 +3763,21 @@ struct omap_mpu_state_s *omap310_mpu_init(Object *parent, MemoryRegion *dram,
 
     omap_clkm_init(system_memory, 0xfffece00, 0xe1008000, s);
 
-    s->ih[0] = qdev_new_orphan("omap-intc");
+    s->ih[0] = qdev_new(parent, "intc[0]", "omap-intc");
     qdev_prop_set_uint32(s->ih[0], "size", 0x100);
     omap_intc_set_iclk(OMAP_INTC(s->ih[0]), omap_findclk(s, "arminth_ck"));
     busdev = SYS_BUS_DEVICE(s->ih[0]);
-    sysbus_realize_and_unref(busdev, &error_fatal);
+    sysbus_realize(busdev, &error_fatal);
     sysbus_connect_irq(busdev, 0,
                        qdev_get_gpio_in(DEVICE(s->cpu), ARM_CPU_IRQ));
     sysbus_connect_irq(busdev, 1,
                        qdev_get_gpio_in(DEVICE(s->cpu), ARM_CPU_FIQ));
     sysbus_mmio_map(busdev, 0, 0xfffecb00);
-    s->ih[1] = qdev_new_orphan("omap-intc");
+    s->ih[1] = qdev_new(parent, "intc[1]", "omap-intc");
     qdev_prop_set_uint32(s->ih[1], "size", 0x800);
     omap_intc_set_iclk(OMAP_INTC(s->ih[1]), omap_findclk(s, "arminth_ck"));
     busdev = SYS_BUS_DEVICE(s->ih[1]);
-    sysbus_realize_and_unref(busdev, &error_fatal);
+    sysbus_realize(busdev, &error_fatal);
     sysbus_connect_irq(busdev, 0,
                        qdev_get_gpio_in(s->ih[0], OMAP_INT_15XX_IH2_IRQ));
     /* The second interrupt controller's FIQ output is not wired up */
@@ -3876,8 +3876,8 @@ struct omap_mpu_state_s *omap310_mpu_init(Object *parent, MemoryRegion *dram,
         warn_report("missing SecureDigital device");
     }
 
-    s->mmc = qdev_new_orphan(TYPE_OMAP_MMC);
-    sysbus_realize_and_unref(SYS_BUS_DEVICE(s->mmc), &error_fatal);
+    s->mmc = qdev_new(parent, "mmc", TYPE_OMAP_MMC);
+    sysbus_realize(SYS_BUS_DEVICE(s->mmc), &error_fatal);
     omap_mmc_set_clk(s->mmc, omap_findclk(s, "mmc_ck"));
 
     memory_region_add_subregion(system_memory, 0xfffb7800,
@@ -3888,11 +3888,11 @@ struct omap_mpu_state_s *omap310_mpu_init(Object *parent, MemoryRegion *dram,
                        qdev_get_gpio_in(s->ih[1], OMAP_INT_OQN));
 
     if (dinfo) {
-        DeviceState *card = qdev_new_orphan(TYPE_SD_CARD);
+        DeviceState *card = qdev_new(parent, "sd-card", TYPE_SD_CARD);
         qdev_prop_set_drive_err(card, "drive", blk_by_legacy_dinfo(dinfo),
                                 &error_fatal);
-        qdev_realize_and_unref(card, qdev_get_child_bus(s->mmc, "sd-bus"),
-                               &error_fatal);
+        qdev_realize(card, qdev_get_child_bus(s->mmc, "sd-bus"),
+                     &error_fatal);
     }
 
     s->mpuio = omap_mpuio_init(system_memory, 0xfffb5000,
@@ -3900,9 +3900,9 @@ struct omap_mpu_state_s *omap310_mpu_init(Object *parent, MemoryRegion *dram,
                                qdev_get_gpio_in(s->ih[1], OMAP_INT_MPUIO),
                                omap_findclk(s, "clk32-kHz"));
 
-    s->gpio = qdev_new_orphan("omap-gpio");
+    s->gpio = qdev_new(parent, "gpio", "omap-gpio");
     omap_gpio_set_clk(OMAP1_GPIO(s->gpio), omap_findclk(s, "arm_gpio_ck"));
-    sysbus_realize_and_unref(SYS_BUS_DEVICE(s->gpio), &error_fatal);
+    sysbus_realize(SYS_BUS_DEVICE(s->gpio), &error_fatal);
     sysbus_connect_irq(SYS_BUS_DEVICE(s->gpio), 0,
                        qdev_get_gpio_in(s->ih[0], OMAP_INT_GPIO_BANK1));
     sysbus_mmio_map(SYS_BUS_DEVICE(s->gpio), 0, 0xfffce000);
@@ -3917,11 +3917,11 @@ struct omap_mpu_state_s *omap310_mpu_init(Object *parent, MemoryRegion *dram,
     s->pwt = omap_pwt_init(system_memory, 0xfffb6000,
                            omap_findclk(s, "armxor_ck"));
 
-    s->i2c[0] = qdev_new_orphan("omap_i2c");
+    s->i2c[0] = qdev_new(parent, "i2c", "omap_i2c");
     qdev_prop_set_uint8(s->i2c[0], "revision", 0x11);
     omap_i2c_set_fclk(OMAP_I2C(s->i2c[0]), omap_findclk(s, "mpuper_ck"));
     busdev = SYS_BUS_DEVICE(s->i2c[0]);
-    sysbus_realize_and_unref(busdev, &error_fatal);
+    sysbus_realize(busdev, &error_fatal);
     sysbus_connect_irq(busdev, 0, qdev_get_gpio_in(s->ih[1], OMAP_INT_I2C));
     sysbus_connect_irq(busdev, 1, s->drq[OMAP_DMA_I2C_TX]);
     sysbus_connect_irq(busdev, 2, s->drq[OMAP_DMA_I2C_RX]);
Signature · 1 line
2.47.1
#226 lore raw

RFC PATCH v2 69/137 hw/arm/mps2: Give onboard devices a QOM parent

In reply to Alexander Graf

Convert the *_orphan() device-creation calls in the hw/arm mps2 board files 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 SoC device for composite children. Names follow existing QOM conventions.

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

hw/arm/mps2.c:302 | qdev_new_orphan | OBJECT(mms) | "uart[*]" | board init (mps2_common_init), MPS2MachineState *mms is machine; indexed loop; drop _and_unref
hw/arm/mps2.c:346 | qdev_new_orphan | OBJECT(mms) | "uart[*]" | board init, second FPGA variant loop; auto-index; drop _and_unref
hw/arm/mps2.c:419 | sysbus_create_simple_orphan | OBJECT(mms) | "spi[*]" | board init; PL022 external ADC; auto-index shared with loop below
hw/arm/mps2.c:438 | sysbus_create_simple_orphan | OBJECT(mms) | "spi[*]" | board init; PL022 in nested loop; auto-index
hw/arm/mps2.c:449 | sysbus_create_simple_orphan | OBJECT(mms) | "i2c[*]" | board init; SBCON I2C in loop; auto-index
hw/arm/mps2-tz.c:511 | qdev_new_orphan | OBJECT(mms) | "lan9118" | make_eth_dev helper receives MPS2TZMachineState *mms (board state); single instance; drop _and_unref
hw/arm/mps2-tz.c:538 | qdev_new_orphan | OBJECT(mms) | "lan9118" | make_eth_usb helper receives mms; single instance (mutually exclusive with make_eth_dev per board); drop _and_unref

AI-used-for: code (refactoring)

---
 hw/arm/mps2-tz.c |  8 ++++----
 hw/arm/mps2.c    | 18 ++++++++++--------
 2 files changed, 14 insertions(+), 12 deletions(-)
hw/arm/mps2-tz.c +4 -4
index c0ab898f2e..17945d2b71 100644
@@ -508,11 +508,11 @@ static MemoryRegion *make_eth_dev(MPS2TZMachineState *mms, void *opaque,
     /* In hardware this is a LAN9220; the LAN9118 is software compatible
      * except that it doesn't support the checksum-offload feature.
      */
-    mms->lan9118 = qdev_new_orphan(TYPE_LAN9118);
+    mms->lan9118 = qdev_new(OBJECT(mms), "lan9118", TYPE_LAN9118);
     qemu_configure_nic_device(mms->lan9118, true, NULL);
 
     s = SYS_BUS_DEVICE(mms->lan9118);
-    sysbus_realize_and_unref(s, &error_fatal);
+    sysbus_realize(s, &error_fatal);
     sysbus_connect_irq(s, 0, get_sse_irq_in(mms, irqs[0]));
     return sysbus_mmio_get_region(s, 0);
 }
@@ -535,11 +535,11 @@ static MemoryRegion *make_eth_usb(MPS2TZMachineState *mms, void *opaque,
      * In hardware this is a LAN9220; the LAN9118 is software compatible
      * except that it doesn't support the checksum-offload feature.
      */
-    mms->lan9118 = qdev_new_orphan(TYPE_LAN9118);
+    mms->lan9118 = qdev_new(OBJECT(mms), "lan9118", TYPE_LAN9118);
     qemu_configure_nic_device(mms->lan9118, true, NULL);
 
     s = SYS_BUS_DEVICE(mms->lan9118);
-    sysbus_realize_and_unref(s, &error_fatal);
+    sysbus_realize(s, &error_fatal);
     sysbus_connect_irq(s, 0, get_sse_irq_in(mms, irqs[0]));
 
     memory_region_add_subregion(&mms->eth_usb_container,
hw/arm/mps2.c +10 -8
index e646c7c71e..2edd222674 100644
@@ -299,11 +299,11 @@ static void mps2_common_init(MachineState *machine)
                 rxovrint = qdev_get_gpio_in(orgate_dev, i * 2 + 1);
             }
 
-            dev = qdev_new_orphan(TYPE_CMSDK_APB_UART);
+            dev = qdev_new(OBJECT(mms), "uart[*]", TYPE_CMSDK_APB_UART);
             s = SYS_BUS_DEVICE(dev);
             qdev_prop_set_chr(dev, "chardev", serial_hd(i));
             qdev_prop_set_uint32(dev, "pclk-frq", SYSCLK_FRQ);
-            sysbus_realize_and_unref(s, &error_fatal);
+            sysbus_realize(s, &error_fatal);
             sysbus_mmio_map(s, 0, uartbase[i]);
             sysbus_connect_irq(s, 0, qdev_get_gpio_in(armv7m, uartirq[i] + 1));
             sysbus_connect_irq(s, 1, qdev_get_gpio_in(armv7m, uartirq[i]));
@@ -343,11 +343,11 @@ static void mps2_common_init(MachineState *machine)
             qdev_connect_gpio_out(txrx_orgate_dev, 0,
                                   qdev_get_gpio_in(armv7m, uart_txrx_irqno[i]));
 
-            dev = qdev_new_orphan(TYPE_CMSDK_APB_UART);
+            dev = qdev_new(OBJECT(mms), "uart[*]", TYPE_CMSDK_APB_UART);
             s = SYS_BUS_DEVICE(dev);
             qdev_prop_set_chr(dev, "chardev", serial_hd(i));
             qdev_prop_set_uint32(dev, "pclk-frq", SYSCLK_FRQ);
-            sysbus_realize_and_unref(s, &error_fatal);
+            sysbus_realize(s, &error_fatal);
             sysbus_mmio_map(s, 0, uartbase[i]);
             sysbus_connect_irq(s, 0, qdev_get_gpio_in(txrx_orgate_dev, 0));
             sysbus_connect_irq(s, 1, qdev_get_gpio_in(txrx_orgate_dev, 1));
@@ -416,8 +416,8 @@ static void mps2_common_init(MachineState *machine)
     qdev_prop_set_uint32(DEVICE(&mms->fpgaio), "prescale-clk", 25000000);
     sysbus_realize(SYS_BUS_DEVICE(&mms->fpgaio), &error_fatal);
     sysbus_mmio_map(SYS_BUS_DEVICE(&mms->fpgaio), 0, 0x40028000);
-    sysbus_create_simple_orphan(TYPE_PL022, 0x40025000,        /* External ADC */
-                         qdev_get_gpio_in(armv7m, 22));
+    sysbus_create_simple(OBJECT(mms), "spi[*]", TYPE_PL022, 0x40025000,
+                         qdev_get_gpio_in(armv7m, 22)); /* External ADC */
     for (i = 0; i < 2; i++) {
         static const int spi_irqno[] = {11, 24};
         static const hwaddr spibase[] = {0x40020000,    /* APB */
@@ -435,7 +435,8 @@ static void mps2_common_init(MachineState *machine)
         qdev_connect_gpio_out(orgate_dev, 0,
                               qdev_get_gpio_in(armv7m, spi_irqno[i]));
         for (j = 0; j < 2; j++) {
-            sysbus_create_simple_orphan(TYPE_PL022, spibase[2 * i + j],
+            sysbus_create_simple(OBJECT(mms), "spi[*]", TYPE_PL022,
+                                 spibase[2 * i + j],
                                  qdev_get_gpio_in(orgate_dev, j));
         }
     }
@@ -446,7 +447,8 @@ static void mps2_common_init(MachineState *machine)
                                          0x4002a000};   /* Shield1 */
         DeviceState *dev;
 
-        dev = sysbus_create_simple_orphan(TYPE_ARM_SBCON_I2C, i2cbase[i], NULL);
+        dev = sysbus_create_simple(OBJECT(mms), "i2c[*]",
+                                   TYPE_ARM_SBCON_I2C, i2cbase[i], NULL);
         if (i < 2) {
             /*
              * internal-only bus: mark it full to avoid user-created
Signature · 1 line
2.47.1
#227 lore raw

RFC PATCH v2 70/137 hw/arm/imx: Give onboard devices a QOM parent

In reply to Alexander Graf

Convert the *_orphan() device-creation calls in the hw/arm imx board files 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 SoC device for composite children. Names follow existing QOM conventions.

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

hw/arm/fsl-imx6.c:171 | sysbus_create_simple_orphan | OBJECT(dev) | "l2x0" | SoC DeviceClass.realize(DeviceState *dev); parent is the SoC device being realized; single instance hw/arm/imx25_pdk.c:130 | qdev_new_orphan | OBJECT(machine) | "sd-card[*]" | board init(MachineState *machine); loop over ESDHC slots; auto-index; drop _and_unref

hw/arm/imx8mm-evk.c:100 | qdev_new_orphan | OBJECT(machine) | "sd-card[*]" | board init; loop over USDHC slots; auto-index; drop _and_unref
hw/arm/imx8mp-evk.c:113 | qdev_new_orphan | OBJECT(machine) | "sd-card[*]" | board init; loop over USDHC slots; auto-index; drop _and_unref

hw/arm/mcimx6ul-evk.c:62 | qdev_new_orphan | OBJECT(machine) | "sd-card[*]" | board init; loop over USDHC slots; auto-index; drop _and_unref hw/arm/mcimx7d-sabre.c:62 | qdev_new_orphan | OBJECT(machine) | "sd-card[*]" | board init; loop over USDHC slots; auto-index; drop _and_unref hw/arm/sabrelite.c:99 | qdev_new_orphan | OBJECT(machine) | "spi-flash" | board init; single NOR flash on SPI bus; drop _and_unref

AI-used-for: code (refactoring)

---
 hw/arm/fsl-imx6.c      | 3 ++-
 hw/arm/imx25_pdk.c     | 4 ++--
 hw/arm/imx8mm-evk.c    | 4 ++--
 hw/arm/imx8mp-evk.c    | 4 ++--
 hw/arm/mcimx6ul-evk.c  | 4 ++--
 hw/arm/mcimx7d-sabre.c | 4 ++--
 hw/arm/sabrelite.c     | 5 +++--
 7 files changed, 15 insertions(+), 13 deletions(-)
hw/arm/fsl-imx6.c +2 -1
index 103adcc2bd..44046953be 100644
@@ -168,7 +168,8 @@ static void fsl_imx6_realize(DeviceState *dev, Error **errp)
     }
 
     /* L2 cache controller */
-    sysbus_create_simple_orphan("l2x0", FSL_IMX6_PL310_ADDR, NULL);
+    sysbus_create_simple(OBJECT(dev), "l2x0", "l2x0", FSL_IMX6_PL310_ADDR,
+                         NULL);
 
     if (!sysbus_realize(SYS_BUS_DEVICE(&s->ccm), errp)) {
         return;
hw/arm/imx25_pdk.c +2 -2
index 6976652370..9351d53850 100644
@@ -127,9 +127,9 @@ static void imx25_pdk_init(MachineState *machine)
         di = drive_get(IF_SD, 0, i);
         blk = di ? blk_by_legacy_dinfo(di) : NULL;
         bus = qdev_get_child_bus(DEVICE(&s->soc.esdhc[i]), "sd-bus");
-        carddev = qdev_new_orphan(TYPE_SD_CARD);
+        carddev = qdev_new(OBJECT(machine), "sd-card[*]", TYPE_SD_CARD);
         qdev_prop_set_drive_err(carddev, "drive", blk, &error_fatal);
-        qdev_realize_and_unref(carddev, bus, &error_fatal);
+        qdev_realize(carddev, bus, &error_fatal);
     }
 
     /*
hw/arm/imx8mm-evk.c +2 -2
index ce7693ca7a..72fa1930ae 100644
@@ -97,9 +97,9 @@ static void imx8mm_evk_init(MachineState *machine)
 
         blk = blk_by_legacy_dinfo(di);
         bus = qdev_get_child_bus(DEVICE(&s->usdhc[i]), "sd-bus");
-        carddev = qdev_new_orphan(TYPE_SD_CARD);
+        carddev = qdev_new(OBJECT(machine), "sd-card[*]", TYPE_SD_CARD);
         qdev_prop_set_drive_err(carddev, "drive", blk, &error_fatal);
-        qdev_realize_and_unref(carddev, bus, &error_fatal);
+        qdev_realize(carddev, bus, &error_fatal);
     }
 
     if (!qtest_enabled()) {
hw/arm/imx8mp-evk.c +2 -2
index 90cda63b49..6116e6e9dc 100644
@@ -110,9 +110,9 @@ static void imx8mp_evk_init(MachineState *machine)
 
         blk = blk_by_legacy_dinfo(di);
         bus = qdev_get_child_bus(DEVICE(&s->soc.usdhc[i]), "sd-bus");
-        carddev = qdev_new_orphan(TYPE_SD_CARD);
+        carddev = qdev_new(OBJECT(machine), "sd-card[*]", TYPE_SD_CARD);
         qdev_prop_set_drive_err(carddev, "drive", blk, &error_fatal);
-        qdev_realize_and_unref(carddev, bus, &error_fatal);
+        qdev_realize(carddev, bus, &error_fatal);
     }
 
     if (!qtest_enabled()) {
hw/arm/mcimx6ul-evk.c +2 -2
index 96309e1bfc..be4c4ca316 100644
@@ -59,9 +59,9 @@ static void mcimx6ul_evk_init(MachineState *machine)
         di = drive_get(IF_SD, 0, i);
         blk = di ? blk_by_legacy_dinfo(di) : NULL;
         bus = qdev_get_child_bus(DEVICE(&s->usdhc[i]), "sd-bus");
-        carddev = qdev_new_orphan(TYPE_SD_CARD);
+        carddev = qdev_new(OBJECT(machine), "sd-card[*]", TYPE_SD_CARD);
         qdev_prop_set_drive_err(carddev, "drive", blk, &error_fatal);
-        qdev_realize_and_unref(carddev, bus, &error_fatal);
+        qdev_realize(carddev, bus, &error_fatal);
     }
 
     if (!qtest_enabled()) {
hw/arm/mcimx7d-sabre.c +2 -2
index be9d0d6993..d8b1e7fc7e 100644
@@ -59,9 +59,9 @@ static void mcimx7d_sabre_init(MachineState *machine)
         di = drive_get(IF_SD, 0, i);
         blk = di ? blk_by_legacy_dinfo(di) : NULL;
         bus = qdev_get_child_bus(DEVICE(&s->usdhc[i]), "sd-bus");
-        carddev = qdev_new_orphan(TYPE_SD_CARD);
+        carddev = qdev_new(OBJECT(machine), "sd-card[*]", TYPE_SD_CARD);
         qdev_prop_set_drive_err(carddev, "drive", blk, &error_fatal);
-        qdev_realize_and_unref(carddev, bus, &error_fatal);
+        qdev_realize(carddev, bus, &error_fatal);
     }
 
     if (!qtest_enabled()) {
hw/arm/sabrelite.c +3 -2
index af4dfef7f2..04c764f82f 100644
@@ -96,13 +96,14 @@ static void sabrelite_init(MachineState *machine)
                 qemu_irq cs_line;
                 DriveInfo *dinfo = drive_get(IF_MTD, 0, 0);
 
-                flash_dev = qdev_new_orphan("sst25vf016b");
+                flash_dev = qdev_new(OBJECT(machine), "spi-flash",
+                                     "sst25vf016b");
                 if (dinfo) {
                     qdev_prop_set_drive_err(flash_dev, "drive",
                                             blk_by_legacy_dinfo(dinfo),
                                             &error_fatal);
                 }
-                qdev_realize_and_unref(flash_dev, BUS(spi_bus), &error_fatal);
+                qdev_realize(flash_dev, BUS(spi_bus), &error_fatal);
 
                 cs_line = qdev_get_gpio_in_named(flash_dev, SSI_GPIO_CS, 0);
                 qdev_connect_gpio_out(DEVICE(&s->soc.gpio[2]), 19, cs_line);
Signature · 1 line
2.47.1
#228 lore raw

RFC PATCH v2 71/137 hw/arm/misc: Give onboard devices a QOM parent

In reply to Alexander Graf

Convert the *_orphan() device-creation calls in the hw/arm misc board files 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 SoC device for composite children. Names follow existing QOM conventions.

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

hw/arm/max78000fthr.c:29 | qdev_new_orphan | OBJECT(machine) | "soc" | board init; existing add_child(machine,"soc") collapsed; drop _and_unref

hw/arm/msf2-som.c:62 | qdev_new_orphan | OBJECT(machine) | "soc" | board init; existing add_child(machine,"soc") collapsed; drop _and_unref
hw/arm/msf2-som.c:86 | qdev_new_orphan | OBJECT(machine) | "spi-flash" | board init; single m25p80 flash on SPI bus; drop _and_unref

hw/arm/netduino2.c:47 | qdev_new_orphan | OBJECT(machine) | "soc" | board init; existing add_child(machine,"soc") collapsed; drop _and_unref hw/arm/netduinoplus2.c:47 | qdev_new_orphan | OBJECT(machine) | "soc" | board init; existing add_child(machine,"soc") collapsed; drop _and_unref hw/arm/olimex-stm32-h405.c:50 | qdev_new_orphan | OBJECT(machine) | "soc" | board init; existing add_child(machine,"soc") collapsed; drop _and_unref hw/arm/raspi.c:286 | qdev_new_orphan | OBJECT(machine) | "sd-card" | raspi_base_machine_init(MachineState *machine); single SD card; drop _and_unref hw/arm/stm32vldiscovery.c:50 | qdev_new_orphan | OBJECT(machine) | "soc" | board init; existing add_child(machine,"soc") collapsed; drop _and_unref

AI-used-for: code (refactoring)

---
 hw/arm/max78000fthr.c      |  5 ++---
 hw/arm/msf2-som.c          | 10 +++++-----
 hw/arm/netduino2.c         |  5 ++---
 hw/arm/netduinoplus2.c     |  5 ++---
 hw/arm/olimex-stm32-h405.c |  5 ++---
 hw/arm/raspi.c             |  4 ++--
 hw/arm/stm32vldiscovery.c  |  5 ++---
 7 files changed, 17 insertions(+), 22 deletions(-)
hw/arm/max78000fthr.c +2 -3
index d2fb4c018b..e38a3340a4 100644
@@ -26,10 +26,9 @@ static void max78000_init(MachineState *machine)
     sysclk = clock_new(OBJECT(machine), "SYSCLK");
     clock_set_hz(sysclk, SYSCLK_FRQ);
 
-    dev = qdev_new_orphan(TYPE_MAX78000_SOC);
-    object_property_add_child(OBJECT(machine), "soc", OBJECT(dev));
+    dev = qdev_new(OBJECT(machine), "soc", TYPE_MAX78000_SOC);
     qdev_connect_clock_in(dev, "sysclk", sysclk);
-    sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
+    sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
 
     armv7m_load_kernel(ARM_CPU(first_cpu),
                        machine->kernel_filename,
hw/arm/msf2-som.c +5 -5
index bb1e774764..0d0e2514dd 100644
@@ -59,8 +59,7 @@ static void emcraft_sf2_s2s010_init(MachineState *machine)
                            &error_fatal);
     memory_region_add_subregion(sysmem, DDR_BASE_ADDRESS, ddr);
 
-    dev = qdev_new_orphan(TYPE_MSF2_SOC);
-    object_property_add_child(OBJECT(machine), "soc", OBJECT(dev));
+    dev = qdev_new(OBJECT(machine), "soc", TYPE_MSF2_SOC);
     qdev_prop_set_string(dev, "part-name", "M2S010");
     qdev_prop_set_uint64(dev, "eNVM-size", M2S010_ENVM_SIZE);
     qdev_prop_set_uint64(dev, "eSRAM-size", M2S010_ESRAM_SIZE);
@@ -77,19 +76,20 @@ static void emcraft_sf2_s2s010_init(MachineState *machine)
     qdev_prop_set_uint32(dev, "apb0div", 2);
     qdev_prop_set_uint32(dev, "apb1div", 2);
 
-    sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
+    sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
 
     soc = MSF2_SOC(dev);
 
     /* Attach SPI flash to SPI0 controller */
     spi_bus = qdev_get_child_bus(dev, "spi0");
-    spi_flash = qdev_new_orphan("s25sl12801"); /* Spansion S25FL128SDPBHICO */
+    /* Spansion S25FL128SDPBHICO */
+    spi_flash = qdev_new(OBJECT(machine), "spi-flash", "s25sl12801");
     qdev_prop_set_uint8(spi_flash, "spansion-cr2nv", 0x8);
     if (dinfo) {
         qdev_prop_set_drive_err(spi_flash, "drive",
                                 blk_by_legacy_dinfo(dinfo), &error_fatal);
     }
-    qdev_realize_and_unref(spi_flash, spi_bus, &error_fatal);
+    qdev_realize(spi_flash, spi_bus, &error_fatal);
     cs_line = qdev_get_gpio_in_named(spi_flash, SSI_GPIO_CS, 0);
     sysbus_connect_irq(SYS_BUS_DEVICE(&soc->spi[0]), 1, cs_line);
 
hw/arm/netduino2.c +2 -3
index cee887c194..9a1caf06a1 100644
@@ -44,10 +44,9 @@ static void netduino2_init(MachineState *machine)
     sysclk = clock_new(OBJECT(machine), "SYSCLK");
     clock_set_hz(sysclk, SYSCLK_FRQ);
 
-    dev = qdev_new_orphan(TYPE_STM32F205_SOC);
-    object_property_add_child(OBJECT(machine), "soc", OBJECT(dev));
+    dev = qdev_new(OBJECT(machine), "soc", TYPE_STM32F205_SOC);
     qdev_connect_clock_in(dev, "sysclk", sysclk);
-    sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
+    sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
 
     armv7m_load_kernel(STM32F205_SOC(dev)->armv7m.cpu, machine->kernel_filename,
                        0, FLASH_SIZE);
hw/arm/netduinoplus2.c +2 -3
index 65251dfe96..564dae1f16 100644
@@ -44,10 +44,9 @@ static void netduinoplus2_init(MachineState *machine)
     sysclk = clock_new(OBJECT(machine), "SYSCLK");
     clock_set_hz(sysclk, SYSCLK_FRQ);
 
-    dev = qdev_new_orphan(TYPE_STM32F405_SOC);
-    object_property_add_child(OBJECT(machine), "soc", OBJECT(dev));
+    dev = qdev_new(OBJECT(machine), "soc", TYPE_STM32F405_SOC);
     qdev_connect_clock_in(dev, "sysclk", sysclk);
-    sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
+    sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
 
     armv7m_load_kernel(STM32F405_SOC(dev)->armv7m.cpu,
                        machine->kernel_filename,
hw/arm/olimex-stm32-h405.c +2 -3
index 70f7791695..b24142e909 100644
@@ -47,10 +47,9 @@ static void olimex_stm32_h405_init(MachineState *machine)
     sysclk = clock_new(OBJECT(machine), "SYSCLK");
     clock_set_hz(sysclk, SYSCLK_FRQ);
 
-    dev = qdev_new_orphan(TYPE_STM32F405_SOC);
-    object_property_add_child(OBJECT(machine), "soc", OBJECT(dev));
+    dev = qdev_new(OBJECT(machine), "soc", TYPE_STM32F405_SOC);
     qdev_connect_clock_in(dev, "sysclk", sysclk);
-    sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
+    sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
 
     armv7m_load_kernel(STM32F405_SOC(dev)->armv7m.cpu,
                        machine->kernel_filename,
hw/arm/raspi.c +2 -2
index 2d5f51506d..55ca84cd1d 100644
@@ -283,9 +283,9 @@ void raspi_base_machine_init(MachineState *machine,
         error_report("No SD bus found in SOC object");
         exit(1);
     }
-    carddev = qdev_new_orphan(TYPE_SD_CARD);
+    carddev = qdev_new(OBJECT(machine), "sd-card", TYPE_SD_CARD);
     qdev_prop_set_drive_err(carddev, "drive", blk, &error_fatal);
-    qdev_realize_and_unref(carddev, bus, &error_fatal);
+    qdev_realize(carddev, bus, &error_fatal);
 
     vcram_size = object_property_get_uint(OBJECT(soc), "vcram-size",
                                           &error_abort);
hw/arm/stm32vldiscovery.c +2 -3
index 8c37d41e63..69503805cb 100644
@@ -47,10 +47,9 @@ static void stm32vldiscovery_init(MachineState *machine)
     sysclk = clock_new(OBJECT(machine), "SYSCLK");
     clock_set_hz(sysclk, SYSCLK_FRQ);
 
-    dev = qdev_new_orphan(TYPE_STM32F100_SOC);
-    object_property_add_child(OBJECT(machine), "soc", OBJECT(dev));
+    dev = qdev_new(OBJECT(machine), "soc", TYPE_STM32F100_SOC);
     qdev_connect_clock_in(dev, "sysclk", sysclk);
-    sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
+    sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
 
     armv7m_load_kernel(STM32F100_SOC(dev)->armv7m.cpu,
                        machine->kernel_filename,
Signature · 1 line
2.47.1
#229 lore raw

RFC PATCH v2 72/137 hw/arm/aspeed: Give onboard devices a QOM parent (part 1)

In reply to Alexander Graf

Convert the *_orphan() device-creation calls in the smaller hw/arm/aspeed_* board files and the shared aspeed helpers 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 (AspeedMachineState) for board-created I2C peripherals, the containing SoC device for composite children. Names follow existing QOM conventions.

The shared helpers aspeed_create_pca9552(), aspeed_create_pca9554() and aspeed_soc_uart_realize() gain an Object *parent first argument; callers in the four large aspeed board files are updated here so this commit builds standalone, but the direct *_orphan() calls in those four files are converted in the next commit.

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

hw/arm/aspeed_* boards — per-callsite rationale (62 sites)
============================================================

Common context: all *_i2c_init(AspeedMachineState *bmc) callbacks are invoked from aspeed_machine_init() (mc->init) via amc->i2c_init(bmc). bmc is the MachineState → parent = OBJECT(bmc). i2c_slave_create_simple realizes internally, so no realize-call change needed. i2c_slave_new pairs with qdev_realize (i2c_slave_realize does not exist).

File:Line                                Old call                              Parent          Name          Notes
---------------------------------------  ------------------------------------  --------------  ------------  ------------------------------------------
aspeed_ast1040_evb.c:59                  i2c_slave_create_simple_orphan        OBJECT(bmc)     "tmp105"      board i2c_init callback
aspeed_ast10x0_evb.c:77                  i2c_slave_create_simple_orphan        OBJECT(bmc)     "tmp105"      board i2c_init callback
aspeed_ast2400_palmetto.c:40             i2c_slave_create_simple_orphan        OBJECT(bmc)     "rtc"         ds1338 RTC
aspeed_ast2400_palmetto.c:46             i2c_slave_create_simple_orphan        OBJECT(bmc)     "tmp423"      single instance
aspeed_ast2400_quanta-q71l.c:36          i2c_slave_create_simple_orphan        OBJECT(bmc)     "tmp105[*]"   3× tmp105 → auto-index
aspeed_ast2400_quanta-q71l.c:37          i2c_slave_create_simple_orphan        OBJECT(bmc)     "tmp105[*]"
aspeed_ast2400_quanta-q71l.c:38          i2c_slave_create_simple_orphan        OBJECT(bmc)     "tmp105[*]"
aspeed_ast2400_quanta-q71l.c:44          i2c_slave_create_simple_orphan        OBJECT(bmc)     "i2c-mux[*]"  pca954x muxes
aspeed_ast2400_quanta-q71l.c:45          i2c_slave_create_simple_orphan        OBJECT(bmc)     "i2c-mux[*]"
aspeed_ast2400_quanta-q71l.c:50          i2c_slave_create_simple_orphan        OBJECT(bmc)     "i2c-mux[*]"
aspeed_ast2400_supermicrox11.c:40        i2c_slave_create_simple_orphan        OBJECT(bmc)     "rtc"         ds1338
aspeed_ast2400_supermicrox11.c:46        i2c_slave_create_simple_orphan        OBJECT(bmc)     "tmp423"
aspeed_ast2500_evb.c:37                  i2c_slave_create_simple_orphan        OBJECT(bmc)     "tmp105"
aspeed_ast2500_g220a.c:35                i2c_slave_create_simple_orphan        OBJECT(bmc)     "emc1413[*]"  3× emc1413
aspeed_ast2500_g220a.c:41                i2c_slave_create_simple_orphan        OBJECT(bmc)     "emc1413[*]"
aspeed_ast2500_g220a.c:47                i2c_slave_create_simple_orphan        OBJECT(bmc)     "emc1413[*]"
aspeed_ast2500_romulus.c:33              i2c_slave_create_simple_orphan        OBJECT(bmc)     "rtc"         ds1338
aspeed_ast2500_supermicro-x11spi.c:36    i2c_slave_create_simple_orphan        OBJECT(bmc)     "rtc"         ds1338
aspeed_ast2500_supermicro-x11spi.c:42    i2c_slave_create_simple_orphan        OBJECT(bmc)     "tmp423"
aspeed_ast2500_tiogapass.c:58            i2c_slave_create_simple_orphan        OBJECT(bmc)     "tmp421[*]"   3× tmp421
aspeed_ast2500_tiogapass.c:59            i2c_slave_create_simple_orphan        OBJECT(bmc)     "tmp421[*]"
aspeed_ast2500_tiogapass.c:60            i2c_slave_create_simple_orphan        OBJECT(bmc)     "tmp421[*]"
aspeed_ast2500_witherspoon.c:47          i2c_slave_new_orphan                  OBJECT(bmc)     "pca9552[*]"  → i2c_slave_new; realize_and_unref → qdev_realize(dev, BUS(bus), ...)
aspeed_ast2500_witherspoon.c:61          i2c_slave_create_simple_orphan        OBJECT(bmc)     "dps310"
aspeed_ast2500_witherspoon.c:62          i2c_slave_create_simple_orphan        OBJECT(bmc)     "max31785"
aspeed_ast2500_witherspoon.c:63          i2c_slave_create_simple_orphan        OBJECT(bmc)     "tmp423[*]"   2× tmp423
aspeed_ast2500_witherspoon.c:64          i2c_slave_create_simple_orphan        OBJECT(bmc)     "tmp423[*]"
aspeed_ast2500_witherspoon.c:67          i2c_slave_create_simple_orphan        OBJECT(bmc)     "tmp105"
aspeed_ast2500_witherspoon.c:74          i2c_slave_create_simple_orphan        OBJECT(bmc)     "rtc"         ds1338
aspeed_ast2500_witherspoon.c:78          i2c_slave_new_orphan                  OBJECT(bmc)     "pca9552[*]"  → i2c_slave_new; realize_and_unref → qdev_realize
aspeed_ast2500_yosemitev2.c:58           i2c_slave_create_simple_orphan        OBJECT(bmc)     "tmp421[*]"   3× tmp421
aspeed_ast2500_yosemitev2.c:59           i2c_slave_create_simple_orphan        OBJECT(bmc)     "tmp421[*]"
aspeed_ast2500_yosemitev2.c:60           i2c_slave_create_simple_orphan        OBJECT(bmc)     "tmp421[*]"
aspeed_ast2600_bletchley.c:38            i2c_slave_create_simple_orphan        OBJECT(bmc)     "tmp421[*]"   loop 0..5
aspeed_ast2600_bletchley.c:40            i2c_slave_create_simple_orphan        OBJECT(bmc)     "pca9552[*]"  loop 0..5
aspeed_ast2600_bletchley.c:41            i2c_slave_create_simple_orphan        OBJECT(bmc)     "pca9552[*]"  loop 0..5
aspeed_ast2600_bletchley.c:48            i2c_slave_create_simple_orphan        OBJECT(bmc)     "rtc"         ds1338
aspeed_ast2600_bletchley.c:55            i2c_slave_create_simple_orphan        OBJECT(bmc)     "tmp421[*]"
aspeed_ast2600_bletchley.c:58            i2c_slave_create_simple_orphan        OBJECT(bmc)     "tmp421[*]"
aspeed_ast2600_bletchley.c:60            i2c_slave_create_simple_orphan        OBJECT(bmc)     "pca9552[*]"
aspeed_ast2600_bletchley.c:64            i2c_slave_create_simple_orphan        OBJECT(bmc)     "tmp421[*]"
aspeed_ast2600_bletchley.c:65            i2c_slave_create_simple_orphan        OBJECT(bmc)     "tmp421[*]"
aspeed_ast2600_bletchley.c:66            i2c_slave_create_simple_orphan        OBJECT(bmc)     "pca9552[*]"
aspeed_ast2600_evb.c:30                  i2c_slave_create_simple_orphan        OBJECT(bmc)     "tmp105"
aspeed_ast2600_fby35.c:105               i2c_slave_create_simple_orphan        OBJECT(bmc)     "lm75[*]"     3× LM75 total
aspeed_ast2600_fby35.c:106               i2c_slave_create_simple_orphan        OBJECT(bmc)     "tmp421"
aspeed_ast2600_fby35.c:108               i2c_slave_create_simple_orphan        OBJECT(bmc)     "adm1272"
aspeed_ast2600_fby35.c:109               i2c_slave_create_simple_orphan        OBJECT(bmc)     "lm75[*]"
aspeed_ast2600_fby35.c:110               i2c_slave_create_simple_orphan        OBJECT(bmc)     "lm75[*]"
aspeed_ast2600_gb200nvl.c:57             i2c_slave_create_simple_orphan        OBJECT(bmc)     "i2c-mux[*]"  6× pca9546
aspeed_ast2600_gb200nvl.c:58             i2c_slave_create_simple_orphan        OBJECT(bmc)     "i2c-mux[*]"
aspeed_ast2600_gb200nvl.c:59             i2c_slave_create_simple_orphan        OBJECT(bmc)     "i2c-mux[*]"
aspeed_ast2600_gb200nvl.c:60             i2c_slave_create_simple_orphan        OBJECT(bmc)     "i2c-mux[*]"
aspeed_ast2600_gb200nvl.c:61             i2c_slave_create_simple_orphan        OBJECT(bmc)     "i2c-mux[*]"
aspeed_ast2600_gb200nvl.c:62             i2c_slave_create_simple_orphan        OBJECT(bmc)     "i2c-mux[*]"
aspeed_ast27x0_evb.c:27                  i2c_slave_create_simple_orphan        OBJECT(bmc)     "tmp105"
aspeed_ast27x0-fc.c:112                  i2c_slave_create_simple_orphan        OBJECT(machine) "tmp105"      ast2700fc_ca35_init(MachineState *machine)
aspeed.c:93                              qdev_new_orphan                       parent          "sd-card[*]"  static helper sdhci_attach_drive(): threaded

Object *parent as first arg; callers pass OBJECT(bmc) from aspeed_machine_init. qdev_realize_and_unref → qdev_realize.
aspeed.c:256 i2c_slave_create_simple_orphan parent "pca9552[*]" aspeed_create_pca9552(): threaded Object *parent
first arg. Prototype in include/hw/arm/aspeed.h updated. Callers in rainier.c, gb200nvl.c updated to pass OBJECT(bmc).
aspeed.c:262 i2c_slave_create_simple_orphan parent "pca9554[*]" aspeed_create_pca9554(): threaded Object *parent
first arg. Prototype updated. Callers in gb200nvl.c updated to pass OBJECT(bmc).
aspeed_soc_common.c:84 qdev_new_orphan OBJECT(s) "ram-empty" aspeed_soc_dram_init(AspeedSoCState *s) called
from SoC realize (ast2400/2600). Parent = SoC. sysbus_realize_and_unref → sysbus_realize.
aspeed_soc_common.c:131 qdev_new_orphan parent "flash[*]" aspeed_board_init_flashes(): threaded Object
*parent first arg. Called from board init (aspeed.c, ast10x0_evb.c, ast27x0-fc.c) — all callers pass OBJECT(bmc)/OBJECT(machine). Prototype in include/hw/arm/aspeed_soc.h updated. qdev_realize_and_unref → qdev_realize.

Threaded-parent helper changes (all callers updated in same diff):

  sdhci_attach_drive()        hw/arm/aspeed.c (static)     — 2 callers in aspeed.c
  aspeed_create_pca9552()     hw/arm/aspeed.c + aspeed.h   — 16 callers in aspeed_ast2600_rainier.c
  aspeed_create_pca9554()     hw/arm/aspeed.c + aspeed.h   — 3 callers in aspeed_ast2600_gb200nvl.c
  aspeed_board_init_flashes() hw/arm/aspeed_soc_common.c + aspeed_soc.h — 8 callers
                              (aspeed.c ×3, ast10x0_evb.c ×3, ast27x0-fc.c ×2)

Not touched (per instructions): at24c_eeprom_init*(), smbus_eeprom_init*().

orphan_justified = 0

AI-used-for: code (refactoring)

---
 hw/arm/aspeed.c                           | 37 +++++++++++++----------
 hw/arm/aspeed_ast1040_evb.c               |  3 +-
 hw/arm/aspeed_ast10x0_evb.c               |  9 +++---
 hw/arm/aspeed_ast2400_palmetto.c          |  6 ++--
 hw/arm/aspeed_ast2400_quanta-q71l.c       | 18 +++++++----
 hw/arm/aspeed_ast2400_supermicrox11.c     |  6 ++--
 hw/arm/aspeed_ast2500_evb.c               |  5 +--
 hw/arm/aspeed_ast2500_g220a.c             |  9 ++++--
 hw/arm/aspeed_ast2500_romulus.c           |  3 +-
 hw/arm/aspeed_ast2500_supermicro-x11spi.c |  6 ++--
 hw/arm/aspeed_ast2500_tiogapass.c         |  9 ++++--
 hw/arm/aspeed_ast2500_witherspoon.c       | 32 +++++++++++---------
 hw/arm/aspeed_ast2500_yosemitev2.c        |  9 ++++--
 hw/arm/aspeed_ast2600_bletchley.c         | 29 ++++++++++++------
 hw/arm/aspeed_ast2600_evb.c               |  5 +--
 hw/arm/aspeed_ast2600_fby35.c             | 10 +++---
 hw/arm/aspeed_ast2600_gb200nvl.c          | 18 +++++------
 hw/arm/aspeed_ast2600_rainier.c           | 32 ++++++++++----------
 hw/arm/aspeed_ast27x0-fc.c                |  9 ++++--
 hw/arm/aspeed_ast27x0_evb.c               |  3 +-
 hw/arm/aspeed_soc_common.c                | 12 +++++---
 include/hw/arm/aspeed.h                   | 10 +++---
 include/hw/arm/aspeed_soc.h               |  3 +-
 23 files changed, 167 insertions(+), 116 deletions(-)
hw/arm/aspeed.c +21 -16
index 4a4c1f1556..2e76e09f8f 100644
@@ -82,15 +82,16 @@ static void aspeed_reset_secondary(ARMCPU *cpu,
     cpu_set_pc(cs, info->smp_loader_start);
 }
 
-static void sdhci_attach_drive(SDHCIState *sdhci, DriveInfo *dinfo, bool emmc,
-                               bool boot_emmc)
+static void sdhci_attach_drive(Object *parent, SDHCIState *sdhci,
+                               DriveInfo *dinfo, bool emmc, bool boot_emmc)
 {
         DeviceState *card;
 
         if (!dinfo) {
             return;
         }
-        card = qdev_new_orphan(emmc ? TYPE_EMMC : TYPE_SD_CARD);
+        card = qdev_new(parent, "sd-card[*]",
+                        emmc ? TYPE_EMMC : TYPE_SD_CARD);
 
         /*
          * Force the boot properties of the eMMC device only when the
@@ -108,9 +109,8 @@ static void sdhci_attach_drive(SDHCIState *sdhci, DriveInfo *dinfo, bool emmc,
         }
         qdev_prop_set_drive_err(card, "drive", blk_by_legacy_dinfo(dinfo),
                                 &error_fatal);
-        qdev_realize_and_unref(card,
-                               qdev_get_child_bus(DEVICE(sdhci), "sd-bus"),
-                               &error_fatal);
+        qdev_realize(card, qdev_get_child_bus(DEVICE(sdhci), "sd-bus"),
+                     &error_fatal);
 }
 
 void aspeed_connect_serial_hds_to_uarts(AspeedMachineState *bmc)
@@ -188,13 +188,13 @@ static void aspeed_machine_init(MachineState *machine)
     qdev_realize(DEVICE(bmc->soc), NULL, &error_abort);
 
     if (defaults_enabled()) {
-        aspeed_board_init_flashes(&bmc->soc->fmc,
+        aspeed_board_init_flashes(OBJECT(bmc), &bmc->soc->fmc,
                               bmc->fmc_model ? bmc->fmc_model : amc->fmc_model,
                               amc->num_cs, 0);
-        aspeed_board_init_flashes(&bmc->soc->spi[0],
+        aspeed_board_init_flashes(OBJECT(bmc), &bmc->soc->spi[0],
                               bmc->spi_model ? bmc->spi_model : amc->spi_model,
                               1, amc->num_cs);
-        aspeed_board_init_flashes(&bmc->soc->spi[1],
+        aspeed_board_init_flashes(OBJECT(bmc), &bmc->soc->spi[1],
                                   amc->spi2_model, 1, amc->num_cs2);
     }
 
@@ -219,7 +219,7 @@ static void aspeed_machine_init(MachineState *machine)
     }
 
     for (i = 0; i < bmc->soc->sdhci.num_slots && defaults_enabled(); i++) {
-        sdhci_attach_drive(&bmc->soc->sdhci.slots[i],
+        sdhci_attach_drive(OBJECT(bmc), &bmc->soc->sdhci.slots[i],
                            drive_get(IF_SD, 0, i), false, false);
     }
 
@@ -227,7 +227,8 @@ static void aspeed_machine_init(MachineState *machine)
 
     if (bmc->soc->emmc.num_slots && defaults_enabled()) {
         emmc0 = drive_get(IF_SD, 0, bmc->soc->sdhci.num_slots);
-        sdhci_attach_drive(&bmc->soc->emmc.slots[0], emmc0, true, boot_emmc);
+        sdhci_attach_drive(OBJECT(bmc), &bmc->soc->emmc.slots[0], emmc0,
+                           true, boot_emmc);
     }
 
     if (!bmc->mmio_exec) {
@@ -251,16 +252,20 @@ static void aspeed_machine_init(MachineState *machine)
     arm_load_kernel(ARM_CPU(first_cpu), machine, &aspeed_board_binfo);
 }
 
-void aspeed_create_pca9552(AspeedSoCState *soc, int bus_id, int addr)
+void aspeed_create_pca9552(Object *parent, AspeedSoCState *soc, int bus_id,
+                           int addr)
 {
-    i2c_slave_create_simple_orphan(aspeed_i2c_get_bus(&soc->i2c, bus_id),
+    i2c_slave_create_simple(parent, "pca9552[*]",
+                            aspeed_i2c_get_bus(&soc->i2c, bus_id),
                             TYPE_PCA9552, addr);
 }
 
-I2CSlave *aspeed_create_pca9554(AspeedSoCState *soc, int bus_id, int addr)
+I2CSlave *aspeed_create_pca9554(Object *parent, AspeedSoCState *soc,
+                                int bus_id, int addr)
 {
-    return i2c_slave_create_simple_orphan(aspeed_i2c_get_bus(&soc->i2c, bus_id),
-                            TYPE_PCA9554, addr);
+    return i2c_slave_create_simple(parent, "pca9554[*]",
+                                   aspeed_i2c_get_bus(&soc->i2c, bus_id),
+                                   TYPE_PCA9554, addr);
 }
 
 static bool aspeed_get_mmio_exec(Object *obj, Error **errp)
hw/arm/aspeed_ast1040_evb.c +2 -1
index fb83087b13..bbb1ebb104 100644
@@ -56,7 +56,8 @@ static void ast1040_evb_i2c_init(AspeedMachineState *bmc)
 
     smbus_eeprom_init_one(OBJECT(bmc), aspeed_i2c_get_bus(&soc->i2c, 0), 0x50,
                           eeprom_buf);
-    i2c_slave_create_simple_orphan(aspeed_i2c_get_bus(&soc->i2c, 1), "tmp105", 0x4d);
+    i2c_slave_create_simple(OBJECT(bmc), "tmp105",
+                            aspeed_i2c_get_bus(&soc->i2c, 1), "tmp105", 0x4d);
 }
 
 static void aspeed_machine_ast1040_evb_class_init(ObjectClass *oc,
hw/arm/aspeed_ast10x0_evb.c +5 -4
index dc134b555c..5153cf7c55 100644
@@ -40,16 +40,16 @@ static void aspeed_minibmc_machine_init(MachineState *machine)
     qdev_realize(DEVICE(bmc->soc), NULL, &error_abort);
 
     if (defaults_enabled()) {
-        aspeed_board_init_flashes(&bmc->soc->fmc,
+        aspeed_board_init_flashes(OBJECT(bmc), &bmc->soc->fmc,
                             bmc->fmc_model ? bmc->fmc_model : amc->fmc_model,
                             amc->num_cs,
                             0);
 
-        aspeed_board_init_flashes(&bmc->soc->spi[0],
+        aspeed_board_init_flashes(OBJECT(bmc), &bmc->soc->spi[0],
                             bmc->spi_model ? bmc->spi_model : amc->spi_model,
                             amc->num_cs, amc->num_cs);
 
-        aspeed_board_init_flashes(&bmc->soc->spi[1],
+        aspeed_board_init_flashes(OBJECT(bmc), &bmc->soc->spi[1],
                             bmc->spi_model ? bmc->spi_model : amc->spi_model,
                             amc->num_cs, (amc->num_cs * 2));
     }
@@ -74,7 +74,8 @@ static void ast1030_evb_i2c_init(AspeedMachineState *bmc)
                           eeprom_buf);
 
     /* U11 LM75 connects to SDA/SCL Group 2 by default */
-    i2c_slave_create_simple_orphan(aspeed_i2c_get_bus(&soc->i2c, 1), "tmp105", 0x4d);
+    i2c_slave_create_simple(OBJECT(bmc), "tmp105",
+                            aspeed_i2c_get_bus(&soc->i2c, 1), "tmp105", 0x4d);
 }
 
 static void aspeed_minibmc_machine_ast1030_evb_class_init(ObjectClass *oc,
hw/arm/aspeed_ast2400_palmetto.c +4 -2
index 80f9c911b8..3ca52cc7a5 100644
@@ -37,13 +37,15 @@ static void palmetto_bmc_i2c_init(AspeedMachineState *bmc)
      * The palmetto platform expects a ds3231 RTC but a ds1338 is
      * enough to provide basic RTC features. Alarms will be missing
      */
-    i2c_slave_create_simple_orphan(aspeed_i2c_get_bus(&soc->i2c, 0), "ds1338", 0x68);
+    i2c_slave_create_simple(OBJECT(bmc), "rtc",
+                            aspeed_i2c_get_bus(&soc->i2c, 0), "ds1338", 0x68);
 
     smbus_eeprom_init_one(OBJECT(bmc), aspeed_i2c_get_bus(&soc->i2c, 0), 0x50,
                           eeprom_buf);
 
     /* add a TMP423 temperature sensor */
-    dev = DEVICE(i2c_slave_create_simple_orphan(aspeed_i2c_get_bus(&soc->i2c, 2),
+    dev = DEVICE(i2c_slave_create_simple(OBJECT(bmc), "tmp423",
+                                         aspeed_i2c_get_bus(&soc->i2c, 2),
                                          "tmp423", 0x4c));
     object_property_set_int(OBJECT(dev), "temperature0", 31000, &error_abort);
     object_property_set_int(OBJECT(dev), "temperature1", 28000, &error_abort);
hw/arm/aspeed_ast2400_quanta-q71l.c +12 -6
index 802ae49604..cc358b9ecf 100644
@@ -33,21 +33,27 @@ static void quanta_q71l_bmc_i2c_init(AspeedMachineState *bmc)
      * The quanta-q71l platform expects tmp75s which are compatible with
      * tmp105s.
      */
-    i2c_slave_create_simple_orphan(aspeed_i2c_get_bus(&soc->i2c, 1), "tmp105", 0x4c);
-    i2c_slave_create_simple_orphan(aspeed_i2c_get_bus(&soc->i2c, 1), "tmp105", 0x4e);
-    i2c_slave_create_simple_orphan(aspeed_i2c_get_bus(&soc->i2c, 1), "tmp105", 0x4f);
+    i2c_slave_create_simple(OBJECT(bmc), "tmp105[*]",
+                            aspeed_i2c_get_bus(&soc->i2c, 1), "tmp105", 0x4c);
+    i2c_slave_create_simple(OBJECT(bmc), "tmp105[*]",
+                            aspeed_i2c_get_bus(&soc->i2c, 1), "tmp105", 0x4e);
+    i2c_slave_create_simple(OBJECT(bmc), "tmp105[*]",
+                            aspeed_i2c_get_bus(&soc->i2c, 1), "tmp105", 0x4f);
 
     /* TODO: i2c-1: Add baseboard FRU eeprom@54 24c64 */
     /* TODO: i2c-1: Add Frontpanel FRU eeprom@57 24c64 */
     /* TODO: Add Memory Riser i2c mux and eeproms. */
 
-    i2c_slave_create_simple_orphan(aspeed_i2c_get_bus(&soc->i2c, 2), "pca9546", 0x74);
-    i2c_slave_create_simple_orphan(aspeed_i2c_get_bus(&soc->i2c, 2), "pca9548", 0x77);
+    i2c_slave_create_simple(OBJECT(bmc), "i2c-mux[*]",
+                            aspeed_i2c_get_bus(&soc->i2c, 2), "pca9546", 0x74);
+    i2c_slave_create_simple(OBJECT(bmc), "i2c-mux[*]",
+                            aspeed_i2c_get_bus(&soc->i2c, 2), "pca9548", 0x77);
 
     /* TODO: i2c-3: Add BIOS FRU eeprom@56 24c64 */
 
     /* i2c-7 */
-    i2c_slave_create_simple_orphan(aspeed_i2c_get_bus(&soc->i2c, 7), "pca9546", 0x70);
+    i2c_slave_create_simple(OBJECT(bmc), "i2c-mux[*]",
+                            aspeed_i2c_get_bus(&soc->i2c, 7), "pca9546", 0x70);
     /*        - i2c@0: pmbus@59 */
     /*        - i2c@1: pmbus@58 */
     /*        - i2c@2: pmbus@58 */
hw/arm/aspeed_ast2400_supermicrox11.c +4 -2
index b18adf3981..cabeb951f9 100644
@@ -37,13 +37,15 @@ static void supermicrox11_bmc_i2c_init(AspeedMachineState *bmc)
      * The palmetto platform expects a ds3231 RTC but a ds1338 is
      * enough to provide basic RTC features. Alarms will be missing
      */
-    i2c_slave_create_simple_orphan(aspeed_i2c_get_bus(&soc->i2c, 0), "ds1338", 0x68);
+    i2c_slave_create_simple(OBJECT(bmc), "rtc",
+                            aspeed_i2c_get_bus(&soc->i2c, 0), "ds1338", 0x68);
 
     smbus_eeprom_init_one(OBJECT(bmc), aspeed_i2c_get_bus(&soc->i2c, 0), 0x50,
                           eeprom_buf);
 
     /* add a TMP423 temperature sensor */
-    dev = DEVICE(i2c_slave_create_simple_orphan(aspeed_i2c_get_bus(&soc->i2c, 2),
+    dev = DEVICE(i2c_slave_create_simple(OBJECT(bmc), "tmp423",
+                                         aspeed_i2c_get_bus(&soc->i2c, 2),
                                          "tmp423", 0x4c));
     object_property_set_int(OBJECT(dev), "temperature0", 31000, &error_abort);
     object_property_set_int(OBJECT(dev), "temperature1", 28000, &error_abort);
hw/arm/aspeed_ast2500_evb.c +3 -2
index ba8a56bafd..933ffa087a 100644
@@ -34,8 +34,9 @@ static void ast2500_evb_i2c_init(AspeedMachineState *bmc)
                           eeprom_buf);
 
     /* The AST2500 EVB expects a LM75 but a TMP105 is compatible */
-    i2c_slave_create_simple_orphan(aspeed_i2c_get_bus(&soc->i2c, 7),
-                     TYPE_TMP105, 0x4d);
+    i2c_slave_create_simple(OBJECT(bmc), "tmp105",
+                            aspeed_i2c_get_bus(&soc->i2c, 7),
+                            TYPE_TMP105, 0x4d);
 }
 
 static void aspeed_machine_ast2500_evb_class_init(ObjectClass *oc,
hw/arm/aspeed_ast2500_g220a.c +6 -3
index 27c9dc436a..c7c3e3efd3 100644
@@ -32,19 +32,22 @@ static void g220a_bmc_i2c_init(AspeedMachineState *bmc)
     AspeedSoCState *soc = bmc->soc;
     DeviceState *dev;
 
-    dev = DEVICE(i2c_slave_create_simple_orphan(aspeed_i2c_get_bus(&soc->i2c, 3),
+    dev = DEVICE(i2c_slave_create_simple(OBJECT(bmc), "emc1413[*]",
+                                         aspeed_i2c_get_bus(&soc->i2c, 3),
                                          "emc1413", 0x4c));
     object_property_set_int(OBJECT(dev), "temperature0", 31000, &error_abort);
     object_property_set_int(OBJECT(dev), "temperature1", 28000, &error_abort);
     object_property_set_int(OBJECT(dev), "temperature2", 20000, &error_abort);
 
-    dev = DEVICE(i2c_slave_create_simple_orphan(aspeed_i2c_get_bus(&soc->i2c, 12),
+    dev = DEVICE(i2c_slave_create_simple(OBJECT(bmc), "emc1413[*]",
+                                         aspeed_i2c_get_bus(&soc->i2c, 12),
                                          "emc1413", 0x4c));
     object_property_set_int(OBJECT(dev), "temperature0", 31000, &error_abort);
     object_property_set_int(OBJECT(dev), "temperature1", 28000, &error_abort);
     object_property_set_int(OBJECT(dev), "temperature2", 20000, &error_abort);
 
-    dev = DEVICE(i2c_slave_create_simple_orphan(aspeed_i2c_get_bus(&soc->i2c, 13),
+    dev = DEVICE(i2c_slave_create_simple(OBJECT(bmc), "emc1413[*]",
+                                         aspeed_i2c_get_bus(&soc->i2c, 13),
                                          "emc1413", 0x4c));
     object_property_set_int(OBJECT(dev), "temperature0", 31000, &error_abort);
     object_property_set_int(OBJECT(dev), "temperature1", 28000, &error_abort);
hw/arm/aspeed_ast2500_romulus.c +2 -1
index 1bbd2802f1..9abb69d6a1 100644
@@ -30,7 +30,8 @@ static void romulus_bmc_i2c_init(AspeedMachineState *bmc)
      * The romulus board expects Epson RX8900 I2C RTC but a ds1338 is
      * good enough
      */
-    i2c_slave_create_simple_orphan(aspeed_i2c_get_bus(&soc->i2c, 11), "ds1338", 0x32);
+    i2c_slave_create_simple(OBJECT(bmc), "rtc",
+                            aspeed_i2c_get_bus(&soc->i2c, 11), "ds1338", 0x32);
 }
 
 static void aspeed_machine_romulus_class_init(ObjectClass *oc,
hw/arm/aspeed_ast2500_supermicro-x11spi.c +4 -2
index bea459eeaa..f20b2d5efb 100644
@@ -33,13 +33,15 @@ static void supermicro_x11spi_bmc_i2c_init(AspeedMachineState *bmc)
      * The palmetto platform expects a ds3231 RTC but a ds1338 is
      * enough to provide basic RTC features. Alarms will be missing
      */
-    i2c_slave_create_simple_orphan(aspeed_i2c_get_bus(&soc->i2c, 0), "ds1338", 0x68);
+    i2c_slave_create_simple(OBJECT(bmc), "rtc",
+                            aspeed_i2c_get_bus(&soc->i2c, 0), "ds1338", 0x68);
 
     smbus_eeprom_init_one(OBJECT(bmc), aspeed_i2c_get_bus(&soc->i2c, 0), 0x50,
                           eeprom_buf);
 
     /* add a TMP423 temperature sensor */
-    dev = DEVICE(i2c_slave_create_simple_orphan(aspeed_i2c_get_bus(&soc->i2c, 2),
+    dev = DEVICE(i2c_slave_create_simple(OBJECT(bmc), "tmp423",
+                                         aspeed_i2c_get_bus(&soc->i2c, 2),
                                          "tmp423", 0x4c));
     object_property_set_int(OBJECT(dev), "temperature0", 31000, &error_abort);
     object_property_set_int(OBJECT(dev), "temperature1", 28000, &error_abort);
hw/arm/aspeed_ast2500_tiogapass.c +6 -3
index a6b3c0d051..13d1db9cfa 100644
@@ -55,9 +55,12 @@ static void tiogapass_bmc_i2c_init(AspeedMachineState *bmc)
     at24c_eeprom_init_rom(aspeed_i2c_get_bus(&soc->i2c, 6), 0x54, 128 * KiB,
                           tiogapass_bmc_fruid, tiogapass_bmc_fruid_len);
     /* TMP421 */
-    i2c_slave_create_simple_orphan(aspeed_i2c_get_bus(&soc->i2c, 8), "tmp421", 0x1f);
-    i2c_slave_create_simple_orphan(aspeed_i2c_get_bus(&soc->i2c, 6), "tmp421", 0x4f);
-    i2c_slave_create_simple_orphan(aspeed_i2c_get_bus(&soc->i2c, 6), "tmp421", 0x4e);
+    i2c_slave_create_simple(OBJECT(bmc), "tmp421[*]",
+                            aspeed_i2c_get_bus(&soc->i2c, 8), "tmp421", 0x1f);
+    i2c_slave_create_simple(OBJECT(bmc), "tmp421[*]",
+                            aspeed_i2c_get_bus(&soc->i2c, 6), "tmp421", 0x4f);
+    i2c_slave_create_simple(OBJECT(bmc), "tmp421[*]",
+                            aspeed_i2c_get_bus(&soc->i2c, 6), "tmp421", 0x4e);
 }
 
 static void aspeed_machine_tiogapass_class_init(ObjectClass *oc,
hw/arm/aspeed_ast2500_witherspoon.c +17 -15
index dda090ab60..2ba7ebb461 100644
@@ -44,11 +44,9 @@ static void witherspoon_bmc_i2c_init(AspeedMachineState *bmc)
     LEDState *led;
 
     /* Bus 3: TODO bmp280@77 */
-    dev = DEVICE(i2c_slave_new_orphan(TYPE_PCA9552, 0x60));
+    dev = DEVICE(i2c_slave_new(OBJECT(bmc), "pca9552[*]", TYPE_PCA9552, 0x60));
     qdev_prop_set_string(dev, "description", "pca1");
-    i2c_slave_realize_and_unref(I2C_SLAVE(dev),
-                                aspeed_i2c_get_bus(&soc->i2c, 3),
-                                &error_fatal);
+    qdev_realize(dev, BUS(aspeed_i2c_get_bus(&soc->i2c, 3)), &error_fatal);
 
     for (size_t i = 0; i < ARRAY_SIZE(pca1_leds); i++) {
         led = led_create_simple(OBJECT(bmc),
@@ -58,28 +56,32 @@ static void witherspoon_bmc_i2c_init(AspeedMachineState *bmc)
         qdev_connect_gpio_out(dev, pca1_leds[i].gpio_id,
                               qdev_get_gpio_in(DEVICE(led), 0));
     }
-    i2c_slave_create_simple_orphan(aspeed_i2c_get_bus(&soc->i2c, 3), "dps310", 0x76);
-    i2c_slave_create_simple_orphan(aspeed_i2c_get_bus(&soc->i2c, 3), "max31785", 0x52);
-    i2c_slave_create_simple_orphan(aspeed_i2c_get_bus(&soc->i2c, 4), "tmp423", 0x4c);
-    i2c_slave_create_simple_orphan(aspeed_i2c_get_bus(&soc->i2c, 5), "tmp423", 0x4c);
+    i2c_slave_create_simple(OBJECT(bmc), "dps310",
+                            aspeed_i2c_get_bus(&soc->i2c, 3), "dps310", 0x76);
+    i2c_slave_create_simple(OBJECT(bmc), "max31785",
+                            aspeed_i2c_get_bus(&soc->i2c, 3), "max31785", 0x52);
+    i2c_slave_create_simple(OBJECT(bmc), "tmp423[*]",
+                            aspeed_i2c_get_bus(&soc->i2c, 4), "tmp423", 0x4c);
+    i2c_slave_create_simple(OBJECT(bmc), "tmp423[*]",
+                            aspeed_i2c_get_bus(&soc->i2c, 5), "tmp423", 0x4c);
 
     /* The Witherspoon expects a TMP275 but a TMP105 is compatible */
-    i2c_slave_create_simple_orphan(aspeed_i2c_get_bus(&soc->i2c, 9), TYPE_TMP105,
-                     0x4a);
+    i2c_slave_create_simple(OBJECT(bmc), "tmp105",
+                            aspeed_i2c_get_bus(&soc->i2c, 9), TYPE_TMP105,
+                            0x4a);
 
     /*
      * The witherspoon board expects Epson RX8900 I2C RTC but a ds1338 is
      * good enough
      */
-    i2c_slave_create_simple_orphan(aspeed_i2c_get_bus(&soc->i2c, 11), "ds1338", 0x32);
+    i2c_slave_create_simple(OBJECT(bmc), "rtc",
+                            aspeed_i2c_get_bus(&soc->i2c, 11), "ds1338", 0x32);
 
     smbus_eeprom_init_one(OBJECT(bmc), aspeed_i2c_get_bus(&soc->i2c, 11), 0x51,
                           eeprom_buf);
-    dev = DEVICE(i2c_slave_new_orphan(TYPE_PCA9552, 0x60));
+    dev = DEVICE(i2c_slave_new(OBJECT(bmc), "pca9552[*]", TYPE_PCA9552, 0x60));
     qdev_prop_set_string(dev, "description", "pca0");
-    i2c_slave_realize_and_unref(I2C_SLAVE(dev),
-                                aspeed_i2c_get_bus(&soc->i2c, 11),
-                                &error_fatal);
+    qdev_realize(dev, BUS(aspeed_i2c_get_bus(&soc->i2c, 11)), &error_fatal);
     /* Bus 11: TODO ucd90160@64 */
 }
 
hw/arm/aspeed_ast2500_yosemitev2.c +6 -3
index 905758c345..4e3c19bc07 100644
@@ -55,9 +55,12 @@ static void yosemitev2_bmc_i2c_init(AspeedMachineState *bmc)
     at24c_eeprom_init_rom(aspeed_i2c_get_bus(&soc->i2c, 8), 0x51, 128 * KiB,
                           yosemitev2_bmc_fruid, yosemitev2_bmc_fruid_len);
     /* TMP421 */
-    i2c_slave_create_simple_orphan(aspeed_i2c_get_bus(&soc->i2c, 11), "tmp421", 0x1f);
-    i2c_slave_create_simple_orphan(aspeed_i2c_get_bus(&soc->i2c, 9), "tmp421", 0x4e);
-    i2c_slave_create_simple_orphan(aspeed_i2c_get_bus(&soc->i2c, 9), "tmp421", 0x4f);
+    i2c_slave_create_simple(OBJECT(bmc), "tmp421[*]",
+                            aspeed_i2c_get_bus(&soc->i2c, 11), "tmp421", 0x1f);
+    i2c_slave_create_simple(OBJECT(bmc), "tmp421[*]",
+                            aspeed_i2c_get_bus(&soc->i2c, 9), "tmp421", 0x4e);
+    i2c_slave_create_simple(OBJECT(bmc), "tmp421[*]",
+                            aspeed_i2c_get_bus(&soc->i2c, 9), "tmp421", 0x4f);
 
 }
 
hw/arm/aspeed_ast2600_bletchley.c +19 -10
index 4930bddb39..58f0bc89bd 100644
@@ -35,35 +35,44 @@ static void bletchley_bmc_i2c_init(AspeedMachineState *bmc)
     for (int i = 0; i < 6; i++) {
         /* Missing model: ti,ina230 @ 0x45 */
         /* Missing model: mps,mp5023 @ 0x40 */
-        i2c_slave_create_simple_orphan(i2c[i], TYPE_TMP421, 0x4f);
+        i2c_slave_create_simple(OBJECT(bmc), "tmp421[*]",
+                                i2c[i], TYPE_TMP421, 0x4f);
         /* Missing model: nxp,pca9539 @ 0x76, but PCA9552 works enough */
-        i2c_slave_create_simple_orphan(i2c[i], TYPE_PCA9552, 0x76);
-        i2c_slave_create_simple_orphan(i2c[i], TYPE_PCA9552, 0x67);
+        i2c_slave_create_simple(OBJECT(bmc), "pca9552[*]",
+                                i2c[i], TYPE_PCA9552, 0x76);
+        i2c_slave_create_simple(OBJECT(bmc), "pca9552[*]",
+                                i2c[i], TYPE_PCA9552, 0x67);
         /* Missing model: fsc,fusb302 @ 0x22 */
     }
 
     /* Bus 6 */
     at24c_eeprom_init(i2c[6], 0x56, 65536);
     /* Missing model: nxp,pcf85263 @ 0x51 , but ds1338 works enough */
-    i2c_slave_create_simple_orphan(i2c[6], "ds1338", 0x51);
+    i2c_slave_create_simple(OBJECT(bmc), "rtc", i2c[6], "ds1338", 0x51);
 
 
     /* Bus 7 */
     at24c_eeprom_init(i2c[7], 0x54, 65536);
 
     /* Bus 9 */
-    i2c_slave_create_simple_orphan(i2c[9], TYPE_TMP421, 0x4f);
+    i2c_slave_create_simple(OBJECT(bmc), "tmp421[*]",
+                            i2c[9], TYPE_TMP421, 0x4f);
 
     /* Bus 10 */
-    i2c_slave_create_simple_orphan(i2c[10], TYPE_TMP421, 0x4f);
+    i2c_slave_create_simple(OBJECT(bmc), "tmp421[*]",
+                            i2c[10], TYPE_TMP421, 0x4f);
     /* Missing model: ti,hdc1080 @ 0x40 */
-    i2c_slave_create_simple_orphan(i2c[10], TYPE_PCA9552, 0x67);
+    i2c_slave_create_simple(OBJECT(bmc), "pca9552[*]",
+                            i2c[10], TYPE_PCA9552, 0x67);
 
     /* Bus 12 */
     /* Missing model: adi,adm1278 @ 0x11 */
-    i2c_slave_create_simple_orphan(i2c[12], TYPE_TMP421, 0x4c);
-    i2c_slave_create_simple_orphan(i2c[12], TYPE_TMP421, 0x4d);
-    i2c_slave_create_simple_orphan(i2c[12], TYPE_PCA9552, 0x67);
+    i2c_slave_create_simple(OBJECT(bmc), "tmp421[*]",
+                            i2c[12], TYPE_TMP421, 0x4c);
+    i2c_slave_create_simple(OBJECT(bmc), "tmp421[*]",
+                            i2c[12], TYPE_TMP421, 0x4d);
+    i2c_slave_create_simple(OBJECT(bmc), "pca9552[*]",
+                            i2c[12], TYPE_PCA9552, 0x67);
 }
 
 static void aspeed_machine_bletchley_class_init(ObjectClass *oc,
hw/arm/aspeed_ast2600_evb.c +3 -2
index ab7667da75..8e389dbe80 100644
@@ -27,8 +27,9 @@ static void ast2600_evb_i2c_init(AspeedMachineState *bmc)
                           eeprom_buf);
 
     /* LM75 is compatible with TMP105 driver */
-    i2c_slave_create_simple_orphan(aspeed_i2c_get_bus(&soc->i2c, 8),
-                     TYPE_TMP105, 0x4d);
+    i2c_slave_create_simple(OBJECT(bmc), "tmp105",
+                            aspeed_i2c_get_bus(&soc->i2c, 8),
+                            TYPE_TMP105, 0x4d);
 }
 
 static void aspeed_machine_ast2600_evb_class_init(ObjectClass *oc,
hw/arm/aspeed_ast2600_fby35.c +5 -5
index fcd1acdc17..dedc273ee3 100644
@@ -102,12 +102,12 @@ static void fby35_i2c_init(AspeedMachineState *bmc)
         i2c[i] = aspeed_i2c_get_bus(&soc->i2c, i);
     }
 
-    i2c_slave_create_simple_orphan(i2c[2], TYPE_LM75, 0x4f);
-    i2c_slave_create_simple_orphan(i2c[8], TYPE_TMP421, 0x1f);
+    i2c_slave_create_simple(OBJECT(bmc), "lm75[*]", i2c[2], TYPE_LM75, 0x4f);
+    i2c_slave_create_simple(OBJECT(bmc), "tmp421", i2c[8], TYPE_TMP421, 0x1f);
     /* Hotswap controller is actually supposed to be mp5920 or ltc4282. */
-    i2c_slave_create_simple_orphan(i2c[11], "adm1272", 0x44);
-    i2c_slave_create_simple_orphan(i2c[12], TYPE_LM75, 0x4e);
-    i2c_slave_create_simple_orphan(i2c[12], TYPE_LM75, 0x4f);
+    i2c_slave_create_simple(OBJECT(bmc), "adm1272", i2c[11], "adm1272", 0x44);
+    i2c_slave_create_simple(OBJECT(bmc), "lm75[*]", i2c[12], TYPE_LM75, 0x4e);
+    i2c_slave_create_simple(OBJECT(bmc), "lm75[*]", i2c[12], TYPE_LM75, 0x4f);
 
     at24c_eeprom_init(i2c[4], 0x51, 128 * KiB);
     at24c_eeprom_init(i2c[6], 0x51, 128 * KiB);
hw/arm/aspeed_ast2600_gb200nvl.c +9 -9
index 2c1c513674..1cf35f96bd 100644
@@ -51,23 +51,23 @@ static void gb200nvl_bmc_i2c_init(AspeedMachineState *bmc)
     }
 
     /* Bus 5 Expander */
-    aspeed_create_pca9554(soc, 4, 0x21);
+    aspeed_create_pca9554(OBJECT(bmc), soc, 4, 0x21);
 
     /* Mux I2c Expanders */
-    i2c_slave_create_simple_orphan(i2c[5], "pca9546", 0x71);
-    i2c_slave_create_simple_orphan(i2c[5], "pca9546", 0x72);
-    i2c_slave_create_simple_orphan(i2c[5], "pca9546", 0x73);
-    i2c_slave_create_simple_orphan(i2c[5], "pca9546", 0x75);
-    i2c_slave_create_simple_orphan(i2c[5], "pca9546", 0x76);
-    i2c_slave_create_simple_orphan(i2c[5], "pca9546", 0x77);
+    i2c_slave_create_simple(OBJECT(bmc), "i2c-mux[*]", i2c[5], "pca9546", 0x71);
+    i2c_slave_create_simple(OBJECT(bmc), "i2c-mux[*]", i2c[5], "pca9546", 0x72);
+    i2c_slave_create_simple(OBJECT(bmc), "i2c-mux[*]", i2c[5], "pca9546", 0x73);
+    i2c_slave_create_simple(OBJECT(bmc), "i2c-mux[*]", i2c[5], "pca9546", 0x75);
+    i2c_slave_create_simple(OBJECT(bmc), "i2c-mux[*]", i2c[5], "pca9546", 0x76);
+    i2c_slave_create_simple(OBJECT(bmc), "i2c-mux[*]", i2c[5], "pca9546", 0x77);
 
     /* Bus 10 */
-    dev = DEVICE(aspeed_create_pca9554(soc, 9, 0x20));
+    dev = DEVICE(aspeed_create_pca9554(OBJECT(bmc), soc, 9, 0x20));
 
     /* Set FPGA_READY */
     object_property_set_str(OBJECT(dev), "pin1", "high", &error_fatal);
 
-    aspeed_create_pca9554(soc, 9, 0x21);
+    aspeed_create_pca9554(OBJECT(bmc), soc, 9, 0x21);
     at24c_eeprom_init(i2c[9], 0x50, 64 * KiB);
     at24c_eeprom_init(i2c[9], 0x51, 64 * KiB);
 
hw/arm/aspeed_ast2600_rainier.c +16 -16
index 0495c2880c..8ba15aceca 100644
@@ -70,7 +70,7 @@ static void rainier_bmc_i2c_init(AspeedMachineState *bmc)
 
     at24c_eeprom_init(aspeed_i2c_get_bus(&soc->i2c, 0), 0x51, 32 * KiB);
 
-    aspeed_create_pca9552(soc, 3, 0x61);
+    aspeed_create_pca9552(OBJECT(bmc), soc, 3, 0x61);
 
     /* The rainier expects a TMP275 but a TMP105 is compatible */
     i2c_slave_create_simple_orphan(aspeed_i2c_get_bus(&soc->i2c, 4), TYPE_TMP105,
@@ -84,14 +84,14 @@ static void rainier_bmc_i2c_init(AspeedMachineState *bmc)
     at24c_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 0), 0x50, 64 * KiB);
     at24c_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 1), 0x51, 64 * KiB);
     at24c_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 2), 0x52, 64 * KiB);
-    aspeed_create_pca9552(soc, 4, 0x60);
+    aspeed_create_pca9552(OBJECT(bmc), soc, 4, 0x60);
 
     i2c_slave_create_simple_orphan(aspeed_i2c_get_bus(&soc->i2c, 5), TYPE_TMP105,
                      0x48);
     i2c_slave_create_simple_orphan(aspeed_i2c_get_bus(&soc->i2c, 5), TYPE_TMP105,
                      0x49);
-    aspeed_create_pca9552(soc, 5, 0x60);
-    aspeed_create_pca9552(soc, 5, 0x61);
+    aspeed_create_pca9552(OBJECT(bmc), soc, 5, 0x60);
+    aspeed_create_pca9552(OBJECT(bmc), soc, 5, 0x61);
     i2c_mux = i2c_slave_create_simple_orphan(aspeed_i2c_get_bus(&soc->i2c, 5),
                                       "pca9546", 0x70);
     at24c_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 0), 0x50, 64 * KiB);
@@ -110,12 +110,12 @@ static void rainier_bmc_i2c_init(AspeedMachineState *bmc)
     at24c_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 2), 0x50, 64 * KiB);
     at24c_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 3), 0x51, 64 * KiB);
 
-    aspeed_create_pca9552(soc, 7, 0x30);
-    aspeed_create_pca9552(soc, 7, 0x31);
-    aspeed_create_pca9552(soc, 7, 0x32);
-    aspeed_create_pca9552(soc, 7, 0x33);
-    aspeed_create_pca9552(soc, 7, 0x60);
-    aspeed_create_pca9552(soc, 7, 0x61);
+    aspeed_create_pca9552(OBJECT(bmc), soc, 7, 0x30);
+    aspeed_create_pca9552(OBJECT(bmc), soc, 7, 0x31);
+    aspeed_create_pca9552(OBJECT(bmc), soc, 7, 0x32);
+    aspeed_create_pca9552(OBJECT(bmc), soc, 7, 0x33);
+    aspeed_create_pca9552(OBJECT(bmc), soc, 7, 0x60);
+    aspeed_create_pca9552(OBJECT(bmc), soc, 7, 0x61);
     i2c_slave_create_simple_orphan(aspeed_i2c_get_bus(&soc->i2c, 7), "dps310", 0x76);
     /* Bus 7: TODO si7021-a20@20 */
     i2c_slave_create_simple_orphan(aspeed_i2c_get_bus(&soc->i2c, 7), TYPE_TMP105,
@@ -132,8 +132,8 @@ static void rainier_bmc_i2c_init(AspeedMachineState *bmc)
                           64 * KiB, rainier_bb_fruid, rainier_bb_fruid_len);
     at24c_eeprom_init_rom(aspeed_i2c_get_bus(&soc->i2c, 8), 0x51,
                           64 * KiB, rainier_bmc_fruid, rainier_bmc_fruid_len);
-    aspeed_create_pca9552(soc, 8, 0x60);
-    aspeed_create_pca9552(soc, 8, 0x61);
+    aspeed_create_pca9552(OBJECT(bmc), soc, 8, 0x60);
+    aspeed_create_pca9552(OBJECT(bmc), soc, 8, 0x61);
     /* Bus 8: ucd90320@11 */
     /* Bus 8: ucd90320@b */
     /* Bus 8: ucd90320@c */
@@ -154,17 +154,17 @@ static void rainier_bmc_i2c_init(AspeedMachineState *bmc)
                                       "pca9546", 0x70);
     at24c_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 0), 0x50, 64 * KiB);
     at24c_eeprom_init(pca954x_i2c_get_bus(i2c_mux, 1), 0x51, 64 * KiB);
-    aspeed_create_pca9552(soc, 11, 0x60);
+    aspeed_create_pca9552(OBJECT(bmc), soc, 11, 0x60);
 
 
     at24c_eeprom_init(aspeed_i2c_get_bus(&soc->i2c, 13), 0x50, 64 * KiB);
-    aspeed_create_pca9552(soc, 13, 0x60);
+    aspeed_create_pca9552(OBJECT(bmc), soc, 13, 0x60);
 
     at24c_eeprom_init(aspeed_i2c_get_bus(&soc->i2c, 14), 0x50, 64 * KiB);
-    aspeed_create_pca9552(soc, 14, 0x60);
+    aspeed_create_pca9552(OBJECT(bmc), soc, 14, 0x60);
 
     at24c_eeprom_init(aspeed_i2c_get_bus(&soc->i2c, 15), 0x50, 64 * KiB);
-    aspeed_create_pca9552(soc, 15, 0x60);
+    aspeed_create_pca9552(OBJECT(bmc), soc, 15, 0x60);
 }
 
 static void aspeed_machine_rainier_class_init(ObjectClass *oc, const void *data)
hw/arm/aspeed_ast27x0-fc.c +6 -3
index f21c842315..74626973bc 100644
@@ -109,10 +109,13 @@ static bool ast2700fc_ca35_init(MachineState *machine, Error **errp)
     /*
      * AST2700 EVB has a LM75 temperature sensor on I2C bus 0 at address 0x4d.
      */
-    i2c_slave_create_simple_orphan(aspeed_i2c_get_bus(&soc->i2c, 0), "tmp105", 0x4d);
+    i2c_slave_create_simple(OBJECT(machine), "tmp105",
+                            aspeed_i2c_get_bus(&soc->i2c, 0), "tmp105", 0x4d);
 
-    aspeed_board_init_flashes(&soc->fmc, AST2700FC_FMC_MODEL, 2, 0);
-    aspeed_board_init_flashes(&soc->spi[0], AST2700FC_SPI_MODEL, 1, 2);
+    aspeed_board_init_flashes(OBJECT(machine), &soc->fmc,
+                              AST2700FC_FMC_MODEL, 2, 0);
+    aspeed_board_init_flashes(OBJECT(machine), &soc->spi[0],
+                              AST2700FC_SPI_MODEL, 1, 2);
 
     ast2700fc_board_info.ram_size = machine->ram_size;
     ast2700fc_board_info.loader_start = sc->memmap[ASPEED_DEV_SDRAM];
hw/arm/aspeed_ast27x0_evb.c +2 -1
index a59714372d..1892a59cce 100644
@@ -24,7 +24,8 @@ static void ast2700_evb_i2c_init(AspeedMachineState *bmc)
     AspeedSoCState *soc = bmc->soc;
 
     /* LM75 is compatible with TMP105 driver */
-    i2c_slave_create_simple_orphan(aspeed_i2c_get_bus(&soc->i2c, 0),
+    i2c_slave_create_simple(OBJECT(bmc), "tmp105",
+                            aspeed_i2c_get_bus(&soc->i2c, 0),
                             TYPE_TMP105, 0x4d);
 }
 
hw/arm/aspeed_soc_common.c +7 -5
index 33f7f10531..780a9659cc 100644
@@ -81,11 +81,12 @@ bool aspeed_soc_dram_init(AspeedSoCState *s, Error **errp)
      * SoC has.
      */
     if (ram_size < max_ram_size) {
-        DeviceState *dev = qdev_new_orphan(TYPE_UNIMPLEMENTED_DEVICE);
+        DeviceState *dev = qdev_new(OBJECT(s), "ram-empty",
+                                    TYPE_UNIMPLEMENTED_DEVICE);
 
         qdev_prop_set_string(dev, "name", "ram-empty");
         qdev_prop_set_uint64(dev, "size", max_ram_size  - ram_size);
-        if (!sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), errp)) {
+        if (!sysbus_realize(SYS_BUS_DEVICE(dev), errp)) {
             return false;
         }
 
@@ -115,7 +116,8 @@ void aspeed_mmio_map_unimplemented(MemoryRegion *memory, SysBusDevice *dev,
                                         sysbus_mmio_get_region(dev, 0), -1000);
 }
 
-void aspeed_board_init_flashes(AspeedSMCState *s, const char *flashtype,
+void aspeed_board_init_flashes(Object *parent, AspeedSMCState *s,
+                               const char *flashtype,
                                unsigned int count, int unit0)
 {
     int i;
@@ -128,12 +130,12 @@ void aspeed_board_init_flashes(AspeedSMCState *s, const char *flashtype,
         DriveInfo *dinfo = drive_get(IF_MTD, 0, unit0 + i);
         DeviceState *dev;
 
-        dev = qdev_new_orphan(flashtype);
+        dev = qdev_new(parent, "flash[*]", flashtype);
         if (dinfo) {
             qdev_prop_set_drive(dev, "drive", blk_by_legacy_dinfo(dinfo));
         }
         qdev_prop_set_uint8(dev, "cs", i);
-        qdev_realize_and_unref(dev, BUS(s->spi), &error_fatal);
+        qdev_realize(dev, BUS(s->spi), &error_fatal);
     }
 }
 
include/hw/arm/aspeed.h +6 -4
index e1c0323cb6..743f7282ae 100644
@@ -83,9 +83,10 @@ void aspeed_machine_class_init_cpus_defaults(MachineClass *mc);
  *
  * Create and attach a PCA9552 LED controller device to the specified I2C bus
  * of the given Aspeed SoC. The device is instantiated using
- * i2c_slave_create_simple_orphan() with the PCA9552 device type.
+ * i2c_slave_create_simple() with the PCA9552 device type.
  */
-void aspeed_create_pca9552(AspeedSoCState *soc, int bus_id, int addr);
+void aspeed_create_pca9552(Object *parent, AspeedSoCState *soc, int bus_id,
+                           int addr);
 
 /*
  * aspeed_create_pca9554:
@@ -95,11 +96,12 @@ void aspeed_create_pca9552(AspeedSoCState *soc, int bus_id, int addr);
  *
  * Create and attach a PCA9554 I/O expander to the specified I2C bus
  * of the given Aspeed SoC. The device is created via
- * i2c_slave_create_simple_orphan() and returned as an #I2CSlave pointer.
+ * i2c_slave_create_simple() and returned as an #I2CSlave pointer.
  *
  * Returns: a pointer to the newly created #I2CSlave instance.
  */
-I2CSlave *aspeed_create_pca9554(AspeedSoCState *soc, int bus_id, int addr);
+I2CSlave *aspeed_create_pca9554(Object *parent, AspeedSoCState *soc,
+                                int bus_id, int addr);
 
 /*
  * aspeed_machine_ast2600_class_emmc_init:
include/hw/arm/aspeed_soc.h +2 -1
index 41dc04e293..d1ad82e00a 100644
@@ -311,7 +311,8 @@ void aspeed_mmio_map(MemoryRegion *memory, SysBusDevice *dev, int n,
 void aspeed_mmio_map_unimplemented(MemoryRegion *memory, SysBusDevice *dev,
                                    const char *name, hwaddr addr,
                                    uint64_t size);
-void aspeed_board_init_flashes(AspeedSMCState *s, const char *flashtype,
+void aspeed_board_init_flashes(Object *parent, AspeedSMCState *s,
+                               const char *flashtype,
                                unsigned int count, int unit0);
 void aspeed_write_boot_rom(BlockBackend *blk, hwaddr addr, size_t rom_size,
                            Error **errp);
Signature · 1 line
2.47.1
#230 lore raw

RFC PATCH v2 73/137 hw/arm/aspeed: Give onboard devices a QOM parent (part 2)

In reply to Alexander Graf

Convert the *_orphan() device-creation calls in the four large hw/arm/aspeed_ast2600_{anacapa,catalina,fuji,rainier}.c board files to the new parented API introduced earlier in this series, so every onboard I2C peripheral 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 machine (AspeedMachineState); the board's .i2c_init() callback receives it directly. Names are derived from the device type and auto-indexed.

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

hw/arm/aspeed_ast2600_anacapa.c:240 | i2c_slave_create_simple | OBJECT(bmc) | "i2c-mux[*]" | anacapa_bmc_i2c_init(AspeedMachineState *bmc) is amc->i2c_init callback invoked from board init; bmc IS the MachineState. Multiple PCA954x muxes -> auto-index. Local Object *o = OBJECT(bmc) added.
hw/arm/aspeed_ast2600_anacapa.c:246 | i2c_slave_create_simple | OBJECT(bmc) | "i2c-mux[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_anacapa.c:250 | i2c_slave_create_simple | OBJECT(bmc) | "i2c-mux[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_anacapa.c:259 | i2c_slave_create_simple | OBJECT(bmc) | "i2c-mux[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_anacapa.c:264 | i2c_slave_create_simple | OBJECT(bmc) | "gpio[*]" | Board i2c_init; PCA9552 GPIO expander behind mux, many instances -> auto-index.
hw/arm/aspeed_ast2600_anacapa.c:267 | i2c_slave_create_simple | OBJECT(bmc) | "gpio[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_anacapa.c:275 | i2c_slave_create_simple | OBJECT(bmc) | "gpio[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_anacapa.c:278 | i2c_slave_create_simple | OBJECT(bmc) | "gpio[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_anacapa.c:294 | i2c_slave_create_simple | OBJECT(bmc) | "i2c-mux[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_anacapa.c:298 | i2c_slave_create_simple | OBJECT(bmc) | "gpio[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_anacapa.c:306 | i2c_slave_create_simple | OBJECT(bmc) | "i2c-mux[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_anacapa.c:312 | i2c_slave_create_simple | OBJECT(bmc) | "gpio[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_anacapa.c:320 | i2c_slave_create_simple | OBJECT(bmc) | "i2c-mux[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_catalina.c:475 | i2c_slave_create_simple | OBJECT(bmc) | "i2c-mux[*]" | catalina_bmc_i2c_init(AspeedMachineState *bmc) board i2c_init callback. Local Object *o = OBJECT(bmc) added. Many PCA954x -> auto-index.
hw/arm/aspeed_ast2600_catalina.c:478 | i2c_slave_create_simple | OBJECT(bmc) | "i2c-mux[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_catalina.c:482 | i2c_slave_create_simple | OBJECT(bmc) | "gpio[*]" | Board i2c_init; PCA9535 GPIO expander -> auto-index.
hw/arm/aspeed_ast2600_catalina.c:489 | i2c_slave_create_simple | OBJECT(bmc) | "i2c-mux[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_catalina.c:492 | i2c_slave_create_simple | OBJECT(bmc) | "i2c-mux[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_catalina.c:495 | i2c_slave_create_simple | OBJECT(bmc) | "i2c-mux[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_catalina.c:499 | i2c_slave_create_simple | OBJECT(bmc) | "gpio[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_catalina.c:506 | i2c_slave_create_simple | OBJECT(bmc) | "i2c-mux[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_catalina.c:511 | i2c_slave_create_simple | OBJECT(bmc) | "i2c-mux[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_catalina.c:528 | i2c_slave_create_simple | OBJECT(bmc) | "tmp75[*]" | Board i2c_init; multiple TMP75 -> auto-index.
hw/arm/aspeed_ast2600_catalina.c:532 | i2c_slave_create_simple | OBJECT(bmc) | "gpio[*]" | Board i2c_init; PCA9554 GPIO expander -> auto-index with other GPIO expanders.
hw/arm/aspeed_ast2600_catalina.c:535 | i2c_slave_create_simple | OBJECT(bmc) | "gpio[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_catalina.c:546 | i2c_slave_create_simple | OBJECT(bmc) | "tmp75[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_catalina.c:550 | i2c_slave_create_simple | OBJECT(bmc) | "gpio[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_catalina.c:552 | i2c_slave_create_simple | OBJECT(bmc) | "gpio[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_catalina.c:554 | i2c_slave_create_simple | OBJECT(bmc) | "gpio[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_catalina.c:562 | i2c_slave_create_simple | OBJECT(bmc) | "i2c-mux[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_catalina.c:575 | i2c_slave_create_simple | OBJECT(bmc) | "gpio[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_catalina.c:577 | i2c_slave_create_simple | OBJECT(bmc) | "rtc" | Board i2c_init; single DS1338 RTC.
hw/arm/aspeed_ast2600_catalina.c:581 | i2c_slave_create_simple | OBJECT(bmc) | "gpio[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_catalina.c:583 | i2c_slave_create_simple | OBJECT(bmc) | "tmp75[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_catalina.c:591 | i2c_slave_create_simple | OBJECT(bmc) | "tmp421[*]" | Board i2c_init; two TMP421 -> auto-index.
hw/arm/aspeed_ast2600_catalina.c:618 | i2c_slave_create_simple | OBJECT(bmc) | "gpio[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_catalina.c:620 | i2c_slave_create_simple | OBJECT(bmc) | "gpio[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_catalina.c:622 | i2c_slave_create_simple | OBJECT(bmc) | "gpio[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_catalina.c:624 | i2c_slave_create_simple | OBJECT(bmc) | "gpio[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_catalina.c:626 | i2c_slave_create_simple | OBJECT(bmc) | "gpio[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_catalina.c:628 | i2c_slave_create_simple | OBJECT(bmc) | "gpio[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_catalina.c:632 | i2c_slave_create_simple | OBJECT(bmc) | "tmp421[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_fuji.c:30 | i2c_slave_create_simple | parent | "i2c-mux[*]" | get_pca9548_channels() static helper called only from fuji_bmc_i2c_init(); no parent-capable pointer -> add Object *parent as first arg and thread OBJECT(bmc) from all 8 direct + 1 loop callers. 15 muxes total -> auto-index.
hw/arm/aspeed_ast2600_fuji.c:60 | i2c_slave_create_simple | OBJECT(bmc) | "lm75[*]" | fuji_bmc_i2c_init(AspeedMachineState *bmc) board i2c_init. Local Object *o = OBJECT(bmc) added. LM75/TMP75 both alias TYPE_TMP105 but keep source-macro-derived names for readability; auto-index.
hw/arm/aspeed_ast2600_fuji.c:61 | i2c_slave_create_simple | OBJECT(bmc) | "lm75[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_fuji.c:71 | i2c_slave_create_simple | OBJECT(bmc) | "lm75[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_fuji.c:72 | i2c_slave_create_simple | OBJECT(bmc) | "lm75[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_fuji.c:73 | i2c_slave_create_simple | OBJECT(bmc) | "lm75[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_fuji.c:74 | i2c_slave_create_simple | OBJECT(bmc) | "tmp422" | Board i2c_init; single TMP422.
hw/arm/aspeed_ast2600_fuji.c:77 | i2c_slave_create_simple | OBJECT(bmc) | "lm75[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_fuji.c:79 | i2c_slave_create_simple | OBJECT(bmc) | "lm75[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_fuji.c:81 | i2c_slave_create_simple | OBJECT(bmc) | "tmp75[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_fuji.c:82 | i2c_slave_create_simple | OBJECT(bmc) | "tmp75[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_fuji.c:84 | i2c_slave_create_simple | OBJECT(bmc) | "tmp75[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_fuji.c:85 | i2c_slave_create_simple | OBJECT(bmc) | "tmp75[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_fuji.c:88 | i2c_slave_create_simple | OBJECT(bmc) | "tmp75[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_fuji.c:89 | i2c_slave_create_simple | OBJECT(bmc) | "tmp75[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_fuji.c:96 | i2c_slave_create_simple | OBJECT(bmc) | "tmp75[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_fuji.c:97 | i2c_slave_create_simple | OBJECT(bmc) | "tmp75[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_fuji.c:106 | i2c_slave_create_simple | OBJECT(bmc) | "tmp75[*]" | Board i2c_init; loop x8 -> auto-index.
hw/arm/aspeed_ast2600_fuji.c:107 | i2c_slave_create_simple | OBJECT(bmc) | "tmp75[*]" | Board i2c_init; loop x8 -> auto-index.
hw/arm/aspeed_ast2600_fuji.c:108 | i2c_slave_create_simple | OBJECT(bmc) | "tmp75[*]" | Board i2c_init; loop x8 -> auto-index.
hw/arm/aspeed_ast2600_rainier.c:76 | i2c_slave_create_simple | OBJECT(bmc) | "tmp105[*]" | rainier_bmc_i2c_init(AspeedMachineState *bmc) board i2c_init. Local Object *o = OBJECT(bmc) added. Many TMP105 -> auto-index.
hw/arm/aspeed_ast2600_rainier.c:78 | i2c_slave_create_simple | OBJECT(bmc) | "tmp105[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_rainier.c:80 | i2c_slave_create_simple | OBJECT(bmc) | "tmp105[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_rainier.c:82 | i2c_slave_create_simple | OBJECT(bmc) | "i2c-mux[*]" | Board i2c_init; multiple PCA9546 -> auto-index.
hw/arm/aspeed_ast2600_rainier.c:89 | i2c_slave_create_simple | OBJECT(bmc) | "tmp105[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_rainier.c:91 | i2c_slave_create_simple | OBJECT(bmc) | "tmp105[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_rainier.c:95 | i2c_slave_create_simple | OBJECT(bmc) | "i2c-mux[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_rainier.c:100 | i2c_slave_create_simple | OBJECT(bmc) | "tmp105[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_rainier.c:102 | i2c_slave_create_simple | OBJECT(bmc) | "tmp105[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_rainier.c:104 | i2c_slave_create_simple | OBJECT(bmc) | "tmp105[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_rainier.c:106 | i2c_slave_create_simple | OBJECT(bmc) | "i2c-mux[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_rainier.c:119 | i2c_slave_create_simple | OBJECT(bmc) | "dps310" | Board i2c_init; single dps310 pressure sensor.
hw/arm/aspeed_ast2600_rainier.c:121 | i2c_slave_create_simple | OBJECT(bmc) | "tmp105[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_rainier.c:123 | i2c_slave_create_simple | OBJECT(bmc) | "max31785" | Board i2c_init; single max31785 fan controller.
hw/arm/aspeed_ast2600_rainier.c:127 | i2c_slave_create_simple | OBJECT(bmc) | "tmp105[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_rainier.c:129 | i2c_slave_create_simple | OBJECT(bmc) | "tmp105[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_rainier.c:141 | i2c_slave_create_simple | OBJECT(bmc) | "tmp423[*]" | Board i2c_init; four tmp423 -> auto-index.
hw/arm/aspeed_ast2600_rainier.c:142 | i2c_slave_create_simple | OBJECT(bmc) | "tmp423[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_rainier.c:145 | i2c_slave_create_simple | OBJECT(bmc) | "tmp423[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_rainier.c:146 | i2c_slave_create_simple | OBJECT(bmc) | "tmp423[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_rainier.c:149 | i2c_slave_create_simple | OBJECT(bmc) | "tmp105[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_rainier.c:151 | i2c_slave_create_simple | OBJECT(bmc) | "tmp105[*]" | Board i2c_init; auto-index.
hw/arm/aspeed_ast2600_rainier.c:153 | i2c_slave_create_simple | OBJECT(bmc) | "i2c-mux[*]" | Board i2c_init; auto-index.

AI-used-for: code (refactoring)

---
 hw/arm/aspeed_ast2600_anacapa.c  |  31 ++++++----
 hw/arm/aspeed_ast2600_catalina.c |  65 +++++++++++---------
 hw/arm/aspeed_ast2600_fuji.c     |  65 +++++++++++---------
 hw/arm/aspeed_ast2600_rainier.c  | 102 ++++++++++++++++++++-----------
 4 files changed, 155 insertions(+), 108 deletions(-)
hw/arm/aspeed_ast2600_anacapa.c +18 -13
index 98395f196b..d6412f5b0c 100644
@@ -228,6 +228,7 @@ static void anacapa_bmc_i2c_init(AspeedMachineState *bmc)
     AspeedSoCState *soc = bmc->soc;
     I2CBus *i2c[16] = {};
     I2CSlave *i2c_mux;
+    Object *o = OBJECT(bmc);
 
     for (int i = 0; i < ARRAY_SIZE(i2c); i++) {
         i2c[i] = aspeed_i2c_get_bus(&soc->i2c, i);
@@ -237,17 +238,17 @@ static void anacapa_bmc_i2c_init(AspeedMachineState *bmc)
     /* eeprom@50 */
     at24c_eeprom_init(i2c[0], 0x50, 256 * KiB);
     /* i2c-mux@70 */
-    i2c_slave_create_simple_orphan(i2c[0], TYPE_PCA9546, 0x70);
+    i2c_slave_create_simple(o, "i2c-mux[*]", i2c[0], TYPE_PCA9546, 0x70);
 
     /* &i2c1 */
     /* eeprom@50 */
     at24c_eeprom_init(i2c[1], 0x50, 256 * KiB);
     /* i2c-mux@70 (PCA9546) — 4 channels, empty */
-    i2c_slave_create_simple_orphan(i2c[1], TYPE_PCA9546, 0x70);
+    i2c_slave_create_simple(o, "i2c-mux[*]", i2c[1], TYPE_PCA9546, 0x70);
 
     /* &i2c4 */
     /* i2c-mux@70 (PCA9548) */
-    i2c_slave_create_simple_orphan(i2c[4], TYPE_PCA9548, 0x70);
+    i2c_slave_create_simple(o, "i2c-mux[*]", i2c[4], TYPE_PCA9548, 0x70);
 
     /* &i2c6 */
     /* eeprom@50 */
@@ -256,15 +257,16 @@ static void anacapa_bmc_i2c_init(AspeedMachineState *bmc)
 
     /* &i2c8 */
     /* i2c-mux@72 (PCA9546) */
-    i2c_mux = i2c_slave_create_simple_orphan(i2c[8], TYPE_PCA9546, 0x72);
+    i2c_mux = i2c_slave_create_simple(o, "i2c-mux[*]", i2c[8],
+                                      TYPE_PCA9546, 0x72);
 
     /* i2c8mux ch0 */
     /* adc128d818@1f — no model */
     /* pca9555@22 */
-    i2c_slave_create_simple_orphan(pca954x_i2c_get_bus(i2c_mux, 0),
+    i2c_slave_create_simple(o, "gpio[*]", pca954x_i2c_get_bus(i2c_mux, 0),
                             TYPE_PCA9552, 0x22);
     /* pca9555@24 */
-    i2c_slave_create_simple_orphan(pca954x_i2c_get_bus(i2c_mux, 0),
+    i2c_slave_create_simple(o, "gpio[*]", pca954x_i2c_get_bus(i2c_mux, 0),
                             TYPE_PCA9552, 0x24);
     /* eeprom@50 */
     at24c_eeprom_init_rom(pca954x_i2c_get_bus(i2c_mux, 0), 0x50, 16 * KiB,
@@ -272,10 +274,10 @@ static void anacapa_bmc_i2c_init(AspeedMachineState *bmc)
 
     /* i2c8mux ch1 */
     /* pca9555@22 */
-    i2c_slave_create_simple_orphan(pca954x_i2c_get_bus(i2c_mux, 1),
+    i2c_slave_create_simple(o, "gpio[*]", pca954x_i2c_get_bus(i2c_mux, 1),
                             TYPE_PCA9552, 0x22);
     /* pca9555@24 */
-    i2c_slave_create_simple_orphan(pca954x_i2c_get_bus(i2c_mux, 1),
+    i2c_slave_create_simple(o, "gpio[*]", pca954x_i2c_get_bus(i2c_mux, 1),
                             TYPE_PCA9552, 0x24);
     /* eeprom@50 */
     at24c_eeprom_init_rom(pca954x_i2c_get_bus(i2c_mux, 1), 0x50, 16 * KiB,
@@ -291,11 +293,12 @@ static void anacapa_bmc_i2c_init(AspeedMachineState *bmc)
 
     /* &i2c10 */
     /* i2c-mux@71 (PCA9548) */
-    i2c_mux = i2c_slave_create_simple_orphan(i2c[10], TYPE_PCA9548, 0x71);
+    i2c_mux = i2c_slave_create_simple(o, "i2c-mux[*]", i2c[10],
+                                      TYPE_PCA9548, 0x71);
 
     /* i2c10mux ch5 */
     /* pca9555@22*/
-    i2c_slave_create_simple_orphan(pca954x_i2c_get_bus(i2c_mux, 5),
+    i2c_slave_create_simple(o, "gpio[*]", pca954x_i2c_get_bus(i2c_mux, 5),
                             TYPE_PCA9552, 0x22);
     /* eeprom@52 */
     at24c_eeprom_init_rom(pca954x_i2c_get_bus(i2c_mux, 5), 0x52, 32 * KiB,
@@ -303,13 +306,14 @@ static void anacapa_bmc_i2c_init(AspeedMachineState *bmc)
 
     /* &i2c11 */
     /* i2c-mux@71 (PCA9548) */
-    i2c_mux = i2c_slave_create_simple_orphan(i2c[11], TYPE_PCA9548, 0x71);
+    i2c_mux = i2c_slave_create_simple(o, "i2c-mux[*]", i2c[11],
+                                      TYPE_PCA9548, 0x71);
 
     /* i2c11mux ch0-ch4 — empty */
 
     /* i2c11mux ch5 */
     /* pca9555@22 */
-    i2c_slave_create_simple_orphan(pca954x_i2c_get_bus(i2c_mux, 5),
+    i2c_slave_create_simple(o, "gpio[*]", pca954x_i2c_get_bus(i2c_mux, 5),
                             TYPE_PCA9552, 0x22);
     /* eeprom@52 */
     at24c_eeprom_init_rom(pca954x_i2c_get_bus(i2c_mux, 5), 0x52, 32 * KiB,
@@ -317,7 +321,8 @@ static void anacapa_bmc_i2c_init(AspeedMachineState *bmc)
 
     /* &i2c13 */
     /* i2c-mux@70 (PCA9548) */
-    i2c_mux = i2c_slave_create_simple_orphan(i2c[13], TYPE_PCA9548, 0x70);
+    i2c_mux = i2c_slave_create_simple(o, "i2c-mux[*]", i2c[13],
+                                      TYPE_PCA9548, 0x70);
 
     /* i2c13mux ch3 */
     /* adc128d818@1f - no model */
hw/arm/aspeed_ast2600_catalina.c +36 -29

164 lines not on this page · raw message

hw/arm/aspeed_ast2600_fuji.c +35 -30

113 lines not on this page · raw message

hw/arm/aspeed_ast2600_rainier.c +66 -36

146 lines not on this page · raw message

Signature · 1 line
2.47.1
#231 lore raw

RFC PATCH v2 74/137 hw/nvram/at24c: Give at24c_eeprom_init() a QOM parent

In reply to Alexander Graf

Now that all callers of at24c_eeprom_init() and at24c_eeprom_init_rom() live in already-converted hw/arm aspeed and npcm board files, thread an Object *parent through these two convenience helpers so that every I2C EEPROM created by an aspeed or npcm board becomes a proper child of its machine instead of landing under /machine/unattached.

AI-used-for: code (refactoring)

---
 hw/arm/aspeed_ast2500_tiogapass.c  |  4 +--
 hw/arm/aspeed_ast2500_yosemitev2.c |  4 +--
 hw/arm/aspeed_ast2600_anacapa.c    | 20 +++++++-------
 hw/arm/aspeed_ast2600_bletchley.c  |  4 +--
 hw/arm/aspeed_ast2600_catalina.c   | 34 ++++++++++++------------
 hw/arm/aspeed_ast2600_fby35.c      | 10 +++----
 hw/arm/aspeed_ast2600_fuji.c       | 34 ++++++++++++------------
 hw/arm/aspeed_ast2600_gb200nvl.c   |  6 ++---
 hw/arm/aspeed_ast2600_rainier.c    | 42 +++++++++++++++---------------
 hw/arm/npcm7xx_boards.c            |  8 +++---
 hw/nvram/eeprom_at24c.c            | 12 +++++----
 include/hw/nvram/eeprom_at24c.h    |  6 +++--
 12 files changed, 94 insertions(+), 90 deletions(-)
hw/arm/aspeed_ast2500_tiogapass.c +2 -2
index 13d1db9cfa..c813fc7301 100644
@@ -51,8 +51,8 @@ static void tiogapass_bmc_i2c_init(AspeedMachineState *bmc)
 {
     AspeedSoCState *soc = bmc->soc;
 
-    at24c_eeprom_init(aspeed_i2c_get_bus(&soc->i2c, 4), 0x54, 128 * KiB);
-    at24c_eeprom_init_rom(aspeed_i2c_get_bus(&soc->i2c, 6), 0x54, 128 * KiB,
+    at24c_eeprom_init(OBJECT(bmc), aspeed_i2c_get_bus(&soc->i2c, 4), 0x54, 128 * KiB);
+    at24c_eeprom_init_rom(OBJECT(bmc), aspeed_i2c_get_bus(&soc->i2c, 6), 0x54, 128 * KiB,
                           tiogapass_bmc_fruid, tiogapass_bmc_fruid_len);
     /* TMP421 */
     i2c_slave_create_simple(OBJECT(bmc), "tmp421[*]",
hw/arm/aspeed_ast2500_yosemitev2.c +2 -2
index 4e3c19bc07..57c9976051 100644
@@ -51,8 +51,8 @@ static void yosemitev2_bmc_i2c_init(AspeedMachineState *bmc)
 {
     AspeedSoCState *soc = bmc->soc;
 
-    at24c_eeprom_init(aspeed_i2c_get_bus(&soc->i2c, 4), 0x51, 128 * KiB);
-    at24c_eeprom_init_rom(aspeed_i2c_get_bus(&soc->i2c, 8), 0x51, 128 * KiB,
+    at24c_eeprom_init(OBJECT(bmc), aspeed_i2c_get_bus(&soc->i2c, 4), 0x51, 128 * KiB);
+    at24c_eeprom_init_rom(OBJECT(bmc), aspeed_i2c_get_bus(&soc->i2c, 8), 0x51, 128 * KiB,
                           yosemitev2_bmc_fruid, yosemitev2_bmc_fruid_len);
     /* TMP421 */
     i2c_slave_create_simple(OBJECT(bmc), "tmp421[*]",
hw/arm/aspeed_ast2600_anacapa.c +10 -10
index d6412f5b0c..faf3fc070d 100644
@@ -236,13 +236,13 @@ static void anacapa_bmc_i2c_init(AspeedMachineState *bmc)
 
     /* &i2c0 */
     /* eeprom@50 */
-    at24c_eeprom_init(i2c[0], 0x50, 256 * KiB);
+    at24c_eeprom_init(o, i2c[0], 0x50, 256 * KiB);
     /* i2c-mux@70 */
     i2c_slave_create_simple(o, "i2c-mux[*]", i2c[0], TYPE_PCA9546, 0x70);
 
     /* &i2c1 */
     /* eeprom@50 */
-    at24c_eeprom_init(i2c[1], 0x50, 256 * KiB);
+    at24c_eeprom_init(o, i2c[1], 0x50, 256 * KiB);
     /* i2c-mux@70 (PCA9546) — 4 channels, empty */
     i2c_slave_create_simple(o, "i2c-mux[*]", i2c[1], TYPE_PCA9546, 0x70);
 
@@ -252,7 +252,7 @@ static void anacapa_bmc_i2c_init(AspeedMachineState *bmc)
 
     /* &i2c6 */
     /* eeprom@50 */
-    at24c_eeprom_init_rom(i2c[6], 0x50, 32 * KiB,
+    at24c_eeprom_init_rom(o, i2c[6], 0x50, 32 * KiB,
                           hpm_eeprom, hpm_eeprom_len);
 
     /* &i2c8 */
@@ -269,7 +269,7 @@ static void anacapa_bmc_i2c_init(AspeedMachineState *bmc)
     i2c_slave_create_simple(o, "gpio[*]", pca954x_i2c_get_bus(i2c_mux, 0),
                             TYPE_PCA9552, 0x24);
     /* eeprom@50 */
-    at24c_eeprom_init_rom(pca954x_i2c_get_bus(i2c_mux, 0), 0x50, 16 * KiB,
+    at24c_eeprom_init_rom(o, pca954x_i2c_get_bus(i2c_mux, 0), 0x50, 16 * KiB,
                           rpdb_eeprom, rpdb_eeprom_len);
 
     /* i2c8mux ch1 */
@@ -280,15 +280,15 @@ static void anacapa_bmc_i2c_init(AspeedMachineState *bmc)
     i2c_slave_create_simple(o, "gpio[*]", pca954x_i2c_get_bus(i2c_mux, 1),
                             TYPE_PCA9552, 0x24);
     /* eeprom@50 */
-    at24c_eeprom_init_rom(pca954x_i2c_get_bus(i2c_mux, 1), 0x50, 16 * KiB,
+    at24c_eeprom_init_rom(o, pca954x_i2c_get_bus(i2c_mux, 1), 0x50, 16 * KiB,
                           lpdb_eeprom, lpdb_eeprom_len);
 
     /* &i2c9 */
     /* eeprom@50 */
-    at24c_eeprom_init_rom(i2c[9], 0x50, 16 * KiB,
+    at24c_eeprom_init_rom(o, i2c[9], 0x50, 16 * KiB,
                           scm_eeprom, scm_eeprom_len);
     /* eeprom@56 */
-    at24c_eeprom_init_rom(i2c[9], 0x56, 8 * KiB,
+    at24c_eeprom_init_rom(o, i2c[9], 0x56, 8 * KiB,
                           bsm_eeprom, bsm_eeprom_len);
 
     /* &i2c10 */
@@ -301,7 +301,7 @@ static void anacapa_bmc_i2c_init(AspeedMachineState *bmc)
     i2c_slave_create_simple(o, "gpio[*]", pca954x_i2c_get_bus(i2c_mux, 5),
                             TYPE_PCA9552, 0x22);
     /* eeprom@52 */
-    at24c_eeprom_init_rom(pca954x_i2c_get_bus(i2c_mux, 5), 0x52, 32 * KiB,
+    at24c_eeprom_init_rom(o, pca954x_i2c_get_bus(i2c_mux, 5), 0x52, 32 * KiB,
                           rbb_eeprom, rbb_eeprom_len);
 
     /* &i2c11 */
@@ -316,7 +316,7 @@ static void anacapa_bmc_i2c_init(AspeedMachineState *bmc)
     i2c_slave_create_simple(o, "gpio[*]", pca954x_i2c_get_bus(i2c_mux, 5),
                             TYPE_PCA9552, 0x22);
     /* eeprom@52 */
-    at24c_eeprom_init_rom(pca954x_i2c_get_bus(i2c_mux, 5), 0x52, 32 * KiB,
+    at24c_eeprom_init_rom(o, pca954x_i2c_get_bus(i2c_mux, 5), 0x52, 32 * KiB,
                           lbb_eeprom, lbb_eeprom_len);
 
     /* &i2c13 */
@@ -329,7 +329,7 @@ static void anacapa_bmc_i2c_init(AspeedMachineState *bmc)
 
     /* i2c13mux ch4 */
     /* eeprom@51 */
-    at24c_eeprom_init_rom(pca954x_i2c_get_bus(i2c_mux, 4), 0x51, 32 * KiB,
+    at24c_eeprom_init_rom(o, pca954x_i2c_get_bus(i2c_mux, 4), 0x51, 32 * KiB,
                           hpm_brd_id_eeprom, hpm_brd_id_eeprom_len);
 
     /* i2c13mux ch7 */
hw/arm/aspeed_ast2600_bletchley.c +2 -2
index 58f0bc89bd..a9ae61f864 100644
@@ -46,13 +46,13 @@ static void bletchley_bmc_i2c_init(AspeedMachineState *bmc)
     }
 
     /* Bus 6 */
-    at24c_eeprom_init(i2c[6], 0x56, 65536);
+    at24c_eeprom_init(OBJECT(bmc), i2c[6], 0x56, 65536);
     /* Missing model: nxp,pcf85263 @ 0x51 , but ds1338 works enough */
     i2c_slave_create_simple(OBJECT(bmc), "rtc", i2c[6], "ds1338", 0x51);
 
 
     /* Bus 7 */
-    at24c_eeprom_init(i2c[7], 0x54, 65536);
+    at24c_eeprom_init(OBJECT(bmc), i2c[7], 0x54, 65536);
 
     /* Bus 9 */
     i2c_slave_create_simple(OBJECT(bmc), "tmp421[*]",
hw/arm/aspeed_ast2600_catalina.c +17 -17
index 59fc0d2437..e33e40590d 100644
@@ -484,7 +484,7 @@ static void catalina_bmc_i2c_init(AspeedMachineState *bmc)
     i2c_slave_create_simple(o, "gpio[*]", pca954x_i2c_get_bus(i2c_mux, 1),
                             TYPE_PCA9535, 0x20);
     /* eeprom@50 */
-    at24c_eeprom_init_rom(pca954x_i2c_get_bus(i2c_mux, 1), 0x50, 8 * KiB,
+    at24c_eeprom_init_rom(o, pca954x_i2c_get_bus(i2c_mux, 1), 0x50, 8 * KiB,
                           gb200io_eeprom, gb200io_eeprom_len);
 
     /* i2c-mux@73 (PCA9546) on i2c0 */
@@ -502,7 +502,7 @@ static void catalina_bmc_i2c_init(AspeedMachineState *bmc)
     i2c_slave_create_simple(o, "gpio[*]", pca954x_i2c_get_bus(i2c_mux, 1),
                             TYPE_PCA9535, 0x21);
     /* eeprom@50 */
-    at24c_eeprom_init_rom(pca954x_i2c_get_bus(i2c_mux, 1), 0x50, 8 * KiB,
+    at24c_eeprom_init_rom(o, pca954x_i2c_get_bus(i2c_mux, 1), 0x50, 8 * KiB,
                           gb200io_eeprom, gb200io_eeprom_len);
 
     /* i2c-mux@77 (PCA9546) on i2c0 */
@@ -526,7 +526,7 @@ static void catalina_bmc_i2c_init(AspeedMachineState *bmc)
 
     /* i2c1mux0ch5 */
     /* eeprom@54 */
-    at24c_eeprom_init_rom(pca954x_i2c_get_bus(i2c_mux, 5), 0x54, 8 * KiB,
+    at24c_eeprom_init_rom(o, pca954x_i2c_get_bus(i2c_mux, 5), 0x54, 8 * KiB,
                           pdb_eeprom, pdb_eeprom_len);
     /* tpm75@4f */
     i2c_slave_create_simple(o, "tmp75[*]", pca954x_i2c_get_bus(i2c_mux, 5),
@@ -540,12 +540,12 @@ static void catalina_bmc_i2c_init(AspeedMachineState *bmc)
     i2c_slave_create_simple(o, "gpio[*]", pca954x_i2c_get_bus(i2c_mux, 6),
                             TYPE_PCA9552, 0x25);
     /* eeprom@51 */
-    at24c_eeprom_init_rom(pca954x_i2c_get_bus(i2c_mux, 6), 0x51, 8 * KiB,
+    at24c_eeprom_init_rom(o, pca954x_i2c_get_bus(i2c_mux, 6), 0x51, 8 * KiB,
                           osfp_eeprom, osfp_eeprom_len);
 
     /* i2c1mux0ch7 */
     /* eeprom@53 */
-    at24c_eeprom_init_rom(pca954x_i2c_get_bus(i2c_mux, 7), 0x53, 8 * KiB,
+    at24c_eeprom_init_rom(o, pca954x_i2c_get_bus(i2c_mux, 7), 0x53, 8 * KiB,
                           fio_eeprom, fio_eeprom_len);
     /* temperature-sensor@4b - tmp75 */
     i2c_slave_create_simple(o, "tmp75[*]", pca954x_i2c_get_bus(i2c_mux, 7),
@@ -559,9 +559,9 @@ static void catalina_bmc_i2c_init(AspeedMachineState *bmc)
     /* io_expander0 - pca9555@27 */
     i2c_slave_create_simple(o, "gpio[*]", i2c[2], TYPE_PCA9552, 0x27);
     /* eeprom@50 */
-    at24c_eeprom_init(i2c[2], 0x50, 8 * KiB);
+    at24c_eeprom_init(o, i2c[2], 0x50, 8 * KiB);
     /* eeprom@51 */
-    at24c_eeprom_init(i2c[2], 0x51, 8 * KiB);
+    at24c_eeprom_init(o, i2c[2], 0x51, 8 * KiB);
 
     /* &i2c5 */
     /* i2c-mux@70 (PCA9548) on i2c5 */
@@ -569,7 +569,7 @@ static void catalina_bmc_i2c_init(AspeedMachineState *bmc)
                                       TYPE_PCA9548, 0x70);
     /* i2c5mux0ch6 */
     /* eeprom@52 */
-    at24c_eeprom_init_rom(pca954x_i2c_get_bus(i2c_mux, 6), 0x52, 8 * KiB,
+    at24c_eeprom_init_rom(o, pca954x_i2c_get_bus(i2c_mux, 6), 0x52, 8 * KiB,
                           hdd_eeprom, hdd_eeprom_len);
     /* i2c5mux0ch7 */
     /* ina230@40 - no model */
@@ -589,36 +589,36 @@ static void catalina_bmc_i2c_init(AspeedMachineState *bmc)
     /* temperature-sensor@4b - tpm75 */
     i2c_slave_create_simple(o, "tmp75[*]", i2c[9], TYPE_TMP75, 0x4b);
     /* eeprom@50 */
-    at24c_eeprom_init_rom(i2c[9], 0x50, 8 * KiB, scm_eeprom, scm_eeprom_len);
+    at24c_eeprom_init_rom(o, i2c[9], 0x50, 8 * KiB, scm_eeprom, scm_eeprom_len);
     /* eeprom@56 */
-    at24c_eeprom_init_rom(i2c[9], 0x56, 8 * KiB, bsm_eeprom, bsm_eeprom_len);
+    at24c_eeprom_init_rom(o, i2c[9], 0x56, 8 * KiB, bsm_eeprom, bsm_eeprom_len);
 
     /* &i2c10 */
     /* temperature-sensor@1f - tpm421 */
     i2c_slave_create_simple(o, "tmp421[*]", i2c[10], TYPE_TMP421, 0x1f);
     /* eeprom@50 */
-    at24c_eeprom_init_rom(i2c[10], 0x50, 8 * KiB, nic_eeprom, nic_eeprom_len);
+    at24c_eeprom_init_rom(o, i2c[10], 0x50, 8 * KiB, nic_eeprom, nic_eeprom_len);
 
     /* &i2c11 */
     /* ssif-bmc@10 - no model */
 
     /* &i2c12 */
     /* eeprom@50 */
-    at24c_eeprom_init_rom(i2c[12], 0x50, 8 * KiB,
+    at24c_eeprom_init_rom(o, i2c[12], 0x50, 8 * KiB,
                           gb200_eeprom, gb200_eeprom_len);
     /* eeprom@54 */
-    at24c_eeprom_init_rom(i2c[12], 0x54, 256,
+    at24c_eeprom_init_rom(o, i2c[12], 0x54, 256,
                           cable_eeprom, cable_eeprom_len);
 
     /* &i2c13 */
     /* eeprom@50 */
-    at24c_eeprom_init_rom(i2c[13], 0x50, 8 * KiB,
+    at24c_eeprom_init_rom(o, i2c[13], 0x50, 8 * KiB,
                           gb200_eeprom, gb200_eeprom_len);
     /* eeprom@54 */
-    at24c_eeprom_init_rom(i2c[13], 0x54, 256,
+    at24c_eeprom_init_rom(o, i2c[13], 0x54, 256,
                           cable_eeprom, cable_eeprom_len);
     /* eeprom@57 */
-    at24c_eeprom_init_rom(i2c[13], 0x57, 256, hmc_eeprom, hmc_eeprom_len);
+    at24c_eeprom_init_rom(o, i2c[13], 0x57, 256, hmc_eeprom, hmc_eeprom_len);
 
     /* &i2c14 */
     /* io_expander9 - pca9555@10 */
@@ -638,7 +638,7 @@ static void catalina_bmc_i2c_init(AspeedMachineState *bmc)
     /* temperature-sensor@1f - tmp421 */
     i2c_slave_create_simple(o, "tmp421[*]", i2c[15], TYPE_TMP421, 0x1f);
     /* eeprom@52 */
-    at24c_eeprom_init_rom(i2c[15], 0x52, 8 * KiB, nic_eeprom, nic_eeprom_len);
+    at24c_eeprom_init_rom(o, i2c[15], 0x52, 8 * KiB, nic_eeprom, nic_eeprom_len);
 }
 
 static void aspeed_machine_catalina_class_init(ObjectClass *oc,
hw/arm/aspeed_ast2600_fby35.c +5 -5
index dedc273ee3..d7bea13706 100644
@@ -109,13 +109,13 @@ static void fby35_i2c_init(AspeedMachineState *bmc)
     i2c_slave_create_simple(OBJECT(bmc), "lm75[*]", i2c[12], TYPE_LM75, 0x4e);
     i2c_slave_create_simple(OBJECT(bmc), "lm75[*]", i2c[12], TYPE_LM75, 0x4f);
 
-    at24c_eeprom_init(i2c[4], 0x51, 128 * KiB);
-    at24c_eeprom_init(i2c[6], 0x51, 128 * KiB);
-    at24c_eeprom_init_rom(i2c[8], 0x50, 32 * KiB, fby35_nic_fruid,
+    at24c_eeprom_init(OBJECT(bmc), i2c[4], 0x51, 128 * KiB);
+    at24c_eeprom_init(OBJECT(bmc), i2c[6], 0x51, 128 * KiB);
+    at24c_eeprom_init_rom(OBJECT(bmc), i2c[8], 0x50, 32 * KiB, fby35_nic_fruid,
                           fby35_nic_fruid_len);
-    at24c_eeprom_init_rom(i2c[11], 0x51, 128 * KiB, fby35_bb_fruid,
+    at24c_eeprom_init_rom(OBJECT(bmc), i2c[11], 0x51, 128 * KiB, fby35_bb_fruid,
                           fby35_bb_fruid_len);
-    at24c_eeprom_init_rom(i2c[11], 0x54, 128 * KiB, fby35_bmc_fruid,
+    at24c_eeprom_init_rom(OBJECT(bmc), i2c[11], 0x54, 128 * KiB, fby35_bmc_fruid,
                           fby35_bmc_fruid_len);
 
     /*
hw/arm/aspeed_ast2600_fuji.c +17 -17
index 1e681d0090..396bd6c8b7 100644
@@ -66,45 +66,45 @@ static void fuji_bmc_i2c_init(AspeedMachineState *bmc)
      * EEPROM 24c64 size is 64Kbits or 8 Kbytes
      *        24c02 size is 2Kbits or 256 bytes
      */
-    at24c_eeprom_init(i2c[19], 0x52, 8 * KiB);
-    at24c_eeprom_init(i2c[20], 0x50, 256);
-    at24c_eeprom_init(i2c[22], 0x52, 256);
+    at24c_eeprom_init(o, i2c[19], 0x52, 8 * KiB);
+    at24c_eeprom_init(o, i2c[20], 0x50, 256);
+    at24c_eeprom_init(o, i2c[22], 0x52, 256);
 
     i2c_slave_create_simple(o, "lm75[*]", i2c[3], TYPE_LM75, 0x48);
     i2c_slave_create_simple(o, "lm75[*]", i2c[3], TYPE_LM75, 0x49);
     i2c_slave_create_simple(o, "lm75[*]", i2c[3], TYPE_LM75, 0x4a);
     i2c_slave_create_simple(o, "tmp422", i2c[3], TYPE_TMP422, 0x4c);
 
-    at24c_eeprom_init(i2c[8], 0x51, 8 * KiB);
+    at24c_eeprom_init(o, i2c[8], 0x51, 8 * KiB);
     i2c_slave_create_simple(o, "lm75[*]", i2c[8], TYPE_LM75, 0x4a);
 
     i2c_slave_create_simple(o, "lm75[*]", i2c[50], TYPE_LM75, 0x4c);
-    at24c_eeprom_init(i2c[50], 0x52, 8 * KiB);
+    at24c_eeprom_init(o, i2c[50], 0x52, 8 * KiB);
     i2c_slave_create_simple(o, "tmp75[*]", i2c[51], TYPE_TMP75, 0x48);
     i2c_slave_create_simple(o, "tmp75[*]", i2c[52], TYPE_TMP75, 0x49);
 
     i2c_slave_create_simple(o, "tmp75[*]", i2c[59], TYPE_TMP75, 0x48);
     i2c_slave_create_simple(o, "tmp75[*]", i2c[60], TYPE_TMP75, 0x49);
 
-    at24c_eeprom_init(i2c[65], 0x53, 8 * KiB);
+    at24c_eeprom_init(o, i2c[65], 0x53, 8 * KiB);
     i2c_slave_create_simple(o, "tmp75[*]", i2c[66], TYPE_TMP75, 0x49);
     i2c_slave_create_simple(o, "tmp75[*]", i2c[66], TYPE_TMP75, 0x48);
-    at24c_eeprom_init(i2c[68], 0x52, 8 * KiB);
-    at24c_eeprom_init(i2c[69], 0x52, 8 * KiB);
-    at24c_eeprom_init(i2c[70], 0x52, 8 * KiB);
-    at24c_eeprom_init(i2c[71], 0x52, 8 * KiB);
+    at24c_eeprom_init(o, i2c[68], 0x52, 8 * KiB);
+    at24c_eeprom_init(o, i2c[69], 0x52, 8 * KiB);
+    at24c_eeprom_init(o, i2c[70], 0x52, 8 * KiB);
+    at24c_eeprom_init(o, i2c[71], 0x52, 8 * KiB);
 
-    at24c_eeprom_init(i2c[73], 0x53, 8 * KiB);
+    at24c_eeprom_init(o, i2c[73], 0x53, 8 * KiB);
     i2c_slave_create_simple(o, "tmp75[*]", i2c[74], TYPE_TMP75, 0x49);
     i2c_slave_create_simple(o, "tmp75[*]", i2c[74], TYPE_TMP75, 0x48);
-    at24c_eeprom_init(i2c[76], 0x52, 8 * KiB);
-    at24c_eeprom_init(i2c[77], 0x52, 8 * KiB);
-    at24c_eeprom_init(i2c[78], 0x52, 8 * KiB);
-    at24c_eeprom_init(i2c[79], 0x52, 8 * KiB);
-    at24c_eeprom_init(i2c[28], 0x50, 256);
+    at24c_eeprom_init(o, i2c[76], 0x52, 8 * KiB);
+    at24c_eeprom_init(o, i2c[77], 0x52, 8 * KiB);
+    at24c_eeprom_init(o, i2c[78], 0x52, 8 * KiB);
+    at24c_eeprom_init(o, i2c[79], 0x52, 8 * KiB);
+    at24c_eeprom_init(o, i2c[28], 0x50, 256);
 
     for (int i = 0; i < 8; i++) {
-        at24c_eeprom_init(i2c[81 + i * 8], 0x56, 64 * KiB);
+        at24c_eeprom_init(o, i2c[81 + i * 8], 0x56, 64 * KiB);
         i2c_slave_create_simple(o, "tmp75[*]", i2c[82 + i * 8],
                                 TYPE_TMP75, 0x48);
         i2c_slave_create_simple(o, "tmp75[*]", i2c[83 + i * 8],
hw/arm/aspeed_ast2600_gb200nvl.c +3 -3
index 1cf35f96bd..357f30cf83 100644
@@ -68,11 +68,11 @@ static void gb200nvl_bmc_i2c_init(AspeedMachineState *bmc)
     object_property_set_str(OBJECT(dev), "pin1", "high", &error_fatal);
 
     aspeed_create_pca9554(OBJECT(bmc), soc, 9, 0x21);
-    at24c_eeprom_init(i2c[9], 0x50, 64 * KiB);
-    at24c_eeprom_init(i2c[9], 0x51, 64 * KiB);
+    at24c_eeprom_init(OBJECT(bmc), i2c[9], 0x50, 64 * KiB);
+    at24c_eeprom_init(OBJECT(bmc), i2c[9], 0x51, 64 * KiB);
 
     /* Bus 11 */
-    at24c_eeprom_init_rom(i2c[10], 0x50, 256, gb200nvl_bmc_fruid,
+    at24c_eeprom_init_rom(OBJECT(bmc), i2c[10], 0x50, 256, gb200nvl_bmc_fruid,
                           gb200nvl_bmc_fruid_len);
 }
 
hw/arm/aspeed_ast2600_rainier.c +21 -21

104 lines not on this page · raw message

hw/arm/npcm7xx_boards.c +4 -4
index 778ef0f232..1862d0d007 100644
@@ -248,8 +248,8 @@ static void quanta_gsj_i2c_init(Object *parent, NPCM7xxState *soc)
     i2c_slave_create_simple(parent, "tmp105[*]",
                             npcm7xx_i2c_get_bus(soc, 4), "tmp105", 0x5c);
 
-    at24c_eeprom_init(npcm7xx_i2c_get_bus(soc, 9), 0x55, 8192);
-    at24c_eeprom_init(npcm7xx_i2c_get_bus(soc, 10), 0x55, 8192);
+    at24c_eeprom_init(parent, npcm7xx_i2c_get_bus(soc, 9), 0x55, 8192);
+    at24c_eeprom_init(parent, npcm7xx_i2c_get_bus(soc, 10), 0x55, 8192);
 
     /*
      * i2c-11:
@@ -363,7 +363,7 @@ static void kudo_bmc_i2c_init(Object *parent, NPCM7xxState *soc)
     i2c_slave_create_simple(parent, "pca9548[*]",
                             npcm7xx_i2c_get_bus(soc, 4), TYPE_PCA9548, 0x77);
 
-    at24c_eeprom_init(npcm7xx_i2c_get_bus(soc, 4), 0x50, 8192); /* mbfru */
+    at24c_eeprom_init(parent, npcm7xx_i2c_get_bus(soc, 4), 0x50, 8192); /* mbfru */
 
     i2c_mux = i2c_slave_create_simple(parent, "pca9548[*]",
                                       npcm7xx_i2c_get_bus(soc, 13),
@@ -379,7 +379,7 @@ static void kudo_bmc_i2c_init(Object *parent, NPCM7xxState *soc)
     i2c_slave_create_simple(parent, "tmp105[*]",
                             pca954x_i2c_get_bus(i2c_mux, 5), "tmp105", 0x49);
 
-    at24c_eeprom_init(npcm7xx_i2c_get_bus(soc, 14), 0x55, 8192); /* bmcfru */
+    at24c_eeprom_init(parent, npcm7xx_i2c_get_bus(soc, 14), 0x55, 8192); /* bmcfru */
 
     /* TODO: Add remaining i2c devices. */
 }
hw/nvram/eeprom_at24c.c +7 -5
index b6d314447c..036955feee 100644
@@ -138,17 +138,19 @@ int at24c_eeprom_send(I2CSlave *s, uint8_t data)
     return 0;
 }
 
-I2CSlave *at24c_eeprom_init(I2CBus *bus, uint8_t address, uint32_t rom_size)
+I2CSlave *at24c_eeprom_init(Object *parent, I2CBus *bus, uint8_t address,
+                            uint32_t rom_size)
 {
-    return at24c_eeprom_init_rom(bus, address, rom_size, NULL, 0);
+    return at24c_eeprom_init_rom(parent, bus, address, rom_size, NULL, 0);
 }
 
-I2CSlave *at24c_eeprom_init_rom(I2CBus *bus, uint8_t address, uint32_t rom_size,
+I2CSlave *at24c_eeprom_init_rom(Object *parent, I2CBus *bus, uint8_t address,
+                                uint32_t rom_size,
                                 const uint8_t *init_rom, uint32_t init_rom_size)
 {
     EEPROMState *s;
 
-    s = AT24C_EE(i2c_slave_new_orphan(TYPE_AT24C_EE, address));
+    s = AT24C_EE(i2c_slave_new(parent, "eeprom[*]", TYPE_AT24C_EE, address));
 
     qdev_prop_set_uint32(DEVICE(s), "rom-size", rom_size);
 
@@ -156,7 +158,7 @@ I2CSlave *at24c_eeprom_init_rom(I2CBus *bus, uint8_t address, uint32_t rom_size,
     s->init_rom = init_rom;
     s->init_rom_size = init_rom_size;
 
-    i2c_slave_realize_and_unref(I2C_SLAVE(s), bus, &error_abort);
+    qdev_realize(DEVICE(s), BUS(bus), &error_abort);
 
     return I2C_SLAVE(s);
 }
include/hw/nvram/eeprom_at24c.h +4 -2
index acb9857b2a..6686c7ff46 100644
@@ -18,7 +18,8 @@
  * Create the device state structure, initialize it, put it on the specified
  * @bus, and drop the reference to it (the device is realized).
  */
-I2CSlave *at24c_eeprom_init(I2CBus *bus, uint8_t address, uint32_t rom_size);
+I2CSlave *at24c_eeprom_init(Object *parent, I2CBus *bus, uint8_t address,
+                            uint32_t rom_size);
 
 
 /*
@@ -33,7 +34,8 @@ I2CSlave *at24c_eeprom_init(I2CBus *bus, uint8_t address, uint32_t rom_size);
  * @bus, and drop the reference to it (the device is realized). Copies the data
  * from @init_rom to the beginning of the EEPROM memory buffer.
  */
-I2CSlave *at24c_eeprom_init_rom(I2CBus *bus, uint8_t address, uint32_t rom_size,
+I2CSlave *at24c_eeprom_init_rom(Object *parent, I2CBus *bus, uint8_t address,
+                                uint32_t rom_size,
                                 const uint8_t *init_rom, uint32_t init_rom_size);
 
 #endif
Signature · 1 line
2.47.1
#232 lore raw

RFC PATCH v2 75/137 hw/i386/pc: Give pcspk a QOM parent

In reply to Alexander Graf

pcspk was created in pc_machine_initfn() as an orphan and manually unref'd in pc_machine_finalize() when the machine was never realized (e.g. -M pc,help). Making it a child<> of the machine at creation time lets the QOM property teardown in object_property_del_all() handle that lifecycle for free, so pc_machine_finalize() and its open-coded refcount juggling can go.

The realize path switches from isa_realize_and_unref() to plain qdev_realize() because the reference is now held by the parent's child<> property, not the caller.

AI-used-for: code (refactoring)

---
 hw/i386/pc.c | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)
hw/i386/pc.c +2 -12
index 0c89310ab7..a00d53b582 100644
@@ -1128,7 +1128,7 @@ void pc_basic_device_init(struct PCMachineState *pcms,
         }
         object_property_set_link(OBJECT(pcms->pcspk), "pit",
                                  OBJECT(pit), &error_fatal);
-        isa_realize_and_unref(pcms->pcspk, isa_bus, &error_fatal);
+        qdev_realize(DEVICE(pcms->pcspk), BUS(isa_bus), &error_fatal);
     }
 
     if (pcms->vmport == ON_OFF_AUTO_AUTO) {
@@ -1640,7 +1640,7 @@ static void pc_machine_initfn(Object *obj)
     pcms->default_bus_bypass_iommu = false;
 
     pc_system_flash_create(pcms);
-    pcms->pcspk = isa_new_orphan(TYPE_PC_SPEAKER);
+    pcms->pcspk = isa_new(obj, "pcspk", TYPE_PC_SPEAKER);
     object_property_add_alias(OBJECT(pcms), "pcspk-audiodev",
                               OBJECT(pcms->pcspk), "audiodev");
     if (pcmc->pci_enabled) {
@@ -1648,15 +1648,6 @@ static void pc_machine_initfn(Object *obj)
     }
 }
 
-static void pc_machine_finalize(Object *obj)
-{
-    PCMachineState *pcms = PC_MACHINE(obj);
-
-    if (pcms->pcspk && !qdev_is_realized(DEVICE(pcms->pcspk))) {
-        object_unref(OBJECT(pcms->pcspk));
-    }
-}
-
 static void pc_machine_reset(MachineState *machine, ResetType type)
 {
     CPUState *cs;
@@ -1795,7 +1786,6 @@ static const TypeInfo pc_machine_info = {
     .abstract = true,
     .instance_size = sizeof(PCMachineState),
     .instance_init = pc_machine_initfn,
-    .instance_finalize = pc_machine_finalize,
     .class_size = sizeof(PCMachineClass),
     .class_init = pc_machine_class_init,
     .interfaces = (const InterfaceInfo[]) {
Signature · 1 line
2.47.1
#233 lore raw

RFC PATCH v2 76/137 hw/timer, hw/net: Give i8254 and isa-ne2000 helpers a QOM parent

In reply to Alexander Graf

The i8254_pit_init(), kvm_pit_init() and isa_ne2000_init() inline helpers still created their ISA device as an orphan. Thread an Object *parent through and switch to isa_new()/isa_try_new() with qdev_realize().

While at it, drop the dead vmport_init() inline: it has had no callers since vmmouse got a proper board-level creator, and it was the last user of isa_create_simple_orphan() outside the ISA layer itself.

Callers pick the composition-tree owner:

  hw/i386/pc.c        pcms (board)
  hw/i386/microvm.c   mms  (board)
  hw/isa/piix.c       d    (south-bridge realize)
  hw/isa/i82378.c     dev  (bridge realize)
  hw/isa/vt82c686.c   d    (super-io realize)
  hw/mips/jazz.c      machine (board)

AI-used-for: code (refactoring)

---
 hw/i386/microvm.c           |  4 ++--
 hw/i386/pc.c                |  6 +++---
 hw/isa/i82378.c             |  2 +-
 hw/isa/piix.c               |  2 +-
 hw/isa/vt82c686.c           |  2 +-
 hw/mips/jazz.c              |  2 +-
 include/hw/i386/vmport.h    |  5 -----
 include/hw/net/ne2000-isa.h |  8 ++++----
 include/hw/timer/i8254.h    | 13 +++++++------
 9 files changed, 20 insertions(+), 24 deletions(-)
hw/i386/microvm.c +2 -2
index d701672c1a..8c61106516 100644
@@ -261,9 +261,9 @@ static void microvm_devices_init(MicrovmMachineState *mms)
 
     if (x86ms->pit == ON_OFF_AUTO_ON || x86ms->pit == ON_OFF_AUTO_AUTO) {
         if (kvm_pit_in_kernel()) {
-            kvm_pit_init(isa_bus, 0x40);
+            kvm_pit_init(OBJECT(mms), isa_bus, 0x40);
         } else {
-            i8254_pit_init(isa_bus, 0x40, 0, NULL);
+            i8254_pit_init(OBJECT(mms), isa_bus, 0x40, 0, NULL);
         }
     }
 
hw/i386/pc.c +3 -3
index a00d53b582..e505391985 100644
@@ -505,7 +505,7 @@ static gboolean pc_init_ne2k_isa(ISABus *bus, NICInfo *nd, Error **errp)
                    "maximum number of ISA NE2000 devices exceeded");
         return false;
     }
-    isa_ne2000_init(bus, ne2000_io[nb_ne2k],
+    isa_ne2000_init(qdev_get_machine(), bus, ne2000_io[nb_ne2k],
                     ne2000_irq[nb_ne2k], nd);
     nb_ne2k++;
     return true;
@@ -1118,9 +1118,9 @@ void pc_basic_device_init(struct PCMachineState *pcms,
     if (!xen_enabled() &&
         (x86ms->pit == ON_OFF_AUTO_AUTO || x86ms->pit == ON_OFF_AUTO_ON)) {
         if (kvm_pit_in_kernel()) {
-            pit = kvm_pit_init(isa_bus, 0x40);
+            pit = kvm_pit_init(OBJECT(pcms), isa_bus, 0x40);
         } else {
-            pit = i8254_pit_init(isa_bus, 0x40, pit_isa_irq, pit_alt_irq);
+            pit = i8254_pit_init(OBJECT(pcms), isa_bus, 0x40, pit_isa_irq, pit_alt_irq);
         }
         if (hpet) {
             /* connect PIT to output control line of the HPET */
hw/isa/i82378.c +1 -1
index 1c0a6ad779..995d1eaa53 100644
@@ -100,7 +100,7 @@ static void i82378_realize(PCIDevice *pci, Error **errp)
     isa_bus_register_input_irqs(isabus, s->isa_irqs_in);
 
     /* 1 82C54 (pit) */
-    pit = i8254_pit_init(isabus, 0x40, 0, NULL);
+    pit = i8254_pit_init(OBJECT(dev), isabus, 0x40, 0, NULL);
 
     /* speaker */
     pcspk = isa_new(OBJECT(s), "pcspk", TYPE_PC_SPEAKER);
hw/isa/piix.c +1 -1
index 6b2946d82c..d96bc3a873 100644
@@ -334,7 +334,7 @@ static void pci_piix_realize(PCIDevice *dev, const char *uhci_type,
 
     /* PIT */
     if (d->has_pit) {
-        i8254_pit_init(isa_bus, 0x40, 0, NULL);
+        i8254_pit_init(OBJECT(d), isa_bus, 0x40, 0, NULL);
     }
 
     i8257_dma_init(OBJECT(dev), isa_bus, 0);
hw/isa/vt82c686.c +1 -1
index de9006bd95..2337c3115b 100644
@@ -732,7 +732,7 @@ static void via_isa_realize(PCIDevice *d, Error **errp)
 
     s->isa_irqs_in = i8259_init(OBJECT(d), isa_bus, &s->i8259_irq);
     isa_bus_register_input_irqs(isa_bus, s->isa_irqs_in);
-    i8254_pit_init(isa_bus, 0x40, 0, NULL);
+    i8254_pit_init(OBJECT(d), isa_bus, 0x40, 0, NULL);
     i8257_dma_init(OBJECT(d), isa_bus, 0);
 
     /* RTC */
hw/mips/jazz.c +1 -1
index 208e59fbeb..23d717d96a 100644
@@ -289,7 +289,7 @@ static void mips_jazz_init(MachineState *machine,
     i8259 = i8259_init(OBJECT(machine), isa_bus, env->irq[4]);
     isa_bus_register_input_irqs(isa_bus, i8259);
     i8257_dma_init(OBJECT(rc4030), isa_bus, 0);
-    pit = i8254_pit_init(isa_bus, 0x40, 0, NULL);
+    pit = i8254_pit_init(OBJECT(machine), isa_bus, 0x40, 0, NULL);
     pcspk = isa_new(OBJECT(machine), "pcspk", TYPE_PC_SPEAKER);
     object_property_set_link(OBJECT(pcspk), "pit", OBJECT(pit), &error_fatal);
     qdev_realize(DEVICE(pcspk), BUS(isa_bus), &error_fatal);
include/hw/i386/vmport.h +0 -5
index 22dd3645d2..02e422029d 100644
@@ -18,11 +18,6 @@ typedef enum {
     VMPORT_ENTRIES
 } VMPortCommand;
 
-static inline void vmport_init(ISABus *bus)
-{
-    isa_create_simple_orphan(bus, TYPE_VMPORT);
-}
-
 void vmport_register(VMPortCommand command, VMPortReadFunc *func, void *opaque);
 
 #endif
include/hw/net/ne2000-isa.h +4 -4
index ef8b3334d7..f504a03db7 100644
@@ -17,19 +17,19 @@
 
 #define TYPE_ISA_NE2000 "ne2k_isa"
 
-static inline ISADevice *isa_ne2000_init(ISABus *bus, int base, int irq,
-                                         NICInfo *nd)
+static inline ISADevice *isa_ne2000_init(Object *parent, ISABus *bus,
+                                          int base, int irq, NICInfo *nd)
 {
     ISADevice *d;
 
-    d = isa_try_new_orphan(TYPE_ISA_NE2000);
+    d = isa_try_new(parent, "ne2k[*]", TYPE_ISA_NE2000);
     if (d) {
         DeviceState *dev = DEVICE(d);
 
         qdev_prop_set_uint32(dev, "iobase", base);
         qdev_prop_set_uint32(dev, "irq",    irq);
         qdev_set_nic_properties(dev, nd);
-        isa_realize_and_unref(d, bus, &error_fatal);
+        qdev_realize(dev, BUS(bus), &error_fatal);
     }
     return d;
 }
include/hw/timer/i8254.h +7 -6
index 38f896063e..b7bc98b688 100644
@@ -45,16 +45,17 @@ OBJECT_DECLARE_TYPE(PITCommonState, PITCommonClass, PIT_COMMON)
 #define TYPE_I8254 "isa-pit"
 #define TYPE_KVM_I8254 "kvm-pit"
 
-static inline ISADevice *i8254_pit_init(ISABus *bus, int base, int isa_irq,
+static inline ISADevice *i8254_pit_init(Object *parent, ISABus *bus,
+                                        int base, int isa_irq,
                                         qemu_irq alt_irq)
 {
     DeviceState *dev;
     ISADevice *d;
 
-    d = isa_new_orphan(TYPE_I8254);
+    d = isa_new(parent, "pit[*]", TYPE_I8254);
     dev = DEVICE(d);
     qdev_prop_set_uint32(dev, "iobase", base);
-    isa_realize_and_unref(d, bus, &error_fatal);
+    qdev_realize(dev, BUS(bus), &error_fatal);
     qdev_connect_gpio_out(dev, 0,
                           isa_irq >= 0 ? isa_bus_get_irq(bus, isa_irq)
                                        : alt_irq);
@@ -62,15 +63,15 @@ static inline ISADevice *i8254_pit_init(ISABus *bus, int base, int isa_irq,
     return d;
 }
 
-static inline ISADevice *kvm_pit_init(ISABus *bus, int base)
+static inline ISADevice *kvm_pit_init(Object *parent, ISABus *bus, int base)
 {
     DeviceState *dev;
     ISADevice *d;
 
-    d = isa_new_orphan(TYPE_KVM_I8254);
+    d = isa_new(parent, "pit[*]", TYPE_KVM_I8254);
     dev = DEVICE(d);
     qdev_prop_set_uint32(dev, "iobase", base);
-    isa_realize_and_unref(d, bus, &error_fatal);
+    qdev_realize(dev, BUS(bus), &error_fatal);
 
     return d;
 }
Signature · 1 line
2.47.1
#234 lore raw

RFC PATCH v2 77/137 hw/misc/unimp: Give create_unimplemented_device() a QOM parent

In reply to Alexander Graf

Every one of the ~500 call sites already sits inside a SoC .realize() or a board .init() where the natural composition-tree owner is in scope. Thread that owner through as the first argument, reuse the existing @name string as the child<> id, and switch the internal qdev_new_orphan()+sysbus_realize_and_unref() pair to the parented qdev_new()+sysbus_realize().

Parent expression per caller class:

*_realize(DeviceState *dev, ...) OBJECT(dev)
*_soc_realize(DeviceState *dev_soc,) OBJECT(dev_soc)
board_init(MachineState *machine) OBJECT(machine) / OBJECT(ms) etc.

No behavioural change: the low-priority overlap mapping still lets real device models take precedence. All 20 softmmu targets build.

AI-used-for: code (refactoring)

---
 hw/arm/allwinner-a10.c                   |   2 +-
 hw/arm/allwinner-h3.c                    |   2 +-
 hw/arm/allwinner-r40.c                   |   2 +-
 hw/arm/fsl-imx6.c                        |   2 +-
 hw/arm/fsl-imx6ul.c                      |  35 +++---
 hw/arm/fsl-imx7.c                        |  33 +++---
 hw/arm/fsl-imx8mm.c                      |   2 +-
 hw/arm/fsl-imx8mp.c                      |   2 +-
 hw/arm/max78000_soc.c                    | 105 ++++++++--------
 hw/arm/mps2-tz.c                         |   7 +-
 hw/arm/mps2.c                            |  27 +++--
 hw/arm/mps3r.c                           |  10 +-
 hw/arm/msf2-soc.c                        |  20 ++--
 hw/arm/npcm7xx.c                         |  91 +++++++-------
 hw/arm/npcm8xx.c                         | 145 ++++++++++++-----------
 hw/arm/nrf51_soc.c                       |   4 +-
 hw/arm/stellaris.c                       |  12 +-
 hw/arm/stm32f100_soc.c                   |  60 +++++-----
 hw/arm/stm32f405_soc.c                   |  84 ++++++-------
 hw/arm/stm32l4x5_soc.c                   |  88 +++++++-------
 hw/arm/xilinx_zynq.c                     |  61 +++++-----
 hw/avr/atmega.c                          |  20 ++--
 hw/loongarch/virt.c                      |   2 +-
 hw/microblaze/petalogix_s3adsp1800_mmu.c |   2 +-
 hw/mips/loongson3_virt.c                 |   5 +-
 hw/pci-host/bonito.c                     |  14 +--
 hw/riscv/k230.c                          | 107 ++++++++---------
 hw/riscv/microblaze-v-generic.c          |  10 +-
 hw/riscv/microchip_pfsoc.c               |  54 ++++-----
 hw/riscv/opentitan.c                     |  52 ++++----
 hw/riscv/sifive_e.c                      |  12 +-
 hw/riscv/sifive_u.c                      |   6 +-
 hw/riscv/tt_atlantis.c                   |   2 +-
 hw/sparc/sun4m.c                         |   8 +-
 hw/sparc64/niagara.c                     |   3 +-
 include/hw/misc/unimp.h                  |   9 +-
 36 files changed, 557 insertions(+), 543 deletions(-)
hw/arm/allwinner-a10.c +1 -1
index cbc0b38986..8b37fd61f3 100644
@@ -131,7 +131,7 @@ static void aw_a10_realize(DeviceState *dev, Error **errp)
     memory_region_init_ram(&s->sram_a, OBJECT(dev), "sram A", 48 * KiB,
                            &error_fatal);
     memory_region_add_subregion(get_system_memory(), 0x00000000, &s->sram_a);
-    create_unimplemented_device("a10-sram-ctrl", 0x01c00000, 4 * KiB);
+    create_unimplemented_device(OBJECT(dev), "a10-sram-ctrl", 0x01c00000, 4 * KiB);
 
     /* Clock Control Module */
     sysbus_realize(SYS_BUS_DEVICE(&s->ccm), &error_fatal);
hw/arm/allwinner-h3.c +1 -1
index 6f9a07610f..711bfae095 100644
@@ -468,7 +468,7 @@ static void allwinner_h3_realize(DeviceState *dev, Error **errp)
 
     /* Unimplemented devices */
     for (i = 0; i < ARRAY_SIZE(unimplemented); i++) {
-        create_unimplemented_device(unimplemented[i].device_name,
+        create_unimplemented_device(OBJECT(dev), unimplemented[i].device_name,
                                     unimplemented[i].base,
                                     unimplemented[i].size);
     }
hw/arm/allwinner-r40.c +1 -1
index 4f9d8a606e..9c15d361b4 100644
@@ -532,7 +532,7 @@ static void allwinner_r40_realize(DeviceState *dev, Error **errp)
 
     /* Unimplemented devices */
     for (unsigned i = 0; i < ARRAY_SIZE(r40_unimplemented); i++) {
-        create_unimplemented_device(r40_unimplemented[i].device_name,
+        create_unimplemented_device(OBJECT(dev), r40_unimplemented[i].device_name,
                                     r40_unimplemented[i].base,
                                     r40_unimplemented[i].size);
     }
hw/arm/fsl-imx6.c +1 -1
index 44046953be..f0fbdc1a68 100644
@@ -471,7 +471,7 @@ static void fsl_imx6_realize(DeviceState *dev, Error **errp)
     /*
      * PCIe PHY
      */
-    create_unimplemented_device("pcie-phy", FSL_IMX6_PCIe_ADDR,
+    create_unimplemented_device(OBJECT(dev), "pcie-phy", FSL_IMX6_PCIe_ADDR,
                                 FSL_IMX6_PCIe_SIZE);
 
     /* ROM memory */
hw/arm/fsl-imx6ul.c +18 -17
index 1863558a0d..adbb896fd1 100644
@@ -161,6 +161,7 @@ static void fsl_imx6ul_init(Object *obj)
 
 static void fsl_imx6ul_realize(DeviceState *dev, Error **errp)
 {
+    Object *obj = OBJECT(dev);
     MachineState *ms = MACHINE(qdev_get_machine());
     FslIMX6ULState *s = FSL_IMX6UL(dev);
     DeviceState *mpcore = DEVICE(&s->a7mpcore);
@@ -198,37 +199,37 @@ static void fsl_imx6ul_realize(DeviceState *dev, Error **errp)
     /*
      * A7MPCORE DAP
      */
-    create_unimplemented_device("a7mpcore-dap", FSL_IMX6UL_A7MPCORE_DAP_ADDR,
+    create_unimplemented_device(obj, "a7mpcore-dap", FSL_IMX6UL_A7MPCORE_DAP_ADDR,
                                 FSL_IMX6UL_A7MPCORE_DAP_SIZE);
 
     /*
      * MMDC
      */
-    create_unimplemented_device("a7mpcore-mmdc", FSL_IMX6UL_MMDC_CFG_ADDR,
+    create_unimplemented_device(obj, "a7mpcore-mmdc", FSL_IMX6UL_MMDC_CFG_ADDR,
                                 FSL_IMX6UL_MMDC_CFG_SIZE);
 
     /*
      * OCOTP
      */
-    create_unimplemented_device("a7mpcore-ocotp", FSL_IMX6UL_OCOTP_CTRL_ADDR,
+    create_unimplemented_device(obj, "a7mpcore-ocotp", FSL_IMX6UL_OCOTP_CTRL_ADDR,
                                 FSL_IMX6UL_OCOTP_CTRL_SIZE);
 
     /*
      * QSPI
      */
-    create_unimplemented_device("a7mpcore-qspi", FSL_IMX6UL_QSPI_ADDR,
+    create_unimplemented_device(obj, "a7mpcore-qspi", FSL_IMX6UL_QSPI_ADDR,
                                 FSL_IMX6UL_QSPI_SIZE);
 
     /*
      * CAAM
      */
-    create_unimplemented_device("a7mpcore-qspi", FSL_IMX6UL_CAAM_ADDR,
+    create_unimplemented_device(obj, "a7mpcore-qspi", FSL_IMX6UL_CAAM_ADDR,
                                 FSL_IMX6UL_CAAM_SIZE);
 
     /*
      * USBMISC
      */
-    create_unimplemented_device("a7mpcore-usbmisc", FSL_IMX6UL_USBO2_USBMISC_ADDR,
+    create_unimplemented_device(obj, "a7mpcore-usbmisc", FSL_IMX6UL_USBO2_USBMISC_ADDR,
                                 FSL_IMX6UL_USBO2_USBMISC_SIZE);
 
     /*
@@ -322,9 +323,9 @@ static void fsl_imx6ul_realize(DeviceState *dev, Error **errp)
     /*
      * IOMUXC
      */
-    create_unimplemented_device("iomuxc", FSL_IMX6UL_IOMUXC_ADDR,
+    create_unimplemented_device(obj, "iomuxc", FSL_IMX6UL_IOMUXC_ADDR,
                                 FSL_IMX6UL_IOMUXC_SIZE);
-    create_unimplemented_device("iomuxc_gpr", FSL_IMX6UL_IOMUXC_GPR_ADDR,
+    create_unimplemented_device(obj, "iomuxc_gpr", FSL_IMX6UL_IOMUXC_GPR_ADDR,
                                 FSL_IMX6UL_IOMUXC_GPR_SIZE);
 
     /*
@@ -581,7 +582,7 @@ static void fsl_imx6ul_realize(DeviceState *dev, Error **errp)
     /*
      * SDMA
      */
-    create_unimplemented_device("sdma", FSL_IMX6UL_SDMA_ADDR,
+    create_unimplemented_device(obj, "sdma", FSL_IMX6UL_SDMA_ADDR,
                                 FSL_IMX6UL_SDMA_SIZE);
 
     /*
@@ -595,7 +596,7 @@ static void fsl_imx6ul_realize(DeviceState *dev, Error **errp)
         };
 
         snprintf(name, NAME_SIZE, "sai%d", i);
-        create_unimplemented_device(name, FSL_IMX6UL_SAIn_ADDR[i],
+        create_unimplemented_device(obj, name, FSL_IMX6UL_SAIn_ADDR[i],
                                     FSL_IMX6UL_SAIn_SIZE);
     }
 
@@ -615,14 +616,14 @@ static void fsl_imx6ul_realize(DeviceState *dev, Error **errp)
         };
 
         snprintf(name, NAME_SIZE, "pwm%d", i);
-        create_unimplemented_device(name, FSL_IMX6UL_PWMn_ADDR[i],
+        create_unimplemented_device(obj, name, FSL_IMX6UL_PWMn_ADDR[i],
                                     FSL_IMX6UL_PWMn_SIZE);
     }
 
     /*
      * Audio ASRC (asynchronous sample rate converter)
      */
-    create_unimplemented_device("asrc", FSL_IMX6UL_ASRC_ADDR,
+    create_unimplemented_device(obj, "asrc", FSL_IMX6UL_ASRC_ADDR,
                                 FSL_IMX6UL_ASRC_SIZE);
 
     /*
@@ -635,14 +636,14 @@ static void fsl_imx6ul_realize(DeviceState *dev, Error **errp)
         };
 
         snprintf(name, NAME_SIZE, "can%d", i);
-        create_unimplemented_device(name, FSL_IMX6UL_CANn_ADDR[i],
+        create_unimplemented_device(obj, name, FSL_IMX6UL_CANn_ADDR[i],
                                     FSL_IMX6UL_CANn_SIZE);
     }
 
     /*
      * APHB_DMA
      */
-    create_unimplemented_device("aphb_dma", FSL_IMX6UL_APBH_DMA_ADDR,
+    create_unimplemented_device(obj, "aphb_dma", FSL_IMX6UL_APBH_DMA_ADDR,
                                 FSL_IMX6UL_APBH_DMA_SIZE);
 
     /*
@@ -655,7 +656,7 @@ static void fsl_imx6ul_realize(DeviceState *dev, Error **errp)
         };
 
         snprintf(name, NAME_SIZE, "adc%d", i);
-        create_unimplemented_device(name, FSL_IMX6UL_ADCn_ADDR[i],
+        create_unimplemented_device(obj, name, FSL_IMX6UL_ADCn_ADDR[i],
                                     FSL_IMX6UL_ADCn_SIZE);
     }
 
@@ -670,13 +671,13 @@ static void fsl_imx6ul_realize(DeviceState *dev, Error **errp)
     /*
      * CSU
      */
-    create_unimplemented_device("csu", FSL_IMX6UL_CSU_ADDR,
+    create_unimplemented_device(obj, "csu", FSL_IMX6UL_CSU_ADDR,
                                 FSL_IMX6UL_CSU_SIZE);
 
     /*
      * TZASC
      */
-    create_unimplemented_device("tzasc", FSL_IMX6UL_TZASC_ADDR,
+    create_unimplemented_device(obj, "tzasc", FSL_IMX6UL_TZASC_ADDR,
                                 FSL_IMX6UL_TZASC_SIZE);
 
     /*
hw/arm/fsl-imx7.c +17 -16
index 2defa498d3..07a5ae8cd0 100644
@@ -154,6 +154,7 @@ static void fsl_imx7_init(Object *obj)
 
 static void fsl_imx7_realize(DeviceState *dev, Error **errp)
 {
+    Object *obj = OBJECT(dev);
     MachineState *ms = MACHINE(qdev_get_machine());
     FslIMX7State *s = FSL_IMX7(dev);
     DeviceState *mpcore = DEVICE(&s->a7mpcore);
@@ -229,7 +230,7 @@ static void fsl_imx7_realize(DeviceState *dev, Error **errp)
     /*
      * A7MPCORE DAP
      */
-    create_unimplemented_device("a7mpcore-dap", FSL_IMX7_A7MPCORE_DAP_ADDR,
+    create_unimplemented_device(obj, "a7mpcore-dap", FSL_IMX7_A7MPCORE_DAP_ADDR,
                                 FSL_IMX7_A7MPCORE_DAP_SIZE);
 
     /*
@@ -305,9 +306,9 @@ static void fsl_imx7_realize(DeviceState *dev, Error **errp)
     /*
      * IOMUXC and IOMUXC_LPSR
      */
-    create_unimplemented_device("iomuxc", FSL_IMX7_IOMUXC_ADDR,
+    create_unimplemented_device(obj, "iomuxc", FSL_IMX7_IOMUXC_ADDR,
                                 FSL_IMX7_IOMUXC_SIZE);
-    create_unimplemented_device("iomuxc_lspr", FSL_IMX7_IOMUXC_LPSR_ADDR,
+    create_unimplemented_device(obj, "iomuxc_lspr", FSL_IMX7_IOMUXC_LPSR_ADDR,
                                 FSL_IMX7_IOMUXC_LPSR_SIZE);
 
     /*
@@ -520,12 +521,12 @@ static void fsl_imx7_realize(DeviceState *dev, Error **errp)
     /*
      * SDMA
      */
-    create_unimplemented_device("sdma", FSL_IMX7_SDMA_ADDR, FSL_IMX7_SDMA_SIZE);
+    create_unimplemented_device(obj, "sdma", FSL_IMX7_SDMA_ADDR, FSL_IMX7_SDMA_SIZE);
 
     /*
      * CAAM
      */
-    create_unimplemented_device("caam", FSL_IMX7_CAAM_ADDR, FSL_IMX7_CAAM_SIZE);
+    create_unimplemented_device(obj, "caam", FSL_IMX7_CAAM_ADDR, FSL_IMX7_CAAM_SIZE);
 
     /*
      * PWMs
@@ -539,7 +540,7 @@ static void fsl_imx7_realize(DeviceState *dev, Error **errp)
         };
 
         snprintf(name, NAME_SIZE, "pwm%d", i);
-        create_unimplemented_device(name, FSL_IMX7_PWMn_ADDR[i],
+        create_unimplemented_device(obj, name, FSL_IMX7_PWMn_ADDR[i],
                                     FSL_IMX7_PWMn_SIZE);
     }
 
@@ -553,7 +554,7 @@ static void fsl_imx7_realize(DeviceState *dev, Error **errp)
         };
 
         snprintf(name, NAME_SIZE, "can%d", i);
-        create_unimplemented_device(name, FSL_IMX7_CANn_ADDR[i],
+        create_unimplemented_device(obj, name, FSL_IMX7_CANn_ADDR[i],
                                     FSL_IMX7_CANn_SIZE);
     }
 
@@ -568,14 +569,14 @@ static void fsl_imx7_realize(DeviceState *dev, Error **errp)
         };
 
         snprintf(name, NAME_SIZE, "sai%d", i);
-        create_unimplemented_device(name, FSL_IMX7_SAIn_ADDR[i],
+        create_unimplemented_device(obj, name, FSL_IMX7_SAIn_ADDR[i],
                                     FSL_IMX7_SAIn_SIZE);
     }
 
     /*
      * OCOTP
      */
-    create_unimplemented_device("ocotp", FSL_IMX7_OCOTP_ADDR,
+    create_unimplemented_device(obj, "ocotp", FSL_IMX7_OCOTP_ADDR,
                                 FSL_IMX7_OCOTP_SIZE);
 
     /*
@@ -638,7 +639,7 @@ static void fsl_imx7_realize(DeviceState *dev, Error **errp)
         sysbus_connect_irq(SYS_BUS_DEVICE(&s->usb[i]), 0, irq);
 
         snprintf(name, NAME_SIZE, "usbmisc%d", i);
-        create_unimplemented_device(name, FSL_IMX7_USBMISCn_ADDR[i],
+        create_unimplemented_device(obj, name, FSL_IMX7_USBMISCn_ADDR[i],
                                     FSL_IMX7_USBMISCn_SIZE);
     }
 
@@ -652,37 +653,37 @@ static void fsl_imx7_realize(DeviceState *dev, Error **errp)
         };
 
         snprintf(name, NAME_SIZE, "adc%d", i);
-        create_unimplemented_device(name, FSL_IMX7_ADCn_ADDR[i],
+        create_unimplemented_device(obj, name, FSL_IMX7_ADCn_ADDR[i],
                                     FSL_IMX7_ADCn_SIZE);
     }
 
     /*
      * LCD
      */
-    create_unimplemented_device("lcdif", FSL_IMX7_LCDIF_ADDR,
+    create_unimplemented_device(obj, "lcdif", FSL_IMX7_LCDIF_ADDR,
                                 FSL_IMX7_LCDIF_SIZE);
 
     /*
      * DMA APBH
      */
-    create_unimplemented_device("dma-apbh", FSL_IMX7_DMA_APBH_ADDR,
+    create_unimplemented_device(obj, "dma-apbh", FSL_IMX7_DMA_APBH_ADDR,
                                 FSL_IMX7_DMA_APBH_SIZE);
     /*
      * PCIe PHY
      */
-    create_unimplemented_device("pcie-phy", FSL_IMX7_PCIE_PHY_ADDR,
+    create_unimplemented_device(obj, "pcie-phy", FSL_IMX7_PCIE_PHY_ADDR,
                                 FSL_IMX7_PCIE_PHY_SIZE);
 
     /*
      * CSU
      */
-    create_unimplemented_device("csu", FSL_IMX7_CSU_ADDR,
+    create_unimplemented_device(obj, "csu", FSL_IMX7_CSU_ADDR,
                                 FSL_IMX7_CSU_SIZE);
 
     /*
      * TZASC
      */
-    create_unimplemented_device("tzasc", FSL_IMX7_TZASC_ADDR,
+    create_unimplemented_device(obj, "tzasc", FSL_IMX7_TZASC_ADDR,
                                 FSL_IMX7_TZASC_SIZE);
 
     /*
hw/arm/fsl-imx8mm.c +1 -1
index 875e92bb34..a38298c4a6 100644
@@ -669,7 +669,7 @@ static void fsl_imx8mm_realize(DeviceState *dev, Error **errp)
             break;
 
         default:
-            create_unimplemented_device(fsl_imx8mm_memmap[i].name,
+            create_unimplemented_device(OBJECT(dev), fsl_imx8mm_memmap[i].name,
                                         fsl_imx8mm_memmap[i].addr,
                                         fsl_imx8mm_memmap[i].size);
             break;
hw/arm/fsl-imx8mp.c +1 -1
index bcd91739d9..c5bace6605 100644
@@ -738,7 +738,7 @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp)
             break;
 
         default:
-            create_unimplemented_device(fsl_imx8mp_memmap[i].name,
+            create_unimplemented_device(OBJECT(dev), fsl_imx8mp_memmap[i].name,
                                         fsl_imx8mp_memmap[i].addr,
                                         fsl_imx8mp_memmap[i].size);
             break;
hw/arm/max78000_soc.c +53 -52

124 lines not on this page · raw message

hw/arm/mps2-tz.c +4 -3
index 17945d2b71..32e3db1134 100644
@@ -800,6 +800,7 @@ static uint32_t boot_ram_size(MPS2TZMachineState *mms)
 
 static void mps2tz_common_init(MachineState *machine)
 {
+    Object *obj = OBJECT(machine);
     MPS2TZMachineState *mms = MPS2TZ_MACHINE(machine);
     MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_GET_CLASS(mms);
     MachineClass *mc = MACHINE_GET_CLASS(machine);
@@ -1193,11 +1194,11 @@ static void mps2tz_common_init(MachineState *machine)
                                                      "cfg_sec_resp", 0));
     }
 
-    create_unimplemented_device("FPGA NS PC", 0x48007000, 0x1000);
+    create_unimplemented_device(obj, "FPGA NS PC", 0x48007000, 0x1000);
 
     if (mmc->fpga_type == FPGA_AN547) {
-        create_unimplemented_device("U55 timing adapter 0", 0x48102000, 0x1000);
-        create_unimplemented_device("U55 timing adapter 1", 0x48103000, 0x1000);
+        create_unimplemented_device(obj, "U55 timing adapter 0", 0x48102000, 0x1000);
+        create_unimplemented_device(obj, "U55 timing adapter 1", 0x48103000, 0x1000);
     }
 
     create_non_mpc_ram(mms);
hw/arm/mps2.c +14 -13
index 2edd222674..23a814e4e4 100644
@@ -135,6 +135,7 @@ static void make_ram_alias(MemoryRegion *mr, const char *name,
 
 static void mps2_common_init(MachineState *machine)
 {
+    Object *obj = OBJECT(machine);
     MPS2MachineState *mms = MPS2_MACHINE(machine);
     MPS2MachineClass *mmc = MPS2_MACHINE_GET_CLASS(machine);
     MemoryRegion *system_memory = get_system_memory();
@@ -246,25 +247,25 @@ static void mps2_common_init(MachineState *machine)
                              OBJECT(system_memory), &error_abort);
     sysbus_realize(SYS_BUS_DEVICE(&mms->armv7m), &error_fatal);
 
-    create_unimplemented_device("zbtsmram mirror", 0x00400000, 0x00400000);
-    create_unimplemented_device("RESERVED 1", 0x00800000, 0x00800000);
-    create_unimplemented_device("Block RAM", 0x01000000, 0x00010000);
-    create_unimplemented_device("RESERVED 2", 0x01010000, 0x1EFF0000);
-    create_unimplemented_device("RESERVED 3", 0x20800000, 0x00800000);
-    create_unimplemented_device("PSRAM", 0x21000000, 0x01000000);
+    create_unimplemented_device(obj, "zbtsmram mirror", 0x00400000, 0x00400000);
+    create_unimplemented_device(obj, "RESERVED 1", 0x00800000, 0x00800000);
+    create_unimplemented_device(obj, "Block RAM", 0x01000000, 0x00010000);
+    create_unimplemented_device(obj, "RESERVED 2", 0x01010000, 0x1EFF0000);
+    create_unimplemented_device(obj, "RESERVED 3", 0x20800000, 0x00800000);
+    create_unimplemented_device(obj, "PSRAM", 0x21000000, 0x01000000);
     /* These three ranges all cover multiple devices; we may implement
      * some of them below (in which case the real device takes precedence
      * over the unimplemented-region mapping).
      */
-    create_unimplemented_device("CMSDK APB peripheral region @0x40000000",
+    create_unimplemented_device(obj, "CMSDK APB peripheral region @0x40000000",
                                 0x40000000, 0x00010000);
-    create_unimplemented_device("CMSDK AHB peripheral region @0x40010000",
+    create_unimplemented_device(obj, "CMSDK AHB peripheral region @0x40010000",
                                 0x40010000, 0x00010000);
-    create_unimplemented_device("Extra peripheral region @0x40020000",
+    create_unimplemented_device(obj, "Extra peripheral region @0x40020000",
                                 0x40020000, 0x00010000);
 
-    create_unimplemented_device("RESERVED 4", 0x40030000, 0x001D0000);
-    create_unimplemented_device("VGA", 0x41000000, 0x0200000);
+    create_unimplemented_device(obj, "RESERVED 4", 0x40030000, 0x001D0000);
+    create_unimplemented_device(obj, "VGA", 0x41000000, 0x0200000);
 
     switch (mmc->fpga_type) {
     case FPGA_AN385:
@@ -362,7 +363,7 @@ static void mps2_common_init(MachineState *machine)
     for (i = 0; i < 4; i++) {
         static const hwaddr gpiobase[] = {0x40010000, 0x40011000,
                                           0x40012000, 0x40013000};
-        create_unimplemented_device("cmsdk-ahb-gpio", gpiobase[i], 0x1000);
+        create_unimplemented_device(obj, "cmsdk-ahb-gpio", gpiobase[i], 0x1000);
     }
 
     /* CMSDK APB subsystem */
@@ -458,7 +459,7 @@ static void mps2_common_init(MachineState *machine)
             qbus_mark_full(qbus);
         }
     }
-    create_unimplemented_device("i2s", 0x40024000, 0x400);
+    create_unimplemented_device(obj, "i2s", 0x40024000, 0x400);
 
     /* In hardware this is a LAN9220; the LAN9118 is software compatible
      * except that it doesn't support the checksum-offload feature.
hw/arm/mps3r.c +5 -5
index 8e249c9b9d..4d432de6ba 100644
@@ -458,7 +458,7 @@ static void mps3r_common_init(MachineState *machine)
     for (int i = 0; i < 4; i++) {
         /* CMSDK GPIO controllers */
         g_autofree char *s = g_strdup_printf("gpio%d", i);
-        create_unimplemented_device(s, 0xe0000000 + i * 0x1000, 0x1000);
+        create_unimplemented_device(OBJECT(machine), s, 0xe0000000 + i * 0x1000, 0x1000);
     }
 
     object_initialize_child(OBJECT(mms), "watchdog", &mms->watchdog,
@@ -526,7 +526,7 @@ static void mps3r_common_init(MachineState *machine)
     sysbus_realize(SYS_BUS_DEVICE(&mms->scc), &error_fatal);
     sysbus_mmio_map(SYS_BUS_DEVICE(&mms->scc), 0, 0xe0200000);
 
-    create_unimplemented_device("i2s-audio", 0xe0201000, 0x1000);
+    create_unimplemented_device(OBJECT(machine), "i2s-audio", 0xe0201000, 0x1000);
 
     object_initialize_child(OBJECT(mms), "fpgaio", &mms->fpgaio,
                             TYPE_MPS2_FPGAIO);
@@ -537,7 +537,7 @@ static void mps3r_common_init(MachineState *machine)
     sysbus_realize(SYS_BUS_DEVICE(&mms->fpgaio), &error_fatal);
     sysbus_mmio_map(SYS_BUS_DEVICE(&mms->fpgaio), 0, 0xe0202000);
 
-    create_unimplemented_device("clcd", 0xe0209000, 0x1000);
+    create_unimplemented_device(OBJECT(machine), "clcd", 0xe0209000, 0x1000);
 
     object_initialize_child(OBJECT(mms), "rtc", &mms->rtc, TYPE_PL031);
     sysbus_realize(SYS_BUS_DEVICE(&mms->rtc), &error_fatal);
@@ -552,8 +552,8 @@ static void mps3r_common_init(MachineState *machine)
     lan9118_init(OBJECT(machine), 0xe0300000,
                  qdev_get_gpio_in(gicdev, 18));
 
-    create_unimplemented_device("usb", 0xe0301000, 0x1000);
-    create_unimplemented_device("qspi-write-config", 0xe0600000, 0x1000);
+    create_unimplemented_device(OBJECT(machine), "usb", 0xe0301000, 0x1000);
+    create_unimplemented_device(OBJECT(machine), "qspi-write-config", 0xe0600000, 0x1000);
 
     mms->bootinfo.ram_size = machine->ram_size;
     mms->bootinfo.board_id = -1;
hw/arm/msf2-soc.c +10 -10
index 76eba752bd..c03778c439 100644
@@ -210,16 +210,16 @@ static void m2sxxx_soc_realize(DeviceState *dev_soc, Error **errp)
                        qdev_get_gpio_in(armv7m, MSF2_EMAC_IRQ));
 
     /* Below devices are not modelled yet. */
-    create_unimplemented_device("i2c_0", 0x40002000, 0x1000);
-    create_unimplemented_device("dma", 0x40003000, 0x1000);
-    create_unimplemented_device("watchdog", 0x40005000, 0x1000);
-    create_unimplemented_device("i2c_1", 0x40012000, 0x1000);
-    create_unimplemented_device("gpio", 0x40013000, 0x1000);
-    create_unimplemented_device("hs-dma", 0x40014000, 0x1000);
-    create_unimplemented_device("can", 0x40015000, 0x1000);
-    create_unimplemented_device("rtc", 0x40017000, 0x1000);
-    create_unimplemented_device("apb_config", 0x40020000, 0x10000);
-    create_unimplemented_device("usb", 0x40043000, 0x1000);
+    create_unimplemented_device(OBJECT(dev_soc), "i2c_0", 0x40002000, 0x1000);
+    create_unimplemented_device(OBJECT(dev_soc), "dma", 0x40003000, 0x1000);
+    create_unimplemented_device(OBJECT(dev_soc), "watchdog", 0x40005000, 0x1000);
+    create_unimplemented_device(OBJECT(dev_soc), "i2c_1", 0x40012000, 0x1000);
+    create_unimplemented_device(OBJECT(dev_soc), "gpio", 0x40013000, 0x1000);
+    create_unimplemented_device(OBJECT(dev_soc), "hs-dma", 0x40014000, 0x1000);
+    create_unimplemented_device(OBJECT(dev_soc), "can", 0x40015000, 0x1000);
+    create_unimplemented_device(OBJECT(dev_soc), "rtc", 0x40017000, 0x1000);
+    create_unimplemented_device(OBJECT(dev_soc), "apb_config", 0x40020000, 0x10000);
+    create_unimplemented_device(OBJECT(dev_soc), "usb", 0x40043000, 0x1000);
 }
 
 static const Property m2sxxx_soc_properties[] = {
hw/arm/npcm7xx.c +46 -45

121 lines not on this page · raw message

hw/arm/npcm8xx.c +73 -72

175 lines not on this page · raw message

hw/arm/nrf51_soc.c +2 -2
index 8d8ea71da4..f75b742242 100644
@@ -171,9 +171,9 @@ static void nrf51_soc_realize(DeviceState *dev_soc, Error **errp)
     memory_region_add_subregion_overlap(&s->container,
                                         NRF51_IOMEM_BASE, &s->clock, -1);
 
-    create_unimplemented_device("nrf51_soc.io", NRF51_IOMEM_BASE,
+    create_unimplemented_device(OBJECT(dev_soc), "nrf51_soc.io", NRF51_IOMEM_BASE,
                                 NRF51_IOMEM_SIZE);
-    create_unimplemented_device("nrf51_soc.private",
+    create_unimplemented_device(OBJECT(dev_soc), "nrf51_soc.private",
                                 NRF51_PRIVATE_BASE, NRF51_PRIVATE_SIZE);
 }
 
hw/arm/stellaris.c +6 -6
index b2ff6f4d97..6a732a3c11 100644
@@ -1381,12 +1381,12 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
     /* Add dummy regions for the devices we don't implement yet,
      * so guest accesses don't cause unlogged crashes.
      */
-    create_unimplemented_device("PWM", 0x40028000, 0x1000);
-    create_unimplemented_device("QEI-0", 0x4002c000, 0x1000);
-    create_unimplemented_device("QEI-1", 0x4002d000, 0x1000);
-    create_unimplemented_device("analogue-comparator", 0x4003c000, 0x1000);
-    create_unimplemented_device("hibernation", 0x400fc000, 0x1000);
-    create_unimplemented_device("flash-control", 0x400fd000, 0x1000);
+    create_unimplemented_device(OBJECT(ms), "PWM", 0x40028000, 0x1000);
+    create_unimplemented_device(OBJECT(ms), "QEI-0", 0x4002c000, 0x1000);
+    create_unimplemented_device(OBJECT(ms), "QEI-1", 0x4002d000, 0x1000);
+    create_unimplemented_device(OBJECT(ms), "analogue-comparator", 0x4003c000, 0x1000);
+    create_unimplemented_device(OBJECT(ms), "hibernation", 0x400fc000, 0x1000);
+    create_unimplemented_device(OBJECT(ms), "flash-control", 0x400fd000, 0x1000);
 
     armv7m_load_kernel(ARMV7M(armv7m)->cpu, ms->kernel_filename, 0, flash_size);
 }
hw/arm/stm32f100_soc.c +30 -30

66 lines not on this page · raw message

hw/arm/stm32f405_soc.c +42 -42

90 lines not on this page · raw message

hw/arm/stm32l4x5_soc.c +44 -44

124 lines not on this page · raw message

hw/arm/xilinx_zynq.c +31 -30

104 lines not on this page · raw message

hw/avr/atmega.c +10 -10
index 5eb640f628..b124db001f 100644
@@ -312,7 +312,7 @@ static void atmega_realize(DeviceState *dev, Error **errp)
             continue;
         }
         devname = g_strdup_printf("atmega-gpio-%c", 'a' + (char)i);
-        create_unimplemented_device(devname,
+        create_unimplemented_device(OBJECT(dev), devname,
                                     OFFSET_DATA + mc->dev[idx].addr, 3);
         g_free(devname);
     }
@@ -344,12 +344,12 @@ static void atmega_realize(DeviceState *dev, Error **errp)
             continue;
         }
         if (!mc->dev[idx].is_timer16) {
-            create_unimplemented_device("avr-timer8",
+            create_unimplemented_device(OBJECT(dev), "avr-timer8",
                                         OFFSET_DATA + mc->dev[idx].addr, 5);
-            create_unimplemented_device("avr-timer8-intmask",
+            create_unimplemented_device(OBJECT(dev), "avr-timer8-intmask",
                                         OFFSET_DATA
                                         + mc->dev[idx].intmask_addr, 1);
-            create_unimplemented_device("avr-timer8-intflag",
+            create_unimplemented_device(OBJECT(dev), "avr-timer8-intflag",
                                         OFFSET_DATA
                                         + mc->dev[idx].intflag_addr, 1);
             continue;
@@ -373,12 +373,12 @@ static void atmega_realize(DeviceState *dev, Error **errp)
         g_free(devname);
     }
 
-    create_unimplemented_device("avr-twi",          OFFSET_DATA + 0x0b8, 6);
-    create_unimplemented_device("avr-adc",          OFFSET_DATA + 0x078, 8);
-    create_unimplemented_device("avr-ext-mem-ctrl", OFFSET_DATA + 0x074, 2);
-    create_unimplemented_device("avr-watchdog",     OFFSET_DATA + 0x060, 1);
-    create_unimplemented_device("avr-spi",          OFFSET_DATA + 0x04c, 3);
-    create_unimplemented_device("avr-eeprom",       OFFSET_DATA + 0x03f, 3);
+    create_unimplemented_device(OBJECT(dev), "avr-twi",          OFFSET_DATA + 0x0b8, 6);
+    create_unimplemented_device(OBJECT(dev), "avr-adc",          OFFSET_DATA + 0x078, 8);
+    create_unimplemented_device(OBJECT(dev), "avr-ext-mem-ctrl", OFFSET_DATA + 0x074, 2);
+    create_unimplemented_device(OBJECT(dev), "avr-watchdog",     OFFSET_DATA + 0x060, 1);
+    create_unimplemented_device(OBJECT(dev), "avr-spi",          OFFSET_DATA + 0x04c, 3);
+    create_unimplemented_device(OBJECT(dev), "avr-eeprom",       OFFSET_DATA + 0x03f, 3);
 }
 
 static const Property atmega_props[] = {
hw/loongarch/virt.c +1 -1
index 20a68ebd44..24d8dc6e57 100644
@@ -483,7 +483,7 @@ static void virt_devices_init(DeviceState *pch_pic,
      * There are some invalid guest memory access.
      * Create some unimplemented devices to emulate this.
      */
-    create_unimplemented_device("pci-dma-cfg", 0x1001041c, 0x4);
+    create_unimplemented_device(OBJECT(lvms), "pci-dma-cfg", 0x1001041c, 0x4);
     sysbus_create_simple(OBJECT(lvms), "rtc", "ls7a_rtc", VIRT_RTC_REG_BASE,
                          qdev_get_gpio_in(pch_pic,
                          VIRT_RTC_IRQ - VIRT_GSI_BASE));
hw/microblaze/petalogix_s3adsp1800_mmu.c +1 -1
index 0979d3632b..6986eb7732 100644
@@ -144,7 +144,7 @@ petalogix_s3adsp1800_init(MachineState *machine)
     sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, ETHLITE_BASEADDR);
     sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, irq[ETHLITE_IRQ]);
 
-    create_unimplemented_device("xps_gpio", GPIO_BASEADDR, 0x10000);
+    create_unimplemented_device(OBJECT(machine), "xps_gpio", GPIO_BASEADDR, 0x10000);
 
     microblaze_load_kernel(cpu, endianness == ENDIAN_MODE_LITTLE, ddr_base,
                            ram_size, machine->initrd_filename,
hw/mips/loongson3_virt.c +3 -2
index 99d2016ef1..8d8430562c 100644
@@ -478,6 +478,7 @@ static inline void loongson3_virt_devices_init(MachineState *machine,
 
 static void mips_loongson3_virt_init(MachineState *machine)
 {
+    Object *obj = OBJECT(machine);
     int i;
     long bios_size;
     MIPSCPU *cpu = NULL;
@@ -515,8 +516,8 @@ static void mips_loongson3_virt_init(MachineState *machine)
      * exception when accessing invalid memory. Create some unimplememted
      * devices to emulate this feature.
      */
-    create_unimplemented_device("mmio fallback 0", 0x10000000, 256 * MiB);
-    create_unimplemented_device("mmio fallback 1", 0x30000000, 256 * MiB);
+    create_unimplemented_device(obj, "mmio fallback 0", 0x10000000, 256 * MiB);
+    create_unimplemented_device(obj, "mmio fallback 1", 0x30000000, 256 * MiB);
 
     memory_region_init(iocsr, OBJECT(machine), "loongson3.iocsr", UINT32_MAX);
 
hw/pci-host/bonito.c +7 -7
index 83b328840a..7b4259c0e7 100644
@@ -647,7 +647,7 @@ static void bonito_host_realize(DeviceState *dev, Error **errp)
         g_free(name);
     }
 
-    create_unimplemented_device("pci.io", BONITO_PCIIO_BASE, 1 * MiB);
+    create_unimplemented_device(OBJECT(dev), "pci.io", BONITO_PCIIO_BASE, 1 * MiB);
 }
 
 static void bonito_pci_realize(PCIDevice *dev, Error **errp)
@@ -681,7 +681,7 @@ static void bonito_pci_realize(PCIDevice *dev, Error **errp)
     memory_region_add_subregion(host_mem, BONITO_SPCICONFIG_BASE,
                                 &phb->data_mem);
 
-    create_unimplemented_device("bonito", BONITO_REG_BASE, BONITO_REG_SIZE);
+    create_unimplemented_device(OBJECT(dev), "bonito", BONITO_REG_BASE, BONITO_REG_SIZE);
 
     memory_region_init_io(&s->iomem_ldma, OBJECT(s), &bonito_ldma_ops, s,
                           "ldma", 0x100);
@@ -692,7 +692,7 @@ static void bonito_pci_realize(PCIDevice *dev, Error **errp)
                           "cop", 0x100);
     memory_region_add_subregion(host_mem, 0x1fe00300, &s->iomem_cop);
 
-    create_unimplemented_device("ROMCS", BONITO_FLASH_BASE, 60 * MiB);
+    create_unimplemented_device(OBJECT(dev), "ROMCS", BONITO_FLASH_BASE, 60 * MiB);
 
     /* Map PCI IO Space  0x1fd0 0000 - 0x1fd1 0000 */
     memory_region_init_alias(&s->bonito_pciio, OBJECT(s), "isa_mmio",
@@ -706,17 +706,17 @@ static void bonito_pci_realize(PCIDevice *dev, Error **errp)
                              get_system_io(), 0, 256 * KiB);
     memory_region_add_subregion(host_mem, BONITO_DEV_BASE,
                                 &s->bonito_localio);
-    create_unimplemented_device("IOCS[1]", BONITO_DEV_BASE + 1 * 256 * KiB,
+    create_unimplemented_device(OBJECT(dev), "IOCS[1]", BONITO_DEV_BASE + 1 * 256 * KiB,
                                 256 * KiB);
-    create_unimplemented_device("IOCS[2]", BONITO_DEV_BASE + 2 * 256 * KiB,
+    create_unimplemented_device(OBJECT(dev), "IOCS[2]", BONITO_DEV_BASE + 2 * 256 * KiB,
                                 256 * KiB);
-    create_unimplemented_device("IOCS[3]", BONITO_DEV_BASE + 3 * 256 * KiB,
+    create_unimplemented_device(OBJECT(dev), "IOCS[3]", BONITO_DEV_BASE + 3 * 256 * KiB,
                                 256 * KiB);
 
     memory_region_init_alias(pcimem_alias, NULL, "pci.mem.alias",
                              &bs->pci_mem, 0, BONITO_PCIHI_SIZE);
     memory_region_add_subregion(host_mem, BONITO_PCIHI_BASE, pcimem_alias);
-    create_unimplemented_device("PCI_2",
+    create_unimplemented_device(OBJECT(dev), "PCI_2",
                                 (hwaddr)BONITO_PCIHI_BASE + BONITO_PCIHI_SIZE,
                                 2 * GiB);
 
hw/riscv/k230.c +54 -53

231 lines not on this page · raw message

hw/riscv/microblaze-v-generic.c +5 -5
index fbfdec7ede..7253ae7822 100644
@@ -166,11 +166,11 @@ static void mb_v_generic_init(MachineState *machine)
     sysbus_connect_irq(SYS_BUS_DEVICE(dma), 1, irq[AXIDMA_IRQ1]);
 
     /* unimplemented devices */
-    create_unimplemented_device("gpio", GPIO_BASEADDR, 0x10000);
-    create_unimplemented_device("gpio2", GPIO_BASEADDR2, 0x10000);
-    create_unimplemented_device("gpio3", GPIO_BASEADDR3, 0x10000);
-    create_unimplemented_device("i2c", I2C_BASEADDR, 0x10000);
-    create_unimplemented_device("qspi", QSPI_BASEADDR, 0x10000);
+    create_unimplemented_device(OBJECT(machine), "gpio", GPIO_BASEADDR, 0x10000);
+    create_unimplemented_device(OBJECT(machine), "gpio2", GPIO_BASEADDR2, 0x10000);
+    create_unimplemented_device(OBJECT(machine), "gpio3", GPIO_BASEADDR3, 0x10000);
+    create_unimplemented_device(OBJECT(machine), "i2c", I2C_BASEADDR, 0x10000);
+    create_unimplemented_device(OBJECT(machine), "qspi", QSPI_BASEADDR, 0x10000);
 }
 
 static void mb_v_generic_machine_init(MachineClass *mc)
hw/riscv/microchip_pfsoc.c +27 -27

146 lines not on this page · raw message

hw/riscv/opentitan.c +26 -26

83 lines not on this page · raw message

hw/riscv/sifive_e.c +6 -6
index fb62bc9aca..31cec460b3 100644
@@ -268,19 +268,19 @@ static void sifive_e_soc_realize(DeviceState *dev, Error **errp)
 
     sifive_uart_create(OBJECT(s), sys_mem, memmap[SIFIVE_E_DEV_UART0].base,
         serial_hd(0), qdev_get_gpio_in(DEVICE(s->plic), SIFIVE_E_UART0_IRQ));
-    create_unimplemented_device("riscv.sifive.e.qspi0",
+    create_unimplemented_device(OBJECT(dev), "riscv.sifive.e.qspi0",
         memmap[SIFIVE_E_DEV_QSPI0].base, memmap[SIFIVE_E_DEV_QSPI0].size);
-    create_unimplemented_device("riscv.sifive.e.pwm0",
+    create_unimplemented_device(OBJECT(dev), "riscv.sifive.e.pwm0",
         memmap[SIFIVE_E_DEV_PWM0].base, memmap[SIFIVE_E_DEV_PWM0].size);
     sifive_uart_create(OBJECT(s), sys_mem, memmap[SIFIVE_E_DEV_UART1].base,
         serial_hd(1), qdev_get_gpio_in(DEVICE(s->plic), SIFIVE_E_UART1_IRQ));
-    create_unimplemented_device("riscv.sifive.e.qspi1",
+    create_unimplemented_device(OBJECT(dev), "riscv.sifive.e.qspi1",
         memmap[SIFIVE_E_DEV_QSPI1].base, memmap[SIFIVE_E_DEV_QSPI1].size);
-    create_unimplemented_device("riscv.sifive.e.pwm1",
+    create_unimplemented_device(OBJECT(dev), "riscv.sifive.e.pwm1",
         memmap[SIFIVE_E_DEV_PWM1].base, memmap[SIFIVE_E_DEV_PWM1].size);
-    create_unimplemented_device("riscv.sifive.e.qspi2",
+    create_unimplemented_device(OBJECT(dev), "riscv.sifive.e.qspi2",
         memmap[SIFIVE_E_DEV_QSPI2].base, memmap[SIFIVE_E_DEV_QSPI2].size);
-    create_unimplemented_device("riscv.sifive.e.pwm2",
+    create_unimplemented_device(OBJECT(dev), "riscv.sifive.e.pwm2",
         memmap[SIFIVE_E_DEV_PWM2].base, memmap[SIFIVE_E_DEV_PWM2].size);
 
     /* Flash memory */
hw/riscv/sifive_u.c +3 -3
index 3d60a501dd..aba6716b73 100644
@@ -861,13 +861,13 @@ static void sifive_u_soc_realize(DeviceState *dev, Error **errp)
         }
     }
 
-    create_unimplemented_device("riscv.sifive.u.gem-mgmt",
+    create_unimplemented_device(OBJECT(dev), "riscv.sifive.u.gem-mgmt",
         memmap[SIFIVE_U_DEV_GEM_MGMT].base, memmap[SIFIVE_U_DEV_GEM_MGMT].size);
 
-    create_unimplemented_device("riscv.sifive.u.dmc",
+    create_unimplemented_device(OBJECT(dev), "riscv.sifive.u.dmc",
         memmap[SIFIVE_U_DEV_DMC].base, memmap[SIFIVE_U_DEV_DMC].size);
 
-    create_unimplemented_device("riscv.sifive.u.l2cc",
+    create_unimplemented_device(OBJECT(dev), "riscv.sifive.u.l2cc",
         memmap[SIFIVE_U_DEV_L2CC].base, memmap[SIFIVE_U_DEV_L2CC].size);
 
     sysbus_realize(SYS_BUS_DEVICE(&s->spi0), errp);
hw/riscv/tt_atlantis.c +1 -1
index 6e0a54fe3c..068a0bc542 100644
@@ -556,7 +556,7 @@ static void tt_atlantis_machine_init(MachineState *machine)
      * Create an unimplemented device region so writes don't fault
      * and reads return zero, which keeps Linux happy.
      */
-    create_unimplemented_device("tt-atlantis.uart0",
+    create_unimplemented_device(OBJECT(machine), "tt-atlantis.uart0",
                                 s->memmap[TT_ATL_UART1].base,
                                 s->memmap[TT_ATL_UART1].size);
 
hw/sparc/sun4m.c +4 -4
index 144345d46a..a0d0213d0b 100644
@@ -948,7 +948,7 @@ static void sun4m_hw_init(MachineState *machine)
     }
 
     if (hwdef->sx_base) {
-        create_unimplemented_device("sun-sx", hwdef->sx_base, 0x2000);
+        create_unimplemented_device(OBJECT(machine), "sun-sx", hwdef->sx_base, 0x2000);
     }
 
     dev = qdev_new(OBJECT(machine), "nvram", "sysbus-m48t08");
@@ -1032,16 +1032,16 @@ static void sun4m_hw_init(MachineState *machine)
     if (hwdef->dbri_base) {
         /* ISDN chip with attached CS4215 audio codec */
         /* prom space */
-        create_unimplemented_device("sun-DBRI.prom",
+        create_unimplemented_device(OBJECT(machine), "sun-DBRI.prom",
                                     hwdef->dbri_base + 0x1000, 0x30);
         /* reg space */
-        create_unimplemented_device("sun-DBRI",
+        create_unimplemented_device(OBJECT(machine), "sun-DBRI",
                                     hwdef->dbri_base + 0x10000, 0x100);
     }
 
     if (hwdef->bpp_base) {
         /* parallel port */
-        create_unimplemented_device("sun-bpp", hwdef->bpp_base, 0x20);
+        create_unimplemented_device(OBJECT(machine), "sun-bpp", hwdef->bpp_base, 0x20);
     }
 
     initrd_size = 0;
hw/sparc64/niagara.c +2 -1
index bceda70f2e..8fb9937127 100644
@@ -98,6 +98,7 @@ static void add_rom_or_fail(const char *file, const hwaddr addr)
 /* Niagara hardware initialisation */
 static void niagara_init(MachineState *machine)
 {
+    Object *obj = OBJECT(machine);
     NiagaraBoardState *s = g_new(NiagaraBoardState, 1);
     DriveInfo *dinfo = drive_get(IF_PFLASH, 0, 0);
     MemoryRegion *sysmem = get_system_memory();
@@ -153,7 +154,7 @@ static void niagara_init(MachineState *machine)
     }
     serial_mm_init(OBJECT(machine), sysmem, NIAGARA_UART_BASE, 0, NULL,
                    115200, serial_hd(0), DEVICE_BIG_ENDIAN);
-    create_unimplemented_device("sun4v-iob", NIAGARA_IOBBASE, NIAGARA_IOBSIZE);
+    create_unimplemented_device(obj, "sun4v-iob", NIAGARA_IOBBASE, NIAGARA_IOBSIZE);
     sun4v_rtc_init(OBJECT(machine), NIAGARA_RTC_BASE);
 }
 
include/hw/misc/unimp.h +6 -3
index 5158d29634..afef25671e 100644
@@ -38,15 +38,18 @@ struct UnimplementedDeviceState {
  * use it to cover a large region and then map other devices on top of it
  * if necessary.
  */
-static inline void create_unimplemented_device(const char *name,
+static inline void create_unimplemented_device(Object *parent,
+                                               const char *name,
                                                hwaddr base,
                                                hwaddr size)
 {
-    DeviceState *dev = qdev_new_orphan(TYPE_UNIMPLEMENTED_DEVICE);
+    g_autofree char *id = name[strlen(name) - 1] == ']'
+                          ? g_strdup(name) : g_strdup_printf("%s[*]", name);
+    DeviceState *dev = qdev_new(parent, id, TYPE_UNIMPLEMENTED_DEVICE);
 
     qdev_prop_set_string(dev, "name", name);
     qdev_prop_set_uint64(dev, "size", size);
-    sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
+    sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
 
     sysbus_mmio_map_overlap(SYS_BUS_DEVICE(dev), 0, base, -1000);
 }
Signature · 1 line
2.47.1
#235 lore raw

RFC PATCH v2 78/137 hw/usb: Give -usbdevice and auto-hub devices a QOM parent

In reply to Alexander Graf

The three remaining orphan-creating sites in hw/usb are all command-line and hotplug-adjacent code paths that always run after the machine is up:

usb_claim_port() auto-hub -> child of the USB host controller

                                 (bus->qbus.parent)

usbdevice_create() -> /machine/peripheral-anon, same as
-device without id=
usb_braille_init() -> ditto (a .usbdevice_init callback)

Switch to qdev_new()/qdev_try_new() with an explicit parent and use plain qdev_realize() since the reference is now held by the parent's child<> property.

AI-used-for: code (refactoring)

---
 hw/usb/bus.c        | 15 ++++++++++-----
 hw/usb/dev-serial.c |  3 ++-
 2 files changed, 12 insertions(+), 6 deletions(-)
hw/usb/bus.c +10 -5
index d45cce7666..725b0303b1 100644
@@ -410,9 +410,10 @@ void usb_claim_port(USBDevice *dev, Error **errp)
     } else {
         if (bus->nfree == 1 && strcmp(object_get_typename(OBJECT(dev)), "usb-hub") != 0) {
             /* Create a new hub and chain it on */
-            hub = USB_DEVICE(qdev_try_new_orphan("usb-hub"));
+            hub = USB_DEVICE(qdev_try_new(OBJECT(bus->qbus.parent),
+                                          "auto-hub[*]", "usb-hub"));
             if (hub) {
-                usb_realize_and_unref(hub, bus, NULL);
+                qdev_realize(DEVICE(hub), &bus->qbus, NULL);
             }
         }
         if (bus->nfree == 0) {
@@ -661,13 +662,17 @@ USBDevice *usbdevice_create(const char *driver)
         return NULL;
     }
 
-    dev = f->usbdevice_init ? f->usbdevice_init()
-                            : USB_DEVICE(qdev_new_orphan(f->name));
+    if (f->usbdevice_init) {
+        dev = f->usbdevice_init();
+    } else {
+        dev = USB_DEVICE(qdev_new(machine_get_container("peripheral-anon"),
+                                  "usbdevice[*]", f->name));
+    }
     if (!dev) {
         error_report("Failed to create USB device '%s'", f->name);
         return NULL;
     }
-    if (!usb_realize_and_unref(dev, bus, &err)) {
+    if (!qdev_realize(DEVICE(dev), &bus->qbus, &err)) {
         error_reportf_err(err, "Failed to initialize USB device '%s': ",
                           f->name);
         object_unparent(OBJECT(dev));
hw/usb/dev-serial.c +2 -1
index 81897b2d76..4ae3faf656 100644
@@ -622,7 +622,8 @@ static USBDevice *usb_braille_init(void)
         return NULL;
     }
 
-    dev = USB_DEVICE(qdev_new_orphan("usb-braille"));
+    dev = USB_DEVICE(qdev_new(machine_get_container("peripheral-anon"),
+                              "usbdevice[*]", "usb-braille"));
     qdev_prop_set_chr(&dev->qdev, "chardev", cdrv);
     return dev;
 }
Signature · 1 line
2.47.1
#236 lore raw

RFC PATCH v2 79/137 hw/audio: Give -audio model= devices a QOM parent

In reply to Alexander Graf

audio_model_devices_init() is the '-audio model=' command-line path, so parent the created device under /machine/peripheral-anon like -device without id= would.

The intel-hda .init helper for '-audio model=hda' additionally creates an hda-duplex codec on the controller's HDA bus; the codec is a natural child of the controller device it just spawned.

Both sites drop the extra unref: the child<> property now holds the reference.

AI-used-for: code (refactoring)

---
 hw/audio/intel-hda.c | 4 ++--
 hw/audio/model.c     | 5 +++--
 2 files changed, 5 insertions(+), 4 deletions(-)
hw/audio/intel-hda.c +2 -2
index cd4743a405..f51c98511a 100644
@@ -1313,9 +1313,9 @@ static void intel_hda_and_codec_init(const char *audiodev)
     intel_hda = qdev_device_add_from_qdict(props, false, &error_fatal);
     hdabus = QLIST_FIRST(&intel_hda->child_bus);
 
-    codec = qdev_new_orphan("hda-duplex");
+    codec = qdev_new(OBJECT(intel_hda), "codec", "hda-duplex");
     qdev_prop_set_string(codec, "audiodev", audiodev);
-    qdev_realize_and_unref(codec, hdabus, &error_fatal);
+    qdev_realize(codec, hdabus, &error_fatal);
     object_unref(intel_hda);
 }
 
hw/audio/model.c +3 -2
index bd8ca35153..308b899459 100644
@@ -110,10 +110,11 @@ void audio_model_init(void)
     }
 
     if (c->typename) {
-        DeviceState *dev = qdev_new_orphan(c->typename);
+        DeviceState *dev = qdev_new(machine_get_container("peripheral-anon"),
+                                    "audio[*]", c->typename);
         BusState *bus = qdev_find_default_bus(DEVICE_GET_CLASS(dev), &error_fatal);
         qdev_prop_set_string(dev, "audiodev", audiodev_id);
-        qdev_realize_and_unref(dev, bus, &error_fatal);
+        qdev_realize(dev, bus, &error_fatal);
     } else {
         c->init(audiodev_id);
     }
Signature · 1 line
2.47.1
#237 lore raw

RFC PATCH v2 80/137 hw/xen: Give xenstore-driven backend devices a QOM parent

In reply to Alexander Graf

The XenBackendInfo .create callbacks (vif, console, vbd) create a XenDevice in response to xenstore hotplug events. The lifetime owner is the xen-bridge device that hosts the XenBus, so parent each device there. The failure paths already call object_unparent() so nothing else changes; the reference previously dropped by qdev_realize_and_unref() is now the parent's child<> property.

AI-used-for: code (refactoring)

---
 hw/block/xen-block.c  | 5 +++--
 hw/char/xen_console.c | 5 +++--
 hw/net/xen_nic.c      | 5 +++--
 3 files changed, 9 insertions(+), 6 deletions(-)
hw/block/xen-block.c +3 -2
index 9dd69faa02..46d94a9a95 100644
@@ -1074,7 +1074,8 @@ static void xen_block_device_create(XenBackendInstance *backend,
         goto fail;
     }
 
-    xendev = XEN_DEVICE(qdev_new_orphan(type));
+    xendev = XEN_DEVICE(qdev_new(OBJECT(BUS(xenbus)->parent), "vbd[*]",
+                                 type));
     blockdev = XEN_BLOCK_DEVICE(xendev);
 
     if (!object_property_set_str(OBJECT(xendev), "vdev", vdev,
@@ -1099,7 +1100,7 @@ static void xen_block_device_create(XenBackendInstance *backend,
     blockdev->iothread = iothread;
     blockdev->drive = drive;
 
-    if (!qdev_realize_and_unref(DEVICE(xendev), BUS(xenbus), errp)) {
+    if (!qdev_realize(DEVICE(xendev), BUS(xenbus), errp)) {
         error_prepend(errp, "realization of device %s failed: ", type);
         goto fail;
     }
hw/char/xen_console.c +3 -2
index cd440b82f4..40449b34e8 100644
@@ -562,7 +562,8 @@ static void xen_console_device_create(XenBackendInstance *backend,
         goto fail;
     }
 
-    xendev = XEN_DEVICE(qdev_new_orphan(TYPE_XEN_CONSOLE_DEVICE));
+    xendev = XEN_DEVICE(qdev_new(OBJECT(BUS(xenbus)->parent), "console[*]",
+                                 TYPE_XEN_CONSOLE_DEVICE));
     con = XEN_CONSOLE_DEVICE(xendev);
 
     con->dev = number;
@@ -610,7 +611,7 @@ static void xen_console_device_create(XenBackendInstance *backend,
         goto fail;
     }
 
-    if (qdev_realize_and_unref(DEVICE(xendev), BUS(xenbus), errp)) {
+    if (qdev_realize(DEVICE(xendev), BUS(xenbus), errp)) {
         xen_backend_set_device(backend, xendev);
         goto done;
     }
hw/net/xen_nic.c +3 -2
index 212281aac7..ff748ae070 100644
@@ -619,13 +619,14 @@ static void xen_net_device_create(XenBackendInstance *backend,
         goto fail;
     }
 
-    xendev = XEN_DEVICE(qdev_new_orphan(TYPE_XEN_NET_DEVICE));
+    xendev = XEN_DEVICE(qdev_new(OBJECT(BUS(xenbus)->parent), "vif[*]",
+                                 TYPE_XEN_NET_DEVICE));
     net = XEN_NET_DEVICE(xendev);
 
     net->dev = number;
     memcpy(&net->conf.macaddr, &mac, sizeof(mac));
 
-    if (qdev_realize_and_unref(DEVICE(xendev), BUS(xenbus), errp)) {
+    if (qdev_realize(DEVICE(xendev), BUS(xenbus), errp)) {
         xen_backend_set_device(backend, xendev);
         return;
     }
Signature · 1 line
2.47.1
#238 lore raw

RFC PATCH v2 81/137 hw/nitro: Give the vsock bridge a QOM parent

In reply to Alexander Graf

nitro_vsock_bridge_create() was using qdev_set_id() to slot the bridge under /machine/peripheral. The bridge is a board-owned singleton created from nitro_machine_init(), so make it a plain child of the machine and drop the qdev_set_id() indirection.

The heartbeat device that hangs off the bridge is already a child<> of it, so the composition tree becomes:

/machine/nitro-vsock (nitro-vsock-bridge) /machine/nitro-vsock/heartbeat (nitro-heartbeat)

AI-used-for: code (refactoring)

---
 hw/nitro/machine.c                 | 2 +-
 hw/nitro/nitro-vsock-bus.c         | 9 ++++-----
 include/hw/nitro/nitro-vsock-bus.h | 2 +-
 3 files changed, 6 insertions(+), 7 deletions(-)
hw/nitro/machine.c +1 -1
index 6b61de911f..e522eae5ba 100644
@@ -194,7 +194,7 @@ static void nitro_machine_init(MachineState *machine)
                         MEMTXATTRS_UNSPECIFIED, eif_data, eif_size);
 
     if (defaults_enabled()) {
-        NitroVsockBridge *bridge = nitro_vsock_bridge_create();
+        NitroVsockBridge *bridge = nitro_vsock_bridge_create(OBJECT(machine));
         DeviceState *dev;
 
         /* Nitro Enclaves require a heartbeat device. Provide one. */
hw/nitro/nitro-vsock-bus.c +4 -5
index f7540eaa54..2c4b66931f 100644
@@ -20,7 +20,6 @@
 
 #include "qemu/osdep.h"
 #include "qapi/error.h"
-#include "monitor/qdev.h"
 #include "hw/core/sysbus.h"
 #include "hw/nitro/nitro-vsock-bus.h"
 
@@ -46,12 +45,12 @@ void nitro_vsock_bridge_start_enclave(NitroVsockBridge *bridge,
     }
 }
 
-NitroVsockBridge *nitro_vsock_bridge_create(void)
+NitroVsockBridge *nitro_vsock_bridge_create(Object *parent)
 {
-    DeviceState *dev = qdev_new_orphan(TYPE_NITRO_VSOCK_BRIDGE);
+    DeviceState *dev = qdev_new(parent, "nitro-vsock",
+                                TYPE_NITRO_VSOCK_BRIDGE);
 
-    qdev_set_id(dev, g_strdup("nitro-vsock"), &error_fatal);
-    sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
+    sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
 
     return NITRO_VSOCK_BRIDGE(dev);
 }
include/hw/nitro/nitro-vsock-bus.h +1 -1
index 064260aa41..36f4dde78f 100644
@@ -50,7 +50,7 @@ struct NitroVsockDeviceClass {
 /*
  * Machine helper to create the Nitro vsock bridge sysbus device.
  */
-NitroVsockBridge *nitro_vsock_bridge_create(void);
+NitroVsockBridge *nitro_vsock_bridge_create(Object *parent);
 
 /*
  * Find the Nitro vsock bridge on the sysbus.
Signature · 1 line
2.47.1
#239 lore raw

RFC PATCH v2 82/137 hw/isa: Give the isabus-bridge a QOM parent

In reply to Alexander Graf

isa_bus_new(NULL, ...) implicitly created a sysbus "isabus-bridge" and put the ISA bus on it. That bridge ended up under /machine/unattached, which this series is deleting.

Split out an explicit isa_bus_new_bridge(parent, ...) helper for the five boards that don't already have a south-bridge device to own the ISA bus, and make plain isa_bus_new() require a non-NULL device. Callers own the bridge in the composition tree:

  hw/i386/microvm.c   OBJECT(mms)
  hw/i386/isapc.c     OBJECT(machine)
  hw/mips/jazz.c      OBJECT(machine)
  hw/hppa/machine.c   parent (already threaded)
  hw/ppc/pnv_lpc.c    OBJECT(lpc)   -- the LPC controller

AI-used-for: code (refactoring)

---
 hw/hppa/machine.c    |  2 +-
 hw/i386/isapc.c      |  2 +-
 hw/i386/microvm.c    |  2 +-
 hw/isa/isa-bus.c     | 21 +++++++++++----------
 hw/mips/jazz.c       |  2 +-
 hw/ppc/pnv_lpc.c     |  4 ++--
 include/hw/isa/isa.h |  2 ++
 7 files changed, 19 insertions(+), 16 deletions(-)
hw/hppa/machine.c +1 -1
index 002f4299cc..d52f27c51c 100644
@@ -108,7 +108,7 @@ static ISABus *hppa_isa_bus(Object *parent, hwaddr addr)
                           NULL, "isa-io", 0x800);
     memory_region_add_subregion(get_system_memory(), addr, isa_region);
 
-    isa_bus = isa_bus_new(NULL, get_system_memory(), isa_region,
+    isa_bus = isa_bus_new_bridge(parent, get_system_memory(), isa_region,
                           &error_abort);
     isa_irqs = i8259_init(parent, isa_bus, NULL);
     isa_bus_register_input_irqs(isa_bus, isa_irqs);
hw/i386/isapc.c +1 -1
index 842ae94acb..e8d5767b80 100644
@@ -108,7 +108,7 @@ static void pc_init_isa(MachineState *machine)
 
     gsi_state = pc_gsi_create(&x86ms->gsi, false);
 
-    isa_bus = isa_bus_new(NULL, system_memory, system_io,
+    isa_bus = isa_bus_new_bridge(OBJECT(machine), system_memory, system_io,
                           &error_abort);
     isa_bus_register_input_irqs(isa_bus, x86ms->gsi);
 
hw/i386/microvm.c +1 -1
index 8c61106516..aa0e1ef155 100644
@@ -171,7 +171,7 @@ static void microvm_devices_init(MicrovmMachineState *mms)
     x86ms->gsi = qemu_allocate_irqs(gsi_handler, gsi_state,
                                     IOAPIC_NUM_PINS * ioapics);
 
-    isa_bus = isa_bus_new(NULL, get_system_memory(), get_system_io(),
+    isa_bus = isa_bus_new_bridge(OBJECT(mms), get_system_memory(), get_system_io(),
                           &error_abort);
     isa_bus_register_input_irqs(isa_bus, x86ms->gsi);
 
hw/isa/isa-bus.c +11 -10
index fb20c43869..7a6a595ce7 100644
@@ -52,28 +52,29 @@ static const TypeInfo isa_bus_info = {
 ISABus *isa_bus_new(DeviceState *dev, MemoryRegion* address_space,
                     MemoryRegion *address_space_io, Error **errp)
 {
-    DeviceState *bridge = NULL;
-
     if (isabus) {
         error_setg(errp, "Can't create a second ISA bus");
         return NULL;
     }
-    if (!dev) {
-        bridge = qdev_new_orphan("isabus-bridge");
-        dev = bridge;
-    }
+    g_assert(dev);
 
     isabus = ISA_BUS(qbus_new(TYPE_ISA_BUS, dev, NULL));
     isabus->address_space = address_space;
     isabus->address_space_io = address_space_io;
 
-    if (bridge) {
-        sysbus_realize_and_unref(SYS_BUS_DEVICE(bridge), &error_fatal);
-    }
-
     return isabus;
 }
 
+ISABus *isa_bus_new_bridge(Object *parent, MemoryRegion *address_space,
+                           MemoryRegion *address_space_io, Error **errp)
+{
+    DeviceState *bridge = qdev_new(parent, "isabus-bridge", "isabus-bridge");
+    ISABus *bus = isa_bus_new(bridge, address_space, address_space_io, errp);
+
+    sysbus_realize(SYS_BUS_DEVICE(bridge), &error_fatal);
+    return bus;
+}
+
 void isa_bus_register_input_irqs(ISABus *bus, qemu_irq *irqs_in)
 {
     bus->irqs_in = irqs_in;
hw/mips/jazz.c +1 -1
index 23d717d96a..8c52608913 100644
@@ -283,7 +283,7 @@ static void mips_jazz_init(MachineState *machine,
     memory_region_init(isa_mem, NULL, "isa-mem", 0x01000000);
     memory_region_add_subregion(address_space, 0x90000000, isa_io);
     memory_region_add_subregion(address_space, 0x91000000, isa_mem);
-    isa_bus = isa_bus_new(NULL, isa_mem, isa_io, &error_abort);
+    isa_bus = isa_bus_new_bridge(OBJECT(machine), isa_mem, isa_io, &error_abort);
 
     /* ISA devices */
     i8259 = i8259_init(OBJECT(machine), isa_bus, env->irq[4]);
hw/ppc/pnv_lpc.c +2 -2
index d1357dd359..6ae228088f 100644
@@ -972,11 +972,11 @@ ISABus *pnv_lpc_isa_create(PnvLpcController *lpc, bool use_cpld, Error **errp)
     qemu_irq *irqs;
     qemu_irq_handler handler;
 
-    /* let isa_bus_new() create its own bridge on SysBus otherwise
+    /* let isa_bus_new_bridge() create the bridge as a child of the LPC;
      * devices specified on the command line won't find the bus and
      * will fail to create.
      */
-    isa_bus = isa_bus_new(NULL, &lpc->isa_mem, &lpc->isa_io, &local_err);
+    isa_bus = isa_bus_new_bridge(OBJECT(lpc), &lpc->isa_mem, &lpc->isa_io, &local_err);
     if (local_err) {
         error_propagate(errp, local_err);
         return NULL;
include/hw/isa/isa.h +2 -0
index 9e35d88b1e..79bfe16361 100644
@@ -69,6 +69,8 @@ struct ISADevice {
 
 ISABus *isa_bus_new(DeviceState *dev, MemoryRegion *address_space,
                     MemoryRegion *address_space_io, Error **errp);
+ISABus *isa_bus_new_bridge(Object *parent, MemoryRegion *address_space,
+                           MemoryRegion *address_space_io, Error **errp);
 void isa_bus_register_input_irqs(ISABus *bus, qemu_irq *irqs_in);
 void isa_bus_dma(ISABus *bus, IsaDma *dma8, IsaDma *dma16);
 IsaDma *isa_bus_get_dma(ISABus *bus, int nchan);
Signature · 1 line
2.47.1
#240 lore raw

RFC PATCH v2 83/137 net, target/mips: Give -nic and CPU-with-clock helpers a QOM parent

In reply to Alexander Graf

qemu_create_nic_device() and qemu_create_nic_bus_devices() are the board-side and bus-side halves of the '-nic' command-line path. Thread an explicit parent through the former (each of the seven callers now supplies the machine or SoC that owns the on-board NIC) and let the latter place devices under /machine/peripheral-anon like -device does. s390 was already parenting the returned device by hand; drop that now-redundant open-coding.

mips_cpu_create_with_clock() likewise gains an explicit parent; the four MIPS boards pass the machine and name the CPU cpu[*]. xtensa_cpu_create_with_clock() has no callers, so just remove it.

For linux-user/bsd-user there is no machine and hence no composition tree; open-code object_new()+qdev_realize() where cpu_create_orphan() used to be.

While at it, fix a stale doc reference in migration.c.

AI-used-for: code (refactoring)

---
 bsd-user/main.c            |  3 ++-
 hw/arm/exynos4_boards.c    |  4 ++--
 hw/hppa/machine.c          |  4 ++--
 hw/m68k/mcf5208.c          |  4 ++--
 hw/mips/fuloong2e.c        |  3 ++-
 hw/mips/jazz.c             |  2 +-
 hw/mips/loongson3_virt.c   |  3 ++-
 hw/mips/malta.c            |  2 +-
 hw/or1k/or1k-sim.c         |  4 ++--
 hw/s390x/s390-virtio-ccw.c |  8 +++-----
 hw/vmapple/vmapple.c       |  5 +++--
 hw/xtensa/xtfpga.c         |  4 ++--
 include/net/net.h          |  5 ++++-
 linux-user/main.c          |  6 ++++--
 migration/migration.c      |  2 +-
 net/net.c                  | 10 ++++++----
 target/mips/cpu.c          |  5 +++--
 target/mips/cpu.h          |  3 ++-
 target/xtensa/cpu.c        | 11 -----------
 target/xtensa/cpu.h        |  2 --
 20 files changed, 44 insertions(+), 46 deletions(-)
bsd-user/main.c +2 -1
index 5269ea42a5..6dbd1cc1ae 100644
@@ -474,7 +474,8 @@ int main(int argc, char **argv)
     set_preferred_target_page_bits(ctz32(host_page_size));
     finalize_target_page_bits();
 
-    cpu = cpu_create_orphan(cpu_type);
+    cpu = CPU(object_new(cpu_type));
+    qdev_realize(DEVICE(cpu), NULL, &error_fatal);
     env = cpu_env(cpu);
     cpu_reset(cpu);
     thread_cpu = cpu;
hw/arm/exynos4_boards.c +2 -2
index 1b8c9b618f..dce2c24860 100644
@@ -78,11 +78,11 @@ static void lan9215_init(uint32_t base, qemu_irq irq)
     SysBusDevice *s;
 
     /* This should be a 9215 but the 9118 is close enough */
-    dev = qemu_create_nic_device(TYPE_LAN9118, true, NULL);
+    dev = qemu_create_nic_device(qdev_get_machine(), "lan9215", TYPE_LAN9118, true, NULL);
     if (dev) {
         qdev_prop_set_uint32(dev, "mode_16bit", 1);
         s = SYS_BUS_DEVICE(dev);
-        sysbus_realize_and_unref(s, &error_fatal);
+        sysbus_realize(s, &error_fatal);
         sysbus_mmio_map(s, 0, base);
         sysbus_connect_irq(s, 0, irq);
     }
hw/hppa/machine.c +2 -2
index d52f27c51c..4fcb3e5e37 100644
@@ -640,9 +640,9 @@ static void machine_HP_715_init(MachineState *machine)
     }
 
     /* LASI i82596 network */
-    dev = qemu_create_nic_device(TYPE_LASI_82596, true, "lasi");
+    dev = qemu_create_nic_device(OBJECT(machine), "lan", TYPE_LASI_82596, true, "lasi");
     if (dev) {
-        sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
+        sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
         sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0,
                            qdev_get_gpio_in(lasi_dev, LASI_IRQ_LAN_HPA));
         memory_region_add_subregion(addr_space,
hw/m68k/mcf5208.c +2 -2
index f305478b8d..a955efebeb 100644
@@ -260,13 +260,13 @@ static void mcf_fec_init(MemoryRegion *sysmem, hwaddr base, DeviceState *intc)
     SysBusDevice *s;
     int i;
 
-    dev = qemu_create_nic_device(TYPE_MCF_FEC_NET, true, NULL);
+    dev = qemu_create_nic_device(qdev_get_machine(), "fec", TYPE_MCF_FEC_NET, true, NULL);
     if (!dev) {
         return;
     }
 
     s = SYS_BUS_DEVICE(dev);
-    sysbus_realize_and_unref(s, &error_fatal);
+    sysbus_realize(s, &error_fatal);
     for (i = 0; i < FEC_NUM_IRQ; i++) {
         sysbus_connect_irq(s, i, qdev_get_gpio_in(intc, i + 36));
     }
hw/mips/fuloong2e.c +2 -1
index 477ad99c87..1b105ca37c 100644
@@ -231,7 +231,8 @@ static void mips_fuloong2e_init(MachineState *machine)
     clock_set_hz(cpuclk, 533080000); /* ~533 MHz */
 
     /* init CPUs */
-    cpu = mips_cpu_create_with_clock(machine->cpu_type, cpuclk, false);
+    cpu = mips_cpu_create_with_clock(OBJECT(machine), "cpu[*]",
+                                     machine->cpu_type, cpuclk, false);
     env = &cpu->env;
 
     qemu_register_reset(main_cpu_reset, cpu);
hw/mips/jazz.c +1 -1
index 8c52608913..cb24d8c00d 100644
@@ -209,7 +209,7 @@ static void mips_jazz_init(MachineState *machine,
                          * ext_clk[jazz_model].pll_mult);
 
     /* init CPUs */
-    cpu = mips_cpu_create_with_clock(machine->cpu_type, cpuclk,
+    cpu = mips_cpu_create_with_clock(OBJECT(machine), "cpu[*]", machine->cpu_type, cpuclk,
                                      TARGET_BIG_ENDIAN);
     env = &cpu->env;
     qemu_register_reset(main_cpu_reset, cpu);
hw/mips/loongson3_virt.c +2 -1
index 8d8430562c..93c14026ab 100644
@@ -552,7 +552,8 @@ static void mips_loongson3_virt_init(MachineState *machine)
         hwaddr ipi_base = ((hwaddr)node << 44) + virt_memmap[VIRT_IPI].base;
 
         /* init CPUs */
-        cpu = mips_cpu_create_with_clock(machine->cpu_type, cpuclk, false);
+        cpu = mips_cpu_create_with_clock(OBJECT(machine), "cpu[*]",
+                                         machine->cpu_type, cpuclk, false);
 
         /* Init internal devices */
         cpu_mips_irq_init_cpu(cpu);
hw/mips/malta.c +1 -1
index e8c130d5bb..72bc97625f 100644
@@ -1027,7 +1027,7 @@ static void create_cpu_without_cps(MachineState *ms, MaltaState *s,
     int i;
 
     for (i = 0; i < ms->smp.cpus; i++) {
-        cpu = mips_cpu_create_with_clock(ms->cpu_type, s->cpuclk,
+        cpu = mips_cpu_create_with_clock(OBJECT(ms), "cpu[*]", ms->cpu_type, s->cpuclk,
                                          TARGET_BIG_ENDIAN);
 
         /* Init internal devices */
hw/or1k/or1k-sim.c +2 -2
index 7ea61327c3..293970f156 100644
@@ -178,13 +178,13 @@ static void openrisc_sim_net_init(Or1ksimState *state, hwaddr base, hwaddr size,
     char *nodename;
     int i;
 
-    dev = qemu_create_nic_device("open_eth", true, NULL);
+    dev = qemu_create_nic_device(OBJECT(state), "eth", "open_eth", true, NULL);
     if (!dev) {
         return;
     }
 
     s = SYS_BUS_DEVICE(dev);
-    sysbus_realize_and_unref(s, &error_fatal);
+    sysbus_realize(s, &error_fatal);
     if (num_cpus > 1) {
         DeviceState *splitter = qdev_new(OBJECT(state), "irq-splitter[*]",
                                          TYPE_SPLIT_IRQ);
hw/s390x/s390-virtio-ccw.c +3 -5
index 1848cde0c4..037cb6eb5e 100644
@@ -237,12 +237,10 @@ static void s390_init_ipl_dev(const char *kernel_filename,
 static void s390_create_virtio_net(BusState *bus, const char *name)
 {
     DeviceState *dev;
-    int cnt = 0;
 
-    while ((dev = qemu_create_nic_device(name, true, "virtio"))) {
-        g_autofree char *childname = g_strdup_printf("%s[%d]", name, cnt++);
-        object_property_add_child(OBJECT(bus), childname, OBJECT(dev));
-        qdev_realize_and_unref(dev, bus, &error_fatal);
+    while ((dev = qemu_create_nic_device(qdev_get_machine(), "nic[*]",
+                                         name, true, "virtio"))) {
+        qdev_realize(dev, bus, &error_fatal);
     }
 }
 
hw/vmapple/vmapple.c +3 -2
index 60c7dab89b..67e499b74a 100644
@@ -416,8 +416,9 @@ static void create_pcie(VMAppleMachineState *vms)
     vms->bus = pci->bus;
     g_assert(vms->bus);
 
-    while ((dev = qemu_create_nic_device("virtio-net-pci", true, NULL))) {
-        qdev_realize_and_unref(dev, BUS(vms->bus), &error_fatal);
+    while ((dev = qemu_create_nic_device(OBJECT(vms), "nic[*]",
+                                         "virtio-net-pci", true, NULL))) {
+        qdev_realize(dev, BUS(vms->bus), &error_fatal);
     }
 
     if (defaults_enabled()) {
hw/xtensa/xtfpga.c +2 -2
index 10bbc34399..1c48283f5d 100644
@@ -149,13 +149,13 @@ static void xtfpga_net_init(MemoryRegion *address_space,
     SysBusDevice *s;
     MemoryRegion *ram;
 
-    dev = qemu_create_nic_device("open_eth", true, NULL);
+    dev = qemu_create_nic_device(qdev_get_machine(), "eth", "open_eth", true, NULL);
     if (!dev) {
         return;
     }
 
     s = SYS_BUS_DEVICE(dev);
-    sysbus_realize_and_unref(s, &error_fatal);
+    sysbus_realize(s, &error_fatal);
     sysbus_connect_irq(s, 0, irq);
     memory_region_add_subregion(address_space, base,
             sysbus_mmio_get_region(s, 0));
include/net/net.h +4 -1
index 45bc86fc86..3bba6e8c11 100644
@@ -243,6 +243,8 @@ bool qemu_configure_nic_device(DeviceState *dev, bool match_default,
 
 /**
  * qemu_create_nic_device: Create a NIC device if a configuration exists for it
+ * @parent: QOM parent of the created device
+ * @id: child<> property name
  * @typename: Object typename of network device
  * @match_default: Match NIC configurations with no model specified
  * @alias: Additional model string to match
@@ -250,7 +252,8 @@ bool qemu_configure_nic_device(DeviceState *dev, bool match_default,
  * Search for a NIC configuration for the provided device type. If found,
  * create an object of the corresponding type and return it.
  */
-DeviceState *qemu_create_nic_device(const char *typename, bool match_default,
+DeviceState *qemu_create_nic_device(Object *parent, const char *id,
+                                    const char *typename, bool match_default,
                                     const char *alias);
 
 /*
linux-user/main.c +4 -2
index 966322dbb3..c04d21ba84 100644
@@ -235,7 +235,8 @@ void init_task_state(TaskState *ts)
 CPUArchState *cpu_copy(CPUArchState *env)
 {
     CPUState *cpu = env_cpu(env);
-    CPUState *new_cpu = cpu_create_orphan(cpu_type);
+    CPUState *new_cpu = CPU(object_new(cpu_type));
+    qdev_realize(DEVICE(new_cpu), NULL, &error_fatal);
     CPUArchState *new_env = cpu_env(new_cpu);
     CPUBreakpoint *bp;
 
@@ -817,7 +818,8 @@ int main(int argc, char **argv, char **envp)
     set_preferred_target_page_bits(ctz32(host_page_size));
     finalize_target_page_bits();
 
-    cpu = cpu_create_orphan(cpu_type);
+    cpu = CPU(object_new(cpu_type));
+    qdev_realize(DEVICE(cpu), NULL, &error_fatal);
     env = cpu_env(cpu);
     cpu_reset(cpu);
     thread_cpu = cpu;
migration/migration.c +1 -1
index bdd163b65d..9736c14458 100644
@@ -4076,7 +4076,7 @@ static const TypeInfo migration_type = {
     .name = TYPE_MIGRATION,
     /*
      * NOTE: TYPE_MIGRATION is not really a device, as the object is
-     * not created using qdev_new_orphan(), it is not attached to the qdev
+     * not created using qdev_new(), it is not attached to the qdev
      * device tree, and it is never realized.
      *
      * TODO: Make this TYPE_OBJECT once QOM provides something like
net/net.c +6 -4
index e09f0c0d4f..2224367523 100644
@@ -1204,7 +1204,8 @@ bool qemu_configure_nic_device(DeviceState *dev, bool match_default,
 }
 
 /* "Please create a device, if you have a configuration for it" */
-DeviceState *qemu_create_nic_device(const char *typename, bool match_default,
+DeviceState *qemu_create_nic_device(Object *parent, const char *id,
+                                    const char *typename, bool match_default,
                                     const char *alias)
 {
     NICInfo *nd = qemu_find_nic_info(typename, match_default, alias);
@@ -1214,7 +1215,7 @@ DeviceState *qemu_create_nic_device(const char *typename, bool match_default,
         return NULL;
     }
 
-    dev = qdev_new_orphan(typename);
+    dev = qdev_new(parent, id, typename);
     qdev_set_nic_properties(dev, nd);
     return dev;
 }
@@ -1264,9 +1265,10 @@ void qemu_create_nic_bus_devices(BusState *bus, const char *parent_type,
             continue;
         }
 
-        dev = qdev_new_orphan(model);
+        dev = qdev_new(machine_get_container("peripheral-anon"),
+                       "nic[*]", model);
         qdev_set_nic_properties(dev, nd);
-        qdev_realize_and_unref(dev, bus, &error_fatal);
+        qdev_realize(dev, bus, &error_fatal);
     }
 
     g_ptr_array_free(nic_models, true);
target/mips/cpu.c +3 -2
index 9ad1b4177d..735a2041b7 100644
@@ -751,12 +751,13 @@ static void mips_cpu_register_types(void)
 type_init(mips_cpu_register_types)
 
 /* Could be used by generic CPU object */
-MIPSCPU *mips_cpu_create_with_clock(const char *cpu_type, Clock *cpu_refclk,
+MIPSCPU *mips_cpu_create_with_clock(Object *parent, const char *id,
+                                    const char *cpu_type, Clock *cpu_refclk,
                                     bool is_big_endian)
 {
     DeviceState *cpu;
 
-    cpu = qdev_new_orphan(cpu_type);
+    cpu = qdev_new(parent, id, cpu_type);
     qdev_connect_clock_in(cpu, "clk-in", cpu_refclk);
     object_property_set_bool(OBJECT(cpu), "big-endian", is_big_endian,
                              &error_abort);
target/mips/cpu.h +2 -1
index 319147a948..491a190271 100644
@@ -1429,7 +1429,8 @@ void cpu_mips_restore_fp_status(CPUMIPSState *env);
  *
  * Returns: A #CPUState or %NULL if an error occurred.
  */
-MIPSCPU *mips_cpu_create_with_clock(const char *cpu_type, Clock *cpu_refclk,
+MIPSCPU *mips_cpu_create_with_clock(Object *parent, const char *id,
+                                    const char *cpu_type, Clock *cpu_refclk,
                                     bool is_big_endian);
 
 #endif /* MIPS_CPU_H */
target/xtensa/cpu.c +0 -11
index 8e888a19d1..7573c1d67b 100644
@@ -284,17 +284,6 @@ static void xtensa_cpu_initfn(Object *obj)
 #endif
 }
 
-XtensaCPU *xtensa_cpu_create_with_clock(const char *cpu_type, Clock *cpu_refclk)
-{
-    DeviceState *cpu;
-
-    cpu = qdev_new_orphan(cpu_type);
-    qdev_connect_clock_in(cpu, "clk-in", cpu_refclk);
-    qdev_realize(cpu, NULL, &error_abort);
-
-    return XTENSA_CPU(cpu);
-}
-
 #ifndef CONFIG_USER_ONLY
 static const VMStateDescription vmstate_xtensa_cpu = {
     .name = "cpu",
target/xtensa/cpu.h +0 -2
index 442e98bd1b..019d0b56c1 100644
@@ -736,8 +736,6 @@ static inline uint32_t xtensa_replicate_windowstart(CPUXtensaState *env)
 #define XTENSA_CSBASE_LBEG_OFF_MASK 0x00ff0000
 #define XTENSA_CSBASE_LBEG_OFF_SHIFT 16
 
-XtensaCPU *xtensa_cpu_create_with_clock(const char *cpu_type,
-                                        Clock *cpu_refclk);
 
 /*
  * Set the NaN propagation rule for future FPU operations:
Signature · 1 line
2.47.1
#241 lore raw

RFC PATCH v2 84/137 usb, ssi, i2c: Remove *_orphan() creator variants

In reply to Alexander Graf

All external callers now go through the parented usb_new()/ usb_create_simple(), ssi_create_peripheral(), i2c_slave_new()/ i2c_slave_create_simple() introduced earlier in the series. Remove the transitional *_orphan() spellings.

The corresponding *_realize_and_unref() helpers stay for now: they are still valid for callers that reach for object_new() directly and hold a floating reference (qdev_device_add() being the primary example one layer down).

AI-used-for: code (refactoring)

---
 hw/i2c/core.c        | 18 ------------------
 hw/ssi/ssi.c         |  8 --------
 include/hw/i2c/i2c.h | 31 ++++---------------------------
 include/hw/ssi/ssi.h |  5 ++---
 include/hw/usb/usb.h |  9 ---------
 5 files changed, 6 insertions(+), 65 deletions(-)
hw/i2c/core.c +0 -18
index fba21fdfad..f333df3760 100644
@@ -364,15 +364,6 @@ const VMStateDescription vmstate_i2c_slave = {
     }
 };
 
-I2CSlave *i2c_slave_new_orphan(const char *name, uint8_t addr)
-{
-    DeviceState *dev;
-
-    dev = qdev_new_orphan(name);
-    qdev_prop_set_uint8(dev, "address", addr);
-    return I2C_SLAVE(dev);
-}
-
 I2CSlave *i2c_slave_new(Object *parent, const char *id,
                         const char *type, uint8_t addr)
 {
@@ -398,15 +389,6 @@ bool i2c_slave_realize_and_unref(I2CSlave *dev, I2CBus *bus, Error **errp)
     return qdev_realize_and_unref(&dev->qdev, &bus->qbus, errp);
 }
 
-I2CSlave *i2c_slave_create_simple_orphan(I2CBus *bus, const char *name, uint8_t addr)
-{
-    I2CSlave *dev = i2c_slave_new_orphan(name, addr);
-
-    i2c_slave_realize_and_unref(dev, bus, &error_abort);
-
-    return dev;
-}
-
 static bool i2c_slave_match(I2CSlave *candidate, uint8_t address,
                             bool broadcast, I2CNodeList *current_devs)
 {
hw/ssi/ssi.c +0 -8
index 6031cde7b0..07188d87bb 100644
@@ -147,14 +147,6 @@ DeviceState *ssi_create_peripheral(Object *parent, const char *id,
     return dev;
 }
 
-DeviceState *ssi_create_peripheral_orphan(SSIBus *bus, const char *name)
-{
-    DeviceState *dev = qdev_new_orphan(name);
-
-    ssi_realize_and_unref(dev, bus, &error_fatal);
-    return dev;
-}
-
 SSIBus *ssi_create_bus(DeviceState *parent, const char *name)
 {
     BusState *bus;
include/hw/i2c/i2c.h +4 -27
index 0bba1a7c20..c0829edf8f 100644
@@ -154,17 +154,6 @@ uint8_t i2c_recv(I2CBus *bus);
 bool i2c_scan_bus(I2CBus *bus, uint8_t address, bool broadcast,
                   I2CNodeList *current_devs);
 
-/**
- * Create an I2C slave device on the heap.
- * @name: a device type name
- * @addr: I2C address of the slave when put on a bus
- *
- * This only initializes the device state structure and allows
- * properties to be set. Type @name must exist. The device still
- * needs to be realized. See qdev-core.h.
- */
-I2CSlave *i2c_slave_new_orphan(const char *name, uint8_t addr);
-
 /**
  * Create a parented I2C slave device on the heap.
  * @parent: the QOM parent
@@ -172,24 +161,12 @@ I2CSlave *i2c_slave_new_orphan(const char *name, uint8_t addr);
  * @type: I2C slave device type name
  * @addr: I2C address of the slave when put on a bus
  *
- * Like i2c_slave_new_orphan(), but the returned device is owned by
+ * Like i2c_slave_new(), but the returned device is owned by
  * @parent's child<> property.  Pair with qdev_realize().
  */
 I2CSlave *i2c_slave_new(Object *parent, const char *id,
                         const char *type, uint8_t addr);
 
-/**
- * Create and realize an I2C slave device on the heap.
- * @bus: I2C bus to put it on
- * @name: I2C slave device type name
- * @addr: I2C address of the slave when put on a bus
- *
- * Create the device state structure, initialize it, put it on the
- * specified @bus, and drop the reference to it (the device is realized).
- */
-I2CSlave *i2c_slave_create_simple_orphan(I2CBus *bus, const char *name,
-                                         uint8_t addr);
-
 /**
  * Create, parent and realize an I2C slave device on the heap.
  * @parent: the QOM parent
@@ -218,11 +195,11 @@ I2CSlave *i2c_slave_create_simple(Object *parent, const char *id,
  * Call 'realize' on @dev, put it on the specified @bus, and drop the
  * reference to it.
  *
- * This function is useful if you have created @dev via qdev_new_orphan(),
- * i2c_slave_new_orphan() or i2c_slave_try_new() (which take a reference to
+ * This function is useful if you have created @dev via qdev_new(),
+ * i2c_slave_new() or i2c_slave_try_new() (which take a reference to
  * the device it returns to you), so that you can set properties on it
  * before realizing it. If you don't need to set properties then
- * i2c_slave_create_simple_orphan() is probably better (as it does the create,
+ * i2c_slave_create_simple() is probably better (as it does the create,
  * init and realize in one step).
  *
  * If you are embedding the I2C slave into another QOM device and
include/hw/ssi/ssi.h +2 -3
index 36ed002281..b2a264bb55 100644
@@ -83,7 +83,6 @@ extern const VMStateDescription vmstate_ssi_peripheral;
 
 DeviceState *ssi_create_peripheral(Object *parent, const char *id,
                                     SSIBus *bus, const char *type);
-DeviceState *ssi_create_peripheral_orphan(SSIBus *bus, const char *name);
 /**
  * ssi_realize_and_unref: realize and unref an SSI peripheral
  * @dev: SSI peripheral to realize
@@ -94,10 +93,10 @@ DeviceState *ssi_create_peripheral_orphan(SSIBus *bus, const char *name);
  * reference to it. Errors are reported via @errp and by returning
  * false.
  *
- * This function is useful if you have created @dev via qdev_new_orphan()
+ * This function is useful if you have created @dev via qdev_new()
  * (which takes a reference to the device it returns to you), so that
  * you can set properties on it before realizing it. If you don't need
- * to set properties then ssi_create_peripheral_orphan() is probably better (as it
+ * to set properties then ssi_create_peripheral() is probably better (as it
  * does the create, init and realize in one step).
  *
  * If you are embedding the SSI peripheral into another QOM device and
include/hw/usb/usb.h +0 -9
index 1ae1f40aa9..d2e59bc83b 100644
@@ -599,13 +599,4 @@ static inline USBDevice *usb_create_simple(Object *parent, const char *id,
     return dev;
 }
 
-static inline USBDevice *usb_create_simple_orphan(USBBus *bus,
-                                                    const char *name)
-{
-    USBDevice *dev = USB_DEVICE(qdev_new_orphan(name));
-
-    usb_realize_and_unref(dev, bus, &error_abort);
-    return dev;
-}
-
 #endif
Signature · 1 line
2.47.1
#242 lore raw

RFC PATCH v2 85/137 isa: Remove *_orphan() creator variants

In reply to Alexander Graf

All boards create their ISA devices with an explicit QOM parent now. Drop isa_new_orphan(), isa_try_new_orphan() and isa_create_simple_orphan().

AI-used-for: code (refactoring)

---
 hw/isa/isa-bus.c     | 19 -------------------
 include/hw/isa/isa.h |  3 ---
 2 files changed, 22 deletions(-)
hw/isa/isa-bus.c +0 -19
index 7a6a595ce7..22452e5048 100644
@@ -172,25 +172,6 @@ ISADevice *isa_create_simple(Object *parent, const char *id,
     return dev;
 }
 
-ISADevice *isa_new_orphan(const char *name)
-{
-    return ISA_DEVICE(qdev_new_orphan(name));
-}
-
-ISADevice *isa_try_new_orphan(const char *name)
-{
-    return ISA_DEVICE(qdev_try_new_orphan(name));
-}
-
-ISADevice *isa_create_simple_orphan(ISABus *bus, const char *name)
-{
-    ISADevice *dev;
-
-    dev = isa_new_orphan(name);
-    isa_realize_and_unref(dev, bus, &error_fatal);
-    return dev;
-}
-
 bool isa_realize_and_unref(ISADevice *dev, ISABus *bus, Error **errp)
 {
     return qdev_realize_and_unref(&dev->parent_obj, &bus->parent_obj, errp);
include/hw/isa/isa.h +0 -3
index 79bfe16361..9bbaa3c258 100644
@@ -86,10 +86,7 @@ ISADevice *isa_new(Object *parent, const char *id, const char *type);
 ISADevice *isa_try_new(Object *parent, const char *id, const char *type);
 ISADevice *isa_create_simple(Object *parent, const char *id,
                              ISABus *bus, const char *type);
-ISADevice *isa_new_orphan(const char *name);
-ISADevice *isa_try_new_orphan(const char *name);
 bool isa_realize_and_unref(ISADevice *dev, ISABus *bus, Error **errp);
-ISADevice *isa_create_simple_orphan(ISABus *bus, const char *name);
 
 ISADevice *isa_vga_init(Object *parent, ISABus *bus);
 
Signature · 1 line
2.47.1
#243 lore raw

RFC PATCH v2 86/137 pci: Remove *_orphan() creator variants

In reply to Alexander Graf

All boards create their PCI devices with an explicit QOM parent now. Drop pci_new_orphan(), pci_new_multifunction_orphan(), pci_create_simple_orphan(), pci_create_simple_multifunction_orphan() and the internal pci_new_internal() they wrapped.

AI-used-for: code (refactoring)

---
 hw/pci/pci.c         | 35 -----------------------------------
 include/hw/pci/pci.h |  5 -----
 2 files changed, 40 deletions(-)
hw/pci/pci.c +0 -35
index ca5882ba59..5ef9dfa8b7 100644
@@ -2388,16 +2388,6 @@ static void pci_qdev_realize(DeviceState *qdev, Error **errp)
     pci_dev->msi_trigger = pci_msi_trigger;
 }
 
-static PCIDevice *pci_new_internal(int devfn, bool multifunction,
-                                   const char *name)
-{
-    DeviceState *dev;
-
-    dev = qdev_new_orphan(name);
-    qdev_prop_set_int32(dev, "addr", devfn);
-    qdev_prop_set_bit(dev, "multifunction", multifunction);
-    return PCI_DEVICE(dev);
-}
 
 static PCIDevice *pci_new_child_internal(Object *parent, const char *id,
                                           int devfn, bool multifunction,
@@ -2440,36 +2430,11 @@ PCIDevice *pci_create_simple(Object *parent, const char *id,
     return dev;
 }
 
-PCIDevice *pci_new_multifunction_orphan(int devfn, const char *name)
-{
-    return pci_new_internal(devfn, true, name);
-}
-
-PCIDevice *pci_new_orphan(int devfn, const char *name)
-{
-    return pci_new_internal(devfn, false, name);
-}
-
 bool pci_realize_and_unref(PCIDevice *dev, PCIBus *bus, Error **errp)
 {
     return qdev_realize_and_unref(&dev->qdev, &bus->qbus, errp);
 }
 
-PCIDevice *pci_create_simple_multifunction_orphan(PCIBus *bus, int devfn,
-                                           const char *name)
-{
-    PCIDevice *dev = pci_new_multifunction_orphan(devfn, name);
-    pci_realize_and_unref(dev, bus, &error_fatal);
-    return dev;
-}
-
-PCIDevice *pci_create_simple_orphan(PCIBus *bus, int devfn, const char *name)
-{
-    PCIDevice *dev = pci_new_orphan(devfn, name);
-    pci_realize_and_unref(dev, bus, &error_fatal);
-    return dev;
-}
-
 static uint8_t pci_find_space(PCIDevice *pdev, uint8_t size)
 {
     int offset = PCI_CONFIG_HEADER_SIZE;
include/hw/pci/pci.h +0 -5
index 9c6bcc0b96..d6191fc529 100644
@@ -1098,13 +1098,8 @@ PCIDevice *pci_create_simple_multifunction(Object *parent, const char *id,
 PCIDevice *pci_create_simple(Object *parent, const char *id,
                              PCIBus *bus, int devfn, const char *type);
 
-PCIDevice *pci_new_multifunction_orphan(int devfn, const char *name);
-PCIDevice *pci_new_orphan(int devfn, const char *name);
 bool pci_realize_and_unref(PCIDevice *dev, PCIBus *bus, Error **errp);
 
-PCIDevice *pci_create_simple_multifunction_orphan(PCIBus *bus, int devfn,
-                                           const char *name);
-PCIDevice *pci_create_simple_orphan(PCIBus *bus, int devfn, const char *name);
 
 void lsi53c8xx_handle_legacy_cmdline(DeviceState *lsi_dev);
 
Signature · 1 line
2.47.1
#244 lore raw

RFC PATCH v2 87/137 cpu: Remove cpu_create_orphan()

In reply to Alexander Graf

All targets create their CPUs with an explicit parent now.

AI-used-for: code (refactoring)

---
 hw/core/cpu-common.c  | 12 ------------
 include/hw/core/cpu.h | 10 ----------
 2 files changed, 22 deletions(-)
hw/core/cpu-common.c +0 -12
index eef243c1ad..829a044e9e 100644
@@ -68,18 +68,6 @@ CPUState *cpu_create(Object *parent, const char *id, const char *typename)
     return cpu;
 }
 
-CPUState *cpu_create_orphan(const char *typename)
-{
-    Error *err = NULL;
-    CPUState *cpu = CPU(object_new(typename));
-    if (!qdev_realize(DEVICE(cpu), NULL, &err)) {
-        error_report_err(err);
-        object_unref(OBJECT(cpu));
-        exit(EXIT_FAILURE);
-    }
-    return cpu;
-}
-
 void cpu_reset_interrupt(CPUState *cpu, int mask)
 {
     qatomic_and(&cpu->interrupt_request, ~mask);
include/hw/core/cpu.h +0 -10
index 1b2ec1ab1e..544740a699 100644
@@ -857,16 +857,6 @@ char *cpu_model_from_type(const char *typename);
  */
 CPUState *cpu_create(Object *parent, const char *id, const char *typename);
 
-/**
- * cpu_create_orphan:
- * @typename: The CPU type.
- *
- * Instantiates a CPU and realizes the CPU.
- *
- * Returns: A #CPUState or %NULL if an error occurred.
- */
-CPUState *cpu_create_orphan(const char *typename);
-
 /**
  * parse_cpu_option:
  * @cpu_option: The -cpu option including optional parameters.
Signature · 1 line
2.47.1
#245 lore raw

RFC PATCH v2 88/137 sysbus: Remove *_orphan() creator variants

In reply to Alexander Graf

All boards create sysbus devices with an explicit parent now. Drop sysbus_create_simple_orphan() and sysbus_create_varargs_orphan().

AI-used-for: code (refactoring)

---
 hw/core/sysbus.c         | 29 -----------------------------
 include/hw/core/sysbus.h | 11 -----------
 2 files changed, 40 deletions(-)
hw/core/sysbus.c +0 -29
index 85f56b68fb..1c67ea3580 100644
@@ -250,35 +250,6 @@ DeviceState *sysbus_create_varargs(Object *parent, const char *id,
     return dev;
 }
 
-DeviceState *sysbus_create_varargs_orphan(const char *name,
-                                   hwaddr addr, ...)
-{
-    DeviceState *dev;
-    SysBusDevice *s;
-    va_list va;
-    qemu_irq irq;
-    int n;
-
-    dev = qdev_new_orphan(name);
-    s = SYS_BUS_DEVICE(dev);
-    sysbus_realize_and_unref(s, &error_fatal);
-    if (addr != (hwaddr)-1) {
-        sysbus_mmio_map(s, 0, addr);
-    }
-    va_start(va, addr);
-    n = 0;
-    while (1) {
-        irq = va_arg(va, qemu_irq);
-        if (!irq) {
-            break;
-        }
-        sysbus_connect_irq(s, n, irq);
-        n++;
-    }
-    va_end(va);
-    return dev;
-}
-
 bool sysbus_realize(SysBusDevice *dev, Error **errp)
 {
     return qdev_realize(DEVICE(dev), sysbus_get_default(), errp);
include/hw/core/sysbus.h +0 -11
index 1e07b1978d..ef3d39f576 100644
@@ -119,15 +119,4 @@ static inline DeviceState *sysbus_create_simple(Object *parent,
     return sysbus_create_varargs(parent, id, type, addr, irq, NULL);
 }
 
-/* Legacy helper function for creating unparented devices.  */
-DeviceState *sysbus_create_varargs_orphan(const char *name,
-                                 hwaddr addr, ...);
-
-static inline DeviceState *sysbus_create_simple_orphan(const char *name,
-                                              hwaddr addr,
-                                              qemu_irq irq)
-{
-    return sysbus_create_varargs_orphan(name, addr, irq, NULL);
-}
-
 #endif /* HW_SYSBUS_H */
Signature · 1 line
2.47.1
#246 lore raw

RFC PATCH v2 89/137 qdev: Remove qdev_new_orphan() and qdev_try_new_orphan()

In reply to Alexander Graf

Every bus-layer *_orphan() wrapper is gone and the last direct caller, qdev_device_add_from_qdict(), now uses object_new() plus qdev_set_id() to place -device instances under /machine/peripheral{,-anon} as before. There is no remaining legitimate way to create a device without picking its parent, so drop the transitional *_orphan() spellings and update the doc comments that still referenced them.

AI-used-for: code (refactoring)

---
 hw/core/qdev.c         | 13 -------------
 include/hw/core/qdev.h | 30 +++---------------------------
 system/qdev-monitor.c  |  2 +-
 3 files changed, 4 insertions(+), 41 deletions(-)
hw/core/qdev.c +0 -13
index 947ba7db80..89bc1e30c0 100644
@@ -165,19 +165,6 @@ DeviceState *qdev_try_new(Object *parent, const char *id, const char *type)
     return DEVICE(obj);
 }
 
-DeviceState *qdev_new_orphan(const char *name)
-{
-    return DEVICE(object_new(name));
-}
-
-DeviceState *qdev_try_new_orphan(const char *name)
-{
-    ObjectClass *oc = module_object_class_by_name(name);
-    if (!oc) {
-        return NULL;
-    }
-    return DEVICE(object_new_with_class(oc));
-}
 
 static QTAILQ_HEAD(, DeviceListener) device_listeners
     = QTAILQ_HEAD_INITIALIZER(device_listeners);
include/hw/core/qdev.h +3 -27
index e692a1d48e..9220e9e3b1 100644
@@ -440,30 +440,6 @@ DeviceState *qdev_new(Object *parent, const char *id, const char *type);
  */
 DeviceState *qdev_try_new(Object *parent, const char *id, const char *type);
 
-/**
- * qdev_new_orphan: Create a device on the heap
- * @name: device type to create (we assert() that this type exists)
- *
- * This only allocates the memory and initializes the device state
- * structure, ready for the caller to set properties if they wish.
- * The device still needs to be realized.
- *
- * Return: a derived DeviceState object with a reference count of 1.
- */
-DeviceState *qdev_new_orphan(const char *name);
-
-/**
- * qdev_try_new_orphan: Try to create a device on the heap
- * @name: device type to create
- *
- * This is like qdev_new_orphan(), except it returns %NULL when type @name
- * does not exist, rather than asserting.
- *
- * Return: a derived DeviceState object with a reference count of 1 or
- * NULL if type @name does not exist.
- */
-DeviceState *qdev_try_new_orphan(const char *name);
-
 /**
  * qdev_is_realized() - check if device is realized
  * @dev: The device to check.
@@ -488,8 +464,8 @@ static inline bool qdev_is_realized(DeviceState *dev)
  * If @bus, plug @dev into @bus.  This takes a reference to @dev.
  * If @dev has no QOM parent, make one up, taking another reference.
  *
- * If you created @dev using qdev_new_orphan(), you probably want to use
- * qdev_realize_and_unref() instead.
+ * If you created @dev via object_new() directly (holding a floating
+ * reference), you probably want to use qdev_realize_and_unref() instead.
  *
  * Return: true on success, else false setting @errp with error
  */
@@ -506,7 +482,7 @@ bool qdev_realize(DeviceState *dev, BusState *bus, Error **errp);
  * (private) reference, which is dropped on return regardless of
  * success or failure.  Intended use::
  *
- *     dev = qdev_new_orphan();
+ *     dev = DEVICE(object_new(TYPE_FOO));
  *     [...]
  *     qdev_realize_and_unref(dev, bus, errp);
  *
system/qdev-monitor.c +1 -1
index adc37d6a89..0e13b1540c 100644
@@ -707,7 +707,7 @@ DeviceState *qdev_device_add_from_qdict(const QDict *opts,
     }
 
     /* create device */
-    dev = qdev_new_orphan(driver);
+    dev = DEVICE(object_new(driver));
 
     /* Check whether the hotplug is allowed by the machine */
     if (phase_check(PHASE_MACHINE_READY) &&
Signature · 1 line
2.47.1
#247 lore raw

RFC PATCH v2 90/137 memory: Accept non-device owners in memory_region_init_ram()

In reply to Alexander Graf

memory_region_register_ram() casts the owner to DeviceState with an asserting DEVICE() check. Historically this was fine because every caller either passed a device or NULL, but the following patches give board-created RAM regions their machine as owner, which is not a device.

vmstate_register_ram() only uses the device to prefix the RAMBlock idstr with the device's canonical path. Use object_dynamic_cast() so non-device owners degrade to the same NULL-owner idstr they had before, and drop the stale TODO comment.

No functional change for existing callers.

AI-used-for: code (refactoring)

---
 system/memory.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
system/memory.c +9 -8
index 5fc36708ec..838be57b4d 100644
@@ -3631,15 +3631,16 @@ void mtree_info(bool flatview, bool dispatch_tree, bool owner, bool disabled)
 
 static void memory_region_register_ram(MemoryRegion *mr, Object *owner)
 {
-    DeviceState *owner_dev;
-
-    /* This will assert if owner is neither NULL nor a DeviceState.
-     * We only want the owner here for the purposes of defining a
-     * unique name for migration. TODO: Ideally we should implement
-     * a naming scheme for Objects which are not DeviceStates, in
-     * which case we can relax this restriction.
+    /*
+     * vmstate_register_ram() prefixes the RAMBlock idstr with the
+     * bus-class dev-path of @owner (via qdev_get_dev_path()), not
+     * the QOM canonical path, when it is a DeviceState.  Board-
+     * created RAM regions are owned by the machine, which is not a
+     * device; pass NULL there so the idstr is the bare region name,
+     * matching historical behaviour for owner==NULL callers.
      */
-    owner_dev = DEVICE(owner);
+    DeviceState *owner_dev =
+        (DeviceState *)object_dynamic_cast(owner, TYPE_DEVICE);
     vmstate_register_ram(mr, owner_dev);
 }
 
Signature · 1 line
2.47.1
#248 lore raw

RFC PATCH v2 91/137 hw/misc-boards: Give memory regions an explicit owner

In reply to Alexander Graf

memory_region_init*() takes an @owner argument that becomes the QOM parent of the MemoryRegion object. When NULL is passed the region is silently reparented under /machine/unattached, hiding its lifetime owner.

Convert trivial owner==NULL sites in board init functions and device realize functions across small subdirectories. The owner is the enclosing machine or device in every case:

  hw/hexagon    OBJECT(machine|ms|vms)  virt, hexagon_dsp
  hw/hppa       parent, OBJECT(machine)
  hw/ipmi       OBJECT(ii)              IPMIInterface implementations
  hw/loongarch  OBJECT(machine)
  hw/microblaze OBJECT(machine)
  hw/or1k       OBJECT(machine)
  hw/pci-host   OBJECT(dev)             bonito realize
  hw/rtc        OBJECT(dev)             ls7a realize
  hw/sparc      OBJECT(machine)
  hw/sparc64    OBJECT(machine)
  hw/vmapple    OBJECT(vms)
  hw/xen        OBJECT(s)               xen-pvh-common ram init

No functional change: memory_region_do_init() would have parented these under /machine/unattached; they now sit under their creator.

RAMBlock idstrs are unchanged: the owners added here are Machine or SysBus devices, and memory_region_register_ram() maps both to dev=NULL for qemu_ram_set_idstr().

AI-used-for: code (refactoring)

---
 hw/hexagon/hexagon_dsp.c                 |  4 ++--
 hw/hexagon/virt.c                        |  8 ++++----
 hw/hppa/machine.c                        |  6 +++---
 hw/ipmi/ipmi_bt.c                        |  2 +-
 hw/ipmi/ipmi_kcs.c                       |  2 +-
 hw/loongarch/virt.c                      |  4 ++--
 hw/microblaze/petalogix_ml605_mmu.c      |  4 ++--
 hw/microblaze/petalogix_s3adsp1800_mmu.c |  4 ++--
 hw/microblaze/xlnx-zynqmp-pmu.c          |  4 ++--
 hw/or1k/or1k-sim.c                       |  2 +-
 hw/or1k/virt.c                           |  2 +-
 hw/pci-host/bonito.c                     |  4 ++--
 hw/rtc/ls7a_rtc.c                        |  2 +-
 hw/sparc/leon3.c                         |  2 +-
 hw/sparc64/niagara.c                     | 13 +++++++------
 hw/vmapple/vmapple.c                     |  2 +-
 hw/xen/xen-pvh-common.c                  | 12 ++++++------
 17 files changed, 39 insertions(+), 38 deletions(-)
hw/hexagon/hexagon_dsp.c +2 -2
index ccd9a06f51..53dfe6741e 100644
@@ -122,12 +122,12 @@ static void hexagon_common_init(MachineState *machine, Rev_t rev,
 
     address_space = get_system_memory();
 
-    memory_region_init_rom(&hms->cfgtable_rom, NULL, "config_table.rom",
+    memory_region_init_rom(&hms->cfgtable_rom, OBJECT(machine), "config_table.rom",
                            sizeof(m_cfg->cfgtable), &error_fatal);
     memory_region_add_subregion(address_space, m_cfg->cfgbase,
                                 &hms->cfgtable_rom);
 
-    memory_region_init_ram(&hms->ram, NULL, "ddr.ram",
+    memory_region_init_ram(&hms->ram, OBJECT(machine), "ddr.ram",
                            machine->ram_size, &error_fatal);
     memory_region_add_subregion(address_space, 0x0, &hms->ram);
 
hw/hexagon/virt.c +4 -4
index 0619f06c41..fb23cda19f 100644
@@ -74,7 +74,7 @@ static void fdt_add_hvx(HexagonVirtMachineState *vms,
     const MachineState *ms = MACHINE(vms);
     uint32_t vtcm_size_bytes = m_cfg->cfgtable.vtcm_size_kb * 1024;
     if (vtcm_size_bytes > 0) {
-        memory_region_init_ram(&vms->vtcm, NULL, "vtcm.ram", vtcm_size_bytes,
+        memory_region_init_ram(&vms->vtcm, OBJECT(vms), "vtcm.ram", vtcm_size_bytes,
                                &error_fatal);
         memory_region_add_subregion(vms->sys, m_cfg->cfgtable.vtcm_base << 16,
                                     &vms->vtcm);
@@ -250,18 +250,18 @@ static void virt_init(MachineState *ms)
     vms->apb_clk = clock_new(OBJECT(ms), "apb-pclk");
     clock_set_hz(vms->apb_clk, 24000000);
 
-    memory_region_init_ram(&vms->parent_obj.ram, NULL, "ddr.ram",
+    memory_region_init_ram(&vms->parent_obj.ram, OBJECT(ms), "ddr.ram",
                            ms->ram_size, &error_fatal);
     memory_region_add_subregion(vms->sys, 0x0, &vms->parent_obj.ram);
 
     if (m_cfg->l2tcm_size) {
-        memory_region_init_ram(&vms->tcm, NULL, "tcm.ram", m_cfg->l2tcm_size,
+        memory_region_init_ram(&vms->tcm, OBJECT(ms), "tcm.ram", m_cfg->l2tcm_size,
                                &error_fatal);
         memory_region_add_subregion(vms->sys, m_cfg->cfgtable.l2tcm_base << 16,
                                     &vms->tcm);
     }
 
-    memory_region_init_rom(&vms->parent_obj.cfgtable_rom, NULL,
+    memory_region_init_rom(&vms->parent_obj.cfgtable_rom, OBJECT(ms),
                            "config_table.rom", sizeof(m_cfg->cfgtable),
                            &error_fatal);
     memory_region_add_subregion(vms->sys, m_cfg->cfgbase,
hw/hppa/machine.c +3 -3
index 4fcb3e5e37..233cf6318b 100644
@@ -104,7 +104,7 @@ static ISABus *hppa_isa_bus(Object *parent, hwaddr addr)
     MemoryRegion *isa_region;
 
     isa_region = g_new(MemoryRegion, 1);
-    memory_region_init_io(isa_region, NULL, &hppa_pci_ignore_ops,
+    memory_region_init_io(isa_region, parent, &hppa_pci_ignore_ops,
                           NULL, "isa-io", 0x800);
     memory_region_add_subregion(get_system_memory(), addr, isa_region);
 
@@ -337,7 +337,7 @@ static TranslateFn *machine_HP_common_init_cpus(MachineState *machine)
          */
         cflush_name = g_strdup_printf("cpu%u-T600-cacheflush", i);
         cflush = g_new(MemoryRegion, 1);
-        memory_region_init_io(cflush, NULL, &hppa_pci_ignore_ops,
+        memory_region_init_io(cflush, OBJECT(machine), &hppa_pci_ignore_ops,
                               NULL, cflush_name, 4);
         memory_region_add_subregion(addr_space,
                               translate(NULL, CPU_HPA + i * 0x1000 + 0x500),
@@ -498,7 +498,7 @@ static void machine_HP_common_init_tail(MachineState *machine, PCIBus *pci_bus,
     }
 
     rom_region = g_new(MemoryRegion, 1);
-    memory_region_init_ram(rom_region, NULL, "firmware",
+    memory_region_init_ram(rom_region, OBJECT(machine), "firmware",
                            (FIRMWARE_END - FIRMWARE_START), &error_fatal);
     memory_region_add_subregion(addr_space,
                                 translate(NULL, FIRMWARE_START), rom_region);
hw/ipmi/ipmi_bt.c +1 -1
index e01d02fe52..173e2e52c6 100644
@@ -361,7 +361,7 @@ static void ipmi_bt_init(IPMIInterface *ii, unsigned int min_size, Error **errp)
     ib->size_mask = min_size - 1;
     ib->io_length = 3;
 
-    memory_region_init_io(&ib->io, NULL, &ipmi_bt_io_ops, ii, "ipmi-bt",
+    memory_region_init_io(&ib->io, OBJECT(ii), &ipmi_bt_io_ops, ii, "ipmi-bt",
                           min_size);
 }
 
hw/ipmi/ipmi_kcs.c +1 -1
index d5cfe6c068..9bd678e725 100644
@@ -339,7 +339,7 @@ static void ipmi_kcs_init(IPMIInterface *ii, unsigned int min_size,
     }
     ik->size_mask = min_size - 1;
     ik->io_length = 2;
-    memory_region_init_io(&ik->io, NULL, &ipmi_kcs_io_ops, ii, "ipmi-kcs",
+    memory_region_init_io(&ik->io, OBJECT(ii), &ipmi_kcs_io_ops, ii, "ipmi-kcs",
                           min_size);
 }
 
hw/loongarch/virt.c +2 -2
index 24d8dc6e57..09c39140bd 100644
@@ -966,13 +966,13 @@ static void virt_init(MachineState *machine)
         size = VIRT_LOWMEM_SIZE;
     }
 
-    memory_region_init_alias(&lvms->lowmem, NULL, "loongarch.lowram",
+    memory_region_init_alias(&lvms->lowmem, OBJECT(machine), "loongarch.lowram",
                               machine->ram, base, size);
     memory_region_add_subregion(address_space_mem, base, &lvms->lowmem);
     base += size;
     if (ram_size - size) {
         base = VIRT_HIGHMEM_BASE;
-        memory_region_init_alias(&lvms->highmem, NULL, "loongarch.highram",
+        memory_region_init_alias(&lvms->highmem, OBJECT(machine), "loongarch.highram",
                 machine->ram, VIRT_LOWMEM_BASE + size, ram_size - size);
         memory_region_add_subregion(address_space_mem, base, &lvms->highmem);
         base += ram_size - size;
hw/microblaze/petalogix_ml605_mmu.c +2 -2
index 1dc34dc247..26470b0251 100644
@@ -94,11 +94,11 @@ petalogix_ml605_init(MachineState *machine)
     qdev_realize(DEVICE(cpu), NULL, &error_abort);
 
     /* Attach emulated BRAM through the LMB.  */
-    memory_region_init_ram(phys_lmb_bram, NULL, "petalogix_ml605.lmb_bram",
+    memory_region_init_ram(phys_lmb_bram, OBJECT(machine), "petalogix_ml605.lmb_bram",
                            LMB_BRAM_SIZE, &error_fatal);
     memory_region_add_subregion(address_space_mem, 0x00000000, phys_lmb_bram);
 
-    memory_region_init_ram(phys_ram, NULL, "petalogix_ml605.ram", ram_size,
+    memory_region_init_ram(phys_ram, OBJECT(machine), "petalogix_ml605.ram", ram_size,
                            &error_fatal);
     memory_region_add_subregion(address_space_mem, MEMORY_BASEADDR, phys_ram);
 
hw/microblaze/petalogix_s3adsp1800_mmu.c +2 -2
index 6986eb7732..83bf325b2b 100644
@@ -92,12 +92,12 @@ petalogix_s3adsp1800_init(MachineState *machine)
     qdev_realize(DEVICE(cpu), NULL, &error_abort);
 
     /* Attach emulated BRAM through the LMB.  */
-    memory_region_init_ram(phys_lmb_bram, NULL,
+    memory_region_init_ram(phys_lmb_bram, OBJECT(machine),
                            "petalogix_s3adsp1800.lmb_bram", LMB_BRAM_SIZE,
                            &error_fatal);
     memory_region_add_subregion(sysmem, 0x00000000, phys_lmb_bram);
 
-    memory_region_init_ram(phys_ram, NULL, "petalogix_s3adsp1800.ram",
+    memory_region_init_ram(phys_ram, OBJECT(machine), "petalogix_s3adsp1800.ram",
                            ram_size, &error_fatal);
     memory_region_add_subregion(sysmem, ddr_base, phys_ram);
 
hw/microblaze/xlnx-zynqmp-pmu.c +2 -2
index 00154236bf..cf9314f86c 100644
@@ -155,13 +155,13 @@ static void xlnx_zynqmp_pmu_init(MachineState *machine)
     MemoryRegion *pmu_ram = g_new(MemoryRegion, 1);
 
     /* Create the ROM */
-    memory_region_init_rom(pmu_rom, NULL, "xlnx-zynqmp-pmu.rom",
+    memory_region_init_rom(pmu_rom, OBJECT(machine), "xlnx-zynqmp-pmu.rom",
                            XLNX_ZYNQMP_PMU_ROM_SIZE, &error_fatal);
     memory_region_add_subregion(address_space_mem, XLNX_ZYNQMP_PMU_ROM_ADDR,
                                 pmu_rom);
 
     /* Create the RAM */
-    memory_region_init_ram(pmu_ram, NULL, "xlnx-zynqmp-pmu.ram",
+    memory_region_init_ram(pmu_ram, OBJECT(machine), "xlnx-zynqmp-pmu.ram",
                            machine->ram_size, &error_fatal);
     memory_region_add_subregion(address_space_mem, XLNX_ZYNQMP_PMU_RAM_ADDR,
                                 pmu_ram);
hw/or1k/or1k-sim.c +1 -1
index 293970f156..ca2852fa87 100644
@@ -312,7 +312,7 @@ static void openrisc_sim_init(MachineState *machine)
     }
 
     ram = g_malloc(sizeof(*ram));
-    memory_region_init_ram(ram, NULL, "openrisc.ram", ram_size, &error_fatal);
+    memory_region_init_ram(ram, OBJECT(machine), "openrisc.ram", ram_size, &error_fatal);
     memory_region_add_subregion(get_system_memory(), 0, ram);
 
     openrisc_create_fdt(state, or1ksim_memmap, smp_cpus, machine->ram_size,
hw/or1k/virt.c +1 -1
index c0e0e3c48b..8cd520b320 100644
@@ -498,7 +498,7 @@ static void openrisc_virt_init(MachineState *machine)
     }
 
     ram = g_malloc(sizeof(*ram));
-    memory_region_init_ram(ram, NULL, "openrisc.ram", ram_size, &error_fatal);
+    memory_region_init_ram(ram, OBJECT(machine), "openrisc.ram", ram_size, &error_fatal);
     memory_region_add_subregion(get_system_memory(), 0, ram);
 
     openrisc_create_fdt(state, virt_memmap, smp_cpus, machine->ram_size,
hw/pci-host/bonito.c +2 -2
index 7b4259c0e7..48135a7fc0 100644
@@ -639,7 +639,7 @@ static void bonito_host_realize(DeviceState *dev, Error **errp)
     for (size_t i = 0; i < 3; i++) {
         char *name = g_strdup_printf("pci.lomem%zu", i);
 
-        memory_region_init_alias(&pcimem_lo_alias[i], NULL, name,
+        memory_region_init_alias(&pcimem_lo_alias[i], OBJECT(dev), name,
                                  &bs->pci_mem, i * 64 * MiB, 64 * MiB);
         memory_region_add_subregion(get_system_memory(),
                                     BONITO_PCILO_BASE + i * 64 * MiB,
@@ -713,7 +713,7 @@ static void bonito_pci_realize(PCIDevice *dev, Error **errp)
     create_unimplemented_device(OBJECT(dev), "IOCS[3]", BONITO_DEV_BASE + 3 * 256 * KiB,
                                 256 * KiB);
 
-    memory_region_init_alias(pcimem_alias, NULL, "pci.mem.alias",
+    memory_region_init_alias(pcimem_alias, OBJECT(dev), "pci.mem.alias",
                              &bs->pci_mem, 0, BONITO_PCIHI_SIZE);
     memory_region_add_subregion(host_mem, BONITO_PCIHI_BASE, pcimem_alias);
     create_unimplemented_device(OBJECT(dev), "PCI_2",
hw/rtc/ls7a_rtc.c +1 -1
index 158c815505..77206b6636 100644
@@ -388,7 +388,7 @@ static void ls7a_rtc_realize(DeviceState *dev, Error **errp)
     int i;
     SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
     LS7ARtcState *d = LS7A_RTC(sbd);
-    memory_region_init_io(&d->iomem, NULL, &ls7a_rtc_ops,
+    memory_region_init_io(&d->iomem, OBJECT(dev), &ls7a_rtc_ops,
                          (void *)d, "ls7a_rtc", 0x100);
 
     sysbus_init_irq(sbd, &d->irq);
hw/sparc/leon3.c +1 -1
index a96ccca8e3..f9ef2758e1 100644
@@ -345,7 +345,7 @@ static void leon3_generic_hw_init(MachineState *machine)
 
     /* Allocate BIOS */
     prom_size = 8 * MiB;
-    memory_region_init_rom(prom, NULL, "Leon3.bios", prom_size, &error_fatal);
+    memory_region_init_rom(prom, OBJECT(machine), "Leon3.bios", prom_size, &error_fatal);
     memory_region_add_subregion(address_space_mem, LEON3_PROM_OFFSET, prom);
 
     /* Load boot prom */
hw/sparc64/niagara.c +7 -6
index 8fb9937127..58384e80da 100644
@@ -106,23 +106,23 @@ static void niagara_init(MachineState *machine)
     /* init CPUs */
     sparc64_cpu_devinit(machine->cpu_type, NIAGARA_PROM_BASE);
     /* set up devices */
-    memory_region_init_ram(&s->hv_ram, NULL, "sun4v-hv.ram",
+    memory_region_init_ram(&s->hv_ram, OBJECT(machine), "sun4v-hv.ram",
                            NIAGARA_HV_RAM_SIZE, &error_fatal);
     memory_region_add_subregion(sysmem, NIAGARA_HV_RAM_BASE, &s->hv_ram);
 
     memory_region_add_subregion(sysmem, NIAGARA_PARTITION_RAM_BASE,
                                 machine->ram);
 
-    memory_region_init_ram(&s->nvram, NULL, "sun4v.nvram", NIAGARA_NVRAM_SIZE,
+    memory_region_init_ram(&s->nvram, OBJECT(machine), "sun4v.nvram", NIAGARA_NVRAM_SIZE,
                            &error_fatal);
     memory_region_add_subregion(sysmem, NIAGARA_NVRAM_BASE, &s->nvram);
-    memory_region_init_ram(&s->md_rom, NULL, "sun4v-md.rom",
+    memory_region_init_ram(&s->md_rom, OBJECT(machine), "sun4v-md.rom",
                            NIAGARA_MD_ROM_SIZE, &error_fatal);
     memory_region_add_subregion(sysmem, NIAGARA_MD_ROM_BASE, &s->md_rom);
-    memory_region_init_ram(&s->hv_rom, NULL, "sun4v-hv.rom",
+    memory_region_init_ram(&s->hv_rom, OBJECT(machine), "sun4v-hv.rom",
                            NIAGARA_HV_ROM_SIZE, &error_fatal);
     memory_region_add_subregion(sysmem, NIAGARA_HV_ROM_BASE, &s->hv_rom);
-    memory_region_init_ram(&s->prom, NULL, "sun4v.prom", PROM_SIZE_MAX,
+    memory_region_init_ram(&s->prom, OBJECT(machine), "sun4v.prom", PROM_SIZE_MAX,
                            &error_fatal);
     memory_region_add_subregion(sysmem, NIAGARA_PROM_BASE, &s->prom);
 
@@ -140,7 +140,8 @@ static void niagara_init(MachineState *machine)
         BlockBackend *blk = blk_by_legacy_dinfo(dinfo);
         int size = blk_getlength(blk);
         if (size > 0) {
-            memory_region_init_ram(&s->vdisk_ram, NULL, "sun4v_vdisk.ram", size,
+            memory_region_init_ram(&s->vdisk_ram, OBJECT(machine), "sun4v_vdisk.ram",
+                                   size,
                                    &error_fatal);
             memory_region_add_subregion(get_system_memory(),
                                         NIAGARA_VDISK_BASE, &s->vdisk_ram);
hw/vmapple/vmapple.c +1 -1
index 67e499b74a..cea7e3d2f4 100644
@@ -357,7 +357,7 @@ static void vmapple_firmware_init(VMAppleMachineState *vms,
         exit(1);
     }
 
-    memory_region_init_ram(&vms->fw_mr, NULL, "firmware", size, &error_fatal);
+    memory_region_init_ram(&vms->fw_mr, OBJECT(vms), "firmware", size, &error_fatal);
     image_size = load_image_mr(fname, &vms->fw_mr);
 
     g_free(fname);
hw/xen/xen-pvh-common.c +6 -6
index dae523f723..1047aabd57 100644
@@ -109,12 +109,12 @@ static void xen_pvh_init_ram(XenPVHMachineState *s,
     }
 
     if (s->cfg.mapcache) {
-        memory_region_init_ram(&xen_memory, NULL, "xen.ram",
+        memory_region_init_ram(&xen_memory, OBJECT(s), "xen.ram",
                                block_len, &error_fatal);
-        memory_region_init_alias(&s->ram.low, NULL, "xen.ram.lo", &xen_memory,
+        memory_region_init_alias(&s->ram.low, OBJECT(s), "xen.ram.lo", &xen_memory,
                                  s->cfg.ram_low.base, ram_size[0]);
         if (ram_size[1] > 0) {
-            memory_region_init_alias(&s->ram.high, NULL, "xen.ram.hi",
+            memory_region_init_alias(&s->ram.high, OBJECT(s), "xen.ram.hi",
                                      &xen_memory,
                                      s->cfg.ram_high.base, ram_size[1]);
         }
@@ -122,11 +122,11 @@ static void xen_pvh_init_ram(XenPVHMachineState *s,
         void *p;
 
         p = xen_map_guest_ram(s, s->cfg.ram_low.base, ram_size[0]);
-        memory_region_init_ram_ptr(&s->ram.low, NULL, "xen.ram.lo",
+        memory_region_init_ram_ptr(&s->ram.low, OBJECT(s), "xen.ram.lo",
                                    ram_size[0], p);
         if (ram_size[1] > 0) {
             p = xen_map_guest_ram(s, s->cfg.ram_high.base, ram_size[1]);
-            memory_region_init_ram_ptr(&s->ram.high, NULL, "xen.ram.hi",
+            memory_region_init_ram_ptr(&s->ram.high, OBJECT(s), "xen.ram.hi",
                                        ram_size[1], p);
         }
     }
@@ -140,7 +140,7 @@ static void xen_pvh_init_ram(XenPVHMachineState *s,
     /* Grants are only supported when the mapcache is on.  */
     if (s->cfg.mapcache) {
         /* Setup support for grants.  */
-        memory_region_init_ram(&xen_grants, NULL, "xen.grants", block_len,
+        memory_region_init_ram(&xen_grants, OBJECT(s), "xen.grants", block_len,
                 &error_fatal);
         memory_region_add_subregion(sysmem, XEN_GRANT_ADDR_OFF, &xen_grants);
     }
Signature · 1 line
2.47.1
#249 lore raw

RFC PATCH v2 92/137 hw/mips: Give memory regions an explicit owner

In reply to Alexander Graf

Convert memory_region_init*() calls that pass NULL owner to pass
the enclosing machine instead. All sites are inside board init functions (MachineState *machine) or a helper that already carries
an Object *parent from the earlier hw/mips device-parenting patch (malta_fpga_init).

No functional change intended.

RAMBlock idstrs are unchanged: the owners added here are Machine or SysBus devices, and memory_region_register_ram() maps both to dev=NULL for qemu_ram_set_idstr().

AI-used-for: code (refactoring)

---
 hw/mips/boston.c         |  8 ++++----
 hw/mips/fuloong2e.c      |  2 +-
 hw/mips/jazz.c           | 16 ++++++++--------
 hw/mips/loongson3_virt.c |  6 +++---
 hw/mips/malta.c          | 12 ++++++------
 5 files changed, 22 insertions(+), 22 deletions(-)
hw/mips/boston.c +4 -4
index a156b218fb..f012f22307 100644
@@ -711,7 +711,7 @@ static void boston_mach_init(MachineState *machine)
     sysbus_mmio_map_overlap(SYS_BUS_DEVICE(&s->cps), 0, 0, 1);
 
     flash =  g_new(MemoryRegion, 1);
-    memory_region_init_rom(flash, NULL, "boston.flash",
+    memory_region_init_rom(flash, OBJECT(machine), "boston.flash",
                            boston_memmap[BOSTON_FLASH].size, &error_fatal);
     memory_region_add_subregion_overlap(sys_mem,
                                         boston_memmap[BOSTON_FLASH].base,
@@ -722,7 +722,7 @@ static void boston_mach_init(MachineState *machine)
                                         machine->ram, 0);
 
     ddr_low_alias = g_new(MemoryRegion, 1);
-    memory_region_init_alias(ddr_low_alias, NULL, "boston_low.ddr",
+    memory_region_init_alias(ddr_low_alias, OBJECT(machine), "boston_low.ddr",
                              machine->ram, 0,
                              MIN(machine->ram_size, (256 * MiB)));
     memory_region_add_subregion_overlap(sys_mem, 0, ddr_low_alias, 0);
@@ -749,7 +749,7 @@ static void boston_mach_init(MachineState *machine)
                              get_cps_irq(&s->cps, 0));
 
     platreg = g_new(MemoryRegion, 1);
-    memory_region_init_io(platreg, NULL, &boston_platreg_ops, s,
+    memory_region_init_io(platreg, OBJECT(machine), &boston_platreg_ops, s,
                           "boston-platregs",
                           boston_memmap[BOSTON_PLATREG].size);
     memory_region_add_subregion_overlap(sys_mem,
@@ -761,7 +761,7 @@ static void boston_mach_init(MachineState *machine)
                              serial_hd(0), DEVICE_LITTLE_ENDIAN);
 
     lcd = g_new(MemoryRegion, 1);
-    memory_region_init_io(lcd, NULL, &boston_lcd_ops, s, "boston-lcd", 0x8);
+    memory_region_init_io(lcd, OBJECT(machine), &boston_lcd_ops, s, "boston-lcd", 0x8);
     memory_region_add_subregion_overlap(sys_mem,
                                         boston_memmap[BOSTON_LCD].base, lcd, 0);
 
hw/mips/fuloong2e.c +1 -1
index 1b105ca37c..29e6561f2a 100644
@@ -245,7 +245,7 @@ static void mips_fuloong2e_init(MachineState *machine)
     memory_region_add_subregion(address_space_mem, 0, machine->ram);
 
     /* Boot ROM */
-    memory_region_init_rom(bios, NULL, "fuloong2e.bios", BIOS_SIZE,
+    memory_region_init_rom(bios, OBJECT(machine), "fuloong2e.bios", BIOS_SIZE,
                            &error_fatal);
     memory_region_add_subregion(address_space_mem, 0x1fc00000LL, bios);
 
hw/mips/jazz.c +8 -8
index cb24d8c00d..8999efb352 100644
@@ -234,9 +234,9 @@ static void mips_jazz_init(MachineState *machine,
     /* allocate RAM */
     memory_region_add_subregion(address_space, 0, machine->ram);
 
-    memory_region_init_rom(bios, NULL, "mips_jazz.bios", MAGNUM_BIOS_SIZE,
+    memory_region_init_rom(bios, OBJECT(machine), "mips_jazz.bios", MAGNUM_BIOS_SIZE,
                            &error_fatal);
-    memory_region_init_alias(bios2, NULL, "mips_jazz.bios", bios,
+    memory_region_init_alias(bios2, OBJECT(machine), "mips_jazz.bios", bios,
                              0, MAGNUM_BIOS_SIZE);
     memory_region_add_subregion(address_space, 0x1fc00000LL, bios);
     memory_region_add_subregion(address_space, 0xfff00000LL, bios2);
@@ -270,17 +270,17 @@ static void mips_jazz_init(MachineState *machine,
                                 sysbus_mmio_get_region(sysbus, 0));
     memory_region_add_subregion(address_space, 0xf0000000,
                                 sysbus_mmio_get_region(sysbus, 1));
-    memory_region_init_io(dma_dummy, NULL, &dma_dummy_ops,
+    memory_region_init_io(dma_dummy, OBJECT(machine), &dma_dummy_ops,
                           NULL, "dummy_dma", 0x1000);
     memory_region_add_subregion(address_space, 0x8000d000, dma_dummy);
 
-    memory_region_init_rom(dp8393x_prom, NULL, "dp8393x-jazz.prom",
+    memory_region_init_rom(dp8393x_prom, OBJECT(machine), "dp8393x-jazz.prom",
                            SONIC_PROM_SIZE, &error_fatal);
     memory_region_add_subregion(address_space, 0x8000b000, dp8393x_prom);
 
     /* ISA bus: IO space at 0x90000000, mem space at 0x91000000 */
-    memory_region_init(isa_io, NULL, "isa-io", 0x00010000);
-    memory_region_init(isa_mem, NULL, "isa-mem", 0x01000000);
+    memory_region_init(isa_io, OBJECT(machine), "isa-io", 0x00010000);
+    memory_region_init(isa_mem, OBJECT(machine), "isa-mem", 0x01000000);
     memory_region_add_subregion(address_space, 0x90000000, isa_io);
     memory_region_add_subregion(address_space, 0x91000000, isa_mem);
     isa_bus = isa_bus_new_bridge(OBJECT(machine), isa_mem, isa_io, &error_abort);
@@ -306,7 +306,7 @@ static void mips_jazz_init(MachineState *machine,
         {
             /* Simple ROM, so user doesn't have to provide one */
             MemoryRegion *rom_mr = g_new(MemoryRegion, 1);
-            memory_region_init_rom(rom_mr, NULL, "g364fb.rom", 0x80000,
+            memory_region_init_rom(rom_mr, OBJECT(machine), "g364fb.rom", 0x80000,
                                    &error_fatal);
             uint8_t *rom = memory_region_get_ram_ptr(rom_mr);
             memory_region_add_subregion(address_space, 0x60000000, rom_mr);
@@ -357,7 +357,7 @@ static void mips_jazz_init(MachineState *machine,
 
     /* Real time clock */
     mc146818_rtc_init(OBJECT(machine), isa_bus, 1980, NULL);
-    memory_region_init_io(rtc, NULL, &rtc_ops, NULL, "rtc", 0x1000);
+    memory_region_init_io(rtc, OBJECT(machine), &rtc_ops, NULL, "rtc", 0x1000);
     memory_region_add_subregion(address_space, 0x80004000, rtc);
 
     /* Keyboard (i8042) */
hw/mips/loongson3_virt.c +3 -3
index 93c14026ab..97d097373d 100644
@@ -586,11 +586,11 @@ static void mips_loongson3_virt_init(MachineState *machine)
     assert(cpu); /* This variable points to the first created cpu. */
 
     /* Allocate RAM/BIOS, 0x00000000~0x10000000 is alias of 0x80000000~0x90000000 */
-    memory_region_init_rom(bios, NULL, "loongson3.bios",
+    memory_region_init_rom(bios, OBJECT(machine), "loongson3.bios",
                            virt_memmap[VIRT_BIOS_ROM].size, &error_fatal);
-    memory_region_init_alias(ram, NULL, "loongson3.lowmem",
+    memory_region_init_alias(ram, OBJECT(machine), "loongson3.lowmem",
                            machine->ram, 0, virt_memmap[VIRT_LOWMEM].size);
-    memory_region_init_io(iomem, NULL, &loongson3_pm_ops,
+    memory_region_init_io(iomem, OBJECT(machine), &loongson3_pm_ops,
                            NULL, "loongson3_pm", virt_memmap[VIRT_PM].size);
     qemu_register_wakeup_support();
 
hw/mips/malta.c +6 -6
index 72bc97625f..e1d8c3b4dd 100644
@@ -577,11 +577,11 @@ static MaltaFPGAState *malta_fpga_init(Object *parent, MemoryRegion *address_spa
 
     s = g_new0(MaltaFPGAState, 1);
 
-    memory_region_init_io(&s->iomem, NULL, &malta_fpga_ops, s,
+    memory_region_init_io(&s->iomem, parent, &malta_fpga_ops, s,
                           "malta-fpga", 0x100000);
-    memory_region_init_alias(&s->iomem_lo, NULL, "malta-fpga",
+    memory_region_init_alias(&s->iomem_lo, parent, "malta-fpga",
                              &s->iomem, 0, 0x900);
-    memory_region_init_alias(&s->iomem_hi, NULL, "malta-fpga",
+    memory_region_init_alias(&s->iomem_hi, parent, "malta-fpga",
                              &s->iomem, 0xa00, 0x100000 - 0xa00);
 
     memory_region_add_subregion(address_space, base, &s->iomem_lo);
@@ -1115,14 +1115,14 @@ void mips_malta_init(MachineState *machine)
     memory_region_add_subregion(system_memory, 0x80000000, machine->ram);
 
     /* alias for pre IO hole access */
-    memory_region_init_alias(ram_low_preio, NULL, "mips_malta_low_preio.ram",
+    memory_region_init_alias(ram_low_preio, OBJECT(machine), "mips_malta_low_preio.ram",
                              machine->ram, 0, MIN(ram_size, 256 * MiB));
     memory_region_add_subregion(system_memory, 0, ram_low_preio);
 
     /* alias for post IO hole access, if there is enough RAM */
     if (ram_size > 512 * MiB) {
         ram_low_postio = g_new(MemoryRegion, 1);
-        memory_region_init_alias(ram_low_postio, NULL,
+        memory_region_init_alias(ram_low_postio, OBJECT(machine),
                                  "mips_malta_low_postio.ram",
                                  machine->ram, 512 * MiB,
                                  ram_size - 512 * MiB);
@@ -1213,7 +1213,7 @@ void mips_malta_init(MachineState *machine)
      * handled by an overlapping region as the resulting ROM code subpage
      * regions are not executable.
      */
-    memory_region_init_ram(bios_copy, NULL, "bios.1fc", BIOS_SIZE,
+    memory_region_init_ram(bios_copy, OBJECT(machine), "bios.1fc", BIOS_SIZE,
                            &error_fatal);
     if (!rom_copy(memory_region_get_ram_ptr(bios_copy),
                   FLASH_ADDRESS, BIOS_SIZE)) {
Signature · 1 line
2.47.1
#250 lore raw

RFC PATCH v2 93/137 hw/riscv: Give memory regions an explicit owner

In reply to Alexander Graf

Convert memory_region_init*() calls that pass NULL owner to pass the enclosing machine or SoC device instead. All sites are inside board init (MachineState *machine) or SoC realize (DeviceState *dev) functions.

No functional change intended.

RAMBlock idstrs are unchanged: the owners added here are Machine or SysBus devices, and memory_region_register_ram() maps both to dev=NULL for qemu_ram_set_idstr().

AI-used-for: code (refactoring)

---
 hw/riscv/boston-aia.c           |  8 ++++----
 hw/riscv/microblaze-v-generic.c |  4 ++--
 hw/riscv/microchip_pfsoc.c      | 14 +++++++-------
 hw/riscv/sifive_u.c             |  4 ++--
 hw/riscv/spike.c                |  2 +-
 hw/riscv/tt_atlantis.c          |  2 +-
 hw/riscv/virt.c                 |  2 +-
 7 files changed, 18 insertions(+), 18 deletions(-)
hw/riscv/boston-aia.c +4 -4
index 5a9ec28068..ef41f53aac 100644
@@ -374,7 +374,7 @@ static void boston_mach_init(MachineState *machine)
     sysbus_mmio_map_overlap(SYS_BUS_DEVICE(&s->cps), 0, 0, 1);
 
     flash =  g_new(MemoryRegion, 1);
-    memory_region_init_rom(flash, NULL, "boston.flash",
+    memory_region_init_rom(flash, OBJECT(machine), "boston.flash",
                            boston_memmap[BOSTON_FLASH].size, &error_fatal);
     memory_region_add_subregion_overlap(sys_mem,
                                         boston_memmap[BOSTON_FLASH].base,
@@ -385,7 +385,7 @@ static void boston_mach_init(MachineState *machine)
                                         machine->ram, 0);
 
     ddr_low_alias = g_new(MemoryRegion, 1);
-    memory_region_init_alias(ddr_low_alias, NULL, "boston_low.ddr",
+    memory_region_init_alias(ddr_low_alias, OBJECT(machine), "boston_low.ddr",
                              machine->ram, 0,
                              MIN(machine->ram_size, (256 * MiB)));
     memory_region_add_subregion_overlap(sys_mem, 0, ddr_low_alias, 0);
@@ -398,7 +398,7 @@ static void boston_mach_init(MachineState *machine)
                              qdev_get_gpio_in(s->cps.aplic, PCIE2_INT));
 
     platreg = g_new(MemoryRegion, 1);
-    memory_region_init_io(platreg, NULL, &boston_platreg_ops, s,
+    memory_region_init_io(platreg, OBJECT(machine), &boston_platreg_ops, s,
                           "boston-platregs",
                           boston_memmap[BOSTON_PLATREG].size);
     memory_region_add_subregion_overlap(sys_mem,
@@ -410,7 +410,7 @@ static void boston_mach_init(MachineState *machine)
                              serial_hd(0), DEVICE_LITTLE_ENDIAN);
 
     lcd = g_new(MemoryRegion, 1);
-    memory_region_init_io(lcd, NULL, &boston_lcd_ops, s, "boston-lcd", 0x8);
+    memory_region_init_io(lcd, OBJECT(machine), &boston_lcd_ops, s, "boston-lcd", 0x8);
     memory_region_add_subregion_overlap(sys_mem,
                                         boston_memmap[BOSTON_LCD].base, lcd, 0);
 
hw/riscv/microblaze-v-generic.c +2 -2
index 7253ae7822..0a83932405 100644
@@ -70,12 +70,12 @@ static void mb_v_generic_init(MachineState *machine)
     object_property_set_bool(OBJECT(cpu), "d", false, NULL);
     qdev_realize(DEVICE(cpu), NULL, &error_abort);
     /* Attach emulated BRAM through the LMB.  */
-    memory_region_init_ram(phys_lmb_bram, NULL,
+    memory_region_init_ram(phys_lmb_bram, OBJECT(machine),
                            "mb_v.lmb_bram", LMB_BRAM_SIZE,
                            &error_fatal);
     memory_region_add_subregion(sysmem, 0x00000000, phys_lmb_bram);
 
-    memory_region_init_ram(phys_ram, NULL, "mb_v.ram",
+    memory_region_init_ram(phys_ram, OBJECT(machine), "mb_v.ram",
                            ram_size, &error_fatal);
     memory_region_add_subregion(sysmem, ddr_base, phys_ram);
 
hw/riscv/microchip_pfsoc.c +7 -7
index 0a98ac1c5e..f1ee64ef86 100644
@@ -219,14 +219,14 @@ static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp)
     qdev_realize(DEVICE(&s->u_cluster), NULL, &error_abort);
 
     /* Reserved Memory at address 0 */
-    memory_region_init_ram(rsvd0_mem, NULL, "microchip.pfsoc.rsvd0_mem",
+    memory_region_init_ram(rsvd0_mem, OBJECT(dev), "microchip.pfsoc.rsvd0_mem",
                            memmap[MICROCHIP_PFSOC_RSVD0].size, &error_fatal);
     memory_region_add_subregion(system_memory,
                                 memmap[MICROCHIP_PFSOC_RSVD0].base,
                                 rsvd0_mem);
 
     /* E51 DTIM */
-    memory_region_init_ram(e51_dtim_mem, NULL, "microchip.pfsoc.e51_dtim_mem",
+    memory_region_init_ram(e51_dtim_mem, OBJECT(dev), "microchip.pfsoc.e51_dtim_mem",
                            memmap[MICROCHIP_PFSOC_E51_DTIM].size, &error_fatal);
     memory_region_add_subregion(system_memory,
                                 memmap[MICROCHIP_PFSOC_E51_DTIM].base,
@@ -271,7 +271,7 @@ static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp)
      * leave it enabled all the time. This won't break anything, but will be
      * too generous to misbehaving guests.
      */
-    memory_region_init_ram(l2lim_mem, NULL, "microchip.pfsoc.l2lim",
+    memory_region_init_ram(l2lim_mem, OBJECT(dev), "microchip.pfsoc.l2lim",
                            memmap[MICROCHIP_PFSOC_L2LIM].size, &error_fatal);
     memory_region_add_subregion(system_memory,
                                 memmap[MICROCHIP_PFSOC_L2LIM].base,
@@ -549,10 +549,10 @@ static void microchip_icicle_kit_machine_init(MachineState *machine)
     /* Split RAM into low and high regions using aliases to machine->ram */
     mem_low_size = memmap[MICROCHIP_PFSOC_DRAM_LO].size;
     mem_high_size = machine->ram_size - mem_low_size;
-    memory_region_init_alias(mem_low, NULL,
+    memory_region_init_alias(mem_low, OBJECT(machine),
                              "microchip.icicle.kit.ram_low", machine->ram,
                              0, mem_low_size);
-    memory_region_init_alias(mem_high, NULL,
+    memory_region_init_alias(mem_high, OBJECT(machine),
                              "microchip.icicle.kit.ram_high", machine->ram,
                              mem_low_size, mem_high_size);
 
@@ -565,13 +565,13 @@ static void microchip_icicle_kit_machine_init(MachineState *machine)
                                 mem_high);
 
     /* Create aliases for the low and high RAM regions */
-    memory_region_init_alias(mem_low_alias, NULL,
+    memory_region_init_alias(mem_low_alias, OBJECT(machine),
                              "microchip.icicle.kit.ram_low.alias",
                              mem_low, 0, mem_low_size);
     memory_region_add_subregion(system_memory,
                                 memmap[MICROCHIP_PFSOC_DRAM_LO_ALIAS].base,
                                 mem_low_alias);
-    memory_region_init_alias(mem_high_alias, NULL,
+    memory_region_init_alias(mem_high_alias, OBJECT(machine),
                              "microchip.icicle.kit.ram_high.alias",
                              mem_high, 0, mem_high_size);
     memory_region_add_subregion(system_memory,
hw/riscv/sifive_u.c +2 -2
index aba6716b73..9d3f5c8f59 100644
@@ -477,7 +477,7 @@ static void sifive_u_machine_init(MachineState *machine)
                                 machine->ram);
 
     /* register QSPI0 Flash */
-    memory_region_init_ram(flash0, NULL, "riscv.sifive.u.flash0",
+    memory_region_init_ram(flash0, OBJECT(machine), "riscv.sifive.u.flash0",
                            memmap[SIFIVE_U_DEV_FLASH0].size, &error_fatal);
     memory_region_add_subregion(system_memory, memmap[SIFIVE_U_DEV_FLASH0].base,
                                 flash0);
@@ -763,7 +763,7 @@ static void sifive_u_soc_realize(DeviceState *dev, Error **errp)
      * leave it enabled all the time. This won't break anything, but will be
      * too generous to misbehaving guests.
      */
-    memory_region_init_ram(l2lim_mem, NULL, "riscv.sifive.u.l2lim",
+    memory_region_init_ram(l2lim_mem, OBJECT(dev), "riscv.sifive.u.l2lim",
                            memmap[SIFIVE_U_DEV_L2LIM].size, &error_fatal);
     memory_region_add_subregion(system_memory, memmap[SIFIVE_U_DEV_L2LIM].base,
                                 l2lim_mem);
hw/riscv/spike.c +1 -1
index c53409e4f1..9f1a1b5898 100644
@@ -179,7 +179,7 @@ static void spike_board_init(MachineState *machine)
         machine->ram);
 
     /* boot rom */
-    memory_region_init_rom(mask_rom, NULL, "riscv.spike.mrom",
+    memory_region_init_rom(mask_rom, OBJECT(machine), "riscv.spike.mrom",
                            memmap[SPIKE_MROM].size, &error_fatal);
     memory_region_add_subregion(system_memory, memmap[SPIKE_MROM].base,
                                 mask_rom);
hw/riscv/tt_atlantis.c +1 -1
index 068a0bc542..e378f6e856 100644
@@ -538,7 +538,7 @@ static void tt_atlantis_machine_init(MachineState *machine)
                                 s->memmap[TT_ATL_DDR_LO].base, ram_lo);
 
     /* Boot ROM */
-    memory_region_init_rom(bootrom, NULL, "tt-atlantis.bootrom",
+    memory_region_init_rom(bootrom, OBJECT(machine), "tt-atlantis.bootrom",
                            s->memmap[TT_ATL_BOOTROM].size, &error_fatal);
     memory_region_add_subregion(system_memory, s->memmap[TT_ATL_BOOTROM].base,
                                 bootrom);
hw/riscv/virt.c +1 -1
index 718b730a4d..3442edb87a 100644
@@ -1462,7 +1462,7 @@ static void virt_machine_init(MachineState *machine)
                                 machine->ram);
 
     /* boot rom */
-    memory_region_init_rom(mask_rom, NULL, "riscv_virt_board.mrom",
+    memory_region_init_rom(mask_rom, OBJECT(machine), "riscv_virt_board.mrom",
                            s->memmap[VIRT_MROM].size, &error_fatal);
     memory_region_add_subregion(system_memory, s->memmap[VIRT_MROM].base,
                                 mask_rom);
Signature · 1 line
2.47.1
#251 lore raw

RFC PATCH v2 94/137 hw/i386: Give memory regions an explicit owner

In reply to Alexander Graf

Convert memory_region_init*() calls that pass NULL owner to pass the enclosing PC/x86/microvm machine or device instead.

Thread X86MachineState through x86_isa_bios_init() so the isa-bios alias is owned by the machine that creates it.

No functional change intended.

RAMBlock idstrs are unchanged: the owners added here are Machine or SysBus devices, and memory_region_register_ram() maps both to dev=NULL for qemu_ram_set_idstr().

AI-used-for: code (refactoring)

---
 hw/i386/microvm.c          |  4 ++--
 hw/i386/pc.c               |  8 ++++----
 hw/i386/pc_piix.c          |  2 +-
 hw/i386/pc_q35.c           |  2 +-
 hw/i386/pc_sysfw.c         |  6 +++---
 hw/i386/x86-common.c       | 11 ++++++-----
 hw/i386/xen/xen-hvm.c      |  8 ++++----
 hw/i386/xen/xen_pvdevice.c |  2 +-
 include/hw/i386/x86.h      |  3 ++-
 9 files changed, 24 insertions(+), 22 deletions(-)
hw/i386/microvm.c +2 -2
index aa0e1ef155..751e3962fa 100644
@@ -305,7 +305,7 @@ static void microvm_memory_init(MicrovmMachineState *mms)
     }
 
     ram_below_4g = g_malloc(sizeof(*ram_below_4g));
-    memory_region_init_alias(ram_below_4g, NULL, "ram-below-4g", machine->ram,
+    memory_region_init_alias(ram_below_4g, OBJECT(mms), "ram-below-4g", machine->ram,
                              0, x86ms->below_4g_mem_size);
     memory_region_add_subregion(system_memory, 0, ram_below_4g);
 
@@ -313,7 +313,7 @@ static void microvm_memory_init(MicrovmMachineState *mms)
 
     if (x86ms->above_4g_mem_size > 0) {
         ram_above_4g = g_malloc(sizeof(*ram_above_4g));
-        memory_region_init_alias(ram_above_4g, NULL, "ram-above-4g",
+        memory_region_init_alias(ram_above_4g, OBJECT(mms), "ram-above-4g",
                                  machine->ram,
                                  x86ms->below_4g_mem_size,
                                  x86ms->above_4g_mem_size);
hw/i386/pc.c +4 -4
index e505391985..8057058ff0 100644
@@ -795,13 +795,13 @@ void pc_memory_init(PCMachineState *pcms,
      * done for backwards compatibility with older qemus.
      */
     ram_below_4g = g_malloc(sizeof(*ram_below_4g));
-    memory_region_init_alias(ram_below_4g, NULL, "ram-below-4g", machine->ram,
+    memory_region_init_alias(ram_below_4g, OBJECT(pcms), "ram-below-4g", machine->ram,
                              0, x86ms->below_4g_mem_size);
     memory_region_add_subregion(system_memory, 0, ram_below_4g);
     e820_add_entry(0, x86ms->below_4g_mem_size, E820_RAM);
     if (x86ms->above_4g_mem_size > 0) {
         ram_above_4g = g_malloc(sizeof(*ram_above_4g));
-        memory_region_init_alias(ram_above_4g, NULL, "ram-above-4g",
+        memory_region_init_alias(ram_above_4g, OBJECT(pcms), "ram-above-4g",
                                  machine->ram,
                                  x86ms->below_4g_mem_size,
                                  x86ms->above_4g_mem_size);
@@ -871,10 +871,10 @@ void pc_memory_init(PCMachineState *pcms,
     if (!is_tdx_vm()) {
         option_rom_mr = g_malloc(sizeof(*option_rom_mr));
         if (machine_require_guest_memfd(machine)) {
-            memory_region_init_ram_guest_memfd(option_rom_mr, NULL, "pc.rom",
+            memory_region_init_ram_guest_memfd(option_rom_mr, OBJECT(pcms), "pc.rom",
                                             PC_ROM_SIZE, &error_fatal);
         } else {
-            memory_region_init_ram(option_rom_mr, NULL, "pc.rom", PC_ROM_SIZE,
+            memory_region_init_ram(option_rom_mr, OBJECT(pcms), "pc.rom", PC_ROM_SIZE,
                                 &error_fatal);
             if (pcmc->pci_enabled) {
                 memory_region_set_readonly(option_rom_mr, true);
hw/i386/pc_piix.c +1 -1
index c9e6c61734..0b8d7d88b9 100644
@@ -191,7 +191,7 @@ static void pc_init1(MachineState *machine, const char *pci_type)
     }
 
     pci_memory = g_new(MemoryRegion, 1);
-    memory_region_init(pci_memory, NULL, "pci", UINT64_MAX);
+    memory_region_init(pci_memory, OBJECT(machine), "pci", UINT64_MAX);
 
     phb = OBJECT(qdev_new(OBJECT(machine), "i440fx", TYPE_I440FX_PCI_HOST_BRIDGE));
     object_property_set_link(phb, PCI_HOST_PROP_RAM_MEM,
hw/i386/pc_q35.c +1 -1
index 62625abed8..b2cdca8ade 100644
@@ -208,7 +208,7 @@ static void pc_q35_init(MachineState *machine)
                                                &error_abort);
 
     /* allocate ram and load rom/bios */
-    memory_region_init(pci_memory, NULL, "pci", UINT64_MAX);
+    memory_region_init(pci_memory, OBJECT(machine), "pci", UINT64_MAX);
     pc_memory_init(pcms, system_memory, pci_memory, pci_hole64_size);
 
     object_property_set_link(phb, PCI_HOST_PROP_RAM_MEM,
hw/i386/pc_sysfw.c +3 -3
index 02d75e2838..b536fca60f 100644
@@ -52,10 +52,10 @@ static void pc_isa_bios_init(PCMachineState *pcms, MemoryRegion *isa_bios,
     /* map the last 128KB of the BIOS in ISA space */
     isa_bios_size = MIN(flash_size, 128 * KiB);
     if (machine_require_guest_memfd(MACHINE(pcms))) {
-        memory_region_init_ram_guest_memfd(isa_bios, NULL, "isa-bios",
+        memory_region_init_ram_guest_memfd(isa_bios, OBJECT(pcms), "isa-bios",
                                            isa_bios_size, &error_fatal);
     } else {
-        memory_region_init_ram(isa_bios, NULL, "isa-bios", isa_bios_size,
+        memory_region_init_ram(isa_bios, OBJECT(pcms), "isa-bios", isa_bios_size,
                                &error_fatal);
     }
     memory_region_add_subregion_overlap(rom_memory,
@@ -189,7 +189,7 @@ static void pc_system_flash_map(PCMachineState *pcms,
         if (i == 0) {
             flash_mem = pflash_cfi01_get_memory(system_flash);
             if (pcmc->isa_bios_alias) {
-                x86_isa_bios_init(&x86ms->isa_bios, rom_memory, flash_mem,
+                x86_isa_bios_init(x86ms, &x86ms->isa_bios, rom_memory, flash_mem,
                                   true);
             } else {
                 pc_isa_bios_init(pcms, &x86ms->isa_bios, rom_memory, flash_mem);
hw/i386/x86-common.c +6 -5
index 73a53fbf3f..151a67ee5f 100644
@@ -993,13 +993,14 @@ void x86_load_linux(X86MachineState *x86ms,
     nb_option_roms++;
 }
 
-void x86_isa_bios_init(MemoryRegion *isa_bios, MemoryRegion *isa_memory,
+void x86_isa_bios_init(X86MachineState *x86ms, MemoryRegion *isa_bios,
+                       MemoryRegion *isa_memory,
                        MemoryRegion *bios, bool read_only)
 {
     uint64_t bios_size = memory_region_size(bios);
     uint64_t isa_bios_size = MIN(bios_size, 128 * KiB);
 
-    memory_region_init_alias(isa_bios, NULL, "isa-bios", bios,
+    memory_region_init_alias(isa_bios, OBJECT(x86ms), "isa-bios", bios,
                              bios_size - isa_bios_size, isa_bios_size);
     memory_region_add_subregion_overlap(isa_memory, 1 * MiB - isa_bios_size,
                                         isa_bios, 1);
@@ -1036,13 +1037,13 @@ static void load_bios_from_file(X86MachineState *x86ms, const char *bios_name,
 
     /* BIOS load */
     if (machine_require_guest_memfd(MACHINE(x86ms))) {
-        memory_region_init_ram_guest_memfd(&x86ms->bios, NULL, "pc.bios",
+        memory_region_init_ram_guest_memfd(&x86ms->bios, OBJECT(x86ms), "pc.bios",
                                            bios_size, &error_fatal);
         if (is_tdx_vm()) {
             tdx_set_tdvf_region(&x86ms->bios);
         }
     } else {
-        memory_region_init_ram(&x86ms->bios, NULL, "pc.bios",
+        memory_region_init_ram(&x86ms->bios, OBJECT(x86ms), "pc.bios",
                                bios_size, &error_fatal);
     }
     if (sev_enabled() || is_tdx_vm()) {
@@ -1107,7 +1108,7 @@ void x86_bios_rom_init(X86MachineState *x86ms, const char *default_firmware,
 
     if (!machine_require_guest_memfd(MACHINE(x86ms))) {
         /* map the last 128KB of the BIOS in ISA space */
-        x86_isa_bios_init(&x86ms->isa_bios, rom_memory, &x86ms->bios,
+        x86_isa_bios_init(x86ms, &x86ms->isa_bios, rom_memory, &x86ms->bios,
                           !isapc_ram_fw);
     }
 
hw/i386/xen/xen-hvm.c +4 -4
index d3ce082e07..01d851ce3e 100644
@@ -156,11 +156,11 @@ static void xen_ram_init(PCMachineState *pcms,
          */
         block_len = (4 * GiB) + x86ms->above_4g_mem_size;
     }
-    memory_region_init_ram(&xen_memory, NULL, "xen.ram", block_len,
+    memory_region_init_ram(&xen_memory, OBJECT(pcms), "xen.ram", block_len,
                            &error_fatal);
     *ram_memory_p = &xen_memory;
 
-    memory_region_init_alias(&ram_640k, NULL, "xen.ram.640k",
+    memory_region_init_alias(&ram_640k, OBJECT(pcms), "xen.ram.640k",
                              &xen_memory, 0, 0xa0000);
     memory_region_add_subregion(sysmem, 0, &ram_640k);
     /* Skip of the VGA IO memory space, it will be registered later by the VGA
@@ -169,12 +169,12 @@ static void xen_ram_init(PCMachineState *pcms,
      * The area between 0xc0000 and 0x100000 will be used by SeaBIOS to load
      * the Options ROM, so it is registered here as RAM.
      */
-    memory_region_init_alias(&ram_lo, NULL, "xen.ram.lo",
+    memory_region_init_alias(&ram_lo, OBJECT(pcms), "xen.ram.lo",
                              &xen_memory, 0xc0000,
                              x86ms->below_4g_mem_size - 0xc0000);
     memory_region_add_subregion(sysmem, 0xc0000, &ram_lo);
     if (x86ms->above_4g_mem_size > 0) {
-        memory_region_init_alias(&ram_hi, NULL, "xen.ram.hi",
+        memory_region_init_alias(&ram_hi, OBJECT(pcms), "xen.ram.hi",
                                  &xen_memory, 0x100000000ULL,
                                  x86ms->above_4g_mem_size);
         memory_region_add_subregion(sysmem, 0x100000000ULL, &ram_hi);
hw/i386/xen/xen_pvdevice.c +1 -1
index fab26a06af..6c255aeae1 100644
@@ -108,7 +108,7 @@ static void xen_pv_realize(PCIDevice *pci_dev, Error **errp)
 
     pci_conf[PCI_INTERRUPT_PIN] = 1;
 
-    memory_region_init_io(&d->mmio, NULL, &xen_pv_mmio_ops, d,
+    memory_region_init_io(&d->mmio, OBJECT(pci_dev), &xen_pv_mmio_ops, d,
                           "mmio", d->size);
 
     pci_register_bar(pci_dev, 1, PCI_BASE_ADDRESS_MEM_PREFETCH,
include/hw/i386/x86.h +2 -1
index 61d6ec1755..9d5d7694d4 100644
@@ -121,7 +121,8 @@ void x86_cpu_unplug_request_cb(HotplugHandler *hotplug_dev,
 void x86_cpu_unplug_cb(HotplugHandler *hotplug_dev,
                        DeviceState *dev, Error **errp);
 
-void x86_isa_bios_init(MemoryRegion *isa_bios, MemoryRegion *isa_memory,
+void x86_isa_bios_init(X86MachineState *x86ms, MemoryRegion *isa_bios,
+                       MemoryRegion *isa_memory,
                        MemoryRegion *bios, bool read_only);
 void x86_bios_rom_init(X86MachineState *x86ms, const char *default_firmware,
                        MemoryRegion *rom_memory, bool isapc_ram_fw);
Signature · 1 line
2.47.1
#252 lore raw

RFC PATCH v2 95/137 hw/arm: Give memory regions an explicit owner

In reply to Alexander Graf

Convert memory_region_init*() calls that pass NULL owner to pass the enclosing SoC device or machine instead.

Static helpers make_ram()/make_ram_alias() in mps2.c and mps2-tz.c, create_tag_ram() in virt.c, and exynos4_boards_init_ram() gain an Object *owner first argument. armsse.c:make_alias() and aspeed_install_boot_rom() already carry a QOM-derived first argument; use it.

hw/arm/omap1.c is handled in a separate commit as its 20+ non-QOM sub-init helpers all need owner threading.

No functional change intended.

RAMBlock idstrs are unchanged: the owners added here are Machine or SysBus devices, and memory_region_register_ram() maps both to dev=NULL for qemu_ram_set_idstr().

AI-used-for: code (refactoring)

---
 hw/arm/armsse.c            |  8 ++++----
 hw/arm/aspeed.c            |  2 +-
 hw/arm/aspeed_soc_common.c |  2 +-
 hw/arm/exynos4210.c        |  2 +-
 hw/arm/exynos4_boards.c    |  8 ++++----
 hw/arm/fsl-imx25.c         |  2 +-
 hw/arm/fsl-imx31.c         |  2 +-
 hw/arm/fsl-imx6.c          |  2 +-
 hw/arm/fsl-imx6ul.c        |  2 +-
 hw/arm/fsl-imx7.c          |  8 ++++----
 hw/arm/imx25_pdk.c         |  2 +-
 hw/arm/integratorcp.c      |  2 +-
 hw/arm/kzm.c               |  2 +-
 hw/arm/max78000_soc.c      |  2 +-
 hw/arm/mps2-tz.c           |  9 +++++----
 hw/arm/mps2.c              | 33 +++++++++++++++++----------------
 hw/arm/mps3r.c             |  4 ++--
 hw/arm/msf2-soc.c          |  2 +-
 hw/arm/msf2-som.c          |  2 +-
 hw/arm/musca.c             |  4 ++--
 hw/arm/musicpal.c          |  2 +-
 hw/arm/omap_sx1.c          | 14 +++++++-------
 hw/arm/realview.c          |  8 ++++----
 hw/arm/sbsa-ref.c          |  2 +-
 hw/arm/stellaris.c         |  4 ++--
 hw/arm/stm32f100_soc.c     |  2 +-
 hw/arm/stm32f205_soc.c     |  2 +-
 hw/arm/stm32f405_soc.c     |  4 ++--
 hw/arm/vexpress.c          |  8 ++++----
 hw/arm/virt.c              | 13 +++++++------
 hw/arm/xilinx_zynq.c       |  2 +-
 hw/arm/xlnx-zynqmp.c       |  2 +-
 32 files changed, 83 insertions(+), 80 deletions(-)
hw/arm/armsse.c +4 -4
index ddb210c895..81895ad370 100644
@@ -620,7 +620,7 @@ static uint32_t armsse_sys_config_value(ARMSSE *s, const ARMSSEInfo *info)
 static void make_alias(ARMSSE *s, MemoryRegion *mr, MemoryRegion *container,
                        const char *name, hwaddr base, hwaddr size, hwaddr orig)
 {
-    memory_region_init_alias(mr, NULL, name, container, orig, size);
+    memory_region_init_alias(mr, OBJECT(s), name, container, orig, size);
     /* The alias is even lower priority than unimplemented_device regions */
     memory_region_add_subregion_overlap(container, base, mr, -1500);
 }
@@ -1161,7 +1161,7 @@ static void armsse_realize(DeviceState *dev, Error **errp)
         SysBusDevice *sbd_mpc;
         uint32_t sram_bank_size = 1 << s->sram_addr_width;
 
-        memory_region_init_ram(&s->sram[i], NULL, ramname,
+        memory_region_init_ram(&s->sram[i], OBJECT(dev), ramname,
                                sram_bank_size, errp);
         g_free(ramname);
         if (*errp) {
@@ -1226,11 +1226,11 @@ static void armsse_realize(DeviceState *dev, Error **errp)
 
     if (info->has_tcms) {
         /* The SSE-300 has an ITCM at 0x0000_0000 and a DTCM at 0x2000_0000 */
-        memory_region_init_ram(&s->itcm, NULL, "sse300-itcm", 512 * KiB, errp);
+        memory_region_init_ram(&s->itcm, OBJECT(dev), "sse300-itcm", 512 * KiB, errp);
         if (*errp) {
             return;
         }
-        memory_region_init_ram(&s->dtcm, NULL, "sse300-dtcm", 512 * KiB, errp);
+        memory_region_init_ram(&s->dtcm, OBJECT(dev), "sse300-dtcm", 512 * KiB, errp);
         if (*errp) {
             return;
         }
hw/arm/aspeed.c +1 -1
index 2e76e09f8f..f9249a9851 100644
@@ -201,7 +201,7 @@ static void aspeed_machine_init(MachineState *machine)
     if (machine->kernel_filename && sc->num_cpus > 1) {
         /* With no u-boot we must set up a boot stub for the secondary CPU */
         MemoryRegion *smpboot = g_new(MemoryRegion, 1);
-        memory_region_init_ram(smpboot, NULL, "aspeed.smpboot",
+        memory_region_init_ram(smpboot, OBJECT(bmc), "aspeed.smpboot",
                                0x80, &error_abort);
         memory_region_add_subregion(get_system_memory(),
                                     AST_SMP_MAILBOX_BASE, smpboot);
hw/arm/aspeed_soc_common.c +1 -1
index 780a9659cc..c79b27c561 100644
@@ -177,7 +177,7 @@ void aspeed_install_boot_rom(AspeedSoCState *soc, BlockBackend *blk,
 {
     AspeedSoCClass *sc = ASPEED_SOC_GET_CLASS(soc);
 
-    memory_region_init_rom(boot_rom, NULL, "aspeed.boot_rom", rom_size,
+    memory_region_init_rom(boot_rom, OBJECT(soc), "aspeed.boot_rom", rom_size,
                            &error_abort);
     memory_region_add_subregion_overlap(&soc->spi_boot_container, 0,
                                         boot_rom, 1);
hw/arm/exynos4210.c +1 -1
index 74ce36c1e6..676915e814 100644
@@ -660,7 +660,7 @@ static void exynos4210_realize(DeviceState *socdev, Error **errp)
                                 &s->irom_alias_mem);
 
     /* Internal RAM */
-    memory_region_init_ram(&s->iram_mem, NULL, "exynos4210.iram",
+    memory_region_init_ram(&s->iram_mem, OBJECT(socdev), "exynos4210.iram",
                            EXYNOS4210_IRAM_SIZE, &error_fatal);
     memory_region_add_subregion(system_mem, EXYNOS4210_IRAM_BASE_ADDR,
                                 &s->iram_mem);
hw/arm/exynos4_boards.c +4 -4
index dce2c24860..8430317815 100644
@@ -88,14 +88,14 @@ static void lan9215_init(uint32_t base, qemu_irq irq)
     }
 }
 
-static void exynos4_boards_init_ram(Exynos4BoardState *s,
+static void exynos4_boards_init_ram(Object *owner, Exynos4BoardState *s,
                                     MemoryRegion *system_mem,
                                     unsigned long ram_size)
 {
     unsigned long mem_size = ram_size;
 
     if (mem_size > EXYNOS4210_DRAM_MAX_SIZE) {
-        memory_region_init_ram(&s->dram1_mem, NULL, "exynos4210.dram1",
+        memory_region_init_ram(&s->dram1_mem, owner, "exynos4210.dram1",
                                mem_size - EXYNOS4210_DRAM_MAX_SIZE,
                                &error_fatal);
         memory_region_add_subregion(system_mem, EXYNOS4210_DRAM1_BASE_ADDR,
@@ -103,7 +103,7 @@ static void exynos4_boards_init_ram(Exynos4BoardState *s,
         mem_size = EXYNOS4210_DRAM_MAX_SIZE;
     }
 
-    memory_region_init_ram(&s->dram0_mem, NULL, "exynos4210.dram0", mem_size,
+    memory_region_init_ram(&s->dram0_mem, owner, "exynos4210.dram0", mem_size,
                            &error_fatal);
     memory_region_add_subregion(system_mem, EXYNOS4210_DRAM0_BASE_ADDR,
                                 &s->dram0_mem);
@@ -122,7 +122,7 @@ exynos4_boards_init_common(MachineState *machine,
     exynos4_board_binfo.gic_cpu_if_addr =
             EXYNOS4210_SMP_PRIVATE_BASE_ADDR + 0x100;
 
-    exynos4_boards_init_ram(s, get_system_memory(),
+    exynos4_boards_init_ram(OBJECT(machine), s, get_system_memory(),
                             exynos4_board_ram_size[board_type]);
 
     object_initialize_child(OBJECT(machine), "soc", &s->soc,
hw/arm/fsl-imx25.c +1 -1
index 7f65f4ca4b..f589c83567 100644
@@ -292,7 +292,7 @@ static void fsl_imx25_realize(DeviceState *dev, Error **errp)
                                 &s->rom[1]);
 
     /* initialize internal RAM (128 KB) */
-    if (!memory_region_init_ram(&s->iram, NULL, "imx25.iram",
+    if (!memory_region_init_ram(&s->iram, OBJECT(dev), "imx25.iram",
                                 FSL_IMX25_IRAM_SIZE, errp)) {
         return;
     }
hw/arm/fsl-imx31.c +1 -1
index 190f863355..fc387bbbc3 100644
@@ -204,7 +204,7 @@ static void fsl_imx31_realize(DeviceState *dev, Error **errp)
                                 &s->rom);
 
     /* initialize internal RAM (16 KB) */
-    if (!memory_region_init_ram(&s->iram, NULL, "imx31.iram",
+    if (!memory_region_init_ram(&s->iram, OBJECT(dev), "imx31.iram",
                                 FSL_IMX31_IRAM_SIZE, errp)) {
         return;
     }
hw/arm/fsl-imx6.c +1 -1
index f0fbdc1a68..99250910cb 100644
@@ -491,7 +491,7 @@ static void fsl_imx6_realize(DeviceState *dev, Error **errp)
                                 &s->caam);
 
     /* OCRAM memory */
-    if (!memory_region_init_ram(&s->ocram, NULL, "imx6.ocram",
+    if (!memory_region_init_ram(&s->ocram, OBJECT(dev), "imx6.ocram",
                                 FSL_IMX6_OCRAM_SIZE, errp)) {
         return;
     }
hw/arm/fsl-imx6ul.c +1 -1
index adbb896fd1..f830dce9df 100644
@@ -699,7 +699,7 @@ static void fsl_imx6ul_realize(DeviceState *dev, Error **errp)
     /*
      * OCRAM memory
      */
-    memory_region_init_ram(&s->ocram, NULL, "imx6ul.ocram",
+    memory_region_init_ram(&s->ocram, OBJECT(dev), "imx6ul.ocram",
                            FSL_IMX6UL_OCRAM_MEM_SIZE,
                            &error_abort);
     memory_region_add_subregion(get_system_memory(), FSL_IMX6UL_OCRAM_MEM_ADDR,
hw/arm/fsl-imx7.c +4 -4
index 07a5ae8cd0..ceb26b4efd 100644
@@ -689,7 +689,7 @@ static void fsl_imx7_realize(DeviceState *dev, Error **errp)
     /*
      * OCRAM memory
      */
-    memory_region_init_ram(&s->ocram, NULL, "imx7.ocram",
+    memory_region_init_ram(&s->ocram, OBJECT(dev), "imx7.ocram",
                            FSL_IMX7_OCRAM_MEM_SIZE,
                            &error_abort);
     memory_region_add_subregion(get_system_memory(), FSL_IMX7_OCRAM_MEM_ADDR,
@@ -698,7 +698,7 @@ static void fsl_imx7_realize(DeviceState *dev, Error **errp)
     /*
      * OCRAM EPDC memory
      */
-    memory_region_init_ram(&s->ocram_epdc, NULL, "imx7.ocram_epdc",
+    memory_region_init_ram(&s->ocram_epdc, OBJECT(dev), "imx7.ocram_epdc",
                            FSL_IMX7_OCRAM_EPDC_SIZE,
                            &error_abort);
     memory_region_add_subregion(get_system_memory(), FSL_IMX7_OCRAM_EPDC_ADDR,
@@ -707,7 +707,7 @@ static void fsl_imx7_realize(DeviceState *dev, Error **errp)
     /*
      * OCRAM PXP memory
      */
-    memory_region_init_ram(&s->ocram_pxp, NULL, "imx7.ocram_pxp",
+    memory_region_init_ram(&s->ocram_pxp, OBJECT(dev), "imx7.ocram_pxp",
                            FSL_IMX7_OCRAM_PXP_SIZE,
                            &error_abort);
     memory_region_add_subregion(get_system_memory(), FSL_IMX7_OCRAM_PXP_ADDR,
@@ -716,7 +716,7 @@ static void fsl_imx7_realize(DeviceState *dev, Error **errp)
     /*
      * OCRAM_S memory
      */
-    memory_region_init_ram(&s->ocram_s, NULL, "imx7.ocram_s",
+    memory_region_init_ram(&s->ocram_s, OBJECT(dev), "imx7.ocram_s",
                            FSL_IMX7_OCRAM_S_SIZE,
                            &error_abort);
     memory_region_add_subregion(get_system_memory(), FSL_IMX7_OCRAM_S_ADDR,
hw/arm/imx25_pdk.c +1 -1
index 9351d53850..cecfc25e9a 100644
@@ -104,7 +104,7 @@ static void imx25_pdk_init(MachineState *machine)
         ram_size -= size;
 
         if (size < ram[i].size) {
-            memory_region_init_alias(&s->ram_alias, NULL, "ram.alias",
+            memory_region_init_alias(&s->ram_alias, OBJECT(machine), "ram.alias",
                                      machine->ram,
                                      alias_offset, ram[i].size - size);
             memory_region_add_subregion(get_system_memory(),
hw/arm/integratorcp.c +1 -1
index ed715a3eb8..81c0bce8f9 100644
@@ -617,7 +617,7 @@ static void integratorcp_init(MachineState *machine)
     /* SDRAM at address zero*/
     memory_region_add_subregion(address_space_mem, 0, machine->ram);
     /* And again at address 0x80000000 */
-    memory_region_init_alias(ram_alias, NULL, "ram.alias", machine->ram,
+    memory_region_init_alias(ram_alias, OBJECT(machine), "ram.alias", machine->ram,
                              0, ram_size);
     memory_region_add_subregion(address_space_mem, 0x80000000, ram_alias);
 
hw/arm/kzm.c +1 -1
index 36e12bb362..3e879c492d 100644
@@ -104,7 +104,7 @@ static void kzm_init(MachineState *machine)
         ram_size -= size;
 
         if (size < ram[i].size) {
-            memory_region_init_alias(&s->ram_alias, NULL, "ram.alias",
+            memory_region_init_alias(&s->ram_alias, OBJECT(machine), "ram.alias",
                                      machine->ram,
                                      alias_offset, ram[i].size - size);
             memory_region_add_subregion(get_system_memory(),
hw/arm/max78000_soc.c +1 -1
index b8e0265de2..41cfaee925 100644
@@ -74,7 +74,7 @@ static void max78000_soc_realize(DeviceState *dev_soc, Error **errp)
 
     memory_region_add_subregion(system_memory, FLASH_BASE_ADDRESS, &s->flash);
 
-    memory_region_init_ram(&s->sram, NULL, "MAX78000.sram", SRAM_SIZE,
+    memory_region_init_ram(&s->sram, obj, "MAX78000.sram", SRAM_SIZE,
                            &err);
 
     gcrdev = DEVICE(&s->gcr);
hw/arm/mps2-tz.c +5 -4
index 32e3db1134..a57915e208 100644
@@ -338,7 +338,7 @@ static MemoryRegion *mr_for_raminfo(MPS2TZMachineState *mms,
     assert(raminfo->mrindex < MPS2TZ_RAM_MAX);
     ram = &mms->ram[raminfo->mrindex];
 
-    memory_region_init_ram(ram, NULL, raminfo->name,
+    memory_region_init_ram(ram, OBJECT(mms), raminfo->name,
                            raminfo->size, &error_fatal);
     if (raminfo->flags & IS_ROM) {
         memory_region_set_readonly(ram, true);
@@ -349,10 +349,10 @@ static MemoryRegion *mr_for_raminfo(MPS2TZMachineState *mms,
 /* Create an alias of an entire original MemoryRegion @orig
  * located at @base in the memory map.
  */
-static void make_ram_alias(MemoryRegion *mr, const char *name,
+static void make_ram_alias(Object *owner, MemoryRegion *mr, const char *name,
                            MemoryRegion *orig, hwaddr base)
 {
-    memory_region_init_alias(mr, NULL, name, orig, 0,
+    memory_region_init_alias(mr, owner, name, orig, 0,
                              memory_region_size(orig));
     memory_region_add_subregion(get_system_memory(), base, mr);
 }
@@ -767,7 +767,8 @@ static void create_non_mpc_ram(MPS2TZMachineState *mms)
         if (p->flags & IS_ALIAS) {
             SysBusDevice *mpc_sbd = SYS_BUS_DEVICE(&mms->mpc[p->mpc]);
             MemoryRegion *upstream = sysbus_mmio_get_region(mpc_sbd, 1);
-            make_ram_alias(&mms->ram[p->mrindex], p->name, upstream, p->base);
+            make_ram_alias(OBJECT(mms), &mms->ram[p->mrindex], p->name,
+                           upstream, p->base);
         } else if (p->mpc == -1) {
             /* RAM not behind an MPC */
             MemoryRegion *mr = mr_for_raminfo(mms, p);
hw/arm/mps2.c +17 -16
index 23a814e4e4..1dec4a5d4d 100644
@@ -115,20 +115,20 @@ OBJECT_DECLARE_TYPE(MPS2MachineState, MPS2MachineClass, MPS2_MACHINE)
 /* Initialize the auxiliary RAM region @mr and map it into
  * the memory map at @base.
  */
-static void make_ram(MemoryRegion *mr, const char *name,
+static void make_ram(Object *owner, MemoryRegion *mr, const char *name,
                      hwaddr base, hwaddr size)
 {
-    memory_region_init_ram(mr, NULL, name, size, &error_fatal);
+    memory_region_init_ram(mr, owner, name, size, &error_fatal);
     memory_region_add_subregion(get_system_memory(), base, mr);
 }
 
 /* Create an alias of an entire original MemoryRegion @orig
  * located at @base in the memory map.
  */
-static void make_ram_alias(MemoryRegion *mr, const char *name,
+static void make_ram_alias(Object *owner, MemoryRegion *mr, const char *name,
                            MemoryRegion *orig, hwaddr base)
 {
-    memory_region_init_alias(mr, NULL, name, orig, 0,
+    memory_region_init_alias(mr, owner, name, orig, 0,
                              memory_region_size(orig));
     memory_region_add_subregion(get_system_memory(), base, mr);
 }
@@ -192,12 +192,12 @@ static void mps2_common_init(MachineState *machine)
     memory_region_add_subregion(system_memory, mmc->psram_base, machine->ram);
 
     if (mmc->has_block_ram) {
-        make_ram(&mms->blockram, "mps.blockram", 0x01000000, 0x4000);
-        make_ram_alias(&mms->blockram_m1, "mps.blockram_m1",
+        make_ram(obj, &mms->blockram, "mps.blockram", 0x01000000, 0x4000);
+        make_ram_alias(obj, &mms->blockram_m1, "mps.blockram_m1",
                        &mms->blockram, 0x01004000);
-        make_ram_alias(&mms->blockram_m2, "mps.blockram_m2",
+        make_ram_alias(obj, &mms->blockram_m2, "mps.blockram_m2",
                        &mms->blockram, 0x01008000);
-        make_ram_alias(&mms->blockram_m3, "mps.blockram_m3",
+        make_ram_alias(obj, &mms->blockram_m3, "mps.blockram_m3",
                        &mms->blockram, 0x0100c000);
     }
 
@@ -205,17 +205,18 @@ static void mps2_common_init(MachineState *machine)
     case FPGA_AN385:
     case FPGA_AN386:
     case FPGA_AN500:
-        make_ram(&mms->ssram1, "mps.ssram1", 0x0, 0x400000);
-        make_ram_alias(&mms->ssram1_m, "mps.ssram1_m", &mms->ssram1, 0x400000);
-        make_ram(&mms->ssram23, "mps.ssram23", 0x20000000, 0x400000);
-        make_ram_alias(&mms->ssram23_m, "mps.ssram23_m",
+        make_ram(obj, &mms->ssram1, "mps.ssram1", 0x0, 0x400000);
+        make_ram_alias(obj, &mms->ssram1_m, "mps.ssram1_m",
+                       &mms->ssram1, 0x400000);
+        make_ram(obj, &mms->ssram23, "mps.ssram23", 0x20000000, 0x400000);
+        make_ram_alias(obj, &mms->ssram23_m, "mps.ssram23_m",
                        &mms->ssram23, 0x20400000);
         break;
     case FPGA_AN511:
-        make_ram(&mms->blockram, "mps.blockram", 0x0, 0x40000);
-        make_ram(&mms->ssram1, "mps.ssram1", 0x00400000, 0x00800000);
-        make_ram(&mms->sram, "mps.sram", 0x20000000, 0x20000);
-        make_ram(&mms->ssram23, "mps.ssram23", 0x20400000, 0x400000);
+        make_ram(obj, &mms->blockram, "mps.blockram", 0x0, 0x40000);
+        make_ram(obj, &mms->ssram1, "mps.ssram1", 0x00400000, 0x00800000);
+        make_ram(obj, &mms->sram, "mps.sram", 0x20000000, 0x20000);
+        make_ram(obj, &mms->ssram23, "mps.ssram23", 0x20400000, 0x400000);
         break;
     default:
         g_assert_not_reached();
hw/arm/mps3r.c +2 -2
index 4d432de6ba..d6c29c1172 100644
@@ -215,7 +215,7 @@ static MemoryRegion *mr_for_raminfo(MPS3RMachineState *mms,
     assert(raminfo->mrindex < MPS3R_RAM_MAX);
     ram = &mms->ram[raminfo->mrindex];
 
-    memory_region_init_ram(ram, NULL, raminfo->name,
+    memory_region_init_ram(ram, OBJECT(mms), raminfo->name,
                            raminfo->size, &error_fatal);
     if (raminfo->flags & IS_ROM) {
         memory_region_set_readonly(ram, true);
@@ -397,7 +397,7 @@ static void mps3r_common_init(MachineState *machine)
         object_unref(mms->cpu[i]);
 
         /* Per-CPU RAM */
-        memory_region_init_ram(&mms->cpu_ram[i], NULL, ramname,
+        memory_region_init_ram(&mms->cpu_ram[i], OBJECT(mms), ramname,
                                0x1000, &error_fatal);
         memory_region_add_subregion(&mms->cpu_sysmem[i], 0xe7c01000,
                                     &mms->cpu_ram[i]);
hw/arm/msf2-soc.c +1 -1
index c03778c439..ce320a5a38 100644
@@ -128,7 +128,7 @@ static void m2sxxx_soc_realize(DeviceState *dev_soc, Error **errp)
     memory_region_add_subregion(system_memory, ENVM_BASE_ADDRESS, &s->nvm);
     memory_region_add_subregion(system_memory, 0, &s->nvm_alias);
 
-    memory_region_init_ram(&s->sram, NULL, "MSF2.eSRAM", s->esram_size,
+    memory_region_init_ram(&s->sram, OBJECT(dev_soc), "MSF2.eSRAM", s->esram_size,
                            &error_fatal);
     memory_region_add_subregion(system_memory, SRAM_BASE_ADDRESS, &s->sram);
 
hw/arm/msf2-som.c +1 -1
index 0d0e2514dd..5493f1cf70 100644
@@ -55,7 +55,7 @@ static void emcraft_sf2_s2s010_init(MachineState *machine)
     MemoryRegion *ddr = g_new(MemoryRegion, 1);
     Clock *m3clk;
 
-    memory_region_init_ram(ddr, NULL, "ddr-ram", DDR_SIZE,
+    memory_region_init_ram(ddr, OBJECT(machine), "ddr-ram", DDR_SIZE,
                            &error_fatal);
     memory_region_add_subregion(sysmem, DDR_BASE_ADDRESS, ddr);
 
hw/arm/musca.c +2 -2
index 75d82eebca..38eac4af76 100644
@@ -235,12 +235,12 @@ static MemoryRegion *make_mpc(MuscaMachineState *mms, void *opaque,
     switch (mpcinfo[i].type) {
     case MPC_ROM:
         downstream = &mms->ram[i];
-        memory_region_init_rom(downstream, NULL, mpcinfo[i].name,
+        memory_region_init_rom(downstream, OBJECT(mms), mpcinfo[i].name,
                                mpcinfo[i].size, &error_fatal);
         break;
     case MPC_RAM:
         downstream = &mms->ram[i];
-        memory_region_init_ram(downstream, NULL, mpcinfo[i].name,
+        memory_region_init_ram(downstream, OBJECT(mms), mpcinfo[i].name,
                                mpcinfo[i].size, &error_fatal);
         break;
     case MPC_CRYPTOISLAND:
hw/arm/musicpal.c +1 -1
index 86ea348d3d..fda42f71d5 100644
@@ -1236,7 +1236,7 @@ static void musicpal_init(MachineState *machine)
 
     memory_region_add_subregion(address_space_mem, 0, machine->ram);
 
-    memory_region_init_ram(sram, NULL, "musicpal.sram", MP_SRAM_SIZE,
+    memory_region_init_ram(sram, OBJECT(machine), "musicpal.sram", MP_SRAM_SIZE,
                            &error_fatal);
     memory_region_add_subregion(address_space_mem, MP_SRAM_BASE, sram);
 
hw/arm/omap_sx1.c +7 -7
index 1bd6c6d4bc..f8d54c2716 100644
@@ -128,22 +128,22 @@ static void sx1_init(MachineState *machine, const int version)
     mpu = omap310_mpu_init(OBJECT(machine), machine->ram, machine->cpu_type);
 
     /* External Flash (EMIFS) */
-    memory_region_init_rom(flash, NULL, "omap_sx1.flash0-0", flash_size,
+    memory_region_init_rom(flash, OBJECT(machine), "omap_sx1.flash0-0", flash_size,
                            &error_fatal);
     memory_region_add_subregion(address_space, OMAP_CS0_BASE, flash);
 
-    memory_region_init_io(&cs[0], NULL, &static_ops, &cs0val,
+    memory_region_init_io(&cs[0], OBJECT(machine), &static_ops, &cs0val,
                           "sx1.cs0", OMAP_CS0_SIZE - flash_size);
     memory_region_add_subregion(address_space,
                                 OMAP_CS0_BASE + flash_size, &cs[0]);
 
 
-    memory_region_init_io(&cs[2], NULL, &static_ops, &cs2val,
+    memory_region_init_io(&cs[2], OBJECT(machine), &static_ops, &cs2val,
                           "sx1.cs2", OMAP_CS2_SIZE);
     memory_region_add_subregion(address_space,
                                 OMAP_CS2_BASE, &cs[2]);
 
-    memory_region_init_io(&cs[3], NULL, &static_ops, &cs3val,
+    memory_region_init_io(&cs[3], OBJECT(machine), &static_ops, &cs3val,
                           "sx1.cs3", OMAP_CS3_SIZE);
     memory_region_add_subregion(address_space,
                                 OMAP_CS3_BASE, &cs[3]);
@@ -160,11 +160,11 @@ static void sx1_init(MachineState *machine, const int version)
     if ((version == 1) &&
             (dinfo = drive_get(IF_PFLASH, 0, fl_idx)) != NULL) {
         MemoryRegion *flash_1 = g_new(MemoryRegion, 1);
-        memory_region_init_rom(flash_1, NULL, "omap_sx1.flash1-0",
+        memory_region_init_rom(flash_1, OBJECT(machine), "omap_sx1.flash1-0",
                                FLASH1_SIZE, &error_fatal);
         memory_region_add_subregion(address_space, OMAP_CS1_BASE, flash_1);
 
-        memory_region_init_io(&cs[1], NULL, &static_ops, &cs1val,
+        memory_region_init_io(&cs[1], OBJECT(machine), &static_ops, &cs1val,
                               "sx1.cs1", OMAP_CS1_SIZE - FLASH1_SIZE);
         memory_region_add_subregion(address_space,
                                 OMAP_CS1_BASE + FLASH1_SIZE, &cs[1]);
@@ -175,7 +175,7 @@ static void sx1_init(MachineState *machine, const int version)
                               SECTOR_SIZE, 4, 0, 0, 0, 0, 0);
         fl_idx++;
     } else {
-        memory_region_init_io(&cs[1], NULL, &static_ops, &cs1val,
+        memory_region_init_io(&cs[1], OBJECT(machine), &static_ops, &cs1val,
                               "sx1.cs1", OMAP_CS1_SIZE);
         memory_region_add_subregion(address_space,
                                 OMAP_CS1_BASE, &cs[1]);
hw/arm/realview.c +4 -4
index 2441137222..73bfffa6e6 100644
@@ -159,18 +159,18 @@ static void realview_init(MachineState *machine,
         ram_lo = g_new(MemoryRegion, 1);
         low_ram_size = ram_size - 0x20000000;
         ram_size = 0x20000000;
-        memory_region_init_ram(ram_lo, NULL, "realview.lowmem", low_ram_size,
+        memory_region_init_ram(ram_lo, OBJECT(machine), "realview.lowmem", low_ram_size,
                                &error_fatal);
         memory_region_add_subregion(sysmem, 0x20000000, ram_lo);
     }
 
-    memory_region_init_ram(ram_hi, NULL, "realview.highmem", ram_size,
+    memory_region_init_ram(ram_hi, OBJECT(machine), "realview.highmem", ram_size,
                            &error_fatal);
     low_ram_size = ram_size;
     if (low_ram_size > 0x10000000)
       low_ram_size = 0x10000000;
     /* SDRAM at address zero.  */
-    memory_region_init_alias(ram_alias, NULL, "realview.alias",
+    memory_region_init_alias(ram_alias, OBJECT(machine), "realview.alias",
                              ram_hi, 0, low_ram_size);
     memory_region_add_subregion(sysmem, 0, ram_alias);
     if (is_pb) {
@@ -396,7 +396,7 @@ static void realview_init(MachineState *machine,
        startup code.  I guess this works on real hardware because the
        BootROM happens to be in ROM/flash or in memory that isn't clobbered
        until after Linux boots the secondary CPUs.  */
-    memory_region_init_ram(ram_hack, NULL, "realview.hack", 0x1000,
+    memory_region_init_ram(ram_hack, OBJECT(machine), "realview.hack", 0x1000,
                            &error_fatal);
     memory_region_add_subregion(sysmem, SMP_BOOT_ADDR, ram_hack);
 
hw/arm/sbsa-ref.c +1 -1
index bb35de1616..1df8efd207 100644
@@ -410,7 +410,7 @@ static void create_secure_ram(SBSAMachineState *sms,
     hwaddr base = sbsa_ref_memmap[SBSA_SECURE_MEM].base;
     hwaddr size = sbsa_ref_memmap[SBSA_SECURE_MEM].size;
 
-    memory_region_init_ram(secram, NULL, "sbsa-ref.secure-ram", size,
+    memory_region_init_ram(secram, OBJECT(sms), "sbsa-ref.secure-ram", size,
                            &error_fatal);
     memory_region_add_subregion(secure_sysmem, base, secram);
 }
hw/arm/stellaris.c +2 -2
index 6a732a3c11..1bc428e063 100644
@@ -1084,11 +1084,11 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
     object_property_add_child(OBJECT(ms), "soc", soc_container);
 
     /* Flash programming is done via the SCU, so pretend it is ROM.  */
-    memory_region_init_rom(flash, NULL, "stellaris.flash", flash_size,
+    memory_region_init_rom(flash, OBJECT(ms), "stellaris.flash", flash_size,
                            &error_fatal);
     memory_region_add_subregion(system_memory, 0, flash);
 
-    memory_region_init_ram(sram, NULL, "stellaris.sram", sram_size,
+    memory_region_init_ram(sram, OBJECT(ms), "stellaris.sram", sram_size,
                            &error_fatal);
     memory_region_add_subregion(system_memory, 0x20000000, sram);
 
hw/arm/stm32f100_soc.c +1 -1
index e9e722f359..d6d81c1338 100644
@@ -108,7 +108,7 @@ static void stm32f100_soc_realize(DeviceState *dev_soc, Error **errp)
     memory_region_add_subregion(system_memory, 0, &s->flash_alias);
 
     /* Init SRAM region */
-    memory_region_init_ram(&s->sram, NULL, "STM32F100.sram", SRAM_SIZE,
+    memory_region_init_ram(&s->sram, OBJECT(dev_soc), "STM32F100.sram", SRAM_SIZE,
                            &error_fatal);
     memory_region_add_subregion(system_memory, SRAM_BASE_ADDRESS, &s->sram);
 
hw/arm/stm32f205_soc.c +1 -1
index a03c6b4002..2997e7d777 100644
@@ -121,7 +121,7 @@ static void stm32f205_soc_realize(DeviceState *dev_soc, Error **errp)
     memory_region_add_subregion(system_memory, FLASH_BASE_ADDRESS, &s->flash);
     memory_region_add_subregion(system_memory, 0, &s->flash_alias);
 
-    memory_region_init_ram(&s->sram, NULL, "STM32F205.sram", SRAM_SIZE,
+    memory_region_init_ram(&s->sram, OBJECT(dev_soc), "STM32F205.sram", SRAM_SIZE,
                            &error_fatal);
     memory_region_add_subregion(system_memory, SRAM_BASE_ADDRESS, &s->sram);
 
hw/arm/stm32f405_soc.c +2 -2
index dc9b3053a5..4783f3f64a 100644
@@ -134,7 +134,7 @@ static void stm32f405_soc_realize(DeviceState *dev_soc, Error **errp)
     memory_region_add_subregion(system_memory, FLASH_BASE_ADDRESS, &s->flash);
     memory_region_add_subregion(system_memory, 0, &s->flash_alias);
 
-    memory_region_init_ram(&s->sram, NULL, "STM32F405.sram", SRAM_SIZE,
+    memory_region_init_ram(&s->sram, OBJECT(dev_soc), "STM32F405.sram", SRAM_SIZE,
                            &err);
     if (err != NULL) {
         error_propagate(errp, err);
@@ -142,7 +142,7 @@ static void stm32f405_soc_realize(DeviceState *dev_soc, Error **errp)
     }
     memory_region_add_subregion(system_memory, SRAM_BASE_ADDRESS, &s->sram);
 
-    memory_region_init_ram(&s->ccm, NULL, "STM32F405.ccm", CCM_SIZE,
+    memory_region_init_ram(&s->ccm, OBJECT(dev_soc), "STM32F405.ccm", CCM_SIZE,
                            &err);
     if (err != NULL) {
         error_propagate(errp, err);
hw/arm/vexpress.c +4 -4
index a643c6b079..f877ccf330 100644
@@ -392,7 +392,7 @@ static void a15_daughterboard_init(VexpressMachineState *vms,
     /* 0x2b060000: SP805 watchdog: not modelled */
     /* 0x2b0a0000: PL341 dynamic memory controller: not modelled */
     /* 0x2e000000: system SRAM */
-    memory_region_init_ram(&vms->a15sram, NULL, "vexpress.a15sram", 0x10000,
+    memory_region_init_ram(&vms->a15sram, OBJECT(vms), "vexpress.a15sram", 0x10000,
                            &error_fatal);
     memory_region_add_subregion(sysmem, 0x2e000000, &vms->a15sram);
 
@@ -677,7 +677,7 @@ static void vexpress_common_init(MachineState *machine)
         /* Map flash 0 as an alias into low memory */
         MemoryRegion *flash0mem;
         flash0mem = sysbus_mmio_get_region(SYS_BUS_DEVICE(pflash0), 0);
-        memory_region_init_alias(&vms->flashalias, NULL, "vexpress.flashalias",
+        memory_region_init_alias(&vms->flashalias, OBJECT(vms), "vexpress.flashalias",
                                  flash0mem, 0, VEXPRESS_FLASH_SIZE);
         memory_region_add_subregion(sysmem, map[VE_NORFLASHALIAS], &vms->flashalias);
     }
@@ -687,12 +687,12 @@ static void vexpress_common_init(MachineState *machine)
                              "vexpress.flash1", dinfo);
 
     sram_size = 0x2000000;
-    memory_region_init_ram(&vms->sram, NULL, "vexpress.sram", sram_size,
+    memory_region_init_ram(&vms->sram, OBJECT(vms), "vexpress.sram", sram_size,
                            &error_fatal);
     memory_region_add_subregion(sysmem, map[VE_SRAM], &vms->sram);
 
     vram_size = 0x800000;
-    memory_region_init_ram(&vms->vram, NULL, "vexpress.vram", vram_size,
+    memory_region_init_ram(&vms->vram, OBJECT(vms), "vexpress.vram", vram_size,
                            &error_fatal);
     memory_region_add_subregion(sysmem, map[VE_VIDEORAM], &vms->vram);
 
hw/arm/virt.c +7 -6
index 8bb20e692e..beb2d481ce 100644
@@ -2308,13 +2308,13 @@ static void create_platform_bus(VirtMachineState *vms)
                                 sysbus_mmio_get_region(s, 0));
 }
 
-static void create_tag_ram(MemoryRegion *tag_sysmem,
+static void create_tag_ram(Object *owner, MemoryRegion *tag_sysmem,
                            hwaddr base, hwaddr size,
                            const char *name)
 {
     MemoryRegion *tagram = g_new(MemoryRegion, 1);
 
-    memory_region_init_ram(tagram, NULL, name, size / 32, &error_fatal);
+    memory_region_init_ram(tagram, owner, name, size / 32, &error_fatal);
     memory_region_add_subregion(tag_sysmem, base / 32, tagram);
 }
 
@@ -2328,7 +2328,7 @@ static void create_secure_ram(VirtMachineState *vms,
     hwaddr size = vms->memmap[VIRT_SECURE_MEM].size;
     MachineState *ms = MACHINE(vms);
 
-    memory_region_init_ram(secram, NULL, "virt.secure-ram", size,
+    memory_region_init_ram(secram, OBJECT(vms), "virt.secure-ram", size,
                            &error_fatal);
     memory_region_add_subregion(secure_sysmem, base, secram);
 
@@ -2340,7 +2340,8 @@ static void create_secure_ram(VirtMachineState *vms,
     qemu_fdt_setprop_string(ms->fdt, nodename, "secure-status", "okay");
 
     if (secure_tag_sysmem) {
-        create_tag_ram(secure_tag_sysmem, base, size, "mach-virt.secure-tag");
+        create_tag_ram(OBJECT(vms), secure_tag_sysmem, base, size,
+                       "mach-virt.secure-tag");
     }
 
     g_free(nodename);
@@ -2840,7 +2841,7 @@ static void virt_post_cpus_gic_realized(VirtMachineState *vms,
                 exit(1);
             }
 
-            memory_region_init_ram(pvtime, NULL, "pvtime", pvtime_size, NULL);
+            memory_region_init_ram(pvtime, OBJECT(vms), "pvtime", pvtime_size, NULL);
             memory_region_add_subregion(sysmem, pvtime_reg_base, pvtime);
         }
         if (!aarch64 && vms->virt) {
@@ -3200,7 +3201,7 @@ static void machvirt_init(MachineState *machine)
     }
 
     if (tag_sysmem) {
-        create_tag_ram(tag_sysmem, vms->memmap[VIRT_MEM].base,
+        create_tag_ram(OBJECT(vms), tag_sysmem, vms->memmap[VIRT_MEM].base,
                        machine->ram_size, "mach-virt.tag");
     }
 
hw/arm/xilinx_zynq.c +1 -1
index 30f0ce5b5f..441289e63f 100644
@@ -238,7 +238,7 @@ static void zynq_init(MachineState *machine)
     memory_region_add_subregion(address_space_mem, 0, machine->ram);
 
     /* 256K of on-chip memory */
-    memory_region_init_ram(ocm_ram, NULL, "zynq.ocm_ram", 256 * KiB,
+    memory_region_init_ram(ocm_ram, OBJECT(machine), "zynq.ocm_ram", 256 * KiB,
                            &error_fatal);
     memory_region_add_subregion(address_space_mem, 0xFFFC0000, ocm_ram);
 
hw/arm/xlnx-zynqmp.c +1 -1
index e4a10861a8..a25d5d3158 100644
@@ -510,7 +510,7 @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp)
     for (i = 0; i < XLNX_ZYNQMP_NUM_OCM_BANKS; i++) {
         char *ocm_name = g_strdup_printf("zynqmp.ocm_ram_bank_%d", i);
 
-        memory_region_init_ram(&s->ocm_ram[i], NULL, ocm_name,
+        memory_region_init_ram(&s->ocm_ram[i], OBJECT(dev), ocm_name,
                                XLNX_ZYNQMP_OCM_RAM_SIZE, &error_fatal);
         memory_region_add_subregion(get_system_memory(),
                                     XLNX_ZYNQMP_OCM_RAM_0_ADDRESS +
Signature · 1 line
2.47.1
#253 lore raw

RFC PATCH v2 96/137 hw/arm/omap1: Give memory regions an explicit owner

In reply to Alexander Graf

omap1.c models the TI OMAP310 MPU with ~20 pre-QOM sub-block init helpers (omap_mpu_timer_init, omap_ulpd_pm_init, omap_pin_cfg_init, omap_id_init, omap_mpui_init, omap_tipb_bridge_init, omap_tcmi_init, omap_dpll_init, omap_clkm_init, omap_mpuio_init, omap_uwire_init, omap_pwl_init, omap_pwt_init, omap_rtc_init, omap_mcbsp_init, omap_lpg_init, omap_setup_mpui_io, omap_setup_dsp_mapping, ...) that each create MemoryRegions with owner==NULL.

Thread an Object *owner first argument through every sub-block init helper. All are static and called only from omap310_mpu_init(), which already carries an Object *parent from the earlier device conversion; pass it through.

No functional change intended.

RAMBlock idstrs are unchanged: the owners added here are Machine or SysBus devices, and memory_region_register_ram() maps both to dev=NULL for qemu_ram_set_idstr().

AI-used-for: code (refactoring)

---
 hw/arm/omap1.c | 175 ++++++++++++++++++++++++++-----------------------
 1 file changed, 94 insertions(+), 81 deletions(-)
hw/arm/omap1.c +94 -81
index e5e092e074..be6af35e26 100644
@@ -221,8 +221,8 @@ static void omap_mpu_timer_reset(struct omap_mpu_timer_s *s)
     s->it_ena = 1;
 }
 
-static struct omap_mpu_timer_s *omap_mpu_timer_init(MemoryRegion *system_memory,
-                hwaddr base,
+static struct omap_mpu_timer_s *omap_mpu_timer_init(Object *owner,
+                MemoryRegion *system_memory, hwaddr base,
                 qemu_irq irq, omap_clk clk)
 {
     struct omap_mpu_timer_s *s = g_new0(struct omap_mpu_timer_s, 1);
@@ -234,7 +234,7 @@ static struct omap_mpu_timer_s *omap_mpu_timer_init(MemoryRegion *system_memory,
     omap_mpu_timer_reset(s);
     omap_timer_clk_setup(s);
 
-    memory_region_init_io(&s->iomem, NULL, &omap_mpu_timer_ops, s,
+    memory_region_init_io(&s->iomem, owner, &omap_mpu_timer_ops, s,
                           "omap-mpu-timer", 0x100);
 
     memory_region_add_subregion(system_memory, base, &s->iomem);
@@ -353,8 +353,8 @@ static void omap_wd_timer_reset(struct omap_watchdog_timer_s *s)
     omap_timer_update(&s->timer);
 }
 
-static struct omap_watchdog_timer_s *omap_wd_timer_init(MemoryRegion *memory,
-                hwaddr base,
+static struct omap_watchdog_timer_s *omap_wd_timer_init(Object *owner,
+                MemoryRegion *memory, hwaddr base,
                 qemu_irq irq, omap_clk clk)
 {
     struct omap_watchdog_timer_s *s = g_new0(struct omap_watchdog_timer_s, 1);
@@ -365,7 +365,7 @@ static struct omap_watchdog_timer_s *omap_wd_timer_init(MemoryRegion *memory,
     omap_wd_timer_reset(s);
     omap_timer_clk_setup(&s->timer);
 
-    memory_region_init_io(&s->iomem, NULL, &omap_wd_timer_ops, s,
+    memory_region_init_io(&s->iomem, owner, &omap_wd_timer_ops, s,
                           "omap-wd-timer", 0x100);
     memory_region_add_subregion(memory, base, &s->iomem);
 
@@ -462,8 +462,8 @@ static void omap_os_timer_reset(struct omap_32khz_timer_s *s)
     s->timer.ar = 1;
 }
 
-static struct omap_32khz_timer_s *omap_os_timer_init(MemoryRegion *memory,
-                hwaddr base,
+static struct omap_32khz_timer_s *omap_os_timer_init(Object *owner,
+                MemoryRegion *memory, hwaddr base,
                 qemu_irq irq, omap_clk clk)
 {
     struct omap_32khz_timer_s *s = g_new0(struct omap_32khz_timer_s, 1);
@@ -474,7 +474,7 @@ static struct omap_32khz_timer_s *omap_os_timer_init(MemoryRegion *memory,
     omap_os_timer_reset(s);
     omap_timer_clk_setup(&s->timer);
 
-    memory_region_init_io(&s->iomem, NULL, &omap_os_timer_ops, s,
+    memory_region_init_io(&s->iomem, owner, &omap_os_timer_ops, s,
                           "omap-os-timer", 0x800);
     memory_region_add_subregion(memory, base, &s->iomem);
 
@@ -707,11 +707,11 @@ static void omap_ulpd_pm_reset(struct omap_mpu_state_s *mpu)
     omap_clk_reparent(omap_findclk(mpu, "ck_48m"), omap_findclk(mpu, "dpll4"));
 }
 
-static void omap_ulpd_pm_init(MemoryRegion *system_memory,
-                hwaddr base,
+static void omap_ulpd_pm_init(Object *owner,
+                MemoryRegion *system_memory, hwaddr base,
                 struct omap_mpu_state_s *mpu)
 {
-    memory_region_init_io(&mpu->ulpd_pm_iomem, NULL, &omap_ulpd_pm_ops, mpu,
+    memory_region_init_io(&mpu->ulpd_pm_iomem, owner, &omap_ulpd_pm_ops, mpu,
                           "omap-ulpd-pm", 0x800);
     memory_region_add_subregion(system_memory, base, &mpu->ulpd_pm_iomem);
     omap_ulpd_pm_reset(mpu);
@@ -933,11 +933,11 @@ static void omap_pin_cfg_reset(struct omap_mpu_state_s *mpu)
     memset(mpu->mod_conf_ctrl, 0, sizeof(mpu->mod_conf_ctrl));
 }
 
-static void omap_pin_cfg_init(MemoryRegion *system_memory,
-                hwaddr base,
+static void omap_pin_cfg_init(Object *owner,
+                MemoryRegion *system_memory, hwaddr base,
                 struct omap_mpu_state_s *mpu)
 {
-    memory_region_init_io(&mpu->pin_cfg_iomem, NULL, &omap_pin_cfg_ops, mpu,
+    memory_region_init_io(&mpu->pin_cfg_iomem, owner, &omap_pin_cfg_ops, mpu,
                           "omap-pin-cfg", 0x800);
     memory_region_add_subregion(system_memory, base, &mpu->pin_cfg_iomem);
     omap_pin_cfg_reset(mpu);
@@ -994,15 +994,16 @@ static const MemoryRegionOps omap_id_ops = {
     .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
-static void omap_id_init(MemoryRegion *memory, struct omap_mpu_state_s *mpu)
+static void omap_id_init(Object *owner, MemoryRegion *memory,
+                         struct omap_mpu_state_s *mpu)
 {
-    memory_region_init_io(&mpu->id_iomem, NULL, &omap_id_ops, mpu,
+    memory_region_init_io(&mpu->id_iomem, owner, &omap_id_ops, mpu,
                           "omap-id", 0x100000000ULL);
-    memory_region_init_alias(&mpu->id_iomem_e18, NULL, "omap-id-e18", &mpu->id_iomem,
-                             0xfffe1800, 0x800);
+    memory_region_init_alias(&mpu->id_iomem_e18, owner, "omap-id-e18",
+                             &mpu->id_iomem, 0xfffe1800, 0x800);
     memory_region_add_subregion(memory, 0xfffe1800, &mpu->id_iomem_e18);
-    memory_region_init_alias(&mpu->id_iomem_ed4, NULL, "omap-id-ed4", &mpu->id_iomem,
-                             0xfffed400, 0x100);
+    memory_region_init_alias(&mpu->id_iomem_ed4, owner, "omap-id-ed4",
+                             &mpu->id_iomem, 0xfffed400, 0x100);
     memory_region_add_subregion(memory, 0xfffed400, &mpu->id_iomem_ed4);
 }
 
@@ -1086,10 +1087,10 @@ static void omap_mpui_reset(struct omap_mpu_state_s *s)
     s->mpui_ctrl = 0x0003ff1b;
 }
 
-static void omap_mpui_init(MemoryRegion *memory, hwaddr base,
+static void omap_mpui_init(Object *owner, MemoryRegion *memory, hwaddr base,
                 struct omap_mpu_state_s *mpu)
 {
-    memory_region_init_io(&mpu->mpui_iomem, NULL, &omap_mpui_ops, mpu,
+    memory_region_init_io(&mpu->mpui_iomem, owner, &omap_mpui_ops, mpu,
                           "omap-mpui", 0x100);
     memory_region_add_subregion(memory, base, &mpu->mpui_iomem);
 
@@ -1195,7 +1196,7 @@ static void omap_tipb_bridge_reset(struct omap_tipb_bridge_s *s)
     s->enh_control = 0x000f;
 }
 
-static struct omap_tipb_bridge_s *omap_tipb_bridge_init(
+static struct omap_tipb_bridge_s *omap_tipb_bridge_init(Object *owner,
     MemoryRegion *memory, hwaddr base,
     qemu_irq abort_irq, omap_clk clk)
 {
@@ -1204,7 +1205,7 @@ static struct omap_tipb_bridge_s *omap_tipb_bridge_init(
     s->abort = abort_irq;
     omap_tipb_bridge_reset(s);
 
-    memory_region_init_io(&s->iomem, NULL, &omap_tipb_bridge_ops, s,
+    memory_region_init_io(&s->iomem, owner, &omap_tipb_bridge_ops, s,
                           "omap-tipb-bridge", 0x100);
     memory_region_add_subregion(memory, base, &s->iomem);
 
@@ -1314,10 +1315,10 @@ static void omap_tcmi_reset(struct omap_mpu_state_s *mpu)
     mpu->tcmi_regs[0x40 >> 2] = 0x00000000;
 }
 
-static void omap_tcmi_init(MemoryRegion *memory, hwaddr base,
+static void omap_tcmi_init(Object *owner, MemoryRegion *memory, hwaddr base,
                 struct omap_mpu_state_s *mpu)
 {
-    memory_region_init_io(&mpu->tcmi_iomem, NULL, &omap_tcmi_ops, mpu,
+    memory_region_init_io(&mpu->tcmi_iomem, owner, &omap_tcmi_ops, mpu,
                           "omap-tcmi", 0x100);
     memory_region_add_subregion(memory, base, &mpu->tcmi_iomem);
     omap_tcmi_reset(mpu);
@@ -1399,11 +1400,12 @@ static void omap_dpll_reset(struct dpll_ctl_s *s)
     omap_clk_setrate(s->dpll, 1, 1);
 }
 
-static struct dpll_ctl_s  *omap_dpll_init(MemoryRegion *memory,
+static struct dpll_ctl_s  *omap_dpll_init(Object *owner, MemoryRegion *memory,
                            hwaddr base, omap_clk clk)
 {
     struct dpll_ctl_s *s = g_malloc0(sizeof(*s));
-    memory_region_init_io(&s->iomem, NULL, &omap_dpll_ops, s, "omap-dpll", 0x100);
+    memory_region_init_io(&s->iomem, owner, &omap_dpll_ops, s,
+                          "omap-dpll", 0x100);
 
     s->dpll = clk;
     omap_dpll_reset(s);
@@ -1822,12 +1824,13 @@ static void omap_clkm_reset(struct omap_mpu_state_s *s)
     s->clkm.dsp_rstct2 = 0x0000;
 }
 
-static void omap_clkm_init(MemoryRegion *memory, hwaddr mpu_base,
-                hwaddr dsp_base, struct omap_mpu_state_s *s)
+static void omap_clkm_init(Object *owner, MemoryRegion *memory,
+                hwaddr mpu_base, hwaddr dsp_base,
+                struct omap_mpu_state_s *s)
 {
-    memory_region_init_io(&s->clkm_iomem, NULL, &omap_clkm_ops, s,
+    memory_region_init_io(&s->clkm_iomem, owner, &omap_clkm_ops, s,
                           "omap-clkm", 0x100);
-    memory_region_init_io(&s->clkdsp_iomem, NULL, &omap_clkdsp_ops, s,
+    memory_region_init_io(&s->clkdsp_iomem, owner, &omap_clkdsp_ops, s,
                           "omap-clkdsp", 0x1000);
 
     s->clkm.arm_idlect1 = 0x03ff;
@@ -2071,8 +2074,8 @@ static void omap_mpuio_onoff(void *opaque, int line, int on)
         omap_mpuio_kbd_update(s);
 }
 
-static struct omap_mpuio_s *omap_mpuio_init(MemoryRegion *memory,
-                hwaddr base,
+static struct omap_mpuio_s *omap_mpuio_init(Object *owner,
+                MemoryRegion *memory, hwaddr base,
                 qemu_irq kbd_int, qemu_irq gpio_int,
                 omap_clk clk)
 {
@@ -2083,7 +2086,7 @@ static struct omap_mpuio_s *omap_mpuio_init(MemoryRegion *memory,
     s->in = qemu_allocate_irqs(omap_mpuio_set, s, 16);
     omap_mpuio_reset(s);
 
-    memory_region_init_io(&s->iomem, NULL, &omap_mpuio_ops, s,
+    memory_region_init_io(&s->iomem, owner, &omap_mpuio_ops, s,
                           "omap-mpuio", 0x800);
     memory_region_add_subregion(memory, base, &s->iomem);
 
@@ -2236,7 +2239,8 @@ static void omap_uwire_reset(struct omap_uwire_s *s)
     s->setup[4] = 0;
 }
 
-static struct omap_uwire_s *omap_uwire_init(MemoryRegion *system_memory,
+static struct omap_uwire_s *omap_uwire_init(Object *owner,
+                                            MemoryRegion *system_memory,
                                             hwaddr base,
                                             qemu_irq txirq, qemu_irq rxirq,
                                             qemu_irq dma,
@@ -2249,7 +2253,8 @@ static struct omap_uwire_s *omap_uwire_init(MemoryRegion *system_memory,
     s->txdrq = dma;
     omap_uwire_reset(s);
 
-    memory_region_init_io(&s->iomem, NULL, &omap_uwire_ops, s, "omap-uwire", 0x800);
+    memory_region_init_io(&s->iomem, owner, &omap_uwire_ops, s,
+                          "omap-uwire", 0x800);
     memory_region_add_subregion(system_memory, base, &s->iomem);
 
     return s;
@@ -2345,7 +2350,8 @@ static void omap_pwl_clk_update(void *opaque, int line, int on)
     omap_pwl_update(s);
 }
 
-static struct omap_pwl_s *omap_pwl_init(MemoryRegion *system_memory,
+static struct omap_pwl_s *omap_pwl_init(Object *owner,
+                                        MemoryRegion *system_memory,
                                         hwaddr base,
                                         omap_clk clk)
 {
@@ -2353,7 +2359,7 @@ static struct omap_pwl_s *omap_pwl_init(MemoryRegion *system_memory,
 
     omap_pwl_reset(s);
 
-    memory_region_init_io(&s->iomem, NULL, &omap_pwl_ops, s,
+    memory_region_init_io(&s->iomem, owner, &omap_pwl_ops, s,
                           "omap-pwl", 0x800);
     memory_region_add_subregion(system_memory, base, &s->iomem);
 
@@ -2456,7 +2462,8 @@ static void omap_pwt_reset(struct omap_pwt_s *s)
     s->gcr = 0;
 }
 
-static struct omap_pwt_s *omap_pwt_init(MemoryRegion *system_memory,
+static struct omap_pwt_s *omap_pwt_init(Object *owner,
+                                        MemoryRegion *system_memory,
                                         hwaddr base,
                                         omap_clk clk)
 {
@@ -2464,7 +2471,7 @@ static struct omap_pwt_s *omap_pwt_init(MemoryRegion *system_memory,
     s->clk = clk;
     omap_pwt_reset(s);
 
-    memory_region_init_io(&s->iomem, NULL, &omap_pwt_ops, s,
+    memory_region_init_io(&s->iomem, owner, &omap_pwt_ops, s,
                           "omap-pwt", 0x800);
     memory_region_add_subregion(system_memory, base, &s->iomem);
     return s;
@@ -2822,7 +2829,8 @@ static void omap_rtc_reset(struct omap_rtc_s *s)
     omap_rtc_tick(s);
 }
 
-static struct omap_rtc_s *omap_rtc_init(MemoryRegion *system_memory,
+static struct omap_rtc_s *omap_rtc_init(Object *owner,
+                                        MemoryRegion *system_memory,
                                         hwaddr base,
                                         qemu_irq timerirq, qemu_irq alarmirq,
                                         omap_clk clk)
@@ -2835,7 +2843,7 @@ static struct omap_rtc_s *omap_rtc_init(MemoryRegion *system_memory,
 
     omap_rtc_reset(s);
 
-    memory_region_init_io(&s->iomem, NULL, &omap_rtc_ops, s,
+    memory_region_init_io(&s->iomem, owner, &omap_rtc_ops, s,
                           "omap-rtc", 0x800);
     memory_region_add_subregion(system_memory, base, &s->iomem);
 
@@ -3372,7 +3380,8 @@ static void omap_mcbsp_reset(struct omap_mcbsp_s *s)
     timer_del(s->sink_timer);
 }
 
-static struct omap_mcbsp_s *omap_mcbsp_init(MemoryRegion *system_memory,
+static struct omap_mcbsp_s *omap_mcbsp_init(Object *owner,
+                                            MemoryRegion *system_memory,
                                             hwaddr base,
                                             qemu_irq txirq, qemu_irq rxirq,
                                             qemu_irq *dma, omap_clk clk)
@@ -3387,7 +3396,8 @@ static struct omap_mcbsp_s *omap_mcbsp_init(MemoryRegion *system_memory,
     s->source_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, omap_mcbsp_source_tick, s);
     omap_mcbsp_reset(s);
 
-    memory_region_init_io(&s->iomem, NULL, &omap_mcbsp_ops, s, "omap-mcbsp", 0x800);
+    memory_region_init_io(&s->iomem, owner, &omap_mcbsp_ops, s,
+                          "omap-mcbsp", 0x800);
     memory_region_add_subregion(system_memory, base, &s->iomem);
 
     return s;
@@ -3555,7 +3565,8 @@ static void omap_lpg_clk_update(void *opaque, int line, int on)
     omap_lpg_update(s);
 }
 
-static struct omap_lpg_s *omap_lpg_init(MemoryRegion *system_memory,
+static struct omap_lpg_s *omap_lpg_init(Object *owner,
+                                        MemoryRegion *system_memory,
                                         hwaddr base, omap_clk clk)
 {
     struct omap_lpg_s *s = g_new0(struct omap_lpg_s, 1);
@@ -3564,7 +3575,8 @@ static struct omap_lpg_s *omap_lpg_init(MemoryRegion *system_memory,
 
     omap_lpg_reset(s);
 
-    memory_region_init_io(&s->iomem, NULL, &omap_lpg_ops, s, "omap-lpg", 0x800);
+    memory_region_init_io(&s->iomem, owner, &omap_lpg_ops, s,
+                          "omap-lpg", 0x800);
     memory_region_add_subregion(system_memory, base, &s->iomem);
 
     omap_clk_adduser(clk, qemu_allocate_irq(omap_lpg_clk_update, s, 0));
@@ -3602,10 +3614,10 @@ static const MemoryRegionOps omap_mpui_io_ops = {
     .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
-static void omap_setup_mpui_io(MemoryRegion *system_memory,
+static void omap_setup_mpui_io(Object *owner, MemoryRegion *system_memory,
                                struct omap_mpu_state_s *mpu)
 {
-    memory_region_init_io(&mpu->mpui_io_iomem, NULL, &omap_mpui_io_ops, mpu,
+    memory_region_init_io(&mpu->mpui_io_iomem, owner, &omap_mpui_io_ops, mpu,
                           "omap-mpui-io", 0x7fff);
     memory_region_add_subregion(system_memory, OMAP_MPUI_BASE,
                                 &mpu->mpui_io_iomem);
@@ -3678,14 +3690,15 @@ static const struct omap_map_s {
     { 0 }
 };
 
-static void omap_setup_dsp_mapping(MemoryRegion *system_memory,
+static void omap_setup_dsp_mapping(Object *owner,
+                                   MemoryRegion *system_memory,
                                    const struct omap_map_s *map)
 {
     MemoryRegion *io;
 
     for (; map->phys_dsp; map ++) {
         io = g_new(MemoryRegion, 1);
-        memory_region_init_alias(io, NULL, map->name,
+        memory_region_init_alias(io, owner, map->name,
                                  system_memory, map->phys_mpu, map->size);
         memory_region_add_subregion(system_memory, map->phys_dsp, io);
     }
@@ -3757,11 +3770,11 @@ struct omap_mpu_state_s *omap310_mpu_init(Object *parent, MemoryRegion *dram,
     omap_clk_init(s);
 
     /* Memory-mapped stuff */
-    memory_region_init_ram(&s->imif_ram, NULL, "omap1.sram", s->sram_size,
+    memory_region_init_ram(&s->imif_ram, parent, "omap1.sram", s->sram_size,
                            &error_fatal);
     memory_region_add_subregion(system_memory, OMAP_IMIF_BASE, &s->imif_ram);
 
-    omap_clkm_init(system_memory, 0xfffece00, 0xe1008000, s);
+    omap_clkm_init(parent, system_memory, 0xfffece00, 0xe1008000, s);
 
     s->ih[0] = qdev_new(parent, "intc[0]", "omap-intc");
     qdev_prop_set_uint32(s->ih[0], "size", 0x100);
@@ -3804,21 +3817,21 @@ struct omap_mpu_state_s *omap310_mpu_init(Object *parent, MemoryRegion *dram,
     soc_dma_port_add_mem(s->dma, memory_region_get_ram_ptr(&s->imif_ram),
                          OMAP_IMIF_BASE, s->sram_size);
 
-    s->timer[0] = omap_mpu_timer_init(system_memory, 0xfffec500,
+    s->timer[0] = omap_mpu_timer_init(parent, system_memory, 0xfffec500,
                     qdev_get_gpio_in(s->ih[0], OMAP_INT_TIMER1),
                     omap_findclk(s, "mputim_ck"));
-    s->timer[1] = omap_mpu_timer_init(system_memory, 0xfffec600,
+    s->timer[1] = omap_mpu_timer_init(parent, system_memory, 0xfffec600,
                     qdev_get_gpio_in(s->ih[0], OMAP_INT_TIMER2),
                     omap_findclk(s, "mputim_ck"));
-    s->timer[2] = omap_mpu_timer_init(system_memory, 0xfffec700,
+    s->timer[2] = omap_mpu_timer_init(parent, system_memory, 0xfffec700,
                     qdev_get_gpio_in(s->ih[0], OMAP_INT_TIMER3),
                     omap_findclk(s, "mputim_ck"));
 
-    s->wdt = omap_wd_timer_init(system_memory, 0xfffec800,
+    s->wdt = omap_wd_timer_init(parent, system_memory, 0xfffec800,
                     qdev_get_gpio_in(s->ih[0], OMAP_INT_WD_TIMER),
                     omap_findclk(s, "armwdt_ck"));
 
-    s->os_timer = omap_os_timer_init(system_memory, 0xfffb9000,
+    s->os_timer = omap_os_timer_init(parent, system_memory, 0xfffb9000,
                     qdev_get_gpio_in(s->ih[1], OMAP_INT_OS_TIMER),
                     omap_findclk(s, "clk32-kHz"));
 
@@ -3827,20 +3840,20 @@ struct omap_mpu_state_s *omap310_mpu_init(Object *parent, MemoryRegion *dram,
                             omap_dma_get_lcdch(s->dma),
                             omap_findclk(s, "lcd_ck"));
 
-    omap_ulpd_pm_init(system_memory, 0xfffe0800, s);
-    omap_pin_cfg_init(system_memory, 0xfffe1000, s);
-    omap_id_init(system_memory, s);
+    omap_ulpd_pm_init(parent, system_memory, 0xfffe0800, s);
+    omap_pin_cfg_init(parent, system_memory, 0xfffe1000, s);
+    omap_id_init(parent, system_memory, s);
 
-    omap_mpui_init(system_memory, 0xfffec900, s);
+    omap_mpui_init(parent, system_memory, 0xfffec900, s);
 
-    s->private_tipb = omap_tipb_bridge_init(system_memory, 0xfffeca00,
+    s->private_tipb = omap_tipb_bridge_init(parent, system_memory, 0xfffeca00,
                     qdev_get_gpio_in(s->ih[0], OMAP_INT_BRIDGE_PRIV),
                     omap_findclk(s, "tipb_ck"));
-    s->public_tipb = omap_tipb_bridge_init(system_memory, 0xfffed300,
+    s->public_tipb = omap_tipb_bridge_init(parent, system_memory, 0xfffed300,
                     qdev_get_gpio_in(s->ih[0], OMAP_INT_BRIDGE_PUB),
                     omap_findclk(s, "tipb_ck"));
 
-    omap_tcmi_init(system_memory, 0xfffecc00, s);
+    omap_tcmi_init(parent, system_memory, 0xfffecc00, s);
 
     s->uart[0] = omap_uart_init(parent, 0xfffb0000,
                                 qdev_get_gpio_in(s->ih[1], OMAP_INT_UART1),
@@ -3864,11 +3877,11 @@ struct omap_mpu_state_s *omap310_mpu_init(Object *parent, MemoryRegion *dram,
                     "uart3",
                     serial_hd(0) && serial_hd(1) ? serial_hd(2) : NULL);
 
-    s->dpll[0] = omap_dpll_init(system_memory, 0xfffecf00,
+    s->dpll[0] = omap_dpll_init(parent, system_memory, 0xfffecf00,
                                 omap_findclk(s, "dpll1"));
-    s->dpll[1] = omap_dpll_init(system_memory, 0xfffed000,
+    s->dpll[1] = omap_dpll_init(parent, system_memory, 0xfffed000,
                                 omap_findclk(s, "dpll2"));
-    s->dpll[2] = omap_dpll_init(system_memory, 0xfffed100,
+    s->dpll[2] = omap_dpll_init(parent, system_memory, 0xfffed100,
                                 omap_findclk(s, "dpll3"));
 
     dinfo = drive_get(IF_SD, 0, 0);
@@ -3895,7 +3908,7 @@ struct omap_mpu_state_s *omap310_mpu_init(Object *parent, MemoryRegion *dram,
                      &error_fatal);
     }
 
-    s->mpuio = omap_mpuio_init(system_memory, 0xfffb5000,
+    s->mpuio = omap_mpuio_init(parent, system_memory, 0xfffb5000,
                                qdev_get_gpio_in(s->ih[1], OMAP_INT_KEYBOARD),
                                qdev_get_gpio_in(s->ih[1], OMAP_INT_MPUIO),
                                omap_findclk(s, "clk32-kHz"));
@@ -3907,14 +3920,14 @@ struct omap_mpu_state_s *omap310_mpu_init(Object *parent, MemoryRegion *dram,
                        qdev_get_gpio_in(s->ih[0], OMAP_INT_GPIO_BANK1));
     sysbus_mmio_map(SYS_BUS_DEVICE(s->gpio), 0, 0xfffce000);
 
-    s->microwire = omap_uwire_init(system_memory, 0xfffb3000,
+    s->microwire = omap_uwire_init(parent, system_memory, 0xfffb3000,
                                    qdev_get_gpio_in(s->ih[1], OMAP_INT_uWireTX),
                                    qdev_get_gpio_in(s->ih[1], OMAP_INT_uWireRX),
                     s->drq[OMAP_DMA_UWIRE_TX], omap_findclk(s, "mpuper_ck"));
 
-    s->pwl = omap_pwl_init(system_memory, 0xfffb5800,
+    s->pwl = omap_pwl_init(parent, system_memory, 0xfffb5800,
                            omap_findclk(s, "armxor_ck"));
-    s->pwt = omap_pwt_init(system_memory, 0xfffb6000,
+    s->pwt = omap_pwt_init(parent, system_memory, 0xfffb6000,
                            omap_findclk(s, "armxor_ck"));
 
     s->i2c[0] = qdev_new(parent, "i2c", "omap_i2c");
@@ -3927,29 +3940,29 @@ struct omap_mpu_state_s *omap310_mpu_init(Object *parent, MemoryRegion *dram,
     sysbus_connect_irq(busdev, 2, s->drq[OMAP_DMA_I2C_RX]);
     sysbus_mmio_map(busdev, 0, 0xfffb3800);
 
-    s->rtc = omap_rtc_init(system_memory, 0xfffb4800,
+    s->rtc = omap_rtc_init(parent, system_memory, 0xfffb4800,
                            qdev_get_gpio_in(s->ih[1], OMAP_INT_RTC_TIMER),
                            qdev_get_gpio_in(s->ih[1], OMAP_INT_RTC_ALARM),
                     omap_findclk(s, "clk32-kHz"));
 
-    s->mcbsp1 = omap_mcbsp_init(system_memory, 0xfffb1800,
+    s->mcbsp1 = omap_mcbsp_init(parent, system_memory, 0xfffb1800,
                                 qdev_get_gpio_in(s->ih[1], OMAP_INT_McBSP1TX),
                                 qdev_get_gpio_in(s->ih[1], OMAP_INT_McBSP1RX),
                     &s->drq[OMAP_DMA_MCBSP1_TX], omap_findclk(s, "dspxor_ck"));
-    s->mcbsp2 = omap_mcbsp_init(system_memory, 0xfffb1000,
+    s->mcbsp2 = omap_mcbsp_init(parent, system_memory, 0xfffb1000,
                                 qdev_get_gpio_in(s->ih[0],
                                                  OMAP_INT_310_McBSP2_TX),
                                 qdev_get_gpio_in(s->ih[0],
                                                  OMAP_INT_310_McBSP2_RX),
                     &s->drq[OMAP_DMA_MCBSP2_TX], omap_findclk(s, "mpuper_ck"));
-    s->mcbsp3 = omap_mcbsp_init(system_memory, 0xfffb7000,
+    s->mcbsp3 = omap_mcbsp_init(parent, system_memory, 0xfffb7000,
                                 qdev_get_gpio_in(s->ih[1], OMAP_INT_McBSP3TX),
                                 qdev_get_gpio_in(s->ih[1], OMAP_INT_McBSP3RX),
                     &s->drq[OMAP_DMA_MCBSP3_TX], omap_findclk(s, "dspxor_ck"));
 
-    s->led[0] = omap_lpg_init(system_memory,
+    s->led[0] = omap_lpg_init(parent, system_memory,
                               0xfffbd000, omap_findclk(s, "clk32-kHz"));
-    s->led[1] = omap_lpg_init(system_memory,
+    s->led[1] = omap_lpg_init(parent, system_memory,
                               0xfffbd800, omap_findclk(s, "clk32-kHz"));
 
     /* Register mappings not currently implemented:
@@ -3967,8 +3980,8 @@ struct omap_mpu_state_s *omap310_mpu_init(Object *parent, MemoryRegion *dram,
      * DSP MMU          fffed200 - fffed2ff
      */
 
-    omap_setup_dsp_mapping(system_memory, omap15xx_dsp_mm);
-    omap_setup_mpui_io(system_memory, s);
+    omap_setup_dsp_mapping(parent, system_memory, omap15xx_dsp_mm);
+    omap_setup_mpui_io(parent, system_memory, s);
 
     qemu_register_reset(omap1_mpu_reset, s);
 
Signature · 1 line
2.47.1
#254 lore raw

RFC PATCH v2 97/137 hw/sh4: Give memory regions an explicit owner

In reply to Alexander Graf

Convert memory_region_init*() calls in the SH7750 SoC model and its non-QOM sub-block helpers (tmu012_init, sh_intc_init, r2d_fpga_init) to pass an explicit owner instead of NULL.

Thread Object *owner as the first argument through tmu012_init(), sh_intc_init() and its static sh_intc_register() helper, and r2d_fpga_init(). sh7750_init() already carries an Object *parent from the earlier device conversion; pass it through.

No functional change intended.

RAMBlock idstrs are unchanged: the owners added here are Machine or SysBus devices, and memory_region_register_ram() maps both to dev=NULL for qemu_ram_set_idstr().

AI-used-for: code (refactoring)

---
 hw/intc/sh_intc.c         | 19 ++++++++++---------
 hw/sh4/r2d.c              |  9 +++++----
 hw/sh4/sh7750.c           | 22 +++++++++++-----------
 hw/timer/sh_timer.c       |  9 +++++----
 include/hw/sh4/sh_intc.h  |  3 ++-
 include/hw/timer/tmu012.h |  3 ++-
 6 files changed, 35 insertions(+), 30 deletions(-)
hw/intc/sh_intc.c +10 -9
index 0da82f9d5e..37feb6a813 100644
@@ -349,7 +349,8 @@ void sh_intc_register_sources(struct intc_desc *desc,
     }
 }
 
-static unsigned int sh_intc_register(MemoryRegion *sysmem,
+static unsigned int sh_intc_register(Object *owner,
+                                     MemoryRegion *sysmem,
                                      struct intc_desc *desc,
                                      const unsigned long address,
                                      const char *type,
@@ -368,18 +369,18 @@ static unsigned int sh_intc_register(MemoryRegion *sysmem,
     iomem_a7 = iomem_p4 + 1;
 
     snprintf(name, sizeof(name), "intc-%s-%s-%s", type, action, "p4");
-    memory_region_init_alias(iomem_p4, NULL, name, iomem, A7ADDR(address), 4);
+    memory_region_init_alias(iomem_p4, owner, name, iomem, A7ADDR(address), 4);
     memory_region_add_subregion(sysmem, P4ADDR(address), iomem_p4);
 
     snprintf(name, sizeof(name), "intc-%s-%s-%s", type, action, "a7");
-    memory_region_init_alias(iomem_a7, NULL, name, iomem, A7ADDR(address), 4);
+    memory_region_init_alias(iomem_a7, owner, name, iomem, A7ADDR(address), 4);
     memory_region_add_subregion(sysmem, A7ADDR(address), iomem_a7);
 
     /* used to increment aliases index */
     return 2;
 }
 
-int sh_intc_init(MemoryRegion *sysmem,
+int sh_intc_init(Object *owner, MemoryRegion *sysmem,
                  struct intc_desc *desc,
                  int nr_sources,
                  struct intc_mask_reg *mask_regs,
@@ -403,15 +404,15 @@ int sh_intc_init(MemoryRegion *sysmem,
         desc->sources[i].parent = desc;
     }
     desc->irqs = qemu_allocate_irqs(sh_intc_set_irq, desc, nr_sources);
-    memory_region_init_io(&desc->iomem, NULL, &sh_intc_ops, desc, "intc",
+    memory_region_init_io(&desc->iomem, owner, &sh_intc_ops, desc, "intc",
                           0x100000000ULL);
     j = 0;
     if (desc->mask_regs) {
         for (i = 0; i < desc->nr_mask_regs; i++) {
             struct intc_mask_reg *mr = &desc->mask_regs[i];
 
-            j += sh_intc_register(sysmem, desc, mr->set_reg, "mask", "set", j);
-            j += sh_intc_register(sysmem, desc, mr->clr_reg, "mask", "clr", j);
+            j += sh_intc_register(owner, sysmem, desc, mr->set_reg, "mask", "set", j);
+            j += sh_intc_register(owner, sysmem, desc, mr->clr_reg, "mask", "clr", j);
         }
     }
 
@@ -419,8 +420,8 @@ int sh_intc_init(MemoryRegion *sysmem,
         for (i = 0; i < desc->nr_prio_regs; i++) {
             struct intc_prio_reg *pr = &desc->prio_regs[i];
 
-            j += sh_intc_register(sysmem, desc, pr->set_reg, "prio", "set", j);
-            j += sh_intc_register(sysmem, desc, pr->clr_reg, "prio", "clr", j);
+            j += sh_intc_register(owner, sysmem, desc, pr->set_reg, "prio", "set", j);
+            j += sh_intc_register(owner, sysmem, desc, pr->clr_reg, "prio", "clr", j);
         }
     }
 
hw/sh4/r2d.c +5 -4
index 6154aed2c4..8deda6e5f4 100644
@@ -187,7 +187,8 @@ static const MemoryRegionOps r2d_fpga_ops = {
     .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
-static r2d_fpga_t *r2d_fpga_init(MemoryRegion *sysmem,
+static r2d_fpga_t *r2d_fpga_init(Object *owner,
+                                 MemoryRegion *sysmem,
                                  hwaddr base, qemu_irq irl)
 {
     r2d_fpga_t *s;
@@ -196,7 +197,7 @@ static r2d_fpga_t *r2d_fpga_init(MemoryRegion *sysmem,
 
     s->irl = irl;
 
-    memory_region_init_io(&s->iomem, NULL, &r2d_fpga_ops, s, "r2d-fpga", 0x40);
+    memory_region_init_io(&s->iomem, owner, &r2d_fpga_ops, s, "r2d-fpga", 0x40);
     memory_region_add_subregion(sysmem, base, &s->iomem);
 
     qemu_init_irqs(s->irq, NR_IRQS, r2d_fpga_irq_set, s);
@@ -261,11 +262,11 @@ static void r2d_init(MachineState *machine)
     qemu_register_reset(main_cpu_reset, reset_info);
 
     /* Allocate memory space */
-    memory_region_init_ram(sdram, NULL, "r2d.sdram", SDRAM_SIZE, &error_fatal);
+    memory_region_init_ram(sdram, OBJECT(machine), "r2d.sdram", SDRAM_SIZE, &error_fatal);
     memory_region_add_subregion(address_space_mem, SDRAM_BASE, sdram);
     /* Register peripherals */
     s = sh7750_init(OBJECT(machine), cpu, address_space_mem);
-    fpga = r2d_fpga_init(address_space_mem, 0x04000000, sh7750_irl(s));
+    fpga = r2d_fpga_init(OBJECT(machine), address_space_mem, 0x04000000, sh7750_irl(s));
 
     dev = qdev_new(OBJECT(machine), "pci-host", "sh_pci");
     busdev = SYS_BUS_DEVICE(dev);
hw/sh4/sh7750.c +11 -11
index ff9724fadf..ea55a3a9cc 100644
@@ -721,38 +721,38 @@ SH7750State *sh7750_init(Object *parent, SuperHCPU *cpu,
     s = g_new0(SH7750State, 1);
     s->cpu = cpu;
     s->periph_freq = 60000000; /* 60MHz */
-    memory_region_init_io(&s->iomem, NULL, &sh7750_mem_ops, s,
+    memory_region_init_io(&s->iomem, parent, &sh7750_mem_ops, s,
                           "memory", 0x1fc01000);
 
-    memory_region_init_alias(&s->iomem_1f0, NULL, "memory-1f0",
+    memory_region_init_alias(&s->iomem_1f0, parent, "memory-1f0",
                              &s->iomem, 0x1f000000, 0x1000);
     memory_region_add_subregion(sysmem, 0x1f000000, &s->iomem_1f0);
 
-    memory_region_init_alias(&s->iomem_ff0, NULL, "memory-ff0",
+    memory_region_init_alias(&s->iomem_ff0, parent, "memory-ff0",
                              &s->iomem, 0x1f000000, 0x1000);
     memory_region_add_subregion(sysmem, 0xff000000, &s->iomem_ff0);
 
-    memory_region_init_alias(&s->iomem_1f8, NULL, "memory-1f8",
+    memory_region_init_alias(&s->iomem_1f8, parent, "memory-1f8",
                              &s->iomem, 0x1f800000, 0x1000);
     memory_region_add_subregion(sysmem, 0x1f800000, &s->iomem_1f8);
 
-    memory_region_init_alias(&s->iomem_ff8, NULL, "memory-ff8",
+    memory_region_init_alias(&s->iomem_ff8, parent, "memory-ff8",
                              &s->iomem, 0x1f800000, 0x1000);
     memory_region_add_subregion(sysmem, 0xff800000, &s->iomem_ff8);
 
-    memory_region_init_alias(&s->iomem_1fc, NULL, "memory-1fc",
+    memory_region_init_alias(&s->iomem_1fc, parent, "memory-1fc",
                              &s->iomem, 0x1fc00000, 0x1000);
     memory_region_add_subregion(sysmem, 0x1fc00000, &s->iomem_1fc);
 
-    memory_region_init_alias(&s->iomem_ffc, NULL, "memory-ffc",
+    memory_region_init_alias(&s->iomem_ffc, parent, "memory-ffc",
                              &s->iomem, 0x1fc00000, 0x1000);
     memory_region_add_subregion(sysmem, 0xffc00000, &s->iomem_ffc);
 
-    memory_region_init_io(&s->mmct_iomem, NULL, &sh7750_mmct_ops, s,
+    memory_region_init_io(&s->mmct_iomem, parent, &sh7750_mmct_ops, s,
                           "cache-and-tlb", 0x08000000);
     memory_region_add_subregion(sysmem, 0xf0000000, &s->mmct_iomem);
 
-    sh_intc_init(sysmem, &s->intc, NR_SOURCES,
+    sh_intc_init(parent, sysmem, &s->intc, NR_SOURCES,
                  _INTC_ARRAY(mask_registers),
                  _INTC_ARRAY(prio_registers));
 
@@ -797,7 +797,7 @@ SH7750State *sh7750_init(Object *parent, SuperHCPU *cpu,
     qdev_connect_gpio_out_named(dev, "txi", 0, s->intc.irqs[SCIF_TXI]);
     qdev_connect_gpio_out_named(dev, "bri", 0, s->intc.irqs[SCIF_BRI]);
 
-    tmu012_init(sysmem, 0x1fd80000,
+    tmu012_init(parent, sysmem, 0x1fd80000,
                 TMU012_FEAT_TOCR | TMU012_FEAT_3CHAN | TMU012_FEAT_EXTCLK,
                 s->periph_freq,
                 s->intc.irqs[TMU0],
@@ -821,7 +821,7 @@ SH7750State *sh7750_init(Object *parent, SuperHCPU *cpu,
         sh_intc_register_sources(&s->intc,
                                  _INTC_ARRAY(vectors_tmu34),
                                  NULL, 0);
-        tmu012_init(sysmem, 0x1e100000, 0, s->periph_freq,
+        tmu012_init(parent, sysmem, 0x1e100000, 0, s->periph_freq,
                     s->intc.irqs[TMU3],
                     s->intc.irqs[TMU4],
                     NULL, NULL);
hw/timer/sh_timer.c +5 -4
index 41ece9c613..ac71d11a0a 100644
@@ -344,7 +344,8 @@ static const MemoryRegionOps tmu012_ops = {
     .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
-void tmu012_init(MemoryRegion *sysmem, hwaddr base, int feat, uint32_t freq,
+void tmu012_init(Object *owner, MemoryRegion *sysmem, hwaddr base,
+                 int feat, uint32_t freq,
                  qemu_irq ch0_irq, qemu_irq ch1_irq,
                  qemu_irq ch2_irq0, qemu_irq ch2_irq1)
 {
@@ -360,13 +361,13 @@ void tmu012_init(MemoryRegion *sysmem, hwaddr base, int feat, uint32_t freq,
                                     ch2_irq0); /* ch2_irq1 not supported */
     }
 
-    memory_region_init_io(&s->iomem, NULL, &tmu012_ops, s, "timer", 0x30);
+    memory_region_init_io(&s->iomem, owner, &tmu012_ops, s, "timer", 0x30);
 
-    memory_region_init_alias(&s->iomem_p4, NULL, "timer-p4",
+    memory_region_init_alias(&s->iomem_p4, owner, "timer-p4",
                              &s->iomem, 0, memory_region_size(&s->iomem));
     memory_region_add_subregion(sysmem, P4ADDR(base), &s->iomem_p4);
 
-    memory_region_init_alias(&s->iomem_a7, NULL, "timer-a7",
+    memory_region_init_alias(&s->iomem_a7, owner, "timer-a7",
                              &s->iomem, 0, memory_region_size(&s->iomem));
     memory_region_add_subregion(sysmem, A7ADDR(base), &s->iomem_a7);
     /* ??? Save/restore.  */
include/hw/sh4/sh_intc.h +2 -1
index 94f183121e..d391710987 100644
@@ -2,6 +2,7 @@
 #define SH_INTC_H
 
 #include "system/memory.h"
+#include "qom/object.h"
 
 typedef unsigned char intc_enum;
 
@@ -68,7 +69,7 @@ void sh_intc_register_sources(struct intc_desc *desc,
                               struct intc_group *groups,
                               int nr_groups);
 
-int sh_intc_init(MemoryRegion *sysmem,
+int sh_intc_init(Object *owner, MemoryRegion *sysmem,
                  struct intc_desc *desc,
                  int nr_sources,
                  struct intc_mask_reg *mask_regs,
include/hw/timer/tmu012.h +2 -1
index 808ed8de1d..fb24c00d3b 100644
@@ -10,12 +10,13 @@
 #define HW_TIMER_TMU012_H
 
 #include "exec/hwaddr.h"
+#include "qom/object.h"
 
 #define TMU012_FEAT_TOCR   (1 << 0)
 #define TMU012_FEAT_3CHAN  (1 << 1)
 #define TMU012_FEAT_EXTCLK (1 << 2)
 
-void tmu012_init(MemoryRegion *sysmem, hwaddr base,
+void tmu012_init(Object *owner, MemoryRegion *sysmem, hwaddr base,
                  int feat, uint32_t freq,
                  qemu_irq ch0_irq, qemu_irq ch1_irq,
                  qemu_irq ch2_irq0, qemu_irq ch2_irq1);
Signature · 1 line
2.47.1
#255 lore raw

RFC PATCH v2 98/137 hw/m68k: Give memory regions an explicit owner

In reply to Alexander Graf

Convert memory_region_init*() calls that pass NULL owner to pass the enclosing machine or device instead.

Thread Object *owner through the static mcf5208_sys_init() helper. mcf5206_mbar_realize() already has DeviceState *dev in scope.

No functional change intended.

RAMBlock idstrs are unchanged: the owners added here are Machine or SysBus devices, and memory_region_register_ram() maps both to dev=NULL for qemu_ram_set_idstr().

AI-used-for: code (refactoring)

---
 hw/m68k/an5206.c    |  2 +-
 hw/m68k/mcf5206.c   |  2 +-
 hw/m68k/mcf5208.c   | 15 ++++++++-------
 hw/m68k/next-cube.c | 10 +++++-----
 hw/m68k/q800.c      | 10 +++++-----
 5 files changed, 20 insertions(+), 19 deletions(-)
hw/m68k/an5206.c +1 -1
index 5027311cad..6c6c7d7248 100644
@@ -60,7 +60,7 @@ static void an5206_init(MachineState *machine)
     memory_region_add_subregion(address_space_mem, 0, machine->ram);
 
     /* Internal SRAM.  */
-    memory_region_init_ram(sram, NULL, "an5206.sram", 512, &error_fatal);
+    memory_region_init_ram(sram, OBJECT(machine), "an5206.sram", 512, &error_fatal);
     memory_region_add_subregion(address_space_mem, AN5206_RAMBAR_ADDR, sram);
 
     mcf5206_init(OBJECT(machine), cpu, address_space_mem, AN5206_MBAR_ADDR);
hw/m68k/mcf5206.c +1 -1
index b3c745d3f9..ee39a6ac30 100644
@@ -589,7 +589,7 @@ static void mcf5206_mbar_realize(DeviceState *dev, Error **errp)
 {
     m5206_mbar_state *s = MCF5206_MBAR(dev);
 
-    memory_region_init_io(&s->iomem, NULL, &m5206_mbar_ops, s,
+    memory_region_init_io(&s->iomem, OBJECT(dev), &m5206_mbar_ops, s,
                           "mbar", 0x00001000);
     sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->iomem);
 
hw/m68k/mcf5208.c +8 -7
index a955efebeb..93aee5ebd5 100644
@@ -227,7 +227,8 @@ static const MemoryRegionOps m5208_rcm_ops = {
     .endianness = DEVICE_BIG_ENDIAN,
 };
 
-static void mcf5208_sys_init(MemoryRegion *address_space, DeviceState *intc,
+static void mcf5208_sys_init(Object *owner, MemoryRegion *address_space,
+                             DeviceState *intc,
                              M68kCPU *cpu)
 {
     MemoryRegion *iomem = g_new(MemoryRegion, 1);
@@ -236,17 +237,17 @@ static void mcf5208_sys_init(MemoryRegion *address_space, DeviceState *intc,
     int i;
 
     /* RCM */
-    memory_region_init_io(iomem_rcm, NULL, &m5208_rcm_ops, cpu,
+    memory_region_init_io(iomem_rcm, owner, &m5208_rcm_ops, cpu,
                           "m5208-rcm", 0x00000080);
     memory_region_add_subregion(address_space, 0xfc0a0000, iomem_rcm);
     /* SDRAMC.  */
-    memory_region_init_io(iomem, NULL, &m5208_sys_ops, NULL, "m5208-sys", 0x00004000);
+    memory_region_init_io(iomem, owner, &m5208_sys_ops, NULL, "m5208-sys", 0x00004000);
     memory_region_add_subregion(address_space, 0xfc0a8000, iomem);
     /* Timers.  */
     for (i = 0; i < 2; i++) {
         s = g_new0(m5208_timer_state, 1);
         s->timer = ptimer_init(m5208_timer_trigger, s, PTIMER_POLICY_LEGACY);
-        memory_region_init_io(&s->iomem, NULL, &m5208_timer_ops, s,
+        memory_region_init_io(&s->iomem, owner, &m5208_timer_ops, s,
                               "m5208-timer", 0x00004000);
         memory_region_add_subregion(address_space, 0xfc080000 + 0x4000 * i,
                                     &s->iomem);
@@ -296,14 +297,14 @@ static void mcf5208evb_init(MachineState *machine)
     /* TODO: Configure BARs.  */
 
     /* ROM at 0x00000000 */
-    memory_region_init_rom(rom, NULL, "mcf5208.rom", ROM_SIZE, &error_fatal);
+    memory_region_init_rom(rom, OBJECT(machine), "mcf5208.rom", ROM_SIZE, &error_fatal);
     memory_region_add_subregion(address_space_mem, 0x00000000, rom);
 
     /* DRAM at 0x40000000 */
     memory_region_add_subregion(address_space_mem, 0x40000000, machine->ram);
 
     /* Internal SRAM.  */
-    memory_region_init_ram(sram, NULL, "mcf5208.sram", 16 * KiB, &error_fatal);
+    memory_region_init_ram(sram, OBJECT(machine), "mcf5208.sram", 16 * KiB, &error_fatal);
     memory_region_add_subregion(address_space_mem, 0x80000000, sram);
 
     /* Internal peripherals.  */
@@ -316,7 +317,7 @@ static void mcf5208evb_init(MachineState *machine)
     mcf_uart_create_mmap(OBJECT(machine), 0xfc068000,
                          qdev_get_gpio_in(intc, 28), serial_hd(2));
 
-    mcf5208_sys_init(address_space_mem, intc, cpu);
+    mcf5208_sys_init(OBJECT(machine), address_space_mem, intc, cpu);
 
     mcf_fec_init(address_space_mem, 0xfc030000, intc);
 
hw/m68k/next-cube.c +5 -5
index c80d32ef29..564a10a69e 100644
@@ -1310,11 +1310,11 @@ static void next_cube_init(MachineState *machine)
     sysbus_mmio_map(SYS_BUS_DEVICE(pcdev), 5, 0x0211a000);
 
     /* BMAP memory */
-    memory_region_init_ram_flags_nomigrate(&m->bmapm1, NULL, "next.bmapmem",
+    memory_region_init_ram_flags_nomigrate(&m->bmapm1, OBJECT(machine), "next.bmapmem",
                                            64, RAM_SHARED, &error_fatal);
     memory_region_add_subregion(sysmem, 0x020c0000, &m->bmapm1);
     /* The Rev_2.5_v66.bin firmware accesses it at 0x820c0020, too */
-    memory_region_init_alias(&m->bmapm2, NULL, "next.bmapmem2", &m->bmapm1,
+    memory_region_init_alias(&m->bmapm2, OBJECT(machine), "next.bmapmem2", &m->bmapm1,
                              0x0, 64);
     memory_region_add_subregion(sysmem, 0x820c0000, &m->bmapm2);
 
@@ -1322,9 +1322,9 @@ static void next_cube_init(MachineState *machine)
     sysbus_create_simple(OBJECT(machine), "kbd", TYPE_NEXTKBD, 0x0200e000, NULL);
 
     /* Load ROM here */
-    memory_region_init_rom(&m->rom, NULL, "next.rom", 0x20000, &error_fatal);
+    memory_region_init_rom(&m->rom, OBJECT(machine), "next.rom", 0x20000, &error_fatal);
     memory_region_add_subregion(sysmem, 0x01000000, &m->rom);
-    memory_region_init_alias(&m->rom2, NULL, "next.rom2", &m->rom, 0x0,
+    memory_region_init_alias(&m->rom2, OBJECT(machine), "next.rom2", &m->rom, 0x0,
                              0x20000);
     memory_region_add_subregion(sysmem, 0x0, &m->rom2);
     Error *local_err = NULL;
@@ -1352,7 +1352,7 @@ static void next_cube_init(MachineState *machine)
     }
 
     /* DMA */
-    memory_region_init_io(&m->dmamem, NULL, &next_dma_ops, machine,
+    memory_region_init_io(&m->dmamem, OBJECT(machine), &next_dma_ops, machine,
                           "next.dma", 0x5000);
     memory_region_add_subregion(sysmem, 0x02000000, &m->dmamem);
 }
hw/m68k/q800.c +5 -5
index 15b3bcab5f..954cdf8489 100644
@@ -309,7 +309,7 @@ static void q800_machine_init(MachineState *machine)
     memory_region_add_subregion(get_system_memory(), IO_BASE + IO_SLICE,
                                 &m->macio_alias);
 
-    memory_region_init_io(&m->machine_id, NULL, &machine_id_ops, NULL,
+    memory_region_init_io(&m->machine_id, OBJECT(machine), &machine_id_ops, NULL,
                           "Machine ID", 4);
     memory_region_add_subregion(get_system_memory(), 0x5ffffffc,
                                 &m->machine_id);
@@ -407,7 +407,7 @@ static void q800_machine_init(MachineState *machine)
     sysbus_connect_irq(sysbus, 0,
                        qdev_get_gpio_in(DEVICE(&m->glue), GLUE_IRQ_IN_SONIC));
 
-    memory_region_init_rom(&m->dp8393x_prom, NULL, "dp8393x-q800.prom",
+    memory_region_init_rom(&m->dp8393x_prom, OBJECT(machine), "dp8393x-q800.prom",
                            SONIC_PROM_SIZE, &error_fatal);
     memory_region_add_subregion(get_system_memory(), SONIC_PROM_BASE,
                                 &m->dp8393x_prom);
@@ -606,7 +606,7 @@ static void q800_machine_init(MachineState *machine)
         BOOTINFO1(param_ptr, BI_MAC_VROW, macfb_mode->stride);
         BOOTINFO1(param_ptr, BI_MAC_SCCBASE, SCC_BASE);
 
-        memory_region_init_ram_ptr(&m->rom, NULL, "m68k_fake_mac.rom",
+        memory_region_init_ram_ptr(&m->rom, OBJECT(machine), "m68k_fake_mac.rom",
                                    sizeof(fake_mac_rom), fake_mac_rom);
         memory_region_set_readonly(&m->rom, true);
         memory_region_add_subregion(get_system_memory(), MACROM_ADDR, &m->rom);
@@ -651,12 +651,12 @@ static void q800_machine_init(MachineState *machine)
     } else {
         uint8_t *ptr;
         /* allocate and load BIOS */
-        memory_region_init_rom(&m->rom, NULL, "m68k_mac.rom", MACROM_SIZE,
+        memory_region_init_rom(&m->rom, OBJECT(machine), "m68k_mac.rom", MACROM_SIZE,
                                &error_abort);
         filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
         memory_region_add_subregion(get_system_memory(), MACROM_ADDR, &m->rom);
 
-        memory_region_init_alias(&m->rom_alias, NULL, "m68k_mac.rom-alias",
+        memory_region_init_alias(&m->rom_alias, OBJECT(machine), "m68k_mac.rom-alias",
                                  &m->rom, 0, MACROM_SIZE);
         memory_region_add_subregion(get_system_memory(), 0x40000000,
                                     &m->rom_alias);
Signature · 1 line
2.47.1
#256 lore raw

RFC PATCH v2 99/137 hw/ppc: Give memory regions an explicit owner

In reply to Alexander Graf

Convert memory_region_init*() calls that pass NULL owner to pass the enclosing machine or device instead.

Thread Object *owner through ppc4xx_l2sram_init() (called from sam460ex board init) and the static ppc4xx_sdram_banks() / sdram_bank_map() / sdram_bank_set_bcr() helpers (called from ppc4xx-sdram-ddr[2] realize and DCR write callbacks that already carry the device state).

No functional change intended.

RAMBlock idstrs are unchanged: the owners added here are Machine or SysBus devices, and memory_region_register_ram() maps both to dev=NULL for qemu_ram_set_idstr().

AI-used-for: code (refactoring)

---
 hw/ppc/amigaone.c      |  6 +++---
 hw/ppc/mac_newworld.c  |  2 +-
 hw/ppc/mac_oldworld.c  |  2 +-
 hw/ppc/pegasos.c       |  2 +-
 hw/ppc/ppc440.h        |  2 +-
 hw/ppc/ppc440_bamboo.c |  2 +-
 hw/ppc/ppc440_uc.c     | 10 +++++-----
 hw/ppc/ppc4xx_sdram.c  | 34 +++++++++++++++++-----------------
 hw/ppc/prep.c          |  2 +-
 hw/ppc/sam460ex.c      |  4 ++--
 10 files changed, 33 insertions(+), 33 deletions(-)
hw/ppc/amigaone.c +3 -3
index 60aed15a6e..4a4e52c1fe 100644
@@ -130,7 +130,7 @@ static void nvram_realize(DeviceState *dev, Error **errp)
     void *p;
     uint32_t crc, *c;
 
-    memory_region_init_rom_device(&s->mr, NULL, &nvram_ops, s, "nvram",
+    memory_region_init_rom_device(&s->mr, OBJECT(dev), &nvram_ops, s, "nvram",
                                   NVRAM_SIZE, &error_fatal);
     sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->mr);
     c = p = memory_region_get_ram_ptr(&s->mr);
@@ -297,7 +297,7 @@ static void amigaone_init(MachineState *machine)
     if (machine->ram_size < 1 * GiB + 32 * KiB) {
         /* Firmware uses this area for startup */
         mr = g_new(MemoryRegion, 1);
-        memory_region_init_ram(mr, NULL, "init-cache", 32 * KiB, &error_fatal);
+        memory_region_init_ram(mr, OBJECT(machine), "init-cache", 32 * KiB, &error_fatal);
         memory_region_add_subregion(get_system_memory(), INIT_RAM_ADDR, mr);
     }
 
@@ -313,7 +313,7 @@ static void amigaone_init(MachineState *machine)
 
     /* allocate and load firmware */
     rom = g_new(MemoryRegion, 1);
-    memory_region_init_rom(rom, NULL, "rom", PROM_SIZE, &error_fatal);
+    memory_region_init_rom(rom, OBJECT(machine), "rom", PROM_SIZE, &error_fatal);
     memory_region_add_subregion(get_system_memory(), PROM_ADDR, rom);
     if (!machine->firmware) {
         rom_add_blob_fixed("dummy-fw", dummy_fw, sizeof(dummy_fw),
hw/ppc/mac_newworld.c +1 -1
index a6af53e21a..392a1fb87d 100644
@@ -176,7 +176,7 @@ static void ppc_core99_init(MachineState *machine)
     memory_region_add_subregion(get_system_memory(), 0, machine->ram);
 
     /* allocate and load firmware ROM */
-    memory_region_init_rom(bios, NULL, "ppc_core99.bios", PROM_SIZE,
+    memory_region_init_rom(bios, OBJECT(machine), "ppc_core99.bios", PROM_SIZE,
                            &error_fatal);
     memory_region_add_subregion(get_system_memory(), PROM_BASE, bios);
 
hw/ppc/mac_oldworld.c +1 -1
index f9b62a518a..0fe8dfaf8c 100644
@@ -130,7 +130,7 @@ static void ppc_heathrow_init(MachineState *machine)
     memory_region_add_subregion(get_system_memory(), 0, machine->ram);
 
     /* allocate and load firmware ROM */
-    memory_region_init_rom(bios, NULL, "ppc_heathrow.bios", PROM_SIZE,
+    memory_region_init_rom(bios, OBJECT(machine), "ppc_heathrow.bios", PROM_SIZE,
                            &error_fatal);
     memory_region_add_subregion(get_system_memory(), PROM_BASE, bios);
 
hw/ppc/pegasos.c +1 -1
index 4917d8137a..426a54d8ee 100644
@@ -194,7 +194,7 @@ static void pegasos_init(MachineState *machine)
     if (pm->type == PEGASOS1) {
         prom_addr += PROM_SIZE;
     }
-    memory_region_init_rom(rom, NULL, "rom", PROM_SIZE, &error_fatal);
+    memory_region_init_rom(rom, OBJECT(machine), "rom", PROM_SIZE, &error_fatal);
     memory_region_add_subregion(get_system_memory(), prom_addr, rom);
     sz = load_elf(filename, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
                   ELFDATA2MSB, PPC_ELF_MACHINE, 0, 0);
hw/ppc/ppc440.h +1 -1
index 909373fb38..192b76adc4 100644
@@ -13,7 +13,7 @@
 
 #include "hw/ppc/ppc.h"
 
-void ppc4xx_l2sram_init(CPUPPCState *env);
+void ppc4xx_l2sram_init(Object *owner, CPUPPCState *env);
 void ppc4xx_cpr_init(CPUPPCState *env);
 void ppc4xx_sdr_init(CPUPPCState *env);
 void ppc4xx_ahb_init(CPUPPCState *env);
hw/ppc/ppc440_bamboo.c +1 -1
index 2d9efeba77..5aad2a504b 100644
@@ -194,7 +194,7 @@ static void bamboo_init(MachineState *machine)
         exit(1);
     }
 
-    memory_region_init_alias(isa, NULL, "isa_mmio",
+    memory_region_init_alias(isa, OBJECT(machine), "isa_mmio",
                              get_system_io(), 0, PPC440EP_PCI_IOLEN);
     memory_region_add_subregion(get_system_memory(), PPC440EP_PCI_IO, isa);
 
hw/ppc/ppc440_uc.c +5 -5
index 016c756c19..e86519326e 100644
@@ -167,19 +167,19 @@ static void l2sram_reset(void *opaque)
     memset(l2sram->isram0, 0, sizeof(l2sram->isram0));
 }
 
-void ppc4xx_l2sram_init(CPUPPCState *env)
+void ppc4xx_l2sram_init(Object *owner, CPUPPCState *env)
 {
     ppc4xx_l2sram_t *l2sram;
 
     l2sram = g_malloc0(sizeof(*l2sram));
     /* XXX: Size is 4*64kB for 460ex, cf. U-Boot, ppc4xx-isram.h */
-    memory_region_init_ram(&l2sram->bank[0], NULL, "ppc4xx.l2sram_bank0",
+    memory_region_init_ram(&l2sram->bank[0], owner, "ppc4xx.l2sram_bank0",
                            64 * KiB, &error_abort);
-    memory_region_init_ram(&l2sram->bank[1], NULL, "ppc4xx.l2sram_bank1",
+    memory_region_init_ram(&l2sram->bank[1], owner, "ppc4xx.l2sram_bank1",
                            64 * KiB, &error_abort);
-    memory_region_init_ram(&l2sram->bank[2], NULL, "ppc4xx.l2sram_bank2",
+    memory_region_init_ram(&l2sram->bank[2], owner, "ppc4xx.l2sram_bank2",
                            64 * KiB, &error_abort);
-    memory_region_init_ram(&l2sram->bank[3], NULL, "ppc4xx.l2sram_bank3",
+    memory_region_init_ram(&l2sram->bank[3], owner, "ppc4xx.l2sram_bank3",
                            64 * KiB, &error_abort);
     qemu_register_reset(&l2sram_reset, l2sram);
     ppc_dcr_register(env, DCR_L2CACHE_CFG,
hw/ppc/ppc4xx_sdram.c +17 -17
index b2c8f96d5f..8be3bb3160 100644
@@ -53,7 +53,7 @@
  * must be one of a small set of sizes. The number of banks and the supported
  * sizes varies by SoC.
  */
-static bool ppc4xx_sdram_banks(MemoryRegion *ram, int nr_banks,
+static bool ppc4xx_sdram_banks(Object *owner, MemoryRegion *ram, int nr_banks,
                                Ppc4xxSdramBank ram_banks[],
                                const ram_addr_t sdram_bank_sizes[],
                                Error **errp)
@@ -76,7 +76,7 @@ static bool ppc4xx_sdram_banks(MemoryRegion *ram, int nr_banks,
                 base += bank_size;
                 size_left -= bank_size;
                 snprintf(name, sizeof(name), "ppc4xx.sdram%d", i);
-                memory_region_init_alias(&ram_banks[i].ram, NULL, name, ram,
+                memory_region_init_alias(&ram_banks[i].ram, owner, name, ram,
                                          ram_banks[i].base, ram_banks[i].size);
                 break;
             }
@@ -108,10 +108,10 @@ static bool ppc4xx_sdram_banks(MemoryRegion *ram, int nr_banks,
     return true;
 }
 
-static void sdram_bank_map(Ppc4xxSdramBank *bank)
+static void sdram_bank_map(Object *owner, Ppc4xxSdramBank *bank)
 {
     trace_ppc4xx_sdram_map(bank->base, bank->size);
-    memory_region_init(&bank->container, NULL, "sdram-container", bank->size);
+    memory_region_init(&bank->container, owner, "sdram-container", bank->size);
     memory_region_add_subregion(&bank->container, 0, &bank->ram);
     memory_region_add_subregion(get_system_memory(), bank->base,
                                 &bank->container);
@@ -125,7 +125,7 @@ static void sdram_bank_unmap(Ppc4xxSdramBank *bank)
     object_unparent(OBJECT(&bank->container));
 }
 
-static void sdram_bank_set_bcr(Ppc4xxSdramBank *bank, uint32_t bcr,
+static void sdram_bank_set_bcr(Object *owner, Ppc4xxSdramBank *bank, uint32_t bcr,
                                hwaddr base, hwaddr size, int enabled)
 {
     if (memory_region_is_mapped(&bank->container)) {
@@ -135,7 +135,7 @@ static void sdram_bank_set_bcr(Ppc4xxSdramBank *bank, uint32_t bcr,
     bank->base = base;
     bank->size = size;
     if (enabled && (bcr & 1)) {
-        sdram_bank_map(bank);
+        sdram_bank_map(owner, bank);
     }
 }
 
@@ -296,7 +296,7 @@ static void sdram_ddr_dcr_write(void *opaque, int dcrn, uint32_t val)
                 /* validate all RAM mappings */
                 for (i = 0; i < s->nbanks; i++) {
                     if (s->bank[i].size) {
-                        sdram_bank_set_bcr(&s->bank[i], s->bank[i].bcr,
+                        sdram_bank_set_bcr(OBJECT(s), &s->bank[i], s->bank[i].bcr,
                                            s->bank[i].base, s->bank[i].size,
                                            1);
                     }
@@ -307,7 +307,7 @@ static void sdram_ddr_dcr_write(void *opaque, int dcrn, uint32_t val)
                 /* invalidate all RAM mappings */
                 for (i = 0; i < s->nbanks; i++) {
                     if (s->bank[i].size) {
-                        sdram_bank_set_bcr(&s->bank[i], s->bank[i].bcr,
+                        sdram_bank_set_bcr(OBJECT(s), &s->bank[i], s->bank[i].bcr,
                                            s->bank[i].base, s->bank[i].size,
                                            0);
                     }
@@ -337,7 +337,7 @@ static void sdram_ddr_dcr_write(void *opaque, int dcrn, uint32_t val)
             i = (s->addr - 0x40) / 4;
             val &= SDRAM_DDR_BCR_MASK;
             if (s->bank[i].size) {
-                sdram_bank_set_bcr(&s->bank[i], val,
+                sdram_bank_set_bcr(OBJECT(s), &s->bank[i], val,
                                    sdram_ddr_base(val), sdram_ddr_size(val),
                                    s->cfg & 0x80000000);
             }
@@ -400,17 +400,17 @@ static void ppc4xx_sdram_ddr_realize(DeviceState *dev, Error **errp)
         error_setg(errp, "Missing dram memory region");
         return;
     }
-    if (!ppc4xx_sdram_banks(s->dram_mr, s->nbanks, s->bank,
+    if (!ppc4xx_sdram_banks(OBJECT(s), s->dram_mr, s->nbanks, s->bank,
                             valid_bank_sizes, errp)) {
         return;
     }
     for (i = 0; i < s->nbanks; i++) {
         if (s->bank[i].size) {
             s->bank[i].bcr = sdram_ddr_bcr(s->bank[i].base, s->bank[i].size);
-            sdram_bank_set_bcr(&s->bank[i], s->bank[i].bcr,
+            sdram_bank_set_bcr(OBJECT(s), &s->bank[i], s->bank[i].bcr,
                                s->bank[i].base, s->bank[i].size, 0);
         } else {
-            sdram_bank_set_bcr(&s->bank[i], 0, 0, 0, 0);
+            sdram_bank_set_bcr(OBJECT(s), &s->bank[i], 0, 0, 0, 0);
         }
         trace_ppc4xx_sdram_init(sdram_ddr_base(s->bank[i].bcr),
                                 sdram_ddr_size(s->bank[i].bcr),
@@ -607,7 +607,7 @@ static void sdram_ddr2_dcr_write(void *opaque, int dcrn, uint32_t val)
                 /* validate all RAM mappings */
                 for (i = 0; i < s->nbanks; i++) {
                     if (s->bank[i].size) {
-                        sdram_bank_set_bcr(&s->bank[i], s->bank[i].bcr,
+                        sdram_bank_set_bcr(OBJECT(s), &s->bank[i], s->bank[i].bcr,
                                            s->bank[i].base, s->bank[i].size,
                                            1);
                     }
@@ -619,7 +619,7 @@ static void sdram_ddr2_dcr_write(void *opaque, int dcrn, uint32_t val)
                 /* invalidate all RAM mappings */
                 for (i = 0; i < s->nbanks; i++) {
                     if (s->bank[i].size) {
-                        sdram_bank_set_bcr(&s->bank[i], s->bank[i].bcr,
+                        sdram_bank_set_bcr(OBJECT(s), &s->bank[i], s->bank[i].bcr,
                                            s->bank[i].base, s->bank[i].size,
                                            0);
                     }
@@ -666,7 +666,7 @@ static void ppc4xx_sdram_ddr2_realize(DeviceState *dev, Error **errp)
         error_setg(errp, "Missing dram memory region");
         return;
     }
-    if (!ppc4xx_sdram_banks(s->dram_mr, s->nbanks, s->bank,
+    if (!ppc4xx_sdram_banks(OBJECT(s), s->dram_mr, s->nbanks, s->bank,
                             valid_bank_sizes, errp)) {
         return;
     }
@@ -674,10 +674,10 @@ static void ppc4xx_sdram_ddr2_realize(DeviceState *dev, Error **errp)
         if (s->bank[i].size) {
             s->bank[i].bcr = sdram_ddr2_bcr(s->bank[i].base, s->bank[i].size);
             s->bank[i].bcr &= SDRAM_DDR2_BCR_MASK;
-            sdram_bank_set_bcr(&s->bank[i], s->bank[i].bcr,
+            sdram_bank_set_bcr(OBJECT(s), &s->bank[i], s->bank[i].bcr,
                                s->bank[i].base, s->bank[i].size, 0);
         } else {
-            sdram_bank_set_bcr(&s->bank[i], 0, 0, 0, 0);
+            sdram_bank_set_bcr(OBJECT(s), &s->bank[i], 0, 0, 0, 0);
         }
         trace_ppc4xx_sdram_init(sdram_ddr2_base(s->bank[i].bcr),
                                 sdram_ddr2_size(s->bank[i].bcr),
hw/ppc/prep.c +1 -1
index 52f94b206a..c79736a1f3 100644
@@ -274,7 +274,7 @@ static void ibm_40p_init(MachineState *machine)
         error_report("Could not find bios image '%s'", bios_name);
         exit(1);
     }
-    memory_region_init_rom(bios, NULL, "bios", BIOS_SIZE, &error_fatal);
+    memory_region_init_rom(bios, OBJECT(machine), "bios", BIOS_SIZE, &error_fatal);
     memory_region_add_subregion(get_system_memory(), BIOS_ADDR, bios);
     bios_size = load_elf(filename, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
                          ELFDATA2MSB, PPC_ELF_MACHINE, 0, 0);
hw/ppc/sam460ex.c +2 -2
index 59c217e2b2..20b2acb40b 100644
@@ -375,9 +375,9 @@ static void sam460ex_init(MachineState *machine)
     ppc4xx_dma_init(env, 0x200);
 
     /* 256K of L2 cache as memory */
-    ppc4xx_l2sram_init(env);
+    ppc4xx_l2sram_init(OBJECT(machine), env);
     /* FIXME: remove this after fixing l2sram mapping in ppc440_uc.c? */
-    memory_region_init_ram(l2cache_ram, NULL, "ppc440.l2cache_ram", 256 * KiB,
+    memory_region_init_ram(l2cache_ram, OBJECT(machine), "ppc440.l2cache_ram", 256 * KiB,
                            &error_abort);
     memory_region_add_subregion(get_system_memory(), 0x400000000LL,
                                 l2cache_ram);
Signature · 1 line
2.47.1
#257 lore raw

RFC PATCH v2 100/137 hw/tricore: Give memory regions an explicit owner

In reply to Alexander Graf

Convert memory_region_init*() calls that pass NULL owner to pass the enclosing machine or device instead.

Thread Object *owner through the static make_rom() / make_ram() / make_alias() helpers in tc27x_soc.c. All callers are inside tc27x_soc_init_memory_mapping(DeviceState *dev_soc).

No functional change intended.

RAMBlock idstrs are unchanged: the owners added here are Machine or SysBus devices, and memory_region_register_ram() maps both to dev=NULL for qemu_ram_set_idstr().

AI-used-for: code (refactoring)

---
 hw/tricore/tc27x_soc.c         | 77 +++++++++++++++++-----------------
 hw/tricore/tricore_testboard.c | 12 +++---
 2 files changed, 45 insertions(+), 44 deletions(-)
hw/tricore/tc27x_soc.c +39 -38
index 5b1b07cee1..0475698b29 100644
@@ -67,10 +67,10 @@ const MemmapEntry tc27x_soc_memmap[] = {
  * Initialize the auxiliary ROM region @mr and map it into
  * the memory map at @base.
  */
-static void make_rom(MemoryRegion *mr, const char *name,
+static void make_rom(Object *owner, MemoryRegion *mr, const char *name,
                      hwaddr base, hwaddr size)
 {
-    memory_region_init_rom(mr, NULL, name, size, &error_fatal);
+    memory_region_init_rom(mr, owner, name, size, &error_fatal);
     memory_region_add_subregion(get_system_memory(), base, mr);
 }
 
@@ -78,10 +78,10 @@ static void make_rom(MemoryRegion *mr, const char *name,
  * Initialize the auxiliary RAM region @mr and map it into
  * the memory map at @base.
  */
-static void make_ram(MemoryRegion *mr, const char *name,
+static void make_ram(Object *owner, MemoryRegion *mr, const char *name,
                      hwaddr base, hwaddr size)
 {
-    memory_region_init_ram(mr, NULL, name, size, &error_fatal);
+    memory_region_init_ram(mr, owner, name, size, &error_fatal);
     memory_region_add_subregion(get_system_memory(), base, mr);
 }
 
@@ -89,10 +89,10 @@ static void make_ram(MemoryRegion *mr, const char *name,
  * Create an alias of an entire original MemoryRegion @orig
  * located at @base in the memory map.
  */
-static void make_alias(MemoryRegion *mr, const char *name,
+static void make_alias(Object *owner, MemoryRegion *mr, const char *name,
                            MemoryRegion *orig, hwaddr base)
 {
-    memory_region_init_alias(mr, NULL, name, orig, 0,
+    memory_region_init_alias(mr, owner, name, orig, 0,
                              memory_region_size(orig));
     memory_region_add_subregion(get_system_memory(), base, mr);
 }
@@ -101,81 +101,82 @@ static void tc27x_soc_init_memory_mapping(DeviceState *dev_soc)
 {
     TC27XSoCState *s = TC27X_SOC(dev_soc);
     TC27XSoCClass *sc = TC27X_SOC_GET_CLASS(s);
+    Object *obj = OBJECT(dev_soc);
 
-    make_ram(&s->cpu0mem.dspr, "CPU0.DSPR",
+    make_ram(obj, &s->cpu0mem.dspr, "CPU0.DSPR",
         sc->memmap[TC27XD_DSPR0].base, sc->memmap[TC27XD_DSPR0].size);
-    make_ram(&s->cpu0mem.pspr, "CPU0.PSPR",
+    make_ram(obj, &s->cpu0mem.pspr, "CPU0.PSPR",
         sc->memmap[TC27XD_PSPR0].base, sc->memmap[TC27XD_PSPR0].size);
-    make_ram(&s->cpu1mem.dspr, "CPU1.DSPR",
+    make_ram(obj, &s->cpu1mem.dspr, "CPU1.DSPR",
         sc->memmap[TC27XD_DSPR1].base, sc->memmap[TC27XD_DSPR1].size);
-    make_ram(&s->cpu1mem.pspr, "CPU1.PSPR",
+    make_ram(obj, &s->cpu1mem.pspr, "CPU1.PSPR",
         sc->memmap[TC27XD_PSPR1].base, sc->memmap[TC27XD_PSPR1].size);
-    make_ram(&s->cpu2mem.dspr, "CPU2.DSPR",
+    make_ram(obj, &s->cpu2mem.dspr, "CPU2.DSPR",
         sc->memmap[TC27XD_DSPR2].base, sc->memmap[TC27XD_DSPR2].size);
-    make_ram(&s->cpu2mem.pspr, "CPU2.PSPR",
+    make_ram(obj, &s->cpu2mem.pspr, "CPU2.PSPR",
         sc->memmap[TC27XD_PSPR2].base, sc->memmap[TC27XD_PSPR2].size);
 
     /* TODO: Control Cache mapping with Memory Test Unit (MTU) */
-    make_ram(&s->cpu2mem.dcache, "CPU2.DCACHE",
+    make_ram(obj, &s->cpu2mem.dcache, "CPU2.DCACHE",
         sc->memmap[TC27XD_DCACHE2].base, sc->memmap[TC27XD_DCACHE2].size);
-    make_ram(&s->cpu2mem.dtag,   "CPU2.DTAG",
+    make_ram(obj, &s->cpu2mem.dtag,   "CPU2.DTAG",
         sc->memmap[TC27XD_DTAG2].base, sc->memmap[TC27XD_DTAG2].size);
-    make_ram(&s->cpu2mem.pcache, "CPU2.PCACHE",
+    make_ram(obj, &s->cpu2mem.pcache, "CPU2.PCACHE",
         sc->memmap[TC27XD_PCACHE2].base, sc->memmap[TC27XD_PCACHE2].size);
-    make_ram(&s->cpu2mem.ptag,   "CPU2.PTAG",
+    make_ram(obj, &s->cpu2mem.ptag,   "CPU2.PTAG",
         sc->memmap[TC27XD_PTAG2].base, sc->memmap[TC27XD_PTAG2].size);
 
-    make_ram(&s->cpu1mem.dcache, "CPU1.DCACHE",
+    make_ram(obj, &s->cpu1mem.dcache, "CPU1.DCACHE",
         sc->memmap[TC27XD_DCACHE1].base, sc->memmap[TC27XD_DCACHE1].size);
-    make_ram(&s->cpu1mem.dtag,   "CPU1.DTAG",
+    make_ram(obj, &s->cpu1mem.dtag,   "CPU1.DTAG",
         sc->memmap[TC27XD_DTAG1].base, sc->memmap[TC27XD_DTAG1].size);
-    make_ram(&s->cpu1mem.pcache, "CPU1.PCACHE",
+    make_ram(obj, &s->cpu1mem.pcache, "CPU1.PCACHE",
         sc->memmap[TC27XD_PCACHE1].base, sc->memmap[TC27XD_PCACHE1].size);
-    make_ram(&s->cpu1mem.ptag,   "CPU1.PTAG",
+    make_ram(obj, &s->cpu1mem.ptag,   "CPU1.PTAG",
         sc->memmap[TC27XD_PTAG1].base, sc->memmap[TC27XD_PTAG1].size);
 
-    make_ram(&s->cpu0mem.pcache, "CPU0.PCACHE",
+    make_ram(obj, &s->cpu0mem.pcache, "CPU0.PCACHE",
         sc->memmap[TC27XD_PCACHE0].base, sc->memmap[TC27XD_PCACHE0].size);
-    make_ram(&s->cpu0mem.ptag,   "CPU0.PTAG",
+    make_ram(obj, &s->cpu0mem.ptag,   "CPU0.PTAG",
         sc->memmap[TC27XD_PTAG0].base, sc->memmap[TC27XD_PTAG0].size);
 
     /*
      * TriCore QEMU executes CPU0 only, thus it is sufficient to map
      * LOCAL.PSPR/LOCAL.DSPR exclusively onto PSPR0/DSPR0.
      */
-    make_alias(&s->psprX, "LOCAL.PSPR", &s->cpu0mem.pspr,
+    make_alias(obj, &s->psprX, "LOCAL.PSPR", &s->cpu0mem.pspr,
         sc->memmap[TC27XD_PSPRX].base);
-    make_alias(&s->dsprX, "LOCAL.DSPR", &s->cpu0mem.dspr,
+    make_alias(obj, &s->dsprX, "LOCAL.DSPR", &s->cpu0mem.dspr,
         sc->memmap[TC27XD_DSPRX].base);
 
-    make_ram(&s->flashmem.pflash0_c, "PF0",
+    make_ram(obj, &s->flashmem.pflash0_c, "PF0",
         sc->memmap[TC27XD_PFLASH0_C].base, sc->memmap[TC27XD_PFLASH0_C].size);
-    make_ram(&s->flashmem.pflash1_c, "PF1",
+    make_ram(obj, &s->flashmem.pflash1_c, "PF1",
         sc->memmap[TC27XD_PFLASH1_C].base, sc->memmap[TC27XD_PFLASH1_C].size);
-    make_ram(&s->flashmem.dflash0,   "DF0",
+    make_ram(obj, &s->flashmem.dflash0,   "DF0",
         sc->memmap[TC27XD_DFLASH0].base, sc->memmap[TC27XD_DFLASH0].size);
-    make_ram(&s->flashmem.dflash1,   "DF1",
+    make_ram(obj, &s->flashmem.dflash1,   "DF1",
         sc->memmap[TC27XD_DFLASH1].base, sc->memmap[TC27XD_DFLASH1].size);
-    make_ram(&s->flashmem.olda_c,    "OLDA",
+    make_ram(obj, &s->flashmem.olda_c,    "OLDA",
         sc->memmap[TC27XD_OLDA_C].base, sc->memmap[TC27XD_OLDA_C].size);
-    make_rom(&s->flashmem.brom_c,    "BROM",
+    make_rom(obj, &s->flashmem.brom_c,    "BROM",
         sc->memmap[TC27XD_BROM_C].base, sc->memmap[TC27XD_BROM_C].size);
-    make_ram(&s->flashmem.lmuram_c,  "LMURAM",
+    make_ram(obj, &s->flashmem.lmuram_c,  "LMURAM",
         sc->memmap[TC27XD_LMURAM_C].base, sc->memmap[TC27XD_LMURAM_C].size);
-    make_ram(&s->flashmem.emem_c,    "EMEM",
+    make_ram(obj, &s->flashmem.emem_c,    "EMEM",
         sc->memmap[TC27XD_EMEM_C].base, sc->memmap[TC27XD_EMEM_C].size);
 
-    make_alias(&s->flashmem.pflash0_u, "PF0.U",    &s->flashmem.pflash0_c,
+    make_alias(obj, &s->flashmem.pflash0_u, "PF0.U",    &s->flashmem.pflash0_c,
         sc->memmap[TC27XD_PFLASH0_U].base);
-    make_alias(&s->flashmem.pflash1_u, "PF1.U",    &s->flashmem.pflash1_c,
+    make_alias(obj, &s->flashmem.pflash1_u, "PF1.U",    &s->flashmem.pflash1_c,
         sc->memmap[TC27XD_PFLASH1_U].base);
-    make_alias(&s->flashmem.olda_u,    "OLDA.U",   &s->flashmem.olda_c,
+    make_alias(obj, &s->flashmem.olda_u,    "OLDA.U",   &s->flashmem.olda_c,
         sc->memmap[TC27XD_OLDA_U].base);
-    make_alias(&s->flashmem.brom_u,    "BROM.U",   &s->flashmem.brom_c,
+    make_alias(obj, &s->flashmem.brom_u,    "BROM.U",   &s->flashmem.brom_c,
         sc->memmap[TC27XD_BROM_U].base);
-    make_alias(&s->flashmem.lmuram_u,  "LMURAM.U", &s->flashmem.lmuram_c,
+    make_alias(obj, &s->flashmem.lmuram_u,  "LMURAM.U", &s->flashmem.lmuram_c,
         sc->memmap[TC27XD_LMURAM_U].base);
-    make_alias(&s->flashmem.emem_u,    "EMEM.U",   &s->flashmem.emem_c,
+    make_alias(obj, &s->flashmem.emem_u,    "EMEM.U",   &s->flashmem.emem_c,
         sc->memmap[TC27XD_EMEM_U].base);
 }
 
hw/tricore/tricore_testboard.c +6 -6
index 9e8cccbd59..4b5398ab95 100644
@@ -70,17 +70,17 @@ static void tricore_testboard_init(MachineState *machine, int board_id)
 
     cpu = TRICORE_CPU(cpu_create(mo, "cpu", machine->cpu_type));
     env = &cpu->env;
-    memory_region_init_ram(ext_cram, NULL, "powerlink_ext_c.ram",
+    memory_region_init_ram(ext_cram, OBJECT(machine), "powerlink_ext_c.ram",
                            2 * MiB, &error_fatal);
-    memory_region_init_ram(ext_dram, NULL, "powerlink_ext_d.ram",
+    memory_region_init_ram(ext_dram, OBJECT(machine), "powerlink_ext_d.ram",
                            4 * MiB, &error_fatal);
-    memory_region_init_ram(int_cram, NULL, "powerlink_int_c.ram", 48 * KiB,
+    memory_region_init_ram(int_cram, OBJECT(machine), "powerlink_int_c.ram", 48 * KiB,
                            &error_fatal);
-    memory_region_init_ram(int_dram, NULL, "powerlink_int_d.ram", 48 * KiB,
+    memory_region_init_ram(int_dram, OBJECT(machine), "powerlink_int_d.ram", 48 * KiB,
                            &error_fatal);
-    memory_region_init_ram(pcp_data, NULL, "powerlink_pcp_data.ram",
+    memory_region_init_ram(pcp_data, OBJECT(machine), "powerlink_pcp_data.ram",
                            16 * KiB, &error_fatal);
-    memory_region_init_ram(pcp_text, NULL, "powerlink_pcp_text.ram",
+    memory_region_init_ram(pcp_text, OBJECT(machine), "powerlink_pcp_text.ram",
                            32 * KiB, &error_fatal);
 
     memory_region_add_subregion(sysmem, 0x80000000, ext_cram);
Signature · 1 line
2.47.1
#258 lore raw

RFC PATCH v2 101/137 hw/xtensa: Give memory regions an explicit owner

In reply to Alexander Graf

Convert memory_region_init*() calls that pass NULL owner to pass the enclosing machine or device instead.

Thread Object *owner through xtensa_create_memory_regions(), xtensa_mx_pic_register_cpu() and the static xtfpga_fpga_init() helper. All callers are inside board init functions.

No functional change intended.

RAMBlock idstrs are unchanged: the owners added here are Machine or SysBus devices, and memory_region_register_ram() maps both to dev=NULL for qemu_ram_set_idstr().

AI-used-for: code (refactoring)

---
 hw/xtensa/mx_pic.c         |  4 ++--
 hw/xtensa/sim.c            | 15 ++++++++-------
 hw/xtensa/xtensa_memory.c  |  5 +++--
 hw/xtensa/xtensa_memory.h  |  3 ++-
 hw/xtensa/xtfpga.c         | 30 ++++++++++++++++--------------
 include/hw/xtensa/mx_pic.h |  2 +-
 6 files changed, 32 insertions(+), 27 deletions(-)
hw/xtensa/mx_pic.c +2 -2
index 8ded3bc79b..f349fb125c 100644
@@ -299,7 +299,7 @@ static const MemoryRegionOps xtensa_mx_pic_ops = {
     },
 };
 
-MemoryRegion *xtensa_mx_pic_register_cpu(XtensaMxPic *mx,
+MemoryRegion *xtensa_mx_pic_register_cpu(Object *owner, XtensaMxPic *mx,
                                          qemu_irq *irq,
                                          qemu_irq runstall)
 {
@@ -309,7 +309,7 @@ MemoryRegion *xtensa_mx_pic_register_cpu(XtensaMxPic *mx,
     mx_cpu->irq = irq;
     mx_cpu->runstall = runstall;
 
-    memory_region_init_io(&mx_cpu->reg, NULL, &xtensa_mx_pic_ops, mx_cpu,
+    memory_region_init_io(&mx_cpu->reg, owner, &xtensa_mx_pic_ops, mx_cpu,
                           "mx_pic", 0x280);
 
     ++mx->n_cpu;
hw/xtensa/sim.c +8 -7
index ad1439a0b4..e3cd69ceca 100644
@@ -60,10 +60,11 @@ XtensaCPU *xtensa_sim_common_init(MachineState *machine)
     XtensaCPU *cpu = NULL;
     CPUXtensaState *env = NULL;
     ram_addr_t ram_size = machine->ram_size;
+    Object *mo = OBJECT(machine);
     int n;
 
     for (n = 0; n < machine->smp.cpus; n++) {
-        cpu = XTENSA_CPU(cpu_create(OBJECT(machine), "cpu[*]", machine->cpu_type));
+        cpu = XTENSA_CPU(cpu_create(mo, "cpu[*]", machine->cpu_type));
         env = &cpu->env;
 
         env->sregs[PRID] = n;
@@ -78,17 +79,17 @@ XtensaCPU *xtensa_sim_common_init(MachineState *machine)
         XtensaMemory sysram = env->config->sysram;
 
         sysram.location[0].size = ram_size;
-        xtensa_create_memory_regions(&env->config->instrom, "xtensa.instrom",
+        xtensa_create_memory_regions(mo, &env->config->instrom, "xtensa.instrom",
                                      get_system_memory());
-        xtensa_create_memory_regions(&env->config->instram, "xtensa.instram",
+        xtensa_create_memory_regions(mo, &env->config->instram, "xtensa.instram",
                                      get_system_memory());
-        xtensa_create_memory_regions(&env->config->datarom, "xtensa.datarom",
+        xtensa_create_memory_regions(mo, &env->config->datarom, "xtensa.datarom",
                                      get_system_memory());
-        xtensa_create_memory_regions(&env->config->dataram, "xtensa.dataram",
+        xtensa_create_memory_regions(mo, &env->config->dataram, "xtensa.dataram",
                                      get_system_memory());
-        xtensa_create_memory_regions(&env->config->sysrom, "xtensa.sysrom",
+        xtensa_create_memory_regions(mo, &env->config->sysrom, "xtensa.sysrom",
                                      get_system_memory());
-        xtensa_create_memory_regions(&sysram, "xtensa.sysram",
+        xtensa_create_memory_regions(mo, &sysram, "xtensa.sysram",
                                      get_system_memory());
     }
     if (serial_hd(0)) {
hw/xtensa/xtensa_memory.c +3 -2
index 13a6077d86..4477eea0ad 100644
@@ -31,7 +31,8 @@
 #include "qemu/error-report.h"
 #include "xtensa_memory.h"
 
-void xtensa_create_memory_regions(const XtensaMemory *memory,
+void xtensa_create_memory_regions(Object *owner,
+                                  const XtensaMemory *memory,
                                   const char *name,
                                   MemoryRegion *super)
 {
@@ -43,7 +44,7 @@ void xtensa_create_memory_regions(const XtensaMemory *memory,
 
         g_string_printf(num_name, "%s%u", name, i);
         m = g_new(MemoryRegion, 1);
-        memory_region_init_ram(m, NULL, num_name->str,
+        memory_region_init_ram(m, owner, num_name->str,
                                memory->location[i].size, &error_fatal);
         memory_region_add_subregion(super, memory->location[i].addr, m);
     }
hw/xtensa/xtensa_memory.h +2 -1
index c86ad06685..b8b2d4b8b4 100644
@@ -30,7 +30,8 @@
 
 #include "target/xtensa/cpu.h"
 
-void xtensa_create_memory_regions(const XtensaMemory *memory,
+void xtensa_create_memory_regions(Object *owner,
+                                  const XtensaMemory *memory,
                                   const char *name,
                                   MemoryRegion *super);
 
hw/xtensa/xtfpga.c +16 -14
index 1c48283f5d..f0c21180a2 100644
@@ -125,12 +125,13 @@ static const MemoryRegionOps xtfpga_fpga_ops = {
     .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
-static XtfpgaFpgaState *xtfpga_fpga_init(MemoryRegion *address_space,
+static XtfpgaFpgaState *xtfpga_fpga_init(Object *owner,
+                                         MemoryRegion *address_space,
                                          hwaddr base, uint32_t freq)
 {
     XtfpgaFpgaState *s = g_new(XtfpgaFpgaState, 1);
 
-    memory_region_init_io(&s->iomem, NULL, &xtfpga_fpga_ops, s,
+    memory_region_init_io(&s->iomem, owner, &xtfpga_fpga_ops, s,
                           "xtfpga.fpga", 0x10000);
     memory_region_add_subregion(address_space, base, &s->iomem);
     s->freq = freq;
@@ -243,6 +244,7 @@ static void xtfpga_init(const XtfpgaBoardDesc *board, MachineState *machine)
     uint32_t freq = 10000000;
     int n;
     unsigned int smp_cpus = machine->smp.cpus;
+    Object *mo = OBJECT(machine);
 
     if (smp_cpus > 1) {
         mx_pic = xtensa_mx_pic_init(31);
@@ -262,7 +264,7 @@ static void xtfpga_init(const XtfpgaBoardDesc *board, MachineState *machine)
         if (mx_pic) {
             MemoryRegion *mx_eri;
 
-            mx_eri = xtensa_mx_pic_register_cpu(mx_pic,
+            mx_eri = xtensa_mx_pic_register_cpu(OBJECT(machine), mx_pic,
                                                 xtensa_get_extints(cenv),
                                                 xtensa_get_runstall(cenv));
             memory_region_add_subregion(xtensa_get_er_region(cenv),
@@ -286,30 +288,30 @@ static void xtfpga_init(const XtfpgaBoardDesc *board, MachineState *machine)
         XtensaMemory sysram = env->config->sysram;
 
         sysram.location[0].size = machine->ram_size;
-        xtensa_create_memory_regions(&env->config->instrom, "xtensa.instrom",
+        xtensa_create_memory_regions(mo, &env->config->instrom, "xtensa.instrom",
                                      system_memory);
-        xtensa_create_memory_regions(&env->config->instram, "xtensa.instram",
+        xtensa_create_memory_regions(mo, &env->config->instram, "xtensa.instram",
                                      system_memory);
-        xtensa_create_memory_regions(&env->config->datarom, "xtensa.datarom",
+        xtensa_create_memory_regions(mo, &env->config->datarom, "xtensa.datarom",
                                      system_memory);
-        xtensa_create_memory_regions(&env->config->dataram, "xtensa.dataram",
+        xtensa_create_memory_regions(mo, &env->config->dataram, "xtensa.dataram",
                                      system_memory);
-        xtensa_create_memory_regions(&sysram, "xtensa.sysram",
+        xtensa_create_memory_regions(mo, &sysram, "xtensa.sysram",
                                      system_memory);
     }
 
     system_io = g_malloc(sizeof(*system_io));
-    memory_region_init_io(system_io, NULL, &xtfpga_io_ops, NULL, "xtfpga.io",
+    memory_region_init_io(system_io, OBJECT(machine), &xtfpga_io_ops, NULL, "xtfpga.io",
                           system_io_size);
     memory_region_add_subregion(system_memory, board->io[0], system_io);
     if (board->io[1]) {
         MemoryRegion *io = g_malloc(sizeof(*io));
 
-        memory_region_init_alias(io, NULL, "xtfpga.io.cached",
+        memory_region_init_alias(io, OBJECT(machine), "xtfpga.io.cached",
                                  system_io, 0, system_io_size);
         memory_region_add_subregion(system_memory, board->io[1], io);
     }
-    xtfpga_fpga_init(system_io, 0x0d020000, freq);
+    xtfpga_fpga_init(OBJECT(machine), system_io, 0x0d020000, freq);
     xtfpga_net_init(system_io, 0x0d030000, 0x0d030400, 0x0d800000, extints[1]);
 
     serial_mm_init(OBJECT(machine), system_io, 0x0d050020, 2, extints[0],
@@ -341,7 +343,7 @@ static void xtfpga_init(const XtfpgaBoardDesc *board, MachineState *machine)
         lowmem_end += env->config->sysram.location[0].addr;
         cur_lowmem += env->config->sysram.location[0].addr;
 
-        xtensa_create_memory_regions(&env->config->sysrom, "xtensa.sysrom",
+        xtensa_create_memory_regions(mo, &env->config->sysrom, "xtensa.sysrom",
                                      system_memory);
 
         if (kernel_cmdline) {
@@ -465,13 +467,13 @@ static void xtfpga_init(const XtfpgaBoardDesc *board, MachineState *machine)
                 size = board->flash->size - board->flash->boot_base;
             }
 
-            memory_region_init_alias(flash_io, NULL, "xtfpga.flash",
+            memory_region_init_alias(flash_io, OBJECT(machine), "xtfpga.flash",
                                      flash_mr, board->flash->boot_base, size);
             memory_region_add_subregion(system_memory,
                                         env->config->sysrom.location[0].addr,
                                         flash_io);
         } else {
-            xtensa_create_memory_regions(&env->config->sysrom, "xtensa.sysrom",
+            xtensa_create_memory_regions(mo, &env->config->sysrom, "xtensa.sysrom",
                                          system_memory);
         }
     }
include/hw/xtensa/mx_pic.h +1 -1
index cd316d86eb..01d5ea884e 100644
@@ -35,7 +35,7 @@ typedef struct XtensaMxPic XtensaMxPic;
 
 XtensaMxPic *xtensa_mx_pic_init(unsigned n_extint);
 void xtensa_mx_pic_reset(void *opaque);
-MemoryRegion *xtensa_mx_pic_register_cpu(XtensaMxPic *mx,
+MemoryRegion *xtensa_mx_pic_register_cpu(Object *owner, XtensaMxPic *mx,
                                          qemu_irq *irq,
                                          qemu_irq runstall);
 qemu_irq *xtensa_mx_pic_get_extints(XtensaMxPic *mx);
Signature · 1 line
2.47.1
#259 lore raw

RFC PATCH v2 102/137 hw/display: Give memory regions an explicit owner

In reply to Alexander Graf

Convert memory_region_init*() calls in device realize functions to pass OBJECT(dev) instead of NULL. All sites (cg3, g364fb, virtio-gpu-gl, vmware_vga) already have the DeviceState in scope.

omap_lcdc is handled separately together with the other OMAP peripherals.

No functional change intended.

RAMBlock idstrs are unchanged for all conversions except vmware_vga.c: the vmsvga.fifo RAM is now owned by a PCI device, so the convenience wrapper is replaced with the _nomigrate variant plus an explicit vmstate_register_ram_global() to preserve the historical bare idstr. All other display owners here are Machine or SysBus devices.

AI-used-for: code (refactoring)

---
 hw/display/cg3.c           |  2 +-
 hw/display/g364fb.c        |  2 +-
 hw/display/virtio-gpu-gl.c |  2 +-
 hw/display/vmware_vga.c    | 12 ++++++++++--
 4 files changed, 13 insertions(+), 5 deletions(-)
hw/display/cg3.c +1 -1
index f9dda1549d..507b0d8189 100644
@@ -304,7 +304,7 @@ static void cg3_realizefn(DeviceState *dev, Error **errp)
         }
     }
 
-    memory_region_init_ram(&s->vram_mem, NULL, "cg3.vram", s->vram_size,
+    memory_region_init_ram(&s->vram_mem, OBJECT(dev), "cg3.vram", s->vram_size,
                            &error_fatal);
     memory_region_set_log(&s->vram_mem, true, DIRTY_MEMORY_VGA);
     sysbus_init_mmio(sbd, &s->vram_mem);
hw/display/g364fb.c +1 -1
index af54f1f900..0bd993b826 100644
@@ -482,7 +482,7 @@ static void g364fb_init(DeviceState *dev, G364State *s)
 
     memory_region_init_io(&s->mem_ctrl, OBJECT(dev), &g364fb_ctrl_ops, s,
                           "ctrl", 0x180000);
-    memory_region_init_ram(&s->mem_vram, NULL, "g364fb.vram", s->vram_size,
+    memory_region_init_ram(&s->mem_vram, OBJECT(dev), "g364fb.vram", s->vram_size,
                            &error_fatal);
     memory_region_set_log(&s->mem_vram, true, DIRTY_MEMORY_VGA);
 }
hw/display/virtio-gpu-gl.c +1 -1
index 2b7a41c466..b6f183123d 100644
@@ -153,7 +153,7 @@ static void virtio_gpu_gl_device_realize(DeviceState *qdev, Error **errp)
         }
 
         gl->hostmem_mmap = map;
-        memory_region_init_ram_ptr(&gl->hostmem_background, NULL,
+        memory_region_init_ram_ptr(&gl->hostmem_background, OBJECT(qdev),
                                    "hostmem-background", b->conf.hostmem,
                                    gl->hostmem_mmap);
         memory_region_add_subregion(&b->hostmem, 0, &gl->hostmem_background);
hw/display/vmware_vga.c +10 -2
index f6f9edfd1d..571c3184c2 100644
@@ -1257,8 +1257,16 @@ static void vmsvga_init(DeviceState *dev, struct vmsvga_state_s *s,
     s->vga.con = qemu_graphic_console_create(dev, 0, &vmsvga_ops, s);
 
     s->fifo_size = SVGA_FIFO_SIZE;
-    memory_region_init_ram(&s->fifo_ram, NULL, "vmsvga.fifo", s->fifo_size,
-                           &error_fatal);
+    /*
+     * The fifo RAM must keep its historical bare RAMBlock idstr
+     * ("vmsvga.fifo") for cross-version migration.  Use _nomigrate + a
+     * global vmstate registration so the QOM owner is the PCI device but
+     * the migration idstr is not prefixed with the PCI dev-path.
+     */
+    memory_region_init_ram_flags_nomigrate(&s->fifo_ram, OBJECT(dev),
+                                           "vmsvga.fifo", s->fifo_size, 0,
+                                           &error_fatal);
+    vmstate_register_ram_global(&s->fifo_ram);
     s->fifo_ptr = memory_region_get_ram_ptr(&s->fifo_ram);
 
     vga_common_init(&s->vga, OBJECT(dev), &error_fatal);
Signature · 1 line
2.47.1
#260 lore raw

RFC PATCH v2 103/137 hw/arm/omap: Give lcdc and dma memory regions an explicit owner

In reply to Alexander Graf

Thread Object *owner as the first argument through omap_lcdc_init() and omap_dma_init(), matching the earlier conversion of omap1.c sub-block helpers. omap310_mpu_init() passes its parent through.

No functional change intended.

AI-used-for: code (refactoring)

---
 hw/arm/omap1.c         | 4 ++--
 hw/display/omap_lcdc.c | 5 +++--
 hw/dma/omap_dma.c      | 4 ++--
 include/hw/arm/omap.h  | 5 +++--
 4 files changed, 10 insertions(+), 8 deletions(-)
hw/arm/omap1.c +2 -2
index be6af35e26..474a3902fe 100644
@@ -3800,7 +3800,7 @@ struct omap_mpu_state_s *omap310_mpu_init(Object *parent, MemoryRegion *dram,
         dma_irqs[i] = qdev_get_gpio_in(s->ih[omap1_dma_irq_map[i].ih],
                                        omap1_dma_irq_map[i].intr);
     }
-    s->dma = omap_dma_init(0xfffed800, dma_irqs, system_memory,
+    s->dma = omap_dma_init(parent, 0xfffed800, dma_irqs, system_memory,
                            qdev_get_gpio_in(s->ih[0], OMAP_INT_DMA_LCD),
                            s, omap_findclk(s, "dma_ck"));
 
@@ -3835,7 +3835,7 @@ struct omap_mpu_state_s *omap310_mpu_init(Object *parent, MemoryRegion *dram,
                     qdev_get_gpio_in(s->ih[1], OMAP_INT_OS_TIMER),
                     omap_findclk(s, "clk32-kHz"));
 
-    s->lcd = omap_lcdc_init(system_memory, 0xfffec000,
+    s->lcd = omap_lcdc_init(parent, system_memory, 0xfffec000,
                             qdev_get_gpio_in(s->ih[0], OMAP_INT_LCD_CTRL),
                             omap_dma_get_lcdch(s->dma),
                             omap_findclk(s, "lcd_ck"));
hw/display/omap_lcdc.c +3 -2
index b88ea5f2f1..3f6066e3a8 100644
@@ -489,7 +489,8 @@ static const GraphicHwOps omap_ops = {
     .gfx_update  = omap_update_display,
 };
 
-struct omap_lcd_panel_s *omap_lcdc_init(MemoryRegion *sysmem,
+struct omap_lcd_panel_s *omap_lcdc_init(Object *owner,
+                                        MemoryRegion *sysmem,
                                         hwaddr base,
                                         qemu_irq irq,
                                         struct omap_dma_lcd_channel_s *dma,
@@ -502,7 +503,7 @@ struct omap_lcd_panel_s *omap_lcdc_init(MemoryRegion *sysmem,
     s->sysmem = sysmem;
     omap_lcdc_reset(s);
 
-    memory_region_init_io(&s->iomem, NULL, &omap_lcdc_ops, s, "omap.lcdc", 0x100);
+    memory_region_init_io(&s->iomem, owner, &omap_lcdc_ops, s, "omap.lcdc", 0x100);
     memory_region_add_subregion(sysmem, base, &s->iomem);
 
     s->con = qemu_graphic_console_create(NULL, 0, &omap_ops, s);
hw/dma/omap_dma.c +2 -2
index 77f1441498..b130ba2480 100644
@@ -1089,7 +1089,7 @@ static void omap_dma_clk_update(void *opaque, int line, int on)
             soc_dma_set_request(s->ch[i].dma, on);
 }
 
-struct soc_dma_s *omap_dma_init(hwaddr base, qemu_irq *irqs,
+struct soc_dma_s *omap_dma_init(Object *owner, hwaddr base, qemu_irq *irqs,
                                 MemoryRegion *sysmem,
                                 qemu_irq lcd_irq,
                                 struct omap_mpu_state_s *mpu, omap_clk clk)
@@ -1127,7 +1127,7 @@ struct soc_dma_s *omap_dma_init(hwaddr base, qemu_irq *irqs,
     omap_dma_reset(s->dma);
     omap_dma_clk_update(s, 0, 1);
 
-    memory_region_init_io(&s->iomem, NULL, &omap_dma_ops, s, "omap.dma", memsize);
+    memory_region_init_io(&s->iomem, owner, &omap_dma_ops, s, "omap.dma", memsize);
     memory_region_add_subregion(sysmem, base, &s->iomem);
 
     mpu->drq = s->dma->drq;
include/hw/arm/omap.h +3 -2
index e000dffe13..591abf752b 100644
@@ -173,7 +173,7 @@ void omap_gpio_set_clk(Omap1GpioState *gpio, omap_clk clk);
 
 /* omap_dma.c */
 struct soc_dma_s;
-struct soc_dma_s *omap_dma_init(hwaddr base, qemu_irq *irqs,
+struct soc_dma_s *omap_dma_init(Object *owner, hwaddr base, qemu_irq *irqs,
                                 MemoryRegion *sysmem,
                                 qemu_irq lcd_irq,
                                 struct omap_mpu_state_s *mpu, omap_clk clk);
@@ -296,7 +296,8 @@ void omap_mcbsp_i2s_attach(struct omap_mcbsp_s *s, I2SCodec *slave);
 /* omap_lcdc.c */
 struct omap_lcd_panel_s;
 void omap_lcdc_reset(struct omap_lcd_panel_s *s);
-struct omap_lcd_panel_s *omap_lcdc_init(MemoryRegion *sysmem,
+struct omap_lcd_panel_s *omap_lcdc_init(Object *owner,
+                                        MemoryRegion *sysmem,
                                         hwaddr base,
                                         qemu_irq irq,
                                         struct omap_dma_lcd_channel_s *dma,
Signature · 1 line
2.47.1
#261 lore raw

RFC PATCH v2 104/137 hw/char: Give parallel and htif memory regions an explicit owner

In reply to Alexander Graf

Thread Object *owner as the first argument through parallel_mm_init() and htif_mm_init(). All callers are inside board init functions and pass OBJECT(machine).

No functional change intended.

AI-used-for: code (refactoring)

---
 hw/char/parallel.c           | 5 +++--
 hw/char/riscv_htif.c         | 5 +++--
 hw/hppa/machine.c            | 5 +++--
 hw/mips/jazz.c               | 2 +-
 hw/riscv/spike.c             | 2 +-
 include/hw/char/parallel.h   | 3 ++-
 include/hw/char/riscv_htif.h | 3 ++-
 7 files changed, 15 insertions(+), 10 deletions(-)
hw/char/parallel.c +3 -2
index 07bbc9443f..39a1d77e9f 100644
@@ -585,7 +585,8 @@ static const MemoryRegionOps parallel_mm_ops = {
 };
 
 /* If fd is zero, it means that the parallel device uses the console */
-bool parallel_mm_init(MemoryRegion *address_space,
+bool parallel_mm_init(Object *owner,
+                      MemoryRegion *address_space,
                       hwaddr base, int it_shift, qemu_irq irq,
                       Chardev *chr)
 {
@@ -597,7 +598,7 @@ bool parallel_mm_init(MemoryRegion *address_space,
     s->it_shift = it_shift;
     qemu_register_reset(parallel_reset, s);
 
-    memory_region_init_io(&s->iomem, NULL, &parallel_mm_ops, s,
+    memory_region_init_io(&s->iomem, owner, &parallel_mm_ops, s,
                           "parallel", 8 << it_shift);
     memory_region_add_subregion(address_space, base, &s->iomem);
     return true;
hw/char/riscv_htif.c +3 -2
index 488f938d98..f9e39c31aa 100644
@@ -329,7 +329,8 @@ static const MemoryRegionOps htif_mm_ops = {
     },
 };
 
-HTIFState *htif_mm_init(MemoryRegion *address_space, Chardev *chr,
+HTIFState *htif_mm_init(Object *owner,
+                        MemoryRegion *address_space, Chardev *chr,
                         uint64_t nonelf_base, bool custom_base)
 {
     uint64_t base, size, tohost_offset, fromhost_offset;
@@ -359,7 +360,7 @@ HTIFState *htif_mm_init(MemoryRegion *address_space, Chardev *chr,
     qemu_chr_fe_set_handlers(&s->chr, htif_can_recv, htif_recv, htif_event,
         htif_be_change, s, NULL, true);
 
-    memory_region_init_io(&s->mmio, NULL, &htif_mm_ops, s,
+    memory_region_init_io(&s->mmio, owner, &htif_mm_ops, s,
                           TYPE_HTIF_UART, size);
     memory_region_add_subregion_overlap(address_space, base,
                                         &s->mmio, 1);
hw/hppa/machine.c +3 -2
index 233cf6318b..ea02b9e70e 100644
@@ -613,7 +613,8 @@ static void machine_HP_715_init(MachineState *machine)
         serial_hd(0), DEVICE_BIG_ENDIAN);
 
     /* Parallel port */
-    parallel_mm_init(addr_space, translate(NULL, LASI_HPA_715 + LASI_LPT + 0x800), 0,
+    parallel_mm_init(OBJECT(machine), addr_space,
+                     translate(NULL, LASI_HPA_715 + LASI_LPT + 0x800), 0,
                      qdev_get_gpio_in(lasi_dev, LASI_IRQ_LPT_HPA),
                      parallel_hds[0]);
 
@@ -706,7 +707,7 @@ static void machine_HP_B160L_init(MachineState *machine)
         serial_hd(1), DEVICE_BIG_ENDIAN);
 
     /* Parallel port */
-    parallel_mm_init(addr_space,
+    parallel_mm_init(OBJECT(machine), addr_space,
                      translate(NULL, LASI_HPA + LASI_LPT + 0x800), 0,
                      qdev_get_gpio_in(lasi_dev, LASI_IRQ_LPT_HPA),
                      parallel_hds[0]);
hw/mips/jazz.c +1 -1
index 8999efb352..ff18b28c86 100644
@@ -385,7 +385,7 @@ static void mips_jazz_init(MachineState *machine,
 
     /* Parallel port */
     if (parallel_hds[0])
-        parallel_mm_init(address_space, 0x80008000, 0,
+        parallel_mm_init(OBJECT(machine), address_space, 0x80008000, 0,
                          qdev_get_gpio_in(rc4030, 0), parallel_hds[0]);
 
     /* FIXME: missing Jazz sound at 0x8000c000, rc4030[2] */
hw/riscv/spike.c +1 -1
index 9f1a1b5898..cd9a2ee0df 100644
@@ -247,7 +247,7 @@ static void spike_board_init(MachineState *machine)
                               fdt_load_addr);
 
     /* initialize HTIF using symbols found in load_kernel */
-    htif_mm_init(system_memory, serial_hd(0), memmap[SPIKE_HTIF].base,
+    htif_mm_init(OBJECT(machine), system_memory, serial_hd(0), memmap[SPIKE_HTIF].base,
                  htif_custom_base);
 }
 
include/hw/char/parallel.h +2 -1
index 782cc12602..7e8b9c9012 100644
@@ -25,7 +25,8 @@ typedef struct ParallelState {
 
 void parallel_hds_isa_init(Object *parent, ISABus *bus, int n);
 
-bool parallel_mm_init(MemoryRegion *address_space,
+bool parallel_mm_init(Object *owner,
+                      MemoryRegion *address_space,
                       hwaddr base, int it_shift, qemu_irq irq,
                       Chardev *chr);
 
include/hw/char/riscv_htif.h +2 -1
index 9d61e60d0a..40516adc08 100644
@@ -48,7 +48,8 @@ void htif_symbol_callback(const char *st_name, int st_info, uint64_t st_value,
     uint64_t st_size);
 
 /* legacy pre qom */
-HTIFState *htif_mm_init(MemoryRegion *address_space, Chardev *chr,
+HTIFState *htif_mm_init(Object *owner,
+                        MemoryRegion *address_space, Chardev *chr,
                         uint64_t nonelf_base, bool custom_base);
 
 #endif
Signature · 1 line
2.47.1
#262 lore raw

RFC PATCH v2 105/137 hw/remote: Give memory regions an explicit owner

In reply to Alexander Graf

remote_machine_init() passes OBJECT(machine). remote_sysmem_reconfig() runs in the multi-process remote and creates system-memory subregions on behalf of the machine; use qdev_get_machine() as owner. dma_register() in the vfio-user server creates DMA windows for a VfuObject; use it as owner.

No functional change intended.

RAMBlock idstrs are unchanged: the owners added here are Machine or SysBus devices, and memory_region_register_ram() maps both to dev=NULL for qemu_ram_set_idstr().

AI-used-for: code (refactoring)

---
 hw/remote/machine.c       | 2 +-
 hw/remote/memory.c        | 3 ++-
 hw/remote/vfio-user-obj.c | 2 +-
 3 files changed, 4 insertions(+), 3 deletions(-)
hw/remote/machine.c +1 -1
index e8e9cf259f..09154fa122 100644
@@ -37,7 +37,7 @@ static void remote_machine_init(MachineState *machine)
     system_io = get_system_io();
 
     pci_memory = g_new(MemoryRegion, 1);
-    memory_region_init(pci_memory, NULL, "pci", UINT64_MAX);
+    memory_region_init(pci_memory, OBJECT(machine), "pci", UINT64_MAX);
 
     rem_host = REMOTE_PCIHOST(qdev_new(OBJECT(s), "remote-pcihost",
                                        TYPE_REMOTE_PCIHOST));
hw/remote/memory.c +2 -1
index 8195aa5fb8..3f8fe54bac 100644
@@ -12,6 +12,7 @@
 
 #include "hw/remote/memory.h"
 #include "qapi/error.h"
+#include "hw/core/qdev.h"
 
 static void remote_sysmem_reset(void)
 {
@@ -42,7 +43,7 @@ void remote_sysmem_reconfig(MPQemuMsg *msg, Error **errp)
     for (region = 0; region < msg->num_fds; region++, suffix++) {
         g_autofree char *name = g_strdup_printf("remote-mem-%u", suffix);
         subregion = g_new(MemoryRegion, 1);
-        memory_region_init_ram_from_fd(subregion, NULL,
+        memory_region_init_ram_from_fd(subregion, qdev_get_machine(),
                                        name, sysmem_info->sizes[region],
                                        RAM_SHARED, msg->fds[region],
                                        sysmem_info->offsets[region],
hw/remote/vfio-user-obj.c +1 -1
index 87fa7b6572..685d4c2baf 100644
@@ -324,7 +324,7 @@ static void dma_register(vfu_ctx_t *vfu_ctx, vfu_dma_info_t *info)
 
     subregion = g_new0(MemoryRegion, 1);
 
-    memory_region_init_ram_ptr(subregion, NULL, name,
+    memory_region_init_ram_ptr(subregion, OBJECT(o), name,
                                iov->iov_len, info->vaddr);
 
     dma_as = pci_device_iommu_address_space(o->pci_dev);
Signature · 1 line
2.47.1
#263 lore raw

RFC PATCH v2 106/137 system, backends: Give named memory regions an explicit owner

In reply to Alexander Graf

memory_map_init() creates the "system" and "io" root memory regions after qemu_create_machine() has instantiated current_machine, so qdev_get_machine() is available as owner.

The IGVM backend creates guest-memory regions on behalf of the confidential-guest machine it carries in ctx->machine_state; use that as owner.

subpage_init() and io_mem_init() pass name==NULL and thus never QOM-parent their MemoryRegion; leave owner NULL there.

No functional change intended.

AI-used-for: code (refactoring)

---
 backends/igvm.c  | 6 ++++--
 system/physmem.c | 4 ++--
 2 files changed, 6 insertions(+), 4 deletions(-)
backends/igvm.c +4 -2
index 80e87fe602..544a51b70e 100644
@@ -256,13 +256,15 @@ static void *qigvm_prepare_memory(QIgvm *ctx, uint64_t addr, uint64_t size,
         igvm_pages = g_new0(MemoryRegion, 1);
         if (ctx->machine_state->cgs &&
             ctx->machine_state->cgs->require_guest_memfd) {
-            if (!memory_region_init_ram_guest_memfd(igvm_pages, NULL,
+            if (!memory_region_init_ram_guest_memfd(igvm_pages,
+                                                     OBJECT(ctx->machine_state),
                                                     region_name, size, errp)) {
                 g_free(igvm_pages);
                 return NULL;
             }
         } else {
-            if (!memory_region_init_ram(igvm_pages, NULL, region_name, size,
+            if (!memory_region_init_ram(igvm_pages, OBJECT(ctx->machine_state),
+                                        region_name, size,
                                         errp)) {
                 g_free(igvm_pages);
                 return NULL;
system/physmem.c +2 -2
index c21ea92915..8466885994 100644
@@ -3100,11 +3100,11 @@ static void memory_map_init(void)
 {
     system_memory = g_malloc(sizeof(*system_memory));
 
-    memory_region_init(system_memory, NULL, "system", UINT64_MAX);
+    memory_region_init(system_memory, qdev_get_machine(), "system", UINT64_MAX);
     address_space_init(&address_space_memory, system_memory, "memory");
 
     system_io = g_malloc(sizeof(*system_io));
-    memory_region_init_io(system_io, NULL, &unassigned_io_ops, NULL, "io",
+    memory_region_init_io(system_io, qdev_get_machine(), &unassigned_io_ops, NULL, "io",
                           65536);
     address_space_init(&address_space_io, system_io, "I/O");
 }
Signature · 1 line
2.47.1
#264 lore raw

RFC PATCH v2 107/137 hw/ide: Let ide_init_ioport() take an explicit owner

In reply to Alexander Graf

hw/ide/piix.c calls ide_init_ioport() with a NULL ISADevice because the PIIX IDE function is a PCI device, not an ISA one. That NULL propagates to isa_register_portio_list() and from there to portio_list_init() as owner==NULL, which the following commit turns into a hard error.

Change ide_init_ioport() to take an Object *owner directly. When the owner is an ISADevice, keep the existing isa_register_portio_list() path so isa_init_ioport() still records the base I/O port for firmware paths. When it is not (the PIIX case), register the port lists with the given owner directly.

AI-used-for: code (refactoring)

---
 hw/ide/ide-internal.h |  2 +-
 hw/ide/ioport.c       | 37 ++++++++++++++++++++++++++-----------
 hw/ide/isa.c          |  2 +-
 hw/ide/piix.c         |  2 +-
 4 files changed, 29 insertions(+), 14 deletions(-)
hw/ide/ide-internal.h +1 -1
index 281d07c9d5..3f48335cdf 100644
@@ -419,7 +419,7 @@ uint32_t ide_data_readl(void *opaque, uint32_t addr);
 int ide_init_drive(IDEState *s, IDEDevice *dev, IDEDriveKind kind, Error **errp);
 void ide_exit(IDEState *s);
 void ide_bus_init_output_irq(IDEBus *bus, qemu_irq irq_out);
-int ide_init_ioport(IDEBus *bus, ISADevice *isa, int iobase, int iobase2);
+int ide_init_ioport(IDEBus *bus, Object *owner, int iobase, int iobase2);
 void ide_bus_set_irq(IDEBus *bus);
 void ide_bus_register_restart_cb(IDEBus *bus);
 
hw/ide/ioport.c +26 -11
index a2f457f0bd..afafe6844c 100644
@@ -1,5 +1,5 @@
 /*
- * QEMU IDE disk and CD/DVD-ROM Emulator
+ * QEMU IDE Emulation: PIO ioport registration.
  *
  * Copyright (c) 2003 Fabrice Bellard
  * Copyright (c) 2006 Openedhand Ltd.
@@ -28,19 +28,34 @@
 #include "ide-internal.h"
 #include "trace.h"
 
-int ide_init_ioport(IDEBus *bus, ISADevice *dev, int iobase, int iobase2)
+int ide_init_ioport(IDEBus *bus, Object *owner, int iobase, int iobase2)
 {
+    ISADevice *isa = ISA_DEVICE(object_dynamic_cast(owner, TYPE_ISA_DEVICE));
     int ret;
 
-    /* ??? Assume only ISA and PCI configurations, and that the PCI-ISA
-       bridge has been setup properly to always register with ISA.  */
-    ret = isa_register_portio_list(dev, &bus->portio_list,
-                                   iobase, ide_portio_list, bus, "ide");
-
-    if (ret == 0 && iobase2) {
-        ret = isa_register_portio_list(dev, &bus->portio2_list,
-                                       iobase2, ide_portio2_list, bus, "ide");
+    if (isa) {
+        ret = isa_register_portio_list(isa, &bus->portio_list,
+                                       iobase, ide_portio_list, bus, "ide");
+        if (ret == 0 && iobase2) {
+            ret = isa_register_portio_list(isa, &bus->portio2_list,
+                                           iobase2, ide_portio2_list, bus,
+                                           "ide");
+        }
+        return ret;
     }
 
-    return ret;
+    /* PIIX3/4: no ISADevice, but ISA I/O space is set up by the PCI-ISA */
+    /* bridge; register the port lists directly with the given owner.   */
+    if (!isa_address_space_io(NULL)) {
+        return -ENODEV;
+    }
+    portio_list_init(&bus->portio_list, owner, ide_portio_list, bus, "ide");
+    portio_list_add(&bus->portio_list, isa_address_space_io(NULL), iobase);
+    if (iobase2) {
+        portio_list_init(&bus->portio2_list, owner,
+                         ide_portio2_list, bus, "ide");
+        portio_list_add(&bus->portio2_list,
+                        isa_address_space_io(NULL), iobase2);
+    }
+    return 0;
 }
hw/ide/isa.c +1 -1
index 37457be035..7949625e00 100644
@@ -71,7 +71,7 @@ static void isa_ide_realizefn(DeviceState *dev, Error **errp)
     ISAIDEState *s = ISA_IDE(dev);
 
     ide_bus_init(&s->bus, sizeof(s->bus), dev, 0, 2);
-    ide_init_ioport(&s->bus, isadev, s->iobase, s->iobase2);
+    ide_init_ioport(&s->bus, OBJECT(isadev), s->iobase, s->iobase2);
     ide_bus_init_output_irq(&s->bus, isa_get_irq(isadev, s->irqnum));
     vmstate_register_any(VMSTATE_IF(dev), &vmstate_ide_isa, s);
     ide_bus_register_restart_cb(&s->bus);
hw/ide/piix.c +1 -1
index a0f2709c69..5c5b91fa52 100644
@@ -134,7 +134,7 @@ static bool pci_piix_init_bus(PCIIDEState *d, unsigned i, Error **errp)
     int ret;
 
     ide_bus_init(&d->bus[i], sizeof(d->bus[i]), DEVICE(d), i, 2);
-    ret = ide_init_ioport(&d->bus[i], NULL, port_info[i].iobase,
+    ret = ide_init_ioport(&d->bus[i], OBJECT(d), port_info[i].iobase,
                           port_info[i].iobase2);
     if (ret) {
         error_setg_errno(errp, -ret, "Failed to realize %s port %u",
Signature · 1 line
2.47.1
#265 lore raw

RFC PATCH v2 108/137 memory: Require an owner for named memory regions

In reply to Alexander Graf

Now that every named memory region in the tree passes an explicit owner, replace the /machine/unattached fallback in memory_region_do_init() and portio_list_add_1() with an assertion.

Anonymous (name==NULL) regions such as subpages and io_mem_unassigned are never QOM-parented and continue to accept a NULL owner.

AI-used-for: code (refactoring)

---
 system/ioport.c | 7 ++-----
 system/memory.c | 7 +++----
 2 files changed, 5 insertions(+), 9 deletions(-)
system/ioport.c +2 -5
index 0a1b80f299..0415b3cd60 100644
@@ -248,11 +248,8 @@ static void portio_list_add_1(PortioList *piolist,
     /* Reparent the MemoryRegion to the piolist owner */
     object_ref(&mrpio->mr);
     object_unparent(OBJECT(&mrpio->mr));
-    if (!piolist->owner) {
-        owner = machine_get_container("unattached");
-    } else {
-        owner = piolist->owner;
-    }
+    g_assert(piolist->owner);
+    owner = piolist->owner;
     name = g_strdup_printf("%s[*]", piolist->name);
     object_property_add_child(owner, name, OBJECT(&mrpio->mr));
     g_free(name);
system/memory.c +3 -4
index 838be57b4d..d1ac7ffa04 100644
@@ -1230,14 +1230,13 @@ static void memory_region_do_init(MemoryRegion *mr,
     mr->dev = (DeviceState *) object_dynamic_cast(mr->owner, TYPE_DEVICE);
     mr->ram_block = NULL;
 
+    /* A named MemoryRegion is a QOM child of @owner */
+    g_assert(!name || owner);
+
     if (name) {
         char *escaped_name = memory_region_escape_name(name);
         char *name_array = g_strdup_printf("%s[*]", escaped_name);
 
-        if (!owner) {
-            owner = machine_get_container("unattached");
-        }
-
         object_property_add_child(owner, name_array, OBJECT(mr));
         object_unref(OBJECT(mr));
         g_free(name_array);
Signature · 1 line
2.47.1