]>
Commit | Line | Data |
---|---|---|
e17f459a RN |
1 | /** @file\r |
2 | \r | |
3 | Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>\r | |
4 | SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
5 | \r | |
6 | **/\r | |
7 | \r | |
8 | #ifndef _MTRR_SUPPORT_H_\r | |
9 | #define _MTRR_SUPPORT_H_\r | |
10 | \r | |
11 | #include <stdio.h>\r | |
12 | #include <stdlib.h>\r | |
13 | #include <string.h>\r | |
14 | #include <stdarg.h>\r | |
15 | #include <stddef.h>\r | |
16 | #include <setjmp.h>\r | |
17 | #include <cmocka.h>\r | |
18 | #include <time.h>\r | |
19 | \r | |
20 | #include <Uefi.h>\r | |
21 | #include <Library/BaseLib.h>\r | |
22 | #include <Library/BaseMemoryLib.h>\r | |
23 | #include <Library/DebugLib.h>\r | |
24 | #include <Library/UnitTestLib.h>\r | |
25 | #include <Library/MtrrLib.h>\r | |
26 | #include <Library/UnitTestHostBaseLib.h>\r | |
27 | \r | |
28 | #include <Register/ArchitecturalMsr.h>\r | |
29 | #include <Register/Cpuid.h>\r | |
30 | #include <Register/Msr.h>\r | |
31 | \r | |
32 | #define UNIT_TEST_APP_NAME "MtrrLib Unit Tests"\r | |
33 | #define UNIT_TEST_APP_VERSION "1.0"\r | |
34 | \r | |
35 | #define SCRATCH_BUFFER_SIZE SIZE_16KB\r | |
36 | \r | |
37 | typedef struct {\r | |
38 | UINT8 PhysicalAddressBits;\r | |
39 | BOOLEAN MtrrSupported;\r | |
40 | BOOLEAN FixedMtrrSupported;\r | |
41 | MTRR_MEMORY_CACHE_TYPE DefaultCacheType;\r | |
42 | UINT32 VariableMtrrCount;\r | |
43 | } MTRR_LIB_SYSTEM_PARAMETER;\r | |
44 | \r | |
45 | extern UINT32 mFixedMtrrsIndex[];\r | |
65904cdb | 46 | extern BOOLEAN mRandomInput;\r |
e17f459a RN |
47 | \r |
48 | /**\r | |
49 | Initialize the MTRR registers.\r | |
50 | \r | |
51 | @param SystemParameter System parameter that controls the MTRR registers initialization.\r | |
52 | **/\r | |
53 | UNIT_TEST_STATUS\r | |
54 | EFIAPI\r | |
55 | InitializeMtrrRegs (\r | |
56 | IN MTRR_LIB_SYSTEM_PARAMETER *SystemParameter\r | |
57 | );\r | |
58 | \r | |
59 | /**\r | |
60 | Initialize the MTRR registers.\r | |
61 | \r | |
62 | @param Context System parameter that controls the MTRR registers initialization.\r | |
63 | **/\r | |
64 | UNIT_TEST_STATUS\r | |
65 | EFIAPI\r | |
66 | InitializeSystem (\r | |
67 | IN UNIT_TEST_CONTEXT Context\r | |
68 | );\r | |
69 | \r | |
70 | /**\r | |
71 | Return a random memory cache type.\r | |
72 | **/\r | |
73 | MTRR_MEMORY_CACHE_TYPE\r | |
74 | GenerateRandomCacheType (\r | |
75 | VOID\r | |
76 | );\r | |
77 | \r | |
78 | /**\r | |
79 | Generate random MTRRs.\r | |
80 | \r | |
81 | @param PhysicalAddressBits Physical address bits.\r | |
82 | @param RawMemoryRanges Return the randomly generated MTRRs.\r | |
83 | @param UcCount Count of Uncacheable MTRRs.\r | |
84 | @param WtCount Count of Write Through MTRRs.\r | |
85 | @param WbCount Count of Write Back MTRRs.\r | |
86 | @param WpCount Count of Write Protected MTRRs.\r | |
87 | @param WcCount Count of Write Combining MTRRs.\r | |
88 | **/\r | |
89 | VOID\r | |
90 | GenerateValidAndConfigurableMtrrPairs (\r | |
91 | IN UINT32 PhysicalAddressBits,\r | |
92 | IN OUT MTRR_MEMORY_RANGE *RawMemoryRanges,\r | |
93 | IN UINT32 UcCount,\r | |
94 | IN UINT32 WtCount,\r | |
95 | IN UINT32 WbCount,\r | |
96 | IN UINT32 WpCount,\r | |
97 | IN UINT32 WcCount\r | |
98 | );\r | |
99 | \r | |
100 | /**\r | |
101 | Convert the MTRR BASE/MASK array to memory ranges.\r | |
102 | \r | |
103 | @param DefaultType Default memory type.\r | |
104 | @param PhysicalAddressBits Physical address bits.\r | |
105 | @param RawMemoryRanges Raw memory ranges.\r | |
106 | @param RawMemoryRangeCount Count of raw memory ranges.\r | |
107 | @param MemoryRanges Memory ranges.\r | |
108 | @param MemoryRangeCount Count of memory ranges.\r | |
109 | **/\r | |
110 | VOID\r | |
111 | GetEffectiveMemoryRanges (\r | |
112 | IN MTRR_MEMORY_CACHE_TYPE DefaultType,\r | |
113 | IN UINT32 PhysicalAddressBits,\r | |
114 | IN MTRR_MEMORY_RANGE *RawMemoryRanges,\r | |
115 | IN UINT32 RawMemoryRangeCount,\r | |
116 | OUT MTRR_MEMORY_RANGE *MemoryRanges,\r | |
117 | OUT UINTN *MemoryRangeCount\r | |
118 | );\r | |
119 | \r | |
120 | /**\r | |
121 | Generate random MTRR BASE/MASK for a specified type.\r | |
122 | \r | |
123 | @param PhysicalAddressBits Physical address bits.\r | |
124 | @param CacheType Cache type.\r | |
125 | @param MtrrPair Return the random MTRR.\r | |
126 | @param MtrrMemoryRange Return the random memory range.\r | |
127 | **/\r | |
128 | VOID\r | |
129 | GenerateRandomMtrrPair (\r | |
130 | IN UINT32 PhysicalAddressBits,\r | |
131 | IN MTRR_MEMORY_CACHE_TYPE CacheType,\r | |
4ec586b9 | 132 | OUT MTRR_VARIABLE_SETTING *MtrrPair OPTIONAL,\r |
e17f459a RN |
133 | OUT MTRR_MEMORY_RANGE *MtrrMemoryRange OPTIONAL\r |
134 | );\r | |
135 | \r | |
136 | /**\r | |
137 | Collect the test result.\r | |
138 | \r | |
139 | @param DefaultType Default memory type.\r | |
140 | @param PhysicalAddressBits Physical address bits.\r | |
141 | @param VariableMtrrCount Count of variable MTRRs.\r | |
142 | @param Mtrrs MTRR settings to collect from.\r | |
143 | @param Ranges Return the memory ranges.\r | |
144 | @param RangeCount Return the count of memory ranges.\r | |
145 | @param MtrrCount Return the count of variable MTRRs being used.\r | |
146 | **/\r | |
147 | VOID\r | |
148 | CollectTestResult (\r | |
149 | IN MTRR_MEMORY_CACHE_TYPE DefaultType,\r | |
150 | IN UINT32 PhysicalAddressBits,\r | |
151 | IN UINT32 VariableMtrrCount,\r | |
152 | IN MTRR_SETTINGS *Mtrrs,\r | |
153 | OUT MTRR_MEMORY_RANGE *Ranges,\r | |
154 | IN OUT UINTN *RangeCount,\r | |
155 | OUT UINT32 *MtrrCount\r | |
156 | );\r | |
157 | \r | |
158 | /**\r | |
159 | Return a 64bit random number.\r | |
160 | \r | |
161 | @param Start Start of the random number range.\r | |
162 | @param Limit Limit of the random number range.\r | |
163 | @return 64bit random number\r | |
164 | **/\r | |
165 | UINT64\r | |
166 | Random64 (\r | |
167 | UINT64 Start,\r | |
168 | UINT64 Limit\r | |
169 | );\r | |
170 | \r | |
171 | /**\r | |
172 | Return a 32bit random number.\r | |
173 | \r | |
174 | @param Start Start of the random number range.\r | |
175 | @param Limit Limit of the random number range.\r | |
176 | @return 32bit random number\r | |
177 | **/\r | |
178 | UINT32\r | |
179 | Random32 (\r | |
180 | UINT32 Start,\r | |
181 | UINT32 Limit\r | |
182 | );\r | |
65904cdb RN |
183 | \r |
184 | /**\r | |
185 | Generate Count random numbers in FilePath.\r | |
186 | \r | |
187 | @param FilePath The file path to put the generated random numbers.\r | |
188 | @param Count Count of random numbers.\r | |
189 | **/\r | |
190 | VOID\r | |
191 | GenerateRandomNumbers (\r | |
192 | CHAR8 *FilePath,\r | |
193 | UINTN Count\r | |
194 | );\r | |
e17f459a | 195 | #endif\r |