12bf28e62SAndrew Thoelke/* 2044bb2faSAntonio Nino Diaz * Copyright (c) 2014-2017, ARM Limited and Contributors. All rights reserved. 32bf28e62SAndrew Thoelke * 4*82cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause 52bf28e62SAndrew Thoelke */ 62bf28e62SAndrew Thoelke 72bf28e62SAndrew Thoelke#include <arch.h> 82bf28e62SAndrew Thoelke#include <asm_macros.S> 932bc85f2SSoby Mathew#include <assert_macros.S> 105f0cdb05SDan Handley#include <platform_def.h> 112bf28e62SAndrew Thoelke 122bf28e62SAndrew Thoelke .local platform_normal_stacks 1332bc85f2SSoby Mathew#if ENABLE_PLAT_COMPAT 1432bc85f2SSoby Mathew .globl plat_get_my_stack 1532bc85f2SSoby Mathew .globl plat_set_my_stack 162bf28e62SAndrew Thoelke .weak platform_get_stack 1732bc85f2SSoby Mathew .weak platform_set_stack 1867487846SSoby Mathew#else 1912d0d00dSSoby Mathew .weak plat_get_my_stack 2012d0d00dSSoby Mathew .weak plat_set_my_stack 215c8babcdSSoby Mathew .globl platform_get_stack 225c8babcdSSoby Mathew .globl platform_set_stack 2332bc85f2SSoby Mathew#endif /* __ENABLE_PLAT_COMPAT__ */ 242bf28e62SAndrew Thoelke 2532bc85f2SSoby Mathew#if ENABLE_PLAT_COMPAT 2632bc85f2SSoby Mathew /* --------------------------------------------------------------------- 2732bc85f2SSoby Mathew * When the compatility layer is enabled, the new platform APIs 2832bc85f2SSoby Mathew * viz plat_get_my_stack() and plat_set_my_stack() need to be 2932bc85f2SSoby Mathew * defined using the previous APIs platform_get_stack() and 3032bc85f2SSoby Mathew * platform_set_stack(). Also we need to provide weak definitions 3132bc85f2SSoby Mathew * of platform_get_stack() and platform_set_stack() for the platforms 3232bc85f2SSoby Mathew * to reuse. 3332bc85f2SSoby Mathew * -------------------------------------------------------------------- 3432bc85f2SSoby Mathew */ 3532bc85f2SSoby Mathew 3632bc85f2SSoby Mathew /* ----------------------------------------------------- 3732bc85f2SSoby Mathew * unsigned long plat_get_my_stack () 3832bc85f2SSoby Mathew * 3932bc85f2SSoby Mathew * For the current CPU, this function returns the stack 4032bc85f2SSoby Mathew * pointer for a stack allocated in device memory. 4132bc85f2SSoby Mathew * ----------------------------------------------------- 4232bc85f2SSoby Mathew */ 4332bc85f2SSoby Mathewfunc plat_get_my_stack 4432bc85f2SSoby Mathew mrs x0, mpidr_el1 4532bc85f2SSoby Mathew b platform_get_stack 4632bc85f2SSoby Mathewendfunc plat_get_my_stack 4732bc85f2SSoby Mathew 4832bc85f2SSoby Mathew /* ----------------------------------------------------- 4932bc85f2SSoby Mathew * void plat_set_my_stack () 5032bc85f2SSoby Mathew * 5132bc85f2SSoby Mathew * For the current CPU, this function sets the stack 5232bc85f2SSoby Mathew * pointer to a stack allocated in normal memory. 5332bc85f2SSoby Mathew * ----------------------------------------------------- 5432bc85f2SSoby Mathew */ 5532bc85f2SSoby Mathewfunc plat_set_my_stack 5632bc85f2SSoby Mathew mrs x0, mpidr_el1 5732bc85f2SSoby Mathew b platform_set_stack 5832bc85f2SSoby Mathewendfunc plat_set_my_stack 5932bc85f2SSoby Mathew 602bf28e62SAndrew Thoelke /* ----------------------------------------------------- 612bf28e62SAndrew Thoelke * unsigned long platform_get_stack (unsigned long mpidr) 622bf28e62SAndrew Thoelke * 632bf28e62SAndrew Thoelke * For a given CPU, this function returns the stack 642bf28e62SAndrew Thoelke * pointer for a stack allocated in device memory. 652bf28e62SAndrew Thoelke * ----------------------------------------------------- 662bf28e62SAndrew Thoelke */ 672bf28e62SAndrew Thoelkefunc platform_get_stack 682bf28e62SAndrew Thoelke mov x10, x30 // lr 692bf28e62SAndrew Thoelke get_mp_stack platform_normal_stacks, PLATFORM_STACK_SIZE 702bf28e62SAndrew Thoelke ret x10 718b779620SKévin Petitendfunc platform_get_stack 722bf28e62SAndrew Thoelke 732bf28e62SAndrew Thoelke /* ----------------------------------------------------- 742bf28e62SAndrew Thoelke * void platform_set_stack (unsigned long mpidr) 752bf28e62SAndrew Thoelke * 762bf28e62SAndrew Thoelke * For a given CPU, this function sets the stack pointer 772bf28e62SAndrew Thoelke * to a stack allocated in normal memory. 782bf28e62SAndrew Thoelke * ----------------------------------------------------- 792bf28e62SAndrew Thoelke */ 802bf28e62SAndrew Thoelkefunc platform_set_stack 812bf28e62SAndrew Thoelke mov x9, x30 // lr 822bf28e62SAndrew Thoelke bl platform_get_stack 832bf28e62SAndrew Thoelke mov sp, x0 842bf28e62SAndrew Thoelke ret x9 858b779620SKévin Petitendfunc platform_set_stack 862bf28e62SAndrew Thoelke 8767487846SSoby Mathew#else 885c8babcdSSoby Mathew /* --------------------------------------------------------------------- 895c8babcdSSoby Mathew * When the compatility layer is disabled, the new platform APIs 905c8babcdSSoby Mathew * viz plat_get_my_stack() and plat_set_my_stack() are 915c8babcdSSoby Mathew * supported by the platform and the previous APIs platform_get_stack() 925c8babcdSSoby Mathew * and platform_set_stack() are defined in terms of new APIs making use 935c8babcdSSoby Mathew * of the fact that they are only ever invoked for the current CPU. 945c8babcdSSoby Mathew * This is to enable components of Trusted Firmware like SPDs using the 955c8babcdSSoby Mathew * old platform APIs to continue to work. 965c8babcdSSoby Mathew * -------------------------------------------------------------------- 975c8babcdSSoby Mathew */ 985c8babcdSSoby Mathew 995c8babcdSSoby Mathew /* ------------------------------------------------------- 1005c8babcdSSoby Mathew * unsigned long platform_get_stack (unsigned long mpidr) 1015c8babcdSSoby Mathew * 1025c8babcdSSoby Mathew * For the current CPU, this function returns the stack 1035c8babcdSSoby Mathew * pointer for a stack allocated in device memory. The 1045c8babcdSSoby Mathew * 'mpidr' should correspond to that of the current CPU. 1055c8babcdSSoby Mathew * This function is deprecated and plat_get_my_stack() 1065c8babcdSSoby Mathew * should be used instead. 1075c8babcdSSoby Mathew * ------------------------------------------------------- 1085c8babcdSSoby Mathew */ 1095c8babcdSSoby Mathewfunc_deprecated platform_get_stack 110044bb2faSAntonio Nino Diaz#if ENABLE_ASSERTIONS 1115c8babcdSSoby Mathew mrs x1, mpidr_el1 1125c8babcdSSoby Mathew cmp x0, x1 1135c8babcdSSoby Mathew ASM_ASSERT(eq) 1145c8babcdSSoby Mathew#endif 1155c8babcdSSoby Mathew b plat_get_my_stack 1165c8babcdSSoby Mathewendfunc_deprecated platform_get_stack 1175c8babcdSSoby Mathew 1185c8babcdSSoby Mathew /* ----------------------------------------------------- 1195c8babcdSSoby Mathew * void platform_set_stack (unsigned long mpidr) 1205c8babcdSSoby Mathew * 1215c8babcdSSoby Mathew * For the current CPU, this function sets the stack pointer 1225c8babcdSSoby Mathew * to a stack allocated in normal memory. The 1235c8babcdSSoby Mathew * 'mpidr' should correspond to that of the current CPU. 1245c8babcdSSoby Mathew * This function is deprecated and plat_get_my_stack() 1255c8babcdSSoby Mathew * should be used instead. 1265c8babcdSSoby Mathew * ----------------------------------------------------- 1275c8babcdSSoby Mathew */ 1285c8babcdSSoby Mathewfunc_deprecated platform_set_stack 129044bb2faSAntonio Nino Diaz#if ENABLE_ASSERTIONS 1305c8babcdSSoby Mathew mrs x1, mpidr_el1 1315c8babcdSSoby Mathew cmp x0, x1 1325c8babcdSSoby Mathew ASM_ASSERT(eq) 1335c8babcdSSoby Mathew#endif 1345c8babcdSSoby Mathew b plat_set_my_stack 1355c8babcdSSoby Mathewendfunc_deprecated platform_set_stack 13667487846SSoby Mathew 1372bf28e62SAndrew Thoelke /* ----------------------------------------------------- 1384c0d0390SSoby Mathew * uintptr_t plat_get_my_stack () 13912d0d00dSSoby Mathew * 14012d0d00dSSoby Mathew * For the current CPU, this function returns the stack 14112d0d00dSSoby Mathew * pointer for a stack allocated in device memory. 14212d0d00dSSoby Mathew * ----------------------------------------------------- 14312d0d00dSSoby Mathew */ 14412d0d00dSSoby Mathewfunc plat_get_my_stack 14512d0d00dSSoby Mathew mov x10, x30 // lr 14612d0d00dSSoby Mathew get_my_mp_stack platform_normal_stacks, PLATFORM_STACK_SIZE 14712d0d00dSSoby Mathew ret x10 14812d0d00dSSoby Mathewendfunc plat_get_my_stack 14912d0d00dSSoby Mathew 15012d0d00dSSoby Mathew /* ----------------------------------------------------- 15112d0d00dSSoby Mathew * void plat_set_my_stack () 15212d0d00dSSoby Mathew * 15312d0d00dSSoby Mathew * For the current CPU, this function sets the stack 15412d0d00dSSoby Mathew * pointer to a stack allocated in normal memory. 15512d0d00dSSoby Mathew * ----------------------------------------------------- 15612d0d00dSSoby Mathew */ 15712d0d00dSSoby Mathewfunc plat_set_my_stack 15812d0d00dSSoby Mathew mov x9, x30 // lr 15912d0d00dSSoby Mathew bl plat_get_my_stack 16012d0d00dSSoby Mathew mov sp, x0 16112d0d00dSSoby Mathew ret x9 16212d0d00dSSoby Mathewendfunc plat_set_my_stack 16312d0d00dSSoby Mathew 16432bc85f2SSoby Mathew#endif /*__ENABLE_PLAT_COMPAT__*/ 16532bc85f2SSoby Mathew 16612d0d00dSSoby Mathew /* ----------------------------------------------------- 167539a7b38SAchin Gupta * Per-cpu stacks in normal memory. Each cpu gets a 168539a7b38SAchin Gupta * stack of PLATFORM_STACK_SIZE bytes. 1692bf28e62SAndrew Thoelke * ----------------------------------------------------- 1702bf28e62SAndrew Thoelke */ 1712bf28e62SAndrew Thoelkedeclare_stack platform_normal_stacks, tzfw_normal_stacks, \ 172663db206SSoby Mathew PLATFORM_STACK_SIZE, PLATFORM_CORE_COUNT, \ 173663db206SSoby Mathew CACHE_WRITEBACK_GRANULE 174