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_runtime_start cortex_x2, ERRATUM(2291219), ERRATA_X2_2291219 180 /* 181 * Set/unset bit 36 in ACTLR2_EL1. The first call will set it, applying 182 * the workaround. Second call clears it to undo it. 183 */ 184 sysreg_bit_toggle CORTEX_X2_CPUACTLR2_EL1, BIT(36) 185workaround_runtime_end cortex_x2, ERRATUM(2291219), NO_ISB 186 187check_erratum_ls cortex_x2, ERRATUM(2291219), CPU_REV(2, 0) 188 189workaround_reset_start cortex_x2, ERRATUM(2313941), ERRATA_DSU_2313941 190 errata_dsu_2313941_wa_impl 191workaround_reset_end cortex_x2, ERRATUM(2313941) 192 193check_erratum_custom_start cortex_x2, ERRATUM(2313941) 194 check_errata_dsu_2313941_impl 195 ret 196check_erratum_custom_end cortex_x2, ERRATUM(2313941) 197 198workaround_reset_start cortex_x2, ERRATUM(2371105), ERRATA_X2_2371105 199 /* Set bit 40 in CPUACTLR2_EL1 */ 200 sysreg_bit_set CORTEX_X2_CPUACTLR2_EL1, CORTEX_X2_CPUACTLR2_EL1_BIT_40 201workaround_reset_end cortex_x2, ERRATUM(2371105) 202 203check_erratum_ls cortex_x2, ERRATUM(2371105), CPU_REV(2, 0) 204 205workaround_reset_start cortex_x2, ERRATUM(2742423), ERRATA_X2_2742423 206 /* Set CPUACTLR5_EL1[56:55] to 2'b01 */ 207 sysreg_bit_set CORTEX_X2_CPUACTLR5_EL1, BIT(55) 208 sysreg_bit_clear CORTEX_X2_CPUACTLR5_EL1, BIT(56) 209workaround_reset_end cortex_x2, ERRATUM(2742423) 210 211check_erratum_ls cortex_x2, ERRATUM(2742423), CPU_REV(2, 1) 212 213workaround_runtime_start cortex_x2, ERRATUM(2768515), ERRATA_X2_2768515 214 /* dsb before isb of power down sequence */ 215 dsb sy 216workaround_runtime_end cortex_x2, ERRATUM(2768515) 217 218check_erratum_ls cortex_x2, ERRATUM(2768515), CPU_REV(2, 1) 219 220workaround_reset_start cortex_x2, ERRATUM(2778471), ERRATA_X2_2778471 221 sysreg_bit_set CORTEX_X2_CPUACTLR3_EL1, BIT(47) 222workaround_reset_end cortex_x2, ERRATUM(2778471) 223 224check_erratum_ls cortex_x2, ERRATUM(2778471), CPU_REV(2, 1) 225 226add_erratum_entry cortex_x2, ERRATUM(3701772), ERRATA_X2_3701772 227 228check_erratum_ls cortex_x2, ERRATUM(3701772), CPU_REV(2, 1) 229 230workaround_reset_start cortex_x2, CVE(2022, 23960), WORKAROUND_CVE_2022_23960 231#if IMAGE_BL31 232 /* 233 * The Cortex-X2 generic vectors are overridden to apply errata 234 * mitigation on exception entry from lower ELs. 235 */ 236 override_vector_table wa_cve_vbar_cortex_x2 237#endif /* IMAGE_BL31 */ 238workaround_reset_end cortex_x2, CVE(2022, 23960) 239 240check_erratum_chosen cortex_x2, CVE(2022, 23960), WORKAROUND_CVE_2022_23960 241 242/* Disable hardware page aggregation. Enables mitigation for `CVE-2024-5660` */ 243workaround_reset_start cortex_x2, CVE(2024, 5660), WORKAROUND_CVE_2024_5660 244 sysreg_bit_set CORTEX_X2_CPUECTLR_EL1, BIT(46) 245workaround_reset_end cortex_x2, CVE(2024, 5660) 246 247check_erratum_ls cortex_x2, CVE(2024, 5660), CPU_REV(2, 1) 248 249 /* ---------------------------------------------------- 250 * HW will do the cache maintenance while powering down 251 * ---------------------------------------------------- 252 */ 253func cortex_x2_core_pwr_dwn 254 apply_erratum cortex_x2, ERRATUM(2291219), ERRATA_X2_2291219, NO_GET_CPU_REV 255 256 /* --------------------------------------------------- 257 * Enable CPU power down bit in power control register 258 * --------------------------------------------------- 259 */ 260 sysreg_bit_set CORTEX_X2_CPUPWRCTLR_EL1, CORTEX_X2_CPUPWRCTLR_EL1_CORE_PWRDN_BIT 261 262 apply_erratum cortex_x2, ERRATUM(2768515), ERRATA_X2_2768515 263 isb 264 ret 265endfunc cortex_x2_core_pwr_dwn 266 267cpu_reset_func_start cortex_x2 268 /* Disable speculative loads */ 269 msr SSBS, xzr 270 enable_mpmm 271cpu_reset_func_end cortex_x2 272 273 /* --------------------------------------------- 274 * This function provides Cortex X2 specific 275 * register information for crash reporting. 276 * It needs to return with x6 pointing to 277 * a list of register names in ascii and 278 * x8 - x15 having values of registers to be 279 * reported. 280 * --------------------------------------------- 281 */ 282.section .rodata.cortex_x2_regs, "aS" 283cortex_x2_regs: /* The ascii list of register names to be reported */ 284 .asciz "cpuectlr_el1", "" 285 286func cortex_x2_cpu_reg_dump 287 adr x6, cortex_x2_regs 288 mrs x8, CORTEX_X2_CPUECTLR_EL1 289 ret 290endfunc cortex_x2_cpu_reg_dump 291 292declare_cpu_ops cortex_x2, CORTEX_X2_MIDR, \ 293 cortex_x2_reset_func, \ 294 cortex_x2_core_pwr_dwn 295