blob: 1897b5196fb57fd9a1cc8962d3d65ad317ca6bcd [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
Ingo Molnar589ee622017-02-04 00:16:44 +010013#ifndef __ASSEMBLY__
14# include <linux/mm_types.h>
15#endif
16
Russell King58e9c472011-02-20 12:27:49 +000017#ifdef CONFIG_MMU
Hyok S. Choi01579032006-02-24 21:41:25 +000018
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <asm/glue.h>
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#define TLB_V4_U_PAGE (1 << 1)
22#define TLB_V4_D_PAGE (1 << 2)
23#define TLB_V4_I_PAGE (1 << 3)
24#define TLB_V6_U_PAGE (1 << 4)
25#define TLB_V6_D_PAGE (1 << 5)
26#define TLB_V6_I_PAGE (1 << 6)
27
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#define TLB_V4_U_FULL (1 << 9)
29#define TLB_V4_D_FULL (1 << 10)
30#define TLB_V4_I_FULL (1 << 11)
31#define TLB_V6_U_FULL (1 << 12)
32#define TLB_V6_D_FULL (1 << 13)
33#define TLB_V6_I_FULL (1 << 14)
34
35#define TLB_V6_U_ASID (1 << 16)
36#define TLB_V6_D_ASID (1 << 17)
37#define TLB_V6_I_ASID (1 << 18)
38
Will Deacon862c5882013-02-28 17:48:11 +010039#define TLB_V6_BP (1 << 19)
40
Catalin Marinasfaa7bc52009-05-30 14:00:14 +010041/* Unified Inner Shareable TLB operations (ARMv7 MP extensions) */
Will Deacon862c5882013-02-28 17:48:11 +010042#define TLB_V7_UIS_PAGE (1 << 20)
43#define TLB_V7_UIS_FULL (1 << 21)
44#define TLB_V7_UIS_ASID (1 << 22)
45#define TLB_V7_UIS_BP (1 << 23)
Catalin Marinasfaa7bc52009-05-30 14:00:14 +010046
Russell King43488102011-07-05 09:01:13 +010047#define TLB_BARRIER (1 << 28)
Lennert Buytenhek99c6dc12008-06-22 22:45:04 +020048#define TLB_L2CLEAN_FR (1 << 29) /* Feroceon */
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#define TLB_DCLEAN (1 << 30)
50#define TLB_WB (1 << 31)
51
52/*
53 * MMU TLB Model
54 * =============
55 *
56 * We have the following to choose from:
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 * v4 - ARMv4 without write buffer
58 * v4wb - ARMv4 with write buffer without I TLB flush entry instruction
59 * v4wbi - ARMv4 with write buffer with I TLB flush entry instruction
Lennert Buytenhek99c6dc12008-06-22 22:45:04 +020060 * fr - Feroceon (v4wbi with non-outer-cacheable page table walks)
Russell King43488102011-07-05 09:01:13 +010061 * fa - Faraday (v4 with write buffer with UTLB)
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 * v6wbi - ARMv6 with write buffer with I TLB flush entry instruction
Paul Walmsley61db7fb2008-08-12 00:04:15 +010063 * v7wbi - identical to v6wbi
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 */
65#undef _TLB
66#undef MULTI_TLB
67
Russell Kingf00ec482010-09-04 10:47:48 +010068#ifdef CONFIG_SMP_ON_UP
69#define MULTI_TLB 1
70#endif
71
Linus Torvalds1da177e2005-04-16 15:20:36 -070072#define v4_tlb_flags (TLB_V4_U_FULL | TLB_V4_U_PAGE)
73
74#ifdef CONFIG_CPU_TLB_V4WT
75# define v4_possible_flags v4_tlb_flags
76# define v4_always_flags v4_tlb_flags
77# ifdef _TLB
78# define MULTI_TLB 1
79# else
80# define _TLB v4
81# endif
82#else
83# define v4_possible_flags 0
84# define v4_always_flags (-1UL)
85#endif
86
Russell King43488102011-07-05 09:01:13 +010087#define fa_tlb_flags (TLB_WB | TLB_DCLEAN | TLB_BARRIER | \
Paulius Zaleckas28853ac2009-03-25 13:10:01 +020088 TLB_V4_U_FULL | TLB_V4_U_PAGE)
89
90#ifdef CONFIG_CPU_TLB_FA
91# define fa_possible_flags fa_tlb_flags
92# define fa_always_flags fa_tlb_flags
93# ifdef _TLB
94# define MULTI_TLB 1
95# else
96# define _TLB fa
97# endif
98#else
99# define fa_possible_flags 0
100# define fa_always_flags (-1UL)
101#endif
102
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103#define v4wbi_tlb_flags (TLB_WB | TLB_DCLEAN | \
104 TLB_V4_I_FULL | TLB_V4_D_FULL | \
105 TLB_V4_I_PAGE | TLB_V4_D_PAGE)
106
107#ifdef CONFIG_CPU_TLB_V4WBI
108# define v4wbi_possible_flags v4wbi_tlb_flags
109# define v4wbi_always_flags v4wbi_tlb_flags
110# ifdef _TLB
111# define MULTI_TLB 1
112# else
113# define _TLB v4wbi
114# endif
115#else
116# define v4wbi_possible_flags 0
117# define v4wbi_always_flags (-1UL)
118#endif
119
Lennert Buytenhek99c6dc12008-06-22 22:45:04 +0200120#define fr_tlb_flags (TLB_WB | TLB_DCLEAN | TLB_L2CLEAN_FR | \
121 TLB_V4_I_FULL | TLB_V4_D_FULL | \
122 TLB_V4_I_PAGE | TLB_V4_D_PAGE)
123
124#ifdef CONFIG_CPU_TLB_FEROCEON
125# define fr_possible_flags fr_tlb_flags
126# define fr_always_flags fr_tlb_flags
127# ifdef _TLB
128# define MULTI_TLB 1
129# else
130# define _TLB v4wbi
131# endif
132#else
133# define fr_possible_flags 0
134# define fr_always_flags (-1UL)
135#endif
136
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137#define v4wb_tlb_flags (TLB_WB | TLB_DCLEAN | \
138 TLB_V4_I_FULL | TLB_V4_D_FULL | \
139 TLB_V4_D_PAGE)
140
141#ifdef CONFIG_CPU_TLB_V4WB
142# define v4wb_possible_flags v4wb_tlb_flags
143# define v4wb_always_flags v4wb_tlb_flags
144# ifdef _TLB
145# define MULTI_TLB 1
146# else
147# define _TLB v4wb
148# endif
149#else
150# define v4wb_possible_flags 0
151# define v4wb_always_flags (-1UL)
152#endif
153
Russell King43488102011-07-05 09:01:13 +0100154#define v6wbi_tlb_flags (TLB_WB | TLB_DCLEAN | TLB_BARRIER | \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 TLB_V6_I_FULL | TLB_V6_D_FULL | \
156 TLB_V6_I_PAGE | TLB_V6_D_PAGE | \
Will Deacon862c5882013-02-28 17:48:11 +0100157 TLB_V6_I_ASID | TLB_V6_D_ASID | \
158 TLB_V6_BP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
160#ifdef CONFIG_CPU_TLB_V6
161# define v6wbi_possible_flags v6wbi_tlb_flags
162# define v6wbi_always_flags v6wbi_tlb_flags
163# ifdef _TLB
164# define MULTI_TLB 1
165# else
166# define _TLB v6wbi
167# endif
168#else
169# define v6wbi_possible_flags 0
170# define v6wbi_always_flags (-1UL)
171#endif
172
Will Deaconae8a8b92013-04-03 17:16:57 +0100173#define v7wbi_tlb_flags_smp (TLB_WB | TLB_BARRIER | \
Will Deacon862c5882013-02-28 17:48:11 +0100174 TLB_V7_UIS_FULL | TLB_V7_UIS_PAGE | \
175 TLB_V7_UIS_ASID | TLB_V7_UIS_BP)
Russell King43488102011-07-05 09:01:13 +0100176#define v7wbi_tlb_flags_up (TLB_WB | TLB_DCLEAN | TLB_BARRIER | \
Will Deacon862c5882013-02-28 17:48:11 +0100177 TLB_V6_U_FULL | TLB_V6_U_PAGE | \
178 TLB_V6_U_ASID | TLB_V6_BP)
Catalin Marinasfaa7bc52009-05-30 14:00:14 +0100179
Catalin Marinas2ccdd1e2007-05-18 11:25:31 +0100180#ifdef CONFIG_CPU_TLB_V7
Russell Kingf00ec482010-09-04 10:47:48 +0100181
182# ifdef CONFIG_SMP_ON_UP
183# define v7wbi_possible_flags (v7wbi_tlb_flags_smp | v7wbi_tlb_flags_up)
184# define v7wbi_always_flags (v7wbi_tlb_flags_smp & v7wbi_tlb_flags_up)
185# elif defined(CONFIG_SMP)
186# define v7wbi_possible_flags v7wbi_tlb_flags_smp
187# define v7wbi_always_flags v7wbi_tlb_flags_smp
188# else
189# define v7wbi_possible_flags v7wbi_tlb_flags_up
190# define v7wbi_always_flags v7wbi_tlb_flags_up
191# endif
Catalin Marinas2ccdd1e2007-05-18 11:25:31 +0100192# ifdef _TLB
193# define MULTI_TLB 1
194# else
195# define _TLB v7wbi
196# endif
197#else
198# define v7wbi_possible_flags 0
199# define v7wbi_always_flags (-1UL)
200#endif
201
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202#ifndef _TLB
203#error Unknown TLB model
204#endif
205
206#ifndef __ASSEMBLY__
207
Alexey Dobriyane8edc6e2007-05-21 01:22:52 +0400208#include <linux/sched.h>
209
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210struct cpu_tlb_fns {
211 void (*flush_user_range)(unsigned long, unsigned long, struct vm_area_struct *);
212 void (*flush_kern_range)(unsigned long, unsigned long);
213 unsigned long tlb_flags;
214};
215
216/*
217 * Select the calling method
218 */
219#ifdef MULTI_TLB
220
221#define __cpu_flush_user_tlb_range cpu_tlb.flush_user_range
222#define __cpu_flush_kern_tlb_range cpu_tlb.flush_kern_range
223
224#else
225
226#define __cpu_flush_user_tlb_range __glue(_TLB,_flush_user_tlb_range)
227#define __cpu_flush_kern_tlb_range __glue(_TLB,_flush_kern_tlb_range)
228
229extern void __cpu_flush_user_tlb_range(unsigned long, unsigned long, struct vm_area_struct *);
230extern void __cpu_flush_kern_tlb_range(unsigned long, unsigned long);
231
232#endif
233
234extern struct cpu_tlb_fns cpu_tlb;
235
236#define __cpu_tlb_flags cpu_tlb.tlb_flags
237
238/*
239 * TLB Management
240 * ==============
241 *
242 * The arch/arm/mm/tlb-*.S files implement these methods.
243 *
244 * The TLB specific code is expected to perform whatever tests it
245 * needs to determine if it should invalidate the TLB for each
246 * call. Start addresses are inclusive and end addresses are
247 * exclusive; it is safe to round these addresses down.
248 *
249 * flush_tlb_all()
250 *
251 * Invalidate the entire TLB.
252 *
253 * flush_tlb_mm(mm)
254 *
255 * Invalidate all TLB entries in a particular address
256 * space.
257 * - mm - mm_struct describing address space
258 *
259 * flush_tlb_range(mm,start,end)
260 *
261 * Invalidate a range of TLB entries in the specified
262 * address space.
263 * - mm - mm_struct describing address space
264 * - start - start address (may not be aligned)
265 * - end - end address (exclusive, may not be aligned)
266 *
267 * flush_tlb_page(vaddr,vma)
268 *
269 * Invalidate the specified page in the specified address range.
270 * - vaddr - virtual address (may not be aligned)
271 * - vma - vma_struct describing address range
272 *
273 * flush_kern_tlb_page(kaddr)
274 *
275 * Invalidate the TLB entry for the specified page. The address
276 * will be in the kernels virtual memory space. Current uses
277 * only require the D-TLB to be invalidated.
278 * - kaddr - Kernel virtual memory address
279 */
280
281/*
282 * We optimise the code below by:
283 * - building a set of TLB flags that might be set in __cpu_tlb_flags
284 * - building a set of TLB flags that will always be set in __cpu_tlb_flags
285 * - if we're going to need __cpu_tlb_flags, access it once and only once
286 *
287 * This allows us to build optimal assembly for the single-CPU type case,
288 * and as close to optimal given the compiler constrants for multi-CPU
289 * case. We could do better for the multi-CPU case if the compiler
290 * implemented the "%?" method, but this has been discontinued due to too
291 * many people getting it wrong.
292 */
Russell King357c9c12012-05-04 12:04:26 +0100293#define possible_tlb_flags (v4_possible_flags | \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 v4wbi_possible_flags | \
Lennert Buytenhek99c6dc12008-06-22 22:45:04 +0200295 fr_possible_flags | \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 v4wb_possible_flags | \
Paulius Zaleckas28853ac2009-03-25 13:10:01 +0200297 fa_possible_flags | \
Paul Walmsley61db7fb2008-08-12 00:04:15 +0100298 v6wbi_possible_flags | \
299 v7wbi_possible_flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
Russell King357c9c12012-05-04 12:04:26 +0100301#define always_tlb_flags (v4_always_flags & \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 v4wbi_always_flags & \
Lennert Buytenhek99c6dc12008-06-22 22:45:04 +0200303 fr_always_flags & \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 v4wb_always_flags & \
Paulius Zaleckas28853ac2009-03-25 13:10:01 +0200305 fa_always_flags & \
Paul Walmsley61db7fb2008-08-12 00:04:15 +0100306 v6wbi_always_flags & \
307 v7wbi_always_flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
309#define tlb_flag(f) ((always_tlb_flags & (f)) || (__tlb_flag & possible_tlb_flags & (f)))
310
Russell King87067a92012-02-04 10:55:38 +0000311#define __tlb_op(f, insnarg, arg) \
312 do { \
313 if (always_tlb_flags & (f)) \
314 asm("mcr " insnarg \
315 : : "r" (arg) : "cc"); \
316 else if (possible_tlb_flags & (f)) \
317 asm("tst %1, %2\n\t" \
318 "mcrne " insnarg \
319 : : "r" (arg), "r" (__tlb_flag), "Ir" (f) \
320 : "cc"); \
321 } while (0)
322
323#define tlb_op(f, regs, arg) __tlb_op(f, "p15, 0, %0, " regs, arg)
324#define tlb_l2_op(f, regs, arg) __tlb_op(f, "p15, 1, %0, " regs, arg)
325
Will Deaconf0915782013-02-11 13:47:48 +0000326static inline void __local_flush_tlb_all(void)
327{
328 const int zero = 0;
329 const unsigned int __tlb_flag = __cpu_tlb_flags;
330
331 tlb_op(TLB_V4_U_FULL | TLB_V6_U_FULL, "c8, c7, 0", zero);
332 tlb_op(TLB_V4_D_FULL | TLB_V6_D_FULL, "c8, c6, 0", zero);
333 tlb_op(TLB_V4_I_FULL | TLB_V6_I_FULL, "c8, c5, 0", zero);
334}
335
Russell King603fff52005-06-28 13:40:39 +0100336static inline void local_flush_tlb_all(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337{
338 const int zero = 0;
339 const unsigned int __tlb_flag = __cpu_tlb_flags;
340
341 if (tlb_flag(TLB_WB))
Will Deacon62cbbc42013-05-23 18:43:58 +0100342 dsb(nshst);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343
Will Deaconf0915782013-02-11 13:47:48 +0000344 __local_flush_tlb_all();
345 tlb_op(TLB_V7_UIS_FULL, "c8, c7, 0", zero);
346
347 if (tlb_flag(TLB_BARRIER)) {
Will Deacon62cbbc42013-05-23 18:43:58 +0100348 dsb(nsh);
Will Deaconf0915782013-02-11 13:47:48 +0000349 isb();
350 }
351}
352
353static inline void __flush_tlb_all(void)
354{
355 const int zero = 0;
356 const unsigned int __tlb_flag = __cpu_tlb_flags;
357
358 if (tlb_flag(TLB_WB))
Will Deacon62cbbc42013-05-23 18:43:58 +0100359 dsb(ishst);
Will Deaconf0915782013-02-11 13:47:48 +0000360
361 __local_flush_tlb_all();
Russell King87067a92012-02-04 10:55:38 +0000362 tlb_op(TLB_V7_UIS_FULL, "c8, c3, 0", zero);
Catalin Marinase6a5d662007-02-05 14:47:51 +0100363
Russell King43488102011-07-05 09:01:13 +0100364 if (tlb_flag(TLB_BARRIER)) {
Will Deacon62cbbc42013-05-23 18:43:58 +0100365 dsb(ish);
Catalin Marinasb8349b52010-05-07 18:03:05 +0100366 isb();
367 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368}
369
Will Deaconf0915782013-02-11 13:47:48 +0000370static inline void __local_flush_tlb_mm(struct mm_struct *mm)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371{
372 const int zero = 0;
373 const int asid = ASID(mm);
374 const unsigned int __tlb_flag = __cpu_tlb_flags;
375
Will Deaconf0915782013-02-11 13:47:48 +0000376 if (possible_tlb_flags & (TLB_V4_U_FULL|TLB_V4_D_FULL|TLB_V4_I_FULL)) {
377 if (cpumask_test_cpu(smp_processor_id(), mm_cpumask(mm))) {
378 tlb_op(TLB_V4_U_FULL, "c8, c7, 0", zero);
379 tlb_op(TLB_V4_D_FULL, "c8, c6, 0", zero);
380 tlb_op(TLB_V4_I_FULL, "c8, c5, 0", zero);
381 }
382 }
383
384 tlb_op(TLB_V6_U_ASID, "c8, c7, 2", asid);
385 tlb_op(TLB_V6_D_ASID, "c8, c6, 2", asid);
386 tlb_op(TLB_V6_I_ASID, "c8, c5, 2", asid);
387}
388
389static inline void local_flush_tlb_mm(struct mm_struct *mm)
390{
391 const int asid = ASID(mm);
392 const unsigned int __tlb_flag = __cpu_tlb_flags;
393
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 if (tlb_flag(TLB_WB))
Will Deacon62cbbc42013-05-23 18:43:58 +0100395 dsb(nshst);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396
Will Deaconf0915782013-02-11 13:47:48 +0000397 __local_flush_tlb_mm(mm);
398 tlb_op(TLB_V7_UIS_ASID, "c8, c7, 2", asid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
Will Deaconf0915782013-02-11 13:47:48 +0000400 if (tlb_flag(TLB_BARRIER))
Will Deacon62cbbc42013-05-23 18:43:58 +0100401 dsb(nsh);
Will Deaconf0915782013-02-11 13:47:48 +0000402}
403
404static inline void __flush_tlb_mm(struct mm_struct *mm)
405{
406 const unsigned int __tlb_flag = __cpu_tlb_flags;
407
408 if (tlb_flag(TLB_WB))
Will Deacon62cbbc42013-05-23 18:43:58 +0100409 dsb(ishst);
Will Deaconf0915782013-02-11 13:47:48 +0000410
411 __local_flush_tlb_mm(mm);
Will Deaconcdf357f2010-08-05 11:20:51 +0100412#ifdef CONFIG_ARM_ERRATA_720789
Will Deaconf0915782013-02-11 13:47:48 +0000413 tlb_op(TLB_V7_UIS_ASID, "c8, c3, 0", 0);
Will Deaconcdf357f2010-08-05 11:20:51 +0100414#else
Will Deaconf0915782013-02-11 13:47:48 +0000415 tlb_op(TLB_V7_UIS_ASID, "c8, c3, 2", ASID(mm));
Will Deaconcdf357f2010-08-05 11:20:51 +0100416#endif
Catalin Marinase6a5d662007-02-05 14:47:51 +0100417
Russell King43488102011-07-05 09:01:13 +0100418 if (tlb_flag(TLB_BARRIER))
Will Deacon62cbbc42013-05-23 18:43:58 +0100419 dsb(ish);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420}
421
422static inline void
Will Deaconf0915782013-02-11 13:47:48 +0000423__local_flush_tlb_page(struct vm_area_struct *vma, unsigned long uaddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424{
425 const int zero = 0;
426 const unsigned int __tlb_flag = __cpu_tlb_flags;
427
428 uaddr = (uaddr & PAGE_MASK) | ASID(vma->vm_mm);
429
Will Deacon4cc3daaf2013-01-14 20:48:55 +0000430 if (possible_tlb_flags & (TLB_V4_U_PAGE|TLB_V4_D_PAGE|TLB_V4_I_PAGE|TLB_V4_I_FULL) &&
Russell King87067a92012-02-04 10:55:38 +0000431 cpumask_test_cpu(smp_processor_id(), mm_cpumask(vma->vm_mm))) {
Russell King87067a92012-02-04 10:55:38 +0000432 tlb_op(TLB_V4_U_PAGE, "c8, c7, 1", uaddr);
433 tlb_op(TLB_V4_D_PAGE, "c8, c6, 1", uaddr);
434 tlb_op(TLB_V4_I_PAGE, "c8, c5, 1", uaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 if (!tlb_flag(TLB_V4_I_PAGE) && tlb_flag(TLB_V4_I_FULL))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100436 asm("mcr p15, 0, %0, c8, c5, 0" : : "r" (zero) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 }
438
Russell King87067a92012-02-04 10:55:38 +0000439 tlb_op(TLB_V6_U_PAGE, "c8, c7, 1", uaddr);
440 tlb_op(TLB_V6_D_PAGE, "c8, c6, 1", uaddr);
441 tlb_op(TLB_V6_I_PAGE, "c8, c5, 1", uaddr);
Will Deaconf0915782013-02-11 13:47:48 +0000442}
443
444static inline void
445local_flush_tlb_page(struct vm_area_struct *vma, unsigned long uaddr)
446{
447 const unsigned int __tlb_flag = __cpu_tlb_flags;
448
449 uaddr = (uaddr & PAGE_MASK) | ASID(vma->vm_mm);
450
451 if (tlb_flag(TLB_WB))
Will Deacon62cbbc42013-05-23 18:43:58 +0100452 dsb(nshst);
Will Deaconf0915782013-02-11 13:47:48 +0000453
454 __local_flush_tlb_page(vma, uaddr);
455 tlb_op(TLB_V7_UIS_PAGE, "c8, c7, 1", uaddr);
456
457 if (tlb_flag(TLB_BARRIER))
Will Deacon62cbbc42013-05-23 18:43:58 +0100458 dsb(nsh);
Will Deaconf0915782013-02-11 13:47:48 +0000459}
460
461static inline void
462__flush_tlb_page(struct vm_area_struct *vma, unsigned long uaddr)
463{
464 const unsigned int __tlb_flag = __cpu_tlb_flags;
465
466 uaddr = (uaddr & PAGE_MASK) | ASID(vma->vm_mm);
467
468 if (tlb_flag(TLB_WB))
Will Deacon62cbbc42013-05-23 18:43:58 +0100469 dsb(ishst);
Will Deaconf0915782013-02-11 13:47:48 +0000470
471 __local_flush_tlb_page(vma, uaddr);
Will Deaconcdf357f2010-08-05 11:20:51 +0100472#ifdef CONFIG_ARM_ERRATA_720789
Russell King87067a92012-02-04 10:55:38 +0000473 tlb_op(TLB_V7_UIS_PAGE, "c8, c3, 3", uaddr & PAGE_MASK);
Will Deaconcdf357f2010-08-05 11:20:51 +0100474#else
Russell King87067a92012-02-04 10:55:38 +0000475 tlb_op(TLB_V7_UIS_PAGE, "c8, c3, 1", uaddr);
Will Deaconcdf357f2010-08-05 11:20:51 +0100476#endif
Catalin Marinase6a5d662007-02-05 14:47:51 +0100477
Russell King43488102011-07-05 09:01:13 +0100478 if (tlb_flag(TLB_BARRIER))
Will Deacon62cbbc42013-05-23 18:43:58 +0100479 dsb(ish);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480}
481
Will Deaconf0915782013-02-11 13:47:48 +0000482static inline void __local_flush_tlb_kernel_page(unsigned long kaddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483{
484 const int zero = 0;
485 const unsigned int __tlb_flag = __cpu_tlb_flags;
486
Russell King87067a92012-02-04 10:55:38 +0000487 tlb_op(TLB_V4_U_PAGE, "c8, c7, 1", kaddr);
488 tlb_op(TLB_V4_D_PAGE, "c8, c6, 1", kaddr);
489 tlb_op(TLB_V4_I_PAGE, "c8, c5, 1", kaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 if (!tlb_flag(TLB_V4_I_PAGE) && tlb_flag(TLB_V4_I_FULL))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100491 asm("mcr p15, 0, %0, c8, c5, 0" : : "r" (zero) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
Russell King87067a92012-02-04 10:55:38 +0000493 tlb_op(TLB_V6_U_PAGE, "c8, c7, 1", kaddr);
494 tlb_op(TLB_V6_D_PAGE, "c8, c6, 1", kaddr);
495 tlb_op(TLB_V6_I_PAGE, "c8, c5, 1", kaddr);
Will Deaconf0915782013-02-11 13:47:48 +0000496}
497
498static inline void local_flush_tlb_kernel_page(unsigned long kaddr)
499{
500 const unsigned int __tlb_flag = __cpu_tlb_flags;
501
502 kaddr &= PAGE_MASK;
503
504 if (tlb_flag(TLB_WB))
Will Deacon62cbbc42013-05-23 18:43:58 +0100505 dsb(nshst);
Will Deaconf0915782013-02-11 13:47:48 +0000506
507 __local_flush_tlb_kernel_page(kaddr);
508 tlb_op(TLB_V7_UIS_PAGE, "c8, c7, 1", kaddr);
509
510 if (tlb_flag(TLB_BARRIER)) {
Will Deacon62cbbc42013-05-23 18:43:58 +0100511 dsb(nsh);
Will Deaconf0915782013-02-11 13:47:48 +0000512 isb();
513 }
514}
515
516static inline void __flush_tlb_kernel_page(unsigned long kaddr)
517{
518 const unsigned int __tlb_flag = __cpu_tlb_flags;
519
520 kaddr &= PAGE_MASK;
521
522 if (tlb_flag(TLB_WB))
Will Deacon62cbbc42013-05-23 18:43:58 +0100523 dsb(ishst);
Will Deaconf0915782013-02-11 13:47:48 +0000524
525 __local_flush_tlb_kernel_page(kaddr);
Russell King87067a92012-02-04 10:55:38 +0000526 tlb_op(TLB_V7_UIS_PAGE, "c8, c3, 1", kaddr);
Catalin Marinas6a0e2432006-03-07 14:42:27 +0000527
Russell King43488102011-07-05 09:01:13 +0100528 if (tlb_flag(TLB_BARRIER)) {
Will Deacon62cbbc42013-05-23 18:43:58 +0100529 dsb(ish);
Catalin Marinasb8349b52010-05-07 18:03:05 +0100530 isb();
531 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532}
533
Will Deacon587b9b62013-05-23 18:29:18 +0100534/*
535 * Branch predictor maintenance is paired with full TLB invalidation, so
536 * there is no need for any barriers here.
537 */
Will Deacon2c813982013-02-18 22:07:47 +0000538static inline void __local_flush_bp_all(void)
539{
540 const int zero = 0;
541 const unsigned int __tlb_flag = __cpu_tlb_flags;
542
543 if (tlb_flag(TLB_V6_BP))
544 asm("mcr p15, 0, %0, c7, c5, 6" : : "r" (zero));
545}
546
Will Deacon862c5882013-02-28 17:48:11 +0100547static inline void local_flush_bp_all(void)
548{
549 const int zero = 0;
550 const unsigned int __tlb_flag = __cpu_tlb_flags;
551
Will Deacon2c813982013-02-18 22:07:47 +0000552 __local_flush_bp_all();
553 if (tlb_flag(TLB_V7_UIS_BP))
554 asm("mcr p15, 0, %0, c7, c5, 6" : : "r" (zero));
555}
556
557static inline void __flush_bp_all(void)
558{
559 const int zero = 0;
560 const unsigned int __tlb_flag = __cpu_tlb_flags;
561
562 __local_flush_bp_all();
Will Deacon862c5882013-02-28 17:48:11 +0100563 if (tlb_flag(TLB_V7_UIS_BP))
564 asm("mcr p15, 0, %0, c7, c1, 6" : : "r" (zero));
Will Deacon862c5882013-02-28 17:48:11 +0100565}
566
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567/*
568 * flush_pmd_entry
569 *
570 * Flush a PMD entry (word aligned, or double-word aligned) to
571 * RAM if the TLB for the CPU we are running on requires this.
572 * This is typically used when we are creating PMD entries.
573 *
574 * clean_pmd_entry
575 *
576 * Clean (but don't drain the write buffer) if the CPU requires
577 * these operations. This is typically used when we are removing
578 * PMD entries.
579 */
Catalin Marinas442e70c2011-09-05 17:51:56 +0100580static inline void flush_pmd_entry(void *pmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 const unsigned int __tlb_flag = __cpu_tlb_flags;
583
Russell King87067a92012-02-04 10:55:38 +0000584 tlb_op(TLB_DCLEAN, "c7, c10, 1 @ flush_pmd", pmd);
585 tlb_l2_op(TLB_L2CLEAN_FR, "c15, c9, 1 @ L2 flush_pmd", pmd);
Lennert Buytenhek99c6dc12008-06-22 22:45:04 +0200586
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 if (tlb_flag(TLB_WB))
Will Deacon62cbbc42013-05-23 18:43:58 +0100588 dsb(ishst);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589}
590
Catalin Marinas442e70c2011-09-05 17:51:56 +0100591static inline void clean_pmd_entry(void *pmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592{
593 const unsigned int __tlb_flag = __cpu_tlb_flags;
594
Russell King87067a92012-02-04 10:55:38 +0000595 tlb_op(TLB_DCLEAN, "c7, c10, 1 @ flush_pmd", pmd);
596 tlb_l2_op(TLB_L2CLEAN_FR, "c15, c9, 1 @ L2 flush_pmd", pmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597}
598
Russell King87067a92012-02-04 10:55:38 +0000599#undef tlb_op
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600#undef tlb_flag
601#undef always_tlb_flags
602#undef possible_tlb_flags
603
604/*
605 * Convert calls to our calling convention.
606 */
Russell King603fff52005-06-28 13:40:39 +0100607#define local_flush_tlb_range(vma,start,end) __cpu_flush_user_tlb_range(start,end,vma)
608#define local_flush_tlb_kernel_range(s,e) __cpu_flush_kern_tlb_range(s,e)
609
610#ifndef CONFIG_SMP
611#define flush_tlb_all local_flush_tlb_all
612#define flush_tlb_mm local_flush_tlb_mm
613#define flush_tlb_page local_flush_tlb_page
614#define flush_tlb_kernel_page local_flush_tlb_kernel_page
615#define flush_tlb_range local_flush_tlb_range
616#define flush_tlb_kernel_range local_flush_tlb_kernel_range
Will Deacon862c5882013-02-28 17:48:11 +0100617#define flush_bp_all local_flush_bp_all
Russell King603fff52005-06-28 13:40:39 +0100618#else
619extern void flush_tlb_all(void);
620extern void flush_tlb_mm(struct mm_struct *mm);
621extern void flush_tlb_page(struct vm_area_struct *vma, unsigned long uaddr);
622extern void flush_tlb_kernel_page(unsigned long kaddr);
623extern void flush_tlb_range(struct vm_area_struct *vma, unsigned long start, unsigned long end);
624extern void flush_tlb_kernel_range(unsigned long start, unsigned long end);
Will Deacon862c5882013-02-28 17:48:11 +0100625extern void flush_bp_all(void);
Russell King603fff52005-06-28 13:40:39 +0100626#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627
628/*
Catalin Marinasc0177802010-09-13 15:57:36 +0100629 * If PG_dcache_clean is not set for the page, we need to ensure that any
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 * cache entries for the kernels virtual memory range are written
Catalin Marinas60121912010-09-13 15:58:06 +0100631 * back to the page. On ARMv6 and later, the cache coherency is handled via
632 * the set_pte_at() function.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 */
Catalin Marinas60121912010-09-13 15:58:06 +0100634#if __LINUX_ARM_ARCH__ < 6
Russell King4b3073e2009-12-18 16:40:18 +0000635extern void update_mmu_cache(struct vm_area_struct *vma, unsigned long addr,
636 pte_t *ptep);
Catalin Marinas60121912010-09-13 15:58:06 +0100637#else
638static inline void update_mmu_cache(struct vm_area_struct *vma,
639 unsigned long addr, pte_t *ptep)
640{
641}
642#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643
Catalin Marinas8d962502012-07-25 14:39:26 +0100644#define update_mmu_cache_pmd(vma, address, pmd) do { } while (0)
645
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646#endif
647
Will Deacon5c709e62012-02-28 12:56:06 +0000648#elif defined(CONFIG_SMP) /* !CONFIG_MMU */
649
650#ifndef __ASSEMBLY__
Will Deacon5c709e62012-02-28 12:56:06 +0000651static inline void local_flush_tlb_all(void) { }
652static inline void local_flush_tlb_mm(struct mm_struct *mm) { }
653static inline void local_flush_tlb_page(struct vm_area_struct *vma, unsigned long uaddr) { }
654static inline void local_flush_tlb_kernel_page(unsigned long kaddr) { }
655static inline void local_flush_tlb_range(struct vm_area_struct *vma, unsigned long start, unsigned long end) { }
656static inline void local_flush_tlb_kernel_range(unsigned long start, unsigned long end) { }
Jonathan Austin8d655d82013-04-24 11:56:09 +0100657static inline void local_flush_bp_all(void) { }
Will Deacon5c709e62012-02-28 12:56:06 +0000658
659extern void flush_tlb_all(void);
660extern void flush_tlb_mm(struct mm_struct *mm);
661extern void flush_tlb_page(struct vm_area_struct *vma, unsigned long uaddr);
662extern void flush_tlb_kernel_page(unsigned long kaddr);
663extern void flush_tlb_range(struct vm_area_struct *vma, unsigned long start, unsigned long end);
664extern void flush_tlb_kernel_range(unsigned long start, unsigned long end);
Jonathan Austin8d655d82013-04-24 11:56:09 +0100665extern void flush_bp_all(void);
Will Deacon5c709e62012-02-28 12:56:06 +0000666#endif /* __ASSEMBLY__ */
667
668#endif
Hyok S. Choi01579032006-02-24 21:41:25 +0000669
Rob Herring92871b92013-10-09 17:26:44 +0100670#ifndef __ASSEMBLY__
671#ifdef CONFIG_ARM_ERRATA_798181
672extern void erratum_a15_798181_init(void);
673#else
674static inline void erratum_a15_798181_init(void) {}
675#endif
676extern bool (*erratum_a15_798181_handler)(void);
677
678static inline bool erratum_a15_798181(void)
679{
680 if (unlikely(IS_ENABLED(CONFIG_ARM_ERRATA_798181) &&
681 erratum_a15_798181_handler))
682 return erratum_a15_798181_handler();
683 return false;
684}
685#endif
686
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687#endif