* [PATCH v5 1/7] MdePkg: MmUnblockMemoryLib: Added definition and null instance [not found] <20210304185814.1652-1-kun.q@outlook.com> @ 2021-03-04 18:58 ` Kun Qin 2021-03-04 19:08 ` Laszlo Ersek 2021-03-05 0:23 ` Kun Qin 0 siblings, 2 replies; 5+ messages in thread From: Kun Qin @ 2021-03-04 18:58 UTC (permalink / raw) To: devel Cc: Michael D Kinney, Liming Gao, Zhiguang Liu, Hao A Wu, Jiewen Yao, Laszlo Ersek REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3168 This interface provides an abstration layer to allow MM modules to access requested areas that are outside of MMRAM. On MM model that blocks all non-MMRAM accesses, areas requested through this API will be mapped or unblocked for accessibility 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 accessible from inside MM. Example usages: 1. To enable runtime cache feature for variable service, Variable MM module will need to access the allocated runtime buffer. Thus the agent sets up these buffers, VariableSmmRuntimeDxe, will need to invoke this API to make these regions accessible by Variable MM. 2. For TPM ACPI table to communicate to physical presence handler, the corresponding NVS region has to be accessible from inside MM. Once the NVS region are assigned, it needs to be unblocked thourgh this API. Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Liming Gao <gaoliming@byosoft.com.cn> Cc: Zhiguang Liu <zhiguang.liu@intel.com> Cc: Hao A Wu <hao.a.wu@intel.com> Cc: Jiewen Yao <jiewen.yao@intel.com> Cc: Laszlo Ersek <lersek@redhat.com> Signed-off-by: Kun Qin <kun.q@outlook.com> --- Notes: v5: - Downgraded data types from EFI_* to RETURN_*. [Laszlo] v4: - Added more commit message [Laszlo] - Added UNI file [Hao] v3: - Move interface to MdePkg [Hao, Liming, Jiewen] - Remove Dxe prefix [Jiewen] v2: - Resend with practical usage. No change [Hao] MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.c | 44 ++++++++++++++++++++ MdePkg/Include/Library/MmUnblockMemoryLib.h | 44 ++++++++++++++++++++ MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.inf | 34 +++++++++++++++ MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.uni | 21 ++++++++++ MdePkg/MdePkg.dec | 5 +++ MdePkg/MdePkg.dsc | 1 + 6 files changed, 149 insertions(+) diff --git a/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.c b/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.c new file mode 100644 index 000000000000..b205c9122df8 --- /dev/null +++ b/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.c @@ -0,0 +1,44 @@ +/** @file + Null 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. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#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. + +**/ +RETURN_STATUS +EFIAPI +MmUnblockMemoryRequest ( + IN PHYSICAL_ADDRESS UnblockAddress, + IN UINT64 NumberOfPages + ) +{ + return RETURN_UNSUPPORTED; +} diff --git a/MdePkg/Include/Library/MmUnblockMemoryLib.h b/MdePkg/Include/Library/MmUnblockMemoryLib.h new file mode 100644 index 000000000000..00fab530a3bc --- /dev/null +++ b/MdePkg/Include/Library/MmUnblockMemoryLib.h @@ -0,0 +1,44 @@ +/** @file + MM Unblock Memory Library Interface. + + 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. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef MM_UNBLOCK_MEMORY_LIB_H_ +#define MM_UNBLOCK_MEMORY_LIB_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. + +**/ +RETURN_STATUS +EFIAPI +MmUnblockMemoryRequest ( + IN PHYSICAL_ADDRESS UnblockAddress, + IN UINT64 NumberOfPages +); + +#endif // MM_UNBLOCK_MEMORY_LIB_H_ diff --git a/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.inf b/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.inf new file mode 100644 index 000000000000..8ecb767ff7bd --- /dev/null +++ b/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.inf @@ -0,0 +1,34 @@ +## @file +# Null 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. +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +# +## + +[Defines] + INF_VERSION = 0x0001001B + BASE_NAME = MmUnblockMemoryLibNull + MODULE_UNI_FILE = MmUnblockMemoryLibNull.uni + FILE_GUID = 9E890F68-5C95-4C31-95DD-59E6286F85EA + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = MmUnblockMemoryLib + +# +# VALID_ARCHITECTURES = IA32 X64 +# + +[Sources] + MmUnblockMemoryLibNull.c + +[Packages] + MdePkg/MdePkg.dec diff --git a/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.uni b/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.uni new file mode 100644 index 000000000000..d7f2709a3dce --- /dev/null +++ b/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.uni @@ -0,0 +1,21 @@ +// /** @file +// Null 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. +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + + +#string STR_MODULE_ABSTRACT #language en-US "Null instance of MM Unblock Page Library." + +#string STR_MODULE_DESCRIPTION #language en-US "This library provides an interface to request non-MMRAM pages to be mapped/unblocked from inside MM environment.\n" + "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." + diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec index 3928db65d188..32a9e009c813 100644 --- a/MdePkg/MdePkg.dec +++ b/MdePkg/MdePkg.dec @@ -257,6 +257,11 @@ [LibraryClasses] # UnitTestHostBaseLib|Test/UnitTest/Include/Library/UnitTestHostBaseLib.h + ## @libraryclass This library provides an interface for DXE drivers to request MM environment + # to map/unblock a memory region for accessibility inside MM. + # + MmUnblockMemoryLib|Include/Library/MmUnblockMemoryLib.h + [LibraryClasses.IA32, LibraryClasses.X64] ## @libraryclass Abstracts both S/W SMI generation and detection. ## diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc index ce009086815f..79629e3f93ba 100644 --- a/MdePkg/MdePkg.dsc +++ b/MdePkg/MdePkg.dsc @@ -168,6 +168,7 @@ [Components.IA32, Components.X64] MdePkg/Library/SmmPciExpressLib/SmmPciExpressLib.inf MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.inf MdePkg/Library/MmServicesTableLib/MmServicesTableLib.inf + MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.inf [Components.EBC] MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf -- 2.30.0.windows.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v5 1/7] MdePkg: MmUnblockMemoryLib: Added definition and null instance 2021-03-04 18:58 ` [PATCH v5 1/7] MdePkg: MmUnblockMemoryLib: Added definition and null instance Kun Qin @ 2021-03-04 19:08 ` Laszlo Ersek 2021-03-05 0:23 ` Kun Qin 1 sibling, 0 replies; 5+ messages in thread From: Laszlo Ersek @ 2021-03-04 19:08 UTC (permalink / raw) To: Kun Qin, devel Cc: Michael D Kinney, Liming Gao, Zhiguang Liu, Hao A Wu, Jiewen Yao On 03/04/21 19:58, Kun Qin wrote: > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3168 > > This interface provides an abstration layer to allow MM modules to access > requested areas that are outside of MMRAM. On MM model that blocks all > non-MMRAM accesses, areas requested through this API will be mapped or > unblocked for accessibility 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 accessible from inside MM. > > Example usages: > 1. To enable runtime cache feature for variable service, Variable MM > module will need to access the allocated runtime buffer. Thus the agent > sets up these buffers, VariableSmmRuntimeDxe, will need to invoke this > API to make these regions accessible by Variable MM. > 2. For TPM ACPI table to communicate to physical presence handler, the > corresponding NVS region has to be accessible from inside MM. Once the > NVS region are assigned, it needs to be unblocked thourgh this API. > > Cc: Michael D Kinney <michael.d.kinney@intel.com> > Cc: Liming Gao <gaoliming@byosoft.com.cn> > Cc: Zhiguang Liu <zhiguang.liu@intel.com> > Cc: Hao A Wu <hao.a.wu@intel.com> > Cc: Jiewen Yao <jiewen.yao@intel.com> > Cc: Laszlo Ersek <lersek@redhat.com> > > Signed-off-by: Kun Qin <kun.q@outlook.com> > --- > > Notes: > v5: > - Downgraded data types from EFI_* to RETURN_*. [Laszlo] > > v4: > - Added more commit message [Laszlo] > - Added UNI file [Hao] > > v3: > - Move interface to MdePkg [Hao, Liming, Jiewen] > - Remove Dxe prefix [Jiewen] > > v2: > - Resend with practical usage. No change [Hao] > > MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.c | 44 ++++++++++++++++++++ > MdePkg/Include/Library/MmUnblockMemoryLib.h | 44 ++++++++++++++++++++ > MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.inf | 34 +++++++++++++++ > MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.uni | 21 ++++++++++ > MdePkg/MdePkg.dec | 5 +++ > MdePkg/MdePkg.dsc | 1 + > 6 files changed, 149 insertions(+) > > diff --git a/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.c b/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.c > new file mode 100644 > index 000000000000..b205c9122df8 > --- /dev/null > +++ b/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.c > @@ -0,0 +1,44 @@ > +/** @file > + Null 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. > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > +#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. > + > +**/ > +RETURN_STATUS > +EFIAPI > +MmUnblockMemoryRequest ( > + IN PHYSICAL_ADDRESS UnblockAddress, > + IN UINT64 NumberOfPages > + ) > +{ > + return RETURN_UNSUPPORTED; > +} > diff --git a/MdePkg/Include/Library/MmUnblockMemoryLib.h b/MdePkg/Include/Library/MmUnblockMemoryLib.h > new file mode 100644 > index 000000000000..00fab530a3bc > --- /dev/null > +++ b/MdePkg/Include/Library/MmUnblockMemoryLib.h > @@ -0,0 +1,44 @@ > +/** @file > + MM Unblock Memory Library Interface. > + > + 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. > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > +#ifndef MM_UNBLOCK_MEMORY_LIB_H_ > +#define MM_UNBLOCK_MEMORY_LIB_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. > + > +**/ > +RETURN_STATUS > +EFIAPI > +MmUnblockMemoryRequest ( > + IN PHYSICAL_ADDRESS UnblockAddress, > + IN UINT64 NumberOfPages > +); > + > +#endif // MM_UNBLOCK_MEMORY_LIB_H_ > diff --git a/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.inf b/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.inf > new file mode 100644 > index 000000000000..8ecb767ff7bd > --- /dev/null > +++ b/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.inf > @@ -0,0 +1,34 @@ > +## @file > +# Null 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. > +# SPDX-License-Identifier: BSD-2-Clause-Patent > +# > +# > +## > + > +[Defines] > + INF_VERSION = 0x0001001B > + BASE_NAME = MmUnblockMemoryLibNull > + MODULE_UNI_FILE = MmUnblockMemoryLibNull.uni > + FILE_GUID = 9E890F68-5C95-4C31-95DD-59E6286F85EA > + MODULE_TYPE = BASE > + VERSION_STRING = 1.0 > + LIBRARY_CLASS = MmUnblockMemoryLib > + > +# > +# VALID_ARCHITECTURES = IA32 X64 > +# > + > +[Sources] > + MmUnblockMemoryLibNull.c > + > +[Packages] > + MdePkg/MdePkg.dec > diff --git a/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.uni b/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.uni > new file mode 100644 > index 000000000000..d7f2709a3dce > --- /dev/null > +++ b/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.uni > @@ -0,0 +1,21 @@ > +// /** @file > +// Null 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. > +// SPDX-License-Identifier: BSD-2-Clause-Patent > +// > +// **/ > + > + > +#string STR_MODULE_ABSTRACT #language en-US "Null instance of MM Unblock Page Library." > + > +#string STR_MODULE_DESCRIPTION #language en-US "This library provides an interface to request non-MMRAM pages to be mapped/unblocked from inside MM environment.\n" > + "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." > + > diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec > index 3928db65d188..32a9e009c813 100644 > --- a/MdePkg/MdePkg.dec > +++ b/MdePkg/MdePkg.dec > @@ -257,6 +257,11 @@ [LibraryClasses] > # > UnitTestHostBaseLib|Test/UnitTest/Include/Library/UnitTestHostBaseLib.h > > + ## @libraryclass This library provides an interface for DXE drivers to request MM environment > + # to map/unblock a memory region for accessibility inside MM. > + # > + MmUnblockMemoryLib|Include/Library/MmUnblockMemoryLib.h > + > [LibraryClasses.IA32, LibraryClasses.X64] > ## @libraryclass Abstracts both S/W SMI generation and detection. > ## > diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc > index ce009086815f..79629e3f93ba 100644 > --- a/MdePkg/MdePkg.dsc > +++ b/MdePkg/MdePkg.dsc > @@ -168,6 +168,7 @@ [Components.IA32, Components.X64] > MdePkg/Library/SmmPciExpressLib/SmmPciExpressLib.inf > MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.inf > MdePkg/Library/MmServicesTableLib/MmServicesTableLib.inf > + MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.inf > > [Components.EBC] > MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf > Acked-by: Laszlo Ersek <lersek@redhat.com> ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v5 1/7] MdePkg: MmUnblockMemoryLib: Added definition and null instance 2021-03-04 18:58 ` [PATCH v5 1/7] MdePkg: MmUnblockMemoryLib: Added definition and null instance Kun Qin 2021-03-04 19:08 ` Laszlo Ersek @ 2021-03-05 0:23 ` Kun Qin 2021-03-05 3:15 ` 回复: [edk2-devel] " gaoliming 1 sibling, 1 reply; 5+ messages in thread From: Kun Qin @ 2021-03-05 0:23 UTC (permalink / raw) To: devel@edk2.groups.io, Michael D Kinney, gaoliming, Zhiguang Liu Cc: Hao A Wu, Jiewen Yao, Laszlo Ersek [-- Attachment #1: Type: text/plain, Size: 10938 bytes --] Hi Mike/Liming/Zhiguang, Could you please review this patch and let me know if you have any feedback on this patch? Any input is appreciated. Regards, Kun From: Kun Qin<mailto:kun.q@outlook.com> Sent: Thursday, March 4, 2021 10:58 To: devel@edk2.groups.io<mailto:devel@edk2.groups.io> Cc: Michael D Kinney<mailto:michael.d.kinney@intel.com>; Liming Gao<mailto:gaoliming@byosoft.com.cn>; Zhiguang Liu<mailto:zhiguang.liu@intel.com>; Hao A Wu<mailto:hao.a.wu@intel.com>; Jiewen Yao<mailto:jiewen.yao@intel.com>; Laszlo Ersek<mailto:lersek@redhat.com> Subject: [PATCH v5 1/7] MdePkg: MmUnblockMemoryLib: Added definition and null instance REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3168 This interface provides an abstration layer to allow MM modules to access requested areas that are outside of MMRAM. On MM model that blocks all non-MMRAM accesses, areas requested through this API will be mapped or unblocked for accessibility 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 accessible from inside MM. Example usages: 1. To enable runtime cache feature for variable service, Variable MM module will need to access the allocated runtime buffer. Thus the agent sets up these buffers, VariableSmmRuntimeDxe, will need to invoke this API to make these regions accessible by Variable MM. 2. For TPM ACPI table to communicate to physical presence handler, the corresponding NVS region has to be accessible from inside MM. Once the NVS region are assigned, it needs to be unblocked thourgh this API. Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Liming Gao <gaoliming@byosoft.com.cn> Cc: Zhiguang Liu <zhiguang.liu@intel.com> Cc: Hao A Wu <hao.a.wu@intel.com> Cc: Jiewen Yao <jiewen.yao@intel.com> Cc: Laszlo Ersek <lersek@redhat.com> Signed-off-by: Kun Qin <kun.q@outlook.com> --- Notes: v5: - Downgraded data types from EFI_* to RETURN_*. [Laszlo] v4: - Added more commit message [Laszlo] - Added UNI file [Hao] v3: - Move interface to MdePkg [Hao, Liming, Jiewen] - Remove Dxe prefix [Jiewen] v2: - Resend with practical usage. No change [Hao] MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.c | 44 ++++++++++++++++++++ MdePkg/Include/Library/MmUnblockMemoryLib.h | 44 ++++++++++++++++++++ MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.inf | 34 +++++++++++++++ MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.uni | 21 ++++++++++ MdePkg/MdePkg.dec | 5 +++ MdePkg/MdePkg.dsc | 1 + 6 files changed, 149 insertions(+) diff --git a/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.c b/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.c new file mode 100644 index 000000000000..b205c9122df8 --- /dev/null +++ b/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.c @@ -0,0 +1,44 @@ +/** @file + Null 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. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#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. + +**/ +RETURN_STATUS +EFIAPI +MmUnblockMemoryRequest ( + IN PHYSICAL_ADDRESS UnblockAddress, + IN UINT64 NumberOfPages + ) +{ + return RETURN_UNSUPPORTED; +} diff --git a/MdePkg/Include/Library/MmUnblockMemoryLib.h b/MdePkg/Include/Library/MmUnblockMemoryLib.h new file mode 100644 index 000000000000..00fab530a3bc --- /dev/null +++ b/MdePkg/Include/Library/MmUnblockMemoryLib.h @@ -0,0 +1,44 @@ +/** @file + MM Unblock Memory Library Interface. + + 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. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef MM_UNBLOCK_MEMORY_LIB_H_ +#define MM_UNBLOCK_MEMORY_LIB_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. + +**/ +RETURN_STATUS +EFIAPI +MmUnblockMemoryRequest ( + IN PHYSICAL_ADDRESS UnblockAddress, + IN UINT64 NumberOfPages +); + +#endif // MM_UNBLOCK_MEMORY_LIB_H_ diff --git a/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.inf b/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.inf new file mode 100644 index 000000000000..8ecb767ff7bd --- /dev/null +++ b/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.inf @@ -0,0 +1,34 @@ +## @file +# Null 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. +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +# +## + +[Defines] + INF_VERSION = 0x0001001B + BASE_NAME = MmUnblockMemoryLibNull + MODULE_UNI_FILE = MmUnblockMemoryLibNull.uni + FILE_GUID = 9E890F68-5C95-4C31-95DD-59E6286F85EA + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = MmUnblockMemoryLib + +# +# VALID_ARCHITECTURES = IA32 X64 +# + +[Sources] + MmUnblockMemoryLibNull.c + +[Packages] + MdePkg/MdePkg.dec diff --git a/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.uni b/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.uni new file mode 100644 index 000000000000..d7f2709a3dce --- /dev/null +++ b/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.uni @@ -0,0 +1,21 @@ +// /** @file +// Null 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. +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + + +#string STR_MODULE_ABSTRACT #language en-US "Null instance of MM Unblock Page Library." + +#string STR_MODULE_DESCRIPTION #language en-US "This library provides an interface to request non-MMRAM pages to be mapped/unblocked from inside MM environment.\n" + "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." + diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec index 3928db65d188..32a9e009c813 100644 --- a/MdePkg/MdePkg.dec +++ b/MdePkg/MdePkg.dec @@ -257,6 +257,11 @@ [LibraryClasses] # UnitTestHostBaseLib|Test/UnitTest/Include/Library/UnitTestHostBaseLib.h + ## @libraryclass This library provides an interface for DXE drivers to request MM environment + # to map/unblock a memory region for accessibility inside MM. + # + MmUnblockMemoryLib|Include/Library/MmUnblockMemoryLib.h + [LibraryClasses.IA32, LibraryClasses.X64] ## @libraryclass Abstracts both S/W SMI generation and detection. ## diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc index ce009086815f..79629e3f93ba 100644 --- a/MdePkg/MdePkg.dsc +++ b/MdePkg/MdePkg.dsc @@ -168,6 +168,7 @@ [Components.IA32, Components.X64] MdePkg/Library/SmmPciExpressLib/SmmPciExpressLib.inf MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.inf MdePkg/Library/MmServicesTableLib/MmServicesTableLib.inf + MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.inf [Components.EBC] MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf -- 2.30.0.windows.1 [-- Attachment #2: Type: text/html, Size: 18687 bytes --] ^ permalink raw reply related [flat|nested] 5+ messages in thread
* 回复: [edk2-devel] [PATCH v5 1/7] MdePkg: MmUnblockMemoryLib: Added definition and null instance 2021-03-05 0:23 ` Kun Qin @ 2021-03-05 3:15 ` gaoliming 2021-03-05 4:09 ` Kun Qin 0 siblings, 1 reply; 5+ messages in thread From: gaoliming @ 2021-03-05 3:15 UTC (permalink / raw) To: devel, kun.q, 'Michael D Kinney', 'Zhiguang Liu' Cc: 'Hao A Wu', 'Jiewen Yao', 'Laszlo Ersek' [-- Attachment #1: Type: text/plain, Size: 12006 bytes --] Kun: I have one minor comment. Please see it. Thanks Liming 发件人: devel@edk2.groups.io <devel@edk2.groups.io> 代表 Kun Qin 发送时间: 2021年3月5日 8:23 收件人: devel@edk2.groups.io; Michael D Kinney <michael.d.kinney@intel.com>; gaoliming <gaoliming@byosoft.com.cn>; Zhiguang Liu <zhiguang.liu@intel.com> 抄送: Hao A Wu <hao.a.wu@intel.com>; Jiewen Yao <jiewen.yao@intel.com>; Laszlo Ersek <lersek@redhat.com> 主题: Re: [edk2-devel] [PATCH v5 1/7] MdePkg: MmUnblockMemoryLib: Added definition and null instance Hi Mike/Liming/Zhiguang, Could you please review this patch and let me know if you have any feedback on this patch? Any input is appreciated. Regards, Kun From: Kun Qin <mailto:kun.q@outlook.com> Sent: Thursday, March 4, 2021 10:58 To: devel@edk2.groups.io <mailto:devel@edk2.groups.io> Cc: Michael D Kinney <mailto:michael.d.kinney@intel.com> ; Liming Gao <mailto:gaoliming@byosoft.com.cn> ; Zhiguang Liu <mailto:zhiguang.liu@intel. com> ; Hao A Wu <mailto:hao.a.wu@intel.com> ; Jiewen Yao <mailto:jiewen.yao@intel.com> ; Laszlo Ersek <mailto:lersek@redhat.com> Subject: [PATCH v5 1/7] MdePkg: MmUnblockMemoryLib: Added definition and null instance REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3168 This interface provides an abstration layer to allow MM modules to access requested areas that are outside of MMRAM. On MM model that blocks all non-MMRAM accesses, areas requested through this API will be mapped or unblocked for accessibility 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 accessible from inside MM. Example usages: 1. To enable runtime cache feature for variable service, Variable MM module will need to access the allocated runtime buffer. Thus the agent sets up these buffers, VariableSmmRuntimeDxe, will need to invoke this API to make these regions accessible by Variable MM. 2. For TPM ACPI table to communicate to physical presence handler, the corresponding NVS region has to be accessible from inside MM. Once the NVS region are assigned, it needs to be unblocked thourgh this API. Cc: Michael D Kinney <michael.d.kinney@intel.com <mailto:michael.d.kinney@intel.com> > Cc: Liming Gao <gaoliming@byosoft.com.cn <mailto:gaoliming@byosoft.com.cn> > Cc: Zhiguang Liu <zhiguang.liu@intel.com <mailto:zhiguang.liu@intel.com> > Cc: Hao A Wu <hao.a.wu@intel.com <mailto:hao.a.wu@intel.com> > Cc: Jiewen Yao <jiewen.yao@intel.com <mailto:jiewen.yao@intel.com> > Cc: Laszlo Ersek <lersek@redhat.com <mailto:lersek@redhat.com> > Signed-off-by: Kun Qin <kun.q@outlook.com <mailto:kun.q@outlook.com> > --- Notes: v5: - Downgraded data types from EFI_* to RETURN_*. [Laszlo] v4: - Added more commit message [Laszlo] - Added UNI file [Hao] v3: - Move interface to MdePkg [Hao, Liming, Jiewen] - Remove Dxe prefix [Jiewen] v2: - Resend with practical usage. No change [Hao] MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.c | 44 ++++++++++++++++++++ MdePkg/Include/Library/MmUnblockMemoryLib.h | 44 ++++++++++++++++++++ MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.inf | 34 +++++++++++++++ MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.uni | 21 ++++++++++ MdePkg/MdePkg.dec | 5 +++ MdePkg/MdePkg.dsc | 1 + 6 files changed, 149 insertions(+) diff --git a/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.c b/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.c new file mode 100644 index 000000000000..b205c9122df8 --- /dev/null +++ b/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.c @@ -0,0 +1,44 @@ +/** @file + Null 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. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#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. + +**/ +RETURN_STATUS +EFIAPI +MmUnblockMemoryRequest ( + IN PHYSICAL_ADDRESS UnblockAddress, + IN UINT64 NumberOfPages + ) +{ + return RETURN_UNSUPPORTED; +} diff --git a/MdePkg/Include/Library/MmUnblockMemoryLib.h b/MdePkg/Include/Library/MmUnblockMemoryLib.h new file mode 100644 index 000000000000..00fab530a3bc --- /dev/null +++ b/MdePkg/Include/Library/MmUnblockMemoryLib.h @@ -0,0 +1,44 @@ +/** @file + MM Unblock Memory Library Interface. + + 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. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef MM_UNBLOCK_MEMORY_LIB_H_ +#define MM_UNBLOCK_MEMORY_LIB_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. + +**/ +RETURN_STATUS +EFIAPI +MmUnblockMemoryRequest ( + IN PHYSICAL_ADDRESS UnblockAddress, + IN UINT64 NumberOfPages +); + +#endif // MM_UNBLOCK_MEMORY_LIB_H_ diff --git a/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.inf b/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.inf new file mode 100644 index 000000000000..8ecb767ff7bd --- /dev/null +++ b/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.inf @@ -0,0 +1,34 @@ +## @file +# Null 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. +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +# +## + +[Defines] + INF_VERSION = 0x0001001B + BASE_NAME = MmUnblockMemoryLibNull + MODULE_UNI_FILE = MmUnblockMemoryLibNull.uni + FILE_GUID = 9E890F68-5C95-4C31-95DD-59E6286F85EA + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = MmUnblockMemoryLib + +# +# VALID_ARCHITECTURES = IA32 X64 +# + +[Sources] + MmUnblockMemoryLibNull.c + +[Packages] + MdePkg/MdePkg.dec diff --git a/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.uni b/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.uni new file mode 100644 index 000000000000..d7f2709a3dce --- /dev/null +++ b/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.uni @@ -0,0 +1,21 @@ +// /** @file +// Null 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. +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + + +#string STR_MODULE_ABSTRACT #language en-US "Null instance of MM Unblock Page Library." + +#string STR_MODULE_DESCRIPTION #language en-US "This library provides an interface to request non-MMRAM pages to be mapped/unblocked from inside MM environment.\n" + "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." + diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec index 3928db65d188..32a9e009c813 100644 --- a/MdePkg/MdePkg.dec +++ b/MdePkg/MdePkg.dec @@ -257,6 +257,11 @@ [LibraryClasses] # UnitTestHostBaseLib|Test/UnitTest/Include/Library/UnitTestHostBaseLib.h + ## @libraryclass This library provides an interface for DXE drivers to request MM environment + # to map/unblock a memory region for accessibility inside MM. [Liming] Is this library for DXE driver only? If not, please update this comments. Other part is good to me. Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn> Thanks Liming + # + MmUnblockMemoryLib|Include/Library/MmUnblockMemoryLib.h + [LibraryClasses.IA32, LibraryClasses.X64] ## @libraryclass Abstracts both S/W SMI generation and detection. ## diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc index ce009086815f..79629e3f93ba 100644 --- a/MdePkg/MdePkg.dsc +++ b/MdePkg/MdePkg.dsc @@ -168,6 +168,7 @@ [Components.IA32, Components.X64] MdePkg/Library/SmmPciExpressLib/SmmPciExpressLib.inf MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.inf MdePkg/Library/MmServicesTableLib/MmServicesTableLib.inf + MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.inf [Components.EBC] MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf -- 2.30.0.windows.1 [-- Attachment #2: Type: text/html, Size: 21931 bytes --] ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [edk2-devel] [PATCH v5 1/7] MdePkg: MmUnblockMemoryLib: Added definition and null instance 2021-03-05 3:15 ` 回复: [edk2-devel] " gaoliming @ 2021-03-05 4:09 ` Kun Qin 0 siblings, 0 replies; 5+ messages in thread From: Kun Qin @ 2021-03-05 4:09 UTC (permalink / raw) To: devel@edk2.groups.io, gaoliming@byosoft.com.cn, 'Michael D Kinney', 'Zhiguang Liu' Cc: 'Hao A Wu', 'Jiewen Yao', 'Laszlo Ersek' [-- Attachment #1.1: Type: text/plain, Size: 12458 bytes --] Thanks, Liming. I will send the updated patches shortly. Regards, Kun From: gaoliming<mailto:gaoliming@byosoft.com.cn> Sent: Thursday, March 4, 2021 19:15 To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>; kun.q@outlook.com<mailto:kun.q@outlook.com>; 'Michael D Kinney'<mailto:michael.d.kinney@intel.com>; 'Zhiguang Liu'<mailto:zhiguang.liu@intel.com> Cc: 'Hao A Wu'<mailto:hao.a.wu@intel.com>; 'Jiewen Yao'<mailto:jiewen.yao@intel.com>; 'Laszlo Ersek'<mailto:lersek@redhat.com> Subject: 回复: [edk2-devel] [PATCH v5 1/7] MdePkg: MmUnblockMemoryLib: Added definition and null instance Kun: I have one minor comment. Please see it. Thanks Liming 发件人: devel@edk2.groups.io <devel@edk2.groups.io> 代表 Kun Qin 发送时间: 2021年3月5日 8:23 收件人: devel@edk2.groups.io; Michael D Kinney <michael.d.kinney@intel.com>; gaoliming <gaoliming@byosoft.com.cn>; Zhiguang Liu <zhiguang.liu@intel.com> 抄送: Hao A Wu <hao.a.wu@intel.com>; Jiewen Yao <jiewen.yao@intel.com>; Laszlo Ersek <lersek@redhat.com> 主题: Re: [edk2-devel] [PATCH v5 1/7] MdePkg: MmUnblockMemoryLib: Added definition and null instance Hi Mike/Liming/Zhiguang, Could you please review this patch and let me know if you have any feedback on this patch? Any input is appreciated. Regards, Kun From: Kun Qin<mailto:kun.q@outlook.com> Sent: Thursday, March 4, 2021 10:58 To: devel@edk2.groups.io<mailto:devel@edk2.groups.io> Cc: Michael D Kinney<mailto:michael.d.kinney@intel.com>; Liming Gao<mailto:gaoliming@byosoft.com.cn>; Zhiguang Liu<mailto:zhiguang.liu@intel.com>; Hao A Wu<mailto:hao.a.wu@intel.com>; Jiewen Yao<mailto:jiewen.yao@intel.com>; Laszlo Ersek<mailto:lersek@redhat.com> Subject: [PATCH v5 1/7] MdePkg: MmUnblockMemoryLib: Added definition and null instance REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3168 This interface provides an abstration layer to allow MM modules to access requested areas that are outside of MMRAM. On MM model that blocks all non-MMRAM accesses, areas requested through this API will be mapped or unblocked for accessibility 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 accessible from inside MM. Example usages: 1. To enable runtime cache feature for variable service, Variable MM module will need to access the allocated runtime buffer. Thus the agent sets up these buffers, VariableSmmRuntimeDxe, will need to invoke this API to make these regions accessible by Variable MM. 2. For TPM ACPI table to communicate to physical presence handler, the corresponding NVS region has to be accessible from inside MM. Once the NVS region are assigned, it needs to be unblocked thourgh this API. Cc: Michael D Kinney <michael.d.kinney@intel.com<mailto:michael.d.kinney@intel.com>> Cc: Liming Gao <gaoliming@byosoft.com.cn<mailto:gaoliming@byosoft.com.cn>> Cc: Zhiguang Liu <zhiguang.liu@intel.com<mailto:zhiguang.liu@intel.com>> Cc: Hao A Wu <hao.a.wu@intel.com<mailto:hao.a.wu@intel.com>> Cc: Jiewen Yao <jiewen.yao@intel.com<mailto:jiewen.yao@intel.com>> Cc: Laszlo Ersek <lersek@redhat.com<mailto:lersek@redhat.com>> Signed-off-by: Kun Qin <kun.q@outlook.com<mailto:kun.q@outlook.com>> --- Notes: v5: - Downgraded data types from EFI_* to RETURN_*. [Laszlo] v4: - Added more commit message [Laszlo] - Added UNI file [Hao] v3: - Move interface to MdePkg [Hao, Liming, Jiewen] - Remove Dxe prefix [Jiewen] v2: - Resend with practical usage. No change [Hao] MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.c | 44 ++++++++++++++++++++ MdePkg/Include/Library/MmUnblockMemoryLib.h | 44 ++++++++++++++++++++ MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.inf | 34 +++++++++++++++ MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.uni | 21 ++++++++++ MdePkg/MdePkg.dec | 5 +++ MdePkg/MdePkg.dsc | 1 + 6 files changed, 149 insertions(+) diff --git a/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.c b/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.c new file mode 100644 index 000000000000..b205c9122df8 --- /dev/null +++ b/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.c @@ -0,0 +1,44 @@ +/** @file + Null 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. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#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. + +**/ +RETURN_STATUS +EFIAPI +MmUnblockMemoryRequest ( + IN PHYSICAL_ADDRESS UnblockAddress, + IN UINT64 NumberOfPages + ) +{ + return RETURN_UNSUPPORTED; +} diff --git a/MdePkg/Include/Library/MmUnblockMemoryLib.h b/MdePkg/Include/Library/MmUnblockMemoryLib.h new file mode 100644 index 000000000000..00fab530a3bc --- /dev/null +++ b/MdePkg/Include/Library/MmUnblockMemoryLib.h @@ -0,0 +1,44 @@ +/** @file + MM Unblock Memory Library Interface. + + 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. + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef MM_UNBLOCK_MEMORY_LIB_H_ +#define MM_UNBLOCK_MEMORY_LIB_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. + +**/ +RETURN_STATUS +EFIAPI +MmUnblockMemoryRequest ( + IN PHYSICAL_ADDRESS UnblockAddress, + IN UINT64 NumberOfPages +); + +#endif // MM_UNBLOCK_MEMORY_LIB_H_ diff --git a/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.inf b/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.inf new file mode 100644 index 000000000000..8ecb767ff7bd --- /dev/null +++ b/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.inf @@ -0,0 +1,34 @@ +## @file +# Null 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. +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +# +## + +[Defines] + INF_VERSION = 0x0001001B + BASE_NAME = MmUnblockMemoryLibNull + MODULE_UNI_FILE = MmUnblockMemoryLibNull.uni + FILE_GUID = 9E890F68-5C95-4C31-95DD-59E6286F85EA + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = MmUnblockMemoryLib + +# +# VALID_ARCHITECTURES = IA32 X64 +# + +[Sources] + MmUnblockMemoryLibNull.c + +[Packages] + MdePkg/MdePkg.dec diff --git a/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.uni b/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.uni new file mode 100644 index 000000000000..d7f2709a3dce --- /dev/null +++ b/MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.uni @@ -0,0 +1,21 @@ +// /** @file +// Null 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. +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + + +#string STR_MODULE_ABSTRACT #language en-US "Null instance of MM Unblock Page Library." + +#string STR_MODULE_DESCRIPTION #language en-US "This library provides an interface to request non-MMRAM pages to be mapped/unblocked from inside MM environment.\n" + "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." + diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec index 3928db65d188..32a9e009c813 100644 --- a/MdePkg/MdePkg.dec +++ b/MdePkg/MdePkg.dec @@ -257,6 +257,11 @@ [LibraryClasses] # UnitTestHostBaseLib|Test/UnitTest/Include/Library/UnitTestHostBaseLib.h + ## @libraryclass This library provides an interface for DXE drivers to request MM environment + # to map/unblock a memory region for accessibility inside MM. [Liming] Is this library for DXE driver only? If not, please update this comments. Other part is good to me. Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn> Thanks Liming + # + MmUnblockMemoryLib|Include/Library/MmUnblockMemoryLib.h + [LibraryClasses.IA32, LibraryClasses.X64] ## @libraryclass Abstracts both S/W SMI generation and detection. ## diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc index ce009086815f..79629e3f93ba 100644 --- a/MdePkg/MdePkg.dsc +++ b/MdePkg/MdePkg.dsc @@ -168,6 +168,7 @@ [Components.IA32, Components.X64] MdePkg/Library/SmmPciExpressLib/SmmPciExpressLib.inf MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.inf MdePkg/Library/MmServicesTableLib/MmServicesTableLib.inf + MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.inf [Components.EBC] MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf -- 2.30.0.windows.1 [-- Attachment #1.2: Type: text/html, Size: 22785 bytes --] [-- Attachment #2: E026B2D1C91645FFB25B0B59DD9EAEF8.png --] [-- Type: image/png, Size: 140 bytes --] ^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-03-05 4:09 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- [not found] <20210304185814.1652-1-kun.q@outlook.com> 2021-03-04 18:58 ` [PATCH v5 1/7] MdePkg: MmUnblockMemoryLib: Added definition and null instance Kun Qin 2021-03-04 19:08 ` Laszlo Ersek 2021-03-05 0:23 ` Kun Qin 2021-03-05 3:15 ` 回复: [edk2-devel] " gaoliming 2021-03-05 4:09 ` Kun Qin
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox