1*91f16700Schasinglulu/* 2*91f16700Schasinglulu * Copyright 2018-2021 NXP 3*91f16700Schasinglulu * 4*91f16700Schasinglulu * SPDX-License-Identifier: BSD-3-Clause 5*91f16700Schasinglulu * 6*91f16700Schasinglulu */ 7*91f16700Schasinglulu 8*91f16700Schasinglulu#include <asm_macros.S> 9*91f16700Schasinglulu#include <cortex_a53.h> 10*91f16700Schasinglulu#include <drivers/console.h> 11*91f16700Schasinglulu#include <lib/cpus/aarch64/cortex_a72.h> 12*91f16700Schasinglulu 13*91f16700Schasinglulu#include <platform_def.h> 14*91f16700Schasinglulu 15*91f16700Schasinglulu 16*91f16700Schasinglulu .globl plat_crash_console_init 17*91f16700Schasinglulu .globl plat_crash_console_putc 18*91f16700Schasinglulu .globl plat_crash_console_flush 19*91f16700Schasinglulu .globl plat_core_pos 20*91f16700Schasinglulu .globl plat_my_core_pos 21*91f16700Schasinglulu .globl plat_core_mask 22*91f16700Schasinglulu .globl plat_my_core_mask 23*91f16700Schasinglulu .globl plat_core_pos_by_mpidr 24*91f16700Schasinglulu .globl _disable_ldstr_pfetch_A53 25*91f16700Schasinglulu .globl _disable_ldstr_pfetch_A72 26*91f16700Schasinglulu .global _set_smmu_pagesz_64 27*91f16700Schasinglulu 28*91f16700Schasinglulu /* int plat_crash_console_init(void) 29*91f16700Schasinglulu * Function to initialize the crash console 30*91f16700Schasinglulu * without a C Runtime to print crash report. 31*91f16700Schasinglulu * Clobber list : x0 - x4 32*91f16700Schasinglulu */ 33*91f16700Schasinglulu 34*91f16700Schasinglulu /* int plat_crash_console_init(void) 35*91f16700Schasinglulu * Use normal console by default. Switch it to crash 36*91f16700Schasinglulu * mode so serial consoles become active again. 37*91f16700Schasinglulu * NOTE: This default implementation will only work for 38*91f16700Schasinglulu * crashes that occur after a normal console (marked 39*91f16700Schasinglulu * valid for the crash state) has been registered with 40*91f16700Schasinglulu * the console framework. To debug crashes that occur 41*91f16700Schasinglulu * earlier, the platform has to override these functions 42*91f16700Schasinglulu * with an implementation that initializes a console 43*91f16700Schasinglulu * driver with hardcoded parameters. See 44*91f16700Schasinglulu * docs/porting-guide.rst for more information. 45*91f16700Schasinglulu */ 46*91f16700Schasinglulufunc plat_crash_console_init 47*91f16700Schasinglulu mov x3, x30 48*91f16700Schasinglulu mov x0, #CONSOLE_FLAG_CRASH 49*91f16700Schasinglulu bl console_switch_state 50*91f16700Schasinglulu mov x0, #1 51*91f16700Schasinglulu ret x3 52*91f16700Schasingluluendfunc plat_crash_console_init 53*91f16700Schasinglulu 54*91f16700Schasinglulu /* void plat_crash_console_putc(int character) 55*91f16700Schasinglulu * Output through the normal console by default. 56*91f16700Schasinglulu */ 57*91f16700Schasinglulufunc plat_crash_console_putc 58*91f16700Schasinglulu b console_putc 59*91f16700Schasingluluendfunc plat_crash_console_putc 60*91f16700Schasinglulu 61*91f16700Schasinglulu /* void plat_crash_console_flush(void) 62*91f16700Schasinglulu * Flush normal console by default. 63*91f16700Schasinglulu */ 64*91f16700Schasinglulufunc plat_crash_console_flush 65*91f16700Schasinglulu b console_flush 66*91f16700Schasingluluendfunc plat_crash_console_flush 67*91f16700Schasinglulu 68*91f16700Schasinglulu/* This function implements a part of the critical interface between the psci 69*91f16700Schasinglulu * generic layer and the platform that allows the former to query the platform 70*91f16700Schasinglulu * to convert an MPIDR to a unique linear index. An error code (-1) is returned 71*91f16700Schasinglulu * in case the MPIDR is invalid. 72*91f16700Schasinglulu */ 73*91f16700Schasinglulufunc plat_core_pos_by_mpidr 74*91f16700Schasinglulu 75*91f16700Schasinglulu b plat_core_pos 76*91f16700Schasinglulu 77*91f16700Schasingluluendfunc plat_core_pos_by_mpidr 78*91f16700Schasinglulu 79*91f16700Schasinglulu#if (SYMMETRICAL_CLUSTERS) 80*91f16700Schasinglulu/* unsigned int plat_my_core_mask(void) 81*91f16700Schasinglulu * generate a mask bit for this core 82*91f16700Schasinglulu */ 83*91f16700Schasinglulufunc plat_my_core_mask 84*91f16700Schasinglulu mrs x0, MPIDR_EL1 85*91f16700Schasinglulu b plat_core_mask 86*91f16700Schasingluluendfunc plat_my_core_mask 87*91f16700Schasinglulu 88*91f16700Schasinglulu/* unsigned int plat_core_mask(u_register_t mpidr) 89*91f16700Schasinglulu * generate a lsb-based mask bit for the core specified by mpidr in x0. 90*91f16700Schasinglulu * 91*91f16700Schasinglulu * SoC core = ((cluster * cpu_per_cluster) + core) 92*91f16700Schasinglulu * mask = (1 << SoC core) 93*91f16700Schasinglulu */ 94*91f16700Schasinglulufunc plat_core_mask 95*91f16700Schasinglulu mov w1, wzr 96*91f16700Schasinglulu mov w2, wzr 97*91f16700Schasinglulu 98*91f16700Schasinglulu /* extract cluster */ 99*91f16700Schasinglulu bfxil w1, w0, #8, #8 100*91f16700Schasinglulu /* extract cpu # */ 101*91f16700Schasinglulu bfxil w2, w0, #0, #8 102*91f16700Schasinglulu 103*91f16700Schasinglulu mov w0, wzr 104*91f16700Schasinglulu 105*91f16700Schasinglulu /* error checking */ 106*91f16700Schasinglulu cmp w1, #NUMBER_OF_CLUSTERS 107*91f16700Schasinglulu b.ge 1f 108*91f16700Schasinglulu cmp w2, #CORES_PER_CLUSTER 109*91f16700Schasinglulu b.ge 1f 110*91f16700Schasinglulu 111*91f16700Schasinglulu mov w0, #CORES_PER_CLUSTER 112*91f16700Schasinglulu mul w1, w1, w0 113*91f16700Schasinglulu add w1, w1, w2 114*91f16700Schasinglulu mov w2, #0x1 115*91f16700Schasinglulu lsl w0, w2, w1 116*91f16700Schasinglulu1: 117*91f16700Schasinglulu ret 118*91f16700Schasingluluendfunc plat_core_mask 119*91f16700Schasinglulu 120*91f16700Schasinglulu/* 121*91f16700Schasinglulu * unsigned int plat_my_core_pos(void) 122*91f16700Schasinglulu * generate a linear core number for this core 123*91f16700Schasinglulu */ 124*91f16700Schasinglulufunc plat_my_core_pos 125*91f16700Schasinglulu mrs x0, MPIDR_EL1 126*91f16700Schasinglulu b plat_core_pos 127*91f16700Schasingluluendfunc plat_my_core_pos 128*91f16700Schasinglulu 129*91f16700Schasinglulu/* 130*91f16700Schasinglulu * unsigned int plat_core_pos(u_register_t mpidr) 131*91f16700Schasinglulu * Generate a linear core number for the core specified by mpidr. 132*91f16700Schasinglulu * 133*91f16700Schasinglulu * SoC core = ((cluster * cpu_per_cluster) + core) 134*91f16700Schasinglulu * Returns -1 if mpidr invalid 135*91f16700Schasinglulu */ 136*91f16700Schasinglulufunc plat_core_pos 137*91f16700Schasinglulu mov w1, wzr 138*91f16700Schasinglulu mov w2, wzr 139*91f16700Schasinglulu bfxil w1, w0, #8, #8 /* extract cluster */ 140*91f16700Schasinglulu bfxil w2, w0, #0, #8 /* extract cpu # */ 141*91f16700Schasinglulu 142*91f16700Schasinglulu mov w0, #-1 143*91f16700Schasinglulu 144*91f16700Schasinglulu /* error checking */ 145*91f16700Schasinglulu cmp w1, #NUMBER_OF_CLUSTERS 146*91f16700Schasinglulu b.ge 1f 147*91f16700Schasinglulu cmp w2, #CORES_PER_CLUSTER 148*91f16700Schasinglulu b.ge 1f 149*91f16700Schasinglulu 150*91f16700Schasinglulu mov w0, #CORES_PER_CLUSTER 151*91f16700Schasinglulu mul w1, w1, w0 152*91f16700Schasinglulu add w0, w1, w2 153*91f16700Schasinglulu1: 154*91f16700Schasinglulu ret 155*91f16700Schasingluluendfunc plat_core_pos 156*91f16700Schasinglulu 157*91f16700Schasinglulu#endif 158*91f16700Schasinglulu 159*91f16700Schasinglulu/* this function disables the load-store prefetch of the calling core 160*91f16700Schasinglulu * Note: this function is for A53 cores ONLY 161*91f16700Schasinglulu * in: none 162*91f16700Schasinglulu * out: none 163*91f16700Schasinglulu * uses x0 164*91f16700Schasinglulu */ 165*91f16700Schasinglulufunc _disable_ldstr_pfetch_A53 166*91f16700Schasinglulu mrs x0, CORTEX_A53_CPUACTLR_EL1 167*91f16700Schasinglulu tst x0, #CORTEX_A53_CPUACTLR_EL1_L1PCTL 168*91f16700Schasinglulu b.ne 1f 169*91f16700Schasinglulu b 2f 170*91f16700Schasinglulu 171*91f16700Schasinglulu.align 6 172*91f16700Schasinglulu1: 173*91f16700Schasinglulu dsb sy 174*91f16700Schasinglulu isb 175*91f16700Schasinglulu bic x0, x0, #CORTEX_A53_CPUACTLR_EL1_L1PCTL 176*91f16700Schasinglulu msr CORTEX_A53_CPUACTLR_EL1, x0 177*91f16700Schasinglulu isb 178*91f16700Schasinglulu 179*91f16700Schasinglulu2: 180*91f16700Schasinglulu ret 181*91f16700Schasingluluendfunc _disable_ldstr_pfetch_A53 182*91f16700Schasinglulu 183*91f16700Schasinglulu 184*91f16700Schasinglulu/* this function disables the load-store prefetch of the calling core 185*91f16700Schasinglulu * Note: this function is for A72 cores ONLY 186*91f16700Schasinglulu * in: none 187*91f16700Schasinglulu * out: none 188*91f16700Schasinglulu * uses x0 189*91f16700Schasinglulu */ 190*91f16700Schasinglulufunc _disable_ldstr_pfetch_A72 191*91f16700Schasinglulu 192*91f16700Schasinglulu mrs x0, CORTEX_A72_CPUACTLR_EL1 193*91f16700Schasinglulu tst x0, #CORTEX_A72_CPUACTLR_EL1_DISABLE_L1_DCACHE_HW_PFTCH 194*91f16700Schasinglulu b.eq 1f 195*91f16700Schasinglulu b 2f 196*91f16700Schasinglulu 197*91f16700Schasinglulu.align 6 198*91f16700Schasinglulu1: 199*91f16700Schasinglulu dsb sy 200*91f16700Schasinglulu isb 201*91f16700Schasinglulu orr x0, x0, #CORTEX_A72_CPUACTLR_EL1_DISABLE_L1_DCACHE_HW_PFTCH 202*91f16700Schasinglulu msr CORTEX_A72_CPUACTLR_EL1, x0 203*91f16700Schasinglulu isb 204*91f16700Schasinglulu 205*91f16700Schasinglulu2: 206*91f16700Schasinglulu ret 207*91f16700Schasingluluendfunc _disable_ldstr_pfetch_A72 208*91f16700Schasinglulu 209*91f16700Schasinglulu/* 210*91f16700Schasinglulu * Function sets the SACR pagesize to 64k 211*91f16700Schasinglulu */ 212*91f16700Schasinglulufunc _set_smmu_pagesz_64 213*91f16700Schasinglulu 214*91f16700Schasinglulu ldr x1, =NXP_SMMU_ADDR 215*91f16700Schasinglulu ldr w0, [x1, #0x10] 216*91f16700Schasinglulu orr w0, w0, #1 << 16 /* setting to 64K page */ 217*91f16700Schasinglulu str w0, [x1, #0x10] 218*91f16700Schasinglulu 219*91f16700Schasinglulu ret 220*91f16700Schasingluluendfunc _set_smmu_pagesz_64 221