diff mbox series

[1/2] hw/ppc/prep_systemio: Use link property to remove &first_cpu

Message ID 20250110173217.80942-2-philmd@linaro.org
State New
Headers show
Series hw/ppc/prep_systemio: Remove &first_cpu and fix IRQ use | expand

Commit Message

Philippe Mathieu-Daudé Jan. 10, 2025, 5:32 p.m. UTC
In order to avoid using the &first_cpu global, pass the CPU
as link property from the 40p MachineClass::init().

Declare the link type as TYPE_POWERPC_CPU to have the CPU
type checked automatically.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/ppc/prep.c          | 2 ++
 hw/ppc/prep_systemio.c | 8 +++++---
 2 files changed, 7 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/hw/ppc/prep.c b/hw/ppc/prep.c
index 3e68d8e6e20..88a9b0fa7bb 100644
--- a/hw/ppc/prep.c
+++ b/hw/ppc/prep.c
@@ -324,6 +324,8 @@  static void ibm_40p_init(MachineState *machine)
         dev = DEVICE(isa_dev);
         qdev_prop_set_uint32(dev, "ibm-planar-id", 0xfc);
         qdev_prop_set_uint32(dev, "equipment", 0xc0);
+        object_property_set_link(OBJECT(dev), "cpu",
+                                 OBJECT(cpu), &error_fatal);
         isa_realize_and_unref(isa_dev, isa_bus, &error_fatal);
 
         dev = DEVICE(pci_create_simple(pci_bus, PCI_DEVFN(1, 0),
diff --git a/hw/ppc/prep_systemio.c b/hw/ppc/prep_systemio.c
index b1f2e130f03..7cbf7e4eecd 100644
--- a/hw/ppc/prep_systemio.c
+++ b/hw/ppc/prep_systemio.c
@@ -44,7 +44,9 @@  OBJECT_DECLARE_SIMPLE_TYPE(PrepSystemIoState, PREP_SYSTEMIO)
 
 struct PrepSystemIoState {
     ISADevice parent_obj;
+
     MemoryRegion ppc_parity_mem;
+    CPUState *cpu;
 
     qemu_irq non_contiguous_io_map_irq;
     uint8_t sreset; /* 0x0092 */
@@ -255,14 +257,12 @@  static void prep_systemio_realize(DeviceState *dev, Error **errp)
 {
     ISADevice *isa = ISA_DEVICE(dev);
     PrepSystemIoState *s = PREP_SYSTEMIO(dev);
-    PowerPCCPU *cpu;
 
     qdev_init_gpio_out(dev, &s->non_contiguous_io_map_irq, 1);
     s->iomap_type = PORT0850_IOMAP_NONCONTIGUOUS;
     qemu_set_irq(s->non_contiguous_io_map_irq,
                  s->iomap_type & PORT0850_IOMAP_NONCONTIGUOUS);
-    cpu = POWERPC_CPU(first_cpu);
-    s->softreset_irq = qdev_get_gpio_in(DEVICE(cpu), PPC6xx_INPUT_HRESET);
+    s->softreset_irq = qdev_get_gpio_in(DEVICE(s->cpu), PPC6xx_INPUT_HRESET);
 
     isa_register_portio_list(isa, &s->portio, 0x0, ppc_io800_port_list, s,
                              "systemio800");
@@ -288,6 +288,8 @@  static const VMStateDescription vmstate_prep_systemio = {
 static const Property prep_systemio_properties[] = {
     DEFINE_PROP_UINT8("ibm-planar-id", PrepSystemIoState, ibm_planar_id, 0),
     DEFINE_PROP_UINT8("equipment", PrepSystemIoState, equipment, 0),
+    DEFINE_PROP_LINK("cpu", PrepSystemIoState, cpu,
+                     TYPE_POWERPC_CPU, CPUState *),
 };
 
 static void prep_systemio_class_initfn(ObjectClass *klass, void *data)