ce2f5557 |
1 | /*++\r |
2 | \r |
3 | Copyright (c) 2006 - 2007, Intel Corporation \r |
4 | All rights reserved. This program and the accompanying materials \r |
5 | are licensed and made available under the terms and conditions of the BSD License \r |
6 | which accompanies this distribution. The full text of the license may be found at \r |
7 | http://opensource.org/licenses/bsd-license.php \r |
8 | \r |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r |
11 | \r |
12 | Module Name:\r |
13 | \r |
14 | BaseMemoryTest.c\r |
15 | \r |
16 | Abstract:\r |
17 | \r |
18 | The PEI memory test support\r |
19 | \r |
20 | --*/\r |
21 | \r |
22 | //\r |
23 | // The package level header files this module uses\r |
24 | //\r |
25 | #include <PiPei.h>\r |
26 | #include <FrameworkPei.h>\r |
27 | //\r |
28 | // The protocols, PPI and GUID defintions for this module\r |
29 | //\r |
30 | #include <Ppi/BaseMemoryTest.h>\r |
31 | //\r |
32 | // The Library classes this module consumes\r |
33 | //\r |
34 | #include <Library/DebugLib.h>\r |
35 | #include <Library/PeimEntryPoint.h>\r |
36 | #include <Library/ReportStatusCodeLib.h>\r |
37 | \r |
38 | #include <BaseMemoryTest.h>\r |
39 | \r |
40 | static PEI_BASE_MEMORY_TEST_PPI mPeiBaseMemoryTestPpi = { BaseMemoryTest };\r |
41 | \r |
42 | static EFI_PEI_PPI_DESCRIPTOR PpiListPeiBaseMemoryTest = {\r |
43 | (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r |
44 | &gPeiBaseMemoryTestPpiGuid,\r |
45 | &mPeiBaseMemoryTestPpi\r |
46 | };\r |
47 | \r |
48 | EFI_STATUS\r |
49 | EFIAPI\r |
50 | PeiBaseMemoryTestInit (\r |
51 | IN EFI_FFS_FILE_HEADER *FfsHeader,\r |
52 | IN EFI_PEI_SERVICES **PeiServices\r |
53 | )\r |
54 | /*++\r |
55 | Description:\r |
56 | \r |
57 | Entry point function of BaseMemoryTestInit Peim.\r |
58 | \r |
59 | Arguments:\r |
60 | \r |
61 | PeiServices - General purpose services available to every PEIM.\r |
62 | FfsHeader - Ffs header pointer\r |
63 | \r |
64 | Returns:\r |
65 | \r |
66 | Status - Result of InstallPpi\r |
67 | \r |
68 | --*/ \r |
69 | {\r |
70 | EFI_STATUS Status;\r |
71 | \r |
72 | Status = (**PeiServices).InstallPpi (PeiServices, &PpiListPeiBaseMemoryTest);\r |
73 | \r |
74 | return Status;\r |
75 | }\r |
76 | \r |
77 | EFI_STATUS\r |
78 | EFIAPI\r |
79 | BaseMemoryTest (\r |
80 | IN EFI_PEI_SERVICES **PeiServices,\r |
81 | IN PEI_BASE_MEMORY_TEST_PPI *This,\r |
82 | IN EFI_PHYSICAL_ADDRESS BeginAddress,\r |
83 | IN UINT64 MemoryLength,\r |
84 | IN PEI_MEMORY_TEST_OP Operation,\r |
85 | OUT EFI_PHYSICAL_ADDRESS *ErrorAddress\r |
86 | )\r |
87 | /*++\r |
88 | Description:\r |
89 | \r |
90 | Test base memory.\r |
91 | \r |
92 | Arguments:\r |
93 | \r |
94 | PeiServices - General purpose services available to every PEIM.\r |
95 | This - Pei memory test PPI pointer.\r |
96 | BeginAddress - Beginning of the memory address to be checked.\r |
97 | MemoryLength - Bytes of memory range to be checked.\r |
98 | Operation - Type of memory check operation to be performed.\r |
99 | ErrorAddress - Return the address of the error memory address.\r |
100 | ErrorAddress - Address which has error when checked.\r |
101 | \r |
102 | Returns:\r |
103 | \r |
104 | Status - Result of InstallPpi\r |
105 | \r |
106 | --*/ \r |
107 | {\r |
108 | UINT32 TestPattern;\r |
109 | EFI_PHYSICAL_ADDRESS TempAddress;\r |
110 | UINT32 SpanSize;\r |
111 | \r |
112 | REPORT_STATUS_CODE (\r |
113 | EFI_PROGRESS_CODE,\r |
114 | EFI_COMPUTING_UNIT_MEMORY + EFI_CU_MEMORY_PC_TEST\r |
115 | );\r |
116 | \r |
117 | TestPattern = TEST_PATTERN;\r |
118 | SpanSize = 0;\r |
119 | \r |
120 | //\r |
121 | // Make sure we don't try and test anything above the max physical address range\r |
122 | //\r |
123 | ASSERT (BeginAddress + MemoryLength < EFI_MAX_ADDRESS);\r |
124 | \r |
125 | switch (Operation) {\r |
126 | case Extensive:\r |
127 | SpanSize = 0x4;\r |
128 | break;\r |
129 | \r |
130 | case Sparse:\r |
131 | case Quick:\r |
132 | SpanSize = COVER_SPAN;\r |
133 | break;\r |
134 | \r |
135 | case Ignore:\r |
136 | goto Done;\r |
137 | break;\r |
138 | }\r |
139 | //\r |
140 | // Write the test pattern into memory range\r |
141 | //\r |
142 | TempAddress = BeginAddress;\r |
143 | while (TempAddress < BeginAddress + MemoryLength) {\r |
144 | (*(UINT32 *) (UINTN) TempAddress) = TestPattern;\r |
145 | TempAddress += SpanSize;\r |
146 | }\r |
147 | //\r |
148 | // Read pattern from memory and compare it\r |
149 | //\r |
150 | TempAddress = BeginAddress;\r |
151 | while (TempAddress < BeginAddress + MemoryLength) {\r |
152 | if ((*(UINT32 *) (UINTN) TempAddress) != TestPattern) {\r |
153 | *ErrorAddress = TempAddress;\r |
154 | REPORT_STATUS_CODE (\r |
155 | EFI_ERROR_CODE | EFI_ERROR_UNRECOVERED,\r |
156 | EFI_COMPUTING_UNIT_MEMORY | EFI_CU_MEMORY_EC_UNCORRECTABLE\r |
157 | );\r |
158 | \r |
159 | return EFI_DEVICE_ERROR;\r |
160 | }\r |
161 | \r |
162 | TempAddress += SpanSize;\r |
163 | }\r |
164 | \r |
165 | Done:\r |
166 | return EFI_SUCCESS;\r |
167 | }\r |