12b357c31SManoj Kumar/* 2*a72144fbSManoj Kumar * Copyright (c) 2020-2022, Arm Limited. All rights reserved. 32b357c31SManoj Kumar * 42b357c31SManoj Kumar * SPDX-License-Identifier: BSD-3-Clause 52b357c31SManoj Kumar */ 62b357c31SManoj Kumar 72b357c31SManoj Kumar#include <arch.h> 82b357c31SManoj Kumar#include <asm_macros.S> 92b357c31SManoj Kumar#include <context.h> 102b357c31SManoj Kumar#include <cpu_macros.S> 112b357c31SManoj Kumar#include <cpuamu.h> 122b357c31SManoj Kumar#include <rainier.h> 132b357c31SManoj Kumar 142b357c31SManoj Kumar/* Hardware handled coherency */ 152b357c31SManoj Kumar#if HW_ASSISTED_COHERENCY == 0 162b357c31SManoj Kumar#error "Rainier CPU must be compiled with HW_ASSISTED_COHERENCY enabled" 172b357c31SManoj Kumar#endif 182b357c31SManoj Kumar 192b357c31SManoj Kumar/* 64-bit only core */ 202b357c31SManoj Kumar#if CTX_INCLUDE_AARCH32_REGS == 1 212b357c31SManoj Kumar#error "Rainier CPU supports only AArch64. Compile with CTX_INCLUDE_AARCH32_REGS=0" 222b357c31SManoj Kumar#endif 232b357c31SManoj Kumar 242b357c31SManoj Kumar/* -------------------------------------------------- 252b357c31SManoj Kumar * Disable speculative loads if Rainier supports 262b357c31SManoj Kumar * SSBS. 272b357c31SManoj Kumar * 282b357c31SManoj Kumar * Shall clobber: x0. 292b357c31SManoj Kumar * -------------------------------------------------- 302b357c31SManoj Kumar */ 312b357c31SManoj Kumarfunc rainier_disable_speculative_loads 322b357c31SManoj Kumar /* Check if the PE implements SSBS */ 332b357c31SManoj Kumar mrs x0, id_aa64pfr1_el1 342b357c31SManoj Kumar tst x0, #(ID_AA64PFR1_EL1_SSBS_MASK << ID_AA64PFR1_EL1_SSBS_SHIFT) 352b357c31SManoj Kumar b.eq 1f 362b357c31SManoj Kumar 372b357c31SManoj Kumar /* Disable speculative loads */ 382b357c31SManoj Kumar msr SSBS, xzr 392b357c31SManoj Kumar 402b357c31SManoj Kumar1: 412b357c31SManoj Kumar ret 422b357c31SManoj Kumarendfunc rainier_disable_speculative_loads 432b357c31SManoj Kumar 44*a72144fbSManoj Kumar /* -------------------------------------------------- 45*a72144fbSManoj Kumar * Errata Workaround for Neoverse N1 Errata #1868343. 46*a72144fbSManoj Kumar * This applies to revision <= r4p0 of Neoverse N1. 47*a72144fbSManoj Kumar * This workaround is the same as the workaround for 48*a72144fbSManoj Kumar * errata 1262606 and 1275112 but applies to a wider 49*a72144fbSManoj Kumar * revision range. 50*a72144fbSManoj Kumar * Rainier R0P0 is based on Neoverse N1 R4P0 so the 51*a72144fbSManoj Kumar * workaround checks for r0p0 version of Rainier CPU. 52*a72144fbSManoj Kumar * Inputs: 53*a72144fbSManoj Kumar * x0: variant[4:7] and revision[0:3] of current cpu. 54*a72144fbSManoj Kumar * Shall clobber: x0, x1 & x17 55*a72144fbSManoj Kumar * -------------------------------------------------- 56*a72144fbSManoj Kumar */ 57*a72144fbSManoj Kumarfunc errata_n1_1868343_wa 58*a72144fbSManoj Kumar /* 59*a72144fbSManoj Kumar * Compare x0 against revision r4p0 60*a72144fbSManoj Kumar */ 61*a72144fbSManoj Kumar mov x17, x30 62*a72144fbSManoj Kumar bl check_errata_1868343 63*a72144fbSManoj Kumar cbz x0, 1f 64*a72144fbSManoj Kumar mrs x1, RAINIER_CPUACTLR_EL1 65*a72144fbSManoj Kumar orr x1, x1, RAINIER_CPUACTLR_EL1_BIT_13 66*a72144fbSManoj Kumar msr RAINIER_CPUACTLR_EL1, x1 67*a72144fbSManoj Kumar isb 68*a72144fbSManoj Kumar1: 69*a72144fbSManoj Kumar ret x17 70*a72144fbSManoj Kumarendfunc errata_n1_1868343_wa 71*a72144fbSManoj Kumar 72*a72144fbSManoj Kumarfunc check_errata_1868343 73*a72144fbSManoj Kumar /* Applies to r0p0 of Rainier CPU */ 74*a72144fbSManoj Kumar mov x1, #0x00 75*a72144fbSManoj Kumar b cpu_rev_var_ls 76*a72144fbSManoj Kumarendfunc check_errata_1868343 77*a72144fbSManoj Kumar 782b357c31SManoj Kumarfunc rainier_reset_func 792b357c31SManoj Kumar mov x19, x30 802b357c31SManoj Kumar 812b357c31SManoj Kumar bl rainier_disable_speculative_loads 822b357c31SManoj Kumar 832b357c31SManoj Kumar /* Forces all cacheable atomic instructions to be near */ 842b357c31SManoj Kumar mrs x0, RAINIER_CPUACTLR2_EL1 852b357c31SManoj Kumar orr x0, x0, #RAINIER_CPUACTLR2_EL1_BIT_2 862b357c31SManoj Kumar msr RAINIER_CPUACTLR2_EL1, x0 872b357c31SManoj Kumar isb 882b357c31SManoj Kumar 892b357c31SManoj Kumar bl cpu_get_rev_var 902b357c31SManoj Kumar mov x18, x0 912b357c31SManoj Kumar 92*a72144fbSManoj Kumar#if ERRATA_N1_1868343 93*a72144fbSManoj Kumar mov x0, x18 94*a72144fbSManoj Kumar bl errata_n1_1868343_wa 95*a72144fbSManoj Kumar#endif 96*a72144fbSManoj Kumar 972b357c31SManoj Kumar#if ENABLE_AMU 982b357c31SManoj Kumar /* Make sure accesses from EL0/EL1 and EL2 are not trapped to EL3 */ 992b357c31SManoj Kumar mrs x0, actlr_el3 1002b357c31SManoj Kumar orr x0, x0, #RAINIER_ACTLR_AMEN_BIT 1012b357c31SManoj Kumar msr actlr_el3, x0 1022b357c31SManoj Kumar 1032b357c31SManoj Kumar /* Make sure accesses from EL0/EL1 are not trapped to EL2 */ 1042b357c31SManoj Kumar mrs x0, actlr_el2 1052b357c31SManoj Kumar orr x0, x0, #RAINIER_ACTLR_AMEN_BIT 1062b357c31SManoj Kumar msr actlr_el2, x0 1072b357c31SManoj Kumar 1082b357c31SManoj Kumar /* Enable group0 counters */ 1092b357c31SManoj Kumar mov x0, #RAINIER_AMU_GROUP0_MASK 1102b357c31SManoj Kumar msr CPUAMCNTENSET_EL0, x0 1112b357c31SManoj Kumar#endif 1122b357c31SManoj Kumar 1132b357c31SManoj Kumar isb 1142b357c31SManoj Kumar ret x19 1152b357c31SManoj Kumarendfunc rainier_reset_func 1162b357c31SManoj Kumar 1172b357c31SManoj Kumar /* --------------------------------------------- 1182b357c31SManoj Kumar * HW will do the cache maintenance while powering down 1192b357c31SManoj Kumar * --------------------------------------------- 1202b357c31SManoj Kumar */ 1212b357c31SManoj Kumarfunc rainier_core_pwr_dwn 1222b357c31SManoj Kumar /* --------------------------------------------- 1232b357c31SManoj Kumar * Enable CPU power down bit in power control register 1242b357c31SManoj Kumar * --------------------------------------------- 1252b357c31SManoj Kumar */ 1262b357c31SManoj Kumar mrs x0, RAINIER_CPUPWRCTLR_EL1 1272b357c31SManoj Kumar orr x0, x0, #RAINIER_CORE_PWRDN_EN_MASK 1282b357c31SManoj Kumar msr RAINIER_CPUPWRCTLR_EL1, x0 1292b357c31SManoj Kumar isb 1302b357c31SManoj Kumar ret 1312b357c31SManoj Kumarendfunc rainier_core_pwr_dwn 1322b357c31SManoj Kumar 1332b357c31SManoj Kumar#if REPORT_ERRATA 1342b357c31SManoj Kumar/* 1352b357c31SManoj Kumar * Errata printing function for Rainier. Must follow AAPCS. 1362b357c31SManoj Kumar */ 1372b357c31SManoj Kumarfunc rainier_errata_report 1382b357c31SManoj Kumar stp x8, x30, [sp, #-16]! 1392b357c31SManoj Kumar 1402b357c31SManoj Kumar bl cpu_get_rev_var 1412b357c31SManoj Kumar mov x8, x0 1422b357c31SManoj Kumar 143*a72144fbSManoj Kumar /* 144*a72144fbSManoj Kumar * Report all errata. The revision-variant information is passed to 145*a72144fbSManoj Kumar * checking functions of each errata. 146*a72144fbSManoj Kumar */ 147*a72144fbSManoj Kumar report_errata ERRATA_N1_1868343, rainier, 1868343 148*a72144fbSManoj Kumar 1492b357c31SManoj Kumar ldp x8, x30, [sp], #16 1502b357c31SManoj Kumar ret 1512b357c31SManoj Kumarendfunc rainier_errata_report 1522b357c31SManoj Kumar#endif 1532b357c31SManoj Kumar 1542b357c31SManoj Kumar /* --------------------------------------------- 1552b357c31SManoj Kumar * This function provides Rainier specific 1562b357c31SManoj Kumar * register information for crash reporting. 1572b357c31SManoj Kumar * It needs to return with x6 pointing to 1582b357c31SManoj Kumar * a list of register names in ascii and 1592b357c31SManoj Kumar * x8 - x15 having values of registers to be 1602b357c31SManoj Kumar * reported. 1612b357c31SManoj Kumar * --------------------------------------------- 1622b357c31SManoj Kumar */ 1632b357c31SManoj Kumar.section .rodata.rainier_regs, "aS" 1642b357c31SManoj Kumarrainier_regs: /* The ascii list of register names to be reported */ 1652b357c31SManoj Kumar .asciz "cpuectlr_el1", "" 1662b357c31SManoj Kumar 1672b357c31SManoj Kumarfunc rainier_cpu_reg_dump 1682b357c31SManoj Kumar adr x6, rainier_regs 1692b357c31SManoj Kumar mrs x8, RAINIER_CPUECTLR_EL1 1702b357c31SManoj Kumar ret 1712b357c31SManoj Kumarendfunc rainier_cpu_reg_dump 1722b357c31SManoj Kumar 173041d7c7bSManoj Kumardeclare_cpu_ops rainier, RAINIER_MIDR, \ 1742b357c31SManoj Kumar rainier_reset_func, \ 1752b357c31SManoj Kumar rainier_core_pwr_dwn 176