]>
Commit | Line | Data |
---|---|---|
504214c4 | 1 | /** @file\r |
504214c4 | 2 | The internal header file includes the common header files, defines\r |
8a2d4996 | 3 | internal structure and functions used by Variable modules.\r |
504214c4 | 4 | \r |
746645bd | 5 | Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>\r |
e5eed7d3 | 6 | This program and the accompanying materials\r |
8d3a5c82 | 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 | |
504214c4 | 14 | **/\r |
8d3a5c82 | 15 | \r |
7c80e839 | 16 | #ifndef _VARIABLE_H_\r |
17 | #define _VARIABLE_H_\r | |
8d3a5c82 | 18 | \r |
39099938 | 19 | #include <PiDxe.h>\r |
8d3a5c82 | 20 | #include <Protocol/VariableWrite.h>\r |
88a5561c | 21 | #include <Protocol/FaultTolerantWrite.h>\r |
8d3a5c82 | 22 | #include <Protocol/FirmwareVolumeBlock.h>\r |
23 | #include <Protocol/Variable.h>\r | |
ff843847 | 24 | #include <Protocol/VariableLock.h>\r |
efb01a10 | 25 | #include <Protocol/VarCheck.h>\r |
8d3a5c82 | 26 | #include <Library/PcdLib.h>\r |
0f7aff72 | 27 | #include <Library/HobLib.h>\r |
8d3a5c82 | 28 | #include <Library/UefiDriverEntryPoint.h>\r |
29 | #include <Library/DxeServicesTableLib.h>\r | |
30 | #include <Library/UefiRuntimeLib.h>\r | |
31 | #include <Library/DebugLib.h>\r | |
32 | #include <Library/BaseMemoryLib.h>\r | |
8d3a5c82 | 33 | #include <Library/UefiBootServicesTableLib.h>\r |
34 | #include <Library/UefiLib.h>\r | |
35 | #include <Library/BaseLib.h>\r | |
4cf894eb | 36 | #include <Library/SynchronizationLib.h>\r |
8d3a5c82 | 37 | #include <Library/MemoryAllocationLib.h>\r |
fa0737a8 | 38 | #include <Library/AuthVariableLib.h>\r |
8021f4c7 | 39 | #include <Library/VarCheckLib.h>\r |
052ad7e1 | 40 | #include <Guid/GlobalVariable.h>\r |
01a5c994 | 41 | #include <Guid/EventGroup.h>\r |
3709c4cd | 42 | #include <Guid/VariableFormat.h>\r |
d6550260 | 43 | #include <Guid/SystemNvDataGuid.h>\r |
3e02ebb2 | 44 | #include <Guid/FaultTolerantWrite.h>\r |
4edb1866 | 45 | #include <Guid/VarErrorFlag.h>\r |
8d3a5c82 | 46 | \r |
00663d04 LE |
47 | #include "PrivilegePolymorphic.h"\r |
48 | \r | |
fa0737a8 SZ |
49 | #define EFI_VARIABLE_ATTRIBUTES_MASK (EFI_VARIABLE_NON_VOLATILE | \\r |
50 | EFI_VARIABLE_BOOTSERVICE_ACCESS | \\r | |
51 | EFI_VARIABLE_RUNTIME_ACCESS | \\r | |
52 | EFI_VARIABLE_HARDWARE_ERROR_RECORD | \\r | |
fa0737a8 SZ |
53 | EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS | \\r |
54 | EFI_VARIABLE_APPEND_WRITE)\r | |
55 | \r | |
255a3f33 RN |
56 | ///\r |
57 | /// The size of a 3 character ISO639 language code.\r | |
58 | ///\r | |
59 | #define ISO_639_2_ENTRY_SIZE 3\r | |
60 | \r | |
0f7aff72 RN |
61 | typedef enum {\r |
62 | VariableStoreTypeVolatile,\r | |
63 | VariableStoreTypeHob,\r | |
64 | VariableStoreTypeNv,\r | |
65 | VariableStoreTypeMax\r | |
66 | } VARIABLE_STORE_TYPE;\r | |
67 | \r | |
8d3a5c82 | 68 | typedef struct {\r |
69 | VARIABLE_HEADER *CurrPtr;\r | |
23b06935 SZ |
70 | //\r |
71 | // If both ADDED and IN_DELETED_TRANSITION variable are present,\r | |
72 | // InDeletedTransitionPtr will point to the IN_DELETED_TRANSITION one.\r | |
73 | // Otherwise, CurrPtr will point to the ADDED or IN_DELETED_TRANSITION one,\r | |
74 | // and InDeletedTransitionPtr will be NULL at the same time.\r | |
75 | //\r | |
76 | VARIABLE_HEADER *InDeletedTransitionPtr;\r | |
8d3a5c82 | 77 | VARIABLE_HEADER *EndPtr;\r |
78 | VARIABLE_HEADER *StartPtr;\r | |
79 | BOOLEAN Volatile;\r | |
80 | } VARIABLE_POINTER_TRACK;\r | |
81 | \r | |
82 | typedef struct {\r | |
0f7aff72 | 83 | EFI_PHYSICAL_ADDRESS HobVariableBase;\r |
8d3a5c82 | 84 | EFI_PHYSICAL_ADDRESS VolatileVariableBase;\r |
85 | EFI_PHYSICAL_ADDRESS NonVolatileVariableBase;\r | |
86 | EFI_LOCK VariableServicesLock;\r | |
fdb7765f | 87 | UINT32 ReentrantState;\r |
fa0737a8 SZ |
88 | BOOLEAN AuthFormat;\r |
89 | BOOLEAN AuthSupport;\r | |
8d3a5c82 | 90 | } VARIABLE_GLOBAL;\r |
91 | \r | |
92 | typedef struct {\r | |
052ad7e1 | 93 | VARIABLE_GLOBAL VariableGlobal;\r |
8d3a5c82 | 94 | UINTN VolatileLastVariableOffset;\r |
95 | UINTN NonVolatileLastVariableOffset;\r | |
4edb1866 SZ |
96 | UINTN CommonVariableSpace;\r |
97 | UINTN CommonMaxUserVariableSpace;\r | |
98 | UINTN CommonRuntimeVariableSpace;\r | |
2fcdca1d | 99 | UINTN CommonVariableTotalSize;\r |
4edb1866 | 100 | UINTN CommonUserVariableTotalSize;\r |
2fcdca1d | 101 | UINTN HwErrVariableTotalSize;\r |
fa0737a8 SZ |
102 | UINTN MaxVariableSize;\r |
103 | UINTN MaxAuthVariableSize;\r | |
9b4a2032 | 104 | UINTN MaxVolatileVariableSize;\r |
fa0737a8 | 105 | UINTN ScratchBufferSize;\r |
255a3f33 RN |
106 | CHAR8 *PlatformLangCodes;\r |
107 | CHAR8 *LangCodes;\r | |
108 | CHAR8 *PlatformLang;\r | |
109 | CHAR8 Lang[ISO_639_2_ENTRY_SIZE + 1];\r | |
8a9e0b72 | 110 | EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbInstance;\r |
052ad7e1 A |
111 | } VARIABLE_MODULE_GLOBAL;\r |
112 | \r | |
335e2681 SZ |
113 | /**\r |
114 | Flush the HOB variable to flash.\r | |
115 | \r | |
116 | @param[in] VariableName Name of variable has been updated or deleted.\r | |
117 | @param[in] VendorGuid Guid of variable has been updated or deleted.\r | |
118 | \r | |
119 | **/\r | |
120 | VOID\r | |
121 | FlushHobVariableToFlash (\r | |
122 | IN CHAR16 *VariableName,\r | |
123 | IN EFI_GUID *VendorGuid\r | |
124 | );\r | |
125 | \r | |
c24b392c | 126 | /**\r |
127 | Writes a buffer to variable storage space, in the working block.\r | |
128 | \r | |
8a2d4996 | 129 | This function writes a buffer to variable storage space into a firmware\r |
130 | volume block device. The destination is specified by the parameter\r | |
c24b392c | 131 | VariableBase. Fault Tolerant Write protocol is used for writing.\r |
132 | \r | |
8a2d4996 | 133 | @param VariableBase Base address of the variable to write.\r |
128ef095 | 134 | @param VariableBuffer Point to the variable data buffer.\r |
c24b392c | 135 | \r |
8a2d4996 | 136 | @retval EFI_SUCCESS The function completed successfully.\r |
137 | @retval EFI_NOT_FOUND Fail to locate Fault Tolerant Write protocol.\r | |
138 | @retval EFI_ABORTED The function could not complete successfully.\r | |
c24b392c | 139 | \r |
140 | **/\r | |
141 | EFI_STATUS\r | |
142 | FtwVariableSpace (\r | |
143 | IN EFI_PHYSICAL_ADDRESS VariableBase,\r | |
128ef095 | 144 | IN VARIABLE_STORE_HEADER *VariableBuffer\r |
c24b392c | 145 | );\r |
146 | \r | |
fa0737a8 SZ |
147 | /**\r |
148 | Finds variable in storage blocks of volatile and non-volatile storage areas.\r | |
149 | \r | |
150 | This code finds variable in storage blocks of volatile and non-volatile storage areas.\r | |
151 | If VariableName is an empty string, then we just return the first\r | |
152 | qualified variable without comparing VariableName and VendorGuid.\r | |
153 | If IgnoreRtCheck is TRUE, then we ignore the EFI_VARIABLE_RUNTIME_ACCESS attribute check\r | |
154 | at runtime when searching existing variable, only VariableName and VendorGuid are compared.\r | |
155 | Otherwise, variables without EFI_VARIABLE_RUNTIME_ACCESS are not visible at runtime.\r | |
156 | \r | |
157 | @param[in] VariableName Name of the variable to be found.\r | |
158 | @param[in] VendorGuid Vendor GUID to be found.\r | |
159 | @param[out] PtrTrack VARIABLE_POINTER_TRACK structure for output,\r | |
160 | including the range searched and the target position.\r | |
161 | @param[in] Global Pointer to VARIABLE_GLOBAL structure, including\r | |
162 | base of volatile variable storage area, base of\r | |
163 | NV variable storage area, and a lock.\r | |
164 | @param[in] IgnoreRtCheck Ignore EFI_VARIABLE_RUNTIME_ACCESS attribute\r | |
165 | check at runtime when searching variable.\r | |
166 | \r | |
167 | @retval EFI_INVALID_PARAMETER If VariableName is not an empty string, while\r | |
168 | VendorGuid is NULL.\r | |
169 | @retval EFI_SUCCESS Variable successfully found.\r | |
170 | @retval EFI_NOT_FOUND Variable not found\r | |
171 | \r | |
172 | **/\r | |
173 | EFI_STATUS\r | |
174 | FindVariable (\r | |
175 | IN CHAR16 *VariableName,\r | |
176 | IN EFI_GUID *VendorGuid,\r | |
177 | OUT VARIABLE_POINTER_TRACK *PtrTrack,\r | |
178 | IN VARIABLE_GLOBAL *Global,\r | |
179 | IN BOOLEAN IgnoreRtCheck\r | |
180 | );\r | |
c24b392c | 181 | \r |
8a2d4996 | 182 | /**\r |
8a2d4996 | 183 | \r |
fa0737a8 | 184 | Gets the pointer to the end of the variable storage area.\r |
8a2d4996 | 185 | \r |
fa0737a8 SZ |
186 | This function gets pointer to the end of the variable storage\r |
187 | area, according to the input variable store header.\r | |
8a2d4996 | 188 | \r |
fa0737a8 | 189 | @param VarStoreHeader Pointer to the Variable Store Header.\r |
8a2d4996 | 190 | \r |
fa0737a8 SZ |
191 | @return Pointer to the end of the variable storage area.\r |
192 | \r | |
193 | **/\r | |
194 | VARIABLE_HEADER *\r | |
195 | GetEndPointer (\r | |
196 | IN VARIABLE_STORE_HEADER *VarStoreHeader\r | |
197 | );\r | |
198 | \r | |
199 | /**\r | |
200 | This code gets the size of variable header.\r | |
201 | \r | |
202 | @return Size of variable header in bytes in type UINTN.\r | |
203 | \r | |
204 | **/\r | |
205 | UINTN\r | |
206 | GetVariableHeaderSize (\r | |
207 | VOID\r | |
208 | );\r | |
209 | \r | |
210 | /**\r | |
211 | \r | |
212 | This code gets the pointer to the variable name.\r | |
213 | \r | |
214 | @param Variable Pointer to the Variable Header.\r | |
215 | \r | |
216 | @return Pointer to Variable Name which is Unicode encoding.\r | |
217 | \r | |
218 | **/\r | |
219 | CHAR16 *\r | |
220 | GetVariableNamePtr (\r | |
221 | IN VARIABLE_HEADER *Variable\r | |
222 | );\r | |
223 | \r | |
224 | /**\r | |
225 | This code gets the pointer to the variable guid.\r | |
226 | \r | |
227 | @param Variable Pointer to the Variable Header.\r | |
228 | \r | |
229 | @return A EFI_GUID* pointer to Vendor Guid.\r | |
230 | \r | |
231 | **/\r | |
232 | EFI_GUID *\r | |
233 | GetVendorGuidPtr (\r | |
234 | IN VARIABLE_HEADER *Variable\r | |
235 | );\r | |
236 | \r | |
237 | /**\r | |
238 | \r | |
239 | This code gets the pointer to the variable data.\r | |
240 | \r | |
241 | @param Variable Pointer to the Variable Header.\r | |
242 | \r | |
243 | @return Pointer to Variable Data.\r | |
244 | \r | |
245 | **/\r | |
246 | UINT8 *\r | |
247 | GetVariableDataPtr (\r | |
248 | IN VARIABLE_HEADER *Variable\r | |
249 | );\r | |
250 | \r | |
251 | /**\r | |
252 | \r | |
253 | This code gets the size of variable data.\r | |
254 | \r | |
255 | @param Variable Pointer to the Variable Header.\r | |
256 | \r | |
257 | @return Size of variable in bytes.\r | |
258 | \r | |
259 | **/\r | |
260 | UINTN\r | |
261 | DataSizeOfVariable (\r | |
262 | IN VARIABLE_HEADER *Variable\r | |
263 | );\r | |
264 | \r | |
265 | /**\r | |
266 | This function is to check if the remaining variable space is enough to set\r | |
267 | all Variables from argument list successfully. The purpose of the check\r | |
268 | is to keep the consistency of the Variables to be in variable storage.\r | |
8a2d4996 | 269 | \r |
fa0737a8 SZ |
270 | Note: Variables are assumed to be in same storage.\r |
271 | The set sequence of Variables will be same with the sequence of VariableEntry from argument list,\r | |
272 | so follow the argument sequence to check the Variables.\r | |
273 | \r | |
274 | @param[in] Attributes Variable attributes for Variable entries.\r | |
275 | @param[in] Marker VA_LIST style variable argument list.\r | |
276 | The variable argument list with type VARIABLE_ENTRY_CONSISTENCY *.\r | |
277 | A NULL terminates the list. The VariableSize of\r | |
278 | VARIABLE_ENTRY_CONSISTENCY is the variable data size as input.\r | |
279 | It will be changed to variable total size as output.\r | |
280 | \r | |
281 | @retval TRUE Have enough variable space to set the Variables successfully.\r | |
282 | @retval FALSE No enough variable space to set the Variables successfully.\r | |
283 | \r | |
284 | **/\r | |
285 | BOOLEAN\r | |
286 | EFIAPI\r | |
287 | CheckRemainingSpaceForConsistencyInternal (\r | |
288 | IN UINT32 Attributes,\r | |
289 | IN VA_LIST Marker\r | |
290 | );\r | |
291 | \r | |
292 | /**\r | |
293 | Update the variable region with Variable information. If EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS is set,\r | |
294 | index of associated public key is needed.\r | |
8a2d4996 | 295 | \r |
fa0737a8 SZ |
296 | @param[in] VariableName Name of variable.\r |
297 | @param[in] VendorGuid Guid of variable.\r | |
298 | @param[in] Data Variable data.\r | |
299 | @param[in] DataSize Size of data. 0 means delete.\r | |
300 | @param[in] Attributes Attributes of the variable.\r | |
301 | @param[in] KeyIndex Index of associated public key.\r | |
302 | @param[in] MonotonicCount Value of associated monotonic count.\r | |
23b06935 | 303 | @param[in, out] Variable The variable information that is used to keep track of variable usage.\r |
8a2d4996 | 304 | \r |
fa0737a8 | 305 | @param[in] TimeStamp Value of associated TimeStamp.\r |
8a2d4996 | 306 | \r |
fa0737a8 | 307 | @retval EFI_SUCCESS The update operation is success.\r |
8a2d4996 | 308 | @retval EFI_OUT_OF_RESOURCES Variable region is full, cannot write other data into this region.\r |
309 | \r | |
310 | **/\r | |
311 | EFI_STATUS\r | |
312 | UpdateVariable (\r | |
313 | IN CHAR16 *VariableName,\r | |
314 | IN EFI_GUID *VendorGuid,\r | |
315 | IN VOID *Data,\r | |
316 | IN UINTN DataSize,\r | |
317 | IN UINT32 Attributes OPTIONAL,\r | |
fa0737a8 SZ |
318 | IN UINT32 KeyIndex OPTIONAL,\r |
319 | IN UINT64 MonotonicCount OPTIONAL,\r | |
320 | IN OUT VARIABLE_POINTER_TRACK *Variable,\r | |
321 | IN EFI_TIME *TimeStamp OPTIONAL\r | |
8a2d4996 | 322 | );\r |
323 | \r | |
324 | \r | |
325 | /**\r | |
326 | Return TRUE if ExitBootServices () has been called.\r | |
fa0737a8 | 327 | \r |
8a2d4996 | 328 | @retval TRUE If ExitBootServices () has been called.\r |
329 | **/\r | |
330 | BOOLEAN\r | |
331 | AtRuntime (\r | |
332 | VOID\r | |
333 | );\r | |
334 | \r | |
335 | /**\r | |
336 | Initializes a basic mutual exclusion lock.\r | |
337 | \r | |
fa0737a8 SZ |
338 | This function initializes a basic mutual exclusion lock to the released state\r |
339 | and returns the lock. Each lock provides mutual exclusion access at its task\r | |
8a2d4996 | 340 | priority level. Since there is no preemption or multiprocessor support in EFI,\r |
341 | acquiring the lock only consists of raising to the locks TPL.\r | |
342 | If Lock is NULL, then ASSERT().\r | |
343 | If Priority is not a valid TPL value, then ASSERT().\r | |
344 | \r | |
345 | @param Lock A pointer to the lock data structure to initialize.\r | |
346 | @param Priority EFI TPL is associated with the lock.\r | |
347 | \r | |
348 | @return The lock.\r | |
349 | \r | |
350 | **/\r | |
351 | EFI_LOCK *\r | |
352 | InitializeLock (\r | |
353 | IN OUT EFI_LOCK *Lock,\r | |
354 | IN EFI_TPL Priority\r | |
355 | );\r | |
356 | \r | |
fa0737a8 | 357 | \r |
8a2d4996 | 358 | /**\r |
359 | Acquires lock only at boot time. Simply returns at runtime.\r | |
360 | \r | |
361 | This is a temperary function that will be removed when\r | |
362 | EfiAcquireLock() in UefiLib can handle the call in UEFI\r | |
363 | Runtimer driver in RT phase.\r | |
364 | It calls EfiAcquireLock() at boot time, and simply returns\r | |
365 | at runtime.\r | |
366 | \r | |
367 | @param Lock A pointer to the lock to acquire.\r | |
368 | \r | |
369 | **/\r | |
370 | VOID\r | |
371 | AcquireLockOnlyAtBootTime (\r | |
372 | IN EFI_LOCK *Lock\r | |
373 | );\r | |
374 | \r | |
375 | \r | |
376 | /**\r | |
377 | Releases lock only at boot time. Simply returns at runtime.\r | |
378 | \r | |
379 | This is a temperary function which will be removed when\r | |
380 | EfiReleaseLock() in UefiLib can handle the call in UEFI\r | |
381 | Runtimer driver in RT phase.\r | |
382 | It calls EfiReleaseLock() at boot time and simply returns\r | |
383 | at runtime.\r | |
384 | \r | |
385 | @param Lock A pointer to the lock to release.\r | |
386 | \r | |
387 | **/\r | |
388 | VOID\r | |
389 | ReleaseLockOnlyAtBootTime (\r | |
390 | IN EFI_LOCK *Lock\r | |
fa0737a8 | 391 | );\r |
8a2d4996 | 392 | \r |
393 | /**\r | |
0a18956d | 394 | Retrieve the FVB protocol interface by HANDLE.\r |
8a2d4996 | 395 | \r |
396 | @param[in] FvBlockHandle The handle of FVB protocol that provides services for\r | |
397 | reading, writing, and erasing the target block.\r | |
398 | @param[out] FvBlock The interface of FVB protocol\r | |
399 | \r | |
400 | @retval EFI_SUCCESS The interface information for the specified protocol was returned.\r | |
401 | @retval EFI_UNSUPPORTED The device does not support the FVB protocol.\r | |
402 | @retval EFI_INVALID_PARAMETER FvBlockHandle is not a valid EFI_HANDLE or FvBlock is NULL.\r | |
fa0737a8 | 403 | \r |
8a2d4996 | 404 | **/\r |
405 | EFI_STATUS\r | |
406 | GetFvbByHandle (\r | |
407 | IN EFI_HANDLE FvBlockHandle,\r | |
408 | OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL **FvBlock\r | |
409 | );\r | |
410 | \r | |
8a2d4996 | 411 | /**\r |
412 | Function returns an array of handles that support the FVB protocol\r | |
fa0737a8 | 413 | in a buffer allocated from pool.\r |
8a2d4996 | 414 | \r |
415 | @param[out] NumberHandles The number of handles returned in Buffer.\r | |
416 | @param[out] Buffer A pointer to the buffer to return the requested\r | |
417 | array of handles that support FVB protocol.\r | |
418 | \r | |
419 | @retval EFI_SUCCESS The array of handles was returned in Buffer, and the number of\r | |
420 | handles in Buffer was returned in NumberHandles.\r | |
421 | @retval EFI_NOT_FOUND No FVB handle was found.\r | |
422 | @retval EFI_OUT_OF_RESOURCES There is not enough pool memory to store the matching results.\r | |
423 | @retval EFI_INVALID_PARAMETER NumberHandles is NULL or Buffer is NULL.\r | |
fa0737a8 | 424 | \r |
8a2d4996 | 425 | **/\r |
426 | EFI_STATUS\r | |
427 | GetFvbCountAndBuffer (\r | |
428 | OUT UINTN *NumberHandles,\r | |
429 | OUT EFI_HANDLE **Buffer\r | |
430 | );\r | |
431 | \r | |
432 | /**\r | |
433 | Initializes variable store area for non-volatile and volatile variable.\r | |
434 | \r | |
435 | @retval EFI_SUCCESS Function successfully executed.\r | |
436 | @retval EFI_OUT_OF_RESOURCES Fail to allocate enough memory resource.\r | |
437 | \r | |
438 | **/\r | |
439 | EFI_STATUS\r | |
440 | VariableCommonInitialize (\r | |
441 | VOID\r | |
442 | );\r | |
443 | \r | |
444 | /**\r | |
445 | This function reclaims variable storage if free size is below the threshold.\r | |
fa0737a8 | 446 | \r |
8a2d4996 | 447 | **/\r |
448 | VOID\r | |
449 | ReclaimForOS(\r | |
450 | VOID\r | |
fa0737a8 SZ |
451 | );\r |
452 | \r | |
453 | /**\r | |
454 | Get non-volatile maximum variable size.\r | |
8a2d4996 | 455 | \r |
fa0737a8 SZ |
456 | @return Non-volatile maximum variable size.\r |
457 | \r | |
458 | **/\r | |
459 | UINTN\r | |
460 | GetNonVolatileMaxVariableSize (\r | |
461 | VOID\r | |
462 | );\r | |
8a2d4996 | 463 | \r |
9b4a2032 LE |
464 | /**\r |
465 | Get maximum variable size, covering both non-volatile and volatile variables.\r | |
466 | \r | |
467 | @return Maximum variable size.\r | |
468 | \r | |
469 | **/\r | |
470 | UINTN\r | |
471 | GetMaxVariableSize (\r | |
472 | VOID\r | |
473 | );\r | |
474 | \r | |
8a2d4996 | 475 | /**\r |
476 | Initializes variable write service after FVB was ready.\r | |
477 | \r | |
478 | @retval EFI_SUCCESS Function successfully executed.\r | |
479 | @retval Others Fail to initialize the variable service.\r | |
480 | \r | |
481 | **/\r | |
482 | EFI_STATUS\r | |
483 | VariableWriteServiceInitialize (\r | |
484 | VOID\r | |
485 | );\r | |
fa0737a8 | 486 | \r |
8a2d4996 | 487 | /**\r |
0a18956d | 488 | Retrieve the SMM Fault Tolerent Write protocol interface.\r |
8a2d4996 | 489 | \r |
490 | @param[out] FtwProtocol The interface of SMM Ftw protocol\r | |
491 | \r | |
492 | @retval EFI_SUCCESS The SMM SAR protocol instance was found and returned in SarProtocol.\r | |
493 | @retval EFI_NOT_FOUND The SMM SAR protocol instance was not found.\r | |
494 | @retval EFI_INVALID_PARAMETER SarProtocol is NULL.\r | |
495 | \r | |
496 | **/\r | |
497 | EFI_STATUS\r | |
498 | GetFtwProtocol (\r | |
499 | OUT VOID **FtwProtocol\r | |
500 | );\r | |
501 | \r | |
502 | /**\r | |
503 | Get the proper fvb handle and/or fvb protocol by the given Flash address.\r | |
504 | \r | |
505 | @param[in] Address The Flash address.\r | |
506 | @param[out] FvbHandle In output, if it is not NULL, it points to the proper FVB handle.\r | |
507 | @param[out] FvbProtocol In output, if it is not NULL, it points to the proper FVB protocol.\r | |
508 | \r | |
509 | **/\r | |
510 | EFI_STATUS\r | |
511 | GetFvbInfoByAddress (\r | |
512 | IN EFI_PHYSICAL_ADDRESS Address,\r | |
513 | OUT EFI_HANDLE *FvbHandle OPTIONAL,\r | |
514 | OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL **FvbProtocol OPTIONAL\r | |
515 | );\r | |
516 | \r | |
517 | /**\r | |
518 | \r | |
519 | This code finds variable in storage blocks (Volatile or Non-Volatile).\r | |
520 | \r | |
fa0737a8 SZ |
521 | Caution: This function may receive untrusted input.\r |
522 | This function may be invoked in SMM mode, and datasize and data are external input.\r | |
523 | This function will do basic validation, before parse the data.\r | |
524 | \r | |
8a2d4996 | 525 | @param VariableName Name of Variable to be found.\r |
526 | @param VendorGuid Variable vendor GUID.\r | |
527 | @param Attributes Attribute value of the variable found.\r | |
528 | @param DataSize Size of Data found. If size is less than the\r | |
529 | data, this value contains the required size.\r | |
746645bd SZ |
530 | @param Data The buffer to return the contents of the variable. May be NULL\r |
531 | with a zero DataSize in order to determine the size buffer needed.\r | |
fa0737a8 | 532 | \r |
8a2d4996 | 533 | @return EFI_INVALID_PARAMETER Invalid parameter.\r |
534 | @return EFI_SUCCESS Find the specified variable.\r | |
535 | @return EFI_NOT_FOUND Not found.\r | |
536 | @return EFI_BUFFER_TO_SMALL DataSize is too small for the result.\r | |
537 | \r | |
538 | **/\r | |
539 | EFI_STATUS\r | |
540 | EFIAPI\r | |
541 | VariableServiceGetVariable (\r | |
542 | IN CHAR16 *VariableName,\r | |
543 | IN EFI_GUID *VendorGuid,\r | |
544 | OUT UINT32 *Attributes OPTIONAL,\r | |
545 | IN OUT UINTN *DataSize,\r | |
746645bd | 546 | OUT VOID *Data OPTIONAL\r |
8a2d4996 | 547 | );\r |
548 | \r | |
fa0737a8 SZ |
549 | /**\r |
550 | This code Finds the Next available variable.\r | |
551 | \r | |
552 | Caution: This function may receive untrusted input.\r | |
553 | This function may be invoked in SMM mode. This function will do basic validation, before parse the data.\r | |
554 | \r | |
555 | @param[in] VariableName Pointer to variable name.\r | |
556 | @param[in] VendorGuid Variable Vendor Guid.\r | |
557 | @param[out] VariablePtr Pointer to variable header address.\r | |
558 | \r | |
6f817f9b SZ |
559 | @retval EFI_SUCCESS The function completed successfully.\r |
560 | @retval EFI_NOT_FOUND The next variable was not found.\r | |
561 | @retval EFI_INVALID_PARAMETER If VariableName is not an empty string, while VendorGuid is NULL.\r | |
562 | @retval EFI_INVALID_PARAMETER The input values of VariableName and VendorGuid are not a name and\r | |
563 | GUID of an existing variable.\r | |
fa0737a8 SZ |
564 | \r |
565 | **/\r | |
566 | EFI_STATUS\r | |
567 | EFIAPI\r | |
568 | VariableServiceGetNextVariableInternal (\r | |
569 | IN CHAR16 *VariableName,\r | |
570 | IN EFI_GUID *VendorGuid,\r | |
571 | OUT VARIABLE_HEADER **VariablePtr\r | |
572 | );\r | |
573 | \r | |
8a2d4996 | 574 | /**\r |
575 | \r | |
576 | This code Finds the Next available variable.\r | |
577 | \r | |
efb01a10 SZ |
578 | Caution: This function may receive untrusted input.\r |
579 | This function may be invoked in SMM mode. This function will do basic validation, before parse the data.\r | |
580 | \r | |
6f817f9b SZ |
581 | @param VariableNameSize The size of the VariableName buffer. The size must be large\r |
582 | enough to fit input string supplied in VariableName buffer.\r | |
8a2d4996 | 583 | @param VariableName Pointer to variable name.\r |
584 | @param VendorGuid Variable Vendor Guid.\r | |
585 | \r | |
6f817f9b SZ |
586 | @retval EFI_SUCCESS The function completed successfully.\r |
587 | @retval EFI_NOT_FOUND The next variable was not found.\r | |
588 | @retval EFI_BUFFER_TOO_SMALL The VariableNameSize is too small for the result.\r | |
589 | VariableNameSize has been updated with the size needed to complete the request.\r | |
590 | @retval EFI_INVALID_PARAMETER VariableNameSize is NULL.\r | |
591 | @retval EFI_INVALID_PARAMETER VariableName is NULL.\r | |
592 | @retval EFI_INVALID_PARAMETER VendorGuid is NULL.\r | |
593 | @retval EFI_INVALID_PARAMETER The input values of VariableName and VendorGuid are not a name and\r | |
594 | GUID of an existing variable.\r | |
595 | @retval EFI_INVALID_PARAMETER Null-terminator is not found in the first VariableNameSize bytes of\r | |
596 | the input VariableName buffer.\r | |
8a2d4996 | 597 | \r |
598 | **/\r | |
599 | EFI_STATUS\r | |
600 | EFIAPI\r | |
601 | VariableServiceGetNextVariableName (\r | |
602 | IN OUT UINTN *VariableNameSize,\r | |
603 | IN OUT CHAR16 *VariableName,\r | |
604 | IN OUT EFI_GUID *VendorGuid\r | |
605 | );\r | |
606 | \r | |
607 | /**\r | |
608 | \r | |
609 | This code sets variable in storage blocks (Volatile or Non-Volatile).\r | |
610 | \r | |
efb01a10 SZ |
611 | Caution: This function may receive untrusted input.\r |
612 | This function may be invoked in SMM mode, and datasize and data are external input.\r | |
613 | This function will do basic validation, before parse the data.\r | |
fa0737a8 SZ |
614 | This function will parse the authentication carefully to avoid security issues, like\r |
615 | buffer overflow, integer overflow.\r | |
616 | This function will check attribute carefully to avoid authentication bypass.\r | |
efb01a10 | 617 | \r |
8a2d4996 | 618 | @param VariableName Name of Variable to be found.\r |
619 | @param VendorGuid Variable vendor GUID.\r | |
620 | @param Attributes Attribute value of the variable found\r | |
621 | @param DataSize Size of Data found. If size is less than the\r | |
622 | data, this value contains the required size.\r | |
623 | @param Data Data pointer.\r | |
624 | \r | |
625 | @return EFI_INVALID_PARAMETER Invalid parameter.\r | |
626 | @return EFI_SUCCESS Set successfully.\r | |
627 | @return EFI_OUT_OF_RESOURCES Resource not enough to set variable.\r | |
628 | @return EFI_NOT_FOUND Not found.\r | |
629 | @return EFI_WRITE_PROTECTED Variable is read-only.\r | |
630 | \r | |
631 | **/\r | |
632 | EFI_STATUS\r | |
633 | EFIAPI\r | |
634 | VariableServiceSetVariable (\r | |
635 | IN CHAR16 *VariableName,\r | |
636 | IN EFI_GUID *VendorGuid,\r | |
637 | IN UINT32 Attributes,\r | |
638 | IN UINTN DataSize,\r | |
639 | IN VOID *Data\r | |
640 | );\r | |
641 | \r | |
b2bd493e SZ |
642 | /**\r |
643 | \r | |
644 | This code returns information about the EFI variables.\r | |
645 | \r | |
efb01a10 SZ |
646 | Caution: This function may receive untrusted input.\r |
647 | This function may be invoked in SMM mode. This function will do basic validation, before parse the data.\r | |
648 | \r | |
b2bd493e SZ |
649 | @param Attributes Attributes bitmask to specify the type of variables\r |
650 | on which to return information.\r | |
651 | @param MaximumVariableStorageSize Pointer to the maximum size of the storage space available\r | |
652 | for the EFI variables associated with the attributes specified.\r | |
653 | @param RemainingVariableStorageSize Pointer to the remaining size of the storage space available\r | |
654 | for EFI variables associated with the attributes specified.\r | |
655 | @param MaximumVariableSize Pointer to the maximum size of an individual EFI variables\r | |
656 | associated with the attributes specified.\r | |
657 | \r | |
658 | @return EFI_SUCCESS Query successfully.\r | |
659 | \r | |
660 | **/\r | |
661 | EFI_STATUS\r | |
662 | EFIAPI\r | |
663 | VariableServiceQueryVariableInfoInternal (\r | |
664 | IN UINT32 Attributes,\r | |
665 | OUT UINT64 *MaximumVariableStorageSize,\r | |
666 | OUT UINT64 *RemainingVariableStorageSize,\r | |
667 | OUT UINT64 *MaximumVariableSize\r | |
668 | );\r | |
669 | \r | |
8a2d4996 | 670 | /**\r |
671 | \r | |
672 | This code returns information about the EFI variables.\r | |
673 | \r | |
efb01a10 SZ |
674 | Caution: This function may receive untrusted input.\r |
675 | This function may be invoked in SMM mode. This function will do basic validation, before parse the data.\r | |
676 | \r | |
8a2d4996 | 677 | @param Attributes Attributes bitmask to specify the type of variables\r |
678 | on which to return information.\r | |
679 | @param MaximumVariableStorageSize Pointer to the maximum size of the storage space available\r | |
680 | for the EFI variables associated with the attributes specified.\r | |
681 | @param RemainingVariableStorageSize Pointer to the remaining size of the storage space available\r | |
682 | for EFI variables associated with the attributes specified.\r | |
683 | @param MaximumVariableSize Pointer to the maximum size of an individual EFI variables\r | |
684 | associated with the attributes specified.\r | |
685 | \r | |
686 | @return EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied.\r | |
687 | @return EFI_SUCCESS Query successfully.\r | |
688 | @return EFI_UNSUPPORTED The attribute is not supported on this platform.\r | |
689 | \r | |
690 | **/\r | |
691 | EFI_STATUS\r | |
692 | EFIAPI\r | |
693 | VariableServiceQueryVariableInfo (\r | |
694 | IN UINT32 Attributes,\r | |
695 | OUT UINT64 *MaximumVariableStorageSize,\r | |
696 | OUT UINT64 *RemainingVariableStorageSize,\r | |
697 | OUT UINT64 *MaximumVariableSize\r | |
fa0737a8 | 698 | );\r |
ff843847 RN |
699 | \r |
700 | /**\r | |
701 | Mark a variable that will become read-only after leaving the DXE phase of execution.\r | |
702 | \r | |
703 | @param[in] This The VARIABLE_LOCK_PROTOCOL instance.\r | |
704 | @param[in] VariableName A pointer to the variable name that will be made read-only subsequently.\r | |
705 | @param[in] VendorGuid A pointer to the vendor GUID that will be made read-only subsequently.\r | |
706 | \r | |
707 | @retval EFI_SUCCESS The variable specified by the VariableName and the VendorGuid was marked\r | |
708 | as pending to be read-only.\r | |
709 | @retval EFI_INVALID_PARAMETER VariableName or VendorGuid is NULL.\r | |
710 | Or VariableName is an empty string.\r | |
711 | @retval EFI_ACCESS_DENIED EFI_END_OF_DXE_EVENT_GROUP_GUID or EFI_EVENT_GROUP_READY_TO_BOOT has\r | |
712 | already been signaled.\r | |
713 | @retval EFI_OUT_OF_RESOURCES There is not enough resource to hold the lock request.\r | |
714 | **/\r | |
715 | EFI_STATUS\r | |
716 | EFIAPI\r | |
717 | VariableLockRequestToLock (\r | |
718 | IN CONST EDKII_VARIABLE_LOCK_PROTOCOL *This,\r | |
719 | IN CHAR16 *VariableName,\r | |
720 | IN EFI_GUID *VendorGuid\r | |
721 | );\r | |
722 | \r | |
efb01a10 SZ |
723 | /**\r |
724 | Register SetVariable check handler.\r | |
725 | \r | |
726 | @param[in] Handler Pointer to check handler.\r | |
727 | \r | |
728 | @retval EFI_SUCCESS The SetVariable check handler was registered successfully.\r | |
729 | @retval EFI_INVALID_PARAMETER Handler is NULL.\r | |
730 | @retval EFI_ACCESS_DENIED EFI_END_OF_DXE_EVENT_GROUP_GUID or EFI_EVENT_GROUP_READY_TO_BOOT has\r | |
731 | already been signaled.\r | |
732 | @retval EFI_OUT_OF_RESOURCES There is not enough resource for the SetVariable check handler register request.\r | |
733 | @retval EFI_UNSUPPORTED This interface is not implemented.\r | |
734 | For example, it is unsupported in VarCheck protocol if both VarCheck and SmmVarCheck protocols are present.\r | |
735 | \r | |
736 | **/\r | |
737 | EFI_STATUS\r | |
738 | EFIAPI\r | |
739 | VarCheckRegisterSetVariableCheckHandler (\r | |
740 | IN VAR_CHECK_SET_VARIABLE_CHECK_HANDLER Handler\r | |
741 | );\r | |
742 | \r | |
4edb1866 | 743 | /**\r |
fa0737a8 | 744 | Variable property set.\r |
4edb1866 | 745 | \r |
fa0737a8 SZ |
746 | @param[in] Name Pointer to the variable name.\r |
747 | @param[in] Guid Pointer to the vendor GUID.\r | |
748 | @param[in] VariableProperty Pointer to the input variable property.\r | |
4edb1866 | 749 | \r |
fa0737a8 SZ |
750 | @retval EFI_SUCCESS The property of variable specified by the Name and Guid was set successfully.\r |
751 | @retval EFI_INVALID_PARAMETER Name, Guid or VariableProperty is NULL, or Name is an empty string,\r | |
752 | or the fields of VariableProperty are not valid.\r | |
753 | @retval EFI_ACCESS_DENIED EFI_END_OF_DXE_EVENT_GROUP_GUID or EFI_EVENT_GROUP_READY_TO_BOOT has\r | |
754 | already been signaled.\r | |
755 | @retval EFI_OUT_OF_RESOURCES There is not enough resource for the variable property set request.\r | |
4edb1866 SZ |
756 | \r |
757 | **/\r | |
758 | EFI_STATUS\r | |
759 | EFIAPI\r | |
fa0737a8 | 760 | VarCheckVariablePropertySet (\r |
4edb1866 SZ |
761 | IN CHAR16 *Name,\r |
762 | IN EFI_GUID *Guid,\r | |
fa0737a8 | 763 | IN VAR_CHECK_VARIABLE_PROPERTY *VariableProperty\r |
4edb1866 SZ |
764 | );\r |
765 | \r | |
efb01a10 SZ |
766 | /**\r |
767 | Variable property get.\r | |
768 | \r | |
769 | @param[in] Name Pointer to the variable name.\r | |
770 | @param[in] Guid Pointer to the vendor GUID.\r | |
771 | @param[out] VariableProperty Pointer to the output variable property.\r | |
772 | \r | |
773 | @retval EFI_SUCCESS The property of variable specified by the Name and Guid was got successfully.\r | |
774 | @retval EFI_INVALID_PARAMETER Name, Guid or VariableProperty is NULL, or Name is an empty string.\r | |
775 | @retval EFI_NOT_FOUND The property of variable specified by the Name and Guid was not found.\r | |
776 | \r | |
777 | **/\r | |
778 | EFI_STATUS\r | |
779 | EFIAPI\r | |
780 | VarCheckVariablePropertyGet (\r | |
781 | IN CHAR16 *Name,\r | |
782 | IN EFI_GUID *Guid,\r | |
783 | OUT VAR_CHECK_VARIABLE_PROPERTY *VariableProperty\r | |
784 | );\r | |
785 | \r | |
4edb1866 SZ |
786 | /**\r |
787 | Initialize variable quota.\r | |
788 | \r | |
789 | **/\r | |
790 | VOID\r | |
791 | InitializeVariableQuota (\r | |
792 | VOID\r | |
793 | );\r | |
794 | \r | |
8a2d4996 | 795 | extern VARIABLE_MODULE_GLOBAL *mVariableModuleGlobal;\r |
796 | \r | |
8021f4c7 | 797 | extern AUTH_VAR_LIB_CONTEXT_OUT mAuthContextOut;\r |
fa0737a8 SZ |
798 | \r |
799 | /**\r | |
800 | Finds variable in storage blocks of volatile and non-volatile storage areas.\r | |
801 | \r | |
802 | This code finds variable in storage blocks of volatile and non-volatile storage areas.\r | |
803 | If VariableName is an empty string, then we just return the first\r | |
804 | qualified variable without comparing VariableName and VendorGuid.\r | |
805 | \r | |
806 | @param[in] VariableName Name of the variable to be found.\r | |
807 | @param[in] VendorGuid Variable vendor GUID to be found.\r | |
808 | @param[out] AuthVariableInfo Pointer to AUTH_VARIABLE_INFO structure for\r | |
809 | output of the variable found.\r | |
810 | \r | |
811 | @retval EFI_INVALID_PARAMETER If VariableName is not an empty string,\r | |
812 | while VendorGuid is NULL.\r | |
813 | @retval EFI_SUCCESS Variable successfully found.\r | |
814 | @retval EFI_NOT_FOUND Variable not found\r | |
815 | \r | |
816 | **/\r | |
817 | EFI_STATUS\r | |
818 | EFIAPI\r | |
819 | VariableExLibFindVariable (\r | |
820 | IN CHAR16 *VariableName,\r | |
821 | IN EFI_GUID *VendorGuid,\r | |
822 | OUT AUTH_VARIABLE_INFO *AuthVariableInfo\r | |
823 | );\r | |
824 | \r | |
825 | /**\r | |
826 | Finds next variable in storage blocks of volatile and non-volatile storage areas.\r | |
827 | \r | |
828 | This code finds next variable in storage blocks of volatile and non-volatile storage areas.\r | |
829 | If VariableName is an empty string, then we just return the first\r | |
830 | qualified variable without comparing VariableName and VendorGuid.\r | |
831 | \r | |
832 | @param[in] VariableName Name of the variable to be found.\r | |
833 | @param[in] VendorGuid Variable vendor GUID to be found.\r | |
834 | @param[out] AuthVariableInfo Pointer to AUTH_VARIABLE_INFO structure for\r | |
835 | output of the next variable.\r | |
836 | \r | |
837 | @retval EFI_INVALID_PARAMETER If VariableName is not an empty string,\r | |
838 | while VendorGuid is NULL.\r | |
839 | @retval EFI_SUCCESS Variable successfully found.\r | |
840 | @retval EFI_NOT_FOUND Variable not found\r | |
841 | \r | |
842 | **/\r | |
843 | EFI_STATUS\r | |
844 | EFIAPI\r | |
845 | VariableExLibFindNextVariable (\r | |
846 | IN CHAR16 *VariableName,\r | |
847 | IN EFI_GUID *VendorGuid,\r | |
848 | OUT AUTH_VARIABLE_INFO *AuthVariableInfo\r | |
849 | );\r | |
850 | \r | |
851 | /**\r | |
852 | Update the variable region with Variable information.\r | |
853 | \r | |
854 | @param[in] AuthVariableInfo Pointer AUTH_VARIABLE_INFO structure for\r | |
855 | input of the variable.\r | |
856 | \r | |
857 | @retval EFI_SUCCESS The update operation is success.\r | |
858 | @retval EFI_INVALID_PARAMETER Invalid parameter.\r | |
859 | @retval EFI_WRITE_PROTECTED Variable is write-protected.\r | |
860 | @retval EFI_OUT_OF_RESOURCES There is not enough resource.\r | |
861 | \r | |
862 | **/\r | |
863 | EFI_STATUS\r | |
864 | EFIAPI\r | |
865 | VariableExLibUpdateVariable (\r | |
866 | IN AUTH_VARIABLE_INFO *AuthVariableInfo\r | |
867 | );\r | |
868 | \r | |
869 | /**\r | |
870 | Get scratch buffer.\r | |
871 | \r | |
872 | @param[in, out] ScratchBufferSize Scratch buffer size. If input size is greater than\r | |
873 | the maximum supported buffer size, this value contains\r | |
874 | the maximum supported buffer size as output.\r | |
875 | @param[out] ScratchBuffer Pointer to scratch buffer address.\r | |
876 | \r | |
877 | @retval EFI_SUCCESS Get scratch buffer successfully.\r | |
878 | @retval EFI_UNSUPPORTED If input size is greater than the maximum supported buffer size.\r | |
879 | \r | |
880 | **/\r | |
881 | EFI_STATUS\r | |
882 | EFIAPI\r | |
883 | VariableExLibGetScratchBuffer (\r | |
884 | IN OUT UINTN *ScratchBufferSize,\r | |
885 | OUT VOID **ScratchBuffer\r | |
886 | );\r | |
887 | \r | |
888 | /**\r | |
889 | This function is to check if the remaining variable space is enough to set\r | |
890 | all Variables from argument list successfully. The purpose of the check\r | |
891 | is to keep the consistency of the Variables to be in variable storage.\r | |
892 | \r | |
893 | Note: Variables are assumed to be in same storage.\r | |
894 | The set sequence of Variables will be same with the sequence of VariableEntry from argument list,\r | |
895 | so follow the argument sequence to check the Variables.\r | |
896 | \r | |
897 | @param[in] Attributes Variable attributes for Variable entries.\r | |
898 | @param ... The variable argument list with type VARIABLE_ENTRY_CONSISTENCY *.\r | |
899 | A NULL terminates the list. The VariableSize of\r | |
900 | VARIABLE_ENTRY_CONSISTENCY is the variable data size as input.\r | |
901 | It will be changed to variable total size as output.\r | |
902 | \r | |
903 | @retval TRUE Have enough variable space to set the Variables successfully.\r | |
904 | @retval FALSE No enough variable space to set the Variables successfully.\r | |
905 | \r | |
906 | **/\r | |
907 | BOOLEAN\r | |
908 | EFIAPI\r | |
909 | VariableExLibCheckRemainingSpaceForConsistency (\r | |
910 | IN UINT32 Attributes,\r | |
911 | ...\r | |
912 | );\r | |
913 | \r | |
914 | /**\r | |
915 | Return TRUE if at OS runtime.\r | |
916 | \r | |
917 | @retval TRUE If at OS runtime.\r | |
918 | @retval FALSE If at boot time.\r | |
919 | \r | |
920 | **/\r | |
921 | BOOLEAN\r | |
922 | EFIAPI\r | |
923 | VariableExLibAtRuntime (\r | |
924 | VOID\r | |
925 | );\r | |
926 | \r | |
8d3a5c82 | 927 | #endif\r |