/**@file\r
-\r
Firmware Volume Block Protocol Runtime Interface Abstraction\r
And FVB Extension protocol Runtime Interface Abstraction\r
\r
mFvbEntry is an array of Handle Fvb pairs. The Fvb Lib Instance matches the\r
index in the mFvbEntry array. This should be the same sequence as the FVB's\r
were described in the HOB. We have to remember the handle so we can tell if\r
- the protocol has been reinstalled and it needs updateing.\r
+ the protocol has been reinstalled and it needs updating.\r
\r
- If you are using any of these lib functions.you must first call FvbInitialize ().\r
\r
Copyright (c) 2006 - 2008, Intel Corporation\r
All rights reserved. This program and the accompanying materials\r
\r
#include "Fvb.h"\r
\r
+\r
//\r
// Event for Set Virtual Map Changed Event\r
//\r
-STATIC EFI_EVENT mSetVirtualMapChangedEvent = NULL;\r
+EFI_EVENT mSetVirtualMapChangedEvent = NULL;\r
\r
//\r
// Lib will ASSERT if more FVB devices than this are added to the system.\r
//\r
-STATIC FVB_ENTRY *mFvbEntry;\r
-STATIC EFI_EVENT mFvbRegistration;\r
-STATIC UINTN mFvbCount;\r
+FVB_ENTRY *mFvbEntry = NULL;\r
+EFI_EVENT mFvbRegistration = NULL;\r
+UINTN mFvbCount = 0;\r
\r
/**\r
Check whether an address is runtime memory or not.\r
// Enlarge space here, because we will allocate pool now.\r
//\r
MemoryMapSize += EFI_PAGE_SIZE;\r
- Status = gBS->AllocatePool (\r
- EfiBootServicesData,\r
- MemoryMapSize,\r
- (VOID**)&MemoryMap\r
- );\r
- ASSERT_EFI_ERROR (Status);\r
+ MemoryMap = AllocatePool (MemoryMapSize);\r
+ ASSERT (MemoryMap != NULL);\r
\r
//\r
// Get System MemoryMap\r
//\r
// Found it\r
//\r
- if (MemoryMap->Attribute & EFI_MEMORY_RUNTIME) {\r
+ if ((MemoryMap->Attribute & EFI_MEMORY_RUNTIME) != 0) {\r
IsRuntime = TRUE;\r
}\r
break;\r
//\r
// Get next item\r
//\r
- MemoryMap = (EFI_MEMORY_DESCRIPTOR *)((UINTN)MemoryMap + DescriptorSize);\r
+ MemoryMap = (EFI_MEMORY_DESCRIPTOR *)((UINTN) MemoryMap + DescriptorSize);\r
}\r
\r
//\r
// Done\r
//\r
- gBS->FreePool (MemoryMapPtr);\r
+ FreePool (MemoryMapPtr);\r
\r
return IsRuntime;\r
}\r
\r
+\r
/**\r
Update mFvbEntry. Add new entry, or update existing entry if Fvb protocol is\r
reinstalled.\r
@param Context Event Context\r
\r
**/\r
-STATIC\r
VOID\r
EFIAPI\r
FvbNotificationEvent (\r
);\r
ASSERT_EFI_ERROR (Status);\r
\r
- Status = gBS->HandleProtocol (\r
- Handle,\r
- &gEfiFvbExtensionProtocolGuid,\r
- (VOID **) &mFvbEntry[UpdateIndex].FvbExtension\r
- );\r
- if (Status != EFI_SUCCESS) {\r
- mFvbEntry[UpdateIndex].FvbExtension = NULL;\r
- }\r
-\r
//\r
- // Check the FVB can be accessed in RUNTIME, The FVBs in FVB handle list comes\r
- // from two way:\r
- // 1) Dxe Core. (FVB information is transferred from FV HOB).\r
- // 2) FVB driver.\r
- // The FVB produced Dxe core is used for discoverying DXE driver and dispatch. These\r
- // FVBs can only be accessed in boot time.\r
- // FVB driver will discovery all FV in FLASH and these FVBs can be accessed in runtime.\r
- // The FVB itself produced by FVB driver is allocated in runtime memory. So we can\r
+ // Check the FVB can be accessed in RUNTIME, The FVBs in FVB handle list come from two ways:\r
+ // 1) Dxe Core. (FVB information is transferred from FV HOB). 2) FVB driver. The FVB produced\r
+ // Dxe core is used to discovery DXE driver and dispatch. These FVBs can only be accessed in\r
+ // boot time. FVB driver will discovery all FV in FLASH and these FVBs can be accessed in\r
+ // runtime. The FVB itself produced by FVB driver is allocated in runtime memory. So we can\r
// determine the what FVB can be accessed in RUNTIME by judging whether FVB itself is allocated\r
// in RUNTIME memory.\r
//\r
)\r
{\r
UINTN Index;\r
+\r
if (mFvbEntry != NULL) {\r
for (Index = 0; Index < MAX_FVB_COUNT; Index++) {\r
if (!mFvbEntry[Index].IsRuntimeAccess) {\r
continue;\r
}\r
\r
- if (NULL != mFvbEntry[Index].Fvb) {\r
+ if (mFvbEntry[Index].Fvb != NULL) {\r
EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->GetBlockSize);\r
EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->GetPhysicalAddress);\r
EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->GetAttributes);\r
EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->EraseBlocks);\r
EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb);\r
}\r
-\r
- if (NULL != mFvbEntry[Index].FvbExtension) {\r
- EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].FvbExtension->EraseFvbCustomBlock);\r
- EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].FvbExtension);\r
- }\r
}\r
\r
EfiConvertPointer (0x0, (VOID **) &mFvbEntry);\r
}\r
}\r
\r
+\r
/**\r
Library constructor function entry.\r
\r
- @param ImageHandle The handle of image who call this libary.\r
+ @param ImageHandle The handle of image who call this library.\r
@param SystemTable The point of System Table.\r
\r
- @retval EFI_SUCESS Sucess construct this library.\r
- @retval Others Fail to contruct this libary.\r
+ @retval EFI_SUCESS Success construct this library.\r
+ @retval Others Fail to construct this library.\r
**/\r
EFI_STATUS\r
EFIAPI\r
IN EFI_SYSTEM_TABLE *SystemTable\r
)\r
{\r
- UINTN Status;\r
- mFvbCount = 0;\r
-\r
- Status = gBS->AllocatePool (\r
- EfiRuntimeServicesData,\r
- (UINTN) sizeof (FVB_ENTRY) * MAX_FVB_COUNT,\r
- (VOID *) &mFvbEntry\r
- );\r
-\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
-\r
- ZeroMem (mFvbEntry, sizeof (FVB_ENTRY) * MAX_FVB_COUNT);\r
+ EFI_STATUS Status;\r
+ \r
+ mFvbEntry = AllocateRuntimeZeroPool (sizeof (FVB_ENTRY) * MAX_FVB_COUNT);\r
+ ASSERT (mFvbEntry != NULL);\r
\r
+ //\r
+ // Register FvbNotificationEvent () notify function.\r
+ // \r
EfiCreateProtocolNotifyEvent (\r
&gEfiFirmwareVolumeBlockProtocolGuid,\r
TPL_CALLBACK,\r
//\r
// Register SetVirtualAddressMap () notify function\r
//\r
- Status = gBS->CreateEvent (\r
- EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE,\r
+ Status = gBS->CreateEventEx (\r
+ EVT_NOTIFY_SIGNAL,\r
TPL_NOTIFY,\r
FvbVirtualAddressChangeNotifyEvent,\r
NULL,\r
+ &gEfiEventVirtualAddressChangeGuid,\r
&mSetVirtualMapChangedEvent\r
);\r
ASSERT_EFI_ERROR (Status);\r
\r
- return EFI_SUCCESS;\r
+ return Status;\r
}\r
\r
//\r
// The Instance translates into Fvb instance. The Fvb order defined by HOBs and\r
// thus the sequence of FVB protocol addition define Instance.\r
//\r
-// EfiFvbInitialize () must be called before any of the following functions\r
-// must be called.\r
-// =============================================================================\r
-//\r
\r
/**\r
Reads specified number of bytes into a buffer from the specified block.\r
@param[out] Buffer Pointer to a caller allocated buffer that will be\r
used to hold the data read.\r
\r
- @retval EFI_SUCCESS The firmware volume was read successfully and contents are in Buffer.\r
- @retval EFI_BAD_BUFFER_SIZE Read attempted across an LBA boundary. On output, NumBytes contains the total number of bytes returned in Buffer.\r
+ @retval EFI_SUCCESS The firmware volume was read successfully and contents are in Buffer.\r
+ @retval EFI_BAD_BUFFER_SIZE Read attempted across an LBA boundary. On output, NumBytes contains\r
+ the total number of bytes returned in Buffer.\r
@retval EFI_ACCESS_DENIED The firmware volume is in the ReadDisabled state.\r
@retval EFI_DEVICE_ERROR The block device is not functioning correctly and could not be read.\r
- @retval EFI_INVALID_PARAMETER Invalid parameter, Instance is larger than the max FVB number. Lba index is larger than the last block of the firmware volume. Offset is larger than the block size.\r
+ @retval EFI_INVALID_PARAMETER Invalid parameter, Instance is larger than the max FVB number. Lba index\r
+ is larger than the last block of the firmware volume. Offset is larger\r
+ than the block size.\r
\r
**/\r
EFI_STATUS\r
+EFIAPI\r
EfiFvbReadBlock (\r
IN UINTN Instance,\r
IN EFI_LBA Lba,\r
\r
If NumBytes is NULL, then ASSERT().\r
\r
- @param Instance The FV instance to be written to\r
- @param Lba The starting logical block index to write to\r
- @param Offset The offset relative to the block, at which to begin writting.\r
+ @param Instance The FV instance to be written to.\r
+ @param Lba The starting logical block index to write.\r
+ @param Offset The offset relative to the block to write.\r
@param NumBytes Pointer to a UINTN. On input, *NumBytes contains\r
the total size of the buffer. On output, it contains\r
the actual number of bytes written.\r
@retval EFI_SUCCESS The firmware volume was written successfully.\r
@retval EFI_BAD_BUFFER_SIZE The write was attempted across an LBA boundary. \r
On output, NumBytes contains the total number of bytes actually written.\r
- @retval EFI_ACCESS_DENIED The firmware volume is in the WriteDisabled state.\r
+ @retval EFI_ACCESS_DENIED The firmware volume is in the WriteDisabled state.\r
@retval EFI_DEVICE_ERROR The block device is malfunctioning and could not be written.\r
@retval EFI_INVALID_PARAMETER Invalid parameter, Instance is larger than the max FVB number. \r
Lba index is larger than the last block of the firmware volume.\r
Offset is larger than the block size.\r
**/\r
EFI_STATUS\r
+EFIAPI\r
EfiFvbWriteBlock (\r
IN UINTN Instance,\r
IN EFI_LBA Lba,\r
return mFvbEntry[Instance].Fvb->Write (mFvbEntry[Instance].Fvb, Lba, Offset, NumBytes, Buffer);\r
}\r
\r
+\r
/**\r
Erases and initializes a firmware volume block.\r
\r
\r
**/\r
EFI_STATUS\r
+EFIAPI\r
EfiFvbEraseBlock (\r
IN UINTN Instance,\r
IN EFI_LBA Lba\r
return mFvbEntry[Instance].Fvb->EraseBlocks (mFvbEntry[Instance].Fvb, Lba, 1, EFI_LBA_LIST_TERMINATOR);\r
}\r
\r
+\r
/**\r
Retrieves the attributes and current settings of the specified block, \r
returns resulting attributes in output parameter.\r
@retval EFI_INVALID_PARAMETER Invalid parameter. Instance is larger than the max FVB number. \r
**/\r
EFI_STATUS\r
+EFIAPI\r
EfiFvbGetVolumeAttributes (\r
IN UINTN Instance,\r
OUT EFI_FVB_ATTRIBUTES_2 *Attributes\r
return mFvbEntry[Instance].Fvb->GetAttributes (mFvbEntry[Instance].Fvb, Attributes);\r
}\r
\r
+\r
/**\r
Modify the attributes and current settings of the specified block\r
according to the input parameter.\r
\r
**/\r
EFI_STATUS\r
+EFIAPI\r
EfiFvbSetVolumeAttributes (\r
IN UINTN Instance,\r
IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes\r
return mFvbEntry[Instance].Fvb->SetAttributes (mFvbEntry[Instance].Fvb, Attributes);\r
}\r
\r
+\r
/**\r
Retrieves the physical address of the specified memory mapped FV.\r
\r
\r
**/\r
EFI_STATUS\r
+EFIAPI\r
EfiFvbGetPhysicalAddress (\r
IN UINTN Instance,\r
OUT EFI_PHYSICAL_ADDRESS *BaseAddress\r
return mFvbEntry[Instance].Fvb->GetPhysicalAddress (mFvbEntry[Instance].Fvb, BaseAddress);\r
}\r
\r
+\r
/**\r
Retrieve the block size of the specified fv.\r
\r
the last block of the firmware volume, this function return the status code\r
EFI_INVALID_PARAMETER.\r
\r
- If BlockSize is NULL, then ASSERT().\r
+ If BlockSize is NULL, then ASSERT().\r
\r
If NumOfBlocks is NULL, then ASSERT().\r
\r
\r
**/\r
EFI_STATUS\r
+EFIAPI\r
EfiFvbGetBlockSize (\r
IN UINTN Instance,\r
IN EFI_LBA Lba,\r
\r
return mFvbEntry[Instance].Fvb->GetBlockSize (mFvbEntry[Instance].Fvb, Lba, BlockSize, NumOfBlocks);\r
}\r
-\r
-/**\r
- Erases and initializes a specified range of a firmware volume.\r
-\r
- The EfiFvbEraseCustomBlockRange() function erases the specified range in the firmware\r
- volume index by Instance. If Instance is larger than the max FVB number, StartLba or \r
- LastLba index is larger than the last block of the firmware volume, StartLba > LastLba\r
- or StartLba equal to LastLba but OffsetStartLba > OffsetLastLba, this function return \r
- the status code EFI_INVALID_PARAMETER.\r
-\r
- @param[in] Instance The FV instance to be operated.\r
- @param[in] StartLba The starting logical block index to be erased.\r
- @param[in] OffsetStartLba Offset into the starting block at which to \r
- begin erasing. \r
- @param[in] LastLba The last logical block index to be erased.\r
- @param[in] OffsetLastLba Offset into the last block at which to end erasing. \r
-\r
- @retval EFI_EFI_SUCCESS Successfully erase custom block range\r
- @retval EFI_INVALID_PARAMETER Invalid parameter. Instance is larger than the max FVB number. \r
- @retval EFI_UNSUPPORTED Firmware volume block device has no this capability.\r
-\r
-**/\r
-EFI_STATUS\r
-EfiFvbEraseCustomBlockRange (\r
- IN UINTN Instance,\r
- IN EFI_LBA StartLba,\r
- IN UINTN OffsetStartLba,\r
- IN EFI_LBA LastLba,\r
- IN UINTN OffsetLastLba\r
- )\r
-{\r
- if (Instance >= mFvbCount) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- if (EfiAtRuntime() && !mFvbEntry[Instance].IsRuntimeAccess) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- if (!(mFvbEntry[Instance].FvbExtension)) {\r
- return EFI_UNSUPPORTED;\r
- }\r
-\r
- if (!(mFvbEntry[Instance].FvbExtension->EraseFvbCustomBlock)) {\r
- return EFI_UNSUPPORTED;\r
- }\r
-\r
- return mFvbEntry[Instance].FvbExtension->EraseFvbCustomBlock (\r
- mFvbEntry[Instance].FvbExtension,\r
- StartLba,\r
- OffsetStartLba,\r
- LastLba,\r
- OffsetLastLba\r
- );\r
-}\r