Catalin Marinas | f1a0c4a | 2012-03-05 11:49:28 +0000 | [diff] [blame] | 1 | /* |
| 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 Murzin | a2d25a5 | 2014-12-01 10:53:08 +0000 | [diff] [blame] | 20 | #include <linux/errno.h> |
Catalin Marinas | f1a0c4a | 2012-03-05 11:49:28 +0000 | [diff] [blame] | 21 | #include <linux/linkage.h> |
| 22 | #include <linux/init.h> |
| 23 | #include <asm/assembler.h> |
Andre Przywara | 301bcfa | 2014-11-14 15:54:10 +0000 | [diff] [blame] | 24 | #include <asm/cpufeature.h> |
Marc Zyngier | 8d883b2 | 2015-06-01 10:47:41 +0100 | [diff] [blame] | 25 | #include <asm/alternative.h> |
Catalin Marinas | f1a0c4a | 2012-03-05 11:49:28 +0000 | [diff] [blame] | 26 | |
| 27 | #include "proc-macros.S" |
| 28 | |
| 29 | /* |
Catalin Marinas | f1a0c4a | 2012-03-05 11:49:28 +0000 | [diff] [blame] | 30 | * flush_icache_range(start,end) |
| 31 | * |
| 32 | * Ensure that the I and D caches are coherent within specified region. |
| 33 | * This is typically used when code has been written to a memory region, |
| 34 | * and will be executed. |
| 35 | * |
| 36 | * - start - virtual start address of region |
| 37 | * - end - virtual end address of region |
| 38 | */ |
| 39 | ENTRY(flush_icache_range) |
| 40 | /* FALLTHROUGH */ |
| 41 | |
| 42 | /* |
| 43 | * __flush_cache_user_range(start,end) |
| 44 | * |
| 45 | * Ensure that the I and D caches are coherent within specified region. |
| 46 | * This is typically used when code has been written to a memory region, |
| 47 | * and will be executed. |
| 48 | * |
| 49 | * - start - virtual start address of region |
| 50 | * - end - virtual end address of region |
| 51 | */ |
| 52 | ENTRY(__flush_cache_user_range) |
| 53 | dcache_line_size x2, x3 |
| 54 | sub x3, x2, #1 |
| 55 | bic x4, x0, x3 |
| 56 | 1: |
| 57 | USER(9f, dc cvau, x4 ) // clean D line to PoU |
| 58 | add x4, x4, x2 |
| 59 | cmp x4, x1 |
| 60 | b.lo 1b |
Will Deacon | dc60b77 | 2014-05-02 16:24:15 +0100 | [diff] [blame] | 61 | dsb ish |
Catalin Marinas | f1a0c4a | 2012-03-05 11:49:28 +0000 | [diff] [blame] | 62 | |
| 63 | icache_line_size x2, x3 |
| 64 | sub x3, x2, #1 |
| 65 | bic x4, x0, x3 |
| 66 | 1: |
| 67 | USER(9f, ic ivau, x4 ) // invalidate I line PoU |
| 68 | add x4, x4, x2 |
| 69 | cmp x4, x1 |
| 70 | b.lo 1b |
Will Deacon | dc60b77 | 2014-05-02 16:24:15 +0100 | [diff] [blame] | 71 | dsb ish |
Catalin Marinas | f1a0c4a | 2012-03-05 11:49:28 +0000 | [diff] [blame] | 72 | isb |
Vladimir Murzin | a2d25a5 | 2014-12-01 10:53:08 +0000 | [diff] [blame] | 73 | mov x0, #0 |
| 74 | ret |
| 75 | 9: |
| 76 | mov x0, #-EFAULT |
Catalin Marinas | f1a0c4a | 2012-03-05 11:49:28 +0000 | [diff] [blame] | 77 | ret |
| 78 | ENDPROC(flush_icache_range) |
| 79 | ENDPROC(__flush_cache_user_range) |
| 80 | |
| 81 | /* |
Jingoo Han | 03324e6 | 2014-01-21 01:17:47 +0000 | [diff] [blame] | 82 | * __flush_dcache_area(kaddr, size) |
Catalin Marinas | f1a0c4a | 2012-03-05 11:49:28 +0000 | [diff] [blame] | 83 | * |
| 84 | * Ensure that the data held in the page kaddr is written back to the |
| 85 | * page in question. |
| 86 | * |
| 87 | * - kaddr - kernel address |
| 88 | * - size - size in question |
| 89 | */ |
| 90 | ENTRY(__flush_dcache_area) |
| 91 | dcache_line_size x2, x3 |
| 92 | add x1, x0, x1 |
| 93 | sub x3, x2, #1 |
| 94 | bic x0, x0, x3 |
| 95 | 1: dc civac, x0 // clean & invalidate D line / unified line |
| 96 | add x0, x0, x2 |
| 97 | cmp x0, x1 |
| 98 | b.lo 1b |
| 99 | dsb sy |
| 100 | ret |
Ard Biesheuvel | 2079184 | 2015-10-08 20:02:03 +0100 | [diff] [blame] | 101 | ENDPIPROC(__flush_dcache_area) |
Catalin Marinas | 7363590 | 2013-05-21 17:35:19 +0100 | [diff] [blame] | 102 | |
| 103 | /* |
Catalin Marinas | c218bca | 2014-03-26 18:25:55 +0000 | [diff] [blame] | 104 | * __inval_cache_range(start, end) |
| 105 | * - start - start address of region |
| 106 | * - end - end address of region |
| 107 | */ |
| 108 | ENTRY(__inval_cache_range) |
| 109 | /* FALLTHROUGH */ |
| 110 | |
| 111 | /* |
Catalin Marinas | 7363590 | 2013-05-21 17:35:19 +0100 | [diff] [blame] | 112 | * __dma_inv_range(start, end) |
| 113 | * - start - virtual start address of region |
| 114 | * - end - virtual end address of region |
| 115 | */ |
| 116 | __dma_inv_range: |
| 117 | dcache_line_size x2, x3 |
| 118 | sub x3, x2, #1 |
Catalin Marinas | ebf81a9 | 2014-04-01 18:32:55 +0100 | [diff] [blame] | 119 | tst x1, x3 // end cache line aligned? |
Catalin Marinas | 7363590 | 2013-05-21 17:35:19 +0100 | [diff] [blame] | 120 | bic x1, x1, x3 |
Catalin Marinas | ebf81a9 | 2014-04-01 18:32:55 +0100 | [diff] [blame] | 121 | b.eq 1f |
| 122 | dc civac, x1 // clean & invalidate D / U line |
| 123 | 1: tst x0, x3 // start cache line aligned? |
| 124 | bic x0, x0, x3 |
| 125 | b.eq 2f |
| 126 | dc civac, x0 // clean & invalidate D / U line |
| 127 | b 3f |
| 128 | 2: dc ivac, x0 // invalidate D / U line |
| 129 | 3: add x0, x0, x2 |
Catalin Marinas | 7363590 | 2013-05-21 17:35:19 +0100 | [diff] [blame] | 130 | cmp x0, x1 |
Catalin Marinas | ebf81a9 | 2014-04-01 18:32:55 +0100 | [diff] [blame] | 131 | b.lo 2b |
Catalin Marinas | 7363590 | 2013-05-21 17:35:19 +0100 | [diff] [blame] | 132 | dsb sy |
| 133 | ret |
Ard Biesheuvel | 2079184 | 2015-10-08 20:02:03 +0100 | [diff] [blame] | 134 | ENDPIPROC(__inval_cache_range) |
Catalin Marinas | 7363590 | 2013-05-21 17:35:19 +0100 | [diff] [blame] | 135 | ENDPROC(__dma_inv_range) |
| 136 | |
| 137 | /* |
| 138 | * __dma_clean_range(start, end) |
| 139 | * - start - virtual start address of region |
| 140 | * - end - virtual end address of region |
| 141 | */ |
| 142 | __dma_clean_range: |
| 143 | dcache_line_size x2, x3 |
| 144 | sub x3, x2, #1 |
| 145 | bic x0, x0, x3 |
Daniel Thompson | 271d35e | 2015-07-22 12:21:02 +0100 | [diff] [blame] | 146 | 1: |
| 147 | alternative_if_not ARM64_WORKAROUND_CLEAN_CACHE |
| 148 | dc cvac, x0 |
| 149 | alternative_else |
| 150 | dc civac, x0 |
| 151 | alternative_endif |
Catalin Marinas | 7363590 | 2013-05-21 17:35:19 +0100 | [diff] [blame] | 152 | add x0, x0, x2 |
| 153 | cmp x0, x1 |
| 154 | b.lo 1b |
| 155 | dsb sy |
| 156 | ret |
| 157 | ENDPROC(__dma_clean_range) |
| 158 | |
| 159 | /* |
| 160 | * __dma_flush_range(start, end) |
| 161 | * - start - virtual start address of region |
| 162 | * - end - virtual end address of region |
| 163 | */ |
| 164 | ENTRY(__dma_flush_range) |
| 165 | dcache_line_size x2, x3 |
| 166 | sub x3, x2, #1 |
| 167 | bic x0, x0, x3 |
| 168 | 1: dc civac, x0 // clean & invalidate D / U line |
| 169 | add x0, x0, x2 |
| 170 | cmp x0, x1 |
| 171 | b.lo 1b |
| 172 | dsb sy |
| 173 | ret |
Ard Biesheuvel | 2079184 | 2015-10-08 20:02:03 +0100 | [diff] [blame] | 174 | ENDPIPROC(__dma_flush_range) |
Catalin Marinas | 7363590 | 2013-05-21 17:35:19 +0100 | [diff] [blame] | 175 | |
| 176 | /* |
| 177 | * __dma_map_area(start, size, dir) |
| 178 | * - start - kernel virtual start address |
| 179 | * - size - size of region |
| 180 | * - dir - DMA direction |
| 181 | */ |
| 182 | ENTRY(__dma_map_area) |
| 183 | add x1, x1, x0 |
| 184 | cmp w2, #DMA_FROM_DEVICE |
| 185 | b.eq __dma_inv_range |
| 186 | b __dma_clean_range |
Ard Biesheuvel | 2079184 | 2015-10-08 20:02:03 +0100 | [diff] [blame] | 187 | ENDPIPROC(__dma_map_area) |
Catalin Marinas | 7363590 | 2013-05-21 17:35:19 +0100 | [diff] [blame] | 188 | |
| 189 | /* |
| 190 | * __dma_unmap_area(start, size, dir) |
| 191 | * - start - kernel virtual start address |
| 192 | * - size - size of region |
| 193 | * - dir - DMA direction |
| 194 | */ |
| 195 | ENTRY(__dma_unmap_area) |
| 196 | add x1, x1, x0 |
| 197 | cmp w2, #DMA_TO_DEVICE |
| 198 | b.ne __dma_inv_range |
| 199 | ret |
Ard Biesheuvel | 2079184 | 2015-10-08 20:02:03 +0100 | [diff] [blame] | 200 | ENDPIPROC(__dma_unmap_area) |