1b04ea14bSJohn Tsichritzis/* 2da6d75a0SJohn Tsichritzis * Copyright (c) 2017-2019, 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> 9da6d75a0SJohn Tsichritzis#include <neoverse_n1.h> 10b04ea14bSJohn Tsichritzis#include <cpuamu.h> 11b04ea14bSJohn Tsichritzis#include <cpu_macros.S> 12b04ea14bSJohn Tsichritzis 13076b5f02SJohn Tsichritzis/* Hardware handled coherency */ 14076b5f02SJohn Tsichritzis#if HW_ASSISTED_COHERENCY == 0 15076b5f02SJohn Tsichritzis#error "Neoverse N1 must be compiled with HW_ASSISTED_COHERENCY enabled" 16076b5f02SJohn Tsichritzis#endif 17076b5f02SJohn Tsichritzis 18629d04f5SJohn Tsichritzis/* 64-bit only core */ 19629d04f5SJohn Tsichritzis#if CTX_INCLUDE_AARCH32_REGS == 1 20629d04f5SJohn Tsichritzis#error "Neoverse-N1 supports only AArch64. Compile with CTX_INCLUDE_AARCH32_REGS=0" 21629d04f5SJohn Tsichritzis#endif 22629d04f5SJohn Tsichritzis 23b04ea14bSJohn Tsichritzis/* -------------------------------------------------- 245f5d0763SAndre Przywara * Errata Workaround for Neoverse N1 Erratum 1043202. 25da6d75a0SJohn Tsichritzis * This applies to revision r0p0 and r1p0 of Neoverse N1. 26b04ea14bSJohn Tsichritzis * Inputs: 27b04ea14bSJohn Tsichritzis * x0: variant[4:7] and revision[0:3] of current cpu. 28b04ea14bSJohn Tsichritzis * Shall clobber: x0-x17 29b04ea14bSJohn Tsichritzis * -------------------------------------------------- 30b04ea14bSJohn Tsichritzis */ 31da6d75a0SJohn Tsichritzisfunc errata_n1_1043202_wa 32b04ea14bSJohn Tsichritzis /* Compare x0 against revision r1p0 */ 33b04ea14bSJohn Tsichritzis mov x17, x30 34b04ea14bSJohn Tsichritzis bl check_errata_1043202 35b04ea14bSJohn Tsichritzis cbz x0, 1f 36b04ea14bSJohn Tsichritzis 37b04ea14bSJohn Tsichritzis /* Apply instruction patching sequence */ 38b04ea14bSJohn Tsichritzis ldr x0, =0x0 39b04ea14bSJohn Tsichritzis msr CPUPSELR_EL3, x0 40b04ea14bSJohn Tsichritzis ldr x0, =0xF3BF8F2F 41b04ea14bSJohn Tsichritzis msr CPUPOR_EL3, x0 42b04ea14bSJohn Tsichritzis ldr x0, =0xFFFFFFFF 43b04ea14bSJohn Tsichritzis msr CPUPMR_EL3, x0 44b04ea14bSJohn Tsichritzis ldr x0, =0x800200071 45b04ea14bSJohn Tsichritzis msr CPUPCR_EL3, x0 46b04ea14bSJohn Tsichritzis isb 47b04ea14bSJohn Tsichritzis1: 48b04ea14bSJohn Tsichritzis ret x17 49da6d75a0SJohn Tsichritzisendfunc errata_n1_1043202_wa 50b04ea14bSJohn Tsichritzis 51b04ea14bSJohn Tsichritzisfunc check_errata_1043202 52b04ea14bSJohn Tsichritzis /* Applies to r0p0 and r1p0 */ 53b04ea14bSJohn Tsichritzis mov x1, #0x10 54b04ea14bSJohn Tsichritzis b cpu_rev_var_ls 55b04ea14bSJohn Tsichritzisendfunc check_errata_1043202 56b04ea14bSJohn Tsichritzis 57eca6e453SSami Mujawar/* -------------------------------------------------- 58eca6e453SSami Mujawar * Disable speculative loads if Neoverse N1 supports 59eca6e453SSami Mujawar * SSBS. 60eca6e453SSami Mujawar * 61eca6e453SSami Mujawar * Shall clobber: x0. 62eca6e453SSami Mujawar * -------------------------------------------------- 63eca6e453SSami Mujawar */ 64eca6e453SSami Mujawarfunc neoverse_n1_disable_speculative_loads 65eca6e453SSami Mujawar /* Check if the PE implements SSBS */ 66eca6e453SSami Mujawar mrs x0, id_aa64pfr1_el1 67eca6e453SSami Mujawar tst x0, #(ID_AA64PFR1_EL1_SSBS_MASK << ID_AA64PFR1_EL1_SSBS_SHIFT) 68eca6e453SSami Mujawar b.eq 1f 69eca6e453SSami Mujawar 70eca6e453SSami Mujawar /* Disable speculative loads */ 71eca6e453SSami Mujawar msr SSBS, xzr 72eca6e453SSami Mujawar isb 73eca6e453SSami Mujawar 74eca6e453SSami Mujawar1: 75eca6e453SSami Mujawar ret 76eca6e453SSami Mujawarendfunc neoverse_n1_disable_speculative_loads 77eca6e453SSami Mujawar 785f5d0763SAndre Przywara/* -------------------------------------------------- 79*a601afe1Slauwal01 * Errata Workaround for Neoverse N1 Errata #1073348 80*a601afe1Slauwal01 * This applies to revision r0p0 and r1p0 of Neoverse N1. 81*a601afe1Slauwal01 * Inputs: 82*a601afe1Slauwal01 * x0: variant[4:7] and revision[0:3] of current cpu. 83*a601afe1Slauwal01 * Shall clobber: x0-x17 84*a601afe1Slauwal01 * -------------------------------------------------- 85*a601afe1Slauwal01 */ 86*a601afe1Slauwal01func errata_n1_1073348_wa 87*a601afe1Slauwal01 /* Compare x0 against revision r1p0 */ 88*a601afe1Slauwal01 mov x17, x30 89*a601afe1Slauwal01 bl check_errata_1073348 90*a601afe1Slauwal01 cbz x0, 1f 91*a601afe1Slauwal01 mrs x1, NEOVERSE_N1_CPUACTLR_EL1 92*a601afe1Slauwal01 orr x1, x1, NEOVERSE_N1_CPUACTLR_EL1_BIT_6 93*a601afe1Slauwal01 msr NEOVERSE_N1_CPUACTLR_EL1, x1 94*a601afe1Slauwal01 isb 95*a601afe1Slauwal011: 96*a601afe1Slauwal01 ret x17 97*a601afe1Slauwal01endfunc errata_n1_1073348_wa 98*a601afe1Slauwal01 99*a601afe1Slauwal01func check_errata_1073348 100*a601afe1Slauwal01 /* Applies to r0p0 and r1p0 */ 101*a601afe1Slauwal01 mov x1, #0x10 102*a601afe1Slauwal01 b cpu_rev_var_ls 103*a601afe1Slauwal01endfunc check_errata_1073348 104*a601afe1Slauwal01 105*a601afe1Slauwal01/* -------------------------------------------------- 1065f5d0763SAndre Przywara * Errata Workaround for Neoverse N1 Erratum 1315703. 1075f5d0763SAndre Przywara * This applies to revision <= r3p0 of Neoverse N1. 1085f5d0763SAndre Przywara * Inputs: 1095f5d0763SAndre Przywara * x0: variant[4:7] and revision[0:3] of current cpu. 1105f5d0763SAndre Przywara * Shall clobber: x0-x17 1115f5d0763SAndre Przywara * -------------------------------------------------- 1125f5d0763SAndre Przywara */ 1135f5d0763SAndre Przywarafunc errata_n1_1315703_wa 1145f5d0763SAndre Przywara /* Compare x0 against revision r3p1 */ 1155f5d0763SAndre Przywara mov x17, x30 1165f5d0763SAndre Przywara bl check_errata_1315703 1175f5d0763SAndre Przywara cbz x0, 1f 1185f5d0763SAndre Przywara 1195f5d0763SAndre Przywara mrs x0, NEOVERSE_N1_CPUACTLR2_EL1 1205f5d0763SAndre Przywara orr x0, x0, #NEOVERSE_N1_CPUACTLR2_EL1_BIT_16 1215f5d0763SAndre Przywara msr NEOVERSE_N1_CPUACTLR2_EL1, x0 1225f5d0763SAndre Przywara isb 1235f5d0763SAndre Przywara 1245f5d0763SAndre Przywara1: 1255f5d0763SAndre Przywara ret x17 1265f5d0763SAndre Przywaraendfunc errata_n1_1315703_wa 1275f5d0763SAndre Przywara 1285f5d0763SAndre Przywarafunc check_errata_1315703 1295f5d0763SAndre Przywara /* Applies to everything <= r3p0. */ 1305f5d0763SAndre Przywara mov x1, #0x30 1315f5d0763SAndre Przywara b cpu_rev_var_ls 1325f5d0763SAndre Przywaraendfunc check_errata_1315703 1335f5d0763SAndre Przywara 134da6d75a0SJohn Tsichritzisfunc neoverse_n1_reset_func 135b04ea14bSJohn Tsichritzis mov x19, x30 1368074448fSJohn Tsichritzis 137eca6e453SSami Mujawar bl neoverse_n1_disable_speculative_loads 1388074448fSJohn Tsichritzis 139632ab3ebSLouis Mayencourt /* Forces all cacheable atomic instructions to be near */ 140632ab3ebSLouis Mayencourt mrs x0, NEOVERSE_N1_CPUACTLR2_EL1 141632ab3ebSLouis Mayencourt orr x0, x0, #NEOVERSE_N1_CPUACTLR2_EL1_BIT_2 142632ab3ebSLouis Mayencourt msr NEOVERSE_N1_CPUACTLR2_EL1, x0 143632ab3ebSLouis Mayencourt isb 144632ab3ebSLouis Mayencourt 145b04ea14bSJohn Tsichritzis bl cpu_get_rev_var 146b04ea14bSJohn Tsichritzis mov x18, x0 147b04ea14bSJohn Tsichritzis 148da6d75a0SJohn Tsichritzis#if ERRATA_N1_1043202 149b04ea14bSJohn Tsichritzis mov x0, x18 150da6d75a0SJohn Tsichritzis bl errata_n1_1043202_wa 151b04ea14bSJohn Tsichritzis#endif 152b04ea14bSJohn Tsichritzis 153*a601afe1Slauwal01#if ERRATA_N1_1073348 154*a601afe1Slauwal01 mov x0, x18 155*a601afe1Slauwal01 bl errata_n1_1073348_wa 156*a601afe1Slauwal01#endif 157*a601afe1Slauwal01 1585f5d0763SAndre Przywara#if ERRATA_N1_1315703 1595f5d0763SAndre Przywara mov x0, x18 1605f5d0763SAndre Przywara bl errata_n1_1315703_wa 1615f5d0763SAndre Przywara#endif 1625f5d0763SAndre Przywara 163b04ea14bSJohn Tsichritzis#if ENABLE_AMU 164b04ea14bSJohn Tsichritzis /* Make sure accesses from EL0/EL1 and EL2 are not trapped to EL3 */ 165b04ea14bSJohn Tsichritzis mrs x0, actlr_el3 166da6d75a0SJohn Tsichritzis orr x0, x0, #NEOVERSE_N1_ACTLR_AMEN_BIT 167b04ea14bSJohn Tsichritzis msr actlr_el3, x0 168b04ea14bSJohn Tsichritzis isb 169b04ea14bSJohn Tsichritzis 170b04ea14bSJohn Tsichritzis /* Make sure accesses from EL0/EL1 are not trapped to EL2 */ 171b04ea14bSJohn Tsichritzis mrs x0, actlr_el2 172da6d75a0SJohn Tsichritzis orr x0, x0, #NEOVERSE_N1_ACTLR_AMEN_BIT 173b04ea14bSJohn Tsichritzis msr actlr_el2, x0 174b04ea14bSJohn Tsichritzis isb 175b04ea14bSJohn Tsichritzis 176b04ea14bSJohn Tsichritzis /* Enable group0 counters */ 177da6d75a0SJohn Tsichritzis mov x0, #NEOVERSE_N1_AMU_GROUP0_MASK 178b04ea14bSJohn Tsichritzis msr CPUAMCNTENSET_EL0, x0 179b04ea14bSJohn Tsichritzis isb 180b04ea14bSJohn Tsichritzis#endif 181bb2f077aSLouis Mayencourt 182bb2f077aSLouis Mayencourt#if ERRATA_DSU_936184 183bb2f077aSLouis Mayencourt bl errata_dsu_936184_wa 184bb2f077aSLouis Mayencourt#endif 185bb2f077aSLouis Mayencourt 186b04ea14bSJohn Tsichritzis ret x19 187da6d75a0SJohn Tsichritzisendfunc neoverse_n1_reset_func 188b04ea14bSJohn Tsichritzis 189b04ea14bSJohn Tsichritzis /* --------------------------------------------- 190b04ea14bSJohn Tsichritzis * HW will do the cache maintenance while powering down 191b04ea14bSJohn Tsichritzis * --------------------------------------------- 192b04ea14bSJohn Tsichritzis */ 193da6d75a0SJohn Tsichritzisfunc neoverse_n1_core_pwr_dwn 194b04ea14bSJohn Tsichritzis /* --------------------------------------------- 195b04ea14bSJohn Tsichritzis * Enable CPU power down bit in power control register 196b04ea14bSJohn Tsichritzis * --------------------------------------------- 197b04ea14bSJohn Tsichritzis */ 198da6d75a0SJohn Tsichritzis mrs x0, NEOVERSE_N1_CPUPWRCTLR_EL1 199da6d75a0SJohn Tsichritzis orr x0, x0, #NEOVERSE_N1_CORE_PWRDN_EN_MASK 200da6d75a0SJohn Tsichritzis msr NEOVERSE_N1_CPUPWRCTLR_EL1, x0 201b04ea14bSJohn Tsichritzis isb 202b04ea14bSJohn Tsichritzis ret 203da6d75a0SJohn Tsichritzisendfunc neoverse_n1_core_pwr_dwn 204b04ea14bSJohn Tsichritzis 205b04ea14bSJohn Tsichritzis#if REPORT_ERRATA 206b04ea14bSJohn Tsichritzis/* 207da6d75a0SJohn Tsichritzis * Errata printing function for Neoverse N1. Must follow AAPCS. 208b04ea14bSJohn Tsichritzis */ 209da6d75a0SJohn Tsichritzisfunc neoverse_n1_errata_report 210b04ea14bSJohn Tsichritzis stp x8, x30, [sp, #-16]! 211b04ea14bSJohn Tsichritzis 212b04ea14bSJohn Tsichritzis bl cpu_get_rev_var 213b04ea14bSJohn Tsichritzis mov x8, x0 214b04ea14bSJohn Tsichritzis 215b04ea14bSJohn Tsichritzis /* 216b04ea14bSJohn Tsichritzis * Report all errata. The revision-variant information is passed to 217b04ea14bSJohn Tsichritzis * checking functions of each errata. 218b04ea14bSJohn Tsichritzis */ 219da6d75a0SJohn Tsichritzis report_errata ERRATA_N1_1043202, neoverse_n1, 1043202 220*a601afe1Slauwal01 report_errata ERRATA_N1_1073348, neoverse_n1, 1073348 2215f5d0763SAndre Przywara report_errata ERRATA_N1_1315703, neoverse_n1, 1315703 222bb2f077aSLouis Mayencourt report_errata ERRATA_DSU_936184, neoverse_n1, dsu_936184 223b04ea14bSJohn Tsichritzis 224b04ea14bSJohn Tsichritzis ldp x8, x30, [sp], #16 225b04ea14bSJohn Tsichritzis ret 226da6d75a0SJohn Tsichritzisendfunc neoverse_n1_errata_report 227b04ea14bSJohn Tsichritzis#endif 228b04ea14bSJohn Tsichritzis 229b04ea14bSJohn Tsichritzis /* --------------------------------------------- 230da6d75a0SJohn Tsichritzis * This function provides neoverse_n1 specific 231b04ea14bSJohn Tsichritzis * register information for crash reporting. 232b04ea14bSJohn Tsichritzis * It needs to return with x6 pointing to 233b04ea14bSJohn Tsichritzis * a list of register names in ascii and 234b04ea14bSJohn Tsichritzis * x8 - x15 having values of registers to be 235b04ea14bSJohn Tsichritzis * reported. 236b04ea14bSJohn Tsichritzis * --------------------------------------------- 237b04ea14bSJohn Tsichritzis */ 238da6d75a0SJohn Tsichritzis.section .rodata.neoverse_n1_regs, "aS" 239da6d75a0SJohn Tsichritzisneoverse_n1_regs: /* The ascii list of register names to be reported */ 240b04ea14bSJohn Tsichritzis .asciz "cpuectlr_el1", "" 241b04ea14bSJohn Tsichritzis 242da6d75a0SJohn Tsichritzisfunc neoverse_n1_cpu_reg_dump 243da6d75a0SJohn Tsichritzis adr x6, neoverse_n1_regs 244da6d75a0SJohn Tsichritzis mrs x8, NEOVERSE_N1_CPUECTLR_EL1 245b04ea14bSJohn Tsichritzis ret 246da6d75a0SJohn Tsichritzisendfunc neoverse_n1_cpu_reg_dump 247b04ea14bSJohn Tsichritzis 248da6d75a0SJohn Tsichritzisdeclare_cpu_ops neoverse_n1, NEOVERSE_N1_MIDR, \ 249da6d75a0SJohn Tsichritzis neoverse_n1_reset_func, \ 250da6d75a0SJohn Tsichritzis neoverse_n1_core_pwr_dwn 251