]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Variable/RuntimeDxe/VariableLockRequestToLock.c
MdeModulePkg: Drop VarLock from RuntimeDxe variable driver
[mirror_edk2.git] / MdeModulePkg / Universal / Variable / RuntimeDxe / VariableLockRequestToLock.c
1 /** @file -- VariableLockRequestToLock.c
2 Temporary location of the RequestToLock shim code while
3 projects are moved to VariablePolicy. Should be removed when deprecated.
4
5 Copyright (c) Microsoft Corporation.
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #include <Uefi.h>
11
12 #include <Library/DebugLib.h>
13 #include <Library/MemoryAllocationLib.h>
14
15 #include <Protocol/VariableLock.h>
16
17 #include <Protocol/VariablePolicy.h>
18 #include <Library/VariablePolicyLib.h>
19 #include <Library/VariablePolicyHelperLib.h>
20
21
22 /**
23 DEPRECATED. THIS IS ONLY HERE AS A CONVENIENCE WHILE PORTING.
24 Mark a variable that will become read-only after leaving the DXE phase of execution.
25 Write request coming from SMM environment through EFI_SMM_VARIABLE_PROTOCOL is allowed.
26
27 @param[in] This The VARIABLE_LOCK_PROTOCOL instance.
28 @param[in] VariableName A pointer to the variable name that will be made read-only subsequently.
29 @param[in] VendorGuid A pointer to the vendor GUID that will be made read-only subsequently.
30
31 @retval EFI_SUCCESS The variable specified by the VariableName and the VendorGuid was marked
32 as pending to be read-only.
33 @retval EFI_INVALID_PARAMETER VariableName or VendorGuid is NULL.
34 Or VariableName is an empty string.
35 @retval EFI_ACCESS_DENIED EFI_END_OF_DXE_EVENT_GROUP_GUID or EFI_EVENT_GROUP_READY_TO_BOOT has
36 already been signaled.
37 @retval EFI_OUT_OF_RESOURCES There is not enough resource to hold the lock request.
38 **/
39 EFI_STATUS
40 EFIAPI
41 VariableLockRequestToLock (
42 IN CONST EDKII_VARIABLE_LOCK_PROTOCOL *This,
43 IN CHAR16 *VariableName,
44 IN EFI_GUID *VendorGuid
45 )
46 {
47 EFI_STATUS Status;
48 VARIABLE_POLICY_ENTRY *NewPolicy;
49
50 NewPolicy = NULL;
51 Status = CreateBasicVariablePolicy( VendorGuid,
52 VariableName,
53 VARIABLE_POLICY_NO_MIN_SIZE,
54 VARIABLE_POLICY_NO_MAX_SIZE,
55 VARIABLE_POLICY_NO_MUST_ATTR,
56 VARIABLE_POLICY_NO_CANT_ATTR,
57 VARIABLE_POLICY_TYPE_LOCK_NOW,
58 &NewPolicy );
59 if (!EFI_ERROR( Status )) {
60 Status = RegisterVariablePolicy( NewPolicy );
61 }
62 if (EFI_ERROR( Status )) {
63 DEBUG(( DEBUG_ERROR, "%a - Failed to lock variable %s! %r\n", __FUNCTION__, VariableName, Status ));
64 ASSERT_EFI_ERROR( Status );
65 }
66 if (NewPolicy != NULL) {
67 FreePool( NewPolicy );
68 }
69
70 return Status;
71 }