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