MdeModulePkg Variable: Implement variable quota management.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16669 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Star Zeng
2015-01-27 08:42:47 +00:00
committed by lzeng14
parent 4139580d31
commit 4edb18663f
10 changed files with 655 additions and 144 deletions

View File

@@ -524,6 +524,214 @@ GetEndPointer (
return (VARIABLE_HEADER *) HEADER_ALIGN ((UINTN) VarStoreHeader + VarStoreHeader->Size);
}
/**
Record variable error flag.
@param[in] Flag Variable error flag to record.
@param[in] VariableName Name of variable.
@param[in] VendorGuid Guid of variable.
@param[in] Attributes Attributes of the variable.
@param[in] VariableSize Size of the variable.
**/
VOID
RecordVarErrorFlag (
IN VAR_ERROR_FLAG Flag,
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid,
IN UINT32 Attributes,
IN UINTN VariableSize
)
{
EFI_STATUS Status;
VARIABLE_POINTER_TRACK Variable;
VAR_ERROR_FLAG *VarErrFlag;
VAR_ERROR_FLAG TempFlag;
DEBUG_CODE (
DEBUG ((EFI_D_ERROR, "RecordVarErrorFlag (0x%02x) %s:%g - 0x%08x - 0x%x\n", Flag, VariableName, VendorGuid, Attributes, VariableSize));
if (Flag == VAR_ERROR_FLAG_SYSTEM_ERROR) {
if (AtRuntime ()) {
DEBUG ((EFI_D_ERROR, "CommonRuntimeVariableSpace = 0x%x - CommonVariableTotalSize = 0x%x\n", mVariableModuleGlobal->CommonRuntimeVariableSpace, mVariableModuleGlobal->CommonVariableTotalSize));
} else {
DEBUG ((EFI_D_ERROR, "CommonVariableSpace = 0x%x - CommonVariableTotalSize = 0x%x\n", mVariableModuleGlobal->CommonVariableSpace, mVariableModuleGlobal->CommonVariableTotalSize));
}
} else {
DEBUG ((EFI_D_ERROR, "CommonMaxUserVariableSpace = 0x%x - CommonUserVariableTotalSize = 0x%x\n", mVariableModuleGlobal->CommonMaxUserVariableSpace, mVariableModuleGlobal->CommonUserVariableTotalSize));
}
);
//
// Record error flag (it should have be initialized).
//
Status = FindVariable (
VAR_ERROR_FLAG_NAME,
&gEdkiiVarErrorFlagGuid,
&Variable,
&mVariableModuleGlobal->VariableGlobal,
FALSE
);
if (!EFI_ERROR (Status)) {
VarErrFlag = (VAR_ERROR_FLAG *) GetVariableDataPtr (Variable.CurrPtr);
TempFlag = *VarErrFlag;
TempFlag &= Flag;
if (TempFlag == *VarErrFlag) {
return;
}
Status = UpdateVariableStore (
&mVariableModuleGlobal->VariableGlobal,
FALSE,
FALSE,
mVariableModuleGlobal->FvbInstance,
(UINTN) VarErrFlag - (UINTN) mNvVariableCache + (UINTN) mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase,
sizeof (TempFlag),
&TempFlag
);
if (!EFI_ERROR (Status)) {
//
// Update the data in NV cache.
//
*VarErrFlag = Flag;
}
}
}
/**
Initialize variable error flag.
Before EndOfDxe, the variable indicates the last boot variable error flag,
then it means the last boot variable error flag must be got before EndOfDxe.
After EndOfDxe, the variable indicates the current boot variable error flag,
then it means the current boot variable error flag must be got after EndOfDxe.
**/
VOID
InitializeVarErrorFlag (
VOID
)
{
EFI_STATUS Status;
VARIABLE_POINTER_TRACK Variable;
VAR_ERROR_FLAG Flag;
VAR_ERROR_FLAG VarErrFlag;
if (!mEndOfDxe) {
return;
}
Flag = VAR_ERROR_FLAG_NO_ERROR;
DEBUG ((EFI_D_INFO, "Initialize variable error flag (%02x)\n", Flag));
Status = FindVariable (
VAR_ERROR_FLAG_NAME,
&gEdkiiVarErrorFlagGuid,
&Variable,
&mVariableModuleGlobal->VariableGlobal,
FALSE
);
if (!EFI_ERROR (Status)) {
VarErrFlag = *((VAR_ERROR_FLAG *) GetVariableDataPtr (Variable.CurrPtr));
if (VarErrFlag == Flag) {
return;
}
}
UpdateVariable (
VAR_ERROR_FLAG_NAME,
&gEdkiiVarErrorFlagGuid,
&Flag,
sizeof (Flag),
VARIABLE_ATTRIBUTE_NV_BS_RT,
&Variable
);
}
/**
Is user variable?
@param[in] Variable Pointer to variable header.
@retval TRUE User variable.
@retval FALSE System variable.
**/
BOOLEAN
IsUserVariable (
IN VARIABLE_HEADER *Variable
)
{
VAR_CHECK_VARIABLE_PROPERTY Property;
//
// Only after End Of Dxe, the variables belong to system variable are fixed.
// If PcdMaxUserNvStorageVariableSize is 0, it means user variable share the same NV storage with system variable,
// then no need to check if the variable is user variable or not specially.
//
if (mEndOfDxe && (mVariableModuleGlobal->CommonMaxUserVariableSpace != mVariableModuleGlobal->CommonVariableSpace)) {
if (InternalVarCheckVariablePropertyGet (GetVariableNamePtr (Variable), &Variable->VendorGuid, &Property) == EFI_NOT_FOUND) {
return TRUE;
}
}
return FALSE;
}
/**
Calculate common user variable total size.
**/
VOID
CalculateCommonUserVariableTotalSize (
VOID
)
{
VARIABLE_HEADER *Variable;
VARIABLE_HEADER *NextVariable;
UINTN VariableSize;
VAR_CHECK_VARIABLE_PROPERTY Property;
//
// Only after End Of Dxe, the variables belong to system variable are fixed.
// If PcdMaxUserNvStorageVariableSize is 0, it means user variable share the same NV storage with system variable,
// then no need to calculate the common user variable total size specially.
//
if (mEndOfDxe && (mVariableModuleGlobal->CommonMaxUserVariableSpace != mVariableModuleGlobal->CommonVariableSpace)) {
Variable = GetStartPointer (mNvVariableCache);
while (IsValidVariableHeader (Variable, GetEndPointer (mNvVariableCache))) {
NextVariable = GetNextVariablePtr (Variable);
VariableSize = (UINTN) NextVariable - (UINTN) Variable;
if ((Variable->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) != EFI_VARIABLE_HARDWARE_ERROR_RECORD) {
if (InternalVarCheckVariablePropertyGet (GetVariableNamePtr (Variable), &Variable->VendorGuid, &Property) == EFI_NOT_FOUND) {
//
// No property, it is user variable.
//
mVariableModuleGlobal->CommonUserVariableTotalSize += VariableSize;
}
}
Variable = NextVariable;
}
}
}
/**
Initialize variable quota.
**/
VOID
InitializeVariableQuota (
VOID
)
{
STATIC BOOLEAN Initialized;
if (!mEndOfDxe || Initialized) {
return;
}
Initialized = TRUE;
InitializeVarErrorFlag ();
CalculateCommonUserVariableTotalSize ();
}
/**
@@ -567,6 +775,7 @@ Reclaim (
BOOLEAN FoundAdded;
EFI_STATUS Status;
UINTN CommonVariableTotalSize;
UINTN CommonUserVariableTotalSize;
UINTN HwErrVariableTotalSize;
VARIABLE_HEADER *UpdatingVariable;
VARIABLE_HEADER *UpdatingInDeletedTransition;
@@ -581,6 +790,7 @@ Reclaim (
VariableStoreHeader = (VARIABLE_STORE_HEADER *) ((UINTN) VariableBase);
CommonVariableTotalSize = 0;
CommonUserVariableTotalSize = 0;
HwErrVariableTotalSize = 0;
if (IsVolatile) {
@@ -650,6 +860,9 @@ Reclaim (
HwErrVariableTotalSize += VariableSize;
} else if ((!IsVolatile) && ((Variable->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) != EFI_VARIABLE_HARDWARE_ERROR_RECORD)) {
CommonVariableTotalSize += VariableSize;
if (IsUserVariable (Variable)) {
CommonUserVariableTotalSize += VariableSize;
}
}
}
Variable = NextVariable;
@@ -698,6 +911,9 @@ Reclaim (
HwErrVariableTotalSize += VariableSize;
} else if ((!IsVolatile) && ((Variable->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) != EFI_VARIABLE_HARDWARE_ERROR_RECORD)) {
CommonVariableTotalSize += VariableSize;
if (IsUserVariable (Variable)) {
CommonUserVariableTotalSize += VariableSize;
}
}
}
}
@@ -721,9 +937,13 @@ Reclaim (
HwErrVariableTotalSize += NewVariableSize;
} else if ((NewVariable->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) != EFI_VARIABLE_HARDWARE_ERROR_RECORD) {
CommonVariableTotalSize += NewVariableSize;
if (IsUserVariable (NewVariable)) {
CommonUserVariableTotalSize += NewVariableSize;
}
}
if ((HwErrVariableTotalSize > PcdGet32 (PcdHwErrStorageSize)) ||
(CommonVariableTotalSize > VariableStoreHeader->Size - sizeof (VARIABLE_STORE_HEADER) - PcdGet32 (PcdHwErrStorageSize))) {
(CommonVariableTotalSize > mVariableModuleGlobal->CommonVariableSpace) ||
(CommonUserVariableTotalSize > mVariableModuleGlobal->CommonMaxUserVariableSpace)) {
//
// No enough space to store the new variable by NV or NV+HR attribute.
//
@@ -761,19 +981,24 @@ Reclaim (
*LastVariableOffset = (UINTN) (CurrPtr - ValidBuffer);
mVariableModuleGlobal->HwErrVariableTotalSize = HwErrVariableTotalSize;
mVariableModuleGlobal->CommonVariableTotalSize = CommonVariableTotalSize;
mVariableModuleGlobal->CommonUserVariableTotalSize = CommonUserVariableTotalSize;
} else {
NextVariable = GetStartPointer ((VARIABLE_STORE_HEADER *)(UINTN)VariableBase);
while (IsValidVariableHeader (NextVariable, GetEndPointer ((VARIABLE_STORE_HEADER *)(UINTN)VariableBase))) {
VariableSize = NextVariable->NameSize + NextVariable->DataSize + sizeof (VARIABLE_HEADER);
Variable = GetStartPointer ((VARIABLE_STORE_HEADER *)(UINTN)VariableBase);
while (IsValidVariableHeader (Variable, GetEndPointer ((VARIABLE_STORE_HEADER *)(UINTN)VariableBase))) {
NextVariable = GetNextVariablePtr (Variable);
VariableSize = (UINTN) NextVariable - (UINTN) Variable;
if ((Variable->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) == EFI_VARIABLE_HARDWARE_ERROR_RECORD) {
mVariableModuleGlobal->HwErrVariableTotalSize += HEADER_ALIGN (VariableSize);
mVariableModuleGlobal->HwErrVariableTotalSize += VariableSize;
} else if ((Variable->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) != EFI_VARIABLE_HARDWARE_ERROR_RECORD) {
mVariableModuleGlobal->CommonVariableTotalSize += HEADER_ALIGN (VariableSize);
mVariableModuleGlobal->CommonVariableTotalSize += VariableSize;
if (IsUserVariable (Variable)) {
mVariableModuleGlobal->CommonUserVariableTotalSize += VariableSize;
}
}
NextVariable = GetNextVariablePtr (NextVariable);
Variable = NextVariable;
}
*LastVariableOffset = (UINTN) NextVariable - (UINTN) VariableBase;
*LastVariableOffset = (UINTN) Variable - (UINTN) VariableBase;
}
}
@@ -1627,7 +1852,6 @@ UpdateVariable (
EFI_STATUS Status;
VARIABLE_HEADER *NextVariable;
UINTN ScratchSize;
UINTN NonVolatileVarableStoreSize;
UINTN VarNameOffset;
UINTN VarDataOffset;
UINTN VarNameSize;
@@ -1639,6 +1863,8 @@ UpdateVariable (
VARIABLE_POINTER_TRACK NvVariable;
VARIABLE_STORE_HEADER *VariableStoreHeader;
UINTN CacheOffset;
BOOLEAN IsCommonVariable;
BOOLEAN IsCommonUserVariable;
if ((mVariableModuleGlobal->FvbInstance == NULL) && ((Attributes & EFI_VARIABLE_NON_VOLATILE) != 0)) {
//
@@ -1856,12 +2082,25 @@ UpdateVariable (
// Create a nonvolatile variable.
//
Volatile = FALSE;
NonVolatileVarableStoreSize = ((VARIABLE_STORE_HEADER *)(UINTN)(mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase))->Size;
if ((((Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) != 0)
IsCommonVariable = FALSE;
IsCommonUserVariable = FALSE;
if ((Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) == 0) {
IsCommonVariable = TRUE;
IsCommonUserVariable = IsUserVariable (NextVariable);
}
if ((((Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) != 0)
&& ((VarSize + mVariableModuleGlobal->HwErrVariableTotalSize) > PcdGet32 (PcdHwErrStorageSize)))
|| (((Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) == 0)
&& ((VarSize + mVariableModuleGlobal->CommonVariableTotalSize) > NonVolatileVarableStoreSize - sizeof (VARIABLE_STORE_HEADER) - PcdGet32 (PcdHwErrStorageSize)))) {
|| (IsCommonVariable && ((VarSize + mVariableModuleGlobal->CommonVariableTotalSize) > mVariableModuleGlobal->CommonVariableSpace))
|| (IsCommonVariable && AtRuntime () && ((VarSize + mVariableModuleGlobal->CommonVariableTotalSize) > mVariableModuleGlobal->CommonRuntimeVariableSpace))
|| (IsCommonUserVariable && ((VarSize + mVariableModuleGlobal->CommonUserVariableTotalSize) > mVariableModuleGlobal->CommonMaxUserVariableSpace))) {
if (AtRuntime ()) {
if (IsCommonUserVariable && ((VarSize + mVariableModuleGlobal->CommonUserVariableTotalSize) > mVariableModuleGlobal->CommonMaxUserVariableSpace)) {
RecordVarErrorFlag (VAR_ERROR_FLAG_USER_ERROR, VariableName, VendorGuid, Attributes, VarSize);
}
if (IsCommonVariable && ((VarSize + mVariableModuleGlobal->CommonVariableTotalSize) > mVariableModuleGlobal->CommonRuntimeVariableSpace)) {
RecordVarErrorFlag (VAR_ERROR_FLAG_SYSTEM_ERROR, VariableName, VendorGuid, Attributes, VarSize);
}
Status = EFI_OUT_OF_RESOURCES;
goto Done;
}
@@ -1880,6 +2119,13 @@ UpdateVariable (
}
UpdateVariableInfo (VariableName, VendorGuid, FALSE, FALSE, TRUE, FALSE, FALSE);
FlushHobVariableToFlash (VariableName, VendorGuid);
} else {
if (IsCommonUserVariable && ((VarSize + mVariableModuleGlobal->CommonUserVariableTotalSize) > mVariableModuleGlobal->CommonMaxUserVariableSpace)) {
RecordVarErrorFlag (VAR_ERROR_FLAG_USER_ERROR, VariableName, VendorGuid, Attributes, VarSize);
}
if (IsCommonVariable && ((VarSize + mVariableModuleGlobal->CommonVariableTotalSize) > mVariableModuleGlobal->CommonVariableSpace)) {
RecordVarErrorFlag (VAR_ERROR_FLAG_SYSTEM_ERROR, VariableName, VendorGuid, Attributes, VarSize);
}
}
goto Done;
}
@@ -1965,6 +2211,9 @@ UpdateVariable (
mVariableModuleGlobal->HwErrVariableTotalSize += HEADER_ALIGN (VarSize);
} else {
mVariableModuleGlobal->CommonVariableTotalSize += HEADER_ALIGN (VarSize);
if (IsCommonUserVariable) {
mVariableModuleGlobal->CommonUserVariableTotalSize += HEADER_ALIGN (VarSize);
}
}
//
// update the memory copy of Flash region.
@@ -2579,7 +2828,7 @@ VariableServiceSetVariable (
// 2. The only attribute differing is EFI_VARIABLE_APPEND_WRITE
//
Status = EFI_INVALID_PARAMETER;
DEBUG ((EFI_D_INFO, "[Variable]: Rewritten a preexisting variable with different attributes - %g:%s\n", VendorGuid, VariableName));
DEBUG ((EFI_D_INFO, "[Variable]: Rewritten a preexisting variable(0x%08x) with different attributes(0x%08x) - %g:%s\n", Variable.CurrPtr->Attributes, Attributes, VendorGuid, VariableName));
goto Done;
}
}
@@ -2672,8 +2921,11 @@ VariableServiceQueryVariableInfoInternal (
*MaximumVariableSize = PcdGet32 (PcdMaxHardwareErrorVariableSize) - sizeof (VARIABLE_HEADER);
} else {
if ((Attributes & EFI_VARIABLE_NON_VOLATILE) != 0) {
ASSERT (PcdGet32 (PcdHwErrStorageSize) < VariableStoreHeader->Size);
*MaximumVariableStorageSize = VariableStoreHeader->Size - sizeof (VARIABLE_STORE_HEADER) - PcdGet32 (PcdHwErrStorageSize);
if (AtRuntime ()) {
*MaximumVariableStorageSize = mVariableModuleGlobal->CommonRuntimeVariableSpace;
} else {
*MaximumVariableStorageSize = mVariableModuleGlobal->CommonVariableSpace;
}
}
//
@@ -2749,8 +3001,12 @@ VariableServiceQueryVariableInfoInternal (
if ((Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) == EFI_VARIABLE_HARDWARE_ERROR_RECORD){
*RemainingVariableStorageSize = *MaximumVariableStorageSize - HwErrVariableTotalSize;
}else {
*RemainingVariableStorageSize = *MaximumVariableStorageSize - CommonVariableTotalSize;
} else {
if (*MaximumVariableStorageSize < CommonVariableTotalSize) {
*RemainingVariableStorageSize = 0;
} else {
*RemainingVariableStorageSize = *MaximumVariableStorageSize - CommonVariableTotalSize;
}
}
if (*RemainingVariableStorageSize < sizeof (VARIABLE_HEADER)) {
@@ -2851,22 +3107,23 @@ ReclaimForOS(
)
{
EFI_STATUS Status;
UINTN CommonVariableSpace;
UINTN RemainingCommonVariableSpace;
UINTN RemainingCommonRuntimeVariableSpace;
UINTN RemainingHwErrVariableSpace;
Status = EFI_SUCCESS;
Status = EFI_SUCCESS;
CommonVariableSpace = ((VARIABLE_STORE_HEADER *) ((UINTN) (mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase)))->Size - sizeof (VARIABLE_STORE_HEADER) - PcdGet32(PcdHwErrStorageSize); //Allowable max size of common variable storage space
RemainingCommonVariableSpace = CommonVariableSpace - mVariableModuleGlobal->CommonVariableTotalSize;
if (mVariableModuleGlobal->CommonRuntimeVariableSpace < mVariableModuleGlobal->CommonVariableTotalSize) {
RemainingCommonRuntimeVariableSpace = 0;
} else {
RemainingCommonRuntimeVariableSpace = mVariableModuleGlobal->CommonRuntimeVariableSpace - mVariableModuleGlobal->CommonVariableTotalSize;
}
RemainingHwErrVariableSpace = PcdGet32 (PcdHwErrStorageSize) - mVariableModuleGlobal->HwErrVariableTotalSize;
//
// Check if the free area is blow a threshold.
// Check if the free area is below a threshold.
//
if ((RemainingCommonVariableSpace < PcdGet32 (PcdMaxVariableSize))
|| ((PcdGet32 (PcdHwErrStorageSize) != 0) &&
if ((RemainingCommonRuntimeVariableSpace < PcdGet32 (PcdMaxVariableSize))
|| ((PcdGet32 (PcdHwErrStorageSize) != 0) &&
(RemainingHwErrVariableSpace < PcdGet32 (PcdMaxHardwareErrorVariableSize)))){
Status = Reclaim (
mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase,
@@ -2894,6 +3151,7 @@ InitNonVolatileVariableStore (
)
{
EFI_FIRMWARE_VOLUME_HEADER *FvHeader;
VARIABLE_HEADER *Variable;
VARIABLE_HEADER *NextVariable;
EFI_PHYSICAL_ADDRESS VariableStoreBase;
UINT64 VariableStoreLength;
@@ -2905,17 +3163,12 @@ InitNonVolatileVariableStore (
FAULT_TOLERANT_WRITE_LAST_WRITE_DATA *FtwLastWriteData;
UINT32 BackUpOffset;
UINT32 BackUpSize;
UINT32 HwErrStorageSize;
UINT32 MaxUserNvVariableSpaceSize;
UINT32 BoottimeReservedNvVariableSpaceSize;
mVariableModuleGlobal->FvbInstance = NULL;
//
// Note that in EdkII variable driver implementation, Hardware Error Record type variable
// is stored with common variable in the same NV region. So the platform integrator should
// ensure that the value of PcdHwErrStorageSize is less than or equal to the value of
// PcdFlashNvStorageVariableSize.
//
ASSERT (PcdGet32 (PcdHwErrStorageSize) <= PcdGet32 (PcdFlashNvStorageVariableSize));
//
// Allocate runtime memory used for a memory copy of the FLASH region.
// Keep the memory and the FLASH in sync as updates occur.
@@ -2985,6 +3238,37 @@ InitNonVolatileVariableStore (
}
ASSERT(mNvVariableCache->Size == VariableStoreLength);
ASSERT (sizeof (VARIABLE_STORE_HEADER) <= VariableStoreLength);
HwErrStorageSize = PcdGet32 (PcdHwErrStorageSize);
MaxUserNvVariableSpaceSize = PcdGet32 (PcdMaxUserNvVariableSpaceSize);
BoottimeReservedNvVariableSpaceSize = PcdGet32 (PcdBoottimeReservedNvVariableSpaceSize);
//
// Note that in EdkII variable driver implementation, Hardware Error Record type variable
// is stored with common variable in the same NV region. So the platform integrator should
// ensure that the value of PcdHwErrStorageSize is less than the value of
// VariableStoreLength - sizeof (VARIABLE_STORE_HEADER)).
//
ASSERT (HwErrStorageSize < (VariableStoreLength - sizeof (VARIABLE_STORE_HEADER)));
//
// Ensure that the value of PcdMaxUserNvVariableSpaceSize is less than the value of
// VariableStoreLength - sizeof (VARIABLE_STORE_HEADER)) - PcdGet32 (PcdHwErrStorageSize).
//
ASSERT (MaxUserNvVariableSpaceSize < (VariableStoreLength - sizeof (VARIABLE_STORE_HEADER) - HwErrStorageSize));
//
// Ensure that the value of PcdBoottimeReservedNvVariableSpaceSize is less than the value of
// VariableStoreLength - sizeof (VARIABLE_STORE_HEADER)) - PcdGet32 (PcdHwErrStorageSize).
//
ASSERT (BoottimeReservedNvVariableSpaceSize < (VariableStoreLength - sizeof (VARIABLE_STORE_HEADER) - HwErrStorageSize));
mVariableModuleGlobal->CommonVariableSpace = ((UINTN) VariableStoreLength - sizeof (VARIABLE_STORE_HEADER) - HwErrStorageSize);
mVariableModuleGlobal->CommonMaxUserVariableSpace = ((MaxUserNvVariableSpaceSize != 0) ? MaxUserNvVariableSpaceSize : mVariableModuleGlobal->CommonVariableSpace);
mVariableModuleGlobal->CommonRuntimeVariableSpace = mVariableModuleGlobal->CommonVariableSpace - BoottimeReservedNvVariableSpaceSize;
DEBUG ((EFI_D_INFO, "Variable driver common space: 0x%x 0x%x 0x%x\n", mVariableModuleGlobal->CommonVariableSpace, mVariableModuleGlobal->CommonMaxUserVariableSpace, mVariableModuleGlobal->CommonRuntimeVariableSpace));
//
// The max variable or hardware error variable size should be < variable store size.
//
@@ -2993,18 +3277,19 @@ InitNonVolatileVariableStore (
//
// Parse non-volatile variable data and get last variable offset.
//
NextVariable = GetStartPointer ((VARIABLE_STORE_HEADER *)(UINTN)VariableStoreBase);
while (IsValidVariableHeader (NextVariable, GetEndPointer ((VARIABLE_STORE_HEADER *)(UINTN)VariableStoreBase))) {
VariableSize = NextVariable->NameSize + NextVariable->DataSize + sizeof (VARIABLE_HEADER);
if ((NextVariable->Attributes & (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_HARDWARE_ERROR_RECORD)) == (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_HARDWARE_ERROR_RECORD)) {
mVariableModuleGlobal->HwErrVariableTotalSize += HEADER_ALIGN (VariableSize);
Variable = GetStartPointer ((VARIABLE_STORE_HEADER *)(UINTN)VariableStoreBase);
while (IsValidVariableHeader (Variable, GetEndPointer ((VARIABLE_STORE_HEADER *)(UINTN)VariableStoreBase))) {
NextVariable = GetNextVariablePtr (Variable);
VariableSize = (UINTN) NextVariable - (UINTN) Variable;
if ((Variable->Attributes & (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_HARDWARE_ERROR_RECORD)) == (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_HARDWARE_ERROR_RECORD)) {
mVariableModuleGlobal->HwErrVariableTotalSize += VariableSize;
} else {
mVariableModuleGlobal->CommonVariableTotalSize += HEADER_ALIGN (VariableSize);
mVariableModuleGlobal->CommonVariableTotalSize += VariableSize;
}
NextVariable = GetNextVariablePtr (NextVariable);
Variable = NextVariable;
}
mVariableModuleGlobal->NonVolatileLastVariableOffset = (UINTN) NextVariable - (UINTN) VariableStoreBase;
mVariableModuleGlobal->NonVolatileLastVariableOffset = (UINTN) Variable - (UINTN) VariableStoreBase;
return EFI_SUCCESS;
}