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_return { 22 unsigned long out_val; 23 unsigned long err_val; 24 struct kvm_cpu_trap *utrap; 25 bool uexit; 26 }; 27 28 struct kvm_vcpu_sbi_extension { 29 unsigned long extid_start; 30 unsigned long extid_end; 31 /** 32 * SBI extension handler. It can be defined for a given extension or group of 33 * extension. But it should always return linux error codes rather than SBI 34 * specific error codes. 35 */ 36 int (*handler)(struct kvm_vcpu *vcpu, struct kvm_run *run, 37 struct kvm_vcpu_sbi_return *retdata); 38 39 /* Extension specific probe function */ 40 unsigned long (*probe)(struct kvm_vcpu *vcpu); 41 }; 42 43 void kvm_riscv_vcpu_sbi_forward(struct kvm_vcpu *vcpu, struct kvm_run *run); 44 void kvm_riscv_vcpu_sbi_system_reset(struct kvm_vcpu *vcpu, 45 struct kvm_run *run, 46 u32 type, u64 flags); 47 int kvm_riscv_vcpu_sbi_return(struct kvm_vcpu *vcpu, struct kvm_run *run); 48 const struct kvm_vcpu_sbi_extension *kvm_vcpu_sbi_find_ext(unsigned long extid); 49 int kvm_riscv_vcpu_sbi_ecall(struct kvm_vcpu *vcpu, struct kvm_run *run); 50 51 #ifdef CONFIG_RISCV_SBI_V01 52 extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_v01; 53 #endif 54 extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_base; 55 extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_time; 56 extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_ipi; 57 extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_rfence; 58 extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_srst; 59 extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_hsm; 60 extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_experimental; 61 extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_vendor; 62 63 #endif /* __RISCV_KVM_VCPU_SBI_H__ */ 64