Add a separate guest timer and IRQ_VTIMER.

Signed-off-by: SignKirigami <[email protected]>
Signed-off-by: Hengyu Yu <[email protected]>
---
 target/loongarch/cpu.c | 8 +++++++-
 target/loongarch/cpu.h | 6 ++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c
index 5cef63a778..8e759a2987 100644
--- a/target/loongarch/cpu.c
+++ b/target/loongarch/cpu.c
@@ -770,7 +770,7 @@ static void loongarch_cpu_init(Object *obj)
     LoongArchCPU *cpu = LOONGARCH_CPU(obj);
 #ifdef CONFIG_TCG
     CPULoongArchState *env = &cpu->env;
-    CPUTimerState *timer;
+    CPUTimerState *timer, *guest_timer;
 #endif
 
     qdev_init_gpio_in(DEVICE(cpu), loongarch_cpu_set_irq, N_IRQS);
@@ -778,8 +778,14 @@ static void loongarch_cpu_init(Object *obj)
     timer = env_timer(env);
     timer->irq = IRQ_TIMER;
     timer->cs  = CPU(obj);
+    guest_timer = env_guest_timer(env);
+    guest_timer->irq = IRQ_VTIMER;
+    guest_timer->cs = CPU(obj);
+
     timer_init_ns(&timer->timer, QEMU_CLOCK_VIRTUAL,
                   &cpu_loongarch_timer_cb, timer);
+    timer_init_ns(&guest_timer->timer, QEMU_CLOCK_VIRTUAL,
+                  &cpu_loongarch_timer_cb, guest_timer);
 #endif
 #endif
 }
diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h
index 8939dbc748..ba28d80272 100644
--- a/target/loongarch/cpu.h
+++ b/target/loongarch/cpu.h
@@ -245,6 +245,7 @@ extern const char * const fregnames[32];
 #define IRQ_IPI     12
 #define INT_DMSI    14
 #define N_VIRQS     (N_IRQS * 2)
+#define IRQ_VTIMER  (N_IRQS + IRQ_TIMER)
 
 #define MAX_PERF_EVENTS        16
 #define LOONGARCH_STLB         2048 /* 2048 STLB */
@@ -577,6 +578,11 @@ static inline CPUTimerState *env_timer(CPULoongArchState 
*env)
     return &env->sys_states[0].timer_state;
 }
 
+static inline CPUTimerState *env_guest_timer(CPULoongArchState *env)
+{
+    return &env->sys_states[1].timer_state;
+}
+
 static inline bool is_la64(CPULoongArchState *env)
 {
     return FIELD_EX32(env->cpucfg[1], CPUCFG1, ARCH) == CPUCFG1_ARCH_LA64;
-- 
2.55.0


Reply via email to