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