2 * linux/include/asm-arm/tlbflush.h
4 * Copyright (C) 1999-2003 Russell King
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 #ifndef _ASMARM_TLBFLUSH_H
11 #define _ASMARM_TLBFLUSH_H
13 #include <linux/config.h>
17 #define tlb_flush(tlb) ((void) tlb)
19 #else /* CONFIG_MMU */
23 #define TLB_V3_PAGE (1 << 0)
24 #define TLB_V4_U_PAGE (1 << 1)
25 #define TLB_V4_D_PAGE (1 << 2)
26 #define TLB_V4_I_PAGE (1 << 3)
27 #define TLB_V6_U_PAGE (1 << 4)
28 #define TLB_V6_D_PAGE (1 << 5)
29 #define TLB_V6_I_PAGE (1 << 6)
31 #define TLB_V3_FULL (1 << 8)
32 #define TLB_V4_U_FULL (1 << 9)
33 #define TLB_V4_D_FULL (1 << 10)
34 #define TLB_V4_I_FULL (1 << 11)
35 #define TLB_V6_U_FULL (1 << 12)
36 #define TLB_V6_D_FULL (1 << 13)
37 #define TLB_V6_I_FULL (1 << 14)
39 #define TLB_V6_U_ASID (1 << 16)
40 #define TLB_V6_D_ASID (1 << 17)
41 #define TLB_V6_I_ASID (1 << 18)
43 #define TLB_DCLEAN (1 << 30)
44 #define TLB_WB (1 << 31)
50 * We have the following to choose from:
52 * v4 - ARMv4 without write buffer
53 * v4wb - ARMv4 with write buffer without I TLB flush entry instruction
54 * v4wbi - ARMv4 with write buffer with I TLB flush entry instruction
55 * v6wbi - ARMv6 with write buffer with I TLB flush entry instruction
60 #define v3_tlb_flags (TLB_V3_FULL | TLB_V3_PAGE)
62 #ifdef CONFIG_CPU_TLB_V3
63 # define v3_possible_flags v3_tlb_flags
64 # define v3_always_flags v3_tlb_flags
71 # define v3_possible_flags 0
72 # define v3_always_flags (-1UL)
75 #define v4_tlb_flags (TLB_V4_U_FULL | TLB_V4_U_PAGE)
77 #ifdef CONFIG_CPU_TLB_V4WT
78 # define v4_possible_flags v4_tlb_flags
79 # define v4_always_flags v4_tlb_flags
86 # define v4_possible_flags 0
87 # define v4_always_flags (-1UL)
90 #define v4wbi_tlb_flags (TLB_WB | TLB_DCLEAN | \
91 TLB_V4_I_FULL | TLB_V4_D_FULL | \
92 TLB_V4_I_PAGE | TLB_V4_D_PAGE)
94 #ifdef CONFIG_CPU_TLB_V4WBI
95 # define v4wbi_possible_flags v4wbi_tlb_flags
96 # define v4wbi_always_flags v4wbi_tlb_flags
103 # define v4wbi_possible_flags 0
104 # define v4wbi_always_flags (-1UL)
107 #define v4wb_tlb_flags (TLB_WB | TLB_DCLEAN | \
108 TLB_V4_I_FULL | TLB_V4_D_FULL | \
111 #ifdef CONFIG_CPU_TLB_V4WB
112 # define v4wb_possible_flags v4wb_tlb_flags
113 # define v4wb_always_flags v4wb_tlb_flags
120 # define v4wb_possible_flags 0
121 # define v4wb_always_flags (-1UL)
124 #define v6wbi_tlb_flags (TLB_WB | TLB_DCLEAN | \
125 TLB_V6_I_FULL | TLB_V6_D_FULL | \
126 TLB_V6_I_PAGE | TLB_V6_D_PAGE | \
127 TLB_V6_I_ASID | TLB_V6_D_ASID)
129 #ifdef CONFIG_CPU_TLB_V6
130 # define v6wbi_possible_flags v6wbi_tlb_flags
131 # define v6wbi_always_flags v6wbi_tlb_flags
138 # define v6wbi_possible_flags 0
139 # define v6wbi_always_flags (-1UL)
143 #error Unknown TLB model
149 void (*flush_user_range
)(unsigned long, unsigned long, struct vm_area_struct
*);
150 void (*flush_kern_range
)(unsigned long, unsigned long);
151 unsigned long tlb_flags
;
155 * Select the calling method
159 #define __cpu_flush_user_tlb_range cpu_tlb.flush_user_range
160 #define __cpu_flush_kern_tlb_range cpu_tlb.flush_kern_range
164 #define __cpu_flush_user_tlb_range __glue(_TLB,_flush_user_tlb_range)
165 #define __cpu_flush_kern_tlb_range __glue(_TLB,_flush_kern_tlb_range)
167 extern void __cpu_flush_user_tlb_range(unsigned long, unsigned long, struct vm_area_struct
*);
168 extern void __cpu_flush_kern_tlb_range(unsigned long, unsigned long);
172 extern struct cpu_tlb_fns cpu_tlb
;
174 #define __cpu_tlb_flags cpu_tlb.tlb_flags
180 * The arch/arm/mm/tlb-*.S files implement these methods.
182 * The TLB specific code is expected to perform whatever tests it
183 * needs to determine if it should invalidate the TLB for each
184 * call. Start addresses are inclusive and end addresses are
185 * exclusive; it is safe to round these addresses down.
189 * Invalidate the entire TLB.
193 * Invalidate all TLB entries in a particular address
195 * - mm - mm_struct describing address space
197 * flush_tlb_range(mm,start,end)
199 * Invalidate a range of TLB entries in the specified
201 * - mm - mm_struct describing address space
202 * - start - start address (may not be aligned)
203 * - end - end address (exclusive, may not be aligned)
205 * flush_tlb_page(vaddr,vma)
207 * Invalidate the specified page in the specified address range.
208 * - vaddr - virtual address (may not be aligned)
209 * - vma - vma_struct describing address range
211 * flush_kern_tlb_page(kaddr)
213 * Invalidate the TLB entry for the specified page. The address
214 * will be in the kernels virtual memory space. Current uses
215 * only require the D-TLB to be invalidated.
216 * - kaddr - Kernel virtual memory address
220 * We optimise the code below by:
221 * - building a set of TLB flags that might be set in __cpu_tlb_flags
222 * - building a set of TLB flags that will always be set in __cpu_tlb_flags
223 * - if we're going to need __cpu_tlb_flags, access it once and only once
225 * This allows us to build optimal assembly for the single-CPU type case,
226 * and as close to optimal given the compiler constrants for multi-CPU
227 * case. We could do better for the multi-CPU case if the compiler
228 * implemented the "%?" method, but this has been discontinued due to too
229 * many people getting it wrong.
231 #define possible_tlb_flags (v3_possible_flags | \
232 v4_possible_flags | \
233 v4wbi_possible_flags | \
234 v4wb_possible_flags | \
235 v6wbi_possible_flags)
237 #define always_tlb_flags (v3_always_flags & \
239 v4wbi_always_flags & \
240 v4wb_always_flags & \
243 #define tlb_flag(f) ((always_tlb_flags & (f)) || (__tlb_flag & possible_tlb_flags & (f)))
245 static inline void local_flush_tlb_all(void)
248 const unsigned int __tlb_flag
= __cpu_tlb_flags
;
250 if (tlb_flag(TLB_WB
))
251 asm("mcr%? p15, 0, %0, c7, c10, 4" : : "r" (zero
));
253 if (tlb_flag(TLB_V3_FULL
))
254 asm("mcr%? p15, 0, %0, c6, c0, 0" : : "r" (zero
));
255 if (tlb_flag(TLB_V4_U_FULL
| TLB_V6_U_FULL
))
256 asm("mcr%? p15, 0, %0, c8, c7, 0" : : "r" (zero
));
257 if (tlb_flag(TLB_V4_D_FULL
| TLB_V6_D_FULL
))
258 asm("mcr%? p15, 0, %0, c8, c6, 0" : : "r" (zero
));
259 if (tlb_flag(TLB_V4_I_FULL
| TLB_V6_I_FULL
))
260 asm("mcr%? p15, 0, %0, c8, c5, 0" : : "r" (zero
));
263 static inline void local_flush_tlb_mm(struct mm_struct
*mm
)
266 const int asid
= ASID(mm
);
267 const unsigned int __tlb_flag
= __cpu_tlb_flags
;
269 if (tlb_flag(TLB_WB
))
270 asm("mcr%? p15, 0, %0, c7, c10, 4" : : "r" (zero
));
272 if (cpu_isset(smp_processor_id(), mm
->cpu_vm_mask
)) {
273 if (tlb_flag(TLB_V3_FULL
))
274 asm("mcr%? p15, 0, %0, c6, c0, 0" : : "r" (zero
));
275 if (tlb_flag(TLB_V4_U_FULL
))
276 asm("mcr%? p15, 0, %0, c8, c7, 0" : : "r" (zero
));
277 if (tlb_flag(TLB_V4_D_FULL
))
278 asm("mcr%? p15, 0, %0, c8, c6, 0" : : "r" (zero
));
279 if (tlb_flag(TLB_V4_I_FULL
))
280 asm("mcr%? p15, 0, %0, c8, c5, 0" : : "r" (zero
));
283 if (tlb_flag(TLB_V6_U_ASID
))
284 asm("mcr%? p15, 0, %0, c8, c7, 2" : : "r" (asid
));
285 if (tlb_flag(TLB_V6_D_ASID
))
286 asm("mcr%? p15, 0, %0, c8, c6, 2" : : "r" (asid
));
287 if (tlb_flag(TLB_V6_I_ASID
))
288 asm("mcr%? p15, 0, %0, c8, c5, 2" : : "r" (asid
));
292 local_flush_tlb_page(struct vm_area_struct
*vma
, unsigned long uaddr
)
295 const unsigned int __tlb_flag
= __cpu_tlb_flags
;
297 uaddr
= (uaddr
& PAGE_MASK
) | ASID(vma
->vm_mm
);
299 if (tlb_flag(TLB_WB
))
300 asm("mcr%? p15, 0, %0, c7, c10, 4" : : "r" (zero
));
302 if (cpu_isset(smp_processor_id(), vma
->vm_mm
->cpu_vm_mask
)) {
303 if (tlb_flag(TLB_V3_PAGE
))
304 asm("mcr%? p15, 0, %0, c6, c0, 0" : : "r" (uaddr
));
305 if (tlb_flag(TLB_V4_U_PAGE
))
306 asm("mcr%? p15, 0, %0, c8, c7, 1" : : "r" (uaddr
));
307 if (tlb_flag(TLB_V4_D_PAGE
))
308 asm("mcr%? p15, 0, %0, c8, c6, 1" : : "r" (uaddr
));
309 if (tlb_flag(TLB_V4_I_PAGE
))
310 asm("mcr%? p15, 0, %0, c8, c5, 1" : : "r" (uaddr
));
311 if (!tlb_flag(TLB_V4_I_PAGE
) && tlb_flag(TLB_V4_I_FULL
))
312 asm("mcr%? p15, 0, %0, c8, c5, 0" : : "r" (zero
));
315 if (tlb_flag(TLB_V6_U_PAGE
))
316 asm("mcr%? p15, 0, %0, c8, c7, 1" : : "r" (uaddr
));
317 if (tlb_flag(TLB_V6_D_PAGE
))
318 asm("mcr%? p15, 0, %0, c8, c6, 1" : : "r" (uaddr
));
319 if (tlb_flag(TLB_V6_I_PAGE
))
320 asm("mcr%? p15, 0, %0, c8, c5, 1" : : "r" (uaddr
));
323 static inline void local_flush_tlb_kernel_page(unsigned long kaddr
)
326 const unsigned int __tlb_flag
= __cpu_tlb_flags
;
330 if (tlb_flag(TLB_WB
))
331 asm("mcr%? p15, 0, %0, c7, c10, 4" : : "r" (zero
));
333 if (tlb_flag(TLB_V3_PAGE
))
334 asm("mcr%? p15, 0, %0, c6, c0, 0" : : "r" (kaddr
));
335 if (tlb_flag(TLB_V4_U_PAGE
))
336 asm("mcr%? p15, 0, %0, c8, c7, 1" : : "r" (kaddr
));
337 if (tlb_flag(TLB_V4_D_PAGE
))
338 asm("mcr%? p15, 0, %0, c8, c6, 1" : : "r" (kaddr
));
339 if (tlb_flag(TLB_V4_I_PAGE
))
340 asm("mcr%? p15, 0, %0, c8, c5, 1" : : "r" (kaddr
));
341 if (!tlb_flag(TLB_V4_I_PAGE
) && tlb_flag(TLB_V4_I_FULL
))
342 asm("mcr%? p15, 0, %0, c8, c5, 0" : : "r" (zero
));
344 if (tlb_flag(TLB_V6_U_PAGE
))
345 asm("mcr%? p15, 0, %0, c8, c7, 1" : : "r" (kaddr
));
346 if (tlb_flag(TLB_V6_D_PAGE
))
347 asm("mcr%? p15, 0, %0, c8, c6, 1" : : "r" (kaddr
));
348 if (tlb_flag(TLB_V6_I_PAGE
))
349 asm("mcr%? p15, 0, %0, c8, c5, 1" : : "r" (kaddr
));
351 /* The ARM ARM states that the completion of a TLB maintenance
352 * operation is only guaranteed by a DSB instruction
354 if (tlb_flag(TLB_V6_U_PAGE
| TLB_V6_D_PAGE
| TLB_V6_I_PAGE
))
355 asm("mcr%? p15, 0, %0, c7, c10, 4" : : "r" (zero
));
361 * Flush a PMD entry (word aligned, or double-word aligned) to
362 * RAM if the TLB for the CPU we are running on requires this.
363 * This is typically used when we are creating PMD entries.
367 * Clean (but don't drain the write buffer) if the CPU requires
368 * these operations. This is typically used when we are removing
371 static inline void flush_pmd_entry(pmd_t
*pmd
)
373 const unsigned int zero
= 0;
374 const unsigned int __tlb_flag
= __cpu_tlb_flags
;
376 if (tlb_flag(TLB_DCLEAN
))
377 asm("mcr%? p15, 0, %0, c7, c10, 1 @ flush_pmd"
379 if (tlb_flag(TLB_WB
))
380 asm("mcr%? p15, 0, %0, c7, c10, 4 @ flush_pmd"
384 static inline void clean_pmd_entry(pmd_t
*pmd
)
386 const unsigned int __tlb_flag
= __cpu_tlb_flags
;
388 if (tlb_flag(TLB_DCLEAN
))
389 asm("mcr%? p15, 0, %0, c7, c10, 1 @ flush_pmd"
394 #undef always_tlb_flags
395 #undef possible_tlb_flags
398 * Convert calls to our calling convention.
400 #define local_flush_tlb_range(vma,start,end) __cpu_flush_user_tlb_range(start,end,vma)
401 #define local_flush_tlb_kernel_range(s,e) __cpu_flush_kern_tlb_range(s,e)
404 #define flush_tlb_all local_flush_tlb_all
405 #define flush_tlb_mm local_flush_tlb_mm
406 #define flush_tlb_page local_flush_tlb_page
407 #define flush_tlb_kernel_page local_flush_tlb_kernel_page
408 #define flush_tlb_range local_flush_tlb_range
409 #define flush_tlb_kernel_range local_flush_tlb_kernel_range
411 extern void flush_tlb_all(void);
412 extern void flush_tlb_mm(struct mm_struct
*mm
);
413 extern void flush_tlb_page(struct vm_area_struct
*vma
, unsigned long uaddr
);
414 extern void flush_tlb_kernel_page(unsigned long kaddr
);
415 extern void flush_tlb_range(struct vm_area_struct
*vma
, unsigned long start
, unsigned long end
);
416 extern void flush_tlb_kernel_range(unsigned long start
, unsigned long end
);
420 * if PG_dcache_dirty is set for the page, we need to ensure that any
421 * cache entries for the kernels virtual memory range are written
424 extern void update_mmu_cache(struct vm_area_struct
*vma
, unsigned long addr
, pte_t pte
);
427 * ARM processors do not cache TLB tables in RAM.
429 #define flush_tlb_pgtables(mm,start,end) do { } while (0)
433 #endif /* CONFIG_MMU */