Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * Copyright (C) 2022, Microchip
0004  */
0005 
0006 #include <linux/arm-smccc.h>
0007 #include <linux/of.h>
0008 
0009 #include "sam_secure.h"
0010 
0011 static bool optee_available;
0012 
0013 #define SAM_SIP_SMC_STD_CALL_VAL(func_num) \
0014     ARM_SMCCC_CALL_VAL(ARM_SMCCC_STD_CALL, ARM_SMCCC_SMC_32, \
0015     ARM_SMCCC_OWNER_SIP, (func_num))
0016 
0017 struct arm_smccc_res sam_smccc_call(u32 fn, u32 arg0, u32 arg1)
0018 {
0019     struct arm_smccc_res res = {.a0 = -1};
0020 
0021     if (WARN_ON(!optee_available))
0022         return res;
0023 
0024     arm_smccc_smc(SAM_SIP_SMC_STD_CALL_VAL(fn), arg0, arg1, 0, 0, 0, 0, 0,
0025               &res);
0026 
0027     return res;
0028 }
0029 
0030 bool sam_linux_is_optee_available(void)
0031 {
0032     /* If optee has been detected, then we are running in normal world */
0033     return optee_available;
0034 }
0035 
0036 void __init sam_secure_init(void)
0037 {
0038     struct device_node *np;
0039 
0040     /*
0041      * We only check that the OP-TEE node is present and available. The
0042      * OP-TEE kernel driver is not needed for the type of interaction made
0043      * with OP-TEE here so the driver's status is not checked.
0044      */
0045     np = of_find_node_by_path("/firmware/optee");
0046     if (np && of_device_is_available(np))
0047         optee_available = true;
0048     of_node_put(np);
0049 
0050     if (optee_available)
0051         pr_info("Running under OP-TEE firmware\n");
0052 }