[RFC PATCH v2 046/137] hw/rtc: Give onboard devices a QOM parent

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

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

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

hw/rtc/mc146818rtc.c:933 | isa_new | parent | "rtc" | helper called from board init; thread Object *parent through mc146818_rtc_init() and its 4 callers (microvm, pnv, jazz, dp264)
hw/rtc/sun4v-rtc.c:60 | qdev_new | parent | "rtc" | helper called from niagara board init; thread Object *parent through sun4v_rtc_init()

Link: https://lore.kernel.org/qemu-devel/[email protected]/
AI-used-for: code (refactoring)
Signed-off-by: Alexander Graf <[email protected]>
---
 hw/alpha/dp264.c             | 2 +-
 hw/i386/microvm.c            | 3 ++-
 hw/mips/jazz.c               | 2 +-
 hw/ppc/pnv.c                 | 2 +-
 hw/rtc/mc146818rtc.c         | 6 +++---
 hw/rtc/sun4v-rtc.c           | 6 +++---
 hw/sparc64/niagara.c         | 2 +-
 include/hw/rtc/mc146818rtc.h | 2 +-
 include/hw/rtc/sun4v-rtc.h   | 2 +-
 9 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/hw/alpha/dp264.c b/hw/alpha/dp264.c
index 9cd448cff1..40dee88f2d 100644
--- a/hw/alpha/dp264.c
+++ b/hw/alpha/dp264.c
@@ -119,7 +119,7 @@ static void clipper_init(MachineState *machine)
     qdev_connect_gpio_out(i82378_dev, 0, isa_irq);
 
     /* Since we have an SRM-compatible PALcode, use the SRM epoch.  */
-    mc146818_rtc_init(isa_bus, 1900, rtc_irq);
+    mc146818_rtc_init(mo, isa_bus, 1900, rtc_irq);
 
     /* VGA setup.  Don't bother loading the bios.  */
     pci_vga_init(pci_bus);
