2 * linux/arch/arm/mm/cache-v6.S
4 * Copyright (C) 2001 Deep Blue Solutions Ltd.
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 * This is the "shell" of the ARMv6 processor support.
12 #include <linux/linkage.h>
13 #include <linux/init.h>
14 #include <asm/assembler.h>
15 #include <asm/errno.h>
16 #include <asm/unwind.h>
18 #include "proc-macros.S"
21 #define CACHE_LINE_SIZE 32
22 #define D_CACHE_LINE_SIZE 32
23 #define BTB_FLUSH_SIZE 8
26 * v6_flush_icache_all()
28 * Flush the whole I-cache.
30 * ARM1136 erratum 411920 - Invalidate Instruction Cache operation can fail.
31 * This erratum is present in 1136, 1156 and 1176. It does not affect the
38 ENTRY(v6_flush_icache_all)
40 #ifdef CONFIG_ARM_ERRATA_411920
42 cpsid ifa @ disable interrupts
43 mcr p15, 0, r0, c7, c5, 0 @ invalidate entire I-cache
44 mcr p15, 0, r0, c7, c5, 0 @ invalidate entire I-cache
45 mcr p15, 0, r0, c7, c5, 0 @ invalidate entire I-cache
46 mcr p15, 0, r0, c7, c5, 0 @ invalidate entire I-cache
47 msr cpsr_cx, r1 @ restore interrupts
48 .rept 11 @ ARM Ltd recommends at least
52 mcr p15, 0, r0, c7, c5, 0 @ invalidate I-cache
55 ENDPROC(v6_flush_icache_all)
58 * v6_flush_cache_all()
60 * Flush the entire cache.
64 ENTRY(v6_flush_kern_cache_all)
67 mcr p15, 0, r0, c7, c14, 0 @ D cache clean+invalidate
68 #ifndef CONFIG_ARM_ERRATA_411920
69 mcr p15, 0, r0, c7, c5, 0 @ I+BTB cache invalidate
74 mcr p15, 0, r0, c7, c15, 0 @ Cache clean+invalidate
79 * v6_flush_cache_all()
81 * Flush all TLB entries in a particular address space
83 * - mm - mm_struct describing address space
85 ENTRY(v6_flush_user_cache_all)
89 * v6_flush_cache_range(start, end, flags)
91 * Flush a range of TLB entries in the specified address space.
93 * - start - start address (may not be aligned)
94 * - end - end address (exclusive, may not be aligned)
95 * - flags - vm_area_struct flags describing address space
98 * - we have a VIPT cache.
100 ENTRY(v6_flush_user_cache_range)
104 * v6_coherent_kern_range(start,end)
106 * Ensure that the I and D caches are coherent within specified
107 * region. This is typically used when code has been written to
108 * a memory region, and will be executed.
110 * - start - virtual start address of region
111 * - end - virtual end address of region
113 * It is assumed that:
114 * - the Icache does not read data from the write buffer
116 ENTRY(v6_coherent_kern_range)
120 * v6_coherent_user_range(start,end)
122 * Ensure that the I and D caches are coherent within specified
123 * region. This is typically used when code has been written to
124 * a memory region, and will be executed.
126 * - start - virtual start address of region
127 * - end - virtual end address of region
129 * It is assumed that:
130 * - the Icache does not read data from the write buffer
132 ENTRY(v6_coherent_user_range)
135 bic r0, r0, #CACHE_LINE_SIZE - 1
137 USER( mcr p15, 0, r0, c7, c10, 1 ) @ clean D line
138 add r0, r0, #CACHE_LINE_SIZE
144 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
145 #ifndef CONFIG_ARM_ERRATA_411920
146 mcr p15, 0, r0, c7, c5, 0 @ I+BTB cache invalidate
148 b v6_flush_icache_all
151 mcr p15, 0, r0, c7, c5, 6 @ invalidate BTB
156 * Fault handling for the cache operation above. If the virtual address in r0
157 * isn't mapped, fail with -EFAULT.
163 ENDPROC(v6_coherent_user_range)
164 ENDPROC(v6_coherent_kern_range)
167 * v6_flush_kern_dcache_area(void *addr, size_t size)
169 * Ensure that the data held in the page kaddr is written back
170 * to the page in question.
172 * - addr - kernel address
173 * - size - region size
175 ENTRY(v6_flush_kern_dcache_area)
177 bic r0, r0, #D_CACHE_LINE_SIZE - 1
180 mcr p15, 0, r0, c7, c14, 1 @ clean & invalidate D line
182 mcr p15, 0, r0, c7, c15, 1 @ clean & invalidate unified line
184 add r0, r0, #D_CACHE_LINE_SIZE
189 mcr p15, 0, r0, c7, c10, 4
195 * v6_dma_inv_range(start,end)
197 * Invalidate the data cache within the specified region; we will
198 * be performing a DMA operation in this region and we want to
199 * purge old data in the cache.
201 * - start - virtual start address of region
202 * - end - virtual end address of region
205 #ifdef CONFIG_DMA_CACHE_RWFO
206 ldrb r2, [r0] @ read for ownership
207 strb r2, [r0] @ write for ownership
209 tst r0, #D_CACHE_LINE_SIZE - 1
210 bic r0, r0, #D_CACHE_LINE_SIZE - 1
212 mcrne p15, 0, r0, c7, c10, 1 @ clean D line
214 mcrne p15, 0, r0, c7, c11, 1 @ clean unified line
216 tst r1, #D_CACHE_LINE_SIZE - 1
217 #ifdef CONFIG_DMA_CACHE_RWFO
218 ldrneb r2, [r1, #-1] @ read for ownership
219 strneb r2, [r1, #-1] @ write for ownership
221 bic r1, r1, #D_CACHE_LINE_SIZE - 1
223 mcrne p15, 0, r1, c7, c14, 1 @ clean & invalidate D line
225 mcrne p15, 0, r1, c7, c15, 1 @ clean & invalidate unified line
229 mcr p15, 0, r0, c7, c6, 1 @ invalidate D line
231 mcr p15, 0, r0, c7, c7, 1 @ invalidate unified line
233 add r0, r0, #D_CACHE_LINE_SIZE
235 #ifdef CONFIG_DMA_CACHE_RWFO
236 ldrlo r2, [r0] @ read for ownership
237 strlo r2, [r0] @ write for ownership
241 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
245 * v6_dma_clean_range(start,end)
246 * - start - virtual start address of region
247 * - end - virtual end address of region
250 bic r0, r0, #D_CACHE_LINE_SIZE - 1
252 #ifdef CONFIG_DMA_CACHE_RWFO
253 ldr r2, [r0] @ read for ownership
256 mcr p15, 0, r0, c7, c10, 1 @ clean D line
258 mcr p15, 0, r0, c7, c11, 1 @ clean unified line
260 add r0, r0, #D_CACHE_LINE_SIZE
264 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
268 * v6_dma_flush_range(start,end)
269 * - start - virtual start address of region
270 * - end - virtual end address of region
272 ENTRY(v6_dma_flush_range)
273 #ifdef CONFIG_DMA_CACHE_RWFO
274 ldrb r2, [r0] @ read for ownership
275 strb r2, [r0] @ write for ownership
277 bic r0, r0, #D_CACHE_LINE_SIZE - 1
280 mcr p15, 0, r0, c7, c14, 1 @ clean & invalidate D line
282 mcr p15, 0, r0, c7, c15, 1 @ clean & invalidate line
284 add r0, r0, #D_CACHE_LINE_SIZE
286 #ifdef CONFIG_DMA_CACHE_RWFO
287 ldrlob r2, [r0] @ read for ownership
288 strlob r2, [r0] @ write for ownership
292 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
296 * dma_map_area(start, size, dir)
297 * - start - kernel virtual start address
298 * - size - size of region
299 * - dir - DMA direction
301 ENTRY(v6_dma_map_area)
303 teq r2, #DMA_FROM_DEVICE
305 #ifndef CONFIG_DMA_CACHE_RWFO
308 teq r2, #DMA_TO_DEVICE
309 beq v6_dma_clean_range
312 ENDPROC(v6_dma_map_area)
315 * dma_unmap_area(start, size, dir)
316 * - start - kernel virtual start address
317 * - size - size of region
318 * - dir - DMA direction
320 ENTRY(v6_dma_unmap_area)
321 #ifndef CONFIG_DMA_CACHE_RWFO
323 teq r2, #DMA_TO_DEVICE
327 ENDPROC(v6_dma_unmap_area)
329 .globl v6_flush_kern_cache_louis
330 .equ v6_flush_kern_cache_louis, v6_flush_kern_cache_all
334 @ define struct cpu_cache_fns (see <asm/cacheflush.h> and proc-macros.S)
335 define_cache_functions v6