xref: /rk3399_ARM-atf/plat/common/aarch64/platform_mp_stack.S (revision 674878464a93bb6d6bf6cb746fc4b9dba6e101ac)
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
42*67487846SSoby Mathew#else
4312d0d00dSSoby Mathew	.weak	plat_get_my_stack
4412d0d00dSSoby Mathew	.weak	plat_set_my_stack
4532bc85f2SSoby Mathew#endif /*__ENABLE_PLAT_COMPAT__*/
462bf28e62SAndrew Thoelke
4732bc85f2SSoby Mathew
4832bc85f2SSoby Mathew#if ENABLE_PLAT_COMPAT
4932bc85f2SSoby Mathew	/* ---------------------------------------------------------------------
5032bc85f2SSoby Mathew	 * When the compatility layer is enabled, the new platform APIs
5132bc85f2SSoby Mathew	 * viz plat_get_my_stack() and plat_set_my_stack() need to be
5232bc85f2SSoby Mathew	 * defined using the previous APIs platform_get_stack() and
5332bc85f2SSoby Mathew	 * platform_set_stack(). Also we need to provide weak definitions
5432bc85f2SSoby Mathew	 * of platform_get_stack() and platform_set_stack() for the platforms
5532bc85f2SSoby Mathew	 * to reuse.
5632bc85f2SSoby Mathew	 * --------------------------------------------------------------------
5732bc85f2SSoby Mathew	 */
5832bc85f2SSoby Mathew
5932bc85f2SSoby Mathew	/* -----------------------------------------------------
6032bc85f2SSoby Mathew	 * unsigned long plat_get_my_stack ()
6132bc85f2SSoby Mathew	 *
6232bc85f2SSoby Mathew	 * For the current CPU, this function returns the stack
6332bc85f2SSoby Mathew	 * pointer for a stack allocated in device memory.
6432bc85f2SSoby Mathew	 * -----------------------------------------------------
6532bc85f2SSoby Mathew	 */
6632bc85f2SSoby Mathewfunc plat_get_my_stack
6732bc85f2SSoby Mathew	mrs	x0, mpidr_el1
6832bc85f2SSoby Mathew	b	platform_get_stack
6932bc85f2SSoby Mathewendfunc plat_get_my_stack
7032bc85f2SSoby Mathew
7132bc85f2SSoby Mathew	/* -----------------------------------------------------
7232bc85f2SSoby Mathew	 * void plat_set_my_stack ()
7332bc85f2SSoby Mathew	 *
7432bc85f2SSoby Mathew	 * For the current CPU, this function sets the stack
7532bc85f2SSoby Mathew	 * pointer to a stack allocated in normal memory.
7632bc85f2SSoby Mathew	 * -----------------------------------------------------
7732bc85f2SSoby Mathew	 */
7832bc85f2SSoby Mathewfunc plat_set_my_stack
7932bc85f2SSoby Mathew	mrs	x0, mpidr_el1
8032bc85f2SSoby Mathew	b	platform_set_stack
8132bc85f2SSoby Mathewendfunc plat_set_my_stack
8232bc85f2SSoby Mathew
832bf28e62SAndrew Thoelke	/* -----------------------------------------------------
842bf28e62SAndrew Thoelke	 * unsigned long platform_get_stack (unsigned long mpidr)
852bf28e62SAndrew Thoelke	 *
862bf28e62SAndrew Thoelke	 * For a given CPU, this function returns the stack
872bf28e62SAndrew Thoelke	 * pointer for a stack allocated in device memory.
882bf28e62SAndrew Thoelke	 * -----------------------------------------------------
892bf28e62SAndrew Thoelke	 */
902bf28e62SAndrew Thoelkefunc platform_get_stack
912bf28e62SAndrew Thoelke	mov x10, x30 // lr
922bf28e62SAndrew Thoelke	get_mp_stack platform_normal_stacks, PLATFORM_STACK_SIZE
932bf28e62SAndrew Thoelke	ret x10
948b779620SKévin Petitendfunc platform_get_stack
952bf28e62SAndrew Thoelke
962bf28e62SAndrew Thoelke	/* -----------------------------------------------------
972bf28e62SAndrew Thoelke	 * void platform_set_stack (unsigned long mpidr)
982bf28e62SAndrew Thoelke	 *
992bf28e62SAndrew Thoelke	 * For a given CPU, this function sets the stack pointer
1002bf28e62SAndrew Thoelke	 * to a stack allocated in normal memory.
1012bf28e62SAndrew Thoelke	 * -----------------------------------------------------
1022bf28e62SAndrew Thoelke	 */
1032bf28e62SAndrew Thoelkefunc platform_set_stack
1042bf28e62SAndrew Thoelke	mov x9, x30 // lr
1052bf28e62SAndrew Thoelke	bl  platform_get_stack
1062bf28e62SAndrew Thoelke	mov sp, x0
1072bf28e62SAndrew Thoelke	ret x9
1088b779620SKévin Petitendfunc platform_set_stack
1092bf28e62SAndrew Thoelke
110*67487846SSoby Mathew#else
111*67487846SSoby Mathew
1122bf28e62SAndrew Thoelke	/* -----------------------------------------------------
11312d0d00dSSoby Mathew	 * unsigned long plat_get_my_stack ()
11412d0d00dSSoby Mathew	 *
11512d0d00dSSoby Mathew	 * For the current CPU, this function returns the stack
11612d0d00dSSoby Mathew	 * pointer for a stack allocated in device memory.
11712d0d00dSSoby Mathew	 * -----------------------------------------------------
11812d0d00dSSoby Mathew	 */
11912d0d00dSSoby Mathewfunc plat_get_my_stack
12012d0d00dSSoby Mathew	mov	x10, x30 // lr
12112d0d00dSSoby Mathew	get_my_mp_stack platform_normal_stacks, PLATFORM_STACK_SIZE
12212d0d00dSSoby Mathew	ret	x10
12312d0d00dSSoby Mathewendfunc plat_get_my_stack
12412d0d00dSSoby Mathew
12512d0d00dSSoby Mathew	/* -----------------------------------------------------
12612d0d00dSSoby Mathew	 * void plat_set_my_stack ()
12712d0d00dSSoby Mathew	 *
12812d0d00dSSoby Mathew	 * For the current CPU, this function sets the stack
12912d0d00dSSoby Mathew	 * pointer to a stack allocated in normal memory.
13012d0d00dSSoby Mathew	 * -----------------------------------------------------
13112d0d00dSSoby Mathew	 */
13212d0d00dSSoby Mathewfunc plat_set_my_stack
13312d0d00dSSoby Mathew	mov	x9, x30 // lr
13412d0d00dSSoby Mathew	bl 	plat_get_my_stack
13512d0d00dSSoby Mathew	mov	sp, x0
13612d0d00dSSoby Mathew	ret	x9
13712d0d00dSSoby Mathewendfunc plat_set_my_stack
13812d0d00dSSoby Mathew
13932bc85f2SSoby Mathew#endif /*__ENABLE_PLAT_COMPAT__*/
14032bc85f2SSoby Mathew
14112d0d00dSSoby Mathew	/* -----------------------------------------------------
142539a7b38SAchin Gupta	 * Per-cpu stacks in normal memory. Each cpu gets a
143539a7b38SAchin Gupta	 * stack of PLATFORM_STACK_SIZE bytes.
1442bf28e62SAndrew Thoelke	 * -----------------------------------------------------
1452bf28e62SAndrew Thoelke	 */
1462bf28e62SAndrew Thoelkedeclare_stack platform_normal_stacks, tzfw_normal_stacks, \
1472bf28e62SAndrew Thoelke		PLATFORM_STACK_SIZE, PLATFORM_CORE_COUNT
148