3 Emulation Variable services operate on the runtime volatile memory.
4 The nonvolatile variable space doesn't exist.
6 Copyright (c) 2006 - 2008, Intel Corporation
7 All rights reserved. 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.
20 // Don't use module globals after the SetVirtualAddress map is signaled
22 ESAL_VARIABLE_GLOBAL
*mVariableModuleGlobal
;
25 // This is a temperary function which will be removed
26 // when EfiAcquireLock in UefiLib can handle the
27 // the call in UEFI Runtimer driver in RT phase.
31 AcquireLockOnlyAtBootTime (
35 if (!EfiAtRuntime ()) {
36 EfiAcquireLock (Lock
);
41 // This is a temperary function which will be removed
42 // when EfiAcquireLock in UefiLib can handle the
43 // the call in UEFI Runtimer driver in RT phase.
47 ReleaseLockOnlyAtBootTime (
51 if (!EfiAtRuntime ()) {
52 EfiReleaseLock (Lock
);
59 IN VARIABLE_HEADER
*Variable
65 This code gets the pointer to the variable data.
69 Variable Pointer to the Variable Header.
73 UINT8* Pointer to Variable Data
77 if (Variable
->StartId
!= VARIABLE_DATA
) {
81 // Be careful about pad size for alignment
83 return (UINT8
*) ((UINTN
) GET_VARIABLE_NAME_PTR (Variable
) + Variable
->NameSize
+ GET_PAD_SIZE (Variable
->NameSize
));
89 IN VARIABLE_HEADER
*Variable
95 This code gets the pointer to the next variable header.
99 Variable Pointer to the Variable Header.
103 VARIABLE_HEADER* Pointer to next variable header.
107 VARIABLE_HEADER
*VarHeader
;
109 if (Variable
->StartId
!= VARIABLE_DATA
) {
113 // Be careful about pad size for alignment
115 VarHeader
= (VARIABLE_HEADER
*) (GetVariableDataPtr (Variable
) + Variable
->DataSize
+ GET_PAD_SIZE (Variable
->DataSize
));
117 if (VarHeader
->StartId
!= VARIABLE_DATA
||
118 (sizeof (VARIABLE_HEADER
) + VarHeader
->DataSize
+ VarHeader
->NameSize
) > MAX_VARIABLE_SIZE
129 IN VARIABLE_STORE_HEADER
*VolHeader
135 This code gets the pointer to the last variable memory pointer byte
139 Variable Pointer to the Variable Header.
143 VARIABLE_HEADER* Pointer to last unavailable Variable Header
148 // The end of variable store
150 return (VARIABLE_HEADER
*) ((UINTN
) VolHeader
+ VolHeader
->Size
);
156 IN CHAR16
*VariableName
,
157 IN EFI_GUID
*VendorGuid
,
158 OUT VARIABLE_POINTER_TRACK
*PtrTrack
,
159 IN VARIABLE_GLOBAL
*Global
165 This code finds variable in storage blocks (Volatile or Non-Volatile)
169 VariableName Name of the variable to be found
170 VendorGuid Vendor GUID to be found.
171 PtrTrack Variable Track Pointer structure that contains
172 Variable Information.
173 Contains the pointer of Variable header.
174 Global VARIABLE_GLOBAL pointer
182 VARIABLE_HEADER
*Variable
[2];
183 VARIABLE_STORE_HEADER
*VariableStoreHeader
[2];
187 // We aquire the lock at the entry of FindVariable as GetVariable, GetNextVariableName
188 // SetVariable all call FindVariable at entry point. Please move "Aquire Lock" to
189 // the correct places if this assumption does not hold TRUE anymore.
191 AcquireLockOnlyAtBootTime(&Global
->VariableServicesLock
);
194 // 0: Non-Volatile, 1: Volatile
196 VariableStoreHeader
[0] = (VARIABLE_STORE_HEADER
*) ((UINTN
) Global
->NonVolatileVariableBase
);
197 VariableStoreHeader
[1] = (VARIABLE_STORE_HEADER
*) ((UINTN
) Global
->VolatileVariableBase
);
200 // Start Pointers for the variable.
201 // Actual Data Pointer where data can be written.
203 Variable
[0] = (VARIABLE_HEADER
*) (VariableStoreHeader
[0] + 1);
204 Variable
[1] = (VARIABLE_HEADER
*) (VariableStoreHeader
[1] + 1);
206 if (VariableName
[0] != 0 && VendorGuid
== NULL
) {
207 return EFI_INVALID_PARAMETER
;
210 // Find the variable by walk through non-volatile and volatile variable store
212 for (Index
= 0; Index
< 2; Index
++) {
213 PtrTrack
->StartPtr
= (VARIABLE_HEADER
*) (VariableStoreHeader
[Index
] + 1);
214 PtrTrack
->EndPtr
= GetEndPointer (VariableStoreHeader
[Index
]);
216 while ((Variable
[Index
] != NULL
) && (Variable
[Index
] <= GetEndPointer (VariableStoreHeader
[Index
]))) {
217 if (Variable
[Index
]->StartId
== VARIABLE_DATA
&& Variable
[Index
]->State
== VAR_ADDED
) {
218 if (!(EfiAtRuntime () && !(Variable
[Index
]->Attributes
& EFI_VARIABLE_RUNTIME_ACCESS
))) {
219 if (VariableName
[0] == 0) {
220 PtrTrack
->CurrPtr
= Variable
[Index
];
221 PtrTrack
->Volatile
= (BOOLEAN
) Index
;
224 if (CompareGuid (VendorGuid
, &Variable
[Index
]->VendorGuid
)) {
225 if (!CompareMem (VariableName
, GET_VARIABLE_NAME_PTR (Variable
[Index
]), Variable
[Index
]->NameSize
)) {
226 PtrTrack
->CurrPtr
= Variable
[Index
];
227 PtrTrack
->Volatile
= (BOOLEAN
) Index
;
235 Variable
[Index
] = GetNextVariablePtr (Variable
[Index
]);
238 PtrTrack
->CurrPtr
= NULL
;
239 return EFI_NOT_FOUND
;
245 IN CHAR16
*VariableName
,
246 IN EFI_GUID
* VendorGuid
,
247 OUT UINT32
*Attributes OPTIONAL
,
248 IN OUT UINTN
*DataSize
,
250 IN VARIABLE_GLOBAL
* Global
,
257 This code finds variable in storage blocks (Volatile or Non-Volatile)
261 VariableName Name of Variable to be found
262 VendorGuid Variable vendor GUID
263 Attributes OPTIONAL Attribute value of the variable found
264 DataSize Size of Data found. If size is less than the
265 data, this value contains the required size.
267 Global Pointer to VARIABLE_GLOBAL structure
268 Instance Instance of the Firmware Volume.
272 EFI_INVALID_PARAMETER - Invalid parameter
273 EFI_SUCCESS - Find the specified variable
274 EFI_NOT_FOUND - Not found
275 EFI_BUFFER_TO_SMALL - DataSize is too small for the result
280 VARIABLE_POINTER_TRACK Variable
;
284 if (VariableName
== NULL
|| VendorGuid
== NULL
|| DataSize
== NULL
) {
285 return EFI_INVALID_PARAMETER
;
288 // Find existing variable
290 Status
= FindVariable (VariableName
, VendorGuid
, &Variable
, Global
);
292 if (Variable
.CurrPtr
== NULL
|| EFI_ERROR (Status
)) {
298 VarDataSize
= Variable
.CurrPtr
->DataSize
;
299 if (*DataSize
>= VarDataSize
) {
301 Status
= EFI_INVALID_PARAMETER
;
305 CopyMem (Data
, GetVariableDataPtr (Variable
.CurrPtr
), VarDataSize
);
306 if (Attributes
!= NULL
) {
307 *Attributes
= Variable
.CurrPtr
->Attributes
;
310 *DataSize
= VarDataSize
;
311 Status
= EFI_SUCCESS
;
314 *DataSize
= VarDataSize
;
315 Status
= EFI_BUFFER_TOO_SMALL
;
320 ReleaseLockOnlyAtBootTime (&Global
->VariableServicesLock
);
326 GetNextVariableName (
327 IN OUT UINTN
*VariableNameSize
,
328 IN OUT CHAR16
*VariableName
,
329 IN OUT EFI_GUID
*VendorGuid
,
330 IN VARIABLE_GLOBAL
*Global
,
337 This code Finds the Next available variable
341 VariableNameSize Size of the variable
342 VariableName Pointer to variable name
343 VendorGuid Variable Vendor Guid
344 Global VARIABLE_GLOBAL structure pointer.
353 VARIABLE_POINTER_TRACK Variable
;
357 if (VariableNameSize
== NULL
|| VariableName
== NULL
|| VendorGuid
== NULL
) {
358 return EFI_INVALID_PARAMETER
;
361 Status
= FindVariable (VariableName
, VendorGuid
, &Variable
, Global
);
363 if (Variable
.CurrPtr
== NULL
|| EFI_ERROR (Status
)) {
368 if (VariableName
[0] != 0) {
370 // If variable name is not NULL, get next variable
372 Variable
.CurrPtr
= GetNextVariablePtr (Variable
.CurrPtr
);
375 // If both volatile and non-volatile variable store are parsed,
378 if (Variable
.CurrPtr
>= Variable
.EndPtr
|| Variable
.CurrPtr
== NULL
) {
379 Variable
.Volatile
= (BOOLEAN
) (Variable
.Volatile
^ ((BOOLEAN
) 0x1));
380 if (Variable
.Volatile
) {
381 Variable
.StartPtr
= (VARIABLE_HEADER
*) ((UINTN
) (Global
->VolatileVariableBase
+ sizeof (VARIABLE_STORE_HEADER
)));
382 Variable
.EndPtr
= (VARIABLE_HEADER
*) GetEndPointer ((VARIABLE_STORE_HEADER
*) ((UINTN
) Global
->VolatileVariableBase
));
384 Status
= EFI_NOT_FOUND
;
388 Variable
.CurrPtr
= Variable
.StartPtr
;
389 if (Variable
.CurrPtr
->StartId
!= VARIABLE_DATA
) {
396 if (Variable
.CurrPtr
->StartId
== VARIABLE_DATA
&& Variable
.CurrPtr
->State
== VAR_ADDED
) {
397 if (!(EfiAtRuntime () && !(Variable
.CurrPtr
->Attributes
& EFI_VARIABLE_RUNTIME_ACCESS
))) {
398 VarNameSize
= Variable
.CurrPtr
->NameSize
;
399 if (VarNameSize
<= *VariableNameSize
) {
402 GET_VARIABLE_NAME_PTR (Variable
.CurrPtr
),
407 &Variable
.CurrPtr
->VendorGuid
,
410 Status
= EFI_SUCCESS
;
412 Status
= EFI_BUFFER_TOO_SMALL
;
415 *VariableNameSize
= VarNameSize
;
422 ReleaseLockOnlyAtBootTime (&Global
->VariableServicesLock
);
430 IN CHAR16
*VariableName
,
431 IN EFI_GUID
*VendorGuid
,
432 IN UINT32 Attributes
,
435 IN VARIABLE_GLOBAL
*Global
,
436 IN UINTN
*VolatileOffset
,
437 IN UINTN
*NonVolatileOffset
,
444 This code sets variable in storage blocks (Volatile or Non-Volatile)
448 VariableName Name of Variable to be found
449 VendorGuid Variable vendor GUID
450 Attributes Attribute value of the variable found
451 DataSize Size of Data found. If size is less than the
452 data, this value contains the required size.
454 Global Pointer to VARIABLE_GLOBAL structure
455 VolatileOffset The offset of last volatile variable
456 NonVolatileOffset The offset of last non-volatile variable
457 Instance Instance of the Firmware Volume.
461 EFI_INVALID_PARAMETER - Invalid parameter
462 EFI_SUCCESS - Set successfully
463 EFI_OUT_OF_RESOURCES - Resource not enough to set variable
464 EFI_NOT_FOUND - Not found
465 EFI_DEVICE_ERROR - Variable can not be saved due to hardware failure
466 EFI_WRITE_PROTECTED - Variable is read-only
470 VARIABLE_POINTER_TRACK Variable
;
472 VARIABLE_HEADER
*NextVariable
;
479 // Check input parameters
481 if (VariableName
== NULL
|| VariableName
[0] == 0 || VendorGuid
== NULL
) {
482 return EFI_INVALID_PARAMETER
;
485 // Make sure if runtime bit is set, boot service bit is set also
487 if ((Attributes
& (EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_BOOTSERVICE_ACCESS
)) == EFI_VARIABLE_RUNTIME_ACCESS
) {
488 return EFI_INVALID_PARAMETER
;
491 // The size of the VariableName, including the Unicode Null in bytes plus
492 // the DataSize is limited to maximum size of MAX_HARDWARE_ERROR_VARIABLE_SIZE (32K)
493 // bytes for HwErrRec, and MAX_VARIABLE_SIZE (1024) bytes for the others.
495 if ((Attributes
& EFI_VARIABLE_HARDWARE_ERROR_RECORD
) == EFI_VARIABLE_HARDWARE_ERROR_RECORD
) {
496 if ((DataSize
> MAX_HARDWARE_ERROR_VARIABLE_SIZE
) ||
497 (sizeof (VARIABLE_HEADER
) + StrSize (VariableName
) + DataSize
> MAX_HARDWARE_ERROR_VARIABLE_SIZE
)) {
498 return EFI_INVALID_PARAMETER
;
502 // The size of the VariableName, including the Unicode Null in bytes plus
503 // the DataSize is limited to maximum size of MAX_VARIABLE_SIZE (1024) bytes.
505 if ((DataSize
> MAX_VARIABLE_SIZE
) ||
506 (sizeof (VARIABLE_HEADER
) + StrSize (VariableName
) + DataSize
> MAX_VARIABLE_SIZE
)) {
507 return EFI_INVALID_PARAMETER
;
511 // Check whether the input variable is already existed
514 Status
= FindVariable (VariableName
, VendorGuid
, &Variable
, Global
);
516 if (Status
== EFI_SUCCESS
&& Variable
.CurrPtr
!= NULL
) {
518 // Update/Delete existing variable
521 if (EfiAtRuntime ()) {
523 // If EfiAtRuntime and the variable is Volatile and Runtime Access,
524 // the volatile is ReadOnly, and SetVariable should be aborted and
525 // return EFI_WRITE_PROTECTED.
527 if (Variable
.Volatile
) {
528 Status
= EFI_WRITE_PROTECTED
;
532 // Only variable have NV attribute can be updated/deleted in Runtime
534 if (!(Variable
.CurrPtr
->Attributes
& EFI_VARIABLE_NON_VOLATILE
)) {
535 Status
= EFI_INVALID_PARAMETER
;
541 // Setting a data variable with no access, or zero DataSize attributes
542 // specified causes it to be deleted.
544 if (DataSize
== 0 || (Attributes
& (EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_BOOTSERVICE_ACCESS
)) == 0) {
545 Variable
.CurrPtr
->State
&= VAR_DELETED
;
546 Status
= EFI_SUCCESS
;
551 // If the variable is marked valid and the same data has been passed in
552 // then return to the caller immediately.
554 if (Variable
.CurrPtr
->DataSize
== DataSize
&&
555 !CompareMem (Data
, GetVariableDataPtr (Variable
.CurrPtr
), DataSize
)
557 Status
= EFI_SUCCESS
;
559 } else if (Variable
.CurrPtr
->State
== VAR_ADDED
) {
561 // Mark the old variable as in delete transition
563 Variable
.CurrPtr
->State
&= VAR_IN_DELETED_TRANSITION
;
566 } else if (Status
== EFI_NOT_FOUND
) {
568 // Create a new variable
572 // Make sure we are trying to create a new variable.
573 // Setting a data variable with no access, or zero DataSize attributes means to delete it.
575 if (DataSize
== 0 || (Attributes
& (EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_BOOTSERVICE_ACCESS
)) == 0) {
576 Status
= EFI_NOT_FOUND
;
581 // Only variable have NV|RT attribute can be created in Runtime
583 if (EfiAtRuntime () &&
584 (!(Attributes
& EFI_VARIABLE_RUNTIME_ACCESS
) || !(Attributes
& EFI_VARIABLE_NON_VOLATILE
))) {
585 Status
= EFI_INVALID_PARAMETER
;
590 // Status should be EFI_INVALID_PARAMETER here according to return status of FindVariable().
592 ASSERT (Status
== EFI_INVALID_PARAMETER
);
597 // Function part - create a new variable and copy the data.
598 // Both update a variable and create a variable will come here.
601 VarNameOffset
= sizeof (VARIABLE_HEADER
);
602 VarNameSize
= StrSize (VariableName
);
603 VarDataOffset
= VarNameOffset
+ VarNameSize
+ GET_PAD_SIZE (VarNameSize
);
604 VarSize
= VarDataOffset
+ DataSize
+ GET_PAD_SIZE (DataSize
);
606 if (Attributes
& EFI_VARIABLE_NON_VOLATILE
) {
607 if ((UINT32
) (VarSize
+*NonVolatileOffset
) >
608 ((VARIABLE_STORE_HEADER
*) ((UINTN
) (Global
->NonVolatileVariableBase
)))->Size
610 Status
= EFI_OUT_OF_RESOURCES
;
614 NextVariable
= (VARIABLE_HEADER
*) (UINT8
*) (*NonVolatileOffset
+ (UINTN
) Global
->NonVolatileVariableBase
);
615 *NonVolatileOffset
= *NonVolatileOffset
+ VarSize
;
617 if ((UINT32
) (VarSize
+*VolatileOffset
) >
618 ((VARIABLE_STORE_HEADER
*) ((UINTN
) (Global
->VolatileVariableBase
)))->Size
620 Status
= EFI_OUT_OF_RESOURCES
;
624 NextVariable
= (VARIABLE_HEADER
*) (UINT8
*) (*VolatileOffset
+ (UINTN
) Global
->VolatileVariableBase
);
625 *VolatileOffset
= *VolatileOffset
+ VarSize
;
628 NextVariable
->StartId
= VARIABLE_DATA
;
629 NextVariable
->Attributes
= Attributes
;
630 NextVariable
->State
= VAR_ADDED
;
631 NextVariable
->Reserved
= 0;
634 // There will be pad bytes after Data, the NextVariable->NameSize and
635 // NextVariable->NameSize should not include pad size so that variable
636 // service can get actual size in GetVariable
638 NextVariable
->NameSize
= (UINT32
)VarNameSize
;
639 NextVariable
->DataSize
= (UINT32
)DataSize
;
641 CopyMem (&NextVariable
->VendorGuid
, VendorGuid
, sizeof (EFI_GUID
));
643 (UINT8
*) ((UINTN
) NextVariable
+ VarNameOffset
),
648 (UINT8
*) ((UINTN
) NextVariable
+ VarDataOffset
),
654 // Mark the old variable as deleted
656 if (!EFI_ERROR (Status
)) {
657 Variable
.CurrPtr
->State
&= VAR_DELETED
;
660 Status
= EFI_SUCCESS
;
662 ReleaseLockOnlyAtBootTime (&Global
->VariableServicesLock
);
669 IN UINT32 Attributes
,
670 OUT UINT64
*MaximumVariableStorageSize
,
671 OUT UINT64
*RemainingVariableStorageSize
,
672 OUT UINT64
*MaximumVariableSize
,
673 IN VARIABLE_GLOBAL
*Global
,
680 This code returns information about the EFI variables.
684 Attributes Attributes bitmask to specify the type of variables
685 on which to return information.
686 MaximumVariableStorageSize Pointer to the maximum size of the storage space available
687 for the EFI variables associated with the attributes specified.
688 RemainingVariableStorageSize Pointer to the remaining size of the storage space available
689 for EFI variables associated with the attributes specified.
690 MaximumVariableSize Pointer to the maximum size of an individual EFI variables
691 associated with the attributes specified.
692 Global Pointer to VARIABLE_GLOBAL structure.
693 Instance Instance of the Firmware Volume.
698 EFI_INVALID_PARAMETER - An invalid combination of attribute bits was supplied.
699 EFI_SUCCESS - Query successfully.
700 EFI_UNSUPPORTED - The attribute is not supported on this platform.
704 VARIABLE_HEADER
*Variable
;
705 VARIABLE_HEADER
*NextVariable
;
707 VARIABLE_STORE_HEADER
*VariableStoreHeader
;
709 if(MaximumVariableStorageSize
== NULL
|| RemainingVariableStorageSize
== NULL
|| MaximumVariableSize
== NULL
|| Attributes
== 0) {
710 return EFI_INVALID_PARAMETER
;
713 if((Attributes
& (EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_HARDWARE_ERROR_RECORD
)) == 0) {
715 // Make sure the Attributes combination is supported by the platform.
717 return EFI_UNSUPPORTED
;
718 } else if ((Attributes
& (EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_BOOTSERVICE_ACCESS
)) == EFI_VARIABLE_RUNTIME_ACCESS
) {
720 // Make sure if runtime bit is set, boot service bit is set also.
722 return EFI_INVALID_PARAMETER
;
723 } else if (EfiAtRuntime () && !(Attributes
& EFI_VARIABLE_RUNTIME_ACCESS
)) {
725 // Make sure RT Attribute is set if we are in Runtime phase.
727 return EFI_INVALID_PARAMETER
;
730 AcquireLockOnlyAtBootTime(&Global
->VariableServicesLock
);
732 if((Attributes
& EFI_VARIABLE_NON_VOLATILE
) == 0) {
734 // Query is Volatile related.
736 VariableStoreHeader
= (VARIABLE_STORE_HEADER
*) ((UINTN
) Global
->VolatileVariableBase
);
739 // Query is Non-Volatile related.
741 VariableStoreHeader
= (VARIABLE_STORE_HEADER
*) ((UINTN
) Global
->NonVolatileVariableBase
);
745 // Now let's fill *MaximumVariableStorageSize *RemainingVariableStorageSize
746 // with the storage size (excluding the storage header size)
748 *MaximumVariableStorageSize
= VariableStoreHeader
->Size
- sizeof (VARIABLE_STORE_HEADER
);
749 *RemainingVariableStorageSize
= VariableStoreHeader
->Size
- sizeof (VARIABLE_STORE_HEADER
);
752 // Let *MaximumVariableSize be MAX_VARIABLE_SIZE with the exception of the variable header size.
754 *MaximumVariableSize
= MAX_VARIABLE_SIZE
- sizeof (VARIABLE_HEADER
);
757 // Harware error record variable needs larger size.
759 if ((Attributes
& EFI_VARIABLE_HARDWARE_ERROR_RECORD
) == EFI_VARIABLE_HARDWARE_ERROR_RECORD
) {
760 *MaximumVariableSize
= MAX_HARDWARE_ERROR_VARIABLE_SIZE
- sizeof (VARIABLE_HEADER
);
764 // Point to the starting address of the variables.
766 Variable
= (VARIABLE_HEADER
*) (VariableStoreHeader
+ 1);
769 // Now walk through the related variable store.
771 while (Variable
< GetEndPointer (VariableStoreHeader
)) {
772 if (Variable
->StartId
!= VARIABLE_DATA
) {
776 NextVariable
= (VARIABLE_HEADER
*) (GetVariableDataPtr (Variable
) + Variable
->DataSize
+ GET_PAD_SIZE (Variable
->DataSize
));
777 VariableSize
= (UINT64
) (UINTN
) NextVariable
- (UINT64
) (UINTN
) Variable
;
779 if (Variable
->State
== VAR_ADDED
) {
780 *RemainingVariableStorageSize
-= VariableSize
;
784 // Go to the next one.
786 Variable
= NextVariable
;
789 if (*RemainingVariableStorageSize
< sizeof (VARIABLE_HEADER
)) {
790 *MaximumVariableSize
= 0;
791 } else if ((*RemainingVariableStorageSize
- sizeof (VARIABLE_HEADER
)) < *MaximumVariableSize
) {
792 *MaximumVariableSize
= *RemainingVariableStorageSize
- sizeof (VARIABLE_HEADER
);
795 ReleaseLockOnlyAtBootTime (&Global
->VariableServicesLock
);
801 InitializeVariableStore (
802 OUT EFI_PHYSICAL_ADDRESS
*VariableBase
,
803 OUT UINTN
*LastVariableOffset
808 This function initializes variable store
816 VARIABLE_STORE_HEADER
*VariableStore
;
819 // Allocate memory for volatile variable store
821 VariableStore
= (VARIABLE_STORE_HEADER
*) AllocateRuntimePool (
824 if (NULL
== VariableStore
) {
825 return EFI_OUT_OF_RESOURCES
;
828 SetMem (VariableStore
, VARIABLE_STORE_SIZE
, 0xff);
831 // Variable Specific Data
833 *VariableBase
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) VariableStore
;
834 *LastVariableOffset
= sizeof (VARIABLE_STORE_HEADER
);
836 VariableStore
->Signature
= VARIABLE_STORE_SIGNATURE
;
837 VariableStore
->Size
= VARIABLE_STORE_SIZE
;
838 VariableStore
->Format
= VARIABLE_STORE_FORMATTED
;
839 VariableStore
->State
= VARIABLE_STORE_HEALTHY
;
840 VariableStore
->Reserved
= 0;
841 VariableStore
->Reserved1
= 0;
848 VariableCommonInitialize (
849 IN EFI_HANDLE ImageHandle
,
850 IN EFI_SYSTEM_TABLE
*SystemTable
855 This function does common initialization for variable services
866 // Allocate memory for mVariableModuleGlobal
868 mVariableModuleGlobal
= (ESAL_VARIABLE_GLOBAL
*) AllocateRuntimePool (
869 sizeof (ESAL_VARIABLE_GLOBAL
)
871 if (NULL
== mVariableModuleGlobal
) {
872 return EFI_OUT_OF_RESOURCES
;
875 EfiInitializeLock(&mVariableModuleGlobal
->VariableGlobal
[Physical
].VariableServicesLock
, TPL_NOTIFY
);
878 // Intialize volatile variable store
880 Status
= InitializeVariableStore (
881 &mVariableModuleGlobal
->VariableGlobal
[Physical
].VolatileVariableBase
,
882 &mVariableModuleGlobal
->VolatileLastVariableOffset
885 if (EFI_ERROR (Status
)) {
889 // Intialize non volatile variable store
891 Status
= InitializeVariableStore (
892 &mVariableModuleGlobal
->VariableGlobal
[Physical
].NonVolatileVariableBase
,
893 &mVariableModuleGlobal
->NonVolatileLastVariableOffset