blob: 55e1532129406e5a003cb2346a3a97ce56ccd0fe [file] [log] [blame]
Achin Gupta7c88f3f2014-02-18 18:09:12 +00001/*
Alexei Fedorov7d616ee2020-11-13 12:36:49 +00002 * Copyright (c) 2013-2020, ARM Limited and Contributors. All rights reserved.
Achin Gupta7c88f3f2014-02-18 18:09:12 +00003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Achin Gupta7c88f3f2014-02-18 18:09:12 +00005 */
6
Alexei Fedorovf41355c2019-09-13 14:11:59 +01007#include <assert.h>
Scott Brandene5dcf982020-08-25 13:49:32 -07008#include <inttypes.h>
9#include <stdint.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000010
Alexei Fedorovf41355c2019-09-13 14:11:59 +010011#include <arch_features.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000012#include <arch_helpers.h>
13#include <bl32/tsp/tsp.h>
14#include <common/bl_common.h>
15#include <common/debug.h>
16#include <lib/spinlock.h>
17#include <plat/common/platform.h>
Alexei Fedorovf41355c2019-09-13 14:11:59 +010018#include <platform_def.h>
Dan Handley4fd2f5c2014-08-04 11:41:20 +010019#include <platform_tsp.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000020
Dan Handleye2c27f52014-08-01 17:58:27 +010021#include "tsp_private.h"
Achin Gupta7c88f3f2014-02-18 18:09:12 +000022
Vikram Kanigirid8c9d262014-05-16 18:48:12 +010023
24/*******************************************************************************
Achin Gupta7c88f3f2014-02-18 18:09:12 +000025 * Lock to control access to the console
26 ******************************************************************************/
27spinlock_t console_lock;
28
29/*******************************************************************************
30 * Per cpu data structure to populate parameters for an SMC in C code and use
31 * a pointer to this structure in assembler code to populate x0-x7
32 ******************************************************************************/
Dan Handleye2712bc2014-04-10 15:37:22 +010033static tsp_args_t tsp_smc_args[PLATFORM_CORE_COUNT];
Achin Gupta7c88f3f2014-02-18 18:09:12 +000034
35/*******************************************************************************
36 * Per cpu data structure to keep track of TSP activity
37 ******************************************************************************/
Achin Gupta76717892014-05-09 11:42:56 +010038work_statistics_t tsp_stats[PLATFORM_CORE_COUNT];
Achin Gupta7c88f3f2014-02-18 18:09:12 +000039
40/*******************************************************************************
Sandrine Bailleuxbdba5e52016-06-16 14:24:26 +010041 * The TSP memory footprint starts at address BL32_BASE and ends with the
42 * linker symbol __BL32_END__. Use these addresses to compute the TSP image
43 * size.
Vikram Kanigirid8c9d262014-05-16 18:48:12 +010044 ******************************************************************************/
Antonio Nino Diazde97ff32019-01-25 13:28:38 +000045#define BL32_TOTAL_LIMIT BL32_END
Sandrine Bailleuxbdba5e52016-06-16 14:24:26 +010046#define BL32_TOTAL_SIZE (BL32_TOTAL_LIMIT - (unsigned long) BL32_BASE)
Vikram Kanigirid8c9d262014-05-16 18:48:12 +010047
Dan Handleye2712bc2014-04-10 15:37:22 +010048static tsp_args_t *set_smc_args(uint64_t arg0,
Achin Gupta7c88f3f2014-02-18 18:09:12 +000049 uint64_t arg1,
50 uint64_t arg2,
51 uint64_t arg3,
52 uint64_t arg4,
53 uint64_t arg5,
54 uint64_t arg6,
55 uint64_t arg7)
56{
Achin Gupta7c88f3f2014-02-18 18:09:12 +000057 uint32_t linear_id;
Dan Handleye2712bc2014-04-10 15:37:22 +010058 tsp_args_t *pcpu_smc_args;
Achin Gupta7c88f3f2014-02-18 18:09:12 +000059
60 /*
61 * Return to Secure Monitor by raising an SMC. The results of the
62 * service are passed as an arguments to the SMC
63 */
Soby Mathewda43b662015-07-08 21:45:46 +010064 linear_id = plat_my_core_pos();
Achin Gupta7c88f3f2014-02-18 18:09:12 +000065 pcpu_smc_args = &tsp_smc_args[linear_id];
66 write_sp_arg(pcpu_smc_args, TSP_ARG0, arg0);
67 write_sp_arg(pcpu_smc_args, TSP_ARG1, arg1);
68 write_sp_arg(pcpu_smc_args, TSP_ARG2, arg2);
69 write_sp_arg(pcpu_smc_args, TSP_ARG3, arg3);
70 write_sp_arg(pcpu_smc_args, TSP_ARG4, arg4);
71 write_sp_arg(pcpu_smc_args, TSP_ARG5, arg5);
72 write_sp_arg(pcpu_smc_args, TSP_ARG6, arg6);
73 write_sp_arg(pcpu_smc_args, TSP_ARG7, arg7);
74
75 return pcpu_smc_args;
76}
77
78/*******************************************************************************
Antonio Nino Diaze61ece02019-02-26 11:41:03 +000079 * Setup function for TSP.
80 ******************************************************************************/
81void tsp_setup(void)
82{
83 /* Perform early platform-specific setup */
84 tsp_early_platform_setup();
85
Antonio Nino Diaze61ece02019-02-26 11:41:03 +000086 /* Perform late platform-specific setup */
87 tsp_plat_arch_setup();
Alexei Fedorovf41355c2019-09-13 14:11:59 +010088
89#if ENABLE_PAUTH
90 /*
91 * Assert that the ARMv8.3-PAuth registers are present or an access
92 * fault will be triggered when they are being saved or restored.
93 */
94 assert(is_armv8_3_pauth_present());
95#endif /* ENABLE_PAUTH */
Antonio Nino Diaze61ece02019-02-26 11:41:03 +000096}
97
98/*******************************************************************************
Achin Gupta7c88f3f2014-02-18 18:09:12 +000099 * TSP main entry point where it gets the opportunity to initialize its secure
100 * state/applications. Once the state is initialized, it must return to the
Andrew Thoelke891c4ca2014-05-20 21:43:27 +0100101 * SPD with a pointer to the 'tsp_vector_table' jump table.
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000102 ******************************************************************************/
103uint64_t tsp_main(void)
104{
Dan Handley91b624e2014-07-29 17:14:00 +0100105 NOTICE("TSP: %s\n", version_string);
106 NOTICE("TSP: %s\n", build_message);
Sandrine Bailleuxbdba5e52016-06-16 14:24:26 +0100107 INFO("TSP: Total memory base : 0x%lx\n", (unsigned long) BL32_BASE);
108 INFO("TSP: Total memory size : 0x%lx bytes\n", BL32_TOTAL_SIZE);
Dan Handley91b624e2014-07-29 17:14:00 +0100109
Soby Mathewda43b662015-07-08 21:45:46 +0100110 uint32_t linear_id = plat_my_core_pos();
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000111
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000112 /* Initialize the platform */
Dan Handley4fd2f5c2014-08-04 11:41:20 +0100113 tsp_platform_setup();
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000114
115 /* Initialize secure/applications state here */
Achin Guptabbc33f22014-05-09 13:33:42 +0100116 tsp_generic_timer_start();
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000117
118 /* Update this cpu's statistics */
119 tsp_stats[linear_id].smc_count++;
120 tsp_stats[linear_id].eret_count++;
121 tsp_stats[linear_id].cpu_on_count++;
122
Dan Handley91b624e2014-07-29 17:14:00 +0100123#if LOG_LEVEL >= LOG_LEVEL_INFO
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000124 spin_lock(&console_lock);
Soby Mathewda43b662015-07-08 21:45:46 +0100125 INFO("TSP: cpu 0x%lx: %d smcs, %d erets %d cpu on requests\n",
126 read_mpidr(),
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000127 tsp_stats[linear_id].smc_count,
128 tsp_stats[linear_id].eret_count,
129 tsp_stats[linear_id].cpu_on_count);
130 spin_unlock(&console_lock);
Dan Handley91b624e2014-07-29 17:14:00 +0100131#endif
Andrew Thoelke891c4ca2014-05-20 21:43:27 +0100132 return (uint64_t) &tsp_vector_table;
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000133}
134
135/*******************************************************************************
136 * This function performs any remaining book keeping in the test secure payload
137 * after this cpu's architectural state has been setup in response to an earlier
138 * psci cpu_on request.
139 ******************************************************************************/
Dan Handleye2712bc2014-04-10 15:37:22 +0100140tsp_args_t *tsp_cpu_on_main(void)
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000141{
Soby Mathewda43b662015-07-08 21:45:46 +0100142 uint32_t linear_id = plat_my_core_pos();
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000143
Achin Guptabbc33f22014-05-09 13:33:42 +0100144 /* Initialize secure/applications state here */
145 tsp_generic_timer_start();
146
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000147 /* Update this cpu's statistics */
148 tsp_stats[linear_id].smc_count++;
149 tsp_stats[linear_id].eret_count++;
150 tsp_stats[linear_id].cpu_on_count++;
151
Dan Handley91b624e2014-07-29 17:14:00 +0100152#if LOG_LEVEL >= LOG_LEVEL_INFO
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000153 spin_lock(&console_lock);
Soby Mathewda43b662015-07-08 21:45:46 +0100154 INFO("TSP: cpu 0x%lx turned on\n", read_mpidr());
155 INFO("TSP: cpu 0x%lx: %d smcs, %d erets %d cpu on requests\n",
156 read_mpidr(),
Dan Handley91b624e2014-07-29 17:14:00 +0100157 tsp_stats[linear_id].smc_count,
158 tsp_stats[linear_id].eret_count,
159 tsp_stats[linear_id].cpu_on_count);
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000160 spin_unlock(&console_lock);
Dan Handley91b624e2014-07-29 17:14:00 +0100161#endif
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000162 /* Indicate to the SPD that we have completed turned ourselves on */
163 return set_smc_args(TSP_ON_DONE, 0, 0, 0, 0, 0, 0, 0);
164}
165
166/*******************************************************************************
167 * This function performs any remaining book keeping in the test secure payload
168 * before this cpu is turned off in response to a psci cpu_off request.
169 ******************************************************************************/
Dan Handleye2712bc2014-04-10 15:37:22 +0100170tsp_args_t *tsp_cpu_off_main(uint64_t arg0,
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000171 uint64_t arg1,
172 uint64_t arg2,
173 uint64_t arg3,
174 uint64_t arg4,
175 uint64_t arg5,
176 uint64_t arg6,
177 uint64_t arg7)
178{
Soby Mathewda43b662015-07-08 21:45:46 +0100179 uint32_t linear_id = plat_my_core_pos();
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000180
Achin Guptabbc33f22014-05-09 13:33:42 +0100181 /*
182 * This cpu is being turned off, so disable the timer to prevent the
183 * secure timer interrupt from interfering with power down. A pending
184 * interrupt will be lost but we do not care as we are turning off.
185 */
186 tsp_generic_timer_stop();
187
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000188 /* Update this cpu's statistics */
189 tsp_stats[linear_id].smc_count++;
190 tsp_stats[linear_id].eret_count++;
191 tsp_stats[linear_id].cpu_off_count++;
192
Dan Handley91b624e2014-07-29 17:14:00 +0100193#if LOG_LEVEL >= LOG_LEVEL_INFO
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000194 spin_lock(&console_lock);
Soby Mathewda43b662015-07-08 21:45:46 +0100195 INFO("TSP: cpu 0x%lx off request\n", read_mpidr());
196 INFO("TSP: cpu 0x%lx: %d smcs, %d erets %d cpu off requests\n",
197 read_mpidr(),
Dan Handley91b624e2014-07-29 17:14:00 +0100198 tsp_stats[linear_id].smc_count,
199 tsp_stats[linear_id].eret_count,
200 tsp_stats[linear_id].cpu_off_count);
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000201 spin_unlock(&console_lock);
Dan Handley91b624e2014-07-29 17:14:00 +0100202#endif
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000203
Achin Gupta607084e2014-02-09 18:24:19 +0000204 /* Indicate to the SPD that we have completed this request */
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000205 return set_smc_args(TSP_OFF_DONE, 0, 0, 0, 0, 0, 0, 0);
206}
207
208/*******************************************************************************
209 * This function performs any book keeping in the test secure payload before
210 * this cpu's architectural state is saved in response to an earlier psci
211 * cpu_suspend request.
212 ******************************************************************************/
Soby Mathewf5121572014-09-30 11:19:51 +0100213tsp_args_t *tsp_cpu_suspend_main(uint64_t arg0,
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000214 uint64_t arg1,
215 uint64_t arg2,
216 uint64_t arg3,
217 uint64_t arg4,
218 uint64_t arg5,
219 uint64_t arg6,
220 uint64_t arg7)
221{
Soby Mathewda43b662015-07-08 21:45:46 +0100222 uint32_t linear_id = plat_my_core_pos();
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000223
Achin Guptabbc33f22014-05-09 13:33:42 +0100224 /*
225 * Save the time context and disable it to prevent the secure timer
226 * interrupt from interfering with wakeup from the suspend state.
227 */
228 tsp_generic_timer_save();
229 tsp_generic_timer_stop();
230
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000231 /* Update this cpu's statistics */
232 tsp_stats[linear_id].smc_count++;
233 tsp_stats[linear_id].eret_count++;
234 tsp_stats[linear_id].cpu_suspend_count++;
235
Dan Handley91b624e2014-07-29 17:14:00 +0100236#if LOG_LEVEL >= LOG_LEVEL_INFO
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000237 spin_lock(&console_lock);
Sandrine Bailleux8723adf2015-02-05 15:42:31 +0000238 INFO("TSP: cpu 0x%lx: %d smcs, %d erets %d cpu suspend requests\n",
Soby Mathewda43b662015-07-08 21:45:46 +0100239 read_mpidr(),
Dan Handley91b624e2014-07-29 17:14:00 +0100240 tsp_stats[linear_id].smc_count,
241 tsp_stats[linear_id].eret_count,
242 tsp_stats[linear_id].cpu_suspend_count);
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000243 spin_unlock(&console_lock);
Dan Handley91b624e2014-07-29 17:14:00 +0100244#endif
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000245
Achin Gupta607084e2014-02-09 18:24:19 +0000246 /* Indicate to the SPD that we have completed this request */
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000247 return set_smc_args(TSP_SUSPEND_DONE, 0, 0, 0, 0, 0, 0, 0);
248}
249
250/*******************************************************************************
251 * This function performs any book keeping in the test secure payload after this
252 * cpu's architectural state has been restored after wakeup from an earlier psci
253 * cpu_suspend request.
254 ******************************************************************************/
Achin Gupta9a0ff9b2015-09-07 20:43:27 +0100255tsp_args_t *tsp_cpu_resume_main(uint64_t max_off_pwrlvl,
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000256 uint64_t arg1,
257 uint64_t arg2,
258 uint64_t arg3,
259 uint64_t arg4,
260 uint64_t arg5,
261 uint64_t arg6,
262 uint64_t arg7)
263{
Soby Mathewda43b662015-07-08 21:45:46 +0100264 uint32_t linear_id = plat_my_core_pos();
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000265
Achin Guptabbc33f22014-05-09 13:33:42 +0100266 /* Restore the generic timer context */
267 tsp_generic_timer_restore();
268
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000269 /* Update this cpu's statistics */
270 tsp_stats[linear_id].smc_count++;
271 tsp_stats[linear_id].eret_count++;
272 tsp_stats[linear_id].cpu_resume_count++;
273
Dan Handley91b624e2014-07-29 17:14:00 +0100274#if LOG_LEVEL >= LOG_LEVEL_INFO
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000275 spin_lock(&console_lock);
Scott Brandene5dcf982020-08-25 13:49:32 -0700276 INFO("TSP: cpu 0x%lx resumed. maximum off power level %" PRId64 "\n",
Achin Gupta9a0ff9b2015-09-07 20:43:27 +0100277 read_mpidr(), max_off_pwrlvl);
Manish Pandeyc4b47a22020-03-06 14:36:25 +0000278 INFO("TSP: cpu 0x%lx: %d smcs, %d erets %d cpu resume requests\n",
Soby Mathewda43b662015-07-08 21:45:46 +0100279 read_mpidr(),
Dan Handley91b624e2014-07-29 17:14:00 +0100280 tsp_stats[linear_id].smc_count,
281 tsp_stats[linear_id].eret_count,
Manish Pandeyc4b47a22020-03-06 14:36:25 +0000282 tsp_stats[linear_id].cpu_resume_count);
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000283 spin_unlock(&console_lock);
Dan Handley91b624e2014-07-29 17:14:00 +0100284#endif
Achin Gupta607084e2014-02-09 18:24:19 +0000285 /* Indicate to the SPD that we have completed this request */
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000286 return set_smc_args(TSP_RESUME_DONE, 0, 0, 0, 0, 0, 0, 0);
287}
288
289/*******************************************************************************
Juan Castillo4dc4a472014-08-12 11:17:06 +0100290 * This function performs any remaining bookkeeping in the test secure payload
291 * before the system is switched off (in response to a psci SYSTEM_OFF request)
292 ******************************************************************************/
293tsp_args_t *tsp_system_off_main(uint64_t arg0,
294 uint64_t arg1,
295 uint64_t arg2,
296 uint64_t arg3,
297 uint64_t arg4,
298 uint64_t arg5,
299 uint64_t arg6,
300 uint64_t arg7)
301{
Soby Mathewda43b662015-07-08 21:45:46 +0100302 uint32_t linear_id = plat_my_core_pos();
Juan Castillo4dc4a472014-08-12 11:17:06 +0100303
304 /* Update this cpu's statistics */
305 tsp_stats[linear_id].smc_count++;
306 tsp_stats[linear_id].eret_count++;
307
308#if LOG_LEVEL >= LOG_LEVEL_INFO
309 spin_lock(&console_lock);
Soby Mathewda43b662015-07-08 21:45:46 +0100310 INFO("TSP: cpu 0x%lx SYSTEM_OFF request\n", read_mpidr());
311 INFO("TSP: cpu 0x%lx: %d smcs, %d erets requests\n", read_mpidr(),
Juan Castillo4dc4a472014-08-12 11:17:06 +0100312 tsp_stats[linear_id].smc_count,
313 tsp_stats[linear_id].eret_count);
314 spin_unlock(&console_lock);
315#endif
316
317 /* Indicate to the SPD that we have completed this request */
318 return set_smc_args(TSP_SYSTEM_OFF_DONE, 0, 0, 0, 0, 0, 0, 0);
319}
320
321/*******************************************************************************
322 * This function performs any remaining bookkeeping in the test secure payload
323 * before the system is reset (in response to a psci SYSTEM_RESET request)
324 ******************************************************************************/
325tsp_args_t *tsp_system_reset_main(uint64_t arg0,
326 uint64_t arg1,
327 uint64_t arg2,
328 uint64_t arg3,
329 uint64_t arg4,
330 uint64_t arg5,
331 uint64_t arg6,
332 uint64_t arg7)
333{
Soby Mathewda43b662015-07-08 21:45:46 +0100334 uint32_t linear_id = plat_my_core_pos();
Juan Castillo4dc4a472014-08-12 11:17:06 +0100335
336 /* Update this cpu's statistics */
337 tsp_stats[linear_id].smc_count++;
338 tsp_stats[linear_id].eret_count++;
339
340#if LOG_LEVEL >= LOG_LEVEL_INFO
341 spin_lock(&console_lock);
Soby Mathewda43b662015-07-08 21:45:46 +0100342 INFO("TSP: cpu 0x%lx SYSTEM_RESET request\n", read_mpidr());
343 INFO("TSP: cpu 0x%lx: %d smcs, %d erets requests\n", read_mpidr(),
Juan Castillo4dc4a472014-08-12 11:17:06 +0100344 tsp_stats[linear_id].smc_count,
345 tsp_stats[linear_id].eret_count);
346 spin_unlock(&console_lock);
347#endif
348
349 /* Indicate to the SPD that we have completed this request */
350 return set_smc_args(TSP_SYSTEM_RESET_DONE, 0, 0, 0, 0, 0, 0, 0);
351}
352
353/*******************************************************************************
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000354 * TSP fast smc handler. The secure monitor jumps to this function by
355 * doing the ERET after populating X0-X7 registers. The arguments are received
356 * in the function arguments in order. Once the service is rendered, this
Soby Mathew9f71f702014-05-09 20:49:17 +0100357 * function returns to Secure Monitor by raising SMC.
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000358 ******************************************************************************/
Soby Mathew9f71f702014-05-09 20:49:17 +0100359tsp_args_t *tsp_smc_handler(uint64_t func,
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000360 uint64_t arg1,
361 uint64_t arg2,
362 uint64_t arg3,
363 uint64_t arg4,
364 uint64_t arg5,
365 uint64_t arg6,
366 uint64_t arg7)
367{
Alexei Fedorov7d616ee2020-11-13 12:36:49 +0000368 uint128_t service_args;
369 uint64_t service_arg0;
370 uint64_t service_arg1;
Achin Gupta916a2c12014-02-09 23:11:46 +0000371 uint64_t results[2];
Soby Mathewda43b662015-07-08 21:45:46 +0100372 uint32_t linear_id = plat_my_core_pos();
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000373
Achin Gupta916a2c12014-02-09 23:11:46 +0000374 /* Update this cpu's statistics */
375 tsp_stats[linear_id].smc_count++;
376 tsp_stats[linear_id].eret_count++;
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000377
Madhukar Pappireddy2598c412020-03-20 01:46:21 -0500378#if LOG_LEVEL >= LOG_LEVEL_INFO
379 spin_lock(&console_lock);
Scott Brandene5dcf982020-08-25 13:49:32 -0700380 INFO("TSP: cpu 0x%lx received %s smc 0x%" PRIx64 "\n", read_mpidr(),
David Cunado28f69ab2017-04-05 11:34:03 +0100381 ((func >> 31) & 1) == 1 ? "fast" : "yielding",
Dan Handley91b624e2014-07-29 17:14:00 +0100382 func);
Soby Mathewda43b662015-07-08 21:45:46 +0100383 INFO("TSP: cpu 0x%lx: %d smcs, %d erets\n", read_mpidr(),
Dan Handley91b624e2014-07-29 17:14:00 +0100384 tsp_stats[linear_id].smc_count,
385 tsp_stats[linear_id].eret_count);
Madhukar Pappireddy2598c412020-03-20 01:46:21 -0500386 spin_unlock(&console_lock);
387#endif
Achin Gupta916a2c12014-02-09 23:11:46 +0000388
389 /* Render secure services and obtain results here */
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000390 results[0] = arg1;
391 results[1] = arg2;
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000392
393 /*
Alexei Fedorov7d616ee2020-11-13 12:36:49 +0000394 * Request a service back from dispatcher/secure monitor.
395 * This call returns and thereafter resumes execution.
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000396 */
Alexei Fedorov7d616ee2020-11-13 12:36:49 +0000397 service_args = tsp_get_magic();
398 service_arg0 = (uint64_t)service_args;
399 service_arg1 = (uint64_t)(service_args >> 64U);
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000400
Justin Chadwell1c7c13a2019-07-18 14:25:33 +0100401#if CTX_INCLUDE_MTE_REGS
402 /*
403 * Write a dummy value to an MTE register, to simulate usage in the
404 * secure world
405 */
406 write_gcr_el1(0x99);
407#endif
408
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000409 /* Determine the function to perform based on the function ID */
Soby Mathew9f71f702014-05-09 20:49:17 +0100410 switch (TSP_BARE_FID(func)) {
411 case TSP_ADD:
Alexei Fedorov7d616ee2020-11-13 12:36:49 +0000412 results[0] += service_arg0;
413 results[1] += service_arg1;
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000414 break;
Soby Mathew9f71f702014-05-09 20:49:17 +0100415 case TSP_SUB:
Alexei Fedorov7d616ee2020-11-13 12:36:49 +0000416 results[0] -= service_arg0;
417 results[1] -= service_arg1;
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000418 break;
Soby Mathew9f71f702014-05-09 20:49:17 +0100419 case TSP_MUL:
Alexei Fedorov7d616ee2020-11-13 12:36:49 +0000420 results[0] *= service_arg0;
421 results[1] *= service_arg1;
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000422 break;
Soby Mathew9f71f702014-05-09 20:49:17 +0100423 case TSP_DIV:
Alexei Fedorov7d616ee2020-11-13 12:36:49 +0000424 results[0] /= service_arg0 ? service_arg0 : 1;
425 results[1] /= service_arg1 ? service_arg1 : 1;
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000426 break;
427 default:
428 break;
429 }
430
Soby Mathew9f71f702014-05-09 20:49:17 +0100431 return set_smc_args(func, 0,
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000432 results[0],
433 results[1],
Soby Mathew9f71f702014-05-09 20:49:17 +0100434 0, 0, 0, 0);
Achin Gupta7c88f3f2014-02-18 18:09:12 +0000435}
436
Douglas Raillardf2129652016-11-24 15:43:19 +0000437/*******************************************************************************
Paul Beesley1fbc97b2019-01-11 18:26:51 +0000438 * TSP smc abort handler. This function is called when aborting a preempted
David Cunado28f69ab2017-04-05 11:34:03 +0100439 * yielding SMC request. It should cleanup all resources owned by the SMC
Douglas Raillardf2129652016-11-24 15:43:19 +0000440 * handler such as locks or dynamically allocated memory so following SMC
441 * request are executed in a clean environment.
442 ******************************************************************************/
443tsp_args_t *tsp_abort_smc_handler(uint64_t func,
444 uint64_t arg1,
445 uint64_t arg2,
446 uint64_t arg3,
447 uint64_t arg4,
448 uint64_t arg5,
449 uint64_t arg6,
450 uint64_t arg7)
451{
452 return set_smc_args(TSP_ABORT_DONE, 0, 0, 0, 0, 0, 0, 0);
453}