1 // SPDX-License-Identifier: GPL-2.0+
3 * EFI variable service via OP-TEE
13 #if CONFIG_IS_ENABLED(ARM_FFA_TRANSPORT)
20 #include <efi_loader.h>
21 #include <efi_variable.h>
24 #include <mm_communication.h>
27 #if CONFIG_IS_ENABLED(ARM_FFA_TRANSPORT)
29 #define MM_SUCCESS (0)
30 #define MM_NOT_SUPPORTED (-1)
31 #define MM_INVALID_PARAMETER (-2)
32 #define MM_DENIED (-3)
33 #define MM_NO_MEMORY (-5)
35 static const char *mm_sp_svc_uuid = MM_SP_UUID;
39 extern struct efi_var_file __efi_runtime_data *efi_var_buf;
40 static efi_uintn_t max_buffer_size; /* comm + var + func + data */
41 static efi_uintn_t max_payload_size; /* func + data */
43 struct mm_connection {
49 * get_connection() - Retrieve OP-TEE session for a specific UUID.
51 * @conn: session buffer to fill
54 static int get_connection(struct mm_connection *conn)
56 static const struct tee_optee_ta_uuid uuid = PTA_STMM_UUID;
57 struct udevice *tee = NULL;
58 struct tee_open_session_arg arg;
61 tee = tee_find_device(tee, NULL, NULL, NULL);
65 memset(&arg, 0, sizeof(arg));
66 tee_optee_ta_uuid_to_octets(arg.uuid, &uuid);
67 rc = tee_open_session(tee, &arg, 0, NULL);
71 /* Check the internal OP-TEE result */
72 if (arg.ret != TEE_SUCCESS) {
78 conn->session = arg.session;
86 * optee_mm_communicate() - Pass a buffer to StandaloneMM running in OP-TEE
88 * @comm_buf: locally allocted communcation buffer
92 static efi_status_t optee_mm_communicate(void *comm_buf, ulong dsize)
96 struct efi_mm_communicate_header *mm_hdr;
97 struct mm_connection conn = { NULL, 0 };
98 struct tee_invoke_arg arg;
99 struct tee_param param[2];
100 struct tee_shm *shm = NULL;
104 return EFI_INVALID_PARAMETER;
106 mm_hdr = (struct efi_mm_communicate_header *)comm_buf;
107 buf_size = mm_hdr->message_len + sizeof(efi_guid_t) + sizeof(size_t);
109 if (dsize != buf_size)
110 return EFI_INVALID_PARAMETER;
112 rc = get_connection(&conn);
114 log_err("Unable to open OP-TEE session (err=%d)\n", rc);
115 return EFI_UNSUPPORTED;
118 if (tee_shm_register(conn.tee, comm_buf, buf_size, 0, &shm)) {
119 log_err("Unable to register shared memory\n");
120 tee_close_session(conn.tee, conn.session);
121 return EFI_UNSUPPORTED;
124 memset(&arg, 0, sizeof(arg));
125 arg.func = PTA_STMM_CMDID_COMMUNICATE;
126 arg.session = conn.session;
128 memset(param, 0, sizeof(param));
129 param[0].attr = TEE_PARAM_ATTR_TYPE_MEMREF_INOUT;
130 param[0].u.memref.size = buf_size;
131 param[0].u.memref.shm = shm;
132 param[1].attr = TEE_PARAM_ATTR_TYPE_VALUE_OUTPUT;
134 rc = tee_invoke_func(conn.tee, &arg, 2, param);
136 tee_close_session(conn.tee, conn.session);
138 return EFI_DEVICE_ERROR;
139 if (arg.ret == TEE_ERROR_EXCESS_DATA)
140 log_err("Variable payload too large\n");
141 if (arg.ret != TEE_SUCCESS)
142 return EFI_DEVICE_ERROR;
144 switch (param[1].u.value.a) {
145 case ARM_SVC_SPM_RET_SUCCESS:
149 case ARM_SVC_SPM_RET_INVALID_PARAMS:
150 ret = EFI_INVALID_PARAMETER;
153 case ARM_SVC_SPM_RET_DENIED:
154 ret = EFI_ACCESS_DENIED;
157 case ARM_SVC_SPM_RET_NO_MEMORY:
158 ret = EFI_OUT_OF_RESOURCES;
162 ret = EFI_ACCESS_DENIED;
168 #if CONFIG_IS_ENABLED(ARM_FFA_TRANSPORT)
170 * ffa_notify_mm_sp() - Announce there is data in the shared buffer
172 * Notify the MM partition in the trusted world that
173 * data is available in the shared buffer.
174 * This is a blocking call during which trusted world has exclusive access
175 * to the MM shared buffer.
181 static int ffa_notify_mm_sp(void)
183 struct ffa_send_direct_data msg = {0};
188 ret = uclass_first_device_err(UCLASS_FFA, &dev);
190 log_err("EFI: Cannot find FF-A bus device, notify MM SP failure\n");
194 msg.data0 = CONFIG_FFA_SHARED_MM_BUF_OFFSET; /* x3 */
196 ret = ffa_sync_send_receive(dev, mm_sp_id, &msg, 1);
200 sp_event_ret = msg.data0; /* x3 */
202 switch (sp_event_ret) {
206 case MM_NOT_SUPPORTED:
209 case MM_INVALID_PARAMETER:
226 * ffa_discover_mm_sp_id() - Query the MM partition ID
228 * Use the FF-A driver to get the MM partition ID.
229 * If multiple partitions are found, use the first one.
230 * This is a boot time function.
236 static int ffa_discover_mm_sp_id(void)
240 struct ffa_partition_desc *descs;
243 ret = uclass_first_device_err(UCLASS_FFA, &dev);
245 log_err("EFI: Cannot find FF-A bus device, MM SP discovery failure\n");
249 /* Ask the driver to fill the buffer with the SPs info */
250 ret = ffa_partition_info_get(dev, mm_sp_svc_uuid, &count, &descs);
252 log_err("EFI: Failure in querying SPs info (%d), MM SP discovery failure\n", ret);
256 /* MM SPs found , use the first one */
258 mm_sp_id = descs[0].info.id;
260 log_info("EFI: MM partition ID 0x%x\n", mm_sp_id);
266 * ffa_mm_communicate() - Exchange EFI services data with the MM partition using FF-A
267 * @comm_buf: locally allocated communication buffer used for rx/tx
268 * @dsize: communication buffer size
270 * Issue a door bell event to notify the MM partition (SP) running in OP-TEE
271 * that there is data to read from the shared buffer.
272 * Communication with the MM SP is performed using FF-A transport.
273 * On the event, MM SP can read the data from the buffer and
274 * update the MM shared buffer with response data.
275 * The response data is copied back to the communication buffer.
281 static efi_status_t ffa_mm_communicate(void *comm_buf, ulong comm_buf_size)
285 efi_status_t efi_ret;
286 struct efi_mm_communicate_header *mm_hdr;
287 void *virt_shared_buf;
290 return EFI_INVALID_PARAMETER;
292 /* Discover MM partition ID at boot time */
293 if (!mm_sp_id && ffa_discover_mm_sp_id()) {
294 log_err("EFI: Failure to discover MM SP ID at boot time, FF-A MM comms failure\n");
295 return EFI_UNSUPPORTED;
298 mm_hdr = (struct efi_mm_communicate_header *)comm_buf;
299 tx_data_size = mm_hdr->message_len + sizeof(efi_guid_t) + sizeof(size_t);
301 if (comm_buf_size != tx_data_size || tx_data_size > CONFIG_FFA_SHARED_MM_BUF_SIZE)
302 return EFI_INVALID_PARAMETER;
304 /* Copy the data to the shared buffer */
306 virt_shared_buf = map_sysmem((phys_addr_t)CONFIG_FFA_SHARED_MM_BUF_ADDR, 0);
307 memcpy(virt_shared_buf, comm_buf, tx_data_size);
310 * The secure world might have cache disabled for
311 * the device region used for shared buffer (which is the case for Optee).
312 * In this case, the secure world reads the data from DRAM.
313 * Let's flush the cache so the DRAM is updated with the latest data.
316 invalidate_dcache_all();
319 /* Announce there is data in the shared buffer */
321 ffa_ret = ffa_notify_mm_sp();
326 /* Copy the MM SP response from the shared buffer to the communication buffer */
327 rx_data_size = ((struct efi_mm_communicate_header *)virt_shared_buf)->message_len +
331 if (rx_data_size > comm_buf_size) {
332 efi_ret = EFI_OUT_OF_RESOURCES;
336 memcpy(comm_buf, virt_shared_buf, rx_data_size);
337 efi_ret = EFI_SUCCESS;
341 efi_ret = EFI_DEVICE_ERROR;
344 efi_ret = EFI_INVALID_PARAMETER;
347 efi_ret = EFI_ACCESS_DENIED;
350 efi_ret = EFI_OUT_OF_RESOURCES;
353 efi_ret = EFI_ACCESS_DENIED;
356 unmap_sysmem(virt_shared_buf);
361 * get_mm_comms() - detect the available MM transport
363 * Make sure the FF-A bus is probed successfully
364 * which means FF-A communication with secure world works and ready
367 * If FF-A bus is not ready, use OPTEE comms.
371 * MM_COMMS_FFA or MM_COMMS_OPTEE
373 static enum mm_comms_select get_mm_comms(void)
378 ret = uclass_first_device_err(UCLASS_FFA, &dev);
380 log_debug("EFI: Cannot find FF-A bus device, trying Optee comms\n");
381 return MM_COMMS_OPTEE;
389 * mm_communicate() - Adjust the communication buffer to the MM SP and send
392 * @comm_buf: locally allocated communication buffer
393 * @dsize: buffer size
395 * The SP (also called partition) can be any MM SP such as StandAlonneMM or smm-gateway.
396 * The comm_buf format is the same for both partitions.
397 * When using the u-boot OP-TEE driver, StandAlonneMM is supported.
398 * When using the u-boot FF-A driver, any MM SP is supported.
400 * Return: status code
402 static efi_status_t mm_communicate(u8 *comm_buf, efi_uintn_t dsize)
405 struct efi_mm_communicate_header *mm_hdr;
406 struct smm_variable_communicate_header *var_hdr;
407 #if CONFIG_IS_ENABLED(ARM_FFA_TRANSPORT)
408 enum mm_comms_select mm_comms;
411 dsize += MM_COMMUNICATE_HEADER_SIZE + MM_VARIABLE_COMMUNICATE_SIZE;
412 mm_hdr = (struct efi_mm_communicate_header *)comm_buf;
413 var_hdr = (struct smm_variable_communicate_header *)mm_hdr->data;
415 #if CONFIG_IS_ENABLED(ARM_FFA_TRANSPORT)
416 mm_comms = get_mm_comms();
417 if (mm_comms == MM_COMMS_FFA)
418 ret = ffa_mm_communicate(comm_buf, dsize);
420 ret = optee_mm_communicate(comm_buf, dsize);
422 ret = optee_mm_communicate(comm_buf, dsize);
425 if (ret != EFI_SUCCESS) {
426 log_err("%s failed!\n", __func__);
430 return var_hdr->ret_status;
434 * setup_mm_hdr() - Allocate a buffer for StandAloneMM and initialize the
437 * @dptr: pointer address of the corresponding StandAloneMM
439 * @payload_size: buffer size
440 * @func: standAloneMM function number
441 * @ret: EFI return code
442 * Return: buffer or NULL
444 static u8 *setup_mm_hdr(void **dptr, efi_uintn_t payload_size,
445 efi_uintn_t func, efi_status_t *ret)
447 const efi_guid_t mm_var_guid = EFI_MM_VARIABLE_GUID;
448 struct efi_mm_communicate_header *mm_hdr;
449 struct smm_variable_communicate_header *var_hdr;
452 /* In the init function we initialize max_buffer_size with
453 * get_max_payload(). So skip the test if max_buffer_size is initialized
454 * StandAloneMM will perform similar checks and drop the buffer if it's
457 if (max_buffer_size && max_buffer_size <
458 (MM_COMMUNICATE_HEADER_SIZE +
459 MM_VARIABLE_COMMUNICATE_SIZE +
461 *ret = EFI_INVALID_PARAMETER;
465 comm_buf = calloc(1, MM_COMMUNICATE_HEADER_SIZE +
466 MM_VARIABLE_COMMUNICATE_SIZE +
469 *ret = EFI_OUT_OF_RESOURCES;
473 mm_hdr = (struct efi_mm_communicate_header *)comm_buf;
474 guidcpy(&mm_hdr->header_guid, &mm_var_guid);
475 mm_hdr->message_len = MM_VARIABLE_COMMUNICATE_SIZE + payload_size;
477 var_hdr = (struct smm_variable_communicate_header *)mm_hdr->data;
478 var_hdr->function = func;
480 *dptr = var_hdr->data;
487 * get_max_payload() - Get variable payload size from StandAloneMM.
489 * @size: size of the variable in storage
490 * Return: status code
492 efi_status_t EFIAPI get_max_payload(efi_uintn_t *size)
494 struct smm_variable_payload_size *var_payload = NULL;
495 efi_uintn_t payload_size;
500 ret = EFI_INVALID_PARAMETER;
504 payload_size = sizeof(*var_payload);
505 comm_buf = setup_mm_hdr((void **)&var_payload, payload_size,
506 SMM_VARIABLE_FUNCTION_GET_PAYLOAD_SIZE, &ret);
510 ret = mm_communicate(comm_buf, payload_size);
511 if (ret != EFI_SUCCESS)
514 /* Make sure the buffer is big enough for storing variables */
515 if (var_payload->size < MM_VARIABLE_ACCESS_HEADER_SIZE + 0x20) {
516 ret = EFI_DEVICE_ERROR;
519 *size = var_payload->size;
521 * There seems to be a bug in EDK2 miscalculating the boundaries and
522 * size checks, so deduct 2 more bytes to fulfill this requirement. Fix
523 * it up here to ensure backwards compatibility with older versions
524 * (cf. StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/EventHandle.c.
525 * sizeof (EFI_MM_COMMUNICATE_HEADER) instead the size minus the
526 * flexible array member).
528 * size is guaranteed to be > 2 due to checks on the beginning.
537 * StMM can store internal attributes and properties for variables, i.e enabling
540 static efi_status_t set_property_int(const u16 *variable_name,
541 efi_uintn_t name_size,
542 const efi_guid_t *vendor,
543 struct var_check_property *var_property)
545 struct smm_variable_var_check_property *smm_property;
546 efi_uintn_t payload_size;
550 payload_size = sizeof(*smm_property) + name_size;
551 if (payload_size > max_payload_size) {
552 ret = EFI_INVALID_PARAMETER;
555 comm_buf = setup_mm_hdr((void **)&smm_property, payload_size,
556 SMM_VARIABLE_FUNCTION_VAR_CHECK_VARIABLE_PROPERTY_SET,
561 guidcpy(&smm_property->guid, vendor);
562 smm_property->name_size = name_size;
563 memcpy(&smm_property->property, var_property,
564 sizeof(smm_property->property));
565 memcpy(smm_property->name, variable_name, name_size);
567 ret = mm_communicate(comm_buf, payload_size);
574 static efi_status_t get_property_int(const u16 *variable_name,
575 efi_uintn_t name_size,
576 const efi_guid_t *vendor,
577 struct var_check_property *var_property)
579 struct smm_variable_var_check_property *smm_property;
580 efi_uintn_t payload_size;
584 memset(var_property, 0, sizeof(*var_property));
585 payload_size = sizeof(*smm_property) + name_size;
586 if (payload_size > max_payload_size) {
587 ret = EFI_INVALID_PARAMETER;
590 comm_buf = setup_mm_hdr((void **)&smm_property, payload_size,
591 SMM_VARIABLE_FUNCTION_VAR_CHECK_VARIABLE_PROPERTY_GET,
596 guidcpy(&smm_property->guid, vendor);
597 smm_property->name_size = name_size;
598 memcpy(smm_property->name, variable_name, name_size);
600 ret = mm_communicate(comm_buf, payload_size);
602 * Currently only R/O property is supported in StMM.
603 * Variables that are not set to R/O will not set the property in StMM
604 * and the call will return EFI_NOT_FOUND. We are setting the
605 * properties to 0x0 so checking against that is enough for the
606 * EFI_NOT_FOUND case.
608 if (ret == EFI_NOT_FOUND)
610 if (ret != EFI_SUCCESS)
612 memcpy(var_property, &smm_property->property, sizeof(*var_property));
619 efi_status_t efi_get_variable_int(const u16 *variable_name,
620 const efi_guid_t *vendor,
621 u32 *attributes, efi_uintn_t *data_size,
622 void *data, u64 *timep)
624 struct var_check_property var_property;
625 struct smm_variable_access *var_acc;
626 efi_uintn_t payload_size;
627 efi_uintn_t name_size;
628 efi_uintn_t tmp_dsize;
630 efi_status_t ret, tmp;
632 if (!variable_name || !vendor || !data_size) {
633 ret = EFI_INVALID_PARAMETER;
637 /* Check payload size */
638 name_size = u16_strsize(variable_name);
639 if (name_size > max_payload_size - MM_VARIABLE_ACCESS_HEADER_SIZE) {
640 ret = EFI_INVALID_PARAMETER;
644 /* Trim output buffer size */
645 tmp_dsize = *data_size;
646 if (name_size + tmp_dsize >
647 max_payload_size - MM_VARIABLE_ACCESS_HEADER_SIZE) {
648 tmp_dsize = max_payload_size -
649 MM_VARIABLE_ACCESS_HEADER_SIZE -
653 /* Get communication buffer and initialize header */
654 payload_size = MM_VARIABLE_ACCESS_HEADER_SIZE + name_size + tmp_dsize;
655 comm_buf = setup_mm_hdr((void **)&var_acc, payload_size,
656 SMM_VARIABLE_FUNCTION_GET_VARIABLE, &ret);
660 /* Fill in contents */
661 guidcpy(&var_acc->guid, vendor);
662 var_acc->data_size = tmp_dsize;
663 var_acc->name_size = name_size;
664 var_acc->attr = attributes ? *attributes : 0;
665 memcpy(var_acc->name, variable_name, name_size);
668 ret = mm_communicate(comm_buf, payload_size);
669 if (ret != EFI_SUCCESS && ret != EFI_BUFFER_TOO_SMALL)
672 /* Update with reported data size for trimmed case */
673 *data_size = var_acc->data_size;
675 * UEFI > 2.7 needs the attributes set even if the buffer is
679 tmp = get_property_int(variable_name, name_size, vendor,
681 if (tmp != EFI_SUCCESS) {
685 *attributes = var_acc->attr;
686 if (var_property.property &
687 VAR_CHECK_VARIABLE_PROPERTY_READ_ONLY)
688 *attributes |= EFI_VARIABLE_READ_ONLY;
691 /* return if ret is EFI_BUFFER_TOO_SMALL */
692 if (ret != EFI_SUCCESS)
696 memcpy(data, (u8 *)var_acc->name + var_acc->name_size,
699 ret = EFI_INVALID_PARAMETER;
706 efi_status_t efi_get_next_variable_name_int(efi_uintn_t *variable_name_size,
710 struct smm_variable_getnext *var_getnext;
711 efi_uintn_t payload_size;
712 efi_uintn_t out_name_size;
713 efi_uintn_t in_name_size;
717 if (!variable_name_size || !variable_name || !guid) {
718 ret = EFI_INVALID_PARAMETER;
722 out_name_size = *variable_name_size;
723 in_name_size = u16_strsize(variable_name);
725 if (out_name_size < in_name_size) {
726 ret = EFI_INVALID_PARAMETER;
730 if (in_name_size > max_payload_size - MM_VARIABLE_GET_NEXT_HEADER_SIZE) {
731 ret = EFI_INVALID_PARAMETER;
735 /* Trim output buffer size */
736 if (out_name_size > max_payload_size - MM_VARIABLE_GET_NEXT_HEADER_SIZE)
737 out_name_size = max_payload_size - MM_VARIABLE_GET_NEXT_HEADER_SIZE;
739 payload_size = MM_VARIABLE_GET_NEXT_HEADER_SIZE + out_name_size;
740 comm_buf = setup_mm_hdr((void **)&var_getnext, payload_size,
741 SMM_VARIABLE_FUNCTION_GET_NEXT_VARIABLE_NAME,
746 /* Fill in contents */
747 guidcpy(&var_getnext->guid, guid);
748 var_getnext->name_size = out_name_size;
749 memcpy(var_getnext->name, variable_name, in_name_size);
750 memset((u8 *)var_getnext->name + in_name_size, 0x0,
751 out_name_size - in_name_size);
754 ret = mm_communicate(comm_buf, payload_size);
755 if (ret == EFI_SUCCESS || ret == EFI_BUFFER_TOO_SMALL) {
756 /* Update with reported data size for trimmed case */
757 *variable_name_size = var_getnext->name_size;
759 if (ret != EFI_SUCCESS)
762 guidcpy(guid, &var_getnext->guid);
763 memcpy(variable_name, var_getnext->name, var_getnext->name_size);
770 efi_status_t efi_set_variable_int(const u16 *variable_name,
771 const efi_guid_t *vendor, u32 attributes,
772 efi_uintn_t data_size, const void *data,
775 efi_status_t ret, alt_ret = EFI_SUCCESS;
776 struct var_check_property var_property;
777 struct smm_variable_access *var_acc;
778 efi_uintn_t payload_size;
779 efi_uintn_t name_size;
783 if (!variable_name || variable_name[0] == 0 || !vendor) {
784 ret = EFI_INVALID_PARAMETER;
787 if (data_size > 0 && !data) {
788 ret = EFI_INVALID_PARAMETER;
791 /* Check payload size */
792 name_size = u16_strsize(variable_name);
793 payload_size = MM_VARIABLE_ACCESS_HEADER_SIZE + name_size + data_size;
794 if (payload_size > max_payload_size) {
795 ret = EFI_INVALID_PARAMETER;
800 * Allocate the buffer early, before switching to RW (if needed)
801 * so we won't need to account for any failures in reading/setting
802 * the properties, if the allocation fails
804 comm_buf = setup_mm_hdr((void **)&var_acc, payload_size,
805 SMM_VARIABLE_FUNCTION_SET_VARIABLE, &ret);
809 ro = !!(attributes & EFI_VARIABLE_READ_ONLY);
810 attributes &= EFI_VARIABLE_MASK;
813 * The API has the ability to override RO flags. If no RO check was
814 * requested switch the variable to RW for the duration of this call
816 ret = get_property_int(variable_name, name_size, vendor,
818 if (ret != EFI_SUCCESS)
821 if (var_property.property & VAR_CHECK_VARIABLE_PROPERTY_READ_ONLY) {
822 /* Bypass r/o check */
824 var_property.property &= ~VAR_CHECK_VARIABLE_PROPERTY_READ_ONLY;
825 ret = set_property_int(variable_name, name_size, vendor, &var_property);
826 if (ret != EFI_SUCCESS)
829 ret = EFI_WRITE_PROTECTED;
834 /* Fill in contents */
835 guidcpy(&var_acc->guid, vendor);
836 var_acc->data_size = data_size;
837 var_acc->name_size = name_size;
838 var_acc->attr = attributes;
839 memcpy(var_acc->name, variable_name, name_size);
840 memcpy((u8 *)var_acc->name + name_size, data, data_size);
843 ret = mm_communicate(comm_buf, payload_size);
844 if (ret != EFI_SUCCESS)
847 if (ro && !(var_property.property & VAR_CHECK_VARIABLE_PROPERTY_READ_ONLY)) {
848 var_property.revision = VAR_CHECK_VARIABLE_PROPERTY_REVISION;
849 var_property.property |= VAR_CHECK_VARIABLE_PROPERTY_READ_ONLY;
850 var_property.attributes = attributes;
851 var_property.minsize = 1;
852 var_property.maxsize = var_acc->data_size;
853 ret = set_property_int(variable_name, name_size, vendor, &var_property);
856 if (alt_ret != EFI_SUCCESS)
859 if (!u16_strcmp(variable_name, u"PK"))
860 alt_ret = efi_init_secure_state();
863 return alt_ret == EFI_SUCCESS ? ret : alt_ret;
866 efi_status_t efi_query_variable_info_int(u32 attributes,
867 u64 *max_variable_storage_size,
868 u64 *remain_variable_storage_size,
869 u64 *max_variable_size)
871 struct smm_variable_query_info *mm_query_info;
872 efi_uintn_t payload_size;
876 payload_size = sizeof(*mm_query_info);
877 comm_buf = setup_mm_hdr((void **)&mm_query_info, payload_size,
878 SMM_VARIABLE_FUNCTION_QUERY_VARIABLE_INFO,
883 mm_query_info->attr = attributes;
884 ret = mm_communicate(comm_buf, payload_size);
885 if (ret != EFI_SUCCESS)
887 *max_variable_storage_size = mm_query_info->max_variable_storage;
888 *remain_variable_storage_size =
889 mm_query_info->remaining_variable_storage;
890 *max_variable_size = mm_query_info->max_variable_size;
898 * efi_query_variable_info() - get information about EFI variables
900 * This function implements the QueryVariableInfo() runtime service.
902 * See the Unified Extensible Firmware Interface (UEFI) specification for
905 * @attributes: bitmask to select variables to be
907 * @maximum_variable_storage_size: maximum size of storage area for the
908 * selected variable types
909 * @remaining_variable_storage_size: remaining size of storage are for the
910 * selected variable types
911 * @maximum_variable_size: maximum size of a variable of the
913 * Return: status code
915 efi_status_t EFIAPI __efi_runtime
916 efi_query_variable_info_runtime(u32 attributes, u64 *max_variable_storage_size,
917 u64 *remain_variable_storage_size,
918 u64 *max_variable_size)
920 return EFI_UNSUPPORTED;
924 * efi_set_variable_runtime() - runtime implementation of SetVariable()
926 * @variable_name: name of the variable
928 * @attributes: attributes of the variable
929 * @data_size: size of the buffer with the variable value
930 * @data: buffer with the variable value
931 * Return: status code
933 static efi_status_t __efi_runtime EFIAPI
934 efi_set_variable_runtime(u16 *variable_name, const efi_guid_t *guid,
935 u32 attributes, efi_uintn_t data_size,
938 return EFI_UNSUPPORTED;
942 * efi_variables_boot_exit_notify() - notify ExitBootServices() is called
944 void efi_variables_boot_exit_notify(void)
949 struct efi_var_file *var_buf;
951 comm_buf = setup_mm_hdr(NULL, 0,
952 SMM_VARIABLE_FUNCTION_EXIT_BOOT_SERVICE, &ret);
954 ret = mm_communicate(comm_buf, 0);
958 if (ret != EFI_SUCCESS)
959 log_err("Unable to notify the MM partition for ExitBootServices\n");
962 ret = efi_var_collect(&var_buf, &len, EFI_VARIABLE_RUNTIME_ACCESS);
963 if (ret != EFI_SUCCESS)
964 log_err("Can't populate EFI variables. No runtime variables will be available\n");
966 efi_var_buf_update(var_buf);
969 /* Update runtime service table */
970 efi_runtime_services.query_variable_info =
971 efi_query_variable_info_runtime;
972 efi_runtime_services.get_variable = efi_get_variable_runtime;
973 efi_runtime_services.get_next_variable_name =
974 efi_get_next_variable_name_runtime;
975 efi_runtime_services.set_variable = efi_set_variable_runtime;
976 efi_update_table_header_crc32(&efi_runtime_services.hdr);
980 * efi_init_variables() - initialize variable services
982 * Return: status code
984 efi_status_t efi_init_variables(void)
988 /* Create a cached copy of the variables that will be enabled on ExitBootServices() */
989 ret = efi_var_mem_init();
990 if (ret != EFI_SUCCESS)
993 ret = get_max_payload(&max_payload_size);
994 if (ret != EFI_SUCCESS)
997 max_buffer_size = MM_COMMUNICATE_HEADER_SIZE +
998 MM_VARIABLE_COMMUNICATE_SIZE +
1001 ret = efi_init_secure_state();
1002 if (ret != EFI_SUCCESS)