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