hw/arm: fsl-imx8mp: Don't call qdev_get_machine in soc init
Calling qdev_get_machine() in the soc_init function would result in the following assert ../hw/core/qdev.c:858: qdev_get_machine: Assertion `dev' failed. when trying to run ./qemu-system-aarch64 -S -display none -M virt -device fsl-imx8mp,help as the machine wasn't created yet. We call qdev_get_machine() to obtain the number of CPUs in the machine. So instead of initialising the CPUs in the SoC init let's instead do it in the realise where the machine will exist. Signed-off-by: Alistair Francis <alistair.francis@wdc.com> Tested-by: Markus Armbruster <armbru@redhat.com> Message-ID: <20260312043158.4191378-6-alistair.francis@wdc.com> Signed-off-by: Thomas Huth <thuth@redhat.com>
Alistair Francis committed
Mar 12, 2026 at 14:31 UTC
b67d0bcdd41cb536883c3732a0f95803e975dcd8
1 file changed
+6
-7
hw/arm/fsl-imx8mp.c
+6
-7
@@ -193,16 +193,9 @@ static const struct {
193
194
static void fsl_imx8mp_init(Object *obj)
195
{
196
- MachineState *ms = MACHINE(qdev_get_machine());
196
FslImx8mpState *s = FSL_IMX8MP(obj);
198
- const char *cpu_type = ms->cpu_type ?: ARM_CPU_TYPE_NAME("cortex-a53");
197
int i;
198
201
- for (i = 0; i < MIN(ms->smp.cpus, FSL_IMX8MP_NUM_CPUS); i++) {
202
- g_autofree char *name = g_strdup_printf("cpu%d", i);
203
- object_initialize_child(obj, name, &s->cpu[i], cpu_type);
204
- }
205
-
199
object_initialize_child(obj, "gic", &s->gic, gicv3_class_name());
200
201
object_initialize_child(obj, "ccm", &s->ccm, TYPE_IMX8MP_CCM);
@@ -265,6 +258,7 @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp)
258
MachineState *ms = MACHINE(qdev_get_machine());
259
FslImx8mpState *s = FSL_IMX8MP(dev);
260
DeviceState *gicdev = DEVICE(&s->gic);
261
+ const char *cpu_type = ms->cpu_type ?: ARM_CPU_TYPE_NAME("cortex-a53");
262
int i;
263
264
if (ms->smp.cpus > FSL_IMX8MP_NUM_CPUS) {
@@ -273,6 +267,11 @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp)
267
return;
268
}
269
270
+ for (i = 0; i < ms->smp.cpus; i++) {
271
+ g_autofree char *name = g_strdup_printf("cpu%d", i);
272
+ object_initialize_child(OBJECT(dev), name, &s->cpu[i], cpu_type);
273
+ }
274
+
275
/* CPUs */
276
for (i = 0; i < ms->smp.cpus; i++) {
277
/* On uniprocessor, the CBAR is set to 0 */