@@ -365,26 +365,35 @@ static void create_fdt(LoongArchVirtMachineState *lvms)
365
365
static void fdt_add_cpu_nodes (const LoongArchVirtMachineState * lvms )
366
366
{
367
367
int num ;
368
- const MachineState * ms = MACHINE (lvms );
369
- int smp_cpus = ms -> smp .cpus ;
368
+ MachineState * ms = MACHINE (lvms );
369
+ MachineClass * mc = MACHINE_GET_CLASS (ms );
370
+ const CPUArchIdList * possible_cpus ;
371
+ LoongArchCPU * cpu ;
372
+ CPUState * cs ;
373
+ char * nodename , * map_path ;
370
374
371
375
qemu_fdt_add_subnode (ms -> fdt , "/cpus" );
372
376
qemu_fdt_setprop_cell (ms -> fdt , "/cpus" , "#address-cells" , 0x1 );
373
377
qemu_fdt_setprop_cell (ms -> fdt , "/cpus" , "#size-cells" , 0x0 );
374
378
375
379
/* cpu nodes */
376
- for (num = smp_cpus - 1 ; num >= 0 ; num -- ) {
377
- char * nodename = g_strdup_printf ("/cpus/cpu@%d" , num );
378
- LoongArchCPU * cpu = LOONGARCH_CPU (qemu_get_cpu (num ));
379
- CPUState * cs = CPU (cpu );
380
+ possible_cpus = mc -> possible_cpu_arch_ids (ms );
381
+ for (num = 0 ; num < possible_cpus -> len ; num ++ ) {
382
+ cs = possible_cpus -> cpus [num ].cpu ;
383
+ if (cs == NULL ) {
384
+ continue ;
385
+ }
386
+
387
+ nodename = g_strdup_printf ("/cpus/cpu@%d" , num );
388
+ cpu = LOONGARCH_CPU (cs );
380
389
381
390
qemu_fdt_add_subnode (ms -> fdt , nodename );
382
391
qemu_fdt_setprop_string (ms -> fdt , nodename , "device_type" , "cpu" );
383
392
qemu_fdt_setprop_string (ms -> fdt , nodename , "compatible" ,
384
393
cpu -> dtb_compatible );
385
- if (ms -> possible_cpus -> cpus [cs -> cpu_index ].props .has_node_id ) {
394
+ if (possible_cpus -> cpus [num ].props .has_node_id ) {
386
395
qemu_fdt_setprop_cell (ms -> fdt , nodename , "numa-node-id" ,
387
- ms -> possible_cpus -> cpus [cs -> cpu_index ].props .node_id );
396
+ possible_cpus -> cpus [num ].props .node_id );
388
397
}
389
398
qemu_fdt_setprop_cell (ms -> fdt , nodename , "reg" , num );
390
399
qemu_fdt_setprop_cell (ms -> fdt , nodename , "phandle" ,
@@ -394,11 +403,13 @@ static void fdt_add_cpu_nodes(const LoongArchVirtMachineState *lvms)
394
403
395
404
/*cpu map */
396
405
qemu_fdt_add_subnode (ms -> fdt , "/cpus/cpu-map" );
406
+ for (num = 0 ; num < possible_cpus -> len ; num ++ ) {
407
+ cs = possible_cpus -> cpus [num ].cpu ;
408
+ if (cs == NULL ) {
409
+ continue ;
410
+ }
397
411
398
- for (num = smp_cpus - 1 ; num >= 0 ; num -- ) {
399
- char * cpu_path = g_strdup_printf ("/cpus/cpu@%d" , num );
400
- char * map_path ;
401
-
412
+ nodename = g_strdup_printf ("/cpus/cpu@%d" , num );
402
413
if (ms -> smp .threads > 1 ) {
403
414
map_path = g_strdup_printf (
404
415
"/cpus/cpu-map/socket%d/core%d/thread%d" ,
@@ -412,10 +423,10 @@ static void fdt_add_cpu_nodes(const LoongArchVirtMachineState *lvms)
412
423
num % ms -> smp .cores );
413
424
}
414
425
qemu_fdt_add_path (ms -> fdt , map_path );
415
- qemu_fdt_setprop_phandle (ms -> fdt , map_path , "cpu" , cpu_path );
426
+ qemu_fdt_setprop_phandle (ms -> fdt , map_path , "cpu" , nodename );
416
427
417
428
g_free (map_path );
418
- g_free (cpu_path );
429
+ g_free (nodename );
419
430
}
420
431
}
421
432
0 commit comments