1*85135283SDan Handley/* 2*85135283SDan Handley * Copyright (c) 2013-2015, ARM Limited and Contributors. All rights reserved. 3*85135283SDan Handley * 4*85135283SDan Handley * Redistribution and use in source and binary forms, with or without 5*85135283SDan Handley * modification, are permitted provided that the following conditions are met: 6*85135283SDan Handley * 7*85135283SDan Handley * Redistributions of source code must retain the above copyright notice, this 8*85135283SDan Handley * list of conditions and the following disclaimer. 9*85135283SDan Handley * 10*85135283SDan Handley * Redistributions in binary form must reproduce the above copyright notice, 11*85135283SDan Handley * this list of conditions and the following disclaimer in the documentation 12*85135283SDan Handley * and/or other materials provided with the distribution. 13*85135283SDan Handley * 14*85135283SDan Handley * Neither the name of ARM nor the names of its contributors may be used 15*85135283SDan Handley * to endorse or promote products derived from this software without specific 16*85135283SDan Handley * prior written permission. 17*85135283SDan Handley * 18*85135283SDan Handley * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19*85135283SDan Handley * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20*85135283SDan Handley * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21*85135283SDan Handley * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22*85135283SDan Handley * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23*85135283SDan Handley * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24*85135283SDan Handley * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25*85135283SDan Handley * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26*85135283SDan Handley * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27*85135283SDan Handley * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28*85135283SDan Handley * POSSIBILITY OF SUCH DAMAGE. 29*85135283SDan Handley */ 30*85135283SDan Handley 31*85135283SDan Handley#include <arch.h> 32*85135283SDan Handley#include <asm_macros.S> 33*85135283SDan Handley#include <bl_common.h> 34*85135283SDan Handley#include <cortex_a57.h> 35*85135283SDan Handley#include <v2m_def.h> 36*85135283SDan Handley#include "../juno_def.h" 37*85135283SDan Handley 38*85135283SDan Handley 39*85135283SDan Handley .globl plat_reset_handler 40*85135283SDan Handley 41*85135283SDan Handley 42*85135283SDan Handley /* -------------------------------------------------------------------- 43*85135283SDan Handley * void plat_reset_handler(void); 44*85135283SDan Handley * 45*85135283SDan Handley * Before adding code in this function, refer to the guidelines in 46*85135283SDan Handley * docs/firmware-design.md to determine whether the code should reside 47*85135283SDan Handley * within the FIRST_RESET_HANDLER_CALL block or not. 48*85135283SDan Handley * 49*85135283SDan Handley * For Juno r0: 50*85135283SDan Handley * - Implement workaround for defect id 831273 by enabling an event 51*85135283SDan Handley * stream every 65536 cycles. 52*85135283SDan Handley * - Set the L2 Data RAM latency to 2 (i.e. 3 cycles) for Cortex-A57 53*85135283SDan Handley * - Set the L2 Tag RAM latency to 2 (i.e. 3 cycles) for Cortex-A57 54*85135283SDan Handley * 55*85135283SDan Handley * For Juno r1: 56*85135283SDan Handley * - Set the L2 Data RAM latency to 2 (i.e. 3 cycles) for Cortex-A57 57*85135283SDan Handley * Note that: 58*85135283SDan Handley * - The default value for the L2 Tag RAM latency for Cortex-A57 is 59*85135283SDan Handley * suitable. 60*85135283SDan Handley * - Defect #831273 doesn't affect Juno r1. 61*85135283SDan Handley * 62*85135283SDan Handley * This code is included only when FIRST_RESET_HANDLER_CALL is defined 63*85135283SDan Handley * since it should be executed only during BL1. 64*85135283SDan Handley * -------------------------------------------------------------------- 65*85135283SDan Handley */ 66*85135283SDan Handleyfunc plat_reset_handler 67*85135283SDan Handley#ifdef FIRST_RESET_HANDLER_CALL 68*85135283SDan Handley /* -------------------------------------------------------------------- 69*85135283SDan Handley * Determine whether this code is running on Juno r0 or Juno r1. 70*85135283SDan Handley * Keep this information in x2. 71*85135283SDan Handley * -------------------------------------------------------------------- 72*85135283SDan Handley */ 73*85135283SDan Handley /* Read the V2M SYS_ID register */ 74*85135283SDan Handley mov_imm x0, (V2M_SYSREGS_BASE + V2M_SYS_ID) 75*85135283SDan Handley ldr w1, [x0] 76*85135283SDan Handley /* Extract board revision from the SYS_ID */ 77*85135283SDan Handley ubfx x1, x1, #V2M_SYS_ID_REV_SHIFT, #4 78*85135283SDan Handley /* 79*85135283SDan Handley * On Juno R0: x2 := REV_JUNO_R0 - 1 = 0 80*85135283SDan Handley * On Juno R1: x2 := REV_JUNO_R1 - 1 = 1 81*85135283SDan Handley */ 82*85135283SDan Handley sub x2, x1, #1 83*85135283SDan Handley 84*85135283SDan Handley /* -------------------------------------------------------------------- 85*85135283SDan Handley * Determine whether this code is executed on a Cortex-A53 or on a 86*85135283SDan Handley * Cortex-A57 core. 87*85135283SDan Handley * -------------------------------------------------------------------- 88*85135283SDan Handley */ 89*85135283SDan Handley mrs x0, midr_el1 90*85135283SDan Handley ubfx x1, x0, MIDR_PN_SHIFT, #12 91*85135283SDan Handley cmp w1, #((CORTEX_A57_MIDR >> MIDR_PN_SHIFT) & MIDR_PN_MASK) 92*85135283SDan Handley b.eq A57 93*85135283SDan Handley 94*85135283SDan Handley /* Nothing needs to be done for the Cortex-A53 on Juno r1 */ 95*85135283SDan Handley cbz x2, apply_831273 96*85135283SDan Handley ret 97*85135283SDan Handley 98*85135283SDan HandleyA57: 99*85135283SDan Handley /* -------------------------------------------------------------------- 100*85135283SDan Handley * Cortex-A57 specific settings 101*85135283SDan Handley * -------------------------------------------------------------------- 102*85135283SDan Handley */ 103*85135283SDan Handley 104*85135283SDan Handley /* Change the L2 Data RAM latency to 3 cycles */ 105*85135283SDan Handley mov x0, #L2_DATA_RAM_LATENCY_3_CYCLES 106*85135283SDan Handley cbnz x2, apply_l2_ram_latencies 107*85135283SDan Handley /* On Juno r0, also change the L2 Tag RAM latency to 3 cycles */ 108*85135283SDan Handley orr x0, x0, #(L2_TAG_RAM_LATENCY_3_CYCLES << \ 109*85135283SDan Handley L2CTLR_TAG_RAM_LATENCY_SHIFT) 110*85135283SDan Handleyapply_l2_ram_latencies: 111*85135283SDan Handley msr L2CTLR_EL1, x0 112*85135283SDan Handley 113*85135283SDan Handley /* Juno r1 doesn't suffer from defect #831273 */ 114*85135283SDan Handley cbnz x2, ret 115*85135283SDan Handley 116*85135283SDan Handleyapply_831273: 117*85135283SDan Handley /* -------------------------------------------------------------------- 118*85135283SDan Handley * On Juno r0, enable the event stream every 65536 cycles 119*85135283SDan Handley * -------------------------------------------------------------------- 120*85135283SDan Handley */ 121*85135283SDan Handley mov x0, #(0xf << EVNTI_SHIFT) 122*85135283SDan Handley orr x0, x0, #EVNTEN_BIT 123*85135283SDan Handley msr CNTKCTL_EL1, x0 124*85135283SDan Handleyret: 125*85135283SDan Handley isb 126*85135283SDan Handley#endif /* FIRST_RESET_HANDLER_CALL */ 127*85135283SDan Handley ret 128*85135283SDan Handleyendfunc plat_reset_handler 129