diff mbox series

[20/23] hw/mips/malta: Keep reference of vCPUs in MaltaState

Message ID 20250113004748.41658-21-philmd@linaro.org
State New
Headers show
Series hw/mips: Remove all uses of &first_cpu | expand

Commit Message

Philippe Mathieu-Daudé Jan. 13, 2025, 12:47 a.m. UTC
When a QOM object create children with object_new(),
it is better to keep reference to them for further
use. This will be helpful to remove &first_cpu uses
in few commits.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/mips/malta.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/hw/mips/malta.c b/hw/mips/malta.c
index 5ccff2cb0c1..a037ec2cc8d 100644
--- a/hw/mips/malta.c
+++ b/hw/mips/malta.c
@@ -107,6 +107,7 @@  struct MaltaState {
     SysBusDevice parent_obj;
 
     Clock *cpuclk;
+    MIPSCPU **cpus;
     MIPSCPSState cps;
 };
 
@@ -1037,6 +1038,7 @@  static void create_cpu_without_cps(MachineState *ms, MaltaState *s,
     for (i = 0; i < ms->smp.cpus; i++) {
         cpu = mips_cpu_create_with_clock(ms->cpu_type, s->cpuclk,
                                          TARGET_BIG_ENDIAN);
+        s->cpus[i] = cpu;
 
         /* Init internal devices */
         cpu_mips_irq_init_cpu(cpu);
@@ -1063,6 +1065,7 @@  static void create_cps(MachineState *ms, MaltaState *s,
                             &error_fatal);
     qdev_connect_clock_in(DEVICE(&s->cps), "clk-in", s->cpuclk);
     sysbus_realize(SYS_BUS_DEVICE(&s->cps), &error_fatal);
+    memcpy(s->cpus, s->cps.cpus, ms->smp.cpus * sizeof(MIPSCPU *));
 
     sysbus_mmio_map_overlap(SYS_BUS_DEVICE(&s->cps), 0, 0, 1);
 
@@ -1070,9 +1073,11 @@  static void create_cps(MachineState *ms, MaltaState *s,
     *cbus_irq = NULL;
 }
 
-static void mips_create_cpu(MachineState *ms, MaltaState *s,
-                            qemu_irq *cbus_irq, qemu_irq *i8259_irq)
+/* Initialize MaltaState::cpus[] */
+static void mips_create_cpus(MachineState *ms, MaltaState *s,
+                             qemu_irq *cbus_irq, qemu_irq *i8259_irq)
 {
+    s->cpus = g_new(MIPSCPU *, ms->smp.cpus);
     if ((ms->smp.cpus > 1) && cpu_type_supports_cps_smp(ms->cpu_type)) {
         create_cps(ms, s, cbus_irq, i8259_irq);
     } else {
@@ -1111,7 +1116,7 @@  void mips_malta_init(MachineState *machine)
     sysbus_realize_and_unref(SYS_BUS_DEVICE(s), &error_fatal);
 
     /* create CPU */
-    mips_create_cpu(machine, s, &cbus_irq, &i8259_irq);
+    mips_create_cpus(machine, s, &cbus_irq, &i8259_irq);
 
     /* allocate RAM */
     if (ram_size > 2 * GiB) {