blob: ffedd2494eabfa9f5b47db0b469ac4f60fe5f7e9 [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
Hyok S. Choi01579032006-02-24 21:41:25 +000013
14#ifndef CONFIG_MMU
15
16#define tlb_flush(tlb) ((void) tlb)
17
Russell Kingfb1c7762006-02-24 21:44:56 +000018#else /* CONFIG_MMU */
Hyok S. Choi01579032006-02-24 21:41:25 +000019
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <asm/glue.h>
21
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)
29
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)
37
38#define TLB_V6_U_ASID (1 << 16)
39#define TLB_V6_D_ASID (1 << 17)
40#define TLB_V6_I_ASID (1 << 18)
41
Paulius Zaleckasbba7d0b2009-03-25 10:58:47 +020042#define TLB_BTB (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)
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 * v6wbi - ARMv6 with write buffer with I TLB flush entry instruction
Paul Walmsley61db7fb2008-08-12 00:04:15 +010058 * v7wbi - identical to v6wbi
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 */
60#undef _TLB
61#undef MULTI_TLB
62
63#define v3_tlb_flags (TLB_V3_FULL | TLB_V3_PAGE)
64
65#ifdef CONFIG_CPU_TLB_V3
66# define v3_possible_flags v3_tlb_flags
67# define v3_always_flags v3_tlb_flags
68# ifdef _TLB
69# define MULTI_TLB 1
70# else
71# define _TLB v3
72# endif
73#else
74# define v3_possible_flags 0
75# define v3_always_flags (-1UL)
76#endif
77
78#define v4_tlb_flags (TLB_V4_U_FULL | TLB_V4_U_PAGE)
79
80#ifdef CONFIG_CPU_TLB_V4WT
81# define v4_possible_flags v4_tlb_flags
82# define v4_always_flags v4_tlb_flags
83# ifdef _TLB
84# define MULTI_TLB 1
85# else
86# define _TLB v4
87# endif
88#else
89# define v4_possible_flags 0
90# define v4_always_flags (-1UL)
91#endif
92
93#define v4wbi_tlb_flags (TLB_WB | TLB_DCLEAN | \
94 TLB_V4_I_FULL | TLB_V4_D_FULL | \
95 TLB_V4_I_PAGE | TLB_V4_D_PAGE)
96
97#ifdef CONFIG_CPU_TLB_V4WBI
98# define v4wbi_possible_flags v4wbi_tlb_flags
99# define v4wbi_always_flags v4wbi_tlb_flags
100# ifdef _TLB
101# define MULTI_TLB 1
102# else
103# define _TLB v4wbi
104# endif
105#else
106# define v4wbi_possible_flags 0
107# define v4wbi_always_flags (-1UL)
108#endif
109
Lennert Buytenhek99c6dc12008-06-22 22:45:04 +0200110#define fr_tlb_flags (TLB_WB | TLB_DCLEAN | TLB_L2CLEAN_FR | \
111 TLB_V4_I_FULL | TLB_V4_D_FULL | \
112 TLB_V4_I_PAGE | TLB_V4_D_PAGE)
113
114#ifdef CONFIG_CPU_TLB_FEROCEON
115# define fr_possible_flags fr_tlb_flags
116# define fr_always_flags fr_tlb_flags
117# ifdef _TLB
118# define MULTI_TLB 1
119# else
120# define _TLB v4wbi
121# endif
122#else
123# define fr_possible_flags 0
124# define fr_always_flags (-1UL)
125#endif
126
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127#define v4wb_tlb_flags (TLB_WB | TLB_DCLEAN | \
128 TLB_V4_I_FULL | TLB_V4_D_FULL | \
129 TLB_V4_D_PAGE)
130
131#ifdef CONFIG_CPU_TLB_V4WB
132# define v4wb_possible_flags v4wb_tlb_flags
133# define v4wb_always_flags v4wb_tlb_flags
134# ifdef _TLB
135# define MULTI_TLB 1
136# else
137# define _TLB v4wb
138# endif
139#else
140# define v4wb_possible_flags 0
141# define v4wb_always_flags (-1UL)
142#endif
143
Paulius Zaleckasbba7d0b2009-03-25 10:58:47 +0200144#define v6wbi_tlb_flags (TLB_WB | TLB_DCLEAN | TLB_BTB | \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 TLB_V6_I_FULL | TLB_V6_D_FULL | \
146 TLB_V6_I_PAGE | TLB_V6_D_PAGE | \
147 TLB_V6_I_ASID | TLB_V6_D_ASID)
148
149#ifdef CONFIG_CPU_TLB_V6
150# define v6wbi_possible_flags v6wbi_tlb_flags
151# define v6wbi_always_flags v6wbi_tlb_flags
152# ifdef _TLB
153# define MULTI_TLB 1
154# else
155# define _TLB v6wbi
156# endif
157#else
158# define v6wbi_possible_flags 0
159# define v6wbi_always_flags (-1UL)
160#endif
161
Catalin Marinas2ccdd1e2007-05-18 11:25:31 +0100162#ifdef CONFIG_CPU_TLB_V7
163# define v7wbi_possible_flags v6wbi_tlb_flags
164# define v7wbi_always_flags v6wbi_tlb_flags
165# ifdef _TLB
166# define MULTI_TLB 1
167# else
168# define _TLB v7wbi
169# endif
170#else
171# define v7wbi_possible_flags 0
172# define v7wbi_always_flags (-1UL)
173#endif
174
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175#ifndef _TLB
176#error Unknown TLB model
177#endif
178
179#ifndef __ASSEMBLY__
180
Alexey Dobriyane8edc6e2007-05-21 01:22:52 +0400181#include <linux/sched.h>
182
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183struct cpu_tlb_fns {
184 void (*flush_user_range)(unsigned long, unsigned long, struct vm_area_struct *);
185 void (*flush_kern_range)(unsigned long, unsigned long);
186 unsigned long tlb_flags;
187};
188
189/*
190 * Select the calling method
191 */
192#ifdef MULTI_TLB
193
194#define __cpu_flush_user_tlb_range cpu_tlb.flush_user_range
195#define __cpu_flush_kern_tlb_range cpu_tlb.flush_kern_range
196
197#else
198
199#define __cpu_flush_user_tlb_range __glue(_TLB,_flush_user_tlb_range)
200#define __cpu_flush_kern_tlb_range __glue(_TLB,_flush_kern_tlb_range)
201
202extern void __cpu_flush_user_tlb_range(unsigned long, unsigned long, struct vm_area_struct *);
203extern void __cpu_flush_kern_tlb_range(unsigned long, unsigned long);
204
205#endif
206
207extern struct cpu_tlb_fns cpu_tlb;
208
209#define __cpu_tlb_flags cpu_tlb.tlb_flags
210
211/*
212 * TLB Management
213 * ==============
214 *
215 * The arch/arm/mm/tlb-*.S files implement these methods.
216 *
217 * The TLB specific code is expected to perform whatever tests it
218 * needs to determine if it should invalidate the TLB for each
219 * call. Start addresses are inclusive and end addresses are
220 * exclusive; it is safe to round these addresses down.
221 *
222 * flush_tlb_all()
223 *
224 * Invalidate the entire TLB.
225 *
226 * flush_tlb_mm(mm)
227 *
228 * Invalidate all TLB entries in a particular address
229 * space.
230 * - mm - mm_struct describing address space
231 *
232 * flush_tlb_range(mm,start,end)
233 *
234 * Invalidate a range of TLB entries in the specified
235 * address space.
236 * - mm - mm_struct describing address space
237 * - start - start address (may not be aligned)
238 * - end - end address (exclusive, may not be aligned)
239 *
240 * flush_tlb_page(vaddr,vma)
241 *
242 * Invalidate the specified page in the specified address range.
243 * - vaddr - virtual address (may not be aligned)
244 * - vma - vma_struct describing address range
245 *
246 * flush_kern_tlb_page(kaddr)
247 *
248 * Invalidate the TLB entry for the specified page. The address
249 * will be in the kernels virtual memory space. Current uses
250 * only require the D-TLB to be invalidated.
251 * - kaddr - Kernel virtual memory address
252 */
253
254/*
255 * We optimise the code below by:
256 * - building a set of TLB flags that might be set in __cpu_tlb_flags
257 * - building a set of TLB flags that will always be set in __cpu_tlb_flags
258 * - if we're going to need __cpu_tlb_flags, access it once and only once
259 *
260 * This allows us to build optimal assembly for the single-CPU type case,
261 * and as close to optimal given the compiler constrants for multi-CPU
262 * case. We could do better for the multi-CPU case if the compiler
263 * implemented the "%?" method, but this has been discontinued due to too
264 * many people getting it wrong.
265 */
266#define possible_tlb_flags (v3_possible_flags | \
267 v4_possible_flags | \
268 v4wbi_possible_flags | \
Lennert Buytenhek99c6dc12008-06-22 22:45:04 +0200269 fr_possible_flags | \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 v4wb_possible_flags | \
Paul Walmsley61db7fb2008-08-12 00:04:15 +0100271 v6wbi_possible_flags | \
272 v7wbi_possible_flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
274#define always_tlb_flags (v3_always_flags & \
275 v4_always_flags & \
276 v4wbi_always_flags & \
Lennert Buytenhek99c6dc12008-06-22 22:45:04 +0200277 fr_always_flags & \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 v4wb_always_flags & \
Paul Walmsley61db7fb2008-08-12 00:04:15 +0100279 v6wbi_always_flags & \
280 v7wbi_always_flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281
282#define tlb_flag(f) ((always_tlb_flags & (f)) || (__tlb_flag & possible_tlb_flags & (f)))
283
Russell King603fff52005-06-28 13:40:39 +0100284static inline void local_flush_tlb_all(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285{
286 const int zero = 0;
287 const unsigned int __tlb_flag = __cpu_tlb_flags;
288
289 if (tlb_flag(TLB_WB))
Catalin Marinase6a5d662007-02-05 14:47:51 +0100290 dsb();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291
292 if (tlb_flag(TLB_V3_FULL))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100293 asm("mcr p15, 0, %0, c6, c0, 0" : : "r" (zero) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 if (tlb_flag(TLB_V4_U_FULL | TLB_V6_U_FULL))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100295 asm("mcr p15, 0, %0, c8, c7, 0" : : "r" (zero) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 if (tlb_flag(TLB_V4_D_FULL | TLB_V6_D_FULL))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100297 asm("mcr p15, 0, %0, c8, c6, 0" : : "r" (zero) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 if (tlb_flag(TLB_V4_I_FULL | TLB_V6_I_FULL))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100299 asm("mcr p15, 0, %0, c8, c5, 0" : : "r" (zero) : "cc");
Catalin Marinase6a5d662007-02-05 14:47:51 +0100300
Paulius Zaleckasbba7d0b2009-03-25 10:58:47 +0200301 if (tlb_flag(TLB_BTB)) {
Catalin Marinase6a5d662007-02-05 14:47:51 +0100302 /* flush the branch target cache */
303 asm("mcr p15, 0, %0, c7, c5, 6" : : "r" (zero) : "cc");
304 dsb();
305 isb();
306 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307}
308
Russell King603fff52005-06-28 13:40:39 +0100309static inline void local_flush_tlb_mm(struct mm_struct *mm)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310{
311 const int zero = 0;
312 const int asid = ASID(mm);
313 const unsigned int __tlb_flag = __cpu_tlb_flags;
314
315 if (tlb_flag(TLB_WB))
Catalin Marinase6a5d662007-02-05 14:47:51 +0100316 dsb();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317
318 if (cpu_isset(smp_processor_id(), mm->cpu_vm_mask)) {
319 if (tlb_flag(TLB_V3_FULL))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100320 asm("mcr p15, 0, %0, c6, c0, 0" : : "r" (zero) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 if (tlb_flag(TLB_V4_U_FULL))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100322 asm("mcr p15, 0, %0, c8, c7, 0" : : "r" (zero) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 if (tlb_flag(TLB_V4_D_FULL))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100324 asm("mcr p15, 0, %0, c8, c6, 0" : : "r" (zero) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 if (tlb_flag(TLB_V4_I_FULL))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100326 asm("mcr p15, 0, %0, c8, c5, 0" : : "r" (zero) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 }
328
329 if (tlb_flag(TLB_V6_U_ASID))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100330 asm("mcr p15, 0, %0, c8, c7, 2" : : "r" (asid) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 if (tlb_flag(TLB_V6_D_ASID))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100332 asm("mcr p15, 0, %0, c8, c6, 2" : : "r" (asid) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 if (tlb_flag(TLB_V6_I_ASID))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100334 asm("mcr p15, 0, %0, c8, c5, 2" : : "r" (asid) : "cc");
Catalin Marinase6a5d662007-02-05 14:47:51 +0100335
Paulius Zaleckasbba7d0b2009-03-25 10:58:47 +0200336 if (tlb_flag(TLB_BTB)) {
Catalin Marinase6a5d662007-02-05 14:47:51 +0100337 /* flush the branch target cache */
338 asm("mcr p15, 0, %0, c7, c5, 6" : : "r" (zero) : "cc");
339 dsb();
340 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341}
342
343static inline void
Russell King603fff52005-06-28 13:40:39 +0100344local_flush_tlb_page(struct vm_area_struct *vma, unsigned long uaddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345{
346 const int zero = 0;
347 const unsigned int __tlb_flag = __cpu_tlb_flags;
348
349 uaddr = (uaddr & PAGE_MASK) | ASID(vma->vm_mm);
350
351 if (tlb_flag(TLB_WB))
Catalin Marinase6a5d662007-02-05 14:47:51 +0100352 dsb();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353
354 if (cpu_isset(smp_processor_id(), vma->vm_mm->cpu_vm_mask)) {
355 if (tlb_flag(TLB_V3_PAGE))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100356 asm("mcr p15, 0, %0, c6, c0, 0" : : "r" (uaddr) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 if (tlb_flag(TLB_V4_U_PAGE))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100358 asm("mcr p15, 0, %0, c8, c7, 1" : : "r" (uaddr) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 if (tlb_flag(TLB_V4_D_PAGE))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100360 asm("mcr p15, 0, %0, c8, c6, 1" : : "r" (uaddr) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 if (tlb_flag(TLB_V4_I_PAGE))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100362 asm("mcr p15, 0, %0, c8, c5, 1" : : "r" (uaddr) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 if (!tlb_flag(TLB_V4_I_PAGE) && tlb_flag(TLB_V4_I_FULL))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100364 asm("mcr p15, 0, %0, c8, c5, 0" : : "r" (zero) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 }
366
367 if (tlb_flag(TLB_V6_U_PAGE))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100368 asm("mcr p15, 0, %0, c8, c7, 1" : : "r" (uaddr) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 if (tlb_flag(TLB_V6_D_PAGE))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100370 asm("mcr p15, 0, %0, c8, c6, 1" : : "r" (uaddr) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 if (tlb_flag(TLB_V6_I_PAGE))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100372 asm("mcr p15, 0, %0, c8, c5, 1" : : "r" (uaddr) : "cc");
Catalin Marinase6a5d662007-02-05 14:47:51 +0100373
Paulius Zaleckasbba7d0b2009-03-25 10:58:47 +0200374 if (tlb_flag(TLB_BTB)) {
Catalin Marinase6a5d662007-02-05 14:47:51 +0100375 /* flush the branch target cache */
376 asm("mcr p15, 0, %0, c7, c5, 6" : : "r" (zero) : "cc");
377 dsb();
378 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379}
380
Russell King603fff52005-06-28 13:40:39 +0100381static inline void local_flush_tlb_kernel_page(unsigned long kaddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382{
383 const int zero = 0;
384 const unsigned int __tlb_flag = __cpu_tlb_flags;
385
386 kaddr &= PAGE_MASK;
387
388 if (tlb_flag(TLB_WB))
Catalin Marinase6a5d662007-02-05 14:47:51 +0100389 dsb();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
391 if (tlb_flag(TLB_V3_PAGE))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100392 asm("mcr p15, 0, %0, c6, c0, 0" : : "r" (kaddr) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 if (tlb_flag(TLB_V4_U_PAGE))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100394 asm("mcr p15, 0, %0, c8, c7, 1" : : "r" (kaddr) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 if (tlb_flag(TLB_V4_D_PAGE))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100396 asm("mcr p15, 0, %0, c8, c6, 1" : : "r" (kaddr) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 if (tlb_flag(TLB_V4_I_PAGE))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100398 asm("mcr p15, 0, %0, c8, c5, 1" : : "r" (kaddr) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 if (!tlb_flag(TLB_V4_I_PAGE) && tlb_flag(TLB_V4_I_FULL))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100400 asm("mcr p15, 0, %0, c8, c5, 0" : : "r" (zero) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401
402 if (tlb_flag(TLB_V6_U_PAGE))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100403 asm("mcr p15, 0, %0, c8, c7, 1" : : "r" (kaddr) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 if (tlb_flag(TLB_V6_D_PAGE))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100405 asm("mcr p15, 0, %0, c8, c6, 1" : : "r" (kaddr) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 if (tlb_flag(TLB_V6_I_PAGE))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100407 asm("mcr p15, 0, %0, c8, c5, 1" : : "r" (kaddr) : "cc");
Catalin Marinas6a0e2432006-03-07 14:42:27 +0000408
Paulius Zaleckasbba7d0b2009-03-25 10:58:47 +0200409 if (tlb_flag(TLB_BTB)) {
Catalin Marinase6a5d662007-02-05 14:47:51 +0100410 /* flush the branch target cache */
411 asm("mcr p15, 0, %0, c7, c5, 6" : : "r" (zero) : "cc");
412 dsb();
413 isb();
414 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415}
416
417/*
418 * flush_pmd_entry
419 *
420 * Flush a PMD entry (word aligned, or double-word aligned) to
421 * RAM if the TLB for the CPU we are running on requires this.
422 * This is typically used when we are creating PMD entries.
423 *
424 * clean_pmd_entry
425 *
426 * Clean (but don't drain the write buffer) if the CPU requires
427 * these operations. This is typically used when we are removing
428 * PMD entries.
429 */
430static inline void flush_pmd_entry(pmd_t *pmd)
431{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 const unsigned int __tlb_flag = __cpu_tlb_flags;
433
434 if (tlb_flag(TLB_DCLEAN))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100435 asm("mcr p15, 0, %0, c7, c10, 1 @ flush_pmd"
436 : : "r" (pmd) : "cc");
Lennert Buytenhek99c6dc12008-06-22 22:45:04 +0200437
438 if (tlb_flag(TLB_L2CLEAN_FR))
439 asm("mcr p15, 1, %0, c15, c9, 1 @ L2 flush_pmd"
440 : : "r" (pmd) : "cc");
441
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 if (tlb_flag(TLB_WB))
Catalin Marinase6a5d662007-02-05 14:47:51 +0100443 dsb();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444}
445
446static inline void clean_pmd_entry(pmd_t *pmd)
447{
448 const unsigned int __tlb_flag = __cpu_tlb_flags;
449
450 if (tlb_flag(TLB_DCLEAN))
Daniel Jacobowitz6a39dd62006-08-30 15:02:08 +0100451 asm("mcr p15, 0, %0, c7, c10, 1 @ flush_pmd"
452 : : "r" (pmd) : "cc");
Lennert Buytenhek99c6dc12008-06-22 22:45:04 +0200453
454 if (tlb_flag(TLB_L2CLEAN_FR))
455 asm("mcr p15, 1, %0, c15, c9, 1 @ L2 flush_pmd"
456 : : "r" (pmd) : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457}
458
459#undef tlb_flag
460#undef always_tlb_flags
461#undef possible_tlb_flags
462
463/*
464 * Convert calls to our calling convention.
465 */
Russell King603fff52005-06-28 13:40:39 +0100466#define local_flush_tlb_range(vma,start,end) __cpu_flush_user_tlb_range(start,end,vma)
467#define local_flush_tlb_kernel_range(s,e) __cpu_flush_kern_tlb_range(s,e)
468
469#ifndef CONFIG_SMP
470#define flush_tlb_all local_flush_tlb_all
471#define flush_tlb_mm local_flush_tlb_mm
472#define flush_tlb_page local_flush_tlb_page
473#define flush_tlb_kernel_page local_flush_tlb_kernel_page
474#define flush_tlb_range local_flush_tlb_range
475#define flush_tlb_kernel_range local_flush_tlb_kernel_range
476#else
477extern void flush_tlb_all(void);
478extern void flush_tlb_mm(struct mm_struct *mm);
479extern void flush_tlb_page(struct vm_area_struct *vma, unsigned long uaddr);
480extern void flush_tlb_kernel_page(unsigned long kaddr);
481extern void flush_tlb_range(struct vm_area_struct *vma, unsigned long start, unsigned long end);
482extern void flush_tlb_kernel_range(unsigned long start, unsigned long end);
483#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
485/*
486 * if PG_dcache_dirty is set for the page, we need to ensure that any
487 * cache entries for the kernels virtual memory range are written
488 * back to the page.
489 */
490extern void update_mmu_cache(struct vm_area_struct *vma, unsigned long addr, pte_t pte);
491
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492#endif
493
Hyok S. Choi01579032006-02-24 21:41:25 +0000494#endif /* CONFIG_MMU */
495
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496#endif