]>
Commit | Line | Data |
---|---|---|
4e342025 AG |
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 SUSE Linux Products GmbH 2009 | |
16 | * | |
17 | * Authors: Alexander Graf <agraf@suse.de> | |
18 | */ | |
19 | ||
20 | #ifndef __ASM_KVM_BOOK3S_H__ | |
21 | #define __ASM_KVM_BOOK3S_H__ | |
22 | ||
23 | #include <linux/types.h> | |
24 | #include <linux/kvm_host.h> | |
2191d657 | 25 | #include <asm/kvm_book3s_asm.h> |
4e342025 | 26 | |
4e342025 | 27 | struct kvmppc_bat { |
e15a1137 | 28 | u64 raw; |
4e342025 AG |
29 | u32 bepi; |
30 | u32 bepi_mask; | |
4e342025 AG |
31 | u32 brpn; |
32 | u8 wimg; | |
33 | u8 pp; | |
3ed9c6d2 AG |
34 | bool vs : 1; |
35 | bool vp : 1; | |
4e342025 AG |
36 | }; |
37 | ||
38 | struct kvmppc_sid_map { | |
39 | u64 guest_vsid; | |
40 | u64 guest_esid; | |
41 | u64 host_vsid; | |
3ed9c6d2 | 42 | bool valid : 1; |
4e342025 AG |
43 | }; |
44 | ||
45 | #define SID_MAP_BITS 9 | |
46 | #define SID_MAP_NUM (1 << SID_MAP_BITS) | |
47 | #define SID_MAP_MASK (SID_MAP_NUM - 1) | |
48 | ||
8b6db3bc AG |
49 | #ifdef CONFIG_PPC_BOOK3S_64 |
50 | #define SID_CONTEXTS 1 | |
51 | #else | |
52 | #define SID_CONTEXTS 128 | |
53 | #define VSID_POOL_SIZE (SID_CONTEXTS * 16) | |
54 | #endif | |
55 | ||
c4befc58 PM |
56 | struct hpte_cache { |
57 | struct hlist_node list_pte; | |
58 | struct hlist_node list_pte_long; | |
59 | struct hlist_node list_vpte; | |
60 | struct hlist_node list_vpte_long; | |
a4a0f252 PM |
61 | #ifdef CONFIG_PPC_BOOK3S_64 |
62 | struct hlist_node list_vpte_64k; | |
63 | #endif | |
c4befc58 | 64 | struct rcu_head rcu_head; |
5524a27d | 65 | u64 host_vpn; |
c4befc58 PM |
66 | u64 pfn; |
67 | ulong slot; | |
68 | struct kvmppc_pte pte; | |
c9029c34 | 69 | int pagesize; |
c4befc58 PM |
70 | }; |
71 | ||
e64fb7e2 SJS |
72 | /* |
73 | * Struct for a virtual core. | |
74 | * Note: entry_exit_map combines a bitmap of threads that have entered | |
75 | * in the bottom 8 bits and a bitmap of threads that have exited in the | |
76 | * next 8 bits. This is so that we can atomically set the entry bit | |
77 | * iff the exit map is 0 without taking a lock. | |
78 | */ | |
79 | struct kvmppc_vcore { | |
80 | int n_runnable; | |
81 | int num_threads; | |
82 | int entry_exit_map; | |
83 | int napping_threads; | |
84 | int first_vcpuid; | |
85 | u16 pcpu; | |
86 | u16 last_cpu; | |
87 | u8 vcore_state; | |
88 | u8 in_guest; | |
89 | struct kvmppc_vcore *master_vcore; | |
90 | struct list_head runnable_threads; | |
91 | struct list_head preempt_list; | |
92 | spinlock_t lock; | |
93 | struct swait_queue_head wq; | |
94 | spinlock_t stoltb_lock; /* protects stolen_tb and preempt_tb */ | |
95 | u64 stolen_tb; | |
96 | u64 preempt_tb; | |
97 | struct kvm_vcpu *runner; | |
98 | struct kvm *kvm; | |
99 | u64 tb_offset; /* guest timebase - host timebase */ | |
100 | ulong lpcr; | |
101 | u32 arch_compat; | |
102 | ulong pcr; | |
103 | ulong dpdes; /* doorbell state (POWER8) */ | |
104 | ulong conferring_threads; | |
105 | }; | |
106 | ||
4e342025 | 107 | struct kvmppc_vcpu_book3s { |
4e342025 | 108 | struct kvmppc_sid_map sid_map[SID_MAP_NUM]; |
4e342025 AG |
109 | struct { |
110 | u64 esid; | |
111 | u64 vsid; | |
112 | } slb_shadow[64]; | |
113 | u8 slb_shadow_max; | |
4e342025 AG |
114 | struct kvmppc_bat ibat[8]; |
115 | struct kvmppc_bat dbat[8]; | |
116 | u64 hid[6]; | |
d6d549b2 | 117 | u64 gqr[8]; |
4e342025 | 118 | u64 sdr1; |
4e342025 AG |
119 | u64 hior; |
120 | u64 msr_mask; | |
8b6db3bc AG |
121 | #ifdef CONFIG_PPC_BOOK3S_32 |
122 | u32 vsid_pool[VSID_POOL_SIZE]; | |
ffe36492 | 123 | u32 vsid_next; |
8b6db3bc | 124 | #else |
ffe36492 BH |
125 | u64 proto_vsid_first; |
126 | u64 proto_vsid_max; | |
127 | u64 proto_vsid_next; | |
8b6db3bc AG |
128 | #endif |
129 | int context_id[SID_CONTEXTS]; | |
c4befc58 | 130 | |
1022fc3d AG |
131 | bool hior_explicit; /* HIOR is set by ioctl, not PVR */ |
132 | ||
c4befc58 PM |
133 | struct hlist_head hpte_hash_pte[HPTEG_HASH_NUM_PTE]; |
134 | struct hlist_head hpte_hash_pte_long[HPTEG_HASH_NUM_PTE_LONG]; | |
135 | struct hlist_head hpte_hash_vpte[HPTEG_HASH_NUM_VPTE]; | |
136 | struct hlist_head hpte_hash_vpte_long[HPTEG_HASH_NUM_VPTE_LONG]; | |
a4a0f252 PM |
137 | #ifdef CONFIG_PPC_BOOK3S_64 |
138 | struct hlist_head hpte_hash_vpte_64k[HPTEG_HASH_NUM_VPTE_64K]; | |
139 | #endif | |
c4befc58 PM |
140 | int hpte_cache_count; |
141 | spinlock_t mmu_lock; | |
4e342025 AG |
142 | }; |
143 | ||
c9029c34 PM |
144 | #define VSID_REAL 0x07ffffffffc00000ULL |
145 | #define VSID_BAT 0x07ffffffffb00000ULL | |
146 | #define VSID_64K 0x0800000000000000ULL | |
0f296829 | 147 | #define VSID_1T 0x1000000000000000ULL |
f7bc74e1 AG |
148 | #define VSID_REAL_DR 0x2000000000000000ULL |
149 | #define VSID_REAL_IR 0x4000000000000000ULL | |
5a1b419f | 150 | #define VSID_PR 0x8000000000000000ULL |
4e342025 | 151 | |
af7b4d10 | 152 | extern void kvmppc_mmu_pte_flush(struct kvm_vcpu *vcpu, ulong ea, ulong ea_mask); |
4e342025 | 153 | extern void kvmppc_mmu_pte_vflush(struct kvm_vcpu *vcpu, u64 vp, u64 vp_mask); |
af7b4d10 | 154 | extern void kvmppc_mmu_pte_pflush(struct kvm_vcpu *vcpu, ulong pa_start, ulong pa_end); |
4e342025 AG |
155 | extern void kvmppc_set_msr(struct kvm_vcpu *vcpu, u64 new_msr); |
156 | extern void kvmppc_mmu_book3s_64_init(struct kvm_vcpu *vcpu); | |
157 | extern void kvmppc_mmu_book3s_32_init(struct kvm_vcpu *vcpu); | |
de56a948 | 158 | extern void kvmppc_mmu_book3s_hv_init(struct kvm_vcpu *vcpu); |
93b159b4 PM |
159 | extern int kvmppc_mmu_map_page(struct kvm_vcpu *vcpu, struct kvmppc_pte *pte, |
160 | bool iswrite); | |
161 | extern void kvmppc_mmu_unmap_page(struct kvm_vcpu *vcpu, struct kvmppc_pte *pte); | |
4e342025 | 162 | extern int kvmppc_mmu_map_segment(struct kvm_vcpu *vcpu, ulong eaddr); |
0f296829 | 163 | extern void kvmppc_mmu_flush_segment(struct kvm_vcpu *vcpu, ulong eaddr, ulong seg_size); |
4e342025 | 164 | extern void kvmppc_mmu_flush_segments(struct kvm_vcpu *vcpu); |
697d3899 PM |
165 | extern int kvmppc_book3s_hv_page_fault(struct kvm_run *run, |
166 | struct kvm_vcpu *vcpu, unsigned long addr, | |
167 | unsigned long status); | |
168 | extern long kvmppc_hv_find_lock_hpte(struct kvm *kvm, gva_t eaddr, | |
169 | unsigned long slb_v, unsigned long valid); | |
fef093be AG |
170 | |
171 | extern void kvmppc_mmu_hpte_cache_map(struct kvm_vcpu *vcpu, struct hpte_cache *pte); | |
172 | extern struct hpte_cache *kvmppc_mmu_hpte_cache_next(struct kvm_vcpu *vcpu); | |
d78bca72 | 173 | extern void kvmppc_mmu_hpte_cache_free(struct hpte_cache *pte); |
fef093be AG |
174 | extern void kvmppc_mmu_hpte_destroy(struct kvm_vcpu *vcpu); |
175 | extern int kvmppc_mmu_hpte_init(struct kvm_vcpu *vcpu); | |
176 | extern void kvmppc_mmu_invalidate_pte(struct kvm_vcpu *vcpu, struct hpte_cache *pte); | |
177 | extern int kvmppc_mmu_hpte_sysinit(void); | |
178 | extern void kvmppc_mmu_hpte_sysexit(void); | |
de56a948 | 179 | extern int kvmppc_mmu_hv_init(void); |
ae2113a4 | 180 | extern int kvmppc_book3s_hcall_implemented(struct kvm *kvm, unsigned long hc); |
fef093be | 181 | |
35c4a733 | 182 | /* XXX remove this export when load_last_inst() is generic */ |
5467a97d | 183 | extern int kvmppc_ld(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr, bool data); |
4e342025 | 184 | extern void kvmppc_book3s_queue_irqprio(struct kvm_vcpu *vcpu, unsigned int vec); |
bc5ad3f3 BH |
185 | extern void kvmppc_book3s_dequeue_irqprio(struct kvm_vcpu *vcpu, |
186 | unsigned int vec); | |
de56a948 | 187 | extern void kvmppc_inject_interrupt(struct kvm_vcpu *vcpu, int vec, u64 flags); |
e15a1137 AG |
188 | extern void kvmppc_set_bat(struct kvm_vcpu *vcpu, struct kvmppc_bat *bat, |
189 | bool upper, u32 val); | |
aba3bd7f | 190 | extern void kvmppc_giveup_ext(struct kvm_vcpu *vcpu, ulong msr); |
831317b6 | 191 | extern int kvmppc_emulate_paired_single(struct kvm_run *run, struct kvm_vcpu *vcpu); |
ba049e93 DW |
192 | extern kvm_pfn_t kvmppc_gpa_to_pfn(struct kvm_vcpu *vcpu, gpa_t gpa, |
193 | bool writing, bool *writable); | |
342d3db7 PM |
194 | extern void kvmppc_add_revmap_chain(struct kvm *kvm, struct revmap_entry *rev, |
195 | unsigned long *rmap, long pte_index, int realmode); | |
08fe1e7b | 196 | extern void kvmppc_update_rmap_change(unsigned long *rmap, unsigned long psize); |
6f22bd32 | 197 | extern void kvmppc_invalidate_hpte(struct kvm *kvm, __be64 *hptep, |
342d3db7 | 198 | unsigned long pte_index); |
6f22bd32 | 199 | void kvmppc_clear_ref_hpte(struct kvm *kvm, __be64 *hptep, |
55514893 | 200 | unsigned long pte_index); |
93e60249 PM |
201 | extern void *kvmppc_pin_guest_page(struct kvm *kvm, unsigned long addr, |
202 | unsigned long *nb_ret); | |
c35635ef PM |
203 | extern void kvmppc_unpin_guest_page(struct kvm *kvm, void *addr, |
204 | unsigned long gpa, bool dirty); | |
7ed661bf PM |
205 | extern long kvmppc_do_h_enter(struct kvm *kvm, unsigned long flags, |
206 | long pte_index, unsigned long pteh, unsigned long ptel, | |
207 | pgd_t *pgdir, bool realmode, unsigned long *idx_ret); | |
6b445ad4 PM |
208 | extern long kvmppc_do_h_remove(struct kvm *kvm, unsigned long flags, |
209 | unsigned long pte_index, unsigned long avpn, | |
210 | unsigned long *hpret); | |
82ed3616 | 211 | extern long kvmppc_hv_get_dirty_log(struct kvm *kvm, |
dfe49dbd | 212 | struct kvm_memory_slot *memslot, unsigned long *map); |
a0144e2a PM |
213 | extern void kvmppc_update_lpcr(struct kvm *kvm, unsigned long lpcr, |
214 | unsigned long mask); | |
8e6afa36 | 215 | extern void kvmppc_set_fscr(struct kvm_vcpu *vcpu, u64 fscr); |
4e342025 | 216 | |
02143947 | 217 | extern void kvmppc_entry_trampoline(void); |
de56a948 | 218 | extern void kvmppc_hv_entry_trampoline(void); |
ca7f4203 AG |
219 | extern u32 kvmppc_alignment_dsisr(struct kvm_vcpu *vcpu, unsigned int inst); |
220 | extern ulong kvmppc_alignment_dar(struct kvm_vcpu *vcpu, unsigned int inst); | |
0254f074 | 221 | extern int kvmppc_h_pr(struct kvm_vcpu *vcpu, unsigned long cmd); |
699a0ea0 | 222 | extern void kvmppc_pr_init_default_hcalls(struct kvm *kvm); |
ae2113a4 PM |
223 | extern int kvmppc_hcall_impl_pr(unsigned long cmd); |
224 | extern int kvmppc_hcall_impl_hv_realmode(unsigned long cmd); | |
c9dad7f9 AG |
225 | extern void kvmppc_copy_to_svcpu(struct kvmppc_book3s_shadow_vcpu *svcpu, |
226 | struct kvm_vcpu *vcpu); | |
227 | extern void kvmppc_copy_from_svcpu(struct kvm_vcpu *vcpu, | |
228 | struct kvmppc_book3s_shadow_vcpu *svcpu); | |
4e342025 AG |
229 | |
230 | static inline struct kvmppc_vcpu_book3s *to_book3s(struct kvm_vcpu *vcpu) | |
231 | { | |
3ff95502 | 232 | return vcpu->arch.book3s; |
4e342025 AG |
233 | } |
234 | ||
de56a948 PM |
235 | /* Also add subarch specific defines */ |
236 | ||
237 | #ifdef CONFIG_KVM_BOOK3S_32_HANDLER | |
238 | #include <asm/kvm_book3s_32.h> | |
239 | #endif | |
240 | #ifdef CONFIG_KVM_BOOK3S_64_HANDLER | |
241 | #include <asm/kvm_book3s_64.h> | |
242 | #endif | |
243 | ||
c7f38f46 AG |
244 | static inline void kvmppc_set_gpr(struct kvm_vcpu *vcpu, int num, ulong val) |
245 | { | |
a2d56020 | 246 | vcpu->arch.gpr[num] = val; |
c7f38f46 AG |
247 | } |
248 | ||
249 | static inline ulong kvmppc_get_gpr(struct kvm_vcpu *vcpu, int num) | |
250 | { | |
a2d56020 | 251 | return vcpu->arch.gpr[num]; |
c7f38f46 AG |
252 | } |
253 | ||
254 | static inline void kvmppc_set_cr(struct kvm_vcpu *vcpu, u32 val) | |
255 | { | |
a2d56020 | 256 | vcpu->arch.cr = val; |
c7f38f46 AG |
257 | } |
258 | ||
259 | static inline u32 kvmppc_get_cr(struct kvm_vcpu *vcpu) | |
260 | { | |
a2d56020 | 261 | return vcpu->arch.cr; |
c7f38f46 AG |
262 | } |
263 | ||
c63517c2 | 264 | static inline void kvmppc_set_xer(struct kvm_vcpu *vcpu, ulong val) |
c7f38f46 | 265 | { |
a2d56020 | 266 | vcpu->arch.xer = val; |
c7f38f46 AG |
267 | } |
268 | ||
c63517c2 | 269 | static inline ulong kvmppc_get_xer(struct kvm_vcpu *vcpu) |
c7f38f46 | 270 | { |
a2d56020 | 271 | return vcpu->arch.xer; |
c7f38f46 AG |
272 | } |
273 | ||
274 | static inline void kvmppc_set_ctr(struct kvm_vcpu *vcpu, ulong val) | |
275 | { | |
a2d56020 | 276 | vcpu->arch.ctr = val; |
c7f38f46 AG |
277 | } |
278 | ||
279 | static inline ulong kvmppc_get_ctr(struct kvm_vcpu *vcpu) | |
280 | { | |
a2d56020 | 281 | return vcpu->arch.ctr; |
c7f38f46 AG |
282 | } |
283 | ||
284 | static inline void kvmppc_set_lr(struct kvm_vcpu *vcpu, ulong val) | |
285 | { | |
a2d56020 | 286 | vcpu->arch.lr = val; |
c7f38f46 AG |
287 | } |
288 | ||
289 | static inline ulong kvmppc_get_lr(struct kvm_vcpu *vcpu) | |
290 | { | |
a2d56020 | 291 | return vcpu->arch.lr; |
c7f38f46 AG |
292 | } |
293 | ||
294 | static inline void kvmppc_set_pc(struct kvm_vcpu *vcpu, ulong val) | |
295 | { | |
a2d56020 | 296 | vcpu->arch.pc = val; |
c7f38f46 AG |
297 | } |
298 | ||
299 | static inline ulong kvmppc_get_pc(struct kvm_vcpu *vcpu) | |
300 | { | |
a2d56020 | 301 | return vcpu->arch.pc; |
c7f38f46 AG |
302 | } |
303 | ||
5deb8e7a | 304 | static inline u64 kvmppc_get_msr(struct kvm_vcpu *vcpu); |
73601775 | 305 | static inline bool kvmppc_need_byteswap(struct kvm_vcpu *vcpu) |
c7f38f46 | 306 | { |
5deb8e7a | 307 | return (kvmppc_get_msr(vcpu) & MSR_LE) != (MSR_KERNEL & MSR_LE); |
73601775 | 308 | } |
c7f38f46 | 309 | |
c7f38f46 AG |
310 | static inline ulong kvmppc_get_fault_dar(struct kvm_vcpu *vcpu) |
311 | { | |
a2d56020 PM |
312 | return vcpu->arch.fault_dar; |
313 | } | |
314 | ||
e59d24e6 GK |
315 | static inline bool is_kvmppc_resume_guest(int r) |
316 | { | |
317 | return (r == RESUME_GUEST || r == RESUME_GUEST_NV); | |
318 | } | |
319 | ||
c12fb43c AG |
320 | static inline bool is_kvmppc_hv_enabled(struct kvm *kvm); |
321 | static inline bool kvmppc_supports_magic_page(struct kvm_vcpu *vcpu) | |
322 | { | |
323 | /* Only PR KVM supports the magic page */ | |
324 | return !is_kvmppc_hv_enabled(vcpu->kvm); | |
325 | } | |
326 | ||
99342cf8 DG |
327 | extern int kvmppc_h_logical_ci_load(struct kvm_vcpu *vcpu); |
328 | extern int kvmppc_h_logical_ci_store(struct kvm_vcpu *vcpu); | |
329 | ||
ad0a048b AG |
330 | /* Magic register values loaded into r3 and r4 before the 'sc' assembly |
331 | * instruction for the OSI hypercalls */ | |
332 | #define OSI_SC_MAGIC_R3 0x113724FA | |
333 | #define OSI_SC_MAGIC_R4 0x77810F9B | |
334 | ||
4e342025 | 335 | #define INS_DCBZ 0x7c0007ec |
8c32a2ea BB |
336 | /* TO = 31 for unconditional trap */ |
337 | #define INS_TW 0x7fe00008 | |
4e342025 | 338 | |
043cc4d7 SW |
339 | /* LPIDs we support with this build -- runtime limit may be lower */ |
340 | #define KVMPPC_NR_LPIDS (LPID_RSVD + 1) | |
341 | ||
c01e3f66 AG |
342 | #define SPLIT_HACK_MASK 0xff000000 |
343 | #define SPLIT_HACK_OFFS 0xfb000000 | |
344 | ||
4e342025 | 345 | #endif /* __ASM_KVM_BOOK3S_H__ */ |