blob: b0a8603400bedafd9ada30d20c9ec83a4f5fb6c0 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/include/asm-arm/cacheflush.h
3 *
4 * Copyright (C) 1999-2002 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_CACHEFLUSH_H
11#define _ASMARM_CACHEFLUSH_H
12
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/sched.h>
14#include <linux/mm.h>
15
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <asm/glue.h>
Russell Kingb8a9b662005-06-20 11:31:09 +010017#include <asm/shmparam.h>
18
19#define CACHE_COLOUR(vaddr) ((vaddr & (SHMLBA - 1)) >> PAGE_SHIFT)
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
21/*
22 * Cache Model
23 * ===========
24 */
25#undef _CACHE
26#undef MULTI_CACHE
27
Hyok S. Choib731c312006-09-26 17:37:50 +090028#if defined(CONFIG_CPU_ARM610) || defined(CONFIG_CPU_ARM710) || \
29 defined(CONFIG_CPU_ARM740T)
Linus Torvalds1da177e2005-04-16 15:20:36 -070030# ifdef _CACHE
31# define MULTI_CACHE 1
32# else
33# define _CACHE v3
34# endif
35#endif
36
Hyok S. Choi43f5f012006-09-26 17:38:05 +090037#if defined(CONFIG_CPU_ARM720T) || defined(CONFIG_CPU_ARM7TDMI) || \
38 defined(CONFIG_CPU_ARM9TDMI)
Linus Torvalds1da177e2005-04-16 15:20:36 -070039# ifdef _CACHE
40# define MULTI_CACHE 1
41# else
42# define _CACHE v4
43# endif
44#endif
45
46#if defined(CONFIG_CPU_ARM920T) || defined(CONFIG_CPU_ARM922T) || \
47 defined(CONFIG_CPU_ARM925T) || defined(CONFIG_CPU_ARM1020)
48# define MULTI_CACHE 1
49#endif
50
51#if defined(CONFIG_CPU_ARM926T)
52# ifdef _CACHE
53# define MULTI_CACHE 1
54# else
55# define _CACHE arm926
56# endif
57#endif
58
Hyok S. Choid60674e2006-09-26 17:38:18 +090059#if defined(CONFIG_CPU_ARM940T)
60# ifdef _CACHE
61# define MULTI_CACHE 1
62# else
63# define _CACHE arm940
64# endif
65#endif
66
Linus Torvalds1da177e2005-04-16 15:20:36 -070067#if defined(CONFIG_CPU_SA110) || defined(CONFIG_CPU_SA1100)
68# ifdef _CACHE
69# define MULTI_CACHE 1
70# else
71# define _CACHE v4wb
72# endif
73#endif
74
75#if defined(CONFIG_CPU_XSCALE)
76# ifdef _CACHE
77# define MULTI_CACHE 1
78# else
79# define _CACHE xscale
80# endif
81#endif
82
Lennert Buytenhek23bdf862006-03-28 21:00:40 +010083#if defined(CONFIG_CPU_XSC3)
84# ifdef _CACHE
85# define MULTI_CACHE 1
86# else
87# define _CACHE xsc3
88# endif
89#endif
90
Linus Torvalds1da177e2005-04-16 15:20:36 -070091#if defined(CONFIG_CPU_V6)
92//# ifdef _CACHE
93# define MULTI_CACHE 1
94//# else
95//# define _CACHE v6
96//# endif
97#endif
98
99#if !defined(_CACHE) && !defined(MULTI_CACHE)
100#error Unknown cache maintainence model
101#endif
102
103/*
104 * This flag is used to indicate that the page pointed to by a pte
105 * is dirty and requires cleaning before returning it to the user.
106 */
107#define PG_dcache_dirty PG_arch_1
108
109/*
110 * MM Cache Management
111 * ===================
112 *
113 * The arch/arm/mm/cache-*.S and arch/arm/mm/proc-*.S files
114 * implement these methods.
115 *
116 * Start addresses are inclusive and end addresses are exclusive;
117 * start addresses should be rounded down, end addresses up.
118 *
119 * See Documentation/cachetlb.txt for more information.
120 * Please note that the implementation of these, and the required
121 * effects are cache-type (VIVT/VIPT/PIPT) specific.
122 *
123 * flush_cache_kern_all()
124 *
125 * Unconditionally clean and invalidate the entire cache.
126 *
127 * flush_cache_user_mm(mm)
128 *
129 * Clean and invalidate all user space cache entries
130 * before a change of page tables.
131 *
132 * flush_cache_user_range(start, end, flags)
133 *
134 * Clean and invalidate a range of cache entries in the
135 * specified address space before a change of page tables.
136 * - start - user start address (inclusive, page aligned)
137 * - end - user end address (exclusive, page aligned)
138 * - flags - vma->vm_flags field
139 *
140 * coherent_kern_range(start, end)
141 *
142 * Ensure coherency between the Icache and the Dcache in the
143 * region described by start, end. If you have non-snooping
144 * Harvard caches, you need to implement this function.
145 * - start - virtual start address
146 * - end - virtual end address
147 *
148 * DMA Cache Coherency
149 * ===================
150 *
151 * dma_inv_range(start, end)
152 *
153 * Invalidate (discard) the specified virtual address range.
154 * May not write back any entries. If 'start' or 'end'
155 * are not cache line aligned, those lines must be written
156 * back.
157 * - start - virtual start address
158 * - end - virtual end address
159 *
160 * dma_clean_range(start, end)
161 *
162 * Clean (write back) the specified virtual address range.
163 * - start - virtual start address
164 * - end - virtual end address
165 *
166 * dma_flush_range(start, end)
167 *
168 * Clean and invalidate the specified virtual address range.
169 * - start - virtual start address
170 * - end - virtual end address
171 */
172
173struct cpu_cache_fns {
174 void (*flush_kern_all)(void);
175 void (*flush_user_all)(void);
176 void (*flush_user_range)(unsigned long, unsigned long, unsigned int);
177
178 void (*coherent_kern_range)(unsigned long, unsigned long);
179 void (*coherent_user_range)(unsigned long, unsigned long);
180 void (*flush_kern_dcache_page)(void *);
181
182 void (*dma_inv_range)(unsigned long, unsigned long);
183 void (*dma_clean_range)(unsigned long, unsigned long);
184 void (*dma_flush_range)(unsigned long, unsigned long);
185};
186
187/*
188 * Select the calling method
189 */
190#ifdef MULTI_CACHE
191
192extern struct cpu_cache_fns cpu_cache;
193
194#define __cpuc_flush_kern_all cpu_cache.flush_kern_all
195#define __cpuc_flush_user_all cpu_cache.flush_user_all
196#define __cpuc_flush_user_range cpu_cache.flush_user_range
197#define __cpuc_coherent_kern_range cpu_cache.coherent_kern_range
198#define __cpuc_coherent_user_range cpu_cache.coherent_user_range
199#define __cpuc_flush_dcache_page cpu_cache.flush_kern_dcache_page
200
201/*
202 * These are private to the dma-mapping API. Do not use directly.
203 * Their sole purpose is to ensure that data held in the cache
204 * is visible to DMA, or data written by DMA to system memory is
205 * visible to the CPU.
206 */
207#define dmac_inv_range cpu_cache.dma_inv_range
208#define dmac_clean_range cpu_cache.dma_clean_range
209#define dmac_flush_range cpu_cache.dma_flush_range
210
211#else
212
213#define __cpuc_flush_kern_all __glue(_CACHE,_flush_kern_cache_all)
214#define __cpuc_flush_user_all __glue(_CACHE,_flush_user_cache_all)
215#define __cpuc_flush_user_range __glue(_CACHE,_flush_user_cache_range)
216#define __cpuc_coherent_kern_range __glue(_CACHE,_coherent_kern_range)
217#define __cpuc_coherent_user_range __glue(_CACHE,_coherent_user_range)
218#define __cpuc_flush_dcache_page __glue(_CACHE,_flush_kern_dcache_page)
219
220extern void __cpuc_flush_kern_all(void);
221extern void __cpuc_flush_user_all(void);
222extern void __cpuc_flush_user_range(unsigned long, unsigned long, unsigned int);
223extern void __cpuc_coherent_kern_range(unsigned long, unsigned long);
224extern void __cpuc_coherent_user_range(unsigned long, unsigned long);
225extern void __cpuc_flush_dcache_page(void *);
226
227/*
228 * These are private to the dma-mapping API. Do not use directly.
229 * Their sole purpose is to ensure that data held in the cache
230 * is visible to DMA, or data written by DMA to system memory is
231 * visible to the CPU.
232 */
233#define dmac_inv_range __glue(_CACHE,_dma_inv_range)
234#define dmac_clean_range __glue(_CACHE,_dma_clean_range)
235#define dmac_flush_range __glue(_CACHE,_dma_flush_range)
236
237extern void dmac_inv_range(unsigned long, unsigned long);
238extern void dmac_clean_range(unsigned long, unsigned long);
239extern void dmac_flush_range(unsigned long, unsigned long);
240
241#endif
242
243/*
244 * flush_cache_vmap() is used when creating mappings (eg, via vmap,
245 * vmalloc, ioremap etc) in kernel space for pages. Since the
246 * direct-mappings of these pages may contain cached data, we need
247 * to do a full cache flush to ensure that writebacks don't corrupt
248 * data placed into these pages via the new mappings.
249 */
250#define flush_cache_vmap(start, end) flush_cache_all()
251#define flush_cache_vunmap(start, end) flush_cache_all()
252
253/*
254 * Copy user data from/to a page which is mapped into a different
255 * processes address space. Really, we want to allow our "user
256 * space" model to handle this.
257 */
258#define copy_to_user_page(vma, page, vaddr, dst, src, len) \
259 do { \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 memcpy(dst, src, len); \
George G. Davisa188ad22006-09-02 18:43:20 +0100261 flush_ptrace_access(vma, page, vaddr, dst, len, 1);\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 } while (0)
263
264#define copy_from_user_page(vma, page, vaddr, dst, src, len) \
265 do { \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 memcpy(dst, src, len); \
267 } while (0)
268
269/*
270 * Convert calls to our calling convention.
271 */
272#define flush_cache_all() __cpuc_flush_kern_all()
Russell Kingd7b6b352005-09-08 15:32:23 +0100273#ifndef CONFIG_CPU_CACHE_VIPT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274static inline void flush_cache_mm(struct mm_struct *mm)
275{
276 if (cpu_isset(smp_processor_id(), mm->cpu_vm_mask))
277 __cpuc_flush_user_all();
278}
279
280static inline void
281flush_cache_range(struct vm_area_struct *vma, unsigned long start, unsigned long end)
282{
283 if (cpu_isset(smp_processor_id(), vma->vm_mm->cpu_vm_mask))
284 __cpuc_flush_user_range(start & PAGE_MASK, PAGE_ALIGN(end),
285 vma->vm_flags);
286}
287
288static inline void
289flush_cache_page(struct vm_area_struct *vma, unsigned long user_addr, unsigned long pfn)
290{
291 if (cpu_isset(smp_processor_id(), vma->vm_mm->cpu_vm_mask)) {
292 unsigned long addr = user_addr & PAGE_MASK;
293 __cpuc_flush_user_range(addr, addr + PAGE_SIZE, vma->vm_flags);
294 }
295}
George G. Davisa188ad22006-09-02 18:43:20 +0100296
297static inline void
298flush_ptrace_access(struct vm_area_struct *vma, struct page *page,
299 unsigned long uaddr, void *kaddr,
300 unsigned long len, int write)
301{
302 if (cpu_isset(smp_processor_id(), vma->vm_mm->cpu_vm_mask)) {
303 unsigned long addr = (unsigned long)kaddr;
304 __cpuc_coherent_kern_range(addr, addr + len);
305 }
306}
Russell Kingd7b6b352005-09-08 15:32:23 +0100307#else
308extern void flush_cache_mm(struct mm_struct *mm);
309extern void flush_cache_range(struct vm_area_struct *vma, unsigned long start, unsigned long end);
310extern void flush_cache_page(struct vm_area_struct *vma, unsigned long user_addr, unsigned long pfn);
George G. Davisa188ad22006-09-02 18:43:20 +0100311extern void flush_ptrace_access(struct vm_area_struct *vma, struct page *page,
312 unsigned long uaddr, void *kaddr,
313 unsigned long len, int write);
Russell Kingd7b6b352005-09-08 15:32:23 +0100314#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
316/*
317 * flush_cache_user_range is used when we want to ensure that the
318 * Harvard caches are synchronised for the user space address range.
319 * This is used for the ARM private sys_cacheflush system call.
320 */
321#define flush_cache_user_range(vma,start,end) \
322 __cpuc_coherent_user_range((start) & PAGE_MASK, PAGE_ALIGN(end))
323
324/*
325 * Perform necessary cache operations to ensure that data previously
326 * stored within this range of addresses can be executed by the CPU.
327 */
328#define flush_icache_range(s,e) __cpuc_coherent_kern_range(s,e)
329
330/*
331 * Perform necessary cache operations to ensure that the TLB will
332 * see data written in the specified area.
333 */
334#define clean_dcache_area(start,size) cpu_dcache_clean_area(start, size)
335
336/*
337 * flush_dcache_page is used when the kernel has written to the page
338 * cache page at virtual address page->virtual.
339 *
340 * If this page isn't mapped (ie, page_mapping == NULL), or it might
341 * have userspace mappings, then we _must_ always clean + invalidate
342 * the dcache entries associated with the kernel mapping.
343 *
344 * Otherwise we can defer the operation, and clean the cache when we are
345 * about to change to user space. This is the same method as used on SPARC64.
346 * See update_mmu_cache for the user space part.
347 */
348extern void flush_dcache_page(struct page *);
349
350#define flush_dcache_mmap_lock(mapping) \
351 write_lock_irq(&(mapping)->tree_lock)
352#define flush_dcache_mmap_unlock(mapping) \
353 write_unlock_irq(&(mapping)->tree_lock)
354
355#define flush_icache_user_range(vma,page,addr,len) \
356 flush_dcache_page(page)
357
358/*
359 * We don't appear to need to do anything here. In fact, if we did, we'd
360 * duplicate cache flushing elsewhere performed by flush_dcache_page().
361 */
362#define flush_icache_page(vma,page) do { } while (0)
363
364#define __cacheid_present(val) (val != read_cpuid(CPUID_ID))
365#define __cacheid_vivt(val) ((val & (15 << 25)) != (14 << 25))
366#define __cacheid_vipt(val) ((val & (15 << 25)) == (14 << 25))
367#define __cacheid_vipt_nonaliasing(val) ((val & (15 << 25 | 1 << 23)) == (14 << 25))
368#define __cacheid_vipt_aliasing(val) ((val & (15 << 25 | 1 << 23)) == (14 << 25 | 1 << 23))
369
370#if defined(CONFIG_CPU_CACHE_VIVT) && !defined(CONFIG_CPU_CACHE_VIPT)
371
372#define cache_is_vivt() 1
373#define cache_is_vipt() 0
374#define cache_is_vipt_nonaliasing() 0
375#define cache_is_vipt_aliasing() 0
376
377#elif defined(CONFIG_CPU_CACHE_VIPT)
378
379#define cache_is_vivt() 0
380#define cache_is_vipt() 1
381#define cache_is_vipt_nonaliasing() \
382 ({ \
383 unsigned int __val = read_cpuid(CPUID_CACHETYPE); \
384 __cacheid_vipt_nonaliasing(__val); \
385 })
386
387#define cache_is_vipt_aliasing() \
388 ({ \
389 unsigned int __val = read_cpuid(CPUID_CACHETYPE); \
390 __cacheid_vipt_aliasing(__val); \
391 })
392
393#else
394
395#define cache_is_vivt() \
396 ({ \
397 unsigned int __val = read_cpuid(CPUID_CACHETYPE); \
398 (!__cacheid_present(__val)) || __cacheid_vivt(__val); \
399 })
400
401#define cache_is_vipt() \
402 ({ \
403 unsigned int __val = read_cpuid(CPUID_CACHETYPE); \
404 __cacheid_present(__val) && __cacheid_vipt(__val); \
405 })
406
407#define cache_is_vipt_nonaliasing() \
408 ({ \
409 unsigned int __val = read_cpuid(CPUID_CACHETYPE); \
410 __cacheid_present(__val) && \
411 __cacheid_vipt_nonaliasing(__val); \
412 })
413
414#define cache_is_vipt_aliasing() \
415 ({ \
416 unsigned int __val = read_cpuid(CPUID_CACHETYPE); \
417 __cacheid_present(__val) && \
418 __cacheid_vipt_aliasing(__val); \
419 })
420
421#endif
422
423#endif