mirror of https://github.com/acidanthera/audk.git
UefiCpuPkg/MtrrLib: Add worker functions not invoke IsMtrrSupported()
Abstract some worker functions not to invoke IsMtrrSupported(). They could be used by other functions to reduce the number of invoking times on IsMtrrSupported(). 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@19153 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
76b4cae357
commit
31b3597ee2
|
@ -103,6 +103,24 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *mMtrrMemoryCacheTypeShortName[] = {
|
||||||
"R*" // Invalid
|
"R*" // Invalid
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
Worker function returns the variable MTRR count for the CPU.
|
||||||
|
|
||||||
|
@return Variable MTRR count
|
||||||
|
|
||||||
|
**/
|
||||||
|
UINT32
|
||||||
|
GetVariableMtrrCountWorker (
|
||||||
|
VOID
|
||||||
|
)
|
||||||
|
{
|
||||||
|
UINT32 VariableMtrrCount;
|
||||||
|
|
||||||
|
VariableMtrrCount = (UINT32)(AsmReadMsr64 (MTRR_LIB_IA32_MTRR_CAP) & MTRR_LIB_IA32_MTRR_CAP_VCNT_MASK);
|
||||||
|
ASSERT (VariableMtrrCount <= MTRR_NUMBER_OF_VARIABLE_MTRR);
|
||||||
|
return VariableMtrrCount;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns the variable MTRR count for the CPU.
|
Returns the variable MTRR count for the CPU.
|
||||||
|
|
||||||
|
@ -115,16 +133,33 @@ GetVariableMtrrCount (
|
||||||
VOID
|
VOID
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
UINT32 VariableMtrrCount;
|
|
||||||
|
|
||||||
if (!IsMtrrSupported ()) {
|
if (!IsMtrrSupported ()) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
return GetVariableMtrrCountWorker ();
|
||||||
|
}
|
||||||
|
|
||||||
VariableMtrrCount = (UINT32)(AsmReadMsr64 (MTRR_LIB_IA32_MTRR_CAP) & MTRR_LIB_IA32_MTRR_CAP_VCNT_MASK);
|
/**
|
||||||
ASSERT (VariableMtrrCount <= MTRR_NUMBER_OF_VARIABLE_MTRR);
|
Worker function returns the firmware usable variable MTRR count for the CPU.
|
||||||
|
|
||||||
return VariableMtrrCount;
|
@return Firmware usable variable MTRR count
|
||||||
|
|
||||||
|
**/
|
||||||
|
UINT32
|
||||||
|
GetFirmwareVariableMtrrCountWorker (
|
||||||
|
VOID
|
||||||
|
)
|
||||||
|
{
|
||||||
|
UINT32 VariableMtrrCount;
|
||||||
|
UINT32 ReservedMtrrNumber;
|
||||||
|
|
||||||
|
VariableMtrrCount = GetVariableMtrrCountWorker ();
|
||||||
|
ReservedMtrrNumber = PcdGet32 (PcdCpuNumberOfReservedVariableMtrrs);
|
||||||
|
if (VariableMtrrCount < ReservedMtrrNumber) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return VariableMtrrCount - ReservedMtrrNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -139,18 +174,27 @@ GetFirmwareVariableMtrrCount (
|
||||||
VOID
|
VOID
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
UINT32 VariableMtrrCount;
|
if (!IsMtrrSupported ()) {
|
||||||
UINT32 ReservedMtrrNumber;
|
|
||||||
|
|
||||||
VariableMtrrCount = GetVariableMtrrCount ();
|
|
||||||
ReservedMtrrNumber = PcdGet32 (PcdCpuNumberOfReservedVariableMtrrs);
|
|
||||||
if (VariableMtrrCount < ReservedMtrrNumber) {
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
return GetFirmwareVariableMtrrCountWorker ();
|
||||||
return VariableMtrrCount - ReservedMtrrNumber;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Worker function returns the default MTRR cache type for the system.
|
||||||
|
|
||||||
|
@return The default MTRR cache type.
|
||||||
|
|
||||||
|
**/
|
||||||
|
MTRR_MEMORY_CACHE_TYPE
|
||||||
|
MtrrGetDefaultMemoryTypeWorker (
|
||||||
|
VOID
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return (MTRR_MEMORY_CACHE_TYPE) (AsmReadMsr64 (MTRR_LIB_IA32_MTRR_DEF_TYPE) & 0x7);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns the default MTRR cache type for the system.
|
Returns the default MTRR cache type for the system.
|
||||||
|
|
||||||
|
@ -166,8 +210,7 @@ MtrrGetDefaultMemoryType (
|
||||||
if (!IsMtrrSupported ()) {
|
if (!IsMtrrSupported ()) {
|
||||||
return CacheUncacheable;
|
return CacheUncacheable;
|
||||||
}
|
}
|
||||||
|
return MtrrGetDefaultMemoryTypeWorker ();
|
||||||
return (MTRR_MEMORY_CACHE_TYPE) (AsmReadMsr64 (MTRR_LIB_IA32_MTRR_DEF_TYPE) & 0x7);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1290,26 +1333,21 @@ MtrrGetMemoryAttribute (
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
This function will get the raw value in variable MTRRs
|
Worker function will get the raw value in variable MTRRs
|
||||||
|
|
||||||
@param[out] FixedSettings A buffer to hold fixed MTRRs content.
|
@param[out] VariableSettings A buffer to hold variable MTRRs content.
|
||||||
|
|
||||||
@return The VariableSettings input pointer
|
@return The VariableSettings input pointer
|
||||||
|
|
||||||
**/
|
**/
|
||||||
MTRR_VARIABLE_SETTINGS*
|
MTRR_VARIABLE_SETTINGS*
|
||||||
EFIAPI
|
MtrrGetVariableMtrrWorker (
|
||||||
MtrrGetVariableMtrr (
|
OUT MTRR_VARIABLE_SETTINGS *VariableSettings
|
||||||
OUT MTRR_VARIABLE_SETTINGS *VariableSettings
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
UINT32 Index;
|
UINT32 Index;
|
||||||
UINT32 VariableMtrrCount;
|
UINT32 VariableMtrrCount;
|
||||||
|
|
||||||
if (!IsMtrrSupported ()) {
|
|
||||||
return VariableSettings;
|
|
||||||
}
|
|
||||||
|
|
||||||
VariableMtrrCount = GetVariableMtrrCount ();
|
VariableMtrrCount = GetVariableMtrrCount ();
|
||||||
ASSERT (VariableMtrrCount <= MTRR_NUMBER_OF_VARIABLE_MTRR);
|
ASSERT (VariableMtrrCount <= MTRR_NUMBER_OF_VARIABLE_MTRR);
|
||||||
|
|
||||||
|
@ -1323,6 +1361,29 @@ MtrrGetVariableMtrr (
|
||||||
return VariableSettings;
|
return VariableSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
This function will get the raw value in variable MTRRs
|
||||||
|
|
||||||
|
@param[out] VariableSettings A buffer to hold variable MTRRs content.
|
||||||
|
|
||||||
|
@return The VariableSettings input pointer
|
||||||
|
|
||||||
|
**/
|
||||||
|
MTRR_VARIABLE_SETTINGS*
|
||||||
|
EFIAPI
|
||||||
|
MtrrGetVariableMtrr (
|
||||||
|
OUT MTRR_VARIABLE_SETTINGS *VariableSettings
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if (!IsMtrrSupported ()) {
|
||||||
|
return VariableSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
return MtrrGetVariableMtrrWorker (
|
||||||
|
VariableSettings
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Worker function setting variable MTRRs
|
Worker function setting variable MTRRs
|
||||||
|
@ -1380,11 +1441,34 @@ MtrrSetVariableMtrr (
|
||||||
return VariableSettings;
|
return VariableSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Worker function gets the content in fixed MTRRs
|
||||||
|
|
||||||
|
@param[out] FixedSettings A buffer to hold fixed MTRRs content.
|
||||||
|
|
||||||
|
@retval The pointer of FixedSettings
|
||||||
|
|
||||||
|
**/
|
||||||
|
MTRR_FIXED_SETTINGS*
|
||||||
|
MtrrGetFixedMtrrWorker (
|
||||||
|
OUT MTRR_FIXED_SETTINGS *FixedSettings
|
||||||
|
)
|
||||||
|
{
|
||||||
|
UINT32 Index;
|
||||||
|
|
||||||
|
for (Index = 0; Index < MTRR_NUMBER_OF_FIXED_MTRR; Index++) {
|
||||||
|
FixedSettings->Mtrr[Index] =
|
||||||
|
AsmReadMsr64 (mMtrrLibFixedMtrrTable[Index].Msr);
|
||||||
|
}
|
||||||
|
|
||||||
|
return FixedSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
This function gets the content in fixed MTRRs
|
This function gets the content in fixed MTRRs
|
||||||
|
|
||||||
@param[out] FixedSettings A buffer to hold fixed Mtrrs content.
|
@param[out] FixedSettings A buffer to hold fixed MTRRs content.
|
||||||
|
|
||||||
@retval The pointer of FixedSettings
|
@retval The pointer of FixedSettings
|
||||||
|
|
||||||
|
@ -1395,18 +1479,11 @@ MtrrGetFixedMtrr (
|
||||||
OUT MTRR_FIXED_SETTINGS *FixedSettings
|
OUT MTRR_FIXED_SETTINGS *FixedSettings
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
UINT32 Index;
|
|
||||||
|
|
||||||
if (!IsMtrrSupported ()) {
|
if (!IsMtrrSupported ()) {
|
||||||
return FixedSettings;
|
return FixedSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Index = 0; Index < MTRR_NUMBER_OF_FIXED_MTRR; Index++) {
|
return MtrrGetFixedMtrrWorker (FixedSettings);
|
||||||
FixedSettings->Mtrr[Index] =
|
|
||||||
AsmReadMsr64 (mMtrrLibFixedMtrrTable[Index].Msr);
|
|
||||||
};
|
|
||||||
|
|
||||||
return FixedSettings;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue