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