xref: /linux/arch/riscv/include/asm/kvm_vcpu_insn.h (revision 9f2c9170934eace462499ba0bfe042cc72900173)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (c) 2022 Ventana Micro Systems Inc.
4  */
5 
6 #ifndef __KVM_VCPU_RISCV_INSN_H
7 #define __KVM_VCPU_RISCV_INSN_H
8 
9 struct kvm_vcpu;
10 struct kvm_run;
11 struct kvm_cpu_trap;
12 
13 struct kvm_mmio_decode {
14 	unsigned long insn;
15 	int insn_len;
16 	int len;
17 	int shift;
18 	int return_handled;
19 };
20 
21 struct kvm_csr_decode {
22 	unsigned long insn;
23 	int return_handled;
24 };
25 
26 /* Return values used by function emulating a particular instruction */
27 enum kvm_insn_return {
28 	KVM_INSN_EXIT_TO_USER_SPACE = 0,
29 	KVM_INSN_CONTINUE_NEXT_SEPC,
30 	KVM_INSN_CONTINUE_SAME_SEPC,
31 	KVM_INSN_ILLEGAL_TRAP,
32 	KVM_INSN_VIRTUAL_TRAP
33 };
34 
35 void kvm_riscv_vcpu_wfi(struct kvm_vcpu *vcpu);
36 int kvm_riscv_vcpu_csr_return(struct kvm_vcpu *vcpu, struct kvm_run *run);
37 int kvm_riscv_vcpu_virtual_insn(struct kvm_vcpu *vcpu, struct kvm_run *run,
38 				struct kvm_cpu_trap *trap);
39 
40 int kvm_riscv_vcpu_mmio_load(struct kvm_vcpu *vcpu, struct kvm_run *run,
41 			     unsigned long fault_addr,
42 			     unsigned long htinst);
43 int kvm_riscv_vcpu_mmio_store(struct kvm_vcpu *vcpu, struct kvm_run *run,
44 			      unsigned long fault_addr,
45 			      unsigned long htinst);
46 int kvm_riscv_vcpu_mmio_return(struct kvm_vcpu *vcpu, struct kvm_run *run);
47 
48 #endif
49