MdeModulePkg: PI1.4 DxeCore GetMemoryMap() update

PI1.4: Updates DxeCore to add all EfiGcdMemoryTypeReserved memory
into UEFI memory map.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Liming Gao <liming.gao@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17253 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Liming Gao
2015-04-29 05:11:21 +00:00
committed by lgao4
parent a1b7065b2e
commit ba2c052791

View File

@ -1530,7 +1530,7 @@ CoreGetMemoryMap (
EFI_STATUS Status; EFI_STATUS Status;
UINTN Size; UINTN Size;
UINTN BufferSize; UINTN BufferSize;
UINTN NumberOfRuntimePersistentEntries; UINTN NumberOfEntries;
LIST_ENTRY *Link; LIST_ENTRY *Link;
MEMORY_MAP *Entry; MEMORY_MAP *Entry;
EFI_GCD_MAP_ENTRY *GcdMapEntry; EFI_GCD_MAP_ENTRY *GcdMapEntry;
@ -1547,21 +1547,17 @@ CoreGetMemoryMap (
CoreAcquireGcdMemoryLock (); CoreAcquireGcdMemoryLock ();
// //
// Count the number of Reserved and MMIO entries that are marked for runtime use // Count the number of Reserved and runtime MMIO entries
// And, count the number of Persistent entries. // And, count the number of Persistent entries.
// //
NumberOfRuntimePersistentEntries = 0; NumberOfEntries = 0;
for (Link = mGcdMemorySpaceMap.ForwardLink; Link != &mGcdMemorySpaceMap; Link = Link->ForwardLink) { for (Link = mGcdMemorySpaceMap.ForwardLink; Link != &mGcdMemorySpaceMap; Link = Link->ForwardLink) {
GcdMapEntry = CR (Link, EFI_GCD_MAP_ENTRY, Link, EFI_GCD_MAP_SIGNATURE); GcdMapEntry = CR (Link, EFI_GCD_MAP_ENTRY, Link, EFI_GCD_MAP_SIGNATURE);
if ((GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypeReserved) || if ((GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypePersistentMemory) ||
(GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypeMemoryMappedIo)) { (GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypeReserved) ||
if ((GcdMapEntry->Attributes & EFI_MEMORY_RUNTIME) == EFI_MEMORY_RUNTIME) { ((GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypeMemoryMappedIo) &&
NumberOfRuntimePersistentEntries ++; ((GcdMapEntry->Attributes & EFI_MEMORY_RUNTIME) == EFI_MEMORY_RUNTIME))) {
} NumberOfEntries ++;
}
if (GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypePersistentMemory) {
NumberOfRuntimePersistentEntries ++;
} }
} }
@ -1587,7 +1583,7 @@ CoreGetMemoryMap (
// //
// Compute the buffer size needed to fit the entire map // Compute the buffer size needed to fit the entire map
// //
BufferSize = Size * NumberOfRuntimePersistentEntries; BufferSize = Size * NumberOfEntries;
for (Link = gMemoryMap.ForwardLink; Link != &gMemoryMap; Link = Link->ForwardLink) { for (Link = gMemoryMap.ForwardLink; Link != &gMemoryMap; Link = Link->ForwardLink) {
BufferSize += Size; BufferSize += Size;
} }
@ -1652,33 +1648,31 @@ CoreGetMemoryMap (
for (Link = mGcdMemorySpaceMap.ForwardLink; Link != &mGcdMemorySpaceMap; Link = Link->ForwardLink) { for (Link = mGcdMemorySpaceMap.ForwardLink; Link != &mGcdMemorySpaceMap; Link = Link->ForwardLink) {
GcdMapEntry = CR (Link, EFI_GCD_MAP_ENTRY, Link, EFI_GCD_MAP_SIGNATURE); GcdMapEntry = CR (Link, EFI_GCD_MAP_ENTRY, Link, EFI_GCD_MAP_SIGNATURE);
if ((GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypeReserved) || if ((GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypeReserved) ||
(GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypeMemoryMappedIo)) { ((GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypeMemoryMappedIo) &&
if ((GcdMapEntry->Attributes & EFI_MEMORY_RUNTIME) == EFI_MEMORY_RUNTIME) { ((GcdMapEntry->Attributes & EFI_MEMORY_RUNTIME) == EFI_MEMORY_RUNTIME))) {
// //
// Create EFI_MEMORY_DESCRIPTOR for every Reserved and MMIO GCD entries // Create EFI_MEMORY_DESCRIPTOR for every Reserved and runtime MMIO GCD entries
// that are marked for runtime use //
// MemoryMap->PhysicalStart = GcdMapEntry->BaseAddress;
MemoryMap->PhysicalStart = GcdMapEntry->BaseAddress; MemoryMap->VirtualStart = 0;
MemoryMap->VirtualStart = 0; MemoryMap->NumberOfPages = RShiftU64 ((GcdMapEntry->EndAddress - GcdMapEntry->BaseAddress + 1), EFI_PAGE_SHIFT);
MemoryMap->NumberOfPages = RShiftU64 ((GcdMapEntry->EndAddress - GcdMapEntry->BaseAddress + 1), EFI_PAGE_SHIFT); MemoryMap->Attribute = GcdMapEntry->Attributes & ~EFI_MEMORY_PORT_IO;
MemoryMap->Attribute = GcdMapEntry->Attributes & ~EFI_MEMORY_PORT_IO;
if (GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypeReserved) { if (GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypeReserved) {
MemoryMap->Type = EfiReservedMemoryType; MemoryMap->Type = EfiReservedMemoryType;
} else if (GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypeMemoryMappedIo) { } else if (GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypeMemoryMappedIo) {
if ((GcdMapEntry->Attributes & EFI_MEMORY_PORT_IO) == EFI_MEMORY_PORT_IO) { if ((GcdMapEntry->Attributes & EFI_MEMORY_PORT_IO) == EFI_MEMORY_PORT_IO) {
MemoryMap->Type = EfiMemoryMappedIOPortSpace; MemoryMap->Type = EfiMemoryMappedIOPortSpace;
} else { } else {
MemoryMap->Type = EfiMemoryMappedIO; MemoryMap->Type = EfiMemoryMappedIO;
}
} }
//
// Check to see if the new Memory Map Descriptor can be merged with an
// existing descriptor if they are adjacent and have the same attributes
//
MemoryMap = MergeMemoryMapDescriptor (MemoryMapStart, MemoryMap, Size);
} }
//
// Check to see if the new Memory Map Descriptor can be merged with an
// existing descriptor if they are adjacent and have the same attributes
//
MemoryMap = MergeMemoryMapDescriptor (MemoryMapStart, MemoryMap, Size);
} }
if (GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypePersistentMemory) { if (GcdMapEntry->GcdMemoryType == EfiGcdMemoryTypePersistentMemory) {