]>
Commit | Line | Data |
---|---|---|
e50466da | 1 | /** @file\r |
2 | MTRR setting library\r | |
3 | \r | |
341fea64 | 4 | Copyright (c) 2008 - 2017, Intel Corporation. All rights reserved.<BR>\r |
01a1c0fc | 5 | This program and the accompanying materials\r |
e50466da | 6 | are licensed and made available under the terms and conditions of the BSD License\r |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | #ifndef _MTRR_LIB_H_\r | |
16 | #define _MTRR_LIB_H_\r | |
17 | \r | |
18 | //\r | |
341fea64 | 19 | // According to IA32 SDM, MTRRs number and MSR offset are always consistent\r |
e50466da | 20 | // for IA32 processor family\r |
21 | //\r | |
3b9be416 JY |
22 | \r |
23 | //\r | |
3ba736f3 | 24 | // The semantics of below macro is MAX_MTRR_NUMBER_OF_VARIABLE_MTRR, the real number can be read out from MTRR_CAP register.\r |
3b9be416 | 25 | //\r |
3ba736f3 | 26 | #define MTRR_NUMBER_OF_VARIABLE_MTRR 32\r |
3b9be416 JY |
27 | //\r |
28 | // Firmware need reserve 2 MTRR for OS\r | |
46309b11 | 29 | // Note: It is replaced by PCD PcdCpuNumberOfReservedVariableMtrrs\r |
3b9be416 JY |
30 | //\r |
31 | #define RESERVED_FIRMWARE_VARIABLE_MTRR_NUMBER 2\r | |
32 | \r | |
e50466da | 33 | #define MTRR_NUMBER_OF_FIXED_MTRR 11\r |
3ba736f3 JY |
34 | //\r |
35 | // Below macro is deprecated, and should not be used.\r | |
36 | //\r | |
37 | #define FIRMWARE_VARIABLE_MTRR_NUMBER 6\r | |
3b9be416 JY |
38 | #define MTRR_LIB_IA32_MTRR_CAP 0x0FE\r |
39 | #define MTRR_LIB_IA32_MTRR_CAP_VCNT_MASK 0x0FF\r | |
e50466da | 40 | #define MTRR_LIB_IA32_MTRR_FIX64K_00000 0x250\r |
41 | #define MTRR_LIB_IA32_MTRR_FIX16K_80000 0x258\r | |
42 | #define MTRR_LIB_IA32_MTRR_FIX16K_A0000 0x259\r | |
43 | #define MTRR_LIB_IA32_MTRR_FIX4K_C0000 0x268\r | |
44 | #define MTRR_LIB_IA32_MTRR_FIX4K_C8000 0x269\r | |
45 | #define MTRR_LIB_IA32_MTRR_FIX4K_D0000 0x26A\r | |
46 | #define MTRR_LIB_IA32_MTRR_FIX4K_D8000 0x26B\r | |
47 | #define MTRR_LIB_IA32_MTRR_FIX4K_E0000 0x26C\r | |
48 | #define MTRR_LIB_IA32_MTRR_FIX4K_E8000 0x26D\r | |
49 | #define MTRR_LIB_IA32_MTRR_FIX4K_F0000 0x26E\r | |
50 | #define MTRR_LIB_IA32_MTRR_FIX4K_F8000 0x26F\r | |
51 | #define MTRR_LIB_IA32_VARIABLE_MTRR_BASE 0x200\r | |
3ba736f3 JY |
52 | //\r |
53 | // Below macro is deprecated, and should not be used.\r | |
54 | //\r | |
55 | #define MTRR_LIB_IA32_VARIABLE_MTRR_END 0x20F\r | |
e50466da | 56 | #define MTRR_LIB_IA32_MTRR_DEF_TYPE 0x2FF\r |
57 | #define MTRR_LIB_MSR_VALID_MASK 0xFFFFFFFFFULL\r | |
58 | #define MTRR_LIB_CACHE_VALID_ADDRESS 0xFFFFFF000ULL\r | |
59 | #define MTRR_LIB_CACHE_MTRR_ENABLED 0x800\r | |
60 | #define MTRR_LIB_CACHE_FIXED_MTRR_ENABLED 0x400\r | |
61 | \r | |
62 | //\r | |
63 | // Structure to describe a fixed MTRR\r | |
64 | //\r | |
65 | typedef struct {\r | |
66 | UINT32 Msr;\r | |
67 | UINT32 BaseAddress;\r | |
68 | UINT32 Length;\r | |
69 | } FIXED_MTRR;\r | |
70 | \r | |
71 | //\r | |
72 | // Structure to describe a variable MTRR\r | |
73 | //\r | |
74 | typedef struct {\r | |
75 | UINT64 BaseAddress;\r | |
76 | UINT64 Length;\r | |
77 | UINT64 Type;\r | |
78 | UINT32 Msr;\r | |
79 | BOOLEAN Valid;\r | |
80 | BOOLEAN Used;\r | |
81 | } VARIABLE_MTRR;\r | |
82 | \r | |
83 | //\r | |
84 | // Structure to hold base and mask pair for variable MTRR register\r | |
85 | //\r | |
86 | typedef struct _MTRR_VARIABLE_SETTING_ {\r | |
76b4cae3 MK |
87 | UINT64 Base;\r |
88 | UINT64 Mask;\r | |
e50466da | 89 | } MTRR_VARIABLE_SETTING;\r |
90 | \r | |
91 | //\r | |
92 | // Array for variable MTRRs\r | |
93 | //\r | |
94 | typedef struct _MTRR_VARIABLE_SETTINGS_ {\r | |
341fea64 RN |
95 | MTRR_VARIABLE_SETTING Mtrr[MTRR_NUMBER_OF_VARIABLE_MTRR];\r |
96 | } MTRR_VARIABLE_SETTINGS;\r | |
e50466da | 97 | \r |
98 | //\r | |
341fea64 | 99 | // Array for fixed MTRRs\r |
e50466da | 100 | //\r |
101 | typedef struct _MTRR_FIXED_SETTINGS_ {\r | |
102 | UINT64 Mtrr[MTRR_NUMBER_OF_FIXED_MTRR];\r | |
103 | } MTRR_FIXED_SETTINGS;\r | |
104 | \r | |
105 | //\r | |
106 | // Structure to hold all MTRRs\r | |
107 | //\r | |
108 | typedef struct _MTRR_SETTINGS_ {\r | |
109 | MTRR_FIXED_SETTINGS Fixed;\r | |
110 | MTRR_VARIABLE_SETTINGS Variables;\r | |
111 | UINT64 MtrrDefType;\r | |
112 | } MTRR_SETTINGS;\r | |
113 | \r | |
114 | //\r | |
115 | // Memory cache types\r | |
116 | //\r | |
117 | typedef enum {\r | |
76b4cae3 MK |
118 | CacheUncacheable = 0,\r |
119 | CacheWriteCombining = 1,\r | |
120 | CacheWriteThrough = 4,\r | |
121 | CacheWriteProtected = 5,\r | |
78c49925 RN |
122 | CacheWriteBack = 6,\r |
123 | CacheInvalid = 7\r | |
e50466da | 124 | } MTRR_MEMORY_CACHE_TYPE;\r |
125 | \r | |
126 | #define MTRR_CACHE_UNCACHEABLE 0\r | |
127 | #define MTRR_CACHE_WRITE_COMBINING 1\r | |
128 | #define MTRR_CACHE_WRITE_THROUGH 4\r | |
129 | #define MTRR_CACHE_WRITE_PROTECTED 5\r | |
130 | #define MTRR_CACHE_WRITE_BACK 6\r | |
131 | #define MTRR_CACHE_INVALID_TYPE 7\r | |
132 | \r | |
3b9be416 JY |
133 | /**\r |
134 | Returns the variable MTRR count for the CPU.\r | |
135 | \r | |
136 | @return Variable MTRR count\r | |
137 | \r | |
138 | **/\r | |
139 | UINT32\r | |
ed8dfd7b | 140 | EFIAPI\r |
3b9be416 JY |
141 | GetVariableMtrrCount (\r |
142 | VOID\r | |
143 | );\r | |
144 | \r | |
145 | /**\r | |
146 | Returns the firmware usable variable MTRR count for the CPU.\r | |
147 | \r | |
148 | @return Firmware usable variable MTRR count\r | |
149 | \r | |
150 | **/\r | |
151 | UINT32\r | |
ed8dfd7b | 152 | EFIAPI\r |
3b9be416 JY |
153 | GetFirmwareVariableMtrrCount (\r |
154 | VOID\r | |
155 | );\r | |
156 | \r | |
e50466da | 157 | /**\r |
158 | This function attempts to set the attributes for a memory range.\r | |
159 | \r | |
76b4cae3 MK |
160 | @param[in] BaseAddress The physical address that is the start\r |
161 | address of a memory region.\r | |
162 | @param[in] Length The size in bytes of the memory region.\r | |
163 | @param[in] Attribute The bit mask of attributes to set for the\r | |
164 | memory region.\r | |
e50466da | 165 | \r |
76b4cae3 MK |
166 | @retval RETURN_SUCCESS The attributes were set for the memory\r |
167 | region.\r | |
e50466da | 168 | @retval RETURN_INVALID_PARAMETER Length is zero.\r |
76b4cae3 MK |
169 | @retval RETURN_UNSUPPORTED The processor does not support one or\r |
170 | more bytes of the memory resource range\r | |
171 | specified by BaseAddress and Length.\r | |
172 | @retval RETURN_UNSUPPORTED The bit mask of attributes is not support\r | |
173 | for the memory resource range specified\r | |
174 | by BaseAddress and Length.\r | |
175 | @retval RETURN_ACCESS_DENIED The attributes for the memory resource\r | |
176 | range specified by BaseAddress and Length\r | |
177 | cannot be modified.\r | |
178 | @retval RETURN_OUT_OF_RESOURCES There are not enough system resources to\r | |
179 | modify the attributes of the memory\r | |
180 | resource range.\r | |
e50466da | 181 | \r |
182 | **/\r | |
183 | RETURN_STATUS\r | |
184 | EFIAPI\r | |
185 | MtrrSetMemoryAttribute (\r | |
186 | IN PHYSICAL_ADDRESS BaseAddress,\r | |
187 | IN UINT64 Length,\r | |
188 | IN MTRR_MEMORY_CACHE_TYPE Attribute\r | |
189 | );\r | |
190 | \r | |
191 | \r | |
192 | /**\r | |
193 | This function will get the memory cache type of the specific address.\r | |
194 | This function is mainly for debugging purposes.\r | |
195 | \r | |
76b4cae3 | 196 | @param[in] Address The specific address\r |
e50466da | 197 | \r |
198 | @return The memory cache type of the specific address\r | |
199 | \r | |
200 | **/\r | |
201 | MTRR_MEMORY_CACHE_TYPE\r | |
202 | EFIAPI\r | |
203 | MtrrGetMemoryAttribute (\r | |
204 | IN PHYSICAL_ADDRESS Address\r | |
205 | );\r | |
206 | \r | |
207 | \r | |
208 | /**\r | |
209 | This function will get the raw value in variable MTRRs\r | |
210 | \r | |
76b4cae3 | 211 | @param[out] VariableSettings A buffer to hold variable MTRRs content.\r |
e50466da | 212 | \r |
341fea64 | 213 | @return The buffer point to MTRR_VARIABLE_SETTINGS in which holds the content of the variable MTRR\r |
e50466da | 214 | \r |
215 | **/\r | |
216 | MTRR_VARIABLE_SETTINGS*\r | |
217 | EFIAPI\r | |
218 | MtrrGetVariableMtrr (\r | |
219 | OUT MTRR_VARIABLE_SETTINGS *VariableSettings\r | |
220 | );\r | |
221 | \r | |
222 | \r | |
223 | /**\r | |
341fea64 | 224 | This function sets variable MTRRs\r |
e50466da | 225 | \r |
76b4cae3 | 226 | @param[in] VariableSettings A buffer to hold variable MTRRs content.\r |
e50466da | 227 | \r |
228 | @return The pointer of VariableSettings\r | |
229 | \r | |
230 | **/\r | |
231 | MTRR_VARIABLE_SETTINGS*\r | |
232 | EFIAPI\r | |
233 | MtrrSetVariableMtrr (\r | |
234 | IN MTRR_VARIABLE_SETTINGS *VariableSettings\r | |
235 | );\r | |
236 | \r | |
237 | \r | |
238 | /**\r | |
239 | This function gets the content in fixed MTRRs\r | |
240 | \r | |
76b4cae3 | 241 | @param[out] FixedSettings A buffer to hold fixed MTRRs content.\r |
e50466da | 242 | \r |
243 | @return The pointer of FixedSettings\r | |
244 | \r | |
245 | **/\r | |
246 | MTRR_FIXED_SETTINGS*\r | |
247 | EFIAPI\r | |
248 | MtrrGetFixedMtrr (\r | |
249 | OUT MTRR_FIXED_SETTINGS *FixedSettings\r | |
250 | );\r | |
251 | \r | |
252 | \r | |
253 | /**\r | |
254 | This function sets fixed MTRRs\r | |
255 | \r | |
76b4cae3 | 256 | @param[in] FixedSettings A buffer holding fixed MTRRs content.\r |
e50466da | 257 | \r |
258 | @return The pointer of FixedSettings\r | |
259 | \r | |
260 | **/\r | |
261 | MTRR_FIXED_SETTINGS*\r | |
262 | EFIAPI\r | |
263 | MtrrSetFixedMtrr (\r | |
264 | IN MTRR_FIXED_SETTINGS *FixedSettings\r | |
265 | );\r | |
266 | \r | |
267 | \r | |
268 | /**\r | |
269 | This function gets the content in all MTRRs (variable and fixed)\r | |
270 | \r | |
76b4cae3 | 271 | @param[out] MtrrSetting A buffer to hold all MTRRs content.\r |
e50466da | 272 | \r |
273 | @return The pointer of MtrrSetting\r | |
274 | \r | |
275 | **/\r | |
276 | MTRR_SETTINGS *\r | |
277 | EFIAPI\r | |
278 | MtrrGetAllMtrrs (\r | |
279 | OUT MTRR_SETTINGS *MtrrSetting\r | |
280 | );\r | |
281 | \r | |
282 | \r | |
283 | /**\r | |
284 | This function sets all MTRRs (variable and fixed)\r | |
285 | \r | |
76b4cae3 | 286 | @param[in] MtrrSetting A buffer to hold all MTRRs content.\r |
e50466da | 287 | \r |
288 | @return The pointer of MtrrSetting\r | |
289 | \r | |
290 | **/\r | |
291 | MTRR_SETTINGS *\r | |
292 | EFIAPI\r | |
293 | MtrrSetAllMtrrs (\r | |
294 | IN MTRR_SETTINGS *MtrrSetting\r | |
295 | );\r | |
296 | \r | |
297 | \r | |
298 | /**\r | |
299 | Get the attribute of variable MTRRs.\r | |
300 | \r | |
301 | This function shadows the content of variable MTRRs into\r | |
302 | an internal array: VariableMtrr\r | |
303 | \r | |
76b4cae3 MK |
304 | @param[in] MtrrValidBitsMask The mask for the valid bit of the MTRR\r |
305 | @param[in] MtrrValidAddressMask The valid address mask for MTRR since the base address in\r | |
306 | MTRR must align to 4K, so valid address mask equal to\r | |
307 | MtrrValidBitsMask & 0xfffffffffffff000ULL\r | |
308 | @param[out] VariableMtrr The array to shadow variable MTRRs content\r | |
309 | \r | |
438f1766 | 310 | @return The return value of this parameter indicates the number of\r |
3ba736f3 | 311 | MTRRs which has been used.\r |
e50466da | 312 | **/\r |
3ba736f3 | 313 | UINT32\r |
e50466da | 314 | EFIAPI\r |
315 | MtrrGetMemoryAttributeInVariableMtrr (\r | |
316 | IN UINT64 MtrrValidBitsMask,\r | |
317 | IN UINT64 MtrrValidAddressMask,\r | |
318 | OUT VARIABLE_MTRR *VariableMtrr\r | |
319 | );\r | |
320 | \r | |
321 | \r | |
322 | /**\r | |
323 | This function prints all MTRRs for debugging.\r | |
324 | **/\r | |
325 | VOID\r | |
ed8dfd7b | 326 | EFIAPI\r |
e50466da | 327 | MtrrDebugPrintAllMtrrs (\r |
430fbbe0 | 328 | VOID\r |
e50466da | 329 | );\r |
330 | \r | |
947a573a | 331 | /**\r |
332 | Checks if MTRR is supported.\r | |
333 | \r | |
334 | @retval TRUE MTRR is supported.\r | |
335 | @retval FALSE MTRR is not supported.\r | |
336 | \r | |
337 | **/\r | |
338 | BOOLEAN\r | |
ed8dfd7b | 339 | EFIAPI\r |
947a573a | 340 | IsMtrrSupported (\r |
341 | VOID\r | |
342 | );\r | |
343 | \r | |
91ec7824 | 344 | /**\r |
345 | Returns the default MTRR cache type for the system.\r | |
346 | \r | |
347 | @return The default MTRR cache type.\r | |
348 | \r | |
349 | **/\r | |
350 | MTRR_MEMORY_CACHE_TYPE\r | |
351 | EFIAPI\r | |
352 | MtrrGetDefaultMemoryType (\r | |
353 | VOID\r | |
354 | );\r | |
355 | \r | |
b970ed68 MK |
356 | /**\r |
357 | This function attempts to set the attributes into MTRR setting buffer for a memory range.\r | |
358 | \r | |
359 | @param[in, out] MtrrSetting MTRR setting buffer to be set.\r | |
360 | @param[in] BaseAddress The physical address that is the start address\r | |
361 | of a memory region.\r | |
362 | @param[in] Length The size in bytes of the memory region.\r | |
363 | @param[in] Attribute The bit mask of attributes to set for the\r | |
364 | memory region.\r | |
365 | \r | |
366 | @retval RETURN_SUCCESS The attributes were set for the memory region.\r | |
367 | @retval RETURN_INVALID_PARAMETER Length is zero.\r | |
368 | @retval RETURN_UNSUPPORTED The processor does not support one or more bytes of the\r | |
369 | memory resource range specified by BaseAddress and Length.\r | |
370 | @retval RETURN_UNSUPPORTED The bit mask of attributes is not support for the memory resource\r | |
371 | range specified by BaseAddress and Length.\r | |
372 | @retval RETURN_ACCESS_DENIED The attributes for the memory resource range specified by\r | |
373 | BaseAddress and Length cannot be modified.\r | |
374 | @retval RETURN_OUT_OF_RESOURCES There are not enough system resources to modify the attributes of\r | |
375 | the memory resource range.\r | |
376 | \r | |
377 | **/\r | |
378 | RETURN_STATUS\r | |
379 | EFIAPI\r | |
380 | MtrrSetMemoryAttributeInMtrrSettings (\r | |
381 | IN OUT MTRR_SETTINGS *MtrrSetting,\r | |
382 | IN PHYSICAL_ADDRESS BaseAddress,\r | |
383 | IN UINT64 Length,\r | |
384 | IN MTRR_MEMORY_CACHE_TYPE Attribute\r | |
385 | );\r | |
386 | \r | |
e50466da | 387 | #endif // _MTRR_LIB_H_\r |