]> git.proxmox.com Git - mirror_edk2.git/commitdiff
UefiCpuPkg/MtrrLib: Reduce the loop time to get fixed-MTRR MSR index
authorJeff Fan <jeff.fan@intel.com>
Wed, 20 Apr 2016 08:51:46 +0000 (16:51 +0800)
committerJeff Fan <jeff.fan@intel.com>
Fri, 29 Apr 2016 02:07:06 +0000 (10:07 +0800)
Add input fixed-MTRR MSR index to be start MSR index to avoid finding fixed-MTRR
MSR index from 0 at each time.

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: Jeff Fan <jeff.fan@intel.com>
Reviewed-by: Feng Tian <feng.tian@intel.com>
UefiCpuPkg/Library/MtrrLib/MtrrLib.c

index 5ed9f226e4d199f91712e868dd9b4cd8c1dab6aa..609aca5c3e23954a0099f3a61c48b289f70aae02 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   MTRR setting library\r
 \r
-  Copyright (c) 2008 - 2015, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2008 - 2016, Intel Corporation. All rights reserved.<BR>\r
   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
@@ -438,7 +438,8 @@ MtrrGetVariableMtrr (
   @param[in]      MemoryCacheType  The memory type to set.\r
   @param[in, out] Base             The base address of memory range.\r
   @param[in, out] Length           The length of memory range.\r
-  @param[out]     ReturnMsrNum     The index of the fixed MTRR MSR to program.\r
+  @param[in, out] LastMsrNum       On input, the last index of the fixed MTRR MSR to program.\r
+                                   On return, the current index of the fixed MTRR MSR to program.\r
   @param[out]     ReturnClearMask  The bits to clear in the fixed MTRR MSR.\r
   @param[out]     ReturnOrMask     The bits to set in the fixed MTRR MSR.\r
 \r
@@ -452,7 +453,7 @@ ProgramFixedMtrr (
   IN     UINT64               MemoryCacheType,\r
   IN OUT UINT64               *Base,\r
   IN OUT UINT64               *Length,\r
-  OUT    UINT32               *ReturnMsrNum,\r
+  IN OUT UINT32               *LastMsrNum,\r
   OUT    UINT64               *ReturnClearMask,\r
   OUT    UINT64               *ReturnOrMask\r
   )\r
@@ -465,7 +466,7 @@ ProgramFixedMtrr (
   OrMask    = 0;\r
   ClearMask = 0;\r
 \r
-  for (MsrNum = 0; MsrNum < MTRR_NUMBER_OF_FIXED_MTRR; MsrNum++) {\r
+  for (MsrNum = *LastMsrNum + 1; MsrNum < MTRR_NUMBER_OF_FIXED_MTRR; MsrNum++) {\r
     if ((*Base >= mMtrrLibFixedMtrrTable[MsrNum].BaseAddress) &&\r
         (*Base <\r
             (\r
@@ -478,7 +479,7 @@ ProgramFixedMtrr (
     }\r
   }\r
 \r
-  if (MsrNum == MTRR_NUMBER_OF_FIXED_MTRR) {\r
+  if (MsrNum >= MTRR_NUMBER_OF_FIXED_MTRR) {\r
     return RETURN_UNSUPPORTED;\r
   }\r
 \r
@@ -515,7 +516,7 @@ ProgramFixedMtrr (
     return RETURN_UNSUPPORTED;\r
   }\r
 \r
-  *ReturnMsrNum    = MsrNum;\r
+  *LastMsrNum      = MsrNum;\r
   *ReturnClearMask = ClearMask;\r
   *ReturnOrMask    = OrMask;\r
 \r
@@ -1528,6 +1529,7 @@ MtrrSetMemoryAttributeWorker (
   //\r
   Status = RETURN_SUCCESS;\r
   if (BaseAddress < BASE_1MB) {\r
+    MsrNum = (UINT32)-1;\r
     while ((BaseAddress < BASE_1MB) && (Length > 0) && Status == RETURN_SUCCESS) {\r
       Status = ProgramFixedMtrr (MemoryType, &BaseAddress, &Length, &MsrNum, &ClearMask, &OrMask);\r
       if (RETURN_ERROR (Status)) {\r