blob: 131c4116dac5f21b265b9d1f839748e85ebc76e8 [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)
119#define TCR_EL2_TG1_4K INPLACE(TCR_EL2_TG1, UL(0))
120
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))
129
130#define ADDR_MASK_48_TO_63 ULL(0xFFFF000000000000)
131#define ADDR_MASK_44_TO_47 ULL(0x0000F00000000000)
132#define ADDR_MASK_42_TO_43 ULL(0x00000C0000000000)
133#define ADDR_MASK_40_TO_41 ULL(0x0000030000000000)
134#define ADDR_MASK_36_TO_39 ULL(0x000000F000000000)
135#define ADDR_MASK_32_TO_35 ULL(0x0000000F00000000)
136
137#define TCR_EL2_AS (UL(1) << 36)
138#define TCR_EL2_HPD0 (UL(1) << 41)
139#define TCR_EL2_HPD1 (UL(1) << 42)
140#define TCR_EL2_E0PD1 (UL(1) << 56) /* TODO: ARMv8.5-E0PD, otherwise RES0 */
141
142#define TCR_TxSZ_MIN UL(16)
143#define TCR_TxSZ_MAX UL(39)
144#define TCR_TxSZ_MAX_TTST UL(48)
145
146/* HCR definitions */
147#define HCR_FWB (UL(1) << 46)
148#define HCR_TEA (UL(1) << 37)
149#define HCR_API (UL(1) << 41)
150#define HCR_APK (UL(1) << 40)
151#define HCR_TERR (UL(1) << 36)
152#define HCR_TLOR (UL(1) << 35)
153#define HCR_E2H (UL(1) << 34)
154#define HCR_RW (UL(1) << 31)
155#define HCR_TGE (UL(1) << 27)
156#define HCR_TSW (UL(1) << 22)
157#define HCR_TACR (UL(1) << 21)
158#define HCR_TIDCP (UL(1) << 20)
159#define HCR_TSC (UL(1) << 19)
160#define HCR_TID3 (UL(1) << 18)
161#define HCR_TWE (UL(1) << 14)
162#define HCR_TWI (UL(1) << 13)
163#define HCR_VSE (UL(1) << 8)
164
165#define HCR_BSU_SHIFT 10
166#define HCR_BSU_WIDTH 2
167#define HCR_BSU_IS INPLACE(HCR_BSU, 1) /* Barriers are promoted to IS */
168
169#define HCR_FB (UL(1) << 9)
170#define HCR_VI (UL(1) << 7)
171#define HCR_AMO (UL(1) << 5)
172#define HCR_IMO (UL(1) << 4)
173#define HCR_FMO (UL(1) << 3)
174#define HCR_PTW (UL(1) << 2)
175#define HCR_SWIO (UL(1) << 1)
176#define HCR_VM (UL(1) << 0)
177
178/* TODO verify that all the traps are enabled */
179#define HCR_FLAGS (HCR_FWB | HCR_E2H | HCR_RW | HCR_TSC | HCR_AMO | \
180 HCR_BSU_IS | HCR_IMO | HCR_FMO | HCR_PTW | HCR_SWIO | HCR_VM | \
181 HCR_TID3 | HCR_TEA)
182
183#define HCR_EL2_INIT (HCR_TGE | HCR_E2H | HCR_TEA)
184
185#define MAIR_ELx_ATTR0_SHIFT 0
186#define MAIR_ELx_ATTR0_WIDTH 8
Soby Mathewb4c6df42022-11-09 11:13:29 +0000187
188/*******************************************************************************
189 * Definitions of MAIR encodings for device and normal memory
190 ******************************************************************************/
191/*
192 * MAIR encodings for device memory attributes.
193 */
194#define MAIR_DEV_NGNRNE UL(0x0) /* Device nGnRnE */
195#define MAIR_DEV_NGNRNE_IDX 0x1
196
197#define MAIR_DEV_NGNRE UL(0x4)
198
199#define MAIR_NIOWBNTRW 0xff
200#define MAIR_NIOWBNTRW_IDX 0x0
201
202/*
203 * MAIR encodings for normal memory attributes.
204 *
205 * Cache Policy
206 * WT: Write Through
207 * WB: Write Back
208 * NC: Non-Cacheable
209 *
210 * Transient Hint
211 * NTR: Non-Transient
212 * TR: Transient
213 *
214 * Allocation Policy
215 * RA: Read Allocate
216 * WA: Write Allocate
217 * RWA: Read and Write Allocate
218 * NA: No Allocation
219 */
220#define MAIR_NORM_WT_TR_WA UL(0x1)
221#define MAIR_NORM_WT_TR_RA UL(0x2)
222#define MAIR_NORM_WT_TR_RWA UL(0x3)
223#define MAIR_NORM_NC UL(0x4)
224#define MAIR_NORM_WB_TR_WA UL(0x5)
225#define MAIR_NORM_WB_TR_RA UL(0x6)
226#define MAIR_NORM_WB_TR_RWA UL(0x7)
227#define MAIR_NORM_WT_NTR_NA UL(0x8)
228#define MAIR_NORM_WT_NTR_WA UL(0x9)
229#define MAIR_NORM_WT_NTR_RA UL(0xa)
230#define MAIR_NORM_WT_NTR_RWA UL(0xb)
231#define MAIR_NORM_WB_NTR_NA UL(0xc)
232#define MAIR_NORM_WB_NTR_WA UL(0xd)
233#define MAIR_NORM_WB_NTR_RA UL(0xe)
234#define MAIR_NORM_WB_NTR_RWA UL(0xf)
235
236#define MAIR_NORM_OUTER_SHIFT U(4)
237
238#define MAKE_MAIR_NORMAL_MEMORY(inner, outer) \
239 ((inner) | ((outer) << MAIR_NORM_OUTER_SHIFT))
240
241#define MAKE_MAIR_NORMAL_MEMORY_IO(_mair) \
242 MAKE_MAIR_NORMAL_MEMORY(_mair, _mair)
243
244/*
245 * TTBR Definitions
246 */
AlexeiFedorov537bee02023-02-02 13:38:23 +0000247#define TTBR_CNP_BIT UL(1)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000248
249#define TTBRx_EL2_CnP_SHIFT 0
250#define TTBRx_EL2_CnP_WIDTH 1
251
252#define TTBRx_EL2_BADDR_SHIFT 1
253#define TTBRx_EL2_BADDR_WIDTH 47
254
255#define TTBRx_EL2_ASID_SHIFT 48
256#define TTBRx_EL2_ASID_WIDTH 16
257
258/*
259 * VTTBR Definitions
260 */
261#define VTTBR_EL2_VMID_SHIFT 48
262#define VTTBR_EL2_VMID_WIDTH 16
263
264/*
265 * ESR Definitions
266 */
267#define ESR_EL2_EC_SHIFT 26
268#define ESR_EL2_EC_WIDTH 6
Soby Mathewb4c6df42022-11-09 11:13:29 +0000269
270#define ESR_EL2_IL_SHIFT 25
271#define ESR_EL2_IL_WIDTH 1
Soby Mathewb4c6df42022-11-09 11:13:29 +0000272
273#define ESR_EL2_ISS_SHIFT 0
274#define ESR_EL2_ISS_WIDTH 25
Soby Mathewb4c6df42022-11-09 11:13:29 +0000275
276#define ESR_EL2_EC_UNKNOWN INPLACE(ESR_EL2_EC, 0)
277#define ESR_EL2_EC_WFX INPLACE(ESR_EL2_EC, 1)
278#define ESR_EL2_EC_FPU INPLACE(ESR_EL2_EC, 7)
279#define ESR_EL2_EC_SVC INPLACE(ESR_EL2_EC, 21)
280#define ESR_EL2_EC_HVC INPLACE(ESR_EL2_EC, 22)
281#define ESR_EL2_EC_SMC INPLACE(ESR_EL2_EC, 23)
282#define ESR_EL2_EC_SYSREG INPLACE(ESR_EL2_EC, 24)
283#define ESR_EL2_EC_SVE INPLACE(ESR_EL2_EC, 25)
284#define ESR_EL2_EC_INST_ABORT INPLACE(ESR_EL2_EC, 32)
285#define ESR_EL2_EC_INST_ABORT_SEL INPLACE(ESR_EL2_EC, 33)
286#define ESR_EL2_EC_DATA_ABORT INPLACE(ESR_EL2_EC, 36)
287#define ESR_EL2_EC_DATA_ABORT_SEL INPLACE(ESR_EL2_EC, 37)
288#define ESR_EL2_EC_SERROR INPLACE(ESR_EL2_EC, 47)
289
290/* Data/Instruction Abort ESR fields */
AlexeiFedorov537bee02023-02-02 13:38:23 +0000291#define ESR_EL2_ABORT_ISV_BIT (UL(1) << 24)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000292
293#define ESR_EL2_ABORT_SAS_SHIFT 22
294#define ESR_EL2_ABORT_SAS_WIDTH 2
Soby Mathewb4c6df42022-11-09 11:13:29 +0000295
296#define ESR_EL2_ABORT_SAS_BYTE_VAL 0
297#define ESR_EL2_ABORT_SAS_HWORD_VAL 1
298#define ESR_EL2_ABORT_SAS_WORD_VAL 2
299#define ESR_EL2_ABORT_SAS_DWORD_VAL 3
300
AlexeiFedorov537bee02023-02-02 13:38:23 +0000301#define ESR_EL2_ABORT_SSE_BIT (UL(1) << 21)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000302
303#define ESR_EL2_ABORT_SRT_SHIFT 16
304#define ESR_EL2_ABORT_SRT_WIDTH 5
Soby Mathewb4c6df42022-11-09 11:13:29 +0000305
306#define ESR_EL2_ABORT_SET_SHIFT 11
307#define ESR_EL2_ABORT_SET_WIDTH 2
Soby Mathewb4c6df42022-11-09 11:13:29 +0000308#define ESR_EL2_ABORT_SET_UER INPLACE(ESR_EL2_ABORT_SET, 0)
309#define ESR_EL2_ABORT_SET_UC INPLACE(ESR_EL2_ABORT_SET, 2)
310#define ESR_EL2_ABORT_SET_UEO INPLACE(ESR_EL2_ABORT_SET, 3)
311
AlexeiFedorov537bee02023-02-02 13:38:23 +0000312#define ESR_EL2_ABORT_SF_BIT (UL(1) << 15)
313#define ESR_EL2_ABORT_FNV_BIT (UL(1) << 10)
314#define ESR_EL2_ABORT_EA_BIT (UL(1) << 9)
315#define ESR_EL2_ABORT_S1PTW_BIT (UL(1) << 7)
316#define ESR_EL2_ABORT_WNR_BIT (UL(1) << 6)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000317#define ESR_EL2_ABORT_FSC_SHIFT 0
318#define ESR_EL2_ABORT_FSC_WIDTH 6
Soby Mathewb4c6df42022-11-09 11:13:29 +0000319
320#define ESR_EL2_ABORT_FSC_TRANSLATION_FAULT 0x04
321#define ESR_EL2_ABORT_FSC_PERMISSION_FAULT 0x0c
322#define ESR_EL2_ABORT_FSC_TRANSLATION_FAULT_L0 0x04
323#define ESR_EL2_ABORT_FSC_SEA 0x10
324#define ESR_EL2_ABORT_FSC_SEA_TTW_START 0x13
325#define ESR_EL2_ABORT_FSC_SEA_TTW_END 0x17
326#define ESR_EL2_ABORT_FSC_GPF 0x28
327#define ESR_EL2_ABORT_FSC_LEVEL_SHIFT 0
328#define ESR_EL2_ABORT_FSC_LEVEL_WIDTH 2
Soby Mathewb4c6df42022-11-09 11:13:29 +0000329
330/* The ESR fields that are reported to the host on Instr./Data Synchronous Abort */
AlexeiFedorov537bee02023-02-02 13:38:23 +0000331#define ESR_NONEMULATED_ABORT_MASK ( \
332 MASK(ESR_EL2_EC) | \
333 MASK(ESR_EL2_ABORT_SET) | \
334 ESR_EL2_ABORT_FNV_BIT | \
335 ESR_EL2_ABORT_EA_BIT | \
336 MASK(ESR_EL2_ABORT_FSC))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000337
AlexeiFedorov537bee02023-02-02 13:38:23 +0000338#define ESR_EMULATED_ABORT_MASK ( \
Soby Mathewb4c6df42022-11-09 11:13:29 +0000339 ESR_NONEMULATED_ABORT_MASK | \
AlexeiFedorov537bee02023-02-02 13:38:23 +0000340 ESR_EL2_ABORT_ISV_BIT | \
341 MASK(ESR_EL2_ABORT_SAS) | \
342 ESR_EL2_ABORT_SF_BIT | \
Soby Mathewb4c6df42022-11-09 11:13:29 +0000343 ESR_EL2_ABORT_WNR_BIT)
344
345#define ESR_EL2_SERROR_DFSC_SHIFT 0
346#define ESR_EL2_SERROR_DFSC_WIDTH 6
Soby Mathewb4c6df42022-11-09 11:13:29 +0000347#define ESR_EL2_SERROR_DFSC_UNCAT INPLACE(ESR_EL2_SERROR_DFSC, 0)
348#define ESR_EL2_SERROR_DFSC_ASYNC INPLACE(ESR_EL2_SERROR_DFSC, 1)
349
AlexeiFedorov537bee02023-02-02 13:38:23 +0000350#define ESR_EL2_SERROR_EA_BIT (UL(1) << 9)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000351
352#define ESR_EL2_SERROR_AET_SHIFT 10
353#define ESR_EL2_SERROR_AET_WIDTH 3
Soby Mathewb4c6df42022-11-09 11:13:29 +0000354#define ESR_EL2_SERROR_AET_UC INPLACE(ESR_EL2_SERROR_AET, 0)
355#define ESR_EL2_SERROR_AET_UEU INPLACE(ESR_EL2_SERROR_AET, 1)
356#define ESR_EL2_SERROR_AET_UEO INPLACE(ESR_EL2_SERROR_AET, 2)
357#define ESR_EL2_SERROR_AET_UER INPLACE(ESR_EL2_SERROR_AET, 3)
358#define ESR_EL2_SERROR_AET_CE INPLACE(ESR_EL2_SERROR_AET, 6)
359
AlexeiFedorov537bee02023-02-02 13:38:23 +0000360#define ESR_EL2_SERROR_IESB_BIT (UL(1) << 13)
361#define ESR_EL2_SERROR_IDS_BIT (UL(1) << 24)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000362
363/* The ESR fields that are reported to the host on SError */
AlexeiFedorov537bee02023-02-02 13:38:23 +0000364#define ESR_SERROR_MASK ( \
365 ESR_EL2_SERROR_IDS_BIT | \
366 MASK(ESR_EL2_SERROR_AET) | \
367 ESR_EL2_SERROR_EA_BIT | \
368 MASK(ESR_EL2_SERROR_DFSC))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000369
370#define ESR_EL2_SYSREG_TRAP_OP0_SHIFT 20
371#define ESR_EL2_SYSREG_TRAP_OP0_WIDTH 2
Soby Mathewb4c6df42022-11-09 11:13:29 +0000372
373#define ESR_EL2_SYSREG_TRAP_OP2_SHIFT 17
374#define ESR_EL2_SYSREG_TRAP_OP2_WIDTH 3
Soby Mathewb4c6df42022-11-09 11:13:29 +0000375
376#define ESR_EL2_SYSREG_TRAP_OP1_SHIFT 14
377#define ESR_EL2_SYSREG_TRAP_OP1_WIDTH 3
Soby Mathewb4c6df42022-11-09 11:13:29 +0000378
379#define ESR_EL2_SYSREG_TRAP_CRN_SHIFT 10
380#define ESR_EL2_SYSREG_TRAP_CRN_WIDTH 4
Soby Mathewb4c6df42022-11-09 11:13:29 +0000381
382#define ESR_EL2_SYSREG_TRAP_RT_SHIFT 5
383#define ESR_EL2_SYSREG_TRAP_RT_WIDTH 5
Soby Mathewb4c6df42022-11-09 11:13:29 +0000384
385#define ESR_EL2_SYSREG_TRAP_CRM_SHIFT 1
386#define ESR_EL2_SYSREG_TRAP_CRM_WIDTH 4
Soby Mathewb4c6df42022-11-09 11:13:29 +0000387
388/* WFx ESR fields */
AlexeiFedorov537bee02023-02-02 13:38:23 +0000389#define ESR_EL2_WFx_TI_BIT (UL(1) << 0)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000390
391/* xVC ESR fields */
392#define ESR_EL2_xVC_IMM_SHIFT 0
393#define ESR_EL2_xVC_IMM_WIDTH 16
Soby Mathewb4c6df42022-11-09 11:13:29 +0000394
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000395/* ID_AA64DFR0_EL1 definitions */
396#define ID_AA64DFR0_EL1_HPMN0_SHIFT UL(60)
397#define ID_AA64DFR0_EL1_HPMN0_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000398
399#define ID_AA64DFR0_EL1_BRBE_SHIFT UL(52)
400#define ID_AA64DFR0_EL1_BRBE_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000401
402#define ID_AA64DFR0_EL1_MTPMU_SHIFT UL(48)
403#define ID_AA64DFR0_EL1_MTPMU_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000404
405#define ID_AA64DFR0_EL1_TraceBuffer_SHIFT UL(44)
406#define ID_AA64DFR0_EL1_TraceBuffer_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000407
408#define ID_AA64DFR0_EL1_TraceFilt_SHIFT UL(40)
409#define ID_AA64DFR0_EL1_TraceFilt_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000410
411#define ID_AA64DFR0_EL1_DoubleLock_SHIFT UL(36)
412#define ID_AA64DFR0_EL1_DoubleLock_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000413
414#define ID_AA64DFR0_EL1_PMSVer_SHIFT UL(32)
415#define ID_AA64DFR0_EL1_PMSVer_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000416
417#define ID_AA64DFR0_EL1_CTX_CMPS_SHIFT UL(28)
418#define ID_AA64DFR0_EL1_CTX_CMPS_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000419
420#define ID_AA64DFR0_EL1_WRPs_SHIFT UL(20)
421#define ID_AA64DFR0_EL1_WRPs_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000422
423#define ID_AA64DFR0_EL1_BRPs_SHIFT UL(12)
424#define ID_AA64DFR0_EL1_BRPs_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000425
426#define ID_AA64DFR0_EL1_PMUVer_SHIFT UL(8)
427#define ID_AA64DFR0_EL1_PMUVer_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000428
429#define ID_AA64DFR0_EL1_TraceVer_SHIFT UL(4)
430#define ID_AA64DFR0_EL1_TraceVer_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000431
432#define ID_AA64DFR0_EL1_DebugVer_SHIFT UL(0)
433#define ID_AA64DFR0_EL1_DebugVer_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000434
435/* Debug architecture version */
436#define ID_AA64DFR0_EL1_DebugVer_8 UL(6)
437#define ID_AA64DFR0_EL1_DebugVer_8_VHE UL(7)
438#define ID_AA64DFR0_EL1_DebugVer_8_2 UL(8)
439#define ID_AA64DFR0_EL1_DebugVer_8_4 UL(9)
440#define ID_AA64DFR0_EL1_DebugVer_8_8 UL(10)
441
Soby Mathewb4c6df42022-11-09 11:13:29 +0000442/* ID_AA64PFR0_EL1 definitions */
443#define ID_AA64PFR0_EL1_SVE_SHIFT UL(32)
444#define ID_AA64PFR0_EL1_SVE_WIDTH UL(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000445
446#define ID_AA64PFR0_EL1_AMU_SHIFT UL(44)
447#define ID_AA64PFR0_EL1_AMU_WIDTH 4
448
449/* ID_AA64MMFR0_EL1 definitions */
450#define ID_AA64MMFR0_EL1_PARANGE_SHIFT U(0)
AlexeiFedorov537bee02023-02-02 13:38:23 +0000451#define ID_AA64MMFR0_EL1_PARANGE_WIDTH UL(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000452
453#define PARANGE_0000_WIDTH U(32)
454#define PARANGE_0001_WIDTH U(36)
455#define PARANGE_0010_WIDTH U(40)
456#define PARANGE_0011_WIDTH U(42)
457#define PARANGE_0100_WIDTH U(44)
458#define PARANGE_0101_WIDTH U(48)
459#define PARANGE_0110_WIDTH U(52)
460
AlexeiFedorov537bee02023-02-02 13:38:23 +0000461#define ID_AA64MMFR0_EL1_ECV_SHIFT UL(60)
462#define ID_AA64MMFR0_EL1_ECV_WIDTH UL(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000463#define ID_AA64MMFR0_EL1_ECV_NOT_SUPPORTED ULL(0x0)
464#define ID_AA64MMFR0_EL1_ECV_SUPPORTED ULL(0x1)
465#define ID_AA64MMFR0_EL1_ECV_SELF_SYNCH ULL(0x2)
466
AlexeiFedorov537bee02023-02-02 13:38:23 +0000467#define ID_AA64MMFR0_EL1_FGT_SHIFT UL(56)
468#define ID_AA64MMFR0_EL1_FGT_WIDTH UL(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000469#define ID_AA64MMFR0_EL1_FGT_SUPPORTED ULL(0x1)
470#define ID_AA64MMFR0_EL1_FGT_NOT_SUPPORTED ULL(0x0)
471
472#define ID_AA64MMFR0_EL1_TGRAN4_2_SHIFT U(40)
AlexeiFedorov537bee02023-02-02 13:38:23 +0000473#define ID_AA64MMFR0_EL1_TGRAN4_2_WIDTH U(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000474#define ID_AA64MMFR0_EL1_TGRAN4_2_TGRAN4 ULL(0x0)
475#define ID_AA64MMFR0_EL1_TGRAN4_2_NOT_SUPPORTED ULL(0x1)
476#define ID_AA64MMFR0_EL1_TGRAN4_2_SUPPORTED ULL(0x2)
477#define ID_AA64MMFR0_EL1_TGRAN4_2_LPA2 ULL(0x3)
478
AlexeiFedorov537bee02023-02-02 13:38:23 +0000479#define ID_AA64MMFR0_EL1_TGRAN16_2_SHIFT UL(32)
480#define ID_AA64MMFR0_EL1_TGRAN16_2_WIDTH UL(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000481#define ID_AA64MMFR0_EL1_TGRAN16_2_TGRAN16 ULL(0x0)
482#define ID_AA64MMFR0_EL1_TGRAN16_2_NOT_SUPPORTED ULL(0x1)
483#define ID_AA64MMFR0_EL1_TGRAN16_2_SUPPORTED ULL(0x2)
484#define ID_AA64MMFR0_EL1_TGRAN16_2_LPA2 ULL(0x3)
485
AlexeiFedorov537bee02023-02-02 13:38:23 +0000486#define ID_AA64MMFR0_EL1_TGRAN4_SHIFT UL(28)
487#define ID_AA64MMFR0_EL1_TGRAN4_WIDTH UL(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000488#define ID_AA64MMFR0_EL1_TGRAN4_SUPPORTED ULL(0x0)
489#define ID_AA64MMFR0_EL1_TGRAN4_LPA2 ULL(0x1)
490#define ID_AA64MMFR0_EL1_TGRAN4_NOT_SUPPORTED ULL(0xf)
491
492#define ID_AA64MMFR0_EL1_TGRAN64_SHIFT UL(24)
AlexeiFedorov537bee02023-02-02 13:38:23 +0000493#define ID_AA64MMFR0_EL1_TGRAN64_WIDTH UL(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000494#define ID_AA64MMFR0_EL1_TGRAN64_SUPPORTED UL(0x0)
495#define ID_AA64MMFR0_EL1_TGRAN64_NOT_SUPPORTED UL(0xf)
496
497#define ID_AA64MMFR0_EL1_TGRAN16_SHIFT UL(20)
AlexeiFedorov537bee02023-02-02 13:38:23 +0000498#define ID_AA64MMFR0_EL1_TGRAN16_WIDTH UL(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000499#define ID_AA64MMFR0_EL1_TGRAN16_NOT_SUPPORTED UL(0x0)
500#define ID_AA64MMFR0_EL1_TGRAN16_SUPPORTED UL(0x1)
501#define ID_AA64MMFR0_EL1_TGRAN16_LPA2 UL(0x2)
502
503/* RNDR definitions */
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000504#define ID_AA64ISAR0_EL1_RNDR_SHIFT UL(60)
505#define ID_AA64ISAR0_EL1_RNDR_WIDTH UL(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000506
507/* ID_AA64MMFR1_EL1 definitions */
508#define ID_AA64MMFR1_EL1_VMIDBits_SHIFT UL(4)
AlexeiFedorov537bee02023-02-02 13:38:23 +0000509#define ID_AA64MMFR1_EL1_VMIDBits_WIDTH UL(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000510#define ID_AA64MMFR1_EL1_VMIDBits_8 UL(0)
511#define ID_AA64MMFR1_EL1_VMIDBits_16 UL(2)
512
513/* HPFAR_EL2 definitions */
514#define HPFAR_EL2_FIPA_SHIFT 4
515#define HPFAR_EL2_FIPA_WIDTH 40
Soby Mathewb4c6df42022-11-09 11:13:29 +0000516#define HPFAR_EL2_FIPA_OFFSET 8
517
518/* SPSR definitions */
519#define SPSR_EL2_MODE_SHIFT 0
520#define SPSR_EL2_MODE_WIDTH 4
521#define SPSR_EL2_MODE_EL0t INPLACE(SPSR_EL2_MODE, 0)
522
523#define SPSR_EL2_MODE_SHIFT 0
524#define SPSR_EL2_MODE_WIDTH 4
525#define SPSR_EL2_MODE_EL1h INPLACE(SPSR_EL2_MODE, 5)
526#define SPSR_EL2_MODE_EL1t INPLACE(SPSR_EL2_MODE, 4)
527
528/* FIXME: DAIF definitions are redundant here. Might need unification. */
529#define SPSR_EL2_nRW_SHIFT 4
530#define SPSR_EL2_nRW_WIDTH 1
531#define SPSR_EL2_nRW_AARCH64 INPLACE(SPSR_EL2_nRW, 0)
532#define SPSR_EL2_nRW_AARCH32 INPLACE(SPSR_EL2_nRW, 1)
533
AlexeiFedorov537bee02023-02-02 13:38:23 +0000534#define SPSR_EL2_DAIF_SHIFT 6
535#define SPSR_EL2_AIF_SHIFT 6
Soby Mathewb4c6df42022-11-09 11:13:29 +0000536
AlexeiFedorov537bee02023-02-02 13:38:23 +0000537#define DAIF_FIQ_BIT (UL(1) << 0)
538#define DAIF_IRQ_BIT (UL(1) << 1)
539#define DAIF_ABT_BIT (UL(1) << 2)
540#define DAIF_DBG_BIT (UL(1) << 3)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000541
AlexeiFedorov537bee02023-02-02 13:38:23 +0000542#define SPSR_EL2_F_BIT (UL(1) << 6)
543#define SPSR_EL2_I_BIT (UL(1) << 7)
544#define SPSR_EL2_A_BIT (UL(1) << 8)
545#define SPSR_EL2_D_BIT (UL(1) << 9)
546#define SPSR_EL2_SSBS_BIT (UL(1) << 12)
547#define SPSR_EL2_ALLINT_BIT (UL(1) << 13)
548#define SPSR_EL2_IL_BIT (UL(1) << 20)
549#define SPSR_EL2_SS_BIT (UL(1) << 21)
550#define SPSR_EL2_PAN_BIT (UL(1) << 22)
551#define SPSR_EL2_UAO_BIT (UL(1) << 23)
552#define SPSR_EL2_DIT_BIT (UL(1) << 24)
553#define SPSR_EL2_TCO_BIT (UL(1) << 25)
554#define SPSR_EL2_V_BIT (UL(1) << 28)
555#define SPSR_EL2_C_BIT (UL(1) << 29)
556#define SPSR_EL2_Z_BIT (UL(1) << 30)
557#define SPSR_EL2_N_BIT (UL(1) << 31)
558#define SPSR_EL2_PM_BIT (UL(1) << 32)
559#define SPSR_EL2_PPEND_BIT (UL(1) << 33)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000560
561/* VTCR definitions */
562#define VTCR_T0SZ_SHIFT 0
563#define VTCR_T0SZ_WIDTH 6
564
565#define VTCR_SL0_SHIFT 6
566#define VTCR_SL0_WIDTH 2
567
568#define VTCR_SL0_4K_L2 INPLACE(VTCR_SL0, 0)
569#define VTCR_SL0_4K_L1 INPLACE(VTCR_SL0, 1)
570#define VTCR_SL0_4K_L0 INPLACE(VTCR_SL0, 2)
571#define VTCR_SL0_4K_L3 INPLACE(VTCR_SL0, 3)
572
573#define VTCR_IRGN0_SHIFT 8
574#define VTCR_IRGN0_WIDTH 2
575#define VTCR_IRGN0_WBRAWA INPLACE(VTCR_IRGN0, 1)
576
577#define VTCR_ORGN0_SHIFT 10
578#define VTCR_ORGN0_WIDTH 2
579#define VTCR_ORGN0_WBRAWA INPLACE(VTCR_ORGN0, 1)
580
581#define VTCR_SH0_SHIFT 12
582#define VTCR_SH0_WIDTH 2
583#define VTCR_SH0_IS INPLACE(VTCR_SH0, 3)
584
585#define VTCR_TG0_SHIFT 14
586#define VTCR_TG0_WIDTH 2
587#define VTCR_TG0_4K INPLACE(VTCR_TG0, 0)
588
589#define VTCR_PS_SHIFT 16
590#define VTCR_PS_WIDTH 3
591#define VTCR_PS_40 INPLACE(VTCR_PS, 2)
592
593#define VTCR_VS (UL(1) << 19)
594#define VTCR_NSA (UL(1) << 30)
595#define VTCR_RES1 (UL(1) << 31)
596
597#define VTCR_FLAGS ( \
598 VTCR_IRGN0_WBRAWA | /* PTW inner cache attr. is WB RAWA*/ \
599 VTCR_ORGN0_WBRAWA | /* PTW outer cache attr. is WB RAWA*/ \
600 VTCR_SH0_IS | /* PTW shareability attr. is Outer Sharable*/\
601 VTCR_TG0_4K | /* 4K granule size in non-secure PT*/ \
602 VTCR_PS_40 | /* size(PA) = 40 */ \
603 /* VS = 0 size(VMID) = 8 */ \
604 /* NSW = 0 non-secure s2 is made of secure pages*/ \
605 VTCR_NSA | /* non-secure IPA maps to non-secure PA */ \
606 VTCR_RES1 \
607 )
608
609
610/* SCTLR definitions */
611#define SCTLR_EL1_EE (UL(1) << 25)
612#define SCTLR_EL1_SPAN (UL(1) << 23)
613#define SCTLR_EL1_EIS (UL(1) << 22)
614#define SCTLR_EL1_nTWE (UL(1) << 18)
615#define SCTLR_EL1_nTWI (UL(1) << 16)
616#define SCTLR_EL1_EOS (UL(1) << 11)
617#define SCTLR_EL1_nAA (UL(1) << 6)
618#define SCTLR_EL1_CP15BEN (UL(1) << 5)
619#define SCTLR_EL1_SA0 (UL(1) << 4)
620#define SCTLR_EL1_SA (UL(1) << 3)
621
622#define SCTLR_EL1_FLAGS (SCTLR_EL1_SPAN | SCTLR_EL1_EIS | SCTLR_EL1_nTWE | \
623 SCTLR_EL1_nTWI | SCTLR_EL1_EOS | SCTLR_EL1_nAA | SCTLR_EL1_CP15BEN | \
624 SCTLR_EL1_SA0 | SCTLR_EL1_SA)
625
626/* PMCR_EL0 Definitions */
AlexeiFedorov537bee02023-02-02 13:38:23 +0000627#define PMCR_EL0_LC_BIT (UL(1) << 6)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000628
AlexeiFedorov537bee02023-02-02 13:38:23 +0000629#define PMCR_EL0_RES1 PMCR_EL0_LC_BIT
Soby Mathewb4c6df42022-11-09 11:13:29 +0000630
631
632/* MDSCR_EL1 Definitions */
AlexeiFedorov537bee02023-02-02 13:38:23 +0000633#define MDSCR_EL1_TDCC_BIT (UL(1) << 12)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000634
635/* SCTLR register definitions */
636#define SCTLR_EL2_RES1 ((UL(1) << 22) /* TODO: ARMv8.5-CSEH, otherwise RES1 */ | \
AlexeiFedorov537bee02023-02-02 13:38:23 +0000637 (UL(1) << 11) /* TODO: ARMv8.5-CSEH, otherwise RES1 */)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000638
639#define SCTLR_EL2_M (UL(1) << 0)
640#define SCTLR_EL2_C (UL(1) << 2)
641#define SCTLR_EL2_SA (UL(1) << 3)
642#define SCTLR_EL2_SA0 (UL(1) << 4)
643#define SCTLR_EL2_SED (UL(1) << 8)
644/* TODO: ARMv8.5-CSEH, otherwise RES1 */
645/* #define SCTLR_EL2_EOS (UL(1) << 11) */
646#define SCTLR_EL2_I (UL(1) << 12)
647#define SCTLR_EL2_DZE (UL(1) << 14)
648#define SCTLR_EL2_UCT (UL(1) << 15)
649#define SCTLR_EL2_NTWI (UL(1) << 16)
650#define SCTLR_EL2_NTWE (UL(1) << 18)
651#define SCTLR_EL2_WXN (UL(1) << 19)
652#define SCTLR_EL2_TSCXT (UL(1) << 20)
653/* TODO: ARMv8.5-CSEH, otherwise RES1 */
654/* #define SCTLR_EL2_EIS (UL(1) << 22) */
655#define SCTLR_EL2_SPAN (UL(1) << 23)
656#define SCTLR_EL2_UCI (UL(1) << 26)
657#define SCTLR_EL2_NTLSMD (UL(1) << 28)
658#define SCTLR_EL2_LSMAOE (UL(1) << 29)
659/* HCR_EL2.E2H == 0b1 and HCR_EL2.TGE == 0b1 */
660#define SECURE_SCTLR_EL2_RES1 ((UL(1) << 22) /* TODO: ARMv8.5-CSEH, otherwise RES1 */ | \
661 (UL(1) << 11) /* TODO: ARMv8.5-CSEH, otherwise RES1 */)
662
663#define SCTLR_EL2_INIT (/* SCTLR_EL2_M = 0 (MMU disabled) */ \
664 /* SCTLR_EL2_A = 0 (No alignment checks) */ \
665 SCTLR_EL2_C /* Data accesses are cacheable
666 * as per translation tables */ | \
667 SCTLR_EL2_SA /* SP aligned at EL2 */ | \
668 SCTLR_EL2_SA0 /* SP Alignment check enable for EL0 */ \
669 /* SCTLR_EL2_CP15BEN = 0 (EL0 using AArch32:
670 * EL0 execution of the CP15DMB, CP15DSB, and
671 * CP15ISB instructions is UNDEFINED. */ \
672 /* SCTLR_EL2_NAA = 0 (unaligned MA fault at EL2 and EL0) */ \
673 /* SCTLR_EL2_ITD = 0 (A32 Only) */ | \
674 SCTLR_EL2_SED /* A32 Only, RES1 for non-A32 systems */ \
675 /* SCTLR_EL2_EOS TODO: ARMv8.5-CSEH, otherwise RES1 */ | \
676 SCTLR_EL2_I /* I$ is ON for EL2 and EL0 */ | \
677 SCTLR_EL2_DZE /* Do not trap DC ZVA */ | \
678 SCTLR_EL2_UCT /* Allow EL0 access to CTR_EL0 */ | \
679 SCTLR_EL2_NTWI /* Don't trap WFI from EL0 to EL2 */ | \
680 SCTLR_EL2_NTWE /* Don't trap WFE from EL0 to EL2 */ | \
681 SCTLR_EL2_WXN /* W implies XN */ | \
682 SCTLR_EL2_TSCXT /* Trap EL0 accesss to SCXTNUM_EL0 */ \
683 /* SCTLR_EL2_EIS EL2 exception is context
684 * synchronizing
685 * TODO: ARMv8.5-CSEH, otherwise RES1 */ \
686 /* SCTLR_EL2_SPAN = 0 (Set PSTATE.PAN = 1 on
687 * exceptions to EL2)) */ | \
688 SCTLR_EL2_UCI /* Allow cache maintenance
689 * instructions at EL0 */ | \
690 SCTLR_EL2_NTLSMD /* A32/T32 only */ | \
691 SCTLR_EL2_LSMAOE /* A32/T32 only */ | \
692 SECURE_SCTLR_EL2_RES1)
693
694#define SCTLR_EL2_RUNTIME (SCTLR_EL2_INIT| \
695 SCTLR_EL2_M /* MMU enabled */)
696
697/* CPTR_EL2 definitions */
698#define CPTR_EL2_RES1 ((UL(1) << 13) | (UL(1) << 12) | (UL(1) << 9) | 0xff)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000699#define CPTR_EL2_TTA (UL(1) << 28)
700#define CPTR_EL2_TAM (UL(1) << 30)
AlexeiFedorov537bee02023-02-02 13:38:23 +0000701#define CPTR_EL2_FPEN_SHIFT UL(20)
702#define CPTR_EL2_FPEN_WIDTH UL(2)
703#define CPTR_EL2_FPEN_TRAP_ALL_00 0x0
704#define CPTR_EL2_FPEN_TRAP_TGE_01 0x1
Soby Mathewb4c6df42022-11-09 11:13:29 +0000705#define CPTR_EL2_FPEN_TRAP_ALL_10 0x2
AlexeiFedorov537bee02023-02-02 13:38:23 +0000706#define CPTR_EL2_FPEN_NO_TRAP_11 0x3
Soby Mathewb4c6df42022-11-09 11:13:29 +0000707#define CPTR_EL2_ZEN_SHIFT UL(16)
AlexeiFedorov537bee02023-02-02 13:38:23 +0000708#define CPTR_EL2_ZEN_WIDTH UL(2)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000709#define CPTR_EL2_ZEN_TRAP_ALL_00 UL(0x0)
710#define CPTR_EL2_ZEN_NO_TRAP_11 UL(0x3)
711 /* Trap all FPU/SVE accesses */
712#define CPTR_EL2_INIT ((CPTR_EL2_ZEN_TRAP_ALL_00 << \
AlexeiFedorov537bee02023-02-02 13:38:23 +0000713 CPTR_EL2_ZEN_SHIFT) | \
714 (CPTR_EL2_FPEN_TRAP_ALL_00 << \
715 CPTR_EL2_FPEN_SHIFT) | \
716 CPTR_EL2_TTA /* trap trace access */ | \
717 CPTR_EL2_TAM /* trap AMU access */ | \
Soby Mathewb4c6df42022-11-09 11:13:29 +0000718 CPTR_EL2_RES1)
719
720/* MDCR_EL2 definitions */
AlexeiFedorov537bee02023-02-02 13:38:23 +0000721#define MDCR_EL2_HLP (UL(1) << 26)
722#define MDCR_EL2_HCCD (UL(1) << 23)
723#define MDCR_EL2_TTRF (UL(1) << 19)
724#define MDCR_EL2_HPMD (UL(1) << 17)
725#define MDCR_EL2_TPMS (UL(1) << 14)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000726#define MDCR_EL2_E2PB(x) ((x) << 12)
AlexeiFedorov537bee02023-02-02 13:38:23 +0000727#define MDCR_EL2_E2PB_EL1 UL(3)
728#define MDCR_EL2_TDRA_BIT (UL(1) << 11)
729#define MDCR_EL2_TDOSA_BIT (UL(1) << 10)
730#define MDCR_EL2_TDA_BIT (UL(1) << 9)
731#define MDCR_EL2_TDE_BIT (UL(1) << 8)
732#define MDCR_EL2_HPME_BIT (UL(1) << 7)
733#define MDCR_EL2_TPM_BIT (UL(1) << 6)
734#define MDCR_EL2_TPMCR_BIT (UL(1) << 5)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000735#define MDCR_EL2_INIT (MDCR_EL2_TPMCR_BIT \
736 | MDCR_EL2_TPM_BIT \
737 | MDCR_EL2_TDA_BIT)
738
739/* MPIDR definitions */
740#define MPIDR_EL1_AFF_MASK 0xFF
741#define MPIDR_EL1_AFF0_SHIFT 0
742#define MPIDR_EL1_AFF1_SHIFT 8
743#define MPIDR_EL1_AFF2_SHIFT 16
744#define MPIDR_EL1_AFF3_SHIFT 32
745#define MPIDR_EL1_MT_MASK (UL(1) << 24)
746#define MPIDR_EL1_AFFINITY_BITS 8
747
748#define MPIDR_EL1_AFF0 INPLACE(MPIDR_EL1_AFF0, MPIDR_EL1_AFF_MASK)
749#define MPIDR_EL1_AFF1 INPLACE(MPIDR_EL1_AFF1, MPIDR_EL1_AFF_MASK)
750#define MPIDR_EL1_AFF2 INPLACE(MPIDR_EL1_AFF2, MPIDR_EL1_AFF_MASK)
751#define MPIDR_EL1_AFF3 INPLACE(MPIDR_EL1_AFF3, MPIDR_EL1_AFF_MASK)
752
753/*
754 * RmiRecMpidr type definitions.
755 *
756 * 'MPIDR_EL2_AFF<n>_VAL_SHIFT' constants specify the right shift
757 * for affinity field <n> that gives the field's actual value.
758 *
759 * Aff0[3:0] - Affinity level 0
760 * For compatibility with GICv3 only Aff0[3:0] field is used,
761 * and Aff0[7:4] of a REC MPIDR value is RES0.
762 */
763#define MPIDR_EL2_AFF0_SHIFT 0
764#define MPIDR_EL2_AFF0_WIDTH 4
765#define MPIDR_EL2_AFF0_VAL_SHIFT 0
766
767/* Aff1[15:8] - Affinity level 1 */
768#define MPIDR_EL2_AFF1_SHIFT 8
769#define MPIDR_EL2_AFF1_WIDTH 8
770#define MPIDR_EL2_AFF1_VAL_SHIFT 4
771
772/* Aff2[23:16] - Affinity level 2 */
773#define MPIDR_EL2_AFF2_SHIFT 16
774#define MPIDR_EL2_AFF2_WIDTH 8
775#define MPIDR_EL2_AFF2_VAL_SHIFT 4
776
777/* Aff3[39:32] - Affinity level 3 */
778#define MPIDR_EL2_AFF3_SHIFT 32
779#define MPIDR_EL2_AFF3_WIDTH 8
780#define MPIDR_EL2_AFF3_VAL_SHIFT 12
781
782/*
783 * Extract the value of Aff<n> register field shifted right
784 * so it can be evaluated directly.
785 */
AlexeiFedorov537bee02023-02-02 13:38:23 +0000786#define MPIDR_EL2_AFF(n, reg) \
Soby Mathewb4c6df42022-11-09 11:13:29 +0000787 (((reg) & MASK(MPIDR_EL2_AFF##n)) >> MPIDR_EL2_AFF##n##_VAL_SHIFT)
788
789/* VMPIDR_EL2 bit [31] = RES1 */
790#define VMPIDR_EL2_RES1 (UL(1) << 31)
791
792/* ICC_SRE_EL2 defintions */
793#define ICC_SRE_EL2_ENABLE (UL(1) << 3) /* Enable lower EL access to ICC_SRE_EL1 */
794#define ICC_SRE_EL2_DIB (UL(1) << 2) /* Disable IRQ bypass */
795#define ICC_SRE_EL2_DFB (UL(1) << 1) /* Disable FIQ bypass */
796#define ICC_SRE_EL2_SRE (UL(1) << 0) /* Enable sysreg access */
797
AlexeiFedorov537bee02023-02-02 13:38:23 +0000798#define ICC_SRE_EL2_INIT (ICC_SRE_EL2_ENABLE | ICC_SRE_EL2_DIB | \
Soby Mathewb4c6df42022-11-09 11:13:29 +0000799 ICC_SRE_EL2_DFB | ICC_SRE_EL2_SRE)
800
801/* MPAM definitions */
802#define MPAM2_EL2_INIT 0x0
803#define MPAMHCR_EL2_INIT 0x0
804
805#define PMSCR_EL2_INIT 0x0
806
807#define SYSREG_ESR(op0, op1, crn, crm, op2) \
808 (((op0) << ESR_EL2_SYSREG_TRAP_OP0_SHIFT) | \
809 ((op1) << ESR_EL2_SYSREG_TRAP_OP1_SHIFT) | \
810 ((crn) << ESR_EL2_SYSREG_TRAP_CRN_SHIFT) | \
811 ((crm) << ESR_EL2_SYSREG_TRAP_CRM_SHIFT) | \
812 ((op2) << ESR_EL2_SYSREG_TRAP_OP2_SHIFT))
813
814#define ESR_EL2_SYSREG_MASK SYSREG_ESR(3, 7, 15, 15, 7)
815
816#define ESR_EL2_SYSREG_ID_MASK SYSREG_ESR(3, 7, 15, 0, 0)
817#define ESR_EL2_SYSREG_ID SYSREG_ESR(3, 0, 0, 0, 0)
818
819#define ESR_EL2_SYSREG_ID_AA64PFR0_EL1 SYSREG_ESR(3, 0, 0, 4, 0)
820#define ESR_EL2_SYSREG_ID_AA64PFR1_EL1 SYSREG_ESR(3, 0, 0, 4, 1)
821#define ESR_EL2_SYSREG_ID_AA64ZFR0_EL1 SYSREG_ESR(3, 0, 0, 4, 4)
822
823#define ESR_EL2_SYSREG_ID_AA64DFR0_EL1 SYSREG_ESR(3, 0, 0, 5, 0)
824#define ESR_EL2_SYSREG_ID_AA64DFR1_EL1 SYSREG_ESR(3, 0, 0, 5, 1)
825
826#define ESR_EL2_SYSREG_ID_AA64AFR0_EL1 SYSREG_ESR(3, 0, 0, 5, 4)
827#define ESR_EL2_SYSREG_ID_AA64AFR1_EL1 SYSREG_ESR(3, 0, 0, 5, 5)
828
829#define ESR_EL2_SYSREG_ID_AA64ISAR0_EL1 SYSREG_ESR(3, 0, 0, 6, 0)
830#define ESR_EL2_SYSREG_ID_AA64ISAR1_EL1 SYSREG_ESR(3, 0, 0, 6, 1)
831
832#define ESR_EL2_SYSREG_ID_AA64MMFR0_EL1 SYSREG_ESR(3, 0, 0, 7, 0)
833#define ESR_EL2_SYSREG_ID_AA64MMFR1_EL1 SYSREG_ESR(3, 0, 0, 7, 1)
834#define ESR_EL2_SYSREG_ID_AA64MMFR2_EL1 SYSREG_ESR(3, 0, 0, 7, 2)
835
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000836/* ID_AA64ISAR1_EL1 definitions */
837#define ID_AA64ISAR1_EL1_GPI_SHIFT UL(28)
838#define ID_AA64ISAR1_EL1_GPI_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000839
840#define ID_AA64ISAR1_EL1_GPA_SHIFT UL(24)
841#define ID_AA64ISAR1_EL1_GPA_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000842
843#define ID_AA64ISAR1_EL1_API_SHIFT UL(8)
844#define ID_AA64ISAR1_EL1_API_WIDTH UL(4)
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000845
846#define ID_AA64ISAR1_EL1_APA_SHIFT UL(4)
847#define ID_AA64ISAR1_EL1_APA_WIDTH UL(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000848
849#define ESR_EL2_SYSREG_TIMERS_MASK SYSREG_ESR(3, 3, 15, 12, 0)
850#define ESR_EL2_SYSREG_TIMERS SYSREG_ESR(3, 3, 14, 0, 0)
851
852#define ESR_EL2_SYSREG_TIMER_CNTP_TVAL_EL0 SYSREG_ESR(3, 3, 14, 2, 0)
853#define ESR_EL2_SYSREG_TIMER_CNTP_CTL_EL0 SYSREG_ESR(3, 3, 14, 2, 1)
854#define ESR_EL2_SYSREG_TIMER_CNTP_CVAL_EL0 SYSREG_ESR(3, 3, 14, 2, 2)
855#define ESR_EL2_SYSREG_TIMER_CNTV_TVAL_EL0 SYSREG_ESR(3, 3, 14, 3, 0)
856#define ESR_EL2_SYSREG_TIMER_CNTV_CTL_EL0 SYSREG_ESR(3, 3, 14, 3, 1)
857#define ESR_EL2_SYSREG_TIMER_CNTV_CVAL_EL0 SYSREG_ESR(3, 3, 14, 3, 2)
858
859#define ESR_EL2_SYSREG_ICC_PMR_EL1 SYSREG_ESR(3, 0, 4, 6, 0)
860
861/*
862 * GIC system registers encoding mask for registers from
863 * ICC_IAR0_EL1(3, 0, 12, 8, 0) to ICC_IGRPEN1_EL1(3, 0, 12, 12, 7).
864 */
865#define ESR_EL2_SYSREG_ICC_EL1_MASK SYSREG_ESR(3, 3, 15, 8, 0)
866#define ESR_EL2_SYSREG_ICC_EL1 SYSREG_ESR(3, 0, 12, 8, 0)
867
868#define ESR_EL2_SYSREG_ICC_DIR SYSREG_ESR(3, 0, 12, 11, 1)
869#define ESR_EL2_SYSREG_ICC_SGI1R_EL1 SYSREG_ESR(3, 0, 12, 11, 5)
870#define ESR_EL2_SYSREG_ICC_SGI0R_EL1 SYSREG_ESR(3, 0, 12, 11, 7)
871
872#define ESR_EL2_SYSREG_DIRECTION (UL(1) << 0)
873#define ESR_EL2_SYSREG_IS_WRITE(esr) (!((esr) & ESR_EL2_SYSREG_DIRECTION))
874
AlexeiFedorov537bee02023-02-02 13:38:23 +0000875#define ESR_IL(esr) ((esr) & MASK(ESR_EL2_IL))
Soby Mathewb4c6df42022-11-09 11:13:29 +0000876
AlexeiFedorovfeaef162022-12-23 16:59:51 +0000877#define ESR_EL2_SYSREG_ISS_RT(esr) EXTRACT(ESR_EL2_SYSREG_TRAP_RT, esr)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000878
879#define ICC_HPPIR1_EL1_INTID_SHIFT 0
880#define ICC_HPPIR1_EL1_INTID_WIDTH 24
Soby Mathewb4c6df42022-11-09 11:13:29 +0000881
882#define CNTHCTL_EL2_EL0PCTEN (UL(1) << UL(0))
883#define CNTHCTL_EL2_EL0VCTEN (UL(1) << UL(1))
884#define CNTHCTL_EL2_EL1PCTEN (UL(1) << 10)
885#define CNTHCTL_EL2_EL1PTEN (UL(1) << 11)
886#define CNTHCTL_EL2_EL1TVT (UL(1) << 13)
887#define CNTHCTL_EL2_EL1TVCT (UL(1) << 14)
888#define CNTHCTL_EL2_CNTVMASK (UL(1) << 18)
889#define CNTHCTL_EL2_CNTPMASK (UL(1) << 19)
890
891#define CNTHCTL_EL2_INIT (CNTHCTL_EL2_EL0VCTEN | CNTHCTL_EL2_EL0PCTEN)
892
893#define CNTHCTL_EL2_NO_TRAPS (CNTHCTL_EL2_EL1PCTEN | \
894 CNTHCTL_EL2_EL1PTEN)
895
896#define CNTx_CTL_ENABLE (UL(1) << 0)
897#define CNTx_CTL_IMASK (UL(1) << 1)
898#define CNTx_CTL_ISTATUS (UL(1) << 2)
899
900/*******************************************************************************
901 * Definitions of register offsets, fields and macros for CPU system
902 * instructions.
903 ******************************************************************************/
904
905#define TLBI_ADDR_SHIFT U(12)
906#define TLBI_ADDR_MASK U(0x0FFFFFFFFFFF)
907#define TLBI_ADDR(x) (((x) >> TLBI_ADDR_SHIFT) & TLBI_ADDR_MASK)
908
909/* ID_AA64MMFR2_EL1 definitions */
AlexeiFedorov537bee02023-02-02 13:38:23 +0000910#define ID_AA64MMFR2_EL1_ST_SHIFT UL(28)
911#define ID_AA64MMFR2_EL1_ST_WIDTH UL(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000912
AlexeiFedorov537bee02023-02-02 13:38:23 +0000913#define ID_AA64MMFR2_EL1_CNP_SHIFT UL(0)
914#define ID_AA64MMFR2_EL1_CNP_WIDTH UL(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000915
916/* Custom defined values to indicate the vector offset to exception handlers */
917#define ARM_EXCEPTION_SYNC_LEL 0
918#define ARM_EXCEPTION_IRQ_LEL 1
919#define ARM_EXCEPTION_FIQ_LEL 2
920#define ARM_EXCEPTION_SERROR_LEL 3
921
AlexeiFedorov537bee02023-02-02 13:38:23 +0000922#define VBAR_CEL_SP_EL0_OFFSET 0x0
923#define VBAR_CEL_SP_ELx_OFFSET 0x200
924#define VBAR_LEL_AA64_OFFSET 0x400
925#define VBAR_LEL_AA32_OFFSET 0x600
Soby Mathewb4c6df42022-11-09 11:13:29 +0000926
927#endif /* ARCH_H */