TianoCore EDK2 master
Loading...
Searching...
No Matches
Variable.c File Reference
#include "Variable.h"

Go to the source code of this file.

Functions

EFI_STATUS EFIAPI BuildVariableRuntimeCacheInfoHob (IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, IN VOID *Ppi)
 
EFI_STATUS EFIAPI PeimInitializeVariableServices (IN EFI_PEI_FILE_HANDLE FileHandle, IN CONST EFI_PEI_SERVICES **PeiServices)
 
VARIABLE_HEADERGetStartPointer (IN VARIABLE_STORE_HEADER *VarStoreHeader)
 
VARIABLE_HEADERGetEndPointer (IN VARIABLE_STORE_HEADER *VarStoreHeader)
 
BOOLEAN IsValidVariableHeader (IN VARIABLE_HEADER *Variable)
 
UINTN GetVariableHeaderSize (IN BOOLEAN AuthFlag)
 
UINTN NameSizeOfVariable (IN VARIABLE_HEADER *Variable, IN BOOLEAN AuthFlag)
 
UINTN DataSizeOfVariable (IN VARIABLE_HEADER *Variable, IN BOOLEAN AuthFlag)
 
CHAR16 * GetVariableNamePtr (IN VARIABLE_HEADER *Variable, IN BOOLEAN AuthFlag)
 
EFI_GUIDGetVendorGuidPtr (IN VARIABLE_HEADER *Variable, IN BOOLEAN AuthFlag)
 
UINT8 * GetVariableDataPtr (IN VARIABLE_HEADER *Variable, IN VARIABLE_HEADER *VariableHeader, IN BOOLEAN AuthFlag)
 
VARIABLE_HEADERGetNextVariablePtr (IN VARIABLE_STORE_INFO *StoreInfo, IN VARIABLE_HEADER *Variable, IN VARIABLE_HEADER *VariableHeader)
 
VARIABLE_STORE_STATUS GetVariableStoreStatus (IN VARIABLE_STORE_HEADER *VarStoreHeader)
 
BOOLEAN CompareVariableName (IN VARIABLE_STORE_INFO *StoreInfo, IN CONST CHAR16 *Name1, IN CONST CHAR16 *Name2, IN UINTN NameSize)
 
EFI_STATUS CompareWithValidVariable (IN VARIABLE_STORE_INFO *StoreInfo, IN VARIABLE_HEADER *Variable, IN VARIABLE_HEADER *VariableHeader, IN CONST CHAR16 *VariableName, IN CONST EFI_GUID *VendorGuid, OUT VARIABLE_POINTER_TRACK *PtrTrack)
 
VOID GetHobVariableStore (OUT VARIABLE_STORE_INFO *StoreInfo, OUT VARIABLE_STORE_HEADER **VariableStoreHeader)
 
VARIABLE_STORE_HEADERGetVariableStore (IN VARIABLE_STORE_TYPE Type, OUT VARIABLE_STORE_INFO *StoreInfo)
 
BOOLEAN GetVariableHeader (IN VARIABLE_STORE_INFO *StoreInfo, IN VARIABLE_HEADER *Variable, OUT VARIABLE_HEADER **VariableHeader)
 
VOID GetVariableNameOrData (IN VARIABLE_STORE_INFO *StoreInfo, IN UINT8 *NameOrData, IN UINTN Size, OUT UINT8 *Buffer)
 
EFI_STATUS FindVariableEx (IN VARIABLE_STORE_INFO *StoreInfo, IN CONST CHAR16 *VariableName, IN CONST EFI_GUID *VendorGuid, OUT VARIABLE_POINTER_TRACK *PtrTrack)
 
EFI_STATUS FindVariable (IN CONST CHAR16 *VariableName, IN CONST EFI_GUID *VendorGuid, OUT VARIABLE_POINTER_TRACK *PtrTrack, OUT VARIABLE_STORE_INFO *StoreInfo)
 
EFI_STATUS EFIAPI PeiGetVariable (IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This, IN CONST CHAR16 *VariableName, IN CONST EFI_GUID *VariableGuid, OUT UINT32 *Attributes, IN OUT UINTN *DataSize, OUT VOID *Data OPTIONAL)
 
EFI_STATUS EFIAPI PeiGetNextVariableName (IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This, IN OUT UINTN *VariableNameSize, IN OUT CHAR16 *VariableName, IN OUT EFI_GUID *VariableGuid)
 
