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