2 * linux/arch/arm/mm/cache-v7.S
4 * Copyright (C) 2001 Deep Blue Solutions Ltd.
5 * Copyright (C) 2005 ARM Ltd.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This is the "shell" of the ARMv7 processor support.
13 #include <linux/linkage.h>
14 #include <linux/init.h>
15 #include <asm/assembler.h>
16 #include <asm/errno.h>
17 #include <asm/unwind.h>
19 #include "proc-macros.S"
22 * v7_flush_icache_all()
24 * Flush the whole I-cache.
29 ENTRY(v7_flush_icache_all)
31 ALT_SMP(mcr p15, 0, r0, c7, c1, 0) @ invalidate I-cache inner shareable
32 ALT_UP(mcr p15, 0, r0, c7, c5, 0) @ I+BTB cache invalidate
34 ENDPROC(v7_flush_icache_all)
37 * v7_flush_dcache_louis()
39 * Flush the D-cache up to the Level of Unification Inner Shareable
41 * Corrupted registers: r0-r7, r9-r11 (r6 only in Thumb mode)
44 ENTRY(v7_flush_dcache_louis)
45 dmb @ ensure ordering with previous memory accesses
46 mrc p15, 1, r0, c0, c0, 1 @ read clidr, r0 = clidr
47 ands r3, r0, #0xe00000 @ extract LoUIS from clidr
48 mov r3, r3, lsr #20 @ r3 = LoUIS * 2
49 moveq pc, lr @ return if level == 0
50 mov r10, #0 @ r10 (starting level) = 0
51 b flush_levels @ start flushing cache levels
52 ENDPROC(v7_flush_dcache_louis)
55 * v7_flush_dcache_all()
57 * Flush the whole D-cache.
59 * Corrupted registers: r0-r7, r9-r11 (r6 only in Thumb mode)
61 * - mm - mm_struct describing address space
63 ENTRY(v7_flush_dcache_all)
64 dmb @ ensure ordering with previous memory accesses
65 mrc p15, 1, r0, c0, c0, 1 @ read clidr
66 ands r3, r0, #0x7000000 @ extract loc from clidr
67 mov r3, r3, lsr #23 @ left align loc bit field
68 beq finished @ if loc is 0, then no need to clean
69 mov r10, #0 @ start clean at cache level 0
71 add r2, r10, r10, lsr #1 @ work out 3x current cache level
72 mov r1, r0, lsr r2 @ extract cache type bits from clidr
73 and r1, r1, #7 @ mask of the bits for current cache only
74 cmp r1, #2 @ see what cache we have at this level
75 blt skip @ skip if no cache, or just i-cache
77 save_and_disable_irqs_notrace r9 @ make cssr&csidr read atomic
79 mcr p15, 2, r10, c0, c0, 0 @ select current cache level in cssr
80 isb @ isb to sych the new cssr&csidr
81 mrc p15, 1, r1, c0, c0, 0 @ read the new csidr
83 restore_irqs_notrace r9
85 and r2, r1, #7 @ extract the length of the cache lines
86 add r2, r2, #4 @ add 4 (line length offset)
88 ands r4, r4, r1, lsr #3 @ find maximum number on the way size
89 clz r5, r4 @ find bit position of way size increment
91 ands r7, r7, r1, lsr #13 @ extract max number of the index size
93 mov r9, r4 @ create working copy of max way size
95 ARM( orr r11, r10, r9, lsl r5 ) @ factor way and cache number into r11
96 THUMB( lsl r6, r9, r5 )
97 THUMB( orr r11, r10, r6 ) @ factor way and cache number into r11
98 ARM( orr r11, r11, r7, lsl r2 ) @ factor index number into r11
99 THUMB( lsl r6, r7, r2 )
100 THUMB( orr r11, r11, r6 ) @ factor index number into r11
101 mcr p15, 0, r11, c7, c14, 2 @ clean & invalidate by set/way
102 subs r9, r9, #1 @ decrement the way
104 subs r7, r7, #1 @ decrement the index
107 add r10, r10, #2 @ increment cache number
111 mov r10, #0 @ swith back to cache level 0
112 mcr p15, 2, r10, c0, c0, 0 @ select current cache level in cssr
116 ENDPROC(v7_flush_dcache_all)
119 * v7_flush_cache_all()
121 * Flush the entire cache system.
122 * The data cache flush is now achieved using atomic clean / invalidates
123 * working outwards from L1 cache. This is done using Set/Way based cache
124 * maintenance instructions.
125 * The instruction cache can still be invalidated back to the point of
126 * unification in a single instruction.
129 ENTRY(v7_flush_kern_cache_all)
130 ARM( stmfd sp!, {r4-r5, r7, r9-r11, lr} )
131 THUMB( stmfd sp!, {r4-r7, r9-r11, lr} )
132 bl v7_flush_dcache_all
134 ALT_SMP(mcr p15, 0, r0, c7, c1, 0) @ invalidate I-cache inner shareable
135 ALT_UP(mcr p15, 0, r0, c7, c5, 0) @ I+BTB cache invalidate
136 ARM( ldmfd sp!, {r4-r5, r7, r9-r11, lr} )
137 THUMB( ldmfd sp!, {r4-r7, r9-r11, lr} )
139 ENDPROC(v7_flush_kern_cache_all)
142 * v7_flush_kern_cache_louis(void)
144 * Flush the data cache up to Level of Unification Inner Shareable.
145 * Invalidate the I-cache to the point of unification.
147 ENTRY(v7_flush_kern_cache_louis)
148 ARM( stmfd sp!, {r4-r5, r7, r9-r11, lr} )
149 THUMB( stmfd sp!, {r4-r7, r9-r11, lr} )
150 bl v7_flush_dcache_louis
152 ALT_SMP(mcr p15, 0, r0, c7, c1, 0) @ invalidate I-cache inner shareable
153 ALT_UP(mcr p15, 0, r0, c7, c5, 0) @ I+BTB cache invalidate
154 ARM( ldmfd sp!, {r4-r5, r7, r9-r11, lr} )
155 THUMB( ldmfd sp!, {r4-r7, r9-r11, lr} )
157 ENDPROC(v7_flush_kern_cache_louis)
160 * v7_flush_cache_all()
162 * Flush all TLB entries in a particular address space
164 * - mm - mm_struct describing address space
166 ENTRY(v7_flush_user_cache_all)
170 * v7_flush_cache_range(start, end, flags)
172 * Flush a range of TLB entries in the specified address space.
174 * - start - start address (may not be aligned)
175 * - end - end address (exclusive, may not be aligned)
176 * - flags - vm_area_struct flags describing address space
178 * It is assumed that:
179 * - we have a VIPT cache.
181 ENTRY(v7_flush_user_cache_range)
183 ENDPROC(v7_flush_user_cache_all)
184 ENDPROC(v7_flush_user_cache_range)
187 * v7_coherent_kern_range(start,end)
189 * Ensure that the I and D caches are coherent within specified
190 * region. This is typically used when code has been written to
191 * a memory region, and will be executed.
193 * - start - virtual start address of region
194 * - end - virtual end address of region
196 * It is assumed that:
197 * - the Icache does not read data from the write buffer
199 ENTRY(v7_coherent_kern_range)
203 * v7_coherent_user_range(start,end)
205 * Ensure that the I and D caches are coherent within specified
206 * region. This is typically used when code has been written to
207 * a memory region, and will be executed.
209 * - start - virtual start address of region
210 * - end - virtual end address of region
212 * It is assumed that:
213 * - the Icache does not read data from the write buffer
215 ENTRY(v7_coherent_user_range)
217 dcache_line_size r2, r3
220 #ifdef CONFIG_ARM_ERRATA_764369
225 USER( mcr p15, 0, r12, c7, c11, 1 ) @ clean D line to the point of unification
230 icache_line_size r2, r3
234 USER( mcr p15, 0, r12, c7, c5, 1 ) @ invalidate I line
239 ALT_SMP(mcr p15, 0, r0, c7, c1, 6) @ invalidate BTB Inner Shareable
240 ALT_UP(mcr p15, 0, r0, c7, c5, 6) @ invalidate BTB
246 * Fault handling for the cache operation above. If the virtual address in r0
247 * isn't mapped, fail with -EFAULT.
250 #ifdef CONFIG_ARM_ERRATA_775420
256 ENDPROC(v7_coherent_kern_range)
257 ENDPROC(v7_coherent_user_range)
260 * v7_flush_kern_dcache_area(void *addr, size_t size)
262 * Ensure that the data held in the page kaddr is written back
263 * to the page in question.
265 * - addr - kernel address
266 * - size - region size
268 ENTRY(v7_flush_kern_dcache_area)
269 dcache_line_size r2, r3
273 #ifdef CONFIG_ARM_ERRATA_764369
278 mcr p15, 0, r0, c7, c14, 1 @ clean & invalidate D line / unified line
284 ENDPROC(v7_flush_kern_dcache_area)
287 * v7_dma_inv_range(start,end)
289 * Invalidate the data cache within the specified region; we will
290 * be performing a DMA operation in this region and we want to
291 * purge old data in the cache.
293 * - start - virtual start address of region
294 * - end - virtual end address of region
297 dcache_line_size r2, r3
301 #ifdef CONFIG_ARM_ERRATA_764369
305 mcrne p15, 0, r0, c7, c14, 1 @ clean & invalidate D / U line
309 mcrne p15, 0, r1, c7, c14, 1 @ clean & invalidate D / U line
311 mcr p15, 0, r0, c7, c6, 1 @ invalidate D / U line
317 ENDPROC(v7_dma_inv_range)
320 * v7_dma_clean_range(start,end)
321 * - start - virtual start address of region
322 * - end - virtual end address of region
325 dcache_line_size r2, r3
328 #ifdef CONFIG_ARM_ERRATA_764369
333 mcr p15, 0, r0, c7, c10, 1 @ clean D / U line
339 ENDPROC(v7_dma_clean_range)
342 * v7_dma_flush_range(start,end)
343 * - start - virtual start address of region
344 * - end - virtual end address of region
346 ENTRY(v7_dma_flush_range)
347 dcache_line_size r2, r3
350 #ifdef CONFIG_ARM_ERRATA_764369
355 mcr p15, 0, r0, c7, c14, 1 @ clean & invalidate D / U line
361 ENDPROC(v7_dma_flush_range)
364 * dma_map_area(start, size, dir)
365 * - start - kernel virtual start address
366 * - size - size of region
367 * - dir - DMA direction
369 ENTRY(v7_dma_map_area)
371 teq r2, #DMA_FROM_DEVICE
374 ENDPROC(v7_dma_map_area)
377 * dma_unmap_area(start, size, dir)
378 * - start - kernel virtual start address
379 * - size - size of region
380 * - dir - DMA direction
382 ENTRY(v7_dma_unmap_area)
384 teq r2, #DMA_TO_DEVICE
387 ENDPROC(v7_dma_unmap_area)
391 @ define struct cpu_cache_fns (see <asm/cacheflush.h> and proc-macros.S)
392 define_cache_functions v7