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