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> 268fae845fSScott 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 72*38f98824SMihai Caraman void kvmppc_set_epcr(struct kvm_vcpu *vcpu, u32 new_epcr); 73dfd4d47eSScott Wood void kvmppc_set_tcr(struct kvm_vcpu *vcpu, u32 new_tcr); 74dfd4d47eSScott Wood void kvmppc_set_tsr_bits(struct kvm_vcpu *vcpu, u32 tsr_bits); 75dfd4d47eSScott Wood void kvmppc_clr_tsr_bits(struct kvm_vcpu *vcpu, u32 tsr_bits); 76dfd4d47eSScott Wood 77d0c7dc03SHollis Blanchard int kvmppc_booke_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu, 78d0c7dc03SHollis Blanchard unsigned int inst, int *advance); 7954771e62SAlexander Graf int kvmppc_booke_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val); 8054771e62SAlexander Graf int kvmppc_booke_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val); 81d0c7dc03SHollis Blanchard 824cd35f67SScott Wood /* low-level asm code to transfer guest state */ 834cd35f67SScott Wood void kvmppc_load_guest_spe(struct kvm_vcpu *vcpu); 844cd35f67SScott Wood void kvmppc_save_guest_spe(struct kvm_vcpu *vcpu); 854cd35f67SScott Wood 864cd35f67SScott Wood /* high-level function, manages flags, host state */ 874cd35f67SScott Wood void kvmppc_vcpu_disable_spe(struct kvm_vcpu *vcpu); 884cd35f67SScott Wood 8994fa9d99SScott Wood void kvmppc_booke_vcpu_load(struct kvm_vcpu *vcpu, int cpu); 9094fa9d99SScott Wood void kvmppc_booke_vcpu_put(struct kvm_vcpu *vcpu); 9194fa9d99SScott Wood 92d30f6e48SScott Wood enum int_class { 93d30f6e48SScott Wood INT_CLASS_NONCRIT, 94d30f6e48SScott Wood INT_CLASS_CRIT, 95d30f6e48SScott Wood INT_CLASS_MC, 96d30f6e48SScott Wood INT_CLASS_DBG, 97d30f6e48SScott Wood }; 98d30f6e48SScott Wood 99d30f6e48SScott Wood void kvmppc_set_pending_interrupt(struct kvm_vcpu *vcpu, enum int_class type); 100d30f6e48SScott Wood 1018fae845fSScott Wood /* 1028fae845fSScott Wood * Load up guest vcpu FP state if it's needed. 1038fae845fSScott Wood * It also set the MSR_FP in thread so that host know 1048fae845fSScott Wood * we're holding FPU, and then host can help to save 1058fae845fSScott Wood * guest vcpu FP state if other threads require to use FPU. 1068fae845fSScott Wood * This simulates an FP unavailable fault. 1078fae845fSScott Wood * 1088fae845fSScott Wood * It requires to be called with preemption disabled. 1098fae845fSScott Wood */ 1108fae845fSScott Wood static inline void kvmppc_load_guest_fp(struct kvm_vcpu *vcpu) 1118fae845fSScott Wood { 1128fae845fSScott Wood #ifdef CONFIG_PPC_FPU 1138fae845fSScott Wood if (vcpu->fpu_active && !(current->thread.regs->msr & MSR_FP)) { 1148fae845fSScott Wood load_up_fpu(); 1158fae845fSScott Wood current->thread.regs->msr |= MSR_FP; 1168fae845fSScott Wood } 1178fae845fSScott Wood #endif 1188fae845fSScott Wood } 1198fae845fSScott Wood 1208fae845fSScott Wood /* 1218fae845fSScott Wood * Save guest vcpu FP state into thread. 1228fae845fSScott Wood * It requires to be called with preemption disabled. 1238fae845fSScott Wood */ 1248fae845fSScott Wood static inline void kvmppc_save_guest_fp(struct kvm_vcpu *vcpu) 1258fae845fSScott Wood { 1268fae845fSScott Wood #ifdef CONFIG_PPC_FPU 1278fae845fSScott Wood if (vcpu->fpu_active && (current->thread.regs->msr & MSR_FP)) 1288fae845fSScott Wood giveup_fpu(current); 1298fae845fSScott Wood #endif 1308fae845fSScott Wood } 13175f74f0dSHollis Blanchard #endif /* __KVM_BOOKE_H__ */ 132