1b4315306SDan Handley/* 2b4315306SDan Handley * Copyright (c) 2013-2015, ARM Limited and Contributors. All rights reserved. 3b4315306SDan Handley * 4b4315306SDan Handley * Redistribution and use in source and binary forms, with or without 5b4315306SDan Handley * modification, are permitted provided that the following conditions are met: 6b4315306SDan Handley * 7b4315306SDan Handley * Redistributions of source code must retain the above copyright notice, this 8b4315306SDan Handley * list of conditions and the following disclaimer. 9b4315306SDan Handley * 10b4315306SDan Handley * Redistributions in binary form must reproduce the above copyright notice, 11b4315306SDan Handley * this list of conditions and the following disclaimer in the documentation 12b4315306SDan Handley * and/or other materials provided with the distribution. 13b4315306SDan Handley * 14b4315306SDan Handley * Neither the name of ARM nor the names of its contributors may be used 15b4315306SDan Handley * to endorse or promote products derived from this software without specific 16b4315306SDan Handley * prior written permission. 17b4315306SDan Handley * 18b4315306SDan Handley * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19b4315306SDan Handley * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20b4315306SDan Handley * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21b4315306SDan Handley * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22b4315306SDan Handley * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23b4315306SDan Handley * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24b4315306SDan Handley * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25b4315306SDan Handley * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26b4315306SDan Handley * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27b4315306SDan Handley * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28b4315306SDan Handley * POSSIBILITY OF SUCH DAMAGE. 29b4315306SDan Handley */ 30b4315306SDan Handley#include <arch.h> 31b4315306SDan Handley#include <asm_macros.S> 32b4315306SDan Handley#include <cpu_macros.S> 33b4315306SDan Handley#include <css_def.h> 34b4315306SDan Handley 35b4315306SDan Handley .weak plat_secondary_cold_boot_setup 3638dce70fSSoby Mathew .weak plat_get_my_entrypoint 37371d4399SDavid Wang .globl css_calc_core_pos_swap_cluster 3838dce70fSSoby Mathew .weak plat_is_my_cpu_primary 39b4315306SDan Handley 40*2bc42067SSandrine Bailleux /* --------------------------------------------------------------------- 41b4315306SDan Handley * void plat_secondary_cold_boot_setup(void); 42b4315306SDan Handley * 43*2bc42067SSandrine Bailleux * In the normal boot flow, cold-booting secondary CPUs is not yet 44*2bc42067SSandrine Bailleux * implemented and they panic. 45*2bc42067SSandrine Bailleux * 46*2bc42067SSandrine Bailleux * When booting an EL3 payload, secondary CPUs are placed in a holding 47*2bc42067SSandrine Bailleux * pen, waiting for their mailbox to be populated. Note that all CPUs 48*2bc42067SSandrine Bailleux * share the same mailbox ; therefore, populating it will release all 49*2bc42067SSandrine Bailleux * CPUs from their holding pen. If finer-grained control is needed then 50*2bc42067SSandrine Bailleux * this should be handled in the code that secondary CPUs jump to. 51*2bc42067SSandrine Bailleux * --------------------------------------------------------------------- 52b4315306SDan Handley */ 53b4315306SDan Handleyfunc plat_secondary_cold_boot_setup 54*2bc42067SSandrine Bailleux#ifndef EL3_PAYLOAD_BASE 55*2bc42067SSandrine Bailleux /* TODO: Implement secondary CPU cold boot setup on CSS platforms */ 56b4315306SDan Handleycb_panic: 57b4315306SDan Handley b cb_panic 58*2bc42067SSandrine Bailleux#else 59*2bc42067SSandrine Bailleux mov_imm x0, PLAT_ARM_TRUSTED_MAILBOX_BASE 60*2bc42067SSandrine Bailleux 61*2bc42067SSandrine Bailleux /* Wait until the mailbox gets populated */ 62*2bc42067SSandrine Bailleuxpoll_mailbox: 63*2bc42067SSandrine Bailleux ldr x1, [x0] 64*2bc42067SSandrine Bailleux cbz x1, 1f 65*2bc42067SSandrine Bailleux br x1 66*2bc42067SSandrine Bailleux1: 67*2bc42067SSandrine Bailleux wfe 68*2bc42067SSandrine Bailleux b poll_mailbox 69*2bc42067SSandrine Bailleux#endif /* EL3_PAYLOAD_BASE */ 70b4315306SDan Handleyendfunc plat_secondary_cold_boot_setup 71b4315306SDan Handley 72804040d1SSandrine Bailleux /* --------------------------------------------------------------------- 7338dce70fSSoby Mathew * unsigned long plat_get_my_entrypoint (void); 74b4315306SDan Handley * 75804040d1SSandrine Bailleux * Main job of this routine is to distinguish between a cold and a warm 76804040d1SSandrine Bailleux * boot. On CSS platforms, this distinction is based on the contents of 77804040d1SSandrine Bailleux * the Trusted Mailbox. It is initialised to zero by the SCP before the 78804040d1SSandrine Bailleux * AP cores are released from reset. Therefore, a zero mailbox means 79804040d1SSandrine Bailleux * it's a cold reset. 80b4315306SDan Handley * 81804040d1SSandrine Bailleux * This functions returns the contents of the mailbox, i.e.: 82804040d1SSandrine Bailleux * - 0 for a cold boot; 83804040d1SSandrine Bailleux * - the warm boot entrypoint for a warm boot. 84804040d1SSandrine Bailleux * --------------------------------------------------------------------- 85b4315306SDan Handley */ 8638dce70fSSoby Mathewfunc plat_get_my_entrypoint 87785fb92bSSoby Mathew mov_imm x0, PLAT_ARM_TRUSTED_MAILBOX_BASE 88804040d1SSandrine Bailleux ldr x0, [x0] 89804040d1SSandrine Bailleux ret 9038dce70fSSoby Mathewendfunc plat_get_my_entrypoint 91b4315306SDan Handley 9238dce70fSSoby Mathew /* ----------------------------------------------------------- 93371d4399SDavid Wang * unsigned int css_calc_core_pos_swap_cluster(uint64_t mpidr) 94371d4399SDavid Wang * Utility function to calculate the core position by 9538dce70fSSoby Mathew * swapping the cluster order. This is necessary in order to 9638dce70fSSoby Mathew * match the format of the boot information passed by the SCP 9758523c07SSoby Mathew * and read in plat_is_my_cpu_primary below. 9838dce70fSSoby Mathew * ----------------------------------------------------------- 99b4315306SDan Handley */ 100371d4399SDavid Wangfunc css_calc_core_pos_swap_cluster 101b4315306SDan Handley and x1, x0, #MPIDR_CPU_MASK 102b4315306SDan Handley and x0, x0, #MPIDR_CLUSTER_MASK 103b4315306SDan Handley eor x0, x0, #(1 << MPIDR_AFFINITY_BITS) // swap cluster order 104b4315306SDan Handley add x0, x1, x0, LSR #6 105b4315306SDan Handley ret 106371d4399SDavid Wangendfunc css_calc_core_pos_swap_cluster 107b4315306SDan Handley 108b4315306SDan Handley /* ----------------------------------------------------- 10938dce70fSSoby Mathew * unsigned int plat_is_my_cpu_primary (void); 110b4315306SDan Handley * 11138dce70fSSoby Mathew * Find out whether the current cpu is the primary 112b4315306SDan Handley * cpu (applicable ony after a cold boot) 113b4315306SDan Handley * ----------------------------------------------------- 114b4315306SDan Handley */ 11538dce70fSSoby Mathewfunc plat_is_my_cpu_primary 116b4315306SDan Handley mov x9, x30 11738dce70fSSoby Mathew bl plat_my_core_pos 118b4315306SDan Handley ldr x1, =SCP_BOOT_CFG_ADDR 119b4315306SDan Handley ldr x1, [x1] 12019af6fceSSoby Mathew ubfx x1, x1, #PRIMARY_CPU_SHIFT, #PRIMARY_CPU_BIT_WIDTH 121b4315306SDan Handley cmp x0, x1 12258523c07SSoby Mathew cset w0, eq 123b4315306SDan Handley ret x9 12438dce70fSSoby Mathewendfunc plat_is_my_cpu_primary 125