mm_communication.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Headers for EFI variable service via StandAloneMM, EDK2 application running
  4. * in OP-TEE
  5. *
  6. * Copyright (c) 2017, Intel Corporation. All rights reserved.
  7. * Copyright (C) 2020 Linaro Ltd. <sughosh.ganu@linaro.org>
  8. * Copyright (C) 2020 Linaro Ltd. <ilias.apalodimas@linaro.org>
  9. */
  10. #ifndef _MM_COMMUNICATION_H_
  11. #define _MM_COMMUNICATION_H_
  12. #include <part_efi.h>
  13. /*
  14. * Interface to the pseudo Trusted Application (TA), which provides a
  15. * communication channel with the Standalone MM (Management Mode)
  16. * Secure Partition running at Secure-EL0
  17. */
  18. #define PTA_STMM_CMDID_COMMUNICATE 0
  19. /* OP-TEE is using big endian GUIDs while UEFI uses little endian ones */
  20. #define PTA_STMM_UUID { 0xed32d533, 0x99e6, 0x4209, {\
  21. 0x9c, 0xc0, 0x2d, 0x72, 0xcd, 0xd9, 0x98, 0xa7 } }
  22. #define EFI_MM_VARIABLE_GUID \
  23. EFI_GUID(0xed32d533, 0x99e6, 0x4209, \
  24. 0x9c, 0xc0, 0x2d, 0x72, 0xcd, 0xd9, 0x98, 0xa7)
  25. /* Defined in EDK2 MdePkg/Include/Protocol/MmCommunication.h */
  26. /**
  27. * struct efi_mm_communicate_header - Header used for SMM variable communication
  28. * @header_guid: header use for disambiguation of content
  29. * @message_len: length of the message. Does not include the size of the
  30. * header
  31. * @data: payload of the message
  32. *
  33. * Defined in EDK2 as EFI_MM_COMMUNICATE_HEADER.
  34. * To avoid confusion in interpreting frames, the communication buffer should
  35. * always begin with efi_mm_communicate_header.
  36. */
  37. struct __packed efi_mm_communicate_header {
  38. efi_guid_t header_guid;
  39. size_t message_len;
  40. u8 data[];
  41. };
  42. #define MM_COMMUNICATE_HEADER_SIZE \
  43. (sizeof(struct efi_mm_communicate_header))
  44. /* Defined in EDK2 ArmPkg/Include/IndustryStandard/ArmMmSvc.h */
  45. /* SPM return error codes */
  46. #define ARM_SVC_SPM_RET_SUCCESS 0
  47. #define ARM_SVC_SPM_RET_NOT_SUPPORTED -1
  48. #define ARM_SVC_SPM_RET_INVALID_PARAMS -2
  49. #define ARM_SVC_SPM_RET_DENIED -3
  50. #define ARM_SVC_SPM_RET_NO_MEMORY -5
  51. /* Defined in EDK2 MdeModulePkg/Include/Guid/SmmVariableCommon.h */
  52. #define SMM_VARIABLE_FUNCTION_GET_VARIABLE 1
  53. /*
  54. * The payload for this function is
  55. * SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME.
  56. */
  57. #define SMM_VARIABLE_FUNCTION_GET_NEXT_VARIABLE_NAME 2
  58. /*
  59. * The payload for this function is SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE.
  60. */
  61. #define SMM_VARIABLE_FUNCTION_SET_VARIABLE 3
  62. /*
  63. * The payload for this function is
  64. * SMM_VARIABLE_COMMUNICATE_QUERY_VARIABLE_INFO.
  65. */
  66. #define SMM_VARIABLE_FUNCTION_QUERY_VARIABLE_INFO 4
  67. /*
  68. * It is a notify event, no extra payload for this function.
  69. */
  70. #define SMM_VARIABLE_FUNCTION_READY_TO_BOOT 5
  71. /*
  72. * It is a notify event, no extra payload for this function.
  73. */
  74. #define SMM_VARIABLE_FUNCTION_EXIT_BOOT_SERVICE 6
  75. /*
  76. * The payload for this function is VARIABLE_INFO_ENTRY.
  77. * The GUID in EFI_SMM_COMMUNICATE_HEADER is gEfiSmmVariableProtocolGuid.
  78. */
  79. #define SMM_VARIABLE_FUNCTION_GET_STATISTICS 7
  80. /*
  81. * The payload for this function is SMM_VARIABLE_COMMUNICATE_LOCK_VARIABLE
  82. */
  83. #define SMM_VARIABLE_FUNCTION_LOCK_VARIABLE 8
  84. #define SMM_VARIABLE_FUNCTION_VAR_CHECK_VARIABLE_PROPERTY_SET 9
  85. #define SMM_VARIABLE_FUNCTION_VAR_CHECK_VARIABLE_PROPERTY_GET 10
  86. #define SMM_VARIABLE_FUNCTION_GET_PAYLOAD_SIZE 11
  87. /*
  88. * The payload for this function is
  89. * SMM_VARIABLE_COMMUNICATE_RUNTIME_VARIABLE_CACHE_CONTEXT
  90. */
  91. #define SMM_VARIABLE_FUNCTION_INIT_RUNTIME_VARIABLE_CACHE_CONTEXT 12
  92. #define SMM_VARIABLE_FUNCTION_SYNC_RUNTIME_CACHE 13
  93. /*
  94. * The payload for this function is
  95. * SMM_VARIABLE_COMMUNICATE_GET_RUNTIME_CACHE_INFO
  96. */
  97. #define SMM_VARIABLE_FUNCTION_GET_RUNTIME_CACHE_INFO 14
  98. /**
  99. * struct smm_variable_communicate_header - Used for SMM variable communication
  100. * @function: function to call in Smm.
  101. * @ret_status: return status
  102. * @data: payload
  103. *
  104. * Defined in EDK2 as SMM_VARIABLE_COMMUNICATE_HEADER.
  105. */
  106. struct smm_variable_communicate_header {
  107. efi_uintn_t function;
  108. efi_status_t ret_status;
  109. u8 data[];
  110. };
  111. #define MM_VARIABLE_COMMUNICATE_SIZE \
  112. (sizeof(struct smm_variable_communicate_header))
  113. /**
  114. * struct smm_variable_access - Used to communicate with StMM by
  115. * SetVariable and GetVariable.
  116. * @guid: vendor GUID
  117. * @data_size: size of EFI variable data
  118. * @name_size: size of EFI name
  119. * @attr: attributes
  120. * @name: variable name
  121. *
  122. * Defined in EDK2 as SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE.
  123. *
  124. */
  125. struct smm_variable_access {
  126. efi_guid_t guid;
  127. efi_uintn_t data_size;
  128. efi_uintn_t name_size;
  129. u32 attr;
  130. u16 name[];
  131. };
  132. #define MM_VARIABLE_ACCESS_HEADER_SIZE \
  133. (sizeof(struct smm_variable_access))
  134. /**
  135. * struct smm_variable_payload_size - Used to get the max allowed
  136. * payload used in StMM.
  137. *
  138. * @size: size to fill in
  139. *
  140. * Defined in EDK2 as SMM_VARIABLE_COMMUNICATE_GET_PAYLOAD_SIZE.
  141. *
  142. */
  143. struct smm_variable_payload_size {
  144. efi_uintn_t size;
  145. };
  146. /**
  147. * struct smm_variable_getnext - Used to communicate with StMM for
  148. * GetNextVariableName.
  149. *
  150. * @guid: vendor GUID
  151. * @name_size: size of the name of the variable
  152. * @name: variable name
  153. *
  154. * Defined in EDK2 as SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME.
  155. */
  156. struct smm_variable_getnext {
  157. efi_guid_t guid;
  158. efi_uintn_t name_size;
  159. u16 name[];
  160. };
  161. #define MM_VARIABLE_GET_NEXT_HEADER_SIZE \
  162. (sizeof(struct smm_variable_getnext))
  163. /**
  164. * struct smm_variable_query_info - Used to communicate with StMM for
  165. * QueryVariableInfo.
  166. *
  167. * @max_variable_storage: max available storage
  168. * @remaining_variable_storage: remaining available storage
  169. * @max_variable_size: max variable supported size
  170. * @attr: attributes to query storage for
  171. *
  172. * Defined in EDK2 as SMM_VARIABLE_COMMUNICATE_QUERY_VARIABLE_INFO.
  173. */
  174. struct smm_variable_query_info {
  175. u64 max_variable_storage;
  176. u64 remaining_variable_storage;
  177. u64 max_variable_size;
  178. u32 attr;
  179. };
  180. #define VAR_CHECK_VARIABLE_PROPERTY_REVISION 0x0001
  181. #define VAR_CHECK_VARIABLE_PROPERTY_READ_ONLY BIT(0)
  182. /**
  183. * struct var_check_property - Used to store variable properties in StMM
  184. *
  185. * @revision: magic revision number for variable property checking
  186. * @property: properties mask for the variable used in StMM.
  187. * Currently RO flag is supported
  188. * @attributes: variable attributes used in StMM checking when properties
  189. * for a variable are enabled
  190. * @minsize: minimum allowed size for variable payload checked against
  191. * smm_variable_access->datasize in StMM
  192. * @maxsize: maximum allowed size for variable payload checked against
  193. * smm_variable_access->datasize in StMM
  194. *
  195. * Defined in EDK2 as VAR_CHECK_VARIABLE_PROPERTY.
  196. */
  197. struct var_check_property {
  198. u16 revision;
  199. u16 property;
  200. u32 attributes;
  201. efi_uintn_t minsize;
  202. efi_uintn_t maxsize;
  203. };
  204. /**
  205. * struct smm_variable_var_check_property - Used to communicate variable
  206. * properties with StMM
  207. *
  208. * @guid: vendor GUID
  209. * @name_size: size of EFI name
  210. * @property: variable properties struct
  211. * @name: variable name
  212. *
  213. * Defined in EDK2 as SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY.
  214. */
  215. struct smm_variable_var_check_property {
  216. efi_guid_t guid;
  217. efi_uintn_t name_size;
  218. struct var_check_property property;
  219. u16 name[];
  220. };
  221. #endif /* _MM_COMMUNICATION_H_ */