Merge branch 'fixes' of git://ftp.arm.linux.org.uk/~rmk/linux-arm
[sfrench/cifs-2.6.git] / arch / powerpc / kvm / booke.h
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License, version 2, as
4  * published by the Free Software Foundation.
5  *
6  * This program is distributed in the hope that it will be useful,
7  * but WITHOUT ANY WARRANTY; without even the implied warranty of
8  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9  * GNU General Public License for more details.
10  *
11  * You should have received a copy of the GNU General Public License
12  * along with this program; if not, write to the Free Software
13  * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
14  *
15  * Copyright IBM Corp. 2008
16  *
17  * Authors: Hollis Blanchard <hollisb@us.ibm.com>
18  */
19
20 #ifndef __KVM_BOOKE_H__
21 #define __KVM_BOOKE_H__
22
23 #include <linux/types.h>
24 #include <linux/kvm_host.h>
25 #include <asm/kvm_ppc.h>
26 #include <asm/switch_to.h>
27 #include "timing.h"
28
29 /* interrupt priortity ordering */
30 #define BOOKE_IRQPRIO_DATA_STORAGE 0
31 #define BOOKE_IRQPRIO_INST_STORAGE 1
32 #define BOOKE_IRQPRIO_ALIGNMENT 2
33 #define BOOKE_IRQPRIO_PROGRAM 3
34 #define BOOKE_IRQPRIO_FP_UNAVAIL 4
35 #ifdef CONFIG_SPE_POSSIBLE
36 #define BOOKE_IRQPRIO_SPE_UNAVAIL 5
37 #define BOOKE_IRQPRIO_SPE_FP_DATA 6
38 #define BOOKE_IRQPRIO_SPE_FP_ROUND 7
39 #endif
40 #ifdef CONFIG_PPC_E500MC
41 #define BOOKE_IRQPRIO_ALTIVEC_UNAVAIL 5
42 #define BOOKE_IRQPRIO_ALTIVEC_ASSIST 6
43 #endif
44 #define BOOKE_IRQPRIO_SYSCALL 8
45 #define BOOKE_IRQPRIO_AP_UNAVAIL 9
46 #define BOOKE_IRQPRIO_DTLB_MISS 10
47 #define BOOKE_IRQPRIO_ITLB_MISS 11
48 #define BOOKE_IRQPRIO_MACHINE_CHECK 12
49 #define BOOKE_IRQPRIO_DEBUG 13
50 #define BOOKE_IRQPRIO_CRITICAL 14
51 #define BOOKE_IRQPRIO_WATCHDOG 15
52 #define BOOKE_IRQPRIO_EXTERNAL 16
53 #define BOOKE_IRQPRIO_FIT 17
54 #define BOOKE_IRQPRIO_DECREMENTER 18
55 #define BOOKE_IRQPRIO_PERFORMANCE_MONITOR 19
56 /* Internal pseudo-irqprio for level triggered externals */
57 #define BOOKE_IRQPRIO_EXTERNAL_LEVEL 20
58 #define BOOKE_IRQPRIO_DBELL 21
59 #define BOOKE_IRQPRIO_DBELL_CRIT 22
60 #define BOOKE_IRQPRIO_MAX 23
61
62 #define BOOKE_IRQMASK_EE ((1 << BOOKE_IRQPRIO_EXTERNAL_LEVEL) | \
63                           (1 << BOOKE_IRQPRIO_PERFORMANCE_MONITOR) | \
64                           (1 << BOOKE_IRQPRIO_DBELL) | \
65                           (1 << BOOKE_IRQPRIO_DECREMENTER) | \
66                           (1 << BOOKE_IRQPRIO_FIT) | \
67                           (1 << BOOKE_IRQPRIO_EXTERNAL))
68
69 #define BOOKE_IRQMASK_CE ((1 << BOOKE_IRQPRIO_DBELL_CRIT) | \
70                           (1 << BOOKE_IRQPRIO_WATCHDOG) | \
71                           (1 << BOOKE_IRQPRIO_CRITICAL))
72
73 extern unsigned long kvmppc_booke_handlers;
74 extern unsigned long kvmppc_booke_handler_addr[];
75
76 void kvmppc_set_msr(struct kvm_vcpu *vcpu, u32 new_msr);
77 void kvmppc_mmu_msr_notify(struct kvm_vcpu *vcpu, u32 old_msr);
78
79 void kvmppc_set_epcr(struct kvm_vcpu *vcpu, u32 new_epcr);
80 void kvmppc_set_tcr(struct kvm_vcpu *vcpu, u32 new_tcr);
81 void kvmppc_set_tsr_bits(struct kvm_vcpu *vcpu, u32 tsr_bits);
82 void kvmppc_clr_tsr_bits(struct kvm_vcpu *vcpu, u32 tsr_bits);
83
84 int kvmppc_booke_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,
85                             unsigned int inst, int *advance);
86 int kvmppc_booke_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val);
87 int kvmppc_booke_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val);
88
89 /* low-level asm code to transfer guest state */
90 void kvmppc_load_guest_spe(struct kvm_vcpu *vcpu);
91 void kvmppc_save_guest_spe(struct kvm_vcpu *vcpu);
92
93 /* high-level function, manages flags, host state */
94 void kvmppc_vcpu_disable_spe(struct kvm_vcpu *vcpu);
95
96 void kvmppc_booke_vcpu_load(struct kvm_vcpu *vcpu, int cpu);
97 void kvmppc_booke_vcpu_put(struct kvm_vcpu *vcpu);
98
99 enum int_class {
100         INT_CLASS_NONCRIT,
101         INT_CLASS_CRIT,
102         INT_CLASS_MC,
103         INT_CLASS_DBG,
104 };
105
106 void kvmppc_set_pending_interrupt(struct kvm_vcpu *vcpu, enum int_class type);
107
108 extern void kvmppc_mmu_destroy_e500(struct kvm_vcpu *vcpu);
109 extern int kvmppc_core_emulate_op_e500(struct kvm_run *run,
110                                        struct kvm_vcpu *vcpu,
111                                        unsigned int inst, int *advance);
112 extern int kvmppc_core_emulate_mtspr_e500(struct kvm_vcpu *vcpu, int sprn,
113                                           ulong spr_val);
114 extern int kvmppc_core_emulate_mfspr_e500(struct kvm_vcpu *vcpu, int sprn,
115                                           ulong *spr_val);
116 extern void kvmppc_mmu_destroy_e500(struct kvm_vcpu *vcpu);
117 extern int kvmppc_core_emulate_op_e500(struct kvm_run *run,
118                                        struct kvm_vcpu *vcpu,
119                                        unsigned int inst, int *advance);
120 extern int kvmppc_core_emulate_mtspr_e500(struct kvm_vcpu *vcpu, int sprn,
121                                           ulong spr_val);
122 extern int kvmppc_core_emulate_mfspr_e500(struct kvm_vcpu *vcpu, int sprn,
123                                           ulong *spr_val);
124
125 static inline void kvmppc_clear_dbsr(void)
126 {
127         mtspr(SPRN_DBSR, mfspr(SPRN_DBSR));
128 }
129 #endif /* __KVM_BOOKE_H__ */