UINTN CalculateAuthVarStorageSize (IN VARIABLE_STORE_INFO *StoreInfo, IN VARIABLE_STORE_HEADER *NormalHobVarStorage)
 
UINTN CalculateHobVariableCacheSize (IN BOOLEAN NvAuthFlag)
 
UINTN CalculateNvVariableCacheSize (OUT BOOLEAN *NvAuthFlag)
 

Variables

EFI_PEI_READ_ONLY_VARIABLE2_PPI mVariablePpi
 
EFI_PEI_PPI_DESCRIPTOR mPpiListVariable
 
EFI_PEI_NOTIFY_DESCRIPTOR mPostMemNotifyList
 

Detailed Description

Implement ReadOnly Variable Services required by PEIM and install PEI ReadOnly Varaiable2 PPI. These services operates the non volatile storage space.

Copyright (c) 2006 - 2024, Intel Corporation. All rights reserved.
Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file Variable.c.

Function Documentation

◆ BuildVariableRuntimeCacheInfoHob()

EFI_STATUS EFIAPI BuildVariableRuntimeCacheInfoHob ( IN EFI_PEI_SERVICES **  PeiServices,
IN EFI_PEI_NOTIFY_DESCRIPTOR NotifyDescriptor,
IN VOID *  Ppi 
)

Build gEdkiiVariableRuntimeCacheInfoHobGuid.

Parameters
[in]PeiServicesGeneral purpose services available to every PEIM.
[in]NotifyDescriptorThe notification structure this PEIM registered on install.
[in]PpiThe memory discovered PPI. Not used.
Return values
EFI_SUCCESSThe function completed successfully.
othersFailed to build VariableRuntimeCacheInfo Hob.

Definition at line 1428 of file Variable.c.

◆ CalculateAuthVarStorageSize()

UINTN CalculateAuthVarStorageSize ( IN VARIABLE_STORE_INFO StoreInfo,
IN VARIABLE_STORE_HEADER NormalHobVarStorage 
)

Calculate the auth variable storage size converted from normal variable storage.

Parameters
[in]StoreInfoPointer to the store info
[in]NormalHobVarStoragePointer to the normal variable storage header
Return values
theauth variable storage size

Definition at line 1292 of file Variable.c.

◆ CalculateHobVariableCacheSize()

UINTN CalculateHobVariableCacheSize ( IN BOOLEAN  NvAuthFlag)

Calculate Hob variable cache size.

Parameters
[in]NvAuthFlagIf the NV variable store is Auth.
Return values
Maximumof Nv variable cache size.

Definition at line 1331 of file Variable.c.

◆ CalculateNvVariableCacheSize()

UINTN CalculateNvVariableCacheSize ( OUT BOOLEAN *  NvAuthFlag)

Calculate Nv variable cache size.

Parameters
[out]NvAuthFlagIf the NV variable store is Auth.
Return values
Maximumof Nv variable cache size.

Definition at line 1370 of file Variable.c.

◆ CompareVariableName()

BOOLEAN CompareVariableName ( IN VARIABLE_STORE_INFO StoreInfo,
IN CONST CHAR16 *  Name1,
IN CONST CHAR16 *  Name2,
IN UINTN  NameSize 
)

Compare two variable names, one of them may be inconsecutive.

Parameters
StoreInfoPointer to variable store info structure.
Name1Pointer to one variable name.
Name2Pointer to another variable name.
NameSizeVariable name size.
Return values
TRUEName1 and Name2 are identical.
FALSEName1 and Name2 are not identical.

Definition at line 413 of file Variable.c.

◆ CompareWithValidVariable()

EFI_STATUS CompareWithValidVariable ( IN VARIABLE_STORE_INFO StoreInfo,
IN VARIABLE_HEADER Variable,
IN VARIABLE_HEADER VariableHeader,
IN CONST CHAR16 *  VariableName,
IN CONST EFI_GUID VendorGuid,
OUT VARIABLE_POINTER_TRACK PtrTrack 
)

This function compares a variable with variable entries in database.

Parameters
StoreInfoPointer to variable store info structure.
VariablePointer to the variable in our database
VariableHeaderPointer to the Variable Header that has consecutive content.
VariableNameName of the variable to compare to 'Variable'
VendorGuidGUID of the variable to compare to 'Variable'
PtrTrackVariable Track Pointer structure that contains Variable Information.
Return values
EFI_SUCCESSFound match variable
EFI_NOT_FOUNDVariable not found

