Catalin Marinas | 0be7320 | 2012-03-05 11:49:26 +0000 | [diff] [blame] | 1 | /* |
Geoff Levand | 7b7293a | 2016-04-27 17:47:00 +0100 | [diff] [blame] | 2 | * Based on arch/arm/include/asm/assembler.h, arch/arm/mm/proc-macros.S |
Catalin Marinas | 0be7320 | 2012-03-05 11:49:26 +0000 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 1996-2000 Russell King |
| 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 | #ifndef __ASSEMBLY__ |
| 20 | #error "Only include this from assembly code" |
| 21 | #endif |
| 22 | |
Marc Zyngier | f3e3927 | 2015-02-20 13:53:13 +0000 | [diff] [blame] | 23 | #ifndef __ASM_ASSEMBLER_H |
| 24 | #define __ASM_ASSEMBLER_H |
| 25 | |
Geoff Levand | 7b7293a | 2016-04-27 17:47:00 +0100 | [diff] [blame] | 26 | #include <asm/asm-offsets.h> |
Andre Przywara | 823066d | 2016-06-28 18:07:29 +0100 | [diff] [blame] | 27 | #include <asm/cpufeature.h> |
Julien Thierry | e28cc02 | 2017-10-25 10:04:32 +0100 | [diff] [blame] | 28 | #include <asm/debug-monitors.h> |
Geoff Levand | 5003dbd | 2016-04-27 17:47:10 +0100 | [diff] [blame] | 29 | #include <asm/page.h> |
Geoff Levand | 7b7293a | 2016-04-27 17:47:00 +0100 | [diff] [blame] | 30 | #include <asm/pgtable-hwdef.h> |
Catalin Marinas | 0be7320 | 2012-03-05 11:49:26 +0000 | [diff] [blame] | 31 | #include <asm/ptrace.h> |
Will Deacon | 2a28307 | 2014-04-29 19:04:06 +0100 | [diff] [blame] | 32 | #include <asm/thread_info.h> |
Catalin Marinas | 0be7320 | 2012-03-05 11:49:26 +0000 | [diff] [blame] | 33 | |
James Morse | 0fbeb31 | 2017-11-02 12:12:34 +0000 | [diff] [blame] | 34 | .macro save_and_disable_daif, flags |
| 35 | mrs \flags, daif |
| 36 | msr daifset, #0xf |
| 37 | .endm |
| 38 | |
| 39 | .macro disable_daif |
| 40 | msr daifset, #0xf |
| 41 | .endm |
| 42 | |
| 43 | .macro enable_daif |
| 44 | msr daifclr, #0xf |
| 45 | .endm |
| 46 | |
| 47 | .macro restore_daif, flags:req |
| 48 | msr daif, \flags |
| 49 | .endm |
| 50 | |
James Morse | b55a5a1 | 2017-11-02 12:12:39 +0000 | [diff] [blame] | 51 | /* Only on aarch64 pstate, PSR_D_BIT is different for aarch32 */ |
| 52 | .macro inherit_daif, pstate:req, tmp:req |
| 53 | and \tmp, \pstate, #(PSR_D_BIT | PSR_A_BIT | PSR_I_BIT | PSR_F_BIT) |
| 54 | msr daif, \tmp |
| 55 | .endm |
| 56 | |
James Morse | b282e1c | 2017-11-02 12:12:41 +0000 | [diff] [blame] | 57 | /* IRQ is the lowest priority flag, unconditionally unmask the rest. */ |
| 58 | .macro enable_da_f |
| 59 | msr daifclr, #(8 | 4 | 1) |
| 60 | .endm |
| 61 | |
Catalin Marinas | 0be7320 | 2012-03-05 11:49:26 +0000 | [diff] [blame] | 62 | /* |
Catalin Marinas | 0be7320 | 2012-03-05 11:49:26 +0000 | [diff] [blame] | 63 | * Enable and disable interrupts. |
| 64 | */ |
| 65 | .macro disable_irq |
| 66 | msr daifset, #2 |
| 67 | .endm |
| 68 | |
| 69 | .macro enable_irq |
| 70 | msr daifclr, #2 |
| 71 | .endm |
| 72 | |
Catalin Marinas | 4b65a5d | 2016-07-01 16:53:00 +0100 | [diff] [blame] | 73 | .macro save_and_disable_irq, flags |
| 74 | mrs \flags, daif |
| 75 | msr daifset, #2 |
| 76 | .endm |
| 77 | |
| 78 | .macro restore_irq, flags |
| 79 | msr daif, \flags |
| 80 | .endm |
| 81 | |
Catalin Marinas | 0be7320 | 2012-03-05 11:49:26 +0000 | [diff] [blame] | 82 | .macro enable_dbg |
| 83 | msr daifclr, #8 |
| 84 | .endm |
| 85 | |
Will Deacon | 2a28307 | 2014-04-29 19:04:06 +0100 | [diff] [blame] | 86 | .macro disable_step_tsk, flgs, tmp |
| 87 | tbz \flgs, #TIF_SINGLESTEP, 9990f |
Catalin Marinas | 0be7320 | 2012-03-05 11:49:26 +0000 | [diff] [blame] | 88 | mrs \tmp, mdscr_el1 |
Julien Thierry | e28cc02 | 2017-10-25 10:04:32 +0100 | [diff] [blame] | 89 | bic \tmp, \tmp, #DBG_MDSCR_SS |
Catalin Marinas | 0be7320 | 2012-03-05 11:49:26 +0000 | [diff] [blame] | 90 | msr mdscr_el1, \tmp |
Will Deacon | 2a28307 | 2014-04-29 19:04:06 +0100 | [diff] [blame] | 91 | isb // Synchronise with enable_dbg |
| 92 | 9990: |
Catalin Marinas | 0be7320 | 2012-03-05 11:49:26 +0000 | [diff] [blame] | 93 | .endm |
| 94 | |
James Morse | 84d0fb1 | 2017-11-02 12:12:38 +0000 | [diff] [blame] | 95 | /* call with daif masked */ |
Will Deacon | 2a28307 | 2014-04-29 19:04:06 +0100 | [diff] [blame] | 96 | .macro enable_step_tsk, flgs, tmp |
| 97 | tbz \flgs, #TIF_SINGLESTEP, 9990f |
Catalin Marinas | 0be7320 | 2012-03-05 11:49:26 +0000 | [diff] [blame] | 98 | mrs \tmp, mdscr_el1 |
Julien Thierry | e28cc02 | 2017-10-25 10:04:32 +0100 | [diff] [blame] | 99 | orr \tmp, \tmp, #DBG_MDSCR_SS |
Catalin Marinas | 0be7320 | 2012-03-05 11:49:26 +0000 | [diff] [blame] | 100 | msr mdscr_el1, \tmp |
Will Deacon | 2a28307 | 2014-04-29 19:04:06 +0100 | [diff] [blame] | 101 | 9990: |
Catalin Marinas | 0be7320 | 2012-03-05 11:49:26 +0000 | [diff] [blame] | 102 | .endm |
| 103 | |
Will Deacon | 2a28307 | 2014-04-29 19:04:06 +0100 | [diff] [blame] | 104 | /* |
Catalin Marinas | 0be7320 | 2012-03-05 11:49:26 +0000 | [diff] [blame] | 105 | * SMP data memory barrier |
| 106 | */ |
| 107 | .macro smp_dmb, opt |
Catalin Marinas | 0be7320 | 2012-03-05 11:49:26 +0000 | [diff] [blame] | 108 | dmb \opt |
Catalin Marinas | 0be7320 | 2012-03-05 11:49:26 +0000 | [diff] [blame] | 109 | .endm |
| 110 | |
Ard Biesheuvel | 6c94f27 | 2016-01-01 15:02:12 +0100 | [diff] [blame] | 111 | /* |
James Morse | 68ddbf0 | 2018-01-15 19:38:59 +0000 | [diff] [blame] | 112 | * RAS Error Synchronization barrier |
| 113 | */ |
| 114 | .macro esb |
| 115 | hint #16 |
| 116 | .endm |
| 117 | |
| 118 | /* |
Will Deacon | 669474e | 2018-02-05 15:34:16 +0000 | [diff] [blame^] | 119 | * Value prediction barrier |
| 120 | */ |
| 121 | .macro csdb |
| 122 | hint #20 |
| 123 | .endm |
| 124 | |
| 125 | /* |
Will Deacon | f99a250 | 2016-09-06 16:40:23 +0100 | [diff] [blame] | 126 | * NOP sequence |
| 127 | */ |
| 128 | .macro nops, num |
| 129 | .rept \num |
| 130 | nop |
| 131 | .endr |
| 132 | .endm |
| 133 | |
| 134 | /* |
Ard Biesheuvel | 6c94f27 | 2016-01-01 15:02:12 +0100 | [diff] [blame] | 135 | * Emit an entry into the exception table |
| 136 | */ |
| 137 | .macro _asm_extable, from, to |
| 138 | .pushsection __ex_table, "a" |
| 139 | .align 3 |
| 140 | .long (\from - .), (\to - .) |
| 141 | .popsection |
| 142 | .endm |
| 143 | |
Catalin Marinas | 0be7320 | 2012-03-05 11:49:26 +0000 | [diff] [blame] | 144 | #define USER(l, x...) \ |
| 145 | 9999: x; \ |
Ard Biesheuvel | 6c94f27 | 2016-01-01 15:02:12 +0100 | [diff] [blame] | 146 | _asm_extable 9999b, l |
Catalin Marinas | 0be7320 | 2012-03-05 11:49:26 +0000 | [diff] [blame] | 147 | |
| 148 | /* |
| 149 | * Register aliases. |
| 150 | */ |
| 151 | lr .req x30 // link register |
Marc Zyngier | dc637f1 | 2012-10-19 17:37:35 +0100 | [diff] [blame] | 152 | |
| 153 | /* |
| 154 | * Vector entry |
| 155 | */ |
| 156 | .macro ventry label |
| 157 | .align 7 |
| 158 | b \label |
| 159 | .endm |
Matthew Leach | e68beda | 2013-10-11 14:52:15 +0100 | [diff] [blame] | 160 | |
| 161 | /* |
| 162 | * Select code when configured for BE. |
| 163 | */ |
| 164 | #ifdef CONFIG_CPU_BIG_ENDIAN |
| 165 | #define CPU_BE(code...) code |
| 166 | #else |
| 167 | #define CPU_BE(code...) |
| 168 | #endif |
| 169 | |
| 170 | /* |
| 171 | * Select code when configured for LE. |
| 172 | */ |
| 173 | #ifdef CONFIG_CPU_BIG_ENDIAN |
| 174 | #define CPU_LE(code...) |
| 175 | #else |
| 176 | #define CPU_LE(code...) code |
| 177 | #endif |
| 178 | |
Matthew Leach | 55b8954 | 2013-10-11 14:52:13 +0100 | [diff] [blame] | 179 | /* |
| 180 | * Define a macro that constructs a 64-bit value by concatenating two |
| 181 | * 32-bit registers. Note that on big endian systems the order of the |
| 182 | * registers is swapped. |
| 183 | */ |
| 184 | #ifndef CONFIG_CPU_BIG_ENDIAN |
| 185 | .macro regs_to_64, rd, lbits, hbits |
| 186 | #else |
| 187 | .macro regs_to_64, rd, hbits, lbits |
| 188 | #endif |
| 189 | orr \rd, \lbits, \hbits, lsl #32 |
| 190 | .endm |
Marc Zyngier | f3e3927 | 2015-02-20 13:53:13 +0000 | [diff] [blame] | 191 | |
Ard Biesheuvel | b784a5d | 2015-03-04 19:45:38 +0100 | [diff] [blame] | 192 | /* |
| 193 | * Pseudo-ops for PC-relative adr/ldr/str <reg>, <symbol> where |
Ard Biesheuvel | 41c066f | 2017-01-11 14:54:53 +0000 | [diff] [blame] | 194 | * <symbol> is within the range +/- 4 GB of the PC when running |
| 195 | * in core kernel context. In module context, a movz/movk sequence |
| 196 | * is used, since modules may be loaded far away from the kernel |
| 197 | * when KASLR is in effect. |
Ard Biesheuvel | b784a5d | 2015-03-04 19:45:38 +0100 | [diff] [blame] | 198 | */ |
| 199 | /* |
| 200 | * @dst: destination register (64 bit wide) |
| 201 | * @sym: name of the symbol |
Ard Biesheuvel | b784a5d | 2015-03-04 19:45:38 +0100 | [diff] [blame] | 202 | */ |
Ard Biesheuvel | 41c066f | 2017-01-11 14:54:53 +0000 | [diff] [blame] | 203 | .macro adr_l, dst, sym |
| 204 | #ifndef MODULE |
Ard Biesheuvel | b784a5d | 2015-03-04 19:45:38 +0100 | [diff] [blame] | 205 | adrp \dst, \sym |
| 206 | add \dst, \dst, :lo12:\sym |
Ard Biesheuvel | 41c066f | 2017-01-11 14:54:53 +0000 | [diff] [blame] | 207 | #else |
| 208 | movz \dst, #:abs_g3:\sym |
| 209 | movk \dst, #:abs_g2_nc:\sym |
| 210 | movk \dst, #:abs_g1_nc:\sym |
| 211 | movk \dst, #:abs_g0_nc:\sym |
| 212 | #endif |
Ard Biesheuvel | b784a5d | 2015-03-04 19:45:38 +0100 | [diff] [blame] | 213 | .endm |
| 214 | |
| 215 | /* |
| 216 | * @dst: destination register (32 or 64 bit wide) |
| 217 | * @sym: name of the symbol |
| 218 | * @tmp: optional 64-bit scratch register to be used if <dst> is a |
| 219 | * 32-bit wide register, in which case it cannot be used to hold |
| 220 | * the address |
| 221 | */ |
| 222 | .macro ldr_l, dst, sym, tmp= |
Ard Biesheuvel | 41c066f | 2017-01-11 14:54:53 +0000 | [diff] [blame] | 223 | #ifndef MODULE |
Ard Biesheuvel | b784a5d | 2015-03-04 19:45:38 +0100 | [diff] [blame] | 224 | .ifb \tmp |
| 225 | adrp \dst, \sym |
| 226 | ldr \dst, [\dst, :lo12:\sym] |
| 227 | .else |
| 228 | adrp \tmp, \sym |
| 229 | ldr \dst, [\tmp, :lo12:\sym] |
| 230 | .endif |
Ard Biesheuvel | 41c066f | 2017-01-11 14:54:53 +0000 | [diff] [blame] | 231 | #else |
| 232 | .ifb \tmp |
| 233 | adr_l \dst, \sym |
| 234 | ldr \dst, [\dst] |
| 235 | .else |
| 236 | adr_l \tmp, \sym |
| 237 | ldr \dst, [\tmp] |
| 238 | .endif |
| 239 | #endif |
Ard Biesheuvel | b784a5d | 2015-03-04 19:45:38 +0100 | [diff] [blame] | 240 | .endm |
| 241 | |
| 242 | /* |
| 243 | * @src: source register (32 or 64 bit wide) |
| 244 | * @sym: name of the symbol |
| 245 | * @tmp: mandatory 64-bit scratch register to calculate the address |
| 246 | * while <src> needs to be preserved. |
| 247 | */ |
| 248 | .macro str_l, src, sym, tmp |
Ard Biesheuvel | 41c066f | 2017-01-11 14:54:53 +0000 | [diff] [blame] | 249 | #ifndef MODULE |
Ard Biesheuvel | b784a5d | 2015-03-04 19:45:38 +0100 | [diff] [blame] | 250 | adrp \tmp, \sym |
| 251 | str \src, [\tmp, :lo12:\sym] |
Ard Biesheuvel | 41c066f | 2017-01-11 14:54:53 +0000 | [diff] [blame] | 252 | #else |
| 253 | adr_l \tmp, \sym |
| 254 | str \src, [\tmp] |
| 255 | #endif |
Ard Biesheuvel | b784a5d | 2015-03-04 19:45:38 +0100 | [diff] [blame] | 256 | .endm |
| 257 | |
James Morse | aa4d5d3 | 2015-12-10 10:22:39 +0000 | [diff] [blame] | 258 | /* |
Ard Biesheuvel | 8ea41b1 | 2017-07-15 17:23:13 +0100 | [diff] [blame] | 259 | * @dst: Result of per_cpu(sym, smp_processor_id()), can be SP for |
| 260 | * non-module code |
James Morse | aa4d5d3 | 2015-12-10 10:22:39 +0000 | [diff] [blame] | 261 | * @sym: The name of the per-cpu variable |
James Morse | aa4d5d3 | 2015-12-10 10:22:39 +0000 | [diff] [blame] | 262 | * @tmp: scratch register |
| 263 | */ |
Mark Rutland | 1b7e229 | 2016-11-03 20:23:12 +0000 | [diff] [blame] | 264 | .macro adr_this_cpu, dst, sym, tmp |
Ard Biesheuvel | 8ea41b1 | 2017-07-15 17:23:13 +0100 | [diff] [blame] | 265 | #ifndef MODULE |
| 266 | adrp \tmp, \sym |
| 267 | add \dst, \tmp, #:lo12:\sym |
| 268 | #else |
Mark Rutland | 1b7e229 | 2016-11-03 20:23:12 +0000 | [diff] [blame] | 269 | adr_l \dst, \sym |
Ard Biesheuvel | 8ea41b1 | 2017-07-15 17:23:13 +0100 | [diff] [blame] | 270 | #endif |
James Morse | 6d99b68 | 2018-01-08 15:38:06 +0000 | [diff] [blame] | 271 | alternative_if_not ARM64_HAS_VIRT_HOST_EXTN |
James Morse | aa4d5d3 | 2015-12-10 10:22:39 +0000 | [diff] [blame] | 272 | mrs \tmp, tpidr_el1 |
James Morse | 6d99b68 | 2018-01-08 15:38:06 +0000 | [diff] [blame] | 273 | alternative_else |
| 274 | mrs \tmp, tpidr_el2 |
| 275 | alternative_endif |
Mark Rutland | 1b7e229 | 2016-11-03 20:23:12 +0000 | [diff] [blame] | 276 | add \dst, \dst, \tmp |
| 277 | .endm |
| 278 | |
| 279 | /* |
| 280 | * @dst: Result of READ_ONCE(per_cpu(sym, smp_processor_id())) |
| 281 | * @sym: The name of the per-cpu variable |
| 282 | * @tmp: scratch register |
| 283 | */ |
| 284 | .macro ldr_this_cpu dst, sym, tmp |
| 285 | adr_l \dst, \sym |
James Morse | 6d99b68 | 2018-01-08 15:38:06 +0000 | [diff] [blame] | 286 | alternative_if_not ARM64_HAS_VIRT_HOST_EXTN |
Mark Rutland | 1b7e229 | 2016-11-03 20:23:12 +0000 | [diff] [blame] | 287 | mrs \tmp, tpidr_el1 |
James Morse | 6d99b68 | 2018-01-08 15:38:06 +0000 | [diff] [blame] | 288 | alternative_else |
| 289 | mrs \tmp, tpidr_el2 |
| 290 | alternative_endif |
Mark Rutland | 1b7e229 | 2016-11-03 20:23:12 +0000 | [diff] [blame] | 291 | ldr \dst, [\dst, \tmp] |
James Morse | aa4d5d3 | 2015-12-10 10:22:39 +0000 | [diff] [blame] | 292 | .endm |
| 293 | |
Ard Biesheuvel | 2079184 | 2015-10-08 20:02:03 +0100 | [diff] [blame] | 294 | /* |
Geoff Levand | 7b7293a | 2016-04-27 17:47:00 +0100 | [diff] [blame] | 295 | * vma_vm_mm - get mm pointer from vma pointer (vma->vm_mm) |
| 296 | */ |
| 297 | .macro vma_vm_mm, rd, rn |
| 298 | ldr \rd, [\rn, #VMA_VM_MM] |
| 299 | .endm |
| 300 | |
| 301 | /* |
| 302 | * mmid - get context id from mm pointer (mm->context.id) |
| 303 | */ |
| 304 | .macro mmid, rd, rn |
| 305 | ldr \rd, [\rn, #MM_CONTEXT_ID] |
| 306 | .endm |
Suzuki K Poulose | 116c81f | 2016-09-09 14:07:16 +0100 | [diff] [blame] | 307 | /* |
| 308 | * read_ctr - read CTR_EL0. If the system has mismatched |
| 309 | * cache line sizes, provide the system wide safe value |
| 310 | * from arm64_ftr_reg_ctrel0.sys_val |
| 311 | */ |
| 312 | .macro read_ctr, reg |
| 313 | alternative_if_not ARM64_MISMATCHED_CACHE_LINE_SIZE |
| 314 | mrs \reg, ctr_el0 // read CTR |
| 315 | nop |
| 316 | alternative_else |
| 317 | ldr_l \reg, arm64_ftr_reg_ctrel0 + ARM64_FTR_SYSVAL |
| 318 | alternative_endif |
| 319 | .endm |
| 320 | |
Geoff Levand | 7b7293a | 2016-04-27 17:47:00 +0100 | [diff] [blame] | 321 | |
| 322 | /* |
Suzuki K Poulose | 072f0a6 | 2016-09-09 14:07:14 +0100 | [diff] [blame] | 323 | * raw_dcache_line_size - get the minimum D-cache line size on this CPU |
| 324 | * from the CTR register. |
Geoff Levand | 7b7293a | 2016-04-27 17:47:00 +0100 | [diff] [blame] | 325 | */ |
Suzuki K Poulose | 072f0a6 | 2016-09-09 14:07:14 +0100 | [diff] [blame] | 326 | .macro raw_dcache_line_size, reg, tmp |
Geoff Levand | 7b7293a | 2016-04-27 17:47:00 +0100 | [diff] [blame] | 327 | mrs \tmp, ctr_el0 // read CTR |
| 328 | ubfm \tmp, \tmp, #16, #19 // cache line size encoding |
| 329 | mov \reg, #4 // bytes per word |
| 330 | lsl \reg, \reg, \tmp // actual cache line size |
| 331 | .endm |
| 332 | |
| 333 | /* |
Suzuki K Poulose | 072f0a6 | 2016-09-09 14:07:14 +0100 | [diff] [blame] | 334 | * dcache_line_size - get the safe D-cache line size across all CPUs |
Geoff Levand | 7b7293a | 2016-04-27 17:47:00 +0100 | [diff] [blame] | 335 | */ |
Suzuki K Poulose | 072f0a6 | 2016-09-09 14:07:14 +0100 | [diff] [blame] | 336 | .macro dcache_line_size, reg, tmp |
Suzuki K Poulose | 116c81f | 2016-09-09 14:07:16 +0100 | [diff] [blame] | 337 | read_ctr \tmp |
| 338 | ubfm \tmp, \tmp, #16, #19 // cache line size encoding |
| 339 | mov \reg, #4 // bytes per word |
| 340 | lsl \reg, \reg, \tmp // actual cache line size |
Suzuki K Poulose | 072f0a6 | 2016-09-09 14:07:14 +0100 | [diff] [blame] | 341 | .endm |
| 342 | |
| 343 | /* |
| 344 | * raw_icache_line_size - get the minimum I-cache line size on this CPU |
| 345 | * from the CTR register. |
| 346 | */ |
| 347 | .macro raw_icache_line_size, reg, tmp |
Geoff Levand | 7b7293a | 2016-04-27 17:47:00 +0100 | [diff] [blame] | 348 | mrs \tmp, ctr_el0 // read CTR |
| 349 | and \tmp, \tmp, #0xf // cache line size encoding |
| 350 | mov \reg, #4 // bytes per word |
| 351 | lsl \reg, \reg, \tmp // actual cache line size |
| 352 | .endm |
| 353 | |
| 354 | /* |
Suzuki K Poulose | 072f0a6 | 2016-09-09 14:07:14 +0100 | [diff] [blame] | 355 | * icache_line_size - get the safe I-cache line size across all CPUs |
| 356 | */ |
| 357 | .macro icache_line_size, reg, tmp |
Suzuki K Poulose | 116c81f | 2016-09-09 14:07:16 +0100 | [diff] [blame] | 358 | read_ctr \tmp |
| 359 | and \tmp, \tmp, #0xf // cache line size encoding |
| 360 | mov \reg, #4 // bytes per word |
| 361 | lsl \reg, \reg, \tmp // actual cache line size |
Suzuki K Poulose | 072f0a6 | 2016-09-09 14:07:14 +0100 | [diff] [blame] | 362 | .endm |
| 363 | |
| 364 | /* |
Geoff Levand | 7b7293a | 2016-04-27 17:47:00 +0100 | [diff] [blame] | 365 | * tcr_set_idmap_t0sz - update TCR.T0SZ so that we can load the ID map |
| 366 | */ |
| 367 | .macro tcr_set_idmap_t0sz, valreg, tmpreg |
Geoff Levand | 7b7293a | 2016-04-27 17:47:00 +0100 | [diff] [blame] | 368 | ldr_l \tmpreg, idmap_t0sz |
| 369 | bfi \valreg, \tmpreg, #TCR_T0SZ_OFFSET, #TCR_TxSZ_WIDTH |
Geoff Levand | 7b7293a | 2016-04-27 17:47:00 +0100 | [diff] [blame] | 370 | .endm |
| 371 | |
| 372 | /* |
Kristina Martsenko | 787fd1d | 2017-12-13 17:07:17 +0000 | [diff] [blame] | 373 | * tcr_compute_pa_size - set TCR.(I)PS to the highest supported |
| 374 | * ID_AA64MMFR0_EL1.PARange value |
| 375 | * |
| 376 | * tcr: register with the TCR_ELx value to be updated |
Kristina Martsenko | 39610a6 | 2018-01-15 15:23:50 +0000 | [diff] [blame] | 377 | * pos: IPS or PS bitfield position |
Kristina Martsenko | 787fd1d | 2017-12-13 17:07:17 +0000 | [diff] [blame] | 378 | * tmp{0,1}: temporary registers |
| 379 | */ |
| 380 | .macro tcr_compute_pa_size, tcr, pos, tmp0, tmp1 |
| 381 | mrs \tmp0, ID_AA64MMFR0_EL1 |
| 382 | // Narrow PARange to fit the PS field in TCR_ELx |
| 383 | ubfx \tmp0, \tmp0, #ID_AA64MMFR0_PARANGE_SHIFT, #3 |
| 384 | mov \tmp1, #ID_AA64MMFR0_PARANGE_MAX |
| 385 | cmp \tmp0, \tmp1 |
| 386 | csel \tmp0, \tmp1, \tmp0, hi |
| 387 | bfi \tcr, \tmp0, \pos, #3 |
Geoff Levand | 7b7293a | 2016-04-27 17:47:00 +0100 | [diff] [blame] | 388 | .endm |
| 389 | |
| 390 | /* |
| 391 | * Macro to perform a data cache maintenance for the interval |
| 392 | * [kaddr, kaddr + size) |
| 393 | * |
| 394 | * op: operation passed to dc instruction |
| 395 | * domain: domain used in dsb instruciton |
| 396 | * kaddr: starting virtual address of the region |
| 397 | * size: size of the region |
| 398 | * Corrupts: kaddr, size, tmp1, tmp2 |
| 399 | */ |
| 400 | .macro dcache_by_line_op op, domain, kaddr, size, tmp1, tmp2 |
| 401 | dcache_line_size \tmp1, \tmp2 |
| 402 | add \size, \kaddr, \size |
| 403 | sub \tmp2, \tmp1, #1 |
| 404 | bic \kaddr, \kaddr, \tmp2 |
Andre Przywara | 823066d | 2016-06-28 18:07:29 +0100 | [diff] [blame] | 405 | 9998: |
| 406 | .if (\op == cvau || \op == cvac) |
| 407 | alternative_if_not ARM64_WORKAROUND_CLEAN_CACHE |
| 408 | dc \op, \kaddr |
| 409 | alternative_else |
| 410 | dc civac, \kaddr |
| 411 | alternative_endif |
Robin Murphy | d50e071 | 2017-07-25 11:55:42 +0100 | [diff] [blame] | 412 | .elseif (\op == cvap) |
| 413 | alternative_if ARM64_HAS_DCPOP |
| 414 | sys 3, c7, c12, 1, \kaddr // dc cvap |
| 415 | alternative_else |
| 416 | dc cvac, \kaddr |
| 417 | alternative_endif |
Andre Przywara | 823066d | 2016-06-28 18:07:29 +0100 | [diff] [blame] | 418 | .else |
| 419 | dc \op, \kaddr |
| 420 | .endif |
Geoff Levand | 7b7293a | 2016-04-27 17:47:00 +0100 | [diff] [blame] | 421 | add \kaddr, \kaddr, \tmp1 |
| 422 | cmp \kaddr, \size |
| 423 | b.lo 9998b |
| 424 | dsb \domain |
| 425 | .endm |
| 426 | |
| 427 | /* |
| 428 | * reset_pmuserenr_el0 - reset PMUSERENR_EL0 if PMUv3 present |
| 429 | */ |
| 430 | .macro reset_pmuserenr_el0, tmpreg |
| 431 | mrs \tmpreg, id_aa64dfr0_el1 // Check ID_AA64DFR0_EL1 PMUVer |
| 432 | sbfx \tmpreg, \tmpreg, #8, #4 |
| 433 | cmp \tmpreg, #1 // Skip if no PMU present |
| 434 | b.lt 9000f |
| 435 | msr pmuserenr_el0, xzr // Disable PMU access from EL0 |
| 436 | 9000: |
| 437 | .endm |
| 438 | |
| 439 | /* |
Geoff Levand | 5003dbd | 2016-04-27 17:47:10 +0100 | [diff] [blame] | 440 | * copy_page - copy src to dest using temp registers t1-t8 |
| 441 | */ |
| 442 | .macro copy_page dest:req src:req t1:req t2:req t3:req t4:req t5:req t6:req t7:req t8:req |
| 443 | 9998: ldp \t1, \t2, [\src] |
| 444 | ldp \t3, \t4, [\src, #16] |
| 445 | ldp \t5, \t6, [\src, #32] |
| 446 | ldp \t7, \t8, [\src, #48] |
| 447 | add \src, \src, #64 |
| 448 | stnp \t1, \t2, [\dest] |
| 449 | stnp \t3, \t4, [\dest, #16] |
| 450 | stnp \t5, \t6, [\dest, #32] |
| 451 | stnp \t7, \t8, [\dest, #48] |
| 452 | add \dest, \dest, #64 |
| 453 | tst \src, #(PAGE_SIZE - 1) |
| 454 | b.ne 9998b |
| 455 | .endm |
| 456 | |
| 457 | /* |
Ard Biesheuvel | 2079184 | 2015-10-08 20:02:03 +0100 | [diff] [blame] | 458 | * Annotate a function as position independent, i.e., safe to be called before |
| 459 | * the kernel virtual mapping is activated. |
| 460 | */ |
| 461 | #define ENDPIPROC(x) \ |
| 462 | .globl __pi_##x; \ |
| 463 | .type __pi_##x, %function; \ |
| 464 | .set __pi_##x, x; \ |
| 465 | .size __pi_##x, . - x; \ |
| 466 | ENDPROC(x) |
| 467 | |
Mark Rutland | ed84b4e | 2017-07-26 16:05:20 +0100 | [diff] [blame] | 468 | /* |
| 469 | * Annotate a function as being unsuitable for kprobes. |
| 470 | */ |
| 471 | #ifdef CONFIG_KPROBES |
| 472 | #define NOKPROBE(x) \ |
| 473 | .pushsection "_kprobe_blacklist", "aw"; \ |
| 474 | .quad x; \ |
| 475 | .popsection; |
| 476 | #else |
| 477 | #define NOKPROBE(x) |
| 478 | #endif |
Ard Biesheuvel | 6ad1fe5 | 2015-12-26 13:48:02 +0100 | [diff] [blame] | 479 | /* |
| 480 | * Emit a 64-bit absolute little endian symbol reference in a way that |
| 481 | * ensures that it will be resolved at build time, even when building a |
| 482 | * PIE binary. This requires cooperation from the linker script, which |
| 483 | * must emit the lo32/hi32 halves individually. |
| 484 | */ |
| 485 | .macro le64sym, sym |
| 486 | .long \sym\()_lo32 |
| 487 | .long \sym\()_hi32 |
| 488 | .endm |
| 489 | |
Ard Biesheuvel | 30b5ba5 | 2016-04-18 17:09:44 +0200 | [diff] [blame] | 490 | /* |
| 491 | * mov_q - move an immediate constant into a 64-bit register using |
| 492 | * between 2 and 4 movz/movk instructions (depending on the |
| 493 | * magnitude and sign of the operand) |
| 494 | */ |
| 495 | .macro mov_q, reg, val |
| 496 | .if (((\val) >> 31) == 0 || ((\val) >> 31) == 0x1ffffffff) |
| 497 | movz \reg, :abs_g1_s:\val |
| 498 | .else |
| 499 | .if (((\val) >> 47) == 0 || ((\val) >> 47) == 0x1ffff) |
| 500 | movz \reg, :abs_g2_s:\val |
| 501 | .else |
| 502 | movz \reg, :abs_g3:\val |
| 503 | movk \reg, :abs_g2_nc:\val |
| 504 | .endif |
| 505 | movk \reg, :abs_g1_nc:\val |
| 506 | .endif |
| 507 | movk \reg, :abs_g0_nc:\val |
| 508 | .endm |
| 509 | |
Catalin Marinas | f33bcf0 | 2016-07-01 15:48:55 +0100 | [diff] [blame] | 510 | /* |
Catalin Marinas | 4b65a5d | 2016-07-01 16:53:00 +0100 | [diff] [blame] | 511 | * Return the current thread_info. |
| 512 | */ |
| 513 | .macro get_thread_info, rd |
| 514 | mrs \rd, sp_el0 |
| 515 | .endm |
| 516 | |
| 517 | /* |
Kristina Martsenko | 529c4b0 | 2017-12-13 17:07:18 +0000 | [diff] [blame] | 518 | * Arrange a physical address in a TTBR register, taking care of 52-bit |
| 519 | * addresses. |
| 520 | * |
| 521 | * phys: physical address, preserved |
| 522 | * ttbr: returns the TTBR value |
| 523 | */ |
Will Deacon | fa0465f | 2018-01-29 11:59:57 +0000 | [diff] [blame] | 524 | .macro phys_to_ttbr, ttbr, phys |
Kristina Martsenko | 529c4b0 | 2017-12-13 17:07:18 +0000 | [diff] [blame] | 525 | #ifdef CONFIG_ARM64_PA_BITS_52 |
| 526 | orr \ttbr, \phys, \phys, lsr #46 |
| 527 | and \ttbr, \ttbr, #TTBR_BADDR_MASK_52 |
| 528 | #else |
| 529 | mov \ttbr, \phys |
| 530 | #endif |
| 531 | .endm |
| 532 | |
Will Deacon | 79ddab3 | 2018-01-29 11:59:59 +0000 | [diff] [blame] | 533 | .macro phys_to_pte, pte, phys |
| 534 | #ifdef CONFIG_ARM64_PA_BITS_52 |
| 535 | /* |
| 536 | * We assume \phys is 64K aligned and this is guaranteed by only |
| 537 | * supporting this configuration with 64K pages. |
| 538 | */ |
| 539 | orr \pte, \phys, \phys, lsr #36 |
| 540 | and \pte, \pte, #PTE_ADDR_MASK |
| 541 | #else |
| 542 | mov \pte, \phys |
| 543 | #endif |
| 544 | .endm |
| 545 | |
Will Deacon | f992b4d | 2018-02-06 22:22:50 +0000 | [diff] [blame] | 546 | .macro pte_to_phys, phys, pte |
| 547 | #ifdef CONFIG_ARM64_PA_BITS_52 |
| 548 | ubfiz \phys, \pte, #(48 - 16 - 12), #16 |
| 549 | bfxil \phys, \pte, #16, #32 |
| 550 | lsl \phys, \phys, #16 |
| 551 | #else |
| 552 | and \phys, \pte, #PTE_ADDR_MASK |
| 553 | #endif |
| 554 | .endm |
| 555 | |
Shanker Donthineni | 3060e9f | 2018-01-29 11:59:52 +0000 | [diff] [blame] | 556 | /** |
| 557 | * Errata workaround prior to disable MMU. Insert an ISB immediately prior |
| 558 | * to executing the MSR that will change SCTLR_ELn[M] from a value of 1 to 0. |
| 559 | */ |
| 560 | .macro pre_disable_mmu_workaround |
| 561 | #ifdef CONFIG_QCOM_FALKOR_ERRATUM_E1041 |
| 562 | isb |
| 563 | #endif |
| 564 | .endm |
| 565 | |
Marc Zyngier | f3e3927 | 2015-02-20 13:53:13 +0000 | [diff] [blame] | 566 | #endif /* __ASM_ASSEMBLER_H */ |