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.
1252 VariableGetBestLanguage (
1253 IN CONST CHAR8
*SupportedLanguages
,
1254 IN BOOLEAN Iso639Language
,
1260 UINTN CompareLength
;
1261 UINTN LanguageLength
;
1262 CONST CHAR8
*Supported
;
1265 ASSERT (SupportedLanguages
!= NULL
);
1267 VA_START (Args
, Iso639Language
);
1268 while ((Language
= VA_ARG (Args
, CHAR8
*)) != NULL
) {
1270 // Default to ISO 639-2 mode
1273 LanguageLength
= MIN (3, AsciiStrLen (Language
));
1276 // If in RFC 4646 mode, then determine the length of the first RFC 4646 language code in Language
1278 if (!Iso639Language
) {
1279 for (LanguageLength
= 0; Language
[LanguageLength
] != 0 && Language
[LanguageLength
] != ';'; LanguageLength
++);
1283 // Trim back the length of Language used until it is empty
1285 while (LanguageLength
> 0) {
1287 // Loop through all language codes in SupportedLanguages
1289 for (Supported
= SupportedLanguages
; *Supported
!= '\0'; Supported
+= CompareLength
) {
1291 // In RFC 4646 mode, then Loop through all language codes in SupportedLanguages
1293 if (!Iso639Language
) {
1295 // Skip ';' characters in Supported
1297 for (; *Supported
!= '\0' && *Supported
== ';'; Supported
++);
1299 // Determine the length of the next language code in Supported
1301 for (CompareLength
= 0; Supported
[CompareLength
] != 0 && Supported
[CompareLength
] != ';'; CompareLength
++);
1303 // If Language is longer than the Supported, then skip to the next language
1305 if (LanguageLength
> CompareLength
) {
1310 // See if the first LanguageLength characters in Supported match Language
1312 if (AsciiStrnCmp (Supported
, Language
, LanguageLength
) == 0) {
1315 Buffer
= Iso639Language
? mVariableModuleGlobal
->Lang
: mVariableModuleGlobal
->PlatformLang
;
1316 Buffer
[CompareLength
] = '\0';
1317 return CopyMem (Buffer
, Supported
, CompareLength
);
1321 if (Iso639Language
) {
1323 // If ISO 639 mode, then each language can only be tested once
1328 // If RFC 4646 mode, then trim Language from the right to the next '-' character
1330 for (LanguageLength
--; LanguageLength
> 0 && Language
[LanguageLength
] != '-'; LanguageLength
--);
1337 // No matches were found
1343 Hook the operations in PlatformLangCodes, LangCodes, PlatformLang and Lang.
1345 When setting Lang/LangCodes, simultaneously update PlatformLang/PlatformLangCodes.
1347 According to UEFI spec, PlatformLangCodes/LangCodes are only set once in firmware initialization,
1348 and are read-only. Therefore, in variable driver, only store the original value for other use.
1350 @param[in] VariableName Name of variable
1352 @param[in] Data Variable data
1354 @param[in] DataSize Size of data. 0 means delete
1358 AutoUpdateLangVariable(
1359 IN CHAR16
*VariableName
,
1365 CHAR8
*BestPlatformLang
;
1369 VARIABLE_POINTER_TRACK Variable
;
1370 BOOLEAN SetLanguageCodes
;
1373 // Don't do updates for delete operation
1375 if (DataSize
== 0) {
1379 SetLanguageCodes
= FALSE
;
1381 if (StrCmp (VariableName
, L
"PlatformLangCodes") == 0) {
1383 // PlatformLangCodes is a volatile variable, so it can not be updated at runtime.
1385 if (EfiAtRuntime ()) {
1389 SetLanguageCodes
= TRUE
;
1392 // According to UEFI spec, PlatformLangCodes is only set once in firmware initialization, and is read-only
1393 // Therefore, in variable driver, only store the original value for other use.
1395 if (mVariableModuleGlobal
->PlatformLangCodes
!= NULL
) {
1396 FreePool (mVariableModuleGlobal
->PlatformLangCodes
);
1398 mVariableModuleGlobal
->PlatformLangCodes
= AllocateRuntimeCopyPool (DataSize
, Data
);
1399 ASSERT (mVariableModuleGlobal
->PlatformLangCodes
!= NULL
);
1402 // PlatformLang holds a single language from PlatformLangCodes,
1403 // so the size of PlatformLangCodes is enough for the PlatformLang.
1405 if (mVariableModuleGlobal
->PlatformLang
!= NULL
) {
1406 FreePool (mVariableModuleGlobal
->PlatformLang
);
1408 mVariableModuleGlobal
->PlatformLang
= AllocateRuntimePool (DataSize
);
1409 ASSERT (mVariableModuleGlobal
->PlatformLang
!= NULL
);
1411 } else if (StrCmp (VariableName
, L
"LangCodes") == 0) {
1413 // LangCodes is a volatile variable, so it can not be updated at runtime.
1415 if (EfiAtRuntime ()) {
1419 SetLanguageCodes
= TRUE
;
1422 // According to UEFI spec, LangCodes is only set once in firmware initialization, and is read-only
1423 // Therefore, in variable driver, only store the original value for other use.
1425 if (mVariableModuleGlobal
->LangCodes
!= NULL
) {
1426 FreePool (mVariableModuleGlobal
->LangCodes
);
1428 mVariableModuleGlobal
->LangCodes
= AllocateRuntimeCopyPool (DataSize
, Data
);
1429 ASSERT (mVariableModuleGlobal
->LangCodes
!= NULL
);
1432 if (SetLanguageCodes
1433 && (mVariableModuleGlobal
->PlatformLangCodes
!= NULL
)
1434 && (mVariableModuleGlobal
->LangCodes
!= NULL
)) {
1436 // Update Lang if PlatformLang is already set
1437 // Update PlatformLang if Lang is already set
1439 Status
= FindVariable (L
"PlatformLang", &gEfiGlobalVariableGuid
, &Variable
, (VARIABLE_GLOBAL
*) mVariableModuleGlobal
);
1440 if (!EFI_ERROR (Status
)) {
1444 VariableName
= L
"PlatformLang";
1445 Data
= GetVariableDataPtr (Variable
.CurrPtr
);
1446 DataSize
= Variable
.CurrPtr
->DataSize
;
1448 Status
= FindVariable (L
"Lang", &gEfiGlobalVariableGuid
, &Variable
, (VARIABLE_GLOBAL
*) mVariableModuleGlobal
);
1449 if (!EFI_ERROR (Status
)) {
1451 // Update PlatformLang
1453 VariableName
= L
"Lang";
1454 Data
= GetVariableDataPtr (Variable
.CurrPtr
);
1455 DataSize
= Variable
.CurrPtr
->DataSize
;
1458 // Neither PlatformLang nor Lang is set, directly return
1466 // According to UEFI spec, "Lang" and "PlatformLang" is NV|BS|RT attributions.
1468 Attributes
= EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
;
1470 if (StrCmp (VariableName
, L
"PlatformLang") == 0) {
1472 // Update Lang when PlatformLangCodes/LangCodes were set.
1474 if ((mVariableModuleGlobal
->PlatformLangCodes
!= NULL
) && (mVariableModuleGlobal
->LangCodes
!= NULL
)) {
1476 // When setting PlatformLang, firstly get most matched language string from supported language codes.
1478 BestPlatformLang
= VariableGetBestLanguage (mVariableModuleGlobal
->PlatformLangCodes
, FALSE
, Data
, NULL
);
1479 if (BestPlatformLang
!= NULL
) {
1481 // Get the corresponding index in language codes.
1483 Index
= GetIndexFromSupportedLangCodes (mVariableModuleGlobal
->PlatformLangCodes
, BestPlatformLang
, FALSE
);
1486 // Get the corresponding ISO639 language tag according to RFC4646 language tag.
1488 BestLang
= GetLangFromSupportedLangCodes (mVariableModuleGlobal
->LangCodes
, Index
, TRUE
);
1491 // Successfully convert PlatformLang to Lang, and set the BestLang value into Lang variable simultaneously.
1493 FindVariable (L
"Lang", &gEfiGlobalVariableGuid
, &Variable
, (VARIABLE_GLOBAL
*)mVariableModuleGlobal
);
1495 Status
= UpdateVariable (L
"Lang", &gEfiGlobalVariableGuid
, BestLang
, ISO_639_2_ENTRY_SIZE
+ 1, Attributes
, &Variable
);
1497 DEBUG ((EFI_D_INFO
, "Variable Driver Auto Update PlatformLang, PlatformLang:%a, Lang:%a\n", BestPlatformLang
, BestLang
));
1499 ASSERT_EFI_ERROR(Status
);
1503 } else if (StrCmp (VariableName
, L
"Lang") == 0) {
1505 // Update PlatformLang when PlatformLangCodes/LangCodes were set.
1507 if ((mVariableModuleGlobal
->PlatformLangCodes
!= NULL
) && (mVariableModuleGlobal
->LangCodes
!= NULL
)) {
1509 // When setting Lang, firstly get most matched language string from supported language codes.
1511 BestLang
= VariableGetBestLanguage (mVariableModuleGlobal
->LangCodes
, TRUE
, Data
, NULL
);
1512 if (BestLang
!= NULL
) {
1514 // Get the corresponding index in language codes.
1516 Index
= GetIndexFromSupportedLangCodes (mVariableModuleGlobal
->LangCodes
, BestLang
, TRUE
);
1519 // Get the corresponding RFC4646 language tag according to ISO639 language tag.
1521 BestPlatformLang
= GetLangFromSupportedLangCodes (mVariableModuleGlobal
->PlatformLangCodes
, Index
, FALSE
);
1524 // Successfully convert Lang to PlatformLang, and set the BestPlatformLang value into PlatformLang variable simultaneously.
1526 FindVariable (L
"PlatformLang", &gEfiGlobalVariableGuid
, &Variable
, (VARIABLE_GLOBAL
*)mVariableModuleGlobal
);
1528 Status
= UpdateVariable (L
"PlatformLang", &gEfiGlobalVariableGuid
, BestPlatformLang
,
1529 AsciiStrSize (BestPlatformLang
), Attributes
, &Variable
);
1531 DEBUG ((EFI_D_INFO
, "Variable Driver Auto Update Lang, Lang:%a, PlatformLang:%a\n", BestLang
, BestPlatformLang
));
1532 ASSERT_EFI_ERROR (Status
);
1539 Update the variable region with Variable information. These are the same
1540 arguments as the EFI Variable services.
1542 @param[in] VariableName Name of variable
1544 @param[in] VendorGuid Guid of variable
1546 @param[in] Data Variable data
1548 @param[in] DataSize Size of data. 0 means delete
1550 @param[in] Attributes Attribues of the variable
1552 @param[in] Variable The variable information which is used to keep track of variable usage.
1554 @retval EFI_SUCCESS The update operation is success.
1556 @retval EFI_OUT_OF_RESOURCES Variable region is full, can not write other data into this region.
1562 IN CHAR16
*VariableName
,
1563 IN EFI_GUID
*VendorGuid
,
1566 IN UINT32 Attributes OPTIONAL
,
1567 IN VARIABLE_POINTER_TRACK
*Variable
1571 VARIABLE_HEADER
*NextVariable
;
1573 UINTN NonVolatileVarableStoreSize
;
1574 UINTN VarNameOffset
;
1575 UINTN VarDataOffset
;
1579 EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL
*Fvb
;
1583 Fvb
= mVariableModuleGlobal
->FvbInstance
;
1586 if (Variable
->CurrPtr
!= NULL
) {
1588 // Update/Delete existing variable
1590 Volatile
= Variable
->Volatile
;
1592 if (EfiAtRuntime ()) {
1594 // If EfiAtRuntime and the variable is Volatile and Runtime Access,
1595 // the volatile is ReadOnly, and SetVariable should be aborted and
1596 // return EFI_WRITE_PROTECTED.
1598 if (Variable
->Volatile
) {
1599 Status
= EFI_WRITE_PROTECTED
;
1603 // Only variable have NV attribute can be updated/deleted in Runtime
1605 if ((Variable
->CurrPtr
->Attributes
& EFI_VARIABLE_NON_VOLATILE
) == 0) {
1606 Status
= EFI_INVALID_PARAMETER
;
1611 // Setting a data variable with no access, or zero DataSize attributes
1612 // specified causes it to be deleted.
1614 if (DataSize
== 0 || (Attributes
& (EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_BOOTSERVICE_ACCESS
)) == 0) {
1615 State
= Variable
->CurrPtr
->State
;
1616 State
&= VAR_DELETED
;
1618 Status
= UpdateVariableStore (
1619 &mVariableModuleGlobal
->VariableGlobal
,
1623 (UINTN
) &Variable
->CurrPtr
->State
,
1627 if (!EFI_ERROR (Status
)) {
1628 UpdateVariableInfo (VariableName
, VendorGuid
, Volatile
, FALSE
, FALSE
, TRUE
, FALSE
);
1629 UpdateVariableCache (VariableName
, VendorGuid
, Attributes
, DataSize
, Data
);
1634 // If the variable is marked valid and the same data has been passed in
1635 // then return to the caller immediately.
1637 if (DataSizeOfVariable (Variable
->CurrPtr
) == DataSize
&&
1638 (CompareMem (Data
, GetVariableDataPtr (Variable
->CurrPtr
), DataSize
) == 0)) {
1640 UpdateVariableInfo (VariableName
, VendorGuid
, Volatile
, FALSE
, TRUE
, FALSE
, FALSE
);
1641 Status
= EFI_SUCCESS
;
1643 } else if ((Variable
->CurrPtr
->State
== VAR_ADDED
) ||
1644 (Variable
->CurrPtr
->State
== (VAR_ADDED
& VAR_IN_DELETED_TRANSITION
))) {
1647 // Mark the old variable as in delete transition
1649 State
= Variable
->CurrPtr
->State
;
1650 State
&= VAR_IN_DELETED_TRANSITION
;
1652 Status
= UpdateVariableStore (
1653 &mVariableModuleGlobal
->VariableGlobal
,
1657 (UINTN
) &Variable
->CurrPtr
->State
,
1661 if (EFI_ERROR (Status
)) {
1667 // Not found existing variable. Create a new variable
1671 // Make sure we are trying to create a new variable.
1672 // Setting a data variable with no access, or zero DataSize attributes means to delete it.
1674 if (DataSize
== 0 || (Attributes
& (EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_BOOTSERVICE_ACCESS
)) == 0) {
1675 Status
= EFI_NOT_FOUND
;
1680 // Only variable have NV|RT attribute can be created in Runtime
1682 if (EfiAtRuntime () &&
1683 (((Attributes
& EFI_VARIABLE_RUNTIME_ACCESS
) == 0) || ((Attributes
& EFI_VARIABLE_NON_VOLATILE
) == 0))) {
1684 Status
= EFI_INVALID_PARAMETER
;
1690 // Function part - create a new variable and copy the data.
1691 // Both update a variable and create a variable will come here.
1693 // Tricky part: Use scratch data area at the end of volatile variable store
1694 // as a temporary storage.
1696 NextVariable
= GetEndPointer ((VARIABLE_STORE_HEADER
*) ((UINTN
) mVariableModuleGlobal
->VariableGlobal
.VolatileVariableBase
));
1697 ScratchSize
= MAX (PcdGet32 (PcdMaxVariableSize
), PcdGet32 (PcdMaxHardwareErrorVariableSize
));
1699 SetMem (NextVariable
, ScratchSize
, 0xff);
1701 NextVariable
->StartId
= VARIABLE_DATA
;
1702 NextVariable
->Attributes
= Attributes
;
1704 // NextVariable->State = VAR_ADDED;
1706 NextVariable
->Reserved
= 0;
1707 VarNameOffset
= sizeof (VARIABLE_HEADER
);
1708 VarNameSize
= StrSize (VariableName
);
1710 (UINT8
*) ((UINTN
) NextVariable
+ VarNameOffset
),
1714 VarDataOffset
= VarNameOffset
+ VarNameSize
+ GET_PAD_SIZE (VarNameSize
);
1716 (UINT8
*) ((UINTN
) NextVariable
+ VarDataOffset
),
1720 CopyMem (&NextVariable
->VendorGuid
, VendorGuid
, sizeof (EFI_GUID
));
1722 // There will be pad bytes after Data, the NextVariable->NameSize and
1723 // NextVariable->DataSize should not include pad size so that variable
1724 // service can get actual size in GetVariable
1726 NextVariable
->NameSize
= (UINT32
)VarNameSize
;
1727 NextVariable
->DataSize
= (UINT32
)DataSize
;
1730 // The actual size of the variable that stores in storage should
1731 // include pad size.
1733 VarSize
= VarDataOffset
+ DataSize
+ GET_PAD_SIZE (DataSize
);
1734 if ((Attributes
& EFI_VARIABLE_NON_VOLATILE
) != 0) {
1736 // Create a nonvolatile variable
1739 NonVolatileVarableStoreSize
= ((VARIABLE_STORE_HEADER
*)(UINTN
)(mVariableModuleGlobal
->VariableGlobal
.NonVolatileVariableBase
))->Size
;
1740 if ((((Attributes
& EFI_VARIABLE_HARDWARE_ERROR_RECORD
) != 0)
1741 && ((VarSize
+ mVariableModuleGlobal
->HwErrVariableTotalSize
) > PcdGet32 (PcdHwErrStorageSize
)))
1742 || (((Attributes
& EFI_VARIABLE_HARDWARE_ERROR_RECORD
) == 0)
1743 && ((VarSize
+ mVariableModuleGlobal
->CommonVariableTotalSize
) > NonVolatileVarableStoreSize
- sizeof (VARIABLE_STORE_HEADER
) - PcdGet32 (PcdHwErrStorageSize
)))) {
1744 if (EfiAtRuntime ()) {
1745 Status
= EFI_OUT_OF_RESOURCES
;
1749 // Perform garbage collection & reclaim operation
1751 Status
= Reclaim (mVariableModuleGlobal
->VariableGlobal
.NonVolatileVariableBase
,
1752 &mVariableModuleGlobal
->NonVolatileLastVariableOffset
, FALSE
, Variable
->CurrPtr
);
1753 if (EFI_ERROR (Status
)) {
1757 // If still no enough space, return out of resources
1759 if ((((Attributes
& EFI_VARIABLE_HARDWARE_ERROR_RECORD
) != 0)
1760 && ((VarSize
+ mVariableModuleGlobal
->HwErrVariableTotalSize
) > PcdGet32 (PcdHwErrStorageSize
)))
1761 || (((Attributes
& EFI_VARIABLE_HARDWARE_ERROR_RECORD
) == 0)
1762 && ((VarSize
+ mVariableModuleGlobal
->CommonVariableTotalSize
) > NonVolatileVarableStoreSize
- sizeof (VARIABLE_STORE_HEADER
) - PcdGet32 (PcdHwErrStorageSize
)))) {
1763 Status
= EFI_OUT_OF_RESOURCES
;
1770 // 1. Write variable header
1771 // 2. Set variable state to header valid
1772 // 3. Write variable data
1773 // 4. Set variable state to valid
1778 Status
= UpdateVariableStore (
1779 &mVariableModuleGlobal
->VariableGlobal
,
1783 mVariableModuleGlobal
->NonVolatileLastVariableOffset
,
1784 sizeof (VARIABLE_HEADER
),
1785 (UINT8
*) NextVariable
1788 if (EFI_ERROR (Status
)) {
1795 NextVariable
->State
= VAR_HEADER_VALID_ONLY
;
1796 Status
= UpdateVariableStore (
1797 &mVariableModuleGlobal
->VariableGlobal
,
1801 mVariableModuleGlobal
->NonVolatileLastVariableOffset
,
1802 sizeof (VARIABLE_HEADER
),
1803 (UINT8
*) NextVariable
1806 if (EFI_ERROR (Status
)) {
1812 Status
= UpdateVariableStore (
1813 &mVariableModuleGlobal
->VariableGlobal
,
1817 mVariableModuleGlobal
->NonVolatileLastVariableOffset
+ sizeof (VARIABLE_HEADER
),
1818 (UINT32
) VarSize
- sizeof (VARIABLE_HEADER
),
1819 (UINT8
*) NextVariable
+ sizeof (VARIABLE_HEADER
)
1822 if (EFI_ERROR (Status
)) {
1828 NextVariable
->State
= VAR_ADDED
;
1829 Status
= UpdateVariableStore (
1830 &mVariableModuleGlobal
->VariableGlobal
,
1834 mVariableModuleGlobal
->NonVolatileLastVariableOffset
,
1835 sizeof (VARIABLE_HEADER
),
1836 (UINT8
*) NextVariable
1839 if (EFI_ERROR (Status
)) {
1843 mVariableModuleGlobal
->NonVolatileLastVariableOffset
+= HEADER_ALIGN (VarSize
);
1845 if ((Attributes
& EFI_VARIABLE_HARDWARE_ERROR_RECORD
) != 0) {
1846 mVariableModuleGlobal
->HwErrVariableTotalSize
+= HEADER_ALIGN (VarSize
);
1848 mVariableModuleGlobal
->CommonVariableTotalSize
+= HEADER_ALIGN (VarSize
);
1852 // Create a volatile variable
1856 if ((UINT32
) (VarSize
+ mVariableModuleGlobal
->VolatileLastVariableOffset
) >
1857 ((VARIABLE_STORE_HEADER
*) ((UINTN
) (mVariableModuleGlobal
->VariableGlobal
.VolatileVariableBase
)))->Size
) {
1859 // Perform garbage collection & reclaim operation
1861 Status
= Reclaim (mVariableModuleGlobal
->VariableGlobal
.VolatileVariableBase
,
1862 &mVariableModuleGlobal
->VolatileLastVariableOffset
, TRUE
, Variable
->CurrPtr
);
1863 if (EFI_ERROR (Status
)) {
1867 // If still no enough space, return out of resources
1869 if ((UINT32
) (VarSize
+ mVariableModuleGlobal
->VolatileLastVariableOffset
) >
1870 ((VARIABLE_STORE_HEADER
*) ((UINTN
) (mVariableModuleGlobal
->VariableGlobal
.VolatileVariableBase
)))->Size
1872 Status
= EFI_OUT_OF_RESOURCES
;
1878 NextVariable
->State
= VAR_ADDED
;
1879 Status
= UpdateVariableStore (
1880 &mVariableModuleGlobal
->VariableGlobal
,
1884 mVariableModuleGlobal
->VolatileLastVariableOffset
,
1886 (UINT8
*) NextVariable
1889 if (EFI_ERROR (Status
)) {
1893 mVariableModuleGlobal
->VolatileLastVariableOffset
+= HEADER_ALIGN (VarSize
);
1897 // Mark the old variable as deleted
1899 if (!Reclaimed
&& !EFI_ERROR (Status
) && Variable
->CurrPtr
!= NULL
) {
1900 State
= Variable
->CurrPtr
->State
;
1901 State
&= VAR_DELETED
;
1903 Status
= UpdateVariableStore (
1904 &mVariableModuleGlobal
->VariableGlobal
,
1908 (UINTN
) &Variable
->CurrPtr
->State
,
1914 if (!EFI_ERROR (Status
)) {
1915 UpdateVariableInfo (VariableName
, VendorGuid
, Volatile
, FALSE
, TRUE
, FALSE
, FALSE
);
1916 UpdateVariableCache (VariableName
, VendorGuid
, Attributes
, DataSize
, Data
);
1925 This code finds variable in storage blocks (Volatile or Non-Volatile).
1927 @param VariableName Name of Variable to be found.
1928 @param VendorGuid Variable vendor GUID.
1929 @param Attributes Attribute value of the variable found.
1930 @param DataSize Size of Data found. If size is less than the
1931 data, this value contains the required size.
1932 @param Data Data pointer.
1934 @return EFI_INVALID_PARAMETER Invalid parameter
1935 @return EFI_SUCCESS Find the specified variable
1936 @return EFI_NOT_FOUND Not found
1937 @return EFI_BUFFER_TO_SMALL DataSize is too small for the result
1942 RuntimeServiceGetVariable (
1943 IN CHAR16
*VariableName
,
1944 IN EFI_GUID
*VendorGuid
,
1945 OUT UINT32
*Attributes OPTIONAL
,
1946 IN OUT UINTN
*DataSize
,
1951 VARIABLE_POINTER_TRACK Variable
;
1954 if (VariableName
== NULL
|| VendorGuid
== NULL
|| DataSize
== NULL
) {
1955 return EFI_INVALID_PARAMETER
;
1958 AcquireLockOnlyAtBootTime(&mVariableModuleGlobal
->VariableGlobal
.VariableServicesLock
);
1961 // Find existing variable
1963 Status
= FindVariableInCache (VariableName
, VendorGuid
, Attributes
, DataSize
, Data
);
1964 if ((Status
== EFI_BUFFER_TOO_SMALL
) || (Status
== EFI_SUCCESS
)){
1966 UpdateVariableInfo (VariableName
, VendorGuid
, FALSE
, TRUE
, FALSE
, FALSE
, TRUE
);
1970 Status
= FindVariable (VariableName
, VendorGuid
, &Variable
, &mVariableModuleGlobal
->VariableGlobal
);
1971 if (Variable
.CurrPtr
== NULL
|| EFI_ERROR (Status
)) {
1978 VarDataSize
= DataSizeOfVariable (Variable
.CurrPtr
);
1979 ASSERT (VarDataSize
!= 0);
1981 if (*DataSize
>= VarDataSize
) {
1983 Status
= EFI_INVALID_PARAMETER
;
1987 CopyMem (Data
, GetVariableDataPtr (Variable
.CurrPtr
), VarDataSize
);
1988 if (Attributes
!= NULL
) {
1989 *Attributes
= Variable
.CurrPtr
->Attributes
;
1992 *DataSize
= VarDataSize
;
1993 UpdateVariableInfo (VariableName
, VendorGuid
, Variable
.Volatile
, TRUE
, FALSE
, FALSE
, FALSE
);
1994 UpdateVariableCache (VariableName
, VendorGuid
, Variable
.CurrPtr
->Attributes
, VarDataSize
, Data
);
1996 Status
= EFI_SUCCESS
;
1999 *DataSize
= VarDataSize
;
2000 Status
= EFI_BUFFER_TOO_SMALL
;
2005 ReleaseLockOnlyAtBootTime (&mVariableModuleGlobal
->VariableGlobal
.VariableServicesLock
);
2013 This code Finds the Next available variable.
2015 @param VariableNameSize Size of the variable name
2016 @param VariableName Pointer to variable name
2017 @param VendorGuid Variable Vendor Guid
2019 @return EFI_INVALID_PARAMETER Invalid parameter
2020 @return EFI_SUCCESS Find the specified variable
2021 @return EFI_NOT_FOUND Not found
2022 @return EFI_BUFFER_TO_SMALL DataSize is too small for the result
2027 RuntimeServiceGetNextVariableName (
2028 IN OUT UINTN
*VariableNameSize
,
2029 IN OUT CHAR16
*VariableName
,
2030 IN OUT EFI_GUID
*VendorGuid
2033 VARIABLE_POINTER_TRACK Variable
;
2037 if (VariableNameSize
== NULL
|| VariableName
== NULL
|| VendorGuid
== NULL
) {
2038 return EFI_INVALID_PARAMETER
;
2041 AcquireLockOnlyAtBootTime(&mVariableModuleGlobal
->VariableGlobal
.VariableServicesLock
);
2043 Status
= FindVariable (VariableName
, VendorGuid
, &Variable
, &mVariableModuleGlobal
->VariableGlobal
);
2044 if (Variable
.CurrPtr
== NULL
|| EFI_ERROR (Status
)) {
2048 if (VariableName
[0] != 0) {
2050 // If variable name is not NULL, get next variable
2052 Variable
.CurrPtr
= GetNextVariablePtr (Variable
.CurrPtr
);
2057 // If both volatile and non-volatile variable store are parsed,
2060 if (Variable
.CurrPtr
>= Variable
.EndPtr
|| Variable
.CurrPtr
== NULL
) {
2061 Variable
.Volatile
= (BOOLEAN
) (Variable
.Volatile
^ ((BOOLEAN
) 0x1));
2062 if (!Variable
.Volatile
) {
2063 Variable
.StartPtr
= GetStartPointer ((VARIABLE_STORE_HEADER
*) (UINTN
) mVariableModuleGlobal
->VariableGlobal
.NonVolatileVariableBase
);
2064 Variable
.EndPtr
= GetEndPointer ((VARIABLE_STORE_HEADER
*) ((UINTN
) mVariableModuleGlobal
->VariableGlobal
.NonVolatileVariableBase
));
2066 Status
= EFI_NOT_FOUND
;
2070 Variable
.CurrPtr
= Variable
.StartPtr
;
2071 if (!IsValidVariableHeader (Variable
.CurrPtr
)) {
2076 // Variable is found
2078 if (IsValidVariableHeader (Variable
.CurrPtr
) && Variable
.CurrPtr
->State
== VAR_ADDED
) {
2079 if ((EfiAtRuntime () && ((Variable
.CurrPtr
->Attributes
& EFI_VARIABLE_RUNTIME_ACCESS
) == 0)) == 0) {
2080 VarNameSize
= NameSizeOfVariable (Variable
.CurrPtr
);
2081 ASSERT (VarNameSize
!= 0);
2083 if (VarNameSize
<= *VariableNameSize
) {
2086 GetVariableNamePtr (Variable
.CurrPtr
),
2091 &Variable
.CurrPtr
->VendorGuid
,
2094 Status
= EFI_SUCCESS
;
2096 Status
= EFI_BUFFER_TOO_SMALL
;
2099 *VariableNameSize
= VarNameSize
;
2104 Variable
.CurrPtr
= GetNextVariablePtr (Variable
.CurrPtr
);
2108 ReleaseLockOnlyAtBootTime (&mVariableModuleGlobal
->VariableGlobal
.VariableServicesLock
);
2114 This code sets variable in storage blocks (Volatile or Non-Volatile).
2116 @param VariableName Name of Variable to be found
2117 @param VendorGuid Variable vendor GUID
2118 @param Attributes Attribute value of the variable found
2119 @param DataSize Size of Data found. If size is less than the
2120 data, this value contains the required size.
2121 @param Data Data pointer
2123 @return EFI_INVALID_PARAMETER Invalid parameter
2124 @return EFI_SUCCESS Set successfully
2125 @return EFI_OUT_OF_RESOURCES Resource not enough to set variable
2126 @return EFI_NOT_FOUND Not found
2127 @return EFI_WRITE_PROTECTED Variable is read-only
2132 RuntimeServiceSetVariable (
2133 IN CHAR16
*VariableName
,
2134 IN EFI_GUID
*VendorGuid
,
2135 IN UINT32 Attributes
,
2140 VARIABLE_POINTER_TRACK Variable
;
2142 VARIABLE_HEADER
*NextVariable
;
2143 EFI_PHYSICAL_ADDRESS Point
;
2146 // Check input parameters
2148 if (VariableName
== NULL
|| VariableName
[0] == 0 || VendorGuid
== NULL
) {
2149 return EFI_INVALID_PARAMETER
;
2152 if (DataSize
!= 0 && Data
== NULL
) {
2153 return EFI_INVALID_PARAMETER
;
2157 // Not support authenticated variable write yet.
2159 if ((Attributes
& EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
) != 0) {
2160 return EFI_INVALID_PARAMETER
;
2164 // Make sure if runtime bit is set, boot service bit is set also
2166 if ((Attributes
& (EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_BOOTSERVICE_ACCESS
)) == EFI_VARIABLE_RUNTIME_ACCESS
) {
2167 return EFI_INVALID_PARAMETER
;
2171 // The size of the VariableName, including the Unicode Null in bytes plus
2172 // the DataSize is limited to maximum size of PcdGet32 (PcdMaxHardwareErrorVariableSize)
2173 // bytes for HwErrRec, and PcdGet32 (PcdMaxVariableSize) bytes for the others.
2175 if ((Attributes
& EFI_VARIABLE_HARDWARE_ERROR_RECORD
) == EFI_VARIABLE_HARDWARE_ERROR_RECORD
) {
2176 if ((DataSize
> PcdGet32 (PcdMaxHardwareErrorVariableSize
)) ||
2177 (sizeof (VARIABLE_HEADER
) + StrSize (VariableName
) + DataSize
> PcdGet32 (PcdMaxHardwareErrorVariableSize
))) {
2178 return EFI_INVALID_PARAMETER
;
2181 // According to UEFI spec, HARDWARE_ERROR_RECORD variable name convention should be L"HwErrRecXXXX"
2183 if (StrnCmp(VariableName
, L
"HwErrRec", StrLen(L
"HwErrRec")) != 0) {
2184 return EFI_INVALID_PARAMETER
;
2188 // The size of the VariableName, including the Unicode Null in bytes plus
2189 // the DataSize is limited to maximum size of PcdGet32 (PcdMaxVariableSize) bytes.
2191 if ((DataSize
> PcdGet32 (PcdMaxVariableSize
)) ||
2192 (sizeof (VARIABLE_HEADER
) + StrSize (VariableName
) + DataSize
> PcdGet32 (PcdMaxVariableSize
))) {
2193 return EFI_INVALID_PARAMETER
;
2197 AcquireLockOnlyAtBootTime(&mVariableModuleGlobal
->VariableGlobal
.VariableServicesLock
);
2200 // Consider reentrant in MCA/INIT/NMI. It needs be reupdated;
2202 if (1 < InterlockedIncrement (&mVariableModuleGlobal
->VariableGlobal
.ReentrantState
)) {
2203 Point
= mVariableModuleGlobal
->VariableGlobal
.NonVolatileVariableBase
;;
2205 // Parse non-volatile variable data and get last variable offset
2207 NextVariable
= GetStartPointer ((VARIABLE_STORE_HEADER
*) (UINTN
) Point
);
2208 while ((NextVariable
< GetEndPointer ((VARIABLE_STORE_HEADER
*) (UINTN
) Point
))
2209 && IsValidVariableHeader (NextVariable
)) {
2210 NextVariable
= GetNextVariablePtr (NextVariable
);
2212 mVariableModuleGlobal
->NonVolatileLastVariableOffset
= (UINTN
) NextVariable
- (UINTN
) Point
;
2216 // Check whether the input variable is already existed
2218 FindVariable (VariableName
, VendorGuid
, &Variable
, &mVariableModuleGlobal
->VariableGlobal
);
2221 // Hook the operation of setting PlatformLangCodes/PlatformLang and LangCodes/Lang
2223 AutoUpdateLangVariable (VariableName
, Data
, DataSize
);
2225 Status
= UpdateVariable (VariableName
, VendorGuid
, Data
, DataSize
, Attributes
, &Variable
);
2227 InterlockedDecrement (&mVariableModuleGlobal
->VariableGlobal
.ReentrantState
);
2228 ReleaseLockOnlyAtBootTime (&mVariableModuleGlobal
->VariableGlobal
.VariableServicesLock
);
2235 This code returns information about the EFI variables.
2237 @param Attributes Attributes bitmask to specify the type of variables
2238 on which to return information.
2239 @param MaximumVariableStorageSize Pointer to the maximum size of the storage space available
2240 for the EFI variables associated with the attributes specified.
2241 @param RemainingVariableStorageSize Pointer to the remaining size of the storage space available
2242 for EFI variables associated with the attributes specified.
2243 @param MaximumVariableSize Pointer to the maximum size of an individual EFI variables
2244 associated with the attributes specified.
2246 @return EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied.
2247 @return EFI_SUCCESS Query successfully.
2248 @return EFI_UNSUPPORTED The attribute is not supported on this platform.
2253 RuntimeServiceQueryVariableInfo (
2254 IN UINT32 Attributes
,
2255 OUT UINT64
*MaximumVariableStorageSize
,
2256 OUT UINT64
*RemainingVariableStorageSize
,
2257 OUT UINT64
*MaximumVariableSize
2260 VARIABLE_HEADER
*Variable
;
2261 VARIABLE_HEADER
*NextVariable
;
2262 UINT64 VariableSize
;
2263 VARIABLE_STORE_HEADER
*VariableStoreHeader
;
2264 UINT64 CommonVariableTotalSize
;
2265 UINT64 HwErrVariableTotalSize
;
2267 CommonVariableTotalSize
= 0;
2268 HwErrVariableTotalSize
= 0;
2270 if(MaximumVariableStorageSize
== NULL
|| RemainingVariableStorageSize
== NULL
|| MaximumVariableSize
== NULL
|| Attributes
== 0) {
2271 return EFI_INVALID_PARAMETER
;
2274 if((Attributes
& (EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_HARDWARE_ERROR_RECORD
)) == 0) {
2276 // Make sure the Attributes combination is supported by the platform.
2278 return EFI_UNSUPPORTED
;
2279 } else if ((Attributes
& (EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_BOOTSERVICE_ACCESS
)) == EFI_VARIABLE_RUNTIME_ACCESS
) {
2281 // Make sure if runtime bit is set, boot service bit is set also.
2283 return EFI_INVALID_PARAMETER
;
2284 } else if (EfiAtRuntime () && ((Attributes
& EFI_VARIABLE_RUNTIME_ACCESS
) == 0)) {
2286 // Make sure RT Attribute is set if we are in Runtime phase.
2288 return EFI_INVALID_PARAMETER
;
2289 } else if ((Attributes
& (EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_HARDWARE_ERROR_RECORD
)) == EFI_VARIABLE_HARDWARE_ERROR_RECORD
) {
2291 // Make sure Hw Attribute is set with NV.
2293 return EFI_INVALID_PARAMETER
;
2294 } else if ((Attributes
& EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
) != 0) {
2296 // Not support authentiated variable write yet.
2298 return EFI_UNSUPPORTED
;
2301 AcquireLockOnlyAtBootTime(&mVariableModuleGlobal
->VariableGlobal
.VariableServicesLock
);
2303 if((Attributes
& EFI_VARIABLE_NON_VOLATILE
) == 0) {
2305 // Query is Volatile related.
2307 VariableStoreHeader
= (VARIABLE_STORE_HEADER
*) ((UINTN
) mVariableModuleGlobal
->VariableGlobal
.VolatileVariableBase
);
2310 // Query is Non-Volatile related.
2312 VariableStoreHeader
= (VARIABLE_STORE_HEADER
*) ((UINTN
) mVariableModuleGlobal
->VariableGlobal
.NonVolatileVariableBase
);
2316 // Now let's fill *MaximumVariableStorageSize *RemainingVariableStorageSize
2317 // with the storage size (excluding the storage header size).
2319 *MaximumVariableStorageSize
= VariableStoreHeader
->Size
- sizeof (VARIABLE_STORE_HEADER
);
2322 // Harware error record variable needs larger size.
2324 if ((Attributes
& (EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_HARDWARE_ERROR_RECORD
)) == (EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_HARDWARE_ERROR_RECORD
)) {
2325 *MaximumVariableStorageSize
= PcdGet32 (PcdHwErrStorageSize
);
2326 *MaximumVariableSize
= PcdGet32 (PcdMaxHardwareErrorVariableSize
) - sizeof (VARIABLE_HEADER
);
2328 if ((Attributes
& EFI_VARIABLE_NON_VOLATILE
) != 0) {
2329 ASSERT (PcdGet32 (PcdHwErrStorageSize
) < VariableStoreHeader
->Size
);
2330 *MaximumVariableStorageSize
= VariableStoreHeader
->Size
- sizeof (VARIABLE_STORE_HEADER
) - PcdGet32 (PcdHwErrStorageSize
);
2334 // Let *MaximumVariableSize be PcdGet32 (PcdMaxVariableSize) with the exception of the variable header size.
2336 *MaximumVariableSize
= PcdGet32 (PcdMaxVariableSize
) - sizeof (VARIABLE_HEADER
);
2340 // Point to the starting address of the variables.
2342 Variable
= GetStartPointer (VariableStoreHeader
);
2345 // Now walk through the related variable store.
2347 while ((Variable
< GetEndPointer (VariableStoreHeader
)) && IsValidVariableHeader (Variable
)) {
2348 NextVariable
= GetNextVariablePtr (Variable
);
2349 VariableSize
= (UINT64
) (UINTN
) NextVariable
- (UINT64
) (UINTN
) Variable
;
2351 if (EfiAtRuntime ()) {
2353 // we don't take the state of the variables in mind
2354 // when calculating RemainingVariableStorageSize,
2355 // since the space occupied by variables not marked with
2356 // VAR_ADDED is not allowed to be reclaimed in Runtime.
2358 if ((NextVariable
->Attributes
& EFI_VARIABLE_HARDWARE_ERROR_RECORD
) == EFI_VARIABLE_HARDWARE_ERROR_RECORD
) {
2359 HwErrVariableTotalSize
+= VariableSize
;
2361 CommonVariableTotalSize
+= VariableSize
;
2365 // Only care about Variables with State VAR_ADDED,because
2366 // the space not marked as VAR_ADDED is reclaimable now.
2368 if (Variable
->State
== VAR_ADDED
) {
2369 if ((NextVariable
->Attributes
& EFI_VARIABLE_HARDWARE_ERROR_RECORD
) == EFI_VARIABLE_HARDWARE_ERROR_RECORD
) {
2370 HwErrVariableTotalSize
+= VariableSize
;
2372 CommonVariableTotalSize
+= VariableSize
;
2378 // Go to the next one
2380 Variable
= NextVariable
;
2383 if ((Attributes
& EFI_VARIABLE_HARDWARE_ERROR_RECORD
) == EFI_VARIABLE_HARDWARE_ERROR_RECORD
){
2384 *RemainingVariableStorageSize
= *MaximumVariableStorageSize
- HwErrVariableTotalSize
;
2386 *RemainingVariableStorageSize
= *MaximumVariableStorageSize
- CommonVariableTotalSize
;
2389 if (*RemainingVariableStorageSize
< sizeof (VARIABLE_HEADER
)) {
2390 *MaximumVariableSize
= 0;
2391 } else if ((*RemainingVariableStorageSize
- sizeof (VARIABLE_HEADER
)) < *MaximumVariableSize
) {
2392 *MaximumVariableSize
= *RemainingVariableStorageSize
- sizeof (VARIABLE_HEADER
);
2395 ReleaseLockOnlyAtBootTime (&mVariableModuleGlobal
->VariableGlobal
.VariableServicesLock
);
2401 Notification function of EVT_GROUP_READY_TO_BOOT event group.
2403 This is a notification function registered on EVT_GROUP_READY_TO_BOOT event group.
2404 When the Boot Manager is about to load and execute a boot option, it reclaims variable
2405 storage if free size is below the threshold.
2407 @param Event Event whose notification function is being invoked
2408 @param Context Pointer to the notification function's context
2419 UINTN CommonVariableSpace
;
2420 UINTN RemainingCommonVariableSpace
;
2421 UINTN RemainingHwErrVariableSpace
;
2423 Status
= EFI_SUCCESS
;
2425 CommonVariableSpace
= ((VARIABLE_STORE_HEADER
*) ((UINTN
) (mVariableModuleGlobal
->VariableGlobal
.NonVolatileVariableBase
)))->Size
- sizeof (VARIABLE_STORE_HEADER
) - PcdGet32(PcdHwErrStorageSize
); //Allowable max size of common variable storage space
2427 RemainingCommonVariableSpace
= CommonVariableSpace
- mVariableModuleGlobal
->CommonVariableTotalSize
;
2429 RemainingHwErrVariableSpace
= PcdGet32 (PcdHwErrStorageSize
) - mVariableModuleGlobal
->HwErrVariableTotalSize
;
2431 // Check if the free area is blow a threshold.
2433 if ((RemainingCommonVariableSpace
< PcdGet32 (PcdMaxVariableSize
))
2434 || ((PcdGet32 (PcdHwErrStorageSize
) != 0) &&
2435 (RemainingHwErrVariableSpace
< PcdGet32 (PcdMaxHardwareErrorVariableSize
)))){
2437 mVariableModuleGlobal
->VariableGlobal
.NonVolatileVariableBase
,
2438 &mVariableModuleGlobal
->NonVolatileLastVariableOffset
,
2442 ASSERT_EFI_ERROR (Status
);
2447 Initializes variable store area for non-volatile and volatile variable.
2449 @param FvbProtocol Pointer to an instance of EFI Firmware Volume Block Protocol.
2451 @retval EFI_SUCCESS Function successfully executed.
2452 @retval EFI_OUT_OF_RESOURCES Fail to allocate enough memory resource.
2456 VariableCommonInitialize (
2457 IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL
*FvbProtocol
2461 VARIABLE_STORE_HEADER
*VolatileVariableStore
;
2462 VARIABLE_STORE_HEADER
*VariableStoreHeader
;
2463 VARIABLE_HEADER
*NextVariable
;
2464 EFI_PHYSICAL_ADDRESS TempVariableStoreHeader
;
2465 EFI_GCD_MEMORY_SPACE_DESCRIPTOR GcdDescriptor
;
2466 EFI_PHYSICAL_ADDRESS BaseAddress
;
2470 EFI_PHYSICAL_ADDRESS VariableStoreBase
;
2471 UINT64 VariableStoreLength
;
2472 EFI_EVENT ReadyToBootEvent
;
2476 Status
= EFI_SUCCESS
;
2478 // Allocate runtime memory for variable driver global structure.
2480 mVariableModuleGlobal
= AllocateRuntimeZeroPool (sizeof (VARIABLE_MODULE_GLOBAL
));
2481 if (mVariableModuleGlobal
== NULL
) {
2482 return EFI_OUT_OF_RESOURCES
;
2485 EfiInitializeLock(&mVariableModuleGlobal
->VariableGlobal
.VariableServicesLock
, TPL_NOTIFY
);
2488 // Note that in EdkII variable driver implementation, Hardware Error Record type variable
2489 // is stored with common variable in the same NV region. So the platform integrator should
2490 // ensure that the value of PcdHwErrStorageSize is less than or equal to the value of
2491 // PcdFlashNvStorageVariableSize.
2493 ASSERT (PcdGet32 (PcdHwErrStorageSize
) <= PcdGet32 (PcdFlashNvStorageVariableSize
));
2496 // Allocate memory for volatile variable store, note that there is a scratch space to store scratch data.
2498 ScratchSize
= MAX (PcdGet32 (PcdMaxVariableSize
), PcdGet32 (PcdMaxHardwareErrorVariableSize
));
2499 VolatileVariableStore
= AllocateRuntimePool (PcdGet32 (PcdVariableStoreSize
) + ScratchSize
);
2500 if (VolatileVariableStore
== NULL
) {
2501 FreePool (mVariableModuleGlobal
);
2502 return EFI_OUT_OF_RESOURCES
;
2505 SetMem (VolatileVariableStore
, PcdGet32 (PcdVariableStoreSize
) + ScratchSize
, 0xff);
2508 // Variable Specific Data
2510 mVariableModuleGlobal
->VariableGlobal
.VolatileVariableBase
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) VolatileVariableStore
;
2511 mVariableModuleGlobal
->VolatileLastVariableOffset
= (UINTN
) GetStartPointer (VolatileVariableStore
) - (UINTN
) VolatileVariableStore
;
2512 mVariableModuleGlobal
->FvbInstance
= FvbProtocol
;
2514 CopyGuid (&VolatileVariableStore
->Signature
, &gEfiVariableGuid
);
2515 VolatileVariableStore
->Size
= PcdGet32 (PcdVariableStoreSize
);
2516 VolatileVariableStore
->Format
= VARIABLE_STORE_FORMATTED
;
2517 VolatileVariableStore
->State
= VARIABLE_STORE_HEALTHY
;
2518 VolatileVariableStore
->Reserved
= 0;
2519 VolatileVariableStore
->Reserved1
= 0;
2522 // Get non volatile varaible store
2525 TempVariableStoreHeader
= (EFI_PHYSICAL_ADDRESS
) PcdGet64 (PcdFlashNvStorageVariableBase64
);
2526 if (TempVariableStoreHeader
== 0) {
2527 TempVariableStoreHeader
= (EFI_PHYSICAL_ADDRESS
) PcdGet32 (PcdFlashNvStorageVariableBase
);
2530 VariableStoreBase
= TempVariableStoreHeader
+ \
2531 (((EFI_FIRMWARE_VOLUME_HEADER
*)(UINTN
)(TempVariableStoreHeader
)) -> HeaderLength
);
2532 VariableStoreLength
= (UINT64
) PcdGet32 (PcdFlashNvStorageVariableSize
) - \
2533 (((EFI_FIRMWARE_VOLUME_HEADER
*)(UINTN
)(TempVariableStoreHeader
)) -> HeaderLength
);
2535 // Mark the variable storage region of the FLASH as RUNTIME
2537 BaseAddress
= VariableStoreBase
& (~EFI_PAGE_MASK
);
2538 Length
= VariableStoreLength
+ (VariableStoreBase
- BaseAddress
);
2539 Length
= (Length
+ EFI_PAGE_SIZE
- 1) & (~EFI_PAGE_MASK
);
2541 Status
= gDS
->GetMemorySpaceDescriptor (BaseAddress
, &GcdDescriptor
);
2542 if (EFI_ERROR (Status
)) {
2546 Status
= gDS
->SetMemorySpaceAttributes (
2549 GcdDescriptor
.Attributes
| EFI_MEMORY_RUNTIME
2551 if (EFI_ERROR (Status
)) {
2555 // Get address of non volatile variable store base
2557 mVariableModuleGlobal
->VariableGlobal
.NonVolatileVariableBase
= VariableStoreBase
;
2558 VariableStoreHeader
= (VARIABLE_STORE_HEADER
*)(UINTN
)VariableStoreBase
;
2559 if (GetVariableStoreStatus (VariableStoreHeader
) == EfiValid
) {
2560 if (~VariableStoreHeader
->Size
== 0) {
2561 Status
= UpdateVariableStore (
2562 &mVariableModuleGlobal
->VariableGlobal
,
2565 mVariableModuleGlobal
->FvbInstance
,
2566 (UINTN
) &VariableStoreHeader
->Size
,
2568 (UINT8
*) &VariableStoreLength
2571 // As Variables are stored in NV storage, which are slow devices,such as flash.
2572 // Variable operation may skip checking variable program result to improve performance,
2573 // We can assume Variable program is OK through some check point.
2574 // Variable Store Size Setting should be the first Variable write operation,
2575 // We can assume all Read/Write is OK if we can set Variable store size successfully.
2576 // If write fail, we will assert here
2578 ASSERT(VariableStoreHeader
->Size
== VariableStoreLength
);
2580 if (EFI_ERROR (Status
)) {
2586 // Parse non-volatile variable data and get last variable offset
2588 NextVariable
= GetStartPointer ((VARIABLE_STORE_HEADER
*)(UINTN
)VariableStoreBase
);
2589 Status
= EFI_SUCCESS
;
2591 while (IsValidVariableHeader (NextVariable
)) {
2592 VariableSize
= NextVariable
->NameSize
+ NextVariable
->DataSize
+ sizeof (VARIABLE_HEADER
);
2593 if ((NextVariable
->Attributes
& (EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_HARDWARE_ERROR_RECORD
)) == (EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_HARDWARE_ERROR_RECORD
)) {
2594 mVariableModuleGlobal
->HwErrVariableTotalSize
+= HEADER_ALIGN (VariableSize
);
2596 mVariableModuleGlobal
->CommonVariableTotalSize
+= HEADER_ALIGN (VariableSize
);
2599 NextVariable
= GetNextVariablePtr (NextVariable
);
2602 mVariableModuleGlobal
->NonVolatileLastVariableOffset
= (UINTN
) NextVariable
- (UINTN
) VariableStoreBase
;
2605 // Check if the free area is really free.
2607 for (Index
= mVariableModuleGlobal
->NonVolatileLastVariableOffset
; Index
< VariableStoreHeader
->Size
; Index
++) {
2608 Data
= ((UINT8
*) (UINTN
) mVariableModuleGlobal
->VariableGlobal
.NonVolatileVariableBase
)[Index
];
2611 // There must be something wrong in variable store, do reclaim operation.
2614 mVariableModuleGlobal
->VariableGlobal
.NonVolatileVariableBase
,
2615 &mVariableModuleGlobal
->NonVolatileLastVariableOffset
,
2620 if (EFI_ERROR (Status
)) {
2629 // Register the event handling function to reclaim variable for OS usage.
2631 Status
= EfiCreateEventReadyToBootEx (
2638 Status
= EFI_VOLUME_CORRUPTED
;
2639 DEBUG((EFI_D_INFO
, "Variable Store header is corrupted\n"));
2643 if (EFI_ERROR (Status
)) {
2644 FreePool (mVariableModuleGlobal
);
2645 FreePool (VolatileVariableStore
);
2652 Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE
2654 This is a notification function registered on EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.
2655 It convers pointer to new virtual address.
2657 @param Event Event whose notification function is being invoked
2658 @param Context Pointer to the notification function's context
2663 VariableClassAddressChangeEvent (
2668 EfiConvertPointer (0x0, (VOID
**) &mVariableModuleGlobal
->FvbInstance
->GetBlockSize
);
2669 EfiConvertPointer (0x0, (VOID
**) &mVariableModuleGlobal
->FvbInstance
->GetPhysicalAddress
);
2670 EfiConvertPointer (0x0, (VOID
**) &mVariableModuleGlobal
->FvbInstance
->GetAttributes
);
2671 EfiConvertPointer (0x0, (VOID
**) &mVariableModuleGlobal
->FvbInstance
->SetAttributes
);
2672 EfiConvertPointer (0x0, (VOID
**) &mVariableModuleGlobal
->FvbInstance
->Read
);
2673 EfiConvertPointer (0x0, (VOID
**) &mVariableModuleGlobal
->FvbInstance
->Write
);
2674 EfiConvertPointer (0x0, (VOID
**) &mVariableModuleGlobal
->FvbInstance
->EraseBlocks
);
2675 EfiConvertPointer (0x0, (VOID
**) &mVariableModuleGlobal
->FvbInstance
);
2676 EfiConvertPointer (0x0, (VOID
**) &mVariableModuleGlobal
->PlatformLangCodes
);
2677 EfiConvertPointer (0x0, (VOID
**) &mVariableModuleGlobal
->LangCodes
);
2678 EfiConvertPointer (0x0, (VOID
**) &mVariableModuleGlobal
->PlatformLang
);
2681 (VOID
**) &mVariableModuleGlobal
->VariableGlobal
.NonVolatileVariableBase
2685 (VOID
**) &mVariableModuleGlobal
->VariableGlobal
.VolatileVariableBase
2687 EfiConvertPointer (0x0, (VOID
**) &mVariableModuleGlobal
);
2691 Firmware Volume Block Protocol notification event handler.
2693 Discover NV Variable Store and install Variable Arch Protocol.
2695 @param[in] Event Event whose notification function is being invoked.
2696 @param[in] Context Pointer to the notification function's context.
2700 FvbNotificationEvent (
2706 EFI_HANDLE
*HandleBuffer
;
2709 EFI_PHYSICAL_ADDRESS FvbBaseAddress
;
2710 EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL
*Fvb
;
2711 EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
;
2712 EFI_FVB_ATTRIBUTES_2 Attributes
;
2713 EFI_SYSTEM_TABLE
*SystemTable
;
2714 EFI_PHYSICAL_ADDRESS NvStorageVariableBase
;
2716 SystemTable
= (EFI_SYSTEM_TABLE
*)Context
;
2720 // Locate all handles of Fvb protocol
2722 Status
= gBS
->LocateHandleBuffer (
2724 &gEfiFirmwareVolumeBlockProtocolGuid
,
2729 if (EFI_ERROR (Status
)) {
2734 // Get the FVB to access variable store
2736 for (Index
= 0; Index
< HandleCount
; Index
+= 1, Status
= EFI_NOT_FOUND
, Fvb
= NULL
) {
2737 Status
= gBS
->HandleProtocol (
2738 HandleBuffer
[Index
],
2739 &gEfiFirmwareVolumeBlockProtocolGuid
,
2742 if (EFI_ERROR (Status
)) {
2743 Status
= EFI_NOT_FOUND
;
2748 // Ensure this FVB protocol supported Write operation.
2750 Status
= Fvb
->GetAttributes (Fvb
, &Attributes
);
2751 if (EFI_ERROR (Status
) || ((Attributes
& EFI_FVB2_WRITE_STATUS
) == 0)) {
2755 // Compare the address and select the right one
2757 Status
= Fvb
->GetPhysicalAddress (Fvb
, &FvbBaseAddress
);
2758 if (EFI_ERROR (Status
)) {
2762 FwVolHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) ((UINTN
) FvbBaseAddress
);
2763 NvStorageVariableBase
= (EFI_PHYSICAL_ADDRESS
) PcdGet64 (PcdFlashNvStorageVariableBase64
);
2764 if (NvStorageVariableBase
== 0) {
2765 NvStorageVariableBase
= (EFI_PHYSICAL_ADDRESS
) PcdGet32 (PcdFlashNvStorageVariableBase
);
2768 if ((NvStorageVariableBase
>= FvbBaseAddress
) && (NvStorageVariableBase
< (FvbBaseAddress
+ FwVolHeader
->FvLength
))) {
2769 Status
= EFI_SUCCESS
;
2774 FreePool (HandleBuffer
);
2775 if (!EFI_ERROR (Status
) && Fvb
!= NULL
) {
2777 // Close the notify event to avoid install gEfiVariableArchProtocolGuid & gEfiVariableWriteArchProtocolGuid again.
2779 Status
= gBS
->CloseEvent (Event
);
2780 ASSERT_EFI_ERROR (Status
);
2782 Status
= VariableCommonInitialize (Fvb
);
2783 ASSERT_EFI_ERROR (Status
);
2785 SystemTable
->RuntimeServices
->GetVariable
= RuntimeServiceGetVariable
;
2786 SystemTable
->RuntimeServices
->GetNextVariableName
= RuntimeServiceGetNextVariableName
;
2787 SystemTable
->RuntimeServices
->SetVariable
= RuntimeServiceSetVariable
;
2788 SystemTable
->RuntimeServices
->QueryVariableInfo
= RuntimeServiceQueryVariableInfo
;
2791 // Now install the Variable Runtime Architectural Protocol on a new handle
2793 Status
= gBS
->InstallMultipleProtocolInterfaces (
2795 &gEfiVariableArchProtocolGuid
, NULL
,
2796 &gEfiVariableWriteArchProtocolGuid
, NULL
,
2799 ASSERT_EFI_ERROR (Status
);
2801 Status
= gBS
->CreateEventEx (
2804 VariableClassAddressChangeEvent
,
2806 &gEfiEventVirtualAddressChangeGuid
,
2807 &mVirtualAddressChangeEvent
2809 ASSERT_EFI_ERROR (Status
);
2815 Variable Driver main entry point. The Variable driver places the 4 EFI
2816 runtime services in the EFI System Table and installs arch protocols
2817 for variable read and write services being availible. It also registers
2818 notification function for EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.
2820 @param[in] ImageHandle The firmware allocated handle for the EFI image.
2821 @param[in] SystemTable A pointer to the EFI System Table.
2823 @retval EFI_SUCCESS Variable service successfully initialized.
2828 VariableServiceInitialize (
2829 IN EFI_HANDLE ImageHandle
,
2830 IN EFI_SYSTEM_TABLE
*SystemTable
2834 // Register FvbNotificationEvent () notify function.
2836 EfiCreateProtocolNotifyEvent (
2837 &gEfiFirmwareVolumeBlockProtocolGuid
,
2839 FvbNotificationEvent
,
2840 (VOID
*)SystemTable
,