xref: /rk3399_ARM-atf/lib/cpus/aarch64/cortex_x2.S (revision 79e7aae82dd173d1ccc63e5d553222f1d58f12f5)
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
28add_erratum_entry cortex_x2, ERRATUM(3701772), ERRATA_X2_3701772
29
30check_erratum_ls cortex_x2, ERRATUM(3701772), CPU_REV(2, 1)
31
32#if WORKAROUND_CVE_2022_23960
33	wa_cve_2022_23960_bhb_vector_table CORTEX_X2_BHB_LOOP_COUNT, cortex_x2
34#endif /* WORKAROUND_CVE_2022_23960 */
35
36cpu_reset_prologue cortex_x2
37
38/* Disable hardware page aggregation. Enables mitigation for `CVE-2024-5660` */
39workaround_reset_start cortex_x2, CVE(2024, 5660), WORKAROUND_CVE_2024_5660
40	sysreg_bit_set CORTEX_X2_CPUECTLR_EL1, BIT(46)
41workaround_reset_end cortex_x2, CVE(2024, 5660)
42
43check_erratum_ls cortex_x2, CVE(2024, 5660), CPU_REV(2, 1)
44
45workaround_reset_start cortex_x2, ERRATUM(2002765), ERRATA_X2_2002765
46	ldr	x0, =0x6
47	msr	S3_6_C15_C8_0, x0 /* CPUPSELR_EL3 */
48	ldr	x0, =0xF3A08002
49	msr	S3_6_C15_C8_2, x0 /* CPUPOR_EL3 */
50	ldr	x0, =0xFFF0F7FE
51	msr	S3_6_C15_C8_3, x0 /* CPUPMR_EL3 */
52	ldr	x0, =0x40000001003ff
53	msr	S3_6_C15_C8_1, x0 /* CPUPCR_EL3 */
54workaround_reset_end cortex_x2, ERRATUM(2002765)
55
56check_erratum_ls cortex_x2, ERRATUM(2002765), CPU_REV(2, 0)
57
58workaround_reset_start cortex_x2, ERRATUM(2017096), ERRATA_X2_2017096
59	sysreg_bit_set CORTEX_X2_CPUECTLR_EL1, CORTEX_X2_CPUECTLR_EL1_PFSTIDIS_BIT
60workaround_reset_end cortex_x2, ERRATUM(2017096)
61
62check_erratum_ls cortex_x2, ERRATUM(2017096), CPU_REV(2, 0)
63
64workaround_reset_start cortex_x2, ERRATUM(2058056), ERRATA_X2_2058056
65	sysreg_bitfield_insert CORTEX_X2_CPUECTLR2_EL1, CORTEX_X2_CPUECTLR2_EL1_PF_MODE_CNSRV, \
66	CORTEX_X2_CPUECTLR2_EL1_PF_MODE_SHIFT, CORTEX_X2_CPUECTLR2_EL1_PF_MODE_WIDTH
67workaround_reset_end cortex_x2, ERRATUM(2058056)
68
69check_erratum_ls cortex_x2, ERRATUM(2058056), CPU_REV(2, 1)
70
71workaround_reset_start cortex_x2, ERRATUM(2081180), ERRATA_X2_2081180
72	/* Apply instruction patching sequence */
73	ldr	x0, =0x3
74	msr	CORTEX_X2_IMP_CPUPSELR_EL3, x0
75	ldr	x0, =0xF3A08002
76	msr	CORTEX_X2_IMP_CPUPOR_EL3, x0
77	ldr	x0, =0xFFF0F7FE
78	msr	CORTEX_X2_IMP_CPUPMR_EL3, x0
79	ldr	x0, =0x10002001003FF
80	msr	CORTEX_X2_IMP_CPUPCR_EL3, x0
81	ldr	x0, =0x4
82	msr	CORTEX_X2_IMP_CPUPSELR_EL3, x0
83	ldr	x0, =0xBF200000
84	msr	CORTEX_X2_IMP_CPUPOR_EL3, x0
85	ldr	x0, =0xFFEF0000
86	msr	CORTEX_X2_IMP_CPUPMR_EL3, x0
87	ldr	x0, =0x10002001003F3
88	msr	CORTEX_X2_IMP_CPUPCR_EL3, x0
89workaround_reset_end cortex_x2, ERRATUM(2081180)
90
91check_erratum_ls cortex_x2, ERRATUM(2081180), CPU_REV(2, 0)
92
93workaround_reset_start cortex_x2, ERRATUM(2083908), ERRATA_X2_2083908
94	/* Apply the workaround by setting bit 13 in CPUACTLR5_EL1. */
95	sysreg_bit_set CORTEX_X2_CPUACTLR5_EL1, BIT(13)
96workaround_reset_end cortex_x2, ERRATUM(2083908)
97
98check_erratum_range cortex_x2, ERRATUM(2083908), CPU_REV(2, 0), CPU_REV(2, 0)
99
100workaround_reset_start cortex_x2, ERRATUM(2147715), ERRATA_X2_2147715
101	/* Apply the workaround by setting bit 22 in CPUACTLR_EL1. */
102	sysreg_bit_set CORTEX_X2_CPUACTLR_EL1, CORTEX_X2_CPUACTLR_EL1_BIT_22
103workaround_reset_end cortex_x2, ERRATUM(2147715)
104
105check_erratum_range cortex_x2, ERRATUM(2147715), CPU_REV(2, 0), CPU_REV(2, 0)
106
107workaround_reset_start cortex_x2, ERRATUM(2216384), ERRATA_X2_2216384
108	sysreg_bit_set CORTEX_X2_CPUACTLR5_EL1, CORTEX_X2_CPUACTLR5_EL1_BIT_17
109
110	/* Apply instruction patching sequence */
111	ldr	x0, =0x5
112	msr	CORTEX_X2_IMP_CPUPSELR_EL3, x0
113	ldr	x0, =0x10F600E000
114	msr	CORTEX_X2_IMP_CPUPOR_EL3, x0
115	ldr	x0, =0x10FF80E000
116	msr	CORTEX_X2_IMP_CPUPMR_EL3, x0
117	ldr	x0, =0x80000000003FF
118	msr	CORTEX_X2_IMP_CPUPCR_EL3, x0
119workaround_reset_end cortex_x2, ERRATUM(2216384)
120
121check_erratum_ls cortex_x2, ERRATUM(2216384), CPU_REV(2, 0)
122
123workaround_reset_start cortex_x2, ERRATUM(2282622), ERRATA_X2_2282622
124	/* Apply the workaround */
125	sysreg_bit_set CORTEX_X2_CPUACTLR2_EL1, BIT(0)
126workaround_reset_end cortex_x2, ERRATUM(2282622)
127
128check_erratum_ls cortex_x2, ERRATUM(2282622), CPU_REV(2, 1)
129
130workaround_reset_start cortex_x2, ERRATUM(2371105), ERRATA_X2_2371105
131	/* Set bit 40 in CPUACTLR2_EL1 */
132	sysreg_bit_set CORTEX_X2_CPUACTLR2_EL1, CORTEX_X2_CPUACTLR2_EL1_BIT_40
133workaround_reset_end cortex_x2, ERRATUM(2371105)
134
135check_erratum_ls cortex_x2, ERRATUM(2371105), CPU_REV(2, 0)
136
137workaround_reset_start cortex_x2, ERRATUM(2742423), ERRATA_X2_2742423
138	/* Set CPUACTLR5_EL1[56:55] to 2'b01 */
139	sysreg_bit_set CORTEX_X2_CPUACTLR5_EL1, BIT(55)
140	sysreg_bit_clear CORTEX_X2_CPUACTLR5_EL1, BIT(56)
141workaround_reset_end cortex_x2, ERRATUM(2742423)
142
143check_erratum_ls cortex_x2, ERRATUM(2742423), CPU_REV(2, 1)
144
145workaround_runtime_start cortex_x2, ERRATUM(2768515), ERRATA_X2_2768515
146	/* dsb before isb of power down sequence */
147	dsb	sy
148workaround_runtime_end cortex_x2, ERRATUM(2768515)
149
150check_erratum_ls cortex_x2, ERRATUM(2768515), CPU_REV(2, 1)
151
152workaround_reset_start cortex_x2, ERRATUM(2778471), ERRATA_X2_2778471
153	sysreg_bit_set CORTEX_X2_CPUACTLR3_EL1, BIT(47)
154workaround_reset_end cortex_x2, ERRATUM(2778471)
155
156check_erratum_ls cortex_x2, ERRATUM(2778471), CPU_REV(2, 1)
157
158workaround_reset_start cortex_x2, CVE(2022, 23960), WORKAROUND_CVE_2022_23960
159#if IMAGE_BL31
160	/*
161	 * The Cortex-X2 generic vectors are overridden to apply errata
162	 * mitigation on exception entry from lower ELs.
163	 */
164	override_vector_table wa_cve_vbar_cortex_x2
165#endif /* IMAGE_BL31 */
166workaround_reset_end cortex_x2, CVE(2022, 23960)
167
168check_erratum_chosen cortex_x2, CVE(2022, 23960), WORKAROUND_CVE_2022_23960
169
170workaround_reset_start cortex_x2, ERRATUM(2313941), ERRATA_DSU_2313941
171	errata_dsu_2313941_wa_impl
172workaround_reset_end cortex_x2, ERRATUM(2313941)
173
174check_erratum_custom_start cortex_x2, ERRATUM(2313941)
175	check_errata_dsu_2313941_impl
176	ret
177check_erratum_custom_end cortex_x2, ERRATUM(2313941)
178
179	/* ----------------------------------------------------
180	 * HW will do the cache maintenance while powering down
181	 * ----------------------------------------------------
182	 */
183func cortex_x2_core_pwr_dwn
184	/* ---------------------------------------------------
185	 * Enable CPU power down bit in power control register
186	 * ---------------------------------------------------
187	 */
188	sysreg_bit_set CORTEX_X2_CPUPWRCTLR_EL1, CORTEX_X2_CPUPWRCTLR_EL1_CORE_PWRDN_BIT
189
190	apply_erratum cortex_x2, ERRATUM(2768515), ERRATA_X2_2768515, NO_GET_CPU_REV
191	isb
192	ret
193endfunc cortex_x2_core_pwr_dwn
194
195cpu_reset_func_start cortex_x2
196	/* Disable speculative loads */
197	msr	SSBS, xzr
198	enable_mpmm
199cpu_reset_func_end cortex_x2
200
201	/* ---------------------------------------------
202	 * This function provides Cortex X2 specific
203	 * register information for crash reporting.
204	 * It needs to return with x6 pointing to
205	 * a list of register names in ascii and
206	 * x8 - x15 having values of registers to be
207	 * reported.
208	 * ---------------------------------------------
209	 */
210.section .rodata.cortex_x2_regs, "aS"
211cortex_x2_regs:  /* The ascii list of register names to be reported */
212	.asciz	"cpuectlr_el1", ""
213
214func cortex_x2_cpu_reg_dump
215	adr	x6, cortex_x2_regs
216	mrs	x8, CORTEX_X2_CPUECTLR_EL1
217	ret
218endfunc cortex_x2_cpu_reg_dump
219
220declare_cpu_ops cortex_x2, CORTEX_X2_MIDR, \
221	cortex_x2_reset_func, \
222	cortex_x2_core_pwr_dwn
223