PlatformBmMemoryTest.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /** @file
  2. Perform the platform memory test
  3. Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include "PlatformBm.h"
  7. //
  8. // BDS Platform Functions
  9. //
  10. /**
  11. Perform the memory test base on the memory test intensive level,
  12. and update the memory resource.
  13. @param Level The memory test intensive level.
  14. @retval EFI_STATUS Success test all the system memory and update
  15. the memory resource
  16. **/
  17. EFI_STATUS
  18. PlatformBootManagerMemoryTest (
  19. IN EXTENDMEM_COVERAGE_LEVEL Level
  20. )
  21. {
  22. EFI_STATUS Status;
  23. EFI_STATUS KeyStatus;
  24. EFI_STATUS InitStatus;
  25. EFI_STATUS ReturnStatus;
  26. BOOLEAN RequireSoftECCInit;
  27. EFI_GENERIC_MEMORY_TEST_PROTOCOL *GenMemoryTest;
  28. UINT64 TestedMemorySize;
  29. UINT64 TotalMemorySize;
  30. BOOLEAN ErrorOut;
  31. BOOLEAN TestAbort;
  32. EFI_INPUT_KEY Key;
  33. ReturnStatus = EFI_SUCCESS;
  34. ZeroMem (&Key, sizeof (EFI_INPUT_KEY));
  35. TestedMemorySize = 0;
  36. TotalMemorySize = 0;
  37. ErrorOut = FALSE;
  38. TestAbort = FALSE;
  39. RequireSoftECCInit = FALSE;
  40. Status = gBS->LocateProtocol (
  41. &gEfiGenericMemTestProtocolGuid,
  42. NULL,
  43. (VOID **)&GenMemoryTest
  44. );
  45. if (EFI_ERROR (Status)) {
  46. return EFI_SUCCESS;
  47. }
  48. InitStatus = GenMemoryTest->MemoryTestInit (
  49. GenMemoryTest,
  50. Level,
  51. &RequireSoftECCInit
  52. );
  53. if (InitStatus == EFI_NO_MEDIA) {
  54. //
  55. // The PEI codes also have the relevant memory test code to check the memory,
  56. // it can select to test some range of the memory or all of them. If PEI code
  57. // checks all the memory, this BDS memory test will has no not-test memory to
  58. // do the test, and then the status of EFI_NO_MEDIA will be returned by
  59. // "MemoryTestInit". So it does not need to test memory again, just return.
  60. //
  61. return EFI_SUCCESS;
  62. }
  63. DEBUG ((DEBUG_INFO, "Enter memory test.\n"));
  64. do {
  65. Status = GenMemoryTest->PerformMemoryTest (
  66. GenMemoryTest,
  67. &TestedMemorySize,
  68. &TotalMemorySize,
  69. &ErrorOut,
  70. TestAbort
  71. );
  72. if (ErrorOut && (Status == EFI_DEVICE_ERROR)) {
  73. PrintXY (10, 10, NULL, NULL, L"Memory Testing failed!");
  74. ASSERT (0);
  75. }
  76. DEBUG ((DEBUG_INFO, "Perform memory test (ESC to skip).\n"));
  77. if (!PcdGetBool (PcdConInConnectOnDemand)) {
  78. KeyStatus = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
  79. if (!EFI_ERROR (KeyStatus) && (Key.ScanCode == SCAN_ESC)) {
  80. if (!RequireSoftECCInit) {
  81. Status = GenMemoryTest->Finished (GenMemoryTest);
  82. goto Done;
  83. }
  84. TestAbort = TRUE;
  85. }
  86. }
  87. } while (Status != EFI_NOT_FOUND);
  88. Status = GenMemoryTest->Finished (GenMemoryTest);
  89. Done:
  90. DEBUG ((DEBUG_INFO, "%d bytes of system memory tested OK\r\n", TotalMemorySize));
  91. return ReturnStatus;
  92. }