blob: d70e4c7a1b7e6ad672b8fad550e9d50e9e772c0d [file] [log] [blame]
Soby Mathewc6820d12016-05-09 17:49:55 +01001/*
Antonio Nino Diazac998032017-02-27 17:23:54 +00002 * Copyright (c) 2016-2017, ARM Limited and Contributors. All rights reserved.
Soby Mathewc6820d12016-05-09 17:49:55 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Soby Mathewc6820d12016-05-09 17:49:55 +01005 */
6
7#ifndef __ARCH_H__
8#define __ARCH_H__
9
10/*******************************************************************************
11 * MIDR bit definitions
12 ******************************************************************************/
13#define MIDR_IMPL_MASK 0xff
14#define MIDR_IMPL_SHIFT 24
15#define MIDR_VAR_SHIFT 20
16#define MIDR_VAR_BITS 4
17#define MIDR_REV_SHIFT 0
18#define MIDR_REV_BITS 4
19#define MIDR_PN_MASK 0xfff
20#define MIDR_PN_SHIFT 4
21
22/*******************************************************************************
23 * MPIDR macros
24 ******************************************************************************/
Summer Qin93c812f2017-02-28 16:46:17 +000025#define MPIDR_MT_MASK (1 << 24)
Soby Mathewc6820d12016-05-09 17:49:55 +010026#define MPIDR_CPU_MASK MPIDR_AFFLVL_MASK
27#define MPIDR_CLUSTER_MASK (MPIDR_AFFLVL_MASK << MPIDR_AFFINITY_BITS)
28#define MPIDR_AFFINITY_BITS 8
29#define MPIDR_AFFLVL_MASK 0xff
30#define MPIDR_AFFLVL_SHIFT 3
31#define MPIDR_AFF0_SHIFT 0
32#define MPIDR_AFF1_SHIFT 8
33#define MPIDR_AFF2_SHIFT 16
34#define MPIDR_AFFINITY_MASK 0x00ffffff
35#define MPIDR_AFFLVL0 0
36#define MPIDR_AFFLVL1 1
37#define MPIDR_AFFLVL2 2
38
39#define MPIDR_AFFLVL0_VAL(mpidr) \
40 (((mpidr) >> MPIDR_AFF0_SHIFT) & MPIDR_AFFLVL_MASK)
41#define MPIDR_AFFLVL1_VAL(mpidr) \
42 (((mpidr) >> MPIDR_AFF1_SHIFT) & MPIDR_AFFLVL_MASK)
43#define MPIDR_AFFLVL2_VAL(mpidr) \
44 (((mpidr) >> MPIDR_AFF2_SHIFT) & MPIDR_AFFLVL_MASK)
45
46/*
47 * The MPIDR_MAX_AFFLVL count starts from 0. Take care to
48 * add one while using this macro to define array sizes.
49 */
50#define MPIDR_MAX_AFFLVL 2
51
52/* Data Cache set/way op type defines */
53#define DC_OP_ISW 0x0
54#define DC_OP_CISW 0x1
55#define DC_OP_CSW 0x2
56
57/*******************************************************************************
58 * Generic timer memory mapped registers & offsets
59 ******************************************************************************/
60#define CNTCR_OFF 0x000
61#define CNTFID_OFF 0x020
62
63#define CNTCR_EN (1 << 0)
64#define CNTCR_HDBG (1 << 1)
65#define CNTCR_FCREQ(x) ((x) << 8)
66
67/*******************************************************************************
68 * System register bit definitions
69 ******************************************************************************/
70/* CLIDR definitions */
71#define LOUIS_SHIFT 21
72#define LOC_SHIFT 24
73#define CLIDR_FIELD_WIDTH 3
74
75/* CSSELR definitions */
76#define LEVEL_SHIFT 1
77
78/* ID_PFR1 definitions */
79#define ID_PFR1_VIRTEXT_SHIFT 12
80#define ID_PFR1_VIRTEXT_MASK 0xf
81#define GET_VIRT_EXT(id) (((id) >> ID_PFR1_VIRTEXT_SHIFT) \
82 & ID_PFR1_VIRTEXT_MASK)
83#define ID_PFR1_GIC_SHIFT 28
84#define ID_PFR1_GIC_MASK 0xf
85
86/* SCTLR definitions */
87#define SCTLR_RES1 ((1 << 23) | (1 << 22) | (1 << 11) | (1 << 4) | \
Soby Mathewa993c422016-09-29 14:15:57 +010088 (1 << 3))
Soby Mathewc6820d12016-05-09 17:49:55 +010089#define SCTLR_M_BIT (1 << 0)
90#define SCTLR_A_BIT (1 << 1)
91#define SCTLR_C_BIT (1 << 2)
92#define SCTLR_CP15BEN_BIT (1 << 5)
93#define SCTLR_ITD_BIT (1 << 7)
94#define SCTLR_I_BIT (1 << 12)
95#define SCTLR_V_BIT (1 << 13)
96#define SCTLR_NTWI_BIT (1 << 16)
97#define SCTLR_NTWE_BIT (1 << 18)
98#define SCTLR_WXN_BIT (1 << 19)
99#define SCTLR_UWXN_BIT (1 << 20)
100#define SCTLR_EE_BIT (1 << 25)
101#define SCTLR_TRE_BIT (1 << 28)
102#define SCTLR_AFE_BIT (1 << 29)
103#define SCTLR_TE_BIT (1 << 30)
104
dp-arm595d0d52017-02-08 11:51:50 +0000105/* SDCR definitions */
106#define SDCR_SPD(x) ((x) << 14)
107#define SDCR_SPD_LEGACY 0x0
108#define SDCR_SPD_DISABLE 0x2
109#define SDCR_SPD_ENABLE 0x3
110
111#define SDCR_DEF_VAL SDCR_SPD(SDCR_SPD_DISABLE)
112
Soby Mathewc6820d12016-05-09 17:49:55 +0100113/* HSCTLR definitions */
114#define HSCTLR_RES1 ((1 << 29) | (1 << 28) | (1 << 23) | (1 << 22) \
115 | (1 << 18) | (1 << 16) | (1 << 11) | (1 << 4) \
Soby Mathewa993c422016-09-29 14:15:57 +0100116 | (1 << 3))
Soby Mathewc6820d12016-05-09 17:49:55 +0100117#define HSCTLR_M_BIT (1 << 0)
118#define HSCTLR_A_BIT (1 << 1)
119#define HSCTLR_C_BIT (1 << 2)
120#define HSCTLR_CP15BEN_BIT (1 << 5)
121#define HSCTLR_ITD_BIT (1 << 7)
122#define HSCTLR_SED_BIT (1 << 8)
123#define HSCTLR_I_BIT (1 << 12)
124#define HSCTLR_WXN_BIT (1 << 19)
125#define HSCTLR_EE_BIT (1 << 25)
126#define HSCTLR_TE_BIT (1 << 30)
127
128/* CPACR definitions */
129#define CPACR_FPEN(x) ((x) << 20)
130#define CPACR_FP_TRAP_PL0 0x1
131#define CPACR_FP_TRAP_ALL 0x2
132#define CPACR_FP_TRAP_NONE 0x3
133
134/* SCR definitions */
135#define SCR_TWE_BIT (1 << 13)
136#define SCR_TWI_BIT (1 << 12)
137#define SCR_SIF_BIT (1 << 9)
138#define SCR_HCE_BIT (1 << 8)
139#define SCR_SCD_BIT (1 << 7)
140#define SCR_NET_BIT (1 << 6)
141#define SCR_AW_BIT (1 << 5)
142#define SCR_FW_BIT (1 << 4)
143#define SCR_EA_BIT (1 << 3)
144#define SCR_FIQ_BIT (1 << 2)
145#define SCR_IRQ_BIT (1 << 1)
146#define SCR_NS_BIT (1 << 0)
147#define SCR_VALID_BIT_MASK 0x33ff
148
149#define GET_NS_BIT(scr) ((scr) & SCR_NS_BIT)
150
151/* HCR definitions */
152#define HCR_AMO_BIT (1 << 5)
153#define HCR_IMO_BIT (1 << 4)
154#define HCR_FMO_BIT (1 << 3)
155
156/* CNTHCTL definitions */
157#define EVNTEN_BIT (1 << 2)
158#define PL1PCEN_BIT (1 << 1)
159#define PL1PCTEN_BIT (1 << 0)
160
161/* CNTKCTL definitions */
162#define PL0PTEN_BIT (1 << 9)
163#define PL0VTEN_BIT (1 << 8)
164#define PL0PCTEN_BIT (1 << 0)
165#define PL0VCTEN_BIT (1 << 1)
166#define EVNTEN_BIT (1 << 2)
167#define EVNTDIR_BIT (1 << 3)
168#define EVNTI_SHIFT 4
169#define EVNTI_MASK 0xf
170
171/* HCPTR definitions */
172#define TCPAC_BIT (1 << 31)
173#define TTA_BIT (1 << 20)
174#define TCP11_BIT (1 << 10)
175#define TCP10_BIT (1 << 10)
176
177/* NASCR definitions */
178#define NSASEDIS_BIT (1 << 15)
Yatharth Kocharf528faf2016-06-28 16:58:26 +0100179#define NSTRCDIS_BIT (1 << 20)
Soby Mathewc6820d12016-05-09 17:49:55 +0100180#define NASCR_CP11_BIT (1 << 11)
181#define NASCR_CP10_BIT (1 << 10)
182
183/* CPACR definitions */
184#define ASEDIS_BIT (1 << 31)
185#define TRCDIS_BIT (1 << 28)
186#define CPACR_CP11_SHIFT 22
187#define CPACR_CP10_SHIFT 20
188#define CPACR_ENABLE_FP_ACCESS (0x3 << CPACR_CP11_SHIFT |\
189 0x3 << CPACR_CP10_SHIFT)
190
191/* FPEXC definitions */
192#define FPEXC_EN_BIT (1 << 30)
193
194/* SPSR/CPSR definitions */
195#define SPSR_FIQ_BIT (1 << 0)
196#define SPSR_IRQ_BIT (1 << 1)
197#define SPSR_ABT_BIT (1 << 2)
198#define SPSR_AIF_SHIFT 6
199#define SPSR_AIF_MASK 0x7
200
201#define SPSR_E_SHIFT 9
202#define SPSR_E_MASK 0x1
203#define SPSR_E_LITTLE 0
204#define SPSR_E_BIG 1
205
206#define SPSR_T_SHIFT 5
207#define SPSR_T_MASK 0x1
208#define SPSR_T_ARM 0
209#define SPSR_T_THUMB 1
210
211#define SPSR_MODE_SHIFT 0
212#define SPSR_MODE_MASK 0x7
213
214
215#define DISABLE_ALL_EXCEPTIONS \
216 (SPSR_FIQ_BIT | SPSR_IRQ_BIT | SPSR_ABT_BIT)
217
218/*
219 * TTBCR definitions
220 */
221/* The ARM Trusted Firmware uses the long descriptor format */
222#define TTBCR_EAE_BIT (1 << 31)
223
224#define TTBCR_SH1_NON_SHAREABLE (0x0 << 28)
225#define TTBCR_SH1_OUTER_SHAREABLE (0x2 << 28)
226#define TTBCR_SH1_INNER_SHAREABLE (0x3 << 28)
227
228#define TTBCR_RGN1_OUTER_NC (0x0 << 26)
229#define TTBCR_RGN1_OUTER_WBA (0x1 << 26)
230#define TTBCR_RGN1_OUTER_WT (0x2 << 26)
231#define TTBCR_RGN1_OUTER_WBNA (0x3 << 26)
232
233#define TTBCR_RGN1_INNER_NC (0x0 << 24)
234#define TTBCR_RGN1_INNER_WBA (0x1 << 24)
235#define TTBCR_RGN1_INNER_WT (0x2 << 24)
236#define TTBCR_RGN1_INNER_WBNA (0x3 << 24)
237
238#define TTBCR_EPD1_BIT (1 << 23)
239#define TTBCR_A1_BIT (1 << 22)
240
241#define TTBCR_T1SZ_SHIFT 16
242#define TTBCR_T1SZ_MASK (0x7)
Antonio Nino Diazd48ae612016-08-02 09:21:41 +0100243#define TTBCR_TxSZ_MIN 0
244#define TTBCR_TxSZ_MAX 7
Soby Mathewc6820d12016-05-09 17:49:55 +0100245
246#define TTBCR_SH0_NON_SHAREABLE (0x0 << 12)
247#define TTBCR_SH0_OUTER_SHAREABLE (0x2 << 12)
248#define TTBCR_SH0_INNER_SHAREABLE (0x3 << 12)
249
250#define TTBCR_RGN0_OUTER_NC (0x0 << 10)
251#define TTBCR_RGN0_OUTER_WBA (0x1 << 10)
252#define TTBCR_RGN0_OUTER_WT (0x2 << 10)
253#define TTBCR_RGN0_OUTER_WBNA (0x3 << 10)
254
255#define TTBCR_RGN0_INNER_NC (0x0 << 8)
256#define TTBCR_RGN0_INNER_WBA (0x1 << 8)
257#define TTBCR_RGN0_INNER_WT (0x2 << 8)
258#define TTBCR_RGN0_INNER_WBNA (0x3 << 8)
259
260#define TTBCR_EPD0_BIT (1 << 7)
261#define TTBCR_T0SZ_SHIFT 0
262#define TTBCR_T0SZ_MASK (0x7)
263
264#define MODE_RW_SHIFT 0x4
265#define MODE_RW_MASK 0x1
266#define MODE_RW_32 0x1
267
268#define MODE32_SHIFT 0
269#define MODE32_MASK 0x1f
270#define MODE32_usr 0x10
271#define MODE32_fiq 0x11
272#define MODE32_irq 0x12
273#define MODE32_svc 0x13
274#define MODE32_mon 0x16
275#define MODE32_abt 0x17
276#define MODE32_hyp 0x1a
277#define MODE32_und 0x1b
278#define MODE32_sys 0x1f
279
280#define GET_M32(mode) (((mode) >> MODE32_SHIFT) & MODE32_MASK)
281
282#define SPSR_MODE32(mode, isa, endian, aif) \
283 (MODE_RW_32 << MODE_RW_SHIFT | \
284 ((mode) & MODE32_MASK) << MODE32_SHIFT | \
285 ((isa) & SPSR_T_MASK) << SPSR_T_SHIFT | \
286 ((endian) & SPSR_E_MASK) << SPSR_E_SHIFT | \
287 ((aif) & SPSR_AIF_MASK) << SPSR_AIF_SHIFT)
288
289/*
290 * CTR definitions
291 */
292#define CTR_CWG_SHIFT 24
293#define CTR_CWG_MASK 0xf
294#define CTR_ERG_SHIFT 20
295#define CTR_ERG_MASK 0xf
296#define CTR_DMINLINE_SHIFT 16
297#define CTR_DMINLINE_WIDTH 4
298#define CTR_DMINLINE_MASK ((1 << 4) - 1)
299#define CTR_L1IP_SHIFT 14
300#define CTR_L1IP_MASK 0x3
301#define CTR_IMINLINE_SHIFT 0
302#define CTR_IMINLINE_MASK 0xf
303
304#define MAX_CACHE_LINE_SIZE 0x800 /* 2KB */
305
David Cunado5f55e282016-10-31 17:37:34 +0000306/* PMCR definitions */
307#define PMCR_N_SHIFT 11
308#define PMCR_N_MASK 0x1f
309#define PMCR_N_BITS (PMCR_N_MASK << PMCR_N_SHIFT)
310
Soby Mathewc6820d12016-05-09 17:49:55 +0100311/*******************************************************************************
Antonio Nino Diazac998032017-02-27 17:23:54 +0000312 * Definitions of register offsets, fields and macros for CPU system
313 * instructions.
314 ******************************************************************************/
315
316#define TLBI_ADDR_SHIFT 0
317#define TLBI_ADDR_MASK 0xFFFFF000
318#define TLBI_ADDR(x) (((x) >> TLBI_ADDR_SHIFT) & TLBI_ADDR_MASK)
319
320/*******************************************************************************
Soby Mathewc6820d12016-05-09 17:49:55 +0100321 * Definitions of register offsets and fields in the CNTCTLBase Frame of the
322 * system level implementation of the Generic Timer.
323 ******************************************************************************/
324#define CNTNSAR 0x4
325#define CNTNSAR_NS_SHIFT(x) (x)
326
327#define CNTACR_BASE(x) (0x40 + ((x) << 2))
328#define CNTACR_RPCT_SHIFT 0x0
329#define CNTACR_RVCT_SHIFT 0x1
330#define CNTACR_RFRQ_SHIFT 0x2
331#define CNTACR_RVOFF_SHIFT 0x3
332#define CNTACR_RWVT_SHIFT 0x4
333#define CNTACR_RWPT_SHIFT 0x5
334
335/* MAIR macros */
336#define MAIR0_ATTR_SET(attr, index) ((attr) << ((index) << 3))
337#define MAIR1_ATTR_SET(attr, index) ((attr) << (((index) - 3) << 3))
338
339/* System register defines The format is: coproc, opt1, CRn, CRm, opt2 */
340#define SCR p15, 0, c1, c1, 0
341#define SCTLR p15, 0, c1, c0, 0
dp-arm595d0d52017-02-08 11:51:50 +0000342#define SDCR p15, 0, c1, c3, 1
Soby Mathewc6820d12016-05-09 17:49:55 +0100343#define MPIDR p15, 0, c0, c0, 5
344#define MIDR p15, 0, c0, c0, 0
345#define VBAR p15, 0, c12, c0, 0
346#define MVBAR p15, 0, c12, c0, 1
347#define NSACR p15, 0, c1, c1, 2
348#define CPACR p15, 0, c1, c0, 2
349#define DCCIMVAC p15, 0, c7, c14, 1
350#define DCCMVAC p15, 0, c7, c10, 1
351#define DCIMVAC p15, 0, c7, c6, 1
352#define DCCISW p15, 0, c7, c14, 2
353#define DCCSW p15, 0, c7, c10, 2
354#define DCISW p15, 0, c7, c6, 2
355#define CTR p15, 0, c0, c0, 1
356#define CNTFRQ p15, 0, c14, c0, 0
357#define ID_PFR1 p15, 0, c0, c1, 1
358#define MAIR0 p15, 0, c10, c2, 0
359#define MAIR1 p15, 0, c10, c2, 1
360#define TTBCR p15, 0, c2, c0, 2
361#define TTBR0 p15, 0, c2, c0, 0
362#define TTBR1 p15, 0, c2, c0, 1
363#define TLBIALL p15, 0, c8, c7, 0
364#define TLBIALLIS p15, 0, c8, c3, 0
365#define TLBIMVA p15, 0, c8, c7, 1
366#define TLBIMVAA p15, 0, c8, c7, 3
Antonio Nino Diazac998032017-02-27 17:23:54 +0000367#define TLBIMVAAIS p15, 0, c8, c3, 3
368#define BPIALLIS p15, 0, c7, c1, 6
Soby Mathewc6820d12016-05-09 17:49:55 +0100369#define HSCTLR p15, 4, c1, c0, 0
370#define HCR p15, 4, c1, c1, 0
371#define HCPTR p15, 4, c1, c1, 2
372#define CNTHCTL p15, 4, c14, c1, 0
Yatharth Kochar2694cba2016-11-14 12:00:41 +0000373#define CNTKCTL p15, 0, c14, c1, 0
Soby Mathewc6820d12016-05-09 17:49:55 +0100374#define VPIDR p15, 4, c0, c0, 0
375#define VMPIDR p15, 4, c0, c0, 5
376#define ISR p15, 0, c12, c1, 0
377#define CLIDR p15, 1, c0, c0, 1
378#define CSSELR p15, 2, c0, c0, 0
379#define CCSIDR p15, 1, c0, c0, 0
Yatharth Kochara9f776c2016-11-10 16:17:51 +0000380#define DBGOSDLR p14, 0, c1, c3, 4
Soby Mathewc6820d12016-05-09 17:49:55 +0100381
David Cunado5f55e282016-10-31 17:37:34 +0000382/* Debug register defines. The format is: coproc, opt1, CRn, CRm, opt2 */
383#define HDCR p15, 4, c1, c1, 1
David Cunado5f55e282016-10-31 17:37:34 +0000384#define PMCR p15, 0, c9, c12, 0
David Cunadoc14b08e2016-11-25 00:21:59 +0000385#define CNTHP_CTL p15, 4, c14, c2, 1
David Cunado5f55e282016-10-31 17:37:34 +0000386
Soby Mathewc6820d12016-05-09 17:49:55 +0100387/* GICv3 CPU Interface system register defines. The format is: coproc, opt1, CRn, CRm, opt2 */
388#define ICC_IAR1 p15, 0, c12, c12, 0
389#define ICC_IAR0 p15, 0, c12, c8, 0
390#define ICC_EOIR1 p15, 0, c12, c12, 1
391#define ICC_EOIR0 p15, 0, c12, c8, 1
392#define ICC_HPPIR1 p15, 0, c12, c12, 2
393#define ICC_HPPIR0 p15, 0, c12, c8, 2
394#define ICC_BPR1 p15, 0, c12, c12, 3
395#define ICC_BPR0 p15, 0, c12, c8, 3
396#define ICC_DIR p15, 0, c12, c11, 1
397#define ICC_PMR p15, 0, c4, c6, 0
398#define ICC_RPR p15, 0, c12, c11, 3
399#define ICC_CTLR p15, 0, c12, c12, 4
400#define ICC_MCTLR p15, 6, c12, c12, 4
401#define ICC_SRE p15, 0, c12, c12, 5
402#define ICC_HSRE p15, 4, c12, c9, 5
403#define ICC_MSRE p15, 6, c12, c12, 5
404#define ICC_IGRPEN0 p15, 0, c12, c12, 6
405#define ICC_IGRPEN1 p15, 0, c12, c12, 7
406#define ICC_MGRPEN1 p15, 6, c12, c12, 7
407
408/* 64 bit system register defines The format is: coproc, opt1, CRm */
409#define TTBR0_64 p15, 0, c2
410#define TTBR1_64 p15, 1, c2
411#define CNTVOFF_64 p15, 4, c14
412#define VTTBR_64 p15, 6, c2
413#define CNTPCT_64 p15, 0, c14
414
415/* 64 bit GICv3 CPU Interface system register defines. The format is: coproc, opt1, CRm */
416#define ICC_SGI1R_EL1_64 p15, 0, c12
417#define ICC_ASGI1R_EL1_64 p15, 1, c12
418#define ICC_SGI0R_EL1_64 p15, 2, c12
419
420#endif /* __ARCH_H__ */