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