BoardMemoryTest.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /** @file
  2. Perform the platform memory test
  3. Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
  4. Copyright (c) 2021, American Megatrends International LLC.<BR>
  5. SPDX-License-Identifier: BSD-2-Clause-Patent
  6. **/
  7. #include "BoardBdsHook.h"
  8. #include <Protocol/GenericMemoryTest.h>
  9. /**
  10. Perform the memory test base on the memory test intensive level,
  11. and update the memory resource.
  12. @param Level The memory test intensive level.
  13. @retval EFI_STATUS Success test all the system memory and update
  14. the memory resource
  15. **/
  16. EFI_STATUS
  17. MemoryTest (
  18. IN EXTENDMEM_COVERAGE_LEVEL Level
  19. )
  20. {
  21. EFI_STATUS Status;
  22. BOOLEAN RequireSoftECCInit;
  23. EFI_GENERIC_MEMORY_TEST_PROTOCOL *GenMemoryTest;
  24. UINT64 TestedMemorySize;
  25. UINT64 TotalMemorySize;
  26. BOOLEAN ErrorOut;
  27. BOOLEAN TestAbort;
  28. TestedMemorySize = 0;
  29. TotalMemorySize = 0;
  30. ErrorOut = FALSE;
  31. TestAbort = FALSE;
  32. RequireSoftECCInit = FALSE;
  33. Status = gBS->LocateProtocol (
  34. &gEfiGenericMemTestProtocolGuid,
  35. NULL,
  36. (VOID **) &GenMemoryTest
  37. );
  38. if (EFI_ERROR (Status)) {
  39. return EFI_SUCCESS;
  40. }
  41. Status = GenMemoryTest->MemoryTestInit (
  42. GenMemoryTest,
  43. Level,
  44. &RequireSoftECCInit
  45. );
  46. if (Status == EFI_NO_MEDIA) {
  47. //
  48. // The PEI codes also have the relevant memory test code to check the memory,
  49. // it can select to test some range of the memory or all of them. If PEI code
  50. // checks all the memory, this BDS memory test will has no not-test memory to
  51. // do the test, and then the status of EFI_NO_MEDIA will be returned by
  52. // "MemoryTestInit". So it does not need to test memory again, just return.
  53. //
  54. return EFI_SUCCESS;
  55. }
  56. if (PcdGetBool (PcdFastBoot) == FALSE) {
  57. do {
  58. Status = GenMemoryTest->PerformMemoryTest (
  59. GenMemoryTest,
  60. &TestedMemorySize,
  61. &TotalMemorySize,
  62. &ErrorOut,
  63. TestAbort
  64. );
  65. if (ErrorOut && (Status == EFI_DEVICE_ERROR)) {
  66. ASSERT (0);
  67. }
  68. } while (Status != EFI_NOT_FOUND);
  69. }
  70. Status = GenMemoryTest->Finished (GenMemoryTest);
  71. return EFI_SUCCESS;
  72. }