target/loongarch/cpu.c | 4 ++-- target/loongarch/cpu.h | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-)
Define VM_LEVEL0 and VM_LEVELS for the available VM levels. Replace
set_sys_state(), which accepted a CPUSysState pointer, with set_sys(),
which selects a state by VM level. There is no function change in this
patch.
Signed-off-by: SignKirigami <prcups@krgm.moe>
---
This patch is a resend of [1], Sorry for wrongly handling Signed-off-by.
[1]: https://lists.gnu.org/archive/html/qemu-devel/2026-09/msg05968.html
target/loongarch/cpu.c | 4 ++--
target/loongarch/cpu.h | 7 +++++--
2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c
index c71531c1cf..9d944dcb29 100644
--- a/target/loongarch/cpu.c
+++ b/target/loongarch/cpu.c
@@ -304,7 +304,7 @@ static void loongarch_la464_initfn(Object *obj)
uint32_t data = 0, field;
int i;
- set_sys_state(env, &env->sys_states[0]);
+ set_sys(env, VM_LEVEL0);
for (i = 0; i < 21; i++) {
env->cpucfg[i] = 0x0;
}
@@ -433,7 +433,7 @@ static void loongarch_la132_initfn(Object *obj)
uint32_t data = 0;
int i;
- set_sys_state(env, &env->sys_states[0]);
+ set_sys(env, VM_LEVEL0);
for (i = 0; i < 21; i++) {
env->cpucfg[i] = 0x0;
}
diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h
index 477a5dee7d..c0edcc9065 100644
--- a/target/loongarch/cpu.h
+++ b/target/loongarch/cpu.h
@@ -321,6 +321,9 @@ typedef struct CPUTimerState {
CPUState *cs;
} CPUTimerState;
+#define VM_LEVEL0 0
+#define VM_LEVELS 1
+
#define CPU_VENDOR_LOONGSON "Loongson"
#define CPU_MODEL_3A5000 "3A5000"
#define CPU_MODEL_1C101 "1C101"
@@ -507,9 +510,9 @@ static inline CPUSysState *env_sys(CPULoongArchState *env)
return env->sys_state;
}
-static inline void set_sys_state(CPULoongArchState *env, CPUSysState *sys)
+static inline void set_sys(CPULoongArchState *env, int vm_level)
{
- env->sys_state = sys;
+ env->sys_state = &env->sys_states[vm_level];
}
static inline CPUSysState *get_sys(CPULoongArchState *env, int vm_level)
--
2.55.0
On 2026/9/20 上午10:43, SignKirigami wrote:
> Define VM_LEVEL0 and VM_LEVELS for the available VM levels. Replace
> set_sys_state(), which accepted a CPUSysState pointer, with set_sys(),
> which selects a state by VM level. There is no function change in this
> patch.
>
> Signed-off-by: SignKirigami <prcups@krgm.moe>
> ---
> This patch is a resend of [1], Sorry for wrongly handling Signed-off-by.
>
> [1]: https://lists.gnu.org/archive/html/qemu-devel/2026-09/msg05968.html
>
> target/loongarch/cpu.c | 4 ++--
> target/loongarch/cpu.h | 7 +++++--
> 2 files changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c
> index c71531c1cf..9d944dcb29 100644
> --- a/target/loongarch/cpu.c
> +++ b/target/loongarch/cpu.c
> @@ -304,7 +304,7 @@ static void loongarch_la464_initfn(Object *obj)
> uint32_t data = 0, field;
> int i;
>
> - set_sys_state(env, &env->sys_states[0]);
> + set_sys(env, VM_LEVEL0);
> for (i = 0; i < 21; i++) {
> env->cpucfg[i] = 0x0;
> }
> @@ -433,7 +433,7 @@ static void loongarch_la132_initfn(Object *obj)
> uint32_t data = 0;
> int i;
>
> - set_sys_state(env, &env->sys_states[0]);
> + set_sys(env, VM_LEVEL0);
> for (i = 0; i < 21; i++) {
> env->cpucfg[i] = 0x0;
> }
> diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h
> index 477a5dee7d..c0edcc9065 100644
> --- a/target/loongarch/cpu.h
> +++ b/target/loongarch/cpu.h
> @@ -321,6 +321,9 @@ typedef struct CPUTimerState {
> CPUState *cs;
> } CPUTimerState;
>
> +#define VM_LEVEL0 0
> +#define VM_LEVELS 1
> +
> #define CPU_VENDOR_LOONGSON "Loongson"
> #define CPU_MODEL_3A5000 "3A5000"
> #define CPU_MODEL_1C101 "1C101"
> @@ -507,9 +510,9 @@ static inline CPUSysState *env_sys(CPULoongArchState *env)
> return env->sys_state;
> }
>
> -static inline void set_sys_state(CPULoongArchState *env, CPUSysState *sys)
> +static inline void set_sys(CPULoongArchState *env, int vm_level)
> {
> - env->sys_state = sys;
> + env->sys_state = &env->sys_states[vm_level];
> }
>
> static inline CPUSysState *get_sys(CPULoongArchState *env, int vm_level)
>
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
© 2016 - 2026 Red Hat, Inc.