]> git.proxmox.com Git - mirror_edk2.git/blame - EdkModulePkg/Universal/GenericMemoryTest/Pei/BaseMemoryTest.c
Clean up the following module msa files, they are edkmodule package ftwlit, Crc32Sect...
[mirror_edk2.git] / EdkModulePkg / Universal / GenericMemoryTest / Pei / BaseMemoryTest.c
CommitLineData
878ddf1f 1/*++\r
2\r
8d8daecb 3Copyright (c) 2006 - 2007, Intel Corporation \r
878ddf1f 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
878ddf1f 23\r
24static PEI_BASE_MEMORY_TEST_PPI mPeiBaseMemoryTestPpi = { BaseMemoryTest };\r
25\r
26static EFI_PEI_PPI_DESCRIPTOR PpiListPeiBaseMemoryTest = {\r
27 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
28 &gPeiBaseMemoryTestPpiGuid,\r
29 &mPeiBaseMemoryTestPpi\r
30};\r
31\r
32EFI_STATUS\r
33EFIAPI\r
34PeiBaseMemoryTestInit (\r
35 IN EFI_FFS_FILE_HEADER *FfsHeader,\r
36 IN EFI_PEI_SERVICES **PeiServices\r
37 )\r
38/*++\r
39Description:\r
40\r
41 Entry point function of BaseMemoryTestInit Peim.\r
42\r
43Arguments:\r
44\r
45 PeiServices - General purpose services available to every PEIM.\r
46 FfsHeader - Ffs header pointer\r
47\r
48Returns:\r
49\r
50 Status - Result of InstallPpi\r
51\r
52--*/ \r
53{\r
54 EFI_STATUS Status;\r
55\r
56 Status = (**PeiServices).InstallPpi (PeiServices, &PpiListPeiBaseMemoryTest);\r
57\r
58 return Status;\r
59}\r
60\r
61EFI_STATUS\r
62EFIAPI\r
63BaseMemoryTest (\r
64 IN EFI_PEI_SERVICES **PeiServices,\r
65 IN PEI_BASE_MEMORY_TEST_PPI *This,\r
66 IN EFI_PHYSICAL_ADDRESS BeginAddress,\r
67 IN UINT64 MemoryLength,\r
68 IN PEI_MEMORY_TEST_OP Operation,\r
69 OUT EFI_PHYSICAL_ADDRESS *ErrorAddress\r
70 )\r
71/*++\r
72Description:\r
73\r
74 Test base memory.\r
75\r
76Arguments:\r
77\r
78 PeiServices - General purpose services available to every PEIM.\r
79 This - Pei memory test PPI pointer.\r
80 BeginAddress - Beginning of the memory address to be checked.\r
81 MemoryLength - Bytes of memory range to be checked.\r
82 Operation - Type of memory check operation to be performed.\r
83 ErrorAddress - Return the address of the error memory address.\r
84 ErrorAddress - Address which has error when checked.\r
85\r
86Returns:\r
87\r
88 Status - Result of InstallPpi\r
89\r
90--*/ \r
91{\r
92 UINT32 TestPattern;\r
878ddf1f 93 EFI_PHYSICAL_ADDRESS TempAddress;\r
94 UINT32 SpanSize;\r
95\r
96 REPORT_STATUS_CODE (\r
97 EFI_PROGRESS_CODE,\r
98 EFI_COMPUTING_UNIT_MEMORY + EFI_CU_MEMORY_PC_TEST\r
99 );\r
100\r
101 TestPattern = TEST_PATTERN;\r
878ddf1f 102 SpanSize = 0;\r
103\r
104 //\r
105 // Make sure we don't try and test anything above the max physical address range\r
106 //\r
8d8daecb 107 ASSERT (BeginAddress + MemoryLength < EFI_MAX_ADDRESS);\r
878ddf1f 108\r
109 switch (Operation) {\r
110 case Extensive:\r
111 SpanSize = 0x4;\r
112 break;\r
113\r
114 case Sparse:\r
115 case Quick:\r
116 SpanSize = COVER_SPAN;\r
117 break;\r
118\r
119 case Ignore:\r
120 goto Done;\r
121 break;\r
122 }\r
123 //\r
124 // Write the test pattern into memory range\r
125 //\r
126 TempAddress = BeginAddress;\r
127 while (TempAddress < BeginAddress + MemoryLength) {\r
128 (*(UINT32 *) (UINTN) TempAddress) = TestPattern;\r
129 TempAddress += SpanSize;\r
130 }\r
131 //\r
132 // Read pattern from memory and compare it\r
133 //\r
134 TempAddress = BeginAddress;\r
135 while (TempAddress < BeginAddress + MemoryLength) {\r
136 if ((*(UINT32 *) (UINTN) TempAddress) != TestPattern) {\r
137 *ErrorAddress = TempAddress;\r
138 REPORT_STATUS_CODE (\r
139 EFI_ERROR_CODE | EFI_ERROR_UNRECOVERED,\r
140 EFI_COMPUTING_UNIT_MEMORY | EFI_CU_MEMORY_EC_UNCORRECTABLE\r
141 );\r
142\r
143 return EFI_DEVICE_ERROR;\r
144 }\r
145\r
146 TempAddress += SpanSize;\r
147 }\r
148\r
149Done:\r
150 return EFI_SUCCESS;\r
151}\r