9 #include <linux/pagemap.h>
12 #include <asm/pgalloc.h>
13 #include <asm/tlbflush.h>
14 #include <asm/mmu_context.h>
17 * TLB handling. This allows us to remove pages from the page
18 * tables, and efficiently handle the TLB issues.
23 unsigned long start, end;
26 DECLARE_PER_CPU(struct mmu_gather, mmu_gathers);
28 static inline void init_tlb_gather(struct mmu_gather *tlb)
30 tlb->start = TASK_SIZE;
39 static inline struct mmu_gather *
40 tlb_gather_mmu(struct mm_struct *mm, unsigned int full_mm_flush)
42 struct mmu_gather *tlb = &get_cpu_var(mmu_gathers);
45 tlb->fullmm = full_mm_flush;
53 tlb_finish_mmu(struct mmu_gather *tlb, unsigned long start, unsigned long end)
56 flush_tlb_mm(tlb->mm);
58 /* keep the page table cache within bounds */
61 put_cpu_var(mmu_gathers);
65 tlb_remove_tlb_entry(struct mmu_gather *tlb, pte_t *ptep, unsigned long address)
67 if (tlb->start > address)
69 if (tlb->end < address + PAGE_SIZE)
70 tlb->end = address + PAGE_SIZE;
74 * In the case of tlb vma handling, we can optimise these away in the
75 * case where we're doing a full MM flush. When we're doing a munmap,
76 * the vmas are adjusted to only cover the region to be torn down.
79 tlb_start_vma(struct mmu_gather *tlb, struct vm_area_struct *vma)
82 flush_cache_range(vma, vma->vm_start, vma->vm_end);
86 tlb_end_vma(struct mmu_gather *tlb, struct vm_area_struct *vma)
88 if (!tlb->fullmm && tlb->end) {
89 flush_tlb_range(vma, tlb->start, tlb->end);
94 #define tlb_remove_page(tlb,page) free_page_and_swap_cache(page)
95 #define pte_free_tlb(tlb, ptep, addr) pte_free((tlb)->mm, ptep)
96 #define pmd_free_tlb(tlb, pmdp, addr) pmd_free((tlb)->mm, pmdp)
97 #define pud_free_tlb(tlb, pudp, addr) pud_free((tlb)->mm, pudp)
99 #define tlb_migrate_finish(mm) do { } while (0)
101 #ifdef CONFIG_CPU_SH4
102 extern void tlb_wire_entry(struct vm_area_struct *, unsigned long, pte_t);
103 extern void tlb_unwire_entry(void);
104 #elif defined(CONFIG_SUPERH64)
105 static int dtlb_entry;
106 static unsigned long long dtlb_entries[64];
108 static inline void tlb_wire_entry(struct vm_area_struct *vma,
109 unsigned long addr, pte_t pte)
111 unsigned long long entry;
112 unsigned long paddr, flags;
114 BUG_ON(dtlb_entry == 64);
116 local_irq_save(flags);
118 entry = sh64_get_wired_dtlb_entry();
119 dtlb_entries[dtlb_entry++] = entry;
121 paddr = pte_val(pte) & _PAGE_FLAGS_HARDWARE_MASK;
124 sh64_setup_tlb_slot(entry, addr, get_asid(), paddr);
126 local_irq_restore(flags);
129 static inline void tlb_unwire_entry(void)
131 unsigned long long entry;
136 local_irq_save(flags);
137 entry = dtlb_entries[dtlb_entry--];
139 sh64_teardown_tlb_slot(entry);
140 sh64_put_wired_dtlb_entry(entry);
142 local_irq_restore(flags);
145 static inline void tlb_wire_entry(struct vm_area_struct *vma ,
146 unsigned long addr, pte_t pte)
151 static inline void tlb_unwire_entry(void)
155 #endif /* CONFIG_CPU_SH4 */
157 #else /* CONFIG_MMU */
159 #define tlb_start_vma(tlb, vma) do { } while (0)
160 #define tlb_end_vma(tlb, vma) do { } while (0)
161 #define __tlb_remove_tlb_entry(tlb, pte, address) do { } while (0)
162 #define tlb_flush(tlb) do { } while (0)
164 #include <asm-generic/tlb.h>
166 #endif /* CONFIG_MMU */
167 #endif /* __ASSEMBLY__ */
168 #endif /* __ASM_SH_TLB_H */