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