mirror of
https://github.com/acidanthera/audk.git
synced 2025-07-31 01:24:12 +02:00
UefiCpuPkg/MtrrLib: Add worker functions to access MTRRs or variable
Add worker functions that could access MTRRs or MTRR settings in input buffer. Cc: Feng Tian <feng.tian@intel.com> Cc: Michael Kinney <michael.d.kinney@intel.com> Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Michael Kinney <michael.d.kinney@intel.com> Signed-off-by: Jeff Fan <jeff.fan@intel.com> Reviewed-by: Feng Tian <feng.tian@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@19160 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
e518b80d80
commit
5abd5ed4c4
@ -183,15 +183,25 @@ GetFirmwareVariableMtrrCount (
|
|||||||
/**
|
/**
|
||||||
Worker function returns the default MTRR cache type for the system.
|
Worker function returns the default MTRR cache type for the system.
|
||||||
|
|
||||||
|
If MtrrSetting is not NULL, returns the default MTRR cache type from input
|
||||||
|
MTRR settings buffer.
|
||||||
|
If MtrrSetting is NULL, returns the default MTRR cache type from MSR.
|
||||||
|
|
||||||
|
@param[in] MtrrSetting A buffer holding all MTRRs content.
|
||||||
|
|
||||||
@return The default MTRR cache type.
|
@return The default MTRR cache type.
|
||||||
|
|
||||||
**/
|
**/
|
||||||
MTRR_MEMORY_CACHE_TYPE
|
MTRR_MEMORY_CACHE_TYPE
|
||||||
MtrrGetDefaultMemoryTypeWorker (
|
MtrrGetDefaultMemoryTypeWorker (
|
||||||
VOID
|
IN MTRR_SETTINGS *MtrrSetting
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return (MTRR_MEMORY_CACHE_TYPE) (AsmReadMsr64 (MTRR_LIB_IA32_MTRR_DEF_TYPE) & 0x7);
|
if (MtrrSetting == NULL) {
|
||||||
|
return (MTRR_MEMORY_CACHE_TYPE) (AsmReadMsr64 (MTRR_LIB_IA32_MTRR_DEF_TYPE) & 0x7);
|
||||||
|
} else {
|
||||||
|
return (MTRR_MEMORY_CACHE_TYPE) (MtrrSetting->MtrrDefType & 0x7);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -210,7 +220,7 @@ MtrrGetDefaultMemoryType (
|
|||||||
if (!IsMtrrSupported ()) {
|
if (!IsMtrrSupported ()) {
|
||||||
return CacheUncacheable;
|
return CacheUncacheable;
|
||||||
}
|
}
|
||||||
return MtrrGetDefaultMemoryTypeWorker ();
|
return MtrrGetDefaultMemoryTypeWorker (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -360,6 +370,12 @@ MtrrGetFixedMtrr (
|
|||||||
/**
|
/**
|
||||||
Worker function will get the raw value in variable MTRRs
|
Worker function will get the raw value in variable MTRRs
|
||||||
|
|
||||||
|
If MtrrSetting is not NULL, gets the variable MTRRs raw value from input
|
||||||
|
MTRR settings buffer.
|
||||||
|
If MtrrSetting is NULL, gets the variable MTRRs raw value from MTRRs.
|
||||||
|
|
||||||
|
@param[in] MtrrSetting A buffer holding all MTRRs content.
|
||||||
|
@param[in] VariableMtrrCount Number of variable MTRRs.
|
||||||
@param[out] VariableSettings A buffer to hold variable MTRRs content.
|
@param[out] VariableSettings A buffer to hold variable MTRRs content.
|
||||||
|
|
||||||
@return The VariableSettings input pointer
|
@return The VariableSettings input pointer
|
||||||
@ -367,6 +383,7 @@ MtrrGetFixedMtrr (
|
|||||||
**/
|
**/
|
||||||
MTRR_VARIABLE_SETTINGS*
|
MTRR_VARIABLE_SETTINGS*
|
||||||
MtrrGetVariableMtrrWorker (
|
MtrrGetVariableMtrrWorker (
|
||||||
|
IN MTRR_SETTINGS *MtrrSetting,
|
||||||
IN UINT32 VariableMtrrCount,
|
IN UINT32 VariableMtrrCount,
|
||||||
OUT MTRR_VARIABLE_SETTINGS *VariableSettings
|
OUT MTRR_VARIABLE_SETTINGS *VariableSettings
|
||||||
)
|
)
|
||||||
@ -376,10 +393,15 @@ MtrrGetVariableMtrrWorker (
|
|||||||
ASSERT (VariableMtrrCount <= MTRR_NUMBER_OF_VARIABLE_MTRR);
|
ASSERT (VariableMtrrCount <= MTRR_NUMBER_OF_VARIABLE_MTRR);
|
||||||
|
|
||||||
for (Index = 0; Index < VariableMtrrCount; Index++) {
|
for (Index = 0; Index < VariableMtrrCount; Index++) {
|
||||||
VariableSettings->Mtrr[Index].Base =
|
if (MtrrSetting == NULL) {
|
||||||
AsmReadMsr64 (MTRR_LIB_IA32_VARIABLE_MTRR_BASE + (Index << 1));
|
VariableSettings->Mtrr[Index].Base =
|
||||||
VariableSettings->Mtrr[Index].Mask =
|
AsmReadMsr64 (MTRR_LIB_IA32_VARIABLE_MTRR_BASE + (Index << 1));
|
||||||
AsmReadMsr64 (MTRR_LIB_IA32_VARIABLE_MTRR_BASE + (Index << 1) + 1);
|
VariableSettings->Mtrr[Index].Mask =
|
||||||
|
AsmReadMsr64 (MTRR_LIB_IA32_VARIABLE_MTRR_BASE + (Index << 1) + 1);
|
||||||
|
} else {
|
||||||
|
VariableSettings->Mtrr[Index].Base = MtrrSetting->Variables.Mtrr[Index].Base;
|
||||||
|
VariableSettings->Mtrr[Index].Mask = MtrrSetting->Variables.Mtrr[Index].Mask;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return VariableSettings;
|
return VariableSettings;
|
||||||
@ -404,6 +426,7 @@ MtrrGetVariableMtrr (
|
|||||||
}
|
}
|
||||||
|
|
||||||
return MtrrGetVariableMtrrWorker (
|
return MtrrGetVariableMtrrWorker (
|
||||||
|
NULL,
|
||||||
GetVariableMtrrCountWorker (),
|
GetVariableMtrrCountWorker (),
|
||||||
VariableSettings
|
VariableSettings
|
||||||
);
|
);
|
||||||
@ -575,6 +598,7 @@ MtrrGetMemoryAttributeInVariableMtrr (
|
|||||||
}
|
}
|
||||||
|
|
||||||
MtrrGetVariableMtrrWorker (
|
MtrrGetVariableMtrrWorker (
|
||||||
|
NULL,
|
||||||
GetVariableMtrrCountWorker (),
|
GetVariableMtrrCountWorker (),
|
||||||
&VariableSettings
|
&VariableSettings
|
||||||
);
|
);
|
||||||
@ -949,6 +973,11 @@ ProgramVariableMtrr (
|
|||||||
/**
|
/**
|
||||||
Converts the Memory attribute value to MTRR_MEMORY_CACHE_TYPE.
|
Converts the Memory attribute value to MTRR_MEMORY_CACHE_TYPE.
|
||||||
|
|
||||||
|
If MtrrSetting is not NULL, gets the default memory attribute from input
|
||||||
|
MTRR settings buffer.
|
||||||
|
If MtrrSetting is NULL, gets the default memory attribute from MSR.
|
||||||
|
|
||||||
|
@param[in] MtrrSetting A buffer holding all MTRRs content.
|
||||||
@param[in] MtrrType MTRR memory type
|
@param[in] MtrrType MTRR memory type
|
||||||
|
|
||||||
@return The enum item in MTRR_MEMORY_CACHE_TYPE
|
@return The enum item in MTRR_MEMORY_CACHE_TYPE
|
||||||
@ -956,6 +985,7 @@ ProgramVariableMtrr (
|
|||||||
**/
|
**/
|
||||||
MTRR_MEMORY_CACHE_TYPE
|
MTRR_MEMORY_CACHE_TYPE
|
||||||
GetMemoryCacheTypeFromMtrrType (
|
GetMemoryCacheTypeFromMtrrType (
|
||||||
|
IN MTRR_SETTINGS *MtrrSetting,
|
||||||
IN UINT64 MtrrType
|
IN UINT64 MtrrType
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@ -975,7 +1005,7 @@ GetMemoryCacheTypeFromMtrrType (
|
|||||||
// MtrrType is MTRR_CACHE_INVALID_TYPE, that means
|
// MtrrType is MTRR_CACHE_INVALID_TYPE, that means
|
||||||
// no MTRR covers the range
|
// no MTRR covers the range
|
||||||
//
|
//
|
||||||
return MtrrGetDefaultMemoryType ();
|
return MtrrGetDefaultMemoryTypeWorker (MtrrSetting);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1084,21 +1114,22 @@ MtrrPrecedence (
|
|||||||
return MtrrType;
|
return MtrrType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
This function will get the memory cache type of the specific address.
|
Worker function will get the memory cache type of the specific address.
|
||||||
|
|
||||||
This function is mainly for debug purpose.
|
If MtrrSetting is not NULL, gets the memory cache type from input
|
||||||
|
MTRR settings buffer.
|
||||||
|
If MtrrSetting is NULL, gets the memory cache type from MTRRs.
|
||||||
|
|
||||||
|
@param[in] MtrrSetting A buffer holding all MTRRs content.
|
||||||
@param[in] Address The specific address
|
@param[in] Address The specific address
|
||||||
|
|
||||||
@return Memory cache type of the specific address
|
@return Memory cache type of the specific address
|
||||||
|
|
||||||
**/
|
**/
|
||||||
MTRR_MEMORY_CACHE_TYPE
|
MTRR_MEMORY_CACHE_TYPE
|
||||||
EFIAPI
|
MtrrGetMemoryAttributeByAddressWorker (
|
||||||
MtrrGetMemoryAttribute (
|
IN MTRR_SETTINGS *MtrrSetting,
|
||||||
IN PHYSICAL_ADDRESS Address
|
IN PHYSICAL_ADDRESS Address
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@ -1114,14 +1145,14 @@ MtrrGetMemoryAttribute (
|
|||||||
UINTN VariableMtrrCount;
|
UINTN VariableMtrrCount;
|
||||||
MTRR_VARIABLE_SETTINGS VariableSettings;
|
MTRR_VARIABLE_SETTINGS VariableSettings;
|
||||||
|
|
||||||
if (!IsMtrrSupported ()) {
|
|
||||||
return CacheUncacheable;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Check if MTRR is enabled, if not, return UC as attribute
|
// Check if MTRR is enabled, if not, return UC as attribute
|
||||||
//
|
//
|
||||||
TempQword = AsmReadMsr64 (MTRR_LIB_IA32_MTRR_DEF_TYPE);
|
if (MtrrSetting == NULL) {
|
||||||
|
TempQword = AsmReadMsr64 (MTRR_LIB_IA32_MTRR_DEF_TYPE);
|
||||||
|
} else {
|
||||||
|
TempQword = MtrrSetting->MtrrDefType;
|
||||||
|
}
|
||||||
MtrrType = MTRR_CACHE_INVALID_TYPE;
|
MtrrType = MTRR_CACHE_INVALID_TYPE;
|
||||||
|
|
||||||
if ((TempQword & MTRR_LIB_CACHE_MTRR_ENABLED) == 0) {
|
if ((TempQword & MTRR_LIB_CACHE_MTRR_ENABLED) == 0) {
|
||||||
@ -1146,9 +1177,13 @@ MtrrGetMemoryAttribute (
|
|||||||
SubIndex =
|
SubIndex =
|
||||||
((UINTN)Address - mMtrrLibFixedMtrrTable[Index].BaseAddress) /
|
((UINTN)Address - mMtrrLibFixedMtrrTable[Index].BaseAddress) /
|
||||||
mMtrrLibFixedMtrrTable[Index].Length;
|
mMtrrLibFixedMtrrTable[Index].Length;
|
||||||
TempQword = AsmReadMsr64 (mMtrrLibFixedMtrrTable[Index].Msr);
|
if (MtrrSetting == NULL) {
|
||||||
|
TempQword = AsmReadMsr64 (mMtrrLibFixedMtrrTable[Index].Msr);
|
||||||
|
} else {
|
||||||
|
TempQword = MtrrSetting->Fixed.Mtrr[Index];
|
||||||
|
}
|
||||||
MtrrType = RShiftU64 (TempQword, SubIndex * 8) & 0xFF;
|
MtrrType = RShiftU64 (TempQword, SubIndex * 8) & 0xFF;
|
||||||
return GetMemoryCacheTypeFromMtrrType (MtrrType);
|
return GetMemoryCacheTypeFromMtrrType (MtrrSetting, MtrrType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1156,6 +1191,7 @@ MtrrGetMemoryAttribute (
|
|||||||
MtrrLibInitializeMtrrMask(&MtrrValidBitsMask, &MtrrValidAddressMask);
|
MtrrLibInitializeMtrrMask(&MtrrValidBitsMask, &MtrrValidAddressMask);
|
||||||
|
|
||||||
MtrrGetVariableMtrrWorker (
|
MtrrGetVariableMtrrWorker (
|
||||||
|
MtrrSetting,
|
||||||
GetVariableMtrrCountWorker (),
|
GetVariableMtrrCountWorker (),
|
||||||
&VariableSettings
|
&VariableSettings
|
||||||
);
|
);
|
||||||
@ -1183,12 +1219,35 @@ MtrrGetMemoryAttribute (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CacheType = GetMemoryCacheTypeFromMtrrType (MtrrType);
|
CacheType = GetMemoryCacheTypeFromMtrrType (MtrrSetting, MtrrType);
|
||||||
|
|
||||||
return CacheType;
|
return CacheType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
This function will get the memory cache type of the specific address.
|
||||||
|
|
||||||
|
This function is mainly for debug purpose.
|
||||||
|
|
||||||
|
@param[in] Address The specific address
|
||||||
|
|
||||||
|
@return Memory cache type of the specific address
|
||||||
|
|
||||||
|
**/
|
||||||
|
MTRR_MEMORY_CACHE_TYPE
|
||||||
|
EFIAPI
|
||||||
|
MtrrGetMemoryAttribute (
|
||||||
|
IN PHYSICAL_ADDRESS Address
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if (!IsMtrrSupported ()) {
|
||||||
|
return CacheUncacheable;
|
||||||
|
}
|
||||||
|
|
||||||
|
return MtrrGetMemoryAttributeByAddressWorker (NULL, Address);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
This function prints all MTRRs for debugging.
|
This function prints all MTRRs for debugging.
|
||||||
@ -1479,7 +1538,7 @@ MtrrSetMemoryAttribute (
|
|||||||
//
|
//
|
||||||
VariableMtrrCount = GetVariableMtrrCountWorker ();
|
VariableMtrrCount = GetVariableMtrrCountWorker ();
|
||||||
FirmwareVariableMtrrCount = GetFirmwareVariableMtrrCountWorker ();
|
FirmwareVariableMtrrCount = GetFirmwareVariableMtrrCountWorker ();
|
||||||
MtrrGetVariableMtrrWorker (VariableMtrrCount, &OriginalVariableSettings);
|
MtrrGetVariableMtrrWorker (NULL, VariableMtrrCount, &OriginalVariableSettings);
|
||||||
CopyMem (&WorkingVariableSettings, &OriginalVariableSettings, sizeof (WorkingVariableSettings));
|
CopyMem (&WorkingVariableSettings, &OriginalVariableSettings, sizeof (WorkingVariableSettings));
|
||||||
ProgramVariableSettings = TRUE;
|
ProgramVariableSettings = TRUE;
|
||||||
VariableSettings = &WorkingVariableSettings;
|
VariableSettings = &WorkingVariableSettings;
|
||||||
@ -1839,6 +1898,7 @@ MtrrGetAllMtrrs (
|
|||||||
// Get variable MTRRs
|
// Get variable MTRRs
|
||||||
//
|
//
|
||||||
MtrrGetVariableMtrrWorker (
|
MtrrGetVariableMtrrWorker (
|
||||||
|
NULL,
|
||||||
GetVariableMtrrCountWorker (),
|
GetVariableMtrrCountWorker (),
|
||||||
&MtrrSetting->Variables
|
&MtrrSetting->Variables
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user