qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/11] hw/mips/loongson3: Remove uses of &first_cpu global
@ 2025-01-12 21:58 Philippe Mathieu-Daudé
  2025-01-12 21:58 ` [PATCH 01/11] hw/mips/loongson3_virt: Factor generic_cpu_reset() out Philippe Mathieu-Daudé
                   ` (10 more replies)
  0 siblings, 11 replies; 25+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-12 21:58 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, Huacai Chen, Jiaxun Yang

Propagate values from machine_init() in order to remove
use of globals such &first_cpu and &current_machine.

Philippe Mathieu-Daudé (11):
  hw/mips/loongson3_virt: Factor generic_cpu_reset() out
  hw/mips/loongson3_virt: Keep reference of vCPUs in machine_init()
  hw/mips/loongson3_virt: Have fw_conf_init() access local loaderparams
  hw/mips/loongson3_virt: Pass CPU argument to get_cpu_freq_hz()
  hw/mips/loongson3_bootp: Include missing headers
  hw/mips/loongson3: Propagate cpu_count to init_loongson_params()
  hw/mips/loongson3_virt: Propagate cpu_count to init_boot_param()
  hw/mips/loongson3_bootp: Propagate processor_id to init_cpu_info()
  hw/mips/loongson3_virt: Propagate processor_id to
    init_loongson_params()
  hw/mips/loongson3_virt: Propagate %processor_id to init_boot_param()
  hw/mips/loongson3_bootp: Move to common_ss[]

 hw/mips/loongson3_bootp.h |  1 +
 hw/mips/loongson3_bootp.c | 16 ++++++-----
 hw/mips/loongson3_virt.c  | 57 ++++++++++++++++++++++-----------------
 hw/mips/meson.build       |  3 ++-
 4 files changed, 45 insertions(+), 32 deletions(-)

-- 
2.47.1



^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH 01/11] hw/mips/loongson3_virt: Factor generic_cpu_reset() out
  2025-01-12 21:58 [PATCH 00/11] hw/mips/loongson3: Remove uses of &first_cpu global Philippe Mathieu-Daudé
@ 2025-01-12 21:58 ` Philippe Mathieu-Daudé
  2025-01-15  5:02   ` Richard Henderson
  2025-01-12 21:58 ` [PATCH 02/11] hw/mips/loongson3_virt: Keep reference of vCPUs in machine_init() Philippe Mathieu-Daudé
                   ` (9 subsequent siblings)
  10 siblings, 1 reply; 25+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-12 21:58 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, Huacai Chen, Jiaxun Yang

main_cpu_reset() is misleadingly named "main": it resets
all vCPUs, with a special case for the first vCPU.

Factor generic_cpu_reset() out of main_cpu_reset(),
allowing to remove one &first_cpu use.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/mips/loongson3_virt.c | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/hw/mips/loongson3_virt.c b/hw/mips/loongson3_virt.c
index f3cc7a8376f..47d112981a2 100644
--- a/hw/mips/loongson3_virt.c
+++ b/hw/mips/loongson3_virt.c
@@ -399,25 +399,33 @@ static uint64_t load_kernel(CPUMIPSState *env)
     return kernel_entry;
 }
 
-static void main_cpu_reset(void *opaque)
+static void generic_cpu_reset(void *opaque)
 {
     MIPSCPU *cpu = opaque;
     CPUMIPSState *env = &cpu->env;
 
     cpu_reset(CPU(cpu));
 
-    /* Loongson-3 reset stuff */
     if (loaderparams.kernel_filename) {
-        if (cpu == MIPS_CPU(first_cpu)) {
-            env->active_tc.gpr[4] = loaderparams.a0;
-            env->active_tc.gpr[5] = loaderparams.a1;
-            env->active_tc.gpr[6] = loaderparams.a2;
-            env->active_tc.PC = loaderparams.kernel_entry;
-        }
         env->CP0_Status &= ~((1 << CP0St_BEV) | (1 << CP0St_ERL));
     }
 }
 
