MdeModulePkg and SecurityPkg Variable: Optimize the code to reduce some SMRAM consumption during variable reclaiming.
Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Star Zeng <star.zeng@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14832 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
@@ -615,40 +615,49 @@ Reclaim (
|
||||
CommonVariableTotalSize = 0;
|
||||
HwErrVariableTotalSize = 0;
|
||||
|
||||
//
|
||||
// Start Pointers for the variable.
|
||||
//
|
||||
Variable = GetStartPointer (VariableStoreHeader);
|
||||
MaximumBufferSize = sizeof (VARIABLE_STORE_HEADER);
|
||||
if (IsVolatile) {
|
||||
//
|
||||
// Start Pointers for the variable.
|
||||
//
|
||||
Variable = GetStartPointer (VariableStoreHeader);
|
||||
MaximumBufferSize = sizeof (VARIABLE_STORE_HEADER);
|
||||
|
||||
while (IsValidVariableHeader (Variable)) {
|
||||
NextVariable = GetNextVariablePtr (Variable);
|
||||
if ((Variable->State == VAR_ADDED || Variable->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)) &&
|
||||
Variable != UpdatingVariable &&
|
||||
Variable != UpdatingInDeletedTransition
|
||||
) {
|
||||
VariableSize = (UINTN) NextVariable - (UINTN) Variable;
|
||||
MaximumBufferSize += VariableSize;
|
||||
while (IsValidVariableHeader (Variable)) {
|
||||
NextVariable = GetNextVariablePtr (Variable);
|
||||
if ((Variable->State == VAR_ADDED || Variable->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)) &&
|
||||
Variable != UpdatingVariable &&
|
||||
Variable != UpdatingInDeletedTransition
|
||||
) {
|
||||
VariableSize = (UINTN) NextVariable - (UINTN) Variable;
|
||||
MaximumBufferSize += VariableSize;
|
||||
}
|
||||
|
||||
Variable = NextVariable;
|
||||
}
|
||||
|
||||
Variable = NextVariable;
|
||||
}
|
||||
if (NewVariable != NULL) {
|
||||
//
|
||||
// Add the new variable size.
|
||||
//
|
||||
MaximumBufferSize += NewVariableSize;
|
||||
}
|
||||
|
||||
if (NewVariable != NULL) {
|
||||
//
|
||||
// Add the new variable size.
|
||||
// Reserve the 1 Bytes with Oxff to identify the
|
||||
// end of the variable buffer.
|
||||
//
|
||||
MaximumBufferSize += NewVariableSize;
|
||||
}
|
||||
|
||||
//
|
||||
// Reserve the 1 Bytes with Oxff to identify the
|
||||
// end of the variable buffer.
|
||||
//
|
||||
MaximumBufferSize += 1;
|
||||
ValidBuffer = AllocatePool (MaximumBufferSize);
|
||||
if (ValidBuffer == NULL) {
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
MaximumBufferSize += 1;
|
||||
ValidBuffer = AllocatePool (MaximumBufferSize);
|
||||
if (ValidBuffer == NULL) {
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// For NV variable reclaim, don't allocate pool here and just use mNvVariableCache
|
||||
// as the buffer to reduce SMRAM consumption for SMM variable driver.
|
||||
//
|
||||
MaximumBufferSize = mNvVariableCache->Size;
|
||||
ValidBuffer = (UINT8 *) mNvVariableCache;
|
||||
}
|
||||
|
||||
SetMem (ValidBuffer, MaximumBufferSize, 0xff);
|
||||
@@ -770,6 +779,7 @@ Reclaim (
|
||||
//
|
||||
SetMem ((UINT8 *) (UINTN) VariableBase, VariableStoreHeader->Size, 0xff);
|
||||
CopyMem ((UINT8 *) (UINTN) VariableBase, ValidBuffer, (UINTN) (CurrPtr - ValidBuffer));
|
||||
*LastVariableOffset = (UINTN) (CurrPtr - ValidBuffer);
|
||||
Status = EFI_SUCCESS;
|
||||
} else {
|
||||
//
|
||||
@@ -777,34 +787,37 @@ Reclaim (
|
||||
//
|
||||
Status = FtwVariableSpace (
|
||||
VariableBase,
|
||||
ValidBuffer,
|
||||
(UINTN) (CurrPtr - ValidBuffer)
|
||||
(VARIABLE_STORE_HEADER *) ValidBuffer
|
||||
);
|
||||
CopyMem (mNvVariableCache, (CHAR8 *)(UINTN)VariableBase, VariableStoreHeader->Size);
|
||||
}
|
||||
if (!EFI_ERROR (Status)) {
|
||||
*LastVariableOffset = (UINTN) (CurrPtr - ValidBuffer);
|
||||
if (!IsVolatile) {
|
||||
if (!EFI_ERROR (Status)) {
|
||||
*LastVariableOffset = (UINTN) (CurrPtr - ValidBuffer);
|
||||
mVariableModuleGlobal->HwErrVariableTotalSize = HwErrVariableTotalSize;
|
||||
mVariableModuleGlobal->CommonVariableTotalSize = CommonVariableTotalSize;
|
||||
}
|
||||
} else {
|
||||
NextVariable = GetStartPointer ((VARIABLE_STORE_HEADER *)(UINTN)VariableBase);
|
||||
while (IsValidVariableHeader (NextVariable)) {
|
||||
VariableSize = NextVariable->NameSize + NextVariable->DataSize + sizeof (VARIABLE_HEADER);
|
||||
if ((!IsVolatile) && ((Variable->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) == EFI_VARIABLE_HARDWARE_ERROR_RECORD)) {
|
||||
mVariableModuleGlobal->HwErrVariableTotalSize += HEADER_ALIGN (VariableSize);
|
||||
} else if ((!IsVolatile) && ((Variable->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) != EFI_VARIABLE_HARDWARE_ERROR_RECORD)) {
|
||||
mVariableModuleGlobal->CommonVariableTotalSize += HEADER_ALIGN (VariableSize);
|
||||
}
|
||||
} else {
|
||||
NextVariable = GetStartPointer ((VARIABLE_STORE_HEADER *)(UINTN)VariableBase);
|
||||
while (IsValidVariableHeader (NextVariable)) {
|
||||
VariableSize = NextVariable->NameSize + NextVariable->DataSize + sizeof (VARIABLE_HEADER);
|
||||
if ((Variable->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) == EFI_VARIABLE_HARDWARE_ERROR_RECORD) {
|
||||
mVariableModuleGlobal->HwErrVariableTotalSize += HEADER_ALIGN (VariableSize);
|
||||
} else if ((Variable->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) != EFI_VARIABLE_HARDWARE_ERROR_RECORD) {
|
||||
mVariableModuleGlobal->CommonVariableTotalSize += HEADER_ALIGN (VariableSize);
|
||||
}
|
||||
|
||||
NextVariable = GetNextVariablePtr (NextVariable);
|
||||
NextVariable = GetNextVariablePtr (NextVariable);
|
||||
}
|
||||
*LastVariableOffset = (UINTN) NextVariable - (UINTN) VariableBase;
|
||||
}
|
||||
*LastVariableOffset = (UINTN) NextVariable - (UINTN) VariableBase;
|
||||
}
|
||||
|
||||
Done:
|
||||
FreePool (ValidBuffer);
|
||||
if (IsVolatile) {
|
||||
FreePool (ValidBuffer);
|
||||
} else {
|
||||
//
|
||||
// For NV variable reclaim, we use mNvVariableCache as the buffer, so copy the data back.
|
||||
//
|
||||
CopyMem (mNvVariableCache, (UINT8 *)(UINTN)VariableBase, VariableStoreHeader->Size);
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
Reference in New Issue
Block a user