blob: c23e8141f38a5b289c37da42a33e8025cc5558a7 [file] [log] [blame]
Soby Mathewb4c6df42022-11-09 11:13:29 +00001/*
2 * SPDX-License-Identifier: BSD-3-Clause
3 * SPDX-FileCopyrightText: Copyright TF-RMM Contributors.
4 */
5
6#ifndef ARCH_H
7#define ARCH_H
8
9#include <utils_def.h>
10
11/* Cache line size */
12#define CACHE_WRITEBACK_GRANULE UL(64)
13
14/* Timer interrupt IDs defined by the Server Base System Architecture */
15#define EL1_VIRT_TIMER_PPI UL(27)
16#define EL1_PHYS_TIMER_PPI UL(30)
17
18/* Counter-timer Physical Offset register */
19#define CNTPOFF_EL2 S3_4_C14_C0_6
20
21/* MPAM0 Register */
22#define MPAM0_EL1 S3_0_C10_C5_1
23
24/* Interrupt Controller registers */
25#define ICC_HPPIR1_EL1 S3_0_C12_C12_2
26#define ICC_SRE_EL2 S3_4_C12_C9_5
27
28/* Interrupt Controller Control Register */
AlexeiFedorov537bee02023-02-02 13:38:23 +000029#define ICC_CTLR_EL1 S3_0_C12_C12_4
Soby Mathewb4c6df42022-11-09 11:13:29 +000030
AlexeiFedorov537bee02023-02-02 13:38:23 +000031#define ICC_CTLR_EL1_EXT_RANGE_BIT (UL(1) << 19)
Soby Mathewb4c6df42022-11-09 11:13:29 +000032
33/* Virtual GIC registers */
34#define ICH_AP0R0_EL2 S3_4_C12_C8_0
35#define ICH_AP0R1_EL2 S3_4_C12_C8_1
36#define ICH_AP0R2_EL2 S3_4_C12_C8_2
37#define ICH_AP0R3_EL2 S3_4_C12_C8_3
38#define ICH_AP1R0_EL2 S3_4_C12_C9_0
39#define ICH_AP1R1_EL2 S3_4_C12_C9_1
40#define ICH_AP1R2_EL2 S3_4_C12_C9_2
41#define ICH_AP1R3_EL2 S3_4_C12_C9_3
42
43#define ICH_LR0_EL2 S3_4_C12_C12_0
44#define ICH_LR1_EL2 S3_4_C12_C12_1
45#define ICH_LR2_EL2 S3_4_C12_C12_2
46#define ICH_LR3_EL2 S3_4_C12_C12_3
47#define ICH_LR4_EL2 S3_4_C12_C12_4
48#define ICH_LR5_EL2 S3_4_C12_C12_5
49#define ICH_LR6_EL2 S3_4_C12_C12_6
50#define ICH_LR7_EL2 S3_4_C12_C12_7
51#define ICH_LR8_EL2 S3_4_C12_C13_0
52#define ICH_LR9_EL2 S3_4_C12_C13_1
53#define ICH_LR10_EL2 S3_4_C12_C13_2
54#define ICH_LR11_EL2 S3_4_C12_C13_3
55#define ICH_LR12_EL2 S3_4_C12_C13_4
56#define ICH_LR13_EL2 S3_4_C12_C13_5
57#define ICH_LR14_EL2 S3_4_C12_C13_6
58#define ICH_LR15_EL2 S3_4_C12_C13_7
59
60#define ICH_HCR_EL2 S3_4_C12_C11_0
61#define ICH_VTR_EL2 S3_4_C12_C11_1
62#define ICH_MISR_EL2 S3_4_C12_C11_2
63#define ICH_VMCR_EL2 S3_4_C12_C11_7
64
65/* RNDR definition */
66#define RNDR S3_3_C2_C4_0
67
Shruti Gupta5732bfe2024-01-17 13:21:06 +000068/* Data Independent Timing Registers */
69#define DIT S3_3_C4_C2_5
70#define DIT_BIT (UL(1) << 24)
71
Soby Mathewb4c6df42022-11-09 11:13:29 +000072/* CLIDR definitions */
73#define LOC_SHIFT U(24)
74#define CTYPE_SHIFT(n) U(3 * ((n) - 1))
75#define CLIDR_FIELD_WIDTH U(3)
76
77/* CSSELR definitions */
78#define LEVEL_SHIFT U(1)
79
80/* Data cache set/way op type defines */
81#define DCISW U(0x0)
82#define DCCISW U(0x1)
83#define DCCSW U(0x2)
84
85#define TCR_EL2_T0SZ_SHIFT UL(0)
86#define TCR_EL2_T0SZ_WIDTH UL(6)
Soby Mathewb4c6df42022-11-09 11:13:29 +000087
88#define TCR_EL2_T1SZ_SHIFT UL(16)
89#define TCR_EL2_T1SZ_WIDTH UL(6)
Soby Mathewb4c6df42022-11-09 11:13:29 +000090
AlexeiFedorov537bee02023-02-02 13:38:23 +000091#define TCR_EL2_EPD0_BIT (UL(1) << 7)
Soby Mathewb4c6df42022-11-09 11:13:29 +000092
93#define TCR_EL2_IRGN0_SHIFT UL(8)
94#define TCR_EL2_IRGN0_WIDTH UL(2)
95#define TCR_EL2_IRGN0_WBWA INPLACE(TCR_EL2_IRGN0, UL(1))
96
97#define TCR_EL2_ORGN0_SHIFT UL(10)
98#define TCR_EL2_ORGN0_WIDTH UL(2)
99#define TCR_EL2_ORGN0_WBWA INPLACE(TCR_EL2_ORGN0, UL(1))
100
101#define TCR_EL2_IRGN1_SHIFT UL(24)
102#define TCR_EL2_IRGN1_WIDTH UL(2)
103#define TCR_EL2_IRGN1_WBWA INPLACE(TCR_EL2_IRGN1, UL(1))
104
105#define TCR_EL2_ORGN1_SHIFT UL(26)
106#define TCR_EL2_ORGN1_WIDTH UL(2)
107#define TCR_EL2_ORGN1_WBWA INPLACE(TCR_EL2_ORGN1, UL(1))
108
109#define TCR_EL2_SH0_SHIFT UL(12)
110#define TCR_EL2_SH0_WIDTH UL(2)
111#define TCR_EL2_SH0_IS INPLACE(TCR_EL2_SH0, UL(3))
112
113#define TCR_EL2_SH1_SHIFT UL(28)
114#define TCR_EL2_SH1_WIDTH UL(2)
115#define TCR_EL2_SH1_IS INPLACE(TCR_EL2_SH1, UL(3))
116
117#define TCR_EL2_TG0_SHIFT UL(14)
118#define TCR_EL2_TG0_WIDTH UL(2)
119#define TCR_EL2_TG0_4K INPLACE(TCR_EL2_TG0, UL(0))
120
121#define TCR_EL2_TG1_SHIFT UL(30)
122#define TCR_EL2_TG1_WIDTH UL(2)
Javier Almansa Sobrino70194902023-02-28 10:27:02 +0000123#define TCR_EL2_TG1_4K INPLACE(TCR_EL2_TG1, UL(2))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000124
125#define TCR_EL2_IPS_SHIFT UL(32)
126#define TCR_EL2_IPS_WIDTH UL(3)
127#define TCR_PS_BITS_4GB INPLACE(TCR_EL2_IPS, UL(0))
128#define TCR_PS_BITS_64GB INPLACE(TCR_EL2_IPS, UL(1))
129#define TCR_PS_BITS_1TB INPLACE(TCR_EL2_IPS, UL(2))
130#define TCR_PS_BITS_4TB INPLACE(TCR_EL2_IPS, UL(3))
131#define TCR_PS_BITS_16TB INPLACE(TCR_EL2_IPS, UL(4))
132#define TCR_PS_BITS_256TB INPLACE(TCR_EL2_IPS, UL(5))
Javier Almansa Sobrino765a3162023-04-27 17:42:58 +0100133#define TCR_PS_BITS_4PB INPLACE(TCR_EL2_IPS, UL(6))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000134
Javier Almansa Sobrino765a3162023-04-27 17:42:58 +0100135#define TCR_EL2_DS_SHIFT UL(59)
136#define TCR_EL2_DS_WIDTH UL(1)
137#define TCR_EL2_DS_LPA2_EN INPLACE(TCR_EL2_DS, UL(1))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000138
139#define TCR_EL2_AS (UL(1) << 36)
140#define TCR_EL2_HPD0 (UL(1) << 41)
141#define TCR_EL2_HPD1 (UL(1) << 42)
142#define TCR_EL2_E0PD1 (UL(1) << 56) /* TODO: ARMv8.5-E0PD, otherwise RES0 */
143
144#define TCR_TxSZ_MIN UL(16)
Javier Almansa Sobrino765a3162023-04-27 17:42:58 +0100145#define TCR_TxSZ_MIN_LPA2 UL(12)
Javier Almansa Sobrinoed932592023-01-24 12:50:41 +0000146#define TCR_TxSZ_MAX UL(48)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000147
148/* HCR definitions */
149#define HCR_FWB (UL(1) << 46)
150#define HCR_TEA (UL(1) << 37)
151#define HCR_API (UL(1) << 41)
152#define HCR_APK (UL(1) << 40)
153#define HCR_TERR (UL(1) << 36)
154#define HCR_TLOR (UL(1) << 35)
155#define HCR_E2H (UL(1) << 34)
156#define HCR_RW (UL(1) << 31)
157#define HCR_TGE (UL(1) << 27)
158#define HCR_TSW (UL(1) << 22)
159#define HCR_TACR (UL(1) << 21)
160#define HCR_TIDCP (UL(1) << 20)
161#define HCR_TSC (UL(1) << 19)
162#define HCR_TID3 (UL(1) << 18)
163#define HCR_TWE (UL(1) << 14)
164#define HCR_TWI (UL(1) << 13)
165#define HCR_VSE (UL(1) << 8)
166
167#define HCR_BSU_SHIFT 10
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100168#define HCR_BSU_WIDTH U(2)
169#define HCR_BSU_IS INPLACE(HCR_BSU, UL(1)) /* Barriers are promoted to IS */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000170
171#define HCR_FB (UL(1) << 9)
172#define HCR_VI (UL(1) << 7)
173#define HCR_AMO (UL(1) << 5)
174#define HCR_IMO (UL(1) << 4)
175#define HCR_FMO (UL(1) << 3)
176#define HCR_PTW (UL(1) << 2)
177#define HCR_SWIO (UL(1) << 1)
178#define HCR_VM (UL(1) << 0)
179
Arunachalam Ganapathy591354a2023-11-16 10:49:09 +0000180#define HCR_REALM_FLAGS (HCR_FWB | HCR_E2H | HCR_RW | HCR_TSC | \
181 HCR_AMO | HCR_BSU_IS | HCR_IMO | HCR_FMO | \
182 HCR_PTW | HCR_SWIO | HCR_VM | HCR_TID3 | \
183 HCR_TEA | HCR_API | HCR_APK | HCR_TSW)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000184
185#define HCR_EL2_INIT (HCR_TGE | HCR_E2H | HCR_TEA)
186
187#define MAIR_ELx_ATTR0_SHIFT 0
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100188#define MAIR_ELx_ATTR0_WIDTH U(8)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000189
190/*******************************************************************************
191 * Definitions of MAIR encodings for device and normal memory
192 ******************************************************************************/
193/*
194 * MAIR encodings for device memory attributes.
195 */
196#define MAIR_DEV_NGNRNE UL(0x0) /* Device nGnRnE */
197#define MAIR_DEV_NGNRNE_IDX 0x1
198
199#define MAIR_DEV_NGNRE UL(0x4)
200
201#define MAIR_NIOWBNTRW 0xff
202#define MAIR_NIOWBNTRW_IDX 0x0
203
204/*
205 * MAIR encodings for normal memory attributes.
206 *
207 * Cache Policy
208 * WT: Write Through
209 * WB: Write Back
210 * NC: Non-Cacheable
211 *
212 * Transient Hint
213 * NTR: Non-Transient
214 * TR: Transient
215 *
216 * Allocation Policy
217 * RA: Read Allocate
218 * WA: Write Allocate
219 * RWA: Read and Write Allocate
220 * NA: No Allocation
221 */
222#define MAIR_NORM_WT_TR_WA UL(0x1)
223#define MAIR_NORM_WT_TR_RA UL(0x2)
224#define MAIR_NORM_WT_TR_RWA UL(0x3)
225#define MAIR_NORM_NC UL(0x4)
226#define MAIR_NORM_WB_TR_WA UL(0x5)
227#define MAIR_NORM_WB_TR_RA UL(0x6)
228#define MAIR_NORM_WB_TR_RWA UL(0x7)
229#define MAIR_NORM_WT_NTR_NA UL(0x8)
230#define MAIR_NORM_WT_NTR_WA UL(0x9)
231#define MAIR_NORM_WT_NTR_RA UL(0xa)
232#define MAIR_NORM_WT_NTR_RWA UL(0xb)
233#define MAIR_NORM_WB_NTR_NA UL(0xc)
234#define MAIR_NORM_WB_NTR_WA UL(0xd)
235#define MAIR_NORM_WB_NTR_RA UL(0xe)
236#define MAIR_NORM_WB_NTR_RWA UL(0xf)
237
238#define MAIR_NORM_OUTER_SHIFT U(4)
239
240#define MAKE_MAIR_NORMAL_MEMORY(inner, outer) \
241 ((inner) | ((outer) << MAIR_NORM_OUTER_SHIFT))
242
243#define MAKE_MAIR_NORMAL_MEMORY_IO(_mair) \
244 MAKE_MAIR_NORMAL_MEMORY(_mair, _mair)
245
246/*
247 * TTBR Definitions
248 */
AlexeiFedorov537bee02023-02-02 13:38:23 +0000249#define TTBR_CNP_BIT UL(1)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000250
251#define TTBRx_EL2_CnP_SHIFT 0
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100252#define TTBRx_EL2_CnP_WIDTH U(1)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000253
254#define TTBRx_EL2_BADDR_SHIFT 1
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100255#define TTBRx_EL2_BADDR_WIDTH U(47)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000256
Javier Almansa Sobrinof6fff692024-02-02 17:13:57 +0000257#define TTBRx_EL2_BADDR_MSB_LPA2_SHIFT 2
258#define TTBRx_EL2_BADDR_MSB_LPA2_WIDTH U(4)
259#define EL2_BADDR_MSB_LPA2_SHIFT 48
260#define EL2_BADDR_MSB_LPA2_WIDTH TTBRx_EL2_BADDR_MSB_LPA2_WIDTH
261
Soby Mathewb4c6df42022-11-09 11:13:29 +0000262#define TTBRx_EL2_ASID_SHIFT 48
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100263#define TTBRx_EL2_ASID_WIDTH U(16)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000264
265/*
266 * VTTBR Definitions
267 */
268#define VTTBR_EL2_VMID_SHIFT 48
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100269#define VTTBR_EL2_VMID_WIDTH U(16)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000270
271/*
272 * ESR Definitions
273 */
274#define ESR_EL2_EC_SHIFT 26
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100275#define ESR_EL2_EC_WIDTH U(6)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000276
277#define ESR_EL2_IL_SHIFT 25
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100278#define ESR_EL2_IL_WIDTH U(1)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000279
280#define ESR_EL2_ISS_SHIFT 0
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100281#define ESR_EL2_ISS_WIDTH U(25)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000282
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100283#define ESR_EL2_EC_UNKNOWN INPLACE(ESR_EL2_EC, UL(0))
284#define ESR_EL2_EC_WFX INPLACE(ESR_EL2_EC, UL(1))
285#define ESR_EL2_EC_FPU INPLACE(ESR_EL2_EC, UL(7))
286#define ESR_EL2_EC_SVC INPLACE(ESR_EL2_EC, UL(21))
287#define ESR_EL2_EC_HVC INPLACE(ESR_EL2_EC, UL(22))
288#define ESR_EL2_EC_SMC INPLACE(ESR_EL2_EC, UL(23))
289#define ESR_EL2_EC_SYSREG INPLACE(ESR_EL2_EC, UL(24))
290#define ESR_EL2_EC_SVE INPLACE(ESR_EL2_EC, UL(25))
Arunachalam Ganapathy83f46ca2023-08-15 18:13:27 +0100291#define ESR_EL2_EC_SME INPLACE(ESR_EL2_EC, UL(29))
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100292#define ESR_EL2_EC_INST_ABORT INPLACE(ESR_EL2_EC, UL(32))
293#define ESR_EL2_EC_INST_ABORT_SEL INPLACE(ESR_EL2_EC, UL(33))
294#define ESR_EL2_EC_DATA_ABORT INPLACE(ESR_EL2_EC, UL(36))
295#define ESR_EL2_EC_DATA_ABORT_SEL INPLACE(ESR_EL2_EC, UL(37))
296#define ESR_EL2_EC_SERROR INPLACE(ESR_EL2_EC, UL(47))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000297
298/* Data/Instruction Abort ESR fields */
AlexeiFedorov537bee02023-02-02 13:38:23 +0000299#define ESR_EL2_ABORT_ISV_BIT (UL(1) << 24)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000300
301#define ESR_EL2_ABORT_SAS_SHIFT 22
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100302#define ESR_EL2_ABORT_SAS_WIDTH U(2)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000303
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100304#define ESR_EL2_ABORT_SAS_BYTE_VAL 0U
305#define ESR_EL2_ABORT_SAS_HWORD_VAL 1U
306#define ESR_EL2_ABORT_SAS_WORD_VAL 2U
307#define ESR_EL2_ABORT_SAS_DWORD_VAL 3U
Soby Mathewb4c6df42022-11-09 11:13:29 +0000308
AlexeiFedorov537bee02023-02-02 13:38:23 +0000309#define ESR_EL2_ABORT_SSE_BIT (UL(1) << 21)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000310
311#define ESR_EL2_ABORT_SRT_SHIFT 16
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100312#define ESR_EL2_ABORT_SRT_WIDTH U(5)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000313
314#define ESR_EL2_ABORT_SET_SHIFT 11
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100315#define ESR_EL2_ABORT_SET_WIDTH U(2)
316#define ESR_EL2_ABORT_SET_UER INPLACE(ESR_EL2_ABORT_SET, UL(0))
317#define ESR_EL2_ABORT_SET_UC INPLACE(ESR_EL2_ABORT_SET, UL(2))
318#define ESR_EL2_ABORT_SET_UEO INPLACE(ESR_EL2_ABORT_SET, UL(3))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000319
AlexeiFedorov537bee02023-02-02 13:38:23 +0000320#define ESR_EL2_ABORT_SF_BIT (UL(1) << 15)
321#define ESR_EL2_ABORT_FNV_BIT (UL(1) << 10)
322#define ESR_EL2_ABORT_EA_BIT (UL(1) << 9)
323#define ESR_EL2_ABORT_S1PTW_BIT (UL(1) << 7)
324#define ESR_EL2_ABORT_WNR_BIT (UL(1) << 6)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000325#define ESR_EL2_ABORT_FSC_SHIFT 0
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100326#define ESR_EL2_ABORT_FSC_WIDTH U(6)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000327
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100328#define ESR_EL2_ABORT_FSC_TRANSLATION_FAULT UL(0x04)
329#define ESR_EL2_ABORT_FSC_PERMISSION_FAULT UL(0x0c)
330#define ESR_EL2_ABORT_FSC_TRANSLATION_FAULT_L0 UL(0x04)
331#define ESR_EL2_ABORT_FSC_SEA UL(0x10)
332#define ESR_EL2_ABORT_FSC_SEA_TTW_START UL(0x13)
333#define ESR_EL2_ABORT_FSC_SEA_TTW_END UL(0x17)
334#define ESR_EL2_ABORT_FSC_GPF UL(0x28)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000335#define ESR_EL2_ABORT_FSC_LEVEL_SHIFT 0
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100336#define ESR_EL2_ABORT_FSC_LEVEL_WIDTH U(2)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000337
338/* The ESR fields that are reported to the host on Instr./Data Synchronous Abort */
AlexeiFedorov537bee02023-02-02 13:38:23 +0000339#define ESR_NONEMULATED_ABORT_MASK ( \
340 MASK(ESR_EL2_EC) | \
341 MASK(ESR_EL2_ABORT_SET) | \
342 ESR_EL2_ABORT_FNV_BIT | \
343 ESR_EL2_ABORT_EA_BIT | \
344 MASK(ESR_EL2_ABORT_FSC))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000345
AlexeiFedorov537bee02023-02-02 13:38:23 +0000346#define ESR_EMULATED_ABORT_MASK ( \
Soby Mathewb4c6df42022-11-09 11:13:29 +0000347 ESR_NONEMULATED_ABORT_MASK | \
AlexeiFedorov537bee02023-02-02 13:38:23 +0000348 ESR_EL2_ABORT_ISV_BIT | \
349 MASK(ESR_EL2_ABORT_SAS) | \
350 ESR_EL2_ABORT_SF_BIT | \
Soby Mathewb4c6df42022-11-09 11:13:29 +0000351 ESR_EL2_ABORT_WNR_BIT)
352
353#define ESR_EL2_SERROR_DFSC_SHIFT 0
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100354#define ESR_EL2_SERROR_DFSC_WIDTH U(6)
355#define ESR_EL2_SERROR_DFSC_UNCAT INPLACE(ESR_EL2_SERROR_DFSC, UL(0))
356#define ESR_EL2_SERROR_DFSC_ASYNC INPLACE(ESR_EL2_SERROR_DFSC, UL(1))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000357
AlexeiFedorov537bee02023-02-02 13:38:23 +0000358#define ESR_EL2_SERROR_EA_BIT (UL(1) << 9)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000359
360#define ESR_EL2_SERROR_AET_SHIFT 10
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100361#define ESR_EL2_SERROR_AET_WIDTH U(3)
362#define ESR_EL2_SERROR_AET_UC INPLACE(ESR_EL2_SERROR_AET, UL(0))
363#define ESR_EL2_SERROR_AET_UEU INPLACE(ESR_EL2_SERROR_AET, UL(1))
364#define ESR_EL2_SERROR_AET_UEO INPLACE(ESR_EL2_SERROR_AET, UL(2))
365#define ESR_EL2_SERROR_AET_UER INPLACE(ESR_EL2_SERROR_AET, UL(3))
366#define ESR_EL2_SERROR_AET_CE INPLACE(ESR_EL2_SERROR_AET, UL(6))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000367
AlexeiFedorov537bee02023-02-02 13:38:23 +0000368#define ESR_EL2_SERROR_IESB_BIT (UL(1) << 13)
369#define ESR_EL2_SERROR_IDS_BIT (UL(1) << 24)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000370
371/* The ESR fields that are reported to the host on SError */
AlexeiFedorov537bee02023-02-02 13:38:23 +0000372#define ESR_SERROR_MASK ( \
373 ESR_EL2_SERROR_IDS_BIT | \
374 MASK(ESR_EL2_SERROR_AET) | \
375 ESR_EL2_SERROR_EA_BIT | \
376 MASK(ESR_EL2_SERROR_DFSC))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000377
378#define ESR_EL2_SYSREG_TRAP_OP0_SHIFT 20
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100379#define ESR_EL2_SYSREG_TRAP_OP0_WIDTH U(2)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000380
381#define ESR_EL2_SYSREG_TRAP_OP2_SHIFT 17
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100382#define ESR_EL2_SYSREG_TRAP_OP2_WIDTH U(3)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000383
384#define ESR_EL2_SYSREG_TRAP_OP1_SHIFT 14
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100385#define ESR_EL2_SYSREG_TRAP_OP1_WIDTH U(3)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000386
387#define ESR_EL2_SYSREG_TRAP_CRN_SHIFT 10
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100388#define ESR_EL2_SYSREG_TRAP_CRN_WIDTH U(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000389
390#define ESR_EL2_SYSREG_TRAP_RT_SHIFT 5
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100391#define ESR_EL2_SYSREG_TRAP_RT_WIDTH U(5)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000392
393#define ESR_EL2_SYSREG_TRAP_CRM_SHIFT 1
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100394#define ESR_EL2_SYSREG_TRAP_CRM_WIDTH U(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000395
396/* WFx ESR fields */
AlexeiFedorov537bee02023-02-02 13:38:23 +0000397#define ESR_EL2_WFx_TI_BIT (UL(1) << 0)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000398
399/* xVC ESR fields */
400#define ESR_EL2_xVC_IMM_SHIFT 0
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100401#define ESR_EL2_xVC_IMM_WIDTH U(16)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000402
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000403/* ID_AA64DFR0_EL1 definitions */
404#define ID_AA64DFR0_EL1_HPMN0_SHIFT UL(60)
405#define ID_AA64DFR0_EL1_HPMN0_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000406
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000407#define ID_AA64DFR0_EL1_ExtTrcBuff_SHIFT UL(56)
408#define ID_AA64DFR0_EL1_ExtTrcBuff_WIDTH UL(4)
409
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000410#define ID_AA64DFR0_EL1_BRBE_SHIFT UL(52)
411#define ID_AA64DFR0_EL1_BRBE_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000412
413#define ID_AA64DFR0_EL1_MTPMU_SHIFT UL(48)
414#define ID_AA64DFR0_EL1_MTPMU_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000415
416#define ID_AA64DFR0_EL1_TraceBuffer_SHIFT UL(44)
417#define ID_AA64DFR0_EL1_TraceBuffer_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000418
419#define ID_AA64DFR0_EL1_TraceFilt_SHIFT UL(40)
420#define ID_AA64DFR0_EL1_TraceFilt_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000421
422#define ID_AA64DFR0_EL1_DoubleLock_SHIFT UL(36)
423#define ID_AA64DFR0_EL1_DoubleLock_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000424
425#define ID_AA64DFR0_EL1_PMSVer_SHIFT UL(32)
426#define ID_AA64DFR0_EL1_PMSVer_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000427
428#define ID_AA64DFR0_EL1_CTX_CMPS_SHIFT UL(28)
429#define ID_AA64DFR0_EL1_CTX_CMPS_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000430
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000431#define ID_AA64DFR0_EL1_SEBEP_SHIFT UL(24)
432#define ID_AA64DFR0_EL1_SEBEP_WIDTH UL(4)
433
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000434#define ID_AA64DFR0_EL1_WRPs_SHIFT UL(20)
435#define ID_AA64DFR0_EL1_WRPs_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000436
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000437#define ID_AA64DFR0_EL1_PMSS_SHIFT UL(16)
438#define ID_AA64DFR0_EL1_PMSS_WIDTH UL(4)
439
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000440#define ID_AA64DFR0_EL1_BRPs_SHIFT UL(12)
441#define ID_AA64DFR0_EL1_BRPs_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000442
443#define ID_AA64DFR0_EL1_PMUVer_SHIFT UL(8)
444#define ID_AA64DFR0_EL1_PMUVer_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000445
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000446/* Performance Monitors Extension version */
447#define ID_AA64DFR0_EL1_PMUv3p7 UL(7)
448#define ID_AA64DFR0_EL1_PMUv3p8 UL(8)
449#define ID_AA64DFR0_EL1_PMUv3p9 UL(9)
450
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000451#define ID_AA64DFR0_EL1_TraceVer_SHIFT UL(4)
452#define ID_AA64DFR0_EL1_TraceVer_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000453
454#define ID_AA64DFR0_EL1_DebugVer_SHIFT UL(0)
455#define ID_AA64DFR0_EL1_DebugVer_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000456
457/* Debug architecture version */
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000458#define ID_AA64DFR0_EL1_Debugv8 UL(6)
459#define ID_AA64DFR0_EL1_DebugVHE UL(7)
460#define ID_AA64DFR0_EL1_Debugv8p2 UL(8)
461#define ID_AA64DFR0_EL1_Debugv8p4 UL(9)
462#define ID_AA64DFR0_EL1_Debugv8p8 UL(10)
463
464/* ID_AA64DFR1_EL1 definitions */
465#define ID_AA64DFR1_EL1_EBEP_SHIFT UL(48)
466#define ID_AA64DFR1_EL1_EBEP_WIDTH UL(4)
467
468#define ID_AA64DFR1_EL1_ICNTR_SHIFT UL(36)
469#define ID_AA64DFR1_EL1_ICNTR_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000470
Soby Mathewb4c6df42022-11-09 11:13:29 +0000471/* ID_AA64PFR0_EL1 definitions */
472#define ID_AA64PFR0_EL1_SVE_SHIFT UL(32)
473#define ID_AA64PFR0_EL1_SVE_WIDTH UL(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000474
475#define ID_AA64PFR0_EL1_AMU_SHIFT UL(44)
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100476#define ID_AA64PFR0_EL1_AMU_WIDTH UL(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000477
Arunachalam Ganapathya27de372023-03-06 11:13:49 +0000478/* ID_AA64PFR1_EL1 definitions */
479#define ID_AA64PFR1_EL1_MTE_SHIFT UL(8)
480#define ID_AA64PFR1_EL1_MTE_WIDTH UL(4)
481
Arunachalam Ganapathy83f46ca2023-08-15 18:13:27 +0100482#define ID_AA64PFR1_EL1_SME_SHIFT UL(24)
483#define ID_AA64PFR1_EL1_SME_WIDTH UL(4)
484#define ID_AA64PFR1_EL1_SME_NOT_IMPLEMENTED UL(0)
485#define ID_AA64PFR1_EL1_SME_IMPLEMENTED UL(1)
486#define ID_AA64PFR1_EL1_SME2_IMPLEMENTED UL(2)
487
Soby Mathewb4c6df42022-11-09 11:13:29 +0000488/* ID_AA64MMFR0_EL1 definitions */
489#define ID_AA64MMFR0_EL1_PARANGE_SHIFT U(0)
AlexeiFedorov537bee02023-02-02 13:38:23 +0000490#define ID_AA64MMFR0_EL1_PARANGE_WIDTH UL(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000491
492#define PARANGE_0000_WIDTH U(32)
493#define PARANGE_0001_WIDTH U(36)
494#define PARANGE_0010_WIDTH U(40)
495#define PARANGE_0011_WIDTH U(42)
496#define PARANGE_0100_WIDTH U(44)
497#define PARANGE_0101_WIDTH U(48)
498#define PARANGE_0110_WIDTH U(52)
499
AlexeiFedorov537bee02023-02-02 13:38:23 +0000500#define ID_AA64MMFR0_EL1_ECV_SHIFT UL(60)
501#define ID_AA64MMFR0_EL1_ECV_WIDTH UL(4)
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000502#define ID_AA64MMFR0_EL1_ECV_NOT_SUPPORTED UL(0x0)
503#define ID_AA64MMFR0_EL1_ECV_SUPPORTED UL(0x1)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000504#define ID_AA64MMFR0_EL1_ECV_SELF_SYNCH ULL(0x2)
505
AlexeiFedorov537bee02023-02-02 13:38:23 +0000506#define ID_AA64MMFR0_EL1_FGT_SHIFT UL(56)
507#define ID_AA64MMFR0_EL1_FGT_WIDTH UL(4)
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000508#define ID_AA64MMFR0_EL1_FGT_NOT_SUPPORTED UL(0x0)
509#define ID_AA64MMFR0_EL1_FGT_SUPPORTED UL(0x1)
510#define ID_AA64MMFR0_EL1_FGT2_SUPPORTED UL(0x2)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000511
512#define ID_AA64MMFR0_EL1_TGRAN4_2_SHIFT U(40)
AlexeiFedorov537bee02023-02-02 13:38:23 +0000513#define ID_AA64MMFR0_EL1_TGRAN4_2_WIDTH U(4)
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000514#define ID_AA64MMFR0_EL1_TGRAN4_2_TGRAN4 UL(0x0)
515#define ID_AA64MMFR0_EL1_TGRAN4_2_NOT_SUPPORTED UL(0x1)
516#define ID_AA64MMFR0_EL1_TGRAN4_2_SUPPORTED UL(0x2)
517#define ID_AA64MMFR0_EL1_TGRAN4_2_LPA2 UL(0x3)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000518
AlexeiFedorov537bee02023-02-02 13:38:23 +0000519#define ID_AA64MMFR0_EL1_TGRAN16_2_SHIFT UL(32)
520#define ID_AA64MMFR0_EL1_TGRAN16_2_WIDTH UL(4)
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000521#define ID_AA64MMFR0_EL1_TGRAN16_2_TGRAN16 UL(0x0)
522#define ID_AA64MMFR0_EL1_TGRAN16_2_NOT_SUPPORTED UL(0x1)
523#define ID_AA64MMFR0_EL1_TGRAN16_2_SUPPORTED UL(0x2)
524#define ID_AA64MMFR0_EL1_TGRAN16_2_LPA2 UL(0x3)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000525
AlexeiFedorov537bee02023-02-02 13:38:23 +0000526#define ID_AA64MMFR0_EL1_TGRAN4_SHIFT UL(28)
527#define ID_AA64MMFR0_EL1_TGRAN4_WIDTH UL(4)
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000528#define ID_AA64MMFR0_EL1_TGRAN4_SUPPORTED UL(0x0)
529#define ID_AA64MMFR0_EL1_TGRAN4_LPA2 UL(0x1)
530#define ID_AA64MMFR0_EL1_TGRAN4_NOT_SUPPORTED UL(0xf)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000531
532#define ID_AA64MMFR0_EL1_TGRAN64_SHIFT UL(24)
AlexeiFedorov537bee02023-02-02 13:38:23 +0000533#define ID_AA64MMFR0_EL1_TGRAN64_WIDTH UL(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000534#define ID_AA64MMFR0_EL1_TGRAN64_SUPPORTED UL(0x0)
535#define ID_AA64MMFR0_EL1_TGRAN64_NOT_SUPPORTED UL(0xf)
536
537#define ID_AA64MMFR0_EL1_TGRAN16_SHIFT UL(20)
AlexeiFedorov537bee02023-02-02 13:38:23 +0000538#define ID_AA64MMFR0_EL1_TGRAN16_WIDTH UL(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000539#define ID_AA64MMFR0_EL1_TGRAN16_NOT_SUPPORTED UL(0x0)
540#define ID_AA64MMFR0_EL1_TGRAN16_SUPPORTED UL(0x1)
541#define ID_AA64MMFR0_EL1_TGRAN16_LPA2 UL(0x2)
542
543/* RNDR definitions */
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000544#define ID_AA64ISAR0_EL1_RNDR_SHIFT UL(60)
545#define ID_AA64ISAR0_EL1_RNDR_WIDTH UL(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000546
547/* ID_AA64MMFR1_EL1 definitions */
548#define ID_AA64MMFR1_EL1_VMIDBits_SHIFT UL(4)
AlexeiFedorov537bee02023-02-02 13:38:23 +0000549#define ID_AA64MMFR1_EL1_VMIDBits_WIDTH UL(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000550#define ID_AA64MMFR1_EL1_VMIDBits_8 UL(0)
551#define ID_AA64MMFR1_EL1_VMIDBits_16 UL(2)
552
Arunachalam Ganapathyf6491212023-02-23 16:04:34 +0000553/* SVE Feature ID register 0 */
554#define ID_AA64ZFR0_EL1 S3_0_C0_C4_4
555
Arunachalam Ganapathy83f46ca2023-08-15 18:13:27 +0100556/* SME Feature ID register 0 */
557#define ID_AA64SMFR0_EL1 S3_0_C0_C4_5
558
AlexeiFedorovbe9209c2024-02-27 15:16:00 +0000559/* PAR_EL1 definitions */
560#define PAR_EL1_F_BIT (UL(1) << 0)
561
Soby Mathewb4c6df42022-11-09 11:13:29 +0000562/* HPFAR_EL2 definitions */
563#define HPFAR_EL2_FIPA_SHIFT 4
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100564#define HPFAR_EL2_FIPA_WIDTH U(40)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000565#define HPFAR_EL2_FIPA_OFFSET 8
566
567/* SPSR definitions */
568#define SPSR_EL2_MODE_SHIFT 0
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100569#define SPSR_EL2_MODE_WIDTH U(4)
570#define SPSR_EL2_MODE_EL0t INPLACE(SPSR_EL2_MODE, UL(0))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000571
572#define SPSR_EL2_MODE_SHIFT 0
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100573#define SPSR_EL2_MODE_WIDTH U(4)
574#define SPSR_EL2_MODE_EL1h INPLACE(SPSR_EL2_MODE, UL(5))
575#define SPSR_EL2_MODE_EL1t INPLACE(SPSR_EL2_MODE, UL(4))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000576
577/* FIXME: DAIF definitions are redundant here. Might need unification. */
578#define SPSR_EL2_nRW_SHIFT 4
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100579#define SPSR_EL2_nRW_WIDTH U(1)
580#define SPSR_EL2_nRW_AARCH64 INPLACE(SPSR_EL2_nRW, UL(0))
581#define SPSR_EL2_nRW_AARCH32 INPLACE(SPSR_EL2_nRW, UL(1))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000582
AlexeiFedorov537bee02023-02-02 13:38:23 +0000583#define SPSR_EL2_DAIF_SHIFT 6
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100584#define SPSR_EL2_AIF_SHIFT U(6)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000585
AlexeiFedorov537bee02023-02-02 13:38:23 +0000586#define DAIF_FIQ_BIT (UL(1) << 0)
587#define DAIF_IRQ_BIT (UL(1) << 1)
588#define DAIF_ABT_BIT (UL(1) << 2)
589#define DAIF_DBG_BIT (UL(1) << 3)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000590
AlexeiFedorov537bee02023-02-02 13:38:23 +0000591#define SPSR_EL2_F_BIT (UL(1) << 6)
592#define SPSR_EL2_I_BIT (UL(1) << 7)
593#define SPSR_EL2_A_BIT (UL(1) << 8)
594#define SPSR_EL2_D_BIT (UL(1) << 9)
595#define SPSR_EL2_SSBS_BIT (UL(1) << 12)
596#define SPSR_EL2_ALLINT_BIT (UL(1) << 13)
597#define SPSR_EL2_IL_BIT (UL(1) << 20)
598#define SPSR_EL2_SS_BIT (UL(1) << 21)
599#define SPSR_EL2_PAN_BIT (UL(1) << 22)
600#define SPSR_EL2_UAO_BIT (UL(1) << 23)
601#define SPSR_EL2_DIT_BIT (UL(1) << 24)
602#define SPSR_EL2_TCO_BIT (UL(1) << 25)
603#define SPSR_EL2_V_BIT (UL(1) << 28)
604#define SPSR_EL2_C_BIT (UL(1) << 29)
605#define SPSR_EL2_Z_BIT (UL(1) << 30)
606#define SPSR_EL2_N_BIT (UL(1) << 31)
607#define SPSR_EL2_PM_BIT (UL(1) << 32)
608#define SPSR_EL2_PPEND_BIT (UL(1) << 33)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000609
Arunachalam Ganapathy4f601e72023-05-22 11:49:29 +0100610/* Floating point control and status register */
611#define FPCR S3_3_C4_C4_0
612#define FPSR S3_3_C4_C4_1
613
Arunachalam Ganapathyf6491212023-02-23 16:04:34 +0000614/* SVE Control Register */
615#define ZCR_EL2 S3_4_C1_C2_0
Arunachalam Ganapathy2b456582023-05-19 11:56:44 +0100616#define ZCR_EL2_LEN_SHIFT UL(0)
617#define ZCR_EL2_LEN_WIDTH UL(4)
Arunachalam Ganapathyf6491212023-02-23 16:04:34 +0000618
Arunachalam Ganapathy4f601e72023-05-22 11:49:29 +0100619#define ZCR_EL12 S3_5_C1_C2_0
620
Arunachalam Ganapathy83f46ca2023-08-15 18:13:27 +0100621/* SME Control Register */
622#define SMCR_EL2 S3_4_C1_C2_6
623#define SMCR_EL2_LEN_SHIFT UL(0)
624#define SMCR_EL2_LEN_WIDTH UL(4)
625/*
626 * SMCR_EL2_RAZ_LEN is defined to find the architecturally permitted SVL. This
627 * is a combination of RAZ and LEN bit fields.
628 */
629#define SMCR_EL2_RAZ_LEN_SHIFT UL(0)
630#define SMCR_EL2_RAZ_LEN_WIDTH UL(9)
631#define SMCR_EL2_EZT0_BIT (UL(1) << 30)
632#define SMCR_EL2_FA64_BIT (UL(1) << 31)
633
634/* Streaming Vector Control register */
635#define SVCR S3_3_C4_C2_2
636#define SVCR_SM_BIT (UL(1) << 0)
637#define SVCR_ZA_BIT (UL(1) << 1)
638
Soby Mathewb4c6df42022-11-09 11:13:29 +0000639/* VTCR definitions */
640#define VTCR_T0SZ_SHIFT 0
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100641#define VTCR_T0SZ_WIDTH U(6)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000642
643#define VTCR_SL0_SHIFT 6
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100644#define VTCR_SL0_WIDTH U(2)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000645
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100646#define VTCR_SL0_4K_L2 INPLACE(VTCR_SL0, UL(0))
647#define VTCR_SL0_4K_L1 INPLACE(VTCR_SL0, UL(1))
648#define VTCR_SL0_4K_L0 INPLACE(VTCR_SL0, UL(2))
649#define VTCR_SL0_4K_L3 INPLACE(VTCR_SL0, UL(3))
Javier Almansa Sobrinof6fff692024-02-02 17:13:57 +0000650#define VTCR_SL0_4K_LM1 VTCR_SL0_4K_L2
651
652#define VTCR_SL2_SHIFT 33
653#define VTCR_SL2_WIDTH U(1)
654#define VCTR_SL2_4K_LM1 INPLACE(VTCR_SL2, UL(1))
655
656#define VTCR_DS_SHIFT 32
657#define VTCR_DS_WIDTH U(1)
658#define VTCR_DS_52BIT INPLACE(VTCR_DS, UL(1))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000659
660#define VTCR_IRGN0_SHIFT 8
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100661#define VTCR_IRGN0_WIDTH U(2)
662#define VTCR_IRGN0_WBRAWA INPLACE(VTCR_IRGN0, UL(1))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000663
664#define VTCR_ORGN0_SHIFT 10
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100665#define VTCR_ORGN0_WIDTH U(2)
666#define VTCR_ORGN0_WBRAWA INPLACE(VTCR_ORGN0, UL(1))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000667
668#define VTCR_SH0_SHIFT 12
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100669#define VTCR_SH0_WIDTH U(2)
670#define VTCR_SH0_IS INPLACE(VTCR_SH0, UL(3))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000671
672#define VTCR_TG0_SHIFT 14
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100673#define VTCR_TG0_WIDTH U(2)
674#define VTCR_TG0_4K INPLACE(VTCR_TG0, UL(0))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000675
676#define VTCR_PS_SHIFT 16
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100677#define VTCR_PS_WIDTH U(3)
678#define VTCR_PS_40 INPLACE(VTCR_PS, UL(2))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000679
680#define VTCR_VS (UL(1) << 19)
681#define VTCR_NSA (UL(1) << 30)
682#define VTCR_RES1 (UL(1) << 31)
683
684#define VTCR_FLAGS ( \
685 VTCR_IRGN0_WBRAWA | /* PTW inner cache attr. is WB RAWA*/ \
686 VTCR_ORGN0_WBRAWA | /* PTW outer cache attr. is WB RAWA*/ \
687 VTCR_SH0_IS | /* PTW shareability attr. is Outer Sharable*/\
688 VTCR_TG0_4K | /* 4K granule size in non-secure PT*/ \
689 VTCR_PS_40 | /* size(PA) = 40 */ \
690 /* VS = 0 size(VMID) = 8 */ \
691 /* NSW = 0 non-secure s2 is made of secure pages*/ \
692 VTCR_NSA | /* non-secure IPA maps to non-secure PA */ \
693 VTCR_RES1 \
694 )
695
696
Soby Mathewb4c6df42022-11-09 11:13:29 +0000697/* PMCR_EL0 Definitions */
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000698#define PMCR_EL0_N_SHIFT 11
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100699#define PMCR_EL0_N_WIDTH U(5)
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000700#define PMCR_EL0_LC_BIT (UL(1) << 6)
701#define PMCR_EL0_DP_BIT (UL(1) << 5)
702#define PMCR_EL0_C_BIT (UL(1) << 2)
703#define PMCR_EL0_P_BIT (UL(1) << 1)
704#define PMCR_EL0_E_BIT (UL(1) << 0)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000705
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000706#define PMCR_EL0_INIT (PMCR_EL0_LC_BIT | PMCR_EL0_DP_BIT)
707#define PMCR_EL0_INIT_RESET (PMCR_EL0_INIT | PMCR_EL0_C_BIT | \
708 PMCR_EL0_P_BIT)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000709
710/* MDSCR_EL1 Definitions */
AlexeiFedorov537bee02023-02-02 13:38:23 +0000711#define MDSCR_EL1_TDCC_BIT (UL(1) << 12)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000712
713/* SCTLR register definitions */
Arvind Ram Prakashbd36a1b2022-12-15 12:16:36 -0600714#define SCTLR_ELx_RES1_BIT ((UL(1) << 22) /* TODO: ARMv8.5-CSEH, otherwise RES1 */ | \
715 (UL(1) << 11) /* TODO: ARMv8.5-CSEH, otherwise RES1 */)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000716
Arvind Ram Prakashbd36a1b2022-12-15 12:16:36 -0600717#define SCTLR_ELx_M_BIT (UL(1) << 0)
AlexeiFedorovbb01b422023-10-24 17:00:50 +0100718#define SCTLR_ELx_A_BIT (UL(1) << 1)
Arvind Ram Prakashbd36a1b2022-12-15 12:16:36 -0600719#define SCTLR_ELx_C_BIT (UL(1) << 2)
720#define SCTLR_ELx_SA_BIT (UL(1) << 3)
721#define SCTLR_ELx_SA0_BIT (UL(1) << 4)
722#define SCTLR_ELx_CP15BEN_BIT (UL(1) << 5)
723#define SCTLR_ELx_nAA_BIT (UL(1) << 6)
724#define SCTLR_ELx_SED_BIT (UL(1) << 8)
725#define SCTLR_ELx_EOS_BIT (UL(1) << 11)
726#define SCTLR_ELx_I_BIT (UL(1) << 12)
727#define SCTLR_ELx_DZE_BIT (UL(1) << 14)
728#define SCTLR_ELx_UCT_BIT (UL(1) << 15)
729#define SCTLR_ELx_nTWI_BIT (UL(1) << 16)
730#define SCTLR_ELx_nTWE_BIT (UL(1) << 18)
731#define SCTLR_ELx_WXN_BIT (UL(1) << 19)
732#define SCTLR_ELx_TSCXT_BIT (UL(1) << 20)
733#define SCTLR_ELx_EIS_BIT (UL(1) << 22)
734#define SCTLR_ELx_SPAN_BIT (UL(1) << 23)
735#define SCTLR_ELx_EE_BIT (UL(1) << 25)
736#define SCTLR_ELx_UCI_BIT (UL(1) << 26)
737#define SCTLR_ELx_nTLSMD_BIT (UL(1) << 28)
738#define SCTLR_ELx_LSMAOE_BIT (UL(1) << 29)
739#define SCTLR_ELx_EnIA_BIT (UL(1) << 31)
Shruti Guptaa4cb2a22023-05-23 14:55:49 +0100740#define SCTLR_ELx_BT0_BIT (UL(1) << 35)
741#define SCTLR_ELx_BT1_BIT (UL(1) << 36)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000742
Arvind Ram Prakashbd36a1b2022-12-15 12:16:36 -0600743#define SCTLR_EL1_FLAGS (SCTLR_ELx_SPAN_BIT | SCTLR_ELx_EIS_BIT | SCTLR_ELx_nTWE_BIT | \
744 SCTLR_ELx_nTWI_BIT | SCTLR_ELx_EOS_BIT | SCTLR_ELx_nAA_BIT | \
745 SCTLR_ELx_CP15BEN_BIT | SCTLR_ELx_SA0_BIT | SCTLR_ELx_SA_BIT)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000746
AlexeiFedorovbb01b422023-10-24 17:00:50 +0100747#define SCTLR_EL2_BITS (SCTLR_ELx_C_BIT /* Data accesses are cacheable
Arvind Ram Prakashbd36a1b2022-12-15 12:16:36 -0600748 * as per translation tables */ | \
749 /* SCTLR_EL2_M = 0 (MMU disabled) */ \
750 /* SCTLR_EL2_A = 0
751 * (No alignment checks) */ \
752 SCTLR_ELx_SA_BIT /* SP aligned at EL2 */ | \
753 SCTLR_ELx_SA0_BIT /* SP Alignment check enable for EL0 */ \
754 /* SCTLR_EL2_CP15BEN = 0 (EL0 using AArch32:
755 * EL0 execution of the CP15DMB, CP15DSB,
756 * and CP15ISB instructions is
757 * UNDEFINED. */ \
758 /* SCTLR_EL2_NAA = 0 (unaligned MA fault
759 * at EL2 and EL0) */ \
760 /* SCTLR_EL2_ITD = 0 (A32 Only) */ | \
761 SCTLR_ELx_SED_BIT /* A32 Only, RES1 for non-A32 systems */ \
762 /* SCTLR_EL2_EOS TODO: ARMv8.5-CSEH,
763 * otherwise RES1 */ | \
764 SCTLR_ELx_I_BIT /* I$ is ON for EL2 and EL0 */ | \
765 SCTLR_ELx_DZE_BIT /* Do not trap DC ZVA */ | \
766 SCTLR_ELx_UCT_BIT /* Allow EL0 access to CTR_EL0 */ | \
767 SCTLR_ELx_nTWI_BIT /* Don't trap WFI from EL0 to EL2 */ | \
768 SCTLR_ELx_nTWE_BIT /* Don't trap WFE from EL0 to EL2 */ | \
769 SCTLR_ELx_WXN_BIT /* W implies XN */ | \
770 SCTLR_ELx_TSCXT_BIT /* Trap EL0 accesss to SCXTNUM_EL0 */ | \
771 /* SCTLR_EL2_EIS EL2 exception is context
772 * synchronizing
773 */ \
774 SCTLR_ELx_RES1_BIT | \
775 /* SCTLR_EL2_SPAN = 0 (Set PSTATE.PAN = 1 on
776 * exceptions to EL2)) */ \
777 SCTLR_ELx_UCI_BIT /* Allow cache maintenance
778 * instructions at EL0 */ | \
779 SCTLR_ELx_nTLSMD_BIT /* A32/T32 only */ | \
780 SCTLR_ELx_LSMAOE_BIT /* A32/T32 only */)
781
AlexeiFedorovbb01b422023-10-24 17:00:50 +0100782#ifdef RMM_FPU_USE_AT_REL2
783#define SCTLR_EL2_INIT SCTLR_EL2_BITS
784#else
785#define SCTLR_EL2_INIT (SCTLR_EL2_BITS | \
786 SCTLR_ELx_A_BIT /* Alignment fault check enable */)
787#endif
788
Arvind Ram Prakashbd36a1b2022-12-15 12:16:36 -0600789#define SCTLR_EL2_RUNTIME (SCTLR_EL2_INIT | \
790 SCTLR_ELx_M_BIT /* MMU enabled */)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000791
Arunachalam Ganapathy9ade18b2023-06-12 14:07:21 +0100792/* RMM sets HCR_EL2.E2H to 1. CPTR_EL2 definitions when HCR_EL2.E2H == 1 */
793#define CPTR_EL2_VHE_TTA (UL(1) << 28)
794#define CPTR_EL2_VHE_TAM (UL(1) << 30)
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100795
Arunachalam Ganapathy9ade18b2023-06-12 14:07:21 +0100796#define CPTR_EL2_VHE_FPEN_SHIFT UL(20)
797#define CPTR_EL2_VHE_FPEN_WIDTH UL(2)
798#define CPTR_EL2_VHE_FPEN_TRAP_ALL_00 UL(0)
799#define CPTR_EL2_VHE_FPEN_TRAP_TGE_01 UL(1)
800#define CPTR_EL2_VHE_FPEN_TRAP_ALL_10 UL(2)
801#define CPTR_EL2_VHE_FPEN_NO_TRAP_11 UL(3)
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100802
Arunachalam Ganapathy9ade18b2023-06-12 14:07:21 +0100803#define CPTR_EL2_VHE_ZEN_SHIFT UL(16)
804#define CPTR_EL2_VHE_ZEN_WIDTH UL(2)
805#define CPTR_EL2_VHE_ZEN_TRAP_ALL_00 UL(0x0)
806#define CPTR_EL2_VHE_ZEN_NO_TRAP_11 UL(0x3)
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100807
Arunachalam Ganapathy83f46ca2023-08-15 18:13:27 +0100808#define CPTR_EL2_VHE_SMEN_SHIFT UL(24)
809#define CPTR_EL2_VHE_SMEN_WIDTH UL(2)
810#define CPTR_EL2_VHE_SMEN_TRAP_ALL_00 UL(0x0)
811#define CPTR_EL2_VHE_SMEN_NO_TRAP_11 UL(0x3)
812
Arunachalam Ganapathyddccbae2023-10-03 11:29:42 +0100813#define CPTR_EL2_VHE_SIMD_MASK (MASK(CPTR_EL2_VHE_FPEN) | \
814 MASK(CPTR_EL2_VHE_ZEN) | \
815 MASK(CPTR_EL2_VHE_SMEN))
816
Arunachalam Ganapathy83f46ca2023-08-15 18:13:27 +0100817/* Trap all AMU, trace, FPU, SVE, SME accesses */
Arunachalam Ganapathy9ade18b2023-06-12 14:07:21 +0100818#define CPTR_EL2_VHE_INIT ((CPTR_EL2_VHE_ZEN_TRAP_ALL_00 << \
819 CPTR_EL2_VHE_ZEN_SHIFT) | \
Arunachalam Ganapathy83f46ca2023-08-15 18:13:27 +0100820 (CPTR_EL2_VHE_SMEN_TRAP_ALL_00 << \
821 CPTR_EL2_VHE_SMEN_SHIFT) | \
Arunachalam Ganapathy9ade18b2023-06-12 14:07:21 +0100822 (CPTR_EL2_VHE_FPEN_TRAP_ALL_00 << \
823 CPTR_EL2_VHE_FPEN_SHIFT) | \
824 CPTR_EL2_VHE_TTA | \
825 CPTR_EL2_VHE_TAM)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000826
827/* MDCR_EL2 definitions */
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000828#define MDCR_EL2_HPMFZS (UL(1) << 36)
829#define MDCR_EL2_HPMFZO (UL(1) << 29)
830#define MDCR_EL2_MTPME (UL(1) << 28)
831#define MDCR_EL2_TDCC (UL(1) << 27)
AlexeiFedorov537bee02023-02-02 13:38:23 +0000832#define MDCR_EL2_HLP (UL(1) << 26)
833#define MDCR_EL2_HCCD (UL(1) << 23)
834#define MDCR_EL2_TTRF (UL(1) << 19)
835#define MDCR_EL2_HPMD (UL(1) << 17)
836#define MDCR_EL2_TPMS (UL(1) << 14)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000837#define MDCR_EL2_E2PB(x) ((x) << 12)
AlexeiFedorov537bee02023-02-02 13:38:23 +0000838#define MDCR_EL2_E2PB_EL1 UL(3)
839#define MDCR_EL2_TDRA_BIT (UL(1) << 11)
840#define MDCR_EL2_TDOSA_BIT (UL(1) << 10)
841#define MDCR_EL2_TDA_BIT (UL(1) << 9)
842#define MDCR_EL2_TDE_BIT (UL(1) << 8)
843#define MDCR_EL2_HPME_BIT (UL(1) << 7)
844#define MDCR_EL2_TPM_BIT (UL(1) << 6)
845#define MDCR_EL2_TPMCR_BIT (UL(1) << 5)
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000846
847#define MDCR_EL2_HPMN_SHIFT UL(0)
848#define MDCR_EL2_HPMN_WIDTH UL(5)
849
850#define MDCR_EL2_INIT (MDCR_EL2_MTPME | \
851 MDCR_EL2_HCCD | \
852 MDCR_EL2_HPMD | \
853 MDCR_EL2_TDA_BIT | \
854 MDCR_EL2_TPM_BIT | \
855 MDCR_EL2_TPMCR_BIT)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000856
Arvind Ram Prakashbd36a1b2022-12-15 12:16:36 -0600857/* Armv8.3 Pointer Authentication Registers */
858#define APIAKeyLo_EL1 S3_0_C2_C1_0
859#define APIAKeyHi_EL1 S3_0_C2_C1_1
860#define APIBKeyLo_EL1 S3_0_C2_C1_2
861#define APIBKeyHi_EL1 S3_0_C2_C1_3
862#define APDAKeyLo_EL1 S3_0_C2_C2_0
863#define APDAKeyHi_EL1 S3_0_C2_C2_1
864#define APDBKeyLo_EL1 S3_0_C2_C2_2
865#define APDBKeyHi_EL1 S3_0_C2_C2_3
866#define APGAKeyLo_EL1 S3_0_C2_C3_0
867#define APGAKeyHi_EL1 S3_0_C2_C3_1
868
Soby Mathewb4c6df42022-11-09 11:13:29 +0000869/* MPIDR definitions */
870#define MPIDR_EL1_AFF_MASK 0xFF
871#define MPIDR_EL1_AFF0_SHIFT 0
872#define MPIDR_EL1_AFF1_SHIFT 8
873#define MPIDR_EL1_AFF2_SHIFT 16
874#define MPIDR_EL1_AFF3_SHIFT 32
875#define MPIDR_EL1_MT_MASK (UL(1) << 24)
876#define MPIDR_EL1_AFFINITY_BITS 8
877
878#define MPIDR_EL1_AFF0 INPLACE(MPIDR_EL1_AFF0, MPIDR_EL1_AFF_MASK)
879#define MPIDR_EL1_AFF1 INPLACE(MPIDR_EL1_AFF1, MPIDR_EL1_AFF_MASK)
880#define MPIDR_EL1_AFF2 INPLACE(MPIDR_EL1_AFF2, MPIDR_EL1_AFF_MASK)
881#define MPIDR_EL1_AFF3 INPLACE(MPIDR_EL1_AFF3, MPIDR_EL1_AFF_MASK)
882
883/*
884 * RmiRecMpidr type definitions.
885 *
886 * 'MPIDR_EL2_AFF<n>_VAL_SHIFT' constants specify the right shift
887 * for affinity field <n> that gives the field's actual value.
888 *
889 * Aff0[3:0] - Affinity level 0
890 * For compatibility with GICv3 only Aff0[3:0] field is used,
891 * and Aff0[7:4] of a REC MPIDR value is RES0.
892 */
893#define MPIDR_EL2_AFF0_SHIFT 0
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100894#define MPIDR_EL2_AFF0_WIDTH U(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000895#define MPIDR_EL2_AFF0_VAL_SHIFT 0
896
897/* Aff1[15:8] - Affinity level 1 */
898#define MPIDR_EL2_AFF1_SHIFT 8
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100899#define MPIDR_EL2_AFF1_WIDTH U(8)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000900#define MPIDR_EL2_AFF1_VAL_SHIFT 4
901
902/* Aff2[23:16] - Affinity level 2 */
903#define MPIDR_EL2_AFF2_SHIFT 16
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100904#define MPIDR_EL2_AFF2_WIDTH U(8)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000905#define MPIDR_EL2_AFF2_VAL_SHIFT 4
906
907/* Aff3[39:32] - Affinity level 3 */
908#define MPIDR_EL2_AFF3_SHIFT 32
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100909#define MPIDR_EL2_AFF3_WIDTH U(8)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000910#define MPIDR_EL2_AFF3_VAL_SHIFT 12
911
912/*
913 * Extract the value of Aff<n> register field shifted right
914 * so it can be evaluated directly.
915 */
AlexeiFedorov537bee02023-02-02 13:38:23 +0000916#define MPIDR_EL2_AFF(n, reg) \
Soby Mathewb4c6df42022-11-09 11:13:29 +0000917 (((reg) & MASK(MPIDR_EL2_AFF##n)) >> MPIDR_EL2_AFF##n##_VAL_SHIFT)
918
919/* VMPIDR_EL2 bit [31] = RES1 */
920#define VMPIDR_EL2_RES1 (UL(1) << 31)
921
922/* ICC_SRE_EL2 defintions */
923#define ICC_SRE_EL2_ENABLE (UL(1) << 3) /* Enable lower EL access to ICC_SRE_EL1 */
924#define ICC_SRE_EL2_DIB (UL(1) << 2) /* Disable IRQ bypass */
925#define ICC_SRE_EL2_DFB (UL(1) << 1) /* Disable FIQ bypass */
926#define ICC_SRE_EL2_SRE (UL(1) << 0) /* Enable sysreg access */
927
AlexeiFedorov537bee02023-02-02 13:38:23 +0000928#define ICC_SRE_EL2_INIT (ICC_SRE_EL2_ENABLE | ICC_SRE_EL2_DIB | \
Soby Mathewb4c6df42022-11-09 11:13:29 +0000929 ICC_SRE_EL2_DFB | ICC_SRE_EL2_SRE)
930
931/* MPAM definitions */
932#define MPAM2_EL2_INIT 0x0
933#define MPAMHCR_EL2_INIT 0x0
934
935#define PMSCR_EL2_INIT 0x0
936
937#define SYSREG_ESR(op0, op1, crn, crm, op2) \
AlexeiFedorov13b86dd2023-08-29 10:38:09 +0100938 ((UL(op0) << ESR_EL2_SYSREG_TRAP_OP0_SHIFT) | \
939 (UL(op1) << ESR_EL2_SYSREG_TRAP_OP1_SHIFT) | \
940 (UL(crn) << ESR_EL2_SYSREG_TRAP_CRN_SHIFT) | \
941 (UL(crm) << ESR_EL2_SYSREG_TRAP_CRM_SHIFT) | \
942 (UL(op2) << ESR_EL2_SYSREG_TRAP_OP2_SHIFT))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000943
944#define ESR_EL2_SYSREG_MASK SYSREG_ESR(3, 7, 15, 15, 7)
945
946#define ESR_EL2_SYSREG_ID_MASK SYSREG_ESR(3, 7, 15, 0, 0)
947#define ESR_EL2_SYSREG_ID SYSREG_ESR(3, 0, 0, 0, 0)
948
949#define ESR_EL2_SYSREG_ID_AA64PFR0_EL1 SYSREG_ESR(3, 0, 0, 4, 0)
950#define ESR_EL2_SYSREG_ID_AA64PFR1_EL1 SYSREG_ESR(3, 0, 0, 4, 1)
951#define ESR_EL2_SYSREG_ID_AA64ZFR0_EL1 SYSREG_ESR(3, 0, 0, 4, 4)
Arunachalam Ganapathy83f46ca2023-08-15 18:13:27 +0100952#define ESR_EL2_SYSREG_ID_AA64SMFR0_EL1 SYSREG_ESR(3, 0, 0, 4, 5)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000953
954#define ESR_EL2_SYSREG_ID_AA64DFR0_EL1 SYSREG_ESR(3, 0, 0, 5, 0)
955#define ESR_EL2_SYSREG_ID_AA64DFR1_EL1 SYSREG_ESR(3, 0, 0, 5, 1)
956
957#define ESR_EL2_SYSREG_ID_AA64AFR0_EL1 SYSREG_ESR(3, 0, 0, 5, 4)
958#define ESR_EL2_SYSREG_ID_AA64AFR1_EL1 SYSREG_ESR(3, 0, 0, 5, 5)
959
960#define ESR_EL2_SYSREG_ID_AA64ISAR0_EL1 SYSREG_ESR(3, 0, 0, 6, 0)
961#define ESR_EL2_SYSREG_ID_AA64ISAR1_EL1 SYSREG_ESR(3, 0, 0, 6, 1)
962
963#define ESR_EL2_SYSREG_ID_AA64MMFR0_EL1 SYSREG_ESR(3, 0, 0, 7, 0)
964#define ESR_EL2_SYSREG_ID_AA64MMFR1_EL1 SYSREG_ESR(3, 0, 0, 7, 1)
965#define ESR_EL2_SYSREG_ID_AA64MMFR2_EL1 SYSREG_ESR(3, 0, 0, 7, 2)
966
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000967/* ID_AA64ISAR1_EL1 definitions */
968#define ID_AA64ISAR1_EL1_GPI_SHIFT UL(28)
969#define ID_AA64ISAR1_EL1_GPI_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000970
971#define ID_AA64ISAR1_EL1_GPA_SHIFT UL(24)
972#define ID_AA64ISAR1_EL1_GPA_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000973
974#define ID_AA64ISAR1_EL1_API_SHIFT UL(8)
975#define ID_AA64ISAR1_EL1_API_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000976
977#define ID_AA64ISAR1_EL1_APA_SHIFT UL(4)
978#define ID_AA64ISAR1_EL1_APA_WIDTH UL(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000979
980#define ESR_EL2_SYSREG_TIMERS_MASK SYSREG_ESR(3, 3, 15, 12, 0)
981#define ESR_EL2_SYSREG_TIMERS SYSREG_ESR(3, 3, 14, 0, 0)
982
983#define ESR_EL2_SYSREG_TIMER_CNTP_TVAL_EL0 SYSREG_ESR(3, 3, 14, 2, 0)
984#define ESR_EL2_SYSREG_TIMER_CNTP_CTL_EL0 SYSREG_ESR(3, 3, 14, 2, 1)
985#define ESR_EL2_SYSREG_TIMER_CNTP_CVAL_EL0 SYSREG_ESR(3, 3, 14, 2, 2)
986#define ESR_EL2_SYSREG_TIMER_CNTV_TVAL_EL0 SYSREG_ESR(3, 3, 14, 3, 0)
987#define ESR_EL2_SYSREG_TIMER_CNTV_CTL_EL0 SYSREG_ESR(3, 3, 14, 3, 1)
988#define ESR_EL2_SYSREG_TIMER_CNTV_CVAL_EL0 SYSREG_ESR(3, 3, 14, 3, 2)
989
990#define ESR_EL2_SYSREG_ICC_PMR_EL1 SYSREG_ESR(3, 0, 4, 6, 0)
991
992/*
993 * GIC system registers encoding mask for registers from
994 * ICC_IAR0_EL1(3, 0, 12, 8, 0) to ICC_IGRPEN1_EL1(3, 0, 12, 12, 7).
995 */
996#define ESR_EL2_SYSREG_ICC_EL1_MASK SYSREG_ESR(3, 3, 15, 8, 0)
997#define ESR_EL2_SYSREG_ICC_EL1 SYSREG_ESR(3, 0, 12, 8, 0)
998
999#define ESR_EL2_SYSREG_ICC_DIR SYSREG_ESR(3, 0, 12, 11, 1)
1000#define ESR_EL2_SYSREG_ICC_SGI1R_EL1 SYSREG_ESR(3, 0, 12, 11, 5)
1001#define ESR_EL2_SYSREG_ICC_SGI0R_EL1 SYSREG_ESR(3, 0, 12, 11, 7)
1002
Arunachalam Ganapathy591354a2023-11-16 10:49:09 +00001003/*
1004 * ESR mask for data cache clean/invalidate by set/way. This mask covers both
1005 * base DC and FEAT_MTE2 specific DC operations.
1006 */
1007#define ESR_EL2_SYSREG_DC_MASK SYSREG_ESR(3, 7, 15, 3, 1)
1008
1009/* Filter all DC sysreg access */
1010#define ESR_EL2_SYSREG_DC_SW SYSREG_ESR(1, 0, 7, 2, 0)
1011
1012/* Base DC instructions */
1013#define ESR_EL2_SYSREG_DC_ISW SYSREG_ESR(1, 0, 7, 6, 2)
1014#define ESR_EL2_SYSREG_DC_CSW SYSREG_ESR(1, 0, 7, 10, 2)
1015#define ESR_EL2_SYSREG_DC_CISW SYSREG_ESR(1, 0, 7, 14, 2)
1016
1017/* FEAT_MTE2 specific DC instructions */
1018#define ESR_EL2_SYSREG_DC_IGSW SYSREG_ESR(1, 0, 7, 6, 4)
1019#define ESR_EL2_SYSREG_DC_IGDSW SYSREG_ESR(1, 0, 7, 6, 6)
1020#define ESR_EL2_SYSREG_DC_CGSW SYSREG_ESR(1, 0, 7, 10, 4)
1021#define ESR_EL2_SYSREG_DC_CGDSW SYSREG_ESR(1, 0, 7, 10, 6)
1022#define ESR_EL2_SYSREG_DC_CIGSW SYSREG_ESR(1, 0, 7, 14, 4)
1023#define ESR_EL2_SYSREG_DC_CIGDSW SYSREG_ESR(1, 0, 7, 14, 6)
1024
Soby Mathewb4c6df42022-11-09 11:13:29 +00001025#define ESR_EL2_SYSREG_DIRECTION (UL(1) << 0)
AlexeiFedorov13b86dd2023-08-29 10:38:09 +01001026#define ESR_EL2_SYSREG_IS_WRITE(esr) (((esr) & ESR_EL2_SYSREG_DIRECTION) == 0UL)
Soby Mathewb4c6df42022-11-09 11:13:29 +00001027
AlexeiFedorov537bee02023-02-02 13:38:23 +00001028#define ESR_IL(esr) ((esr) & MASK(ESR_EL2_IL))
Soby Mathewb4c6df42022-11-09 11:13:29 +00001029
AlexeiFedorovfeaef162022-12-23 16:59:51 +00001030#define ESR_EL2_SYSREG_ISS_RT(esr) EXTRACT(ESR_EL2_SYSREG_TRAP_RT, esr)
Soby Mathewb4c6df42022-11-09 11:13:29 +00001031
AlexeiFedorov93f5ec52023-08-31 14:26:53 +01001032#define ICC_HPPIR1_EL1_INTID_SHIFT UL(0)
1033#define ICC_HPPIR1_EL1_INTID_WIDTH UL(24)
Soby Mathewb4c6df42022-11-09 11:13:29 +00001034
1035#define CNTHCTL_EL2_EL0PCTEN (UL(1) << UL(0))
1036#define CNTHCTL_EL2_EL0VCTEN (UL(1) << UL(1))
1037#define CNTHCTL_EL2_EL1PCTEN (UL(1) << 10)
1038#define CNTHCTL_EL2_EL1PTEN (UL(1) << 11)
1039#define CNTHCTL_EL2_EL1TVT (UL(1) << 13)
1040#define CNTHCTL_EL2_EL1TVCT (UL(1) << 14)
1041#define CNTHCTL_EL2_CNTVMASK (UL(1) << 18)
1042#define CNTHCTL_EL2_CNTPMASK (UL(1) << 19)
1043
1044#define CNTHCTL_EL2_INIT (CNTHCTL_EL2_EL0VCTEN | CNTHCTL_EL2_EL0PCTEN)
1045
1046#define CNTHCTL_EL2_NO_TRAPS (CNTHCTL_EL2_EL1PCTEN | \
1047 CNTHCTL_EL2_EL1PTEN)
1048
1049#define CNTx_CTL_ENABLE (UL(1) << 0)
1050#define CNTx_CTL_IMASK (UL(1) << 1)
1051#define CNTx_CTL_ISTATUS (UL(1) << 2)
1052
1053/*******************************************************************************
1054 * Definitions of register offsets, fields and macros for CPU system
1055 * instructions.
1056 ******************************************************************************/
1057
1058#define TLBI_ADDR_SHIFT U(12)
AlexeiFedorov1ba649f2023-10-19 13:56:02 +01001059#define TLBI_ADDR_MASK UL(0x0FFFFFFFFFFF)
Soby Mathewb4c6df42022-11-09 11:13:29 +00001060#define TLBI_ADDR(x) (((x) >> TLBI_ADDR_SHIFT) & TLBI_ADDR_MASK)
1061
1062/* ID_AA64MMFR2_EL1 definitions */
AlexeiFedorov537bee02023-02-02 13:38:23 +00001063#define ID_AA64MMFR2_EL1_ST_SHIFT UL(28)
1064#define ID_AA64MMFR2_EL1_ST_WIDTH UL(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +00001065
AlexeiFedorov537bee02023-02-02 13:38:23 +00001066#define ID_AA64MMFR2_EL1_CNP_SHIFT UL(0)
1067#define ID_AA64MMFR2_EL1_CNP_WIDTH UL(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +00001068
1069/* Custom defined values to indicate the vector offset to exception handlers */
1070#define ARM_EXCEPTION_SYNC_LEL 0
1071#define ARM_EXCEPTION_IRQ_LEL 1
1072#define ARM_EXCEPTION_FIQ_LEL 2
1073#define ARM_EXCEPTION_SERROR_LEL 3
1074
AlexeiFedorov537bee02023-02-02 13:38:23 +00001075#define VBAR_CEL_SP_EL0_OFFSET 0x0
1076#define VBAR_CEL_SP_ELx_OFFSET 0x200
1077#define VBAR_LEL_AA64_OFFSET 0x400
1078#define VBAR_LEL_AA32_OFFSET 0x600
Soby Mathewb4c6df42022-11-09 11:13:29 +00001079
AlexeiFedorov4c7d4852024-01-25 14:37:34 +00001080/* Stack Pointer selection */
1081#define MODE_SP_EL0 UL(0)
1082#define MODE_SP_ELX UL(1)
1083
Soby Mathewb4c6df42022-11-09 11:13:29 +00001084#endif /* ARCH_H */