mm_communication.h 7.9 KB

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