std_svc_setup.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /*
  2. * Copyright (c) 2014-2023, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <stdint.h>
  8. #include <common/debug.h>
  9. #include <common/runtime_svc.h>
  10. #include <lib/el3_runtime/cpu_data.h>
  11. #include <lib/pmf/pmf.h>
  12. #include <lib/psci/psci.h>
  13. #include <lib/runtime_instr.h>
  14. #include <services/drtm_svc.h>
  15. #include <services/errata_abi_svc.h>
  16. #include <services/pci_svc.h>
  17. #include <services/rmmd_svc.h>
  18. #include <services/sdei.h>
  19. #include <services/spm_mm_svc.h>
  20. #include <services/spmc_svc.h>
  21. #include <services/spmd_svc.h>
  22. #include <services/std_svc.h>
  23. #include <services/trng_svc.h>
  24. #include <smccc_helpers.h>
  25. #include <tools_share/uuid.h>
  26. /* Standard Service UUID */
  27. static uuid_t arm_svc_uid = {
  28. {0x5b, 0x90, 0x8d, 0x10},
  29. {0x63, 0xf8},
  30. {0xe8, 0x47},
  31. 0xae, 0x2d,
  32. {0xc0, 0xfb, 0x56, 0x41, 0xf6, 0xe2}
  33. };
  34. /* Setup Standard Services */
  35. static int32_t std_svc_setup(void)
  36. {
  37. uintptr_t svc_arg;
  38. int ret = 0;
  39. svc_arg = get_arm_std_svc_args(PSCI_FID_MASK);
  40. assert(svc_arg);
  41. /*
  42. * PSCI is one of the specifications implemented as a Standard Service.
  43. * The `psci_setup()` also does EL3 architectural setup.
  44. */
  45. if (psci_setup((const psci_lib_args_t *)svc_arg) != PSCI_E_SUCCESS) {
  46. ret = 1;
  47. }
  48. #if SPM_MM
  49. if (spm_mm_setup() != 0) {
  50. ret = 1;
  51. }
  52. #endif
  53. #if defined(SPD_spmd)
  54. if (spmd_setup() != 0) {
  55. ret = 1;
  56. }
  57. #endif
  58. #if ENABLE_RME
  59. if (rmmd_setup() != 0) {
  60. ret = 1;
  61. }
  62. #endif
  63. #if SDEI_SUPPORT
  64. /* SDEI initialisation */
  65. sdei_init();
  66. #endif
  67. #if TRNG_SUPPORT
  68. /* TRNG initialisation */
  69. trng_setup();
  70. #endif /* TRNG_SUPPORT */
  71. #if DRTM_SUPPORT
  72. if (drtm_setup() != 0) {
  73. ret = 1;
  74. }
  75. #endif /* DRTM_SUPPORT */
  76. return ret;
  77. }
  78. /*
  79. * Top-level Standard Service SMC handler. This handler will in turn dispatch
  80. * calls to PSCI SMC handler
  81. */
  82. static uintptr_t std_svc_smc_handler(uint32_t smc_fid,
  83. u_register_t x1,
  84. u_register_t x2,
  85. u_register_t x3,
  86. u_register_t x4,
  87. void *cookie,
  88. void *handle,
  89. u_register_t flags)
  90. {
  91. if (((smc_fid >> FUNCID_CC_SHIFT) & FUNCID_CC_MASK) == SMC_32) {
  92. /* 32-bit SMC function, clear top parameter bits */
  93. x1 &= UINT32_MAX;
  94. x2 &= UINT32_MAX;
  95. x3 &= UINT32_MAX;
  96. x4 &= UINT32_MAX;
  97. }
  98. /*
  99. * Dispatch PSCI calls to PSCI SMC handler and return its return
  100. * value
  101. */
  102. if (is_psci_fid(smc_fid)) {
  103. uint64_t ret;
  104. #if ENABLE_RUNTIME_INSTRUMENTATION
  105. /*
  106. * Flush cache line so that even if CPU power down happens
  107. * the timestamp update is reflected in memory.
  108. */
  109. PMF_WRITE_TIMESTAMP(rt_instr_svc,
  110. RT_INSTR_ENTER_PSCI,
  111. PMF_CACHE_MAINT,
  112. get_cpu_data(cpu_data_pmf_ts[CPU_DATA_PMF_TS0_IDX]));
  113. #endif
  114. ret = psci_smc_handler(smc_fid, x1, x2, x3, x4,
  115. cookie, handle, flags);
  116. #if ENABLE_RUNTIME_INSTRUMENTATION
  117. PMF_CAPTURE_TIMESTAMP(rt_instr_svc,
  118. RT_INSTR_EXIT_PSCI,
  119. PMF_NO_CACHE_MAINT);
  120. #endif
  121. SMC_RET1(handle, ret);
  122. }
  123. #if SPM_MM
  124. /*
  125. * Dispatch SPM calls to SPM SMC handler and return its return
  126. * value
  127. */
  128. if (is_spm_mm_fid(smc_fid)) {
  129. return spm_mm_smc_handler(smc_fid, x1, x2, x3, x4, cookie,
  130. handle, flags);
  131. }
  132. #endif
  133. #if defined(SPD_spmd)
  134. /*
  135. * Dispatch FFA calls to the FFA SMC handler implemented by the SPM
  136. * dispatcher and return its return value
  137. */
  138. if (is_ffa_fid(smc_fid)) {
  139. return spmd_ffa_smc_handler(smc_fid, x1, x2, x3, x4, cookie,
  140. handle, flags);
  141. }
  142. #endif
  143. #if SDEI_SUPPORT
  144. if (is_sdei_fid(smc_fid)) {
  145. return sdei_smc_handler(smc_fid, x1, x2, x3, x4, cookie, handle,
  146. flags);
  147. }
  148. #endif
  149. #if TRNG_SUPPORT
  150. if (is_trng_fid(smc_fid)) {
  151. return trng_smc_handler(smc_fid, x1, x2, x3, x4, cookie, handle,
  152. flags);
  153. }
  154. #endif /* TRNG_SUPPORT */
  155. #if ERRATA_ABI_SUPPORT
  156. if (is_errata_fid(smc_fid)) {
  157. return errata_abi_smc_handler(smc_fid, x1, x2, x3, x4, cookie,
  158. handle, flags);
  159. }
  160. #endif /* ERRATA_ABI_SUPPORT */
  161. #if ENABLE_RME
  162. if (is_rmmd_el3_fid(smc_fid)) {
  163. return rmmd_rmm_el3_handler(smc_fid, x1, x2, x3, x4, cookie,
  164. handle, flags);
  165. }
  166. if (is_rmi_fid(smc_fid)) {
  167. return rmmd_rmi_handler(smc_fid, x1, x2, x3, x4, cookie,
  168. handle, flags);
  169. }
  170. #endif
  171. #if SMC_PCI_SUPPORT
  172. if (is_pci_fid(smc_fid)) {
  173. return pci_smc_handler(smc_fid, x1, x2, x3, x4, cookie, handle,
  174. flags);
  175. }
  176. #endif
  177. #if DRTM_SUPPORT
  178. if (is_drtm_fid(smc_fid)) {
  179. return drtm_smc_handler(smc_fid, x1, x2, x3, x4, cookie, handle,
  180. flags);
  181. }
  182. #endif /* DRTM_SUPPORT */
  183. switch (smc_fid) {
  184. case ARM_STD_SVC_CALL_COUNT:
  185. /*
  186. * Return the number of Standard Service Calls. PSCI is the only
  187. * standard service implemented; so return number of PSCI calls
  188. */
  189. SMC_RET1(handle, PSCI_NUM_CALLS);
  190. case ARM_STD_SVC_UID:
  191. /* Return UID to the caller */
  192. SMC_UUID_RET(handle, arm_svc_uid);
  193. case ARM_STD_SVC_VERSION:
  194. /* Return the version of current implementation */
  195. SMC_RET2(handle, STD_SVC_VERSION_MAJOR, STD_SVC_VERSION_MINOR);
  196. default:
  197. VERBOSE("Unimplemented Standard Service Call: 0x%x \n", smc_fid);
  198. SMC_RET1(handle, SMC_UNK);
  199. }
  200. }
  201. /* Register Standard Service Calls as runtime service */
  202. DECLARE_RT_SVC(
  203. std_svc,
  204. OEN_STD_START,
  205. OEN_STD_END,
  206. SMC_TYPE_FAST,
  207. std_svc_setup,
  208. std_svc_smc_handler
  209. );