mirror of https://github.com/acidanthera/audk.git
1. Introduce the API MtrrGetDefaultMemoryType () in Mtrr Library.
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
This commit is contained in:
parent
beda2356f5
commit
91ec78241c
|
@ -23,7 +23,6 @@ EFI_CPU_INTERRUPT_HANDLER ExternalVectorTable[0x100];
|
||||||
BOOLEAN InterruptState = FALSE;
|
BOOLEAN InterruptState = FALSE;
|
||||||
EFI_HANDLE mCpuHandle = NULL;
|
EFI_HANDLE mCpuHandle = NULL;
|
||||||
BOOLEAN mIsFlushingGCD;
|
BOOLEAN mIsFlushingGCD;
|
||||||
UINT8 mDefaultMemoryType = MTRR_CACHE_WRITE_BACK;
|
|
||||||
UINT64 mValidMtrrAddressMask = MTRR_LIB_CACHE_VALID_ADDRESS;
|
UINT64 mValidMtrrAddressMask = MTRR_LIB_CACHE_VALID_ADDRESS;
|
||||||
UINT64 mValidMtrrBitsMask = MTRR_LIB_MSR_VALID_MASK;
|
UINT64 mValidMtrrBitsMask = MTRR_LIB_MSR_VALID_MASK;
|
||||||
|
|
||||||
|
@ -715,7 +714,7 @@ InitializeMtrrMask (
|
||||||
**/
|
**/
|
||||||
UINT64
|
UINT64
|
||||||
GetMemorySpaceAttributeFromMtrrType (
|
GetMemorySpaceAttributeFromMtrrType (
|
||||||
IN UINT8 MtrrAttributes
|
IN MTRR_MEMORY_CACHE_TYPE MtrrAttributes
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
switch (MtrrAttributes) {
|
switch (MtrrAttributes) {
|
||||||
|
@ -880,13 +879,14 @@ RefreshGcdMemoryAttributes (
|
||||||
UINT64 Length;
|
UINT64 Length;
|
||||||
UINT64 Attributes;
|
UINT64 Attributes;
|
||||||
UINT64 CurrentAttributes;
|
UINT64 CurrentAttributes;
|
||||||
UINT8 MtrrType;
|
MTRR_MEMORY_CACHE_TYPE MtrrType;
|
||||||
UINTN NumberOfDescriptors;
|
UINTN NumberOfDescriptors;
|
||||||
EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMap;
|
EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMap;
|
||||||
UINT64 DefaultAttributes;
|
UINT64 DefaultAttributes;
|
||||||
VARIABLE_MTRR VariableMtrr[MTRR_NUMBER_OF_VARIABLE_MTRR];
|
VARIABLE_MTRR VariableMtrr[MTRR_NUMBER_OF_VARIABLE_MTRR];
|
||||||
MTRR_FIXED_SETTINGS MtrrFixedSettings;
|
MTRR_FIXED_SETTINGS MtrrFixedSettings;
|
||||||
UINT32 FirmwareVariableMtrrCount;
|
UINT32 FirmwareVariableMtrrCount;
|
||||||
|
MTRR_MEMORY_CACHE_TYPE DefaultMemoryType;
|
||||||
|
|
||||||
if (!IsMtrrSupported ()) {
|
if (!IsMtrrSupported ()) {
|
||||||
return;
|
return;
|
||||||
|
@ -895,8 +895,7 @@ RefreshGcdMemoryAttributes (
|
||||||
FirmwareVariableMtrrCount = GetFirmwareVariableMtrrCount ();
|
FirmwareVariableMtrrCount = GetFirmwareVariableMtrrCount ();
|
||||||
ASSERT (FirmwareVariableMtrrCount <= MTRR_NUMBER_OF_VARIABLE_MTRR);
|
ASSERT (FirmwareVariableMtrrCount <= MTRR_NUMBER_OF_VARIABLE_MTRR);
|
||||||
|
|
||||||
// mIsFlushingGCD = TRUE;
|
mIsFlushingGCD = TRUE;
|
||||||
mIsFlushingGCD = FALSE;
|
|
||||||
MemorySpaceMap = NULL;
|
MemorySpaceMap = NULL;
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -922,7 +921,8 @@ RefreshGcdMemoryAttributes (
|
||||||
);
|
);
|
||||||
ASSERT_EFI_ERROR (Status);
|
ASSERT_EFI_ERROR (Status);
|
||||||
|
|
||||||
DefaultAttributes = GetMemorySpaceAttributeFromMtrrType (mDefaultMemoryType);
|
DefaultMemoryType = MtrrGetDefaultMemoryType ();
|
||||||
|
DefaultAttributes = GetMemorySpaceAttributeFromMtrrType (DefaultMemoryType);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Set default attributes to all spaces.
|
// Set default attributes to all spaces.
|
||||||
|
@ -954,13 +954,15 @@ RefreshGcdMemoryAttributes (
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Go for variable MTRRs with Non-WB attribute
|
// Go for variable MTRRs with the attribute except for WB and UC attributes
|
||||||
//
|
//
|
||||||
for (Index = 0; Index < FirmwareVariableMtrrCount; Index++) {
|
for (Index = 0; Index < FirmwareVariableMtrrCount; Index++) {
|
||||||
if (VariableMtrr[Index].Valid &&
|
if (VariableMtrr[Index].Valid &&
|
||||||
VariableMtrr[Index].Type != MTRR_CACHE_WRITE_BACK) {
|
VariableMtrr[Index].Type != MTRR_CACHE_WRITE_BACK &&
|
||||||
Attributes = GetMemorySpaceAttributeFromMtrrType ((UINT8) VariableMtrr[Index].Type);
|
VariableMtrr[Index].Type != MTRR_CACHE_UNCACHEABLE) {
|
||||||
|
Attributes = GetMemorySpaceAttributeFromMtrrType ((MTRR_MEMORY_CACHE_TYPE) VariableMtrr[Index].Type);
|
||||||
SetGcdMemorySpaceAttributes (
|
SetGcdMemorySpaceAttributes (
|
||||||
MemorySpaceMap,
|
MemorySpaceMap,
|
||||||
NumberOfDescriptors,
|
NumberOfDescriptors,
|
||||||
|
@ -971,6 +973,22 @@ RefreshGcdMemoryAttributes (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Go for variable MTRRs with UC attribute
|
||||||
|
//
|
||||||
|
for (Index = 0; Index < FirmwareVariableMtrrCount; Index++) {
|
||||||
|
if (VariableMtrr[Index].Valid &&
|
||||||
|
VariableMtrr[Index].Type == MTRR_CACHE_UNCACHEABLE) {
|
||||||
|
SetGcdMemorySpaceAttributes (
|
||||||
|
MemorySpaceMap,
|
||||||
|
NumberOfDescriptors,
|
||||||
|
VariableMtrr[Index].BaseAddress,
|
||||||
|
VariableMtrr[Index].Length,
|
||||||
|
EFI_MEMORY_UC
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Go for fixed MTRRs
|
// Go for fixed MTRRs
|
||||||
//
|
//
|
||||||
|
@ -984,7 +1002,7 @@ RefreshGcdMemoryAttributes (
|
||||||
// Check for continuous fixed MTRR sections
|
// Check for continuous fixed MTRR sections
|
||||||
//
|
//
|
||||||
for (SubIndex = 0; SubIndex < 8; SubIndex++) {
|
for (SubIndex = 0; SubIndex < 8; SubIndex++) {
|
||||||
MtrrType = (UINT8) RShiftU64 (RegValue, SubIndex * 8);
|
MtrrType = (MTRR_MEMORY_CACHE_TYPE) RShiftU64 (RegValue, SubIndex * 8);
|
||||||
CurrentAttributes = GetMemorySpaceAttributeFromMtrrType (MtrrType);
|
CurrentAttributes = GetMemorySpaceAttributeFromMtrrType (MtrrType);
|
||||||
if (Length == 0) {
|
if (Length == 0) {
|
||||||
//
|
//
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/** @file
|
/** @file
|
||||||
MTRR setting library
|
MTRR setting library
|
||||||
|
|
||||||
Copyright (c) 2008 - 2010, Intel Corporation. All rights reserved.<BR>
|
Copyright (c) 2008 - 2011, Intel Corporation. All rights reserved.<BR>
|
||||||
This program and the accompanying materials
|
This program and the accompanying materials
|
||||||
are licensed and made available under the terms and conditions of the BSD License
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
which accompanies this distribution. The full text of the license may be found at
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
@ -331,4 +331,16 @@ IsMtrrSupported (
|
||||||
VOID
|
VOID
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns the default MTRR cache type for the system.
|
||||||
|
|
||||||
|
@return The default MTRR cache type.
|
||||||
|
|
||||||
|
**/
|
||||||
|
MTRR_MEMORY_CACHE_TYPE
|
||||||
|
EFIAPI
|
||||||
|
MtrrGetDefaultMemoryType (
|
||||||
|
VOID
|
||||||
|
);
|
||||||
|
|
||||||
#endif // _MTRR_LIB_H_
|
#endif // _MTRR_LIB_H_
|
||||||
|
|
|
@ -144,17 +144,21 @@ GetFirmwareVariableMtrrCount (
|
||||||
/**
|
/**
|
||||||
Returns the default MTRR cache type for the system.
|
Returns the default MTRR cache type for the system.
|
||||||
|
|
||||||
@return MTRR default type
|
@return The default MTRR cache type.
|
||||||
|
|
||||||
**/
|
**/
|
||||||
UINT64
|
MTRR_MEMORY_CACHE_TYPE
|
||||||
GetMtrrDefaultMemoryType (
|
EFIAPI
|
||||||
|
MtrrGetDefaultMemoryType (
|
||||||
VOID
|
VOID
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return (AsmReadMsr64 (MTRR_LIB_IA32_MTRR_DEF_TYPE) & 0xff);
|
if (!IsMtrrSupported ()) {
|
||||||
|
return CacheUncacheable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return (MTRR_MEMORY_CACHE_TYPE) (AsmReadMsr64 (MTRR_LIB_IA32_MTRR_DEF_TYPE) & 0x7);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Preparation before programming MTRR.
|
Preparation before programming MTRR.
|
||||||
|
@ -1036,7 +1040,7 @@ MtrrSetMemoryAttribute (
|
||||||
// The memory type is the same with the type specified by
|
// The memory type is the same with the type specified by
|
||||||
// MTRR_LIB_IA32_MTRR_DEF_TYPE.
|
// MTRR_LIB_IA32_MTRR_DEF_TYPE.
|
||||||
//
|
//
|
||||||
if ((!OverwriteExistingMtrr) && (Attribute == GetMtrrDefaultMemoryType ())) {
|
if ((!OverwriteExistingMtrr) && (Attribute == MtrrGetDefaultMemoryType ())) {
|
||||||
//
|
//
|
||||||
// Invalidate the now-unused MTRRs
|
// Invalidate the now-unused MTRRs
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in New Issue