13fc4124cSDan Handley/* 29c29e5f7SJohn Tsichritzis * Copyright (c) 2013-2019, 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*d38c64d2SGovindraj Raja#include <drivers/arm/fvp/fvp_cpu_pwr.h> 10*d38c64d2SGovindraj Raja#include <drivers/arm/fvp/fvp_pwrc.h> 1109d40e0eSAntonio Nino Diaz#include <drivers/arm/gicv2.h> 1209d40e0eSAntonio Nino Diaz#include <drivers/arm/gicv3.h> 133fc4124cSDan Handley#include <platform_def.h> 14234bc7f8SAntonio Nino Diaz 153fc4124cSDan Handley .globl plat_secondary_cold_boot_setup 1638dce70fSSoby Mathew .globl plat_get_my_entrypoint 1738dce70fSSoby Mathew .globl plat_is_my_cpu_primary 1811ad8f20SJeenu Viswambharan .globl plat_arm_calc_core_pos 193fc4124cSDan Handley 203fc4124cSDan Handley /* ----------------------------------------------------- 213fc4124cSDan Handley * void plat_secondary_cold_boot_setup (void); 223fc4124cSDan Handley * 233fc4124cSDan Handley * This function performs any platform specific actions 243fc4124cSDan Handley * needed for a secondary cpu after a cold reset e.g 253fc4124cSDan Handley * mark the cpu's presence, mechanism to place it in a 263fc4124cSDan Handley * holding pen etc. 273fc4124cSDan Handley * TODO: Should we read the PSYS register to make sure 283fc4124cSDan Handley * that the request has gone through. 293fc4124cSDan Handley * ----------------------------------------------------- 303fc4124cSDan Handley */ 313fc4124cSDan Handleyfunc plat_secondary_cold_boot_setup 32cdf14088SSandrine Bailleux#ifndef EL3_PAYLOAD_BASE 33*d38c64d2SGovindraj Raja 34*d38c64d2SGovindraj Raja /* -------------------------------------------- 35*d38c64d2SGovindraj Raja * Check if core supports powering down, if it 36*d38c64d2SGovindraj Raja * supports power down then set core power down 37*d38c64d2SGovindraj Raja * bit before requesting for the cores to be 38*d38c64d2SGovindraj Raja * powered off from base power controller. 39*d38c64d2SGovindraj Raja * --------------------------------------------- 40*d38c64d2SGovindraj Raja */ 41*d38c64d2SGovindraj Raja bl check_cpupwrctrl_el1_is_available 42*d38c64d2SGovindraj Raja cbz x0, base_power_off 43*d38c64d2SGovindraj Raja 44*d38c64d2SGovindraj Raja mrs x1, CPUPWRCTLR_EL1 45*d38c64d2SGovindraj Raja orr x1, x1, #CPUPWRCTLR_EL1_CORE_PWRDN_BIT 46*d38c64d2SGovindraj Raja msr CPUPWRCTLR_EL1, x1 47*d38c64d2SGovindraj Raja 483fc4124cSDan Handley /* --------------------------------------------- 493fc4124cSDan Handley * Power down this cpu. 503fc4124cSDan Handley * TODO: Do we need to worry about powering the 513fc4124cSDan Handley * cluster down as well here. That will need 523fc4124cSDan Handley * locks which we won't have unless an elf- 533fc4124cSDan Handley * loader zeroes out the zi section. 543fc4124cSDan Handley * --------------------------------------------- 553fc4124cSDan Handley */ 56*d38c64d2SGovindraj Rajabase_power_off: 573fc4124cSDan Handley mrs x0, mpidr_el1 58bd83b396SSoby Mathew mov_imm x1, PWRC_BASE 593fc4124cSDan Handley str w0, [x1, #PPOFFR_OFF] 603fc4124cSDan Handley 613fc4124cSDan Handley /* --------------------------------------------- 623fc4124cSDan Handley * There is no sane reason to come out of this 633fc4124cSDan Handley * wfi so panic if we do. This cpu will be pow- 643fc4124cSDan Handley * ered on and reset by the cpu_on pm api 653fc4124cSDan Handley * --------------------------------------------- 663fc4124cSDan Handley */ 673fc4124cSDan Handley dsb sy 683fc4124cSDan Handley wfi 69a806dad5SJeenu Viswambharan no_ret plat_panic_handler 70cdf14088SSandrine Bailleux#else 71cdf14088SSandrine Bailleux mov_imm x0, PLAT_ARM_TRUSTED_MAILBOX_BASE 72cdf14088SSandrine Bailleux 73cdf14088SSandrine Bailleux /* Wait until the entrypoint gets populated */ 74cdf14088SSandrine Bailleuxpoll_mailbox: 75cdf14088SSandrine Bailleux ldr x1, [x0] 76cdf14088SSandrine Bailleux cbz x1, 1f 77cdf14088SSandrine Bailleux br x1 78cdf14088SSandrine Bailleux1: 79cdf14088SSandrine Bailleux wfe 80cdf14088SSandrine Bailleux b poll_mailbox 81cdf14088SSandrine Bailleux#endif /* EL3_PAYLOAD_BASE */ 823fc4124cSDan Handleyendfunc plat_secondary_cold_boot_setup 833fc4124cSDan Handley 84804040d1SSandrine Bailleux /* --------------------------------------------------------------------- 854c0d0390SSoby Mathew * uintptr_t plat_get_my_entrypoint (void); 863fc4124cSDan Handley * 87804040d1SSandrine Bailleux * Main job of this routine is to distinguish between a cold and warm 88804040d1SSandrine Bailleux * boot. On FVP, this information can be queried from the power 89804040d1SSandrine Bailleux * controller. The Power Control SYS Status Register (PSYSR) indicates 90804040d1SSandrine Bailleux * the wake-up reason for the CPU. 913fc4124cSDan Handley * 92804040d1SSandrine Bailleux * For a cold boot, return 0. 93804040d1SSandrine Bailleux * For a warm boot, read the mailbox and return the address it contains. 94804040d1SSandrine Bailleux * 953fc4124cSDan Handley * TODO: PSYSR is a common register and should be 961645d3eeSSandrine Bailleux * accessed using locks. Since it is not possible 973fc4124cSDan Handley * to use locks immediately after a cold reset 983fc4124cSDan Handley * we are relying on the fact that after a cold 993fc4124cSDan Handley * reset all cpus will read the same WK field 100804040d1SSandrine Bailleux * --------------------------------------------------------------------- 1013fc4124cSDan Handley */ 10238dce70fSSoby Mathewfunc plat_get_my_entrypoint 103804040d1SSandrine Bailleux /* --------------------------------------------------------------------- 104804040d1SSandrine Bailleux * When bit PSYSR.WK indicates either "Wake by PPONR" or "Wake by GIC 105804040d1SSandrine Bailleux * WakeRequest signal" then it is a warm boot. 106804040d1SSandrine Bailleux * --------------------------------------------------------------------- 107804040d1SSandrine Bailleux */ 10838dce70fSSoby Mathew mrs x2, mpidr_el1 109bd83b396SSoby Mathew mov_imm x1, PWRC_BASE 1103fc4124cSDan Handley str w2, [x1, #PSYSR_OFF] 1113fc4124cSDan Handley ldr w2, [x1, #PSYSR_OFF] 112c8f0c3f7SSoby Mathew ubfx w2, w2, #PSYSR_WK_SHIFT, #PSYSR_WK_WIDTH 1133fc4124cSDan Handley cmp w2, #WKUP_PPONR 1143fc4124cSDan Handley beq warm_reset 1153fc4124cSDan Handley cmp w2, #WKUP_GICREQ 1163fc4124cSDan Handley beq warm_reset 117804040d1SSandrine Bailleux 118804040d1SSandrine Bailleux /* Cold reset */ 1193fc4124cSDan Handley mov x0, #0 120804040d1SSandrine Bailleux ret 121804040d1SSandrine Bailleux 1223fc4124cSDan Handleywarm_reset: 123804040d1SSandrine Bailleux /* --------------------------------------------------------------------- 124804040d1SSandrine Bailleux * A mailbox is maintained in the trusted SRAM. It is flushed out of the 125804040d1SSandrine Bailleux * caches after every update using normal memory so it is safe to read 126804040d1SSandrine Bailleux * it here with SO attributes. 127804040d1SSandrine Bailleux * --------------------------------------------------------------------- 1283fc4124cSDan Handley */ 129785fb92bSSoby Mathew mov_imm x0, PLAT_ARM_TRUSTED_MAILBOX_BASE 130804040d1SSandrine Bailleux ldr x0, [x0] 1311c3ea103SAntonio Nino Diaz cbz x0, _panic_handler 132804040d1SSandrine Bailleux ret 133804040d1SSandrine Bailleux 134804040d1SSandrine Bailleux /* --------------------------------------------------------------------- 135804040d1SSandrine Bailleux * The power controller indicates this is a warm reset but the mailbox 136804040d1SSandrine Bailleux * is empty. This should never happen! 137804040d1SSandrine Bailleux * --------------------------------------------------------------------- 138804040d1SSandrine Bailleux */ 1391c3ea103SAntonio Nino Diaz_panic_handler: 140a806dad5SJeenu Viswambharan no_ret plat_panic_handler 14138dce70fSSoby Mathewendfunc plat_get_my_entrypoint 1423fc4124cSDan Handley 14358523c07SSoby Mathew /* ----------------------------------------------------- 14458523c07SSoby Mathew * unsigned int plat_is_my_cpu_primary (void); 14558523c07SSoby Mathew * 14658523c07SSoby Mathew * Find out whether the current cpu is the primary 14758523c07SSoby Mathew * cpu. 14858523c07SSoby Mathew * ----------------------------------------------------- 14958523c07SSoby Mathew */ 15038dce70fSSoby Mathewfunc plat_is_my_cpu_primary 15138dce70fSSoby Mathew mrs x0, mpidr_el1 152bd83b396SSoby Mathew mov_imm x1, MPIDR_AFFINITY_MASK 15311ad8f20SJeenu Viswambharan and x0, x0, x1 1543fc4124cSDan Handley cmp x0, #FVP_PRIMARY_CPU 15558523c07SSoby Mathew cset w0, eq 1563fc4124cSDan Handley ret 15738dce70fSSoby Mathewendfunc plat_is_my_cpu_primary 15811ad8f20SJeenu Viswambharan 15939b21d19SWang Feng /* --------------------------------------------------------------------- 16011ad8f20SJeenu Viswambharan * unsigned int plat_arm_calc_core_pos(u_register_t mpidr) 16111ad8f20SJeenu Viswambharan * 16211ad8f20SJeenu Viswambharan * Function to calculate the core position on FVP. 16311ad8f20SJeenu Viswambharan * 16439b21d19SWang Feng * (ClusterId * FVP_MAX_CPUS_PER_CLUSTER * FVP_MAX_PE_PER_CPU) + 16511ad8f20SJeenu Viswambharan * (CPUId * FVP_MAX_PE_PER_CPU) + 16611ad8f20SJeenu Viswambharan * ThreadId 16739b21d19SWang Feng * 16839b21d19SWang Feng * which can be simplified as: 16939b21d19SWang Feng * 17039b21d19SWang Feng * ((ClusterId * FVP_MAX_CPUS_PER_CLUSTER + CPUId) * FVP_MAX_PE_PER_CPU) 17139b21d19SWang Feng * + ThreadId 17239b21d19SWang Feng * --------------------------------------------------------------------- 17311ad8f20SJeenu Viswambharan */ 17411ad8f20SJeenu Viswambharanfunc plat_arm_calc_core_pos 17511ad8f20SJeenu Viswambharan /* 17611ad8f20SJeenu Viswambharan * Check for MT bit in MPIDR. If not set, shift MPIDR to left to make it 17711ad8f20SJeenu Viswambharan * look as if in a multi-threaded implementation. 17811ad8f20SJeenu Viswambharan */ 17911ad8f20SJeenu Viswambharan tst x0, #MPIDR_MT_MASK 18011ad8f20SJeenu Viswambharan lsl x3, x0, #MPIDR_AFFINITY_BITS 18111ad8f20SJeenu Viswambharan csel x3, x3, x0, eq 18211ad8f20SJeenu Viswambharan 18311ad8f20SJeenu Viswambharan /* Extract individual affinity fields from MPIDR */ 18411ad8f20SJeenu Viswambharan ubfx x0, x3, #MPIDR_AFF0_SHIFT, #MPIDR_AFFINITY_BITS 18511ad8f20SJeenu Viswambharan ubfx x1, x3, #MPIDR_AFF1_SHIFT, #MPIDR_AFFINITY_BITS 18611ad8f20SJeenu Viswambharan ubfx x2, x3, #MPIDR_AFF2_SHIFT, #MPIDR_AFFINITY_BITS 18711ad8f20SJeenu Viswambharan 18811ad8f20SJeenu Viswambharan /* Compute linear position */ 18939b21d19SWang Feng mov x4, #FVP_MAX_CPUS_PER_CLUSTER 19039b21d19SWang Feng madd x1, x2, x4, x1 19139b21d19SWang Feng mov x5, #FVP_MAX_PE_PER_CPU 19239b21d19SWang Feng madd x0, x1, x5, x0 19311ad8f20SJeenu Viswambharan ret 19411ad8f20SJeenu Viswambharanendfunc plat_arm_calc_core_pos 195