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 invalidate_icache_by_line x0, x1, x2, x3, 9f
66 uaccess_ttbr0_disable x1, x2
71 ENDPROC(flush_icache_range)
72 ENDPROC(__flush_cache_user_range)
75 * invalidate_icache_range(start,end)
77 * Ensure that the I cache is invalid within specified region.
79 * - start - virtual start address of region
80 * - end - virtual end address of region
82 ENTRY(invalidate_icache_range)
83 uaccess_ttbr0_enable x2, x3, x4
85 invalidate_icache_by_line x0, x1, x2, x3, 2f
88 uaccess_ttbr0_disable x1, x2
93 ENDPROC(invalidate_icache_range)
96 * __flush_dcache_area(kaddr, size)
98 * Ensure that any D-cache lines for the interval [kaddr, kaddr+size)
99 * are cleaned and invalidated to the PoC.
101 * - kaddr - kernel address
102 * - size - size in question
104 ENTRY(__flush_dcache_area)
105 dcache_by_line_op civac, sy, x0, x1, x2, x3
107 ENDPIPROC(__flush_dcache_area)
110 * __clean_dcache_area_pou(kaddr, size)
112 * Ensure that any D-cache lines for the interval [kaddr, kaddr+size)
113 * are cleaned to the PoU.
115 * - kaddr - kernel address
116 * - size - size in question
118 ENTRY(__clean_dcache_area_pou)
119 dcache_by_line_op cvau, ish, x0, x1, x2, x3
121 ENDPROC(__clean_dcache_area_pou)
124 * __inval_dcache_area(kaddr, size)
126 * Ensure that any D-cache lines for the interval [kaddr, kaddr+size)
127 * are invalidated. Any partial lines at the ends of the interval are
128 * also cleaned to PoC to prevent data loss.
130 * - kaddr - kernel address
131 * - size - size in question
133 ENTRY(__inval_dcache_area)
137 * __dma_inv_area(start, size)
138 * - start - virtual start address of region
139 * - size - size in question
143 dcache_line_size x2, x3
145 tst x1, x3 // end cache line aligned?
148 dc civac, x1 // clean & invalidate D / U line
149 1: tst x0, x3 // start cache line aligned?
152 dc civac, x0 // clean & invalidate D / U line
154 2: dc ivac, x0 // invalidate D / U line
160 ENDPIPROC(__inval_dcache_area)
161 ENDPROC(__dma_inv_area)
164 * __clean_dcache_area_poc(kaddr, size)
166 * Ensure that any D-cache lines for the interval [kaddr, kaddr+size)
167 * are cleaned to the PoC.
169 * - kaddr - kernel address
170 * - size - size in question
172 ENTRY(__clean_dcache_area_poc)
176 * __dma_clean_area(start, size)
177 * - start - virtual start address of region
178 * - size - size in question
181 dcache_by_line_op cvac, sy, x0, x1, x2, x3
183 ENDPIPROC(__clean_dcache_area_poc)
184 ENDPROC(__dma_clean_area)
187 * __clean_dcache_area_pop(kaddr, size)
189 * Ensure that any D-cache lines for the interval [kaddr, kaddr+size)
190 * are cleaned to the PoP.
192 * - kaddr - kernel address
193 * - size - size in question
195 ENTRY(__clean_dcache_area_pop)
196 dcache_by_line_op cvap, sy, x0, x1, x2, x3
198 ENDPIPROC(__clean_dcache_area_pop)
201 * __dma_flush_area(start, size)
203 * clean & invalidate D / U line
205 * - start - virtual start address of region
206 * - size - size in question
208 ENTRY(__dma_flush_area)
209 dcache_by_line_op civac, sy, x0, x1, x2, x3
211 ENDPIPROC(__dma_flush_area)
214 * __dma_map_area(start, size, dir)
215 * - start - kernel virtual start address
216 * - size - size of region
217 * - dir - DMA direction
219 ENTRY(__dma_map_area)
220 cmp w2, #DMA_FROM_DEVICE
223 ENDPIPROC(__dma_map_area)
226 * __dma_unmap_area(start, size, dir)
227 * - start - kernel virtual start address
228 * - size - size of region
229 * - dir - DMA direction
231 ENTRY(__dma_unmap_area)
232 cmp w2, #DMA_TO_DEVICE
235 ENDPIPROC(__dma_unmap_area)