diff options
author | qhuang8 <qhuang8@6f19259b-4bc3-4df7-8a09-765794883524> | 2008-11-06 08:29:42 +0000 |
---|---|---|
committer | qhuang8 <qhuang8@6f19259b-4bc3-4df7-8a09-765794883524> | 2008-11-06 08:29:42 +0000 |
commit | bac86c0d528fc6d2724c81ad80b1ef8873b7a467 (patch) | |
tree | 7afd1785867fe0edb4c73b70e3671396d6473d84 /MdeModulePkg/Library | |
parent | 63a66a35c8443b98a0188271edf67f882eb7b25e (diff) | |
download | edk2-platforms-bac86c0d528fc6d2724c81ad80b1ef8873b7a467.tar.xz |
Code scrub EdkFvbServiceLib.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@6412 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'MdeModulePkg/Library')
-rw-r--r-- | MdeModulePkg/Library/EdkFvbServiceLib/EdkFvbServiceLib.inf | 5 | ||||
-rw-r--r-- | MdeModulePkg/Library/EdkFvbServiceLib/Fvb.c | 96 | ||||
-rw-r--r-- | MdeModulePkg/Library/EdkFvbServiceLib/Fvb.h | 1 |
3 files changed, 53 insertions, 49 deletions
diff --git a/MdeModulePkg/Library/EdkFvbServiceLib/EdkFvbServiceLib.inf b/MdeModulePkg/Library/EdkFvbServiceLib/EdkFvbServiceLib.inf index 886f2f49bd..9101fc38e2 100644 --- a/MdeModulePkg/Library/EdkFvbServiceLib/EdkFvbServiceLib.inf +++ b/MdeModulePkg/Library/EdkFvbServiceLib/EdkFvbServiceLib.inf @@ -20,7 +20,7 @@ FILE_GUID = bd4d540e-04b0-4b10-8fd5-4a7bb533cf67
MODULE_TYPE = DXE_RUNTIME_DRIVER
VERSION_STRING = 1.0
- LIBRARY_CLASS = FvbServiceLib|DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION
+ LIBRARY_CLASS = FvbServiceLib|DXE_RUNTIME_DRIVER DXE_SMM_DRIVER
EDK_RELEASE_VERSION = 0x00020000
EFI_SPECIFICATION_VERSION = 0x00020000
@@ -49,9 +49,10 @@ DebugLib
BaseLib
UefiLib
+ MemoryAllocationLib
[Protocols]
gEfiFirmwareVolumeBlockProtocolGuid # PROTOCOL_NOTIFY SOMETIMES_CONSUMED
gEfiFvbExtensionProtocolGuid # PROTOCOL ALWAYS_CONSUMED
- gEfiFirmwareVolumeBlockProtocolGuid # PROTOCOL ALWAYS_CONSUMED
+
diff --git a/MdeModulePkg/Library/EdkFvbServiceLib/Fvb.c b/MdeModulePkg/Library/EdkFvbServiceLib/Fvb.c index 65a2ac8c6f..6080b1c0c6 100644 --- a/MdeModulePkg/Library/EdkFvbServiceLib/Fvb.c +++ b/MdeModulePkg/Library/EdkFvbServiceLib/Fvb.c @@ -8,7 +8,6 @@ were described in the HOB. We have to remember the handle so we can tell if
the protocol has been reinstalled and it needs updateing.
- If you are using any of these lib functions.you must first call FvbInitialize ().
Copyright (c) 2006 - 2008, Intel Corporation
All rights reserved. This program and the accompanying materials
@@ -24,6 +23,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include "Fvb.h"
+
//
// Event for Set Virtual Map Changed Event
//
@@ -32,9 +32,9 @@ EFI_EVENT mSetVirtualMapChangedEvent = NULL; //
// Lib will ASSERT if more FVB devices than this are added to the system.
//
-FVB_ENTRY *mFvbEntry;
-EFI_EVENT mFvbRegistration;
-UINTN mFvbCount;
+FVB_ENTRY *mFvbEntry = NULL;
+EFI_EVENT mFvbRegistration = NULL;
+UINTN mFvbCount = 0;
/**
Check whether an address is runtime memory or not.
@@ -78,12 +78,8 @@ IsRuntimeMemory ( // Enlarge space here, because we will allocate pool now.
//
MemoryMapSize += EFI_PAGE_SIZE;
- Status = gBS->AllocatePool (
- EfiBootServicesData,
- MemoryMapSize,
- (VOID**)&MemoryMap
- );
- ASSERT_EFI_ERROR (Status);
+ MemoryMap = AllocatePool (MemoryMapSize);
+ ASSERT (MemoryMap != NULL);
//
// Get System MemoryMap
@@ -108,7 +104,7 @@ IsRuntimeMemory ( //
// Found it
//
- if (MemoryMap->Attribute & EFI_MEMORY_RUNTIME) {
+ if ((MemoryMap->Attribute & EFI_MEMORY_RUNTIME) != 0) {
IsRuntime = TRUE;
}
break;
@@ -116,17 +112,18 @@ IsRuntimeMemory ( //
// Get next item
//
- MemoryMap = (EFI_MEMORY_DESCRIPTOR *)((UINTN)MemoryMap + DescriptorSize);
+ MemoryMap = (EFI_MEMORY_DESCRIPTOR *)((UINTN) MemoryMap + DescriptorSize);
}
//
// Done
//
- gBS->FreePool (MemoryMapPtr);
+ FreePool (MemoryMapPtr);
return IsRuntime;
}
+
/**
Update mFvbEntry. Add new entry, or update existing entry if Fvb protocol is
reinstalled.
@@ -211,14 +208,11 @@ FvbNotificationEvent ( }
//
- // Check the FVB can be accessed in RUNTIME, The FVBs in FVB handle list comes
- // from two way:
- // 1) Dxe Core. (FVB information is transferred from FV HOB).
- // 2) FVB driver.
- // The FVB produced Dxe core is used for discoverying DXE driver and dispatch. These
- // FVBs can only be accessed in boot time.
- // FVB driver will discovery all FV in FLASH and these FVBs can be accessed in runtime.
- // The FVB itself produced by FVB driver is allocated in runtime memory. So we can
+ // Check the FVB can be accessed in RUNTIME, The FVBs in FVB handle list come from two ways:
+ // 1) Dxe Core. (FVB information is transferred from FV HOB). 2) FVB driver. The FVB produced
+ // Dxe core is used to discovery DXE driver and dispatch. These FVBs can only be accessed in
+ // boot time. FVB driver will discovery all FV in FLASH and these FVBs can be accessed in
+ // runtime. The FVB itself produced by FVB driver is allocated in runtime memory. So we can
// determine the what FVB can be accessed in RUNTIME by judging whether FVB itself is allocated
// in RUNTIME memory.
//
@@ -241,13 +235,14 @@ FvbVirtualAddressChangeNotifyEvent ( )
{
UINTN Index;
+
if (mFvbEntry != NULL) {
for (Index = 0; Index < MAX_FVB_COUNT; Index++) {
if (!mFvbEntry[Index].IsRuntimeAccess) {
continue;
}
- if (NULL != mFvbEntry[Index].Fvb) {
+ if (mFvbEntry[Index].Fvb != NULL) {
EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->GetBlockSize);
EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->GetPhysicalAddress);
EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->GetAttributes);
@@ -258,7 +253,7 @@ FvbVirtualAddressChangeNotifyEvent ( EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb);
}
- if (NULL != mFvbEntry[Index].FvbExtension) {
+ if (mFvbEntry[Index].FvbExtension != NULL) {
EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].FvbExtension->EraseFvbCustomBlock);
EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].FvbExtension);
}
@@ -268,6 +263,7 @@ FvbVirtualAddressChangeNotifyEvent ( }
}
+
/**
Library constructor function entry.
@@ -284,21 +280,14 @@ FvbLibInitialize ( IN EFI_SYSTEM_TABLE *SystemTable
)
{
- UINTN Status;
- mFvbCount = 0;
-
- Status = gBS->AllocatePool (
- EfiRuntimeServicesData,
- (UINTN) sizeof (FVB_ENTRY) * MAX_FVB_COUNT,
- (VOID *) &mFvbEntry
- );
-
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- ZeroMem (mFvbEntry, sizeof (FVB_ENTRY) * MAX_FVB_COUNT);
+ EFI_STATUS Status;
+
+ mFvbEntry = AllocateRuntimeZeroPool (sizeof (FVB_ENTRY) * MAX_FVB_COUNT);
+ ASSERT (mFvbEntry != NULL);
+ //
+ // Register FvbNotificationEvent () notify function.
+ //
EfiCreateProtocolNotifyEvent (
&gEfiFirmwareVolumeBlockProtocolGuid,
TPL_CALLBACK,
@@ -319,7 +308,7 @@ FvbLibInitialize ( );
ASSERT_EFI_ERROR (Status);
- return EFI_SUCCESS;
+ return Status;
}
//
@@ -328,10 +317,6 @@ FvbLibInitialize ( // The Instance translates into Fvb instance. The Fvb order defined by HOBs and
// thus the sequence of FVB protocol addition define Instance.
//
-// EfiFvbInitialize () must be called before any of the following functions
-// must be called.
-// =============================================================================
-//
/**
Reads specified number of bytes into a buffer from the specified block.
@@ -362,14 +347,18 @@ FvbLibInitialize ( @param[out] Buffer Pointer to a caller allocated buffer that will be
used to hold the data read.
- @retval EFI_SUCCESS The firmware volume was read successfully and contents are in Buffer.
- @retval EFI_BAD_BUFFER_SIZE Read attempted across an LBA boundary. On output, NumBytes contains the total number of bytes returned in Buffer.
+ @retval EFI_SUCCESS The firmware volume was read successfully and contents are in Buffer.
+ @retval EFI_BAD_BUFFER_SIZE Read attempted across an LBA boundary. On output, NumBytes contains
+ the total number of bytes returned in Buffer.
@retval EFI_ACCESS_DENIED The firmware volume is in the ReadDisabled state.
@retval EFI_DEVICE_ERROR The block device is not functioning correctly and could not be read.
- @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.
+ @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.
**/
EFI_STATUS
+EFIAPI
EfiFvbReadBlock (
IN UINTN Instance,
IN EFI_LBA Lba,
@@ -436,13 +425,14 @@ EfiFvbReadBlock ( @retval EFI_SUCCESS The firmware volume was written successfully.
@retval EFI_BAD_BUFFER_SIZE The write was attempted across an LBA boundary.
On output, NumBytes contains the total number of bytes actually written.
- @retval EFI_ACCESS_DENIED The firmware volume is in the WriteDisabled state.
+ @retval EFI_ACCESS_DENIED The firmware volume is in the WriteDisabled state.
@retval EFI_DEVICE_ERROR The block device is malfunctioning and could not be written.
@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.
**/
EFI_STATUS
+EFIAPI
EfiFvbWriteBlock (
IN UINTN Instance,
IN EFI_LBA Lba,
@@ -464,6 +454,7 @@ EfiFvbWriteBlock ( return mFvbEntry[Instance].Fvb->Write (mFvbEntry[Instance].Fvb, Lba, Offset, NumBytes, Buffer);
}
+
/**
Erases and initializes a firmware volume block.
@@ -493,6 +484,7 @@ EfiFvbWriteBlock ( **/
EFI_STATUS
+EFIAPI
EfiFvbEraseBlock (
IN UINTN Instance,
IN EFI_LBA Lba
@@ -509,6 +501,7 @@ EfiFvbEraseBlock ( return mFvbEntry[Instance].Fvb->EraseBlocks (mFvbEntry[Instance].Fvb, Lba, 1, EFI_LBA_LIST_TERMINATOR);
}
+
/**
Retrieves the attributes and current settings of the specified block,
returns resulting attributes in output parameter.
@@ -527,6 +520,7 @@ EfiFvbEraseBlock ( @retval EFI_INVALID_PARAMETER Invalid parameter. Instance is larger than the max FVB number.
**/
EFI_STATUS
+EFIAPI
EfiFvbGetVolumeAttributes (
IN UINTN Instance,
OUT EFI_FVB_ATTRIBUTES_2 *Attributes
@@ -545,6 +539,7 @@ EfiFvbGetVolumeAttributes ( return mFvbEntry[Instance].Fvb->GetAttributes (mFvbEntry[Instance].Fvb, Attributes);
}
+
/**
Modify the attributes and current settings of the specified block
according to the input parameter.
@@ -566,6 +561,7 @@ EfiFvbGetVolumeAttributes ( **/
EFI_STATUS
+EFIAPI
EfiFvbSetVolumeAttributes (
IN UINTN Instance,
IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes
@@ -584,6 +580,7 @@ EfiFvbSetVolumeAttributes ( return mFvbEntry[Instance].Fvb->SetAttributes (mFvbEntry[Instance].Fvb, Attributes);
}
+
/**
Retrieves the physical address of the specified memory mapped FV.
@@ -603,6 +600,7 @@ EfiFvbSetVolumeAttributes ( **/
EFI_STATUS
+EFIAPI
EfiFvbGetPhysicalAddress (
IN UINTN Instance,
OUT EFI_PHYSICAL_ADDRESS *BaseAddress
@@ -621,6 +619,7 @@ EfiFvbGetPhysicalAddress ( return mFvbEntry[Instance].Fvb->GetPhysicalAddress (mFvbEntry[Instance].Fvb, BaseAddress);
}
+
/**
Retrieve the block size of the specified fv.
@@ -630,7 +629,7 @@ EfiFvbGetPhysicalAddress ( the last block of the firmware volume, this function return the status code
EFI_INVALID_PARAMETER.
- If BlockSize is NULL, then ASSERT().
+ If BlockSize is NULL, then ASSERT().
If NumOfBlocks is NULL, then ASSERT().
@@ -648,6 +647,7 @@ EfiFvbGetPhysicalAddress ( **/
EFI_STATUS
+EFIAPI
EfiFvbGetBlockSize (
IN UINTN Instance,
IN EFI_LBA Lba,
@@ -669,6 +669,7 @@ EfiFvbGetBlockSize ( return mFvbEntry[Instance].Fvb->GetBlockSize (mFvbEntry[Instance].Fvb, Lba, BlockSize, NumOfBlocks);
}
+
/**
Erases and initializes a specified range of a firmware volume.
@@ -691,6 +692,7 @@ EfiFvbGetBlockSize ( **/
EFI_STATUS
+EFIAPI
EfiFvbEraseCustomBlockRange (
IN UINTN Instance,
IN EFI_LBA StartLba,
diff --git a/MdeModulePkg/Library/EdkFvbServiceLib/Fvb.h b/MdeModulePkg/Library/EdkFvbServiceLib/Fvb.h index 5d54fd18c9..7d0a09c7e1 100644 --- a/MdeModulePkg/Library/EdkFvbServiceLib/Fvb.h +++ b/MdeModulePkg/Library/EdkFvbServiceLib/Fvb.h @@ -31,6 +31,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include <Library/BaseMemoryLib.h>
#include <Library/UefiRuntimeLib.h>
#include <Library/UefiBootServicesTableLib.h>
+#include <Library/MemoryAllocationLib.h>
#define MAX_FVB_COUNT 16
|