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