Revision: 19153
          http://sourceforge.net/p/edk2/code/19153
Author:   vanjeff
Date:     2015-12-08 05:21:24 +0000 (Tue, 08 Dec 2015)
Log Message:
-----------
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 <[email protected]>
Cc: Michael Kinney <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Michael Kinney <[email protected]>
Signed-off-by: Jeff Fan <[email protected]>
Reviewed-by: Feng Tian <[email protected]>

Modified Paths:
--------------
    trunk/edk2/UefiCpuPkg/Library/MtrrLib/MtrrLib.c

Modified: trunk/edk2/UefiCpuPkg/Library/MtrrLib/MtrrLib.c
===================================================================
--- trunk/edk2/UefiCpuPkg/Library/MtrrLib/MtrrLib.c     2015-12-08 05:20:44 UTC 
(rev 19152)
+++ trunk/edk2/UefiCpuPkg/Library/MtrrLib/MtrrLib.c     2015-12-08 05:21:24 UTC 
(rev 19153)
@@ -104,6 +104,24 @@
 };
 
 /**
+  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 @@
   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 @@
 }
 
 /**
+  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 @@
   if (!IsMtrrSupported ()) {
     return CacheUncacheable;
   }
-
-  return (MTRR_MEMORY_CACHE_TYPE) (AsmReadMsr64 (MTRR_LIB_IA32_MTRR_DEF_TYPE) 
& 0x7);
+  return MtrrGetDefaultMemoryTypeWorker ();
 }
 
 /**
@@ -1290,26 +1333,21 @@
 
 
 /**
-  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,7 +1361,30 @@
   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 @@
   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 @@
   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);
 }
 
 /**


------------------------------------------------------------------------------
Go from Idea to Many App Stores Faster with Intel(R) XDK
Give your users amazing mobile app experiences with Intel(R) XDK.
Use one codebase in this all-in-one HTML5 development environment.
Design, debug & build mobile apps & 2D/3D high-impact games for multiple OSs.
http://pubads.g.doubleclick.net/gampad/clk?id=254741911&iu=/4140
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to