1 // SPDX-License-Identifier: BSD-2-Clause 2 /* 3 * Copyright (c) Microsoft Corporation. All rights reserved. 4 */ 5 6 #include <kernel/thread.h> 7 #include <sm/optee_smc.h> 8 #include <sm/sm.h> 9 #include <trace.h> 10 #include "imx_pl310.h" 11 12 #define IMX_SIP_PL310_ENABLE 1 13 #define IMX_SIP_PL310_DISABLE 2 14 #define IMX_SIP_PL310_ENABLE_WRITEBACK 3 15 #define IMX_SIP_PL310_DISABLE_WRITEBACK 4 16 #define IMX_SIP_PL310_ENABLE_WFLZ 5 17 imx_sip_handler(struct thread_smc_args * smc_args)18static enum sm_handler_ret imx_sip_handler(struct thread_smc_args *smc_args) 19 { 20 uint16_t sip_func = OPTEE_SMC_FUNC_NUM(smc_args->a0); 21 22 switch (sip_func) { 23 #ifdef CFG_PL310_SIP_PROTOCOL 24 case IMX_SIP_PL310_ENABLE: 25 smc_args->a0 = pl310_enable(); 26 break; 27 case IMX_SIP_PL310_DISABLE: 28 smc_args->a0 = pl310_disable(); 29 break; 30 case IMX_SIP_PL310_ENABLE_WRITEBACK: 31 smc_args->a0 = pl310_enable_writeback(); 32 break; 33 case IMX_SIP_PL310_DISABLE_WRITEBACK: 34 smc_args->a0 = pl310_disable_writeback(); 35 break; 36 case IMX_SIP_PL310_ENABLE_WFLZ: 37 smc_args->a0 = pl310_enable_wflz(); 38 break; 39 #endif 40 default: 41 EMSG("Invalid SIP function code: 0x%x", sip_func); 42 smc_args->a0 = OPTEE_SMC_RETURN_EBADCMD; 43 break; 44 } 45 46 return SM_HANDLER_SMC_HANDLED; 47 } 48 sm_platform_handler(struct sm_ctx * ctx)49enum sm_handler_ret sm_platform_handler(struct sm_ctx *ctx) 50 { 51 uint32_t *nsec_r0 = (uint32_t *)(&ctx->nsec.r0); 52 uint16_t smc_owner = OPTEE_SMC_OWNER_NUM(*nsec_r0); 53 54 switch (smc_owner) { 55 case OPTEE_SMC_OWNER_SIP: 56 return imx_sip_handler((struct thread_smc_args *)nsec_r0); 57 default: 58 return SM_HANDLER_PENDING_SMC; 59 } 60 } 61