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 ALT_SMP(ands r3, r0, #(7 << 21)) @ extract LoUIS from clidr
48 ALT_UP(ands r3, r0, #(7 << 27)) @ extract LoUU from clidr
49 ALT_SMP(mov r3, r3, lsr #20) @ r3 = LoUIS * 2
50 ALT_UP(mov r3, r3, lsr #26) @ r3 = LoUU * 2
51 moveq pc, lr @ return if level == 0
52 mov r10, #0 @ r10 (starting level) = 0
53 b flush_levels @ start flushing cache levels
54 ENDPROC(v7_flush_dcache_louis)
57 * v7_flush_dcache_all()
59 * Flush the whole D-cache.
61 * Corrupted registers: r0-r7, r9-r11 (r6 only in Thumb mode)
63 * - mm - mm_struct describing address space
65 ENTRY(v7_flush_dcache_all)
66 dmb @ ensure ordering with previous memory accesses
67 mrc p15, 1, r0, c0, c0, 1 @ read clidr
68 ands r3, r0, #0x7000000 @ extract loc from clidr
69 mov r3, r3, lsr #23 @ left align loc bit field
70 beq finished @ if loc is 0, then no need to clean
71 mov r10, #0 @ start clean at cache level 0
73 add r2, r10, r10, lsr #1 @ work out 3x current cache level
74 mov r1, r0, lsr r2 @ extract cache type bits from clidr
75 and r1, r1, #7 @ mask of the bits for current cache only
76 cmp r1, #2 @ see what cache we have at this level
77 blt skip @ skip if no cache, or just i-cache
79 save_and_disable_irqs_notrace r9 @ make cssr&csidr read atomic
81 mcr p15, 2, r10, c0, c0, 0 @ select current cache level in cssr
82 isb @ isb to sych the new cssr&csidr
83 mrc p15, 1, r1, c0, c0, 0 @ read the new csidr
85 restore_irqs_notrace r9
87 and r2, r1, #7 @ extract the length of the cache lines
88 add r2, r2, #4 @ add 4 (line length offset)
90 ands r4, r4, r1, lsr #3 @ find maximum number on the way size
91 clz r5, r4 @ find bit position of way size increment
93 ands r7, r7, r1, lsr #13 @ extract max number of the index size
95 mov r9, r4 @ create working copy of max way size
97 ARM( orr r11, r10, r9, lsl r5 ) @ factor way and cache number into r11
98 THUMB( lsl r6, r9, r5 )
99 THUMB( orr r11, r10, r6 ) @ factor way and cache number into r11
100 ARM( orr r11, r11, r7, lsl r2 ) @ factor index number into r11
101 THUMB( lsl r6, r7, r2 )
102 THUMB( orr r11, r11, r6 ) @ factor index number into r11
103 mcr p15, 0, r11, c7, c14, 2 @ clean & invalidate by set/way
104 subs r9, r9, #1 @ decrement the way
106 subs r7, r7, #1 @ decrement the index
109 add r10, r10, #2 @ increment cache number
113 mov r10, #0 @ swith back to cache level 0
114 mcr p15, 2, r10, c0, c0, 0 @ select current cache level in cssr
118 ENDPROC(v7_flush_dcache_all)
121 * v7_flush_cache_all()
123 * Flush the entire cache system.
124 * The data cache flush is now achieved using atomic clean / invalidates
125 * working outwards from L1 cache. This is done using Set/Way based cache
126 * maintenance instructions.
127 * The instruction cache can still be invalidated back to the point of
128 * unification in a single instruction.
131 ENTRY(v7_flush_kern_cache_all)
132 ARM( stmfd sp!, {r4-r5, r7, r9-r11, lr} )
133 THUMB( stmfd sp!, {r4-r7, r9-r11, lr} )
134 bl v7_flush_dcache_all
136 ALT_SMP(mcr p15, 0, r0, c7, c1, 0) @ invalidate I-cache inner shareable
137 ALT_UP(mcr p15, 0, r0, c7, c5, 0) @ I+BTB cache invalidate
138 ARM( ldmfd sp!, {r4-r5, r7, r9-r11, lr} )
139 THUMB( ldmfd sp!, {r4-r7, r9-r11, lr} )
141 ENDPROC(v7_flush_kern_cache_all)
144 * v7_flush_kern_cache_louis(void)
146 * Flush the data cache up to Level of Unification Inner Shareable.
147 * Invalidate the I-cache to the point of unification.
149 ENTRY(v7_flush_kern_cache_louis)
150 ARM( stmfd sp!, {r4-r5, r7, r9-r11, lr} )
151 THUMB( stmfd sp!, {r4-r7, r9-r11, lr} )
152 bl v7_flush_dcache_louis
154 ALT_SMP(mcr p15, 0, r0, c7, c1, 0) @ invalidate I-cache inner shareable
155 ALT_UP(mcr p15, 0, r0, c7, c5, 0) @ I+BTB cache invalidate
156 ARM( ldmfd sp!, {r4-r5, r7, r9-r11, lr} )
157 THUMB( ldmfd sp!, {r4-r7, r9-r11, lr} )
159 ENDPROC(v7_flush_kern_cache_louis)
162 * v7_flush_cache_all()
164 * Flush all TLB entries in a particular address space
166 * - mm - mm_struct describing address space
168 ENTRY(v7_flush_user_cache_all)
172 * v7_flush_cache_range(start, end, flags)
174 * Flush a range of TLB entries in the specified address space.
176 * - start - start address (may not be aligned)
177 * - end - end address (exclusive, may not be aligned)
178 * - flags - vm_area_struct flags describing address space
180 * It is assumed that:
181 * - we have a VIPT cache.
183 ENTRY(v7_flush_user_cache_range)
185 ENDPROC(v7_flush_user_cache_all)
186 ENDPROC(v7_flush_user_cache_range)
189 * v7_coherent_kern_range(start,end)
191 * Ensure that the I and D caches are coherent within specified
192 * region. This is typically used when code has been written to
193 * a memory region, and will be executed.
195 * - start - virtual start address of region
196 * - end - virtual end address of region
198 * It is assumed that:
199 * - the Icache does not read data from the write buffer
201 ENTRY(v7_coherent_kern_range)
205 * v7_coherent_user_range(start,end)
207 * Ensure that the I and D caches are coherent within specified
208 * region. This is typically used when code has been written to
209 * a memory region, and will be executed.
211 * - start - virtual start address of region
212 * - end - virtual end address of region
214 * It is assumed that:
215 * - the Icache does not read data from the write buffer
217 ENTRY(v7_coherent_user_range)
219 dcache_line_size r2, r3
222 #ifdef CONFIG_ARM_ERRATA_764369
227 USER( mcr p15, 0, r12, c7, c11, 1 ) @ clean D line to the point of unification
232 icache_line_size r2, r3
236 USER( mcr p15, 0, r12, c7, c5, 1 ) @ invalidate I line
241 ALT_SMP(mcr p15, 0, r0, c7, c1, 6) @ invalidate BTB Inner Shareable
242 ALT_UP(mcr p15, 0, r0, c7, c5, 6) @ invalidate BTB
248 * Fault handling for the cache operation above. If the virtual address in r0
249 * isn't mapped, fail with -EFAULT.
252 #ifdef CONFIG_ARM_ERRATA_775420
258 ENDPROC(v7_coherent_kern_range)
259 ENDPROC(v7_coherent_user_range)
262 * v7_flush_kern_dcache_area(void *addr, size_t size)
264 * Ensure that the data held in the page kaddr is written back
265 * to the page in question.
267 * - addr - kernel address
268 * - size - region size
270 ENTRY(v7_flush_kern_dcache_area)
271 dcache_line_size r2, r3
275 #ifdef CONFIG_ARM_ERRATA_764369
280 mcr p15, 0, r0, c7, c14, 1 @ clean & invalidate D line / unified line
286 ENDPROC(v7_flush_kern_dcache_area)
289 * v7_dma_inv_range(start,end)
291 * Invalidate the data cache within the specified region; we will
292 * be performing a DMA operation in this region and we want to
293 * purge old data in the cache.
295 * - start - virtual start address of region
296 * - end - virtual end address of region
299 dcache_line_size r2, r3
303 #ifdef CONFIG_ARM_ERRATA_764369
307 mcrne p15, 0, r0, c7, c14, 1 @ clean & invalidate D / U line
311 mcrne p15, 0, r1, c7, c14, 1 @ clean & invalidate D / U line
313 mcr p15, 0, r0, c7, c6, 1 @ invalidate D / U line
319 ENDPROC(v7_dma_inv_range)
322 * v7_dma_clean_range(start,end)
323 * - start - virtual start address of region
324 * - end - virtual end address of region
327 dcache_line_size r2, r3
330 #ifdef CONFIG_ARM_ERRATA_764369
335 mcr p15, 0, r0, c7, c10, 1 @ clean D / U line
341 ENDPROC(v7_dma_clean_range)
344 * v7_dma_flush_range(start,end)
345 * - start - virtual start address of region
346 * - end - virtual end address of region
348 ENTRY(v7_dma_flush_range)
349 dcache_line_size r2, r3
352 #ifdef CONFIG_ARM_ERRATA_764369
357 mcr p15, 0, r0, c7, c14, 1 @ clean & invalidate D / U line
363 ENDPROC(v7_dma_flush_range)
366 * dma_map_area(start, size, dir)
367 * - start - kernel virtual start address
368 * - size - size of region
369 * - dir - DMA direction
371 ENTRY(v7_dma_map_area)
373 teq r2, #DMA_FROM_DEVICE
376 ENDPROC(v7_dma_map_area)
379 * dma_unmap_area(start, size, dir)
380 * - start - kernel virtual start address
381 * - size - size of region
382 * - dir - DMA direction
384 ENTRY(v7_dma_unmap_area)
386 teq r2, #DMA_TO_DEVICE
389 ENDPROC(v7_dma_unmap_area)
393 @ define struct cpu_cache_fns (see <asm/cacheflush.h> and proc-macros.S)
394 define_cache_functions v7