xref: /rk3399_ARM-atf/plat/common/aarch64/platform_mp_stack.S (revision 1123a5e2f973dc9f0223467f4782f6b2df542620)
1/*
2 * Copyright (c) 2014-2020, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <arch.h>
8#include <asm_macros.S>
9#include <assert_macros.S>
10#include <platform_def.h>
11
12	.local	platform_normal_stacks
13	.weak	plat_get_my_stack
14	.weak	plat_set_my_stack
15
16	/* ---------------------------------------------------------------------
17	 * When the compatility layer is disabled, the platform APIs
18	 * plat_get_my_stack() and plat_set_my_stack() are supported by the
19	 * platform and the previous APIs platform_get_stack() and
20	 * platform_set_stack() are defined in terms of new APIs making use of
21	 * the fact that they are only ever invoked for the current CPU.  This
22	 * is to enable components of Trusted Firmware like SPDs using the old
23	 * platform APIs to continue to work.
24	 * --------------------------------------------------------------------
25	 */
26
27	/* -----------------------------------------------------
28	 * uintptr_t plat_get_my_stack ()
29	 *
30	 * For the current CPU, this function returns the stack
31	 * pointer for a stack allocated in device memory.
32	 * -----------------------------------------------------
33	 */
34func plat_get_my_stack
35#if (defined(IMAGE_BL31) && RECLAIM_INIT_CODE)
36#if (PLATFORM_CORE_COUNT == 1)
37	/* Single CPU */
38	adrp	x0, __PRIMARY_STACK__
39	add	x0, x0, :lo12:__PRIMARY_STACK__
40	ret
41#else
42	mov	x10, x30
43	bl	plat_my_core_pos
44	cbnz	x0, 2f
45
46	/* Primary CPU */
47	adrp	x0, __PRIMARY_STACK__
48	add	x0, x0, :lo12:__PRIMARY_STACK__
49	ret	x10
50
51	/* Secondary CPU */
522:	sub	x0, x0, #(PLATFORM_CORE_COUNT - 1)
53	adrp	x1, __STACKS_END__
54	adrp	x2, __STACK_SIZE__
55	add	x1, x1, :lo12:__STACKS_END__
56	add	x2, x2, :lo12:__STACK_SIZE__
57
58	madd	x0, x0, x2, x1
59	bic	x0, x0, #(CACHE_WRITEBACK_GRANULE - 1)
60	ret	x10
61#endif
62	/* Prevent linker from removal of stack section */
63	.quad	platform_normal_stacks
64
65#else /* !(IMAGE_BL31 && RECLAIM_INIT_CODE) */
66	mov	x10, x30
67	get_my_mp_stack platform_normal_stacks, PLATFORM_STACK_SIZE
68	ret	x10
69
70#endif /* IMAGE_BL31 && RECLAIM_INIT_CODE */
71endfunc plat_get_my_stack
72
73	/* -----------------------------------------------------
74	 * void plat_set_my_stack ()
75	 *
76	 * For the current CPU, this function sets the stack
77	 * pointer to a stack allocated in normal memory.
78	 * -----------------------------------------------------
79	 */
80func plat_set_my_stack
81	mov	x9, x30
82	bl 	plat_get_my_stack
83	mov	sp, x0
84	ret	x9
85endfunc plat_set_my_stack
86
87	/* -----------------------------------------------------
88	 * Per-CPU stacks in normal memory. Each CPU gets a
89	 * stack of PLATFORM_STACK_SIZE bytes.
90	 * -----------------------------------------------------
91	 */
92declare_stack platform_normal_stacks, tzfw_normal_stacks, \
93		PLATFORM_STACK_SIZE, PLATFORM_CORE_COUNT, \
94		CACHE_WRITEBACK_GRANULE
95