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

Missing review: #2

Since v1:
- Reworked patch 2 (rth)

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: Invert vCPU creation order to remove
    &first_cpu
  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  | 54 ++++++++++++++++++++++-----------------
 hw/mips/meson.build       |  3 ++-
 4 files changed, 42 insertions(+), 32 deletions(-)

-- 
2.47.1



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

* [PATCH v2 01/11] hw/mips/loongson3_virt: Factor generic_cpu_reset() out
  2025-01-15 23:29 [PATCH v2 00/11] hw/mips/loongson3: Remove uses of &first_cpu global Philippe Mathieu-Daudé
@ 2025-01-15 23:29 ` Philippe Mathieu-Daudé
  2025-01-15 23:29 ` [PATCH v2 02/11] hw/mips/loongson3_virt: Invert vCPU creation order to remove &first_cpu Philippe Mathieu-Daudé
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-15 23:29 UTC (permalink / raw)
  To: qemu-devel
  Cc: Jiaxun Yang, Philippe Mathieu-Daudé, Huacai Chen,
	Richard Henderson

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>
Reviewed-by: Richard Henderson <richard.henderson@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] 14+ messages in thread

* [PATCH v2 02/11] hw/mips/loongson3_virt: Invert vCPU creation order to remove &first_cpu
  2025-01-15 23:29 [PATCH v2 00/11] hw/mips/loongson3: Remove uses of &first_cpu global Philippe Mathieu-Daudé
  2025-01-15 23:29 ` [PATCH v2 01/11] hw/mips/loongson3_virt: Factor generic_cpu_reset() out Philippe Mathieu-Daudé
@ 2025-01-15 23:29 ` Philippe Mathieu-Daudé
  2025-01-16 17:35   ` Richard Henderson
  2025-01-15 23:29 ` [PATCH v2 03/11] hw/mips/loongson3_virt: Have fw_conf_init() access local loaderparams Philippe Mathieu-Daudé
                   ` (9 subsequent siblings)
  11 siblings, 1 reply; 14+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-15 23:29 UTC (permalink / raw)
  To: qemu-devel; +Cc: Jiaxun Yang, Philippe Mathieu-Daudé, Huacai Chen

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>
---
 hw/mips/loongson3_virt.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

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
@@ -494,7 +494,6 @@ static void mips_loongson3_virt_init(MachineState *machine)
     long bios_size;
     MIPSCPU *cpu;
     Clock *cpuclk;
-    CPUMIPSState *env;
     DeviceState *liointc;
     DeviceState *ipi = NULL;
     char *filename;
@@ -569,7 +568,7 @@ static void mips_loongson3_virt_init(MachineState *machine)
     cpuclk = clock_new(OBJECT(machine), "cpu-refclk");
     clock_set_hz(cpuclk, DEF_LOONGSON3_FREQ);
 
-    for (i = 0; i < machine->smp.cpus; i++) {
+    for (i = machine->smp.cpus - 1; i >= 0; --i) {
         int node = i / LOONGSON3_CORE_PER_NODE;
         int core = i % LOONGSON3_CORE_PER_NODE;
         int ip;
@@ -609,7 +608,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 +638,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(&cpu->env);
 
         init_boot_rom();
         init_boot_param();
-- 
2.47.1



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

* [PATCH v2 03/11] hw/mips/loongson3_virt: Have fw_conf_init() access local loaderparams
  2025-01-15 23:29 [PATCH v2 00/11] hw/mips/loongson3: Remove uses of &first_cpu global Philippe Mathieu-Daudé
  2025-01-15 23:29 ` [PATCH v2 01/11] hw/mips/loongson3_virt: Factor generic_cpu_reset() out Philippe Mathieu-Daudé
  2025-01-15 23:29 ` [PATCH v2 02/11] hw/mips/loongson3_virt: Invert vCPU creation order to remove &first_cpu Philippe Mathieu-Daudé
@ 2025-01-15 23:29 ` Philippe Mathieu-Daudé
  2025-01-15 23:29 ` [PATCH v2 04/11] hw/mips/loongson3_virt: Pass CPU argument to get_cpu_freq_hz() Philippe Mathieu-Daudé
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-15 23:29 UTC (permalink / raw)
  To: qemu-devel
  Cc: Jiaxun Yang, Philippe Mathieu-Daudé, Huacai Chen,
	Richard Henderson

'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>
Reviewed-by: Richard Henderson <richard.henderson@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 488eba495cd..1f5952d7082 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));
@@ -632,9 +632,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;
@@ -660,7 +660,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] 14+ messages in thread

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

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

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@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 1f5952d7082..9c2001295d1 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;
         }
@@ -632,7 +632,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] 14+ messages in thread

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

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>
Reviewed-by: Richard Henderson <richard.henderson@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] 14+ messages in thread

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

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>
Reviewed-by: Richard Henderson <richard.henderson@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 9c2001295d1..93700a1612e 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] 14+ messages in thread

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

Remove one use of the 'current_machine' global.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@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 93700a1612e..46b298f6d72 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,
@@ -642,7 +641,7 @@ static void mips_loongson3_virt_init(MachineState *machine)
         loaderparams.kernel_entry = load_kernel(&cpu->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] 14+ messages in thread

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

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@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] 14+ messages in thread

* [PATCH v2 09/11] hw/mips/loongson3_virt: Propagate processor_id to init_loongson_params()
  2025-01-15 23:29 [PATCH v2 00/11] hw/mips/loongson3: Remove uses of &first_cpu global Philippe Mathieu-Daudé
                   ` (7 preceding siblings ...)
  2025-01-15 23:29 ` [PATCH v2 08/11] hw/mips/loongson3_bootp: Propagate processor_id to init_cpu_info() Philippe Mathieu-Daudé
@ 2025-01-15 23:29 ` Philippe Mathieu-Daudé
  2025-01-15 23:29 ` [PATCH v2 10/11] hw/mips/loongson3_virt: Propagate %processor_id to init_boot_param() Philippe Mathieu-Daudé
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-15 23:29 UTC (permalink / raw)
  To: qemu-devel
  Cc: Jiaxun Yang, Philippe Mathieu-Daudé, Huacai Chen,
	Richard Henderson

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

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@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 46b298f6d72..4924ea88eda 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] 14+ messages in thread

* [PATCH v2 10/11] hw/mips/loongson3_virt: Propagate %processor_id to init_boot_param()
  2025-01-15 23:29 [PATCH v2 00/11] hw/mips/loongson3: Remove uses of &first_cpu global Philippe Mathieu-Daudé
                   ` (8 preceding siblings ...)
  2025-01-15 23:29 ` [PATCH v2 09/11] hw/mips/loongson3_virt: Propagate processor_id to init_loongson_params() Philippe Mathieu-Daudé
@ 2025-01-15 23:29 ` Philippe Mathieu-Daudé
  2025-01-15 23:29 ` [PATCH v2 11/11] hw/mips/loongson3_bootp: Move to common_ss[] Philippe Mathieu-Daudé
  2025-01-31 18:08 ` [PATCH v2 00/11] hw/mips/loongson3: Remove uses of &first_cpu global Philippe Mathieu-Daudé
  11 siblings, 0 replies; 14+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-15 23:29 UTC (permalink / raw)
  To: qemu-devel
  Cc: Jiaxun Yang, Philippe Mathieu-Daudé, Huacai Chen,
	Richard Henderson

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>
Reviewed-by: Richard Henderson <richard.henderson@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 4924ea88eda..7d6369876ba 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,
@@ -642,7 +641,7 @@ static void mips_loongson3_virt_init(MachineState *machine)
         loaderparams.kernel_entry = load_kernel(&cpu->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] 14+ messages in thread

