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 | |
Catalin Marinas | f1a0c4a | 2012-03-05 11:49:28 +0000 | [diff] [blame] | 27 | /* |
Catalin Marinas | f1a0c4a | 2012-03-05 11:49:28 +0000 | [diff] [blame] | 28 | * 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 | */ |
| 37 | ENTRY(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 | */ |
| 50 | ENTRY(__flush_cache_user_range) |
| 51 | dcache_line_size x2, x3 |
| 52 | sub x3, x2, #1 |
| 53 | bic x4, x0, x3 |
| 54 | 1: |
Andre Przywara | 290622e | 2016-06-28 18:07:28 +0100 | [diff] [blame] | 55 | user_alt 9f, "dc cvau, x4", "dc civac, x4", ARM64_WORKAROUND_CLEAN_CACHE |
Catalin Marinas | f1a0c4a | 2012-03-05 11:49:28 +0000 | [diff] [blame] | 56 | add x4, x4, x2 |
| 57 | cmp x4, x1 |
| 58 | b.lo 1b |
Will Deacon | dc60b77 | 2014-05-02 16:24:15 +0100 | [diff] [blame] | 59 | dsb ish |
Catalin Marinas | f1a0c4a | 2012-03-05 11:49:28 +0000 | [diff] [blame] | 60 | |
| 61 | icache_line_size x2, x3 |
| 62 | sub x3, x2, #1 |
| 63 | bic x4, x0, x3 |
| 64 | 1: |
| 65 | USER(9f, ic ivau, x4 ) // invalidate I line PoU |
| 66 | add x4, x4, x2 |
| 67 | cmp x4, x1 |
| 68 | b.lo 1b |
Will Deacon | dc60b77 | 2014-05-02 16:24:15 +0100 | [diff] [blame] | 69 | dsb ish |
Catalin Marinas | f1a0c4a | 2012-03-05 11:49:28 +0000 | [diff] [blame] | 70 | isb |
Vladimir Murzin | a2d25a5 | 2014-12-01 10:53:08 +0000 | [diff] [blame] | 71 | mov x0, #0 |
| 72 | ret |
| 73 | 9: |
| 74 | mov x0, #-EFAULT |
Catalin Marinas | f1a0c4a | 2012-03-05 11:49:28 +0000 | [diff] [blame] | 75 | ret |
| 76 | ENDPROC(flush_icache_range) |
| 77 | ENDPROC(__flush_cache_user_range) |
| 78 | |
| 79 | /* |
Jingoo Han | 03324e6 | 2014-01-21 01:17:47 +0000 | [diff] [blame] | 80 | * __flush_dcache_area(kaddr, size) |
Catalin Marinas | f1a0c4a | 2012-03-05 11:49:28 +0000 | [diff] [blame] | 81 | * |
Ashok Kumar | 0a28714 | 2015-12-17 01:38:32 -0800 | [diff] [blame] | 82 | * Ensure that any D-cache lines for the interval [kaddr, kaddr+size) |
| 83 | * are cleaned and invalidated to the PoC. |
Catalin Marinas | f1a0c4a | 2012-03-05 11:49:28 +0000 | [diff] [blame] | 84 | * |
| 85 | * - kaddr - kernel address |
| 86 | * - size - size in question |
| 87 | */ |
| 88 | ENTRY(__flush_dcache_area) |
Ashok Kumar | 0a28714 | 2015-12-17 01:38:32 -0800 | [diff] [blame] | 89 | dcache_by_line_op civac, sy, x0, x1, x2, x3 |
Catalin Marinas | f1a0c4a | 2012-03-05 11:49:28 +0000 | [diff] [blame] | 90 | ret |
Ard Biesheuvel | 2079184 | 2015-10-08 20:02:03 +0100 | [diff] [blame] | 91 | ENDPIPROC(__flush_dcache_area) |
Catalin Marinas | 7363590 | 2013-05-21 17:35:19 +0100 | [diff] [blame] | 92 | |
| 93 | /* |
Ashok Kumar | 0a28714 | 2015-12-17 01:38:32 -0800 | [diff] [blame] | 94 | * __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 | */ |
| 102 | ENTRY(__clean_dcache_area_pou) |
| 103 | dcache_by_line_op cvau, ish, x0, x1, x2, x3 |
| 104 | ret |
| 105 | ENDPROC(__clean_dcache_area_pou) |
| 106 | |
| 107 | /* |
Kwangwoo Lee | d34fdb7 | 2016-08-02 09:50:50 +0900 | [diff] [blame] | 108 | * __dma_inv_area(start, size) |
| 109 | * - start - virtual start address of region |
| 110 | * - size - size in question |
| 111 | */ |
| 112 | __dma_inv_area: |
| 113 | add x1, x1, x0 |
| 114 | /* FALLTHROUGH */ |
| 115 | |
| 116 | /* |
Catalin Marinas | c218bca | 2014-03-26 18:25:55 +0000 | [diff] [blame] | 117 | * __inval_cache_range(start, end) |
| 118 | * - start - start address of region |
| 119 | * - end - end address of region |
| 120 | */ |
| 121 | ENTRY(__inval_cache_range) |
Catalin Marinas | 7363590 | 2013-05-21 17:35:19 +0100 | [diff] [blame] | 122 | dcache_line_size x2, x3 |
| 123 | sub x3, x2, #1 |
Catalin Marinas | ebf81a9 | 2014-04-01 18:32:55 +0100 | [diff] [blame] | 124 | tst x1, x3 // end cache line aligned? |
Catalin Marinas | 7363590 | 2013-05-21 17:35:19 +0100 | [diff] [blame] | 125 | bic x1, x1, x3 |
Catalin Marinas | ebf81a9 | 2014-04-01 18:32:55 +0100 | [diff] [blame] | 126 | b.eq 1f |
| 127 | dc civac, x1 // clean & invalidate D / U line |
| 128 | 1: tst x0, x3 // start cache line aligned? |
| 129 | bic x0, x0, x3 |
| 130 | b.eq 2f |
| 131 | dc civac, x0 // clean & invalidate D / U line |
| 132 | b 3f |
| 133 | 2: dc ivac, x0 // invalidate D / U line |
| 134 | 3: add x0, x0, x2 |
Catalin Marinas | 7363590 | 2013-05-21 17:35:19 +0100 | [diff] [blame] | 135 | cmp x0, x1 |
Catalin Marinas | ebf81a9 | 2014-04-01 18:32:55 +0100 | [diff] [blame] | 136 | b.lo 2b |
Catalin Marinas | 7363590 | 2013-05-21 17:35:19 +0100 | [diff] [blame] | 137 | dsb sy |
| 138 | ret |
Ard Biesheuvel | 2079184 | 2015-10-08 20:02:03 +0100 | [diff] [blame] | 139 | ENDPIPROC(__inval_cache_range) |
Kwangwoo Lee | d34fdb7 | 2016-08-02 09:50:50 +0900 | [diff] [blame] | 140 | ENDPROC(__dma_inv_area) |
Catalin Marinas | 7363590 | 2013-05-21 17:35:19 +0100 | [diff] [blame] | 141 | |
| 142 | /* |
Kwangwoo Lee | d34fdb7 | 2016-08-02 09:50:50 +0900 | [diff] [blame] | 143 | * __clean_dcache_area_poc(kaddr, size) |
| 144 | * |
| 145 | * Ensure that any D-cache lines for the interval [kaddr, kaddr+size) |
| 146 | * are cleaned to the PoC. |
| 147 | * |
| 148 | * - kaddr - kernel address |
| 149 | * - size - size in question |
Catalin Marinas | 7363590 | 2013-05-21 17:35:19 +0100 | [diff] [blame] | 150 | */ |
Kwangwoo Lee | d34fdb7 | 2016-08-02 09:50:50 +0900 | [diff] [blame] | 151 | ENTRY(__clean_dcache_area_poc) |
| 152 | /* FALLTHROUGH */ |
Catalin Marinas | 7363590 | 2013-05-21 17:35:19 +0100 | [diff] [blame] | 153 | |
| 154 | /* |
Kwangwoo Lee | d34fdb7 | 2016-08-02 09:50:50 +0900 | [diff] [blame] | 155 | * __dma_clean_area(start, size) |
Catalin Marinas | 7363590 | 2013-05-21 17:35:19 +0100 | [diff] [blame] | 156 | * - start - virtual start address of region |
Kwangwoo Lee | d34fdb7 | 2016-08-02 09:50:50 +0900 | [diff] [blame] | 157 | * - size - size in question |
Catalin Marinas | 7363590 | 2013-05-21 17:35:19 +0100 | [diff] [blame] | 158 | */ |
Kwangwoo Lee | d34fdb7 | 2016-08-02 09:50:50 +0900 | [diff] [blame] | 159 | __dma_clean_area: |
| 160 | dcache_by_line_op cvac, sy, x0, x1, x2, x3 |
Catalin Marinas | 7363590 | 2013-05-21 17:35:19 +0100 | [diff] [blame] | 161 | ret |
Kwangwoo Lee | d34fdb7 | 2016-08-02 09:50:50 +0900 | [diff] [blame] | 162 | ENDPIPROC(__clean_dcache_area_poc) |
| 163 | ENDPROC(__dma_clean_area) |
| 164 | |
| 165 | /* |
| 166 | * __dma_flush_area(start, size) |
| 167 | * |
| 168 | * clean & invalidate D / U line |
| 169 | * |
| 170 | * - start - virtual start address of region |
| 171 | * - size - size in question |
| 172 | */ |
| 173 | ENTRY(__dma_flush_area) |
| 174 | dcache_by_line_op civac, sy, x0, x1, x2, x3 |
| 175 | ret |
| 176 | ENDPIPROC(__dma_flush_area) |
Catalin Marinas | 7363590 | 2013-05-21 17:35:19 +0100 | [diff] [blame] | 177 | |
| 178 | /* |
| 179 | * __dma_map_area(start, size, dir) |
| 180 | * - start - kernel virtual start address |
| 181 | * - size - size of region |
| 182 | * - dir - DMA direction |
| 183 | */ |
| 184 | ENTRY(__dma_map_area) |
Catalin Marinas | 7363590 | 2013-05-21 17:35:19 +0100 | [diff] [blame] | 185 | cmp w2, #DMA_FROM_DEVICE |
Kwangwoo Lee | d34fdb7 | 2016-08-02 09:50:50 +0900 | [diff] [blame] | 186 | b.eq __dma_inv_area |
| 187 | b __dma_clean_area |
Ard Biesheuvel | 2079184 | 2015-10-08 20:02:03 +0100 | [diff] [blame] | 188 | ENDPIPROC(__dma_map_area) |
Catalin Marinas | 7363590 | 2013-05-21 17:35:19 +0100 | [diff] [blame] | 189 | |
| 190 | /* |
| 191 | * __dma_unmap_area(start, size, dir) |
| 192 | * - start - kernel virtual start address |
| 193 | * - size - size of region |
| 194 | * - dir - DMA direction |
| 195 | */ |
| 196 | ENTRY(__dma_unmap_area) |
Catalin Marinas | 7363590 | 2013-05-21 17:35:19 +0100 | [diff] [blame] | 197 | cmp w2, #DMA_TO_DEVICE |
Kwangwoo Lee | d34fdb7 | 2016-08-02 09:50:50 +0900 | [diff] [blame] | 198 | b.ne __dma_inv_area |
Catalin Marinas | 7363590 | 2013-05-21 17:35:19 +0100 | [diff] [blame] | 199 | ret |
Ard Biesheuvel | 2079184 | 2015-10-08 20:02:03 +0100 | [diff] [blame] | 200 | ENDPIPROC(__dma_unmap_area) |