Reclaim occurs as late as possible before OS boot for keep enough space used by OS

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@4574 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
lgao4
2008-01-17 09:59:51 +00:00
parent c3f6b7b62e
commit 7800593dca

View File

@@ -1,7 +1,7 @@
/** @file /** @file
EFI Runtime Variable services. EFI Runtime Variable services.
Copyright (c) 2006 - 2007, Intel Corporation Copyright (c) 2006 - 2008, Intel Corporation
All rights reserved. This program and the accompanying materials All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License 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 which accompanies this distribution. The full text of the license may be found at
@@ -15,9 +15,7 @@
#include "Variable.h" #include "Variable.h"
VARIABLE_MODULE_GLOBAL *mVariableModuleGlobal;
VARIABLE_MODULE_GLOBAL mRuntimeData;
VARIABLE_MODULE_GLOBAL *mVariableModuleGlobal = &mRuntimeData;
EFI_EVENT mVirtualAddressChangeEvent = NULL; EFI_EVENT mVirtualAddressChangeEvent = NULL;
EFI_HANDLE mHandle = NULL; EFI_HANDLE mHandle = NULL;
@@ -1705,6 +1703,32 @@ RuntimeServiceQueryVariableInfo (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
VOID
EFIAPI
ReclaimForOS(
EFI_EVENT Event,
VOID *Context
)
{
UINT32 VarSize;
EFI_STATUS Status;
VarSize = ((VARIABLE_STORE_HEADER *) ((UINTN) mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase))->Size;
Status = EFI_SUCCESS;
//
// Check if the free area is blow a threshold
//
if ((VarSize - mVariableModuleGlobal->NonVolatileLastVariableOffset) < VARIABLE_RECLAIM_THRESHOLD) {
Status = Reclaim (
mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase,
&mVariableModuleGlobal->NonVolatileLastVariableOffset,
FALSE
);
ASSERT_EFI_ERROR (Status);
}
}
EFI_STATUS EFI_STATUS
VariableCommonInitialize ( VariableCommonInitialize (
IN EFI_HANDLE ImageHandle, IN EFI_HANDLE ImageHandle,
@@ -1746,7 +1770,16 @@ Returns:
UINT8 Data; UINT8 Data;
UINT64 VariableStoreBase; UINT64 VariableStoreBase;
UINT64 VariableStoreLength; UINT64 VariableStoreLength;
EFI_EVENT ReadyToBootEvent;
Status = EFI_SUCCESS;
//
// Allocate runtime memory for variable driver global structure.
//
mVariableModuleGlobal = AllocateRuntimePool (sizeof (VARIABLE_MODULE_GLOBAL));
if (mVariableModuleGlobal == NULL) {
return EFI_OUT_OF_RESOURCES;
}
EfiInitializeLock(&mVariableModuleGlobal->VariableGlobal.VariableServicesLock, TPL_NOTIFY); EfiInitializeLock(&mVariableModuleGlobal->VariableGlobal.VariableServicesLock, TPL_NOTIFY);
mVariableModuleGlobal->VariableGlobal.ReentrantState = 0; mVariableModuleGlobal->VariableGlobal.ReentrantState = 0;
@@ -1793,9 +1826,7 @@ Returns:
Status = gDS->GetMemorySpaceDescriptor (BaseAddress, &GcdDescriptor); Status = gDS->GetMemorySpaceDescriptor (BaseAddress, &GcdDescriptor);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
FreePool (mVariableModuleGlobal); goto Done;
FreePool (VolatileVariableStore);
return EFI_UNSUPPORTED;
} }
Status = gDS->SetMemorySpaceAttributes ( Status = gDS->SetMemorySpaceAttributes (
@@ -1804,9 +1835,7 @@ Returns:
GcdDescriptor.Attributes | EFI_MEMORY_RUNTIME GcdDescriptor.Attributes | EFI_MEMORY_RUNTIME
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
FreePool (mVariableModuleGlobal); goto Done;
FreePool (VolatileVariableStore);
return EFI_UNSUPPORTED;
} }
// //
// Get address of non volatile variable store base // Get address of non volatile variable store base
@@ -1854,7 +1883,7 @@ Returns:
ASSERT(VariableStoreHeader->Size == VariableStoreLength); ASSERT(VariableStoreHeader->Size == VariableStoreLength);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; goto Done;
} }
} }
@@ -1871,23 +1900,6 @@ Returns:
mVariableModuleGlobal->NonVolatileLastVariableOffset = (UINTN) NextVariable - (UINTN) CurrPtr; mVariableModuleGlobal->NonVolatileLastVariableOffset = (UINTN) NextVariable - (UINTN) CurrPtr;
//
// Check if the free area is blow a threshold
//
if ((((VARIABLE_STORE_HEADER *)((UINTN) CurrPtr))->Size - mVariableModuleGlobal->NonVolatileLastVariableOffset) < VARIABLE_RECLAIM_THRESHOLD) {
Status = Reclaim (
mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase,
&mVariableModuleGlobal->NonVolatileLastVariableOffset,
FALSE
);
}
if (EFI_ERROR (Status)) {
FreePool (mVariableModuleGlobal);
FreePool (VolatileVariableStore);
return Status;
}
// //
// Check if the free area is really free. // Check if the free area is really free.
// //
@@ -1902,11 +1914,27 @@ Returns:
&mVariableModuleGlobal->NonVolatileLastVariableOffset, &mVariableModuleGlobal->NonVolatileLastVariableOffset,
FALSE FALSE
); );
if (EFI_ERROR (Status)) {
goto Done;
}
break; break;
} }
} }
//
// Register the event handling function to reclaim variable for OS usage.
//
Status = EfiCreateEventReadyToBootEx (
TPL_NOTIFY,
ReclaimForOS,
NULL,
&ReadyToBootEvent
);
} }
Done:
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
FreePool (mVariableModuleGlobal); FreePool (mVariableModuleGlobal);
FreePool (VolatileVariableStore); FreePool (VolatileVariableStore);
@@ -1915,9 +1943,6 @@ Returns:
return Status; return Status;
} }
VOID VOID
EFIAPI EFIAPI
VariableClassAddressChangeEvent ( VariableClassAddressChangeEvent (