]> git.proxmox.com Git - mirror_edk2.git/blob - EdkModulePkg/Universal/GenericMemoryTest/Pei/BaseMemoryTest.c
48ed607961de18764a513dd4fdb797cdafd9e55d
[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 EFI_PHYSICAL_ADDRESS TempAddress;
95 UINT32 SpanSize;
96
97 REPORT_STATUS_CODE (
98 EFI_PROGRESS_CODE,
99 EFI_COMPUTING_UNIT_MEMORY + EFI_CU_MEMORY_PC_TEST
100 );
101
102 TestPattern = TEST_PATTERN;
103 SpanSize = 0;
104
105 //
106 // Make sure we don't try and test anything above the max physical address range
107 //
108 ASSERT_EFI_ERROR (BeginAddress + MemoryLength < EFI_MAX_ADDRESS);
109
110 switch (Operation) {
111 case Extensive:
112 SpanSize = 0x4;
113 break;
114
115 case Sparse:
116 case Quick:
117 SpanSize = COVER_SPAN;
118 break;
119
120 case Ignore:
121 goto Done;
122 break;
123 }
124 //
125 // Write the test pattern into memory range
126 //
127 TempAddress = BeginAddress;
128 while (TempAddress < BeginAddress + MemoryLength) {
129 (*(UINT32 *) (UINTN) TempAddress) = TestPattern;
130 TempAddress += SpanSize;
131 }
132 //
133 // Read pattern from memory and compare it
134 //
135 TempAddress = BeginAddress;
136 while (TempAddress < BeginAddress + MemoryLength) {
137 if ((*(UINT32 *) (UINTN) TempAddress) != TestPattern) {
138 *ErrorAddress = TempAddress;
139 REPORT_STATUS_CODE (
140 EFI_ERROR_CODE | EFI_ERROR_UNRECOVERED,
141 EFI_COMPUTING_UNIT_MEMORY | EFI_CU_MEMORY_EC_UNCORRECTABLE
142 );
143
144 return EFI_DEVICE_ERROR;
145 }
146
147 TempAddress += SpanSize;
148 }
149
150 Done:
151 return EFI_SUCCESS;
152 }