blob: 8525c7babd7c8b497dcdc9a2af4a9b8b6d8cdfd7 [file] [log] [blame]
Soby Mathewc6820d12016-05-09 17:49:55 +01001/*
2 * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9 *
10 * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * Neither the name of ARM nor the names of its contributors may be used
15 * to endorse or promote products derived from this software without specific
16 * prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#ifndef __ARCH_H__
32#define __ARCH_H__
33
34/*******************************************************************************
35 * MIDR bit definitions
36 ******************************************************************************/
37#define MIDR_IMPL_MASK 0xff
38#define MIDR_IMPL_SHIFT 24
39#define MIDR_VAR_SHIFT 20
40#define MIDR_VAR_BITS 4
41#define MIDR_REV_SHIFT 0
42#define MIDR_REV_BITS 4
43#define MIDR_PN_MASK 0xfff
44#define MIDR_PN_SHIFT 4
45
46/*******************************************************************************
47 * MPIDR macros
48 ******************************************************************************/
49#define MPIDR_CPU_MASK MPIDR_AFFLVL_MASK
50#define MPIDR_CLUSTER_MASK (MPIDR_AFFLVL_MASK << MPIDR_AFFINITY_BITS)
51#define MPIDR_AFFINITY_BITS 8
52#define MPIDR_AFFLVL_MASK 0xff
53#define MPIDR_AFFLVL_SHIFT 3
54#define MPIDR_AFF0_SHIFT 0
55#define MPIDR_AFF1_SHIFT 8
56#define MPIDR_AFF2_SHIFT 16
57#define MPIDR_AFFINITY_MASK 0x00ffffff
58#define MPIDR_AFFLVL0 0
59#define MPIDR_AFFLVL1 1
60#define MPIDR_AFFLVL2 2
61
62#define MPIDR_AFFLVL0_VAL(mpidr) \
63 (((mpidr) >> MPIDR_AFF0_SHIFT) & MPIDR_AFFLVL_MASK)
64#define MPIDR_AFFLVL1_VAL(mpidr) \
65 (((mpidr) >> MPIDR_AFF1_SHIFT) & MPIDR_AFFLVL_MASK)
66#define MPIDR_AFFLVL2_VAL(mpidr) \
67 (((mpidr) >> MPIDR_AFF2_SHIFT) & MPIDR_AFFLVL_MASK)
68
69/*
70 * The MPIDR_MAX_AFFLVL count starts from 0. Take care to
71 * add one while using this macro to define array sizes.
72 */
73#define MPIDR_MAX_AFFLVL 2
74
75/* Data Cache set/way op type defines */
76#define DC_OP_ISW 0x0
77#define DC_OP_CISW 0x1
78#define DC_OP_CSW 0x2
79
80/*******************************************************************************
81 * Generic timer memory mapped registers & offsets
82 ******************************************************************************/
83#define CNTCR_OFF 0x000
84#define CNTFID_OFF 0x020
85
86#define CNTCR_EN (1 << 0)
87#define CNTCR_HDBG (1 << 1)
88#define CNTCR_FCREQ(x) ((x) << 8)
89
90/*******************************************************************************
91 * System register bit definitions
92 ******************************************************************************/
93/* CLIDR definitions */
94#define LOUIS_SHIFT 21
95#define LOC_SHIFT 24
96#define CLIDR_FIELD_WIDTH 3
97
98/* CSSELR definitions */
99#define LEVEL_SHIFT 1
100
101/* ID_PFR1 definitions */
102#define ID_PFR1_VIRTEXT_SHIFT 12
103#define ID_PFR1_VIRTEXT_MASK 0xf
104#define GET_VIRT_EXT(id) (((id) >> ID_PFR1_VIRTEXT_SHIFT) \
105 & ID_PFR1_VIRTEXT_MASK)
106#define ID_PFR1_GIC_SHIFT 28
107#define ID_PFR1_GIC_MASK 0xf
108
109/* SCTLR definitions */
110#define SCTLR_RES1 ((1 << 23) | (1 << 22) | (1 << 11) | (1 << 4) | \
Soby Mathewa993c422016-09-29 14:15:57 +0100111 (1 << 3))
Soby Mathewc6820d12016-05-09 17:49:55 +0100112#define SCTLR_M_BIT (1 << 0)
113#define SCTLR_A_BIT (1 << 1)
114#define SCTLR_C_BIT (1 << 2)
115#define SCTLR_CP15BEN_BIT (1 << 5)
116#define SCTLR_ITD_BIT (1 << 7)
117#define SCTLR_I_BIT (1 << 12)
118#define SCTLR_V_BIT (1 << 13)
119#define SCTLR_NTWI_BIT (1 << 16)
120#define SCTLR_NTWE_BIT (1 << 18)
121#define SCTLR_WXN_BIT (1 << 19)
122#define SCTLR_UWXN_BIT (1 << 20)
123#define SCTLR_EE_BIT (1 << 25)
124#define SCTLR_TRE_BIT (1 << 28)
125#define SCTLR_AFE_BIT (1 << 29)
126#define SCTLR_TE_BIT (1 << 30)
127
dp-arm595d0d52017-02-08 11:51:50 +0000128/* SDCR definitions */
129#define SDCR_SPD(x) ((x) << 14)
130#define SDCR_SPD_LEGACY 0x0
131#define SDCR_SPD_DISABLE 0x2
132#define SDCR_SPD_ENABLE 0x3
133
134#define SDCR_DEF_VAL SDCR_SPD(SDCR_SPD_DISABLE)
135
Soby Mathewc6820d12016-05-09 17:49:55 +0100136/* HSCTLR definitions */
137#define HSCTLR_RES1 ((1 << 29) | (1 << 28) | (1 << 23) | (1 << 22) \
138 | (1 << 18) | (1 << 16) | (1 << 11) | (1 << 4) \
Soby Mathewa993c422016-09-29 14:15:57 +0100139 | (1 << 3))
Soby Mathewc6820d12016-05-09 17:49:55 +0100140#define HSCTLR_M_BIT (1 << 0)
141#define HSCTLR_A_BIT (1 << 1)
142#define HSCTLR_C_BIT (1 << 2)
143#define HSCTLR_CP15BEN_BIT (1 << 5)
144#define HSCTLR_ITD_BIT (1 << 7)
145#define HSCTLR_SED_BIT (1 << 8)
146#define HSCTLR_I_BIT (1 << 12)
147#define HSCTLR_WXN_BIT (1 << 19)
148#define HSCTLR_EE_BIT (1 << 25)
149#define HSCTLR_TE_BIT (1 << 30)
150
151/* CPACR definitions */
152#define CPACR_FPEN(x) ((x) << 20)
153#define CPACR_FP_TRAP_PL0 0x1
154#define CPACR_FP_TRAP_ALL 0x2
155#define CPACR_FP_TRAP_NONE 0x3
156
157/* SCR definitions */
158#define SCR_TWE_BIT (1 << 13)
159#define SCR_TWI_BIT (1 << 12)
160#define SCR_SIF_BIT (1 << 9)
161#define SCR_HCE_BIT (1 << 8)
162#define SCR_SCD_BIT (1 << 7)
163#define SCR_NET_BIT (1 << 6)
164#define SCR_AW_BIT (1 << 5)
165#define SCR_FW_BIT (1 << 4)
166#define SCR_EA_BIT (1 << 3)
167#define SCR_FIQ_BIT (1 << 2)
168#define SCR_IRQ_BIT (1 << 1)
169#define SCR_NS_BIT (1 << 0)
170#define SCR_VALID_BIT_MASK 0x33ff
171
172#define GET_NS_BIT(scr) ((scr) & SCR_NS_BIT)
173
174/* HCR definitions */
175#define HCR_AMO_BIT (1 << 5)
176#define HCR_IMO_BIT (1 << 4)
177#define HCR_FMO_BIT (1 << 3)
178
179/* CNTHCTL definitions */
180#define EVNTEN_BIT (1 << 2)
181#define PL1PCEN_BIT (1 << 1)
182#define PL1PCTEN_BIT (1 << 0)
183
184/* CNTKCTL definitions */
185#define PL0PTEN_BIT (1 << 9)
186#define PL0VTEN_BIT (1 << 8)
187#define PL0PCTEN_BIT (1 << 0)
188#define PL0VCTEN_BIT (1 << 1)
189#define EVNTEN_BIT (1 << 2)
190#define EVNTDIR_BIT (1 << 3)
191#define EVNTI_SHIFT 4
192#define EVNTI_MASK 0xf
193
194/* HCPTR definitions */
195#define TCPAC_BIT (1 << 31)
196#define TTA_BIT (1 << 20)
197#define TCP11_BIT (1 << 10)
198#define TCP10_BIT (1 << 10)
199
200/* NASCR definitions */
201#define NSASEDIS_BIT (1 << 15)
Yatharth Kocharf528faf2016-06-28 16:58:26 +0100202#define NSTRCDIS_BIT (1 << 20)
Soby Mathewc6820d12016-05-09 17:49:55 +0100203#define NASCR_CP11_BIT (1 << 11)
204#define NASCR_CP10_BIT (1 << 10)
205
206/* CPACR definitions */
207#define ASEDIS_BIT (1 << 31)
208#define TRCDIS_BIT (1 << 28)
209#define CPACR_CP11_SHIFT 22
210#define CPACR_CP10_SHIFT 20
211#define CPACR_ENABLE_FP_ACCESS (0x3 << CPACR_CP11_SHIFT |\
212 0x3 << CPACR_CP10_SHIFT)
213
214/* FPEXC definitions */
215#define FPEXC_EN_BIT (1 << 30)
216
217/* SPSR/CPSR definitions */
218#define SPSR_FIQ_BIT (1 << 0)
219#define SPSR_IRQ_BIT (1 << 1)
220#define SPSR_ABT_BIT (1 << 2)
221#define SPSR_AIF_SHIFT 6
222#define SPSR_AIF_MASK 0x7
223
224#define SPSR_E_SHIFT 9
225#define SPSR_E_MASK 0x1
226#define SPSR_E_LITTLE 0
227#define SPSR_E_BIG 1
228
229#define SPSR_T_SHIFT 5
230#define SPSR_T_MASK 0x1
231#define SPSR_T_ARM 0
232#define SPSR_T_THUMB 1
233
234#define SPSR_MODE_SHIFT 0
235#define SPSR_MODE_MASK 0x7
236
237
238#define DISABLE_ALL_EXCEPTIONS \
239 (SPSR_FIQ_BIT | SPSR_IRQ_BIT | SPSR_ABT_BIT)
240
241/*
242 * TTBCR definitions
243 */
244/* The ARM Trusted Firmware uses the long descriptor format */
245#define TTBCR_EAE_BIT (1 << 31)
246
247#define TTBCR_SH1_NON_SHAREABLE (0x0 << 28)
248#define TTBCR_SH1_OUTER_SHAREABLE (0x2 << 28)
249#define TTBCR_SH1_INNER_SHAREABLE (0x3 << 28)
250
251#define TTBCR_RGN1_OUTER_NC (0x0 << 26)
252#define TTBCR_RGN1_OUTER_WBA (0x1 << 26)
253#define TTBCR_RGN1_OUTER_WT (0x2 << 26)
254#define TTBCR_RGN1_OUTER_WBNA (0x3 << 26)
255
256#define TTBCR_RGN1_INNER_NC (0x0 << 24)
257#define TTBCR_RGN1_INNER_WBA (0x1 << 24)
258#define TTBCR_RGN1_INNER_WT (0x2 << 24)
259#define TTBCR_RGN1_INNER_WBNA (0x3 << 24)
260
261#define TTBCR_EPD1_BIT (1 << 23)
262#define TTBCR_A1_BIT (1 << 22)
263
264#define TTBCR_T1SZ_SHIFT 16
265#define TTBCR_T1SZ_MASK (0x7)
Antonio Nino Diazd48ae612016-08-02 09:21:41 +0100266#define TTBCR_TxSZ_MIN 0
267#define TTBCR_TxSZ_MAX 7
Soby Mathewc6820d12016-05-09 17:49:55 +0100268
269#define TTBCR_SH0_NON_SHAREABLE (0x0 << 12)
270#define TTBCR_SH0_OUTER_SHAREABLE (0x2 << 12)
271#define TTBCR_SH0_INNER_SHAREABLE (0x3 << 12)
272
273#define TTBCR_RGN0_OUTER_NC (0x0 << 10)
274#define TTBCR_RGN0_OUTER_WBA (0x1 << 10)
275#define TTBCR_RGN0_OUTER_WT (0x2 << 10)
276#define TTBCR_RGN0_OUTER_WBNA (0x3 << 10)
277
278#define TTBCR_RGN0_INNER_NC (0x0 << 8)
279#define TTBCR_RGN0_INNER_WBA (0x1 << 8)
280#define TTBCR_RGN0_INNER_WT (0x2 << 8)
281#define TTBCR_RGN0_INNER_WBNA (0x3 << 8)
282
283#define TTBCR_EPD0_BIT (1 << 7)
284#define TTBCR_T0SZ_SHIFT 0
285#define TTBCR_T0SZ_MASK (0x7)
286
287#define MODE_RW_SHIFT 0x4
288#define MODE_RW_MASK 0x1
289#define MODE_RW_32 0x1
290
291#define MODE32_SHIFT 0
292#define MODE32_MASK 0x1f
293#define MODE32_usr 0x10
294#define MODE32_fiq 0x11
295#define MODE32_irq 0x12
296#define MODE32_svc 0x13
297#define MODE32_mon 0x16
298#define MODE32_abt 0x17
299#define MODE32_hyp 0x1a
300#define MODE32_und 0x1b
301#define MODE32_sys 0x1f
302
303#define GET_M32(mode) (((mode) >> MODE32_SHIFT) & MODE32_MASK)
304
305#define SPSR_MODE32(mode, isa, endian, aif) \
306 (MODE_RW_32 << MODE_RW_SHIFT | \
307 ((mode) & MODE32_MASK) << MODE32_SHIFT | \
308 ((isa) & SPSR_T_MASK) << SPSR_T_SHIFT | \
309 ((endian) & SPSR_E_MASK) << SPSR_E_SHIFT | \
310 ((aif) & SPSR_AIF_MASK) << SPSR_AIF_SHIFT)
311
312/*
313 * CTR definitions
314 */
315#define CTR_CWG_SHIFT 24
316#define CTR_CWG_MASK 0xf
317#define CTR_ERG_SHIFT 20
318#define CTR_ERG_MASK 0xf
319#define CTR_DMINLINE_SHIFT 16
320#define CTR_DMINLINE_WIDTH 4
321#define CTR_DMINLINE_MASK ((1 << 4) - 1)
322#define CTR_L1IP_SHIFT 14
323#define CTR_L1IP_MASK 0x3
324#define CTR_IMINLINE_SHIFT 0
325#define CTR_IMINLINE_MASK 0xf
326
327#define MAX_CACHE_LINE_SIZE 0x800 /* 2KB */
328
David Cunado5f55e282016-10-31 17:37:34 +0000329/* PMCR definitions */
330#define PMCR_N_SHIFT 11
331#define PMCR_N_MASK 0x1f
332#define PMCR_N_BITS (PMCR_N_MASK << PMCR_N_SHIFT)
333
Soby Mathewc6820d12016-05-09 17:49:55 +0100334/*******************************************************************************
335 * Definitions of register offsets and fields in the CNTCTLBase Frame of the
336 * system level implementation of the Generic Timer.
337 ******************************************************************************/
338#define CNTNSAR 0x4
339#define CNTNSAR_NS_SHIFT(x) (x)
340
341#define CNTACR_BASE(x) (0x40 + ((x) << 2))
342#define CNTACR_RPCT_SHIFT 0x0
343#define CNTACR_RVCT_SHIFT 0x1
344#define CNTACR_RFRQ_SHIFT 0x2
345#define CNTACR_RVOFF_SHIFT 0x3
346#define CNTACR_RWVT_SHIFT 0x4
347#define CNTACR_RWPT_SHIFT 0x5
348
349/* MAIR macros */
350#define MAIR0_ATTR_SET(attr, index) ((attr) << ((index) << 3))
351#define MAIR1_ATTR_SET(attr, index) ((attr) << (((index) - 3) << 3))
352
353/* System register defines The format is: coproc, opt1, CRn, CRm, opt2 */
354#define SCR p15, 0, c1, c1, 0
355#define SCTLR p15, 0, c1, c0, 0
dp-arm595d0d52017-02-08 11:51:50 +0000356#define SDCR p15, 0, c1, c3, 1
Soby Mathewc6820d12016-05-09 17:49:55 +0100357#define MPIDR p15, 0, c0, c0, 5
358#define MIDR p15, 0, c0, c0, 0
359#define VBAR p15, 0, c12, c0, 0
360#define MVBAR p15, 0, c12, c0, 1
361#define NSACR p15, 0, c1, c1, 2
362#define CPACR p15, 0, c1, c0, 2
363#define DCCIMVAC p15, 0, c7, c14, 1
364#define DCCMVAC p15, 0, c7, c10, 1
365#define DCIMVAC p15, 0, c7, c6, 1
366#define DCCISW p15, 0, c7, c14, 2
367#define DCCSW p15, 0, c7, c10, 2
368#define DCISW p15, 0, c7, c6, 2
369#define CTR p15, 0, c0, c0, 1
370#define CNTFRQ p15, 0, c14, c0, 0
371#define ID_PFR1 p15, 0, c0, c1, 1
372#define MAIR0 p15, 0, c10, c2, 0
373#define MAIR1 p15, 0, c10, c2, 1
374#define TTBCR p15, 0, c2, c0, 2
375#define TTBR0 p15, 0, c2, c0, 0
376#define TTBR1 p15, 0, c2, c0, 1
377#define TLBIALL p15, 0, c8, c7, 0
378#define TLBIALLIS p15, 0, c8, c3, 0
379#define TLBIMVA p15, 0, c8, c7, 1
380#define TLBIMVAA p15, 0, c8, c7, 3
381#define HSCTLR p15, 4, c1, c0, 0
382#define HCR p15, 4, c1, c1, 0
383#define HCPTR p15, 4, c1, c1, 2
384#define CNTHCTL p15, 4, c14, c1, 0
385#define VPIDR p15, 4, c0, c0, 0
386#define VMPIDR p15, 4, c0, c0, 5
387#define ISR p15, 0, c12, c1, 0
388#define CLIDR p15, 1, c0, c0, 1
389#define CSSELR p15, 2, c0, c0, 0
390#define CCSIDR p15, 1, c0, c0, 0
391
David Cunado5f55e282016-10-31 17:37:34 +0000392/* Debug register defines. The format is: coproc, opt1, CRn, CRm, opt2 */
393#define HDCR p15, 4, c1, c1, 1
David Cunado5f55e282016-10-31 17:37:34 +0000394#define PMCR p15, 0, c9, c12, 0
David Cunadoc14b08e2016-11-25 00:21:59 +0000395#define CNTHP_CTL p15, 4, c14, c2, 1
David Cunado5f55e282016-10-31 17:37:34 +0000396
Soby Mathewc6820d12016-05-09 17:49:55 +0100397/* GICv3 CPU Interface system register defines. The format is: coproc, opt1, CRn, CRm, opt2 */
398#define ICC_IAR1 p15, 0, c12, c12, 0
399#define ICC_IAR0 p15, 0, c12, c8, 0
400#define ICC_EOIR1 p15, 0, c12, c12, 1
401#define ICC_EOIR0 p15, 0, c12, c8, 1
402#define ICC_HPPIR1 p15, 0, c12, c12, 2
403#define ICC_HPPIR0 p15, 0, c12, c8, 2
404#define ICC_BPR1 p15, 0, c12, c12, 3
405#define ICC_BPR0 p15, 0, c12, c8, 3
406#define ICC_DIR p15, 0, c12, c11, 1
407#define ICC_PMR p15, 0, c4, c6, 0
408#define ICC_RPR p15, 0, c12, c11, 3
409#define ICC_CTLR p15, 0, c12, c12, 4
410#define ICC_MCTLR p15, 6, c12, c12, 4
411#define ICC_SRE p15, 0, c12, c12, 5
412#define ICC_HSRE p15, 4, c12, c9, 5
413#define ICC_MSRE p15, 6, c12, c12, 5
414#define ICC_IGRPEN0 p15, 0, c12, c12, 6
415#define ICC_IGRPEN1 p15, 0, c12, c12, 7
416#define ICC_MGRPEN1 p15, 6, c12, c12, 7
417
418/* 64 bit system register defines The format is: coproc, opt1, CRm */
419#define TTBR0_64 p15, 0, c2
420#define TTBR1_64 p15, 1, c2
421#define CNTVOFF_64 p15, 4, c14
422#define VTTBR_64 p15, 6, c2
423#define CNTPCT_64 p15, 0, c14
424
425/* 64 bit GICv3 CPU Interface system register defines. The format is: coproc, opt1, CRm */
426#define ICC_SGI1R_EL1_64 p15, 0, c12
427#define ICC_ASGI1R_EL1_64 p15, 1, c12
428#define ICC_SGI0R_EL1_64 p15, 2, c12
429
430#endif /* __ARCH_H__ */