summaryrefslogtreecommitdiff
path: root/MdeModulePkg
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
parent436296125b1b013b211d7cfa80df5ea9421bfebd (diff)
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')
-rw-r--r--MdeModulePkg/Core/Dxe/DxeMain.h7
-rw-r--r--MdeModulePkg/Core/Dxe/FwVol/FwVol.c160
-rw-r--r--MdeModulePkg/Core/Dxe/FwVol/FwVolDriver.h6
-rw-r--r--MdeModulePkg/Core/Dxe/FwVol/FwVolRead.c37
-rw-r--r--MdeModulePkg/Core/Dxe/SectionExtraction/CoreSectionExtraction.c13
5 files changed, 140 insertions, 83 deletions
diff --git a/MdeModulePkg/Core/Dxe/DxeMain.h b/MdeModulePkg/Core/Dxe/DxeMain.h
index 3b2b11d276..f4db06d43e 100644
--- a/MdeModulePkg/Core/Dxe/DxeMain.h
+++ b/MdeModulePkg/Core/Dxe/DxeMain.h
@@ -2,7 +2,7 @@
The internal header file includes the common header files, defines
internal structure and functions used by DxeCore module.
-Copyright (c) 2006 - 2013, 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
@@ -2356,6 +2356,8 @@ GetSection (
SEP member function. Deletes an existing section stream
@param StreamHandleToClose Indicates the stream to close
+ @param FreeStreamBuffer TRUE - Need to free stream buffer;
+ FALSE - No need to free stream buffer.
@retval EFI_SUCCESS The section stream is closed sucessfully.
@retval EFI_OUT_OF_RESOURCES Memory allocation failed.
@@ -2366,7 +2368,8 @@ GetSection (
EFI_STATUS
EFIAPI
CloseSectionStream (
- IN UINTN StreamHandleToClose
+ IN UINTN StreamHandleToClose,
+ IN BOOLEAN FreeStreamBuffer
);
/**
diff --git a/MdeModulePkg/Core/Dxe/FwVol/FwVol.c b/MdeModulePkg/Core/Dxe/FwVol/FwVol.c
index 9355e52ab0..d3447a57ac 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++;
+ }
}
//
diff --git a/MdeModulePkg/Core/Dxe/FwVol/FwVolDriver.h b/MdeModulePkg/Core/Dxe/FwVol/FwVolDriver.h
index 4986792edd..514c6ed211 100644
--- a/MdeModulePkg/Core/Dxe/FwVol/FwVolDriver.h
+++ b/MdeModulePkg/Core/Dxe/FwVol/FwVolDriver.h
@@ -2,7 +2,7 @@
Firmware File System protocol. 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
@@ -26,6 +26,7 @@ typedef struct {
LIST_ENTRY Link;
EFI_FFS_FILE_HEADER *FfsHeader;
UINTN StreamHandle;
+ BOOLEAN FileCached;
} FFS_FILE_LIST_ENTRY;
typedef struct {
@@ -42,9 +43,10 @@ typedef struct {
LIST_ENTRY FfsFileListHeader;
+ UINT32 AuthenticationStatus;
UINT8 ErasePolarity;
BOOLEAN IsFfs3Fv;
- UINT32 AuthenticationStatus;
+ BOOLEAN IsMemoryMapped;
} FV_DEVICE;
#define FV_DEVICE_FROM_THIS(a) CR(a, FV_DEVICE, Fv, FV2_DEVICE_SIGNATURE)
diff --git a/MdeModulePkg/Core/Dxe/FwVol/FwVolRead.c b/MdeModulePkg/Core/Dxe/FwVol/FwVolRead.c
index f2c0dd5de4..1acac5d8fd 100644
--- a/MdeModulePkg/Core/Dxe/FwVol/FwVolRead.c
+++ b/MdeModulePkg/Core/Dxe/FwVol/FwVolRead.c
@@ -280,6 +280,7 @@ FvReadFile (
UINT8 *SrcPtr;
EFI_FFS_FILE_HEADER *FfsHeader;
UINTN InputBufferSize;
+ UINTN WholeFileSize;
if (NameGuid == NULL) {
return EFI_INVALID_PARAMETER;
@@ -290,7 +291,7 @@ FvReadFile (
//
// Keep looking until we find the matching NameGuid.
- // The Key is really an FfsFileEntry
+ // The Key is really a FfsFileEntry
//
FvDevice->LastKey = 0;
do {
@@ -312,6 +313,26 @@ FvReadFile (
// Get a pointer to the header
//
FfsHeader = FvDevice->LastKey->FfsHeader;
+ if (FvDevice->IsMemoryMapped) {
+ //
+ // Memory mapped FV has not been cached, so here is to cache by file.
+ //
+ if (!FvDevice->LastKey->FileCached) {
+ //
+ // Cache FFS file to memory buffer.
+ //
+ WholeFileSize = IS_FFS_FILE2 (FfsHeader) ? FFS_FILE2_SIZE (FfsHeader): FFS_FILE_SIZE (FfsHeader);
+ FfsHeader = AllocateCopyPool (WholeFileSize, FfsHeader);
+ if (FfsHeader == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+ //
+ // Let FfsHeader in FfsFileEntry point to the cached file buffer.
+ //
+ FvDevice->LastKey->FfsHeader = FfsHeader;
+ FvDevice->LastKey->FileCached = TRUE;
+ }
+ }
//
// Remember callers buffer size
@@ -427,13 +448,12 @@ FvReadFileSection (
FvDevice = FV_DEVICE_FROM_THIS (This);
//
- // Read the whole file into buffer
+ // Read the file
//
- FileBuffer = NULL;
Status = FvReadFile (
This,
NameGuid,
- (VOID **)&FileBuffer,
+ NULL,
&FileSize,
&FileType,
&FileAttributes,
@@ -447,8 +467,11 @@ FvReadFileSection (
if (EFI_ERROR (Status)) {
return Status;
}
- ASSERT (FileBuffer != NULL);
-
+ if (IS_FFS_FILE2 (FfsEntry->FfsHeader)) {
+ FileBuffer = ((UINT8 *) FfsEntry->FfsHeader) + sizeof (EFI_FFS_FILE_HEADER2);
+ } else {
+ FileBuffer = ((UINT8 *) FfsEntry->FfsHeader) + sizeof (EFI_FFS_FILE_HEADER);
+ }
//
// Check to see that the file actually HAS sections before we go any further.
//
@@ -497,8 +520,6 @@ FvReadFileSection (
//
Done:
- CoreFreePool (FileBuffer);
-
return Status;
}
diff --git a/MdeModulePkg/Core/Dxe/SectionExtraction/CoreSectionExtraction.c b/MdeModulePkg/Core/Dxe/SectionExtraction/CoreSectionExtraction.c
index 981744c4d3..3c4f3f58db 100644
--- a/MdeModulePkg/Core/Dxe/SectionExtraction/CoreSectionExtraction.c
+++ b/MdeModulePkg/Core/Dxe/SectionExtraction/CoreSectionExtraction.c
@@ -440,7 +440,7 @@ OpenSectionStream (
return OpenSectionStreamEx (
SectionStreamLength,
SectionStream,
- TRUE,
+ FALSE,
0,
SectionStreamHandle
);
@@ -1344,7 +1344,7 @@ FreeChildNode (
// If it's an encapsulating section, we close the resulting section stream.
// CloseSectionStream will free all memory associated with the stream.
//
- CloseSectionStream (ChildNode->EncapsulatedStreamHandle);
+ CloseSectionStream (ChildNode->EncapsulatedStreamHandle, TRUE);
}
if (ChildNode->Event != NULL) {
@@ -1362,6 +1362,8 @@ FreeChildNode (
SEP member function. Deletes an existing section stream
@param StreamHandleToClose Indicates the stream to close
+ @param FreeStreamBuffer TRUE - Need to free stream buffer;
+ FALSE - No need to free stream buffer.
@retval EFI_SUCCESS The section stream is closed sucessfully.
@retval EFI_OUT_OF_RESOURCES Memory allocation failed.
@@ -1372,7 +1374,8 @@ FreeChildNode (
EFI_STATUS
EFIAPI
CloseSectionStream (
- IN UINTN StreamHandleToClose
+ IN UINTN StreamHandleToClose,
+ IN BOOLEAN FreeStreamBuffer
)
{
CORE_SECTION_STREAM_NODE *StreamNode;
@@ -1397,7 +1400,9 @@ CloseSectionStream (
ChildNode = CHILD_SECTION_NODE_FROM_LINK (Link);
FreeChildNode (ChildNode);
}
- CoreFreePool (StreamNode->StreamBuffer);
+ if (FreeStreamBuffer) {
+ CoreFreePool (StreamNode->StreamBuffer);
+ }
CoreFreePool (StreamNode);
Status = EFI_SUCCESS;
} else {