Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 1 | /* |
Paul Beesley | 1fbc97b | 2019-01-11 18:26:51 +0000 | [diff] [blame] | 2 | * Copyright (c) 2013-2019, ARM Limited and Contributors. All rights reserved. |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
Dan Handley | ed6ff95 | 2014-05-14 17:44:19 +0100 | [diff] [blame] | 7 | #include <platform_def.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 8 | |
| 9 | #include <arch_helpers.h> |
| 10 | #include <bl32/tsp/tsp.h> |
| 11 | #include <common/bl_common.h> |
| 12 | #include <common/debug.h> |
| 13 | #include <lib/spinlock.h> |
| 14 | #include <plat/common/platform.h> |
Dan Handley | 4fd2f5c | 2014-08-04 11:41:20 +0100 | [diff] [blame] | 15 | #include <platform_tsp.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 16 | |
Dan Handley | e2c27f5 | 2014-08-01 17:58:27 +0100 | [diff] [blame] | 17 | #include "tsp_private.h" |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 18 | |
Vikram Kanigiri | d8c9d26 | 2014-05-16 18:48:12 +0100 | [diff] [blame] | 19 | |
| 20 | /******************************************************************************* |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 21 | * Lock to control access to the console |
| 22 | ******************************************************************************/ |
| 23 | spinlock_t console_lock; |
| 24 | |
| 25 | /******************************************************************************* |
| 26 | * Per cpu data structure to populate parameters for an SMC in C code and use |
| 27 | * a pointer to this structure in assembler code to populate x0-x7 |
| 28 | ******************************************************************************/ |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 29 | static tsp_args_t tsp_smc_args[PLATFORM_CORE_COUNT]; |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 30 | |
| 31 | /******************************************************************************* |
| 32 | * Per cpu data structure to keep track of TSP activity |
| 33 | ******************************************************************************/ |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 34 | work_statistics_t tsp_stats[PLATFORM_CORE_COUNT]; |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 35 | |
| 36 | /******************************************************************************* |
Sandrine Bailleux | bdba5e5 | 2016-06-16 14:24:26 +0100 | [diff] [blame] | 37 | * The TSP memory footprint starts at address BL32_BASE and ends with the |
| 38 | * linker symbol __BL32_END__. Use these addresses to compute the TSP image |
| 39 | * size. |
Vikram Kanigiri | d8c9d26 | 2014-05-16 18:48:12 +0100 | [diff] [blame] | 40 | ******************************************************************************/ |
Antonio Nino Diaz | de97ff3 | 2019-01-25 13:28:38 +0000 | [diff] [blame] | 41 | #define BL32_TOTAL_LIMIT BL32_END |
Sandrine Bailleux | bdba5e5 | 2016-06-16 14:24:26 +0100 | [diff] [blame] | 42 | #define BL32_TOTAL_SIZE (BL32_TOTAL_LIMIT - (unsigned long) BL32_BASE) |
Vikram Kanigiri | d8c9d26 | 2014-05-16 18:48:12 +0100 | [diff] [blame] | 43 | |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 44 | static tsp_args_t *set_smc_args(uint64_t arg0, |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 45 | uint64_t arg1, |
| 46 | uint64_t arg2, |
| 47 | uint64_t arg3, |
| 48 | uint64_t arg4, |
| 49 | uint64_t arg5, |
| 50 | uint64_t arg6, |
| 51 | uint64_t arg7) |
| 52 | { |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 53 | uint32_t linear_id; |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 54 | tsp_args_t *pcpu_smc_args; |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 55 | |
| 56 | /* |
| 57 | * Return to Secure Monitor by raising an SMC. The results of the |
| 58 | * service are passed as an arguments to the SMC |
| 59 | */ |
Soby Mathew | da43b66 | 2015-07-08 21:45:46 +0100 | [diff] [blame] | 60 | linear_id = plat_my_core_pos(); |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 61 | pcpu_smc_args = &tsp_smc_args[linear_id]; |
| 62 | write_sp_arg(pcpu_smc_args, TSP_ARG0, arg0); |
| 63 | write_sp_arg(pcpu_smc_args, TSP_ARG1, arg1); |
| 64 | write_sp_arg(pcpu_smc_args, TSP_ARG2, arg2); |
| 65 | write_sp_arg(pcpu_smc_args, TSP_ARG3, arg3); |
| 66 | write_sp_arg(pcpu_smc_args, TSP_ARG4, arg4); |
| 67 | write_sp_arg(pcpu_smc_args, TSP_ARG5, arg5); |
| 68 | write_sp_arg(pcpu_smc_args, TSP_ARG6, arg6); |
| 69 | write_sp_arg(pcpu_smc_args, TSP_ARG7, arg7); |
| 70 | |
| 71 | return pcpu_smc_args; |
| 72 | } |
| 73 | |
| 74 | /******************************************************************************* |
| 75 | * TSP main entry point where it gets the opportunity to initialize its secure |
| 76 | * state/applications. Once the state is initialized, it must return to the |
Andrew Thoelke | 891c4ca | 2014-05-20 21:43:27 +0100 | [diff] [blame] | 77 | * SPD with a pointer to the 'tsp_vector_table' jump table. |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 78 | ******************************************************************************/ |
| 79 | uint64_t tsp_main(void) |
| 80 | { |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 81 | NOTICE("TSP: %s\n", version_string); |
| 82 | NOTICE("TSP: %s\n", build_message); |
Sandrine Bailleux | bdba5e5 | 2016-06-16 14:24:26 +0100 | [diff] [blame] | 83 | INFO("TSP: Total memory base : 0x%lx\n", (unsigned long) BL32_BASE); |
| 84 | INFO("TSP: Total memory size : 0x%lx bytes\n", BL32_TOTAL_SIZE); |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 85 | |
Soby Mathew | da43b66 | 2015-07-08 21:45:46 +0100 | [diff] [blame] | 86 | uint32_t linear_id = plat_my_core_pos(); |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 87 | |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 88 | /* Initialize the platform */ |
Dan Handley | 4fd2f5c | 2014-08-04 11:41:20 +0100 | [diff] [blame] | 89 | tsp_platform_setup(); |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 90 | |
| 91 | /* Initialize secure/applications state here */ |
Achin Gupta | bbc33f2 | 2014-05-09 13:33:42 +0100 | [diff] [blame] | 92 | tsp_generic_timer_start(); |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 93 | |
| 94 | /* Update this cpu's statistics */ |
| 95 | tsp_stats[linear_id].smc_count++; |
| 96 | tsp_stats[linear_id].eret_count++; |
| 97 | tsp_stats[linear_id].cpu_on_count++; |
| 98 | |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 99 | #if LOG_LEVEL >= LOG_LEVEL_INFO |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 100 | spin_lock(&console_lock); |
Soby Mathew | da43b66 | 2015-07-08 21:45:46 +0100 | [diff] [blame] | 101 | INFO("TSP: cpu 0x%lx: %d smcs, %d erets %d cpu on requests\n", |
| 102 | read_mpidr(), |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 103 | tsp_stats[linear_id].smc_count, |
| 104 | tsp_stats[linear_id].eret_count, |
| 105 | tsp_stats[linear_id].cpu_on_count); |
| 106 | spin_unlock(&console_lock); |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 107 | #endif |
Andrew Thoelke | 891c4ca | 2014-05-20 21:43:27 +0100 | [diff] [blame] | 108 | return (uint64_t) &tsp_vector_table; |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | /******************************************************************************* |
| 112 | * This function performs any remaining book keeping in the test secure payload |
| 113 | * after this cpu's architectural state has been setup in response to an earlier |
| 114 | * psci cpu_on request. |
| 115 | ******************************************************************************/ |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 116 | tsp_args_t *tsp_cpu_on_main(void) |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 117 | { |
Soby Mathew | da43b66 | 2015-07-08 21:45:46 +0100 | [diff] [blame] | 118 | uint32_t linear_id = plat_my_core_pos(); |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 119 | |
Achin Gupta | bbc33f2 | 2014-05-09 13:33:42 +0100 | [diff] [blame] | 120 | /* Initialize secure/applications state here */ |
| 121 | tsp_generic_timer_start(); |
| 122 | |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 123 | /* Update this cpu's statistics */ |
| 124 | tsp_stats[linear_id].smc_count++; |
| 125 | tsp_stats[linear_id].eret_count++; |
| 126 | tsp_stats[linear_id].cpu_on_count++; |
| 127 | |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 128 | #if LOG_LEVEL >= LOG_LEVEL_INFO |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 129 | spin_lock(&console_lock); |
Soby Mathew | da43b66 | 2015-07-08 21:45:46 +0100 | [diff] [blame] | 130 | INFO("TSP: cpu 0x%lx turned on\n", read_mpidr()); |
| 131 | INFO("TSP: cpu 0x%lx: %d smcs, %d erets %d cpu on requests\n", |
| 132 | read_mpidr(), |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 133 | tsp_stats[linear_id].smc_count, |
| 134 | tsp_stats[linear_id].eret_count, |
| 135 | tsp_stats[linear_id].cpu_on_count); |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 136 | spin_unlock(&console_lock); |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 137 | #endif |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 138 | /* Indicate to the SPD that we have completed turned ourselves on */ |
| 139 | return set_smc_args(TSP_ON_DONE, 0, 0, 0, 0, 0, 0, 0); |
| 140 | } |
| 141 | |
| 142 | /******************************************************************************* |
| 143 | * This function performs any remaining book keeping in the test secure payload |
| 144 | * before this cpu is turned off in response to a psci cpu_off request. |
| 145 | ******************************************************************************/ |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 146 | tsp_args_t *tsp_cpu_off_main(uint64_t arg0, |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 147 | uint64_t arg1, |
| 148 | uint64_t arg2, |
| 149 | uint64_t arg3, |
| 150 | uint64_t arg4, |
| 151 | uint64_t arg5, |
| 152 | uint64_t arg6, |
| 153 | uint64_t arg7) |
| 154 | { |
Soby Mathew | da43b66 | 2015-07-08 21:45:46 +0100 | [diff] [blame] | 155 | uint32_t linear_id = plat_my_core_pos(); |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 156 | |
Achin Gupta | bbc33f2 | 2014-05-09 13:33:42 +0100 | [diff] [blame] | 157 | /* |
| 158 | * This cpu is being turned off, so disable the timer to prevent the |
| 159 | * secure timer interrupt from interfering with power down. A pending |
| 160 | * interrupt will be lost but we do not care as we are turning off. |
| 161 | */ |
| 162 | tsp_generic_timer_stop(); |
| 163 | |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 164 | /* Update this cpu's statistics */ |
| 165 | tsp_stats[linear_id].smc_count++; |
| 166 | tsp_stats[linear_id].eret_count++; |
| 167 | tsp_stats[linear_id].cpu_off_count++; |
| 168 | |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 169 | #if LOG_LEVEL >= LOG_LEVEL_INFO |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 170 | spin_lock(&console_lock); |
Soby Mathew | da43b66 | 2015-07-08 21:45:46 +0100 | [diff] [blame] | 171 | INFO("TSP: cpu 0x%lx off request\n", read_mpidr()); |
| 172 | INFO("TSP: cpu 0x%lx: %d smcs, %d erets %d cpu off requests\n", |
| 173 | read_mpidr(), |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 174 | tsp_stats[linear_id].smc_count, |
| 175 | tsp_stats[linear_id].eret_count, |
| 176 | tsp_stats[linear_id].cpu_off_count); |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 177 | spin_unlock(&console_lock); |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 178 | #endif |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 179 | |
Achin Gupta | 607084e | 2014-02-09 18:24:19 +0000 | [diff] [blame] | 180 | /* Indicate to the SPD that we have completed this request */ |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 181 | return set_smc_args(TSP_OFF_DONE, 0, 0, 0, 0, 0, 0, 0); |
| 182 | } |
| 183 | |
| 184 | /******************************************************************************* |
| 185 | * This function performs any book keeping in the test secure payload before |
| 186 | * this cpu's architectural state is saved in response to an earlier psci |
| 187 | * cpu_suspend request. |
| 188 | ******************************************************************************/ |
Soby Mathew | f512157 | 2014-09-30 11:19:51 +0100 | [diff] [blame] | 189 | tsp_args_t *tsp_cpu_suspend_main(uint64_t arg0, |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 190 | uint64_t arg1, |
| 191 | uint64_t arg2, |
| 192 | uint64_t arg3, |
| 193 | uint64_t arg4, |
| 194 | uint64_t arg5, |
| 195 | uint64_t arg6, |
| 196 | uint64_t arg7) |
| 197 | { |
Soby Mathew | da43b66 | 2015-07-08 21:45:46 +0100 | [diff] [blame] | 198 | uint32_t linear_id = plat_my_core_pos(); |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 199 | |
Achin Gupta | bbc33f2 | 2014-05-09 13:33:42 +0100 | [diff] [blame] | 200 | /* |
| 201 | * Save the time context and disable it to prevent the secure timer |
| 202 | * interrupt from interfering with wakeup from the suspend state. |
| 203 | */ |
| 204 | tsp_generic_timer_save(); |
| 205 | tsp_generic_timer_stop(); |
| 206 | |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 207 | /* Update this cpu's statistics */ |
| 208 | tsp_stats[linear_id].smc_count++; |
| 209 | tsp_stats[linear_id].eret_count++; |
| 210 | tsp_stats[linear_id].cpu_suspend_count++; |
| 211 | |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 212 | #if LOG_LEVEL >= LOG_LEVEL_INFO |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 213 | spin_lock(&console_lock); |
Sandrine Bailleux | 8723adf | 2015-02-05 15:42:31 +0000 | [diff] [blame] | 214 | INFO("TSP: cpu 0x%lx: %d smcs, %d erets %d cpu suspend requests\n", |
Soby Mathew | da43b66 | 2015-07-08 21:45:46 +0100 | [diff] [blame] | 215 | read_mpidr(), |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 216 | tsp_stats[linear_id].smc_count, |
| 217 | tsp_stats[linear_id].eret_count, |
| 218 | tsp_stats[linear_id].cpu_suspend_count); |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 219 | spin_unlock(&console_lock); |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 220 | #endif |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 221 | |
Achin Gupta | 607084e | 2014-02-09 18:24:19 +0000 | [diff] [blame] | 222 | /* Indicate to the SPD that we have completed this request */ |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 223 | return set_smc_args(TSP_SUSPEND_DONE, 0, 0, 0, 0, 0, 0, 0); |
| 224 | } |
| 225 | |
| 226 | /******************************************************************************* |
| 227 | * This function performs any book keeping in the test secure payload after this |
| 228 | * cpu's architectural state has been restored after wakeup from an earlier psci |
| 229 | * cpu_suspend request. |
| 230 | ******************************************************************************/ |
Achin Gupta | 9a0ff9b | 2015-09-07 20:43:27 +0100 | [diff] [blame] | 231 | tsp_args_t *tsp_cpu_resume_main(uint64_t max_off_pwrlvl, |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 232 | uint64_t arg1, |
| 233 | uint64_t arg2, |
| 234 | uint64_t arg3, |
| 235 | uint64_t arg4, |
| 236 | uint64_t arg5, |
| 237 | uint64_t arg6, |
| 238 | uint64_t arg7) |
| 239 | { |
Soby Mathew | da43b66 | 2015-07-08 21:45:46 +0100 | [diff] [blame] | 240 | uint32_t linear_id = plat_my_core_pos(); |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 241 | |
Achin Gupta | bbc33f2 | 2014-05-09 13:33:42 +0100 | [diff] [blame] | 242 | /* Restore the generic timer context */ |
| 243 | tsp_generic_timer_restore(); |
| 244 | |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 245 | /* Update this cpu's statistics */ |
| 246 | tsp_stats[linear_id].smc_count++; |
| 247 | tsp_stats[linear_id].eret_count++; |
| 248 | tsp_stats[linear_id].cpu_resume_count++; |
| 249 | |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 250 | #if LOG_LEVEL >= LOG_LEVEL_INFO |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 251 | spin_lock(&console_lock); |
Masahiro Yamada | e93a0f4 | 2018-02-02 15:09:36 +0900 | [diff] [blame] | 252 | INFO("TSP: cpu 0x%lx resumed. maximum off power level %lld\n", |
Achin Gupta | 9a0ff9b | 2015-09-07 20:43:27 +0100 | [diff] [blame] | 253 | read_mpidr(), max_off_pwrlvl); |
Sandrine Bailleux | 8723adf | 2015-02-05 15:42:31 +0000 | [diff] [blame] | 254 | INFO("TSP: cpu 0x%lx: %d smcs, %d erets %d cpu suspend requests\n", |
Soby Mathew | da43b66 | 2015-07-08 21:45:46 +0100 | [diff] [blame] | 255 | read_mpidr(), |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 256 | tsp_stats[linear_id].smc_count, |
| 257 | tsp_stats[linear_id].eret_count, |
| 258 | tsp_stats[linear_id].cpu_suspend_count); |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 259 | spin_unlock(&console_lock); |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 260 | #endif |
Achin Gupta | 607084e | 2014-02-09 18:24:19 +0000 | [diff] [blame] | 261 | /* Indicate to the SPD that we have completed this request */ |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 262 | return set_smc_args(TSP_RESUME_DONE, 0, 0, 0, 0, 0, 0, 0); |
| 263 | } |
| 264 | |
| 265 | /******************************************************************************* |
Juan Castillo | 4dc4a47 | 2014-08-12 11:17:06 +0100 | [diff] [blame] | 266 | * This function performs any remaining bookkeeping in the test secure payload |
| 267 | * before the system is switched off (in response to a psci SYSTEM_OFF request) |
| 268 | ******************************************************************************/ |
| 269 | tsp_args_t *tsp_system_off_main(uint64_t arg0, |
| 270 | uint64_t arg1, |
| 271 | uint64_t arg2, |
| 272 | uint64_t arg3, |
| 273 | uint64_t arg4, |
| 274 | uint64_t arg5, |
| 275 | uint64_t arg6, |
| 276 | uint64_t arg7) |
| 277 | { |
Soby Mathew | da43b66 | 2015-07-08 21:45:46 +0100 | [diff] [blame] | 278 | uint32_t linear_id = plat_my_core_pos(); |
Juan Castillo | 4dc4a47 | 2014-08-12 11:17:06 +0100 | [diff] [blame] | 279 | |
| 280 | /* Update this cpu's statistics */ |
| 281 | tsp_stats[linear_id].smc_count++; |
| 282 | tsp_stats[linear_id].eret_count++; |
| 283 | |
| 284 | #if LOG_LEVEL >= LOG_LEVEL_INFO |
| 285 | spin_lock(&console_lock); |
Soby Mathew | da43b66 | 2015-07-08 21:45:46 +0100 | [diff] [blame] | 286 | INFO("TSP: cpu 0x%lx SYSTEM_OFF request\n", read_mpidr()); |
| 287 | INFO("TSP: cpu 0x%lx: %d smcs, %d erets requests\n", read_mpidr(), |
Juan Castillo | 4dc4a47 | 2014-08-12 11:17:06 +0100 | [diff] [blame] | 288 | tsp_stats[linear_id].smc_count, |
| 289 | tsp_stats[linear_id].eret_count); |
| 290 | spin_unlock(&console_lock); |
| 291 | #endif |
| 292 | |
| 293 | /* Indicate to the SPD that we have completed this request */ |
| 294 | return set_smc_args(TSP_SYSTEM_OFF_DONE, 0, 0, 0, 0, 0, 0, 0); |
| 295 | } |
| 296 | |
| 297 | /******************************************************************************* |
| 298 | * This function performs any remaining bookkeeping in the test secure payload |
| 299 | * before the system is reset (in response to a psci SYSTEM_RESET request) |
| 300 | ******************************************************************************/ |
| 301 | tsp_args_t *tsp_system_reset_main(uint64_t arg0, |
| 302 | uint64_t arg1, |
| 303 | uint64_t arg2, |
| 304 | uint64_t arg3, |
| 305 | uint64_t arg4, |
| 306 | uint64_t arg5, |
| 307 | uint64_t arg6, |
| 308 | uint64_t arg7) |
| 309 | { |
Soby Mathew | da43b66 | 2015-07-08 21:45:46 +0100 | [diff] [blame] | 310 | uint32_t linear_id = plat_my_core_pos(); |
Juan Castillo | 4dc4a47 | 2014-08-12 11:17:06 +0100 | [diff] [blame] | 311 | |
| 312 | /* Update this cpu's statistics */ |
| 313 | tsp_stats[linear_id].smc_count++; |
| 314 | tsp_stats[linear_id].eret_count++; |
| 315 | |
| 316 | #if LOG_LEVEL >= LOG_LEVEL_INFO |
| 317 | spin_lock(&console_lock); |
Soby Mathew | da43b66 | 2015-07-08 21:45:46 +0100 | [diff] [blame] | 318 | INFO("TSP: cpu 0x%lx SYSTEM_RESET request\n", read_mpidr()); |
| 319 | INFO("TSP: cpu 0x%lx: %d smcs, %d erets requests\n", read_mpidr(), |
Juan Castillo | 4dc4a47 | 2014-08-12 11:17:06 +0100 | [diff] [blame] | 320 | tsp_stats[linear_id].smc_count, |
| 321 | tsp_stats[linear_id].eret_count); |
| 322 | spin_unlock(&console_lock); |
| 323 | #endif |
| 324 | |
| 325 | /* Indicate to the SPD that we have completed this request */ |
| 326 | return set_smc_args(TSP_SYSTEM_RESET_DONE, 0, 0, 0, 0, 0, 0, 0); |
| 327 | } |
| 328 | |
| 329 | /******************************************************************************* |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 330 | * TSP fast smc handler. The secure monitor jumps to this function by |
| 331 | * doing the ERET after populating X0-X7 registers. The arguments are received |
| 332 | * in the function arguments in order. Once the service is rendered, this |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 333 | * function returns to Secure Monitor by raising SMC. |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 334 | ******************************************************************************/ |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 335 | tsp_args_t *tsp_smc_handler(uint64_t func, |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 336 | uint64_t arg1, |
| 337 | uint64_t arg2, |
| 338 | uint64_t arg3, |
| 339 | uint64_t arg4, |
| 340 | uint64_t arg5, |
| 341 | uint64_t arg6, |
| 342 | uint64_t arg7) |
| 343 | { |
Achin Gupta | 916a2c1 | 2014-02-09 23:11:46 +0000 | [diff] [blame] | 344 | uint64_t results[2]; |
| 345 | uint64_t service_args[2]; |
Soby Mathew | da43b66 | 2015-07-08 21:45:46 +0100 | [diff] [blame] | 346 | uint32_t linear_id = plat_my_core_pos(); |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 347 | |
Achin Gupta | 916a2c1 | 2014-02-09 23:11:46 +0000 | [diff] [blame] | 348 | /* Update this cpu's statistics */ |
| 349 | tsp_stats[linear_id].smc_count++; |
| 350 | tsp_stats[linear_id].eret_count++; |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 351 | |
Masahiro Yamada | e93a0f4 | 2018-02-02 15:09:36 +0900 | [diff] [blame] | 352 | INFO("TSP: cpu 0x%lx received %s smc 0x%llx\n", read_mpidr(), |
David Cunado | 28f69ab | 2017-04-05 11:34:03 +0100 | [diff] [blame] | 353 | ((func >> 31) & 1) == 1 ? "fast" : "yielding", |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 354 | func); |
Soby Mathew | da43b66 | 2015-07-08 21:45:46 +0100 | [diff] [blame] | 355 | INFO("TSP: cpu 0x%lx: %d smcs, %d erets\n", read_mpidr(), |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 356 | tsp_stats[linear_id].smc_count, |
| 357 | tsp_stats[linear_id].eret_count); |
Achin Gupta | 916a2c1 | 2014-02-09 23:11:46 +0000 | [diff] [blame] | 358 | |
| 359 | /* Render secure services and obtain results here */ |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 360 | results[0] = arg1; |
| 361 | results[1] = arg2; |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 362 | |
| 363 | /* |
| 364 | * Request a service back from dispatcher/secure monitor. This call |
Paul Beesley | 1fbc97b | 2019-01-11 18:26:51 +0000 | [diff] [blame] | 365 | * return and thereafter resume execution |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 366 | */ |
| 367 | tsp_get_magic(service_args); |
| 368 | |
| 369 | /* Determine the function to perform based on the function ID */ |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 370 | switch (TSP_BARE_FID(func)) { |
| 371 | case TSP_ADD: |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 372 | results[0] += service_args[0]; |
| 373 | results[1] += service_args[1]; |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 374 | break; |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 375 | case TSP_SUB: |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 376 | results[0] -= service_args[0]; |
| 377 | results[1] -= service_args[1]; |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 378 | break; |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 379 | case TSP_MUL: |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 380 | results[0] *= service_args[0]; |
| 381 | results[1] *= service_args[1]; |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 382 | break; |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 383 | case TSP_DIV: |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 384 | results[0] /= service_args[0] ? service_args[0] : 1; |
| 385 | results[1] /= service_args[1] ? service_args[1] : 1; |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 386 | break; |
| 387 | default: |
| 388 | break; |
| 389 | } |
| 390 | |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 391 | return set_smc_args(func, 0, |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 392 | results[0], |
| 393 | results[1], |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 394 | 0, 0, 0, 0); |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 395 | } |
| 396 | |
Douglas Raillard | f212965 | 2016-11-24 15:43:19 +0000 | [diff] [blame] | 397 | /******************************************************************************* |
Paul Beesley | 1fbc97b | 2019-01-11 18:26:51 +0000 | [diff] [blame] | 398 | * TSP smc abort handler. This function is called when aborting a preempted |
David Cunado | 28f69ab | 2017-04-05 11:34:03 +0100 | [diff] [blame] | 399 | * yielding SMC request. It should cleanup all resources owned by the SMC |
Douglas Raillard | f212965 | 2016-11-24 15:43:19 +0000 | [diff] [blame] | 400 | * handler such as locks or dynamically allocated memory so following SMC |
| 401 | * request are executed in a clean environment. |
| 402 | ******************************************************************************/ |
| 403 | tsp_args_t *tsp_abort_smc_handler(uint64_t func, |
| 404 | uint64_t arg1, |
| 405 | uint64_t arg2, |
| 406 | uint64_t arg3, |
| 407 | uint64_t arg4, |
| 408 | uint64_t arg5, |
| 409 | uint64_t arg6, |
| 410 | uint64_t arg7) |
| 411 | { |
| 412 | return set_smc_args(TSP_ABORT_DONE, 0, 0, 0, 0, 0, 0, 0); |
| 413 | } |