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