xref: /xnu-11417.121.6/pexpert/pexpert/arm64/apple_arm64_regs.h (revision a1e26a70f38d1d7daa7b49b258e2f8538ad81650)
1 /*
2  * Copyright (c) 2012-2015 Apple Inc. All rights reserved.
3  */
4 
5 #ifndef _PEXPERT_ARM64_COMMON_H
6 #define _PEXPERT_ARM64_COMMON_H
7 
8 /* This block of definitions is misplaced to shelter it from lines that will be
9  * removed in rdar://56937184. These definitions must be moved back after that
10  * change has been merged. */
11 #ifdef APPLE_ARM64_ARCH_FAMILY
12 #endif
13 
14 #ifdef ASSEMBLER
15 #define __MSR_STR(x) x
16 #else
17 #define __MSR_STR1(x) #x
18 #define __MSR_STR(x) __MSR_STR1(x)
19 #endif
20 
21 #ifdef APPLE_ARM64_ARCH_FAMILY
22 
23 
24 
25 #if defined(APPLETYPHOON) || defined(APPLETWISTER)
26 #define ARM64_REG_CYC_CFG_skipInit     (1ULL<<30)
27 #define ARM64_REG_CYC_CFG_deepSleep    (1ULL<<24)
28 #else /* defined(APPLECYCLONE) || defined(APPLETYPHOON) || defined(APPLETWISTER) */
29 #define ARM64_REG_ACC_OVRD_enDeepSleep                 (1ULL << 34)
30 #define ARM64_REG_ACC_OVRD_disPioOnWfiCpu              (1ULL << 32)
31 #define ARM64_REG_ACC_OVRD_dsblClkDtr                  (1ULL << 29)
32 #define ARM64_REG_ACC_OVRD_cpmWakeUp_mask              (3ULL << 27)
33 #define ARM64_REG_ACC_OVRD_cpmWakeUp_force             (3ULL << 27)
34 #define ARM64_REG_ACC_OVRD_ok2PwrDnCPM_mask            (3ULL << 25)
35 #define ARM64_REG_ACC_OVRD_ok2PwrDnCPM_deny            (2ULL << 25)
36 #define ARM64_REG_ACC_OVRD_ok2PwrDnCPM_deepsleep       (3ULL << 25)
37 #define ARM64_REG_ACC_OVRD_ok2TrDnLnk_mask             (3ULL << 17)
38 #define ARM64_REG_ACC_OVRD_ok2TrDnLnk_deepsleep        (3ULL << 17)
39 #define ARM64_REG_ACC_OVRD_disL2Flush4AccSlp_mask      (3ULL << 15)
40 #define ARM64_REG_ACC_OVRD_disL2Flush4AccSlp_deepsleep (2ULL << 15)
41 #define ARM64_REG_ACC_OVRD_ok2PwrDnSRM_mask            (3ULL << 13)
42 #define ARM64_REG_ACC_OVRD_ok2PwrDnSRM_deepsleep       (3ULL << 13)
43 #endif /* defined(APPLECYCLONE) || defined(APPLETYPHOON) || defined(APPLETWISTER) */
44 
45 #define ARM64_REG_CYC_OVRD_irq_mask            (3<<22)
46 #define ARM64_REG_CYC_OVRD_irq_disable         (2<<22)
47 #define ARM64_REG_CYC_OVRD_fiq_mask            (3<<20)
48 #define ARM64_REG_CYC_OVRD_fiq_disable         (2<<20)
49 #define ARM64_REG_CYC_OVRD_ok2pwrdn_force_up   (2<<24)
50 #define ARM64_REG_CYC_OVRD_ok2pwrdn_force_down (3<<24)
51 #define ARM64_REG_CYC_OVRD_disWfiRetn          (1<<0)
52 
53 #if defined(APPLEMONSOON)
54 #define ARM64_REG_CYC_OVRD_dsblSnoopTime_mask  (3ULL << 30)
55 #define ARM64_REG_CYC_OVRD_dsblSnoopPTime      (1ULL << 31)  /// Don't fetch the timebase from the P-block
56 #endif /* APPLEMONSOON */
57 
58 #define ARM64_REG_LSU_ERR_STS_L1DTlbMultiHitEN (1ULL<<54)
59 #define ARM64_REG_LSU_ERR_CTL_L1DTlbMultiHitEN (1ULL<<3)
60 
61 
62 
63 #if defined(HAS_IPI)
64 #define ARM64_REG_IPI_RR_TYPE_IMMEDIATE (0 << 28)
65 #define ARM64_REG_IPI_RR_TYPE_RETRACT   (1 << 28)
66 #define ARM64_REG_IPI_RR_TYPE_DEFERRED  (2 << 28)
67 #define ARM64_REG_IPI_RR_TYPE_NOWAKE    (3 << 28)
68 
69 #define ARM64_IPISR_IPI_PENDING         (1ull << 0)
70 #endif /* defined(HAS_IPI) */
71 
72 #if defined(HAS_OBJC_BP_HELPER)
73 #define ARM64_REG_BP_OBJC_ADR_EL1_mask                 (0x00ffffffffffffffull)
74 #define ARM64_REG_BP_OBJC_ADR_EL1_shift                (0)
75 
76 #define ARM64_REG_BP_OBJC_CTL_EL1_Mask_mask            (0x001ffffff8000000ull)
77 #define ARM64_REG_BP_OBJC_CTL_EL1_Mask_shift           (27)
78 
79 #define ARM64_REG_BP_OBJC_CTL_EL1_AR_ClassPtr_mask     (0x00000000003e0000ull)
80 #define ARM64_REG_BP_OBJC_CTL_EL1_AR_ClassPtr_shift    (17)
81 
82 #define ARM64_REG_BP_OBJC_CTL_EL1_AR_Selector_mask     (0x000000000001f000ull)
83 #define ARM64_REG_BP_OBJC_CTL_EL1_AR_Selector_shift    (12)
84 
85 #define ARM64_REG_BP_OBJC_CTL_EL1_Br_Offset_mask       (0x000000000000007full)
86 #define ARM64_REG_BP_OBJC_CTL_EL1_Br_Offset_shift      (0)
87 #endif /* defined(HAS_OBJC_BP_HELPER) */
88 
89 
90 #endif /* APPLE_ARM64_ARCH_FAMILY */
91 
92 
93 #if defined(HAS_BP_RET)
94 #define ARM64_REG_ACC_CFG_bdpSlpEn    (1ULL << 2)
95 #define ARM64_REG_ACC_CFG_btpSlpEn    (1ULL << 3)
96 #define ARM64_REG_ACC_CFG_bpSlp_mask  3
97 #define ARM64_REG_ACC_CFG_bpSlp_shift 2
98 #endif /* defined(HAS_BP_RET) */
99 
100 
101 
102 #define MPIDR_CORETYPE_SHIFT  (16)
103 #define MPIDR_CORETYPE_WIDTH  (3)
104 #define MPIDR_CORETYPE_MASK   ((1ULL << MPIDR_CORETYPE_WIDTH) - 1)
105 #define MPIDR_CORETYPE_ACC_E  (0ULL)
106 #define MPIDR_CORETYPE_ACC_P  (1ULL)
107 
108 
109 
110 #define CPU_PIO_CPU_STS_OFFSET               (0x100ULL)
111 #define CPU_PIO_CPU_STS_cpuRunSt_mask        (0xff)
112 
113 /*
114  * CORE_THRTL_CFG2 non-sysreg tunable
115  */
116 #define CORE_THRTL_CFG2_OFFSET               (0x218)
117 
118 #define CORE_THRTL_CFG2_c1pptThrtlRate_shift (56)
119 #define CORE_THRTL_CFG2_c1pptThrtlRate_mask  (0xFFULL << CORE_THRTL_CFG2_c1pptThrtlRate_shift)
120 
121 
122 
123 
124 #if defined(APPLEH16)
125 /*
126  * EACC/PACC cpmX_IMPL register offset
127  */
128 #define LLC_ERR_INF_OFFSET (0x18ULL)
129 #define LLC_ERR_INF_NREC   (1ULL << 36)
130 #endif /* defined(APPLEH16) */
131 
132 #ifdef ASSEMBLER
133 
134 /*
135  * Determines whether the executing core is a P-core.
136  *
137  * @param arg0 result register; will be non-zero if executed on a P-core, else
138  *             zero if executed on an E-core / non-PE core / non-AMP architectures.
139  */
140 .macro ARM64_IS_PCORE
141 #if defined(APPLEMONSOON) || HAS_CLUSTER
142 	mrs   $0, MPIDR_EL1
143 	ubfx  $0, $0, #MPIDR_CORETYPE_SHIFT, #MPIDR_CORETYPE_WIDTH
144 	and   $0, $0, #MPIDR_CORETYPE_ACC_P
145 #else
146 	mov   $0, xzr
147 #endif
148 .endmacro
149 
150 
151 /*
152  * Determines whether the executing core is an E-core.
153  *
154  * @note Clobbers condition flags.
155  *
156  * @param arg0 result register; will be non-zero if executed on an E-core, else
157  *             zero if executed on a P-core / non-PE core / non-AMP architectures.
158  */
159 .macro ARM64_IS_ECORE
160 #if defined(APPLEMONSOON) || HAS_CLUSTER
161 	mrs    $0, MPIDR_EL1
162 	ands   $0, $0, #(MPIDR_CORETYPE_MASK << MPIDR_CORETYPE_SHIFT)
163 	csinc  $0, xzr, xzr, ne
164 #else
165 	mov    $0, xzr
166 #endif
167 .endmacro
168 
169 /*
170  * Reads a system register using the appropriate name for E-cores, P-cores and
171  * non-PE cores.
172  *
173  * @note See also: ARM64_IS_ECORE
174  *
175  * @param arg0 GPR indicating the core type; non-zero if this is an E-core, else zero
176  * @param arg1 destination GPR
177  * @param arg2 system register name to use for E-cores
178  * @param arg3 system register name to use for P-cores, non-PE cores or
179  *             non-AMP architectures.
180  */
181 .macro ARM64_READ_CORE_SYSREG
182 #if defined(APPLEMONSOON) || HAS_CLUSTER
183 	cbz  $0, 1f
184 // E-core
185 	mrs  $1, $2
186 	b    2f
187 // non-PE core / P-core / non-AMP architecture
188 1:
189 #endif /* defined(APPLEMONSOON) || HAS_CLUSTER */
190 	mrs  $1, $3
191 2:
192 .endmacro
193 
194 /*
195  * Writes a system register using the appropriate name for E-cores, P-cores and
196  * non-PE cores.
197  *
198  * @note See also: ARM64_IS_ECORE
199  *
200  * @param arg0 GPR indicating the core type; non-zero if this is an E-core, else zero
201  * @param arg1 source GPR
202  * @param arg2 system register name to use for E-cores
203  * @param arg3 system register name to use for P-cores, non-PE cores or
204  *             non-AMP architectures.
205  */
206 .macro ARM64_WRITE_CORE_SYSREG
207 #if defined(APPLEMONSOON) || HAS_CLUSTER
208 	cbz  $0, 1f
209 // E-core
210 	msr  $2, $1
211 	b    2f
212 // non-PE core / P-core / non-AMP architecture
213 1:
214 #endif /* defined(APPLEMONSOON) || HAS_CLUSTER */
215 	msr  $3, $1
216 2:
217 .endmacro
218 
219 #endif /* ASSEMBLER */
220 
221 #endif /* ! _PEXPERT_ARM_ARM64_H */
222