xref: /rk3399_ARM-atf/lib/cpus/aarch64/cortex_x2.S (revision 41b969764a866587c1403db0971877aa267fd783)
1/*
2 * Copyright (c) 2021-2025, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <arch.h>
8#include <asm_macros.S>
9#include <common/bl_common.h>
10#include <cortex_x2.h>
11#include <cpu_macros.S>
12#include <dsu_macros.S>
13#include <plat_macros.S>
14#include "wa_cve_2022_23960_bhb_vector.S"
15
16/* Hardware handled coherency */
17#if HW_ASSISTED_COHERENCY == 0
18#error "Cortex X2 must be compiled with HW_ASSISTED_COHERENCY enabled"
19#endif
20
21/* 64-bit only core */
22#if CTX_INCLUDE_AARCH32_REGS == 1
23#error "Cortex X2 supports only AArch64. Compile with CTX_INCLUDE_AARCH32_REGS=0"
24#endif
25
26.global check_erratum_cortex_x2_3701772
27
28#if WORKAROUND_CVE_2022_23960
29	wa_cve_2022_23960_bhb_vector_table CORTEX_X2_BHB_LOOP_COUNT, cortex_x2
30#endif /* WORKAROUND_CVE_2022_23960 */
31
32cpu_reset_prologue cortex_x2
33
34workaround_reset_start cortex_x2, ERRATUM(1901946), ERRATA_X2_1901946
35	sysreg_bit_set CORTEX_X2_CPUACTLR4_EL1, BIT(15)
36workaround_reset_end cortex_x2, ERRATUM(1901946)
37
38check_erratum_range cortex_x2, ERRATUM(1901946), CPU_REV(1, 0), CPU_REV(1, 0)
39
40workaround_reset_start cortex_x2, ERRATUM(1916945), ERRATA_X2_1916945
41	sysreg_bit_set CORTEX_X2_CPUECTLR_EL1, BIT(8)
42workaround_reset_end cortex_x2, ERRATUM(1916945)
43
44check_erratum_ls cortex_x2, ERRATUM(1916945), CPU_REV(1, 0)
45
46workaround_reset_start cortex_x2, ERRATUM(1917258), ERRATA_X2_1917258
47	sysreg_bit_set CORTEX_X2_CPUACTLR4_EL1, BIT(43)
48workaround_reset_end cortex_x2, ERRATUM(1917258)
49
50check_erratum_ls cortex_x2, ERRATUM(1917258), CPU_REV(1, 0)
51
52workaround_reset_start cortex_x2, ERRATUM(1927200), ERRATA_X2_1927200
53	mov	x0, #0
54	msr	S3_6_C15_C8_0, x0 /* CPUPSELR_EL3 */
55	ldr	x0, =0x10E3900002
56	msr	S3_6_C15_C8_2, x0 /* CPUPOR_EL3 */
57	ldr	x0, =0x10FFF00083
58	msr	S3_6_C15_C8_3, x0 /* CPUPMR_EL3 */
59	ldr	x0, =0x2001003FF
60	msr	S3_6_C15_C8_1, x0 /* CPUPCR_EL3 */
61
62	mov	x0, #1
63	msr	S3_6_C15_C8_0, x0 /* CPUPSELR_EL3 */
64	ldr	x0, =0x10E3800082
65	msr	S3_6_C15_C8_2, x0 /* CPUPOR_EL3 */
66	ldr	x0, =0x10FFF00083
67	msr	S3_6_C15_C8_3, x0 /* CPUPMR_EL3 */
68	ldr	x0, =0x2001003FF
69	msr	S3_6_C15_C8_1, x0 /* CPUPCR_EL3 */
70
71	mov	x0, #2
72	msr	S3_6_C15_C8_0, x0 /* CPUPSELR_EL3 */
73	ldr	x0, =0x10E3800200
74	msr	S3_6_C15_C8_2, x0 /* CPUPOR_EL3 */
75	ldr	x0, =0x10FFF003E0
76	msr	S3_6_C15_C8_3, x0 /* CPUPMR_EL3 */
77	ldr	x0, =0x2001003FF
78	msr	S3_6_C15_C8_1, x0 /* CPUPCR_EL3 */
79workaround_reset_end cortex_x2, ERRATUM(1927200)
80
81check_erratum_ls cortex_x2, ERRATUM(1927200), CPU_REV(1, 0)
82
83workaround_reset_start cortex_x2, ERRATUM(1934260), ERRATA_X2_1934260
84	sysreg_bit_set CORTEX_X2_CPUECTLR_EL1, CORTEX_X2_CPUECTLR_EL1_WS_THR_DISABLE_ALL_BITS
85workaround_reset_end cortex_x2, ERRATUM(1934260)
86
87check_erratum_range cortex_x2, ERRATUM(1934260), CPU_REV(1, 0), CPU_REV(1, 0)
88
89workaround_reset_start cortex_x2, ERRATUM(2002765), ERRATA_X2_2002765
90	ldr	x0, =0x6
91	msr	S3_6_C15_C8_0, x0 /* CPUPSELR_EL3 */
92	ldr	x0, =0xF3A08002
93	msr	S3_6_C15_C8_2, x0 /* CPUPOR_EL3 */
94	ldr	x0, =0xFFF0F7FE
95	msr	S3_6_C15_C8_3, x0 /* CPUPMR_EL3 */
96	ldr	x0, =0x40000001003ff
97	msr	S3_6_C15_C8_1, x0 /* CPUPCR_EL3 */
98workaround_reset_end cortex_x2, ERRATUM(2002765)
99
100check_erratum_ls cortex_x2, ERRATUM(2002765), CPU_REV(2, 0)
101
102workaround_reset_start cortex_x2, ERRATUM(2017096), ERRATA_X2_2017096
103	sysreg_bit_set CORTEX_X2_CPUECTLR_EL1, CORTEX_X2_CPUECTLR_EL1_PFSTIDIS_BIT
104workaround_reset_end cortex_x2, ERRATUM(2017096)
105
106check_erratum_ls cortex_x2, ERRATUM(2017096), CPU_REV(2, 0)
107
108workaround_reset_start cortex_x2, ERRATUM(2081180), ERRATA_X2_2081180
109	/* Apply instruction patching sequence */
110	ldr	x0, =0x3
111	msr	CORTEX_X2_IMP_CPUPSELR_EL3, x0
112	ldr	x0, =0xF3A08002
113	msr	CORTEX_X2_IMP_CPUPOR_EL3, x0
114	ldr	x0, =0xFFF0F7FE
115	msr	CORTEX_X2_IMP_CPUPMR_EL3, x0
116	ldr	x0, =0x10002001003FF
117	msr	CORTEX_X2_IMP_CPUPCR_EL3, x0
118	ldr	x0, =0x4
119	msr	CORTEX_X2_IMP_CPUPSELR_EL3, x0
120	ldr	x0, =0xBF200000
121	msr	CORTEX_X2_IMP_CPUPOR_EL3, x0
122	ldr	x0, =0xFFEF0000
123	msr	CORTEX_X2_IMP_CPUPMR_EL3, x0
124	ldr	x0, =0x10002001003F3
125	msr	CORTEX_X2_IMP_CPUPCR_EL3, x0
126workaround_reset_end cortex_x2, ERRATUM(2081180)
127
128check_erratum_ls cortex_x2, ERRATUM(2081180), CPU_REV(2, 0)
129
130workaround_reset_start cortex_x2, ERRATUM(2083908), ERRATA_X2_2083908
131	/* Apply the workaround by setting bit 13 in CPUACTLR5_EL1. */
132	sysreg_bit_set CORTEX_X2_CPUACTLR5_EL1, BIT(13)
133workaround_reset_end cortex_x2, ERRATUM(2083908)
134
135check_erratum_range cortex_x2, ERRATUM(2083908), CPU_REV(2, 0), CPU_REV(2, 0)
136
137workaround_reset_start cortex_x2, ERRATUM(2136059), ERRATA_X2_2136059
138	sysreg_bit_set CORTEX_X2_CPUACTLR5_EL1, BIT(44)
139workaround_reset_end cortex_x2, ERRATUM(2136059)
140
141check_erratum_ls cortex_x2, ERRATUM(2136059), CPU_REV(2, 0)
142
143workaround_reset_start cortex_x2, ERRATUM(2147715), ERRATA_X2_2147715
144	/* Apply the workaround by setting bit 22 in CPUACTLR_EL1. */
145	sysreg_bit_set CORTEX_X2_CPUACTLR_EL1, CORTEX_X2_CPUACTLR_EL1_BIT_22
146workaround_reset_end cortex_x2, ERRATUM(2147715)
147
148check_erratum_range cortex_x2, ERRATUM(2147715), CPU_REV(2, 0), CPU_REV(2, 0)
149
150workaround_reset_start cortex_x2, ERRATUM(2216384), ERRATA_X2_2216384
151	sysreg_bit_set CORTEX_X2_CPUACTLR5_EL1, CORTEX_X2_CPUACTLR5_EL1_BIT_17
152
153	/* Apply instruction patching sequence */
154	ldr	x0, =0x5
155	msr	CORTEX_X2_IMP_CPUPSELR_EL3, x0
156	ldr	x0, =0x10F600E000
157	msr	CORTEX_X2_IMP_CPUPOR_EL3, x0
158	ldr	x0, =0x10FF80E000
159	msr	CORTEX_X2_IMP_CPUPMR_EL3, x0
160	ldr	x0, =0x80000000003FF
161	msr	CORTEX_X2_IMP_CPUPCR_EL3, x0
162workaround_reset_end cortex_x2, ERRATUM(2216384)
163
164check_erratum_ls cortex_x2, ERRATUM(2216384), CPU_REV(2, 0)
165
166workaround_reset_start cortex_x2, ERRATUM(2267065), ERRATA_X2_2267065
167	sysreg_bit_set CORTEX_X2_CPUACTLR_EL1, BIT(22)
168workaround_reset_end cortex_x2, ERRATUM(2267065)
169
170check_erratum_ls cortex_x2, ERRATUM(2267065), CPU_REV(2, 0)
171
172workaround_reset_start cortex_x2, ERRATUM(2282622), ERRATA_X2_2282622
173	/* Apply the workaround */
174	sysreg_bit_set CORTEX_X2_CPUACTLR2_EL1, BIT(0)
175workaround_reset_end cortex_x2, ERRATUM(2282622)
176
177check_erratum_ls cortex_x2, ERRATUM(2282622), CPU_REV(2, 1)
178
179workaround_reset_start cortex_x2, ERRATUM(2313941), ERRATA_DSU_2313941
180	errata_dsu_2313941_wa_impl
181workaround_reset_end cortex_x2, ERRATUM(2313941)
182
183check_erratum_custom_start cortex_x2, ERRATUM(2313941)
184	check_errata_dsu_2313941_impl
185	ret
186check_erratum_custom_end cortex_x2, ERRATUM(2313941)
187
188workaround_reset_start cortex_x2, ERRATUM(2371105), ERRATA_X2_2371105
189	/* Set bit 40 in CPUACTLR2_EL1 */
190	sysreg_bit_set CORTEX_X2_CPUACTLR2_EL1, CORTEX_X2_CPUACTLR2_EL1_BIT_40
191workaround_reset_end cortex_x2, ERRATUM(2371105)
192
193check_erratum_ls cortex_x2, ERRATUM(2371105), CPU_REV(2, 0)
194
195workaround_reset_start cortex_x2, ERRATUM(2742423), ERRATA_X2_2742423
196	/* Set CPUACTLR5_EL1[56:55] to 2'b01 */
197	sysreg_bit_set CORTEX_X2_CPUACTLR5_EL1, BIT(55)
198	sysreg_bit_clear CORTEX_X2_CPUACTLR5_EL1, BIT(56)
199workaround_reset_end cortex_x2, ERRATUM(2742423)
200
201check_erratum_ls cortex_x2, ERRATUM(2742423), CPU_REV(2, 1)
202
203workaround_runtime_start cortex_x2, ERRATUM(2768515), ERRATA_X2_2768515
204	/* dsb before isb of power down sequence */
205	dsb	sy
206workaround_runtime_end cortex_x2, ERRATUM(2768515)
207
208check_erratum_ls cortex_x2, ERRATUM(2768515), CPU_REV(2, 1)
209
210workaround_reset_start cortex_x2, ERRATUM(2778471), ERRATA_X2_2778471
211	sysreg_bit_set CORTEX_X2_CPUACTLR3_EL1, BIT(47)
212workaround_reset_end cortex_x2, ERRATUM(2778471)
213
214check_erratum_ls cortex_x2, ERRATUM(2778471), CPU_REV(2, 1)
215
216add_erratum_entry cortex_x2, ERRATUM(3701772), ERRATA_X2_3701772
217
218check_erratum_ls cortex_x2, ERRATUM(3701772), CPU_REV(2, 1)
219
220workaround_reset_start cortex_x2, CVE(2022, 23960), WORKAROUND_CVE_2022_23960
221#if IMAGE_BL31
222	/*
223	 * The Cortex-X2 generic vectors are overridden to apply errata
224	 * mitigation on exception entry from lower ELs.
225	 */
226	override_vector_table wa_cve_vbar_cortex_x2
227#endif /* IMAGE_BL31 */
228workaround_reset_end cortex_x2, CVE(2022, 23960)
229
230check_erratum_chosen cortex_x2, CVE(2022, 23960), WORKAROUND_CVE_2022_23960
231
232/* Disable hardware page aggregation. Enables mitigation for `CVE-2024-5660` */
233workaround_reset_start cortex_x2, CVE(2024, 5660), WORKAROUND_CVE_2024_5660
234	sysreg_bit_set CORTEX_X2_CPUECTLR_EL1, BIT(46)
235workaround_reset_end cortex_x2, CVE(2024, 5660)
236
237check_erratum_ls cortex_x2, CVE(2024, 5660), CPU_REV(2, 1)
238
239	/* ----------------------------------------------------
240	 * HW will do the cache maintenance while powering down
241	 * ----------------------------------------------------
242	 */
243func cortex_x2_core_pwr_dwn
244	/* ---------------------------------------------------
245	 * Enable CPU power down bit in power control register
246	 * ---------------------------------------------------
247	 */
248	sysreg_bit_set CORTEX_X2_CPUPWRCTLR_EL1, CORTEX_X2_CPUPWRCTLR_EL1_CORE_PWRDN_BIT
249
250	apply_erratum cortex_x2, ERRATUM(2768515), ERRATA_X2_2768515
251	isb
252	ret
253endfunc cortex_x2_core_pwr_dwn
254
255cpu_reset_func_start cortex_x2
256	/* Disable speculative loads */
257	msr	SSBS, xzr
258	enable_mpmm
259cpu_reset_func_end cortex_x2
260
261	/* ---------------------------------------------
262	 * This function provides Cortex X2 specific
263	 * register information for crash reporting.
264	 * It needs to return with x6 pointing to
265	 * a list of register names in ascii and
266	 * x8 - x15 having values of registers to be
267	 * reported.
268	 * ---------------------------------------------
269	 */
270.section .rodata.cortex_x2_regs, "aS"
271cortex_x2_regs:  /* The ascii list of register names to be reported */
272	.asciz	"cpuectlr_el1", ""
273
274func cortex_x2_cpu_reg_dump
275	adr	x6, cortex_x2_regs
276	mrs	x8, CORTEX_X2_CPUECTLR_EL1
277	ret
278endfunc cortex_x2_cpu_reg_dump
279
280declare_cpu_ops cortex_x2, CORTEX_X2_MIDR, \
281	cortex_x2_reset_func, \
282	cortex_x2_core_pwr_dwn
283