1b04ea14bSJohn Tsichritzis/* 2*1fe4a9d1SBipin Ravi * Copyright (c) 2017-2022, Arm Limited and Contributors. All rights reserved. 3b04ea14bSJohn Tsichritzis * 4b04ea14bSJohn Tsichritzis * SPDX-License-Identifier: BSD-3-Clause 5b04ea14bSJohn Tsichritzis */ 6b04ea14bSJohn Tsichritzis 7b04ea14bSJohn Tsichritzis#include <arch.h> 8b04ea14bSJohn Tsichritzis#include <asm_macros.S> 9b04ea14bSJohn Tsichritzis#include <cpuamu.h> 10b04ea14bSJohn Tsichritzis#include <cpu_macros.S> 1125bbbd2dSJavier Almansa Sobrino#include <neoverse_n1.h> 12*1fe4a9d1SBipin Ravi#include "wa_cve_2022_23960_bhb_vector.S" 13b04ea14bSJohn Tsichritzis 14076b5f02SJohn Tsichritzis/* Hardware handled coherency */ 15076b5f02SJohn Tsichritzis#if HW_ASSISTED_COHERENCY == 0 16076b5f02SJohn Tsichritzis#error "Neoverse N1 must be compiled with HW_ASSISTED_COHERENCY enabled" 17076b5f02SJohn Tsichritzis#endif 18076b5f02SJohn Tsichritzis 19629d04f5SJohn Tsichritzis/* 64-bit only core */ 20629d04f5SJohn Tsichritzis#if CTX_INCLUDE_AARCH32_REGS == 1 21629d04f5SJohn Tsichritzis#error "Neoverse-N1 supports only AArch64. Compile with CTX_INCLUDE_AARCH32_REGS=0" 22629d04f5SJohn Tsichritzis#endif 23629d04f5SJohn Tsichritzis 2480942622Slaurenw-arm .global neoverse_n1_errata_ic_trap_handler 2580942622Slaurenw-arm 26*1fe4a9d1SBipin Ravi#if WORKAROUND_CVE_2022_23960 27*1fe4a9d1SBipin Ravi wa_cve_2022_23960_bhb_vector_table NEOVERSE_N1_BHB_LOOP_COUNT, neoverse_n1 28*1fe4a9d1SBipin Ravi#endif /* WORKAROUND_CVE_2022_23960 */ 29*1fe4a9d1SBipin Ravi 30b04ea14bSJohn Tsichritzis/* -------------------------------------------------- 315f5d0763SAndre Przywara * Errata Workaround for Neoverse N1 Erratum 1043202. 32da6d75a0SJohn Tsichritzis * This applies to revision r0p0 and r1p0 of Neoverse N1. 33b04ea14bSJohn Tsichritzis * Inputs: 34b04ea14bSJohn Tsichritzis * x0: variant[4:7] and revision[0:3] of current cpu. 35b04ea14bSJohn Tsichritzis * Shall clobber: x0-x17 36b04ea14bSJohn Tsichritzis * -------------------------------------------------- 37b04ea14bSJohn Tsichritzis */ 38da6d75a0SJohn Tsichritzisfunc errata_n1_1043202_wa 39b04ea14bSJohn Tsichritzis /* Compare x0 against revision r1p0 */ 40b04ea14bSJohn Tsichritzis mov x17, x30 41b04ea14bSJohn Tsichritzis bl check_errata_1043202 42b04ea14bSJohn Tsichritzis cbz x0, 1f 43b04ea14bSJohn Tsichritzis 44b04ea14bSJohn Tsichritzis /* Apply instruction patching sequence */ 45b04ea14bSJohn Tsichritzis ldr x0, =0x0 46b04ea14bSJohn Tsichritzis msr CPUPSELR_EL3, x0 47b04ea14bSJohn Tsichritzis ldr x0, =0xF3BF8F2F 48b04ea14bSJohn Tsichritzis msr CPUPOR_EL3, x0 49b04ea14bSJohn Tsichritzis ldr x0, =0xFFFFFFFF 50b04ea14bSJohn Tsichritzis msr CPUPMR_EL3, x0 51b04ea14bSJohn Tsichritzis ldr x0, =0x800200071 52b04ea14bSJohn Tsichritzis msr CPUPCR_EL3, x0 53a33ec1e7Slaurenw-arm isb 54b04ea14bSJohn Tsichritzis1: 55b04ea14bSJohn Tsichritzis ret x17 56da6d75a0SJohn Tsichritzisendfunc errata_n1_1043202_wa 57b04ea14bSJohn Tsichritzis 58b04ea14bSJohn Tsichritzisfunc check_errata_1043202 59b04ea14bSJohn Tsichritzis /* Applies to r0p0 and r1p0 */ 60b04ea14bSJohn Tsichritzis mov x1, #0x10 61b04ea14bSJohn Tsichritzis b cpu_rev_var_ls 62b04ea14bSJohn Tsichritzisendfunc check_errata_1043202 63b04ea14bSJohn Tsichritzis 64eca6e453SSami Mujawar/* -------------------------------------------------- 65eca6e453SSami Mujawar * Disable speculative loads if Neoverse N1 supports 66eca6e453SSami Mujawar * SSBS. 67eca6e453SSami Mujawar * 68eca6e453SSami Mujawar * Shall clobber: x0. 69eca6e453SSami Mujawar * -------------------------------------------------- 70eca6e453SSami Mujawar */ 71eca6e453SSami Mujawarfunc neoverse_n1_disable_speculative_loads 72eca6e453SSami Mujawar /* Check if the PE implements SSBS */ 73eca6e453SSami Mujawar mrs x0, id_aa64pfr1_el1 74eca6e453SSami Mujawar tst x0, #(ID_AA64PFR1_EL1_SSBS_MASK << ID_AA64PFR1_EL1_SSBS_SHIFT) 75eca6e453SSami Mujawar b.eq 1f 76eca6e453SSami Mujawar 77eca6e453SSami Mujawar /* Disable speculative loads */ 78eca6e453SSami Mujawar msr SSBS, xzr 79eca6e453SSami Mujawar 80eca6e453SSami Mujawar1: 81eca6e453SSami Mujawar ret 82eca6e453SSami Mujawarendfunc neoverse_n1_disable_speculative_loads 83eca6e453SSami Mujawar 845f5d0763SAndre Przywara/* -------------------------------------------------- 85a601afe1Slauwal01 * Errata Workaround for Neoverse N1 Errata #1073348 86a601afe1Slauwal01 * This applies to revision r0p0 and r1p0 of Neoverse N1. 87a601afe1Slauwal01 * Inputs: 88a601afe1Slauwal01 * x0: variant[4:7] and revision[0:3] of current cpu. 89a601afe1Slauwal01 * Shall clobber: x0-x17 90a601afe1Slauwal01 * -------------------------------------------------- 91a601afe1Slauwal01 */ 92a601afe1Slauwal01func errata_n1_1073348_wa 93a601afe1Slauwal01 /* Compare x0 against revision r1p0 */ 94a601afe1Slauwal01 mov x17, x30 95a601afe1Slauwal01 bl check_errata_1073348 96a601afe1Slauwal01 cbz x0, 1f 97a601afe1Slauwal01 mrs x1, NEOVERSE_N1_CPUACTLR_EL1 98a601afe1Slauwal01 orr x1, x1, NEOVERSE_N1_CPUACTLR_EL1_BIT_6 99a601afe1Slauwal01 msr NEOVERSE_N1_CPUACTLR_EL1, x1 100a601afe1Slauwal011: 101a601afe1Slauwal01 ret x17 102a601afe1Slauwal01endfunc errata_n1_1073348_wa 103a601afe1Slauwal01 104a601afe1Slauwal01func check_errata_1073348 105a601afe1Slauwal01 /* Applies to r0p0 and r1p0 */ 106a601afe1Slauwal01 mov x1, #0x10 107a601afe1Slauwal01 b cpu_rev_var_ls 108a601afe1Slauwal01endfunc check_errata_1073348 109a601afe1Slauwal01 110a601afe1Slauwal01/* -------------------------------------------------- 111e34606f2Slauwal01 * Errata Workaround for Neoverse N1 Errata #1130799 112e34606f2Slauwal01 * This applies to revision <=r2p0 of Neoverse N1. 113e34606f2Slauwal01 * Inputs: 114e34606f2Slauwal01 * x0: variant[4:7] and revision[0:3] of current cpu. 115e34606f2Slauwal01 * Shall clobber: x0-x17 116e34606f2Slauwal01 * -------------------------------------------------- 117e34606f2Slauwal01 */ 118e34606f2Slauwal01func errata_n1_1130799_wa 119e34606f2Slauwal01 /* Compare x0 against revision r2p0 */ 120e34606f2Slauwal01 mov x17, x30 121e34606f2Slauwal01 bl check_errata_1130799 122e34606f2Slauwal01 cbz x0, 1f 123e34606f2Slauwal01 mrs x1, NEOVERSE_N1_CPUACTLR2_EL1 124e34606f2Slauwal01 orr x1, x1, NEOVERSE_N1_CPUACTLR2_EL1_BIT_59 125e34606f2Slauwal01 msr NEOVERSE_N1_CPUACTLR2_EL1, x1 126e34606f2Slauwal011: 127e34606f2Slauwal01 ret x17 128e34606f2Slauwal01endfunc errata_n1_1130799_wa 129e34606f2Slauwal01 130e34606f2Slauwal01func check_errata_1130799 131e34606f2Slauwal01 /* Applies to <=r2p0 */ 132e34606f2Slauwal01 mov x1, #0x20 133e34606f2Slauwal01 b cpu_rev_var_ls 134e34606f2Slauwal01endfunc check_errata_1130799 135e34606f2Slauwal01 136e34606f2Slauwal01/* -------------------------------------------------- 1372017ab24Slauwal01 * Errata Workaround for Neoverse N1 Errata #1165347 1382017ab24Slauwal01 * This applies to revision <=r2p0 of Neoverse N1. 1392017ab24Slauwal01 * Inputs: 1402017ab24Slauwal01 * x0: variant[4:7] and revision[0:3] of current cpu. 1412017ab24Slauwal01 * Shall clobber: x0-x17 1422017ab24Slauwal01 * -------------------------------------------------- 1432017ab24Slauwal01 */ 1442017ab24Slauwal01func errata_n1_1165347_wa 1452017ab24Slauwal01 /* Compare x0 against revision r2p0 */ 1462017ab24Slauwal01 mov x17, x30 1472017ab24Slauwal01 bl check_errata_1165347 1482017ab24Slauwal01 cbz x0, 1f 1492017ab24Slauwal01 mrs x1, NEOVERSE_N1_CPUACTLR2_EL1 1502017ab24Slauwal01 orr x1, x1, NEOVERSE_N1_CPUACTLR2_EL1_BIT_0 1512017ab24Slauwal01 orr x1, x1, NEOVERSE_N1_CPUACTLR2_EL1_BIT_15 1522017ab24Slauwal01 msr NEOVERSE_N1_CPUACTLR2_EL1, x1 1532017ab24Slauwal011: 1542017ab24Slauwal01 ret x17 1552017ab24Slauwal01endfunc errata_n1_1165347_wa 1562017ab24Slauwal01 1572017ab24Slauwal01func check_errata_1165347 1582017ab24Slauwal01 /* Applies to <=r2p0 */ 1592017ab24Slauwal01 mov x1, #0x20 1602017ab24Slauwal01 b cpu_rev_var_ls 1612017ab24Slauwal01endfunc check_errata_1165347 1622017ab24Slauwal01 1632017ab24Slauwal01/* -------------------------------------------------- 164ef5fa7d4Slauwal01 * Errata Workaround for Neoverse N1 Errata #1207823 165ef5fa7d4Slauwal01 * This applies to revision <=r2p0 of Neoverse N1. 166ef5fa7d4Slauwal01 * Inputs: 167ef5fa7d4Slauwal01 * x0: variant[4:7] and revision[0:3] of current cpu. 168ef5fa7d4Slauwal01 * Shall clobber: x0-x17 169ef5fa7d4Slauwal01 * -------------------------------------------------- 170ef5fa7d4Slauwal01 */ 171ef5fa7d4Slauwal01func errata_n1_1207823_wa 172ef5fa7d4Slauwal01 /* Compare x0 against revision r2p0 */ 173ef5fa7d4Slauwal01 mov x17, x30 174ef5fa7d4Slauwal01 bl check_errata_1207823 175ef5fa7d4Slauwal01 cbz x0, 1f 176ef5fa7d4Slauwal01 mrs x1, NEOVERSE_N1_CPUACTLR2_EL1 177ef5fa7d4Slauwal01 orr x1, x1, NEOVERSE_N1_CPUACTLR2_EL1_BIT_11 178ef5fa7d4Slauwal01 msr NEOVERSE_N1_CPUACTLR2_EL1, x1 179ef5fa7d4Slauwal011: 180ef5fa7d4Slauwal01 ret x17 181ef5fa7d4Slauwal01endfunc errata_n1_1207823_wa 182ef5fa7d4Slauwal01 183ef5fa7d4Slauwal01func check_errata_1207823 184ef5fa7d4Slauwal01 /* Applies to <=r2p0 */ 185ef5fa7d4Slauwal01 mov x1, #0x20 186ef5fa7d4Slauwal01 b cpu_rev_var_ls 187ef5fa7d4Slauwal01endfunc check_errata_1207823 188ef5fa7d4Slauwal01 189ef5fa7d4Slauwal01/* -------------------------------------------------- 1909eceb020Slauwal01 * Errata Workaround for Neoverse N1 Errata #1220197 1919eceb020Slauwal01 * This applies to revision <=r2p0 of Neoverse N1. 1929eceb020Slauwal01 * Inputs: 1939eceb020Slauwal01 * x0: variant[4:7] and revision[0:3] of current cpu. 1949eceb020Slauwal01 * Shall clobber: x0-x17 1959eceb020Slauwal01 * -------------------------------------------------- 1969eceb020Slauwal01 */ 1979eceb020Slauwal01func errata_n1_1220197_wa 1989eceb020Slauwal01 /* Compare x0 against revision r2p0 */ 1999eceb020Slauwal01 mov x17, x30 2009eceb020Slauwal01 bl check_errata_1220197 2019eceb020Slauwal01 cbz x0, 1f 2029eceb020Slauwal01 mrs x1, NEOVERSE_N1_CPUECTLR_EL1 2039eceb020Slauwal01 orr x1, x1, NEOVERSE_N1_WS_THR_L2_MASK 2049eceb020Slauwal01 msr NEOVERSE_N1_CPUECTLR_EL1, x1 2059eceb020Slauwal011: 2069eceb020Slauwal01 ret x17 2079eceb020Slauwal01endfunc errata_n1_1220197_wa 2089eceb020Slauwal01 2099eceb020Slauwal01func check_errata_1220197 2109eceb020Slauwal01 /* Applies to <=r2p0 */ 2119eceb020Slauwal01 mov x1, #0x20 2129eceb020Slauwal01 b cpu_rev_var_ls 2139eceb020Slauwal01endfunc check_errata_1220197 2149eceb020Slauwal01 2159eceb020Slauwal01/* -------------------------------------------------- 216335b3c79Slauwal01 * Errata Workaround for Neoverse N1 Errata #1257314 217335b3c79Slauwal01 * This applies to revision <=r3p0 of Neoverse N1. 218335b3c79Slauwal01 * Inputs: 219335b3c79Slauwal01 * x0: variant[4:7] and revision[0:3] of current cpu. 220335b3c79Slauwal01 * Shall clobber: x0-x17 221335b3c79Slauwal01 * -------------------------------------------------- 222335b3c79Slauwal01 */ 223335b3c79Slauwal01func errata_n1_1257314_wa 224335b3c79Slauwal01 /* Compare x0 against revision r3p0 */ 225335b3c79Slauwal01 mov x17, x30 226335b3c79Slauwal01 bl check_errata_1257314 227335b3c79Slauwal01 cbz x0, 1f 228335b3c79Slauwal01 mrs x1, NEOVERSE_N1_CPUACTLR3_EL1 229335b3c79Slauwal01 orr x1, x1, NEOVERSE_N1_CPUACTLR3_EL1_BIT_10 230335b3c79Slauwal01 msr NEOVERSE_N1_CPUACTLR3_EL1, x1 231335b3c79Slauwal011: 232335b3c79Slauwal01 ret x17 233335b3c79Slauwal01endfunc errata_n1_1257314_wa 234335b3c79Slauwal01 235335b3c79Slauwal01func check_errata_1257314 236335b3c79Slauwal01 /* Applies to <=r3p0 */ 237335b3c79Slauwal01 mov x1, #0x30 238335b3c79Slauwal01 b cpu_rev_var_ls 239335b3c79Slauwal01endfunc check_errata_1257314 240335b3c79Slauwal01 241335b3c79Slauwal01/* -------------------------------------------------- 242411f4959Slauwal01 * Errata Workaround for Neoverse N1 Errata #1262606 243411f4959Slauwal01 * This applies to revision <=r3p0 of Neoverse N1. 244411f4959Slauwal01 * Inputs: 245411f4959Slauwal01 * x0: variant[4:7] and revision[0:3] of current cpu. 246411f4959Slauwal01 * Shall clobber: x0-x17 247411f4959Slauwal01 * -------------------------------------------------- 248411f4959Slauwal01 */ 249411f4959Slauwal01func errata_n1_1262606_wa 250411f4959Slauwal01 /* Compare x0 against revision r3p0 */ 251411f4959Slauwal01 mov x17, x30 252411f4959Slauwal01 bl check_errata_1262606 253411f4959Slauwal01 cbz x0, 1f 254411f4959Slauwal01 mrs x1, NEOVERSE_N1_CPUACTLR_EL1 255411f4959Slauwal01 orr x1, x1, NEOVERSE_N1_CPUACTLR_EL1_BIT_13 256411f4959Slauwal01 msr NEOVERSE_N1_CPUACTLR_EL1, x1 257411f4959Slauwal011: 258411f4959Slauwal01 ret x17 259411f4959Slauwal01endfunc errata_n1_1262606_wa 260411f4959Slauwal01 261411f4959Slauwal01func check_errata_1262606 262411f4959Slauwal01 /* Applies to <=r3p0 */ 263411f4959Slauwal01 mov x1, #0x30 264411f4959Slauwal01 b cpu_rev_var_ls 265411f4959Slauwal01endfunc check_errata_1262606 266411f4959Slauwal01 267411f4959Slauwal01/* -------------------------------------------------- 26811c48370Slauwal01 * Errata Workaround for Neoverse N1 Errata #1262888 26911c48370Slauwal01 * This applies to revision <=r3p0 of Neoverse N1. 27011c48370Slauwal01 * Inputs: 27111c48370Slauwal01 * x0: variant[4:7] and revision[0:3] of current cpu. 27211c48370Slauwal01 * Shall clobber: x0-x17 27311c48370Slauwal01 * -------------------------------------------------- 27411c48370Slauwal01 */ 27511c48370Slauwal01func errata_n1_1262888_wa 27611c48370Slauwal01 /* Compare x0 against revision r3p0 */ 27711c48370Slauwal01 mov x17, x30 27811c48370Slauwal01 bl check_errata_1262888 27911c48370Slauwal01 cbz x0, 1f 28011c48370Slauwal01 mrs x1, NEOVERSE_N1_CPUECTLR_EL1 28111c48370Slauwal01 orr x1, x1, NEOVERSE_N1_CPUECTLR_EL1_MM_TLBPF_DIS_BIT 28211c48370Slauwal01 msr NEOVERSE_N1_CPUECTLR_EL1, x1 28311c48370Slauwal011: 28411c48370Slauwal01 ret x17 28511c48370Slauwal01endfunc errata_n1_1262888_wa 28611c48370Slauwal01 28711c48370Slauwal01func check_errata_1262888 28811c48370Slauwal01 /* Applies to <=r3p0 */ 28911c48370Slauwal01 mov x1, #0x30 29011c48370Slauwal01 b cpu_rev_var_ls 29111c48370Slauwal01endfunc check_errata_1262888 29211c48370Slauwal01 29311c48370Slauwal01/* -------------------------------------------------- 2944d8801feSlauwal01 * Errata Workaround for Neoverse N1 Errata #1275112 2954d8801feSlauwal01 * This applies to revision <=r3p0 of Neoverse N1. 2964d8801feSlauwal01 * Inputs: 2974d8801feSlauwal01 * x0: variant[4:7] and revision[0:3] of current cpu. 2984d8801feSlauwal01 * Shall clobber: x0-x17 2994d8801feSlauwal01 * -------------------------------------------------- 3004d8801feSlauwal01 */ 3014d8801feSlauwal01func errata_n1_1275112_wa 3024d8801feSlauwal01 /* Compare x0 against revision r3p0 */ 3034d8801feSlauwal01 mov x17, x30 3044d8801feSlauwal01 bl check_errata_1275112 3054d8801feSlauwal01 cbz x0, 1f 3064d8801feSlauwal01 mrs x1, NEOVERSE_N1_CPUACTLR_EL1 3074d8801feSlauwal01 orr x1, x1, NEOVERSE_N1_CPUACTLR_EL1_BIT_13 3084d8801feSlauwal01 msr NEOVERSE_N1_CPUACTLR_EL1, x1 3094d8801feSlauwal011: 3104d8801feSlauwal01 ret x17 3114d8801feSlauwal01endfunc errata_n1_1275112_wa 3124d8801feSlauwal01 3134d8801feSlauwal01func check_errata_1275112 3144d8801feSlauwal01 /* Applies to <=r3p0 */ 3154d8801feSlauwal01 mov x1, #0x30 3164d8801feSlauwal01 b cpu_rev_var_ls 3174d8801feSlauwal01endfunc check_errata_1275112 3184d8801feSlauwal01 3194d8801feSlauwal01/* -------------------------------------------------- 3205f5d0763SAndre Przywara * Errata Workaround for Neoverse N1 Erratum 1315703. 3215f5d0763SAndre Przywara * This applies to revision <= r3p0 of Neoverse N1. 3225f5d0763SAndre Przywara * Inputs: 3235f5d0763SAndre Przywara * x0: variant[4:7] and revision[0:3] of current cpu. 3245f5d0763SAndre Przywara * Shall clobber: x0-x17 3255f5d0763SAndre Przywara * -------------------------------------------------- 3265f5d0763SAndre Przywara */ 3275f5d0763SAndre Przywarafunc errata_n1_1315703_wa 3285f5d0763SAndre Przywara /* Compare x0 against revision r3p1 */ 3295f5d0763SAndre Przywara mov x17, x30 3305f5d0763SAndre Przywara bl check_errata_1315703 3315f5d0763SAndre Przywara cbz x0, 1f 3325f5d0763SAndre Przywara 3335f5d0763SAndre Przywara mrs x0, NEOVERSE_N1_CPUACTLR2_EL1 3345f5d0763SAndre Przywara orr x0, x0, #NEOVERSE_N1_CPUACTLR2_EL1_BIT_16 3355f5d0763SAndre Przywara msr NEOVERSE_N1_CPUACTLR2_EL1, x0 3365f5d0763SAndre Przywara 3375f5d0763SAndre Przywara1: 3385f5d0763SAndre Przywara ret x17 3395f5d0763SAndre Przywaraendfunc errata_n1_1315703_wa 3405f5d0763SAndre Przywara 3415f5d0763SAndre Przywarafunc check_errata_1315703 3425f5d0763SAndre Przywara /* Applies to everything <= r3p0. */ 3435f5d0763SAndre Przywara mov x1, #0x30 3445f5d0763SAndre Przywara b cpu_rev_var_ls 3455f5d0763SAndre Przywaraendfunc check_errata_1315703 3465f5d0763SAndre Przywara 34780942622Slaurenw-arm/* -------------------------------------------------- 34880942622Slaurenw-arm * Errata Workaround for Neoverse N1 Erratum 1542419. 34980942622Slaurenw-arm * This applies to revisions r3p0 - r4p0 of Neoverse N1 35080942622Slaurenw-arm * Inputs: 35180942622Slaurenw-arm * x0: variant[4:7] and revision[0:3] of current cpu. 35280942622Slaurenw-arm * Shall clobber: x0-x17 35380942622Slaurenw-arm * -------------------------------------------------- 35480942622Slaurenw-arm */ 35580942622Slaurenw-armfunc errata_n1_1542419_wa 35680942622Slaurenw-arm /* Compare x0 against revision r3p0 and r4p0 */ 35780942622Slaurenw-arm mov x17, x30 35880942622Slaurenw-arm bl check_errata_1542419 35980942622Slaurenw-arm cbz x0, 1f 36080942622Slaurenw-arm 36180942622Slaurenw-arm /* Apply instruction patching sequence */ 36280942622Slaurenw-arm ldr x0, =0x0 36380942622Slaurenw-arm msr CPUPSELR_EL3, x0 36480942622Slaurenw-arm ldr x0, =0xEE670D35 36580942622Slaurenw-arm msr CPUPOR_EL3, x0 36680942622Slaurenw-arm ldr x0, =0xFFFF0FFF 36780942622Slaurenw-arm msr CPUPMR_EL3, x0 36880942622Slaurenw-arm ldr x0, =0x08000020007D 36980942622Slaurenw-arm msr CPUPCR_EL3, x0 37080942622Slaurenw-arm isb 37180942622Slaurenw-arm1: 37280942622Slaurenw-arm ret x17 37380942622Slaurenw-armendfunc errata_n1_1542419_wa 37480942622Slaurenw-arm 37580942622Slaurenw-armfunc check_errata_1542419 37680942622Slaurenw-arm /* Applies to everything r3p0 - r4p0. */ 37780942622Slaurenw-arm mov x1, #0x30 37880942622Slaurenw-arm mov x2, #0x40 37980942622Slaurenw-arm b cpu_rev_var_range 38080942622Slaurenw-armendfunc check_errata_1542419 38180942622Slaurenw-arm 38261f0ffc4Sjohpow01 /* -------------------------------------------------- 38361f0ffc4Sjohpow01 * Errata Workaround for Neoverse N1 Errata #1868343. 38461f0ffc4Sjohpow01 * This applies to revision <= r4p0 of Neoverse N1. 38561f0ffc4Sjohpow01 * This workaround is the same as the workaround for 38661f0ffc4Sjohpow01 * errata 1262606 and 1275112 but applies to a wider 38761f0ffc4Sjohpow01 * revision range. 38861f0ffc4Sjohpow01 * Inputs: 38961f0ffc4Sjohpow01 * x0: variant[4:7] and revision[0:3] of current cpu. 39061f0ffc4Sjohpow01 * Shall clobber: x0-x17 39161f0ffc4Sjohpow01 * -------------------------------------------------- 39261f0ffc4Sjohpow01 */ 39361f0ffc4Sjohpow01func errata_n1_1868343_wa 39461f0ffc4Sjohpow01 /* 39561f0ffc4Sjohpow01 * Compare x0 against revision r4p0 39661f0ffc4Sjohpow01 */ 39761f0ffc4Sjohpow01 mov x17, x30 39861f0ffc4Sjohpow01 bl check_errata_1868343 39961f0ffc4Sjohpow01 cbz x0, 1f 40061f0ffc4Sjohpow01 mrs x1, NEOVERSE_N1_CPUACTLR_EL1 40161f0ffc4Sjohpow01 orr x1, x1, NEOVERSE_N1_CPUACTLR_EL1_BIT_13 40261f0ffc4Sjohpow01 msr NEOVERSE_N1_CPUACTLR_EL1, x1 40361f0ffc4Sjohpow01 isb 40461f0ffc4Sjohpow011: 40561f0ffc4Sjohpow01 ret x17 40661f0ffc4Sjohpow01endfunc errata_n1_1868343_wa 40761f0ffc4Sjohpow01 40861f0ffc4Sjohpow01func check_errata_1868343 40961f0ffc4Sjohpow01 /* Applies to everything <= r4p0 */ 41061f0ffc4Sjohpow01 mov x1, #0x40 41161f0ffc4Sjohpow01 b cpu_rev_var_ls 41261f0ffc4Sjohpow01endfunc check_errata_1868343 41361f0ffc4Sjohpow01 414263ee781Sjohpow01 /* -------------------------------------------------- 415263ee781Sjohpow01 * Errata Workaround for Neoverse N1 Errata #1946160. 416263ee781Sjohpow01 * This applies to revisions r3p0, r3p1, r4p0, and 417263ee781Sjohpow01 * r4p1 of Neoverse N1. It also exists in r0p0, r1p0, 418263ee781Sjohpow01 * and r2p0 but there is no fix in these revisions. 419263ee781Sjohpow01 * Inputs: 420263ee781Sjohpow01 * x0: variant[4:7] and revision[0:3] of current cpu. 421263ee781Sjohpow01 * Shall clobber: x0-x17 422263ee781Sjohpow01 * -------------------------------------------------- 423263ee781Sjohpow01 */ 424263ee781Sjohpow01func errata_n1_1946160_wa 425263ee781Sjohpow01 /* 426263ee781Sjohpow01 * Compare x0 against r3p0 - r4p1 427263ee781Sjohpow01 */ 428263ee781Sjohpow01 mov x17, x30 429263ee781Sjohpow01 bl check_errata_1946160 430263ee781Sjohpow01 cbz x0, 1f 431263ee781Sjohpow01 432263ee781Sjohpow01 mov x0, #3 433263ee781Sjohpow01 msr S3_6_C15_C8_0, x0 434263ee781Sjohpow01 ldr x0, =0x10E3900002 435263ee781Sjohpow01 msr S3_6_C15_C8_2, x0 436263ee781Sjohpow01 ldr x0, =0x10FFF00083 437263ee781Sjohpow01 msr S3_6_C15_C8_3, x0 438263ee781Sjohpow01 ldr x0, =0x2001003FF 439263ee781Sjohpow01 msr S3_6_C15_C8_1, x0 440263ee781Sjohpow01 441263ee781Sjohpow01 mov x0, #4 442263ee781Sjohpow01 msr S3_6_C15_C8_0, x0 443263ee781Sjohpow01 ldr x0, =0x10E3800082 444263ee781Sjohpow01 msr S3_6_C15_C8_2, x0 445263ee781Sjohpow01 ldr x0, =0x10FFF00083 446263ee781Sjohpow01 msr S3_6_C15_C8_3, x0 447263ee781Sjohpow01 ldr x0, =0x2001003FF 448263ee781Sjohpow01 msr S3_6_C15_C8_1, x0 449263ee781Sjohpow01 450263ee781Sjohpow01 mov x0, #5 451263ee781Sjohpow01 msr S3_6_C15_C8_0, x0 452263ee781Sjohpow01 ldr x0, =0x10E3800200 453263ee781Sjohpow01 msr S3_6_C15_C8_2, x0 454263ee781Sjohpow01 ldr x0, =0x10FFF003E0 455263ee781Sjohpow01 msr S3_6_C15_C8_3, x0 456263ee781Sjohpow01 ldr x0, =0x2001003FF 457263ee781Sjohpow01 msr S3_6_C15_C8_1, x0 458263ee781Sjohpow01 459263ee781Sjohpow01 isb 460263ee781Sjohpow011: 461263ee781Sjohpow01 ret x17 462263ee781Sjohpow01endfunc errata_n1_1946160_wa 463263ee781Sjohpow01 464263ee781Sjohpow01func check_errata_1946160 465263ee781Sjohpow01 /* Applies to r3p0 - r4p1. */ 466263ee781Sjohpow01 mov x1, #0x30 467263ee781Sjohpow01 mov x2, #0x41 468263ee781Sjohpow01 b cpu_rev_var_range 469263ee781Sjohpow01endfunc check_errata_1946160 470263ee781Sjohpow01 471*1fe4a9d1SBipin Ravifunc check_errata_cve_2022_23960 472*1fe4a9d1SBipin Ravi#if WORKAROUND_CVE_2022_23960 473*1fe4a9d1SBipin Ravi mov x0, #ERRATA_APPLIES 474*1fe4a9d1SBipin Ravi#else 475*1fe4a9d1SBipin Ravi mov x0, #ERRATA_MISSING 476*1fe4a9d1SBipin Ravi#endif 477*1fe4a9d1SBipin Ravi ret 478*1fe4a9d1SBipin Raviendfunc check_errata_cve_2022_23960 479*1fe4a9d1SBipin Ravi 480da6d75a0SJohn Tsichritzisfunc neoverse_n1_reset_func 481b04ea14bSJohn Tsichritzis mov x19, x30 4828074448fSJohn Tsichritzis 483eca6e453SSami Mujawar bl neoverse_n1_disable_speculative_loads 4848074448fSJohn Tsichritzis 485632ab3ebSLouis Mayencourt /* Forces all cacheable atomic instructions to be near */ 486632ab3ebSLouis Mayencourt mrs x0, NEOVERSE_N1_CPUACTLR2_EL1 487632ab3ebSLouis Mayencourt orr x0, x0, #NEOVERSE_N1_CPUACTLR2_EL1_BIT_2 488632ab3ebSLouis Mayencourt msr NEOVERSE_N1_CPUACTLR2_EL1, x0 489632ab3ebSLouis Mayencourt isb 490632ab3ebSLouis Mayencourt 491b04ea14bSJohn Tsichritzis bl cpu_get_rev_var 492b04ea14bSJohn Tsichritzis mov x18, x0 493b04ea14bSJohn Tsichritzis 494da6d75a0SJohn Tsichritzis#if ERRATA_N1_1043202 495b04ea14bSJohn Tsichritzis mov x0, x18 496da6d75a0SJohn Tsichritzis bl errata_n1_1043202_wa 497b04ea14bSJohn Tsichritzis#endif 498b04ea14bSJohn Tsichritzis 499a601afe1Slauwal01#if ERRATA_N1_1073348 500a601afe1Slauwal01 mov x0, x18 501a601afe1Slauwal01 bl errata_n1_1073348_wa 502a601afe1Slauwal01#endif 503a601afe1Slauwal01 504e34606f2Slauwal01#if ERRATA_N1_1130799 505e34606f2Slauwal01 mov x0, x18 506e34606f2Slauwal01 bl errata_n1_1130799_wa 507e34606f2Slauwal01#endif 508e34606f2Slauwal01 5092017ab24Slauwal01#if ERRATA_N1_1165347 5102017ab24Slauwal01 mov x0, x18 5112017ab24Slauwal01 bl errata_n1_1165347_wa 5122017ab24Slauwal01#endif 5132017ab24Slauwal01 514ef5fa7d4Slauwal01#if ERRATA_N1_1207823 515ef5fa7d4Slauwal01 mov x0, x18 516ef5fa7d4Slauwal01 bl errata_n1_1207823_wa 517ef5fa7d4Slauwal01#endif 518ef5fa7d4Slauwal01 5199eceb020Slauwal01#if ERRATA_N1_1220197 5209eceb020Slauwal01 mov x0, x18 5219eceb020Slauwal01 bl errata_n1_1220197_wa 5229eceb020Slauwal01#endif 5239eceb020Slauwal01 524335b3c79Slauwal01#if ERRATA_N1_1257314 525335b3c79Slauwal01 mov x0, x18 526335b3c79Slauwal01 bl errata_n1_1257314_wa 527335b3c79Slauwal01#endif 528335b3c79Slauwal01 529411f4959Slauwal01#if ERRATA_N1_1262606 530411f4959Slauwal01 mov x0, x18 531411f4959Slauwal01 bl errata_n1_1262606_wa 532411f4959Slauwal01#endif 533411f4959Slauwal01 53411c48370Slauwal01#if ERRATA_N1_1262888 53511c48370Slauwal01 mov x0, x18 53611c48370Slauwal01 bl errata_n1_1262888_wa 53711c48370Slauwal01#endif 53811c48370Slauwal01 5394d8801feSlauwal01#if ERRATA_N1_1275112 5404d8801feSlauwal01 mov x0, x18 5414d8801feSlauwal01 bl errata_n1_1275112_wa 5424d8801feSlauwal01#endif 5434d8801feSlauwal01 5445f5d0763SAndre Przywara#if ERRATA_N1_1315703 5455f5d0763SAndre Przywara mov x0, x18 5465f5d0763SAndre Przywara bl errata_n1_1315703_wa 5475f5d0763SAndre Przywara#endif 5485f5d0763SAndre Przywara 54980942622Slaurenw-arm#if ERRATA_N1_1542419 55080942622Slaurenw-arm mov x0, x18 55180942622Slaurenw-arm bl errata_n1_1542419_wa 55280942622Slaurenw-arm#endif 55380942622Slaurenw-arm 55461f0ffc4Sjohpow01#if ERRATA_N1_1868343 55561f0ffc4Sjohpow01 mov x0, x18 55661f0ffc4Sjohpow01 bl errata_n1_1868343_wa 55761f0ffc4Sjohpow01#endif 55861f0ffc4Sjohpow01 559263ee781Sjohpow01#if ERRATA_N1_1946160 560263ee781Sjohpow01 mov x0, x18 561263ee781Sjohpow01 bl errata_n1_1946160_wa 562263ee781Sjohpow01#endif 563263ee781Sjohpow01 564b04ea14bSJohn Tsichritzis#if ENABLE_AMU 565b04ea14bSJohn Tsichritzis /* Make sure accesses from EL0/EL1 and EL2 are not trapped to EL3 */ 566b04ea14bSJohn Tsichritzis mrs x0, actlr_el3 567da6d75a0SJohn Tsichritzis orr x0, x0, #NEOVERSE_N1_ACTLR_AMEN_BIT 568b04ea14bSJohn Tsichritzis msr actlr_el3, x0 569b04ea14bSJohn Tsichritzis 570b04ea14bSJohn Tsichritzis /* Make sure accesses from EL0/EL1 are not trapped to EL2 */ 571b04ea14bSJohn Tsichritzis mrs x0, actlr_el2 572da6d75a0SJohn Tsichritzis orr x0, x0, #NEOVERSE_N1_ACTLR_AMEN_BIT 573b04ea14bSJohn Tsichritzis msr actlr_el2, x0 574b04ea14bSJohn Tsichritzis 575b04ea14bSJohn Tsichritzis /* Enable group0 counters */ 576da6d75a0SJohn Tsichritzis mov x0, #NEOVERSE_N1_AMU_GROUP0_MASK 577b04ea14bSJohn Tsichritzis msr CPUAMCNTENSET_EL0, x0 578b04ea14bSJohn Tsichritzis#endif 579bb2f077aSLouis Mayencourt 58025bbbd2dSJavier Almansa Sobrino#if NEOVERSE_Nx_EXTERNAL_LLC 581f2d6b4eeSManish Pandey /* Some system may have External LLC, core needs to be made aware */ 582f2d6b4eeSManish Pandey mrs x0, NEOVERSE_N1_CPUECTLR_EL1 583f2d6b4eeSManish Pandey orr x0, x0, NEOVERSE_N1_CPUECTLR_EL1_EXTLLC_BIT 584f2d6b4eeSManish Pandey msr NEOVERSE_N1_CPUECTLR_EL1, x0 585f2d6b4eeSManish Pandey#endif 586f2d6b4eeSManish Pandey 587bb2f077aSLouis Mayencourt#if ERRATA_DSU_936184 588bb2f077aSLouis Mayencourt bl errata_dsu_936184_wa 589bb2f077aSLouis Mayencourt#endif 590bb2f077aSLouis Mayencourt 591*1fe4a9d1SBipin Ravi#if IMAGE_BL31 && WORKAROUND_CVE_2022_23960 592*1fe4a9d1SBipin Ravi /* 593*1fe4a9d1SBipin Ravi * The Neoverse-N1 generic vectors are overridden to apply errata 594*1fe4a9d1SBipin Ravi * mitigation on exception entry from lower ELs. 595*1fe4a9d1SBipin Ravi */ 596*1fe4a9d1SBipin Ravi adr x0, wa_cve_vbar_neoverse_n1 597*1fe4a9d1SBipin Ravi msr vbar_el3, x0 598*1fe4a9d1SBipin Ravi#endif /* IMAGE_BL31 && WORKAROUND_CVE_2022_23960 */ 599*1fe4a9d1SBipin Ravi 6007d6f7518Slauwal01 isb 601b04ea14bSJohn Tsichritzis ret x19 602da6d75a0SJohn Tsichritzisendfunc neoverse_n1_reset_func 603b04ea14bSJohn Tsichritzis 604b04ea14bSJohn Tsichritzis /* --------------------------------------------- 605b04ea14bSJohn Tsichritzis * HW will do the cache maintenance while powering down 606b04ea14bSJohn Tsichritzis * --------------------------------------------- 607b04ea14bSJohn Tsichritzis */ 608da6d75a0SJohn Tsichritzisfunc neoverse_n1_core_pwr_dwn 609b04ea14bSJohn Tsichritzis /* --------------------------------------------- 610b04ea14bSJohn Tsichritzis * Enable CPU power down bit in power control register 611b04ea14bSJohn Tsichritzis * --------------------------------------------- 612b04ea14bSJohn Tsichritzis */ 613da6d75a0SJohn Tsichritzis mrs x0, NEOVERSE_N1_CPUPWRCTLR_EL1 614da6d75a0SJohn Tsichritzis orr x0, x0, #NEOVERSE_N1_CORE_PWRDN_EN_MASK 615da6d75a0SJohn Tsichritzis msr NEOVERSE_N1_CPUPWRCTLR_EL1, x0 616b04ea14bSJohn Tsichritzis isb 617b04ea14bSJohn Tsichritzis ret 618da6d75a0SJohn Tsichritzisendfunc neoverse_n1_core_pwr_dwn 619b04ea14bSJohn Tsichritzis 620b04ea14bSJohn Tsichritzis#if REPORT_ERRATA 621b04ea14bSJohn Tsichritzis/* 622da6d75a0SJohn Tsichritzis * Errata printing function for Neoverse N1. Must follow AAPCS. 623b04ea14bSJohn Tsichritzis */ 624da6d75a0SJohn Tsichritzisfunc neoverse_n1_errata_report 625b04ea14bSJohn Tsichritzis stp x8, x30, [sp, #-16]! 626b04ea14bSJohn Tsichritzis 627b04ea14bSJohn Tsichritzis bl cpu_get_rev_var 628b04ea14bSJohn Tsichritzis mov x8, x0 629b04ea14bSJohn Tsichritzis 630b04ea14bSJohn Tsichritzis /* 631b04ea14bSJohn Tsichritzis * Report all errata. The revision-variant information is passed to 632b04ea14bSJohn Tsichritzis * checking functions of each errata. 633b04ea14bSJohn Tsichritzis */ 634da6d75a0SJohn Tsichritzis report_errata ERRATA_N1_1043202, neoverse_n1, 1043202 635a601afe1Slauwal01 report_errata ERRATA_N1_1073348, neoverse_n1, 1073348 636e34606f2Slauwal01 report_errata ERRATA_N1_1130799, neoverse_n1, 1130799 6372017ab24Slauwal01 report_errata ERRATA_N1_1165347, neoverse_n1, 1165347 638ef5fa7d4Slauwal01 report_errata ERRATA_N1_1207823, neoverse_n1, 1207823 6399eceb020Slauwal01 report_errata ERRATA_N1_1220197, neoverse_n1, 1220197 640335b3c79Slauwal01 report_errata ERRATA_N1_1257314, neoverse_n1, 1257314 641411f4959Slauwal01 report_errata ERRATA_N1_1262606, neoverse_n1, 1262606 64211c48370Slauwal01 report_errata ERRATA_N1_1262888, neoverse_n1, 1262888 6434d8801feSlauwal01 report_errata ERRATA_N1_1275112, neoverse_n1, 1275112 6445f5d0763SAndre Przywara report_errata ERRATA_N1_1315703, neoverse_n1, 1315703 64580942622Slaurenw-arm report_errata ERRATA_N1_1542419, neoverse_n1, 1542419 64661f0ffc4Sjohpow01 report_errata ERRATA_N1_1868343, neoverse_n1, 1868343 647263ee781Sjohpow01 report_errata ERRATA_N1_1946160, neoverse_n1, 1946160 648bb2f077aSLouis Mayencourt report_errata ERRATA_DSU_936184, neoverse_n1, dsu_936184 649*1fe4a9d1SBipin Ravi report_errata WORKAROUND_CVE_2022_23960, neoverse_n1, cve_2022_23960 650b04ea14bSJohn Tsichritzis 651b04ea14bSJohn Tsichritzis ldp x8, x30, [sp], #16 652b04ea14bSJohn Tsichritzis ret 653da6d75a0SJohn Tsichritzisendfunc neoverse_n1_errata_report 654b04ea14bSJohn Tsichritzis#endif 655b04ea14bSJohn Tsichritzis 65680942622Slaurenw-arm/* 65780942622Slaurenw-arm * Handle trap of EL0 IC IVAU instructions to EL3 by executing a TLB 65880942622Slaurenw-arm * inner-shareable invalidation to an arbitrary address followed by a DSB. 65980942622Slaurenw-arm * 66080942622Slaurenw-arm * x1: Exception Syndrome 66180942622Slaurenw-arm */ 66280942622Slaurenw-armfunc neoverse_n1_errata_ic_trap_handler 66380942622Slaurenw-arm cmp x1, #NEOVERSE_N1_EC_IC_TRAP 66480942622Slaurenw-arm b.ne 1f 66580942622Slaurenw-arm tlbi vae3is, xzr 66680942622Slaurenw-arm dsb sy 66780942622Slaurenw-arm 66880942622Slaurenw-arm # Skip the IC instruction itself 66980942622Slaurenw-arm mrs x3, elr_el3 67080942622Slaurenw-arm add x3, x3, #4 67180942622Slaurenw-arm msr elr_el3, x3 67280942622Slaurenw-arm 67380942622Slaurenw-arm ldp x0, x1, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X0] 67480942622Slaurenw-arm ldp x2, x3, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X2] 67580942622Slaurenw-arm ldp x4, x5, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X4] 67680942622Slaurenw-arm ldr x30, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_LR] 67780942622Slaurenw-arm 67880942622Slaurenw-arm#if IMAGE_BL31 && RAS_EXTENSION 67980942622Slaurenw-arm /* 68080942622Slaurenw-arm * Issue Error Synchronization Barrier to synchronize SErrors before 68180942622Slaurenw-arm * exiting EL3. We're running with EAs unmasked, so any synchronized 68280942622Slaurenw-arm * errors would be taken immediately; therefore no need to inspect 68380942622Slaurenw-arm * DISR_EL1 register. 68480942622Slaurenw-arm */ 68580942622Slaurenw-arm esb 68680942622Slaurenw-arm#endif 687f461fe34SAnthony Steinhauser exception_return 68880942622Slaurenw-arm1: 68980942622Slaurenw-arm ret 69080942622Slaurenw-armendfunc neoverse_n1_errata_ic_trap_handler 69180942622Slaurenw-arm 692b04ea14bSJohn Tsichritzis /* --------------------------------------------- 693da6d75a0SJohn Tsichritzis * This function provides neoverse_n1 specific 694b04ea14bSJohn Tsichritzis * register information for crash reporting. 695b04ea14bSJohn Tsichritzis * It needs to return with x6 pointing to 696b04ea14bSJohn Tsichritzis * a list of register names in ascii and 697b04ea14bSJohn Tsichritzis * x8 - x15 having values of registers to be 698b04ea14bSJohn Tsichritzis * reported. 699b04ea14bSJohn Tsichritzis * --------------------------------------------- 700b04ea14bSJohn Tsichritzis */ 701da6d75a0SJohn Tsichritzis.section .rodata.neoverse_n1_regs, "aS" 702da6d75a0SJohn Tsichritzisneoverse_n1_regs: /* The ascii list of register names to be reported */ 703b04ea14bSJohn Tsichritzis .asciz "cpuectlr_el1", "" 704b04ea14bSJohn Tsichritzis 705da6d75a0SJohn Tsichritzisfunc neoverse_n1_cpu_reg_dump 706da6d75a0SJohn Tsichritzis adr x6, neoverse_n1_regs 707da6d75a0SJohn Tsichritzis mrs x8, NEOVERSE_N1_CPUECTLR_EL1 708b04ea14bSJohn Tsichritzis ret 709da6d75a0SJohn Tsichritzisendfunc neoverse_n1_cpu_reg_dump 710b04ea14bSJohn Tsichritzis 71180942622Slaurenw-armdeclare_cpu_ops_eh neoverse_n1, NEOVERSE_N1_MIDR, \ 712da6d75a0SJohn Tsichritzis neoverse_n1_reset_func, \ 71380942622Slaurenw-arm neoverse_n1_errata_ic_trap_handler, \ 714da6d75a0SJohn Tsichritzis neoverse_n1_core_pwr_dwn 715