* [PATCH v2 11/11] hw/mips/loongson3_bootp: Move to common_ss[]
  2025-01-15 23:29 [PATCH v2 00/11] hw/mips/loongson3: Remove uses of &first_cpu global Philippe Mathieu-Daudé
                   ` (9 preceding siblings ...)
  2025-01-15 23:29 ` [PATCH v2 10/11] hw/mips/loongson3_virt: Propagate %processor_id to init_boot_param() Philippe Mathieu-Daudé
@ 2025-01-15 23:29 ` Philippe Mathieu-Daudé
  2025-01-31 18:08 ` [PATCH v2 00/11] hw/mips/loongson3: Remove uses of &first_cpu global Philippe Mathieu-Daudé
  11 siblings, 0 replies; 14+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-15 23:29 UTC (permalink / raw)
  To: qemu-devel
  Cc: Jiaxun Yang, Philippe Mathieu-Daudé, Huacai Chen,
	Richard Henderson

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>
Reviewed-by: Richard Henderson <richard.henderson@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] 14+ messages in thread

* Re: [PATCH v2 02/11] hw/mips/loongson3_virt: Invert vCPU creation order to remove &first_cpu
  2025-01-15 23:29 ` [PATCH v2 02/11] hw/mips/loongson3_virt: Invert vCPU creation order to remove &first_cpu Philippe Mathieu-Daudé
@ 2025-01-16 17:35   ` Richard Henderson
  0 siblings, 0 replies; 14+ messages in thread
