Home | History | Annotate | Download | only in NullMemoryTestDxe
      1 /** @file
      2   Implementation of Generic Memory Test Protocol which does not perform real memory test.
      3 
      4 Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
      5 This program and the accompanying materials
      6 are licensed and made available under the terms and conditions of the BSD License
      7 which accompanies this distribution.  The full text of the license may be found at
      8 http://opensource.org/licenses/bsd-license.php
      9 
     10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     12 
     13 **/
     14 
     15 
     16 #include "NullMemoryTest.h"
     17 
     18 UINT64                            mTestedSystemMemory = 0;
     19 UINT64                            mTotalSystemMemory  = 0;
     20 EFI_HANDLE                        mGenericMemoryTestHandle;
     21 
     22 EFI_GENERIC_MEMORY_TEST_PROTOCOL  mGenericMemoryTest = {
     23   InitializeMemoryTest,
     24   GenPerformMemoryTest,
     25   GenMemoryTestFinished,
     26   GenCompatibleRangeTest
     27 };
     28 
     29 /**
     30   Entry point of the NULL memory test driver.
     31 
     32   This function is the entry point of the NULL memory test driver.
     33   It simply installs the Generic Memory Test Protocol.
     34 
     35   @param  ImageHandle    The firmware allocated handle for the EFI image.
     36   @param  SystemTable    A pointer to the EFI System Table.
     37 
     38   @retval EFI_SUCCESS    Generic Memory Test Protocol is successfully installed.
     39 
     40 **/
     41 EFI_STATUS
     42 EFIAPI
     43 GenericMemoryTestEntryPoint (
     44   IN  EFI_HANDLE           ImageHandle,
     45   IN  EFI_SYSTEM_TABLE     *SystemTable
     46   )
     47 {
     48   EFI_STATUS  Status;
     49 
     50   Status = gBS->InstallProtocolInterface (
     51                   &mGenericMemoryTestHandle,
     52                   &gEfiGenericMemTestProtocolGuid,
     53                   EFI_NATIVE_INTERFACE,
     54                   &mGenericMemoryTest
     55                   );
     56   ASSERT_EFI_ERROR (Status);
     57 
     58   return EFI_SUCCESS;
     59 }
     60 
     61 /**
     62   Initialize the generic memory test.
     63 
     64   This function implements EFI_GENERIC_MEMORY_TEST_PROTOCOL.MemoryTestInit.
     65   It simply promotes untested reserved memory to system memory without real test.
     66 
     67   @param  This                Protocol instance pointer.
     68   @param  Level               The coverage level of the memory test.
     69   @param  RequireSoftECCInit  Indicate if the memory need software ECC init.
     70 
     71   @retval EFI_SUCCESS         The generic memory test initialized correctly.
     72   @retval EFI_NO_MEDIA        There is not any non-tested memory found, in this
     73                               function if not any non-tesed memory found means
     74                               that the memory test driver have not detect any
     75                               non-tested extended memory of current system.
     76 
     77 **/
     78 EFI_STATUS
     79 EFIAPI
     80 InitializeMemoryTest (
     81   IN EFI_GENERIC_MEMORY_TEST_PROTOCOL          *This,
     82   IN  EXTENDMEM_COVERAGE_LEVEL                 Level,
     83   OUT BOOLEAN                                  *RequireSoftECCInit
     84   )
     85 {
     86   UINTN                           NumberOfDescriptors;
     87   EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMap;
     88   UINTN                           Index;
     89 
     90   gDS->GetMemorySpaceMap (&NumberOfDescriptors, &MemorySpaceMap);
     91   for (Index = 0; Index < NumberOfDescriptors; Index++) {
     92     if (MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeReserved &&
     93         (MemorySpaceMap[Index].Capabilities & (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED)) ==
     94           (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED)
     95           ) {
     96       //
     97       // For those reserved memory that have not been tested, simply promote to system memory.
     98       //
     99       gDS->RemoveMemorySpace (
    100             MemorySpaceMap[Index].BaseAddress,
    101             MemorySpaceMap[Index].Length
    102             );
    103 
    104       gDS->AddMemorySpace (
    105             EfiGcdMemoryTypeSystemMemory,
    106             MemorySpaceMap[Index].BaseAddress,
    107             MemorySpaceMap[Index].Length,
    108             MemorySpaceMap[Index].Capabilities &~
    109             (EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED | EFI_MEMORY_RUNTIME)
    110             );
    111 
    112       mTestedSystemMemory += MemorySpaceMap[Index].Length;
    113       mTotalSystemMemory += MemorySpaceMap[Index].Length;
    114     } else if (MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeSystemMemory) {
    115       mTotalSystemMemory += MemorySpaceMap[Index].Length;
    116     }
    117   }
    118 
    119   FreePool (MemorySpaceMap);
    120 
    121   *RequireSoftECCInit = FALSE;
    122   return EFI_SUCCESS;
    123 }
    124 
    125 /**
    126   Perform the memory test.
    127 
    128   This function implements EFI_GENERIC_MEMORY_TEST_PROTOCOL.PerformMemoryTest.
    129   It simply returns EFI_NOT_FOUND.
    130 
    131   @param  This                Protocol instance pointer.
    132   @param  TestedMemorySize    Return the tested extended memory size.
    133   @param  TotalMemorySize     Return the whole system physical memory size, this
    134                               value may be changed if in some case some error
    135                               DIMMs be disabled.
    136   @param  ErrorOut            Any time the memory error occurs, this will be
    137                               TRUE.
    138   @param  IfTestAbort         Indicate if the user press "ESC" to skip the memory
    139                               test.
    140 
    141   @retval EFI_SUCCESS         One block of memory test ok, the block size is hide
    142                               internally.
    143   @retval EFI_NOT_FOUND       Indicate all the non-tested memory blocks have
    144                               already go through.
    145   @retval EFI_DEVICE_ERROR    Mis-compare error, and no agent can handle it
    146 
    147 **/
    148 EFI_STATUS
    149 EFIAPI
    150 GenPerformMemoryTest (
    151   IN EFI_GENERIC_MEMORY_TEST_PROTOCOL          *This,
    152   IN OUT UINT64                                *TestedMemorySize,
    153   OUT UINT64                                   *TotalMemorySize,
    154   OUT BOOLEAN                                  *ErrorOut,
    155   IN BOOLEAN                                   TestAbort
    156   )
    157 {
    158   *ErrorOut         = FALSE;
    159   *TestedMemorySize = mTestedSystemMemory;
    160   *TotalMemorySize  = mTotalSystemMemory;
    161 
    162   return EFI_NOT_FOUND;
    163 
    164 }
    165 
    166 /**
    167   The memory test finished.
    168 
    169   This function implements EFI_GENERIC_MEMORY_TEST_PROTOCOL.Finished.
    170   It simply returns EFI_SUCCESS.
    171 
    172   @param  This                Protocol instance pointer.
    173 
    174   @retval EFI_SUCCESS         Successful free all the generic memory test driver
    175                               allocated resource and notify to platform memory
    176                               test driver that memory test finished.
    177 
    178 **/
    179 EFI_STATUS
    180 EFIAPI
    181 GenMemoryTestFinished (
    182   IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This
    183   )
    184 {
    185   return EFI_SUCCESS;
    186 }
    187 
    188 /**
    189   Provide capability to test compatible range which used by some special
    190   driver required using memory range before BDS perform memory test.
    191 
    192   This function implements EFI_GENERIC_MEMORY_TEST_PROTOCOL.CompatibleRangeTest.
    193   It simply sets the memory range to system memory.
    194 
    195   @param  This                Protocol instance pointer.
    196   @param  StartAddress        The start address of the memory range.
    197   @param  Length              The memory range's length.
    198 
    199   @retval EFI_SUCCESS           The compatible memory range pass the memory test.
    200   @retval EFI_INVALID_PARAMETER The compatible memory range must be below 16M.
    201 
    202 **/
    203 EFI_STATUS
    204 EFIAPI
    205 GenCompatibleRangeTest (
    206   IN EFI_GENERIC_MEMORY_TEST_PROTOCOL          *This,
    207   IN  EFI_PHYSICAL_ADDRESS                     StartAddress,
    208   IN  UINT64                                   Length
    209   )
    210 {
    211   EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor;
    212 
    213   gDS->GetMemorySpaceDescriptor (StartAddress, &Descriptor);
    214 
    215   gDS->RemoveMemorySpace (StartAddress, Length);
    216 
    217   gDS->AddMemorySpace (
    218         EfiGcdMemoryTypeSystemMemory,
    219         StartAddress,
    220         Length,
    221         Descriptor.Capabilities &~(EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | EFI_MEMORY_TESTED | EFI_MEMORY_RUNTIME)
    222         );
    223 
    224   return EFI_SUCCESS;
    225 }
    226