blob: 10323bf6490ff66138af844d43744b1b4be29ef8 [file] [log] [blame]
Andrew Thoelke65668f92014-03-20 10:48:23 +00001/*
Antonio Nino Diaz7c65c1e2017-04-20 09:58:28 +01002 * Copyright (c) 2014-2017, ARM Limited and Contributors. All rights reserved.
Andrew Thoelke65668f92014-03-20 10:48:23 +00003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Andrew Thoelke65668f92014-03-20 10:48:23 +00005 */
6
7#include <arch.h>
Andrew Thoelke65668f92014-03-20 10:48:23 +00008#include <asm_macros.S>
Soby Mathew49473e42015-06-10 13:49:59 +01009#include <assert_macros.S>
Dan Handleyed6ff952014-05-14 17:44:19 +010010#include <platform_def.h>
Andrew Thoelke65668f92014-03-20 10:48:23 +000011
Andrew Thoelke65668f92014-03-20 10:48:23 +000012 .local platform_normal_stacks
Soby Mathew49473e42015-06-10 13:49:59 +010013#if ENABLE_PLAT_COMPAT
14 .globl plat_get_my_stack
15 .globl plat_set_my_stack
Andrew Thoelke65668f92014-03-20 10:48:23 +000016 .weak platform_get_stack
Soby Mathew49473e42015-06-10 13:49:59 +010017 .weak platform_set_stack
Soby Mathew981487a2015-07-13 14:10:57 +010018#else
Soby Mathewb0082d22015-04-09 13:40:55 +010019 .weak plat_get_my_stack
20 .weak plat_set_my_stack
Soby Mathew70716d62015-07-13 16:26:11 +010021 .globl platform_get_stack
22 .globl platform_set_stack
23#endif /* __ENABLE_PLAT_COMPAT__ */
Soby Mathew49473e42015-06-10 13:49:59 +010024
25#if ENABLE_PLAT_COMPAT
26 /* ---------------------------------------------------------------------
27 * When the compatility layer is enabled, the new platform APIs
28 * viz plat_get_my_stack() and plat_set_my_stack() need to be
29 * defined using the previous APIs platform_get_stack() and
30 * platform_set_stack(). Also we need to provide weak definitions
31 * of platform_get_stack() and platform_set_stack() for the platforms
32 * to reuse.
33 * --------------------------------------------------------------------
34 */
Andrew Thoelke65668f92014-03-20 10:48:23 +000035
36 /* -----------------------------------------------------
Soby Mathew49473e42015-06-10 13:49:59 +010037 * unsigned long plat_get_my_stack ()
38 *
39 * For the current CPU, this function returns the stack
40 * pointer for a stack allocated in device memory.
41 * -----------------------------------------------------
42 */
43func plat_get_my_stack
44 mrs x0, mpidr_el1
45 b platform_get_stack
46endfunc plat_get_my_stack
47
48 /* -----------------------------------------------------
49 * void plat_set_my_stack ()
50 *
51 * For the current CPU, this function sets the stack
52 * pointer to a stack allocated in normal memory.
53 * -----------------------------------------------------
54 */
55func plat_set_my_stack
56 mrs x0, mpidr_el1
57 b platform_set_stack
58endfunc plat_set_my_stack
59
Soby Mathew49473e42015-06-10 13:49:59 +010060 /* -----------------------------------------------------
Andrew Thoelke65668f92014-03-20 10:48:23 +000061 * unsigned long platform_get_stack (unsigned long mpidr)
62 *
63 * For a given CPU, this function returns the stack
64 * pointer for a stack allocated in device memory.
65 * -----------------------------------------------------
66 */
67func platform_get_stack
68 mov x10, x30 // lr
69 get_mp_stack platform_normal_stacks, PLATFORM_STACK_SIZE
70 ret x10
Kévin Petita877c252015-03-24 14:03:57 +000071endfunc platform_get_stack
Andrew Thoelke65668f92014-03-20 10:48:23 +000072
73 /* -----------------------------------------------------
74 * void platform_set_stack (unsigned long mpidr)
75 *
76 * For a given CPU, this function sets the stack pointer
77 * to a stack allocated in normal memory.
78 * -----------------------------------------------------
79 */
80func platform_set_stack
81 mov x9, x30 // lr
82 bl platform_get_stack
83 mov sp, x0
84 ret x9
Kévin Petita877c252015-03-24 14:03:57 +000085endfunc platform_set_stack
Andrew Thoelke65668f92014-03-20 10:48:23 +000086
Soby Mathew981487a2015-07-13 14:10:57 +010087#else
Soby Mathew70716d62015-07-13 16:26:11 +010088 /* ---------------------------------------------------------------------
89 * When the compatility layer is disabled, the new platform APIs
90 * viz plat_get_my_stack() and plat_set_my_stack() are
91 * supported by the platform and the previous APIs platform_get_stack()
92 * and platform_set_stack() are defined in terms of new APIs making use
93 * of the fact that they are only ever invoked for the current CPU.
94 * This is to enable components of Trusted Firmware like SPDs using the
95 * old platform APIs to continue to work.
96 * --------------------------------------------------------------------
97 */
98
99 /* -------------------------------------------------------
100 * unsigned long platform_get_stack (unsigned long mpidr)
101 *
102 * For the current CPU, this function returns the stack
103 * pointer for a stack allocated in device memory. The
104 * 'mpidr' should correspond to that of the current CPU.
105 * This function is deprecated and plat_get_my_stack()
106 * should be used instead.
107 * -------------------------------------------------------
108 */
109func_deprecated platform_get_stack
Antonio Nino Diaz7c65c1e2017-04-20 09:58:28 +0100110#if ENABLE_ASSERTIONS
Soby Mathew70716d62015-07-13 16:26:11 +0100111 mrs x1, mpidr_el1
112 cmp x0, x1
113 ASM_ASSERT(eq)
114#endif
115 b plat_get_my_stack
116endfunc_deprecated platform_get_stack
117
118 /* -----------------------------------------------------
119 * void platform_set_stack (unsigned long mpidr)
120 *
121 * For the current CPU, this function sets the stack pointer
122 * to a stack allocated in normal memory. The
123 * 'mpidr' should correspond to that of the current CPU.
124 * This function is deprecated and plat_get_my_stack()
125 * should be used instead.
126 * -----------------------------------------------------
127 */
128func_deprecated platform_set_stack
Antonio Nino Diaz7c65c1e2017-04-20 09:58:28 +0100129#if ENABLE_ASSERTIONS
Soby Mathew70716d62015-07-13 16:26:11 +0100130 mrs x1, mpidr_el1
131 cmp x0, x1
132 ASM_ASSERT(eq)
133#endif
134 b plat_set_my_stack
135endfunc_deprecated platform_set_stack
Soby Mathew981487a2015-07-13 14:10:57 +0100136
Andrew Thoelke65668f92014-03-20 10:48:23 +0000137 /* -----------------------------------------------------
Soby Mathewa0fedc42016-06-16 14:52:04 +0100138 * uintptr_t plat_get_my_stack ()
Soby Mathewb0082d22015-04-09 13:40:55 +0100139 *
140 * For the current CPU, this function returns the stack
141 * pointer for a stack allocated in device memory.
142 * -----------------------------------------------------
143 */
144func plat_get_my_stack
145 mov x10, x30 // lr
146 get_my_mp_stack platform_normal_stacks, PLATFORM_STACK_SIZE
147 ret x10
148endfunc plat_get_my_stack
149
150 /* -----------------------------------------------------
151 * void plat_set_my_stack ()
152 *
153 * For the current CPU, this function sets the stack
154 * pointer to a stack allocated in normal memory.
155 * -----------------------------------------------------
156 */
157func plat_set_my_stack
158 mov x9, x30 // lr
159 bl plat_get_my_stack
160 mov sp, x0
161 ret x9
162endfunc plat_set_my_stack
163
Soby Mathew49473e42015-06-10 13:49:59 +0100164#endif /*__ENABLE_PLAT_COMPAT__*/
165
Soby Mathewb0082d22015-04-09 13:40:55 +0100166 /* -----------------------------------------------------
Achin Gupta9c60d802014-06-26 11:12:37 +0100167 * Per-cpu stacks in normal memory. Each cpu gets a
168 * stack of PLATFORM_STACK_SIZE bytes.
Andrew Thoelke65668f92014-03-20 10:48:23 +0000169 * -----------------------------------------------------
170 */
171declare_stack platform_normal_stacks, tzfw_normal_stacks, \
Soby Mathewbfdbecf2016-06-09 17:16:35 +0100172 PLATFORM_STACK_SIZE, PLATFORM_CORE_COUNT, \
173 CACHE_WRITEBACK_GRANULE