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