mtk_sip_svc.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * Copyright (c) 2015, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <common/debug.h>
  8. #include <common/runtime_svc.h>
  9. #include <drivers/console.h>
  10. #include <lib/mmio.h>
  11. #include <tools_share/uuid.h>
  12. #include <mtk_plat_common.h>
  13. #include <mtk_sip_svc.h>
  14. #include <plat_sip_calls.h>
  15. /* Mediatek SiP Service UUID */
  16. DEFINE_SVC_UUID2(mtk_sip_svc_uid,
  17. 0xa42b58f7, 0x6242, 0x7d4d, 0x80, 0xe5,
  18. 0x8f, 0x95, 0x05, 0x00, 0x0f, 0x3d);
  19. #pragma weak mediatek_plat_sip_handler
  20. uintptr_t mediatek_plat_sip_handler(uint32_t smc_fid,
  21. u_register_t x1,
  22. u_register_t x2,
  23. u_register_t x3,
  24. u_register_t x4,
  25. void *cookie,
  26. void *handle,
  27. u_register_t flags)
  28. {
  29. ERROR("%s: unhandled SMC (0x%x)\n", __func__, smc_fid);
  30. SMC_RET1(handle, SMC_UNK);
  31. }
  32. /*
  33. * This function handles Mediatek defined SiP Calls */
  34. uintptr_t mediatek_sip_handler(uint32_t smc_fid,
  35. u_register_t x1,
  36. u_register_t x2,
  37. u_register_t x3,
  38. u_register_t x4,
  39. void *cookie,
  40. void *handle,
  41. u_register_t flags)
  42. {
  43. uint32_t ns;
  44. /* if parameter is sent from SMC32. Clean top 32 bits */
  45. clean_top_32b_of_param(smc_fid, &x1, &x2, &x3, &x4);
  46. /* Determine which security state this SMC originated from */
  47. ns = is_caller_non_secure(flags);
  48. if (!ns) {
  49. /* SiP SMC service secure world's call */
  50. ;
  51. } else {
  52. /* SiP SMC service normal world's call */
  53. switch (smc_fid) {
  54. #if MTK_SIP_SET_AUTHORIZED_SECURE_REG_ENABLE
  55. case MTK_SIP_SET_AUTHORIZED_SECURE_REG: {
  56. /* only use ret here */
  57. uint64_t ret;
  58. ret = mt_sip_set_authorized_sreg((uint32_t)x1,
  59. (uint32_t)x2);
  60. SMC_RET1(handle, ret);
  61. }
  62. #endif
  63. #if MTK_SIP_KERNEL_BOOT_ENABLE
  64. case MTK_SIP_KERNEL_BOOT_AARCH32:
  65. boot_to_kernel(x1, x2, x3, x4);
  66. SMC_RET0(handle);
  67. #endif
  68. default:
  69. /* Do nothing in default case */
  70. break;
  71. }
  72. }
  73. return mediatek_plat_sip_handler(smc_fid, x1, x2, x3, x4,
  74. cookie, handle, flags);
  75. }
  76. /*
  77. * This function is responsible for handling all SiP calls from the NS world
  78. */
  79. uintptr_t sip_smc_handler(uint32_t smc_fid,
  80. u_register_t x1,
  81. u_register_t x2,
  82. u_register_t x3,
  83. u_register_t x4,
  84. void *cookie,
  85. void *handle,
  86. u_register_t flags)
  87. {
  88. switch (smc_fid) {
  89. case SIP_SVC_CALL_COUNT:
  90. /* Return the number of Mediatek SiP Service Calls. */
  91. SMC_RET1(handle,
  92. MTK_COMMON_SIP_NUM_CALLS + MTK_PLAT_SIP_NUM_CALLS);
  93. case SIP_SVC_UID:
  94. /* Return UID to the caller */
  95. SMC_UUID_RET(handle, mtk_sip_svc_uid);
  96. case SIP_SVC_VERSION:
  97. /* Return the version of current implementation */
  98. SMC_RET2(handle, MTK_SIP_SVC_VERSION_MAJOR,
  99. MTK_SIP_SVC_VERSION_MINOR);
  100. default:
  101. return mediatek_sip_handler(smc_fid, x1, x2, x3, x4,
  102. cookie, handle, flags);
  103. }
  104. }
  105. /* Define a runtime service descriptor for fast SMC calls */
  106. DECLARE_RT_SVC(
  107. mediatek_sip_svc,
  108. OEN_SIP_START,
  109. OEN_SIP_END,
  110. SMC_TYPE_FAST,
  111. NULL,
  112. sip_smc_handler
  113. );