drtm_svc.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /*
  2. * Copyright (c) 2022-2024 Arm Limited. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. * DRTM service
  7. *
  8. * Authors:
  9. * Lucian Paul-Trifu <lucian.paultrifu@gmail.com>
  10. * Brian Nezvadovitz <brinez@microsoft.com> 2021-02-01
  11. *
  12. */
  13. #ifndef ARM_DRTM_SVC_H
  14. #define ARM_DRTM_SVC_H
  15. /*
  16. * SMC function IDs for DRTM Service
  17. * Upper word bits set: Fast call, SMC64, Standard Secure Svc. Call (OEN = 4)
  18. */
  19. #define DRTM_FID(func_num) \
  20. ((SMC_TYPE_FAST << FUNCID_TYPE_SHIFT) | \
  21. (SMC_64 << FUNCID_CC_SHIFT) | \
  22. (OEN_STD_START << FUNCID_OEN_SHIFT) | \
  23. ((func_num) << FUNCID_NUM_SHIFT))
  24. #define DRTM_FNUM_SVC_VERSION U(0x110)
  25. #define DRTM_FNUM_SVC_FEATURES U(0x111)
  26. #define DRTM_FNUM_SVC_UNPROTECT_MEM U(0x113)
  27. #define DRTM_FNUM_SVC_DYNAMIC_LAUNCH U(0x114)
  28. #define DRTM_FNUM_SVC_CLOSE_LOCALITY U(0x115)
  29. #define DRTM_FNUM_SVC_GET_ERROR U(0x116)
  30. #define DRTM_FNUM_SVC_SET_ERROR U(0x117)
  31. #define DRTM_FNUM_SVC_SET_TCB_HASH U(0x118)
  32. #define DRTM_FNUM_SVC_LOCK_TCB_HASH U(0x119)
  33. #define ARM_DRTM_SVC_VERSION DRTM_FID(DRTM_FNUM_SVC_VERSION)
  34. #define ARM_DRTM_SVC_FEATURES DRTM_FID(DRTM_FNUM_SVC_FEATURES)
  35. #define ARM_DRTM_SVC_UNPROTECT_MEM DRTM_FID(DRTM_FNUM_SVC_UNPROTECT_MEM)
  36. #define ARM_DRTM_SVC_DYNAMIC_LAUNCH DRTM_FID(DRTM_FNUM_SVC_DYNAMIC_LAUNCH)
  37. #define ARM_DRTM_SVC_CLOSE_LOCALITY DRTM_FID(DRTM_FNUM_SVC_CLOSE_LOCALITY)
  38. #define ARM_DRTM_SVC_GET_ERROR DRTM_FID(DRTM_FNUM_SVC_GET_ERROR)
  39. #define ARM_DRTM_SVC_SET_ERROR DRTM_FID(DRTM_FNUM_SVC_SET_ERROR)
  40. #define ARM_DRTM_SVC_SET_TCB_HASH DRTM_FID(DRTM_FNUM_SVC_SET_TCB_HASH)
  41. #define ARM_DRTM_SVC_LOCK_TCB_HASH DRTM_FID(DRTM_FNUM_SVC_LOCK_TCB_HASH)
  42. #define ARM_DRTM_FEATURES_TPM U(0x1)
  43. #define ARM_DRTM_FEATURES_MEM_REQ U(0x2)
  44. #define ARM_DRTM_FEATURES_DMA_PROT U(0x3)
  45. #define ARM_DRTM_FEATURES_BOOT_PE_ID U(0x4)
  46. #define ARM_DRTM_FEATURES_TCB_HASHES U(0x5)
  47. #define is_drtm_fid(_fid) \
  48. (((_fid) >= ARM_DRTM_SVC_VERSION) && ((_fid) <= ARM_DRTM_SVC_LOCK_TCB_HASH))
  49. /* ARM DRTM Service Calls version numbers */
  50. #define ARM_DRTM_VERSION_MAJOR U(1)
  51. #define ARM_DRTM_VERSION_MAJOR_SHIFT 16
  52. #define ARM_DRTM_VERSION_MAJOR_MASK U(0x7FFF)
  53. #define ARM_DRTM_VERSION_MINOR U(0)
  54. #define ARM_DRTM_VERSION_MINOR_SHIFT 0
  55. #define ARM_DRTM_VERSION_MINOR_MASK U(0xFFFF)
  56. #define ARM_DRTM_VERSION \
  57. ((((ARM_DRTM_VERSION_MAJOR) & ARM_DRTM_VERSION_MAJOR_MASK) << \
  58. ARM_DRTM_VERSION_MAJOR_SHIFT) \
  59. | (((ARM_DRTM_VERSION_MINOR) & ARM_DRTM_VERSION_MINOR_MASK) << \
  60. ARM_DRTM_VERSION_MINOR_SHIFT))
  61. #define ARM_DRTM_FUNC_SHIFT U(63)
  62. #define ARM_DRTM_FUNC_MASK ULL(0x1)
  63. #define ARM_DRTM_FUNC_ID U(0x0)
  64. #define ARM_DRTM_FEAT_ID U(0x1)
  65. #define ARM_DRTM_FEAT_ID_MASK ULL(0xff)
  66. /*
  67. * Definitions for DRTM features as per DRTM 1.0 section 3.3,
  68. * Table 6 DRTM_FEATURES
  69. */
  70. #define ARM_DRTM_TPM_FEATURES_PCR_SCHEMA_SHIFT U(33)
  71. #define ARM_DRTM_TPM_FEATURES_PCR_SCHEMA_MASK ULL(0xF)
  72. #define ARM_DRTM_TPM_FEATURES_PCR_SCHEMA_DEFAULT ULL(0x1)
  73. #define ARM_DRTM_TPM_FEATURES_TPM_HASH_SHIFT U(32)
  74. #define ARM_DRTM_TPM_FEATURES_TPM_HASH_MASK ULL(0x1)
  75. #define ARM_DRTM_TPM_FEATURES_TPM_HASH_NOT_SUPPORTED ULL(0x0)
  76. #define ARM_DRTM_TPM_FEATURES_TPM_HASH_SUPPORTED ULL(0x1)
  77. #define ARM_DRTM_TPM_FEATURES_FW_HASH_SHIFT U(0)
  78. #define ARM_DRTM_TPM_FEATURES_FW_HASH_MASK ULL(0xFFFF)
  79. #define ARM_DRTM_TPM_FEATURES_FW_HASH_SHA256 ULL(0xB)
  80. #define ARM_DRTM_TPM_FEATURES_FW_HASH_SHA384 ULL(0xC)
  81. #define ARM_DRTM_TPM_FEATURES_FW_HASH_SHA512 ULL(0xD)
  82. #define ARM_DRTM_MIN_MEM_REQ_DCE_SIZE_SHIFT U(32)
  83. #define ARM_DRTM_MIN_MEM_REQ_DCE_SIZE_MASK ULL(0xFFFFFFFF)
  84. #define ARM_DRTM_MIN_MEM_REQ_MIN_DLME_DATA_SIZE_SHIFT U(0)
  85. #define ARM_DRTM_MIN_MEM_REQ_MIN_DLME_DATA_SIZE_MASK ULL(0xFFFFFFFF)
  86. #define ARM_DRTM_DMA_PROT_FEATURES_MAX_REGIONS_SHIFT U(8)
  87. #define ARM_DRTM_DMA_PROT_FEATURES_MAX_REGIONS_MASK ULL(0xF)
  88. #define ARM_DRTM_DMA_PROT_FEATURES_DMA_SUPPORT_SHIFT U(0)
  89. #define ARM_DRTM_DMA_PROT_FEATURES_DMA_SUPPORT_MASK ULL(0xFF)
  90. #define ARM_DRTM_DMA_PROT_FEATURES_DMA_SUPPORT_COMPLETE ULL(0x1)
  91. #define ARM_DRTM_DMA_PROT_FEATURES_DMA_SUPPORT_REGION ULL(0x2)
  92. #define ARM_DRTM_TCB_HASH_FEATURES_MAX_NUM_HASHES_SHIFT U(0)
  93. #define ARM_DRTM_TCB_HASH_FEATURES_MAX_NUM_HASHES_MASK ULL(0xFF)
  94. #define ARM_DRTM_TPM_FEATURES_SET_PCR_SCHEMA(reg, val) \
  95. do { \
  96. reg = (((reg) & ~(ARM_DRTM_TPM_FEATURES_PCR_SCHEMA_MASK \
  97. << ARM_DRTM_TPM_FEATURES_PCR_SCHEMA_SHIFT)) | (((val) & \
  98. ARM_DRTM_TPM_FEATURES_PCR_SCHEMA_MASK) << \
  99. ARM_DRTM_TPM_FEATURES_PCR_SCHEMA_SHIFT)); \
  100. } while (false)
  101. #define ARM_DRTM_TPM_FEATURES_SET_TPM_HASH(reg, val) \
  102. do { \
  103. reg = (((reg) & ~(ARM_DRTM_TPM_FEATURES_TPM_HASH_MASK \
  104. << ARM_DRTM_TPM_FEATURES_TPM_HASH_SHIFT)) | (((val) & \
  105. ARM_DRTM_TPM_FEATURES_TPM_HASH_MASK) << \
  106. ARM_DRTM_TPM_FEATURES_TPM_HASH_SHIFT)); \
  107. } while (false)
  108. #define ARM_DRTM_TPM_FEATURES_SET_FW_HASH(reg, val) \
  109. do { \
  110. reg = (((reg) & ~(ARM_DRTM_TPM_FEATURES_FW_HASH_MASK \
  111. << ARM_DRTM_TPM_FEATURES_FW_HASH_SHIFT)) | (((val) & \
  112. ARM_DRTM_TPM_FEATURES_FW_HASH_MASK) << \
  113. ARM_DRTM_TPM_FEATURES_FW_HASH_SHIFT)); \
  114. } while (false)
  115. #define ARM_DRTM_MIN_MEM_REQ_SET_DCE_SIZE(reg, val) \
  116. do { \
  117. reg = (((reg) & ~(ARM_DRTM_MIN_MEM_REQ_DCE_SIZE_MASK \
  118. << ARM_DRTM_MIN_MEM_REQ_DCE_SIZE_SHIFT)) | (((val) & \
  119. ARM_DRTM_MIN_MEM_REQ_DCE_SIZE_MASK) << \
  120. ARM_DRTM_MIN_MEM_REQ_DCE_SIZE_SHIFT)); \
  121. } while (false)
  122. #define ARM_DRTM_MIN_MEM_REQ_SET_MIN_DLME_DATA_SIZE(reg, val) \
  123. do { \
  124. reg = (((reg) & \
  125. ~(ARM_DRTM_MIN_MEM_REQ_MIN_DLME_DATA_SIZE_MASK << \
  126. ARM_DRTM_MIN_MEM_REQ_MIN_DLME_DATA_SIZE_SHIFT)) | \
  127. (((val) & ARM_DRTM_MIN_MEM_REQ_MIN_DLME_DATA_SIZE_MASK) \
  128. << ARM_DRTM_MIN_MEM_REQ_MIN_DLME_DATA_SIZE_SHIFT)); \
  129. } while (false)
  130. #define ARM_DRTM_DMA_PROT_FEATURES_SET_MAX_REGIONS(reg, val) \
  131. do { \
  132. reg = (((reg) & \
  133. ~(ARM_DRTM_DMA_PROT_FEATURES_MAX_REGIONS_MASK << \
  134. ARM_DRTM_DMA_PROT_FEATURES_MAX_REGIONS_SHIFT)) | \
  135. (((val) & ARM_DRTM_DMA_PROT_FEATURES_MAX_REGIONS_MASK) \
  136. << ARM_DRTM_DMA_PROT_FEATURES_MAX_REGIONS_SHIFT)); \
  137. } while (false)
  138. #define ARM_DRTM_DMA_PROT_FEATURES_SET_DMA_SUPPORT(reg, val) \
  139. do { \
  140. reg = (((reg) & \
  141. ~(ARM_DRTM_DMA_PROT_FEATURES_DMA_SUPPORT_MASK << \
  142. ARM_DRTM_DMA_PROT_FEATURES_DMA_SUPPORT_SHIFT)) | \
  143. (((val) & ARM_DRTM_DMA_PROT_FEATURES_DMA_SUPPORT_MASK) \
  144. << ARM_DRTM_DMA_PROT_FEATURES_DMA_SUPPORT_SHIFT)); \
  145. } while (false)
  146. #define ARM_DRTM_TCB_HASH_FEATURES_SET_MAX_NUM_HASHES(reg, val) \
  147. do { \
  148. reg = (((reg) & \
  149. ~(ARM_DRTM_TCB_HASH_FEATURES_MAX_NUM_HASHES_MASK << \
  150. ARM_DRTM_TCB_HASH_FEATURES_MAX_NUM_HASHES_SHIFT)) | \
  151. (((val) & \
  152. ARM_DRTM_TCB_HASH_FEATURES_MAX_NUM_HASHES_MASK) << \
  153. ARM_DRTM_TCB_HASH_FEATURES_MAX_NUM_HASHES_SHIFT)); \
  154. } while (false)
  155. /* Definitions for DRTM address map */
  156. #define ARM_DRTM_REGION_SIZE_TYPE_CACHEABILITY_SHIFT U(55)
  157. #define ARM_DRTM_REGION_SIZE_TYPE_CACHEABILITY_MASK ULL(0x3)
  158. #define ARM_DRTM_REGION_SIZE_TYPE_CACHEABILITY_NC ULL(0)
  159. #define ARM_DRTM_REGION_SIZE_TYPE_CACHEABILITY_WC ULL(1)
  160. #define ARM_DRTM_REGION_SIZE_TYPE_CACHEABILITY_WT ULL(2)
  161. #define ARM_DRTM_REGION_SIZE_TYPE_CACHEABILITY_WB ULL(3)
  162. #define ARM_DRTM_REGION_SIZE_TYPE_REGION_TYPE_SHIFT U(52)
  163. #define ARM_DRTM_REGION_SIZE_TYPE_REGION_TYPE_MASK ULL(0x7)
  164. #define ARM_DRTM_REGION_SIZE_TYPE_REGION_TYPE_NORMAL ULL(0)
  165. #define ARM_DRTM_REGION_SIZE_TYPE_REGION_TYPE_NCAR ULL(1)
  166. #define ARM_DRTM_REGION_SIZE_TYPE_REGION_TYPE_DEVICE ULL(2)
  167. #define ARM_DRTM_REGION_SIZE_TYPE_REGION_TYPE_NV ULL(3)
  168. #define ARM_DRTM_REGION_SIZE_TYPE_REGION_TYPE_RSVD ULL(4)
  169. #define ARM_DRTM_REGION_SIZE_TYPE_4K_PAGE_NUM_SHIFT U(0)
  170. #define ARM_DRTM_REGION_SIZE_TYPE_4K_PAGE_NUM_MASK ULL(0xFFFFFFFFFFFFF)
  171. #define ARM_DRTM_REGION_SIZE_TYPE_SET_CACHEABILITY(reg, val) \
  172. do { \
  173. reg = (((reg) & \
  174. ~(ARM_DRTM_REGION_SIZE_TYPE_CACHEABILITY_MASK << \
  175. ARM_DRTM_REGION_SIZE_TYPE_CACHEABILITY_SHIFT)) | \
  176. (((val) & \
  177. ARM_DRTM_REGION_SIZE_TYPE_CACHEABILITY_MASK) << \
  178. ARM_DRTM_REGION_SIZE_TYPE_CACHEABILITY_SHIFT)); \
  179. } while (false)
  180. #define ARM_DRTM_REGION_SIZE_TYPE_SET_REGION_TYPE(reg, val) \
  181. do { \
  182. reg = (((reg) & \
  183. ~(ARM_DRTM_REGION_SIZE_TYPE_REGION_TYPE_MASK << \
  184. ARM_DRTM_REGION_SIZE_TYPE_REGION_TYPE_SHIFT)) | \
  185. (((val) & ARM_DRTM_REGION_SIZE_TYPE_REGION_TYPE_MASK) \
  186. << ARM_DRTM_REGION_SIZE_TYPE_REGION_TYPE_SHIFT)); \
  187. } while (false)
  188. #define ARM_DRTM_REGION_SIZE_TYPE_SET_4K_PAGE_NUM(reg, val) \
  189. do { \
  190. reg = (((reg) & \
  191. ~(ARM_DRTM_REGION_SIZE_TYPE_4K_PAGE_NUM_MASK << \
  192. ARM_DRTM_REGION_SIZE_TYPE_4K_PAGE_NUM_SHIFT)) | \
  193. (((val) & ARM_DRTM_REGION_SIZE_TYPE_4K_PAGE_NUM_MASK) \
  194. << ARM_DRTM_REGION_SIZE_TYPE_4K_PAGE_NUM_SHIFT)); \
  195. } while (false)
  196. /* Initialization routine for the DRTM service */
  197. int drtm_setup(void);
  198. /* Handler to be called to handle DRTM SMC calls */
  199. uint64_t drtm_smc_handler(uint32_t smc_fid,
  200. uint64_t x1,
  201. uint64_t x2,
  202. uint64_t x3,
  203. uint64_t x4,
  204. void *cookie,
  205. void *handle,
  206. uint64_t flags);
  207. #endif /* ARM_DRTM_SVC_H */