]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | Implementation functions and structures for var check protocol\r | |
3 | and variable lock protocol based on VarCheckLib.\r | |
4 | \r | |
5 | Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r | |
6 | This program and the accompanying materials\r | |
7 | are licensed and made available under the terms and conditions of the BSD License\r | |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | \r | |
14 | **/\r | |
15 | \r | |
16 | #include "Variable.h"\r | |
17 | \r | |
18 | /**\r | |
19 | Mark a variable that will become read-only after leaving the DXE phase of execution.\r | |
20 | Write request coming from SMM environment through EFI_SMM_VARIABLE_PROTOCOL is allowed.\r | |
21 | \r | |
22 | @param[in] This The VARIABLE_LOCK_PROTOCOL instance.\r | |
23 | @param[in] VariableName A pointer to the variable name that will be made read-only subsequently.\r | |
24 | @param[in] VendorGuid A pointer to the vendor GUID that will be made read-only subsequently.\r | |
25 | \r | |
26 | @retval EFI_SUCCESS The variable specified by the VariableName and the VendorGuid was marked\r | |
27 | as pending to be read-only.\r | |
28 | @retval EFI_INVALID_PARAMETER VariableName or VendorGuid is NULL.\r | |
29 | Or VariableName is an empty string.\r | |
30 | @retval EFI_ACCESS_DENIED EFI_END_OF_DXE_EVENT_GROUP_GUID or EFI_EVENT_GROUP_READY_TO_BOOT has\r | |
31 | already been signaled.\r | |
32 | @retval EFI_OUT_OF_RESOURCES There is not enough resource to hold the lock request.\r | |
33 | **/\r | |
34 | EFI_STATUS\r | |
35 | EFIAPI\r | |
36 | VariableLockRequestToLock (\r | |
37 | IN CONST EDKII_VARIABLE_LOCK_PROTOCOL *This,\r | |
38 | IN CHAR16 *VariableName,\r | |
39 | IN EFI_GUID *VendorGuid\r | |
40 | )\r | |
41 | {\r | |
42 | EFI_STATUS Status;\r | |
43 | VAR_CHECK_VARIABLE_PROPERTY Property;\r | |
44 | \r | |
45 | AcquireLockOnlyAtBootTime (&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);\r | |
46 | \r | |
47 | Status = VarCheckLibVariablePropertyGet (VariableName, VendorGuid, &Property);\r | |
48 | if (!EFI_ERROR (Status)) {\r | |
49 | Property.Property |= VAR_CHECK_VARIABLE_PROPERTY_READ_ONLY;\r | |
50 | } else {\r | |
51 | Property.Revision = VAR_CHECK_VARIABLE_PROPERTY_REVISION;\r | |
52 | Property.Property = VAR_CHECK_VARIABLE_PROPERTY_READ_ONLY;\r | |
53 | Property.Attributes = 0;\r | |
54 | Property.MinSize = 1;\r | |
55 | Property.MaxSize = MAX_UINTN;\r | |
56 | }\r | |
57 | Status = VarCheckLibVariablePropertySet (VariableName, VendorGuid, &Property);\r | |
58 | \r | |
59 | DEBUG ((EFI_D_INFO, "[Variable] Lock: %g:%s %r\n", VendorGuid, VariableName, Status));\r | |
60 | \r | |
61 | ReleaseLockOnlyAtBootTime (&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);\r | |
62 | \r | |
63 | return Status;\r | |
64 | }\r | |
65 | \r | |
66 | /**\r | |
67 | Register SetVariable check handler.\r | |
68 | \r | |
69 | @param[in] Handler Pointer to check handler.\r | |
70 | \r | |
71 | @retval EFI_SUCCESS The SetVariable check handler was registered successfully.\r | |
72 | @retval EFI_INVALID_PARAMETER Handler is NULL.\r | |
73 | @retval EFI_ACCESS_DENIED EFI_END_OF_DXE_EVENT_GROUP_GUID or EFI_EVENT_GROUP_READY_TO_BOOT has\r | |
74 | already been signaled.\r | |
75 | @retval EFI_OUT_OF_RESOURCES There is not enough resource for the SetVariable check handler register request.\r | |
76 | @retval EFI_UNSUPPORTED This interface is not implemented.\r | |
77 | For example, it is unsupported in VarCheck protocol if both VarCheck and SmmVarCheck protocols are present.\r | |
78 | \r | |
79 | **/\r | |
80 | EFI_STATUS\r | |
81 | EFIAPI\r | |
82 | VarCheckRegisterSetVariableCheckHandler (\r | |
83 | IN VAR_CHECK_SET_VARIABLE_CHECK_HANDLER Handler\r | |
84 | )\r | |
85 | {\r | |
86 | EFI_STATUS Status;\r | |
87 | \r | |
88 | AcquireLockOnlyAtBootTime (&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);\r | |
89 | Status = VarCheckLibRegisterSetVariableCheckHandler (Handler);\r | |
90 | ReleaseLockOnlyAtBootTime (&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);\r | |
91 | \r | |
92 | return Status;\r | |
93 | }\r | |
94 | \r | |
95 | /**\r | |
96 | Variable property set.\r | |
97 | \r | |
98 | @param[in] Name Pointer to the variable name.\r | |
99 | @param[in] Guid Pointer to the vendor GUID.\r | |
100 | @param[in] VariableProperty Pointer to the input variable property.\r | |
101 | \r | |
102 | @retval EFI_SUCCESS The property of variable specified by the Name and Guid was set successfully.\r | |
103 | @retval EFI_INVALID_PARAMETER Name, Guid or VariableProperty is NULL, or Name is an empty string,\r | |
104 | or the fields of VariableProperty are not valid.\r | |
105 | @retval EFI_ACCESS_DENIED EFI_END_OF_DXE_EVENT_GROUP_GUID or EFI_EVENT_GROUP_READY_TO_BOOT has\r | |
106 | already been signaled.\r | |
107 | @retval EFI_OUT_OF_RESOURCES There is not enough resource for the variable property set request.\r | |
108 | \r | |
109 | **/\r | |
110 | EFI_STATUS\r | |
111 | EFIAPI\r | |
112 | VarCheckVariablePropertySet (\r | |
113 | IN CHAR16 *Name,\r | |
114 | IN EFI_GUID *Guid,\r | |
115 | IN VAR_CHECK_VARIABLE_PROPERTY *VariableProperty\r | |
116 | )\r | |
117 | {\r | |
118 | EFI_STATUS Status;\r | |
119 | \r | |
120 | AcquireLockOnlyAtBootTime (&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);\r | |
121 | Status = VarCheckLibVariablePropertySet (Name, Guid, VariableProperty);\r | |
122 | ReleaseLockOnlyAtBootTime (&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);\r | |
123 | \r | |
124 | return Status;\r | |
125 | }\r | |
126 | \r | |
127 | /**\r | |
128 | Variable property get.\r | |
129 | \r | |
130 | @param[in] Name Pointer to the variable name.\r | |
131 | @param[in] Guid Pointer to the vendor GUID.\r | |
132 | @param[out] VariableProperty Pointer to the output variable property.\r | |
133 | \r | |
134 | @retval EFI_SUCCESS The property of variable specified by the Name and Guid was got successfully.\r | |
135 | @retval EFI_INVALID_PARAMETER Name, Guid or VariableProperty is NULL, or Name is an empty string.\r | |
136 | @retval EFI_NOT_FOUND The property of variable specified by the Name and Guid was not found.\r | |
137 | \r | |
138 | **/\r | |
139 | EFI_STATUS\r | |
140 | EFIAPI\r | |
141 | VarCheckVariablePropertyGet (\r | |
142 | IN CHAR16 *Name,\r | |
143 | IN EFI_GUID *Guid,\r | |
144 | OUT VAR_CHECK_VARIABLE_PROPERTY *VariableProperty\r | |
145 | )\r | |
146 | {\r | |
147 | EFI_STATUS Status;\r | |
148 | \r | |
149 | AcquireLockOnlyAtBootTime (&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);\r | |
150 | Status = VarCheckLibVariablePropertyGet (Name, Guid, VariableProperty);\r | |
151 | ReleaseLockOnlyAtBootTime (&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);\r | |
152 | \r | |
153 | return Status;\r | |
154 | }\r | |
155 | \r |