]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiCpuPkg/Library/MtrrLib/MtrrLib.c
UefiCpuPkg/MtrrLib: Add worker functions not invoke IsMtrrSupported()
[mirror_edk2.git] / UefiCpuPkg / Library / MtrrLib / MtrrLib.c
index 1584ae23d9ce49d57fdfa034c04a6d1644b6dd44..b1c12aa32e01026a4a2765b9f08a4bd13d51c39f 100644 (file)
@@ -103,6 +103,24 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *mMtrrMemoryCacheTypeShortName[] = {
   "R*"   // Invalid\r
 };\r
 \r
+/**\r
+  Worker function returns the variable MTRR count for the CPU.\r
+\r
+  @return Variable MTRR count\r
+\r
+**/\r
+UINT32\r
+GetVariableMtrrCountWorker (\r
+  VOID\r
+  )\r
+{\r
+  UINT32  VariableMtrrCount;\r
+\r
+  VariableMtrrCount = (UINT32)(AsmReadMsr64 (MTRR_LIB_IA32_MTRR_CAP) & MTRR_LIB_IA32_MTRR_CAP_VCNT_MASK);\r
+  ASSERT (VariableMtrrCount <= MTRR_NUMBER_OF_VARIABLE_MTRR);\r
+  return VariableMtrrCount;\r
+}\r
+\r
 /**\r
   Returns the variable MTRR count for the CPU.\r
 \r
@@ -115,34 +133,27 @@ GetVariableMtrrCount (
   VOID\r
   )\r
 {\r
-  UINT32  VariableMtrrCount;\r
-\r
   if (!IsMtrrSupported ()) {\r
     return 0;\r
   }\r
-\r
-  VariableMtrrCount = (UINT32)(AsmReadMsr64 (MTRR_LIB_IA32_MTRR_CAP) & MTRR_LIB_IA32_MTRR_CAP_VCNT_MASK);\r
-  ASSERT (VariableMtrrCount <= MTRR_NUMBER_OF_VARIABLE_MTRR);\r
-\r
-  return VariableMtrrCount;\r
+  return GetVariableMtrrCountWorker ();\r
 }\r
 \r
 /**\r
-  Returns the firmware usable variable MTRR count for the CPU.\r
+  Worker function returns the firmware usable variable MTRR count for the CPU.\r
 \r
   @return Firmware usable variable MTRR count\r
 \r
 **/\r
 UINT32\r
