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