3 Copyright (c) 2006 - 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
25 // Don't use module globals after the SetVirtualAddress map is signaled
27 ESAL_VARIABLE_GLOBAL
*mVariableModuleGlobal
;
30 // This is a temperary function which will be removed
31 // when EfiAcquireLock in UefiLib can handle the
32 // the call in UEFI Runtimer driver in RT phase.
36 AcquireLockOnlyAtBootTime (
40 if (!EfiAtRuntime ()) {
41 EfiAcquireLock (Lock
);
46 // This is a temperary function which will be removed
47 // when EfiAcquireLock in UefiLib can handle the
48 // the call in UEFI Runtimer driver in RT phase.
52 ReleaseLockOnlyAtBootTime (
56 if (!EfiAtRuntime ()) {
57 EfiReleaseLock (Lock
);
64 IN VARIABLE_HEADER
*Variable
70 This code gets the pointer to the variable data.
74 Variable Pointer to the Variable Header.
78 UINT8* Pointer to Variable Data
82 if (Variable
->StartId
!= VARIABLE_DATA
) {
86 // Be careful about pad size for alignment
88 return (UINT8
*) ((UINTN
) GET_VARIABLE_NAME_PTR (Variable
) + Variable
->NameSize
+ GET_PAD_SIZE (Variable
->NameSize
));
94 IN VARIABLE_HEADER
*Variable
100 This code gets the pointer to the next variable header.
104 Variable Pointer to the Variable Header.
108 VARIABLE_HEADER* Pointer to next variable header.
112 VARIABLE_HEADER
*VarHeader
;
114 if (Variable
->StartId
!= VARIABLE_DATA
) {
118 // Be careful about pad size for alignment
120 VarHeader
= (VARIABLE_HEADER
*) (GetVariableDataPtr (Variable
) + Variable
->DataSize
+ GET_PAD_SIZE (Variable
->DataSize
));
122 if (VarHeader
->StartId
!= VARIABLE_DATA
||
123 (sizeof (VARIABLE_HEADER
) + VarHeader
->DataSize
+ VarHeader
->NameSize
) > MAX_VARIABLE_SIZE
134 IN VARIABLE_STORE_HEADER
*VolHeader
140 This code gets the pointer to the last variable memory pointer byte
144 Variable Pointer to the Variable Header.
148 VARIABLE_HEADER* Pointer to last unavailable Variable Header
153 // The end of variable store
155 return (VARIABLE_HEADER
*) ((UINTN
) VolHeader
+ VolHeader
->Size
);
161 IN CHAR16
*VariableName
,
162 IN EFI_GUID
*VendorGuid
,
163 OUT VARIABLE_POINTER_TRACK
*PtrTrack
,
164 IN VARIABLE_GLOBAL
*Global
170 This code finds variable in storage blocks (Volatile or Non-Volatile)
174 VariableName Name of the variable to be found
175 VendorGuid Vendor GUID to be found.
176 PtrTrack Variable Track Pointer structure that contains
177 Variable Information.
178 Contains the pointer of Variable header.
179 Global VARIABLE_GLOBAL pointer
187 VARIABLE_HEADER
*Variable
[2];
188 VARIABLE_STORE_HEADER
*VariableStoreHeader
[2];
192 // We aquire the lock at the entry of FindVariable as GetVariable, GetNextVariableName
193 // SetVariable all call FindVariable at entry point. Please move "Aquire Lock" to
194 // the correct places if this assumption does not hold TRUE anymore.
196 AcquireLockOnlyAtBootTime(&Global
->VariableServicesLock
);
199 // 0: Non-Volatile, 1: Volatile
201 VariableStoreHeader
[0] = (VARIABLE_STORE_HEADER
*) ((UINTN
) Global
->NonVolatileVariableBase
);
202 VariableStoreHeader
[1] = (VARIABLE_STORE_HEADER
*) ((UINTN
) Global
->VolatileVariableBase
);
205 // Start Pointers for the variable.
206 // Actual Data Pointer where data can be written.
208 Variable
[0] = (VARIABLE_HEADER
*) (VariableStoreHeader
[0] + 1);
209 Variable
[1] = (VARIABLE_HEADER
*) (VariableStoreHeader
[1] + 1);
211 if (VariableName
[0] != 0 && VendorGuid
== NULL
) {
212 return EFI_INVALID_PARAMETER
;
215 // Find the variable by walk through non-volatile and volatile variable store
217 for (Index
= 0; Index
< 2; Index
++) {
218 PtrTrack
->StartPtr
= (VARIABLE_HEADER
*) (VariableStoreHeader
[Index
] + 1);
219 PtrTrack
->EndPtr
= GetEndPointer (VariableStoreHeader
[Index
]);
221 while ((Variable
[Index
] != NULL
) && (Variable
[Index
] <= GetEndPointer (VariableStoreHeader
[Index
]))) {
222 if (Variable
[Index
]->StartId
== VARIABLE_DATA
&& Variable
[Index
]->State
== VAR_ADDED
) {
223 if (!(EfiAtRuntime () && !(Variable
[Index
]->Attributes
& EFI_VARIABLE_RUNTIME_ACCESS
))) {
224 if (VariableName
[0] == 0) {
225 PtrTrack
->CurrPtr
= Variable
[Index
];
226 PtrTrack
->Volatile
= (BOOLEAN
) Index
;
229 if (CompareGuid (VendorGuid
, &Variable
[Index
]->VendorGuid
)) {
230 if (!CompareMem (VariableName
, GET_VARIABLE_NAME_PTR (Variable
[Index
]), Variable
[Index
]->NameSize
)) {
231 PtrTrack
->CurrPtr
= Variable
[Index
];
232 PtrTrack
->Volatile
= (BOOLEAN
) Index
;
240 Variable
[Index
] = GetNextVariablePtr (Variable
[Index
]);
243 PtrTrack
->CurrPtr
= NULL
;
244 return EFI_NOT_FOUND
;
250 IN CHAR16
*VariableName
,
251 IN EFI_GUID
* VendorGuid
,
252 OUT UINT32
*Attributes OPTIONAL
,
253 IN OUT UINTN
*DataSize
,
255 IN VARIABLE_GLOBAL
* Global
,
262 This code finds variable in storage blocks (Volatile or Non-Volatile)
266 VariableName Name of Variable to be found
267 VendorGuid Variable vendor GUID
268 Attributes OPTIONAL Attribute value of the variable found
269 DataSize Size of Data found. If size is less than the
270 data, this value contains the required size.
272 Global Pointer to VARIABLE_GLOBAL structure
273 Instance Instance of the Firmware Volume.
277 EFI_INVALID_PARAMETER - Invalid parameter
278 EFI_SUCCESS - Find the specified variable
279 EFI_NOT_FOUND - Not found
280 EFI_BUFFER_TO_SMALL - DataSize is too small for the result
285 VARIABLE_POINTER_TRACK Variable
;
289 if (VariableName
== NULL
|| VendorGuid
== NULL
|| DataSize
== NULL
) {
290 return EFI_INVALID_PARAMETER
;
293 // Find existing variable
295 Status
= FindVariable (VariableName
, VendorGuid
, &Variable
, Global
);
297 if (Variable
.CurrPtr
== NULL
|| EFI_ERROR (Status
)) {
303 VarDataSize
= Variable
.CurrPtr
->DataSize
;
304 if (*DataSize
>= VarDataSize
) {
306 Status
= EFI_INVALID_PARAMETER
;
310 CopyMem (Data
, GetVariableDataPtr (Variable
.CurrPtr
), VarDataSize
);
311 if (Attributes
!= NULL
) {
312 *Attributes
= Variable
.CurrPtr
->Attributes
;
315 *DataSize
= VarDataSize
;
316 Status
= EFI_SUCCESS
;
319 *DataSize
= VarDataSize
;
320 Status
= EFI_BUFFER_TOO_SMALL
;
325 ReleaseLockOnlyAtBootTime (&Global
->VariableServicesLock
);
331 GetNextVariableName (
332 IN OUT UINTN
*VariableNameSize
,
333 IN OUT CHAR16
*VariableName
,
334 IN OUT EFI_GUID
*VendorGuid
,
335 IN VARIABLE_GLOBAL
*Global
,
342 This code Finds the Next available variable
346 VariableNameSize Size of the variable
347 VariableName Pointer to variable name
348 VendorGuid Variable Vendor Guid
349 Global VARIABLE_GLOBAL structure pointer.
358 VARIABLE_POINTER_TRACK Variable
;
362 if (VariableNameSize
== NULL
|| VariableName
== NULL
|| VendorGuid
== NULL
) {
363 return EFI_INVALID_PARAMETER
;
366 Status
= FindVariable (VariableName
, VendorGuid
, &Variable
, Global
);
368 if (Variable
.CurrPtr
== NULL
|| EFI_ERROR (Status
)) {
373 if (VariableName
[0] != 0) {
375 // If variable name is not NULL, get next variable
377 Variable
.CurrPtr
= GetNextVariablePtr (Variable
.CurrPtr
);
380 // If both volatile and non-volatile variable store are parsed,
383 if (Variable
.CurrPtr
>= Variable
.EndPtr
|| Variable
.CurrPtr
== NULL
) {
384 Variable
.Volatile
= (BOOLEAN
) (Variable
.Volatile
^ ((BOOLEAN
) 0x1));
385 if (Variable
.Volatile
) {
386 Variable
.StartPtr
= (VARIABLE_HEADER
*) ((UINTN
) (Global
->VolatileVariableBase
+ sizeof (VARIABLE_STORE_HEADER
)));
387 Variable
.EndPtr
= (VARIABLE_HEADER
*) GetEndPointer ((VARIABLE_STORE_HEADER
*) ((UINTN
) Global
->VolatileVariableBase
));
389 Status
= EFI_NOT_FOUND
;
393 Variable
.CurrPtr
= Variable
.StartPtr
;
394 if (Variable
.CurrPtr
->StartId
!= VARIABLE_DATA
) {
401 if (Variable
.CurrPtr
->StartId
== VARIABLE_DATA
&& Variable
.CurrPtr
->State
== VAR_ADDED
) {
402 if (!(EfiAtRuntime () && !(Variable
.CurrPtr
->Attributes
& EFI_VARIABLE_RUNTIME_ACCESS
))) {
403 VarNameSize
= Variable
.CurrPtr
->NameSize
;
404 if (VarNameSize
<= *VariableNameSize
) {
407 GET_VARIABLE_NAME_PTR (Variable
.CurrPtr
),
412 &Variable
.CurrPtr
->VendorGuid
,
415 Status
= EFI_SUCCESS
;
417 Status
= EFI_BUFFER_TOO_SMALL
;
420 *VariableNameSize
= VarNameSize
;
427 ReleaseLockOnlyAtBootTime (&Global
->VariableServicesLock
);
435 IN CHAR16
*VariableName
,
436 IN EFI_GUID
*VendorGuid
,
437 IN UINT32 Attributes
,
440 IN VARIABLE_GLOBAL
*Global
,
441 IN UINTN
*VolatileOffset
,
442 IN UINTN
*NonVolatileOffset
,
449 This code sets variable in storage blocks (Volatile or Non-Volatile)
453 VariableName Name of Variable to be found
454 VendorGuid Variable vendor GUID
455 Attributes Attribute value of the variable found
456 DataSize Size of Data found. If size is less than the
457 data, this value contains the required size.
459 Global Pointer to VARIABLE_GLOBAL structure
460 VolatileOffset The offset of last volatile variable
461 NonVolatileOffset The offset of last non-volatile variable
462 Instance Instance of the Firmware Volume.
466 EFI_INVALID_PARAMETER - Invalid parameter
467 EFI_SUCCESS - Set successfully
468 EFI_OUT_OF_RESOURCES - Resource not enough to set variable
469 EFI_NOT_FOUND - Not found
470 EFI_DEVICE_ERROR - Variable can not be saved due to hardware failure
471 EFI_WRITE_PROTECTED - Variable is read-only
475 VARIABLE_POINTER_TRACK Variable
;
477 VARIABLE_HEADER
*NextVariable
;
484 // Check input parameters
486 if (VariableName
== NULL
|| VariableName
[0] == 0 || VendorGuid
== NULL
) {
487 return EFI_INVALID_PARAMETER
;
490 // Make sure if runtime bit is set, boot service bit is set also
492 if ((Attributes
& (EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_BOOTSERVICE_ACCESS
)) == EFI_VARIABLE_RUNTIME_ACCESS
) {
493 return EFI_INVALID_PARAMETER
;
496 // The size of the VariableName, including the Unicode Null in bytes plus
497 // the DataSize is limited to maximum size of MAX_HARDWARE_ERROR_VARIABLE_SIZE (32K)
498 // bytes for HwErrRec, and MAX_VARIABLE_SIZE (1024) bytes for the others.
500 if ((Attributes
& EFI_VARIABLE_HARDWARE_ERROR_RECORD
) == EFI_VARIABLE_HARDWARE_ERROR_RECORD
) {
501 if ((DataSize
> MAX_HARDWARE_ERROR_VARIABLE_SIZE
) ||
502 (sizeof (VARIABLE_HEADER
) + StrSize (VariableName
) + DataSize
> MAX_HARDWARE_ERROR_VARIABLE_SIZE
)) {
503 return EFI_INVALID_PARAMETER
;
507 // The size of the VariableName, including the Unicode Null in bytes plus
508 // the DataSize is limited to maximum size of MAX_VARIABLE_SIZE (1024) bytes.
510 if ((DataSize
> MAX_VARIABLE_SIZE
) ||
511 (sizeof (VARIABLE_HEADER
) + StrSize (VariableName
) + DataSize
> MAX_VARIABLE_SIZE
)) {
512 return EFI_INVALID_PARAMETER
;
516 // Check whether the input variable is already existed
519 Status
= FindVariable (VariableName
, VendorGuid
, &Variable
, Global
);
521 if (Status
== EFI_SUCCESS
&& Variable
.CurrPtr
!= NULL
) {
523 // Update/Delete existing variable
526 if (EfiAtRuntime ()) {
528 // If EfiAtRuntime and the variable is Volatile and Runtime Access,
529 // the volatile is ReadOnly, and SetVariable should be aborted and
530 // return EFI_WRITE_PROTECTED.
532 if (Variable
.Volatile
) {
533 Status
= EFI_WRITE_PROTECTED
;
537 // Only variable have NV attribute can be updated/deleted in Runtime
539 if (!(Variable
.CurrPtr
->Attributes
& EFI_VARIABLE_NON_VOLATILE
)) {
540 Status
= EFI_INVALID_PARAMETER
;
546 // Setting a data variable with no access, or zero DataSize attributes
547 // specified causes it to be deleted.
549 if (DataSize
== 0 || (Attributes
& (EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_BOOTSERVICE_ACCESS
)) == 0) {
550 Variable
.CurrPtr
->State
&= VAR_DELETED
;
551 Status
= EFI_SUCCESS
;
556 // If the variable is marked valid and the same data has been passed in
557 // then return to the caller immediately.
559 if (Variable
.CurrPtr
->DataSize
== DataSize
&&
560 !CompareMem (Data
, GetVariableDataPtr (Variable
.CurrPtr
), DataSize
)
562 Status
= EFI_SUCCESS
;
564 } else if (Variable
.CurrPtr
->State
== VAR_ADDED
) {
566 // Mark the old variable as in delete transition
568 Variable
.CurrPtr
->State
&= VAR_IN_DELETED_TRANSITION
;
571 } else if (Status
== EFI_NOT_FOUND
) {
573 // Create a new variable
577 // Make sure we are trying to create a new variable.
578 // Setting a data variable with no access, or zero DataSize attributes means to delete it.
580 if (DataSize
== 0 || (Attributes
& (EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_BOOTSERVICE_ACCESS
)) == 0) {
581 Status
= EFI_NOT_FOUND
;
586 // Only variable have NV|RT attribute can be created in Runtime
588 if (EfiAtRuntime () &&
589 (!(Attributes
& EFI_VARIABLE_RUNTIME_ACCESS
) || !(Attributes
& EFI_VARIABLE_NON_VOLATILE
))) {
590 Status
= EFI_INVALID_PARAMETER
;
595 // Status should be EFI_INVALID_PARAMETER here according to return status of FindVariable().
597 ASSERT (Status
== EFI_INVALID_PARAMETER
);
602 // Function part - create a new variable and copy the data.
603 // Both update a variable and create a variable will come here.
606 VarNameOffset
= sizeof (VARIABLE_HEADER
);
607 VarNameSize
= StrSize (VariableName
);
608 VarDataOffset
= VarNameOffset
+ VarNameSize
+ GET_PAD_SIZE (VarNameSize
);
609 VarSize
= VarDataOffset
+ DataSize
+ GET_PAD_SIZE (DataSize
);
611 if (Attributes
& EFI_VARIABLE_NON_VOLATILE
) {
612 if ((UINT32
) (VarSize
+*NonVolatileOffset
) >
613 ((VARIABLE_STORE_HEADER
*) ((UINTN
) (Global
->NonVolatileVariableBase
)))->Size
615 Status
= EFI_OUT_OF_RESOURCES
;
619 NextVariable
= (VARIABLE_HEADER
*) (UINT8
*) (*NonVolatileOffset
+ (UINTN
) Global
->NonVolatileVariableBase
);
620 *NonVolatileOffset
= *NonVolatileOffset
+ VarSize
;
622 if ((UINT32
) (VarSize
+*VolatileOffset
) >
623 ((VARIABLE_STORE_HEADER
*) ((UINTN
) (Global
->VolatileVariableBase
)))->Size
625 Status
= EFI_OUT_OF_RESOURCES
;
629 NextVariable
= (VARIABLE_HEADER
*) (UINT8
*) (*VolatileOffset
+ (UINTN
) Global
->VolatileVariableBase
);
630 *VolatileOffset
= *VolatileOffset
+ VarSize
;
633 NextVariable
->StartId
= VARIABLE_DATA
;
634 NextVariable
->Attributes
= Attributes
;
635 NextVariable
->State
= VAR_ADDED
;
636 NextVariable
->Reserved
= 0;
639 // There will be pad bytes after Data, the NextVariable->NameSize and
640 // NextVariable->NameSize should not include pad size so that variable
641 // service can get actual size in GetVariable
643 NextVariable
->NameSize
= (UINT32
)VarNameSize
;
644 NextVariable
->DataSize
= (UINT32
)DataSize
;
646 CopyMem (&NextVariable
->VendorGuid
, VendorGuid
, sizeof (EFI_GUID
));
648 (UINT8
*) ((UINTN
) NextVariable
+ VarNameOffset
),
653 (UINT8
*) ((UINTN
) NextVariable
+ VarDataOffset
),
659 // Mark the old variable as deleted
661 if (!EFI_ERROR (Status
)) {
662 Variable
.CurrPtr
->State
&= VAR_DELETED
;
665 Status
= EFI_SUCCESS
;
667 ReleaseLockOnlyAtBootTime (&Global
->VariableServicesLock
);
674 IN UINT32 Attributes
,
675 OUT UINT64
*MaximumVariableStorageSize
,
676 OUT UINT64
*RemainingVariableStorageSize
,
677 OUT UINT64
*MaximumVariableSize
,
678 IN VARIABLE_GLOBAL
*Global
,
685 This code returns information about the EFI variables.
689 Attributes Attributes bitmask to specify the type of variables
690 on which to return information.
691 MaximumVariableStorageSize Pointer to the maximum size of the storage space available
692 for the EFI variables associated with the attributes specified.
693 RemainingVariableStorageSize Pointer to the remaining size of the storage space available
694 for EFI variables associated with the attributes specified.
695 MaximumVariableSize Pointer to the maximum size of an individual EFI variables
696 associated with the attributes specified.
697 Global Pointer to VARIABLE_GLOBAL structure.
698 Instance Instance of the Firmware Volume.
703 EFI_INVALID_PARAMETER - An invalid combination of attribute bits was supplied.
704 EFI_SUCCESS - Query successfully.
705 EFI_UNSUPPORTED - The attribute is not supported on this platform.
709 VARIABLE_HEADER
*Variable
;
710 VARIABLE_HEADER
*NextVariable
;
712 VARIABLE_STORE_HEADER
*VariableStoreHeader
;
714 if(MaximumVariableStorageSize
== NULL
|| RemainingVariableStorageSize
== NULL
|| MaximumVariableSize
== NULL
|| Attributes
== 0) {
715 return EFI_INVALID_PARAMETER
;
718 if((Attributes
& (EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_HARDWARE_ERROR_RECORD
)) == 0) {
720 // Make sure the Attributes combination is supported by the platform.
722 return EFI_UNSUPPORTED
;
723 } else if ((Attributes
& (EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_BOOTSERVICE_ACCESS
)) == EFI_VARIABLE_RUNTIME_ACCESS
) {
725 // Make sure if runtime bit is set, boot service bit is set also.
727 return EFI_INVALID_PARAMETER
;
728 } else if (EfiAtRuntime () && !(Attributes
& EFI_VARIABLE_RUNTIME_ACCESS
)) {
730 // Make sure RT Attribute is set if we are in Runtime phase.
732 return EFI_INVALID_PARAMETER
;
733 } else if (EfiAtRuntime () && Attributes
&& !(Attributes
& EFI_VARIABLE_NON_VOLATILE
)) {
735 // Cannot Query volatile variable in Runtime
737 return EFI_INVALID_PARAMETER
;
740 AcquireLockOnlyAtBootTime(&Global
->VariableServicesLock
);
742 if((Attributes
& EFI_VARIABLE_NON_VOLATILE
) == 0) {
744 // Query is Volatile related.
746 VariableStoreHeader
= (VARIABLE_STORE_HEADER
*) ((UINTN
) Global
->VolatileVariableBase
);
749 // Query is Non-Volatile related.
751 VariableStoreHeader
= (VARIABLE_STORE_HEADER
*) ((UINTN
) Global
->NonVolatileVariableBase
);
755 // Now let's fill *MaximumVariableStorageSize *RemainingVariableStorageSize
756 // with the storage size (excluding the storage header size)
758 *MaximumVariableStorageSize
= VariableStoreHeader
->Size
- sizeof (VARIABLE_STORE_HEADER
);
759 *RemainingVariableStorageSize
= VariableStoreHeader
->Size
- sizeof (VARIABLE_STORE_HEADER
);
762 // Let *MaximumVariableSize be MAX_VARIABLE_SIZE with the exception of the variable header size.
764 *MaximumVariableSize
= MAX_VARIABLE_SIZE
- sizeof (VARIABLE_HEADER
);
767 // Harware error record variable needs larger size.
769 if ((Attributes
& EFI_VARIABLE_HARDWARE_ERROR_RECORD
) == EFI_VARIABLE_HARDWARE_ERROR_RECORD
) {
770 *MaximumVariableSize
= MAX_HARDWARE_ERROR_VARIABLE_SIZE
- sizeof (VARIABLE_HEADER
);
774 // Point to the starting address of the variables.
776 Variable
= (VARIABLE_HEADER
*) (VariableStoreHeader
+ 1);
779 // Now walk through the related variable store.
781 while (Variable
< GetEndPointer (VariableStoreHeader
)) {
782 if (Variable
->StartId
!= VARIABLE_DATA
) {
786 NextVariable
= (VARIABLE_HEADER
*) (GetVariableDataPtr (Variable
) + Variable
->DataSize
+ GET_PAD_SIZE (Variable
->DataSize
));
787 VariableSize
= (UINT64
) (UINTN
) NextVariable
- (UINT64
) (UINTN
) Variable
;
789 if (Variable
->State
== VAR_ADDED
) {
790 *RemainingVariableStorageSize
-= VariableSize
;
794 // Go to the next one.
796 Variable
= NextVariable
;
799 if (*RemainingVariableStorageSize
< sizeof (VARIABLE_HEADER
)) {
800 *MaximumVariableSize
= 0;
801 } else if ((*RemainingVariableStorageSize
- sizeof (VARIABLE_HEADER
)) < *MaximumVariableSize
) {
802 *MaximumVariableSize
= *RemainingVariableStorageSize
- sizeof (VARIABLE_HEADER
);
805 ReleaseLockOnlyAtBootTime (&Global
->VariableServicesLock
);
811 InitializeVariableStore (
812 OUT EFI_PHYSICAL_ADDRESS
*VariableBase
,
813 OUT UINTN
*LastVariableOffset
818 This function initializes variable store
826 VARIABLE_STORE_HEADER
*VariableStore
;
829 // Allocate memory for volatile variable store
831 VariableStore
= (VARIABLE_STORE_HEADER
*) AllocateRuntimePool (
834 if (NULL
== VariableStore
) {
835 return EFI_OUT_OF_RESOURCES
;
838 SetMem (VariableStore
, VARIABLE_STORE_SIZE
, 0xff);
841 // Variable Specific Data
843 *VariableBase
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) VariableStore
;
844 *LastVariableOffset
= sizeof (VARIABLE_STORE_HEADER
);
846 VariableStore
->Signature
= VARIABLE_STORE_SIGNATURE
;
847 VariableStore
->Size
= VARIABLE_STORE_SIZE
;
848 VariableStore
->Format
= VARIABLE_STORE_FORMATTED
;
849 VariableStore
->State
= VARIABLE_STORE_HEALTHY
;
850 VariableStore
->Reserved
= 0;
851 VariableStore
->Reserved1
= 0;
858 VariableCommonInitialize (
859 IN EFI_HANDLE ImageHandle
,
860 IN EFI_SYSTEM_TABLE
*SystemTable
865 This function does common initialization for variable services
876 // Allocate memory for mVariableModuleGlobal
878 mVariableModuleGlobal
= (ESAL_VARIABLE_GLOBAL
*) AllocateRuntimePool (
879 sizeof (ESAL_VARIABLE_GLOBAL
)
881 if (NULL
== mVariableModuleGlobal
) {
882 return EFI_OUT_OF_RESOURCES
;
885 EfiInitializeLock(&mVariableModuleGlobal
->VariableGlobal
[Physical
].VariableServicesLock
, TPL_NOTIFY
);
888 // Intialize volatile variable store
890 Status
= InitializeVariableStore (
891 &mVariableModuleGlobal
->VariableGlobal
[Physical
].VolatileVariableBase
,
892 &mVariableModuleGlobal
->VolatileLastVariableOffset
895 if (EFI_ERROR (Status
)) {
899 // Intialize non volatile variable store
901 Status
= InitializeVariableStore (
902 &mVariableModuleGlobal
->VariableGlobal
[Physical
].NonVolatileVariableBase
,
903 &mVariableModuleGlobal
->NonVolatileLastVariableOffset