blob: 02b2f82039828bb0d4b016e41882c3071b686b93 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Russell King4baa9922008-08-02 10:55:55 +01002 * arch/arm/include/asm/tlbflush.h
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * Copyright (C) 1999-2003 Russell King
5 *
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.
9 */
10#ifndef _ASMARM_TLBFLUSH_H
11#define _ASMARM_TLBFLUSH_H
12
Russell King58e9c472011-02-20 12:27:49 +000013#ifdef CONFIG_MMU
Hyok S. Choi01579032006-02-24 21:41:25 +000014
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <asm/glue.h>
16
17#define TLB_V3_PAGE (1 << 0)
18#define TLB_V4_U_PAGE (1 << 1)
19#define TLB_V4_D_PAGE (1 << 2)
20#define TLB_V4_I_PAGE (1 << 3)
21#define TLB_V6_U_PAGE (1 << 4)
22#define TLB_V6_D_PAGE (1 << 5)
23#define TLB_V6_I_PAGE (1 << 6)
24
25#define TLB_V3_FULL (1 << 8)
26#define TLB_V4_U_FULL (1 << 9)
27#define TLB_V4_D_FULL (1 << 10)
28#define TLB_V4_I_FULL (1 << 11)
29#define TLB_V6_U_FULL (1 << 12)
30#define TLB_V6_D_FULL (1 << 13)
31#define TLB_V6_I_FULL (1 << 14)
32
33#define TLB_V6_U_ASID (1 << 16)
34#define TLB_V6_D_ASID (1 << 17)
35#define TLB_V6_I_ASID (1 << 18)
36
Catalin Marinasfaa7bc52009-05-30 14:00:14 +010037/* Unified Inner Shareable TLB operations (ARMv7 MP extensions) */
38#define TLB_V7_UIS_PAGE (1 << 19)
39#define TLB_V7_UIS_FULL (1 << 20)
40#define TLB_V7_UIS_ASID (1 << 21)
41
Russell King43488102011-07-05 09:01:13 +010042#define TLB_BARRIER (1 << 28)
Lennert Buytenhek99c6dc12008-06-22 22:45:04 +020043#define TLB_L2CLEAN_FR (1 << 29) /* Feroceon */
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#define TLB_DCLEAN (1 << 30)
45#define TLB_WB (1 << 31)
46
47/*
48 * MMU TLB Model
49 * =============
50 *
51 * We have the following to choose from:
52 * v3 - ARMv3
53 * v4 - ARMv4 without write buffer
54 * v4wb - ARMv4 with write buffer without I TLB flush entry instruction
55 * v4wbi - ARMv4 with write buffer with I TLB flush entry instruction
Lennert Buytenhek99c6dc12008-06-22 22:45:04 +020056 * fr - Feroceon (v4wbi with non-outer-cacheable page table walks)
Russell King43488102011-07-05 09:01:13 +010057 * fa - Faraday (v4 with write buffer with UTLB)
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 * v6wbi - ARMv6 with write buffer with I TLB flush entry instruction
Paul Walmsley61db7fb2008-08-12 00:04:15 +010059 * v7wbi - identical to v6wbi
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 */
61#undef _TLB
62#undef MULTI_TLB
63
Russell Kingf00ec482010-09-04 10:47:48 +010064#ifdef CONFIG_SMP_ON_UP
65#define MULTI_TLB 1
66#endif
67
Linus Torvalds1da177e2005-04-16 15:20:36 -070068#define v3_tlb_flags (TLB_V3_FULL | TLB_V3_PAGE)
69
70#ifdef CONFIG_CPU_TLB_V3
71# define v3_possible_flags v3_tlb_flags
72# define v3_always_flags v3_tlb_flags
73# ifdef _TLB
74# define MULTI_TLB 1
75# else
76# define _TLB v3
77# endif
78#else
79# define v3_possible_flags 0
80# define v3_always_flags (-1UL)
81#endif
82
83#define v4_tlb_flags (TLB_V4_U_FULL | TLB_V4_U_PAGE)
84
85#ifdef CONFIG_CPU_TLB_V4WT
86# define v4_possible_flags v4_tlb_flags
87# define v4_always_flags v4_tlb_flags
88# ifdef _TLB
89# define MULTI_TLB 1
90# else
91# define _TLB v4
92# endif
93#else
94# define v4_possible_flags 0
95# define v4_always_flags (-1UL)
96#endif
97
Russell King43488102011-07-05 09:01:13 +010098#define fa_tlb_flags (TLB_WB | TLB_DCLEAN | TLB_BARRIER | \
Paulius Zaleckas28853ac2009-03-25 13:10:01 +020099 TLB_V4_U_FULL | TLB_V4_U_PAGE)
100
101#ifdef CONFIG_CPU_TLB_FA
102# define fa_possible_flags fa_tlb_flags
103# define fa_always_flags fa_tlb_flags
104# ifdef _TLB
105# define MULTI_TLB 1
106# else
107# define _TLB fa
108# endif
109#else
110# define fa_possible_flags 0
111# define fa_always_flags (-1UL)
112#endif
113
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114#define v4wbi_tlb_flags (TLB_WB | TLB_DCLEAN | \
115 TLB_V4_I_FULL | TLB_V4_D_FULL | \
116 TLB_V4_I_PAGE | TLB_V4_D_PAGE)
117
118#ifdef CONFIG_CPU_TLB_V4WBI
119# define v4wbi_possible_flags v4wbi_tlb_flags
120# define v4wbi_always_flags v4wbi_tlb_flags
121# ifdef _TLB
122# define MULTI_TLB 1
123# else
124# define _TLB v4wbi
125# endif
126#else
127# define v4wbi_possible_flags 0
128# define v4wbi_always_flags (-1UL)
129#endif
130
Lennert Buytenhek99c6dc12008-06-22 22:45:04 +0200131#define fr_tlb_flags (TLB_WB | TLB_DCLEAN | TLB_L2CLEAN_FR | \
132 TLB_V4_I_FULL | TLB_V4_D_FULL | \
133 TLB_V4_I_PAGE | TLB_V4_D_PAGE)
134
135#ifdef CONFIG_CPU_TLB_FEROCEON
136# define fr_possible_flags fr_tlb_flags
137# define fr_always_flags fr_tlb_flags
138# ifdef _TLB
139# define MULTI_TLB 1
140# else
141# define _TLB v4wbi
142# endif
143#else
144# define fr_possible_flags 0
145# define fr_always_flags (-1UL)
146#endif
147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148#define v4wb_tlb_flags (TLB_WB | TLB_DCLEAN | \
149 TLB_V4_I_FULL | TLB_V4_D_FULL | \
150 TLB_V4_D_PAGE)
151
152#ifdef CONFIG_CPU_TLB_V4WB
153# define v4wb_possible_flags v4wb_tlb_flags
154# define v4wb_always_flags v4wb_tlb_flags
155# ifdef _TLB
156# define MULTI_TLB 1
157# else
158# define _TLB v4wb
159# endif
160#else
161# define v4wb_possible_flags 0
162# define v4wb_always_flags (-1UL)
163#endif
164
Russell King43488102011-07-05 09:01:13 +0100165#define v6wbi_tlb_flags (TLB_WB | TLB_DCLEAN | TLB_BARRIER | \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 TLB_V6_I_FULL | TLB_V6_D_FULL | \
167 TLB_V6_I_PAGE | TLB_V6_D_PAGE | \
168 TLB_V6_I_ASID | TLB_V6_D_ASID)
169
170#ifdef CONFIG_CPU_TLB_V6
171# define v6wbi_possible_flags v6wbi_tlb_flags
172# define v6wbi_always_flags v6wbi_tlb_flags
173# ifdef _TLB
174# define MULTI_TLB 1
175# else
176# define _TLB v6wbi
177# endif
178#else
179# define v6wbi_possible_flags 0
180# define v6wbi_always_flags (-1UL)
181#endif
182
Russell King43488102011-07-05 09:01:13 +0100183#define v7wbi_tlb_flags_smp (TLB_WB | TLB_DCLEAN | TLB_BARRIER | \
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100184 TLB_V7_UIS_FULL | TLB_V7_UIS_PAGE | TLB_V7_UIS_ASID)
Russell King43488102011-07-05 09:01:13 +0100185#define v7wbi_tlb_flags_up (TLB_WB | TLB_DCLEAN | TLB_BARRIER | \
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100186 TLB_V6_U_FULL | TLB_V6_U_PAGE | TLB_V6_U_ASID)
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100187
Catalin Marinas2ccdd1e2007-05-18 11:25:31 +0100188#ifdef CONFIG_CPU_TLB_V7
Russell Kingf00ec482010-09-04 10:47:48 +0100189
190# ifdef CONFIG_SMP_ON_UP
191# define v7wbi_possible_flags (v7wbi_tlb_flags_smp | v7wbi_tlb_flags_up)
192# define v7wbi_always_flags (v7wbi_tlb_flags_smp & v7wbi_tlb_flags_up)
193# elif defined(CONFIG_SMP)
194# define v7wbi_possible_flags v7wbi_tlb_flags_smp
195# define v7wbi_always_flags v7wbi_tlb_flags_smp
196# else
197# define v7wbi_possible_flags v7wbi_tlb_flags_up
198# define v7wbi_always_flags v7wbi_tlb_flags_up
199# endif
Catalin Marinas2ccdd1e2007-05-18 11:25:31 +0100200# ifdef _TLB
201# define MULTI_TLB 1
202# else
203# define _TLB v7wbi
204# endif
205#else
206# define v7wbi_possible_flags 0
207# define v7wbi_always_flags (-1UL)
208#endif
209
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210#ifndef _TLB
211#error Unknown TLB model
212#endif
213
214#ifndef __ASSEMBLY__
215
Alexey Dobriyane8edc6e2007-05-21 01:22:52 +0400216#include <linux/sched.h>
217
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218struct cpu_tlb_fns {
219 void (*flush_user_range)(unsigned long, unsigned long, struct vm_area_struct *);
220 void (*flush_kern_range)(unsigned long, unsigned long);
221 unsigned long tlb_flags;
222};
223
224/*
225 * Select the calling method
226 */
227#ifdef MULTI_TLB
228
229#define __cpu_flush_user_tlb_range cpu_tlb.flush_user_range
230#define __cpu_flush_kern_tlb_range cpu_tlb.flush_kern_range
231
232#else
233
234#define __cpu_flush_user_tlb_range __glue(_TLB,_flush_user_tlb_range)
235#define __cpu_flush_kern_tlb_range __glue(_TLB,_flush_kern_tlb_range)
236
237extern void __cpu_flush_user_tlb_range(unsigned long, unsigned long, struct vm_area_struct *);
238extern void __cpu_flush_kern_tlb_range(unsigned long, unsigned long);
239
240#endif
241
242extern struct cpu_tlb_fns cpu_tlb;
243
244#define __cpu_tlb_flags cpu_tlb.tlb_flags
245
246/*
247 * TLB Management
248 * ==============
249 *
250 * The arch/arm/mm/tlb-*.S files implement these methods.
251 *
252 * The TLB specific code is expected to perform whatever tests it
253 * needs to determine if it should invalidate the TLB for each
254 * call. Start addresses are inclusive and end addresses are
255 * exclusive; it is safe to round these addresses down.
256 *
257 * flush_tlb_all()
258 *
259 * Invalidate the entire TLB.
260 *
261 * flush_tlb_mm(mm)
262 *
263 * Invalidate all TLB entries in a particular address
264 * space.
265 * - mm - mm_struct describing address space
266 *
267 * flush_tlb_range(mm,start,end)
268 *
269 * Invalidate a range of TLB entries in the specified
270 * address space.
271 * - mm - mm_struct describing address space
272 * - start - start address (may not be aligned)
273 * - end - end address (exclusive, may not be aligned)
274 *
275 * flush_tlb_page(vaddr,vma)
276 *
277 * Invalidate the specified page in the specified address range.
278 * - vaddr - virtual address (may not be aligned)
279 * - vma - vma_struct describing address range
280 *
281 * flush_kern_tlb_page(kaddr)
282 *
283 * Invalidate the TLB entry for the specified page. The address
284 * will be in the kernels virtual memory space. Current uses
285 * only require the D-TLB to be invalidated.
286 * - kaddr - Kernel virtual memory address
287 */
288
289/*
290 * We optimise the code below by:
291 * - building a set of TLB flags that might be set in __cpu_tlb_flags
292 * - building a set of TLB flags that will always be set in __cpu_tlb_flags
293 * - if we're going to need __cpu_tlb_flags, access it once and only once
294 *
295 * This allows us to build optimal assembly for the single-CPU type case,
296 * and as close to optimal given the compiler constrants for multi-CPU
297 * case. We could do better for the multi-CPU case if the compiler
298 * implemented the "%?" method, but this has been discontinued due to too
299 * many people getting it wrong.
300 */
301#define possible_tlb_flags (v3_possible_flags | \
302 v4_possible_flags | \
303 v4wbi_possible_flags | \
Lennert Buytenhek99c6dc12008-06-22 22:45:04 +0200304 fr_possible_flags | \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 v4wb_possible_flags | \
Paulius Zaleckas28853ac2009-03-25 13:10:01 +0200306 fa_possible_flags | \
Paul Walmsley61db7fb2008-08-12 00:04:15 +0100307 v6wbi_possible_flags | \
308 v7wbi_possible_flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309
310#define always_tlb_flags (v3_always_flags & \
311 v4_always_flags & \
312 v4wbi_always_flags & \
Lennert Buytenhek99c6dc12008-06-22 22:45:04 +0200313 fr_always_flags & \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 v4wb_always_flags & \
Paulius Zaleckas28853ac2009-03-25 13:10:01 +0200315 fa_always_flags & \
Paul Walmsley61db7fb2008-08-12 00:04:15 +0100316 v6wbi_always_flags & \
317 v7wbi_always_flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318
319#define tlb_flag(f) ((always_tlb_flags & (f)) || (__tlb_flag & possible_tlb_flags & (f)))
320
Russell King603fff52005-06-28 13:40:39 +0100321static inline void local_flush_tlb_all(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322{
323 const int zero = 0;
324 const unsigned int __tlb_flag = __cpu_tlb_flags;
325
326 if (tlb_flag(TLB_WB))
Catalin Marinase6a5d662007-02-05 14:47:51 +0100327 dsb();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
329 if (tlb_flag(TLB_V3_FULL))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100330 asm("mcr p15, 0, %0, c6, c0, 0" : : "r" (zero) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 if (tlb_flag(TLB_V4_U_FULL | TLB_V6_U_FULL))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100332 asm("mcr p15, 0, %0, c8, c7, 0" : : "r" (zero) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 if (tlb_flag(TLB_V4_D_FULL | TLB_V6_D_FULL))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100334 asm("mcr p15, 0, %0, c8, c6, 0" : : "r" (zero) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 if (tlb_flag(TLB_V4_I_FULL | TLB_V6_I_FULL))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100336 asm("mcr p15, 0, %0, c8, c5, 0" : : "r" (zero) : "cc");
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100337 if (tlb_flag(TLB_V7_UIS_FULL))
338 asm("mcr p15, 0, %0, c8, c3, 0" : : "r" (zero) : "cc");
Catalin Marinase6a5d662007-02-05 14:47:51 +0100339
Russell King43488102011-07-05 09:01:13 +0100340 if (tlb_flag(TLB_BARRIER)) {
Catalin Marinasb8349b52010-05-07 18:03:05 +0100341 dsb();
342 isb();
343 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344}
345
Russell King603fff52005-06-28 13:40:39 +0100346static inline void local_flush_tlb_mm(struct mm_struct *mm)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347{
348 const int zero = 0;
349 const int asid = ASID(mm);
350 const unsigned int __tlb_flag = __cpu_tlb_flags;
351
352 if (tlb_flag(TLB_WB))
Catalin Marinase6a5d662007-02-05 14:47:51 +0100353 dsb();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
Santosh Shilimkardaaeb6c2009-10-15 15:06:47 +0100355 if (cpumask_test_cpu(get_cpu(), mm_cpumask(mm))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 if (tlb_flag(TLB_V3_FULL))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100357 asm("mcr p15, 0, %0, c6, c0, 0" : : "r" (zero) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 if (tlb_flag(TLB_V4_U_FULL))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100359 asm("mcr p15, 0, %0, c8, c7, 0" : : "r" (zero) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 if (tlb_flag(TLB_V4_D_FULL))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100361 asm("mcr p15, 0, %0, c8, c6, 0" : : "r" (zero) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 if (tlb_flag(TLB_V4_I_FULL))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100363 asm("mcr p15, 0, %0, c8, c5, 0" : : "r" (zero) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 }
Santosh Shilimkardaaeb6c2009-10-15 15:06:47 +0100365 put_cpu();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
367 if (tlb_flag(TLB_V6_U_ASID))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100368 asm("mcr p15, 0, %0, c8, c7, 2" : : "r" (asid) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 if (tlb_flag(TLB_V6_D_ASID))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100370 asm("mcr p15, 0, %0, c8, c6, 2" : : "r" (asid) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 if (tlb_flag(TLB_V6_I_ASID))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100372 asm("mcr p15, 0, %0, c8, c5, 2" : : "r" (asid) : "cc");
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100373 if (tlb_flag(TLB_V7_UIS_ASID))
Will Deaconcdf357f2010-08-05 11:20:51 +0100374#ifdef CONFIG_ARM_ERRATA_720789
375 asm("mcr p15, 0, %0, c8, c3, 0" : : "r" (zero) : "cc");
376#else
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100377 asm("mcr p15, 0, %0, c8, c3, 2" : : "r" (asid) : "cc");
Will Deaconcdf357f2010-08-05 11:20:51 +0100378#endif
Catalin Marinase6a5d662007-02-05 14:47:51 +0100379
Russell King43488102011-07-05 09:01:13 +0100380 if (tlb_flag(TLB_BARRIER))
Catalin Marinase6a5d662007-02-05 14:47:51 +0100381 dsb();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382}
383
384static inline void
Russell King603fff52005-06-28 13:40:39 +0100385local_flush_tlb_page(struct vm_area_struct *vma, unsigned long uaddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386{
387 const int zero = 0;
388 const unsigned int __tlb_flag = __cpu_tlb_flags;
389
390 uaddr = (uaddr & PAGE_MASK) | ASID(vma->vm_mm);
391
392 if (tlb_flag(TLB_WB))
Catalin Marinase6a5d662007-02-05 14:47:51 +0100393 dsb();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
Rusty Russell56f8ba82009-09-24 09:34:49 -0600395 if (cpumask_test_cpu(smp_processor_id(), mm_cpumask(vma->vm_mm))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 if (tlb_flag(TLB_V3_PAGE))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100397 asm("mcr p15, 0, %0, c6, c0, 0" : : "r" (uaddr) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 if (tlb_flag(TLB_V4_U_PAGE))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100399 asm("mcr p15, 0, %0, c8, c7, 1" : : "r" (uaddr) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 if (tlb_flag(TLB_V4_D_PAGE))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100401 asm("mcr p15, 0, %0, c8, c6, 1" : : "r" (uaddr) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 if (tlb_flag(TLB_V4_I_PAGE))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100403 asm("mcr p15, 0, %0, c8, c5, 1" : : "r" (uaddr) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 if (!tlb_flag(TLB_V4_I_PAGE) && tlb_flag(TLB_V4_I_FULL))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100405 asm("mcr p15, 0, %0, c8, c5, 0" : : "r" (zero) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 }
407
408 if (tlb_flag(TLB_V6_U_PAGE))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100409 asm("mcr p15, 0, %0, c8, c7, 1" : : "r" (uaddr) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 if (tlb_flag(TLB_V6_D_PAGE))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100411 asm("mcr p15, 0, %0, c8, c6, 1" : : "r" (uaddr) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 if (tlb_flag(TLB_V6_I_PAGE))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100413 asm("mcr p15, 0, %0, c8, c5, 1" : : "r" (uaddr) : "cc");
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100414 if (tlb_flag(TLB_V7_UIS_PAGE))
Will Deaconcdf357f2010-08-05 11:20:51 +0100415#ifdef CONFIG_ARM_ERRATA_720789
416 asm("mcr p15, 0, %0, c8, c3, 3" : : "r" (uaddr & PAGE_MASK) : "cc");
417#else
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100418 asm("mcr p15, 0, %0, c8, c3, 1" : : "r" (uaddr) : "cc");
Will Deaconcdf357f2010-08-05 11:20:51 +0100419#endif
Catalin Marinase6a5d662007-02-05 14:47:51 +0100420
Russell King43488102011-07-05 09:01:13 +0100421 if (tlb_flag(TLB_BARRIER))
Catalin Marinase6a5d662007-02-05 14:47:51 +0100422 dsb();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423}
424
Russell King603fff52005-06-28 13:40:39 +0100425static inline void local_flush_tlb_kernel_page(unsigned long kaddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426{
427 const int zero = 0;
428 const unsigned int __tlb_flag = __cpu_tlb_flags;
429
430 kaddr &= PAGE_MASK;
431
432 if (tlb_flag(TLB_WB))
Catalin Marinase6a5d662007-02-05 14:47:51 +0100433 dsb();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
435 if (tlb_flag(TLB_V3_PAGE))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100436 asm("mcr p15, 0, %0, c6, c0, 0" : : "r" (kaddr) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 if (tlb_flag(TLB_V4_U_PAGE))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100438 asm("mcr p15, 0, %0, c8, c7, 1" : : "r" (kaddr) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 if (tlb_flag(TLB_V4_D_PAGE))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100440 asm("mcr p15, 0, %0, c8, c6, 1" : : "r" (kaddr) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 if (tlb_flag(TLB_V4_I_PAGE))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100442 asm("mcr p15, 0, %0, c8, c5, 1" : : "r" (kaddr) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 if (!tlb_flag(TLB_V4_I_PAGE) && tlb_flag(TLB_V4_I_FULL))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100444 asm("mcr p15, 0, %0, c8, c5, 0" : : "r" (zero) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445
446 if (tlb_flag(TLB_V6_U_PAGE))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100447 asm("mcr p15, 0, %0, c8, c7, 1" : : "r" (kaddr) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 if (tlb_flag(TLB_V6_D_PAGE))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100449 asm("mcr p15, 0, %0, c8, c6, 1" : : "r" (kaddr) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 if (tlb_flag(TLB_V6_I_PAGE))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100451 asm("mcr p15, 0, %0, c8, c5, 1" : : "r" (kaddr) : "cc");
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100452 if (tlb_flag(TLB_V7_UIS_PAGE))
453 asm("mcr p15, 0, %0, c8, c3, 1" : : "r" (kaddr) : "cc");
Catalin Marinas6a0e2432006-03-07 14:42:27 +0000454
Russell King43488102011-07-05 09:01:13 +0100455 if (tlb_flag(TLB_BARRIER)) {
Catalin Marinasb8349b52010-05-07 18:03:05 +0100456 dsb();
457 isb();
458 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459}
460
461/*
462 * flush_pmd_entry
463 *
464 * Flush a PMD entry (word aligned, or double-word aligned) to
465 * RAM if the TLB for the CPU we are running on requires this.
466 * This is typically used when we are creating PMD entries.
467 *
468 * clean_pmd_entry
469 *
470 * Clean (but don't drain the write buffer) if the CPU requires
471 * these operations. This is typically used when we are removing
472 * PMD entries.
473 */
Catalin Marinas442e70c2011-09-05 17:51:56 +0100474static inline void flush_pmd_entry(void *pmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 const unsigned int __tlb_flag = __cpu_tlb_flags;
477
478 if (tlb_flag(TLB_DCLEAN))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100479 asm("mcr p15, 0, %0, c7, c10, 1 @ flush_pmd"
480 : : "r" (pmd) : "cc");
Lennert Buytenhek99c6dc12008-06-22 22:45:04 +0200481
482 if (tlb_flag(TLB_L2CLEAN_FR))
483 asm("mcr p15, 1, %0, c15, c9, 1 @ L2 flush_pmd"
484 : : "r" (pmd) : "cc");
485
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 if (tlb_flag(TLB_WB))
Catalin Marinase6a5d662007-02-05 14:47:51 +0100487 dsb();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488}
489
Catalin Marinas442e70c2011-09-05 17:51:56 +0100490static inline void clean_pmd_entry(void *pmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491{
492 const unsigned int __tlb_flag = __cpu_tlb_flags;
493
494 if (tlb_flag(TLB_DCLEAN))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100495 asm("mcr p15, 0, %0, c7, c10, 1 @ flush_pmd"
496 : : "r" (pmd) : "cc");
Lennert Buytenhek99c6dc12008-06-22 22:45:04 +0200497
498 if (tlb_flag(TLB_L2CLEAN_FR))
499 asm("mcr p15, 1, %0, c15, c9, 1 @ L2 flush_pmd"
500 : : "r" (pmd) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501}
502
503#undef tlb_flag
504#undef always_tlb_flags
505#undef possible_tlb_flags
506
507/*
508 * Convert calls to our calling convention.
509 */
Russell King603fff52005-06-28 13:40:39 +0100510#define local_flush_tlb_range(vma,start,end) __cpu_flush_user_tlb_range(start,end,vma)
511#define local_flush_tlb_kernel_range(s,e) __cpu_flush_kern_tlb_range(s,e)
512
513#ifndef CONFIG_SMP
514#define flush_tlb_all local_flush_tlb_all
515#define flush_tlb_mm local_flush_tlb_mm
516#define flush_tlb_page local_flush_tlb_page
517#define flush_tlb_kernel_page local_flush_tlb_kernel_page
518#define flush_tlb_range local_flush_tlb_range
519#define flush_tlb_kernel_range local_flush_tlb_kernel_range
520#else
521extern void flush_tlb_all(void);
522extern void flush_tlb_mm(struct mm_struct *mm);
523extern void flush_tlb_page(struct vm_area_struct *vma, unsigned long uaddr);
524extern void flush_tlb_kernel_page(unsigned long kaddr);
525extern void flush_tlb_range(struct vm_area_struct *vma, unsigned long start, unsigned long end);
526extern void flush_tlb_kernel_range(unsigned long start, unsigned long end);
527#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
529/*
Catalin Marinasc0177802010-09-13 15:57:36 +0100530 * If PG_dcache_clean is not set for the page, we need to ensure that any
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 * cache entries for the kernels virtual memory range are written
Catalin Marinas60121912010-09-13 15:58:06 +0100532 * back to the page. On ARMv6 and later, the cache coherency is handled via
533 * the set_pte_at() function.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 */
Catalin Marinas60121912010-09-13 15:58:06 +0100535#if __LINUX_ARM_ARCH__ < 6
Russell King4b3073e2009-12-18 16:40:18 +0000536extern void update_mmu_cache(struct vm_area_struct *vma, unsigned long addr,
537 pte_t *ptep);
Catalin Marinas60121912010-09-13 15:58:06 +0100538#else
539static inline void update_mmu_cache(struct vm_area_struct *vma,
540 unsigned long addr, pte_t *ptep)
541{
542}
543#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545#endif
546
Hyok S. Choi01579032006-02-24 21:41:25 +0000547#endif /* CONFIG_MMU */
548
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549#endif