MdeModulePkg/GenericMemoryTest: Handle more reliable memory

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=650
Today's implementation converts the untested more reliable memory
from reserved GCD type to system memory GCD type.
Though it doesn't impact the return result of gBS->GetMemoryMap().
But it impacts the return result of gDS->GetMemorySpaceDescriptor().
The patch fixes the bug to convert the untested more reliable memory
from reserved GCD type to more reliable memory GCD type.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
This commit is contained in:
Ruiyu Ni 2018-02-10 22:22:15 +08:00
parent f068aa038d
commit 2e5fb984ed
1 changed files with 50 additions and 25 deletions

View File

@ -1,6 +1,6 @@
/** @file /** @file
Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR> Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials This program and the accompanying materials
are licensed and made available under the terms and conditions are licensed and made available under the terms and conditions
@ -106,7 +106,8 @@ ConstructBaseMemoryRange (
gDS->GetMemorySpaceMap (&NumberOfDescriptors, &MemorySpaceMap); gDS->GetMemorySpaceMap (&NumberOfDescriptors, &MemorySpaceMap);
for (Index = 0; Index < NumberOfDescriptors; Index++) { for (Index = 0; Index < NumberOfDescriptors; Index++) {
if (MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeSystemMemory) { if ((MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeSystemMemory) ||
(MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeMoreReliable)) {
Private->BaseMemorySize += MemorySpaceMap[Index].Length; Private->BaseMemorySize += MemorySpaceMap[Index].Length;
} }
} }
@ -138,6 +139,41 @@ DestroyLinkList (
} }
} }
/**
Convert the memory range to tested.
@param BaseAddress Base address of the memory range.
@param Length Length of the memory range.
@param Capabilities Capabilities of the memory range.
@retval EFI_SUCCESS The memory range is converted to tested.
@retval others Error happens.
**/
EFI_STATUS
ConvertToTestedMemory (
IN UINT64 BaseAddress,
IN UINT64 Length,
IN UINT64 Capabilities
)
{
EFI_STATUS Status;
Status = gDS->RemoveMemorySpace (
BaseAddress,
Length
);
if (!EFI_ERROR (Status)) {
Status = gDS->AddMemorySpace (
((Capabilities & EFI_MEMORY_MORE_RELIABLE) == EFI_MEMORY_MORE_RELIABLE) ?
EfiGcdMemoryTypeMoreReliable : EfiGcdMemoryTypeSystemMemory,
BaseAddress,
Length,
Capabilities &~
(EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED | EFI_MEMORY_RUNTIME)
);
}
return Status;
}
/** /**
Add the extened memory to whole system memory map. Add the extened memory to whole system memory map.
@ -160,18 +196,12 @@ UpdateMemoryMap (
while (Link != &Private->NonTestedMemRanList) { while (Link != &Private->NonTestedMemRanList) {
Range = NONTESTED_MEMORY_RANGE_FROM_LINK (Link); Range = NONTESTED_MEMORY_RANGE_FROM_LINK (Link);
gDS->RemoveMemorySpace ( ConvertToTestedMemory (
Range->StartAddress, Range->StartAddress,
Range->Length Range->Length,
); Range->Capabilities &~
(EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED | EFI_MEMORY_RUNTIME)
gDS->AddMemorySpace ( );
EfiGcdMemoryTypeSystemMemory,
Range->StartAddress,
Range->Length,
Range->Capabilities &~(EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED | EFI_MEMORY_RUNTIME)
);
Link = Link->ForwardLink; Link = Link->ForwardLink;
} }
@ -215,17 +245,12 @@ DirectRangeTest (
// //
// Add the tested compatible memory to system memory using GCD service // Add the tested compatible memory to system memory using GCD service
// //
gDS->RemoveMemorySpace ( ConvertToTestedMemory (
StartAddress, StartAddress,
Length Length,
); Capabilities &~
(EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED | EFI_MEMORY_RUNTIME)
gDS->AddMemorySpace ( );
EfiGcdMemoryTypeSystemMemory,
StartAddress,
Length,
Capabilities &~(EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED | EFI_MEMORY_RUNTIME)
);
return EFI_SUCCESS; return EFI_SUCCESS;
} }