Export the QOM declaration of TyphoonState by moving it out of
hw/alpha/typhoon.c into hw/alpha/alpha_sys.h. Keep its definition
encapsulated.

Define ClipperMachineState with a TyphoonState member.

Move the instantiation of Typhoon out of typhoon_init() into the
Clipper machine and add it as a QOM child object of Clipper.

For now, add TyphoonState pointer as a parameter of typhoon_init().

Note: Eventually, typhoon_init() will be split into Typhoon's
instance_init and realize hooks; this is an intermediate commit
to that end.

Signed-off-by: Yodel Eldar <[email protected]>
---
 hw/alpha/alpha_sys.h |  4 +++-
 hw/alpha/dp264.c     | 31 ++++++++++++++++++++++++++++---
 hw/alpha/typhoon.c   | 12 +++---------
 3 files changed, 34 insertions(+), 13 deletions(-)

diff --git a/hw/alpha/alpha_sys.h b/hw/alpha/alpha_sys.h
index 6e6691d116..247a52b776 100644
--- a/hw/alpha/alpha_sys.h
+++ b/hw/alpha/alpha_sys.h
@@ -8,9 +8,11 @@
 #include "hw/core/boards.h"
 #include "hw/intc/i8259.h"
 
+#define TYPE_TYPHOON_PCI_HOST_BRIDGE "typhoon-pcihost"
+OBJECT_DECLARE_SIMPLE_TYPE(TyphoonState, TYPHOON_PCI_HOST_BRIDGE)
 
 PCIBus *typhoon_init(MemoryRegion *, qemu_irq *, qemu_irq *, AlphaCPU *[4],
-                     pci_map_irq_fn, uint8_t devfn_min);
+                     pci_map_irq_fn, uint8_t devfn_min, TyphoonState *);
 
 /* alpha_pci.c.  */
 extern const MemoryRegionOps alpha_pci_ignore_ops;
diff --git a/hw/alpha/dp264.c b/hw/alpha/dp264.c
index b2ef423f93..c9d639eb7b 100644
--- a/hw/alpha/dp264.c
+++ b/hw/alpha/dp264.c
@@ -18,6 +18,15 @@
 #include "hw/isa/superio.h"
 #include "qemu/datadir.h"
 
+#define TYPE_CLIPPER_MACHINE MACHINE_TYPE_NAME("clipper")
+OBJECT_DECLARE_SIMPLE_TYPE(ClipperMachineState, CLIPPER_MACHINE)
+
+struct ClipperMachineState {
+    MachineState parent_obj;
+
+    TyphoonState *typhoon;
+};
+
 static uint64_t cpu_alpha_superpage_to_phys(void *opaque, uint64_t addr)
 {
     if (((addr >> 41) & 3) == 2) {
@@ -46,6 +55,7 @@ static int clipper_pci_map_irq(PCIDevice *d, int irq_num)
 
 static void clipper_init(MachineState *machine)
 {
+    ClipperMachineState *cms = CLIPPER_MACHINE(machine);
     ram_addr_t ram_size = machine->ram_size;
     const char *kernel_filename = machine->kernel_filename;
     const char *kernel_cmdline = machine->kernel_cmdline;
@@ -64,6 +74,11 @@ static void clipper_init(MachineState *machine)
     uint64_t kernel_entry, kernel_low, kernel_high;
     unsigned int smp_cpus = machine->smp.cpus;
 
+    Object * const typhoon_obj = object_new(TYPE_TYPHOON_PCI_HOST_BRIDGE);
+    TyphoonState * const typhoon = TYPHOON_PCI_HOST_BRIDGE(typhoon_obj);
+    cms->typhoon = typhoon;
+    object_property_add_child(OBJECT(machine), "typhoon", typhoon_obj);
+
     /* Create up to 4 cpus.  */
     memset(cpus, 0, sizeof(cpus));
     for (i = 0; i < smp_cpus; ++i) {
@@ -93,7 +108,7 @@ static void clipper_init(MachineState *machine)
      * the minimum PCI device IdSel is 1.
      */
     pci_bus = typhoon_init(machine->ram, &isa_irq, &rtc_irq, cpus,
-                           clipper_pci_map_irq, PCI_DEVFN(1, 0));
+                           clipper_pci_map_irq, PCI_DEVFN(1, 0), typhoon);
 
     /*
      * Init the PCI -> ISA bridge.
@@ -218,8 +233,9 @@ static void clipper_init(MachineState *machine)
     }
 }
 
-static void clipper_machine_init(MachineClass *mc)
+static void clipper_machine_init(ObjectClass *oc, const void *data)
 {
+    MachineClass *mc = MACHINE_CLASS(oc);
     mc->desc = "Alpha DP264/CLIPPER";
     mc->init = clipper_init;
     mc->block_default_type = IF_IDE;
@@ -230,4 +246,13 @@ static void clipper_machine_init(MachineClass *mc)
     mc->default_nic = "e1000";
 }
 
-DEFINE_MACHINE("clipper", clipper_machine_init)
+static const TypeInfo clipper_types[] = {
+    {
+        .name = TYPE_CLIPPER_MACHINE,
+        .parent = TYPE_MACHINE,
+        .instance_size = sizeof(ClipperMachineState),
+        .class_init = clipper_machine_init,
+    },
+};
+
+DEFINE_TYPES(clipper_types);
diff --git a/hw/alpha/typhoon.c b/hw/alpha/typhoon.c
index 5789829818..b0eb4e415c 100644
--- a/hw/alpha/typhoon.c
+++ b/hw/alpha/typhoon.c
@@ -18,7 +18,6 @@
 #include "hw/core/qdev-properties.h"
 
 
-#define TYPE_TYPHOON_PCI_HOST_BRIDGE "typhoon-pcihost"
 #define TYPE_TYPHOON_IOMMU_MEMORY_REGION "typhoon-iommu-memory-region"
 
 typedef struct TyphoonCchip {
@@ -50,8 +49,6 @@ typedef struct TyphoonPchip {
     TyphoonWindow win[4];
 } TyphoonPchip;
 
-OBJECT_DECLARE_SIMPLE_TYPE(TyphoonState, TYPHOON_PCI_HOST_BRIDGE)
-
 struct TyphoonState {
     PCIHostState parent_obj;
 
@@ -836,18 +833,15 @@ static void typhoon_alarm_timer(void *opaque)
 
 PCIBus *typhoon_init(MemoryRegion *ram, qemu_irq *p_isa_irq,
                      qemu_irq *p_rtc_irq, AlphaCPU *cpus[4],
-                     pci_map_irq_fn sys_map_irq, uint8_t devfn_min)
+                     pci_map_irq_fn sys_map_irq, uint8_t devfn_min,
+                     TyphoonState *s)
 {
     MemoryRegion *addr_space = get_system_memory();
-    DeviceState *dev;
-    TyphoonState *s;
+    DeviceState *dev = DEVICE(s);
     PCIHostState *phb;
     PCIBus *b;
     int i;
 
-    dev = qdev_new(TYPE_TYPHOON_PCI_HOST_BRIDGE);
-
-    s = TYPHOON_PCI_HOST_BRIDGE(dev);
     phb = PCI_HOST_BRIDGE(dev);
 
     s->cchip.misc = 0x800000000ull; /* Revision: Typhoon.  */

-- 
2.53.0


Reply via email to