12bf28e62SAndrew Thoelke/* 2*34dd1e96SAlexei Fedorov * Copyright (c) 2014-2020, ARM Limited and Contributors. All rights reserved. 32bf28e62SAndrew Thoelke * 482cb2c1aSdp-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 1312d0d00dSSoby Mathew .weak plat_get_my_stack 1412d0d00dSSoby Mathew .weak plat_set_my_stack 152bf28e62SAndrew Thoelke 165c8babcdSSoby Mathew /* --------------------------------------------------------------------- 1773308618SAntonio Nino Diaz * When the compatility layer is disabled, the platform APIs 1873308618SAntonio Nino Diaz * plat_get_my_stack() and plat_set_my_stack() are supported by the 1973308618SAntonio Nino Diaz * platform and the previous APIs platform_get_stack() and 2073308618SAntonio Nino Diaz * platform_set_stack() are defined in terms of new APIs making use of 2173308618SAntonio Nino Diaz * the fact that they are only ever invoked for the current CPU. This 2273308618SAntonio Nino Diaz * is to enable components of Trusted Firmware like SPDs using the old 2373308618SAntonio Nino Diaz * platform APIs to continue to work. 245c8babcdSSoby Mathew * -------------------------------------------------------------------- 255c8babcdSSoby Mathew */ 265c8babcdSSoby Mathew 272bf28e62SAndrew Thoelke /* ----------------------------------------------------- 284c0d0390SSoby Mathew * uintptr_t plat_get_my_stack () 2912d0d00dSSoby Mathew * 3012d0d00dSSoby Mathew * For the current CPU, this function returns the stack 3112d0d00dSSoby Mathew * pointer for a stack allocated in device memory. 3212d0d00dSSoby Mathew * ----------------------------------------------------- 3312d0d00dSSoby Mathew */ 3412d0d00dSSoby Mathewfunc plat_get_my_stack 35*34dd1e96SAlexei Fedorov#if (defined(IMAGE_BL31) && RECLAIM_INIT_CODE) 36*34dd1e96SAlexei Fedorov#if (PLATFORM_CORE_COUNT == 1) 37*34dd1e96SAlexei Fedorov /* Single CPU */ 38*34dd1e96SAlexei Fedorov adrp x0, __PRIMARY_STACK__ 39*34dd1e96SAlexei Fedorov add x0, x0, :lo12:__PRIMARY_STACK__ 40*34dd1e96SAlexei Fedorov ret 41*34dd1e96SAlexei Fedorov#else 42*34dd1e96SAlexei Fedorov mov x10, x30 43*34dd1e96SAlexei Fedorov bl plat_my_core_pos 44*34dd1e96SAlexei Fedorov cbnz x0, 2f 45*34dd1e96SAlexei Fedorov 46*34dd1e96SAlexei Fedorov /* Primary CPU */ 47*34dd1e96SAlexei Fedorov adrp x0, __PRIMARY_STACK__ 48*34dd1e96SAlexei Fedorov add x0, x0, :lo12:__PRIMARY_STACK__ 49*34dd1e96SAlexei Fedorov ret x10 50*34dd1e96SAlexei Fedorov 51*34dd1e96SAlexei Fedorov /* Secondary CPU */ 52*34dd1e96SAlexei Fedorov2: sub x0, x0, #(PLATFORM_CORE_COUNT - 1) 53*34dd1e96SAlexei Fedorov adrp x1, __STACKS_END__ 54*34dd1e96SAlexei Fedorov adrp x2, __STACK_SIZE__ 55*34dd1e96SAlexei Fedorov add x1, x1, :lo12:__STACKS_END__ 56*34dd1e96SAlexei Fedorov add x2, x2, :lo12:__STACK_SIZE__ 57*34dd1e96SAlexei Fedorov 58*34dd1e96SAlexei Fedorov madd x0, x0, x2, x1 59*34dd1e96SAlexei Fedorov bic x0, x0, #(CACHE_WRITEBACK_GRANULE - 1) 60*34dd1e96SAlexei Fedorov ret x10 61*34dd1e96SAlexei Fedorov#endif 62*34dd1e96SAlexei Fedorov .word platform_normal_stacks 63*34dd1e96SAlexei Fedorov 64*34dd1e96SAlexei Fedorov#else /* !(IMAGE_BL31 && RECLAIM_INIT_CODE) */ 65*34dd1e96SAlexei Fedorov mov x10, x30 6612d0d00dSSoby Mathew get_my_mp_stack platform_normal_stacks, PLATFORM_STACK_SIZE 6712d0d00dSSoby Mathew ret x10 68*34dd1e96SAlexei Fedorov 69*34dd1e96SAlexei Fedorov#endif /* IMAGE_BL31 && RECLAIM_INIT_CODE */ 7012d0d00dSSoby Mathewendfunc plat_get_my_stack 7112d0d00dSSoby Mathew 7212d0d00dSSoby Mathew /* ----------------------------------------------------- 7312d0d00dSSoby Mathew * void plat_set_my_stack () 7412d0d00dSSoby Mathew * 7512d0d00dSSoby Mathew * For the current CPU, this function sets the stack 7612d0d00dSSoby Mathew * pointer to a stack allocated in normal memory. 7712d0d00dSSoby Mathew * ----------------------------------------------------- 7812d0d00dSSoby Mathew */ 7912d0d00dSSoby Mathewfunc plat_set_my_stack 80*34dd1e96SAlexei Fedorov mov x9, x30 8112d0d00dSSoby Mathew bl plat_get_my_stack 8212d0d00dSSoby Mathew mov sp, x0 8312d0d00dSSoby Mathew ret x9 8412d0d00dSSoby Mathewendfunc plat_set_my_stack 8512d0d00dSSoby Mathew 8612d0d00dSSoby Mathew /* ----------------------------------------------------- 87*34dd1e96SAlexei Fedorov * Per-CPU stacks in normal memory. Each CPU gets a 88539a7b38SAchin Gupta * stack of PLATFORM_STACK_SIZE bytes. 892bf28e62SAndrew Thoelke * ----------------------------------------------------- 902bf28e62SAndrew Thoelke */ 912bf28e62SAndrew Thoelkedeclare_stack platform_normal_stacks, tzfw_normal_stacks, \ 92663db206SSoby Mathew PLATFORM_STACK_SIZE, PLATFORM_CORE_COUNT, \ 93663db206SSoby Mathew CACHE_WRITEBACK_GRANULE 94