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.
30 AcquireLockOnlyAtBootTime (
34 if (!EfiAtRuntime ()) {
35 EfiAcquireLock (Lock
);
40 // This is a temperary function which will be removed
41 // when EfiAcquireLock in UefiLib can handle the
42 // the call in UEFI Runtimer driver in RT phase.
45 ReleaseLockOnlyAtBootTime (
49 if (!EfiAtRuntime ()) {
50 EfiReleaseLock (Lock
);
56 IN VARIABLE_HEADER
*Variable
62 This code gets the pointer to the variable data.
66 Variable Pointer to the Variable Header.
70 UINT8* Pointer to Variable Data
74 if (Variable
->StartId
!= VARIABLE_DATA
) {
78 // Be careful about pad size for alignment
80 return (UINT8
*) ((UINTN
) GET_VARIABLE_NAME_PTR (Variable
) + Variable
->NameSize
+ GET_PAD_SIZE (Variable
->NameSize
));
85 IN VARIABLE_HEADER
*Variable
91 This code gets the pointer to the next variable header.
95 Variable Pointer to the Variable Header.
99 VARIABLE_HEADER* Pointer to next variable header.
103 VARIABLE_HEADER
*VarHeader
;
105 if (Variable
->StartId
!= VARIABLE_DATA
) {
109 // Be careful about pad size for alignment
111 VarHeader
= (VARIABLE_HEADER
*) (GetVariableDataPtr (Variable
) + Variable
->DataSize
+ GET_PAD_SIZE (Variable
->DataSize
));
113 if (VarHeader
->StartId
!= VARIABLE_DATA
||
114 (sizeof (VARIABLE_HEADER
) + VarHeader
->DataSize
+ VarHeader
->NameSize
) > MAX_VARIABLE_SIZE
124 IN VARIABLE_STORE_HEADER
*VolHeader
130 This code gets the pointer to the last variable memory pointer byte
134 Variable Pointer to the Variable Header.
138 VARIABLE_HEADER* Pointer to last unavailable Variable Header
143 // The end of variable store
145 return (VARIABLE_HEADER
*) ((UINTN
) VolHeader
+ VolHeader
->Size
);
150 IN CHAR16
*VariableName
,
151 IN EFI_GUID
*VendorGuid
,
152 OUT VARIABLE_POINTER_TRACK
*PtrTrack
,
153 IN VARIABLE_GLOBAL
*Global
159 This code finds variable in storage blocks (Volatile or Non-Volatile)
163 VariableName Name of the variable to be found
164 VendorGuid Vendor GUID to be found.
165 PtrTrack Variable Track Pointer structure that contains
166 Variable Information.
167 Contains the pointer of Variable header.
168 Global VARIABLE_GLOBAL pointer
176 VARIABLE_HEADER
*Variable
[2];
177 VARIABLE_STORE_HEADER
*VariableStoreHeader
[2];
181 // We aquire the lock at the entry of FindVariable as GetVariable, GetNextVariableName
182 // SetVariable all call FindVariable at entry point. Please move "Aquire Lock" to
183 // the correct places if this assumption does not hold TRUE anymore.
185 AcquireLockOnlyAtBootTime(&Global
->VariableServicesLock
);
188 // 0: Non-Volatile, 1: Volatile
190 VariableStoreHeader
[0] = (VARIABLE_STORE_HEADER
*) ((UINTN
) Global
->NonVolatileVariableBase
);
191 VariableStoreHeader
[1] = (VARIABLE_STORE_HEADER
*) ((UINTN
) Global
->VolatileVariableBase
);
194 // Start Pointers for the variable.
195 // Actual Data Pointer where data can be written.
197 Variable
[0] = (VARIABLE_HEADER
*) (VariableStoreHeader
[0] + 1);
198 Variable
[1] = (VARIABLE_HEADER
*) (VariableStoreHeader
[1] + 1);
200 if (VariableName
[0] != 0 && VendorGuid
== NULL
) {
201 return EFI_INVALID_PARAMETER
;
204 // Find the variable by walk through non-volatile and volatile variable store
206 for (Index
= 0; Index
< 2; Index
++) {
207 PtrTrack
->StartPtr
= (VARIABLE_HEADER
*) (VariableStoreHeader
[Index
] + 1);
208 PtrTrack
->EndPtr
= GetEndPointer (VariableStoreHeader
[Index
]);
210 while ((Variable
[Index
] != NULL
) && (Variable
[Index
] <= GetEndPointer (VariableStoreHeader
[Index
]))) {
211 if (Variable
[Index
]->StartId
== VARIABLE_DATA
&& Variable
[Index
]->State
== VAR_ADDED
) {
212 if (!(EfiAtRuntime () && !(Variable
[Index
]->Attributes
& EFI_VARIABLE_RUNTIME_ACCESS
))) {
213 if (VariableName
[0] == 0) {
214 PtrTrack
->CurrPtr
= Variable
[Index
];
215 PtrTrack
->Volatile
= (BOOLEAN
) Index
;
218 if (CompareGuid (VendorGuid
, &Variable
[Index
]->VendorGuid
)) {
219 if (!CompareMem (VariableName
, GET_VARIABLE_NAME_PTR (Variable
[Index
]), Variable
[Index
]->NameSize
)) {
220 PtrTrack
->CurrPtr
= Variable
[Index
];
221 PtrTrack
->Volatile
= (BOOLEAN
) Index
;
229 Variable
[Index
] = GetNextVariablePtr (Variable
[Index
]);
232 PtrTrack
->CurrPtr
= NULL
;
233 return EFI_NOT_FOUND
;
239 IN CHAR16
*VariableName
,
240 IN EFI_GUID
* VendorGuid
,
241 OUT UINT32
*Attributes OPTIONAL
,
242 IN OUT UINTN
*DataSize
,
244 IN VARIABLE_GLOBAL
* Global
,
251 This code finds variable in storage blocks (Volatile or Non-Volatile)
255 VariableName Name of Variable to be found
256 VendorGuid Variable vendor GUID
257 Attributes OPTIONAL Attribute value of the variable found
258 DataSize Size of Data found. If size is less than the
259 data, this value contains the required size.
261 Global Pointer to VARIABLE_GLOBAL structure
262 Instance Instance of the Firmware Volume.
266 EFI_INVALID_PARAMETER - Invalid parameter
267 EFI_SUCCESS - Find the specified variable
268 EFI_NOT_FOUND - Not found
269 EFI_BUFFER_TO_SMALL - DataSize is too small for the result
274 VARIABLE_POINTER_TRACK Variable
;
278 if (VariableName
== NULL
|| VendorGuid
== NULL
|| DataSize
== NULL
) {
279 return EFI_INVALID_PARAMETER
;
282 // Find existing variable
284 Status
= FindVariable (VariableName
, VendorGuid
, &Variable
, Global
);
286 if (Variable
.CurrPtr
== NULL
|| EFI_ERROR (Status
)) {
292 VarDataSize
= Variable
.CurrPtr
->DataSize
;
293 if (*DataSize
>= VarDataSize
) {
295 Status
= EFI_INVALID_PARAMETER
;
299 CopyMem (Data
, GetVariableDataPtr (Variable
.CurrPtr
), VarDataSize
);
300 if (Attributes
!= NULL
) {
301 *Attributes
= Variable
.CurrPtr
->Attributes
;
304 *DataSize
= VarDataSize
;
305 Status
= EFI_SUCCESS
;
308 *DataSize
= VarDataSize
;
309 Status
= EFI_BUFFER_TOO_SMALL
;
314 ReleaseLockOnlyAtBootTime (&Global
->VariableServicesLock
);
320 GetNextVariableName (
321 IN OUT UINTN
*VariableNameSize
,
322 IN OUT CHAR16
*VariableName
,
323 IN OUT EFI_GUID
*VendorGuid
,
324 IN VARIABLE_GLOBAL
*Global
,
331 This code Finds the Next available variable
335 VariableNameSize Size of the variable
336 VariableName Pointer to variable name
337 VendorGuid Variable Vendor Guid
338 Global VARIABLE_GLOBAL structure pointer.
347 VARIABLE_POINTER_TRACK Variable
;
351 if (VariableNameSize
== NULL
|| VariableName
== NULL
|| VendorGuid
== NULL
) {
352 return EFI_INVALID_PARAMETER
;
355 Status
= FindVariable (VariableName
, VendorGuid
, &Variable
, Global
);
357 if (Variable
.CurrPtr
== NULL
|| EFI_ERROR (Status
)) {
362 if (VariableName
[0] != 0) {
364 // If variable name is not NULL, get next variable
366 Variable
.CurrPtr
= GetNextVariablePtr (Variable
.CurrPtr
);
369 // If both volatile and non-volatile variable store are parsed,
372 if (Variable
.CurrPtr
>= Variable
.EndPtr
|| Variable
.CurrPtr
== NULL
) {
373 Variable
.Volatile
= (BOOLEAN
) (Variable
.Volatile
^ ((BOOLEAN
) 0x1));
374 if (Variable
.Volatile
) {
375 Variable
.StartPtr
= (VARIABLE_HEADER
*) ((UINTN
) (Global
->VolatileVariableBase
+ sizeof (VARIABLE_STORE_HEADER
)));
376 Variable
.EndPtr
= (VARIABLE_HEADER
*) GetEndPointer ((VARIABLE_STORE_HEADER
*) ((UINTN
) Global
->VolatileVariableBase
));
378 Status
= EFI_NOT_FOUND
;
382 Variable
.CurrPtr
= Variable
.StartPtr
;
383 if (Variable
.CurrPtr
->StartId
!= VARIABLE_DATA
) {
390 if (Variable
.CurrPtr
->StartId
== VARIABLE_DATA
&& Variable
.CurrPtr
->State
== VAR_ADDED
) {
391 if (!(EfiAtRuntime () && !(Variable
.CurrPtr
->Attributes
& EFI_VARIABLE_RUNTIME_ACCESS
))) {
392 VarNameSize
= Variable
.CurrPtr
->NameSize
;
393 if (VarNameSize
<= *VariableNameSize
) {
396 GET_VARIABLE_NAME_PTR (Variable
.CurrPtr
),
401 &Variable
.CurrPtr
->VendorGuid
,
404 Status
= EFI_SUCCESS
;
406 Status
= EFI_BUFFER_TOO_SMALL
;
409 *VariableNameSize
= VarNameSize
;
416 ReleaseLockOnlyAtBootTime (&Global
->VariableServicesLock
);
424 IN CHAR16
*VariableName
,
425 IN EFI_GUID
*VendorGuid
,
426 IN UINT32 Attributes
,
429 IN VARIABLE_GLOBAL
*Global
,
430 IN UINTN
*VolatileOffset
,
431 IN UINTN
*NonVolatileOffset
,
438 This code sets variable in storage blocks (Volatile or Non-Volatile)
442 VariableName Name of Variable to be found
443 VendorGuid Variable vendor GUID
444 Attributes Attribute value of the variable found
445 DataSize Size of Data found. If size is less than the
446 data, this value contains the required size.
448 Global Pointer to VARIABLE_GLOBAL structure
449 VolatileOffset The offset of last volatile variable
450 NonVolatileOffset The offset of last non-volatile variable
451 Instance Instance of the Firmware Volume.
455 EFI_INVALID_PARAMETER - Invalid parameter
456 EFI_SUCCESS - Set successfully
457 EFI_OUT_OF_RESOURCES - Resource not enough to set variable
458 EFI_NOT_FOUND - Not found
459 EFI_DEVICE_ERROR - Variable can not be saved due to hardware failure
460 EFI_WRITE_PROTECTED - Variable is read-only
464 VARIABLE_POINTER_TRACK Variable
;
466 VARIABLE_HEADER
*NextVariable
;
473 // Check input parameters
475 if (VariableName
== NULL
|| VariableName
[0] == 0 || VendorGuid
== NULL
) {
476 return EFI_INVALID_PARAMETER
;
479 // Make sure if runtime bit is set, boot service bit is set also
481 if ((Attributes
& (EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_BOOTSERVICE_ACCESS
)) == EFI_VARIABLE_RUNTIME_ACCESS
) {
482 return EFI_INVALID_PARAMETER
;
485 // The size of the VariableName, including the Unicode Null in bytes plus
486 // the DataSize is limited to maximum size of MAX_HARDWARE_ERROR_VARIABLE_SIZE (32K)
487 // bytes for HwErrRec, and MAX_VARIABLE_SIZE (1024) bytes for the others.
489 if ((Attributes
& EFI_VARIABLE_HARDWARE_ERROR_RECORD
) == EFI_VARIABLE_HARDWARE_ERROR_RECORD
) {
490 if ((DataSize
> MAX_HARDWARE_ERROR_VARIABLE_SIZE
) ||
491 (sizeof (VARIABLE_HEADER
) + StrSize (VariableName
) + DataSize
> MAX_HARDWARE_ERROR_VARIABLE_SIZE
)) {
492 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_VARIABLE_SIZE (1024) bytes.
499 if ((DataSize
> MAX_VARIABLE_SIZE
) ||
500 (sizeof (VARIABLE_HEADER
) + StrSize (VariableName
) + DataSize
> MAX_VARIABLE_SIZE
)) {
501 return EFI_INVALID_PARAMETER
;
505 // Check whether the input variable is already existed
508 Status
= FindVariable (VariableName
, VendorGuid
, &Variable
, Global
);
510 if (Status
== EFI_SUCCESS
&& Variable
.CurrPtr
!= NULL
) {
512 // Update/Delete existing variable
515 if (EfiAtRuntime ()) {
517 // If EfiAtRuntime and the variable is Volatile and Runtime Access,
518 // the volatile is ReadOnly, and SetVariable should be aborted and
519 // return EFI_WRITE_PROTECTED.
521 if (Variable
.Volatile
) {
522 Status
= EFI_WRITE_PROTECTED
;
526 // Only variable have NV attribute can be updated/deleted in Runtime
528 if (!(Variable
.CurrPtr
->Attributes
& EFI_VARIABLE_NON_VOLATILE
)) {
529 Status
= EFI_INVALID_PARAMETER
;
535 // Setting a data variable with no access, or zero DataSize attributes
536 // specified causes it to be deleted.
538 if (DataSize
== 0 || (Attributes
& (EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_BOOTSERVICE_ACCESS
)) == 0) {
539 Variable
.CurrPtr
->State
&= VAR_DELETED
;
540 Status
= EFI_SUCCESS
;
545 // If the variable is marked valid and the same data has been passed in
546 // then return to the caller immediately.
548 if (Variable
.CurrPtr
->DataSize
== DataSize
&&
549 !CompareMem (Data
, GetVariableDataPtr (Variable
.CurrPtr
), DataSize
)
551 Status
= EFI_SUCCESS
;
553 } else if (Variable
.CurrPtr
->State
== VAR_ADDED
) {
555 // Mark the old variable as in delete transition
557 Variable
.CurrPtr
->State
&= VAR_IN_DELETED_TRANSITION
;
560 } else if (Status
== EFI_NOT_FOUND
) {
562 // Create a new variable
566 // Make sure we are trying to create a new variable.
567 // Setting a data variable with no access, or zero DataSize attributes means to delete it.
569 if (DataSize
== 0 || (Attributes
& (EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_BOOTSERVICE_ACCESS
)) == 0) {
570 Status
= EFI_NOT_FOUND
;
575 // Only variable have NV|RT attribute can be created in Runtime
577 if (EfiAtRuntime () &&
578 (!(Attributes
& EFI_VARIABLE_RUNTIME_ACCESS
) || !(Attributes
& EFI_VARIABLE_NON_VOLATILE
))) {
579 Status
= EFI_INVALID_PARAMETER
;
584 // Status should be EFI_INVALID_PARAMETER here according to return status of FindVariable().
586 ASSERT (Status
== EFI_INVALID_PARAMETER
);
591 // Function part - create a new variable and copy the data.
592 // Both update a variable and create a variable will come here.
595 VarNameOffset
= sizeof (VARIABLE_HEADER
);
596 VarNameSize
= StrSize (VariableName
);
597 VarDataOffset
= VarNameOffset
+ VarNameSize
+ GET_PAD_SIZE (VarNameSize
);
598 VarSize
= VarDataOffset
+ DataSize
+ GET_PAD_SIZE (DataSize
);
600 if (Attributes
& EFI_VARIABLE_NON_VOLATILE
) {
601 if ((UINT32
) (VarSize
+*NonVolatileOffset
) >
602 ((VARIABLE_STORE_HEADER
*) ((UINTN
) (Global
->NonVolatileVariableBase
)))->Size
604 Status
= EFI_OUT_OF_RESOURCES
;
608 NextVariable
= (VARIABLE_HEADER
*) (UINT8
*) (*NonVolatileOffset
+ (UINTN
) Global
->NonVolatileVariableBase
);
609 *NonVolatileOffset
= *NonVolatileOffset
+ VarSize
;
611 if ((UINT32
) (VarSize
+*VolatileOffset
) >
612 ((VARIABLE_STORE_HEADER
*) ((UINTN
) (Global
->VolatileVariableBase
)))->Size
614 Status
= EFI_OUT_OF_RESOURCES
;
618 NextVariable
= (VARIABLE_HEADER
*) (UINT8
*) (*VolatileOffset
+ (UINTN
) Global
->VolatileVariableBase
);
619 *VolatileOffset
= *VolatileOffset
+ VarSize
;
622 NextVariable
->StartId
= VARIABLE_DATA
;
623 NextVariable
->Attributes
= Attributes
;
624 NextVariable
->State
= VAR_ADDED
;
625 NextVariable
->Reserved
= 0;
628 // There will be pad bytes after Data, the NextVariable->NameSize and
629 // NextVariable->NameSize should not include pad size so that variable
630 // service can get actual size in GetVariable
632 NextVariable
->NameSize
= (UINT32
)VarNameSize
;
633 NextVariable
->DataSize
= (UINT32
)DataSize
;
635 CopyMem (&NextVariable
->VendorGuid
, VendorGuid
, sizeof (EFI_GUID
));
637 (UINT8
*) ((UINTN
) NextVariable
+ VarNameOffset
),
642 (UINT8
*) ((UINTN
) NextVariable
+ VarDataOffset
),
648 // Mark the old variable as deleted
650 if (!EFI_ERROR (Status
)) {
651 Variable
.CurrPtr
->State
&= VAR_DELETED
;
654 Status
= EFI_SUCCESS
;
656 ReleaseLockOnlyAtBootTime (&Global
->VariableServicesLock
);
663 IN UINT32 Attributes
,
664 OUT UINT64
*MaximumVariableStorageSize
,
665 OUT UINT64
*RemainingVariableStorageSize
,
666 OUT UINT64
*MaximumVariableSize
,
667 IN VARIABLE_GLOBAL
*Global
,
674 This code returns information about the EFI variables.
678 Attributes Attributes bitmask to specify the type of variables
679 on which to return information.
680 MaximumVariableStorageSize Pointer to the maximum size of the storage space available
681 for the EFI variables associated with the attributes specified.
682 RemainingVariableStorageSize Pointer to the remaining size of the storage space available
683 for EFI variables associated with the attributes specified.
684 MaximumVariableSize Pointer to the maximum size of an individual EFI variables
685 associated with the attributes specified.
686 Global Pointer to VARIABLE_GLOBAL structure.
687 Instance Instance of the Firmware Volume.
692 EFI_INVALID_PARAMETER - An invalid combination of attribute bits was supplied.
693 EFI_SUCCESS - Query successfully.
694 EFI_UNSUPPORTED - The attribute is not supported on this platform.
698 VARIABLE_HEADER
*Variable
;
699 VARIABLE_HEADER
*NextVariable
;
701 VARIABLE_STORE_HEADER
*VariableStoreHeader
;
703 if(MaximumVariableStorageSize
== NULL
|| RemainingVariableStorageSize
== NULL
|| MaximumVariableSize
== NULL
|| Attributes
== 0) {
704 return EFI_INVALID_PARAMETER
;
707 if((Attributes
& (EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_HARDWARE_ERROR_RECORD
)) == 0) {
709 // Make sure the Attributes combination is supported by the platform.
711 return EFI_UNSUPPORTED
;
712 } else if ((Attributes
& (EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_BOOTSERVICE_ACCESS
)) == EFI_VARIABLE_RUNTIME_ACCESS
) {
714 // Make sure if runtime bit is set, boot service bit is set also.
716 return EFI_INVALID_PARAMETER
;
717 } else if (EfiAtRuntime () && !(Attributes
& EFI_VARIABLE_RUNTIME_ACCESS
)) {
719 // Make sure RT Attribute is set if we are in Runtime phase.
721 return EFI_INVALID_PARAMETER
;
724 AcquireLockOnlyAtBootTime(&Global
->VariableServicesLock
);
726 if((Attributes
& EFI_VARIABLE_NON_VOLATILE
) == 0) {
728 // Query is Volatile related.
730 VariableStoreHeader
= (VARIABLE_STORE_HEADER
*) ((UINTN
) Global
->VolatileVariableBase
);
733 // Query is Non-Volatile related.
735 VariableStoreHeader
= (VARIABLE_STORE_HEADER
*) ((UINTN
) Global
->NonVolatileVariableBase
);
739 // Now let's fill *MaximumVariableStorageSize *RemainingVariableStorageSize
740 // with the storage size (excluding the storage header size)
742 *MaximumVariableStorageSize
= VariableStoreHeader
->Size
- sizeof (VARIABLE_STORE_HEADER
);
743 *RemainingVariableStorageSize
= VariableStoreHeader
->Size
- sizeof (VARIABLE_STORE_HEADER
);
746 // Let *MaximumVariableSize be MAX_VARIABLE_SIZE with the exception of the variable header size.
748 *MaximumVariableSize
= MAX_VARIABLE_SIZE
- sizeof (VARIABLE_HEADER
);
751 // Harware error record variable needs larger size.
753 if ((Attributes
& EFI_VARIABLE_HARDWARE_ERROR_RECORD
) == EFI_VARIABLE_HARDWARE_ERROR_RECORD
) {
754 *MaximumVariableSize
= MAX_HARDWARE_ERROR_VARIABLE_SIZE
- sizeof (VARIABLE_HEADER
);
758 // Point to the starting address of the variables.
760 Variable
= (VARIABLE_HEADER
*) (VariableStoreHeader
+ 1);
763 // Now walk through the related variable store.
765 while (Variable
< GetEndPointer (VariableStoreHeader
)) {
766 if (Variable
->StartId
!= VARIABLE_DATA
) {
770 NextVariable
= (VARIABLE_HEADER
*) (GetVariableDataPtr (Variable
) + Variable
->DataSize
+ GET_PAD_SIZE (Variable
->DataSize
));
771 VariableSize
= (UINT64
) (UINTN
) NextVariable
- (UINT64
) (UINTN
) Variable
;
773 if (Variable
->State
== VAR_ADDED
) {
774 *RemainingVariableStorageSize
-= VariableSize
;
778 // Go to the next one.
780 Variable
= NextVariable
;
783 if (*RemainingVariableStorageSize
< sizeof (VARIABLE_HEADER
)) {
784 *MaximumVariableSize
= 0;
785 } else if ((*RemainingVariableStorageSize
- sizeof (VARIABLE_HEADER
)) < *MaximumVariableSize
) {
786 *MaximumVariableSize
= *RemainingVariableStorageSize
- sizeof (VARIABLE_HEADER
);
789 ReleaseLockOnlyAtBootTime (&Global
->VariableServicesLock
);
794 InitializeVariableStore (
795 OUT EFI_PHYSICAL_ADDRESS
*VariableBase
,
796 OUT UINTN
*LastVariableOffset
801 This function initializes variable store
809 VARIABLE_STORE_HEADER
*VariableStore
;
812 // Allocate memory for volatile variable store
814 VariableStore
= (VARIABLE_STORE_HEADER
*) AllocateRuntimePool (
817 if (NULL
== VariableStore
) {
818 return EFI_OUT_OF_RESOURCES
;
821 SetMem (VariableStore
, VARIABLE_STORE_SIZE
, 0xff);
824 // Variable Specific Data
826 *VariableBase
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) VariableStore
;
827 *LastVariableOffset
= sizeof (VARIABLE_STORE_HEADER
);
829 VariableStore
->Signature
= VARIABLE_STORE_SIGNATURE
;
830 VariableStore
->Size
= VARIABLE_STORE_SIZE
;
831 VariableStore
->Format
= VARIABLE_STORE_FORMATTED
;
832 VariableStore
->State
= VARIABLE_STORE_HEALTHY
;
833 VariableStore
->Reserved
= 0;
834 VariableStore
->Reserved1
= 0;
841 VariableCommonInitialize (
842 IN EFI_HANDLE ImageHandle
,
843 IN EFI_SYSTEM_TABLE
*SystemTable
848 This function does common initialization for variable services
859 // Allocate memory for mVariableModuleGlobal
861 mVariableModuleGlobal
= (ESAL_VARIABLE_GLOBAL
*) AllocateRuntimePool (
862 sizeof (ESAL_VARIABLE_GLOBAL
)
864 if (NULL
== mVariableModuleGlobal
) {
865 return EFI_OUT_OF_RESOURCES
;
868 EfiInitializeLock(&mVariableModuleGlobal
->VariableGlobal
[Physical
].VariableServicesLock
, TPL_NOTIFY
);
871 // Intialize volatile variable store
873 Status
= InitializeVariableStore (
874 &mVariableModuleGlobal
->VariableGlobal
[Physical
].VolatileVariableBase
,
875 &mVariableModuleGlobal
->VolatileLastVariableOffset
878 if (EFI_ERROR (Status
)) {
882 // Intialize non volatile variable store
884 Status
= InitializeVariableStore (
885 &mVariableModuleGlobal
->VariableGlobal
[Physical
].NonVolatileVariableBase
,
886 &mVariableModuleGlobal
->NonVolatileLastVariableOffset