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