Andrew Thoelke | 65668f9 | 2014-03-20 10:48:23 +0000 | [diff] [blame] | 1 | /* |
Alexei Fedorov | 490ace7 | 2020-05-30 17:33:26 +0100 | [diff] [blame] | 2 | * Copyright (c) 2014-2020, 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 | b0082d2 | 2015-04-09 13:40:55 +0100 | [diff] [blame] | 13 | .weak plat_get_my_stack |
| 14 | .weak plat_set_my_stack |
Soby Mathew | 49473e4 | 2015-06-10 13:49:59 +0100 | [diff] [blame] | 15 | |
Soby Mathew | 70716d6 | 2015-07-13 16:26:11 +0100 | [diff] [blame] | 16 | /* --------------------------------------------------------------------- |
Antonio Nino Diaz | 56b68ad | 2019-02-28 13:35:21 +0000 | [diff] [blame] | 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. |
Soby Mathew | 70716d6 | 2015-07-13 16:26:11 +0100 | [diff] [blame] | 24 | * -------------------------------------------------------------------- |
| 25 | */ |
| 26 | |
Andrew Thoelke | 65668f9 | 2014-03-20 10:48:23 +0000 | [diff] [blame] | 27 | /* ----------------------------------------------------- |
Soby Mathew | a0fedc4 | 2016-06-16 14:52:04 +0100 | [diff] [blame] | 28 | * uintptr_t plat_get_my_stack () |
Soby Mathew | b0082d2 | 2015-04-09 13:40:55 +0100 | [diff] [blame] | 29 | * |
| 30 | * For the current CPU, this function returns the stack |
| 31 | * pointer for a stack allocated in device memory. |
| 32 | * ----------------------------------------------------- |
| 33 | */ |
| 34 | func plat_get_my_stack |
Alexei Fedorov | 490ace7 | 2020-05-30 17:33:26 +0100 | [diff] [blame] | 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 */ |
| 52 | 2: 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 | .word platform_normal_stacks |
| 63 | |
| 64 | #else /* !(IMAGE_BL31 && RECLAIM_INIT_CODE) */ |
| 65 | mov x10, x30 |
Soby Mathew | b0082d2 | 2015-04-09 13:40:55 +0100 | [diff] [blame] | 66 | get_my_mp_stack platform_normal_stacks, PLATFORM_STACK_SIZE |
| 67 | ret x10 |
Alexei Fedorov | 490ace7 | 2020-05-30 17:33:26 +0100 | [diff] [blame] | 68 | |
| 69 | #endif /* IMAGE_BL31 && RECLAIM_INIT_CODE */ |
Soby Mathew | b0082d2 | 2015-04-09 13:40:55 +0100 | [diff] [blame] | 70 | endfunc plat_get_my_stack |
| 71 | |
| 72 | /* ----------------------------------------------------- |
| 73 | * void plat_set_my_stack () |
| 74 | * |
| 75 | * For the current CPU, this function sets the stack |
| 76 | * pointer to a stack allocated in normal memory. |
| 77 | * ----------------------------------------------------- |
| 78 | */ |
| 79 | func plat_set_my_stack |
Alexei Fedorov | 490ace7 | 2020-05-30 17:33:26 +0100 | [diff] [blame] | 80 | mov x9, x30 |
Soby Mathew | b0082d2 | 2015-04-09 13:40:55 +0100 | [diff] [blame] | 81 | bl plat_get_my_stack |
| 82 | mov sp, x0 |
| 83 | ret x9 |
| 84 | endfunc plat_set_my_stack |
| 85 | |
| 86 | /* ----------------------------------------------------- |
Alexei Fedorov | 490ace7 | 2020-05-30 17:33:26 +0100 | [diff] [blame] | 87 | * Per-CPU stacks in normal memory. Each CPU gets a |
Achin Gupta | 9c60d80 | 2014-06-26 11:12:37 +0100 | [diff] [blame] | 88 | * stack of PLATFORM_STACK_SIZE bytes. |
Andrew Thoelke | 65668f9 | 2014-03-20 10:48:23 +0000 | [diff] [blame] | 89 | * ----------------------------------------------------- |
| 90 | */ |
| 91 | declare_stack platform_normal_stacks, tzfw_normal_stacks, \ |
Soby Mathew | bfdbecf | 2016-06-09 17:16:35 +0100 | [diff] [blame] | 92 | PLATFORM_STACK_SIZE, PLATFORM_CORE_COUNT, \ |
| 93 | CACHE_WRITEBACK_GRANULE |