Skip to content

Commit 945d880

Browse files
Andrew Jonesavpatel
authored andcommitted
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>
1 parent 0dcab5c commit 945d880

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

tools/testing/selftests/kvm/include/riscv/processor.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,32 @@ static inline uint64_t __kvm_reg_id(uint64_t type, uint64_t subtype,
108108
#define SATP_ASID_SHIFT 44
109109
#define SATP_ASID_MASK _AC(0xFFFF, UL)
110110

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+
111122
#define SBI_EXT_EXPERIMENTAL_START 0x08000000
112123
#define SBI_EXT_EXPERIMENTAL_END 0x08FFFFFF
113124

114125
#define KVM_RISCV_SELFTESTS_SBI_EXT SBI_EXT_EXPERIMENTAL_END
115126
#define KVM_RISCV_SELFTESTS_SBI_UCALL 0
116127
#define KVM_RISCV_SELFTESTS_SBI_UNEXP 1
117128

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+
};
136+
118137
struct sbiret {
119138
long error;
120139
long value;
@@ -125,4 +144,6 @@ struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0,
125144
unsigned long arg3, unsigned long arg4,
126145
unsigned long arg5);
127146

147+
bool guest_sbi_probe_extension(int extid, long *out_val);
148+
128149
#endif /* SELFTEST_KVM_PROCESSOR_H */

tools/testing/selftests/kvm/lib/riscv/processor.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,3 +393,22 @@ struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0,
393393

394394
return ret;
395395
}
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+
}

0 commit comments

Comments
 (0)