From: Richard Henderson @ 2025-01-16 17:35 UTC (permalink / raw)
  To: qemu-devel

On 1/15/25 15:29, Philippe Mathieu-Daudé wrote:
> 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>
> ---
>   hw/mips/loongson3_virt.c | 6 ++----
>   1 file changed, 2 insertions(+), 4 deletions(-)

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

r~


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

* Re: [PATCH v2 00/11] hw/mips/loongson3: Remove uses of &first_cpu global
  2025-01-15 23:29 [PATCH v2 00/11] hw/mips/loongson3: Remove uses of &first_cpu global Philippe Mathieu-Daudé
                   ` (10 preceding siblings ...)
  2025-01-15 23:29 ` [PATCH v2 11/11] hw/mips/loongson3_bootp: Move to common_ss[] Philippe Mathieu-Daudé
@ 2025-01-31 18:08 ` Philippe Mathieu-Daudé
  11 siblings, 0 replies; 14+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-01-31 18:08 UTC (permalink / raw)
  To: qemu-devel; +Cc: Jiaxun Yang, Huacai Chen

On 16/1/25 00:29, Philippe Mathieu-Daudé wrote:

> Philippe Mathieu-Daudé (11):
>    hw/mips/loongson3_virt: Factor generic_cpu_reset() out
>    hw/mips/loongson3_virt: Invert vCPU creation order to remove
>      &first_cpu
>    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[]

Series queued, thanks.


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

end of thread, other threads:[~2025-01-31 18:08 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-15 23:29 [PATCH v2 00/11] hw/mips/loongson3: Remove uses of &first_cpu global Philippe Mathieu-Daudé
2025-01-15 23:29 ` [PATCH v2 01/11] hw/mips/loongson3_virt: Factor generic_cpu_reset() out Philippe Mathieu-Daudé
2025-01-15 23:29 ` [PATCH v2 02/11] hw/mips/loongson3_virt: Invert vCPU creation order to remove &first_cpu Philippe Mathieu-Daudé
2025-01-16 17:35   ` Richard Henderson
2025-01-15 23:29 ` [PATCH v2 03/11] hw/mips/loongson3_virt: Have fw_conf_init() access local loaderparams Philippe Mathieu-Daudé
2025-01-15 23:29 ` [PATCH v2 04/11] hw/mips/loongson3_virt: Pass CPU argument to get_cpu_freq_hz() Philippe Mathieu-Daudé
2025-01-15 23:29 ` [PATCH v2 05/11] hw/mips/loongson3_bootp: Include missing headers Philippe Mathieu-Daudé
2025-01-15 23:29 ` [PATCH v2 06/11] hw/mips/loongson3: Propagate cpu_count to init_loongson_params() Philippe Mathieu-Daudé
2025-01-15 23:29 ` [PATCH v2 07/11] hw/mips/loongson3_virt: Propagate cpu_count to init_boot_param() Philippe Mathieu-Daudé
2025-01-15 23:29 ` [PATCH v2 08/11] hw/mips/loongson3_bootp: Propagate processor_id to init_cpu_info() Philippe Mathieu-Daudé
2025-01-15 23:29 ` [PATCH v2 09/11] hw/mips/loongson3_virt: Propagate processor_id to init_loongson_params() Philippe Mathieu-Daudé
2025-01-15 23:29 ` [PATCH v2 10/11] hw/mips/loongson3_virt: Propagate %processor_id to init_boot_param() Philippe Mathieu-Daudé
2025-01-15 23:29 ` [PATCH v2 11/11] hw/mips/loongson3_bootp: Move to common_ss[] Philippe Mathieu-Daudé
2025-01-31 18:08 ` [PATCH v2 00/11] hw/mips/loongson3: Remove uses of &first_cpu global Philippe Mathieu-Daudé

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).