Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 1 | /* |
Daniel Boulby | 60786e7 | 2021-10-22 11:37:34 +0100 | [diff] [blame] | 2 | * Copyright (c) 2013-2022, 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> |
Scott Branden | e5dcf98 | 2020-08-25 13:49:32 -0700 | [diff] [blame] | 8 | #include <inttypes.h> |
| 9 | #include <stdint.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 10 | |
Alexei Fedorov | f41355c | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 11 | #include <arch_features.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 12 | #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> |
Dan Handley | 4fd2f5c | 2014-08-04 11:41:20 +0100 | [diff] [blame] | 18 | #include <platform_tsp.h> |
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 | |
Achin Gupta | 6b4ec24 | 2021-10-04 20:13:36 +0100 | [diff] [blame] | 21 | #include <platform_def.h> |
Antonio Nino Diaz | e61ece0 | 2019-02-26 11:41:03 +0000 | [diff] [blame] | 22 | |
| 23 | /******************************************************************************* |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 24 | * TSP main entry point where it gets the opportunity to initialize its secure |
| 25 | * state/applications. Once the state is initialized, it must return to the |
Andrew Thoelke | 891c4ca | 2014-05-20 21:43:27 +0100 | [diff] [blame] | 26 | * SPD with a pointer to the 'tsp_vector_table' jump table. |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 27 | ******************************************************************************/ |
| 28 | uint64_t tsp_main(void) |
| 29 | { |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 30 | NOTICE("TSP: %s\n", version_string); |
| 31 | NOTICE("TSP: %s\n", build_message); |
Sandrine Bailleux | bdba5e5 | 2016-06-16 14:24:26 +0100 | [diff] [blame] | 32 | INFO("TSP: Total memory base : 0x%lx\n", (unsigned long) BL32_BASE); |
| 33 | INFO("TSP: Total memory size : 0x%lx bytes\n", BL32_TOTAL_SIZE); |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 34 | |
Soby Mathew | da43b66 | 2015-07-08 21:45:46 +0100 | [diff] [blame] | 35 | uint32_t linear_id = plat_my_core_pos(); |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 36 | |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 37 | /* Initialize the platform */ |
Dan Handley | 4fd2f5c | 2014-08-04 11:41:20 +0100 | [diff] [blame] | 38 | tsp_platform_setup(); |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 39 | |
| 40 | /* Initialize secure/applications state here */ |
Achin Gupta | bbc33f2 | 2014-05-09 13:33:42 +0100 | [diff] [blame] | 41 | tsp_generic_timer_start(); |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 42 | |
| 43 | /* Update this cpu's statistics */ |
| 44 | tsp_stats[linear_id].smc_count++; |
| 45 | tsp_stats[linear_id].eret_count++; |
| 46 | tsp_stats[linear_id].cpu_on_count++; |
| 47 | |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 48 | #if LOG_LEVEL >= LOG_LEVEL_INFO |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 49 | spin_lock(&console_lock); |
Soby Mathew | da43b66 | 2015-07-08 21:45:46 +0100 | [diff] [blame] | 50 | INFO("TSP: cpu 0x%lx: %d smcs, %d erets %d cpu on requests\n", |
| 51 | read_mpidr(), |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 52 | tsp_stats[linear_id].smc_count, |
| 53 | tsp_stats[linear_id].eret_count, |
| 54 | tsp_stats[linear_id].cpu_on_count); |
| 55 | spin_unlock(&console_lock); |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 56 | #endif |
Andrew Thoelke | 891c4ca | 2014-05-20 21:43:27 +0100 | [diff] [blame] | 57 | return (uint64_t) &tsp_vector_table; |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | /******************************************************************************* |
| 61 | * This function performs any remaining book keeping in the test secure payload |
| 62 | * after this cpu's architectural state has been setup in response to an earlier |
| 63 | * psci cpu_on request. |
| 64 | ******************************************************************************/ |
Achin Gupta | 6b4ec24 | 2021-10-04 20:13:36 +0100 | [diff] [blame] | 65 | smc_args_t *tsp_cpu_on_main(void) |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 66 | { |
Soby Mathew | da43b66 | 2015-07-08 21:45:46 +0100 | [diff] [blame] | 67 | uint32_t linear_id = plat_my_core_pos(); |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 68 | |
Achin Gupta | bbc33f2 | 2014-05-09 13:33:42 +0100 | [diff] [blame] | 69 | /* Initialize secure/applications state here */ |
| 70 | tsp_generic_timer_start(); |
| 71 | |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 72 | /* Update this cpu's statistics */ |
| 73 | tsp_stats[linear_id].smc_count++; |
| 74 | tsp_stats[linear_id].eret_count++; |
| 75 | tsp_stats[linear_id].cpu_on_count++; |
| 76 | |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 77 | #if LOG_LEVEL >= LOG_LEVEL_INFO |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 78 | spin_lock(&console_lock); |
Soby Mathew | da43b66 | 2015-07-08 21:45:46 +0100 | [diff] [blame] | 79 | INFO("TSP: cpu 0x%lx turned on\n", read_mpidr()); |
| 80 | INFO("TSP: cpu 0x%lx: %d smcs, %d erets %d cpu on requests\n", |
| 81 | read_mpidr(), |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 82 | tsp_stats[linear_id].smc_count, |
| 83 | tsp_stats[linear_id].eret_count, |
| 84 | tsp_stats[linear_id].cpu_on_count); |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 85 | spin_unlock(&console_lock); |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 86 | #endif |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 87 | /* Indicate to the SPD that we have completed turned ourselves on */ |
| 88 | return set_smc_args(TSP_ON_DONE, 0, 0, 0, 0, 0, 0, 0); |
| 89 | } |
| 90 | |
| 91 | /******************************************************************************* |
| 92 | * This function performs any remaining book keeping in the test secure payload |
| 93 | * before this cpu is turned off in response to a psci cpu_off request. |
| 94 | ******************************************************************************/ |
Achin Gupta | 6b4ec24 | 2021-10-04 20:13:36 +0100 | [diff] [blame] | 95 | smc_args_t *tsp_cpu_off_main(uint64_t arg0, |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 96 | uint64_t arg1, |
| 97 | uint64_t arg2, |
| 98 | uint64_t arg3, |
| 99 | uint64_t arg4, |
| 100 | uint64_t arg5, |
| 101 | uint64_t arg6, |
| 102 | uint64_t arg7) |
| 103 | { |
Soby Mathew | da43b66 | 2015-07-08 21:45:46 +0100 | [diff] [blame] | 104 | uint32_t linear_id = plat_my_core_pos(); |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 105 | |
Achin Gupta | bbc33f2 | 2014-05-09 13:33:42 +0100 | [diff] [blame] | 106 | /* |
| 107 | * This cpu is being turned off, so disable the timer to prevent the |
| 108 | * secure timer interrupt from interfering with power down. A pending |
| 109 | * interrupt will be lost but we do not care as we are turning off. |
| 110 | */ |
| 111 | tsp_generic_timer_stop(); |
| 112 | |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 113 | /* Update this cpu's statistics */ |
| 114 | tsp_stats[linear_id].smc_count++; |
| 115 | tsp_stats[linear_id].eret_count++; |
| 116 | tsp_stats[linear_id].cpu_off_count++; |
| 117 | |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 118 | #if LOG_LEVEL >= LOG_LEVEL_INFO |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 119 | spin_lock(&console_lock); |
Soby Mathew | da43b66 | 2015-07-08 21:45:46 +0100 | [diff] [blame] | 120 | INFO("TSP: cpu 0x%lx off request\n", read_mpidr()); |
| 121 | INFO("TSP: cpu 0x%lx: %d smcs, %d erets %d cpu off requests\n", |
| 122 | read_mpidr(), |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 123 | tsp_stats[linear_id].smc_count, |
| 124 | tsp_stats[linear_id].eret_count, |
| 125 | tsp_stats[linear_id].cpu_off_count); |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 126 | spin_unlock(&console_lock); |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 127 | #endif |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 128 | |
Achin Gupta | 607084e | 2014-02-09 18:24:19 +0000 | [diff] [blame] | 129 | /* Indicate to the SPD that we have completed this request */ |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 130 | return set_smc_args(TSP_OFF_DONE, 0, 0, 0, 0, 0, 0, 0); |
| 131 | } |
| 132 | |
| 133 | /******************************************************************************* |
| 134 | * This function performs any book keeping in the test secure payload before |
| 135 | * this cpu's architectural state is saved in response to an earlier psci |
| 136 | * cpu_suspend request. |
| 137 | ******************************************************************************/ |
Achin Gupta | 6b4ec24 | 2021-10-04 20:13:36 +0100 | [diff] [blame] | 138 | smc_args_t *tsp_cpu_suspend_main(uint64_t arg0, |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 139 | uint64_t arg1, |
| 140 | uint64_t arg2, |
| 141 | uint64_t arg3, |
| 142 | uint64_t arg4, |
| 143 | uint64_t arg5, |
| 144 | uint64_t arg6, |
| 145 | uint64_t arg7) |
| 146 | { |
Soby Mathew | da43b66 | 2015-07-08 21:45:46 +0100 | [diff] [blame] | 147 | uint32_t linear_id = plat_my_core_pos(); |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 148 | |
Achin Gupta | bbc33f2 | 2014-05-09 13:33:42 +0100 | [diff] [blame] | 149 | /* |
| 150 | * Save the time context and disable it to prevent the secure timer |
| 151 | * interrupt from interfering with wakeup from the suspend state. |
| 152 | */ |
| 153 | tsp_generic_timer_save(); |
| 154 | tsp_generic_timer_stop(); |
| 155 | |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 156 | /* Update this cpu's statistics */ |
| 157 | tsp_stats[linear_id].smc_count++; |
| 158 | tsp_stats[linear_id].eret_count++; |
| 159 | tsp_stats[linear_id].cpu_suspend_count++; |
| 160 | |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 161 | #if LOG_LEVEL >= LOG_LEVEL_INFO |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 162 | spin_lock(&console_lock); |
Sandrine Bailleux | 8723adf | 2015-02-05 15:42:31 +0000 | [diff] [blame] | 163 | 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] | 164 | read_mpidr(), |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 165 | tsp_stats[linear_id].smc_count, |
| 166 | tsp_stats[linear_id].eret_count, |
| 167 | tsp_stats[linear_id].cpu_suspend_count); |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 168 | spin_unlock(&console_lock); |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 169 | #endif |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 170 | |
Achin Gupta | 607084e | 2014-02-09 18:24:19 +0000 | [diff] [blame] | 171 | /* Indicate to the SPD that we have completed this request */ |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 172 | return set_smc_args(TSP_SUSPEND_DONE, 0, 0, 0, 0, 0, 0, 0); |
| 173 | } |
| 174 | |
| 175 | /******************************************************************************* |
| 176 | * This function performs any book keeping in the test secure payload after this |
| 177 | * cpu's architectural state has been restored after wakeup from an earlier psci |
| 178 | * cpu_suspend request. |
| 179 | ******************************************************************************/ |
Achin Gupta | 6b4ec24 | 2021-10-04 20:13:36 +0100 | [diff] [blame] | 180 | smc_args_t *tsp_cpu_resume_main(uint64_t max_off_pwrlvl, |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 181 | uint64_t arg1, |
| 182 | uint64_t arg2, |
| 183 | uint64_t arg3, |
| 184 | uint64_t arg4, |
| 185 | uint64_t arg5, |
| 186 | uint64_t arg6, |
| 187 | uint64_t arg7) |
| 188 | { |
Soby Mathew | da43b66 | 2015-07-08 21:45:46 +0100 | [diff] [blame] | 189 | uint32_t linear_id = plat_my_core_pos(); |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 190 | |
Achin Gupta | bbc33f2 | 2014-05-09 13:33:42 +0100 | [diff] [blame] | 191 | /* Restore the generic timer context */ |
| 192 | tsp_generic_timer_restore(); |
| 193 | |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 194 | /* Update this cpu's statistics */ |
| 195 | tsp_stats[linear_id].smc_count++; |
| 196 | tsp_stats[linear_id].eret_count++; |
| 197 | tsp_stats[linear_id].cpu_resume_count++; |
| 198 | |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 199 | #if LOG_LEVEL >= LOG_LEVEL_INFO |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 200 | spin_lock(&console_lock); |
Scott Branden | e5dcf98 | 2020-08-25 13:49:32 -0700 | [diff] [blame] | 201 | INFO("TSP: cpu 0x%lx resumed. maximum off power level %" PRId64 "\n", |
Achin Gupta | 9a0ff9b | 2015-09-07 20:43:27 +0100 | [diff] [blame] | 202 | read_mpidr(), max_off_pwrlvl); |
Manish Pandey | c4b47a2 | 2020-03-06 14:36:25 +0000 | [diff] [blame] | 203 | 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] | 204 | read_mpidr(), |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 205 | tsp_stats[linear_id].smc_count, |
| 206 | tsp_stats[linear_id].eret_count, |
Manish Pandey | c4b47a2 | 2020-03-06 14:36:25 +0000 | [diff] [blame] | 207 | tsp_stats[linear_id].cpu_resume_count); |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 208 | spin_unlock(&console_lock); |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 209 | #endif |
Achin Gupta | 607084e | 2014-02-09 18:24:19 +0000 | [diff] [blame] | 210 | /* Indicate to the SPD that we have completed this request */ |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 211 | return set_smc_args(TSP_RESUME_DONE, 0, 0, 0, 0, 0, 0, 0); |
| 212 | } |
| 213 | |
| 214 | /******************************************************************************* |
| 215 | * TSP fast smc handler. The secure monitor jumps to this function by |
| 216 | * doing the ERET after populating X0-X7 registers. The arguments are received |
| 217 | * in the function arguments in order. Once the service is rendered, this |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 218 | * function returns to Secure Monitor by raising SMC. |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 219 | ******************************************************************************/ |
Achin Gupta | 6b4ec24 | 2021-10-04 20:13:36 +0100 | [diff] [blame] | 220 | smc_args_t *tsp_smc_handler(uint64_t func, |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 221 | uint64_t arg1, |
| 222 | uint64_t arg2, |
| 223 | uint64_t arg3, |
| 224 | uint64_t arg4, |
| 225 | uint64_t arg5, |
| 226 | uint64_t arg6, |
| 227 | uint64_t arg7) |
| 228 | { |
Alexei Fedorov | 7d616ee | 2020-11-13 12:36:49 +0000 | [diff] [blame] | 229 | uint128_t service_args; |
| 230 | uint64_t service_arg0; |
| 231 | uint64_t service_arg1; |
Achin Gupta | 916a2c1 | 2014-02-09 23:11:46 +0000 | [diff] [blame] | 232 | uint64_t results[2]; |
Soby Mathew | da43b66 | 2015-07-08 21:45:46 +0100 | [diff] [blame] | 233 | uint32_t linear_id = plat_my_core_pos(); |
Daniel Boulby | 60786e7 | 2021-10-22 11:37:34 +0100 | [diff] [blame] | 234 | u_register_t dit; |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 235 | |
Achin Gupta | 916a2c1 | 2014-02-09 23:11:46 +0000 | [diff] [blame] | 236 | /* Update this cpu's statistics */ |
| 237 | tsp_stats[linear_id].smc_count++; |
| 238 | tsp_stats[linear_id].eret_count++; |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 239 | |
Madhukar Pappireddy | 2598c41 | 2020-03-20 01:46:21 -0500 | [diff] [blame] | 240 | #if LOG_LEVEL >= LOG_LEVEL_INFO |
| 241 | spin_lock(&console_lock); |
Scott Branden | e5dcf98 | 2020-08-25 13:49:32 -0700 | [diff] [blame] | 242 | INFO("TSP: cpu 0x%lx received %s smc 0x%" PRIx64 "\n", read_mpidr(), |
David Cunado | 28f69ab | 2017-04-05 11:34:03 +0100 | [diff] [blame] | 243 | ((func >> 31) & 1) == 1 ? "fast" : "yielding", |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 244 | func); |
Soby Mathew | da43b66 | 2015-07-08 21:45:46 +0100 | [diff] [blame] | 245 | INFO("TSP: cpu 0x%lx: %d smcs, %d erets\n", read_mpidr(), |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 246 | tsp_stats[linear_id].smc_count, |
| 247 | tsp_stats[linear_id].eret_count); |
Madhukar Pappireddy | 2598c41 | 2020-03-20 01:46:21 -0500 | [diff] [blame] | 248 | spin_unlock(&console_lock); |
| 249 | #endif |
Achin Gupta | 916a2c1 | 2014-02-09 23:11:46 +0000 | [diff] [blame] | 250 | |
| 251 | /* Render secure services and obtain results here */ |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 252 | results[0] = arg1; |
| 253 | results[1] = arg2; |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 254 | |
| 255 | /* |
Alexei Fedorov | 7d616ee | 2020-11-13 12:36:49 +0000 | [diff] [blame] | 256 | * Request a service back from dispatcher/secure monitor. |
| 257 | * This call returns and thereafter resumes execution. |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 258 | */ |
Alexei Fedorov | 7d616ee | 2020-11-13 12:36:49 +0000 | [diff] [blame] | 259 | service_args = tsp_get_magic(); |
| 260 | service_arg0 = (uint64_t)service_args; |
| 261 | service_arg1 = (uint64_t)(service_args >> 64U); |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 262 | |
Justin Chadwell | 1c7c13a | 2019-07-18 14:25:33 +0100 | [diff] [blame] | 263 | #if CTX_INCLUDE_MTE_REGS |
| 264 | /* |
| 265 | * Write a dummy value to an MTE register, to simulate usage in the |
| 266 | * secure world |
| 267 | */ |
| 268 | write_gcr_el1(0x99); |
| 269 | #endif |
| 270 | |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 271 | /* Determine the function to perform based on the function ID */ |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 272 | switch (TSP_BARE_FID(func)) { |
| 273 | case TSP_ADD: |
Alexei Fedorov | 7d616ee | 2020-11-13 12:36:49 +0000 | [diff] [blame] | 274 | results[0] += service_arg0; |
| 275 | results[1] += service_arg1; |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 276 | break; |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 277 | case TSP_SUB: |
Alexei Fedorov | 7d616ee | 2020-11-13 12:36:49 +0000 | [diff] [blame] | 278 | results[0] -= service_arg0; |
| 279 | results[1] -= service_arg1; |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 280 | break; |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 281 | case TSP_MUL: |
Alexei Fedorov | 7d616ee | 2020-11-13 12:36:49 +0000 | [diff] [blame] | 282 | results[0] *= service_arg0; |
| 283 | results[1] *= service_arg1; |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 284 | break; |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 285 | case TSP_DIV: |
Alexei Fedorov | 7d616ee | 2020-11-13 12:36:49 +0000 | [diff] [blame] | 286 | results[0] /= service_arg0 ? service_arg0 : 1; |
| 287 | results[1] /= service_arg1 ? service_arg1 : 1; |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 288 | break; |
Daniel Boulby | 60786e7 | 2021-10-22 11:37:34 +0100 | [diff] [blame] | 289 | case TSP_CHECK_DIT: |
| 290 | if (!is_armv8_4_dit_present()) { |
| 291 | #if LOG_LEVEL >= LOG_LEVEL_ERROR |
| 292 | spin_lock(&console_lock); |
| 293 | ERROR("DIT not supported\n"); |
| 294 | spin_unlock(&console_lock); |
| 295 | #endif |
| 296 | results[0] = 0; |
| 297 | results[1] = 0xffff; |
| 298 | break; |
| 299 | } |
| 300 | dit = read_dit(); |
| 301 | results[0] = dit == service_arg0; |
| 302 | results[1] = dit; |
| 303 | /* Toggle the dit bit */ |
| 304 | write_dit(service_arg0 != 0U ? 0 : DIT_BIT); |
| 305 | break; |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 306 | default: |
| 307 | break; |
| 308 | } |
| 309 | |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 310 | return set_smc_args(func, 0, |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 311 | results[0], |
| 312 | results[1], |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 313 | 0, 0, 0, 0); |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 314 | } |