Skip to contentSkip to conversation

target/loongarch: select sys state by VM level

PATCH RESEND In review SignKirigami 2 participants 2 messages Sep 20

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 target/loongarch: select sys state by VM level

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.

---
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(-)
target/loongarch/cpu.c +2 -2
index c71531c1cf..9d944dcb29 100644
@@ -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;
     }
target/loongarch/cpu.h +5 -2
index 477a5dee7d..c0edcc9065 100644
@@ -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)
Signature · 1 line
2.55.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 54 lines · SignKirigami

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.

---
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(-)
target/loongarch/cpu.c +2 -2
index c71531c1cf..9d944dcb29 100644
@@ -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;
      }
target/loongarch/cpu.h +3 -0
index 477a5dee7d..c0edcc9065 100644
@@ -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;

target/loongarch/cpu.h static inline CPUSysState *env_sys(CPULoongArchState *env) · line 518

Quoted 10 lines
target/loongarch/cpu.h +2 -2
  }
 
-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)