2 * PPC Huge TLB Page Support for Book3E MMU
4 * Copyright (C) 2009 David Gibson, IBM Corporation.
5 * Copyright (C) 2011 Becky Bruce, Freescale Semiconductor
9 #include <linux/hugetlb.h>
11 static inline int mmu_get_tsize(int psize
)
13 return mmu_psize_defs
[psize
].enc
;
16 static inline int book3e_tlb_exists(unsigned long ea
, unsigned long pid
)
20 mtspr(SPRN_MAS6
, pid
<< 16);
21 if (mmu_has_feature(MMU_FTR_USE_TLBRSRV
)) {
28 : "=&r"(found
) : "r"(ea
));
34 : "=&r"(found
) : "r"(ea
));
40 void book3e_hugetlb_preload(struct vm_area_struct
*vma
, unsigned long ea
,
43 unsigned long mas1
, mas2
;
45 unsigned long psize
, tsize
, shift
;
49 #ifdef CONFIG_PPC_FSL_BOOK3E
53 if (unlikely(is_kernel_addr(ea
)))
58 #ifdef CONFIG_PPC_MM_SLICES
59 psize
= get_slice_psize(mm
, ea
);
60 tsize
= mmu_get_tsize(psize
);
61 shift
= mmu_psize_defs
[psize
].shift
;
63 psize
= vma_mmu_pagesize(vma
);
64 shift
= __ilog2(psize
);
69 * We can't be interrupted while we're setting up the MAS
70 * regusters or after we've confirmed that no tlb exists.
72 local_irq_save(flags
);
74 if (unlikely(book3e_tlb_exists(ea
, mm
->context
.id
))) {
75 local_irq_restore(flags
);
79 #ifdef CONFIG_PPC_FSL_BOOK3E
80 ncams
= mfspr(SPRN_TLB1CFG
) & TLBnCFG_N_ENTRY
;
82 /* We have to use the CAM(TLB1) on FSL parts for hugepages */
83 index
= __get_cpu_var(next_tlbcam_idx
);
84 mtspr(SPRN_MAS0
, MAS0_ESEL(index
) | MAS0_TLBSEL(1));
86 /* Just round-robin the entries and wrap when we hit the end */
87 if (unlikely(index
== ncams
- 1))
88 __get_cpu_var(next_tlbcam_idx
) = tlbcam_index
;
90 __get_cpu_var(next_tlbcam_idx
)++;
92 mas1
= MAS1_VALID
| MAS1_TID(mm
->context
.id
) | MAS1_TSIZE(tsize
);
93 mas2
= ea
& ~((1UL << shift
) - 1);
94 mas2
|= (pte_val(pte
) >> PTE_WIMGE_SHIFT
) & MAS2_WIMGE_MASK
;
95 mas7_3
= (u64
)pte_pfn(pte
) << PAGE_SHIFT
;
96 mas7_3
|= (pte_val(pte
) >> PTE_BAP_SHIFT
) & MAS3_BAP_MASK
;
98 mas7_3
&= ~(MAS3_SW
|MAS3_UW
);
100 mtspr(SPRN_MAS1
, mas1
);
101 mtspr(SPRN_MAS2
, mas2
);
103 if (mmu_has_feature(MMU_FTR_USE_PAIRED_MAS
)) {
104 mtspr(SPRN_MAS7_MAS3
, mas7_3
);
106 mtspr(SPRN_MAS7
, upper_32_bits(mas7_3
));
107 mtspr(SPRN_MAS3
, lower_32_bits(mas7_3
));
110 asm volatile ("tlbwe");
112 local_irq_restore(flags
);
115 void flush_hugetlb_page(struct vm_area_struct
*vma
, unsigned long vmaddr
)
117 struct hstate
*hstate
= hstate_file(vma
->vm_file
);
118 unsigned long tsize
= huge_page_shift(hstate
) - 10;
120 __flush_tlb_page(vma
? vma
->vm_mm
: NULL
, vmaddr
, tsize
, 0);