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/config.h>
14 #include <linux/sched.h>
19 #include <asm/shmparam.h>
21 #define CACHE_COLOUR(vaddr) ((vaddr & (SHMLBA - 1)) >> PAGE_SHIFT)
30 #if defined(CONFIG_CPU_ARM610) || defined(CONFIG_CPU_ARM710)
32 # define MULTI_CACHE 1
38 #if defined(CONFIG_CPU_ARM720T)
40 # define MULTI_CACHE 1
46 #if defined(CONFIG_CPU_ARM920T) || defined(CONFIG_CPU_ARM922T) || \
47 defined(CONFIG_CPU_ARM925T) || defined(CONFIG_CPU_ARM1020)
48 # define MULTI_CACHE 1
51 #if defined(CONFIG_CPU_ARM926T)
53 # define MULTI_CACHE 1
55 # define _CACHE arm926
59 #if defined(CONFIG_CPU_SA110) || defined(CONFIG_CPU_SA1100)
61 # define MULTI_CACHE 1
67 #if defined(CONFIG_CPU_XSCALE)
69 # define MULTI_CACHE 1
71 # define _CACHE xscale
75 #if defined(CONFIG_CPU_V6)
77 # define MULTI_CACHE 1
83 #if !defined(_CACHE) && !defined(MULTI_CACHE)
84 #error Unknown cache maintainence model
88 * This flag is used to indicate that the page pointed to by a pte
89 * is dirty and requires cleaning before returning it to the user.
91 #define PG_dcache_dirty PG_arch_1
97 * The arch/arm/mm/cache-*.S and arch/arm/mm/proc-*.S files
98 * implement these methods.
100 * Start addresses are inclusive and end addresses are exclusive;
101 * start addresses should be rounded down, end addresses up.
103 * See Documentation/cachetlb.txt for more information.
104 * Please note that the implementation of these, and the required
105 * effects are cache-type (VIVT/VIPT/PIPT) specific.
107 * flush_cache_kern_all()
109 * Unconditionally clean and invalidate the entire cache.
111 * flush_cache_user_mm(mm)
113 * Clean and invalidate all user space cache entries
114 * before a change of page tables.
116 * flush_cache_user_range(start, end, flags)
118 * Clean and invalidate a range of cache entries in the
119 * specified address space before a change of page tables.
120 * - start - user start address (inclusive, page aligned)
121 * - end - user end address (exclusive, page aligned)
122 * - flags - vma->vm_flags field
124 * coherent_kern_range(start, end)
126 * Ensure coherency between the Icache and the Dcache in the
127 * region described by start, end. If you have non-snooping
128 * Harvard caches, you need to implement this function.
129 * - start - virtual start address
130 * - end - virtual end address
132 * DMA Cache Coherency
133 * ===================
135 * dma_inv_range(start, end)
137 * Invalidate (discard) the specified virtual address range.
138 * May not write back any entries. If 'start' or 'end'
139 * are not cache line aligned, those lines must be written
141 * - start - virtual start address
142 * - end - virtual end address
144 * dma_clean_range(start, end)
146 * Clean (write back) the specified virtual address range.
147 * - start - virtual start address
148 * - end - virtual end address
150 * dma_flush_range(start, end)
152 * Clean and invalidate the specified virtual address range.
153 * - start - virtual start address
154 * - end - virtual end address
157 struct cpu_cache_fns
{
158 void (*flush_kern_all
)(void);
159 void (*flush_user_all
)(void);
160 void (*flush_user_range
)(unsigned long, unsigned long, unsigned int);
162 void (*coherent_kern_range
)(unsigned long, unsigned long);
163 void (*coherent_user_range
)(unsigned long, unsigned long);
164 void (*flush_kern_dcache_page
)(void *);
166 void (*dma_inv_range
)(unsigned long, unsigned long);
167 void (*dma_clean_range
)(unsigned long, unsigned long);
168 void (*dma_flush_range
)(unsigned long, unsigned long);
172 * Select the calling method
176 extern struct cpu_cache_fns cpu_cache
;
178 #define __cpuc_flush_kern_all cpu_cache.flush_kern_all
179 #define __cpuc_flush_user_all cpu_cache.flush_user_all
180 #define __cpuc_flush_user_range cpu_cache.flush_user_range
181 #define __cpuc_coherent_kern_range cpu_cache.coherent_kern_range
182 #define __cpuc_coherent_user_range cpu_cache.coherent_user_range
183 #define __cpuc_flush_dcache_page cpu_cache.flush_kern_dcache_page
186 * These are private to the dma-mapping API. Do not use directly.
187 * Their sole purpose is to ensure that data held in the cache
188 * is visible to DMA, or data written by DMA to system memory is
189 * visible to the CPU.
191 #define dmac_inv_range cpu_cache.dma_inv_range
192 #define dmac_clean_range cpu_cache.dma_clean_range
193 #define dmac_flush_range cpu_cache.dma_flush_range
197 #define __cpuc_flush_kern_all __glue(_CACHE,_flush_kern_cache_all)
198 #define __cpuc_flush_user_all __glue(_CACHE,_flush_user_cache_all)
199 #define __cpuc_flush_user_range __glue(_CACHE,_flush_user_cache_range)
200 #define __cpuc_coherent_kern_range __glue(_CACHE,_coherent_kern_range)
201 #define __cpuc_coherent_user_range __glue(_CACHE,_coherent_user_range)
202 #define __cpuc_flush_dcache_page __glue(_CACHE,_flush_kern_dcache_page)
204 extern void __cpuc_flush_kern_all(void);
205 extern void __cpuc_flush_user_all(void);
206 extern void __cpuc_flush_user_range(unsigned long, unsigned long, unsigned int);
207 extern void __cpuc_coherent_kern_range(unsigned long, unsigned long);
208 extern void __cpuc_coherent_user_range(unsigned long, unsigned long);
209 extern void __cpuc_flush_dcache_page(void *);
212 * These are private to the dma-mapping API. Do not use directly.
213 * Their sole purpose is to ensure that data held in the cache
214 * is visible to DMA, or data written by DMA to system memory is
215 * visible to the CPU.
217 #define dmac_inv_range __glue(_CACHE,_dma_inv_range)
218 #define dmac_clean_range __glue(_CACHE,_dma_clean_range)
219 #define dmac_flush_range __glue(_CACHE,_dma_flush_range)
221 extern void dmac_inv_range(unsigned long, unsigned long);
222 extern void dmac_clean_range(unsigned long, unsigned long);
223 extern void dmac_flush_range(unsigned long, unsigned long);
228 * flush_cache_vmap() is used when creating mappings (eg, via vmap,
229 * vmalloc, ioremap etc) in kernel space for pages. Since the
230 * direct-mappings of these pages may contain cached data, we need
231 * to do a full cache flush to ensure that writebacks don't corrupt
232 * data placed into these pages via the new mappings.
234 #define flush_cache_vmap(start, end) flush_cache_all()
235 #define flush_cache_vunmap(start, end) flush_cache_all()
238 * Copy user data from/to a page which is mapped into a different
239 * processes address space. Really, we want to allow our "user
240 * space" model to handle this.
242 #define copy_to_user_page(vma, page, vaddr, dst, src, len) \
244 flush_cache_page(vma, vaddr, page_to_pfn(page));\
245 memcpy(dst, src, len); \
246 flush_dcache_page(page); \
249 #define copy_from_user_page(vma, page, vaddr, dst, src, len) \
251 flush_cache_page(vma, vaddr, page_to_pfn(page));\
252 memcpy(dst, src, len); \
256 * Convert calls to our calling convention.
258 #define flush_cache_all() __cpuc_flush_kern_all()
259 #ifndef CONFIG_CPU_CACHE_VIPT
260 static inline void flush_cache_mm(struct mm_struct
*mm
)
262 if (cpu_isset(smp_processor_id(), mm
->cpu_vm_mask
))
263 __cpuc_flush_user_all();
267 flush_cache_range(struct vm_area_struct
*vma
, unsigned long start
, unsigned long end
)
269 if (cpu_isset(smp_processor_id(), vma
->vm_mm
->cpu_vm_mask
))
270 __cpuc_flush_user_range(start
& PAGE_MASK
, PAGE_ALIGN(end
),
275 flush_cache_page(struct vm_area_struct
*vma
, unsigned long user_addr
, unsigned long pfn
)
277 if (cpu_isset(smp_processor_id(), vma
->vm_mm
->cpu_vm_mask
)) {
278 unsigned long addr
= user_addr
& PAGE_MASK
;
279 __cpuc_flush_user_range(addr
, addr
+ PAGE_SIZE
, vma
->vm_flags
);
283 extern void flush_cache_mm(struct mm_struct
*mm
);
284 extern void flush_cache_range(struct vm_area_struct
*vma
, unsigned long start
, unsigned long end
);
285 extern void flush_cache_page(struct vm_area_struct
*vma
, unsigned long user_addr
, unsigned long pfn
);
289 * flush_cache_user_range is used when we want to ensure that the
290 * Harvard caches are synchronised for the user space address range.
291 * This is used for the ARM private sys_cacheflush system call.
293 #define flush_cache_user_range(vma,start,end) \
294 __cpuc_coherent_user_range((start) & PAGE_MASK, PAGE_ALIGN(end))
297 * Perform necessary cache operations to ensure that data previously
298 * stored within this range of addresses can be executed by the CPU.
300 #define flush_icache_range(s,e) __cpuc_coherent_kern_range(s,e)
303 * Perform necessary cache operations to ensure that the TLB will
304 * see data written in the specified area.
306 #define clean_dcache_area(start,size) cpu_dcache_clean_area(start, size)
309 * flush_dcache_page is used when the kernel has written to the page
310 * cache page at virtual address page->virtual.
312 * If this page isn't mapped (ie, page_mapping == NULL), or it might
313 * have userspace mappings, then we _must_ always clean + invalidate
314 * the dcache entries associated with the kernel mapping.
316 * Otherwise we can defer the operation, and clean the cache when we are
317 * about to change to user space. This is the same method as used on SPARC64.
318 * See update_mmu_cache for the user space part.
320 extern void flush_dcache_page(struct page
*);
322 #define flush_dcache_mmap_lock(mapping) \
323 write_lock_irq(&(mapping)->tree_lock)
324 #define flush_dcache_mmap_unlock(mapping) \
325 write_unlock_irq(&(mapping)->tree_lock)
327 #define flush_icache_user_range(vma,page,addr,len) \
328 flush_dcache_page(page)
331 * We don't appear to need to do anything here. In fact, if we did, we'd
332 * duplicate cache flushing elsewhere performed by flush_dcache_page().
334 #define flush_icache_page(vma,page) do { } while (0)
336 #define __cacheid_present(val) (val != read_cpuid(CPUID_ID))
337 #define __cacheid_vivt(val) ((val & (15 << 25)) != (14 << 25))
338 #define __cacheid_vipt(val) ((val & (15 << 25)) == (14 << 25))
339 #define __cacheid_vipt_nonaliasing(val) ((val & (15 << 25 | 1 << 23)) == (14 << 25))
340 #define __cacheid_vipt_aliasing(val) ((val & (15 << 25 | 1 << 23)) == (14 << 25 | 1 << 23))
342 #if defined(CONFIG_CPU_CACHE_VIVT) && !defined(CONFIG_CPU_CACHE_VIPT)
344 #define cache_is_vivt() 1
345 #define cache_is_vipt() 0
346 #define cache_is_vipt_nonaliasing() 0
347 #define cache_is_vipt_aliasing() 0
349 #elif defined(CONFIG_CPU_CACHE_VIPT)
351 #define cache_is_vivt() 0
352 #define cache_is_vipt() 1
353 #define cache_is_vipt_nonaliasing() \
355 unsigned int __val = read_cpuid(CPUID_CACHETYPE); \
356 __cacheid_vipt_nonaliasing(__val); \
359 #define cache_is_vipt_aliasing() \
361 unsigned int __val = read_cpuid(CPUID_CACHETYPE); \
362 __cacheid_vipt_aliasing(__val); \
367 #define cache_is_vivt() \
369 unsigned int __val = read_cpuid(CPUID_CACHETYPE); \
370 (!__cacheid_present(__val)) || __cacheid_vivt(__val); \
373 #define cache_is_vipt() \
375 unsigned int __val = read_cpuid(CPUID_CACHETYPE); \
376 __cacheid_present(__val) && __cacheid_vipt(__val); \
379 #define cache_is_vipt_nonaliasing() \
381 unsigned int __val = read_cpuid(CPUID_CACHETYPE); \
382 __cacheid_present(__val) && \
383 __cacheid_vipt_nonaliasing(__val); \
386 #define cache_is_vipt_aliasing() \
388 unsigned int __val = read_cpuid(CPUID_CACHETYPE); \
389 __cacheid_present(__val) && \
390 __cacheid_vipt_aliasing(__val); \