Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are met: |
| 6 | * |
| 7 | * Redistributions of source code must retain the above copyright notice, this |
| 8 | * list of conditions and the following disclaimer. |
| 9 | * |
| 10 | * Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * Neither the name of ARM nor the names of its contributors may be used |
| 15 | * to endorse or promote products derived from this software without specific |
| 16 | * prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 28 | * POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 31 | #include <arch_helpers.h> |
Dan Handley | 2bd4ef2 | 2014-04-09 13:14:54 +0100 | [diff] [blame] | 32 | #include <bl_common.h> |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 33 | #include <debug.h> |
Dan Handley | 2bd4ef2 | 2014-04-09 13:14:54 +0100 | [diff] [blame] | 34 | #include <platform.h> |
Dan Handley | ed6ff95 | 2014-05-14 17:44:19 +0100 | [diff] [blame] | 35 | #include <platform_def.h> |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 36 | #include <spinlock.h> |
Dan Handley | 2bd4ef2 | 2014-04-09 13:14:54 +0100 | [diff] [blame] | 37 | #include <tsp.h> |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 38 | |
| 39 | /******************************************************************************* |
Vikram Kanigiri | d8c9d26 | 2014-05-16 18:48:12 +0100 | [diff] [blame] | 40 | * Declarations of linker defined symbols which will help us find the layout |
| 41 | * of trusted SRAM |
| 42 | ******************************************************************************/ |
| 43 | extern unsigned long __RO_START__; |
| 44 | extern unsigned long __COHERENT_RAM_END__; |
| 45 | |
| 46 | /******************************************************************************* |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 47 | * Lock to control access to the console |
| 48 | ******************************************************************************/ |
| 49 | spinlock_t console_lock; |
| 50 | |
| 51 | /******************************************************************************* |
| 52 | * Per cpu data structure to populate parameters for an SMC in C code and use |
| 53 | * a pointer to this structure in assembler code to populate x0-x7 |
| 54 | ******************************************************************************/ |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 55 | static tsp_args_t tsp_smc_args[PLATFORM_CORE_COUNT]; |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 56 | |
| 57 | /******************************************************************************* |
| 58 | * Per cpu data structure to keep track of TSP activity |
| 59 | ******************************************************************************/ |
Achin Gupta | 7671789 | 2014-05-09 11:42:56 +0100 | [diff] [blame] | 60 | work_statistics_t tsp_stats[PLATFORM_CORE_COUNT]; |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 61 | |
| 62 | /******************************************************************************* |
Vikram Kanigiri | d8c9d26 | 2014-05-16 18:48:12 +0100 | [diff] [blame] | 63 | * The BL32 memory footprint starts with an RO sections and ends |
| 64 | * with a section for coherent RAM. Use it to find the memory size |
| 65 | ******************************************************************************/ |
| 66 | #define BL32_TOTAL_BASE (unsigned long)(&__RO_START__) |
| 67 | |
| 68 | #define BL32_TOTAL_LIMIT (unsigned long)(&__COHERENT_RAM_END__) |
| 69 | |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 70 | static tsp_args_t *set_smc_args(uint64_t arg0, |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 71 | uint64_t arg1, |
| 72 | uint64_t arg2, |
| 73 | uint64_t arg3, |
| 74 | uint64_t arg4, |
| 75 | uint64_t arg5, |
| 76 | uint64_t arg6, |
| 77 | uint64_t arg7) |
| 78 | { |
| 79 | uint64_t mpidr = read_mpidr(); |
| 80 | uint32_t linear_id; |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 81 | tsp_args_t *pcpu_smc_args; |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 82 | |
| 83 | /* |
| 84 | * Return to Secure Monitor by raising an SMC. The results of the |
| 85 | * service are passed as an arguments to the SMC |
| 86 | */ |
| 87 | linear_id = platform_get_core_pos(mpidr); |
| 88 | pcpu_smc_args = &tsp_smc_args[linear_id]; |
| 89 | write_sp_arg(pcpu_smc_args, TSP_ARG0, arg0); |
| 90 | write_sp_arg(pcpu_smc_args, TSP_ARG1, arg1); |
| 91 | write_sp_arg(pcpu_smc_args, TSP_ARG2, arg2); |
| 92 | write_sp_arg(pcpu_smc_args, TSP_ARG3, arg3); |
| 93 | write_sp_arg(pcpu_smc_args, TSP_ARG4, arg4); |
| 94 | write_sp_arg(pcpu_smc_args, TSP_ARG5, arg5); |
| 95 | write_sp_arg(pcpu_smc_args, TSP_ARG6, arg6); |
| 96 | write_sp_arg(pcpu_smc_args, TSP_ARG7, arg7); |
| 97 | |
| 98 | return pcpu_smc_args; |
| 99 | } |
| 100 | |
| 101 | /******************************************************************************* |
| 102 | * TSP main entry point where it gets the opportunity to initialize its secure |
| 103 | * state/applications. Once the state is initialized, it must return to the |
Andrew Thoelke | 891c4ca | 2014-05-20 21:43:27 +0100 | [diff] [blame] | 104 | * SPD with a pointer to the 'tsp_vector_table' jump table. |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 105 | ******************************************************************************/ |
| 106 | uint64_t tsp_main(void) |
| 107 | { |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame^] | 108 | NOTICE("TSP: %s\n", version_string); |
| 109 | NOTICE("TSP: %s\n", build_message); |
| 110 | INFO("TSP: Total memory base : 0x%x\n", (unsigned long)BL32_TOTAL_BASE); |
| 111 | INFO("TSP: Total memory size : 0x%x bytes\n", |
| 112 | (unsigned long)(BL32_TOTAL_LIMIT - BL32_TOTAL_BASE)); |
| 113 | |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 114 | uint64_t mpidr = read_mpidr(); |
| 115 | uint32_t linear_id = platform_get_core_pos(mpidr); |
| 116 | |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 117 | /* Initialize the platform */ |
| 118 | bl32_platform_setup(); |
| 119 | |
| 120 | /* Initialize secure/applications state here */ |
Achin Gupta | bbc33f2 | 2014-05-09 13:33:42 +0100 | [diff] [blame] | 121 | tsp_generic_timer_start(); |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 122 | |
| 123 | /* Update this cpu's statistics */ |
| 124 | tsp_stats[linear_id].smc_count++; |
| 125 | tsp_stats[linear_id].eret_count++; |
| 126 | tsp_stats[linear_id].cpu_on_count++; |
| 127 | |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame^] | 128 | #if LOG_LEVEL >= LOG_LEVEL_INFO |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 129 | spin_lock(&console_lock); |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame^] | 130 | INFO("TSP: cpu 0x%x: %d smcs, %d erets %d cpu on requests\n", mpidr, |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 131 | tsp_stats[linear_id].smc_count, |
| 132 | tsp_stats[linear_id].eret_count, |
| 133 | tsp_stats[linear_id].cpu_on_count); |
| 134 | spin_unlock(&console_lock); |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame^] | 135 | #endif |
Andrew Thoelke | 891c4ca | 2014-05-20 21:43:27 +0100 | [diff] [blame] | 136 | return (uint64_t) &tsp_vector_table; |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | /******************************************************************************* |
| 140 | * This function performs any remaining book keeping in the test secure payload |
| 141 | * after this cpu's architectural state has been setup in response to an earlier |
| 142 | * psci cpu_on request. |
| 143 | ******************************************************************************/ |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 144 | tsp_args_t *tsp_cpu_on_main(void) |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 145 | { |
| 146 | uint64_t mpidr = read_mpidr(); |
| 147 | uint32_t linear_id = platform_get_core_pos(mpidr); |
| 148 | |
Achin Gupta | bbc33f2 | 2014-05-09 13:33:42 +0100 | [diff] [blame] | 149 | /* Initialize secure/applications state here */ |
| 150 | tsp_generic_timer_start(); |
| 151 | |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 152 | /* Update this cpu's statistics */ |
| 153 | tsp_stats[linear_id].smc_count++; |
| 154 | tsp_stats[linear_id].eret_count++; |
| 155 | tsp_stats[linear_id].cpu_on_count++; |
| 156 | |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame^] | 157 | #if LOG_LEVEL >= LOG_LEVEL_INFO |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 158 | spin_lock(&console_lock); |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame^] | 159 | INFO("TSP: cpu 0x%x turned on\n", mpidr); |
| 160 | INFO("TSP: cpu 0x%x: %d smcs, %d erets %d cpu on requests\n", mpidr, |
| 161 | tsp_stats[linear_id].smc_count, |
| 162 | tsp_stats[linear_id].eret_count, |
| 163 | tsp_stats[linear_id].cpu_on_count); |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 164 | spin_unlock(&console_lock); |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame^] | 165 | #endif |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 166 | /* Indicate to the SPD that we have completed turned ourselves on */ |
| 167 | return set_smc_args(TSP_ON_DONE, 0, 0, 0, 0, 0, 0, 0); |
| 168 | } |
| 169 | |
| 170 | /******************************************************************************* |
| 171 | * This function performs any remaining book keeping in the test secure payload |
| 172 | * before this cpu is turned off in response to a psci cpu_off request. |
| 173 | ******************************************************************************/ |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 174 | tsp_args_t *tsp_cpu_off_main(uint64_t arg0, |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 175 | uint64_t arg1, |
| 176 | uint64_t arg2, |
| 177 | uint64_t arg3, |
| 178 | uint64_t arg4, |
| 179 | uint64_t arg5, |
| 180 | uint64_t arg6, |
| 181 | uint64_t arg7) |
| 182 | { |
| 183 | uint64_t mpidr = read_mpidr(); |
| 184 | uint32_t linear_id = platform_get_core_pos(mpidr); |
| 185 | |
Achin Gupta | bbc33f2 | 2014-05-09 13:33:42 +0100 | [diff] [blame] | 186 | /* |
| 187 | * This cpu is being turned off, so disable the timer to prevent the |
| 188 | * secure timer interrupt from interfering with power down. A pending |
| 189 | * interrupt will be lost but we do not care as we are turning off. |
| 190 | */ |
| 191 | tsp_generic_timer_stop(); |
| 192 | |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 193 | /* Update this cpu's statistics */ |
| 194 | tsp_stats[linear_id].smc_count++; |
| 195 | tsp_stats[linear_id].eret_count++; |
| 196 | tsp_stats[linear_id].cpu_off_count++; |
| 197 | |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame^] | 198 | #if LOG_LEVEL >= LOG_LEVEL_INFO |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 199 | spin_lock(&console_lock); |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame^] | 200 | INFO("TSP: cpu 0x%x off request\n", mpidr); |
| 201 | INFO("TSP: cpu 0x%x: %d smcs, %d erets %d cpu off requests\n", mpidr, |
| 202 | tsp_stats[linear_id].smc_count, |
| 203 | tsp_stats[linear_id].eret_count, |
| 204 | tsp_stats[linear_id].cpu_off_count); |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 205 | spin_unlock(&console_lock); |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame^] | 206 | #endif |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 207 | |
Achin Gupta | 607084e | 2014-02-09 18:24:19 +0000 | [diff] [blame] | 208 | /* Indicate to the SPD that we have completed this request */ |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 209 | return set_smc_args(TSP_OFF_DONE, 0, 0, 0, 0, 0, 0, 0); |
| 210 | } |
| 211 | |
| 212 | /******************************************************************************* |
| 213 | * This function performs any book keeping in the test secure payload before |
| 214 | * this cpu's architectural state is saved in response to an earlier psci |
| 215 | * cpu_suspend request. |
| 216 | ******************************************************************************/ |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 217 | tsp_args_t *tsp_cpu_suspend_main(uint64_t power_state, |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 218 | uint64_t arg1, |
| 219 | uint64_t arg2, |
| 220 | uint64_t arg3, |
| 221 | uint64_t arg4, |
| 222 | uint64_t arg5, |
| 223 | uint64_t arg6, |
| 224 | uint64_t arg7) |
| 225 | { |
| 226 | uint64_t mpidr = read_mpidr(); |
| 227 | uint32_t linear_id = platform_get_core_pos(mpidr); |
| 228 | |
Achin Gupta | bbc33f2 | 2014-05-09 13:33:42 +0100 | [diff] [blame] | 229 | /* |
| 230 | * Save the time context and disable it to prevent the secure timer |
| 231 | * interrupt from interfering with wakeup from the suspend state. |
| 232 | */ |
| 233 | tsp_generic_timer_save(); |
| 234 | tsp_generic_timer_stop(); |
| 235 | |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 236 | /* Update this cpu's statistics */ |
| 237 | tsp_stats[linear_id].smc_count++; |
| 238 | tsp_stats[linear_id].eret_count++; |
| 239 | tsp_stats[linear_id].cpu_suspend_count++; |
| 240 | |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame^] | 241 | #if LOG_LEVEL >= LOG_LEVEL_INFO |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 242 | spin_lock(&console_lock); |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame^] | 243 | INFO("TSP: cpu 0x%x suspend request. power state: 0x%x\n", |
| 244 | mpidr, power_state); |
| 245 | INFO("TSP: cpu 0x%x: %d smcs, %d erets %d cpu suspend requests\n", |
| 246 | mpidr, |
| 247 | tsp_stats[linear_id].smc_count, |
| 248 | tsp_stats[linear_id].eret_count, |
| 249 | tsp_stats[linear_id].cpu_suspend_count); |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 250 | spin_unlock(&console_lock); |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame^] | 251 | #endif |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 252 | |
Achin Gupta | 607084e | 2014-02-09 18:24:19 +0000 | [diff] [blame] | 253 | /* Indicate to the SPD that we have completed this request */ |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 254 | return set_smc_args(TSP_SUSPEND_DONE, 0, 0, 0, 0, 0, 0, 0); |
| 255 | } |
| 256 | |
| 257 | /******************************************************************************* |
| 258 | * This function performs any book keeping in the test secure payload after this |
| 259 | * cpu's architectural state has been restored after wakeup from an earlier psci |
| 260 | * cpu_suspend request. |
| 261 | ******************************************************************************/ |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 262 | tsp_args_t *tsp_cpu_resume_main(uint64_t suspend_level, |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 263 | uint64_t arg1, |
| 264 | uint64_t arg2, |
| 265 | uint64_t arg3, |
| 266 | uint64_t arg4, |
| 267 | uint64_t arg5, |
| 268 | uint64_t arg6, |
| 269 | uint64_t arg7) |
| 270 | { |
| 271 | uint64_t mpidr = read_mpidr(); |
| 272 | uint32_t linear_id = platform_get_core_pos(mpidr); |
| 273 | |
Achin Gupta | bbc33f2 | 2014-05-09 13:33:42 +0100 | [diff] [blame] | 274 | /* Restore the generic timer context */ |
| 275 | tsp_generic_timer_restore(); |
| 276 | |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 277 | /* Update this cpu's statistics */ |
| 278 | tsp_stats[linear_id].smc_count++; |
| 279 | tsp_stats[linear_id].eret_count++; |
| 280 | tsp_stats[linear_id].cpu_resume_count++; |
| 281 | |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame^] | 282 | #if LOG_LEVEL >= LOG_LEVEL_INFO |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 283 | spin_lock(&console_lock); |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame^] | 284 | INFO("TSP: cpu 0x%x resumed. suspend level %d\n", |
| 285 | mpidr, suspend_level); |
| 286 | INFO("TSP: cpu 0x%x: %d smcs, %d erets %d cpu suspend requests\n", |
| 287 | mpidr, |
| 288 | tsp_stats[linear_id].smc_count, |
| 289 | tsp_stats[linear_id].eret_count, |
| 290 | tsp_stats[linear_id].cpu_suspend_count); |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 291 | spin_unlock(&console_lock); |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame^] | 292 | #endif |
Achin Gupta | 607084e | 2014-02-09 18:24:19 +0000 | [diff] [blame] | 293 | /* Indicate to the SPD that we have completed this request */ |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 294 | return set_smc_args(TSP_RESUME_DONE, 0, 0, 0, 0, 0, 0, 0); |
| 295 | } |
| 296 | |
| 297 | /******************************************************************************* |
| 298 | * TSP fast smc handler. The secure monitor jumps to this function by |
| 299 | * doing the ERET after populating X0-X7 registers. The arguments are received |
| 300 | * in the function arguments in order. Once the service is rendered, this |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 301 | * function returns to Secure Monitor by raising SMC. |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 302 | ******************************************************************************/ |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 303 | tsp_args_t *tsp_smc_handler(uint64_t func, |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 304 | uint64_t arg1, |
| 305 | uint64_t arg2, |
| 306 | uint64_t arg3, |
| 307 | uint64_t arg4, |
| 308 | uint64_t arg5, |
| 309 | uint64_t arg6, |
| 310 | uint64_t arg7) |
| 311 | { |
Achin Gupta | 916a2c1 | 2014-02-09 23:11:46 +0000 | [diff] [blame] | 312 | uint64_t results[2]; |
| 313 | uint64_t service_args[2]; |
| 314 | uint64_t mpidr = read_mpidr(); |
| 315 | uint32_t linear_id = platform_get_core_pos(mpidr); |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 316 | |
Achin Gupta | 916a2c1 | 2014-02-09 23:11:46 +0000 | [diff] [blame] | 317 | /* Update this cpu's statistics */ |
| 318 | tsp_stats[linear_id].smc_count++; |
| 319 | tsp_stats[linear_id].eret_count++; |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 320 | |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame^] | 321 | INFO("TSP: cpu 0x%x received %s smc 0x%x\n", read_mpidr(), |
| 322 | ((func >> 31) & 1) == 1 ? "fast" : "standard", |
| 323 | func); |
| 324 | INFO("TSP: cpu 0x%x: %d smcs, %d erets\n", mpidr, |
| 325 | tsp_stats[linear_id].smc_count, |
| 326 | tsp_stats[linear_id].eret_count); |
Achin Gupta | 916a2c1 | 2014-02-09 23:11:46 +0000 | [diff] [blame] | 327 | |
| 328 | /* Render secure services and obtain results here */ |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 329 | results[0] = arg1; |
| 330 | results[1] = arg2; |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 331 | |
| 332 | /* |
| 333 | * Request a service back from dispatcher/secure monitor. This call |
| 334 | * return and thereafter resume exectuion |
| 335 | */ |
| 336 | tsp_get_magic(service_args); |
| 337 | |
| 338 | /* Determine the function to perform based on the function ID */ |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 339 | switch (TSP_BARE_FID(func)) { |
| 340 | case TSP_ADD: |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 341 | results[0] += service_args[0]; |
| 342 | results[1] += service_args[1]; |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 343 | break; |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 344 | case TSP_SUB: |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 345 | results[0] -= service_args[0]; |
| 346 | results[1] -= service_args[1]; |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 347 | break; |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 348 | case TSP_MUL: |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 349 | results[0] *= service_args[0]; |
| 350 | results[1] *= service_args[1]; |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 351 | break; |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 352 | case TSP_DIV: |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 353 | results[0] /= service_args[0] ? service_args[0] : 1; |
| 354 | results[1] /= service_args[1] ? service_args[1] : 1; |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 355 | break; |
| 356 | default: |
| 357 | break; |
| 358 | } |
| 359 | |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 360 | return set_smc_args(func, 0, |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 361 | results[0], |
| 362 | results[1], |
Soby Mathew | 9f71f70 | 2014-05-09 20:49:17 +0100 | [diff] [blame] | 363 | 0, 0, 0, 0); |
Achin Gupta | 7c88f3f | 2014-02-18 18:09:12 +0000 | [diff] [blame] | 364 | } |
| 365 | |