[PATCH] don't allow users to set CONFIG_BROKEN=y
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / include / asm-arm / cacheflush.h
blob09e19a783a51dd9339e5234fae2f65d01484742f
1 /*
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.
9 */
10 #ifndef _ASMARM_CACHEFLUSH_H
11 #define _ASMARM_CACHEFLUSH_H
13 #include <linux/config.h>
14 #include <linux/sched.h>
15 #include <linux/mm.h>
17 #include <asm/glue.h>
18 #include <asm/shmparam.h>
20 #define CACHE_COLOUR(vaddr) ((vaddr & (SHMLBA - 1)) >> PAGE_SHIFT)
23 * Cache Model
24 * ===========
26 #undef _CACHE
27 #undef MULTI_CACHE
29 #if defined(CONFIG_CPU_ARM610) || defined(CONFIG_CPU_ARM710)
30 # ifdef _CACHE
31 # define MULTI_CACHE 1
32 # else
33 # define _CACHE v3
34 # endif
35 #endif
37 #if defined(CONFIG_CPU_ARM720T)
38 # ifdef _CACHE
39 # define MULTI_CACHE 1
40 # else
41 # define _CACHE v4
42 # endif
43 #endif
45 #if defined(CONFIG_CPU_ARM920T) || defined(CONFIG_CPU_ARM922T) || \
46 defined(CONFIG_CPU_ARM925T) || defined(CONFIG_CPU_ARM1020)
47 # define MULTI_CACHE 1
48 #endif
50 #if defined(CONFIG_CPU_ARM926T)
51 # ifdef _CACHE
52 # define MULTI_CACHE 1
53 # else
54 # define _CACHE arm926
55 # endif
56 #endif
58 #if defined(CONFIG_CPU_SA110) || defined(CONFIG_CPU_SA1100)
59 # ifdef _CACHE
60 # define MULTI_CACHE 1
61 # else
62 # define _CACHE v4wb
63 # endif
64 #endif
66 #if defined(CONFIG_CPU_XSCALE)
67 # ifdef _CACHE
68 # define MULTI_CACHE 1
69 # else
70 # define _CACHE xscale
71 # endif
72 #endif
74 #if defined(CONFIG_CPU_V6)
75 //# ifdef _CACHE
76 # define MULTI_CACHE 1
77 //# else
78 //# define _CACHE v6
79 //# endif
80 #endif
82 #if !defined(_CACHE) && !defined(MULTI_CACHE)
83 #error Unknown cache maintainence model
84 #endif
87 * This flag is used to indicate that the page pointed to by a pte
88 * is dirty and requires cleaning before returning it to the user.
90 #define PG_dcache_dirty PG_arch_1
93 * MM Cache Management
94 * ===================
96 * The arch/arm/mm/cache-*.S and arch/arm/mm/proc-*.S files
97 * implement these methods.
99 * Start addresses are inclusive and end addresses are exclusive;
100 * start addresses should be rounded down, end addresses up.
102 * See Documentation/cachetlb.txt for more information.
103 * Please note that the implementation of these, and the required
104 * effects are cache-type (VIVT/VIPT/PIPT) specific.
106 * flush_cache_kern_all()
108 * Unconditionally clean and invalidate the entire cache.
110 * flush_cache_user_mm(mm)
112 * Clean and invalidate all user space cache entries
113 * before a change of page tables.
115 * flush_cache_user_range(start, end, flags)
117 * Clean and invalidate a range of cache entries in the
118 * specified address space before a change of page tables.
119 * - start - user start address (inclusive, page aligned)
120 * - end - user end address (exclusive, page aligned)
121 * - flags - vma->vm_flags field
123 * coherent_kern_range(start, end)
125 * Ensure coherency between the Icache and the Dcache in the
126 * region described by start, end. If you have non-snooping
127 * Harvard caches, you need to implement this function.
128 * - start - virtual start address
129 * - end - virtual end address
131 * DMA Cache Coherency
132 * ===================
134 * dma_inv_range(start, end)
136 * Invalidate (discard) the specified virtual address range.
137 * May not write back any entries. If 'start' or 'end'
138 * are not cache line aligned, those lines must be written
139 * back.
140 * - start - virtual start address
141 * - end - virtual end address
143 * dma_clean_range(start, end)
145 * Clean (write back) the specified virtual address range.
146 * - start - virtual start address
147 * - end - virtual end address
149 * dma_flush_range(start, end)
151 * Clean and invalidate the specified virtual address range.
152 * - start - virtual start address
153 * - end - virtual end address
156 struct cpu_cache_fns {
157 void (*flush_kern_all)(void);
158 void (*flush_user_all)(void);
159 void (*flush_user_range)(unsigned long, unsigned long, unsigned int);
161 void (*coherent_kern_range)(unsigned long, unsigned long);
162 void (*coherent_user_range)(unsigned long, unsigned long);
163 void (*flush_kern_dcache_page)(void *);
165 void (*dma_inv_range)(unsigned long, unsigned long);
166 void (*dma_clean_range)(unsigned long, unsigned long);
167 void (*dma_flush_range)(unsigned long, unsigned long);
171 * Select the calling method
173 #ifdef MULTI_CACHE
175 extern struct cpu_cache_fns cpu_cache;
177 #define __cpuc_flush_kern_all cpu_cache.flush_kern_all
178 #define __cpuc_flush_user_all cpu_cache.flush_user_all
179 #define __cpuc_flush_user_range cpu_cache.flush_user_range
180 #define __cpuc_coherent_kern_range cpu_cache.coherent_kern_range
181 #define __cpuc_coherent_user_range cpu_cache.coherent_user_range
182 #define __cpuc_flush_dcache_page cpu_cache.flush_kern_dcache_page
185 * These are private to the dma-mapping API. Do not use directly.
186 * Their sole purpose is to ensure that data held in the cache
187 * is visible to DMA, or data written by DMA to system memory is
188 * visible to the CPU.
190 #define dmac_inv_range cpu_cache.dma_inv_range
191 #define dmac_clean_range cpu_cache.dma_clean_range
192 #define dmac_flush_range cpu_cache.dma_flush_range
194 #else
196 #define __cpuc_flush_kern_all __glue(_CACHE,_flush_kern_cache_all)
197 #define __cpuc_flush_user_all __glue(_CACHE,_flush_user_cache_all)
198 #define __cpuc_flush_user_range __glue(_CACHE,_flush_user_cache_range)
199 #define __cpuc_coherent_kern_range __glue(_CACHE,_coherent_kern_range)
200 #define __cpuc_coherent_user_range __glue(_CACHE,_coherent_user_range)
201 #define __cpuc_flush_dcache_page __glue(_CACHE,_flush_kern_dcache_page)
203 extern void __cpuc_flush_kern_all(void);
204 extern void __cpuc_flush_user_all(void);
205 extern void __cpuc_flush_user_range(unsigned long, unsigned long, unsigned int);
206 extern void __cpuc_coherent_kern_range(unsigned long, unsigned long);
207 extern void __cpuc_coherent_user_range(unsigned long, unsigned long);
208 extern void __cpuc_flush_dcache_page(void *);
211 * These are private to the dma-mapping API. Do not use directly.
212 * Their sole purpose is to ensure that data held in the cache
213 * is visible to DMA, or data written by DMA to system memory is
214 * visible to the CPU.
216 #define dmac_inv_range __glue(_CACHE,_dma_inv_range)
217 #define dmac_clean_range __glue(_CACHE,_dma_clean_range)
218 #define dmac_flush_range __glue(_CACHE,_dma_flush_range)
220 extern void dmac_inv_range(unsigned long, unsigned long);
221 extern void dmac_clean_range(unsigned long, unsigned long);
222 extern void dmac_flush_range(unsigned long, unsigned long);
224 #endif
227 * flush_cache_vmap() is used when creating mappings (eg, via vmap,
228 * vmalloc, ioremap etc) in kernel space for pages. Since the
229 * direct-mappings of these pages may contain cached data, we need
230 * to do a full cache flush to ensure that writebacks don't corrupt
231 * data placed into these pages via the new mappings.
233 #define flush_cache_vmap(start, end) flush_cache_all()
234 #define flush_cache_vunmap(start, end) flush_cache_all()
237 * Copy user data from/to a page which is mapped into a different
238 * processes address space. Really, we want to allow our "user
239 * space" model to handle this.
241 #define copy_to_user_page(vma, page, vaddr, dst, src, len) \
242 do { \
243 flush_cache_page(vma, vaddr, page_to_pfn(page));\
244 memcpy(dst, src, len); \
245 flush_dcache_page(page); \
246 } while (0)
248 #define copy_from_user_page(vma, page, vaddr, dst, src, len) \
249 do { \
250 flush_cache_page(vma, vaddr, page_to_pfn(page));\
251 memcpy(dst, src, len); \
252 } while (0)
255 * Convert calls to our calling convention.
257 #define flush_cache_all() __cpuc_flush_kern_all()
258 #ifndef CONFIG_CPU_CACHE_VIPT
259 static inline void flush_cache_mm(struct mm_struct *mm)
261 if (cpu_isset(smp_processor_id(), mm->cpu_vm_mask))
262 __cpuc_flush_user_all();
265 static inline void
266 flush_cache_range(struct vm_area_struct *vma, unsigned long start, unsigned long end)
268 if (cpu_isset(smp_processor_id(), vma->vm_mm->cpu_vm_mask))
269 __cpuc_flush_user_range(start & PAGE_MASK, PAGE_ALIGN(end),
270 vma->vm_flags);
273 static inline void
274 flush_cache_page(struct vm_area_struct *vma, unsigned long user_addr, unsigned long pfn)
276 if (cpu_isset(smp_processor_id(), vma->vm_mm->cpu_vm_mask)) {
277 unsigned long addr = user_addr & PAGE_MASK;
278 __cpuc_flush_user_range(addr, addr + PAGE_SIZE, vma->vm_flags);
281 #else
282 extern void flush_cache_mm(struct mm_struct *mm);
283 extern void flush_cache_range(struct vm_area_struct *vma, unsigned long start, unsigned long end);
284 extern void flush_cache_page(struct vm_area_struct *vma, unsigned long user_addr, unsigned long pfn);
285 #endif
288 * flush_cache_user_range is used when we want to ensure that the
289 * Harvard caches are synchronised for the user space address range.
290 * This is used for the ARM private sys_cacheflush system call.
292 #define flush_cache_user_range(vma,start,end) \
293 __cpuc_coherent_user_range((start) & PAGE_MASK, PAGE_ALIGN(end))
296 * Perform necessary cache operations to ensure that data previously
297 * stored within this range of addresses can be executed by the CPU.
299 #define flush_icache_range(s,e) __cpuc_coherent_kern_range(s,e)
302 * Perform necessary cache operations to ensure that the TLB will
303 * see data written in the specified area.
305 #define clean_dcache_area(start,size) cpu_dcache_clean_area(start, size)
308 * flush_dcache_page is used when the kernel has written to the page
309 * cache page at virtual address page->virtual.
311 * If this page isn't mapped (ie, page_mapping == NULL), or it might
312 * have userspace mappings, then we _must_ always clean + invalidate
313 * the dcache entries associated with the kernel mapping.
315 * Otherwise we can defer the operation, and clean the cache when we are
316 * about to change to user space. This is the same method as used on SPARC64.
317 * See update_mmu_cache for the user space part.
319 extern void flush_dcache_page(struct page *);
321 #define flush_dcache_mmap_lock(mapping) \
322 write_lock_irq(&(mapping)->tree_lock)
323 #define flush_dcache_mmap_unlock(mapping) \
324 write_unlock_irq(&(mapping)->tree_lock)
326 #define flush_icache_user_range(vma,page,addr,len) \
327 flush_dcache_page(page)
330 * We don't appear to need to do anything here. In fact, if we did, we'd
331 * duplicate cache flushing elsewhere performed by flush_dcache_page().
333 #define flush_icache_page(vma,page) do { } while (0)
335 #define __cacheid_present(val) (val != read_cpuid(CPUID_ID))
336 #define __cacheid_vivt(val) ((val & (15 << 25)) != (14 << 25))
337 #define __cacheid_vipt(val) ((val & (15 << 25)) == (14 << 25))
338 #define __cacheid_vipt_nonaliasing(val) ((val & (15 << 25 | 1 << 23)) == (14 << 25))
339 #define __cacheid_vipt_aliasing(val) ((val & (15 << 25 | 1 << 23)) == (14 << 25 | 1 << 23))
341 #if defined(CONFIG_CPU_CACHE_VIVT) && !defined(CONFIG_CPU_CACHE_VIPT)
343 #define cache_is_vivt() 1
344 #define cache_is_vipt() 0
345 #define cache_is_vipt_nonaliasing() 0
346 #define cache_is_vipt_aliasing() 0
348 #elif defined(CONFIG_CPU_CACHE_VIPT)
350 #define cache_is_vivt() 0
351 #define cache_is_vipt() 1
352 #define cache_is_vipt_nonaliasing() \
353 ({ \
354 unsigned int __val = read_cpuid(CPUID_CACHETYPE); \
355 __cacheid_vipt_nonaliasing(__val); \
358 #define cache_is_vipt_aliasing() \
359 ({ \
360 unsigned int __val = read_cpuid(CPUID_CACHETYPE); \
361 __cacheid_vipt_aliasing(__val); \
364 #else
366 #define cache_is_vivt() \
367 ({ \
368 unsigned int __val = read_cpuid(CPUID_CACHETYPE); \
369 (!__cacheid_present(__val)) || __cacheid_vivt(__val); \
372 #define cache_is_vipt() \
373 ({ \
374 unsigned int __val = read_cpuid(CPUID_CACHETYPE); \
375 __cacheid_present(__val) && __cacheid_vipt(__val); \
378 #define cache_is_vipt_nonaliasing() \
379 ({ \
380 unsigned int __val = read_cpuid(CPUID_CACHETYPE); \
381 __cacheid_present(__val) && \
382 __cacheid_vipt_nonaliasing(__val); \
385 #define cache_is_vipt_aliasing() \
386 ({ \
387 unsigned int __val = read_cpuid(CPUID_CACHETYPE); \
388 __cacheid_present(__val) && \
389 __cacheid_vipt_aliasing(__val); \
392 #endif
394 #endif