2 * linux/include/asm-arm/cacheflush.h
4 * Copyright (C) 1999-2002 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_CACHEFLUSH_H
11 #define _ASMARM_CACHEFLUSH_H
13 #include <linux/sched.h>
17 #include <asm/shmparam.h>
19 #define CACHE_COLOUR(vaddr) ((vaddr & (SHMLBA - 1)) >> PAGE_SHIFT)
28 #if defined(CONFIG_CPU_CACHE_V3)
30 # define MULTI_CACHE 1
36 #if defined(CONFIG_CPU_CACHE_V4)
38 # define MULTI_CACHE 1
44 #if defined(CONFIG_CPU_ARM7TDMI) || defined(CONFIG_CPU_ARM9TDMI)
46 # define MULTI_CACHE 1
52 #if defined(CONFIG_CPU_S3C4510B)
54 # define MULTI_CACHE 1
56 # define _CACHE s3c4510b
60 #if defined(CONFIG_CPU_ARM920T) || defined(CONFIG_CPU_ARM922T) || \
61 defined(CONFIG_CPU_ARM925T) || defined(CONFIG_CPU_ARM1020)
62 # define MULTI_CACHE 1
65 #if defined(CONFIG_CPU_ARM926T)
67 # define MULTI_CACHE 1
69 # define _CACHE arm926
73 #if defined(CONFIG_CPU_ARM940T)
75 # define MULTI_CACHE 1
77 # define _CACHE arm940
81 #if defined(CONFIG_CPU_ARM946E)
83 # define MULTI_CACHE 1
85 # define _CACHE arm946
89 #if defined(CONFIG_CPU_CACHE_V4WB)
91 # define MULTI_CACHE 1
97 #if defined(CONFIG_CPU_XSCALE)
99 # define MULTI_CACHE 1
101 # define _CACHE xscale
105 #if defined(CONFIG_CPU_XSC3)
107 # define MULTI_CACHE 1
113 #if defined(CONFIG_CPU_V6)
115 # define MULTI_CACHE 1
121 #if !defined(_CACHE) && !defined(MULTI_CACHE)
122 #error Unknown cache maintainence model
126 * This flag is used to indicate that the page pointed to by a pte
127 * is dirty and requires cleaning before returning it to the user.
129 #define PG_dcache_dirty PG_arch_1
132 * MM Cache Management
133 * ===================
135 * The arch/arm/mm/cache-*.S and arch/arm/mm/proc-*.S files
136 * implement these methods.
138 * Start addresses are inclusive and end addresses are exclusive;
139 * start addresses should be rounded down, end addresses up.
141 * See Documentation/cachetlb.txt for more information.
142 * Please note that the implementation of these, and the required
143 * effects are cache-type (VIVT/VIPT/PIPT) specific.
145 * flush_cache_kern_all()
147 * Unconditionally clean and invalidate the entire cache.
149 * flush_cache_user_mm(mm)
151 * Clean and invalidate all user space cache entries
152 * before a change of page tables.
154 * flush_cache_user_range(start, end, flags)
156 * Clean and invalidate a range of cache entries in the
157 * specified address space before a change of page tables.
158 * - start - user start address (inclusive, page aligned)
159 * - end - user end address (exclusive, page aligned)
160 * - flags - vma->vm_flags field
162 * coherent_kern_range(start, end)
164 * Ensure coherency between the Icache and the Dcache in the
165 * region described by start, end. If you have non-snooping
166 * Harvard caches, you need to implement this function.
167 * - start - virtual start address
168 * - end - virtual end address
170 * DMA Cache Coherency
171 * ===================
173 * dma_inv_range(start, end)
175 * Invalidate (discard) the specified virtual address range.
176 * May not write back any entries. If 'start' or 'end'
177 * are not cache line aligned, those lines must be written
179 * - start - virtual start address
180 * - end - virtual end address
182 * dma_clean_range(start, end)
184 * Clean (write back) the specified virtual address range.
185 * - start - virtual start address
186 * - end - virtual end address
188 * dma_flush_range(start, end)
190 * Clean and invalidate the specified virtual address range.
191 * - start - virtual start address
192 * - end - virtual end address
195 struct cpu_cache_fns
{
196 void (*flush_kern_all
)(void);
197 void (*flush_user_all
)(void);
198 void (*flush_user_range
)(unsigned long, unsigned long, unsigned int);
200 void (*coherent_kern_range
)(unsigned long, unsigned long);
201 void (*coherent_user_range
)(unsigned long, unsigned long);
202 void (*flush_kern_dcache_page
)(void *);
204 void (*dma_inv_range
)(unsigned long, unsigned long);
205 void (*dma_clean_range
)(unsigned long, unsigned long);
206 void (*dma_flush_range
)(unsigned long, unsigned long);
210 * Select the calling method
214 extern struct cpu_cache_fns cpu_cache
;
216 #define __cpuc_flush_kern_all cpu_cache.flush_kern_all
217 #define __cpuc_flush_user_all cpu_cache.flush_user_all
218 #define __cpuc_flush_user_range cpu_cache.flush_user_range
219 #define __cpuc_coherent_kern_range cpu_cache.coherent_kern_range
220 #define __cpuc_coherent_user_range cpu_cache.coherent_user_range
221 #define __cpuc_flush_dcache_page cpu_cache.flush_kern_dcache_page
224 * These are private to the dma-mapping API. Do not use directly.
225 * Their sole purpose is to ensure that data held in the cache
226 * is visible to DMA, or data written by DMA to system memory is
227 * visible to the CPU.
229 #define dmac_inv_range cpu_cache.dma_inv_range
230 #define dmac_clean_range cpu_cache.dma_clean_range
231 #define dmac_flush_range cpu_cache.dma_flush_range
235 #define __cpuc_flush_kern_all __glue(_CACHE,_flush_kern_cache_all)
236 #define __cpuc_flush_user_all __glue(_CACHE,_flush_user_cache_all)
237 #define __cpuc_flush_user_range __glue(_CACHE,_flush_user_cache_range)
238 #define __cpuc_coherent_kern_range __glue(_CACHE,_coherent_kern_range)
239 #define __cpuc_coherent_user_range __glue(_CACHE,_coherent_user_range)
240 #define __cpuc_flush_dcache_page __glue(_CACHE,_flush_kern_dcache_page)
242 extern void __cpuc_flush_kern_all(void);
243 extern void __cpuc_flush_user_all(void);
244 extern void __cpuc_flush_user_range(unsigned long, unsigned long, unsigned int);
245 extern void __cpuc_coherent_kern_range(unsigned long, unsigned long);
246 extern void __cpuc_coherent_user_range(unsigned long, unsigned long);
247 extern void __cpuc_flush_dcache_page(void *);
250 * These are private to the dma-mapping API. Do not use directly.
251 * Their sole purpose is to ensure that data held in the cache
252 * is visible to DMA, or data written by DMA to system memory is
253 * visible to the CPU.
255 #define dmac_inv_range __glue(_CACHE,_dma_inv_range)
256 #define dmac_clean_range __glue(_CACHE,_dma_clean_range)
257 #define dmac_flush_range __glue(_CACHE,_dma_flush_range)
259 extern void dmac_inv_range(unsigned long, unsigned long);
260 extern void dmac_clean_range(unsigned long, unsigned long);
261 extern void dmac_flush_range(unsigned long, unsigned long);
266 * flush_cache_vmap() is used when creating mappings (eg, via vmap,
267 * vmalloc, ioremap etc) in kernel space for pages. Since the
268 * direct-mappings of these pages may contain cached data, we need
269 * to do a full cache flush to ensure that writebacks don't corrupt
270 * data placed into these pages via the new mappings.
272 #define flush_cache_vmap(start, end) flush_cache_all()
273 #define flush_cache_vunmap(start, end) flush_cache_all()
276 * Copy user data from/to a page which is mapped into a different
277 * processes address space. Really, we want to allow our "user
278 * space" model to handle this.
280 #define copy_to_user_page(vma, page, vaddr, dst, src, len) \
282 memcpy(dst, src, len); \
283 flush_ptrace_access(vma, page, vaddr, dst, len, 1);\
286 #define copy_from_user_page(vma, page, vaddr, dst, src, len) \
288 memcpy(dst, src, len); \
292 * Convert calls to our calling convention.
294 #define flush_cache_all() __cpuc_flush_kern_all()
295 #ifndef CONFIG_CPU_CACHE_VIPT
296 static inline void flush_cache_mm(struct mm_struct
*mm
)
298 if (cpu_isset(smp_processor_id(), mm
->cpu_vm_mask
))
299 __cpuc_flush_user_all();
303 flush_cache_range(struct vm_area_struct
*vma
, unsigned long start
, unsigned long end
)
305 if (cpu_isset(smp_processor_id(), vma
->vm_mm
->cpu_vm_mask
))
306 __cpuc_flush_user_range(start
& PAGE_MASK
, PAGE_ALIGN(end
),
311 flush_cache_page(struct vm_area_struct
*vma
, unsigned long user_addr
, unsigned long pfn
)
313 if (cpu_isset(smp_processor_id(), vma
->vm_mm
->cpu_vm_mask
)) {
314 unsigned long addr
= user_addr
& PAGE_MASK
;
315 __cpuc_flush_user_range(addr
, addr
+ PAGE_SIZE
, vma
->vm_flags
);
320 flush_ptrace_access(struct vm_area_struct
*vma
, struct page
*page
,
321 unsigned long uaddr
, void *kaddr
,
322 unsigned long len
, int write
)
324 if (cpu_isset(smp_processor_id(), vma
->vm_mm
->cpu_vm_mask
)) {
325 unsigned long addr
= (unsigned long)kaddr
;
326 __cpuc_coherent_kern_range(addr
, addr
+ len
);
330 extern void flush_cache_mm(struct mm_struct
*mm
);
331 extern void flush_cache_range(struct vm_area_struct
*vma
, unsigned long start
, unsigned long end
);
332 extern void flush_cache_page(struct vm_area_struct
*vma
, unsigned long user_addr
, unsigned long pfn
);
333 extern void flush_ptrace_access(struct vm_area_struct
*vma
, struct page
*page
,
334 unsigned long uaddr
, void *kaddr
,
335 unsigned long len
, int write
);
339 * flush_cache_user_range is used when we want to ensure that the
340 * Harvard caches are synchronised for the user space address range.
341 * This is used for the ARM private sys_cacheflush system call.
343 #define flush_cache_user_range(vma,start,end) \
344 __cpuc_coherent_user_range((start) & PAGE_MASK, PAGE_ALIGN(end))
347 * Perform necessary cache operations to ensure that data previously
348 * stored within this range of addresses can be executed by the CPU.
350 #define flush_icache_range(s,e) __cpuc_coherent_kern_range(s,e)
353 * Perform necessary cache operations to ensure that the TLB will
354 * see data written in the specified area.
356 #define clean_dcache_area(start,size) cpu_dcache_clean_area(start, size)
359 * flush_dcache_page is used when the kernel has written to the page
360 * cache page at virtual address page->virtual.
362 * If this page isn't mapped (ie, page_mapping == NULL), or it might
363 * have userspace mappings, then we _must_ always clean + invalidate
364 * the dcache entries associated with the kernel mapping.
366 * Otherwise we can defer the operation, and clean the cache when we are
367 * about to change to user space. This is the same method as used on SPARC64.
368 * See update_mmu_cache for the user space part.
370 extern void flush_dcache_page(struct page
*);
372 #define flush_dcache_mmap_lock(mapping) \
373 write_lock_irq(&(mapping)->tree_lock)
374 #define flush_dcache_mmap_unlock(mapping) \
375 write_unlock_irq(&(mapping)->tree_lock)
377 #define flush_icache_user_range(vma,page,addr,len) \
378 flush_dcache_page(page)
381 * We don't appear to need to do anything here. In fact, if we did, we'd
382 * duplicate cache flushing elsewhere performed by flush_dcache_page().
384 #define flush_icache_page(vma,page) do { } while (0)
386 #define __cacheid_present(val) (val != read_cpuid(CPUID_ID))
387 #define __cacheid_vivt(val) ((val & (15 << 25)) != (14 << 25))
388 #define __cacheid_vipt(val) ((val & (15 << 25)) == (14 << 25))
389 #define __cacheid_vipt_nonaliasing(val) ((val & (15 << 25 | 1 << 23)) == (14 << 25))
390 #define __cacheid_vipt_aliasing(val) ((val & (15 << 25 | 1 << 23)) == (14 << 25 | 1 << 23))
392 #if defined(CONFIG_CPU_CACHE_VIVT) && !defined(CONFIG_CPU_CACHE_VIPT)
394 #define cache_is_vivt() 1
395 #define cache_is_vipt() 0
396 #define cache_is_vipt_nonaliasing() 0
397 #define cache_is_vipt_aliasing() 0
399 #elif defined(CONFIG_CPU_CACHE_VIPT)
401 #define cache_is_vivt() 0
402 #define cache_is_vipt() 1
403 #define cache_is_vipt_nonaliasing() \
405 unsigned int __val = read_cpuid(CPUID_CACHETYPE); \
406 __cacheid_vipt_nonaliasing(__val); \
409 #define cache_is_vipt_aliasing() \
411 unsigned int __val = read_cpuid(CPUID_CACHETYPE); \
412 __cacheid_vipt_aliasing(__val); \
417 #define cache_is_vivt() \
419 unsigned int __val = read_cpuid(CPUID_CACHETYPE); \
420 (!__cacheid_present(__val)) || __cacheid_vivt(__val); \
423 #define cache_is_vipt() \
425 unsigned int __val = read_cpuid(CPUID_CACHETYPE); \
426 __cacheid_present(__val) && __cacheid_vipt(__val); \
429 #define cache_is_vipt_nonaliasing() \
431 unsigned int __val = read_cpuid(CPUID_CACHETYPE); \
432 __cacheid_present(__val) && \
433 __cacheid_vipt_nonaliasing(__val); \
436 #define cache_is_vipt_aliasing() \
438 unsigned int __val = read_cpuid(CPUID_CACHETYPE); \
439 __cacheid_present(__val) && \
440 __cacheid_vipt_aliasing(__val); \