1*91f16700Schasinglulu/* 2*91f16700Schasinglulu * Copyright (c) 2021-2023, Arm Limited. All rights reserved. 3*91f16700Schasinglulu * 4*91f16700Schasinglulu * SPDX-License-Identifier: BSD-3-Clause 5*91f16700Schasinglulu */ 6*91f16700Schasinglulu 7*91f16700Schasinglulu#include <arch.h> 8*91f16700Schasinglulu#include <asm_macros.S> 9*91f16700Schasinglulu#include <common/bl_common.h> 10*91f16700Schasinglulu#include <cortex_x2.h> 11*91f16700Schasinglulu#include <cpu_macros.S> 12*91f16700Schasinglulu#include <plat_macros.S> 13*91f16700Schasinglulu#include "wa_cve_2022_23960_bhb_vector.S" 14*91f16700Schasinglulu 15*91f16700Schasinglulu/* Hardware handled coherency */ 16*91f16700Schasinglulu#if HW_ASSISTED_COHERENCY == 0 17*91f16700Schasinglulu#error "Cortex X2 must be compiled with HW_ASSISTED_COHERENCY enabled" 18*91f16700Schasinglulu#endif 19*91f16700Schasinglulu 20*91f16700Schasinglulu/* 64-bit only core */ 21*91f16700Schasinglulu#if CTX_INCLUDE_AARCH32_REGS == 1 22*91f16700Schasinglulu#error "Cortex X2 supports only AArch64. Compile with CTX_INCLUDE_AARCH32_REGS=0" 23*91f16700Schasinglulu#endif 24*91f16700Schasinglulu 25*91f16700Schasinglulu#if WORKAROUND_CVE_2022_23960 26*91f16700Schasinglulu wa_cve_2022_23960_bhb_vector_table CORTEX_X2_BHB_LOOP_COUNT, cortex_x2 27*91f16700Schasinglulu#endif /* WORKAROUND_CVE_2022_23960 */ 28*91f16700Schasinglulu 29*91f16700Schasingluluworkaround_reset_start cortex_x2, ERRATUM(2002765), ERRATA_X2_2002765 30*91f16700Schasinglulu ldr x0, =0x6 31*91f16700Schasinglulu msr S3_6_C15_C8_0, x0 /* CPUPSELR_EL3 */ 32*91f16700Schasinglulu ldr x0, =0xF3A08002 33*91f16700Schasinglulu msr S3_6_C15_C8_2, x0 /* CPUPOR_EL3 */ 34*91f16700Schasinglulu ldr x0, =0xFFF0F7FE 35*91f16700Schasinglulu msr S3_6_C15_C8_3, x0 /* CPUPMR_EL3 */ 36*91f16700Schasinglulu ldr x0, =0x40000001003ff 37*91f16700Schasinglulu msr S3_6_C15_C8_1, x0 /* CPUPCR_EL3 */ 38*91f16700Schasingluluworkaround_reset_end cortex_x2, ERRATUM(2002765) 39*91f16700Schasinglulu 40*91f16700Schasinglulucheck_erratum_ls cortex_x2, ERRATUM(2002765), CPU_REV(2, 0) 41*91f16700Schasinglulu 42*91f16700Schasingluluworkaround_reset_start cortex_x2, ERRATUM(2017096), ERRATA_X2_2017096 43*91f16700Schasinglulu sysreg_bit_set CORTEX_X2_CPUECTLR_EL1, CORTEX_X2_CPUECTLR_EL1_PFSTIDIS_BIT 44*91f16700Schasingluluworkaround_reset_end cortex_x2, ERRATUM(2017096) 45*91f16700Schasinglulu 46*91f16700Schasinglulucheck_erratum_ls cortex_x2, ERRATUM(2017096), CPU_REV(2, 0) 47*91f16700Schasinglulu 48*91f16700Schasingluluworkaround_reset_start cortex_x2, ERRATUM(2058056), ERRATA_X2_2058056 49*91f16700Schasinglulu sysreg_bitfield_insert CORTEX_X2_CPUECTLR2_EL1, CORTEX_X2_CPUECTLR2_EL1_PF_MODE_CNSRV, \ 50*91f16700Schasinglulu CORTEX_X2_CPUECTLR2_EL1_PF_MODE_SHIFT, CORTEX_X2_CPUECTLR2_EL1_PF_MODE_WIDTH 51*91f16700Schasingluluworkaround_reset_end cortex_x2, ERRATUM(2058056) 52*91f16700Schasinglulu 53*91f16700Schasinglulucheck_erratum_ls cortex_x2, ERRATUM(2058056), CPU_REV(2, 1) 54*91f16700Schasinglulu 55*91f16700Schasingluluworkaround_reset_start cortex_x2, ERRATUM(2081180), ERRATA_X2_2081180 56*91f16700Schasinglulu /* Apply instruction patching sequence */ 57*91f16700Schasinglulu ldr x0, =0x3 58*91f16700Schasinglulu msr CORTEX_X2_IMP_CPUPSELR_EL3, x0 59*91f16700Schasinglulu ldr x0, =0xF3A08002 60*91f16700Schasinglulu msr CORTEX_X2_IMP_CPUPOR_EL3, x0 61*91f16700Schasinglulu ldr x0, =0xFFF0F7FE 62*91f16700Schasinglulu msr CORTEX_X2_IMP_CPUPMR_EL3, x0 63*91f16700Schasinglulu ldr x0, =0x10002001003FF 64*91f16700Schasinglulu msr CORTEX_X2_IMP_CPUPCR_EL3, x0 65*91f16700Schasinglulu ldr x0, =0x4 66*91f16700Schasinglulu msr CORTEX_X2_IMP_CPUPSELR_EL3, x0 67*91f16700Schasinglulu ldr x0, =0xBF200000 68*91f16700Schasinglulu msr CORTEX_X2_IMP_CPUPOR_EL3, x0 69*91f16700Schasinglulu ldr x0, =0xFFEF0000 70*91f16700Schasinglulu msr CORTEX_X2_IMP_CPUPMR_EL3, x0 71*91f16700Schasinglulu ldr x0, =0x10002001003F3 72*91f16700Schasinglulu msr CORTEX_X2_IMP_CPUPCR_EL3, x0 73*91f16700Schasingluluworkaround_reset_end cortex_x2, ERRATUM(2081180) 74*91f16700Schasinglulu 75*91f16700Schasinglulucheck_erratum_ls cortex_x2, ERRATUM(2081180), CPU_REV(2, 0) 76*91f16700Schasinglulu 77*91f16700Schasingluluworkaround_reset_start cortex_x2, ERRATUM(2083908), ERRATA_X2_2083908 78*91f16700Schasinglulu /* Apply the workaround by setting bit 13 in CPUACTLR5_EL1. */ 79*91f16700Schasinglulu sysreg_bit_set CORTEX_X2_CPUACTLR5_EL1, BIT(13) 80*91f16700Schasingluluworkaround_reset_end cortex_x2, ERRATUM(2083908) 81*91f16700Schasinglulu 82*91f16700Schasinglulucheck_erratum_range cortex_x2, ERRATUM(2083908), CPU_REV(2, 0), CPU_REV(2, 0) 83*91f16700Schasinglulu 84*91f16700Schasingluluworkaround_reset_start cortex_x2, ERRATUM(2147715), ERRATA_X2_2147715 85*91f16700Schasinglulu /* Apply the workaround by setting bit 22 in CPUACTLR_EL1. */ 86*91f16700Schasinglulu sysreg_bit_set CORTEX_X2_CPUACTLR_EL1, CORTEX_X2_CPUACTLR_EL1_BIT_22 87*91f16700Schasingluluworkaround_reset_end cortex_x2, ERRATUM(2147715) 88*91f16700Schasinglulu 89*91f16700Schasinglulucheck_erratum_range cortex_x2, ERRATUM(2147715), CPU_REV(2, 0), CPU_REV(2, 0) 90*91f16700Schasinglulu 91*91f16700Schasingluluworkaround_reset_start cortex_x2, ERRATUM(2216384), ERRATA_X2_2216384 92*91f16700Schasinglulu sysreg_bit_set CORTEX_X2_CPUACTLR5_EL1, CORTEX_X2_CPUACTLR5_EL1_BIT_17 93*91f16700Schasinglulu 94*91f16700Schasinglulu /* Apply instruction patching sequence */ 95*91f16700Schasinglulu ldr x0, =0x5 96*91f16700Schasinglulu msr CORTEX_X2_IMP_CPUPSELR_EL3, x0 97*91f16700Schasinglulu ldr x0, =0x10F600E000 98*91f16700Schasinglulu msr CORTEX_X2_IMP_CPUPOR_EL3, x0 99*91f16700Schasinglulu ldr x0, =0x10FF80E000 100*91f16700Schasinglulu msr CORTEX_X2_IMP_CPUPMR_EL3, x0 101*91f16700Schasinglulu ldr x0, =0x80000000003FF 102*91f16700Schasinglulu msr CORTEX_X2_IMP_CPUPCR_EL3, x0 103*91f16700Schasingluluworkaround_reset_end cortex_x2, ERRATUM(2216384) 104*91f16700Schasinglulu 105*91f16700Schasinglulucheck_erratum_ls cortex_x2, ERRATUM(2216384), CPU_REV(2, 0) 106*91f16700Schasinglulu 107*91f16700Schasingluluworkaround_reset_start cortex_x2, ERRATUM(2282622), ERRATA_X2_2282622 108*91f16700Schasinglulu /* Apply the workaround */ 109*91f16700Schasinglulu sysreg_bit_set CORTEX_X2_CPUACTLR2_EL1, BIT(0) 110*91f16700Schasingluluworkaround_reset_end cortex_x2, ERRATUM(2282622) 111*91f16700Schasinglulu 112*91f16700Schasinglulucheck_erratum_ls cortex_x2, ERRATUM(2282622), CPU_REV(2, 1) 113*91f16700Schasinglulu 114*91f16700Schasingluluworkaround_reset_start cortex_x2, ERRATUM(2371105), ERRATA_X2_2371105 115*91f16700Schasinglulu /* Set bit 40 in CPUACTLR2_EL1 */ 116*91f16700Schasinglulu sysreg_bit_set CORTEX_X2_CPUACTLR2_EL1, CORTEX_X2_CPUACTLR2_EL1_BIT_40 117*91f16700Schasingluluworkaround_reset_end cortex_x2, ERRATUM(2371105) 118*91f16700Schasinglulu 119*91f16700Schasinglulucheck_erratum_ls cortex_x2, ERRATUM(2371105), CPU_REV(2, 0) 120*91f16700Schasinglulu 121*91f16700Schasingluluworkaround_reset_start cortex_x2, ERRATUM(2742423), ERRATA_X2_2742423 122*91f16700Schasinglulu /* Set CPUACTLR5_EL1[56:55] to 2'b01 */ 123*91f16700Schasinglulu sysreg_bit_set CORTEX_X2_CPUACTLR5_EL1, BIT(55) 124*91f16700Schasinglulu sysreg_bit_clear CORTEX_X2_CPUACTLR5_EL1, BIT(56) 125*91f16700Schasingluluworkaround_reset_end cortex_x2, ERRATUM(2742423) 126*91f16700Schasinglulu 127*91f16700Schasinglulucheck_erratum_ls cortex_x2, ERRATUM(2742423), CPU_REV(2, 1) 128*91f16700Schasinglulu 129*91f16700Schasingluluworkaround_reset_start cortex_x2, ERRATUM(2768515), ERRATA_X2_2768515 130*91f16700Schasinglulu /* dsb before isb of power down sequence */ 131*91f16700Schasinglulu dsb sy 132*91f16700Schasingluluworkaround_reset_end cortex_x2, ERRATUM(2768515) 133*91f16700Schasinglulu 134*91f16700Schasinglulucheck_erratum_ls cortex_x2, ERRATUM(2768515), CPU_REV(2, 1) 135*91f16700Schasinglulu 136*91f16700Schasingluluworkaround_reset_start cortex_x2, CVE(2022, 23960), WORKAROUND_CVE_2022_23960 137*91f16700Schasinglulu#if IMAGE_BL31 138*91f16700Schasinglulu /* 139*91f16700Schasinglulu * The Cortex-X2 generic vectors are overridden to apply errata 140*91f16700Schasinglulu * mitigation on exception entry from lower ELs. 141*91f16700Schasinglulu */ 142*91f16700Schasinglulu override_vector_table wa_cve_vbar_cortex_x2 143*91f16700Schasinglulu#endif /* IMAGE_BL31 */ 144*91f16700Schasingluluworkaround_reset_end cortex_x2, CVE(2022, 23960) 145*91f16700Schasinglulu 146*91f16700Schasinglulucheck_erratum_chosen cortex_x2, CVE(2022, 23960), WORKAROUND_CVE_2022_23960 147*91f16700Schasinglulu 148*91f16700Schasinglulu/* 149*91f16700Schasinglulu * ERRATA_DSU_2313941 : 150*91f16700Schasinglulu * The errata is defined in dsu_helpers.S but applies to cortex_x2 151*91f16700Schasinglulu * as well. Henceforth creating symbolic names to the already existing errata 152*91f16700Schasinglulu * workaround functions to get them registered under the Errata Framework. 153*91f16700Schasinglulu */ 154*91f16700Schasinglulu.equ check_erratum_cortex_x2_2313941, check_errata_dsu_2313941 155*91f16700Schasinglulu.equ erratum_cortex_x2_2313941_wa, errata_dsu_2313941_wa 156*91f16700Schasingluluadd_erratum_entry cortex_x2, ERRATUM(2313941), ERRATA_DSU_2313941, APPLY_AT_RESET 157*91f16700Schasinglulu 158*91f16700Schasinglulu /* ---------------------------------------------------- 159*91f16700Schasinglulu * HW will do the cache maintenance while powering down 160*91f16700Schasinglulu * ---------------------------------------------------- 161*91f16700Schasinglulu */ 162*91f16700Schasinglulufunc cortex_x2_core_pwr_dwn 163*91f16700Schasinglulu /* --------------------------------------------------- 164*91f16700Schasinglulu * Enable CPU power down bit in power control register 165*91f16700Schasinglulu * --------------------------------------------------- 166*91f16700Schasinglulu */ 167*91f16700Schasinglulu sysreg_bit_set CORTEX_X2_CPUPWRCTLR_EL1, CORTEX_X2_CPUPWRCTLR_EL1_CORE_PWRDN_BIT 168*91f16700Schasinglulu 169*91f16700Schasinglulu#if ERRATA_X2_2768515 170*91f16700Schasinglulu mov x15, x30 171*91f16700Schasinglulu bl cpu_get_rev_var 172*91f16700Schasinglulu bl erratum_cortex_x2_2768515_wa 173*91f16700Schasinglulu mov x30, x15 174*91f16700Schasinglulu#endif /* ERRATA_X2_2768515 */ 175*91f16700Schasinglulu isb 176*91f16700Schasinglulu ret 177*91f16700Schasingluluendfunc cortex_x2_core_pwr_dwn 178*91f16700Schasinglulu 179*91f16700Schasingluluerrata_report_shim cortex_x2 180*91f16700Schasinglulu 181*91f16700Schasinglulucpu_reset_func_start cortex_x2 182*91f16700Schasinglulu /* Disable speculative loads */ 183*91f16700Schasinglulu msr SSBS, xzr 184*91f16700Schasinglulucpu_reset_func_end cortex_x2 185*91f16700Schasinglulu 186*91f16700Schasinglulu /* --------------------------------------------- 187*91f16700Schasinglulu * This function provides Cortex X2 specific 188*91f16700Schasinglulu * register information for crash reporting. 189*91f16700Schasinglulu * It needs to return with x6 pointing to 190*91f16700Schasinglulu * a list of register names in ascii and 191*91f16700Schasinglulu * x8 - x15 having values of registers to be 192*91f16700Schasinglulu * reported. 193*91f16700Schasinglulu * --------------------------------------------- 194*91f16700Schasinglulu */ 195*91f16700Schasinglulu.section .rodata.cortex_x2_regs, "aS" 196*91f16700Schasinglulucortex_x2_regs: /* The ascii list of register names to be reported */ 197*91f16700Schasinglulu .asciz "cpuectlr_el1", "" 198*91f16700Schasinglulu 199*91f16700Schasinglulufunc cortex_x2_cpu_reg_dump 200*91f16700Schasinglulu adr x6, cortex_x2_regs 201*91f16700Schasinglulu mrs x8, CORTEX_X2_CPUECTLR_EL1 202*91f16700Schasinglulu ret 203*91f16700Schasingluluendfunc cortex_x2_cpu_reg_dump 204*91f16700Schasinglulu 205*91f16700Schasingluludeclare_cpu_ops cortex_x2, CORTEX_X2_MIDR, \ 206*91f16700Schasinglulu cortex_x2_reset_func, \ 207*91f16700Schasinglulu cortex_x2_core_pwr_dwn 208