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
16 #define tlb_flush(tlb) ((void) tlb)
18 #else /* CONFIG_MMU */
22 #define TLB_V3_PAGE (1 << 0)
23 #define TLB_V4_U_PAGE (1 << 1)
24 #define TLB_V4_D_PAGE (1 << 2)
25 #define TLB_V4_I_PAGE (1 << 3)
26 #define TLB_V6_U_PAGE (1 << 4)
27 #define TLB_V6_D_PAGE (1 << 5)
28 #define TLB_V6_I_PAGE (1 << 6)
30 #define TLB_V3_FULL (1 << 8)
31 #define TLB_V4_U_FULL (1 << 9)
32 #define TLB_V4_D_FULL (1 << 10)
33 #define TLB_V4_I_FULL (1 << 11)
34 #define TLB_V6_U_FULL (1 << 12)
35 #define TLB_V6_D_FULL (1 << 13)
36 #define TLB_V6_I_FULL (1 << 14)
38 #define TLB_V6_U_ASID (1 << 16)
39 #define TLB_V6_D_ASID (1 << 17)
40 #define TLB_V6_I_ASID (1 << 18)
42 #define TLB_L2CLEAN_FR (1 << 29) /* Feroceon */
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 * fr - Feroceon (v4wbi with non-outer-cacheable page table walks)
56 * v6wbi - ARMv6 with write buffer with I TLB flush entry instruction
61 #define v3_tlb_flags (TLB_V3_FULL | TLB_V3_PAGE)
63 #ifdef CONFIG_CPU_TLB_V3
64 # define v3_possible_flags v3_tlb_flags
65 # define v3_always_flags v3_tlb_flags
72 # define v3_possible_flags 0
73 # define v3_always_flags (-1UL)
76 #define v4_tlb_flags (TLB_V4_U_FULL | TLB_V4_U_PAGE)
78 #ifdef CONFIG_CPU_TLB_V4WT
79 # define v4_possible_flags v4_tlb_flags
80 # define v4_always_flags v4_tlb_flags
87 # define v4_possible_flags 0
88 # define v4_always_flags (-1UL)
91 #define v4wbi_tlb_flags (TLB_WB | TLB_DCLEAN | \
92 TLB_V4_I_FULL | TLB_V4_D_FULL | \
93 TLB_V4_I_PAGE | TLB_V4_D_PAGE)
95 #ifdef CONFIG_CPU_TLB_V4WBI
96 # define v4wbi_possible_flags v4wbi_tlb_flags
97 # define v4wbi_always_flags v4wbi_tlb_flags
104 # define v4wbi_possible_flags 0
105 # define v4wbi_always_flags (-1UL)
108 #define fr_tlb_flags (TLB_WB | TLB_DCLEAN | TLB_L2CLEAN_FR | \
109 TLB_V4_I_FULL | TLB_V4_D_FULL | \
110 TLB_V4_I_PAGE | TLB_V4_D_PAGE)
112 #ifdef CONFIG_CPU_TLB_FEROCEON
113 # define fr_possible_flags fr_tlb_flags
114 # define fr_always_flags fr_tlb_flags
121 # define fr_possible_flags 0
122 # define fr_always_flags (-1UL)
125 #define v4wb_tlb_flags (TLB_WB | TLB_DCLEAN | \
126 TLB_V4_I_FULL | TLB_V4_D_FULL | \
129 #ifdef CONFIG_CPU_TLB_V4WB
130 # define v4wb_possible_flags v4wb_tlb_flags
131 # define v4wb_always_flags v4wb_tlb_flags
138 # define v4wb_possible_flags 0
139 # define v4wb_always_flags (-1UL)
142 #define v6wbi_tlb_flags (TLB_WB | TLB_DCLEAN | \
143 TLB_V6_I_FULL | TLB_V6_D_FULL | \
144 TLB_V6_I_PAGE | TLB_V6_D_PAGE | \
145 TLB_V6_I_ASID | TLB_V6_D_ASID)
147 #ifdef CONFIG_CPU_TLB_V6
148 # define v6wbi_possible_flags v6wbi_tlb_flags
149 # define v6wbi_always_flags v6wbi_tlb_flags
156 # define v6wbi_possible_flags 0
157 # define v6wbi_always_flags (-1UL)
160 #ifdef CONFIG_CPU_TLB_V7
161 # define v7wbi_possible_flags v6wbi_tlb_flags
162 # define v7wbi_always_flags v6wbi_tlb_flags
169 # define v7wbi_possible_flags 0
170 # define v7wbi_always_flags (-1UL)
174 #error Unknown TLB model
179 #include <linux/sched.h>
182 void (*flush_user_range)(unsigned long, unsigned long, struct vm_area_struct *);
183 void (*flush_kern_range)(unsigned long, unsigned long);
184 unsigned long tlb_flags;
188 * Select the calling method
192 #define __cpu_flush_user_tlb_range cpu_tlb.flush_user_range
193 #define __cpu_flush_kern_tlb_range cpu_tlb.flush_kern_range
197 #define __cpu_flush_user_tlb_range __glue(_TLB,_flush_user_tlb_range)
198 #define __cpu_flush_kern_tlb_range __glue(_TLB,_flush_kern_tlb_range)
200 extern void __cpu_flush_user_tlb_range(unsigned long, unsigned long, struct vm_area_struct *);
201 extern void __cpu_flush_kern_tlb_range(unsigned long, unsigned long);
205 extern struct cpu_tlb_fns cpu_tlb;
207 #define __cpu_tlb_flags cpu_tlb.tlb_flags
213 * The arch/arm/mm/tlb-*.S files implement these methods.
215 * The TLB specific code is expected to perform whatever tests it
216 * needs to determine if it should invalidate the TLB for each
217 * call. Start addresses are inclusive and end addresses are
218 * exclusive; it is safe to round these addresses down.
222 * Invalidate the entire TLB.
226 * Invalidate all TLB entries in a particular address
228 * - mm - mm_struct describing address space
230 * flush_tlb_range(mm,start,end)
232 * Invalidate a range of TLB entries in the specified
234 * - mm - mm_struct describing address space
235 * - start - start address (may not be aligned)
236 * - end - end address (exclusive, may not be aligned)
238 * flush_tlb_page(vaddr,vma)
240 * Invalidate the specified page in the specified address range.
241 * - vaddr - virtual address (may not be aligned)
242 * - vma - vma_struct describing address range
244 * flush_kern_tlb_page(kaddr)
246 * Invalidate the TLB entry for the specified page. The address
247 * will be in the kernels virtual memory space. Current uses
248 * only require the D-TLB to be invalidated.
249 * - kaddr - Kernel virtual memory address
253 * We optimise the code below by:
254 * - building a set of TLB flags that might be set in __cpu_tlb_flags
255 * - building a set of TLB flags that will always be set in __cpu_tlb_flags
256 * - if we're going to need __cpu_tlb_flags, access it once and only once
258 * This allows us to build optimal assembly for the single-CPU type case,
259 * and as close to optimal given the compiler constrants for multi-CPU
260 * case. We could do better for the multi-CPU case if the compiler
261 * implemented the "%?" method, but this has been discontinued due to too
262 * many people getting it wrong.
264 #define possible_tlb_flags (v3_possible_flags | \
265 v4_possible_flags | \
266 v4wbi_possible_flags | \
267 fr_possible_flags | \
268 v4wb_possible_flags | \
269 v6wbi_possible_flags)
271 #define always_tlb_flags (v3_always_flags & \
273 v4wbi_always_flags & \
275 v4wb_always_flags & \
278 #define tlb_flag(f) ((always_tlb_flags & (f)) || (__tlb_flag & possible_tlb_flags & (f)))
280 static inline void local_flush_tlb_all(void)
283 const unsigned int __tlb_flag = __cpu_tlb_flags;
285 if (tlb_flag(TLB_WB))
288 if (tlb_flag(TLB_V3_FULL))
289 asm("mcr p15, 0, %0, c6, c0, 0" : : "r" (zero) : "cc");
290 if (tlb_flag(TLB_V4_U_FULL | TLB_V6_U_FULL))
291 asm("mcr p15, 0, %0, c8, c7, 0" : : "r" (zero) : "cc");
292 if (tlb_flag(TLB_V4_D_FULL | TLB_V6_D_FULL))
293 asm("mcr p15, 0, %0, c8, c6, 0" : : "r" (zero) : "cc");
294 if (tlb_flag(TLB_V4_I_FULL | TLB_V6_I_FULL))
295 asm("mcr p15, 0, %0, c8, c5, 0" : : "r" (zero) : "cc");
297 if (tlb_flag(TLB_V6_I_FULL | TLB_V6_D_FULL |
298 TLB_V6_I_PAGE | TLB_V6_D_PAGE |
299 TLB_V6_I_ASID | TLB_V6_D_ASID)) {
300 /* flush the branch target cache */
301 asm("mcr p15, 0, %0, c7, c5, 6" : : "r" (zero) : "cc");
307 static inline void local_flush_tlb_mm(struct mm_struct *mm)
310 const int asid = ASID(mm);
311 const unsigned int __tlb_flag = __cpu_tlb_flags;
313 if (tlb_flag(TLB_WB))
316 if (cpu_isset(smp_processor_id(), mm->cpu_vm_mask)) {
317 if (tlb_flag(TLB_V3_FULL))
318 asm("mcr p15, 0, %0, c6, c0, 0" : : "r" (zero) : "cc");
319 if (tlb_flag(TLB_V4_U_FULL))
320 asm("mcr p15, 0, %0, c8, c7, 0" : : "r" (zero) : "cc");
321 if (tlb_flag(TLB_V4_D_FULL))
322 asm("mcr p15, 0, %0, c8, c6, 0" : : "r" (zero) : "cc");
323 if (tlb_flag(TLB_V4_I_FULL))
324 asm("mcr p15, 0, %0, c8, c5, 0" : : "r" (zero) : "cc");
327 if (tlb_flag(TLB_V6_U_ASID))
328 asm("mcr p15, 0, %0, c8, c7, 2" : : "r" (asid) : "cc");
329 if (tlb_flag(TLB_V6_D_ASID))
330 asm("mcr p15, 0, %0, c8, c6, 2" : : "r" (asid) : "cc");
331 if (tlb_flag(TLB_V6_I_ASID))
332 asm("mcr p15, 0, %0, c8, c5, 2" : : "r" (asid) : "cc");
334 if (tlb_flag(TLB_V6_I_FULL | TLB_V6_D_FULL |
335 TLB_V6_I_PAGE | TLB_V6_D_PAGE |
336 TLB_V6_I_ASID | TLB_V6_D_ASID)) {
337 /* flush the branch target cache */
338 asm("mcr p15, 0, %0, c7, c5, 6" : : "r" (zero) : "cc");
344 local_flush_tlb_page(struct vm_area_struct *vma, unsigned long uaddr)
347 const unsigned int __tlb_flag = __cpu_tlb_flags;
349 uaddr = (uaddr & PAGE_MASK) | ASID(vma->vm_mm);
351 if (tlb_flag(TLB_WB))
354 if (cpu_isset(smp_processor_id(), vma->vm_mm->cpu_vm_mask)) {
355 if (tlb_flag(TLB_V3_PAGE))
356 asm("mcr p15, 0, %0, c6, c0, 0" : : "r" (uaddr) : "cc");
357 if (tlb_flag(TLB_V4_U_PAGE))
358 asm("mcr p15, 0, %0, c8, c7, 1" : : "r" (uaddr) : "cc");
359 if (tlb_flag(TLB_V4_D_PAGE))
360 asm("mcr p15, 0, %0, c8, c6, 1" : : "r" (uaddr) : "cc");
361 if (tlb_flag(TLB_V4_I_PAGE))
362 asm("mcr p15, 0, %0, c8, c5, 1" : : "r" (uaddr) : "cc");
363 if (!tlb_flag(TLB_V4_I_PAGE) && tlb_flag(TLB_V4_I_FULL))
364 asm("mcr p15, 0, %0, c8, c5, 0" : : "r" (zero) : "cc");
367 if (tlb_flag(TLB_V6_U_PAGE))
368 asm("mcr p15, 0, %0, c8, c7, 1" : : "r" (uaddr) : "cc");
369 if (tlb_flag(TLB_V6_D_PAGE))
370 asm("mcr p15, 0, %0, c8, c6, 1" : : "r" (uaddr) : "cc");
371 if (tlb_flag(TLB_V6_I_PAGE))
372 asm("mcr p15, 0, %0, c8, c5, 1" : : "r" (uaddr) : "cc");
374 if (tlb_flag(TLB_V6_I_FULL | TLB_V6_D_FULL |
375 TLB_V6_I_PAGE | TLB_V6_D_PAGE |
376 TLB_V6_I_ASID | TLB_V6_D_ASID)) {
377 /* flush the branch target cache */
378 asm("mcr p15, 0, %0, c7, c5, 6" : : "r" (zero) : "cc");
383 static inline void local_flush_tlb_kernel_page(unsigned long kaddr)
386 const unsigned int __tlb_flag = __cpu_tlb_flags;
390 if (tlb_flag(TLB_WB))
393 if (tlb_flag(TLB_V3_PAGE))
394 asm("mcr p15, 0, %0, c6, c0, 0" : : "r" (kaddr) : "cc");
395 if (tlb_flag(TLB_V4_U_PAGE))
396 asm("mcr p15, 0, %0, c8, c7, 1" : : "r" (kaddr) : "cc");
397 if (tlb_flag(TLB_V4_D_PAGE))
398 asm("mcr p15, 0, %0, c8, c6, 1" : : "r" (kaddr) : "cc");
399 if (tlb_flag(TLB_V4_I_PAGE))
400 asm("mcr p15, 0, %0, c8, c5, 1" : : "r" (kaddr) : "cc");
401 if (!tlb_flag(TLB_V4_I_PAGE) && tlb_flag(TLB_V4_I_FULL))
402 asm("mcr p15, 0, %0, c8, c5, 0" : : "r" (zero) : "cc");
404 if (tlb_flag(TLB_V6_U_PAGE))
405 asm("mcr p15, 0, %0, c8, c7, 1" : : "r" (kaddr) : "cc");
406 if (tlb_flag(TLB_V6_D_PAGE))
407 asm("mcr p15, 0, %0, c8, c6, 1" : : "r" (kaddr) : "cc");
408 if (tlb_flag(TLB_V6_I_PAGE))
409 asm("mcr p15, 0, %0, c8, c5, 1" : : "r" (kaddr) : "cc");
411 if (tlb_flag(TLB_V6_I_FULL | TLB_V6_D_FULL |
412 TLB_V6_I_PAGE | TLB_V6_D_PAGE |
413 TLB_V6_I_ASID | TLB_V6_D_ASID)) {
414 /* flush the branch target cache */
415 asm("mcr p15, 0, %0, c7, c5, 6" : : "r" (zero) : "cc");
424 * Flush a PMD entry (word aligned, or double-word aligned) to
425 * RAM if the TLB for the CPU we are running on requires this.
426 * This is typically used when we are creating PMD entries.
430 * Clean (but don't drain the write buffer) if the CPU requires
431 * these operations. This is typically used when we are removing
434 static inline void flush_pmd_entry(pmd_t *pmd)
436 const unsigned int __tlb_flag = __cpu_tlb_flags;
438 if (tlb_flag(TLB_DCLEAN))
439 asm("mcr p15, 0, %0, c7, c10, 1 @ flush_pmd"
440 : : "r" (pmd) : "cc");
442 if (tlb_flag(TLB_L2CLEAN_FR))
443 asm("mcr p15, 1, %0, c15, c9, 1 @ L2 flush_pmd"
444 : : "r" (pmd) : "cc");
446 if (tlb_flag(TLB_WB))
450 static inline void clean_pmd_entry(pmd_t *pmd)
452 const unsigned int __tlb_flag = __cpu_tlb_flags;
454 if (tlb_flag(TLB_DCLEAN))
455 asm("mcr p15, 0, %0, c7, c10, 1 @ flush_pmd"
456 : : "r" (pmd) : "cc");
458 if (tlb_flag(TLB_L2CLEAN_FR))
459 asm("mcr p15, 1, %0, c15, c9, 1 @ L2 flush_pmd"
460 : : "r" (pmd) : "cc");
464 #undef always_tlb_flags
465 #undef possible_tlb_flags
468 * Convert calls to our calling convention.
470 #define local_flush_tlb_range(vma,start,end) __cpu_flush_user_tlb_range(start,end,vma)
471 #define local_flush_tlb_kernel_range(s,e) __cpu_flush_kern_tlb_range(s,e)
474 #define flush_tlb_all local_flush_tlb_all
475 #define flush_tlb_mm local_flush_tlb_mm
476 #define flush_tlb_page local_flush_tlb_page
477 #define flush_tlb_kernel_page local_flush_tlb_kernel_page
478 #define flush_tlb_range local_flush_tlb_range
479 #define flush_tlb_kernel_range local_flush_tlb_kernel_range
481 extern void flush_tlb_all(void);
482 extern void flush_tlb_mm(struct mm_struct *mm);
483 extern void flush_tlb_page(struct vm_area_struct *vma, unsigned long uaddr);
484 extern void flush_tlb_kernel_page(unsigned long kaddr);
485 extern void flush_tlb_range(struct vm_area_struct *vma, unsigned long start, unsigned long end);
486 extern void flush_tlb_kernel_range(unsigned long start, unsigned long end);
490 * if PG_dcache_dirty is set for the page, we need to ensure that any
491 * cache entries for the kernels virtual memory range are written
494 extern void update_mmu_cache(struct vm_area_struct *vma, unsigned long addr, pte_t pte);
498 #endif /* CONFIG_MMU */