arm_sip_svc.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * Copyright (c) 2016-2024, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <stdint.h>
  7. #include <common/debug.h>
  8. #include <common/runtime_svc.h>
  9. #include <drivers/arm/ethosn.h>
  10. #include <lib/debugfs.h>
  11. #include <lib/pmf/pmf.h>
  12. #include <plat/arm/common/arm_sip_svc.h>
  13. #include <plat/arm/common/plat_arm.h>
  14. #include <tools_share/uuid.h>
  15. /* ARM SiP Service UUID */
  16. DEFINE_SVC_UUID2(arm_sip_svc_uid,
  17. 0x556d75e2, 0x6033, 0xb54b, 0xb5, 0x75,
  18. 0x62, 0x79, 0xfd, 0x11, 0x37, 0xff);
  19. static int arm_sip_setup(void)
  20. {
  21. #if ENABLE_PMF
  22. if (pmf_setup() != 0) {
  23. return 1;
  24. }
  25. #endif /* ENABLE_PMF */
  26. #if USE_DEBUGFS
  27. if (debugfs_smc_setup() != 0) {
  28. return 1;
  29. }
  30. #endif /* USE_DEBUGFS */
  31. #if ETHOSN_NPU_DRIVER
  32. if (ethosn_smc_setup() != 0) {
  33. return 1;
  34. }
  35. #endif /* ETHOSN_NPU_DRIVER */
  36. return 0;
  37. }
  38. /*
  39. * This function handles ARM defined SiP Calls
  40. */
  41. static uintptr_t arm_sip_handler(unsigned int smc_fid,
  42. u_register_t x1,
  43. u_register_t x2,
  44. u_register_t x3,
  45. u_register_t x4,
  46. void *cookie,
  47. void *handle,
  48. u_register_t flags)
  49. {
  50. int call_count = 0;
  51. #if ENABLE_PMF
  52. /*
  53. * Dispatch PMF calls to PMF SMC handler and return its return
  54. * value
  55. */
  56. if (is_pmf_fid_deprecated(smc_fid)) {
  57. NOTICE("PMF Interface usage from arm-sip range is deprecated. \
  58. Please migrate smc call to Vendor-specific el3 range.\n");
  59. return pmf_smc_handler(smc_fid, x1, x2, x3, x4, cookie,
  60. handle, flags);
  61. }
  62. #endif /* ENABLE_PMF */
  63. #if USE_DEBUGFS
  64. if (is_debugfs_fid_deprecated(smc_fid)) {
  65. NOTICE("Debugfs Interface usage from arm-sip range is deprecated. \
  66. Please migrate smc call to vendor-specific el3 range.\n");
  67. return debugfs_smc_handler(smc_fid, x1, x2, x3, x4, cookie,
  68. handle, flags);
  69. }
  70. #endif /* USE_DEBUGFS */
  71. #if ETHOSN_NPU_DRIVER
  72. if (is_ethosn_fid(smc_fid)) {
  73. return ethosn_smc_handler(smc_fid, x1, x2, x3, x4, cookie,
  74. handle, flags);
  75. }
  76. #endif /* ETHOSN_NPU_DRIVER */
  77. switch (smc_fid) {
  78. case ARM_SIP_SVC_EXE_STATE_SWITCH: {
  79. /* Execution state can be switched only if EL3 is AArch64 */
  80. #ifdef __aarch64__
  81. /* Allow calls from non-secure only */
  82. if (!is_caller_non_secure(flags))
  83. SMC_RET1(handle, STATE_SW_E_DENIED);
  84. /*
  85. * Pointers used in execution state switch are all 32 bits wide
  86. */
  87. return (uintptr_t) arm_execution_state_switch(smc_fid,
  88. (uint32_t) x1, (uint32_t) x2, (uint32_t) x3,
  89. (uint32_t) x4, handle);
  90. #else
  91. /* State switch denied */
  92. SMC_RET1(handle, STATE_SW_E_DENIED);
  93. #endif /* __aarch64__ */
  94. }
  95. case ARM_SIP_SVC_CALL_COUNT:
  96. /* PMF calls */
  97. call_count += PMF_NUM_SMC_CALLS;
  98. #if ETHOSN_NPU_DRIVER
  99. /* ETHOSN calls */
  100. call_count += ETHOSN_NUM_SMC_CALLS;
  101. #endif /* ETHOSN_NPU_DRIVER */
  102. /* State switch call */
  103. call_count += 1;
  104. SMC_RET1(handle, call_count);
  105. case ARM_SIP_SVC_UID:
  106. /* Return UID to the caller */
  107. SMC_UUID_RET(handle, arm_sip_svc_uid);
  108. case ARM_SIP_SVC_VERSION:
  109. /* Return the version of current implementation */
  110. SMC_RET2(handle, ARM_SIP_SVC_VERSION_MAJOR, ARM_SIP_SVC_VERSION_MINOR);
  111. default:
  112. break;
  113. }
  114. /*
  115. * Fall back to allow Arm platform specific handler.
  116. * TODO: Refactor needed to move out generic handlers from this file and
  117. * only keep Arm Platform specific handlers here.
  118. */
  119. return plat_arm_sip_handler(smc_fid, x1, x2, x3, x4,
  120. cookie, handle, flags);
  121. }
  122. /* Define a runtime service descriptor for fast SMC calls */
  123. DECLARE_RT_SVC(
  124. arm_sip_svc,
  125. OEN_SIP_START,
  126. OEN_SIP_END,
  127. SMC_TYPE_FAST,
  128. arm_sip_setup,
  129. arm_sip_handler
  130. );