]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - arch/sh/include/asm/tlb.h
Merge tag 'for-linus-20170812' of git://git.infradead.org/linux-mtd
[karo-tx-linux.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 arch_tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm,
40                 unsigned long start, unsigned long end)
41 {
42         tlb->mm = mm;
43         tlb->start = start;
44         tlb->end = end;
45         tlb->fullmm = !(start | (end+1));
46
47         init_tlb_gather(tlb);
48 }
49
50 static inline void
51 arch_tlb_finish_mmu(struct mmu_gather *tlb,
52                 unsigned long start, unsigned long end, bool force)
53 {
54         if (tlb->fullmm || force)
55                 flush_tlb_mm(tlb->mm);
56
57         /* keep the page table cache within bounds */
58         check_pgt_cache();
59 }
60
61 static inline void
62 tlb_remove_tlb_entry(struct mmu_gather *tlb, pte_t *ptep, unsigned long address)
63 {
64         if (tlb->start > address)
65                 tlb->start = address;
66         if (tlb->end < address + PAGE_SIZE)
67                 tlb->end = address + PAGE_SIZE;
68 }
69
70 #define tlb_remove_huge_tlb_entry(h, tlb, ptep, address)        \
71         tlb_remove_tlb_entry(tlb, ptep, address)
72
73 /*
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.
77  */
78 static inline void
79 tlb_start_vma(struct mmu_gather *tlb, struct vm_area_struct *vma)
80 {
81         if (!tlb->fullmm)
82                 flush_cache_range(vma, vma->vm_start, vma->vm_end);
83 }
84
85 static inline void
86 tlb_end_vma(struct mmu_gather *tlb, struct vm_area_struct *vma)
87 {
88         if (!tlb->fullmm && tlb->end) {
89                 flush_tlb_range(vma, tlb->start, tlb->end);
90                 init_tlb_gather(tlb);
91         }
92 }
93
94 static inline void tlb_flush_mmu_tlbonly(struct mmu_gather *tlb)
95 {
96 }
97
98 static inline void tlb_flush_mmu_free(struct mmu_gather *tlb)
99 {
100 }
101
102 static inline void tlb_flush_mmu(struct mmu_gather *tlb)
103 {
104 }
105
106 static inline int __tlb_remove_page(struct mmu_gather *tlb, struct page *page)
107 {
108         free_page_and_swap_cache(page);
109         return false; /* avoid calling tlb_flush_mmu */
110 }
111
112 static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page)
113 {
114         __tlb_remove_page(tlb, page);
115 }
116
117 static inline bool __tlb_remove_page_size(struct mmu_gather *tlb,
118                                           struct page *page, int page_size)
119 {
120         return __tlb_remove_page(tlb, page);
121 }
122
123 static inline void tlb_remove_page_size(struct mmu_gather *tlb,
124                                         struct page *page, int page_size)
125 {
126         return tlb_remove_page(tlb, page);
127 }
128
129 #define tlb_remove_check_page_size_change tlb_remove_check_page_size_change
130 static inline void tlb_remove_check_page_size_change(struct mmu_gather *tlb,
131                                                      unsigned int page_size)
132 {
133 }
134
135 #define pte_free_tlb(tlb, ptep, addr)   pte_free((tlb)->mm, ptep)
136 #define pmd_free_tlb(tlb, pmdp, addr)   pmd_free((tlb)->mm, pmdp)
137 #define pud_free_tlb(tlb, pudp, addr)   pud_free((tlb)->mm, pudp)
138
139 #define tlb_migrate_finish(mm)          do { } while (0)
140
141 #if defined(CONFIG_CPU_SH4) || defined(CONFIG_SUPERH64)
142 extern void tlb_wire_entry(struct vm_area_struct *, unsigned long, pte_t);
143 extern void tlb_unwire_entry(void);
144 #else
145 static inline void tlb_wire_entry(struct vm_area_struct *vma ,
146                                   unsigned long addr, pte_t pte)
147 {
148         BUG();
149 }
150
151 static inline void tlb_unwire_entry(void)
152 {
153         BUG();
154 }
155 #endif
156
157 #else /* CONFIG_MMU */
158
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)
163
164 #include <asm-generic/tlb.h>
165
166 #endif /* CONFIG_MMU */
167 #endif /* __ASSEMBLY__ */
168 #endif /* __ASM_SH_TLB_H */