4 * Copyright (C) 2001 Deep Blue Solutions Ltd.
5 * Copyright (C) 2012 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 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.
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/>.
20 #include <linux/errno.h>
21 #include <linux/linkage.h>
22 #include <linux/init.h>
23 #include <asm/assembler.h>
24 #include <asm/cpufeature.h>
25 #include <asm/alternative.h>
26 #include <asm/asm-uaccess.h>
29 * flush_icache_range(start,end)
31 * Ensure that the I and D caches are coherent within specified region.
32 * This is typically used when code has been written to a memory region,
33 * and will be executed.
35 * - start - virtual start address of region
36 * - end - virtual end address of region
38 ENTRY(flush_icache_range)
42 * __flush_cache_user_range(start,end)
44 * Ensure that the I and D caches are coherent within specified region.
45 * This is typically used when code has been written to a memory region,
46 * and will be executed.
48 * - start - virtual start address of region
49 * - end - virtual end address of region
51 ENTRY(__flush_cache_user_range)
52 uaccess_ttbr0_enable x2, x3, x4
53 dcache_line_size x2, x3
57 user_alt 9f, "dc cvau, x4", "dc civac, x4", ARM64_WORKAROUND_CLEAN_CACHE
63 icache_line_size x2, x3
67 USER(9f, ic ivau, x4 ) // invalidate I line PoU
75 uaccess_ttbr0_disable x1, x2
80 ENDPROC(flush_icache_range)
81 ENDPROC(__flush_cache_user_range)
84 * __flush_dcache_area(kaddr, size)
86 * Ensure that any D-cache lines for the interval [kaddr, kaddr+size)
87 * are cleaned and invalidated to the PoC.
89 * - kaddr - kernel address
90 * - size - size in question
92 ENTRY(__flush_dcache_area)
93 dcache_by_line_op civac, sy, x0, x1, x2, x3
95 ENDPIPROC(__flush_dcache_area)
98 * __clean_dcache_area_pou(kaddr, size)
100 * Ensure that any D-cache lines for the interval [kaddr, kaddr+size)
101 * are cleaned to the PoU.
103 * - kaddr - kernel address
104 * - size - size in question
106 ENTRY(__clean_dcache_area_pou)
107 dcache_by_line_op cvau, ish, x0, x1, x2, x3
109 ENDPROC(__clean_dcache_area_pou)
112 * __inval_dcache_area(kaddr, size)
114 * Ensure that any D-cache lines for the interval [kaddr, kaddr+size)
115 * are invalidated. Any partial lines at the ends of the interval are
116 * also cleaned to PoC to prevent data loss.
118 * - kaddr - kernel address
119 * - size - size in question
121 ENTRY(__inval_dcache_area)
125 * __dma_inv_area(start, size)
126 * - start - virtual start address of region
127 * - size - size in question
131 dcache_line_size x2, x3
133 tst x1, x3 // end cache line aligned?
136 dc civac, x1 // clean & invalidate D / U line
137 1: tst x0, x3 // start cache line aligned?
140 dc civac, x0 // clean & invalidate D / U line
142 2: dc ivac, x0 // invalidate D / U line
148 ENDPIPROC(__inval_dcache_area)
149 ENDPROC(__dma_inv_area)
152 * __clean_dcache_area_poc(kaddr, size)
154 * Ensure that any D-cache lines for the interval [kaddr, kaddr+size)
155 * are cleaned to the PoC.
157 * - kaddr - kernel address
158 * - size - size in question
160 ENTRY(__clean_dcache_area_poc)
164 * __dma_clean_area(start, size)
165 * - start - virtual start address of region
166 * - size - size in question
169 dcache_by_line_op cvac, sy, x0, x1, x2, x3
171 ENDPIPROC(__clean_dcache_area_poc)
172 ENDPROC(__dma_clean_area)
175 * __clean_dcache_area_pop(kaddr, size)
177 * Ensure that any D-cache lines for the interval [kaddr, kaddr+size)
178 * are cleaned to the PoP.
180 * - kaddr - kernel address
181 * - size - size in question
183 ENTRY(__clean_dcache_area_pop)
184 alternative_if_not ARM64_HAS_DCPOP
185 b __clean_dcache_area_poc
186 alternative_else_nop_endif
187 dcache_by_line_op cvap, sy, x0, x1, x2, x3
189 ENDPIPROC(__clean_dcache_area_pop)
192 * __dma_flush_area(start, size)
194 * clean & invalidate D / U line
196 * - start - virtual start address of region
197 * - size - size in question
199 ENTRY(__dma_flush_area)
200 dcache_by_line_op civac, sy, x0, x1, x2, x3
202 ENDPIPROC(__dma_flush_area)
205 * __dma_map_area(start, size, dir)
206 * - start - kernel virtual start address
207 * - size - size of region
208 * - dir - DMA direction
210 ENTRY(__dma_map_area)
211 cmp w2, #DMA_FROM_DEVICE
214 ENDPIPROC(__dma_map_area)
217 * __dma_unmap_area(start, size, dir)
218 * - start - kernel virtual start address
219 * - size - size of region
220 * - dir - DMA direction
222 ENTRY(__dma_unmap_area)
223 cmp w2, #DMA_TO_DEVICE
226 ENDPIPROC(__dma_unmap_area)