Add the TEE-backed runtime QueryVariableInfo() implementation for the
FF-A/MM variable backend. The runtime path uses the shared MM
communication path after ExitBootServices() and returns the variable
storage limits reported by the MM secure partition.

Reviewed-by: Simon Glass <[email protected]>
Signed-off-by: Harsimran Singh Tungal <[email protected]>

---
Changelog:
===============

v6:

Ilias:

- Restore OP-TEE runtime callbacks when FF-A runtime mode is disabled
- Rename FF-A QueryVariableInfo runtime handler with _ffa_runtime suffix

v4:

Ilias:

- Split the runtime QueryVariableInfo() support out of the combined
  runtime variable-services patch.

v3:

Ilias:

- Rename TEE/FF-A runtime handlers to private *_int_runtime names
---
 lib/efi_loader/efi_variable_tee.c | 56 ++++++++++++++++++++++++-------
 1 file changed, 43 insertions(+), 13 deletions(-)

diff --git a/lib/efi_loader/efi_variable_tee.c 
b/lib/efi_loader/efi_variable_tee.c
index b078ccce20e..0e795892bd7 100644
--- a/lib/efi_loader/efi_variable_tee.c
+++ b/lib/efi_loader/efi_variable_tee.c
@@ -1202,29 +1202,56 @@ out:
 }
 
 /**
- * efi_query_variable_info() - get information about EFI variables
+ * efi_query_variable_info_ffa_runtime() - get information about EFI variables
  *
- * This function implements the QueryVariableInfo() runtime service.
+ * This function implements the QueryVariableInfo() runtime service for
+ * OP-TEE with FF-A runtime transport.
  *
  * See the Unified Extensible Firmware Interface (UEFI) specification for
  * details.
  *
  * @attributes:                                bitmask to select variables to 
be
  *                                     queried
- * @maximum_variable_storage_size:     maximum size of storage area for the
+ * @max_variable_storage_size:         maximum size of storage area for the
  *                                     selected variable types
- * @remaining_variable_storage_size:   remaining size of storage are for the
+ * @remain_variable_storage_size:      remaining size of storage are for the
  *                                     selected variable types
- * @maximum_variable_size:             maximum size of a variable of the
+ * @max_variable_size:                 maximum size of a variable of the
  *                                     selected type
  * Return:                             status code
  */
 efi_status_t EFIAPI __efi_runtime
-efi_query_variable_info_runtime(u32 attributes, u64 *max_variable_storage_size,
-                               u64 *remain_variable_storage_size,
-                               u64 *max_variable_size)
+efi_query_variable_info_ffa_runtime(u32 attributes, u64 
*max_variable_storage_size,
+                                   u64 *remain_variable_storage_size,
+                                   u64 *max_variable_size)
 {
-       return EFI_UNSUPPORTED;
+       struct smm_variable_query_info *mm_query_info;
+       efi_uintn_t payload_size;
+       efi_status_t ret;
+       u8 *comm_buf;
+
+       if (!max_variable_storage_size ||
+           !remain_variable_storage_size ||
+           !max_variable_size || !attributes)
+               return EFI_INVALID_PARAMETER;
+
+       payload_size = sizeof(*mm_query_info);
+       comm_buf = setup_mm_hdr((void **)&mm_query_info, payload_size,
+                               SMM_VARIABLE_FUNCTION_QUERY_VARIABLE_INFO,
+                               &ret);
+       if (!comm_buf)
+               return ret;
+
+       mm_query_info->attr = attributes;
+       ret = mm_communicate(comm_buf, payload_size);
+       if (ret != EFI_SUCCESS)
+               return ret;
+       *max_variable_storage_size = mm_query_info->max_variable_storage;
+       *remain_variable_storage_size =
+                       mm_query_info->remaining_variable_storage;
+       *max_variable_size = mm_query_info->max_variable_size;
+
+       return ret;
 }
 
 /**
@@ -1307,9 +1334,10 @@ efi_set_variable_ffa_runtime(u16 *variable_name, const 
efi_guid_t *guid,
 }
 
 /**
- * efi_query_variable_info() - get information about EFI variables
+ * efi_query_variable_info_runtime() - get information about EFI variables
  *
- * This function implements the QueryVariableInfo() runtime service.
+ * This function implements the QueryVariableInfo() runtime service for
+ * OP-TEE without FF-A runtime transport.
  *
  * See the Unified Extensible Firmware Interface (UEFI) specification for
  * details.
@@ -1383,18 +1411,20 @@ void efi_variables_boot_exit_notify(void)
 
        /* Update runtime service table */
        if (IS_ENABLED(CONFIG_ARM_FFA_RT_MODE)) {
+               efi_runtime_services.query_variable_info =
+                               efi_query_variable_info_ffa_runtime;
                efi_runtime_services.get_variable = 
efi_get_variable_ffa_runtime;
                efi_runtime_services.get_next_variable_name =
                                efi_get_next_variable_name_ffa_runtime;
                efi_runtime_services.set_variable = 
efi_set_variable_ffa_runtime;
        } else {
+               efi_runtime_services.query_variable_info =
+                               efi_query_variable_info_runtime;
                efi_runtime_services.get_variable = efi_get_variable_runtime;
                efi_runtime_services.get_next_variable_name =
                                efi_get_next_variable_name_runtime;
                efi_runtime_services.set_variable = efi_set_variable_runtime;
        }
-       efi_runtime_services.query_variable_info =
-                       efi_query_variable_info_runtime;
        efi_update_table_header_crc32(&efi_runtime_services.hdr);
 
        /* Record that ExitBootServices() has been called */
-- 
2.43.0

Reply via email to