xref: /rk3399_ARM-atf/plat/common/aarch64/platform_mp_stack.S (revision 663db206f85653f05c5f6adb577970cc4669a7ea)
12bf28e62SAndrew Thoelke/*
22bf28e62SAndrew Thoelke * Copyright (c) 2014, ARM Limited and Contributors. All rights reserved.
32bf28e62SAndrew Thoelke *
42bf28e62SAndrew Thoelke * Redistribution and use in source and binary forms, with or without
52bf28e62SAndrew Thoelke * modification, are permitted provided that the following conditions are met:
62bf28e62SAndrew Thoelke *
72bf28e62SAndrew Thoelke * Redistributions of source code must retain the above copyright notice, this
82bf28e62SAndrew Thoelke * list of conditions and the following disclaimer.
92bf28e62SAndrew Thoelke *
102bf28e62SAndrew Thoelke * Redistributions in binary form must reproduce the above copyright notice,
112bf28e62SAndrew Thoelke * this list of conditions and the following disclaimer in the documentation
122bf28e62SAndrew Thoelke * and/or other materials provided with the distribution.
132bf28e62SAndrew Thoelke *
142bf28e62SAndrew Thoelke * Neither the name of ARM nor the names of its contributors may be used
152bf28e62SAndrew Thoelke * to endorse or promote products derived from this software without specific
162bf28e62SAndrew Thoelke * prior written permission.
172bf28e62SAndrew Thoelke *
182bf28e62SAndrew Thoelke * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
192bf28e62SAndrew Thoelke * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
202bf28e62SAndrew Thoelke * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
212bf28e62SAndrew Thoelke * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
222bf28e62SAndrew Thoelke * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
232bf28e62SAndrew Thoelke * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
242bf28e62SAndrew Thoelke * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
252bf28e62SAndrew Thoelke * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
262bf28e62SAndrew Thoelke * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
272bf28e62SAndrew Thoelke * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
282bf28e62SAndrew Thoelke * POSSIBILITY OF SUCH DAMAGE.
292bf28e62SAndrew Thoelke */
302bf28e62SAndrew Thoelke
312bf28e62SAndrew Thoelke#include <arch.h>
322bf28e62SAndrew Thoelke#include <asm_macros.S>
3332bc85f2SSoby Mathew#include <assert_macros.S>
345f0cdb05SDan Handley#include <platform_def.h>
352bf28e62SAndrew Thoelke
362bf28e62SAndrew Thoelke	.local	platform_normal_stacks
3732bc85f2SSoby Mathew#if ENABLE_PLAT_COMPAT
3832bc85f2SSoby Mathew	.globl	plat_get_my_stack
3932bc85f2SSoby Mathew	.globl	plat_set_my_stack
402bf28e62SAndrew Thoelke	.weak	platform_get_stack
4132bc85f2SSoby Mathew	.weak	platform_set_stack
4267487846SSoby Mathew#else
4312d0d00dSSoby Mathew	.weak	plat_get_my_stack
4412d0d00dSSoby Mathew	.weak	plat_set_my_stack
455c8babcdSSoby Mathew	.globl	platform_get_stack
465c8babcdSSoby Mathew	.globl	platform_set_stack
4732bc85f2SSoby Mathew#endif /* __ENABLE_PLAT_COMPAT__ */
482bf28e62SAndrew Thoelke
4932bc85f2SSoby Mathew#if ENABLE_PLAT_COMPAT
5032bc85f2SSoby Mathew	/* ---------------------------------------------------------------------
5132bc85f2SSoby Mathew	 * When the compatility layer is enabled, the new platform APIs
5232bc85f2SSoby Mathew	 * viz plat_get_my_stack() and plat_set_my_stack() need to be
5332bc85f2SSoby Mathew	 * defined using the previous APIs platform_get_stack() and
5432bc85f2SSoby Mathew	 * platform_set_stack(). Also we need to provide weak definitions
5532bc85f2SSoby Mathew	 * of platform_get_stack() and platform_set_stack() for the platforms
5632bc85f2SSoby Mathew	 * to reuse.
5732bc85f2SSoby Mathew	 * --------------------------------------------------------------------
5832bc85f2SSoby Mathew	 */
5932bc85f2SSoby Mathew
6032bc85f2SSoby Mathew	/* -----------------------------------------------------
6132bc85f2SSoby Mathew	 * unsigned long plat_get_my_stack ()
6232bc85f2SSoby Mathew	 *
6332bc85f2SSoby Mathew	 * For the current CPU, this function returns the stack
6432bc85f2SSoby Mathew	 * pointer for a stack allocated in device memory.
6532bc85f2SSoby Mathew	 * -----------------------------------------------------
6632bc85f2SSoby Mathew	 */
6732bc85f2SSoby Mathewfunc plat_get_my_stack
6832bc85f2SSoby Mathew	mrs	x0, mpidr_el1
6932bc85f2SSoby Mathew	b	platform_get_stack
7032bc85f2SSoby Mathewendfunc plat_get_my_stack
7132bc85f2SSoby Mathew
7232bc85f2SSoby Mathew	/* -----------------------------------------------------
7332bc85f2SSoby Mathew	 * void plat_set_my_stack ()
7432bc85f2SSoby Mathew	 *
7532bc85f2SSoby Mathew	 * For the current CPU, this function sets the stack
7632bc85f2SSoby Mathew	 * pointer to a stack allocated in normal memory.
7732bc85f2SSoby Mathew	 * -----------------------------------------------------
7832bc85f2SSoby Mathew	 */
7932bc85f2SSoby Mathewfunc plat_set_my_stack
8032bc85f2SSoby Mathew	mrs	x0, mpidr_el1
8132bc85f2SSoby Mathew	b	platform_set_stack
8232bc85f2SSoby Mathewendfunc plat_set_my_stack
8332bc85f2SSoby Mathew
842bf28e62SAndrew Thoelke	/* -----------------------------------------------------
852bf28e62SAndrew Thoelke	 * unsigned long platform_get_stack (unsigned long mpidr)
862bf28e62SAndrew Thoelke	 *
872bf28e62SAndrew Thoelke	 * For a given CPU, this function returns the stack
882bf28e62SAndrew Thoelke	 * pointer for a stack allocated in device memory.
892bf28e62SAndrew Thoelke	 * -----------------------------------------------------
902bf28e62SAndrew Thoelke	 */
912bf28e62SAndrew Thoelkefunc platform_get_stack
922bf28e62SAndrew Thoelke	mov x10, x30 // lr
932bf28e62SAndrew Thoelke	get_mp_stack platform_normal_stacks, PLATFORM_STACK_SIZE
942bf28e62SAndrew Thoelke	ret x10
958b779620SKévin Petitendfunc platform_get_stack
962bf28e62SAndrew Thoelke
972bf28e62SAndrew Thoelke	/* -----------------------------------------------------
982bf28e62SAndrew Thoelke	 * void platform_set_stack (unsigned long mpidr)
992bf28e62SAndrew Thoelke	 *
1002bf28e62SAndrew Thoelke	 * For a given CPU, this function sets the stack pointer
1012bf28e62SAndrew Thoelke	 * to a stack allocated in normal memory.
1022bf28e62SAndrew Thoelke	 * -----------------------------------------------------
1032bf28e62SAndrew Thoelke	 */
1042bf28e62SAndrew Thoelkefunc platform_set_stack
1052bf28e62SAndrew Thoelke	mov x9, x30 // lr
1062bf28e62SAndrew Thoelke	bl  platform_get_stack
1072bf28e62SAndrew Thoelke	mov sp, x0
1082bf28e62SAndrew Thoelke	ret x9
1098b779620SKévin Petitendfunc platform_set_stack
1102bf28e62SAndrew Thoelke
11167487846SSoby Mathew#else
1125c8babcdSSoby Mathew	/* ---------------------------------------------------------------------
1135c8babcdSSoby Mathew	 * When the compatility layer is disabled, the new platform APIs
1145c8babcdSSoby Mathew	 * viz plat_get_my_stack() and plat_set_my_stack() are
1155c8babcdSSoby Mathew	 * supported by the platform and the previous APIs platform_get_stack()
1165c8babcdSSoby Mathew	 * and platform_set_stack() are defined in terms of new APIs making use
1175c8babcdSSoby Mathew	 * of the fact that they are only ever invoked for the current CPU.
1185c8babcdSSoby Mathew	 * This is to enable components of Trusted Firmware like SPDs using the
1195c8babcdSSoby Mathew	 * old platform APIs to continue to work.
1205c8babcdSSoby Mathew	 * --------------------------------------------------------------------
1215c8babcdSSoby Mathew	 */
1225c8babcdSSoby Mathew
1235c8babcdSSoby Mathew	/* -------------------------------------------------------
1245c8babcdSSoby Mathew	 * unsigned long platform_get_stack (unsigned long mpidr)
1255c8babcdSSoby Mathew	 *
1265c8babcdSSoby Mathew	 * For the current CPU, this function returns the stack
1275c8babcdSSoby Mathew	 * pointer for a stack allocated in device memory. The
1285c8babcdSSoby Mathew	 * 'mpidr' should correspond to that of the current CPU.
1295c8babcdSSoby Mathew	 * This function is deprecated and plat_get_my_stack()
1305c8babcdSSoby Mathew	 * should be used instead.
1315c8babcdSSoby Mathew	 * -------------------------------------------------------
1325c8babcdSSoby Mathew	 */
1335c8babcdSSoby Mathewfunc_deprecated platform_get_stack
1345c8babcdSSoby Mathew#if ASM_ASSERTION
1355c8babcdSSoby Mathew	mrs	x1, mpidr_el1
1365c8babcdSSoby Mathew	cmp	x0, x1
1375c8babcdSSoby Mathew	ASM_ASSERT(eq)
1385c8babcdSSoby Mathew#endif
1395c8babcdSSoby Mathew	b	plat_get_my_stack
1405c8babcdSSoby Mathewendfunc_deprecated platform_get_stack
1415c8babcdSSoby Mathew
1425c8babcdSSoby Mathew	/* -----------------------------------------------------
1435c8babcdSSoby Mathew	 * void platform_set_stack (unsigned long mpidr)
1445c8babcdSSoby Mathew	 *
1455c8babcdSSoby Mathew	 * For the current CPU, this function sets the stack pointer
1465c8babcdSSoby Mathew	 * to a stack allocated in normal memory. The
1475c8babcdSSoby Mathew	 * 'mpidr' should correspond to that of the current CPU.
1485c8babcdSSoby Mathew	 * This function is deprecated and plat_get_my_stack()
1495c8babcdSSoby Mathew	 * should be used instead.
1505c8babcdSSoby Mathew	 * -----------------------------------------------------
1515c8babcdSSoby Mathew	 */
1525c8babcdSSoby Mathewfunc_deprecated platform_set_stack
1535c8babcdSSoby Mathew#if ASM_ASSERTION
1545c8babcdSSoby Mathew	mrs	x1, mpidr_el1
1555c8babcdSSoby Mathew	cmp	x0, x1
1565c8babcdSSoby Mathew	ASM_ASSERT(eq)
1575c8babcdSSoby Mathew#endif
1585c8babcdSSoby Mathew	b	plat_set_my_stack
1595c8babcdSSoby Mathewendfunc_deprecated platform_set_stack
16067487846SSoby Mathew
1612bf28e62SAndrew Thoelke	/* -----------------------------------------------------
16212d0d00dSSoby Mathew	 * unsigned long plat_get_my_stack ()
16312d0d00dSSoby Mathew	 *
16412d0d00dSSoby Mathew	 * For the current CPU, this function returns the stack
16512d0d00dSSoby Mathew	 * pointer for a stack allocated in device memory.
16612d0d00dSSoby Mathew	 * -----------------------------------------------------
16712d0d00dSSoby Mathew	 */
16812d0d00dSSoby Mathewfunc plat_get_my_stack
16912d0d00dSSoby Mathew	mov	x10, x30 // lr
17012d0d00dSSoby Mathew	get_my_mp_stack platform_normal_stacks, PLATFORM_STACK_SIZE
17112d0d00dSSoby Mathew	ret	x10
17212d0d00dSSoby Mathewendfunc plat_get_my_stack
17312d0d00dSSoby Mathew
17412d0d00dSSoby Mathew	/* -----------------------------------------------------
17512d0d00dSSoby Mathew	 * void plat_set_my_stack ()
17612d0d00dSSoby Mathew	 *
17712d0d00dSSoby Mathew	 * For the current CPU, this function sets the stack
17812d0d00dSSoby Mathew	 * pointer to a stack allocated in normal memory.
17912d0d00dSSoby Mathew	 * -----------------------------------------------------
18012d0d00dSSoby Mathew	 */
18112d0d00dSSoby Mathewfunc plat_set_my_stack
18212d0d00dSSoby Mathew	mov	x9, x30 // lr
18312d0d00dSSoby Mathew	bl 	plat_get_my_stack
18412d0d00dSSoby Mathew	mov	sp, x0
18512d0d00dSSoby Mathew	ret	x9
18612d0d00dSSoby Mathewendfunc plat_set_my_stack
18712d0d00dSSoby Mathew
18832bc85f2SSoby Mathew#endif /*__ENABLE_PLAT_COMPAT__*/
18932bc85f2SSoby Mathew
19012d0d00dSSoby Mathew	/* -----------------------------------------------------
191539a7b38SAchin Gupta	 * Per-cpu stacks in normal memory. Each cpu gets a
192539a7b38SAchin Gupta	 * stack of PLATFORM_STACK_SIZE bytes.
1932bf28e62SAndrew Thoelke	 * -----------------------------------------------------
1942bf28e62SAndrew Thoelke	 */
1952bf28e62SAndrew Thoelkedeclare_stack platform_normal_stacks, tzfw_normal_stacks, \
196*663db206SSoby Mathew		PLATFORM_STACK_SIZE, PLATFORM_CORE_COUNT, \
197*663db206SSoby Mathew		CACHE_WRITEBACK_GRANULE
198