blob: 6653cd14416b59ef6353a848c8166ab4262403e8 [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) | \
111 (1 << 3) | SCTLR_CP15BEN_BIT | SCTLR_NTWI_BIT | SCTLR_NTWE_BIT)
112#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
128/* HSCTLR definitions */
129#define HSCTLR_RES1 ((1 << 29) | (1 << 28) | (1 << 23) | (1 << 22) \
130 | (1 << 18) | (1 << 16) | (1 << 11) | (1 << 4) \
131 | (1 << 3) | HSCTLR_CP15BEN_BIT)
132#define HSCTLR_M_BIT (1 << 0)
133#define HSCTLR_A_BIT (1 << 1)
134#define HSCTLR_C_BIT (1 << 2)
135#define HSCTLR_CP15BEN_BIT (1 << 5)
136#define HSCTLR_ITD_BIT (1 << 7)
137#define HSCTLR_SED_BIT (1 << 8)
138#define HSCTLR_I_BIT (1 << 12)
139#define HSCTLR_WXN_BIT (1 << 19)
140#define HSCTLR_EE_BIT (1 << 25)
141#define HSCTLR_TE_BIT (1 << 30)
142
143/* CPACR definitions */
144#define CPACR_FPEN(x) ((x) << 20)
145#define CPACR_FP_TRAP_PL0 0x1
146#define CPACR_FP_TRAP_ALL 0x2
147#define CPACR_FP_TRAP_NONE 0x3
148
149/* SCR definitions */
150#define SCR_TWE_BIT (1 << 13)
151#define SCR_TWI_BIT (1 << 12)
152#define SCR_SIF_BIT (1 << 9)
153#define SCR_HCE_BIT (1 << 8)
154#define SCR_SCD_BIT (1 << 7)
155#define SCR_NET_BIT (1 << 6)
156#define SCR_AW_BIT (1 << 5)
157#define SCR_FW_BIT (1 << 4)
158#define SCR_EA_BIT (1 << 3)
159#define SCR_FIQ_BIT (1 << 2)
160#define SCR_IRQ_BIT (1 << 1)
161#define SCR_NS_BIT (1 << 0)
162#define SCR_VALID_BIT_MASK 0x33ff
163
164#define GET_NS_BIT(scr) ((scr) & SCR_NS_BIT)
165
166/* HCR definitions */
167#define HCR_AMO_BIT (1 << 5)
168#define HCR_IMO_BIT (1 << 4)
169#define HCR_FMO_BIT (1 << 3)
170
171/* CNTHCTL definitions */
172#define EVNTEN_BIT (1 << 2)
173#define PL1PCEN_BIT (1 << 1)
174#define PL1PCTEN_BIT (1 << 0)
175
176/* CNTKCTL definitions */
177#define PL0PTEN_BIT (1 << 9)
178#define PL0VTEN_BIT (1 << 8)
179#define PL0PCTEN_BIT (1 << 0)
180#define PL0VCTEN_BIT (1 << 1)
181#define EVNTEN_BIT (1 << 2)
182#define EVNTDIR_BIT (1 << 3)
183#define EVNTI_SHIFT 4
184#define EVNTI_MASK 0xf
185
186/* HCPTR definitions */
187#define TCPAC_BIT (1 << 31)
188#define TTA_BIT (1 << 20)
189#define TCP11_BIT (1 << 10)
190#define TCP10_BIT (1 << 10)
191
192/* NASCR definitions */
193#define NSASEDIS_BIT (1 << 15)
194#define NASCR_CP11_BIT (1 << 11)
195#define NASCR_CP10_BIT (1 << 10)
196
197/* CPACR definitions */
198#define ASEDIS_BIT (1 << 31)
199#define TRCDIS_BIT (1 << 28)
200#define CPACR_CP11_SHIFT 22
201#define CPACR_CP10_SHIFT 20
202#define CPACR_ENABLE_FP_ACCESS (0x3 << CPACR_CP11_SHIFT |\
203 0x3 << CPACR_CP10_SHIFT)
204
205/* FPEXC definitions */
206#define FPEXC_EN_BIT (1 << 30)
207
208/* SPSR/CPSR definitions */
209#define SPSR_FIQ_BIT (1 << 0)
210#define SPSR_IRQ_BIT (1 << 1)
211#define SPSR_ABT_BIT (1 << 2)
212#define SPSR_AIF_SHIFT 6
213#define SPSR_AIF_MASK 0x7
214
215#define SPSR_E_SHIFT 9
216#define SPSR_E_MASK 0x1
217#define SPSR_E_LITTLE 0
218#define SPSR_E_BIG 1
219
220#define SPSR_T_SHIFT 5
221#define SPSR_T_MASK 0x1
222#define SPSR_T_ARM 0
223#define SPSR_T_THUMB 1
224
225#define SPSR_MODE_SHIFT 0
226#define SPSR_MODE_MASK 0x7
227
228
229#define DISABLE_ALL_EXCEPTIONS \
230 (SPSR_FIQ_BIT | SPSR_IRQ_BIT | SPSR_ABT_BIT)
231
232/*
233 * TTBCR definitions
234 */
235/* The ARM Trusted Firmware uses the long descriptor format */
236#define TTBCR_EAE_BIT (1 << 31)
237
238#define TTBCR_SH1_NON_SHAREABLE (0x0 << 28)
239#define TTBCR_SH1_OUTER_SHAREABLE (0x2 << 28)
240#define TTBCR_SH1_INNER_SHAREABLE (0x3 << 28)
241
242#define TTBCR_RGN1_OUTER_NC (0x0 << 26)
243#define TTBCR_RGN1_OUTER_WBA (0x1 << 26)
244#define TTBCR_RGN1_OUTER_WT (0x2 << 26)
245#define TTBCR_RGN1_OUTER_WBNA (0x3 << 26)
246
247#define TTBCR_RGN1_INNER_NC (0x0 << 24)
248#define TTBCR_RGN1_INNER_WBA (0x1 << 24)
249#define TTBCR_RGN1_INNER_WT (0x2 << 24)
250#define TTBCR_RGN1_INNER_WBNA (0x3 << 24)
251
252#define TTBCR_EPD1_BIT (1 << 23)
253#define TTBCR_A1_BIT (1 << 22)
254
255#define TTBCR_T1SZ_SHIFT 16
256#define TTBCR_T1SZ_MASK (0x7)
Antonio Nino Diazd48ae612016-08-02 09:21:41 +0100257#define TTBCR_TxSZ_MIN 0
258#define TTBCR_TxSZ_MAX 7
Soby Mathewc6820d12016-05-09 17:49:55 +0100259
260#define TTBCR_SH0_NON_SHAREABLE (0x0 << 12)
261#define TTBCR_SH0_OUTER_SHAREABLE (0x2 << 12)
262#define TTBCR_SH0_INNER_SHAREABLE (0x3 << 12)
263
264#define TTBCR_RGN0_OUTER_NC (0x0 << 10)
265#define TTBCR_RGN0_OUTER_WBA (0x1 << 10)
266#define TTBCR_RGN0_OUTER_WT (0x2 << 10)
267#define TTBCR_RGN0_OUTER_WBNA (0x3 << 10)
268
269#define TTBCR_RGN0_INNER_NC (0x0 << 8)
270#define TTBCR_RGN0_INNER_WBA (0x1 << 8)
271#define TTBCR_RGN0_INNER_WT (0x2 << 8)
272#define TTBCR_RGN0_INNER_WBNA (0x3 << 8)
273
274#define TTBCR_EPD0_BIT (1 << 7)
275#define TTBCR_T0SZ_SHIFT 0
276#define TTBCR_T0SZ_MASK (0x7)
277
278#define MODE_RW_SHIFT 0x4
279#define MODE_RW_MASK 0x1
280#define MODE_RW_32 0x1
281
282#define MODE32_SHIFT 0
283#define MODE32_MASK 0x1f
284#define MODE32_usr 0x10
285#define MODE32_fiq 0x11
286#define MODE32_irq 0x12
287#define MODE32_svc 0x13
288#define MODE32_mon 0x16
289#define MODE32_abt 0x17
290#define MODE32_hyp 0x1a
291#define MODE32_und 0x1b
292#define MODE32_sys 0x1f
293
294#define GET_M32(mode) (((mode) >> MODE32_SHIFT) & MODE32_MASK)
295
296#define SPSR_MODE32(mode, isa, endian, aif) \
297 (MODE_RW_32 << MODE_RW_SHIFT | \
298 ((mode) & MODE32_MASK) << MODE32_SHIFT | \
299 ((isa) & SPSR_T_MASK) << SPSR_T_SHIFT | \
300 ((endian) & SPSR_E_MASK) << SPSR_E_SHIFT | \
301 ((aif) & SPSR_AIF_MASK) << SPSR_AIF_SHIFT)
302
303/*
304 * CTR definitions
305 */
306#define CTR_CWG_SHIFT 24
307#define CTR_CWG_MASK 0xf
308#define CTR_ERG_SHIFT 20
309#define CTR_ERG_MASK 0xf
310#define CTR_DMINLINE_SHIFT 16
311#define CTR_DMINLINE_WIDTH 4
312#define CTR_DMINLINE_MASK ((1 << 4) - 1)
313#define CTR_L1IP_SHIFT 14
314#define CTR_L1IP_MASK 0x3
315#define CTR_IMINLINE_SHIFT 0
316#define CTR_IMINLINE_MASK 0xf
317
318#define MAX_CACHE_LINE_SIZE 0x800 /* 2KB */
319
320/*******************************************************************************
321 * 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
342#define MPIDR p15, 0, c0, c0, 5
343#define MIDR p15, 0, c0, c0, 0
344#define VBAR p15, 0, c12, c0, 0
345#define MVBAR p15, 0, c12, c0, 1
346#define NSACR p15, 0, c1, c1, 2
347#define CPACR p15, 0, c1, c0, 2
348#define DCCIMVAC p15, 0, c7, c14, 1
349#define DCCMVAC p15, 0, c7, c10, 1
350#define DCIMVAC p15, 0, c7, c6, 1
351#define DCCISW p15, 0, c7, c14, 2
352#define DCCSW p15, 0, c7, c10, 2
353#define DCISW p15, 0, c7, c6, 2
354#define CTR p15, 0, c0, c0, 1
355#define CNTFRQ p15, 0, c14, c0, 0
356#define ID_PFR1 p15, 0, c0, c1, 1
357#define MAIR0 p15, 0, c10, c2, 0
358#define MAIR1 p15, 0, c10, c2, 1
359#define TTBCR p15, 0, c2, c0, 2
360#define TTBR0 p15, 0, c2, c0, 0
361#define TTBR1 p15, 0, c2, c0, 1
362#define TLBIALL p15, 0, c8, c7, 0
363#define TLBIALLIS p15, 0, c8, c3, 0
364#define TLBIMVA p15, 0, c8, c7, 1
365#define TLBIMVAA p15, 0, c8, c7, 3
366#define HSCTLR p15, 4, c1, c0, 0
367#define HCR p15, 4, c1, c1, 0
368#define HCPTR p15, 4, c1, c1, 2
369#define CNTHCTL p15, 4, c14, c1, 0
370#define VPIDR p15, 4, c0, c0, 0
371#define VMPIDR p15, 4, c0, c0, 5
372#define ISR p15, 0, c12, c1, 0
373#define CLIDR p15, 1, c0, c0, 1
374#define CSSELR p15, 2, c0, c0, 0
375#define CCSIDR p15, 1, c0, c0, 0
376
377/* GICv3 CPU Interface system register defines. The format is: coproc, opt1, CRn, CRm, opt2 */
378#define ICC_IAR1 p15, 0, c12, c12, 0
379#define ICC_IAR0 p15, 0, c12, c8, 0
380#define ICC_EOIR1 p15, 0, c12, c12, 1
381#define ICC_EOIR0 p15, 0, c12, c8, 1
382#define ICC_HPPIR1 p15, 0, c12, c12, 2
383#define ICC_HPPIR0 p15, 0, c12, c8, 2
384#define ICC_BPR1 p15, 0, c12, c12, 3
385#define ICC_BPR0 p15, 0, c12, c8, 3
386#define ICC_DIR p15, 0, c12, c11, 1
387#define ICC_PMR p15, 0, c4, c6, 0
388#define ICC_RPR p15, 0, c12, c11, 3
389#define ICC_CTLR p15, 0, c12, c12, 4
390#define ICC_MCTLR p15, 6, c12, c12, 4
391#define ICC_SRE p15, 0, c12, c12, 5
392#define ICC_HSRE p15, 4, c12, c9, 5
393#define ICC_MSRE p15, 6, c12, c12, 5
394#define ICC_IGRPEN0 p15, 0, c12, c12, 6
395#define ICC_IGRPEN1 p15, 0, c12, c12, 7
396#define ICC_MGRPEN1 p15, 6, c12, c12, 7
397
398/* 64 bit system register defines The format is: coproc, opt1, CRm */
399#define TTBR0_64 p15, 0, c2
400#define TTBR1_64 p15, 1, c2
401#define CNTVOFF_64 p15, 4, c14
402#define VTTBR_64 p15, 6, c2
403#define CNTPCT_64 p15, 0, c14
404
405/* 64 bit GICv3 CPU Interface system register defines. The format is: coproc, opt1, CRm */
406#define ICC_SGI1R_EL1_64 p15, 0, c12
407#define ICC_ASGI1R_EL1_64 p15, 1, c12
408#define ICC_SGI0R_EL1_64 p15, 2, c12
409
410#endif /* __ARCH_H__ */