+static void main_cpu_reset(void *opaque)
+{
+    generic_cpu_reset(opaque);
+
+    if (loaderparams.kernel_filename) {
+        MIPSCPU *cpu = opaque;
+        CPUMIPSState *env = &cpu->env;
+
+        env->active_tc.gpr[4] = loaderparams.a0;
+        env->active_tc.gpr[5] = loaderparams.a1;
+        env->active_tc.gpr[6] = loaderparams.a2;
+        env->active_tc.PC = loaderparams.kernel_entry;
+    }
+}
+
 static inline void loongson3_virt_devices_init(MachineState *machine,
                                                DeviceState *pic)
 {
@@ -572,7 +580,7 @@ static void mips_loongson3_virt_init(MachineState *machine)
         /* Init internal devices */
         cpu_mips_irq_init_cpu(cpu);
         cpu_mips_clock_init(cpu);
-        qemu_register_reset(main_cpu_reset, cpu);
+        qemu_register_reset(i ? generic_cpu_reset : main_cpu_reset, cpu);
 
         if (!kvm_enabled()) {
             hwaddr base = ((hwaddr)node << 44) + virt_memmap[VIRT_IPI].base;
-- 
2.47.1



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 02/11] hw/mips/loongson3_virt: Keep reference of vCPUs in machine_init()
  2025-01-12 21:58 [PATCH 00/11] hw/mips/loongson3: Remove uses of &first_cpu global Philippe Mathieu-Daudé
  2025-01-12 21:58 ` [PATCH 01/11] hw/mips/loongson3_virt: Factor generic_cpu_reset() out Philippe Mathieu-Daudé
@ 2025-01-12 21:58 ` Philippe Mathieu-Daudé
  2025-01-15  5:18   ` Richard Henderson
  2025-01-12 21:58 ` [PATCH 03/11] hw/mips/loongson3_virt: Have fw_conf_init() access local loaderparams Philippe Mathieu-Daudé
                   ` (8 subsequent siblings)
  10 siblings, 1 reply; 25+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-12 21:58 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, Huacai Chen, Jiaxun Yang

Keep references of all vCPUs created. That allows
to directly access the first vCPU without using the
&first_cpu global.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/mips/loongson3_virt.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/hw/mips/loongson3_virt.c b/hw/mips/loongson3_virt.c
index 47d112981a2..4b19941c1dc 100644
--- a/hw/mips/loongson3_virt.c
+++ b/hw/mips/loongson3_virt.c
@@ -492,9 +492,8 @@ static void mips_loongson3_virt_init(MachineState *machine)
 {
     int i;
     long bios_size;
-    MIPSCPU *cpu;
+    g_autofree MIPSCPU **cpus = NULL;
     Clock *cpuclk;
-    CPUMIPSState *env;
     DeviceState *liointc;
     DeviceState *ipi = NULL;
     char *filename;
@@ -569,13 +568,16 @@ static void mips_loongson3_virt_init(MachineState *machine)
     cpuclk = clock_new(OBJECT(machine), "cpu-refclk");
     clock_set_hz(cpuclk, DEF_LOONGSON3_FREQ);
 
+    cpus = g_new(MIPSCPU *, machine->smp.cpus);
     for (i = 0; i < machine->smp.cpus; i++) {
+        MIPSCPU *cpu;
         int node = i / LOONGSON3_CORE_PER_NODE;
         int core = i % LOONGSON3_CORE_PER_NODE;
         int ip;
 
         /* init CPUs */
         cpu = mips_cpu_create_with_clock(machine->cpu_type, cpuclk, false);
+        cpus[i] = cpu;
 
         /* Init internal devices */
         cpu_mips_irq_init_cpu(cpu);
@@ -609,7 +611,6 @@ static void mips_loongson3_virt_init(MachineState *machine)
                                pin, cpu->env.irq[ip + 2]);
         }
     }
-    env = &MIPS_CPU(first_cpu)->env;
 
     /* Allocate RAM/BIOS, 0x00000000~0x10000000 is alias of 0x80000000~0x90000000 */
     memory_region_init_rom(bios, NULL, "loongson3.bios",
@@ -640,7 +641,7 @@ static void mips_loongson3_virt_init(MachineState *machine)
         loaderparams.kernel_filename = kernel_filename;
         loaderparams.kernel_cmdline = kernel_cmdline;
         loaderparams.initrd_filename = initrd_filename;
-        loaderparams.kernel_entry = load_kernel(env);
+        loaderparams.kernel_entry = load_kernel(&cpus[0]->env);
 
         init_boot_rom();
         init_boot_param();
-- 
2.47.1



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 03/11] hw/mips/loongson3_virt: Have fw_conf_init() access local loaderparams
  2025-01-12 21:58 [PATCH 00/11] hw/mips/loongson3: Remove uses of &first_cpu global Philippe Mathieu-Daudé
  2025-01-12 21:58 ` [PATCH 01/11] hw/mips/loongson3_virt: Factor generic_cpu_reset() out Philippe Mathieu-Daudé
  2025-01-12 21:58 ` [PATCH 02/11] hw/mips/loongson3_virt: Keep reference of vCPUs in machine_init() Philippe Mathieu-Daudé
@ 2025-01-12 21:58 ` Philippe Mathieu-Daudé
  2025-01-15  5:09   ` Richard Henderson
  2025-01-12 21:58 ` [PATCH 04/11] hw/mips/loongson3_virt: Pass CPU argument to get_cpu_freq_hz() Philippe Mathieu-Daudé
                   ` (7 subsequent siblings)
  10 siblings, 1 reply; 25+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-12 21:58 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, Huacai Chen, Jiaxun Yang

'loaderparams' is declared statically. Let fw_conf_init()
access its 'cpu_freq' and 'ram_size' fields.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/mips/loongson3_virt.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/hw/mips/loongson3_virt.c b/hw/mips/loongson3_virt.c
index 4b19941c1dc..032ff92383e 100644
--- a/hw/mips/loongson3_virt.c
+++ b/hw/mips/loongson3_virt.c
@@ -280,7 +280,7 @@ static void fw_cfg_boot_set(void *opaque, const char *boot_device,
     fw_cfg_modify_i16(opaque, FW_CFG_BOOT_DEVICE, boot_device[0]);
 }
 
-static void fw_conf_init(unsigned long ram_size)
+static void fw_conf_init(void)
 {
     static const uint8_t suspend[6] = {128, 0, 0, 129, 128, 128};
     FWCfgState *fw_cfg;
@@ -289,9 +289,9 @@ static void fw_conf_init(unsigned long ram_size)
     fw_cfg = fw_cfg_init_mem_wide(cfg_addr, cfg_addr + 8, 8, 0, NULL);
     fw_cfg_add_i16(fw_cfg, FW_CFG_NB_CPUS, (uint16_t)current_machine->smp.cpus);
     fw_cfg_add_i16(fw_cfg, FW_CFG_MAX_CPUS, (uint16_t)current_machine->smp.max_cpus);
-    fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
+    fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, loaderparams.ram_size);
     fw_cfg_add_i32(fw_cfg, FW_CFG_MACHINE_VERSION, 1);
-    fw_cfg_add_i64(fw_cfg, FW_CFG_CPU_FREQ, get_cpu_freq_hz());
+    fw_cfg_add_i64(fw_cfg, FW_CFG_CPU_FREQ, loaderparams.cpu_freq);
 
     fw_cfg_add_file(fw_cfg, "etc/system-states",
                     g_memdup2(suspend, sizeof(suspend)), sizeof(suspend));
@@ -635,9 +635,9 @@ static void mips_loongson3_virt_init(MachineState *machine)
      * Please use -L to set the BIOS path and -bios to set bios name.
      */
 
+    loaderparams.cpu_freq = get_cpu_freq_hz();
+    loaderparams.ram_size = ram_size;
     if (kernel_filename) {
-        loaderparams.cpu_freq = get_cpu_freq_hz();
-        loaderparams.ram_size = ram_size;
         loaderparams.kernel_filename = kernel_filename;
         loaderparams.kernel_cmdline = kernel_cmdline;
         loaderparams.initrd_filename = initrd_filename;
@@ -663,7 +663,7 @@ static void mips_loongson3_virt_init(MachineState *machine)
             exit(1);
         }
 
-        fw_conf_init(ram_size);
+        fw_conf_init();
     }
 
     loongson3_virt_devices_init(machine, liointc);
-- 
2.47.1



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 04/11] hw/mips/loongson3_virt: Pass CPU argument to get_cpu_freq_hz()
  2025-01-12 21:58 [PATCH 00/11] hw/mips/loongson3: Remove uses of &first_cpu global Philippe Mathieu-Daudé
                   ` (2 preceding siblings ...)
  2025-01-12 21:58 ` [PATCH 03/11] hw/mips/loongson3_virt: Have fw_conf_init() access local loaderparams Philippe Mathieu-Daudé
@ 2025-01-12 21:58 ` Philippe Mathieu-Daudé
  2025-01-15  5:09   ` Richard Henderson
  2025-01-12 21:58 ` [PATCH 05/11] hw/mips/loongson3_bootp: Include missing headers Philippe Mathieu-Daudé
                   ` (6 subsequent siblings)
  10 siblings, 1 reply; 25+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-12 21:58 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, Huacai Chen, Jiaxun Yang

Pass the first vCPU as argument, allowing to remove
another &first_cpu global use.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/mips/loongson3_virt.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/mips/loongson3_virt.c b/hw/mips/loongson3_virt.c
index 032ff92383e..078ad46174f 100644
--- a/hw/mips/loongson3_virt.c
+++ b/hw/mips/loongson3_virt.c
@@ -153,7 +153,7 @@ static const MemoryRegionOps loongson3_pm_ops = {
 
 #define DEF_LOONGSON3_FREQ (800 * 1000 * 1000)
 
-static uint64_t get_cpu_freq_hz(void)
+static uint64_t get_cpu_freq_hz(const MIPSCPU *cpu)
 {
 #ifdef CONFIG_KVM
     int ret;
@@ -164,7 +164,7 @@ static uint64_t get_cpu_freq_hz(void)
     };
 
     if (kvm_enabled()) {
-        ret = kvm_vcpu_ioctl(first_cpu, KVM_GET_ONE_REG, &freq_reg);
+        ret = kvm_vcpu_ioctl(CPU(cpu), KVM_GET_ONE_REG, &freq_reg);
         if (ret >= 0) {
             return freq * 2;
         }
@@ -635,7 +635,7 @@ static void mips_loongson3_virt_init(MachineState *machine)
      * Please use -L to set the BIOS path and -bios to set bios name.
      */
 
-    loaderparams.cpu_freq = get_cpu_freq_hz();
+    loaderparams.cpu_freq = get_cpu_freq_hz(cpus[0]);
     loaderparams.ram_size = ram_size;
     if (kernel_filename) {
         loaderparams.kernel_filename = kernel_filename;
-- 
2.47.1



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 05/11] hw/mips/loongson3_bootp: Include missing headers
  2025-01-12 21:58 [PATCH 00/11] hw/mips/loongson3: Remove uses of &first_cpu global Philippe Mathieu-Daudé
                   ` (3 preceding siblings ...)
  2025-01-12 21:58 ` [PATCH 04/11] hw/mips/loongson3_virt: Pass CPU argument to get_cpu_freq_hz() Philippe Mathieu-Daudé
@ 2025-01-12 21:58 ` Philippe Mathieu-Daudé
  2025-01-15  5:10   ` Richard Henderson
  2025-01-12 21:58 ` [PATCH 06/11] hw/mips/loongson3: Propagate cpu_count to init_loongson_params() Philippe Mathieu-Daudé
                   ` (5 subsequent siblings)
  10 siblings, 1 reply; 25+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-12 21:58 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, Huacai Chen, Jiaxun Yang

MemMapEntry is declared in "exec/hwaddr.h", cpu_to_le32() in
"qemu/bswap.h". These headers are indirectly included via "cpu.h".
Include them explicitly in order to avoid when removing "cpu.h":

  In file included from ../../hw/mips/loongson3_bootp.c:27:
  hw/mips/loongson3_bootp.h:234:14: error: unknown type name 'MemMapEntry'
    234 | extern const MemMapEntry virt_memmap[];
        |              ^
  hw/mips/loongson3_bootp.c:33:18: error: call to undeclared function 'cpu_to_le32'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     33 |     c->cputype = cpu_to_le32(Loongson_3A);
        |                  ^

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/mips/loongson3_bootp.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/hw/mips/loongson3_bootp.c b/hw/mips/loongson3_bootp.c
index b97b81903b7..712439c2575 100644
--- a/hw/mips/loongson3_bootp.c
+++ b/hw/mips/loongson3_bootp.c
@@ -21,6 +21,8 @@
 #include "qemu/osdep.h"
 #include "qemu/units.h"
 #include "qemu/cutils.h"
+#include "qemu/bswap.h"
+#include "exec/hwaddr.h"
 #include "cpu.h"
 #include "hw/boards.h"
 #include "hw/mips/loongson3_bootp.h"
-- 
2.47.1



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 06/11] hw/mips/loongson3: Propagate cpu_count to init_loongson_params()
  2025-01-12 21:58 [PATCH 00/11] hw/mips/loongson3: Remove uses of &first_cpu global Philippe Mathieu-Daudé
                   ` (4 preceding siblings ...)
  2025-01-12 21:58 ` [PATCH 05/11] hw/mips/loongson3_bootp: Include missing headers Philippe Mathieu-Daudé
@ 2025-01-12 21:58 ` Philippe Mathieu-Daudé
  2025-01-15  5:13   ` Richard Henderson
  2025-01-12 21:58 ` [PATCH 07/11] hw/mips/loongson3_virt: Propagate cpu_count to init_boot_param() Philippe Mathieu-Daudé
                   ` (4 subsequent siblings)
  10 siblings, 1 reply; 25+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-12 21:58 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, Huacai Chen, Jiaxun Yang

Propagate the %cpu_count from the machine file, allowing
to remove the "hw/boards.h" dependency (which is machine
specific) from loongson3_bootp.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/mips/loongson3_bootp.h |  1 +
 hw/mips/loongson3_bootp.c | 11 ++++++-----
 hw/mips/loongson3_virt.c  |  1 +
 3 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/hw/mips/loongson3_bootp.h b/hw/mips/loongson3_bootp.h
index 9091265df7f..ee6340e42c1 100644
--- a/hw/mips/loongson3_bootp.h
+++ b/hw/mips/loongson3_bootp.h
@@ -233,6 +233,7 @@ enum {
 
 extern const MemMapEntry virt_memmap[];
 void init_loongson_params(struct loongson_params *lp, void *p,
+                          uint32_t cpu_count,
                           uint64_t cpu_freq, uint64_t ram_size);
 void init_reset_system(struct efi_reset_system_t *reset);
 
diff --git a/hw/mips/loongson3_bootp.c b/hw/mips/loongson3_bootp.c
index 712439c2575..91b58a71a68 100644
--- a/hw/mips/loongson3_bootp.c
+++ b/hw/mips/loongson3_bootp.c
@@ -24,10 +24,10 @@
 #include "qemu/bswap.h"
 #include "exec/hwaddr.h"
 #include "cpu.h"
-#include "hw/boards.h"
 #include "hw/mips/loongson3_bootp.h"
 
-static void init_cpu_info(void *g_cpuinfo, uint64_t cpu_freq)
+static void init_cpu_info(void *g_cpuinfo, uint32_t cpu_count,
+                          uint64_t cpu_freq)
 {
     struct efi_cpuinfo_loongson *c = g_cpuinfo;
 
@@ -40,8 +40,8 @@ static void init_cpu_info(void *g_cpuinfo, uint64_t cpu_freq)
     }
 
     c->cpu_startup_core_id = cpu_to_le16(0);
-    c->nr_cpus = cpu_to_le32(current_machine->smp.cpus);
-    c->total_node = cpu_to_le32(DIV_ROUND_UP(current_machine->smp.cpus,
+    c->nr_cpus = cpu_to_le32(cpu_count);
+    c->total_node = cpu_to_le32(DIV_ROUND_UP(cpu_count,
                                              LOONGSON3_CORE_PER_NODE));
 }
 
@@ -112,9 +112,10 @@ static void init_special_info(void *g_special)
 }
 
 void init_loongson_params(struct loongson_params *lp, void *p,
+                          uint32_t cpu_count,
                           uint64_t cpu_freq, uint64_t ram_size)
 {
-    init_cpu_info(p, cpu_freq);
+    init_cpu_info(p, cpu_count, cpu_freq);
     lp->cpu_offset = cpu_to_le64((uintptr_t)p - (uintptr_t)lp);
     p += ROUND_UP(sizeof(struct efi_cpuinfo_loongson), 64);
 
diff --git a/hw/mips/loongson3_virt.c b/hw/mips/loongson3_virt.c
index 078ad46174f..af1937455b0 100644
--- a/hw/mips/loongson3_virt.c
+++ b/hw/mips/loongson3_virt.c
@@ -185,6 +185,7 @@ static void init_boot_param(void)
     init_reset_system(&(bp->reset_system));
     p += ROUND_UP(sizeof(struct boot_params), 64);
     init_loongson_params(&(bp->efi.smbios.lp), p,
+                         current_machine->smp.cpus,
                          loaderparams.cpu_freq, loaderparams.ram_size);
 
     rom_add_blob_fixed("params_rom", bp,
-- 
2.47.1



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 07/11] hw/mips/loongson3_virt: Propagate cpu_count to init_boot_param()
  2025-01-12 21:58 [PATCH 00/11] hw/mips/loongson3: Remove uses of &first_cpu global Philippe Mathieu-Daudé
                   ` (5 preceding siblings ...)
  2025-01-12 21:58 ` [PATCH 06/11] hw/mips/loongson3: Propagate cpu_count to init_loongson_params() Philippe Mathieu-Daudé
@ 2025-01-12 21:58 ` Philippe Mathieu-Daudé
  2025-01-15  5:13   ` Richard Henderson
  2025-01-12 21:58 ` [PATCH 08/11] hw/mips/loongson3_bootp: Propagate processor_id to init_cpu_info() Philippe Mathieu-Daudé
                   ` (3 subsequent siblings)
  10 siblings, 1 reply; 25+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-12 21:58 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, Huacai Chen, Jiaxun Yang

Remove one use of the 'current_machine' global.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/mips/loongson3_virt.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/hw/mips/loongson3_virt.c b/hw/mips/loongson3_virt.c
index af1937455b0..a240662016b 100644
--- a/hw/mips/loongson3_virt.c
+++ b/hw/mips/loongson3_virt.c
@@ -173,7 +173,7 @@ static uint64_t get_cpu_freq_hz(const MIPSCPU *cpu)
     return DEF_LOONGSON3_FREQ;
 }
 
-static void init_boot_param(void)
+static void init_boot_param(unsigned cpu_count)
 {
     static void *p;
     struct boot_params *bp;
@@ -184,8 +184,7 @@ static void init_boot_param(void)
     bp->efi.smbios.vers = cpu_to_le16(1);
     init_reset_system(&(bp->reset_system));
     p += ROUND_UP(sizeof(struct boot_params), 64);
-    init_loongson_params(&(bp->efi.smbios.lp), p,
-                         current_machine->smp.cpus,
+    init_loongson_params(&(bp->efi.smbios.lp), p, cpu_count,
                          loaderparams.cpu_freq, loaderparams.ram_size);
 
     rom_add_blob_fixed("params_rom", bp,
@@ -645,7 +644,7 @@ static void mips_loongson3_virt_init(MachineState *machine)
         loaderparams.kernel_entry = load_kernel(&cpus[0]->env);
 
         init_boot_rom();
-        init_boot_param();
+        init_boot_param(machine->smp.cpus);
     } else {
         filename = qemu_find_file(QEMU_FILE_TYPE_BIOS,
                                   machine->firmware ?: LOONGSON3_BIOSNAME);
-- 
2.47.1



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 08/11] hw/mips/loongson3_bootp: Propagate processor_id to init_cpu_info()
  2025-01-12 21:58 [PATCH 00/11] hw/mips/loongson3: Remove uses of &first_cpu global Philippe Mathieu-Daudé
                   ` (6 preceding siblings ...)
  2025-01-12 21:58 ` [PATCH 07/11] hw/mips/loongson3_virt: Propagate cpu_count to init_boot_param() Philippe Mathieu-Daudé
@ 2025-01-12 21:58 ` Philippe Mathieu-Daudé
  2025-01-15  5:15   ` Richard Henderson
  2025-01-12 21:58 ` [PATCH 09/11] hw/mips/loongson3_virt: Propagate processor_id to init_loongson_params() Philippe Mathieu-Daudé
                   ` (2 subsequent siblings)
  10 siblings, 1 reply; 25+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-12 21:58 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, Huacai Chen, Jiaxun Yang

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/mips/loongson3_bootp.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/mips/loongson3_bootp.c b/hw/mips/loongson3_bootp.c
index 91b58a71a68..1aab26df69e 100644
--- a/hw/mips/loongson3_bootp.c
+++ b/hw/mips/loongson3_bootp.c
@@ -27,12 +27,12 @@
 #include "hw/mips/loongson3_bootp.h"
 
 static void init_cpu_info(void *g_cpuinfo, uint32_t cpu_count,
-                          uint64_t cpu_freq)
+                          uint32_t processor_id, uint64_t cpu_freq)
 {
     struct efi_cpuinfo_loongson *c = g_cpuinfo;
 
     c->cputype = cpu_to_le32(Loongson_3A);
-    c->processor_id = cpu_to_le32(MIPS_CPU(first_cpu)->env.CP0_PRid);
+    c->processor_id = cpu_to_le32(processor_id);
     if (cpu_freq > UINT_MAX) {
         c->cpu_clock_freq = cpu_to_le32(UINT_MAX);
     } else {
@@ -115,7 +115,7 @@ void init_loongson_params(struct loongson_params *lp, void *p,
                           uint32_t cpu_count,
                           uint64_t cpu_freq, uint64_t ram_size)
 {
-    init_cpu_info(p, cpu_count, cpu_freq);
+    init_cpu_info(p, MIPS_CPU(first_cpu)->env.CP0_PRid, cpu_count, cpu_freq);
     lp->cpu_offset = cpu_to_le64((uintptr_t)p - (uintptr_t)lp);
     p += ROUND_UP(sizeof(struct efi_cpuinfo_loongson), 64);
 
-- 
2.47.1



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 09/11] hw/mips/loongson3_virt: Propagate processor_id to init_loongson_params()
  2025-01-12 21:58 [PATCH 00/11] hw/mips/loongson3: Remove uses of &first_cpu global Philippe Mathieu-Daudé
                   ` (7 preceding siblings ...)
  2025-01-12 21:58 ` [PATCH 08/11] hw/mips/loongson3_bootp: Propagate processor_id to init_cpu_info() Philippe Mathieu-Daudé
@ 2025-01-12 21:58 ` Philippe Mathieu-Daudé
  2025-01-15  5:16   ` Richard Henderson
  2025-01-12 21:58 ` [PATCH 10/11] hw/mips/loongson3_virt: Propagate %processor_id to init_boot_param() Philippe Mathieu-Daudé
  2025-01-12 21:58 ` [PATCH 11/11] hw/mips/loongson3_bootp: Move to common_ss[] Philippe Mathieu-Daudé
  10 siblings, 1 reply; 25+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-12 21:58 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, Huacai Chen, Jiaxun Yang

Remove one &first_cpu use in hw/mips/loongson3_bootp.c.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/mips/loongson3_bootp.h | 2 +-
 hw/mips/loongson3_bootp.c | 5 ++---
 hw/mips/loongson3_virt.c  | 1 +
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/hw/mips/loongson3_bootp.h b/hw/mips/loongson3_bootp.h
index ee6340e42c1..9dc325a8557 100644
--- a/hw/mips/loongson3_bootp.h
+++ b/hw/mips/loongson3_bootp.h
@@ -233,7 +233,7 @@ enum {
 
 extern const MemMapEntry virt_memmap[];
 void init_loongson_params(struct loongson_params *lp, void *p,
-                          uint32_t cpu_count,
+                          uint32_t cpu_count, uint32_t processor_id,
                           uint64_t cpu_freq, uint64_t ram_size);
 void init_reset_system(struct efi_reset_system_t *reset);
 
diff --git a/hw/mips/loongson3_bootp.c b/hw/mips/loongson3_bootp.c
index 1aab26df69e..67812666c5b 100644
--- a/hw/mips/loongson3_bootp.c
+++ b/hw/mips/loongson3_bootp.c
@@ -23,7 +23,6 @@
 #include "qemu/cutils.h"
 #include "qemu/bswap.h"
 #include "exec/hwaddr.h"
-#include "cpu.h"
 #include "hw/mips/loongson3_bootp.h"
 
 static void init_cpu_info(void *g_cpuinfo, uint32_t cpu_count,
@@ -112,10 +111,10 @@ static void init_special_info(void *g_special)
 }
 
 void init_loongson_params(struct loongson_params *lp, void *p,
-                          uint32_t cpu_count,
+                          uint32_t cpu_count, uint32_t processor_id,
                           uint64_t cpu_freq, uint64_t ram_size)
 {
-    init_cpu_info(p, MIPS_CPU(first_cpu)->env.CP0_PRid, cpu_count, cpu_freq);
+    init_cpu_info(p, cpu_count, processor_id, cpu_freq);
     lp->cpu_offset = cpu_to_le64((uintptr_t)p - (uintptr_t)lp);
     p += ROUND_UP(sizeof(struct efi_cpuinfo_loongson), 64);
 
diff --git a/hw/mips/loongson3_virt.c b/hw/mips/loongson3_virt.c
index a240662016b..45cd348c14e 100644
--- a/hw/mips/loongson3_virt.c
+++ b/hw/mips/loongson3_virt.c
@@ -185,6 +185,7 @@ static void init_boot_param(unsigned cpu_count)
     init_reset_system(&(bp->reset_system));
     p += ROUND_UP(sizeof(struct boot_params), 64);
     init_loongson_params(&(bp->efi.smbios.lp), p, cpu_count,
+                         MIPS_CPU(first_cpu)->env.CP0_PRid,
                          loaderparams.cpu_freq, loaderparams.ram_size);
 
     rom_add_blob_fixed("params_rom", bp,
-- 
2.47.1



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 10/11] hw/mips/loongson3_virt: Propagate %processor_id to init_boot_param()
  2025-01-12 21:58 [PATCH 00/11] hw/mips/loongson3: Remove uses of &first_cpu global Philippe Mathieu-Daudé
                   ` (8 preceding siblings ...)
  2025-01-12 21:58 ` [PATCH 09/11] hw/mips/loongson3_virt: Propagate processor_id to init_loongson_params() Philippe Mathieu-Daudé
@ 2025-01-12 21:58 ` Philippe Mathieu-Daudé
  2025-01-15  5:17   ` Richard Henderson
  2025-01-12 21:58 ` [PATCH 11/11] hw/mips/loongson3_bootp: Move to common_ss[] Philippe Mathieu-Daudé
  10 siblings, 1 reply; 25+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-12 21:58 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, Huacai Chen, Jiaxun Yang

Propagate %processor_id from mips_loongson3_virt_init() where
we have a reference to the first vCPU, so use it instead of
the &first_cpu global.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/mips/loongson3_virt.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/hw/mips/loongson3_virt.c b/hw/mips/loongson3_virt.c
index 45cd348c14e..59b1619df0c 100644
--- a/hw/mips/loongson3_virt.c
+++ b/hw/mips/loongson3_virt.c
@@ -173,7 +173,7 @@ static uint64_t get_cpu_freq_hz(const MIPSCPU *cpu)
     return DEF_LOONGSON3_FREQ;
 }
 
-static void init_boot_param(unsigned cpu_count)
+static void init_boot_param(unsigned cpu_count, uint32_t processor_id)
 {
     static void *p;
     struct boot_params *bp;
@@ -184,8 +184,7 @@ static void init_boot_param(unsigned cpu_count)
     bp->efi.smbios.vers = cpu_to_le16(1);
     init_reset_system(&(bp->reset_system));
     p += ROUND_UP(sizeof(struct boot_params), 64);
-    init_loongson_params(&(bp->efi.smbios.lp), p, cpu_count,
-                         MIPS_CPU(first_cpu)->env.CP0_PRid,
+    init_loongson_params(&(bp->efi.smbios.lp), p, cpu_count, processor_id,
                          loaderparams.cpu_freq, loaderparams.ram_size);
 
     rom_add_blob_fixed("params_rom", bp,
@@ -645,7 +644,7 @@ static void mips_loongson3_virt_init(MachineState *machine)
         loaderparams.kernel_entry = load_kernel(&cpus[0]->env);
 
         init_boot_rom();
-        init_boot_param(machine->smp.cpus);
+        init_boot_param(machine->smp.cpus, cpus[0]->env.CP0_PRid);
     } else {
         filename = qemu_find_file(QEMU_FILE_TYPE_BIOS,
                                   machine->firmware ?: LOONGSON3_BIOSNAME);
-- 
2.47.1



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH 11/11] hw/mips/loongson3_bootp: Move to common_ss[]
  2025-01-12 21:58 [PATCH 00/11] hw/mips/loongson3: Remove uses of &first_cpu global Philippe Mathieu-Daudé
                   ` (9 preceding siblings ...)
  2025-01-12 21:58 ` [PATCH 10/11] hw/mips/loongson3_virt: Propagate %processor_id to init_boot_param() Philippe Mathieu-Daudé
@ 2025-01-12 21:58 ` Philippe Mathieu-Daudé
  2025-01-15  5:17   ` Richard Henderson
  10 siblings, 1 reply; 25+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-12 21:58 UTC (permalink / raw)
  To: qemu-devel; +Cc: Philippe Mathieu-Daudé, Huacai Chen, Jiaxun Yang

loongson3_bootp.c doesn't contain any target-specific code
and can be build generically, move it to common_ss[].

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/mips/meson.build | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/hw/mips/meson.build b/hw/mips/meson.build
index fcbee53bb32..31dbd2bf4d9 100644
--- a/hw/mips/meson.build
+++ b/hw/mips/meson.build
@@ -1,7 +1,8 @@
 mips_ss = ss.source_set()
 mips_ss.add(files('bootloader.c', 'mips_int.c'))
 common_ss.add(when: 'CONFIG_FW_CFG_MIPS', if_true: files('fw_cfg.c'))
-mips_ss.add(when: 'CONFIG_LOONGSON3V', if_true: files('loongson3_bootp.c', 'loongson3_virt.c'))
+common_ss.add(when: 'CONFIG_LOONGSON3V', if_true: files('loongson3_bootp.c'))
+mips_ss.add(when: 'CONFIG_LOONGSON3V', if_true: files('loongson3_virt.c'))
 mips_ss.add(when: 'CONFIG_MALTA', if_true: files('malta.c'))
 mips_ss.add(when: 'CONFIG_MIPS_CPS', if_true: files('cps.c'))
 
-- 
2.47.1



^ permalink raw reply related	[flat|nested] 25+ messages in thread

* Re: [PATCH 01/11] hw/mips/loongson3_virt: Factor generic_cpu_reset() out
  2025-01-12 21:58 ` [PATCH 01/11] hw/mips/loongson3_virt: Factor generic_cpu_reset() out Philippe Mathieu-Daudé
@ 2025-01-15  5:02   ` Richard Henderson
  0 siblings, 0 replies; 25+ messages in thread
From: Richard Henderson @ 2025-01-15  5:02 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel; +Cc: Huacai Chen, Jiaxun Yang

On 1/12/25 13:58, Philippe Mathieu-Daudé wrote:
> main_cpu_reset() is misleadingly named "main": it resets
> all vCPUs, with a special case for the first vCPU.
> 
> Factor generic_cpu_reset() out of main_cpu_reset(),
> allowing to remove one &first_cpu use.
> 
> Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org>
> ---
>   hw/mips/loongson3_virt.c | 26 +++++++++++++++++---------
>   1 file changed, 17 insertions(+), 9 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 03/11] hw/mips/loongson3_virt: Have fw_conf_init() access local loaderparams
  2025-01-12 21:58 ` [PATCH 03/11] hw/mips/loongson3_virt: Have fw_conf_init() access local loaderparams Philippe Mathieu-Daudé
@ 2025-01-15  5:09   ` Richard Henderson
  0 siblings, 0 replies; 25+ messages in thread
From: Richard Henderson @ 2025-01-15  5:09 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel; +Cc: Huacai Chen, Jiaxun Yang

On 1/12/25 13:58, Philippe Mathieu-Daudé wrote:
> 'loaderparams' is declared statically. Let fw_conf_init()
> access its 'cpu_freq' and 'ram_size' fields.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   hw/mips/loongson3_virt.c | 12 ++++++------
>   1 file changed, 6 insertions(+), 6 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 04/11] hw/mips/loongson3_virt: Pass CPU argument to get_cpu_freq_hz()
  2025-01-12 21:58 ` [PATCH 04/11] hw/mips/loongson3_virt: Pass CPU argument to get_cpu_freq_hz() Philippe Mathieu-Daudé
@ 2025-01-15  5:09   ` Richard Henderson
  0 siblings, 0 replies; 25+ messages in thread
