Zephyr API Documentation
4.3.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
cpu.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2019 Carlo Caione <ccaione@baylibre.com>
3
*
4
* SPDX-License-Identifier: Apache-2.0
5
*/
6
7
#ifndef ZEPHYR_INCLUDE_ARCH_ARM64_CPU_H_
8
#define ZEPHYR_INCLUDE_ARCH_ARM64_CPU_H_
9
10
#include <
zephyr/sys/util_macro.h
>
11
#include <
stdbool.h
>
12
14
15
#define DAIFSET_FIQ_BIT BIT(0)
16
#define DAIFSET_IRQ_BIT BIT(1)
17
#define DAIFSET_ABT_BIT BIT(2)
18
#define DAIFSET_DBG_BIT BIT(3)
19
20
#define DAIFCLR_FIQ_BIT BIT(0)
21
#define DAIFCLR_IRQ_BIT BIT(1)
22
#define DAIFCLR_ABT_BIT BIT(2)
23
#define DAIFCLR_DBG_BIT BIT(3)
24
25
#define DAIF_FIQ_BIT BIT(6)
26
#define DAIF_IRQ_BIT BIT(7)
27
#define DAIF_ABT_BIT BIT(8)
28
#define DAIF_DBG_BIT BIT(9)
29
30
#define SPSR_DAIF_SHIFT (6)
31
#define SPSR_DAIF_MASK (0xf << SPSR_DAIF_SHIFT)
32
33
#define SPSR_MODE_EL0T (0x0)
34
#define SPSR_MODE_EL1T (0x4)
35
#define SPSR_MODE_EL1H (0x5)
36
#define SPSR_MODE_EL2T (0x8)
37
#define SPSR_MODE_EL2H (0x9)
38
#define SPSR_MODE_MASK (0xf)
39
40
41
#define SCTLR_EL3_RES1 (BIT(29) | BIT(28) | BIT(23) | \
42
BIT(22) | BIT(18) | BIT(16) | \
43
BIT(11) | BIT(5) | BIT(4))
44
45
#define SCTLR_EL2_RES1 (BIT(29) | BIT(28) | BIT(23) | \
46
BIT(22) | BIT(18) | BIT(16) | \
47
BIT(11) | BIT(5) | BIT(4))
48
49
#define SCTLR_EL1_RES1 (BIT(29) | BIT(28) | BIT(23) | \
50
BIT(22) | BIT(20) | BIT(11))
51
52
#define SCTLR_M_BIT BIT(0)
53
#define SCTLR_A_BIT BIT(1)
54
#define SCTLR_C_BIT BIT(2)
55
#define SCTLR_SA_BIT BIT(3)
56
#define SCTLR_I_BIT BIT(12)
57
#define SCTLR_BR_BIT BIT(17)
58
#define SCTLR_EnIA_BIT BIT(31)
/* Enable Instruction address signing using key A */
59
#define SCTLR_BT0_BIT BIT(35)
/* PAC Branch Type compatibility for EL0 */
60
#define SCTLR_BT1_BIT BIT(36)
/* PAC Branch Type compatibility for EL1 */
61
62
#define CPACR_EL1_FPEN GENMASK(21, 20)
63
#define CPACR_EL1_ZEN GENMASK(17, 16)
64
65
#define SCR_NS_BIT BIT(0)
66
#define SCR_IRQ_BIT BIT(1)
67
#define SCR_FIQ_BIT BIT(2)
68
#define SCR_EA_BIT BIT(3)
69
#define SCR_SMD_BIT BIT(7)
70
#define SCR_HCE_BIT BIT(8)
71
#define SCR_RW_BIT BIT(10)
72
#define SCR_ST_BIT BIT(11)
73
#define SCR_APK_BIT BIT(16)
/* Do not trap pointer authentication key accesses */
74
#define SCR_API_BIT BIT(17)
/* Do not trap pointer authentication instructions */
75
#define SCR_EEL2_BIT BIT(18)
76
77
#define SCR_RES1 (BIT(4) | BIT(5))
78
79
/* MPIDR */
80
#define MPIDR_AFFLVL_MASK (0xffULL)
81
82
#define MPIDR_AFF0_SHIFT (0)
83
#define MPIDR_AFF1_SHIFT (8)
84
#define MPIDR_AFF2_SHIFT (16)
85
#define MPIDR_AFF3_SHIFT (32)
86
87
#define MPIDR_AFF_MASK (GENMASK(23, 0) | GENMASK(39, 32))
88
89
#define MPIDR_AFFLVL(mpidr, aff_level) \
90
(((mpidr) >> MPIDR_AFF##aff_level##_SHIFT) & MPIDR_AFFLVL_MASK)
91
92
#define GET_MPIDR() read_sysreg(mpidr_el1)
93
#define MPIDR_TO_CORE(mpidr) (mpidr & MPIDR_AFF_MASK)
94
95
#define MODE_EL_SHIFT (0x2)
96
#define MODE_EL_MASK (0x3)
97
98
#define MODE_EL3 (0x3)
99
#define MODE_EL2 (0x2)
100
#define MODE_EL1 (0x1)
101
#define MODE_EL0 (0x0)
102
103
#define GET_EL(_mode) (((_mode) >> MODE_EL_SHIFT) & MODE_EL_MASK)
104
105
#define ESR_EC_SHIFT (26)
106
#define ESR_EC_MASK BIT_MASK(6)
107
#define ESR_ISS_SHIFT (0)
108
#define ESR_ISS_MASK BIT_MASK(25)
109
#define ESR_IL_SHIFT (25)
110
#define ESR_IL_MASK BIT_MASK(1)
111
112
#define GET_ESR_EC(esr) (((esr) >> ESR_EC_SHIFT) & ESR_EC_MASK)
113
#define GET_ESR_IL(esr) (((esr) >> ESR_IL_SHIFT) & ESR_IL_MASK)
114
#define GET_ESR_ISS(esr) (((esr) >> ESR_ISS_SHIFT) & ESR_ISS_MASK)
115
116
#define CNTV_CTL_ENABLE_BIT BIT(0)
117
#define CNTV_CTL_IMASK_BIT BIT(1)
118
119
#define ID_AA64PFR0_EL0_SHIFT (0)
120
#define ID_AA64PFR0_EL1_SHIFT (4)
121
#define ID_AA64PFR0_EL2_SHIFT (8)
122
#define ID_AA64PFR0_EL3_SHIFT (12)
123
#define ID_AA64PFR0_ELX_MASK (0xf)
124
#define ID_AA64PFR0_FP_SHIFT (16)
125
#define ID_AA64PFR0_FP_MASK (0xf)
126
#define ID_AA64PFR0_ADVSIMD_SHIFT (20)
127
#define ID_AA64PFR0_ADVSIMD_MASK (0xf)
128
#define ID_AA64PFR0_SVE_SHIFT (32)
129
#define ID_AA64PFR0_SVE_MASK (0xf)
130
#define ID_AA64PFR0_SEL2_SHIFT (36)
131
#define ID_AA64PFR0_SEL2_MASK (0xf)
132
133
/*
134
* TODO: ACTLR is of class implementation defined. All core implementations
135
* in armv8a have the same implementation so far w.r.t few controls.
136
* When there will be differences we have to create core specific headers.
137
*/
138
#define ACTLR_EL3_CPUACTLR_BIT BIT(0)
139
#define ACTLR_EL3_CPUECTLR_BIT BIT(1)
140
#define ACTLR_EL3_L2CTLR_BIT BIT(4)
141
#define ACTLR_EL3_L2ECTLR_BIT BIT(5)
142
#define ACTLR_EL3_L2ACTLR_BIT BIT(6)
143
144
#define CPTR_EZ_BIT BIT(8)
145
#define CPTR_TFP_BIT BIT(10)
146
#define CPTR_TTA_BIT BIT(20)
147
#define CPTR_TCPAC_BIT BIT(31)
148
149
/* SVE-specific CPTR_EL2 bits */
150
#define CPTR_EL2_TZ_BIT BIT(8)
151
#define CPTR_EL2_ZEN_SHIFT 16
152
#define CPTR_EL2_ZEN_MASK (0x3 << CPTR_EL2_ZEN_SHIFT)
153
#define CPTR_EL2_ZEN_EL1_EN BIT(16)
154
#define CPTR_EL2_ZEN_EL0_EN BIT(17)
155
156
#define CPTR_EL2_RES1 BIT(13) | BIT(12) | BIT(9) | (0xff)
157
158
/* SVE Control Register (ZCR) */
159
#define ZCR_EL1 S3_0_C1_C2_0
160
#define ZCR_EL2 S3_4_C1_C2_0
161
#define ZCR_EL3 S3_6_C1_C2_0
162
163
#define HCR_FMO_BIT BIT(3)
164
#define HCR_IMO_BIT BIT(4)
165
#define HCR_AMO_BIT BIT(5)
166
#define HCR_TGE_BIT BIT(27)
167
#define HCR_RW_BIT BIT(31)
168
#define HCR_APK_BIT BIT(40)
/* Trap pointer authentication key registers */
169
#define HCR_API_BIT BIT(41)
/* Trap pointer authentication instructions */
170
171
/* PAC Key Registers - System register encodings */
172
#define APIAKeyLo_EL1 S3_0_C2_C1_0
173
#define APIAKeyHi_EL1 S3_0_C2_C1_1
174
#define APIBKeyLo_EL1 S3_0_C2_C1_2
175
#define APIBKeyHi_EL1 S3_0_C2_C1_3
176
#define APDAKeyLo_EL1 S3_0_C2_C2_0
177
#define APDAKeyHi_EL1 S3_0_C2_C2_1
178
#define APDBKeyLo_EL1 S3_0_C2_C2_2
179
#define APDBKeyHi_EL1 S3_0_C2_C2_3
180
#define APGAKeyLo_EL1 S3_0_C2_C3_0
181
#define APGAKeyHi_EL1 S3_0_C2_C3_1
182
183
/* System register interface to GICv3 */
184
#define ICC_IGRPEN1_EL1 S3_0_C12_C12_7
185
#define ICC_SGI1R S3_0_C12_C11_5
186
#define ICC_SRE_EL1 S3_0_C12_C12_5
187
#define ICC_SRE_EL2 S3_4_C12_C9_5
188
#define ICC_SRE_EL3 S3_6_C12_C12_5
189
#define ICC_CTLR_EL1 S3_0_C12_C12_4
190
#define ICC_CTLR_EL3 S3_6_C12_C12_4
191
#define ICC_PMR_EL1 S3_0_C4_C6_0
192
#define ICC_RPR_EL1 S3_0_C12_C11_3
193
#define ICC_IGRPEN1_EL3 S3_6_C12_C12_7
194
#define ICC_IGRPEN0_EL1 S3_0_C12_C12_6
195
#define ICC_HPPIR0_EL1 S3_0_C12_C8_2
196
#define ICC_HPPIR1_EL1 S3_0_C12_C12_2
197
#define ICC_IAR0_EL1 S3_0_C12_C8_0
198
#define ICC_IAR1_EL1 S3_0_C12_C12_0
199
#define ICC_EOIR0_EL1 S3_0_C12_C8_1
200
#define ICC_EOIR1_EL1 S3_0_C12_C12_1
201
#define ICC_SGI0R_EL1 S3_0_C12_C11_7
202
203
/* register constants */
204
#define ICC_SRE_ELx_SRE_BIT BIT(0)
205
#define ICC_SRE_ELx_DFB_BIT BIT(1)
206
#define ICC_SRE_ELx_DIB_BIT BIT(2)
207
#define ICC_SRE_ELx_EN_BIT BIT(3)
208
209
/* ICC SGI macros */
210
#define SGIR_TGT_MASK (0xffff)
211
#define SGIR_AFF1_SHIFT (16)
212
#define SGIR_AFF2_SHIFT (32)
213
#define SGIR_AFF3_SHIFT (48)
214
#define SGIR_AFF_MASK (0xff)
215
#define SGIR_INTID_SHIFT (24)
216
#define SGIR_INTID_MASK (0xf)
217
#define SGIR_IRM_SHIFT (40)
218
#define SGIR_IRM_MASK (0x1)
219
#define SGIR_IRM_TO_AFF (0)
220
221
#define GICV3_SGIR_VALUE(_aff3, _aff2, _aff1, _intid, _irm, _tgt) \
222
((((uint64_t) (_aff3) & SGIR_AFF_MASK) << SGIR_AFF3_SHIFT) | \
223
(((uint64_t) (_irm) & SGIR_IRM_MASK) << SGIR_IRM_SHIFT) | \
224
(((uint64_t) (_aff2) & SGIR_AFF_MASK) << SGIR_AFF2_SHIFT) | \
225
(((_intid) & SGIR_INTID_MASK) << SGIR_INTID_SHIFT) | \
226
(((_aff1) & SGIR_AFF_MASK) << SGIR_AFF1_SHIFT) | \
227
((_tgt) & SGIR_TGT_MASK))
228
229
/* Implementation defined register definitions */
230
#if defined(CONFIG_CPU_CORTEX_A72)
231
232
#define CORTEX_A72_L2CTLR_EL1 S3_1_C11_C0_2
233
#define CORTEX_A72_L2CTLR_DATA_RAM_LATENCY_SHIFT (0)
234
#define CORTEX_A72_L2CTLR_DATA_RAM_SETUP_SHIFT (5)
235
#define CORTEX_A72_L2CTLR_TAG_RAM_LATENCY_SHIFT (6)
236
#define CORTEX_A72_L2CTLR_TAG_RAM_SETUP_SHIFT (9)
237
238
#define CORTEX_A72_L2_DATA_RAM_LATENCY_3_CYCLES (2)
239
#define CORTEX_A72_L2_DATA_RAM_LATENCY_MASK (0x7)
240
#define CORTEX_A72_L2_DATA_RAM_SETUP_1_CYCLE (1)
241
#define CORTEX_A72_L2_TAG_RAM_LATENCY_2_CYCLES (1)
242
#define CORTEX_A72_L2_TAG_RAM_LATENCY_3_CYCLES (2)
243
#define CORTEX_A72_L2_TAG_RAM_LATENCY_MASK (0x7)
244
#define CORTEX_A72_L2_TAG_RAM_SETUP_1_CYCLE (1)
245
246
#define CORTEX_A72_L2ACTLR_EL1 S3_1_C15_C0_0
247
#define CORTEX_A72_L2ACTLR_DISABLE_ACE_SH_OR_CHI_BIT BIT(6)
248
249
#endif
/* CONFIG_CPU_CORTEX_A72 */
250
251
#define L1_CACHE_SHIFT (6)
252
#define L1_CACHE_BYTES BIT(L1_CACHE_SHIFT)
253
#define ARM64_CPU_INIT_SIZE L1_CACHE_BYTES
254
256
257
#endif
/* ZEPHYR_INCLUDE_ARCH_ARM64_CPU_H_ */
stdbool.h
util_macro.h
Macro utilities.
zephyr
arch
arm64
cpu.h
Generated on
for Zephyr API Documentation by
1.15.0