1. retire the FvbServiceLib. Directly locating FVB protocol to access interfaces.

2. modify the method of getting right FVB protocol interface. move the notification event of FVB installation into variable driver. and also move ExitBootService event into variable driver.
3. use EFI_FVB2_WRITE_STATUS flag to distinct whether the FVB protocol supports writing operation or not.Currently, DxeCore installs FVB which has ~EFI_FVB2_WRITE_STATUS(that is, disable write) attrbiute. FvbRuntimeDxe driver should provide a full FVB protocol, which returns EFI_FVB2_WRITE_STATUS attribute to signify itself provide writable FVB protocol. So other modules which need write data by FVB protocol can locate it correctly.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@7835 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
eric_tian 2009-03-09 06:39:13 +00:00
parent 242d687699
commit 8a9e0b7274
5 changed files with 185 additions and 105 deletions

View File

@ -86,7 +86,7 @@ FwVolBlockGetAttributes (
//
// Since we are read only, it's safe to get attributes data from our in-memory copy.
//
*Attributes = FvbDevice->FvbAttributes;
*Attributes = FvbDevice->FvbAttributes & ~EFI_FVB2_WRITE_STATUS;
return EFI_SUCCESS;
}

View File

@ -44,6 +44,7 @@ GetFvbHandleByAddress (
EFI_PHYSICAL_ADDRESS FvbBaseAddress;
EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb;
EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;
EFI_FVB_ATTRIBUTES_2 Attributes;
*FvbHandle = NULL;
//
@ -72,6 +73,11 @@ GetFvbHandleByAddress (
Status = EFI_NOT_FOUND;
break;
}
Status = Fvb->GetAttributes (Fvb, &Attributes);
if (EFI_ERROR (Status) || ((Attributes & EFI_FVB2_WRITE_STATUS) == 0)) {
continue;
}
//
// Compare the address and select the right one
//

View File

@ -37,6 +37,8 @@ VARIABLE_CACHE_ENTRY mVariableCache[] = {
};
VARIABLE_INFO_ENTRY *gVariableInfo = NULL;
EFI_EVENT mFvbRegistration = NULL;
/**
Acquires lock only at boot time. Simply returns at runtime.
@ -213,7 +215,7 @@ IsValidVariableHeader (
@param Volatile Point out the Variable is Volatile or Non-Volatile
@param SetByIndex TRUE if target pointer is given as index
FALSE if target pointer is absolute
@param Instance Instance of FV Block services
@param Fvb Pointer to the writable FVB protocol
@param DataPtrIndex Pointer to the Data from the end of VARIABLE_STORE_HEADER
structure
@param DataSize Size of data to be written
@ -228,7 +230,7 @@ UpdateVariableStore (
IN VARIABLE_GLOBAL *Global,
IN BOOLEAN Volatile,
IN BOOLEAN SetByIndex,
IN UINTN Instance,
IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb,
IN UINTN DataPtrIndex,
IN UINT32 DataSize,
IN UINT8 *Buffer
@ -255,7 +257,9 @@ UpdateVariableStore (
// Check if the Data is Volatile
//
if (!Volatile) {
EfiFvbGetPhysicalAddress (Instance, &FvVolHdr);
Status = Fvb->GetPhysicalAddress(Fvb, &FvVolHdr);
ASSERT_EFI_ERROR (Status);
FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *) ((UINTN) FvVolHdr);
//
// Data Pointer should point to the actual Address where data is to be
@ -310,8 +314,8 @@ UpdateVariableStore (
//
if ((CurrWritePtr >= LinearOffset) && (CurrWritePtr < LinearOffset + PtrBlockMapEntry->Length)) {
if ((CurrWritePtr + CurrWriteSize) <= (LinearOffset + PtrBlockMapEntry->Length)) {
Status = EfiFvbWriteBlock (
Instance,
Status = Fvb->Write (
Fvb,
LbaNumber,
(UINTN) (CurrWritePtr - LinearOffset),
&CurrWriteSize,
@ -320,8 +324,8 @@ UpdateVariableStore (
return Status;
} else {
Size = (UINT32) (LinearOffset + PtrBlockMapEntry->Length - CurrWritePtr);
Status = EfiFvbWriteBlock (
Instance,
Status = Fvb->Write (
Fvb,
LbaNumber,
(UINTN) (CurrWritePtr - LinearOffset),
&Size,
@ -1209,7 +1213,7 @@ RuntimeServiceSetVariable (
BOOLEAN Reclaimed;
UINTN *VolatileOffset;
UINTN *NonVolatileOffset;
UINT32 Instance;
EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb;
BOOLEAN Volatile;
EFI_PHYSICAL_ADDRESS Point;
@ -1250,7 +1254,7 @@ RuntimeServiceSetVariable (
AcquireLockOnlyAtBootTime(&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);
Reclaimed = FALSE;
Instance = mVariableModuleGlobal->FvbInstance;
Fvb = mVariableModuleGlobal->FvbInstance;
VolatileOffset = &mVariableModuleGlobal->VolatileLastVariableOffset;
//
@ -1312,7 +1316,7 @@ RuntimeServiceSetVariable (
&mVariableModuleGlobal->VariableGlobal,
Variable.Volatile,
FALSE,
Instance,
Fvb,
(UINTN) &Variable.CurrPtr->State,
sizeof (UINT8),
&State
@ -1346,7 +1350,7 @@ RuntimeServiceSetVariable (
&mVariableModuleGlobal->VariableGlobal,
Variable.Volatile,
FALSE,
Instance,
Fvb,
(UINTN) &Variable.CurrPtr->State,
sizeof (UINT8),
&State
@ -1475,7 +1479,7 @@ RuntimeServiceSetVariable (
&mVariableModuleGlobal->VariableGlobal,
FALSE,
TRUE,
Instance,
Fvb,
*NonVolatileOffset,
sizeof (VARIABLE_HEADER),
(UINT8 *) NextVariable
@ -1493,7 +1497,7 @@ RuntimeServiceSetVariable (
&mVariableModuleGlobal->VariableGlobal,
FALSE,
TRUE,
Instance,
Fvb,
*NonVolatileOffset,
sizeof (VARIABLE_HEADER),
(UINT8 *) NextVariable
@ -1509,7 +1513,7 @@ RuntimeServiceSetVariable (
&mVariableModuleGlobal->VariableGlobal,
FALSE,
TRUE,
Instance,
Fvb,
*NonVolatileOffset + sizeof (VARIABLE_HEADER),
(UINT32) VarSize - sizeof (VARIABLE_HEADER),
(UINT8 *) NextVariable + sizeof (VARIABLE_HEADER)
@ -1526,7 +1530,7 @@ RuntimeServiceSetVariable (
&mVariableModuleGlobal->VariableGlobal,
FALSE,
TRUE,
Instance,
Fvb,
*NonVolatileOffset,
sizeof (VARIABLE_HEADER),
(UINT8 *) NextVariable
@ -1571,7 +1575,7 @@ RuntimeServiceSetVariable (
&mVariableModuleGlobal->VariableGlobal,
TRUE,
TRUE,
Instance,
Fvb,
*VolatileOffset,
(UINT32) VarSize,
(UINT8 *) NextVariable
@ -1594,7 +1598,7 @@ RuntimeServiceSetVariable (
&mVariableModuleGlobal->VariableGlobal,
Variable.Volatile,
FALSE,
Instance,
Fvb,
(UINTN) &Variable.CurrPtr->State,
sizeof (UINT8),
&State
@ -1792,7 +1796,6 @@ ReclaimForOS(
/**
Initializes variable store area for non-volatile and volatile variable.
@param ImageHandle The Image handle of this driver.
@param SystemTable The pointer of EFI_SYSTEM_TABLE.
@retval EFI_SUCCESS Function successfully executed.
@ -1801,25 +1804,20 @@ ReclaimForOS(
**/
EFI_STATUS
VariableCommonInitialize (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbProtocol
)
{
EFI_STATUS Status;
EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;
CHAR8 *CurrPtr;
VARIABLE_STORE_HEADER *VolatileVariableStore;
VARIABLE_STORE_HEADER *VariableStoreHeader;
VARIABLE_HEADER *NextVariable;
UINT32 Instance;
EFI_PHYSICAL_ADDRESS FvVolHdr;
UINT64 TempVariableStoreHeader;
EFI_PHYSICAL_ADDRESS TempVariableStoreHeader;
EFI_GCD_MEMORY_SPACE_DESCRIPTOR GcdDescriptor;
UINT64 BaseAddress;
EFI_PHYSICAL_ADDRESS BaseAddress;
UINT64 Length;
UINTN Index;
UINT8 Data;
UINT64 VariableStoreBase;
EFI_PHYSICAL_ADDRESS VariableStoreBase;
UINT64 VariableStoreLength;
EFI_EVENT ReadyToBootEvent;
@ -1851,6 +1849,7 @@ VariableCommonInitialize (
//
mVariableModuleGlobal->VariableGlobal.VolatileVariableBase = (EFI_PHYSICAL_ADDRESS) (UINTN) VolatileVariableStore;
mVariableModuleGlobal->VolatileLastVariableOffset = (UINTN) GetStartPointer (VolatileVariableStore) - (UINTN) VolatileVariableStore;
mVariableModuleGlobal->FvbInstance = FvbProtocol;
CopyGuid (&VolatileVariableStore->Signature, &gEfiVariableGuid);
VolatileVariableStore->Size = FixedPcdGet32(PcdVariableStoreSize);
@ -1863,7 +1862,7 @@ VariableCommonInitialize (
// Get non volatile varaible store
//
TempVariableStoreHeader = (UINT64) PcdGet32 (PcdFlashNvStorageVariableBase);
TempVariableStoreHeader = (EFI_PHYSICAL_ADDRESS) PcdGet32 (PcdFlashNvStorageVariableBase);
VariableStoreBase = TempVariableStoreHeader + \
(((EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)(TempVariableStoreHeader)) -> HeaderLength);
VariableStoreLength = (UINT64) PcdGet32 (PcdFlashNvStorageVariableSize) - \
@ -1892,26 +1891,7 @@ VariableCommonInitialize (
// Get address of non volatile variable store base
//
mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase = VariableStoreBase;
//
// Check Integrity
//
//
// Find the Correct Instance of the FV Block Service.
//
Instance = 0;
CurrPtr = (CHAR8 *) ((UINTN) mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase);
while (EfiFvbGetPhysicalAddress (Instance, &FvVolHdr) == EFI_SUCCESS) {
FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *) ((UINTN) FvVolHdr);
if (CurrPtr >= (CHAR8 *) FwVolHeader && CurrPtr < (((CHAR8 *) FwVolHeader) + FwVolHeader->FvLength)) {
mVariableModuleGlobal->FvbInstance = Instance;
break;
}
Instance++;
}
VariableStoreHeader = (VARIABLE_STORE_HEADER *) CurrPtr;
VariableStoreHeader = (VARIABLE_STORE_HEADER *)(UINTN)VariableStoreBase;
if (GetVariableStoreStatus (VariableStoreHeader) == EfiValid) {
if (~VariableStoreHeader->Size == 0) {
Status = UpdateVariableStore (
@ -1938,18 +1918,17 @@ VariableCommonInitialize (
}
}
mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase = (EFI_PHYSICAL_ADDRESS) ((UINTN) CurrPtr);
//
// Parse non-volatile variable data and get last variable offset
//
NextVariable = GetStartPointer ((VARIABLE_STORE_HEADER *) CurrPtr);
NextVariable = GetStartPointer ((VARIABLE_STORE_HEADER *)(UINTN)VariableStoreBase);
Status = EFI_SUCCESS;
while (IsValidVariableHeader (NextVariable)) {
NextVariable = GetNextVariablePtr (NextVariable);
}
mVariableModuleGlobal->NonVolatileLastVariableOffset = (UINTN) NextVariable - (UINTN) CurrPtr;
mVariableModuleGlobal->NonVolatileLastVariableOffset = (UINTN) NextVariable - (UINTN) VariableStoreBase;
//
// Check if the free area is really free.
@ -2015,6 +1994,14 @@ VariableClassAddressChangeEvent (
IN VOID *Context
)
{
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->GetBlockSize);
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->GetPhysicalAddress);
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->GetAttributes);
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->SetAttributes);
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->Read);
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->Write);
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->EraseBlocks);
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance);
EfiConvertPointer (
0x0,
(VOID **) &mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase
@ -2026,29 +2013,84 @@ VariableClassAddressChangeEvent (
EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal);
}
/**
Variable Driver main entry point. The Variable driver places the 4 EFI
runtime services in the EFI System Table and installs arch protocols
for variable read and write services being availible. It also registers
notification function for EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.
@param[in] ImageHandle The firmware allocated handle for the EFI image.
@param[in] SystemTable A pointer to the EFI System Table.
@retval EFI_SUCCESS Variable service successfully initialized.
**/
EFI_STATUS
VOID
EFIAPI
VariableServiceInitialize (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
FvbNotificationEvent (
IN EFI_EVENT Event,
IN VOID *Context
)
{
EFI_STATUS Status;
EFI_HANDLE *HandleBuffer;
EFI_HANDLE FvbHandle;
UINTN HandleCount;
UINTN Index;
EFI_PHYSICAL_ADDRESS FvbBaseAddress;
EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb;
EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;
EFI_FVB_ATTRIBUTES_2 Attributes;
EFI_SYSTEM_TABLE *SystemTable;
EFI_PHYSICAL_ADDRESS NvStorageVariableBase;
Status = VariableCommonInitialize (ImageHandle, SystemTable);
SystemTable = (EFI_SYSTEM_TABLE *)Context;
Fvb = NULL;
FvbHandle = NULL;
//
// Locate all handles of Fvb protocol
//
Status = gBS->LocateHandleBuffer (
ByProtocol,
&gEfiFirmwareVolumeBlockProtocolGuid,
NULL,
&HandleCount,
&HandleBuffer
);
if (EFI_ERROR (Status)) {
return ;
}
//
// Get the FVB to access variable store
//
for (Index = 0; Index < HandleCount; Index += 1, Status = EFI_NOT_FOUND) {
Status = gBS->HandleProtocol (
HandleBuffer[Index],
&gEfiFirmwareVolumeBlockProtocolGuid,
(VOID **) &Fvb
);
if (EFI_ERROR (Status)) {
Status = EFI_NOT_FOUND;
break;
}
//
// Ensure this FVB protocol supported Write operation.
//
Status = Fvb->GetAttributes (Fvb, &Attributes);
if (EFI_ERROR (Status) || ((Attributes & EFI_FVB2_WRITE_STATUS) == 0)) {
continue;
}
//
// Compare the address and select the right one
//
Status = Fvb->GetPhysicalAddress (Fvb, &FvbBaseAddress);
if (EFI_ERROR (Status)) {
continue;
}
FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *) ((UINTN) FvbBaseAddress);
NvStorageVariableBase = (EFI_PHYSICAL_ADDRESS) PcdGet32 (PcdFlashNvStorageVariableBase);
if ((NvStorageVariableBase >= FvbBaseAddress) && (NvStorageVariableBase < (FvbBaseAddress + FwVolHeader->FvLength))) {
FvbHandle = HandleBuffer[Index];
Status = EFI_SUCCESS;
break;
}
}
FreePool (HandleBuffer);
if (!EFI_ERROR (Status)) {
Status = VariableCommonInitialize (Fvb);
ASSERT_EFI_ERROR (Status);
SystemTable->RuntimeServices->GetVariable = RuntimeServiceGetVariable;
@ -2076,6 +2118,39 @@ VariableServiceInitialize (
&mVirtualAddressChangeEvent
);
ASSERT_EFI_ERROR (Status);
}
}
/**
Variable Driver main entry point. The Variable driver places the 4 EFI
runtime services in the EFI System Table and installs arch protocols
for variable read and write services being availible. It also registers
notification function for EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.
@param[in] ImageHandle The firmware allocated handle for the EFI image.
@param[in] SystemTable A pointer to the EFI System Table.
@retval EFI_SUCCESS Variable service successfully initialized.
**/
EFI_STATUS
EFIAPI
VariableServiceInitialize (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
//
// Register FvbNotificationEvent () notify function.
//
EfiCreateProtocolNotifyEvent (
&gEfiFirmwareVolumeBlockProtocolGuid,
TPL_CALLBACK,
FvbNotificationEvent,
(VOID *)SystemTable,
&mFvbRegistration
);
return EFI_SUCCESS;
}

View File

@ -58,7 +58,7 @@ typedef struct {
VARIABLE_GLOBAL VariableGlobal;
UINTN VolatileLastVariableOffset;
UINTN NonVolatileLastVariableOffset;
UINT32 FvbInstance;
EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbInstance;
} VARIABLE_MODULE_GLOBAL;
typedef struct {

View File

@ -45,7 +45,6 @@
SynchronizationLib
UefiLib
UefiBootServicesTableLib
FvbServiceLib
BaseMemoryLib
DebugLib
UefiRuntimeLib