]> git.saurik.com Git - apple/xnu.git/blob - osfmk/arm64/proc_reg.h
xnu-4570.61.1.tar.gz
[apple/xnu.git] / osfmk / arm64 / proc_reg.h
1 /*
2 * Copyright (c) 2007-2013 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28 /*
29 * Processor registers for ARM64
30 */
31 #ifndef _ARM64_PROC_REG_H_
32 #define _ARM64_PROC_REG_H_
33
34 #include <arm/proc_reg.h>
35
36 #if __ARM_KERNEL_PROTECT__
37 /*
38 * __ARM_KERNEL_PROTECT__ is a feature intended to guard against potential
39 * architectural or microarchitectural vulnerabilities that could allow cores to
40 * read/access EL1-only mappings while in EL0 mode. This is achieved by
41 * removing as many mappings as possible when the core transitions to EL0 mode
42 * from EL1 mode, and restoring those mappings when the core transitions to EL1
43 * mode from EL0 mode.
44 *
45 * At the moment, this is achieved through use of ASIDs and TCR_EL1. TCR_EL1 is
46 * used to map and unmap the ordinary kernel mappings, by contracting and
47 * expanding translation zone size for TTBR1 when exiting and entering EL1,
48 * respectively:
49 *
50 * Kernel EL0 Mappings: TTBR1 mappings that must remain mapped while the core is
51 * is in EL0.
52 * Kernel EL1 Mappings: TTBR1 mappings that must be mapped while the core is in
53 * EL1.
54 *
55 * T1SZ_USER: T1SZ_BOOT + 1
56 * TTBR1_EL1_BASE_BOOT: (2^64) - (2^(64 - T1SZ_BOOT)
57 * TTBR1_EL1_BASE_USER: (2^64) - (2^(64 - T1SZ_USER)
58 * TTBR1_EL1_MAX: (2^64) - 1
59 *
60 * When in EL1, we program TCR_EL1 (specifically, TCR_EL1.T1SZ) to give the
61 * the following TTBR1 layout:
62 *
63 * TTBR1_EL1_BASE_BOOT TTBR1_EL1_BASE_USER TTBR1_EL1_MAX
64 * +---------------------------------------------------------+
65 * | Kernel EL0 Mappings | Kernel EL1 Mappings |
66 * +---------------------------------------------------------+
67 *
68 * And when in EL0, we program TCR_EL1 to give the following TTBR1 layout:
69 *
70 * TTBR1_EL1_BASE_USER TTBR1_EL1_MAX
71 * +---------------------------------------------------------+
72 * | Kernel EL0 Mappings |
73 * +---------------------------------------------------------+
74 *
75 * With the current implementation, both the EL0 and EL1 mappings for the kernel
76 * use otherwise empty translation tables for mapping the exception vectors (so
77 * that we do not need to TLB flush the exception vector address when switching
78 * between EL0 and EL1). The rationale here is that the TLBI would require a
79 * DSB, and DSBs can be extremely expensive.
80 *
81 * Each pmap is given two ASIDs: (n & ~1) as an EL0 ASID, and (n | 1) as an EL1
82 * ASID. The core switches between ASIDs on EL transitions, so that the TLB
83 * does not need to be fully invalidated on an EL transition.
84 *
85 * Most kernel mappings will be marked non-global in this configuration, as
86 * global mappings would be visible to userspace unless we invalidate them on
87 * eret.
88 */
89 #endif /* __ARM_KERNEL_PROTECT */
90
91 /*
92 * 64-bit Program Status Register (PSR64)
93 *
94 * 31 27 23 22 21 20 19 10 9 5 4 0
95 * +-+-+-+-+-----+---+--+--+----------+-+-+-+-+-+-----+
96 * |N|Z|C|V|00000|PAN|SS|IL|0000000000|D|A|I|F|0| M |
97 * +-+-+-+-+-+---+---+--+--+----------+-+-+-+-+-+-----+
98 *
99 * where:
100 * NZCV Comparison flags
101 * PAN Privileged Access Never
102 * SS Single step
103 * IL Illegal state
104 * DAIF Interrupt masks
105 * M Mode field
106 */
107
108 #define PSR64_NZCV_SHIFT 28
109 #define PSR64_NZCV_MASK (1 << PSR64_NZCV_SHIFT)
110
111 #define PSR64_N_SHIFT 31
112 #define PSR64_N (1 << PSR64_N_SHIFT)
113
114 #define PSR64_Z_SHIFT 30
115 #define PSR64_Z (1 << PSR64_Z_SHIFT)
116
117 #define PSR64_C_SHIFT 29
118 #define PSR64_C (1 << PSR64_C_SHIFT)
119
120 #define PSR64_V_SHIFT 28
121 #define PSR64_V (1 << PSR64_V_SHIFT)
122
123 #define PSR64_PAN_SHIFT 22
124 #define PSR64_PAN (1 << PSR64_PAN_SHIFT)
125
126 #define PSR64_SS_SHIFT 21
127 #define PSR64_SS (1 << PSR64_SS_SHIFT)
128
129 #define PSR64_IL_SHIFT 20
130 #define PSR64_IL (1 << PSR64_IL_SHIFT)
131
132 /*
133 * msr DAIF, Xn and mrs Xn, DAIF transfer into
134 * and out of bits 9:6
135 */
136 #define DAIF_DEBUG_SHIFT 9
137 #define DAIF_DEBUGF (1 << DAIF_DEBUG_SHIFT)
138
139 #define DAIF_ASYNC_SHIFT 8
140 #define DAIF_ASYNCF (1 << DAIF_ASYNC_SHIFT)
141
142 #define DAIF_IRQF_SHIFT 7
143 #define DAIF_IRQF (1 << DAIF_IRQF_SHIFT)
144
145 #define DAIF_FIQF_SHIFT 6
146 #define DAIF_FIQF (1 << DAIF_FIQF_SHIFT)
147
148 #define DAIF_ALL (DAIF_DEBUGF | DAIF_ASYNCF | DAIF_IRQF | DAIF_FIQF)
149 #define DAIF_STANDARD_DISABLE (DAIF_ASYNCF | DAIF_IRQF | DAIF_FIQF)
150
151 #define SPSR_INTERRUPTS_ENABLED(x) (!(x & DAIF_FIQF))
152
153 /*
154 * msr DAIFSet, Xn, and msr DAIFClr, Xn transfer
155 * from bits 3:0.
156 */
157 #define DAIFSC_DEBUGF (1 << 3)
158 #define DAIFSC_ASYNCF (1 << 2)
159 #define DAIFSC_IRQF (1 << 1)
160 #define DAIFSC_FIQF (1 << 0)
161 #define DAIFSC_ALL (DAIFSC_DEBUGF | DAIFSC_ASYNCF | DAIFSC_IRQF | DAIFSC_FIQF)
162 #define DAIFSC_STANDARD_DISABLE (DAIFSC_ASYNCF | DAIFSC_IRQF | DAIFSC_FIQF)
163
164 /*
165 * ARM64_TODO: unify with ARM?
166 */
167 #define PSR64_CF 0x20000000 /* Carry/Borrow/Extend */
168
169 #define PSR64_MODE_MASK 0x1F
170
171 #define PSR64_MODE_USER32_THUMB 0x20
172
173 #define PSR64_MODE_RW_SHIFT 4
174 #define PSR64_MODE_RW_64 0
175 #define PSR64_MODE_RW_32 (0x1 << PSR64_MODE_RW_SHIFT)
176
177 #define PSR64_MODE_EL_SHIFT 2
178 #define PSR64_MODE_EL_MASK (0x3 << PSR64_MODE_EL_SHIFT)
179 #define PSR64_MODE_EL3 (0x3 << PSR64_MODE_EL_SHIFT)
180 #define PSR64_MODE_EL1 (0x1 << PSR64_MODE_EL_SHIFT)
181 #define PSR64_MODE_EL0 0
182
183 #define PSR64_MODE_SPX 0x1
184 #define PSR64_MODE_SP0 0
185
186 #define PSR64_USER32_DEFAULT (PSR64_MODE_RW_32 | PSR64_MODE_EL0 | PSR64_MODE_SP0)
187 #define PSR64_USER64_DEFAULT (PSR64_MODE_RW_64 | PSR64_MODE_EL0 | PSR64_MODE_SP0)
188 #define PSR64_KERNEL_DEFAULT (DAIF_STANDARD_DISABLE | PSR64_MODE_RW_64 | PSR64_MODE_EL1 | PSR64_MODE_SP0)
189
190 #define PSR64_IS_KERNEL(x) ((x & PSR64_MODE_EL_MASK) == PSR64_MODE_EL1)
191 #define PSR64_IS_USER(x) ((x & PSR64_MODE_EL_MASK) == PSR64_MODE_EL0)
192
193 #define PSR64_IS_USER32(x) (PSR64_IS_USER(x) && (x & PSR64_MODE_RW_32))
194 #define PSR64_IS_USER64(x) (PSR64_IS_USER(x) && !(x & PSR64_MODE_RW_32))
195
196
197
198 /*
199 * System Control Register (SCTLR)
200 */
201
202 #define SCTLR_RESERVED ((3 << 28) | (1 << 22) | (1 << 20) | (1 << 11))
203
204 // 31 PACIA_ENABLED AddPACIA and AuthIA functions enabled
205 #define SCTLR_PACIA_ENABLED (1 << 31)
206 // 30 PACIB_ENABLED AddPACIB and AuthIB functions enabled
207 #define SCTLR_PACIB_ENABLED (1 << 30)
208 // 29:28 RES1 11
209 // 27 PACDA_ENABLED AddPACDA and AuthDA functions enabled
210 #define SCTLR_PACDA_ENABLED (1 << 27)
211
212 // 26 UCI User Cache Instructions
213 #define SCTLR_UCI_ENABLED (1 << 26)
214
215 // 25 EE Exception Endianness
216 #define SCTLR_EE_BIG_ENDIAN (1 << 25)
217
218 // 24 E0E EL0 Endianness
219 #define SCTLR_E0E_BIG_ENDIAN (1 << 24)
220
221 // 23 SPAN Set PAN
222 #define SCTLR_PAN_UNCHANGED (1 << 23)
223
224 // 22 RES1 1
225 // 21 RES0 0
226 // 20 RES1 1
227
228 // 19 WXN Writeable implies eXecute Never
229 #define SCTLR_WXN_ENABLED (1 << 19)
230
231 // 18 nTWE Not trap WFE from EL0
232 #define SCTLR_nTWE_WFE_ENABLED (1 << 18)
233
234 // 17 RES0 0
235
236 // 16 nTWI Not trap WFI from EL0
237 #define SCTRL_nTWI_WFI_ENABLED (1 << 16)
238
239 // 15 UCT User Cache Type register (CTR_EL0)
240 #define SCTLR_UCT_ENABLED (1 << 15)
241
242 // 14 DZE User Data Cache Zero (DC ZVA)
243 #define SCTLR_DZE_ENABLED (1 << 14)
244
245 // 13 RES0 0
246
247 // 12 I Instruction cache enable
248 #define SCTLR_I_ENABLED (1 << 12)
249
250 // 11 RES1 1
251 // 10 RES0 0
252
253 // 9 UMA User Mask Access
254 #define SCTLR_UMA_ENABLED (1 << 9)
255
256 // 8 SED SETEND Disable
257 #define SCTLR_SED_DISABLED (1 << 8)
258
259 // 7 ITD IT Disable
260 #define SCTLR_ITD_DISABLED (1 << 7)
261
262 // 6 RES0 0
263
264 // 5 CP15BEN CP15 Barrier ENable
265 #define SCTLR_CP15BEN_ENABLED (1 << 5)
266
267 // 4 SA0 Stack Alignment check for EL0
268 #define SCTLR_SA0_ENABLED (1 << 4)
269
270 // 3 SA Stack Alignment check
271 #define SCTLR_SA_ENABLED (1 << 3)
272
273 // 2 C Cache enable
274 #define SCTLR_C_ENABLED (1 << 2)
275
276 // 1 A Alignment check
277 #define SCTLR_A_ENABLED (1 << 1)
278
279 // 0 M MMU enable
280 #define SCTLR_M_ENABLED (1 << 0)
281
282 #define SCTLR_PAC_DEFAULT 0
283
284 #define SCTLR_EL1_DEFAULT (SCTLR_PAC_DEFAULT | SCTLR_RESERVED | SCTLR_UCI_ENABLED | SCTLR_nTWE_WFE_ENABLED | SCTLR_DZE_ENABLED | \
285 SCTLR_I_ENABLED | SCTLR_SED_DISABLED | SCTLR_CP15BEN_ENABLED | \
286 SCTLR_SA0_ENABLED | SCTLR_SA_ENABLED | SCTLR_C_ENABLED | SCTLR_M_ENABLED)
287
288 /*
289 * Coprocessor Access Control Register (CPACR)
290 *
291 * 31 28 27 22 21 20 19 0
292 * +---+---+------+------+--------------------+
293 * |000|TTA|000000| FPEN |00000000000000000000|
294 * +---+---+------+------+--------------------+
295 *
296 * where:
297 * TTA Trace trap
298 * FPEN Floating point enable
299 */
300 #define CPACR_TTA_SHIFT 28
301 #define CPACR_TTA (1 << CPACR_TTA_SHIFT)
302
303 #define CPACR_FPEN_SHIFT 20
304 #define CPACR_FPEN_EL0_TRAP (0x1 << CPACR_FPEN_SHIFT)
305 #define CPACR_FPEN_ENABLE (0x3 << CPACR_FPEN_SHIFT)
306
307 /*
308 * FPSR: Floating Point Status Register
309 *
310 * 31 30 29 28 27 26 7 6 4 3 2 1 0
311 * +--+--+--+--+--+-------------------+---+--+---+---+---+---+---+
312 * | N| Z| C| V|QC|0000000000000000000|IDC|00|IXC|UFC|OFC|DZC|IOC|
313 * +--+--+--+--+--+-------------------+---+--+---+---+---+---+---+
314 */
315
316 #define FPSR_N_SHIFT 31
317 #define FPSR_Z_SHIFT 30
318 #define FPSR_C_SHIFT 29
319 #define FPSR_V_SHIFT 28
320 #define FPSR_QC_SHIFT 27
321 #define FPSR_IDC_SHIFT 7
322 #define FPSR_IXC_SHIFT 4
323 #define FPSR_UFC_SHIFT 3
324 #define FPSR_OFC_SHIFT 2
325 #define FPSR_DZC_SHIFT 1
326 #define FPSR_IOC_SHIFT 0
327 #define FPSR_N (1 << FPSR_N_SHIFT)
328 #define FPSR_Z (1 << FPSR_Z_SHIFT)
329 #define FPSR_C (1 << FPSR_C_SHIFT)
330 #define FPSR_V (1 << FPSR_V_SHIFT)
331 #define FPSR_QC (1 << FPSR_QC_SHIFT)
332 #define FPSR_IDC (1 << FPSR_IDC_SHIFT)
333 #define FPSR_IXC (1 << FPSR_IXC_SHIFT)
334 #define FPSR_UFC (1 << FPSR_UFC_SHIFT)
335 #define FPSR_OFC (1 << FPSR_OFC_SHIFT)
336 #define FPSR_DZC (1 << FPSR_DZC_SHIFT)
337 #define FPSR_IOC (1 << FPSR_IOC_SHIFT)
338
339 /*
340 * A mask for all for all of the bits that are not RAZ for FPSR; this
341 * is primarily for converting between a 32-bit view of NEON state
342 * (FPSCR) and a 64-bit view of NEON state (FPSR, FPCR).
343 */
344 #define FPSR_MASK (FPSR_N | FPSR_Z | FPSR_C | FPSR_V | FPSR_QC | \
345 FPSR_IDC | FPSR_IXC | FPSR_UFC | FPSR_OFC | \
346 FPSR_DZC | FPSR_IOC)
347
348 /*
349 * FPCR: Floating Point Control Register
350 *
351 * 31 26 25 24 23 21 19 18 15 14 12 11 10 9 8 7 0
352 * +-----+---+--+--+-----+------+--+---+---+--+---+---+---+---+---+--------+
353 * |00000|AHP|DN|FZ|RMODE|STRIDE| 0|LEN|IDE|00|IXE|UFE|OFE|DZE|IOE|00000000|
354 * +-----+---+--+--+-----+------+--+---+---+--+---+---+---+---+---+--------+
355 */
356
357 #define FPCR_AHP_SHIFT 26
358 #define FPCR_DN_SHIFT 25
359 #define FPCR_FZ_SHIFT 24
360 #define FPCR_RMODE_SHIFT 22
361 #define FPCR_STRIDE_SHIFT 20
362 #define FPCR_LEN_SHIFT 16
363 #define FPCR_IDE_SHIFT 15
364 #define FPCR_IXE_SHIFT 12
365 #define FPCR_UFE_SHIFT 11
366 #define FPCR_OFE_SHIFT 10
367 #define FPCR_DZE_SHIFT 9
368 #define FPCR_IOE_SHIFT 8
369 #define FPCR_AHP (1 << FPCR_AHP_SHIFT)
370 #define FPCR_DN (1 << FPCR_DN_SHIFT)
371 #define FPCR_FZ (1 << FPCR_FZ_SHIFT)
372 #define FPCR_RMODE (0x3 << FPCR_RMODE_SHIFT)
373 #define FPCR_STRIDE (0x3 << FPCR_STRIDE_SHIFT)
374 #define FPCR_LEN (0x7 << FPCR_LEN_SHIFT)
375 #define FPCR_IDE (1 << FPCR_IDE_SHIFT)
376 #define FPCR_IXE (1 << FPCR_IXE_SHIFT)
377 #define FPCR_UFE (1 << FPCR_UFE_SHIFT)
378 #define FPCR_OFE (1 << FPCR_OFE_SHIFT)
379 #define FPCR_DZE (1 << FPCR_DZE_SHIFT)
380 #define FPCR_IOE (1 << FPCR_IOE_SHIFT)
381 #define FPCR_DEFAULT (FPCR_DN)
382 #define FPCR_DEFAULT_32 (FPCR_DN|FPCR_FZ)
383
384 /*
385 * A mask for all for all of the bits that are not RAZ for FPCR; this
386 * is primarily for converting between a 32-bit view of NEON state
387 * (FPSCR) and a 64-bit view of NEON state (FPSR, FPCR).
388 */
389 #define FPCR_MASK (FPCR_AHP | FPCR_DN | FPCR_FZ | FPCR_RMODE | \
390 FPCR_STRIDE | FPCR_LEN | FPCR_IDE | FPCR_IXE | \
391 FPCR_UFE | FPCR_OFE | FPCR_DZE | FPCR_IOE)
392
393 /*
394 * Translation Control Register (TCR)
395 *
396 * Legacy:
397 *
398 * 63 39 38 37 36 34 32 30 29 28 27 26 25 24 23 22 21 16 14 13 12 11 10 9 8 7 5 0
399 * +------+----+----+--+-+-----+-+---+-----+-----+-----+----+--+------+-+---+-----+-----+-----+----+-+----+
400 * | zero |TBI1|TBI0|AS|z| IPS |z|TG1| SH1 |ORGN1|IRGN1|EPD1|A1| T1SZ |z|TG0| SH0 |ORGN0|IRGN0|EPD0|z|T0SZ|
401 * +------+----+----+--+-+-----+-+---+-----+-----+-----+----+--+------+-+---+-----+-----+-----+----+-+----+
402 *
403 * Current (with 16KB granule support):
404 *
405 * 63 39 38 37 36 34 32 30 29 28 27 26 25 24 23 22 21 16 14 13 12 11 10 9 8 7 5 0
406 * +------+----+----+--+-+-----+-----+-----+-----+-----+----+--+------+-----+-----+-----+-----+----+-+----+
407 * | zero |TBI1|TBI0|AS|z| IPS | TG1 | SH1 |ORGN1|IRGN1|EPD1|A1| T1SZ | TG0 | SH0 |ORGN0|IRGN0|EPD0|z|T0SZ|
408 * +------+----+----+--+-+-----+-----+-----+-----+-----+----+--+------+-----+-----+-----+-----+----+-+----+
409 *
410 * TBI1 Top Byte Ignored for TTBR1 region
411 * TBI0 Top Byte Ignored for TTBR0 region
412 * AS ASID Size
413 * IPS Physical Address Size limit
414 * TG1 Granule Size for TTBR1 region
415 * SH1 Shareability for TTBR1 region
416 * ORGN1 Outer Cacheability for TTBR1 region
417 * IRGN1 Inner Cacheability for TTBR1 region
418 * EPD1 Translation table walk disable for TTBR1
419 * A1 ASID selection from TTBR1 enable
420 * T1SZ Virtual address size for TTBR1
421 * TG0 Granule Size for TTBR0 region
422 * SH0 Shareability for TTBR0 region
423 * ORGN0 Outer Cacheability for TTBR0 region
424 * IRGN0 Inner Cacheability for TTBR0 region
425 * T0SZ Virtual address size for TTBR0
426 */
427
428 #define TCR_T0SZ_SHIFT 0ULL
429 #define TCR_TSZ_BITS 6ULL
430 #define TCR_TSZ_MASK ((1ULL << TCR_TSZ_BITS) - 1ULL)
431
432 #define TCR_IRGN0_SHIFT 8ULL
433 #define TCR_IRGN0_DISABLED (0ULL << TCR_IRGN0_SHIFT)
434 #define TCR_IRGN0_WRITEBACK (1ULL << TCR_IRGN0_SHIFT)
435 #define TCR_IRGN0_WRITETHRU (2ULL << TCR_IRGN0_SHIFT)
436 #define TCR_IRGN0_WRITEBACKNO (3ULL << TCR_IRGN0_SHIFT)
437
438 #define TCR_ORGN0_SHIFT 10ULL
439 #define TCR_ORGN0_DISABLED (0ULL << TCR_ORGN0_SHIFT)
440 #define TCR_ORGN0_WRITEBACK (1ULL << TCR_ORGN0_SHIFT)
441 #define TCR_ORGN0_WRITETHRU (2ULL << TCR_ORGN0_SHIFT)
442 #define TCR_ORGN0_WRITEBACKNO (3ULL << TCR_ORGN0_SHIFT)
443
444 #define TCR_SH0_SHIFT 12ULL
445 #define TCR_SH0_NONE (0ULL << TCR_SH0_SHIFT)
446 #define TCR_SH0_OUTER (2ULL << TCR_SH0_SHIFT)
447 #define TCR_SH0_INNER (3ULL << TCR_SH0_SHIFT)
448
449 #define TCR_TG0_GRANULE_SHIFT (14ULL)
450
451 #define TCR_TG0_GRANULE_4KB (0ULL << TCR_TG0_GRANULE_SHIFT)
452 #define TCR_TG0_GRANULE_64KB (1ULL << TCR_TG0_GRANULE_SHIFT)
453 #define TCR_TG0_GRANULE_16KB (2ULL << TCR_TG0_GRANULE_SHIFT)
454
455 #if __ARM_16K_PG__
456 #define TCR_TG0_GRANULE_SIZE (TCR_TG0_GRANULE_16KB)
457 #else
458 #define TCR_TG0_GRANULE_SIZE (TCR_TG0_GRANULE_4KB)
459 #endif
460
461 #define TCR_T1SZ_SHIFT 16ULL
462
463 #define TCR_A1_ASID1 (1ULL << 22ULL)
464 #define TCR_EPD1_TTBR1_DISABLED (1ULL << 23ULL)
465
466 #define TCR_IRGN1_SHIFT 24ULL
467 #define TCR_IRGN1_DISABLED (0ULL << TCR_IRGN1_SHIFT)
468 #define TCR_IRGN1_WRITEBACK (1ULL << TCR_IRGN1_SHIFT)
469 #define TCR_IRGN1_WRITETHRU (2ULL << TCR_IRGN1_SHIFT)
470 #define TCR_IRGN1_WRITEBACKNO (3ULL << TCR_IRGN1_SHIFT)
471
472 #define TCR_ORGN1_SHIFT 26ULL
473 #define TCR_ORGN1_DISABLED (0ULL << TCR_ORGN1_SHIFT)
474 #define TCR_ORGN1_WRITEBACK (1ULL << TCR_ORGN1_SHIFT)
475 #define TCR_ORGN1_WRITETHRU (2ULL << TCR_ORGN1_SHIFT)
476 #define TCR_ORGN1_WRITEBACKNO (3ULL << TCR_ORGN1_SHIFT)
477
478 #define TCR_SH1_SHIFT 28ULL
479 #define TCR_SH1_NONE (0ULL << TCR_SH1_SHIFT)
480 #define TCR_SH1_OUTER (2ULL << TCR_SH1_SHIFT)
481 #define TCR_SH1_INNER (3ULL << TCR_SH1_SHIFT)
482
483 #define TCR_TG1_GRANULE_SHIFT 30ULL
484
485 #define TCR_TG1_GRANULE_16KB (1ULL << TCR_TG1_GRANULE_SHIFT)
486 #define TCR_TG1_GRANULE_4KB (2ULL << TCR_TG1_GRANULE_SHIFT)
487 #define TCR_TG1_GRANULE_64KB (3ULL << TCR_TG1_GRANULE_SHIFT)
488
489 #if __ARM_16K_PG__
490 #define TCR_TG1_GRANULE_SIZE (TCR_TG1_GRANULE_16KB)
491 #else
492 #define TCR_TG1_GRANULE_SIZE (TCR_TG1_GRANULE_4KB)
493 #endif
494
495 #define TCR_IPS_SHIFT 32ULL
496 #define TCR_IPS_32BITS (0ULL << TCR_IPS_SHIFT)
497 #define TCR_IPS_36BITS (1ULL << TCR_IPS_SHIFT)
498 #define TCR_IPS_40BITS (2ULL << TCR_IPS_SHIFT)
499 #define TCR_IPS_42BITS (3ULL << TCR_IPS_SHIFT)
500 #define TCR_IPS_44BITS (4ULL << TCR_IPS_SHIFT)
501 #define TCR_IPS_48BITS (5ULL << TCR_IPS_SHIFT)
502
503 #define TCR_AS_16BIT_ASID (1ULL << 36)
504 #define TCR_TBI0_TOPBYTE_IGNORED (1ULL << 37)
505 #define TCR_TBI1_TOPBYTE_IGNORED (1ULL << 38)
506
507 /*
508 * Multiprocessor Affinity Register (MPIDR_EL1)
509 *
510 * +64-----------------------------31+30+29-25+24+23-16+15-8+7--0+
511 * |000000000000000000000000000000001| U|00000|MT| Aff2|Aff1|Aff0|
512 * +---------------------------------+--+-----+--+-----+----+----+
513 *
514 * where
515 * U Uniprocessor
516 * MT Multi-threading at lowest affinity level
517 * Aff2 "1" - PCORE, "0" - ECORE
518 * Aff1 Cluster ID
519 * Aff0 CPU ID
520 */
521 #define MPIDR_AFF0_MASK 0xFF
522 #define MPIDR_AFF1_MASK 0xFF00
523 #define MPIDR_AFF2_MASK 0xFF0000
524
525 /*
526 * We currently use a 3 level page table (rather than the full 4
527 * level page table). As a result, we do not have the full 48-bits
528 * of address space per TTBR (although the 16KB granule size lets us
529 * get very close).
530 */
531 #if __ARM64_TWO_LEVEL_PMAP__ && !__ARM_16K_PG__
532 #error ARM64 does not currently support a 2 level page table with 4KB pages
533 #endif /* __ARM64_TWO_LEVEL_PMAP__ */
534
535 /*
536 * TXSZ indicates the size of the range a TTBR covers. Currently,
537 * we support the following:
538 *
539 * 4KB pages, full page L1: 39 bit range.
540 * 4KB pages, sub-page L1: 38 bit range.
541 * 16KB pages, full page L1: 47 bit range.
542 * 16KB pages, sub-page L1: 39 bit range.
543 * 16KB pages, two level page tables: 36 bit range.
544 */
545 #if __ARM_KERNEL_PROTECT__
546 /*
547 * If we are configured to use __ARM_KERNEL_PROTECT__, the first half of the
548 * address space is used for the mappings that will remain in place when in EL0.
549 * As a result, 1 bit less of address space is available to the rest of the
550 * the kernel.
551 */
552 #endif /* __ARM_KERNEL_PROTECT__ */
553 #ifdef __ARM_16K_PG__
554 #if __ARM64_TWO_LEVEL_PMAP__
555 #define T0SZ_BOOT 28ULL
556 #elif __ARM64_PMAP_SUBPAGE_L1__
557 #define T0SZ_BOOT 25ULL
558 #else /* __ARM64_TWO_LEVEL_PMAP__ */
559 #define T0SZ_BOOT 17ULL
560 #endif /* __ARM64_TWO_LEVEL_PMAP__ */
561 #else /* __ARM_16K_PG__ */
562 #if __ARM64_PMAP_SUBPAGE_L1__
563 #define T0SZ_BOOT 26ULL
564 #else /* __ARM64_PMAP_SUBPAGE_L1__ */
565 #define T0SZ_BOOT 25ULL
566 #endif /* __ARM64_PMAP_SUBPAGE_L1__ */
567 #endif /* __ARM_16K_PG__ */
568
569 #if defined(APPLE_ARM64_ARCH_FAMILY)
570 /* T0SZ must be the same as T1SZ */
571 #define T1SZ_BOOT T0SZ_BOOT
572 #else /* defined(APPLE_ARM64_ARCH_FAMILY) */
573 #ifdef __ARM_16K_PG__
574 #if __ARM64_TWO_LEVEL_PMAP__
575 #define T1SZ_BOOT 28ULL
576 #elif __ARM64_PMAP_SUBPAGE_L1__
577 #define T1SZ_BOOT 25ULL
578 #else /* __ARM64_TWO_LEVEL_PMAP__ */
579 #define T1SZ_BOOT 17ULL
580 #endif /* __ARM64_TWO_LEVEL_PMAP__ */
581 #else /* __ARM_16K_PG__ */
582 #if __ARM64_PMAP_SUBPAGE_L1__
583 #define T1SZ_BOOT 26ULL
584 #else /* __ARM64_PMAP_SUBPAGE_L1__ */
585 #define T1SZ_BOOT 25ULL
586 #endif /*__ARM64_PMAP_SUBPAGE_L1__*/
587 #endif /* __ARM_16K_PG__ */
588 #endif /* defined(APPLE_ARM64_ARCH_FAMILY) */
589
590 #define TCR_EL1_BASE (TCR_IPS_40BITS | \
591 TCR_SH0_OUTER | TCR_ORGN0_WRITEBACK | TCR_IRGN0_WRITEBACK | (T0SZ_BOOT << TCR_T0SZ_SHIFT) | (TCR_TG0_GRANULE_SIZE) |\
592 TCR_SH1_OUTER | TCR_ORGN1_WRITEBACK | TCR_IRGN1_WRITEBACK | (TCR_TG1_GRANULE_SIZE))
593
594 #if __ARM_KERNEL_PROTECT__
595 #define TCR_EL1_BOOT (TCR_EL1_BASE | \
596 (T1SZ_BOOT << TCR_T1SZ_SHIFT) | TCR_TBI0_TOPBYTE_IGNORED)
597 #define T1SZ_USER (T1SZ_BOOT + 1)
598 #define TCR_EL1_USER (TCR_EL1_BASE | (T1SZ_USER << TCR_T1SZ_SHIFT) | TCR_TBI0_TOPBYTE_IGNORED)
599 #else
600 #define TCR_EL1_BOOT (TCR_EL1_BASE | \
601 (T1SZ_BOOT << TCR_T1SZ_SHIFT))
602 #endif /* __ARM_KERNEL_PROTECT__ */
603
604 /*
605 * Translation Table Base Register (TTBR)
606 *
607 * 63 48 47 x x-1 0
608 * +--------+------------------+------+
609 * | ASID | Base Address | zero |
610 * +--------+------------------+------+
611 *
612 */
613 #define TTBR_ASID_SHIFT 48
614 #define TTBR_ASID_MASK 0xffff000000000000
615
616 #define TTBR_BADDR_MASK 0x0000ffffffffffff
617
618 /*
619 * Memory Attribute Indirection Register
620 *
621 * 63 56 55 48 47 40 39 32 31 24 23 16 15 8 7 0
622 * +-------+-------+-------+-------+-------+-------+-------+-------+
623 * | Attr7 | Attr6 | Attr5 | Attr4 | Attr3 | Attr2 | Attr1 | Attr0 |
624 * +-------+-------+-------+-------+-------+-------+-------+-------+
625 *
626 */
627
628 #define MAIR_ATTR_SHIFT(x) (8*(x))
629
630 /* Strongly ordered or device memory attributes */
631 #define MAIR_OUTER_STRONGLY_ORDERED 0x0
632 #define MAIR_OUTER_DEVICE 0x0
633
634 #define MAIR_INNER_STRONGLY_ORDERED 0x0
635 #define MAIR_INNER_DEVICE 0x4
636
637 /* Normal memory attributes */
638 #define MAIR_OUTER_NON_CACHEABLE 0x40
639 #define MAIR_OUTER_WRITE_THROUGH 0x80
640 #define MAIR_OUTER_WRITE_BACK 0xc0
641
642 #define MAIR_INNER_NON_CACHEABLE 0x4
643 #define MAIR_INNER_WRITE_THROUGH 0x8
644 #define MAIR_INNER_WRITE_BACK 0xc
645
646 /* Allocate policy for cacheable memory */
647 #define MAIR_OUTER_WRITE_ALLOCATE 0x10
648 #define MAIR_OUTER_READ_ALLOCATE 0x20
649
650 #define MAIR_INNER_WRITE_ALLOCATE 0x1
651 #define MAIR_INNER_READ_ALLOCATE 0x2
652
653 /* Memory Atribute Encoding */
654
655 /* Device memory types:
656 G (gathering): multiple reads/writes can be combined
657 R (reordering): reads or writes may reach device out of program order
658 E (early-acknowledge): writes may return immediately (e.g. PCIe posted writes)
659 */
660 #define MAIR_DISABLE 0x00 /* Device Memory, nGnRnE (strongly ordered) */
661 #define MAIR_POSTED 0x04 /* Device Memory, nGnRE (strongly ordered, posted writes) */
662 #define MAIR_WRITECOMB 0x44 /* Normal Memory, Outer Non-Cacheable, Inner Non-Cacheable */
663 #define MAIR_WRITETHRU 0xBB /* Normal Memory, Outer Write-through, Inner Write-through */
664 #define MAIR_WRITEBACK 0xFF /* Normal Memory, Outer Write-back, Inner Write-back */
665 #define MAIR_INNERWRITEBACK 0x4F /* Normal Memory, Outer Non-Cacheable, Inner Write-back */
666
667
668 /*
669 * ARM 4-level Page Table support - 2*1024TB (2^48) of address space
670 */
671
672
673 /*
674 * Memory Attribute Index
675 */
676 #define CACHE_ATTRINDX_WRITEBACK 0x0 /* cache enabled, buffer enabled */
677 #define CACHE_ATTRINDX_WRITECOMB 0x1 /* no cache, buffered writes */
678 #define CACHE_ATTRINDX_WRITETHRU 0x2 /* cache enabled, buffer disabled */
679 #define CACHE_ATTRINDX_DISABLE 0x3 /* no cache, no buffer */
680 #define CACHE_ATTRINDX_INNERWRITEBACK 0x4 /* inner cache enabled, buffer enabled, write allocate */
681 #define CACHE_ATTRINDX_POSTED 0x5 /* no cache, no buffer, posted writes */
682 #define CACHE_ATTRINDX_DEFAULT CACHE_ATTRINDX_WRITEBACK
683
684 /*
685 * Access protection bit values (TTEs and PTEs)
686 */
687 #define AP_RWNA 0x0 /* priv=read-write, user=no-access */
688 #define AP_RWRW 0x1 /* priv=read-write, user=read-write */
689 #define AP_RONA 0x2 /* priv=read-only, user=no-access */
690 #define AP_RORO 0x3 /* priv=read-only, user=read-only */
691 #define AP_MASK 0x3 /* mask to find ap bits */
692
693 /*
694 * Shareability attributes
695 */
696 #define SH_NONE 0x0 /* Non shareable */
697 #define SH_NONE 0x0 /* Device shareable */
698 #define SH_DEVICE 0x2 /* Normal memory Inner non shareable - Outer non shareable */
699 #define SH_OUTER_MEMORY 0x2 /* Normal memory Inner shareable - Outer shareable */
700 #define SH_INNER_MEMORY 0x3 /* Normal memory Inner shareable - Outer non shareable */
701
702
703 /*
704 * ARM Page Granule
705 */
706 #ifdef __ARM_16K_PG__
707 #define ARM_PGSHIFT 14
708 #else
709 #define ARM_PGSHIFT 12
710 #endif
711 #define ARM_PGBYTES (1 << ARM_PGSHIFT)
712 #define ARM_PGMASK (ARM_PGBYTES-1)
713
714
715 /*
716 * L0 Translation table
717 *
718 * 4KB granule size:
719 * Each translation table is 4KB
720 * 512 64-bit entries of 512GB (2^39) of address space.
721 * Covers 256TB (2^48) of address space.
722 *
723 * 16KB granule size:
724 * Each translation table is 16KB
725 * 2 64-bit entries of 128TB (2^47) of address space.
726 * Covers 256TB (2^48) of address space.
727 */
728
729 #ifdef __ARM_16K_PG__
730 #define ARM_TT_L0_SIZE 0x0000800000000000ULL /* size of area covered by a tte */
731 #define ARM_TT_L0_OFFMASK 0x00007fffffffffffULL /* offset within an L0 entry */
732 #define ARM_TT_L0_SHIFT 47 /* page descriptor shift */
733 #define ARM_TT_L0_INDEX_MASK 0x0000800000000000ULL /* mask for getting index in L0 table from virtual address */
734 #else
735 #define ARM_TT_L0_SIZE 0x0000008000000000ULL /* size of area covered by a tte */
736 #define ARM_TT_L0_OFFMASK 0x0000007fffffffffULL /* offset within an L0 entry */
737 #define ARM_TT_L0_SHIFT 39 /* page descriptor shift */
738 #define ARM_TT_L0_INDEX_MASK 0x0000ff8000000000ULL /* mask for getting index in L0 table from virtual address */
739 #endif
740
741 /*
742 * L1 Translation table
743 *
744 * 4KB granule size:
745 * Each translation table is 4KB
746 * 512 64-bit entries of 1GB (2^30) of address space.
747 * Covers 512GB (2^39) of address space.
748 *
749 * 16KB granule size:
750 * Each translation table is 16KB
751 * 2048 64-bit entries of 64GB (2^36) of address space.
752 * Covers 128TB (2^47) of address space.
753 */
754
755 #ifdef __ARM_16K_PG__
756 #define ARM_TT_L1_SIZE 0x0000001000000000ULL /* size of area covered by a tte */
757 #define ARM_TT_L1_OFFMASK 0x0000000fffffffffULL /* offset within an L1 entry */
758 #define ARM_TT_L1_SHIFT 36 /* page descriptor shift */
759 #ifdef __ARM64_PMAP_SUBPAGE_L1__
760 /* This config supports 512GB per TTBR. */
761 #define ARM_TT_L1_INDEX_MASK 0x0000007000000000ULL /* mask for getting index into L1 table from virtual address */
762 #else /* __ARM64_PMAP_SUBPAGE_L1__ */
763 #define ARM_TT_L1_INDEX_MASK 0x00007ff000000000ULL /* mask for getting index into L1 table from virtual address */
764 #endif /* __ARM64_PMAP_SUBPAGE_L1__ */
765 #else /* __ARM_16K_PG__ */
766 #define ARM_TT_L1_SIZE 0x0000000040000000ULL /* size of area covered by a tte */
767 #define ARM_TT_L1_OFFMASK 0x000000003fffffffULL /* offset within an L1 entry */
768 #define ARM_TT_L1_SHIFT 30 /* page descriptor shift */
769 #ifdef __ARM64_PMAP_SUBPAGE_L1__
770 /* This config supports 256GB per TTBR. */
771 #define ARM_TT_L1_INDEX_MASK 0x0000003fc0000000ULL /* mask for getting index into L1 table from virtual address */
772 #else /* __ARM64_PMAP_SUBPAGE_L1__ */
773 #define ARM_TT_L1_INDEX_MASK 0x0000007fc0000000ULL /* mask for getting index into L1 table from virtual address */
774 #endif /* __ARM64_PMAP_SUBPAGE_L1__ */
775 #endif
776
777 /*
778 * L2 Translation table
779 *
780 * 4KB granule size:
781 * Each translation table is 4KB
782 * 512 64-bit entries of 2MB (2^21) of address space.
783 * Covers 1GB (2^30) of address space.
784 *
785 * 16KB granule size:
786 * Each translation table is 16KB
787 * 2048 64-bit entries of 32MB (2^25) of address space.
788 * Covers 64GB (2^36) of address space.
789 */
790
791 #ifdef __ARM_16K_PG__
792 #define ARM_TT_L2_SIZE 0x0000000002000000ULL /* size of area covered by a tte */
793 #define ARM_TT_L2_OFFMASK 0x0000000001ffffffULL /* offset within an L2 entry */
794 #define ARM_TT_L2_SHIFT 25 /* page descriptor shift */
795 #define ARM_TT_L2_INDEX_MASK 0x0000000ffe000000ULL /* mask for getting index in L2 table from virtual address */
796 #else
797 #define ARM_TT_L2_SIZE 0x0000000000200000ULL /* size of area covered by a tte */
798 #define ARM_TT_L2_OFFMASK 0x00000000001fffffULL /* offset within an L2 entry */
799 #define ARM_TT_L2_SHIFT 21 /* page descriptor shift */
800 #define ARM_TT_L2_INDEX_MASK 0x000000003fe00000ULL /* mask for getting index in L2 table from virtual address */
801 #endif
802
803 /*
804 * L3 Translation table
805 *
806 * 4KB granule size:
807 * Each translation table is 4KB
808 * 512 64-bit entries of 4KB (2^12) of address space.
809 * Covers 2MB (2^21) of address space.
810 *
811 * 16KB granule size:
812 * Each translation table is 16KB
813 * 2048 64-bit entries of 16KB (2^14) of address space.
814 * Covers 32MB (2^25) of address space.
815 */
816
817 #ifdef __ARM_16K_PG__
818 #define ARM_TT_L3_SIZE 0x0000000000004000ULL /* size of area covered by a tte */
819 #define ARM_TT_L3_OFFMASK 0x0000000000003fffULL /* offset within L3 PTE */
820 #define ARM_TT_L3_SHIFT 14 /* page descriptor shift */
821 #define ARM_TT_L3_INDEX_MASK 0x0000000001ffc000ULL /* mask for page descriptor index */
822 #else
823 #define ARM_TT_L3_SIZE 0x0000000000001000ULL /* size of area covered by a tte */
824 #define ARM_TT_L3_OFFMASK 0x0000000000000fffULL /* offset within L3 PTE */
825 #define ARM_TT_L3_SHIFT 12 /* page descriptor shift */
826 #define ARM_TT_L3_INDEX_MASK 0x00000000001ff000ULL /* mask for page descriptor index */
827 #endif
828
829 /*
830 * Convenience definitions for:
831 * ARM_TT_LEAF: The last level of the configured page table format.
832 * ARM_TT_TWIG: The second to last level of the configured page table format.
833 * ARM_TT_ROOT: The first level of the configured page table format.
834 *
835 * My apologies to any botanists who may be reading this.
836 */
837 #define ARM_TT_LEAF_SIZE ARM_TT_L3_SIZE
838 #define ARM_TT_LEAF_OFFMASK ARM_TT_L3_OFFMASK
839 #define ARM_TT_LEAF_SHIFT ARM_TT_L3_SHIFT
840 #define ARM_TT_LEAF_INDEX_MASK ARM_TT_L3_INDEX_MASK
841
842 #define ARM_TT_TWIG_SIZE ARM_TT_L2_SIZE
843 #define ARM_TT_TWIG_OFFMASK ARM_TT_L2_OFFMASK
844 #define ARM_TT_TWIG_SHIFT ARM_TT_L2_SHIFT
845 #define ARM_TT_TWIG_INDEX_MASK ARM_TT_L2_INDEX_MASK
846
847 #if __ARM64_TWO_LEVEL_PMAP__
848 #define ARM_TT_ROOT_SIZE ARM_TT_L2_SIZE
849 #define ARM_TT_ROOT_OFFMASK ARM_TT_L2_OFFMASK
850 #define ARM_TT_ROOT_SHIFT ARM_TT_L2_SHIFT
851 #define ARM_TT_ROOT_INDEX_MASK ARM_TT_L2_INDEX_MASK
852 #else
853 #define ARM_TT_ROOT_SIZE ARM_TT_L1_SIZE
854 #define ARM_TT_ROOT_OFFMASK ARM_TT_L1_OFFMASK
855 #define ARM_TT_ROOT_SHIFT ARM_TT_L1_SHIFT
856 #define ARM_TT_ROOT_INDEX_MASK ARM_TT_L1_INDEX_MASK
857 #endif
858
859 /*
860 * 4KB granule size:
861 *
862 * Level 0 Translation Table Entry
863 *
864 * 63 62 61 60 59 58 52 51 48 47 12 11 2 1 0
865 * +--+-----+--+---+-------+------+----------------------+-------+-+-+
866 * |NS| AP |XN|PXN|ignored| zero | L1TableOutputAddress |ignored|1|V|
867 * +--+-----+--+---+-------+------+----------------------+-------+-+-+
868 *
869 * Level 1 Translation Table Entry
870 *
871 * 63 62 61 60 59 58 52 51 48 47 12 11 2 1 0
872 * +--+-----+--+---+-------+------+----------------------+-------+-+-+
873 * |NS| AP |XN|PXN|ignored| zero | L2TableOutputAddress |ignored|1|V|
874 * +--+-----+--+---+-------+------+----------------------+-------+-+-+
875 *
876 * Level 1 Translation Block Entry
877 *
878 * 63 59 58 55 54 53 52 51 48 47 30 29 12 11 10 9 8 7 6 5 4 2 1 0
879 * +-----+------+--+---+----+------+----------------------+------+--+--+----+----+--+-------+-+-+
880 * | ign |sw use|XN|PXN|HINT| zero | OutputAddress[47:30] | zero |nG|AF| SH | AP |NS|AttrIdx|0|V|
881 * +-----+------+--+---+----+------+----------------------+------+--+--+----+----+--+-------+-+-+
882 *
883 * Level 2 Translation Table Entry
884 *
885 * 63 62 61 60 59 58 52 51 48 47 12 11 2 1 0
886 * +--+-----+--+---+-------+------+----------------------+-------+-+-+
887 * |NS| AP |XN|PXN|ignored| zero | L3TableOutputAddress |ignored|1|V|
888 * +--+-----+--+---+-------+------+----------------------+-------+-+-+
889 *
890 * Level 2 Translation Block Entry
891 *
892 * 63 59 58 55 54 53 52 51 48 47 21 20 12 11 10 9 8 7 6 5 4 2 1 0
893 * +-----+------+--+---+----+------+----------------------+------+--+--+----+----+--+-------+-+-+
894 * | ign |sw use|XN|PXN|HINT| zero | OutputAddress[47:21] | zero |nG|AF| SH | AP |NS|AttrIdx|0|V|
895 * +-----+------+--+---+----+------+----------------------+------+--+--+----+----+--+-------+-+-+
896 *
897 * 16KB granule size:
898 *
899 * Level 0 Translation Table Entry
900 *
901 * 63 62 61 60 59 58 52 51 48 47 14 13 2 1 0
902 * +--+-----+--+---+-------+------+----------------------+-------+-+-+
903 * |NS| AP |XN|PXN|ignored| zero | L1TableOutputAddress |ignored|1|V|
904 * +--+-----+--+---+-------+------+----------------------+-------+-+-+
905 *
906 * Level 1 Translation Table Entry
907 *
908 * 63 62 61 60 59 58 52 51 48 47 14 13 2 1 0
909 * +--+-----+--+---+-------+------+----------------------+-------+-+-+
910 * |NS| AP |XN|PXN|ignored| zero | L2TableOutputAddress |ignored|1|V|
911 * +--+-----+--+---+-------+------+----------------------+-------+-+-+
912 *
913 * Level 2 Translation Table Entry
914 *
915 * 63 62 61 60 59 58 52 51 48 47 14 13 2 1 0
916 * +--+-----+--+---+-------+------+----------------------+-------+-+-+
917 * |NS| AP |XN|PXN|ignored| zero | L3TableOutputAddress |ignored|1|V|
918 * +--+-----+--+---+-------+------+----------------------+-------+-+-+
919 *
920 * Level 2 Translation Block Entry
921 *
922 * 63 59 58 55 54 53 52 51 48 47 25 24 12 11 10 9 8 7 6 5 4 2 1 0
923 * +-----+------+--+---+----+------+----------------------+------+--+--+----+----+--+-------+-+-+
924 * | ign |sw use|XN|PXN|HINT| zero | OutputAddress[47:25] | zero |nG|AF| SH | AP |NS|AttrIdx|0|V|
925 * +-----+------+--+---+----+------+----------------------+------+--+--+----+----+--+-------+-+-+
926 *
927 * where:
928 * 'nG' notGlobal bit
929 * 'SH' Shareability field
930 * 'AP' access protection
931 * 'XN' eXecute Never bit
932 * 'PXN' Privilege eXecute Never bit
933 * 'NS' Non-Secure bit
934 * 'HINT' 16 entry continuguous output hint
935 * 'AttrIdx' Memory Attribute Index
936 */
937
938 #define TTE_SHIFT 3 /* shift width of a tte (sizeof(tte) == (1 << TTE_SHIFT)) */
939 #ifdef __ARM_16K_PG__
940 #define TTE_PGENTRIES (16384 >> TTE_SHIFT) /* number of ttes per page */
941 #else
942 #define TTE_PGENTRIES (4096 >> TTE_SHIFT) /* number of ttes per page */
943 #endif
944
945 #define ARM_TTE_MAX (TTE_PGENTRIES)
946
947 #define ARM_TTE_EMPTY 0x0000000000000000ULL /* unasigned - invalid entry */
948 #define ARM_TTE_TYPE_FAULT 0x0000000000000000ULL /* unasigned - invalid entry */
949
950 #define ARM_TTE_VALID 0x0000000000000001ULL /* valid entry */
951
952 #define ARM_TTE_TYPE_MASK 0x0000000000000002ULL /* mask for extracting the type */
953 #define ARM_TTE_TYPE_TABLE 0x0000000000000002ULL /* page table type */
954 #define ARM_TTE_TYPE_BLOCK 0x0000000000000000ULL /* block entry type */
955 #define ARM_TTE_TYPE_L3BLOCK 0x0000000000000002ULL
956 #define ARM_TTE_TYPE_MASK 0x0000000000000002ULL /* mask for extracting the type */
957
958 #ifdef __ARM_16K_PG__
959 /* Note that L0/L1 block entries are disallowed for the 16KB granule size; what are we doing with these? */
960 #define ARM_TTE_BLOCK_SHIFT 12 /* entry shift for a 16KB L3 TTE entry */
961 #define ARM_TTE_BLOCK_L0_SHIFT ARM_TT_L0_SHIFT /* block shift for 128TB section */
962 #define ARM_TTE_BLOCK_L1_MASK 0x0000fff000000000ULL /* mask to extract phys address from L1 block entry */
963 #define ARM_TTE_BLOCK_L1_SHIFT ARM_TT_L1_SHIFT /* block shift for 64GB section */
964 #define ARM_TTE_BLOCK_L2_MASK 0x0000fffffe000000ULL /* mask to extract phys address from Level 2 Translation Block entry */
965 #define ARM_TTE_BLOCK_L2_SHIFT ARM_TT_L2_SHIFT /* block shift for 32MB section */
966 #else
967 #define ARM_TTE_BLOCK_SHIFT 12 /* entry shift for a 4KB L3 TTE entry */
968 #define ARM_TTE_BLOCK_L0_SHIFT ARM_TT_L0_SHIFT /* block shift for 2048GB section */
969 #define ARM_TTE_BLOCK_L1_MASK 0x0000ffffc0000000ULL /* mask to extract phys address from L1 block entry */
970 #define ARM_TTE_BLOCK_L1_SHIFT ARM_TT_L1_SHIFT /* block shift for 1GB section */
971 #define ARM_TTE_BLOCK_L2_MASK 0x0000ffffffe00000ULL /* mask to extract phys address from Level 2 Translation Block entry */
972 #define ARM_TTE_BLOCK_L2_SHIFT ARM_TT_L2_SHIFT /* block shift for 2MB section */
973 #endif
974
975 #define ARM_TTE_BLOCK_APSHIFT 6
976 #define ARM_TTE_BLOCK_AP(x) ((x)<<ARM_TTE_BLOCK_APSHIFT) /* access protection */
977 #define ARM_TTE_BLOCK_APMASK (0x3 << ARM_TTE_BLOCK_APSHIFT)
978
979 #define ARM_TTE_BLOCK_ATTRINDX(x) ((x) << 2) /* memory attributes index */
980 #define ARM_TTE_BLOCK_ATTRINDXMASK (0x7ULL << 2) /* mask memory attributes index */
981
982 #define ARM_TTE_BLOCK_SH(x) ((x) << 8) /* access shared */
983 #define ARM_TTE_BLOCK_SHMASK (0x3ULL << 8) /* mask access shared */
984
985 #define ARM_TTE_BLOCK_AF 0x0000000000000400ULL /* value for access */
986 #define ARM_TTE_BLOCK_AFMASK 0x0000000000000400ULL /* access mask */
987
988 #define ARM_TTE_BLOCK_NG 0x0000000000000800ULL /* value for a global mapping */
989 #define ARM_TTE_BLOCK_NG_MASK 0x0000000000000800ULL /* notGlobal mapping mask */
990
991 #define ARM_TTE_BLOCK_NS 0x0000000000000020ULL /* value for a secure mapping */
992 #define ARM_TTE_BLOCK_NS_MASK 0x0000000000000020ULL /* notSecure mapping mask */
993
994 #define ARM_TTE_BLOCK_PNX 0x0020000000000000ULL /* value for privilege no execute bit */
995 #define ARM_TTE_BLOCK_PNXMASK 0x0020000000000000ULL /* privilege execute mask */
996
997 #define ARM_TTE_BLOCK_NX 0x0040000000000000ULL /* value for no execute */
998 #define ARM_TTE_BLOCK_NXMASK 0x0040000000000000ULL /* no execute mask */
999
1000 #define ARM_TTE_BLOCK_WIRED 0x0080000000000000ULL /* value for software wired bit */
1001 #define ARM_TTE_BLOCK_WIREDMASK 0x0080000000000000ULL /* software wired mask */
1002
1003 #define ARM_TTE_BLOCK_WRITEABLE 0x0100000000000000ULL /* value for software writeable bit */
1004 #define ARM_TTE_BLOCK_WRITEABLEMASK 0x0100000000000000ULL /* software writeable mask */
1005
1006 #ifdef __ARM_16K_PG__
1007 /*
1008 * TODO: Do we care about the low bits being unused? It should technically work either way, but masking them out should be future proof;
1009 * it is only a matter of time before someone wants to shove something into the free bits.
1010 */
1011 #define ARM_TTE_TABLE_MASK (0x0000ffffffffc000ULL) /* mask for extracting pointer to next table (works at any level) */
1012 #else
1013 #define ARM_TTE_TABLE_MASK (0x0000fffffffff000ULL) /* mask for extracting pointer to next table (works at any level) */
1014 #endif
1015
1016 #define ARM_TTE_TABLE_APSHIFT 61
1017 #define ARM_TTE_TABLE_AP(x) ((x)<<TTE_BLOCK_APSHIFT) /* access protection */
1018
1019 #define ARM_TTE_TABLE_NS 0x8000000000000020ULL /* value for a secure mapping */
1020 #define ARM_TTE_TABLE_NS_MASK 0x8000000000000020ULL /* notSecure mapping mask */
1021
1022 #define ARM_TTE_TABLE_XN 0x1000000000000000ULL /* value for no execute */
1023 #define ARM_TTE_TABLE_XNMASK 0x1000000000000000ULL /* no execute mask */
1024
1025 #define ARM_TTE_TABLE_PXN 0x0800000000000000ULL /* value for privilege no execute bit */
1026 #define ARM_TTE_TABLE_PXNMASK 0x0800000000000000ULL /* privilege execute mask */
1027
1028 #if __ARM_KERNEL_PROTECT__
1029 #define ARM_TTE_BOOT_BLOCK (ARM_TTE_TYPE_BLOCK | ARM_TTE_VALID | ARM_TTE_BLOCK_SH(SH_OUTER_MEMORY) \
1030 | ARM_TTE_BLOCK_ATTRINDX(CACHE_ATTRINDX_WRITEBACK) | ARM_TTE_BLOCK_AF \
1031 | ARM_TTE_BLOCK_NG)
1032 #else /* __ARM_KERNEL_PROTECT__ */
1033 #define ARM_TTE_BOOT_BLOCK (ARM_TTE_TYPE_BLOCK | ARM_TTE_VALID | ARM_TTE_BLOCK_SH(SH_OUTER_MEMORY) \
1034 | ARM_TTE_BLOCK_ATTRINDX(CACHE_ATTRINDX_WRITEBACK) | ARM_TTE_BLOCK_AF)
1035 #endif /* __ARM_KERNEL_PROTECT__ */
1036
1037 #define ARM_TTE_BOOT_TABLE (ARM_TTE_TYPE_TABLE | ARM_TTE_VALID )
1038 /*
1039 * L3 Translation table
1040 *
1041 * 4KB granule size:
1042 * Each translation table is 4KB
1043 * 512 64-bit entries of 4KB (2^12) of address space.
1044 * Covers 2MB (2^21) of address space.
1045 *
1046 * 16KB granule size:
1047 * Each translation table is 16KB
1048 * 2048 64-bit entries of 16KB (2^14) of address space.
1049 * Covers 32MB (2^25) of address space.
1050 */
1051
1052 #ifdef __ARM_16K_PG__
1053 #define ARM_PTE_SIZE 0x0000000000004000ULL /* size of area covered by a tte */
1054 #define ARM_PTE_OFFMASK 0x0000000000003fffULL /* offset within pte area */
1055 #define ARM_PTE_SHIFT 14 /* page descriptor shift */
1056 #define ARM_PTE_MASK 0x0000ffffffffc000ULL /* mask for output address in PTE */
1057 #else
1058 #define ARM_PTE_SIZE 0x0000000000001000ULL /* size of area covered by a tte */
1059 #define ARM_PTE_OFFMASK 0x0000000000000fffULL /* offset within pte area */
1060 #define ARM_PTE_SHIFT 12 /* page descriptor shift */
1061 #define ARM_PTE_MASK 0x0000fffffffff000ULL /* mask for output address in PTE */
1062 #endif
1063
1064 /*
1065 * L3 Page table entries
1066 *
1067 * The following page table entry types are possible:
1068 *
1069 * fault page entry
1070 * 63 2 0
1071 * +------------------------------+--+
1072 * | ignored |00|
1073 * +------------------------------+--+
1074 *
1075 *
1076 * 63 59 58 55 54 53 52 51 48 47 12 11 10 9 8 7 6 5 4 2 1 0
1077 * +-----+------+--+---+----+------+----------------------+--+--+----+----+--+-------+-+-+
1078 * | ign |sw use|XN|PXN|HINT| zero | OutputAddress[47:12] |nG|AF| SH | AP |NS|AttrIdx|1|V|
1079 * +-----+------+--+---+----+------+----------------------+--+--+----+----+--+-------+-+-+
1080 *
1081 * where:
1082 * 'nG' notGlobal bit
1083 * 'SH' Shareability field
1084 * 'AP' access protection
1085 * 'XN' eXecute Never bit
1086 * 'PXN' Privilege eXecute Never bit
1087 * 'NS' Non-Secure bit
1088 * 'HINT' 16 entry continuguous output hint
1089 * 'AttrIdx' Memory Attribute Index
1090 */
1091
1092 #define PTE_SHIFT 3 /* shift width of a pte (sizeof(pte) == (1 << PTE_SHIFT)) */
1093 #ifdef __ARM_16K_PG__
1094 #define PTE_PGENTRIES (16384 >> PTE_SHIFT) /* number of ptes per page */
1095 #else
1096 #define PTE_PGENTRIES (4096 >> PTE_SHIFT) /* number of ptes per page */
1097 #endif
1098
1099 #define ARM_PTE_EMPTY 0x0000000000000000ULL /* unasigned - invalid entry */
1100
1101 /* markers for (invalid) PTE for a page sent to compressor */
1102 #define ARM_PTE_COMPRESSED 0x8000000000000000ULL /* compressed... */
1103 #define ARM_PTE_COMPRESSED_ALT 0x4000000000000000ULL /* ... and was "alt_acct" */
1104 #define ARM_PTE_COMPRESSED_MASK 0xC000000000000000ULL
1105 #define ARM_PTE_IS_COMPRESSED(x) \
1106 ((((x) & 0x3) == 0) && /* PTE is not valid... */ \
1107 ((x) & ARM_PTE_COMPRESSED) && /* ...has "compressed" marker" */ \
1108 ((!((x) & ~ARM_PTE_COMPRESSED_MASK)) || /* ...no other bits */ \
1109 (panic("compressed PTE %p 0x%llx has extra bits 0x%llx: corrupted?", \
1110 &(x), (x), (x) & ~ARM_PTE_COMPRESSED_MASK), FALSE)))
1111
1112 #define ARM_PTE_TYPE 0x0000000000000003ULL /* valid L3 entry: includes bit #1 (counterintuitively) */
1113 #define ARM_PTE_TYPE_VALID 0x0000000000000003ULL /* valid L3 entry: includes bit #1 (counterintuitively) */
1114 #define ARM_PTE_TYPE_FAULT 0x0000000000000000ULL /* invalid L3 entry */
1115 #define ARM_PTE_TYPE_MASK 0x0000000000000002ULL /* mask to get pte type */
1116
1117 #ifdef __ARM_16K_PG__
1118 /* TODO: What does the shift mean here? */
1119 #define ARM_PTE_PAGE_MASK 0x0000FFFFFFFFC000ULL /* mask for 16KB page */
1120 #else
1121 #define ARM_PTE_PAGE_MASK 0x0000FFFFFFFFF000ULL /* mask for 4KB page */
1122 #define ARM_PTE_PAGE_SHIFT 12 /* page shift for 4KB page */
1123 #endif
1124
1125 #define ARM_PTE_AP(x) ((x) << 6) /* access protections */
1126 #define ARM_PTE_APMASK (0x3ULL << 6) /* mask access protections */
1127 #define ARM_PTE_EXTRACT_AP(x) (((x) >> 6) & 0x3ULL) /* extract access protections from PTE */
1128
1129 #define ARM_PTE_ATTRINDX(x) ((x) << 2) /* memory attributes index */
1130 #define ARM_PTE_ATTRINDXMASK (0x7ULL << 2) /* mask memory attributes index */
1131
1132 #define ARM_PTE_SH(x) ((x) << 8) /* access shared */
1133 #define ARM_PTE_SHMASK (0x3ULL << 8) /* mask access shared */
1134
1135 #define ARM_PTE_AF 0x0000000000000400ULL /* value for access */
1136 #define ARM_PTE_AFMASK 0x0000000000000400ULL /* access mask */
1137
1138 #define ARM_PTE_NG 0x0000000000000800ULL /* value for a global mapping */
1139 #define ARM_PTE_NG_MASK 0x0000000000000800ULL /* notGlobal mapping mask */
1140
1141 #define ARM_PTE_NS 0x0000000000000020ULL /* value for a secure mapping */
1142 #define ARM_PTE_NS_MASK 0x0000000000000020ULL /* notSecure mapping mask */
1143
1144 #define ARM_PTE_HINT 0x0010000000000000ULL /* value for contiguous entries hint */
1145 #define ARM_PTE_HINT_MASK 0x0010000000000000ULL /* mask for contiguous entries hint */
1146
1147 #if __ARM_16K_PG__
1148 #define ARM_PTE_HINT_ENTRIES 128ULL /* number of entries the hint covers */
1149 #define ARM_PTE_HINT_ENTRIES_SHIFT 7ULL /* shift to construct the number of entries */
1150 #define ARM_PTE_HINT_ADDR_MASK 0x0000FFFFFFE00000ULL /* mask to extract the starting hint address */
1151 #define ARM_PTE_HINT_ADDR_SHIFT 21 /* shift for the hint address */
1152 #else
1153 #define ARM_PTE_HINT_ENTRIES 16ULL /* number of entries the hint covers */
1154 #define ARM_PTE_HINT_ENTRIES_SHIFT 4ULL /* shift to construct the number of entries */
1155 #define ARM_PTE_HINT_ADDR_MASK 0x0000FFFFFFFF0000ULL /* mask to extract the starting hint address */
1156 #define ARM_PTE_HINT_ADDR_SHIFT 16 /* shift for the hint address */
1157 #endif
1158
1159 #define ARM_PTE_PNX 0x0020000000000000ULL /* value for no execute */
1160 #define ARM_PTE_PNXMASK 0x0020000000000000ULL /* no execute mask */
1161
1162 #define ARM_PTE_NX 0x0040000000000000ULL /* value for privilege no execute bit */
1163 #define ARM_PTE_NXMASK 0x0040000000000000ULL /* privilege execute mask */
1164
1165 #define ARM_PTE_WIRED 0x0080000000000000ULL /* value for software wired bit */
1166 #define ARM_PTE_WIRED_MASK 0x0080000000000000ULL /* software wired mask */
1167
1168 #define ARM_PTE_WRITEABLE 0x0100000000000000ULL /* value for software writeable bit */
1169 #define ARM_PTE_WRITEABLE_MASK 0x0100000000000000ULL /* software writeable mask */
1170
1171 #if CONFIG_PGTRACE
1172 #define ARM_PTE_PGTRACE 0x0200000000000000ULL /* value for software trace bit */
1173 #define ARM_PTE_PGTRACE_MASK 0x0200000000000000ULL /* software trace mask */
1174 #endif
1175
1176 #define ARM_PTE_BOOT_PAGE_BASE (ARM_PTE_TYPE_VALID | ARM_PTE_SH(SH_OUTER_MEMORY) \
1177 | ARM_PTE_ATTRINDX(CACHE_ATTRINDX_WRITEBACK) | ARM_PTE_AF)
1178
1179 #if __ARM_KERNEL_PROTECT__
1180 #define ARM_PTE_BOOT_PAGE (ARM_PTE_BOOT_PAGE_BASE | ARM_PTE_NG)
1181 #else /* __ARM_KERNEL_PROTECT__ */
1182 #define ARM_PTE_BOOT_PAGE (ARM_PTE_BOOT_PAGE_BASE)
1183 #endif /* __ARM_KERNEL_PROTECT__ */
1184
1185 /*
1186 * TLBI appers to only deal in 4KB page addresses, so give
1187 * it an explicit shift of 12.
1188 */
1189 #define TLBI_ADDR_SIZE (44)
1190 #define TLBI_ADDR_MASK ((1ULL << TLBI_ADDR_SIZE) - 1)
1191 #define TLBI_ADDR_SHIFT (12)
1192 #define TLBI_ASID_SHIFT (48)
1193 #define TLBI_ASID_SIZE (16)
1194 #define TLBI_ASID_MASK (((1ULL << TLBI_ASID_SIZE) - 1) << TLBI_ASID_SHIFT)
1195
1196 /*
1197 * Exception Syndrome Register
1198 *
1199 * 31 26 25 24 0
1200 * +------+--+------------------+
1201 * | EC |IL| ISS |
1202 * +------+--+------------------+
1203 *
1204 * EC - Exception Class
1205 * IL - Instruction Length
1206 * ISS- Instruction Specific Syndrome
1207 *
1208 * Note: The ISS can have many forms. These are defined separately below.
1209 */
1210
1211 #define ESR_EC_SHIFT 26
1212 #define ESR_EC_MASK (0x3F << ESR_EC_SHIFT)
1213 #define ESR_EC(x) ((x & ESR_EC_MASK) >> ESR_EC_SHIFT)
1214
1215 #define ESR_IL_SHIFT 25
1216 #define ESR_IL (1 << ESR_IL_SHIFT)
1217
1218 #define ESR_INSTR_IS_2BYTES(x) (!(x & ESR_IL))
1219
1220 #define ESR_ISS_MASK 0x01FFFFFF
1221 #define ESR_ISS(x) (x & ESR_ISS_MASK)
1222
1223 #ifdef __ASSEMBLER__
1224 /* Define only the classes we need to test in the exception vectors. */
1225 #define ESR_EC_IABORT_EL1 0x21
1226 #define ESR_EC_DABORT_EL1 0x25
1227 #define ESR_EC_SP_ALIGN 0x26
1228 #else
1229 typedef enum {
1230 ESR_EC_UNCATEGORIZED = 0x00,
1231 ESR_EC_WFI_WFE = 0x01,
1232 ESR_EC_MCR_MRC_CP15_TRAP = 0x03,
1233 ESR_EC_MCRR_MRRC_CP15_TRAP = 0x04,
1234 ESR_EC_MCR_MRC_CP14_TRAP = 0x05,
1235 ESR_EC_LDC_STC_CP14_TRAP = 0x06,
1236 ESR_EC_TRAP_SIMD_FP = 0x07,
1237 ESR_EC_MCRR_MRRC_CP14_TRAP = 0x0c,
1238 ESR_EC_ILLEGAL_INSTR_SET = 0x0e,
1239 ESR_EC_SVC_32 = 0x11,
1240 ESR_EC_SVC_64 = 0x15,
1241 ESR_EC_MSR_TRAP = 0x18,
1242 ESR_EC_IABORT_EL0 = 0x20,
1243 ESR_EC_IABORT_EL1 = 0x21,
1244 ESR_EC_PC_ALIGN = 0x22,
1245 ESR_EC_DABORT_EL0 = 0x24,
1246 ESR_EC_DABORT_EL1 = 0x25,
1247 ESR_EC_SP_ALIGN = 0x26,
1248 ESR_EC_FLOATING_POINT_32 = 0x28,
1249 ESR_EC_FLOATING_POINT_64 = 0x2C,
1250 ESR_EC_BKPT_REG_MATCH_EL0 = 0x30, // Breakpoint Debug event taken to the EL from a lower EL.
1251 ESR_EC_BKPT_REG_MATCH_EL1 = 0x31, // Breakpoint Debug event taken to the EL from the EL.
1252 ESR_EC_SW_STEP_DEBUG_EL0 = 0x32, // Software Step Debug event taken to the EL from a lower EL.
1253 ESR_EC_SW_STEP_DEBUG_EL1 = 0x33, // Software Step Debug event taken to the EL from the EL.
1254 ESR_EC_WATCHPT_MATCH_EL0 = 0x34, // Watchpoint Debug event taken to the EL from a lower EL.
1255 ESR_EC_WATCHPT_MATCH_EL1 = 0x35, // Watchpoint Debug event taken to the EL from the EL.
1256 ESR_EC_BKPT_AARCH32 = 0x38,
1257 ESR_EC_BRK_AARCH64 = 0x3C
1258 } esr_exception_class_t;
1259
1260 typedef enum {
1261 FSC_TRANSLATION_FAULT_L0 = 0x04,
1262 FSC_TRANSLATION_FAULT_L1 = 0x05,
1263 FSC_TRANSLATION_FAULT_L2 = 0x06,
1264 FSC_TRANSLATION_FAULT_L3 = 0x07,
1265 FSC_ACCESS_FLAG_FAULT_L1 = 0x09,
1266 FSC_ACCESS_FLAG_FAULT_L2 = 0x0A,
1267 FSC_ACCESS_FLAG_FAULT_L3 = 0x0B,
1268 FSC_PERMISSION_FAULT_L1 = 0x0D,
1269 FSC_PERMISSION_FAULT_L2 = 0x0E,
1270 FSC_PERMISSION_FAULT_L3 = 0x0F,
1271 FSC_SYNC_EXT_ABORT = 0x10,
1272 FSC_ASYNC_EXT_ABORT = 0x11,
1273 FSC_SYNC_EXT_ABORT_TT_L1 = 0x15,
1274 FSC_SYNC_EXT_ABORT_TT_L2 = 0x16,
1275 FSC_SYNC_EXT_ABORT_TT_L3 = 0x17,
1276 FSC_SYNC_PARITY = 0x18,
1277 FSC_ASYNC_PARITY = 0x19,
1278 FSC_SYNC_PARITY_TT_L1 = 0x1D,
1279 FSC_SYNC_PARITY_TT_L2 = 0x1E,
1280 FSC_SYNC_PARITY_TT_L3 = 0x1F,
1281 FSC_ALIGNMENT_FAULT = 0x21,
1282 FSC_DEBUG_FAULT = 0x22
1283 } fault_status_t;
1284 #endif /* ASSEMBLER */
1285
1286 /*
1287 * Software step debug event ISS (EL1)
1288 * 24 23 6 5 0
1289 * +---+-----------------+--+------+
1290 * |ISV|00000000000000000|EX| IFSC |
1291 * +---+-----------------+--+------+
1292 *
1293 * where:
1294 * ISV Instruction syndrome valid
1295 * EX Exclusive access
1296 * IFSC Instruction Fault Status Code
1297 */
1298
1299 #define ISS_SSDE_ISV_SHIFT 24
1300 #define ISS_SSDE_ISV (0x1 << ISS_SSDE_ISV_SHIFT)
1301
1302 #define ISS_SSDE_EX_SHIFT 6
1303 #define ISS_SSDE_EX (0x1 << ISS_SSDE_EX_SHIFT)
1304
1305 #define ISS_SSDE_FSC_MASK 0x3F
1306 #define ISS_SSDE_FSC(x) (x & ISS_SSDE_FSC_MASK)
1307
1308 /*
1309 * Instruction Abort ISS (EL1)
1310 * 24 10 9 5 0
1311 * +---------------+--+---+------+
1312 * |000000000000000|EA|000| IFSC |
1313 * +---------------+--+---+------+
1314 *
1315 * where:
1316 * EA External Abort type
1317 * IFSC Instruction Fault Status Code
1318 */
1319
1320 #define ISS_IA_EA_SHIFT 9
1321 #define ISS_IA_EA (0x1 << ISS_IA_EA_SHIFT)
1322
1323 #define ISS_IA_FSC_MASK 0x3F
1324 #define ISS_IA_FSC(x) (x & ISS_IA_FSC_MASK)
1325
1326
1327 /*
1328 * Data Abort ISS (EL1)
1329 *
1330 * 24 9 8 7 6 5 0
1331 * +---------------+--+--+-+---+----+
1332 * |000000000000000|EA|CM|0|WnR|DFSC|
1333 * +---------------+--+--+-+---+----+
1334 *
1335 * where:
1336 * EA External Abort type
1337 * CM Cache Maintenance operation
1338 * WnR Write not Read
1339 * DFSC Data Fault Status Code
1340 */
1341 #define ISS_DA_EA_SHIFT 9
1342 #define ISS_DA_EA (0x1 << ISS_DA_EA_SHIFT)
1343
1344 #define ISS_DA_CM_SHIFT 8
1345 #define ISS_DA_CM (0x1 << ISS_DA_CM_SHIFT)
1346
1347 #define ISS_DA_WNR_SHIFT 6
1348 #define ISS_DA_WNR (0x1 << ISS_DA_WNR_SHIFT)
1349
1350 #define ISS_DA_FSC_MASK 0x3F
1351 #define ISS_DA_FSC(x) (x & ISS_DA_FSC_MASK)
1352
1353 /*
1354 * Physical Address Register (EL1)
1355 */
1356 #define PAR_F_SHIFT 0
1357 #define PAR_F (0x1 << PAR_F_SHIFT)
1358
1359 #define PLATFORM_SYSCALL_TRAP_NO 0x80000000
1360
1361 #define ARM64_SYSCALL_CODE_REG_NUM (16)
1362
1363 #define ARM64_CLINE_SHIFT 6
1364
1365 #if defined(APPLE_ARM64_ARCH_FAMILY)
1366 #define L2CERRSTS_DATSBEESV (1ULL << 2) /* L2C data single bit ECC error */
1367 #define L2CERRSTS_DATDBEESV (1ULL << 4) /* L2C data double bit ECC error */
1368 #endif
1369
1370 /*
1371 * Timer definitions.
1372 */
1373 #define CNTKCTL_EL1_PL0PTEN (0x1 << 9) /* 1: EL0 access to physical timer regs permitted */
1374 #define CNTKCTL_EL1_PL0VTEN (0x1 << 8) /* 1: EL0 access to virtual timer regs permitted */
1375 #define CNTKCTL_EL1_EVENTI_MASK (0x000000f0) /* Mask for bits describing which bit to use for triggering event stream */
1376 #define CNTKCTL_EL1_EVENTI_SHIFT (0x4) /* Shift for same */
1377 #define CNTKCTL_EL1_EVENTDIR (0x1 << 3) /* 1: one-to-zero transition of specified bit causes event */
1378 #define CNTKCTL_EL1_EVNTEN (0x1 << 2) /* 1: enable event stream */
1379 #define CNTKCTL_EL1_PL0VCTEN (0x1 << 1) /* 1: EL0 access to physical timebase + frequency reg enabled */
1380 #define CNTKCTL_EL1_PL0PCTEN (0x1 << 0) /* 1: EL0 access to virtual timebase + frequency reg enabled */
1381
1382 #define CNTV_CTL_EL0_ISTATUS (0x1 << 2) /* (read only): whether interrupt asserted */
1383 #define CNTV_CTL_EL0_IMASKED (0x1 << 1) /* 1: interrupt masked */
1384 #define CNTV_CTL_EL0_ENABLE (0x1 << 0) /* 1: virtual timer enabled */
1385
1386 #define CNTP_CTL_EL0_ISTATUS CNTV_CTL_EL0_ISTATUS
1387 #define CNTP_CTL_EL0_IMASKED CNTV_CTL_EL0_IMASKED
1388 #define CNTP_CTL_EL0_ENABLE CNTV_CTL_EL0_ENABLE
1389
1390 /*
1391 * At present all other uses of ARM_DBG_* are shared bit compatibly with the 32bit definitons.
1392 * (cf. osfmk/arm/proc_reg.h)
1393 */
1394 #define ARM_DBG_VR_ADDRESS_MASK64 0xFFFFFFFFFFFFFFFCull /* BVR & WVR */
1395
1396 #define MIDR_EL1_REV_SHIFT 0
1397 #define MIDR_EL1_REV_MASK (0xf << MIDR_EL1_REV_SHIFT)
1398 #define MIDR_EL1_PNUM_SHIFT 4
1399 #define MIDR_EL1_PNUM_MASK (0xfff << MIDR_EL1_PNUM_SHIFT)
1400 #define MIDR_EL1_ARCH_SHIFT 16
1401 #define MIDR_EL1_ARCH_MASK (0xf << MIDR_EL1_ARCH_SHIFT)
1402 #define MIDR_EL1_VAR_SHIFT 20
1403 #define MIDR_EL1_VAR_MASK (0xf << MIDR_EL1_VAR_SHIFT)
1404 #define MIDR_EL1_IMP_SHIFT 24
1405 #define MIDR_EL1_IMP_MASK (0xff << MIDR_EL1_IMP_SHIFT)
1406
1407 /*
1408 * CoreSight debug registers
1409 */
1410 #define CORESIGHT_ED 0
1411 #define CORESIGHT_CTI 1
1412 #define CORESIGHT_PMU 2
1413 #define CORESIGHT_UTT 3 /* Not truly a coresight thing, but at a fixed convenient location right after the coresight region */
1414
1415 #define CORESIGHT_OFFSET(x) ((x) * 0x10000)
1416 #define CORESIGHT_REGIONS 4
1417 #define CORESIGHT_SIZE 0x1000
1418
1419
1420 /*
1421 * ID_AA64ISAR0_EL1 - AArch64 Instruction Set Attribute Register 0
1422 *
1423 * 63 24 23 20 19 16 15 12 11 8 7 4 3 0
1424 * +----------+--------+------+------+------+-----+------+
1425 * | reserved | atomic |crc32 | sha2 | sha1 | aes | res0 |
1426 * +----------+--------+------+------+------+-----+------+
1427 */
1428
1429 #define ID_AA64ISAR0_EL1_ATOMIC_OFFSET 20
1430 #define ID_AA64ISAR0_EL1_ATOMIC_MASK (0xfull << ID_AA64ISAR0_EL1_ATOMIC_OFFSET)
1431 #define ID_AA64ISAR0_EL1_ATOMIC_8_1 (2ull << ID_AA64ISAR0_EL1_ATOMIC_OFFSET)
1432
1433 #define ID_AA64ISAR0_EL1_CRC32_OFFSET 16
1434 #define ID_AA64ISAR0_EL1_CRC32_MASK (0xfull << ID_AA64ISAR0_EL1_CRC32_OFFSET)
1435 #define ID_AA64ISAR0_EL1_CRC32_EN (1ull << ID_AA64ISAR0_EL1_CRC32_OFFSET)
1436
1437 #define ID_AA64ISAR0_EL1_SHA2_OFFSET 12
1438 #define ID_AA64ISAR0_EL1_SHA2_MASK (0xfull << ID_AA64ISAR0_EL1_SHA2_OFFSET)
1439 #define ID_AA64ISAR0_EL1_SHA2_EN (1ull << ID_AA64ISAR0_EL1_SHA2_OFFSET)
1440
1441 #define ID_AA64ISAR0_EL1_SHA1_OFFSET 8
1442 #define ID_AA64ISAR0_EL1_SHA1_MASK (0xfull << ID_AA64ISAR0_EL1_SHA1_OFFSET)
1443 #define ID_AA64ISAR0_EL1_SHA1_EN (1ull << ID_AA64ISAR0_EL1_SHA1_OFFSET)
1444
1445 #define ID_AA64ISAR0_EL1_AES_OFFSET 4
1446 #define ID_AA64ISAR0_EL1_AES_MASK (0xfull << ID_AA64ISAR0_EL1_AES_OFFSET)
1447 #define ID_AA64ISAR0_EL1_AES_EN (1ull << ID_AA64ISAR0_EL1_AES_OFFSET)
1448 #define ID_AA64ISAR0_EL1_AES_PMULL_EN (2ull << ID_AA64ISAR0_EL1_AES_OFFSET)
1449
1450
1451
1452 #ifdef __ASSEMBLER__
1453
1454 /*
1455 * Compute CPU version:
1456 * Version is constructed as [4 bits of MIDR variant]:[4 bits of MIDR revision]
1457 *
1458 * Where the "variant" is the major number and the "revision" is the minor number.
1459 *
1460 * For example:
1461 * Cyclone A0 is variant 0, revision 0, i.e. 0.
1462 * Cyclone B0 is variant 1, revision 0, i.e. 0x10
1463 * $0 - register to place value in
1464 */
1465 .macro GET_MIDR_CPU_VERSION
1466 mrs $0, MIDR_EL1 // Read MIDR_EL1 for CPUID
1467 bfi $0, $0, #(MIDR_EL1_VAR_SHIFT - 4), #4 // move bits 3:0 (revision) to 19:16 (below variant) to get values adjacent
1468 ubfx $0, $0, #(MIDR_EL1_VAR_SHIFT - 4), #8 // And extract the concatenated bitstring to beginning of register
1469 .endmacro
1470
1471 /*
1472 * To apply a workaround for CPU versions less than a given value
1473 * (e.g. earlier than when a fix arrived)
1474 *
1475 * $0 - scratch register1
1476 * $1 - version at which to stop applying workaround
1477 * $2 - label to branch to (at end of workaround)
1478 */
1479 .macro SKIP_IF_CPU_VERSION_GREATER_OR_EQUAL
1480 GET_MIDR_CPU_VERSION $0
1481 cmp $0, $1
1482 b.pl $2 // Unsigned "greater or equal"
1483 .endmacro
1484
1485 /*
1486 * To apply a workaround for CPU versions greater than a given value
1487 * (e.g. starting when a bug was introduced)
1488 *
1489 * $0 - scratch register1
1490 * $1 - version at which to stop applying workaround
1491 * $2 - label to branch to (at end of workaround)
1492 */
1493 .macro SKIP_IF_CPU_VERSION_LESS_THAN
1494 GET_MIDR_CPU_VERSION $0
1495 cmp $0, $1
1496 b.mi $2 // Unsigned "strictly less than"
1497 .endmacro
1498
1499 #endif /* __ASSEMBLER__ */
1500
1501 #define MSR(reg,src) __asm__ volatile ("msr " reg ", %0" :: "r" (src))
1502 #define MRS(dest,reg) __asm__ volatile ("mrs %0, " reg : "=r" (dest))
1503
1504
1505 #endif /* _ARM64_PROC_REG_H_ */