1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /**
3  * Copyright (c) 2021 Western Digital Corporation or its affiliates.
4  *
5  * Authors:
6  *     Atish Patra <atish.patra@wdc.com>
7  */
8 
9 #ifndef __RISCV_KVM_VCPU_SBI_H__
10 #define __RISCV_KVM_VCPU_SBI_H__
11 
12 #define KVM_SBI_IMPID 3
13 
14 #define KVM_SBI_VERSION_MAJOR 1
15 #define KVM_SBI_VERSION_MINOR 0
16 
17 struct kvm_vcpu_sbi_context {
18 	int return_handled;
19 };
20 
21 struct kvm_vcpu_sbi_extension {
22 	unsigned long extid_start;
23 	unsigned long extid_end;
24 	/**
25 	 * SBI extension handler. It can be defined for a given extension or group of
26 	 * extension. But it should always return linux error codes rather than SBI
27 	 * specific error codes.
28 	 */
29 	int (*handler)(struct kvm_vcpu *vcpu, struct kvm_run *run,
30 		       unsigned long *out_val, struct kvm_cpu_trap *utrap,
31 		       bool *exit);
32 };
33 
34 void kvm_riscv_vcpu_sbi_forward(struct kvm_vcpu *vcpu, struct kvm_run *run);
35 void kvm_riscv_vcpu_sbi_system_reset(struct kvm_vcpu *vcpu,
36 				     struct kvm_run *run,
37 				     u32 type, u64 flags);
38 int kvm_riscv_vcpu_sbi_return(struct kvm_vcpu *vcpu, struct kvm_run *run);
39 const struct kvm_vcpu_sbi_extension *kvm_vcpu_sbi_find_ext(unsigned long extid);
40 int kvm_riscv_vcpu_sbi_ecall(struct kvm_vcpu *vcpu, struct kvm_run *run);
41 
42 #ifdef CONFIG_RISCV_SBI_V01
43 extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_v01;
44 #endif
45 extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_base;
46 extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_time;
47 extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_ipi;
48 extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_rfence;
49 extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_srst;
50 extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_hsm;
51 extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_experimental;
52 extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_vendor;
53 
54 #endif /* __RISCV_KVM_VCPU_SBI_H__ */
55