sam_secure.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (C) 2022, Microchip
  4. */
  5. #include <linux/arm-smccc.h>
  6. #include <linux/of.h>
  7. #include "sam_secure.h"
  8. static bool optee_available;
  9. #define SAM_SIP_SMC_STD_CALL_VAL(func_num) \
  10. ARM_SMCCC_CALL_VAL(ARM_SMCCC_STD_CALL, ARM_SMCCC_SMC_32, \
  11. ARM_SMCCC_OWNER_SIP, (func_num))
  12. struct arm_smccc_res sam_smccc_call(u32 fn, u32 arg0, u32 arg1)
  13. {
  14. struct arm_smccc_res res = {.a0 = -1};
  15. if (WARN_ON(!optee_available))
  16. return res;
  17. arm_smccc_smc(SAM_SIP_SMC_STD_CALL_VAL(fn), arg0, arg1, 0, 0, 0, 0, 0,
  18. &res);
  19. return res;
  20. }
  21. bool sam_linux_is_optee_available(void)
  22. {
  23. /* If optee has been detected, then we are running in normal world */
  24. return optee_available;
  25. }
  26. void __init sam_secure_init(void)
  27. {
  28. struct device_node *np;
  29. /*
  30. * We only check that the OP-TEE node is present and available. The
  31. * OP-TEE kernel driver is not needed for the type of interaction made
  32. * with OP-TEE here so the driver's status is not checked.
  33. */
  34. np = of_find_node_by_path("/firmware/optee");
  35. if (np && of_device_is_available(np))
  36. optee_available = true;
  37. of_node_put(np);
  38. if (optee_available)
  39. pr_info("Running under OP-TEE firmware\n");
  40. }