blob: 8d0ed429b412a462d96ba142e7cb289aac46bbb7 [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
68/* CLIDR definitions */
69#define LOC_SHIFT U(24)
70#define CTYPE_SHIFT(n) U(3 * ((n) - 1))
71#define CLIDR_FIELD_WIDTH U(3)
72
73/* CSSELR definitions */
74#define LEVEL_SHIFT U(1)
75
76/* Data cache set/way op type defines */
77#define DCISW U(0x0)
78#define DCCISW U(0x1)
79#define DCCSW U(0x2)
80
81#define TCR_EL2_T0SZ_SHIFT UL(0)
82#define TCR_EL2_T0SZ_WIDTH UL(6)
Soby Mathewb4c6df42022-11-09 11:13:29 +000083
84#define TCR_EL2_T1SZ_SHIFT UL(16)
85#define TCR_EL2_T1SZ_WIDTH UL(6)
Soby Mathewb4c6df42022-11-09 11:13:29 +000086
AlexeiFedorov537bee02023-02-02 13:38:23 +000087#define TCR_EL2_EPD0_BIT (UL(1) << 7)
Soby Mathewb4c6df42022-11-09 11:13:29 +000088
89#define TCR_EL2_IRGN0_SHIFT UL(8)
90#define TCR_EL2_IRGN0_WIDTH UL(2)
91#define TCR_EL2_IRGN0_WBWA INPLACE(TCR_EL2_IRGN0, UL(1))
92
93#define TCR_EL2_ORGN0_SHIFT UL(10)
94#define TCR_EL2_ORGN0_WIDTH UL(2)
95#define TCR_EL2_ORGN0_WBWA INPLACE(TCR_EL2_ORGN0, UL(1))
96
97#define TCR_EL2_IRGN1_SHIFT UL(24)
98#define TCR_EL2_IRGN1_WIDTH UL(2)
99#define TCR_EL2_IRGN1_WBWA INPLACE(TCR_EL2_IRGN1, UL(1))
100
101#define TCR_EL2_ORGN1_SHIFT UL(26)
102#define TCR_EL2_ORGN1_WIDTH UL(2)
103#define TCR_EL2_ORGN1_WBWA INPLACE(TCR_EL2_ORGN1, UL(1))
104
105#define TCR_EL2_SH0_SHIFT UL(12)
106#define TCR_EL2_SH0_WIDTH UL(2)
107#define TCR_EL2_SH0_IS INPLACE(TCR_EL2_SH0, UL(3))
108
109#define TCR_EL2_SH1_SHIFT UL(28)
110#define TCR_EL2_SH1_WIDTH UL(2)
111#define TCR_EL2_SH1_IS INPLACE(TCR_EL2_SH1, UL(3))
112
113#define TCR_EL2_TG0_SHIFT UL(14)
114#define TCR_EL2_TG0_WIDTH UL(2)
115#define TCR_EL2_TG0_4K INPLACE(TCR_EL2_TG0, UL(0))
116
117#define TCR_EL2_TG1_SHIFT UL(30)
118#define TCR_EL2_TG1_WIDTH UL(2)
Javier Almansa Sobrino70194902023-02-28 10:27:02 +0000119#define TCR_EL2_TG1_4K INPLACE(TCR_EL2_TG1, UL(2))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000120
121#define TCR_EL2_IPS_SHIFT UL(32)
122#define TCR_EL2_IPS_WIDTH UL(3)
123#define TCR_PS_BITS_4GB INPLACE(TCR_EL2_IPS, UL(0))
124#define TCR_PS_BITS_64GB INPLACE(TCR_EL2_IPS, UL(1))
125#define TCR_PS_BITS_1TB INPLACE(TCR_EL2_IPS, UL(2))
126#define TCR_PS_BITS_4TB INPLACE(TCR_EL2_IPS, UL(3))
127#define TCR_PS_BITS_16TB INPLACE(TCR_EL2_IPS, UL(4))
128#define TCR_PS_BITS_256TB INPLACE(TCR_EL2_IPS, UL(5))
Javier Almansa Sobrino765a3162023-04-27 17:42:58 +0100129#define TCR_PS_BITS_4PB INPLACE(TCR_EL2_IPS, UL(6))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000130
Javier Almansa Sobrino765a3162023-04-27 17:42:58 +0100131#define TCR_EL2_DS_SHIFT UL(59)
132#define TCR_EL2_DS_WIDTH UL(1)
133#define TCR_EL2_DS_LPA2_EN INPLACE(TCR_EL2_DS, UL(1))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000134
135#define TCR_EL2_AS (UL(1) << 36)
136#define TCR_EL2_HPD0 (UL(1) << 41)
137#define TCR_EL2_HPD1 (UL(1) << 42)
138#define TCR_EL2_E0PD1 (UL(1) << 56) /* TODO: ARMv8.5-E0PD, otherwise RES0 */
139
140#define TCR_TxSZ_MIN UL(16)
Javier Almansa Sobrino765a3162023-04-27 17:42:58 +0100141#define TCR_TxSZ_MIN_LPA2 UL(12)
Javier Almansa Sobrinoed932592023-01-24 12:50:41 +0000142#define TCR_TxSZ_MAX UL(48)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000143
144/* HCR definitions */
145#define HCR_FWB (UL(1) << 46)
146#define HCR_TEA (UL(1) << 37)
147#define HCR_API (UL(1) << 41)
148#define HCR_APK (UL(1) << 40)
149#define HCR_TERR (UL(1) << 36)
150#define HCR_TLOR (UL(1) << 35)
151#define HCR_E2H (UL(1) << 34)
152#define HCR_RW (UL(1) << 31)
153#define HCR_TGE (UL(1) << 27)
154#define HCR_TSW (UL(1) << 22)
155#define HCR_TACR (UL(1) << 21)
156#define HCR_TIDCP (UL(1) << 20)
157#define HCR_TSC (UL(1) << 19)
158#define HCR_TID3 (UL(1) << 18)
159#define HCR_TWE (UL(1) << 14)
160#define HCR_TWI (UL(1) << 13)
161#define HCR_VSE (UL(1) << 8)
162
163#define HCR_BSU_SHIFT 10
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100164#define HCR_BSU_WIDTH U(2)
165#define HCR_BSU_IS INPLACE(HCR_BSU, UL(1)) /* Barriers are promoted to IS */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000166
167#define HCR_FB (UL(1) << 9)
168#define HCR_VI (UL(1) << 7)
169#define HCR_AMO (UL(1) << 5)
170#define HCR_IMO (UL(1) << 4)
171#define HCR_FMO (UL(1) << 3)
172#define HCR_PTW (UL(1) << 2)
173#define HCR_SWIO (UL(1) << 1)
174#define HCR_VM (UL(1) << 0)
175
Soby Mathewb4c6df42022-11-09 11:13:29 +0000176#define HCR_FLAGS (HCR_FWB | HCR_E2H | HCR_RW | HCR_TSC | HCR_AMO | \
177 HCR_BSU_IS | HCR_IMO | HCR_FMO | HCR_PTW | HCR_SWIO | HCR_VM | \
Arvind Ram Prakashbd36a1b2022-12-15 12:16:36 -0600178 HCR_TID3 | HCR_TEA | HCR_API | HCR_APK)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000179
180#define HCR_EL2_INIT (HCR_TGE | HCR_E2H | HCR_TEA)
181
182#define MAIR_ELx_ATTR0_SHIFT 0
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100183#define MAIR_ELx_ATTR0_WIDTH U(8)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000184
185/*******************************************************************************
186 * Definitions of MAIR encodings for device and normal memory
187 ******************************************************************************/
188/*
189 * MAIR encodings for device memory attributes.
190 */
191#define MAIR_DEV_NGNRNE UL(0x0) /* Device nGnRnE */
192#define MAIR_DEV_NGNRNE_IDX 0x1
193
194#define MAIR_DEV_NGNRE UL(0x4)
195
196#define MAIR_NIOWBNTRW 0xff
197#define MAIR_NIOWBNTRW_IDX 0x0
198
199/*
200 * MAIR encodings for normal memory attributes.
201 *
202 * Cache Policy
203 * WT: Write Through
204 * WB: Write Back
205 * NC: Non-Cacheable
206 *
207 * Transient Hint
208 * NTR: Non-Transient
209 * TR: Transient
210 *
211 * Allocation Policy
212 * RA: Read Allocate
213 * WA: Write Allocate
214 * RWA: Read and Write Allocate
215 * NA: No Allocation
216 */
217#define MAIR_NORM_WT_TR_WA UL(0x1)
218#define MAIR_NORM_WT_TR_RA UL(0x2)
219#define MAIR_NORM_WT_TR_RWA UL(0x3)
220#define MAIR_NORM_NC UL(0x4)
221#define MAIR_NORM_WB_TR_WA UL(0x5)
222#define MAIR_NORM_WB_TR_RA UL(0x6)
223#define MAIR_NORM_WB_TR_RWA UL(0x7)
224#define MAIR_NORM_WT_NTR_NA UL(0x8)
225#define MAIR_NORM_WT_NTR_WA UL(0x9)
226#define MAIR_NORM_WT_NTR_RA UL(0xa)
227#define MAIR_NORM_WT_NTR_RWA UL(0xb)
228#define MAIR_NORM_WB_NTR_NA UL(0xc)
229#define MAIR_NORM_WB_NTR_WA UL(0xd)
230#define MAIR_NORM_WB_NTR_RA UL(0xe)
231#define MAIR_NORM_WB_NTR_RWA UL(0xf)
232
233#define MAIR_NORM_OUTER_SHIFT U(4)
234
235#define MAKE_MAIR_NORMAL_MEMORY(inner, outer) \
236 ((inner) | ((outer) << MAIR_NORM_OUTER_SHIFT))
237
238#define MAKE_MAIR_NORMAL_MEMORY_IO(_mair) \
239 MAKE_MAIR_NORMAL_MEMORY(_mair, _mair)
240
241/*
242 * TTBR Definitions
243 */
AlexeiFedorov537bee02023-02-02 13:38:23 +0000244#define TTBR_CNP_BIT UL(1)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000245
246#define TTBRx_EL2_CnP_SHIFT 0
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100247#define TTBRx_EL2_CnP_WIDTH U(1)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000248
249#define TTBRx_EL2_BADDR_SHIFT 1
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100250#define TTBRx_EL2_BADDR_WIDTH U(47)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000251
252#define TTBRx_EL2_ASID_SHIFT 48
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100253#define TTBRx_EL2_ASID_WIDTH U(16)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000254
255/*
256 * VTTBR Definitions
257 */
258#define VTTBR_EL2_VMID_SHIFT 48
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100259#define VTTBR_EL2_VMID_WIDTH U(16)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000260
261/*
262 * ESR Definitions
263 */
264#define ESR_EL2_EC_SHIFT 26
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100265#define ESR_EL2_EC_WIDTH U(6)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000266
267#define ESR_EL2_IL_SHIFT 25
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100268#define ESR_EL2_IL_WIDTH U(1)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000269
270#define ESR_EL2_ISS_SHIFT 0
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100271#define ESR_EL2_ISS_WIDTH U(25)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000272
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100273#define ESR_EL2_EC_UNKNOWN INPLACE(ESR_EL2_EC, UL(0))
274#define ESR_EL2_EC_WFX INPLACE(ESR_EL2_EC, UL(1))
275#define ESR_EL2_EC_FPU INPLACE(ESR_EL2_EC, UL(7))
276#define ESR_EL2_EC_SVC INPLACE(ESR_EL2_EC, UL(21))
277#define ESR_EL2_EC_HVC INPLACE(ESR_EL2_EC, UL(22))
278#define ESR_EL2_EC_SMC INPLACE(ESR_EL2_EC, UL(23))
279#define ESR_EL2_EC_SYSREG INPLACE(ESR_EL2_EC, UL(24))
280#define ESR_EL2_EC_SVE INPLACE(ESR_EL2_EC, UL(25))
Arunachalam Ganapathy83f46ca2023-08-15 18:13:27 +0100281#define ESR_EL2_EC_SME INPLACE(ESR_EL2_EC, UL(29))
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100282#define ESR_EL2_EC_INST_ABORT INPLACE(ESR_EL2_EC, UL(32))
283#define ESR_EL2_EC_INST_ABORT_SEL INPLACE(ESR_EL2_EC, UL(33))
284#define ESR_EL2_EC_DATA_ABORT INPLACE(ESR_EL2_EC, UL(36))
285#define ESR_EL2_EC_DATA_ABORT_SEL INPLACE(ESR_EL2_EC, UL(37))
286#define ESR_EL2_EC_SERROR INPLACE(ESR_EL2_EC, UL(47))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000287
288/* Data/Instruction Abort ESR fields */
AlexeiFedorov537bee02023-02-02 13:38:23 +0000289#define ESR_EL2_ABORT_ISV_BIT (UL(1) << 24)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000290
291#define ESR_EL2_ABORT_SAS_SHIFT 22
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100292#define ESR_EL2_ABORT_SAS_WIDTH U(2)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000293
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100294#define ESR_EL2_ABORT_SAS_BYTE_VAL 0U
295#define ESR_EL2_ABORT_SAS_HWORD_VAL 1U
296#define ESR_EL2_ABORT_SAS_WORD_VAL 2U
297#define ESR_EL2_ABORT_SAS_DWORD_VAL 3U
Soby Mathewb4c6df42022-11-09 11:13:29 +0000298
AlexeiFedorov537bee02023-02-02 13:38:23 +0000299#define ESR_EL2_ABORT_SSE_BIT (UL(1) << 21)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000300
301#define ESR_EL2_ABORT_SRT_SHIFT 16
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100302#define ESR_EL2_ABORT_SRT_WIDTH U(5)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000303
304#define ESR_EL2_ABORT_SET_SHIFT 11
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100305#define ESR_EL2_ABORT_SET_WIDTH U(2)
306#define ESR_EL2_ABORT_SET_UER INPLACE(ESR_EL2_ABORT_SET, UL(0))
307#define ESR_EL2_ABORT_SET_UC INPLACE(ESR_EL2_ABORT_SET, UL(2))
308#define ESR_EL2_ABORT_SET_UEO INPLACE(ESR_EL2_ABORT_SET, UL(3))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000309
AlexeiFedorov537bee02023-02-02 13:38:23 +0000310#define ESR_EL2_ABORT_SF_BIT (UL(1) << 15)
311#define ESR_EL2_ABORT_FNV_BIT (UL(1) << 10)
312#define ESR_EL2_ABORT_EA_BIT (UL(1) << 9)
313#define ESR_EL2_ABORT_S1PTW_BIT (UL(1) << 7)
314#define ESR_EL2_ABORT_WNR_BIT (UL(1) << 6)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000315#define ESR_EL2_ABORT_FSC_SHIFT 0
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100316#define ESR_EL2_ABORT_FSC_WIDTH U(6)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000317
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100318#define ESR_EL2_ABORT_FSC_TRANSLATION_FAULT UL(0x04)
319#define ESR_EL2_ABORT_FSC_PERMISSION_FAULT UL(0x0c)
320#define ESR_EL2_ABORT_FSC_TRANSLATION_FAULT_L0 UL(0x04)
321#define ESR_EL2_ABORT_FSC_SEA UL(0x10)
322#define ESR_EL2_ABORT_FSC_SEA_TTW_START UL(0x13)
323#define ESR_EL2_ABORT_FSC_SEA_TTW_END UL(0x17)
324#define ESR_EL2_ABORT_FSC_GPF UL(0x28)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000325#define ESR_EL2_ABORT_FSC_LEVEL_SHIFT 0
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100326#define ESR_EL2_ABORT_FSC_LEVEL_WIDTH U(2)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000327
328/* The ESR fields that are reported to the host on Instr./Data Synchronous Abort */
AlexeiFedorov537bee02023-02-02 13:38:23 +0000329#define ESR_NONEMULATED_ABORT_MASK ( \
330 MASK(ESR_EL2_EC) | \
331 MASK(ESR_EL2_ABORT_SET) | \
332 ESR_EL2_ABORT_FNV_BIT | \
333 ESR_EL2_ABORT_EA_BIT | \
334 MASK(ESR_EL2_ABORT_FSC))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000335
AlexeiFedorov537bee02023-02-02 13:38:23 +0000336#define ESR_EMULATED_ABORT_MASK ( \
Soby Mathewb4c6df42022-11-09 11:13:29 +0000337 ESR_NONEMULATED_ABORT_MASK | \
AlexeiFedorov537bee02023-02-02 13:38:23 +0000338 ESR_EL2_ABORT_ISV_BIT | \
339 MASK(ESR_EL2_ABORT_SAS) | \
340 ESR_EL2_ABORT_SF_BIT | \
Soby Mathewb4c6df42022-11-09 11:13:29 +0000341 ESR_EL2_ABORT_WNR_BIT)
342
343#define ESR_EL2_SERROR_DFSC_SHIFT 0
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100344#define ESR_EL2_SERROR_DFSC_WIDTH U(6)
345#define ESR_EL2_SERROR_DFSC_UNCAT INPLACE(ESR_EL2_SERROR_DFSC, UL(0))
346#define ESR_EL2_SERROR_DFSC_ASYNC INPLACE(ESR_EL2_SERROR_DFSC, UL(1))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000347
AlexeiFedorov537bee02023-02-02 13:38:23 +0000348#define ESR_EL2_SERROR_EA_BIT (UL(1) << 9)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000349
350#define ESR_EL2_SERROR_AET_SHIFT 10
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100351#define ESR_EL2_SERROR_AET_WIDTH U(3)
352#define ESR_EL2_SERROR_AET_UC INPLACE(ESR_EL2_SERROR_AET, UL(0))
353#define ESR_EL2_SERROR_AET_UEU INPLACE(ESR_EL2_SERROR_AET, UL(1))
354#define ESR_EL2_SERROR_AET_UEO INPLACE(ESR_EL2_SERROR_AET, UL(2))
355#define ESR_EL2_SERROR_AET_UER INPLACE(ESR_EL2_SERROR_AET, UL(3))
356#define ESR_EL2_SERROR_AET_CE INPLACE(ESR_EL2_SERROR_AET, UL(6))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000357
AlexeiFedorov537bee02023-02-02 13:38:23 +0000358#define ESR_EL2_SERROR_IESB_BIT (UL(1) << 13)
359#define ESR_EL2_SERROR_IDS_BIT (UL(1) << 24)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000360
361/* The ESR fields that are reported to the host on SError */
AlexeiFedorov537bee02023-02-02 13:38:23 +0000362#define ESR_SERROR_MASK ( \
363 ESR_EL2_SERROR_IDS_BIT | \
364 MASK(ESR_EL2_SERROR_AET) | \
365 ESR_EL2_SERROR_EA_BIT | \
366 MASK(ESR_EL2_SERROR_DFSC))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000367
368#define ESR_EL2_SYSREG_TRAP_OP0_SHIFT 20
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100369#define ESR_EL2_SYSREG_TRAP_OP0_WIDTH U(2)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000370
371#define ESR_EL2_SYSREG_TRAP_OP2_SHIFT 17
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100372#define ESR_EL2_SYSREG_TRAP_OP2_WIDTH U(3)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000373
374#define ESR_EL2_SYSREG_TRAP_OP1_SHIFT 14
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100375#define ESR_EL2_SYSREG_TRAP_OP1_WIDTH U(3)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000376
377#define ESR_EL2_SYSREG_TRAP_CRN_SHIFT 10
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100378#define ESR_EL2_SYSREG_TRAP_CRN_WIDTH U(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000379
380#define ESR_EL2_SYSREG_TRAP_RT_SHIFT 5
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100381#define ESR_EL2_SYSREG_TRAP_RT_WIDTH U(5)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000382
383#define ESR_EL2_SYSREG_TRAP_CRM_SHIFT 1
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100384#define ESR_EL2_SYSREG_TRAP_CRM_WIDTH U(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000385
386/* WFx ESR fields */
AlexeiFedorov537bee02023-02-02 13:38:23 +0000387#define ESR_EL2_WFx_TI_BIT (UL(1) << 0)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000388
389/* xVC ESR fields */
390#define ESR_EL2_xVC_IMM_SHIFT 0
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100391#define ESR_EL2_xVC_IMM_WIDTH U(16)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000392
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000393/* ID_AA64DFR0_EL1 definitions */
394#define ID_AA64DFR0_EL1_HPMN0_SHIFT UL(60)
395#define ID_AA64DFR0_EL1_HPMN0_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000396
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000397#define ID_AA64DFR0_EL1_ExtTrcBuff_SHIFT UL(56)
398#define ID_AA64DFR0_EL1_ExtTrcBuff_WIDTH UL(4)
399
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000400#define ID_AA64DFR0_EL1_BRBE_SHIFT UL(52)
401#define ID_AA64DFR0_EL1_BRBE_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000402
403#define ID_AA64DFR0_EL1_MTPMU_SHIFT UL(48)
404#define ID_AA64DFR0_EL1_MTPMU_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000405
406#define ID_AA64DFR0_EL1_TraceBuffer_SHIFT UL(44)
407#define ID_AA64DFR0_EL1_TraceBuffer_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000408
409#define ID_AA64DFR0_EL1_TraceFilt_SHIFT UL(40)
410#define ID_AA64DFR0_EL1_TraceFilt_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000411
412#define ID_AA64DFR0_EL1_DoubleLock_SHIFT UL(36)
413#define ID_AA64DFR0_EL1_DoubleLock_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000414
415#define ID_AA64DFR0_EL1_PMSVer_SHIFT UL(32)
416#define ID_AA64DFR0_EL1_PMSVer_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000417
418#define ID_AA64DFR0_EL1_CTX_CMPS_SHIFT UL(28)
419#define ID_AA64DFR0_EL1_CTX_CMPS_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000420
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000421#define ID_AA64DFR0_EL1_SEBEP_SHIFT UL(24)
422#define ID_AA64DFR0_EL1_SEBEP_WIDTH UL(4)
423
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000424#define ID_AA64DFR0_EL1_WRPs_SHIFT UL(20)
425#define ID_AA64DFR0_EL1_WRPs_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000426
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000427#define ID_AA64DFR0_EL1_PMSS_SHIFT UL(16)
428#define ID_AA64DFR0_EL1_PMSS_WIDTH UL(4)
429
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000430#define ID_AA64DFR0_EL1_BRPs_SHIFT UL(12)
431#define ID_AA64DFR0_EL1_BRPs_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000432
433#define ID_AA64DFR0_EL1_PMUVer_SHIFT UL(8)
434#define ID_AA64DFR0_EL1_PMUVer_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000435
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000436/* Performance Monitors Extension version */
437#define ID_AA64DFR0_EL1_PMUv3p7 UL(7)
438#define ID_AA64DFR0_EL1_PMUv3p8 UL(8)
439#define ID_AA64DFR0_EL1_PMUv3p9 UL(9)
440
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000441#define ID_AA64DFR0_EL1_TraceVer_SHIFT UL(4)
442#define ID_AA64DFR0_EL1_TraceVer_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000443
444#define ID_AA64DFR0_EL1_DebugVer_SHIFT UL(0)
445#define ID_AA64DFR0_EL1_DebugVer_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000446
447/* Debug architecture version */
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000448#define ID_AA64DFR0_EL1_Debugv8 UL(6)
449#define ID_AA64DFR0_EL1_DebugVHE UL(7)
450#define ID_AA64DFR0_EL1_Debugv8p2 UL(8)
451#define ID_AA64DFR0_EL1_Debugv8p4 UL(9)
452#define ID_AA64DFR0_EL1_Debugv8p8 UL(10)
453
454/* ID_AA64DFR1_EL1 definitions */
455#define ID_AA64DFR1_EL1_EBEP_SHIFT UL(48)
456#define ID_AA64DFR1_EL1_EBEP_WIDTH UL(4)
457
458#define ID_AA64DFR1_EL1_ICNTR_SHIFT UL(36)
459#define ID_AA64DFR1_EL1_ICNTR_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000460
Soby Mathewb4c6df42022-11-09 11:13:29 +0000461/* ID_AA64PFR0_EL1 definitions */
462#define ID_AA64PFR0_EL1_SVE_SHIFT UL(32)
463#define ID_AA64PFR0_EL1_SVE_WIDTH UL(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000464
465#define ID_AA64PFR0_EL1_AMU_SHIFT UL(44)
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100466#define ID_AA64PFR0_EL1_AMU_WIDTH UL(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000467
Arunachalam Ganapathya27de372023-03-06 11:13:49 +0000468/* ID_AA64PFR1_EL1 definitions */
469#define ID_AA64PFR1_EL1_MTE_SHIFT UL(8)
470#define ID_AA64PFR1_EL1_MTE_WIDTH UL(4)
471
Arunachalam Ganapathy83f46ca2023-08-15 18:13:27 +0100472#define ID_AA64PFR1_EL1_SME_SHIFT UL(24)
473#define ID_AA64PFR1_EL1_SME_WIDTH UL(4)
474#define ID_AA64PFR1_EL1_SME_NOT_IMPLEMENTED UL(0)
475#define ID_AA64PFR1_EL1_SME_IMPLEMENTED UL(1)
476#define ID_AA64PFR1_EL1_SME2_IMPLEMENTED UL(2)
477
Soby Mathewb4c6df42022-11-09 11:13:29 +0000478/* ID_AA64MMFR0_EL1 definitions */
479#define ID_AA64MMFR0_EL1_PARANGE_SHIFT U(0)
AlexeiFedorov537bee02023-02-02 13:38:23 +0000480#define ID_AA64MMFR0_EL1_PARANGE_WIDTH UL(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000481
482#define PARANGE_0000_WIDTH U(32)
483#define PARANGE_0001_WIDTH U(36)
484#define PARANGE_0010_WIDTH U(40)
485#define PARANGE_0011_WIDTH U(42)
486#define PARANGE_0100_WIDTH U(44)
487#define PARANGE_0101_WIDTH U(48)
488#define PARANGE_0110_WIDTH U(52)
489
AlexeiFedorov537bee02023-02-02 13:38:23 +0000490#define ID_AA64MMFR0_EL1_ECV_SHIFT UL(60)
491#define ID_AA64MMFR0_EL1_ECV_WIDTH UL(4)
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000492#define ID_AA64MMFR0_EL1_ECV_NOT_SUPPORTED UL(0x0)
493#define ID_AA64MMFR0_EL1_ECV_SUPPORTED UL(0x1)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000494#define ID_AA64MMFR0_EL1_ECV_SELF_SYNCH ULL(0x2)
495
AlexeiFedorov537bee02023-02-02 13:38:23 +0000496#define ID_AA64MMFR0_EL1_FGT_SHIFT UL(56)
497#define ID_AA64MMFR0_EL1_FGT_WIDTH UL(4)
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000498#define ID_AA64MMFR0_EL1_FGT_NOT_SUPPORTED UL(0x0)
499#define ID_AA64MMFR0_EL1_FGT_SUPPORTED UL(0x1)
500#define ID_AA64MMFR0_EL1_FGT2_SUPPORTED UL(0x2)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000501
502#define ID_AA64MMFR0_EL1_TGRAN4_2_SHIFT U(40)
AlexeiFedorov537bee02023-02-02 13:38:23 +0000503#define ID_AA64MMFR0_EL1_TGRAN4_2_WIDTH U(4)
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000504#define ID_AA64MMFR0_EL1_TGRAN4_2_TGRAN4 UL(0x0)
505#define ID_AA64MMFR0_EL1_TGRAN4_2_NOT_SUPPORTED UL(0x1)
506#define ID_AA64MMFR0_EL1_TGRAN4_2_SUPPORTED UL(0x2)
507#define ID_AA64MMFR0_EL1_TGRAN4_2_LPA2 UL(0x3)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000508
AlexeiFedorov537bee02023-02-02 13:38:23 +0000509#define ID_AA64MMFR0_EL1_TGRAN16_2_SHIFT UL(32)
510#define ID_AA64MMFR0_EL1_TGRAN16_2_WIDTH UL(4)
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000511#define ID_AA64MMFR0_EL1_TGRAN16_2_TGRAN16 UL(0x0)
512#define ID_AA64MMFR0_EL1_TGRAN16_2_NOT_SUPPORTED UL(0x1)
513#define ID_AA64MMFR0_EL1_TGRAN16_2_SUPPORTED UL(0x2)
514#define ID_AA64MMFR0_EL1_TGRAN16_2_LPA2 UL(0x3)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000515
AlexeiFedorov537bee02023-02-02 13:38:23 +0000516#define ID_AA64MMFR0_EL1_TGRAN4_SHIFT UL(28)
517#define ID_AA64MMFR0_EL1_TGRAN4_WIDTH UL(4)
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000518#define ID_AA64MMFR0_EL1_TGRAN4_SUPPORTED UL(0x0)
519#define ID_AA64MMFR0_EL1_TGRAN4_LPA2 UL(0x1)
520#define ID_AA64MMFR0_EL1_TGRAN4_NOT_SUPPORTED UL(0xf)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000521
522#define ID_AA64MMFR0_EL1_TGRAN64_SHIFT UL(24)
AlexeiFedorov537bee02023-02-02 13:38:23 +0000523#define ID_AA64MMFR0_EL1_TGRAN64_WIDTH UL(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000524#define ID_AA64MMFR0_EL1_TGRAN64_SUPPORTED UL(0x0)
525#define ID_AA64MMFR0_EL1_TGRAN64_NOT_SUPPORTED UL(0xf)
526
527#define ID_AA64MMFR0_EL1_TGRAN16_SHIFT UL(20)
AlexeiFedorov537bee02023-02-02 13:38:23 +0000528#define ID_AA64MMFR0_EL1_TGRAN16_WIDTH UL(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000529#define ID_AA64MMFR0_EL1_TGRAN16_NOT_SUPPORTED UL(0x0)
530#define ID_AA64MMFR0_EL1_TGRAN16_SUPPORTED UL(0x1)
531#define ID_AA64MMFR0_EL1_TGRAN16_LPA2 UL(0x2)
532
533/* RNDR definitions */
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000534#define ID_AA64ISAR0_EL1_RNDR_SHIFT UL(60)
535#define ID_AA64ISAR0_EL1_RNDR_WIDTH UL(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000536
537/* ID_AA64MMFR1_EL1 definitions */
538#define ID_AA64MMFR1_EL1_VMIDBits_SHIFT UL(4)
AlexeiFedorov537bee02023-02-02 13:38:23 +0000539#define ID_AA64MMFR1_EL1_VMIDBits_WIDTH UL(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000540#define ID_AA64MMFR1_EL1_VMIDBits_8 UL(0)
541#define ID_AA64MMFR1_EL1_VMIDBits_16 UL(2)
542
Arunachalam Ganapathyf6491212023-02-23 16:04:34 +0000543/* SVE Feature ID register 0 */
544#define ID_AA64ZFR0_EL1 S3_0_C0_C4_4
545
Arunachalam Ganapathy83f46ca2023-08-15 18:13:27 +0100546/* SME Feature ID register 0 */
547#define ID_AA64SMFR0_EL1 S3_0_C0_C4_5
548
Soby Mathewb4c6df42022-11-09 11:13:29 +0000549/* HPFAR_EL2 definitions */
550#define HPFAR_EL2_FIPA_SHIFT 4
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100551#define HPFAR_EL2_FIPA_WIDTH U(40)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000552#define HPFAR_EL2_FIPA_OFFSET 8
553
554/* SPSR definitions */
555#define SPSR_EL2_MODE_SHIFT 0
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100556#define SPSR_EL2_MODE_WIDTH U(4)
557#define SPSR_EL2_MODE_EL0t INPLACE(SPSR_EL2_MODE, UL(0))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000558
559#define SPSR_EL2_MODE_SHIFT 0
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100560#define SPSR_EL2_MODE_WIDTH U(4)
561#define SPSR_EL2_MODE_EL1h INPLACE(SPSR_EL2_MODE, UL(5))
562#define SPSR_EL2_MODE_EL1t INPLACE(SPSR_EL2_MODE, UL(4))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000563
564/* FIXME: DAIF definitions are redundant here. Might need unification. */
565#define SPSR_EL2_nRW_SHIFT 4
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100566#define SPSR_EL2_nRW_WIDTH U(1)
567#define SPSR_EL2_nRW_AARCH64 INPLACE(SPSR_EL2_nRW, UL(0))
568#define SPSR_EL2_nRW_AARCH32 INPLACE(SPSR_EL2_nRW, UL(1))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000569
AlexeiFedorov537bee02023-02-02 13:38:23 +0000570#define SPSR_EL2_DAIF_SHIFT 6
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100571#define SPSR_EL2_AIF_SHIFT U(6)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000572
AlexeiFedorov537bee02023-02-02 13:38:23 +0000573#define DAIF_FIQ_BIT (UL(1) << 0)
574#define DAIF_IRQ_BIT (UL(1) << 1)
575#define DAIF_ABT_BIT (UL(1) << 2)
576#define DAIF_DBG_BIT (UL(1) << 3)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000577
AlexeiFedorov537bee02023-02-02 13:38:23 +0000578#define SPSR_EL2_F_BIT (UL(1) << 6)
579#define SPSR_EL2_I_BIT (UL(1) << 7)
580#define SPSR_EL2_A_BIT (UL(1) << 8)
581#define SPSR_EL2_D_BIT (UL(1) << 9)
582#define SPSR_EL2_SSBS_BIT (UL(1) << 12)
583#define SPSR_EL2_ALLINT_BIT (UL(1) << 13)
584#define SPSR_EL2_IL_BIT (UL(1) << 20)
585#define SPSR_EL2_SS_BIT (UL(1) << 21)
586#define SPSR_EL2_PAN_BIT (UL(1) << 22)
587#define SPSR_EL2_UAO_BIT (UL(1) << 23)
588#define SPSR_EL2_DIT_BIT (UL(1) << 24)
589#define SPSR_EL2_TCO_BIT (UL(1) << 25)
590#define SPSR_EL2_V_BIT (UL(1) << 28)
591#define SPSR_EL2_C_BIT (UL(1) << 29)
592#define SPSR_EL2_Z_BIT (UL(1) << 30)
593#define SPSR_EL2_N_BIT (UL(1) << 31)
594#define SPSR_EL2_PM_BIT (UL(1) << 32)
595#define SPSR_EL2_PPEND_BIT (UL(1) << 33)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000596
Arunachalam Ganapathy4f601e72023-05-22 11:49:29 +0100597/* Floating point control and status register */
598#define FPCR S3_3_C4_C4_0
599#define FPSR S3_3_C4_C4_1
600
Arunachalam Ganapathyf6491212023-02-23 16:04:34 +0000601/* SVE Control Register */
602#define ZCR_EL2 S3_4_C1_C2_0
Arunachalam Ganapathy2b456582023-05-19 11:56:44 +0100603#define ZCR_EL2_LEN_SHIFT UL(0)
604#define ZCR_EL2_LEN_WIDTH UL(4)
Arunachalam Ganapathyf6491212023-02-23 16:04:34 +0000605
Arunachalam Ganapathy4f601e72023-05-22 11:49:29 +0100606#define ZCR_EL12 S3_5_C1_C2_0
607
Arunachalam Ganapathy83f46ca2023-08-15 18:13:27 +0100608/* SME Control Register */
609#define SMCR_EL2 S3_4_C1_C2_6
610#define SMCR_EL2_LEN_SHIFT UL(0)
611#define SMCR_EL2_LEN_WIDTH UL(4)
612/*
613 * SMCR_EL2_RAZ_LEN is defined to find the architecturally permitted SVL. This
614 * is a combination of RAZ and LEN bit fields.
615 */
616#define SMCR_EL2_RAZ_LEN_SHIFT UL(0)
617#define SMCR_EL2_RAZ_LEN_WIDTH UL(9)
618#define SMCR_EL2_EZT0_BIT (UL(1) << 30)
619#define SMCR_EL2_FA64_BIT (UL(1) << 31)
620
621/* Streaming Vector Control register */
622#define SVCR S3_3_C4_C2_2
623#define SVCR_SM_BIT (UL(1) << 0)
624#define SVCR_ZA_BIT (UL(1) << 1)
625
Soby Mathewb4c6df42022-11-09 11:13:29 +0000626/* VTCR definitions */
627#define VTCR_T0SZ_SHIFT 0
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100628#define VTCR_T0SZ_WIDTH U(6)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000629
630#define VTCR_SL0_SHIFT 6
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100631#define VTCR_SL0_WIDTH U(2)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000632
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100633#define VTCR_SL0_4K_L2 INPLACE(VTCR_SL0, UL(0))
634#define VTCR_SL0_4K_L1 INPLACE(VTCR_SL0, UL(1))
635#define VTCR_SL0_4K_L0 INPLACE(VTCR_SL0, UL(2))
636#define VTCR_SL0_4K_L3 INPLACE(VTCR_SL0, UL(3))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000637
638#define VTCR_IRGN0_SHIFT 8
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100639#define VTCR_IRGN0_WIDTH U(2)
640#define VTCR_IRGN0_WBRAWA INPLACE(VTCR_IRGN0, UL(1))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000641
642#define VTCR_ORGN0_SHIFT 10
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100643#define VTCR_ORGN0_WIDTH U(2)
644#define VTCR_ORGN0_WBRAWA INPLACE(VTCR_ORGN0, UL(1))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000645
646#define VTCR_SH0_SHIFT 12
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100647#define VTCR_SH0_WIDTH U(2)
648#define VTCR_SH0_IS INPLACE(VTCR_SH0, UL(3))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000649
650#define VTCR_TG0_SHIFT 14
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100651#define VTCR_TG0_WIDTH U(2)
652#define VTCR_TG0_4K INPLACE(VTCR_TG0, UL(0))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000653
654#define VTCR_PS_SHIFT 16
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100655#define VTCR_PS_WIDTH U(3)
656#define VTCR_PS_40 INPLACE(VTCR_PS, UL(2))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000657
658#define VTCR_VS (UL(1) << 19)
659#define VTCR_NSA (UL(1) << 30)
660#define VTCR_RES1 (UL(1) << 31)
661
662#define VTCR_FLAGS ( \
663 VTCR_IRGN0_WBRAWA | /* PTW inner cache attr. is WB RAWA*/ \
664 VTCR_ORGN0_WBRAWA | /* PTW outer cache attr. is WB RAWA*/ \
665 VTCR_SH0_IS | /* PTW shareability attr. is Outer Sharable*/\
666 VTCR_TG0_4K | /* 4K granule size in non-secure PT*/ \
667 VTCR_PS_40 | /* size(PA) = 40 */ \
668 /* VS = 0 size(VMID) = 8 */ \
669 /* NSW = 0 non-secure s2 is made of secure pages*/ \
670 VTCR_NSA | /* non-secure IPA maps to non-secure PA */ \
671 VTCR_RES1 \
672 )
673
674
Soby Mathewb4c6df42022-11-09 11:13:29 +0000675/* PMCR_EL0 Definitions */
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000676#define PMCR_EL0_N_SHIFT 11
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100677#define PMCR_EL0_N_WIDTH U(5)
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000678#define PMCR_EL0_LC_BIT (UL(1) << 6)
679#define PMCR_EL0_DP_BIT (UL(1) << 5)
680#define PMCR_EL0_C_BIT (UL(1) << 2)
681#define PMCR_EL0_P_BIT (UL(1) << 1)
682#define PMCR_EL0_E_BIT (UL(1) << 0)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000683
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000684#define PMCR_EL0_INIT (PMCR_EL0_LC_BIT | PMCR_EL0_DP_BIT)
685#define PMCR_EL0_INIT_RESET (PMCR_EL0_INIT | PMCR_EL0_C_BIT | \
686 PMCR_EL0_P_BIT)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000687
688/* MDSCR_EL1 Definitions */
AlexeiFedorov537bee02023-02-02 13:38:23 +0000689#define MDSCR_EL1_TDCC_BIT (UL(1) << 12)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000690
691/* SCTLR register definitions */
Arvind Ram Prakashbd36a1b2022-12-15 12:16:36 -0600692#define SCTLR_ELx_RES1_BIT ((UL(1) << 22) /* TODO: ARMv8.5-CSEH, otherwise RES1 */ | \
693 (UL(1) << 11) /* TODO: ARMv8.5-CSEH, otherwise RES1 */)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000694
Arvind Ram Prakashbd36a1b2022-12-15 12:16:36 -0600695#define SCTLR_ELx_M_BIT (UL(1) << 0)
696#define SCTLR_ELx_C_BIT (UL(1) << 2)
697#define SCTLR_ELx_SA_BIT (UL(1) << 3)
698#define SCTLR_ELx_SA0_BIT (UL(1) << 4)
699#define SCTLR_ELx_CP15BEN_BIT (UL(1) << 5)
700#define SCTLR_ELx_nAA_BIT (UL(1) << 6)
701#define SCTLR_ELx_SED_BIT (UL(1) << 8)
702#define SCTLR_ELx_EOS_BIT (UL(1) << 11)
703#define SCTLR_ELx_I_BIT (UL(1) << 12)
704#define SCTLR_ELx_DZE_BIT (UL(1) << 14)
705#define SCTLR_ELx_UCT_BIT (UL(1) << 15)
706#define SCTLR_ELx_nTWI_BIT (UL(1) << 16)
707#define SCTLR_ELx_nTWE_BIT (UL(1) << 18)
708#define SCTLR_ELx_WXN_BIT (UL(1) << 19)
709#define SCTLR_ELx_TSCXT_BIT (UL(1) << 20)
710#define SCTLR_ELx_EIS_BIT (UL(1) << 22)
711#define SCTLR_ELx_SPAN_BIT (UL(1) << 23)
712#define SCTLR_ELx_EE_BIT (UL(1) << 25)
713#define SCTLR_ELx_UCI_BIT (UL(1) << 26)
714#define SCTLR_ELx_nTLSMD_BIT (UL(1) << 28)
715#define SCTLR_ELx_LSMAOE_BIT (UL(1) << 29)
716#define SCTLR_ELx_EnIA_BIT (UL(1) << 31)
Shruti Guptaa4cb2a22023-05-23 14:55:49 +0100717#define SCTLR_ELx_BT0_BIT (UL(1) << 35)
718#define SCTLR_ELx_BT1_BIT (UL(1) << 36)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000719
Arvind Ram Prakashbd36a1b2022-12-15 12:16:36 -0600720#define SCTLR_EL1_FLAGS (SCTLR_ELx_SPAN_BIT | SCTLR_ELx_EIS_BIT | SCTLR_ELx_nTWE_BIT | \
721 SCTLR_ELx_nTWI_BIT | SCTLR_ELx_EOS_BIT | SCTLR_ELx_nAA_BIT | \
722 SCTLR_ELx_CP15BEN_BIT | SCTLR_ELx_SA0_BIT | SCTLR_ELx_SA_BIT)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000723
Arvind Ram Prakashbd36a1b2022-12-15 12:16:36 -0600724#define SCTLR_EL2_INIT (SCTLR_ELx_C_BIT /* Data accesses are cacheable
725 * as per translation tables */ | \
726 /* SCTLR_EL2_M = 0 (MMU disabled) */ \
727 /* SCTLR_EL2_A = 0
728 * (No alignment checks) */ \
729 SCTLR_ELx_SA_BIT /* SP aligned at EL2 */ | \
730 SCTLR_ELx_SA0_BIT /* SP Alignment check enable for EL0 */ \
731 /* SCTLR_EL2_CP15BEN = 0 (EL0 using AArch32:
732 * EL0 execution of the CP15DMB, CP15DSB,
733 * and CP15ISB instructions is
734 * UNDEFINED. */ \
735 /* SCTLR_EL2_NAA = 0 (unaligned MA fault
736 * at EL2 and EL0) */ \
737 /* SCTLR_EL2_ITD = 0 (A32 Only) */ | \
738 SCTLR_ELx_SED_BIT /* A32 Only, RES1 for non-A32 systems */ \
739 /* SCTLR_EL2_EOS TODO: ARMv8.5-CSEH,
740 * otherwise RES1 */ | \
741 SCTLR_ELx_I_BIT /* I$ is ON for EL2 and EL0 */ | \
742 SCTLR_ELx_DZE_BIT /* Do not trap DC ZVA */ | \
743 SCTLR_ELx_UCT_BIT /* Allow EL0 access to CTR_EL0 */ | \
744 SCTLR_ELx_nTWI_BIT /* Don't trap WFI from EL0 to EL2 */ | \
745 SCTLR_ELx_nTWE_BIT /* Don't trap WFE from EL0 to EL2 */ | \
746 SCTLR_ELx_WXN_BIT /* W implies XN */ | \
747 SCTLR_ELx_TSCXT_BIT /* Trap EL0 accesss to SCXTNUM_EL0 */ | \
748 /* SCTLR_EL2_EIS EL2 exception is context
749 * synchronizing
750 */ \
751 SCTLR_ELx_RES1_BIT | \
752 /* SCTLR_EL2_SPAN = 0 (Set PSTATE.PAN = 1 on
753 * exceptions to EL2)) */ \
754 SCTLR_ELx_UCI_BIT /* Allow cache maintenance
755 * instructions at EL0 */ | \
756 SCTLR_ELx_nTLSMD_BIT /* A32/T32 only */ | \
757 SCTLR_ELx_LSMAOE_BIT /* A32/T32 only */)
758
759#define SCTLR_EL2_RUNTIME (SCTLR_EL2_INIT | \
760 SCTLR_ELx_M_BIT /* MMU enabled */)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000761
Arunachalam Ganapathy9ade18b2023-06-12 14:07:21 +0100762/* RMM sets HCR_EL2.E2H to 1. CPTR_EL2 definitions when HCR_EL2.E2H == 1 */
763#define CPTR_EL2_VHE_TTA (UL(1) << 28)
764#define CPTR_EL2_VHE_TAM (UL(1) << 30)
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100765
Arunachalam Ganapathy9ade18b2023-06-12 14:07:21 +0100766#define CPTR_EL2_VHE_FPEN_SHIFT UL(20)
767#define CPTR_EL2_VHE_FPEN_WIDTH UL(2)
768#define CPTR_EL2_VHE_FPEN_TRAP_ALL_00 UL(0)
769#define CPTR_EL2_VHE_FPEN_TRAP_TGE_01 UL(1)
770#define CPTR_EL2_VHE_FPEN_TRAP_ALL_10 UL(2)
771#define CPTR_EL2_VHE_FPEN_NO_TRAP_11 UL(3)
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100772
Arunachalam Ganapathy9ade18b2023-06-12 14:07:21 +0100773#define CPTR_EL2_VHE_ZEN_SHIFT UL(16)
774#define CPTR_EL2_VHE_ZEN_WIDTH UL(2)
775#define CPTR_EL2_VHE_ZEN_TRAP_ALL_00 UL(0x0)
776#define CPTR_EL2_VHE_ZEN_NO_TRAP_11 UL(0x3)
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100777
Arunachalam Ganapathy83f46ca2023-08-15 18:13:27 +0100778#define CPTR_EL2_VHE_SMEN_SHIFT UL(24)
779#define CPTR_EL2_VHE_SMEN_WIDTH UL(2)
780#define CPTR_EL2_VHE_SMEN_TRAP_ALL_00 UL(0x0)
781#define CPTR_EL2_VHE_SMEN_NO_TRAP_11 UL(0x3)
782
783/* Trap all AMU, trace, FPU, SVE, SME accesses */
Arunachalam Ganapathy9ade18b2023-06-12 14:07:21 +0100784#define CPTR_EL2_VHE_INIT ((CPTR_EL2_VHE_ZEN_TRAP_ALL_00 << \
785 CPTR_EL2_VHE_ZEN_SHIFT) | \
Arunachalam Ganapathy83f46ca2023-08-15 18:13:27 +0100786 (CPTR_EL2_VHE_SMEN_TRAP_ALL_00 << \
787 CPTR_EL2_VHE_SMEN_SHIFT) | \
Arunachalam Ganapathy9ade18b2023-06-12 14:07:21 +0100788 (CPTR_EL2_VHE_FPEN_TRAP_ALL_00 << \
789 CPTR_EL2_VHE_FPEN_SHIFT) | \
790 CPTR_EL2_VHE_TTA | \
791 CPTR_EL2_VHE_TAM)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000792
793/* MDCR_EL2 definitions */
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000794#define MDCR_EL2_HPMFZS (UL(1) << 36)
795#define MDCR_EL2_HPMFZO (UL(1) << 29)
796#define MDCR_EL2_MTPME (UL(1) << 28)
797#define MDCR_EL2_TDCC (UL(1) << 27)
AlexeiFedorov537bee02023-02-02 13:38:23 +0000798#define MDCR_EL2_HLP (UL(1) << 26)
799#define MDCR_EL2_HCCD (UL(1) << 23)
800#define MDCR_EL2_TTRF (UL(1) << 19)
801#define MDCR_EL2_HPMD (UL(1) << 17)
802#define MDCR_EL2_TPMS (UL(1) << 14)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000803#define MDCR_EL2_E2PB(x) ((x) << 12)
AlexeiFedorov537bee02023-02-02 13:38:23 +0000804#define MDCR_EL2_E2PB_EL1 UL(3)
805#define MDCR_EL2_TDRA_BIT (UL(1) << 11)
806#define MDCR_EL2_TDOSA_BIT (UL(1) << 10)
807#define MDCR_EL2_TDA_BIT (UL(1) << 9)
808#define MDCR_EL2_TDE_BIT (UL(1) << 8)
809#define MDCR_EL2_HPME_BIT (UL(1) << 7)
810#define MDCR_EL2_TPM_BIT (UL(1) << 6)
811#define MDCR_EL2_TPMCR_BIT (UL(1) << 5)
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000812
813#define MDCR_EL2_HPMN_SHIFT UL(0)
814#define MDCR_EL2_HPMN_WIDTH UL(5)
815
816#define MDCR_EL2_INIT (MDCR_EL2_MTPME | \
817 MDCR_EL2_HCCD | \
818 MDCR_EL2_HPMD | \
819 MDCR_EL2_TDA_BIT | \
820 MDCR_EL2_TPM_BIT | \
821 MDCR_EL2_TPMCR_BIT)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000822
Arvind Ram Prakashbd36a1b2022-12-15 12:16:36 -0600823/* Armv8.3 Pointer Authentication Registers */
824#define APIAKeyLo_EL1 S3_0_C2_C1_0
825#define APIAKeyHi_EL1 S3_0_C2_C1_1
826#define APIBKeyLo_EL1 S3_0_C2_C1_2
827#define APIBKeyHi_EL1 S3_0_C2_C1_3
828#define APDAKeyLo_EL1 S3_0_C2_C2_0
829#define APDAKeyHi_EL1 S3_0_C2_C2_1
830#define APDBKeyLo_EL1 S3_0_C2_C2_2
831#define APDBKeyHi_EL1 S3_0_C2_C2_3
832#define APGAKeyLo_EL1 S3_0_C2_C3_0
833#define APGAKeyHi_EL1 S3_0_C2_C3_1
834
Soby Mathewb4c6df42022-11-09 11:13:29 +0000835/* MPIDR definitions */
836#define MPIDR_EL1_AFF_MASK 0xFF
837#define MPIDR_EL1_AFF0_SHIFT 0
838#define MPIDR_EL1_AFF1_SHIFT 8
839#define MPIDR_EL1_AFF2_SHIFT 16
840#define MPIDR_EL1_AFF3_SHIFT 32
841#define MPIDR_EL1_MT_MASK (UL(1) << 24)
842#define MPIDR_EL1_AFFINITY_BITS 8
843
844#define MPIDR_EL1_AFF0 INPLACE(MPIDR_EL1_AFF0, MPIDR_EL1_AFF_MASK)
845#define MPIDR_EL1_AFF1 INPLACE(MPIDR_EL1_AFF1, MPIDR_EL1_AFF_MASK)
846#define MPIDR_EL1_AFF2 INPLACE(MPIDR_EL1_AFF2, MPIDR_EL1_AFF_MASK)
847#define MPIDR_EL1_AFF3 INPLACE(MPIDR_EL1_AFF3, MPIDR_EL1_AFF_MASK)
848
849/*
850 * RmiRecMpidr type definitions.
851 *
852 * 'MPIDR_EL2_AFF<n>_VAL_SHIFT' constants specify the right shift
853 * for affinity field <n> that gives the field's actual value.
854 *
855 * Aff0[3:0] - Affinity level 0
856 * For compatibility with GICv3 only Aff0[3:0] field is used,
857 * and Aff0[7:4] of a REC MPIDR value is RES0.
858 */
859#define MPIDR_EL2_AFF0_SHIFT 0
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100860#define MPIDR_EL2_AFF0_WIDTH U(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000861#define MPIDR_EL2_AFF0_VAL_SHIFT 0
862
863/* Aff1[15:8] - Affinity level 1 */
864#define MPIDR_EL2_AFF1_SHIFT 8
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100865#define MPIDR_EL2_AFF1_WIDTH U(8)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000866#define MPIDR_EL2_AFF1_VAL_SHIFT 4
867
868/* Aff2[23:16] - Affinity level 2 */
869#define MPIDR_EL2_AFF2_SHIFT 16
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100870#define MPIDR_EL2_AFF2_WIDTH U(8)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000871#define MPIDR_EL2_AFF2_VAL_SHIFT 4
872
873/* Aff3[39:32] - Affinity level 3 */
874#define MPIDR_EL2_AFF3_SHIFT 32
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100875#define MPIDR_EL2_AFF3_WIDTH U(8)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000876#define MPIDR_EL2_AFF3_VAL_SHIFT 12
877
878/*
879 * Extract the value of Aff<n> register field shifted right
880 * so it can be evaluated directly.
881 */
AlexeiFedorov537bee02023-02-02 13:38:23 +0000882#define MPIDR_EL2_AFF(n, reg) \
Soby Mathewb4c6df42022-11-09 11:13:29 +0000883 (((reg) & MASK(MPIDR_EL2_AFF##n)) >> MPIDR_EL2_AFF##n##_VAL_SHIFT)
884
885/* VMPIDR_EL2 bit [31] = RES1 */
886#define VMPIDR_EL2_RES1 (UL(1) << 31)
887
888/* ICC_SRE_EL2 defintions */
889#define ICC_SRE_EL2_ENABLE (UL(1) << 3) /* Enable lower EL access to ICC_SRE_EL1 */
890#define ICC_SRE_EL2_DIB (UL(1) << 2) /* Disable IRQ bypass */
891#define ICC_SRE_EL2_DFB (UL(1) << 1) /* Disable FIQ bypass */
892#define ICC_SRE_EL2_SRE (UL(1) << 0) /* Enable sysreg access */
893
AlexeiFedorov537bee02023-02-02 13:38:23 +0000894#define ICC_SRE_EL2_INIT (ICC_SRE_EL2_ENABLE | ICC_SRE_EL2_DIB | \
Soby Mathewb4c6df42022-11-09 11:13:29 +0000895 ICC_SRE_EL2_DFB | ICC_SRE_EL2_SRE)
896
897/* MPAM definitions */
898#define MPAM2_EL2_INIT 0x0
899#define MPAMHCR_EL2_INIT 0x0
900
901#define PMSCR_EL2_INIT 0x0
902
903#define SYSREG_ESR(op0, op1, crn, crm, op2) \
AlexeiFedorov13b86dd2023-08-29 10:38:09 +0100904 ((UL(op0) << ESR_EL2_SYSREG_TRAP_OP0_SHIFT) | \
905 (UL(op1) << ESR_EL2_SYSREG_TRAP_OP1_SHIFT) | \
906 (UL(crn) << ESR_EL2_SYSREG_TRAP_CRN_SHIFT) | \
907 (UL(crm) << ESR_EL2_SYSREG_TRAP_CRM_SHIFT) | \
908 (UL(op2) << ESR_EL2_SYSREG_TRAP_OP2_SHIFT))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000909
910#define ESR_EL2_SYSREG_MASK SYSREG_ESR(3, 7, 15, 15, 7)
911
912#define ESR_EL2_SYSREG_ID_MASK SYSREG_ESR(3, 7, 15, 0, 0)
913#define ESR_EL2_SYSREG_ID SYSREG_ESR(3, 0, 0, 0, 0)
914
915#define ESR_EL2_SYSREG_ID_AA64PFR0_EL1 SYSREG_ESR(3, 0, 0, 4, 0)
916#define ESR_EL2_SYSREG_ID_AA64PFR1_EL1 SYSREG_ESR(3, 0, 0, 4, 1)
917#define ESR_EL2_SYSREG_ID_AA64ZFR0_EL1 SYSREG_ESR(3, 0, 0, 4, 4)
Arunachalam Ganapathy83f46ca2023-08-15 18:13:27 +0100918#define ESR_EL2_SYSREG_ID_AA64SMFR0_EL1 SYSREG_ESR(3, 0, 0, 4, 5)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000919
920#define ESR_EL2_SYSREG_ID_AA64DFR0_EL1 SYSREG_ESR(3, 0, 0, 5, 0)
921#define ESR_EL2_SYSREG_ID_AA64DFR1_EL1 SYSREG_ESR(3, 0, 0, 5, 1)
922
923#define ESR_EL2_SYSREG_ID_AA64AFR0_EL1 SYSREG_ESR(3, 0, 0, 5, 4)
924#define ESR_EL2_SYSREG_ID_AA64AFR1_EL1 SYSREG_ESR(3, 0, 0, 5, 5)
925
926#define ESR_EL2_SYSREG_ID_AA64ISAR0_EL1 SYSREG_ESR(3, 0, 0, 6, 0)
927#define ESR_EL2_SYSREG_ID_AA64ISAR1_EL1 SYSREG_ESR(3, 0, 0, 6, 1)
928
929#define ESR_EL2_SYSREG_ID_AA64MMFR0_EL1 SYSREG_ESR(3, 0, 0, 7, 0)
930#define ESR_EL2_SYSREG_ID_AA64MMFR1_EL1 SYSREG_ESR(3, 0, 0, 7, 1)
931#define ESR_EL2_SYSREG_ID_AA64MMFR2_EL1 SYSREG_ESR(3, 0, 0, 7, 2)
932
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000933/* ID_AA64ISAR1_EL1 definitions */
934#define ID_AA64ISAR1_EL1_GPI_SHIFT UL(28)
935#define ID_AA64ISAR1_EL1_GPI_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000936
937#define ID_AA64ISAR1_EL1_GPA_SHIFT UL(24)
938#define ID_AA64ISAR1_EL1_GPA_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000939
940#define ID_AA64ISAR1_EL1_API_SHIFT UL(8)
941#define ID_AA64ISAR1_EL1_API_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000942
943#define ID_AA64ISAR1_EL1_APA_SHIFT UL(4)
944#define ID_AA64ISAR1_EL1_APA_WIDTH UL(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000945
946#define ESR_EL2_SYSREG_TIMERS_MASK SYSREG_ESR(3, 3, 15, 12, 0)
947#define ESR_EL2_SYSREG_TIMERS SYSREG_ESR(3, 3, 14, 0, 0)
948
949#define ESR_EL2_SYSREG_TIMER_CNTP_TVAL_EL0 SYSREG_ESR(3, 3, 14, 2, 0)
950#define ESR_EL2_SYSREG_TIMER_CNTP_CTL_EL0 SYSREG_ESR(3, 3, 14, 2, 1)
951#define ESR_EL2_SYSREG_TIMER_CNTP_CVAL_EL0 SYSREG_ESR(3, 3, 14, 2, 2)
952#define ESR_EL2_SYSREG_TIMER_CNTV_TVAL_EL0 SYSREG_ESR(3, 3, 14, 3, 0)
953#define ESR_EL2_SYSREG_TIMER_CNTV_CTL_EL0 SYSREG_ESR(3, 3, 14, 3, 1)
954#define ESR_EL2_SYSREG_TIMER_CNTV_CVAL_EL0 SYSREG_ESR(3, 3, 14, 3, 2)
955
956#define ESR_EL2_SYSREG_ICC_PMR_EL1 SYSREG_ESR(3, 0, 4, 6, 0)
957
958/*
959 * GIC system registers encoding mask for registers from
960 * ICC_IAR0_EL1(3, 0, 12, 8, 0) to ICC_IGRPEN1_EL1(3, 0, 12, 12, 7).
961 */
962#define ESR_EL2_SYSREG_ICC_EL1_MASK SYSREG_ESR(3, 3, 15, 8, 0)
963#define ESR_EL2_SYSREG_ICC_EL1 SYSREG_ESR(3, 0, 12, 8, 0)
964
965#define ESR_EL2_SYSREG_ICC_DIR SYSREG_ESR(3, 0, 12, 11, 1)
966#define ESR_EL2_SYSREG_ICC_SGI1R_EL1 SYSREG_ESR(3, 0, 12, 11, 5)
967#define ESR_EL2_SYSREG_ICC_SGI0R_EL1 SYSREG_ESR(3, 0, 12, 11, 7)
968
969#define ESR_EL2_SYSREG_DIRECTION (UL(1) << 0)
AlexeiFedorov13b86dd2023-08-29 10:38:09 +0100970#define ESR_EL2_SYSREG_IS_WRITE(esr) (((esr) & ESR_EL2_SYSREG_DIRECTION) == 0UL)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000971
AlexeiFedorov537bee02023-02-02 13:38:23 +0000972#define ESR_IL(esr) ((esr) & MASK(ESR_EL2_IL))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000973
AlexeiFedorovfeaef162022-12-23 16:59:51 +0000974#define ESR_EL2_SYSREG_ISS_RT(esr) EXTRACT(ESR_EL2_SYSREG_TRAP_RT, esr)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000975
AlexeiFedorov93f5ec52023-08-31 14:26:53 +0100976#define ICC_HPPIR1_EL1_INTID_SHIFT UL(0)
977#define ICC_HPPIR1_EL1_INTID_WIDTH UL(24)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000978
979#define CNTHCTL_EL2_EL0PCTEN (UL(1) << UL(0))
980#define CNTHCTL_EL2_EL0VCTEN (UL(1) << UL(1))
981#define CNTHCTL_EL2_EL1PCTEN (UL(1) << 10)
982#define CNTHCTL_EL2_EL1PTEN (UL(1) << 11)
983#define CNTHCTL_EL2_EL1TVT (UL(1) << 13)
984#define CNTHCTL_EL2_EL1TVCT (UL(1) << 14)
985#define CNTHCTL_EL2_CNTVMASK (UL(1) << 18)
986#define CNTHCTL_EL2_CNTPMASK (UL(1) << 19)
987
988#define CNTHCTL_EL2_INIT (CNTHCTL_EL2_EL0VCTEN | CNTHCTL_EL2_EL0PCTEN)
989
990#define CNTHCTL_EL2_NO_TRAPS (CNTHCTL_EL2_EL1PCTEN | \
991 CNTHCTL_EL2_EL1PTEN)
992
993#define CNTx_CTL_ENABLE (UL(1) << 0)
994#define CNTx_CTL_IMASK (UL(1) << 1)
995#define CNTx_CTL_ISTATUS (UL(1) << 2)
996
997/*******************************************************************************
998 * Definitions of register offsets, fields and macros for CPU system
999 * instructions.
1000 ******************************************************************************/
1001
1002#define TLBI_ADDR_SHIFT U(12)
1003#define TLBI_ADDR_MASK U(0x0FFFFFFFFFFF)
1004#define TLBI_ADDR(x) (((x) >> TLBI_ADDR_SHIFT) & TLBI_ADDR_MASK)
1005
1006/* ID_AA64MMFR2_EL1 definitions */
AlexeiFedorov537bee02023-02-02 13:38:23 +00001007#define ID_AA64MMFR2_EL1_ST_SHIFT UL(28)
1008#define ID_AA64MMFR2_EL1_ST_WIDTH UL(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +00001009
AlexeiFedorov537bee02023-02-02 13:38:23 +00001010#define ID_AA64MMFR2_EL1_CNP_SHIFT UL(0)
1011#define ID_AA64MMFR2_EL1_CNP_WIDTH UL(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +00001012
1013/* Custom defined values to indicate the vector offset to exception handlers */
1014#define ARM_EXCEPTION_SYNC_LEL 0
1015#define ARM_EXCEPTION_IRQ_LEL 1
1016#define ARM_EXCEPTION_FIQ_LEL 2
1017#define ARM_EXCEPTION_SERROR_LEL 3
1018
AlexeiFedorov537bee02023-02-02 13:38:23 +00001019#define VBAR_CEL_SP_EL0_OFFSET 0x0
1020#define VBAR_CEL_SP_ELx_OFFSET 0x200
1021#define VBAR_LEL_AA64_OFFSET 0x400
1022#define VBAR_LEL_AA32_OFFSET 0x600
Soby Mathewb4c6df42022-11-09 11:13:29 +00001023
1024#endif /* ARCH_H */