GNU Linux-libre 4.4.299-gnu1
[releases.git] / arch / sh / include / asm / tlb.h
1 #ifndef __ASM_SH_TLB_H
2 #define __ASM_SH_TLB_H
3
4 #ifdef CONFIG_SUPERH64
5 # include <asm/tlb_64.h>
6 #endif
7
8 #ifndef __ASSEMBLY__
9 #include <linux/pagemap.h>
10
11 #ifdef CONFIG_MMU
12 #include <linux/swap.h>
13 #include <asm/pgalloc.h>
14 #include <asm/tlbflush.h>
15 #include <asm/mmu_context.h>
16
17 /*
18  * TLB handling.  This allows us to remove pages from the page
19  * tables, and efficiently handle the TLB issues.
20  */
21 struct mmu_gather {
22         struct mm_struct        *mm;
23         unsigned int            fullmm;
24         unsigned long           start, end;
25 };
26
27 static inline void init_tlb_gather(struct mmu_gather *tlb)
28 {
29         tlb->start = TASK_SIZE;
30         tlb->end = 0;
31
32         if (tlb->fullmm) {
33                 tlb->start = 0;
34                 tlb->end = TASK_SIZE;
35         }
36 }
37
38 static inline void
39 tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm, unsigned long start, unsigned long end)
40 {
41         tlb->mm = mm;
42         tlb->start = start;
43         tlb->end = end;
44         tlb->fullmm = !(start | (end+1));
45
46         init_tlb_gather(tlb);
47 }
48
49 static inline void
50 tlb_finish_mmu(struct mmu_gather *tlb, unsigned long start, unsigned long end)
51 {
52         if (tlb->fullmm)
53                 flush_tlb_mm(tlb->mm);
54
55         /* keep the page table cache within bounds */
56         check_pgt_cache();
57 }
58
59 static inline void
60 tlb_remove_tlb_entry(struct mmu_gather *tlb, pte_t *ptep, unsigned long address)
61 {
62         if (tlb->start > address)
63                 tlb->start = address;
64         if (tlb->end < address + PAGE_SIZE)
65                 tlb->end = address + PAGE_SIZE;
66 }
67
68 static inline void
69 tlb_flush_pmd_range(struct mmu_gather *tlb, unsigned long address,
70                     unsigned long size)
71 {
72         if (tlb->start > address)
73                 tlb->start = address;
74         if (tlb->end < address + size)
75                 tlb->end = address + size;
76 }
77
78 /*
79  * In the case of tlb vma handling, we can optimise these away in the
80  * case where we're doing a full MM flush.  When we're doing a munmap,
81  * the vmas are adjusted to only cover the region to be torn down.
82  */
83 static inline void
84 tlb_start_vma(struct mmu_gather *tlb, struct vm_area_struct *vma)
85 {
86         if (!tlb->fullmm)
87                 flush_cache_range(vma, vma->vm_start, vma->vm_end);
88 }
89
90 static inline void
91 tlb_end_vma(struct mmu_gather *tlb, struct vm_area_struct *vma)
92 {
93         if (!tlb->fullmm && tlb->end) {
94                 flush_tlb_range(vma, tlb->start, tlb->end);
95                 init_tlb_gather(tlb);
96         }
97 }
98
99 static inline void tlb_flush_mmu_tlbonly(struct mmu_gather *tlb)
100 {
101 }
102
103 static inline void tlb_flush_mmu_free(struct mmu_gather *tlb)
104 {
105 }
106
107 static inline void tlb_flush_mmu(struct mmu_gather *tlb)
108 {
109 }
110
111 static inline int __tlb_remove_page(struct mmu_gather *tlb, struct page *page)
112 {
113         free_page_and_swap_cache(page);
114         return 1; /* avoid calling tlb_flush_mmu */
115 }
116
117 static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page)
118 {
119         __tlb_remove_page(tlb, page);
120 }
121
122 #define pte_free_tlb(tlb, ptep, addr)   pte_free((tlb)->mm, ptep)
123 #define pmd_free_tlb(tlb, pmdp, addr)   pmd_free((tlb)->mm, pmdp)
124 #define pud_free_tlb(tlb, pudp, addr)   pud_free((tlb)->mm, pudp)
125
126 #define tlb_migrate_finish(mm)          do { } while (0)
127
128 #if defined(CONFIG_CPU_SH4) || defined(CONFIG_SUPERH64)
129 extern void tlb_wire_entry(struct vm_area_struct *, unsigned long, pte_t);
130 extern void tlb_unwire_entry(void);
131 #else
132 static inline void tlb_wire_entry(struct vm_area_struct *vma ,
133                                   unsigned long addr, pte_t pte)
134 {
135         BUG();
136 }
137
138 static inline void tlb_unwire_entry(void)
139 {
140         BUG();
141 }
142 #endif
143
144 #else /* CONFIG_MMU */
145
146 #define tlb_start_vma(tlb, vma)                         do { } while (0)
147 #define tlb_end_vma(tlb, vma)                           do { } while (0)
148 #define __tlb_remove_tlb_entry(tlb, pte, address)       do { } while (0)
149 #define tlb_flush(tlb)                                  do { } while (0)
150
151 #include <asm-generic/tlb.h>
152
153 #endif /* CONFIG_MMU */
154 #endif /* __ASSEMBLY__ */
155 #endif /* __ASM_SH_TLB_H */