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

Alexander Graf <[email protected]>
Newsgroups org.nongnu.qemu-riscv,org.nongnu.qemu-arm,org.nongnu.qemu-devel
Message-ID <[email protected]>
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)
Signed-off-by: Alexander Graf <[email protected]>
---
 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(-)

diff --git a/hw/i386/microvm.c b/hw/i386/microvm.c
index d701672c1a..8c61106516 100644
--- a/hw/i386/microvm.c
+++ b/hw/i386/microvm.c
@@ -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);
         }
     }
 
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index a00d53b582..e505391985 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -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 */
diff --git a/hw/isa/i82378.c b/hw/isa/i82378.c
index 1c0a6ad779..995d1eaa53 100644
--- a/hw/isa/i82378.c
+++ b/hw/isa/i82378.c
@@ -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);
diff --git a/hw/isa/piix.c b/hw/isa/piix.c
index 6b2946d82c..d96bc3a873 100644
--- a/hw/isa/piix.c
+++ b/hw/isa/piix.c
@@ -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);
diff --git a/hw/isa/vt82c686.c b/hw/isa/vt82c686.c
index de9006bd95..2337c3115b 100644
--- a/hw/isa/vt82c686.c
+++ b/hw/isa/vt82c686.c
@@ -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 */
diff --git a/hw/mips/jazz.c b/hw/mips/jazz.c
index 208e59fbeb..23d717d96a 100644
--- a/hw/mips/jazz.c
+++ b/hw/mips/jazz.c
@@ -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);
diff --git a/include/hw/i386/vmport.h b/include/hw/i386/vmport.h
index 22dd3645d2..02e422029d 100644
--- a/include/hw/i386/vmport.h
+++ b/include/hw/i386/vmport.h
@@ -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
diff --git a/include/hw/net/ne2000-isa.h b/include/hw/net/ne2000-isa.h
index ef8b3334d7..f504a03db7 100644
--- a/include/hw/net/ne2000-isa.h
+++ b/include/hw/net/ne2000-isa.h
@@ -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;
 }
diff --git a/include/hw/timer/i8254.h b/include/hw/timer/i8254.h
index 38f896063e..b7bc98b688 100644
--- a/include/hw/timer/i8254.h
+++ b/include/hw/timer/i8254.h
@@ -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;
 }
-- 
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.