xref: /openbmc/linux/arch/powerpc/kvm/booke.h (revision b830f94f)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  *
4  * Copyright IBM Corp. 2008
5  *
6  * Authors: Hollis Blanchard <hollisb@us.ibm.com>
7  */
8 
9 #ifndef __KVM_BOOKE_H__
10 #define __KVM_BOOKE_H__
11 
12 #include <linux/types.h>
13 #include <linux/kvm_host.h>
14 #include <asm/kvm_ppc.h>
15 #include <asm/switch_to.h>
16 #include "timing.h"
17 
18 /* interrupt priortity ordering */
19 #define BOOKE_IRQPRIO_DATA_STORAGE 0
20 #define BOOKE_IRQPRIO_INST_STORAGE 1
21 #define BOOKE_IRQPRIO_ALIGNMENT 2
22 #define BOOKE_IRQPRIO_PROGRAM 3
23 #define BOOKE_IRQPRIO_FP_UNAVAIL 4
24 #ifdef CONFIG_SPE_POSSIBLE
25 #define BOOKE_IRQPRIO_SPE_UNAVAIL 5
26 #define BOOKE_IRQPRIO_SPE_FP_DATA 6
27 #define BOOKE_IRQPRIO_SPE_FP_ROUND 7
28 #endif
29 #ifdef CONFIG_PPC_E500MC
30 #define BOOKE_IRQPRIO_ALTIVEC_UNAVAIL 5
31 #define BOOKE_IRQPRIO_ALTIVEC_ASSIST 6
32 #endif
33 #define BOOKE_IRQPRIO_SYSCALL 8
34 #define BOOKE_IRQPRIO_AP_UNAVAIL 9
35 #define BOOKE_IRQPRIO_DTLB_MISS 10
36 #define BOOKE_IRQPRIO_ITLB_MISS 11
37 #define BOOKE_IRQPRIO_MACHINE_CHECK 12
38 #define BOOKE_IRQPRIO_DEBUG 13
39 #define BOOKE_IRQPRIO_CRITICAL 14
40 #define BOOKE_IRQPRIO_WATCHDOG 15
41 #define BOOKE_IRQPRIO_EXTERNAL 16
42 #define BOOKE_IRQPRIO_FIT 17
43 #define BOOKE_IRQPRIO_DECREMENTER 18
44 #define BOOKE_IRQPRIO_PERFORMANCE_MONITOR 19
45 /* Internal pseudo-irqprio for level triggered externals */
46 #define BOOKE_IRQPRIO_EXTERNAL_LEVEL 20
47 #define BOOKE_IRQPRIO_DBELL 21
48 #define BOOKE_IRQPRIO_DBELL_CRIT 22
49 #define BOOKE_IRQPRIO_MAX 23
50 
51 #define BOOKE_IRQMASK_EE ((1 << BOOKE_IRQPRIO_EXTERNAL_LEVEL) | \
52 			  (1 << BOOKE_IRQPRIO_PERFORMANCE_MONITOR) | \
53 			  (1 << BOOKE_IRQPRIO_DBELL) | \
54 			  (1 << BOOKE_IRQPRIO_DECREMENTER) | \
55 			  (1 << BOOKE_IRQPRIO_FIT) | \
56 			  (1 << BOOKE_IRQPRIO_EXTERNAL))
57 
58 #define BOOKE_IRQMASK_CE ((1 << BOOKE_IRQPRIO_DBELL_CRIT) | \
59 			  (1 << BOOKE_IRQPRIO_WATCHDOG) | \
60 			  (1 << BOOKE_IRQPRIO_CRITICAL))
61 
62 extern unsigned long kvmppc_booke_handlers;
63 extern unsigned long kvmppc_booke_handler_addr[];
64 
65 void kvmppc_set_msr(struct kvm_vcpu *vcpu, u32 new_msr);
66 void kvmppc_mmu_msr_notify(struct kvm_vcpu *vcpu, u32 old_msr);
67 
68 void kvmppc_set_epcr(struct kvm_vcpu *vcpu, u32 new_epcr);
69 void kvmppc_set_tcr(struct kvm_vcpu *vcpu, u32 new_tcr);
70 void kvmppc_set_tsr_bits(struct kvm_vcpu *vcpu, u32 tsr_bits);
71 void kvmppc_clr_tsr_bits(struct kvm_vcpu *vcpu, u32 tsr_bits);
72 
73 int kvmppc_booke_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,
74                             unsigned int inst, int *advance);
75 int kvmppc_booke_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val);
76 int kvmppc_booke_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val);
77 
78 /* low-level asm code to transfer guest state */
79 void kvmppc_load_guest_spe(struct kvm_vcpu *vcpu);
80 void kvmppc_save_guest_spe(struct kvm_vcpu *vcpu);
81 
82 /* high-level function, manages flags, host state */
83 void kvmppc_vcpu_disable_spe(struct kvm_vcpu *vcpu);
84 
85 void kvmppc_booke_vcpu_load(struct kvm_vcpu *vcpu, int cpu);
86 void kvmppc_booke_vcpu_put(struct kvm_vcpu *vcpu);
87 
88 enum int_class {
89 	INT_CLASS_NONCRIT,
90 	INT_CLASS_CRIT,
91 	INT_CLASS_MC,
92 	INT_CLASS_DBG,
93 };
94 
95 void kvmppc_set_pending_interrupt(struct kvm_vcpu *vcpu, enum int_class type);
96 
97 extern void kvmppc_mmu_destroy_e500(struct kvm_vcpu *vcpu);
98 extern int kvmppc_core_emulate_op_e500(struct kvm_run *run,
99 				       struct kvm_vcpu *vcpu,
100 				       unsigned int inst, int *advance);
101 extern int kvmppc_core_emulate_mtspr_e500(struct kvm_vcpu *vcpu, int sprn,
102 					  ulong spr_val);
103 extern int kvmppc_core_emulate_mfspr_e500(struct kvm_vcpu *vcpu, int sprn,
104 					  ulong *spr_val);
105 extern void kvmppc_mmu_destroy_e500(struct kvm_vcpu *vcpu);
106 extern int kvmppc_core_emulate_op_e500(struct kvm_run *run,
107 				       struct kvm_vcpu *vcpu,
108 				       unsigned int inst, int *advance);
109 extern int kvmppc_core_emulate_mtspr_e500(struct kvm_vcpu *vcpu, int sprn,
110 					  ulong spr_val);
111 extern int kvmppc_core_emulate_mfspr_e500(struct kvm_vcpu *vcpu, int sprn,
112 					  ulong *spr_val);
113 
114 static inline void kvmppc_clear_dbsr(void)
115 {
116 	mtspr(SPRN_DBSR, mfspr(SPRN_DBSR));
117 }
118 #endif /* __KVM_BOOKE_H__ */
119