16f249345SYatharth Kochar/* 26f249345SYatharth Kochar * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved. 36f249345SYatharth Kochar * 482cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause 56f249345SYatharth Kochar */ 66f249345SYatharth Kochar 76f249345SYatharth Kochar#include <arch.h> 86f249345SYatharth Kochar#include <asm_macros.S> 96f249345SYatharth Kochar#include <bl_common.h> 106f249345SYatharth Kochar#include <cortex_a53.h> 116f249345SYatharth Kochar#include <cortex_a57.h> 126f249345SYatharth Kochar#include <cortex_a72.h> 136f249345SYatharth Kochar#include <v2m_def.h> 146f249345SYatharth Kochar#include "../juno_def.h" 156f249345SYatharth Kochar 166f249345SYatharth Kochar 176f249345SYatharth Kochar .globl plat_reset_handler 186f249345SYatharth Kochar .globl plat_arm_calc_core_pos 196f249345SYatharth Kochar 206f249345SYatharth Kochar#define JUNO_REVISION(rev) REV_JUNO_R##rev 216f249345SYatharth Kochar#define JUNO_HANDLER(rev) plat_reset_handler_juno_r##rev 226f249345SYatharth Kochar#define JUMP_TO_HANDLER_IF_JUNO_R(revision) \ 236f249345SYatharth Kochar jump_to_handler JUNO_REVISION(revision), JUNO_HANDLER(revision) 246f249345SYatharth Kochar 256f249345SYatharth Kochar /* -------------------------------------------------------------------- 266f249345SYatharth Kochar * Helper macro to jump to the given handler if the board revision 276f249345SYatharth Kochar * matches. 286f249345SYatharth Kochar * Expects the Juno board revision in x0. 296f249345SYatharth Kochar * -------------------------------------------------------------------- 306f249345SYatharth Kochar */ 316f249345SYatharth Kochar .macro jump_to_handler _revision, _handler 326f249345SYatharth Kochar cmp r0, #\_revision 336f249345SYatharth Kochar beq \_handler 346f249345SYatharth Kochar .endm 356f249345SYatharth Kochar 366f249345SYatharth Kochar /* -------------------------------------------------------------------- 376f249345SYatharth Kochar * Helper macro that reads the part number of the current CPU and jumps 386f249345SYatharth Kochar * to the given label if it matches the CPU MIDR provided. 396f249345SYatharth Kochar * 406f249345SYatharth Kochar * Clobbers r0. 416f249345SYatharth Kochar * -------------------------------------------------------------------- 426f249345SYatharth Kochar */ 436f249345SYatharth Kochar .macro jump_if_cpu_midr _cpu_midr, _label 446f249345SYatharth Kochar ldcopr r0, MIDR 456f249345SYatharth Kochar ubfx r0, r0, #MIDR_PN_SHIFT, #12 466f249345SYatharth Kochar ldr r1, =((\_cpu_midr >> MIDR_PN_SHIFT) & MIDR_PN_MASK) 476f249345SYatharth Kochar cmp r0, r1 486f249345SYatharth Kochar beq \_label 496f249345SYatharth Kochar .endm 506f249345SYatharth Kochar 516f249345SYatharth Kochar /* -------------------------------------------------------------------- 526f249345SYatharth Kochar * Platform reset handler for Juno R0. 536f249345SYatharth Kochar * 546f249345SYatharth Kochar * Juno R0 has the following topology: 556f249345SYatharth Kochar * - Quad core Cortex-A53 processor cluster; 566f249345SYatharth Kochar * - Dual core Cortex-A57 processor cluster. 576f249345SYatharth Kochar * 586f249345SYatharth Kochar * This handler does the following: 596f249345SYatharth Kochar * - Implement workaround for defect id 831273 by enabling an event 606f249345SYatharth Kochar * stream every 65536 cycles. 616f249345SYatharth Kochar * - Set the L2 Data RAM latency to 2 (i.e. 3 cycles) for Cortex-A57 626f249345SYatharth Kochar * - Set the L2 Tag RAM latency to 2 (i.e. 3 cycles) for Cortex-A57 636f249345SYatharth Kochar * -------------------------------------------------------------------- 646f249345SYatharth Kochar */ 656f249345SYatharth Kocharfunc JUNO_HANDLER(0) 666f249345SYatharth Kochar /* -------------------------------------------------------------------- 676f249345SYatharth Kochar * Enable the event stream every 65536 cycles 686f249345SYatharth Kochar * -------------------------------------------------------------------- 696f249345SYatharth Kochar */ 706f249345SYatharth Kochar mov r0, #(0xf << EVNTI_SHIFT) 716f249345SYatharth Kochar orr r0, r0, #EVNTEN_BIT 726f249345SYatharth Kochar stcopr r0, CNTKCTL 736f249345SYatharth Kochar 746f249345SYatharth Kochar /* -------------------------------------------------------------------- 756f249345SYatharth Kochar * Nothing else to do on Cortex-A53. 766f249345SYatharth Kochar * -------------------------------------------------------------------- 776f249345SYatharth Kochar */ 786f249345SYatharth Kochar jump_if_cpu_midr CORTEX_A53_MIDR, 1f 796f249345SYatharth Kochar 806f249345SYatharth Kochar /* -------------------------------------------------------------------- 816f249345SYatharth Kochar * Cortex-A57 specific settings 826f249345SYatharth Kochar * -------------------------------------------------------------------- 836f249345SYatharth Kochar */ 84*c9711432SDimitris Papastamos mov r0, #((CORTEX_A57_L2_DATA_RAM_LATENCY_3_CYCLES << CORTEX_A57_L2CTLR_DATA_RAM_LATENCY_SHIFT) | \ 85*c9711432SDimitris Papastamos (CORTEX_A57_L2_TAG_RAM_LATENCY_3_CYCLES << CORTEX_A57_L2CTLR_TAG_RAM_LATENCY_SHIFT)) 86*c9711432SDimitris Papastamos stcopr r0, CORTEX_A57_L2CTLR 876f249345SYatharth Kochar1: 886f249345SYatharth Kochar isb 896f249345SYatharth Kochar bx lr 906f249345SYatharth Kocharendfunc JUNO_HANDLER(0) 916f249345SYatharth Kochar 926f249345SYatharth Kochar /* -------------------------------------------------------------------- 936f249345SYatharth Kochar * Platform reset handler for Juno R1. 946f249345SYatharth Kochar * 956f249345SYatharth Kochar * Juno R1 has the following topology: 966f249345SYatharth Kochar * - Quad core Cortex-A53 processor cluster; 976f249345SYatharth Kochar * - Dual core Cortex-A57 processor cluster. 986f249345SYatharth Kochar * 996f249345SYatharth Kochar * This handler does the following: 1006f249345SYatharth Kochar * - Set the L2 Data RAM latency to 2 (i.e. 3 cycles) for Cortex-A57 1016f249345SYatharth Kochar * 1026f249345SYatharth Kochar * Note that: 1036f249345SYatharth Kochar * - The default value for the L2 Tag RAM latency for Cortex-A57 is 1046f249345SYatharth Kochar * suitable. 1056f249345SYatharth Kochar * - Defect #831273 doesn't affect Juno R1. 1066f249345SYatharth Kochar * -------------------------------------------------------------------- 1076f249345SYatharth Kochar */ 1086f249345SYatharth Kocharfunc JUNO_HANDLER(1) 1096f249345SYatharth Kochar /* -------------------------------------------------------------------- 1106f249345SYatharth Kochar * Nothing to do on Cortex-A53. 1116f249345SYatharth Kochar * -------------------------------------------------------------------- 1126f249345SYatharth Kochar */ 1136f249345SYatharth Kochar jump_if_cpu_midr CORTEX_A57_MIDR, A57 1146f249345SYatharth Kochar bx lr 1156f249345SYatharth Kochar 1166f249345SYatharth KocharA57: 1176f249345SYatharth Kochar /* -------------------------------------------------------------------- 1186f249345SYatharth Kochar * Cortex-A57 specific settings 1196f249345SYatharth Kochar * -------------------------------------------------------------------- 1206f249345SYatharth Kochar */ 121*c9711432SDimitris Papastamos mov r0, #(CORTEX_A57_L2_DATA_RAM_LATENCY_3_CYCLES << CORTEX_A57_L2CTLR_DATA_RAM_LATENCY_SHIFT) 122*c9711432SDimitris Papastamos stcopr r0, CORTEX_A57_L2CTLR 1236f249345SYatharth Kochar isb 1246f249345SYatharth Kochar bx lr 1256f249345SYatharth Kocharendfunc JUNO_HANDLER(1) 1266f249345SYatharth Kochar 1276f249345SYatharth Kochar /* -------------------------------------------------------------------- 1286f249345SYatharth Kochar * Platform reset handler for Juno R2. 1296f249345SYatharth Kochar * 1306f249345SYatharth Kochar * Juno R2 has the following topology: 1316f249345SYatharth Kochar * - Quad core Cortex-A53 processor cluster; 1326f249345SYatharth Kochar * - Dual core Cortex-A72 processor cluster. 1336f249345SYatharth Kochar * 1346f249345SYatharth Kochar * This handler does the following: 1356f249345SYatharth Kochar * - Set the L2 Data RAM latency to 2 (i.e. 3 cycles) for Cortex-A72 1366f249345SYatharth Kochar * - Set the L2 Tag RAM latency to 1 (i.e. 2 cycles) for Cortex-A72 1376f249345SYatharth Kochar * 1386f249345SYatharth Kochar * Note that: 1396f249345SYatharth Kochar * - Defect #831273 doesn't affect Juno R2. 1406f249345SYatharth Kochar * -------------------------------------------------------------------- 1416f249345SYatharth Kochar */ 1426f249345SYatharth Kocharfunc JUNO_HANDLER(2) 1436f249345SYatharth Kochar /* -------------------------------------------------------------------- 1446f249345SYatharth Kochar * Nothing to do on Cortex-A53. 1456f249345SYatharth Kochar * -------------------------------------------------------------------- 1466f249345SYatharth Kochar */ 1476f249345SYatharth Kochar jump_if_cpu_midr CORTEX_A72_MIDR, A72 1486f249345SYatharth Kochar bx lr 1496f249345SYatharth Kochar 1506f249345SYatharth KocharA72: 1516f249345SYatharth Kochar /* -------------------------------------------------------------------- 1526f249345SYatharth Kochar * Cortex-A72 specific settings 1536f249345SYatharth Kochar * -------------------------------------------------------------------- 1546f249345SYatharth Kochar */ 155*c9711432SDimitris Papastamos mov r0, #((CORTEX_A72_L2_DATA_RAM_LATENCY_3_CYCLES << CORTEX_A72_L2CTLR_DATA_RAM_LATENCY_SHIFT) | \ 156*c9711432SDimitris Papastamos (CORTEX_A72_L2_TAG_RAM_LATENCY_2_CYCLES << CORTEX_A72_L2CTLR_TAG_RAM_LATENCY_SHIFT)) 157*c9711432SDimitris Papastamos stcopr r0, CORTEX_A72_L2CTLR 1586f249345SYatharth Kochar isb 1596f249345SYatharth Kochar bx lr 1606f249345SYatharth Kocharendfunc JUNO_HANDLER(2) 1616f249345SYatharth Kochar 1626f249345SYatharth Kochar /* -------------------------------------------------------------------- 1636f249345SYatharth Kochar * void plat_reset_handler(void); 1646f249345SYatharth Kochar * 1656f249345SYatharth Kochar * Determine the Juno board revision and call the appropriate reset 1666f249345SYatharth Kochar * handler. 1676f249345SYatharth Kochar * -------------------------------------------------------------------- 1686f249345SYatharth Kochar */ 1696f249345SYatharth Kocharfunc plat_reset_handler 1706f249345SYatharth Kochar /* Read the V2M SYS_ID register */ 1716f249345SYatharth Kochar ldr r0, =(V2M_SYSREGS_BASE + V2M_SYS_ID) 1726f249345SYatharth Kochar ldr r1, [r0] 1736f249345SYatharth Kochar /* Extract board revision from the SYS_ID */ 1746f249345SYatharth Kochar ubfx r0, r1, #V2M_SYS_ID_REV_SHIFT, #4 1756f249345SYatharth Kochar 1766f249345SYatharth Kochar JUMP_TO_HANDLER_IF_JUNO_R(0) 1776f249345SYatharth Kochar JUMP_TO_HANDLER_IF_JUNO_R(1) 1786f249345SYatharth Kochar JUMP_TO_HANDLER_IF_JUNO_R(2) 1796f249345SYatharth Kochar 1806f249345SYatharth Kochar /* Board revision is not supported */ 1816f249345SYatharth Kochar no_ret plat_panic_handler 1826f249345SYatharth Kochar 1836f249345SYatharth Kocharendfunc plat_reset_handler 1846f249345SYatharth Kochar 1856f249345SYatharth Kochar /* ----------------------------------------------------- 1866f249345SYatharth Kochar * unsigned int plat_arm_calc_core_pos(u_register_t mpidr) 1876f249345SYatharth Kochar * Helper function to calculate the core position. 1886f249345SYatharth Kochar * ----------------------------------------------------- 1896f249345SYatharth Kochar */ 1906f249345SYatharth Kocharfunc plat_arm_calc_core_pos 1916f249345SYatharth Kochar b css_calc_core_pos_swap_cluster 1926f249345SYatharth Kocharendfunc plat_arm_calc_core_pos 193