// Structure to hold base and mask pair for variable MTRR register\r
//\r
typedef struct _MTRR_VARIABLE_SETTING_ {\r
- UINT64 Base;\r
- UINT64 Mask;\r
+ UINT64 Base;\r
+ UINT64 Mask;\r
} MTRR_VARIABLE_SETTING;\r
\r
//\r
// Memory cache types\r
//\r
typedef enum {\r
- CacheUncacheable = 0,\r
- CacheWriteCombining = 1,\r
- CacheWriteThrough = 4,\r
- CacheWriteProtected = 5,\r
- CacheWriteBack = 6\r
+ CacheUncacheable = 0,\r
+ CacheWriteCombining = 1,\r
+ CacheWriteThrough = 4,\r
+ CacheWriteProtected = 5,\r
+ CacheWriteBack = 6\r
} MTRR_MEMORY_CACHE_TYPE;\r
\r
#define MTRR_CACHE_UNCACHEABLE 0\r
/**\r
This function attempts to set the attributes for a memory range.\r
\r
- @param BaseAddress The physical address that is the start address of a memory region.\r
- @param Length The size in bytes of the memory region.\r
- @param Attributes The bit mask of attributes to set for the memory region.\r
+ @param[in] BaseAddress The physical address that is the start\r
+ address of a memory region.\r
+ @param[in] Length The size in bytes of the memory region.\r
+ @param[in] Attribute The bit mask of attributes to set for the\r
+ memory region.\r
\r
- @retval RETURN_SUCCESS The attributes were set for the memory region.\r
+ @retval RETURN_SUCCESS The attributes were set for the memory\r
+ region.\r
@retval RETURN_INVALID_PARAMETER Length is zero.\r
- @retval RETURN_UNSUPPORTED The processor does not support one or more bytes of the\r
- memory resource range specified by BaseAddress and Length.\r
- @retval RETURN_UNSUPPORTED The bit mask of attributes is not support for the memory resource\r
- range specified by BaseAddress and Length.\r
- @retval RETURN_ACCESS_DENIED The attributes for the memory resource range specified by\r
- BaseAddress and Length cannot be modified.\r
- @retval RETURN_OUT_OF_RESOURCES There are not enough system resources to modify the attributes of\r
- the memory resource range.\r
+ @retval RETURN_UNSUPPORTED The processor does not support one or\r
+ more bytes of the memory resource range\r
+ specified by BaseAddress and Length.\r
+ @retval RETURN_UNSUPPORTED The bit mask of attributes is not support\r
+ for the memory resource range specified\r
+ by BaseAddress and Length.\r
+ @retval RETURN_ACCESS_DENIED The attributes for the memory resource\r
+ range specified by BaseAddress and Length\r
+ cannot be modified.\r
+ @retval RETURN_OUT_OF_RESOURCES There are not enough system resources to\r
+ modify the attributes of the memory\r
+ resource range.\r
\r
**/\r
RETURN_STATUS\r
This function will get the memory cache type of the specific address.\r
This function is mainly for debugging purposes.\r
\r
- @param Address The specific address\r
+ @param[in] Address The specific address\r
\r
@return The memory cache type of the specific address\r
\r
/**\r
This function will get the raw value in variable MTRRs\r
\r
- @param VariableSettings A buffer to hold variable MTRRs content.\r
+ @param[out] VariableSettings A buffer to hold variable MTRRs content.\r
\r
@return The buffer point to MTRR_VARIABLE_SETTINGS in which holds the content of the variable mtrr\r
\r
/**\r
This function sets fixed MTRRs\r
\r
- @param VariableSettings A buffer to hold variable MTRRs content.\r
+ @param[in] VariableSettings A buffer to hold variable MTRRs content.\r
\r
@return The pointer of VariableSettings\r
\r
/**\r
This function gets the content in fixed MTRRs\r
\r
- @param FixedSettings A buffer to hold fixed MTRRs content.\r
+ @param[out] FixedSettings A buffer to hold fixed MTRRs content.\r
\r
@return The pointer of FixedSettings\r
\r
/**\r
This function sets fixed MTRRs\r
\r
- @param FixedSettings A buffer holding fixed MTRRs content.\r
+ @param[in] FixedSettings A buffer holding fixed MTRRs content.\r
\r
@return The pointer of FixedSettings\r
\r
/**\r
This function gets the content in all MTRRs (variable and fixed)\r
\r
- @param MtrrSetting A buffer to hold all MTRRs content.\r
+ @param[out] MtrrSetting A buffer to hold all MTRRs content.\r
\r
@return The pointer of MtrrSetting\r
\r
/**\r
This function sets all MTRRs (variable and fixed)\r
\r
- @param MtrrSetting A buffer to hold all MTRRs content.\r
+ @param[in] MtrrSetting A buffer to hold all MTRRs content.\r
\r
@return The pointer of MtrrSetting\r
\r
This function shadows the content of variable MTRRs into\r
an internal array: VariableMtrr\r
\r
- @param MtrrValidBitsMask The mask for the valid bit of the MTRR\r
- @param MtrrValidAddressMask The valid address mask for MTRR since the base address in\r
- MTRR must align to 4K, so valid address mask equal to\r
- MtrrValidBitsMask & 0xfffffffffffff000ULL\r
- @param VariableMtrr The array to shadow variable MTRRs content\r
+ @param[in] MtrrValidBitsMask The mask for the valid bit of the MTRR\r
+ @param[in] MtrrValidAddressMask The valid address mask for MTRR since the base address in\r
+ MTRR must align to 4K, so valid address mask equal to\r
+ MtrrValidBitsMask & 0xfffffffffffff000ULL\r
+ @param[out] VariableMtrr The array to shadow variable MTRRs content\r
+\r
@return The ruturn value of this paramter indicates the number of\r
MTRRs which has been used.\r
**/\r
MTRR_LIB_IA32_MTRR_FIX4K_F8000,\r
0xF8000,\r
SIZE_4KB\r
- },\r
+ }\r
};\r
\r
//\r
// Disable interrupts and save current interrupt state\r
//\r
MtrrContext->InterruptState = SaveAndDisableInterrupts();\r
- \r
+\r
//\r
// Enter no fill cache mode, CD=1(Bit30), NW=0 (Bit29)\r
//\r
CpuFlushTlb ();\r
\r
//\r
- // Disable Mtrrs\r
+ // Disable MTRRs\r
//\r
AsmMsrBitFieldWrite64 (MTRR_LIB_IA32_MTRR_DEF_TYPE, 10, 11, 0);\r
}\r
)\r
{\r
//\r
- // Flush all TLBs \r
+ // Flush all TLBs\r
//\r
CpuFlushTlb ();\r
\r
// Restore original CR4 value\r
//\r
AsmWriteCr4 (MtrrContext->Cr4);\r
- \r
+\r
//\r
// Restore original interrupt state\r
//\r
/**\r
Programs fixed MTRRs registers.\r
\r
- @param MemoryCacheType The memory type to set.\r
- @param Base The base address of memory range.\r
- @param Length The length of memory range.\r
+ @param[in] MemoryCacheType The memory type to set.\r
+ @param[in, out] Base The base address of memory range.\r
+ @param[in, out] Length The length of memory range.\r
\r
@retval RETURN_SUCCESS The cache type was updated successfully\r
@retval RETURN_UNSUPPORTED The requested range or cache type was invalid\r
\r
\r
/**\r
- Get the attribute of variable MTRRs.\r
+ Gets the attribute of variable MTRRs.\r
\r
This function shadows the content of variable MTRRs into an\r
internal array: VariableMtrr.\r
\r
- @param MtrrValidBitsMask The mask for the valid bit of the MTRR\r
- @param MtrrValidAddressMask The valid address mask for MTRR\r
- @param VariableMtrr The array to shadow variable MTRRs content\r
+ @param[in] MtrrValidBitsMask The mask for the valid bit of the MTRR\r
+ @param[in] MtrrValidAddressMask The valid address mask for MTRR\r
+ @param[out] VariableMtrr The array to shadow variable MTRRs content\r
\r
@return The return value of this paramter indicates the\r
number of MTRRs which has been used.\r
/**\r
Checks overlap between given memory range and MTRRs.\r
\r
- @param Start The start address of memory range.\r
- @param End The end address of memory range.\r
- @param VariableMtrr The array to shadow variable MTRRs content\r
+ @param[in] Start The start address of memory range.\r
+ @param[in] End The end address of memory range.\r
+ @param[in] VariableMtrr The array to shadow variable MTRRs content\r
\r
@retval TRUE Overlap exists.\r
@retval FALSE No overlap.\r
/**\r
Marks a variable MTRR as non-valid.\r
\r
- @param Index The index of the array VariableMtrr to be invalidated\r
- @param VariableMtrr The array to shadow variable MTRRs content\r
- @param UsedMtrr The number of MTRRs which has already been used\r
+ @param[in] Index The index of the array VariableMtrr to be invalidated\r
+ @param[in] VariableMtrr The array to shadow variable MTRRs content\r
+ @param[out] UsedMtrr The number of MTRRs which has already been used\r
\r
**/\r
VOID\r
\r
\r
/**\r
- Combine memory attributes.\r
+ Combines memory attributes.\r
\r
If overlap exists between given memory range and MTRRs, try to combine them.\r
\r
- @param Attributes The memory type to set.\r
- @param Base The base address of memory range.\r
- @param Length The length of memory range.\r
- @param VariableMtrr The array to shadow variable MTRRs content\r
- @param UsedMtrr The number of MTRRs which has already been used\r
- @param OverwriteExistingMtrr Returns whether an existing MTRR was used\r
+ @param[in] Attributes The memory type to set.\r
+ @param[in, out] Base The base address of memory range.\r
+ @param[in, out] Length The length of memory range.\r
+ @param[in] VariableMtrr The array to shadow variable MTRRs content\r
+ @param[in, out] UsedMtrr The number of MTRRs which has already been used\r
+ @param[out] OverwriteExistingMtrr Returns whether an existing MTRR was used\r
\r
@retval EFI_SUCCESS Memory region successfully combined.\r
@retval EFI_ACCESS_DENIED Memory region cannot be combined.\r
//\r
if (Attributes == VariableMtrr[Index].Type) {\r
//\r
- // if the Mtrr range contain the request range, set a flag, then continue to \r
+ // if the MTRR range contain the request range, set a flag, then continue to\r
// invalidate any MTRR of the same request range with higher priority cache type.\r
//\r
if (VariableMtrr[Index].BaseAddress <= *Base && MtrrEnd >= EndAddress) {\r
\r
\r
/**\r
- Calculate the maximum value which is a power of 2, but less the MemoryLength.\r
+ Calculates the maximum value which is a power of 2, but less the MemoryLength.\r
+\r
+ @param[in] MemoryLength The number to pass in.\r
\r
- @param MemoryLength The number to pass in.\r
@return The maximum value which is align to power of 2 and less the MemoryLength\r
\r
**/\r
\r
\r
/**\r
- Determine the MTRR numbers used to program a memory range.\r
+ Determines the MTRR numbers used to program a memory range.\r
\r
- This function first checks the alignment of the base address. If the alignment of the base address <= Length,\r
- cover the memory range (BaseAddress, alignment) by a MTRR, then BaseAddress += alignment and Length -= alignment.\r
- Repeat the step until alignment > Length.\r
+ This function first checks the alignment of the base address.\r
+ If the alignment of the base address <= Length, cover the memory range\r
+ (BaseAddress, alignment) by a MTRR, then BaseAddress += alignment and\r
+ Length -= alignment. Repeat the step until alignment > Length.\r
\r
- Then this function determines which direction of programming the variable MTRRs for the remaining length\r
- will use fewer MTRRs.\r
+ Then this function determines which direction of programming the variable\r
+ MTRRs for the remaining length will use fewer MTRRs.\r
\r
- @param BaseAddress Length of Memory to program MTRR\r
- @param Length Length of Memory to program MTRR\r
- @param MtrrNumber Pointer to the number of necessary MTRRs\r
+ @param[in] BaseAddress Length of Memory to program MTRR\r
+ @param[in] Length Length of Memory to program MTRR\r
+ @param[in] MtrrNumber Pointer to the number of necessary MTRRs\r
\r
@retval TRUE Positive direction is better.\r
- FALSE Negtive direction is better.\r
+ FALSE Negative direction is better.\r
\r
**/\r
BOOLEAN\r
This function programs MTRRs according to the values specified\r
in the shadow array.\r
\r
- @param VariableMtrr The array to shadow variable MTRRs content\r
+ @param[in, out] VariableMtrr Shadow of variable MTRR contents\r
\r
**/\r
VOID\r
InvalidateMtrr (\r
- IN VARIABLE_MTRR *VariableMtrr\r
- )\r
+ IN OUT VARIABLE_MTRR *VariableMtrr\r
+ )\r
{\r
UINTN Index;\r
UINTN VariableMtrrCount;\r
\r
This function programs variable MTRRs\r
\r
- @param MtrrNumber Index of MTRR to program.\r
- @param BaseAddress Base address of memory region.\r
- @param Length Length of memory region.\r
- @param MemoryCacheType Memory type to set.\r
- @param MtrrValidAddressMask The valid address mask for MTRR\r
+ @param[in] MtrrNumber Index of MTRR to program.\r
+ @param[in] BaseAddress Base address of memory region.\r
+ @param[in] Length Length of memory region.\r
+ @param[in] MemoryCacheType Memory type to set.\r
+ @param[in] MtrrValidAddressMask The valid address mask for MTRR\r
\r
**/\r
VOID\r
\r
\r
/**\r
- Convert the Memory attibute value to MTRR_MEMORY_CACHE_TYPE.\r
+ Converts the Memory attribute value to MTRR_MEMORY_CACHE_TYPE.\r
\r
- @param MtrrType MTRR memory type\r
+ @param[in] MtrrType MTRR memory type\r
\r
@return The enum item in MTRR_MEMORY_CACHE_TYPE\r
\r
default:\r
//\r
// MtrrType is MTRR_CACHE_INVALID_TYPE, that means\r
- // no mtrr covers the range\r
+ // no MTRR covers the range\r
//\r
return MtrrGetDefaultMemoryType ();\r
}\r
\r
This function initializes the valid bits mask and valid address mask for MTRRs.\r
\r
- @param MtrrValidBitsMask The mask for the valid bit of the MTRR\r
- @param MtrrValidAddressMask The valid address mask for the MTRR\r
+ @param[out] MtrrValidBitsMask The mask for the valid bit of the MTRR\r
+ @param[out] MtrrValidAddressMask The valid address mask for the MTRR\r
\r
**/\r
VOID\r
\r
\r
/**\r
- Determing the real attribute of a memory range.\r
+ Determines the real attribute of a memory range.\r
\r
This function is to arbitrate the real attribute of the memory when\r
- there are 2 MTRR covers the same memory range. For further details,\r
+ there are 2 MTRRs covers the same memory range. For further details,\r
please refer the IA32 Software Developer's Manual, Volume 3,\r
Section 10.11.4.1.\r
\r
- @param MtrrType1 the first kind of Memory type\r
- @param MtrrType2 the second kind of memory type\r
+ @param[in] MtrrType1 The first kind of Memory type\r
+ @param[in] MtrrType2 The second kind of memory type\r
\r
**/\r
UINT64\r
MtrrPrecedence (\r
- UINT64 MtrrType1,\r
- UINT64 MtrrType2\r
+ IN UINT64 MtrrType1,\r
+ IN UINT64 MtrrType2\r
)\r
{\r
UINT64 MtrrType;\r
/**\r
This function attempts to set the attributes for a memory range.\r
\r
- @param BaseAddress The physical address that is the start\r
- address of a memory region.\r
- @param Length The size in bytes of the memory region.\r
- @param Attributes The bit mask of attributes to set for the\r
- memory region.\r
+ @param[in] BaseAddress The physical address that is the start\r
+ address of a memory region.\r
+ @param[in] Length The size in bytes of the memory region.\r
+ @param[in] Attribute The bit mask of attributes to set for the\r
+ memory region.\r
\r
@retval RETURN_SUCCESS The attributes were set for the memory\r
region.\r
\r
This function is mainly for debug purpose.\r
\r
- @param Address The specific address\r
+ @param[in] Address The specific address\r
\r
- @return Memory cache type of the sepcific address\r
+ @return Memory cache type of the specific address\r
\r
**/\r
MTRR_MEMORY_CACHE_TYPE\r
/**\r
This function will get the raw value in variable MTRRs\r
\r
- @param VariableSettings A buffer to hold variable MTRRs content.\r
+ @param[out] FixedSettings A buffer to hold fixed MTRRs content.\r
\r
@return The VariableSettings input pointer\r
\r
/**\r
Worker function setting variable MTRRs\r
\r
- @param VariableSettings A buffer to hold variable MTRRs content.\r
+ @param[in] VariableSettings A buffer to hold variable MTRRs content.\r
\r
**/\r
VOID\r
/**\r
This function sets variable MTRRs\r
\r
- @param VariableSettings A buffer to hold variable MTRRs content.\r
+ @param[in] VariableSettings A buffer to hold variable MTRRs content.\r
\r
@return The pointer of VariableSettings\r
\r
/**\r
This function gets the content in fixed MTRRs\r
\r
- @param FixedSettings A buffer to hold fixed Mtrrs content.\r
+ @param[out] FixedSettings A buffer to hold fixed Mtrrs content.\r
\r
@retval The pointer of FixedSettings\r
\r
/**\r
Worker function setting fixed MTRRs\r
\r
- @param FixedSettings A buffer to hold fixed Mtrrs content.\r
+ @param[in] FixedSettings A buffer to hold fixed Mtrrs content.\r
\r
**/\r
VOID\r
/**\r
This function sets fixed MTRRs\r
\r
- @param FixedSettings A buffer to hold fixed Mtrrs content.\r
+ @param[in] FixedSettings A buffer to hold fixed Mtrrs content.\r
\r
@retval The pointer of FixedSettings\r
\r
/**\r
This function gets the content in all MTRRs (variable and fixed)\r
\r
- @param MtrrSetting A buffer to hold all Mtrrs content.\r
+ @param[out] MtrrSetting A buffer to hold all Mtrrs content.\r
\r
@retval the pointer of MtrrSetting\r
\r
/**\r
This function sets all MTRRs (variable and fixed)\r
\r
- @param MtrrSetting A buffer holding all MTRRs content.\r
+ @param[in] MtrrSetting A buffer holding all MTRRs content.\r
\r
@retval The pointer of MtrrSetting\r
\r
\r
DEBUG((DEBUG_CACHE, "MTRR Settings\n"));\r
DEBUG((DEBUG_CACHE, "=============\n"));\r
- \r
+\r
MtrrGetAllMtrrs (&MtrrSettings);\r
DEBUG((DEBUG_CACHE, "MTRR Default Type: %016lx\n", MtrrSettings.MtrrDefType));\r
for (Index = 0; Index < MTRR_NUMBER_OF_FIXED_MTRR; Index++) {\r
MemoryType = (UINTN)(RShiftU64 (MtrrSettings.Fixed.Mtrr[Index], Index1 * 8) & 0xff);\r
if (MemoryType > CacheWriteBack) {\r
MemoryType = MTRR_CACHE_INVALID_TYPE;\r
- } \r
+ }\r
if (MemoryType != PreviousMemoryType) {\r
if (PreviousMemoryType != MTRR_CACHE_INVALID_TYPE) {\r
DEBUG((DEBUG_CACHE, "%016lx\n", Base - 1));\r
PreviousMemoryType = MemoryType;\r
DEBUG((DEBUG_CACHE, "%a:%016lx-", mMtrrMemoryCacheTypeShortName[MemoryType], Base));\r
}\r
- \r
- RangeBase = BASE_1MB; \r
+\r
+ RangeBase = BASE_1MB;\r
NoRangeBase = BASE_1MB;\r
RangeLimit = Limit;\r
NoRangeLimit = Limit;\r
- \r
+\r
for (Index = 0, Found = FALSE; Index < VariableMtrrCount; Index++) {\r
if ((MtrrSettings.Variables.Mtrr[Index].Mask & BIT11) == 0) {\r
//\r
if (Base >= MtrrBase && Base < MtrrLimit) {\r
Found = TRUE;\r
}\r
- \r
+\r
if (Base >= MtrrBase && MtrrBase > RangeBase) {\r
RangeBase = MtrrBase;\r
}\r
if (Base < MtrrLimit && MtrrLimit <= RangeLimit) {\r
RangeLimit = MtrrLimit;\r
}\r
- \r
+\r
if (Base > MtrrLimit && NoRangeBase < MtrrLimit) {\r
NoRangeBase = MtrrLimit + 1;\r
}\r
NoRangeLimit = MtrrBase - 1;\r
}\r
}\r
- \r
+\r
if (Found) {\r
Base = RangeLimit + 1;\r
} else {\r