|
1 | 1 | /*
|
2 |
| - * Based on arch/arm/include/asm/assembler.h |
| 2 | + * Based on arch/arm/include/asm/assembler.h, arch/arm/mm/proc-macros.S |
3 | 3 | *
|
4 | 4 | * Copyright (C) 1996-2000 Russell King
|
5 | 5 | * Copyright (C) 2012 ARM Ltd.
|
|
23 | 23 | #ifndef __ASM_ASSEMBLER_H
|
24 | 24 | #define __ASM_ASSEMBLER_H
|
25 | 25 |
|
| 26 | +#include <asm/asm-offsets.h> |
| 27 | +#include <asm/pgtable-hwdef.h> |
26 | 28 | #include <asm/ptrace.h>
|
27 | 29 | #include <asm/thread_info.h>
|
28 | 30 |
|
@@ -199,6 +201,84 @@ lr .req x30 // link register
|
199 | 201 | add \reg, \reg, \tmp
|
200 | 202 | .endm
|
201 | 203 |
|
| 204 | +/* |
| 205 | + * vma_vm_mm - get mm pointer from vma pointer (vma->vm_mm) |
| 206 | + */ |
| 207 | + .macro vma_vm_mm, rd, rn |
| 208 | + ldr \rd, [\rn, #VMA_VM_MM] |
| 209 | + .endm |
| 210 | + |
| 211 | +/* |
| 212 | + * mmid - get context id from mm pointer (mm->context.id) |
| 213 | + */ |
| 214 | + .macro mmid, rd, rn |
| 215 | + ldr \rd, [\rn, #MM_CONTEXT_ID] |
| 216 | + .endm |
| 217 | + |
| 218 | +/* |
| 219 | + * dcache_line_size - get the minimum D-cache line size from the CTR register. |
| 220 | + */ |
| 221 | + .macro dcache_line_size, reg, tmp |
| 222 | + mrs \tmp, ctr_el0 // read CTR |
| 223 | + ubfm \tmp, \tmp, #16, #19 // cache line size encoding |
| 224 | + mov \reg, #4 // bytes per word |
| 225 | + lsl \reg, \reg, \tmp // actual cache line size |
| 226 | + .endm |
| 227 | + |
| 228 | +/* |
| 229 | + * icache_line_size - get the minimum I-cache line size from the CTR register. |
| 230 | + */ |
| 231 | + .macro icache_line_size, reg, tmp |
| 232 | + mrs \tmp, ctr_el0 // read CTR |
| 233 | + and \tmp, \tmp, #0xf // cache line size encoding |
| 234 | + mov \reg, #4 // bytes per word |
| 235 | + lsl \reg, \reg, \tmp // actual cache line size |
| 236 | + .endm |
| 237 | + |
| 238 | +/* |
| 239 | + * tcr_set_idmap_t0sz - update TCR.T0SZ so that we can load the ID map |
| 240 | + */ |
| 241 | + .macro tcr_set_idmap_t0sz, valreg, tmpreg |
| 242 | +#ifndef CONFIG_ARM64_VA_BITS_48 |
| 243 | + ldr_l \tmpreg, idmap_t0sz |
| 244 | + bfi \valreg, \tmpreg, #TCR_T0SZ_OFFSET, #TCR_TxSZ_WIDTH |
| 245 | +#endif |
| 246 | + .endm |
| 247 | + |
| 248 | +/* |
| 249 | + * Macro to perform a data cache maintenance for the interval |
| 250 | + * [kaddr, kaddr + size) |
| 251 | + * |
| 252 | + * op: operation passed to dc instruction |
| 253 | + * domain: domain used in dsb instruciton |
| 254 | + * kaddr: starting virtual address of the region |
| 255 | + * size: size of the region |
| 256 | + * Corrupts: kaddr, size, tmp1, tmp2 |
| 257 | + */ |
| 258 | + .macro dcache_by_line_op op, domain, kaddr, size, tmp1, tmp2 |
| 259 | + dcache_line_size \tmp1, \tmp2 |
| 260 | + add \size, \kaddr, \size |
| 261 | + sub \tmp2, \tmp1, #1 |
| 262 | + bic \kaddr, \kaddr, \tmp2 |
| 263 | +9998: dc \op, \kaddr |
| 264 | + add \kaddr, \kaddr, \tmp1 |
| 265 | + cmp \kaddr, \size |
| 266 | + b.lo 9998b |
| 267 | + dsb \domain |
| 268 | + .endm |
| 269 | + |
| 270 | +/* |
| 271 | + * reset_pmuserenr_el0 - reset PMUSERENR_EL0 if PMUv3 present |
| 272 | + */ |
| 273 | + .macro reset_pmuserenr_el0, tmpreg |
| 274 | + mrs \tmpreg, id_aa64dfr0_el1 // Check ID_AA64DFR0_EL1 PMUVer |
| 275 | + sbfx \tmpreg, \tmpreg, #8, #4 |
| 276 | + cmp \tmpreg, #1 // Skip if no PMU present |
| 277 | + b.lt 9000f |
| 278 | + msr pmuserenr_el0, xzr // Disable PMU access from EL0 |
| 279 | +9000: |
| 280 | + .endm |
| 281 | + |
202 | 282 | /*
|
203 | 283 | * Annotate a function as position independent, i.e., safe to be called before
|
204 | 284 | * the kernel virtual mapping is activated.
|
|
0 commit comments