blob: e9ffd6bb9fe5e897accc5109298dad52002a0ea8 [file] [log] [blame]
Andrew Geisslerea144b032023-01-27 16:03:57 -06001From cefc1d101c62e62e66f9cbf1775defde7d2c3d27 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
Andrew Geisslerea144b032023-01-27 16:03:57 -06004Subject: [PATCH 09/25] 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
Andrew Geisslerea144b032023-01-27 16:03:57 -060082---
83 include/mm_communication.h | 5 +
Patrick Williams8dd68482022-10-04 07:57:18 -050084 lib/efi_loader/Kconfig | 14 +-
Andrew Geisslerea144b032023-01-27 16:03:57 -060085 lib/efi_loader/efi_variable_tee.c | 294 +++++++++++++++++++++++++++++-
86 3 files changed, 307 insertions(+), 6 deletions(-)
Patrick Williams8dd68482022-10-04 07:57:18 -050087
Patrick Williams8dd68482022-10-04 07:57:18 -050088diff --git a/include/mm_communication.h b/include/mm_communication.h
Andrew Geisslerea144b032023-01-27 16:03:57 -060089index e65fbde60d..d409bed777 100644
Patrick Williams8dd68482022-10-04 07:57:18 -050090--- a/include/mm_communication.h
91+++ b/include/mm_communication.h
Andrew Geisslerea144b032023-01-27 16:03:57 -060092@@ -6,6 +6,8 @@
93 * Copyright (c) 2017, Intel Corporation. All rights reserved.
94 * Copyright (C) 2020 Linaro Ltd. <sughosh.ganu@linaro.org>
95 * Copyright (C) 2020 Linaro Ltd. <ilias.apalodimas@linaro.org>
96+ * (C) Copyright 2022 ARM Limited
97+ * Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
98 */
99
100 #ifndef _MM_COMMUNICATION_H_
101@@ -13,6 +15,9 @@
Patrick Williams8dd68482022-10-04 07:57:18 -0500102
103 #include <part_efi.h>
104
105+/* MM service UUID string (big-endian format). This UUID is common across all MM SPs */
106+#define MM_SP_UUID "33d532ed-e699-0942-c09c-a798d9cd722d"
107+
108 /*
109 * Interface to the pseudo Trusted Application (TA), which provides a
110 * communication channel with the Standalone MM (Management Mode)
Patrick Williams8dd68482022-10-04 07:57:18 -0500111diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
Andrew Geisslerea144b032023-01-27 16:03:57 -0600112index b8fb2701a7..d292f57244 100644
Patrick Williams8dd68482022-10-04 07:57:18 -0500113--- a/lib/efi_loader/Kconfig
114+++ b/lib/efi_loader/Kconfig
Andrew Geisslerea144b032023-01-27 16:03:57 -0600115@@ -61,13 +61,23 @@ config EFI_VARIABLE_FILE_STORE
Patrick Williams8dd68482022-10-04 07:57:18 -0500116 stored as file /ubootefi.var on the EFI system partition.
117
118 config EFI_MM_COMM_TEE
119- bool "UEFI variables storage service via OP-TEE"
120- depends on OPTEE
121+ bool "UEFI variables storage service via the trusted world"
122+ depends on OPTEE || ARM_FFA_TRANSPORT
123 help
124+ Allowing access to the MM SP services (SPs such as StandAlonneMM, smm-gateway).
125+ When using the u-boot OP-TEE driver, StandAlonneMM is supported.
126+ When using the u-boot FF-A driver any MM SP is supported.
127+
128 If OP-TEE is present and running StandAloneMM, dispatch all UEFI
129 variable related operations to that. The application will verify,
130 authenticate and store the variables on an RPMB.
131
132+ When ARM_FFA_TRANSPORT is used, dispatch all UEFI variable related
133+ operations to the MM SP running in the secure world.
134+ A door bell mechanism is used to notify the SP when there is data in the shared
135+ MM buffer. The data is copied by u-boot to the shared buffer before issuing
136+ the door bell event.
137+
138 config EFI_VARIABLE_NO_STORE
139 bool "Don't persist non-volatile UEFI variables"
140 help
Patrick Williams8dd68482022-10-04 07:57:18 -0500141diff --git a/lib/efi_loader/efi_variable_tee.c b/lib/efi_loader/efi_variable_tee.c
Andrew Geisslerea144b032023-01-27 16:03:57 -0600142index dfef18435d..3933a24e8c 100644
Patrick Williams8dd68482022-10-04 07:57:18 -0500143--- a/lib/efi_loader/efi_variable_tee.c
144+++ b/lib/efi_loader/efi_variable_tee.c
Andrew Geisslerea144b032023-01-27 16:03:57 -0600145@@ -4,9 +4,12 @@
146 *
147 * Copyright (C) 2019 Linaro Ltd. <sughosh.ganu@linaro.org>
148 * Copyright (C) 2019 Linaro Ltd. <ilias.apalodimas@linaro.org>
149+ * Copyright (C) 2022 ARM Limited
150+ * Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
151 */
152
153 #include <common.h>
154+#include <dm.h>
155 #include <efi.h>
156 #include <efi_api.h>
157 #include <efi_loader.h>
158@@ -15,6 +18,36 @@
Patrick Williams8dd68482022-10-04 07:57:18 -0500159 #include <malloc.h>
160 #include <mm_communication.h>
161
162+#if (IS_ENABLED(CONFIG_ARM_FFA_TRANSPORT))
163+
164+#include <arm_ffa.h>
165+#include <cpu_func.h>
166+#include <mapmem.h>
167+
168+#ifndef FFA_SHARED_MM_BUFFER_SIZE
Andrew Geisslerea144b032023-01-27 16:03:57 -0600169+#error "FFA_SHARED_MM_BUFFER_SIZE must be defined in include/configs/<board>.h"
Patrick Williams8dd68482022-10-04 07:57:18 -0500170+#define FFA_SHARED_MM_BUFFER_SIZE 0
171+#endif
172+
173+#ifndef FFA_SHARED_MM_BUFFER_OFFSET
Andrew Geisslerea144b032023-01-27 16:03:57 -0600174+#error "FFA_SHARED_MM_BUFFER_OFFSET must be defined in include/configs/<board>.h"
Patrick Williams8dd68482022-10-04 07:57:18 -0500175+#define FFA_SHARED_MM_BUFFER_OFFSET 0
176+#endif
177+
178+#ifndef FFA_SHARED_MM_BUFFER_ADDR
Andrew Geisslerea144b032023-01-27 16:03:57 -0600179+#error "FFA_SHARED_MM_BUFFER_ADDR must be defined in include/configs/<board>.h"
Patrick Williams8dd68482022-10-04 07:57:18 -0500180+#define FFA_SHARED_MM_BUFFER_ADDR 0
181+#endif
182+
183+/* MM return codes */
184+#define MM_SUCCESS (0)
185+
Andrew Geisslerea144b032023-01-27 16:03:57 -0600186+static const char *mm_sp_svc_uuid = MM_SP_UUID;
Patrick Williams8dd68482022-10-04 07:57:18 -0500187+
Andrew Geisslerea144b032023-01-27 16:03:57 -0600188+static u16 mm_sp_id;
Patrick Williams8dd68482022-10-04 07:57:18 -0500189+
190+#endif
191+
192 extern struct efi_var_file __efi_runtime_data *efi_var_buf;
193 static efi_uintn_t max_buffer_size; /* comm + var + func + data */
194 static efi_uintn_t max_payload_size; /* func + data */
Andrew Geisslerea144b032023-01-27 16:03:57 -0600195@@ -24,6 +57,7 @@ struct mm_connection {
Patrick Williams8dd68482022-10-04 07:57:18 -0500196 u32 session;
197 };
198
199+#if (IS_ENABLED(CONFIG_OPTEE))
200 /**
201 * get_connection() - Retrieve OP-TEE session for a specific UUID.
202 *
Andrew Geisslerea144b032023-01-27 16:03:57 -0600203@@ -143,13 +177,248 @@ static efi_status_t optee_mm_communicate(void *comm_buf, ulong dsize)
Patrick Williams8dd68482022-10-04 07:57:18 -0500204
205 return ret;
206 }
207+#endif
208+
209+#if (IS_ENABLED(CONFIG_ARM_FFA_TRANSPORT))
210
211 /**
212- * mm_communicate() - Adjust the cmonnucation buffer to StandAlonneMM and send
213+ * ffa_notify_mm_sp() - Announce there is data in the shared buffer
214+ *
215+ * Notifies the MM partition in the trusted world that
216+ * data is available in the shared buffer.
217+ * This is a blocking call during which trusted world has exclusive access
218+ * to the MM shared buffer.
219+ *
220+ * Return:
221+ *
222+ * 0 on success
223+ */
Andrew Geisslerea144b032023-01-27 16:03:57 -0600224+static int ffa_notify_mm_sp(void)
Patrick Williams8dd68482022-10-04 07:57:18 -0500225+{
226+ struct ffa_send_direct_data msg = {0};
227+ int ret;
228+ int sp_event_ret = -1;
229+
230+ if (!ffa_bus_ops_get())
231+ return -EINVAL;
232+
233+ msg.data0 = FFA_SHARED_MM_BUFFER_OFFSET; /* x3 */
234+
Andrew Geisslerea144b032023-01-27 16:03:57 -0600235+ ret = ffa_bus_ops_get()->sync_send_receive(NULL, mm_sp_id, &msg, 1);
Patrick Williams8dd68482022-10-04 07:57:18 -0500236+ if (ret != 0)
237+ return ret;
238+
239+ sp_event_ret = msg.data0; /* x3 */
240+
241+ if (sp_event_ret == MM_SUCCESS)
242+ return 0;
243+
244+ /*
245+ * Failure to notify the MM SP
246+ */
247+
248+ return -EACCES;
249+}
250+
251+/**
252+ * ffa_discover_mm_sp_id() - Query the MM partition ID
253+ *
254+ * Use the FF-A driver to get the MM partition ID.
255+ * If multiple partitions are found, use the first one.
256+ * This is a boot time function.
257+ *
258+ * Return:
259+ *
260+ * 0 on success
261+ */
262+static int ffa_discover_mm_sp_id(void)
263+{
Andrew Geisslerea144b032023-01-27 16:03:57 -0600264+ u32 count = 0;
Patrick Williams8dd68482022-10-04 07:57:18 -0500265+ int ret;
266+ struct ffa_partition_info *parts_info;
267+
268+ if (!ffa_bus_ops_get())
269+ return -EINVAL;
270+
271+ /*
272+ * get from the driver the count of the SPs matching the UUID
273+ */
Andrew Geisslerea144b032023-01-27 16:03:57 -0600274+ ret = ffa_bus_ops_get()->partition_info_get(NULL, mm_sp_svc_uuid, &count, NULL);
Patrick Williams8dd68482022-10-04 07:57:18 -0500275+ if (ret != 0) {
276+ log_err("EFI: Failure in querying partitions count (error code: %d)\n", ret);
277+ return ret;
278+ }
279+
280+ if (!count) {
281+ log_info("EFI: No MM partition found\n");
282+ return ret;
283+ }
284+
285+ /*
286+ * pre-allocate a buffer to be filled by the driver
287+ * with ffa_partition_info structs
288+ */
289+
290+ log_info("EFI: Pre-allocating %d partition(s) info structures\n", count);
291+
Andrew Geisslerea144b032023-01-27 16:03:57 -0600292+ parts_info = calloc(count, sizeof(*parts_info));
Patrick Williams8dd68482022-10-04 07:57:18 -0500293+ if (!parts_info)
Andrew Geisslerea144b032023-01-27 16:03:57 -0600294+ return -ENOMEM;
Patrick Williams8dd68482022-10-04 07:57:18 -0500295+
296+ /*
297+ * ask the driver to fill the
298+ * buffer with the SPs info
299+ */
Andrew Geisslerea144b032023-01-27 16:03:57 -0600300+ ret = ffa_bus_ops_get()->partition_info_get(NULL, mm_sp_svc_uuid, &count, parts_info);
301+ if (ret) {
Patrick Williams8dd68482022-10-04 07:57:18 -0500302+ log_err("EFI: Failure in querying partition(s) info (error code: %d)\n", ret);
303+ free(parts_info);
304+ return ret;
305+ }
306+
307+ /*
308+ * MM SPs found , use the first one
309+ */
310+
311+ mm_sp_id = parts_info[0].id;
312+
313+ log_info("EFI: MM partition ID 0x%x\n", mm_sp_id);
314+
315+ free(parts_info);
316+
317+ return 0;
318+}
319+
320+/**
321+ * ffa_mm_communicate() - Exchange EFI services data with the MM partition using FF-A
322+ * @comm_buf: locally allocated communication buffer used for rx/tx
323+ * @dsize: communication buffer size
324+ *
325+ * Issues a door bell event to notify the MM partition (SP) running in OP-TEE
326+ * that there is data to read from the shared buffer.
327+ * Communication with the MM SP is performed using FF-A transport.
328+ * On the event, MM SP can read the data from the buffer and
329+ * update the MM shared buffer with response data.
330+ * The response data is copied back to the communication buffer.
331+ *
332+ * Return:
333+ *
334+ * EFI status code
335+ */
Andrew Geisslerea144b032023-01-27 16:03:57 -0600336+static efi_status_t ffa_mm_communicate(void *comm_buf, ulong comm_buf_size)
Patrick Williams8dd68482022-10-04 07:57:18 -0500337+{
338+ ulong tx_data_size;
339+ int ffa_ret;
Andrew Geisslerea144b032023-01-27 16:03:57 -0600340+ efi_status_t efi_ret;
Patrick Williams8dd68482022-10-04 07:57:18 -0500341+ struct efi_mm_communicate_header *mm_hdr;
342+ void *virt_shared_buf;
343+
344+ if (!comm_buf)
345+ return EFI_INVALID_PARAMETER;
346+
347+ /* Discover MM partition ID at boot time */
348+ if (!mm_sp_id && ffa_discover_mm_sp_id() != 0) {
349+ log_err("EFI: Failure to discover MM partition ID at boot time\n");
350+ return EFI_UNSUPPORTED;
351+ }
352+
353+ mm_hdr = (struct efi_mm_communicate_header *)comm_buf;
354+ tx_data_size = mm_hdr->message_len + sizeof(efi_guid_t) + sizeof(size_t);
355+
356+ if (comm_buf_size != tx_data_size || tx_data_size > FFA_SHARED_MM_BUFFER_SIZE)
357+ return EFI_INVALID_PARAMETER;
358+
359+ /* Copy the data to the shared buffer */
360+
361+ virt_shared_buf = (void *)map_sysmem((phys_addr_t)FFA_SHARED_MM_BUFFER_ADDR, 0);
Andrew Geisslerea144b032023-01-27 16:03:57 -0600362+ memcpy(virt_shared_buf, comm_buf, tx_data_size);
Patrick Williams8dd68482022-10-04 07:57:18 -0500363+
364+ /*
365+ * The secure world might have cache disabled for
366+ * the device region used for shared buffer (which is the case for Optee).
367+ * In this case, the secure world reads the data from DRAM.
368+ * Let's flush the cache so the DRAM is updated with the latest data.
369+ */
370+ #ifdef CONFIG_ARM64
371+ invalidate_dcache_all();
372+ #endif
373+
374+ /* Announce there is data in the shared buffer */
375+
376+ ffa_ret = ffa_notify_mm_sp();
Patrick Williams8dd68482022-10-04 07:57:18 -0500377+
378+ switch (ffa_ret) {
379+ case 0:
380+ {
381+ ulong rx_data_size;
382+ /* Copy the MM SP response from the shared buffer to the communication buffer */
383+ rx_data_size = ((struct efi_mm_communicate_header *)virt_shared_buf)->message_len +
384+ sizeof(efi_guid_t) +
385+ sizeof(size_t);
386+
387+ if (rx_data_size > comm_buf_size) {
Andrew Geisslerea144b032023-01-27 16:03:57 -0600388+ efi_ret = EFI_OUT_OF_RESOURCES;
389+ break;
Patrick Williams8dd68482022-10-04 07:57:18 -0500390+ }
391+
Andrew Geisslerea144b032023-01-27 16:03:57 -0600392+ memcpy(comm_buf, virt_shared_buf, rx_data_size);
393+ efi_ret = EFI_SUCCESS;
394+ break;
Patrick Williams8dd68482022-10-04 07:57:18 -0500395+ }
396+ case -EINVAL:
Andrew Geisslerea144b032023-01-27 16:03:57 -0600397+ efi_ret = EFI_DEVICE_ERROR;
398+ break;
Patrick Williams8dd68482022-10-04 07:57:18 -0500399+ case -EPERM:
Andrew Geisslerea144b032023-01-27 16:03:57 -0600400+ efi_ret = EFI_INVALID_PARAMETER;
401+ break;
Patrick Williams8dd68482022-10-04 07:57:18 -0500402+ case -EACCES:
Andrew Geisslerea144b032023-01-27 16:03:57 -0600403+ efi_ret = EFI_ACCESS_DENIED;
404+ break;
Patrick Williams8dd68482022-10-04 07:57:18 -0500405+ case -EBUSY:
Andrew Geisslerea144b032023-01-27 16:03:57 -0600406+ efi_ret = EFI_OUT_OF_RESOURCES;
407+ break;
Patrick Williams8dd68482022-10-04 07:57:18 -0500408+ default:
Andrew Geisslerea144b032023-01-27 16:03:57 -0600409+ efi_ret = EFI_ACCESS_DENIED;
Patrick Williams8dd68482022-10-04 07:57:18 -0500410+ }
Andrew Geisslerea144b032023-01-27 16:03:57 -0600411+
412+ unmap_sysmem(virt_shared_buf);
413+ return efi_ret;
Patrick Williams8dd68482022-10-04 07:57:18 -0500414+}
415+#endif
416+
417+/**
Andrew Geisslerea144b032023-01-27 16:03:57 -0600418+ * select_ffa_mm_comms() - checks FF-A support availability
419+ *
420+ * Making sure FF-A is compiled in. If that's the case try to discover
421+ * the FF-A bus.
422+ *
423+ * Return:
424+ *
425+ * 0: FF-A ready for use. Otherwise, failure
426+ */
427+static efi_status_t select_ffa_mm_comms(void)
428+{
429+ efi_status_t ret = EFI_UNSUPPORTED;
430+#if (IS_ENABLED(CONFIG_ARM_FFA_TRANSPORT))
431+ ret = ffa_bus_discover(NULL);
432+ if (ret)
433+ ret = EFI_NOT_READY;
434+#endif
435+ return ret;
436+}
437+
438+/**
Patrick Williams8dd68482022-10-04 07:57:18 -0500439+ * mm_communicate() - Adjust the communication buffer to the MM SP and send
440 * it to OP-TEE
441 *
442- * @comm_buf: locally allocted communcation buffer
443+ * @comm_buf: locally allocated communication buffer
444 * @dsize: buffer size
445+ *
Andrew Geisslerea144b032023-01-27 16:03:57 -0600446+ * The SP (also called partition) can be any MM SP such as StandAlonneMM or smm-gateway.
Patrick Williams8dd68482022-10-04 07:57:18 -0500447+ * The comm_buf format is the same for both partitions.
448+ * When using the u-boot OP-TEE driver, StandAlonneMM is supported.
Andrew Geisslerea144b032023-01-27 16:03:57 -0600449+ * When using the u-boot FF-A driver, any MM SP is supported.
Patrick Williams8dd68482022-10-04 07:57:18 -0500450+ *
451 * Return: status code
452 */
Andrew Geisslerea144b032023-01-27 16:03:57 -0600453 static efi_status_t mm_communicate(u8 *comm_buf, efi_uintn_t dsize)
454@@ -162,7 +431,17 @@ static efi_status_t mm_communicate(u8 *comm_buf, efi_uintn_t dsize)
Patrick Williams8dd68482022-10-04 07:57:18 -0500455 mm_hdr = (struct efi_mm_communicate_header *)comm_buf;
456 var_hdr = (struct smm_variable_communicate_header *)mm_hdr->data;
457
Andrew Geisslerea144b032023-01-27 16:03:57 -0600458- ret = optee_mm_communicate(comm_buf, dsize);
459+ ret = select_ffa_mm_comms();
460+ if (ret != EFI_SUCCESS) {
461+#if (IS_ENABLED(CONFIG_OPTEE))
462+ ret = optee_mm_communicate(comm_buf, dsize);
463+#endif
464+ } else {
465+#if (IS_ENABLED(CONFIG_ARM_FFA_TRANSPORT))
466+ ret = ffa_mm_communicate(comm_buf, dsize);
467+#endif
468+ }
469+
Patrick Williams8dd68482022-10-04 07:57:18 -0500470 if (ret != EFI_SUCCESS) {
471 log_err("%s failed!\n", __func__);
472 return ret;
Andrew Geisslerea144b032023-01-27 16:03:57 -0600473@@ -258,6 +537,13 @@ efi_status_t EFIAPI get_max_payload(efi_uintn_t *size)
Patrick Williams8dd68482022-10-04 07:57:18 -0500474 goto out;
475 }
476 *size = var_payload->size;
477+
478+ #if (IS_ENABLED(CONFIG_ARM_FFA_TRANSPORT))
479+ if (*size > FFA_SHARED_MM_BUFFER_SIZE)
480+ *size = FFA_SHARED_MM_BUFFER_SIZE - MM_COMMUNICATE_HEADER_SIZE -
481+ MM_VARIABLE_COMMUNICATE_SIZE;
482+ #endif
483+
484 /*
485 * There seems to be a bug in EDK2 miscalculating the boundaries and
486 * size checks, so deduct 2 more bytes to fulfill this requirement. Fix
Andrew Geisslerea144b032023-01-27 16:03:57 -0600487@@ -697,7 +983,7 @@ void efi_variables_boot_exit_notify(void)
Patrick Williams8dd68482022-10-04 07:57:18 -0500488 ret = EFI_NOT_FOUND;
489
490 if (ret != EFI_SUCCESS)
491- log_err("Unable to notify StMM for ExitBootServices\n");
492+ log_err("Unable to notify the MM partition for ExitBootServices\n");
493 free(comm_buf);
494
495 /*
496--
4972.17.1
498