2. Invoke MtrrGetDefaultMemoryType() to get the default memory type instead of the hard code value in module.
3. Add go though for UC attributes.
Signed-off-by: vanjeff
Reviewed-by: rsun3
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12587
6f19259b-4bc3-4df7-8a09-
765794883524
BOOLEAN InterruptState = FALSE;\r
EFI_HANDLE mCpuHandle = NULL;\r
BOOLEAN mIsFlushingGCD;\r
BOOLEAN InterruptState = FALSE;\r
EFI_HANDLE mCpuHandle = NULL;\r
BOOLEAN mIsFlushingGCD;\r
-UINT8 mDefaultMemoryType = MTRR_CACHE_WRITE_BACK;\r
UINT64 mValidMtrrAddressMask = MTRR_LIB_CACHE_VALID_ADDRESS;\r
UINT64 mValidMtrrBitsMask = MTRR_LIB_MSR_VALID_MASK;\r
\r
UINT64 mValidMtrrAddressMask = MTRR_LIB_CACHE_VALID_ADDRESS;\r
UINT64 mValidMtrrBitsMask = MTRR_LIB_MSR_VALID_MASK;\r
\r
**/\r
UINT64\r
GetMemorySpaceAttributeFromMtrrType (\r
**/\r
UINT64\r
GetMemorySpaceAttributeFromMtrrType (\r
- IN UINT8 MtrrAttributes\r
+ IN MTRR_MEMORY_CACHE_TYPE MtrrAttributes\r
)\r
{\r
switch (MtrrAttributes) {\r
)\r
{\r
switch (MtrrAttributes) {\r
UINT64 Length;\r
UINT64 Attributes;\r
UINT64 CurrentAttributes;\r
UINT64 Length;\r
UINT64 Attributes;\r
UINT64 CurrentAttributes;\r
+ MTRR_MEMORY_CACHE_TYPE MtrrType;\r
UINTN NumberOfDescriptors;\r
EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMap;\r
UINT64 DefaultAttributes;\r
VARIABLE_MTRR VariableMtrr[MTRR_NUMBER_OF_VARIABLE_MTRR];\r
MTRR_FIXED_SETTINGS MtrrFixedSettings;\r
UINT32 FirmwareVariableMtrrCount;\r
UINTN NumberOfDescriptors;\r
EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMap;\r
UINT64 DefaultAttributes;\r
VARIABLE_MTRR VariableMtrr[MTRR_NUMBER_OF_VARIABLE_MTRR];\r
MTRR_FIXED_SETTINGS MtrrFixedSettings;\r
UINT32 FirmwareVariableMtrrCount;\r
+ MTRR_MEMORY_CACHE_TYPE DefaultMemoryType;\r
\r
if (!IsMtrrSupported ()) {\r
return;\r
\r
if (!IsMtrrSupported ()) {\r
return;\r
FirmwareVariableMtrrCount = GetFirmwareVariableMtrrCount ();\r
ASSERT (FirmwareVariableMtrrCount <= MTRR_NUMBER_OF_VARIABLE_MTRR);\r
\r
FirmwareVariableMtrrCount = GetFirmwareVariableMtrrCount ();\r
ASSERT (FirmwareVariableMtrrCount <= MTRR_NUMBER_OF_VARIABLE_MTRR);\r
\r
-// mIsFlushingGCD = TRUE;\r
- mIsFlushingGCD = FALSE;\r
+ mIsFlushingGCD = TRUE;\r
MemorySpaceMap = NULL;\r
\r
//\r
MemorySpaceMap = NULL;\r
\r
//\r
);\r
ASSERT_EFI_ERROR (Status);\r
\r
);\r
ASSERT_EFI_ERROR (Status);\r
\r
- DefaultAttributes = GetMemorySpaceAttributeFromMtrrType (mDefaultMemoryType);\r
+ DefaultMemoryType = MtrrGetDefaultMemoryType ();\r
+ DefaultAttributes = GetMemorySpaceAttributeFromMtrrType (DefaultMemoryType);\r
\r
//\r
// Set default attributes to all spaces.\r
\r
//\r
// Set default attributes to all spaces.\r
- // Go for variable MTRRs with Non-WB attribute\r
+ // Go for variable MTRRs with the attribute except for WB and UC attributes\r
//\r
for (Index = 0; Index < FirmwareVariableMtrrCount; Index++) {\r
//\r
for (Index = 0; Index < FirmwareVariableMtrrCount; Index++) {\r
- if (VariableMtrr[Index].Valid &&\r
- VariableMtrr[Index].Type != MTRR_CACHE_WRITE_BACK) {\r
- Attributes = GetMemorySpaceAttributeFromMtrrType ((UINT8) VariableMtrr[Index].Type);\r
+ if (VariableMtrr[Index].Valid && \r
+ VariableMtrr[Index].Type != MTRR_CACHE_WRITE_BACK &&\r
+ VariableMtrr[Index].Type != MTRR_CACHE_UNCACHEABLE) {\r
+ Attributes = GetMemorySpaceAttributeFromMtrrType ((MTRR_MEMORY_CACHE_TYPE) VariableMtrr[Index].Type);\r
SetGcdMemorySpaceAttributes (\r
MemorySpaceMap,\r
NumberOfDescriptors,\r
SetGcdMemorySpaceAttributes (\r
MemorySpaceMap,\r
NumberOfDescriptors,\r
+ //\r
+ // Go for variable MTRRs with UC attribute\r
+ //\r
+ for (Index = 0; Index < FirmwareVariableMtrrCount; Index++) {\r
+ if (VariableMtrr[Index].Valid &&\r
+ VariableMtrr[Index].Type == MTRR_CACHE_UNCACHEABLE) {\r
+ SetGcdMemorySpaceAttributes (\r
+ MemorySpaceMap,\r
+ NumberOfDescriptors,\r
+ VariableMtrr[Index].BaseAddress,\r
+ VariableMtrr[Index].Length,\r
+ EFI_MEMORY_UC\r
+ );\r
+ }\r
+ }\r
+\r
//\r
// Go for fixed MTRRs\r
//\r
//\r
// Go for fixed MTRRs\r
//\r
// Check for continuous fixed MTRR sections\r
//\r
for (SubIndex = 0; SubIndex < 8; SubIndex++) {\r
// Check for continuous fixed MTRR sections\r
//\r
for (SubIndex = 0; SubIndex < 8; SubIndex++) {\r
- MtrrType = (UINT8) RShiftU64 (RegValue, SubIndex * 8);\r
+ MtrrType = (MTRR_MEMORY_CACHE_TYPE) RShiftU64 (RegValue, SubIndex * 8);\r
CurrentAttributes = GetMemorySpaceAttributeFromMtrrType (MtrrType);\r
if (Length == 0) {\r
//\r
CurrentAttributes = GetMemorySpaceAttributeFromMtrrType (MtrrType);\r
if (Length == 0) {\r
//\r
/** @file\r
MTRR setting library\r
\r
/** @file\r
MTRR setting library\r
\r
- Copyright (c) 2008 - 2010, Intel Corporation. All rights reserved.<BR>\r
+ Copyright (c) 2008 - 2011, Intel Corporation. All rights reserved.<BR>\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
+/**\r
+ Returns the default MTRR cache type for the system.\r
+\r
+ @return The default MTRR cache type.\r
+\r
+**/\r
+MTRR_MEMORY_CACHE_TYPE\r
+EFIAPI\r
+MtrrGetDefaultMemoryType (\r
+ VOID\r
+ );\r
+\r
/**\r
Returns the default MTRR cache type for the system.\r
\r
/**\r
Returns the default MTRR cache type for the system.\r
\r
- @return MTRR default type\r
+ @return The default MTRR cache type.\r
-UINT64\r
-GetMtrrDefaultMemoryType (\r
+MTRR_MEMORY_CACHE_TYPE\r
+EFIAPI\r
+MtrrGetDefaultMemoryType (\r
- return (AsmReadMsr64 (MTRR_LIB_IA32_MTRR_DEF_TYPE) & 0xff);\r
-}\r
+ if (!IsMtrrSupported ()) {\r
+ return CacheUncacheable;\r
+ }\r
+ return (MTRR_MEMORY_CACHE_TYPE) (AsmReadMsr64 (MTRR_LIB_IA32_MTRR_DEF_TYPE) & 0x7);\r
+}\r
\r
/**\r
Preparation before programming MTRR.\r
\r
/**\r
Preparation before programming MTRR.\r
// The memory type is the same with the type specified by\r
// MTRR_LIB_IA32_MTRR_DEF_TYPE.\r
//\r
// The memory type is the same with the type specified by\r
// MTRR_LIB_IA32_MTRR_DEF_TYPE.\r
//\r
- if ((!OverwriteExistingMtrr) && (Attribute == GetMtrrDefaultMemoryType ())) {\r
+ if ((!OverwriteExistingMtrr) && (Attribute == MtrrGetDefaultMemoryType ())) {\r
//\r
// Invalidate the now-unused MTRRs\r
//\r
//\r
// Invalidate the now-unused MTRRs\r
//\r