blob: 1f44b4255a2877d5a21ca4d7194f1c7053d58c73 [file] [log] [blame]
Catalin Marinas0be73202012-03-05 11:49:26 +00001/*
Geoff Levand7b7293a2016-04-27 17:47:00 +01002 * Based on arch/arm/include/asm/assembler.h, arch/arm/mm/proc-macros.S
Catalin Marinas0be73202012-03-05 11:49:26 +00003 *
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 Zyngierf3e39272015-02-20 13:53:13 +000023#ifndef __ASM_ASSEMBLER_H
24#define __ASM_ASSEMBLER_H
25
Geoff Levand7b7293a2016-04-27 17:47:00 +010026#include <asm/asm-offsets.h>
Andre Przywara823066d2016-06-28 18:07:29 +010027#include <asm/cpufeature.h>
Julien Thierrye28cc022017-10-25 10:04:32 +010028#include <asm/debug-monitors.h>
Geoff Levand5003dbd2016-04-27 17:47:10 +010029#include <asm/page.h>
Geoff Levand7b7293a2016-04-27 17:47:00 +010030#include <asm/pgtable-hwdef.h>
Catalin Marinas0be73202012-03-05 11:49:26 +000031#include <asm/ptrace.h>
Will Deacon2a283072014-04-29 19:04:06 +010032#include <asm/thread_info.h>
Catalin Marinas0be73202012-03-05 11:49:26 +000033
James Morse0fbeb312017-11-02 12:12:34 +000034 .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 Morseb55a5a12017-11-02 12:12:39 +000051 /* 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 Morseb282e1c2017-11-02 12:12:41 +000057 /* 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 Marinas0be73202012-03-05 11:49:26 +000062/*
Catalin Marinas0be73202012-03-05 11:49:26 +000063 * 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 Marinas4b65a5d2016-07-01 16:53:00 +010073 .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 Marinas0be73202012-03-05 11:49:26 +000082 .macro enable_dbg
83 msr daifclr, #8
84 .endm
85
Will Deacon2a283072014-04-29 19:04:06 +010086 .macro disable_step_tsk, flgs, tmp
87 tbz \flgs, #TIF_SINGLESTEP, 9990f
Catalin Marinas0be73202012-03-05 11:49:26 +000088 mrs \tmp, mdscr_el1
Julien Thierrye28cc022017-10-25 10:04:32 +010089 bic \tmp, \tmp, #DBG_MDSCR_SS
Catalin Marinas0be73202012-03-05 11:49:26 +000090 msr mdscr_el1, \tmp
Will Deacon2a283072014-04-29 19:04:06 +010091 isb // Synchronise with enable_dbg
929990:
Catalin Marinas0be73202012-03-05 11:49:26 +000093 .endm
94
James Morse84d0fb12017-11-02 12:12:38 +000095 /* call with daif masked */
Will Deacon2a283072014-04-29 19:04:06 +010096 .macro enable_step_tsk, flgs, tmp
97 tbz \flgs, #TIF_SINGLESTEP, 9990f
Catalin Marinas0be73202012-03-05 11:49:26 +000098 mrs \tmp, mdscr_el1
Julien Thierrye28cc022017-10-25 10:04:32 +010099 orr \tmp, \tmp, #DBG_MDSCR_SS
Catalin Marinas0be73202012-03-05 11:49:26 +0000100 msr mdscr_el1, \tmp
Will Deacon2a283072014-04-29 19:04:06 +01001019990:
Catalin Marinas0be73202012-03-05 11:49:26 +0000102 .endm
103
Will Deacon2a283072014-04-29 19:04:06 +0100104/*
Catalin Marinas0be73202012-03-05 11:49:26 +0000105 * SMP data memory barrier
106 */
107 .macro smp_dmb, opt
Catalin Marinas0be73202012-03-05 11:49:26 +0000108 dmb \opt
Catalin Marinas0be73202012-03-05 11:49:26 +0000109 .endm
110
Ard Biesheuvel6c94f272016-01-01 15:02:12 +0100111/*
James Morse68ddbf02018-01-15 19:38:59 +0000112 * RAS Error Synchronization barrier
113 */
114 .macro esb
115 hint #16
116 .endm
117
118/*
Will Deacon669474e2018-02-05 15:34:16 +0000119 * Value prediction barrier
120 */
121 .macro csdb
122 hint #20
123 .endm
124
125/*
Will Deaconf99a2502016-09-06 16:40:23 +0100126 * NOP sequence
127 */
128 .macro nops, num
129 .rept \num
130 nop
131 .endr
132 .endm
133
134/*
Ard Biesheuvel6c94f272016-01-01 15:02:12 +0100135 * 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 Marinas0be73202012-03-05 11:49:26 +0000144#define USER(l, x...) \
1459999: x; \
Ard Biesheuvel6c94f272016-01-01 15:02:12 +0100146 _asm_extable 9999b, l
Catalin Marinas0be73202012-03-05 11:49:26 +0000147
148/*
149 * Register aliases.
150 */
151lr .req x30 // link register
Marc Zyngierdc637f12012-10-19 17:37:35 +0100152
153/*
154 * Vector entry
155 */
156 .macro ventry label
157 .align 7
158 b \label
159 .endm
Matthew Leache68beda2013-10-11 14:52:15 +0100160
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 Leach55b89542013-10-11 14:52:13 +0100179/*
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 Zyngierf3e39272015-02-20 13:53:13 +0000191
Ard Biesheuvelb784a5d2015-03-04 19:45:38 +0100192/*
193 * Pseudo-ops for PC-relative adr/ldr/str <reg>, <symbol> where
Ard Biesheuvel41c066f2017-01-11 14:54:53 +0000194 * <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 Biesheuvelb784a5d2015-03-04 19:45:38 +0100198 */
199 /*
200 * @dst: destination register (64 bit wide)
201 * @sym: name of the symbol
Ard Biesheuvelb784a5d2015-03-04 19:45:38 +0100202 */
Ard Biesheuvel41c066f2017-01-11 14:54:53 +0000203 .macro adr_l, dst, sym
204#ifndef MODULE
Ard Biesheuvelb784a5d2015-03-04 19:45:38 +0100205 adrp \dst, \sym
206 add \dst, \dst, :lo12:\sym
Ard Biesheuvel41c066f2017-01-11 14:54:53 +0000207#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 Biesheuvelb784a5d2015-03-04 19:45:38 +0100213 .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 Biesheuvel41c066f2017-01-11 14:54:53 +0000223#ifndef MODULE
Ard Biesheuvelb784a5d2015-03-04 19:45:38 +0100224 .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 Biesheuvel41c066f2017-01-11 14:54:53 +0000231#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 Biesheuvelb784a5d2015-03-04 19:45:38 +0100240 .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 Biesheuvel41c066f2017-01-11 14:54:53 +0000249#ifndef MODULE
Ard Biesheuvelb784a5d2015-03-04 19:45:38 +0100250 adrp \tmp, \sym
251 str \src, [\tmp, :lo12:\sym]
Ard Biesheuvel41c066f2017-01-11 14:54:53 +0000252#else
253 adr_l \tmp, \sym
254 str \src, [\tmp]
255#endif
Ard Biesheuvelb784a5d2015-03-04 19:45:38 +0100256 .endm
257
James Morseaa4d5d32015-12-10 10:22:39 +0000258 /*
Ard Biesheuvel8ea41b12017-07-15 17:23:13 +0100259 * @dst: Result of per_cpu(sym, smp_processor_id()), can be SP for
260 * non-module code
James Morseaa4d5d32015-12-10 10:22:39 +0000261 * @sym: The name of the per-cpu variable
James Morseaa4d5d32015-12-10 10:22:39 +0000262 * @tmp: scratch register
263 */
Mark Rutland1b7e2292016-11-03 20:23:12 +0000264 .macro adr_this_cpu, dst, sym, tmp
Ard Biesheuvel8ea41b12017-07-15 17:23:13 +0100265#ifndef MODULE
266 adrp \tmp, \sym
267 add \dst, \tmp, #:lo12:\sym
268#else
Mark Rutland1b7e2292016-11-03 20:23:12 +0000269 adr_l \dst, \sym
Ard Biesheuvel8ea41b12017-07-15 17:23:13 +0100270#endif
James Morse6d99b682018-01-08 15:38:06 +0000271alternative_if_not ARM64_HAS_VIRT_HOST_EXTN
James Morseaa4d5d32015-12-10 10:22:39 +0000272 mrs \tmp, tpidr_el1
James Morse6d99b682018-01-08 15:38:06 +0000273alternative_else
274 mrs \tmp, tpidr_el2
275alternative_endif
Mark Rutland1b7e2292016-11-03 20:23:12 +0000276 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 Morse6d99b682018-01-08 15:38:06 +0000286alternative_if_not ARM64_HAS_VIRT_HOST_EXTN
Mark Rutland1b7e2292016-11-03 20:23:12 +0000287 mrs \tmp, tpidr_el1
James Morse6d99b682018-01-08 15:38:06 +0000288alternative_else
289 mrs \tmp, tpidr_el2
290alternative_endif
Mark Rutland1b7e2292016-11-03 20:23:12 +0000291 ldr \dst, [\dst, \tmp]
James Morseaa4d5d32015-12-10 10:22:39 +0000292 .endm
293
Ard Biesheuvel20791842015-10-08 20:02:03 +0100294/*
Geoff Levand7b7293a2016-04-27 17:47:00 +0100295 * 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 Poulose116c81f2016-09-09 14:07:16 +0100307/*
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
313alternative_if_not ARM64_MISMATCHED_CACHE_LINE_SIZE
314 mrs \reg, ctr_el0 // read CTR
315 nop
316alternative_else
317 ldr_l \reg, arm64_ftr_reg_ctrel0 + ARM64_FTR_SYSVAL
318alternative_endif
319 .endm
320
Geoff Levand7b7293a2016-04-27 17:47:00 +0100321
322/*
Suzuki K Poulose072f0a62016-09-09 14:07:14 +0100323 * raw_dcache_line_size - get the minimum D-cache line size on this CPU
324 * from the CTR register.
Geoff Levand7b7293a2016-04-27 17:47:00 +0100325 */
Suzuki K Poulose072f0a62016-09-09 14:07:14 +0100326 .macro raw_dcache_line_size, reg, tmp
Geoff Levand7b7293a2016-04-27 17:47:00 +0100327 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 Poulose072f0a62016-09-09 14:07:14 +0100334 * dcache_line_size - get the safe D-cache line size across all CPUs
Geoff Levand7b7293a2016-04-27 17:47:00 +0100335 */
Suzuki K Poulose072f0a62016-09-09 14:07:14 +0100336 .macro dcache_line_size, reg, tmp
Suzuki K Poulose116c81f2016-09-09 14:07:16 +0100337 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 Poulose072f0a62016-09-09 14:07:14 +0100341 .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 Levand7b7293a2016-04-27 17:47:00 +0100348 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 Poulose072f0a62016-09-09 14:07:14 +0100355 * icache_line_size - get the safe I-cache line size across all CPUs
356 */
357 .macro icache_line_size, reg, tmp
Suzuki K Poulose116c81f2016-09-09 14:07:16 +0100358 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 Poulose072f0a62016-09-09 14:07:14 +0100362 .endm
363
364/*
Geoff Levand7b7293a2016-04-27 17:47:00 +0100365 * 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 Levand7b7293a2016-04-27 17:47:00 +0100368 ldr_l \tmpreg, idmap_t0sz
369 bfi \valreg, \tmpreg, #TCR_T0SZ_OFFSET, #TCR_TxSZ_WIDTH
Geoff Levand7b7293a2016-04-27 17:47:00 +0100370 .endm
371
372/*
Kristina Martsenko787fd1d2017-12-13 17:07:17 +0000373 * 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 Martsenko39610a62018-01-15 15:23:50 +0000377 * pos: IPS or PS bitfield position
Kristina Martsenko787fd1d2017-12-13 17:07:17 +0000378 * 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 Levand7b7293a2016-04-27 17:47:00 +0100388 .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 Przywara823066d2016-06-28 18:07:29 +01004059998:
406 .if (\op == cvau || \op == cvac)
407alternative_if_not ARM64_WORKAROUND_CLEAN_CACHE
408 dc \op, \kaddr
409alternative_else
410 dc civac, \kaddr
411alternative_endif
Robin Murphyd50e0712017-07-25 11:55:42 +0100412 .elseif (\op == cvap)
413alternative_if ARM64_HAS_DCPOP
414 sys 3, c7, c12, 1, \kaddr // dc cvap
415alternative_else
416 dc cvac, \kaddr
417alternative_endif
Andre Przywara823066d2016-06-28 18:07:29 +0100418 .else
419 dc \op, \kaddr
420 .endif
Geoff Levand7b7293a2016-04-27 17:47:00 +0100421 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
4369000:
437 .endm
438
439/*
Geoff Levand5003dbd2016-04-27 17:47:10 +0100440 * 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
4439998: 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 Biesheuvel20791842015-10-08 20:02:03 +0100458 * 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 Rutlanded84b4e2017-07-26 16:05:20 +0100468/*
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 Biesheuvel6ad1fe52015-12-26 13:48:02 +0100479 /*
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 Biesheuvel30b5ba52016-04-18 17:09:44 +0200490 /*
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 Marinasf33bcf02016-07-01 15:48:55 +0100510/*
Catalin Marinas4b65a5d2016-07-01 16:53:00 +0100511 * Return the current thread_info.
512 */
513 .macro get_thread_info, rd
514 mrs \rd, sp_el0
515 .endm
516
517/*
Kristina Martsenko529c4b02017-12-13 17:07:18 +0000518 * 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 Deaconfa0465f2018-01-29 11:59:57 +0000524 .macro phys_to_ttbr, ttbr, phys
Kristina Martsenko529c4b02017-12-13 17:07:18 +0000525#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 Deacon79ddab32018-01-29 11:59:59 +0000533 .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 Deaconf992b4d2018-02-06 22:22:50 +0000546 .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 Donthineni3060e9f2018-01-29 11:59:52 +0000556/**
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 Zyngierf3e39272015-02-20 13:53:13 +0000566#endif /* __ASM_ASSEMBLER_H */