blob: 061a2792179a7c3057eb194b0d4a1e6ad0e2e661 [file] [log] [blame]
Catalin Marinas72c58392014-07-24 14:14:42 +01001/*
2 * Macros for accessing system registers with older binutils.
3 *
4 * Copyright (C) 2014 ARM Ltd.
5 * Author: Catalin Marinas <catalin.marinas@arm.com>
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
20#ifndef __ASM_SYSREG_H
21#define __ASM_SYSREG_H
22
James Morse338d4f42015-07-22 19:05:54 +010023#include <asm/opcodes.h>
24
James Morse870828e2015-07-21 13:23:27 +010025#define SCTLR_EL1_CP15BEN (0x1 << 5)
26#define SCTLR_EL1_SED (0x1 << 8)
27
Suzuki K. Poulose9ded63a2015-07-22 11:38:14 +010028/*
29 * ARMv8 ARM reserves the following encoding for system registers:
30 * (Ref: ARMv8 ARM, Section: "System instruction class encoding overview",
31 * C5.2, version:ARM DDI 0487A.f)
32 * [20-19] : Op0
33 * [18-16] : Op1
34 * [15-12] : CRn
35 * [11-8] : CRm
36 * [7-5] : Op2
37 */
Catalin Marinas72c58392014-07-24 14:14:42 +010038#define sys_reg(op0, op1, crn, crm, op2) \
Suzuki K. Poulose9ded63a2015-07-22 11:38:14 +010039 ((((op0)&3)<<19)|((op1)<<16)|((crn)<<12)|((crm)<<8)|((op2)<<5))
Catalin Marinas72c58392014-07-24 14:14:42 +010040
James Morse338d4f42015-07-22 19:05:54 +010041#define REG_PSTATE_PAN_IMM sys_reg(0, 0, 4, 0, 4)
42#define SCTLR_EL1_SPAN (1 << 23)
43
44#define SET_PSTATE_PAN(x) __inst_arm(0xd5000000 | REG_PSTATE_PAN_IMM |\
45 (!!x)<<8 | 0x1f)
46
Suzuki K. Poulosecdcf8172015-10-19 14:24:42 +010047#define ID_AA64MMFR0_BIGENDEL0_SHIFT 16
48#define ID_AA64MMFR0_BIGENDEL_SHIFT 8
Suzuki K. Poulose4bf8b962015-10-19 14:19:35 +010049
50#define ID_AA64MMFR0_TGRAN4_SHIFT 28
51#define ID_AA64MMFR0_TGRAN64_SHIFT 24
52#define ID_AA64MMFR0_TGRAN16_SHIFT 20
53
54#define ID_AA64MMFR0_TGRAN4_NI 0xf
55#define ID_AA64MMFR0_TGRAN4_SUPPORTED 0x0
56#define ID_AA64MMFR0_TGRAN64_NI 0xf
57#define ID_AA64MMFR0_TGRAN64_SUPPORTED 0x0
58#define ID_AA64MMFR0_TGRAN16_NI 0x0
59#define ID_AA64MMFR0_TGRAN16_SUPPORTED 0x1
60
61#if defined(CONFIG_ARM64_4K_PAGES)
62#define ID_AA64MMFR0_TGRAN_SHIFT ID_AA64MMFR0_TGRAN4_SHIFT
63#define ID_AA64MMFR0_TGRAN_SUPPORTED ID_AA64MMFR0_TGRAN4_SUPPORTED
Suzuki K. Poulose44eaacf2015-10-19 14:19:37 +010064#elif defined(CONFIG_ARM64_16K_PAGES)
65#define ID_AA64MMFR0_TGRAN_SHIFT ID_AA64MMFR0_TGRAN16_SHIFT
66#define ID_AA64MMFR0_TGRAN_SUPPORTED ID_AA64MMFR0_TGRAN16_SUPPORTED
Suzuki K. Poulose4bf8b962015-10-19 14:19:35 +010067#elif defined(CONFIG_ARM64_64K_PAGES)
68#define ID_AA64MMFR0_TGRAN_SHIFT ID_AA64MMFR0_TGRAN64_SHIFT
69#define ID_AA64MMFR0_TGRAN_SUPPORTED ID_AA64MMFR0_TGRAN64_SUPPORTED
70#endif
71
Catalin Marinas72c58392014-07-24 14:14:42 +010072#ifdef __ASSEMBLY__
73
74 .irp num,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30
75 .equ __reg_num_x\num, \num
76 .endr
77 .equ __reg_num_xzr, 31
78
79 .macro mrs_s, rt, sreg
Suzuki K. Poulose9ded63a2015-07-22 11:38:14 +010080 .inst 0xd5200000|(\sreg)|(__reg_num_\rt)
Catalin Marinas72c58392014-07-24 14:14:42 +010081 .endm
82
83 .macro msr_s, sreg, rt
Suzuki K. Poulose9ded63a2015-07-22 11:38:14 +010084 .inst 0xd5000000|(\sreg)|(__reg_num_\rt)
Catalin Marinas72c58392014-07-24 14:14:42 +010085 .endm
86
87#else
88
89asm(
90" .irp num,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30\n"
91" .equ __reg_num_x\\num, \\num\n"
92" .endr\n"
93" .equ __reg_num_xzr, 31\n"
94"\n"
95" .macro mrs_s, rt, sreg\n"
Suzuki K. Poulose9ded63a2015-07-22 11:38:14 +010096" .inst 0xd5200000|(\\sreg)|(__reg_num_\\rt)\n"
Catalin Marinas72c58392014-07-24 14:14:42 +010097" .endm\n"
98"\n"
99" .macro msr_s, sreg, rt\n"
Suzuki K. Poulose9ded63a2015-07-22 11:38:14 +0100100" .inst 0xd5000000|(\\sreg)|(__reg_num_\\rt)\n"
Catalin Marinas72c58392014-07-24 14:14:42 +0100101" .endm\n"
102);
103
James Morse870828e2015-07-21 13:23:27 +0100104static inline void config_sctlr_el1(u32 clear, u32 set)
105{
106 u32 val;
107
108 asm volatile("mrs %0, sctlr_el1" : "=r" (val));
109 val &= ~clear;
110 val |= set;
111 asm volatile("msr sctlr_el1, %0" : : "r" (val));
112}
Catalin Marinas72c58392014-07-24 14:14:42 +0100113#endif
114
115#endif /* __ASM_SYSREG_H */