Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

RISC-V: KVM: selftests: Add guest_sbi_probe_extension

Add guest_sbi_probe_extension(), allowing guest code to probe for
SBI extensions. As guest_sbi_probe_extension() needs
SBI_ERR_NOT_SUPPORTED, take the opportunity to bring in all SBI
error codes. We don't bring in all current extension IDs or base
extension function IDs though, even though we need one of each,
because we'd prefer to bring those in as necessary.

Reviewed-by: Anup Patel <anup@brainfault.org>
Reviewed-by: Atish Patra <atishp@rivosinc.com>
Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
Signed-off-by: Anup Patel <anup@brainfault.org>

authored by

Andrew Jones and committed by
Anup Patel
945d880d 0dcab5c4

+40
+21
tools/testing/selftests/kvm/include/riscv/processor.h
··· 108 108 #define SATP_ASID_SHIFT 44 109 109 #define SATP_ASID_MASK _AC(0xFFFF, UL) 110 110 111 + /* SBI return error codes */ 112 + #define SBI_SUCCESS 0 113 + #define SBI_ERR_FAILURE -1 114 + #define SBI_ERR_NOT_SUPPORTED -2 115 + #define SBI_ERR_INVALID_PARAM -3 116 + #define SBI_ERR_DENIED -4 117 + #define SBI_ERR_INVALID_ADDRESS -5 118 + #define SBI_ERR_ALREADY_AVAILABLE -6 119 + #define SBI_ERR_ALREADY_STARTED -7 120 + #define SBI_ERR_ALREADY_STOPPED -8 121 + 111 122 #define SBI_EXT_EXPERIMENTAL_START 0x08000000 112 123 #define SBI_EXT_EXPERIMENTAL_END 0x08FFFFFF 113 124 114 125 #define KVM_RISCV_SELFTESTS_SBI_EXT SBI_EXT_EXPERIMENTAL_END 115 126 #define KVM_RISCV_SELFTESTS_SBI_UCALL 0 116 127 #define KVM_RISCV_SELFTESTS_SBI_UNEXP 1 128 + 129 + enum sbi_ext_id { 130 + SBI_EXT_BASE = 0x10, 131 + }; 132 + 133 + enum sbi_ext_base_fid { 134 + SBI_EXT_BASE_PROBE_EXT = 3, 135 + }; 117 136 118 137 struct sbiret { 119 138 long error; ··· 143 124 unsigned long arg1, unsigned long arg2, 144 125 unsigned long arg3, unsigned long arg4, 145 126 unsigned long arg5); 127 + 128 + bool guest_sbi_probe_extension(int extid, long *out_val); 146 129 147 130 #endif /* SELFTEST_KVM_PROCESSOR_H */
+19
tools/testing/selftests/kvm/lib/riscv/processor.c
··· 393 393 394 394 return ret; 395 395 } 396 + 397 + bool guest_sbi_probe_extension(int extid, long *out_val) 398 + { 399 + struct sbiret ret; 400 + 401 + ret = sbi_ecall(SBI_EXT_BASE, SBI_EXT_BASE_PROBE_EXT, extid, 402 + 0, 0, 0, 0, 0); 403 + 404 + __GUEST_ASSERT(!ret.error || ret.error == SBI_ERR_NOT_SUPPORTED, 405 + "ret.error=%ld, ret.value=%ld\n", ret.error, ret.value); 406 + 407 + if (ret.error == SBI_ERR_NOT_SUPPORTED) 408 + return false; 409 + 410 + if (out_val) 411 + *out_val = ret.value; 412 + 413 + return true; 414 + }