]>
Commit | Line | Data |
---|---|---|
fa0737a8 SZ |
1 | /** @file\r |
2 | Provides variable driver extended services.\r | |
3 | \r | |
20a27a64 | 4 | Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.<BR>\r |
9d510e61 | 5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
fa0737a8 SZ |
6 | \r |
7 | **/\r | |
8 | \r | |
9 | #include "Variable.h"\r | |
20a27a64 | 10 | #include "VariableParsing.h"\r |
fa0737a8 SZ |
11 | \r |
12 | /**\r | |
13 | Finds variable in storage blocks of volatile and non-volatile storage areas.\r | |
14 | \r | |
15 | This code finds variable in storage blocks of volatile and non-volatile storage areas.\r | |
16 | If VariableName is an empty string, then we just return the first\r | |
17 | qualified variable without comparing VariableName and VendorGuid.\r | |
18 | \r | |
19 | @param[in] VariableName Name of the variable to be found.\r | |
20 | @param[in] VendorGuid Variable vendor GUID to be found.\r | |
21 | @param[out] AuthVariableInfo Pointer to AUTH_VARIABLE_INFO structure for\r | |
22 | output of the variable found.\r | |
23 | \r | |
24 | @retval EFI_INVALID_PARAMETER If VariableName is not an empty string,\r | |
25 | while VendorGuid is NULL.\r | |
26 | @retval EFI_SUCCESS Variable successfully found.\r | |
27 | @retval EFI_NOT_FOUND Variable not found\r | |
28 | \r | |
29 | **/\r | |
30 | EFI_STATUS\r | |
31 | EFIAPI\r | |
32 | VariableExLibFindVariable (\r | |
33 | IN CHAR16 *VariableName,\r | |
34 | IN EFI_GUID *VendorGuid,\r | |
35 | OUT AUTH_VARIABLE_INFO *AuthVariableInfo\r | |
36 | )\r | |
37 | {\r | |
38 | EFI_STATUS Status;\r | |
39 | VARIABLE_POINTER_TRACK Variable;\r | |
40 | AUTHENTICATED_VARIABLE_HEADER *AuthVariable;\r | |
41 | \r | |
42 | Status = FindVariable (\r | |
43 | VariableName,\r | |
44 | VendorGuid,\r | |
45 | &Variable,\r | |
46 | &mVariableModuleGlobal->VariableGlobal,\r | |
47 | FALSE\r | |
48 | );\r | |
49 | if (EFI_ERROR (Status)) {\r | |
50 | AuthVariableInfo->Data = NULL;\r | |
51 | AuthVariableInfo->DataSize = 0;\r | |
52 | AuthVariableInfo->Attributes = 0;\r | |
53 | AuthVariableInfo->PubKeyIndex = 0;\r | |
54 | AuthVariableInfo->MonotonicCount = 0;\r | |
55 | AuthVariableInfo->TimeStamp = NULL;\r | |
56 | return Status;\r | |
57 | }\r | |
58 | \r | |
59 | AuthVariableInfo->DataSize = DataSizeOfVariable (Variable.CurrPtr);\r | |
60 | AuthVariableInfo->Data = GetVariableDataPtr (Variable.CurrPtr);\r | |
61 | AuthVariableInfo->Attributes = Variable.CurrPtr->Attributes;\r | |
62 | if (mVariableModuleGlobal->VariableGlobal.AuthFormat) {\r | |
63 | AuthVariable = (AUTHENTICATED_VARIABLE_HEADER *) Variable.CurrPtr;\r | |
64 | AuthVariableInfo->PubKeyIndex = AuthVariable->PubKeyIndex;\r | |
cdc83ccf | 65 | AuthVariableInfo->MonotonicCount = ReadUnaligned64 (&(AuthVariable->MonotonicCount));\r |
fa0737a8 SZ |
66 | AuthVariableInfo->TimeStamp = &AuthVariable->TimeStamp;\r |
67 | }\r | |
68 | \r | |
69 | return EFI_SUCCESS;\r | |
70 | }\r | |
71 | \r | |
72 | /**\r | |
73 | Finds next variable in storage blocks of volatile and non-volatile storage areas.\r | |
74 | \r | |
75 | This code finds next variable in storage blocks of volatile and non-volatile storage areas.\r | |
76 | If VariableName is an empty string, then we just return the first\r | |
77 | qualified variable without comparing VariableName and VendorGuid.\r | |
78 | \r | |
79 | @param[in] VariableName Name of the variable to be found.\r | |
80 | @param[in] VendorGuid Variable vendor GUID to be found.\r | |
81 | @param[out] AuthVariableInfo Pointer to AUTH_VARIABLE_INFO structure for\r | |
82 | output of the next variable.\r | |
83 | \r | |
84 | @retval EFI_INVALID_PARAMETER If VariableName is not an empty string,\r | |
85 | while VendorGuid is NULL.\r | |
86 | @retval EFI_SUCCESS Variable successfully found.\r | |
87 | @retval EFI_NOT_FOUND Variable not found\r | |
88 | \r | |
89 | **/\r | |
90 | EFI_STATUS\r | |
91 | EFIAPI\r | |
92 | VariableExLibFindNextVariable (\r | |
93 | IN CHAR16 *VariableName,\r | |
94 | IN EFI_GUID *VendorGuid,\r | |
95 | OUT AUTH_VARIABLE_INFO *AuthVariableInfo\r | |
96 | )\r | |
97 | {\r | |
98 | EFI_STATUS Status;\r | |
99 | VARIABLE_HEADER *VariablePtr;\r | |
100 | AUTHENTICATED_VARIABLE_HEADER *AuthVariablePtr;\r | |
f8ff4cca MK |
101 | VARIABLE_STORE_HEADER *VariableStoreHeader[VariableStoreTypeMax];\r |
102 | \r | |
103 | VariableStoreHeader[VariableStoreTypeVolatile] = (VARIABLE_STORE_HEADER *) (UINTN) mVariableModuleGlobal->VariableGlobal.VolatileVariableBase;\r | |
104 | VariableStoreHeader[VariableStoreTypeHob] = (VARIABLE_STORE_HEADER *) (UINTN) mVariableModuleGlobal->VariableGlobal.HobVariableBase;\r | |
105 | VariableStoreHeader[VariableStoreTypeNv] = mNvVariableCache;\r | |
fa0737a8 SZ |
106 | \r |
107 | Status = VariableServiceGetNextVariableInternal (\r | |
108 | VariableName,\r | |
109 | VendorGuid,\r | |
f8ff4cca | 110 | VariableStoreHeader,\r |
fa0737a8 SZ |
111 | &VariablePtr\r |
112 | );\r | |
113 | if (EFI_ERROR (Status)) {\r | |
114 | AuthVariableInfo->VariableName = NULL;\r | |
115 | AuthVariableInfo->VendorGuid = NULL;\r | |
116 | AuthVariableInfo->Data = NULL;\r | |
117 | AuthVariableInfo->DataSize = 0;\r | |
118 | AuthVariableInfo->Attributes = 0;\r | |
119 | AuthVariableInfo->PubKeyIndex = 0;\r | |
120 | AuthVariableInfo->MonotonicCount = 0;\r | |
121 | AuthVariableInfo->TimeStamp = NULL;\r | |
122 | return Status;\r | |
123 | }\r | |
124 | \r | |
125 | AuthVariableInfo->VariableName = GetVariableNamePtr (VariablePtr);\r | |
126 | AuthVariableInfo->VendorGuid = GetVendorGuidPtr (VariablePtr);\r | |
127 | AuthVariableInfo->DataSize = DataSizeOfVariable (VariablePtr);\r | |
128 | AuthVariableInfo->Data = GetVariableDataPtr (VariablePtr);\r | |
129 | AuthVariableInfo->Attributes = VariablePtr->Attributes;\r | |
130 | if (mVariableModuleGlobal->VariableGlobal.AuthFormat) {\r | |
131 | AuthVariablePtr = (AUTHENTICATED_VARIABLE_HEADER *) VariablePtr;\r | |
132 | AuthVariableInfo->PubKeyIndex = AuthVariablePtr->PubKeyIndex;\r | |
cdc83ccf | 133 | AuthVariableInfo->MonotonicCount = ReadUnaligned64 (&(AuthVariablePtr->MonotonicCount));\r |
fa0737a8 SZ |
134 | AuthVariableInfo->TimeStamp = &AuthVariablePtr->TimeStamp;\r |
135 | }\r | |
136 | \r | |
137 | return EFI_SUCCESS;\r | |
138 | }\r | |
139 | \r | |
140 | /**\r | |
141 | Update the variable region with Variable information.\r | |
142 | \r | |
143 | @param[in] AuthVariableInfo Pointer AUTH_VARIABLE_INFO structure for\r | |
144 | input of the variable.\r | |
145 | \r | |
146 | @retval EFI_SUCCESS The update operation is success.\r | |
147 | @retval EFI_INVALID_PARAMETER Invalid parameter.\r | |
148 | @retval EFI_WRITE_PROTECTED Variable is write-protected.\r | |
149 | @retval EFI_OUT_OF_RESOURCES There is not enough resource.\r | |
150 | \r | |
151 | **/\r | |
152 | EFI_STATUS\r | |
153 | EFIAPI\r | |
154 | VariableExLibUpdateVariable (\r | |
155 | IN AUTH_VARIABLE_INFO *AuthVariableInfo\r | |
156 | )\r | |
157 | {\r | |
158 | VARIABLE_POINTER_TRACK Variable;\r | |
159 | \r | |
160 | FindVariable (AuthVariableInfo->VariableName, AuthVariableInfo->VendorGuid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE);\r | |
161 | return UpdateVariable (\r | |
162 | AuthVariableInfo->VariableName,\r | |
163 | AuthVariableInfo->VendorGuid,\r | |
164 | AuthVariableInfo->Data,\r | |
165 | AuthVariableInfo->DataSize,\r | |
166 | AuthVariableInfo->Attributes,\r | |
167 | AuthVariableInfo->PubKeyIndex,\r | |
168 | AuthVariableInfo->MonotonicCount,\r | |
169 | &Variable,\r | |
170 | AuthVariableInfo->TimeStamp\r | |
171 | );\r | |
172 | }\r | |
173 | \r | |
174 | /**\r | |
175 | Get scratch buffer.\r | |
176 | \r | |
177 | @param[in, out] ScratchBufferSize Scratch buffer size. If input size is greater than\r | |
178 | the maximum supported buffer size, this value contains\r | |
179 | the maximum supported buffer size as output.\r | |
180 | @param[out] ScratchBuffer Pointer to scratch buffer address.\r | |
181 | \r | |
182 | @retval EFI_SUCCESS Get scratch buffer successfully.\r | |
183 | @retval EFI_UNSUPPORTED If input size is greater than the maximum supported buffer size.\r | |
184 | \r | |
185 | **/\r | |
186 | EFI_STATUS\r | |
187 | EFIAPI\r | |
188 | VariableExLibGetScratchBuffer (\r | |
189 | IN OUT UINTN *ScratchBufferSize,\r | |
190 | OUT VOID **ScratchBuffer\r | |
191 | )\r | |
192 | {\r | |
193 | UINTN MaxBufferSize;\r | |
194 | \r | |
195 | MaxBufferSize = mVariableModuleGlobal->ScratchBufferSize;\r | |
196 | if (*ScratchBufferSize > MaxBufferSize) {\r | |
197 | *ScratchBufferSize = MaxBufferSize;\r | |
198 | return EFI_UNSUPPORTED;\r | |
199 | }\r | |
200 | \r | |
201 | *ScratchBuffer = GetEndPointer ((VARIABLE_STORE_HEADER *) ((UINTN) mVariableModuleGlobal->VariableGlobal.VolatileVariableBase));\r | |
202 | return EFI_SUCCESS;\r | |
203 | }\r | |
204 | \r | |
205 | /**\r | |
206 | This function is to check if the remaining variable space is enough to set\r | |
207 | all Variables from argument list successfully. The purpose of the check\r | |
208 | is to keep the consistency of the Variables to be in variable storage.\r | |
209 | \r | |
210 | Note: Variables are assumed to be in same storage.\r | |
211 | The set sequence of Variables will be same with the sequence of VariableEntry from argument list,\r | |
212 | so follow the argument sequence to check the Variables.\r | |
213 | \r | |
214 | @param[in] Attributes Variable attributes for Variable entries.\r | |
215 | @param ... The variable argument list with type VARIABLE_ENTRY_CONSISTENCY *.\r | |
216 | A NULL terminates the list. The VariableSize of\r | |
217 | VARIABLE_ENTRY_CONSISTENCY is the variable data size as input.\r | |
218 | It will be changed to variable total size as output.\r | |
219 | \r | |
220 | @retval TRUE Have enough variable space to set the Variables successfully.\r | |
221 | @retval FALSE No enough variable space to set the Variables successfully.\r | |
222 | \r | |
223 | **/\r | |
224 | BOOLEAN\r | |
225 | EFIAPI\r | |
226 | VariableExLibCheckRemainingSpaceForConsistency (\r | |
227 | IN UINT32 Attributes,\r | |
228 | ...\r | |
229 | )\r | |
230 | {\r | |
231 | VA_LIST Marker;\r | |
232 | BOOLEAN Return;\r | |
233 | \r | |
234 | VA_START (Marker, Attributes);\r | |
235 | \r | |
236 | Return = CheckRemainingSpaceForConsistencyInternal (Attributes, Marker);\r | |
237 | \r | |
238 | VA_END (Marker);\r | |
239 | \r | |
240 | return Return;\r | |
241 | }\r | |
242 | \r | |
243 | /**\r | |
244 | Return TRUE if at OS runtime.\r | |
245 | \r | |
246 | @retval TRUE If at OS runtime.\r | |
247 | @retval FALSE If at boot time.\r | |
248 | \r | |
249 | **/\r | |
250 | BOOLEAN\r | |
251 | EFIAPI\r | |
252 | VariableExLibAtRuntime (\r | |
253 | VOID\r | |
254 | )\r | |
255 | {\r | |
256 | return AtRuntime ();\r | |
257 | }\r |