mtk_sip_svc.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * Copyright (c) 2022-2023, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef MTK_SIP_SVC_H
  7. #define MTK_SIP_SVC_H
  8. #include <stdint.h>
  9. #include <lib/smccc.h>
  10. #include <mtk_sip_def.h>
  11. /* SMC function IDs for SiP Service queries */
  12. #define SIP_SVC_CALL_COUNT U(0x8200ff00)
  13. #define SIP_SVC_UID U(0x8200ff01)
  14. /* 0x8200ff02 is reserved */
  15. #define SIP_SVC_VERSION U(0x8200ff03)
  16. /* MediaTek SiP Service Calls version numbers */
  17. #define MTK_SIP_SVC_VERSION_MAJOR U(0x0)
  18. #define MTK_SIP_SVC_VERSION_MINOR U(0x1)
  19. /* Number of MediaTek SiP Calls implemented */
  20. #define MTK_COMMON_SIP_NUM_CALLS U(4)
  21. /* MediaTek SiP Service Calls function IDs */
  22. #define MTK_SIP_SET_AUTHORIZED_SECURE_REG U(0x82000001)
  23. #define SMC_ID_EXPAND_AS_ENUM(_smc_id, _smc_num) \
  24. _smc_id##_AARCH32 = ((SMC_TYPE_FAST << FUNCID_TYPE_SHIFT) | \
  25. ((0) << FUNCID_CC_SHIFT) | \
  26. (OEN_SIP_START << FUNCID_OEN_SHIFT) | \
  27. ((_smc_num) << FUNCID_NUM_SHIFT)), \
  28. _smc_id##_AARCH64 = ((SMC_TYPE_FAST << FUNCID_TYPE_SHIFT) | \
  29. ((1) << FUNCID_CC_SHIFT) | \
  30. (OEN_SIP_START << FUNCID_OEN_SHIFT) | \
  31. ((_smc_num) << FUNCID_NUM_SHIFT)),
  32. #define SMC_ID_EXPAND_AS_EXTERN_SMC_INDEX(_smc_id, _smc_num) \
  33. extern short _smc_id##_descriptor_index;
  34. /* Bind SMC handler with SMC ID */
  35. #define DECLARE_SMC_HANDLER(_smc_id, _smc_handler) \
  36. const struct smc_descriptor _smc_id##_descriptor \
  37. __used \
  38. __aligned(sizeof(void *)) \
  39. __section(".mtk_smc_descriptor_pool") = { \
  40. .smc_handler = _smc_handler, \
  41. .smc_name = #_smc_id, \
  42. .smc_id_aarch32 = _smc_id##_AARCH32, \
  43. .smc_id_aarch64 = _smc_id##_AARCH64, \
  44. .smc_descriptor_index = &_smc_id##_descriptor_index \
  45. }
  46. MTK_SIP_SMC_FROM_BL33_TABLE(SMC_ID_EXPAND_AS_EXTERN_SMC_INDEX);
  47. MTK_SIP_SMC_FROM_NS_EL1_TABLE(SMC_ID_EXPAND_AS_EXTERN_SMC_INDEX);
  48. MTK_SIP_SMC_FROM_S_EL1_TABLE(SMC_ID_EXPAND_AS_EXTERN_SMC_INDEX);
  49. /* Expand SiP SMC ID table as enum */
  50. enum {
  51. MTK_SIP_SMC_FROM_BL33_TABLE(SMC_ID_EXPAND_AS_ENUM)
  52. MTK_SIP_SMC_FROM_NS_EL1_TABLE(SMC_ID_EXPAND_AS_ENUM)
  53. MTK_SIP_SMC_FROM_S_EL1_TABLE(SMC_ID_EXPAND_AS_ENUM)
  54. MTK_SIP_SMC_MAX_NUMBER
  55. };
  56. /* MediaTek SiP Calls error code */
  57. enum {
  58. MTK_SIP_E_SUCCESS = 0,
  59. MTK_SIP_E_INVALID_PARAM = -1,
  60. MTK_SIP_E_NOT_SUPPORTED = -2,
  61. MTK_SIP_E_INVALID_RANGE = -3,
  62. MTK_SIP_E_PERMISSION_DENY = -4,
  63. MTK_SIP_E_LOCK_FAIL = -5,
  64. };
  65. struct smccc_res {
  66. uint64_t a1;
  67. uint64_t a2;
  68. uint64_t a3;
  69. };
  70. typedef uintptr_t (*smc_handler_t)(u_register_t,
  71. u_register_t,
  72. u_register_t,
  73. u_register_t,
  74. void *,
  75. struct smccc_res *);
  76. struct smc_descriptor {
  77. smc_handler_t smc_handler;
  78. const uint32_t smc_id_aarch32;
  79. const uint32_t smc_id_aarch64;
  80. const char *smc_name;
  81. short *const smc_descriptor_index;
  82. };
  83. /*
  84. * This function should be implemented in MediaTek SOC directory. It fulfills
  85. * MTK_SIP_SET_AUTHORIZED_SECURE_REG SiP call by checking the sreg with the
  86. * predefined secure register list, if a match was found, set val to sreg.
  87. *
  88. * Return MTK_SIP_E_SUCCESS on success, and MTK_SIP_E_INVALID_PARAM on failure.
  89. */
  90. uint64_t mt_sip_set_authorized_sreg(uint32_t sreg, uint32_t val);
  91. #endif /* MTK_SIP_SVC_H */