From: Richard Henderson @ 2025-01-15  5:09 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel; +Cc: Huacai Chen, Jiaxun Yang

On 1/12/25 13:58, Philippe Mathieu-Daudé wrote:
> Pass the first vCPU as argument, allowing to remove
> another &first_cpu global use.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   hw/mips/loongson3_virt.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 05/11] hw/mips/loongson3_bootp: Include missing headers
  2025-01-12 21:58 ` [PATCH 05/11] hw/mips/loongson3_bootp: Include missing headers Philippe Mathieu-Daudé
@ 2025-01-15  5:10   ` Richard Henderson
  0 siblings, 0 replies; 25+ messages in thread
From: Richard Henderson @ 2025-01-15  5:10 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel; +Cc: Huacai Chen, Jiaxun Yang

On 1/12/25 13:58, Philippe Mathieu-Daudé wrote:
> MemMapEntry is declared in "exec/hwaddr.h", cpu_to_le32() in
> "qemu/bswap.h". These headers are indirectly included via "cpu.h".
> Include them explicitly in order to avoid when removing "cpu.h":
> 
>    In file included from ../../hw/mips/loongson3_bootp.c:27:
>    hw/mips/loongson3_bootp.h:234:14: error: unknown type name 'MemMapEntry'
>      234 | extern const MemMapEntry virt_memmap[];
>          |              ^
>    hw/mips/loongson3_bootp.c:33:18: error: call to undeclared function 'cpu_to_le32'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
>       33 |     c->cputype = cpu_to_le32(Loongson_3A);
>          |                  ^
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   hw/mips/loongson3_bootp.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/hw/mips/loongson3_bootp.c b/hw/mips/loongson3_bootp.c
> index b97b81903b7..712439c2575 100644
> --- a/hw/mips/loongson3_bootp.c
> +++ b/hw/mips/loongson3_bootp.c
> @@ -21,6 +21,8 @@
>   #include "qemu/osdep.h"
>   #include "qemu/units.h"
>   #include "qemu/cutils.h"
> +#include "qemu/bswap.h"
> +#include "exec/hwaddr.h"
>   #include "cpu.h"
>   #include "hw/boards.h"
>   #include "hw/mips/loongson3_bootp.h"

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 06/11] hw/mips/loongson3: Propagate cpu_count to init_loongson_params()
  2025-01-12 21:58 ` [PATCH 06/11] hw/mips/loongson3: Propagate cpu_count to init_loongson_params() Philippe Mathieu-Daudé
@ 2025-01-15  5:13   ` Richard Henderson
  0 siblings, 0 replies; 25+ messages in thread