Definition at line 491 of file Variable.c.

◆ DataSizeOfVariable()

UINTN DataSizeOfVariable ( IN VARIABLE_HEADER Variable,
IN BOOLEAN  AuthFlag 
)

This code gets the size of data of variable.

Parameters
VariablePointer to the Variable Header.
AuthFlagAuthenticated variable flag.
Returns
Size of variable in bytes in type UINTN.

Definition at line 215 of file Variable.c.

◆ FindVariable()

EFI_STATUS FindVariable ( IN CONST CHAR16 *  VariableName,
IN CONST EFI_GUID VendorGuid,
OUT VARIABLE_POINTER_TRACK PtrTrack,
OUT VARIABLE_STORE_INFO StoreInfo 
)

Find the variable in HOB and Non-Volatile variable storages.

Parameters
VariableNameName of the variable to be found
VendorGuidVendor GUID to be found.
PtrTrackVariable Track Pointer structure that contains Variable Information.
StoreInfoReturn the store info.
Return values
EFI_SUCCESSVariable found successfully
EFI_NOT_FOUNDVariable not found
EFI_INVALID_PARAMETERInvalid variable name

Definition at line 992 of file Variable.c.

◆ FindVariableEx()

EFI_STATUS FindVariableEx ( IN VARIABLE_STORE_INFO StoreInfo,
IN CONST CHAR16 *  VariableName,
IN CONST EFI_GUID VendorGuid,
OUT VARIABLE_POINTER_TRACK PtrTrack 
)

Find the variable in the specified variable store.

Parameters
StoreInfoPointer to the store info structure.
VariableNameName of the variable to be found
VendorGuidVendor GUID to be found.
PtrTrackVariable Track Pointer structure that contains Variable Information.
Return values
EFI_SUCCESSVariable found successfully
EFI_NOT_FOUNDVariable not found
EFI_INVALID_PARAMETERInvalid variable name

Definition at line 844 of file Variable.c.

◆ GetEndPointer()

VARIABLE_HEADER * GetEndPointer ( IN VARIABLE_STORE_HEADER VarStoreHeader)

Gets the pointer to the end of the variable storage area.

This function gets pointer to the end of the variable storage area, according to the input variable store header.

Parameters
VarStoreHeaderPointer to the Variable Store Header.
Returns
Pointer to the end of the variable storage area.

Definition at line 109 of file Variable.c.

◆ GetHobVariableStore()

VOID GetHobVariableStore ( OUT VARIABLE_STORE_INFO StoreInfo,
OUT VARIABLE_STORE_HEADER **  VariableStoreHeader 
)

Get HOB variable store.

Parameters
[out]StoreInfoReturn the store info.
[out]VariableStoreHeaderReturn variable store header.

Definition at line 540 of file Variable.c.

◆ GetNextVariablePtr()

VARIABLE_HEADER * GetNextVariablePtr ( IN VARIABLE_STORE_INFO StoreInfo,
IN VARIABLE_HEADER Variable,
IN VARIABLE_HEADER VariableHeader 
)

This code gets the pointer to the next variable header.

Parameters
StoreInfoPointer to variable store info structure.
VariablePointer to the Variable Header.
VariableHeaderPointer to the Variable Header that has consecutive content.
Returns
A VARIABLE_HEADER* pointer to next variable header.

Definition at line 329 of file Variable.c.

◆ GetStartPointer()

VARIABLE_HEADER * GetStartPointer ( IN VARIABLE_STORE_HEADER VarStoreHeader)

Gets the pointer to the first variable header in given variable store area.

Parameters
VarStoreHeaderPointer to the Variable Store Header.
Returns
Pointer to the first variable header.

Definition at line 86 of file Variable.c.

◆ GetVariableDataPtr()

UINT8 * GetVariableDataPtr ( IN VARIABLE_HEADER Variable,
IN VARIABLE_HEADER VariableHeader,
IN BOOLEAN  AuthFlag 
)

This code gets the pointer to the variable data.

Parameters
VariablePointer to the Variable Header.
VariableHeaderPointer to the Variable Header that has consecutive content.
AuthFlagAuthenticated variable flag.
Returns
A UINT8* pointer to Variable Data.

Definition at line 300 of file Variable.c.

◆ GetVariableHeader()

BOOLEAN GetVariableHeader ( IN VARIABLE_STORE_INFO StoreInfo,
IN VARIABLE_HEADER Variable,
OUT VARIABLE_HEADER **  VariableHeader 
)

