/** @file
Implement ReadOnly Variable Services required by PEIM and install PEI
ReadOnly Varaiable2 PPI. These services operates the non-volatile
storage space.
Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "Variable.h"
//
// Module globals
//
};
};
/**
Provide the functionality of the variable services.
@param FileHandle Handle of the file being invoked.
Type EFI_PEI_FILE_HANDLE is defined in FfsFindNextFile().
@param PeiServices General purpose services available to every PEIM.
@retval EFI_SUCCESS If the interface could be successfully installed
@retval Others Returned from PeiServicesInstallPpi()
**/
)
{
return PeiServicesInstallPpi (&mPpiListVariable);
}
/**
Gets the pointer to the first variable header in given variable store area.
@param VarStoreHeader Pointer to the Variable Store Header.
@return Pointer to the first variable header
**/
)
{
//
// The end of variable store
//
}
/**
This code gets the pointer to the last variable memory pointer byte.
@param VarStoreHeader Pointer to the Variable Store Header.
@return VARIABLE_HEADER* pointer to last unavailable Variable Header.
**/
)
{
//
// The end of variable store
//
}
/**
This code checks if variable header is valid or not.
@param Variable Pointer to the Variable Header.
@retval TRUE Variable header is valid.
@retval FALSE Variable header is not valid.
**/
)
{
return FALSE;
}
return TRUE;
}
/**
This code gets the size of name of variable.
@param Variable Pointer to the Variable Header.
@return Size of variable in bytes in type UINTN.
**/
)
{
return 0;
}
}
/**
This code gets the size of data of variable.
@param Variable Pointer to the Variable Header.
@return Size of variable in bytes in type UINTN.
**/
)
{
return 0;
}
}
/**
This code gets the pointer to the variable name.
@param Variable Pointer to the Variable Header.
@return A CHAR16* pointer to Variable Name.
**/
CHAR16 *
)
{
}
/**
This code gets the pointer to the variable data.
@param Variable Pointer to the Variable Header.
@return A UINT8* pointer to Variable Data.
**/
UINT8 *
)
{
//
// Be careful about pad size for alignment
//
}
/**
This code gets the pointer to the next variable header.
@param Variable Pointer to the Variable Header.
@return A VARIABLE_HEADER* pointer to next variable header.
**/
)
{
if (!IsValidVariableHeader (Variable)) {
return NULL;
}
//
// Be careful about pad size for alignment
//
}
/**
This code gets the pointer to the variable name.
@param VarStoreHeader Pointer to the Variable Store Header.
@retval EfiRaw Variable store is raw
@retval EfiValid Variable store is valid
@retval EfiInvalid Variable store is invalid
**/
)
{
) {
return EfiValid;
}
) {
return EfiRaw;
} else {
return EfiInvalid;
}
}
/**
This function compares a variable with variable entries in database.
@param Variable Pointer to the variable in our database
@param VariableName Name of the variable to compare to 'Variable'
@param VendorGuid GUID of the variable to compare to 'Variable'
@param PtrTrack Variable Track Pointer structure that contains Variable Information.
@retval EFI_SUCCESS Found match variable
@retval EFI_NOT_FOUND Variable not found
**/
)
{
if (VariableName[0] == 0) {
return EFI_SUCCESS;
} else {
//
// Don't use CompareGuid function here for performance reasons.
// Instead we compare the GUID a UINT32 at a time and branch
// on the first failed comparison.
//
) {
return EFI_SUCCESS;
}
}
}
return EFI_NOT_FOUND;
}
/**
Return the variable store header and the index table based on the Index.
@param Type The type of the variable store.
@param IndexTable Return the index table.
@return Pointer to the variable store header.
**/
)
{
if (IndexTable != NULL) {
*IndexTable = NULL;
}
switch (Type) {
case VariableStoreTypeHob:
}
break;
case VariableStoreTypeNv:
if (GetBootModeHob () != BOOT_IN_RECOVERY_MODE) {
//
// The content of NV storage for variable is not reliable in recovery boot mode.
//
FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) (PcdGet64 (PcdFlashNvStorageVariableBase64) != 0 ?
);
//
// Check if the Firmware Volume is not corrupted
//
if ((FvHeader->Signature != EFI_FVH_SIGNATURE) || (!CompareGuid (&gEfiSystemNvDataFvGuid, &FvHeader->FileSystemGuid))) {
break;
}
if (IndexTable != NULL) {
} else {
//
// If it's the first time to access variable region in flash, create a guid hob to record
// VAR_ADDED type variable info.
// Note that as the resource of PEI phase is limited, only store the limited number of
// VAR_ADDED type variables to reduce access time.
//
(*IndexTable)->Length = 0;
(*IndexTable)->GoneThrough = 0;
}
}
}
break;
default:
break;
}
return VariableStoreHeader;
}
/**
Find the variable in the specified variable store.
@param VariableStoreHeader Pointer to the variable store header.
@param IndexTable Pointer to the index table.
@param VariableName Name of the variable to be found
@param VendorGuid Vendor GUID to be found.
@param PtrTrack Variable Track Pointer structure that contains Variable Information.
@retval EFI_SUCCESS Variable found successfully
@retval EFI_NOT_FOUND Variable not found
@retval EFI_INVALID_PARAMETER Invalid variable name
**/
)
{
if (VariableStoreHeader == NULL) {
return EFI_INVALID_PARAMETER;
}
return EFI_UNSUPPORTED;
}
if (~VariableStoreHeader->Size == 0) {
return EFI_NOT_FOUND;
}
//
// No Variable Address equals zero, so 0 as initial value is safe.
//
if (IndexTable != NULL) {
//
// traverse the variable index table to look for varible.
// The IndexTable->Index[Index] records the distance of two neighbouring VAR_ADDED type variables.
//
return EFI_SUCCESS;
}
}
if (IndexTable->GoneThrough != 0) {
//
// If the table has all the existing variables indexed and we still cannot find it.
//
return EFI_NOT_FOUND;
}
}
//
// HOB exists but the variable cannot be found in HOB
// If not found in HOB, then let's start from the MaxIndex we've found.
//
} else {
//
// Start Pointers for the variable.
// Actual Data Pointer where data can be written.
//
}
//
// Find the variable by walk through non-volatile variable store
//
StopRecord = FALSE;
//
// Record Variable in VariableIndex HOB
//
if ((Offset > 0x0FFFF) || (IndexTable->Length == sizeof (IndexTable->Index) / sizeof (IndexTable->Index[0]))) {
//
// Stop to record if the distance of two neighbouring VAR_ADDED variable is larger than the allowable scope(UINT16),
// or the record buffer is full.
//
StopRecord = TRUE;
} else {
}
}
return EFI_SUCCESS;
}
}
}
//
// If gone through the VariableStore, that means we never find in Firmware any more.
//
}
return EFI_NOT_FOUND;
}
/**
Find the variable in HOB and Non-Volatile variable storages.
@param VariableName Name of the variable to be found
@param VendorGuid Vendor GUID to be found.
@param PtrTrack Variable Track Pointer structure that contains Variable Information.
@retval EFI_SUCCESS Variable found successfully
@retval EFI_NOT_FOUND Variable not found
@retval EFI_INVALID_PARAMETER Invalid variable name
**/
)
{
return EFI_INVALID_PARAMETER;
}
Status = FindVariableEx (
);
return Status;
}
}
return EFI_NOT_FOUND;
}
/**
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.
@param This A pointer to this instance of the EFI_PEI_READ_ONLY_VARIABLE2_PPI.
@param VariableName A pointer to a null-terminated string that is the variable's name.
@param VariableGuid A pointer to an EFI_GUID that is the variable's GUID. The combination of
VariableGuid and VariableName must be unique.
@param Attributes If non-NULL, on return, points to the variable's attributes.
@param DataSize On entry, points to the size in bytes of the Data buffer.
On return, points to the size of the data returned in Data.
@param Data Points to the buffer which will hold the returned variable value.
@retval EFI_SUCCESS The variable was read successfully.
@retval EFI_NOT_FOUND The variable could not be found.
@retval EFI_BUFFER_TOO_SMALL The DataSize is too small for the resulting data.
DataSize is updated with the size required for
the specified variable.
@retval EFI_INVALID_PARAMETER VariableName, VariableGuid, DataSize or Data is NULL.
@retval EFI_DEVICE_ERROR The variable could not be retrieved because of a device error.
**/
)
{
return EFI_INVALID_PARAMETER;
}
//
// Find existing variable
//
return Status;
}
//
// Get data size
//
if (*DataSize >= VarDataSize) {
return EFI_INVALID_PARAMETER;
}
if (Attributes != NULL) {
}
*DataSize = VarDataSize;
return EFI_SUCCESS;
} else {
*DataSize = VarDataSize;
return EFI_BUFFER_TOO_SMALL;
}
}
/**
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.
@param This A pointer to this instance of the EFI_PEI_READ_ONLY_VARIABLE2_PPI.
@param VariableNameSize On entry, points to the size of the buffer pointed to by VariableName.
On return, the size of the variable name buffer.
@param VariableName On 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.
@param VariableGuid On entry, a pointer to an EFI_GUID that is the variable's GUID.
On return, a pointer to the next variable's GUID.
@retval EFI_SUCCESS The variable was read successfully.
@retval EFI_NOT_FOUND The variable could not be found.
@retval EFI_BUFFER_TOO_SMALL The VariableNameSize is too small for the resulting
data. VariableNameSize is updated with the size
required for the specified variable.
@retval EFI_INVALID_PARAMETER VariableName, VariableGuid or
VariableNameSize is NULL.
@retval EFI_DEVICE_ERROR The variable could not be retrieved because of a device error.
**/
)
{
return EFI_INVALID_PARAMETER;
}
return Status;
}
if (VariableName[0] != 0) {
//
// If variable name is not NULL, get next variable
//
}
while (TRUE) {
//
// Switch from HOB to Non-Volatile.
//
) {
//
// Find current storage index
//
if ((VariableStoreHeader[Type] != NULL) && (Variable.StartPtr == GetStartPointer (VariableStoreHeader[Type]))) {
break;
}
}
//
// Switch to next storage
//
break;
}
}
//
// Capture the case that
// 1. current storage is the last one, or
// 2. no further storage
//
if (Type == VariableStoreTypeMax) {
return EFI_NOT_FOUND;
}
}
//
// Don't return NV variable when HOB overrides it
//
if ((VariableStoreHeader[VariableStoreTypeHob] != NULL) && (VariableStoreHeader[VariableStoreTypeNv] != NULL) &&
) {
Status = FindVariableEx (
NULL,
);
continue;
}
}
ASSERT (VarNameSize != 0);
if (VarNameSize <= *VariableNameSize) {
} else {
}
//
// Variable is found
//
return Status;
} else {
}
}
}