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 18b04ea14bSJohn Tsichritzis/* -------------------------------------------------- 19*5f5d0763SAndre Przywara * Errata Workaround for Neoverse N1 Erratum 1043202. 20da6d75a0SJohn Tsichritzis * This applies to revision r0p0 and r1p0 of Neoverse N1. 21b04ea14bSJohn Tsichritzis * Inputs: 22b04ea14bSJohn Tsichritzis * x0: variant[4:7] and revision[0:3] of current cpu. 23b04ea14bSJohn Tsichritzis * Shall clobber: x0-x17 24b04ea14bSJohn Tsichritzis * -------------------------------------------------- 25b04ea14bSJohn Tsichritzis */ 26da6d75a0SJohn Tsichritzisfunc errata_n1_1043202_wa 27b04ea14bSJohn Tsichritzis /* Compare x0 against revision r1p0 */ 28b04ea14bSJohn Tsichritzis mov x17, x30 29b04ea14bSJohn Tsichritzis bl check_errata_1043202 30b04ea14bSJohn Tsichritzis cbz x0, 1f 31b04ea14bSJohn Tsichritzis 32b04ea14bSJohn Tsichritzis /* Apply instruction patching sequence */ 33b04ea14bSJohn Tsichritzis ldr x0, =0x0 34b04ea14bSJohn Tsichritzis msr CPUPSELR_EL3, x0 35b04ea14bSJohn Tsichritzis ldr x0, =0xF3BF8F2F 36b04ea14bSJohn Tsichritzis msr CPUPOR_EL3, x0 37b04ea14bSJohn Tsichritzis ldr x0, =0xFFFFFFFF 38b04ea14bSJohn Tsichritzis msr CPUPMR_EL3, x0 39b04ea14bSJohn Tsichritzis ldr x0, =0x800200071 40b04ea14bSJohn Tsichritzis msr CPUPCR_EL3, x0 41b04ea14bSJohn Tsichritzis isb 42b04ea14bSJohn Tsichritzis1: 43b04ea14bSJohn Tsichritzis ret x17 44da6d75a0SJohn Tsichritzisendfunc errata_n1_1043202_wa 45b04ea14bSJohn Tsichritzis 46b04ea14bSJohn Tsichritzisfunc check_errata_1043202 47b04ea14bSJohn Tsichritzis /* Applies to r0p0 and r1p0 */ 48b04ea14bSJohn Tsichritzis mov x1, #0x10 49b04ea14bSJohn Tsichritzis b cpu_rev_var_ls 50b04ea14bSJohn Tsichritzisendfunc check_errata_1043202 51b04ea14bSJohn Tsichritzis 52eca6e453SSami Mujawar/* -------------------------------------------------- 53eca6e453SSami Mujawar * Disable speculative loads if Neoverse N1 supports 54eca6e453SSami Mujawar * SSBS. 55eca6e453SSami Mujawar * 56eca6e453SSami Mujawar * Shall clobber: x0. 57eca6e453SSami Mujawar * -------------------------------------------------- 58eca6e453SSami Mujawar */ 59eca6e453SSami Mujawarfunc neoverse_n1_disable_speculative_loads 60eca6e453SSami Mujawar /* Check if the PE implements SSBS */ 61eca6e453SSami Mujawar mrs x0, id_aa64pfr1_el1 62eca6e453SSami Mujawar tst x0, #(ID_AA64PFR1_EL1_SSBS_MASK << ID_AA64PFR1_EL1_SSBS_SHIFT) 63eca6e453SSami Mujawar b.eq 1f 64eca6e453SSami Mujawar 65eca6e453SSami Mujawar /* Disable speculative loads */ 66eca6e453SSami Mujawar msr SSBS, xzr 67eca6e453SSami Mujawar isb 68eca6e453SSami Mujawar 69eca6e453SSami Mujawar1: 70eca6e453SSami Mujawar ret 71eca6e453SSami Mujawarendfunc neoverse_n1_disable_speculative_loads 72eca6e453SSami Mujawar 73*5f5d0763SAndre Przywara/* -------------------------------------------------- 74*5f5d0763SAndre Przywara * Errata Workaround for Neoverse N1 Erratum 1315703. 75*5f5d0763SAndre Przywara * This applies to revision <= r3p0 of Neoverse N1. 76*5f5d0763SAndre Przywara * Inputs: 77*5f5d0763SAndre Przywara * x0: variant[4:7] and revision[0:3] of current cpu. 78*5f5d0763SAndre Przywara * Shall clobber: x0-x17 79*5f5d0763SAndre Przywara * -------------------------------------------------- 80*5f5d0763SAndre Przywara */ 81*5f5d0763SAndre Przywarafunc errata_n1_1315703_wa 82*5f5d0763SAndre Przywara /* Compare x0 against revision r3p1 */ 83*5f5d0763SAndre Przywara mov x17, x30 84*5f5d0763SAndre Przywara bl check_errata_1315703 85*5f5d0763SAndre Przywara cbz x0, 1f 86*5f5d0763SAndre Przywara 87*5f5d0763SAndre Przywara mrs x0, NEOVERSE_N1_CPUACTLR2_EL1 88*5f5d0763SAndre Przywara orr x0, x0, #NEOVERSE_N1_CPUACTLR2_EL1_BIT_16 89*5f5d0763SAndre Przywara msr NEOVERSE_N1_CPUACTLR2_EL1, x0 90*5f5d0763SAndre Przywara isb 91*5f5d0763SAndre Przywara 92*5f5d0763SAndre Przywara1: 93*5f5d0763SAndre Przywara ret x17 94*5f5d0763SAndre Przywaraendfunc errata_n1_1315703_wa 95*5f5d0763SAndre Przywara 96*5f5d0763SAndre Przywarafunc check_errata_1315703 97*5f5d0763SAndre Przywara /* Applies to everything <= r3p0. */ 98*5f5d0763SAndre Przywara mov x1, #0x30 99*5f5d0763SAndre Przywara b cpu_rev_var_ls 100*5f5d0763SAndre Przywaraendfunc check_errata_1315703 101*5f5d0763SAndre Przywara 102da6d75a0SJohn Tsichritzisfunc neoverse_n1_reset_func 103b04ea14bSJohn Tsichritzis mov x19, x30 1048074448fSJohn Tsichritzis 105eca6e453SSami Mujawar bl neoverse_n1_disable_speculative_loads 1068074448fSJohn Tsichritzis 107632ab3ebSLouis Mayencourt /* Forces all cacheable atomic instructions to be near */ 108632ab3ebSLouis Mayencourt mrs x0, NEOVERSE_N1_CPUACTLR2_EL1 109632ab3ebSLouis Mayencourt orr x0, x0, #NEOVERSE_N1_CPUACTLR2_EL1_BIT_2 110632ab3ebSLouis Mayencourt msr NEOVERSE_N1_CPUACTLR2_EL1, x0 111632ab3ebSLouis Mayencourt isb 112632ab3ebSLouis Mayencourt 113b04ea14bSJohn Tsichritzis bl cpu_get_rev_var 114b04ea14bSJohn Tsichritzis mov x18, x0 115b04ea14bSJohn Tsichritzis 116da6d75a0SJohn Tsichritzis#if ERRATA_N1_1043202 117b04ea14bSJohn Tsichritzis mov x0, x18 118da6d75a0SJohn Tsichritzis bl errata_n1_1043202_wa 119b04ea14bSJohn Tsichritzis#endif 120b04ea14bSJohn Tsichritzis 121*5f5d0763SAndre Przywara#if ERRATA_N1_1315703 122*5f5d0763SAndre Przywara mov x0, x18 123*5f5d0763SAndre Przywara bl errata_n1_1315703_wa 124*5f5d0763SAndre Przywara#endif 125*5f5d0763SAndre Przywara 126b04ea14bSJohn Tsichritzis#if ENABLE_AMU 127b04ea14bSJohn Tsichritzis /* Make sure accesses from EL0/EL1 and EL2 are not trapped to EL3 */ 128b04ea14bSJohn Tsichritzis mrs x0, actlr_el3 129da6d75a0SJohn Tsichritzis orr x0, x0, #NEOVERSE_N1_ACTLR_AMEN_BIT 130b04ea14bSJohn Tsichritzis msr actlr_el3, x0 131b04ea14bSJohn Tsichritzis isb 132b04ea14bSJohn Tsichritzis 133b04ea14bSJohn Tsichritzis /* Make sure accesses from EL0/EL1 are not trapped to EL2 */ 134b04ea14bSJohn Tsichritzis mrs x0, actlr_el2 135da6d75a0SJohn Tsichritzis orr x0, x0, #NEOVERSE_N1_ACTLR_AMEN_BIT 136b04ea14bSJohn Tsichritzis msr actlr_el2, x0 137b04ea14bSJohn Tsichritzis isb 138b04ea14bSJohn Tsichritzis 139b04ea14bSJohn Tsichritzis /* Enable group0 counters */ 140da6d75a0SJohn Tsichritzis mov x0, #NEOVERSE_N1_AMU_GROUP0_MASK 141b04ea14bSJohn Tsichritzis msr CPUAMCNTENSET_EL0, x0 142b04ea14bSJohn Tsichritzis isb 143b04ea14bSJohn Tsichritzis#endif 144b04ea14bSJohn Tsichritzis ret x19 145da6d75a0SJohn Tsichritzisendfunc neoverse_n1_reset_func 146b04ea14bSJohn Tsichritzis 147b04ea14bSJohn Tsichritzis /* --------------------------------------------- 148b04ea14bSJohn Tsichritzis * HW will do the cache maintenance while powering down 149b04ea14bSJohn Tsichritzis * --------------------------------------------- 150b04ea14bSJohn Tsichritzis */ 151da6d75a0SJohn Tsichritzisfunc neoverse_n1_core_pwr_dwn 152b04ea14bSJohn Tsichritzis /* --------------------------------------------- 153b04ea14bSJohn Tsichritzis * Enable CPU power down bit in power control register 154b04ea14bSJohn Tsichritzis * --------------------------------------------- 155b04ea14bSJohn Tsichritzis */ 156da6d75a0SJohn Tsichritzis mrs x0, NEOVERSE_N1_CPUPWRCTLR_EL1 157da6d75a0SJohn Tsichritzis orr x0, x0, #NEOVERSE_N1_CORE_PWRDN_EN_MASK 158da6d75a0SJohn Tsichritzis msr NEOVERSE_N1_CPUPWRCTLR_EL1, x0 159b04ea14bSJohn Tsichritzis isb 160b04ea14bSJohn Tsichritzis ret 161da6d75a0SJohn Tsichritzisendfunc neoverse_n1_core_pwr_dwn 162b04ea14bSJohn Tsichritzis 163b04ea14bSJohn Tsichritzis#if REPORT_ERRATA 164b04ea14bSJohn Tsichritzis/* 165da6d75a0SJohn Tsichritzis * Errata printing function for Neoverse N1. Must follow AAPCS. 166b04ea14bSJohn Tsichritzis */ 167da6d75a0SJohn Tsichritzisfunc neoverse_n1_errata_report 168b04ea14bSJohn Tsichritzis stp x8, x30, [sp, #-16]! 169b04ea14bSJohn Tsichritzis 170b04ea14bSJohn Tsichritzis bl cpu_get_rev_var 171b04ea14bSJohn Tsichritzis mov x8, x0 172b04ea14bSJohn Tsichritzis 173b04ea14bSJohn Tsichritzis /* 174b04ea14bSJohn Tsichritzis * Report all errata. The revision-variant information is passed to 175b04ea14bSJohn Tsichritzis * checking functions of each errata. 176b04ea14bSJohn Tsichritzis */ 177da6d75a0SJohn Tsichritzis report_errata ERRATA_N1_1043202, neoverse_n1, 1043202 178*5f5d0763SAndre Przywara report_errata ERRATA_N1_1315703, neoverse_n1, 1315703 179b04ea14bSJohn Tsichritzis 180b04ea14bSJohn Tsichritzis ldp x8, x30, [sp], #16 181b04ea14bSJohn Tsichritzis ret 182da6d75a0SJohn Tsichritzisendfunc neoverse_n1_errata_report 183b04ea14bSJohn Tsichritzis#endif 184b04ea14bSJohn Tsichritzis 185b04ea14bSJohn Tsichritzis /* --------------------------------------------- 186da6d75a0SJohn Tsichritzis * This function provides neoverse_n1 specific 187b04ea14bSJohn Tsichritzis * register information for crash reporting. 188b04ea14bSJohn Tsichritzis * It needs to return with x6 pointing to 189b04ea14bSJohn Tsichritzis * a list of register names in ascii and 190b04ea14bSJohn Tsichritzis * x8 - x15 having values of registers to be 191b04ea14bSJohn Tsichritzis * reported. 192b04ea14bSJohn Tsichritzis * --------------------------------------------- 193b04ea14bSJohn Tsichritzis */ 194da6d75a0SJohn Tsichritzis.section .rodata.neoverse_n1_regs, "aS" 195da6d75a0SJohn Tsichritzisneoverse_n1_regs: /* The ascii list of register names to be reported */ 196b04ea14bSJohn Tsichritzis .asciz "cpuectlr_el1", "" 197b04ea14bSJohn Tsichritzis 198da6d75a0SJohn Tsichritzisfunc neoverse_n1_cpu_reg_dump 199da6d75a0SJohn Tsichritzis adr x6, neoverse_n1_regs 200da6d75a0SJohn Tsichritzis mrs x8, NEOVERSE_N1_CPUECTLR_EL1 201b04ea14bSJohn Tsichritzis ret 202da6d75a0SJohn Tsichritzisendfunc neoverse_n1_cpu_reg_dump 203b04ea14bSJohn Tsichritzis 204da6d75a0SJohn Tsichritzisdeclare_cpu_ops neoverse_n1, NEOVERSE_N1_MIDR, \ 205da6d75a0SJohn Tsichritzis neoverse_n1_reset_func, \ 206da6d75a0SJohn Tsichritzis neoverse_n1_core_pwr_dwn 207