13fc4124cSDan Handley/* 21c3ea103SAntonio Nino Diaz * Copyright (c) 2013-2016, ARM Limited and Contributors. All rights reserved. 33fc4124cSDan Handley * 43fc4124cSDan Handley * Redistribution and use in source and binary forms, with or without 53fc4124cSDan Handley * modification, are permitted provided that the following conditions are met: 63fc4124cSDan Handley * 73fc4124cSDan Handley * Redistributions of source code must retain the above copyright notice, this 83fc4124cSDan Handley * list of conditions and the following disclaimer. 93fc4124cSDan Handley * 103fc4124cSDan Handley * Redistributions in binary form must reproduce the above copyright notice, 113fc4124cSDan Handley * this list of conditions and the following disclaimer in the documentation 123fc4124cSDan Handley * and/or other materials provided with the distribution. 133fc4124cSDan Handley * 143fc4124cSDan Handley * Neither the name of ARM nor the names of its contributors may be used 153fc4124cSDan Handley * to endorse or promote products derived from this software without specific 163fc4124cSDan Handley * prior written permission. 173fc4124cSDan Handley * 183fc4124cSDan Handley * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 193fc4124cSDan Handley * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 203fc4124cSDan Handley * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 213fc4124cSDan Handley * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 223fc4124cSDan Handley * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 233fc4124cSDan Handley * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 243fc4124cSDan Handley * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 253fc4124cSDan Handley * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 263fc4124cSDan Handley * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 273fc4124cSDan Handley * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 283fc4124cSDan Handley * POSSIBILITY OF SUCH DAMAGE. 293fc4124cSDan Handley */ 303fc4124cSDan Handley 313fc4124cSDan Handley#include <arch.h> 323fc4124cSDan Handley#include <asm_macros.S> 33f14d1886SSoby Mathew#include <gicv2.h> 34f14d1886SSoby Mathew#include <gicv3.h> 353fc4124cSDan Handley#include <platform_def.h> 363fc4124cSDan Handley#include <v2m_def.h> 373fc4124cSDan Handley#include "../drivers/pwrc/fvp_pwrc.h" 383fc4124cSDan Handley#include "../fvp_def.h" 393fc4124cSDan Handley 403fc4124cSDan Handley .globl plat_secondary_cold_boot_setup 4138dce70fSSoby Mathew .globl plat_get_my_entrypoint 4238dce70fSSoby Mathew .globl plat_is_my_cpu_primary 433fc4124cSDan Handley 443fc4124cSDan Handley .macro fvp_choose_gicmmap param1, param2, x_tmp, w_tmp, res 453fc4124cSDan Handley ldr \x_tmp, =V2M_SYSREGS_BASE + V2M_SYS_ID 463fc4124cSDan Handley ldr \w_tmp, [\x_tmp] 473fc4124cSDan Handley ubfx \w_tmp, \w_tmp, #V2M_SYS_ID_BLD_SHIFT, #V2M_SYS_ID_BLD_LENGTH 483fc4124cSDan Handley cmp \w_tmp, #BLD_GIC_VE_MMAP 493fc4124cSDan Handley csel \res, \param1, \param2, eq 503fc4124cSDan Handley .endm 513fc4124cSDan Handley 523fc4124cSDan Handley /* ----------------------------------------------------- 533fc4124cSDan Handley * void plat_secondary_cold_boot_setup (void); 543fc4124cSDan Handley * 553fc4124cSDan Handley * This function performs any platform specific actions 563fc4124cSDan Handley * needed for a secondary cpu after a cold reset e.g 573fc4124cSDan Handley * mark the cpu's presence, mechanism to place it in a 583fc4124cSDan Handley * holding pen etc. 593fc4124cSDan Handley * TODO: Should we read the PSYS register to make sure 603fc4124cSDan Handley * that the request has gone through. 613fc4124cSDan Handley * ----------------------------------------------------- 623fc4124cSDan Handley */ 633fc4124cSDan Handleyfunc plat_secondary_cold_boot_setup 64cdf14088SSandrine Bailleux#ifndef EL3_PAYLOAD_BASE 653fc4124cSDan Handley /* --------------------------------------------- 663fc4124cSDan Handley * Power down this cpu. 673fc4124cSDan Handley * TODO: Do we need to worry about powering the 683fc4124cSDan Handley * cluster down as well here. That will need 693fc4124cSDan Handley * locks which we won't have unless an elf- 703fc4124cSDan Handley * loader zeroes out the zi section. 713fc4124cSDan Handley * --------------------------------------------- 723fc4124cSDan Handley */ 733fc4124cSDan Handley mrs x0, mpidr_el1 743fc4124cSDan Handley ldr x1, =PWRC_BASE 753fc4124cSDan Handley str w0, [x1, #PPOFFR_OFF] 763fc4124cSDan Handley 773fc4124cSDan Handley /* --------------------------------------------- 78f14d1886SSoby Mathew * Disable GIC bypass as well 793fc4124cSDan Handley * --------------------------------------------- 803fc4124cSDan Handley */ 81f14d1886SSoby Mathew /* Check for GICv3 system register access */ 82f14d1886SSoby Mathew mrs x0, id_aa64pfr0_el1 83f14d1886SSoby Mathew ubfx x0, x0, #ID_AA64PFR0_GIC_SHIFT, #ID_AA64PFR0_GIC_WIDTH 84f14d1886SSoby Mathew cmp x0, #1 85f14d1886SSoby Mathew b.ne gicv2_bypass_disable 86f14d1886SSoby Mathew 87f14d1886SSoby Mathew /* Check for SRE enable */ 88f14d1886SSoby Mathew mrs x1, ICC_SRE_EL3 89f14d1886SSoby Mathew tst x1, #ICC_SRE_SRE_BIT 90f14d1886SSoby Mathew b.eq gicv2_bypass_disable 91f14d1886SSoby Mathew 92f14d1886SSoby Mathew mrs x2, ICC_SRE_EL3 93f14d1886SSoby Mathew orr x2, x2, #(ICC_SRE_DIB_BIT | ICC_SRE_DFB_BIT) 94f14d1886SSoby Mathew msr ICC_SRE_EL3, x2 95f14d1886SSoby Mathew b secondary_cold_boot_wait 96f14d1886SSoby Mathew 97f14d1886SSoby Mathewgicv2_bypass_disable: 983fc4124cSDan Handley ldr x0, =VE_GICC_BASE 993fc4124cSDan Handley ldr x1, =BASE_GICC_BASE 1003fc4124cSDan Handley fvp_choose_gicmmap x0, x1, x2, w2, x1 1013fc4124cSDan Handley mov w0, #(IRQ_BYP_DIS_GRP1 | FIQ_BYP_DIS_GRP1) 1023fc4124cSDan Handley orr w0, w0, #(IRQ_BYP_DIS_GRP0 | FIQ_BYP_DIS_GRP0) 1033fc4124cSDan Handley str w0, [x1, #GICC_CTLR] 1043fc4124cSDan Handley 105f14d1886SSoby Mathewsecondary_cold_boot_wait: 1063fc4124cSDan Handley /* --------------------------------------------- 1073fc4124cSDan Handley * There is no sane reason to come out of this 1083fc4124cSDan Handley * wfi so panic if we do. This cpu will be pow- 1093fc4124cSDan Handley * ered on and reset by the cpu_on pm api 1103fc4124cSDan Handley * --------------------------------------------- 1113fc4124cSDan Handley */ 1123fc4124cSDan Handley dsb sy 1133fc4124cSDan Handley wfi 114*a806dad5SJeenu Viswambharan no_ret plat_panic_handler 115cdf14088SSandrine Bailleux#else 116cdf14088SSandrine Bailleux mov_imm x0, PLAT_ARM_TRUSTED_MAILBOX_BASE 117cdf14088SSandrine Bailleux 118cdf14088SSandrine Bailleux /* Wait until the entrypoint gets populated */ 119cdf14088SSandrine Bailleuxpoll_mailbox: 120cdf14088SSandrine Bailleux ldr x1, [x0] 121cdf14088SSandrine Bailleux cbz x1, 1f 122cdf14088SSandrine Bailleux br x1 123cdf14088SSandrine Bailleux1: 124cdf14088SSandrine Bailleux wfe 125cdf14088SSandrine Bailleux b poll_mailbox 126cdf14088SSandrine Bailleux#endif /* EL3_PAYLOAD_BASE */ 1273fc4124cSDan Handleyendfunc plat_secondary_cold_boot_setup 1283fc4124cSDan Handley 129804040d1SSandrine Bailleux /* --------------------------------------------------------------------- 1304c0d0390SSoby Mathew * uintptr_t plat_get_my_entrypoint (void); 1313fc4124cSDan Handley * 132804040d1SSandrine Bailleux * Main job of this routine is to distinguish between a cold and warm 133804040d1SSandrine Bailleux * boot. On FVP, this information can be queried from the power 134804040d1SSandrine Bailleux * controller. The Power Control SYS Status Register (PSYSR) indicates 135804040d1SSandrine Bailleux * the wake-up reason for the CPU. 1363fc4124cSDan Handley * 137804040d1SSandrine Bailleux * For a cold boot, return 0. 138804040d1SSandrine Bailleux * For a warm boot, read the mailbox and return the address it contains. 139804040d1SSandrine Bailleux * 1403fc4124cSDan Handley * TODO: PSYSR is a common register and should be 1411645d3eeSSandrine Bailleux * accessed using locks. Since it is not possible 1423fc4124cSDan Handley * to use locks immediately after a cold reset 1433fc4124cSDan Handley * we are relying on the fact that after a cold 1443fc4124cSDan Handley * reset all cpus will read the same WK field 145804040d1SSandrine Bailleux * --------------------------------------------------------------------- 1463fc4124cSDan Handley */ 14738dce70fSSoby Mathewfunc plat_get_my_entrypoint 148804040d1SSandrine Bailleux /* --------------------------------------------------------------------- 149804040d1SSandrine Bailleux * When bit PSYSR.WK indicates either "Wake by PPONR" or "Wake by GIC 150804040d1SSandrine Bailleux * WakeRequest signal" then it is a warm boot. 151804040d1SSandrine Bailleux * --------------------------------------------------------------------- 152804040d1SSandrine Bailleux */ 15338dce70fSSoby Mathew mrs x2, mpidr_el1 1543fc4124cSDan Handley ldr x1, =PWRC_BASE 1553fc4124cSDan Handley str w2, [x1, #PSYSR_OFF] 1563fc4124cSDan Handley ldr w2, [x1, #PSYSR_OFF] 157c8f0c3f7SSoby Mathew ubfx w2, w2, #PSYSR_WK_SHIFT, #PSYSR_WK_WIDTH 1583fc4124cSDan Handley cmp w2, #WKUP_PPONR 1593fc4124cSDan Handley beq warm_reset 1603fc4124cSDan Handley cmp w2, #WKUP_GICREQ 1613fc4124cSDan Handley beq warm_reset 162804040d1SSandrine Bailleux 163804040d1SSandrine Bailleux /* Cold reset */ 1643fc4124cSDan Handley mov x0, #0 165804040d1SSandrine Bailleux ret 166804040d1SSandrine Bailleux 1673fc4124cSDan Handleywarm_reset: 168804040d1SSandrine Bailleux /* --------------------------------------------------------------------- 169804040d1SSandrine Bailleux * A mailbox is maintained in the trusted SRAM. It is flushed out of the 170804040d1SSandrine Bailleux * caches after every update using normal memory so it is safe to read 171804040d1SSandrine Bailleux * it here with SO attributes. 172804040d1SSandrine Bailleux * --------------------------------------------------------------------- 1733fc4124cSDan Handley */ 174785fb92bSSoby Mathew mov_imm x0, PLAT_ARM_TRUSTED_MAILBOX_BASE 175804040d1SSandrine Bailleux ldr x0, [x0] 1761c3ea103SAntonio Nino Diaz cbz x0, _panic_handler 177804040d1SSandrine Bailleux ret 178804040d1SSandrine Bailleux 179804040d1SSandrine Bailleux /* --------------------------------------------------------------------- 180804040d1SSandrine Bailleux * The power controller indicates this is a warm reset but the mailbox 181804040d1SSandrine Bailleux * is empty. This should never happen! 182804040d1SSandrine Bailleux * --------------------------------------------------------------------- 183804040d1SSandrine Bailleux */ 1841c3ea103SAntonio Nino Diaz_panic_handler: 185*a806dad5SJeenu Viswambharan no_ret plat_panic_handler 18638dce70fSSoby Mathewendfunc plat_get_my_entrypoint 1873fc4124cSDan Handley 18858523c07SSoby Mathew /* ----------------------------------------------------- 18958523c07SSoby Mathew * unsigned int plat_is_my_cpu_primary (void); 19058523c07SSoby Mathew * 19158523c07SSoby Mathew * Find out whether the current cpu is the primary 19258523c07SSoby Mathew * cpu. 19358523c07SSoby Mathew * ----------------------------------------------------- 19458523c07SSoby Mathew */ 19538dce70fSSoby Mathewfunc plat_is_my_cpu_primary 19638dce70fSSoby Mathew mrs x0, mpidr_el1 1973fc4124cSDan Handley and x0, x0, #(MPIDR_CLUSTER_MASK | MPIDR_CPU_MASK) 1983fc4124cSDan Handley cmp x0, #FVP_PRIMARY_CPU 19958523c07SSoby Mathew cset w0, eq 2003fc4124cSDan Handley ret 20138dce70fSSoby Mathewendfunc plat_is_my_cpu_primary 202