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> 909d40e0eSAntonio Nino Diaz#include <common/bl_common.h> 106f249345SYatharth Kochar#include <cortex_a53.h> 116f249345SYatharth Kochar#include <cortex_a57.h> 126f249345SYatharth Kochar#include <cortex_a72.h> 13da3b038fSDeepak Pandey#include <cpu_macros.S> 14*234bc7f8SAntonio Nino Diaz#include <platform_def.h> 156f249345SYatharth Kochar 166f249345SYatharth Kochar .globl plat_reset_handler 176f249345SYatharth Kochar .globl plat_arm_calc_core_pos 186f249345SYatharth Kochar 196f249345SYatharth Kochar#define JUNO_REVISION(rev) REV_JUNO_R##rev 206f249345SYatharth Kochar#define JUNO_HANDLER(rev) plat_reset_handler_juno_r##rev 216f249345SYatharth Kochar#define JUMP_TO_HANDLER_IF_JUNO_R(revision) \ 226f249345SYatharth Kochar jump_to_handler JUNO_REVISION(revision), JUNO_HANDLER(revision) 236f249345SYatharth Kochar 246f249345SYatharth Kochar /* -------------------------------------------------------------------- 256f249345SYatharth Kochar * Helper macro to jump to the given handler if the board revision 266f249345SYatharth Kochar * matches. 276f249345SYatharth Kochar * Expects the Juno board revision in x0. 286f249345SYatharth Kochar * -------------------------------------------------------------------- 296f249345SYatharth Kochar */ 306f249345SYatharth Kochar .macro jump_to_handler _revision, _handler 316f249345SYatharth Kochar cmp r0, #\_revision 326f249345SYatharth Kochar beq \_handler 336f249345SYatharth Kochar .endm 346f249345SYatharth Kochar 356f249345SYatharth Kochar /* -------------------------------------------------------------------- 366f249345SYatharth Kochar * Platform reset handler for Juno R0. 376f249345SYatharth Kochar * 386f249345SYatharth Kochar * Juno R0 has the following topology: 396f249345SYatharth Kochar * - Quad core Cortex-A53 processor cluster; 406f249345SYatharth Kochar * - Dual core Cortex-A57 processor cluster. 416f249345SYatharth Kochar * 426f249345SYatharth Kochar * This handler does the following: 436f249345SYatharth Kochar * - Implement workaround for defect id 831273 by enabling an event 446f249345SYatharth Kochar * stream every 65536 cycles. 456f249345SYatharth Kochar * - Set the L2 Data RAM latency to 2 (i.e. 3 cycles) for Cortex-A57 466f249345SYatharth Kochar * - Set the L2 Tag RAM latency to 2 (i.e. 3 cycles) for Cortex-A57 476f249345SYatharth Kochar * -------------------------------------------------------------------- 486f249345SYatharth Kochar */ 496f249345SYatharth Kocharfunc JUNO_HANDLER(0) 506f249345SYatharth Kochar /* -------------------------------------------------------------------- 516f249345SYatharth Kochar * Enable the event stream every 65536 cycles 526f249345SYatharth Kochar * -------------------------------------------------------------------- 536f249345SYatharth Kochar */ 546f249345SYatharth Kochar mov r0, #(0xf << EVNTI_SHIFT) 556f249345SYatharth Kochar orr r0, r0, #EVNTEN_BIT 566f249345SYatharth Kochar stcopr r0, CNTKCTL 576f249345SYatharth Kochar 586f249345SYatharth Kochar /* -------------------------------------------------------------------- 596f249345SYatharth Kochar * Nothing else to do on Cortex-A53. 606f249345SYatharth Kochar * -------------------------------------------------------------------- 616f249345SYatharth Kochar */ 626f249345SYatharth Kochar jump_if_cpu_midr CORTEX_A53_MIDR, 1f 636f249345SYatharth Kochar 646f249345SYatharth Kochar /* -------------------------------------------------------------------- 656f249345SYatharth Kochar * Cortex-A57 specific settings 666f249345SYatharth Kochar * -------------------------------------------------------------------- 676f249345SYatharth Kochar */ 68c9711432SDimitris Papastamos mov r0, #((CORTEX_A57_L2_DATA_RAM_LATENCY_3_CYCLES << CORTEX_A57_L2CTLR_DATA_RAM_LATENCY_SHIFT) | \ 69c9711432SDimitris Papastamos (CORTEX_A57_L2_TAG_RAM_LATENCY_3_CYCLES << CORTEX_A57_L2CTLR_TAG_RAM_LATENCY_SHIFT)) 70c9711432SDimitris Papastamos stcopr r0, CORTEX_A57_L2CTLR 716f249345SYatharth Kochar1: 726f249345SYatharth Kochar isb 736f249345SYatharth Kochar bx lr 746f249345SYatharth Kocharendfunc JUNO_HANDLER(0) 756f249345SYatharth Kochar 766f249345SYatharth Kochar /* -------------------------------------------------------------------- 776f249345SYatharth Kochar * Platform reset handler for Juno R1. 786f249345SYatharth Kochar * 796f249345SYatharth Kochar * Juno R1 has the following topology: 806f249345SYatharth Kochar * - Quad core Cortex-A53 processor cluster; 816f249345SYatharth Kochar * - Dual core Cortex-A57 processor cluster. 826f249345SYatharth Kochar * 836f249345SYatharth Kochar * This handler does the following: 846f249345SYatharth Kochar * - Set the L2 Data RAM latency to 2 (i.e. 3 cycles) for Cortex-A57 856f249345SYatharth Kochar * 866f249345SYatharth Kochar * Note that: 876f249345SYatharth Kochar * - The default value for the L2 Tag RAM latency for Cortex-A57 is 886f249345SYatharth Kochar * suitable. 896f249345SYatharth Kochar * - Defect #831273 doesn't affect Juno R1. 906f249345SYatharth Kochar * -------------------------------------------------------------------- 916f249345SYatharth Kochar */ 926f249345SYatharth Kocharfunc JUNO_HANDLER(1) 936f249345SYatharth Kochar /* -------------------------------------------------------------------- 946f249345SYatharth Kochar * Nothing to do on Cortex-A53. 956f249345SYatharth Kochar * -------------------------------------------------------------------- 966f249345SYatharth Kochar */ 976f249345SYatharth Kochar jump_if_cpu_midr CORTEX_A57_MIDR, A57 986f249345SYatharth Kochar bx lr 996f249345SYatharth Kochar 1006f249345SYatharth KocharA57: 1016f249345SYatharth Kochar /* -------------------------------------------------------------------- 1026f249345SYatharth Kochar * Cortex-A57 specific settings 1036f249345SYatharth Kochar * -------------------------------------------------------------------- 1046f249345SYatharth Kochar */ 105c9711432SDimitris Papastamos mov r0, #(CORTEX_A57_L2_DATA_RAM_LATENCY_3_CYCLES << CORTEX_A57_L2CTLR_DATA_RAM_LATENCY_SHIFT) 106c9711432SDimitris Papastamos stcopr r0, CORTEX_A57_L2CTLR 1076f249345SYatharth Kochar isb 1086f249345SYatharth Kochar bx lr 1096f249345SYatharth Kocharendfunc JUNO_HANDLER(1) 1106f249345SYatharth Kochar 1116f249345SYatharth Kochar /* -------------------------------------------------------------------- 1126f249345SYatharth Kochar * Platform reset handler for Juno R2. 1136f249345SYatharth Kochar * 1146f249345SYatharth Kochar * Juno R2 has the following topology: 1156f249345SYatharth Kochar * - Quad core Cortex-A53 processor cluster; 1166f249345SYatharth Kochar * - Dual core Cortex-A72 processor cluster. 1176f249345SYatharth Kochar * 1186f249345SYatharth Kochar * This handler does the following: 1196f249345SYatharth Kochar * - Set the L2 Data RAM latency to 2 (i.e. 3 cycles) for Cortex-A72 1206f249345SYatharth Kochar * - Set the L2 Tag RAM latency to 1 (i.e. 2 cycles) for Cortex-A72 1216f249345SYatharth Kochar * 1226f249345SYatharth Kochar * Note that: 1236f249345SYatharth Kochar * - Defect #831273 doesn't affect Juno R2. 1246f249345SYatharth Kochar * -------------------------------------------------------------------- 1256f249345SYatharth Kochar */ 1266f249345SYatharth Kocharfunc JUNO_HANDLER(2) 1276f249345SYatharth Kochar /* -------------------------------------------------------------------- 1286f249345SYatharth Kochar * Nothing to do on Cortex-A53. 1296f249345SYatharth Kochar * -------------------------------------------------------------------- 1306f249345SYatharth Kochar */ 1316f249345SYatharth Kochar jump_if_cpu_midr CORTEX_A72_MIDR, A72 1326f249345SYatharth Kochar bx lr 1336f249345SYatharth Kochar 1346f249345SYatharth KocharA72: 1356f249345SYatharth Kochar /* -------------------------------------------------------------------- 1366f249345SYatharth Kochar * Cortex-A72 specific settings 1376f249345SYatharth Kochar * -------------------------------------------------------------------- 1386f249345SYatharth Kochar */ 139c9711432SDimitris Papastamos mov r0, #((CORTEX_A72_L2_DATA_RAM_LATENCY_3_CYCLES << CORTEX_A72_L2CTLR_DATA_RAM_LATENCY_SHIFT) | \ 140c9711432SDimitris Papastamos (CORTEX_A72_L2_TAG_RAM_LATENCY_2_CYCLES << CORTEX_A72_L2CTLR_TAG_RAM_LATENCY_SHIFT)) 141c9711432SDimitris Papastamos stcopr r0, CORTEX_A72_L2CTLR 1426f249345SYatharth Kochar isb 1436f249345SYatharth Kochar bx lr 1446f249345SYatharth Kocharendfunc JUNO_HANDLER(2) 1456f249345SYatharth Kochar 1466f249345SYatharth Kochar /* -------------------------------------------------------------------- 1476f249345SYatharth Kochar * void plat_reset_handler(void); 1486f249345SYatharth Kochar * 1496f249345SYatharth Kochar * Determine the Juno board revision and call the appropriate reset 1506f249345SYatharth Kochar * handler. 1516f249345SYatharth Kochar * -------------------------------------------------------------------- 1526f249345SYatharth Kochar */ 1536f249345SYatharth Kocharfunc plat_reset_handler 1546f249345SYatharth Kochar /* Read the V2M SYS_ID register */ 1556f249345SYatharth Kochar ldr r0, =(V2M_SYSREGS_BASE + V2M_SYS_ID) 1566f249345SYatharth Kochar ldr r1, [r0] 1576f249345SYatharth Kochar /* Extract board revision from the SYS_ID */ 1586f249345SYatharth Kochar ubfx r0, r1, #V2M_SYS_ID_REV_SHIFT, #4 1596f249345SYatharth Kochar 1606f249345SYatharth Kochar JUMP_TO_HANDLER_IF_JUNO_R(0) 1616f249345SYatharth Kochar JUMP_TO_HANDLER_IF_JUNO_R(1) 1626f249345SYatharth Kochar JUMP_TO_HANDLER_IF_JUNO_R(2) 1636f249345SYatharth Kochar 1646f249345SYatharth Kochar /* Board revision is not supported */ 1656f249345SYatharth Kochar no_ret plat_panic_handler 1666f249345SYatharth Kochar 1676f249345SYatharth Kocharendfunc plat_reset_handler 1686f249345SYatharth Kochar 1696f249345SYatharth Kochar /* ----------------------------------------------------- 1706f249345SYatharth Kochar * unsigned int plat_arm_calc_core_pos(u_register_t mpidr) 1716f249345SYatharth Kochar * Helper function to calculate the core position. 1726f249345SYatharth Kochar * ----------------------------------------------------- 1736f249345SYatharth Kochar */ 1746f249345SYatharth Kocharfunc plat_arm_calc_core_pos 1756f249345SYatharth Kochar b css_calc_core_pos_swap_cluster 1766f249345SYatharth Kocharendfunc plat_arm_calc_core_pos 177