patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / include / asm-arm / cacheflush.h
1 /*
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
13 #include <linux/config.h>
14 #include <linux/sched.h>
15 #include <linux/mm.h>
16
17 #include <asm/mman.h>
18 #include <asm/glue.h>
19
20 /*
21  *      Cache Model
22  *      ===========
23  */
24 #undef _CACHE
25 #undef MULTI_CACHE
26
27 #if defined(CONFIG_CPU_ARM610) || defined(CONFIG_CPU_ARM710)
28 # ifdef _CACHE
29 #  define MULTI_CACHE 1
30 # else
31 #  define _CACHE v3
32 # endif
33 #endif
34
35 #if defined(CONFIG_CPU_ARM720T)
36 # ifdef _CACHE
37 #  define MULTI_CACHE 1
38 # else
39 #  define _CACHE v4
40 # endif
41 #endif
42
43 #if defined(CONFIG_CPU_ARM920T) || defined(CONFIG_CPU_ARM922T) || \
44     defined(CONFIG_CPU_ARM925T) || defined(CONFIG_CPU_ARM1020)
45 # define MULTI_CACHE 1
46 #endif
47
48 #if defined(CONFIG_CPU_ARM926T)
49 # ifdef _CACHE
50 #  define MULTI_CACHE 1
51 # else
52 #  define _CACHE arm926
53 # endif
54 #endif
55
56 #if defined(CONFIG_CPU_SA110) || defined(CONFIG_CPU_SA1100)
57 # ifdef _CACHE
58 #  define MULTI_CACHE 1
59 # else
60 #  define _CACHE v4wb
61 # endif
62 #endif
63
64 #if defined(CONFIG_CPU_XSCALE)
65 # ifdef _CACHE
66 #  define MULTI_CACHE 1
67 # else
68 #  define _CACHE xscale
69 # endif
70 #endif
71
72 #if defined(CONFIG_CPU_V6)
73 //# ifdef _CACHE
74 #  define MULTI_CACHE 1
75 //# else
76 //#  define _CACHE v6
77 //# endif
78 #endif
79
80 #if !defined(_CACHE) && !defined(MULTI_CACHE)
81 #error Unknown cache maintainence model
82 #endif
83
84 /*
85  * This flag is used to indicate that the page pointed to by a pte
86  * is dirty and requires cleaning before returning it to the user.
87  */
88 #define PG_dcache_dirty PG_arch_1
89
90 /*
91  *      MM Cache Management
92  *      ===================
93  *
94  *      The arch/arm/mm/cache-*.S and arch/arm/mm/proc-*.S files
95  *      implement these methods.
96  *
97  *      Start addresses are inclusive and end addresses are exclusive;
98  *      start addresses should be rounded down, end addresses up.
99  *
100  *      See linux/Documentation/cachetlb.txt for more information.
101  *      Please note that the implementation of these, and the required
102  *      effects are cache-type (VIVT/VIPT/PIPT) specific.
103  *
104  *      flush_cache_kern_all()
105  *
106  *              Unconditionally clean and invalidate the entire cache.
107  *
108  *      flush_cache_user_mm(mm)
109  *
110  *              Clean and invalidate all user space cache entries
111  *              before a change of page tables.
112  *
113  *      flush_cache_user_range(start, end, flags)
114  *
115  *              Clean and invalidate a range of cache entries in the
116  *              specified address space before a change of page tables.
117  *              - start - user start address (inclusive, page aligned)
118  *              - end   - user end address   (exclusive, page aligned)
119  *              - flags - vma->vm_flags field
120  *
121  *      coherent_kern_range(start, end)
122  *
123  *              Ensure coherency between the Icache and the Dcache in the
124  *              region described by start, end.  If you have non-snooping
125  *              Harvard caches, you need to implement this function.
126  *              - start  - virtual start address
127  *              - end    - virtual end address
128  *
129  *      DMA Cache Coherency
130  *      ===================
131  *
132  *      dma_inv_range(start, end)
133  *
134  *              Invalidate (discard) the specified virtual address range.
135  *              May not write back any entries.  If 'start' or 'end'
136  *              are not cache line aligned, those lines must be written
137  *              back.
138  *              - start  - virtual start address
139  *              - end    - virtual end address
140  *
141  *      dma_clean_range(start, end)
142  *
143  *              Clean (write back) the specified virtual address range.
144  *              - start  - virtual start address
145  *              - end    - virtual end address
146  *
147  *      dma_flush_range(start, end)
148  *
149  *              Clean and invalidate the specified virtual address range.
150  *              - start  - virtual start address
151  *              - end    - virtual end address
152  */
153
154 struct cpu_cache_fns {
155         void (*flush_kern_all)(void);
156         void (*flush_user_all)(void);
157         void (*flush_user_range)(unsigned long, unsigned long, unsigned int);
158
159         void (*coherent_kern_range)(unsigned long, unsigned long);
160         void (*flush_kern_dcache_page)(void *);
161
162         void (*dma_inv_range)(unsigned long, unsigned long);
163         void (*dma_clean_range)(unsigned long, unsigned long);
164         void (*dma_flush_range)(unsigned long, unsigned long);
165 };
166
167 /*
168  * Select the calling method
169  */
170 #ifdef MULTI_CACHE
171
172 extern struct cpu_cache_fns cpu_cache;
173
174 #define __cpuc_flush_kern_all           cpu_cache.flush_kern_all
175 #define __cpuc_flush_user_all           cpu_cache.flush_user_all
176 #define __cpuc_flush_user_range         cpu_cache.flush_user_range
177 #define __cpuc_coherent_kern_range      cpu_cache.coherent_kern_range
178 #define __cpuc_flush_dcache_page        cpu_cache.flush_kern_dcache_page
179
180 /*
181  * These are private to the dma-mapping API.  Do not use directly.
182  * Their sole purpose is to ensure that data held in the cache
183  * is visible to DMA, or data written by DMA to system memory is
184  * visible to the CPU.
185  */
186 #define dmac_inv_range                  cpu_cache.dma_inv_range
187 #define dmac_clean_range                cpu_cache.dma_clean_range
188 #define dmac_flush_range                cpu_cache.dma_flush_range
189
190 #else
191
192 #define __cpuc_flush_kern_all           __glue(_CACHE,_flush_kern_cache_all)
193 #define __cpuc_flush_user_all           __glue(_CACHE,_flush_user_cache_all)
194 #define __cpuc_flush_user_range         __glue(_CACHE,_flush_user_cache_range)
195 #define __cpuc_coherent_kern_range      __glue(_CACHE,_coherent_kern_range)
196 #define __cpuc_flush_dcache_page        __glue(_CACHE,_flush_kern_dcache_page)
197
198 extern void __cpuc_flush_kern_all(void);
199 extern void __cpuc_flush_user_all(void);
200 extern void __cpuc_flush_user_range(unsigned long, unsigned long, unsigned int);
201 extern void __cpuc_coherent_kern_range(unsigned long, unsigned long);
202 extern void __cpuc_flush_dcache_page(void *);
203
204 /*
205  * These are private to the dma-mapping API.  Do not use directly.
206  * Their sole purpose is to ensure that data held in the cache
207  * is visible to DMA, or data written by DMA to system memory is
208  * visible to the CPU.
209  */
210 #define dmac_inv_range                  __glue(_CACHE,_dma_inv_range)
211 #define dmac_clean_range                __glue(_CACHE,_dma_clean_range)
212 #define dmac_flush_range                __glue(_CACHE,_dma_flush_range)
213
214 extern void dmac_inv_range(unsigned long, unsigned long);
215 extern void dmac_clean_range(unsigned long, unsigned long);
216 extern void dmac_flush_range(unsigned long, unsigned long);
217
218 #endif
219
220 /*
221  * flush_cache_vmap() is used when creating mappings (eg, via vmap,
222  * vmalloc, ioremap etc) in kernel space for pages.  Since the
223  * direct-mappings of these pages may contain cached data, we need
224  * to do a full cache flush to ensure that writebacks don't corrupt
225  * data placed into these pages via the new mappings.
226  */
227 #define flush_cache_vmap(start, end)            flush_cache_all()
228 #define flush_cache_vunmap(start, end)          flush_cache_all()
229
230 /*
231  * Copy user data from/to a page which is mapped into a different
232  * processes address space.  Really, we want to allow our "user
233  * space" model to handle this.
234  */
235 #define copy_to_user_page(vma, page, vaddr, dst, src, len) \
236 do { memcpy(dst, src, len); \
237      flush_icache_user_range(vma, page, vaddr, len); \
238 } while (0)
239 #define copy_from_user_page(vma, page, vaddr, dst, src, len) \
240         memcpy(dst, src, len)
241
242 /*
243  * Convert calls to our calling convention.
244  */
245 #define flush_cache_all()               __cpuc_flush_kern_all()
246
247 static inline void flush_cache_mm(struct mm_struct *mm)
248 {
249         if (current->active_mm == mm)
250                 __cpuc_flush_user_all();
251 }
252
253 static inline void
254 flush_cache_range(struct vm_area_struct *vma, unsigned long start, unsigned long end)
255 {
256         if (current->active_mm == vma->vm_mm)
257                 __cpuc_flush_user_range(start & PAGE_MASK, PAGE_ALIGN(end),
258                                         vma->vm_flags);
259 }
260
261 static inline void
262 flush_cache_page(struct vm_area_struct *vma, unsigned long user_addr)
263 {
264         if (current->active_mm == vma->vm_mm) {
265                 unsigned long addr = user_addr & PAGE_MASK;
266                 __cpuc_flush_user_range(addr, addr + PAGE_SIZE, vma->vm_flags);
267         }
268 }
269
270 /*
271  * Perform necessary cache operations to ensure that data previously
272  * stored within this range of addresses can be executed by the CPU.
273  */
274 #define flush_icache_range(s,e)         __cpuc_coherent_kern_range(s,e)
275
276 /*
277  * Perform necessary cache operations to ensure that the TLB will
278  * see data written in the specified area.
279  */
280 #define clean_dcache_area(start,size)   cpu_dcache_clean_area(start, size)
281
282 /*
283  * flush_dcache_page is used when the kernel has written to the page
284  * cache page at virtual address page->virtual.
285  *
286  * If this page isn't mapped (ie, page_mapping == NULL), or it might
287  * have userspace mappings, then we _must_ always clean + invalidate
288  * the dcache entries associated with the kernel mapping.
289  *
290  * Otherwise we can defer the operation, and clean the cache when we are
291  * about to change to user space.  This is the same method as used on SPARC64.
292  * See update_mmu_cache for the user space part.
293  */
294 extern void flush_dcache_page(struct page *);
295
296 #define flush_dcache_mmap_lock(mapping) \
297         spin_lock_irq(&(mapping)->tree_lock)
298 #define flush_dcache_mmap_unlock(mapping) \
299         spin_unlock_irq(&(mapping)->tree_lock)
300
301 #define flush_icache_user_range(vma,page,addr,len) \
302         flush_dcache_page(page)
303
304 /*
305  * We don't appear to need to do anything here.  In fact, if we did, we'd
306  * duplicate cache flushing elsewhere performed by flush_dcache_page().
307  */
308 #define flush_icache_page(vma,page)     do { } while (0)
309
310 #endif