Add a lock to protect the critical region in Service APIs for UEFI Runtime Variable Service to prevent re-entrance of the variable service API from from different allowable TPL level. In UEFI 2.x and EFI 1.10 spec, EFI_TPL_CALLBACK is the allowable TPL level for Variable services.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2444 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
qwang12 2007-03-12 07:56:16 +00:00
parent c094abe585
commit 6ed71dcc32
12 changed files with 275 additions and 125 deletions

View File

@ -1,6 +1,6 @@
/*++ /*++
Copyright (c) 2006, Intel Corporation Copyright (c) 2006 - 2007, 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
@ -26,6 +26,37 @@ Revision History
// //
ESAL_VARIABLE_GLOBAL *mVariableModuleGlobal; ESAL_VARIABLE_GLOBAL *mVariableModuleGlobal;
//
// This is a temperary function which will be removed
// when EfiAcquireLock in UefiLib can handle the
// the call in UEFI Runtimer driver in RT phase.
//
VOID
AcquireLockOnlyAtBootTime (
IN EFI_LOCK *Lock
)
{
if (!EfiAtRuntime ()) {
EfiAcquireLock (Lock);
}
}
//
// This is a temperary function which will be removed
// when EfiAcquireLock in UefiLib can handle the
// the call in UEFI Runtimer driver in RT phase.
//
VOID
ReleaseLockOnlyAtBootTime (
IN EFI_LOCK *Lock
)
{
if (!EfiAtRuntime ()) {
EfiReleaseLock (Lock);
}
}
STATIC STATIC
UINT32 UINT32
EFIAPI EFIAPI
@ -197,6 +228,13 @@ Returns:
VARIABLE_STORE_HEADER *VariableStoreHeader[2]; VARIABLE_STORE_HEADER *VariableStoreHeader[2];
UINTN Index; UINTN Index;
//
// We aquire the lock at the entry of FindVariable as GetVariable, GetNextVariableName
// SetVariable all call FindVariable at entry point. Please move "Aquire Lock" to
// the correct places if this assumption does not hold TRUE anymore.
//
AcquireLockOnlyAtBootTime(&Global->VariableServicesLock);
// //
// 0: Non-Volatile, 1: Volatile // 0: Non-Volatile, 1: Volatile
// //
@ -293,7 +331,7 @@ Returns:
Status = FindVariable (VariableName, VendorGuid, &Variable, Global); Status = FindVariable (VariableName, VendorGuid, &Variable, Global);
if (Variable.CurrPtr == NULL || EFI_ERROR (Status)) { if (Variable.CurrPtr == NULL || EFI_ERROR (Status)) {
return Status; goto Done;
} }
// //
// Get data size // Get data size
@ -301,7 +339,8 @@ Returns:
VarDataSize = Variable.CurrPtr->DataSize; VarDataSize = Variable.CurrPtr->DataSize;
if (*DataSize >= VarDataSize) { if (*DataSize >= VarDataSize) {
if (Data == NULL) { if (Data == NULL) {
return EFI_INVALID_PARAMETER; Status = EFI_INVALID_PARAMETER;
goto Done;
} }
CopyMem (Data, GetVariableDataPtr (Variable.CurrPtr), VarDataSize); CopyMem (Data, GetVariableDataPtr (Variable.CurrPtr), VarDataSize);
@ -310,11 +349,17 @@ Returns:
} }
*DataSize = VarDataSize; *DataSize = VarDataSize;
return EFI_SUCCESS; Status = EFI_SUCCESS;
goto Done;
} else { } else {
*DataSize = VarDataSize; *DataSize = VarDataSize;
return EFI_BUFFER_TOO_SMALL; Status = EFI_BUFFER_TOO_SMALL;
goto Done;
} }
Done:
ReleaseLockOnlyAtBootTime (&Global->VariableServicesLock);
return Status;
} }
EFI_STATUS EFI_STATUS
@ -357,7 +402,7 @@ Returns:
Status = FindVariable (VariableName, VendorGuid, &Variable, Global); Status = FindVariable (VariableName, VendorGuid, &Variable, Global);
if (Variable.CurrPtr == NULL || EFI_ERROR (Status)) { if (Variable.CurrPtr == NULL || EFI_ERROR (Status)) {
return Status; goto Done;
} }
while (TRUE) { while (TRUE) {
@ -377,7 +422,8 @@ Returns:
Variable.StartPtr = (VARIABLE_HEADER *) ((UINTN) (Global->VolatileVariableBase + sizeof (VARIABLE_STORE_HEADER))); Variable.StartPtr = (VARIABLE_HEADER *) ((UINTN) (Global->VolatileVariableBase + sizeof (VARIABLE_STORE_HEADER)));
Variable.EndPtr = (VARIABLE_HEADER *) GetEndPointer ((VARIABLE_STORE_HEADER *) ((UINTN) Global->VolatileVariableBase)); Variable.EndPtr = (VARIABLE_HEADER *) GetEndPointer ((VARIABLE_STORE_HEADER *) ((UINTN) Global->VolatileVariableBase));
} else { } else {
goto Error; Status = EFI_NOT_FOUND;
goto Done;
} }
Variable.CurrPtr = Variable.StartPtr; Variable.CurrPtr = Variable.StartPtr;
@ -408,13 +454,15 @@ Returns:
} }
*VariableNameSize = VarNameSize; *VariableNameSize = VarNameSize;
return Status; goto Done;
} }
} }
} }
Error: Done:
return EFI_NOT_FOUND; ReleaseLockOnlyAtBootTime (&Global->VariableServicesLock);
return Status;
} }
EFI_STATUS EFI_STATUS
@ -470,36 +518,41 @@ Returns:
Status = FindVariable (VariableName, VendorGuid, &Variable, Global); Status = FindVariable (VariableName, VendorGuid, &Variable, Global);
if (Status == EFI_INVALID_PARAMETER) { if (Status == EFI_INVALID_PARAMETER) {
return Status; goto Done;
} else if (!EFI_ERROR (Status) && Variable.Volatile && EfiAtRuntime()) { } else if (!EFI_ERROR (Status) && Variable.Volatile && EfiAtRuntime()) {
// //
// If EfiAtRuntime and the variable is Volatile and Runtime Access, // If EfiAtRuntime and the variable is Volatile and Runtime Access,
// the volatile is ReadOnly, and SetVariable should be aborted and // the volatile is ReadOnly, and SetVariable should be aborted and
// return EFI_WRITE_PROTECTED. // return EFI_WRITE_PROTECTED.
// //
return EFI_WRITE_PROTECTED; Status = EFI_WRITE_PROTECTED;
goto Done;
} else if (sizeof (VARIABLE_HEADER) + (ArrayLength (VariableName) + DataSize) > MAX_VARIABLE_SIZE) { } else if (sizeof (VARIABLE_HEADER) + (ArrayLength (VariableName) + DataSize) > MAX_VARIABLE_SIZE) {
// //
// The size of the VariableName, including the Unicode Null in bytes plus // The size of the VariableName, including the Unicode Null in bytes plus
// the DataSize is limited to maximum size of MAX_VARIABLE_SIZE (1024) bytes. // the DataSize is limited to maximum size of MAX_VARIABLE_SIZE (1024) bytes.
// //
return EFI_INVALID_PARAMETER; Status = EFI_INVALID_PARAMETER;
goto Done;
} else if ((Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == EFI_VARIABLE_RUNTIME_ACCESS } else if ((Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == EFI_VARIABLE_RUNTIME_ACCESS
) { ) {
// //
// Make sure if runtime bit is set, boot service bit is set also // Make sure if runtime bit is set, boot service bit is set also
// //
return EFI_INVALID_PARAMETER; Status = EFI_INVALID_PARAMETER;
goto Done;
} else if (EfiAtRuntime () && Attributes && !(Attributes & EFI_VARIABLE_RUNTIME_ACCESS)) { } else if (EfiAtRuntime () && Attributes && !(Attributes & EFI_VARIABLE_RUNTIME_ACCESS)) {
// //
// Runtime but Attribute is not Runtime // Runtime but Attribute is not Runtime
// //
return EFI_INVALID_PARAMETER; Status = EFI_INVALID_PARAMETER;
goto Done;
} else if (EfiAtRuntime () && Attributes && !(Attributes & EFI_VARIABLE_NON_VOLATILE)) { } else if (EfiAtRuntime () && Attributes && !(Attributes & EFI_VARIABLE_NON_VOLATILE)) {
// //
// Cannot set volatile variable in Runtime // Cannot set volatile variable in Runtime
// //
return EFI_INVALID_PARAMETER; Status = EFI_INVALID_PARAMETER;
goto Done;
} else if (DataSize == 0 || (Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == 0) { } else if (DataSize == 0 || (Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == 0) {
// //
// Setting a data variable with no access, or zero DataSize attributes // Setting a data variable with no access, or zero DataSize attributes
@ -507,10 +560,12 @@ Returns:
// //
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
Variable.CurrPtr->State &= VAR_DELETED; Variable.CurrPtr->State &= VAR_DELETED;
return EFI_SUCCESS; Status = EFI_SUCCESS;
goto Done;
} }
return EFI_NOT_FOUND; Status = EFI_NOT_FOUND;
goto Done;
} else { } else {
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
// //
@ -520,7 +575,8 @@ Returns:
if (Variable.CurrPtr->DataSize == DataSize && if (Variable.CurrPtr->DataSize == DataSize &&
!CompareMem (Data, GetVariableDataPtr (Variable.CurrPtr), DataSize) !CompareMem (Data, GetVariableDataPtr (Variable.CurrPtr), DataSize)
) { ) {
return EFI_SUCCESS; Status = EFI_SUCCESS;
goto Done;
} else if (Variable.CurrPtr->State == VAR_ADDED) { } else if (Variable.CurrPtr->State == VAR_ADDED) {
// //
// Mark the old variable as in delete transition // Mark the old variable as in delete transition
@ -540,20 +596,23 @@ Returns:
if ((UINT32) (VarSize +*NonVolatileOffset) > if ((UINT32) (VarSize +*NonVolatileOffset) >
((VARIABLE_STORE_HEADER *) ((UINTN) (Global->NonVolatileVariableBase)))->Size ((VARIABLE_STORE_HEADER *) ((UINTN) (Global->NonVolatileVariableBase)))->Size
) { ) {
return EFI_OUT_OF_RESOURCES; Status = EFI_OUT_OF_RESOURCES;
goto Done;
} }
NextVariable = (VARIABLE_HEADER *) (UINT8 *) (*NonVolatileOffset + (UINTN) Global->NonVolatileVariableBase); NextVariable = (VARIABLE_HEADER *) (UINT8 *) (*NonVolatileOffset + (UINTN) Global->NonVolatileVariableBase);
*NonVolatileOffset = *NonVolatileOffset + VarSize; *NonVolatileOffset = *NonVolatileOffset + VarSize;
} else { } else {
if (EfiAtRuntime ()) { if (EfiAtRuntime ()) {
return EFI_INVALID_PARAMETER; Status = EFI_INVALID_PARAMETER;
goto Done;
} }
if ((UINT32) (VarSize +*VolatileOffset) > if ((UINT32) (VarSize +*VolatileOffset) >
((VARIABLE_STORE_HEADER *) ((UINTN) (Global->VolatileVariableBase)))->Size ((VARIABLE_STORE_HEADER *) ((UINTN) (Global->VolatileVariableBase)))->Size
) { ) {
return EFI_OUT_OF_RESOURCES; Status = EFI_OUT_OF_RESOURCES;
goto Done;
} }
NextVariable = (VARIABLE_HEADER *) (UINT8 *) (*VolatileOffset + (UINTN) Global->VolatileVariableBase); NextVariable = (VARIABLE_HEADER *) (UINT8 *) (*VolatileOffset + (UINTN) Global->VolatileVariableBase);
@ -593,7 +652,10 @@ Returns:
} }
} }
return EFI_SUCCESS; Status = EFI_SUCCESS;
Done:
ReleaseLockOnlyAtBootTime (&Global->VariableServicesLock);
return Status;
} }
#if (EFI_SPECIFICATION_VERSION >= 0x00020000) #if (EFI_SPECIFICATION_VERSION >= 0x00020000)
@ -666,6 +728,8 @@ Returns:
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
AcquireLockOnlyAtBootTime(&Global->VariableServicesLock);
if((Attributes & EFI_VARIABLE_NON_VOLATILE) == 0) { if((Attributes & EFI_VARIABLE_NON_VOLATILE) == 0) {
// //
// Query is Volatile related. // Query is Volatile related.
@ -716,6 +780,7 @@ Returns:
Variable = NextVariable; Variable = NextVariable;
} }
ReleaseLockOnlyAtBootTime (&Global->VariableServicesLock);
return EFI_SUCCESS; return EFI_SUCCESS;
} }
#endif #endif
@ -796,11 +861,14 @@ Returns:
if (NULL == mVariableModuleGlobal) { if (NULL == mVariableModuleGlobal) {
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
EfiInitializeLock(&mVariableModuleGlobal->VariableGlobal[Physical].VariableServicesLock, EFI_TPL_CALLBACK);
// //
// Intialize volatile variable store // Intialize volatile variable store
// //
Status = InitializeVariableStore ( Status = InitializeVariableStore (
&mVariableModuleGlobal->VariableBase[Physical].VolatileVariableBase, &mVariableModuleGlobal->VariableGlobal[Physical].VolatileVariableBase,
&mVariableModuleGlobal->VolatileLastVariableOffset &mVariableModuleGlobal->VolatileLastVariableOffset
); );
@ -811,7 +879,7 @@ Returns:
// Intialize non volatile variable store // Intialize non volatile variable store
// //
Status = InitializeVariableStore ( Status = InitializeVariableStore (
&mVariableModuleGlobal->VariableBase[Physical].NonVolatileVariableBase, &mVariableModuleGlobal->VariableGlobal[Physical].NonVolatileVariableBase,
&mVariableModuleGlobal->NonVolatileLastVariableOffset &mVariableModuleGlobal->NonVolatileLastVariableOffset
); );

View File

@ -40,6 +40,9 @@
<LibraryClass Usage="ALWAYS_CONSUMED"> <LibraryClass Usage="ALWAYS_CONSUMED">
<Keyword>UefiBootServicesTableLib</Keyword> <Keyword>UefiBootServicesTableLib</Keyword>
</LibraryClass> </LibraryClass>
<LibraryClass Usage="ALWAYS_CONSUMED">
<Keyword>UefiLib</Keyword>
</LibraryClass>
</LibraryClassDefinitions> </LibraryClassDefinitions>
<SourceFiles> <SourceFiles>
<Filename>Variable.h</Filename> <Filename>Variable.h</Filename>

View File

@ -43,6 +43,9 @@
<LibraryClass Usage="ALWAYS_CONSUMED"> <LibraryClass Usage="ALWAYS_CONSUMED">
<Keyword>UefiBootServicesTableLib</Keyword> <Keyword>UefiBootServicesTableLib</Keyword>
</LibraryClass> </LibraryClass>
<LibraryClass Usage="ALWAYS_CONSUMED">
<Keyword>UefiLib</Keyword>
</LibraryClass>
</LibraryClassDefinitions> </LibraryClassDefinitions>
<SourceFiles> <SourceFiles>
<Filename>Variable.h</Filename> <Filename>Variable.h</Filename>

View File

@ -1,6 +1,6 @@
/*++ /*++
Copyright (c) 2006, Intel Corporation Copyright (c) 2006 - 2007, 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
@ -51,7 +51,7 @@ Returns:
Attributes OPTIONAL, Attributes OPTIONAL,
DataSize, DataSize,
Data, Data,
&mVariableModuleGlobal->VariableBase[Physical], &mVariableModuleGlobal->VariableGlobal[Physical],
mVariableModuleGlobal->FvbInstance mVariableModuleGlobal->FvbInstance
); );
} }
@ -77,7 +77,7 @@ Returns:
VariableNameSize, VariableNameSize,
VariableName, VariableName,
VendorGuid, VendorGuid,
&mVariableModuleGlobal->VariableBase[Physical], &mVariableModuleGlobal->VariableGlobal[Physical],
mVariableModuleGlobal->FvbInstance mVariableModuleGlobal->FvbInstance
); );
} }
@ -107,7 +107,7 @@ Returns:
Attributes, Attributes,
DataSize, DataSize,
Data, Data,
&mVariableModuleGlobal->VariableBase[Physical], &mVariableModuleGlobal->VariableGlobal[Physical],
&mVariableModuleGlobal->VolatileLastVariableOffset, &mVariableModuleGlobal->VolatileLastVariableOffset,
&mVariableModuleGlobal->NonVolatileLastVariableOffset, &mVariableModuleGlobal->NonVolatileLastVariableOffset,
mVariableModuleGlobal->FvbInstance mVariableModuleGlobal->FvbInstance
@ -138,7 +138,7 @@ Returns:
MaximumVariableStorageSize, MaximumVariableStorageSize,
RemainingVariableStorageSize, RemainingVariableStorageSize,
MaximumVariableSize, MaximumVariableSize,
&mVariableModuleGlobal->VariableBase[Physical], &mVariableModuleGlobal->VariableGlobal[Physical],
mVariableModuleGlobal->FvbInstance mVariableModuleGlobal->FvbInstance
); );
} }
@ -162,11 +162,11 @@ Returns:
{ {
EfiConvertPointer ( EfiConvertPointer (
0x0, 0x0,
(VOID **) &mVariableModuleGlobal->VariableBase[Physical].NonVolatileVariableBase (VOID **) &mVariableModuleGlobal->VariableGlobal[Physical].NonVolatileVariableBase
); );
EfiConvertPointer ( EfiConvertPointer (
0x0, 0x0,
(VOID **) &mVariableModuleGlobal->VariableBase[Physical].VolatileVariableBase (VOID **) &mVariableModuleGlobal->VariableGlobal[Physical].VolatileVariableBase
); );
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal); EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal);
} }

View File

@ -60,7 +60,7 @@ Returns:
(UINT32 *) Arg4, (UINT32 *) Arg4,
(UINTN *) Arg5, (UINTN *) Arg5,
(VOID *) Arg6, (VOID *) Arg6,
&Global->VariableBase[VirtualMode], &Global->VariableGlobal[VirtualMode],
Global->FvbInstance Global->FvbInstance
); );
return ReturnVal; return ReturnVal;
@ -70,7 +70,7 @@ Returns:
(UINTN *) Arg2, (UINTN *) Arg2,
(CHAR16 *) Arg3, (CHAR16 *) Arg3,
(EFI_GUID *) Arg4, (EFI_GUID *) Arg4,
&Global->VariableBase[VirtualMode], &Global->VariableGlobal[VirtualMode],
Global->FvbInstance Global->FvbInstance
); );
return ReturnVal; return ReturnVal;
@ -82,7 +82,7 @@ Returns:
(UINT32) Arg4, (UINT32) Arg4,
(UINTN) Arg5, (UINTN) Arg5,
(VOID *) Arg6, (VOID *) Arg6,
&Global->VariableBase[VirtualMode], &Global->VariableGlobal[VirtualMode],
(UINTN *) &Global->VolatileLastVariableOffset, (UINTN *) &Global->VolatileLastVariableOffset,
(UINTN *) &Global->NonVolatileLastVariableOffset, (UINTN *) &Global->NonVolatileLastVariableOffset,
Global->FvbInstance Global->FvbInstance
@ -96,7 +96,7 @@ Returns:
(UINT64 *) Arg3, (UINT64 *) Arg3,
(UINT64 *) Arg4, (UINT64 *) Arg4,
(UINT64 *) Arg5, (UINT64 *) Arg5,
&Global->VariableBase[VirtualMode], &Global->VariableGlobal[VirtualMode],
Global->FvbInstance Global->FvbInstance
); );
return ReturnVal; return ReturnVal;
@ -125,18 +125,18 @@ Returns:
--*/ --*/
{ {
CopyMem ( CopyMem (
&mVariableModuleGlobal->VariableBase[Virtual], &mVariableModuleGlobal->VariableGlobal[Virtual],
&mVariableModuleGlobal->VariableBase[Physical], &mVariableModuleGlobal->VariableGlobal[Physical],
sizeof (VARIABLE_GLOBAL) sizeof (VARIABLE_GLOBAL)
); );
EfiConvertPointer ( EfiConvertPointer (
0x0, 0x0,
(VOID **) &mVariableModuleGlobal->VariableBase[Virtual].NonVolatileVariableBase (VOID **) &mVariableModuleGlobal->VariableGlobal[Virtual].NonVolatileVariableBase
); );
EfiConvertPointer ( EfiConvertPointer (
0x0, 0x0,
(VOID **) &mVariableModuleGlobal->VariableBase[Virtual].VolatileVariableBase (VOID **) &mVariableModuleGlobal->VariableGlobal[Virtual].VolatileVariableBase
); );
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal); EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal);
} }

