summaryrefslogtreecommitdiff
path: root/MdeModulePkg/Core/Dxe/FwVol/FwVol.c
diff options
context:
space:
mode:
authorStar Zeng <star.zeng@intel.com>2014-08-27 08:31:44 +0000
committerlzeng14 <lzeng14@6f19259b-4bc3-4df7-8a09-765794883524>2014-08-27 08:31:44 +0000
commiteb1cace292ff0c66ca11eff4703c9fa16219c2a1 (patch)
tree83d468a07e859d38d11fe74e8c1edacd634352fb /MdeModulePkg/Core/Dxe/FwVol/FwVol.c
parent436296125b1b013b211d7cfa80df5ea9421bfebd (diff)
downloadedk2-eb1cace292ff0c66ca11eff4703c9fa16219c2a1.zip
edk2-eb1cace292ff0c66ca11eff4703c9fa16219c2a1.tar.gz
edk2-eb1cace292ff0c66ca11eff4703c9fa16219c2a1.tar.bz2
MdeModulePkg DxeCore: Don't cache memory mapped IO FV.
Previous DxeCore FwVol code will cache whole FvMain FV from flash that may be uncached if platform reports FvMain FVB, it will impact DXE performance. The code already has file level cache, so don’t need to cache memory mapped IO FV. It can also reduce memory consumption of caching memory mapped IO FVs. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Star Zeng <star.zeng@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15916 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'MdeModulePkg/Core/Dxe/FwVol/FwVol.c')
-rw-r--r--MdeModulePkg/Core/Dxe/FwVol/FwVol.c160
1 files changed, 93 insertions, 67 deletions
diff --git a/MdeModulePkg/Core/Dxe/FwVol/FwVol.c b/MdeModulePkg/Core/Dxe/FwVol/FwVol.c
index 9355e52..d3447a5 100644
--- a/MdeModulePkg/Core/Dxe/FwVol/FwVol.c
+++ b/MdeModulePkg/Core/Dxe/FwVol/FwVol.c
@@ -3,7 +3,7 @@
Layers on top of Firmware Block protocol to produce a file abstraction
of FV based files.
-Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
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
@@ -46,8 +46,9 @@ FV_DEVICE mFvDevice = {
NULL,
{ NULL, NULL },
0,
+ 0,
FALSE,
- 0
+ FALSE
};
@@ -254,7 +255,14 @@ FreeFvDeviceResource (
//
// Close stream and free resources from SEP
//
- CloseSectionStream (FfsFileEntry->StreamHandle);
+ CloseSectionStream (FfsFileEntry->StreamHandle, FALSE);
+ }
+
+ if (FfsFileEntry->FileCached) {
+ //
+ // Free the cached file buffer.
+ //
+ CoreFreePool (FfsFileEntry->FfsHeader);
}
CoreFreePool (FfsFileEntry);
@@ -262,11 +270,12 @@ FreeFvDeviceResource (
FfsFileEntry = (FFS_FILE_LIST_ENTRY *) NextEntry;
}
-
- //
- // Free the cache
- //
- CoreFreePool (FvDevice->CachedFv);
+ if (!FvDevice->IsMemoryMapped) {
+ //
+ // Free the cached FV buffer.
+ //
+ CoreFreePool (FvDevice->CachedFv);
+ }
//
// Free Volume Header
@@ -310,7 +319,7 @@ FvCheck (
EFI_FFS_FILE_STATE FileState;
UINT8 *TopFvAddress;
UINTN TestLength;
-
+ EFI_PHYSICAL_ADDRESS PhysicalAddress;
Fvb = FvDevice->Fvb;
FwVolHeader = FvDevice->FwVolHeader;
@@ -325,10 +334,25 @@ FvCheck (
// the header to check to make sure the volume is valid
//
Size = (UINTN)(FwVolHeader->FvLength - FwVolHeader->HeaderLength);
- FvDevice->CachedFv = AllocatePool (Size);
+ if ((FvbAttributes & EFI_FVB2_MEMORY_MAPPED) != 0) {
+ FvDevice->IsMemoryMapped = TRUE;
- if (FvDevice->CachedFv == NULL) {
- return EFI_OUT_OF_RESOURCES;
+ Status = Fvb->GetPhysicalAddress (Fvb, &PhysicalAddress);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ //
+ // Don't cache memory mapped FV really.
+ //
+ FvDevice->CachedFv = (UINT8 *) (UINTN) (PhysicalAddress + FwVolHeader->HeaderLength);
+ } else {
+ FvDevice->IsMemoryMapped = FALSE;
+ FvDevice->CachedFv = AllocatePool (Size);
+
+ if (FvDevice->CachedFv == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
}
//
@@ -336,69 +360,71 @@ FvCheck (
//
FvDevice->EndOfCachedFv = FvDevice->CachedFv + Size;
- //
- // Copy FV minus header into memory using the block map we have all ready
- // read into memory.
- //
- BlockMap = FwVolHeader->BlockMap;
- CacheLocation = FvDevice->CachedFv;
- LbaIndex = 0;
- LbaOffset = 0;
- HeaderSize = FwVolHeader->HeaderLength;
- while ((BlockMap->NumBlocks != 0) || (BlockMap->Length != 0)) {
- Index = 0;
- Size = BlockMap->Length;
- if (HeaderSize > 0) {
- //
- // Skip header size
- //
- for (; Index < BlockMap->NumBlocks && HeaderSize >= BlockMap->Length; Index ++) {
- HeaderSize -= BlockMap->Length;
- LbaIndex ++;
- }
-
- //
- // Check whether FvHeader is crossing the multi block range.
- //
- if (Index >= BlockMap->NumBlocks) {
- BlockMap++;
- continue;
- } else if (HeaderSize > 0) {
- LbaOffset = HeaderSize;
- Size = BlockMap->Length - HeaderSize;
- HeaderSize = 0;
- }
- }
-
+ if (!FvDevice->IsMemoryMapped) {
//
- // read the FV data
+ // Copy FV minus header into memory using the block map we have all ready
+ // read into memory.
//
- for (; Index < BlockMap->NumBlocks; Index ++) {
- Status = Fvb->Read (Fvb,
- LbaIndex,
- LbaOffset,
- &Size,
- CacheLocation
- );
+ BlockMap = FwVolHeader->BlockMap;
+ CacheLocation = FvDevice->CachedFv;
+ LbaIndex = 0;
+ LbaOffset = 0;
+ HeaderSize = FwVolHeader->HeaderLength;
+ while ((BlockMap->NumBlocks != 0) || (BlockMap->Length != 0)) {
+ Index = 0;
+ Size = BlockMap->Length;
+ if (HeaderSize > 0) {
+ //
+ // Skip header size
+ //
+ for (; Index < BlockMap->NumBlocks && HeaderSize >= BlockMap->Length; Index ++) {
+ HeaderSize -= BlockMap->Length;
+ LbaIndex ++;
+ }
+ //
+ // Check whether FvHeader is crossing the multi block range.
+ //
+ if (Index >= BlockMap->NumBlocks) {
+ BlockMap++;
+ continue;
+ } else if (HeaderSize > 0) {
+ LbaOffset = HeaderSize;
+ Size = BlockMap->Length - HeaderSize;
+ HeaderSize = 0;
+ }
+ }
+
//
- // Not check EFI_BAD_BUFFER_SIZE, for Size = BlockMap->Length
+ // read the FV data
//
- if (EFI_ERROR (Status)) {
- goto Done;
- }
+ for (; Index < BlockMap->NumBlocks; Index ++) {
+ Status = Fvb->Read (Fvb,
+ LbaIndex,
+ LbaOffset,
+ &Size,
+ CacheLocation
+ );
- LbaIndex++;
- CacheLocation += Size;
+ //
+ // Not check EFI_BAD_BUFFER_SIZE, for Size = BlockMap->Length
+ //
+ if (EFI_ERROR (Status)) {
+ goto Done;
+ }
- //
- // After we skip Fv Header always read from start of block
- //
- LbaOffset = 0;
- Size = BlockMap->Length;
- }
+ LbaIndex++;
+ CacheLocation += Size;
- BlockMap++;
+ //
+ // After we skip Fv Header always read from start of block
+ //
+ LbaOffset = 0;
+ Size = BlockMap->Length;
+ }
+
+ BlockMap++;
+ }
}
//