]> git.proxmox.com Git - mirror_edk2.git/blob - EdkModulePkg/Universal/GenericMemoryTest/Pei/BaseMemoryTest.c
Clean up the following module msa files, they are edkmodule package ftwlit, Crc32Sect...
[mirror_edk2.git] / EdkModulePkg / Universal / GenericMemoryTest / Pei / 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
24 static PEI_BASE_MEMORY_TEST_PPI mPeiBaseMemoryTestPpi = { BaseMemoryTest };
25
26 static EFI_PEI_PPI_DESCRIPTOR PpiListPeiBaseMemoryTest = {
27 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
28 &gPeiBaseMemoryTestPpiGuid,
29 &mPeiBaseMemoryTestPpi
30 };
31
32 EFI_STATUS
33 EFIAPI
34 PeiBaseMemoryTestInit (
35 IN EFI_FFS_FILE_HEADER *FfsHeader,
36 IN EFI_PEI_SERVICES **PeiServices
37 )
38 /*++
39 Description:
40
41 Entry point function of BaseMemoryTestInit Peim.
42
43 Arguments:
44
45 PeiServices - General purpose services available to every PEIM.
46 FfsHeader - Ffs header pointer
47
48 Returns:
49
50 Status - Result of InstallPpi
51
52 --*/
53 {
54 EFI_STATUS Status;
55
56 Status = (**PeiServices).InstallPpi (PeiServices, &PpiListPeiBaseMemoryTest);
57
58 return Status;
59 }
60
61 EFI_STATUS
62 EFIAPI
63 BaseMemoryTest (
64 IN EFI_PEI_SERVICES **PeiServices,
65 IN PEI_BASE_MEMORY_TEST_PPI *This,
66 IN EFI_PHYSICAL_ADDRESS BeginAddress,
67 IN UINT64 MemoryLength,
68 IN PEI_MEMORY_TEST_OP Operation,
69 OUT EFI_PHYSICAL_ADDRESS *ErrorAddress
70 )
71 /*++
72 Description:
73
74 Test base memory.
75
76 Arguments:
77
78 PeiServices - General purpose services available to every PEIM.
79 This - Pei memory test PPI pointer.
80 BeginAddress - Beginning of the memory address to be checked.
81 MemoryLength - Bytes of memory range to be checked.
82 Operation - Type of memory check operation to be performed.
83 ErrorAddress - Return the address of the error memory address.
84 ErrorAddress - Address which has error when checked.
85
86 Returns:
87
88 Status - Result of InstallPpi
89
90 --*/
91 {
92 UINT32 TestPattern;
93 EFI_PHYSICAL_ADDRESS TempAddress;
94 UINT32 SpanSize;
95
96 REPORT_STATUS_CODE (
97 EFI_PROGRESS_CODE,
98 EFI_COMPUTING_UNIT_MEMORY + EFI_CU_MEMORY_PC_TEST
99 );
100
101 TestPattern = TEST_PATTERN;
102 SpanSize = 0;
103
104 //
105 // Make sure we don't try and test anything above the max physical address range
106 //
107 ASSERT (BeginAddress + MemoryLength < EFI_MAX_ADDRESS);
108
109 switch (Operation) {
110 case Extensive:
111 SpanSize = 0x4;
112 break;
113
114 case Sparse:
115 case Quick:
116 SpanSize = COVER_SPAN;
117 break;
118
119 case Ignore:
120 goto Done;
121 break;
122 }
123 //
124 // Write the test pattern into memory range
125 //
126 TempAddress = BeginAddress;
127 while (TempAddress < BeginAddress + MemoryLength) {
128 (*(UINT32 *) (UINTN) TempAddress) = TestPattern;
129 TempAddress += SpanSize;
130 }
131 //
132 // Read pattern from memory and compare it
133 //
134 TempAddress = BeginAddress;
135 while (TempAddress < BeginAddress + MemoryLength) {
136 if ((*(UINT32 *) (UINTN) TempAddress) != TestPattern) {
137 *ErrorAddress = TempAddress;
138 REPORT_STATUS_CODE (
139 EFI_ERROR_CODE | EFI_ERROR_UNRECOVERED,
140 EFI_COMPUTING_UNIT_MEMORY | EFI_CU_MEMORY_EC_UNCORRECTABLE
141 );
142
143 return EFI_DEVICE_ERROR;
144 }
145
146 TempAddress += SpanSize;
147 }
148
149 Done:
150 return EFI_SUCCESS;
151 }