From: Richard Henderson @ 2025-01-15  5:13 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel; +Cc: Huacai Chen, Jiaxun Yang

On 1/12/25 13:58, Philippe Mathieu-Daudé wrote:
> Propagate the %cpu_count from the machine file, allowing
> to remove the "hw/boards.h" dependency (which is machine
> specific) from loongson3_bootp.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   hw/mips/loongson3_bootp.h |  1 +
>   hw/mips/loongson3_bootp.c | 11 ++++++-----
>   hw/mips/loongson3_virt.c  |  1 +
>   3 files changed, 8 insertions(+), 5 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 07/11] hw/mips/loongson3_virt: Propagate cpu_count to init_boot_param()
  2025-01-12 21:58 ` [PATCH 07/11] hw/mips/loongson3_virt: Propagate cpu_count to init_boot_param() Philippe Mathieu-Daudé
@ 2025-01-15  5:13   ` Richard Henderson
  0 siblings, 0 replies; 25+ messages in thread
From: Richard Henderson @ 2025-01-15  5:13 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel; +Cc: Huacai Chen, Jiaxun Yang

On 1/12/25 13:58, Philippe Mathieu-Daudé wrote:
> Remove one use of the 'current_machine' global.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   hw/mips/loongson3_virt.c | 7 +++----
>   1 file changed, 3 insertions(+), 4 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~

