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 #ifdef CONFIG_PPC_FSL_BOOK3E
13 static inline int tlb1_next(void)
15 struct paca_struct *paca = get_paca();
16 struct tlb_core_data *tcd;
20 this = tcd->esel_next;
23 if (next >= tcd->esel_max)
24 next = tcd->esel_first;
26 tcd->esel_next = next;
30 static inline int tlb1_next(void)
34 ncams = mfspr(SPRN_TLB1CFG) & TLBnCFG_N_ENTRY;
36 index = this_cpu_read(next_tlbcam_idx);
38 /* Just round-robin the entries and wrap when we hit the end */
39 if (unlikely(index == ncams - 1))
40 __this_cpu_write(next_tlbcam_idx, tlbcam_index);
42 __this_cpu_inc(next_tlbcam_idx);
49 static inline int mmu_get_tsize(int psize)
51 return mmu_psize_defs[psize].enc;
54 #if defined(CONFIG_PPC_FSL_BOOK3E) && defined(CONFIG_PPC64)
57 static inline void book3e_tlb_lock(void)
59 struct paca_struct *paca = get_paca();
61 int token = smp_processor_id() + 1;
63 asm volatile("1: lbarx %0, 0, %1;"
75 : "r" (&paca->tcd_ptr->lock), "r" (token)
79 static inline void book3e_tlb_unlock(void)
81 struct paca_struct *paca = get_paca();
84 paca->tcd_ptr->lock = 0;
87 static inline void book3e_tlb_lock(void)
91 static inline void book3e_tlb_unlock(void)
96 static inline int book3e_tlb_exists(unsigned long ea, unsigned long pid)
100 mtspr(SPRN_MAS6, pid << 16);
101 if (mmu_has_feature(MMU_FTR_USE_TLBRSRV)) {
108 : "=&r"(found) : "r"(ea));
114 : "=&r"(found) : "r"(ea));
120 void book3e_hugetlb_preload(struct vm_area_struct *vma, unsigned long ea,
123 unsigned long mas1, mas2;
125 unsigned long psize, tsize, shift;
127 struct mm_struct *mm;
129 #ifdef CONFIG_PPC_FSL_BOOK3E
133 if (unlikely(is_kernel_addr(ea)))
138 #ifdef CONFIG_PPC_MM_SLICES
139 psize = get_slice_psize(mm, ea);
140 tsize = mmu_get_tsize(psize);
141 shift = mmu_psize_defs[psize].shift;
143 psize = vma_mmu_pagesize(vma);
144 shift = __ilog2(psize);
149 * We can't be interrupted while we're setting up the MAS
150 * regusters or after we've confirmed that no tlb exists.
152 local_irq_save(flags);
156 if (unlikely(book3e_tlb_exists(ea, mm->context.id))) {
158 local_irq_restore(flags);
162 #ifdef CONFIG_PPC_FSL_BOOK3E
163 /* We have to use the CAM(TLB1) on FSL parts for hugepages */
165 mtspr(SPRN_MAS0, MAS0_ESEL(index) | MAS0_TLBSEL(1));
168 mas1 = MAS1_VALID | MAS1_TID(mm->context.id) | MAS1_TSIZE(tsize);
169 mas2 = ea & ~((1UL << shift) - 1);
170 mas2 |= (pte_val(pte) >> PTE_WIMGE_SHIFT) & MAS2_WIMGE_MASK;
171 mas7_3 = (u64)pte_pfn(pte) << PAGE_SHIFT;
172 mas7_3 |= (pte_val(pte) >> PTE_BAP_SHIFT) & MAS3_BAP_MASK;
174 mas7_3 &= ~(MAS3_SW|MAS3_UW);
176 mtspr(SPRN_MAS1, mas1);
177 mtspr(SPRN_MAS2, mas2);
179 if (mmu_has_feature(MMU_FTR_USE_PAIRED_MAS)) {
180 mtspr(SPRN_MAS7_MAS3, mas7_3);
182 if (mmu_has_feature(MMU_FTR_BIG_PHYS))
183 mtspr(SPRN_MAS7, upper_32_bits(mas7_3));
184 mtspr(SPRN_MAS3, lower_32_bits(mas7_3));
187 asm volatile ("tlbwe");
190 local_irq_restore(flags);
193 void flush_hugetlb_page(struct vm_area_struct *vma, unsigned long vmaddr)
195 struct hstate *hstate = hstate_file(vma->vm_file);
196 unsigned long tsize = huge_page_shift(hstate) - 10;
198 __flush_tlb_page(vma->vm_mm, vmaddr, tsize, 0);