blob: 0847cee02e14757a64688ffcafb0e0ee7506de31 [file] [log] [blame]
Patrick Williams864cc432023-02-09 14:54:44 -06001From e371b2d29aa447c1a186ab25b37b99fded967b77 Mon Sep 17 00:00:00 2001
Patrick Williams8dd68482022-10-04 07:57:18 -05002From: Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
3Date: Mon, 15 Aug 2022 15:12:49 +0100
Patrick Williams864cc432023-02-09 14:54:44 -06004Subject: [PATCH 09/27] arm_ffa: efi: introduce FF-A MM communication
Patrick Williams8dd68482022-10-04 07:57:18 -05005
6Add MM communication support using FF-A transport
7
Patrick Williams8dd68482022-10-04 07:57:18 -05008This feature allows accessing MM partitions services through
9EFI MM communication protocol. MM partitions such as StandAlonneMM
10or smm-gateway secure partitions which reside in secure world.
11
12An MM shared buffer and a door bell event are used to exchange
13the data.
14
15The data is used by EFI services such as GetVariable()/SetVariable()
16and copied from the communication buffer to the MM shared buffer.
17
18The secure partition is notified about availability of data in the
19MM shared buffer by an FF-A message (door bell).
20
21On such event, MM SP can read the data and updates the MM shared
22buffer with the response data.
23
24The response data is copied back to the communication buffer and
25consumed by the EFI subsystem.
26
Andrew Geisslerea144b032023-01-27 16:03:57 -060027MM communication protocol supports FF-A 64-bit direct messaging.
Patrick Williams8dd68482022-10-04 07:57:18 -050028
29Signed-off-by: Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
30Signed-off-by: Gowtham Suresh Kumar <gowtham.sureshkumar@arm.com>
Andrew Geisslerea144b032023-01-27 16:03:57 -060031Cc: Tom Rini <trini@konsulko.com>
32Cc: Simon Glass <sjg@chromium.org>
33Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>
34Cc: Jens Wiklander <jens.wiklander@linaro.org>
35Upstream-Status: Submitted [cover letter: https://lore.kernel.org/all/20221122131751.22747-1-abdellatif.elkhlifi@arm.com/]
Patrick Williams8dd68482022-10-04 07:57:18 -050036
37Changelog:
38===============
39
Andrew Geisslerea144b032023-01-27 16:03:57 -060040v8:
41
42* isolate the compilation choices between FF-A and OP-TEE
43* update partition_info_get() second argument to be an SP count
44* pass NULL device pointer to the FF-A bus discovery and operations
45
46v7:
47
48* set the MM door bell event to use 64-bit direct messaging
49* issue a compile time error when one of these macros are not found :
50 FFA_SHARED_MM_BUFFER_SIZE, FFA_SHARED_MM_BUFFER_OFFSET, FFA_SHARED_MM_BUFFER_ADDR
51* make mm_sp_svc_uuid static
52* replace EINVAL with ENOMEM in ffa_discover_mm_sp_id() when calloc() fails
53* improve use of unmap_sysmem() in ffa_mm_communicate()
54
55v6:
56
57* add FF-A runtime discovery at MM communication level
58* drop EFI runtime support for FF-A MM communication
59* revert the changes in include/mm_communication.h for
60 efi_mm_communicate_header and smm_variable_access structures
61
Patrick Williams8dd68482022-10-04 07:57:18 -050062v4:
63
64* use the new FF-A driver interfaces
65* discover MM partitions at runtime
66* copy FF-A driver private data to EFI runtime section at
67 ExitBootServices()
68* drop use of FFA_ERR_STAT_SUCCESS error code
Andrew Geisslerea144b032023-01-27 16:03:57 -060069* replace EFI_BUFFER_TOO_SMALL with EFI_OUT_OF_RESOURCES
Patrick Williams8dd68482022-10-04 07:57:18 -050070 in ffa_mm_communicate(). No need for efi_memcpy_runtime() anymore
71* revert the error log in mm_communicate() in case of failure
72* remove packed attribute from efi_mm_communicate_header and
73 smm_variable_communicate_header
74
75v2:
76
77* set default values to 0 for FFA_SHARED_MM_BUFFER_SIZE, FFA_SHARED_MM_BUFFER_ADDR and MM_SP_UUID_DATA and add warnings
78
79v1:
80
81* introduce FF-A MM communication
Patrick Williams864cc432023-02-09 14:54:44 -060082
83Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Andrew Geisslerea144b032023-01-27 16:03:57 -060084---
85 include/mm_communication.h | 5 +
Patrick Williams8dd68482022-10-04 07:57:18 -050086 lib/efi_loader/Kconfig | 14 +-
Andrew Geisslerea144b032023-01-27 16:03:57 -060087 lib/efi_loader/efi_variable_tee.c | 294 +++++++++++++++++++++++++++++-
88 3 files changed, 307 insertions(+), 6 deletions(-)
Patrick Williams8dd68482022-10-04 07:57:18 -050089
Patrick Williams8dd68482022-10-04 07:57:18 -050090diff --git a/include/mm_communication.h b/include/mm_communication.h
Patrick Williams864cc432023-02-09 14:54:44 -060091index e65fbde60d0a..d409bed77714 100644
Patrick Williams8dd68482022-10-04 07:57:18 -050092--- a/include/mm_communication.h
93+++ b/include/mm_communication.h
Andrew Geisslerea144b032023-01-27 16:03:57 -060094@@ -6,6 +6,8 @@
95 * Copyright (c) 2017, Intel Corporation. All rights reserved.
96 * Copyright (C) 2020 Linaro Ltd. <sughosh.ganu@linaro.org>
97 * Copyright (C) 2020 Linaro Ltd. <ilias.apalodimas@linaro.org>
98+ * (C) Copyright 2022 ARM Limited
99+ * Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
100 */
101
102 #ifndef _MM_COMMUNICATION_H_
103@@ -13,6 +15,9 @@
Patrick Williams8dd68482022-10-04 07:57:18 -0500104
105 #include <part_efi.h>
106
107+/* MM service UUID string (big-endian format). This UUID is common across all MM SPs */
108+#define MM_SP_UUID "33d532ed-e699-0942-c09c-a798d9cd722d"
109+
110 /*
111 * Interface to the pseudo Trusted Application (TA), which provides a
112 * communication channel with the Standalone MM (Management Mode)
Patrick Williams8dd68482022-10-04 07:57:18 -0500113diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
Patrick Williams864cc432023-02-09 14:54:44 -0600114index b498c72206fd..ca7390848125 100644
Patrick Williams8dd68482022-10-04 07:57:18 -0500115--- a/lib/efi_loader/Kconfig
116+++ b/lib/efi_loader/Kconfig
Patrick Williams864cc432023-02-09 14:54:44 -0600117@@ -55,13 +55,23 @@ config EFI_VARIABLE_FILE_STORE
Patrick Williams8dd68482022-10-04 07:57:18 -0500118 stored as file /ubootefi.var on the EFI system partition.
119
120 config EFI_MM_COMM_TEE
121- bool "UEFI variables storage service via OP-TEE"
122- depends on OPTEE
123+ bool "UEFI variables storage service via the trusted world"
124+ depends on OPTEE || ARM_FFA_TRANSPORT
125 help
126+ Allowing access to the MM SP services (SPs such as StandAlonneMM, smm-gateway).
127+ When using the u-boot OP-TEE driver, StandAlonneMM is supported.
128+ When using the u-boot FF-A driver any MM SP is supported.
129+
130 If OP-TEE is present and running StandAloneMM, dispatch all UEFI
131 variable related operations to that. The application will verify,
132 authenticate and store the variables on an RPMB.
133
134+ When ARM_FFA_TRANSPORT is used, dispatch all UEFI variable related
135+ operations to the MM SP running in the secure world.
136+ A door bell mechanism is used to notify the SP when there is data in the shared
137+ MM buffer. The data is copied by u-boot to the shared buffer before issuing
138+ the door bell event.
139+
140 config EFI_VARIABLE_NO_STORE
141 bool "Don't persist non-volatile UEFI variables"
142 help
Patrick Williams8dd68482022-10-04 07:57:18 -0500143diff --git a/lib/efi_loader/efi_variable_tee.c b/lib/efi_loader/efi_variable_tee.c
Patrick Williams864cc432023-02-09 14:54:44 -0600144index dfef18435dfa..3933a24e8cdc 100644
Patrick Williams8dd68482022-10-04 07:57:18 -0500145--- a/lib/efi_loader/efi_variable_tee.c
146+++ b/lib/efi_loader/efi_variable_tee.c
Andrew Geisslerea144b032023-01-27 16:03:57 -0600147@@ -4,9 +4,12 @@
148 *
149 * Copyright (C) 2019 Linaro Ltd. <sughosh.ganu@linaro.org>
150 * Copyright (C) 2019 Linaro Ltd. <ilias.apalodimas@linaro.org>
151+ * Copyright (C) 2022 ARM Limited
152+ * Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
153 */
154
155 #include <common.h>
156+#include <dm.h>
157 #include <efi.h>
158 #include <efi_api.h>
159 #include <efi_loader.h>
160@@ -15,6 +18,36 @@
Patrick Williams8dd68482022-10-04 07:57:18 -0500161 #include <malloc.h>
162 #include <mm_communication.h>
163
164+#if (IS_ENABLED(CONFIG_ARM_FFA_TRANSPORT))
165+
166+#include <arm_ffa.h>
167+#include <cpu_func.h>
168+#include <mapmem.h>
169+
170+#ifndef FFA_SHARED_MM_BUFFER_SIZE
Andrew Geisslerea144b032023-01-27 16:03:57 -0600171+#error "FFA_SHARED_MM_BUFFER_SIZE must be defined in include/configs/<board>.h"
Patrick Williams8dd68482022-10-04 07:57:18 -0500172+#define FFA_SHARED_MM_BUFFER_SIZE 0
173+#endif
174+
175+#ifndef FFA_SHARED_MM_BUFFER_OFFSET
Andrew Geisslerea144b032023-01-27 16:03:57 -0600176+#error "FFA_SHARED_MM_BUFFER_OFFSET must be defined in include/configs/<board>.h"
Patrick Williams8dd68482022-10-04 07:57:18 -0500177+#define FFA_SHARED_MM_BUFFER_OFFSET 0
178+#endif
179+
180+#ifndef FFA_SHARED_MM_BUFFER_ADDR
Andrew Geisslerea144b032023-01-27 16:03:57 -0600181+#error "FFA_SHARED_MM_BUFFER_ADDR must be defined in include/configs/<board>.h"
Patrick Williams8dd68482022-10-04 07:57:18 -0500182+#define FFA_SHARED_MM_BUFFER_ADDR 0
183+#endif
184+
185+/* MM return codes */
186+#define MM_SUCCESS (0)
187+
Andrew Geisslerea144b032023-01-27 16:03:57 -0600188+static const char *mm_sp_svc_uuid = MM_SP_UUID;
Patrick Williams8dd68482022-10-04 07:57:18 -0500189+
Andrew Geisslerea144b032023-01-27 16:03:57 -0600190+static u16 mm_sp_id;
Patrick Williams8dd68482022-10-04 07:57:18 -0500191+
192+#endif
193+
194 extern struct efi_var_file __efi_runtime_data *efi_var_buf;
195 static efi_uintn_t max_buffer_size; /* comm + var + func + data */
196 static efi_uintn_t max_payload_size; /* func + data */
Andrew Geisslerea144b032023-01-27 16:03:57 -0600197@@ -24,6 +57,7 @@ struct mm_connection {
Patrick Williams8dd68482022-10-04 07:57:18 -0500198 u32 session;
199 };
200
201+#if (IS_ENABLED(CONFIG_OPTEE))
202 /**
203 * get_connection() - Retrieve OP-TEE session for a specific UUID.
204 *
Andrew Geisslerea144b032023-01-27 16:03:57 -0600205@@ -143,13 +177,248 @@ static efi_status_t optee_mm_communicate(void *comm_buf, ulong dsize)
Patrick Williams8dd68482022-10-04 07:57:18 -0500206
207 return ret;
208 }
209+#endif
210+
211+#if (IS_ENABLED(CONFIG_ARM_FFA_TRANSPORT))
212
213 /**
214- * mm_communicate() - Adjust the cmonnucation buffer to StandAlonneMM and send
215+ * ffa_notify_mm_sp() - Announce there is data in the shared buffer
216+ *
217+ * Notifies the MM partition in the trusted world that
218+ * data is available in the shared buffer.
219+ * This is a blocking call during which trusted world has exclusive access
220+ * to the MM shared buffer.
221+ *
222+ * Return:
223+ *
224+ * 0 on success
225+ */
Andrew Geisslerea144b032023-01-27 16:03:57 -0600226+static int ffa_notify_mm_sp(void)
Patrick Williams8dd68482022-10-04 07:57:18 -0500227+{
228+ struct ffa_send_direct_data msg = {0};
229+ int ret;
230+ int sp_event_ret = -1;
231+
232+ if (!ffa_bus_ops_get())
233+ return -EINVAL;
234+
235+ msg.data0 = FFA_SHARED_MM_BUFFER_OFFSET; /* x3 */
236+
Andrew Geisslerea144b032023-01-27 16:03:57 -0600237+ ret = ffa_bus_ops_get()->sync_send_receive(NULL, mm_sp_id, &msg, 1);
Patrick Williams8dd68482022-10-04 07:57:18 -0500238+ if (ret != 0)
239+ return ret;
240+
241+ sp_event_ret = msg.data0; /* x3 */
242+
243+ if (sp_event_ret == MM_SUCCESS)
244+ return 0;
245+
246+ /*
247+ * Failure to notify the MM SP
248+ */
249+
250+ return -EACCES;
251+}
252+
253+/**
254+ * ffa_discover_mm_sp_id() - Query the MM partition ID
255+ *
256+ * Use the FF-A driver to get the MM partition ID.
257+ * If multiple partitions are found, use the first one.
258+ * This is a boot time function.
259+ *
260+ * Return:
261+ *
262+ * 0 on success
263+ */
264+static int ffa_discover_mm_sp_id(void)
265+{
Andrew Geisslerea144b032023-01-27 16:03:57 -0600266+ u32 count = 0;
Patrick Williams8dd68482022-10-04 07:57:18 -0500267+ int ret;
268+ struct ffa_partition_info *parts_info;
269+
270+ if (!ffa_bus_ops_get())
271+ return -EINVAL;
272+
273+ /*
274+ * get from the driver the count of the SPs matching the UUID
275+ */
Andrew Geisslerea144b032023-01-27 16:03:57 -0600276+ ret = ffa_bus_ops_get()->partition_info_get(NULL, mm_sp_svc_uuid, &count, NULL);
Patrick Williams8dd68482022-10-04 07:57:18 -0500277+ if (ret != 0) {
278+ log_err("EFI: Failure in querying partitions count (error code: %d)\n", ret);
279+ return ret;
280+ }
281+
282+ if (!count) {
283+ log_info("EFI: No MM partition found\n");
284+ return ret;
285+ }
286+
287+ /*
288+ * pre-allocate a buffer to be filled by the driver
289+ * with ffa_partition_info structs
290+ */
291+
292+ log_info("EFI: Pre-allocating %d partition(s) info structures\n", count);
293+
Andrew Geisslerea144b032023-01-27 16:03:57 -0600294+ parts_info = calloc(count, sizeof(*parts_info));
Patrick Williams8dd68482022-10-04 07:57:18 -0500295+ if (!parts_info)
Andrew Geisslerea144b032023-01-27 16:03:57 -0600296+ return -ENOMEM;
Patrick Williams8dd68482022-10-04 07:57:18 -0500297+
298+ /*
299+ * ask the driver to fill the
300+ * buffer with the SPs info
301+ */
Andrew Geisslerea144b032023-01-27 16:03:57 -0600302+ ret = ffa_bus_ops_get()->partition_info_get(NULL, mm_sp_svc_uuid, &count, parts_info);
303+ if (ret) {
Patrick Williams8dd68482022-10-04 07:57:18 -0500304+ log_err("EFI: Failure in querying partition(s) info (error code: %d)\n", ret);
305+ free(parts_info);
306+ return ret;
307+ }
308+
309+ /*
310+ * MM SPs found , use the first one
311+ */
312+
313+ mm_sp_id = parts_info[0].id;
314+
315+ log_info("EFI: MM partition ID 0x%x\n", mm_sp_id);
316+
317+ free(parts_info);
318+
319+ return 0;
320+}
321+
322+/**
323+ * ffa_mm_communicate() - Exchange EFI services data with the MM partition using FF-A
324+ * @comm_buf: locally allocated communication buffer used for rx/tx
325+ * @dsize: communication buffer size
326+ *
327+ * Issues a door bell event to notify the MM partition (SP) running in OP-TEE
328+ * that there is data to read from the shared buffer.
329+ * Communication with the MM SP is performed using FF-A transport.
330+ * On the event, MM SP can read the data from the buffer and
331+ * update the MM shared buffer with response data.
332+ * The response data is copied back to the communication buffer.
333+ *
334+ * Return:
335+ *
336+ * EFI status code
337+ */
Andrew Geisslerea144b032023-01-27 16:03:57 -0600338+static efi_status_t ffa_mm_communicate(void *comm_buf, ulong comm_buf_size)
Patrick Williams8dd68482022-10-04 07:57:18 -0500339+{
340+ ulong tx_data_size;
341+ int ffa_ret;
Andrew Geisslerea144b032023-01-27 16:03:57 -0600342+ efi_status_t efi_ret;
Patrick Williams8dd68482022-10-04 07:57:18 -0500343+ struct efi_mm_communicate_header *mm_hdr;
344+ void *virt_shared_buf;
345+
346+ if (!comm_buf)
347+ return EFI_INVALID_PARAMETER;
348+
349+ /* Discover MM partition ID at boot time */
350+ if (!mm_sp_id && ffa_discover_mm_sp_id() != 0) {
351+ log_err("EFI: Failure to discover MM partition ID at boot time\n");
352+ return EFI_UNSUPPORTED;
353+ }
354+
355+ mm_hdr = (struct efi_mm_communicate_header *)comm_buf;
356+ tx_data_size = mm_hdr->message_len + sizeof(efi_guid_t) + sizeof(size_t);
357+
358+ if (comm_buf_size != tx_data_size || tx_data_size > FFA_SHARED_MM_BUFFER_SIZE)
359+ return EFI_INVALID_PARAMETER;
360+
361+ /* Copy the data to the shared buffer */
362+
363+ virt_shared_buf = (void *)map_sysmem((phys_addr_t)FFA_SHARED_MM_BUFFER_ADDR, 0);
Andrew Geisslerea144b032023-01-27 16:03:57 -0600364+ memcpy(virt_shared_buf, comm_buf, tx_data_size);
Patrick Williams8dd68482022-10-04 07:57:18 -0500365+
366+ /*
367+ * The secure world might have cache disabled for
368+ * the device region used for shared buffer (which is the case for Optee).
369+ * In this case, the secure world reads the data from DRAM.
370+ * Let's flush the cache so the DRAM is updated with the latest data.
371+ */
372+ #ifdef CONFIG_ARM64
373+ invalidate_dcache_all();
374+ #endif
375+
376+ /* Announce there is data in the shared buffer */
377+
378+ ffa_ret = ffa_notify_mm_sp();
Patrick Williams8dd68482022-10-04 07:57:18 -0500379+
380+ switch (ffa_ret) {
381+ case 0:
382+ {
383+ ulong rx_data_size;
384+ /* Copy the MM SP response from the shared buffer to the communication buffer */
385+ rx_data_size = ((struct efi_mm_communicate_header *)virt_shared_buf)->message_len +
386+ sizeof(efi_guid_t) +
387+ sizeof(size_t);
388+
389+ if (rx_data_size > comm_buf_size) {
Andrew Geisslerea144b032023-01-27 16:03:57 -0600390+ efi_ret = EFI_OUT_OF_RESOURCES;
391+ break;
Patrick Williams8dd68482022-10-04 07:57:18 -0500392+ }
393+
Andrew Geisslerea144b032023-01-27 16:03:57 -0600394+ memcpy(comm_buf, virt_shared_buf, rx_data_size);
395+ efi_ret = EFI_SUCCESS;
396+ break;
Patrick Williams8dd68482022-10-04 07:57:18 -0500397+ }
398+ case -EINVAL:
Andrew Geisslerea144b032023-01-27 16:03:57 -0600399+ efi_ret = EFI_DEVICE_ERROR;
400+ break;
Patrick Williams8dd68482022-10-04 07:57:18 -0500401+ case -EPERM:
Andrew Geisslerea144b032023-01-27 16:03:57 -0600402+ efi_ret = EFI_INVALID_PARAMETER;
403+ break;
Patrick Williams8dd68482022-10-04 07:57:18 -0500404+ case -EACCES:
Andrew Geisslerea144b032023-01-27 16:03:57 -0600405+ efi_ret = EFI_ACCESS_DENIED;
406+ break;
Patrick Williams8dd68482022-10-04 07:57:18 -0500407+ case -EBUSY:
Andrew Geisslerea144b032023-01-27 16:03:57 -0600408+ efi_ret = EFI_OUT_OF_RESOURCES;
409+ break;
Patrick Williams8dd68482022-10-04 07:57:18 -0500410+ default:
Andrew Geisslerea144b032023-01-27 16:03:57 -0600411+ efi_ret = EFI_ACCESS_DENIED;
Patrick Williams8dd68482022-10-04 07:57:18 -0500412+ }
Andrew Geisslerea144b032023-01-27 16:03:57 -0600413+
414+ unmap_sysmem(virt_shared_buf);
415+ return efi_ret;
Patrick Williams8dd68482022-10-04 07:57:18 -0500416+}
417+#endif
418+
419+/**
Andrew Geisslerea144b032023-01-27 16:03:57 -0600420+ * select_ffa_mm_comms() - checks FF-A support availability
421+ *
422+ * Making sure FF-A is compiled in. If that's the case try to discover
423+ * the FF-A bus.
424+ *
425+ * Return:
426+ *
427+ * 0: FF-A ready for use. Otherwise, failure
428+ */
429+static efi_status_t select_ffa_mm_comms(void)
430+{
431+ efi_status_t ret = EFI_UNSUPPORTED;
432+#if (IS_ENABLED(CONFIG_ARM_FFA_TRANSPORT))
433+ ret = ffa_bus_discover(NULL);
434+ if (ret)
435+ ret = EFI_NOT_READY;
436+#endif
437+ return ret;
438+}
439+
440+/**
Patrick Williams8dd68482022-10-04 07:57:18 -0500441+ * mm_communicate() - Adjust the communication buffer to the MM SP and send
442 * it to OP-TEE
443 *
444- * @comm_buf: locally allocted communcation buffer
445+ * @comm_buf: locally allocated communication buffer
446 * @dsize: buffer size
447+ *
Andrew Geisslerea144b032023-01-27 16:03:57 -0600448+ * The SP (also called partition) can be any MM SP such as StandAlonneMM or smm-gateway.
Patrick Williams8dd68482022-10-04 07:57:18 -0500449+ * The comm_buf format is the same for both partitions.
450+ * When using the u-boot OP-TEE driver, StandAlonneMM is supported.
Andrew Geisslerea144b032023-01-27 16:03:57 -0600451+ * When using the u-boot FF-A driver, any MM SP is supported.
Patrick Williams8dd68482022-10-04 07:57:18 -0500452+ *
453 * Return: status code
454 */
Andrew Geisslerea144b032023-01-27 16:03:57 -0600455 static efi_status_t mm_communicate(u8 *comm_buf, efi_uintn_t dsize)
456@@ -162,7 +431,17 @@ static efi_status_t mm_communicate(u8 *comm_buf, efi_uintn_t dsize)
Patrick Williams8dd68482022-10-04 07:57:18 -0500457 mm_hdr = (struct efi_mm_communicate_header *)comm_buf;
458 var_hdr = (struct smm_variable_communicate_header *)mm_hdr->data;
459
Andrew Geisslerea144b032023-01-27 16:03:57 -0600460- ret = optee_mm_communicate(comm_buf, dsize);
461+ ret = select_ffa_mm_comms();
462+ if (ret != EFI_SUCCESS) {
463+#if (IS_ENABLED(CONFIG_OPTEE))
464+ ret = optee_mm_communicate(comm_buf, dsize);
465+#endif
466+ } else {
467+#if (IS_ENABLED(CONFIG_ARM_FFA_TRANSPORT))
468+ ret = ffa_mm_communicate(comm_buf, dsize);
469+#endif
470+ }
471+
Patrick Williams8dd68482022-10-04 07:57:18 -0500472 if (ret != EFI_SUCCESS) {
473 log_err("%s failed!\n", __func__);
474 return ret;
Andrew Geisslerea144b032023-01-27 16:03:57 -0600475@@ -258,6 +537,13 @@ efi_status_t EFIAPI get_max_payload(efi_uintn_t *size)
Patrick Williams8dd68482022-10-04 07:57:18 -0500476 goto out;
477 }
478 *size = var_payload->size;
479+
480+ #if (IS_ENABLED(CONFIG_ARM_FFA_TRANSPORT))
481+ if (*size > FFA_SHARED_MM_BUFFER_SIZE)
482+ *size = FFA_SHARED_MM_BUFFER_SIZE - MM_COMMUNICATE_HEADER_SIZE -
483+ MM_VARIABLE_COMMUNICATE_SIZE;
484+ #endif
485+
486 /*
487 * There seems to be a bug in EDK2 miscalculating the boundaries and
488 * size checks, so deduct 2 more bytes to fulfill this requirement. Fix
Andrew Geisslerea144b032023-01-27 16:03:57 -0600489@@ -697,7 +983,7 @@ void efi_variables_boot_exit_notify(void)
Patrick Williams8dd68482022-10-04 07:57:18 -0500490 ret = EFI_NOT_FOUND;
491
492 if (ret != EFI_SUCCESS)
493- log_err("Unable to notify StMM for ExitBootServices\n");
494+ log_err("Unable to notify the MM partition for ExitBootServices\n");
495 free(comm_buf);
496
497 /*
498--
Patrick Williams864cc432023-02-09 14:54:44 -06004992.39.1
Patrick Williams8dd68482022-10-04 07:57:18 -0500500