| .. | .. |
|---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-only */ |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Cache maintenance |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2001 Deep Blue Solutions Ltd. |
|---|
| 5 | 6 | * 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 | 7 | */ |
|---|
| 19 | 8 | |
|---|
| 20 | 9 | #include <linux/errno.h> |
|---|
| .. | .. |
|---|
| 26 | 15 | #include <asm/asm-uaccess.h> |
|---|
| 27 | 16 | |
|---|
| 28 | 17 | /* |
|---|
| 29 | | - * __flush_dcache_all() |
|---|
| 30 | | - * |
|---|
| 31 | | - * Flush the whole D-cache. |
|---|
| 32 | | - * |
|---|
| 33 | | - * Corrupted registers: x0-x7, x9-x11 |
|---|
| 34 | | - */ |
|---|
| 35 | | -ENTRY(__flush_dcache_all) |
|---|
| 36 | | - dmb sy // ensure ordering with previous memory accesses |
|---|
| 37 | | - mrs x0, clidr_el1 // read clidr |
|---|
| 38 | | - and x3, x0, #0x7000000 // extract loc from clidr |
|---|
| 39 | | - lsr x3, x3, #23 // left align loc bit field |
|---|
| 40 | | - cbz x3, finished // if loc is 0, then no need to clean |
|---|
| 41 | | - mov x10, #0 // start clean at cache level 0 |
|---|
| 42 | | -loop1: |
|---|
| 43 | | - add x2, x10, x10, lsr #1 // work out 3x current cache level |
|---|
| 44 | | - lsr x1, x0, x2 // extract cache type bits from clidr |
|---|
| 45 | | - and x1, x1, #7 // mask of the bits for current cache only |
|---|
| 46 | | - cmp x1, #2 // see what cache we have at this level |
|---|
| 47 | | - b.lt skip // skip if no cache, or just i-cache |
|---|
| 48 | | - save_and_disable_irqs x9 // make CSSELR and CCSIDR access atomic |
|---|
| 49 | | - msr csselr_el1, x10 // select current cache level in csselr |
|---|
| 50 | | - isb // isb to sych the new cssr&csidr |
|---|
| 51 | | - mrs x1, ccsidr_el1 // read the new ccsidr |
|---|
| 52 | | - restore_irqs x9 |
|---|
| 53 | | - and x2, x1, #7 // extract the length of the cache lines |
|---|
| 54 | | - add x2, x2, #4 // add 4 (line length offset) |
|---|
| 55 | | - mov x4, #0x3ff |
|---|
| 56 | | - and x4, x4, x1, lsr #3 // find maximum number on the way size |
|---|
| 57 | | - clz w5, w4 // find bit position of way size increment |
|---|
| 58 | | - mov x7, #0x7fff |
|---|
| 59 | | - and x7, x7, x1, lsr #13 // extract max number of the index size |
|---|
| 60 | | -loop2: |
|---|
| 61 | | - mov x9, x4 // create working copy of max way size |
|---|
| 62 | | -loop3: |
|---|
| 63 | | - lsl x6, x9, x5 |
|---|
| 64 | | - orr x11, x10, x6 // factor way and cache number into x11 |
|---|
| 65 | | - lsl x6, x7, x2 |
|---|
| 66 | | - orr x11, x11, x6 // factor index number into x11 |
|---|
| 67 | | - dc cisw, x11 // clean & invalidate by set/way |
|---|
| 68 | | - subs x9, x9, #1 // decrement the way |
|---|
| 69 | | - b.ge loop3 |
|---|
| 70 | | - subs x7, x7, #1 // decrement the index |
|---|
| 71 | | - b.ge loop2 |
|---|
| 72 | | -skip: |
|---|
| 73 | | - add x10, x10, #2 // increment cache number |
|---|
| 74 | | - cmp x3, x10 |
|---|
| 75 | | - b.gt loop1 |
|---|
| 76 | | -finished: |
|---|
| 77 | | - mov x10, #0 // swith back to cache level 0 |
|---|
| 78 | | - msr csselr_el1, x10 // select current cache level in csselr |
|---|
| 79 | | - dsb sy |
|---|
| 80 | | - isb |
|---|
| 81 | | - ret |
|---|
| 82 | | -ENDPROC(__flush_dcache_all) |
|---|
| 83 | | - |
|---|
| 84 | | -/* |
|---|
| 85 | | - * flush_cache_all() |
|---|
| 86 | | - * |
|---|
| 87 | | - * Flush the entire cache system. The data cache flush is now achieved |
|---|
| 88 | | - * using atomic clean / invalidates working outwards from L1 cache. This |
|---|
| 89 | | - * is done using Set/Way based cache maintenance instructions. The |
|---|
| 90 | | - * instruction cache can still be invalidated back to the point of |
|---|
| 91 | | - * unification in a single instruction. |
|---|
| 92 | | - */ |
|---|
| 93 | | -ENTRY(flush_cache_all) |
|---|
| 94 | | - mov x12, lr |
|---|
| 95 | | - bl __flush_dcache_all |
|---|
| 96 | | - mov x0, #0 |
|---|
| 97 | | - ic ialluis // I+BTB cache invalidate |
|---|
| 98 | | - ret x12 |
|---|
| 99 | | -ENDPROC(flush_cache_all) |
|---|
| 100 | | - |
|---|
| 101 | | -/* |
|---|
| 102 | 18 | * flush_icache_range(start,end) |
|---|
| 103 | 19 | * |
|---|
| 104 | 20 | * Ensure that the I and D caches are coherent within specified region. |
|---|
| .. | .. |
|---|
| 108 | 24 | * - start - virtual start address of region |
|---|
| 109 | 25 | * - end - virtual end address of region |
|---|
| 110 | 26 | */ |
|---|
| 111 | | -ENTRY(__flush_icache_range) |
|---|
| 27 | +SYM_FUNC_START(__flush_icache_range) |
|---|
| 112 | 28 | /* FALLTHROUGH */ |
|---|
| 113 | 29 | |
|---|
| 114 | 30 | /* |
|---|
| .. | .. |
|---|
| 121 | 37 | * - start - virtual start address of region |
|---|
| 122 | 38 | * - end - virtual end address of region |
|---|
| 123 | 39 | */ |
|---|
| 124 | | -ENTRY(__flush_cache_user_range) |
|---|
| 40 | +SYM_FUNC_START(__flush_cache_user_range) |
|---|
| 125 | 41 | uaccess_ttbr0_enable x2, x3, x4 |
|---|
| 126 | 42 | alternative_if ARM64_HAS_CACHE_IDC |
|---|
| 127 | 43 | dsb ishst |
|---|
| .. | .. |
|---|
| 150 | 66 | 9: |
|---|
| 151 | 67 | mov x0, #-EFAULT |
|---|
| 152 | 68 | b 1b |
|---|
| 153 | | -ENDPROC(__flush_icache_range) |
|---|
| 154 | | -ENDPROC(__flush_cache_user_range) |
|---|
| 69 | +SYM_FUNC_END(__flush_icache_range) |
|---|
| 70 | +SYM_FUNC_END(__flush_cache_user_range) |
|---|
| 155 | 71 | |
|---|
| 156 | 72 | /* |
|---|
| 157 | 73 | * invalidate_icache_range(start,end) |
|---|
| .. | .. |
|---|
| 161 | 77 | * - start - virtual start address of region |
|---|
| 162 | 78 | * - end - virtual end address of region |
|---|
| 163 | 79 | */ |
|---|
| 164 | | -ENTRY(invalidate_icache_range) |
|---|
| 80 | +SYM_FUNC_START(invalidate_icache_range) |
|---|
| 165 | 81 | alternative_if ARM64_HAS_CACHE_DIC |
|---|
| 166 | 82 | mov x0, xzr |
|---|
| 167 | 83 | isb |
|---|
| .. | .. |
|---|
| 178 | 94 | 2: |
|---|
| 179 | 95 | mov x0, #-EFAULT |
|---|
| 180 | 96 | b 1b |
|---|
| 181 | | -ENDPROC(invalidate_icache_range) |
|---|
| 97 | +SYM_FUNC_END(invalidate_icache_range) |
|---|
| 182 | 98 | |
|---|
| 183 | 99 | /* |
|---|
| 184 | 100 | * __flush_dcache_area(kaddr, size) |
|---|
| .. | .. |
|---|
| 189 | 105 | * - kaddr - kernel address |
|---|
| 190 | 106 | * - size - size in question |
|---|
| 191 | 107 | */ |
|---|
| 192 | | -ENTRY(__flush_dcache_area) |
|---|
| 108 | +SYM_FUNC_START_PI(__flush_dcache_area) |
|---|
| 193 | 109 | dcache_by_line_op civac, sy, x0, x1, x2, x3 |
|---|
| 194 | 110 | ret |
|---|
| 195 | | -ENDPIPROC(__flush_dcache_area) |
|---|
| 111 | +SYM_FUNC_END_PI(__flush_dcache_area) |
|---|
| 196 | 112 | |
|---|
| 197 | 113 | /* |
|---|
| 198 | 114 | * __clean_dcache_area_pou(kaddr, size) |
|---|
| .. | .. |
|---|
| 203 | 119 | * - kaddr - kernel address |
|---|
| 204 | 120 | * - size - size in question |
|---|
| 205 | 121 | */ |
|---|
| 206 | | -ENTRY(__clean_dcache_area_pou) |
|---|
| 122 | +SYM_FUNC_START(__clean_dcache_area_pou) |
|---|
| 207 | 123 | alternative_if ARM64_HAS_CACHE_IDC |
|---|
| 208 | 124 | dsb ishst |
|---|
| 209 | 125 | ret |
|---|
| 210 | 126 | alternative_else_nop_endif |
|---|
| 211 | 127 | dcache_by_line_op cvau, ish, x0, x1, x2, x3 |
|---|
| 212 | 128 | ret |
|---|
| 213 | | -ENDPROC(__clean_dcache_area_pou) |
|---|
| 129 | +SYM_FUNC_END(__clean_dcache_area_pou) |
|---|
| 214 | 130 | |
|---|
| 215 | 131 | /* |
|---|
| 216 | 132 | * __inval_dcache_area(kaddr, size) |
|---|
| .. | .. |
|---|
| 222 | 138 | * - kaddr - kernel address |
|---|
| 223 | 139 | * - size - size in question |
|---|
| 224 | 140 | */ |
|---|
| 225 | | -ENTRY(__inval_dcache_area) |
|---|
| 141 | +SYM_FUNC_START_LOCAL(__dma_inv_area) |
|---|
| 142 | +SYM_FUNC_START_PI(__inval_dcache_area) |
|---|
| 226 | 143 | /* FALLTHROUGH */ |
|---|
| 227 | 144 | |
|---|
| 228 | 145 | /* |
|---|
| .. | .. |
|---|
| 230 | 147 | * - start - virtual start address of region |
|---|
| 231 | 148 | * - size - size in question |
|---|
| 232 | 149 | */ |
|---|
| 233 | | -ENTRY(__dma_inv_area) |
|---|
| 234 | 150 | add x1, x1, x0 |
|---|
| 235 | 151 | dcache_line_size x2, x3 |
|---|
| 236 | 152 | sub x3, x2, #1 |
|---|
| .. | .. |
|---|
| 249 | 165 | b.lo 2b |
|---|
| 250 | 166 | dsb sy |
|---|
| 251 | 167 | ret |
|---|
| 252 | | -ENDPIPROC(__inval_dcache_area) |
|---|
| 253 | | -ENDPROC(__dma_inv_area) |
|---|
| 168 | +SYM_FUNC_END_PI(__inval_dcache_area) |
|---|
| 169 | +SYM_FUNC_END(__dma_inv_area) |
|---|
| 254 | 170 | |
|---|
| 255 | 171 | /* |
|---|
| 256 | 172 | * __clean_dcache_area_poc(kaddr, size) |
|---|
| .. | .. |
|---|
| 261 | 177 | * - kaddr - kernel address |
|---|
| 262 | 178 | * - size - size in question |
|---|
| 263 | 179 | */ |
|---|
| 264 | | -ENTRY(__clean_dcache_area_poc) |
|---|
| 180 | +SYM_FUNC_START_LOCAL(__dma_clean_area) |
|---|
| 181 | +SYM_FUNC_START_PI(__clean_dcache_area_poc) |
|---|
| 265 | 182 | /* FALLTHROUGH */ |
|---|
| 266 | 183 | |
|---|
| 267 | 184 | /* |
|---|
| .. | .. |
|---|
| 269 | 186 | * - start - virtual start address of region |
|---|
| 270 | 187 | * - size - size in question |
|---|
| 271 | 188 | */ |
|---|
| 272 | | -ENTRY(__dma_clean_area) |
|---|
| 273 | 189 | dcache_by_line_op cvac, sy, x0, x1, x2, x3 |
|---|
| 274 | 190 | ret |
|---|
| 275 | | -ENDPIPROC(__clean_dcache_area_poc) |
|---|
| 276 | | -ENDPROC(__dma_clean_area) |
|---|
| 191 | +SYM_FUNC_END_PI(__clean_dcache_area_poc) |
|---|
| 192 | +SYM_FUNC_END(__dma_clean_area) |
|---|
| 277 | 193 | |
|---|
| 278 | 194 | /* |
|---|
| 279 | 195 | * __clean_dcache_area_pop(kaddr, size) |
|---|
| .. | .. |
|---|
| 284 | 200 | * - kaddr - kernel address |
|---|
| 285 | 201 | * - size - size in question |
|---|
| 286 | 202 | */ |
|---|
| 287 | | -ENTRY(__clean_dcache_area_pop) |
|---|
| 203 | +SYM_FUNC_START_PI(__clean_dcache_area_pop) |
|---|
| 288 | 204 | alternative_if_not ARM64_HAS_DCPOP |
|---|
| 289 | 205 | b __clean_dcache_area_poc |
|---|
| 290 | 206 | alternative_else_nop_endif |
|---|
| 291 | 207 | dcache_by_line_op cvap, sy, x0, x1, x2, x3 |
|---|
| 292 | 208 | ret |
|---|
| 293 | | -ENDPIPROC(__clean_dcache_area_pop) |
|---|
| 209 | +SYM_FUNC_END_PI(__clean_dcache_area_pop) |
|---|
| 294 | 210 | |
|---|
| 295 | 211 | /* |
|---|
| 296 | 212 | * __dma_flush_area(start, size) |
|---|
| .. | .. |
|---|
| 300 | 216 | * - start - virtual start address of region |
|---|
| 301 | 217 | * - size - size in question |
|---|
| 302 | 218 | */ |
|---|
| 303 | | -ENTRY(__dma_flush_area) |
|---|
| 219 | +SYM_FUNC_START_PI(__dma_flush_area) |
|---|
| 304 | 220 | dcache_by_line_op civac, sy, x0, x1, x2, x3 |
|---|
| 305 | 221 | ret |
|---|
| 306 | | -ENDPIPROC(__dma_flush_area) |
|---|
| 222 | +SYM_FUNC_END_PI(__dma_flush_area) |
|---|
| 307 | 223 | |
|---|
| 308 | 224 | /* |
|---|
| 309 | 225 | * __dma_map_area(start, size, dir) |
|---|
| .. | .. |
|---|
| 311 | 227 | * - size - size of region |
|---|
| 312 | 228 | * - dir - DMA direction |
|---|
| 313 | 229 | */ |
|---|
| 314 | | -ENTRY(__dma_map_area) |
|---|
| 230 | +SYM_FUNC_START_PI(__dma_map_area) |
|---|
| 315 | 231 | cmp w2, #DMA_FROM_DEVICE |
|---|
| 316 | | - b.eq __dma_inv_area |
|---|
| 232 | + b.eq __dma_flush_area |
|---|
| 317 | 233 | b __dma_clean_area |
|---|
| 318 | | -ENDPIPROC(__dma_map_area) |
|---|
| 234 | +SYM_FUNC_END_PI(__dma_map_area) |
|---|
| 319 | 235 | |
|---|
| 320 | 236 | /* |
|---|
| 321 | 237 | * __dma_unmap_area(start, size, dir) |
|---|
| .. | .. |
|---|
| 323 | 239 | * - size - size of region |
|---|
| 324 | 240 | * - dir - DMA direction |
|---|
| 325 | 241 | */ |
|---|
| 326 | | -ENTRY(__dma_unmap_area) |
|---|
| 242 | +SYM_FUNC_START_PI(__dma_unmap_area) |
|---|
| 327 | 243 | cmp w2, #DMA_TO_DEVICE |
|---|
| 328 | 244 | b.ne __dma_inv_area |
|---|
| 329 | 245 | ret |
|---|
| 330 | | -ENDPIPROC(__dma_unmap_area) |
|---|
| 246 | +SYM_FUNC_END_PI(__dma_unmap_area) |
|---|