13fc4124cSDan Handley/* 211ad8f20SJeenu Viswambharan * Copyright (c) 2013-2017, ARM Limited and Contributors. All rights reserved. 33fc4124cSDan Handley * 482cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause 53fc4124cSDan Handley */ 63fc4124cSDan Handley 73fc4124cSDan Handley#include <arch.h> 83fc4124cSDan Handley#include <asm_macros.S> 9*09d40e0eSAntonio Nino Diaz#include <drivers/arm/gicv2.h> 10*09d40e0eSAntonio Nino Diaz#include <drivers/arm/gicv3.h> 113fc4124cSDan Handley#include <platform_def.h> 123fc4124cSDan Handley#include <v2m_def.h> 133fc4124cSDan Handley#include "../drivers/pwrc/fvp_pwrc.h" 143fc4124cSDan Handley#include "../fvp_def.h" 153fc4124cSDan Handley 163fc4124cSDan Handley .globl plat_secondary_cold_boot_setup 1738dce70fSSoby Mathew .globl plat_get_my_entrypoint 1838dce70fSSoby Mathew .globl plat_is_my_cpu_primary 1911ad8f20SJeenu Viswambharan .globl plat_arm_calc_core_pos 203fc4124cSDan Handley 213fc4124cSDan Handley .macro fvp_choose_gicmmap param1, param2, x_tmp, w_tmp, res 22bd83b396SSoby Mathew mov_imm \x_tmp, V2M_SYSREGS_BASE + V2M_SYS_ID 233fc4124cSDan Handley ldr \w_tmp, [\x_tmp] 243fc4124cSDan Handley ubfx \w_tmp, \w_tmp, #V2M_SYS_ID_BLD_SHIFT, #V2M_SYS_ID_BLD_LENGTH 253fc4124cSDan Handley cmp \w_tmp, #BLD_GIC_VE_MMAP 263fc4124cSDan Handley csel \res, \param1, \param2, eq 273fc4124cSDan Handley .endm 283fc4124cSDan Handley 293fc4124cSDan Handley /* ----------------------------------------------------- 303fc4124cSDan Handley * void plat_secondary_cold_boot_setup (void); 313fc4124cSDan Handley * 323fc4124cSDan Handley * This function performs any platform specific actions 333fc4124cSDan Handley * needed for a secondary cpu after a cold reset e.g 343fc4124cSDan Handley * mark the cpu's presence, mechanism to place it in a 353fc4124cSDan Handley * holding pen etc. 363fc4124cSDan Handley * TODO: Should we read the PSYS register to make sure 373fc4124cSDan Handley * that the request has gone through. 383fc4124cSDan Handley * ----------------------------------------------------- 393fc4124cSDan Handley */ 403fc4124cSDan Handleyfunc plat_secondary_cold_boot_setup 41cdf14088SSandrine Bailleux#ifndef EL3_PAYLOAD_BASE 423fc4124cSDan Handley /* --------------------------------------------- 433fc4124cSDan Handley * Power down this cpu. 443fc4124cSDan Handley * TODO: Do we need to worry about powering the 453fc4124cSDan Handley * cluster down as well here. That will need 463fc4124cSDan Handley * locks which we won't have unless an elf- 473fc4124cSDan Handley * loader zeroes out the zi section. 483fc4124cSDan Handley * --------------------------------------------- 493fc4124cSDan Handley */ 503fc4124cSDan Handley mrs x0, mpidr_el1 51bd83b396SSoby Mathew mov_imm x1, PWRC_BASE 523fc4124cSDan Handley str w0, [x1, #PPOFFR_OFF] 533fc4124cSDan Handley 543fc4124cSDan Handley /* --------------------------------------------- 55f14d1886SSoby Mathew * Disable GIC bypass as well 563fc4124cSDan Handley * --------------------------------------------- 573fc4124cSDan Handley */ 58f14d1886SSoby Mathew /* Check for GICv3 system register access */ 59f14d1886SSoby Mathew mrs x0, id_aa64pfr0_el1 60f14d1886SSoby Mathew ubfx x0, x0, #ID_AA64PFR0_GIC_SHIFT, #ID_AA64PFR0_GIC_WIDTH 61f14d1886SSoby Mathew cmp x0, #1 62f14d1886SSoby Mathew b.ne gicv2_bypass_disable 63f14d1886SSoby Mathew 64f14d1886SSoby Mathew /* Check for SRE enable */ 65f14d1886SSoby Mathew mrs x1, ICC_SRE_EL3 66f14d1886SSoby Mathew tst x1, #ICC_SRE_SRE_BIT 67f14d1886SSoby Mathew b.eq gicv2_bypass_disable 68f14d1886SSoby Mathew 69f14d1886SSoby Mathew mrs x2, ICC_SRE_EL3 70f14d1886SSoby Mathew orr x2, x2, #(ICC_SRE_DIB_BIT | ICC_SRE_DFB_BIT) 71f14d1886SSoby Mathew msr ICC_SRE_EL3, x2 72f14d1886SSoby Mathew b secondary_cold_boot_wait 73f14d1886SSoby Mathew 74f14d1886SSoby Mathewgicv2_bypass_disable: 75bd83b396SSoby Mathew mov_imm x0, VE_GICC_BASE 76bd83b396SSoby Mathew mov_imm x1, BASE_GICC_BASE 773fc4124cSDan Handley fvp_choose_gicmmap x0, x1, x2, w2, x1 783fc4124cSDan Handley mov w0, #(IRQ_BYP_DIS_GRP1 | FIQ_BYP_DIS_GRP1) 793fc4124cSDan Handley orr w0, w0, #(IRQ_BYP_DIS_GRP0 | FIQ_BYP_DIS_GRP0) 803fc4124cSDan Handley str w0, [x1, #GICC_CTLR] 813fc4124cSDan Handley 82f14d1886SSoby Mathewsecondary_cold_boot_wait: 833fc4124cSDan Handley /* --------------------------------------------- 843fc4124cSDan Handley * There is no sane reason to come out of this 853fc4124cSDan Handley * wfi so panic if we do. This cpu will be pow- 863fc4124cSDan Handley * ered on and reset by the cpu_on pm api 873fc4124cSDan Handley * --------------------------------------------- 883fc4124cSDan Handley */ 893fc4124cSDan Handley dsb sy 903fc4124cSDan Handley wfi 91a806dad5SJeenu Viswambharan no_ret plat_panic_handler 92cdf14088SSandrine Bailleux#else 93cdf14088SSandrine Bailleux mov_imm x0, PLAT_ARM_TRUSTED_MAILBOX_BASE 94cdf14088SSandrine Bailleux 95cdf14088SSandrine Bailleux /* Wait until the entrypoint gets populated */ 96cdf14088SSandrine Bailleuxpoll_mailbox: 97cdf14088SSandrine Bailleux ldr x1, [x0] 98cdf14088SSandrine Bailleux cbz x1, 1f 99cdf14088SSandrine Bailleux br x1 100cdf14088SSandrine Bailleux1: 101cdf14088SSandrine Bailleux wfe 102cdf14088SSandrine Bailleux b poll_mailbox 103cdf14088SSandrine Bailleux#endif /* EL3_PAYLOAD_BASE */ 1043fc4124cSDan Handleyendfunc plat_secondary_cold_boot_setup 1053fc4124cSDan Handley 106804040d1SSandrine Bailleux /* --------------------------------------------------------------------- 1074c0d0390SSoby Mathew * uintptr_t plat_get_my_entrypoint (void); 1083fc4124cSDan Handley * 109804040d1SSandrine Bailleux * Main job of this routine is to distinguish between a cold and warm 110804040d1SSandrine Bailleux * boot. On FVP, this information can be queried from the power 111804040d1SSandrine Bailleux * controller. The Power Control SYS Status Register (PSYSR) indicates 112804040d1SSandrine Bailleux * the wake-up reason for the CPU. 1133fc4124cSDan Handley * 114804040d1SSandrine Bailleux * For a cold boot, return 0. 115804040d1SSandrine Bailleux * For a warm boot, read the mailbox and return the address it contains. 116804040d1SSandrine Bailleux * 1173fc4124cSDan Handley * TODO: PSYSR is a common register and should be 1181645d3eeSSandrine Bailleux * accessed using locks. Since it is not possible 1193fc4124cSDan Handley * to use locks immediately after a cold reset 1203fc4124cSDan Handley * we are relying on the fact that after a cold 1213fc4124cSDan Handley * reset all cpus will read the same WK field 122804040d1SSandrine Bailleux * --------------------------------------------------------------------- 1233fc4124cSDan Handley */ 12438dce70fSSoby Mathewfunc plat_get_my_entrypoint 125804040d1SSandrine Bailleux /* --------------------------------------------------------------------- 126804040d1SSandrine Bailleux * When bit PSYSR.WK indicates either "Wake by PPONR" or "Wake by GIC 127804040d1SSandrine Bailleux * WakeRequest signal" then it is a warm boot. 128804040d1SSandrine Bailleux * --------------------------------------------------------------------- 129804040d1SSandrine Bailleux */ 13038dce70fSSoby Mathew mrs x2, mpidr_el1 131bd83b396SSoby Mathew mov_imm x1, PWRC_BASE 1323fc4124cSDan Handley str w2, [x1, #PSYSR_OFF] 1333fc4124cSDan Handley ldr w2, [x1, #PSYSR_OFF] 134c8f0c3f7SSoby Mathew ubfx w2, w2, #PSYSR_WK_SHIFT, #PSYSR_WK_WIDTH 1353fc4124cSDan Handley cmp w2, #WKUP_PPONR 1363fc4124cSDan Handley beq warm_reset 1373fc4124cSDan Handley cmp w2, #WKUP_GICREQ 1383fc4124cSDan Handley beq warm_reset 139804040d1SSandrine Bailleux 140804040d1SSandrine Bailleux /* Cold reset */ 1413fc4124cSDan Handley mov x0, #0 142804040d1SSandrine Bailleux ret 143804040d1SSandrine Bailleux 1443fc4124cSDan Handleywarm_reset: 145804040d1SSandrine Bailleux /* --------------------------------------------------------------------- 146804040d1SSandrine Bailleux * A mailbox is maintained in the trusted SRAM. It is flushed out of the 147804040d1SSandrine Bailleux * caches after every update using normal memory so it is safe to read 148804040d1SSandrine Bailleux * it here with SO attributes. 149804040d1SSandrine Bailleux * --------------------------------------------------------------------- 1503fc4124cSDan Handley */ 151785fb92bSSoby Mathew mov_imm x0, PLAT_ARM_TRUSTED_MAILBOX_BASE 152804040d1SSandrine Bailleux ldr x0, [x0] 1531c3ea103SAntonio Nino Diaz cbz x0, _panic_handler 154804040d1SSandrine Bailleux ret 155804040d1SSandrine Bailleux 156804040d1SSandrine Bailleux /* --------------------------------------------------------------------- 157804040d1SSandrine Bailleux * The power controller indicates this is a warm reset but the mailbox 158804040d1SSandrine Bailleux * is empty. This should never happen! 159804040d1SSandrine Bailleux * --------------------------------------------------------------------- 160804040d1SSandrine Bailleux */ 1611c3ea103SAntonio Nino Diaz_panic_handler: 162a806dad5SJeenu Viswambharan no_ret plat_panic_handler 16338dce70fSSoby Mathewendfunc plat_get_my_entrypoint 1643fc4124cSDan Handley 16558523c07SSoby Mathew /* ----------------------------------------------------- 16658523c07SSoby Mathew * unsigned int plat_is_my_cpu_primary (void); 16758523c07SSoby Mathew * 16858523c07SSoby Mathew * Find out whether the current cpu is the primary 16958523c07SSoby Mathew * cpu. 17058523c07SSoby Mathew * ----------------------------------------------------- 17158523c07SSoby Mathew */ 17238dce70fSSoby Mathewfunc plat_is_my_cpu_primary 17338dce70fSSoby Mathew mrs x0, mpidr_el1 174bd83b396SSoby Mathew mov_imm x1, MPIDR_AFFINITY_MASK 17511ad8f20SJeenu Viswambharan and x0, x0, x1 1763fc4124cSDan Handley cmp x0, #FVP_PRIMARY_CPU 17758523c07SSoby Mathew cset w0, eq 1783fc4124cSDan Handley ret 17938dce70fSSoby Mathewendfunc plat_is_my_cpu_primary 18011ad8f20SJeenu Viswambharan 18139b21d19SWang Feng /* --------------------------------------------------------------------- 18211ad8f20SJeenu Viswambharan * unsigned int plat_arm_calc_core_pos(u_register_t mpidr) 18311ad8f20SJeenu Viswambharan * 18411ad8f20SJeenu Viswambharan * Function to calculate the core position on FVP. 18511ad8f20SJeenu Viswambharan * 18639b21d19SWang Feng * (ClusterId * FVP_MAX_CPUS_PER_CLUSTER * FVP_MAX_PE_PER_CPU) + 18711ad8f20SJeenu Viswambharan * (CPUId * FVP_MAX_PE_PER_CPU) + 18811ad8f20SJeenu Viswambharan * ThreadId 18939b21d19SWang Feng * 19039b21d19SWang Feng * which can be simplified as: 19139b21d19SWang Feng * 19239b21d19SWang Feng * ((ClusterId * FVP_MAX_CPUS_PER_CLUSTER + CPUId) * FVP_MAX_PE_PER_CPU) 19339b21d19SWang Feng * + ThreadId 19439b21d19SWang Feng * --------------------------------------------------------------------- 19511ad8f20SJeenu Viswambharan */ 19611ad8f20SJeenu Viswambharanfunc plat_arm_calc_core_pos 19711ad8f20SJeenu Viswambharan /* 19811ad8f20SJeenu Viswambharan * Check for MT bit in MPIDR. If not set, shift MPIDR to left to make it 19911ad8f20SJeenu Viswambharan * look as if in a multi-threaded implementation. 20011ad8f20SJeenu Viswambharan */ 20111ad8f20SJeenu Viswambharan tst x0, #MPIDR_MT_MASK 20211ad8f20SJeenu Viswambharan lsl x3, x0, #MPIDR_AFFINITY_BITS 20311ad8f20SJeenu Viswambharan csel x3, x3, x0, eq 20411ad8f20SJeenu Viswambharan 20511ad8f20SJeenu Viswambharan /* Extract individual affinity fields from MPIDR */ 20611ad8f20SJeenu Viswambharan ubfx x0, x3, #MPIDR_AFF0_SHIFT, #MPIDR_AFFINITY_BITS 20711ad8f20SJeenu Viswambharan ubfx x1, x3, #MPIDR_AFF1_SHIFT, #MPIDR_AFFINITY_BITS 20811ad8f20SJeenu Viswambharan ubfx x2, x3, #MPIDR_AFF2_SHIFT, #MPIDR_AFFINITY_BITS 20911ad8f20SJeenu Viswambharan 21011ad8f20SJeenu Viswambharan /* Compute linear position */ 21139b21d19SWang Feng mov x4, #FVP_MAX_CPUS_PER_CLUSTER 21239b21d19SWang Feng madd x1, x2, x4, x1 21339b21d19SWang Feng mov x5, #FVP_MAX_PE_PER_CPU 21439b21d19SWang Feng madd x0, x1, x5, x0 21511ad8f20SJeenu Viswambharan ret 21611ad8f20SJeenu Viswambharanendfunc plat_arm_calc_core_pos 217