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