19b476841SSoby Mathew/* 242d4d3baSArvind Ram Prakash * Copyright (c) 2014-2023, Arm Limited and Contributors. All rights reserved. 39b476841SSoby Mathew * 482cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause 59b476841SSoby Mathew */ 69b476841SSoby Mathew 79b476841SSoby Mathew#include <arch.h> 89b476841SSoby Mathew#include <asm_macros.S> 99b476841SSoby Mathew#include <assert_macros.S> 10c2ad38ceSVarun Wadekar#include <common/bl_common.h> 1109d40e0eSAntonio Nino Diaz#include <common/debug.h> 1255c70cb7SDavid Cunado#include <cpu_macros.S> 13007433d8SBoyan Karatotev#include <lib/cpus/cpu_ops.h> 146bb96fa6SBoyan Karatotev#include <lib/cpus/errata.h> 1509d40e0eSAntonio Nino Diaz#include <lib/el3_runtime/cpu_data.h> 169b476841SSoby Mathew 179b476841SSoby Mathew /* Reset fn is needed in BL at reset vector */ 1842d4d3baSArvind Ram Prakash#if defined(IMAGE_BL1) || defined(IMAGE_BL31) || \ 1942d4d3baSArvind Ram Prakash (defined(IMAGE_BL2) && RESET_TO_BL2) 209b476841SSoby Mathew /* 219b476841SSoby Mathew * The reset handler common to all platforms. After a matching 229b476841SSoby Mathew * cpu_ops structure entry is found, the correponding reset_handler 239b476841SSoby Mathew * in the cpu_ops is invoked. 24683f788fSSoby Mathew * Clobbers: x0 - x19, x30 259b476841SSoby Mathew */ 269b476841SSoby Mathew .globl reset_handler 279b476841SSoby Mathewfunc reset_handler 287395a725SSoby Mathew mov x19, x30 299b476841SSoby Mathew 30683f788fSSoby Mathew /* The plat_reset_handler can clobber x0 - x18, x30 */ 3124fb838fSSoby Mathew bl plat_reset_handler 3224fb838fSSoby Mathew 339b476841SSoby Mathew /* Get the matching cpu_ops pointer */ 349b476841SSoby Mathew bl get_cpu_ops_ptr 359b476841SSoby Mathew 36*3f721c6eSThaddeus Serna#if ENABLE_ASSERTIONS 37*3f721c6eSThaddeus Serna /* 38*3f721c6eSThaddeus Serna * Assert if invalid cpu_ops obtained. If this is not valid, it may 39*3f721c6eSThaddeus Serna * suggest that the proper CPU file hasn't been included. 40*3f721c6eSThaddeus Serna */ 41*3f721c6eSThaddeus Serna cmp x0, #0 42*3f721c6eSThaddeus Serna ASM_ASSERT(ne) 43*3f721c6eSThaddeus Serna#endif 44*3f721c6eSThaddeus Serna 459b476841SSoby Mathew /* Get the cpu_ops reset handler */ 469b476841SSoby Mathew ldr x2, [x0, #CPU_RESET_FUNC] 477395a725SSoby Mathew mov x30, x19 489b476841SSoby Mathew cbz x2, 1f 49683f788fSSoby Mathew 50683f788fSSoby Mathew /* The cpu_ops reset handler can clobber x0 - x19, x30 */ 517395a725SSoby Mathew br x2 529b476841SSoby Mathew1: 537395a725SSoby Mathew ret 548b779620SKévin Petitendfunc reset_handler 5524fb838fSSoby Mathew 56b1d27b48SRoberto Vargas#endif 579b476841SSoby Mathew 583d8256b2SMasahiro Yamada#ifdef IMAGE_BL31 /* The power down core and cluster is needed only in BL31 */ 59add40351SSoby Mathew /* 605dd9dbb5SJeenu Viswambharan * void prepare_cpu_pwr_dwn(unsigned int power_level) 615dd9dbb5SJeenu Viswambharan * 625dd9dbb5SJeenu Viswambharan * Prepare CPU power down function for all platforms. The function takes 635dd9dbb5SJeenu Viswambharan * a domain level to be powered down as its parameter. After the cpu_ops 645dd9dbb5SJeenu Viswambharan * pointer is retrieved from cpu_data, the handler for requested power 655dd9dbb5SJeenu Viswambharan * level is called. 66add40351SSoby Mathew */ 675dd9dbb5SJeenu Viswambharan .globl prepare_cpu_pwr_dwn 685dd9dbb5SJeenu Viswambharanfunc prepare_cpu_pwr_dwn 69add40351SSoby Mathew /* 705dd9dbb5SJeenu Viswambharan * If the given power level exceeds CPU_MAX_PWR_DWN_OPS, we call the 715dd9dbb5SJeenu Viswambharan * power down handler for the last power level 72add40351SSoby Mathew */ 735dd9dbb5SJeenu Viswambharan mov_imm x2, (CPU_MAX_PWR_DWN_OPS - 1) 745dd9dbb5SJeenu Viswambharan cmp x0, x2 755dd9dbb5SJeenu Viswambharan csel x2, x2, x0, hi 765dd9dbb5SJeenu Viswambharan 77add40351SSoby Mathew mrs x1, tpidr_el3 78add40351SSoby Mathew ldr x0, [x1, #CPU_DATA_CPU_OPS_PTR] 79044bb2faSAntonio Nino Diaz#if ENABLE_ASSERTIONS 80add40351SSoby Mathew cmp x0, #0 81add40351SSoby Mathew ASM_ASSERT(ne) 82add40351SSoby Mathew#endif 83add40351SSoby Mathew 845dd9dbb5SJeenu Viswambharan /* Get the appropriate power down handler */ 855dd9dbb5SJeenu Viswambharan mov x1, #CPU_PWR_DWN_OPS 865dd9dbb5SJeenu Viswambharan add x1, x1, x2, lsl #3 875dd9dbb5SJeenu Viswambharan ldr x1, [x0, x1] 88601e3ed2SVarun Wadekar#if ENABLE_ASSERTIONS 89601e3ed2SVarun Wadekar cmp x1, #0 90601e3ed2SVarun Wadekar ASM_ASSERT(ne) 91601e3ed2SVarun Wadekar#endif 92add40351SSoby Mathew br x1 935dd9dbb5SJeenu Viswambharanendfunc prepare_cpu_pwr_dwn 94add40351SSoby Mathew 95add40351SSoby Mathew 96add40351SSoby Mathew /* 97add40351SSoby Mathew * Initializes the cpu_ops_ptr if not already initialized 9812e7c4abSVikram Kanigiri * in cpu_data. This can be called without a runtime stack, but may 9912e7c4abSVikram Kanigiri * only be called after the MMU is enabled. 100add40351SSoby Mathew * clobbers: x0 - x6, x10 101add40351SSoby Mathew */ 102add40351SSoby Mathew .globl init_cpu_ops 103add40351SSoby Mathewfunc init_cpu_ops 104add40351SSoby Mathew mrs x6, tpidr_el3 105add40351SSoby Mathew ldr x0, [x6, #CPU_DATA_CPU_OPS_PTR] 106add40351SSoby Mathew cbnz x0, 1f 107add40351SSoby Mathew mov x10, x30 108add40351SSoby Mathew bl get_cpu_ops_ptr 10909997346SSoby Mathew str x0, [x6, #CPU_DATA_CPU_OPS_PTR]! 110add40351SSoby Mathew mov x30, x10 111add40351SSoby Mathew1: 112add40351SSoby Mathew ret 1138b779620SKévin Petitendfunc init_cpu_ops 114add40351SSoby Mathew#endif /* IMAGE_BL31 */ 115add40351SSoby Mathew 1163d8256b2SMasahiro Yamada#if defined(IMAGE_BL31) && CRASH_REPORTING 117d3f70af6SSoby Mathew /* 118d3f70af6SSoby Mathew * The cpu specific registers which need to be reported in a crash 119d3f70af6SSoby Mathew * are reported via cpu_ops cpu_reg_dump function. After a matching 120d3f70af6SSoby Mathew * cpu_ops structure entry is found, the correponding cpu_reg_dump 121d3f70af6SSoby Mathew * in the cpu_ops is invoked. 122d3f70af6SSoby Mathew */ 123d3f70af6SSoby Mathew .globl do_cpu_reg_dump 124d3f70af6SSoby Mathewfunc do_cpu_reg_dump 125d3f70af6SSoby Mathew mov x16, x30 126d3f70af6SSoby Mathew 127d3f70af6SSoby Mathew /* Get the matching cpu_ops pointer */ 128d3f70af6SSoby Mathew bl get_cpu_ops_ptr 129d3f70af6SSoby Mathew cbz x0, 1f 130d3f70af6SSoby Mathew 131d3f70af6SSoby Mathew /* Get the cpu_ops cpu_reg_dump */ 132d3f70af6SSoby Mathew ldr x2, [x0, #CPU_REG_DUMP] 133d3f70af6SSoby Mathew cbz x2, 1f 134d3f70af6SSoby Mathew blr x2 135d3f70af6SSoby Mathew1: 136d3f70af6SSoby Mathew mov x30, x16 137d3f70af6SSoby Mathew ret 1388b779620SKévin Petitendfunc do_cpu_reg_dump 139d3f70af6SSoby Mathew#endif 140d3f70af6SSoby Mathew 1419b476841SSoby Mathew /* 1429b476841SSoby Mathew * The below function returns the cpu_ops structure matching the 1439b476841SSoby Mathew * midr of the core. It reads the MIDR_EL1 and finds the matching 1449b476841SSoby Mathew * entry in cpu_ops entries. Only the implementation and part number 1459b476841SSoby Mathew * are used to match the entries. 1461994e562SJavier Almansa Sobrino * 1471994e562SJavier Almansa Sobrino * If cpu_ops for the MIDR_EL1 cannot be found and 1481994e562SJavier Almansa Sobrino * SUPPORT_UNKNOWN_MPID is enabled, it will try to look for a 1491994e562SJavier Almansa Sobrino * default cpu_ops with an MIDR value of 0. 1502e61d687SOlivier Deprez * (Implementation number 0x0 should be reserved for software use 1511994e562SJavier Almansa Sobrino * and therefore no clashes should happen with that default value). 1521994e562SJavier Almansa Sobrino * 1539b476841SSoby Mathew * Return : 1549b476841SSoby Mathew * x0 - The matching cpu_ops pointer on Success 1559b476841SSoby Mathew * x0 - 0 on failure. 1569b476841SSoby Mathew * Clobbers : x0 - x5 1579b476841SSoby Mathew */ 1589b476841SSoby Mathew .globl get_cpu_ops_ptr 1599b476841SSoby Mathewfunc get_cpu_ops_ptr 1609b476841SSoby Mathew /* Read the MIDR_EL1 */ 1619b476841SSoby Mathew mrs x2, midr_el1 1629b476841SSoby Mathew mov_imm x3, CPU_IMPL_PN_MASK 1639b476841SSoby Mathew 1649b476841SSoby Mathew /* Retain only the implementation and part number using mask */ 1659b476841SSoby Mathew and w2, w2, w3 1661994e562SJavier Almansa Sobrino 1671994e562SJavier Almansa Sobrino /* Get the cpu_ops end location */ 1681994e562SJavier Almansa Sobrino adr x5, (__CPU_OPS_END__ + CPU_MIDR) 1691994e562SJavier Almansa Sobrino 1701994e562SJavier Almansa Sobrino /* Initialize the return parameter */ 1711994e562SJavier Almansa Sobrino mov x0, #0 1729b476841SSoby Mathew1: 1731994e562SJavier Almansa Sobrino /* Get the cpu_ops start location */ 1741994e562SJavier Almansa Sobrino adr x4, (__CPU_OPS_START__ + CPU_MIDR) 1751994e562SJavier Almansa Sobrino 1761994e562SJavier Almansa Sobrino2: 1779b476841SSoby Mathew /* Check if we have reached end of list */ 1789b476841SSoby Mathew cmp x4, x5 1791994e562SJavier Almansa Sobrino b.eq search_def_ptr 1809b476841SSoby Mathew 1819b476841SSoby Mathew /* load the midr from the cpu_ops */ 1829b476841SSoby Mathew ldr x1, [x4], #CPU_OPS_SIZE 1839b476841SSoby Mathew and w1, w1, w3 1849b476841SSoby Mathew 1859b476841SSoby Mathew /* Check if midr matches to midr of this core */ 1869b476841SSoby Mathew cmp w1, w2 1871994e562SJavier Almansa Sobrino b.ne 2b 1889b476841SSoby Mathew 1899b476841SSoby Mathew /* Subtract the increment and offset to get the cpu-ops pointer */ 1909b476841SSoby Mathew sub x0, x4, #(CPU_OPS_SIZE + CPU_MIDR) 191601e3ed2SVarun Wadekar#if ENABLE_ASSERTIONS 192601e3ed2SVarun Wadekar cmp x0, #0 193601e3ed2SVarun Wadekar ASM_ASSERT(ne) 194601e3ed2SVarun Wadekar#endif 1951994e562SJavier Almansa Sobrino#ifdef SUPPORT_UNKNOWN_MPID 1961994e562SJavier Almansa Sobrino cbnz x2, exit_mpid_found 1971994e562SJavier Almansa Sobrino /* Mark the unsupported MPID flag */ 1981994e562SJavier Almansa Sobrino adrp x1, unsupported_mpid_flag 1991994e562SJavier Almansa Sobrino add x1, x1, :lo12:unsupported_mpid_flag 2001994e562SJavier Almansa Sobrino str w2, [x1] 2011994e562SJavier Almansa Sobrinoexit_mpid_found: 2021994e562SJavier Almansa Sobrino#endif 2031994e562SJavier Almansa Sobrino ret 2041994e562SJavier Almansa Sobrino 2051994e562SJavier Almansa Sobrino /* 2061994e562SJavier Almansa Sobrino * Search again for a default pointer (MIDR = 0x0) 2071994e562SJavier Almansa Sobrino * or return error if already searched. 2081994e562SJavier Almansa Sobrino */ 2091994e562SJavier Almansa Sobrinosearch_def_ptr: 2101994e562SJavier Almansa Sobrino#ifdef SUPPORT_UNKNOWN_MPID 2111994e562SJavier Almansa Sobrino cbz x2, error_exit 2121994e562SJavier Almansa Sobrino mov x2, #0 2131994e562SJavier Almansa Sobrino b 1b 2149b476841SSoby Mathewerror_exit: 2151994e562SJavier Almansa Sobrino#endif 2169b476841SSoby Mathew ret 2178b779620SKévin Petitendfunc get_cpu_ops_ptr 2187395a725SSoby Mathew 21910bcd761SJeenu Viswambharan/* 22010bcd761SJeenu Viswambharan * Extract CPU revision and variant, and combine them into a single numeric for 22110bcd761SJeenu Viswambharan * easier comparison. 22210bcd761SJeenu Viswambharan */ 22310bcd761SJeenu Viswambharan .globl cpu_get_rev_var 22410bcd761SJeenu Viswambharanfunc cpu_get_rev_var 22510bcd761SJeenu Viswambharan mrs x1, midr_el1 2267395a725SSoby Mathew 22754035fc4SSandrine Bailleux /* 22810bcd761SJeenu Viswambharan * Extract the variant[23:20] and revision[3:0] from MIDR, and pack them 22910bcd761SJeenu Viswambharan * as variant[7:4] and revision[3:0] of x0. 23054035fc4SSandrine Bailleux * 23110bcd761SJeenu Viswambharan * First extract x1[23:16] to x0[7:0] and zero fill the rest. Then 23210bcd761SJeenu Viswambharan * extract x1[3:0] into x0[3:0] retaining other bits. 23354035fc4SSandrine Bailleux */ 23410bcd761SJeenu Viswambharan ubfx x0, x1, #(MIDR_VAR_SHIFT - MIDR_REV_BITS), #(MIDR_REV_BITS + MIDR_VAR_BITS) 23510bcd761SJeenu Viswambharan bfxil x0, x1, #MIDR_REV_SHIFT, #MIDR_REV_BITS 23610bcd761SJeenu Viswambharan ret 23710bcd761SJeenu Viswambharanendfunc cpu_get_rev_var 2387395a725SSoby Mathew 23910bcd761SJeenu Viswambharan/* 24010bcd761SJeenu Viswambharan * Compare the CPU's revision-variant (x0) with a given value (x1), for errata 24110bcd761SJeenu Viswambharan * application purposes. If the revision-variant is less than or same as a given 24210bcd761SJeenu Viswambharan * value, indicates that errata applies; otherwise not. 2439ec3921cSJonathan Wright * 2449ec3921cSJonathan Wright * Shall clobber: x0-x3 24510bcd761SJeenu Viswambharan */ 24610bcd761SJeenu Viswambharan .globl cpu_rev_var_ls 24710bcd761SJeenu Viswambharanfunc cpu_rev_var_ls 24810bcd761SJeenu Viswambharan mov x2, #ERRATA_APPLIES 24910bcd761SJeenu Viswambharan mov x3, #ERRATA_NOT_APPLIES 25010bcd761SJeenu Viswambharan cmp x0, x1 25110bcd761SJeenu Viswambharan csel x0, x2, x3, ls 25210bcd761SJeenu Viswambharan ret 25310bcd761SJeenu Viswambharanendfunc cpu_rev_var_ls 25410bcd761SJeenu Viswambharan 255b75dc0e4SAndre Przywara/* 256b75dc0e4SAndre Przywara * Compare the CPU's revision-variant (x0) with a given value (x1), for errata 257b75dc0e4SAndre Przywara * application purposes. If the revision-variant is higher than or same as a 258b75dc0e4SAndre Przywara * given value, indicates that errata applies; otherwise not. 2599ec3921cSJonathan Wright * 2609ec3921cSJonathan Wright * Shall clobber: x0-x3 261b75dc0e4SAndre Przywara */ 262b75dc0e4SAndre Przywara .globl cpu_rev_var_hs 263b75dc0e4SAndre Przywarafunc cpu_rev_var_hs 264b75dc0e4SAndre Przywara mov x2, #ERRATA_APPLIES 265b75dc0e4SAndre Przywara mov x3, #ERRATA_NOT_APPLIES 266b75dc0e4SAndre Przywara cmp x0, x1 267b75dc0e4SAndre Przywara csel x0, x2, x3, hs 268b75dc0e4SAndre Przywara ret 269b75dc0e4SAndre Przywaraendfunc cpu_rev_var_hs 270b75dc0e4SAndre Przywara 27180942622Slaurenw-arm/* 27280942622Slaurenw-arm * Compare the CPU's revision-variant (x0) with a given range (x1 - x2), for errata 27380942622Slaurenw-arm * application purposes. If the revision-variant is between or includes the given 27480942622Slaurenw-arm * values, this indicates that errata applies; otherwise not. 27580942622Slaurenw-arm * 27680942622Slaurenw-arm * Shall clobber: x0-x4 27780942622Slaurenw-arm */ 27880942622Slaurenw-arm .globl cpu_rev_var_range 27980942622Slaurenw-armfunc cpu_rev_var_range 28080942622Slaurenw-arm mov x3, #ERRATA_APPLIES 28180942622Slaurenw-arm mov x4, #ERRATA_NOT_APPLIES 28280942622Slaurenw-arm cmp x0, x1 28380942622Slaurenw-arm csel x1, x3, x4, hs 28480942622Slaurenw-arm cbz x1, 1f 28580942622Slaurenw-arm cmp x0, x2 28680942622Slaurenw-arm csel x1, x3, x4, ls 28780942622Slaurenw-arm1: 28880942622Slaurenw-arm mov x0, x1 28980942622Slaurenw-arm ret 29080942622Slaurenw-armendfunc cpu_rev_var_range 29180942622Slaurenw-arm 292a205a56eSDimitris Papastamos/* 2932c3a1078SDimitris Papastamos * int check_wa_cve_2017_5715(void); 294a205a56eSDimitris Papastamos * 295a205a56eSDimitris Papastamos * This function returns: 296a205a56eSDimitris Papastamos * - ERRATA_APPLIES when firmware mitigation is required. 297a205a56eSDimitris Papastamos * - ERRATA_NOT_APPLIES when firmware mitigation is _not_ required. 298a205a56eSDimitris Papastamos * - ERRATA_MISSING when firmware mitigation would be required but 299a205a56eSDimitris Papastamos * is not compiled in. 300a205a56eSDimitris Papastamos * 301a205a56eSDimitris Papastamos * NOTE: Must be called only after cpu_ops have been initialized 302a205a56eSDimitris Papastamos * in per-CPU data. 303a205a56eSDimitris Papastamos */ 3042c3a1078SDimitris Papastamos .globl check_wa_cve_2017_5715 3052c3a1078SDimitris Papastamosfunc check_wa_cve_2017_5715 306a205a56eSDimitris Papastamos mrs x0, tpidr_el3 307a205a56eSDimitris Papastamos#if ENABLE_ASSERTIONS 308a205a56eSDimitris Papastamos cmp x0, #0 309a205a56eSDimitris Papastamos ASM_ASSERT(ne) 310a205a56eSDimitris Papastamos#endif 311a205a56eSDimitris Papastamos ldr x0, [x0, #CPU_DATA_CPU_OPS_PTR] 312601e3ed2SVarun Wadekar#if ENABLE_ASSERTIONS 313601e3ed2SVarun Wadekar cmp x0, #0 314601e3ed2SVarun Wadekar ASM_ASSERT(ne) 315601e3ed2SVarun Wadekar#endif 316a205a56eSDimitris Papastamos ldr x0, [x0, #CPU_EXTRA1_FUNC] 317a205a56eSDimitris Papastamos /* 318a205a56eSDimitris Papastamos * If the reserved function pointer is NULL, this CPU 319a205a56eSDimitris Papastamos * is unaffected by CVE-2017-5715 so bail out. 320a205a56eSDimitris Papastamos */ 3219b2510b6SBipin Ravi cmp x0, #CPU_NO_EXTRA1_FUNC 322a205a56eSDimitris Papastamos beq 1f 323a205a56eSDimitris Papastamos br x0 324a205a56eSDimitris Papastamos1: 325a205a56eSDimitris Papastamos mov x0, #ERRATA_NOT_APPLIES 326a205a56eSDimitris Papastamos ret 3272c3a1078SDimitris Papastamosendfunc check_wa_cve_2017_5715 328fe007b2eSDimitris Papastamos 329fe007b2eSDimitris Papastamos/* 330fe007b2eSDimitris Papastamos * void *wa_cve_2018_3639_get_disable_ptr(void); 331fe007b2eSDimitris Papastamos * 332fe007b2eSDimitris Papastamos * Returns a function pointer which is used to disable mitigation 333fe007b2eSDimitris Papastamos * for CVE-2018-3639. 334fe007b2eSDimitris Papastamos * The function pointer is only returned on cores that employ 335fe007b2eSDimitris Papastamos * dynamic mitigation. If the core uses static mitigation or is 336fe007b2eSDimitris Papastamos * unaffected by CVE-2018-3639 this function returns NULL. 337fe007b2eSDimitris Papastamos * 338fe007b2eSDimitris Papastamos * NOTE: Must be called only after cpu_ops have been initialized 339fe007b2eSDimitris Papastamos * in per-CPU data. 340fe007b2eSDimitris Papastamos */ 341fe007b2eSDimitris Papastamos .globl wa_cve_2018_3639_get_disable_ptr 342fe007b2eSDimitris Papastamosfunc wa_cve_2018_3639_get_disable_ptr 343fe007b2eSDimitris Papastamos mrs x0, tpidr_el3 344fe007b2eSDimitris Papastamos#if ENABLE_ASSERTIONS 345fe007b2eSDimitris Papastamos cmp x0, #0 346fe007b2eSDimitris Papastamos ASM_ASSERT(ne) 347fe007b2eSDimitris Papastamos#endif 348fe007b2eSDimitris Papastamos ldr x0, [x0, #CPU_DATA_CPU_OPS_PTR] 349601e3ed2SVarun Wadekar#if ENABLE_ASSERTIONS 350601e3ed2SVarun Wadekar cmp x0, #0 351601e3ed2SVarun Wadekar ASM_ASSERT(ne) 352601e3ed2SVarun Wadekar#endif 353fe007b2eSDimitris Papastamos ldr x0, [x0, #CPU_EXTRA2_FUNC] 354fe007b2eSDimitris Papastamos ret 355fe007b2eSDimitris Papastamosendfunc wa_cve_2018_3639_get_disable_ptr 3569b2510b6SBipin Ravi 3579b2510b6SBipin Ravi/* 3589b2510b6SBipin Ravi * int check_smccc_arch_wa3_applies(void); 3599b2510b6SBipin Ravi * 3609b2510b6SBipin Ravi * This function checks whether SMCCC_ARCH_WORKAROUND_3 is enabled to mitigate 3619b2510b6SBipin Ravi * CVE-2022-23960 for this CPU. It returns: 3629b2510b6SBipin Ravi * - ERRATA_APPLIES when SMCCC_ARCH_WORKAROUND_3 can be invoked to mitigate 3639b2510b6SBipin Ravi * the CVE. 3649b2510b6SBipin Ravi * - ERRATA_NOT_APPLIES when SMCCC_ARCH_WORKAROUND_3 should not be invoked to 3659b2510b6SBipin Ravi * mitigate the CVE. 3669b2510b6SBipin Ravi * 3679b2510b6SBipin Ravi * NOTE: Must be called only after cpu_ops have been initialized 3689b2510b6SBipin Ravi * in per-CPU data. 3699b2510b6SBipin Ravi */ 3709b2510b6SBipin Ravi .globl check_smccc_arch_wa3_applies 3719b2510b6SBipin Ravifunc check_smccc_arch_wa3_applies 3729b2510b6SBipin Ravi mrs x0, tpidr_el3 3739b2510b6SBipin Ravi#if ENABLE_ASSERTIONS 3749b2510b6SBipin Ravi cmp x0, #0 3759b2510b6SBipin Ravi ASM_ASSERT(ne) 3769b2510b6SBipin Ravi#endif 3779b2510b6SBipin Ravi ldr x0, [x0, #CPU_DATA_CPU_OPS_PTR] 3789b2510b6SBipin Ravi#if ENABLE_ASSERTIONS 3799b2510b6SBipin Ravi cmp x0, #0 3809b2510b6SBipin Ravi ASM_ASSERT(ne) 3819b2510b6SBipin Ravi#endif 3829b2510b6SBipin Ravi ldr x0, [x0, #CPU_EXTRA3_FUNC] 3839b2510b6SBipin Ravi /* 3849b2510b6SBipin Ravi * If the reserved function pointer is NULL, this CPU 3859b2510b6SBipin Ravi * is unaffected by CVE-2022-23960 so bail out. 3869b2510b6SBipin Ravi */ 3879b2510b6SBipin Ravi cmp x0, #CPU_NO_EXTRA3_FUNC 3889b2510b6SBipin Ravi beq 1f 3899b2510b6SBipin Ravi br x0 3909b2510b6SBipin Ravi1: 3919b2510b6SBipin Ravi mov x0, #ERRATA_NOT_APPLIES 3929b2510b6SBipin Ravi ret 3939b2510b6SBipin Raviendfunc check_smccc_arch_wa3_applies 394