-EFIAPI\r
-GetFirmwareVariableMtrrCount (\r
+GetFirmwareVariableMtrrCountWorker (\r
   VOID\r
   )\r
 {\r
   UINT32  VariableMtrrCount;\r
   UINT32  ReservedMtrrNumber;\r
 \r
-  VariableMtrrCount = GetVariableMtrrCount ();\r
+  VariableMtrrCount = GetVariableMtrrCountWorker ();\r
   ReservedMtrrNumber = PcdGet32 (PcdCpuNumberOfReservedVariableMtrrs);\r
   if (VariableMtrrCount < ReservedMtrrNumber) {\r
     return 0;\r
@@ -151,6 +162,39 @@ GetFirmwareVariableMtrrCount (
   return VariableMtrrCount - ReservedMtrrNumber;\r
 }\r
 \r
+/**\r
+  Returns the firmware usable variable MTRR count for the CPU.\r
+\r
+  @return Firmware usable variable MTRR count\r
+\r
+**/\r
+UINT32\r
+EFIAPI\r
+GetFirmwareVariableMtrrCount (\r
+  VOID\r
+  )\r
+{\r
+  if (!IsMtrrSupported ()) {\r
+    return 0;\r
+  }\r
+  return GetFirmwareVariableMtrrCountWorker ();\r
+}\r
+\r
+/**\r
+  Worker function returns the default MTRR cache type for the system.\r
+\r
+  @return  The default MTRR cache type.\r
+\r
+**/\r
+MTRR_MEMORY_CACHE_TYPE\r
+MtrrGetDefaultMemoryTypeWorker (\r
+  VOID\r
+  )\r
+{\r
+  return (MTRR_MEMORY_CACHE_TYPE) (AsmReadMsr64 (MTRR_LIB_IA32_MTRR_DEF_TYPE) & 0x7);\r
+}\r
+\r
+\r
 /**\r
   Returns the default MTRR cache type for the system.\r
 \r
@@ -166,8 +210,7 @@ MtrrGetDefaultMemoryType (
   if (!IsMtrrSupported ()) {\r
     return CacheUncacheable;\r
   }\r
-\r
-  return (MTRR_MEMORY_CACHE_TYPE) (AsmReadMsr64 (MTRR_LIB_IA32_MTRR_DEF_TYPE) & 0x7);\r
+  return MtrrGetDefaultMemoryTypeWorker ();\r
 }\r
 \r
 /**\r
@@ -1290,26 +1333,21 @@ MtrrGetMemoryAttribute (
 \r
 \r
 /**\r
-  This function will get the raw value in variable MTRRs\r
+  Worker function will get the raw value in variable MTRRs\r
 \r
-  @param[out]  FixedSettings  A buffer to hold fixed MTRRs content.\r
+  @param[out] VariableSettings   A buffer to hold variable MTRRs content.\r
 \r
   @return The VariableSettings input pointer\r
 \r
 **/\r
 MTRR_VARIABLE_SETTINGS*\r
-EFIAPI\r
-MtrrGetVariableMtrr (\r
-  OUT MTRR_VARIABLE_SETTINGS         *VariableSettings\r
+MtrrGetVariableMtrrWorker (\r
+  OUT MTRR_VARIABLE_SETTINGS  *VariableSettings\r
   )\r
 {\r
   UINT32  Index;\r
   UINT32  VariableMtrrCount;\r
 \r
-  if (!IsMtrrSupported ()) {\r
-    return VariableSettings;\r
-  }\r
-\r
   VariableMtrrCount = GetVariableMtrrCount ();\r
   ASSERT (VariableMtrrCount <= MTRR_NUMBER_OF_VARIABLE_MTRR);\r
 \r
@@ -1323,6 +1361,29 @@ MtrrGetVariableMtrr (
   return  VariableSettings;\r
 }\r
 \r
+/**\r
+  This function will get the raw value in variable MTRRs\r
+\r
+  @param[out]  VariableSettings   A buffer to hold variable MTRRs content.\r
+\r
+  @return The VariableSettings input pointer\r
+\r
+**/\r
+MTRR_VARIABLE_SETTINGS*\r
+EFIAPI\r
+MtrrGetVariableMtrr (\r
+  OUT MTRR_VARIABLE_SETTINGS         *VariableSettings\r
+  )\r
+{\r
+  if (!IsMtrrSupported ()) {\r
+    return VariableSettings;\r
+  }\r
+\r
+  return MtrrGetVariableMtrrWorker (\r
+           VariableSettings\r
+           );\r
+}\r
+\r
 \r
 /**\r
   Worker function setting variable MTRRs\r
@@ -1380,11 +1441,34 @@ MtrrSetVariableMtrr (
   return  VariableSettings;\r
 }\r
 \r
+/**\r
+  Worker function gets the content in fixed MTRRs\r
+\r
+  @param[out]  FixedSettings  A buffer to hold fixed MTRRs content.\r
+\r
+  @retval The pointer of FixedSettings\r
+\r
+**/\r
+MTRR_FIXED_SETTINGS*\r
+MtrrGetFixedMtrrWorker (\r
+  OUT MTRR_FIXED_SETTINGS         *FixedSettings\r
+  )\r
+{\r
+  UINT32  Index;\r
+\r
+  for (Index = 0; Index < MTRR_NUMBER_OF_FIXED_MTRR; Index++) {\r
+      FixedSettings->Mtrr[Index] =\r
+        AsmReadMsr64 (mMtrrLibFixedMtrrTable[Index].Msr);\r
+  }\r
+\r
+  return FixedSettings;\r
+}\r
+\r
 \r
 /**\r
   This function gets the content in fixed MTRRs\r
 \r
-  @param[out]  FixedSettings  A buffer to hold fixed Mtrrs content.\r
+  @param[out]  FixedSettings  A buffer to hold fixed MTRRs content.\r
 \r
   @retval The pointer of FixedSettings\r
 \r
@@ -1395,18 +1479,11 @@ MtrrGetFixedMtrr (
   OUT MTRR_FIXED_SETTINGS         *FixedSettings\r
   )\r
 {\r
-  UINT32  Index;\r
-\r
   if (!IsMtrrSupported ()) {\r
     return FixedSettings;\r
   }\r
 \r
-  for (Index = 0; Index < MTRR_NUMBER_OF_FIXED_MTRR; Index++) {\r
-      FixedSettings->Mtrr[Index] =\r
-        AsmReadMsr64 (mMtrrLibFixedMtrrTable[Index].Msr);\r
-  };\r
-\r
-  return FixedSettings;\r
+  return MtrrGetFixedMtrrWorker (FixedSettings);\r
 }\r
 \r
 /**\r