Get variable header that has consecutive content.

Parameters
StoreInfoPointer to variable store info structure.
VariablePointer to the Variable Header.
VariableHeaderPointer to Pointer to the Variable Header that has consecutive content.
Return values
TRUEVariable header is valid.
FALSEVariable header is not valid.

Definition at line 718 of file Variable.c.

◆ GetVariableHeaderSize()

UINTN GetVariableHeaderSize ( IN BOOLEAN  AuthFlag)

This code gets the size of variable header.

Parameters
AuthFlagAuthenticated variable flag.
Returns
Size of variable header in bytes in type UINTN.

Definition at line 149 of file Variable.c.

◆ GetVariableNameOrData()

VOID GetVariableNameOrData ( IN VARIABLE_STORE_INFO StoreInfo,
IN UINT8 *  NameOrData,
IN UINTN  Size,
OUT UINT8 *  Buffer 
)

Get variable name or data to output buffer.

Parameters
StoreInfoPointer to variable store info structure.
NameOrDataPointer to the variable name/data that may be inconsecutive.
SizeVariable name/data size.
BufferPointer to output buffer to hold the variable name/data.

Definition at line 793 of file Variable.c.

◆ GetVariableNamePtr()

CHAR16 * GetVariableNamePtr ( IN VARIABLE_HEADER Variable,
IN BOOLEAN  AuthFlag 
)

This code gets the pointer to the variable name.

Parameters
VariablePointer to the Variable Header.
AuthFlagAuthenticated variable flag.
Returns
A CHAR16* pointer to Variable Name.

Definition at line 256 of file Variable.c.

◆ GetVariableStore()

VARIABLE_STORE_HEADER * GetVariableStore ( IN VARIABLE_STORE_TYPE  Type,
OUT VARIABLE_STORE_INFO StoreInfo 
)

Return the variable store header and the store info based on the Index.

Parameters
TypeThe type of the variable store.
StoreInfoReturn the store info.
Returns
Pointer to the variable store header.

Definition at line 594 of file Variable.c.

◆ GetVariableStoreStatus()

VARIABLE_STORE_STATUS GetVariableStoreStatus ( IN VARIABLE_STORE_HEADER VarStoreHeader)

Get variable store status.

Parameters
VarStoreHeaderPointer to the Variable Store Header.
Return values
EfiRawVariable store is raw
EfiValidVariable store is valid
EfiInvalidVariable store is invalid

Definition at line 372 of file Variable.c.

◆ GetVendorGuidPtr()

EFI_GUID * GetVendorGuidPtr ( IN VARIABLE_HEADER Variable,
IN BOOLEAN  AuthFlag 
)

This code gets the pointer to the variable guid.

Parameters
VariablePointer to the Variable Header.
AuthFlagAuthenticated variable flag.
Returns
A EFI_GUID* pointer to Vendor Guid.

Definition at line 274 of file Variable.c.

◆ IsValidVariableHeader()

BOOLEAN IsValidVariableHeader ( IN VARIABLE_HEADER Variable)

This code checks if variable header is valid or not.

Parameters
VariablePointer to the Variable Header.
Return values
TRUEVariable header is valid.
FALSEVariable header is not valid.

Definition at line 129 of file Variable.c.

◆ NameSizeOfVariable()

UINTN NameSizeOfVariable ( IN VARIABLE_HEADER Variable,
IN BOOLEAN  AuthFlag 
)

This code gets the size of name of variable.

Parameters
VariablePointer to the Variable Header.
AuthFlagAuthenticated variable flag.
Returns
Size of variable in bytes in type UINTN.

Definition at line 174 of file Variable.c.

◆ PeiGetNextVariableName()

EFI_STATUS EFIAPI PeiGetNextVariableName ( IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI This,
IN OUT UINTN VariableNameSize,
IN OUT CHAR16 *  VariableName,
IN OUT EFI_GUID VariableGuid 
)

Return the next variable name and GUID.

This function is called multiple times to retrieve the VariableName and VariableGuid of all variables currently available in the system. On each call, the previous results are passed into the interface, and, on return, the interface returns the data for the next interface. When the entire variable list has been returned, EFI_NOT_FOUND is returned.

