summaryrefslogtreecommitdiffstats
path: root/UefiCpuPkg/Library
diff options
context:
space:
mode:
authorxieyuanh <yuanhao.xie@intel.com>2024-06-25 11:36:48 +0800
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2024-08-28 15:25:27 +0000
commit8f219119518ea48930c891602fd7609ffb881539 (patch)
tree0d50bb4e5a4e96eb8a41fd81aece43acd62f11d9 /UefiCpuPkg/Library
parent630e819bf3fb4aa3485f29ba498341c8b277e02b (diff)
downloadedk2-8f219119518ea48930c891602fd7609ffb881539.tar.gz
edk2-8f219119518ea48930c891602fd7609ffb881539.tar.bz2
edk2-8f219119518ea48930c891602fd7609ffb881539.zip
UefiCpuPkg: Add MM Unblock Page Library
This library provides an interface to request non-MMRAM pages to be mapped/unblocked from inside MM environment. For MM modules that need to access areas outside of MMRAMs, the agents responsible for setting up these regions must use this API to enable access to these memory areas from within MM. During the IPL, when RestrictedMemoryAccess is enabled, this unblocked memory is specifically used to create a BuildResourceHob, which allocates storage for the SMM accessible DRAM (non-MMIO) range. Cc: Liming Gao <gaoliming@byosoft.com.cn> Cc: Jiaxin Wu <jiaxin.wu@intel.com> Cc: Ray Ni <ray.ni@intel.com> Cc: Ard Biesheuvel <ardb+tianocore@kernel.org> Cc: Sami Mujawar <sami.mujawar@arm.com> Cc: Star Zeng <star.zeng@intel.com> Cc: Hongbin1 Zhang <hongbin1.zhang@intel.com> Cc: Wei6 Xu <wei6.xu@intel.com> Cc: Dun Tan <dun.tan@intel.com> Signed-off-by: Yuanhao Xie <yuanhao.xie@intel.com>
Diffstat (limited to 'UefiCpuPkg/Library')
-rw-r--r--UefiCpuPkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLib.c81
-rw-r--r--UefiCpuPkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLib.inf47
2 files changed, 128 insertions, 0 deletions
diff --git a/UefiCpuPkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLib.c b/UefiCpuPkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLib.c
new file mode 100644
index 0000000000..790392b19d
--- /dev/null
+++ b/UefiCpuPkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLib.c
@@ -0,0 +1,81 @@
+/** @file
+ The instance of MM Unblock Page Library.
+ This library provides an interface to request non-MMRAM pages to be mapped/unblocked
+ from inside MM environment.
+ For MM modules that need to access regions outside of MMRAMs, the agents that set up
+ these regions are responsible for invoking this API in order for these memory areas
+ to be accessed from inside MM.
+
+ Copyright (c) Microsoft Corporation.
+ Copyright (c) 2024, Intel Corporation. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+#include <Uefi.h>
+#include <Guid/MmUnblockRegion.h>
+#include <Ppi/MmCommunication.h>
+#include <Library/HobLib.h>
+#include <Library/DebugLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/PeiServicesLib.h>
+#include <Base.h>
+
+/**
+ This API provides a way to unblock certain data pages to be accessible inside MM environment.
+
+ @param UnblockAddress The address of buffer caller requests to unblock, the address
+ has to be page aligned.
+ @param NumberOfPages The number of pages requested to be unblocked from MM
+ environment.
+ @retval RETURN_SUCCESS The request goes through successfully.
+ @retval RETURN_NOT_AVAILABLE_YET The requested functionality is not produced yet.
+ @retval RETURN_UNSUPPORTED The requested functionality is not supported on current platform.
+ @retval RETURN_SECURITY_VIOLATION The requested address failed to pass security check for
+ unblocking.
+ @retval RETURN_INVALID_PARAMETER Input address either NULL pointer or not page aligned.
+ @retval RETURN_ACCESS_DENIED The request is rejected due to system has passed certain boot
+ phase.
+**/
+EFI_STATUS
+EFIAPI
+MmUnblockMemoryRequest (
+ IN EFI_PHYSICAL_ADDRESS UnblockAddress,
+ IN UINT64 NumberOfPages
+ )
+{
+ EFI_STATUS Status;
+ MM_UNBLOCK_REGION *MmUnblockMemoryHob;
+ EFI_PEI_MM_COMMUNICATION_PPI *MmCommunicationPpi;
+
+ if (!IS_ALIGNED (UnblockAddress, SIZE_4KB)) {
+ DEBUG ((DEBUG_ERROR, "Error: UnblockAddress is not 4KB aligned: %p\n", UnblockAddress));
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // Unblock requests are rejected when MmIpl finishes execution.
+ //
+ Status = PeiServicesLocatePpi (&gEfiPeiMmCommunicationPpiGuid, 0, NULL, (VOID **)&MmCommunicationPpi);
+ if (!EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "Unblock requests are rejected since the MmIpl finishes execution\n"));
+ return RETURN_ACCESS_DENIED;
+ }
+
+ //
+ // Build the GUID'd HOB for MmCore
+ //
+ MmUnblockMemoryHob = BuildGuidHob (&gMmUnblockRegionHobGuid, sizeof (MM_UNBLOCK_REGION));
+ if (MmUnblockMemoryHob == NULL) {
+ DEBUG ((DEBUG_ERROR, "MmUnblockMemoryRequest: Failed to allocate hob for unblocked data parameter!!\n"));
+ return Status;
+ }
+
+ ZeroMem (MmUnblockMemoryHob, sizeof (MM_UNBLOCK_REGION));
+
+ //
+ // Caller ID is filled in.
+ //
+ CopyGuid (&MmUnblockMemoryHob->IdentifierGuid, &gEfiCallerIdGuid);
+ MmUnblockMemoryHob->PhysicalStart = UnblockAddress;
+ MmUnblockMemoryHob->NumberOfPages = NumberOfPages;
+ return EFI_SUCCESS;
+}
diff --git a/UefiCpuPkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLib.inf b/UefiCpuPkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLib.inf
new file mode 100644
index 0000000000..c3c748d398
--- /dev/null
+++ b/UefiCpuPkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLib.inf
@@ -0,0 +1,47 @@
+## @file
+# Instance of MM Unblock Page Library.
+#
+# This library provides an interface to request non-MMRAM pages to be mapped/unblocked
+# from inside MM environment.
+#
+# For MM modules that need to access regions outside of MMRAMs, the agents that set up
+# these regions are responsible for invoking this API in order for these memory areas
+# to be accessed from inside MM.
+#
+# Copyright (c) Microsoft Corporation.
+# Copyright (c) 2024, Intel Corporation. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+#
+##
+
+[Defines]
+ INF_VERSION = 0x0001001B
+ BASE_NAME = MmUnblockMemoryLib
+ FILE_GUID = CBFE5800-70FD-4D9A-AA78-DB617294077E
+ MODULE_TYPE = PEIM
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = MmUnblockMemoryLib
+
+#
+# VALID_ARCHITECTURES = IA32 X64
+#
+
+[Sources]
+ MmUnblockMemoryLib.c
+
+[Packages]
+ UefiCpuPkg/UefiCpuPkg.dec
+ MdePkg/MdePkg.dec
+
+[LibraryClasses]
+ HobLib
+ DebugLib
+ BaseMemoryLib
+ PeiServicesLib
+
+[Ppis]
+ gEfiPeiMmCommunicationPpiGuid
+
+[Guids]
+ gMmUnblockRegionHobGuid