17c88f3f6SAchin Gupta /* 2fd650ff6SSoby Mathew * Copyright (c) 2013-2015, ARM Limited and Contributors. All rights reserved. 37c88f3f6SAchin Gupta * 47c88f3f6SAchin Gupta * Redistribution and use in source and binary forms, with or without 57c88f3f6SAchin Gupta * modification, are permitted provided that the following conditions are met: 67c88f3f6SAchin Gupta * 77c88f3f6SAchin Gupta * Redistributions of source code must retain the above copyright notice, this 87c88f3f6SAchin Gupta * list of conditions and the following disclaimer. 97c88f3f6SAchin Gupta * 107c88f3f6SAchin Gupta * Redistributions in binary form must reproduce the above copyright notice, 117c88f3f6SAchin Gupta * this list of conditions and the following disclaimer in the documentation 127c88f3f6SAchin Gupta * and/or other materials provided with the distribution. 137c88f3f6SAchin Gupta * 147c88f3f6SAchin Gupta * Neither the name of ARM nor the names of its contributors may be used 157c88f3f6SAchin Gupta * to endorse or promote products derived from this software without specific 167c88f3f6SAchin Gupta * prior written permission. 177c88f3f6SAchin Gupta * 187c88f3f6SAchin Gupta * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 197c88f3f6SAchin Gupta * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 207c88f3f6SAchin Gupta * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 217c88f3f6SAchin Gupta * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 227c88f3f6SAchin Gupta * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 237c88f3f6SAchin Gupta * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 247c88f3f6SAchin Gupta * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 257c88f3f6SAchin Gupta * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 267c88f3f6SAchin Gupta * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 277c88f3f6SAchin Gupta * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 287c88f3f6SAchin Gupta * POSSIBILITY OF SUCH DAMAGE. 297c88f3f6SAchin Gupta */ 307c88f3f6SAchin Gupta 317c88f3f6SAchin Gupta #include <arch_helpers.h> 3297043ac9SDan Handley #include <bl_common.h> 337c88f3f6SAchin Gupta #include <debug.h> 3497043ac9SDan Handley #include <platform.h> 355f0cdb05SDan Handley #include <platform_def.h> 365a06bb7eSDan Handley #include <platform_tsp.h> 377c88f3f6SAchin Gupta #include <spinlock.h> 3897043ac9SDan Handley #include <tsp.h> 39da0af78aSDan Handley #include "tsp_private.h" 407c88f3f6SAchin Gupta 416871c5d3SVikram Kanigiri 426871c5d3SVikram Kanigiri /******************************************************************************* 437c88f3f6SAchin Gupta * Lock to control access to the console 447c88f3f6SAchin Gupta ******************************************************************************/ 457c88f3f6SAchin Gupta spinlock_t console_lock; 467c88f3f6SAchin Gupta 477c88f3f6SAchin Gupta /******************************************************************************* 487c88f3f6SAchin Gupta * Per cpu data structure to populate parameters for an SMC in C code and use 497c88f3f6SAchin Gupta * a pointer to this structure in assembler code to populate x0-x7 507c88f3f6SAchin Gupta ******************************************************************************/ 51fb037bfbSDan Handley static tsp_args_t tsp_smc_args[PLATFORM_CORE_COUNT]; 527c88f3f6SAchin Gupta 537c88f3f6SAchin Gupta /******************************************************************************* 547c88f3f6SAchin Gupta * Per cpu data structure to keep track of TSP activity 557c88f3f6SAchin Gupta ******************************************************************************/ 566cf89021SAchin Gupta work_statistics_t tsp_stats[PLATFORM_CORE_COUNT]; 577c88f3f6SAchin Gupta 587c88f3f6SAchin Gupta /******************************************************************************* 596871c5d3SVikram Kanigiri * The BL32 memory footprint starts with an RO sections and ends 60ab8707e6SSoby Mathew * with the linker symbol __BL32_END__. Use it to find the memory size 616871c5d3SVikram Kanigiri ******************************************************************************/ 626871c5d3SVikram Kanigiri #define BL32_TOTAL_BASE (unsigned long)(&__RO_START__) 636871c5d3SVikram Kanigiri 64ab8707e6SSoby Mathew #define BL32_TOTAL_LIMIT (unsigned long)(&__BL32_END__) 656871c5d3SVikram Kanigiri 66fb037bfbSDan Handley static tsp_args_t *set_smc_args(uint64_t arg0, 677c88f3f6SAchin Gupta uint64_t arg1, 687c88f3f6SAchin Gupta uint64_t arg2, 697c88f3f6SAchin Gupta uint64_t arg3, 707c88f3f6SAchin Gupta uint64_t arg4, 717c88f3f6SAchin Gupta uint64_t arg5, 727c88f3f6SAchin Gupta uint64_t arg6, 737c88f3f6SAchin Gupta uint64_t arg7) 747c88f3f6SAchin Gupta { 757c88f3f6SAchin Gupta uint32_t linear_id; 76fb037bfbSDan Handley tsp_args_t *pcpu_smc_args; 777c88f3f6SAchin Gupta 787c88f3f6SAchin Gupta /* 797c88f3f6SAchin Gupta * Return to Secure Monitor by raising an SMC. The results of the 807c88f3f6SAchin Gupta * service are passed as an arguments to the SMC 817c88f3f6SAchin Gupta */ 82fd650ff6SSoby Mathew linear_id = plat_my_core_pos(); 837c88f3f6SAchin Gupta pcpu_smc_args = &tsp_smc_args[linear_id]; 847c88f3f6SAchin Gupta write_sp_arg(pcpu_smc_args, TSP_ARG0, arg0); 857c88f3f6SAchin Gupta write_sp_arg(pcpu_smc_args, TSP_ARG1, arg1); 867c88f3f6SAchin Gupta write_sp_arg(pcpu_smc_args, TSP_ARG2, arg2); 877c88f3f6SAchin Gupta write_sp_arg(pcpu_smc_args, TSP_ARG3, arg3); 887c88f3f6SAchin Gupta write_sp_arg(pcpu_smc_args, TSP_ARG4, arg4); 897c88f3f6SAchin Gupta write_sp_arg(pcpu_smc_args, TSP_ARG5, arg5); 907c88f3f6SAchin Gupta write_sp_arg(pcpu_smc_args, TSP_ARG6, arg6); 917c88f3f6SAchin Gupta write_sp_arg(pcpu_smc_args, TSP_ARG7, arg7); 927c88f3f6SAchin Gupta 937c88f3f6SAchin Gupta return pcpu_smc_args; 947c88f3f6SAchin Gupta } 957c88f3f6SAchin Gupta 967c88f3f6SAchin Gupta /******************************************************************************* 977c88f3f6SAchin Gupta * TSP main entry point where it gets the opportunity to initialize its secure 987c88f3f6SAchin Gupta * state/applications. Once the state is initialized, it must return to the 99399fb08fSAndrew Thoelke * SPD with a pointer to the 'tsp_vector_table' jump table. 1007c88f3f6SAchin Gupta ******************************************************************************/ 1017c88f3f6SAchin Gupta uint64_t tsp_main(void) 1027c88f3f6SAchin Gupta { 1036ad2e461SDan Handley NOTICE("TSP: %s\n", version_string); 1046ad2e461SDan Handley NOTICE("TSP: %s\n", build_message); 105dad25049SSandrine Bailleux INFO("TSP: Total memory base : 0x%lx\n", BL32_TOTAL_BASE); 106dad25049SSandrine Bailleux INFO("TSP: Total memory size : 0x%lx bytes\n", 107dad25049SSandrine Bailleux BL32_TOTAL_LIMIT - BL32_TOTAL_BASE); 1086ad2e461SDan Handley 109fd650ff6SSoby Mathew uint32_t linear_id = plat_my_core_pos(); 1107c88f3f6SAchin Gupta 1117c88f3f6SAchin Gupta /* Initialize the platform */ 1125a06bb7eSDan Handley tsp_platform_setup(); 1137c88f3f6SAchin Gupta 1147c88f3f6SAchin Gupta /* Initialize secure/applications state here */ 115a20a81e5SAchin Gupta tsp_generic_timer_start(); 1167c88f3f6SAchin Gupta 1177c88f3f6SAchin Gupta /* Update this cpu's statistics */ 1187c88f3f6SAchin Gupta tsp_stats[linear_id].smc_count++; 1197c88f3f6SAchin Gupta tsp_stats[linear_id].eret_count++; 1207c88f3f6SAchin Gupta tsp_stats[linear_id].cpu_on_count++; 1217c88f3f6SAchin Gupta 1226ad2e461SDan Handley #if LOG_LEVEL >= LOG_LEVEL_INFO 1237c88f3f6SAchin Gupta spin_lock(&console_lock); 124fd650ff6SSoby Mathew INFO("TSP: cpu 0x%lx: %d smcs, %d erets %d cpu on requests\n", 125fd650ff6SSoby Mathew read_mpidr(), 1267c88f3f6SAchin Gupta tsp_stats[linear_id].smc_count, 1277c88f3f6SAchin Gupta tsp_stats[linear_id].eret_count, 1287c88f3f6SAchin Gupta tsp_stats[linear_id].cpu_on_count); 1297c88f3f6SAchin Gupta spin_unlock(&console_lock); 1306ad2e461SDan Handley #endif 131399fb08fSAndrew Thoelke return (uint64_t) &tsp_vector_table; 1327c88f3f6SAchin Gupta } 1337c88f3f6SAchin Gupta 1347c88f3f6SAchin Gupta /******************************************************************************* 1357c88f3f6SAchin Gupta * This function performs any remaining book keeping in the test secure payload 1367c88f3f6SAchin Gupta * after this cpu's architectural state has been setup in response to an earlier 1377c88f3f6SAchin Gupta * psci cpu_on request. 1387c88f3f6SAchin Gupta ******************************************************************************/ 139fb037bfbSDan Handley tsp_args_t *tsp_cpu_on_main(void) 1407c88f3f6SAchin Gupta { 141fd650ff6SSoby Mathew uint32_t linear_id = plat_my_core_pos(); 1427c88f3f6SAchin Gupta 143a20a81e5SAchin Gupta /* Initialize secure/applications state here */ 144a20a81e5SAchin Gupta tsp_generic_timer_start(); 145a20a81e5SAchin Gupta 1467c88f3f6SAchin Gupta /* Update this cpu's statistics */ 1477c88f3f6SAchin Gupta tsp_stats[linear_id].smc_count++; 1487c88f3f6SAchin Gupta tsp_stats[linear_id].eret_count++; 1497c88f3f6SAchin Gupta tsp_stats[linear_id].cpu_on_count++; 1507c88f3f6SAchin Gupta 1516ad2e461SDan Handley #if LOG_LEVEL >= LOG_LEVEL_INFO 1527c88f3f6SAchin Gupta spin_lock(&console_lock); 153fd650ff6SSoby Mathew INFO("TSP: cpu 0x%lx turned on\n", read_mpidr()); 154fd650ff6SSoby Mathew INFO("TSP: cpu 0x%lx: %d smcs, %d erets %d cpu on requests\n", 155fd650ff6SSoby Mathew read_mpidr(), 1567c88f3f6SAchin Gupta tsp_stats[linear_id].smc_count, 1577c88f3f6SAchin Gupta tsp_stats[linear_id].eret_count, 1587c88f3f6SAchin Gupta tsp_stats[linear_id].cpu_on_count); 1597c88f3f6SAchin Gupta spin_unlock(&console_lock); 1606ad2e461SDan Handley #endif 1617c88f3f6SAchin Gupta /* Indicate to the SPD that we have completed turned ourselves on */ 1627c88f3f6SAchin Gupta return set_smc_args(TSP_ON_DONE, 0, 0, 0, 0, 0, 0, 0); 1637c88f3f6SAchin Gupta } 1647c88f3f6SAchin Gupta 1657c88f3f6SAchin Gupta /******************************************************************************* 1667c88f3f6SAchin Gupta * This function performs any remaining book keeping in the test secure payload 1677c88f3f6SAchin Gupta * before this cpu is turned off in response to a psci cpu_off request. 1687c88f3f6SAchin Gupta ******************************************************************************/ 169fb037bfbSDan Handley tsp_args_t *tsp_cpu_off_main(uint64_t arg0, 1707c88f3f6SAchin Gupta uint64_t arg1, 1717c88f3f6SAchin Gupta uint64_t arg2, 1727c88f3f6SAchin Gupta uint64_t arg3, 1737c88f3f6SAchin Gupta uint64_t arg4, 1747c88f3f6SAchin Gupta uint64_t arg5, 1757c88f3f6SAchin Gupta uint64_t arg6, 1767c88f3f6SAchin Gupta uint64_t arg7) 1777c88f3f6SAchin Gupta { 178fd650ff6SSoby Mathew uint32_t linear_id = plat_my_core_pos(); 1797c88f3f6SAchin Gupta 180a20a81e5SAchin Gupta /* 181a20a81e5SAchin Gupta * This cpu is being turned off, so disable the timer to prevent the 182a20a81e5SAchin Gupta * secure timer interrupt from interfering with power down. A pending 183a20a81e5SAchin Gupta * interrupt will be lost but we do not care as we are turning off. 184a20a81e5SAchin Gupta */ 185a20a81e5SAchin Gupta tsp_generic_timer_stop(); 186a20a81e5SAchin Gupta 1877c88f3f6SAchin Gupta /* Update this cpu's statistics */ 1887c88f3f6SAchin Gupta tsp_stats[linear_id].smc_count++; 1897c88f3f6SAchin Gupta tsp_stats[linear_id].eret_count++; 1907c88f3f6SAchin Gupta tsp_stats[linear_id].cpu_off_count++; 1917c88f3f6SAchin Gupta 1926ad2e461SDan Handley #if LOG_LEVEL >= LOG_LEVEL_INFO 1937c88f3f6SAchin Gupta spin_lock(&console_lock); 194fd650ff6SSoby Mathew INFO("TSP: cpu 0x%lx off request\n", read_mpidr()); 195fd650ff6SSoby Mathew INFO("TSP: cpu 0x%lx: %d smcs, %d erets %d cpu off requests\n", 196fd650ff6SSoby Mathew read_mpidr(), 1977c88f3f6SAchin Gupta tsp_stats[linear_id].smc_count, 1987c88f3f6SAchin Gupta tsp_stats[linear_id].eret_count, 1997c88f3f6SAchin Gupta tsp_stats[linear_id].cpu_off_count); 2007c88f3f6SAchin Gupta spin_unlock(&console_lock); 2016ad2e461SDan Handley #endif 2027c88f3f6SAchin Gupta 203607084eeSAchin Gupta /* Indicate to the SPD that we have completed this request */ 2047c88f3f6SAchin Gupta return set_smc_args(TSP_OFF_DONE, 0, 0, 0, 0, 0, 0, 0); 2057c88f3f6SAchin Gupta } 2067c88f3f6SAchin Gupta 2077c88f3f6SAchin Gupta /******************************************************************************* 2087c88f3f6SAchin Gupta * This function performs any book keeping in the test secure payload before 2097c88f3f6SAchin Gupta * this cpu's architectural state is saved in response to an earlier psci 2107c88f3f6SAchin Gupta * cpu_suspend request. 2117c88f3f6SAchin Gupta ******************************************************************************/ 21231244d74SSoby Mathew tsp_args_t *tsp_cpu_suspend_main(uint64_t arg0, 2137c88f3f6SAchin Gupta uint64_t arg1, 2147c88f3f6SAchin Gupta uint64_t arg2, 2157c88f3f6SAchin Gupta uint64_t arg3, 2167c88f3f6SAchin Gupta uint64_t arg4, 2177c88f3f6SAchin Gupta uint64_t arg5, 2187c88f3f6SAchin Gupta uint64_t arg6, 2197c88f3f6SAchin Gupta uint64_t arg7) 2207c88f3f6SAchin Gupta { 221fd650ff6SSoby Mathew uint32_t linear_id = plat_my_core_pos(); 2227c88f3f6SAchin Gupta 223a20a81e5SAchin Gupta /* 224a20a81e5SAchin Gupta * Save the time context and disable it to prevent the secure timer 225a20a81e5SAchin Gupta * interrupt from interfering with wakeup from the suspend state. 226a20a81e5SAchin Gupta */ 227a20a81e5SAchin Gupta tsp_generic_timer_save(); 228a20a81e5SAchin Gupta tsp_generic_timer_stop(); 229a20a81e5SAchin Gupta 2307c88f3f6SAchin Gupta /* Update this cpu's statistics */ 2317c88f3f6SAchin Gupta tsp_stats[linear_id].smc_count++; 2327c88f3f6SAchin Gupta tsp_stats[linear_id].eret_count++; 2337c88f3f6SAchin Gupta tsp_stats[linear_id].cpu_suspend_count++; 2347c88f3f6SAchin Gupta 2356ad2e461SDan Handley #if LOG_LEVEL >= LOG_LEVEL_INFO 2367c88f3f6SAchin Gupta spin_lock(&console_lock); 237dad25049SSandrine Bailleux INFO("TSP: cpu 0x%lx: %d smcs, %d erets %d cpu suspend requests\n", 238fd650ff6SSoby Mathew read_mpidr(), 2397c88f3f6SAchin Gupta tsp_stats[linear_id].smc_count, 2407c88f3f6SAchin Gupta tsp_stats[linear_id].eret_count, 2417c88f3f6SAchin Gupta tsp_stats[linear_id].cpu_suspend_count); 2427c88f3f6SAchin Gupta spin_unlock(&console_lock); 2436ad2e461SDan Handley #endif 2447c88f3f6SAchin Gupta 245607084eeSAchin Gupta /* Indicate to the SPD that we have completed this request */ 2467c88f3f6SAchin Gupta return set_smc_args(TSP_SUSPEND_DONE, 0, 0, 0, 0, 0, 0, 0); 2477c88f3f6SAchin Gupta } 2487c88f3f6SAchin Gupta 2497c88f3f6SAchin Gupta /******************************************************************************* 2507c88f3f6SAchin Gupta * This function performs any book keeping in the test secure payload after this 2517c88f3f6SAchin Gupta * cpu's architectural state has been restored after wakeup from an earlier psci 2527c88f3f6SAchin Gupta * cpu_suspend request. 2537c88f3f6SAchin Gupta ******************************************************************************/ 254*f1054c93SAchin Gupta tsp_args_t *tsp_cpu_resume_main(uint64_t max_off_pwrlvl, 2557c88f3f6SAchin Gupta uint64_t arg1, 2567c88f3f6SAchin Gupta uint64_t arg2, 2577c88f3f6SAchin Gupta uint64_t arg3, 2587c88f3f6SAchin Gupta uint64_t arg4, 2597c88f3f6SAchin Gupta uint64_t arg5, 2607c88f3f6SAchin Gupta uint64_t arg6, 2617c88f3f6SAchin Gupta uint64_t arg7) 2627c88f3f6SAchin Gupta { 263fd650ff6SSoby Mathew uint32_t linear_id = plat_my_core_pos(); 2647c88f3f6SAchin Gupta 265a20a81e5SAchin Gupta /* Restore the generic timer context */ 266a20a81e5SAchin Gupta tsp_generic_timer_restore(); 267a20a81e5SAchin Gupta 2687c88f3f6SAchin Gupta /* Update this cpu's statistics */ 2697c88f3f6SAchin Gupta tsp_stats[linear_id].smc_count++; 2707c88f3f6SAchin Gupta tsp_stats[linear_id].eret_count++; 2717c88f3f6SAchin Gupta tsp_stats[linear_id].cpu_resume_count++; 2727c88f3f6SAchin Gupta 2736ad2e461SDan Handley #if LOG_LEVEL >= LOG_LEVEL_INFO 2747c88f3f6SAchin Gupta spin_lock(&console_lock); 275*f1054c93SAchin Gupta INFO("TSP: cpu 0x%lx resumed. maximum off power level %ld\n", 276*f1054c93SAchin Gupta read_mpidr(), max_off_pwrlvl); 277dad25049SSandrine Bailleux INFO("TSP: cpu 0x%lx: %d smcs, %d erets %d cpu suspend requests\n", 278fd650ff6SSoby Mathew read_mpidr(), 2797c88f3f6SAchin Gupta tsp_stats[linear_id].smc_count, 2807c88f3f6SAchin Gupta tsp_stats[linear_id].eret_count, 2817c88f3f6SAchin Gupta tsp_stats[linear_id].cpu_suspend_count); 2827c88f3f6SAchin Gupta spin_unlock(&console_lock); 2836ad2e461SDan Handley #endif 284607084eeSAchin Gupta /* Indicate to the SPD that we have completed this request */ 2857c88f3f6SAchin Gupta return set_smc_args(TSP_RESUME_DONE, 0, 0, 0, 0, 0, 0, 0); 2867c88f3f6SAchin Gupta } 2877c88f3f6SAchin Gupta 2887c88f3f6SAchin Gupta /******************************************************************************* 289d5f13093SJuan Castillo * This function performs any remaining bookkeeping in the test secure payload 290d5f13093SJuan Castillo * before the system is switched off (in response to a psci SYSTEM_OFF request) 291d5f13093SJuan Castillo ******************************************************************************/ 292d5f13093SJuan Castillo tsp_args_t *tsp_system_off_main(uint64_t arg0, 293d5f13093SJuan Castillo uint64_t arg1, 294d5f13093SJuan Castillo uint64_t arg2, 295d5f13093SJuan Castillo uint64_t arg3, 296d5f13093SJuan Castillo uint64_t arg4, 297d5f13093SJuan Castillo uint64_t arg5, 298d5f13093SJuan Castillo uint64_t arg6, 299d5f13093SJuan Castillo uint64_t arg7) 300d5f13093SJuan Castillo { 301fd650ff6SSoby Mathew uint32_t linear_id = plat_my_core_pos(); 302d5f13093SJuan Castillo 303d5f13093SJuan Castillo /* Update this cpu's statistics */ 304d5f13093SJuan Castillo tsp_stats[linear_id].smc_count++; 305d5f13093SJuan Castillo tsp_stats[linear_id].eret_count++; 306d5f13093SJuan Castillo 307d5f13093SJuan Castillo #if LOG_LEVEL >= LOG_LEVEL_INFO 308d5f13093SJuan Castillo spin_lock(&console_lock); 309fd650ff6SSoby Mathew INFO("TSP: cpu 0x%lx SYSTEM_OFF request\n", read_mpidr()); 310fd650ff6SSoby Mathew INFO("TSP: cpu 0x%lx: %d smcs, %d erets requests\n", read_mpidr(), 311d5f13093SJuan Castillo tsp_stats[linear_id].smc_count, 312d5f13093SJuan Castillo tsp_stats[linear_id].eret_count); 313d5f13093SJuan Castillo spin_unlock(&console_lock); 314d5f13093SJuan Castillo #endif 315d5f13093SJuan Castillo 316d5f13093SJuan Castillo /* Indicate to the SPD that we have completed this request */ 317d5f13093SJuan Castillo return set_smc_args(TSP_SYSTEM_OFF_DONE, 0, 0, 0, 0, 0, 0, 0); 318d5f13093SJuan Castillo } 319d5f13093SJuan Castillo 320d5f13093SJuan Castillo /******************************************************************************* 321d5f13093SJuan Castillo * This function performs any remaining bookkeeping in the test secure payload 322d5f13093SJuan Castillo * before the system is reset (in response to a psci SYSTEM_RESET request) 323d5f13093SJuan Castillo ******************************************************************************/ 324d5f13093SJuan Castillo tsp_args_t *tsp_system_reset_main(uint64_t arg0, 325d5f13093SJuan Castillo uint64_t arg1, 326d5f13093SJuan Castillo uint64_t arg2, 327d5f13093SJuan Castillo uint64_t arg3, 328d5f13093SJuan Castillo uint64_t arg4, 329d5f13093SJuan Castillo uint64_t arg5, 330d5f13093SJuan Castillo uint64_t arg6, 331d5f13093SJuan Castillo uint64_t arg7) 332d5f13093SJuan Castillo { 333fd650ff6SSoby Mathew uint32_t linear_id = plat_my_core_pos(); 334d5f13093SJuan Castillo 335d5f13093SJuan Castillo /* Update this cpu's statistics */ 336d5f13093SJuan Castillo tsp_stats[linear_id].smc_count++; 337d5f13093SJuan Castillo tsp_stats[linear_id].eret_count++; 338d5f13093SJuan Castillo 339d5f13093SJuan Castillo #if LOG_LEVEL >= LOG_LEVEL_INFO 340d5f13093SJuan Castillo spin_lock(&console_lock); 341fd650ff6SSoby Mathew INFO("TSP: cpu 0x%lx SYSTEM_RESET request\n", read_mpidr()); 342fd650ff6SSoby Mathew INFO("TSP: cpu 0x%lx: %d smcs, %d erets requests\n", read_mpidr(), 343d5f13093SJuan Castillo tsp_stats[linear_id].smc_count, 344d5f13093SJuan Castillo tsp_stats[linear_id].eret_count); 345d5f13093SJuan Castillo spin_unlock(&console_lock); 346d5f13093SJuan Castillo #endif 347d5f13093SJuan Castillo 348d5f13093SJuan Castillo /* Indicate to the SPD that we have completed this request */ 349d5f13093SJuan Castillo return set_smc_args(TSP_SYSTEM_RESET_DONE, 0, 0, 0, 0, 0, 0, 0); 350d5f13093SJuan Castillo } 351d5f13093SJuan Castillo 352d5f13093SJuan Castillo /******************************************************************************* 3537c88f3f6SAchin Gupta * TSP fast smc handler. The secure monitor jumps to this function by 3547c88f3f6SAchin Gupta * doing the ERET after populating X0-X7 registers. The arguments are received 3557c88f3f6SAchin Gupta * in the function arguments in order. Once the service is rendered, this 356239b04faSSoby Mathew * function returns to Secure Monitor by raising SMC. 3577c88f3f6SAchin Gupta ******************************************************************************/ 358239b04faSSoby Mathew tsp_args_t *tsp_smc_handler(uint64_t func, 3597c88f3f6SAchin Gupta uint64_t arg1, 3607c88f3f6SAchin Gupta uint64_t arg2, 3617c88f3f6SAchin Gupta uint64_t arg3, 3627c88f3f6SAchin Gupta uint64_t arg4, 3637c88f3f6SAchin Gupta uint64_t arg5, 3647c88f3f6SAchin Gupta uint64_t arg6, 3657c88f3f6SAchin Gupta uint64_t arg7) 3667c88f3f6SAchin Gupta { 367916a2c1eSAchin Gupta uint64_t results[2]; 368916a2c1eSAchin Gupta uint64_t service_args[2]; 369fd650ff6SSoby Mathew uint32_t linear_id = plat_my_core_pos(); 3707c88f3f6SAchin Gupta 371916a2c1eSAchin Gupta /* Update this cpu's statistics */ 372916a2c1eSAchin Gupta tsp_stats[linear_id].smc_count++; 373916a2c1eSAchin Gupta tsp_stats[linear_id].eret_count++; 3747c88f3f6SAchin Gupta 375fd650ff6SSoby Mathew INFO("TSP: cpu 0x%lx received %s smc 0x%lx\n", read_mpidr(), 3766ad2e461SDan Handley ((func >> 31) & 1) == 1 ? "fast" : "standard", 3776ad2e461SDan Handley func); 378fd650ff6SSoby Mathew INFO("TSP: cpu 0x%lx: %d smcs, %d erets\n", read_mpidr(), 379916a2c1eSAchin Gupta tsp_stats[linear_id].smc_count, 380916a2c1eSAchin Gupta tsp_stats[linear_id].eret_count); 381916a2c1eSAchin Gupta 382916a2c1eSAchin Gupta /* Render secure services and obtain results here */ 3837c88f3f6SAchin Gupta results[0] = arg1; 3847c88f3f6SAchin Gupta results[1] = arg2; 3857c88f3f6SAchin Gupta 3867c88f3f6SAchin Gupta /* 3877c88f3f6SAchin Gupta * Request a service back from dispatcher/secure monitor. This call 3887c88f3f6SAchin Gupta * return and thereafter resume exectuion 3897c88f3f6SAchin Gupta */ 3907c88f3f6SAchin Gupta tsp_get_magic(service_args); 3917c88f3f6SAchin Gupta 3927c88f3f6SAchin Gupta /* Determine the function to perform based on the function ID */ 393239b04faSSoby Mathew switch (TSP_BARE_FID(func)) { 394239b04faSSoby Mathew case TSP_ADD: 3957c88f3f6SAchin Gupta results[0] += service_args[0]; 3967c88f3f6SAchin Gupta results[1] += service_args[1]; 3977c88f3f6SAchin Gupta break; 398239b04faSSoby Mathew case TSP_SUB: 3997c88f3f6SAchin Gupta results[0] -= service_args[0]; 4007c88f3f6SAchin Gupta results[1] -= service_args[1]; 4017c88f3f6SAchin Gupta break; 402239b04faSSoby Mathew case TSP_MUL: 4037c88f3f6SAchin Gupta results[0] *= service_args[0]; 4047c88f3f6SAchin Gupta results[1] *= service_args[1]; 4057c88f3f6SAchin Gupta break; 406239b04faSSoby Mathew case TSP_DIV: 4077c88f3f6SAchin Gupta results[0] /= service_args[0] ? service_args[0] : 1; 4087c88f3f6SAchin Gupta results[1] /= service_args[1] ? service_args[1] : 1; 4097c88f3f6SAchin Gupta break; 4107c88f3f6SAchin Gupta default: 4117c88f3f6SAchin Gupta break; 4127c88f3f6SAchin Gupta } 4137c88f3f6SAchin Gupta 414239b04faSSoby Mathew return set_smc_args(func, 0, 4157c88f3f6SAchin Gupta results[0], 4167c88f3f6SAchin Gupta results[1], 417239b04faSSoby Mathew 0, 0, 0, 0); 4187c88f3f6SAchin Gupta } 4197c88f3f6SAchin Gupta 420