]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/MemoryTest/BaseMemoryTestPei/BaseMemoryTest.c
Clean up gEfiHotPlugDeviceGuid in ConPlatformDxe.
[mirror_edk2.git] / MdeModulePkg / Universal / MemoryTest / BaseMemoryTestPei / BaseMemoryTest.c
1 /** @file
2 Support of memory test in PEI Phase.
3
4 Copyright (c) 2006 - 2008, Intel Corporation. <BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include "BaseMemoryTest.h"
16
17 PEI_BASE_MEMORY_TEST_PPI mPeiBaseMemoryTestPpi = {
18 BaseMemoryTest
19 };
20
21 EFI_PEI_PPI_DESCRIPTOR PpiListPeiBaseMemoryTest = {
22 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
23 &gPeiBaseMemoryTestPpiGuid,
24 &mPeiBaseMemoryTestPpi
25 };
26
27 /**
28 Entry point of BaseMemoryTestPei PEIM.
29
30 This function is the entry point of BaseMemoryTestPei PEIM.
31 It installs the PEI_BASE_MEMORY_TEST_PPI.
32
33 @param FileHandle Handle of the file being invoked.
34 @param PeiServices Describes the list of possible PEI Services.
35
36 @retval EFI_SUCCESS PEI_BASE_MEMORY_TEST_PPI is successfully installed.
37 @retval Others PEI_BASE_MEMORY_TEST_PPI is not successfully installed.
38
39 **/
40 EFI_STATUS
41 EFIAPI
42 PeiBaseMemoryTestInit (
43 IN EFI_PEI_FILE_HANDLE FileHandle,
44 IN CONST EFI_PEI_SERVICES **PeiServices
45 )
46 {
47 return PeiServicesInstallPpi (&PpiListPeiBaseMemoryTest);
48
49 }
50
51 /**
52 Test base memory.
53
54 @param PeiServices An indirect pointer to the PEI Services Table published by the PEI Foundation.
55 @param This Pointer to this PPI instance.
56 @param BeginAddress Beginning of the memory address to be checked.
57 @param MemoryLength Bytes of memory range to be checked.
58 @param Operation Type of memory check operation to be performed.
59 @param ErrorAddress Pointer to address of the error memory returned.
60
61 @retval EFI_SUCCESS Memory test passed.
62 @retval EFI_DEVICE_ERROR Memory test failed.
63
64 **/
65 EFI_STATUS
66 EFIAPI
67 BaseMemoryTest (
68 IN EFI_PEI_SERVICES **PeiServices,
69 IN PEI_BASE_MEMORY_TEST_PPI *This,
70 IN EFI_PHYSICAL_ADDRESS BeginAddress,
71 IN UINT64 MemoryLength,
72 IN PEI_MEMORY_TEST_OP Operation,
73 OUT EFI_PHYSICAL_ADDRESS *ErrorAddress
74 )
75 {
76 UINT32 TestPattern;
77 EFI_PHYSICAL_ADDRESS TempAddress;
78 UINT32 SpanSize;
79
80 REPORT_STATUS_CODE (EFI_PROGRESS_CODE, PcdGet32 (PcdStatusCodeValueMemoryTestStarted));
81
82 TestPattern = TEST_PATTERN;
83 SpanSize = 0;
84
85 //
86 // Make sure we don't try and test anything above the max physical address range
87 //
88 ASSERT (BeginAddress + MemoryLength < MAX_ADDRESS);
89
90 switch (Operation) {
91 case Extensive:
92 //
93 // Extensive means full and detailed check,
94 // so use small span size to cover the entire test range.
95 //
96 SpanSize = 0x4;
97 break;
98
99 case Sparse:
100 case Quick:
101 //
102 // Sparse and Quick indicates quick test,
103 // so use large span size for sample test.
104 //
105 SpanSize = COVER_SPAN;
106 break;
107
108 case Ignore:
109 //
110 // Ignore means no test.
111 //
112 goto Done;
113 break;
114 }
115 //
116 // Write the test pattern into memory range
117 //
118 TempAddress = BeginAddress;
119 while (TempAddress < BeginAddress + MemoryLength) {
120 (*(UINT32 *) (UINTN) TempAddress) = TestPattern;
121 TempAddress += SpanSize;
122 }
123 //
124 // Read pattern from memory and compare it
125 //
126 TempAddress = BeginAddress;
127 while (TempAddress < BeginAddress + MemoryLength) {
128 if ((*(UINT32 *) (UINTN) TempAddress) != TestPattern) {
129 //
130 // Value read back does not equal to the value written, so error is detected.
131 //
132 *ErrorAddress = TempAddress;
133 REPORT_STATUS_CODE (EFI_ERROR_CODE | EFI_ERROR_UNRECOVERED, PcdGet32 (PcdStatusCodeValueUncorrectableMemoryError));
134
135 return EFI_DEVICE_ERROR;
136 }
137
138 TempAddress += SpanSize;
139 }
140
141 Done:
142 return EFI_SUCCESS;
143 }