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/unwind.h>
17 #include "proc-macros.S"
20 #define CACHE_LINE_SIZE 32
21 #define D_CACHE_LINE_SIZE 32
22 #define BTB_FLUSH_SIZE 8
25 * v6_flush_icache_all()
27 * Flush the whole I-cache.
29 * ARM1136 erratum 411920 - Invalidate Instruction Cache operation can fail.
30 * This erratum is present in 1136, 1156 and 1176. It does not affect the
37 ENTRY(v6_flush_icache_all)
39 #ifdef CONFIG_ARM_ERRATA_411920
41 cpsid ifa @ disable interrupts
42 mcr p15, 0, r0, c7, c5, 0 @ invalidate entire I-cache
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 msr cpsr_cx, r1 @ restore interrupts
47 .rept 11 @ ARM Ltd recommends at least
51 mcr p15, 0, r0, c7, c5, 0 @ invalidate I-cache
54 ENDPROC(v6_flush_icache_all)
57 * v6_flush_cache_all()
59 * Flush the entire cache.
63 ENTRY(v6_flush_kern_cache_all)
66 mcr p15, 0, r0, c7, c14, 0 @ D cache clean+invalidate
67 #ifndef CONFIG_ARM_ERRATA_411920
68 mcr p15, 0, r0, c7, c5, 0 @ I+BTB cache invalidate
73 mcr p15, 0, r0, c7, c15, 0 @ Cache clean+invalidate
78 * v6_flush_cache_all()
80 * Flush all TLB entries in a particular address space
82 * - mm - mm_struct describing address space
84 ENTRY(v6_flush_user_cache_all)
88 * v6_flush_cache_range(start, end, flags)
90 * Flush a range of TLB entries in the specified address space.
92 * - start - start address (may not be aligned)
93 * - end - end address (exclusive, may not be aligned)
94 * - flags - vm_area_struct flags describing address space
97 * - we have a VIPT cache.
99 ENTRY(v6_flush_user_cache_range)
103 * v6_coherent_kern_range(start,end)
105 * Ensure that the I and D caches are coherent within specified
106 * region. This is typically used when code has been written to
107 * a memory region, and will be executed.
109 * - start - virtual start address of region
110 * - end - virtual end address of region
112 * It is assumed that:
113 * - the Icache does not read data from the write buffer
115 ENTRY(v6_coherent_kern_range)
119 * v6_coherent_user_range(start,end)
121 * Ensure that the I and D caches are coherent within specified
122 * region. This is typically used when code has been written to
123 * a memory region, and will be executed.
125 * - start - virtual start address of region
126 * - end - virtual end address of region
128 * It is assumed that:
129 * - the Icache does not read data from the write buffer
131 ENTRY(v6_coherent_user_range)
134 bic r0, r0, #CACHE_LINE_SIZE - 1
136 USER( mcr p15, 0, r0, c7, c10, 1 ) @ clean D line
137 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, just try the next page.
165 ENDPROC(v6_coherent_user_range)
166 ENDPROC(v6_coherent_kern_range)
169 * v6_flush_kern_dcache_area(void *addr, size_t size)
171 * Ensure that the data held in the page kaddr is written back
172 * to the page in question.
174 * - addr - kernel address
175 * - size - region size
177 ENTRY(v6_flush_kern_dcache_area)
179 bic r0, r0, #D_CACHE_LINE_SIZE - 1
182 mcr p15, 0, r0, c7, c14, 1 @ clean & invalidate D line
184 mcr p15, 0, r0, c7, c15, 1 @ clean & invalidate unified line
186 add r0, r0, #D_CACHE_LINE_SIZE
191 mcr p15, 0, r0, c7, c10, 4
197 * v6_dma_inv_range(start,end)
199 * Invalidate the data cache within the specified region; we will
200 * be performing a DMA operation in this region and we want to
201 * purge old data in the cache.
203 * - start - virtual start address of region
204 * - end - virtual end address of region
207 #ifdef CONFIG_DMA_CACHE_RWFO
208 ldrb r2, [r0] @ read for ownership
209 strb r2, [r0] @ write for ownership
211 tst r0, #D_CACHE_LINE_SIZE - 1
212 bic r0, r0, #D_CACHE_LINE_SIZE - 1
214 mcrne p15, 0, r0, c7, c10, 1 @ clean D line
216 mcrne p15, 0, r0, c7, c11, 1 @ clean unified line
218 tst r1, #D_CACHE_LINE_SIZE - 1
219 #ifdef CONFIG_DMA_CACHE_RWFO
220 ldrneb r2, [r1, #-1] @ read for ownership
221 strneb r2, [r1, #-1] @ write for ownership
223 bic r1, r1, #D_CACHE_LINE_SIZE - 1
225 mcrne p15, 0, r1, c7, c14, 1 @ clean & invalidate D line
227 mcrne p15, 0, r1, c7, c15, 1 @ clean & invalidate unified line
231 mcr p15, 0, r0, c7, c6, 1 @ invalidate D line
233 mcr p15, 0, r0, c7, c7, 1 @ invalidate unified line
235 add r0, r0, #D_CACHE_LINE_SIZE
237 #ifdef CONFIG_DMA_CACHE_RWFO
238 ldrlo r2, [r0] @ read for ownership
239 strlo r2, [r0] @ write for ownership
243 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
247 * v6_dma_clean_range(start,end)
248 * - start - virtual start address of region
249 * - end - virtual end address of region
252 bic r0, r0, #D_CACHE_LINE_SIZE - 1
254 #ifdef CONFIG_DMA_CACHE_RWFO
255 ldr r2, [r0] @ read for ownership
258 mcr p15, 0, r0, c7, c10, 1 @ clean D line
260 mcr p15, 0, r0, c7, c11, 1 @ clean unified line
262 add r0, r0, #D_CACHE_LINE_SIZE
266 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
270 * v6_dma_flush_range(start,end)
271 * - start - virtual start address of region
272 * - end - virtual end address of region
274 ENTRY(v6_dma_flush_range)
275 #ifdef CONFIG_DMA_CACHE_RWFO
276 ldrb r2, [r0] @ read for ownership
277 strb r2, [r0] @ write for ownership
279 bic r0, r0, #D_CACHE_LINE_SIZE - 1
282 mcr p15, 0, r0, c7, c14, 1 @ clean & invalidate D line
284 mcr p15, 0, r0, c7, c15, 1 @ clean & invalidate line
286 add r0, r0, #D_CACHE_LINE_SIZE
288 #ifdef CONFIG_DMA_CACHE_RWFO
289 ldrlob r2, [r0] @ read for ownership
290 strlob r2, [r0] @ write for ownership
294 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
298 * dma_map_area(start, size, dir)
299 * - start - kernel virtual start address
300 * - size - size of region
301 * - dir - DMA direction
303 ENTRY(v6_dma_map_area)
305 teq r2, #DMA_FROM_DEVICE
307 #ifndef CONFIG_DMA_CACHE_RWFO
310 teq r2, #DMA_TO_DEVICE
311 beq v6_dma_clean_range
314 ENDPROC(v6_dma_map_area)
317 * dma_unmap_area(start, size, dir)
318 * - start - kernel virtual start address
319 * - size - size of region
320 * - dir - DMA direction
322 ENTRY(v6_dma_unmap_area)
323 #ifndef CONFIG_DMA_CACHE_RWFO
325 teq r2, #DMA_TO_DEVICE
329 ENDPROC(v6_dma_unmap_area)
333 .type v6_cache_fns, #object
335 .long v6_flush_icache_all
336 .long v6_flush_kern_cache_all
337 .long v6_flush_user_cache_all
338 .long v6_flush_user_cache_range
339 .long v6_coherent_kern_range
340 .long v6_coherent_user_range
341 .long v6_flush_kern_dcache_area
342 .long v6_dma_map_area
343 .long v6_dma_unmap_area
344 .long v6_dma_flush_range
345 .size v6_cache_fns, . - v6_cache_fns