diff --git a/hw/i386/microvm.c b/hw/i386/microvm.c
index 16bd885541..d13036bd73 100644
--- a/hw/i386/microvm.c
+++ b/hw/i386/microvm.c
@@ -268,7 +268,8 @@ static void microvm_devices_init(MicrovmMachineState *mms)
 
     if (mms->rtc == ON_OFF_AUTO_ON ||
         (mms->rtc == ON_OFF_AUTO_AUTO && !kvm_enabled())) {
-        microvm_set_rtc(mms, mc146818_rtc_init(isa_bus, 2000, NULL));
+        microvm_set_rtc(mms, mc146818_rtc_init(OBJECT(mms), isa_bus,
+                                               2000, NULL));
     }
 
     if (mms->isa_serial) {
diff --git a/hw/mips/jazz.c b/hw/mips/jazz.c
index 62f2350d36..938aaf3fe1 100644
--- a/hw/mips/jazz.c
+++ b/hw/mips/jazz.c
@@ -354,7 +354,7 @@ static void mips_jazz_init(MachineState *machine,
     fdctrl_init_sysbus(qdev_get_gpio_in(rc4030, 1), 0x80003000, fds);
 
     /* Real time clock */
-    mc146818_rtc_init(isa_bus, 1980, NULL);
+    mc146818_rtc_init(OBJECT(machine), isa_bus, 1980, NULL);
     memory_region_init_io(rtc, NULL, &rtc_ops, NULL, "rtc", 0x1000);
     memory_region_add_subregion(address_space, 0x80004000, rtc);
 
diff --git a/hw/ppc/pnv.c b/hw/ppc/pnv.c
index 0a22d854d7..1eb3c09672 100644
--- a/hw/ppc/pnv.c
+++ b/hw/ppc/pnv.c
@@ -1314,7 +1314,7 @@ static void pnv_init(MachineState *machine)
     serial_hds_isa_init(pnv->isa_bus, 0, MAX_ISA_SERIAL_PORTS);
 
     /* Create an RTC ISA device too */
-    mc146818_rtc_init(pnv->isa_bus, 2000, NULL);
+    mc146818_rtc_init(OBJECT(machine), pnv->isa_bus, 2000, NULL);
 
     /*
      * Create the machine BMC simulator and the IPMI BT device for
diff --git a/hw/rtc/mc146818rtc.c b/hw/rtc/mc146818rtc.c
index b9e5ec6ff6..a4d6d59502 100644
--- a/hw/rtc/mc146818rtc.c
+++ b/hw/rtc/mc146818rtc.c
@@ -923,18 +923,18 @@ static void rtc_realizefn(DeviceState *dev, Error **errp)
     qdev_init_gpio_out(dev, &s->irq, 1);
 }
 
-MC146818RtcState *mc146818_rtc_init(ISABus *bus, int base_year,
+MC146818RtcState *mc146818_rtc_init(Object *parent, ISABus *bus, int base_year,
                                     qemu_irq intercept_irq)
 {
     DeviceState *dev;
     ISADevice *isadev;
     MC146818RtcState *s;
 
-    isadev = isa_new_orphan(TYPE_MC146818_RTC);
+    isadev = isa_new(parent, "rtc[*]", TYPE_MC146818_RTC);
     dev = DEVICE(isadev);
     s = MC146818_RTC(isadev);
     qdev_prop_set_int32(dev, "base_year", base_year);
-    isa_realize_and_unref(isadev, bus, &error_fatal);
+    qdev_realize(dev, BUS(bus), &error_fatal);
     if (intercept_irq) {
         qdev_connect_gpio_out(dev, 0, intercept_irq);
     } else {
diff --git a/hw/rtc/sun4v-rtc.c b/hw/rtc/sun4v-rtc.c
index 257f70885d..ee07b7a979 100644
--- a/hw/rtc/sun4v-rtc.c
+++ b/hw/rtc/sun4v-rtc.c
@@ -52,15 +52,15 @@ static const MemoryRegionOps sun4v_rtc_ops = {
     .endianness = DEVICE_BIG_ENDIAN,
 };
 
-void sun4v_rtc_init(hwaddr addr)
+void sun4v_rtc_init(Object *parent, hwaddr addr)
 {
     DeviceState *dev;
     SysBusDevice *s;
 
-    dev = qdev_new_orphan(TYPE_SUN4V_RTC);
+    dev = qdev_new(parent, "rtc", TYPE_SUN4V_RTC);
     s = SYS_BUS_DEVICE(dev);
 
-    sysbus_realize_and_unref(s, &error_fatal);
+    sysbus_realize(s, &error_fatal);
 
     sysbus_mmio_map(s, 0, addr);
 }
diff --git a/hw/sparc64/niagara.c b/hw/sparc64/niagara.c
index 1211ecb82d..d47d62dac7 100644
--- a/hw/sparc64/niagara.c
+++ b/hw/sparc64/niagara.c
@@ -154,7 +154,7 @@ static void niagara_init(MachineState *machine)
     serial_mm_init(sysmem, NIAGARA_UART_BASE, 0, NULL,
                    115200, serial_hd(0), DEVICE_BIG_ENDIAN);
     create_unimplemented_device("sun4v-iob", NIAGARA_IOBBASE, NIAGARA_IOBSIZE);
-    sun4v_rtc_init(NIAGARA_RTC_BASE);
+    sun4v_rtc_init(OBJECT(machine), NIAGARA_RTC_BASE);
 }
 
 static void niagara_class_init(ObjectClass *oc, const void *data)
diff --git a/include/hw/rtc/mc146818rtc.h b/include/hw/rtc/mc146818rtc.h
index 64893be151..1bdd63cf5c 100644
--- a/include/hw/rtc/mc146818rtc.h
+++ b/include/hw/rtc/mc146818rtc.h
@@ -51,7 +51,7 @@ struct MC146818RtcState {
 
 #define RTC_ISA_IRQ 8
 
-MC146818RtcState *mc146818_rtc_init(ISABus *bus, int base_year,
+MC146818RtcState *mc146818_rtc_init(Object *parent, ISABus *bus, int base_year,
                                     qemu_irq intercept_irq);
 void mc146818rtc_set_cmos_data(MC146818RtcState *s, int addr, int val);
 int mc146818rtc_get_cmos_data(MC146818RtcState *s, int addr);
diff --git a/include/hw/rtc/sun4v-rtc.h b/include/hw/rtc/sun4v-rtc.h
index 26a9eb6196..9152a0082f 100644
--- a/include/hw/rtc/sun4v-rtc.h
+++ b/include/hw/rtc/sun4v-rtc.h
@@ -14,6 +14,6 @@
 
 #include "exec/hwaddr.h"
 
-void sun4v_rtc_init(hwaddr addr);
+void sun4v_rtc_init(Object *parent, hwaddr addr);
 
 #endif
-- 
2.47.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.