stm32mp1_svc_setup.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright (c) 2014-2021, STMicroelectronics - All Rights Reserved
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <stdbool.h>
  7. #include <stdint.h>
  8. #include <common/debug.h>
  9. #include <common/runtime_svc.h>
  10. #include <drivers/scmi-msg.h>
  11. #include <lib/psci/psci.h>
  12. #include <tools_share/uuid.h>
  13. #include <stm32mp1_smc.h>
  14. #include "bsec_svc.h"
  15. /* STM32 SiP Service UUID */
  16. DEFINE_SVC_UUID2(stm32_sip_svc_uid,
  17. 0xa778aa50, 0xf49b, 0x144a, 0x8a, 0x5e,
  18. 0x26, 0x4d, 0x59, 0x94, 0xc2, 0x14);
  19. /* Setup STM32MP1 Standard Services */
  20. static int32_t stm32mp1_svc_setup(void)
  21. {
  22. /*
  23. * PSCI is the only specification implemented as a Standard Service.
  24. * Invoke PSCI setup from here.
  25. */
  26. return 0;
  27. }
  28. /*
  29. * Top-level Standard Service SMC handler. This handler will in turn dispatch
  30. * calls to PSCI SMC handler.
  31. */
  32. static uintptr_t stm32mp1_svc_smc_handler(uint32_t smc_fid, u_register_t x1,
  33. u_register_t x2, u_register_t x3,
  34. u_register_t x4, void *cookie,
  35. void *handle, u_register_t flags)
  36. {
  37. uint32_t ret1 = 0U, ret2 = 0U;
  38. bool ret_uid = false, ret2_enabled = false;
  39. switch (smc_fid) {
  40. case STM32_SIP_SVC_CALL_COUNT:
  41. ret1 = STM32_COMMON_SIP_NUM_CALLS;
  42. break;
  43. case STM32_SIP_SVC_UID:
  44. /* Return UUID to the caller */
  45. ret_uid = true;
  46. break;
  47. case STM32_SIP_SVC_VERSION:
  48. /* Return the version of current implementation */
  49. ret1 = STM32_SIP_SVC_VERSION_MAJOR;
  50. ret2 = STM32_SIP_SVC_VERSION_MINOR;
  51. ret2_enabled = true;
  52. break;
  53. case STM32_SMC_BSEC:
  54. ret1 = bsec_main(x1, x2, x3, &ret2);
  55. ret2_enabled = true;
  56. break;
  57. case STM32_SIP_SMC_SCMI_AGENT0:
  58. scmi_smt_fastcall_smc_entry(0);
  59. break;
  60. case STM32_SIP_SMC_SCMI_AGENT1:
  61. scmi_smt_fastcall_smc_entry(1);
  62. break;
  63. default:
  64. WARN("Unimplemented STM32MP1 Service Call: 0x%x\n", smc_fid);
  65. ret1 = STM32_SMC_NOT_SUPPORTED;
  66. break;
  67. }
  68. if (ret_uid) {
  69. SMC_UUID_RET(handle, stm32_sip_svc_uid);
  70. }
  71. if (ret2_enabled) {
  72. SMC_RET2(handle, ret1, ret2);
  73. }
  74. SMC_RET1(handle, ret1);
  75. }
  76. /* Register Standard Service Calls as runtime service */
  77. DECLARE_RT_SVC(stm32mp1_sip_svc,
  78. OEN_SIP_START,
  79. OEN_SIP_END,
  80. SMC_TYPE_FAST,
  81. stm32mp1_svc_setup,
  82. stm32mp1_svc_smc_handler
  83. );