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