]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Original MTRR lib hardcode VARIABLE_MTRR as 8. But it is 7 in Core2 if SMRR enabled...
authorjyao1 <jyao1@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 5 Feb 2010 06:33:42 +0000 (06:33 +0000)
committerjyao1 <jyao1@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 5 Feb 2010 06:33:42 +0000 (06:33 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@9935 6f19259b-4bc3-4df7-8a09-765794883524

UefiCpuPkg/CpuDxe/CpuDxe.c
UefiCpuPkg/Include/Library/MtrrLib.h
UefiCpuPkg/Library/MtrrLib/MtrrLib.c

index 25131febf20a0fc098ffdb98eca905e562bfa7ca..68579a7da0ebaad88967b2164de0cf2a5b3c3943 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   CPU DXE Module.\r
 \r
-  Copyright (c) 2008 - 2009, Intel Corporation\r
+  Copyright (c) 2008 - 2010, Intel Corporation\r
   All rights reserved. This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -852,8 +852,12 @@ RefreshGcdMemoryAttributes (
   UINTN                               NumberOfDescriptors;\r
   EFI_GCD_MEMORY_SPACE_DESCRIPTOR     *MemorySpaceMap;\r
   UINT64                              DefaultAttributes;\r
-  VARIABLE_MTRR                       VariableMtrr[MTRR_NUMBER_OF_VARIABLE_MTRR];\r
+  VARIABLE_MTRR                       VariableMtrr[MAX_MTRR_NUMBER_OF_VARIABLE_MTRR];\r
   MTRR_FIXED_SETTINGS                 MtrrFixedSettings;\r
+  UINT32                              FirmwareVariableMtrrCount;\r
+  UINT32                              UsedMtrr;\r
+\r
+  FirmwareVariableMtrrCount = GetFirmwareVariableMtrrCount ();\r
 \r
 //  mIsFlushingGCD = TRUE;\r
   mIsFlushingGCD = FALSE;\r
@@ -867,9 +871,11 @@ RefreshGcdMemoryAttributes (
   //\r
   // Get the memory attribute of variable MTRRs\r
   //\r
+  UsedMtrr = MAX_MTRR_NUMBER_OF_VARIABLE_MTRR;\r
   MtrrGetMemoryAttributeInVariableMtrr (\r
     mValidMtrrBitsMask,\r
     mValidMtrrAddressMask,\r
+    &UsedMtrr,\r
     VariableMtrr\r
     );\r
 \r
@@ -902,7 +908,7 @@ RefreshGcdMemoryAttributes (
   //\r
   // Go for variable MTRRs with WB attribute\r
   //\r
-  for (Index = 0; Index < FIRMWARE_VARIABLE_MTRR_NUMBER; Index++) {\r
+  for (Index = 0; Index < FirmwareVariableMtrrCount; Index++) {\r
     if (VariableMtrr[Index].Valid &&\r
         VariableMtrr[Index].Type == MTRR_CACHE_WRITE_BACK) {\r
       SetGcdMemorySpaceAttributes (\r
@@ -917,7 +923,7 @@ RefreshGcdMemoryAttributes (
   //\r
   // Go for variable MTRRs with Non-WB attribute\r
   //\r
-  for (Index = 0; Index < FIRMWARE_VARIABLE_MTRR_NUMBER; Index++) {\r
+  for (Index = 0; Index < FirmwareVariableMtrrCount; Index++) {\r
     if (VariableMtrr[Index].Valid &&\r
         VariableMtrr[Index].Type != MTRR_CACHE_WRITE_BACK) {\r
       Attributes = GetMemorySpaceAttributeFromMtrrType ((UINT8) VariableMtrr[Index].Type);\r
index e3ad1cde316a7445ffa1886b5a397d5fa790fb1a..14453719bf6ec0ac6592322caa75f4302514a3c1 100644 (file)
 // According to IA32 SDM, MTRRs number and msr offset are always consistent\r
 // for IA32 processor family\r
 //\r
-#define  MTRR_NUMBER_OF_VARIABLE_MTRR   8\r
+\r
+//\r
+// We can not use Pcd as macro to define structure, so we have to define MAX_MTRR_NUMBER_OF_VARIABLE_MTRR\r
+//\r
+#define  MAX_MTRR_NUMBER_OF_VARIABLE_MTRR  32\r
+//\r
+// Firmware need reserve 2 MTRR for OS\r
+//\r
+#define  RESERVED_FIRMWARE_VARIABLE_MTRR_NUMBER  2\r
+\r
 #define  MTRR_NUMBER_OF_FIXED_MTRR      11\r
-#define  FIRMWARE_VARIABLE_MTRR_NUMBER  6\r
+#define  MTRR_LIB_IA32_MTRR_CAP                      0x0FE\r
+#define  MTRR_LIB_IA32_MTRR_CAP_VCNT_MASK            0x0FF\r
 #define  MTRR_LIB_IA32_MTRR_FIX64K_00000             0x250\r
 #define  MTRR_LIB_IA32_MTRR_FIX16K_80000             0x258\r
 #define  MTRR_LIB_IA32_MTRR_FIX16K_A0000             0x259\r
@@ -34,7 +44,6 @@
 #define  MTRR_LIB_IA32_MTRR_FIX4K_F0000              0x26E\r
 #define  MTRR_LIB_IA32_MTRR_FIX4K_F8000              0x26F\r
 #define  MTRR_LIB_IA32_VARIABLE_MTRR_BASE            0x200\r
-#define  MTRR_LIB_IA32_VARIABLE_MTRR_END             0x20F\r
 #define  MTRR_LIB_IA32_MTRR_DEF_TYPE                 0x2FF\r
 #define  MTRR_LIB_MSR_VALID_MASK                     0xFFFFFFFFFULL\r
 #define  MTRR_LIB_CACHE_VALID_ADDRESS                0xFFFFFF000ULL\r
@@ -74,7 +83,7 @@ typedef struct _MTRR_VARIABLE_SETTING_ {
 // Array for variable MTRRs\r
 //\r
 typedef struct _MTRR_VARIABLE_SETTINGS_ {\r
-       MTRR_VARIABLE_SETTING   Mtrr[MTRR_NUMBER_OF_VARIABLE_MTRR];\r
+       MTRR_VARIABLE_SETTING   Mtrr[MAX_MTRR_NUMBER_OF_VARIABLE_MTRR];\r
 }      MTRR_VARIABLE_SETTINGS;\r
 \r
 //\r
@@ -111,6 +120,28 @@ typedef enum {
 #define  MTRR_CACHE_WRITE_BACK       6\r
 #define  MTRR_CACHE_INVALID_TYPE     7\r
 \r
+/**\r
+  Returns the variable MTRR count for the CPU.\r
+\r
+  @return Variable MTRR count\r
+\r
+**/\r
+UINT32\r
+GetVariableMtrrCount (\r
+  VOID\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
+GetFirmwareVariableMtrrCount (\r
+  VOID\r
+  );\r
+\r
 /**\r
   This function attempts to set the attributes for a memory range.\r
 \r
@@ -251,19 +282,25 @@ MtrrSetAllMtrrs (
   This function shadows the content of variable MTRRs into\r
   an internal array: VariableMtrr\r
 \r
-  @param  MtrrValidBitsMask     The mask for the valid bit of the MTRR\r
-  @param  MtrrValidAddressMask  The valid address mask for MTRR since the base address in\r
-                                MTRR must align to 4K, so valid address mask equal to\r
-                                MtrrValidBitsMask & 0xfffffffffffff000ULL\r
-  @param  VariableMtrr          The array to shadow variable MTRRs content\r
-  @return                       The ruturn value of this paramter indicates the number of\r
-                                MTRRs which has been used.\r
+  @param  MtrrValidBitsMask        The mask for the valid bit of the MTRR\r
+  @param  MtrrValidAddressMask     The valid address mask for MTRR since the base address in\r
+                                   MTRR must align to 4K, so valid address mask equal to\r
+                                   MtrrValidBitsMask & 0xfffffffffffff000ULL\r
+  @param  VariableMtrrCount        On input, it means the array number of variable MTRRs passed in.\r
+                                   On output, it means the number of MTRRs which has been used if EFI_SUCCESS,\r
+                                   or the number of MTRR required if BUFFER_TOO_SMALL.\r
+  @param  VariableMtrr             The array to shadow variable MTRRs content\r
+\r
+  @retval RETURN_SUCCESS           The variable MTRRs are returned.\r
+  @retval RETURN_BUFFER_TOO_SMALL  The input buffer is too small to hold the variable MTRRs.\r
+\r
 **/\r
-UINT32\r
+RETURN_STATUS\r
 EFIAPI\r
 MtrrGetMemoryAttributeInVariableMtrr (\r
   IN  UINT64                    MtrrValidBitsMask,\r
   IN  UINT64                    MtrrValidAddressMask,\r
+  IN OUT UINT32                 *VariableMtrrCount,\r
   OUT VARIABLE_MTRR             *VariableMtrr\r
   );\r
 \r
index dcd99b9084addfc963cfe74e59617a70ebc78bed..a95a72bfa3c8933b88be3f526cf7790b2e9bd930 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   MTRR setting library\r
 \r
-  Copyright (c) 2008 - 2009, Intel Corporation\r
+  Copyright (c) 2008 - 2010, Intel Corporation\r
   All rights reserved. This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -82,6 +82,33 @@ FIXED_MTRR    MtrrLibFixedMtrrTable[] = {
   },\r
 };\r
 \r
+/**\r
+  Returns the variable MTRR count for the CPU.\r
+\r
+  @return Variable MTRR count\r
+\r
+**/\r
+UINT32\r
+GetVariableMtrrCount (\r
+  VOID\r
+  )\r
+{\r
+  return (UINT32)(AsmReadMsr64 (MTRR_LIB_IA32_MTRR_CAP) & MTRR_LIB_IA32_MTRR_CAP_VCNT_MASK);\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
+GetFirmwareVariableMtrrCount (\r
+  VOID\r
+  )\r
+{\r
+  return GetVariableMtrrCount () - RESERVED_FIRMWARE_VARIABLE_MTRR_NUMBER;\r
+}\r
 \r
 /**\r
   Returns the default MTRR cache type for the system.\r
@@ -273,36 +300,55 @@ ProgramFixedMtrr (
 /**\r
   Get the attribute of variable MTRRs.\r
 \r
-  This function shadows the content of variable MTRRs into an\r
-  internal array: VariableMtrr.\r
+  This function shadows the content of variable MTRRs into\r
+  an internal array: VariableMtrr\r
 \r
-  @param  MtrrValidBitsMask     The mask for the valid bit of the MTRR\r
-  @param  MtrrValidAddressMask  The valid address mask for MTRR\r
-  @param  VariableMtrr          The array to shadow variable MTRRs content\r
+  @param  MtrrValidBitsMask        The mask for the valid bit of the MTRR\r
+  @param  MtrrValidAddressMask     The valid address mask for MTRR since the base address in\r
+                                   MTRR must align to 4K, so valid address mask equal to\r
+                                   MtrrValidBitsMask & 0xfffffffffffff000ULL\r
+  @param  VariableMtrrCount        On input, it means the array number of variable MTRRs passed in.\r
+                                   On output, it means the number of MTRRs which has been used if EFI_SUCCESS,\r
+                                   or the number of MTRR required if BUFFER_TOO_SMALL.\r
+  @param  VariableMtrr             The array to shadow variable MTRRs content\r
 \r
-  @return                       The return value of this paramter indicates the\r
-                                number of MTRRs which has been used.\r
+  @retval RETURN_SUCCESS           The variable MTRRs are returned.\r
+  @retval RETURN_BUFFER_TOO_SMALL  The input buffer is too small to hold the variable MTRRs.\r
 \r
 **/\r
-UINT32\r
+RETURN_STATUS\r
 EFIAPI\r
 MtrrGetMemoryAttributeInVariableMtrr (\r
   IN  UINT64                    MtrrValidBitsMask,\r
   IN  UINT64                    MtrrValidAddressMask,\r
+  IN OUT UINT32                 *VariableMtrrCount,\r
   OUT VARIABLE_MTRR             *VariableMtrr\r
   )\r
 {\r
   UINTN   Index;\r
   UINT32  MsrNum;\r
   UINT32  UsedMtrr;\r
+  UINTN   FirmwareVariableMtrrCount;\r
+  UINT32  VariableMtrrEnd;\r
+\r
+  //\r
+  // Check if input buffer is large enough\r
+  //\r
+  FirmwareVariableMtrrCount = GetFirmwareVariableMtrrCount ();\r
+  if (*VariableMtrrCount < FirmwareVariableMtrrCount) {\r
+    *VariableMtrrCount = (UINT32)FirmwareVariableMtrrCount;\r
+    return RETURN_BUFFER_TOO_SMALL;\r
+  }\r
+\r
+  VariableMtrrEnd = MTRR_LIB_IA32_VARIABLE_MTRR_BASE + (2 * GetVariableMtrrCount ()) - 1;\r
 \r
-  ZeroMem (VariableMtrr, sizeof (VARIABLE_MTRR) * MTRR_NUMBER_OF_VARIABLE_MTRR);\r
+  ZeroMem (VariableMtrr, sizeof (VARIABLE_MTRR) * (*VariableMtrrCount));\r
   UsedMtrr = 0;\r
 \r
   for (MsrNum = MTRR_LIB_IA32_VARIABLE_MTRR_BASE, Index = 0;\r
        (\r
-         (MsrNum < MTRR_LIB_IA32_VARIABLE_MTRR_END) &&\r
-         (Index < FIRMWARE_VARIABLE_MTRR_NUMBER)\r
+         (MsrNum < VariableMtrrEnd) &&\r
+         (Index < FirmwareVariableMtrrCount)\r
        );\r
        MsrNum += 2\r
       ) {\r
@@ -322,7 +368,8 @@ MtrrGetMemoryAttributeInVariableMtrr (
       Index++;\r
     }\r
   }\r
-  return UsedMtrr;\r
+  *VariableMtrrCount = UsedMtrr;\r
+  return RETURN_SUCCESS;\r
 }\r
 \r
 \r
@@ -415,11 +462,14 @@ CombineMemoryAttribute (
   UINT64  CombineEnd;\r
   UINT64  MtrrEnd;\r
   UINT64  EndAddress;\r
+  UINT32  FirmwareVariableMtrrCount;\r
+\r
+  FirmwareVariableMtrrCount = GetFirmwareVariableMtrrCount ();\r
 \r
   *OverwriteExistingMtrr = FALSE;\r
   EndAddress = *Base +*Length - 1;\r
 \r
-  for (Index = 0; Index < FIRMWARE_VARIABLE_MTRR_NUMBER; Index++) {\r
+  for (Index = 0; Index < FirmwareVariableMtrrCount; Index++) {\r
 \r
     MtrrEnd = VariableMtrr[Index].BaseAddress + VariableMtrr[Index].Length - 1;\r
     if (\r
@@ -586,10 +636,12 @@ InvalidateMtrr (
 {\r
   UINTN Index;\r
   UINTN Cr4;\r
+  UINTN VariableMtrrCount;\r
 \r
   Cr4 = PreMtrrChange ();\r
   Index = 0;\r
-  while (Index < MTRR_NUMBER_OF_VARIABLE_MTRR) {\r
+  VariableMtrrCount = GetVariableMtrrCount ();\r
+  while (Index < VariableMtrrCount) {\r
     if (VariableMtrr[Index].Valid == FALSE && VariableMtrr[Index].Used == TRUE ) {\r
        AsmWriteMsr64 (VariableMtrr[Index].Msr, 0);\r
        AsmWriteMsr64 (VariableMtrr[Index].Msr + 1, 0);\r
@@ -830,12 +882,17 @@ MtrrSetMemoryAttribute (
   BOOLEAN                   Positive;\r
   UINT32                    MsrNum;\r
   UINTN                     MtrrNumber;\r
-  VARIABLE_MTRR             VariableMtrr[MTRR_NUMBER_OF_VARIABLE_MTRR];\r
+  VARIABLE_MTRR             VariableMtrr[MAX_MTRR_NUMBER_OF_VARIABLE_MTRR];\r
   UINT32                    UsedMtrr;\r
   UINT64                    MtrrValidBitsMask;\r
   UINT64                    MtrrValidAddressMask;\r
   UINTN                     Cr4;\r
   BOOLEAN                   OverwriteExistingMtrr;\r
+  UINT32                    FirmwareVariableMtrrCount;\r
+  UINT32                    VariableMtrrEnd;\r
+\r
+  FirmwareVariableMtrrCount = GetFirmwareVariableMtrrCount ();\r
+  VariableMtrrEnd = MTRR_LIB_IA32_VARIABLE_MTRR_BASE + (2 * GetVariableMtrrCount ()) - 1;\r
 \r
   MtrrLibInitializeMtrrMask(&MtrrValidBitsMask, &MtrrValidAddressMask);\r
 \r
@@ -903,7 +960,8 @@ MtrrSetMemoryAttribute (
   //\r
   // Check for overlap\r
   //\r
-  UsedMtrr = MtrrGetMemoryAttributeInVariableMtrr (MtrrValidBitsMask, MtrrValidAddressMask, VariableMtrr);\r
+  UsedMtrr = MAX_MTRR_NUMBER_OF_VARIABLE_MTRR;\r
+  MtrrGetMemoryAttributeInVariableMtrr (MtrrValidBitsMask, MtrrValidAddressMask, &UsedMtrr, VariableMtrr);\r
   OverLap = CheckMemoryAttributeOverlap (BaseAddress, BaseAddress + Length - 1, VariableMtrr);\r
   if (OverLap) {\r
     Status = CombineMemoryAttribute (MemoryType, &BaseAddress, &Length, VariableMtrr, &UsedMtrr, &OverwriteExistingMtrr);\r
@@ -925,7 +983,7 @@ MtrrSetMemoryAttribute (
   //\r
   // Avoid hardcode here and read data dynamically\r
   //\r
-  if (UsedMtrr >= FIRMWARE_VARIABLE_MTRR_NUMBER) {\r
+  if (UsedMtrr >= FirmwareVariableMtrrCount) {\r
     Status = RETURN_OUT_OF_RESOURCES;\r
     goto Done;\r
   }\r
@@ -955,7 +1013,7 @@ MtrrSetMemoryAttribute (
     // Find first unused MTRR\r
     //\r
     for (MsrNum = MTRR_LIB_IA32_VARIABLE_MTRR_BASE;\r
-         MsrNum < MTRR_LIB_IA32_VARIABLE_MTRR_END;\r
+         MsrNum < VariableMtrrEnd;\r
          MsrNum += 2\r
         ) {\r
       if ((AsmReadMsr64 (MsrNum + 1) & MTRR_LIB_CACHE_MTRR_ENABLED) == 0) {\r
@@ -974,7 +1032,7 @@ MtrrSetMemoryAttribute (
 \r
     Positive = GetDirection (TempQword, &MtrrNumber);\r
 \r
-    if ((UsedMtrr + MtrrNumber) > FIRMWARE_VARIABLE_MTRR_NUMBER) {\r
+    if ((UsedMtrr + MtrrNumber) > FirmwareVariableMtrrCount) {\r
       Status = RETURN_OUT_OF_RESOURCES;\r
       goto Done;\r
     }\r
@@ -988,7 +1046,7 @@ MtrrSetMemoryAttribute (
     // Find first unused MTRR\r
     //\r
     for (MsrNum = MTRR_LIB_IA32_VARIABLE_MTRR_BASE;\r
-         MsrNum < MTRR_LIB_IA32_VARIABLE_MTRR_END;\r
+         MsrNum < VariableMtrrEnd;\r
          MsrNum += 2\r
         ) {\r
       if ((AsmReadMsr64 (MsrNum + 1) & MTRR_LIB_CACHE_MTRR_ENABLED) == 0) {\r
@@ -1014,7 +1072,7 @@ MtrrSetMemoryAttribute (
       //\r
       // Find unused MTRR\r
       //\r
-      for (; MsrNum < MTRR_LIB_IA32_VARIABLE_MTRR_END; MsrNum += 2) {\r
+      for (; MsrNum < VariableMtrrEnd; MsrNum += 2) {\r
         if ((AsmReadMsr64 (MsrNum + 1) & MTRR_LIB_CACHE_MTRR_ENABLED) == 0) {\r
           break;\r
         }\r
@@ -1069,9 +1127,11 @@ MtrrGetMemoryAttribute (
   UINT64                  MtrrType;\r
   UINT64                  TempMtrrType;\r
   MTRR_MEMORY_CACHE_TYPE  CacheType;\r
-  VARIABLE_MTRR           VariableMtrr[MTRR_NUMBER_OF_VARIABLE_MTRR];\r
+  VARIABLE_MTRR           VariableMtrr[MAX_MTRR_NUMBER_OF_VARIABLE_MTRR];\r
   UINT64                  MtrrValidBitsMask;\r
   UINT64                  MtrrValidAddressMask;\r
+  UINTN                   VariableMtrrCount;\r
+  UINT32                  UsedMtrr;\r
 \r
   //\r
   // Check if MTRR is enabled, if not, return UC as attribute\r
@@ -1109,16 +1169,19 @@ MtrrGetMemoryAttribute (
     }\r
   }\r
   MtrrLibInitializeMtrrMask(&MtrrValidBitsMask, &MtrrValidAddressMask);\r
+  UsedMtrr = MAX_MTRR_NUMBER_OF_VARIABLE_MTRR;\r
   MtrrGetMemoryAttributeInVariableMtrr(\r
     MtrrValidBitsMask,\r
     MtrrValidAddressMask,\r
+    &UsedMtrr,\r
     VariableMtrr\r
     );\r
 \r
   //\r
   // Go through the variable MTRR\r
   //\r
-  for (Index = 0; Index < MTRR_NUMBER_OF_VARIABLE_MTRR; Index++) {\r
+  VariableMtrrCount = GetVariableMtrrCount ();\r
+  for (Index = 0; Index < VariableMtrrCount; Index++) {\r
     if (VariableMtrr[Index].Valid) {\r
       if (Address >= VariableMtrr[Index].BaseAddress &&\r
           Address < VariableMtrr[Index].BaseAddress+VariableMtrr[Index].Length) {\r
@@ -1148,8 +1211,10 @@ MtrrGetVariableMtrr (
   )\r
 {\r
   UINT32  Index;\r
+  UINT32  VariableMtrrCount;\r
 \r
-  for (Index = 0; Index < MTRR_NUMBER_OF_VARIABLE_MTRR; Index++) {\r
+  VariableMtrrCount = GetVariableMtrrCount ();\r
+  for (Index = 0; Index < VariableMtrrCount; Index++) {\r
     VariableSettings->Mtrr[Index].Base =\r
       AsmReadMsr64 (MTRR_LIB_IA32_VARIABLE_MTRR_BASE + (Index << 1));\r
     VariableSettings->Mtrr[Index].Mask =\r
@@ -1172,8 +1237,10 @@ MtrrSetVariableMtrrWorker (
   )\r
 {\r
   UINT32  Index;\r
+  UINT32  VariableMtrrCount;\r
 \r
-  for (Index = 0; Index < MTRR_NUMBER_OF_VARIABLE_MTRR; Index++) {\r
+  VariableMtrrCount = GetVariableMtrrCount ();\r
+  for (Index = 0; Index < VariableMtrrCount; Index++) {\r
     AsmWriteMsr64 (\r
       MTRR_LIB_IA32_VARIABLE_MTRR_BASE + (Index << 1),\r
       VariableSettings->Mtrr[Index].Base\r
@@ -1362,6 +1429,7 @@ MtrrDebugPrintAllMtrrs (
     {\r
       MTRR_SETTINGS  MtrrSettings;\r
       UINTN          Index;\r
+      UINTN          VariableMtrrCount;\r
 \r
       MtrrGetAllMtrrs (&MtrrSettings);\r
       DEBUG((EFI_D_ERROR, "DefaultType = %016lx\n", MtrrSettings.MtrrDefType));\r
@@ -1372,7 +1440,9 @@ MtrrDebugPrintAllMtrrs (
           MtrrSettings.Fixed.Mtrr[Index]\r
           ));\r
       }\r
-      for (Index = 0; Index < MTRR_NUMBER_OF_VARIABLE_MTRR; Index++) {\r
+\r
+      VariableMtrrCount = GetVariableMtrrCount ();\r
+      for (Index = 0; Index < VariableMtrrCount; Index++) {\r
         DEBUG((\r
           EFI_D_ERROR, "Variable[%02d] = %016lx, %016lx\n",\r
           Index,\r