
From: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com> virt inclusion category: feature bugzilla: https://gitee.com/openeuler/qemu/issues/IBSJV9 ------------------------------------------------------------------------ The register set represents a common minimum between HIP09、HIP10 and HIP12. We need to check the writable masks to verify whether we can actually update KVM with these new register values. Otherwise KVM set reg may fail later. Signed-off-by: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com> Signed-off-by: Jinqian Yang <yangjinqian1@huawei.com> --- target/arm/cpregs.h | 9 ++++++++ target/arm/cpu64.c | 5 +++++ target/arm/kunpeng920-regs.c | 42 ++++++++++++++++++++++++++++++++++++ target/arm/meson.build | 2 +- 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 target/arm/kunpeng920-regs.c diff --git a/target/arm/cpregs.h b/target/arm/cpregs.h index f1293d16c0..d0e34c2ae1 100644 --- a/target/arm/cpregs.h +++ b/target/arm/cpregs.h @@ -1077,6 +1077,15 @@ static inline void define_cortex_a72_a57_a53_cp_reginfo(ARMCPU *cpu) { } void define_cortex_a72_a57_a53_cp_reginfo(ARMCPU *cpu); #endif +#ifdef CONFIG_KVM +int kunpeng920_update_registers(ARMCPU *cpu); +#else +static inline int kunpeng920_update_registers(ARMCPU *cpu) +{ + return -EINVAL; +} +#endif + CPAccessResult access_tvm_trvm(CPUARMState *, const ARMCPRegInfo *, bool); #endif /* TARGET_ARM_CPREGS_H */ diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c index 69c3f5710e..6a03fa97bc 100644 --- a/target/arm/cpu64.c +++ b/target/arm/cpu64.c @@ -827,6 +827,11 @@ static void aarch64_kunpeng_920_initfn_hack(Object *obj) cpu->host_cpu_probe_failed = true; return; } + + if (kunpeng920_update_registers(cpu)) { + cpu->kvm_target = QEMU_KVM_ARM_TARGET_NONE; + return; + } } static const ARMCPUInfo aarch64_cpus[] = { diff --git a/target/arm/kunpeng920-regs.c b/target/arm/kunpeng920-regs.c new file mode 100644 index 0000000000..8a764a2011 --- /dev/null +++ b/target/arm/kunpeng920-regs.c @@ -0,0 +1,42 @@ +/* + * HiSilicon Kunpeng 920 registers + * + * This code is licensed under the GNU GPL v2 or later. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "cpu.h" +#include "cpregs.h" + +int kunpeng920_update_registers(ARMCPU *cpu) +{ + /* + * Check host is indeed a supported HiSilicon 920 platform and + * kernel supports writable ID reg. + * We now only supports HIP09 & HIP10 & HIP12. + */ + if ((cpu->midr != 0x480fd020 && cpu->midr != 0x480fd030 && + cpu->midr != 0x480fd060) || !cpu->writable_masks) { + return -EINVAL; + } + + /* + * Set a miniumum set of features between HIP09、HIP10 and HIP12. + * This is to enable migration between these two. + * We need to make use of writable_masks to check + * whether we can actually change the host returned values. + * If not, KVM write reg will fail later. + */ + cpu->isar.id_aa64pfr0 = 0x1101001121111111; + cpu->isar.id_aa64pfr1 = 0x21; + cpu->isar.id_aa64isar2 = 0; + cpu->isar.id_aa64mmfr1 = 0x110212122; + cpu->isar.id_aa64mmfr2 = 0x1221011110000010; + cpu->isar.id_aa64dfr0 = 0xf010305409; + cpu->isar.id_aa64zfr0 = 0x100000100000; + cpu->ctr = 0xb4448004; + + return 0; +} diff --git a/target/arm/meson.build b/target/arm/meson.build index 389ee54658..902602a93e 100644 --- a/target/arm/meson.build +++ b/target/arm/meson.build @@ -8,7 +8,7 @@ arm_ss.add(files( )) arm_ss.add(zlib) -arm_ss.add(when: 'CONFIG_KVM', if_true: files('hyp_gdbstub.c', 'kvm.c', 'kvm64.c'), if_false: files('kvm-stub.c')) +arm_ss.add(when: 'CONFIG_KVM', if_true: files('hyp_gdbstub.c', 'kvm.c', 'kvm64.c', 'kunpeng920-regs.c'), if_false: files('kvm-stub.c')) arm_ss.add(when: 'CONFIG_HVF', if_true: files('hyp_gdbstub.c')) arm_ss.add(when: 'CONFIG_KVM', if_true: files('kvm.c', 'kvm64.c', 'kvm-tmm.c'), if_false: files('kvm-stub.c')) -- 2.33.0