View File

@ -1,6 +1,6 @@
/*++ /*++
Copyright (c) 2006, Intel Corporation Copyright (c) 2006 - 2007, 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
@ -65,10 +65,11 @@ typedef struct {
typedef struct { typedef struct {
EFI_PHYSICAL_ADDRESS VolatileVariableBase; EFI_PHYSICAL_ADDRESS VolatileVariableBase;
EFI_PHYSICAL_ADDRESS NonVolatileVariableBase; EFI_PHYSICAL_ADDRESS NonVolatileVariableBase;
EFI_LOCK VariableServicesLock;
} VARIABLE_GLOBAL; } VARIABLE_GLOBAL;
typedef struct { typedef struct {
VARIABLE_GLOBAL VariableBase[2]; VARIABLE_GLOBAL VariableGlobal[2];
UINTN VolatileLastVariableOffset; UINTN VolatileLastVariableOffset;
UINTN NonVolatileLastVariableOffset; UINTN NonVolatileLastVariableOffset;
UINT32 FvbInstance; UINT32 FvbInstance;

View File

@ -1,6 +1,6 @@
/*++ /*++
Copyright (c) 2006, Intel Corporation Copyright (c) 2006 - 2007, 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
@ -51,7 +51,7 @@ Returns:
Attributes OPTIONAL, Attributes OPTIONAL,
DataSize, DataSize,
Data, Data,
&mVariableModuleGlobal->VariableBase[Physical], &mVariableModuleGlobal->VariableGlobal[Physical],
mVariableModuleGlobal->FvbInstance mVariableModuleGlobal->FvbInstance
); );
} }
@ -77,7 +77,7 @@ Returns:
VariableNameSize, VariableNameSize,
VariableName, VariableName,
VendorGuid, VendorGuid,
&mVariableModuleGlobal->VariableBase[Physical], &mVariableModuleGlobal->VariableGlobal[Physical],
mVariableModuleGlobal->FvbInstance mVariableModuleGlobal->FvbInstance
); );
} }
@ -107,7 +107,7 @@ Returns:
Attributes, Attributes,
DataSize, DataSize,
Data, Data,
&mVariableModuleGlobal->VariableBase[Physical], &mVariableModuleGlobal->VariableGlobal[Physical],
&mVariableModuleGlobal->VolatileLastVariableOffset, &mVariableModuleGlobal->VolatileLastVariableOffset,
&mVariableModuleGlobal->NonVolatileLastVariableOffset, &mVariableModuleGlobal->NonVolatileLastVariableOffset,
mVariableModuleGlobal->FvbInstance mVariableModuleGlobal->FvbInstance
@ -138,7 +138,7 @@ Returns:
MaximumVariableStorageSize, MaximumVariableStorageSize,
RemainingVariableStorageSize, RemainingVariableStorageSize,
MaximumVariableSize, MaximumVariableSize,
&mVariableModuleGlobal->VariableBase[Physical], &mVariableModuleGlobal->VariableGlobal[Physical],
mVariableModuleGlobal->FvbInstance mVariableModuleGlobal->FvbInstance
); );
} }
@ -162,11 +162,11 @@ Returns:
{ {
EfiConvertPointer ( EfiConvertPointer (
0x0, 0x0,
(VOID **) &mVariableModuleGlobal->VariableBase[Physical].NonVolatileVariableBase (VOID **) &mVariableModuleGlobal->VariableGlobal[Physical].NonVolatileVariableBase
); );
EfiConvertPointer ( EfiConvertPointer (
0x0, 0x0,
(VOID **) &mVariableModuleGlobal->VariableBase[Physical].VolatileVariableBase (VOID **) &mVariableModuleGlobal->VariableGlobal[Physical].VolatileVariableBase
); );
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal); EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal);
} }

View File

@ -1,6 +1,6 @@
/*++ /*++
Copyright (c) 2006, Intel Corporation Copyright (c) 2006 - 2007, 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
@ -60,7 +60,7 @@ Returns:
(UINT32 *) Arg4, (UINT32 *) Arg4,
(UINTN *) Arg5, (UINTN *) Arg5,
(VOID *) Arg6, (VOID *) Arg6,
&Global->VariableBase[VirtualMode], &Global->VariableGlobal[VirtualMode],
Global->FvbInstance Global->FvbInstance
); );
return ReturnVal; return ReturnVal;
@ -70,7 +70,7 @@ Returns:
(UINTN *) Arg2, (UINTN *) Arg2,
(CHAR16 *) Arg3, (CHAR16 *) Arg3,
(EFI_GUID *) Arg4, (EFI_GUID *) Arg4,
&Global->VariableBase[VirtualMode], &Global->VariableGlobal[VirtualMode],
Global->FvbInstance Global->FvbInstance
); );
return ReturnVal; return ReturnVal;
@ -82,7 +82,7 @@ Returns:
(UINT32) Arg4, (UINT32) Arg4,
(UINTN) Arg5, (UINTN) Arg5,
(VOID *) Arg6, (VOID *) Arg6,
&Global->VariableBase[VirtualMode], &Global->VariableGlobal[VirtualMode],
(UINTN *) &Global->VolatileLastVariableOffset, (UINTN *) &Global->VolatileLastVariableOffset,
(UINTN *) &Global->NonVolatileLastVariableOffset, (UINTN *) &Global->NonVolatileLastVariableOffset,
Global->FvbInstance Global->FvbInstance
@ -96,7 +96,7 @@ Returns:
(UINT64 *) Arg3, (UINT64 *) Arg3,
(UINT64 *) Arg4, (UINT64 *) Arg4,
(UINT64 *) Arg5, (UINT64 *) Arg5,
&Global->VariableBase[VirtualMode], &Global->VariableGlobal[VirtualMode],
Global->FvbInstance Global->FvbInstance
); );
return ReturnVal; return ReturnVal;
@ -125,18 +125,18 @@ Returns:
--*/ --*/
{ {
CopyMem ( CopyMem (
&mVariableModuleGlobal->VariableBase[Virtual], &mVariableModuleGlobal->VariableGlobal[Virtual],
&mVariableModuleGlobal->VariableBase[Physical], &mVariableModuleGlobal->VariableGlobal[Physical],
sizeof (VARIABLE_GLOBAL) sizeof (VARIABLE_GLOBAL)
); );
EfiConvertPointer ( EfiConvertPointer (
0x0, 0x0,
(VOID **) &mVariableModuleGlobal->VariableBase[Virtual].NonVolatileVariableBase (VOID **) &mVariableModuleGlobal->VariableGlobal[Virtual].NonVolatileVariableBase
); );
EfiConvertPointer ( EfiConvertPointer (
0x0, 0x0,
(VOID **) &mVariableModuleGlobal->VariableBase[Virtual].VolatileVariableBase (VOID **) &mVariableModuleGlobal->VariableGlobal[Virtual].VolatileVariableBase
); );
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal); EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal);
} }

