237 lines · c
1/* SPDX-License-Identifier: GPL-2.0+ */2/*3 * Headers for EFI variable service via StandAloneMM, EDK2 application running4 * in OP-TEE. Most of the structs and defines resemble the EDK2 naming.5 *6 * Copyright (c) 2017, Intel Corporation. All rights reserved.7 * Copyright (C) 2020 Linaro Ltd.8 */9 10#ifndef _MM_COMMUNICATION_H_11#define _MM_COMMUNICATION_H_12 13/*14 * Interface to the pseudo Trusted Application (TA), which provides a15 * communication channel with the Standalone MM (Management Mode)16 * Secure Partition running at Secure-EL017 */18 19#define PTA_STMM_CMD_COMMUNICATE 020 21/*22 * Defined in OP-TEE, this UUID is used to identify the pseudo-TA.23 * OP-TEE is using big endian GUIDs while UEFI uses little endian ones24 */25#define PTA_STMM_UUID \26 UUID_INIT(0xed32d533, 0x99e6, 0x4209, \27 0x9c, 0xc0, 0x2d, 0x72, 0xcd, 0xd9, 0x98, 0xa7)28 29#define EFI_MM_VARIABLE_GUID \30 EFI_GUID(0xed32d533, 0x99e6, 0x4209, \31 0x9c, 0xc0, 0x2d, 0x72, 0xcd, 0xd9, 0x98, 0xa7)32 33/**34 * struct efi_mm_communicate_header - Header used for SMM variable communication35 36 * @header_guid: header use for disambiguation of content37 * @message_len: length of the message. Does not include the size of the38 * header39 * @data: payload of the message40 *41 * Defined in the PI spec as EFI_MM_COMMUNICATE_HEADER.42 * To avoid confusion in interpreting frames, the communication buffer should43 * always begin with efi_mm_communicate_header.44 */45struct efi_mm_communicate_header {46 efi_guid_t header_guid;47 size_t message_len;48 u8 data[];49} __packed;50 51#define MM_COMMUNICATE_HEADER_SIZE \52 (sizeof(struct efi_mm_communicate_header))53 54/* SPM return error codes */55#define ARM_SVC_SPM_RET_SUCCESS 056#define ARM_SVC_SPM_RET_NOT_SUPPORTED -157#define ARM_SVC_SPM_RET_INVALID_PARAMS -258#define ARM_SVC_SPM_RET_DENIED -359#define ARM_SVC_SPM_RET_NO_MEMORY -560 61#define SMM_VARIABLE_FUNCTION_GET_VARIABLE 162/*63 * The payload for this function is64 * SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME.65 */66#define SMM_VARIABLE_FUNCTION_GET_NEXT_VARIABLE_NAME 267/*68 * The payload for this function is SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE.69 */70#define SMM_VARIABLE_FUNCTION_SET_VARIABLE 371/*72 * The payload for this function is73 * SMM_VARIABLE_COMMUNICATE_QUERY_VARIABLE_INFO.74 */75#define SMM_VARIABLE_FUNCTION_QUERY_VARIABLE_INFO 476/*77 * It is a notify event, no extra payload for this function.78 */79#define SMM_VARIABLE_FUNCTION_READY_TO_BOOT 580/*81 * It is a notify event, no extra payload for this function.82 */83#define SMM_VARIABLE_FUNCTION_EXIT_BOOT_SERVICE 684/*85 * The payload for this function is VARIABLE_INFO_ENTRY.86 * The GUID in EFI_SMM_COMMUNICATE_HEADER is gEfiSmmVariableProtocolGuid.87 */88#define SMM_VARIABLE_FUNCTION_GET_STATISTICS 789/*90 * The payload for this function is SMM_VARIABLE_COMMUNICATE_LOCK_VARIABLE91 */92#define SMM_VARIABLE_FUNCTION_LOCK_VARIABLE 893 94#define SMM_VARIABLE_FUNCTION_VAR_CHECK_VARIABLE_PROPERTY_SET 995 96#define SMM_VARIABLE_FUNCTION_VAR_CHECK_VARIABLE_PROPERTY_GET 1097 98#define SMM_VARIABLE_FUNCTION_GET_PAYLOAD_SIZE 1199/*100 * The payload for this function is101 * SMM_VARIABLE_COMMUNICATE_RUNTIME_VARIABLE_CACHE_CONTEXT102 */103#define SMM_VARIABLE_FUNCTION_INIT_RUNTIME_VARIABLE_CACHE_CONTEXT 12104 105#define SMM_VARIABLE_FUNCTION_SYNC_RUNTIME_CACHE 13106/*107 * The payload for this function is108 * SMM_VARIABLE_COMMUNICATE_GET_RUNTIME_CACHE_INFO109 */110#define SMM_VARIABLE_FUNCTION_GET_RUNTIME_CACHE_INFO 14111 112/**113 * struct smm_variable_communicate_header - Used for SMM variable communication114 115 * @function: function to call in Smm.116 * @ret_status: return status117 * @data: payload118 */119struct smm_variable_communicate_header {120 size_t function;121 efi_status_t ret_status;122 u8 data[];123};124 125#define MM_VARIABLE_COMMUNICATE_SIZE \126 (sizeof(struct smm_variable_communicate_header))127 128/**129 * struct smm_variable_access - Used to communicate with StMM by130 * SetVariable and GetVariable.131 132 * @guid: vendor GUID133 * @data_size: size of EFI variable data134 * @name_size: size of EFI name135 * @attr: attributes136 * @name: variable name137 *138 */139struct smm_variable_access {140 efi_guid_t guid;141 size_t data_size;142 size_t name_size;143 u32 attr;144 u16 name[];145};146 147#define MM_VARIABLE_ACCESS_HEADER_SIZE \148 (sizeof(struct smm_variable_access))149/**150 * struct smm_variable_payload_size - Used to get the max allowed151 * payload used in StMM.152 *153 * @size: size to fill in154 *155 */156struct smm_variable_payload_size {157 size_t size;158};159 160/**161 * struct smm_variable_getnext - Used to communicate with StMM for162 * GetNextVariableName.163 *164 * @guid: vendor GUID165 * @name_size: size of the name of the variable166 * @name: variable name167 *168 */169struct smm_variable_getnext {170 efi_guid_t guid;171 size_t name_size;172 u16 name[];173};174 175#define MM_VARIABLE_GET_NEXT_HEADER_SIZE \176 (sizeof(struct smm_variable_getnext))177 178/**179 * struct smm_variable_query_info - Used to communicate with StMM for180 * QueryVariableInfo.181 *182 * @max_variable_storage: max available storage183 * @remaining_variable_storage: remaining available storage184 * @max_variable_size: max variable supported size185 * @attr: attributes to query storage for186 *187 */188struct smm_variable_query_info {189 u64 max_variable_storage;190 u64 remaining_variable_storage;191 u64 max_variable_size;192 u32 attr;193};194 195#define VAR_CHECK_VARIABLE_PROPERTY_REVISION 0x0001196#define VAR_CHECK_VARIABLE_PROPERTY_READ_ONLY BIT(0)197/**198 * struct var_check_property - Used to store variable properties in StMM199 *200 * @revision: magic revision number for variable property checking201 * @property: properties mask for the variable used in StMM.202 * Currently RO flag is supported203 * @attributes: variable attributes used in StMM checking when properties204 * for a variable are enabled205 * @minsize: minimum allowed size for variable payload checked against206 * smm_variable_access->datasize in StMM207 * @maxsize: maximum allowed size for variable payload checked against208 * smm_variable_access->datasize in StMM209 *210 */211struct var_check_property {212 u16 revision;213 u16 property;214 u32 attributes;215 size_t minsize;216 size_t maxsize;217};218 219/**220 * struct smm_variable_var_check_property - Used to communicate variable221 * properties with StMM222 *223 * @guid: vendor GUID224 * @name_size: size of EFI name225 * @property: variable properties struct226 * @name: variable name227 *228 */229struct smm_variable_var_check_property {230 efi_guid_t guid;231 size_t name_size;232 struct var_check_property property;233 u16 name[];234};235 236#endif /* _MM_COMMUNICATION_H_ */237