From 8f227c2fd97c8160c6e3f99c532d778942efaf62 Mon Sep 17 00:00:00 2001 From: Ruiyu Ni Date: Thu, 6 Aug 2015 08:39:30 +0000 Subject: [PATCH 1/1] 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 Reviewed-by: Star Zeng git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@18172 6f19259b-4bc3-4df7-8a09-765794883524 --- .../PlatformBootManager.c | 88 +++++++++++++++++++ .../PlatformBootManager.h | 1 + .../PlatformBootManagerLib.inf | 3 + 3 files changed, 92 insertions(+) diff --git a/Nt32Pkg/Library/PlatformBootManagerLib/PlatformBootManager.c b/Nt32Pkg/Library/PlatformBootManagerLib/PlatformBootManager.c index a527a4233d..7964b2b808 100644 --- a/Nt32Pkg/Library/PlatformBootManagerLib/PlatformBootManager.c +++ b/Nt32Pkg/Library/PlatformBootManagerLib/PlatformBootManager.c @@ -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 ( diff --git a/Nt32Pkg/Library/PlatformBootManagerLib/PlatformBootManager.h b/Nt32Pkg/Library/PlatformBootManagerLib/PlatformBootManager.h index 6ab7d9f70c..eb1ffe1c71 100644 --- a/Nt32Pkg/Library/PlatformBootManagerLib/PlatformBootManager.h +++ b/Nt32Pkg/Library/PlatformBootManagerLib/PlatformBootManager.h @@ -17,6 +17,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include +#include #include #include #include diff --git a/Nt32Pkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf b/Nt32Pkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf index 897c5cd2ce..7fac55b3fd 100644 --- a/Nt32Pkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf +++ b/Nt32Pkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf @@ -47,6 +47,9 @@ [Guids] gEfiWinNtSystemConfigGuid +[Protocols] + gEfiGenericMemTestProtocolGuid ## CONSUMES + [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdConOutRow gEfiMdeModulePkgTokenSpaceGuid.PcdConOutColumn -- 2.39.2