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 bool extension_disabled[KVM_RISCV_SBI_EXT_MAX]; 20 }; 21 22 struct kvm_vcpu_sbi_return { 23 unsigned long out_val; 24 unsigned long err_val; 25 struct kvm_cpu_trap *utrap; 26 bool uexit; 27 }; 28 29 struct kvm_vcpu_sbi_extension { 30 unsigned long extid_start; 31 unsigned long extid_end; 32 /** 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. 36 */ 37 int (*handler)(struct kvm_vcpu *vcpu, struct kvm_run *run, 38 struct kvm_vcpu_sbi_return *retdata); 39 40 /* Extension specific probe function */ 41 unsigned long (*probe)(struct kvm_vcpu *vcpu); 42 }; 43 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, 46 struct kvm_run *run, 47 u32 type, u64 flags); 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); 56 57 #ifdef CONFIG_RISCV_SBI_V01 58 extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_v01; 59 #endif 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; 68 69 #endif /* __RISCV_KVM_VCPU_SBI_H__ */ 70