blob: 07d7352d7c3896cb70d1640bb3215d09b3dc1ad6 [file] [log] [blame]
Catalin Marinasf1a0c4a2012-03-05 11:49:28 +00001/*
2 * Cache maintenance
3 *
4 * Copyright (C) 2001 Deep Blue Solutions Ltd.
5 * Copyright (C) 2012 ARM Ltd.
6 *
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.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
Vladimir Murzina2d25a52014-12-01 10:53:08 +000020#include <linux/errno.h>
Catalin Marinasf1a0c4a2012-03-05 11:49:28 +000021#include <linux/linkage.h>
22#include <linux/init.h>
23#include <asm/assembler.h>
Andre Przywara301bcfa2014-11-14 15:54:10 +000024#include <asm/cpufeature.h>
Marc Zyngier8d883b22015-06-01 10:47:41 +010025#include <asm/alternative.h>
Catalin Marinasf1a0c4a2012-03-05 11:49:28 +000026
Catalin Marinasf1a0c4a2012-03-05 11:49:28 +000027/*
Catalin Marinasf1a0c4a2012-03-05 11:49:28 +000028 * flush_icache_range(start,end)
29 *
30 * Ensure that the I and D caches are coherent within specified region.
31 * This is typically used when code has been written to a memory region,
32 * and will be executed.
33 *
34 * - start - virtual start address of region
35 * - end - virtual end address of region
36 */
37ENTRY(flush_icache_range)
38 /* FALLTHROUGH */
39
40/*
41 * __flush_cache_user_range(start,end)
42 *
43 * Ensure that the I and D caches are coherent within specified region.
44 * This is typically used when code has been written to a memory region,
45 * and will be executed.
46 *
47 * - start - virtual start address of region
48 * - end - virtual end address of region
49 */
50ENTRY(__flush_cache_user_range)
51 dcache_line_size x2, x3
52 sub x3, x2, #1
53 bic x4, x0, x3
541:
Andre Przywara290622e2016-06-28 18:07:28 +010055user_alt 9f, "dc cvau, x4", "dc civac, x4", ARM64_WORKAROUND_CLEAN_CACHE
Catalin Marinasf1a0c4a2012-03-05 11:49:28 +000056 add x4, x4, x2
57 cmp x4, x1
58 b.lo 1b
Will Deacondc60b772014-05-02 16:24:15 +010059 dsb ish
Catalin Marinasf1a0c4a2012-03-05 11:49:28 +000060
61 icache_line_size x2, x3
62 sub x3, x2, #1
63 bic x4, x0, x3
641:
65USER(9f, ic ivau, x4 ) // invalidate I line PoU
66 add x4, x4, x2
67 cmp x4, x1
68 b.lo 1b
Will Deacondc60b772014-05-02 16:24:15 +010069 dsb ish
Catalin Marinasf1a0c4a2012-03-05 11:49:28 +000070 isb
Vladimir Murzina2d25a52014-12-01 10:53:08 +000071 mov x0, #0
72 ret
739:
74 mov x0, #-EFAULT
Catalin Marinasf1a0c4a2012-03-05 11:49:28 +000075 ret
76ENDPROC(flush_icache_range)
77ENDPROC(__flush_cache_user_range)
78
79/*
Jingoo Han03324e62014-01-21 01:17:47 +000080 * __flush_dcache_area(kaddr, size)
Catalin Marinasf1a0c4a2012-03-05 11:49:28 +000081 *
Ashok Kumar0a287142015-12-17 01:38:32 -080082 * Ensure that any D-cache lines for the interval [kaddr, kaddr+size)
83 * are cleaned and invalidated to the PoC.
Catalin Marinasf1a0c4a2012-03-05 11:49:28 +000084 *
85 * - kaddr - kernel address
86 * - size - size in question
87 */
88ENTRY(__flush_dcache_area)
Ashok Kumar0a287142015-12-17 01:38:32 -080089 dcache_by_line_op civac, sy, x0, x1, x2, x3
Catalin Marinasf1a0c4a2012-03-05 11:49:28 +000090 ret
Ard Biesheuvel20791842015-10-08 20:02:03 +010091ENDPIPROC(__flush_dcache_area)
Catalin Marinas73635902013-05-21 17:35:19 +010092
93/*
Ashok Kumar0a287142015-12-17 01:38:32 -080094 * __clean_dcache_area_pou(kaddr, size)
95 *
96 * Ensure that any D-cache lines for the interval [kaddr, kaddr+size)
97 * are cleaned to the PoU.
98 *
99 * - kaddr - kernel address
100 * - size - size in question
101 */
102ENTRY(__clean_dcache_area_pou)
103 dcache_by_line_op cvau, ish, x0, x1, x2, x3
104 ret
105ENDPROC(__clean_dcache_area_pou)
106
107/*
Catalin Marinasc218bca2014-03-26 18:25:55 +0000108 * __inval_cache_range(start, end)
109 * - start - start address of region
110 * - end - end address of region
111 */
112ENTRY(__inval_cache_range)
113 /* FALLTHROUGH */
114
115/*
Catalin Marinas73635902013-05-21 17:35:19 +0100116 * __dma_inv_range(start, end)
117 * - start - virtual start address of region
118 * - end - virtual end address of region
119 */
120__dma_inv_range:
121 dcache_line_size x2, x3
122 sub x3, x2, #1
Catalin Marinasebf81a92014-04-01 18:32:55 +0100123 tst x1, x3 // end cache line aligned?
Catalin Marinas73635902013-05-21 17:35:19 +0100124 bic x1, x1, x3
Catalin Marinasebf81a92014-04-01 18:32:55 +0100125 b.eq 1f
126 dc civac, x1 // clean & invalidate D / U line
1271: tst x0, x3 // start cache line aligned?
128 bic x0, x0, x3
129 b.eq 2f
130 dc civac, x0 // clean & invalidate D / U line
131 b 3f
1322: dc ivac, x0 // invalidate D / U line
1333: add x0, x0, x2
Catalin Marinas73635902013-05-21 17:35:19 +0100134 cmp x0, x1
Catalin Marinasebf81a92014-04-01 18:32:55 +0100135 b.lo 2b
Catalin Marinas73635902013-05-21 17:35:19 +0100136 dsb sy
137 ret
Ard Biesheuvel20791842015-10-08 20:02:03 +0100138ENDPIPROC(__inval_cache_range)
Catalin Marinas73635902013-05-21 17:35:19 +0100139ENDPROC(__dma_inv_range)
140
141/*
142 * __dma_clean_range(start, end)
143 * - start - virtual start address of region
144 * - end - virtual end address of region
145 */
146__dma_clean_range:
147 dcache_line_size x2, x3
148 sub x3, x2, #1
149 bic x0, x0, x3
Daniel Thompson271d35e2015-07-22 12:21:02 +01001501:
151alternative_if_not ARM64_WORKAROUND_CLEAN_CACHE
152 dc cvac, x0
153alternative_else
154 dc civac, x0
155alternative_endif
Catalin Marinas73635902013-05-21 17:35:19 +0100156 add x0, x0, x2
157 cmp x0, x1
158 b.lo 1b
159 dsb sy
160 ret
161ENDPROC(__dma_clean_range)
162
163/*
164 * __dma_flush_range(start, end)
165 * - start - virtual start address of region
166 * - end - virtual end address of region
167 */
168ENTRY(__dma_flush_range)
169 dcache_line_size x2, x3
170 sub x3, x2, #1
171 bic x0, x0, x3
1721: dc civac, x0 // clean & invalidate D / U line
173 add x0, x0, x2
174 cmp x0, x1
175 b.lo 1b
176 dsb sy
177 ret
Ard Biesheuvel20791842015-10-08 20:02:03 +0100178ENDPIPROC(__dma_flush_range)
Catalin Marinas73635902013-05-21 17:35:19 +0100179
180/*
181 * __dma_map_area(start, size, dir)
182 * - start - kernel virtual start address
183 * - size - size of region
184 * - dir - DMA direction
185 */
186ENTRY(__dma_map_area)
187 add x1, x1, x0
188 cmp w2, #DMA_FROM_DEVICE
189 b.eq __dma_inv_range
190 b __dma_clean_range
Ard Biesheuvel20791842015-10-08 20:02:03 +0100191ENDPIPROC(__dma_map_area)
Catalin Marinas73635902013-05-21 17:35:19 +0100192
193/*
194 * __dma_unmap_area(start, size, dir)
195 * - start - kernel virtual start address
196 * - size - size of region
197 * - dir - DMA direction
198 */
199ENTRY(__dma_unmap_area)
200 add x1, x1, x0
201 cmp w2, #DMA_TO_DEVICE
202 b.ne __dma_inv_range
203 ret
Ard Biesheuvel20791842015-10-08 20:02:03 +0100204ENDPIPROC(__dma_unmap_area)