blob: 6f41db968a9b35a336e838b791b8838b6f010c52 [file] [log] [blame]
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02001/*
AlexeiFedorov2f30f102023-03-13 19:37:46 +00002 * Copyright (c) 2016-2023, Arm Limited and Contributors. All rights reserved.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Antonio Nino Diazdcfc4832018-11-22 15:53:23 +00007#ifndef ARCH_H
8#define ARCH_H
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02009
10#include <utils_def.h>
11
12/*******************************************************************************
13 * MIDR bit definitions
14 ******************************************************************************/
15#define MIDR_IMPL_MASK U(0xff)
16#define MIDR_IMPL_SHIFT U(24)
17#define MIDR_VAR_SHIFT U(20)
18#define MIDR_VAR_BITS U(4)
19#define MIDR_REV_SHIFT U(0)
20#define MIDR_REV_BITS U(4)
21#define MIDR_PN_MASK U(0xfff)
22#define MIDR_PN_SHIFT U(4)
Sona Mathew07384212022-11-28 13:19:11 -060023#define MIDR_VAR_MASK U(0xf0)
24#define MIDR_REV_MASK U(0xf)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020025
26/*******************************************************************************
27 * MPIDR macros
28 ******************************************************************************/
29#define MPIDR_MT_MASK (U(1) << 24)
30#define MPIDR_CPU_MASK MPIDR_AFFLVL_MASK
31#define MPIDR_CLUSTER_MASK (MPIDR_AFFLVL_MASK << MPIDR_AFFINITY_BITS)
32#define MPIDR_AFFINITY_BITS U(8)
33#define MPIDR_AFFLVL_MASK U(0xff)
34#define MPIDR_AFFLVL_SHIFT U(3)
35#define MPIDR_AFF0_SHIFT U(0)
36#define MPIDR_AFF1_SHIFT U(8)
37#define MPIDR_AFF2_SHIFT U(16)
38#define MPIDR_AFF_SHIFT(_n) MPIDR_AFF##_n##_SHIFT
39#define MPIDR_AFFINITY_MASK U(0x00ffffff)
40#define MPIDR_AFFLVL0 U(0)
41#define MPIDR_AFFLVL1 U(1)
42#define MPIDR_AFFLVL2 U(2)
43#define MPIDR_AFFLVL(_n) MPIDR_AFFLVL##_n
44
45#define MPIDR_AFFLVL0_VAL(mpidr) \
46 (((mpidr) >> MPIDR_AFF0_SHIFT) & MPIDR_AFFLVL_MASK)
47#define MPIDR_AFFLVL1_VAL(mpidr) \
48 (((mpidr) >> MPIDR_AFF1_SHIFT) & MPIDR_AFFLVL_MASK)
49#define MPIDR_AFFLVL2_VAL(mpidr) \
50 (((mpidr) >> MPIDR_AFF2_SHIFT) & MPIDR_AFFLVL_MASK)
Antonio Nino Diazdcfc4832018-11-22 15:53:23 +000051#define MPIDR_AFFLVL3_VAL(mpidr) U(0)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020052
53#define MPIDR_AFF_ID(mpid, n) \
54 (((mpid) >> MPIDR_AFF_SHIFT(n)) & MPIDR_AFFLVL_MASK)
55
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020056#define MPID_MASK (MPIDR_MT_MASK |\
57 (MPIDR_AFFLVL_MASK << MPIDR_AFF2_SHIFT)|\
58 (MPIDR_AFFLVL_MASK << MPIDR_AFF1_SHIFT)|\
59 (MPIDR_AFFLVL_MASK << MPIDR_AFF0_SHIFT))
60
61/*
62 * An invalid MPID. This value can be used by functions that return an MPID to
63 * indicate an error.
64 */
65#define INVALID_MPID U(0xFFFFFFFF)
66
67/*
68 * The MPIDR_MAX_AFFLVL count starts from 0. Take care to
69 * add one while using this macro to define array sizes.
70 */
71#define MPIDR_MAX_AFFLVL U(2)
72
73/* Data Cache set/way op type defines */
74#define DC_OP_ISW U(0x0)
75#define DC_OP_CISW U(0x1)
76#define DC_OP_CSW U(0x2)
77
78/*******************************************************************************
79 * Generic timer memory mapped registers & offsets
80 ******************************************************************************/
81#define CNTCR_OFF U(0x000)
82#define CNTFID_OFF U(0x020)
83
84#define CNTCR_EN (U(1) << 0)
85#define CNTCR_HDBG (U(1) << 1)
86#define CNTCR_FCREQ(x) ((x) << 8)
87
88/*******************************************************************************
89 * System register bit definitions
90 ******************************************************************************/
91/* CLIDR definitions */
92#define LOUIS_SHIFT U(21)
93#define LOC_SHIFT U(24)
94#define CLIDR_FIELD_WIDTH U(3)
95
96/* CSSELR definitions */
97#define LEVEL_SHIFT U(1)
98
Antonio Nino Diaz69068db2019-01-11 13:01:45 +000099/* ID_MMFR4 definitions */
100#define ID_MMFR4_CNP_SHIFT U(12)
101#define ID_MMFR4_CNP_LENGTH U(4)
102#define ID_MMFR4_CNP_MASK U(0xf)
103
Manish V Badarkhe2c518e52021-07-08 16:36:57 +0100104/* ID_DFR0_EL1 definitions */
105#define ID_DFR0_TRACEFILT_SHIFT U(28)
106#define ID_DFR0_TRACEFILT_MASK U(0xf)
107#define ID_DFR0_TRACEFILT_SUPPORTED U(1)
108
Manish V Badarkhe6d0e1b62021-07-09 13:58:28 +0100109/* ID_DFR0_EL1 definitions */
110#define ID_DFR0_COPTRC_SHIFT U(12)
111#define ID_DFR0_COPTRC_MASK U(0xf)
112#define ID_DFR0_COPTRC_SUPPORTED U(1)
113
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200114/* ID_PFR0 definitions */
115#define ID_PFR0_AMU_SHIFT U(20)
116#define ID_PFR0_AMU_LENGTH U(4)
117#define ID_PFR0_AMU_MASK U(0xf)
johpow01b7d752a2020-10-08 17:29:11 -0500118#define ID_PFR0_AMU_NOT_SUPPORTED U(0x0)
119#define ID_PFR0_AMU_V1 U(0x1)
120#define ID_PFR0_AMU_V1P1 U(0x2)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200121
Antonio Nino Diaz69068db2019-01-11 13:01:45 +0000122#define ID_PFR0_DIT_SHIFT U(24)
123#define ID_PFR0_DIT_LENGTH U(4)
124#define ID_PFR0_DIT_MASK U(0xf)
125#define ID_PFR0_DIT_SUPPORTED (U(1) << ID_PFR0_DIT_SHIFT)
126
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200127/* ID_PFR1 definitions */
128#define ID_PFR1_VIRTEXT_SHIFT U(12)
129#define ID_PFR1_VIRTEXT_MASK U(0xf)
130#define GET_VIRT_EXT(id) (((id) >> ID_PFR1_VIRTEXT_SHIFT) \
131 & ID_PFR1_VIRTEXT_MASK)
Antonio Nino Diazffdfd162019-02-11 15:34:32 +0000132#define ID_PFR1_GENTIMER_SHIFT U(16)
133#define ID_PFR1_GENTIMER_MASK U(0xf)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200134#define ID_PFR1_GIC_SHIFT U(28)
135#define ID_PFR1_GIC_MASK U(0xf)
136
137/* SCTLR definitions */
Antonio Nino Diazdcfc4832018-11-22 15:53:23 +0000138#define SCTLR_RES1_DEF ((U(1) << 23) | (U(1) << 22) | (U(1) << 4) | \
139 (U(1) << 3))
140#if ARM_ARCH_MAJOR == 7
141#define SCTLR_RES1 SCTLR_RES1_DEF
142#else
143#define SCTLR_RES1 (SCTLR_RES1_DEF | (U(1) << 11))
144#endif
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200145#define SCTLR_M_BIT (U(1) << 0)
146#define SCTLR_A_BIT (U(1) << 1)
147#define SCTLR_C_BIT (U(1) << 2)
148#define SCTLR_CP15BEN_BIT (U(1) << 5)
149#define SCTLR_ITD_BIT (U(1) << 7)
150#define SCTLR_Z_BIT (U(1) << 11)
151#define SCTLR_I_BIT (U(1) << 12)
152#define SCTLR_V_BIT (U(1) << 13)
153#define SCTLR_RR_BIT (U(1) << 14)
154#define SCTLR_NTWI_BIT (U(1) << 16)
155#define SCTLR_NTWE_BIT (U(1) << 18)
156#define SCTLR_WXN_BIT (U(1) << 19)
157#define SCTLR_UWXN_BIT (U(1) << 20)
158#define SCTLR_EE_BIT (U(1) << 25)
159#define SCTLR_TRE_BIT (U(1) << 28)
160#define SCTLR_AFE_BIT (U(1) << 29)
161#define SCTLR_TE_BIT (U(1) << 30)
Antonio Nino Diaz69068db2019-01-11 13:01:45 +0000162#define SCTLR_DSSBS_BIT (U(1) << 31)
Antonio Nino Diazdcfc4832018-11-22 15:53:23 +0000163#define SCTLR_RESET_VAL (SCTLR_RES1 | SCTLR_NTWE_BIT | \
164 SCTLR_NTWI_BIT | SCTLR_CP15BEN_BIT)
165
166/* SDCR definitions */
167#define SDCR_SPD(x) ((x) << 14)
168#define SDCR_SPD_LEGACY U(0x0)
169#define SDCR_SPD_DISABLE U(0x2)
170#define SDCR_SPD_ENABLE U(0x3)
Antonio Nino Diazcc023992019-04-04 11:18:32 +0100171#define SDCR_SCCD_BIT (U(1) << 23)
Antonio Nino Diazdcfc4832018-11-22 15:53:23 +0000172#define SDCR_RESET_VAL U(0x0)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200173
174/* HSCTLR definitions */
175#define HSCTLR_RES1 ((U(1) << 29) | (U(1) << 28) | (U(1) << 23) | \
176 (U(1) << 22) | (U(1) << 18) | (U(1) << 16) | \
Antonio Nino Diazdcfc4832018-11-22 15:53:23 +0000177 (U(1) << 11) | (U(1) << 4) | (U(1) << 3))
178
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200179#define HSCTLR_M_BIT (U(1) << 0)
180#define HSCTLR_A_BIT (U(1) << 1)
181#define HSCTLR_C_BIT (U(1) << 2)
182#define HSCTLR_CP15BEN_BIT (U(1) << 5)
183#define HSCTLR_ITD_BIT (U(1) << 7)
184#define HSCTLR_SED_BIT (U(1) << 8)
185#define HSCTLR_I_BIT (U(1) << 12)
186#define HSCTLR_WXN_BIT (U(1) << 19)
187#define HSCTLR_EE_BIT (U(1) << 25)
188#define HSCTLR_TE_BIT (U(1) << 30)
189
190/* CPACR definitions */
191#define CPACR_FPEN(x) ((x) << 20)
192#define CPACR_FP_TRAP_PL0 U(0x1)
193#define CPACR_FP_TRAP_ALL U(0x2)
194#define CPACR_FP_TRAP_NONE U(0x3)
195
196/* SCR definitions */
197#define SCR_TWE_BIT (U(1) << 13)
198#define SCR_TWI_BIT (U(1) << 12)
199#define SCR_SIF_BIT (U(1) << 9)
200#define SCR_HCE_BIT (U(1) << 8)
201#define SCR_SCD_BIT (U(1) << 7)
202#define SCR_NET_BIT (U(1) << 6)
203#define SCR_AW_BIT (U(1) << 5)
204#define SCR_FW_BIT (U(1) << 4)
205#define SCR_EA_BIT (U(1) << 3)
206#define SCR_FIQ_BIT (U(1) << 2)
207#define SCR_IRQ_BIT (U(1) << 1)
208#define SCR_NS_BIT (U(1) << 0)
209#define SCR_VALID_BIT_MASK U(0x33ff)
210#define SCR_RESET_VAL U(0x0)
211
212#define GET_NS_BIT(scr) ((scr) & SCR_NS_BIT)
213
214/* HCR definitions */
215#define HCR_TGE_BIT (U(1) << 27)
216#define HCR_AMO_BIT (U(1) << 5)
217#define HCR_IMO_BIT (U(1) << 4)
218#define HCR_FMO_BIT (U(1) << 3)
219#define HCR_RESET_VAL U(0x0)
220
221/* CNTHCTL definitions */
222#define CNTHCTL_RESET_VAL U(0x0)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200223#define PL1PCEN_BIT (U(1) << 1)
224#define PL1PCTEN_BIT (U(1) << 0)
225
226/* CNTKCTL definitions */
227#define PL0PTEN_BIT (U(1) << 9)
228#define PL0VTEN_BIT (U(1) << 8)
229#define PL0PCTEN_BIT (U(1) << 0)
230#define PL0VCTEN_BIT (U(1) << 1)
231#define EVNTEN_BIT (U(1) << 2)
232#define EVNTDIR_BIT (U(1) << 3)
233#define EVNTI_SHIFT U(4)
234#define EVNTI_MASK U(0xf)
235
236/* HCPTR definitions */
237#define HCPTR_RES1 ((U(1) << 13) | (U(1) << 12) | U(0x3ff))
238#define TCPAC_BIT (U(1) << 31)
239#define TAM_BIT (U(1) << 30)
240#define TTA_BIT (U(1) << 20)
241#define TCP11_BIT (U(1) << 11)
242#define TCP10_BIT (U(1) << 10)
243#define HCPTR_RESET_VAL HCPTR_RES1
244
Antonio Nino Diazdcfc4832018-11-22 15:53:23 +0000245/* VTTBR defintions */
246#define VTTBR_RESET_VAL ULL(0x0)
247#define VTTBR_VMID_MASK ULL(0xff)
248#define VTTBR_VMID_SHIFT U(48)
249#define VTTBR_BADDR_MASK ULL(0xffffffffffff)
250#define VTTBR_BADDR_SHIFT U(0)
251
252/* HDCR definitions */
253#define HDCR_RESET_VAL U(0x0)
254
255/* HSTR definitions */
256#define HSTR_RESET_VAL U(0x0)
257
258/* CNTHP_CTL definitions */
259#define CNTHP_CTL_RESET_VAL U(0x0)
260
261/* NSACR definitions */
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200262#define NSASEDIS_BIT (U(1) << 15)
263#define NSTRCDIS_BIT (U(1) << 20)
264#define NSACR_CP11_BIT (U(1) << 11)
265#define NSACR_CP10_BIT (U(1) << 10)
266#define NSACR_IMP_DEF_MASK (U(0x7) << 16)
267#define NSACR_ENABLE_FP_ACCESS (NSACR_CP11_BIT | NSACR_CP10_BIT)
268#define NSACR_RESET_VAL U(0x0)
269
270/* CPACR definitions */
271#define ASEDIS_BIT (U(1) << 31)
272#define TRCDIS_BIT (U(1) << 28)
273#define CPACR_CP11_SHIFT U(22)
274#define CPACR_CP10_SHIFT U(20)
275#define CPACR_ENABLE_FP_ACCESS ((U(0x3) << CPACR_CP11_SHIFT) |\
276 (U(0x3) << CPACR_CP10_SHIFT))
277#define CPACR_RESET_VAL U(0x0)
278
279/* FPEXC definitions */
280#define FPEXC_RES1 ((U(1) << 10) | (U(1) << 9) | (U(1) << 8))
281#define FPEXC_EN_BIT (U(1) << 30)
282#define FPEXC_RESET_VAL FPEXC_RES1
283
284/* SPSR/CPSR definitions */
285#define SPSR_FIQ_BIT (U(1) << 0)
286#define SPSR_IRQ_BIT (U(1) << 1)
287#define SPSR_ABT_BIT (U(1) << 2)
288#define SPSR_AIF_SHIFT U(6)
289#define SPSR_AIF_MASK U(0x7)
290
291#define SPSR_E_SHIFT U(9)
292#define SPSR_E_MASK U(0x1)
293#define SPSR_E_LITTLE U(0)
294#define SPSR_E_BIG U(1)
295
296#define SPSR_T_SHIFT U(5)
297#define SPSR_T_MASK U(0x1)
298#define SPSR_T_ARM U(0)
299#define SPSR_T_THUMB U(1)
300
301#define SPSR_MODE_SHIFT U(0)
302#define SPSR_MODE_MASK U(0x7)
303
304#define DISABLE_ALL_EXCEPTIONS \
305 (SPSR_FIQ_BIT | SPSR_IRQ_BIT | SPSR_ABT_BIT)
306
Antonio Nino Diaz69068db2019-01-11 13:01:45 +0000307#define CPSR_DIT_BIT (U(1) << 21)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200308/*
309 * TTBCR definitions
310 */
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200311#define TTBCR_EAE_BIT (U(1) << 31)
312
313#define TTBCR_SH1_NON_SHAREABLE (U(0x0) << 28)
314#define TTBCR_SH1_OUTER_SHAREABLE (U(0x2) << 28)
315#define TTBCR_SH1_INNER_SHAREABLE (U(0x3) << 28)
316
317#define TTBCR_RGN1_OUTER_NC (U(0x0) << 26)
318#define TTBCR_RGN1_OUTER_WBA (U(0x1) << 26)
319#define TTBCR_RGN1_OUTER_WT (U(0x2) << 26)
320#define TTBCR_RGN1_OUTER_WBNA (U(0x3) << 26)
321
322#define TTBCR_RGN1_INNER_NC (U(0x0) << 24)
323#define TTBCR_RGN1_INNER_WBA (U(0x1) << 24)
324#define TTBCR_RGN1_INNER_WT (U(0x2) << 24)
325#define TTBCR_RGN1_INNER_WBNA (U(0x3) << 24)
326
327#define TTBCR_EPD1_BIT (U(1) << 23)
328#define TTBCR_A1_BIT (U(1) << 22)
329
330#define TTBCR_T1SZ_SHIFT U(16)
331#define TTBCR_T1SZ_MASK U(0x7)
332#define TTBCR_TxSZ_MIN U(0)
333#define TTBCR_TxSZ_MAX U(7)
334
335#define TTBCR_SH0_NON_SHAREABLE (U(0x0) << 12)
336#define TTBCR_SH0_OUTER_SHAREABLE (U(0x2) << 12)
337#define TTBCR_SH0_INNER_SHAREABLE (U(0x3) << 12)
338
339#define TTBCR_RGN0_OUTER_NC (U(0x0) << 10)
340#define TTBCR_RGN0_OUTER_WBA (U(0x1) << 10)
341#define TTBCR_RGN0_OUTER_WT (U(0x2) << 10)
342#define TTBCR_RGN0_OUTER_WBNA (U(0x3) << 10)
343
344#define TTBCR_RGN0_INNER_NC (U(0x0) << 8)
345#define TTBCR_RGN0_INNER_WBA (U(0x1) << 8)
346#define TTBCR_RGN0_INNER_WT (U(0x2) << 8)
347#define TTBCR_RGN0_INNER_WBNA (U(0x3) << 8)
348
349#define TTBCR_EPD0_BIT (U(1) << 7)
350#define TTBCR_T0SZ_SHIFT U(0)
351#define TTBCR_T0SZ_MASK U(0x7)
352
353/*
354 * HTCR definitions
355 */
Antonio Nino Diazdcfc4832018-11-22 15:53:23 +0000356#define HTCR_RES1 ((U(1) << 31) | (U(1) << 23))
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200357
Antonio Nino Diazdcfc4832018-11-22 15:53:23 +0000358#define HTCR_SH0_NON_SHAREABLE (U(0x0) << 12)
359#define HTCR_SH0_OUTER_SHAREABLE (U(0x2) << 12)
360#define HTCR_SH0_INNER_SHAREABLE (U(0x3) << 12)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200361
Antonio Nino Diazdcfc4832018-11-22 15:53:23 +0000362#define HTCR_RGN0_OUTER_NC (U(0x0) << 10)
363#define HTCR_RGN0_OUTER_WBA (U(0x1) << 10)
364#define HTCR_RGN0_OUTER_WT (U(0x2) << 10)
365#define HTCR_RGN0_OUTER_WBNA (U(0x3) << 10)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200366
Antonio Nino Diazdcfc4832018-11-22 15:53:23 +0000367#define HTCR_RGN0_INNER_NC (U(0x0) << 8)
368#define HTCR_RGN0_INNER_WBA (U(0x1) << 8)
369#define HTCR_RGN0_INNER_WT (U(0x2) << 8)
370#define HTCR_RGN0_INNER_WBNA (U(0x3) << 8)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200371
Antonio Nino Diazdcfc4832018-11-22 15:53:23 +0000372#define HTCR_T0SZ_SHIFT U(0)
373#define HTCR_T0SZ_MASK U(0x7)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200374
375#define MODE_RW_SHIFT U(0x4)
376#define MODE_RW_MASK U(0x1)
377#define MODE_RW_32 U(0x1)
378
379#define MODE32_SHIFT U(0)
380#define MODE32_MASK U(0x1f)
381#define MODE32_usr U(0x10)
382#define MODE32_fiq U(0x11)
383#define MODE32_irq U(0x12)
384#define MODE32_svc U(0x13)
385#define MODE32_mon U(0x16)
386#define MODE32_abt U(0x17)
387#define MODE32_hyp U(0x1a)
388#define MODE32_und U(0x1b)
389#define MODE32_sys U(0x1f)
390
391#define GET_M32(mode) (((mode) >> MODE32_SHIFT) & MODE32_MASK)
392
393#define SPSR_MODE32(mode, isa, endian, aif) \
394 (MODE_RW_32 << MODE_RW_SHIFT | \
395 ((mode) & MODE32_MASK) << MODE32_SHIFT | \
396 ((isa) & SPSR_T_MASK) << SPSR_T_SHIFT | \
397 ((endian) & SPSR_E_MASK) << SPSR_E_SHIFT | \
398 ((aif) & SPSR_AIF_MASK) << SPSR_AIF_SHIFT)
399
400/*
401 * TTBR definitions
402 */
Antonio Nino Diazdcfc4832018-11-22 15:53:23 +0000403#define TTBR_CNP_BIT ULL(0x1)
404
405/*
406 * CTR definitions
407 */
408#define CTR_CWG_SHIFT U(24)
409#define CTR_CWG_MASK U(0xf)
410#define CTR_ERG_SHIFT U(20)
411#define CTR_ERG_MASK U(0xf)
412#define CTR_DMINLINE_SHIFT U(16)
413#define CTR_DMINLINE_WIDTH U(4)
414#define CTR_DMINLINE_MASK ((U(1) << 4) - U(1))
415#define CTR_L1IP_SHIFT U(14)
416#define CTR_L1IP_MASK U(0x3)
417#define CTR_IMINLINE_SHIFT U(0)
418#define CTR_IMINLINE_MASK U(0xf)
419
420#define MAX_CACHE_LINE_SIZE U(0x800) /* 2KB */
421
422/* PMCR definitions */
Petre-Ionut Tudorf1a45f72019-10-08 16:51:45 +0100423#define PMCR_EL0_N_SHIFT U(11)
424#define PMCR_EL0_N_MASK U(0x1f)
425#define PMCR_EL0_N_BITS (PMCR_EL0_N_MASK << PMCR_EL0_N_SHIFT)
426#define PMCR_EL0_LC_BIT (U(1) << 6)
427#define PMCR_EL0_DP_BIT (U(1) << 5)
428#define PMCR_EL0_E_BIT (U(1) << 0)
429
430/* PMCNTENSET definitions */
431#define PMCNTENSET_EL0_C_BIT (U(1) << 31)
432#define PMCNTENSET_EL0_P_BIT(x) (U(1) << x)
433
434/* PMEVTYPER<n> definitions */
435#define PMEVTYPER_EL0_P_BIT (U(1) << 31)
436#define PMEVTYPER_EL0_NSK_BIT (U(1) << 29)
437#define PMEVTYPER_EL0_NSH_BIT (U(1) << 27)
438#define PMEVTYPER_EL0_M_BIT (U(1) << 26)
439#define PMEVTYPER_EL0_MT_BIT (U(1) << 25)
440#define PMEVTYPER_EL0_SH_BIT (U(1) << 24)
441#define PMEVTYPER_EL0_EVTCOUNT_BITS U(0x000003FF)
442
443/* PMCCFILTR definitions */
444#define PMCCFILTR_EL0_P_BIT (U(1) << 31)
AlexeiFedorov2f30f102023-03-13 19:37:46 +0000445#define PMCCFILTR_EL0_U_BIT (U(1) << 30)
Petre-Ionut Tudorf1a45f72019-10-08 16:51:45 +0100446#define PMCCFILTR_EL0_NSK_BIT (U(1) << 29)
AlexeiFedorov2f30f102023-03-13 19:37:46 +0000447#define PMCCFILTR_EL0_NSU_BIT (U(1) << 28)
Petre-Ionut Tudorf1a45f72019-10-08 16:51:45 +0100448#define PMCCFILTR_EL0_NSH_BIT (U(1) << 27)
449#define PMCCFILTR_EL0_M_BIT (U(1) << 26)
Petre-Ionut Tudorf1a45f72019-10-08 16:51:45 +0100450#define PMCCFILTR_EL0_SH_BIT (U(1) << 24)
451
452/* PMU event counter ID definitions */
453#define PMU_EV_PC_WRITE_RETIRED U(0x000C)
454
455/* DBGDIDR definitions */
456#define DBGDIDR_VERSION_SHIFT U(16)
457#define DBGDIDR_VERSION_MASK U(0xf)
458#define DBGDIDR_VERSION_BITS (DBGDIDR_VERSION_MASK << DBGDIDR_VERSION_SHIFT)
459#define DBGDIDR_V8_DEBUG_ARCH_SUPPORTED U(6)
460#define DBGDIDR_V8_DEBUG_ARCH_VHE_SUPPORTED U(7)
461#define DBGDIDR_V8_2_DEBUG_ARCH_SUPPORTED U(8)
462#define DBGDIDR_V8_4_DEBUG_ARCH_SUPPORTED U(9)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200463
464/*******************************************************************************
465 * Definitions of register offsets, fields and macros for CPU system
466 * instructions.
467 ******************************************************************************/
468
469#define TLBI_ADDR_SHIFT U(0)
470#define TLBI_ADDR_MASK U(0xFFFFF000)
471#define TLBI_ADDR(x) (((x) >> TLBI_ADDR_SHIFT) & TLBI_ADDR_MASK)
472
473/*******************************************************************************
Antonio Nino Diazdcfc4832018-11-22 15:53:23 +0000474 * Definitions of register offsets and fields in the CNTCTLBase Frame of the
475 * system level implementation of the Generic Timer.
476 ******************************************************************************/
477#define CNTCTLBASE_CNTFRQ U(0x0)
478#define CNTNSAR U(0x4)
479#define CNTNSAR_NS_SHIFT(x) (x)
480
481#define CNTACR_BASE(x) (U(0x40) + ((x) << 2))
482#define CNTACR_RPCT_SHIFT U(0x0)
483#define CNTACR_RVCT_SHIFT U(0x1)
484#define CNTACR_RFRQ_SHIFT U(0x2)
485#define CNTACR_RVOFF_SHIFT U(0x3)
486#define CNTACR_RWVT_SHIFT U(0x4)
487#define CNTACR_RWPT_SHIFT U(0x5)
488
489/*******************************************************************************
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200490 * Definitions of register offsets and fields in the CNTBaseN Frame of the
491 * system level implementation of the Generic Timer.
492 ******************************************************************************/
493/* Physical Count register. */
Antonio Nino Diazdcfc4832018-11-22 15:53:23 +0000494#define CNTPCT_LO U(0x0)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200495/* Counter Frequency register. */
Antonio Nino Diazdcfc4832018-11-22 15:53:23 +0000496#define CNTBASEN_CNTFRQ U(0x10)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200497/* Physical Timer CompareValue register. */
Antonio Nino Diazdcfc4832018-11-22 15:53:23 +0000498#define CNTP_CVAL_LO U(0x20)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200499/* Physical Timer Control register. */
Antonio Nino Diazdcfc4832018-11-22 15:53:23 +0000500#define CNTP_CTL U(0x2c)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200501
502/* Physical timer control register bit fields shifts and masks */
503#define CNTP_CTL_ENABLE_SHIFT 0
504#define CNTP_CTL_IMASK_SHIFT 1
505#define CNTP_CTL_ISTATUS_SHIFT 2
506
Antonio Nino Diazdcfc4832018-11-22 15:53:23 +0000507#define CNTP_CTL_ENABLE_MASK U(1)
508#define CNTP_CTL_IMASK_MASK U(1)
509#define CNTP_CTL_ISTATUS_MASK U(1)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200510
nabkah01002e5692022-10-10 12:36:46 +0100511/* Exception Syndrome register bits and bobs */
512#define ESR_EC_SHIFT U(26)
513#define ESR_EC_MASK U(0x3f)
514#define ESR_EC_LENGTH U(6)
515#define ESR_ISS_SHIFT U(0x0)
516#define ESR_ISS_MASK U(0x1ffffff)
517#define EC_UNKNOWN U(0x0)
518#define EC_WFE_WFI U(0x1)
519#define EC_CP15_MRC_MCR U(0x3)
520#define EC_CP15_MRRC_MCRR U(0x4)
521#define EC_CP14_MRC_MCR U(0x5)
522#define EC_CP14_LDC_STC U(0x6)
523#define EC_FP_SIMD U(0x7)
524#define EC_CP10_MRC U(0x8)
525#define EC_CP14_MRRC_MCRR U(0xc)
526#define EC_ILLEGAL U(0xe)
527#define EC_SVC U(0x11)
528#define EC_HVC U(0x12)
529#define EC_SMC U(0x13)
530#define EC_IABORT_LOWER_EL U(0x20)
531#define EC_IABORT_CUR_EL U(0x21)
532#define EC_PC_ALIGN U(0x22)
533#define EC_DABORT_LOWER_EL U(0x24)
534#define EC_DABORT_CUR_EL U(0x25)
535#define EC_SP_ALIGN U(0x26)
536#define EC_FP U(0x28)
537#define EC_SERROR U(0x2f)
538/* Data Fault Status code, not all error codes listed */
539#define ISS_DFSC_MASK U(0x3f)
540#define DFSC_EXT_DABORT U(0x10)
541#define DFSC_GPF_DABORT U(0x28)
542/* ISS encoding an exception from HVC or SVC instruction execution */
543#define ISS_HVC_SMC_IMM16_MASK U(0xffff)
544
545/*
546 * External Abort bit in Instruction and Data Aborts synchronous exception
547 * syndromes.
548 */
549#define ESR_ISS_EABORT_EA_BIT U(9)
550
551#define EC_BITS(x) (((x) >> ESR_EC_SHIFT) & ESR_EC_MASK)
552#define ISS_BITS(x) (((x) >> ESR_ISS_SHIFT) & ESR_ISS_MASK)
553
554
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200555/* MAIR macros */
556#define MAIR0_ATTR_SET(attr, index) ((attr) << ((index) << U(3)))
557#define MAIR1_ATTR_SET(attr, index) ((attr) << (((index) - U(3)) << U(3)))
558
559/* System register defines The format is: coproc, opt1, CRn, CRm, opt2 */
560#define SCR p15, 0, c1, c1, 0
561#define SCTLR p15, 0, c1, c0, 0
Antonio Nino Diazdcfc4832018-11-22 15:53:23 +0000562#define ACTLR p15, 0, c1, c0, 1
563#define SDCR p15, 0, c1, c3, 1
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200564#define MPIDR p15, 0, c0, c0, 5
565#define MIDR p15, 0, c0, c0, 0
566#define HVBAR p15, 4, c12, c0, 0
567#define VBAR p15, 0, c12, c0, 0
568#define MVBAR p15, 0, c12, c0, 1
569#define NSACR p15, 0, c1, c1, 2
570#define CPACR p15, 0, c1, c0, 2
571#define DCCIMVAC p15, 0, c7, c14, 1
572#define DCCMVAC p15, 0, c7, c10, 1
573#define DCIMVAC p15, 0, c7, c6, 1
574#define DCCISW p15, 0, c7, c14, 2
575#define DCCSW p15, 0, c7, c10, 2
576#define DCISW p15, 0, c7, c6, 2
577#define CTR p15, 0, c0, c0, 1
578#define CNTFRQ p15, 0, c14, c0, 0
Antonio Nino Diaz69068db2019-01-11 13:01:45 +0000579#define ID_MMFR4 p15, 0, c0, c2, 6
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200580#define ID_PFR0 p15, 0, c0, c1, 0
581#define ID_PFR1 p15, 0, c0, c1, 1
Manish V Badarkhe2c518e52021-07-08 16:36:57 +0100582#define ID_DFR0 p15, 0, c0, c1, 2
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200583#define MAIR0 p15, 0, c10, c2, 0
584#define MAIR1 p15, 0, c10, c2, 1
585#define TTBCR p15, 0, c2, c0, 2
586#define TTBR0 p15, 0, c2, c0, 0
587#define TTBR1 p15, 0, c2, c0, 1
588#define TLBIALL p15, 0, c8, c7, 0
589#define TLBIALLH p15, 4, c8, c7, 0
590#define TLBIALLIS p15, 0, c8, c3, 0
591#define TLBIMVA p15, 0, c8, c7, 1
592#define TLBIMVAA p15, 0, c8, c7, 3
593#define TLBIMVAAIS p15, 0, c8, c3, 3
594#define TLBIMVAHIS p15, 4, c8, c3, 1
595#define BPIALLIS p15, 0, c7, c1, 6
596#define BPIALL p15, 0, c7, c5, 6
Antonio Nino Diazdcfc4832018-11-22 15:53:23 +0000597#define ICIALLU p15, 0, c7, c5, 0
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200598#define HSCTLR p15, 4, c1, c0, 0
599#define HCR p15, 4, c1, c1, 0
600#define HCPTR p15, 4, c1, c1, 2
Antonio Nino Diazdcfc4832018-11-22 15:53:23 +0000601#define HSTR p15, 4, c1, c1, 3
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200602#define CNTHCTL p15, 4, c14, c1, 0
Antonio Nino Diazdcfc4832018-11-22 15:53:23 +0000603#define CNTKCTL p15, 0, c14, c1, 0
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200604#define VPIDR p15, 4, c0, c0, 0
605#define VMPIDR p15, 4, c0, c0, 5
606#define ISR p15, 0, c12, c1, 0
607#define CLIDR p15, 1, c0, c0, 1
608#define CSSELR p15, 2, c0, c0, 0
609#define CCSIDR p15, 1, c0, c0, 0
610#define HTCR p15, 4, c2, c0, 2
611#define HMAIR0 p15, 4, c10, c2, 0
Antonio Nino Diazdcfc4832018-11-22 15:53:23 +0000612#define ATS1CPR p15, 0, c7, c8, 0
613#define ATS1HR p15, 4, c7, c8, 0
614#define DBGOSDLR p14, 0, c1, c3, 4
Sandrine Bailleuxa43b0032019-01-14 14:04:32 +0100615#define HSR p15, 4, c5, c2, 0
Antonio Nino Diazdcfc4832018-11-22 15:53:23 +0000616
617/* Debug register defines. The format is: coproc, opt1, CRn, CRm, opt2 */
618#define HDCR p15, 4, c1, c1, 1
619#define PMCR p15, 0, c9, c12, 0
Petre-Ionut Tudorf1a45f72019-10-08 16:51:45 +0100620#define PMCNTENSET p15, 0, c9, c12, 1
621#define PMCCFILTR p15, 0, c14, c15, 7
622#define PMCCNTR p15, 0, c9, c13, 0
623#define PMEVTYPER0 p15, 0, c14, c12, 0
624#define PMEVCNTR0 p15, 0, c14, c8, 0
625#define DBGDIDR p14, 0, c0, c0, 0
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200626#define CNTHP_TVAL p15, 4, c14, c2, 0
Antonio Nino Diazdcfc4832018-11-22 15:53:23 +0000627#define CNTHP_CTL p15, 4, c14, c2, 1
628
629/* AArch32 coproc registers for 32bit MMU descriptor support */
630#define PRRR p15, 0, c10, c2, 0
631#define NMRR p15, 0, c10, c2, 1
632#define DACR p15, 0, c3, c0, 0
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200633
634/* GICv3 CPU Interface system register defines. The format is: coproc, opt1, CRn, CRm, opt2 */
635#define ICC_IAR1 p15, 0, c12, c12, 0
636#define ICC_IAR0 p15, 0, c12, c8, 0
637#define ICC_EOIR1 p15, 0, c12, c12, 1
638#define ICC_EOIR0 p15, 0, c12, c8, 1
639#define ICC_HPPIR1 p15, 0, c12, c12, 2
640#define ICC_HPPIR0 p15, 0, c12, c8, 2
641#define ICC_BPR1 p15, 0, c12, c12, 3
642#define ICC_BPR0 p15, 0, c12, c8, 3
643#define ICC_DIR p15, 0, c12, c11, 1
644#define ICC_PMR p15, 0, c4, c6, 0
645#define ICC_RPR p15, 0, c12, c11, 3
646#define ICC_CTLR p15, 0, c12, c12, 4
647#define ICC_MCTLR p15, 6, c12, c12, 4
648#define ICC_SRE p15, 0, c12, c12, 5
649#define ICC_HSRE p15, 4, c12, c9, 5
650#define ICC_MSRE p15, 6, c12, c12, 5
651#define ICC_IGRPEN0 p15, 0, c12, c12, 6
652#define ICC_IGRPEN1 p15, 0, c12, c12, 7
653#define ICC_MGRPEN1 p15, 6, c12, c12, 7
654
655/* 64 bit system register defines The format is: coproc, opt1, CRm */
656#define TTBR0_64 p15, 0, c2
657#define TTBR1_64 p15, 1, c2
658#define CNTVOFF_64 p15, 4, c14
659#define VTTBR_64 p15, 6, c2
660#define CNTPCT_64 p15, 0, c14
661#define HTTBR_64 p15, 4, c2
662#define CNTHP_CVAL_64 p15, 6, c14
Antonio Nino Diazdcfc4832018-11-22 15:53:23 +0000663#define PAR_64 p15, 0, c7
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200664
665/* 64 bit GICv3 CPU Interface system register defines. The format is: coproc, opt1, CRm */
666#define ICC_SGI1R_EL1_64 p15, 0, c12
667#define ICC_ASGI1R_EL1_64 p15, 1, c12
668#define ICC_SGI0R_EL1_64 p15, 2, c12
669
670/*******************************************************************************
671 * Definitions of MAIR encodings for device and normal memory
672 ******************************************************************************/
673/*
674 * MAIR encodings for device memory attributes.
675 */
676#define MAIR_DEV_nGnRnE U(0x0)
677#define MAIR_DEV_nGnRE U(0x4)
678#define MAIR_DEV_nGRE U(0x8)
679#define MAIR_DEV_GRE U(0xc)
680
681/*
682 * MAIR encodings for normal memory attributes.
683 *
684 * Cache Policy
685 * WT: Write Through
686 * WB: Write Back
687 * NC: Non-Cacheable
688 *
689 * Transient Hint
690 * NTR: Non-Transient
691 * TR: Transient
692 *
693 * Allocation Policy
694 * RA: Read Allocate
695 * WA: Write Allocate
696 * RWA: Read and Write Allocate
697 * NA: No Allocation
698 */
699#define MAIR_NORM_WT_TR_WA U(0x1)
700#define MAIR_NORM_WT_TR_RA U(0x2)
701#define MAIR_NORM_WT_TR_RWA U(0x3)
702#define MAIR_NORM_NC U(0x4)
703#define MAIR_NORM_WB_TR_WA U(0x5)
704#define MAIR_NORM_WB_TR_RA U(0x6)
705#define MAIR_NORM_WB_TR_RWA U(0x7)
706#define MAIR_NORM_WT_NTR_NA U(0x8)
707#define MAIR_NORM_WT_NTR_WA U(0x9)
708#define MAIR_NORM_WT_NTR_RA U(0xa)
709#define MAIR_NORM_WT_NTR_RWA U(0xb)
710#define MAIR_NORM_WB_NTR_NA U(0xc)
711#define MAIR_NORM_WB_NTR_WA U(0xd)
712#define MAIR_NORM_WB_NTR_RA U(0xe)
713#define MAIR_NORM_WB_NTR_RWA U(0xf)
714
715#define MAIR_NORM_OUTER_SHIFT U(4)
716
717#define MAKE_MAIR_NORMAL_MEMORY(inner, outer) \
718 ((inner) | ((outer) << MAIR_NORM_OUTER_SHIFT))
719
Antonio Nino Diazdcfc4832018-11-22 15:53:23 +0000720/* PAR fields */
721#define PAR_F_SHIFT U(0)
722#define PAR_F_MASK ULL(0x1)
723#define PAR_ADDR_SHIFT U(12)
724#define PAR_ADDR_MASK (BIT_64(40) - ULL(1)) /* 40-bits-wide page address */
725
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200726/*******************************************************************************
727 * Definitions for system register interface to AMU for ARMv8.4 onwards
728 ******************************************************************************/
729#define AMCR p15, 0, c13, c2, 0
730#define AMCFGR p15, 0, c13, c2, 1
731#define AMCGCR p15, 0, c13, c2, 2
732#define AMUSERENR p15, 0, c13, c2, 3
733#define AMCNTENCLR0 p15, 0, c13, c2, 4
734#define AMCNTENSET0 p15, 0, c13, c2, 5
735#define AMCNTENCLR1 p15, 0, c13, c3, 0
736#define AMCNTENSET1 p15, 0, c13, c3, 1
737
738/* Activity Monitor Group 0 Event Counter Registers */
739#define AMEVCNTR00 p15, 0, c0
740#define AMEVCNTR01 p15, 1, c0
741#define AMEVCNTR02 p15, 2, c0
742#define AMEVCNTR03 p15, 3, c0
743
744/* Activity Monitor Group 0 Event Type Registers */
745#define AMEVTYPER00 p15, 0, c13, c6, 0
746#define AMEVTYPER01 p15, 0, c13, c6, 1
747#define AMEVTYPER02 p15, 0, c13, c6, 2
748#define AMEVTYPER03 p15, 0, c13, c6, 3
749
750/* Activity Monitor Group 1 Event Counter Registers */
751#define AMEVCNTR10 p15, 0, c4
752#define AMEVCNTR11 p15, 1, c4
753#define AMEVCNTR12 p15, 2, c4
754#define AMEVCNTR13 p15, 3, c4
755#define AMEVCNTR14 p15, 4, c4
756#define AMEVCNTR15 p15, 5, c4
757#define AMEVCNTR16 p15, 6, c4
758#define AMEVCNTR17 p15, 7, c4
759#define AMEVCNTR18 p15, 0, c5
760#define AMEVCNTR19 p15, 1, c5
761#define AMEVCNTR1A p15, 2, c5
762#define AMEVCNTR1B p15, 3, c5
763#define AMEVCNTR1C p15, 4, c5
764#define AMEVCNTR1D p15, 5, c5
765#define AMEVCNTR1E p15, 6, c5
766#define AMEVCNTR1F p15, 7, c5
767
768/* Activity Monitor Group 1 Event Type Registers */
769#define AMEVTYPER10 p15, 0, c13, c14, 0
770#define AMEVTYPER11 p15, 0, c13, c14, 1
771#define AMEVTYPER12 p15, 0, c13, c14, 2
772#define AMEVTYPER13 p15, 0, c13, c14, 3
773#define AMEVTYPER14 p15, 0, c13, c14, 4
774#define AMEVTYPER15 p15, 0, c13, c14, 5
775#define AMEVTYPER16 p15, 0, c13, c14, 6
776#define AMEVTYPER17 p15, 0, c13, c14, 7
777#define AMEVTYPER18 p15, 0, c13, c15, 0
778#define AMEVTYPER19 p15, 0, c13, c15, 1
779#define AMEVTYPER1A p15, 0, c13, c15, 2
780#define AMEVTYPER1B p15, 0, c13, c15, 3
781#define AMEVTYPER1C p15, 0, c13, c15, 4
782#define AMEVTYPER1D p15, 0, c13, c15, 5
783#define AMEVTYPER1E p15, 0, c13, c15, 6
784#define AMEVTYPER1F p15, 0, c13, c15, 7
785
Manish V Badarkhe2c518e52021-07-08 16:36:57 +0100786/*******************************************************************************
787 * Armv8.4 - Trace Filter System Registers
788 ******************************************************************************/
789#define TRFCR p15, 0, c1, c2, 1
790#define HTRFCR p15, 4, c1, c2, 1
791
Manish V Badarkhe6d0e1b62021-07-09 13:58:28 +0100792/*******************************************************************************
793 * Trace System Registers
794 ******************************************************************************/
795#define TRCAUXCTLR p14, 1, c0, c6, 0
796#define TRCRSR p14, 1, c0, c10, 0
797#define TRCCCCTLR p14, 1, c0, c14, 0
798#define TRCBBCTLR p14, 1, c0, c15, 0
799#define TRCEXTINSELR0 p14, 1, c0, c8, 4
800#define TRCEXTINSELR1 p14, 1, c0, c9, 4
801#define TRCEXTINSELR2 p14, 1, c0, c10, 4
802#define TRCEXTINSELR3 p14, 1, c0, c11, 4
803#define TRCCLAIMSET p14, 1, c7, c8, 6
804#define TRCCLAIMCLR p14, 1, c7, c9, 6
805#define TRCDEVARCH p14, 1, c7, c15, 6
806
Antonio Nino Diazdcfc4832018-11-22 15:53:23 +0000807#endif /* ARCH_H */