Nt32Pkg: Platform BDS should test the untested memory

NT32 has two ranges of memory, each 64MB. The first range is tested
but the second range is not tested. Platform BDS should have code
to use MemoryTest protocol to test the memory so that the second
range of untested memory can be added to the system memory pool.

Without the code SCT MemoryAllocation test case may fail. Because it
firstly use GetMemoryMap to find the biggest free memory descriptor
and then requests to allocate one page more than that biggest free memory.
It expects the allocation fails but actually the DXE core automatically
converts the second range of untested memory to tested and allocate the memory
from the second range.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@18172 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Ruiyu Ni 2015-08-06 08:39:30 +00:00 committed by niruiyu
parent 72362a75a4
commit 8f227c2fd9
3 changed files with 92 additions and 0 deletions

View File

@ -18,6 +18,93 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
EFI_GUID mUefiShellFileGuid = { 0x7C04A583, 0x9E3E, 0x4f1c, 0xAD, 0x65, 0xE0, 0x52, 0x68, 0xD0, 0xB4, 0xD1 };
/**
Perform the memory test base on the memory test intensive level,
and update the memory resource.
@param Level The memory test intensive level.
@retval EFI_STATUS Success test all the system memory and update
the memory resource
**/
EFI_STATUS
PlatformBootManagerMemoryTest (
IN EXTENDMEM_COVERAGE_LEVEL Level
)
{
EFI_STATUS Status;
BOOLEAN RequireSoftECCInit;
EFI_GENERIC_MEMORY_TEST_PROTOCOL *GenMemoryTest;
UINT64 TestedMemorySize;
UINT64 TotalMemorySize;
UINTN TestPercent;
UINT64 PreviousValue;
BOOLEAN ErrorOut;
UINT32 TempData;
TestedMemorySize = 0;
TotalMemorySize = 0;
PreviousValue = 0;
RequireSoftECCInit = FALSE;
Status = gBS->LocateProtocol (
&gEfiGenericMemTestProtocolGuid,
NULL,
(VOID **) &GenMemoryTest
);
if (EFI_ERROR (Status)) {
return EFI_SUCCESS;
}
Status = GenMemoryTest->MemoryTestInit (
GenMemoryTest,
Level,
&RequireSoftECCInit
);
if (Status == EFI_NO_MEDIA) {
//
// The PEI codes also have the relevant memory test code to check the memory,
// it can select to test some range of the memory or all of them. If PEI code
// checks all the memory, this BDS memory test will has no not-test memory to
// do the test, and then the status of EFI_NO_MEDIA will be returned by
// "MemoryTestInit". So it does not need to test memory again, just return.
//
return EFI_SUCCESS;
}
do {
Status = GenMemoryTest->PerformMemoryTest (
GenMemoryTest,
&TestedMemorySize,
&TotalMemorySize,
&ErrorOut,
FALSE
);
if (ErrorOut && (Status == EFI_DEVICE_ERROR)) {
Print (L"System encounters memory errors!");
CpuDeadLoop ();
}
TempData = (UINT32) DivU64x32 (TotalMemorySize, 16);
TestPercent = (UINTN) DivU64x32 (
DivU64x32 (MultU64x32 (TestedMemorySize, 100), 16),
TempData
);
if (TestPercent != PreviousValue) {
Print (L"Perform memory test: %d/100", TestPercent);
PreviousValue = TestPercent;
}
} while (Status != EFI_NOT_FOUND);
Status = GenMemoryTest->Finished (GenMemoryTest);
Print (L"\r%dM bytes of system memory tested OK\n", (UINT32) DivU64x32 (TotalMemorySize, 1024 * 1024));
return EFI_SUCCESS;
}
/**
Return the index of the load option in the load option array.
@ -197,6 +284,7 @@ PlatformBootManagerAfterConsole (
VOID
)
{
PlatformBootManagerMemoryTest (QUICK);
EfiBootManagerConnectAll ();
EfiBootManagerRefreshAllBootOption ();
Print (

View File

@ -17,6 +17,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <PiDxe.h>
#include <Guid/WinNtSystemConfig.h>
#include <Protocol/GenericMemoryTest.h>
#include <Protocol/WinNtThunk.h>
#include <Protocol/WinNtIo.h>
#include <Protocol/LoadedImage.h>

View File

@ -47,6 +47,9 @@
[Guids]
gEfiWinNtSystemConfigGuid
[Protocols]
gEfiGenericMemTestProtocolGuid ## CONSUMES
[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdConOutRow
gEfiMdeModulePkgTokenSpaceGuid.PcdConOutColumn