Parameters
ThisA pointer to this instance of the EFI_PEI_READ_ONLY_VARIABLE2_PPI.
VariableNameSizeOn entry, points to the size of the buffer pointed to by VariableName. On return, the size of the variable name buffer.
VariableNameOn entry, a pointer to a null-terminated string that is the variable's name. On return, points to the next variable's null-terminated name string.
VariableGuidOn entry, a pointer to an EFI_GUID that is the variable's GUID. On return, a pointer to the next variable's GUID.
Return values
EFI_SUCCESSThe variable was read successfully.
EFI_NOT_FOUNDThe variable could not be found.
EFI_BUFFER_TOO_SMALLThe VariableNameSize is too small for the resulting data. VariableNameSize is updated with the size required for the specified variable.
EFI_INVALID_PARAMETERVariableName, VariableGuid or VariableNameSize is NULL.
EFI_DEVICE_ERRORThe variable could not be retrieved because of a device error.

Definition at line 1141 of file Variable.c.

◆ PeiGetVariable()

EFI_STATUS EFIAPI PeiGetVariable ( IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI This,
IN CONST CHAR16 *  VariableName,
IN CONST EFI_GUID VariableGuid,
OUT UINT32 *  Attributes,
IN OUT UINTN DataSize,
OUT VOID *Data  OPTIONAL 
)

This service retrieves a variable's value using its name and GUID.

Read the specified variable from the UEFI variable store. If the Data buffer is too small to hold the contents of the variable, the error EFI_BUFFER_TOO_SMALL is returned and DataSize is set to the required buffer size to obtain the data.

Parameters
ThisA pointer to this instance of the EFI_PEI_READ_ONLY_VARIABLE2_PPI.
VariableNameA pointer to a null-terminated string that is the variable's name.
VariableGuidA pointer to an EFI_GUID that is the variable's GUID. The combination of VariableGuid and VariableName must be unique.
AttributesIf non-NULL, on return, points to the variable's attributes.
DataSizeOn entry, points to the size in bytes of the Data buffer. On return, points to the size of the data returned in Data.
DataPoints to the buffer which will hold the returned variable value. May be NULL with a zero DataSize in order to determine the size of the buffer needed.
Return values
EFI_SUCCESSThe variable was read successfully.
EFI_NOT_FOUNDThe variable was be found.
EFI_BUFFER_TOO_SMALLThe DataSize is too small for the resulting data. DataSize is updated with the size required for the specified variable.
EFI_INVALID_PARAMETERVariableName, VariableGuid, DataSize or Data is NULL.
EFI_DEVICE_ERRORThe variable could not be retrieved because of a device error.

Definition at line 1051 of file Variable.c.

◆ PeimInitializeVariableServices()

EFI_STATUS EFIAPI PeimInitializeVariableServices ( IN EFI_PEI_FILE_HANDLE  FileHandle,
IN CONST EFI_PEI_SERVICES **  PeiServices 
)

Provide the functionality of the variable services.

Parameters
FileHandleHandle of the file being invoked. Type EFI_PEI_FILE_HANDLE is defined in FfsFindNextFile().
PeiServicesGeneral purpose services available to every PEIM.
Return values
EFI_SUCCESSIf the interface could be successfully installed
OthersReturned from PeiServicesInstallPpi()

Definition at line 64 of file Variable.c.

Variable Documentation

◆ mPostMemNotifyList

EFI_PEI_NOTIFY_DESCRIPTOR mPostMemNotifyList
Initial value:
= {
(EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
&gEfiPeiMemoryDiscoveredPpiGuid,
}
EFI_STATUS EFIAPI BuildVariableRuntimeCacheInfoHob(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, IN VOID *Ppi)
Definition: Variable.c:1428

Definition at line 46 of file Variable.c.

◆ mPpiListVariable

EFI_PEI_PPI_DESCRIPTOR mPpiListVariable
Initial value:
= {
(EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
&gEfiPeiReadOnlyVariable2PpiGuid,
&mVariablePpi
}

Definition at line 21 of file Variable.c.

◆ mVariablePpi

Initial value:
= {
}
EFI_STATUS EFIAPI PeiGetVariable(IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This, IN CONST CHAR16 *VariableName, IN CONST EFI_GUID *VariableGuid, OUT UINT32 *Attributes, IN OUT UINTN *DataSize, OUT VOID *Data OPTIONAL)
Definition: Variable.c:1051
EFI_STATUS EFIAPI PeiGetNextVariableName(IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This, IN OUT UINTN *VariableNameSize, IN OUT CHAR16 *VariableName, IN OUT EFI_GUID *VariableGuid)
Definition: Variable.c:1141

Definition at line 16 of file Variable.c.