summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Fan <jeff.fan@intel.com>2016-04-20 16:51:46 +0800
committerJeff Fan <jeff.fan@intel.com>2016-04-29 10:07:06 +0800
commit0f354122328755c7a1cb0f68a37748f166d412ae (patch)
treec130fb11b482d9aa73925212744c28951553b1ae
parent21cc5ebf361248631fcfebde6494d4b615c62f4b (diff)
downloadedk2-platforms-0f354122328755c7a1cb0f68a37748f166d412ae.tar.xz
UefiCpuPkg/MtrrLib: Reduce the loop time to get fixed-MTRR MSR index
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>
-rw-r--r--UefiCpuPkg/Library/MtrrLib/MtrrLib.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c
index 5ed9f226e4..609aca5c3e 100644
--- a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c
+++ b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c
@@ -1,7 +1,7 @@
/** @file
MTRR setting library
- Copyright (c) 2008 - 2015, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2008 - 2016, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -438,7 +438,8 @@ MtrrGetVariableMtrr (
@param[in] MemoryCacheType The memory type to set.
@param[in, out] Base The base address of memory range.
@param[in, out] Length The length of memory range.
- @param[out] ReturnMsrNum The index of the fixed MTRR MSR to program.
+ @param[in, out] LastMsrNum On input, the last index of the fixed MTRR MSR to program.
+ On return, the current index of the fixed MTRR MSR to program.
@param[out] ReturnClearMask The bits to clear in the fixed MTRR MSR.
@param[out] ReturnOrMask The bits to set in the fixed MTRR MSR.
@@ -452,7 +453,7 @@ ProgramFixedMtrr (
IN UINT64 MemoryCacheType,
IN OUT UINT64 *Base,
IN OUT UINT64 *Length,
- OUT UINT32 *ReturnMsrNum,
+ IN OUT UINT32 *LastMsrNum,
OUT UINT64 *ReturnClearMask,
OUT UINT64 *ReturnOrMask
)
@@ -465,7 +466,7 @@ ProgramFixedMtrr (
OrMask = 0;
ClearMask = 0;
- for (MsrNum = 0; MsrNum < MTRR_NUMBER_OF_FIXED_MTRR; MsrNum++) {
+ for (MsrNum = *LastMsrNum + 1; MsrNum < MTRR_NUMBER_OF_FIXED_MTRR; MsrNum++) {
if ((*Base >= mMtrrLibFixedMtrrTable[MsrNum].BaseAddress) &&
(*Base <
(
@@ -478,7 +479,7 @@ ProgramFixedMtrr (
}
}
- if (MsrNum == MTRR_NUMBER_OF_FIXED_MTRR) {
+ if (MsrNum >= MTRR_NUMBER_OF_FIXED_MTRR) {
return RETURN_UNSUPPORTED;
}
@@ -515,7 +516,7 @@ ProgramFixedMtrr (
return RETURN_UNSUPPORTED;
}
- *ReturnMsrNum = MsrNum;
+ *LastMsrNum = MsrNum;
*ReturnClearMask = ClearMask;
*ReturnOrMask = OrMask;
@@ -1528,6 +1529,7 @@ MtrrSetMemoryAttributeWorker (
//
Status = RETURN_SUCCESS;
if (BaseAddress < BASE_1MB) {
+ MsrNum = (UINT32)-1;
while ((BaseAddress < BASE_1MB) && (Length > 0) && Status == RETURN_SUCCESS) {
Status = ProgramFixedMtrr (MemoryType, &BaseAddress, &Length, &MsrNum, &ClearMask, &OrMask);
if (RETURN_ERROR (Status)) {