1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
|
/** @file
The generic memory test driver definition
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions
of the BSD License which accompanies this distribution. The
full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef _GENERIC_MEMORY_TEST_H_
#define _GENERIC_MEMORY_TEST_H_
#include <Guid/StatusCodeDataTypeId.h>
#include <Protocol/GenericMemoryTest.h>
#include <Protocol/Cpu.h>
#include <Library/DebugLib.h>
#include <Library/UefiDriverEntryPoint.h>
#include <Library/HobLib.h>
#include <Library/DxeServicesTableLib.h>
#include <Library/ReportStatusCodeLib.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/UefiBootServicesTableLib.h>
//
// Some global define
//
#define GENERIC_CACHELINE_SIZE 0x40
//
// attributes for reserved memory before it is promoted to system memory
//
#define EFI_MEMORY_PRESENT 0x0100000000000000ULL
#define EFI_MEMORY_INITIALIZED 0x0200000000000000ULL
#define EFI_MEMORY_TESTED 0x0400000000000000ULL
//
// The SPARSE_SPAN_SIZE size can not small then the MonoTestSize
//
#define TEST_BLOCK_SIZE 0x2000000
#define QUICK_SPAN_SIZE (TEST_BLOCK_SIZE >> 2)
#define SPARSE_SPAN_SIZE (TEST_BLOCK_SIZE >> 4)
//
// This structure records every nontested memory range parsed through GCD
// service.
//
#define EFI_NONTESTED_MEMORY_RANGE_SIGNATURE SIGNATURE_32 ('N', 'T', 'M', 'E')
typedef struct {
UINTN Signature;
LIST_ENTRY Link;
EFI_PHYSICAL_ADDRESS StartAddress;
UINT64 Length;
UINT64 Capabilities;
BOOLEAN Above4G;
BOOLEAN AlreadyMapped;
} NONTESTED_MEMORY_RANGE;
#define NONTESTED_MEMORY_RANGE_FROM_LINK(link) \
CR ( \
link, \
NONTESTED_MEMORY_RANGE, \
Link, \
EFI_NONTESTED_MEMORY_RANGE_SIGNATURE \
)
//
// This is the memory test driver's structure definition
//
#define EFI_GENERIC_MEMORY_TEST_PRIVATE_SIGNATURE SIGNATURE_32 ('G', 'E', 'M', 'T')
typedef struct {
UINTN Signature;
EFI_HANDLE Handle;
//
// Cpu arch protocol's pointer
//
EFI_CPU_ARCH_PROTOCOL *Cpu;
//
// generic memory test driver's protocol
//
EFI_GENERIC_MEMORY_TEST_PROTOCOL GenericMemoryTest;
//
// memory test covered spans
//
EXTENDMEM_COVERAGE_LEVEL CoverLevel;
UINTN CoverageSpan;
UINT64 BdsBlockSize;
//
// the memory test pattern and size every time R/W/V memory
//
VOID *MonoPattern;
UINTN MonoTestSize;
//
// base memory's size which tested in PEI phase
//
UINT64 BaseMemorySize;
//
// memory range list
//
LIST_ENTRY NonTestedMemRanList;
} GENERIC_MEMORY_TEST_PRIVATE;
#define GENERIC_MEMORY_TEST_PRIVATE_FROM_THIS(a) \
CR ( \
a, \
GENERIC_MEMORY_TEST_PRIVATE, \
GenericMemoryTest, \
EFI_GENERIC_MEMORY_TEST_PRIVATE_SIGNATURE \
)
//
// Function Prototypes
//
/**
Construct the system base memory range through GCD service.
@param[in] Private Point to generic memory test driver's private data.
@retval EFI_SUCCESS Successful construct the base memory range through GCD service.
@retval EFI_OUT_OF_RESOURCE Could not allocate needed resource from base memory.
@retval Others Failed to construct base memory range through GCD service.
**/
EFI_STATUS
ConstructBaseMemoryRange (
IN GENERIC_MEMORY_TEST_PRIVATE *Private
);
/**
Construct the system non-tested memory range through GCD service.
@param[in] Private Point to generic memory test driver's private data.
@retval EFI_SUCCESS Successful construct the non-tested memory range through GCD service.
@retval EFI_OUT_OF_RESOURCE Could not allocate needed resource from base memory.
@retval Others Failed to construct non-tested memory range through GCD service.
**/
EFI_STATUS
ConstructNonTestedMemoryRange (
IN GENERIC_MEMORY_TEST_PRIVATE *Private
);
/**
Perform the address line walking ones test.
@param[in] Private Point to generic memory test driver's private data.
@retval EFI_SUCCESS Successful finished walking ones test.
@retval EFI_OUT_OF_RESOURCE Could not get resource in base memory.
@retval EFI_ACCESS_DENIED Code may can not run here because if walking one test
failed, system may be already halt.
**/
EFI_STATUS
PerformAddressDataLineTest (
IN GENERIC_MEMORY_TEST_PRIVATE *Private
);
/**
Destroy the link list base on the correspond link list type.
@param[in] Private Point to generic memory test driver's private data.
**/
VOID
DestroyLinkList (
IN GENERIC_MEMORY_TEST_PRIVATE *Private
);
/**
Add the extened memory to whole system memory map.
@param[in] Private Point to generic memory test driver's private data.
@retval EFI_SUCCESS Successful add all the extended memory to system memory map.
@retval Others Failed to add the tested extended memory.
**/
EFI_STATUS
UpdateMemoryMap (
IN GENERIC_MEMORY_TEST_PRIVATE *Private
);
/**
Write the memory test pattern into a range of physical memory.
@param[in] Private Point to generic memory test driver's private data.
@param[in] Start The memory range's start address.
@param[in] Size The memory range's size.
@retval EFI_SUCCESS Successful write the test pattern into the non-tested memory.
@retval Others The test pattern may not really write into the physical memory.
**/
EFI_STATUS
WriteMemory (
IN GENERIC_MEMORY_TEST_PRIVATE *Private,
IN EFI_PHYSICAL_ADDRESS Start,
IN UINT64 Size
);
/**
Verify the range of physical memory which covered by memory test pattern.
This function will also do not return any informatin just cause system reset,
because the handle error encount fatal error and disable the bad DIMMs.
@param[in] Private Point to generic memory test driver's private data.
@param[in] Start The memory range's start address.
@param[in] Size The memory range's size.
@retval EFI_SUCCESS Successful verify the range of memory, no errors' location found.
@retval Others The range of memory have errors contained.
**/
EFI_STATUS
VerifyMemory (
IN GENERIC_MEMORY_TEST_PRIVATE *Private,
IN EFI_PHYSICAL_ADDRESS Start,
IN UINT64 Size
);
/**
Test a range of the memory directly .
@param[in] Private Point to generic memory test driver's private data.
@param[in] StartAddress Starting address of the memory range to be tested.
@param[in] Length Length in bytes of the memory range to be tested.
@param[in] Capabilities The bit mask of attributes that the memory range supports.
@retval EFI_SUCCESS Successful test the range of memory.
@retval Others Failed to test the range of memory.
**/
EFI_STATUS
DirectRangeTest (
IN GENERIC_MEMORY_TEST_PRIVATE *Private,
IN EFI_PHYSICAL_ADDRESS StartAddress,
IN UINT64 Length,
IN UINT64 Capabilities
);
/**
Initialize the generic memory test.
@param[in] This The protocol instance pointer.
@param[in] Level The coverage level of the memory test.
@param[out] RequireSoftECCInit Indicate if the memory need software ECC init.
@retval EFI_SUCCESS The generic memory test is initialized correctly.
@retval EFI_NO_MEDIA The system had no memory to be tested.
**/
EFI_STATUS
EFIAPI
InitializeMemoryTest (
IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,
IN EXTENDMEM_COVERAGE_LEVEL Level,
OUT BOOLEAN *RequireSoftECCInit
);
/**
Perform the memory test.
@param[in] This The protocol instance pointer.
@param[out] TestedMemorySize Return the tested extended memory size.
@param[out] TotalMemorySize Return the whole system physical memory size.
The total memory size does not include memory in a slot with a disabled DIMM.
@param[out] ErrorOut TRUE if the memory error occured.
@param[in] IfTestAbort Indicates that the user pressed "ESC" to skip the memory test.
@retval EFI_SUCCESS One block of memory passed the test.
@retval EFI_NOT_FOUND All memory blocks have already been tested.
@retval EFI_DEVICE_ERROR Memory device error occured, and no agent can handle it.
**/
EFI_STATUS
EFIAPI
GenPerformMemoryTest (
IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,
OUT UINT64 *TestedMemorySize,
OUT UINT64 *TotalMemorySize,
OUT BOOLEAN *ErrorOut,
IN BOOLEAN TestAbort
);
/**
Finish the memory test.
@param[in] This The protocol instance pointer.
@retval EFI_SUCCESS Success. All resources used in the memory test are freed.
**/
EFI_STATUS
EFIAPI
GenMemoryTestFinished (
IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This
);
/**
Provides the capability to test the compatible range used by some special drivers.
@param[in] This The protocol instance pointer.
@param[in] StartAddress The start address of the compatible memory range that
must be below 16M.
@param[in] Length The compatible memory range's length.
@retval EFI_SUCCESS The compatible memory range pass the memory test.
@retval EFI_INVALID_PARAMETER The compatible memory range are not below Low 16M.
**/
EFI_STATUS
EFIAPI
GenCompatibleRangeTest (
IN EFI_GENERIC_MEMORY_TEST_PROTOCOL *This,
IN EFI_PHYSICAL_ADDRESS StartAddress,
IN UINT64 Length
);
#endif
|