blob: f0f65eb073e481e082e216f846c7aebf20d0e279 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * linux/arch/arm/mm/cache-v6.S
4 *
5 * Copyright (C) 2001 Deep Blue Solutions Ltd.
6 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * This is the "shell" of the ARMv6 processor support.
8 */
9#include <linux/linkage.h>
10#include <linux/init.h>
11#include <asm/assembler.h>
Will Deaconc5102f52012-04-27 13:08:53 +010012#include <asm/errno.h>
Catalin Marinas32cfb1b2009-10-06 17:57:09 +010013#include <asm/unwind.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
15#include "proc-macros.S"
16
17#define HARVARD_CACHE
18#define CACHE_LINE_SIZE 32
19#define D_CACHE_LINE_SIZE 32
Gen FUKATSU217874f2005-09-30 16:09:17 +010020#define BTB_FLUSH_SIZE 8
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
Catalin Marinas9cba3cc2009-04-30 17:06:03 +010022/*
Tony Lindgren81d11952010-09-21 17:16:40 +010023 * v6_flush_icache_all()
Catalin Marinas9cba3cc2009-04-30 17:06:03 +010024 *
Tony Lindgren81d11952010-09-21 17:16:40 +010025 * Flush the whole I-cache.
26 *
27 * ARM1136 erratum 411920 - Invalidate Instruction Cache operation can fail.
28 * This erratum is present in 1136, 1156 and 1176. It does not affect the
29 * MPCore.
30 *
31 * Registers:
32 * r0 - set to 0
33 * r1 - corrupted
Catalin Marinas9cba3cc2009-04-30 17:06:03 +010034 */
Tony Lindgren81d11952010-09-21 17:16:40 +010035ENTRY(v6_flush_icache_all)
Catalin Marinas9cba3cc2009-04-30 17:06:03 +010036 mov r0, #0
Tony Lindgren81d11952010-09-21 17:16:40 +010037#ifdef CONFIG_ARM_ERRATA_411920
Catalin Marinas9cba3cc2009-04-30 17:06:03 +010038 mrs r1, cpsr
39 cpsid ifa @ disable interrupts
40 mcr p15, 0, r0, c7, c5, 0 @ invalidate entire I-cache
41 mcr p15, 0, r0, c7, c5, 0 @ invalidate entire I-cache
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 msr cpsr_cx, r1 @ restore interrupts
45 .rept 11 @ ARM Ltd recommends at least
46 nop @ 11 NOPs
47 .endr
Tony Lindgren81d11952010-09-21 17:16:40 +010048#else
49 mcr p15, 0, r0, c7, c5, 0 @ invalidate I-cache
Catalin Marinas9cba3cc2009-04-30 17:06:03 +010050#endif
Russell King6ebbf2c2014-06-30 16:29:12 +010051 ret lr
Tony Lindgren81d11952010-09-21 17:16:40 +010052ENDPROC(v6_flush_icache_all)
Catalin Marinas9cba3cc2009-04-30 17:06:03 +010053
Linus Torvalds1da177e2005-04-16 15:20:36 -070054/*
55 * v6_flush_cache_all()
56 *
57 * Flush the entire cache.
58 *
59 * It is assumed that:
60 */
61ENTRY(v6_flush_kern_cache_all)
62 mov r0, #0
63#ifdef HARVARD_CACHE
64 mcr p15, 0, r0, c7, c14, 0 @ D cache clean+invalidate
Catalin Marinas9cba3cc2009-04-30 17:06:03 +010065#ifndef CONFIG_ARM_ERRATA_411920
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 mcr p15, 0, r0, c7, c5, 0 @ I+BTB cache invalidate
67#else
Tony Lindgren81d11952010-09-21 17:16:40 +010068 b v6_flush_icache_all
Catalin Marinas9cba3cc2009-04-30 17:06:03 +010069#endif
70#else
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 mcr p15, 0, r0, c7, c15, 0 @ Cache clean+invalidate
72#endif
Russell King6ebbf2c2014-06-30 16:29:12 +010073 ret lr
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
75/*
76 * v6_flush_cache_all()
77 *
78 * Flush all TLB entries in a particular address space
79 *
80 * - mm - mm_struct describing address space
81 */
82ENTRY(v6_flush_user_cache_all)
83 /*FALLTHROUGH*/
84
85/*
86 * v6_flush_cache_range(start, end, flags)
87 *
88 * Flush a range of TLB entries in the specified address space.
89 *
90 * - start - start address (may not be aligned)
91 * - end - end address (exclusive, may not be aligned)
92 * - flags - vm_area_struct flags describing address space
93 *
94 * It is assumed that:
95 * - we have a VIPT cache.
96 */
97ENTRY(v6_flush_user_cache_range)
Russell King6ebbf2c2014-06-30 16:29:12 +010098 ret lr
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
100/*
101 * v6_coherent_kern_range(start,end)
102 *
103 * Ensure that the I and D caches are coherent within specified
104 * region. This is typically used when code has been written to
105 * a memory region, and will be executed.
106 *
107 * - start - virtual start address of region
108 * - end - virtual end address of region
109 *
110 * It is assumed that:
111 * - the Icache does not read data from the write buffer
112 */
113ENTRY(v6_coherent_kern_range)
114 /* FALLTHROUGH */
115
116/*
117 * v6_coherent_user_range(start,end)
118 *
119 * Ensure that the I and D caches are coherent within specified
120 * region. This is typically used when code has been written to
121 * a memory region, and will be executed.
122 *
123 * - start - virtual start address of region
124 * - end - virtual end address of region
125 *
126 * It is assumed that:
127 * - the Icache does not read data from the write buffer
128 */
129ENTRY(v6_coherent_user_range)
Catalin Marinas32cfb1b2009-10-06 17:57:09 +0100130 UNWIND(.fnstart )
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131#ifdef HARVARD_CACHE
Nicolas Pitre18afea02006-02-01 19:26:01 +0000132 bic r0, r0, #CACHE_LINE_SIZE - 1
Catalin Marinas32cfb1b2009-10-06 17:57:09 +01001331:
134 USER( mcr p15, 0, r0, c7, c10, 1 ) @ clean D line
Nicolas Pitre18afea02006-02-01 19:26:01 +0000135 add r0, r0, #CACHE_LINE_SIZE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 cmp r0, r1
137 blo 1b
Nicolas Pitre18afea02006-02-01 19:26:01 +0000138#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 mov r0, #0
Catalin Marinas141fa402006-03-10 22:26:47 +0000140#ifdef HARVARD_CACHE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
Catalin Marinas9cba3cc2009-04-30 17:06:03 +0100142#ifndef CONFIG_ARM_ERRATA_411920
Catalin Marinas141fa402006-03-10 22:26:47 +0000143 mcr p15, 0, r0, c7, c5, 0 @ I+BTB cache invalidate
144#else
Tony Lindgren81d11952010-09-21 17:16:40 +0100145 b v6_flush_icache_all
Catalin Marinas9cba3cc2009-04-30 17:06:03 +0100146#endif
147#else
Catalin Marinas141fa402006-03-10 22:26:47 +0000148 mcr p15, 0, r0, c7, c5, 6 @ invalidate BTB
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149#endif
Russell King6ebbf2c2014-06-30 16:29:12 +0100150 ret lr
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
152/*
Catalin Marinas32cfb1b2009-10-06 17:57:09 +0100153 * Fault handling for the cache operation above. If the virtual address in r0
Will Deaconc5102f52012-04-27 13:08:53 +0100154 * isn't mapped, fail with -EFAULT.
Catalin Marinas32cfb1b2009-10-06 17:57:09 +0100155 */
1569001:
Will Deaconc5102f52012-04-27 13:08:53 +0100157 mov r0, #-EFAULT
Russell King6ebbf2c2014-06-30 16:29:12 +0100158 ret lr
Catalin Marinas32cfb1b2009-10-06 17:57:09 +0100159 UNWIND(.fnend )
160ENDPROC(v6_coherent_user_range)
161ENDPROC(v6_coherent_kern_range)
162
163/*
Russell King2c9b9c82009-11-26 12:56:21 +0000164 * v6_flush_kern_dcache_area(void *addr, size_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 *
166 * Ensure that the data held in the page kaddr is written back
167 * to the page in question.
168 *
Russell King2c9b9c82009-11-26 12:56:21 +0000169 * - addr - kernel address
170 * - size - region size
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 */
Russell King2c9b9c82009-11-26 12:56:21 +0000172ENTRY(v6_flush_kern_dcache_area)
173 add r1, r0, r1
Will Deacona248b132011-05-26 11:20:19 +0100174 bic r0, r0, #D_CACHE_LINE_SIZE - 1
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751:
176#ifdef HARVARD_CACHE
177 mcr p15, 0, r0, c7, c14, 1 @ clean & invalidate D line
178#else
179 mcr p15, 0, r0, c7, c15, 1 @ clean & invalidate unified line
180#endif
181 add r0, r0, #D_CACHE_LINE_SIZE
182 cmp r0, r1
183 blo 1b
184#ifdef HARVARD_CACHE
185 mov r0, #0
186 mcr p15, 0, r0, c7, c10, 4
187#endif
Russell King6ebbf2c2014-06-30 16:29:12 +0100188 ret lr
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
190
191/*
192 * v6_dma_inv_range(start,end)
193 *
194 * Invalidate the data cache within the specified region; we will
195 * be performing a DMA operation in this region and we want to
196 * purge old data in the cache.
197 *
198 * - start - virtual start address of region
199 * - end - virtual end address of region
200 */
Russell King702b94b2009-11-26 16:24:19 +0000201v6_dma_inv_range:
Valentine Barshak85b093b2010-12-14 00:03:16 +0100202#ifdef CONFIG_DMA_CACHE_RWFO
203 ldrb r2, [r0] @ read for ownership
204 strb r2, [r0] @ write for ownership
205#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 tst r0, #D_CACHE_LINE_SIZE - 1
207 bic r0, r0, #D_CACHE_LINE_SIZE - 1
208#ifdef HARVARD_CACHE
209 mcrne p15, 0, r0, c7, c10, 1 @ clean D line
210#else
211 mcrne p15, 0, r0, c7, c11, 1 @ clean unified line
212#endif
213 tst r1, #D_CACHE_LINE_SIZE - 1
Valentine Barshak85b093b2010-12-14 00:03:16 +0100214#ifdef CONFIG_DMA_CACHE_RWFO
Stefan Agnere44fc382019-02-18 00:57:38 +0100215 ldrbne r2, [r1, #-1] @ read for ownership
216 strbne r2, [r1, #-1] @ write for ownership
Valentine Barshak85b093b2010-12-14 00:03:16 +0100217#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 bic r1, r1, #D_CACHE_LINE_SIZE - 1
219#ifdef HARVARD_CACHE
220 mcrne p15, 0, r1, c7, c14, 1 @ clean & invalidate D line
221#else
222 mcrne p15, 0, r1, c7, c15, 1 @ clean & invalidate unified line
223#endif
2241:
225#ifdef HARVARD_CACHE
226 mcr p15, 0, r0, c7, c6, 1 @ invalidate D line
227#else
228 mcr p15, 0, r0, c7, c7, 1 @ invalidate unified line
229#endif
230 add r0, r0, #D_CACHE_LINE_SIZE
231 cmp r0, r1
Valentine Barshak85b093b2010-12-14 00:03:16 +0100232#ifdef CONFIG_DMA_CACHE_RWFO
233 ldrlo r2, [r0] @ read for ownership
234 strlo r2, [r0] @ write for ownership
235#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 blo 1b
237 mov r0, #0
238 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
Russell King6ebbf2c2014-06-30 16:29:12 +0100239 ret lr
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240
241/*
242 * v6_dma_clean_range(start,end)
243 * - start - virtual start address of region
244 * - end - virtual end address of region
245 */
Russell King702b94b2009-11-26 16:24:19 +0000246v6_dma_clean_range:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 bic r0, r0, #D_CACHE_LINE_SIZE - 1
2481:
Catalin Marinasad642d92010-06-21 15:10:07 +0100249#ifdef CONFIG_DMA_CACHE_RWFO
Catalin Marinasf4d64772010-05-07 16:26:24 +0100250 ldr r2, [r0] @ read for ownership
251#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252#ifdef HARVARD_CACHE
253 mcr p15, 0, r0, c7, c10, 1 @ clean D line
254#else
255 mcr p15, 0, r0, c7, c11, 1 @ clean unified line
256#endif
257 add r0, r0, #D_CACHE_LINE_SIZE
258 cmp r0, r1
259 blo 1b
260 mov r0, #0
261 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
Russell King6ebbf2c2014-06-30 16:29:12 +0100262 ret lr
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
264/*
265 * v6_dma_flush_range(start,end)
266 * - start - virtual start address of region
267 * - end - virtual end address of region
268 */
269ENTRY(v6_dma_flush_range)
Valentine Barshak85b093b2010-12-14 00:03:16 +0100270#ifdef CONFIG_DMA_CACHE_RWFO
271 ldrb r2, [r0] @ read for ownership
272 strb r2, [r0] @ write for ownership
273#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 bic r0, r0, #D_CACHE_LINE_SIZE - 1
2751:
276#ifdef HARVARD_CACHE
277 mcr p15, 0, r0, c7, c14, 1 @ clean & invalidate D line
278#else
279 mcr p15, 0, r0, c7, c15, 1 @ clean & invalidate line
280#endif
281 add r0, r0, #D_CACHE_LINE_SIZE
282 cmp r0, r1
Valentine Barshak85b093b2010-12-14 00:03:16 +0100283#ifdef CONFIG_DMA_CACHE_RWFO
Stefan Agnere44fc382019-02-18 00:57:38 +0100284 ldrblo r2, [r0] @ read for ownership
285 strblo r2, [r0] @ write for ownership
Valentine Barshak85b093b2010-12-14 00:03:16 +0100286#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 blo 1b
288 mov r0, #0
289 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
Russell King6ebbf2c2014-06-30 16:29:12 +0100290 ret lr
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291
Russell Kinga9c91472009-11-26 16:19:58 +0000292/*
293 * dma_map_area(start, size, dir)
294 * - start - kernel virtual start address
295 * - size - size of region
296 * - dir - DMA direction
297 */
298ENTRY(v6_dma_map_area)
299 add r1, r1, r0
Russell King2ffe2da2009-10-31 16:52:16 +0000300 teq r2, #DMA_FROM_DEVICE
301 beq v6_dma_inv_range
Catalin Marinasad642d92010-06-21 15:10:07 +0100302#ifndef CONFIG_DMA_CACHE_RWFO
303 b v6_dma_clean_range
304#else
Catalin Marinasf4d64772010-05-07 16:26:24 +0100305 teq r2, #DMA_TO_DEVICE
306 beq v6_dma_clean_range
307 b v6_dma_flush_range
Catalin Marinasad642d92010-06-21 15:10:07 +0100308#endif
Russell Kinga9c91472009-11-26 16:19:58 +0000309ENDPROC(v6_dma_map_area)
310
311/*
312 * dma_unmap_area(start, size, dir)
313 * - start - kernel virtual start address
314 * - size - size of region
315 * - dir - DMA direction
316 */
317ENTRY(v6_dma_unmap_area)
Catalin Marinasad642d92010-06-21 15:10:07 +0100318#ifndef CONFIG_DMA_CACHE_RWFO
319 add r1, r1, r0
320 teq r2, #DMA_TO_DEVICE
321 bne v6_dma_inv_range
322#endif
Russell King6ebbf2c2014-06-30 16:29:12 +0100323 ret lr
Russell Kinga9c91472009-11-26 16:19:58 +0000324ENDPROC(v6_dma_unmap_area)
325
Lorenzo Pieralisi031bd872012-09-06 18:35:13 +0530326 .globl v6_flush_kern_cache_louis
327 .equ v6_flush_kern_cache_louis, v6_flush_kern_cache_all
328
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 __INITDATA
330
Dave Martin641d8232011-06-23 17:16:04 +0100331 @ define struct cpu_cache_fns (see <asm/cacheflush.h> and proc-macros.S)
332 define_cache_functions v6