> 
> diff --git a/hw/mips/loongson3_virt.c b/hw/mips/loongson3_virt.c
> index af1937455b0..a240662016b 100644
> --- a/hw/mips/loongson3_virt.c
> +++ b/hw/mips/loongson3_virt.c
> @@ -173,7 +173,7 @@ static uint64_t get_cpu_freq_hz(const MIPSCPU *cpu)
>       return DEF_LOONGSON3_FREQ;
>   }
>   
> -static void init_boot_param(void)
> +static void init_boot_param(unsigned cpu_count)
>   {
>       static void *p;
>       struct boot_params *bp;
> @@ -184,8 +184,7 @@ static void init_boot_param(void)
>       bp->efi.smbios.vers = cpu_to_le16(1);
>       init_reset_system(&(bp->reset_system));
>       p += ROUND_UP(sizeof(struct boot_params), 64);
> -    init_loongson_params(&(bp->efi.smbios.lp), p,
> -                         current_machine->smp.cpus,
> +    init_loongson_params(&(bp->efi.smbios.lp), p, cpu_count,
>                            loaderparams.cpu_freq, loaderparams.ram_size);
>   
>       rom_add_blob_fixed("params_rom", bp,
> @@ -645,7 +644,7 @@ static void mips_loongson3_virt_init(MachineState *machine)
>           loaderparams.kernel_entry = load_kernel(&cpus[0]->env);
>   
>           init_boot_rom();
> -        init_boot_param();
> +        init_boot_param(machine->smp.cpus);
>       } else {
>           filename = qemu_find_file(QEMU_FILE_TYPE_BIOS,
>                                     machine->firmware ?: LOONGSON3_BIOSNAME);



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 08/11] hw/mips/loongson3_bootp: Propagate processor_id to init_cpu_info()
  2025-01-12 21:58 ` [PATCH 08/11] hw/mips/loongson3_bootp: Propagate processor_id to init_cpu_info() Philippe Mathieu-Daudé
@ 2025-01-15  5:15   ` Richard Henderson
  0 siblings, 0 replies; 25+ messages in thread
From: Richard Henderson @ 2025-01-15  5:15 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel; +Cc: Huacai Chen, Jiaxun Yang

On 1/12/25 13:58, Philippe Mathieu-Daudé wrote:
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   hw/mips/loongson3_bootp.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 09/11] hw/mips/loongson3_virt: Propagate processor_id to init_loongson_params()
  2025-01-12 21:58 ` [PATCH 09/11] hw/mips/loongson3_virt: Propagate processor_id to init_loongson_params() Philippe Mathieu-Daudé
@ 2025-01-15  5:16   ` Richard Henderson
  0 siblings, 0 replies; 25+ messages in thread
From: Richard Henderson @ 2025-01-15  5:16 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel; +Cc: Huacai Chen, Jiaxun Yang

On 1/12/25 13:58, Philippe Mathieu-Daudé wrote:
> Remove one &first_cpu use in hw/mips/loongson3_bootp.c.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   hw/mips/loongson3_bootp.h | 2 +-
>   hw/mips/loongson3_bootp.c | 5 ++---
>   hw/mips/loongson3_virt.c  | 1 +
>   3 files changed, 4 insertions(+), 4 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 10/11] hw/mips/loongson3_virt: Propagate %processor_id to init_boot_param()
  2025-01-12 21:58 ` [PATCH 10/11] hw/mips/loongson3_virt: Propagate %processor_id to init_boot_param() Philippe Mathieu-Daudé
@ 2025-01-15  5:17   ` Richard Henderson
  0 siblings, 0 replies; 25+ messages in thread
From: Richard Henderson @ 2025-01-15  5:17 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel; +Cc: Huacai Chen, Jiaxun Yang

On 1/12/25 13:58, Philippe Mathieu-Daudé wrote:
> Propagate %processor_id from mips_loongson3_virt_init() where
> we have a reference to the first vCPU, so use it instead of
> the &first_cpu global.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   hw/mips/loongson3_virt.c | 7 +++----
>   1 file changed, 3 insertions(+), 4 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 11/11] hw/mips/loongson3_bootp: Move to common_ss[]
  2025-01-12 21:58 ` [PATCH 11/11] hw/mips/loongson3_bootp: Move to common_ss[] Philippe Mathieu-Daudé
@ 2025-01-15  5:17   ` Richard Henderson
  0 siblings, 0 replies; 25+ messages in thread
From: Richard Henderson @ 2025-01-15  5:17 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel; +Cc: Huacai Chen, Jiaxun Yang

On 1/12/25 13:58, Philippe Mathieu-Daudé wrote:
> loongson3_bootp.c doesn't contain any target-specific code
> and can be build generically, move it to common_ss[].
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   hw/mips/meson.build | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/mips/meson.build b/hw/mips/meson.build
> index fcbee53bb32..31dbd2bf4d9 100644
> --- a/hw/mips/meson.build
> +++ b/hw/mips/meson.build
> @@ -1,7 +1,8 @@
>   mips_ss = ss.source_set()
>   mips_ss.add(files('bootloader.c', 'mips_int.c'))
>   common_ss.add(when: 'CONFIG_FW_CFG_MIPS', if_true: files('fw_cfg.c'))
> -mips_ss.add(when: 'CONFIG_LOONGSON3V', if_true: files('loongson3_bootp.c', 'loongson3_virt.c'))
> +common_ss.add(when: 'CONFIG_LOONGSON3V', if_true: files('loongson3_bootp.c'))
> +mips_ss.add(when: 'CONFIG_LOONGSON3V', if_true: files('loongson3_virt.c'))
>   mips_ss.add(when: 'CONFIG_MALTA', if_true: files('malta.c'))
>   mips_ss.add(when: 'CONFIG_MIPS_CPS', if_true: files('cps.c'))
>   

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 02/11] hw/mips/loongson3_virt: Keep reference of vCPUs in machine_init()
  2025-01-12 21:58 ` [PATCH 02/11] hw/mips/loongson3_virt: Keep reference of vCPUs in machine_init() Philippe Mathieu-Daudé
@ 2025-01-15  5:18   ` Richard Henderson
  2025-01-15 20:32     ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 25+ messages in thread
From: Richard Henderson @ 2025-01-15  5:18 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel; +Cc: Huacai Chen, Jiaxun Yang

