]>
Commit | Line | Data |
---|---|---|
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 | |
ce2f5557 | 22 | #include <BaseMemoryTest.h>\r |
23 | \r | |
24 | static PEI_BASE_MEMORY_TEST_PPI mPeiBaseMemoryTestPpi = { BaseMemoryTest };\r | |
25 | \r | |
26 | static 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 | |
32 | EFI_STATUS\r | |
33 | EFIAPI\r | |
34 | PeiBaseMemoryTestInit (\r | |
35 | IN EFI_FFS_FILE_HEADER *FfsHeader,\r | |
36 | IN EFI_PEI_SERVICES **PeiServices\r | |
37 | )\r | |
38 | /*++\r | |
39 | Description:\r | |
40 | \r | |
41 | Entry point function of BaseMemoryTestInit Peim.\r | |
42 | \r | |
43 | Arguments:\r | |
44 | \r | |
45 | PeiServices - General purpose services available to every PEIM.\r | |
46 | FfsHeader - Ffs header pointer\r | |
47 | \r | |
48 | Returns:\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 | |
61 | EFI_STATUS\r | |
62 | EFIAPI\r | |
63 | BaseMemoryTest (\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 | |
72 | Description:\r | |
73 | \r | |
74 | Test base memory.\r | |
75 | \r | |
76 | Arguments:\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 | |
86 | Returns:\r | |
87 | \r | |
88 | Status - Result of InstallPpi\r | |
89 | \r | |
90 | --*/ \r | |
91 | {\r | |
92 | UINT32 TestPattern;\r | |
93 | EFI_PHYSICAL_ADDRESS TempAddress;\r | |
94 | UINT32 SpanSize;\r | |
95 | \r | |
ba237732 | 96 | REPORT_STATUS_CODE (EFI_PROGRESS_CODE, PcdGet32 (PcdStatusCodeValueMemoryTestStarted));\r |
ce2f5557 | 97 | \r |
98 | TestPattern = TEST_PATTERN;\r | |
99 | SpanSize = 0;\r | |
100 | \r | |
101 | //\r | |
102 | // Make sure we don't try and test anything above the max physical address range\r | |
103 | //\r | |
104 | ASSERT (BeginAddress + MemoryLength < EFI_MAX_ADDRESS);\r | |
105 | \r | |
106 | switch (Operation) {\r | |
107 | case Extensive:\r | |
108 | SpanSize = 0x4;\r | |
109 | break;\r | |
110 | \r | |
111 | case Sparse:\r | |
112 | case Quick:\r | |
113 | SpanSize = COVER_SPAN;\r | |
114 | break;\r | |
115 | \r | |
116 | case Ignore:\r | |
117 | goto Done;\r | |
118 | break;\r | |
119 | }\r | |
120 | //\r | |
121 | // Write the test pattern into memory range\r | |
122 | //\r | |
123 | TempAddress = BeginAddress;\r | |
124 | while (TempAddress < BeginAddress + MemoryLength) {\r | |
125 | (*(UINT32 *) (UINTN) TempAddress) = TestPattern;\r | |
126 | TempAddress += SpanSize;\r | |
127 | }\r | |
128 | //\r | |
129 | // Read pattern from memory and compare it\r | |
130 | //\r | |
131 | TempAddress = BeginAddress;\r | |
132 | while (TempAddress < BeginAddress + MemoryLength) {\r | |
133 | if ((*(UINT32 *) (UINTN) TempAddress) != TestPattern) {\r | |
134 | *ErrorAddress = TempAddress;\r | |
ba237732 | 135 | REPORT_STATUS_CODE (EFI_ERROR_CODE | EFI_ERROR_UNRECOVERED, PcdGet32 (PcdStatusCodeValueUncorrectableMemoryError));\r |
ce2f5557 | 136 | \r |
137 | return EFI_DEVICE_ERROR;\r | |
138 | }\r | |
139 | \r | |
140 | TempAddress += SpanSize;\r | |
141 | }\r | |
142 | \r | |
143 | Done:\r | |
144 | return EFI_SUCCESS;\r | |
145 | }\r |