target/loongarch: Use cpu_has_msgint() and FIELD_EX32 for cpucfg cpu_has_msgint() is more generic and can be used in TCG mode, so use it instead of the KVM-specific feature check.
The cpucfg register is 32 bits wide; use FIELD_EX32() rather than FIELD_EX64() when extracting its fields. Signed-off-by: Bibo Mao <[email protected]> Reviewed-by: Philippe Mathieu-Daudé <[email protected]> --- target/loongarch/cpu.h | 6 ++++++ target/loongarch/kvm/kvm.c | 11 ++--------- target/loongarch/machine.c | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h index 277fc4f475..8dae4e12cf 100644 --- a/target/loongarch/cpu.h +++ b/target/loongarch/cpu.h @@ -542,6 +542,12 @@ static inline bool is_va32(CPULoongArchState *env) return va32; } +static inline bool cpu_has_msgint(CPULoongArchState *env) +{ + + return FIELD_EX32(env->cpucfg[1], CPUCFG1, MSG_INT); +} + static inline void set_pc(CPULoongArchState *env, uint64_t value) { if (is_va32(env)) { diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c index db39267375..957e73eb02 100644 --- a/target/loongarch/kvm/kvm.c +++ b/target/loongarch/kvm/kvm.c @@ -36,13 +36,6 @@ const KVMCapabilityInfo kvm_arch_required_capabilities[] = { KVM_CAP_LAST_INFO }; -static bool kvm_cpu_has_msgint(CPUState *cs) -{ - LoongArchCPU *cpu = LOONGARCH_CPU(cs); - - return FIELD_EX64(cpu->env.cpucfg[1], CPUCFG1, MSG_INT); -} - static int kvm_get_stealtime(CPUState *cs) { CPULoongArchState *env = cpu_env(cs); @@ -374,7 +367,7 @@ static int kvm_loongarch_get_csr(CPUState *cs) * Since register CSR_ESTAT will sync software pending MSGINT status to * hardware register and modify HW CSR MSGIS registers. */ - if (kvm_cpu_has_msgint(cs)) { + if (cpu_has_msgint(env)) { ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_MSGIS(0)), &sys->CSR_MSGIS[0]); @@ -564,7 +557,7 @@ static int kvm_loongarch_put_csr(CPUState *cs, KvmPutState level) ret |= kvm_loongarch_put_pmu(cs); - if (kvm_cpu_has_msgint(cs)) { + if (cpu_has_msgint(env)) { ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_MSGIS(0)), &sys->CSR_MSGIS[0]); diff --git a/target/loongarch/machine.c b/target/loongarch/machine.c index 952c5497af..4acab2a4a3 100644 --- a/target/loongarch/machine.c +++ b/target/loongarch/machine.c @@ -49,7 +49,7 @@ static bool msgint_needed(void *opaque) { LoongArchCPU *cpu = opaque; - return FIELD_EX64(cpu->env.cpucfg[1], CPUCFG1, MSG_INT); + return cpu_has_msgint(&cpu->env); } static const VMStateDescription vmstate_msgint = { -- 2.54.0