On 1/12/25 13:58, Philippe Mathieu-Daudé wrote:
> Keep references of all vCPUs created. That allows
> to directly access the first vCPU without using the
> &first_cpu global.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   hw/mips/loongson3_virt.c | 9 +++++----
>   1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/mips/loongson3_virt.c b/hw/mips/loongson3_virt.c
> index 47d112981a2..4b19941c1dc 100644
> --- a/hw/mips/loongson3_virt.c
> +++ b/hw/mips/loongson3_virt.c
> @@ -492,9 +492,8 @@ static void mips_loongson3_virt_init(MachineState *machine)
>   {
>       int i;
>       long bios_size;
> -    MIPSCPU *cpu;
> +    g_autofree MIPSCPU **cpus = NULL;
>       Clock *cpuclk;
> -    CPUMIPSState *env;
>       DeviceState *liointc;
>       DeviceState *ipi = NULL;
>       char *filename;
> @@ -569,13 +568,16 @@ static void mips_loongson3_virt_init(MachineState *machine)
>       cpuclk = clock_new(OBJECT(machine), "cpu-refclk");
>       clock_set_hz(cpuclk, DEF_LOONGSON3_FREQ);
>   
> +    cpus = g_new(MIPSCPU *, machine->smp.cpus);
>       for (i = 0; i < machine->smp.cpus; i++) {
> +        MIPSCPU *cpu;
>           int node = i / LOONGSON3_CORE_PER_NODE;
>           int core = i % LOONGSON3_CORE_PER_NODE;
>           int ip;
>   
>           /* init CPUs */
>           cpu = mips_cpu_create_with_clock(machine->cpu_type, cpuclk, false);
> +        cpus[i] = cpu;
>   
>           /* Init internal devices */
>           cpu_mips_irq_init_cpu(cpu);
> @@ -609,7 +611,6 @@ static void mips_loongson3_virt_init(MachineState *machine)
>                                  pin, cpu->env.irq[ip + 2]);
>           }
>       }
> -    env = &MIPS_CPU(first_cpu)->env;
>   
>       /* Allocate RAM/BIOS, 0x00000000~0x10000000 is alias of 0x80000000~0x90000000 */
>       memory_region_init_rom(bios, NULL, "loongson3.bios",
> @@ -640,7 +641,7 @@ static void mips_loongson3_virt_init(MachineState *machine)
>           loaderparams.kernel_filename = kernel_filename;
>           loaderparams.kernel_cmdline = kernel_cmdline;
>           loaderparams.initrd_filename = initrd_filename;
> -        loaderparams.kernel_entry = load_kernel(env);
> +        loaderparams.kernel_entry = load_kernel(&cpus[0]->env);
We only ever use cpu[0].  We don't really need the whole array.


r~


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH 02/11] hw/mips/loongson3_virt: Keep reference of vCPUs in machine_init()
  2025-01-15  5:18   ` Richard Henderson
@ 2025-01-15 20:32     ` Philippe Mathieu-Daudé
  2025-01-15 23:02       ` Richard Henderson
  0 siblings, 1 reply; 25+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-15 20:32 UTC (permalink / raw)
  To: Richard Henderson, qemu-devel; +Cc: Huacai Chen, Jiaxun Yang

On 15/1/25 06:18, Richard Henderson wrote:
> On 1/12/25 13:58, Philippe Mathieu-Daudé wrote:
>> Keep references of all vCPUs created. That allows
>> to directly access the first vCPU without using the
>> &first_cpu global.
>>
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>> ---
>>   hw/mips/loongson3_virt.c | 9 +++++----
>>   1 file changed, 5 insertions(+), 4 deletions(-)
>>
>> diff --git a/hw/mips/loongson3_virt.c b/hw/mips/loongson3_virt.c
>> index 47d112981a2..4b19941c1dc 100644
>> --- a/hw/mips/loongson3_virt.c
>> +++ b/hw/mips/loongson3_virt.c
>> @@ -492,9 +492,8 @@ static void mips_loongson3_virt_init(MachineState 
>> *machine)
>>   {
>>       int i;
>>       long bios_size;
>> -    MIPSCPU *cpu;
>> +    g_autofree MIPSCPU **cpus = NULL;
>>       Clock *cpuclk;
>> -    CPUMIPSState *env;
>>       DeviceState *liointc;
>>       DeviceState *ipi = NULL;
>>       char *filename;
>> @@ -569,13 +568,16 @@ static void 
>> mips_loongson3_virt_init(MachineState *machine)
>>       cpuclk = clock_new(OBJECT(machine), "cpu-refclk");
>>       clock_set_hz(cpuclk, DEF_LOONGSON3_FREQ);
>> +    cpus = g_new(MIPSCPU *, machine->smp.cpus);
>>       for (i = 0; i < machine->smp.cpus; i++) {
>> +        MIPSCPU *cpu;
>>           int node = i / LOONGSON3_CORE_PER_NODE;
>>           int core = i % LOONGSON3_CORE_PER_NODE;
>>           int ip;
>>           /* init CPUs */
>>           cpu = mips_cpu_create_with_clock(machine->cpu_type, cpuclk, 
>> false);
>> +        cpus[i] = cpu;
>>           /* Init internal devices */
>>           cpu_mips_irq_init_cpu(cpu);
>> @@ -609,7 +611,6 @@ static void mips_loongson3_virt_init(MachineState 
>> *machine)
>>                                  pin, cpu->env.irq[ip + 2]);
>>           }
>>       }
>> -    env = &MIPS_CPU(first_cpu)->env;
>>       /* Allocate RAM/BIOS, 0x00000000~0x10000000 is alias of 
>> 0x80000000~0x90000000 */
>>       memory_region_init_rom(bios, NULL, "loongson3.bios",
>> @@ -640,7 +641,7 @@ static void mips_loongson3_virt_init(MachineState 
>> *machine)
>>           loaderparams.kernel_filename = kernel_filename;
>>           loaderparams.kernel_cmdline = kernel_cmdline;
>>           loaderparams.initrd_filename = initrd_filename;
>> -        loaderparams.kernel_entry = load_kernel(env);
>> +        loaderparams.kernel_entry = load_kernel(&cpus[0]->env);

> We only ever use cpu[0].  We don't really need the whole array.

Yes. What about:

-- >8 --
commit ffc8c8873c0c102457f0e660437874555b022cc2
Author: Philippe Mathieu-Daudé <philmd@linaro.org>
Date:   Sun Jan 12 21:01:24 2025 +0100

     hw/mips/loongson3_virt: Invert vCPU creation order to remove &first_cpu

     Create vCPUs from the last one to the first one.
     No need to use the &first_cpu global since we already
     have it referenced.

     Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>

diff --git a/hw/mips/loongson3_virt.c b/hw/mips/loongson3_virt.c
index 47d112981a2..488eba495cd 100644
--- a/hw/mips/loongson3_virt.c
+++ b/hw/mips/loongson3_virt.c
@@ -496,3 +496,2 @@ static void mips_loongson3_virt_init(MachineState 
*machine)
      Clock *cpuclk;
-    CPUMIPSState *env;
      DeviceState *liointc;
@@ -571,3 +570,3 @@ static void mips_loongson3_virt_init(MachineState 
*machine)

-    for (i = 0; i < machine->smp.cpus; i++) {
+    for (i = machine->smp.cpus - 1; i >= 0; --i) {
          int node = i / LOONGSON3_CORE_PER_NODE;
@@ -611,3 +610,2 @@ static void mips_loongson3_virt_init(MachineState 
*machine)
      }
-    env = &MIPS_CPU(first_cpu)->env;

@@ -642,3 +640,3 @@ static void mips_loongson3_virt_init(MachineState 
*machine)
          loaderparams.initrd_filename = initrd_filename;
-        loaderparams.kernel_entry = load_kernel(env);
+        loaderparams.kernel_entry = load_kernel(&cpu->env);

---


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* Re: [PATCH 02/11] hw/mips/loongson3_virt: Keep reference of vCPUs in machine_init()
  2025-01-15 20:32     ` Philippe Mathieu-Daudé
