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