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]>
---
 lib/efi_loader/efi_variable_tee.c | 44 ++++++++++++++++++++++++-------
 1 file changed, 35 insertions(+), 9 deletions(-)

diff --git a/lib/efi_loader/efi_variable_tee.c 
b/lib/efi_loader/efi_variable_tee.c
index 5f324b4d09f..4189cdeaef0 100644
--- a/lib/efi_loader/efi_variable_tee.c
+++ b/lib/efi_loader/efi_variable_tee.c
@@ -1270,7 +1270,7 @@ out:
 }
 
 /**
- * efi_query_variable_info() - get information about EFI variables
+ * efi_query_variable_info_int_runtime() - get information about EFI variables
  *
  * This function implements the QueryVariableInfo() runtime service.
  *
@@ -1279,20 +1279,46 @@ out:
  *
  * @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_int_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;
 }
 
 /**
@@ -1401,7 +1427,7 @@ void efi_variables_boot_exit_notify(void)
 
        /* Update runtime service table */
        efi_runtime_services.query_variable_info =
-                       efi_query_variable_info_runtime;
+                       efi_query_variable_info_int_runtime;
        efi_runtime_services.get_variable = efi_get_variable_int_runtime;
        efi_runtime_services.get_next_variable_name =
                        efi_get_next_variable_name_int_runtime;
-- 
2.34.1

Reply via email to