rmmd_svc.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. * Copyright (c) 2021-2022, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef RMMD_SVC_H
  7. #define RMMD_SVC_H
  8. #include <lib/smccc.h>
  9. #include <lib/utils_def.h>
  10. /* STD calls FNUM Min/Max ranges */
  11. #define RMI_FNUM_MIN_VALUE U(0x150)
  12. #define RMI_FNUM_MAX_VALUE U(0x18F)
  13. /* Construct RMI fastcall std FID from offset */
  14. #define SMC64_RMI_FID(_offset) \
  15. ((SMC_TYPE_FAST << FUNCID_TYPE_SHIFT) | \
  16. (SMC_64 << FUNCID_CC_SHIFT) | \
  17. (OEN_STD_START << FUNCID_OEN_SHIFT) | \
  18. (((RMI_FNUM_MIN_VALUE + (_offset)) & FUNCID_NUM_MASK) \
  19. << FUNCID_NUM_SHIFT))
  20. #define is_rmi_fid(fid) __extension__ ({ \
  21. __typeof__(fid) _fid = (fid); \
  22. ((GET_SMC_NUM(_fid) >= RMI_FNUM_MIN_VALUE) && \
  23. (GET_SMC_NUM(_fid) <= RMI_FNUM_MAX_VALUE) && \
  24. (GET_SMC_TYPE(_fid) == SMC_TYPE_FAST) && \
  25. (GET_SMC_CC(_fid) == SMC_64) && \
  26. (GET_SMC_OEN(_fid) == OEN_STD_START) && \
  27. ((_fid & 0x00FE0000) == 0U)); })
  28. /*
  29. * RMI_FNUM_REQ_COMPLETE is the only function in the RMI range that originates
  30. * from the Realm world and is handled by the RMMD. The RMI functions are
  31. * always invoked by the Normal world, forwarded by RMMD and handled by the
  32. * RMM.
  33. */
  34. /* 0x18F */
  35. #define RMM_RMI_REQ_COMPLETE SMC64_RMI_FID(U(0x3F))
  36. /* RMM_BOOT_COMPLETE arg0 error codes */
  37. #define E_RMM_BOOT_SUCCESS (0)
  38. #define E_RMM_BOOT_UNKNOWN (-1)
  39. #define E_RMM_BOOT_VERSION_MISMATCH (-2)
  40. #define E_RMM_BOOT_CPUS_OUT_OF_RANGE (-3)
  41. #define E_RMM_BOOT_CPU_ID_OUT_OF_RANGE (-4)
  42. #define E_RMM_BOOT_INVALID_SHARED_BUFFER (-5)
  43. #define E_RMM_BOOT_MANIFEST_VERSION_NOT_SUPPORTED (-6)
  44. #define E_RMM_BOOT_MANIFEST_DATA_ERROR (-7)
  45. /* The SMC in the range 0x8400 0191 - 0x8400 01AF are reserved for RSIs.*/
  46. /*
  47. * EL3 - RMM SMCs used for requesting RMMD services. These SMCs originate in Realm
  48. * world and return to Realm world.
  49. *
  50. * These are allocated from 0x8400 01B0 - 0x8400 01CF in the RMM Service range.
  51. */
  52. #define RMMD_EL3_FNUM_MIN_VALUE U(0x1B0)
  53. #define RMMD_EL3_FNUM_MAX_VALUE U(0x1CF)
  54. /* Construct RMM_EL3 fastcall std FID from offset */
  55. #define SMC64_RMMD_EL3_FID(_offset) \
  56. ((SMC_TYPE_FAST << FUNCID_TYPE_SHIFT) | \
  57. (SMC_64 << FUNCID_CC_SHIFT) | \
  58. (OEN_STD_START << FUNCID_OEN_SHIFT) | \
  59. (((RMMD_EL3_FNUM_MIN_VALUE + (_offset)) & FUNCID_NUM_MASK) \
  60. << FUNCID_NUM_SHIFT))
  61. /* The macros below are used to identify GTSI calls from the SMC function ID */
  62. #define is_rmmd_el3_fid(fid) __extension__ ({ \
  63. __typeof__(fid) _fid = (fid); \
  64. ((GET_SMC_NUM(_fid) >= RMMD_EL3_FNUM_MIN_VALUE) &&\
  65. (GET_SMC_NUM(_fid) <= RMMD_EL3_FNUM_MAX_VALUE) &&\
  66. (GET_SMC_TYPE(_fid) == SMC_TYPE_FAST) && \
  67. (GET_SMC_CC(_fid) == SMC_64) && \
  68. (GET_SMC_OEN(_fid) == OEN_STD_START) && \
  69. ((_fid & 0x00FE0000) == 0U)); })
  70. /* 0x1B0 - 0x1B1 */
  71. #define RMM_GTSI_DELEGATE SMC64_RMMD_EL3_FID(U(0))
  72. #define RMM_GTSI_UNDELEGATE SMC64_RMMD_EL3_FID(U(1))
  73. /* Return error codes from RMM-EL3 SMCs */
  74. #define E_RMM_OK 0
  75. #define E_RMM_UNK -1
  76. #define E_RMM_BAD_ADDR -2
  77. #define E_RMM_BAD_PAS -3
  78. #define E_RMM_NOMEM -4
  79. #define E_RMM_INVAL -5
  80. /* Acceptable SHA sizes for Challenge object */
  81. #define SHA256_DIGEST_SIZE 32U
  82. #define SHA384_DIGEST_SIZE 48U
  83. #define SHA512_DIGEST_SIZE 64U
  84. /*
  85. * Retrieve Realm attestation key from EL3. Only P-384 ECC curve key is
  86. * supported. The arguments to this SMC are :
  87. * arg0 - Function ID.
  88. * arg1 - Realm attestation key buffer Physical address.
  89. * arg2 - Realm attestation key buffer size (in bytes).
  90. * arg3 - The type of the elliptic curve to which the requested
  91. * attestation key belongs to. The value should be one of the
  92. * defined curve types.
  93. * The return arguments are :
  94. * ret0 - Status / error.
  95. * ret1 - Size of the realm attestation key if successful.
  96. */
  97. /* 0x1B2 */
  98. #define RMM_ATTEST_GET_REALM_KEY SMC64_RMMD_EL3_FID(U(2))
  99. /*
  100. * Retrieve Platform token from EL3.
  101. * The arguments to this SMC are :
  102. * arg0 - Function ID.
  103. * arg1 - Platform attestation token buffer Physical address. (The challenge
  104. * object is passed in this buffer.)
  105. * arg2 - Platform attestation token buffer size (in bytes).
  106. * arg3 - Challenge object size (in bytes). It has to be one of the defined
  107. * SHA hash sizes.
  108. * The return arguments are :
  109. * ret0 - Status / error.
  110. * ret1 - Size of the platform token if successful.
  111. */
  112. /* 0x1B3 */
  113. #define RMM_ATTEST_GET_PLAT_TOKEN SMC64_RMMD_EL3_FID(U(3))
  114. /* ECC Curve types for attest key generation */
  115. #define ATTEST_KEY_CURVE_ECC_SECP384R1 0
  116. /*
  117. * RMM_BOOT_COMPLETE originates on RMM when the boot finishes (either cold
  118. * or warm boot). This is handled by the RMM-EL3 interface SMC handler.
  119. *
  120. * RMM_BOOT_COMPLETE FID is located at the end of the available range.
  121. */
  122. /* 0x1CF */
  123. #define RMM_BOOT_COMPLETE SMC64_RMMD_EL3_FID(U(0x1F))
  124. /*
  125. * The major version number of the RMM Boot Interface implementation.
  126. * Increase this whenever the semantics of the boot arguments change making it
  127. * backwards incompatible.
  128. */
  129. #define RMM_EL3_IFC_VERSION_MAJOR (U(0))
  130. /*
  131. * The minor version number of the RMM Boot Interface implementation.
  132. * Increase this when a bug is fixed, or a feature is added without
  133. * breaking compatibility.
  134. */
  135. #define RMM_EL3_IFC_VERSION_MINOR (U(1))
  136. #define RMM_EL3_INTERFACE_VERSION \
  137. (((RMM_EL3_IFC_VERSION_MAJOR << 16) & 0x7FFFF) | \
  138. RMM_EL3_IFC_VERSION_MINOR)
  139. #define RMM_EL3_IFC_VERSION_GET_MAJOR(_version) (((_version) >> 16) \
  140. & 0x7FFF)
  141. #define RMM_EL3_IFC_VERSION_GET_MAJOR_MINOR(_version) ((_version) & 0xFFFF)
  142. #ifndef __ASSEMBLER__
  143. #include <stdint.h>
  144. int rmmd_setup(void);
  145. uint64_t rmmd_rmi_handler(uint32_t smc_fid,
  146. uint64_t x1,
  147. uint64_t x2,
  148. uint64_t x3,
  149. uint64_t x4,
  150. void *cookie,
  151. void *handle,
  152. uint64_t flags);
  153. uint64_t rmmd_rmm_el3_handler(uint32_t smc_fid,
  154. uint64_t x1,
  155. uint64_t x2,
  156. uint64_t x3,
  157. uint64_t x4,
  158. void *cookie,
  159. void *handle,
  160. uint64_t flags);
  161. #endif /* __ASSEMBLER__ */
  162. #endif /* RMMD_SVC_H */