blob: 44331a5a8e057b15b512eedef0db615877941337 [file] [log] [blame]
Javier Almansa Sobrino9faad3c2020-10-23 13:22:07 +01001/*
Arvind Ram Prakash5b27ecf2023-06-23 14:47:30 -05002 * Copyright (c) 2020-2023, Arm Limited. All rights reserved.
Javier Almansa Sobrino9faad3c2020-10-23 13:22:07 +01003 *
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>
Bipin Ravi86499742022-01-18 01:59:06 -060011#include "wa_cve_2022_23960_bhb_vector.S"
Javier Almansa Sobrino9faad3c2020-10-23 13:22:07 +010012
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
Bipin Ravi86499742022-01-18 01:59:06 -060023#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
Arvind Ram Prakash7aea56c2023-06-26 15:05:40 -050027/*
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.
nayanpatel-arm277581e2021-08-06 17:46:10 -070032 */
Arvind Ram Prakash7aea56c2023-06-26 15:05:40 -050033.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
nayanpatel-arm277581e2021-08-06 17:46:10 -070036
Arvind Ram Prakash7aea56c2023-06-26 15:05:40 -050037workaround_reset_start neoverse_n2, ERRATUM(2002655), ERRATA_N2_2002655
nayanpatel-arm277581e2021-08-06 17:46:10 -070038 /* 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
Arvind Ram Prakash7aea56c2023-06-26 15:05:40 -050055workaround_reset_end neoverse_n2, ERRATUM(2002655)
nayanpatel-arm277581e2021-08-06 17:46:10 -070056
Arvind Ram Prakash7aea56c2023-06-26 15:05:40 -050057check_erratum_ls neoverse_n2, ERRATUM(2002655), CPU_REV(0, 0)
nayanpatel-arm277581e2021-08-06 17:46:10 -070058
Arvind Ram Prakash7aea56c2023-06-26 15:05:40 -050059workaround_reset_start neoverse_n2, ERRATUM(2025414), ERRATA_N2_2025414
Arvind Ram Prakash05464d92023-06-27 09:54:23 -050060 sysreg_bit_set NEOVERSE_N2_CPUECTLR_EL1, NEOVERSE_N2_CPUECTLR_EL1_PFSTIDIS_BIT
Arvind Ram Prakash7aea56c2023-06-26 15:05:40 -050061workaround_reset_end neoverse_n2, ERRATUM(2025414)
Bipin Ravi7f565472021-03-31 10:10:27 -050062
Arvind Ram Prakash7aea56c2023-06-26 15:05:40 -050063check_erratum_ls neoverse_n2, ERRATUM(2025414), CPU_REV(0, 0)
Bipin Ravi7f565472021-03-31 10:10:27 -050064
Arvind Ram Prakash7aea56c2023-06-26 15:05:40 -050065workaround_reset_start neoverse_n2, ERRATUM(2067956), ERRATA_N2_2067956
Arvind Ram Prakash05464d92023-06-27 09:54:23 -050066 sysreg_bit_set NEOVERSE_N2_CPUACTLR_EL1, NEOVERSE_N2_CPUACTLR_EL1_BIT_46
Arvind Ram Prakash7aea56c2023-06-26 15:05:40 -050067workaround_reset_end neoverse_n2, ERRATUM(2067956)
Bipin Ravi7e030692021-08-30 13:02:51 -050068
Arvind Ram Prakash7aea56c2023-06-26 15:05:40 -050069check_erratum_ls neoverse_n2, ERRATUM(2067956), CPU_REV(0, 0)
Arvind Ram Prakash5b27ecf2023-06-23 14:47:30 -050070
Arvind Ram Prakash7aea56c2023-06-26 15:05:40 -050071workaround_reset_start neoverse_n2, ERRATUM(2138953), ERRATA_N2_2138953
Arvind Ram Prakash5b27ecf2023-06-23 14:47:30 -050072 /* 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
Arvind Ram Prakash7aea56c2023-06-26 15:05:40 -050077workaround_reset_end neoverse_n2, ERRATUM(2138953)
Bipin Ravi7e030692021-08-30 13:02:51 -050078
Arvind Ram Prakashf99b7982023-06-29 16:17:23 -050079check_erratum_ls neoverse_n2, ERRATUM(2138953), CPU_REV(0, 3)
Bipin Ravi0ba631c2021-09-01 01:36:43 -050080
Arvind Ram Prakash7aea56c2023-06-26 15:05:40 -050081workaround_reset_start neoverse_n2, ERRATUM(2138956), ERRATA_N2_2138956
Bipin Ravi0ba631c2021-09-01 01:36:43 -050082 /* 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
Arvind Ram Prakash7aea56c2023-06-26 15:05:40 -050099workaround_reset_end neoverse_n2, ERRATUM(2138956)
Bipin Ravi0ba631c2021-09-01 01:36:43 -0500100
Arvind Ram Prakash7aea56c2023-06-26 15:05:40 -0500101check_erratum_ls neoverse_n2, ERRATUM(2138956), CPU_REV(0, 0)
Bipin Ravi0ba631c2021-09-01 01:36:43 -0500102
nayanpatel-arm2f153992021-10-06 15:31:24 -0700103
Arvind Ram Prakash7aea56c2023-06-26 15:05:40 -0500104workaround_reset_start neoverse_n2, ERRATUM(2138958), ERRATA_N2_2138958
nayanpatel-arm2f153992021-10-06 15:31:24 -0700105 /* Apply instruction patching sequence */
Arvind Ram Prakash05464d92023-06-27 09:54:23 -0500106 sysreg_bit_set NEOVERSE_N2_CPUACTLR5_EL1, NEOVERSE_N2_CPUACTLR5_EL1_BIT_13
Arvind Ram Prakash7aea56c2023-06-26 15:05:40 -0500107workaround_reset_end neoverse_n2, ERRATUM(2138958)
nayanpatel-arm2f153992021-10-06 15:31:24 -0700108
Arvind Ram Prakash7aea56c2023-06-26 15:05:40 -0500109check_erratum_ls neoverse_n2, ERRATUM(2138958), CPU_REV(0, 0)
nayanpatel-arm2f153992021-10-06 15:31:24 -0700110
Arvind Ram Prakash7aea56c2023-06-26 15:05:40 -0500111workaround_reset_start neoverse_n2, ERRATUM(2189731), ERRATA_N2_2189731
Arvind Ram Prakash05464d92023-06-27 09:54:23 -0500112 sysreg_bit_set NEOVERSE_N2_CPUACTLR5_EL1, NEOVERSE_N2_CPUACTLR5_EL1_BIT_44
Arvind Ram Prakash7aea56c2023-06-26 15:05:40 -0500113workaround_reset_end neoverse_n2, ERRATUM(2189731)
nayanpatel-armd4c5f9c2021-09-28 09:46:45 -0700114
Arvind Ram Prakash7aea56c2023-06-26 15:05:40 -0500115check_erratum_ls neoverse_n2, ERRATUM(2189731), CPU_REV(0, 0)
nayanpatel-arm8e1aa012021-10-20 18:28:58 -0700116
Arvind Ram Prakash7aea56c2023-06-26 15:05:40 -0500117workaround_reset_start neoverse_n2, ERRATUM(2242400), ERRATA_N2_2242400
nayanpatel-arm8e1aa012021-10-20 18:28:58 -0700118 /* Apply instruction patching sequence */
Arvind Ram Prakash05464d92023-06-27 09:54:23 -0500119 sysreg_bit_set NEOVERSE_N2_CPUACTLR5_EL1, NEOVERSE_N2_CPUACTLR5_EL1_BIT_17
Arvind Ram Prakash5b27ecf2023-06-23 14:47:30 -0500120 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
Arvind Ram Prakash7aea56c2023-06-26 15:05:40 -0500128workaround_reset_end neoverse_n2, ERRATUM(2242400)
nayanpatel-arm8e1aa012021-10-20 18:28:58 -0700129
Arvind Ram Prakash7aea56c2023-06-26 15:05:40 -0500130check_erratum_ls neoverse_n2, ERRATUM(2242400), CPU_REV(0, 0)
nayanpatel-arm8e1aa012021-10-20 18:28:58 -0700131
Arvind Ram Prakash7aea56c2023-06-26 15:05:40 -0500132workaround_reset_start neoverse_n2, ERRATUM(2242415), ERRATA_N2_2242415
Arvind Ram Prakash05464d92023-06-27 09:54:23 -0500133 sysreg_bit_set NEOVERSE_N2_CPUACTLR_EL1, NEOVERSE_N2_CPUACTLR_EL1_BIT_22
Arvind Ram Prakash7aea56c2023-06-26 15:05:40 -0500134workaround_reset_end neoverse_n2, ERRATUM(2242415)
nayanpatel-armfed98132021-10-07 17:59:33 -0700135
Arvind Ram Prakash7aea56c2023-06-26 15:05:40 -0500136check_erratum_ls neoverse_n2, ERRATUM(2242415), CPU_REV(0, 0)
nayanpatel-armfed98132021-10-07 17:59:33 -0700137
Arvind Ram Prakash7aea56c2023-06-26 15:05:40 -0500138workaround_reset_start neoverse_n2, ERRATUM(2280757), ERRATA_N2_2280757
nayanpatel-arm45b9f6f2021-10-20 17:30:46 -0700139 /* Apply instruction patching sequence */
Arvind Ram Prakash05464d92023-06-27 09:54:23 -0500140 sysreg_bit_set NEOVERSE_N2_CPUACTLR_EL1, NEOVERSE_N2_CPUACTLR_EL1_BIT_22
Arvind Ram Prakash7aea56c2023-06-26 15:05:40 -0500141workaround_reset_end neoverse_n2, ERRATUM(2280757)
nayanpatel-arm45b9f6f2021-10-20 17:30:46 -0700142
Arvind Ram Prakash7aea56c2023-06-26 15:05:40 -0500143check_erratum_ls neoverse_n2, ERRATUM(2280757), CPU_REV(0, 0)
Boyan Karatotevd3f8b4d2022-10-03 14:07:08 +0100144
Arvind Ram Prakash7aea56c2023-06-26 15:05:40 -0500145workaround_runtime_start neoverse_n2, ERRATUM(2326639), ERRATA_N2_2326639
Boyan Karatotevd3f8b4d2022-10-03 14:07:08 +0100146 /* Set bit 36 in ACTLR2_EL1 */
Arvind Ram Prakash05464d92023-06-27 09:54:23 -0500147 sysreg_bit_set NEOVERSE_N2_CPUACTLR2_EL1, NEOVERSE_N2_CPUACTLR2_EL1_BIT_36
Arvind Ram Prakash7aea56c2023-06-26 15:05:40 -0500148workaround_runtime_end neoverse_n2, ERRATUM(2326639)
Akram Ahmadb621bda2022-07-18 12:27:29 +0100149
Arvind Ram Prakash7aea56c2023-06-26 15:05:40 -0500150check_erratum_ls neoverse_n2, ERRATUM(2326639), CPU_REV(0, 0)
Akram Ahmadb621bda2022-07-18 12:27:29 +0100151
Arvind Ram Prakash7aea56c2023-06-26 15:05:40 -0500152workaround_reset_start neoverse_n2, ERRATUM(2376738), ERRATA_N2_2376738
Akram Ahmadb621bda2022-07-18 12:27:29 +0100153 /* 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 */
Arvind Ram Prakash05464d92023-06-27 09:54:23 -0500157 sysreg_bit_set NEOVERSE_N2_CPUACTLR2_EL1, NEOVERSE_N2_CPUACTLR2_EL1_BIT_0
Arvind Ram Prakash7aea56c2023-06-26 15:05:40 -0500158workaround_reset_end neoverse_n2, ERRATUM(2376738)
Akram Ahmadb621bda2022-07-18 12:27:29 +0100159
Arvind Ram Prakashf99b7982023-06-29 16:17:23 -0500160check_erratum_ls neoverse_n2, ERRATUM(2376738), CPU_REV(0, 3)
Daniel Boulby1af2b112022-07-06 14:33:13 +0100161
Arvind Ram Prakash7aea56c2023-06-26 15:05:40 -0500162workaround_reset_start neoverse_n2, ERRATUM(2388450), ERRATA_N2_2388450
Daniel Boulby1af2b112022-07-06 14:33:13 +0100163 /*Set bit 40 in ACTLR2_EL1 */
Arvind Ram Prakash05464d92023-06-27 09:54:23 -0500164 sysreg_bit_set NEOVERSE_N2_CPUACTLR2_EL1, NEOVERSE_N2_CPUACTLR2_EL1_BIT_40
Arvind Ram Prakash7aea56c2023-06-26 15:05:40 -0500165workaround_reset_end neoverse_n2, ERRATUM(2388450)
Daniel Boulby1af2b112022-07-06 14:33:13 +0100166
Arvind Ram Prakash7aea56c2023-06-26 15:05:40 -0500167check_erratum_ls neoverse_n2, ERRATUM(2388450), CPU_REV(0, 0)
Daniel Boulby1af2b112022-07-06 14:33:13 +0100168
Arvind Ram Prakash7aea56c2023-06-26 15:05:40 -0500169workaround_runtime_start neoverse_n2, ERRATUM(2743089), ERRATA_N2_2743089
Bipin Ravicc744bf2022-12-07 17:01:26 -0600170 /* dsb before isb of power down sequence */
171 dsb sy
Arvind Ram Prakash7aea56c2023-06-26 15:05:40 -0500172workaround_runtime_end neoverse_n2, ERRATUM(2743089)
Bipin Ravicc744bf2022-12-07 17:01:26 -0600173
Arvind Ram Prakash7aea56c2023-06-26 15:05:40 -0500174check_erratum_ls neoverse_n2, ERRATUM(2743089), CPU_REV(0, 2)
Bipin Ravicc744bf2022-12-07 17:01:26 -0600175
Arvind Ram Prakash7aea56c2023-06-26 15:05:40 -0500176workaround_reset_start neoverse_n2, CVE(2022,23960), WORKAROUND_CVE_2022_23960
177#if IMAGE_BL31
178 /*
179 * The Neoverse-N2 generic vectors are overridden to apply errata
180 * mitigation on exception entry from lower ELs.
181 */
Arvind Ram Prakash05464d92023-06-27 09:54:23 -0500182 override_vector_table wa_cve_vbar_neoverse_n2
Arvind Ram Prakash7aea56c2023-06-26 15:05:40 -0500183#endif /* IMAGE_BL31 */
184workaround_reset_end neoverse_n2, CVE(2022,23960)
185
186check_erratum_chosen neoverse_n2, CVE(2022, 23960), WORKAROUND_CVE_2022_23960
Bipin Ravi86499742022-01-18 01:59:06 -0600187
Bipin Ravi7f565472021-03-31 10:10:27 -0500188 /* -------------------------------------------
Javier Almansa Sobrino9faad3c2020-10-23 13:22:07 +0100189 * The CPU Ops reset function for Neoverse N2.
Bipin Ravi7f565472021-03-31 10:10:27 -0500190 * -------------------------------------------
Javier Almansa Sobrino9faad3c2020-10-23 13:22:07 +0100191 */
Arvind Ram Prakash7aea56c2023-06-26 15:05:40 -0500192cpu_reset_func_start neoverse_n2
nayanpatel-arm277581e2021-08-06 17:46:10 -0700193
Javier Almansa Sobrino9faad3c2020-10-23 13:22:07 +0100194 /* Check if the PE implements SSBS */
195 mrs x0, id_aa64pfr1_el1
196 tst x0, #(ID_AA64PFR1_EL1_SSBS_MASK << ID_AA64PFR1_EL1_SSBS_SHIFT)
197 b.eq 1f
198
199 /* Disable speculative loads */
200 msr SSBS, xzr
2011:
202 /* Force all cacheable atomic instructions to be near */
Arvind Ram Prakash05464d92023-06-27 09:54:23 -0500203 sysreg_bit_set NEOVERSE_N2_CPUACTLR2_EL1, NEOVERSE_N2_CPUACTLR2_EL1_BIT_2
Javier Almansa Sobrino9faad3c2020-10-23 13:22:07 +0100204
Andre Przywara0b7f1b02023-03-21 13:53:19 +0000205#if ENABLE_FEAT_AMU
Javier Almansa Sobrino9faad3c2020-10-23 13:22:07 +0100206 /* Make sure accesses from EL0/EL1 and EL2 are not trapped to EL3 */
Arvind Ram Prakash05464d92023-06-27 09:54:23 -0500207 sysreg_bit_set cptr_el3, TAM_BIT
Javier Almansa Sobrino9faad3c2020-10-23 13:22:07 +0100208 /* Make sure accesses from EL0/EL1 are not trapped to EL2 */
Arvind Ram Prakash05464d92023-06-27 09:54:23 -0500209 sysreg_bit_set cptr_el2, TAM_BIT
Javier Almansa Sobrino9faad3c2020-10-23 13:22:07 +0100210 /* No need to enable the counters as this would be done at el3 exit */
211#endif
212
213#if NEOVERSE_Nx_EXTERNAL_LLC
214 /* Some systems may have External LLC, core needs to be made aware */
Arvind Ram Prakash05464d92023-06-27 09:54:23 -0500215 sysreg_bit_set NEOVERSE_N2_CPUECTLR_EL1, NEOVERSE_N2_CPUECTLR_EL1_EXTLLC_BIT
Javier Almansa Sobrino9faad3c2020-10-23 13:22:07 +0100216#endif
Arvind Ram Prakash7aea56c2023-06-26 15:05:40 -0500217cpu_reset_func_end neoverse_n2
Javier Almansa Sobrino9faad3c2020-10-23 13:22:07 +0100218
219func neoverse_n2_core_pwr_dwn
Boyan Karatotevd3f8b4d2022-10-03 14:07:08 +0100220
Arvind Ram Prakash05464d92023-06-27 09:54:23 -0500221 apply_erratum neoverse_n2, ERRATUM(2326639), ERRATA_N2_2326639
Bipin Ravi7f565472021-03-31 10:10:27 -0500222 /* ---------------------------------------------------
Javier Almansa Sobrino9faad3c2020-10-23 13:22:07 +0100223 * Enable CPU power down bit in power control register
224 * No need to do cache maintenance here.
Bipin Ravi7f565472021-03-31 10:10:27 -0500225 * ---------------------------------------------------
Javier Almansa Sobrino9faad3c2020-10-23 13:22:07 +0100226 */
Arvind Ram Prakash05464d92023-06-27 09:54:23 -0500227 sysreg_bit_set NEOVERSE_N2_CPUPWRCTLR_EL1, NEOVERSE_N2_CORE_PWRDN_EN_BIT
228
229 apply_erratum neoverse_n2, ERRATUM(2743089), ERRATA_N2_2743089
230
Javier Almansa Sobrino9faad3c2020-10-23 13:22:07 +0100231 isb
232 ret
233endfunc neoverse_n2_core_pwr_dwn
234
Arvind Ram Prakash7aea56c2023-06-26 15:05:40 -0500235errata_report_shim neoverse_n2
Javier Almansa Sobrino9faad3c2020-10-23 13:22:07 +0100236
237 /* ---------------------------------------------
238 * This function provides Neoverse N2 specific
239 * register information for crash reporting.
240 * It needs to return with x6 pointing to
241 * a list of register names in ASCII and
242 * x8 - x15 having values of registers to be
243 * reported.
244 * ---------------------------------------------
245 */
246.section .rodata.neoverse_n2_regs, "aS"
247neoverse_n2_regs: /* The ASCII list of register names to be reported */
248 .asciz "cpupwrctlr_el1", ""
249
250func neoverse_n2_cpu_reg_dump
251 adr x6, neoverse_n2_regs
252 mrs x8, NEOVERSE_N2_CPUPWRCTLR_EL1
253 ret
254endfunc neoverse_n2_cpu_reg_dump
255
256declare_cpu_ops neoverse_n2, NEOVERSE_N2_MIDR, \
257 neoverse_n2_reset_func, \
258 neoverse_n2_core_pwr_dwn