summaryrefslogtreecommitdiff
path: root/UefiCpuPkg
diff options
context:
space:
mode:
authorMichael Kinney <michael.d.kinney@intel.com>2015-12-08 05:21:24 +0000
committervanjeff <vanjeff@Edk2>2015-12-08 05:21:24 +0000
commit31b3597ee22c431904476bacd1970fb1cb3f8fc5 (patch)
tree98a77945c821338698787110106f9242fa1dfe94 /UefiCpuPkg
parent76b4cae357dff0f8f1f5cc3ce20675ba20ed2847 (diff)
downloadedk2-31b3597ee22c431904476bacd1970fb1cb3f8fc5.zip
edk2-31b3597ee22c431904476bacd1970fb1cb3f8fc5.tar.gz
edk2-31b3597ee22c431904476bacd1970fb1cb3f8fc5.tar.bz2
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
Diffstat (limited to 'UefiCpuPkg')
-rw-r--r--UefiCpuPkg/Library/MtrrLib/MtrrLib.c139
1 files changed, 108 insertions, 31 deletions
diff --git a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c
index 1584ae2..b1c12aa 100644
--- a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c
+++ b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c
@@ -104,6 +104,24 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *mMtrrMemoryCacheTypeShortName[] = {
};
/**
+ 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.
@return Variable MTRR count
@@ -115,34 +133,27 @@ GetVariableMtrrCount (
VOID
)
{
- UINT32 VariableMtrrCount;
-
if (!IsMtrrSupported ()) {
return 0;
}
-
- VariableMtrrCount = (UINT32)(AsmReadMsr64 (MTRR_LIB_IA32_MTRR_CAP) & MTRR_LIB_IA32_MTRR_CAP_VCNT_MASK);
- ASSERT (VariableMtrrCount <= MTRR_NUMBER_OF_VARIABLE_MTRR);
-
- return VariableMtrrCount;
+ return GetVariableMtrrCountWorker ();
}
/**
- Returns the firmware usable variable MTRR count for the CPU.
+ Worker function returns the firmware usable variable MTRR count for the CPU.
@return Firmware usable variable MTRR count
**/
UINT32
-EFIAPI
-GetFirmwareVariableMtrrCount (
+GetFirmwareVariableMtrrCountWorker (
VOID
)
{
UINT32 VariableMtrrCount;
UINT32 ReservedMtrrNumber;
- VariableMtrrCount = GetVariableMtrrCount ();
+ VariableMtrrCount = GetVariableMtrrCountWorker ();
ReservedMtrrNumber = PcdGet32 (PcdCpuNumberOfReservedVariableMtrrs);
if (VariableMtrrCount < ReservedMtrrNumber) {
return 0;
@@ -152,6 +163,39 @@ GetFirmwareVariableMtrrCount (
}
/**
+ Returns the firmware usable variable MTRR count for the CPU.
+
+ @return Firmware usable variable MTRR count
+
+**/
+UINT32
+EFIAPI
+GetFirmwareVariableMtrrCount (
+ VOID
+ )
+{
+ if (!IsMtrrSupported ()) {
+ return 0;
+ }
+ return GetFirmwareVariableMtrrCountWorker ();
+}
+
+/**
+ 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.
@return The default MTRR cache type.
@@ -166,8 +210,7 @@ MtrrGetDefaultMemoryType (
if (!IsMtrrSupported ()) {
return CacheUncacheable;
}
-
- return (MTRR_MEMORY_CACHE_TYPE) (AsmReadMsr64 (MTRR_LIB_IA32_MTRR_DEF_TYPE) & 0x7);
+ return MtrrGetDefaultMemoryTypeWorker ();
}
/**
@@ -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
**/
MTRR_VARIABLE_SETTINGS*
-EFIAPI
-MtrrGetVariableMtrr (
- OUT MTRR_VARIABLE_SETTINGS *VariableSettings
+MtrrGetVariableMtrrWorker (
+ OUT MTRR_VARIABLE_SETTINGS *VariableSettings
)
{
UINT32 Index;
UINT32 VariableMtrrCount;
- if (!IsMtrrSupported ()) {
- return VariableSettings;
- }
-
VariableMtrrCount = GetVariableMtrrCount ();
ASSERT (VariableMtrrCount <= MTRR_NUMBER_OF_VARIABLE_MTRR);
@@ -1323,6 +1361,29 @@ MtrrGetVariableMtrr (
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
@@ -1380,11 +1441,34 @@ MtrrSetVariableMtrr (
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
- @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
@@ -1395,18 +1479,11 @@ MtrrGetFixedMtrr (
OUT MTRR_FIXED_SETTINGS *FixedSettings
)
{
- UINT32 Index;
-
if (!IsMtrrSupported ()) {
return FixedSettings;
}
- for (Index = 0; Index < MTRR_NUMBER_OF_FIXED_MTRR; Index++) {
- FixedSettings->Mtrr[Index] =
- AsmReadMsr64 (mMtrrLibFixedMtrrTable[Index].Msr);
- };
-
- return FixedSettings;
+ return MtrrGetFixedMtrrWorker (FixedSettings);
}
/**