xref: /linux/arch/riscv/include/asm/kvm_vcpu_sbi.h (revision 4b96679170c63be361d1b0fdeb81bb0ef207dbcb)
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 enum kvm_riscv_sbi_ext_status {
18 	KVM_RISCV_SBI_EXT_UNINITIALIZED,
19 	KVM_RISCV_SBI_EXT_AVAILABLE,
20 	KVM_RISCV_SBI_EXT_UNAVAILABLE,
21 };
22 
23 struct kvm_vcpu_sbi_context {
24 	int return_handled;
25 	enum kvm_riscv_sbi_ext_status ext_status[KVM_RISCV_SBI_EXT_MAX];
26 };
27 
28 struct kvm_vcpu_sbi_return {
29 	unsigned long out_val;
30 	unsigned long err_val;
31 	struct kvm_cpu_trap *utrap;
32 	bool uexit;
33 };
34 
35 struct kvm_vcpu_sbi_extension {
36 	unsigned long extid_start;
37 	unsigned long extid_end;
38 	/**
39 	 * SBI extension handler. It can be defined for a given extension or group of
40 	 * extension. But it should always return linux error codes rather than SBI
41 	 * specific error codes.
42 	 */
43 	int (*handler)(struct kvm_vcpu *vcpu, struct kvm_run *run,
44 		       struct kvm_vcpu_sbi_return *retdata);
45 
46 	/* Extension specific probe function */
47 	unsigned long (*probe)(struct kvm_vcpu *vcpu);
48 };
49 
50 void kvm_riscv_vcpu_sbi_forward(struct kvm_vcpu *vcpu, struct kvm_run *run);
51 void kvm_riscv_vcpu_sbi_system_reset(struct kvm_vcpu *vcpu,
52 				     struct kvm_run *run,
53 				     u32 type, u64 flags);
54 int kvm_riscv_vcpu_sbi_return(struct kvm_vcpu *vcpu, struct kvm_run *run);
55 int kvm_riscv_vcpu_set_reg_sbi_ext(struct kvm_vcpu *vcpu,
56 				   const struct kvm_one_reg *reg);
57 int kvm_riscv_vcpu_get_reg_sbi_ext(struct kvm_vcpu *vcpu,
58 				   const struct kvm_one_reg *reg);
59 const struct kvm_vcpu_sbi_extension *kvm_vcpu_sbi_find_ext(
60 				struct kvm_vcpu *vcpu, unsigned long extid);
61 int kvm_riscv_vcpu_sbi_ecall(struct kvm_vcpu *vcpu, struct kvm_run *run);
62 
63 #ifdef CONFIG_RISCV_SBI_V01
64 extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_v01;
65 #endif
66 extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_base;
67 extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_time;
68 extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_ipi;
69 extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_rfence;
70 extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_srst;
71 extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_hsm;
72 extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_experimental;
73 extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_vendor;
74 
75 #ifdef CONFIG_RISCV_PMU_SBI
76 extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_pmu;
77 #endif
78 #endif /* __RISCV_KVM_VCPU_SBI_H__ */
79