]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/MemoryTest/BaseMemoryTestPei/BaseMemoryTest.c
a0179be4de7b1b14407e00885f7ff783a2172f41
[mirror_edk2.git] / MdeModulePkg / Universal / MemoryTest / BaseMemoryTestPei / BaseMemoryTest.c
1 /** @file
2 The PEI memory test support
3
4 Copyright (c) 2006 - 2008, Intel Corporation. <BR>
5 All rights reserved. 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 #include <BaseMemoryTest.h>
16 #include <Library/PeiServicesLib.h>
17
18 PEI_BASE_MEMORY_TEST_PPI mPeiBaseMemoryTestPpi = { BaseMemoryTest };
19
20 EFI_PEI_PPI_DESCRIPTOR PpiListPeiBaseMemoryTest = {
21 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
22 &gPeiBaseMemoryTestPpiGuid,
23 &mPeiBaseMemoryTestPpi
24 };
25
26 EFI_STATUS
27 EFIAPI
28 PeiBaseMemoryTestInit (
29 IN EFI_FFS_FILE_HEADER *FfsHeader,
30 IN EFI_PEI_SERVICES **PeiServices
31 )
32 /*++
33 Description:
34
35 Entry point function of BaseMemoryTestInit Peim.
36
37 Arguments:
38
39 PeiServices - General purpose services available to every PEIM.
40 FfsHeader - Ffs header pointer
41
42 Returns:
43
44 Status - Result of InstallPpi
45
46 --*/
47 {
48
49 return PeiServicesInstallPpi (&PpiListPeiBaseMemoryTest);
50
51 }
52
53 EFI_STATUS
54 EFIAPI
55 BaseMemoryTest (
56 IN EFI_PEI_SERVICES **PeiServices,
57 IN PEI_BASE_MEMORY_TEST_PPI *This,
58 IN EFI_PHYSICAL_ADDRESS BeginAddress,
59 IN UINT64 MemoryLength,
60 IN PEI_MEMORY_TEST_OP Operation,
61 OUT EFI_PHYSICAL_ADDRESS *ErrorAddress
62 )
63 /*++
64 Description:
65
66 Test base memory.
67
68 Arguments:
69
70 PeiServices - General purpose services available to every PEIM.
71 This - Pei memory test PPI pointer.
72 BeginAddress - Beginning of the memory address to be checked.
73 MemoryLength - Bytes of memory range to be checked.
74 Operation - Type of memory check operation to be performed.
75 ErrorAddress - Return the address of the error memory address.
76 ErrorAddress - Address which has error when checked.
77
78 Returns:
79
80 Status - Result of InstallPpi
81
82 --*/
83 {
84 UINT32 TestPattern;
85 EFI_PHYSICAL_ADDRESS TempAddress;
86 UINT32 SpanSize;
87
88 REPORT_STATUS_CODE (EFI_PROGRESS_CODE, PcdGet32 (PcdStatusCodeValueMemoryTestStarted));
89
90 TestPattern = TEST_PATTERN;
91 SpanSize = 0;
92
93 //
94 // Make sure we don't try and test anything above the max physical address range
95 //
96 ASSERT (BeginAddress + MemoryLength < EFI_MAX_ADDRESS);
97
98 switch (Operation) {
99 case Extensive:
100 SpanSize = 0x4;
101 break;
102
103 case Sparse:
104 case Quick:
105 SpanSize = COVER_SPAN;
106 break;
107
108 case Ignore:
109 goto Done;
110 break;
111 }
112 //
113 // Write the test pattern into memory range
114 //
115 TempAddress = BeginAddress;
116 while (TempAddress < BeginAddress + MemoryLength) {
117 (*(UINT32 *) (UINTN) TempAddress) = TestPattern;
118 TempAddress += SpanSize;
119 }
120 //
121 // Read pattern from memory and compare it
122 //
123 TempAddress = BeginAddress;
124 while (TempAddress < BeginAddress + MemoryLength) {
125 if ((*(UINT32 *) (UINTN) TempAddress) != TestPattern) {
126 *ErrorAddress = TempAddress;
127 REPORT_STATUS_CODE (EFI_ERROR_CODE | EFI_ERROR_UNRECOVERED, PcdGet32 (PcdStatusCodeValueUncorrectableMemoryError));
128
129 return EFI_DEVICE_ERROR;
130 }
131
132 TempAddress += SpanSize;
133 }
134
135 Done:
136 return EFI_SUCCESS;
137 }