xref: /rk3399_ARM-atf/lib/cpus/aarch64/neoverse_n2.S (revision ffdf5ea47a5ffede59f6fc7bf32775598dcd75a0)
1/*
2 * Copyright (c) 2020-2023, 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 <cpu_macros.S>
10#include <neoverse_n2.h>
11#include "wa_cve_2022_23960_bhb_vector.S"
12
13/* Hardware handled coherency */
14#if HW_ASSISTED_COHERENCY == 0
15#error "Neoverse N2 must be compiled with HW_ASSISTED_COHERENCY enabled"
16#endif
17
18/* 64-bit only core */
19#if CTX_INCLUDE_AARCH32_REGS == 1
20#error "Neoverse-N2 supports only AArch64. Compile with CTX_INCLUDE_AARCH32_REGS=0"
21#endif
22
23#if WORKAROUND_CVE_2022_23960
24	wa_cve_2022_23960_bhb_vector_table NEOVERSE_N2_BHB_LOOP_COUNT, neoverse_n2
25#endif /* WORKAROUND_CVE_2022_23960 */
26
27/*
28 * ERRATA_DSU_2313941:
29 * The errata is defined in dsu_helpers.S and applies to Neoverse N2.
30 * Henceforth creating symbolic names to the already existing errata
31 * workaround functions to get them registered under the Errata Framework.
32 */
33.equ check_erratum_neoverse_n2_2313941, check_errata_dsu_2313941
34.equ erratum_neoverse_n2_2313941_wa, errata_dsu_2313941_wa
35add_erratum_entry neoverse_n2, ERRATUM(2313941), ERRATA_DSU_2313941, APPLY_AT_RESET
36
37workaround_reset_start neoverse_n2, ERRATUM(2002655), ERRATA_N2_2002655
38	/* Apply instruction patching sequence */
39	ldr x0,=0x6
40	msr S3_6_c15_c8_0,x0
41	ldr x0,=0xF3A08002
42	msr S3_6_c15_c8_2,x0
43	ldr x0,=0xFFF0F7FE
44	msr S3_6_c15_c8_3,x0
45	ldr x0,=0x40000001003ff
46	msr S3_6_c15_c8_1,x0
47	ldr x0,=0x7
48	msr S3_6_c15_c8_0,x0
49	ldr x0,=0xBF200000
50	msr S3_6_c15_c8_2,x0
51	ldr x0,=0xFFEF0000
52	msr S3_6_c15_c8_3,x0
53	ldr x0,=0x40000001003f3
54	msr S3_6_c15_c8_1,x0
55workaround_reset_end neoverse_n2, ERRATUM(2002655)
56
57check_erratum_ls neoverse_n2, ERRATUM(2002655), CPU_REV(0, 0)
58
59workaround_reset_start neoverse_n2, ERRATUM(2025414), ERRATA_N2_2025414
60	sysreg_bit_set NEOVERSE_N2_CPUECTLR_EL1, NEOVERSE_N2_CPUECTLR_EL1_PFSTIDIS_BIT
61workaround_reset_end neoverse_n2, ERRATUM(2025414)
62
63check_erratum_ls neoverse_n2, ERRATUM(2025414), CPU_REV(0, 0)
64
65workaround_reset_start neoverse_n2, ERRATUM(2067956), ERRATA_N2_2067956
66	sysreg_bit_set NEOVERSE_N2_CPUACTLR_EL1, NEOVERSE_N2_CPUACTLR_EL1_BIT_46
67workaround_reset_end neoverse_n2, ERRATUM(2067956)
68
69check_erratum_ls neoverse_n2, ERRATUM(2067956), CPU_REV(0, 0)
70
71workaround_reset_start neoverse_n2, ERRATUM(2138953), ERRATA_N2_2138953
72	/* Apply instruction patching sequence */
73	mrs	x1, NEOVERSE_N2_CPUECTLR2_EL1
74	mov	x0, #NEOVERSE_N2_CPUECTLR2_EL1_PF_MODE_CNSRV
75	bfi	x1, x0, #CPUECTLR2_EL1_PF_MODE_LSB, #CPUECTLR2_EL1_PF_MODE_WIDTH
76	msr	NEOVERSE_N2_CPUECTLR2_EL1, x1
77workaround_reset_end neoverse_n2, ERRATUM(2138953)
78
79check_erratum_ls neoverse_n2, ERRATUM(2138953), CPU_REV(0, 3)
80
81workaround_reset_start neoverse_n2, ERRATUM(2138956), ERRATA_N2_2138956
82	/* Apply instruction patching sequence */
83	ldr	x0,=0x3
84	msr	S3_6_c15_c8_0,x0
85	ldr	x0,=0xF3A08002
86	msr	S3_6_c15_c8_2,x0
87	ldr	x0,=0xFFF0F7FE
88	msr	S3_6_c15_c8_3,x0
89	ldr	x0,=0x10002001003FF
90	msr	S3_6_c15_c8_1,x0
91	ldr	x0,=0x4
92	msr	S3_6_c15_c8_0,x0
93	ldr	x0,=0xBF200000
94	msr	S3_6_c15_c8_2,x0
95	ldr	x0,=0xFFEF0000
96	msr	S3_6_c15_c8_3,x0
97	ldr	x0,=0x10002001003F3
98	msr	S3_6_c15_c8_1,x0
99workaround_reset_end neoverse_n2, ERRATUM(2138956)
100
101check_erratum_ls neoverse_n2, ERRATUM(2138956), CPU_REV(0, 0)
102
103
104workaround_reset_start neoverse_n2, ERRATUM(2138958), ERRATA_N2_2138958
105	/* Apply instruction patching sequence */
106	sysreg_bit_set NEOVERSE_N2_CPUACTLR5_EL1, NEOVERSE_N2_CPUACTLR5_EL1_BIT_13
107workaround_reset_end neoverse_n2, ERRATUM(2138958)
108
109check_erratum_ls neoverse_n2, ERRATUM(2138958), CPU_REV(0, 0)
110
111workaround_reset_start neoverse_n2, ERRATUM(2189731), ERRATA_N2_2189731
112	sysreg_bit_set NEOVERSE_N2_CPUACTLR5_EL1, NEOVERSE_N2_CPUACTLR5_EL1_BIT_44
113workaround_reset_end neoverse_n2, ERRATUM(2189731)
114
115check_erratum_ls neoverse_n2, ERRATUM(2189731), CPU_REV(0, 0)
116
117workaround_reset_start neoverse_n2, ERRATUM(2242400), ERRATA_N2_2242400
118	/* Apply instruction patching sequence */
119	sysreg_bit_set NEOVERSE_N2_CPUACTLR5_EL1, NEOVERSE_N2_CPUACTLR5_EL1_BIT_17
120	ldr	x0, =0x2
121	msr	S3_6_c15_c8_0, x0
122	ldr	x0, =0x10F600E000
123	msr	S3_6_c15_c8_2, x0
124	ldr	x0, =0x10FF80E000
125	msr	S3_6_c15_c8_3, x0
126	ldr	x0, =0x80000000003FF
127	msr	S3_6_c15_c8_1, x0
128workaround_reset_end neoverse_n2, ERRATUM(2242400)
129
130check_erratum_ls neoverse_n2, ERRATUM(2242400), CPU_REV(0, 0)
131
132workaround_reset_start neoverse_n2, ERRATUM(2242415), ERRATA_N2_2242415
133	sysreg_bit_set NEOVERSE_N2_CPUACTLR_EL1, NEOVERSE_N2_CPUACTLR_EL1_BIT_22
134workaround_reset_end neoverse_n2, ERRATUM(2242415)
135
136check_erratum_ls neoverse_n2, ERRATUM(2242415), CPU_REV(0, 0)
137
138workaround_reset_start neoverse_n2, ERRATUM(2280757), ERRATA_N2_2280757
139	/* Apply instruction patching sequence */
140	sysreg_bit_set NEOVERSE_N2_CPUACTLR_EL1, NEOVERSE_N2_CPUACTLR_EL1_BIT_22
141workaround_reset_end neoverse_n2, ERRATUM(2280757)
142
143check_erratum_ls neoverse_n2, ERRATUM(2280757), CPU_REV(0, 0)
144
145workaround_runtime_start neoverse_n2, ERRATUM(2326639), ERRATA_N2_2326639
146	/* Set bit 36 in ACTLR2_EL1 */
147	sysreg_bit_set NEOVERSE_N2_CPUACTLR2_EL1, NEOVERSE_N2_CPUACTLR2_EL1_BIT_36
148workaround_runtime_end neoverse_n2, ERRATUM(2326639)
149
150check_erratum_ls neoverse_n2, ERRATUM(2326639), CPU_REV(0, 0)
151
152workaround_reset_start neoverse_n2, ERRATUM(2376738), ERRATA_N2_2376738
153	/* Set CPUACTLR2_EL1[0] to 1 to force PLDW/PFRM
154	 * ST to behave like PLD/PFRM LD and not cause
155	 * invalidations to other PE caches.
156	 */
157	sysreg_bit_set NEOVERSE_N2_CPUACTLR2_EL1, NEOVERSE_N2_CPUACTLR2_EL1_BIT_0
158workaround_reset_end neoverse_n2, ERRATUM(2376738)
159
160check_erratum_ls neoverse_n2, ERRATUM(2376738), CPU_REV(0, 3)
161
162workaround_reset_start neoverse_n2, ERRATUM(2388450), ERRATA_N2_2388450
163	/*Set bit 40 in ACTLR2_EL1 */
164	sysreg_bit_set NEOVERSE_N2_CPUACTLR2_EL1, NEOVERSE_N2_CPUACTLR2_EL1_BIT_40
165workaround_reset_end neoverse_n2, ERRATUM(2388450)
166
167check_erratum_ls neoverse_n2, ERRATUM(2388450), CPU_REV(0, 0)
168
169workaround_reset_start neoverse_n2, ERRATUM(2743014), ERRATA_N2_2743014
170	/* Set CPUACTLR5_EL1[56:55] to 2'b01 */
171	sysreg_bit_set NEOVERSE_N2_CPUACTLR5_EL1, NEOVERSE_N2_CPUACTLR5_EL1_BIT_55
172	sysreg_bit_clear NEOVERSE_N2_CPUACTLR5_EL1, NEOVERSE_N2_CPUACTLR5_EL1_BIT_56
173workaround_reset_end neoverse_n2, ERRATUM(2743014)
174
175check_erratum_ls neoverse_n2, ERRATUM(2743014), CPU_REV(0, 2)
176
177workaround_runtime_start neoverse_n2, ERRATUM(2743089), ERRATA_N2_2743089
178	/* dsb before isb of power down sequence */
179	dsb	sy
180workaround_runtime_end neoverse_n2, ERRATUM(2743089)
181
182check_erratum_ls neoverse_n2, ERRATUM(2743089), CPU_REV(0, 2)
183
184workaround_reset_start neoverse_n2, ERRATUM(2779511), ERRATA_N2_2779511
185	/* Set bit 47 in ACTLR3_EL1 */
186	sysreg_bit_set NEOVERSE_N2_CPUACTLR3_EL1, NEOVERSE_N2_CPUACTLR3_EL1_BIT_47
187workaround_reset_end neoverse_n2, ERRATUM(2779511)
188
189check_erratum_ls neoverse_n2, ERRATUM(2779511), CPU_REV(0, 2)
190
191workaround_reset_start neoverse_n2, CVE(2022,23960), WORKAROUND_CVE_2022_23960
192#if IMAGE_BL31
193	/*
194	 * The Neoverse-N2 generic vectors are overridden to apply errata
195         * mitigation on exception entry from lower ELs.
196	 */
197	override_vector_table wa_cve_vbar_neoverse_n2
198#endif /* IMAGE_BL31 */
199workaround_reset_end neoverse_n2, CVE(2022,23960)
200
201check_erratum_chosen neoverse_n2, CVE(2022, 23960), WORKAROUND_CVE_2022_23960
202
203	/* -------------------------------------------
204	 * The CPU Ops reset function for Neoverse N2.
205	 * -------------------------------------------
206	 */
207cpu_reset_func_start neoverse_n2
208
209	/* Check if the PE implements SSBS */
210	mrs	x0, id_aa64pfr1_el1
211	tst	x0, #(ID_AA64PFR1_EL1_SSBS_MASK << ID_AA64PFR1_EL1_SSBS_SHIFT)
212	b.eq	1f
213
214	/* Disable speculative loads */
215	msr	SSBS, xzr
2161:
217	/* Force all cacheable atomic instructions to be near */
218	sysreg_bit_set NEOVERSE_N2_CPUACTLR2_EL1, NEOVERSE_N2_CPUACTLR2_EL1_BIT_2
219
220#if ENABLE_FEAT_AMU
221	/* Make sure accesses from EL0/EL1 and EL2 are not trapped to EL3 */
222	sysreg_bit_set cptr_el3, TAM_BIT
223	/* Make sure accesses from EL0/EL1 are not trapped to EL2 */
224	sysreg_bit_set cptr_el2, TAM_BIT
225	/* No need to enable the counters as this would be done at el3 exit */
226#endif
227
228#if NEOVERSE_Nx_EXTERNAL_LLC
229	/* Some systems may have External LLC, core needs to be made aware */
230	sysreg_bit_set NEOVERSE_N2_CPUECTLR_EL1, NEOVERSE_N2_CPUECTLR_EL1_EXTLLC_BIT
231#endif
232cpu_reset_func_end neoverse_n2
233
234func neoverse_n2_core_pwr_dwn
235
236	apply_erratum neoverse_n2, ERRATUM(2326639), ERRATA_N2_2326639
237	/* ---------------------------------------------------
238	 * Enable CPU power down bit in power control register
239	 * No need to do cache maintenance here.
240	 * ---------------------------------------------------
241	 */
242	sysreg_bit_set NEOVERSE_N2_CPUPWRCTLR_EL1, NEOVERSE_N2_CORE_PWRDN_EN_BIT
243
244	apply_erratum neoverse_n2, ERRATUM(2743089), ERRATA_N2_2743089
245
246	isb
247	ret
248endfunc neoverse_n2_core_pwr_dwn
249
250errata_report_shim neoverse_n2
251
252	/* ---------------------------------------------
253	 * This function provides Neoverse N2 specific
254	 * register information for crash reporting.
255	 * It needs to return with x6 pointing to
256	 * a list of register names in ASCII and
257	 * x8 - x15 having values of registers to be
258	 * reported.
259	 * ---------------------------------------------
260	 */
261.section .rodata.neoverse_n2_regs, "aS"
262neoverse_n2_regs:  /* The ASCII list of register names to be reported */
263	.asciz	"cpupwrctlr_el1", ""
264
265func neoverse_n2_cpu_reg_dump
266	adr	x6, neoverse_n2_regs
267	mrs	x8, NEOVERSE_N2_CPUPWRCTLR_EL1
268	ret
269endfunc neoverse_n2_cpu_reg_dump
270
271declare_cpu_ops neoverse_n2, NEOVERSE_N2_MIDR, \
272	neoverse_n2_reset_func, \
273	neoverse_n2_core_pwr_dwn
274