1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * linux/arch/arm/mm/cache-v6.S
5 * Copyright (C) 2001 Deep Blue Solutions Ltd.
7 * This is the "shell" of the ARMv6 processor support.
9 #include <linux/linkage.h>
10 #include <linux/init.h>
11 #include <linux/cfi_types.h>
12 #include <asm/assembler.h>
13 #include <asm/errno.h>
14 #include <asm/unwind.h>
16 #include "proc-macros.S"
19 #define CACHE_LINE_SIZE 32
20 #define D_CACHE_LINE_SIZE 32
21 #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 SYM_TYPED_FUNC_START(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 SYM_FUNC_END(v6_flush_icache_all)
58 * v6_flush_cache_all()
60 * Flush the entire cache.
64 SYM_TYPED_FUNC_START(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
77 SYM_FUNC_END(v6_flush_kern_cache_all)
80 * v6_flush_cache_all()
82 * Flush all TLB entries in a particular address space
84 * - mm - mm_struct describing address space
86 SYM_TYPED_FUNC_START(v6_flush_user_cache_all)
88 SYM_FUNC_END(v6_flush_user_cache_all)
91 * v6_flush_cache_range(start, end, flags)
93 * Flush a range of TLB entries in the specified address space.
95 * - start - start address (may not be aligned)
96 * - end - end address (exclusive, may not be aligned)
97 * - flags - vm_area_struct flags describing address space
100 * - we have a VIPT cache.
102 SYM_TYPED_FUNC_START(v6_flush_user_cache_range)
104 SYM_FUNC_END(v6_flush_user_cache_range)
107 * v6_coherent_kern_range(start,end)
109 * Ensure that the I and D caches are coherent within specified
110 * region. This is typically used when code has been written to
111 * a memory region, and will be executed.
113 * - start - virtual start address of region
114 * - end - virtual end address of region
116 * It is assumed that:
117 * - the Icache does not read data from the write buffer
119 SYM_TYPED_FUNC_START(v6_coherent_kern_range)
120 #ifdef CONFIG_CFI_CLANG /* Fallthrough if !CFI */
121 b v6_coherent_user_range
123 SYM_FUNC_END(v6_coherent_kern_range)
126 * v6_coherent_user_range(start,end)
128 * Ensure that the I and D caches are coherent within specified
129 * region. This is typically used when code has been written to
130 * a memory region, and will be executed.
132 * - start - virtual start address of region
133 * - end - virtual end address of region
135 * It is assumed that:
136 * - the Icache does not read data from the write buffer
138 SYM_TYPED_FUNC_START(v6_coherent_user_range)
141 bic r0, r0, #CACHE_LINE_SIZE - 1
143 USER( mcr p15, 0, r0, c7, c10, 1 ) @ clean D line
144 add r0, r0, #CACHE_LINE_SIZE
150 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
151 #ifndef CONFIG_ARM_ERRATA_411920
152 mcr p15, 0, r0, c7, c5, 0 @ I+BTB cache invalidate
154 b v6_flush_icache_all
157 mcr p15, 0, r0, c7, c5, 6 @ invalidate BTB
162 * Fault handling for the cache operation above. If the virtual address in r0
163 * isn't mapped, fail with -EFAULT.
169 SYM_FUNC_END(v6_coherent_user_range)
172 * v6_flush_kern_dcache_area(void *addr, size_t size)
174 * Ensure that the data held in the page kaddr is written back
175 * to the page in question.
177 * - addr - kernel address
178 * - size - region size
180 SYM_TYPED_FUNC_START(v6_flush_kern_dcache_area)
182 bic r0, r0, #D_CACHE_LINE_SIZE - 1
185 mcr p15, 0, r0, c7, c14, 1 @ clean & invalidate D line
187 mcr p15, 0, r0, c7, c15, 1 @ clean & invalidate unified line
189 add r0, r0, #D_CACHE_LINE_SIZE
194 mcr p15, 0, r0, c7, c10, 4
197 SYM_FUNC_END(v6_flush_kern_dcache_area)
200 * v6_dma_inv_range(start,end)
202 * Invalidate the data cache within the specified region; we will
203 * be performing a DMA operation in this region and we want to
204 * purge old data in the cache.
206 * - start - virtual start address of region
207 * - end - virtual end address of region
210 tst r0, #D_CACHE_LINE_SIZE - 1
211 bic r0, r0, #D_CACHE_LINE_SIZE - 1
213 mcrne p15, 0, r0, c7, c10, 1 @ clean D line
215 mcrne p15, 0, r0, c7, c11, 1 @ clean unified line
217 tst r1, #D_CACHE_LINE_SIZE - 1
218 bic r1, r1, #D_CACHE_LINE_SIZE - 1
220 mcrne p15, 0, r1, c7, c14, 1 @ clean & invalidate D line
222 mcrne p15, 0, r1, c7, c15, 1 @ clean & invalidate unified line
226 mcr p15, 0, r0, c7, c6, 1 @ invalidate D line
228 mcr p15, 0, r0, c7, c7, 1 @ invalidate unified line
230 add r0, r0, #D_CACHE_LINE_SIZE
234 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
238 * v6_dma_clean_range(start,end)
239 * - start - virtual start address of region
240 * - end - virtual end address of region
243 bic r0, r0, #D_CACHE_LINE_SIZE - 1
246 mcr p15, 0, r0, c7, c10, 1 @ clean D line
248 mcr p15, 0, r0, c7, c11, 1 @ clean unified line
250 add r0, r0, #D_CACHE_LINE_SIZE
254 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
258 * v6_dma_flush_range(start,end)
259 * - start - virtual start address of region
260 * - end - virtual end address of region
262 SYM_TYPED_FUNC_START(v6_dma_flush_range)
263 bic r0, r0, #D_CACHE_LINE_SIZE - 1
266 mcr p15, 0, r0, c7, c14, 1 @ clean & invalidate D line
268 mcr p15, 0, r0, c7, c15, 1 @ clean & invalidate line
270 add r0, r0, #D_CACHE_LINE_SIZE
274 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
276 SYM_FUNC_END(v6_dma_flush_range)
279 * dma_map_area(start, size, dir)
280 * - start - kernel virtual start address
281 * - size - size of region
282 * - dir - DMA direction
284 SYM_TYPED_FUNC_START(v6_dma_map_area)
286 teq r2, #DMA_FROM_DEVICE
289 SYM_FUNC_END(v6_dma_map_area)
292 * dma_unmap_area(start, size, dir)
293 * - start - kernel virtual start address
294 * - size - size of region
295 * - dir - DMA direction
297 SYM_TYPED_FUNC_START(v6_dma_unmap_area)
299 teq r2, #DMA_TO_DEVICE
302 SYM_FUNC_END(v6_dma_unmap_area)