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