]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg: VariableSmmRuntimeDxe: Added request unblock memory interface
authorKun Qin <kun.q@outlook.com>
Fri, 5 Mar 2021 04:14:11 +0000 (20:14 -0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Fri, 5 Mar 2021 15:25:07 +0000 (15:25 +0000)
This changes added usage of MmUnblockMemoryLib to explicitly request
runtime cache regions(and its indicators) to be accessible from MM
environment when PcdEnableVariableRuntimeCache is enabled. It will bring
in compatibility with architectures that supports full memory blockage
inside MM.

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Signed-off-by: Kun Qin <kun.q@outlook.com>
Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
Message-Id: <MWHPR06MB31026EA41F28F2CE12B68574F3969@MWHPR06MB3102.namprd06.prod.outlook.com>

MdeModulePkg/MdeModulePkg.dsc
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.inf

index 7ca4a1bb30805ec9a63b131a65eb873cfb44fe5f..9272da89a9982757c585c8b343c66e16034a9bb2 100644 (file)
   SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf\r
   DisplayUpdateProgressLib|MdeModulePkg/Library/DisplayUpdateProgressLibGraphics/DisplayUpdateProgressLibGraphics.inf\r
   VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.inf\r
+  MmUnblockMemoryLib|MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.inf\r
 \r
 [LibraryClasses.EBC.PEIM]\r
   IoLib|MdePkg/Library/PeiIoLibCpuIo/PeiIoLibCpuIo.inf\r
index c47e614d81f4594c36b31fab80c26508854818d8..a166d284dfe43458b1d7c07f7fdaa94f30507851 100644 (file)
@@ -35,6 +35,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 #include <Library/DebugLib.h>\r
 #include <Library/UefiLib.h>\r
 #include <Library/BaseLib.h>\r
+#include <Library/MmUnblockMemoryLib.h>\r
 \r
 #include <Guid/EventGroup.h>\r
 #include <Guid/SmmVariableCommon.h>\r
@@ -165,6 +166,7 @@ InitVariableCache (
   )\r
 {\r
   VARIABLE_STORE_HEADER   *VariableCacheStorePtr;\r
+  EFI_STATUS              Status;\r
 \r
   if (TotalVariableCacheSize == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -186,6 +188,18 @@ InitVariableCache (
   if (*VariableCacheBuffer == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
+\r
+  //\r
+  // Request to unblock the newly allocated cache region to be accessible from inside MM\r
+  //\r
+  Status = MmUnblockMemoryRequest (\r
+            (EFI_PHYSICAL_ADDRESS) (UINTN) *VariableCacheBuffer,\r
+            EFI_SIZE_TO_PAGES (*TotalVariableCacheSize)\r
+            );\r
+  if (Status != EFI_UNSUPPORTED && EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
   VariableCacheStorePtr = *VariableCacheBuffer;\r
   SetMem32 ((VOID *) VariableCacheStorePtr, *TotalVariableCacheSize, (UINT32) 0xFFFFFFFF);\r
 \r
@@ -1536,6 +1550,34 @@ SendRuntimeVariableCacheContextToSmm (
   SmmRuntimeVarCacheContext->ReadLock = &mVariableRuntimeCacheReadLock;\r
   SmmRuntimeVarCacheContext->HobFlushComplete = &mHobFlushComplete;\r
 \r
+  //\r
+  // Request to unblock this region to be accessible from inside MM environment\r
+  // These fields "should" be all on the same page, but just to be on the safe side...\r
+  //\r
+  Status = MmUnblockMemoryRequest (\r
+            (EFI_PHYSICAL_ADDRESS) ALIGN_VALUE ((UINTN) SmmRuntimeVarCacheContext->PendingUpdate - EFI_PAGE_SIZE + 1, EFI_PAGE_SIZE),\r
+            EFI_SIZE_TO_PAGES (sizeof(mVariableRuntimeCachePendingUpdate))\r
+            );\r
+  if (Status != EFI_UNSUPPORTED && EFI_ERROR (Status)) {\r
+    goto Done;\r
+  }\r
+\r
+  Status = MmUnblockMemoryRequest (\r
+            (EFI_PHYSICAL_ADDRESS) ALIGN_VALUE ((UINTN) SmmRuntimeVarCacheContext->ReadLock - EFI_PAGE_SIZE + 1, EFI_PAGE_SIZE),\r
+            EFI_SIZE_TO_PAGES (sizeof(mVariableRuntimeCacheReadLock))\r
+            );\r
+  if (Status != EFI_UNSUPPORTED && EFI_ERROR (Status)) {\r
+    goto Done;\r
+  }\r
+\r
+  Status = MmUnblockMemoryRequest (\r
+            (EFI_PHYSICAL_ADDRESS) ALIGN_VALUE ((UINTN) SmmRuntimeVarCacheContext->HobFlushComplete - EFI_PAGE_SIZE + 1, EFI_PAGE_SIZE),\r
+            EFI_SIZE_TO_PAGES (sizeof(mHobFlushComplete))\r
+            );\r
+  if (Status != EFI_UNSUPPORTED && EFI_ERROR (Status)) {\r
+    goto Done;\r
+  }\r
+\r
   //\r
   // Send data to SMM.\r
   //\r
index b6dbc839e02356b93c3786b5e00e9d11638c5242..a0d8b2267e920ca110df3f8f7f88a60eebb9fd64 100644 (file)
@@ -60,6 +60,7 @@
   TpmMeasurementLib\r
   SafeIntLib\r
   PcdLib\r
+  MmUnblockMemoryLib\r
 \r
 [Protocols]\r
   gEfiVariableWriteArchProtocolGuid             ## PRODUCES\r