Andrew Thoelke | 65668f9 | 2014-03-20 10:48:23 +0000 | [diff] [blame] | 1 | /* |
Antonio Nino Diaz | 7c65c1e | 2017-04-20 09:58:28 +0100 | [diff] [blame] | 2 | * Copyright (c) 2014-2017, ARM Limited and Contributors. All rights reserved. |
Andrew Thoelke | 65668f9 | 2014-03-20 10:48:23 +0000 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Andrew Thoelke | 65668f9 | 2014-03-20 10:48:23 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <arch.h> |
Andrew Thoelke | 65668f9 | 2014-03-20 10:48:23 +0000 | [diff] [blame] | 8 | #include <asm_macros.S> |
Soby Mathew | 49473e4 | 2015-06-10 13:49:59 +0100 | [diff] [blame] | 9 | #include <assert_macros.S> |
Dan Handley | ed6ff95 | 2014-05-14 17:44:19 +0100 | [diff] [blame] | 10 | #include <platform_def.h> |
Andrew Thoelke | 65668f9 | 2014-03-20 10:48:23 +0000 | [diff] [blame] | 11 | |
Andrew Thoelke | 65668f9 | 2014-03-20 10:48:23 +0000 | [diff] [blame] | 12 | .local platform_normal_stacks |
Soby Mathew | 49473e4 | 2015-06-10 13:49:59 +0100 | [diff] [blame] | 13 | #if ENABLE_PLAT_COMPAT |
| 14 | .globl plat_get_my_stack |
| 15 | .globl plat_set_my_stack |
Andrew Thoelke | 65668f9 | 2014-03-20 10:48:23 +0000 | [diff] [blame] | 16 | .weak platform_get_stack |
Soby Mathew | 49473e4 | 2015-06-10 13:49:59 +0100 | [diff] [blame] | 17 | .weak platform_set_stack |
Soby Mathew | 981487a | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 18 | #else |
Soby Mathew | b0082d2 | 2015-04-09 13:40:55 +0100 | [diff] [blame] | 19 | .weak plat_get_my_stack |
| 20 | .weak plat_set_my_stack |
Soby Mathew | 70716d6 | 2015-07-13 16:26:11 +0100 | [diff] [blame] | 21 | .globl platform_get_stack |
| 22 | .globl platform_set_stack |
| 23 | #endif /* __ENABLE_PLAT_COMPAT__ */ |
Soby Mathew | 49473e4 | 2015-06-10 13:49:59 +0100 | [diff] [blame] | 24 | |
| 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 Thoelke | 65668f9 | 2014-03-20 10:48:23 +0000 | [diff] [blame] | 35 | |
| 36 | /* ----------------------------------------------------- |
Soby Mathew | 49473e4 | 2015-06-10 13:49:59 +0100 | [diff] [blame] | 37 | * 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 | */ |
| 43 | func plat_get_my_stack |
| 44 | mrs x0, mpidr_el1 |
| 45 | b platform_get_stack |
| 46 | endfunc 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 | */ |
| 55 | func plat_set_my_stack |
| 56 | mrs x0, mpidr_el1 |
| 57 | b platform_set_stack |
| 58 | endfunc plat_set_my_stack |
| 59 | |
Soby Mathew | 49473e4 | 2015-06-10 13:49:59 +0100 | [diff] [blame] | 60 | /* ----------------------------------------------------- |
Andrew Thoelke | 65668f9 | 2014-03-20 10:48:23 +0000 | [diff] [blame] | 61 | * 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 | */ |
| 67 | func platform_get_stack |
| 68 | mov x10, x30 // lr |
| 69 | get_mp_stack platform_normal_stacks, PLATFORM_STACK_SIZE |
| 70 | ret x10 |
Kévin Petit | a877c25 | 2015-03-24 14:03:57 +0000 | [diff] [blame] | 71 | endfunc platform_get_stack |
Andrew Thoelke | 65668f9 | 2014-03-20 10:48:23 +0000 | [diff] [blame] | 72 | |
| 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 | */ |
| 80 | func platform_set_stack |
| 81 | mov x9, x30 // lr |
| 82 | bl platform_get_stack |
| 83 | mov sp, x0 |
| 84 | ret x9 |
Kévin Petit | a877c25 | 2015-03-24 14:03:57 +0000 | [diff] [blame] | 85 | endfunc platform_set_stack |
Andrew Thoelke | 65668f9 | 2014-03-20 10:48:23 +0000 | [diff] [blame] | 86 | |
Soby Mathew | 981487a | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 87 | #else |
Soby Mathew | 70716d6 | 2015-07-13 16:26:11 +0100 | [diff] [blame] | 88 | /* --------------------------------------------------------------------- |
| 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 | */ |
| 109 | func_deprecated platform_get_stack |
Antonio Nino Diaz | 7c65c1e | 2017-04-20 09:58:28 +0100 | [diff] [blame] | 110 | #if ENABLE_ASSERTIONS |
Soby Mathew | 70716d6 | 2015-07-13 16:26:11 +0100 | [diff] [blame] | 111 | mrs x1, mpidr_el1 |
| 112 | cmp x0, x1 |
| 113 | ASM_ASSERT(eq) |
| 114 | #endif |
| 115 | b plat_get_my_stack |
| 116 | endfunc_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 | */ |
| 128 | func_deprecated platform_set_stack |
Antonio Nino Diaz | 7c65c1e | 2017-04-20 09:58:28 +0100 | [diff] [blame] | 129 | #if ENABLE_ASSERTIONS |
Soby Mathew | 70716d6 | 2015-07-13 16:26:11 +0100 | [diff] [blame] | 130 | mrs x1, mpidr_el1 |
| 131 | cmp x0, x1 |
| 132 | ASM_ASSERT(eq) |
| 133 | #endif |
| 134 | b plat_set_my_stack |
| 135 | endfunc_deprecated platform_set_stack |
Soby Mathew | 981487a | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 136 | |
Andrew Thoelke | 65668f9 | 2014-03-20 10:48:23 +0000 | [diff] [blame] | 137 | /* ----------------------------------------------------- |
Soby Mathew | a0fedc4 | 2016-06-16 14:52:04 +0100 | [diff] [blame] | 138 | * uintptr_t plat_get_my_stack () |
Soby Mathew | b0082d2 | 2015-04-09 13:40:55 +0100 | [diff] [blame] | 139 | * |
| 140 | * For the current CPU, this function returns the stack |
| 141 | * pointer for a stack allocated in device memory. |
| 142 | * ----------------------------------------------------- |
| 143 | */ |
| 144 | func plat_get_my_stack |
| 145 | mov x10, x30 // lr |
| 146 | get_my_mp_stack platform_normal_stacks, PLATFORM_STACK_SIZE |
| 147 | ret x10 |
| 148 | endfunc 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 | */ |
| 157 | func plat_set_my_stack |
| 158 | mov x9, x30 // lr |
| 159 | bl plat_get_my_stack |
| 160 | mov sp, x0 |
| 161 | ret x9 |
| 162 | endfunc plat_set_my_stack |
| 163 | |
Soby Mathew | 49473e4 | 2015-06-10 13:49:59 +0100 | [diff] [blame] | 164 | #endif /*__ENABLE_PLAT_COMPAT__*/ |
| 165 | |
Soby Mathew | b0082d2 | 2015-04-09 13:40:55 +0100 | [diff] [blame] | 166 | /* ----------------------------------------------------- |
Achin Gupta | 9c60d80 | 2014-06-26 11:12:37 +0100 | [diff] [blame] | 167 | * Per-cpu stacks in normal memory. Each cpu gets a |
| 168 | * stack of PLATFORM_STACK_SIZE bytes. |
Andrew Thoelke | 65668f9 | 2014-03-20 10:48:23 +0000 | [diff] [blame] | 169 | * ----------------------------------------------------- |
| 170 | */ |
| 171 | declare_stack platform_normal_stacks, tzfw_normal_stacks, \ |
Soby Mathew | bfdbecf | 2016-06-09 17:16:35 +0100 | [diff] [blame] | 172 | PLATFORM_STACK_SIZE, PLATFORM_CORE_COUNT, \ |
| 173 | CACHE_WRITEBACK_GRANULE |