@ 2025-01-15 23:02       ` Richard Henderson
  0 siblings, 0 replies; 25+ messages in thread
From: Richard Henderson @ 2025-01-15 23:02 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel; +Cc: Huacai Chen, Jiaxun Yang

On 1/15/25 12:32, Philippe Mathieu-Daudé wrote:
> On 15/1/25 06:18, Richard Henderson wrote:
>> On 1/12/25 13:58, Philippe Mathieu-Daudé wrote:
>>> Keep references of all vCPUs created. That allows
>>> to directly access the first vCPU without using the
>>> &first_cpu global.
>>>
>>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>>> ---
>>>   hw/mips/loongson3_virt.c | 9 +++++----
>>>   1 file changed, 5 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/hw/mips/loongson3_virt.c b/hw/mips/loongson3_virt.c
>>> index 47d112981a2..4b19941c1dc 100644
>>> --- a/hw/mips/loongson3_virt.c
>>> +++ b/hw/mips/loongson3_virt.c
>>> @@ -492,9 +492,8 @@ static void mips_loongson3_virt_init(MachineState *machine)
>>>   {
>>>       int i;
>>>       long bios_size;
>>> -    MIPSCPU *cpu;
>>> +    g_autofree MIPSCPU **cpus = NULL;
>>>       Clock *cpuclk;
>>> -    CPUMIPSState *env;
>>>       DeviceState *liointc;
>>>       DeviceState *ipi = NULL;
>>>       char *filename;
>>> @@ -569,13 +568,16 @@ static void mips_loongson3_virt_init(MachineState *machine)
>>>       cpuclk = clock_new(OBJECT(machine), "cpu-refclk");
>>>       clock_set_hz(cpuclk, DEF_LOONGSON3_FREQ);
>>> +    cpus = g_new(MIPSCPU *, machine->smp.cpus);
>>>       for (i = 0; i < machine->smp.cpus; i++) {
>>> +        MIPSCPU *cpu;
>>>           int node = i / LOONGSON3_CORE_PER_NODE;
>>>           int core = i % LOONGSON3_CORE_PER_NODE;
>>>           int ip;
>>>           /* init CPUs */
>>>           cpu = mips_cpu_create_with_clock(machine->cpu_type, cpuclk, false);
>>> +        cpus[i] = cpu;
>>>           /* Init internal devices */
>>>           cpu_mips_irq_init_cpu(cpu);
>>> @@ -609,7 +611,6 @@ static void mips_loongson3_virt_init(MachineState *machine)
>>>                                  pin, cpu->env.irq[ip + 2]);
>>>           }
>>>       }
>>> -    env = &MIPS_CPU(first_cpu)->env;
>>>       /* Allocate RAM/BIOS, 0x00000000~0x10000000 is alias of 0x80000000~0x90000000 */
>>>       memory_region_init_rom(bios, NULL, "loongson3.bios",
>>> @@ -640,7 +641,7 @@ static void mips_loongson3_virt_init(MachineState *machine)
>>>           loaderparams.kernel_filename = kernel_filename;
>>>           loaderparams.kernel_cmdline = kernel_cmdline;
>>>           loaderparams.initrd_filename = initrd_filename;
>>> -        loaderparams.kernel_entry = load_kernel(env);
>>> +        loaderparams.kernel_entry = load_kernel(&cpus[0]->env);
> 
>> We only ever use cpu[0].  We don't really need the whole array.
> 
> Yes. What about:
> 
> -- >8 --
> commit ffc8c8873c0c102457f0e660437874555b022cc2
> Author: Philippe Mathieu-Daudé <philmd@linaro.org>
> Date:   Sun Jan 12 21:01:24 2025 +0100
> 
>      hw/mips/loongson3_virt: Invert vCPU creation order to remove &first_cpu
> 
>      Create vCPUs from the last one to the first one.
>      No need to use the &first_cpu global since we already
>      have it referenced.
> 
>      Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> 
> diff --git a/hw/mips/loongson3_virt.c b/hw/mips/loongson3_virt.c
> index 47d112981a2..488eba495cd 100644
> --- a/hw/mips/loongson3_virt.c
> +++ b/hw/mips/loongson3_virt.c
> @@ -496,3 +496,2 @@ static void mips_loongson3_virt_init(MachineState *machine)
>       Clock *cpuclk;
> -    CPUMIPSState *env;
>       DeviceState *liointc;
> @@ -571,3 +570,3 @@ static void mips_loongson3_virt_init(MachineState *machine)
> 
> -    for (i = 0; i < machine->smp.cpus; i++) {
> +    for (i = machine->smp.cpus - 1; i >= 0; --i) {
>           int node = i / LOONGSON3_CORE_PER_NODE;
> @@ -611,3 +610,2 @@ static void mips_loongson3_virt_init(MachineState *machine)
>       }
> -    env = &MIPS_CPU(first_cpu)->env;
> 
> @@ -642,3 +640,3 @@ static void mips_loongson3_virt_init(MachineState *machine)
>           loaderparams.initrd_filename = initrd_filename;
> -        loaderparams.kernel_entry = load_kernel(env);
> +        loaderparams.kernel_entry = load_kernel(&cpu->env);
> 
> ---

Looks good, thanks.


r~


^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2025-01-15 23:03 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-12 21:58 [PATCH 00/11] hw/mips/loongson3: Remove uses of &first_cpu global Philippe Mathieu-Daudé
2025-01-12 21:58 ` [PATCH 01/11] hw/mips/loongson3_virt: Factor generic_cpu_reset() out Philippe Mathieu-Daudé
2025-01-15  5:02   ` Richard Henderson
2025-01-12 21:58 ` [PATCH 02/11] hw/mips/loongson3_virt: Keep reference of vCPUs in machine_init() Philippe Mathieu-Daudé
2025-01-15  5:18   ` Richard Henderson
2025-01-15 20:32     ` Philippe Mathieu-Daudé
2025-01-15 23:02       ` Richard Henderson
2025-01-12 21:58 ` [PATCH 03/11] hw/mips/loongson3_virt: Have fw_conf_init() access local loaderparams Philippe Mathieu-Daudé
2025-01-15  5:09   ` Richard Henderson
2025-01-12 21:58 ` [PATCH 04/11] hw/mips/loongson3_virt: Pass CPU argument to get_cpu_freq_hz() Philippe Mathieu-Daudé
2025-01-15  5:09   ` Richard Henderson
2025-01-12 21:58 ` [PATCH 05/11] hw/mips/loongson3_bootp: Include missing headers Philippe Mathieu-Daudé
2025-01-15  5:10   ` Richard Henderson
2025-01-12 21:58 ` [PATCH 06/11] hw/mips/loongson3: Propagate cpu_count to init_loongson_params() Philippe Mathieu-Daudé
2025-01-15  5:13   ` Richard Henderson
2025-01-12 21:58 ` [PATCH 07/11] hw/mips/loongson3_virt: Propagate cpu_count to init_boot_param() Philippe Mathieu-Daudé
2025-01-15  5:13   ` Richard Henderson
2025-01-12 21:58 ` [PATCH 08/11] hw/mips/loongson3_bootp: Propagate processor_id to init_cpu_info() Philippe Mathieu-Daudé
2025-01-15  5:15   ` Richard Henderson
2025-01-12 21:58 ` [PATCH 09/11] hw/mips/loongson3_virt: Propagate processor_id to init_loongson_params() Philippe Mathieu-Daudé
2025-01-15  5:16   ` Richard Henderson
2025-01-12 21:58 ` [PATCH 10/11] hw/mips/loongson3_virt: Propagate %processor_id to init_boot_param() Philippe Mathieu-Daudé
2025-01-15  5:17   ` Richard Henderson
2025-01-12 21:58 ` [PATCH 11/11] hw/mips/loongson3_bootp: Move to common_ss[] Philippe Mathieu-Daudé
2025-01-15  5:17   ` Richard Henderson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).