]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Variable/RuntimeDxe/VariableLockRequestToLock.c
MdeModulePkg: Drop VarLock from RuntimeDxe variable driver
[mirror_edk2.git] / MdeModulePkg / Universal / Variable / RuntimeDxe / VariableLockRequestToLock.c
diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableLockRequestToLock.c b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableLockRequestToLock.c
new file mode 100644 (file)
index 0000000..4aa854a
--- /dev/null
@@ -0,0 +1,71 @@
+/** @file -- VariableLockRequestToLock.c\r
+Temporary location of the RequestToLock shim code while\r
+projects are moved to VariablePolicy. Should be removed when deprecated.\r
+\r
+Copyright (c) Microsoft Corporation.\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#include <Uefi.h>\r
+\r
+#include <Library/DebugLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+\r
+#include <Protocol/VariableLock.h>\r
+\r
+#include <Protocol/VariablePolicy.h>\r
+#include <Library/VariablePolicyLib.h>\r
+#include <Library/VariablePolicyHelperLib.h>\r
+\r
+\r
+/**\r
+  DEPRECATED. THIS IS ONLY HERE AS A CONVENIENCE WHILE PORTING.\r
+  Mark a variable that will become read-only after leaving the DXE phase of execution.\r
+  Write request coming from SMM environment through EFI_SMM_VARIABLE_PROTOCOL is allowed.\r
+\r
+  @param[in] This          The VARIABLE_LOCK_PROTOCOL instance.\r
+  @param[in] VariableName  A pointer to the variable name that will be made read-only subsequently.\r
+  @param[in] VendorGuid    A pointer to the vendor GUID that will be made read-only subsequently.\r
+\r
+  @retval EFI_SUCCESS           The variable specified by the VariableName and the VendorGuid was marked\r
+                                as pending to be read-only.\r
+  @retval EFI_INVALID_PARAMETER VariableName or VendorGuid is NULL.\r
+                                Or VariableName is an empty string.\r
+  @retval EFI_ACCESS_DENIED     EFI_END_OF_DXE_EVENT_GROUP_GUID or EFI_EVENT_GROUP_READY_TO_BOOT has\r
+                                already been signaled.\r
+  @retval EFI_OUT_OF_RESOURCES  There is not enough resource to hold the lock request.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+VariableLockRequestToLock (\r
+  IN CONST EDKII_VARIABLE_LOCK_PROTOCOL *This,\r
+  IN       CHAR16                       *VariableName,\r
+  IN       EFI_GUID                     *VendorGuid\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+  VARIABLE_POLICY_ENTRY   *NewPolicy;\r
+\r
+  NewPolicy = NULL;\r
+  Status = CreateBasicVariablePolicy( VendorGuid,\r
+                                      VariableName,\r
+                                      VARIABLE_POLICY_NO_MIN_SIZE,\r
+                                      VARIABLE_POLICY_NO_MAX_SIZE,\r
+                                      VARIABLE_POLICY_NO_MUST_ATTR,\r
+                                      VARIABLE_POLICY_NO_CANT_ATTR,\r
+                                      VARIABLE_POLICY_TYPE_LOCK_NOW,\r
+                                      &NewPolicy );\r
+  if (!EFI_ERROR( Status )) {\r
+    Status = RegisterVariablePolicy( NewPolicy );\r
+  }\r
+  if (EFI_ERROR( Status )) {\r
+    DEBUG(( DEBUG_ERROR, "%a - Failed to lock variable %s! %r\n", __FUNCTION__, VariableName, Status ));\r
+    ASSERT_EFI_ERROR( Status );\r
+  }\r
+  if (NewPolicy != NULL) {\r
+    FreePool( NewPolicy );\r
+  }\r
+\r
+  return Status;\r
+}\r