1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (c) 2021 Western Digital Corporation or its affiliates.
6 * Atish Patra <atish.patra@wdc.com>
9 #ifndef __RISCV_KVM_VCPU_SBI_H__
10 #define __RISCV_KVM_VCPU_SBI_H__
12 #define KVM_SBI_IMPID 3
14 #define KVM_SBI_VERSION_MAJOR 1
15 #define KVM_SBI_VERSION_MINOR 0
17 struct kvm_vcpu_sbi_context {
19 bool extension_disabled[KVM_RISCV_SBI_EXT_MAX];
22 struct kvm_vcpu_sbi_return {
23 unsigned long out_val;
24 unsigned long err_val;
25 struct kvm_cpu_trap *utrap;
29 struct kvm_vcpu_sbi_extension {
30 unsigned long extid_start;
31 unsigned long extid_end;
33 * SBI extension handler. It can be defined for a given extension or group of
34 * extension. But it should always return linux error codes rather than SBI
35 * specific error codes.
37 int (*handler)(struct kvm_vcpu *vcpu, struct kvm_run *run,
38 struct kvm_vcpu_sbi_return *retdata);
40 /* Extension specific probe function */
41 unsigned long (*probe)(struct kvm_vcpu *vcpu);
44 void kvm_riscv_vcpu_sbi_forward(struct kvm_vcpu *vcpu, struct kvm_run *run);
45 void kvm_riscv_vcpu_sbi_system_reset(struct kvm_vcpu *vcpu,
48 int kvm_riscv_vcpu_sbi_return(struct kvm_vcpu *vcpu, struct kvm_run *run);
49 int kvm_riscv_vcpu_set_reg_sbi_ext(struct kvm_vcpu *vcpu,
50 const struct kvm_one_reg *reg);
51 int kvm_riscv_vcpu_get_reg_sbi_ext(struct kvm_vcpu *vcpu,
52 const struct kvm_one_reg *reg);
53 const struct kvm_vcpu_sbi_extension *kvm_vcpu_sbi_find_ext(
54 struct kvm_vcpu *vcpu, unsigned long extid);
55 int kvm_riscv_vcpu_sbi_ecall(struct kvm_vcpu *vcpu, struct kvm_run *run);
57 #ifdef CONFIG_RISCV_SBI_V01
58 extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_v01;
60 extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_base;
61 extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_time;
62 extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_ipi;
63 extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_rfence;
64 extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_srst;
65 extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_hsm;
66 extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_experimental;
67 extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_vendor;
69 #endif /* __RISCV_KVM_VCPU_SBI_H__ */