From: Ruiyu Ni <ruiyu.ni@intel.com>
To: edk2-devel@lists.01.org
Cc: Eric Dong <eric.dong@intel.com>, Star Zeng <star.zeng@intel.com>
Subject: [PATCH] UefiCpuPkg/MtrrLib: Refine the debug messages
Date: Mon, 8 Jan 2018 11:50:39 +0800 [thread overview]
Message-ID: <20180108035039.334288-1-ruiyu.ni@intel.com> (raw)
MtrrSetMemoryAttributesInMtrrSettings() missed the debug messages
of memory attribute request and status.
The patch moves all debug messages from
MtrrSetMemoryAttributeInMtrrSettings() to
MtrrSetMemoryAttributesInMtrrSettings() and refines the debug message
to carry more information.
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
---
UefiCpuPkg/Library/MtrrLib/MtrrLib.c | 66 +++++++++++++++++++++++-------------
1 file changed, 42 insertions(+), 24 deletions(-)
diff --git a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c
index f37b740fdf..5d44435459 100644
--- a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c
+++ b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c
@@ -5,7 +5,7 @@
Most of services in this library instance are suggested to be invoked by BSP only,
except for MtrrSetAllMtrrs() which is used to sync BSP's MTRR setting to APs.
- Copyright (c) 2008 - 2017, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2008 - 2018, 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
@@ -1570,7 +1570,7 @@ MtrrLibCalculateMtrrs (
//
VectorCount = VectorIndex + 1;
DEBUG ((
- DEBUG_CACHE, "VectorCount (%016lx - %016lx) = %d\n",
+ DEBUG_CACHE, " VectorCount (%016lx - %016lx) = %d\n",
Ranges[0].BaseAddress, Ranges[RangeCount - 1].BaseAddress + Ranges[RangeCount - 1].Length, VectorCount
));
ASSERT (VectorCount < MAX_UINT16);
@@ -2209,6 +2209,7 @@ MtrrSetMemoryAttributesInMtrrSettings (
MTRR_CONTEXT MtrrContext;
BOOLEAN MtrrContextValid;
+ Status = RETURN_SUCCESS;
MtrrLibInitializeMtrrMask (&MtrrValidBitsMask, &MtrrValidAddressMask);
//
@@ -2226,24 +2227,48 @@ MtrrSetMemoryAttributesInMtrrSettings (
Above1MbExist = FALSE;
OriginalVariableMtrrCount = 0;
+ //
+ // 0. Dump the requests.
+ //
+ DEBUG_CODE (
+ DEBUG ((DEBUG_CACHE, "Mtrr: Set Mem Attribute to %a, ScratchSize = %x%a",
+ (MtrrSetting == NULL) ? "Hardware" : "Buffer", ScratchSize,
+ (RangeCount <= 1) ? "," : "\n"
+ ));
+ for (Index = 0; Index < RangeCount; Index++) {
+ DEBUG ((DEBUG_CACHE, " %a: [%016lx, %016lx)\n",
+ mMtrrMemoryCacheTypeShortName[MIN (Ranges[Index].Type, CacheInvalid)],
+ Ranges[Index].BaseAddress, Ranges[Index].BaseAddress + Ranges[Index].Length
+ ));
+ }
+ );
+
//
// 1. Validate the parameters.
//
+ if (!IsMtrrSupported ()) {
+ Status = RETURN_UNSUPPORTED;
+ goto Exit;
+ }
+
for (Index = 0; Index < RangeCount; Index++) {
if (Ranges[Index].Length == 0) {
- return RETURN_INVALID_PARAMETER;
+ Status = RETURN_INVALID_PARAMETER;
+ goto Exit;
}
if (((Ranges[Index].BaseAddress & ~MtrrValidAddressMask) != 0) ||
((Ranges[Index].Length & ~MtrrValidAddressMask) != 0)
) {
- return RETURN_UNSUPPORTED;
+ Status = RETURN_UNSUPPORTED;
+ goto Exit;
}
if ((Ranges[Index].Type != CacheUncacheable) &&
(Ranges[Index].Type != CacheWriteCombining) &&
(Ranges[Index].Type != CacheWriteThrough) &&
(Ranges[Index].Type != CacheWriteProtected) &&
(Ranges[Index].Type != CacheWriteBack)) {
- return RETURN_INVALID_PARAMETER;
+ Status = RETURN_INVALID_PARAMETER;
+ goto Exit;
}
if (Ranges[Index].BaseAddress + Ranges[Index].Length > BASE_1MB) {
Above1MbExist = TRUE;
@@ -2309,7 +2334,7 @@ MtrrSetMemoryAttributesInMtrrSettings (
if (Status == RETURN_ALREADY_STARTED) {
Status = RETURN_SUCCESS;
} else if (Status == RETURN_OUT_OF_RESOURCES) {
- return Status;
+ goto Exit;
} else {
ASSERT_RETURN_ERROR (Status);
Modified = TRUE;
@@ -2327,7 +2352,7 @@ MtrrSetMemoryAttributesInMtrrSettings (
WorkingVariableMtrr, FirmwareVariableMtrrCount + 1, &WorkingVariableMtrrCount
);
if (RETURN_ERROR (Status)) {
- return Status;
+ goto Exit;
}
//
@@ -2346,7 +2371,8 @@ MtrrSetMemoryAttributesInMtrrSettings (
}
if (WorkingVariableMtrrCount > FirmwareVariableMtrrCount) {
- return RETURN_OUT_OF_RESOURCES;
+ Status = RETURN_OUT_OF_RESOURCES;
+ goto Exit;
}
//
@@ -2375,7 +2401,7 @@ MtrrSetMemoryAttributesInMtrrSettings (
Ranges[Index].BaseAddress, Ranges[Index].Length, Ranges[Index].Type
);
if (RETURN_ERROR (Status)) {
- return Status;
+ goto Exit;
}
}
@@ -2441,7 +2467,12 @@ MtrrSetMemoryAttributesInMtrrSettings (
}
}
- return RETURN_SUCCESS;
+Exit:
+ DEBUG ((DEBUG_CACHE, " Result = %r\n", Status));
+ if (!RETURN_ERROR (Status)) {
+ MtrrDebugPrintAllMtrrsWorker (MtrrSetting);
+ }
+ return Status;
}
/**
@@ -2475,28 +2506,15 @@ MtrrSetMemoryAttributeInMtrrSettings (
IN MTRR_MEMORY_CACHE_TYPE Attribute
)
{
- RETURN_STATUS Status;
UINT8 Scratch[SCRATCH_BUFFER_SIZE];
UINTN ScratchSize;
MTRR_MEMORY_RANGE Range;
- if (!IsMtrrSupported ()) {
- return RETURN_UNSUPPORTED;
- }
-
Range.BaseAddress = BaseAddress;
Range.Length = Length;
Range.Type = Attribute;
ScratchSize = sizeof (Scratch);
- Status = MtrrSetMemoryAttributesInMtrrSettings (MtrrSetting, Scratch, &ScratchSize, &Range, 1);
- DEBUG ((DEBUG_CACHE, "MtrrSetMemoryAttribute(MtrrSettings = %p) %a: [%016lx, %016lx) - %r\n",
- MtrrSetting,
- mMtrrMemoryCacheTypeShortName[Attribute], BaseAddress, BaseAddress + Length, Status));
-
- if (!RETURN_ERROR (Status)) {
- MtrrDebugPrintAllMtrrsWorker (MtrrSetting);
- }
- return Status;
+ return MtrrSetMemoryAttributesInMtrrSettings (MtrrSetting, Scratch, &ScratchSize, &Range, 1);
}
/**
--
2.15.1.windows.2
reply other threads:[~2018-01-08 3:45 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180108035039.334288-1-ruiyu.ni@intel.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox