[RFC PATCH v2 038/137] hw/net: 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/net 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/net/lan9118.c:1342 | qdev_new | parent | "eth" | thread Object *parent as first arg; 5 board-init callers pass OBJECT(machine)
hw/net/smc91c111.c:957 | qdev_new | parent | "eth" | thread Object *parent as first arg; 3 board-init callers pass OBJECT(machine)
hw/net/spapr_llan.c:374 | qdev_new | parent | "vlan[*]" | thread Object *parent as first arg; single caller in hw/ppc/spapr.c board-init loop passes OBJECT(spapr)
hw/net/xen_nic.c:622 | qdev_new | ORPHAN-JUSTIFIED | - | XenBackendOps.create hotplug callback driven by xenstore watch; dynamic device with no board owner (same pattern as xen-block/xen_console)

Link: https://lore.kernel.org/qemu-devel/[email protected]/
AI-used-for: code (refactoring)
Signed-off-by: Alexander Graf <[email protected]>
---
 hw/arm/integratorcp.c      | 2 +-
 hw/arm/kzm.c               | 2 +-
 hw/arm/mps2.c              | 2 +-
 hw/arm/mps3r.c             | 2 +-
 hw/arm/realview.c          | 4 ++--
 hw/arm/versatilepb.c       | 2 +-
 hw/arm/vexpress.c          | 2 +-
 hw/net/lan9118.c           | 6 +++---
 hw/net/smc91c111.c         | 6 +++---
 hw/net/spapr_llan.c        | 6 +++---
 hw/ppc/spapr.c             | 2 +-
 include/hw/net/lan9118.h   | 2 +-
 include/hw/net/smc91c111.h | 2 +-
 include/hw/ppc/spapr_vio.h | 2 +-
 14 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/hw/arm/integratorcp.c b/hw/arm/integratorcp.c
index 3df488921a..163012a7bf 100644
--- a/hw/arm/integratorcp.c
+++ b/hw/arm/integratorcp.c
@@ -670,7 +670,7 @@ static void integratorcp_init(MachineState *machine)
     sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, pic[25]);
 
     if (qemu_find_nic_info("smc91c111", true, NULL)) {
-        smc91c111_init(0xc8000000, pic[27]);
+        smc91c111_init(OBJECT(machine), 0xc8000000, pic[27]);
     }
 
     dev = qdev_new_orphan("pl110");
diff --git a/hw/arm/kzm.c b/hw/arm/kzm.c
index 168ecf35d0..de9919c8cb 100644
--- a/hw/arm/kzm.c
+++ b/hw/arm/kzm.c
@@ -115,7 +115,7 @@ static void kzm_init(MachineState *machine)
     }
 
     if (qemu_find_nic_info("lan9118", true, NULL)) {
-        lan9118_init(KZM_LAN9118_ADDR,
+        lan9118_init(OBJECT(machine), KZM_LAN9118_ADDR,
                      qdev_get_gpio_in(DEVICE(&s->soc.avic), 52));
     }
 
diff --git a/hw/arm/mps2.c b/hw/arm/mps2.c
index 5a0384a412..e646c7c71e 100644
--- a/hw/arm/mps2.c
+++ b/hw/arm/mps2.c
@@ -461,7 +461,7 @@ static void mps2_common_init(MachineState *machine)
     /* In hardware this is a LAN9220; the LAN9118 is software compatible
      * except that it doesn't support the checksum-offload feature.
      */
-    lan9118_init(mmc->ethernet_base,
+    lan9118_init(OBJECT(machine), mmc->ethernet_base,
                  qdev_get_gpio_in(armv7m,
                                   mmc->fpga_type == FPGA_AN511 ? 47 : 13));
 
diff --git a/hw/arm/mps3r.c b/hw/arm/mps3r.c
index caad820d3b..8e249c9b9d 100644
--- a/hw/arm/mps3r.c
+++ b/hw/arm/mps3r.c
@@ -549,7 +549,7 @@ static void mps3r_common_init(MachineState *machine)
      * In hardware this is a LAN9220; the LAN9118 is software compatible
      * except that it doesn't support the checksum-offload feature.
      */
-    lan9118_init(0xe0300000,
+    lan9118_init(OBJECT(machine), 0xe0300000,
                  qdev_get_gpio_in(gicdev, 18));
 
     create_unimplemented_device("usb", 0xe0301000, 0x1000);
diff --git a/hw/arm/realview.c b/hw/arm/realview.c
index f37ddf8073..f51730c487 100644
--- a/hw/arm/realview.c
+++ b/hw/arm/realview.c
@@ -309,9 +309,9 @@ static void realview_init(MachineState *machine,
 
     if (qemu_find_nic_info(is_pb ? "lan9118" : "smc91c111", true, NULL)) {
         if (is_pb) {
-            lan9118_init(0x4e000000, pic[28]);
+            lan9118_init(OBJECT(machine), 0x4e000000, pic[28]);
         } else {
-            smc91c111_init(0x4e000000, pic[28]);
+            smc91c111_init(OBJECT(machine), 0x4e000000, pic[28]);
         }
     }
 
diff --git a/hw/arm/versatilepb.c b/hw/arm/versatilepb.c
index dcc7b7debd..5de99cb854 100644
--- a/hw/arm/versatilepb.c
+++ b/hw/arm/versatilepb.c
@@ -265,7 +265,7 @@ static void versatile_init(MachineState *machine, int board_id)
     pci_bus = (PCIBus *)qdev_get_child_bus(dev, "pci");
 
     if (qemu_find_nic_info("smc91c111", true, NULL)) {
-        smc91c111_init(0x10010000, sic[25]);
+        smc91c111_init(OBJECT(machine), 0x10010000, sic[25]);
     }
     pci_init_nic_devices(pci_bus, "rtl8139");
 
diff --git a/hw/arm/vexpress.c b/hw/arm/vexpress.c
index ffd3c52d4f..5cbb2c44cb 100644
--- a/hw/arm/vexpress.c
+++ b/hw/arm/vexpress.c
@@ -694,7 +694,7 @@ static void vexpress_common_init(MachineState *machine)
 
     /* 0x4e000000 LAN9118 Ethernet */
     if (qemu_find_nic_info("lan9118", true, NULL)) {
-        lan9118_init(map[VE_ETHERNET], pic[15]);
+        lan9118_init(OBJECT(machine), map[VE_ETHERNET], pic[15]);
     }
 
     /* VE_USB: not modelled */
diff --git a/hw/net/lan9118.c b/hw/net/lan9118.c
index 87213c0d8d..91c3533702 100644
--- a/hw/net/lan9118.c
+++ b/hw/net/lan9118.c
@@ -1334,15 +1334,15 @@ static void lan9118_register_types(void)
 
 /* Legacy helper function.  Should go away when machine config files are
    implemented.  */
-void lan9118_init(uint32_t base, qemu_irq irq)
+void lan9118_init(Object *parent, uint32_t base, qemu_irq irq)
 {
     DeviceState *dev;
     SysBusDevice *s;
 
-    dev = qdev_new_orphan(TYPE_LAN9118);
+    dev = qdev_new(parent, "eth", TYPE_LAN9118);
     qemu_configure_nic_device(dev, true, NULL);
     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);
 }
diff --git a/hw/net/smc91c111.c b/hw/net/smc91c111.c
index 6186d88717..85f3d4d34a 100644
--- a/hw/net/smc91c111.c
+++ b/hw/net/smc91c111.c
@@ -949,15 +949,15 @@ static void smc91c111_register_types(void)
 
 /* Legacy helper function.  Should go away when machine config files are
    implemented.  */
-void smc91c111_init(uint32_t base, qemu_irq irq)
+void smc91c111_init(Object *parent, uint32_t base, qemu_irq irq)
 {
     DeviceState *dev;
     SysBusDevice *s;
 
-    dev = qdev_new_orphan(TYPE_SMC91C111);
+    dev = qdev_new(parent, "eth", TYPE_SMC91C111);
     qemu_configure_nic_device(dev, true, NULL);
     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);
 }
diff --git a/hw/net/spapr_llan.c b/hw/net/spapr_llan.c
index f10ea64798..1d5637f294 100644
--- a/hw/net/spapr_llan.c
+++ b/hw/net/spapr_llan.c
@@ -367,15 +367,15 @@ static void spapr_vlan_instance_finalize(Object *obj)
     }
 }
 
