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