x86/efi: Enforce CONFIG_RELOCATABLE for EFI boot stub
[linux/fpc-iii.git] / arch / powerpc / include / asm / kvm_book3s.h
blobfa19e2f1a874b3878d0cd556bc5c39417ff1a08d
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.
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.
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.
15 * Copyright SUSE Linux Products GmbH 2009
17 * Authors: Alexander Graf <agraf@suse.de>
20 #ifndef __ASM_KVM_BOOK3S_H__
21 #define __ASM_KVM_BOOK3S_H__
23 #include <linux/types.h>
24 #include <linux/kvm_host.h>
25 #include <asm/kvm_book3s_asm.h>
27 struct kvmppc_bat {
28 u64 raw;
29 u32 bepi;
30 u32 bepi_mask;
31 u32 brpn;
32 u8 wimg;
33 u8 pp;
34 bool vs : 1;
35 bool vp : 1;
38 struct kvmppc_sid_map {
39 u64 guest_vsid;
40 u64 guest_esid;
41 u64 host_vsid;
42 bool valid : 1;
45 #define SID_MAP_BITS 9
46 #define SID_MAP_NUM (1 << SID_MAP_BITS)
47 #define SID_MAP_MASK (SID_MAP_NUM - 1)
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
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;
61 struct rcu_head rcu_head;
62 u64 host_vpn;
63 u64 pfn;
64 ulong slot;
65 struct kvmppc_pte pte;
68 struct kvmppc_vcpu_book3s {
69 struct kvm_vcpu vcpu;
70 struct kvmppc_book3s_shadow_vcpu *shadow_vcpu;
71 struct kvmppc_sid_map sid_map[SID_MAP_NUM];
72 struct {
73 u64 esid;
74 u64 vsid;
75 } slb_shadow[64];
76 u8 slb_shadow_max;
77 struct kvmppc_bat ibat[8];
78 struct kvmppc_bat dbat[8];
79 u64 hid[6];
80 u64 gqr[8];
81 u64 sdr1;
82 u64 hior;
83 u64 msr_mask;
84 u64 purr_offset;
85 u64 spurr_offset;
86 #ifdef CONFIG_PPC_BOOK3S_32
87 u32 vsid_pool[VSID_POOL_SIZE];
88 u32 vsid_next;
89 #else
90 u64 proto_vsid_first;
91 u64 proto_vsid_max;
92 u64 proto_vsid_next;
93 #endif
94 int context_id[SID_CONTEXTS];
96 bool hior_explicit; /* HIOR is set by ioctl, not PVR */
98 struct hlist_head hpte_hash_pte[HPTEG_HASH_NUM_PTE];
99 struct hlist_head hpte_hash_pte_long[HPTEG_HASH_NUM_PTE_LONG];
100 struct hlist_head hpte_hash_vpte[HPTEG_HASH_NUM_VPTE];
101 struct hlist_head hpte_hash_vpte_long[HPTEG_HASH_NUM_VPTE_LONG];
102 int hpte_cache_count;
103 spinlock_t mmu_lock;
106 #define CONTEXT_HOST 0
107 #define CONTEXT_GUEST 1
108 #define CONTEXT_GUEST_END 2
110 #define VSID_REAL 0x0fffffffffc00000ULL
111 #define VSID_BAT 0x0fffffffffb00000ULL
112 #define VSID_1T 0x1000000000000000ULL
113 #define VSID_REAL_DR 0x2000000000000000ULL
114 #define VSID_REAL_IR 0x4000000000000000ULL
115 #define VSID_PR 0x8000000000000000ULL
117 extern void kvmppc_mmu_pte_flush(struct kvm_vcpu *vcpu, ulong ea, ulong ea_mask);
118 extern void kvmppc_mmu_pte_vflush(struct kvm_vcpu *vcpu, u64 vp, u64 vp_mask);
119 extern void kvmppc_mmu_pte_pflush(struct kvm_vcpu *vcpu, ulong pa_start, ulong pa_end);
120 extern void kvmppc_set_msr(struct kvm_vcpu *vcpu, u64 new_msr);
121 extern void kvmppc_set_pvr(struct kvm_vcpu *vcpu, u32 pvr);
122 extern void kvmppc_mmu_book3s_64_init(struct kvm_vcpu *vcpu);
123 extern void kvmppc_mmu_book3s_32_init(struct kvm_vcpu *vcpu);
124 extern void kvmppc_mmu_book3s_hv_init(struct kvm_vcpu *vcpu);
125 extern int kvmppc_mmu_map_page(struct kvm_vcpu *vcpu, struct kvmppc_pte *pte);
126 extern int kvmppc_mmu_map_segment(struct kvm_vcpu *vcpu, ulong eaddr);
127 extern void kvmppc_mmu_flush_segment(struct kvm_vcpu *vcpu, ulong eaddr, ulong seg_size);
128 extern void kvmppc_mmu_flush_segments(struct kvm_vcpu *vcpu);
129 extern int kvmppc_book3s_hv_page_fault(struct kvm_run *run,
130 struct kvm_vcpu *vcpu, unsigned long addr,
131 unsigned long status);
132 extern long kvmppc_hv_find_lock_hpte(struct kvm *kvm, gva_t eaddr,
133 unsigned long slb_v, unsigned long valid);
135 extern void kvmppc_mmu_hpte_cache_map(struct kvm_vcpu *vcpu, struct hpte_cache *pte);
136 extern struct hpte_cache *kvmppc_mmu_hpte_cache_next(struct kvm_vcpu *vcpu);
137 extern void kvmppc_mmu_hpte_destroy(struct kvm_vcpu *vcpu);
138 extern int kvmppc_mmu_hpte_init(struct kvm_vcpu *vcpu);
139 extern void kvmppc_mmu_invalidate_pte(struct kvm_vcpu *vcpu, struct hpte_cache *pte);
140 extern int kvmppc_mmu_hpte_sysinit(void);
141 extern void kvmppc_mmu_hpte_sysexit(void);
142 extern int kvmppc_mmu_hv_init(void);
144 extern int kvmppc_ld(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr, bool data);
145 extern int kvmppc_st(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr, bool data);
146 extern void kvmppc_book3s_queue_irqprio(struct kvm_vcpu *vcpu, unsigned int vec);
147 extern void kvmppc_book3s_dequeue_irqprio(struct kvm_vcpu *vcpu,
148 unsigned int vec);
149 extern void kvmppc_inject_interrupt(struct kvm_vcpu *vcpu, int vec, u64 flags);
150 extern void kvmppc_set_bat(struct kvm_vcpu *vcpu, struct kvmppc_bat *bat,
151 bool upper, u32 val);
152 extern void kvmppc_giveup_ext(struct kvm_vcpu *vcpu, ulong msr);
153 extern int kvmppc_emulate_paired_single(struct kvm_run *run, struct kvm_vcpu *vcpu);
154 extern pfn_t kvmppc_gfn_to_pfn(struct kvm_vcpu *vcpu, gfn_t gfn);
155 extern void kvmppc_add_revmap_chain(struct kvm *kvm, struct revmap_entry *rev,
156 unsigned long *rmap, long pte_index, int realmode);
157 extern void kvmppc_invalidate_hpte(struct kvm *kvm, unsigned long *hptep,
158 unsigned long pte_index);
159 void kvmppc_clear_ref_hpte(struct kvm *kvm, unsigned long *hptep,
160 unsigned long pte_index);
161 extern void *kvmppc_pin_guest_page(struct kvm *kvm, unsigned long addr,
162 unsigned long *nb_ret);
163 extern void kvmppc_unpin_guest_page(struct kvm *kvm, void *addr,
164 unsigned long gpa, bool dirty);
165 extern long kvmppc_virtmode_h_enter(struct kvm_vcpu *vcpu, unsigned long flags,
166 long pte_index, unsigned long pteh, unsigned long ptel);
167 extern long kvmppc_do_h_enter(struct kvm *kvm, unsigned long flags,
168 long pte_index, unsigned long pteh, unsigned long ptel,
169 pgd_t *pgdir, bool realmode, unsigned long *idx_ret);
170 extern long kvmppc_do_h_remove(struct kvm *kvm, unsigned long flags,
171 unsigned long pte_index, unsigned long avpn,
172 unsigned long *hpret);
173 extern long kvmppc_hv_get_dirty_log(struct kvm *kvm,
174 struct kvm_memory_slot *memslot, unsigned long *map);
176 extern void kvmppc_entry_trampoline(void);
177 extern void kvmppc_hv_entry_trampoline(void);
178 extern void kvmppc_load_up_fpu(void);
179 extern void kvmppc_load_up_altivec(void);
180 extern void kvmppc_load_up_vsx(void);
181 extern u32 kvmppc_alignment_dsisr(struct kvm_vcpu *vcpu, unsigned int inst);
182 extern ulong kvmppc_alignment_dar(struct kvm_vcpu *vcpu, unsigned int inst);
183 extern int kvmppc_h_pr(struct kvm_vcpu *vcpu, unsigned long cmd);
185 static inline struct kvmppc_vcpu_book3s *to_book3s(struct kvm_vcpu *vcpu)
187 return container_of(vcpu, struct kvmppc_vcpu_book3s, vcpu);
190 extern void kvm_return_point(void);
192 /* Also add subarch specific defines */
194 #ifdef CONFIG_KVM_BOOK3S_32_HANDLER
195 #include <asm/kvm_book3s_32.h>
196 #endif
197 #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
198 #include <asm/kvm_book3s_64.h>
199 #endif
201 #ifdef CONFIG_KVM_BOOK3S_PR
203 static inline unsigned long kvmppc_interrupt_offset(struct kvm_vcpu *vcpu)
205 return to_book3s(vcpu)->hior;
208 static inline void kvmppc_update_int_pending(struct kvm_vcpu *vcpu,
209 unsigned long pending_now, unsigned long old_pending)
211 if (pending_now)
212 vcpu->arch.shared->int_pending = 1;
213 else if (old_pending)
214 vcpu->arch.shared->int_pending = 0;
217 static inline void kvmppc_set_gpr(struct kvm_vcpu *vcpu, int num, ulong val)
219 if ( num < 14 ) {
220 struct kvmppc_book3s_shadow_vcpu *svcpu = svcpu_get(vcpu);
221 svcpu->gpr[num] = val;
222 svcpu_put(svcpu);
223 to_book3s(vcpu)->shadow_vcpu->gpr[num] = val;
224 } else
225 vcpu->arch.gpr[num] = val;
228 static inline ulong kvmppc_get_gpr(struct kvm_vcpu *vcpu, int num)
230 if ( num < 14 ) {
231 struct kvmppc_book3s_shadow_vcpu *svcpu = svcpu_get(vcpu);
232 ulong r = svcpu->gpr[num];
233 svcpu_put(svcpu);
234 return r;
235 } else
236 return vcpu->arch.gpr[num];
239 static inline void kvmppc_set_cr(struct kvm_vcpu *vcpu, u32 val)
241 struct kvmppc_book3s_shadow_vcpu *svcpu = svcpu_get(vcpu);
242 svcpu->cr = val;
243 svcpu_put(svcpu);
244 to_book3s(vcpu)->shadow_vcpu->cr = val;
247 static inline u32 kvmppc_get_cr(struct kvm_vcpu *vcpu)
249 struct kvmppc_book3s_shadow_vcpu *svcpu = svcpu_get(vcpu);
250 u32 r;
251 r = svcpu->cr;
252 svcpu_put(svcpu);
253 return r;
256 static inline void kvmppc_set_xer(struct kvm_vcpu *vcpu, u32 val)
258 struct kvmppc_book3s_shadow_vcpu *svcpu = svcpu_get(vcpu);
259 svcpu->xer = val;
260 to_book3s(vcpu)->shadow_vcpu->xer = val;
261 svcpu_put(svcpu);
264 static inline u32 kvmppc_get_xer(struct kvm_vcpu *vcpu)
266 struct kvmppc_book3s_shadow_vcpu *svcpu = svcpu_get(vcpu);
267 u32 r;
268 r = svcpu->xer;
269 svcpu_put(svcpu);
270 return r;
273 static inline void kvmppc_set_ctr(struct kvm_vcpu *vcpu, ulong val)
275 struct kvmppc_book3s_shadow_vcpu *svcpu = svcpu_get(vcpu);
276 svcpu->ctr = val;
277 svcpu_put(svcpu);
280 static inline ulong kvmppc_get_ctr(struct kvm_vcpu *vcpu)
282 struct kvmppc_book3s_shadow_vcpu *svcpu = svcpu_get(vcpu);
283 ulong r;
284 r = svcpu->ctr;
285 svcpu_put(svcpu);
286 return r;
289 static inline void kvmppc_set_lr(struct kvm_vcpu *vcpu, ulong val)
291 struct kvmppc_book3s_shadow_vcpu *svcpu = svcpu_get(vcpu);
292 svcpu->lr = val;
293 svcpu_put(svcpu);
296 static inline ulong kvmppc_get_lr(struct kvm_vcpu *vcpu)
298 struct kvmppc_book3s_shadow_vcpu *svcpu = svcpu_get(vcpu);
299 ulong r;
300 r = svcpu->lr;
301 svcpu_put(svcpu);
302 return r;
305 static inline void kvmppc_set_pc(struct kvm_vcpu *vcpu, ulong val)
307 struct kvmppc_book3s_shadow_vcpu *svcpu = svcpu_get(vcpu);
308 svcpu->pc = val;
309 svcpu_put(svcpu);
312 static inline ulong kvmppc_get_pc(struct kvm_vcpu *vcpu)
314 struct kvmppc_book3s_shadow_vcpu *svcpu = svcpu_get(vcpu);
315 ulong r;
316 r = svcpu->pc;
317 svcpu_put(svcpu);
318 return r;
321 static inline u32 kvmppc_get_last_inst(struct kvm_vcpu *vcpu)
323 ulong pc = kvmppc_get_pc(vcpu);
324 struct kvmppc_book3s_shadow_vcpu *svcpu = svcpu_get(vcpu);
325 u32 r;
327 /* Load the instruction manually if it failed to do so in the
328 * exit path */
329 if (svcpu->last_inst == KVM_INST_FETCH_FAILED)
330 kvmppc_ld(vcpu, &pc, sizeof(u32), &svcpu->last_inst, false);
332 r = svcpu->last_inst;
333 svcpu_put(svcpu);
334 return r;
338 * Like kvmppc_get_last_inst(), but for fetching a sc instruction.
339 * Because the sc instruction sets SRR0 to point to the following
340 * instruction, we have to fetch from pc - 4.
342 static inline u32 kvmppc_get_last_sc(struct kvm_vcpu *vcpu)
344 ulong pc = kvmppc_get_pc(vcpu) - 4;
345 struct kvmppc_book3s_shadow_vcpu *svcpu = svcpu_get(vcpu);
346 u32 r;
348 /* Load the instruction manually if it failed to do so in the
349 * exit path */
350 if (svcpu->last_inst == KVM_INST_FETCH_FAILED)
351 kvmppc_ld(vcpu, &pc, sizeof(u32), &svcpu->last_inst, false);
353 r = svcpu->last_inst;
354 svcpu_put(svcpu);
355 return r;
358 static inline ulong kvmppc_get_fault_dar(struct kvm_vcpu *vcpu)
360 struct kvmppc_book3s_shadow_vcpu *svcpu = svcpu_get(vcpu);
361 ulong r;
362 r = svcpu->fault_dar;
363 svcpu_put(svcpu);
364 return r;
367 static inline bool kvmppc_critical_section(struct kvm_vcpu *vcpu)
369 ulong crit_raw = vcpu->arch.shared->critical;
370 ulong crit_r1 = kvmppc_get_gpr(vcpu, 1);
371 bool crit;
373 /* Truncate crit indicators in 32 bit mode */
374 if (!(vcpu->arch.shared->msr & MSR_SF)) {
375 crit_raw &= 0xffffffff;
376 crit_r1 &= 0xffffffff;
379 /* Critical section when crit == r1 */
380 crit = (crit_raw == crit_r1);
381 /* ... and we're in supervisor mode */
382 crit = crit && !(vcpu->arch.shared->msr & MSR_PR);
384 return crit;
386 #else /* CONFIG_KVM_BOOK3S_PR */
388 static inline unsigned long kvmppc_interrupt_offset(struct kvm_vcpu *vcpu)
390 return 0;
393 static inline void kvmppc_update_int_pending(struct kvm_vcpu *vcpu,
394 unsigned long pending_now, unsigned long old_pending)
398 static inline void kvmppc_set_gpr(struct kvm_vcpu *vcpu, int num, ulong val)
400 vcpu->arch.gpr[num] = val;
403 static inline ulong kvmppc_get_gpr(struct kvm_vcpu *vcpu, int num)
405 return vcpu->arch.gpr[num];
408 static inline void kvmppc_set_cr(struct kvm_vcpu *vcpu, u32 val)
410 vcpu->arch.cr = val;
413 static inline u32 kvmppc_get_cr(struct kvm_vcpu *vcpu)
415 return vcpu->arch.cr;
418 static inline void kvmppc_set_xer(struct kvm_vcpu *vcpu, u32 val)
420 vcpu->arch.xer = val;
423 static inline u32 kvmppc_get_xer(struct kvm_vcpu *vcpu)
425 return vcpu->arch.xer;
428 static inline void kvmppc_set_ctr(struct kvm_vcpu *vcpu, ulong val)
430 vcpu->arch.ctr = val;
433 static inline ulong kvmppc_get_ctr(struct kvm_vcpu *vcpu)
435 return vcpu->arch.ctr;
438 static inline void kvmppc_set_lr(struct kvm_vcpu *vcpu, ulong val)
440 vcpu->arch.lr = val;
443 static inline ulong kvmppc_get_lr(struct kvm_vcpu *vcpu)
445 return vcpu->arch.lr;
448 static inline void kvmppc_set_pc(struct kvm_vcpu *vcpu, ulong val)
450 vcpu->arch.pc = val;
453 static inline ulong kvmppc_get_pc(struct kvm_vcpu *vcpu)
455 return vcpu->arch.pc;
458 static inline u32 kvmppc_get_last_inst(struct kvm_vcpu *vcpu)
460 ulong pc = kvmppc_get_pc(vcpu);
462 /* Load the instruction manually if it failed to do so in the
463 * exit path */
464 if (vcpu->arch.last_inst == KVM_INST_FETCH_FAILED)
465 kvmppc_ld(vcpu, &pc, sizeof(u32), &vcpu->arch.last_inst, false);
467 return vcpu->arch.last_inst;
471 * Like kvmppc_get_last_inst(), but for fetching a sc instruction.
472 * Because the sc instruction sets SRR0 to point to the following
473 * instruction, we have to fetch from pc - 4.
475 static inline u32 kvmppc_get_last_sc(struct kvm_vcpu *vcpu)
477 ulong pc = kvmppc_get_pc(vcpu) - 4;
479 /* Load the instruction manually if it failed to do so in the
480 * exit path */
481 if (vcpu->arch.last_inst == KVM_INST_FETCH_FAILED)
482 kvmppc_ld(vcpu, &pc, sizeof(u32), &vcpu->arch.last_inst, false);
484 return vcpu->arch.last_inst;
487 static inline ulong kvmppc_get_fault_dar(struct kvm_vcpu *vcpu)
489 return vcpu->arch.fault_dar;
492 static inline bool kvmppc_critical_section(struct kvm_vcpu *vcpu)
494 return false;
496 #endif
498 /* Magic register values loaded into r3 and r4 before the 'sc' assembly
499 * instruction for the OSI hypercalls */
500 #define OSI_SC_MAGIC_R3 0x113724FA
501 #define OSI_SC_MAGIC_R4 0x77810F9B
503 #define INS_DCBZ 0x7c0007ec
504 /* TO = 31 for unconditional trap */
505 #define INS_TW 0x7fe00008
507 /* LPIDs we support with this build -- runtime limit may be lower */
508 #define KVMPPC_NR_LPIDS (LPID_RSVD + 1)
510 #endif /* __ASM_KVM_BOOK3S_H__ */