185135283SDan Handley/* 235bd2ddaSDimitris Papastamos * Copyright (c) 2013-2017, ARM Limited and Contributors. All rights reserved. 385135283SDan Handley * 482cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause 585135283SDan Handley */ 685135283SDan Handley 785135283SDan Handley#include <arch.h> 885135283SDan Handley#include <asm_macros.S> 9*09d40e0eSAntonio Nino Diaz#include <common/bl_common.h> 1023d39dbcSSandrine Bailleux#include <cortex_a53.h> 1185135283SDan Handley#include <cortex_a57.h> 121dbe3159SSandrine Bailleux#include <cortex_a72.h> 1307570d59SYatharth Kochar#include <cpu_macros.S> 1407570d59SYatharth Kochar#include <css_def.h> 1585135283SDan Handley#include <v2m_def.h> 1685135283SDan Handley#include "../juno_def.h" 1785135283SDan Handley 1885135283SDan Handley 1985135283SDan Handley .globl plat_reset_handler 20371d4399SDavid Wang .globl plat_arm_calc_core_pos 2107570d59SYatharth Kochar#if JUNO_AARCH32_EL3_RUNTIME 2207570d59SYatharth Kochar .globl plat_get_my_entrypoint 2307570d59SYatharth Kochar .globl juno_reset_to_aarch32_state 2407570d59SYatharth Kochar#endif 2585135283SDan Handley 2623d39dbcSSandrine Bailleux#define JUNO_REVISION(rev) REV_JUNO_R##rev 2723d39dbcSSandrine Bailleux#define JUNO_HANDLER(rev) plat_reset_handler_juno_r##rev 2823d39dbcSSandrine Bailleux#define JUMP_TO_HANDLER_IF_JUNO_R(revision) \ 2923d39dbcSSandrine Bailleux jump_to_handler JUNO_REVISION(revision), JUNO_HANDLER(revision) 3023d39dbcSSandrine Bailleux 3185135283SDan Handley /* -------------------------------------------------------------------- 3223d39dbcSSandrine Bailleux * Helper macro to jump to the given handler if the board revision 3323d39dbcSSandrine Bailleux * matches. 3423d39dbcSSandrine Bailleux * Expects the Juno board revision in x0. 3523d39dbcSSandrine Bailleux * -------------------------------------------------------------------- 3623d39dbcSSandrine Bailleux */ 3723d39dbcSSandrine Bailleux .macro jump_to_handler _revision, _handler 3823d39dbcSSandrine Bailleux cmp x0, #\_revision 3923d39dbcSSandrine Bailleux b.eq \_handler 4023d39dbcSSandrine Bailleux .endm 4123d39dbcSSandrine Bailleux 4223d39dbcSSandrine Bailleux /* -------------------------------------------------------------------- 4323d39dbcSSandrine Bailleux * Platform reset handler for Juno R0. 4423d39dbcSSandrine Bailleux * 4523d39dbcSSandrine Bailleux * Juno R0 has the following topology: 4623d39dbcSSandrine Bailleux * - Quad core Cortex-A53 processor cluster; 4723d39dbcSSandrine Bailleux * - Dual core Cortex-A57 processor cluster. 4823d39dbcSSandrine Bailleux * 4923d39dbcSSandrine Bailleux * This handler does the following: 5085135283SDan Handley * - Implement workaround for defect id 831273 by enabling an event 5185135283SDan Handley * stream every 65536 cycles. 5285135283SDan Handley * - Set the L2 Data RAM latency to 2 (i.e. 3 cycles) for Cortex-A57 5385135283SDan Handley * - Set the L2 Tag RAM latency to 2 (i.e. 3 cycles) for Cortex-A57 5423d39dbcSSandrine Bailleux * -------------------------------------------------------------------- 5523d39dbcSSandrine Bailleux */ 5623d39dbcSSandrine Bailleuxfunc JUNO_HANDLER(0) 5723d39dbcSSandrine Bailleux /* -------------------------------------------------------------------- 5823d39dbcSSandrine Bailleux * Enable the event stream every 65536 cycles 5923d39dbcSSandrine Bailleux * -------------------------------------------------------------------- 6023d39dbcSSandrine Bailleux */ 6123d39dbcSSandrine Bailleux mov x0, #(0xf << EVNTI_SHIFT) 6223d39dbcSSandrine Bailleux orr x0, x0, #EVNTEN_BIT 6323d39dbcSSandrine Bailleux msr CNTKCTL_EL1, x0 6423d39dbcSSandrine Bailleux 6523d39dbcSSandrine Bailleux /* -------------------------------------------------------------------- 6623d39dbcSSandrine Bailleux * Nothing else to do on Cortex-A53. 6723d39dbcSSandrine Bailleux * -------------------------------------------------------------------- 6823d39dbcSSandrine Bailleux */ 6923d39dbcSSandrine Bailleux jump_if_cpu_midr CORTEX_A53_MIDR, 1f 7023d39dbcSSandrine Bailleux 7123d39dbcSSandrine Bailleux /* -------------------------------------------------------------------- 7223d39dbcSSandrine Bailleux * Cortex-A57 specific settings 7323d39dbcSSandrine Bailleux * -------------------------------------------------------------------- 7423d39dbcSSandrine Bailleux */ 75fb7d32e5SVarun Wadekar mov x0, #((CORTEX_A57_L2_DATA_RAM_LATENCY_3_CYCLES << CORTEX_A57_L2CTLR_DATA_RAM_LATENCY_SHIFT) | \ 76fb7d32e5SVarun Wadekar (CORTEX_A57_L2_TAG_RAM_LATENCY_3_CYCLES << CORTEX_A57_L2CTLR_TAG_RAM_LATENCY_SHIFT)) 77fb7d32e5SVarun Wadekar msr CORTEX_A57_L2CTLR_EL1, x0 7823d39dbcSSandrine Bailleux1: 7923d39dbcSSandrine Bailleux isb 8023d39dbcSSandrine Bailleux ret 8123d39dbcSSandrine Bailleuxendfunc JUNO_HANDLER(0) 8223d39dbcSSandrine Bailleux 8323d39dbcSSandrine Bailleux /* -------------------------------------------------------------------- 8423d39dbcSSandrine Bailleux * Platform reset handler for Juno R1. 8585135283SDan Handley * 8623d39dbcSSandrine Bailleux * Juno R1 has the following topology: 8723d39dbcSSandrine Bailleux * - Quad core Cortex-A53 processor cluster; 8823d39dbcSSandrine Bailleux * - Dual core Cortex-A57 processor cluster. 8923d39dbcSSandrine Bailleux * 9023d39dbcSSandrine Bailleux * This handler does the following: 9185135283SDan Handley * - Set the L2 Data RAM latency to 2 (i.e. 3 cycles) for Cortex-A57 9223d39dbcSSandrine Bailleux * 9385135283SDan Handley * Note that: 9485135283SDan Handley * - The default value for the L2 Tag RAM latency for Cortex-A57 is 9585135283SDan Handley * suitable. 9623d39dbcSSandrine Bailleux * - Defect #831273 doesn't affect Juno R1. 9785135283SDan Handley * -------------------------------------------------------------------- 9885135283SDan Handley */ 9923d39dbcSSandrine Bailleuxfunc JUNO_HANDLER(1) 10085135283SDan Handley /* -------------------------------------------------------------------- 10123d39dbcSSandrine Bailleux * Nothing to do on Cortex-A53. 10285135283SDan Handley * -------------------------------------------------------------------- 10385135283SDan Handley */ 10423d39dbcSSandrine Bailleux jump_if_cpu_midr CORTEX_A57_MIDR, A57 10585135283SDan Handley ret 10685135283SDan Handley 10785135283SDan HandleyA57: 10885135283SDan Handley /* -------------------------------------------------------------------- 10985135283SDan Handley * Cortex-A57 specific settings 11085135283SDan Handley * -------------------------------------------------------------------- 11185135283SDan Handley */ 112fb7d32e5SVarun Wadekar mov x0, #(CORTEX_A57_L2_DATA_RAM_LATENCY_3_CYCLES << CORTEX_A57_L2CTLR_DATA_RAM_LATENCY_SHIFT) 113fb7d32e5SVarun Wadekar msr CORTEX_A57_L2CTLR_EL1, x0 11485135283SDan Handley isb 11585135283SDan Handley ret 11623d39dbcSSandrine Bailleuxendfunc JUNO_HANDLER(1) 11723d39dbcSSandrine Bailleux 11823d39dbcSSandrine Bailleux /* -------------------------------------------------------------------- 11923d39dbcSSandrine Bailleux * Platform reset handler for Juno R2. 12023d39dbcSSandrine Bailleux * 12123d39dbcSSandrine Bailleux * Juno R2 has the following topology: 12223d39dbcSSandrine Bailleux * - Quad core Cortex-A53 processor cluster; 12323d39dbcSSandrine Bailleux * - Dual core Cortex-A72 processor cluster. 12423d39dbcSSandrine Bailleux * 1251dbe3159SSandrine Bailleux * This handler does the following: 1261dbe3159SSandrine Bailleux * - Set the L2 Data RAM latency to 2 (i.e. 3 cycles) for Cortex-A72 1271dbe3159SSandrine Bailleux * - Set the L2 Tag RAM latency to 1 (i.e. 2 cycles) for Cortex-A72 1281dbe3159SSandrine Bailleux * 1291dbe3159SSandrine Bailleux * Note that: 1301dbe3159SSandrine Bailleux * - Defect #831273 doesn't affect Juno R2. 13123d39dbcSSandrine Bailleux * -------------------------------------------------------------------- 13223d39dbcSSandrine Bailleux */ 13323d39dbcSSandrine Bailleuxfunc JUNO_HANDLER(2) 1341dbe3159SSandrine Bailleux /* -------------------------------------------------------------------- 1351dbe3159SSandrine Bailleux * Nothing to do on Cortex-A53. 1361dbe3159SSandrine Bailleux * -------------------------------------------------------------------- 1371dbe3159SSandrine Bailleux */ 1381dbe3159SSandrine Bailleux jump_if_cpu_midr CORTEX_A72_MIDR, A72 1391dbe3159SSandrine Bailleux ret 1401dbe3159SSandrine Bailleux 1411dbe3159SSandrine BailleuxA72: 1421dbe3159SSandrine Bailleux /* -------------------------------------------------------------------- 1431dbe3159SSandrine Bailleux * Cortex-A72 specific settings 1441dbe3159SSandrine Bailleux * -------------------------------------------------------------------- 1451dbe3159SSandrine Bailleux */ 146fb7d32e5SVarun Wadekar mov x0, #((CORTEX_A72_L2_DATA_RAM_LATENCY_3_CYCLES << CORTEX_A72_L2CTLR_DATA_RAM_LATENCY_SHIFT) | \ 147fb7d32e5SVarun Wadekar (CORTEX_A72_L2_TAG_RAM_LATENCY_2_CYCLES << CORTEX_A72_L2CTLR_TAG_RAM_LATENCY_SHIFT)) 148fb7d32e5SVarun Wadekar msr CORTEX_A57_L2CTLR_EL1, x0 1491dbe3159SSandrine Bailleux isb 15023d39dbcSSandrine Bailleux ret 15123d39dbcSSandrine Bailleuxendfunc JUNO_HANDLER(2) 15223d39dbcSSandrine Bailleux 15323d39dbcSSandrine Bailleux /* -------------------------------------------------------------------- 15423d39dbcSSandrine Bailleux * void plat_reset_handler(void); 15523d39dbcSSandrine Bailleux * 15623d39dbcSSandrine Bailleux * Determine the Juno board revision and call the appropriate reset 15723d39dbcSSandrine Bailleux * handler. 15823d39dbcSSandrine Bailleux * -------------------------------------------------------------------- 15923d39dbcSSandrine Bailleux */ 16023d39dbcSSandrine Bailleuxfunc plat_reset_handler 16123d39dbcSSandrine Bailleux /* Read the V2M SYS_ID register */ 16223d39dbcSSandrine Bailleux mov_imm x0, (V2M_SYSREGS_BASE + V2M_SYS_ID) 16323d39dbcSSandrine Bailleux ldr w1, [x0] 16423d39dbcSSandrine Bailleux /* Extract board revision from the SYS_ID */ 16523d39dbcSSandrine Bailleux ubfx x0, x1, #V2M_SYS_ID_REV_SHIFT, #4 16623d39dbcSSandrine Bailleux 16723d39dbcSSandrine Bailleux JUMP_TO_HANDLER_IF_JUNO_R(0) 16823d39dbcSSandrine Bailleux JUMP_TO_HANDLER_IF_JUNO_R(1) 16923d39dbcSSandrine Bailleux JUMP_TO_HANDLER_IF_JUNO_R(2) 17023d39dbcSSandrine Bailleux 17123d39dbcSSandrine Bailleux /* Board revision is not supported */ 172a806dad5SJeenu Viswambharan no_ret plat_panic_handler 17323d39dbcSSandrine Bailleux 17485135283SDan Handleyendfunc plat_reset_handler 175371d4399SDavid Wang 176371d4399SDavid Wang /* ----------------------------------------------------- 17707570d59SYatharth Kochar * void juno_do_reset_to_aarch32_state(void); 17807570d59SYatharth Kochar * 17907570d59SYatharth Kochar * Request warm reset to AArch32 mode. 18007570d59SYatharth Kochar * ----------------------------------------------------- 18107570d59SYatharth Kochar */ 18207570d59SYatharth Kocharfunc juno_do_reset_to_aarch32_state 18307570d59SYatharth Kochar mov x0, #RMR_EL3_RR_BIT 18407570d59SYatharth Kochar dsb sy 18507570d59SYatharth Kochar msr rmr_el3, x0 18607570d59SYatharth Kochar isb 18707570d59SYatharth Kochar wfi 188d9b7636eSRoberto Vargas b plat_panic_handler 18907570d59SYatharth Kocharendfunc juno_do_reset_to_aarch32_state 19007570d59SYatharth Kochar 19107570d59SYatharth Kochar /* ----------------------------------------------------- 1924c0d0390SSoby Mathew * unsigned int plat_arm_calc_core_pos(u_register_t mpidr) 193371d4399SDavid Wang * Helper function to calculate the core position. 194371d4399SDavid Wang * ----------------------------------------------------- 195371d4399SDavid Wang */ 196371d4399SDavid Wangfunc plat_arm_calc_core_pos 197371d4399SDavid Wang b css_calc_core_pos_swap_cluster 198371d4399SDavid Wangendfunc plat_arm_calc_core_pos 19907570d59SYatharth Kochar 20007570d59SYatharth Kochar#if JUNO_AARCH32_EL3_RUNTIME 20107570d59SYatharth Kochar /* --------------------------------------------------------------------- 20207570d59SYatharth Kochar * uintptr_t plat_get_my_entrypoint (void); 20307570d59SYatharth Kochar * 20407570d59SYatharth Kochar * Main job of this routine is to distinguish between a cold and a warm 20507570d59SYatharth Kochar * boot. On JUNO platform, this distinction is based on the contents of 20607570d59SYatharth Kochar * the Trusted Mailbox. It is initialised to zero by the SCP before the 20707570d59SYatharth Kochar * AP cores are released from reset. Therefore, a zero mailbox means 20807570d59SYatharth Kochar * it's a cold reset. If it is a warm boot then a request to reset to 20907570d59SYatharth Kochar * AArch32 state is issued. This is the only way to reset to AArch32 21007570d59SYatharth Kochar * in EL3 on Juno. A trampoline located at the high vector address 21107570d59SYatharth Kochar * has already been prepared by BL1. 21207570d59SYatharth Kochar * 21307570d59SYatharth Kochar * This functions returns the contents of the mailbox, i.e.: 21407570d59SYatharth Kochar * - 0 for a cold boot; 21507570d59SYatharth Kochar * - request warm reset in AArch32 state for warm boot case; 21607570d59SYatharth Kochar * --------------------------------------------------------------------- 21707570d59SYatharth Kochar */ 21807570d59SYatharth Kocharfunc plat_get_my_entrypoint 21907570d59SYatharth Kochar mov_imm x0, PLAT_ARM_TRUSTED_MAILBOX_BASE 22007570d59SYatharth Kochar ldr x0, [x0] 22107570d59SYatharth Kochar cbz x0, return 22207570d59SYatharth Kochar b juno_do_reset_to_aarch32_state 22307570d59SYatharth Kocharreturn: 22407570d59SYatharth Kochar ret 22507570d59SYatharth Kocharendfunc plat_get_my_entrypoint 22607570d59SYatharth Kochar 22707570d59SYatharth Kochar/* 22807570d59SYatharth Kochar * Emit a "movw r0, #imm16" which moves the lower 22907570d59SYatharth Kochar * 16 bits of `_val` into r0. 23007570d59SYatharth Kochar */ 23107570d59SYatharth Kochar.macro emit_movw _reg_d, _val 23207570d59SYatharth Kochar mov_imm \_reg_d, (0xe3000000 | \ 23307570d59SYatharth Kochar ((\_val & 0xfff) | \ 23407570d59SYatharth Kochar ((\_val & 0xf000) << 4))) 23507570d59SYatharth Kochar.endm 23607570d59SYatharth Kochar 23707570d59SYatharth Kochar/* 23807570d59SYatharth Kochar * Emit a "movt r0, #imm16" which moves the upper 23907570d59SYatharth Kochar * 16 bits of `_val` into r0. 24007570d59SYatharth Kochar */ 24107570d59SYatharth Kochar.macro emit_movt _reg_d, _val 24207570d59SYatharth Kochar mov_imm \_reg_d, (0xe3400000 | \ 24307570d59SYatharth Kochar (((\_val & 0x0fff0000) >> 16) | \ 24407570d59SYatharth Kochar ((\_val & 0xf0000000) >> 12))) 24507570d59SYatharth Kochar.endm 24607570d59SYatharth Kochar 24707570d59SYatharth Kochar/* 24807570d59SYatharth Kochar * This function writes the trampoline code at HI-VEC (0xFFFF0000) 24907570d59SYatharth Kochar * address which loads r0 with the entrypoint address for 25007570d59SYatharth Kochar * BL32 (a.k.a SP_MIN) when EL3 is in AArch32 mode. A warm reset 25107570d59SYatharth Kochar * to AArch32 mode is then requested by writing into RMR_EL3. 25207570d59SYatharth Kochar */ 25307570d59SYatharth Kocharfunc juno_reset_to_aarch32_state 25435bd2ddaSDimitris Papastamos /* 25535bd2ddaSDimitris Papastamos * Invalidate all caches before the warm reset to AArch32 state. 25635bd2ddaSDimitris Papastamos * This is required on the Juno AArch32 boot flow because the L2 25735bd2ddaSDimitris Papastamos * unified cache may contain code and data from when the processor 25835bd2ddaSDimitris Papastamos * was still executing in AArch64 state. This code only runs on 25935bd2ddaSDimitris Papastamos * the primary core, all other cores are powered down. 26035bd2ddaSDimitris Papastamos */ 26135bd2ddaSDimitris Papastamos mov x0, #DCISW 26235bd2ddaSDimitris Papastamos bl dcsw_op_all 26335bd2ddaSDimitris Papastamos 26407570d59SYatharth Kochar emit_movw w0, BL32_BASE 26507570d59SYatharth Kochar emit_movt w1, BL32_BASE 26607570d59SYatharth Kochar /* opcode "bx r0" to branch using r0 in AArch32 mode */ 26707570d59SYatharth Kochar mov_imm w2, 0xe12fff10 26807570d59SYatharth Kochar 26907570d59SYatharth Kochar /* Write the above opcodes at HI-VECTOR location */ 27007570d59SYatharth Kochar mov_imm x3, HI_VECTOR_BASE 27107570d59SYatharth Kochar str w0, [x3], #4 27207570d59SYatharth Kochar str w1, [x3], #4 27307570d59SYatharth Kochar str w2, [x3] 27407570d59SYatharth Kochar 275d9b7636eSRoberto Vargas b juno_do_reset_to_aarch32_state 27607570d59SYatharth Kocharendfunc juno_reset_to_aarch32_state 27707570d59SYatharth Kochar 27807570d59SYatharth Kochar#endif /* JUNO_AARCH32_EL3_RUNTIME */ 279