View File

@ -1,6 +1,6 @@
/*++ /*++
Copyright (c) 2006, Intel Corporation Copyright (c) 2006 - 2007, 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
@ -27,6 +27,36 @@ Revision History
// //
ESAL_VARIABLE_GLOBAL *mVariableModuleGlobal; ESAL_VARIABLE_GLOBAL *mVariableModuleGlobal;
//
// This is a temperary function which will be removed
// when EfiAcquireLock in UefiLib can handle the
// the call in UEFI Runtimer driver in RT phase.
//
VOID
AcquireLockOnlyAtBootTime (
IN EFI_LOCK *Lock
)
{
if (!EfiAtRuntime ()) {
EfiAcquireLock (Lock);
}
}
//
// This is a temperary function which will be removed
// when EfiAcquireLock in UefiLib can handle the
// the call in UEFI Runtimer driver in RT phase.
//
VOID
ReleaseLockOnlyAtBootTime (
IN EFI_LOCK *Lock
)
{
if (!EfiAtRuntime ()) {
EfiReleaseLock (Lock);
}
}
STATIC STATIC
UINT32 UINT32
EFIAPI EFIAPI
@ -529,6 +559,13 @@ Returns:
VARIABLE_STORE_HEADER *VariableStoreHeader[2]; VARIABLE_STORE_HEADER *VariableStoreHeader[2];
UINTN Index; UINTN Index;
//
// We aquire the lock at the entry of FindVariable as GetVariable, GetNextVariableName
// SetVariable all call FindVariable at entry point. Please move "Aquire Lock" to
// the correct places if this assumption does not hold TRUE anymore.
//
AcquireLockOnlyAtBootTime(&Global->VariableServicesLock);
// //
// 0: Non-Volatile, 1: Volatile // 0: Non-Volatile, 1: Volatile
// //
@ -631,7 +668,7 @@ Returns:
Status = FindVariable (VariableName, VendorGuid, &Variable, Global); Status = FindVariable (VariableName, VendorGuid, &Variable, Global);
if (Variable.CurrPtr == NULL || EFI_ERROR (Status)) { if (Variable.CurrPtr == NULL || EFI_ERROR (Status)) {
return Status; goto Done;
} }
// //
// Get data size // Get data size
@ -639,7 +676,8 @@ Returns:
VarDataSize = Variable.CurrPtr->DataSize; VarDataSize = Variable.CurrPtr->DataSize;
if (*DataSize >= VarDataSize) { if (*DataSize >= VarDataSize) {
if (Data == NULL) { if (Data == NULL) {
return EFI_INVALID_PARAMETER; Status = EFI_INVALID_PARAMETER;
goto Done;
} }
CopyMem (Data, GetVariableDataPtr (Variable.CurrPtr), VarDataSize); CopyMem (Data, GetVariableDataPtr (Variable.CurrPtr), VarDataSize);
@ -648,11 +686,17 @@ Returns:
} }
*DataSize = VarDataSize; *DataSize = VarDataSize;
return EFI_SUCCESS; Status = EFI_SUCCESS;
goto Done;
} else { } else {
*DataSize = VarDataSize; *DataSize = VarDataSize;
return EFI_BUFFER_TOO_SMALL; Status = EFI_BUFFER_TOO_SMALL;
goto Done;
} }
Done:
ReleaseLockOnlyAtBootTime (&Global->VariableServicesLock);
return Status;
} }
EFI_STATUS EFI_STATUS
@ -695,7 +739,7 @@ Returns:
Status = FindVariable (VariableName, VendorGuid, &Variable, Global); Status = FindVariable (VariableName, VendorGuid, &Variable, Global);
if (Variable.CurrPtr == NULL || EFI_ERROR (Status)) { if (Variable.CurrPtr == NULL || EFI_ERROR (Status)) {
return Status; goto Done;
} }
if (VariableName[0] != 0) { if (VariableName[0] != 0) {
@ -716,7 +760,8 @@ Returns:
Variable.StartPtr = (VARIABLE_HEADER *) ((UINTN) (Global->VolatileVariableBase + sizeof (VARIABLE_STORE_HEADER))); Variable.StartPtr = (VARIABLE_HEADER *) ((UINTN) (Global->VolatileVariableBase + sizeof (VARIABLE_STORE_HEADER)));
Variable.EndPtr = (VARIABLE_HEADER *) GetEndPointer ((VARIABLE_STORE_HEADER *) ((UINTN) Global->VolatileVariableBase)); Variable.EndPtr = (VARIABLE_HEADER *) GetEndPointer ((VARIABLE_STORE_HEADER *) ((UINTN) Global->VolatileVariableBase));
} else { } else {
goto Error; Status = EFI_NOT_FOUND;
goto Done;
} }
Variable.CurrPtr = Variable.StartPtr; Variable.CurrPtr = Variable.StartPtr;
@ -747,15 +792,16 @@ Returns:
} }
*VariableNameSize = VarNameSize; *VariableNameSize = VarNameSize;
return Status; goto Done;
} }
} }
Variable.CurrPtr = GetNextVariablePtr (Variable.CurrPtr); Variable.CurrPtr = GetNextVariablePtr (Variable.CurrPtr);
} }
Error: Done:
return EFI_NOT_FOUND; ReleaseLockOnlyAtBootTime (&Global->VariableServicesLock);
return Status;
} }
EFI_STATUS EFI_STATUS
@ -819,41 +865,47 @@ Returns:
Status = FindVariable (VariableName, VendorGuid, &Variable, Global); Status = FindVariable (VariableName, VendorGuid, &Variable, Global);
if (Status == EFI_INVALID_PARAMETER) { if (Status == EFI_INVALID_PARAMETER) {
return Status; goto Done;
} else if (!EFI_ERROR (Status) && Variable.Volatile && EfiAtRuntime()) { } else if (!EFI_ERROR (Status) && Variable.Volatile && EfiAtRuntime()) {
// //
// If EfiAtRuntime and the variable is Volatile and Runtime Access, // If EfiAtRuntime and the variable is Volatile and Runtime Access,
// the volatile is ReadOnly, and SetVariable should be aborted and // the volatile is ReadOnly, and SetVariable should be aborted and
// return EFI_WRITE_PROTECTED. // return EFI_WRITE_PROTECTED.
// //
return EFI_WRITE_PROTECTED; Status = EFI_WRITE_PROTECTED;
goto Done;
} else if (sizeof (VARIABLE_HEADER) + ArrayLength (VariableName) + DataSize > MAX_VARIABLE_SIZE) { } else if (sizeof (VARIABLE_HEADER) + ArrayLength (VariableName) + DataSize > MAX_VARIABLE_SIZE) {
// //
// The size of the VariableName, including the Unicode Null in bytes plus // The size of the VariableName, including the Unicode Null in bytes plus
// the DataSize is limited to maximum size of MAX_VARIABLE_SIZE (1024) bytes. // the DataSize is limited to maximum size of MAX_VARIABLE_SIZE (1024) bytes.
// //
return EFI_INVALID_PARAMETER; Status = EFI_INVALID_PARAMETER;
goto Done;
} else if (Attributes == EFI_VARIABLE_NON_VOLATILE) { } else if (Attributes == EFI_VARIABLE_NON_VOLATILE) {
// //
// Make sure not only EFI_VARIABLE_NON_VOLATILE is set // Make sure not only EFI_VARIABLE_NON_VOLATILE is set
// //
return EFI_INVALID_PARAMETER; Status = EFI_INVALID_PARAMETER;
goto Done;
} else if ((Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == } else if ((Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) ==
EFI_VARIABLE_RUNTIME_ACCESS) { EFI_VARIABLE_RUNTIME_ACCESS) {
// //
// Make sure if runtime bit is set, boot service bit is set also // Make sure if runtime bit is set, boot service bit is set also
// //
return EFI_INVALID_PARAMETER; Status = EFI_INVALID_PARAMETER;
goto Done;
} else if (EfiAtRuntime () && Attributes && !(Attributes & EFI_VARIABLE_RUNTIME_ACCESS)) { } else if (EfiAtRuntime () && Attributes && !(Attributes & EFI_VARIABLE_RUNTIME_ACCESS)) {
// //
// Runtime but Attribute is not Runtime // Runtime but Attribute is not Runtime
// //
return EFI_INVALID_PARAMETER; Status = EFI_INVALID_PARAMETER;
goto Done;
} else if (EfiAtRuntime () && Attributes && !(Attributes & EFI_VARIABLE_NON_VOLATILE)) { } else if (EfiAtRuntime () && Attributes && !(Attributes & EFI_VARIABLE_NON_VOLATILE)) {
// //
// Cannot set volatile variable in Runtime // Cannot set volatile variable in Runtime
// //
return EFI_INVALID_PARAMETER; Status = EFI_INVALID_PARAMETER;
goto Done;
} else if (DataSize == 0 || (Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == 0) { } else if (DataSize == 0 || (Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == 0) {
// //
// Setting a data variable with no access, or zero DataSize attributes // Setting a data variable with no access, or zero DataSize attributes
@ -873,13 +925,15 @@ Returns:
&State &State
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; goto Done;
} }
return EFI_SUCCESS; Status = EFI_SUCCESS;
goto Done;
} }
return EFI_NOT_FOUND; Status = EFI_NOT_FOUND;
goto Done;
} else { } else {
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
// //
@ -889,7 +943,8 @@ Returns:
if (Variable.CurrPtr->DataSize == DataSize && if (Variable.CurrPtr->DataSize == DataSize &&
!CompareMem (Data, GetVariableDataPtr (Variable.CurrPtr), DataSize) !CompareMem (Data, GetVariableDataPtr (Variable.CurrPtr), DataSize)
) { ) {
return EFI_SUCCESS; Status = EFI_SUCCESS;
goto Done;
} else if (Variable.CurrPtr->State == VAR_ADDED) { } else if (Variable.CurrPtr->State == VAR_ADDED) {
// //
// Mark the old variable as in delete transition // Mark the old variable as in delete transition
@ -907,7 +962,7 @@ Returns:
&State &State
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; goto Done;
} }
} }
} }
@ -959,14 +1014,15 @@ Returns:
((VARIABLE_STORE_HEADER *) ((UINTN) (Global->NonVolatileVariableBase)))->Size ((VARIABLE_STORE_HEADER *) ((UINTN) (Global->NonVolatileVariableBase)))->Size
) { ) {
if (EfiAtRuntime ()) { if (EfiAtRuntime ()) {
return EFI_OUT_OF_RESOURCES; Status = EFI_OUT_OF_RESOURCES;
goto Done;
} }
// //
// Perform garbage collection & reclaim operation // Perform garbage collection & reclaim operation
// //
Status = Reclaim (Global->NonVolatileVariableBase, NonVolatileOffset, FALSE); Status = Reclaim (Global->NonVolatileVariableBase, NonVolatileOffset, FALSE);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; goto Done;
} }
// //
// If still no enough space, return out of resources // If still no enough space, return out of resources
@ -974,7 +1030,8 @@ Returns:
if ((UINT32) (VarSize +*NonVolatileOffset) > if ((UINT32) (VarSize +*NonVolatileOffset) >
((VARIABLE_STORE_HEADER *) ((UINTN) (Global->NonVolatileVariableBase)))->Size ((VARIABLE_STORE_HEADER *) ((UINTN) (Global->NonVolatileVariableBase)))->Size
) { ) {
return EFI_OUT_OF_RESOURCES; Status = EFI_OUT_OF_RESOURCES;
goto Done;
} }
Reclaimed = TRUE; Reclaimed = TRUE;
@ -999,7 +1056,7 @@ Returns:
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; goto Done;
} }
// //
// Step 2: // Step 2:
@ -1015,7 +1072,7 @@ Returns:
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; goto Done;
} }
// //
// Step 3: // Step 3:
@ -1032,14 +1089,15 @@ Returns:
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; goto Done;
} }
*NonVolatileOffset = *NonVolatileOffset + VarSize; *NonVolatileOffset = *NonVolatileOffset + VarSize;
} else { } else {
if (EfiAtRuntime ()) { if (EfiAtRuntime ()) {
return EFI_INVALID_PARAMETER; Status = EFI_INVALID_PARAMETER;
goto Done;
} }
if ((UINT32) (VarSize +*VolatileOffset) > if ((UINT32) (VarSize +*VolatileOffset) >
@ -1050,7 +1108,7 @@ Returns:
// //
Status = Reclaim (Global->VolatileVariableBase, VolatileOffset, TRUE); Status = Reclaim (Global->VolatileVariableBase, VolatileOffset, TRUE);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; goto Done;
} }
// //
// If still no enough space, return out of resources // If still no enough space, return out of resources
@ -1058,7 +1116,8 @@ Returns:
if ((UINT32) (VarSize +*VolatileOffset) > if ((UINT32) (VarSize +*VolatileOffset) >
((VARIABLE_STORE_HEADER *) ((UINTN) (Global->VolatileVariableBase)))->Size ((VARIABLE_STORE_HEADER *) ((UINTN) (Global->VolatileVariableBase)))->Size
) { ) {
return EFI_OUT_OF_RESOURCES; Status = EFI_OUT_OF_RESOURCES;
goto Done;
} }
Reclaimed = TRUE; Reclaimed = TRUE;
@ -1076,7 +1135,7 @@ Returns:
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; goto Done;
} }
*VolatileOffset = *VolatileOffset + VarSize; *VolatileOffset = *VolatileOffset + VarSize;
@ -1099,12 +1158,15 @@ Returns:
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; goto Done;
} }
} }
} }
return EFI_SUCCESS; Status = EFI_SUCCESS;
Done:
ReleaseLockOnlyAtBootTime (&Global->VariableServicesLock);
return Status;
} }
#if (EFI_SPECIFICATION_VERSION >= 0x00020000) #if (EFI_SPECIFICATION_VERSION >= 0x00020000)
@ -1172,6 +1234,8 @@ Returns:
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
AcquireLockOnlyAtBootTime(&Global->VariableServicesLock);
if((Attributes & EFI_VARIABLE_NON_VOLATILE) == 0) { if((Attributes & EFI_VARIABLE_NON_VOLATILE) == 0) {
// //
// Query is Volatile related. // Query is Volatile related.
@ -1232,6 +1296,7 @@ Returns:
Variable = NextVariable; Variable = NextVariable;
} }
ReleaseLockOnlyAtBootTime (&Global->VariableServicesLock);
return EFI_SUCCESS; return EFI_SUCCESS;
} }
#endif #endif
@ -1289,6 +1354,9 @@ Returns:
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
EfiInitializeLock(&mVariableModuleGlobal->VariableGlobal[Physical].VariableServicesLock, EFI_TPL_CALLBACK);
// //
// Allocate memory for volatile variable store // Allocate memory for volatile variable store
// //
@ -1308,7 +1376,7 @@ Returns:
// //
// Variable Specific Data // Variable Specific Data
// //
mVariableModuleGlobal->VariableBase[Physical].VolatileVariableBase = (EFI_PHYSICAL_ADDRESS) (UINTN) VolatileVariableStore; mVariableModuleGlobal->VariableGlobal[Physical].VolatileVariableBase = (EFI_PHYSICAL_ADDRESS) (UINTN) VolatileVariableStore;
mVariableModuleGlobal->VolatileLastVariableOffset = sizeof (VARIABLE_STORE_HEADER); mVariableModuleGlobal->VolatileLastVariableOffset = sizeof (VARIABLE_STORE_HEADER);
VolatileVariableStore->Signature = VARIABLE_STORE_SIGNATURE; VolatileVariableStore->Signature = VARIABLE_STORE_SIGNATURE;
@ -1354,7 +1422,7 @@ Returns:
// //
// Get address of non volatile variable store base // Get address of non volatile variable store base
// //
mVariableModuleGlobal->VariableBase[Physical].NonVolatileVariableBase = VariableStoreEntry.Base; mVariableModuleGlobal->VariableGlobal[Physical].NonVolatileVariableBase = VariableStoreEntry.Base;
// //
// Check Integrity // Check Integrity
@ -1363,7 +1431,7 @@ Returns:
// Find the Correct Instance of the FV Block Service. // Find the Correct Instance of the FV Block Service.
// //
Instance = 0; Instance = 0;
CurrPtr = (CHAR8 *) ((UINTN) mVariableModuleGlobal->VariableBase[Physical].NonVolatileVariableBase); CurrPtr = (CHAR8 *) ((UINTN) mVariableModuleGlobal->VariableGlobal[Physical].NonVolatileVariableBase);
while (EfiFvbGetPhysicalAddress (Instance, &FvVolHdr) == EFI_SUCCESS) { while (EfiFvbGetPhysicalAddress (Instance, &FvVolHdr) == EFI_SUCCESS) {
FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *) ((UINTN) FvVolHdr); FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *) ((UINTN) FvVolHdr);
if (CurrPtr >= (CHAR8 *) FwVolHeader && CurrPtr < (((CHAR8 *) FwVolHeader) + FwVolHeader->FvLength)) { if (CurrPtr >= (CHAR8 *) FwVolHeader && CurrPtr < (((CHAR8 *) FwVolHeader) + FwVolHeader->FvLength)) {
@ -1378,7 +1446,7 @@ Returns:
if (GetVariableStoreStatus (VariableStoreHeader) == EfiValid) { if (GetVariableStoreStatus (VariableStoreHeader) == EfiValid) {
if (~VariableStoreHeader->Size == 0) { if (~VariableStoreHeader->Size == 0) {
Status = UpdateVariableStore ( Status = UpdateVariableStore (
&mVariableModuleGlobal->VariableBase[Physical], &mVariableModuleGlobal->VariableGlobal[Physical],
FALSE, FALSE,
FALSE, FALSE,
mVariableModuleGlobal->FvbInstance, mVariableModuleGlobal->FvbInstance,
@ -1392,7 +1460,7 @@ Returns:
} }
} }
mVariableModuleGlobal->VariableBase[Physical].NonVolatileVariableBase = (EFI_PHYSICAL_ADDRESS) ((UINTN) CurrPtr); mVariableModuleGlobal->VariableGlobal[Physical].NonVolatileVariableBase = (EFI_PHYSICAL_ADDRESS) ((UINTN) CurrPtr);
// //
// Parse non-volatile variable data and get last variable offset // Parse non-volatile variable data and get last variable offset
// //
@ -1410,7 +1478,7 @@ Returns:
// //
if ((((VARIABLE_STORE_HEADER *)((UINTN) CurrPtr))->Size - mVariableModuleGlobal->NonVolatileLastVariableOffset) < VARIABLE_RECLAIM_THRESHOLD) { if ((((VARIABLE_STORE_HEADER *)((UINTN) CurrPtr))->Size - mVariableModuleGlobal->NonVolatileLastVariableOffset) < VARIABLE_RECLAIM_THRESHOLD) {
Status = Reclaim ( Status = Reclaim (
mVariableModuleGlobal->VariableBase[Physical].NonVolatileVariableBase, mVariableModuleGlobal->VariableGlobal[Physical].NonVolatileVariableBase,
&mVariableModuleGlobal->NonVolatileLastVariableOffset, &mVariableModuleGlobal->NonVolatileLastVariableOffset,
FALSE FALSE
); );
@ -1426,13 +1494,13 @@ Returns:
// Check if the free area is really free. // Check if the free area is really free.
// //
for (Index = mVariableModuleGlobal->NonVolatileLastVariableOffset; Index < VariableStoreHeader->Size; Index++) { for (Index = mVariableModuleGlobal->NonVolatileLastVariableOffset; Index < VariableStoreHeader->Size; Index++) {
Data = ((UINT8 *) (UINTN) mVariableModuleGlobal->VariableBase[Physical].NonVolatileVariableBase)[Index]; Data = ((UINT8 *) (UINTN) mVariableModuleGlobal->VariableGlobal[Physical].NonVolatileVariableBase)[Index];
if (Data != 0xff) { if (Data != 0xff) {
// //
// There must be something wrong in variable store, do reclaim operation. // There must be something wrong in variable store, do reclaim operation.
// //
Status = Reclaim ( Status = Reclaim (
mVariableModuleGlobal->VariableBase[Physical].NonVolatileVariableBase, mVariableModuleGlobal->VariableGlobal[Physical].NonVolatileVariableBase,
&mVariableModuleGlobal->NonVolatileLastVariableOffset, &mVariableModuleGlobal->NonVolatileLastVariableOffset,
FALSE FALSE
); );

View File

@ -1,6 +1,6 @@
/*++ /*++
Copyright (c) 2006, Intel Corporation Copyright (c) 2006 - 2007, 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
@ -66,10 +66,11 @@ typedef struct {
typedef struct { typedef struct {
EFI_PHYSICAL_ADDRESS VolatileVariableBase; EFI_PHYSICAL_ADDRESS VolatileVariableBase;
EFI_PHYSICAL_ADDRESS NonVolatileVariableBase; EFI_PHYSICAL_ADDRESS NonVolatileVariableBase;
EFI_LOCK VariableServicesLock;
} VARIABLE_GLOBAL; } VARIABLE_GLOBAL;
typedef struct { typedef struct {
VARIABLE_GLOBAL VariableBase[2]; VARIABLE_GLOBAL VariableGlobal[2];
UINTN VolatileLastVariableOffset; UINTN VolatileLastVariableOffset;
UINTN NonVolatileLastVariableOffset; UINTN NonVolatileLastVariableOffset;
UINT32 FvbInstance; UINT32 FvbInstance;

View File

@ -46,6 +46,9 @@
<LibraryClass Usage="ALWAYS_CONSUMED"> <LibraryClass Usage="ALWAYS_CONSUMED">
<Keyword>UefiBootServicesTableLib</Keyword> <Keyword>UefiBootServicesTableLib</Keyword>
</LibraryClass> </LibraryClass>
<LibraryClass Usage="ALWAYS_CONSUMED">
<Keyword>UefiLib</Keyword>
</LibraryClass>
</LibraryClassDefinitions> </LibraryClassDefinitions>
<SourceFiles> <SourceFiles>
<Filename>Variable.h</Filename> <Filename>Variable.h</Filename>

View File

@ -49,6 +49,9 @@
<LibraryClass Usage="ALWAYS_CONSUMED"> <LibraryClass Usage="ALWAYS_CONSUMED">
<Keyword>UefiBootServicesTableLib</Keyword> <Keyword>UefiBootServicesTableLib</Keyword>
</LibraryClass> </LibraryClass>
<LibraryClass Usage="ALWAYS_CONSUMED">
<Keyword>UefiLib</Keyword>
</LibraryClass>
</LibraryClassDefinitions> </LibraryClassDefinitions>
<SourceFiles> <SourceFiles>
<Filename>Variable.h</Filename> <Filename>Variable.h</Filename>