2 * Copyright (C) 2008-2011 Freescale Semiconductor, Inc. All rights reserved.
4 * Author: Yu Liu, yu.liu@freescale.com
7 * This file is based on arch/powerpc/kvm/44x_tlb.c,
8 * by Hollis Blanchard <hollisb@us.ibm.com>.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License, version 2, as
12 * published by the Free Software Foundation.
15 #include <linux/types.h>
16 #include <linux/slab.h>
17 #include <linux/string.h>
18 #include <linux/kvm.h>
19 #include <linux/kvm_host.h>
20 #include <linux/highmem.h>
21 #include <asm/kvm_ppc.h>
22 #include <asm/kvm_e500.h>
24 #include "../mm/mmu_decl.h"
29 #define to_htlb1_esel(esel) (tlb1_entry_num - (esel) - 1)
31 static unsigned int tlb1_entry_num;
33 void kvmppc_dump_tlbs(struct kvm_vcpu *vcpu)
35 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
39 printk("| %8s | %8s | %8s | %8s | %8s |\n",
40 "nr", "mas1", "mas2", "mas3", "mas7");
42 for (tlbsel = 0; tlbsel < 2; tlbsel++) {
43 printk("Guest TLB%d:\n", tlbsel);
44 for (i = 0; i < vcpu_e500->guest_tlb_size[tlbsel]; i++) {
45 tlbe = &vcpu_e500->guest_tlb[tlbsel][i];
46 if (tlbe->mas1 & MAS1_VALID)
47 printk(" G[%d][%3d] | %08X | %08X | %08X | %08X |\n",
48 tlbsel, i, tlbe->mas1, tlbe->mas2,
49 tlbe->mas3, tlbe->mas7);
53 for (tlbsel = 0; tlbsel < 2; tlbsel++) {
54 printk("Shadow TLB%d:\n", tlbsel);
55 for (i = 0; i < vcpu_e500->shadow_tlb_size[tlbsel]; i++) {
56 tlbe = &vcpu_e500->shadow_tlb[tlbsel][i];
57 if (tlbe->mas1 & MAS1_VALID)
58 printk(" S[%d][%3d] | %08X | %08X | %08X | %08X |\n",
59 tlbsel, i, tlbe->mas1, tlbe->mas2,
60 tlbe->mas3, tlbe->mas7);
65 static inline unsigned int tlb0_get_next_victim(
66 struct kvmppc_vcpu_e500 *vcpu_e500)
70 victim = vcpu_e500->guest_tlb_nv[0]++;
71 if (unlikely(vcpu_e500->guest_tlb_nv[0] >= KVM_E500_TLB0_WAY_NUM))
72 vcpu_e500->guest_tlb_nv[0] = 0;
77 static inline unsigned int tlb1_max_shadow_size(void)
79 return tlb1_entry_num - tlbcam_index;
82 static inline int tlbe_is_writable(struct tlbe *tlbe)
84 return tlbe->mas3 & (MAS3_SW|MAS3_UW);
87 static inline u32 e500_shadow_mas3_attrib(u32 mas3, int usermode)
89 /* Mask off reserved bits. */
90 mas3 &= MAS3_ATTRIB_MASK;
93 /* Guest is in supervisor mode,
94 * so we need to translate guest
95 * supervisor permissions into user permissions. */
96 mas3 &= ~E500_TLB_USER_PERM_MASK;
97 mas3 |= (mas3 & E500_TLB_SUPER_PERM_MASK) << 1;
100 return mas3 | E500_TLB_SUPER_PERM_MASK;
103 static inline u32 e500_shadow_mas2_attrib(u32 mas2, int usermode)
106 return (mas2 & MAS2_ATTRIB_MASK) | MAS2_M;
108 return mas2 & MAS2_ATTRIB_MASK;
113 * writing shadow tlb entry to host TLB
115 static inline void __write_host_tlbe(struct tlbe *stlbe)
117 mtspr(SPRN_MAS1, stlbe->mas1);
118 mtspr(SPRN_MAS2, stlbe->mas2);
119 mtspr(SPRN_MAS3, stlbe->mas3);
120 mtspr(SPRN_MAS7, stlbe->mas7);
121 __asm__ __volatile__ ("tlbwe\n" : : );
124 static inline void write_host_tlbe(struct kvmppc_vcpu_e500 *vcpu_e500,
125 int tlbsel, int esel)
127 struct tlbe *stlbe = &vcpu_e500->shadow_tlb[tlbsel][esel];
131 __write_host_tlbe(stlbe);
133 unsigned register mas0;
135 mas0 = mfspr(SPRN_MAS0);
137 mtspr(SPRN_MAS0, MAS0_TLBSEL(1) | MAS0_ESEL(to_htlb1_esel(esel)));
138 __write_host_tlbe(stlbe);
140 mtspr(SPRN_MAS0, mas0);
145 void kvmppc_e500_tlb_load(struct kvm_vcpu *vcpu, int cpu)
149 void kvmppc_e500_tlb_put(struct kvm_vcpu *vcpu)
154 /* Search the guest TLB for a matching entry. */
155 static int kvmppc_e500_tlb_index(struct kvmppc_vcpu_e500 *vcpu_e500,
156 gva_t eaddr, int tlbsel, unsigned int pid, int as)
160 /* XXX Replace loop with fancy data structures. */
161 for (i = 0; i < vcpu_e500->guest_tlb_size[tlbsel]; i++) {
162 struct tlbe *tlbe = &vcpu_e500->guest_tlb[tlbsel][i];
165 if (eaddr < get_tlb_eaddr(tlbe))
168 if (eaddr > get_tlb_end(tlbe))
171 tid = get_tlb_tid(tlbe);
172 if (tid && (tid != pid))
175 if (!get_tlb_v(tlbe))
178 if (get_tlb_ts(tlbe) != as && as != -1)
187 static void kvmppc_e500_shadow_release(struct kvmppc_vcpu_e500 *vcpu_e500,
188 int tlbsel, int esel)
190 struct tlbe *stlbe = &vcpu_e500->shadow_tlb[tlbsel][esel];
191 struct page *page = vcpu_e500->shadow_pages[tlbsel][esel];
194 vcpu_e500->shadow_pages[tlbsel][esel] = NULL;
196 if (get_tlb_v(stlbe)) {
197 if (tlbe_is_writable(stlbe))
198 kvm_release_page_dirty(page);
200 kvm_release_page_clean(page);
205 static void kvmppc_e500_stlbe_invalidate(struct kvmppc_vcpu_e500 *vcpu_e500,
206 int tlbsel, int esel)
208 struct tlbe *stlbe = &vcpu_e500->shadow_tlb[tlbsel][esel];
210 kvmppc_e500_shadow_release(vcpu_e500, tlbsel, esel);
212 trace_kvm_stlb_inval(index_of(tlbsel, esel));
215 static void kvmppc_e500_tlb1_invalidate(struct kvmppc_vcpu_e500 *vcpu_e500,
216 gva_t eaddr, gva_t eend, u32 tid)
218 unsigned int pid = tid & 0xff;
221 /* XXX Replace loop with fancy data structures. */
222 for (i = 0; i < vcpu_e500->guest_tlb_size[1]; i++) {
223 struct tlbe *stlbe = &vcpu_e500->shadow_tlb[1][i];
226 if (!get_tlb_v(stlbe))
229 if (eend < get_tlb_eaddr(stlbe))
232 if (eaddr > get_tlb_end(stlbe))
235 tid = get_tlb_tid(stlbe);
236 if (tid && (tid != pid))
239 kvmppc_e500_stlbe_invalidate(vcpu_e500, 1, i);
240 write_host_tlbe(vcpu_e500, 1, i);
244 static inline void kvmppc_e500_deliver_tlb_miss(struct kvm_vcpu *vcpu,
245 unsigned int eaddr, int as)
247 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
248 unsigned int victim, pidsel, tsized;
251 /* since we only have two TLBs, only lower bit is used. */
252 tlbsel = (vcpu_e500->mas4 >> 28) & 0x1;
253 victim = (tlbsel == 0) ? tlb0_get_next_victim(vcpu_e500) : 0;
254 pidsel = (vcpu_e500->mas4 >> 16) & 0xf;
255 tsized = (vcpu_e500->mas4 >> 7) & 0x1f;
257 vcpu_e500->mas0 = MAS0_TLBSEL(tlbsel) | MAS0_ESEL(victim)
258 | MAS0_NV(vcpu_e500->guest_tlb_nv[tlbsel]);
259 vcpu_e500->mas1 = MAS1_VALID | (as ? MAS1_TS : 0)
260 | MAS1_TID(vcpu_e500->pid[pidsel])
261 | MAS1_TSIZE(tsized);
262 vcpu_e500->mas2 = (eaddr & MAS2_EPN)
263 | (vcpu_e500->mas4 & MAS2_ATTRIB_MASK);
264 vcpu_e500->mas3 &= MAS3_U0 | MAS3_U1 | MAS3_U2 | MAS3_U3;
265 vcpu_e500->mas6 = (vcpu_e500->mas6 & MAS6_SPID1)
266 | (get_cur_pid(vcpu) << 16)
267 | (as ? MAS6_SAS : 0);
271 static inline void kvmppc_e500_shadow_map(struct kvmppc_vcpu_e500 *vcpu_e500,
272 u64 gvaddr, gfn_t gfn, struct tlbe *gtlbe, int tlbsel, int esel)
274 struct page *new_page;
278 stlbe = &vcpu_e500->shadow_tlb[tlbsel][esel];
280 /* Get reference to new page. */
281 new_page = gfn_to_page(vcpu_e500->vcpu.kvm, gfn);
282 if (is_error_page(new_page)) {
283 printk(KERN_ERR "Couldn't get guest page for gfn %lx!\n",
285 kvm_release_page_clean(new_page);
288 hpaddr = page_to_phys(new_page);
290 /* Drop reference to old page. */
291 kvmppc_e500_shadow_release(vcpu_e500, tlbsel, esel);
293 vcpu_e500->shadow_pages[tlbsel][esel] = new_page;
295 /* Force TS=1 IPROT=0 TSIZE=4KB for all guest mappings. */
296 stlbe->mas1 = MAS1_TSIZE(BOOK3E_PAGESZ_4K)
297 | MAS1_TID(get_tlb_tid(gtlbe)) | MAS1_TS | MAS1_VALID;
298 stlbe->mas2 = (gvaddr & MAS2_EPN)
299 | e500_shadow_mas2_attrib(gtlbe->mas2,
300 vcpu_e500->vcpu.arch.shared->msr & MSR_PR);
301 stlbe->mas3 = (hpaddr & MAS3_RPN)
302 | e500_shadow_mas3_attrib(gtlbe->mas3,
303 vcpu_e500->vcpu.arch.shared->msr & MSR_PR);
304 stlbe->mas7 = (hpaddr >> 32) & MAS7_RPN;
306 trace_kvm_stlb_write(index_of(tlbsel, esel), stlbe->mas1, stlbe->mas2,
307 stlbe->mas3, stlbe->mas7);
310 /* XXX only map the one-one case, for now use TLB0 */
311 static int kvmppc_e500_stlbe_map(struct kvmppc_vcpu_e500 *vcpu_e500,
312 int tlbsel, int esel)
316 gtlbe = &vcpu_e500->guest_tlb[tlbsel][esel];
318 kvmppc_e500_shadow_map(vcpu_e500, get_tlb_eaddr(gtlbe),
319 get_tlb_raddr(gtlbe) >> PAGE_SHIFT,
320 gtlbe, tlbsel, esel);
325 /* Caller must ensure that the specified guest TLB entry is safe to insert into
327 /* XXX for both one-one and one-to-many , for now use TLB1 */
328 static int kvmppc_e500_tlb1_map(struct kvmppc_vcpu_e500 *vcpu_e500,
329 u64 gvaddr, gfn_t gfn, struct tlbe *gtlbe)
333 victim = vcpu_e500->guest_tlb_nv[1]++;
335 if (unlikely(vcpu_e500->guest_tlb_nv[1] >= tlb1_max_shadow_size()))
336 vcpu_e500->guest_tlb_nv[1] = 0;
338 kvmppc_e500_shadow_map(vcpu_e500, gvaddr, gfn, gtlbe, 1, victim);
343 /* Invalidate all guest kernel mappings when enter usermode,
344 * so that when they fault back in they will get the
345 * proper permission bits. */
346 void kvmppc_mmu_priv_switch(struct kvm_vcpu *vcpu, int usermode)
349 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
352 /* XXX Replace loop with fancy data structures. */
353 for (i = 0; i < tlb1_max_shadow_size(); i++)
354 kvmppc_e500_stlbe_invalidate(vcpu_e500, 1, i);
360 static int kvmppc_e500_gtlbe_invalidate(struct kvmppc_vcpu_e500 *vcpu_e500,
361 int tlbsel, int esel)
363 struct tlbe *gtlbe = &vcpu_e500->guest_tlb[tlbsel][esel];
365 if (unlikely(get_tlb_iprot(gtlbe)))
369 kvmppc_e500_tlb1_invalidate(vcpu_e500, get_tlb_eaddr(gtlbe),
373 kvmppc_e500_stlbe_invalidate(vcpu_e500, tlbsel, esel);
381 int kvmppc_e500_emul_mt_mmucsr0(struct kvmppc_vcpu_e500 *vcpu_e500, ulong value)
385 if (value & MMUCSR0_TLB0FI)
386 for (esel = 0; esel < vcpu_e500->guest_tlb_size[0]; esel++)
387 kvmppc_e500_gtlbe_invalidate(vcpu_e500, 0, esel);
388 if (value & MMUCSR0_TLB1FI)
389 for (esel = 0; esel < vcpu_e500->guest_tlb_size[1]; esel++)
390 kvmppc_e500_gtlbe_invalidate(vcpu_e500, 1, esel);
397 int kvmppc_e500_emul_tlbivax(struct kvm_vcpu *vcpu, int ra, int rb)
399 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
404 ea = ((ra) ? kvmppc_get_gpr(vcpu, ra) : 0) + kvmppc_get_gpr(vcpu, rb);
406 ia = (ea >> 2) & 0x1;
408 /* since we only have two TLBs, only lower bit is used. */
409 tlbsel = (ea >> 3) & 0x1;
412 /* invalidate all entries */
413 for (esel = 0; esel < vcpu_e500->guest_tlb_size[tlbsel]; esel++)
414 kvmppc_e500_gtlbe_invalidate(vcpu_e500, tlbsel, esel);
417 esel = kvmppc_e500_tlb_index(vcpu_e500, ea, tlbsel,
418 get_cur_pid(vcpu), -1);
420 kvmppc_e500_gtlbe_invalidate(vcpu_e500, tlbsel, esel);
428 int kvmppc_e500_emul_tlbre(struct kvm_vcpu *vcpu)
430 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
434 tlbsel = get_tlb_tlbsel(vcpu_e500);
435 esel = get_tlb_esel(vcpu_e500, tlbsel);
437 gtlbe = &vcpu_e500->guest_tlb[tlbsel][esel];
438 vcpu_e500->mas0 &= ~MAS0_NV(~0);
439 vcpu_e500->mas0 |= MAS0_NV(vcpu_e500->guest_tlb_nv[tlbsel]);
440 vcpu_e500->mas1 = gtlbe->mas1;
441 vcpu_e500->mas2 = gtlbe->mas2;
442 vcpu_e500->mas3 = gtlbe->mas3;
443 vcpu_e500->mas7 = gtlbe->mas7;
448 int kvmppc_e500_emul_tlbsx(struct kvm_vcpu *vcpu, int rb)
450 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
451 int as = !!get_cur_sas(vcpu_e500);
452 unsigned int pid = get_cur_spid(vcpu_e500);
454 struct tlbe *gtlbe = NULL;
457 ea = kvmppc_get_gpr(vcpu, rb);
459 for (tlbsel = 0; tlbsel < 2; tlbsel++) {
460 esel = kvmppc_e500_tlb_index(vcpu_e500, ea, tlbsel, pid, as);
462 gtlbe = &vcpu_e500->guest_tlb[tlbsel][esel];
468 vcpu_e500->mas0 = MAS0_TLBSEL(tlbsel) | MAS0_ESEL(esel)
469 | MAS0_NV(vcpu_e500->guest_tlb_nv[tlbsel]);
470 vcpu_e500->mas1 = gtlbe->mas1;
471 vcpu_e500->mas2 = gtlbe->mas2;
472 vcpu_e500->mas3 = gtlbe->mas3;
473 vcpu_e500->mas7 = gtlbe->mas7;
477 /* since we only have two TLBs, only lower bit is used. */
478 tlbsel = vcpu_e500->mas4 >> 28 & 0x1;
479 victim = (tlbsel == 0) ? tlb0_get_next_victim(vcpu_e500) : 0;
481 vcpu_e500->mas0 = MAS0_TLBSEL(tlbsel) | MAS0_ESEL(victim)
482 | MAS0_NV(vcpu_e500->guest_tlb_nv[tlbsel]);
483 vcpu_e500->mas1 = (vcpu_e500->mas6 & MAS6_SPID0)
484 | (vcpu_e500->mas6 & (MAS6_SAS ? MAS1_TS : 0))
485 | (vcpu_e500->mas4 & MAS4_TSIZED(~0));
486 vcpu_e500->mas2 &= MAS2_EPN;
487 vcpu_e500->mas2 |= vcpu_e500->mas4 & MAS2_ATTRIB_MASK;
488 vcpu_e500->mas3 &= MAS3_U0 | MAS3_U1 | MAS3_U2 | MAS3_U3;
492 kvmppc_set_exit_type(vcpu, EMULATED_TLBSX_EXITS);
496 int kvmppc_e500_emul_tlbwe(struct kvm_vcpu *vcpu)
498 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
503 int tlbsel, esel, stlbsel, sesel;
505 tlbsel = get_tlb_tlbsel(vcpu_e500);
506 esel = get_tlb_esel(vcpu_e500, tlbsel);
508 gtlbe = &vcpu_e500->guest_tlb[tlbsel][esel];
510 if (get_tlb_v(gtlbe) && tlbsel == 1) {
511 eaddr = get_tlb_eaddr(gtlbe);
512 tid = get_tlb_tid(gtlbe);
513 kvmppc_e500_tlb1_invalidate(vcpu_e500, eaddr,
514 get_tlb_end(gtlbe), tid);
517 gtlbe->mas1 = vcpu_e500->mas1;
518 gtlbe->mas2 = vcpu_e500->mas2;
519 gtlbe->mas3 = vcpu_e500->mas3;
520 gtlbe->mas7 = vcpu_e500->mas7;
522 trace_kvm_gtlb_write(vcpu_e500->mas0, gtlbe->mas1, gtlbe->mas2,
523 gtlbe->mas3, gtlbe->mas7);
525 /* Invalidate shadow mappings for the about-to-be-clobbered TLBE. */
526 if (tlbe_is_host_safe(vcpu, gtlbe)) {
530 gtlbe->mas1 &= ~MAS1_TSIZE(~0);
531 gtlbe->mas1 |= MAS1_TSIZE(BOOK3E_PAGESZ_4K);
534 sesel = kvmppc_e500_stlbe_map(vcpu_e500, 0, esel);
540 eaddr = get_tlb_eaddr(gtlbe);
541 raddr = get_tlb_raddr(gtlbe);
543 /* Create a 4KB mapping on the host.
544 * If the guest wanted a large page,
545 * only the first 4KB is mapped here and the rest
546 * are mapped on the fly. */
548 sesel = kvmppc_e500_tlb1_map(vcpu_e500, eaddr,
549 raddr >> PAGE_SHIFT, gtlbe);
555 write_host_tlbe(vcpu_e500, stlbsel, sesel);
558 kvmppc_set_exit_type(vcpu, EMULATED_TLBWE_EXITS);
562 int kvmppc_mmu_itlb_index(struct kvm_vcpu *vcpu, gva_t eaddr)
564 unsigned int as = !!(vcpu->arch.shared->msr & MSR_IS);
566 return kvmppc_e500_tlb_search(vcpu, eaddr, get_cur_pid(vcpu), as);
569 int kvmppc_mmu_dtlb_index(struct kvm_vcpu *vcpu, gva_t eaddr)
571 unsigned int as = !!(vcpu->arch.shared->msr & MSR_DS);
573 return kvmppc_e500_tlb_search(vcpu, eaddr, get_cur_pid(vcpu), as);
576 void kvmppc_mmu_itlb_miss(struct kvm_vcpu *vcpu)
578 unsigned int as = !!(vcpu->arch.shared->msr & MSR_IS);
580 kvmppc_e500_deliver_tlb_miss(vcpu, vcpu->arch.pc, as);
583 void kvmppc_mmu_dtlb_miss(struct kvm_vcpu *vcpu)
585 unsigned int as = !!(vcpu->arch.shared->msr & MSR_DS);
587 kvmppc_e500_deliver_tlb_miss(vcpu, vcpu->arch.fault_dear, as);
590 gpa_t kvmppc_mmu_xlate(struct kvm_vcpu *vcpu, unsigned int index,
593 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
595 &vcpu_e500->guest_tlb[tlbsel_of(index)][esel_of(index)];
596 u64 pgmask = get_tlb_bytes(gtlbe) - 1;
598 return get_tlb_raddr(gtlbe) | (eaddr & pgmask);
601 void kvmppc_mmu_destroy(struct kvm_vcpu *vcpu)
603 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
606 for (tlbsel = 0; tlbsel < 2; tlbsel++)
607 for (i = 0; i < vcpu_e500->guest_tlb_size[tlbsel]; i++)
608 kvmppc_e500_shadow_release(vcpu_e500, tlbsel, i);
610 /* discard all guest mapping */
614 void kvmppc_mmu_map(struct kvm_vcpu *vcpu, u64 eaddr, gpa_t gpaddr,
617 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
618 int tlbsel = tlbsel_of(index);
619 int esel = esel_of(index);
629 gfn_t gfn = gpaddr >> PAGE_SHIFT;
631 = &vcpu_e500->guest_tlb[tlbsel][esel];
634 sesel = kvmppc_e500_tlb1_map(vcpu_e500, eaddr, gfn, gtlbe);
642 write_host_tlbe(vcpu_e500, stlbsel, sesel);
645 int kvmppc_e500_tlb_search(struct kvm_vcpu *vcpu,
646 gva_t eaddr, unsigned int pid, int as)
648 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
651 for (tlbsel = 0; tlbsel < 2; tlbsel++) {
652 esel = kvmppc_e500_tlb_index(vcpu_e500, eaddr, tlbsel, pid, as);
654 return index_of(tlbsel, esel);
660 void kvmppc_set_pid(struct kvm_vcpu *vcpu, u32 pid)
662 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
664 vcpu_e500->pid[0] = vcpu->arch.shadow_pid =
665 vcpu->arch.pid = pid;
668 void kvmppc_e500_tlb_setup(struct kvmppc_vcpu_e500 *vcpu_e500)
672 /* Insert large initial mapping for guest. */
673 tlbe = &vcpu_e500->guest_tlb[1][0];
674 tlbe->mas1 = MAS1_VALID | MAS1_TSIZE(BOOK3E_PAGESZ_256M);
676 tlbe->mas3 = E500_TLB_SUPER_PERM_MASK;
679 /* 4K map for serial output. Used by kernel wrapper. */
680 tlbe = &vcpu_e500->guest_tlb[1][1];
681 tlbe->mas1 = MAS1_VALID | MAS1_TSIZE(BOOK3E_PAGESZ_4K);
682 tlbe->mas2 = (0xe0004500 & 0xFFFFF000) | MAS2_I | MAS2_G;
683 tlbe->mas3 = (0xe0004500 & 0xFFFFF000) | E500_TLB_SUPER_PERM_MASK;
687 int kvmppc_e500_tlb_init(struct kvmppc_vcpu_e500 *vcpu_e500)
689 tlb1_entry_num = mfspr(SPRN_TLB1CFG) & 0xFFF;
691 vcpu_e500->guest_tlb_size[0] = KVM_E500_TLB0_SIZE;
692 vcpu_e500->guest_tlb[0] =
693 kzalloc(sizeof(struct tlbe) * KVM_E500_TLB0_SIZE, GFP_KERNEL);
694 if (vcpu_e500->guest_tlb[0] == NULL)
697 vcpu_e500->shadow_tlb_size[0] = KVM_E500_TLB0_SIZE;
698 vcpu_e500->shadow_tlb[0] =
699 kzalloc(sizeof(struct tlbe) * KVM_E500_TLB0_SIZE, GFP_KERNEL);
700 if (vcpu_e500->shadow_tlb[0] == NULL)
703 vcpu_e500->guest_tlb_size[1] = KVM_E500_TLB1_SIZE;
704 vcpu_e500->guest_tlb[1] =
705 kzalloc(sizeof(struct tlbe) * KVM_E500_TLB1_SIZE, GFP_KERNEL);
706 if (vcpu_e500->guest_tlb[1] == NULL)
707 goto err_out_shadow0;
709 vcpu_e500->shadow_tlb_size[1] = tlb1_entry_num;
710 vcpu_e500->shadow_tlb[1] =
711 kzalloc(sizeof(struct tlbe) * tlb1_entry_num, GFP_KERNEL);
712 if (vcpu_e500->shadow_tlb[1] == NULL)
715 vcpu_e500->shadow_pages[0] = (struct page **)
716 kzalloc(sizeof(struct page *) * KVM_E500_TLB0_SIZE, GFP_KERNEL);
717 if (vcpu_e500->shadow_pages[0] == NULL)
718 goto err_out_shadow1;
720 vcpu_e500->shadow_pages[1] = (struct page **)
721 kzalloc(sizeof(struct page *) * tlb1_entry_num, GFP_KERNEL);
722 if (vcpu_e500->shadow_pages[1] == NULL)
725 /* Init TLB configuration register */
726 vcpu_e500->tlb0cfg = mfspr(SPRN_TLB0CFG) & ~0xfffUL;
727 vcpu_e500->tlb0cfg |= vcpu_e500->guest_tlb_size[0];
728 vcpu_e500->tlb1cfg = mfspr(SPRN_TLB1CFG) & ~0xfffUL;
729 vcpu_e500->tlb1cfg |= vcpu_e500->guest_tlb_size[1];
734 kfree(vcpu_e500->shadow_pages[0]);
736 kfree(vcpu_e500->shadow_tlb[1]);
738 kfree(vcpu_e500->guest_tlb[1]);
740 kfree(vcpu_e500->shadow_tlb[0]);
742 kfree(vcpu_e500->guest_tlb[0]);
747 void kvmppc_e500_tlb_uninit(struct kvmppc_vcpu_e500 *vcpu_e500)
749 kfree(vcpu_e500->shadow_pages[1]);
750 kfree(vcpu_e500->shadow_pages[0]);
751 kfree(vcpu_e500->shadow_tlb[1]);
752 kfree(vcpu_e500->guest_tlb[1]);
753 kfree(vcpu_e500->shadow_tlb[0]);
754 kfree(vcpu_e500->guest_tlb[0]);