xref: /openbmc/linux/arch/powerpc/kvm/booke.h (revision 8fae845f4956de0becc115e926d33eff46722e94)
175f74f0dSHollis Blanchard /*
275f74f0dSHollis Blanchard  * This program is free software; you can redistribute it and/or modify
375f74f0dSHollis Blanchard  * it under the terms of the GNU General Public License, version 2, as
475f74f0dSHollis Blanchard  * published by the Free Software Foundation.
575f74f0dSHollis Blanchard  *
675f74f0dSHollis Blanchard  * This program is distributed in the hope that it will be useful,
775f74f0dSHollis Blanchard  * but WITHOUT ANY WARRANTY; without even the implied warranty of
875f74f0dSHollis Blanchard  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
975f74f0dSHollis Blanchard  * GNU General Public License for more details.
1075f74f0dSHollis Blanchard  *
1175f74f0dSHollis Blanchard  * You should have received a copy of the GNU General Public License
1275f74f0dSHollis Blanchard  * along with this program; if not, write to the Free Software
1375f74f0dSHollis Blanchard  * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
1475f74f0dSHollis Blanchard  *
1575f74f0dSHollis Blanchard  * Copyright IBM Corp. 2008
1675f74f0dSHollis Blanchard  *
1775f74f0dSHollis Blanchard  * Authors: Hollis Blanchard <hollisb@us.ibm.com>
1875f74f0dSHollis Blanchard  */
1975f74f0dSHollis Blanchard 
2075f74f0dSHollis Blanchard #ifndef __KVM_BOOKE_H__
2175f74f0dSHollis Blanchard #define __KVM_BOOKE_H__
2275f74f0dSHollis Blanchard 
2375f74f0dSHollis Blanchard #include <linux/types.h>
2475f74f0dSHollis Blanchard #include <linux/kvm_host.h>
25d0c7dc03SHollis Blanchard #include <asm/kvm_ppc.h>
26*8fae845fSScott Wood #include <asm/switch_to.h>
2773e75b41SHollis Blanchard #include "timing.h"
2875f74f0dSHollis Blanchard 
29d4cf3892SHollis Blanchard /* interrupt priortity ordering */
30d4cf3892SHollis Blanchard #define BOOKE_IRQPRIO_DATA_STORAGE 0
31d4cf3892SHollis Blanchard #define BOOKE_IRQPRIO_INST_STORAGE 1
32d4cf3892SHollis Blanchard #define BOOKE_IRQPRIO_ALIGNMENT 2
33d4cf3892SHollis Blanchard #define BOOKE_IRQPRIO_PROGRAM 3
34d4cf3892SHollis Blanchard #define BOOKE_IRQPRIO_FP_UNAVAIL 4
35bb3a8a17SHollis Blanchard #define BOOKE_IRQPRIO_SPE_UNAVAIL 5
36bb3a8a17SHollis Blanchard #define BOOKE_IRQPRIO_SPE_FP_DATA 6
37bb3a8a17SHollis Blanchard #define BOOKE_IRQPRIO_SPE_FP_ROUND 7
38bb3a8a17SHollis Blanchard #define BOOKE_IRQPRIO_SYSCALL 8
39bb3a8a17SHollis Blanchard #define BOOKE_IRQPRIO_AP_UNAVAIL 9
40bb3a8a17SHollis Blanchard #define BOOKE_IRQPRIO_DTLB_MISS 10
41bb3a8a17SHollis Blanchard #define BOOKE_IRQPRIO_ITLB_MISS 11
42bb3a8a17SHollis Blanchard #define BOOKE_IRQPRIO_MACHINE_CHECK 12
43bb3a8a17SHollis Blanchard #define BOOKE_IRQPRIO_DEBUG 13
44bb3a8a17SHollis Blanchard #define BOOKE_IRQPRIO_CRITICAL 14
45bb3a8a17SHollis Blanchard #define BOOKE_IRQPRIO_WATCHDOG 15
46bb3a8a17SHollis Blanchard #define BOOKE_IRQPRIO_EXTERNAL 16
47bb3a8a17SHollis Blanchard #define BOOKE_IRQPRIO_FIT 17
48bb3a8a17SHollis Blanchard #define BOOKE_IRQPRIO_DECREMENTER 18
49bb3a8a17SHollis Blanchard #define BOOKE_IRQPRIO_PERFORMANCE_MONITOR 19
50c5335f17SAlexander Graf /* Internal pseudo-irqprio for level triggered externals */
51c5335f17SAlexander Graf #define BOOKE_IRQPRIO_EXTERNAL_LEVEL 20
52d30f6e48SScott Wood #define BOOKE_IRQPRIO_DBELL 21
53d30f6e48SScott Wood #define BOOKE_IRQPRIO_DBELL_CRIT 22
54d30f6e48SScott Wood #define BOOKE_IRQPRIO_MAX 23
55d30f6e48SScott Wood 
56d30f6e48SScott Wood #define BOOKE_IRQMASK_EE ((1 << BOOKE_IRQPRIO_EXTERNAL_LEVEL) | \
57d30f6e48SScott Wood 			  (1 << BOOKE_IRQPRIO_PERFORMANCE_MONITOR) | \
58d30f6e48SScott Wood 			  (1 << BOOKE_IRQPRIO_DBELL) | \
59d30f6e48SScott Wood 			  (1 << BOOKE_IRQPRIO_DECREMENTER) | \
60d30f6e48SScott Wood 			  (1 << BOOKE_IRQPRIO_FIT) | \
61d30f6e48SScott Wood 			  (1 << BOOKE_IRQPRIO_EXTERNAL))
62d30f6e48SScott Wood 
63d30f6e48SScott Wood #define BOOKE_IRQMASK_CE ((1 << BOOKE_IRQPRIO_DBELL_CRIT) | \
64d30f6e48SScott Wood 			  (1 << BOOKE_IRQPRIO_WATCHDOG) | \
65d30f6e48SScott Wood 			  (1 << BOOKE_IRQPRIO_CRITICAL))
66bb3a8a17SHollis Blanchard 
67bb3a8a17SHollis Blanchard extern unsigned long kvmppc_booke_handlers;
68d4cf3892SHollis Blanchard 
694cd35f67SScott Wood void kvmppc_set_msr(struct kvm_vcpu *vcpu, u32 new_msr);
70dd9ebf1fSLiu Yu void kvmppc_mmu_msr_notify(struct kvm_vcpu *vcpu, u32 old_msr);
7175f74f0dSHollis Blanchard 
72dfd4d47eSScott Wood void kvmppc_set_tcr(struct kvm_vcpu *vcpu, u32 new_tcr);
73dfd4d47eSScott Wood void kvmppc_set_tsr_bits(struct kvm_vcpu *vcpu, u32 tsr_bits);
74dfd4d47eSScott Wood void kvmppc_clr_tsr_bits(struct kvm_vcpu *vcpu, u32 tsr_bits);
75dfd4d47eSScott Wood 
76d0c7dc03SHollis Blanchard int kvmppc_booke_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,
77d0c7dc03SHollis Blanchard                             unsigned int inst, int *advance);
78d0c7dc03SHollis Blanchard int kvmppc_booke_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, int rt);
79d0c7dc03SHollis Blanchard int kvmppc_booke_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, int rs);
80d0c7dc03SHollis Blanchard 
814cd35f67SScott Wood /* low-level asm code to transfer guest state */
824cd35f67SScott Wood void kvmppc_load_guest_spe(struct kvm_vcpu *vcpu);
834cd35f67SScott Wood void kvmppc_save_guest_spe(struct kvm_vcpu *vcpu);
844cd35f67SScott Wood 
854cd35f67SScott Wood /* high-level function, manages flags, host state */
864cd35f67SScott Wood void kvmppc_vcpu_disable_spe(struct kvm_vcpu *vcpu);
874cd35f67SScott Wood 
8894fa9d99SScott Wood void kvmppc_booke_vcpu_load(struct kvm_vcpu *vcpu, int cpu);
8994fa9d99SScott Wood void kvmppc_booke_vcpu_put(struct kvm_vcpu *vcpu);
9094fa9d99SScott Wood 
91d30f6e48SScott Wood enum int_class {
92d30f6e48SScott Wood 	INT_CLASS_NONCRIT,
93d30f6e48SScott Wood 	INT_CLASS_CRIT,
94d30f6e48SScott Wood 	INT_CLASS_MC,
95d30f6e48SScott Wood 	INT_CLASS_DBG,
96d30f6e48SScott Wood };
97d30f6e48SScott Wood 
98d30f6e48SScott Wood void kvmppc_set_pending_interrupt(struct kvm_vcpu *vcpu, enum int_class type);
99d30f6e48SScott Wood 
100*8fae845fSScott Wood /*
101*8fae845fSScott Wood  * Load up guest vcpu FP state if it's needed.
102*8fae845fSScott Wood  * It also set the MSR_FP in thread so that host know
103*8fae845fSScott Wood  * we're holding FPU, and then host can help to save
104*8fae845fSScott Wood  * guest vcpu FP state if other threads require to use FPU.
105*8fae845fSScott Wood  * This simulates an FP unavailable fault.
106*8fae845fSScott Wood  *
107*8fae845fSScott Wood  * It requires to be called with preemption disabled.
108*8fae845fSScott Wood  */
109*8fae845fSScott Wood static inline void kvmppc_load_guest_fp(struct kvm_vcpu *vcpu)
110*8fae845fSScott Wood {
111*8fae845fSScott Wood #ifdef CONFIG_PPC_FPU
112*8fae845fSScott Wood 	if (vcpu->fpu_active && !(current->thread.regs->msr & MSR_FP)) {
113*8fae845fSScott Wood 		load_up_fpu();
114*8fae845fSScott Wood 		current->thread.regs->msr |= MSR_FP;
115*8fae845fSScott Wood 	}
116*8fae845fSScott Wood #endif
117*8fae845fSScott Wood }
118*8fae845fSScott Wood 
119*8fae845fSScott Wood /*
120*8fae845fSScott Wood  * Save guest vcpu FP state into thread.
121*8fae845fSScott Wood  * It requires to be called with preemption disabled.
122*8fae845fSScott Wood  */
123*8fae845fSScott Wood static inline void kvmppc_save_guest_fp(struct kvm_vcpu *vcpu)
124*8fae845fSScott Wood {
125*8fae845fSScott Wood #ifdef CONFIG_PPC_FPU
126*8fae845fSScott Wood 	if (vcpu->fpu_active && (current->thread.regs->msr & MSR_FP))
127*8fae845fSScott Wood 		giveup_fpu(current);
128*8fae845fSScott Wood #endif
129*8fae845fSScott Wood }
13075f74f0dSHollis Blanchard #endif /* __KVM_BOOKE_H__ */
131