Commit 812806bd authored by Haibo Xu's avatar Haibo Xu Committed by Anup Patel

KVM: riscv: selftests: Change vcpu_has_ext to a common function

Move vcpu_has_ext to the processor.c and rename it to __vcpu_has_ext
so that other test cases can use it for vCPU extension check.
Signed-off-by: default avatarHaibo Xu <haibo1.xu@intel.com>
Reviewed-by: default avatarAndrew Jones <ajones@ventanamicro.com>
Signed-off-by: default avatarAnup Patel <anup@brainfault.org>
parent 1e979288
...@@ -48,6 +48,8 @@ static inline uint64_t __kvm_reg_id(uint64_t type, uint64_t subtype, ...@@ -48,6 +48,8 @@ static inline uint64_t __kvm_reg_id(uint64_t type, uint64_t subtype,
KVM_REG_RISCV_SBI_SINGLE, \ KVM_REG_RISCV_SBI_SINGLE, \
idx, KVM_REG_SIZE_ULONG) idx, KVM_REG_SIZE_ULONG)
bool __vcpu_has_ext(struct kvm_vcpu *vcpu, uint64_t ext);
struct ex_regs { struct ex_regs {
unsigned long ra; unsigned long ra;
unsigned long sp; unsigned long sp;
......
...@@ -15,6 +15,16 @@ ...@@ -15,6 +15,16 @@
static vm_vaddr_t exception_handlers; static vm_vaddr_t exception_handlers;
bool __vcpu_has_ext(struct kvm_vcpu *vcpu, uint64_t ext)
{
unsigned long value = 0;
int ret;
ret = __vcpu_get_reg(vcpu, ext, &value);
return !ret && !!value;
}
static uint64_t page_align(struct kvm_vm *vm, uint64_t v) static uint64_t page_align(struct kvm_vm *vm, uint64_t v)
{ {
return (v + vm->page_size) & ~(vm->page_size - 1); return (v + vm->page_size) & ~(vm->page_size - 1);
......
...@@ -123,15 +123,6 @@ bool check_reject_set(int err) ...@@ -123,15 +123,6 @@ bool check_reject_set(int err)
return err == EINVAL; return err == EINVAL;
} }
static bool vcpu_has_ext(struct kvm_vcpu *vcpu, uint64_t ext_id)
{
int ret;
unsigned long value;
ret = __vcpu_get_reg(vcpu, ext_id, &value);
return (ret) ? false : !!value;
}
void finalize_vcpu(struct kvm_vcpu *vcpu, struct vcpu_reg_list *c) void finalize_vcpu(struct kvm_vcpu *vcpu, struct vcpu_reg_list *c)
{ {
unsigned long isa_ext_state[KVM_RISCV_ISA_EXT_MAX] = { 0 }; unsigned long isa_ext_state[KVM_RISCV_ISA_EXT_MAX] = { 0 };
...@@ -176,7 +167,7 @@ void finalize_vcpu(struct kvm_vcpu *vcpu, struct vcpu_reg_list *c) ...@@ -176,7 +167,7 @@ void finalize_vcpu(struct kvm_vcpu *vcpu, struct vcpu_reg_list *c)
__vcpu_set_reg(vcpu, feature, 1); __vcpu_set_reg(vcpu, feature, 1);
/* Double check whether the desired extension was enabled */ /* Double check whether the desired extension was enabled */
__TEST_REQUIRE(vcpu_has_ext(vcpu, feature), __TEST_REQUIRE(__vcpu_has_ext(vcpu, feature),
"%s not available, skipping tests", s->name); "%s not available, skipping tests", s->name);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment