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> 909d40e0eSAntonio 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> 14*234bc7f8SAntonio Nino Diaz#include <platform_def.h> 1585135283SDan Handley 1685135283SDan Handley .globl plat_reset_handler 17371d4399SDavid Wang .globl plat_arm_calc_core_pos 1807570d59SYatharth Kochar#if JUNO_AARCH32_EL3_RUNTIME 1907570d59SYatharth Kochar .globl plat_get_my_entrypoint 2007570d59SYatharth Kochar .globl juno_reset_to_aarch32_state 2107570d59SYatharth Kochar#endif 2285135283SDan Handley 2323d39dbcSSandrine Bailleux#define JUNO_REVISION(rev) REV_JUNO_R##rev 2423d39dbcSSandrine Bailleux#define JUNO_HANDLER(rev) plat_reset_handler_juno_r##rev 2523d39dbcSSandrine Bailleux#define JUMP_TO_HANDLER_IF_JUNO_R(revision) \ 2623d39dbcSSandrine Bailleux jump_to_handler JUNO_REVISION(revision), JUNO_HANDLER(revision) 2723d39dbcSSandrine Bailleux 2885135283SDan Handley /* -------------------------------------------------------------------- 2923d39dbcSSandrine Bailleux * Helper macro to jump to the given handler if the board revision 3023d39dbcSSandrine Bailleux * matches. 3123d39dbcSSandrine Bailleux * Expects the Juno board revision in x0. 3223d39dbcSSandrine Bailleux * -------------------------------------------------------------------- 3323d39dbcSSandrine Bailleux */ 3423d39dbcSSandrine Bailleux .macro jump_to_handler _revision, _handler 3523d39dbcSSandrine Bailleux cmp x0, #\_revision 3623d39dbcSSandrine Bailleux b.eq \_handler 3723d39dbcSSandrine Bailleux .endm 3823d39dbcSSandrine Bailleux 3923d39dbcSSandrine Bailleux /* -------------------------------------------------------------------- 4023d39dbcSSandrine Bailleux * Platform reset handler for Juno R0. 4123d39dbcSSandrine Bailleux * 4223d39dbcSSandrine Bailleux * Juno R0 has the following topology: 4323d39dbcSSandrine Bailleux * - Quad core Cortex-A53 processor cluster; 4423d39dbcSSandrine Bailleux * - Dual core Cortex-A57 processor cluster. 4523d39dbcSSandrine Bailleux * 4623d39dbcSSandrine Bailleux * This handler does the following: 4785135283SDan Handley * - Implement workaround for defect id 831273 by enabling an event 4885135283SDan Handley * stream every 65536 cycles. 4985135283SDan Handley * - Set the L2 Data RAM latency to 2 (i.e. 3 cycles) for Cortex-A57 5085135283SDan Handley * - Set the L2 Tag RAM latency to 2 (i.e. 3 cycles) for Cortex-A57 5123d39dbcSSandrine Bailleux * -------------------------------------------------------------------- 5223d39dbcSSandrine Bailleux */ 5323d39dbcSSandrine Bailleuxfunc JUNO_HANDLER(0) 5423d39dbcSSandrine Bailleux /* -------------------------------------------------------------------- 5523d39dbcSSandrine Bailleux * Enable the event stream every 65536 cycles 5623d39dbcSSandrine Bailleux * -------------------------------------------------------------------- 5723d39dbcSSandrine Bailleux */ 5823d39dbcSSandrine Bailleux mov x0, #(0xf << EVNTI_SHIFT) 5923d39dbcSSandrine Bailleux orr x0, x0, #EVNTEN_BIT 6023d39dbcSSandrine Bailleux msr CNTKCTL_EL1, x0 6123d39dbcSSandrine Bailleux 6223d39dbcSSandrine Bailleux /* -------------------------------------------------------------------- 6323d39dbcSSandrine Bailleux * Nothing else to do on Cortex-A53. 6423d39dbcSSandrine Bailleux * -------------------------------------------------------------------- 6523d39dbcSSandrine Bailleux */ 6623d39dbcSSandrine Bailleux jump_if_cpu_midr CORTEX_A53_MIDR, 1f 6723d39dbcSSandrine Bailleux 6823d39dbcSSandrine Bailleux /* -------------------------------------------------------------------- 6923d39dbcSSandrine Bailleux * Cortex-A57 specific settings 7023d39dbcSSandrine Bailleux * -------------------------------------------------------------------- 7123d39dbcSSandrine Bailleux */ 72fb7d32e5SVarun Wadekar mov x0, #((CORTEX_A57_L2_DATA_RAM_LATENCY_3_CYCLES << CORTEX_A57_L2CTLR_DATA_RAM_LATENCY_SHIFT) | \ 73fb7d32e5SVarun Wadekar (CORTEX_A57_L2_TAG_RAM_LATENCY_3_CYCLES << CORTEX_A57_L2CTLR_TAG_RAM_LATENCY_SHIFT)) 74fb7d32e5SVarun Wadekar msr CORTEX_A57_L2CTLR_EL1, x0 7523d39dbcSSandrine Bailleux1: 7623d39dbcSSandrine Bailleux isb 7723d39dbcSSandrine Bailleux ret 7823d39dbcSSandrine Bailleuxendfunc JUNO_HANDLER(0) 7923d39dbcSSandrine Bailleux 8023d39dbcSSandrine Bailleux /* -------------------------------------------------------------------- 8123d39dbcSSandrine Bailleux * Platform reset handler for Juno R1. 8285135283SDan Handley * 8323d39dbcSSandrine Bailleux * Juno R1 has the following topology: 8423d39dbcSSandrine Bailleux * - Quad core Cortex-A53 processor cluster; 8523d39dbcSSandrine Bailleux * - Dual core Cortex-A57 processor cluster. 8623d39dbcSSandrine Bailleux * 8723d39dbcSSandrine Bailleux * This handler does the following: 8885135283SDan Handley * - Set the L2 Data RAM latency to 2 (i.e. 3 cycles) for Cortex-A57 8923d39dbcSSandrine Bailleux * 9085135283SDan Handley * Note that: 9185135283SDan Handley * - The default value for the L2 Tag RAM latency for Cortex-A57 is 9285135283SDan Handley * suitable. 9323d39dbcSSandrine Bailleux * - Defect #831273 doesn't affect Juno R1. 9485135283SDan Handley * -------------------------------------------------------------------- 9585135283SDan Handley */ 9623d39dbcSSandrine Bailleuxfunc JUNO_HANDLER(1) 9785135283SDan Handley /* -------------------------------------------------------------------- 9823d39dbcSSandrine Bailleux * Nothing to do on Cortex-A53. 9985135283SDan Handley * -------------------------------------------------------------------- 10085135283SDan Handley */ 10123d39dbcSSandrine Bailleux jump_if_cpu_midr CORTEX_A57_MIDR, A57 10285135283SDan Handley ret 10385135283SDan Handley 10485135283SDan HandleyA57: 10585135283SDan Handley /* -------------------------------------------------------------------- 10685135283SDan Handley * Cortex-A57 specific settings 10785135283SDan Handley * -------------------------------------------------------------------- 10885135283SDan Handley */ 109fb7d32e5SVarun Wadekar mov x0, #(CORTEX_A57_L2_DATA_RAM_LATENCY_3_CYCLES << CORTEX_A57_L2CTLR_DATA_RAM_LATENCY_SHIFT) 110fb7d32e5SVarun Wadekar msr CORTEX_A57_L2CTLR_EL1, x0 11185135283SDan Handley isb 11285135283SDan Handley ret 11323d39dbcSSandrine Bailleuxendfunc JUNO_HANDLER(1) 11423d39dbcSSandrine Bailleux 11523d39dbcSSandrine Bailleux /* -------------------------------------------------------------------- 11623d39dbcSSandrine Bailleux * Platform reset handler for Juno R2. 11723d39dbcSSandrine Bailleux * 11823d39dbcSSandrine Bailleux * Juno R2 has the following topology: 11923d39dbcSSandrine Bailleux * - Quad core Cortex-A53 processor cluster; 12023d39dbcSSandrine Bailleux * - Dual core Cortex-A72 processor cluster. 12123d39dbcSSandrine Bailleux * 1221dbe3159SSandrine Bailleux * This handler does the following: 1231dbe3159SSandrine Bailleux * - Set the L2 Data RAM latency to 2 (i.e. 3 cycles) for Cortex-A72 1241dbe3159SSandrine Bailleux * - Set the L2 Tag RAM latency to 1 (i.e. 2 cycles) for Cortex-A72 1251dbe3159SSandrine Bailleux * 1261dbe3159SSandrine Bailleux * Note that: 1271dbe3159SSandrine Bailleux * - Defect #831273 doesn't affect Juno R2. 12823d39dbcSSandrine Bailleux * -------------------------------------------------------------------- 12923d39dbcSSandrine Bailleux */ 13023d39dbcSSandrine Bailleuxfunc JUNO_HANDLER(2) 1311dbe3159SSandrine Bailleux /* -------------------------------------------------------------------- 1321dbe3159SSandrine Bailleux * Nothing to do on Cortex-A53. 1331dbe3159SSandrine Bailleux * -------------------------------------------------------------------- 1341dbe3159SSandrine Bailleux */ 1351dbe3159SSandrine Bailleux jump_if_cpu_midr CORTEX_A72_MIDR, A72 1361dbe3159SSandrine Bailleux ret 1371dbe3159SSandrine Bailleux 1381dbe3159SSandrine BailleuxA72: 1391dbe3159SSandrine Bailleux /* -------------------------------------------------------------------- 1401dbe3159SSandrine Bailleux * Cortex-A72 specific settings 1411dbe3159SSandrine Bailleux * -------------------------------------------------------------------- 1421dbe3159SSandrine Bailleux */ 143fb7d32e5SVarun Wadekar mov x0, #((CORTEX_A72_L2_DATA_RAM_LATENCY_3_CYCLES << CORTEX_A72_L2CTLR_DATA_RAM_LATENCY_SHIFT) | \ 144fb7d32e5SVarun Wadekar (CORTEX_A72_L2_TAG_RAM_LATENCY_2_CYCLES << CORTEX_A72_L2CTLR_TAG_RAM_LATENCY_SHIFT)) 145fb7d32e5SVarun Wadekar msr CORTEX_A57_L2CTLR_EL1, x0 1461dbe3159SSandrine Bailleux isb 14723d39dbcSSandrine Bailleux ret 14823d39dbcSSandrine Bailleuxendfunc JUNO_HANDLER(2) 14923d39dbcSSandrine Bailleux 15023d39dbcSSandrine Bailleux /* -------------------------------------------------------------------- 15123d39dbcSSandrine Bailleux * void plat_reset_handler(void); 15223d39dbcSSandrine Bailleux * 15323d39dbcSSandrine Bailleux * Determine the Juno board revision and call the appropriate reset 15423d39dbcSSandrine Bailleux * handler. 15523d39dbcSSandrine Bailleux * -------------------------------------------------------------------- 15623d39dbcSSandrine Bailleux */ 15723d39dbcSSandrine Bailleuxfunc plat_reset_handler 15823d39dbcSSandrine Bailleux /* Read the V2M SYS_ID register */ 15923d39dbcSSandrine Bailleux mov_imm x0, (V2M_SYSREGS_BASE + V2M_SYS_ID) 16023d39dbcSSandrine Bailleux ldr w1, [x0] 16123d39dbcSSandrine Bailleux /* Extract board revision from the SYS_ID */ 16223d39dbcSSandrine Bailleux ubfx x0, x1, #V2M_SYS_ID_REV_SHIFT, #4 16323d39dbcSSandrine Bailleux 16423d39dbcSSandrine Bailleux JUMP_TO_HANDLER_IF_JUNO_R(0) 16523d39dbcSSandrine Bailleux JUMP_TO_HANDLER_IF_JUNO_R(1) 16623d39dbcSSandrine Bailleux JUMP_TO_HANDLER_IF_JUNO_R(2) 16723d39dbcSSandrine Bailleux 16823d39dbcSSandrine Bailleux /* Board revision is not supported */ 169a806dad5SJeenu Viswambharan no_ret plat_panic_handler 17023d39dbcSSandrine Bailleux 17185135283SDan Handleyendfunc plat_reset_handler 172371d4399SDavid Wang 173371d4399SDavid Wang /* ----------------------------------------------------- 17407570d59SYatharth Kochar * void juno_do_reset_to_aarch32_state(void); 17507570d59SYatharth Kochar * 17607570d59SYatharth Kochar * Request warm reset to AArch32 mode. 17707570d59SYatharth Kochar * ----------------------------------------------------- 17807570d59SYatharth Kochar */ 17907570d59SYatharth Kocharfunc juno_do_reset_to_aarch32_state 18007570d59SYatharth Kochar mov x0, #RMR_EL3_RR_BIT 18107570d59SYatharth Kochar dsb sy 18207570d59SYatharth Kochar msr rmr_el3, x0 18307570d59SYatharth Kochar isb 18407570d59SYatharth Kochar wfi 185d9b7636eSRoberto Vargas b plat_panic_handler 18607570d59SYatharth Kocharendfunc juno_do_reset_to_aarch32_state 18707570d59SYatharth Kochar 18807570d59SYatharth Kochar /* ----------------------------------------------------- 1894c0d0390SSoby Mathew * unsigned int plat_arm_calc_core_pos(u_register_t mpidr) 190371d4399SDavid Wang * Helper function to calculate the core position. 191371d4399SDavid Wang * ----------------------------------------------------- 192371d4399SDavid Wang */ 193371d4399SDavid Wangfunc plat_arm_calc_core_pos 194371d4399SDavid Wang b css_calc_core_pos_swap_cluster 195371d4399SDavid Wangendfunc plat_arm_calc_core_pos 19607570d59SYatharth Kochar 19707570d59SYatharth Kochar#if JUNO_AARCH32_EL3_RUNTIME 19807570d59SYatharth Kochar /* --------------------------------------------------------------------- 19907570d59SYatharth Kochar * uintptr_t plat_get_my_entrypoint (void); 20007570d59SYatharth Kochar * 20107570d59SYatharth Kochar * Main job of this routine is to distinguish between a cold and a warm 20207570d59SYatharth Kochar * boot. On JUNO platform, this distinction is based on the contents of 20307570d59SYatharth Kochar * the Trusted Mailbox. It is initialised to zero by the SCP before the 20407570d59SYatharth Kochar * AP cores are released from reset. Therefore, a zero mailbox means 20507570d59SYatharth Kochar * it's a cold reset. If it is a warm boot then a request to reset to 20607570d59SYatharth Kochar * AArch32 state is issued. This is the only way to reset to AArch32 20707570d59SYatharth Kochar * in EL3 on Juno. A trampoline located at the high vector address 20807570d59SYatharth Kochar * has already been prepared by BL1. 20907570d59SYatharth Kochar * 21007570d59SYatharth Kochar * This functions returns the contents of the mailbox, i.e.: 21107570d59SYatharth Kochar * - 0 for a cold boot; 21207570d59SYatharth Kochar * - request warm reset in AArch32 state for warm boot case; 21307570d59SYatharth Kochar * --------------------------------------------------------------------- 21407570d59SYatharth Kochar */ 21507570d59SYatharth Kocharfunc plat_get_my_entrypoint 21607570d59SYatharth Kochar mov_imm x0, PLAT_ARM_TRUSTED_MAILBOX_BASE 21707570d59SYatharth Kochar ldr x0, [x0] 21807570d59SYatharth Kochar cbz x0, return 21907570d59SYatharth Kochar b juno_do_reset_to_aarch32_state 22007570d59SYatharth Kocharreturn: 22107570d59SYatharth Kochar ret 22207570d59SYatharth Kocharendfunc plat_get_my_entrypoint 22307570d59SYatharth Kochar 22407570d59SYatharth Kochar/* 22507570d59SYatharth Kochar * Emit a "movw r0, #imm16" which moves the lower 22607570d59SYatharth Kochar * 16 bits of `_val` into r0. 22707570d59SYatharth Kochar */ 22807570d59SYatharth Kochar.macro emit_movw _reg_d, _val 22907570d59SYatharth Kochar mov_imm \_reg_d, (0xe3000000 | \ 23007570d59SYatharth Kochar ((\_val & 0xfff) | \ 23107570d59SYatharth Kochar ((\_val & 0xf000) << 4))) 23207570d59SYatharth Kochar.endm 23307570d59SYatharth Kochar 23407570d59SYatharth Kochar/* 23507570d59SYatharth Kochar * Emit a "movt r0, #imm16" which moves the upper 23607570d59SYatharth Kochar * 16 bits of `_val` into r0. 23707570d59SYatharth Kochar */ 23807570d59SYatharth Kochar.macro emit_movt _reg_d, _val 23907570d59SYatharth Kochar mov_imm \_reg_d, (0xe3400000 | \ 24007570d59SYatharth Kochar (((\_val & 0x0fff0000) >> 16) | \ 24107570d59SYatharth Kochar ((\_val & 0xf0000000) >> 12))) 24207570d59SYatharth Kochar.endm 24307570d59SYatharth Kochar 24407570d59SYatharth Kochar/* 24507570d59SYatharth Kochar * This function writes the trampoline code at HI-VEC (0xFFFF0000) 24607570d59SYatharth Kochar * address which loads r0 with the entrypoint address for 24707570d59SYatharth Kochar * BL32 (a.k.a SP_MIN) when EL3 is in AArch32 mode. A warm reset 24807570d59SYatharth Kochar * to AArch32 mode is then requested by writing into RMR_EL3. 24907570d59SYatharth Kochar */ 25007570d59SYatharth Kocharfunc juno_reset_to_aarch32_state 25135bd2ddaSDimitris Papastamos /* 25235bd2ddaSDimitris Papastamos * Invalidate all caches before the warm reset to AArch32 state. 25335bd2ddaSDimitris Papastamos * This is required on the Juno AArch32 boot flow because the L2 25435bd2ddaSDimitris Papastamos * unified cache may contain code and data from when the processor 25535bd2ddaSDimitris Papastamos * was still executing in AArch64 state. This code only runs on 25635bd2ddaSDimitris Papastamos * the primary core, all other cores are powered down. 25735bd2ddaSDimitris Papastamos */ 25835bd2ddaSDimitris Papastamos mov x0, #DCISW 25935bd2ddaSDimitris Papastamos bl dcsw_op_all 26035bd2ddaSDimitris Papastamos 26107570d59SYatharth Kochar emit_movw w0, BL32_BASE 26207570d59SYatharth Kochar emit_movt w1, BL32_BASE 26307570d59SYatharth Kochar /* opcode "bx r0" to branch using r0 in AArch32 mode */ 26407570d59SYatharth Kochar mov_imm w2, 0xe12fff10 26507570d59SYatharth Kochar 26607570d59SYatharth Kochar /* Write the above opcodes at HI-VECTOR location */ 26707570d59SYatharth Kochar mov_imm x3, HI_VECTOR_BASE 26807570d59SYatharth Kochar str w0, [x3], #4 26907570d59SYatharth Kochar str w1, [x3], #4 27007570d59SYatharth Kochar str w2, [x3] 27107570d59SYatharth Kochar 272d9b7636eSRoberto Vargas b juno_do_reset_to_aarch32_state 27307570d59SYatharth Kocharendfunc juno_reset_to_aarch32_state 27407570d59SYatharth Kochar 27507570d59SYatharth Kochar#endif /* JUNO_AARCH32_EL3_RUNTIME */ 276