]> git.proxmox.com Git - mirror_edk2.git/blob - EdkModulePkg/Universal/GenericMemoryTest/Pei/BaseMemoryTest.c
Convert backslashes to forward slashes in many build files. This is necessary for...
[mirror_edk2.git] / EdkModulePkg / Universal / GenericMemoryTest / Pei / BaseMemoryTest.c
1 /*++
2
3 Copyright (c) 2006, 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/ReportStatusCodeLib.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 EFI_STATUS Status;
56
57 Status = (**PeiServices).InstallPpi (PeiServices, &PpiListPeiBaseMemoryTest);
58
59 return Status;
60 }
61
62 EFI_STATUS
63 EFIAPI
64 BaseMemoryTest (
65 IN EFI_PEI_SERVICES **PeiServices,
66 IN PEI_BASE_MEMORY_TEST_PPI *This,
67 IN EFI_PHYSICAL_ADDRESS BeginAddress,
68 IN UINT64 MemoryLength,
69 IN PEI_MEMORY_TEST_OP Operation,
70 OUT EFI_PHYSICAL_ADDRESS *ErrorAddress
71 )
72 /*++
73 Description:
74
75 Test base memory.
76
77 Arguments:
78
79 PeiServices - General purpose services available to every PEIM.
80 This - Pei memory test PPI pointer.
81 BeginAddress - Beginning of the memory address to be checked.
82 MemoryLength - Bytes of memory range to be checked.
83 Operation - Type of memory check operation to be performed.
84 ErrorAddress - Return the address of the error memory address.
85 ErrorAddress - Address which has error when checked.
86
87 Returns:
88
89 Status - Result of InstallPpi
90
91 --*/
92 {
93 UINT32 TestPattern;
94 UINT32 TestMask;
95 EFI_PHYSICAL_ADDRESS TempAddress;
96 UINT32 SpanSize;
97
98 REPORT_STATUS_CODE (
99 EFI_PROGRESS_CODE,
100 EFI_COMPUTING_UNIT_MEMORY + EFI_CU_MEMORY_PC_TEST
101 );
102
103 TestPattern = TEST_PATTERN;
104 TestMask = 0;
105 SpanSize = 0;
106
107 //
108 // Make sure we don't try and test anything above the max physical address range
109 //
110 ASSERT_EFI_ERROR (BeginAddress + MemoryLength < EFI_MAX_ADDRESS);
111
112 switch (Operation) {
113 case Extensive:
114 SpanSize = 0x4;
115 break;
116
117 case Sparse:
118 case Quick:
119 SpanSize = COVER_SPAN;
120 break;
121
122 case Ignore:
123 goto Done;
124 break;
125 }
126 //
127 // Write the test pattern into memory range
128 //
129 TempAddress = BeginAddress;
130 while (TempAddress < BeginAddress + MemoryLength) {
131 (*(UINT32 *) (UINTN) TempAddress) = TestPattern;
132 TempAddress += SpanSize;
133 }
134 //
135 // Read pattern from memory and compare it
136 //
137 TempAddress = BeginAddress;
138 while (TempAddress < BeginAddress + MemoryLength) {
139 if ((*(UINT32 *) (UINTN) TempAddress) != TestPattern) {
140 *ErrorAddress = TempAddress;
141 REPORT_STATUS_CODE (
142 EFI_ERROR_CODE | EFI_ERROR_UNRECOVERED,
143 EFI_COMPUTING_UNIT_MEMORY | EFI_CU_MEMORY_EC_UNCORRECTABLE
144 );
145
146 return EFI_DEVICE_ERROR;
147 }
148
149 TempAddress += SpanSize;
150 }
151
152 Done:
153 return EFI_SUCCESS;
154 }