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 18*629d04f5SJohn Tsichritzis/* 64-bit only core */ 19*629d04f5SJohn Tsichritzis#if CTX_INCLUDE_AARCH32_REGS == 1 20*629d04f5SJohn Tsichritzis#error "Neoverse-N1 supports only AArch64. Compile with CTX_INCLUDE_AARCH32_REGS=0" 21*629d04f5SJohn Tsichritzis#endif 22*629d04f5SJohn Tsichritzis 23b04ea14bSJohn Tsichritzis/* -------------------------------------------------- 24da6d75a0SJohn Tsichritzis * Errata Workaround for Neoverse N1 Errata 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 78da6d75a0SJohn Tsichritzisfunc neoverse_n1_reset_func 79b04ea14bSJohn Tsichritzis mov x19, x30 808074448fSJohn Tsichritzis 81eca6e453SSami Mujawar bl neoverse_n1_disable_speculative_loads 828074448fSJohn Tsichritzis 83632ab3ebSLouis Mayencourt /* Forces all cacheable atomic instructions to be near */ 84632ab3ebSLouis Mayencourt mrs x0, NEOVERSE_N1_CPUACTLR2_EL1 85632ab3ebSLouis Mayencourt orr x0, x0, #NEOVERSE_N1_CPUACTLR2_EL1_BIT_2 86632ab3ebSLouis Mayencourt msr NEOVERSE_N1_CPUACTLR2_EL1, x0 87632ab3ebSLouis Mayencourt isb 88632ab3ebSLouis Mayencourt 89b04ea14bSJohn Tsichritzis bl cpu_get_rev_var 90b04ea14bSJohn Tsichritzis mov x18, x0 91b04ea14bSJohn Tsichritzis 92da6d75a0SJohn Tsichritzis#if ERRATA_N1_1043202 93b04ea14bSJohn Tsichritzis mov x0, x18 94da6d75a0SJohn Tsichritzis bl errata_n1_1043202_wa 95b04ea14bSJohn Tsichritzis#endif 96b04ea14bSJohn Tsichritzis 97b04ea14bSJohn Tsichritzis#if ENABLE_AMU 98b04ea14bSJohn Tsichritzis /* Make sure accesses from EL0/EL1 and EL2 are not trapped to EL3 */ 99b04ea14bSJohn Tsichritzis mrs x0, actlr_el3 100da6d75a0SJohn Tsichritzis orr x0, x0, #NEOVERSE_N1_ACTLR_AMEN_BIT 101b04ea14bSJohn Tsichritzis msr actlr_el3, x0 102b04ea14bSJohn Tsichritzis isb 103b04ea14bSJohn Tsichritzis 104b04ea14bSJohn Tsichritzis /* Make sure accesses from EL0/EL1 are not trapped to EL2 */ 105b04ea14bSJohn Tsichritzis mrs x0, actlr_el2 106da6d75a0SJohn Tsichritzis orr x0, x0, #NEOVERSE_N1_ACTLR_AMEN_BIT 107b04ea14bSJohn Tsichritzis msr actlr_el2, x0 108b04ea14bSJohn Tsichritzis isb 109b04ea14bSJohn Tsichritzis 110b04ea14bSJohn Tsichritzis /* Enable group0 counters */ 111da6d75a0SJohn Tsichritzis mov x0, #NEOVERSE_N1_AMU_GROUP0_MASK 112b04ea14bSJohn Tsichritzis msr CPUAMCNTENSET_EL0, x0 113b04ea14bSJohn Tsichritzis isb 114b04ea14bSJohn Tsichritzis#endif 115b04ea14bSJohn Tsichritzis ret x19 116da6d75a0SJohn Tsichritzisendfunc neoverse_n1_reset_func 117b04ea14bSJohn Tsichritzis 118b04ea14bSJohn Tsichritzis /* --------------------------------------------- 119b04ea14bSJohn Tsichritzis * HW will do the cache maintenance while powering down 120b04ea14bSJohn Tsichritzis * --------------------------------------------- 121b04ea14bSJohn Tsichritzis */ 122da6d75a0SJohn Tsichritzisfunc neoverse_n1_core_pwr_dwn 123b04ea14bSJohn Tsichritzis /* --------------------------------------------- 124b04ea14bSJohn Tsichritzis * Enable CPU power down bit in power control register 125b04ea14bSJohn Tsichritzis * --------------------------------------------- 126b04ea14bSJohn Tsichritzis */ 127da6d75a0SJohn Tsichritzis mrs x0, NEOVERSE_N1_CPUPWRCTLR_EL1 128da6d75a0SJohn Tsichritzis orr x0, x0, #NEOVERSE_N1_CORE_PWRDN_EN_MASK 129da6d75a0SJohn Tsichritzis msr NEOVERSE_N1_CPUPWRCTLR_EL1, x0 130b04ea14bSJohn Tsichritzis isb 131b04ea14bSJohn Tsichritzis ret 132da6d75a0SJohn Tsichritzisendfunc neoverse_n1_core_pwr_dwn 133b04ea14bSJohn Tsichritzis 134b04ea14bSJohn Tsichritzis#if REPORT_ERRATA 135b04ea14bSJohn Tsichritzis/* 136da6d75a0SJohn Tsichritzis * Errata printing function for Neoverse N1. Must follow AAPCS. 137b04ea14bSJohn Tsichritzis */ 138da6d75a0SJohn Tsichritzisfunc neoverse_n1_errata_report 139b04ea14bSJohn Tsichritzis stp x8, x30, [sp, #-16]! 140b04ea14bSJohn Tsichritzis 141b04ea14bSJohn Tsichritzis bl cpu_get_rev_var 142b04ea14bSJohn Tsichritzis mov x8, x0 143b04ea14bSJohn Tsichritzis 144b04ea14bSJohn Tsichritzis /* 145b04ea14bSJohn Tsichritzis * Report all errata. The revision-variant information is passed to 146b04ea14bSJohn Tsichritzis * checking functions of each errata. 147b04ea14bSJohn Tsichritzis */ 148da6d75a0SJohn Tsichritzis report_errata ERRATA_N1_1043202, neoverse_n1, 1043202 149b04ea14bSJohn Tsichritzis 150b04ea14bSJohn Tsichritzis ldp x8, x30, [sp], #16 151b04ea14bSJohn Tsichritzis ret 152da6d75a0SJohn Tsichritzisendfunc neoverse_n1_errata_report 153b04ea14bSJohn Tsichritzis#endif 154b04ea14bSJohn Tsichritzis 155b04ea14bSJohn Tsichritzis /* --------------------------------------------- 156da6d75a0SJohn Tsichritzis * This function provides neoverse_n1 specific 157b04ea14bSJohn Tsichritzis * register information for crash reporting. 158b04ea14bSJohn Tsichritzis * It needs to return with x6 pointing to 159b04ea14bSJohn Tsichritzis * a list of register names in ascii and 160b04ea14bSJohn Tsichritzis * x8 - x15 having values of registers to be 161b04ea14bSJohn Tsichritzis * reported. 162b04ea14bSJohn Tsichritzis * --------------------------------------------- 163b04ea14bSJohn Tsichritzis */ 164da6d75a0SJohn Tsichritzis.section .rodata.neoverse_n1_regs, "aS" 165da6d75a0SJohn Tsichritzisneoverse_n1_regs: /* The ascii list of register names to be reported */ 166b04ea14bSJohn Tsichritzis .asciz "cpuectlr_el1", "" 167b04ea14bSJohn Tsichritzis 168da6d75a0SJohn Tsichritzisfunc neoverse_n1_cpu_reg_dump 169da6d75a0SJohn Tsichritzis adr x6, neoverse_n1_regs 170da6d75a0SJohn Tsichritzis mrs x8, NEOVERSE_N1_CPUECTLR_EL1 171b04ea14bSJohn Tsichritzis ret 172da6d75a0SJohn Tsichritzisendfunc neoverse_n1_cpu_reg_dump 173b04ea14bSJohn Tsichritzis 174da6d75a0SJohn Tsichritzisdeclare_cpu_ops neoverse_n1, NEOVERSE_N1_MIDR, \ 175da6d75a0SJohn Tsichritzis neoverse_n1_reset_func, \ 176da6d75a0SJohn Tsichritzis neoverse_n1_core_pwr_dwn 177