]>
Commit | Line | Data |
---|---|---|
79021021 | 1 | /** @file\r |
37887186 | 2 | Support of memory test in PEI Phase.\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 |
c64223e3 | 15 | #include "BaseMemoryTest.h"\r |
05177bef | 16 | \r |
37887186 | 17 | PEI_BASE_MEMORY_TEST_PPI mPeiBaseMemoryTestPpi = {\r |
18 | BaseMemoryTest\r | |
19 | };\r | |
05177bef | 20 | \r |
fe1e36e5 | 21 | EFI_PEI_PPI_DESCRIPTOR PpiListPeiBaseMemoryTest = {\r |
05177bef | 22 | (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r |
23 | &gPeiBaseMemoryTestPpiGuid,\r | |
24 | &mPeiBaseMemoryTestPpi\r | |
25 | };\r | |
26 | \r | |
37887186 | 27 | /**\r |
28 | Entry point of BaseMemoryTestPei PEIM.\r | |
29 | \r | |
30 | This function is the entry point of BaseMemoryTestPei PEIM.\r | |
31 | It installs the PEI_BASE_MEMORY_TEST_PPI.\r | |
32 | \r | |
a55caa53 LG |
33 | @param FileHandle Handle of the file being invoked.\r |
34 | @param PeiServices Describes the list of possible PEI Services.\r | |
37887186 | 35 | \r |
36 | @retval EFI_SUCCESS PEI_BASE_MEMORY_TEST_PPI is successfully installed.\r | |
37 | @retval Others PEI_BASE_MEMORY_TEST_PPI is not successfully installed.\r | |
38 | \r | |
39 | **/ \r | |
05177bef | 40 | EFI_STATUS\r |
41 | EFIAPI\r | |
42 | PeiBaseMemoryTestInit (\r | |
a55caa53 LG |
43 | IN EFI_PEI_FILE_HANDLE FileHandle,\r |
44 | IN CONST EFI_PEI_SERVICES **PeiServices\r | |
05177bef | 45 | )\r |
05177bef | 46 | {\r |
0c2b5da8 | 47 | return PeiServicesInstallPpi (&PpiListPeiBaseMemoryTest);\r |
37887186 | 48 | \r |
05177bef | 49 | }\r |
50 | \r | |
37887186 | 51 | /**\r |
52 | Test base memory.\r | |
53 | \r | |
54 | @param PeiServices An indirect pointer to the PEI Services Table published by the PEI Foundation.\r | |
55 | @param This Pointer to this PPI instance.\r | |
56 | @param BeginAddress Beginning of the memory address to be checked.\r | |
57 | @param MemoryLength Bytes of memory range to be checked.\r | |
58 | @param Operation Type of memory check operation to be performed.\r | |
59 | @param ErrorAddress Pointer to address of the error memory returned.\r | |
60 | \r | |
61 | @retval EFI_SUCCESS Memory test passed.\r | |
62 | @retval EFI_DEVICE_ERROR Memory test failed.\r | |
63 | \r | |
64 | **/ \r | |
05177bef | 65 | EFI_STATUS\r |
66 | EFIAPI\r | |
67 | BaseMemoryTest (\r | |
68 | IN EFI_PEI_SERVICES **PeiServices,\r | |
37887186 | 69 | IN PEI_BASE_MEMORY_TEST_PPI *This,\r |
05177bef | 70 | IN EFI_PHYSICAL_ADDRESS BeginAddress,\r |
71 | IN UINT64 MemoryLength,\r | |
72 | IN PEI_MEMORY_TEST_OP Operation,\r | |
73 | OUT EFI_PHYSICAL_ADDRESS *ErrorAddress\r | |
74 | )\r | |
05177bef | 75 | {\r |
76 | UINT32 TestPattern;\r | |
77 | EFI_PHYSICAL_ADDRESS TempAddress;\r | |
78 | UINT32 SpanSize;\r | |
79 | \r | |
80 | REPORT_STATUS_CODE (EFI_PROGRESS_CODE, PcdGet32 (PcdStatusCodeValueMemoryTestStarted));\r | |
81 | \r | |
82 | TestPattern = TEST_PATTERN;\r | |
83 | SpanSize = 0;\r | |
84 | \r | |
85 | //\r | |
86 | // Make sure we don't try and test anything above the max physical address range\r | |
87 | //\r | |
f3f2e05d | 88 | ASSERT (BeginAddress + MemoryLength < MAX_ADDRESS);\r |
05177bef | 89 | \r |
90 | switch (Operation) {\r | |
91 | case Extensive:\r | |
37887186 | 92 | //\r |
93 | // Extensive means full and detailed check,\r | |
94 | // so use small span size to cover the entire test range.\r | |
95 | //\r | |
05177bef | 96 | SpanSize = 0x4;\r |
97 | break;\r | |
98 | \r | |
99 | case Sparse:\r | |
100 | case Quick:\r | |
37887186 | 101 | //\r |
102 | // Sparse and Quick indicates quick test,\r | |
103 | // so use large span size for sample test.\r | |
104 | //\r | |
05177bef | 105 | SpanSize = COVER_SPAN;\r |
106 | break;\r | |
107 | \r | |
108 | case Ignore:\r | |
37887186 | 109 | //\r |
110 | // Ignore means no test.\r | |
111 | //\r | |
05177bef | 112 | goto Done;\r |
113 | break;\r | |
114 | }\r | |
115 | //\r | |
116 | // Write the test pattern into memory range\r | |
117 | //\r | |
118 | TempAddress = BeginAddress;\r | |
119 | while (TempAddress < BeginAddress + MemoryLength) {\r | |
120 | (*(UINT32 *) (UINTN) TempAddress) = TestPattern;\r | |
121 | TempAddress += SpanSize;\r | |
122 | }\r | |
123 | //\r | |
124 | // Read pattern from memory and compare it\r | |
125 | //\r | |
126 | TempAddress = BeginAddress;\r | |
127 | while (TempAddress < BeginAddress + MemoryLength) {\r | |
128 | if ((*(UINT32 *) (UINTN) TempAddress) != TestPattern) {\r | |
37887186 | 129 | //\r |
130 | // Value read back does not equal to the value written, so error is detected.\r | |
131 | //\r | |
05177bef | 132 | *ErrorAddress = TempAddress;\r |
133 | REPORT_STATUS_CODE (EFI_ERROR_CODE | EFI_ERROR_UNRECOVERED, PcdGet32 (PcdStatusCodeValueUncorrectableMemoryError));\r | |
134 | \r | |
135 | return EFI_DEVICE_ERROR;\r | |
136 | }\r | |
137 | \r | |
138 | TempAddress += SpanSize;\r | |
139 | }\r | |
140 | \r | |
141 | Done:\r | |
142 | return EFI_SUCCESS;\r | |
143 | }\r |