-void spapr_vlan_create(SpaprVioBus *bus, NICInfo *nd)
+void spapr_vlan_create(Object *parent, SpaprVioBus *bus, NICInfo *nd)
 {
     DeviceState *dev;
 
-    dev = qdev_new_orphan("spapr-vlan");
+    dev = qdev_new(parent, "vlan[*]", "spapr-vlan");
 
     qdev_set_nic_properties(dev, nd);
 
-    qdev_realize_and_unref(dev, &bus->bus, &error_fatal);
+    qdev_realize(dev, &bus->bus, &error_fatal);
 }
 
 static int spapr_vlan_devnode(SpaprVioDevice *dev, void *fdt, int node_off)
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 91f9d873b8..b81db9e8f3 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -3056,7 +3056,7 @@ static void spapr_machine_init(MachineState *machine)
     phb = spapr_create_default_phb();
 
     while ((nd = qemu_find_nic_info("spapr-vlan", true, "ibmveth"))) {
-        spapr_vlan_create(spapr->vio_bus, nd);
+        spapr_vlan_create(OBJECT(spapr), spapr->vio_bus, nd);
     }
 
     pci_init_nic_devices(phb->bus, NULL);
diff --git a/include/hw/net/lan9118.h b/include/hw/net/lan9118.h
index 4bf9da7a63..b199f1912f 100644
--- a/include/hw/net/lan9118.h
+++ b/include/hw/net/lan9118.h
@@ -15,6 +15,6 @@
 
 #define TYPE_LAN9118 "lan9118"
 
-void lan9118_init(uint32_t, qemu_irq);
+void lan9118_init(Object *parent, uint32_t, qemu_irq);
 
 #endif
diff --git a/include/hw/net/smc91c111.h b/include/hw/net/smc91c111.h
index dba32a233f..788f12678e 100644
--- a/include/hw/net/smc91c111.h
+++ b/include/hw/net/smc91c111.h
@@ -13,6 +13,6 @@
 
 #include "net/net.h"
 
-void smc91c111_init(uint32_t, qemu_irq);
+void smc91c111_init(Object *parent, uint32_t, qemu_irq);
 
 #endif
diff --git a/include/hw/ppc/spapr_vio.h b/include/hw/ppc/spapr_vio.h
index 72baef6919..fcb29aebff 100644
--- a/include/hw/ppc/spapr_vio.h
+++ b/include/hw/ppc/spapr_vio.h
@@ -138,7 +138,7 @@ int spapr_vio_send_crq(SpaprVioDevice *dev, uint8_t *crq);
 SpaprVioDevice *vty_lookup(SpaprMachineState *spapr, target_ulong reg);
 void vty_putchars(SpaprVioDevice *sdev, uint8_t *buf, int len);
 void spapr_vty_create(SpaprVioBus *bus, Chardev *chardev);
-void spapr_vlan_create(SpaprVioBus *bus, NICInfo *nd);
+void spapr_vlan_create(Object *parent, SpaprVioBus *bus, NICInfo *nd);
 void spapr_vscsi_create(Object *parent, SpaprVioBus *bus);
 
 SpaprVioDevice *spapr_vty_get_default(SpaprVioBus *bus);
-- 
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.