3 Implement all four UEFI Runtime Variable services for the nonvolatile
4 and volatile storage space and install variable architecture protocol.
6 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 VARIABLE_MODULE_GLOBAL
*mVariableModuleGlobal
;
20 EFI_EVENT mVirtualAddressChangeEvent
= NULL
;
21 EFI_HANDLE mHandle
= NULL
;
24 /// The current Hii implementation accesses this variable many times on every boot.
25 /// Other common variables are only accessed once. This is why this cache algorithm
26 /// only targets a single variable. Probably to get an performance improvement out of
27 /// a Cache you would need a cache that improves the search performance for a variable.
29 VARIABLE_CACHE_ENTRY mVariableCache
[] = {
31 &gEfiGlobalVariableGuid
,
38 &gEfiGlobalVariableGuid
,
46 VARIABLE_INFO_ENTRY
*gVariableInfo
= NULL
;
47 EFI_EVENT mFvbRegistration
= NULL
;
50 Update the variable region with Variable information. These are the same
51 arguments as the EFI Variable services.
53 @param[in] VariableName Name of variable
55 @param[in] VendorGuid Guid of variable
57 @param[in] Data Variable data
59 @param[in] DataSize Size of data. 0 means delete
61 @param[in] Attributes Attribues of the variable
63 @param[in] Variable The variable information which is used to keep track of variable usage.
65 @retval EFI_SUCCESS The update operation is success.
67 @retval EFI_OUT_OF_RESOURCES Variable region is full, can not write other data into this region.
73 IN CHAR16
*VariableName
,
74 IN EFI_GUID
*VendorGuid
,
77 IN UINT32 Attributes OPTIONAL
,
78 IN VARIABLE_POINTER_TRACK
*Variable
82 Acquires lock only at boot time. Simply returns at runtime.
84 This is a temperary function which will be removed when
85 EfiAcquireLock() in UefiLib can handle the call in UEFI
86 Runtimer driver in RT phase.
87 It calls EfiAcquireLock() at boot time, and simply returns
90 @param Lock A pointer to the lock to acquire
94 AcquireLockOnlyAtBootTime (
98 if (!EfiAtRuntime ()) {
99 EfiAcquireLock (Lock
);
104 Releases lock only at boot time. Simply returns at runtime.
106 This is a temperary function which will be removed when
107 EfiReleaseLock() in UefiLib can handle the call in UEFI
108 Runtimer driver in RT phase.
109 It calls EfiReleaseLock() at boot time, and simply returns
112 @param Lock A pointer to the lock to release
116 ReleaseLockOnlyAtBootTime (
120 if (!EfiAtRuntime ()) {
121 EfiReleaseLock (Lock
);
127 Routine used to track statistical information about variable usage.
128 The data is stored in the EFI system table so it can be accessed later.
129 VariableInfo.efi can dump out the table. Only Boot Services variable
130 accesses are tracked by this code. The PcdVariableCollectStatistics
131 build flag controls if this feature is enabled.
133 A read that hits in the cache will have Read and Cache true for
134 the transaction. Data is allocated by this routine, but never
137 @param[in] VariableName Name of the Variable to track
138 @param[in] VendorGuid Guid of the Variable to track
139 @param[in] Volatile TRUE if volatile FALSE if non-volatile
140 @param[in] Read TRUE if GetVariable() was called
141 @param[in] Write TRUE if SetVariable() was called
142 @param[in] Delete TRUE if deleted via SetVariable()
143 @param[in] Cache TRUE for a cache hit.
148 IN CHAR16
*VariableName
,
149 IN EFI_GUID
*VendorGuid
,
157 VARIABLE_INFO_ENTRY
*Entry
;
159 if (FeaturePcdGet (PcdVariableCollectStatistics
)) {
161 if (EfiAtRuntime ()) {
162 // Don't collect statistics at runtime
166 if (gVariableInfo
== NULL
) {
168 // on the first call allocate a entry and place a pointer to it in
169 // the EFI System Table
171 gVariableInfo
= AllocateZeroPool (sizeof (VARIABLE_INFO_ENTRY
));
172 ASSERT (gVariableInfo
!= NULL
);
174 CopyGuid (&gVariableInfo
->VendorGuid
, VendorGuid
);
175 gVariableInfo
->Name
= AllocatePool (StrSize (VariableName
));
176 ASSERT (gVariableInfo
->Name
!= NULL
);
177 StrCpy (gVariableInfo
->Name
, VariableName
);
178 gVariableInfo
->Volatile
= Volatile
;
180 gBS
->InstallConfigurationTable (&gEfiVariableGuid
, gVariableInfo
);
184 for (Entry
= gVariableInfo
; Entry
!= NULL
; Entry
= Entry
->Next
) {
185 if (CompareGuid (VendorGuid
, &Entry
->VendorGuid
)) {
186 if (StrCmp (VariableName
, Entry
->Name
) == 0) {
194 Entry
->DeleteCount
++;
204 if (Entry
->Next
== NULL
) {
206 // If the entry is not in the table add it.
207 // Next iteration of the loop will fill in the data
209 Entry
->Next
= AllocateZeroPool (sizeof (VARIABLE_INFO_ENTRY
));
210 ASSERT (Entry
->Next
!= NULL
);
212 CopyGuid (&Entry
->Next
->VendorGuid
, VendorGuid
);
213 Entry
->Next
->Name
= AllocatePool (StrSize (VariableName
));
214 ASSERT (Entry
->Next
->Name
!= NULL
);
215 StrCpy (Entry
->Next
->Name
, VariableName
);
216 Entry
->Next
->Volatile
= Volatile
;
226 This code checks if variable header is valid or not.
228 @param Variable Pointer to the Variable Header.
230 @retval TRUE Variable header is valid.
231 @retval FALSE Variable header is not valid.
235 IsValidVariableHeader (
236 IN VARIABLE_HEADER
*Variable
239 if (Variable
== NULL
|| Variable
->StartId
!= VARIABLE_DATA
) {
249 This function writes data to the FWH at the correct LBA even if the LBAs
252 @param Global Pointer to VARAIBLE_GLOBAL structure
253 @param Volatile Point out the Variable is Volatile or Non-Volatile
254 @param SetByIndex TRUE if target pointer is given as index
255 FALSE if target pointer is absolute
256 @param Fvb Pointer to the writable FVB protocol
257 @param DataPtrIndex Pointer to the Data from the end of VARIABLE_STORE_HEADER
259 @param DataSize Size of data to be written
260 @param Buffer Pointer to the buffer from which data is written
262 @retval EFI_INVALID_PARAMETER Parameters not valid
263 @retval EFI_SUCCESS Variable store successfully updated
267 UpdateVariableStore (
268 IN VARIABLE_GLOBAL
*Global
,
270 IN BOOLEAN SetByIndex
,
271 IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL
*Fvb
,
272 IN UINTN DataPtrIndex
,
277 EFI_FV_BLOCK_MAP_ENTRY
*PtrBlockMapEntry
;
285 EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
;
286 VARIABLE_STORE_HEADER
*VolatileBase
;
287 EFI_PHYSICAL_ADDRESS FvVolHdr
;
288 EFI_PHYSICAL_ADDRESS DataPtr
;
292 DataPtr
= DataPtrIndex
;
295 // Check if the Data is Volatile
298 Status
= Fvb
->GetPhysicalAddress(Fvb
, &FvVolHdr
);
299 ASSERT_EFI_ERROR (Status
);
301 FwVolHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) ((UINTN
) FvVolHdr
);
303 // Data Pointer should point to the actual Address where data is to be
307 DataPtr
+= mVariableModuleGlobal
->VariableGlobal
.NonVolatileVariableBase
;
310 if ((DataPtr
+ DataSize
) >= ((EFI_PHYSICAL_ADDRESS
) (UINTN
) ((UINT8
*) FwVolHeader
+ FwVolHeader
->FvLength
))) {
311 return EFI_INVALID_PARAMETER
;
315 // Data Pointer should point to the actual Address where data is to be
318 VolatileBase
= (VARIABLE_STORE_HEADER
*) ((UINTN
) mVariableModuleGlobal
->VariableGlobal
.VolatileVariableBase
);
320 DataPtr
+= mVariableModuleGlobal
->VariableGlobal
.VolatileVariableBase
;
323 if ((DataPtr
+ DataSize
) >= ((UINTN
) ((UINT8
*) VolatileBase
+ VolatileBase
->Size
))) {
324 return EFI_INVALID_PARAMETER
;
328 // If Volatile Variable just do a simple mem copy.
330 CopyMem ((UINT8
*)(UINTN
)DataPtr
, Buffer
, DataSize
);
335 // If we are here we are dealing with Non-Volatile Variables
337 LinearOffset
= (UINTN
) FwVolHeader
;
338 CurrWritePtr
= (UINTN
) DataPtr
;
339 CurrWriteSize
= DataSize
;
343 if (CurrWritePtr
< LinearOffset
) {
344 return EFI_INVALID_PARAMETER
;
347 for (PtrBlockMapEntry
= FwVolHeader
->BlockMap
; PtrBlockMapEntry
->NumBlocks
!= 0; PtrBlockMapEntry
++) {
348 for (BlockIndex2
= 0; BlockIndex2
< PtrBlockMapEntry
->NumBlocks
; BlockIndex2
++) {
350 // Check to see if the Variable Writes are spanning through multiple
353 if ((CurrWritePtr
>= LinearOffset
) && (CurrWritePtr
< LinearOffset
+ PtrBlockMapEntry
->Length
)) {
354 if ((CurrWritePtr
+ CurrWriteSize
) <= (LinearOffset
+ PtrBlockMapEntry
->Length
)) {
355 Status
= Fvb
->Write (
358 (UINTN
) (CurrWritePtr
- LinearOffset
),
364 Size
= (UINT32
) (LinearOffset
+ PtrBlockMapEntry
->Length
- CurrWritePtr
);
365 Status
= Fvb
->Write (
368 (UINTN
) (CurrWritePtr
- LinearOffset
),
372 if (EFI_ERROR (Status
)) {
376 CurrWritePtr
= LinearOffset
+ PtrBlockMapEntry
->Length
;
377 CurrBuffer
= CurrBuffer
+ Size
;
378 CurrWriteSize
= CurrWriteSize
- Size
;
382 LinearOffset
+= PtrBlockMapEntry
->Length
;
393 This code gets the current status of Variable Store.
395 @param VarStoreHeader Pointer to the Variable Store Header.
397 @retval EfiRaw Variable store status is raw
398 @retval EfiValid Variable store status is valid
399 @retval EfiInvalid Variable store status is invalid
402 VARIABLE_STORE_STATUS
403 GetVariableStoreStatus (
404 IN VARIABLE_STORE_HEADER
*VarStoreHeader
407 if (CompareGuid (&VarStoreHeader
->Signature
, &gEfiVariableGuid
) &&
408 VarStoreHeader
->Format
== VARIABLE_STORE_FORMATTED
&&
409 VarStoreHeader
->State
== VARIABLE_STORE_HEALTHY
413 } else if (((UINT32
*)(&VarStoreHeader
->Signature
))[0] == 0xffffffff &&
414 ((UINT32
*)(&VarStoreHeader
->Signature
))[1] == 0xffffffff &&
415 ((UINT32
*)(&VarStoreHeader
->Signature
))[2] == 0xffffffff &&
416 ((UINT32
*)(&VarStoreHeader
->Signature
))[3] == 0xffffffff &&
417 VarStoreHeader
->Size
== 0xffffffff &&
418 VarStoreHeader
->Format
== 0xff &&
419 VarStoreHeader
->State
== 0xff
431 This code gets the size of name of variable.
433 @param Variable Pointer to the Variable Header
435 @return UINTN Size of variable in bytes
440 IN VARIABLE_HEADER
*Variable
443 if (Variable
->State
== (UINT8
) (-1) ||
444 Variable
->DataSize
== (UINT32
) (-1) ||
445 Variable
->NameSize
== (UINT32
) (-1) ||
446 Variable
->Attributes
== (UINT32
) (-1)) {
449 return (UINTN
) Variable
->NameSize
;
454 This code gets the size of variable data.
456 @param Variable Pointer to the Variable Header
458 @return Size of variable in bytes
463 IN VARIABLE_HEADER
*Variable
466 if (Variable
->State
== (UINT8
) (-1) ||
467 Variable
->DataSize
== (UINT32
) (-1) ||
468 Variable
->NameSize
== (UINT32
) (-1) ||
469 Variable
->Attributes
== (UINT32
) (-1)) {
472 return (UINTN
) Variable
->DataSize
;
477 This code gets the pointer to the variable name.
479 @param Variable Pointer to the Variable Header
481 @return Pointer to Variable Name which is Unicode encoding
486 IN VARIABLE_HEADER
*Variable
490 return (CHAR16
*) (Variable
+ 1);
495 This code gets the pointer to the variable data.
497 @param Variable Pointer to the Variable Header
499 @return Pointer to Variable Data
504 IN VARIABLE_HEADER
*Variable
510 // Be careful about pad size for alignment
512 Value
= (UINTN
) GetVariableNamePtr (Variable
);
513 Value
+= NameSizeOfVariable (Variable
);
514 Value
+= GET_PAD_SIZE (NameSizeOfVariable (Variable
));
516 return (UINT8
*) Value
;
522 This code gets the pointer to the next variable header.
524 @param Variable Pointer to the Variable Header
526 @return Pointer to next variable header
531 IN VARIABLE_HEADER
*Variable
536 if (!IsValidVariableHeader (Variable
)) {
540 Value
= (UINTN
) GetVariableDataPtr (Variable
);
541 Value
+= DataSizeOfVariable (Variable
);
542 Value
+= GET_PAD_SIZE (DataSizeOfVariable (Variable
));
545 // Be careful about pad size for alignment
547 return (VARIABLE_HEADER
*) HEADER_ALIGN (Value
);
552 Gets the pointer to the first variable header in given variable store area.
554 @param VarStoreHeader Pointer to the Variable Store Header.
556 @return Pointer to the first variable header
561 IN VARIABLE_STORE_HEADER
*VarStoreHeader
565 // The end of variable store
567 return (VARIABLE_HEADER
*) HEADER_ALIGN (VarStoreHeader
+ 1);
572 Gets the pointer to the end of the variable storage area.
574 This function gets pointer to the end of the variable storage
575 area, according to the input variable store header.
577 @param VarStoreHeader Pointer to the Variable Store Header
579 @return Pointer to the end of the variable storage area
584 IN VARIABLE_STORE_HEADER
*VarStoreHeader
588 // The end of variable store
590 return (VARIABLE_HEADER
*) HEADER_ALIGN ((UINTN
) VarStoreHeader
+ VarStoreHeader
->Size
);
596 Variable store garbage collection and reclaim operation.
598 @param VariableBase Base address of variable store
599 @param LastVariableOffset Offset of last variable
600 @param IsVolatile The variable store is volatile or not,
601 if it is non-volatile, need FTW
602 @param UpdatingVariable Pointer to updateing variable.
604 @return EFI_OUT_OF_RESOURCES
611 IN EFI_PHYSICAL_ADDRESS VariableBase
,
612 OUT UINTN
*LastVariableOffset
,
613 IN BOOLEAN IsVolatile
,
614 IN VARIABLE_HEADER
*UpdatingVariable
617 VARIABLE_HEADER
*Variable
;
618 VARIABLE_HEADER
*AddedVariable
;
619 VARIABLE_HEADER
*NextVariable
;
620 VARIABLE_HEADER
*NextAddedVariable
;
621 VARIABLE_STORE_HEADER
*VariableStoreHeader
;
623 UINTN MaximumBufferSize
;
625 UINTN VariableNameSize
;
626 UINTN UpdatingVariableNameSize
;
633 CHAR16
*VariableNamePtr
;
634 CHAR16
*UpdatingVariableNamePtr
;
636 VariableStoreHeader
= (VARIABLE_STORE_HEADER
*) ((UINTN
) VariableBase
);
638 // recaluate the total size of Common/HwErr type variables in non-volatile area.
641 mVariableModuleGlobal
->CommonVariableTotalSize
= 0;
642 mVariableModuleGlobal
->HwErrVariableTotalSize
= 0;
646 // Start Pointers for the variable.
648 Variable
= GetStartPointer (VariableStoreHeader
);
649 MaximumBufferSize
= sizeof (VARIABLE_STORE_HEADER
);
651 while (IsValidVariableHeader (Variable
)) {
652 NextVariable
= GetNextVariablePtr (Variable
);
653 if (Variable
->State
== VAR_ADDED
||
654 Variable
->State
== (VAR_IN_DELETED_TRANSITION
& VAR_ADDED
)
656 VariableSize
= (UINTN
) NextVariable
- (UINTN
) Variable
;
657 MaximumBufferSize
+= VariableSize
;
660 Variable
= NextVariable
;
664 // Reserve the 1 Bytes with Oxff to identify the
665 // end of the variable buffer.
667 MaximumBufferSize
+= 1;
668 ValidBuffer
= AllocatePool (MaximumBufferSize
);
669 if (ValidBuffer
== NULL
) {
670 return EFI_OUT_OF_RESOURCES
;
673 SetMem (ValidBuffer
, MaximumBufferSize
, 0xff);
676 // Copy variable store header
678 CopyMem (ValidBuffer
, VariableStoreHeader
, sizeof (VARIABLE_STORE_HEADER
));
679 CurrPtr
= (UINT8
*) GetStartPointer ((VARIABLE_STORE_HEADER
*) ValidBuffer
);
682 // Reinstall all ADDED variables as long as they are not identical to Updating Variable
684 Variable
= GetStartPointer (VariableStoreHeader
);
685 while (IsValidVariableHeader (Variable
)) {
686 NextVariable
= GetNextVariablePtr (Variable
);
687 if (Variable
->State
== VAR_ADDED
) {
688 if (UpdatingVariable
!= NULL
) {
689 if (UpdatingVariable
== Variable
) {
690 Variable
= NextVariable
;
694 VariableNameSize
= NameSizeOfVariable(Variable
);
695 UpdatingVariableNameSize
= NameSizeOfVariable(UpdatingVariable
);
697 VariableNamePtr
= GetVariableNamePtr (Variable
);
698 UpdatingVariableNamePtr
= GetVariableNamePtr (UpdatingVariable
);
699 if (CompareGuid (&Variable
->VendorGuid
, &UpdatingVariable
->VendorGuid
) &&
700 VariableNameSize
== UpdatingVariableNameSize
&&
701 CompareMem (VariableNamePtr
, UpdatingVariableNamePtr
, VariableNameSize
) == 0 ) {
702 Variable
= NextVariable
;
706 VariableSize
= (UINTN
) NextVariable
- (UINTN
) Variable
;
707 CopyMem (CurrPtr
, (UINT8
*) Variable
, VariableSize
);
708 CurrPtr
+= VariableSize
;
709 if ((!IsVolatile
) && ((Variable
->Attributes
& EFI_VARIABLE_HARDWARE_ERROR_RECORD
) == EFI_VARIABLE_HARDWARE_ERROR_RECORD
)) {
710 mVariableModuleGlobal
->HwErrVariableTotalSize
+= VariableSize
;
711 } else if ((!IsVolatile
) && ((Variable
->Attributes
& EFI_VARIABLE_HARDWARE_ERROR_RECORD
) != EFI_VARIABLE_HARDWARE_ERROR_RECORD
)) {
712 mVariableModuleGlobal
->CommonVariableTotalSize
+= VariableSize
;
715 Variable
= NextVariable
;
719 // Reinstall the variable being updated if it is not NULL
721 if (UpdatingVariable
!= NULL
) {
722 VariableSize
= (UINTN
)(GetNextVariablePtr (UpdatingVariable
)) - (UINTN
)UpdatingVariable
;
723 CopyMem (CurrPtr
, (UINT8
*) UpdatingVariable
, VariableSize
);
724 CurrPtr
+= VariableSize
;
725 if ((!IsVolatile
) && ((UpdatingVariable
->Attributes
& EFI_VARIABLE_HARDWARE_ERROR_RECORD
) == EFI_VARIABLE_HARDWARE_ERROR_RECORD
)) {
726 mVariableModuleGlobal
->HwErrVariableTotalSize
+= VariableSize
;
727 } else if ((!IsVolatile
) && ((UpdatingVariable
->Attributes
& EFI_VARIABLE_HARDWARE_ERROR_RECORD
) != EFI_VARIABLE_HARDWARE_ERROR_RECORD
)) {
728 mVariableModuleGlobal
->CommonVariableTotalSize
+= VariableSize
;
733 // Reinstall all in delete transition variables
735 Variable
= GetStartPointer (VariableStoreHeader
);
736 while (IsValidVariableHeader (Variable
)) {
737 NextVariable
= GetNextVariablePtr (Variable
);
738 if (Variable
!= UpdatingVariable
&& Variable
->State
== (VAR_IN_DELETED_TRANSITION
& VAR_ADDED
)) {
741 // Buffer has cached all ADDED variable.
742 // Per IN_DELETED variable, we have to guarantee that
743 // no ADDED one in previous buffer.
747 AddedVariable
= GetStartPointer ((VARIABLE_STORE_HEADER
*) ValidBuffer
);
748 while (IsValidVariableHeader (AddedVariable
)) {
749 NextAddedVariable
= GetNextVariablePtr (AddedVariable
);
750 NameSize
= NameSizeOfVariable (AddedVariable
);
751 if (CompareGuid (&AddedVariable
->VendorGuid
, &Variable
->VendorGuid
) &&
752 NameSize
== NameSizeOfVariable (Variable
)
754 Point0
= (VOID
*) GetVariableNamePtr (AddedVariable
);
755 Point1
= (VOID
*) GetVariableNamePtr (Variable
);
756 if (CompareMem (Point0
, Point1
, NameSizeOfVariable (AddedVariable
)) == 0) {
761 AddedVariable
= NextAddedVariable
;
765 // Promote VAR_IN_DELETED_TRANSITION to VAR_ADDED
767 VariableSize
= (UINTN
) NextVariable
- (UINTN
) Variable
;
768 CopyMem (CurrPtr
, (UINT8
*) Variable
, VariableSize
);
769 ((VARIABLE_HEADER
*) CurrPtr
)->State
= VAR_ADDED
;
770 CurrPtr
+= VariableSize
;
771 if ((!IsVolatile
) && ((Variable
->Attributes
& EFI_VARIABLE_HARDWARE_ERROR_RECORD
) == EFI_VARIABLE_HARDWARE_ERROR_RECORD
)) {
772 mVariableModuleGlobal
->HwErrVariableTotalSize
+= VariableSize
;
773 } else if ((!IsVolatile
) && ((Variable
->Attributes
& EFI_VARIABLE_HARDWARE_ERROR_RECORD
) != EFI_VARIABLE_HARDWARE_ERROR_RECORD
)) {
774 mVariableModuleGlobal
->CommonVariableTotalSize
+= VariableSize
;
779 Variable
= NextVariable
;
784 // If volatile variable store, just copy valid buffer
786 SetMem ((UINT8
*) (UINTN
) VariableBase
, VariableStoreHeader
->Size
, 0xff);
787 CopyMem ((UINT8
*) (UINTN
) VariableBase
, ValidBuffer
, (UINTN
) (CurrPtr
- (UINT8
*) ValidBuffer
));
788 Status
= EFI_SUCCESS
;
791 // If non-volatile variable store, perform FTW here.
793 Status
= FtwVariableSpace (
796 (UINTN
) (CurrPtr
- (UINT8
*) ValidBuffer
)
799 if (!EFI_ERROR (Status
)) {
800 *LastVariableOffset
= (UINTN
) (CurrPtr
- (UINT8
*) ValidBuffer
);
802 *LastVariableOffset
= 0;
805 FreePool (ValidBuffer
);
812 Update the Cache with Variable information. These are the same
813 arguments as the EFI Variable services.
815 @param[in] VariableName Name of variable
816 @param[in] VendorGuid Guid of variable
817 @param[in] Attributes Attribues of the variable
818 @param[in] DataSize Size of data. 0 means delete
819 @param[in] Data Variable data
823 UpdateVariableCache (
824 IN CHAR16
*VariableName
,
825 IN EFI_GUID
*VendorGuid
,
826 IN UINT32 Attributes
,
831 VARIABLE_CACHE_ENTRY
*Entry
;
834 if (EfiAtRuntime ()) {
836 // Don't use the cache at runtime
841 for (Index
= 0, Entry
= mVariableCache
; Index
< sizeof (mVariableCache
)/sizeof (VARIABLE_CACHE_ENTRY
); Index
++, Entry
++) {
842 if (CompareGuid (VendorGuid
, Entry
->Guid
)) {
843 if (StrCmp (VariableName
, Entry
->Name
) == 0) {
844 Entry
->Attributes
= Attributes
;
849 if (Entry
->DataSize
!= 0) {
850 FreePool (Entry
->Data
);
852 Entry
->DataSize
= DataSize
;
853 } else if (DataSize
== Entry
->DataSize
) {
854 CopyMem (Entry
->Data
, Data
, DataSize
);
856 Entry
->Data
= AllocatePool (DataSize
);
857 ASSERT (Entry
->Data
!= NULL
);
859 Entry
->DataSize
= DataSize
;
860 CopyMem (Entry
->Data
, Data
, DataSize
);
869 Search the cache to check if the variable is in it.
871 This function searches the variable cache. If the variable to find exists, return its data
874 @param VariableName A Null-terminated Unicode string that is the name of the vendor's
875 variable. Each VariableName is unique for each
877 @param VendorGuid A unique identifier for the vendor
878 @param Attributes Pointer to the attributes bitmask of the variable for output.
879 @param DataSize On input, size of the buffer of Data.
880 On output, size of the variable's data.
881 @param Data Pointer to the data buffer for output.
883 @retval EFI_SUCCESS VariableGuid & VariableName data was returned.
884 @retval EFI_NOT_FOUND No matching variable found in cache.
885 @retval EFI_BUFFER_TOO_SMALL *DataSize is smaller than size of the variable's data to return.
889 FindVariableInCache (
890 IN CHAR16
*VariableName
,
891 IN EFI_GUID
*VendorGuid
,
892 OUT UINT32
*Attributes OPTIONAL
,
893 IN OUT UINTN
*DataSize
,
897 VARIABLE_CACHE_ENTRY
*Entry
;
900 if (EfiAtRuntime ()) {
901 // Don't use the cache at runtime
902 return EFI_NOT_FOUND
;
905 for (Index
= 0, Entry
= mVariableCache
; Index
< sizeof (mVariableCache
)/sizeof (VARIABLE_CACHE_ENTRY
); Index
++, Entry
++) {
906 if (CompareGuid (VendorGuid
, Entry
->Guid
)) {
907 if (StrCmp (VariableName
, Entry
->Name
) == 0) {
908 if (Entry
->DataSize
== 0) {
909 // Variable was deleted so return not found
910 return EFI_NOT_FOUND
;
911 } else if (Entry
->DataSize
> *DataSize
) {
912 // If the buffer is too small return correct size
913 *DataSize
= Entry
->DataSize
;
914 return EFI_BUFFER_TOO_SMALL
;
916 *DataSize
= Entry
->DataSize
;
918 CopyMem (Data
, Entry
->Data
, Entry
->DataSize
);
919 if (Attributes
!= NULL
) {
920 *Attributes
= Entry
->Attributes
;
928 return EFI_NOT_FOUND
;
932 Finds variable in storage blocks of volatile and non-volatile storage areas.
934 This code finds variable in storage blocks of volatile and non-volatile storage areas.
935 If VariableName is an empty string, then we just return the first
936 qualified variable without comparing VariableName and VendorGuid.
937 Otherwise, VariableName and VendorGuid are compared.
939 @param VariableName Name of the variable to be found
940 @param VendorGuid Vendor GUID to be found.
941 @param PtrTrack VARIABLE_POINTER_TRACK structure for output,
942 including the range searched and the target position.
943 @param Global Pointer to VARIABLE_GLOBAL structure, including
944 base of volatile variable storage area, base of
945 NV variable storage area, and a lock.
947 @retval EFI_INVALID_PARAMETER If VariableName is not an empty string, while
949 @retval EFI_SUCCESS Variable successfully found
950 @retval EFI_NOT_FOUND Variable not found
955 IN CHAR16
*VariableName
,
956 IN EFI_GUID
*VendorGuid
,
957 OUT VARIABLE_POINTER_TRACK
*PtrTrack
,
958 IN VARIABLE_GLOBAL
*Global
961 VARIABLE_HEADER
*Variable
[2];
962 VARIABLE_HEADER
*InDeletedVariable
;
963 VARIABLE_STORE_HEADER
*VariableStoreHeader
[2];
964 UINTN InDeletedStorageIndex
;
969 // 0: Volatile, 1: Non-Volatile
970 // The index and attributes mapping must be kept in this order as RuntimeServiceGetNextVariableName
971 // make use of this mapping to implement search algorithme.
973 VariableStoreHeader
[0] = (VARIABLE_STORE_HEADER
*) ((UINTN
) mVariableModuleGlobal
->VariableGlobal
.VolatileVariableBase
);
974 VariableStoreHeader
[1] = (VARIABLE_STORE_HEADER
*) ((UINTN
) mVariableModuleGlobal
->VariableGlobal
.NonVolatileVariableBase
);
977 // Start Pointers for the variable.
978 // Actual Data Pointer where data can be written.
980 Variable
[0] = GetStartPointer (VariableStoreHeader
[0]);
981 Variable
[1] = GetStartPointer (VariableStoreHeader
[1]);
983 if (VariableName
[0] != 0 && VendorGuid
== NULL
) {
984 return EFI_INVALID_PARAMETER
;
988 // Find the variable by walk through volatile and then non-volatile variable store
990 InDeletedVariable
= NULL
;
991 InDeletedStorageIndex
= 0;
992 for (Index
= 0; Index
< 2; Index
++) {
993 while ((Variable
[Index
] < GetEndPointer (VariableStoreHeader
[Index
])) && IsValidVariableHeader (Variable
[Index
])) {
994 if (Variable
[Index
]->State
== VAR_ADDED
||
995 Variable
[Index
]->State
== (VAR_IN_DELETED_TRANSITION
& VAR_ADDED
)
997 if (!EfiAtRuntime () || ((Variable
[Index
]->Attributes
& EFI_VARIABLE_RUNTIME_ACCESS
) != 0)) {
998 if (VariableName
[0] == 0) {
999 if (Variable
[Index
]->State
== (VAR_IN_DELETED_TRANSITION
& VAR_ADDED
)) {
1000 InDeletedVariable
= Variable
[Index
];
1001 InDeletedStorageIndex
= Index
;
1003 PtrTrack
->StartPtr
= GetStartPointer (VariableStoreHeader
[Index
]);
1004 PtrTrack
->EndPtr
= GetEndPointer (VariableStoreHeader
[Index
]);
1005 PtrTrack
->CurrPtr
= Variable
[Index
];
1006 PtrTrack
->Volatile
= (BOOLEAN
)(Index
== 0);
1011 if (CompareGuid (VendorGuid
, &Variable
[Index
]->VendorGuid
)) {
1012 Point
= (VOID
*) GetVariableNamePtr (Variable
[Index
]);
1014 ASSERT (NameSizeOfVariable (Variable
[Index
]) != 0);
1015 if (CompareMem (VariableName
, Point
, NameSizeOfVariable (Variable
[Index
])) == 0) {
1016 if (Variable
[Index
]->State
== (VAR_IN_DELETED_TRANSITION
& VAR_ADDED
)) {
1017 InDeletedVariable
= Variable
[Index
];
1018 InDeletedStorageIndex
= Index
;
1020 PtrTrack
->StartPtr
= GetStartPointer (VariableStoreHeader
[Index
]);
1021 PtrTrack
->EndPtr
= GetEndPointer (VariableStoreHeader
[Index
]);
1022 PtrTrack
->CurrPtr
= Variable
[Index
];
1023 PtrTrack
->Volatile
= (BOOLEAN
)(Index
== 0);
1033 Variable
[Index
] = GetNextVariablePtr (Variable
[Index
]);
1035 if (InDeletedVariable
!= NULL
) {
1036 PtrTrack
->StartPtr
= GetStartPointer (VariableStoreHeader
[InDeletedStorageIndex
]);
1037 PtrTrack
->EndPtr
= GetEndPointer (VariableStoreHeader
[InDeletedStorageIndex
]);
1038 PtrTrack
->CurrPtr
= InDeletedVariable
;
1039 PtrTrack
->Volatile
= (BOOLEAN
)(InDeletedStorageIndex
== 0);
1043 PtrTrack
->CurrPtr
= NULL
;
1044 return EFI_NOT_FOUND
;
1048 Get index from supported language codes according to language string.
1050 This code is used to get corresponding index in supported language codes. It can handle
1051 RFC4646 and ISO639 language tags.
1052 In ISO639 language tags, take 3-characters as a delimitation to find matched string and calculate the index.
1053 In RFC4646 language tags, take semicolon as a delimitation to find matched string and calculate the index.
1056 SupportedLang = "engfraengfra"
1058 Iso639Language = TRUE
1059 The return value is "0".
1061 SupportedLang = "en;fr;en-US;fr-FR"
1063 Iso639Language = FALSE
1064 The return value is "3".
1066 @param SupportedLang Platform supported language codes.
1067 @param Lang Configured language.
1068 @param Iso639Language A bool value to signify if the handler is operated on ISO639 or RFC4646.
1070 @retval the index of language in the language codes.
1074 GetIndexFromSupportedLangCodes(
1075 IN CHAR8
*SupportedLang
,
1077 IN BOOLEAN Iso639Language
1081 UINTN CompareLength
;
1082 UINTN LanguageLength
;
1084 if (Iso639Language
) {
1085 CompareLength
= ISO_639_2_ENTRY_SIZE
;
1086 for (Index
= 0; Index
< AsciiStrLen (SupportedLang
); Index
+= CompareLength
) {
1087 if (AsciiStrnCmp (Lang
, SupportedLang
+ Index
, CompareLength
) == 0) {
1089 // Successfully find the index of Lang string in SupportedLang string.
1091 Index
= Index
/ CompareLength
;
1099 // Compare RFC4646 language code
1102 for (LanguageLength
= 0; Lang
[LanguageLength
] != '\0'; LanguageLength
++);
1104 for (Index
= 0; *SupportedLang
!= '\0'; Index
++, SupportedLang
+= CompareLength
) {
1106 // Skip ';' characters in SupportedLang
1108 for (; *SupportedLang
!= '\0' && *SupportedLang
== ';'; SupportedLang
++);
1110 // Determine the length of the next language code in SupportedLang
1112 for (CompareLength
= 0; SupportedLang
[CompareLength
] != '\0' && SupportedLang
[CompareLength
] != ';'; CompareLength
++);
1114 if ((CompareLength
== LanguageLength
) &&
1115 (AsciiStrnCmp (Lang
, SupportedLang
, CompareLength
) == 0)) {
1117 // Successfully find the index of Lang string in SupportedLang string.
1128 Get language string from supported language codes according to index.
1130 This code is used to get corresponding language string in supported language codes. It can handle
1131 RFC4646 and ISO639 language tags.
1132 In ISO639 language tags, take 3-characters as a delimitation. Find language string according to the index.
1133 In RFC4646 language tags, take semicolon as a delimitation. Find language string according to the index.
1136 SupportedLang = "engfraengfra"
1138 Iso639Language = TRUE
1139 The return value is "fra".
1141 SupportedLang = "en;fr;en-US;fr-FR"
1143 Iso639Language = FALSE
1144 The return value is "fr".
1146 @param SupportedLang Platform supported language codes.
1147 @param Index the index in supported language codes.
1148 @param Iso639Language A bool value to signify if the handler is operated on ISO639 or RFC4646.
1150 @retval the language string in the language codes.
1154 GetLangFromSupportedLangCodes (
1155 IN CHAR8
*SupportedLang
,
1157 IN BOOLEAN Iso639Language
1161 UINTN CompareLength
;
1165 Supported
= SupportedLang
;
1166 if (Iso639Language
) {
1168 // according to the index of Lang string in SupportedLang string to get the language.
1169 // As this code will be invoked in RUNTIME, therefore there is not memory allocate/free operation.
1170 // In driver entry, it pre-allocates a runtime attribute memory to accommodate this string.
1172 CompareLength
= ISO_639_2_ENTRY_SIZE
;
1173 mVariableModuleGlobal
->Lang
[CompareLength
] = '\0';
1174 return CopyMem (mVariableModuleGlobal
->Lang
, SupportedLang
+ Index
* CompareLength
, CompareLength
);
1179 // take semicolon as delimitation, sequentially traverse supported language codes.
1181 for (CompareLength
= 0; *Supported
!= ';' && *Supported
!= '\0'; CompareLength
++) {
1184 if ((*Supported
== '\0') && (SubIndex
!= Index
)) {
1186 // Have completed the traverse, but not find corrsponding string.
1187 // This case is not allowed to happen.
1192 if (SubIndex
== Index
) {
1194 // according to the index of Lang string in SupportedLang string to get the language.
1195 // As this code will be invoked in RUNTIME, therefore there is not memory allocate/free operation.
1196 // In driver entry, it pre-allocates a runtime attribute memory to accommodate this string.
1198 mVariableModuleGlobal
->PlatformLang
[CompareLength
] = '\0';
1199 return CopyMem (mVariableModuleGlobal
->PlatformLang
, Supported
- CompareLength
, CompareLength
);
1204 // Skip ';' characters in Supported
1206 for (; *Supported
!= '\0' && *Supported
== ';'; Supported
++);
1212 Returns a pointer to an allocated buffer that contains the best matching language
1213 from a set of supported languages.
1215 This function supports both ISO 639-2 and RFC 4646 language codes, but language
1216 code types may not be mixed in a single call to this function. This function
1217 supports a variable argument list that allows the caller to pass in a prioritized
1218 list of language codes to test against all the language codes in SupportedLanguages.
1220 If SupportedLanguages is NULL, then ASSERT().
1222 @param[in] SupportedLanguages A pointer to a Null-terminated ASCII string that
1223 contains a set of language codes in the format
1224 specified by Iso639Language.
1225 @param[in] Iso639Language If TRUE, then all language codes are assumed to be
1226 in ISO 639-2 format. If FALSE, then all language
1227 codes are assumed to be in RFC 4646 language format
1228 @param[in] ... A variable argument list that contains pointers to
1229 Null-terminated ASCII strings that contain one or more
1230 language codes in the format specified by Iso639Language.
1231 The first language code from each of these language
1232 code lists is used to determine if it is an exact or
1233 close match to any of the language codes in
1234 SupportedLanguages. Close matches only apply to RFC 4646
1235 language codes, and the matching algorithm from RFC 4647
1236 is used to determine if a close match is present. If
1237 an exact or close match is found, then the matching
1238 language code from SupportedLanguages is returned. If
1239 no matches are found, then the next variable argument
1240 parameter is evaluated. The variable argument list
1241 is terminated by a NULL.
1243 @retval NULL The best matching language could not be found in SupportedLanguages.
1244 @retval NULL There are not enough resources available to return the best matching
1246 @retval Other A pointer to a Null-terminated ASCII string that is the best matching
1247 language in SupportedLanguages.
1251 VariableGetBestLanguage (
1252 IN CONST CHAR8
*SupportedLanguages
,
1253 IN BOOLEAN Iso639Language
,
1259 UINTN CompareLength
;
1260 UINTN LanguageLength
;
1261 CONST CHAR8
*Supported
;
1264 ASSERT (SupportedLanguages
!= NULL
);
1266 VA_START (Args
, Iso639Language
);
1267 while ((Language
= VA_ARG (Args
, CHAR8
*)) != NULL
) {
1269 // Default to ISO 639-2 mode
1272 LanguageLength
= MIN (3, AsciiStrLen (Language
));
1275 // If in RFC 4646 mode, then determine the length of the first RFC 4646 language code in Language
1277 if (!Iso639Language
) {
1278 for (LanguageLength
= 0; Language
[LanguageLength
] != 0 && Language
[LanguageLength
] != ';'; LanguageLength
++);
1282 // Trim back the length of Language used until it is empty
1284 while (LanguageLength
> 0) {
1286 // Loop through all language codes in SupportedLanguages
1288 for (Supported
= SupportedLanguages
; *Supported
!= '\0'; Supported
+= CompareLength
) {
1290 // In RFC 4646 mode, then Loop through all language codes in SupportedLanguages
1292 if (!Iso639Language
) {
1294 // Skip ';' characters in Supported
1296 for (; *Supported
!= '\0' && *Supported
== ';'; Supported
++);
1298 // Determine the length of the next language code in Supported
1300 for (CompareLength
= 0; Supported
[CompareLength
] != 0 && Supported
[CompareLength
] != ';'; CompareLength
++);
1302 // If Language is longer than the Supported, then skip to the next language
1304 if (LanguageLength
> CompareLength
) {
1309 // See if the first LanguageLength characters in Supported match Language
1311 if (AsciiStrnCmp (Supported
, Language
, LanguageLength
) == 0) {
1314 Buffer
= Iso639Language
? mVariableModuleGlobal
->Lang
: mVariableModuleGlobal
->PlatformLang
;
1315 Buffer
[CompareLength
] = '\0';
1316 return CopyMem (Buffer
, Supported
, CompareLength
);
1320 if (Iso639Language
) {
1322 // If ISO 639 mode, then each language can only be tested once
1327 // If RFC 4646 mode, then trim Language from the right to the next '-' character
1329 for (LanguageLength
--; LanguageLength
> 0 && Language
[LanguageLength
] != '-'; LanguageLength
--);
1336 // No matches were found
1342 Hook the operations in PlatformLangCodes, LangCodes, PlatformLang and Lang.
1344 When setting Lang/LangCodes, simultaneously update PlatformLang/PlatformLangCodes.
1346 According to UEFI spec, PlatformLangCodes/LangCodes are only set once in firmware initialization,
1347 and are read-only. Therefore, in variable driver, only store the original value for other use.
1349 @param[in] VariableName Name of variable
1351 @param[in] Data Variable data
1353 @param[in] DataSize Size of data. 0 means delete
1357 AutoUpdateLangVariable(
1358 IN CHAR16
*VariableName
,
1364 CHAR8
*BestPlatformLang
;
1368 VARIABLE_POINTER_TRACK Variable
;
1369 BOOLEAN SetLanguageCodes
;
1372 // Don't do updates for delete operation
1374 if (DataSize
== 0) {
1378 SetLanguageCodes
= FALSE
;
1380 if (StrCmp (VariableName
, L
"PlatformLangCodes") == 0) {
1382 // PlatformLangCodes is a volatile variable, so it can not be updated at runtime.
1384 if (EfiAtRuntime ()) {
1388 SetLanguageCodes
= TRUE
;
1391 // According to UEFI spec, PlatformLangCodes is only set once in firmware initialization, and is read-only
1392 // Therefore, in variable driver, only store the original value for other use.
1394 if (mVariableModuleGlobal
->PlatformLangCodes
!= NULL
) {
1395 FreePool (mVariableModuleGlobal
->PlatformLangCodes
);
1397 mVariableModuleGlobal
->PlatformLangCodes
= AllocateRuntimeCopyPool (DataSize
, Data
);
1398 ASSERT (mVariableModuleGlobal
->PlatformLangCodes
!= NULL
);
1401 // PlatformLang holds a single language from PlatformLangCodes,
1402 // so the size of PlatformLangCodes is enough for the PlatformLang.
1404 if (mVariableModuleGlobal
->PlatformLang
!= NULL
) {
1405 FreePool (mVariableModuleGlobal
->PlatformLang
);
1407 mVariableModuleGlobal
->PlatformLang
= AllocateRuntimePool (DataSize
);
1408 ASSERT (mVariableModuleGlobal
->PlatformLang
!= NULL
);
1410 } else if (StrCmp (VariableName
, L
"LangCodes") == 0) {
1412 // LangCodes is a volatile variable, so it can not be updated at runtime.
1414 if (EfiAtRuntime ()) {
1418 SetLanguageCodes
= TRUE
;
1421 // According to UEFI spec, LangCodes is only set once in firmware initialization, and is read-only
1422 // Therefore, in variable driver, only store the original value for other use.
1424 if (mVariableModuleGlobal
->LangCodes
!= NULL
) {
1425 FreePool (mVariableModuleGlobal
->LangCodes
);
1427 mVariableModuleGlobal
->LangCodes
= AllocateRuntimeCopyPool (DataSize
, Data
);
1428 ASSERT (mVariableModuleGlobal
->LangCodes
!= NULL
);
1431 if (SetLanguageCodes
1432 && (mVariableModuleGlobal
->PlatformLangCodes
!= NULL
)
1433 && (mVariableModuleGlobal
->LangCodes
!= NULL
)) {
1435 // Update Lang if PlatformLang is already set
1436 // Update PlatformLang if Lang is already set
1438 Status
= FindVariable (L
"PlatformLang", &gEfiGlobalVariableGuid
, &Variable
, (VARIABLE_GLOBAL
*) mVariableModuleGlobal
);
1439 if (!EFI_ERROR (Status
)) {
1443 VariableName
= L
"PlatformLang";
1444 Data
= GetVariableDataPtr (Variable
.CurrPtr
);
1445 DataSize
= Variable
.CurrPtr
->DataSize
;
1447 Status
= FindVariable (L
"Lang", &gEfiGlobalVariableGuid
, &Variable
, (VARIABLE_GLOBAL
*) mVariableModuleGlobal
);
1448 if (!EFI_ERROR (Status
)) {
1450 // Update PlatformLang
1452 VariableName
= L
"Lang";
1453 Data
= GetVariableDataPtr (Variable
.CurrPtr
);
1454 DataSize
= Variable
.CurrPtr
->DataSize
;
1457 // Neither PlatformLang nor Lang is set, directly return
1465 // According to UEFI spec, "Lang" and "PlatformLang" is NV|BS|RT attributions.
1467 Attributes
= EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
;
1469 if (StrCmp (VariableName
, L
"PlatformLang") == 0) {
1471 // Update Lang when PlatformLangCodes/LangCodes were set.
1473 if ((mVariableModuleGlobal
->PlatformLangCodes
!= NULL
) && (mVariableModuleGlobal
->LangCodes
!= NULL
)) {
1475 // When setting PlatformLang, firstly get most matched language string from supported language codes.
1477 BestPlatformLang
= VariableGetBestLanguage (mVariableModuleGlobal
->PlatformLangCodes
, FALSE
, Data
, NULL
);
1478 if (BestPlatformLang
!= NULL
) {
1480 // Get the corresponding index in language codes.
1482 Index
= GetIndexFromSupportedLangCodes (mVariableModuleGlobal
->PlatformLangCodes
, BestPlatformLang
, FALSE
);
1485 // Get the corresponding ISO639 language tag according to RFC4646 language tag.
1487 BestLang
= GetLangFromSupportedLangCodes (mVariableModuleGlobal
->LangCodes
, Index
, TRUE
);
1490 // Successfully convert PlatformLang to Lang, and set the BestLang value into Lang variable simultaneously.
1492 FindVariable (L
"Lang", &gEfiGlobalVariableGuid
, &Variable
, (VARIABLE_GLOBAL
*)mVariableModuleGlobal
);
1494 Status
= UpdateVariable (L
"Lang", &gEfiGlobalVariableGuid
, BestLang
, ISO_639_2_ENTRY_SIZE
+ 1, Attributes
, &Variable
);
1496 DEBUG ((EFI_D_INFO
, "Variable Driver Auto Update PlatformLang, PlatformLang:%a, Lang:%a\n", BestPlatformLang
, BestLang
));
1498 ASSERT_EFI_ERROR(Status
);
1502 } else if (StrCmp (VariableName
, L
"Lang") == 0) {
1504 // Update PlatformLang when PlatformLangCodes/LangCodes were set.
1506 if ((mVariableModuleGlobal
->PlatformLangCodes
!= NULL
) && (mVariableModuleGlobal
->LangCodes
!= NULL
)) {
1508 // When setting Lang, firstly get most matched language string from supported language codes.
1510 BestLang
= VariableGetBestLanguage (mVariableModuleGlobal
->LangCodes
, TRUE
, Data
, NULL
);
1511 if (BestLang
!= NULL
) {
1513 // Get the corresponding index in language codes.
1515 Index
= GetIndexFromSupportedLangCodes (mVariableModuleGlobal
->LangCodes
, BestLang
, TRUE
);
1518 // Get the corresponding RFC4646 language tag according to ISO639 language tag.
1520 BestPlatformLang
= GetLangFromSupportedLangCodes (mVariableModuleGlobal
->PlatformLangCodes
, Index
, FALSE
);
1523 // Successfully convert Lang to PlatformLang, and set the BestPlatformLang value into PlatformLang variable simultaneously.
1525 FindVariable (L
"PlatformLang", &gEfiGlobalVariableGuid
, &Variable
, (VARIABLE_GLOBAL
*)mVariableModuleGlobal
);
1527 Status
= UpdateVariable (L
"PlatformLang", &gEfiGlobalVariableGuid
, BestPlatformLang
,
1528 AsciiStrSize (BestPlatformLang
), Attributes
, &Variable
);
1530 DEBUG ((EFI_D_INFO
, "Variable Driver Auto Update Lang, Lang:%a, PlatformLang:%a\n", BestLang
, BestPlatformLang
));
1531 ASSERT_EFI_ERROR (Status
);
1538 Update the variable region with Variable information. These are the same
1539 arguments as the EFI Variable services.
1541 @param[in] VariableName Name of variable
1543 @param[in] VendorGuid Guid of variable
1545 @param[in] Data Variable data
1547 @param[in] DataSize Size of data. 0 means delete
1549 @param[in] Attributes Attribues of the variable
1551 @param[in] Variable The variable information which is used to keep track of variable usage.
1553 @retval EFI_SUCCESS The update operation is success.
1555 @retval EFI_OUT_OF_RESOURCES Variable region is full, can not write other data into this region.
1561 IN CHAR16
*VariableName
,
1562 IN EFI_GUID
*VendorGuid
,
1565 IN UINT32 Attributes OPTIONAL
,
1566 IN VARIABLE_POINTER_TRACK
*Variable
1570 VARIABLE_HEADER
*NextVariable
;
1572 UINTN NonVolatileVarableStoreSize
;
1573 UINTN VarNameOffset
;
1574 UINTN VarDataOffset
;
1578 EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL
*Fvb
;
1582 Fvb
= mVariableModuleGlobal
->FvbInstance
;
1585 if (Variable
->CurrPtr
!= NULL
) {
1587 // Update/Delete existing variable
1589 Volatile
= Variable
->Volatile
;
1591 if (EfiAtRuntime ()) {
1593 // If EfiAtRuntime and the variable is Volatile and Runtime Access,
1594 // the volatile is ReadOnly, and SetVariable should be aborted and
1595 // return EFI_WRITE_PROTECTED.
1597 if (Variable
->Volatile
) {
1598 Status
= EFI_WRITE_PROTECTED
;
1602 // Only variable have NV attribute can be updated/deleted in Runtime
1604 if ((Variable
->CurrPtr
->Attributes
& EFI_VARIABLE_NON_VOLATILE
) == 0) {
1605 Status
= EFI_INVALID_PARAMETER
;
1610 // Setting a data variable with no access, or zero DataSize attributes
1611 // specified causes it to be deleted.
1613 if (DataSize
== 0 || (Attributes
& (EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_BOOTSERVICE_ACCESS
)) == 0) {
1614 State
= Variable
->CurrPtr
->State
;
1615 State
&= VAR_DELETED
;
1617 Status
= UpdateVariableStore (
1618 &mVariableModuleGlobal
->VariableGlobal
,
1622 (UINTN
) &Variable
->CurrPtr
->State
,
1626 if (!EFI_ERROR (Status
)) {
1627 UpdateVariableInfo (VariableName
, VendorGuid
, Volatile
, FALSE
, FALSE
, TRUE
, FALSE
);
1628 UpdateVariableCache (VariableName
, VendorGuid
, Attributes
, DataSize
, Data
);
1633 // If the variable is marked valid and the same data has been passed in
1634 // then return to the caller immediately.
1636 if (DataSizeOfVariable (Variable
->CurrPtr
) == DataSize
&&
1637 (CompareMem (Data
, GetVariableDataPtr (Variable
->CurrPtr
), DataSize
) == 0)) {
1639 UpdateVariableInfo (VariableName
, VendorGuid
, Volatile
, FALSE
, TRUE
, FALSE
, FALSE
);
1640 Status
= EFI_SUCCESS
;
1642 } else if ((Variable
->CurrPtr
->State
== VAR_ADDED
) ||
1643 (Variable
->CurrPtr
->State
== (VAR_ADDED
& VAR_IN_DELETED_TRANSITION
))) {
1646 // Mark the old variable as in delete transition
1648 State
= Variable
->CurrPtr
->State
;
1649 State
&= VAR_IN_DELETED_TRANSITION
;
1651 Status
= UpdateVariableStore (
1652 &mVariableModuleGlobal
->VariableGlobal
,
1656 (UINTN
) &Variable
->CurrPtr
->State
,
1660 if (EFI_ERROR (Status
)) {
1666 // Not found existing variable. Create a new variable
1670 // Make sure we are trying to create a new variable.
1671 // Setting a data variable with no access, or zero DataSize attributes means to delete it.
1673 if (DataSize
== 0 || (Attributes
& (EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_BOOTSERVICE_ACCESS
)) == 0) {
1674 Status
= EFI_NOT_FOUND
;
1679 // Only variable have NV|RT attribute can be created in Runtime
1681 if (EfiAtRuntime () &&
1682 (((Attributes
& EFI_VARIABLE_RUNTIME_ACCESS
) == 0) || ((Attributes
& EFI_VARIABLE_NON_VOLATILE
) == 0))) {
1683 Status
= EFI_INVALID_PARAMETER
;
1689 // Function part - create a new variable and copy the data.
1690 // Both update a variable and create a variable will come here.
1692 // Tricky part: Use scratch data area at the end of volatile variable store
1693 // as a temporary storage.
1695 NextVariable
= GetEndPointer ((VARIABLE_STORE_HEADER
*) ((UINTN
) mVariableModuleGlobal
->VariableGlobal
.VolatileVariableBase
));
1696 ScratchSize
= MAX (PcdGet32 (PcdMaxVariableSize
), PcdGet32 (PcdMaxHardwareErrorVariableSize
));
1698 SetMem (NextVariable
, ScratchSize
, 0xff);
1700 NextVariable
->StartId
= VARIABLE_DATA
;
1701 NextVariable
->Attributes
= Attributes
;
1703 // NextVariable->State = VAR_ADDED;
1705 NextVariable
->Reserved
= 0;
1706 VarNameOffset
= sizeof (VARIABLE_HEADER
);
1707 VarNameSize
= StrSize (VariableName
);
1709 (UINT8
*) ((UINTN
) NextVariable
+ VarNameOffset
),
1713 VarDataOffset
= VarNameOffset
+ VarNameSize
+ GET_PAD_SIZE (VarNameSize
);
1715 (UINT8
*) ((UINTN
) NextVariable
+ VarDataOffset
),
1719 CopyMem (&NextVariable
->VendorGuid
, VendorGuid
, sizeof (EFI_GUID
));
1721 // There will be pad bytes after Data, the NextVariable->NameSize and
1722 // NextVariable->DataSize should not include pad size so that variable
1723 // service can get actual size in GetVariable
1725 NextVariable
->NameSize
= (UINT32
)VarNameSize
;
1726 NextVariable
->DataSize
= (UINT32
)DataSize
;
1729 // The actual size of the variable that stores in storage should
1730 // include pad size.
1732 VarSize
= VarDataOffset
+ DataSize
+ GET_PAD_SIZE (DataSize
);
1733 if ((Attributes
& EFI_VARIABLE_NON_VOLATILE
) != 0) {
1735 // Create a nonvolatile variable
1738 NonVolatileVarableStoreSize
= ((VARIABLE_STORE_HEADER
*)(UINTN
)(mVariableModuleGlobal
->VariableGlobal
.NonVolatileVariableBase
))->Size
;
1739 if ((((Attributes
& EFI_VARIABLE_HARDWARE_ERROR_RECORD
) != 0)
1740 && ((VarSize
+ mVariableModuleGlobal
->HwErrVariableTotalSize
) > PcdGet32 (PcdHwErrStorageSize
)))
1741 || (((Attributes
& EFI_VARIABLE_HARDWARE_ERROR_RECORD
) == 0)
1742 && ((VarSize
+ mVariableModuleGlobal
->CommonVariableTotalSize
) > NonVolatileVarableStoreSize
- sizeof (VARIABLE_STORE_HEADER
) - PcdGet32 (PcdHwErrStorageSize
)))) {
1743 if (EfiAtRuntime ()) {
1744 Status
= EFI_OUT_OF_RESOURCES
;
1748 // Perform garbage collection & reclaim operation
1750 Status
= Reclaim (mVariableModuleGlobal
->VariableGlobal
.NonVolatileVariableBase
,
1751 &mVariableModuleGlobal
->NonVolatileLastVariableOffset
, FALSE
, Variable
->CurrPtr
);
1752 if (EFI_ERROR (Status
)) {
1756 // If still no enough space, return out of resources
1758 if ((((Attributes
& EFI_VARIABLE_HARDWARE_ERROR_RECORD
) != 0)
1759 && ((VarSize
+ mVariableModuleGlobal
->HwErrVariableTotalSize
) > PcdGet32 (PcdHwErrStorageSize
)))
1760 || (((Attributes
& EFI_VARIABLE_HARDWARE_ERROR_RECORD
) == 0)
1761 && ((VarSize
+ mVariableModuleGlobal
->CommonVariableTotalSize
) > NonVolatileVarableStoreSize
- sizeof (VARIABLE_STORE_HEADER
) - PcdGet32 (PcdHwErrStorageSize
)))) {
1762 Status
= EFI_OUT_OF_RESOURCES
;
1769 // 1. Write variable header
1770 // 2. Set variable state to header valid
1771 // 3. Write variable data
1772 // 4. Set variable state to valid
1777 Status
= UpdateVariableStore (
1778 &mVariableModuleGlobal
->VariableGlobal
,
1782 mVariableModuleGlobal
->NonVolatileLastVariableOffset
,
1783 sizeof (VARIABLE_HEADER
),
1784 (UINT8
*) NextVariable
1787 if (EFI_ERROR (Status
)) {
1794 NextVariable
->State
= VAR_HEADER_VALID_ONLY
;
1795 Status
= UpdateVariableStore (
1796 &mVariableModuleGlobal
->VariableGlobal
,
1800 mVariableModuleGlobal
->NonVolatileLastVariableOffset
,
1801 sizeof (VARIABLE_HEADER
),
1802 (UINT8
*) NextVariable
1805 if (EFI_ERROR (Status
)) {
1811 Status
= UpdateVariableStore (
1812 &mVariableModuleGlobal
->VariableGlobal
,
1816 mVariableModuleGlobal
->NonVolatileLastVariableOffset
+ sizeof (VARIABLE_HEADER
),
1817 (UINT32
) VarSize
- sizeof (VARIABLE_HEADER
),
1818 (UINT8
*) NextVariable
+ sizeof (VARIABLE_HEADER
)
1821 if (EFI_ERROR (Status
)) {
1827 NextVariable
->State
= VAR_ADDED
;
1828 Status
= UpdateVariableStore (
1829 &mVariableModuleGlobal
->VariableGlobal
,
1833 mVariableModuleGlobal
->NonVolatileLastVariableOffset
,
1834 sizeof (VARIABLE_HEADER
),
1835 (UINT8
*) NextVariable
1838 if (EFI_ERROR (Status
)) {
1842 mVariableModuleGlobal
->NonVolatileLastVariableOffset
+= HEADER_ALIGN (VarSize
);
1844 if ((Attributes
& EFI_VARIABLE_HARDWARE_ERROR_RECORD
) != 0) {
1845 mVariableModuleGlobal
->HwErrVariableTotalSize
+= HEADER_ALIGN (VarSize
);
1847 mVariableModuleGlobal
->CommonVariableTotalSize
+= HEADER_ALIGN (VarSize
);
1851 // Create a volatile variable
1855 if ((UINT32
) (VarSize
+ mVariableModuleGlobal
->VolatileLastVariableOffset
) >
1856 ((VARIABLE_STORE_HEADER
*) ((UINTN
) (mVariableModuleGlobal
->VariableGlobal
.VolatileVariableBase
)))->Size
) {
1858 // Perform garbage collection & reclaim operation
1860 Status
= Reclaim (mVariableModuleGlobal
->VariableGlobal
.VolatileVariableBase
,
1861 &mVariableModuleGlobal
->VolatileLastVariableOffset
, TRUE
, Variable
->CurrPtr
);
1862 if (EFI_ERROR (Status
)) {
1866 // If still no enough space, return out of resources
1868 if ((UINT32
) (VarSize
+ mVariableModuleGlobal
->VolatileLastVariableOffset
) >
1869 ((VARIABLE_STORE_HEADER
*) ((UINTN
) (mVariableModuleGlobal
->VariableGlobal
.VolatileVariableBase
)))->Size
1871 Status
= EFI_OUT_OF_RESOURCES
;
1877 NextVariable
->State
= VAR_ADDED
;
1878 Status
= UpdateVariableStore (
1879 &mVariableModuleGlobal
->VariableGlobal
,
1883 mVariableModuleGlobal
->VolatileLastVariableOffset
,
1885 (UINT8
*) NextVariable
1888 if (EFI_ERROR (Status
)) {
1892 mVariableModuleGlobal
->VolatileLastVariableOffset
+= HEADER_ALIGN (VarSize
);
1896 // Mark the old variable as deleted
1898 if (!Reclaimed
&& !EFI_ERROR (Status
) && Variable
->CurrPtr
!= NULL
) {
1899 State
= Variable
->CurrPtr
->State
;
1900 State
&= VAR_DELETED
;
1902 Status
= UpdateVariableStore (
1903 &mVariableModuleGlobal
->VariableGlobal
,
1907 (UINTN
) &Variable
->CurrPtr
->State
,
1913 if (!EFI_ERROR (Status
)) {
1914 UpdateVariableInfo (VariableName
, VendorGuid
, Volatile
, FALSE
, TRUE
, FALSE
, FALSE
);
1915 UpdateVariableCache (VariableName
, VendorGuid
, Attributes
, DataSize
, Data
);
1924 This code finds variable in storage blocks (Volatile or Non-Volatile).
1926 @param VariableName Name of Variable to be found.
1927 @param VendorGuid Variable vendor GUID.
1928 @param Attributes Attribute value of the variable found.
1929 @param DataSize Size of Data found. If size is less than the
1930 data, this value contains the required size.
1931 @param Data Data pointer.
1933 @return EFI_INVALID_PARAMETER Invalid parameter
1934 @return EFI_SUCCESS Find the specified variable
1935 @return EFI_NOT_FOUND Not found
1936 @return EFI_BUFFER_TO_SMALL DataSize is too small for the result
1941 RuntimeServiceGetVariable (
1942 IN CHAR16
*VariableName
,
1943 IN EFI_GUID
*VendorGuid
,
1944 OUT UINT32
*Attributes OPTIONAL
,
1945 IN OUT UINTN
*DataSize
,
1950 VARIABLE_POINTER_TRACK Variable
;
1953 if (VariableName
== NULL
|| VendorGuid
== NULL
|| DataSize
== NULL
) {
1954 return EFI_INVALID_PARAMETER
;
1957 AcquireLockOnlyAtBootTime(&mVariableModuleGlobal
->VariableGlobal
.VariableServicesLock
);
1960 // Find existing variable
1962 Status
= FindVariableInCache (VariableName
, VendorGuid
, Attributes
, DataSize
, Data
);
1963 if ((Status
== EFI_BUFFER_TOO_SMALL
) || (Status
== EFI_SUCCESS
)){
1965 UpdateVariableInfo (VariableName
, VendorGuid
, FALSE
, TRUE
, FALSE
, FALSE
, TRUE
);
1969 Status
= FindVariable (VariableName
, VendorGuid
, &Variable
, &mVariableModuleGlobal
->VariableGlobal
);
1970 if (Variable
.CurrPtr
== NULL
|| EFI_ERROR (Status
)) {
1977 VarDataSize
= DataSizeOfVariable (Variable
.CurrPtr
);
1978 ASSERT (VarDataSize
!= 0);
1980 if (*DataSize
>= VarDataSize
) {
1982 Status
= EFI_INVALID_PARAMETER
;
1986 CopyMem (Data
, GetVariableDataPtr (Variable
.CurrPtr
), VarDataSize
);
1987 if (Attributes
!= NULL
) {
1988 *Attributes
= Variable
.CurrPtr
->Attributes
;
1991 *DataSize
= VarDataSize
;
1992 UpdateVariableInfo (VariableName
, VendorGuid
, Variable
.Volatile
, TRUE
, FALSE
, FALSE
, FALSE
);
1993 UpdateVariableCache (VariableName
, VendorGuid
, Variable
.CurrPtr
->Attributes
, VarDataSize
, Data
);
1995 Status
= EFI_SUCCESS
;
1998 *DataSize
= VarDataSize
;
1999 Status
= EFI_BUFFER_TOO_SMALL
;
2004 ReleaseLockOnlyAtBootTime (&mVariableModuleGlobal
->VariableGlobal
.VariableServicesLock
);
2012 This code Finds the Next available variable.
2014 @param VariableNameSize Size of the variable name
2015 @param VariableName Pointer to variable name
2016 @param VendorGuid Variable Vendor Guid
2018 @return EFI_INVALID_PARAMETER Invalid parameter
2019 @return EFI_SUCCESS Find the specified variable
2020 @return EFI_NOT_FOUND Not found
2021 @return EFI_BUFFER_TO_SMALL DataSize is too small for the result
2026 RuntimeServiceGetNextVariableName (
2027 IN OUT UINTN
*VariableNameSize
,
2028 IN OUT CHAR16
*VariableName
,
2029 IN OUT EFI_GUID
*VendorGuid
2032 VARIABLE_POINTER_TRACK Variable
;
2036 if (VariableNameSize
== NULL
|| VariableName
== NULL
|| VendorGuid
== NULL
) {
2037 return EFI_INVALID_PARAMETER
;
2040 AcquireLockOnlyAtBootTime(&mVariableModuleGlobal
->VariableGlobal
.VariableServicesLock
);
2042 Status
= FindVariable (VariableName
, VendorGuid
, &Variable
, &mVariableModuleGlobal
->VariableGlobal
);
2043 if (Variable
.CurrPtr
== NULL
|| EFI_ERROR (Status
)) {
2047 if (VariableName
[0] != 0) {
2049 // If variable name is not NULL, get next variable
2051 Variable
.CurrPtr
= GetNextVariablePtr (Variable
.CurrPtr
);
2056 // If both volatile and non-volatile variable store are parsed,
2059 if (Variable
.CurrPtr
>= Variable
.EndPtr
|| Variable
.CurrPtr
== NULL
) {
2060 Variable
.Volatile
= (BOOLEAN
) (Variable
.Volatile
^ ((BOOLEAN
) 0x1));
2061 if (!Variable
.Volatile
) {
2062 Variable
.StartPtr
= GetStartPointer ((VARIABLE_STORE_HEADER
*) (UINTN
) mVariableModuleGlobal
->VariableGlobal
.NonVolatileVariableBase
);
2063 Variable
.EndPtr
= GetEndPointer ((VARIABLE_STORE_HEADER
*) ((UINTN
) mVariableModuleGlobal
->VariableGlobal
.NonVolatileVariableBase
));
2065 Status
= EFI_NOT_FOUND
;
2069 Variable
.CurrPtr
= Variable
.StartPtr
;
2070 if (!IsValidVariableHeader (Variable
.CurrPtr
)) {
2075 // Variable is found
2077 if (IsValidVariableHeader (Variable
.CurrPtr
) && Variable
.CurrPtr
->State
== VAR_ADDED
) {
2078 if ((EfiAtRuntime () && ((Variable
.CurrPtr
->Attributes
& EFI_VARIABLE_RUNTIME_ACCESS
) == 0)) == 0) {
2079 VarNameSize
= NameSizeOfVariable (Variable
.CurrPtr
);
2080 ASSERT (VarNameSize
!= 0);
2082 if (VarNameSize
<= *VariableNameSize
) {
2085 GetVariableNamePtr (Variable
.CurrPtr
),
2090 &Variable
.CurrPtr
->VendorGuid
,
2093 Status
= EFI_SUCCESS
;
2095 Status
= EFI_BUFFER_TOO_SMALL
;
2098 *VariableNameSize
= VarNameSize
;
2103 Variable
.CurrPtr
= GetNextVariablePtr (Variable
.CurrPtr
);
2107 ReleaseLockOnlyAtBootTime (&mVariableModuleGlobal
->VariableGlobal
.VariableServicesLock
);
2113 This code sets variable in storage blocks (Volatile or Non-Volatile).
2115 @param VariableName Name of Variable to be found
2116 @param VendorGuid Variable vendor GUID
2117 @param Attributes Attribute value of the variable found
2118 @param DataSize Size of Data found. If size is less than the
2119 data, this value contains the required size.
2120 @param Data Data pointer
2122 @return EFI_INVALID_PARAMETER Invalid parameter
2123 @return EFI_SUCCESS Set successfully
2124 @return EFI_OUT_OF_RESOURCES Resource not enough to set variable
2125 @return EFI_NOT_FOUND Not found
2126 @return EFI_WRITE_PROTECTED Variable is read-only
2131 RuntimeServiceSetVariable (
2132 IN CHAR16
*VariableName
,
2133 IN EFI_GUID
*VendorGuid
,
2134 IN UINT32 Attributes
,
2139 VARIABLE_POINTER_TRACK Variable
;
2141 VARIABLE_HEADER
*NextVariable
;
2142 EFI_PHYSICAL_ADDRESS Point
;
2145 // Check input parameters
2147 if (VariableName
== NULL
|| VariableName
[0] == 0 || VendorGuid
== NULL
) {
2148 return EFI_INVALID_PARAMETER
;
2151 if (DataSize
!= 0 && Data
== NULL
) {
2152 return EFI_INVALID_PARAMETER
;
2156 // Not support authenticated variable write yet.
2158 if ((Attributes
& EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
) != 0) {
2159 return EFI_INVALID_PARAMETER
;
2163 // Make sure if runtime bit is set, boot service bit is set also
2165 if ((Attributes
& (EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_BOOTSERVICE_ACCESS
)) == EFI_VARIABLE_RUNTIME_ACCESS
) {
2166 return EFI_INVALID_PARAMETER
;
2170 // The size of the VariableName, including the Unicode Null in bytes plus
2171 // the DataSize is limited to maximum size of PcdGet32 (PcdMaxHardwareErrorVariableSize)
2172 // bytes for HwErrRec, and PcdGet32 (PcdMaxVariableSize) bytes for the others.
2174 if ((Attributes
& EFI_VARIABLE_HARDWARE_ERROR_RECORD
) == EFI_VARIABLE_HARDWARE_ERROR_RECORD
) {
2175 if ((DataSize
> PcdGet32 (PcdMaxHardwareErrorVariableSize
)) ||
2176 (sizeof (VARIABLE_HEADER
) + StrSize (VariableName
) + DataSize
> PcdGet32 (PcdMaxHardwareErrorVariableSize
))) {
2177 return EFI_INVALID_PARAMETER
;
2180 // According to UEFI spec, HARDWARE_ERROR_RECORD variable name convention should be L"HwErrRecXXXX"
2182 if (StrnCmp(VariableName
, L
"HwErrRec", StrLen(L
"HwErrRec")) != 0) {
2183 return EFI_INVALID_PARAMETER
;
2187 // The size of the VariableName, including the Unicode Null in bytes plus
2188 // the DataSize is limited to maximum size of PcdGet32 (PcdMaxVariableSize) bytes.
2190 if ((DataSize
> PcdGet32 (PcdMaxVariableSize
)) ||
2191 (sizeof (VARIABLE_HEADER
) + StrSize (VariableName
) + DataSize
> PcdGet32 (PcdMaxVariableSize
))) {
2192 return EFI_INVALID_PARAMETER
;
2196 AcquireLockOnlyAtBootTime(&mVariableModuleGlobal
->VariableGlobal
.VariableServicesLock
);
2199 // Consider reentrant in MCA/INIT/NMI. It needs be reupdated;
2201 if (1 < InterlockedIncrement (&mVariableModuleGlobal
->VariableGlobal
.ReentrantState
)) {
2202 Point
= mVariableModuleGlobal
->VariableGlobal
.NonVolatileVariableBase
;;
2204 // Parse non-volatile variable data and get last variable offset
2206 NextVariable
= GetStartPointer ((VARIABLE_STORE_HEADER
*) (UINTN
) Point
);
2207 while ((NextVariable
< GetEndPointer ((VARIABLE_STORE_HEADER
*) (UINTN
) Point
))
2208 && IsValidVariableHeader (NextVariable
)) {
2209 NextVariable
= GetNextVariablePtr (NextVariable
);
2211 mVariableModuleGlobal
->NonVolatileLastVariableOffset
= (UINTN
) NextVariable
- (UINTN
) Point
;
2215 // Check whether the input variable is already existed
2217 FindVariable (VariableName
, VendorGuid
, &Variable
, &mVariableModuleGlobal
->VariableGlobal
);
2220 // Hook the operation of setting PlatformLangCodes/PlatformLang and LangCodes/Lang
2222 AutoUpdateLangVariable (VariableName
, Data
, DataSize
);
2224 Status
= UpdateVariable (VariableName
, VendorGuid
, Data
, DataSize
, Attributes
, &Variable
);
2226 InterlockedDecrement (&mVariableModuleGlobal
->VariableGlobal
.ReentrantState
);
2227 ReleaseLockOnlyAtBootTime (&mVariableModuleGlobal
->VariableGlobal
.VariableServicesLock
);
2234 This code returns information about the EFI variables.
2236 @param Attributes Attributes bitmask to specify the type of variables
2237 on which to return information.
2238 @param MaximumVariableStorageSize Pointer to the maximum size of the storage space available
2239 for the EFI variables associated with the attributes specified.
2240 @param RemainingVariableStorageSize Pointer to the remaining size of the storage space available
2241 for EFI variables associated with the attributes specified.
2242 @param MaximumVariableSize Pointer to the maximum size of an individual EFI variables
2243 associated with the attributes specified.
2245 @return EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied.
2246 @return EFI_SUCCESS Query successfully.
2247 @return EFI_UNSUPPORTED The attribute is not supported on this platform.
2252 RuntimeServiceQueryVariableInfo (
2253 IN UINT32 Attributes
,
2254 OUT UINT64
*MaximumVariableStorageSize
,
2255 OUT UINT64
*RemainingVariableStorageSize
,
2256 OUT UINT64
*MaximumVariableSize
2259 VARIABLE_HEADER
*Variable
;
2260 VARIABLE_HEADER
*NextVariable
;
2261 UINT64 VariableSize
;
2262 VARIABLE_STORE_HEADER
*VariableStoreHeader
;
2263 UINT64 CommonVariableTotalSize
;
2264 UINT64 HwErrVariableTotalSize
;
2266 CommonVariableTotalSize
= 0;
2267 HwErrVariableTotalSize
= 0;
2269 if(MaximumVariableStorageSize
== NULL
|| RemainingVariableStorageSize
== NULL
|| MaximumVariableSize
== NULL
|| Attributes
== 0) {
2270 return EFI_INVALID_PARAMETER
;
2273 if((Attributes
& (EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_HARDWARE_ERROR_RECORD
)) == 0) {
2275 // Make sure the Attributes combination is supported by the platform.
2277 return EFI_UNSUPPORTED
;
2278 } else if ((Attributes
& (EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_BOOTSERVICE_ACCESS
)) == EFI_VARIABLE_RUNTIME_ACCESS
) {
2280 // Make sure if runtime bit is set, boot service bit is set also.
2282 return EFI_INVALID_PARAMETER
;
2283 } else if (EfiAtRuntime () && ((Attributes
& EFI_VARIABLE_RUNTIME_ACCESS
) == 0)) {
2285 // Make sure RT Attribute is set if we are in Runtime phase.
2287 return EFI_INVALID_PARAMETER
;
2288 } else if ((Attributes
& (EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_HARDWARE_ERROR_RECORD
)) == EFI_VARIABLE_HARDWARE_ERROR_RECORD
) {
2290 // Make sure Hw Attribute is set with NV.
2292 return EFI_INVALID_PARAMETER
;
2293 } else if ((Attributes
& EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
) != 0) {
2295 // Not support authentiated variable write yet.
2297 return EFI_UNSUPPORTED
;
2300 AcquireLockOnlyAtBootTime(&mVariableModuleGlobal
->VariableGlobal
.VariableServicesLock
);
2302 if((Attributes
& EFI_VARIABLE_NON_VOLATILE
) == 0) {
2304 // Query is Volatile related.
2306 VariableStoreHeader
= (VARIABLE_STORE_HEADER
*) ((UINTN
) mVariableModuleGlobal
->VariableGlobal
.VolatileVariableBase
);
2309 // Query is Non-Volatile related.
2311 VariableStoreHeader
= (VARIABLE_STORE_HEADER
*) ((UINTN
) mVariableModuleGlobal
->VariableGlobal
.NonVolatileVariableBase
);
2315 // Now let's fill *MaximumVariableStorageSize *RemainingVariableStorageSize
2316 // with the storage size (excluding the storage header size).
2318 *MaximumVariableStorageSize
= VariableStoreHeader
->Size
- sizeof (VARIABLE_STORE_HEADER
);
2321 // Harware error record variable needs larger size.
2323 if ((Attributes
& (EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_HARDWARE_ERROR_RECORD
)) == (EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_HARDWARE_ERROR_RECORD
)) {
2324 *MaximumVariableStorageSize
= PcdGet32 (PcdHwErrStorageSize
);
2325 *MaximumVariableSize
= PcdGet32 (PcdMaxHardwareErrorVariableSize
) - sizeof (VARIABLE_HEADER
);
2327 if ((Attributes
& EFI_VARIABLE_NON_VOLATILE
) != 0) {
2328 ASSERT (PcdGet32 (PcdHwErrStorageSize
) < VariableStoreHeader
->Size
);
2329 *MaximumVariableStorageSize
= VariableStoreHeader
->Size
- sizeof (VARIABLE_STORE_HEADER
) - PcdGet32 (PcdHwErrStorageSize
);
2333 // Let *MaximumVariableSize be PcdGet32 (PcdMaxVariableSize) with the exception of the variable header size.
2335 *MaximumVariableSize
= PcdGet32 (PcdMaxVariableSize
) - sizeof (VARIABLE_HEADER
);
2339 // Point to the starting address of the variables.
2341 Variable
= GetStartPointer (VariableStoreHeader
);
2344 // Now walk through the related variable store.
2346 while ((Variable
< GetEndPointer (VariableStoreHeader
)) && IsValidVariableHeader (Variable
)) {
2347 NextVariable
= GetNextVariablePtr (Variable
);
2348 VariableSize
= (UINT64
) (UINTN
) NextVariable
- (UINT64
) (UINTN
) Variable
;
2350 if (EfiAtRuntime ()) {
2352 // we don't take the state of the variables in mind
2353 // when calculating RemainingVariableStorageSize,
2354 // since the space occupied by variables not marked with
2355 // VAR_ADDED is not allowed to be reclaimed in Runtime.
2357 if ((NextVariable
->Attributes
& EFI_VARIABLE_HARDWARE_ERROR_RECORD
) == EFI_VARIABLE_HARDWARE_ERROR_RECORD
) {
2358 HwErrVariableTotalSize
+= VariableSize
;
2360 CommonVariableTotalSize
+= VariableSize
;
2364 // Only care about Variables with State VAR_ADDED,because
2365 // the space not marked as VAR_ADDED is reclaimable now.
2367 if (Variable
->State
== VAR_ADDED
) {
2368 if ((NextVariable
->Attributes
& EFI_VARIABLE_HARDWARE_ERROR_RECORD
) == EFI_VARIABLE_HARDWARE_ERROR_RECORD
) {
2369 HwErrVariableTotalSize
+= VariableSize
;
2371 CommonVariableTotalSize
+= VariableSize
;
2377 // Go to the next one
2379 Variable
= NextVariable
;
2382 if ((Attributes
& EFI_VARIABLE_HARDWARE_ERROR_RECORD
) == EFI_VARIABLE_HARDWARE_ERROR_RECORD
){
2383 *RemainingVariableStorageSize
= *MaximumVariableStorageSize
- HwErrVariableTotalSize
;
2385 *RemainingVariableStorageSize
= *MaximumVariableStorageSize
- CommonVariableTotalSize
;
2388 if (*RemainingVariableStorageSize
< sizeof (VARIABLE_HEADER
)) {
2389 *MaximumVariableSize
= 0;
2390 } else if ((*RemainingVariableStorageSize
- sizeof (VARIABLE_HEADER
)) < *MaximumVariableSize
) {
2391 *MaximumVariableSize
= *RemainingVariableStorageSize
- sizeof (VARIABLE_HEADER
);
2394 ReleaseLockOnlyAtBootTime (&mVariableModuleGlobal
->VariableGlobal
.VariableServicesLock
);
2400 Notification function of EVT_GROUP_READY_TO_BOOT event group.
2402 This is a notification function registered on EVT_GROUP_READY_TO_BOOT event group.
2403 When the Boot Manager is about to load and execute a boot option, it reclaims variable
2404 storage if free size is below the threshold.
2406 @param Event Event whose notification function is being invoked
2407 @param Context Pointer to the notification function's context
2418 UINTN CommonVariableSpace
;
2419 UINTN RemainingCommonVariableSpace
;
2420 UINTN RemainingHwErrVariableSpace
;
2422 Status
= EFI_SUCCESS
;
2424 CommonVariableSpace
= ((VARIABLE_STORE_HEADER
*) ((UINTN
) (mVariableModuleGlobal
->VariableGlobal
.NonVolatileVariableBase
)))->Size
- sizeof (VARIABLE_STORE_HEADER
) - PcdGet32(PcdHwErrStorageSize
); //Allowable max size of common variable storage space
2426 RemainingCommonVariableSpace
= CommonVariableSpace
- mVariableModuleGlobal
->CommonVariableTotalSize
;
2428 RemainingHwErrVariableSpace
= PcdGet32 (PcdHwErrStorageSize
) - mVariableModuleGlobal
->HwErrVariableTotalSize
;
2430 // Check if the free area is blow a threshold.
2432 if ((RemainingCommonVariableSpace
< PcdGet32 (PcdMaxVariableSize
))
2433 || ((PcdGet32 (PcdHwErrStorageSize
) != 0) &&
2434 (RemainingHwErrVariableSpace
< PcdGet32 (PcdMaxHardwareErrorVariableSize
)))){
2436 mVariableModuleGlobal
->VariableGlobal
.NonVolatileVariableBase
,
2437 &mVariableModuleGlobal
->NonVolatileLastVariableOffset
,
2441 ASSERT_EFI_ERROR (Status
);
2446 Initializes variable store area for non-volatile and volatile variable.
2448 @param FvbProtocol Pointer to an instance of EFI Firmware Volume Block Protocol.
2450 @retval EFI_SUCCESS Function successfully executed.
2451 @retval EFI_OUT_OF_RESOURCES Fail to allocate enough memory resource.
2455 VariableCommonInitialize (
2456 IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL
*FvbProtocol
2460 VARIABLE_STORE_HEADER
*VolatileVariableStore
;
2461 VARIABLE_STORE_HEADER
*VariableStoreHeader
;
2462 VARIABLE_HEADER
*NextVariable
;
2463 EFI_PHYSICAL_ADDRESS TempVariableStoreHeader
;
2464 EFI_GCD_MEMORY_SPACE_DESCRIPTOR GcdDescriptor
;
2465 EFI_PHYSICAL_ADDRESS BaseAddress
;
2469 EFI_PHYSICAL_ADDRESS VariableStoreBase
;
2470 UINT64 VariableStoreLength
;
2471 EFI_EVENT ReadyToBootEvent
;
2475 Status
= EFI_SUCCESS
;
2477 // Allocate runtime memory for variable driver global structure.
2479 mVariableModuleGlobal
= AllocateRuntimeZeroPool (sizeof (VARIABLE_MODULE_GLOBAL
));
2480 if (mVariableModuleGlobal
== NULL
) {
2481 return EFI_OUT_OF_RESOURCES
;
2484 EfiInitializeLock(&mVariableModuleGlobal
->VariableGlobal
.VariableServicesLock
, TPL_NOTIFY
);
2487 // Note that in EdkII variable driver implementation, Hardware Error Record type variable
2488 // is stored with common variable in the same NV region. So the platform integrator should
2489 // ensure that the value of PcdHwErrStorageSize is less than or equal to the value of
2490 // PcdFlashNvStorageVariableSize.
2492 ASSERT (PcdGet32 (PcdHwErrStorageSize
) <= PcdGet32 (PcdFlashNvStorageVariableSize
));
2495 // Allocate memory for volatile variable store, note that there is a scratch space to store scratch data.
2497 ScratchSize
= MAX (PcdGet32 (PcdMaxVariableSize
), PcdGet32 (PcdMaxHardwareErrorVariableSize
));
2498 VolatileVariableStore
= AllocateRuntimePool (PcdGet32 (PcdVariableStoreSize
) + ScratchSize
);
2499 if (VolatileVariableStore
== NULL
) {
2500 FreePool (mVariableModuleGlobal
);
2501 return EFI_OUT_OF_RESOURCES
;
2504 SetMem (VolatileVariableStore
, PcdGet32 (PcdVariableStoreSize
) + ScratchSize
, 0xff);
2507 // Variable Specific Data
2509 mVariableModuleGlobal
->VariableGlobal
.VolatileVariableBase
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) VolatileVariableStore
;
2510 mVariableModuleGlobal
->VolatileLastVariableOffset
= (UINTN
) GetStartPointer (VolatileVariableStore
) - (UINTN
) VolatileVariableStore
;
2511 mVariableModuleGlobal
->FvbInstance
= FvbProtocol
;
2513 CopyGuid (&VolatileVariableStore
->Signature
, &gEfiVariableGuid
);
2514 VolatileVariableStore
->Size
= PcdGet32 (PcdVariableStoreSize
);
2515 VolatileVariableStore
->Format
= VARIABLE_STORE_FORMATTED
;
2516 VolatileVariableStore
->State
= VARIABLE_STORE_HEALTHY
;
2517 VolatileVariableStore
->Reserved
= 0;
2518 VolatileVariableStore
->Reserved1
= 0;
2521 // Get non volatile varaible store
2524 TempVariableStoreHeader
= (EFI_PHYSICAL_ADDRESS
) PcdGet64 (PcdFlashNvStorageVariableBase64
);
2525 if (TempVariableStoreHeader
== 0) {
2526 TempVariableStoreHeader
= (EFI_PHYSICAL_ADDRESS
) PcdGet32 (PcdFlashNvStorageVariableBase
);
2529 VariableStoreBase
= TempVariableStoreHeader
+ \
2530 (((EFI_FIRMWARE_VOLUME_HEADER
*)(UINTN
)(TempVariableStoreHeader
)) -> HeaderLength
);
2531 VariableStoreLength
= (UINT64
) PcdGet32 (PcdFlashNvStorageVariableSize
) - \
2532 (((EFI_FIRMWARE_VOLUME_HEADER
*)(UINTN
)(TempVariableStoreHeader
)) -> HeaderLength
);
2534 // Mark the variable storage region of the FLASH as RUNTIME
2536 BaseAddress
= VariableStoreBase
& (~EFI_PAGE_MASK
);
2537 Length
= VariableStoreLength
+ (VariableStoreBase
- BaseAddress
);
2538 Length
= (Length
+ EFI_PAGE_SIZE
- 1) & (~EFI_PAGE_MASK
);
2540 Status
= gDS
->GetMemorySpaceDescriptor (BaseAddress
, &GcdDescriptor
);
2541 if (EFI_ERROR (Status
)) {
2545 Status
= gDS
->SetMemorySpaceAttributes (
2548 GcdDescriptor
.Attributes
| EFI_MEMORY_RUNTIME
2550 if (EFI_ERROR (Status
)) {
2554 // Get address of non volatile variable store base
2556 mVariableModuleGlobal
->VariableGlobal
.NonVolatileVariableBase
= VariableStoreBase
;
2557 VariableStoreHeader
= (VARIABLE_STORE_HEADER
*)(UINTN
)VariableStoreBase
;
2558 if (GetVariableStoreStatus (VariableStoreHeader
) == EfiValid
) {
2559 if (~VariableStoreHeader
->Size
== 0) {
2560 Status
= UpdateVariableStore (
2561 &mVariableModuleGlobal
->VariableGlobal
,
2564 mVariableModuleGlobal
->FvbInstance
,
2565 (UINTN
) &VariableStoreHeader
->Size
,
2567 (UINT8
*) &VariableStoreLength
2570 // As Variables are stored in NV storage, which are slow devices,such as flash.
2571 // Variable operation may skip checking variable program result to improve performance,
2572 // We can assume Variable program is OK through some check point.
2573 // Variable Store Size Setting should be the first Variable write operation,
2574 // We can assume all Read/Write is OK if we can set Variable store size successfully.
2575 // If write fail, we will assert here
2577 ASSERT(VariableStoreHeader
->Size
== VariableStoreLength
);
2579 if (EFI_ERROR (Status
)) {
2585 // Parse non-volatile variable data and get last variable offset
2587 NextVariable
= GetStartPointer ((VARIABLE_STORE_HEADER
*)(UINTN
)VariableStoreBase
);
2588 Status
= EFI_SUCCESS
;
2590 while (IsValidVariableHeader (NextVariable
)) {
2591 VariableSize
= NextVariable
->NameSize
+ NextVariable
->DataSize
+ sizeof (VARIABLE_HEADER
);
2592 if ((NextVariable
->Attributes
& (EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_HARDWARE_ERROR_RECORD
)) == (EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_HARDWARE_ERROR_RECORD
)) {
2593 mVariableModuleGlobal
->HwErrVariableTotalSize
+= HEADER_ALIGN (VariableSize
);
2595 mVariableModuleGlobal
->CommonVariableTotalSize
+= HEADER_ALIGN (VariableSize
);
2598 NextVariable
= GetNextVariablePtr (NextVariable
);
2601 mVariableModuleGlobal
->NonVolatileLastVariableOffset
= (UINTN
) NextVariable
- (UINTN
) VariableStoreBase
;
2604 // Check if the free area is really free.
2606 for (Index
= mVariableModuleGlobal
->NonVolatileLastVariableOffset
; Index
< VariableStoreHeader
->Size
; Index
++) {
2607 Data
= ((UINT8
*) (UINTN
) mVariableModuleGlobal
->VariableGlobal
.NonVolatileVariableBase
)[Index
];
2610 // There must be something wrong in variable store, do reclaim operation.
2613 mVariableModuleGlobal
->VariableGlobal
.NonVolatileVariableBase
,
2614 &mVariableModuleGlobal
->NonVolatileLastVariableOffset
,
2619 if (EFI_ERROR (Status
)) {
2628 // Register the event handling function to reclaim variable for OS usage.
2630 Status
= EfiCreateEventReadyToBootEx (
2637 Status
= EFI_VOLUME_CORRUPTED
;
2638 DEBUG((EFI_D_INFO
, "Variable Store header is corrupted\n"));
2642 if (EFI_ERROR (Status
)) {
2643 FreePool (mVariableModuleGlobal
);
2644 FreePool (VolatileVariableStore
);
2651 Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE
2653 This is a notification function registered on EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.
2654 It convers pointer to new virtual address.
2656 @param Event Event whose notification function is being invoked
2657 @param Context Pointer to the notification function's context
2662 VariableClassAddressChangeEvent (
2667 EfiConvertPointer (0x0, (VOID
**) &mVariableModuleGlobal
->FvbInstance
->GetBlockSize
);
2668 EfiConvertPointer (0x0, (VOID
**) &mVariableModuleGlobal
->FvbInstance
->GetPhysicalAddress
);
2669 EfiConvertPointer (0x0, (VOID
**) &mVariableModuleGlobal
->FvbInstance
->GetAttributes
);
2670 EfiConvertPointer (0x0, (VOID
**) &mVariableModuleGlobal
->FvbInstance
->SetAttributes
);
2671 EfiConvertPointer (0x0, (VOID
**) &mVariableModuleGlobal
->FvbInstance
->Read
);
2672 EfiConvertPointer (0x0, (VOID
**) &mVariableModuleGlobal
->FvbInstance
->Write
);
2673 EfiConvertPointer (0x0, (VOID
**) &mVariableModuleGlobal
->FvbInstance
->EraseBlocks
);
2674 EfiConvertPointer (0x0, (VOID
**) &mVariableModuleGlobal
->FvbInstance
);
2675 EfiConvertPointer (0x0, (VOID
**) &mVariableModuleGlobal
->PlatformLangCodes
);
2676 EfiConvertPointer (0x0, (VOID
**) &mVariableModuleGlobal
->LangCodes
);
2677 EfiConvertPointer (0x0, (VOID
**) &mVariableModuleGlobal
->PlatformLang
);
2680 (VOID
**) &mVariableModuleGlobal
->VariableGlobal
.NonVolatileVariableBase
2684 (VOID
**) &mVariableModuleGlobal
->VariableGlobal
.VolatileVariableBase
2686 EfiConvertPointer (0x0, (VOID
**) &mVariableModuleGlobal
);
2690 Firmware Volume Block Protocol notification event handler.
2692 Discover NV Variable Store and install Variable Arch Protocol.
2694 @param[in] Event Event whose notification function is being invoked.
2695 @param[in] Context Pointer to the notification function's context.
2699 FvbNotificationEvent (
2705 EFI_HANDLE
*HandleBuffer
;
2708 EFI_PHYSICAL_ADDRESS FvbBaseAddress
;
2709 EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL
*Fvb
;
2710 EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
;
2711 EFI_FVB_ATTRIBUTES_2 Attributes
;
2712 EFI_SYSTEM_TABLE
*SystemTable
;
2713 EFI_PHYSICAL_ADDRESS NvStorageVariableBase
;
2715 SystemTable
= (EFI_SYSTEM_TABLE
*)Context
;
2719 // Locate all handles of Fvb protocol
2721 Status
= gBS
->LocateHandleBuffer (
2723 &gEfiFirmwareVolumeBlockProtocolGuid
,
2728 if (EFI_ERROR (Status
)) {
2733 // Get the FVB to access variable store
2735 for (Index
= 0; Index
< HandleCount
; Index
+= 1, Status
= EFI_NOT_FOUND
, Fvb
= NULL
) {
2736 Status
= gBS
->HandleProtocol (
2737 HandleBuffer
[Index
],
2738 &gEfiFirmwareVolumeBlockProtocolGuid
,
2741 if (EFI_ERROR (Status
)) {
2742 Status
= EFI_NOT_FOUND
;
2747 // Ensure this FVB protocol supported Write operation.
2749 Status
= Fvb
->GetAttributes (Fvb
, &Attributes
);
2750 if (EFI_ERROR (Status
) || ((Attributes
& EFI_FVB2_WRITE_STATUS
) == 0)) {
2754 // Compare the address and select the right one
2756 Status
= Fvb
->GetPhysicalAddress (Fvb
, &FvbBaseAddress
);
2757 if (EFI_ERROR (Status
)) {
2761 FwVolHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) ((UINTN
) FvbBaseAddress
);
2762 NvStorageVariableBase
= (EFI_PHYSICAL_ADDRESS
) PcdGet64 (PcdFlashNvStorageVariableBase64
);
2763 if (NvStorageVariableBase
== 0) {
2764 NvStorageVariableBase
= (EFI_PHYSICAL_ADDRESS
) PcdGet32 (PcdFlashNvStorageVariableBase
);
2767 if ((NvStorageVariableBase
>= FvbBaseAddress
) && (NvStorageVariableBase
< (FvbBaseAddress
+ FwVolHeader
->FvLength
))) {
2768 Status
= EFI_SUCCESS
;
2773 FreePool (HandleBuffer
);
2774 if (!EFI_ERROR (Status
) && Fvb
!= NULL
) {
2776 // Close the notify event to avoid install gEfiVariableArchProtocolGuid & gEfiVariableWriteArchProtocolGuid again.
2778 Status
= gBS
->CloseEvent (Event
);
2779 ASSERT_EFI_ERROR (Status
);
2781 Status
= VariableCommonInitialize (Fvb
);
2782 ASSERT_EFI_ERROR (Status
);
2784 SystemTable
->RuntimeServices
->GetVariable
= RuntimeServiceGetVariable
;
2785 SystemTable
->RuntimeServices
->GetNextVariableName
= RuntimeServiceGetNextVariableName
;
2786 SystemTable
->RuntimeServices
->SetVariable
= RuntimeServiceSetVariable
;
2787 SystemTable
->RuntimeServices
->QueryVariableInfo
= RuntimeServiceQueryVariableInfo
;
2790 // Now install the Variable Runtime Architectural Protocol on a new handle
2792 Status
= gBS
->InstallMultipleProtocolInterfaces (
2794 &gEfiVariableArchProtocolGuid
, NULL
,
2795 &gEfiVariableWriteArchProtocolGuid
, NULL
,
2798 ASSERT_EFI_ERROR (Status
);
2800 Status
= gBS
->CreateEventEx (
2803 VariableClassAddressChangeEvent
,
2805 &gEfiEventVirtualAddressChangeGuid
,
2806 &mVirtualAddressChangeEvent
2808 ASSERT_EFI_ERROR (Status
);
2814 Variable Driver main entry point. The Variable driver places the 4 EFI
2815 runtime services in the EFI System Table and installs arch protocols
2816 for variable read and write services being availible. It also registers
2817 notification function for EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.
2819 @param[in] ImageHandle The firmware allocated handle for the EFI image.
2820 @param[in] SystemTable A pointer to the EFI System Table.
2822 @retval EFI_SUCCESS Variable service successfully initialized.
2827 VariableServiceInitialize (
2828 IN EFI_HANDLE ImageHandle
,
2829 IN EFI_SYSTEM_TABLE
*SystemTable
2833 // Register FvbNotificationEvent () notify function.
2835 EfiCreateProtocolNotifyEvent (
2836 &gEfiFirmwareVolumeBlockProtocolGuid
,
2838 FvbNotificationEvent
,
2839 (VOID
*)SystemTable
,