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
|
/** @file
Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef _MTRR_SUPPORT_H_
#define _MTRR_SUPPORT_H_
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <time.h>
#include <Uefi.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/UnitTestLib.h>
#include <Library/MtrrLib.h>
#include <Library/UnitTestHostBaseLib.h>
#include <Register/ArchitecturalMsr.h>
#include <Register/Cpuid.h>
#include <Register/Msr.h>
#define UNIT_TEST_APP_NAME "MtrrLib Unit Tests"
#define UNIT_TEST_APP_VERSION "1.0"
#define SCRATCH_BUFFER_SIZE SIZE_16KB
typedef struct {
UINT8 PhysicalAddressBits;
BOOLEAN MtrrSupported;
BOOLEAN FixedMtrrSupported;
MTRR_MEMORY_CACHE_TYPE DefaultCacheType;
UINT32 VariableMtrrCount;
} MTRR_LIB_SYSTEM_PARAMETER;
extern UINT32 mFixedMtrrsIndex[];
extern BOOLEAN mRandomInput;
/**
Initialize the MTRR registers.
@param SystemParameter System parameter that controls the MTRR registers initialization.
**/
UNIT_TEST_STATUS
EFIAPI
InitializeMtrrRegs (
IN MTRR_LIB_SYSTEM_PARAMETER *SystemParameter
);
/**
Initialize the MTRR registers.
@param Context System parameter that controls the MTRR registers initialization.
**/
UNIT_TEST_STATUS
EFIAPI
InitializeSystem (
IN UNIT_TEST_CONTEXT Context
);
/**
Return a random memory cache type.
**/
MTRR_MEMORY_CACHE_TYPE
GenerateRandomCacheType (
VOID
);
/**
Generate random MTRRs.
@param PhysicalAddressBits Physical address bits.
@param RawMemoryRanges Return the randomly generated MTRRs.
@param UcCount Count of Uncacheable MTRRs.
@param WtCount Count of Write Through MTRRs.
@param WbCount Count of Write Back MTRRs.
@param WpCount Count of Write Protected MTRRs.
@param WcCount Count of Write Combining MTRRs.
**/
VOID
GenerateValidAndConfigurableMtrrPairs (
IN UINT32 PhysicalAddressBits,
IN OUT MTRR_MEMORY_RANGE *RawMemoryRanges,
IN UINT32 UcCount,
IN UINT32 WtCount,
IN UINT32 WbCount,
IN UINT32 WpCount,
IN UINT32 WcCount
);
/**
Convert the MTRR BASE/MASK array to memory ranges.
@param DefaultType Default memory type.
@param PhysicalAddressBits Physical address bits.
@param RawMemoryRanges Raw memory ranges.
@param RawMemoryRangeCount Count of raw memory ranges.
@param MemoryRanges Memory ranges.
@param MemoryRangeCount Count of memory ranges.
**/
VOID
GetEffectiveMemoryRanges (
IN MTRR_MEMORY_CACHE_TYPE DefaultType,
IN UINT32 PhysicalAddressBits,
IN MTRR_MEMORY_RANGE *RawMemoryRanges,
IN UINT32 RawMemoryRangeCount,
OUT MTRR_MEMORY_RANGE *MemoryRanges,
OUT UINTN *MemoryRangeCount
);
/**
Generate random MTRR BASE/MASK for a specified type.
@param PhysicalAddressBits Physical address bits.
@param CacheType Cache type.
@param MtrrPair Return the random MTRR.
@param MtrrMemoryRange Return the random memory range.
**/
VOID
GenerateRandomMtrrPair (
IN UINT32 PhysicalAddressBits,
IN MTRR_MEMORY_CACHE_TYPE CacheType,
OUT MTRR_VARIABLE_SETTING *MtrrPair, OPTIONAL
OUT MTRR_MEMORY_RANGE *MtrrMemoryRange OPTIONAL
);
/**
Collect the test result.
@param DefaultType Default memory type.
@param PhysicalAddressBits Physical address bits.
@param VariableMtrrCount Count of variable MTRRs.
@param Mtrrs MTRR settings to collect from.
@param Ranges Return the memory ranges.
@param RangeCount Return the count of memory ranges.
@param MtrrCount Return the count of variable MTRRs being used.
**/
VOID
CollectTestResult (
IN MTRR_MEMORY_CACHE_TYPE DefaultType,
IN UINT32 PhysicalAddressBits,
IN UINT32 VariableMtrrCount,
IN MTRR_SETTINGS *Mtrrs,
OUT MTRR_MEMORY_RANGE *Ranges,
IN OUT UINTN *RangeCount,
OUT UINT32 *MtrrCount
);
/**
Return a 64bit random number.
@param Start Start of the random number range.
@param Limit Limit of the random number range.
@return 64bit random number
**/
UINT64
Random64 (
UINT64 Start,
UINT64 Limit
);
/**
Return a 32bit random number.
@param Start Start of the random number range.
@param Limit Limit of the random number range.
@return 32bit random number
**/
UINT32
Random32 (
UINT32 Start,
UINT32 Limit
);
/**
Generate Count random numbers in FilePath.
@param FilePath The file path to put the generated random numbers.
@param Count Count of random numbers.
**/
VOID
GenerateRandomNumbers (
CHAR8 *FilePath,
UINTN Count
);
#endif
|