4 Copyright (c) 2008 - 2017, Intel Corporation. All rights reserved.<BR>
5 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
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.
19 // According to IA32 SDM, MTRRs number and MSR offset are always consistent
20 // for IA32 processor family
24 // The semantics of below macro is MAX_MTRR_NUMBER_OF_VARIABLE_MTRR, the real number can be read out from MTRR_CAP register.
26 #define MTRR_NUMBER_OF_VARIABLE_MTRR 32
28 // Firmware need reserve 2 MTRR for OS
29 // Note: It is replaced by PCD PcdCpuNumberOfReservedVariableMtrrs
31 #define RESERVED_FIRMWARE_VARIABLE_MTRR_NUMBER 2
33 #define MTRR_NUMBER_OF_FIXED_MTRR 11
36 // Structure to describe a fixed MTRR
45 // Structure to describe a variable MTRR
57 // Structure to hold base and mask pair for variable MTRR register
59 typedef struct _MTRR_VARIABLE_SETTING_
{
62 } MTRR_VARIABLE_SETTING
;
65 // Array for variable MTRRs
67 typedef struct _MTRR_VARIABLE_SETTINGS_
{
68 MTRR_VARIABLE_SETTING Mtrr
[MTRR_NUMBER_OF_VARIABLE_MTRR
];
69 } MTRR_VARIABLE_SETTINGS
;
72 // Array for fixed MTRRs
74 typedef struct _MTRR_FIXED_SETTINGS_
{
75 UINT64 Mtrr
[MTRR_NUMBER_OF_FIXED_MTRR
];
76 } MTRR_FIXED_SETTINGS
;
79 // Structure to hold all MTRRs
81 typedef struct _MTRR_SETTINGS_
{
82 MTRR_FIXED_SETTINGS Fixed
;
83 MTRR_VARIABLE_SETTINGS Variables
;
92 CacheWriteCombining
= 1,
93 CacheWriteThrough
= 4,
94 CacheWriteProtected
= 5,
97 } MTRR_MEMORY_CACHE_TYPE
;
99 #define MTRR_CACHE_UNCACHEABLE 0
100 #define MTRR_CACHE_WRITE_COMBINING 1
101 #define MTRR_CACHE_WRITE_THROUGH 4
102 #define MTRR_CACHE_WRITE_PROTECTED 5
103 #define MTRR_CACHE_WRITE_BACK 6
104 #define MTRR_CACHE_INVALID_TYPE 7
107 Returns the variable MTRR count for the CPU.
109 @return Variable MTRR count
114 GetVariableMtrrCount (
119 Returns the firmware usable variable MTRR count for the CPU.
121 @return Firmware usable variable MTRR count
126 GetFirmwareVariableMtrrCount (
131 This function attempts to set the attributes for a memory range.
133 @param[in] BaseAddress The physical address that is the start
134 address of a memory region.
135 @param[in] Length The size in bytes of the memory region.
136 @param[in] Attribute The bit mask of attributes to set for the
139 @retval RETURN_SUCCESS The attributes were set for the memory
141 @retval RETURN_INVALID_PARAMETER Length is zero.
142 @retval RETURN_UNSUPPORTED The processor does not support one or
143 more bytes of the memory resource range
144 specified by BaseAddress and Length.
145 @retval RETURN_UNSUPPORTED The bit mask of attributes is not support
146 for the memory resource range specified
147 by BaseAddress and Length.
148 @retval RETURN_ACCESS_DENIED The attributes for the memory resource
149 range specified by BaseAddress and Length
151 @retval RETURN_OUT_OF_RESOURCES There are not enough system resources to
152 modify the attributes of the memory
158 MtrrSetMemoryAttribute (
159 IN PHYSICAL_ADDRESS BaseAddress
,
161 IN MTRR_MEMORY_CACHE_TYPE Attribute
166 This function will get the memory cache type of the specific address.
167 This function is mainly for debugging purposes.
169 @param[in] Address The specific address
171 @return The memory cache type of the specific address
174 MTRR_MEMORY_CACHE_TYPE
176 MtrrGetMemoryAttribute (
177 IN PHYSICAL_ADDRESS Address
182 This function will get the raw value in variable MTRRs
184 @param[out] VariableSettings A buffer to hold variable MTRRs content.
186 @return The buffer point to MTRR_VARIABLE_SETTINGS in which holds the content of the variable MTRR
189 MTRR_VARIABLE_SETTINGS
*
191 MtrrGetVariableMtrr (
192 OUT MTRR_VARIABLE_SETTINGS
*VariableSettings
197 This function sets variable MTRRs
199 @param[in] VariableSettings A buffer to hold variable MTRRs content.
201 @return The pointer of VariableSettings
204 MTRR_VARIABLE_SETTINGS
*
206 MtrrSetVariableMtrr (
207 IN MTRR_VARIABLE_SETTINGS
*VariableSettings
212 This function gets the content in fixed MTRRs
214 @param[out] FixedSettings A buffer to hold fixed MTRRs content.
216 @return The pointer of FixedSettings
222 OUT MTRR_FIXED_SETTINGS
*FixedSettings
227 This function sets fixed MTRRs
229 @param[in] FixedSettings A buffer holding fixed MTRRs content.
231 @return The pointer of FixedSettings
237 IN MTRR_FIXED_SETTINGS
*FixedSettings
242 This function gets the content in all MTRRs (variable and fixed)
244 @param[out] MtrrSetting A buffer to hold all MTRRs content.
246 @return The pointer of MtrrSetting
252 OUT MTRR_SETTINGS
*MtrrSetting
257 This function sets all MTRRs (variable and fixed)
259 @param[in] MtrrSetting A buffer to hold all MTRRs content.
261 @return The pointer of MtrrSetting
267 IN MTRR_SETTINGS
*MtrrSetting
272 Get the attribute of variable MTRRs.
274 This function shadows the content of variable MTRRs into
275 an internal array: VariableMtrr
277 @param[in] MtrrValidBitsMask The mask for the valid bit of the MTRR
278 @param[in] MtrrValidAddressMask The valid address mask for MTRR since the base address in
279 MTRR must align to 4K, so valid address mask equal to
280 MtrrValidBitsMask & 0xfffffffffffff000ULL
281 @param[out] VariableMtrr The array to shadow variable MTRRs content
283 @return The return value of this parameter indicates the number of
284 MTRRs which has been used.
288 MtrrGetMemoryAttributeInVariableMtrr (
289 IN UINT64 MtrrValidBitsMask
,
290 IN UINT64 MtrrValidAddressMask
,
291 OUT VARIABLE_MTRR
*VariableMtrr
296 This function prints all MTRRs for debugging.
300 MtrrDebugPrintAllMtrrs (
305 Checks if MTRR is supported.
307 @retval TRUE MTRR is supported.
308 @retval FALSE MTRR is not supported.
318 Returns the default MTRR cache type for the system.
320 @return The default MTRR cache type.
323 MTRR_MEMORY_CACHE_TYPE
325 MtrrGetDefaultMemoryType (
330 This function attempts to set the attributes into MTRR setting buffer for a memory range.
332 @param[in, out] MtrrSetting MTRR setting buffer to be set.
333 @param[in] BaseAddress The physical address that is the start address
335 @param[in] Length The size in bytes of the memory region.
336 @param[in] Attribute The bit mask of attributes to set for the
339 @retval RETURN_SUCCESS The attributes were set for the memory region.
340 @retval RETURN_INVALID_PARAMETER Length is zero.
341 @retval RETURN_UNSUPPORTED The processor does not support one or more bytes of the
342 memory resource range specified by BaseAddress and Length.
343 @retval RETURN_UNSUPPORTED The bit mask of attributes is not support for the memory resource
344 range specified by BaseAddress and Length.
345 @retval RETURN_ACCESS_DENIED The attributes for the memory resource range specified by
346 BaseAddress and Length cannot be modified.
347 @retval RETURN_OUT_OF_RESOURCES There are not enough system resources to modify the attributes of
348 the memory resource range.
353 MtrrSetMemoryAttributeInMtrrSettings (
354 IN OUT MTRR_SETTINGS
*MtrrSetting
,
355 IN PHYSICAL_ADDRESS BaseAddress
,
357 IN MTRR_MEMORY_CACHE_TYPE Attribute
360 #endif // _MTRR_LIB_H_