1/* 2 * Copyright (c) 2021-2022, 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_x3.h> 11#include <cpu_macros.S> 12#include <plat_macros.S> 13#include "wa_cve_2022_23960_bhb_vector.S" 14 15/* Hardware handled coherency */ 16#if HW_ASSISTED_COHERENCY == 0 17#error "Cortex-X3 must be compiled with HW_ASSISTED_COHERENCY enabled" 18#endif 19 20/* 64-bit only core */ 21#if CTX_INCLUDE_AARCH32_REGS == 1 22#error "Cortex-X3 supports only AArch64. Compile with CTX_INCLUDE_AARCH32_REGS=0" 23#endif 24 25#if WORKAROUND_CVE_2022_23960 26 wa_cve_2022_23960_bhb_vector_table CORTEX_X3_BHB_LOOP_COUNT, cortex_x3 27#endif /* WORKAROUND_CVE_2022_23960 */ 28 29 /* ---------------------------------------------------- 30 * HW will do the cache maintenance while powering down 31 * ---------------------------------------------------- 32 */ 33func cortex_x3_core_pwr_dwn 34#if ERRATA_X3_2313909 35 mov x15, x30 36 bl cpu_get_rev_var 37 bl errata_cortex_x3_2313909_wa 38 mov x30, x15 39#endif /* ERRATA_X3_2313909 */ 40 41 /* --------------------------------------------------- 42 * Enable CPU power down bit in power control register 43 * --------------------------------------------------- 44 */ 45 mrs x0, CORTEX_X3_CPUPWRCTLR_EL1 46 orr x0, x0, #CORTEX_X3_CPUPWRCTLR_EL1_CORE_PWRDN_BIT 47 msr CORTEX_X3_CPUPWRCTLR_EL1, x0 48 isb 49 ret 50endfunc cortex_x3_core_pwr_dwn 51 52func check_errata_cve_2022_23960 53#if WORKAROUND_CVE_2022_23960 54 mov x0, #ERRATA_APPLIES 55#else 56 mov x0, #ERRATA_MISSING 57#endif 58 ret 59endfunc check_errata_cve_2022_23960 60 61func cortex_x3_reset_func 62 mov x19, x30 63 /* Disable speculative loads */ 64 msr SSBS, xzr 65 66#if IMAGE_BL31 && WORKAROUND_CVE_2022_23960 67 /* 68 * The Cortex-X3 generic vectors are overridden to apply 69 * errata mitigation on exception entry from lower ELs. 70 */ 71 adr x0, wa_cve_vbar_cortex_x3 72 msr vbar_el3, x0 73#endif /* IMAGE_BL31 && WORKAROUND_CVE_2022_23960 */ 74 75 bl cpu_get_rev_var 76 77#if ERRATA_X3_2615812 78 bl errata_cortex_x3_2615812_wa 79#endif /* ERRATA_X3_2615812 */ 80 81 isb 82 ret x19 83endfunc cortex_x3_reset_func 84 85/* ---------------------------------------------------------------------- 86 * Errata Workaround for Cortex-X3 Erratum 2313909 on power down request. 87 * This applies to revision r0p0 and r1p0 of Cortex-X3. Fixed in r1p1. 88 * Inputs: 89 * x0: variant[4:7] and revision[0:3] of current cpu. 90 * Shall clobber: x0-x1, x17 91 * ---------------------------------------------------------------------- 92 */ 93func errata_cortex_x3_2313909_wa 94 /* Check revision. */ 95 mov x17, x30 96 bl check_errata_2313909 97 cbz x0, 1f 98 99 /* Set bit 36 in ACTLR2_EL1 */ 100 mrs x1, CORTEX_X3_CPUACTLR2_EL1 101 orr x1, x1, #CORTEX_X3_CPUACTLR2_EL1_BIT_36 102 msr CORTEX_X3_CPUACTLR2_EL1, x1 1031: 104 ret x17 105endfunc errata_cortex_x3_2313909_wa 106 107func check_errata_2313909 108 /* Applies to r0p0 and r1p0 */ 109 mov x1, #0x10 110 b cpu_rev_var_ls 111endfunc check_errata_2313909 112 113/* ---------------------------------------------------------------------- 114 * Errata Workaround for Cortex-X3 Erratum 2615812 on power-on. 115 * This applies to revision r0p0, r1p0, r1p1 of Cortex-X3. Open. 116 * Inputs: 117 * x0: variant[4:7] and revision[0:3] of current cpu. 118 * Shall clobber: x0-x1, x17 119 * ---------------------------------------------------------------------- 120 */ 121func errata_cortex_x3_2615812_wa 122 /* Check revision. */ 123 mov x17, x30 124 bl check_errata_2615812 125 cbz x0, 1f 126 127 /* Disable retention control for WFI and WFE. */ 128 mrs x0, CORTEX_X3_CPUPWRCTLR_EL1 129 bfi x0, xzr, #CORTEX_X3_CPUPWRCTLR_EL1_WFI_RET_CTRL_BITS_SHIFT, #3 130 bfi x0, xzr, #CORTEX_X3_CPUPWRCTLR_EL1_WFE_RET_CTRL_BITS_SHIFT, #3 131 msr CORTEX_X3_CPUPWRCTLR_EL1, x0 1321: 133 ret x17 134endfunc errata_cortex_x3_2615812_wa 135 136func check_errata_2615812 137 /* Applies to r1p1 and below. */ 138 mov x1, #0x11 139 b cpu_rev_var_ls 140endfunc check_errata_2615812 141 142#if REPORT_ERRATA 143 /* 144 * Errata printing function for Cortex-X3. Must follow AAPCS. 145 */ 146func cortex_x3_errata_report 147 stp x8, x30, [sp, #-16]! 148 149 bl cpu_get_rev_var 150 mov x8, x0 151 152 /* 153 * Report all errata. The revision-variant information is passed to 154 * checking functions of each errata. 155 */ 156 report_errata ERRATA_X3_2313909, cortex_x3, 2313909 157 report_errata ERRATA_X3_2615812, cortex_x3, 2615812 158 report_errata WORKAROUND_CVE_2022_23960, cortex_x3, cve_2022_23960 159 160 ldp x8, x30, [sp], #16 161 ret 162endfunc cortex_x3_errata_report 163#endif 164 165 /* --------------------------------------------- 166 * This function provides Cortex-X3- 167 * specific register information for crash 168 * reporting. It needs to return with x6 169 * pointing to a list of register names in ascii 170 * and x8 - x15 having values of registers to be 171 * reported. 172 * --------------------------------------------- 173 */ 174.section .rodata.cortex_x3_regs, "aS" 175cortex_x3_regs: /* The ascii list of register names to be reported */ 176 .asciz "cpuectlr_el1", "" 177 178func cortex_x3_cpu_reg_dump 179 adr x6, cortex_x3_regs 180 mrs x8, CORTEX_X3_CPUECTLR_EL1 181 ret 182endfunc cortex_x3_cpu_reg_dump 183 184declare_cpu_ops cortex_x3, CORTEX_X3_MIDR, \ 185 cortex_x3_reset_func, \ 186 cortex_x3_core_pwr_dwn 187