xref: /rk3399_ARM-atf/lib/cpus/aarch64/cortex_x2.S (revision e236548455cc3f8e28cdd2daa3cffc6fae6ea73c)
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(2002765), ERRATA_X2_2002765
84	ldr	x0, =0x6
85	msr	S3_6_C15_C8_0, x0 /* CPUPSELR_EL3 */
86	ldr	x0, =0xF3A08002
87	msr	S3_6_C15_C8_2, x0 /* CPUPOR_EL3 */
88	ldr	x0, =0xFFF0F7FE
89	msr	S3_6_C15_C8_3, x0 /* CPUPMR_EL3 */
90	ldr	x0, =0x40000001003ff
91	msr	S3_6_C15_C8_1, x0 /* CPUPCR_EL3 */
92workaround_reset_end cortex_x2, ERRATUM(2002765)
93
94check_erratum_ls cortex_x2, ERRATUM(2002765), CPU_REV(2, 0)
95
96workaround_reset_start cortex_x2, ERRATUM(2017096), ERRATA_X2_2017096
97	sysreg_bit_set CORTEX_X2_CPUECTLR_EL1, CORTEX_X2_CPUECTLR_EL1_PFSTIDIS_BIT
98workaround_reset_end cortex_x2, ERRATUM(2017096)
99
100check_erratum_ls cortex_x2, ERRATUM(2017096), CPU_REV(2, 0)
101
102workaround_reset_start cortex_x2, ERRATUM(2081180), ERRATA_X2_2081180
103	/* Apply instruction patching sequence */
104	ldr	x0, =0x3
105	msr	CORTEX_X2_IMP_CPUPSELR_EL3, x0
106	ldr	x0, =0xF3A08002
107	msr	CORTEX_X2_IMP_CPUPOR_EL3, x0
108	ldr	x0, =0xFFF0F7FE
109	msr	CORTEX_X2_IMP_CPUPMR_EL3, x0
110	ldr	x0, =0x10002001003FF
111	msr	CORTEX_X2_IMP_CPUPCR_EL3, x0
112	ldr	x0, =0x4
113	msr	CORTEX_X2_IMP_CPUPSELR_EL3, x0
114	ldr	x0, =0xBF200000
115	msr	CORTEX_X2_IMP_CPUPOR_EL3, x0
116	ldr	x0, =0xFFEF0000
117	msr	CORTEX_X2_IMP_CPUPMR_EL3, x0
118	ldr	x0, =0x10002001003F3
119	msr	CORTEX_X2_IMP_CPUPCR_EL3, x0
120workaround_reset_end cortex_x2, ERRATUM(2081180)
121
122check_erratum_ls cortex_x2, ERRATUM(2081180), CPU_REV(2, 0)
123
124workaround_reset_start cortex_x2, ERRATUM(2083908), ERRATA_X2_2083908
125	/* Apply the workaround by setting bit 13 in CPUACTLR5_EL1. */
126	sysreg_bit_set CORTEX_X2_CPUACTLR5_EL1, BIT(13)
127workaround_reset_end cortex_x2, ERRATUM(2083908)
128
129check_erratum_range cortex_x2, ERRATUM(2083908), CPU_REV(2, 0), CPU_REV(2, 0)
130
131workaround_reset_start cortex_x2, ERRATUM(2147715), ERRATA_X2_2147715
132	/* Apply the workaround by setting bit 22 in CPUACTLR_EL1. */
133	sysreg_bit_set CORTEX_X2_CPUACTLR_EL1, CORTEX_X2_CPUACTLR_EL1_BIT_22
134workaround_reset_end cortex_x2, ERRATUM(2147715)
135
136check_erratum_range cortex_x2, ERRATUM(2147715), CPU_REV(2, 0), CPU_REV(2, 0)
137
138workaround_reset_start cortex_x2, ERRATUM(2216384), ERRATA_X2_2216384
139	sysreg_bit_set CORTEX_X2_CPUACTLR5_EL1, CORTEX_X2_CPUACTLR5_EL1_BIT_17
140
141	/* Apply instruction patching sequence */
142	ldr	x0, =0x5
143	msr	CORTEX_X2_IMP_CPUPSELR_EL3, x0
144	ldr	x0, =0x10F600E000
145	msr	CORTEX_X2_IMP_CPUPOR_EL3, x0
146	ldr	x0, =0x10FF80E000
147	msr	CORTEX_X2_IMP_CPUPMR_EL3, x0
148	ldr	x0, =0x80000000003FF
149	msr	CORTEX_X2_IMP_CPUPCR_EL3, x0
150workaround_reset_end cortex_x2, ERRATUM(2216384)
151
152check_erratum_ls cortex_x2, ERRATUM(2216384), CPU_REV(2, 0)
153
154workaround_reset_start cortex_x2, ERRATUM(2282622), ERRATA_X2_2282622
155	/* Apply the workaround */
156	sysreg_bit_set CORTEX_X2_CPUACTLR2_EL1, BIT(0)
157workaround_reset_end cortex_x2, ERRATUM(2282622)
158
159check_erratum_ls cortex_x2, ERRATUM(2282622), CPU_REV(2, 1)
160
161workaround_reset_start cortex_x2, ERRATUM(2313941), ERRATA_DSU_2313941
162	errata_dsu_2313941_wa_impl
163workaround_reset_end cortex_x2, ERRATUM(2313941)
164
165check_erratum_custom_start cortex_x2, ERRATUM(2313941)
166	check_errata_dsu_2313941_impl
167	ret
168check_erratum_custom_end cortex_x2, ERRATUM(2313941)
169
170workaround_reset_start cortex_x2, ERRATUM(2371105), ERRATA_X2_2371105
171	/* Set bit 40 in CPUACTLR2_EL1 */
172	sysreg_bit_set CORTEX_X2_CPUACTLR2_EL1, CORTEX_X2_CPUACTLR2_EL1_BIT_40
173workaround_reset_end cortex_x2, ERRATUM(2371105)
174
175check_erratum_ls cortex_x2, ERRATUM(2371105), CPU_REV(2, 0)
176
177workaround_reset_start cortex_x2, ERRATUM(2742423), ERRATA_X2_2742423
178	/* Set CPUACTLR5_EL1[56:55] to 2'b01 */
179	sysreg_bit_set CORTEX_X2_CPUACTLR5_EL1, BIT(55)
180	sysreg_bit_clear CORTEX_X2_CPUACTLR5_EL1, BIT(56)
181workaround_reset_end cortex_x2, ERRATUM(2742423)
182
183check_erratum_ls cortex_x2, ERRATUM(2742423), CPU_REV(2, 1)
184
185workaround_runtime_start cortex_x2, ERRATUM(2768515), ERRATA_X2_2768515
186	/* dsb before isb of power down sequence */
187	dsb	sy
188workaround_runtime_end cortex_x2, ERRATUM(2768515)
189
190check_erratum_ls cortex_x2, ERRATUM(2768515), CPU_REV(2, 1)
191
192workaround_reset_start cortex_x2, ERRATUM(2778471), ERRATA_X2_2778471
193	sysreg_bit_set CORTEX_X2_CPUACTLR3_EL1, BIT(47)
194workaround_reset_end cortex_x2, ERRATUM(2778471)
195
196check_erratum_ls cortex_x2, ERRATUM(2778471), CPU_REV(2, 1)
197
198add_erratum_entry cortex_x2, ERRATUM(3701772), ERRATA_X2_3701772
199
200check_erratum_ls cortex_x2, ERRATUM(3701772), CPU_REV(2, 1)
201
202workaround_reset_start cortex_x2, CVE(2022, 23960), WORKAROUND_CVE_2022_23960
203#if IMAGE_BL31
204	/*
205	 * The Cortex-X2 generic vectors are overridden to apply errata
206	 * mitigation on exception entry from lower ELs.
207	 */
208	override_vector_table wa_cve_vbar_cortex_x2
209#endif /* IMAGE_BL31 */
210workaround_reset_end cortex_x2, CVE(2022, 23960)
211
212check_erratum_chosen cortex_x2, CVE(2022, 23960), WORKAROUND_CVE_2022_23960
213
214/* Disable hardware page aggregation. Enables mitigation for `CVE-2024-5660` */
215workaround_reset_start cortex_x2, CVE(2024, 5660), WORKAROUND_CVE_2024_5660
216	sysreg_bit_set CORTEX_X2_CPUECTLR_EL1, BIT(46)
217workaround_reset_end cortex_x2, CVE(2024, 5660)
218
219check_erratum_ls cortex_x2, CVE(2024, 5660), CPU_REV(2, 1)
220
221	/* ----------------------------------------------------
222	 * HW will do the cache maintenance while powering down
223	 * ----------------------------------------------------
224	 */
225func cortex_x2_core_pwr_dwn
226	/* ---------------------------------------------------
227	 * Enable CPU power down bit in power control register
228	 * ---------------------------------------------------
229	 */
230	sysreg_bit_set CORTEX_X2_CPUPWRCTLR_EL1, CORTEX_X2_CPUPWRCTLR_EL1_CORE_PWRDN_BIT
231
232	apply_erratum cortex_x2, ERRATUM(2768515), ERRATA_X2_2768515
233	isb
234	ret
235endfunc cortex_x2_core_pwr_dwn
236
237cpu_reset_func_start cortex_x2
238	/* Disable speculative loads */
239	msr	SSBS, xzr
240	enable_mpmm
241cpu_reset_func_end cortex_x2
242
243	/* ---------------------------------------------
244	 * This function provides Cortex X2 specific
245	 * register information for crash reporting.
246	 * It needs to return with x6 pointing to
247	 * a list of register names in ascii and
248	 * x8 - x15 having values of registers to be
249	 * reported.
250	 * ---------------------------------------------
251	 */
252.section .rodata.cortex_x2_regs, "aS"
253cortex_x2_regs:  /* The ascii list of register names to be reported */
254	.asciz	"cpuectlr_el1", ""
255
256func cortex_x2_cpu_reg_dump
257	adr	x6, cortex_x2_regs
258	mrs	x8, CORTEX_X2_CPUECTLR_EL1
259	ret
260endfunc cortex_x2_cpu_reg_dump
261
262declare_cpu_ops cortex_x2, CORTEX_X2_MIDR, \
263	cortex_x2_reset_func, \
264	cortex_x2_core_pwr_dwn
265