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