blob: e36ffabc0a1c45d5d285e081119b4faf8bdcec94 [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
Soby Mathewb4c6df42022-11-09 11:13:29 +000021/* Interrupt Controller registers */
22#define ICC_HPPIR1_EL1 S3_0_C12_C12_2
23#define ICC_SRE_EL2 S3_4_C12_C9_5
24
25/* Interrupt Controller Control Register */
AlexeiFedorov537bee02023-02-02 13:38:23 +000026#define ICC_CTLR_EL1 S3_0_C12_C12_4
Soby Mathewb4c6df42022-11-09 11:13:29 +000027
AlexeiFedorov537bee02023-02-02 13:38:23 +000028#define ICC_CTLR_EL1_EXT_RANGE_BIT (UL(1) << 19)
Soby Mathewb4c6df42022-11-09 11:13:29 +000029
30/* Virtual GIC registers */
31#define ICH_AP0R0_EL2 S3_4_C12_C8_0
32#define ICH_AP0R1_EL2 S3_4_C12_C8_1
33#define ICH_AP0R2_EL2 S3_4_C12_C8_2
34#define ICH_AP0R3_EL2 S3_4_C12_C8_3
35#define ICH_AP1R0_EL2 S3_4_C12_C9_0
36#define ICH_AP1R1_EL2 S3_4_C12_C9_1
37#define ICH_AP1R2_EL2 S3_4_C12_C9_2
38#define ICH_AP1R3_EL2 S3_4_C12_C9_3
39
40#define ICH_LR0_EL2 S3_4_C12_C12_0
41#define ICH_LR1_EL2 S3_4_C12_C12_1
42#define ICH_LR2_EL2 S3_4_C12_C12_2
43#define ICH_LR3_EL2 S3_4_C12_C12_3
44#define ICH_LR4_EL2 S3_4_C12_C12_4
45#define ICH_LR5_EL2 S3_4_C12_C12_5
46#define ICH_LR6_EL2 S3_4_C12_C12_6
47#define ICH_LR7_EL2 S3_4_C12_C12_7
48#define ICH_LR8_EL2 S3_4_C12_C13_0
49#define ICH_LR9_EL2 S3_4_C12_C13_1
50#define ICH_LR10_EL2 S3_4_C12_C13_2
51#define ICH_LR11_EL2 S3_4_C12_C13_3
52#define ICH_LR12_EL2 S3_4_C12_C13_4
53#define ICH_LR13_EL2 S3_4_C12_C13_5
54#define ICH_LR14_EL2 S3_4_C12_C13_6
55#define ICH_LR15_EL2 S3_4_C12_C13_7
56
57#define ICH_HCR_EL2 S3_4_C12_C11_0
58#define ICH_VTR_EL2 S3_4_C12_C11_1
59#define ICH_MISR_EL2 S3_4_C12_C11_2
60#define ICH_VMCR_EL2 S3_4_C12_C11_7
61
62/* RNDR definition */
63#define RNDR S3_3_C2_C4_0
64
Shruti Gupta5732bfe2024-01-17 13:21:06 +000065/* Data Independent Timing Registers */
66#define DIT S3_3_C4_C2_5
67#define DIT_BIT (UL(1) << 24)
68
Javier Almansa Sobrinocfd32542024-10-09 19:38:56 +010069/* SCTLR2_EL12 register */
70#define SCTLR2_EL12 S3_5_C1_C0_3
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
Mate Toth-Pal9d595752024-12-10 13:22:47 +0100139#define TCR_EL2_A1 (UL(1) << 22)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000140#define TCR_EL2_AS (UL(1) << 36)
141#define TCR_EL2_HPD0 (UL(1) << 41)
142#define TCR_EL2_HPD1 (UL(1) << 42)
Mate Toth-Pal8f949242025-02-06 10:16:22 +0100143#define TCR_EL2_E0PD0 (UL(1) << 55)
144#define TCR_EL2_E0PD1 (UL(1) << 56)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000145
146#define TCR_TxSZ_MIN UL(16)
Javier Almansa Sobrino765a3162023-04-27 17:42:58 +0100147#define TCR_TxSZ_MIN_LPA2 UL(12)
Javier Almansa Sobrinoed932592023-01-24 12:50:41 +0000148#define TCR_TxSZ_MAX UL(48)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000149
150/* HCR definitions */
151#define HCR_FWB (UL(1) << 46)
152#define HCR_TEA (UL(1) << 37)
153#define HCR_API (UL(1) << 41)
154#define HCR_APK (UL(1) << 40)
155#define HCR_TERR (UL(1) << 36)
156#define HCR_TLOR (UL(1) << 35)
157#define HCR_E2H (UL(1) << 34)
158#define HCR_RW (UL(1) << 31)
AlexeiFedorov862f96c2024-03-01 16:26:48 +0000159#define HCR_TDZ (UL(1) << 28)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000160#define HCR_TGE (UL(1) << 27)
161#define HCR_TSW (UL(1) << 22)
162#define HCR_TACR (UL(1) << 21)
163#define HCR_TIDCP (UL(1) << 20)
164#define HCR_TSC (UL(1) << 19)
165#define HCR_TID3 (UL(1) << 18)
166#define HCR_TWE (UL(1) << 14)
167#define HCR_TWI (UL(1) << 13)
168#define HCR_VSE (UL(1) << 8)
169
170#define HCR_BSU_SHIFT 10
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100171#define HCR_BSU_WIDTH U(2)
172#define HCR_BSU_IS INPLACE(HCR_BSU, UL(1)) /* Barriers are promoted to IS */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000173
174#define HCR_FB (UL(1) << 9)
175#define HCR_VI (UL(1) << 7)
176#define HCR_AMO (UL(1) << 5)
177#define HCR_IMO (UL(1) << 4)
178#define HCR_FMO (UL(1) << 3)
179#define HCR_PTW (UL(1) << 2)
180#define HCR_SWIO (UL(1) << 1)
181#define HCR_VM (UL(1) << 0)
182
Arunachalam Ganapathy591354a2023-11-16 10:49:09 +0000183#define HCR_REALM_FLAGS (HCR_FWB | HCR_E2H | HCR_RW | HCR_TSC | \
Sona Mathewc744b932024-07-16 11:29:25 -0500184 HCR_AMO | HCR_BSU_IS | HCR_IMO | HCR_FMO | \
185 HCR_PTW | HCR_SWIO | HCR_VM | HCR_TID3 | \
186 HCR_TEA | HCR_API | HCR_APK)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000187
188#define HCR_EL2_INIT (HCR_TGE | HCR_E2H | HCR_TEA)
189
Javier Almansa Sobrinocfd32542024-10-09 19:38:56 +0100190/* HCRX_EL2 Register */
191#define HCRX_EL2 S3_4_C1_C2_2
192
193/* HCRX_EL2 definitions */
194#define HCRX_SCTLR2EN (UL(1) << 15)
195
196#define HCRX_INIT (UL(0))
197
Soby Mathewb4c6df42022-11-09 11:13:29 +0000198#define MAIR_ELx_ATTR0_SHIFT 0
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100199#define MAIR_ELx_ATTR0_WIDTH U(8)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000200
Sona Mathew21992e72025-02-03 00:37:22 -0600201/* BRBCR Register */
202#define BRBCR_EL1 S2_1_C9_C0_0
203#define BRBCR_EL2 S2_4_C9_C0_0
204
205#define BRBCR_INIT UL(0)
206
207/* HDFGRTR_EL2 Register */
208#define HDFGRTR_EL2 S3_4_C3_C1_4
209
210#define HDFGRTR_EL2_NBRBDATA_SHIFT 61
211#define HDFGRTR_EL2_NBRBDATA_WIDTH UL(1)
212#define HDFGRTR_EL2_NBRBCTL_SHIFT 60
213#define HDFGRTR_EL2_NBRBCTL_WIDTH UL(1)
214#define HDFGRTR_EL2_NBRBIDR_SHIFT 59
215#define HDFGRTR_EL2_NBRBIDR_WIDTH UL(1)
216
217#define HDFGRTR_EL2_INIT_CLEAR_MASK MASK(HDFGRTR_EL2_NBRBDATA) | \
218 MASK(HDFGRTR_EL2_NBRBCTL) | \
219 MASK(HDFGRTR_EL2_NBRBIDR)
220
Soby Mathewb4c6df42022-11-09 11:13:29 +0000221/*******************************************************************************
222 * Definitions of MAIR encodings for device and normal memory
223 ******************************************************************************/
224/*
225 * MAIR encodings for device memory attributes.
226 */
227#define MAIR_DEV_NGNRNE UL(0x0) /* Device nGnRnE */
228#define MAIR_DEV_NGNRNE_IDX 0x1
229
230#define MAIR_DEV_NGNRE UL(0x4)
231
232#define MAIR_NIOWBNTRW 0xff
233#define MAIR_NIOWBNTRW_IDX 0x0
234
235/*
236 * MAIR encodings for normal memory attributes.
237 *
238 * Cache Policy
239 * WT: Write Through
240 * WB: Write Back
241 * NC: Non-Cacheable
242 *
243 * Transient Hint
244 * NTR: Non-Transient
245 * TR: Transient
246 *
247 * Allocation Policy
248 * RA: Read Allocate
249 * WA: Write Allocate
250 * RWA: Read and Write Allocate
251 * NA: No Allocation
252 */
253#define MAIR_NORM_WT_TR_WA UL(0x1)
254#define MAIR_NORM_WT_TR_RA UL(0x2)
255#define MAIR_NORM_WT_TR_RWA UL(0x3)
256#define MAIR_NORM_NC UL(0x4)
257#define MAIR_NORM_WB_TR_WA UL(0x5)
258#define MAIR_NORM_WB_TR_RA UL(0x6)
259#define MAIR_NORM_WB_TR_RWA UL(0x7)
260#define MAIR_NORM_WT_NTR_NA UL(0x8)
261#define MAIR_NORM_WT_NTR_WA UL(0x9)
262#define MAIR_NORM_WT_NTR_RA UL(0xa)
263#define MAIR_NORM_WT_NTR_RWA UL(0xb)
264#define MAIR_NORM_WB_NTR_NA UL(0xc)
265#define MAIR_NORM_WB_NTR_WA UL(0xd)
266#define MAIR_NORM_WB_NTR_RA UL(0xe)
267#define MAIR_NORM_WB_NTR_RWA UL(0xf)
268
269#define MAIR_NORM_OUTER_SHIFT U(4)
270
271#define MAKE_MAIR_NORMAL_MEMORY(inner, outer) \
272 ((inner) | ((outer) << MAIR_NORM_OUTER_SHIFT))
273
274#define MAKE_MAIR_NORMAL_MEMORY_IO(_mair) \
275 MAKE_MAIR_NORMAL_MEMORY(_mair, _mair)
276
277/*
278 * TTBR Definitions
279 */
AlexeiFedorov537bee02023-02-02 13:38:23 +0000280#define TTBR_CNP_BIT UL(1)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000281
282#define TTBRx_EL2_CnP_SHIFT 0
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100283#define TTBRx_EL2_CnP_WIDTH U(1)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000284
285#define TTBRx_EL2_BADDR_SHIFT 1
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100286#define TTBRx_EL2_BADDR_WIDTH U(47)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000287
Javier Almansa Sobrinof6fff692024-02-02 17:13:57 +0000288#define TTBRx_EL2_BADDR_MSB_LPA2_SHIFT 2
289#define TTBRx_EL2_BADDR_MSB_LPA2_WIDTH U(4)
290#define EL2_BADDR_MSB_LPA2_SHIFT 48
291#define EL2_BADDR_MSB_LPA2_WIDTH TTBRx_EL2_BADDR_MSB_LPA2_WIDTH
292
Soby Mathewb4c6df42022-11-09 11:13:29 +0000293#define TTBRx_EL2_ASID_SHIFT 48
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100294#define TTBRx_EL2_ASID_WIDTH U(16)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000295
296/*
297 * VTTBR Definitions
298 */
299#define VTTBR_EL2_VMID_SHIFT 48
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100300#define VTTBR_EL2_VMID_WIDTH U(16)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000301
302/*
303 * ESR Definitions
304 */
305#define ESR_EL2_EC_SHIFT 26
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100306#define ESR_EL2_EC_WIDTH U(6)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000307
308#define ESR_EL2_IL_SHIFT 25
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100309#define ESR_EL2_IL_WIDTH U(1)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000310
311#define ESR_EL2_ISS_SHIFT 0
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100312#define ESR_EL2_ISS_WIDTH U(25)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000313
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100314#define ESR_EL2_EC_UNKNOWN INPLACE(ESR_EL2_EC, UL(0))
315#define ESR_EL2_EC_WFX INPLACE(ESR_EL2_EC, UL(1))
316#define ESR_EL2_EC_FPU INPLACE(ESR_EL2_EC, UL(7))
317#define ESR_EL2_EC_SVC INPLACE(ESR_EL2_EC, UL(21))
318#define ESR_EL2_EC_HVC INPLACE(ESR_EL2_EC, UL(22))
319#define ESR_EL2_EC_SMC INPLACE(ESR_EL2_EC, UL(23))
320#define ESR_EL2_EC_SYSREG INPLACE(ESR_EL2_EC, UL(24))
321#define ESR_EL2_EC_SVE INPLACE(ESR_EL2_EC, UL(25))
Arunachalam Ganapathy83f46ca2023-08-15 18:13:27 +0100322#define ESR_EL2_EC_SME INPLACE(ESR_EL2_EC, UL(29))
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100323#define ESR_EL2_EC_INST_ABORT INPLACE(ESR_EL2_EC, UL(32))
324#define ESR_EL2_EC_INST_ABORT_SEL INPLACE(ESR_EL2_EC, UL(33))
325#define ESR_EL2_EC_DATA_ABORT INPLACE(ESR_EL2_EC, UL(36))
326#define ESR_EL2_EC_DATA_ABORT_SEL INPLACE(ESR_EL2_EC, UL(37))
327#define ESR_EL2_EC_SERROR INPLACE(ESR_EL2_EC, UL(47))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000328
329/* Data/Instruction Abort ESR fields */
AlexeiFedorov537bee02023-02-02 13:38:23 +0000330#define ESR_EL2_ABORT_ISV_BIT (UL(1) << 24)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000331
332#define ESR_EL2_ABORT_SAS_SHIFT 22
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100333#define ESR_EL2_ABORT_SAS_WIDTH U(2)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000334
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100335#define ESR_EL2_ABORT_SAS_BYTE_VAL 0U
336#define ESR_EL2_ABORT_SAS_HWORD_VAL 1U
337#define ESR_EL2_ABORT_SAS_WORD_VAL 2U
338#define ESR_EL2_ABORT_SAS_DWORD_VAL 3U
Soby Mathewb4c6df42022-11-09 11:13:29 +0000339
AlexeiFedorov537bee02023-02-02 13:38:23 +0000340#define ESR_EL2_ABORT_SSE_BIT (UL(1) << 21)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000341
342#define ESR_EL2_ABORT_SRT_SHIFT 16
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100343#define ESR_EL2_ABORT_SRT_WIDTH U(5)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000344
345#define ESR_EL2_ABORT_SET_SHIFT 11
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100346#define ESR_EL2_ABORT_SET_WIDTH U(2)
347#define ESR_EL2_ABORT_SET_UER INPLACE(ESR_EL2_ABORT_SET, UL(0))
348#define ESR_EL2_ABORT_SET_UC INPLACE(ESR_EL2_ABORT_SET, UL(2))
349#define ESR_EL2_ABORT_SET_UEO INPLACE(ESR_EL2_ABORT_SET, UL(3))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000350
AlexeiFedorov537bee02023-02-02 13:38:23 +0000351#define ESR_EL2_ABORT_SF_BIT (UL(1) << 15)
352#define ESR_EL2_ABORT_FNV_BIT (UL(1) << 10)
353#define ESR_EL2_ABORT_EA_BIT (UL(1) << 9)
354#define ESR_EL2_ABORT_S1PTW_BIT (UL(1) << 7)
355#define ESR_EL2_ABORT_WNR_BIT (UL(1) << 6)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000356#define ESR_EL2_ABORT_FSC_SHIFT 0
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100357#define ESR_EL2_ABORT_FSC_WIDTH U(6)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000358
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100359#define ESR_EL2_ABORT_FSC_TRANSLATION_FAULT UL(0x04)
360#define ESR_EL2_ABORT_FSC_PERMISSION_FAULT UL(0x0c)
361#define ESR_EL2_ABORT_FSC_TRANSLATION_FAULT_L0 UL(0x04)
362#define ESR_EL2_ABORT_FSC_SEA UL(0x10)
363#define ESR_EL2_ABORT_FSC_SEA_TTW_START UL(0x13)
364#define ESR_EL2_ABORT_FSC_SEA_TTW_END UL(0x17)
365#define ESR_EL2_ABORT_FSC_GPF UL(0x28)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000366#define ESR_EL2_ABORT_FSC_LEVEL_SHIFT 0
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100367#define ESR_EL2_ABORT_FSC_LEVEL_WIDTH U(2)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000368
369/* The ESR fields that are reported to the host on Instr./Data Synchronous Abort */
AlexeiFedorov537bee02023-02-02 13:38:23 +0000370#define ESR_NONEMULATED_ABORT_MASK ( \
371 MASK(ESR_EL2_EC) | \
372 MASK(ESR_EL2_ABORT_SET) | \
373 ESR_EL2_ABORT_FNV_BIT | \
374 ESR_EL2_ABORT_EA_BIT | \
375 MASK(ESR_EL2_ABORT_FSC))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000376
AlexeiFedorov537bee02023-02-02 13:38:23 +0000377#define ESR_EMULATED_ABORT_MASK ( \
Soby Mathewb4c6df42022-11-09 11:13:29 +0000378 ESR_NONEMULATED_ABORT_MASK | \
AlexeiFedorov537bee02023-02-02 13:38:23 +0000379 ESR_EL2_ABORT_ISV_BIT | \
380 MASK(ESR_EL2_ABORT_SAS) | \
381 ESR_EL2_ABORT_SF_BIT | \
Soby Mathewb4c6df42022-11-09 11:13:29 +0000382 ESR_EL2_ABORT_WNR_BIT)
383
384#define ESR_EL2_SERROR_DFSC_SHIFT 0
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100385#define ESR_EL2_SERROR_DFSC_WIDTH U(6)
386#define ESR_EL2_SERROR_DFSC_UNCAT INPLACE(ESR_EL2_SERROR_DFSC, UL(0))
Raghu Krishnamurthy79530bd2025-01-17 16:04:33 -0800387#define ESR_EL2_SERROR_DFSC_ASYNC INPLACE(ESR_EL2_SERROR_DFSC, UL(0x11))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000388
AlexeiFedorov537bee02023-02-02 13:38:23 +0000389#define ESR_EL2_SERROR_EA_BIT (UL(1) << 9)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000390
391#define ESR_EL2_SERROR_AET_SHIFT 10
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100392#define ESR_EL2_SERROR_AET_WIDTH U(3)
393#define ESR_EL2_SERROR_AET_UC INPLACE(ESR_EL2_SERROR_AET, UL(0))
394#define ESR_EL2_SERROR_AET_UEU INPLACE(ESR_EL2_SERROR_AET, UL(1))
395#define ESR_EL2_SERROR_AET_UEO INPLACE(ESR_EL2_SERROR_AET, UL(2))
396#define ESR_EL2_SERROR_AET_UER INPLACE(ESR_EL2_SERROR_AET, UL(3))
397#define ESR_EL2_SERROR_AET_CE INPLACE(ESR_EL2_SERROR_AET, UL(6))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000398
AlexeiFedorov537bee02023-02-02 13:38:23 +0000399#define ESR_EL2_SERROR_IESB_BIT (UL(1) << 13)
400#define ESR_EL2_SERROR_IDS_BIT (UL(1) << 24)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000401
402/* The ESR fields that are reported to the host on SError */
AlexeiFedorov537bee02023-02-02 13:38:23 +0000403#define ESR_SERROR_MASK ( \
404 ESR_EL2_SERROR_IDS_BIT | \
405 MASK(ESR_EL2_SERROR_AET) | \
406 ESR_EL2_SERROR_EA_BIT | \
407 MASK(ESR_EL2_SERROR_DFSC))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000408
409#define ESR_EL2_SYSREG_TRAP_OP0_SHIFT 20
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100410#define ESR_EL2_SYSREG_TRAP_OP0_WIDTH U(2)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000411
412#define ESR_EL2_SYSREG_TRAP_OP2_SHIFT 17
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100413#define ESR_EL2_SYSREG_TRAP_OP2_WIDTH U(3)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000414
415#define ESR_EL2_SYSREG_TRAP_OP1_SHIFT 14
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100416#define ESR_EL2_SYSREG_TRAP_OP1_WIDTH U(3)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000417
418#define ESR_EL2_SYSREG_TRAP_CRN_SHIFT 10
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100419#define ESR_EL2_SYSREG_TRAP_CRN_WIDTH U(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000420
421#define ESR_EL2_SYSREG_TRAP_RT_SHIFT 5
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100422#define ESR_EL2_SYSREG_TRAP_RT_WIDTH U(5)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000423
424#define ESR_EL2_SYSREG_TRAP_CRM_SHIFT 1
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100425#define ESR_EL2_SYSREG_TRAP_CRM_WIDTH U(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000426
427/* WFx ESR fields */
AlexeiFedorov537bee02023-02-02 13:38:23 +0000428#define ESR_EL2_WFx_TI_BIT (UL(1) << 0)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000429
430/* xVC ESR fields */
431#define ESR_EL2_xVC_IMM_SHIFT 0
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100432#define ESR_EL2_xVC_IMM_WIDTH U(16)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000433
Javier Almansa Sobrinoe2d133c2025-01-16 18:18:08 +0000434/* MPAM2_EL2 definitions */
435#define MPAM2_EL2_TIDR_BIT (UL(1) << 58)
436#define MPAM2_EL2_TRAPMPAM0EL1_BIT (UL(1) << 49)
437#define MPAM2_EL2_TRAPMPAM1EL1_BIT (UL(1) << 48)
438
439#define MPAM2_EL2_INIT (MPAM2_EL2_TRAPMPAM0EL1_BIT | \
440 MPAM2_EL2_TRAPMPAM1EL1_BIT | \
441 MPAM2_EL2_TIDR_BIT)
442
443/* MPAMHCR_EL2 definitions */
444#define MPAMHCR_EL2_TRAP_MPAMIDR_EL1_BIT (UL(1) << 31)
445
446#define MPAMHCR_EL2_INIT (MPAMHCR_EL2_TRAP_MPAMIDR_EL1_BIT)
447
448/* MPAMIDR_EL1 definitions */
449#define MPAMIDR_EL1_HAS_TIDR_BIT (UL(1) << 58)
450#define MPAMIDR_EL1_HAS_HCR_BIT (UL(1) << 17)
451
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000452/* ID_AA64DFR0_EL1 definitions */
453#define ID_AA64DFR0_EL1_HPMN0_SHIFT UL(60)
454#define ID_AA64DFR0_EL1_HPMN0_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000455
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000456#define ID_AA64DFR0_EL1_ExtTrcBuff_SHIFT UL(56)
457#define ID_AA64DFR0_EL1_ExtTrcBuff_WIDTH UL(4)
458
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000459#define ID_AA64DFR0_EL1_BRBE_SHIFT UL(52)
460#define ID_AA64DFR0_EL1_BRBE_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000461
462#define ID_AA64DFR0_EL1_MTPMU_SHIFT UL(48)
463#define ID_AA64DFR0_EL1_MTPMU_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000464
465#define ID_AA64DFR0_EL1_TraceBuffer_SHIFT UL(44)
466#define ID_AA64DFR0_EL1_TraceBuffer_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000467
468#define ID_AA64DFR0_EL1_TraceFilt_SHIFT UL(40)
469#define ID_AA64DFR0_EL1_TraceFilt_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000470
471#define ID_AA64DFR0_EL1_DoubleLock_SHIFT UL(36)
472#define ID_AA64DFR0_EL1_DoubleLock_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000473
474#define ID_AA64DFR0_EL1_PMSVer_SHIFT UL(32)
475#define ID_AA64DFR0_EL1_PMSVer_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000476
477#define ID_AA64DFR0_EL1_CTX_CMPS_SHIFT UL(28)
478#define ID_AA64DFR0_EL1_CTX_CMPS_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000479
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000480#define ID_AA64DFR0_EL1_SEBEP_SHIFT UL(24)
481#define ID_AA64DFR0_EL1_SEBEP_WIDTH UL(4)
482
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000483#define ID_AA64DFR0_EL1_WRPs_SHIFT UL(20)
484#define ID_AA64DFR0_EL1_WRPs_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000485
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000486#define ID_AA64DFR0_EL1_PMSS_SHIFT UL(16)
487#define ID_AA64DFR0_EL1_PMSS_WIDTH UL(4)
488
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000489#define ID_AA64DFR0_EL1_BRPs_SHIFT UL(12)
490#define ID_AA64DFR0_EL1_BRPs_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000491
492#define ID_AA64DFR0_EL1_PMUVer_SHIFT UL(8)
493#define ID_AA64DFR0_EL1_PMUVer_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000494
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000495/* Performance Monitors Extension version */
496#define ID_AA64DFR0_EL1_PMUv3p7 UL(7)
497#define ID_AA64DFR0_EL1_PMUv3p8 UL(8)
498#define ID_AA64DFR0_EL1_PMUv3p9 UL(9)
499
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000500#define ID_AA64DFR0_EL1_TraceVer_SHIFT UL(4)
501#define ID_AA64DFR0_EL1_TraceVer_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000502
503#define ID_AA64DFR0_EL1_DebugVer_SHIFT UL(0)
504#define ID_AA64DFR0_EL1_DebugVer_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000505
506/* Debug architecture version */
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000507#define ID_AA64DFR0_EL1_Debugv8 UL(6)
AlexeiFedorova2ef91d2024-08-08 13:49:20 +0100508#define ID_AA64DFR0_EL1_Debugv8p1 UL(7)
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000509#define ID_AA64DFR0_EL1_Debugv8p2 UL(8)
510#define ID_AA64DFR0_EL1_Debugv8p4 UL(9)
511#define ID_AA64DFR0_EL1_Debugv8p8 UL(10)
AlexeiFedorova2ef91d2024-08-08 13:49:20 +0100512#define ID_AA64DFR0_EL1_Debugv8p9 UL(11)
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000513
514/* ID_AA64DFR1_EL1 definitions */
515#define ID_AA64DFR1_EL1_EBEP_SHIFT UL(48)
516#define ID_AA64DFR1_EL1_EBEP_WIDTH UL(4)
517
518#define ID_AA64DFR1_EL1_ICNTR_SHIFT UL(36)
519#define ID_AA64DFR1_EL1_ICNTR_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000520
AlexeiFedorova2ef91d2024-08-08 13:49:20 +0100521#define ID_AA64DFR1_EL1_WRPs_SHIFT UL(16)
522#define ID_AA64DFR1_EL1_WRPs_WIDTH UL(8)
523
524#define ID_AA64DFR1_EL1_BRPs_SHIFT UL(8)
525#define ID_AA64DFR1_EL1_BRPs_WIDTH UL(8)
526
Soby Mathewb4c6df42022-11-09 11:13:29 +0000527/* ID_AA64PFR0_EL1 definitions */
528#define ID_AA64PFR0_EL1_SVE_SHIFT UL(32)
529#define ID_AA64PFR0_EL1_SVE_WIDTH UL(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000530
Javier Almansa Sobrino7b087442025-01-16 18:18:08 +0000531#define ID_AA64PFR0_EL1_MPAM_SHIFT UL(40)
532#define ID_AA64PFR0_EL1_MPAM_WIDTH UL(4)
533
Soby Mathewb4c6df42022-11-09 11:13:29 +0000534#define ID_AA64PFR0_EL1_AMU_SHIFT UL(44)
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100535#define ID_AA64PFR0_EL1_AMU_WIDTH UL(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000536
Arunachalam Ganapathya27de372023-03-06 11:13:49 +0000537/* ID_AA64PFR1_EL1 definitions */
Javier Almansa Sobrino34005b92024-10-11 17:53:41 +0100538#define ID_AA64PFR1_EL1_SSBS_SHIFT UL(4)
539#define ID_AA64PFR1_EL1_SSBS_WIDTH UL(4)
540#define ID_AA64PFR1_EL1_SSBS_NOT_IMPLEMENTED UL(0)
541#define ID_AA64PFR1_EL1_FEAT_SSBS UL(1)
542#define ID_AA64PFR1_EL1_FEAT_SSBS2 UL(2)
543
544#define ID_AA64PFR1_EL1_MTE_SHIFT UL(8)
545#define ID_AA64PFR1_EL1_MTE_WIDTH UL(4)
546#define ID_AA64PFR1_EL1_MTE_NOT_IMPLEMENTED UL(0)
547#define ID_AA64PFR1_EL1_MTE1 UL(1)
548#define ID_AA64PFR1_EL1_MTE2 UL(2)
549#define ID_AA64PFR1_EL1_MTE3 UL(3)
Arunachalam Ganapathya27de372023-03-06 11:13:49 +0000550
Javier Almansa Sobrino7b087442025-01-16 18:18:08 +0000551#define ID_AA64PFR1_EL1_MPAM_F_SHIFT UL(16)
552#define ID_AA64PFR1_EL1_MPAM_F_WIDTH UL(4)
553
Arunachalam Ganapathy83f46ca2023-08-15 18:13:27 +0100554#define ID_AA64PFR1_EL1_SME_SHIFT UL(24)
555#define ID_AA64PFR1_EL1_SME_WIDTH UL(4)
556#define ID_AA64PFR1_EL1_SME_NOT_IMPLEMENTED UL(0)
557#define ID_AA64PFR1_EL1_SME_IMPLEMENTED UL(1)
558#define ID_AA64PFR1_EL1_SME2_IMPLEMENTED UL(2)
559
Javier Almansa Sobrino34005b92024-10-11 17:53:41 +0100560#define ID_AA64PFR1_EL1_NMI_SHIFT UL(36)
561#define ID_AA64PFR1_EL1_NMI_WIDTH UL(4)
562
563#define ID_AA64PFR1_EL1_GCS_SHIFT UL(44)
564#define ID_AA64PFR1_EL1_GCS_WIDTH UL(4)
565
Javier Almansa Sobrinocfd32542024-10-09 19:38:56 +0100566#define ID_AA64PFR1_EL1_DF2_SHIFT UL(56)
567#define ID_AA64PFR1_EL1_DF2_WIDTH UL(4)
568
Soby Mathewb4c6df42022-11-09 11:13:29 +0000569/* ID_AA64MMFR0_EL1 definitions */
570#define ID_AA64MMFR0_EL1_PARANGE_SHIFT U(0)
AlexeiFedorov537bee02023-02-02 13:38:23 +0000571#define ID_AA64MMFR0_EL1_PARANGE_WIDTH UL(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000572
Soby Mathew1eccd462024-10-21 13:36:34 +0100573/* Defines for PA width corresponding to PARange [0:3] in id_aa64mmfr0_el1 */
574#define PARANGE_WIDTH_32BITS U(32) /* PARange - 0x0 */
575#define PARANGE_WIDTH_36BITS U(36) /* PARange - 0x1 */
576#define PARANGE_WIDTH_40BITS U(40) /* PARange - 0x2 */
577#define PARANGE_WIDTH_42BITS U(42) /* PARange - 0x3 */
578#define PARANGE_WIDTH_44BITS U(44) /* PARange - 0x4 */
579#define PARANGE_WIDTH_48BITS U(48) /* PARange - 0x5 */
580#define PARANGE_WIDTH_52BITS U(52) /* PARange - 0x6 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000581
AlexeiFedorov537bee02023-02-02 13:38:23 +0000582#define ID_AA64MMFR0_EL1_ECV_SHIFT UL(60)
583#define ID_AA64MMFR0_EL1_ECV_WIDTH UL(4)
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000584#define ID_AA64MMFR0_EL1_ECV_NOT_SUPPORTED UL(0x0)
585#define ID_AA64MMFR0_EL1_ECV_SUPPORTED UL(0x1)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000586#define ID_AA64MMFR0_EL1_ECV_SELF_SYNCH ULL(0x2)
587
AlexeiFedorov537bee02023-02-02 13:38:23 +0000588#define ID_AA64MMFR0_EL1_FGT_SHIFT UL(56)
589#define ID_AA64MMFR0_EL1_FGT_WIDTH UL(4)
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000590#define ID_AA64MMFR0_EL1_FGT_NOT_SUPPORTED UL(0x0)
591#define ID_AA64MMFR0_EL1_FGT_SUPPORTED UL(0x1)
592#define ID_AA64MMFR0_EL1_FGT2_SUPPORTED UL(0x2)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000593
594#define ID_AA64MMFR0_EL1_TGRAN4_2_SHIFT U(40)
AlexeiFedorov537bee02023-02-02 13:38:23 +0000595#define ID_AA64MMFR0_EL1_TGRAN4_2_WIDTH U(4)
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000596#define ID_AA64MMFR0_EL1_TGRAN4_2_TGRAN4 UL(0x0)
597#define ID_AA64MMFR0_EL1_TGRAN4_2_NOT_SUPPORTED UL(0x1)
598#define ID_AA64MMFR0_EL1_TGRAN4_2_SUPPORTED UL(0x2)
599#define ID_AA64MMFR0_EL1_TGRAN4_2_LPA2 UL(0x3)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000600
AlexeiFedorov537bee02023-02-02 13:38:23 +0000601#define ID_AA64MMFR0_EL1_TGRAN16_2_SHIFT UL(32)
602#define ID_AA64MMFR0_EL1_TGRAN16_2_WIDTH UL(4)
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000603#define ID_AA64MMFR0_EL1_TGRAN16_2_TGRAN16 UL(0x0)
604#define ID_AA64MMFR0_EL1_TGRAN16_2_NOT_SUPPORTED UL(0x1)
605#define ID_AA64MMFR0_EL1_TGRAN16_2_SUPPORTED UL(0x2)
606#define ID_AA64MMFR0_EL1_TGRAN16_2_LPA2 UL(0x3)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000607
AlexeiFedorov537bee02023-02-02 13:38:23 +0000608#define ID_AA64MMFR0_EL1_TGRAN4_SHIFT UL(28)
609#define ID_AA64MMFR0_EL1_TGRAN4_WIDTH UL(4)
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000610#define ID_AA64MMFR0_EL1_TGRAN4_SUPPORTED UL(0x0)
611#define ID_AA64MMFR0_EL1_TGRAN4_LPA2 UL(0x1)
612#define ID_AA64MMFR0_EL1_TGRAN4_NOT_SUPPORTED UL(0xf)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000613
614#define ID_AA64MMFR0_EL1_TGRAN64_SHIFT UL(24)
AlexeiFedorov537bee02023-02-02 13:38:23 +0000615#define ID_AA64MMFR0_EL1_TGRAN64_WIDTH UL(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000616#define ID_AA64MMFR0_EL1_TGRAN64_SUPPORTED UL(0x0)
617#define ID_AA64MMFR0_EL1_TGRAN64_NOT_SUPPORTED UL(0xf)
618
619#define ID_AA64MMFR0_EL1_TGRAN16_SHIFT UL(20)
AlexeiFedorov537bee02023-02-02 13:38:23 +0000620#define ID_AA64MMFR0_EL1_TGRAN16_WIDTH UL(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000621#define ID_AA64MMFR0_EL1_TGRAN16_NOT_SUPPORTED UL(0x0)
622#define ID_AA64MMFR0_EL1_TGRAN16_SUPPORTED UL(0x1)
623#define ID_AA64MMFR0_EL1_TGRAN16_LPA2 UL(0x2)
624
625/* RNDR definitions */
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000626#define ID_AA64ISAR0_EL1_RNDR_SHIFT UL(60)
627#define ID_AA64ISAR0_EL1_RNDR_WIDTH UL(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000628
629/* ID_AA64MMFR1_EL1 definitions */
630#define ID_AA64MMFR1_EL1_VMIDBits_SHIFT UL(4)
AlexeiFedorov537bee02023-02-02 13:38:23 +0000631#define ID_AA64MMFR1_EL1_VMIDBits_WIDTH UL(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000632#define ID_AA64MMFR1_EL1_VMIDBits_8 UL(0)
633#define ID_AA64MMFR1_EL1_VMIDBits_16 UL(2)
634
Arunachalam Ganapathyf6491212023-02-23 16:04:34 +0000635/* SVE Feature ID register 0 */
636#define ID_AA64ZFR0_EL1 S3_0_C0_C4_4
637
Arunachalam Ganapathy83f46ca2023-08-15 18:13:27 +0100638/* SME Feature ID register 0 */
639#define ID_AA64SMFR0_EL1 S3_0_C0_C4_5
640
AlexeiFedorovbe9209c2024-02-27 15:16:00 +0000641/* PAR_EL1 definitions */
642#define PAR_EL1_F_BIT (UL(1) << 0)
643
Soby Mathewb4c6df42022-11-09 11:13:29 +0000644/* HPFAR_EL2 definitions */
645#define HPFAR_EL2_FIPA_SHIFT 4
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100646#define HPFAR_EL2_FIPA_WIDTH U(40)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000647#define HPFAR_EL2_FIPA_OFFSET 8
648
649/* SPSR definitions */
650#define SPSR_EL2_MODE_SHIFT 0
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100651#define SPSR_EL2_MODE_WIDTH U(4)
652#define SPSR_EL2_MODE_EL0t INPLACE(SPSR_EL2_MODE, UL(0))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000653
654#define SPSR_EL2_MODE_SHIFT 0
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100655#define SPSR_EL2_MODE_WIDTH U(4)
656#define SPSR_EL2_MODE_EL1h INPLACE(SPSR_EL2_MODE, UL(5))
657#define SPSR_EL2_MODE_EL1t INPLACE(SPSR_EL2_MODE, UL(4))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000658
659/* FIXME: DAIF definitions are redundant here. Might need unification. */
660#define SPSR_EL2_nRW_SHIFT 4
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100661#define SPSR_EL2_nRW_WIDTH U(1)
662#define SPSR_EL2_nRW_AARCH64 INPLACE(SPSR_EL2_nRW, UL(0))
663#define SPSR_EL2_nRW_AARCH32 INPLACE(SPSR_EL2_nRW, UL(1))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000664
AlexeiFedorov537bee02023-02-02 13:38:23 +0000665#define SPSR_EL2_DAIF_SHIFT 6
Javier Almansa Sobrino34005b92024-10-11 17:53:41 +0100666#define SPSR_EL2_DAIF_WIDTH U(4)
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100667#define SPSR_EL2_AIF_SHIFT U(6)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000668
Javier Almansa Sobrino34005b92024-10-11 17:53:41 +0100669#define SPSR_EL2_BTYPE_SHIFT U(10)
670#define SPSR_EL2_BTYPE_WIDTH U(2)
671
672#define SPSR_EL2_NZCV_BITS_SHIFT U(28)
673#define SPSR_EL2_NZCV_BITS_WIDTH U(4)
674
AlexeiFedorov537bee02023-02-02 13:38:23 +0000675#define DAIF_FIQ_BIT (UL(1) << 0)
676#define DAIF_IRQ_BIT (UL(1) << 1)
677#define DAIF_ABT_BIT (UL(1) << 2)
678#define DAIF_DBG_BIT (UL(1) << 3)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000679
AlexeiFedorov537bee02023-02-02 13:38:23 +0000680#define SPSR_EL2_F_BIT (UL(1) << 6)
681#define SPSR_EL2_I_BIT (UL(1) << 7)
682#define SPSR_EL2_A_BIT (UL(1) << 8)
683#define SPSR_EL2_D_BIT (UL(1) << 9)
684#define SPSR_EL2_SSBS_BIT (UL(1) << 12)
685#define SPSR_EL2_ALLINT_BIT (UL(1) << 13)
686#define SPSR_EL2_IL_BIT (UL(1) << 20)
687#define SPSR_EL2_SS_BIT (UL(1) << 21)
688#define SPSR_EL2_PAN_BIT (UL(1) << 22)
689#define SPSR_EL2_UAO_BIT (UL(1) << 23)
690#define SPSR_EL2_DIT_BIT (UL(1) << 24)
691#define SPSR_EL2_TCO_BIT (UL(1) << 25)
692#define SPSR_EL2_V_BIT (UL(1) << 28)
693#define SPSR_EL2_C_BIT (UL(1) << 29)
694#define SPSR_EL2_Z_BIT (UL(1) << 30)
695#define SPSR_EL2_N_BIT (UL(1) << 31)
696#define SPSR_EL2_PM_BIT (UL(1) << 32)
697#define SPSR_EL2_PPEND_BIT (UL(1) << 33)
Javier Almansa Sobrino34005b92024-10-11 17:53:41 +0100698#define SPSR_EL2_EXLOCK_BIT (UL(1) << 34)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000699
Arunachalam Ganapathy4f601e72023-05-22 11:49:29 +0100700/* Floating point control and status register */
701#define FPCR S3_3_C4_C4_0
702#define FPSR S3_3_C4_C4_1
703
Arunachalam Ganapathyf6491212023-02-23 16:04:34 +0000704/* SVE Control Register */
705#define ZCR_EL2 S3_4_C1_C2_0
Arunachalam Ganapathy2b456582023-05-19 11:56:44 +0100706#define ZCR_EL2_LEN_SHIFT UL(0)
707#define ZCR_EL2_LEN_WIDTH UL(4)
Arunachalam Ganapathyf6491212023-02-23 16:04:34 +0000708
Arunachalam Ganapathy4f601e72023-05-22 11:49:29 +0100709#define ZCR_EL12 S3_5_C1_C2_0
710
Arunachalam Ganapathy83f46ca2023-08-15 18:13:27 +0100711/* SME Control Register */
712#define SMCR_EL2 S3_4_C1_C2_6
713#define SMCR_EL2_LEN_SHIFT UL(0)
714#define SMCR_EL2_LEN_WIDTH UL(4)
715/*
716 * SMCR_EL2_RAZ_LEN is defined to find the architecturally permitted SVL. This
717 * is a combination of RAZ and LEN bit fields.
718 */
719#define SMCR_EL2_RAZ_LEN_SHIFT UL(0)
720#define SMCR_EL2_RAZ_LEN_WIDTH UL(9)
721#define SMCR_EL2_EZT0_BIT (UL(1) << 30)
722#define SMCR_EL2_FA64_BIT (UL(1) << 31)
723
724/* Streaming Vector Control register */
725#define SVCR S3_3_C4_C2_2
726#define SVCR_SM_BIT (UL(1) << 0)
727#define SVCR_ZA_BIT (UL(1) << 1)
728
Soby Mathewb4c6df42022-11-09 11:13:29 +0000729/* VTCR definitions */
730#define VTCR_T0SZ_SHIFT 0
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100731#define VTCR_T0SZ_WIDTH U(6)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000732
733#define VTCR_SL0_SHIFT 6
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100734#define VTCR_SL0_WIDTH U(2)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000735
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100736#define VTCR_SL0_4K_L2 INPLACE(VTCR_SL0, UL(0))
737#define VTCR_SL0_4K_L1 INPLACE(VTCR_SL0, UL(1))
738#define VTCR_SL0_4K_L0 INPLACE(VTCR_SL0, UL(2))
739#define VTCR_SL0_4K_L3 INPLACE(VTCR_SL0, UL(3))
Javier Almansa Sobrinof6fff692024-02-02 17:13:57 +0000740#define VTCR_SL0_4K_LM1 VTCR_SL0_4K_L2
741
742#define VTCR_SL2_SHIFT 33
743#define VTCR_SL2_WIDTH U(1)
744#define VCTR_SL2_4K_LM1 INPLACE(VTCR_SL2, UL(1))
745
746#define VTCR_DS_SHIFT 32
747#define VTCR_DS_WIDTH U(1)
748#define VTCR_DS_52BIT INPLACE(VTCR_DS, UL(1))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000749
750#define VTCR_IRGN0_SHIFT 8
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100751#define VTCR_IRGN0_WIDTH U(2)
752#define VTCR_IRGN0_WBRAWA INPLACE(VTCR_IRGN0, UL(1))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000753
754#define VTCR_ORGN0_SHIFT 10
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100755#define VTCR_ORGN0_WIDTH U(2)
756#define VTCR_ORGN0_WBRAWA INPLACE(VTCR_ORGN0, UL(1))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000757
758#define VTCR_SH0_SHIFT 12
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100759#define VTCR_SH0_WIDTH U(2)
760#define VTCR_SH0_IS INPLACE(VTCR_SH0, UL(3))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000761
762#define VTCR_TG0_SHIFT 14
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100763#define VTCR_TG0_WIDTH U(2)
764#define VTCR_TG0_4K INPLACE(VTCR_TG0, UL(0))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000765
766#define VTCR_PS_SHIFT 16
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100767#define VTCR_PS_WIDTH U(3)
Mathieu Poirier6752efa2024-09-24 11:53:59 -0600768#define VTCR_PS_32 INPLACE(VTCR_PS, UL(0))
769#define VTCR_PS_36 INPLACE(VTCR_PS, UL(1))
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100770#define VTCR_PS_40 INPLACE(VTCR_PS, UL(2))
Mathieu Poirier6752efa2024-09-24 11:53:59 -0600771#define VTCR_PS_42 INPLACE(VTCR_PS, UL(3))
772#define VTCR_PS_44 INPLACE(VTCR_PS, UL(4))
773#define VTCR_PS_48 INPLACE(VTCR_PS, UL(5))
774#define VTCR_PS_52 INPLACE(VTCR_PS, UL(6))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000775
776#define VTCR_VS (UL(1) << 19)
777#define VTCR_NSA (UL(1) << 30)
778#define VTCR_RES1 (UL(1) << 31)
779
780#define VTCR_FLAGS ( \
781 VTCR_IRGN0_WBRAWA | /* PTW inner cache attr. is WB RAWA*/ \
782 VTCR_ORGN0_WBRAWA | /* PTW outer cache attr. is WB RAWA*/ \
783 VTCR_SH0_IS | /* PTW shareability attr. is Outer Sharable*/\
784 VTCR_TG0_4K | /* 4K granule size in non-secure PT*/ \
Soby Mathewb4c6df42022-11-09 11:13:29 +0000785 /* VS = 0 size(VMID) = 8 */ \
786 /* NSW = 0 non-secure s2 is made of secure pages*/ \
787 VTCR_NSA | /* non-secure IPA maps to non-secure PA */ \
788 VTCR_RES1 \
789 )
790
Soby Mathewb4c6df42022-11-09 11:13:29 +0000791/* PMCR_EL0 Definitions */
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000792#define PMCR_EL0_N_SHIFT 11
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100793#define PMCR_EL0_N_WIDTH U(5)
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000794#define PMCR_EL0_LC_BIT (UL(1) << 6)
795#define PMCR_EL0_DP_BIT (UL(1) << 5)
796#define PMCR_EL0_C_BIT (UL(1) << 2)
797#define PMCR_EL0_P_BIT (UL(1) << 1)
798#define PMCR_EL0_E_BIT (UL(1) << 0)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000799
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000800#define PMCR_EL0_INIT (PMCR_EL0_LC_BIT | PMCR_EL0_DP_BIT)
801#define PMCR_EL0_INIT_RESET (PMCR_EL0_INIT | PMCR_EL0_C_BIT | \
802 PMCR_EL0_P_BIT)
AlexeiFedorovc1c2aed2025-01-15 18:00:08 +0000803/* PMSELR_EL0 Definitions */
804#define PMSELR_EL0_SEL_SHIFT 0
805#define PMSELR_EL0_SEL_WIDTH U(5)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000806
AlexeiFedorov862f96c2024-03-01 16:26:48 +0000807/* DCZID_EL0 Definitions */
808#define DCZID_EL0_BS_SHIFT 0
809#define DCZID_EL0_BS_WIDTH U(4)
810#define DCZID_EL0_DZP_BIT (UL(1) << 4)
811
Soby Mathewb4c6df42022-11-09 11:13:29 +0000812/* MDSCR_EL1 Definitions */
AlexeiFedorov537bee02023-02-02 13:38:23 +0000813#define MDSCR_EL1_TDCC_BIT (UL(1) << 12)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000814
815/* SCTLR register definitions */
Arvind Ram Prakashbd36a1b2022-12-15 12:16:36 -0600816#define SCTLR_ELx_RES1_BIT ((UL(1) << 22) /* TODO: ARMv8.5-CSEH, otherwise RES1 */ | \
817 (UL(1) << 11) /* TODO: ARMv8.5-CSEH, otherwise RES1 */)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000818
Arvind Ram Prakashbd36a1b2022-12-15 12:16:36 -0600819#define SCTLR_ELx_M_BIT (UL(1) << 0)
AlexeiFedorovbb01b422023-10-24 17:00:50 +0100820#define SCTLR_ELx_A_BIT (UL(1) << 1)
Arvind Ram Prakashbd36a1b2022-12-15 12:16:36 -0600821#define SCTLR_ELx_C_BIT (UL(1) << 2)
822#define SCTLR_ELx_SA_BIT (UL(1) << 3)
823#define SCTLR_ELx_SA0_BIT (UL(1) << 4)
824#define SCTLR_ELx_CP15BEN_BIT (UL(1) << 5)
825#define SCTLR_ELx_nAA_BIT (UL(1) << 6)
826#define SCTLR_ELx_SED_BIT (UL(1) << 8)
827#define SCTLR_ELx_EOS_BIT (UL(1) << 11)
828#define SCTLR_ELx_I_BIT (UL(1) << 12)
829#define SCTLR_ELx_DZE_BIT (UL(1) << 14)
830#define SCTLR_ELx_UCT_BIT (UL(1) << 15)
831#define SCTLR_ELx_nTWI_BIT (UL(1) << 16)
832#define SCTLR_ELx_nTWE_BIT (UL(1) << 18)
833#define SCTLR_ELx_WXN_BIT (UL(1) << 19)
834#define SCTLR_ELx_TSCXT_BIT (UL(1) << 20)
835#define SCTLR_ELx_EIS_BIT (UL(1) << 22)
836#define SCTLR_ELx_SPAN_BIT (UL(1) << 23)
837#define SCTLR_ELx_EE_BIT (UL(1) << 25)
838#define SCTLR_ELx_UCI_BIT (UL(1) << 26)
839#define SCTLR_ELx_nTLSMD_BIT (UL(1) << 28)
840#define SCTLR_ELx_LSMAOE_BIT (UL(1) << 29)
841#define SCTLR_ELx_EnIA_BIT (UL(1) << 31)
Shruti Guptaa4cb2a22023-05-23 14:55:49 +0100842#define SCTLR_ELx_BT0_BIT (UL(1) << 35)
843#define SCTLR_ELx_BT1_BIT (UL(1) << 36)
Javier Almansa Sobrino34005b92024-10-11 17:53:41 +0100844#define SCTLR_ELx_DSSBS_BIT (UL(1) << 44)
845#define SCTLR_ELx_SPINTMASK_BIT (UL(1) << 62)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000846
Arvind Ram Prakashbd36a1b2022-12-15 12:16:36 -0600847#define SCTLR_EL1_FLAGS (SCTLR_ELx_SPAN_BIT | SCTLR_ELx_EIS_BIT | SCTLR_ELx_nTWE_BIT | \
848 SCTLR_ELx_nTWI_BIT | SCTLR_ELx_EOS_BIT | SCTLR_ELx_nAA_BIT | \
849 SCTLR_ELx_CP15BEN_BIT | SCTLR_ELx_SA0_BIT | SCTLR_ELx_SA_BIT)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000850
AlexeiFedorovbb01b422023-10-24 17:00:50 +0100851#define SCTLR_EL2_BITS (SCTLR_ELx_C_BIT /* Data accesses are cacheable
Arvind Ram Prakashbd36a1b2022-12-15 12:16:36 -0600852 * as per translation tables */ | \
853 /* SCTLR_EL2_M = 0 (MMU disabled) */ \
854 /* SCTLR_EL2_A = 0
855 * (No alignment checks) */ \
856 SCTLR_ELx_SA_BIT /* SP aligned at EL2 */ | \
857 SCTLR_ELx_SA0_BIT /* SP Alignment check enable for EL0 */ \
858 /* SCTLR_EL2_CP15BEN = 0 (EL0 using AArch32:
859 * EL0 execution of the CP15DMB, CP15DSB,
860 * and CP15ISB instructions is
861 * UNDEFINED. */ \
862 /* SCTLR_EL2_NAA = 0 (unaligned MA fault
863 * at EL2 and EL0) */ \
864 /* SCTLR_EL2_ITD = 0 (A32 Only) */ | \
865 SCTLR_ELx_SED_BIT /* A32 Only, RES1 for non-A32 systems */ \
866 /* SCTLR_EL2_EOS TODO: ARMv8.5-CSEH,
867 * otherwise RES1 */ | \
868 SCTLR_ELx_I_BIT /* I$ is ON for EL2 and EL0 */ | \
869 SCTLR_ELx_DZE_BIT /* Do not trap DC ZVA */ | \
870 SCTLR_ELx_UCT_BIT /* Allow EL0 access to CTR_EL0 */ | \
871 SCTLR_ELx_nTWI_BIT /* Don't trap WFI from EL0 to EL2 */ | \
872 SCTLR_ELx_nTWE_BIT /* Don't trap WFE from EL0 to EL2 */ | \
873 SCTLR_ELx_WXN_BIT /* W implies XN */ | \
874 SCTLR_ELx_TSCXT_BIT /* Trap EL0 accesss to SCXTNUM_EL0 */ | \
875 /* SCTLR_EL2_EIS EL2 exception is context
876 * synchronizing
877 */ \
878 SCTLR_ELx_RES1_BIT | \
879 /* SCTLR_EL2_SPAN = 0 (Set PSTATE.PAN = 1 on
880 * exceptions to EL2)) */ \
881 SCTLR_ELx_UCI_BIT /* Allow cache maintenance
882 * instructions at EL0 */ | \
883 SCTLR_ELx_nTLSMD_BIT /* A32/T32 only */ | \
884 SCTLR_ELx_LSMAOE_BIT /* A32/T32 only */)
885
AlexeiFedorovbb01b422023-10-24 17:00:50 +0100886#ifdef RMM_FPU_USE_AT_REL2
887#define SCTLR_EL2_INIT SCTLR_EL2_BITS
888#else
889#define SCTLR_EL2_INIT (SCTLR_EL2_BITS | \
890 SCTLR_ELx_A_BIT /* Alignment fault check enable */)
891#endif
892
Arvind Ram Prakashbd36a1b2022-12-15 12:16:36 -0600893#define SCTLR_EL2_RUNTIME (SCTLR_EL2_INIT | \
894 SCTLR_ELx_M_BIT /* MMU enabled */)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000895
Javier Almansa Sobrinocfd32542024-10-09 19:38:56 +0100896/* SCTLR2_ELx Register definitions */
897#define SCTLR2_ELx_NMEA_BIT (UL(1) << 2)
898#define SCTLR2_ELx_EnADERR_BIT (UL(1) << 3)
899#define SCTLR2_ELx_EnANERR_BIT (UL(1) << 4)
900#define SCTLR2_ELx_EASE_BIT (UL(1) << 5)
901#define SCTLR2_ELx_EnIDCP128_BIT (UL(1) << 6)
902
Arunachalam Ganapathy9ade18b2023-06-12 14:07:21 +0100903/* RMM sets HCR_EL2.E2H to 1. CPTR_EL2 definitions when HCR_EL2.E2H == 1 */
904#define CPTR_EL2_VHE_TTA (UL(1) << 28)
905#define CPTR_EL2_VHE_TAM (UL(1) << 30)
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100906
Arunachalam Ganapathy9ade18b2023-06-12 14:07:21 +0100907#define CPTR_EL2_VHE_FPEN_SHIFT UL(20)
908#define CPTR_EL2_VHE_FPEN_WIDTH UL(2)
909#define CPTR_EL2_VHE_FPEN_TRAP_ALL_00 UL(0)
910#define CPTR_EL2_VHE_FPEN_TRAP_TGE_01 UL(1)
911#define CPTR_EL2_VHE_FPEN_TRAP_ALL_10 UL(2)
912#define CPTR_EL2_VHE_FPEN_NO_TRAP_11 UL(3)
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100913
Arunachalam Ganapathy9ade18b2023-06-12 14:07:21 +0100914#define CPTR_EL2_VHE_ZEN_SHIFT UL(16)
915#define CPTR_EL2_VHE_ZEN_WIDTH UL(2)
916#define CPTR_EL2_VHE_ZEN_TRAP_ALL_00 UL(0x0)
917#define CPTR_EL2_VHE_ZEN_NO_TRAP_11 UL(0x3)
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100918
Arunachalam Ganapathy83f46ca2023-08-15 18:13:27 +0100919#define CPTR_EL2_VHE_SMEN_SHIFT UL(24)
920#define CPTR_EL2_VHE_SMEN_WIDTH UL(2)
921#define CPTR_EL2_VHE_SMEN_TRAP_ALL_00 UL(0x0)
922#define CPTR_EL2_VHE_SMEN_NO_TRAP_11 UL(0x3)
923
Arunachalam Ganapathyddccbae2023-10-03 11:29:42 +0100924#define CPTR_EL2_VHE_SIMD_MASK (MASK(CPTR_EL2_VHE_FPEN) | \
925 MASK(CPTR_EL2_VHE_ZEN) | \
926 MASK(CPTR_EL2_VHE_SMEN))
927
Arunachalam Ganapathy83f46ca2023-08-15 18:13:27 +0100928/* Trap all AMU, trace, FPU, SVE, SME accesses */
Arunachalam Ganapathy9ade18b2023-06-12 14:07:21 +0100929#define CPTR_EL2_VHE_INIT ((CPTR_EL2_VHE_ZEN_TRAP_ALL_00 << \
930 CPTR_EL2_VHE_ZEN_SHIFT) | \
Arunachalam Ganapathy83f46ca2023-08-15 18:13:27 +0100931 (CPTR_EL2_VHE_SMEN_TRAP_ALL_00 << \
932 CPTR_EL2_VHE_SMEN_SHIFT) | \
Arunachalam Ganapathy9ade18b2023-06-12 14:07:21 +0100933 (CPTR_EL2_VHE_FPEN_TRAP_ALL_00 << \
934 CPTR_EL2_VHE_FPEN_SHIFT) | \
935 CPTR_EL2_VHE_TTA | \
936 CPTR_EL2_VHE_TAM)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000937
938/* MDCR_EL2 definitions */
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000939#define MDCR_EL2_HPMFZS (UL(1) << 36)
940#define MDCR_EL2_HPMFZO (UL(1) << 29)
941#define MDCR_EL2_MTPME (UL(1) << 28)
942#define MDCR_EL2_TDCC (UL(1) << 27)
AlexeiFedorov537bee02023-02-02 13:38:23 +0000943#define MDCR_EL2_HLP (UL(1) << 26)
944#define MDCR_EL2_HCCD (UL(1) << 23)
945#define MDCR_EL2_TTRF (UL(1) << 19)
946#define MDCR_EL2_HPMD (UL(1) << 17)
947#define MDCR_EL2_TPMS (UL(1) << 14)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000948#define MDCR_EL2_E2PB(x) ((x) << 12)
AlexeiFedorov537bee02023-02-02 13:38:23 +0000949#define MDCR_EL2_E2PB_EL1 UL(3)
950#define MDCR_EL2_TDRA_BIT (UL(1) << 11)
951#define MDCR_EL2_TDOSA_BIT (UL(1) << 10)
952#define MDCR_EL2_TDA_BIT (UL(1) << 9)
953#define MDCR_EL2_TDE_BIT (UL(1) << 8)
954#define MDCR_EL2_HPME_BIT (UL(1) << 7)
955#define MDCR_EL2_TPM_BIT (UL(1) << 6)
956#define MDCR_EL2_TPMCR_BIT (UL(1) << 5)
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000957
958#define MDCR_EL2_HPMN_SHIFT UL(0)
959#define MDCR_EL2_HPMN_WIDTH UL(5)
960
961#define MDCR_EL2_INIT (MDCR_EL2_MTPME | \
962 MDCR_EL2_HCCD | \
963 MDCR_EL2_HPMD | \
964 MDCR_EL2_TDA_BIT | \
965 MDCR_EL2_TPM_BIT | \
966 MDCR_EL2_TPMCR_BIT)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000967
Arvind Ram Prakashbd36a1b2022-12-15 12:16:36 -0600968/* Armv8.3 Pointer Authentication Registers */
969#define APIAKeyLo_EL1 S3_0_C2_C1_0
970#define APIAKeyHi_EL1 S3_0_C2_C1_1
971#define APIBKeyLo_EL1 S3_0_C2_C1_2
972#define APIBKeyHi_EL1 S3_0_C2_C1_3
973#define APDAKeyLo_EL1 S3_0_C2_C2_0
974#define APDAKeyHi_EL1 S3_0_C2_C2_1
975#define APDBKeyLo_EL1 S3_0_C2_C2_2
976#define APDBKeyHi_EL1 S3_0_C2_C2_3
977#define APGAKeyLo_EL1 S3_0_C2_C3_0
978#define APGAKeyHi_EL1 S3_0_C2_C3_1
979
AlexeiFedorov887a8aa2024-09-11 16:22:20 +0100980/*
981 * MPIDR_EL1 definitions
982 * 'MPIDR_EL1_AFF<n>_VAL_SHIFT' constants specify the right shift
983 * for affinity field <n> that gives the field's actual value.
984 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000985
AlexeiFedorov887a8aa2024-09-11 16:22:20 +0100986/* Aff0[3:0] - Affinity level 0
987 * For compatibility with GICv3 only Aff0[3:0] field is used,
988 * and Aff0[7:4] of MPIDR_EL1 value is RES0 to match RmiRecMpidr.
989 */
990#define MPIDR_EL1_AFF0_SHIFT U(0)
991#define MPIDR_EL1_AFF0_WIDTH U(4)
992#define MPIDR_EL1_AFF0_VAL_SHIFT U(0)
993
994/* Aff1[15:8] - Affinity level 1 */
995#define MPIDR_EL1_AFF1_SHIFT U(8)
996#define MPIDR_EL1_AFF1_WIDTH U(8)
997#define MPIDR_EL1_AFF1_VAL_SHIFT U(4)
998
999/* Aff2[23:16] - Affinity level 2 */
1000#define MPIDR_EL1_AFF2_SHIFT U(16)
1001#define MPIDR_EL1_AFF2_WIDTH U(8)
1002#define MPIDR_EL1_AFF2_VAL_SHIFT U(4)
1003
1004/* Aff3[39:32] - Affinity level 3 */
1005#define MPIDR_EL1_AFF3_SHIFT U(32)
1006#define MPIDR_EL1_AFF3_WIDTH U(8)
1007#define MPIDR_EL1_AFF3_VAL_SHIFT U(12)
1008
1009/*
1010 * Extract the value of MPIDR_EL1.Aff<n> register field shifted right
1011 * so it can be evaluated directly.
1012 */
1013#define MPIDR_EL1_AFF(n, reg) \
1014 (((reg) & MASK(MPIDR_EL1_AFF##n)) >> MPIDR_EL1_AFF##n##_VAL_SHIFT)
Soby Mathewb4c6df42022-11-09 11:13:29 +00001015
1016/*
1017 * RmiRecMpidr type definitions.
1018 *
AlexeiFedorov887a8aa2024-09-11 16:22:20 +01001019 * 'RMI_MPIDR_AFF<n>_VAL_SHIFT' constants specify the right shift
Soby Mathewb4c6df42022-11-09 11:13:29 +00001020 * for affinity field <n> that gives the field's actual value.
1021 *
1022 * Aff0[3:0] - Affinity level 0
1023 * For compatibility with GICv3 only Aff0[3:0] field is used,
1024 * and Aff0[7:4] of a REC MPIDR value is RES0.
1025 */
AlexeiFedorov887a8aa2024-09-11 16:22:20 +01001026#define RMI_MPIDR_AFF0_SHIFT U(0)
1027#define RMI_MPIDR_AFF0_WIDTH U(4)
1028#define RMI_MPIDR_AFF0_VAL_SHIFT U(0)
Soby Mathewb4c6df42022-11-09 11:13:29 +00001029
1030/* Aff1[15:8] - Affinity level 1 */
AlexeiFedorov887a8aa2024-09-11 16:22:20 +01001031#define RMI_MPIDR_AFF1_SHIFT U(8)
1032#define RMI_MPIDR_AFF1_WIDTH U(8)
1033#define RMI_MPIDR_AFF1_VAL_SHIFT U(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +00001034
1035/* Aff2[23:16] - Affinity level 2 */
AlexeiFedorov887a8aa2024-09-11 16:22:20 +01001036#define RMI_MPIDR_AFF2_SHIFT U(16)
1037#define RMI_MPIDR_AFF2_WIDTH U(8)
1038#define RMI_MPIDR_AFF2_VAL_SHIFT U(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +00001039
AlexeiFedorov887a8aa2024-09-11 16:22:20 +01001040/* Aff3[31:24] - Affinity level 3 */
1041#define RMI_MPIDR_AFF3_SHIFT U(24)
1042#define RMI_MPIDR_AFF3_WIDTH U(8)
1043#define RMI_MPIDR_AFF3_VAL_SHIFT U(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +00001044
1045/*
AlexeiFedorov887a8aa2024-09-11 16:22:20 +01001046 * Extract the value of RmiRecMpidr.Aff<n> field shifted right
Soby Mathewb4c6df42022-11-09 11:13:29 +00001047 * so it can be evaluated directly.
1048 */
AlexeiFedorov887a8aa2024-09-11 16:22:20 +01001049#define RMI_MPIDR_AFF(n, val) \
1050 (((val) & MASK(RMI_MPIDR_AFF##n)) >> RMI_MPIDR_AFF##n##_VAL_SHIFT)
Soby Mathewb4c6df42022-11-09 11:13:29 +00001051
AlexeiFedorov887a8aa2024-09-11 16:22:20 +01001052/* VMPIDR bit [31] = RES1 */
1053#define VMPIDR_EL2_RES1 (UL(1) << 31)
Soby Mathewb4c6df42022-11-09 11:13:29 +00001054
1055/* ICC_SRE_EL2 defintions */
1056#define ICC_SRE_EL2_ENABLE (UL(1) << 3) /* Enable lower EL access to ICC_SRE_EL1 */
1057#define ICC_SRE_EL2_DIB (UL(1) << 2) /* Disable IRQ bypass */
1058#define ICC_SRE_EL2_DFB (UL(1) << 1) /* Disable FIQ bypass */
1059#define ICC_SRE_EL2_SRE (UL(1) << 0) /* Enable sysreg access */
1060
AlexeiFedorov537bee02023-02-02 13:38:23 +00001061#define ICC_SRE_EL2_INIT (ICC_SRE_EL2_ENABLE | ICC_SRE_EL2_DIB | \
Soby Mathewb4c6df42022-11-09 11:13:29 +00001062 ICC_SRE_EL2_DFB | ICC_SRE_EL2_SRE)
1063
Soby Mathewb4c6df42022-11-09 11:13:29 +00001064#define PMSCR_EL2_INIT 0x0
1065
1066#define SYSREG_ESR(op0, op1, crn, crm, op2) \
AlexeiFedorov13b86dd2023-08-29 10:38:09 +01001067 ((UL(op0) << ESR_EL2_SYSREG_TRAP_OP0_SHIFT) | \
1068 (UL(op1) << ESR_EL2_SYSREG_TRAP_OP1_SHIFT) | \
1069 (UL(crn) << ESR_EL2_SYSREG_TRAP_CRN_SHIFT) | \
1070 (UL(crm) << ESR_EL2_SYSREG_TRAP_CRM_SHIFT) | \
1071 (UL(op2) << ESR_EL2_SYSREG_TRAP_OP2_SHIFT))
Soby Mathewb4c6df42022-11-09 11:13:29 +00001072
1073#define ESR_EL2_SYSREG_MASK SYSREG_ESR(3, 7, 15, 15, 7)
1074
1075#define ESR_EL2_SYSREG_ID_MASK SYSREG_ESR(3, 7, 15, 0, 0)
1076#define ESR_EL2_SYSREG_ID SYSREG_ESR(3, 0, 0, 0, 0)
1077
1078#define ESR_EL2_SYSREG_ID_AA64PFR0_EL1 SYSREG_ESR(3, 0, 0, 4, 0)
1079#define ESR_EL2_SYSREG_ID_AA64PFR1_EL1 SYSREG_ESR(3, 0, 0, 4, 1)
1080#define ESR_EL2_SYSREG_ID_AA64ZFR0_EL1 SYSREG_ESR(3, 0, 0, 4, 4)
Arunachalam Ganapathy83f46ca2023-08-15 18:13:27 +01001081#define ESR_EL2_SYSREG_ID_AA64SMFR0_EL1 SYSREG_ESR(3, 0, 0, 4, 5)
Soby Mathewb4c6df42022-11-09 11:13:29 +00001082
1083#define ESR_EL2_SYSREG_ID_AA64DFR0_EL1 SYSREG_ESR(3, 0, 0, 5, 0)
1084#define ESR_EL2_SYSREG_ID_AA64DFR1_EL1 SYSREG_ESR(3, 0, 0, 5, 1)
1085
1086#define ESR_EL2_SYSREG_ID_AA64AFR0_EL1 SYSREG_ESR(3, 0, 0, 5, 4)
1087#define ESR_EL2_SYSREG_ID_AA64AFR1_EL1 SYSREG_ESR(3, 0, 0, 5, 5)
1088
1089#define ESR_EL2_SYSREG_ID_AA64ISAR0_EL1 SYSREG_ESR(3, 0, 0, 6, 0)
1090#define ESR_EL2_SYSREG_ID_AA64ISAR1_EL1 SYSREG_ESR(3, 0, 0, 6, 1)
1091
1092#define ESR_EL2_SYSREG_ID_AA64MMFR0_EL1 SYSREG_ESR(3, 0, 0, 7, 0)
1093#define ESR_EL2_SYSREG_ID_AA64MMFR1_EL1 SYSREG_ESR(3, 0, 0, 7, 1)
1094#define ESR_EL2_SYSREG_ID_AA64MMFR2_EL1 SYSREG_ESR(3, 0, 0, 7, 2)
1095
Javier Almansa Sobrinoe2d133c2025-01-16 18:18:08 +00001096/*
1097 * FEAT_MPAM system registers encoding mask for registers
1098 * MPAM0_EL1: (3, 0, 10, 5, 1)
1099 * MPAM1_EL1: (3, 0, 10, 5, 0)
1100 * MPAMSM_EL1: (3, 0, 10, 5, 3)
1101 * MPAMIDR_EL1: (3, 0, 10, 4, 4)
1102 */
1103#define ESR_EL2_SYSREG_MPAM_MASK SYSREG_ESR(3, 7, 15, 14, 0)
1104#define ESR_EL2_SYSREG_MPAM SYSREG_ESR(3, 0, 10, 4, 0)
1105
AlexeiFedorov7bb7a702023-01-17 17:04:14 +00001106/* ID_AA64ISAR1_EL1 definitions */
1107#define ID_AA64ISAR1_EL1_GPI_SHIFT UL(28)
1108#define ID_AA64ISAR1_EL1_GPI_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +00001109
1110#define ID_AA64ISAR1_EL1_GPA_SHIFT UL(24)
1111#define ID_AA64ISAR1_EL1_GPA_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +00001112
1113#define ID_AA64ISAR1_EL1_API_SHIFT UL(8)
1114#define ID_AA64ISAR1_EL1_API_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +00001115
1116#define ID_AA64ISAR1_EL1_APA_SHIFT UL(4)
1117#define ID_AA64ISAR1_EL1_APA_WIDTH UL(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +00001118
1119#define ESR_EL2_SYSREG_TIMERS_MASK SYSREG_ESR(3, 3, 15, 12, 0)
1120#define ESR_EL2_SYSREG_TIMERS SYSREG_ESR(3, 3, 14, 0, 0)
1121
1122#define ESR_EL2_SYSREG_TIMER_CNTP_TVAL_EL0 SYSREG_ESR(3, 3, 14, 2, 0)
1123#define ESR_EL2_SYSREG_TIMER_CNTP_CTL_EL0 SYSREG_ESR(3, 3, 14, 2, 1)
1124#define ESR_EL2_SYSREG_TIMER_CNTP_CVAL_EL0 SYSREG_ESR(3, 3, 14, 2, 2)
1125#define ESR_EL2_SYSREG_TIMER_CNTV_TVAL_EL0 SYSREG_ESR(3, 3, 14, 3, 0)
1126#define ESR_EL2_SYSREG_TIMER_CNTV_CTL_EL0 SYSREG_ESR(3, 3, 14, 3, 1)
1127#define ESR_EL2_SYSREG_TIMER_CNTV_CVAL_EL0 SYSREG_ESR(3, 3, 14, 3, 2)
1128
1129#define ESR_EL2_SYSREG_ICC_PMR_EL1 SYSREG_ESR(3, 0, 4, 6, 0)
1130
1131/*
1132 * GIC system registers encoding mask for registers from
1133 * ICC_IAR0_EL1(3, 0, 12, 8, 0) to ICC_IGRPEN1_EL1(3, 0, 12, 12, 7).
1134 */
1135#define ESR_EL2_SYSREG_ICC_EL1_MASK SYSREG_ESR(3, 3, 15, 8, 0)
1136#define ESR_EL2_SYSREG_ICC_EL1 SYSREG_ESR(3, 0, 12, 8, 0)
1137
1138#define ESR_EL2_SYSREG_ICC_DIR SYSREG_ESR(3, 0, 12, 11, 1)
1139#define ESR_EL2_SYSREG_ICC_SGI1R_EL1 SYSREG_ESR(3, 0, 12, 11, 5)
1140#define ESR_EL2_SYSREG_ICC_SGI0R_EL1 SYSREG_ESR(3, 0, 12, 11, 7)
1141
1142#define ESR_EL2_SYSREG_DIRECTION (UL(1) << 0)
AlexeiFedorov13b86dd2023-08-29 10:38:09 +01001143#define ESR_EL2_SYSREG_IS_WRITE(esr) (((esr) & ESR_EL2_SYSREG_DIRECTION) == 0UL)
Soby Mathewb4c6df42022-11-09 11:13:29 +00001144
Sona Mathew21992e72025-02-03 00:37:22 -06001145/*
1146 * FEAT_BRBE system registers encoding mask for registers from
1147 * BRBINF<n>_EL1(2, 1, 8, 0, 0) to BRBTGTINJ_EL1(2, 1, 9, 1, 2).
1148 */
1149#define ESR_EL2_SYSREG_BRBE SYSREG_ESR(2, 1, 8, 0, 0)
1150#define ESR_EL2_SYSREG_BRBE_MASK SYSREG_ESR(2, 7, 14, 0, 0)
1151
AlexeiFedorov537bee02023-02-02 13:38:23 +00001152#define ESR_IL(esr) ((esr) & MASK(ESR_EL2_IL))
Soby Mathewb4c6df42022-11-09 11:13:29 +00001153
AlexeiFedorovfeaef162022-12-23 16:59:51 +00001154#define ESR_EL2_SYSREG_ISS_RT(esr) EXTRACT(ESR_EL2_SYSREG_TRAP_RT, esr)
Soby Mathewb4c6df42022-11-09 11:13:29 +00001155
AlexeiFedorov93f5ec52023-08-31 14:26:53 +01001156#define ICC_HPPIR1_EL1_INTID_SHIFT UL(0)
1157#define ICC_HPPIR1_EL1_INTID_WIDTH UL(24)
Soby Mathewb4c6df42022-11-09 11:13:29 +00001158
1159#define CNTHCTL_EL2_EL0PCTEN (UL(1) << UL(0))
1160#define CNTHCTL_EL2_EL0VCTEN (UL(1) << UL(1))
1161#define CNTHCTL_EL2_EL1PCTEN (UL(1) << 10)
1162#define CNTHCTL_EL2_EL1PTEN (UL(1) << 11)
1163#define CNTHCTL_EL2_EL1TVT (UL(1) << 13)
1164#define CNTHCTL_EL2_EL1TVCT (UL(1) << 14)
1165#define CNTHCTL_EL2_CNTVMASK (UL(1) << 18)
1166#define CNTHCTL_EL2_CNTPMASK (UL(1) << 19)
1167
1168#define CNTHCTL_EL2_INIT (CNTHCTL_EL2_EL0VCTEN | CNTHCTL_EL2_EL0PCTEN)
1169
1170#define CNTHCTL_EL2_NO_TRAPS (CNTHCTL_EL2_EL1PCTEN | \
1171 CNTHCTL_EL2_EL1PTEN)
1172
1173#define CNTx_CTL_ENABLE (UL(1) << 0)
1174#define CNTx_CTL_IMASK (UL(1) << 1)
1175#define CNTx_CTL_ISTATUS (UL(1) << 2)
1176
1177/*******************************************************************************
1178 * Definitions of register offsets, fields and macros for CPU system
1179 * instructions.
1180 ******************************************************************************/
1181
1182#define TLBI_ADDR_SHIFT U(12)
AlexeiFedorov1ba649f2023-10-19 13:56:02 +01001183#define TLBI_ADDR_MASK UL(0x0FFFFFFFFFFF)
Soby Mathewb4c6df42022-11-09 11:13:29 +00001184#define TLBI_ADDR(x) (((x) >> TLBI_ADDR_SHIFT) & TLBI_ADDR_MASK)
1185
1186/* ID_AA64MMFR2_EL1 definitions */
AlexeiFedorov537bee02023-02-02 13:38:23 +00001187#define ID_AA64MMFR2_EL1_ST_SHIFT UL(28)
1188#define ID_AA64MMFR2_EL1_ST_WIDTH UL(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +00001189
AlexeiFedorov537bee02023-02-02 13:38:23 +00001190#define ID_AA64MMFR2_EL1_CNP_SHIFT UL(0)
1191#define ID_AA64MMFR2_EL1_CNP_WIDTH UL(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +00001192
Javier Almansa Sobrinocfd32542024-10-09 19:38:56 +01001193/* ID_AA64MMFR3_EL1_definitions */
1194#define ID_AA64MMFR3 S3_0_C0_C7_3
1195#define ID_AA64MMFR3_EL1_SCTLRX_SHIFT UL(4)
1196#define ID_AA64MMFR3_EL1_SCTLRX_WIDTH UL(4)
1197
Soby Mathewb4c6df42022-11-09 11:13:29 +00001198/* Custom defined values to indicate the vector offset to exception handlers */
1199#define ARM_EXCEPTION_SYNC_LEL 0
1200#define ARM_EXCEPTION_IRQ_LEL 1
1201#define ARM_EXCEPTION_FIQ_LEL 2
1202#define ARM_EXCEPTION_SERROR_LEL 3
1203
AlexeiFedorov537bee02023-02-02 13:38:23 +00001204#define VBAR_CEL_SP_EL0_OFFSET 0x0
1205#define VBAR_CEL_SP_ELx_OFFSET 0x200
1206#define VBAR_LEL_AA64_OFFSET 0x400
1207#define VBAR_LEL_AA32_OFFSET 0x600
Soby Mathewb4c6df42022-11-09 11:13:29 +00001208
Javier Almansa Sobrinocfd32542024-10-09 19:38:56 +01001209/* SError vector offset from Sync exception vector */
1210#define VBAR_SERROR_OFFSET UL(0x180)
1211
AlexeiFedorov4c7d4852024-01-25 14:37:34 +00001212/* Stack Pointer selection */
1213#define MODE_SP_EL0 UL(0)
1214#define MODE_SP_ELX UL(1)
1215
Javier Almansa Sobrino34005b92024-10-11 17:53:41 +01001216/*******************************************************************************
1217 * FEAT_GCS - Guarded Control Stack Registers
1218 ******************************************************************************/
1219#define ID_GCSCR_EL12 S3_5_C2_C5_0
1220#define GCSCR_EXLOCK_EN_BIT (UL(1) << 6)
1221
1222
Soby Mathewb4c6df42022-11-09 11:13:29 +00001223#endif /* ARCH_H */