1*2b357c31SManoj Kumar/* 2*2b357c31SManoj Kumar * Copyright (c) 2020, Arm Limited. All rights reserved. 3*2b357c31SManoj Kumar * 4*2b357c31SManoj Kumar * SPDX-License-Identifier: BSD-3-Clause 5*2b357c31SManoj Kumar */ 6*2b357c31SManoj Kumar 7*2b357c31SManoj Kumar#include <arch.h> 8*2b357c31SManoj Kumar#include <asm_macros.S> 9*2b357c31SManoj Kumar#include <context.h> 10*2b357c31SManoj Kumar#include <cpu_macros.S> 11*2b357c31SManoj Kumar#include <cpuamu.h> 12*2b357c31SManoj Kumar#include <rainier.h> 13*2b357c31SManoj Kumar 14*2b357c31SManoj Kumar/* Hardware handled coherency */ 15*2b357c31SManoj Kumar#if HW_ASSISTED_COHERENCY == 0 16*2b357c31SManoj Kumar#error "Rainier CPU must be compiled with HW_ASSISTED_COHERENCY enabled" 17*2b357c31SManoj Kumar#endif 18*2b357c31SManoj Kumar 19*2b357c31SManoj Kumar/* 64-bit only core */ 20*2b357c31SManoj Kumar#if CTX_INCLUDE_AARCH32_REGS == 1 21*2b357c31SManoj Kumar#error "Rainier CPU supports only AArch64. Compile with CTX_INCLUDE_AARCH32_REGS=0" 22*2b357c31SManoj Kumar#endif 23*2b357c31SManoj Kumar 24*2b357c31SManoj Kumar#if ERRATA_RAINIER_IC_TRAP 25*2b357c31SManoj Kumar .global rainier_errata_ic_trap_handler 26*2b357c31SManoj Kumar#endif 27*2b357c31SManoj Kumar 28*2b357c31SManoj Kumar/* -------------------------------------------------- 29*2b357c31SManoj Kumar * Disable speculative loads if Rainier supports 30*2b357c31SManoj Kumar * SSBS. 31*2b357c31SManoj Kumar * 32*2b357c31SManoj Kumar * Shall clobber: x0. 33*2b357c31SManoj Kumar * -------------------------------------------------- 34*2b357c31SManoj Kumar */ 35*2b357c31SManoj Kumarfunc rainier_disable_speculative_loads 36*2b357c31SManoj Kumar /* Check if the PE implements SSBS */ 37*2b357c31SManoj Kumar mrs x0, id_aa64pfr1_el1 38*2b357c31SManoj Kumar tst x0, #(ID_AA64PFR1_EL1_SSBS_MASK << ID_AA64PFR1_EL1_SSBS_SHIFT) 39*2b357c31SManoj Kumar b.eq 1f 40*2b357c31SManoj Kumar 41*2b357c31SManoj Kumar /* Disable speculative loads */ 42*2b357c31SManoj Kumar msr SSBS, xzr 43*2b357c31SManoj Kumar 44*2b357c31SManoj Kumar1: 45*2b357c31SManoj Kumar ret 46*2b357c31SManoj Kumarendfunc rainier_disable_speculative_loads 47*2b357c31SManoj Kumar 48*2b357c31SManoj Kumar/* -------------------------------------------------- 49*2b357c31SManoj Kumar * Errata Workaround for Neoverse N1 Erratum 1542419. 50*2b357c31SManoj Kumar * This applies to revisions r3p0 - r4p0 of Neoverse N1 51*2b357c31SManoj Kumar * Since Rainier core is based on Neoverse N1 r4p0, this 52*2b357c31SManoj Kumar * errata applies to Rainier core r0p0 53*2b357c31SManoj Kumar * Inputs: 54*2b357c31SManoj Kumar * x0: variant[4:7] and revision[0:3] of current cpu. 55*2b357c31SManoj Kumar * Shall clobber: x0-x17 56*2b357c31SManoj Kumar * -------------------------------------------------- 57*2b357c31SManoj Kumar */ 58*2b357c31SManoj Kumarfunc errata_n1_1542419_wa 59*2b357c31SManoj Kumar /* Compare x0 against revision r3p0 and r4p0 */ 60*2b357c31SManoj Kumar mov x17, x30 61*2b357c31SManoj Kumar bl check_errata_1542419 62*2b357c31SManoj Kumar cbz x0, 1f 63*2b357c31SManoj Kumar 64*2b357c31SManoj Kumar /* Apply instruction patching sequence */ 65*2b357c31SManoj Kumar mov x0, xzr 66*2b357c31SManoj Kumar msr CPUPSELR_EL3, x0 67*2b357c31SManoj Kumar ldr x0, =0xEE670D35 68*2b357c31SManoj Kumar msr CPUPOR_EL3, x0 69*2b357c31SManoj Kumar ldr x0, =0xFFFF0FFF 70*2b357c31SManoj Kumar msr CPUPMR_EL3, x0 71*2b357c31SManoj Kumar ldr x0, =0x08000020007D 72*2b357c31SManoj Kumar msr CPUPCR_EL3, x0 73*2b357c31SManoj Kumar isb 74*2b357c31SManoj Kumar1: 75*2b357c31SManoj Kumar ret x17 76*2b357c31SManoj Kumarendfunc errata_n1_1542419_wa 77*2b357c31SManoj Kumar 78*2b357c31SManoj Kumarfunc check_errata_1542419 79*2b357c31SManoj Kumar /* Applies to Rainier core r0p0. */ 80*2b357c31SManoj Kumar mov x1, #0x00 81*2b357c31SManoj Kumar b cpu_rev_var_ls 82*2b357c31SManoj Kumarendfunc check_errata_1542419 83*2b357c31SManoj Kumar 84*2b357c31SManoj Kumarfunc rainier_reset_func 85*2b357c31SManoj Kumar mov x19, x30 86*2b357c31SManoj Kumar 87*2b357c31SManoj Kumar bl rainier_disable_speculative_loads 88*2b357c31SManoj Kumar 89*2b357c31SManoj Kumar /* Forces all cacheable atomic instructions to be near */ 90*2b357c31SManoj Kumar mrs x0, RAINIER_CPUACTLR2_EL1 91*2b357c31SManoj Kumar orr x0, x0, #RAINIER_CPUACTLR2_EL1_BIT_2 92*2b357c31SManoj Kumar msr RAINIER_CPUACTLR2_EL1, x0 93*2b357c31SManoj Kumar isb 94*2b357c31SManoj Kumar 95*2b357c31SManoj Kumar bl cpu_get_rev_var 96*2b357c31SManoj Kumar mov x18, x0 97*2b357c31SManoj Kumar 98*2b357c31SManoj Kumar#if ERRATA_N1_1542419 99*2b357c31SManoj Kumar mov x0, x18 100*2b357c31SManoj Kumar bl errata_n1_1542419_wa 101*2b357c31SManoj Kumar#endif 102*2b357c31SManoj Kumar 103*2b357c31SManoj Kumar#if ENABLE_AMU 104*2b357c31SManoj Kumar /* Make sure accesses from EL0/EL1 and EL2 are not trapped to EL3 */ 105*2b357c31SManoj Kumar mrs x0, actlr_el3 106*2b357c31SManoj Kumar orr x0, x0, #RAINIER_ACTLR_AMEN_BIT 107*2b357c31SManoj Kumar msr actlr_el3, x0 108*2b357c31SManoj Kumar 109*2b357c31SManoj Kumar /* Make sure accesses from EL0/EL1 are not trapped to EL2 */ 110*2b357c31SManoj Kumar mrs x0, actlr_el2 111*2b357c31SManoj Kumar orr x0, x0, #RAINIER_ACTLR_AMEN_BIT 112*2b357c31SManoj Kumar msr actlr_el2, x0 113*2b357c31SManoj Kumar 114*2b357c31SManoj Kumar /* Enable group0 counters */ 115*2b357c31SManoj Kumar mov x0, #RAINIER_AMU_GROUP0_MASK 116*2b357c31SManoj Kumar msr CPUAMCNTENSET_EL0, x0 117*2b357c31SManoj Kumar#endif 118*2b357c31SManoj Kumar 119*2b357c31SManoj Kumar isb 120*2b357c31SManoj Kumar ret x19 121*2b357c31SManoj Kumarendfunc rainier_reset_func 122*2b357c31SManoj Kumar 123*2b357c31SManoj Kumar /* --------------------------------------------- 124*2b357c31SManoj Kumar * HW will do the cache maintenance while powering down 125*2b357c31SManoj Kumar * --------------------------------------------- 126*2b357c31SManoj Kumar */ 127*2b357c31SManoj Kumarfunc rainier_core_pwr_dwn 128*2b357c31SManoj Kumar /* --------------------------------------------- 129*2b357c31SManoj Kumar * Enable CPU power down bit in power control register 130*2b357c31SManoj Kumar * --------------------------------------------- 131*2b357c31SManoj Kumar */ 132*2b357c31SManoj Kumar mrs x0, RAINIER_CPUPWRCTLR_EL1 133*2b357c31SManoj Kumar orr x0, x0, #RAINIER_CORE_PWRDN_EN_MASK 134*2b357c31SManoj Kumar msr RAINIER_CPUPWRCTLR_EL1, x0 135*2b357c31SManoj Kumar isb 136*2b357c31SManoj Kumar ret 137*2b357c31SManoj Kumarendfunc rainier_core_pwr_dwn 138*2b357c31SManoj Kumar 139*2b357c31SManoj Kumar#if REPORT_ERRATA 140*2b357c31SManoj Kumar/* 141*2b357c31SManoj Kumar * Errata printing function for Rainier. Must follow AAPCS. 142*2b357c31SManoj Kumar */ 143*2b357c31SManoj Kumarfunc rainier_errata_report 144*2b357c31SManoj Kumar stp x8, x30, [sp, #-16]! 145*2b357c31SManoj Kumar 146*2b357c31SManoj Kumar bl cpu_get_rev_var 147*2b357c31SManoj Kumar mov x8, x0 148*2b357c31SManoj Kumar 149*2b357c31SManoj Kumar /* 150*2b357c31SManoj Kumar * Report all errata. The revision-variant information is passed to 151*2b357c31SManoj Kumar * checking functions of each errata. 152*2b357c31SManoj Kumar */ 153*2b357c31SManoj Kumar report_errata ERRATA_N1_1542419, rainier, 1542419 154*2b357c31SManoj Kumar 155*2b357c31SManoj Kumar ldp x8, x30, [sp], #16 156*2b357c31SManoj Kumar ret 157*2b357c31SManoj Kumarendfunc rainier_errata_report 158*2b357c31SManoj Kumar#endif 159*2b357c31SManoj Kumar 160*2b357c31SManoj Kumar/* 161*2b357c31SManoj Kumar * Handle trap of EL0 IC IVAU instructions to EL3 by executing a TLB 162*2b357c31SManoj Kumar * inner-shareable invalidation to an arbitrary address followed by a DSB. 163*2b357c31SManoj Kumar * 164*2b357c31SManoj Kumar * x1: Exception Syndrome 165*2b357c31SManoj Kumar */ 166*2b357c31SManoj Kumarfunc rainier_errata_ic_trap_handler 167*2b357c31SManoj Kumar cmp x1, #RAINIER_EC_IC_TRAP 168*2b357c31SManoj Kumar b.ne 1f 169*2b357c31SManoj Kumar tlbi vae3is, xzr 170*2b357c31SManoj Kumar dsb sy 171*2b357c31SManoj Kumar 172*2b357c31SManoj Kumar # Skip the IC instruction itself 173*2b357c31SManoj Kumar mrs x3, elr_el3 174*2b357c31SManoj Kumar add x3, x3, #4 175*2b357c31SManoj Kumar msr elr_el3, x3 176*2b357c31SManoj Kumar 177*2b357c31SManoj Kumar ldp x0, x1, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X0] 178*2b357c31SManoj Kumar ldp x2, x3, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X2] 179*2b357c31SManoj Kumar ldp x4, x5, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X4] 180*2b357c31SManoj Kumar ldr x30, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_LR] 181*2b357c31SManoj Kumar 182*2b357c31SManoj Kumar#if IMAGE_BL31 && RAS_EXTENSION 183*2b357c31SManoj Kumar /* 184*2b357c31SManoj Kumar * Issue Error Synchronization Barrier to synchronize SErrors before 185*2b357c31SManoj Kumar * exiting EL3. We're running with EAs unmasked, so any synchronized 186*2b357c31SManoj Kumar * errors would be taken immediately; therefore no need to inspect 187*2b357c31SManoj Kumar * DISR_EL1 register. 188*2b357c31SManoj Kumar */ 189*2b357c31SManoj Kumar esb 190*2b357c31SManoj Kumar#endif 191*2b357c31SManoj Kumar eret 192*2b357c31SManoj Kumar1: 193*2b357c31SManoj Kumar ret 194*2b357c31SManoj Kumarendfunc rainier_errata_ic_trap_handler 195*2b357c31SManoj Kumar 196*2b357c31SManoj Kumar /* --------------------------------------------- 197*2b357c31SManoj Kumar * This function provides Rainier specific 198*2b357c31SManoj Kumar * register information for crash reporting. 199*2b357c31SManoj Kumar * It needs to return with x6 pointing to 200*2b357c31SManoj Kumar * a list of register names in ascii and 201*2b357c31SManoj Kumar * x8 - x15 having values of registers to be 202*2b357c31SManoj Kumar * reported. 203*2b357c31SManoj Kumar * --------------------------------------------- 204*2b357c31SManoj Kumar */ 205*2b357c31SManoj Kumar.section .rodata.rainier_regs, "aS" 206*2b357c31SManoj Kumarrainier_regs: /* The ascii list of register names to be reported */ 207*2b357c31SManoj Kumar .asciz "cpuectlr_el1", "" 208*2b357c31SManoj Kumar 209*2b357c31SManoj Kumarfunc rainier_cpu_reg_dump 210*2b357c31SManoj Kumar adr x6, rainier_regs 211*2b357c31SManoj Kumar mrs x8, RAINIER_CPUECTLR_EL1 212*2b357c31SManoj Kumar ret 213*2b357c31SManoj Kumarendfunc rainier_cpu_reg_dump 214*2b357c31SManoj Kumar 215*2b357c31SManoj Kumardeclare_cpu_ops_eh rainier, RAINIER_MIDR, \ 216*2b357c31SManoj Kumar rainier_reset_func, \ 217*2b357c31SManoj Kumar rainier_errata_ic_trap_handler, \ 218*2b357c31SManoj Kumar rainier_core_pwr_dwn 219