1 // SPDX-License-Identifier: BSD-2-Clause 2 /* 3 * Copyright (c) 2016, Linaro Limited 4 * Copyright (c) 2014, STMicroelectronics International N.V. 5 */ 6 #include <arm.h> 7 #include <compiler.h> 8 #include <kernel/misc.h> 9 #include <platform_config.h> 10 #include <sm/optee_smc.h> 11 #include <sm/sm.h> 12 #include <sm/std_smc.h> 13 #include <string.h> 14 #include "sm_private.h" 15 16 bool sm_from_nsec(struct sm_ctx *ctx) 17 { 18 uint32_t *nsec_r0 = (uint32_t *)(&ctx->nsec.r0); 19 20 if (!sm_platform_handler(ctx)) 21 return false; 22 23 #ifdef CFG_PSCI_ARM32 24 if (OPTEE_SMC_OWNER_NUM(*nsec_r0) == OPTEE_SMC_OWNER_STANDARD) { 25 smc_std_handler((struct thread_smc_args *)nsec_r0, &ctx->nsec); 26 return false; /* Return to non secure state */ 27 } 28 #endif 29 30 sm_save_modes_regs(&ctx->nsec.mode_regs); 31 sm_restore_modes_regs(&ctx->sec.mode_regs); 32 33 memcpy(&ctx->sec.r0, nsec_r0, sizeof(uint32_t) * 8); 34 if (OPTEE_SMC_IS_FAST_CALL(ctx->sec.r0)) 35 ctx->sec.mon_lr = (uint32_t)&thread_vector_table.fast_smc_entry; 36 else 37 ctx->sec.mon_lr = (uint32_t)&thread_vector_table.std_smc_entry; 38 return true; /* return into secure state */ 39 } 40