public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v1 01/15] StandaloneMmPkg: StandaloneMmCoreEntryPoint: Extends support for X64
       [not found] <20201218185011.1366-1-kun.q@outlook.com>
@ 2020-12-18 18:49 ` Kun Qin
  2020-12-28  0:11   ` [edk2-devel] " Yao, Jiewen
  2020-12-18 18:49 ` [PATCH v1 02/15] StandaloneMmPkg: StandaloneMmCoreHobLib: Extend support for x64 Mm Core Kun Qin
                   ` (13 subsequent siblings)
  14 siblings, 1 reply; 44+ messages in thread
From: Kun Qin @ 2020-12-18 18:49 UTC (permalink / raw)
  To: devel; +Cc: Ard Biesheuvel, Sami Mujawar, Jiewen Yao, Supreeth Venkatesh

This change extends StandaloneMmCoreEntryPoint library to support X64
architecture.

Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Cc: Sami Mujawar <sami.mujawar@arm.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Supreeth Venkatesh <supreeth.venkatesh@arm.com>

Signed-off-by: Kun Qin <kun.q@outlook.com>
---
 StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/X64/StandaloneMmCoreEntryPoint.c | 71 ++++++++++++++++++++
 StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf   |  3 +
 2 files changed, 74 insertions(+)

diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/X64/StandaloneMmCoreEntryPoint.c b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/X64/StandaloneMmCoreEntryPoint.c
new file mode 100644
index 000000000000..dffa965b8425
--- /dev/null
+++ b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/X64/StandaloneMmCoreEntryPoint.c
@@ -0,0 +1,71 @@
+/** @file
+  Entry point to the Standalone Mm Core.
+
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
+Copyright (c) Microsoft Corporation.
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+
+#include <PiMm.h>
+
+#include <Library/StandaloneMmCoreEntryPoint.h>
+#include <Library/DebugLib.h>
+#include <Library/BaseLib.h>
+
+//
+// Cache copy of HobList pointer.
+//
+VOID *gHobList = NULL;
+
+/**
+  The entry point of PE/COFF Image for the STANDALONE MM Core.
+
+  This function is the entry point for the STANDALONE MM Core. This function is required to call
+  ProcessModuleEntryPointList() and ProcessModuleEntryPointList() is never expected to return.
+  The STANDALONE MM Core is responsible for calling ProcessLibraryConstructorList() as soon as the EFI
+  System Table and the image handle for the STANDALONE MM Core itself have been established.
+  If ProcessModuleEntryPointList() returns, then ASSERT() and halt the system.
+
+  @param  HobStart  Pointer to the beginning of the HOB List passed in from the PEI Phase.
+
+**/
+VOID
+EFIAPI
+_ModuleEntryPoint (
+  IN VOID  *HobStart
+  )
+{
+  //
+  // Cache a pointer to the HobList
+  //
+  gHobList = HobStart;
+
+  //
+  // Call the Standalone MM Core entry point
+  //
+  ProcessModuleEntryPointList (HobStart);
+
+  //
+  // TODO: Set page table here?? AARCH64 has this step for some reason
+  //
+}
+
+
+/**
+  Required by the EBC compiler and identical in functionality to _ModuleEntryPoint().
+
+  This function is required to call _ModuleEntryPoint() passing in HobStart.
+
+  @param  HobStart  Pointer to the beginning of the HOB List passed in from the PEI Phase.
+
+**/
+VOID
+EFIAPI
+EfiMain (
+  IN VOID  *HobStart
+  )
+{
+  _ModuleEntryPoint (HobStart);
+}
diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf
index 7d6ee4e08ecb..3b7629bc8fb9 100644
--- a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf
+++ b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf
@@ -26,6 +26,9 @@ [Sources.AARCH64]
   AArch64/SetPermissions.c
   AArch64/CreateHobList.c
 
+[Sources.X64]
+  X64/StandaloneMmCoreEntryPoint.c
+
 [Packages]
   MdePkg/MdePkg.dec
   MdeModulePkg/MdeModulePkg.dec
-- 
2.28.0.windows.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH v1 02/15] StandaloneMmPkg: StandaloneMmCoreHobLib: Extend support for x64 Mm Core
       [not found] <20201218185011.1366-1-kun.q@outlook.com>
  2020-12-18 18:49 ` [PATCH v1 01/15] StandaloneMmPkg: StandaloneMmCoreEntryPoint: Extends support for X64 Kun Qin
@ 2020-12-18 18:49 ` Kun Qin
  2020-12-28  0:12   ` Yao, Jiewen
  2020-12-18 18:49 ` [PATCH v1 03/15] StandaloneMmPkg: StandaloneMmCoreMemoryAllocationLib: Fix compiler warning Kun Qin
                   ` (12 subsequent siblings)
  14 siblings, 1 reply; 44+ messages in thread
From: Kun Qin @ 2020-12-18 18:49 UTC (permalink / raw)
  To: devel; +Cc: Ard Biesheuvel, Sami Mujawar, Jiewen Yao, Supreeth Venkatesh

This change adds support of x64 version of StandaloneMmCoreHobLib. It
brings in global variable "gHobList" through StandaloneMmCoreEntryPoint
and imports implementation from DxeCoreHobLib.inf to support x64 Mm Core.

Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Cc: Sami Mujawar <sami.mujawar@arm.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Supreeth Venkatesh <supreeth.venkatesh@arm.com>

Signed-off-by: Kun Qin <kun.q@outlook.com>
---
 StandaloneMmPkg/Library/StandaloneMmCoreHobLib/{ => AArch64}/StandaloneMmCoreHobLib.c |   6 +-
 StandaloneMmPkg/Library/StandaloneMmCoreHobLib/{ => X64}/StandaloneMmCoreHobLib.c     | 426 ++++++++++----------
 StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmCoreHobLib.inf             |   8 +-
 3 files changed, 215 insertions(+), 225 deletions(-)

diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmCoreHobLib.c b/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/AArch64/StandaloneMmCoreHobLib.c
similarity index 96%
copy from StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmCoreHobLib.c
copy to StandaloneMmPkg/Library/StandaloneMmCoreHobLib/AArch64/StandaloneMmCoreHobLib.c
index e3d4743b63f2..006bff816e39 100644
--- a/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmCoreHobLib.c
+++ b/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/AArch64/StandaloneMmCoreHobLib.c
@@ -13,14 +13,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 #include <Library/HobLib.h>
 #include <Library/DebugLib.h>
 #include <Library/BaseMemoryLib.h>
+#include <Library/StandaloneMmCoreEntryPoint.h>
 
 #include <Guid/MemoryAllocationHob.h>
 
-//
-// Cache copy of HobList pointer.
-//
-VOID *gHobList = NULL;
-
 /**
   Returns the pointer to the HOB list.
 
diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmCoreHobLib.c b/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/X64/StandaloneMmCoreHobLib.c
similarity index 70%
rename from StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmCoreHobLib.c
rename to StandaloneMmPkg/Library/StandaloneMmCoreHobLib/X64/StandaloneMmCoreHobLib.c
index e3d4743b63f2..69b20bf07a21 100644
--- a/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmCoreHobLib.c
+++ b/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/X64/StandaloneMmCoreHobLib.c
@@ -13,14 +13,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 #include <Library/HobLib.h>
 #include <Library/DebugLib.h>
 #include <Library/BaseMemoryLib.h>
+#include <Library/StandaloneMmCoreEntryPoint.h>
 
 #include <Guid/MemoryAllocationHob.h>
 
-//
-// Cache copy of HobList pointer.
-//
-VOID *gHobList = NULL;
-
 /**
   Returns the pointer to the HOB list.
 
@@ -203,48 +199,13 @@ GetBootModeHob (
   return HandOffHob->BootMode;
 }
 
-VOID *
-CreateHob (
-  IN  UINT16    HobType,
-  IN  UINT16    HobLength
-  )
-{
-  EFI_HOB_HANDOFF_INFO_TABLE  *HandOffHob;
-  EFI_HOB_GENERIC_HEADER      *HobEnd;
-  EFI_PHYSICAL_ADDRESS        FreeMemory;
-  VOID                        *Hob;
-
-  HandOffHob = GetHobList ();
-
-  HobLength = (UINT16)((HobLength + 0x7) & (~0x7));
-
-  FreeMemory = HandOffHob->EfiFreeMemoryTop - HandOffHob->EfiFreeMemoryBottom;
-
-  if (FreeMemory < HobLength) {
-    return NULL;
-  }
-
-  Hob = (VOID*) (UINTN) HandOffHob->EfiEndOfHobList;
-  ((EFI_HOB_GENERIC_HEADER*) Hob)->HobType = HobType;
-  ((EFI_HOB_GENERIC_HEADER*) Hob)->HobLength = HobLength;
-  ((EFI_HOB_GENERIC_HEADER*) Hob)->Reserved = 0;
-
-  HobEnd = (EFI_HOB_GENERIC_HEADER*) ((UINTN)Hob + HobLength);
-  HandOffHob->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd;
-
-  HobEnd->HobType   = EFI_HOB_TYPE_END_OF_HOB_LIST;
-  HobEnd->HobLength = sizeof (EFI_HOB_GENERIC_HEADER);
-  HobEnd->Reserved  = 0;
-  HobEnd++;
-  HandOffHob->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd;
-
-  return Hob;
-}
-
 /**
   Builds a HOB for a loaded PE32 module.
 
   This function builds a HOB for a loaded PE32 module.
+  It can only be invoked during PEI phase;
+  for MM phase, it will ASSERT() because PEI HOB is read-only for MM phase.
+
   If ModuleName is NULL, then ASSERT().
   If there is no additional space for HOB creation, then ASSERT().
 
@@ -263,31 +224,51 @@ BuildModuleHob (
   IN EFI_PHYSICAL_ADDRESS   EntryPoint
   )
 {
-  EFI_HOB_MEMORY_ALLOCATION_MODULE  *Hob;
+  //
+  // PEI HOB is read only for MM phase
+  //
+  ASSERT (FALSE);
+}
 
-  ASSERT (((MemoryAllocationModule & (EFI_PAGE_SIZE - 1)) == 0) &&
-          ((ModuleLength & (EFI_PAGE_SIZE - 1)) == 0));
+/**
+  Builds a HOB that describes a chunk of system memory with Owner GUID.
 
-  Hob = CreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, sizeof (EFI_HOB_MEMORY_ALLOCATION_MODULE));
+  This function builds a HOB that describes a chunk of system memory.
+  It can only be invoked during PEI phase;
+  for MM phase, it will ASSERT() since PEI HOB is read-only for MM phase.
 
-  CopyGuid (&(Hob->MemoryAllocationHeader.Name), &gEfiHobMemoryAllocModuleGuid);
-  Hob->MemoryAllocationHeader.MemoryBaseAddress = MemoryAllocationModule;
-  Hob->MemoryAllocationHeader.MemoryLength      = ModuleLength;
-  Hob->MemoryAllocationHeader.MemoryType        = EfiBootServicesCode;
+  If there is no additional space for HOB creation, then ASSERT().
 
+  @param  ResourceType        The type of resource described by this HOB.
+  @param  ResourceAttribute   The resource attributes of the memory described by this HOB.
+  @param  PhysicalStart       The 64 bit physical address of memory described by this HOB.
+  @param  NumberOfBytes       The length of the memory described by this HOB in bytes.
+  @param  OwnerGUID           GUID for the owner of this resource.
+
+**/
+VOID
+EFIAPI
+BuildResourceDescriptorWithOwnerHob (
+  IN EFI_RESOURCE_TYPE            ResourceType,
+  IN EFI_RESOURCE_ATTRIBUTE_TYPE  ResourceAttribute,
+  IN EFI_PHYSICAL_ADDRESS         PhysicalStart,
+  IN UINT64                       NumberOfBytes,
+  IN EFI_GUID                     *OwnerGUID
+  )
+{
   //
-  // Zero the reserved space to match HOB spec
+  // PEI HOB is read only for MM phase
   //
-  ZeroMem (Hob->MemoryAllocationHeader.Reserved, sizeof (Hob->MemoryAllocationHeader.Reserved));
-
-  CopyGuid (&Hob->ModuleName, ModuleName);
-  Hob->EntryPoint = EntryPoint;
+  ASSERT (FALSE);
 }
 
 /**
   Builds a HOB that describes a chunk of system memory.
 
   This function builds a HOB that describes a chunk of system memory.
+  It can only be invoked during PEI phase;
+  for MM phase, it will ASSERT() because PEI HOB is read-only for MM phase.
+
   If there is no additional space for HOB creation, then ASSERT().
 
   @param  ResourceType        The type of resource described by this HOB.
@@ -305,31 +286,32 @@ BuildResourceDescriptorHob (
   IN UINT64                       NumberOfBytes
   )
 {
-  EFI_HOB_RESOURCE_DESCRIPTOR  *Hob;
-
-  Hob = CreateHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, sizeof (EFI_HOB_RESOURCE_DESCRIPTOR));
-  ASSERT (Hob != NULL);
-
-  Hob->ResourceType      = ResourceType;
-  Hob->ResourceAttribute = ResourceAttribute;
-  Hob->PhysicalStart     = PhysicalStart;
-  Hob->ResourceLength    = NumberOfBytes;
+  //
+  // PEI HOB is read only for MM phase
+  //
+  ASSERT (FALSE);
 }
 
 /**
-  Builds a GUID HOB with a certain data length.
+  Builds a customized HOB tagged with a GUID for identification and returns
+  the start address of GUID HOB data.
 
   This function builds a customized HOB tagged with a GUID for identification
   and returns the start address of GUID HOB data so that caller can fill the customized data.
   The HOB Header and Name field is already stripped.
+  It can only be invoked during PEI phase.
+  For MM phase, it will ASSERT() because PEI HOB is read-only for MM phase.
+
   If Guid is NULL, then ASSERT().
   If there is no additional space for HOB creation, then ASSERT().
-  If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
+  If DataLength > (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
+  HobLength is UINT16 and multiples of 8 bytes, so the max HobLength is 0xFFF8.
 
   @param  Guid          The GUID to tag the customized HOB.
   @param  DataLength    The size of the data payload for the GUID HOB.
 
-  @return The start address of GUID HOB data.
+  @retval  NULL         The GUID HOB could not be allocated.
+  @retval  others       The start address of GUID HOB data.
 
 **/
 VOID *
@@ -339,35 +321,36 @@ BuildGuidHob (
   IN UINTN                       DataLength
   )
 {
-  EFI_HOB_GUID_TYPE *Hob;
-
   //
-  // Make sure that data length is not too long.
+  // PEI HOB is read only for MM phase
   //
-  ASSERT (DataLength <= (0xffff - sizeof (EFI_HOB_GUID_TYPE)));
-
-  Hob = CreateHob (EFI_HOB_TYPE_GUID_EXTENSION, (UINT16) (sizeof (EFI_HOB_GUID_TYPE) + DataLength));
-  CopyGuid (&Hob->Name, Guid);
-  return Hob + 1;
+  ASSERT (FALSE);
+  return NULL;
 }
 
-
 /**
-  Copies a data buffer to a newly-built HOB.
+  Builds a customized HOB tagged with a GUID for identification, copies the input data to the HOB
+  data field, and returns the start address of the GUID HOB data.
 
-  This function builds a customized HOB tagged with a GUID for identification,
-  copies the input data to the HOB data field and returns the start address of the GUID HOB data.
+  This function builds a customized HOB tagged with a GUID for identification and copies the input
+  data to the HOB data field and returns the start address of the GUID HOB data.  It can only be
+  invoked during PEI phase; for MM phase, it will ASSERT() because PEI HOB is read-only for MM phase.
   The HOB Header and Name field is already stripped.
+  It can only be invoked during PEI phase.
+  For MM phase, it will ASSERT() because PEI HOB is read-only for MM phase.
+
   If Guid is NULL, then ASSERT().
   If Data is NULL and DataLength > 0, then ASSERT().
   If there is no additional space for HOB creation, then ASSERT().
-  If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
+  If DataLength > (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
+  HobLength is UINT16 and multiples of 8 bytes, so the max HobLength is 0xFFF8.
 
   @param  Guid          The GUID to tag the customized HOB.
   @param  Data          The data to be copied into the data field of the GUID HOB.
   @param  DataLength    The size of the data payload for the GUID HOB.
 
-  @return The start address of GUID HOB data.
+  @retval  NULL         The GUID HOB could not be allocated.
+  @retval  others       The start address of GUID HOB data.
 
 **/
 VOID *
@@ -378,20 +361,22 @@ BuildGuidDataHob (
   IN UINTN                       DataLength
   )
 {
-  VOID  *HobData;
-
-  ASSERT (Data != NULL || DataLength == 0);
-
-  HobData = BuildGuidHob (Guid, DataLength);
-
-  return CopyMem (HobData, Data, DataLength);
+  //
+  // PEI HOB is read only for MM phase
+  //
+  ASSERT (FALSE);
+  return NULL;
 }
 
 /**
   Builds a Firmware Volume HOB.
 
   This function builds a Firmware Volume HOB.
+  It can only be invoked during PEI phase;
+  for MM phase, it will ASSERT() because PEI HOB is read-only for MM phase.
+
   If there is no additional space for HOB creation, then ASSERT().
+  If the FvImage buffer is not at its required alignment, then ASSERT().
 
   @param  BaseAddress   The base address of the Firmware Volume.
   @param  Length        The size of the Firmware Volume in bytes.
@@ -404,24 +389,25 @@ BuildFvHob (
   IN UINT64                      Length
   )
 {
-  EFI_HOB_FIRMWARE_VOLUME  *Hob;
-
-  Hob = CreateHob (EFI_HOB_TYPE_FV, sizeof (EFI_HOB_FIRMWARE_VOLUME));
-
-  Hob->BaseAddress = BaseAddress;
-  Hob->Length      = Length;
+  //
+  // PEI HOB is read only for MM phase
+  //
+  ASSERT (FALSE);
 }
 
-
 /**
   Builds a EFI_HOB_TYPE_FV2 HOB.
 
   This function builds a EFI_HOB_TYPE_FV2 HOB.
+  It can only be invoked during PEI phase;
+  for MM phase, it will ASSERT() because PEI HOB is read-only for MM phase.
+
   If there is no additional space for HOB creation, then ASSERT().
+  If the FvImage buffer is not at its required alignment, then ASSERT().
 
   @param  BaseAddress   The base address of the Firmware Volume.
   @param  Length        The size of the Firmware Volume in bytes.
-  @param  FvName       The name of the Firmware Volume.
+  @param  FvName        The name of the Firmware Volume.
   @param  FileName      The name of the file.
 
 **/
@@ -434,21 +420,78 @@ BuildFv2Hob (
   IN CONST    EFI_GUID                    *FileName
   )
 {
-  EFI_HOB_FIRMWARE_VOLUME2  *Hob;
+  ASSERT (FALSE);
+}
+
+/**
+  Builds a EFI_HOB_TYPE_FV3 HOB.
+
+  This function builds a EFI_HOB_TYPE_FV3 HOB.
+  It can only be invoked during PEI phase;
+  for MM phase, it will ASSERT() since PEI HOB is read-only for MM phase.
 
-  Hob = CreateHob (EFI_HOB_TYPE_FV2, sizeof (EFI_HOB_FIRMWARE_VOLUME2));
+  If there is no additional space for HOB creation, then ASSERT().
+  If the FvImage buffer is not at its required alignment, then ASSERT().
 
-  Hob->BaseAddress = BaseAddress;
-  Hob->Length      = Length;
-  CopyGuid (&Hob->FvName, FvName);
-  CopyGuid (&Hob->FileName, FileName);
+  @param BaseAddress            The base address of the Firmware Volume.
+  @param Length                 The size of the Firmware Volume in bytes.
+  @param AuthenticationStatus   The authentication status.
+  @param ExtractedFv            TRUE if the FV was extracted as a file within
+                                another firmware volume. FALSE otherwise.
+  @param FvName                 The name of the Firmware Volume.
+                                Valid only if IsExtractedFv is TRUE.
+  @param FileName               The name of the file.
+                                Valid only if IsExtractedFv is TRUE.
+
+**/
+VOID
+EFIAPI
+BuildFv3Hob (
+  IN          EFI_PHYSICAL_ADDRESS        BaseAddress,
+  IN          UINT64                      Length,
+  IN          UINT32                      AuthenticationStatus,
+  IN          BOOLEAN                     ExtractedFv,
+  IN CONST    EFI_GUID                    *FvName, OPTIONAL
+  IN CONST    EFI_GUID                    *FileName OPTIONAL
+  )
+{
+  ASSERT (FALSE);
 }
 
+/**
+  Builds a Capsule Volume HOB.
+
+  This function builds a Capsule Volume HOB.
+  It can only be invoked during PEI phase;
+  for MM phase, it will ASSERT() because PEI HOB is read-only for MM phase.
+
+  If the platform does not support Capsule Volume HOBs, then ASSERT().
+  If there is no additional space for HOB creation, then ASSERT().
+
+  @param  BaseAddress   The base address of the Capsule Volume.
+  @param  Length        The size of the Capsule Volume in bytes.
+
+**/
+VOID
+EFIAPI
+BuildCvHob (
+  IN EFI_PHYSICAL_ADDRESS        BaseAddress,
+  IN UINT64                      Length
+  )
+{
+  //
+  // PEI HOB is read only for MM phase
+  //
+  ASSERT (FALSE);
+}
 
 /**
   Builds a HOB for the CPU.
 
   This function builds a HOB for the CPU.
+  It can only be invoked during PEI phase;
+  for MM phase, it will ASSERT() because PEI HOB is read-only for MM phase.
+
   If there is no additional space for HOB creation, then ASSERT().
 
   @param  SizeOfMemorySpace   The maximum physical memory addressability of the processor.
@@ -462,122 +505,9 @@ BuildCpuHob (
   IN UINT8                       SizeOfIoSpace
   )
 {
-  EFI_HOB_CPU  *Hob;
-
-  Hob = CreateHob (EFI_HOB_TYPE_CPU, sizeof (EFI_HOB_CPU));
-
-  Hob->SizeOfMemorySpace = SizeOfMemorySpace;
-  Hob->SizeOfIoSpace     = SizeOfIoSpace;
-
   //
-  // Zero the reserved space to match HOB spec
+  // PEI HOB is read only for MM phase
   //
-  ZeroMem (Hob->Reserved, sizeof (Hob->Reserved));
-}
-
-/**
-  Builds a HOB for the memory allocation.
-
-  This function builds a HOB for the memory allocation.
-  If there is no additional space for HOB creation, then ASSERT().
-
-  @param  BaseAddress   The 64 bit physical address of the memory.
-  @param  Length        The length of the memory allocation in bytes.
-  @param  MemoryType    Type of memory allocated by this HOB.
-
-**/
-VOID
-EFIAPI
-BuildMemoryAllocationHob (
-  IN EFI_PHYSICAL_ADDRESS        BaseAddress,
-  IN UINT64                      Length,
-  IN EFI_MEMORY_TYPE             MemoryType
-  )
-{
-  EFI_HOB_MEMORY_ALLOCATION  *Hob;
-
-  ASSERT (((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) &&
-          ((Length & (EFI_PAGE_SIZE - 1)) == 0));
-
-  Hob = CreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, sizeof (EFI_HOB_MEMORY_ALLOCATION));
-
-  ZeroMem (&(Hob->AllocDescriptor.Name), sizeof (EFI_GUID));
-  Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;
-  Hob->AllocDescriptor.MemoryLength      = Length;
-  Hob->AllocDescriptor.MemoryType        = MemoryType;
-  //
-  // Zero the reserved space to match HOB spec
-  //
-  ZeroMem (Hob->AllocDescriptor.Reserved, sizeof (Hob->AllocDescriptor.Reserved));
-}
-
-/**
-  Builds a HOB that describes a chunk of system memory with Owner GUID.
-
-  This function builds a HOB that describes a chunk of system memory.
-  If there is no additional space for HOB creation, then ASSERT().
-
-  @param  ResourceType        The type of resource described by this HOB.
-  @param  ResourceAttribute   The resource attributes of the memory described by this HOB.
-  @param  PhysicalStart       The 64 bit physical address of memory described by this HOB.
-  @param  NumberOfBytes       The length of the memory described by this HOB in bytes.
-  @param  OwnerGUID           GUID for the owner of this resource.
-
-**/
-VOID
-EFIAPI
-BuildResourceDescriptorWithOwnerHob (
-  IN EFI_RESOURCE_TYPE            ResourceType,
-  IN EFI_RESOURCE_ATTRIBUTE_TYPE  ResourceAttribute,
-  IN EFI_PHYSICAL_ADDRESS         PhysicalStart,
-  IN UINT64                       NumberOfBytes,
-  IN EFI_GUID                     *OwnerGUID
-  )
-{
-  ASSERT (FALSE);
-}
-
-/**
-  Builds a Capsule Volume HOB.
-
-  This function builds a Capsule Volume HOB.
-  If the platform does not support Capsule Volume HOBs, then ASSERT().
-  If there is no additional space for HOB creation, then ASSERT().
-
-  @param  BaseAddress   The base address of the Capsule Volume.
-  @param  Length        The size of the Capsule Volume in bytes.
-
-**/
-VOID
-EFIAPI
-BuildCvHob (
-  IN EFI_PHYSICAL_ADDRESS        BaseAddress,
-  IN UINT64                      Length
-  )
-{
-  ASSERT (FALSE);
-}
-
-
-/**
-  Builds a HOB for the BSP store.
-
-  This function builds a HOB for BSP store.
-  If there is no additional space for HOB creation, then ASSERT().
-
-  @param  BaseAddress   The 64 bit physical address of the BSP.
-  @param  Length        The length of the BSP store in bytes.
-  @param  MemoryType    Type of memory allocated by this HOB.
-
-**/
-VOID
-EFIAPI
-BuildBspStoreHob (
-  IN EFI_PHYSICAL_ADDRESS        BaseAddress,
-  IN UINT64                      Length,
-  IN EFI_MEMORY_TYPE             MemoryType
-  )
-{
   ASSERT (FALSE);
 }
 
@@ -585,6 +515,9 @@ BuildBspStoreHob (
   Builds a HOB for the Stack.
 
   This function builds a HOB for the stack.
+  It can only be invoked during PEI phase;
+  for MM phase, it will ASSERT() because PEI HOB is read-only for MM phase.
+
   If there is no additional space for HOB creation, then ASSERT().
 
   @param  BaseAddress   The 64 bit physical address of the Stack.
@@ -598,5 +531,64 @@ BuildStackHob (
   IN UINT64                      Length
   )
 {
+  //
+  // PEI HOB is read only for MM phase
+  //
+  ASSERT (FALSE);
+}
+
+/**
+  Builds a HOB for the BSP store.
+
+  This function builds a HOB for BSP store.
+  It can only be invoked during PEI phase;
+  for MM phase, it will ASSERT() because PEI HOB is read-only for MM phase.
+
+  If there is no additional space for HOB creation, then ASSERT().
+
+  @param  BaseAddress   The 64 bit physical address of the BSP.
+  @param  Length        The length of the BSP store in bytes.
+  @param  MemoryType    Type of memory allocated by this HOB.
+
+**/
+VOID
+EFIAPI
+BuildBspStoreHob (
+  IN EFI_PHYSICAL_ADDRESS        BaseAddress,
+  IN UINT64                      Length,
+  IN EFI_MEMORY_TYPE             MemoryType
+  )
+{
+  //
+  // PEI HOB is read only for MM phase
+  //
+  ASSERT (FALSE);
+}
+
+/**
+  Builds a HOB for the memory allocation.
+
+  This function builds a HOB for the memory allocation.
+  It can only be invoked during PEI phase;
+  for MM phase, it will ASSERT() because PEI HOB is read-only for MM phase.
+
+  If there is no additional space for HOB creation, then ASSERT().
+
+  @param  BaseAddress   The 64 bit physical address of the memory.
+  @param  Length        The length of the memory allocation in bytes.
+  @param  MemoryType    Type of memory allocated by this HOB.
+
+**/
+VOID
+EFIAPI
+BuildMemoryAllocationHob (
+  IN EFI_PHYSICAL_ADDRESS        BaseAddress,
+  IN UINT64                      Length,
+  IN EFI_MEMORY_TYPE             MemoryType
+  )
+{
+  //
+  // PEI HOB is read only for MM phase
+  //
   ASSERT (FALSE);
 }
diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmCoreHobLib.inf b/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmCoreHobLib.inf
index 0046cd804def..e43a1e63bf14 100644
--- a/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmCoreHobLib.inf
+++ b/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmCoreHobLib.inf
@@ -22,16 +22,18 @@ [Defines]
   LIBRARY_CLASS                  = HobLib|MM_CORE_STANDALONE
 
 #
-#  VALID_ARCHITECTURES           = AARCH64
+#  VALID_ARCHITECTURES           = X64 AARCH64
 #
-[Sources.Common]
-  StandaloneMmCoreHobLib.c
+[Sources.X64]
+  X64/StandaloneMmCoreHobLib.c
 
 [Sources.AARCH64]
+  AArch64/StandaloneMmCoreHobLib.c
   AArch64/StandaloneMmCoreHobLibInternal.c
 
 [Packages]
   MdePkg/MdePkg.dec
+  StandaloneMmPkg/StandaloneMmPkg.dec
 
 
 [LibraryClasses]
-- 
2.28.0.windows.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH v1 03/15] StandaloneMmPkg: StandaloneMmCoreMemoryAllocationLib: Fix compiler warning
       [not found] <20201218185011.1366-1-kun.q@outlook.com>
  2020-12-18 18:49 ` [PATCH v1 01/15] StandaloneMmPkg: StandaloneMmCoreEntryPoint: Extends support for X64 Kun Qin
  2020-12-18 18:49 ` [PATCH v1 02/15] StandaloneMmPkg: StandaloneMmCoreHobLib: Extend support for x64 Mm Core Kun Qin
@ 2020-12-18 18:49 ` Kun Qin
  2020-12-28  0:14   ` Yao, Jiewen
  2020-12-18 18:50 ` [PATCH v1 04/15] StandaloneMmPkg: StandaloneMmMemLib: Extends support for X64 architecture Kun Qin
                   ` (11 subsequent siblings)
  14 siblings, 1 reply; 44+ messages in thread
From: Kun Qin @ 2020-12-18 18:49 UTC (permalink / raw)
  To: devel; +Cc: Ard Biesheuvel, Sami Mujawar, Jiewen Yao, Supreeth Venkatesh

Assigning MmramRangeCount from MmCorePrivate (UINT64) to local variable
MmramRangeCount (UINT32) will cause compilation failure due to "warning
C4244: '=': conversion from 'UINT64' to 'UINT32', possible loss of data".
This changes defines local MmramRangeCount as UINT64 type.

Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Cc: Sami Mujawar <sami.mujawar@arm.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Supreeth Venkatesh <supreeth.venkatesh@arm.com>

Signed-off-by: Kun Qin <kun.q@outlook.com>
---
 StandaloneMmPkg/Library/StandaloneMmCoreMemoryAllocationLib/StandaloneMmCoreMemoryAllocationLib.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreMemoryAllocationLib/StandaloneMmCoreMemoryAllocationLib.c b/StandaloneMmPkg/Library/StandaloneMmCoreMemoryAllocationLib/StandaloneMmCoreMemoryAllocationLib.c
index eb3d772e18c5..798d546a2037 100644
--- a/StandaloneMmPkg/Library/StandaloneMmCoreMemoryAllocationLib/StandaloneMmCoreMemoryAllocationLib.c
+++ b/StandaloneMmPkg/Library/StandaloneMmCoreMemoryAllocationLib/StandaloneMmCoreMemoryAllocationLib.c
@@ -841,7 +841,7 @@ MemoryAllocationLibConstructor (
   VOID                            *HobStart;
   EFI_MMRAM_HOB_DESCRIPTOR_BLOCK  *MmramRangesHobData;
   EFI_MMRAM_DESCRIPTOR            *MmramRanges;
-  UINT32                           MmramRangeCount;
+  UINT64                           MmramRangeCount;
   EFI_HOB_GUID_TYPE               *MmramRangesHob;
 
   HobStart = GetHobList ();
-- 
2.28.0.windows.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH v1 04/15] StandaloneMmPkg: StandaloneMmMemLib: Extends support for X64 architecture
       [not found] <20201218185011.1366-1-kun.q@outlook.com>
                   ` (2 preceding siblings ...)
  2020-12-18 18:49 ` [PATCH v1 03/15] StandaloneMmPkg: StandaloneMmCoreMemoryAllocationLib: Fix compiler warning Kun Qin
@ 2020-12-18 18:50 ` Kun Qin
  2020-12-28  0:18   ` Yao, Jiewen
  2020-12-18 18:50 ` [PATCH v1 05/15] MdeModulePkg: SmmLockBoxSmmLib: Support StandaloneMm for SmmLockBoxLib Kun Qin
                   ` (10 subsequent siblings)
  14 siblings, 1 reply; 44+ messages in thread
From: Kun Qin @ 2020-12-18 18:50 UTC (permalink / raw)
  To: devel; +Cc: Ard Biesheuvel, Sami Mujawar, Jiewen Yao, Supreeth Venkatesh

This change extends StandaloneMmMemLib library to support X64
architecture. The implementation is ported from MdePkg/Library/SmmMemLib.

Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Cc: Sami Mujawar <sami.mujawar@arm.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Supreeth Venkatesh <supreeth.venkatesh@arm.com>

Signed-off-by: Kun Qin <kun.q@outlook.com>
---
 StandaloneMmPkg/Library/StandaloneMmMemLib/X64/StandaloneMmMemLibInternal.c | 67 ++++++++++++++++++++
 StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.inf           |  6 +-
 2 files changed, 72 insertions(+), 1 deletion(-)

diff --git a/StandaloneMmPkg/Library/StandaloneMmMemLib/X64/StandaloneMmMemLibInternal.c b/StandaloneMmPkg/Library/StandaloneMmMemLib/X64/StandaloneMmMemLibInternal.c
new file mode 100644
index 000000000000..c5e21c583f44
--- /dev/null
+++ b/StandaloneMmPkg/Library/StandaloneMmMemLib/X64/StandaloneMmMemLibInternal.c
@@ -0,0 +1,67 @@
+/** @file
+  Internal ARCH Specific file of MM memory check library.
+
+  MM memory check library implementation. This library consumes MM_ACCESS_PROTOCOL
+  to get MMRAM information. In order to use this library instance, the platform should produce
+  all MMRAM range via MM_ACCESS_PROTOCOL, including the range for firmware (like MM Core
+  and MM driver) and/or specific dedicated hardware.
+
+  Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.<BR>
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/HobLib.h>
+//
+// Maximum support address used to check input buffer
+//
+extern EFI_PHYSICAL_ADDRESS  mMmMemLibInternalMaximumSupportAddress;
+
+/**
+  Calculate and save the maximum support address.
+
+**/
+VOID
+MmMemLibInternalCalculateMaximumSupportAddress (
+  VOID
+  )
+{
+  VOID         *Hob;
+  UINT32       RegEax;
+  UINT8        PhysicalAddressBits;
+
+  //
+  // Get physical address bits supported.
+  //
+  Hob = GetFirstHob (EFI_HOB_TYPE_CPU);
+  if (Hob != NULL) {
+    PhysicalAddressBits = ((EFI_HOB_CPU *) Hob)->SizeOfMemorySpace;
+  } else {
+    AsmCpuid (0x80000000, &RegEax, NULL, NULL, NULL);
+    if (RegEax >= 0x80000008) {
+      AsmCpuid (0x80000008, &RegEax, NULL, NULL, NULL);
+      PhysicalAddressBits = (UINT8) RegEax;
+    } else {
+      PhysicalAddressBits = 36;
+    }
+  }
+  //
+  // IA-32e paging translates 48-bit linear addresses to 52-bit physical addresses.
+  //
+  ASSERT (PhysicalAddressBits <= 52);
+  if (PhysicalAddressBits > 48) {
+    PhysicalAddressBits = 48;
+  }
+
+  //
+  // Save the maximum support address in one global variable
+  //
+  mMmMemLibInternalMaximumSupportAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)(LShiftU64 (1, PhysicalAddressBits) - 1);
+  DEBUG ((DEBUG_INFO, "mMmMemLibInternalMaximumSupportAddress = 0x%lx\n", mMmMemLibInternalMaximumSupportAddress));
+}
+
+
diff --git a/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.inf b/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.inf
index 49da02e54e6d..65ad0a48905c 100644
--- a/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.inf
+++ b/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.inf
@@ -26,12 +26,15 @@ [Defines]
 #
 # The following information is for reference only and not required by the build tools.
 #
-#  VALID_ARCHITECTURES           = AARCH64
+#  VALID_ARCHITECTURES           = X64 AARCH64
 #
 
 [Sources.Common]
   StandaloneMmMemLib.c
 
+[Sources.X64]
+  X64/StandaloneMmMemLibInternal.c
+
 [Sources.AARCH64]
   AArch64/StandaloneMmMemLibInternal.c
 
@@ -42,3 +45,4 @@ [Packages]
 [LibraryClasses]
   BaseMemoryLib
   DebugLib
+  HobLib
-- 
2.28.0.windows.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH v1 05/15] MdeModulePkg: SmmLockBoxSmmLib: Support StandaloneMm for SmmLockBoxLib
       [not found] <20201218185011.1366-1-kun.q@outlook.com>
                   ` (3 preceding siblings ...)
  2020-12-18 18:50 ` [PATCH v1 04/15] StandaloneMmPkg: StandaloneMmMemLib: Extends support for X64 architecture Kun Qin
@ 2020-12-18 18:50 ` Kun Qin
  2020-12-22  8:35   ` [edk2-devel] " Wu, Hao A
  2020-12-18 18:50 ` [PATCH v1 06/15] MdeModulePkg: SmmReportStatusCodeLib: ReportStatusCodeLib in StandaloneMm Kun Qin
                   ` (9 subsequent siblings)
  14 siblings, 1 reply; 44+ messages in thread
From: Kun Qin @ 2020-12-18 18:50 UTC (permalink / raw)
  To: devel; +Cc: Jian J Wang, Hao A Wu, Eric Dong

This change added support of StandaloneMm for SmmLockBoxLib. It replaces
gSmst with gMmst to support both traditional MM and standalone MM. The
contructor and desctructor functions are abstracted to support different
function prototype definitions.

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Eric Dong <eric.dong@intel.com>

Signed-off-by: Kun Qin <kun.q@outlook.com>
---
 MdeModulePkg/Library/SmmLockBoxLib/{SmmLockBoxSmmLib.c => SmmLockBoxMmLib.c}               | 77 +++++++++-----------
 MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxStandaloneMmLib.c                             | 53 ++++++++++++++
 MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxTraditionalMmLib.c                            | 53 ++++++++++++++
 MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxLibPrivate.h                                  | 27 +++++++
 MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.inf                                    | 15 ++--
 MdeModulePkg/Library/SmmLockBoxLib/{SmmLockBoxSmmLib.inf => SmmLockBoxStandaloneMmLib.inf} | 26 ++++---
 MdeModulePkg/MdeModulePkg.dsc                                                              |  2 +
 7 files changed, 193 insertions(+), 60 deletions(-)

diff --git a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.c b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxMmLib.c
similarity index 89%
rename from MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.c
rename to MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxMmLib.c
index 4cc0e8b78e5b..68fcf2a78ed6 100644
--- a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.c
+++ b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxMmLib.c
@@ -6,16 +6,16 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
 
-#include <PiSmm.h>
-#include <Library/SmmServicesTableLib.h>
+#include <PiMm.h>
+#include <Library/MmServicesTableLib.h>
 #include <Library/BaseLib.h>
 #include <Library/BaseMemoryLib.h>
 #include <Library/LockBoxLib.h>
 #include <Library/DebugLib.h>
 #include <Guid/SmmLockBox.h>
 #include <Guid/EndOfS3Resume.h>
-#include <Protocol/SmmReadyToLock.h>
-#include <Protocol/SmmEndOfDxe.h>
+#include <Protocol/MmReadyToLock.h>
+#include <Protocol/MmEndOfDxe.h>
 #include <Protocol/SmmSxDispatch2.h>
 
 #include "SmmLockBoxLibPrivate.h"
@@ -49,13 +49,13 @@ InternalGetSmmLockBoxContext (
   //
   // Check if gEfiSmmLockBoxCommunicationGuid is installed by someone
   //
-  for (Index = 0; Index < gSmst->NumberOfTableEntries; Index++) {
-    if (CompareGuid (&gSmst->SmmConfigurationTable[Index].VendorGuid, &gEfiSmmLockBoxCommunicationGuid)) {
+  for (Index = 0; Index < gMmst->NumberOfTableEntries; Index++) {
+    if (CompareGuid (&gMmst->MmConfigurationTable[Index].VendorGuid, &gEfiSmmLockBoxCommunicationGuid)) {
       //
       // Found. That means some other library instance is already run.
       // No need to install again, just return.
       //
-      return (SMM_LOCK_BOX_CONTEXT *)gSmst->SmmConfigurationTable[Index].VendorTable;
+      return (SMM_LOCK_BOX_CONTEXT *)gMmst->MmConfigurationTable[Index].VendorTable;
     }
   }
 
@@ -142,8 +142,8 @@ SmmLockBoxSmmEndOfDxeNotify (
   //
   // Locate SmmSxDispatch2 protocol.
   //
-  Status = gSmst->SmmLocateProtocol (
-                    &gEfiSmmSxDispatch2ProtocolGuid,
+  Status = gMmst->MmLocateProtocol (
+                    &gEfiMmSxDispatchProtocolGuid,
                     NULL,
                     (VOID **)&SxDispatch
                     );
@@ -191,29 +191,25 @@ SmmLockBoxEndOfS3ResumeNotify (
   Constructor for SmmLockBox library.
   This is used to set SmmLockBox context, which will be used in PEI phase in S3 boot path later.
 
-  @param[in] ImageHandle  Image handle of this driver.
-  @param[in] SystemTable  A Pointer to the EFI System Table.
-
   @retval EFI_SUCEESS
   @return Others          Some error occurs.
 **/
 EFI_STATUS
 EFIAPI
-SmmLockBoxSmmConstructor (
-  IN EFI_HANDLE        ImageHandle,
-  IN EFI_SYSTEM_TABLE  *SystemTable
+SmmLockBoxMmConstructor (
+  VOID
   )
 {
   EFI_STATUS           Status;
   SMM_LOCK_BOX_CONTEXT *SmmLockBoxContext;
 
-  DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib SmmLockBoxSmmConstructor - Enter\n"));
+  DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib SmmLockBoxMmConstructor - Enter\n"));
 
   //
   // Register SmmReadyToLock notification.
   //
-  Status = gSmst->SmmRegisterProtocolNotify (
-                    &gEfiSmmReadyToLockProtocolGuid,
+  Status = gMmst->MmRegisterProtocolNotify (
+                    &gEfiMmReadyToLockProtocolGuid,
                     SmmLockBoxSmmReadyToLockNotify,
                     &mSmmLockBoxRegistrationSmmReadyToLock
                     );
@@ -222,8 +218,8 @@ SmmLockBoxSmmConstructor (
   //
   // Register SmmEndOfDxe notification.
   //
-  Status = gSmst->SmmRegisterProtocolNotify (
-                    &gEfiSmmEndOfDxeProtocolGuid,
+  Status = gMmst->MmRegisterProtocolNotify (
+                    &gEfiMmEndOfDxeProtocolGuid,
                     SmmLockBoxSmmEndOfDxeNotify,
                     &mSmmLockBoxRegistrationSmmEndOfDxe
                     );
@@ -232,7 +228,7 @@ SmmLockBoxSmmConstructor (
   //
   // Register EndOfS3Resume notification.
   //
-  Status = gSmst->SmmRegisterProtocolNotify (
+  Status = gMmst->MmRegisterProtocolNotify (
                     &gEdkiiEndOfS3ResumeGuid,
                     SmmLockBoxEndOfS3ResumeNotify,
                     &mSmmLockBoxRegistrationEndOfS3Resume
@@ -249,7 +245,7 @@ SmmLockBoxSmmConstructor (
     // No need to install again, just return.
     //
     DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib SmmLockBoxContext - already installed\n"));
-    DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib SmmLockBoxSmmConstructor - Exit\n"));
+    DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib SmmLockBoxMmConstructor - Exit\n"));
     return EFI_SUCCESS;
   }
 
@@ -263,8 +259,8 @@ SmmLockBoxSmmConstructor (
   }
   mSmmLockBoxContext.LockBoxDataAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)&mLockBoxQueue;
 
-  Status = gSmst->SmmInstallConfigurationTable (
-                    gSmst,
+  Status = gMmst->MmInstallConfigurationTable (
+                    gMmst,
                     &gEfiSmmLockBoxCommunicationGuid,
                     &mSmmLockBoxContext,
                     sizeof(mSmmLockBoxContext)
@@ -274,7 +270,7 @@ SmmLockBoxSmmConstructor (
 
   DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib SmmLockBoxContext - %x\n", (UINTN)&mSmmLockBoxContext));
   DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib LockBoxDataAddress - %x\n", (UINTN)&mLockBoxQueue));
-  DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib SmmLockBoxSmmConstructor - Exit\n"));
+  DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib SmmLockBoxMmConstructor - Exit\n"));
 
   return Status;
 }
@@ -292,18 +288,17 @@ SmmLockBoxSmmConstructor (
 **/
 EFI_STATUS
 EFIAPI
-SmmLockBoxSmmDestructor (
-  IN EFI_HANDLE         ImageHandle,
-  IN EFI_SYSTEM_TABLE   *SystemTable
+SmmLockBoxMmDestructor (
+  VOID
   )
 {
   EFI_STATUS            Status;
 
-  DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib SmmLockBoxSmmDestructor in %a module\n", gEfiCallerBaseName));
+  DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib SmmLockBoxMmDestructor in %a module\n", gEfiCallerBaseName));
 
   if (mSmmConfigurationTableInstalled) {
-    Status = gSmst->SmmInstallConfigurationTable (
-                      gSmst,
+    Status = gMmst->MmInstallConfigurationTable (
+                      gMmst,
                       &gEfiSmmLockBoxCommunicationGuid,
                       NULL,
                       0
@@ -316,8 +311,8 @@ SmmLockBoxSmmDestructor (
     //
     // Unregister SmmReadyToLock notification.
     //
-    Status = gSmst->SmmRegisterProtocolNotify (
-                      &gEfiSmmReadyToLockProtocolGuid,
+    Status = gMmst->MmRegisterProtocolNotify (
+                      &gEfiMmReadyToLockProtocolGuid,
                       NULL,
                       &mSmmLockBoxRegistrationSmmReadyToLock
                       );
@@ -327,8 +322,8 @@ SmmLockBoxSmmDestructor (
     //
     // Unregister SmmEndOfDxe notification.
     //
-    Status = gSmst->SmmRegisterProtocolNotify (
-                      &gEfiSmmEndOfDxeProtocolGuid,
+    Status = gMmst->MmRegisterProtocolNotify (
+                      &gEfiMmEndOfDxeProtocolGuid,
                       NULL,
                       &mSmmLockBoxRegistrationSmmEndOfDxe
                       );
@@ -338,7 +333,7 @@ SmmLockBoxSmmDestructor (
     //
     // Unregister EndOfS3Resume notification.
     //
-    Status = gSmst->SmmRegisterProtocolNotify (
+    Status = gMmst->MmRegisterProtocolNotify (
                       &gEdkiiEndOfS3ResumeGuid,
                       NULL,
                       &mSmmLockBoxRegistrationEndOfS3Resume
@@ -453,7 +448,7 @@ SaveLockBox (
   //
   // Allocate SMRAM buffer
   //
-  Status = gSmst->SmmAllocatePages (
+  Status = gMmst->MmAllocatePages (
                     AllocateAnyPages,
                     EfiRuntimeServicesData,
                     EFI_SIZE_TO_PAGES (Length),
@@ -468,14 +463,14 @@ SaveLockBox (
   //
   // Allocate LockBox
   //
-  Status = gSmst->SmmAllocatePool (
+  Status = gMmst->MmAllocatePool (
                     EfiRuntimeServicesData,
                     sizeof(*LockBox),
                     (VOID **)&LockBox
                     );
   ASSERT_EFI_ERROR (Status);
   if (EFI_ERROR (Status)) {
-    gSmst->SmmFreePages (SmramBuffer, EFI_SIZE_TO_PAGES (Length));
+    gMmst->MmFreePages (SmramBuffer, EFI_SIZE_TO_PAGES (Length));
     DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib SaveLockBox - Exit (%r)\n", EFI_OUT_OF_RESOURCES));
     return EFI_OUT_OF_RESOURCES;
   }
@@ -662,7 +657,7 @@ UpdateLockBox (
           DEBUG_INFO,
           "SmmLockBoxSmmLib UpdateLockBox - Allocate new buffer to enlarge.\n"
           ));
-        Status = gSmst->SmmAllocatePages (
+        Status = gMmst->MmAllocatePages (
                           AllocateAnyPages,
                           EfiRuntimeServicesData,
                           EFI_SIZE_TO_PAGES (Offset + Length),
@@ -679,7 +674,7 @@ UpdateLockBox (
         //
         CopyMem ((VOID *)(UINTN)SmramBuffer, (VOID *)(UINTN)LockBox->SmramBuffer, (UINTN)LockBox->Length);
         ZeroMem ((VOID *)(UINTN)LockBox->SmramBuffer, (UINTN)LockBox->Length);
-        gSmst->SmmFreePages (LockBox->SmramBuffer, EFI_SIZE_TO_PAGES ((UINTN)LockBox->Length));
+        gMmst->MmFreePages (LockBox->SmramBuffer, EFI_SIZE_TO_PAGES ((UINTN)LockBox->Length));
 
         LockBox->SmramBuffer = SmramBuffer;
       }
diff --git a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxStandaloneMmLib.c b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxStandaloneMmLib.c
new file mode 100644
index 000000000000..722121da430b
--- /dev/null
+++ b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxStandaloneMmLib.c
@@ -0,0 +1,53 @@
+/** @file
+
+Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved.<BR>
+Copyright (c) Microsoft Corporation.
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <PiMm.h>
+
+#include "SmmLockBoxLibPrivate.h"
+
+/**
+  Constructor for SmmLockBox library.
+  This is used to set SmmLockBox context, which will be used in PEI phase in S3 boot path later.
+
+  @param[in] ImageHandle  Image handle of this driver.
+  @param[in] SystemTable  A Pointer to the EFI System Table.
+
+  @retval EFI_SUCEESS
+  @return Others          Some error occurs.
+**/
+EFI_STATUS
+EFIAPI
+SmmLockBoxStandaloneMmConstructor (
+  IN EFI_HANDLE           ImageHandle,
+  IN EFI_MM_SYSTEM_TABLE  *SystemTable
+  )
+{
+  return SmmLockBoxMmConstructor ();
+}
+
+/**
+  Destructor for SmmLockBox library.
+  This is used to uninstall SmmLockBoxCommunication configuration table
+  if it has been installed in Constructor.
+
+  @param[in] ImageHandle    Image handle of this driver.
+  @param[in] SystemTable    A Pointer to the EFI System Table.
+
+  @retval EFI_SUCEESS       The destructor always returns EFI_SUCCESS.
+
+**/
+EFI_STATUS
+EFIAPI
+SmmLockBoxStandaloneMmDestructor (
+  IN EFI_HANDLE             ImageHandle,
+  IN EFI_MM_SYSTEM_TABLE    *SystemTable
+  )
+{
+  return SmmLockBoxMmDestructor ();
+}
diff --git a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxTraditionalMmLib.c b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxTraditionalMmLib.c
new file mode 100644
index 000000000000..a748abb16c54
--- /dev/null
+++ b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxTraditionalMmLib.c
@@ -0,0 +1,53 @@
+/** @file
+
+Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved.<BR>
+Copyright (c) Microsoft Corporation.
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <PiSmm.h>
+
+#include "SmmLockBoxLibPrivate.h"
+
+/**
+  Constructor for SmmLockBox library.
+  This is used to set SmmLockBox context, which will be used in PEI phase in S3 boot path later.
+
+  @param[in] ImageHandle  Image handle of this driver.
+  @param[in] SystemTable  A Pointer to the EFI System Table.
+
+  @retval EFI_SUCEESS
+  @return Others          Some error occurs.
+**/
+EFI_STATUS
+EFIAPI
+SmmLockBoxTraditionalConstructor (
+  IN EFI_HANDLE        ImageHandle,
+  IN EFI_SYSTEM_TABLE  *SystemTable
+  )
+{
+  return SmmLockBoxMmConstructor ();
+}
+
+/**
+  Destructor for SmmLockBox library.
+  This is used to uninstall SmmLockBoxCommunication configuration table
+  if it has been installed in Constructor.
+
+  @param[in] ImageHandle    Image handle of this driver.
+  @param[in] SystemTable    A Pointer to the EFI System Table.
+
+  @retval EFI_SUCEESS       The destructor always returns EFI_SUCCESS.
+
+**/
+EFI_STATUS
+EFIAPI
+SmmLockBoxTraditionalDestructor (
+  IN EFI_HANDLE          ImageHandle,
+  IN EFI_SYSTEM_TABLE    *SystemTable
+  )
+{
+  return SmmLockBoxMmDestructor ();
+}
diff --git a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxLibPrivate.h b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxLibPrivate.h
index 35311cb85d69..f729c6cceeea 100644
--- a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxLibPrivate.h
+++ b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxLibPrivate.h
@@ -43,5 +43,32 @@ typedef struct {
 
 #pragma pack()
 
+/**
+  Constructor for SmmLockBox library.
+  This is used to set SmmLockBox context, which will be used in PEI phase in S3 boot path later.
+
+  @retval EFI_SUCEESS
+  @return Others          Some error occurs.
+**/
+EFI_STATUS
+EFIAPI
+SmmLockBoxMmConstructor (
+  VOID
+  );
+
+/**
+  Destructor for SmmLockBox library.
+  This is used to uninstall SmmLockBoxCommunication configuration table
+  if it has been installed in Constructor.
+
+  @retval EFI_SUCEESS       The destructor always returns EFI_SUCCESS.
+
+**/
+EFI_STATUS
+EFIAPI
+SmmLockBoxMmDestructor (
+  VOID
+  );
+
 #endif
 
diff --git a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.inf b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.inf
index 2b6cc983b988..44f7b63c5d20 100644
--- a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.inf
+++ b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.inf
@@ -15,8 +15,8 @@ [Defines]
   MODULE_TYPE                    = DXE_SMM_DRIVER
   VERSION_STRING                 = 1.0
   LIBRARY_CLASS                  = LockBoxLib|DXE_SMM_DRIVER
-  CONSTRUCTOR                    = SmmLockBoxSmmConstructor
-  DESTRUCTOR                     = SmmLockBoxSmmDestructor
+  CONSTRUCTOR                    = SmmLockBoxTraditionalConstructor
+  DESTRUCTOR                     = SmmLockBoxTraditionalDestructor
 
 #
 # The following information is for reference only and not required by the build tools.
@@ -25,7 +25,8 @@ [Defines]
 #
 
 [Sources]
-  SmmLockBoxSmmLib.c
+  SmmLockBoxTraditionalMmLib.c
+  SmmLockBoxMmLib.c
   SmmLockBoxLibPrivate.h
 
 [Packages]
@@ -33,14 +34,14 @@ [Packages]
   MdeModulePkg/MdeModulePkg.dec
 
 [LibraryClasses]
-  SmmServicesTableLib
+  MmServicesTableLib
   BaseLib
   DebugLib
 
 [Protocols]
-  gEfiSmmReadyToLockProtocolGuid    ## NOTIFY
-  gEfiSmmEndOfDxeProtocolGuid       ## NOTIFY
-  gEfiSmmSxDispatch2ProtocolGuid    ## NOTIFY
+  gEfiMmReadyToLockProtocolGuid    ## NOTIFY
+  gEfiMmEndOfDxeProtocolGuid       ## NOTIFY
+  gEfiMmSxDispatchProtocolGuid     ## NOTIFY
 
 [Guids]
   ## SOMETIMES_CONSUMES   ## UNDEFINED # SmmSystemTable
diff --git a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.inf b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxStandaloneMmLib.inf
similarity index 52%
copy from MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.inf
copy to MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxStandaloneMmLib.inf
index 2b6cc983b988..d46dfb3f9aa8 100644
--- a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.inf
+++ b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxStandaloneMmLib.inf
@@ -2,6 +2,7 @@
 #  SMM LockBox library instance.
 #
 #  Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
+#  Copyright (c) Microsoft Corporation.
 #
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -9,14 +10,14 @@
 
 [Defines]
   INF_VERSION                    = 0x00010005
-  BASE_NAME                      = SmmLockBoxSmmLib
-  MODULE_UNI_FILE                = SmmLockBoxSmmLib.uni
-  FILE_GUID                      = E04894D6-290D-4171-A362-0ACFD939F3C8
-  MODULE_TYPE                    = DXE_SMM_DRIVER
+  BASE_NAME                      = SmmLockBoxStandaloneMmLib
+  FILE_GUID                      = 3C05978B-30CA-4544-9C5A-AB99265EFC31
+  MODULE_TYPE                    = MM_STANDALONE
   VERSION_STRING                 = 1.0
-  LIBRARY_CLASS                  = LockBoxLib|DXE_SMM_DRIVER
-  CONSTRUCTOR                    = SmmLockBoxSmmConstructor
-  DESTRUCTOR                     = SmmLockBoxSmmDestructor
+  PI_SPECIFICATION_VERSION       = 0x00010032
+  LIBRARY_CLASS                  = LockBoxLib|MM_STANDALONE
+  CONSTRUCTOR                    = SmmLockBoxStandaloneMmConstructor
+  DESTRUCTOR                     = SmmLockBoxStandaloneMmDestructor
 
 #
 # The following information is for reference only and not required by the build tools.
@@ -25,7 +26,8 @@ [Defines]
 #
 
 [Sources]
-  SmmLockBoxSmmLib.c
+  SmmLockBoxStandaloneMmLib.c
+  SmmLockBoxMmLib.c
   SmmLockBoxLibPrivate.h
 
 [Packages]
@@ -33,14 +35,14 @@ [Packages]
   MdeModulePkg/MdeModulePkg.dec
 
 [LibraryClasses]
-  SmmServicesTableLib
+  MmServicesTableLib
   BaseLib
   DebugLib
 
 [Protocols]
-  gEfiSmmReadyToLockProtocolGuid    ## NOTIFY
-  gEfiSmmEndOfDxeProtocolGuid       ## NOTIFY
-  gEfiSmmSxDispatch2ProtocolGuid    ## NOTIFY
+  gEfiMmReadyToLockProtocolGuid    ## NOTIFY
+  gEfiMmEndOfDxeProtocolGuid       ## NOTIFY
+  gEfiMmSxDispatchProtocolGuid     ## NOTIFY
 
 [Guids]
   ## SOMETIMES_CONSUMES   ## UNDEFINED # SmmSystemTable
diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc
index 90165ca443bf..cd91a70b4fdd 100644
--- a/MdeModulePkg/MdeModulePkg.dsc
+++ b/MdeModulePkg/MdeModulePkg.dsc
@@ -167,6 +167,7 @@ [LibraryClasses.common.MM_STANDALONE]
   MemoryAllocationLib|MdeModulePkg/Library/BaseMemoryAllocationLibNull/BaseMemoryAllocationLibNull.inf
   StandaloneMmDriverEntryPoint|MdePkg/Library/StandaloneMmDriverEntryPoint/StandaloneMmDriverEntryPoint.inf
   MmServicesTableLib|MdePkg/Library/StandaloneMmServicesTableLib/StandaloneMmServicesTableLib.inf
+  LockBoxLib|MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxStandaloneMmLib.inf
 
 [LibraryClasses.ARM, LibraryClasses.AARCH64]
   ArmLib|ArmPkg/Library/ArmLib/ArmBaseLib.inf
@@ -483,6 +484,7 @@ [Components.IA32, Components.X64]
   MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxPeiLib.inf
   MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.inf
   MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.inf
+  MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxStandaloneMmLib.inf
   MdeModulePkg/Library/SmmCorePlatformHookLibNull/SmmCorePlatformHookLibNull.inf
   MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.inf
   MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaArchCustomDecompressLib.inf
-- 
2.28.0.windows.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH v1 06/15] MdeModulePkg: SmmReportStatusCodeLib: ReportStatusCodeLib in StandaloneMm
       [not found] <20201218185011.1366-1-kun.q@outlook.com>
                   ` (4 preceding siblings ...)
  2020-12-18 18:50 ` [PATCH v1 05/15] MdeModulePkg: SmmLockBoxSmmLib: Support StandaloneMm for SmmLockBoxLib Kun Qin
@ 2020-12-18 18:50 ` Kun Qin
  2020-12-22  8:35   ` [edk2-devel] " Wu, Hao A
  2020-12-18 18:50 ` [PATCH v1 07/15] MdeModulePkg: FirmwarePerformanceDataTable: Added StandaloneMm support Kun Qin
                   ` (8 subsequent siblings)
  14 siblings, 1 reply; 44+ messages in thread
From: Kun Qin @ 2020-12-18 18:50 UTC (permalink / raw)
  To: devel; +Cc: Jian J Wang, Hao A Wu, Dandan Bi, Liming Gao

This change added support of StandaloneMm for ReportStatusCodeLib. It
adds a new instance of ReportStatusCodeLib for MM_STANDALONE type, and
abstracts the references of gMmst and gSmst functionalities into separate
files in order to link in proper Service Table for SMM core/drivers.

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Dandan Bi <dandan.bi@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>

Signed-off-by: Kun Qin <kun.q@outlook.com>
---
 MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.c                                               | 16 ++++----
 MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibStandaloneMm.c                                   | 39 ++++++++++++++++++++
 MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibTraditional.c                                    | 39 ++++++++++++++++++++
 MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.h                                               | 37 +++++++++++++++++++
 MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLib.inf                                          |  4 +-
 MdeModulePkg/Library/SmmReportStatusCodeLib/{SmmReportStatusCodeLib.inf => StandaloneMmReportStatusCodeLib.inf} | 17 +++++----
 MdeModulePkg/MdeModulePkg.dsc                                                                                   |  1 +
 7 files changed, 137 insertions(+), 16 deletions(-)

diff --git a/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.c b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.c
index 3a1772538cdf..fb1769db9223 100644
--- a/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.c
+++ b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.c
@@ -1,5 +1,5 @@
 /** @file
-  Report Status Code Library for SMM Phase.
+  Report Status Code Library for MM Phase.
 
   Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
   SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -8,7 +8,7 @@
 
 #include <Library/ReportStatusCodeLib.h>
 #include <Library/DebugLib.h>
-#include <Library/SmmServicesTableLib.h>
+#include <Library/MmServicesTableLib.h>
 #include <Library/BaseLib.h>
 #include <Library/BaseMemoryLib.h>
 #include <Library/PcdLib.h>
@@ -16,10 +16,12 @@
 
 #include <Guid/StatusCodeDataTypeId.h>
 #include <Guid/StatusCodeDataTypeDebug.h>
-#include <Protocol/SmmStatusCode.h>
+#include <Protocol/MmStatusCode.h>
 
-EFI_SMM_REPORT_STATUS_CODE     mReportStatusCode = NULL;
-EFI_SMM_STATUS_CODE_PROTOCOL   *mStatusCodeProtocol = NULL;
+#include "ReportStatusCodeLib.h"
+
+EFI_MM_REPORT_STATUS_CODE     mReportStatusCode = NULL;
+EFI_MM_STATUS_CODE_PROTOCOL   *mStatusCodeProtocol = NULL;
 
 
 /**
@@ -29,14 +31,14 @@ EFI_SMM_STATUS_CODE_PROTOCOL   *mStatusCodeProtocol = NULL;
             NULL is returned if no status code service is available.
 
 **/
-EFI_SMM_REPORT_STATUS_CODE
+EFI_MM_REPORT_STATUS_CODE
 InternalGetReportStatusCode (
   VOID
   )
 {
   EFI_STATUS                    Status;
 
-  Status = gSmst->SmmLocateProtocol (&gEfiSmmStatusCodeProtocolGuid, NULL, (VOID**)&mStatusCodeProtocol);
+  Status = InternalLocateProtocol (&gEfiMmStatusCodeProtocolGuid, NULL, (VOID**)&mStatusCodeProtocol);
   if (!EFI_ERROR (Status) && mStatusCodeProtocol != NULL) {
     return mStatusCodeProtocol->ReportStatusCode;
   }
diff --git a/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibStandaloneMm.c b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibStandaloneMm.c
new file mode 100644
index 000000000000..fc47dffe9ffb
--- /dev/null
+++ b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibStandaloneMm.c
@@ -0,0 +1,39 @@
+/** @file
+  Abstraction layer for MM service table used by MM ReportStatusCodeLib.
+
+  Copyright (c) Microsoft Corporation.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <PiMm.h>
+
+#include <Library/MmServicesTableLib.h>
+
+/**
+  Returns the first protocol instance that matches the given protocol.
+
+  @param[in]  Protocol          Provides the protocol to search for.
+  @param[in]  Registration      Optional registration key returned from
+                                RegisterProtocolNotify().
+  @param[out]  Interface        On return, a pointer to the first interface that matches Protocol and
+                                Registration.
+
+  @retval EFI_SUCCESS           A protocol instance matching Protocol was found and returned in
+                                Interface.
+  @retval EFI_NOT_FOUND         No protocol instances were found that match Protocol and
+                                Registration.
+  @retval EFI_INVALID_PARAMETER Interface is NULL.
+                                Protocol is NULL.
+
+**/
+EFI_STATUS
+EFIAPI
+InternalLocateProtocol (
+  IN  EFI_GUID  *Protocol,
+  IN  VOID      *Registration, OPTIONAL
+  OUT VOID      **Interface
+  )
+{
+  return gMmst->MmLocateProtocol (Protocol, Registration, Interface);
+}
diff --git a/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibTraditional.c b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibTraditional.c
new file mode 100644
index 000000000000..6b3a7c6051c5
--- /dev/null
+++ b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibTraditional.c
@@ -0,0 +1,39 @@
+/** @file
+  Abstraction layer for SMM service table used by SMM ReportStatusCodeLib.
+
+  Copyright (c) Microsoft Corporation.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <PiMm.h>
+
+#include <Library/SmmServicesTableLib.h>
+
+/**
+  Returns the first protocol instance that matches the given protocol.
+
+  @param[in]  Protocol          Provides the protocol to search for.
+  @param[in]  Registration      Optional registration key returned from
+                                RegisterProtocolNotify().
+  @param[out]  Interface        On return, a pointer to the first interface that matches Protocol and
+                                Registration.
+
+  @retval EFI_SUCCESS           A protocol instance matching Protocol was found and returned in
+                                Interface.
+  @retval EFI_NOT_FOUND         No protocol instances were found that match Protocol and
+                                Registration.
+  @retval EFI_INVALID_PARAMETER Interface is NULL.
+                                Protocol is NULL.
+
+**/
+EFI_STATUS
+EFIAPI
+InternalLocateProtocol (
+  IN  EFI_GUID  *Protocol,
+  IN  VOID      *Registration, OPTIONAL
+  OUT VOID      **Interface
+  )
+{
+  return gSmst->SmmLocateProtocol (Protocol, Registration, Interface);
+}
diff --git a/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.h b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.h
new file mode 100644
index 000000000000..9a16741e64f6
--- /dev/null
+++ b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.h
@@ -0,0 +1,37 @@
+/** @file
+  Report Status Code Library for MM Phase.
+
+  Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef _MM_RSC_LIB_H_
+#define _MM_RSC_LIB_H_
+
+/**
+  Returns the first protocol instance that matches the given protocol.
+
+  @param[in]  Protocol          Provides the protocol to search for.
+  @param[in]  Registration      Optional registration key returned from
+                                RegisterProtocolNotify().
+  @param[out]  Interface        On return, a pointer to the first interface that matches Protocol and
+                                Registration.
+
+  @retval EFI_SUCCESS           A protocol instance matching Protocol was found and returned in
+                                Interface.
+  @retval EFI_NOT_FOUND         No protocol instances were found that match Protocol and
+                                Registration.
+  @retval EFI_INVALID_PARAMETER Interface is NULL.
+                                Protocol is NULL.
+
+**/
+EFI_STATUS
+EFIAPI
+InternalLocateProtocol (
+  IN  EFI_GUID  *Protocol,
+  IN  VOID      *Registration, OPTIONAL
+  OUT VOID      **Interface
+  );
+
+#endif // _MM_RSC_LIB_H_
diff --git a/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLib.inf b/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLib.inf
index 72496bfababd..02dce09a199d 100644
--- a/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLib.inf
+++ b/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLib.inf
@@ -28,6 +28,8 @@ [Defines]
 
 [Sources]
   ReportStatusCodeLib.c
+  ReportStatusCodeLib.h
+  ReportStatusCodeLibTraditional.c
 
 [Packages]
   MdePkg/MdePkg.dec
@@ -45,7 +47,7 @@ [Guids]
   gEfiStatusCodeDataTypeDebugGuid               ## SOMETIMES_CONSUMES   ## UNDEFINED
 
 [Protocols]
-  gEfiSmmStatusCodeProtocolGuid                 ## CONSUMES
+  gEfiMmStatusCodeProtocolGuid                  ## CONSUMES
 
 [Pcd]
   gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask  ## CONSUMES
diff --git a/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLib.inf b/MdeModulePkg/Library/SmmReportStatusCodeLib/StandaloneMmReportStatusCodeLib.inf
similarity index 64%
copy from MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLib.inf
copy to MdeModulePkg/Library/SmmReportStatusCodeLib/StandaloneMmReportStatusCodeLib.inf
index 72496bfababd..11ecc67fc4fa 100644
--- a/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLib.inf
+++ b/MdeModulePkg/Library/SmmReportStatusCodeLib/StandaloneMmReportStatusCodeLib.inf
@@ -12,13 +12,12 @@
 
 [Defines]
   INF_VERSION                    = 0x00010005
-  BASE_NAME                      = SmmReportStatusCodeLib
-  MODULE_UNI_FILE                = SmmReportStatusCodeLib.uni
-  FILE_GUID                      = 67089D19-B3D6-4d9e-A0EB-FEDC1F83A1EE
-  MODULE_TYPE                    = DXE_SMM_DRIVER
+  BASE_NAME                      = StandaloneMmReportStatusCodeLib
+  FILE_GUID                      = 17C7FC8C-8C5D-497E-9C0E-C21255B30E04
+  MODULE_TYPE                    = MM_STANDALONE
   VERSION_STRING                 = 1.0
-  PI_SPECIFICATION_VERSION       = 0x0001000A
-  LIBRARY_CLASS                  = ReportStatusCodeLib|DXE_SMM_DRIVER SMM_CORE
+  PI_SPECIFICATION_VERSION       = 0x00010032
+  LIBRARY_CLASS                  = ReportStatusCodeLib|MM_STANDALONE
 
 #
 # The following information is for reference only and not required by the build tools.
@@ -28,6 +27,8 @@ [Defines]
 
 [Sources]
   ReportStatusCodeLib.c
+  ReportStatusCodeLib.h
+  ReportStatusCodeLibStandaloneMm.c
 
 [Packages]
   MdePkg/MdePkg.dec
@@ -36,7 +37,7 @@ [Packages]
 [LibraryClasses]
   PcdLib
   BaseMemoryLib
-  SmmServicesTableLib
+  MmServicesTableLib
   DebugLib
   MemoryAllocationLib
 
@@ -45,7 +46,7 @@ [Guids]
   gEfiStatusCodeDataTypeDebugGuid               ## SOMETIMES_CONSUMES   ## UNDEFINED
 
 [Protocols]
-  gEfiSmmStatusCodeProtocolGuid                 ## CONSUMES
+  gEfiMmStatusCodeProtocolGuid                  ## CONSUMES
 
 [Pcd]
   gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask  ## CONSUMES
diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc
index cd91a70b4fdd..05bf5fe08094 100644
--- a/MdeModulePkg/MdeModulePkg.dsc
+++ b/MdeModulePkg/MdeModulePkg.dsc
@@ -473,6 +473,7 @@ [Components.IA32, Components.X64]
   }
   MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.inf
   MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLib.inf
+  MdeModulePkg/Library/SmmReportStatusCodeLib/StandaloneMmReportStatusCodeLib.inf
   MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSmm.inf
   MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterSmm.inf
   MdeModulePkg/Universal/LockBox/SmmLockBox/SmmLockBox.inf
-- 
2.28.0.windows.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH v1 07/15] MdeModulePkg: FirmwarePerformanceDataTable: Added StandaloneMm support
       [not found] <20201218185011.1366-1-kun.q@outlook.com>
                   ` (5 preceding siblings ...)
  2020-12-18 18:50 ` [PATCH v1 06/15] MdeModulePkg: SmmReportStatusCodeLib: ReportStatusCodeLib in StandaloneMm Kun Qin
@ 2020-12-18 18:50 ` Kun Qin
  2020-12-22  8:36   ` Wu, Hao A
  2020-12-18 18:50 ` [PATCH v1 08/15] MdeModulePkg: ReportStatusCodeRouter: Support StandaloneMm RSC Router Kun Qin
                   ` (7 subsequent siblings)
  14 siblings, 1 reply; 44+ messages in thread
From: Kun Qin @ 2020-12-18 18:50 UTC (permalink / raw)
  To: devel; +Cc: Jian J Wang, Hao A Wu, Dandan Bi, Liming Gao

This change added support of FPDT driver under StandaloneMm. It replaces
SMM version ReportStatusCode protocol with MM version. This patch also
abstracts standalone and traditional MM interfaces into separate files to
support each corresponding function prototypes and implementations.

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Dandan Bi <dandan.bi@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>

Signed-off-by: Kun Qin <kun.q@outlook.com>
---
 MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/{FirmwarePerformanceSmm.c => FirmwarePerformanceCommon.c}           | 72 ++++++++++----------
 MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceStandaloneMm.c                                   | 62 +++++++++++++++++
 MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceTraditional.c                                    | 62 +++++++++++++++++
 MdeModulePkg/MdeModulePkg.dsc                                                                                                   |  2 +
 MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceCommon.h                                         | 55 +++++++++++++++
 MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceSmm.inf                                          | 11 +--
 MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/{FirmwarePerformanceSmm.inf => FirmwarePerformanceStandaloneMm.inf} | 31 ++++-----
 7 files changed, 237 insertions(+), 58 deletions(-)

diff --git a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceSmm.c b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceCommon.c
similarity index 77%
rename from MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceSmm.c
rename to MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceCommon.c
index d6c6e7693e4d..c2aa9455f9c4 100644
--- a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceSmm.c
+++ b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceCommon.c
@@ -1,11 +1,11 @@
 /** @file
-  This module collects performance data for SMM driver boot records and S3 Suspend Performance Record.
+  This module collects performance data for MM driver boot records and S3 Suspend Performance Record.
 
   This module registers report status code listener to collect performance data
-  for SMM driver boot records and S3 Suspend Performance Record.
+  for MM driver boot records and S3 Suspend Performance Record.
 
   Caution: This module requires additional review when modified.
-  This driver will have external input - communicate buffer in SMM mode.
+  This driver will have external input - communicate buffer in MM mode.
   This external input must be validated carefully to avoid security issue like
   buffer overflow, integer overflow.
 
@@ -16,13 +16,13 @@
 
 **/
 
-#include <PiSmm.h>
+#include <PiMm.h>
 
-#include <Protocol/SmmReportStatusCodeHandler.h>
+#include <Protocol/MmReportStatusCodeHandler.h>
 
 #include <Guid/FirmwarePerformance.h>
 
-#include <Library/SmmServicesTableLib.h>
+#include <Library/MmServicesTableLib.h>
 #include <Library/BaseLib.h>
 #include <Library/DebugLib.h>
 #include <Library/TimerLib.h>
@@ -30,23 +30,22 @@
 #include <Library/PcdLib.h>
 #include <Library/BaseMemoryLib.h>
 #include <Library/MemoryAllocationLib.h>
-#include <Library/UefiBootServicesTableLib.h>
 #include <Library/SynchronizationLib.h>
-#include <Library/SmmMemLib.h>
+#include "FirmwarePerformanceCommon.h"
 
-SMM_BOOT_PERFORMANCE_TABLE    *mSmmBootPerformanceTable = NULL;
+SMM_BOOT_PERFORMANCE_TABLE    *mMmBootPerformanceTable = NULL;
 
-EFI_SMM_RSC_HANDLER_PROTOCOL  *mRscHandlerProtocol    = NULL;
+EFI_MM_RSC_HANDLER_PROTOCOL   *mRscHandlerProtocol    = NULL;
 UINT64                        mSuspendStartTime       = 0;
 BOOLEAN                       mS3SuspendLockBoxSaved  = FALSE;
 UINT32                        mBootRecordSize = 0;
 UINT8                         *mBootRecordBuffer = NULL;
 
-SPIN_LOCK                     mSmmFpdtLock;
-BOOLEAN                       mSmramIsOutOfResource = FALSE;
+SPIN_LOCK                     mMmFpdtLock;
+BOOLEAN                       mMmramIsOutOfResource = FALSE;
 
 /**
-  Report status code listener for SMM. This is used to record the performance
+  Report status code listener for MM. This is used to record the performance
   data for S3 Suspend Start and S3 Suspend End in FPDT.
 
   @param[in]  CodeType            Indicates the type of status code being reported.
@@ -66,7 +65,7 @@ BOOLEAN                       mSmramIsOutOfResource = FALSE;
 **/
 EFI_STATUS
 EFIAPI
-FpdtStatusCodeListenerSmm (
+FpdtStatusCodeListenerMm (
   IN EFI_STATUS_CODE_TYPE     CodeType,
   IN EFI_STATUS_CODE_VALUE    Value,
   IN UINT32                   Instance,
@@ -89,19 +88,19 @@ FpdtStatusCodeListenerSmm (
   // Collect one or more Boot records in boot time
   //
   if (Data != NULL && CompareGuid (&Data->Type, &gEdkiiFpdtExtendedFirmwarePerformanceGuid)) {
-    AcquireSpinLock (&mSmmFpdtLock);
+    AcquireSpinLock (&mMmFpdtLock);
     //
     // Get the boot performance data.
     //
-    CopyMem (&mSmmBootPerformanceTable, Data + 1, Data->Size);
-    mBootRecordBuffer = ((UINT8 *) (mSmmBootPerformanceTable)) + sizeof (SMM_BOOT_PERFORMANCE_TABLE);
+    CopyMem (&mMmBootPerformanceTable, Data + 1, Data->Size);
+    mBootRecordBuffer = ((UINT8 *) (mMmBootPerformanceTable)) + sizeof (SMM_BOOT_PERFORMANCE_TABLE);
 
-    ReleaseSpinLock (&mSmmFpdtLock);
+    ReleaseSpinLock (&mMmFpdtLock);
     return EFI_SUCCESS;
   }
 
   if (Data != NULL && CompareGuid (&Data->Type, &gEfiFirmwarePerformanceGuid)) {
-    DEBUG ((DEBUG_ERROR, "FpdtStatusCodeListenerSmm: Performance data reported through gEfiFirmwarePerformanceGuid will not be collected by FirmwarePerformanceDataTableSmm\n"));
+    DEBUG ((DEBUG_ERROR, "FpdtStatusCodeListenerMm: Performance data reported through gEfiFirmwarePerformanceGuid will not be collected by FirmwarePerformanceDataTableMm\n"));
     return EFI_UNSUPPORTED;
   }
 
@@ -157,7 +156,7 @@ FpdtStatusCodeListenerSmm (
 /**
   Communication service SMI Handler entry.
 
-  This SMI handler provides services for report SMM boot records.
+  This SMI handler provides services for report MM boot records.
 
   Caution: This function may receive untrusted input.
   Communicate buffer and buffer size are external input, so this function will do basic validation.
@@ -166,7 +165,7 @@ FpdtStatusCodeListenerSmm (
   @param[in]     RegisterContext Points to an optional handler context which was specified when the
                                  handler was registered.
   @param[in, out] CommBuffer     A pointer to a collection of data in memory that will
-                                 be conveyed from a non-SMM environment into an SMM environment.
+                                 be conveyed from a non-MM environment into an MM environment.
   @param[in, out] CommBufferSize The size of the CommBuffer.
 
   @retval EFI_SUCCESS                         The interrupt was handled and quiesced. No other handlers
@@ -207,8 +206,8 @@ FpdtSmiHandler (
     return EFI_SUCCESS;
   }
 
-  if (!SmmIsBufferOutsideSmmValid ((UINTN)CommBuffer, TempCommBufferSize)) {
-    DEBUG ((EFI_D_ERROR, "FpdtSmiHandler: SMM communication data buffer in SMRAM or overflow!\n"));
+  if (!IsBufferOutsideMmValid ((UINTN)CommBuffer, TempCommBufferSize)) {
+    DEBUG ((DEBUG_ERROR, "FpdtSmiHandler: MM communication data buffer in MMRAM or overflow!\n"));
     return EFI_SUCCESS;
   }
 
@@ -218,8 +217,8 @@ FpdtSmiHandler (
 
   switch (SmmCommData->Function) {
     case SMM_FPDT_FUNCTION_GET_BOOT_RECORD_SIZE :
-      if (mSmmBootPerformanceTable != NULL) {
-        mBootRecordSize = mSmmBootPerformanceTable->Header.Length - sizeof (SMM_BOOT_PERFORMANCE_TABLE);
+      if (mMmBootPerformanceTable != NULL) {
+        mBootRecordSize = mMmBootPerformanceTable->Header.Length - sizeof (SMM_BOOT_PERFORMANCE_TABLE);
       }
       SmmCommData->BootRecordSize = mBootRecordSize;
       break;
@@ -244,8 +243,8 @@ FpdtSmiHandler (
         BootRecordSize = mBootRecordSize - BootRecordOffset;
       }
       SmmCommData->BootRecordSize = BootRecordSize;
-      if (!SmmIsBufferOutsideSmmValid ((UINTN)BootRecordData, BootRecordSize)) {
-        DEBUG ((EFI_D_ERROR, "FpdtSmiHandler: SMM Data buffer in SMRAM or overflow!\n"));
+      if (!IsBufferOutsideMmValid ((UINTN)BootRecordData, BootRecordSize)) {
+        DEBUG ((DEBUG_ERROR, "FpdtSmiHandler: MM Data buffer in MMRAM or overflow!\n"));
         Status = EFI_ACCESS_DENIED;
         break;
       }
@@ -267,7 +266,7 @@ FpdtSmiHandler (
 }
 
 /**
-  The module Entry Point of the Firmware Performance Data Table SMM driver.
+  The module Entry Point of the Firmware Performance Data Table MM driver.
 
   @param[in]  ImageHandle    The firmware allocated handle for the EFI image.
   @param[in]  SystemTable    A pointer to the EFI System Table.
@@ -278,9 +277,8 @@ FpdtSmiHandler (
 **/
 EFI_STATUS
 EFIAPI
-FirmwarePerformanceSmmEntryPoint (
-  IN EFI_HANDLE          ImageHandle,
-  IN EFI_SYSTEM_TABLE    *SystemTable
+FirmwarePerformanceCommonEntryPoint (
+  VOID
   )
 {
   EFI_STATUS                Status;
@@ -289,13 +287,13 @@ FirmwarePerformanceSmmEntryPoint (
   //
   // Initialize spin lock
   //
-  InitializeSpinLock (&mSmmFpdtLock);
+  InitializeSpinLock (&mMmFpdtLock);
 
   //
-  // Get SMM Report Status Code Handler Protocol.
+  // Get MM Report Status Code Handler Protocol.
   //
-  Status = gSmst->SmmLocateProtocol (
-                    &gEfiSmmRscHandlerProtocolGuid,
+  Status = gMmst->MmLocateProtocol (
+                    &gEfiMmRscHandlerProtocolGuid,
                     NULL,
                     (VOID **) &mRscHandlerProtocol
                     );
@@ -304,14 +302,14 @@ FirmwarePerformanceSmmEntryPoint (
   //
   // Register report status code listener for BootRecords and S3 Suspend Start and End.
   //
-  Status = mRscHandlerProtocol->Register (FpdtStatusCodeListenerSmm);
+  Status = mRscHandlerProtocol->Register (FpdtStatusCodeListenerMm);
   ASSERT_EFI_ERROR (Status);
 
   //
   // Register SMI handler.
   //
   Handle = NULL;
-  Status = gSmst->SmiHandlerRegister (FpdtSmiHandler, &gEfiFirmwarePerformanceGuid, &Handle);
+  Status = gMmst->MmiHandlerRegister (FpdtSmiHandler, &gEfiFirmwarePerformanceGuid, &Handle);
   ASSERT_EFI_ERROR (Status);
 
   return Status;
diff --git a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceStandaloneMm.c b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceStandaloneMm.c
new file mode 100644
index 000000000000..2c4f40eceaea
--- /dev/null
+++ b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceStandaloneMm.c
@@ -0,0 +1,62 @@
+/** @file
+  This module collects performance data for MM driver boot records and S3 Suspend Performance Record.
+
+  This module registers report status code listener to collect performance data
+  for MM driver boot records and S3 Suspend Performance Record.
+
+  Caution: This module requires additional review when modified.
+  This driver will have external input - communicate buffer in MM mode.
+  This external input must be validated carefully to avoid security issue like
+  buffer overflow, integer overflow.
+
+  FpdtSmiHandler() will receive untrusted input and do basic validation.
+
+  Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
+  Copyright (c), Microsoft Corporation.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <PiMm.h>
+
+#include <Library/StandaloneMmMemLib.h>
+#include "FirmwarePerformanceCommon.h"
+
+/**
+  This function is an abstraction layer for implementation specific Mm buffer validation routine.
+
+  @param Buffer  The buffer start address to be checked.
+  @param Length  The buffer length to be checked.
+
+  @retval TRUE  This buffer is valid per processor architecture and not overlap with SMRAM.
+  @retval FALSE This buffer is not valid per processor architecture or overlap with SMRAM.
+**/
+BOOLEAN
+EFIAPI
+IsBufferOutsideMmValid (
+  IN EFI_PHYSICAL_ADDRESS  Buffer,
+  IN UINT64                Length
+  )
+{
+  return MmIsBufferOutsideMmValid (Buffer, Length);
+}
+
+/**
+  The module Entry Point of the Firmware Performance Data Table MM driver.
+
+  @param[in]  ImageHandle    The firmware allocated handle for the EFI image.
+  @param[in]  SystemTable    A pointer to the EFI System Table.
+
+  @retval EFI_SUCCESS    The entry point is executed successfully.
+  @retval Other          Some error occurs when executing this entry point.
+
+**/
+EFI_STATUS
+EFIAPI
+FirmwarePerformanceStandaloneMmEntryPoint (
+  IN EFI_HANDLE             ImageHandle,
+  IN EFI_MM_SYSTEM_TABLE    *SystemTable
+  )
+{
+  return FirmwarePerformanceCommonEntryPoint ();
+}
diff --git a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceTraditional.c b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceTraditional.c
new file mode 100644
index 000000000000..507aabcb4e88
--- /dev/null
+++ b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceTraditional.c
@@ -0,0 +1,62 @@
+/** @file
+  This module collects performance data for MM driver boot records and S3 Suspend Performance Record.
+
+  This module registers report status code listener to collect performance data
+  for MM driver boot records and S3 Suspend Performance Record.
+
+  Caution: This module requires additional review when modified.
+  This driver will have external input - communicate buffer in MM mode.
+  This external input must be validated carefully to avoid security issue like
+  buffer overflow, integer overflow.
+
+  FpdtSmiHandler() will receive untrusted input and do basic validation.
+
+  Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
+  Copyright (c), Microsoft Corporation.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <PiSmm.h>
+
+#include <Library/SmmMemLib.h>
+#include "FirmwarePerformanceCommon.h"
+
+/**
+  This function is an abstraction layer for implementation specific Mm buffer validation routine.
+
+  @param Buffer  The buffer start address to be checked.
+  @param Length  The buffer length to be checked.
+
+  @retval TRUE  This buffer is valid per processor architecture and not overlap with SMRAM.
+  @retval FALSE This buffer is not valid per processor architecture or overlap with SMRAM.
+**/
+BOOLEAN
+EFIAPI
+IsBufferOutsideMmValid (
+  IN EFI_PHYSICAL_ADDRESS  Buffer,
+  IN UINT64                Length
+  )
+{
+  return SmmIsBufferOutsideSmmValid (Buffer, Length);
+}
+
+/**
+  The module Entry Point of the Firmware Performance Data Table MM driver.
+
+  @param[in]  ImageHandle    The firmware allocated handle for the EFI image.
+  @param[in]  SystemTable    A pointer to the EFI System Table.
+
+  @retval EFI_SUCCESS    The entry point is executed successfully.
+  @retval Other          Some error occurs when executing this entry point.
+
+**/
+EFI_STATUS
+EFIAPI
+FirmwarePerformanceSmmEntryPoint (
+  IN EFI_HANDLE          ImageHandle,
+  IN EFI_SYSTEM_TABLE    *SystemTable
+  )
+{
+  return FirmwarePerformanceCommonEntryPoint ();
+}
diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc
index 05bf5fe08094..dc85d108d958 100644
--- a/MdeModulePkg/MdeModulePkg.dsc
+++ b/MdeModulePkg/MdeModulePkg.dsc
@@ -168,6 +168,7 @@ [LibraryClasses.common.MM_STANDALONE]
   StandaloneMmDriverEntryPoint|MdePkg/Library/StandaloneMmDriverEntryPoint/StandaloneMmDriverEntryPoint.inf
   MmServicesTableLib|MdePkg/Library/StandaloneMmServicesTableLib/StandaloneMmServicesTableLib.inf
   LockBoxLib|MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxStandaloneMmLib.inf
+  MemLib|StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.inf
 
 [LibraryClasses.ARM, LibraryClasses.AARCH64]
   ArmLib|ArmPkg/Library/ArmLib/ArmBaseLib.inf
@@ -501,6 +502,7 @@ [Components.IA32, Components.X64]
 
 [Components.X64]
   MdeModulePkg/Universal/CapsulePei/CapsuleX64.inf
+  MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceStandaloneMm.inf
 
 [BuildOptions]
 
diff --git a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceCommon.h b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceCommon.h
new file mode 100644
index 000000000000..ba01e28f2493
--- /dev/null
+++ b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceCommon.h
@@ -0,0 +1,55 @@
+/** @file
+  This module collects performance data for SMM driver boot records and S3 Suspend Performance Record.
+
+  This module registers report status code listener to collect performance data
+  for SMM driver boot records and S3 Suspend Performance Record.
+
+  Caution: This module requires additional review when modified.
+  This driver will have external input - communicate buffer in SMM mode.
+  This external input must be validated carefully to avoid security issue like
+  buffer overflow, integer overflow.
+
+  FpdtSmiHandler() will receive untrusted input and do basic validation.
+
+  Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
+  Copyright (c), Microsoft Corporation.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef _FW_PERF_COMMON_H_
+#define _FW_PERF_COMMON_H_
+
+/**
+  This function is an abstraction layer for implementation specific Mm buffer validation routine.
+
+  @param Buffer  The buffer start address to be checked.
+  @param Length  The buffer length to be checked.
+
+  @retval TRUE  This buffer is valid per processor architecture and not overlap with SMRAM.
+  @retval FALSE This buffer is not valid per processor architecture or overlap with SMRAM.
+**/
+BOOLEAN
+EFIAPI
+IsBufferOutsideMmValid (
+  IN EFI_PHYSICAL_ADDRESS  Buffer,
+  IN UINT64                Length
+  );
+
+/**
+  The module Entry Point of the Firmware Performance Data Table MM driver.
+
+  @param[in]  ImageHandle    The firmware allocated handle for the EFI image.
+  @param[in]  SystemTable    A pointer to the EFI System Table.
+
+  @retval EFI_SUCCESS    The entry point is executed successfully.
+  @retval Other          Some error occurs when executing this entry point.
+
+**/
+EFI_STATUS
+EFIAPI
+FirmwarePerformanceCommonEntryPoint (
+  VOID
+  );
+
+#endif // _FW_PERF_COMMON_H_
diff --git a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceSmm.inf b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceSmm.inf
index 618cbd56ca59..b7194bd899dd 100644
--- a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceSmm.inf
+++ b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceSmm.inf
@@ -26,7 +26,9 @@ [Defines]
 #
 
 [Sources]
-  FirmwarePerformanceSmm.c
+  FirmwarePerformanceCommon.c
+  FirmwarePerformanceCommon.h
+  FirmwarePerformanceTraditional.c
 
 [Packages]
   MdePkg/MdePkg.dec
@@ -34,7 +36,7 @@ [Packages]
 
 [LibraryClasses]
   UefiDriverEntryPoint
-  SmmServicesTableLib
+  MmServicesTableLib
   BaseLib
   DebugLib
   TimerLib
@@ -42,12 +44,11 @@ [LibraryClasses]
   PcdLib
   BaseMemoryLib
   MemoryAllocationLib
-  UefiBootServicesTableLib
   SynchronizationLib
   SmmMemLib
 
 [Protocols]
-  gEfiSmmRscHandlerProtocolGuid                 ## CONSUMES
+  gEfiMmRscHandlerProtocolGuid                 ## CONSUMES
 
 [Guids]
   ## SOMETIMES_PRODUCES   ## UNDEFINED # SaveLockBox
@@ -61,7 +62,7 @@ [Pcd]
   gEfiMdeModulePkgTokenSpaceGuid.PcdProgressCodeS3SuspendEnd    ## CONSUMES
 
 [Depex]
-  gEfiSmmRscHandlerProtocolGuid
+  gEfiMmRscHandlerProtocolGuid
 
 [UserExtensions.TianoCore."ExtraFiles"]
   FirmwarePerformanceSmmExtra.uni
diff --git a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceSmm.inf b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceStandaloneMm.inf
similarity index 65%
copy from MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceSmm.inf
copy to MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceStandaloneMm.inf
index 618cbd56ca59..e6aad88be0ef 100644
--- a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceSmm.inf
+++ b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceStandaloneMm.inf
@@ -5,19 +5,19 @@
 #  for SMM boot performance records and S3 Suspend Performance Record.
 #
 #  Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
+#  Copyright (c) Microsoft Corporation.
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #
 ##
 
 [Defines]
   INF_VERSION                    = 0x00010005
-  BASE_NAME                      = FirmwarePerformanceSmm
-  MODULE_UNI_FILE                = FirmwarePerformanceSmm.uni
-  FILE_GUID                      = 044310AB-77FD-402a-AF1A-87D4120E7329
-  MODULE_TYPE                    = DXE_SMM_DRIVER
+  BASE_NAME                      = FirmwarePerformanceStandaloneMm
+  FILE_GUID                      = 827AC29D-E52D-4B1A-874A-C6577E0699CF
+  MODULE_TYPE                    = MM_STANDALONE
   VERSION_STRING                 = 1.0
-  PI_SPECIFICATION_VERSION       = 0x0001000A
-  ENTRY_POINT                    = FirmwarePerformanceSmmEntryPoint
+  PI_SPECIFICATION_VERSION       = 0x00010032
+  ENTRY_POINT                    = FirmwarePerformanceStandaloneMmEntryPoint
 
 #
 # The following information is for reference only and not required by the build tools.
@@ -26,15 +26,18 @@ [Defines]
 #
 
 [Sources]
-  FirmwarePerformanceSmm.c
+  FirmwarePerformanceCommon.c
+  FirmwarePerformanceCommon.h
+  FirmwarePerformanceStandaloneMm.c
 
 [Packages]
   MdePkg/MdePkg.dec
   MdeModulePkg/MdeModulePkg.dec
+  StandaloneMmPkg/StandaloneMmPkg.dec
 
 [LibraryClasses]
-  UefiDriverEntryPoint
-  SmmServicesTableLib
+  StandaloneMmDriverEntryPoint
+  MmServicesTableLib
   BaseLib
   DebugLib
   TimerLib
@@ -42,12 +45,11 @@ [LibraryClasses]
   PcdLib
   BaseMemoryLib
   MemoryAllocationLib
-  UefiBootServicesTableLib
   SynchronizationLib
-  SmmMemLib
+  MemLib
 
 [Protocols]
-  gEfiSmmRscHandlerProtocolGuid                 ## CONSUMES
+  gEfiMmRscHandlerProtocolGuid                 ## CONSUMES
 
 [Guids]
   ## SOMETIMES_PRODUCES   ## UNDEFINED # SaveLockBox
@@ -61,7 +63,4 @@ [Pcd]
   gEfiMdeModulePkgTokenSpaceGuid.PcdProgressCodeS3SuspendEnd    ## CONSUMES
 
 [Depex]
-  gEfiSmmRscHandlerProtocolGuid
-
-[UserExtensions.TianoCore."ExtraFiles"]
-  FirmwarePerformanceSmmExtra.uni
+  gEfiMmRscHandlerProtocolGuid
-- 
2.28.0.windows.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH v1 08/15] MdeModulePkg: ReportStatusCodeRouter: Support StandaloneMm RSC Router
       [not found] <20201218185011.1366-1-kun.q@outlook.com>
                   ` (6 preceding siblings ...)
  2020-12-18 18:50 ` [PATCH v1 07/15] MdeModulePkg: FirmwarePerformanceDataTable: Added StandaloneMm support Kun Qin
@ 2020-12-18 18:50 ` Kun Qin
  2020-12-22  8:42   ` Wu, Hao A
  2020-12-18 18:50 ` [PATCH v1 09/15] MdePkg: UefiDevicePathLib: Support UefiDevicePathLib under StandaloneMm Kun Qin
                   ` (6 subsequent siblings)
  14 siblings, 1 reply; 44+ messages in thread
From: Kun Qin @ 2020-12-18 18:50 UTC (permalink / raw)
  To: devel; +Cc: Jian J Wang, Hao A Wu, Dandan Bi, Liming Gao

This change added support of RSC router under StandaloneMm. It replaces
SMM version ReportStatusCode protocol definitions with MM version. This
patch also switched to use gMmst instead of gSmst. Lastly, it abstracts
standalone and traditional MM driver entrypoints into separate files to
allow maximal common implementations.

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Dandan Bi <dandan.bi@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>

Signed-off-by: Kun Qin <kun.q@outlook.com>
---
 MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/{ReportStatusCodeRouterSmm.c => ReportStatusCodeRouterCommon.c} | 43 ++++++++---------
 MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterStandaloneMm.c                            | 33 +++++++++++++
 MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterTraditional.c                             | 33 +++++++++++++
 MdeModulePkg/MdeModulePkg.dsc                                                                                     |  1 +
 MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/{ReportStatusCodeRouterSmm.h => ReportStatusCodeRouterCommon.h} | 50 +++++++++++++-------
 MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterSmm.inf                                   | 13 ++---
 MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterStandaloneMm.inf                          | 49 +++++++++++++++++++
 7 files changed, 177 insertions(+), 45 deletions(-)

diff --git a/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterSmm.c b/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterCommon.c
similarity index 80%
rename from MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterSmm.c
rename to MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterCommon.c
index c3ab5cd05045..585428aad669 100644
--- a/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterSmm.c
+++ b/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterCommon.c
@@ -7,7 +7,7 @@
 
 **/
 
-#include "ReportStatusCodeRouterSmm.h"
+#include "ReportStatusCodeRouterCommon.h"
 
 LIST_ENTRY   mCallbackListHead          = INITIALIZE_LIST_HEAD_VARIABLE (mCallbackListHead);
 
@@ -17,11 +17,11 @@ LIST_ENTRY   mCallbackListHead          = INITIALIZE_LIST_HEAD_VARIABLE (mCallba
 //
 UINT32       mStatusCodeNestStatus = 0;
 
-EFI_SMM_STATUS_CODE_PROTOCOL  mSmmStatusCodeProtocol  = {
+EFI_MM_STATUS_CODE_PROTOCOL   mSmmStatusCodeProtocol  = {
   ReportDispatcher
 };
 
-EFI_SMM_RSC_HANDLER_PROTOCOL  mSmmRscHandlerProtocol = {
+EFI_MM_RSC_HANDLER_PROTOCOL   mSmmRscHandlerProtocol = {
   Register,
   Unregister
   };
@@ -45,18 +45,18 @@ EFI_SMM_RSC_HANDLER_PROTOCOL  mSmmRscHandlerProtocol = {
 EFI_STATUS
 EFIAPI
 Register (
-  IN EFI_SMM_RSC_HANDLER_CALLBACK   Callback
+  IN EFI_MM_RSC_HANDLER_CALLBACK    Callback
   )
 {
   LIST_ENTRY                      *Link;
-  SMM_RSC_HANDLER_CALLBACK_ENTRY  *CallbackEntry;
+  MM_RSC_HANDLER_CALLBACK_ENTRY  *CallbackEntry;
 
   if (Callback == NULL) {
     return EFI_INVALID_PARAMETER;
   }
 
   for (Link = GetFirstNode (&mCallbackListHead); !IsNull (&mCallbackListHead, Link); Link = GetNextNode (&mCallbackListHead, Link)) {
-    CallbackEntry = CR (Link, SMM_RSC_HANDLER_CALLBACK_ENTRY, Node, SMM_RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE);
+    CallbackEntry = CR (Link, MM_RSC_HANDLER_CALLBACK_ENTRY, Node, MM_RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE);
     if (CallbackEntry->RscHandlerCallback == Callback) {
       //
       // If the function was already registered. It can't be registered again.
@@ -65,10 +65,10 @@ Register (
     }
   }
 
-  CallbackEntry = (SMM_RSC_HANDLER_CALLBACK_ENTRY *)AllocatePool (sizeof (SMM_RSC_HANDLER_CALLBACK_ENTRY));
+  CallbackEntry = (MM_RSC_HANDLER_CALLBACK_ENTRY *)AllocatePool (sizeof (MM_RSC_HANDLER_CALLBACK_ENTRY));
   ASSERT (CallbackEntry != NULL);
 
-  CallbackEntry->Signature          = SMM_RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE;
+  CallbackEntry->Signature          = MM_RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE;
   CallbackEntry->RscHandlerCallback = Callback;
 
   InsertTailList (&mCallbackListHead, &CallbackEntry->Node);
@@ -92,18 +92,18 @@ Register (
 EFI_STATUS
 EFIAPI
 Unregister (
-  IN EFI_SMM_RSC_HANDLER_CALLBACK Callback
+  IN EFI_MM_RSC_HANDLER_CALLBACK  Callback
   )
 {
   LIST_ENTRY                        *Link;
-  SMM_RSC_HANDLER_CALLBACK_ENTRY    *CallbackEntry;
+  MM_RSC_HANDLER_CALLBACK_ENTRY    *CallbackEntry;
 
   if (Callback == NULL) {
     return EFI_INVALID_PARAMETER;
   }
 
   for (Link = GetFirstNode (&mCallbackListHead); !IsNull (&mCallbackListHead, Link); Link = GetNextNode (&mCallbackListHead, Link)) {
-    CallbackEntry = CR (Link, SMM_RSC_HANDLER_CALLBACK_ENTRY, Node, SMM_RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE);
+    CallbackEntry = CR (Link, MM_RSC_HANDLER_CALLBACK_ENTRY, Node, MM_RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE);
     if (CallbackEntry->RscHandlerCallback == Callback) {
       //
       // If the function is found in list, delete it and return.
@@ -140,16 +140,16 @@ Unregister (
 EFI_STATUS
 EFIAPI
 ReportDispatcher (
-  IN CONST EFI_SMM_STATUS_CODE_PROTOCOL  *This,
+  IN CONST EFI_MM_STATUS_CODE_PROTOCOL   *This,
   IN EFI_STATUS_CODE_TYPE                Type,
   IN EFI_STATUS_CODE_VALUE               Value,
   IN UINT32                              Instance,
-  IN CONST EFI_GUID                      *CallerId  OPTIONAL,
+  IN CONST EFI_GUID                      *CallerId,
   IN EFI_STATUS_CODE_DATA                *Data      OPTIONAL
   )
 {
   LIST_ENTRY                        *Link;
-  SMM_RSC_HANDLER_CALLBACK_ENTRY    *CallbackEntry;
+  MM_RSC_HANDLER_CALLBACK_ENTRY    *CallbackEntry;
 
   //
   // Use atom operation to avoid the reentant of report.
@@ -160,7 +160,7 @@ ReportDispatcher (
   }
 
   for (Link = GetFirstNode (&mCallbackListHead); !IsNull (&mCallbackListHead, Link);) {
-    CallbackEntry = CR (Link, SMM_RSC_HANDLER_CALLBACK_ENTRY, Node, SMM_RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE);
+    CallbackEntry = CR (Link, MM_RSC_HANDLER_CALLBACK_ENTRY, Node, MM_RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE);
     //
     // The handler may remove itself, so get the next handler in advance.
     //
@@ -197,9 +197,8 @@ ReportDispatcher (
 **/
 EFI_STATUS
 EFIAPI
-GenericStatusCodeSmmEntry (
-  IN EFI_HANDLE         ImageHandle,
-  IN EFI_SYSTEM_TABLE   *SystemTable
+GenericStatusCodeCommonEntry (
+  VOID
   )
 {
   EFI_STATUS     Status;
@@ -210,9 +209,9 @@ GenericStatusCodeSmmEntry (
   //
   // Install SmmRscHandler Protocol
   //
-  Status = gSmst->SmmInstallProtocolInterface (
+  Status = gMmst->MmInstallProtocolInterface (
                     &Handle,
-                    &gEfiSmmRscHandlerProtocolGuid,
+                    &gEfiMmRscHandlerProtocolGuid,
                     EFI_NATIVE_INTERFACE,
                     &mSmmRscHandlerProtocol
                     );
@@ -221,9 +220,9 @@ GenericStatusCodeSmmEntry (
   //
   // Install SmmStatusCode Protocol
   //
-  Status = gSmst->SmmInstallProtocolInterface (
+  Status = gMmst->MmInstallProtocolInterface (
                     &Handle,
-                    &gEfiSmmStatusCodeProtocolGuid,
+                    &gEfiMmStatusCodeProtocolGuid,
                     EFI_NATIVE_INTERFACE,
                     &mSmmStatusCodeProtocol
                     );
diff --git a/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterStandaloneMm.c b/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterStandaloneMm.c
new file mode 100644
index 000000000000..501572719fdc
--- /dev/null
+++ b/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterStandaloneMm.c
@@ -0,0 +1,33 @@
+/** @file
+  Report Status Code Router Driver which produces SMM Report Stataus Code Handler Protocol
+  and SMM Status Code Protocol.
+
+  Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) Microsoft Corporation.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "ReportStatusCodeRouterCommon.h"
+
+/**
+  Entry point of Generic Status Code Driver.
+
+  This function is the entry point of SMM Status Code Router .
+  It produces SMM Report Stataus Code Handler and Status Code protocol.
+
+  @param  ImageHandle       The firmware allocated handle for the EFI image.
+  @param  SystemTable       A pointer to the EFI System Table.
+
+  @retval EFI_SUCCESS       The entry point is executed successfully.
+
+**/
+EFI_STATUS
+EFIAPI
+GenericStatusCodeStandaloneMmEntry (
+  IN EFI_HANDLE             ImageHandle,
+  IN EFI_MM_SYSTEM_TABLE    *SystemTable
+  )
+{
+  return GenericStatusCodeCommonEntry ();
+}
diff --git a/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterTraditional.c b/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterTraditional.c
new file mode 100644
index 000000000000..360a0eef6b6d
--- /dev/null
+++ b/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterTraditional.c
@@ -0,0 +1,33 @@
+/** @file
+  Report Status Code Router Driver which produces MM Report Stataus Code Handler Protocol
+  and MM Status Code Protocol.
+
+  Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) Microsoft Corporation.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "ReportStatusCodeRouterCommon.h"
+
+/**
+  Entry point of Generic Status Code Driver.
+
+  This function is the entry point of SMM Status Code Router .
+  It produces SMM Report Stataus Code Handler and Status Code protocol.
+
+  @param  ImageHandle       The firmware allocated handle for the EFI image.
+  @param  SystemTable       A pointer to the EFI System Table.
+
+  @retval EFI_SUCCESS       The entry point is executed successfully.
+
+**/
+EFI_STATUS
+EFIAPI
+GenericStatusCodeTraditionalEntry (
+  IN EFI_HANDLE         ImageHandle,
+  IN EFI_SYSTEM_TABLE   *SystemTable
+  )
+{
+  return GenericStatusCodeCommonEntry ();
+}
diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc
index dc85d108d958..84ad577c2851 100644
--- a/MdeModulePkg/MdeModulePkg.dsc
+++ b/MdeModulePkg/MdeModulePkg.dsc
@@ -477,6 +477,7 @@ [Components.IA32, Components.X64]
   MdeModulePkg/Library/SmmReportStatusCodeLib/StandaloneMmReportStatusCodeLib.inf
   MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSmm.inf
   MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterSmm.inf
+  MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterStandaloneMm.inf
   MdeModulePkg/Universal/LockBox/SmmLockBox/SmmLockBox.inf
   MdeModulePkg/Library/SmmMemoryAllocationProfileLib/SmmMemoryAllocationProfileLib.inf
   MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/PiSmmCoreMemoryAllocationProfileLib.inf
diff --git a/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterSmm.h b/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterCommon.h
similarity index 70%
rename from MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterSmm.h
rename to MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterCommon.h
index f8c48c62e790..f7962e773bb3 100644
--- a/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterSmm.h
+++ b/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterCommon.h
@@ -6,28 +6,26 @@
 
 **/
 
-#ifndef __REPORT_STATUS_CODE_ROUTER_SMM_H__
-#define __REPORT_STATUS_CODE_ROUTER_SMM_H__
+#ifndef __REPORT_STATUS_CODE_ROUTER_COMMON_H__
+#define __REPORT_STATUS_CODE_ROUTER_COMMON_H__
 
-
-#include <Protocol/SmmReportStatusCodeHandler.h>
-#include <Protocol/SmmStatusCode.h>
+#include <Protocol/MmReportStatusCodeHandler.h>
+#include <Protocol/MmStatusCode.h>
 
 #include <Library/BaseLib.h>
 #include <Library/SynchronizationLib.h>
 #include <Library/DebugLib.h>
 #include <Library/PcdLib.h>
-#include <Library/UefiDriverEntryPoint.h>
-#include <Library/SmmServicesTableLib.h>
+#include <Library/MmServicesTableLib.h>
 #include <Library/MemoryAllocationLib.h>
 
-#define SMM_RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE  SIGNATURE_32 ('s', 'h', 'c', 'e')
+#define MM_RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE  SIGNATURE_32 ('s', 'h', 'c', 'e')
 
 typedef struct {
   UINTN                         Signature;
-  EFI_SMM_RSC_HANDLER_CALLBACK  RscHandlerCallback;
+  EFI_MM_RSC_HANDLER_CALLBACK   RscHandlerCallback;
   LIST_ENTRY                    Node;
-} SMM_RSC_HANDLER_CALLBACK_ENTRY;
+} MM_RSC_HANDLER_CALLBACK_ENTRY;
 
 /**
   Register the callback function for ReportStatusCode() notification.
@@ -48,7 +46,7 @@ typedef struct {
 EFI_STATUS
 EFIAPI
 Register (
-  IN EFI_SMM_RSC_HANDLER_CALLBACK   Callback
+  IN EFI_MM_RSC_HANDLER_CALLBACK    Callback
   );
 
 /**
@@ -67,13 +65,13 @@ Register (
 EFI_STATUS
 EFIAPI
 Unregister (
-  IN EFI_SMM_RSC_HANDLER_CALLBACK Callback
+  IN EFI_MM_RSC_HANDLER_CALLBACK  Callback
   );
 
 /**
   Provides an interface that a software module can call to report a status code.
 
-  @param  This             EFI_SMM_STATUS_CODE_PROTOCOL instance.
+  @param  This             EFI_MM_RSC_HANDLER_CALLBACK instance.
   @param  Type             Indicates the type of status code being reported.
   @param  Value            Describes the current status of a hardware or software entity.
                            This included information about the class and subclass that is used to
@@ -92,12 +90,30 @@ Unregister (
 EFI_STATUS
 EFIAPI
 ReportDispatcher (
-  IN CONST EFI_SMM_STATUS_CODE_PROTOCOL  *This,
-  IN EFI_STATUS_CODE_TYPE                Type,
+  IN CONST EFI_MM_STATUS_CODE_PROTOCOL   *This,
+  IN EFI_STATUS_CODE_TYPE                CodeType,
   IN EFI_STATUS_CODE_VALUE               Value,
   IN UINT32                              Instance,
-  IN CONST EFI_GUID                      *CallerId  OPTIONAL,
-  IN EFI_STATUS_CODE_DATA                *Data      OPTIONAL
+  IN CONST EFI_GUID                      *CallerId,
+  IN EFI_STATUS_CODE_DATA                *Data OPTIONAL
+  );
+
+/**
+  Entry point of Generic Status Code Driver.
+
+  This function is the entry point of SMM Status Code Router .
+  It produces SMM Report Stataus Code Handler and Status Code protocol.
+
+  @param  ImageHandle       The firmware allocated handle for the EFI image.
+  @param  SystemTable       A pointer to the EFI System Table.
+
+  @retval EFI_SUCCESS       The entry point is executed successfully.
+
+**/
+EFI_STATUS
+EFIAPI
+GenericStatusCodeCommonEntry (
+  VOID
   );
 
 #endif
diff --git a/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterSmm.inf b/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterSmm.inf
index 46fdcb7bf959..539badc4c755 100644
--- a/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterSmm.inf
+++ b/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterSmm.inf
@@ -16,7 +16,7 @@ [Defines]
   MODULE_TYPE                    = DXE_SMM_DRIVER
   PI_SPECIFICATION_VERSION       = 0x0001000A
   VERSION_STRING                 = 1.0
-  ENTRY_POINT                    = GenericStatusCodeSmmEntry
+  ENTRY_POINT                    = GenericStatusCodeTraditionalEntry
 
 #
 # The following information is for reference only and not required by the build tools.
@@ -25,15 +25,16 @@ [Defines]
 #
 
 [Sources]
-  ReportStatusCodeRouterSmm.c
-  ReportStatusCodeRouterSmm.h
+  ReportStatusCodeRouterCommon.c
+  ReportStatusCodeRouterCommon.h
+  ReportStatusCodeRouterTraditional.c
 
 [Packages]
   MdePkg/MdePkg.dec
   MdeModulePkg/MdeModulePkg.dec
 
 [LibraryClasses]
-  SmmServicesTableLib
+  MmServicesTableLib
   UefiDriverEntryPoint
   DebugLib
   BaseLib
@@ -41,8 +42,8 @@ [LibraryClasses]
   MemoryAllocationLib
 
 [Protocols]
-  gEfiSmmRscHandlerProtocolGuid               ## PRODUCES
-  gEfiSmmStatusCodeProtocolGuid               ## PRODUCES
+  gEfiMmRscHandlerProtocolGuid               ## PRODUCES
+  gEfiMmStatusCodeProtocolGuid               ## PRODUCES
 
 [Depex]
   TRUE
diff --git a/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterStandaloneMm.inf b/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterStandaloneMm.inf
new file mode 100644
index 000000000000..f34b3e29d4ad
--- /dev/null
+++ b/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterStandaloneMm.inf
@@ -0,0 +1,49 @@
+## @file
+#  Report Status Code Router Driver which produces SMM Report Stataus Code Handler Protocol and SMM Status Code Protocol.
+#
+#  Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
+#  Copyright (c) Microsoft Corporation.
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = ReportStatusCodeRouterStandaloneMm
+  FILE_GUID                      = EAEEDEF9-ABE7-4B95-82B0-5A534C899B46
+  MODULE_TYPE                    = MM_STANDALONE
+  PI_SPECIFICATION_VERSION       = 0x00010032
+  VERSION_STRING                 = 1.0
+  ENTRY_POINT                    = GenericStatusCodeStandaloneMmEntry
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+#  VALID_ARCHITECTURES           = IA32 X64
+#
+
+[Sources]
+  ReportStatusCodeRouterCommon.c
+  ReportStatusCodeRouterCommon.h
+  ReportStatusCodeRouterStandaloneMm.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+
+[LibraryClasses]
+  MmServicesTableLib
+  StandaloneMmDriverEntryPoint
+  DebugLib
+  BaseLib
+  SynchronizationLib
+  MemoryAllocationLib
+
+[Protocols]
+  gEfiMmRscHandlerProtocolGuid               ## PRODUCES
+  gEfiMmStatusCodeProtocolGuid               ## PRODUCES
+
+[Depex]
+  TRUE
-- 
2.28.0.windows.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH v1 09/15] MdePkg: UefiDevicePathLib: Support UefiDevicePathLib under StandaloneMm
       [not found] <20201218185011.1366-1-kun.q@outlook.com>
                   ` (7 preceding siblings ...)
  2020-12-18 18:50 ` [PATCH v1 08/15] MdeModulePkg: ReportStatusCodeRouter: Support StandaloneMm RSC Router Kun Qin
@ 2020-12-18 18:50 ` Kun Qin
  2021-01-04 18:32   ` [edk2-devel] " Kun Qin
  2020-12-18 18:50 ` [PATCH v1 10/15] PcAtChipsetPkg: AcpiTimerLib: Added StandaloneMm instance of AcpiTimerLib Kun Qin
                   ` (5 subsequent siblings)
  14 siblings, 1 reply; 44+ messages in thread
From: Kun Qin @ 2020-12-18 18:50 UTC (permalink / raw)
  To: devel; +Cc: Michael D Kinney, Liming Gao, Zhiguang Liu

This change added an instance of UefiDevicePathLib for StandaloneMm. It
abstracts DevicePathFromHandle function into different files for
Standalone MM and other instances to avoid linking gBS into MM_STANDALONE
drivers.

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>

Signed-off-by: Kun Qin <kun.q@outlook.com>
---
 MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c                                        | 33 -------------
 MdePkg/Library/UefiDevicePathLib/DevicePathUtilitiesDxeSmm.c                                  | 51 ++++++++++++++++++++
 MdePkg/Library/UefiDevicePathLib/DevicePathUtilitiesStandaloneMm.c                            | 40 +++++++++++++++
 MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf                                        |  1 +
 MdePkg/Library/UefiDevicePathLib/UefiDevicePathLibOptionalDevicePathProtocol.inf              |  1 +
 MdePkg/Library/UefiDevicePathLib/{UefiDevicePathLib.inf => UefiDevicePathLibStandaloneMm.inf} | 11 +++--
 MdePkg/MdePkg.dsc                                                                             |  1 +
 7 files changed, 100 insertions(+), 38 deletions(-)

diff --git a/MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c b/MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c
index 9274ef8dda98..7d5fb18d2516 100644
--- a/MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c
+++ b/MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c
@@ -806,39 +806,6 @@ UefiDevicePathLibIsDevicePathMultiInstance (
 }
 
 
-/**
-  Retrieves the device path protocol from a handle.
-
-  This function returns the device path protocol from the handle specified by Handle.
-  If Handle is NULL or Handle does not contain a device path protocol, then NULL
-  is returned.
-
-  @param  Handle                     The handle from which to retrieve the device
-                                     path protocol.
-
-  @return The device path protocol from the handle specified by Handle.
-
-**/
-EFI_DEVICE_PATH_PROTOCOL *
-EFIAPI
-DevicePathFromHandle (
-  IN EFI_HANDLE                      Handle
-  )
-{
-  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;
-  EFI_STATUS                Status;
-
-  Status = gBS->HandleProtocol (
-                  Handle,
-                  &gEfiDevicePathProtocolGuid,
-                  (VOID *) &DevicePath
-                  );
-  if (EFI_ERROR (Status)) {
-    DevicePath = NULL;
-  }
-  return DevicePath;
-}
-
 /**
   Allocates a device path for a file and appends it to an existing device path.
 
diff --git a/MdePkg/Library/UefiDevicePathLib/DevicePathUtilitiesDxeSmm.c b/MdePkg/Library/UefiDevicePathLib/DevicePathUtilitiesDxeSmm.c
new file mode 100644
index 000000000000..7f3b6076ef34
--- /dev/null
+++ b/MdePkg/Library/UefiDevicePathLib/DevicePathUtilitiesDxeSmm.c
@@ -0,0 +1,51 @@
+/** @file
+  Device Path services. The thing to remember is device paths are built out of
+  nodes. The device path is terminated by an end node that is length
+  sizeof(EFI_DEVICE_PATH_PROTOCOL). That would be why there is sizeof(EFI_DEVICE_PATH_PROTOCOL)
+  all over this file.
+
+  The only place where multi-instance device paths are supported is in
+  environment varibles. Multi-instance device paths should never be placed
+  on a Handle.
+
+  Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) Microsoft Corporation.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "UefiDevicePathLib.h"
+
+
+/**
+  Retrieves the device path protocol from a handle.
+
+  This function returns the device path protocol from the handle specified by Handle.
+  If Handle is NULL or Handle does not contain a device path protocol, then NULL
+  is returned.
+
+  @param  Handle                     The handle from which to retrieve the device
+                                     path protocol.
+
+  @return The device path protocol from the handle specified by Handle.
+
+**/
+EFI_DEVICE_PATH_PROTOCOL *
+EFIAPI
+DevicePathFromHandle (
+  IN EFI_HANDLE                      Handle
+  )
+{
+  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;
+  EFI_STATUS                Status;
+
+  Status = gBS->HandleProtocol (
+                  Handle,
+                  &gEfiDevicePathProtocolGuid,
+                  (VOID *) &DevicePath
+                  );
+  if (EFI_ERROR (Status)) {
+    DevicePath = NULL;
+  }
+  return DevicePath;
+}
diff --git a/MdePkg/Library/UefiDevicePathLib/DevicePathUtilitiesStandaloneMm.c b/MdePkg/Library/UefiDevicePathLib/DevicePathUtilitiesStandaloneMm.c
new file mode 100644
index 000000000000..930e778d373a
--- /dev/null
+++ b/MdePkg/Library/UefiDevicePathLib/DevicePathUtilitiesStandaloneMm.c
@@ -0,0 +1,40 @@
+/** @file
+  Device Path services. The thing to remember is device paths are built out of
+  nodes. The device path is terminated by an end node that is length
+  sizeof(EFI_DEVICE_PATH_PROTOCOL). That would be why there is sizeof(EFI_DEVICE_PATH_PROTOCOL)
+  all over this file.
+
+  The only place where multi-instance device paths are supported is in
+  environment varibles. Multi-instance device paths should never be placed
+  on a Handle.
+
+  Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) Microsoft Corporation.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "UefiDevicePathLib.h"
+
+
+/**
+  Retrieves the device path protocol from a handle.
+
+  This function returns the device path protocol from the handle specified by Handle.
+  If Handle is NULL or Handle does not contain a device path protocol, then NULL
+  is returned.
+
+  @param  Handle                     The handle from which to retrieve the device
+                                     path protocol.
+
+  @return The device path protocol from the handle specified by Handle.
+
+**/
+EFI_DEVICE_PATH_PROTOCOL *
+EFIAPI
+DevicePathFromHandle (
+  IN EFI_HANDLE                      Handle
+  )
+{
+  return NULL;
+}
diff --git a/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf b/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
index 3c41c0695a72..eb85a54a74c3 100644
--- a/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
+++ b/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
@@ -26,6 +26,7 @@ [Defines]
 
 [Sources]
   DevicePathUtilities.c
+  DevicePathUtilitiesDxeSmm.c
   DevicePathToText.c
   DevicePathFromText.c
   UefiDevicePathLib.c
diff --git a/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLibOptionalDevicePathProtocol.inf b/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLibOptionalDevicePathProtocol.inf
index e812e3e1d41e..81323bc70061 100644
--- a/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLibOptionalDevicePathProtocol.inf
+++ b/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLibOptionalDevicePathProtocol.inf
@@ -29,6 +29,7 @@ [Defines]
 
 [Sources]
   DevicePathUtilities.c
+  DevicePathUtilitiesDxeSmm.c
   DevicePathToText.c
   DevicePathFromText.c
   UefiDevicePathLibOptionalDevicePathProtocol.c
diff --git a/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf b/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLibStandaloneMm.inf
similarity index 79%
copy from MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
copy to MdePkg/Library/UefiDevicePathLib/UefiDevicePathLibStandaloneMm.inf
index 3c41c0695a72..23fedf38b7eb 100644
--- a/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
+++ b/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLibStandaloneMm.inf
@@ -4,6 +4,7 @@
 # Device Path Library that layers on top of the Memory Allocation Library.
 #
 # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) Microsoft Corporation.
 #
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -14,10 +15,11 @@ [Defines]
   INF_VERSION                    = 0x00010005
   BASE_NAME                      = UefiDevicePathLib
   MODULE_UNI_FILE                = UefiDevicePathLib.uni
-  FILE_GUID                      = 91c1677a-e57f-4191-8b8e-eb7711a716e0
-  MODULE_TYPE                    = UEFI_DRIVER
+  FILE_GUID                      = D8E58437-44D3-4154-B7A7-EB794923EF12
+  MODULE_TYPE                    = MM_STANDALONE
+  PI_SPECIFICATION_VERSION       = 0x00010032
   VERSION_STRING                 = 1.0
-  LIBRARY_CLASS                  = DevicePathLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER SMM_CORE MM_STANDALONE
+  LIBRARY_CLASS                  = DevicePathLib | MM_STANDALONE MM_CORE_STANDALONE
 
 
 #
@@ -26,6 +28,7 @@ [Defines]
 
 [Sources]
   DevicePathUtilities.c
+  DevicePathUtilitiesStandaloneMm.c
   DevicePathToText.c
   DevicePathFromText.c
   UefiDevicePathLib.c
@@ -34,7 +37,6 @@ [Sources]
 [Packages]
   MdePkg/MdePkg.dec
 
-
 [LibraryClasses]
   BaseLib
   MemoryAllocationLib
@@ -71,4 +73,3 @@ [Protocols]
 
 [Pcd]
   gEfiMdePkgTokenSpaceGuid.PcdMaximumDevicePathNodeCount    ## SOMETIMES_CONSUMES
-
diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc
index 8d1a5b20c9cd..ce009086815f 100644
--- a/MdePkg/MdePkg.dsc
+++ b/MdePkg/MdePkg.dsc
@@ -109,6 +109,7 @@ [Components]
   MdePkg/Library/UefiDebugLibDebugPortProtocol/UefiDebugLibDebugPortProtocol.inf
   MdePkg/Library/UefiDebugLibStdErr/UefiDebugLibStdErr.inf
   MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
+  MdePkg/Library/UefiDevicePathLib/UefiDevicePathLibStandaloneMm.inf
   MdePkg/Library/UefiDevicePathLib/UefiDevicePathLibOptionalDevicePathProtocol.inf
   MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLibDevicePathProtocol.inf
   MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf
-- 
2.28.0.windows.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH v1 10/15] PcAtChipsetPkg: AcpiTimerLib: Added StandaloneMm instance of AcpiTimerLib
       [not found] <20201218185011.1366-1-kun.q@outlook.com>
                   ` (8 preceding siblings ...)
  2020-12-18 18:50 ` [PATCH v1 09/15] MdePkg: UefiDevicePathLib: Support UefiDevicePathLib under StandaloneMm Kun Qin
@ 2020-12-18 18:50 ` Kun Qin
  2021-01-04 18:30   ` [edk2-devel] " Kun Qin
  2020-12-18 18:50 ` [PATCH v1 11/15] SecurityPkg: Tcg2PhysicalPresenceLib: Introduce StandaloneMm instance Kun Qin
                   ` (4 subsequent siblings)
  14 siblings, 1 reply; 44+ messages in thread
From: Kun Qin @ 2020-12-18 18:50 UTC (permalink / raw)
  To: devel; +Cc: Ray Ni

This change added a new instance of AcpiTimerLib for StandaloneMm core
and drivers. It centralizes the common routines into shared files and
abstract the library constructor into corresponding files to accommodate
each constructor function prototypes.

Cc: Ray Ni <ray.ni@intel.com>

Signed-off-by: Kun Qin <kun.q@outlook.com>
---
 PcAtChipsetPkg/Library/AcpiTimerLib/{DxeAcpiTimerLib.c => CommonAcpiTimerLib.c}         |  8 +-
 PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c                                   | 81 +-------------------
 PcAtChipsetPkg/Library/AcpiTimerLib/StandaloneAcpiTimerLib.c                            | 31 ++++++++
 PcAtChipsetPkg/Library/AcpiTimerLib/CommonAcpiTimerLib.h                                | 25 ++++++
 PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf                                 |  2 +
 PcAtChipsetPkg/Library/AcpiTimerLib/{DxeAcpiTimerLib.inf => StandaloneAcpiTimerLib.inf} | 19 +++--
 PcAtChipsetPkg/PcAtChipsetPkg.dsc                                                       |  1 +
 7 files changed, 75 insertions(+), 92 deletions(-)

diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c b/PcAtChipsetPkg/Library/AcpiTimerLib/CommonAcpiTimerLib.c
similarity index 86%
copy from PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c
copy to PcAtChipsetPkg/Library/AcpiTimerLib/CommonAcpiTimerLib.c
index 3ad831b15e8a..a4d6d0556429 100644
--- a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c
+++ b/PcAtChipsetPkg/Library/AcpiTimerLib/CommonAcpiTimerLib.c
@@ -72,17 +72,13 @@ InternalGetPerformanceCounterFrequency (
 /**
   The constructor function enables ACPI IO space, and caches PerformanceCounterFrequency.
 
-  @param  ImageHandle   The firmware allocated handle for the EFI image.
-  @param  SystemTable   A pointer to the EFI System Table.
-
   @retval EFI_SUCCESS   The constructor always returns RETURN_SUCCESS.
 
 **/
 EFI_STATUS
 EFIAPI
-DxeAcpiTimerLibConstructor (
-  IN EFI_HANDLE        ImageHandle,
-  IN EFI_SYSTEM_TABLE  *SystemTable
+CommonAcpiTimerLibConstructor (
+  VOID
   )
 {
   EFI_HOB_GUID_TYPE   *GuidHob;
diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c
index 3ad831b15e8a..e519ad8ed07e 100644
--- a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c
+++ b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c
@@ -2,72 +2,14 @@
   ACPI Timer implements one instance of Timer Library.
 
   Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) Microsoft Corporation.
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
 
 #include <PiDxe.h>
-#include <Library/TimerLib.h>
-#include <Library/BaseLib.h>
-#include <Library/HobLib.h>
 
-extern GUID mFrequencyHobGuid;
-
-/**
-  The constructor function enables ACPI IO space.
-
-  If ACPI I/O space not enabled, this function will enable it.
-  It will always return RETURN_SUCCESS.
-
-  @retval EFI_SUCCESS   The constructor always returns RETURN_SUCCESS.
-
-**/
-RETURN_STATUS
-EFIAPI
-AcpiTimerLibConstructor (
-  VOID
-  );
-
-/**
-  Calculate TSC frequency.
-
-  The TSC counting frequency is determined by comparing how far it counts
-  during a 101.4 us period as determined by the ACPI timer.
-  The ACPI timer is used because it counts at a known frequency.
-  The TSC is sampled, followed by waiting 363 counts of the ACPI timer,
-  or 101.4 us. The TSC is then sampled again. The difference multiplied by
-  9861 is the TSC frequency. There will be a small error because of the
-  overhead of reading the ACPI timer. An attempt is made to determine and
-  compensate for this error.
-
-  @return The number of TSC counts per second.
-
-**/
-UINT64
-InternalCalculateTscFrequency (
-  VOID
-  );
-
-//
-// Cached performance counter frequency
-//
-UINT64  mPerformanceCounterFrequency = 0;
-
-/**
-  Internal function to retrieves the 64-bit frequency in Hz.
-
-  Internal function to retrieves the 64-bit frequency in Hz.
-
-  @return The frequency in Hz.
-
-**/
-UINT64
-InternalGetPerformanceCounterFrequency (
-  VOID
-  )
-{
-  return  mPerformanceCounterFrequency;
-}
+#include "CommonAcpiTimerLib.h"
 
 /**
   The constructor function enables ACPI IO space, and caches PerformanceCounterFrequency.
@@ -85,22 +27,5 @@ DxeAcpiTimerLibConstructor (
   IN EFI_SYSTEM_TABLE  *SystemTable
   )
 {
-  EFI_HOB_GUID_TYPE   *GuidHob;
-
-  //
-  // Enable ACPI IO space.
-  //
-  AcpiTimerLibConstructor ();
-
-  //
-  // Initialize PerformanceCounterFrequency
-  //
-  GuidHob = GetFirstGuidHob (&mFrequencyHobGuid);
-  if (GuidHob != NULL) {
-    mPerformanceCounterFrequency = *(UINT64*)GET_GUID_HOB_DATA (GuidHob);
-  } else {
-    mPerformanceCounterFrequency = InternalCalculateTscFrequency ();
-  }
-
-  return EFI_SUCCESS;
+  return CommonAcpiTimerLibConstructor ();
 }
diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/StandaloneAcpiTimerLib.c b/PcAtChipsetPkg/Library/AcpiTimerLib/StandaloneAcpiTimerLib.c
new file mode 100644
index 000000000000..8509f94ba7cb
--- /dev/null
+++ b/PcAtChipsetPkg/Library/AcpiTimerLib/StandaloneAcpiTimerLib.c
@@ -0,0 +1,31 @@
+/** @file
+  ACPI Timer implements one instance of Timer Library.
+
+  Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) Microsoft Corporation.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <PiMm.h>
+
+#include "CommonAcpiTimerLib.h"
+
+/**
+  The constructor function enables ACPI IO space, and caches PerformanceCounterFrequency.
+
+  @param  ImageHandle   The firmware allocated handle for the EFI image.
+  @param  SystemTable   A pointer to the EFI System Table.
+
+  @retval EFI_SUCCESS   The constructor always returns RETURN_SUCCESS.
+
+**/
+EFI_STATUS
+EFIAPI
+StandaloneMmAcpiTimerLibConstructor (
+  IN EFI_HANDLE           ImageHandle,
+  IN EFI_MM_SYSTEM_TABLE  *SystemTable
+  )
+{
+  return CommonAcpiTimerLibConstructor ();
+}
diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/CommonAcpiTimerLib.h b/PcAtChipsetPkg/Library/AcpiTimerLib/CommonAcpiTimerLib.h
new file mode 100644
index 000000000000..d5a38479b644
--- /dev/null
+++ b/PcAtChipsetPkg/Library/AcpiTimerLib/CommonAcpiTimerLib.h
@@ -0,0 +1,25 @@
+/** @file
+  Header file internal to ACPI TimerLib.
+
+Copyright (c) Microsoft Corporation.
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+
+#ifndef _COMMON_ACPI_TIMER_LIB_H_
+#define _COMMON_ACPI_TIMER_LIB_H_
+
+/**
+  The constructor function enables ACPI IO space, and caches PerformanceCounterFrequency.
+
+  @retval EFI_SUCCESS   The constructor always returns RETURN_SUCCESS.
+
+**/
+EFI_STATUS
+EFIAPI
+CommonAcpiTimerLibConstructor (
+  VOID
+  );
+
+#endif
diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf
index d86356f4ff17..bbf14b3b5b53 100644
--- a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf
+++ b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf
@@ -25,6 +25,8 @@ [Defines]
 [Sources]
   AcpiTimerLib.c
   DxeAcpiTimerLib.c
+  CommonAcpiTimerLib.c
+  CommonAcpiTimerLib.h
 
 [Packages]
   MdePkg/MdePkg.dec
diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf b/PcAtChipsetPkg/Library/AcpiTimerLib/StandaloneAcpiTimerLib.inf
similarity index 70%
copy from PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf
copy to PcAtChipsetPkg/Library/AcpiTimerLib/StandaloneAcpiTimerLib.inf
index d86356f4ff17..aa8f0012f744 100644
--- a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf
+++ b/PcAtChipsetPkg/Library/AcpiTimerLib/StandaloneAcpiTimerLib.inf
@@ -1,5 +1,5 @@
 ## @file
-#  DXE ACPI Timer Library
+#  Standalone MM ACPI Timer Library
 #
 #  Provides basic timer support using the ACPI timer hardware.  The performance
 #  counter features are provided by the processors time stamp counter.
@@ -8,23 +8,26 @@
 #  is compatible with both 24-bit and 32-bit ACPI timers.
 #
 #  Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
+#  Copyright (c) Microsoft Corporation.
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #
 ##
 
 [Defines]
   INF_VERSION                    = 0x00010005
-  BASE_NAME                      = DxeAcpiTimerLib
-  FILE_GUID                      = E624B98C-845A-4b94-9B50-B20475D552B9
-  MODULE_TYPE                    = DXE_DRIVER
+  BASE_NAME                      = StandaloneAcpiTimerLib
+  FILE_GUID                      = C771858D-AF09-4D1A-B2F3-C7F081C3F076
+  MODULE_TYPE                    = MM_STANDALONE
   VERSION_STRING                 = 1.0
-  LIBRARY_CLASS                  = TimerLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER SMM_CORE
-  CONSTRUCTOR                    = DxeAcpiTimerLibConstructor
-  MODULE_UNI_FILE                = DxeAcpiTimerLib.uni
+  PI_SPECIFICATION_VERSION       = 0x00010032
+  LIBRARY_CLASS                  = TimerLib|MM_CORE_STANDALONE MM_STANDALONE
+  CONSTRUCTOR                    = StandaloneMmAcpiTimerLibConstructor
 
 [Sources]
   AcpiTimerLib.c
-  DxeAcpiTimerLib.c
+  StandaloneAcpiTimerLib.c
+  CommonAcpiTimerLib.c
+  CommonAcpiTimerLib.h
 
 [Packages]
   MdePkg/MdePkg.dec
diff --git a/PcAtChipsetPkg/PcAtChipsetPkg.dsc b/PcAtChipsetPkg/PcAtChipsetPkg.dsc
index b61b7d1f528e..8862ca7a0006 100644
--- a/PcAtChipsetPkg/PcAtChipsetPkg.dsc
+++ b/PcAtChipsetPkg/PcAtChipsetPkg.dsc
@@ -53,6 +53,7 @@ [Components]
   PcAtChipsetPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.inf
   PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf
   PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.inf
+  PcAtChipsetPkg/Library/AcpiTimerLib/StandaloneAcpiTimerLib.inf
   PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf
 
 [BuildOptions]
-- 
2.28.0.windows.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH v1 11/15] SecurityPkg: Tcg2PhysicalPresenceLib: Introduce StandaloneMm instance
       [not found] <20201218185011.1366-1-kun.q@outlook.com>
                   ` (9 preceding siblings ...)
  2020-12-18 18:50 ` [PATCH v1 10/15] PcAtChipsetPkg: AcpiTimerLib: Added StandaloneMm instance of AcpiTimerLib Kun Qin
@ 2020-12-18 18:50 ` Kun Qin
  2020-12-28  0:08   ` Yao, Jiewen
  2020-12-18 18:50 ` [PATCH v1 12/15] SecurityPkg: Tcg2PpVendorLibNull: Added support for MM_STANDALONE type Kun Qin
                   ` (3 subsequent siblings)
  14 siblings, 1 reply; 44+ messages in thread
From: Kun Qin @ 2020-12-18 18:50 UTC (permalink / raw)
  To: devel; +Cc: Jiewen Yao, Jian J Wang, Qi Zhang, Rahul Kumar

This change added a new instance of Tcg2PhysicalPresenceLib to support
MM_STANDALONE type drivers. It centralizes the common routines into
shared files and abstract the library constructor into corresponding
files to implement each constructor function prototypes.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Qi Zhang <qi1.zhang@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>

Signed-off-by: Kun Qin <kun.q@outlook.com>
---
 SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/{SmmTcg2PhysicalPresenceLib.c => MmTcg2PhysicalPresenceLibCommon.c}         |  29 +-
 SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenceLib.c                                                | 368 +-------------------
 SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/StandaloneMmTcg2PhysicalPresenceLib.c                                       |  42 +++
 SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/MmTcg2PhysicalPresenceLibCommon.h                                           |  35 ++
 SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenceLib.inf                                              |   6 +-
 SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/{SmmTcg2PhysicalPresenceLib.inf => StandaloneMmTcg2PhysicalPresenceLib.inf} |  22 +-
 SecurityPkg/SecurityPkg.dsc                                                                                                |   2 +
 7 files changed, 114 insertions(+), 390 deletions(-)

diff --git a/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenceLib.c b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/MmTcg2PhysicalPresenceLibCommon.c
similarity index 91%
copy from SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenceLib.c
copy to SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/MmTcg2PhysicalPresenceLibCommon.c
index 8afaa0a7857d..90023f09a042 100644
--- a/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenceLib.c
+++ b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/MmTcg2PhysicalPresenceLibCommon.c
@@ -15,7 +15,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
 
-#include <PiSmm.h>
+#include <PiMm.h>
 
 #include <Guid/Tcg2PhysicalPresenceData.h>
 
@@ -25,7 +25,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 #include <Library/DebugLib.h>
 #include <Library/BaseMemoryLib.h>
 #include <Library/Tcg2PpVendorLib.h>
-#include <Library/SmmServicesTableLib.h>
+#include <Library/MmServicesTableLib.h>
 
 #define     PP_INF_VERSION_1_2    "1.2"
 
@@ -55,7 +55,7 @@ Tcg2PhysicalPresenceLibReturnOperationResponseToOsFunction (
   UINTN                             DataSize;
   EFI_TCG2_PHYSICAL_PRESENCE        PpData;
 
-  DEBUG ((EFI_D_INFO, "[TPM2] ReturnOperationResponseToOsFunction\n"));
+  DEBUG ((DEBUG_INFO, "[TPM2] ReturnOperationResponseToOsFunction\n"));
 
   //
   // Get the Physical Presence variable
@@ -71,7 +71,7 @@ Tcg2PhysicalPresenceLibReturnOperationResponseToOsFunction (
   if (EFI_ERROR (Status)) {
     *MostRecentRequest = 0;
     *Response          = 0;
-    DEBUG ((EFI_D_ERROR, "[TPM2] Get PP variable failure! Status = %r\n", Status));
+    DEBUG ((DEBUG_ERROR, "[TPM2] Get PP variable failure! Status = %r\n", Status));
     return TCG_PP_RETURN_TPM_OPERATION_RESPONSE_FAILURE;
   }
 
@@ -108,7 +108,7 @@ Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunctionEx (
   EFI_TCG2_PHYSICAL_PRESENCE        PpData;
   EFI_TCG2_PHYSICAL_PRESENCE_FLAGS  Flags;
 
-  DEBUG ((EFI_D_INFO, "[TPM2] SubmitRequestToPreOSFunction, Request = %x, %x\n", *OperationRequest, *RequestParameter));
+  DEBUG ((DEBUG_INFO, "[TPM2] SubmitRequestToPreOSFunction, Request = %x, %x\n", *OperationRequest, *RequestParameter));
   ReturnCode = TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS;
 
   //
@@ -123,7 +123,7 @@ Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunctionEx (
                                  &PpData
                                  );
   if (EFI_ERROR (Status)) {
-    DEBUG ((EFI_D_ERROR, "[TPM2] Get PP variable failure! Status = %r\n", Status));
+    DEBUG ((DEBUG_ERROR, "[TPM2] Get PP variable failure! Status = %r\n", Status));
     ReturnCode = TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE;
     goto EXIT;
   }
@@ -147,7 +147,7 @@ Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunctionEx (
                                    &PpData
                                    );
     if (EFI_ERROR (Status)) {
-      DEBUG ((EFI_D_ERROR, "[TPM2] Set PP variable failure! Status = %r\n", Status));
+      DEBUG ((DEBUG_ERROR, "[TPM2] Set PP variable failure! Status = %r\n", Status));
       ReturnCode = TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE;
       goto EXIT;
     }
@@ -173,7 +173,7 @@ Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunctionEx (
   // Sync PPRQ/PPRM from PP Variable if PP submission fails
   //
   if (ReturnCode != TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS) {
-    DEBUG ((EFI_D_ERROR, "[TPM2] Submit PP Request failure! Sync PPRQ/PPRM with PP variable.\n", Status));
+    DEBUG ((DEBUG_ERROR, "[TPM2] Submit PP Request failure! Sync PPRQ/PPRM with PP variable.\n", Status));
     DataSize = sizeof (EFI_TCG2_PHYSICAL_PRESENCE);
     ZeroMem(&PpData, DataSize);
     Status = mTcg2PpSmmVariable->SmmGetVariable (
@@ -245,7 +245,7 @@ Tcg2PhysicalPresenceLibGetUserConfirmationStatusFunction (
   EFI_TCG2_PHYSICAL_PRESENCE_FLAGS  Flags;
   BOOLEAN                           RequestConfirmed;
 
-  DEBUG ((EFI_D_INFO, "[TPM2] GetUserConfirmationStatusFunction, Request = %x\n", OperationRequest));
+  DEBUG ((DEBUG_INFO, "[TPM2] GetUserConfirmationStatusFunction, Request = %x\n", OperationRequest));
 
   //
   // Get the Physical Presence variable
@@ -259,7 +259,7 @@ Tcg2PhysicalPresenceLibGetUserConfirmationStatusFunction (
                                  &PpData
                                  );
   if (EFI_ERROR (Status)) {
-    DEBUG ((EFI_D_ERROR, "[TPM2] Get PP variable failure! Status = %r\n", Status));
+    DEBUG ((DEBUG_ERROR, "[TPM2] Get PP variable failure! Status = %r\n", Status));
     return TCG_PP_GET_USER_CONFIRMATION_BLOCKED_BY_BIOS_CONFIGURATION;
   }
   //
@@ -274,7 +274,7 @@ Tcg2PhysicalPresenceLibGetUserConfirmationStatusFunction (
                                  &Flags
                                  );
   if (EFI_ERROR (Status)) {
-    DEBUG ((EFI_D_ERROR, "[TPM2] Get PP flags failure! Status = %r\n", Status));
+    DEBUG ((DEBUG_ERROR, "[TPM2] Get PP flags failure! Status = %r\n", Status));
     return TCG_PP_GET_USER_CONFIRMATION_BLOCKED_BY_BIOS_CONFIGURATION;
   }
 
@@ -380,9 +380,8 @@ Tcg2PhysicalPresenceLibGetUserConfirmationStatusFunction (
 **/
 EFI_STATUS
 EFIAPI
-Tcg2PhysicalPresenceLibConstructor (
-  IN EFI_HANDLE        ImageHandle,
-  IN EFI_SYSTEM_TABLE  *SystemTable
+Tcg2PhysicalPresenceLibCommonConstructor (
+  VOID
   )
 {
   EFI_STATUS  Status;
@@ -394,7 +393,7 @@ Tcg2PhysicalPresenceLibConstructor (
   //
   // Locate SmmVariableProtocol.
   //
-  Status = gSmst->SmmLocateProtocol (&gEfiSmmVariableProtocolGuid, NULL, (VOID**)&mTcg2PpSmmVariable);
+  Status = gMmst->MmLocateProtocol (&gEfiSmmVariableProtocolGuid, NULL, (VOID**)&mTcg2PpSmmVariable);
   ASSERT_EFI_ERROR (Status);
 
   mTcg2PhysicalPresenceFlags = PcdGet32(PcdTcg2PhysicalPresenceFlags);
diff --git a/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenceLib.c b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenceLib.c
index 8afaa0a7857d..36d8b89dcdd9 100644
--- a/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenceLib.c
+++ b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenceLib.c
@@ -17,355 +17,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 
 #include <PiSmm.h>
 
-#include <Guid/Tcg2PhysicalPresenceData.h>
-
-#include <Protocol/SmmVariable.h>
-
-#include <Library/BaseLib.h>
-#include <Library/DebugLib.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/Tcg2PpVendorLib.h>
-#include <Library/SmmServicesTableLib.h>
-
-#define     PP_INF_VERSION_1_2    "1.2"
-
-EFI_SMM_VARIABLE_PROTOCOL  *mTcg2PpSmmVariable;
-BOOLEAN                    mIsTcg2PPVerLowerThan_1_3 = FALSE;
-UINT32                     mTcg2PhysicalPresenceFlags;
-
-/**
-  The handler for TPM physical presence function:
-  Return TPM Operation Response to OS Environment.
-
-  This API should be invoked in OS runtime phase to interface with ACPI method.
-
-  @param[out]     MostRecentRequest Most recent operation request.
-  @param[out]     Response          Response to the most recent operation request.
-
-  @return Return Code for Return TPM Operation Response to OS Environment.
-**/
-UINT32
-EFIAPI
-Tcg2PhysicalPresenceLibReturnOperationResponseToOsFunction (
-  OUT UINT32                *MostRecentRequest,
-  OUT UINT32                *Response
-  )
-{
-  EFI_STATUS                        Status;
-  UINTN                             DataSize;
-  EFI_TCG2_PHYSICAL_PRESENCE        PpData;
-
-  DEBUG ((EFI_D_INFO, "[TPM2] ReturnOperationResponseToOsFunction\n"));
-
-  //
-  // Get the Physical Presence variable
-  //
-  DataSize = sizeof (EFI_TCG2_PHYSICAL_PRESENCE);
-  Status = mTcg2PpSmmVariable->SmmGetVariable (
-                                 TCG2_PHYSICAL_PRESENCE_VARIABLE,
-                                 &gEfiTcg2PhysicalPresenceGuid,
-                                 NULL,
-                                 &DataSize,
-                                 &PpData
-                                 );
-  if (EFI_ERROR (Status)) {
-    *MostRecentRequest = 0;
-    *Response          = 0;
-    DEBUG ((EFI_D_ERROR, "[TPM2] Get PP variable failure! Status = %r\n", Status));
-    return TCG_PP_RETURN_TPM_OPERATION_RESPONSE_FAILURE;
-  }
-
-  *MostRecentRequest = PpData.LastPPRequest;
-  *Response          = PpData.PPResponse;
-
-  return TCG_PP_RETURN_TPM_OPERATION_RESPONSE_SUCCESS;
-}
-
-/**
-  The handler for TPM physical presence function:
-  Submit TPM Operation Request to Pre-OS Environment and
-  Submit TPM Operation Request to Pre-OS Environment 2.
-
-  This API should be invoked in OS runtime phase to interface with ACPI method.
-
-  Caution: This function may receive untrusted input.
-
-  @param[in, out]  Pointer to OperationRequest TPM physical presence operation request.
-  @param[in, out]  Pointer to RequestParameter TPM physical presence operation request parameter.
-
-  @return Return Code for Submit TPM Operation Request to Pre-OS Environment and
-        Submit TPM Operation Request to Pre-OS Environment 2.
-  **/
-UINT32
-Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunctionEx (
-  IN OUT UINT32               *OperationRequest,
-  IN OUT UINT32               *RequestParameter
-  )
-{
-  EFI_STATUS                        Status;
-  UINT32                            ReturnCode;
-  UINTN                             DataSize;
-  EFI_TCG2_PHYSICAL_PRESENCE        PpData;
-  EFI_TCG2_PHYSICAL_PRESENCE_FLAGS  Flags;
-
-  DEBUG ((EFI_D_INFO, "[TPM2] SubmitRequestToPreOSFunction, Request = %x, %x\n", *OperationRequest, *RequestParameter));
-  ReturnCode = TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS;
-
-  //
-  // Get the Physical Presence variable
-  //
-  DataSize = sizeof (EFI_TCG2_PHYSICAL_PRESENCE);
-  Status = mTcg2PpSmmVariable->SmmGetVariable (
-                                 TCG2_PHYSICAL_PRESENCE_VARIABLE,
-                                 &gEfiTcg2PhysicalPresenceGuid,
-                                 NULL,
-                                 &DataSize,
-                                 &PpData
-                                 );
-  if (EFI_ERROR (Status)) {
-    DEBUG ((EFI_D_ERROR, "[TPM2] Get PP variable failure! Status = %r\n", Status));
-    ReturnCode = TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE;
-    goto EXIT;
-  }
-
-  if ((*OperationRequest > TCG2_PHYSICAL_PRESENCE_NO_ACTION_MAX) &&
-      (*OperationRequest < TCG2_PHYSICAL_PRESENCE_STORAGE_MANAGEMENT_BEGIN) ) {
-    ReturnCode = TCG_PP_SUBMIT_REQUEST_TO_PREOS_NOT_IMPLEMENTED;
-    goto EXIT;
-  }
-
-  if ((PpData.PPRequest != *OperationRequest) ||
-      (PpData.PPRequestParameter != *RequestParameter)) {
-    PpData.PPRequest = (UINT8)*OperationRequest;
-    PpData.PPRequestParameter = *RequestParameter;
-    DataSize = sizeof (EFI_TCG2_PHYSICAL_PRESENCE);
-    Status = mTcg2PpSmmVariable->SmmSetVariable (
-                                   TCG2_PHYSICAL_PRESENCE_VARIABLE,
-                                   &gEfiTcg2PhysicalPresenceGuid,
-                                   EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
-                                   DataSize,
-                                   &PpData
-                                   );
-    if (EFI_ERROR (Status)) {
-      DEBUG ((EFI_D_ERROR, "[TPM2] Set PP variable failure! Status = %r\n", Status));
-      ReturnCode = TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE;
-      goto EXIT;
-    }
-  }
-
-  if (*OperationRequest >= TCG2_PHYSICAL_PRESENCE_VENDOR_SPECIFIC_OPERATION) {
-    DataSize = sizeof (EFI_TCG2_PHYSICAL_PRESENCE_FLAGS);
-    Status = mTcg2PpSmmVariable->SmmGetVariable (
-                                   TCG2_PHYSICAL_PRESENCE_FLAGS_VARIABLE,
-                                   &gEfiTcg2PhysicalPresenceGuid,
-                                   NULL,
-                                   &DataSize,
-                                   &Flags
-                                   );
-    if (EFI_ERROR (Status)) {
-      Flags.PPFlags = mTcg2PhysicalPresenceFlags;
-    }
-    ReturnCode = Tcg2PpVendorLibSubmitRequestToPreOSFunction (*OperationRequest, Flags.PPFlags, *RequestParameter);
-  }
-
-EXIT:
-  //
-  // Sync PPRQ/PPRM from PP Variable if PP submission fails
-  //
-  if (ReturnCode != TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS) {
-    DEBUG ((EFI_D_ERROR, "[TPM2] Submit PP Request failure! Sync PPRQ/PPRM with PP variable.\n", Status));
-    DataSize = sizeof (EFI_TCG2_PHYSICAL_PRESENCE);
-    ZeroMem(&PpData, DataSize);
-    Status = mTcg2PpSmmVariable->SmmGetVariable (
-                                   TCG2_PHYSICAL_PRESENCE_VARIABLE,
-                                   &gEfiTcg2PhysicalPresenceGuid,
-                                   NULL,
-                                   &DataSize,
-                                   &PpData
-                                   );
-    *OperationRequest = (UINT32)PpData.PPRequest;
-    *RequestParameter = PpData.PPRequestParameter;
-  }
-
-  return ReturnCode;
-}
-
-/**
-  The handler for TPM physical presence function:
-  Submit TPM Operation Request to Pre-OS Environment and
-  Submit TPM Operation Request to Pre-OS Environment 2.
-
-  This API should be invoked in OS runtime phase to interface with ACPI method.
-
-  Caution: This function may receive untrusted input.
-
-  @param[in]      OperationRequest TPM physical presence operation request.
-  @param[in]      RequestParameter TPM physical presence operation request parameter.
-
-  @return Return Code for Submit TPM Operation Request to Pre-OS Environment and
-          Submit TPM Operation Request to Pre-OS Environment 2.
-**/
-UINT32
-EFIAPI
-Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction (
-  IN UINT32                 OperationRequest,
-  IN UINT32                 RequestParameter
-  )
-{
-  UINT32                 TempOperationRequest;
-  UINT32                 TempRequestParameter;
-
-  TempOperationRequest = OperationRequest;
-  TempRequestParameter = RequestParameter;
-
-  return Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunctionEx(&TempOperationRequest, &TempRequestParameter);
-}
-
-/**
-  The handler for TPM physical presence function:
-  Get User Confirmation Status for Operation.
-
-  This API should be invoked in OS runtime phase to interface with ACPI method.
-
-  Caution: This function may receive untrusted input.
-
-  @param[in]      OperationRequest TPM physical presence operation request.
-
-  @return Return Code for Get User Confirmation Status for Operation.
-**/
-UINT32
-EFIAPI
-Tcg2PhysicalPresenceLibGetUserConfirmationStatusFunction (
-  IN UINT32                 OperationRequest
-  )
-{
-  EFI_STATUS                        Status;
-  UINTN                             DataSize;
-  EFI_TCG2_PHYSICAL_PRESENCE        PpData;
-  EFI_TCG2_PHYSICAL_PRESENCE_FLAGS  Flags;
-  BOOLEAN                           RequestConfirmed;
-
-  DEBUG ((EFI_D_INFO, "[TPM2] GetUserConfirmationStatusFunction, Request = %x\n", OperationRequest));
-
-  //
-  // Get the Physical Presence variable
-  //
-  DataSize = sizeof (EFI_TCG2_PHYSICAL_PRESENCE);
-  Status = mTcg2PpSmmVariable->SmmGetVariable (
-                                 TCG2_PHYSICAL_PRESENCE_VARIABLE,
-                                 &gEfiTcg2PhysicalPresenceGuid,
-                                 NULL,
-                                 &DataSize,
-                                 &PpData
-                                 );
-  if (EFI_ERROR (Status)) {
-    DEBUG ((EFI_D_ERROR, "[TPM2] Get PP variable failure! Status = %r\n", Status));
-    return TCG_PP_GET_USER_CONFIRMATION_BLOCKED_BY_BIOS_CONFIGURATION;
-  }
-  //
-  // Get the Physical Presence flags
-  //
-  DataSize = sizeof (EFI_TCG2_PHYSICAL_PRESENCE_FLAGS);
-  Status = mTcg2PpSmmVariable->SmmGetVariable (
-                                 TCG2_PHYSICAL_PRESENCE_FLAGS_VARIABLE,
-                                 &gEfiTcg2PhysicalPresenceGuid,
-                                 NULL,
-                                 &DataSize,
-                                 &Flags
-                                 );
-  if (EFI_ERROR (Status)) {
-    DEBUG ((EFI_D_ERROR, "[TPM2] Get PP flags failure! Status = %r\n", Status));
-    return TCG_PP_GET_USER_CONFIRMATION_BLOCKED_BY_BIOS_CONFIGURATION;
-  }
-
-  RequestConfirmed = FALSE;
-
-  switch (OperationRequest) {
-    case TCG2_PHYSICAL_PRESENCE_CLEAR:
-    case TCG2_PHYSICAL_PRESENCE_ENABLE_CLEAR:
-    case TCG2_PHYSICAL_PRESENCE_ENABLE_CLEAR_2:
-    case TCG2_PHYSICAL_PRESENCE_ENABLE_CLEAR_3:
-      if ((Flags.PPFlags & TCG2_BIOS_TPM_MANAGEMENT_FLAG_PP_REQUIRED_FOR_CLEAR) == 0) {
-        RequestConfirmed = TRUE;
-      }
-      break;
-
-    case TCG2_PHYSICAL_PRESENCE_NO_ACTION:
-    case TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_CLEAR_TRUE:
-      RequestConfirmed = TRUE;
-      break;
-
-    case TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_CLEAR_FALSE:
-      break;
-
-    case TCG2_PHYSICAL_PRESENCE_SET_PCR_BANKS:
-      if ((Flags.PPFlags & TCG2_BIOS_TPM_MANAGEMENT_FLAG_PP_REQUIRED_FOR_CHANGE_PCRS) == 0) {
-        RequestConfirmed = TRUE;
-      }
-      break;
-
-    case TCG2_PHYSICAL_PRESENCE_CHANGE_EPS:
-      if ((Flags.PPFlags & TCG2_BIOS_TPM_MANAGEMENT_FLAG_PP_REQUIRED_FOR_CHANGE_EPS) == 0) {
-        RequestConfirmed = TRUE;
-      }
-      break;
-
-    case TCG2_PHYSICAL_PRESENCE_LOG_ALL_DIGESTS:
-      RequestConfirmed = TRUE;
-      break;
-
-    case TCG2_PHYSICAL_PRESENCE_ENABLE_BLOCK_SID:
-      if ((Flags.PPFlags & TCG2_BIOS_STORAGE_MANAGEMENT_FLAG_PP_REQUIRED_FOR_ENABLE_BLOCK_SID) == 0) {
-        RequestConfirmed = TRUE;
-      }
-      break;
-
-    case TCG2_PHYSICAL_PRESENCE_DISABLE_BLOCK_SID:
-      if ((Flags.PPFlags & TCG2_BIOS_STORAGE_MANAGEMENT_FLAG_PP_REQUIRED_FOR_DISABLE_BLOCK_SID) == 0) {
-        RequestConfirmed = TRUE;
-      }
-      break;
-
-    case TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_ENABLE_BLOCK_SID_FUNC_TRUE:
-    case TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_DISABLE_BLOCK_SID_FUNC_TRUE:
-      RequestConfirmed = TRUE;
-      break;
-
-    case TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_ENABLE_BLOCK_SID_FUNC_FALSE:
-    case TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_DISABLE_BLOCK_SID_FUNC_FALSE:
-      break;
-
-    default:
-      if (!mIsTcg2PPVerLowerThan_1_3) {
-        if (OperationRequest < TCG2_PHYSICAL_PRESENCE_VENDOR_SPECIFIC_OPERATION) {
-          //
-          // TCG2 PP1.3 spec defined operations that are reserved or un-implemented
-          //
-          return TCG_PP_GET_USER_CONFIRMATION_NOT_IMPLEMENTED;
-        }
-      } else {
-       //
-       // TCG PP lower than 1.3. (1.0, 1.1, 1.2)
-       //
-       if (OperationRequest <= TCG2_PHYSICAL_PRESENCE_NO_ACTION_MAX) {
-         RequestConfirmed = TRUE;
-       } else if (OperationRequest < TCG2_PHYSICAL_PRESENCE_VENDOR_SPECIFIC_OPERATION) {
-         return TCG_PP_GET_USER_CONFIRMATION_NOT_IMPLEMENTED;
-       }
-      }
-      break;
-  }
-
-  if (OperationRequest >= TCG2_PHYSICAL_PRESENCE_VENDOR_SPECIFIC_OPERATION) {
-    return Tcg2PpVendorLibGetUserConfirmationStatusFunction (OperationRequest, Flags.PPFlags);
-  }
-
-  if (RequestConfirmed) {
-    return TCG_PP_GET_USER_CONFIRMATION_ALLOWED_AND_PPUSER_NOT_REQUIRED;
-  } else {
-    return TCG_PP_GET_USER_CONFIRMATION_ALLOWED_AND_PPUSER_REQUIRED;
-  }
-}
+#include "MmTcg2PhysicalPresenceLibCommon.h"
 
 /**
   The constructor function locates SmmVariable protocol.
@@ -380,24 +32,10 @@ Tcg2PhysicalPresenceLibGetUserConfirmationStatusFunction (
 **/
 EFI_STATUS
 EFIAPI
-Tcg2PhysicalPresenceLibConstructor (
+Tcg2PhysicalPresenceLibTraditionalConstructor (
   IN EFI_HANDLE        ImageHandle,
   IN EFI_SYSTEM_TABLE  *SystemTable
   )
 {
-  EFI_STATUS  Status;
-
-  if (AsciiStrnCmp(PP_INF_VERSION_1_2, (CHAR8 *)PcdGetPtr(PcdTcgPhysicalPresenceInterfaceVer), sizeof(PP_INF_VERSION_1_2) - 1) >= 0) {
-    mIsTcg2PPVerLowerThan_1_3 = TRUE;
-  }
-
-  //
-  // Locate SmmVariableProtocol.
-  //
-  Status = gSmst->SmmLocateProtocol (&gEfiSmmVariableProtocolGuid, NULL, (VOID**)&mTcg2PpSmmVariable);
-  ASSERT_EFI_ERROR (Status);
-
-  mTcg2PhysicalPresenceFlags = PcdGet32(PcdTcg2PhysicalPresenceFlags);
-
-  return EFI_SUCCESS;
+  return Tcg2PhysicalPresenceLibCommonConstructor ();
 }
diff --git a/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/StandaloneMmTcg2PhysicalPresenceLib.c b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/StandaloneMmTcg2PhysicalPresenceLib.c
new file mode 100644
index 000000000000..5c298a8d5720
--- /dev/null
+++ b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/StandaloneMmTcg2PhysicalPresenceLib.c
@@ -0,0 +1,42 @@
+/** @file
+  Handle TPM 2.0 physical presence requests from OS.
+
+  This library will handle TPM 2.0 physical presence request from OS.
+
+  Caution: This module requires additional review when modified.
+  This driver will have external input - variable.
+  This external input must be validated carefully to avoid security issue.
+
+  Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction() and Tcg2PhysicalPresenceLibGetUserConfirmationStatusFunction()
+  will receive untrusted input and do validation.
+
+Copyright (c) 2015 - 2020, Intel Corporation. All rights reserved.<BR>
+Copyright (c) Microsoft Corporation.
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <PiMm.h>
+
+#include "MmTcg2PhysicalPresenceLibCommon.h"
+
+/**
+  The constructor function locates SmmVariable protocol.
+
+  It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.
+
+  @param  ImageHandle   The firmware allocated handle for the EFI image.
+  @param  SystemTable   A pointer to the EFI System Table.
+
+  @retval EFI_SUCCESS   The constructor successfully added string package.
+  @retval Other value   The constructor can't add string package.
+**/
+EFI_STATUS
+EFIAPI
+Tcg2PhysicalPresenceLibStandaloneMmConstructor (
+  IN EFI_HANDLE           ImageHandle,
+  IN EFI_MM_SYSTEM_TABLE  *SystemTable
+  )
+{
+  return Tcg2PhysicalPresenceLibCommonConstructor ();
+}
diff --git a/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/MmTcg2PhysicalPresenceLibCommon.h b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/MmTcg2PhysicalPresenceLibCommon.h
new file mode 100644
index 000000000000..c53674d37f12
--- /dev/null
+++ b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/MmTcg2PhysicalPresenceLibCommon.h
@@ -0,0 +1,35 @@
+/** @file
+  Handle TPM 2.0 physical presence requests from OS.
+
+  This library will handle TPM 2.0 physical presence request from OS.
+
+  Caution: This module requires additional review when modified.
+  This driver will have external input - variable.
+  This external input must be validated carefully to avoid security issue.
+
+  Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction() and Tcg2PhysicalPresenceLibGetUserConfirmationStatusFunction()
+  will receive untrusted input and do validation.
+
+Copyright (c) 2015 - 2020, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef _MM_TCG2_PHYSICAL_PRESENCE_LIB_COMMON_H_
+#define _MM_TCG2_PHYSICAL_PRESENCE_LIB_COMMON_H_
+
+/**
+  The constructor function locates MmVariable protocol.
+
+  It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.
+
+  @retval EFI_SUCCESS   The constructor successfully added string package.
+  @retval Other value   The constructor can't add string package.
+**/
+EFI_STATUS
+EFIAPI
+Tcg2PhysicalPresenceLibCommonConstructor (
+  VOID
+  );
+
+#endif
diff --git a/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenceLib.inf b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenceLib.inf
index 6a9bdf66f0a6..d911adbdb648 100644
--- a/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenceLib.inf
+++ b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenceLib.inf
@@ -20,7 +20,7 @@ [Defines]
   MODULE_TYPE                    = DXE_SMM_DRIVER
   VERSION_STRING                 = 1.0
   LIBRARY_CLASS                  = Tcg2PhysicalPresenceLib|DXE_SMM_DRIVER
-  CONSTRUCTOR                    = Tcg2PhysicalPresenceLibConstructor
+  CONSTRUCTOR                    = Tcg2PhysicalPresenceLibTraditionalConstructor
 
 #
 # The following information is for reference only and not required by the build tools.
@@ -30,6 +30,8 @@ [Defines]
 
 [Sources]
   SmmTcg2PhysicalPresenceLib.c
+  MmTcg2PhysicalPresenceLibCommon.c
+  MmTcg2PhysicalPresenceLibCommon.h
 
 [Packages]
   MdePkg/MdePkg.dec
@@ -39,7 +41,7 @@ [Packages]
 [LibraryClasses]
   DebugLib
   Tcg2PpVendorLib
-  SmmServicesTableLib
+  MmServicesTableLib
   BaseMemoryLib
 
 [Guids]
diff --git a/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenceLib.inf b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/StandaloneMmTcg2PhysicalPresenceLib.inf
similarity index 64%
copy from SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenceLib.inf
copy to SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/StandaloneMmTcg2PhysicalPresenceLib.inf
index 6a9bdf66f0a6..6d11b6b9f198 100644
--- a/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenceLib.inf
+++ b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/StandaloneMmTcg2PhysicalPresenceLib.inf
@@ -8,19 +8,20 @@
 #  This external input must be validated carefully to avoid security issue.
 #
 # Copyright (c) 2015 - 2020, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) Microsoft Corporation.
 # SPDX-License-Identifier: BSD-2-Clause-Patent
 #
 ##
 
 [Defines]
   INF_VERSION                    = 0x00010005
-  BASE_NAME                      = SmmTcg2PhysicalPresenceLib
-  MODULE_UNI_FILE                = SmmTcg2PhysicalPresenceLib.uni
-  FILE_GUID                      = AAE02741-858B-4964-9887-CA870489D944
-  MODULE_TYPE                    = DXE_SMM_DRIVER
+  BASE_NAME                      = StandaloneMmTcg2PhysicalPresenceLib
+  FILE_GUID                      = 75E3D07B-689C-4F42-A8A0-46AFAE868A6F
+  MODULE_TYPE                    = MM_STANDALONE
+  PI_SPECIFICATION_VERSION       = 0x00010032
   VERSION_STRING                 = 1.0
-  LIBRARY_CLASS                  = Tcg2PhysicalPresenceLib|DXE_SMM_DRIVER
-  CONSTRUCTOR                    = Tcg2PhysicalPresenceLibConstructor
+  LIBRARY_CLASS                  = Tcg2PhysicalPresenceLib|MM_STANDALONE
+  CONSTRUCTOR                    = Tcg2PhysicalPresenceLibStandaloneMmConstructor
 
 #
 # The following information is for reference only and not required by the build tools.
@@ -29,7 +30,9 @@ [Defines]
 #
 
 [Sources]
-  SmmTcg2PhysicalPresenceLib.c
+  StandaloneMmTcg2PhysicalPresenceLib.c
+  MmTcg2PhysicalPresenceLibCommon.c
+  MmTcg2PhysicalPresenceLibCommon.h
 
 [Packages]
   MdePkg/MdePkg.dec
@@ -39,7 +42,7 @@ [Packages]
 [LibraryClasses]
   DebugLib
   Tcg2PpVendorLib
-  SmmServicesTableLib
+  MmServicesTableLib
   BaseMemoryLib
 
 [Guids]
@@ -48,6 +51,9 @@ [Guids]
   ## SOMETIMES_CONSUMES ## Variable:L"PhysicalPresenceFlags"
   gEfiTcg2PhysicalPresenceGuid
 
+[Protocols]
+  gEfiSmmVariableProtocolGuid                                       ## CONSUMES
+
 [Pcd]
   gEfiSecurityPkgTokenSpaceGuid.PcdTcgPhysicalPresenceInterfaceVer  ## CONSUMES
   gEfiSecurityPkgTokenSpaceGuid.PcdTcg2PhysicalPresenceFlags        ## SOMETIMES_CONSUMES
diff --git a/SecurityPkg/SecurityPkg.dsc b/SecurityPkg/SecurityPkg.dsc
index 36d15b79f928..7240b2573e4e 100644
--- a/SecurityPkg/SecurityPkg.dsc
+++ b/SecurityPkg/SecurityPkg.dsc
@@ -150,6 +150,7 @@ [LibraryClasses.common.UEFI_DRIVER, LibraryClasses.common.UEFI_APPLICATION]
 [LibraryClasses.common.DXE_SMM_DRIVER]
   HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
   SmmServicesTableLib|MdePkg/Library/SmmServicesTableLib/SmmServicesTableLib.inf
+  MmServicesTableLib|MdePkg/Library/MmServicesTableLib/MmServicesTableLib.inf
   MemoryAllocationLib|MdePkg/Library/SmmMemoryAllocationLib/SmmMemoryAllocationLib.inf
   ReportStatusCodeLib|MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLib.inf
   SmmMemLib|MdePkg/Library/SmmMemLib/SmmMemLib.inf
@@ -316,6 +317,7 @@ [Components.IA32, Components.X64]
   SecurityPkg/Tcg/TcgSmm/TcgSmm.inf
   SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.inf
   SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenceLib.inf
+  SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/StandaloneMmTcg2PhysicalPresenceLib.inf
 
   #
   # Random Number Generator
-- 
2.28.0.windows.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH v1 12/15] SecurityPkg: Tcg2PpVendorLibNull: Added support for MM_STANDALONE type
       [not found] <20201218185011.1366-1-kun.q@outlook.com>
                   ` (10 preceding siblings ...)
  2020-12-18 18:50 ` [PATCH v1 11/15] SecurityPkg: Tcg2PhysicalPresenceLib: Introduce StandaloneMm instance Kun Qin
@ 2020-12-18 18:50 ` Kun Qin
  2020-12-28  0:08   ` Yao, Jiewen
  2020-12-18 18:50 ` [PATCH v1 13/15] SecurityPkg: Tpm2DeviceLibDTpm: Introduce StandaloneMm instance Kun Qin
                   ` (2 subsequent siblings)
  14 siblings, 1 reply; 44+ messages in thread
From: Kun Qin @ 2020-12-18 18:50 UTC (permalink / raw)
  To: devel; +Cc: Jiewen Yao, Jian J Wang, Qi Zhang, Rahul Kumar

This change extends this null instance of Tcg2PpVendorLib to support
MM_STANDALONE drivers.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Qi Zhang <qi1.zhang@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>

Signed-off-by: Kun Qin <kun.q@outlook.com>
---
 SecurityPkg/Library/Tcg2PpVendorLibNull/Tcg2PpVendorLibNull.inf | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/SecurityPkg/Library/Tcg2PpVendorLibNull/Tcg2PpVendorLibNull.inf b/SecurityPkg/Library/Tcg2PpVendorLibNull/Tcg2PpVendorLibNull.inf
index b969cbf9afff..9b18a1ab82f1 100644
--- a/SecurityPkg/Library/Tcg2PpVendorLibNull/Tcg2PpVendorLibNull.inf
+++ b/SecurityPkg/Library/Tcg2PpVendorLibNull/Tcg2PpVendorLibNull.inf
@@ -13,7 +13,7 @@ [Defines]
   FILE_GUID                      = 51924AE9-BE81-4820-94BA-7C9546E702D0
   MODULE_TYPE                    = DXE_DRIVER
   VERSION_STRING                 = 1.0
-  LIBRARY_CLASS                  = Tcg2PpVendorLib|DXE_RUNTIME_DRIVER DXE_SMM_DRIVER DXE_DRIVER
+  LIBRARY_CLASS                  = Tcg2PpVendorLib|DXE_RUNTIME_DRIVER DXE_SMM_DRIVER DXE_DRIVER MM_STANDALONE
 
 #
 # The following information is for reference only and not required by the build tools.
-- 
2.28.0.windows.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH v1 13/15] SecurityPkg: Tpm2DeviceLibDTpm: Introduce StandaloneMm instance
       [not found] <20201218185011.1366-1-kun.q@outlook.com>
                   ` (11 preceding siblings ...)
  2020-12-18 18:50 ` [PATCH v1 12/15] SecurityPkg: Tcg2PpVendorLibNull: Added support for MM_STANDALONE type Kun Qin
@ 2020-12-18 18:50 ` Kun Qin
  2020-12-28  0:08   ` Yao, Jiewen
  2020-12-18 18:50 ` [PATCH v1 14/15] UefiCpuPkg: CpuIo2Smm: Support of CpuIo driver under StandaloneMm Kun Qin
  2020-12-18 18:50 ` [PATCH v1 15/15] UefiCpuPkg: SmmCpuExceptionHandlerLib: Added StandaloneMm module support Kun Qin
  14 siblings, 1 reply; 44+ messages in thread
From: Kun Qin @ 2020-12-18 18:50 UTC (permalink / raw)
  To: devel; +Cc: Jiewen Yao, Jian J Wang, Qi Zhang, Rahul Kumar

This change added a new instance of Tpm2DeviceLibDTpm to support drivers
of type MM_STANDALONE. It abstracts dynamic Pcd access into separate file
for different instances to avoid dynamic usage for StandaloneMm modules.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Qi Zhang <qi1.zhang@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>

Signed-off-by: Kun Qin <kun.q@outlook.com>
---
 SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.c                                          | 42 +-----------
 SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmBase.c                                      | 69 ++++++++++++++++++++
 SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmStandaloneMm.c                              | 67 +++++++++++++++++++
 SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.c                                        | 40 +-----------
 SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Ptp.c                                                    | 15 +++--
 SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.h                                          | 68 +++++++++++++++++++
 SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf                                        |  3 +
 SecurityPkg/Library/Tpm2DeviceLibDTpm/{Tpm2DeviceLibDTpm.inf => Tpm2DeviceLibDTpmStandaloneMm.inf} | 13 ++--
 SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.inf                                      |  3 +
 SecurityPkg/SecurityPkg.dsc                                                                        |  1 +
 10 files changed, 231 insertions(+), 90 deletions(-)

diff --git a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.c b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.c
index 42e1ecbce95a..238389dbdb1b 100644
--- a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.c
+++ b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.c
@@ -13,29 +13,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 #include <Library/Tpm2DeviceLib.h>
 #include <Library/PcdLib.h>
 
-/**
-  Return PTP interface type.
-
-  @param[in] Register                Pointer to PTP register.
-
-  @return PTP interface type.
-**/
-TPM2_PTP_INTERFACE_TYPE
-Tpm2GetPtpInterface (
-  IN VOID *Register
-  );
-
-/**
-  Return PTP CRB interface IdleByPass state.
-
-  @param[in] Register                Pointer to PTP register.
-
-  @return PTP CRB interface IdleByPass state.
-**/
-UINT8
-Tpm2GetIdleByPass (
-  IN VOID *Register
-  );
+#include "Tpm2DeviceLibDTpm.h"
 
 /**
   This service enables the sending of commands to the TPM2.
@@ -145,21 +123,5 @@ Tpm2DeviceLibConstructor (
   VOID
   )
 {
-  TPM2_PTP_INTERFACE_TYPE  PtpInterface;
-  UINT8                    IdleByPass;
-
-  //
-  // Cache current active TpmInterfaceType only when needed
-  //
-  if (PcdGet8(PcdActiveTpmInterfaceType) == 0xFF) {
-    PtpInterface = Tpm2GetPtpInterface ((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));
-    PcdSet8S(PcdActiveTpmInterfaceType, PtpInterface);
-  }
-
-  if (PcdGet8(PcdActiveTpmInterfaceType) == Tpm2PtpInterfaceCrb && PcdGet8(PcdCRBIdleByPass) == 0xFF) {
-    IdleByPass = Tpm2GetIdleByPass((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));
-    PcdSet8S(PcdCRBIdleByPass, IdleByPass);
-  }
-
-  return EFI_SUCCESS;
+  return InternalTpm2DeviceLibDTpmCommonConstructor ();
 }
diff --git a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmBase.c b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmBase.c
new file mode 100644
index 000000000000..aaa215eee9f7
--- /dev/null
+++ b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmBase.c
@@ -0,0 +1,69 @@
+/** @file
+  This file abstract internal interfaces of which implementation differs per library instance.
+
+Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved. <BR>
+Copyright (c) Microsoft Corporation.
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Library/Tpm2DeviceLib.h>
+#include <Library/PcdLib.h>
+
+#include "Tpm2DeviceLibDTpm.h"
+
+/**
+  Return cached PTP CRB interface IdleByPass state.
+
+  @return Cached PTP CRB interface IdleByPass state.
+**/
+UINT8
+GetCachedIdleByPass (
+  VOID
+  )
+{
+  return PcdGet8(PcdCRBIdleByPass);
+}
+
+/**
+  Return cached PTP interface type.
+
+  @return Cached PTP interface type.
+**/
+TPM2_PTP_INTERFACE_TYPE
+GetCachedPtpInterface (
+  VOID
+  )
+{
+  return PcdGet8(PcdActiveTpmInterfaceType);
+}
+
+/**
+  The common function cache current active TpmInterfaceType when needed.
+
+  @retval EFI_SUCCESS   DTPM2.0 instance is registered, or system does not support register DTPM2.0 instance
+**/
+EFI_STATUS
+EFIAPI
+InternalTpm2DeviceLibDTpmCommonConstructor (
+  VOID
+  )
+{
+  TPM2_PTP_INTERFACE_TYPE  PtpInterface;
+  UINT8                    IdleByPass;
+
+  //
+  // Cache current active TpmInterfaceType only when needed
+  //
+  if (PcdGet8(PcdActiveTpmInterfaceType) == 0xFF) {
+    PtpInterface = Tpm2GetPtpInterface ((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));
+    PcdSet8S(PcdActiveTpmInterfaceType, PtpInterface);
+  }
+
+  if (PcdGet8(PcdActiveTpmInterfaceType) == Tpm2PtpInterfaceCrb && PcdGet8(PcdCRBIdleByPass) == 0xFF) {
+    IdleByPass = Tpm2GetIdleByPass((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));
+    PcdSet8S(PcdCRBIdleByPass, IdleByPass);
+  }
+
+  return EFI_SUCCESS;
+}
diff --git a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmStandaloneMm.c b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmStandaloneMm.c
new file mode 100644
index 000000000000..9e3d3f0a8e9d
--- /dev/null
+++ b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmStandaloneMm.c
@@ -0,0 +1,67 @@
+/** @file
+  This file abstract internal interfaces of which implementation differs per library instance.
+
+Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved. <BR>
+Copyright (c) Microsoft Corporation.
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Library/Tpm2DeviceLib.h>
+
+#include "Tpm2DeviceLibDTpm.h"
+
+TPM2_PTP_INTERFACE_TYPE  mActiveTpmInterfaceType;
+UINT8                    mCRBIdleByPass;
+
+/**
+  Return cached PTP CRB interface IdleByPass state.
+
+  @return Cached PTP CRB interface IdleByPass state.
+**/
+UINT8
+GetCachedIdleByPass (
+  VOID
+  )
+{
+  return mCRBIdleByPass;
+}
+
+/**
+  Return cached PTP interface type.
+
+  @return Cached PTP interface type.
+**/
+TPM2_PTP_INTERFACE_TYPE
+GetCachedPtpInterface (
+  VOID
+  )
+{
+  return mActiveTpmInterfaceType;
+}
+
+/**
+  The common function cache current active TpmInterfaceType when needed.
+
+  @retval EFI_SUCCESS   DTPM2.0 instance is registered, or system does not support register DTPM2.0 instance
+**/
+EFI_STATUS
+EFIAPI
+InternalTpm2DeviceLibDTpmCommonConstructor (
+  VOID
+  )
+{
+  mActiveTpmInterfaceType = 0xFF;
+  mCRBIdleByPass = 0xFF;
+
+  //
+  // Always cache current active TpmInterfaceType for StandaloneMm implementation
+  //
+  mActiveTpmInterfaceType = Tpm2GetPtpInterface ((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));
+
+  if (mActiveTpmInterfaceType == Tpm2PtpInterfaceCrb) {
+    mCRBIdleByPass = Tpm2GetIdleByPass((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));
+  }
+
+  return EFI_SUCCESS;
+}
diff --git a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.c b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.c
index 691eaa40c045..053e597d2ee2 100644
--- a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.c
+++ b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.c
@@ -16,29 +16,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 
 #include <Guid/TpmInstance.h>
 
-/**
-  Return PTP interface type.
-
-  @param[in] Register                Pointer to PTP register.
-
-  @return PTP interface type.
-**/
-TPM2_PTP_INTERFACE_TYPE
-Tpm2GetPtpInterface (
-  IN VOID *Register
-  );
-
-/**
-  Return PTP CRB interface IdleByPass state.
-
-  @param[in] Register                Pointer to PTP register.
-
-  @return PTP CRB interface IdleByPass state.
-**/
-UINT8
-Tpm2GetIdleByPass (
-  IN VOID *Register
-  );
+#include "Tpm2DeviceLibDTpm.h"
 
 /**
   Dump PTP register information.
@@ -102,8 +80,6 @@ Tpm2InstanceLibDTpmConstructor (
   )
 {
   EFI_STATUS               Status;
-  TPM2_PTP_INTERFACE_TYPE  PtpInterface;
-  UINT8                    IdleByPass;
 
   Status = Tpm2RegisterTpm2DeviceLib (&mDTpm2InternalTpm2Device);
   if ((Status == EFI_SUCCESS) || (Status == EFI_UNSUPPORTED)) {
@@ -111,19 +87,7 @@ Tpm2InstanceLibDTpmConstructor (
     // Unsupported means platform policy does not need this instance enabled.
     //
     if (Status == EFI_SUCCESS) {
-      //
-      // Cache current active TpmInterfaceType only when needed
-      //
-      if (PcdGet8(PcdActiveTpmInterfaceType) == 0xFF) {
-        PtpInterface = Tpm2GetPtpInterface ((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));
-        PcdSet8S(PcdActiveTpmInterfaceType, PtpInterface);
-      }
-
-      if (PcdGet8(PcdActiveTpmInterfaceType) == Tpm2PtpInterfaceCrb && PcdGet8(PcdCRBIdleByPass) == 0xFF) {
-        IdleByPass = Tpm2GetIdleByPass((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));
-        PcdSet8S(PcdCRBIdleByPass, IdleByPass);
-      }
-
+      Status = InternalTpm2DeviceLibDTpmCommonConstructor ();
       DumpPtpInfo ((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));
     }
     return EFI_SUCCESS;
diff --git a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Ptp.c b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Ptp.c
index 2c73385b6ce5..f1f80916834f 100644
--- a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Ptp.c
+++ b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Ptp.c
@@ -2,6 +2,7 @@
   PTP (Platform TPM Profile) CRB (Command Response Buffer) interface used by dTPM2.0 library.
 
 Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>
+Copyright (c), Microsoft Corporation.
 SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
@@ -19,6 +20,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 #include <IndustryStandard/TpmPtp.h>
 #include <IndustryStandard/TpmTis.h>
 
+#include "Tpm2DeviceLibDTpm.h"
+
 //
 // Execution of the command may take from several seconds to minutes for certain
 // commands, such as key generation.
@@ -174,7 +177,7 @@ PtpCrbTpmCommand (
   // STEP 0:
   // if CapCRbIdelByPass == 0, enforce Idle state before sending command
   //
-  if (PcdGet8(PcdCRBIdleByPass) == 0 && (MmioRead32((UINTN)&CrbReg->CrbControlStatus) & PTP_CRB_CONTROL_AREA_STATUS_TPM_IDLE) == 0){
+  if (GetCachedIdleByPass () == 0 && (MmioRead32((UINTN)&CrbReg->CrbControlStatus) & PTP_CRB_CONTROL_AREA_STATUS_TPM_IDLE) == 0){
     Status = PtpCrbWaitRegisterBits (
               &CrbReg->CrbControlStatus,
               PTP_CRB_CONTROL_AREA_STATUS_TPM_IDLE,
@@ -330,7 +333,7 @@ PtpCrbTpmCommand (
   // Goto Ready State if command is completed successfully and TPM support IdleBypass
   // If not supported. flow down to GoIdle
   //
-  if (PcdGet8(PcdCRBIdleByPass) == 1) {
+  if (GetCachedIdleByPass () == 1) {
     MmioWrite32((UINTN)&CrbReg->CrbControlRequest, PTP_CRB_CONTROL_AREA_REQUEST_COMMAND_READY);
     return Status;
   }
@@ -350,7 +353,7 @@ PtpCrbTpmCommand (
   // Only enforce Idle state transition if execution fails when CRBIdleBypass==1
   // Leave regular Idle delay at the beginning of next command execution
   //
-  if (PcdGet8(PcdCRBIdleByPass) == 1){
+  if (GetCachedIdleByPass () == 1){
     Status = PtpCrbWaitRegisterBits (
                &CrbReg->CrbControlStatus,
                PTP_CRB_CONTROL_AREA_STATUS_TPM_IDLE,
@@ -519,7 +522,7 @@ DumpPtpInfo (
   Vid = 0xFFFF;
   Did = 0xFFFF;
   Rid = 0xFF;
-  PtpInterface = PcdGet8(PcdActiveTpmInterfaceType);
+  PtpInterface = GetCachedPtpInterface ();
   DEBUG ((EFI_D_INFO, "PtpInterface - %x\n", PtpInterface));
   switch (PtpInterface) {
   case Tpm2PtpInterfaceCrb:
@@ -564,7 +567,7 @@ DTpm2SubmitCommand (
 {
   TPM2_PTP_INTERFACE_TYPE  PtpInterface;
 
-  PtpInterface = PcdGet8(PcdActiveTpmInterfaceType);
+  PtpInterface = GetCachedPtpInterface ();
   switch (PtpInterface) {
   case Tpm2PtpInterfaceCrb:
     return PtpCrbTpmCommand (
@@ -603,7 +606,7 @@ DTpm2RequestUseTpm (
 {
   TPM2_PTP_INTERFACE_TYPE  PtpInterface;
 
-  PtpInterface = PcdGet8(PcdActiveTpmInterfaceType);
+  PtpInterface = GetCachedPtpInterface ();
   switch (PtpInterface) {
   case Tpm2PtpInterfaceCrb:
     return PtpCrbRequestUseTpm ((PTP_CRB_REGISTERS_PTR) (UINTN) PcdGet64 (PcdTpmBaseAddress));
diff --git a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.h b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.h
new file mode 100644
index 000000000000..4eabb6cd182e
--- /dev/null
+++ b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.h
@@ -0,0 +1,68 @@
+/** @file
+  This header file includes common internal fuction prototypes.
+
+Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved. <BR>
+Copyright (c) Microsoft Corporation.
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef _TPM2_DEVICE_LIB_DTPM_H_
+#define _TPM2_DEVICE_LIB_DTPM_H_
+
+/**
+  Return PTP interface type.
+
+  @param[in] Register                Pointer to PTP register.
+
+  @return PTP interface type.
+**/
+TPM2_PTP_INTERFACE_TYPE
+Tpm2GetPtpInterface (
+  IN VOID *Register
+  );
+
+/**
+  Return PTP CRB interface IdleByPass state.
+
+  @param[in] Register                Pointer to PTP register.
+
+  @return PTP CRB interface IdleByPass state.
+**/
+UINT8
+Tpm2GetIdleByPass (
+  IN VOID *Register
+  );
+
+/**
+  Return cached PTP interface type.
+
+  @return Cached PTP interface type.
+**/
+TPM2_PTP_INTERFACE_TYPE
+GetCachedPtpInterface (
+  VOID
+  );
+
+/**
+  Return cached PTP CRB interface IdleByPass state.
+
+  @return Cached PTP CRB interface IdleByPass state.
+**/
+UINT8
+GetCachedIdleByPass (
+  VOID
+  );
+
+/**
+  The common function cache current active TpmInterfaceType when needed.
+
+  @retval EFI_SUCCESS   DTPM2.0 instance is registered, or system does not support register DTPM2.0 instance
+**/
+EFI_STATUS
+EFIAPI
+InternalTpm2DeviceLibDTpmCommonConstructor (
+  VOID
+  );
+
+#endif // _TPM2_DEVICE_LIB_DTPM_H_
diff --git a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf
index 2b627504634d..be3a0053ccce 100644
--- a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf
+++ b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf
@@ -11,6 +11,7 @@
 #  only uses TPM 2.0 DTPM device.
 #
 # Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) Microsoft Corporation.
 # SPDX-License-Identifier: BSD-2-Clause-Patent
 #
 ##
@@ -34,6 +35,8 @@ [Sources]
   Tpm2Tis.c
   Tpm2Ptp.c
   Tpm2DeviceLibDTpm.c
+  Tpm2DeviceLibDTpmBase.c
+  Tpm2DeviceLibDTpm.h
 
 [Packages]
   MdePkg/MdePkg.dec
diff --git a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmStandaloneMm.inf
similarity index 70%
copy from SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf
copy to SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmStandaloneMm.inf
index 2b627504634d..18c08ad8bdcc 100644
--- a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf
+++ b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmStandaloneMm.inf
@@ -11,19 +11,20 @@
 #  only uses TPM 2.0 DTPM device.
 #
 # Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) Microsoft Corporation.
 # SPDX-License-Identifier: BSD-2-Clause-Patent
 #
 ##
 
 [Defines]
   INF_VERSION                    = 0x00010005
-  BASE_NAME                      = Tpm2DeviceLibDTpm
-  MODULE_UNI_FILE                = Tpm2DeviceLibDTpm.uni
-  FILE_GUID                      = E54A3327-A345-4068-8842-70AC0D519855
+  BASE_NAME                      = Tpm2DeviceLibDTpmStandaloneMm
+  FILE_GUID                      = 9A5DB21A-FF0B-46D0-8672-B4F83FEF1F0E
   MODULE_TYPE                    = BASE
   VERSION_STRING                 = 1.0
-  LIBRARY_CLASS                  = Tpm2DeviceLib|PEIM DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER
+  LIBRARY_CLASS                  = Tpm2DeviceLib|MM_STANDALONE
   CONSTRUCTOR                    = Tpm2DeviceLibConstructor
+
 #
 # The following information is for reference only and not required by the build tools.
 #
@@ -34,6 +35,8 @@ [Sources]
   Tpm2Tis.c
   Tpm2Ptp.c
   Tpm2DeviceLibDTpm.c
+  Tpm2DeviceLibDTpmStandaloneMm.c
+  Tpm2DeviceLibDTpm.h
 
 [Packages]
   MdePkg/MdePkg.dec
@@ -49,5 +52,3 @@ [LibraryClasses]
 
 [Pcd]
   gEfiSecurityPkgTokenSpaceGuid.PcdTpmBaseAddress            ## CONSUMES
-  gEfiSecurityPkgTokenSpaceGuid.PcdActiveTpmInterfaceType    ## PRODUCES
-  gEfiSecurityPkgTokenSpaceGuid.PcdCRBIdleByPass             ## PRODUCES
diff --git a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.inf b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.inf
index 5f267f552ce3..31113d93ee41 100644
--- a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.inf
+++ b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.inf
@@ -6,6 +6,7 @@
 #  and PTP (Platform TPM Profile) functions.
 #
 # Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) Microsoft Corporation
 # SPDX-License-Identifier: BSD-2-Clause-Patent
 #
 ##
@@ -30,6 +31,8 @@ [Sources]
   Tpm2Tis.c
   Tpm2Ptp.c
   Tpm2InstanceLibDTpm.c
+  Tpm2DeviceLibDTpmBase.c
+  Tpm2DeviceLibDTpm.h
 
 [Packages]
   MdePkg/MdePkg.dec
diff --git a/SecurityPkg/SecurityPkg.dsc b/SecurityPkg/SecurityPkg.dsc
index 7240b2573e4e..618420a56c33 100644
--- a/SecurityPkg/SecurityPkg.dsc
+++ b/SecurityPkg/SecurityPkg.dsc
@@ -211,6 +211,7 @@ [Components]
   SecurityPkg/Library/Tpm2DeviceLibTcg2/Tpm2DeviceLibTcg2.inf
   SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf
   SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.inf
+  SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmStandaloneMm.inf
   SecurityPkg/Library/Tpm2DeviceLibRouter/Tpm2DeviceLibRouterDxe.inf
   SecurityPkg/Library/Tpm2DeviceLibRouter/Tpm2DeviceLibRouterPei.inf
 
-- 
2.28.0.windows.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH v1 14/15] UefiCpuPkg: CpuIo2Smm: Support of CpuIo driver under StandaloneMm
       [not found] <20201218185011.1366-1-kun.q@outlook.com>
                   ` (12 preceding siblings ...)
  2020-12-18 18:50 ` [PATCH v1 13/15] SecurityPkg: Tpm2DeviceLibDTpm: Introduce StandaloneMm instance Kun Qin
@ 2020-12-18 18:50 ` Kun Qin
  2021-01-04 18:31   ` [edk2-devel] " Kun Qin
  2020-12-18 18:50 ` [PATCH v1 15/15] UefiCpuPkg: SmmCpuExceptionHandlerLib: Added StandaloneMm module support Kun Qin
  14 siblings, 1 reply; 44+ messages in thread
From: Kun Qin @ 2020-12-18 18:50 UTC (permalink / raw)
  To: devel; +Cc: Eric Dong, Ray Ni, Laszlo Ersek, Rahul Kumar

This change added support of CpuIo driver under StandaloneMm. The core
services switched to gMmst based instead of gMmst. It also abstracts
standalone and traditional MM driver entrypoints into separate files to
allow maximal common implementations.

Cc: Eric Dong <eric.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>

Signed-off-by: Kun Qin <kun.q@outlook.com>
---
 UefiCpuPkg/CpuIo2Smm/{CpuIo2Smm.c => CpuIo2Common.c}           |  14 +-
 UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c                               | 384 +-------------------
 UefiCpuPkg/CpuIo2Smm/CpuIo2StandaloneMm.c                      |  31 ++
 UefiCpuPkg/CpuIo2Smm/{CpuIo2Smm.h => CpuIo2Common.h}           |  18 +-
 UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf                             |   7 +-
 UefiCpuPkg/CpuIo2Smm/{CpuIo2Smm.inf => CpuIo2StandaloneMm.inf} |  23 +-
 UefiCpuPkg/UefiCpuPkg.dsc                                      |   6 +
 7 files changed, 76 insertions(+), 407 deletions(-)

diff --git a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c b/UefiCpuPkg/CpuIo2Smm/CpuIo2Common.c
similarity index 94%
copy from UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c
copy to UefiCpuPkg/CpuIo2Smm/CpuIo2Common.c
index b840d3e10cae..13e04e0d236d 100644
--- a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c
+++ b/UefiCpuPkg/CpuIo2Smm/CpuIo2Common.c
@@ -6,7 +6,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
 
-#include "CpuIo2Smm.h"
+#include "CpuIo2Common.h"
 
 //
 // Handle for the SMM CPU I/O Protocol
@@ -371,18 +371,14 @@ CpuIoServiceWrite (
 /**
   The module Entry Point SmmCpuIoProtocol driver
 
-  @param[in] ImageHandle  The firmware allocated handle for the EFI image.
-  @param[in] SystemTable  A pointer to the EFI System Table.
-
   @retval EFI_SUCCESS  The entry point is executed successfully.
   @retval Other        Some error occurs when executing this entry point.
 
 **/
 EFI_STATUS
 EFIAPI
-SmmCpuIo2Initialize (
-  IN EFI_HANDLE        ImageHandle,
-  IN EFI_SYSTEM_TABLE  *SystemTable
+CommonCpuIo2Initialize (
+  VOID
   )
 {
   EFI_STATUS  Status;
@@ -390,12 +386,12 @@ SmmCpuIo2Initialize (
   //
   // Copy the SMM CPU I/O Protocol instance into the System Management System Table
   //
-  CopyMem (&gSmst->SmmIo, &mSmmCpuIo2, sizeof (mSmmCpuIo2));
+  CopyMem (&gMmst->MmIo, &mSmmCpuIo2, sizeof (mSmmCpuIo2));
 
   //
   // Install the SMM CPU I/O Protocol into the SMM protocol database
   //
-  Status = gSmst->SmmInstallProtocolInterface (
+  Status = gMmst->MmInstallProtocolInterface (
                     &mHandle,
                     &gEfiSmmCpuIo2ProtocolGuid,
                     EFI_NATIVE_INTERFACE,
diff --git a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c
index b840d3e10cae..062d1a47a09f 100644
--- a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c
+++ b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c
@@ -6,367 +6,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
 
-#include "CpuIo2Smm.h"
+#include <PiSmm.h>
 
-//
-// Handle for the SMM CPU I/O Protocol
-//
-EFI_HANDLE  mHandle = NULL;
-
-//
-// SMM CPU I/O Protocol instance
-//
-EFI_SMM_CPU_IO2_PROTOCOL mSmmCpuIo2 = {
-  {
-    CpuMemoryServiceRead,
-    CpuMemoryServiceWrite
-  },
-  {
-    CpuIoServiceRead,
-    CpuIoServiceWrite
-  }
-};
-
-//
-// Lookup table for increment values based on transfer widths
-//
-UINT8 mStride[] = {
-  1, // SMM_IO_UINT8
-  2, // SMM_IO_UINT16
-  4, // SMM_IO_UINT32
-  8  // SMM_IO_UINT64
-};
-
-/**
-  Check parameters to a SMM CPU I/O Protocol service request.
-
-  @param[in]  MmioOperation  TRUE for an MMIO operation, FALSE for I/O Port operation.
-  @param[in]  Width          Signifies the width of the I/O operations.
-  @param[in]  Address        The base address of the I/O operations.  The caller is
-                             responsible for aligning the Address if required.
-  @param[in]  Count          The number of I/O operations to perform.
-  @param[in]  Buffer         For read operations, the destination buffer to store
-                             the results.  For write operations, the source buffer
-                             from which to write data.
-
-  @retval EFI_SUCCESS            The data was read from or written to the device.
-  @retval EFI_UNSUPPORTED        The Address is not valid for this system.
-  @retval EFI_INVALID_PARAMETER  Width or Count, or both, were invalid.
-
-**/
-EFI_STATUS
-CpuIoCheckParameter (
-  IN BOOLEAN           MmioOperation,
-  IN EFI_SMM_IO_WIDTH  Width,
-  IN UINT64            Address,
-  IN UINTN             Count,
-  IN VOID              *Buffer
-  )
-{
-  UINT64  MaxCount;
-  UINT64  Limit;
-
-  //
-  // Check to see if Buffer is NULL
-  //
-  if (Buffer == NULL) {
-    return EFI_INVALID_PARAMETER;
-  }
-
-  //
-  // Check to see if Width is in the valid range
-  //
-  if ((UINT32)Width > SMM_IO_UINT64) {
-    return EFI_INVALID_PARAMETER;
-  }
-
-  //
-  // Check to see if Width is in the valid range for I/O Port operations
-  //
-  if (!MmioOperation && (Width == SMM_IO_UINT64)) {
-    return EFI_INVALID_PARAMETER;
-  }
-
-  //
-  // Check to see if any address associated with this transfer exceeds the maximum
-  // allowed address.  The maximum address implied by the parameters passed in is
-  // Address + Size * Count.  If the following condition is met, then the transfer
-  // is not supported.
-  //
-  //    Address + Size * Count > (MmioOperation ? MAX_ADDRESS : MAX_IO_PORT_ADDRESS) + 1
-  //
-  // Since MAX_ADDRESS can be the maximum integer value supported by the CPU and Count
-  // can also be the maximum integer value supported by the CPU, this range
-  // check must be adjusted to avoid all overflow conditions.
-  //
-  // The following form of the range check is equivalent but assumes that
-  // MAX_ADDRESS and MAX_IO_PORT_ADDRESS are of the form (2^n - 1).
-  //
-  Limit = (MmioOperation ? MAX_ADDRESS : MAX_IO_PORT_ADDRESS);
-  if (Count == 0) {
-    if (Address > Limit) {
-      return EFI_UNSUPPORTED;
-    }
-  } else {
-    MaxCount = RShiftU64 (Limit, Width);
-    if (MaxCount < (Count - 1)) {
-      return EFI_UNSUPPORTED;
-    }
-    if (Address > LShiftU64 (MaxCount - Count + 1, Width)) {
-      return EFI_UNSUPPORTED;
-    }
-  }
-
-  //
-  // Check to see if Address is aligned
-  //
-  if ((Address & ((UINT64)mStride[Width] - 1)) != 0) {
-    return EFI_UNSUPPORTED;
-  }
-
-  return EFI_SUCCESS;
-}
-
-/**
-  Reads memory-mapped registers.
-
-  The I/O operations are carried out exactly as requested.  The caller is
-  responsible for any alignment and I/O width issues that the bus, device,
-  platform, or type of I/O might require.
-
-  @param[in]  This     The EFI_SMM_CPU_IO2_PROTOCOL instance.
-  @param[in]  Width    Signifies the width of the I/O operations.
-  @param[in]  Address  The base address of the I/O operations.  The caller is
-                       responsible for aligning the Address if required.
-  @param[in]  Count    The number of I/O operations to perform.
-  @param[out] Buffer   For read operations, the destination buffer to store
-                       the results.  For write operations, the source buffer
-                       from which to write data.
-
-  @retval EFI_SUCCESS            The data was read from or written to the device.
-  @retval EFI_UNSUPPORTED        The Address is not valid for this system.
-  @retval EFI_INVALID_PARAMETER  Width or Count, or both, were invalid.
-  @retval EFI_OUT_OF_RESOURCES   The request could not be completed due to a
-                                 lack of resources
-
-**/
-EFI_STATUS
-EFIAPI
-CpuMemoryServiceRead (
-  IN  CONST EFI_SMM_CPU_IO2_PROTOCOL  *This,
-  IN  EFI_SMM_IO_WIDTH                Width,
-  IN  UINT64                          Address,
-  IN  UINTN                           Count,
-  OUT VOID                            *Buffer
-  )
-{
-  EFI_STATUS  Status;
-  UINT8       Stride;
-  UINT8       *Uint8Buffer;
-
-  Status = CpuIoCheckParameter (TRUE, Width, Address, Count, Buffer);
-  if (EFI_ERROR (Status)) {
-    return Status;
-  }
-
-  //
-  // Select loop based on the width of the transfer
-  //
-  Stride = mStride[Width];
-  for (Uint8Buffer = Buffer; Count > 0; Address += Stride, Uint8Buffer += Stride, Count--) {
-    if (Width == SMM_IO_UINT8) {
-      *Uint8Buffer = MmioRead8 ((UINTN)Address);
-    } else if (Width == SMM_IO_UINT16) {
-      *((UINT16 *)Uint8Buffer) = MmioRead16 ((UINTN)Address);
-    } else if (Width == SMM_IO_UINT32) {
-      *((UINT32 *)Uint8Buffer) = MmioRead32 ((UINTN)Address);
-    } else if (Width == SMM_IO_UINT64) {
-      *((UINT64 *)Uint8Buffer) = MmioRead64 ((UINTN)Address);
-    }
-  }
-  return EFI_SUCCESS;
-}
-
-/**
-  Writes memory-mapped registers.
-
-  The I/O operations are carried out exactly as requested.  The caller is
-  responsible for any alignment and I/O width issues that the bus, device,
-  platform, or type of I/O might require.
-
-  @param[in]  This     The EFI_SMM_CPU_IO2_PROTOCOL instance.
-  @param[in]  Width    Signifies the width of the I/O operations.
-  @param[in]  Address  The base address of the I/O operations.  The caller is
-                       responsible for aligning the Address if required.
-  @param[in]  Count    The number of I/O operations to perform.
-  @param[in]  Buffer   For read operations, the destination buffer to store
-                       the results.  For write operations, the source buffer
-                       from which to write data.
-
-  @retval EFI_SUCCESS            The data was read from or written to the device.
-  @retval EFI_UNSUPPORTED        The Address is not valid for this system.
-  @retval EFI_INVALID_PARAMETER  Width or Count, or both, were invalid.
-  @retval EFI_OUT_OF_RESOURCES   The request could not be completed due to a
-                                 lack of resources
-
-**/
-EFI_STATUS
-EFIAPI
-CpuMemoryServiceWrite (
-  IN CONST EFI_SMM_CPU_IO2_PROTOCOL  *This,
-  IN EFI_SMM_IO_WIDTH                Width,
-  IN UINT64                          Address,
-  IN UINTN                           Count,
-  IN VOID                            *Buffer
-  )
-{
-  EFI_STATUS  Status;
-  UINT8       Stride;
-  UINT8       *Uint8Buffer;
-
-  Status = CpuIoCheckParameter (TRUE, Width, Address, Count, Buffer);
-  if (EFI_ERROR (Status)) {
-    return Status;
-  }
-
-  //
-  // Select loop based on the width of the transfer
-  //
-  Stride = mStride[Width];
-  for (Uint8Buffer = Buffer; Count > 0; Address += Stride, Uint8Buffer += Stride, Count--) {
-    if (Width == SMM_IO_UINT8) {
-      MmioWrite8 ((UINTN)Address, *Uint8Buffer);
-    } else if (Width == SMM_IO_UINT16) {
-      MmioWrite16 ((UINTN)Address, *((UINT16 *)Uint8Buffer));
-    } else if (Width == SMM_IO_UINT32) {
-      MmioWrite32 ((UINTN)Address, *((UINT32 *)Uint8Buffer));
-    } else if (Width == SMM_IO_UINT64) {
-      MmioWrite64 ((UINTN)Address, *((UINT64 *)Uint8Buffer));
-    }
-  }
-  return EFI_SUCCESS;
-}
-
-/**
-  Reads I/O registers.
-
-  The I/O operations are carried out exactly as requested.  The caller is
-  responsible for any alignment and I/O width issues that the bus, device,
-  platform, or type of I/O might require.
-
-  @param[in]  This     The EFI_SMM_CPU_IO2_PROTOCOL instance.
-  @param[in]  Width    Signifies the width of the I/O operations.
-  @param[in]  Address  The base address of the I/O operations.  The caller is
-                       responsible for aligning the Address if required.
-  @param[in]  Count    The number of I/O operations to perform.
-  @param[out] Buffer   For read operations, the destination buffer to store
-                       the results.  For write operations, the source buffer
-                       from which to write data.
-
-  @retval EFI_SUCCESS            The data was read from or written to the device.
-  @retval EFI_UNSUPPORTED        The Address is not valid for this system.
-  @retval EFI_INVALID_PARAMETER  Width or Count, or both, were invalid.
-  @retval EFI_OUT_OF_RESOURCES   The request could not be completed due to a
-                                 lack of resources
-
-**/
-EFI_STATUS
-EFIAPI
-CpuIoServiceRead (
-  IN  CONST EFI_SMM_CPU_IO2_PROTOCOL  *This,
-  IN  EFI_SMM_IO_WIDTH                Width,
-  IN  UINT64                          Address,
-  IN  UINTN                           Count,
-  OUT VOID                            *Buffer
-  )
-{
-  EFI_STATUS  Status;
-  UINT8       Stride;
-  UINT8       *Uint8Buffer;
-
-  Status = CpuIoCheckParameter (FALSE, Width, Address, Count, Buffer);
-  if (EFI_ERROR (Status)) {
-    return Status;
-  }
-
-  //
-  // Select loop based on the width of the transfer
-  //
-  Stride = mStride[Width];
-  for (Uint8Buffer = Buffer; Count > 0; Address += Stride, Uint8Buffer += Stride, Count--) {
-    if (Width == SMM_IO_UINT8) {
-      *Uint8Buffer = IoRead8 ((UINTN)Address);
-    } else if (Width == SMM_IO_UINT16) {
-      *((UINT16 *)Uint8Buffer) = IoRead16 ((UINTN)Address);
-    } else if (Width == SMM_IO_UINT32) {
-      *((UINT32 *)Uint8Buffer) = IoRead32 ((UINTN)Address);
-    }
-  }
-
-  return EFI_SUCCESS;
-}
-
-/**
-  Write I/O registers.
-
-  The I/O operations are carried out exactly as requested.  The caller is
-  responsible for any alignment and I/O width issues that the bus, device,
-  platform, or type of I/O might require.
-
-  @param[in]  This     The EFI_SMM_CPU_IO2_PROTOCOL instance.
-  @param[in]  Width    Signifies the width of the I/O operations.
-  @param[in]  Address  The base address of the I/O operations.  The caller is
-                       responsible for aligning the Address if required.
-  @param[in]  Count    The number of I/O operations to perform.
-  @param[in]  Buffer   For read operations, the destination buffer to store
-                       the results.  For write operations, the source buffer
-                       from which to write data.
-
-  @retval EFI_SUCCESS            The data was read from or written to the device.
-  @retval EFI_UNSUPPORTED        The Address is not valid for this system.
-  @retval EFI_INVALID_PARAMETER  Width or Count, or both, were invalid.
-  @retval EFI_OUT_OF_RESOURCES   The request could not be completed due to a
-                                 lack of resources
-
-**/
-EFI_STATUS
-EFIAPI
-CpuIoServiceWrite (
-  IN CONST EFI_SMM_CPU_IO2_PROTOCOL  *This,
-  IN EFI_SMM_IO_WIDTH                Width,
-  IN UINT64                          Address,
-  IN UINTN                           Count,
-  IN VOID                            *Buffer
-  )
-{
-  EFI_STATUS  Status;
-  UINT8       Stride;
-  UINT8       *Uint8Buffer;
-
-  //
-  // Make sure the parameters are valid
-  //
-  Status = CpuIoCheckParameter (FALSE, Width, Address, Count, Buffer);
-  if (EFI_ERROR (Status)) {
-    return Status;
-  }
-
-  //
-  // Select loop based on the width of the transfer
-  //
-  Stride = mStride[Width];
-  for (Uint8Buffer = (UINT8 *)Buffer; Count > 0; Address += Stride, Uint8Buffer += Stride, Count--) {
-    if (Width == SMM_IO_UINT8) {
-      IoWrite8 ((UINTN)Address, *Uint8Buffer);
-    } else if (Width == SMM_IO_UINT16) {
-      IoWrite16 ((UINTN)Address, *((UINT16 *)Uint8Buffer));
-    } else if (Width == SMM_IO_UINT32) {
-      IoWrite32 ((UINTN)Address, *((UINT32 *)Uint8Buffer));
-    }
-  }
-
-  return EFI_SUCCESS;
-}
+#include "CpuIo2Common.h"
 
 /**
   The module Entry Point SmmCpuIoProtocol driver
@@ -380,28 +22,10 @@ CpuIoServiceWrite (
 **/
 EFI_STATUS
 EFIAPI
-SmmCpuIo2Initialize (
+TraditionalMmCpuIo2Initialize (
   IN EFI_HANDLE        ImageHandle,
   IN EFI_SYSTEM_TABLE  *SystemTable
   )
 {
-  EFI_STATUS  Status;
-
-  //
-  // Copy the SMM CPU I/O Protocol instance into the System Management System Table
-  //
-  CopyMem (&gSmst->SmmIo, &mSmmCpuIo2, sizeof (mSmmCpuIo2));
-
-  //
-  // Install the SMM CPU I/O Protocol into the SMM protocol database
-  //
-  Status = gSmst->SmmInstallProtocolInterface (
-                    &mHandle,
-                    &gEfiSmmCpuIo2ProtocolGuid,
-                    EFI_NATIVE_INTERFACE,
-                    &mSmmCpuIo2
-                    );
-  ASSERT_EFI_ERROR (Status);
-
-  return Status;
+  return CommonCpuIo2Initialize ();
 }
diff --git a/UefiCpuPkg/CpuIo2Smm/CpuIo2StandaloneMm.c b/UefiCpuPkg/CpuIo2Smm/CpuIo2StandaloneMm.c
new file mode 100644
index 000000000000..2978f82eb815
--- /dev/null
+++ b/UefiCpuPkg/CpuIo2Smm/CpuIo2StandaloneMm.c
@@ -0,0 +1,31 @@
+/** @file
+  Produces the SMM CPU I/O Protocol.
+
+Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <PiMm.h>
+
+#include "CpuIo2Common.h"
+
+/**
+  The module Entry Point SmmCpuIoProtocol driver
+
+  @param[in] ImageHandle  The firmware allocated handle for the EFI image.
+  @param[in] SystemTable  A pointer to the EFI System Table.
+
+  @retval EFI_SUCCESS  The entry point is executed successfully.
+  @retval Other        Some error occurs when executing this entry point.
+
+**/
+EFI_STATUS
+EFIAPI
+StandaloneMmCpuIo2Initialize (
+  IN EFI_HANDLE           ImageHandle,
+  IN EFI_MM_SYSTEM_TABLE  *SystemTable
+  )
+{
+  return CommonCpuIo2Initialize ();
+}
diff --git a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.h b/UefiCpuPkg/CpuIo2Smm/CpuIo2Common.h
similarity index 92%
rename from UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.h
rename to UefiCpuPkg/CpuIo2Smm/CpuIo2Common.h
index 4c133b58c9f4..b34c54fa4290 100644
--- a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.h
+++ b/UefiCpuPkg/CpuIo2Smm/CpuIo2Common.h
@@ -9,14 +9,14 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 #ifndef _CPU_IO2_SMM_H_
 #define _CPU_IO2_SMM_H_
 
-#include <PiSmm.h>
+#include <PiMm.h>
 
 #include <Protocol/SmmCpuIo2.h>
 
 #include <Library/BaseLib.h>
 #include <Library/DebugLib.h>
 #include <Library/IoLib.h>
-#include <Library/SmmServicesTableLib.h>
+#include <Library/MmServicesTableLib.h>
 #include <Library/BaseMemoryLib.h>
 
 #define MAX_IO_PORT_ADDRESS   0xFFFF
@@ -153,4 +153,18 @@ CpuIoServiceWrite (
   IN VOID                            *Buffer
   );
 
+
+/**
+  The module Entry Point SmmCpuIoProtocol driver
+
+  @retval EFI_SUCCESS  The entry point is executed successfully.
+  @retval Other        Some error occurs when executing this entry point.
+
+**/
+EFI_STATUS
+EFIAPI
+CommonCpuIo2Initialize (
+  VOID
+  );
+
 #endif
diff --git a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf
index bc78fa4e42d2..031db1d100b9 100644
--- a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf
+++ b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf
@@ -14,7 +14,7 @@ [Defines]
   MODULE_TYPE                    = DXE_SMM_DRIVER
   VERSION_STRING                 = 1.0
   PI_SPECIFICATION_VERSION       = 0x0001000A
-  ENTRY_POINT                    = SmmCpuIo2Initialize
+  ENTRY_POINT                    = TraditionalMmCpuIo2Initialize
 
 #
 # The following information is for reference only and not required by the build tools.
@@ -24,7 +24,8 @@ [Defines]
 
 [Sources]
   CpuIo2Smm.c
-  CpuIo2Smm.h
+  CpuIo2Common.c
+  CpuIo2Common.h
 
 [Packages]
   MdePkg/MdePkg.dec
@@ -34,7 +35,7 @@ [LibraryClasses]
   BaseLib
   DebugLib
   IoLib
-  SmmServicesTableLib
+  MmServicesTableLib
   BaseMemoryLib
 
 [Protocols]
diff --git a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf b/UefiCpuPkg/CpuIo2Smm/CpuIo2StandaloneMm.inf
similarity index 56%
copy from UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf
copy to UefiCpuPkg/CpuIo2Smm/CpuIo2StandaloneMm.inf
index bc78fa4e42d2..cce7742bee7a 100644
--- a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf
+++ b/UefiCpuPkg/CpuIo2Smm/CpuIo2StandaloneMm.inf
@@ -8,13 +8,12 @@
 
 [Defines]
   INF_VERSION                    = 0x00010005
-  BASE_NAME                      = CpuIo2Smm
-  MODULE_UNI_FILE                = CpuIo2Smm.uni
-  FILE_GUID                      = A47EE2D8-F60E-42fd-8E58-7BD65EE4C29B
-  MODULE_TYPE                    = DXE_SMM_DRIVER
+  BASE_NAME                      = CpuIo2StandaloneMm
+  FILE_GUID                      = E3121A26-BB1C-4A18-8E23-2EA3F0412248
+  MODULE_TYPE                    = MM_STANDALONE
   VERSION_STRING                 = 1.0
-  PI_SPECIFICATION_VERSION       = 0x0001000A
-  ENTRY_POINT                    = SmmCpuIo2Initialize
+  PI_SPECIFICATION_VERSION       = 0x00010032
+  ENTRY_POINT                    = StandaloneMmCpuIo2Initialize
 
 #
 # The following information is for reference only and not required by the build tools.
@@ -23,18 +22,19 @@ [Defines]
 #
 
 [Sources]
-  CpuIo2Smm.c
-  CpuIo2Smm.h
+  CpuIo2StandaloneMm.c
+  CpuIo2Common.c
+  CpuIo2Common.h
 
 [Packages]
   MdePkg/MdePkg.dec
 
 [LibraryClasses]
-  UefiDriverEntryPoint
+  StandaloneMmDriverEntryPoint
   BaseLib
   DebugLib
   IoLib
-  SmmServicesTableLib
+  MmServicesTableLib
   BaseMemoryLib
 
 [Protocols]
@@ -42,6 +42,3 @@ [Protocols]
 
 [Depex]
   TRUE
-
-[UserExtensions.TianoCore."ExtraFiles"]
-  CpuIo2SmmExtra.uni
diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc
index b2b6d78a71b0..4e46c600788f 100644
--- a/UefiCpuPkg/UefiCpuPkg.dsc
+++ b/UefiCpuPkg/UefiCpuPkg.dsc
@@ -38,6 +38,7 @@ [LibraryClasses]
   UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf
   UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf
   UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf
+  StandaloneMmDriverEntryPoint|MdePkg/Library/StandaloneMmDriverEntryPoint/StandaloneMmDriverEntryPoint.inf
   DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf
   PeimEntryPoint|MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf
   PeiServicesLib|MdePkg/Library/PeiServicesLib/PeiServicesLib.inf
@@ -89,10 +90,14 @@ [LibraryClasses.common.DXE_DRIVER]
 
 [LibraryClasses.common.DXE_SMM_DRIVER]
   SmmServicesTableLib|MdePkg/Library/SmmServicesTableLib/SmmServicesTableLib.inf
+  MmServicesTableLib|MdePkg/Library/MmServicesTableLib/MmServicesTableLib.inf
   MemoryAllocationLib|MdePkg/Library/SmmMemoryAllocationLib/SmmMemoryAllocationLib.inf
   HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
   CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf
 
+[LibraryClasses.common.MM_STANDALONE]
+  MmServicesTableLib|MdePkg/Library/StandaloneMmServicesTableLib/StandaloneMmServicesTableLib.inf
+
 [LibraryClasses.common.UEFI_APPLICATION]
   UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf
   MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
@@ -121,6 +126,7 @@ [Components.IA32, Components.X64]
       NULL|UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.inf
   }
   UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf
+  UefiCpuPkg/CpuIo2Smm/CpuIo2StandaloneMm.inf
   UefiCpuPkg/CpuMpPei/CpuMpPei.inf
   UefiCpuPkg/CpuS3DataDxe/CpuS3DataDxe.inf
   UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.inf
-- 
2.28.0.windows.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* [PATCH v1 15/15] UefiCpuPkg: SmmCpuExceptionHandlerLib: Added StandaloneMm module support
       [not found] <20201218185011.1366-1-kun.q@outlook.com>
                   ` (13 preceding siblings ...)
  2020-12-18 18:50 ` [PATCH v1 14/15] UefiCpuPkg: CpuIo2Smm: Support of CpuIo driver under StandaloneMm Kun Qin
@ 2020-12-18 18:50 ` Kun Qin
  2021-01-04 18:30   ` [edk2-devel] " Kun Qin
  14 siblings, 1 reply; 44+ messages in thread
From: Kun Qin @ 2020-12-18 18:50 UTC (permalink / raw)
  To: devel; +Cc: Eric Dong, Ray Ni, Laszlo Ersek, Rahul Kumar

This change of SmmCpuExceptionHandlerLib adds support for StandaloneMm
components to allow x64 StandaloneMm environment setting up exception
handlers.

Cc: Eric Dong <eric.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>

Signed-off-by: Kun Qin <kun.q@outlook.com>
---
 UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf
index 4cdb11c04ea0..ea5b10b5c8e4 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf
@@ -13,7 +13,7 @@ [Defines]
   FILE_GUID                      = 8D2C439B-3981-42ff-9CE5-1B50ECA502D6
   MODULE_TYPE                    = DXE_SMM_DRIVER
   VERSION_STRING                 = 1.1
-  LIBRARY_CLASS                  = CpuExceptionHandlerLib|DXE_SMM_DRIVER
+  LIBRARY_CLASS                  = CpuExceptionHandlerLib|DXE_SMM_DRIVER MM_STANDALONE MM_CORE_STANDALONE
 
 #
 # The following information is for reference only and not required by the build tools.
-- 
2.28.0.windows.1


^ permalink raw reply related	[flat|nested] 44+ messages in thread

* Re: [edk2-devel] [PATCH v1 05/15] MdeModulePkg: SmmLockBoxSmmLib: Support StandaloneMm for SmmLockBoxLib
  2020-12-18 18:50 ` [PATCH v1 05/15] MdeModulePkg: SmmLockBoxSmmLib: Support StandaloneMm for SmmLockBoxLib Kun Qin
@ 2020-12-22  8:35   ` Wu, Hao A
  0 siblings, 0 replies; 44+ messages in thread
From: Wu, Hao A @ 2020-12-22  8:35 UTC (permalink / raw)
  To: devel@edk2.groups.io, kun.q@outlook.com
  Cc: Wang, Jian J, Dong, Eric, Yao, Jiewen

A couple of minor inline comments below.

With them handled:
Reviewed-by: Hao A Wu <hao.a.wu@intel.com>


> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Kun Qin
> Sent: Saturday, December 19, 2020 2:50 AM
> To: devel@edk2.groups.io
> Cc: Wang, Jian J <jian.j.wang@intel.com>; Wu, Hao A <hao.a.wu@intel.com>;
> Dong, Eric <eric.dong@intel.com>
> Subject: [edk2-devel] [PATCH v1 05/15] MdeModulePkg:
> SmmLockBoxSmmLib: Support StandaloneMm for SmmLockBoxLib
> 
> This change added support of StandaloneMm for SmmLockBoxLib. It replaces
> gSmst with gMmst to support both traditional MM and standalone MM. The
> contructor and desctructor functions are abstracted to support different
> function prototype definitions.
> 
> Cc: Jian J Wang <jian.j.wang@intel.com>
> Cc: Hao A Wu <hao.a.wu@intel.com>
> Cc: Eric Dong <eric.dong@intel.com>
> 
> Signed-off-by: Kun Qin <kun.q@outlook.com>
> ---
>  MdeModulePkg/Library/SmmLockBoxLib/{SmmLockBoxSmmLib.c =>
> SmmLockBoxMmLib.c}               | 77 +++++++++-----------
>  MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxStandaloneMmLib.c
> | 53 ++++++++++++++
>  MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxTraditionalMmLib.c
> | 53 ++++++++++++++
>  MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxLibPrivate.h
> | 27 +++++++
>  MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.inf
> | 15 ++--
>  MdeModulePkg/Library/SmmLockBoxLib/{SmmLockBoxSmmLib.inf =>
> SmmLockBoxStandaloneMmLib.inf} | 26 ++++---
>  MdeModulePkg/MdeModulePkg.dsc                                                              |  2 +
>  7 files changed, 193 insertions(+), 60 deletions(-)
> 
> diff --git a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.c
> b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxMmLib.c
> similarity index 89%
> rename from
> MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.c
> rename to MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxMmLib.c
> index 4cc0e8b78e5b..68fcf2a78ed6 100644
> --- a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.c
> +++ b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxMmLib.c
> @@ -6,16 +6,16 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
> 
>  **/
> 
> -#include <PiSmm.h>
> -#include <Library/SmmServicesTableLib.h>
> +#include <PiMm.h>
> +#include <Library/MmServicesTableLib.h>
>  #include <Library/BaseLib.h>
>  #include <Library/BaseMemoryLib.h>
>  #include <Library/LockBoxLib.h>
>  #include <Library/DebugLib.h>
>  #include <Guid/SmmLockBox.h>
>  #include <Guid/EndOfS3Resume.h>
> -#include <Protocol/SmmReadyToLock.h>
> -#include <Protocol/SmmEndOfDxe.h>
> +#include <Protocol/MmReadyToLock.h>
> +#include <Protocol/MmEndOfDxe.h>
>  #include <Protocol/SmmSxDispatch2.h>
> 
>  #include "SmmLockBoxLibPrivate.h"
> @@ -49,13 +49,13 @@ InternalGetSmmLockBoxContext (
>    //
>    // Check if gEfiSmmLockBoxCommunicationGuid is installed by someone
>    //
> -  for (Index = 0; Index < gSmst->NumberOfTableEntries; Index++) {
> -    if (CompareGuid (&gSmst->SmmConfigurationTable[Index].VendorGuid,
> &gEfiSmmLockBoxCommunicationGuid)) {
> +  for (Index = 0; Index < gMmst->NumberOfTableEntries; Index++) {
> +    if (CompareGuid (&gMmst->MmConfigurationTable[Index].VendorGuid,
> + &gEfiSmmLockBoxCommunicationGuid)) {
>        //
>        // Found. That means some other library instance is already run.
>        // No need to install again, just return.
>        //
> -      return (SMM_LOCK_BOX_CONTEXT *)gSmst-
> >SmmConfigurationTable[Index].VendorTable;
> +      return (SMM_LOCK_BOX_CONTEXT
> + *)gMmst->MmConfigurationTable[Index].VendorTable;
>      }
>    }
> 
> @@ -142,8 +142,8 @@ SmmLockBoxSmmEndOfDxeNotify (
>    //
>    // Locate SmmSxDispatch2 protocol.
>    //
> -  Status = gSmst->SmmLocateProtocol (
> -                    &gEfiSmmSxDispatch2ProtocolGuid,
> +  Status = gMmst->MmLocateProtocol (
> +                    &gEfiMmSxDispatchProtocolGuid,
>                      NULL,
>                      (VOID **)&SxDispatch
>                      );
> @@ -191,29 +191,25 @@ SmmLockBoxEndOfS3ResumeNotify (
>    Constructor for SmmLockBox library.
>    This is used to set SmmLockBox context, which will be used in PEI phase in
> S3 boot path later.
> 
> -  @param[in] ImageHandle  Image handle of this driver.
> -  @param[in] SystemTable  A Pointer to the EFI System Table.
> -
>    @retval EFI_SUCEESS
>    @return Others          Some error occurs.
>  **/
>  EFI_STATUS
>  EFIAPI
> -SmmLockBoxSmmConstructor (
> -  IN EFI_HANDLE        ImageHandle,
> -  IN EFI_SYSTEM_TABLE  *SystemTable
> +SmmLockBoxMmConstructor (
> +  VOID
>    )


Since function SmmLockBoxMmConstructor() now has become an library internal function.
Could you help to remove the 'EFIAPI' keyword for it?


>  {
>    EFI_STATUS           Status;
>    SMM_LOCK_BOX_CONTEXT *SmmLockBoxContext;
> 
> -  DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib
> SmmLockBoxSmmConstructor - Enter\n"));
> +  DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib
> SmmLockBoxMmConstructor -
> + Enter\n"));
> 
>    //
>    // Register SmmReadyToLock notification.
>    //
> -  Status = gSmst->SmmRegisterProtocolNotify (
> -                    &gEfiSmmReadyToLockProtocolGuid,
> +  Status = gMmst->MmRegisterProtocolNotify (
> +                    &gEfiMmReadyToLockProtocolGuid,
>                      SmmLockBoxSmmReadyToLockNotify,
>                      &mSmmLockBoxRegistrationSmmReadyToLock
>                      );
> @@ -222,8 +218,8 @@ SmmLockBoxSmmConstructor (
>    //
>    // Register SmmEndOfDxe notification.
>    //
> -  Status = gSmst->SmmRegisterProtocolNotify (
> -                    &gEfiSmmEndOfDxeProtocolGuid,
> +  Status = gMmst->MmRegisterProtocolNotify (
> +                    &gEfiMmEndOfDxeProtocolGuid,
>                      SmmLockBoxSmmEndOfDxeNotify,
>                      &mSmmLockBoxRegistrationSmmEndOfDxe
>                      );
> @@ -232,7 +228,7 @@ SmmLockBoxSmmConstructor (
>    //
>    // Register EndOfS3Resume notification.
>    //
> -  Status = gSmst->SmmRegisterProtocolNotify (
> +  Status = gMmst->MmRegisterProtocolNotify (
>                      &gEdkiiEndOfS3ResumeGuid,
>                      SmmLockBoxEndOfS3ResumeNotify,
>                      &mSmmLockBoxRegistrationEndOfS3Resume
> @@ -249,7 +245,7 @@ SmmLockBoxSmmConstructor (
>      // No need to install again, just return.
>      //
>      DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib SmmLockBoxContext -
> already installed\n"));
> -    DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib
> SmmLockBoxSmmConstructor - Exit\n"));
> +    DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib
> SmmLockBoxMmConstructor -
> + Exit\n"));
>      return EFI_SUCCESS;
>    }
> 
> @@ -263,8 +259,8 @@ SmmLockBoxSmmConstructor (
>    }
>    mSmmLockBoxContext.LockBoxDataAddress =
> (EFI_PHYSICAL_ADDRESS)(UINTN)&mLockBoxQueue;
> 
> -  Status = gSmst->SmmInstallConfigurationTable (
> -                    gSmst,
> +  Status = gMmst->MmInstallConfigurationTable (
> +                    gMmst,
>                      &gEfiSmmLockBoxCommunicationGuid,
>                      &mSmmLockBoxContext,
>                      sizeof(mSmmLockBoxContext) @@ -274,7 +270,7 @@
> SmmLockBoxSmmConstructor (
> 
>    DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib SmmLockBoxContext -
>  %x\n", (UINTN)&mSmmLockBoxContext));
>    DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib LockBoxDataAddress -
>  %x\n", (UINTN)&mLockBoxQueue));
> -  DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib
> SmmLockBoxSmmConstructor - Exit\n"));
> +  DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib
> SmmLockBoxMmConstructor -
> + Exit\n"));
> 
>    return Status;
>  }
> @@ -292,18 +288,17 @@ SmmLockBoxSmmConstructor (  **/  EFI_STATUS
> EFIAPI -SmmLockBoxSmmDestructor (
> -  IN EFI_HANDLE         ImageHandle,
> -  IN EFI_SYSTEM_TABLE   *SystemTable
> +SmmLockBoxMmDestructor (
> +  VOID
>    )


Since function SmmLockBoxMmDestructor() now has become an library internal function.
Could you help to remove the 'EFIAPI' keyword for it?

Best Regards,
Hao Wu


>  {
>    EFI_STATUS            Status;
> 
> -  DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib
> SmmLockBoxSmmDestructor in %a module\n", gEfiCallerBaseName));
> +  DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib SmmLockBoxMmDestructor
> in %a
> + module\n", gEfiCallerBaseName));
> 
>    if (mSmmConfigurationTableInstalled) {
> -    Status = gSmst->SmmInstallConfigurationTable (
> -                      gSmst,
> +    Status = gMmst->MmInstallConfigurationTable (
> +                      gMmst,
>                        &gEfiSmmLockBoxCommunicationGuid,
>                        NULL,
>                        0
> @@ -316,8 +311,8 @@ SmmLockBoxSmmDestructor (
>      //
>      // Unregister SmmReadyToLock notification.
>      //
> -    Status = gSmst->SmmRegisterProtocolNotify (
> -                      &gEfiSmmReadyToLockProtocolGuid,
> +    Status = gMmst->MmRegisterProtocolNotify (
> +                      &gEfiMmReadyToLockProtocolGuid,
>                        NULL,
>                        &mSmmLockBoxRegistrationSmmReadyToLock
>                        );
> @@ -327,8 +322,8 @@ SmmLockBoxSmmDestructor (
>      //
>      // Unregister SmmEndOfDxe notification.
>      //
> -    Status = gSmst->SmmRegisterProtocolNotify (
> -                      &gEfiSmmEndOfDxeProtocolGuid,
> +    Status = gMmst->MmRegisterProtocolNotify (
> +                      &gEfiMmEndOfDxeProtocolGuid,
>                        NULL,
>                        &mSmmLockBoxRegistrationSmmEndOfDxe
>                        );
> @@ -338,7 +333,7 @@ SmmLockBoxSmmDestructor (
>      //
>      // Unregister EndOfS3Resume notification.
>      //
> -    Status = gSmst->SmmRegisterProtocolNotify (
> +    Status = gMmst->MmRegisterProtocolNotify (
>                        &gEdkiiEndOfS3ResumeGuid,
>                        NULL,
>                        &mSmmLockBoxRegistrationEndOfS3Resume
> @@ -453,7 +448,7 @@ SaveLockBox (
>    //
>    // Allocate SMRAM buffer
>    //
> -  Status = gSmst->SmmAllocatePages (
> +  Status = gMmst->MmAllocatePages (
>                      AllocateAnyPages,
>                      EfiRuntimeServicesData,
>                      EFI_SIZE_TO_PAGES (Length), @@ -468,14 +463,14 @@
> SaveLockBox (
>    //
>    // Allocate LockBox
>    //
> -  Status = gSmst->SmmAllocatePool (
> +  Status = gMmst->MmAllocatePool (
>                      EfiRuntimeServicesData,
>                      sizeof(*LockBox),
>                      (VOID **)&LockBox
>                      );
>    ASSERT_EFI_ERROR (Status);
>    if (EFI_ERROR (Status)) {
> -    gSmst->SmmFreePages (SmramBuffer, EFI_SIZE_TO_PAGES (Length));
> +    gMmst->MmFreePages (SmramBuffer, EFI_SIZE_TO_PAGES (Length));
>      DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib SaveLockBox - Exit (%r)\n",
> EFI_OUT_OF_RESOURCES));
>      return EFI_OUT_OF_RESOURCES;
>    }
> @@ -662,7 +657,7 @@ UpdateLockBox (
>            DEBUG_INFO,
>            "SmmLockBoxSmmLib UpdateLockBox - Allocate new buffer to
> enlarge.\n"
>            ));
> -        Status = gSmst->SmmAllocatePages (
> +        Status = gMmst->MmAllocatePages (
>                            AllocateAnyPages,
>                            EfiRuntimeServicesData,
>                            EFI_SIZE_TO_PAGES (Offset + Length), @@ -679,7 +674,7 @@
> UpdateLockBox (
>          //
>          CopyMem ((VOID *)(UINTN)SmramBuffer, (VOID *)(UINTN)LockBox-
> >SmramBuffer, (UINTN)LockBox->Length);
>          ZeroMem ((VOID *)(UINTN)LockBox->SmramBuffer, (UINTN)LockBox-
> >Length);
> -        gSmst->SmmFreePages (LockBox->SmramBuffer, EFI_SIZE_TO_PAGES
> ((UINTN)LockBox->Length));
> +        gMmst->MmFreePages (LockBox->SmramBuffer, EFI_SIZE_TO_PAGES
> + ((UINTN)LockBox->Length));
> 
>          LockBox->SmramBuffer = SmramBuffer;
>        }
> diff --git
> a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxStandaloneMmLib.
> c
> b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxStandaloneMmLib.
> c
> new file mode 100644
> index 000000000000..722121da430b
> --- /dev/null
> +++
> b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxStandaloneMmLib.
> c
> @@ -0,0 +1,53 @@
> +/** @file
> +
> +Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved.<BR>
> +Copyright (c) Microsoft Corporation.
> +
> +SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <PiMm.h>
> +
> +#include "SmmLockBoxLibPrivate.h"
> +
> +/**
> +  Constructor for SmmLockBox library.
> +  This is used to set SmmLockBox context, which will be used in PEI phase in
> S3 boot path later.
> +
> +  @param[in] ImageHandle  Image handle of this driver.
> +  @param[in] SystemTable  A Pointer to the EFI System Table.
> +
> +  @retval EFI_SUCEESS
> +  @return Others          Some error occurs.
> +**/
> +EFI_STATUS
> +EFIAPI
> +SmmLockBoxStandaloneMmConstructor (
> +  IN EFI_HANDLE           ImageHandle,
> +  IN EFI_MM_SYSTEM_TABLE  *SystemTable
> +  )
> +{
> +  return SmmLockBoxMmConstructor ();
> +}
> +
> +/**
> +  Destructor for SmmLockBox library.
> +  This is used to uninstall SmmLockBoxCommunication configuration table
> +  if it has been installed in Constructor.
> +
> +  @param[in] ImageHandle    Image handle of this driver.
> +  @param[in] SystemTable    A Pointer to the EFI System Table.
> +
> +  @retval EFI_SUCEESS       The destructor always returns EFI_SUCCESS.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +SmmLockBoxStandaloneMmDestructor (
> +  IN EFI_HANDLE             ImageHandle,
> +  IN EFI_MM_SYSTEM_TABLE    *SystemTable
> +  )
> +{
> +  return SmmLockBoxMmDestructor ();
> +}
> diff --git
> a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxTraditionalMmLib.c
> b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxTraditionalMmLib.c
> new file mode 100644
> index 000000000000..a748abb16c54
> --- /dev/null
> +++
> b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxTraditionalMmLib.c
> @@ -0,0 +1,53 @@
> +/** @file
> +
> +Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved.<BR>
> +Copyright (c) Microsoft Corporation.
> +
> +SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <PiSmm.h>
> +
> +#include "SmmLockBoxLibPrivate.h"
> +
> +/**
> +  Constructor for SmmLockBox library.
> +  This is used to set SmmLockBox context, which will be used in PEI phase in
> S3 boot path later.
> +
> +  @param[in] ImageHandle  Image handle of this driver.
> +  @param[in] SystemTable  A Pointer to the EFI System Table.
> +
> +  @retval EFI_SUCEESS
> +  @return Others          Some error occurs.
> +**/
> +EFI_STATUS
> +EFIAPI
> +SmmLockBoxTraditionalConstructor (
> +  IN EFI_HANDLE        ImageHandle,
> +  IN EFI_SYSTEM_TABLE  *SystemTable
> +  )
> +{
> +  return SmmLockBoxMmConstructor ();
> +}
> +
> +/**
> +  Destructor for SmmLockBox library.
> +  This is used to uninstall SmmLockBoxCommunication configuration table
> +  if it has been installed in Constructor.
> +
> +  @param[in] ImageHandle    Image handle of this driver.
> +  @param[in] SystemTable    A Pointer to the EFI System Table.
> +
> +  @retval EFI_SUCEESS       The destructor always returns EFI_SUCCESS.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +SmmLockBoxTraditionalDestructor (
> +  IN EFI_HANDLE          ImageHandle,
> +  IN EFI_SYSTEM_TABLE    *SystemTable
> +  )
> +{
> +  return SmmLockBoxMmDestructor ();
> +}
> diff --git
> a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxLibPrivate.h
> b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxLibPrivate.h
> index 35311cb85d69..f729c6cceeea 100644
> --- a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxLibPrivate.h
> +++ b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxLibPrivate.h
> @@ -43,5 +43,32 @@ typedef struct {
> 
>  #pragma pack()
> 
> +/**
> +  Constructor for SmmLockBox library.
> +  This is used to set SmmLockBox context, which will be used in PEI phase in
> S3 boot path later.
> +
> +  @retval EFI_SUCEESS
> +  @return Others          Some error occurs.
> +**/
> +EFI_STATUS
> +EFIAPI
> +SmmLockBoxMmConstructor (
> +  VOID
> +  );
> +
> +/**
> +  Destructor for SmmLockBox library.
> +  This is used to uninstall SmmLockBoxCommunication configuration table
> +  if it has been installed in Constructor.
> +
> +  @retval EFI_SUCEESS       The destructor always returns EFI_SUCCESS.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +SmmLockBoxMmDestructor (
> +  VOID
> +  );
> +
>  #endif
> 
> diff --git a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.inf
> b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.inf
> index 2b6cc983b988..44f7b63c5d20 100644
> --- a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.inf
> +++ b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.inf
> @@ -15,8 +15,8 @@ [Defines]
>    MODULE_TYPE                    = DXE_SMM_DRIVER
>    VERSION_STRING                 = 1.0
>    LIBRARY_CLASS                  = LockBoxLib|DXE_SMM_DRIVER
> -  CONSTRUCTOR                    = SmmLockBoxSmmConstructor
> -  DESTRUCTOR                     = SmmLockBoxSmmDestructor
> +  CONSTRUCTOR                    = SmmLockBoxTraditionalConstructor
> +  DESTRUCTOR                     = SmmLockBoxTraditionalDestructor
> 
>  #
>  # The following information is for reference only and not required by the
> build tools.
> @@ -25,7 +25,8 @@ [Defines]
>  #
> 
>  [Sources]
> -  SmmLockBoxSmmLib.c
> +  SmmLockBoxTraditionalMmLib.c
> +  SmmLockBoxMmLib.c
>    SmmLockBoxLibPrivate.h
> 
>  [Packages]
> @@ -33,14 +34,14 @@ [Packages]
>    MdeModulePkg/MdeModulePkg.dec
> 
>  [LibraryClasses]
> -  SmmServicesTableLib
> +  MmServicesTableLib
>    BaseLib
>    DebugLib
> 
>  [Protocols]
> -  gEfiSmmReadyToLockProtocolGuid    ## NOTIFY
> -  gEfiSmmEndOfDxeProtocolGuid       ## NOTIFY
> -  gEfiSmmSxDispatch2ProtocolGuid    ## NOTIFY
> +  gEfiMmReadyToLockProtocolGuid    ## NOTIFY
> +  gEfiMmEndOfDxeProtocolGuid       ## NOTIFY
> +  gEfiMmSxDispatchProtocolGuid     ## NOTIFY
> 
>  [Guids]
>    ## SOMETIMES_CONSUMES   ## UNDEFINED # SmmSystemTable
> diff --git a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.inf
> b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxStandaloneMmLib.i
> nf
> similarity index 52%
> copy from MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.inf
> copy to
> MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxStandaloneMmLib.inf
> index 2b6cc983b988..d46dfb3f9aa8 100644
> --- a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.inf
> +++
> b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxStandaloneMmLib.i
> nf
> @@ -2,6 +2,7 @@
>  #  SMM LockBox library instance.
>  #
>  #  Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
> +#  Copyright (c) Microsoft Corporation.
>  #
>  #  SPDX-License-Identifier: BSD-2-Clause-Patent  # @@ -9,14 +10,14 @@
> 
>  [Defines]
>    INF_VERSION                    = 0x00010005
> -  BASE_NAME                      = SmmLockBoxSmmLib
> -  MODULE_UNI_FILE                = SmmLockBoxSmmLib.uni
> -  FILE_GUID                      = E04894D6-290D-4171-A362-0ACFD939F3C8
> -  MODULE_TYPE                    = DXE_SMM_DRIVER
> +  BASE_NAME                      = SmmLockBoxStandaloneMmLib
> +  FILE_GUID                      = 3C05978B-30CA-4544-9C5A-AB99265EFC31
> +  MODULE_TYPE                    = MM_STANDALONE
>    VERSION_STRING                 = 1.0
> -  LIBRARY_CLASS                  = LockBoxLib|DXE_SMM_DRIVER
> -  CONSTRUCTOR                    = SmmLockBoxSmmConstructor
> -  DESTRUCTOR                     = SmmLockBoxSmmDestructor
> +  PI_SPECIFICATION_VERSION       = 0x00010032
> +  LIBRARY_CLASS                  = LockBoxLib|MM_STANDALONE
> +  CONSTRUCTOR                    = SmmLockBoxStandaloneMmConstructor
> +  DESTRUCTOR                     = SmmLockBoxStandaloneMmDestructor
> 
>  #
>  # The following information is for reference only and not required by the
> build tools.
> @@ -25,7 +26,8 @@ [Defines]
>  #
> 
>  [Sources]
> -  SmmLockBoxSmmLib.c
> +  SmmLockBoxStandaloneMmLib.c
> +  SmmLockBoxMmLib.c
>    SmmLockBoxLibPrivate.h
> 
>  [Packages]
> @@ -33,14 +35,14 @@ [Packages]
>    MdeModulePkg/MdeModulePkg.dec
> 
>  [LibraryClasses]
> -  SmmServicesTableLib
> +  MmServicesTableLib
>    BaseLib
>    DebugLib
> 
>  [Protocols]
> -  gEfiSmmReadyToLockProtocolGuid    ## NOTIFY
> -  gEfiSmmEndOfDxeProtocolGuid       ## NOTIFY
> -  gEfiSmmSxDispatch2ProtocolGuid    ## NOTIFY
> +  gEfiMmReadyToLockProtocolGuid    ## NOTIFY
> +  gEfiMmEndOfDxeProtocolGuid       ## NOTIFY
> +  gEfiMmSxDispatchProtocolGuid     ## NOTIFY
> 
>  [Guids]
>    ## SOMETIMES_CONSUMES   ## UNDEFINED # SmmSystemTable
> diff --git a/MdeModulePkg/MdeModulePkg.dsc
> b/MdeModulePkg/MdeModulePkg.dsc index 90165ca443bf..cd91a70b4fdd
> 100644
> --- a/MdeModulePkg/MdeModulePkg.dsc
> +++ b/MdeModulePkg/MdeModulePkg.dsc
> @@ -167,6 +167,7 @@ [LibraryClasses.common.MM_STANDALONE]
> 
> MemoryAllocationLib|MdeModulePkg/Library/BaseMemoryAllocationLibNul
> l/BaseMemoryAllocationLibNull.inf
> 
> StandaloneMmDriverEntryPoint|MdePkg/Library/StandaloneMmDriverEntry
> Point/StandaloneMmDriverEntryPoint.inf
> 
> MmServicesTableLib|MdePkg/Library/StandaloneMmServicesTableLib/Stan
> daloneMmServicesTableLib.inf
> +
> +
> LockBoxLib|MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxStandalo
> neMmLi
> + b.inf
> 
>  [LibraryClasses.ARM, LibraryClasses.AARCH64]
>    ArmLib|ArmPkg/Library/ArmLib/ArmBaseLib.inf
> @@ -483,6 +484,7 @@ [Components.IA32, Components.X64]
>    MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxPeiLib.inf
>    MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.inf
>    MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.inf
> +
> MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxStandaloneMmLib.inf
> 
> MdeModulePkg/Library/SmmCorePlatformHookLibNull/SmmCorePlatformH
> ookLibNull.inf
> 
> MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLi
> b.inf
> 
> MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaArchCustomDeco
> mpressLib.inf
> --
> 2.28.0.windows.1
> 
> 
> 
> 
> 


^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [edk2-devel] [PATCH v1 06/15] MdeModulePkg: SmmReportStatusCodeLib: ReportStatusCodeLib in StandaloneMm
  2020-12-18 18:50 ` [PATCH v1 06/15] MdeModulePkg: SmmReportStatusCodeLib: ReportStatusCodeLib in StandaloneMm Kun Qin
@ 2020-12-22  8:35   ` Wu, Hao A
  2020-12-22 19:15     ` Kun Qin
  0 siblings, 1 reply; 44+ messages in thread
From: Wu, Hao A @ 2020-12-22  8:35 UTC (permalink / raw)
  To: devel@edk2.groups.io, kun.q@outlook.com
  Cc: Wang, Jian J, Bi, Dandan, Liming Gao, Yao, Jiewen

> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Kun Qin
> Sent: Saturday, December 19, 2020 2:50 AM
> To: devel@edk2.groups.io
> Cc: Wang, Jian J <jian.j.wang@intel.com>; Wu, Hao A <hao.a.wu@intel.com>;
> Bi, Dandan <dandan.bi@intel.com>; Liming Gao <gaoliming@byosoft.com.cn>
> Subject: [edk2-devel] [PATCH v1 06/15] MdeModulePkg:
> SmmReportStatusCodeLib: ReportStatusCodeLib in StandaloneMm
> 
> This change added support of StandaloneMm for ReportStatusCodeLib. It
> adds a new instance of ReportStatusCodeLib for MM_STANDALONE type,
> and abstracts the references of gMmst and gSmst functionalities into
> separate files in order to link in proper Service Table for SMM core/drivers.


Sorry for a question.

Do you think it is feasible to use:
gMmst->MmLocateProtocol to locate gEfiMmStatusCodeProtocolGuid
and avoid introducing 2 separate implementations for internal function InternalLocateProtocol()?

Since I found that the definitions for gEfiMmStatusCodeProtocolGuid an gEfiSmmStatusCodeProtocolGuid are identical.

Best Regards,
Hao Wu


> 
> Cc: Jian J Wang <jian.j.wang@intel.com>
> Cc: Hao A Wu <hao.a.wu@intel.com>
> Cc: Dandan Bi <dandan.bi@intel.com>
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> 
> Signed-off-by: Kun Qin <kun.q@outlook.com>
> ---
>  MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.c
> | 16 ++++----
> 
> MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibSta
> ndaloneMm.c                                   | 39 ++++++++++++++++++++
> 
> MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibTra
> ditional.c                                    | 39 ++++++++++++++++++++
>  MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.h
> | 37 +++++++++++++++++++
> 
> MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLi
> b.inf                                          |  4 +-
> 
> MdeModulePkg/Library/SmmReportStatusCodeLib/{SmmReportStatusCode
> Lib.inf => StandaloneMmReportStatusCodeLib.inf} | 17 +++++----
>  MdeModulePkg/MdeModulePkg.dsc
> |  1 +
>  7 files changed, 137 insertions(+), 16 deletions(-)
> 
> diff --git
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.c
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.
> c
> index 3a1772538cdf..fb1769db9223 100644
> ---
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.c
> +++
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.
> c
> @@ -1,5 +1,5 @@
>  /** @file
> -  Report Status Code Library for SMM Phase.
> +  Report Status Code Library for MM Phase.
> 
>    Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
>    SPDX-License-Identifier: BSD-2-Clause-Patent @@ -8,7 +8,7 @@
> 
>  #include <Library/ReportStatusCodeLib.h>  #include <Library/DebugLib.h> -
> #include <Library/SmmServicesTableLib.h>
> +#include <Library/MmServicesTableLib.h>
>  #include <Library/BaseLib.h>
>  #include <Library/BaseMemoryLib.h>
>  #include <Library/PcdLib.h>
> @@ -16,10 +16,12 @@
> 
>  #include <Guid/StatusCodeDataTypeId.h>
>  #include <Guid/StatusCodeDataTypeDebug.h> -#include
> <Protocol/SmmStatusCode.h>
> +#include <Protocol/MmStatusCode.h>
> 
> -EFI_SMM_REPORT_STATUS_CODE     mReportStatusCode = NULL;
> -EFI_SMM_STATUS_CODE_PROTOCOL   *mStatusCodeProtocol = NULL;
> +#include "ReportStatusCodeLib.h"
> +
> +EFI_MM_REPORT_STATUS_CODE     mReportStatusCode = NULL;
> +EFI_MM_STATUS_CODE_PROTOCOL   *mStatusCodeProtocol = NULL;
> 
> 
>  /**
> @@ -29,14 +31,14 @@ EFI_SMM_STATUS_CODE_PROTOCOL
> *mStatusCodeProtocol = NULL;
>              NULL is returned if no status code service is available.
> 
>  **/
> -EFI_SMM_REPORT_STATUS_CODE
> +EFI_MM_REPORT_STATUS_CODE
>  InternalGetReportStatusCode (
>    VOID
>    )
>  {
>    EFI_STATUS                    Status;
> 
> -  Status = gSmst->SmmLocateProtocol (&gEfiSmmStatusCodeProtocolGuid,
> NULL, (VOID**)&mStatusCodeProtocol);
> +  Status = InternalLocateProtocol (&gEfiMmStatusCodeProtocolGuid, NULL,
> + (VOID**)&mStatusCodeProtocol);
>    if (!EFI_ERROR (Status) && mStatusCodeProtocol != NULL) {
>      return mStatusCodeProtocol->ReportStatusCode;
>    }
> diff --git
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibS
> tandaloneMm.c
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibS
> tandaloneMm.c
> new file mode 100644
> index 000000000000..fc47dffe9ffb
> --- /dev/null
> +++
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibS
> ta
> +++ ndaloneMm.c
> @@ -0,0 +1,39 @@
> +/** @file
> +  Abstraction layer for MM service table used by MM ReportStatusCodeLib.
> +
> +  Copyright (c) Microsoft Corporation.
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <PiMm.h>
> +
> +#include <Library/MmServicesTableLib.h>
> +
> +/**
> +  Returns the first protocol instance that matches the given protocol.
> +
> +  @param[in]  Protocol          Provides the protocol to search for.
> +  @param[in]  Registration      Optional registration key returned from
> +                                RegisterProtocolNotify().
> +  @param[out]  Interface        On return, a pointer to the first interface that
> matches Protocol and
> +                                Registration.
> +
> +  @retval EFI_SUCCESS           A protocol instance matching Protocol was
> found and returned in
> +                                Interface.
> +  @retval EFI_NOT_FOUND         No protocol instances were found that
> match Protocol and
> +                                Registration.
> +  @retval EFI_INVALID_PARAMETER Interface is NULL.
> +                                Protocol is NULL.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +InternalLocateProtocol (
> +  IN  EFI_GUID  *Protocol,
> +  IN  VOID      *Registration, OPTIONAL
> +  OUT VOID      **Interface
> +  )
> +{
> +  return gMmst->MmLocateProtocol (Protocol, Registration, Interface); }
> diff --git
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibT
> raditional.c
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibT
> raditional.c
> new file mode 100644
> index 000000000000..6b3a7c6051c5
> --- /dev/null
> +++
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibT
> ra
> +++ ditional.c
> @@ -0,0 +1,39 @@
> +/** @file
> +  Abstraction layer for SMM service table used by SMM
> ReportStatusCodeLib.
> +
> +  Copyright (c) Microsoft Corporation.
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <PiMm.h>
> +
> +#include <Library/SmmServicesTableLib.h>
> +
> +/**
> +  Returns the first protocol instance that matches the given protocol.
> +
> +  @param[in]  Protocol          Provides the protocol to search for.
> +  @param[in]  Registration      Optional registration key returned from
> +                                RegisterProtocolNotify().
> +  @param[out]  Interface        On return, a pointer to the first interface that
> matches Protocol and
> +                                Registration.
> +
> +  @retval EFI_SUCCESS           A protocol instance matching Protocol was
> found and returned in
> +                                Interface.
> +  @retval EFI_NOT_FOUND         No protocol instances were found that
> match Protocol and
> +                                Registration.
> +  @retval EFI_INVALID_PARAMETER Interface is NULL.
> +                                Protocol is NULL.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +InternalLocateProtocol (
> +  IN  EFI_GUID  *Protocol,
> +  IN  VOID      *Registration, OPTIONAL
> +  OUT VOID      **Interface
> +  )
> +{
> +  return gSmst->SmmLocateProtocol (Protocol, Registration, Interface);
> +}
> diff --git
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.
> h
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.
> h
> new file mode 100644
> index 000000000000..9a16741e64f6
> --- /dev/null
> +++
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.
> h
> @@ -0,0 +1,37 @@
> +/** @file
> +  Report Status Code Library for MM Phase.
> +
> +  Copyright (c) 2009 - 2018, Intel Corporation. All rights
> + reserved.<BR>
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#ifndef _MM_RSC_LIB_H_
> +#define _MM_RSC_LIB_H_
> +
> +/**
> +  Returns the first protocol instance that matches the given protocol.
> +
> +  @param[in]  Protocol          Provides the protocol to search for.
> +  @param[in]  Registration      Optional registration key returned from
> +                                RegisterProtocolNotify().
> +  @param[out]  Interface        On return, a pointer to the first interface that
> matches Protocol and
> +                                Registration.
> +
> +  @retval EFI_SUCCESS           A protocol instance matching Protocol was
> found and returned in
> +                                Interface.
> +  @retval EFI_NOT_FOUND         No protocol instances were found that
> match Protocol and
> +                                Registration.
> +  @retval EFI_INVALID_PARAMETER Interface is NULL.
> +                                Protocol is NULL.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +InternalLocateProtocol (
> +  IN  EFI_GUID  *Protocol,
> +  IN  VOID      *Registration, OPTIONAL
> +  OUT VOID      **Interface
> +  );
> +
> +#endif // _MM_RSC_LIB_H_
> diff --git
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCod
> eLib.inf
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCod
> eLib.inf
> index 72496bfababd..02dce09a199d 100644
> ---
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCod
> eLib.inf
> +++
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCod
> eLib
> +++ .inf
> @@ -28,6 +28,8 @@ [Defines]
> 
>  [Sources]
>    ReportStatusCodeLib.c
> +  ReportStatusCodeLib.h
> +  ReportStatusCodeLibTraditional.c
> 
>  [Packages]
>    MdePkg/MdePkg.dec
> @@ -45,7 +47,7 @@ [Guids]
>    gEfiStatusCodeDataTypeDebugGuid               ## SOMETIMES_CONSUMES
> ## UNDEFINED
> 
>  [Protocols]
> -  gEfiSmmStatusCodeProtocolGuid                 ## CONSUMES
> +  gEfiMmStatusCodeProtocolGuid                  ## CONSUMES
> 
>  [Pcd]
>    gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask  ##
> CONSUMES diff --git
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCod
> eLib.inf
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/StandaloneMmReport
> StatusCodeLib.inf
> similarity index 64%
> copy from
> MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLi
> b.inf
> copy to
> MdeModulePkg/Library/SmmReportStatusCodeLib/StandaloneMmReportSt
> atusCodeLib.inf
> index 72496bfababd..11ecc67fc4fa 100644
> ---
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCod
> eLib.inf
> +++
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/StandaloneMmReport
> Stat
> +++ usCodeLib.inf
> @@ -12,13 +12,12 @@
> 
>  [Defines]
>    INF_VERSION                    = 0x00010005
> -  BASE_NAME                      = SmmReportStatusCodeLib
> -  MODULE_UNI_FILE                = SmmReportStatusCodeLib.uni
> -  FILE_GUID                      = 67089D19-B3D6-4d9e-A0EB-FEDC1F83A1EE
> -  MODULE_TYPE                    = DXE_SMM_DRIVER
> +  BASE_NAME                      = StandaloneMmReportStatusCodeLib
> +  FILE_GUID                      = 17C7FC8C-8C5D-497E-9C0E-C21255B30E04
> +  MODULE_TYPE                    = MM_STANDALONE
>    VERSION_STRING                 = 1.0
> -  PI_SPECIFICATION_VERSION       = 0x0001000A
> -  LIBRARY_CLASS                  = ReportStatusCodeLib|DXE_SMM_DRIVER
> SMM_CORE
> +  PI_SPECIFICATION_VERSION       = 0x00010032
> +  LIBRARY_CLASS                  = ReportStatusCodeLib|MM_STANDALONE
> 
>  #
>  # The following information is for reference only and not required by the
> build tools.
> @@ -28,6 +27,8 @@ [Defines]
> 
>  [Sources]
>    ReportStatusCodeLib.c
> +  ReportStatusCodeLib.h
> +  ReportStatusCodeLibStandaloneMm.c
> 
>  [Packages]
>    MdePkg/MdePkg.dec
> @@ -36,7 +37,7 @@ [Packages]
>  [LibraryClasses]
>    PcdLib
>    BaseMemoryLib
> -  SmmServicesTableLib
> +  MmServicesTableLib
>    DebugLib
>    MemoryAllocationLib
> 
> @@ -45,7 +46,7 @@ [Guids]
>    gEfiStatusCodeDataTypeDebugGuid               ## SOMETIMES_CONSUMES
> ## UNDEFINED
> 
>  [Protocols]
> -  gEfiSmmStatusCodeProtocolGuid                 ## CONSUMES
> +  gEfiMmStatusCodeProtocolGuid                  ## CONSUMES
> 
>  [Pcd]
>    gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask  ##
> CONSUMES diff --git a/MdeModulePkg/MdeModulePkg.dsc
> b/MdeModulePkg/MdeModulePkg.dsc index cd91a70b4fdd..05bf5fe08094
> 100644
> --- a/MdeModulePkg/MdeModulePkg.dsc
> +++ b/MdeModulePkg/MdeModulePkg.dsc
> @@ -473,6 +473,7 @@ [Components.IA32, Components.X64]
>    }
> 
> MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.i
> nf
> 
> MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLi
> b.inf
> +
> +
> MdeModulePkg/Library/SmmReportStatusCodeLib/StandaloneMmReportSt
> atusCo
> + deLib.inf
> 
> MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSm
> m.inf
> 
> MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCod
> eRouterSmm.inf
>    MdeModulePkg/Universal/LockBox/SmmLockBox/SmmLockBox.inf
> --
> 2.28.0.windows.1
> 
> 
> 
> 
> 


^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v1 07/15] MdeModulePkg: FirmwarePerformanceDataTable: Added StandaloneMm support
  2020-12-18 18:50 ` [PATCH v1 07/15] MdeModulePkg: FirmwarePerformanceDataTable: Added StandaloneMm support Kun Qin
@ 2020-12-22  8:36   ` Wu, Hao A
  2020-12-22 20:06     ` [edk2-devel] " Kun Qin
  0 siblings, 1 reply; 44+ messages in thread
From: Wu, Hao A @ 2020-12-22  8:36 UTC (permalink / raw)
  To: Kun Qin, devel@edk2.groups.io
  Cc: Wang, Jian J, Bi, Dandan, Liming Gao, Yao, Jiewen

> -----Original Message-----
> From: Kun Qin <kun.q@outlook.com>
> Sent: Saturday, December 19, 2020 2:50 AM
> To: devel@edk2.groups.io
> Cc: Wang, Jian J <jian.j.wang@intel.com>; Wu, Hao A <hao.a.wu@intel.com>;
> Bi, Dandan <dandan.bi@intel.com>; Liming Gao <gaoliming@byosoft.com.cn>
> Subject: [PATCH v1 07/15] MdeModulePkg: FirmwarePerformanceDataTable:
> Added StandaloneMm support
> 
> This change added support of FPDT driver under StandaloneMm. It replaces
> SMM version ReportStatusCode protocol with MM version. This patch also
> abstracts standalone and traditional MM interfaces into separate files to
> support each corresponding function prototypes and implementations.


Could you help to remove the 'EFIAPI' for functions:
  FirmwarePerformanceCommonEntryPoint()
  IsBufferOutsideMmValid()
I found that they are internal functions.

Another question I have is that is there any special consideration to list FirmwarePerformanceStandaloneMm.inf
under the [Components.X64] section in the DSC file?

Best Regards,
Hao Wu


> 
> Cc: Jian J Wang <jian.j.wang@intel.com>
> Cc: Hao A Wu <hao.a.wu@intel.com>
> Cc: Dandan Bi <dandan.bi@intel.com>
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> 
> Signed-off-by: Kun Qin <kun.q@outlook.com>
> ---
> 
> MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/{Firm
> warePerformanceSmm.c => FirmwarePerformanceCommon.c}           | 72
> ++++++++++----------
> 
> MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Firm
> warePerformanceStandaloneMm.c                                   | 62
> +++++++++++++++++
> 
> MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Firm
> warePerformanceTraditional.c                                    | 62 +++++++++++++++++
>  MdeModulePkg/MdeModulePkg.dsc
> |  2 +
> 
> MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Firm
> warePerformanceCommon.h                                         | 55 +++++++++++++++
> 
> MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Firm
> warePerformanceSmm.inf                                          | 11 +--
> 
> MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/{Firm
> warePerformanceSmm.inf => FirmwarePerformanceStandaloneMm.inf} | 31
> ++++-----
>  7 files changed, 237 insertions(+), 58 deletions(-)
> 
> diff --git
> a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fir
> mwarePerformanceSmm.c
> b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fir
> mwarePerformanceCommon.c
> similarity index 77%
> rename from
> MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Firm
> warePerformanceSmm.c
> rename to
> MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Firm
> warePerformanceCommon.c
> index d6c6e7693e4d..c2aa9455f9c4 100644
> ---
> a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fir
> mwarePerformanceSmm.c
> +++
> b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fir
> mwa
> +++ rePerformanceCommon.c
> @@ -1,11 +1,11 @@
>  /** @file
> -  This module collects performance data for SMM driver boot records and S3
> Suspend Performance Record.
> +  This module collects performance data for MM driver boot records and S3
> Suspend Performance Record.
> 
>    This module registers report status code listener to collect performance
> data
> -  for SMM driver boot records and S3 Suspend Performance Record.
> +  for MM driver boot records and S3 Suspend Performance Record.
> 
>    Caution: This module requires additional review when modified.
> -  This driver will have external input - communicate buffer in SMM mode.
> +  This driver will have external input - communicate buffer in MM mode.
>    This external input must be validated carefully to avoid security issue like
>    buffer overflow, integer overflow.
> 
> @@ -16,13 +16,13 @@
> 
>  **/
> 
> -#include <PiSmm.h>
> +#include <PiMm.h>
> 
> -#include <Protocol/SmmReportStatusCodeHandler.h>
> +#include <Protocol/MmReportStatusCodeHandler.h>
> 
>  #include <Guid/FirmwarePerformance.h>
> 
> -#include <Library/SmmServicesTableLib.h>
> +#include <Library/MmServicesTableLib.h>
>  #include <Library/BaseLib.h>
>  #include <Library/DebugLib.h>
>  #include <Library/TimerLib.h>
> @@ -30,23 +30,22 @@
>  #include <Library/PcdLib.h>
>  #include <Library/BaseMemoryLib.h>
>  #include <Library/MemoryAllocationLib.h> -#include
> <Library/UefiBootServicesTableLib.h>
>  #include <Library/SynchronizationLib.h> -#include <Library/SmmMemLib.h>
> +#include "FirmwarePerformanceCommon.h"
> 
> -SMM_BOOT_PERFORMANCE_TABLE    *mSmmBootPerformanceTable =
> NULL;
> +SMM_BOOT_PERFORMANCE_TABLE    *mMmBootPerformanceTable =
> NULL;
> 
> -EFI_SMM_RSC_HANDLER_PROTOCOL  *mRscHandlerProtocol    = NULL;
> +EFI_MM_RSC_HANDLER_PROTOCOL   *mRscHandlerProtocol    = NULL;
>  UINT64                        mSuspendStartTime       = 0;
>  BOOLEAN                       mS3SuspendLockBoxSaved  = FALSE;
>  UINT32                        mBootRecordSize = 0;
>  UINT8                         *mBootRecordBuffer = NULL;
> 
> -SPIN_LOCK                     mSmmFpdtLock;
> -BOOLEAN                       mSmramIsOutOfResource = FALSE;
> +SPIN_LOCK                     mMmFpdtLock;
> +BOOLEAN                       mMmramIsOutOfResource = FALSE;
> 
>  /**
> -  Report status code listener for SMM. This is used to record the
> performance
> +  Report status code listener for MM. This is used to record the
> + performance
>    data for S3 Suspend Start and S3 Suspend End in FPDT.
> 
>    @param[in]  CodeType            Indicates the type of status code being
> reported.
> @@ -66,7 +65,7 @@ BOOLEAN                       mSmramIsOutOfResource = FALSE;
>  **/
>  EFI_STATUS
>  EFIAPI
> -FpdtStatusCodeListenerSmm (
> +FpdtStatusCodeListenerMm (
>    IN EFI_STATUS_CODE_TYPE     CodeType,
>    IN EFI_STATUS_CODE_VALUE    Value,
>    IN UINT32                   Instance,
> @@ -89,19 +88,19 @@ FpdtStatusCodeListenerSmm (
>    // Collect one or more Boot records in boot time
>    //
>    if (Data != NULL && CompareGuid (&Data->Type,
> &gEdkiiFpdtExtendedFirmwarePerformanceGuid)) {
> -    AcquireSpinLock (&mSmmFpdtLock);
> +    AcquireSpinLock (&mMmFpdtLock);
>      //
>      // Get the boot performance data.
>      //
> -    CopyMem (&mSmmBootPerformanceTable, Data + 1, Data->Size);
> -    mBootRecordBuffer = ((UINT8 *) (mSmmBootPerformanceTable)) +
> sizeof (SMM_BOOT_PERFORMANCE_TABLE);
> +    CopyMem (&mMmBootPerformanceTable, Data + 1, Data->Size);
> +    mBootRecordBuffer = ((UINT8 *) (mMmBootPerformanceTable)) + sizeof
> + (SMM_BOOT_PERFORMANCE_TABLE);
> 
> -    ReleaseSpinLock (&mSmmFpdtLock);
> +    ReleaseSpinLock (&mMmFpdtLock);
>      return EFI_SUCCESS;
>    }
> 
>    if (Data != NULL && CompareGuid (&Data->Type,
> &gEfiFirmwarePerformanceGuid)) {
> -    DEBUG ((DEBUG_ERROR, "FpdtStatusCodeListenerSmm: Performance
> data reported through gEfiFirmwarePerformanceGuid will not be collected
> by FirmwarePerformanceDataTableSmm\n"));
> +    DEBUG ((DEBUG_ERROR, "FpdtStatusCodeListenerMm: Performance
> data
> + reported through gEfiFirmwarePerformanceGuid will not be collected by
> + FirmwarePerformanceDataTableMm\n"));
>      return EFI_UNSUPPORTED;
>    }
> 
> @@ -157,7 +156,7 @@ FpdtStatusCodeListenerSmm (
>  /**
>    Communication service SMI Handler entry.
> 
> -  This SMI handler provides services for report SMM boot records.
> +  This SMI handler provides services for report MM boot records.
> 
>    Caution: This function may receive untrusted input.
>    Communicate buffer and buffer size are external input, so this function will
> do basic validation.
> @@ -166,7 +165,7 @@ FpdtStatusCodeListenerSmm (
>    @param[in]     RegisterContext Points to an optional handler context which
> was specified when the
>                                   handler was registered.
>    @param[in, out] CommBuffer     A pointer to a collection of data in memory
> that will
> -                                 be conveyed from a non-SMM environment into an SMM
> environment.
> +                                 be conveyed from a non-MM environment into an MM
> environment.
>    @param[in, out] CommBufferSize The size of the CommBuffer.
> 
>    @retval EFI_SUCCESS                         The interrupt was handled and quiesced.
> No other handlers
> @@ -207,8 +206,8 @@ FpdtSmiHandler (
>      return EFI_SUCCESS;
>    }
> 
> -  if (!SmmIsBufferOutsideSmmValid ((UINTN)CommBuffer,
> TempCommBufferSize)) {
> -    DEBUG ((EFI_D_ERROR, "FpdtSmiHandler: SMM communication data
> buffer in SMRAM or overflow!\n"));
> +  if (!IsBufferOutsideMmValid ((UINTN)CommBuffer,
> TempCommBufferSize)) {
> +    DEBUG ((DEBUG_ERROR, "FpdtSmiHandler: MM communication data
> buffer
> + in MMRAM or overflow!\n"));
>      return EFI_SUCCESS;
>    }
> 
> @@ -218,8 +217,8 @@ FpdtSmiHandler (
> 
>    switch (SmmCommData->Function) {
>      case SMM_FPDT_FUNCTION_GET_BOOT_RECORD_SIZE :
> -      if (mSmmBootPerformanceTable != NULL) {
> -        mBootRecordSize = mSmmBootPerformanceTable->Header.Length -
> sizeof (SMM_BOOT_PERFORMANCE_TABLE);
> +      if (mMmBootPerformanceTable != NULL) {
> +        mBootRecordSize = mMmBootPerformanceTable->Header.Length -
> + sizeof (SMM_BOOT_PERFORMANCE_TABLE);
>        }
>        SmmCommData->BootRecordSize = mBootRecordSize;
>        break;
> @@ -244,8 +243,8 @@ FpdtSmiHandler (
>          BootRecordSize = mBootRecordSize - BootRecordOffset;
>        }
>        SmmCommData->BootRecordSize = BootRecordSize;
> -      if (!SmmIsBufferOutsideSmmValid ((UINTN)BootRecordData,
> BootRecordSize)) {
> -        DEBUG ((EFI_D_ERROR, "FpdtSmiHandler: SMM Data buffer in SMRAM
> or overflow!\n"));
> +      if (!IsBufferOutsideMmValid ((UINTN)BootRecordData, BootRecordSize))
> {
> +        DEBUG ((DEBUG_ERROR, "FpdtSmiHandler: MM Data buffer in
> MMRAM
> + or overflow!\n"));
>          Status = EFI_ACCESS_DENIED;
>          break;
>        }
> @@ -267,7 +266,7 @@ FpdtSmiHandler (
>  }
> 
>  /**
> -  The module Entry Point of the Firmware Performance Data Table SMM
> driver.
> +  The module Entry Point of the Firmware Performance Data Table MM
> driver.
> 
>    @param[in]  ImageHandle    The firmware allocated handle for the EFI
> image.
>    @param[in]  SystemTable    A pointer to the EFI System Table.
> @@ -278,9 +277,8 @@ FpdtSmiHandler (
>  **/
>  EFI_STATUS
>  EFIAPI
> -FirmwarePerformanceSmmEntryPoint (
> -  IN EFI_HANDLE          ImageHandle,
> -  IN EFI_SYSTEM_TABLE    *SystemTable
> +FirmwarePerformanceCommonEntryPoint (
> +  VOID
>    )
>  {
>    EFI_STATUS                Status;
> @@ -289,13 +287,13 @@ FirmwarePerformanceSmmEntryPoint (
>    //
>    // Initialize spin lock
>    //
> -  InitializeSpinLock (&mSmmFpdtLock);
> +  InitializeSpinLock (&mMmFpdtLock);
> 
>    //
> -  // Get SMM Report Status Code Handler Protocol.
> +  // Get MM Report Status Code Handler Protocol.
>    //
> -  Status = gSmst->SmmLocateProtocol (
> -                    &gEfiSmmRscHandlerProtocolGuid,
> +  Status = gMmst->MmLocateProtocol (
> +                    &gEfiMmRscHandlerProtocolGuid,
>                      NULL,
>                      (VOID **) &mRscHandlerProtocol
>                      );
> @@ -304,14 +302,14 @@ FirmwarePerformanceSmmEntryPoint (
>    //
>    // Register report status code listener for BootRecords and S3 Suspend
> Start and End.
>    //
> -  Status = mRscHandlerProtocol->Register (FpdtStatusCodeListenerSmm);
> +  Status = mRscHandlerProtocol->Register (FpdtStatusCodeListenerMm);
>    ASSERT_EFI_ERROR (Status);
> 
>    //
>    // Register SMI handler.
>    //
>    Handle = NULL;
> -  Status = gSmst->SmiHandlerRegister (FpdtSmiHandler,
> &gEfiFirmwarePerformanceGuid, &Handle);
> +  Status = gMmst->MmiHandlerRegister (FpdtSmiHandler,
> + &gEfiFirmwarePerformanceGuid, &Handle);
>    ASSERT_EFI_ERROR (Status);
> 
>    return Status;
> diff --git
> a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fir
> mwarePerformanceStandaloneMm.c
> b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fir
> mwarePerformanceStandaloneMm.c
> new file mode 100644
> index 000000000000..2c4f40eceaea
> --- /dev/null
> +++
> b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fir
> mwa
> +++ rePerformanceStandaloneMm.c
> @@ -0,0 +1,62 @@
> +/** @file
> +  This module collects performance data for MM driver boot records and S3
> Suspend Performance Record.
> +
> +  This module registers report status code listener to collect
> + performance data  for MM driver boot records and S3 Suspend
> Performance Record.
> +
> +  Caution: This module requires additional review when modified.
> +  This driver will have external input - communicate buffer in MM mode.
> +  This external input must be validated carefully to avoid security
> + issue like  buffer overflow, integer overflow.
> +
> +  FpdtSmiHandler() will receive untrusted input and do basic validation.
> +
> +  Copyright (c) 2011 - 2018, Intel Corporation. All rights
> + reserved.<BR>  Copyright (c), Microsoft Corporation.
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <PiMm.h>
> +
> +#include <Library/StandaloneMmMemLib.h> #include
> +"FirmwarePerformanceCommon.h"
> +
> +/**
> +  This function is an abstraction layer for implementation specific Mm buffer
> validation routine.
> +
> +  @param Buffer  The buffer start address to be checked.
> +  @param Length  The buffer length to be checked.
> +
> +  @retval TRUE  This buffer is valid per processor architecture and not
> overlap with SMRAM.
> +  @retval FALSE This buffer is not valid per processor architecture or overlap
> with SMRAM.
> +**/
> +BOOLEAN
> +EFIAPI
> +IsBufferOutsideMmValid (
> +  IN EFI_PHYSICAL_ADDRESS  Buffer,
> +  IN UINT64                Length
> +  )
> +{
> +  return MmIsBufferOutsideMmValid (Buffer, Length); }
> +
> +/**
> +  The module Entry Point of the Firmware Performance Data Table MM
> driver.
> +
> +  @param[in]  ImageHandle    The firmware allocated handle for the EFI
> image.
> +  @param[in]  SystemTable    A pointer to the EFI System Table.
> +
> +  @retval EFI_SUCCESS    The entry point is executed successfully.
> +  @retval Other          Some error occurs when executing this entry point.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +FirmwarePerformanceStandaloneMmEntryPoint (
> +  IN EFI_HANDLE             ImageHandle,
> +  IN EFI_MM_SYSTEM_TABLE    *SystemTable
> +  )
> +{
> +  return FirmwarePerformanceCommonEntryPoint (); }
> diff --git
> a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fir
> mwarePerformanceTraditional.c
> b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fir
> mwarePerformanceTraditional.c
> new file mode 100644
> index 000000000000..507aabcb4e88
> --- /dev/null
> +++
> b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fir
> mwa
> +++ rePerformanceTraditional.c
> @@ -0,0 +1,62 @@
> +/** @file
> +  This module collects performance data for MM driver boot records and S3
> Suspend Performance Record.
> +
> +  This module registers report status code listener to collect
> + performance data  for MM driver boot records and S3 Suspend
> Performance Record.
> +
> +  Caution: This module requires additional review when modified.
> +  This driver will have external input - communicate buffer in MM mode.
> +  This external input must be validated carefully to avoid security
> + issue like  buffer overflow, integer overflow.
> +
> +  FpdtSmiHandler() will receive untrusted input and do basic validation.
> +
> +  Copyright (c) 2011 - 2018, Intel Corporation. All rights
> + reserved.<BR>  Copyright (c), Microsoft Corporation.
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <PiSmm.h>
> +
> +#include <Library/SmmMemLib.h>
> +#include "FirmwarePerformanceCommon.h"
> +
> +/**
> +  This function is an abstraction layer for implementation specific Mm buffer
> validation routine.
> +
> +  @param Buffer  The buffer start address to be checked.
> +  @param Length  The buffer length to be checked.
> +
> +  @retval TRUE  This buffer is valid per processor architecture and not
> overlap with SMRAM.
> +  @retval FALSE This buffer is not valid per processor architecture or overlap
> with SMRAM.
> +**/
> +BOOLEAN
> +EFIAPI
> +IsBufferOutsideMmValid (
> +  IN EFI_PHYSICAL_ADDRESS  Buffer,
> +  IN UINT64                Length
> +  )
> +{
> +  return SmmIsBufferOutsideSmmValid (Buffer, Length); }
> +
> +/**
> +  The module Entry Point of the Firmware Performance Data Table MM
> driver.
> +
> +  @param[in]  ImageHandle    The firmware allocated handle for the EFI
> image.
> +  @param[in]  SystemTable    A pointer to the EFI System Table.
> +
> +  @retval EFI_SUCCESS    The entry point is executed successfully.
> +  @retval Other          Some error occurs when executing this entry point.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +FirmwarePerformanceSmmEntryPoint (
> +  IN EFI_HANDLE          ImageHandle,
> +  IN EFI_SYSTEM_TABLE    *SystemTable
> +  )
> +{
> +  return FirmwarePerformanceCommonEntryPoint (); }
> diff --git a/MdeModulePkg/MdeModulePkg.dsc
> b/MdeModulePkg/MdeModulePkg.dsc index 05bf5fe08094..dc85d108d958
> 100644
> --- a/MdeModulePkg/MdeModulePkg.dsc
> +++ b/MdeModulePkg/MdeModulePkg.dsc
> @@ -168,6 +168,7 @@ [LibraryClasses.common.MM_STANDALONE]
> 
> StandaloneMmDriverEntryPoint|MdePkg/Library/StandaloneMmDriverEntry
> Point/StandaloneMmDriverEntryPoint.inf
> 
> MmServicesTableLib|MdePkg/Library/StandaloneMmServicesTableLib/Stan
> daloneMmServicesTableLib.inf
> 
> LockBoxLib|MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxStandalo
> neMmLib.inf
> +
> +
> MemLib|StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMm
> MemLib.i
> + nf
> 
>  [LibraryClasses.ARM, LibraryClasses.AARCH64]
>    ArmLib|ArmPkg/Library/ArmLib/ArmBaseLib.inf
> @@ -501,6 +502,7 @@ [Components.IA32, Components.X64]
> 
>  [Components.X64]
>    MdeModulePkg/Universal/CapsulePei/CapsuleX64.inf
> +
> +
> MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Firm
> warePe
> + rformanceStandaloneMm.inf
> 
>  [BuildOptions]
> 
> diff --git
> a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fir
> mwarePerformanceCommon.h
> b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fir
> mwarePerformanceCommon.h
> new file mode 100644
> index 000000000000..ba01e28f2493
> --- /dev/null
> +++
> b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fir
> mwa
> +++ rePerformanceCommon.h
> @@ -0,0 +1,55 @@
> +/** @file
> +  This module collects performance data for SMM driver boot records and S3
> Suspend Performance Record.
> +
> +  This module registers report status code listener to collect
> + performance data  for SMM driver boot records and S3 Suspend
> Performance Record.
> +
> +  Caution: This module requires additional review when modified.
> +  This driver will have external input - communicate buffer in SMM mode.
> +  This external input must be validated carefully to avoid security
> + issue like  buffer overflow, integer overflow.
> +
> +  FpdtSmiHandler() will receive untrusted input and do basic validation.
> +
> +  Copyright (c) 2011 - 2018, Intel Corporation. All rights
> + reserved.<BR>  Copyright (c), Microsoft Corporation.
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#ifndef _FW_PERF_COMMON_H_
> +#define _FW_PERF_COMMON_H_
> +
> +/**
> +  This function is an abstraction layer for implementation specific Mm buffer
> validation routine.
> +
> +  @param Buffer  The buffer start address to be checked.
> +  @param Length  The buffer length to be checked.
> +
> +  @retval TRUE  This buffer is valid per processor architecture and not
> overlap with SMRAM.
> +  @retval FALSE This buffer is not valid per processor architecture or overlap
> with SMRAM.
> +**/
> +BOOLEAN
> +EFIAPI
> +IsBufferOutsideMmValid (
> +  IN EFI_PHYSICAL_ADDRESS  Buffer,
> +  IN UINT64                Length
> +  );
> +
> +/**
> +  The module Entry Point of the Firmware Performance Data Table MM
> driver.
> +
> +  @param[in]  ImageHandle    The firmware allocated handle for the EFI
> image.
> +  @param[in]  SystemTable    A pointer to the EFI System Table.
> +
> +  @retval EFI_SUCCESS    The entry point is executed successfully.
> +  @retval Other          Some error occurs when executing this entry point.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +FirmwarePerformanceCommonEntryPoint (
> +  VOID
> +  );
> +
> +#endif // _FW_PERF_COMMON_H_
> diff --git
> a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fir
> mwarePerformanceSmm.inf
> b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fir
> mwarePerformanceSmm.inf
> index 618cbd56ca59..b7194bd899dd 100644
> ---
> a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fir
> mwarePerformanceSmm.inf
> +++
> b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fir
> mwa
> +++ rePerformanceSmm.inf
> @@ -26,7 +26,9 @@ [Defines]
>  #
> 
>  [Sources]
> -  FirmwarePerformanceSmm.c
> +  FirmwarePerformanceCommon.c
> +  FirmwarePerformanceCommon.h
> +  FirmwarePerformanceTraditional.c
> 
>  [Packages]
>    MdePkg/MdePkg.dec
> @@ -34,7 +36,7 @@ [Packages]
> 
>  [LibraryClasses]
>    UefiDriverEntryPoint
> -  SmmServicesTableLib
> +  MmServicesTableLib
>    BaseLib
>    DebugLib
>    TimerLib
> @@ -42,12 +44,11 @@ [LibraryClasses]
>    PcdLib
>    BaseMemoryLib
>    MemoryAllocationLib
> -  UefiBootServicesTableLib
>    SynchronizationLib
>    SmmMemLib
> 
>  [Protocols]
> -  gEfiSmmRscHandlerProtocolGuid                 ## CONSUMES
> +  gEfiMmRscHandlerProtocolGuid                 ## CONSUMES
> 
>  [Guids]
>    ## SOMETIMES_PRODUCES   ## UNDEFINED # SaveLockBox
> @@ -61,7 +62,7 @@ [Pcd]
>    gEfiMdeModulePkgTokenSpaceGuid.PcdProgressCodeS3SuspendEnd    ##
> CONSUMES
> 
>  [Depex]
> -  gEfiSmmRscHandlerProtocolGuid
> +  gEfiMmRscHandlerProtocolGuid
> 
>  [UserExtensions.TianoCore."ExtraFiles"]
>    FirmwarePerformanceSmmExtra.uni
> diff --git
> a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fir
> mwarePerformanceSmm.inf
> b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fir
> mwarePerformanceStandaloneMm.inf
> similarity index 65%
> copy from
> MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Firm
> warePerformanceSmm.inf
> copy to
> MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Firm
> warePerformanceStandaloneMm.inf
> index 618cbd56ca59..e6aad88be0ef 100644
> ---
> a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fir
> mwarePerformanceSmm.inf
> +++
> b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fir
> mwa
> +++ rePerformanceStandaloneMm.inf
> @@ -5,19 +5,19 @@
>  #  for SMM boot performance records and S3 Suspend Performance Record.
>  #
>  #  Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
> +#  Copyright (c) Microsoft Corporation.
>  #  SPDX-License-Identifier: BSD-2-Clause-Patent  #  ##
> 
>  [Defines]
>    INF_VERSION                    = 0x00010005
> -  BASE_NAME                      = FirmwarePerformanceSmm
> -  MODULE_UNI_FILE                = FirmwarePerformanceSmm.uni
> -  FILE_GUID                      = 044310AB-77FD-402a-AF1A-87D4120E7329
> -  MODULE_TYPE                    = DXE_SMM_DRIVER
> +  BASE_NAME                      = FirmwarePerformanceStandaloneMm
> +  FILE_GUID                      = 827AC29D-E52D-4B1A-874A-C6577E0699CF
> +  MODULE_TYPE                    = MM_STANDALONE
>    VERSION_STRING                 = 1.0
> -  PI_SPECIFICATION_VERSION       = 0x0001000A
> -  ENTRY_POINT                    = FirmwarePerformanceSmmEntryPoint
> +  PI_SPECIFICATION_VERSION       = 0x00010032
> +  ENTRY_POINT                    = FirmwarePerformanceStandaloneMmEntryPoint
> 
>  #
>  # The following information is for reference only and not required by the
> build tools.
> @@ -26,15 +26,18 @@ [Defines]
>  #
> 
>  [Sources]
> -  FirmwarePerformanceSmm.c
> +  FirmwarePerformanceCommon.c
> +  FirmwarePerformanceCommon.h
> +  FirmwarePerformanceStandaloneMm.c
> 
>  [Packages]
>    MdePkg/MdePkg.dec
>    MdeModulePkg/MdeModulePkg.dec
> +  StandaloneMmPkg/StandaloneMmPkg.dec
> 
>  [LibraryClasses]
> -  UefiDriverEntryPoint
> -  SmmServicesTableLib
> +  StandaloneMmDriverEntryPoint
> +  MmServicesTableLib
>    BaseLib
>    DebugLib
>    TimerLib
> @@ -42,12 +45,11 @@ [LibraryClasses]
>    PcdLib
>    BaseMemoryLib
>    MemoryAllocationLib
> -  UefiBootServicesTableLib
>    SynchronizationLib
> -  SmmMemLib
> +  MemLib
> 
>  [Protocols]
> -  gEfiSmmRscHandlerProtocolGuid                 ## CONSUMES
> +  gEfiMmRscHandlerProtocolGuid                 ## CONSUMES
> 
>  [Guids]
>    ## SOMETIMES_PRODUCES   ## UNDEFINED # SaveLockBox
> @@ -61,7 +63,4 @@ [Pcd]
>    gEfiMdeModulePkgTokenSpaceGuid.PcdProgressCodeS3SuspendEnd    ##
> CONSUMES
> 
>  [Depex]
> -  gEfiSmmRscHandlerProtocolGuid
> -
> -[UserExtensions.TianoCore."ExtraFiles"]
> -  FirmwarePerformanceSmmExtra.uni
> +  gEfiMmRscHandlerProtocolGuid
> --
> 2.28.0.windows.1


^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v1 08/15] MdeModulePkg: ReportStatusCodeRouter: Support StandaloneMm RSC Router
  2020-12-18 18:50 ` [PATCH v1 08/15] MdeModulePkg: ReportStatusCodeRouter: Support StandaloneMm RSC Router Kun Qin
@ 2020-12-22  8:42   ` Wu, Hao A
  0 siblings, 0 replies; 44+ messages in thread
From: Wu, Hao A @ 2020-12-22  8:42 UTC (permalink / raw)
  To: Kun Qin, devel@edk2.groups.io
  Cc: Wang, Jian J, Bi, Dandan, Liming Gao, Yao, Jiewen

A couple of inline comments below:


> -----Original Message-----
> From: Kun Qin <kun.q@outlook.com>
> Sent: Saturday, December 19, 2020 2:50 AM
> To: devel@edk2.groups.io
> Cc: Wang, Jian J <jian.j.wang@intel.com>; Wu, Hao A <hao.a.wu@intel.com>;
> Bi, Dandan <dandan.bi@intel.com>; Liming Gao <gaoliming@byosoft.com.cn>
> Subject: [PATCH v1 08/15] MdeModulePkg: ReportStatusCodeRouter:
> Support StandaloneMm RSC Router
> 
> This change added support of RSC router under StandaloneMm. It replaces
> SMM version ReportStatusCode protocol definitions with MM version. This
> patch also switched to use gMmst instead of gSmst. Lastly, it abstracts
> standalone and traditional MM driver entrypoints into separate files to allow
> maximal common implementations.
> 
> Cc: Jian J Wang <jian.j.wang@intel.com>
> Cc: Hao A Wu <hao.a.wu@intel.com>
> Cc: Dandan Bi <dandan.bi@intel.com>
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> 
> Signed-off-by: Kun Qin <kun.q@outlook.com>
> ---
> 
> MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/{ReportStatusCo
> deRouterSmm.c => ReportStatusCodeRouterCommon.c} | 43 ++++++++------
> ---
> 
> MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCod
> eRouterStandaloneMm.c                            | 33 +++++++++++++
> 
> MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCod
> eRouterTraditional.c                             | 33 +++++++++++++
>  MdeModulePkg/MdeModulePkg.dsc
> |  1 +
> 
> MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/{ReportStatusCo
> deRouterSmm.h => ReportStatusCodeRouterCommon.h} | 50
> +++++++++++++-------
> 
> MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCod
> eRouterSmm.inf                                   | 13 ++---
> 
> MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCod
> eRouterStandaloneMm.inf                          | 49 +++++++++++++++++++
>  7 files changed, 177 insertions(+), 45 deletions(-)
> 
> diff --git
> a/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusC
> odeRouterSmm.c
> b/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusC
> odeRouterCommon.c
> similarity index 80%
> rename from
> MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCod
> eRouterSmm.c
> rename to
> MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCod
> eRouterCommon.c
> index c3ab5cd05045..585428aad669 100644
> ---
> a/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusC
> odeRouterSmm.c
> +++
> b/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusC
> ode
> +++ RouterCommon.c
> @@ -7,7 +7,7 @@
> 
>  **/
> 
> -#include "ReportStatusCodeRouterSmm.h"
> +#include "ReportStatusCodeRouterCommon.h"
> 
>  LIST_ENTRY   mCallbackListHead          = INITIALIZE_LIST_HEAD_VARIABLE
> (mCallbackListHead);
> 
> @@ -17,11 +17,11 @@ LIST_ENTRY   mCallbackListHead          =
> INITIALIZE_LIST_HEAD_VARIABLE (mCallba
>  //
>  UINT32       mStatusCodeNestStatus = 0;
> 
> -EFI_SMM_STATUS_CODE_PROTOCOL  mSmmStatusCodeProtocol  = {
> +EFI_MM_STATUS_CODE_PROTOCOL   mSmmStatusCodeProtocol  = {
>    ReportDispatcher
>  };
> 
> -EFI_SMM_RSC_HANDLER_PROTOCOL  mSmmRscHandlerProtocol = {
> +EFI_MM_RSC_HANDLER_PROTOCOL   mSmmRscHandlerProtocol = {
>    Register,
>    Unregister
>    };
> @@ -45,18 +45,18 @@ EFI_SMM_RSC_HANDLER_PROTOCOL
> mSmmRscHandlerProtocol = {  EFI_STATUS  EFIAPI  Register (
> -  IN EFI_SMM_RSC_HANDLER_CALLBACK   Callback
> +  IN EFI_MM_RSC_HANDLER_CALLBACK    Callback
>    )
>  {
>    LIST_ENTRY                      *Link;
> -  SMM_RSC_HANDLER_CALLBACK_ENTRY  *CallbackEntry;
> +  MM_RSC_HANDLER_CALLBACK_ENTRY  *CallbackEntry;
> 
>    if (Callback == NULL) {
>      return EFI_INVALID_PARAMETER;
>    }
> 
>    for (Link = GetFirstNode (&mCallbackListHead); !IsNull (&mCallbackListHead,
> Link); Link = GetNextNode (&mCallbackListHead, Link)) {
> -    CallbackEntry = CR (Link, SMM_RSC_HANDLER_CALLBACK_ENTRY, Node,
> SMM_RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE);
> +    CallbackEntry = CR (Link, MM_RSC_HANDLER_CALLBACK_ENTRY, Node,
> + MM_RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE);
>      if (CallbackEntry->RscHandlerCallback == Callback) {
>        //
>        // If the function was already registered. It can't be registered again.
> @@ -65,10 +65,10 @@ Register (
>      }
>    }
> 
> -  CallbackEntry = (SMM_RSC_HANDLER_CALLBACK_ENTRY *)AllocatePool
> (sizeof (SMM_RSC_HANDLER_CALLBACK_ENTRY));
> +  CallbackEntry = (MM_RSC_HANDLER_CALLBACK_ENTRY *)AllocatePool
> (sizeof
> + (MM_RSC_HANDLER_CALLBACK_ENTRY));
>    ASSERT (CallbackEntry != NULL);
> 
> -  CallbackEntry->Signature          =
> SMM_RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE;
> +  CallbackEntry->Signature          =
> MM_RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE;
>    CallbackEntry->RscHandlerCallback = Callback;
> 
>    InsertTailList (&mCallbackListHead, &CallbackEntry->Node); @@ -92,18
> +92,18 @@ Register (  EFI_STATUS  EFIAPI  Unregister (
> -  IN EFI_SMM_RSC_HANDLER_CALLBACK Callback
> +  IN EFI_MM_RSC_HANDLER_CALLBACK  Callback
>    )
>  {
>    LIST_ENTRY                        *Link;
> -  SMM_RSC_HANDLER_CALLBACK_ENTRY    *CallbackEntry;
> +  MM_RSC_HANDLER_CALLBACK_ENTRY    *CallbackEntry;
> 
>    if (Callback == NULL) {
>      return EFI_INVALID_PARAMETER;
>    }
> 
>    for (Link = GetFirstNode (&mCallbackListHead); !IsNull (&mCallbackListHead,
> Link); Link = GetNextNode (&mCallbackListHead, Link)) {
> -    CallbackEntry = CR (Link, SMM_RSC_HANDLER_CALLBACK_ENTRY, Node,
> SMM_RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE);
> +    CallbackEntry = CR (Link, MM_RSC_HANDLER_CALLBACK_ENTRY, Node,
> + MM_RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE);
>      if (CallbackEntry->RscHandlerCallback == Callback) {
>        //
>        // If the function is found in list, delete it and return.
> @@ -140,16 +140,16 @@ Unregister (
>  EFI_STATUS
>  EFIAPI
>  ReportDispatcher (
> -  IN CONST EFI_SMM_STATUS_CODE_PROTOCOL  *This,
> +  IN CONST EFI_MM_STATUS_CODE_PROTOCOL   *This,
>    IN EFI_STATUS_CODE_TYPE                Type,
>    IN EFI_STATUS_CODE_VALUE               Value,
>    IN UINT32                              Instance,
> -  IN CONST EFI_GUID                      *CallerId  OPTIONAL,
> +  IN CONST EFI_GUID                      *CallerId,
>    IN EFI_STATUS_CODE_DATA                *Data      OPTIONAL
>    )
>  {
>    LIST_ENTRY                        *Link;
> -  SMM_RSC_HANDLER_CALLBACK_ENTRY    *CallbackEntry;
> +  MM_RSC_HANDLER_CALLBACK_ENTRY    *CallbackEntry;
> 
>    //
>    // Use atom operation to avoid the reentant of report.
> @@ -160,7 +160,7 @@ ReportDispatcher (
>    }
> 
>    for (Link = GetFirstNode (&mCallbackListHead); !IsNull (&mCallbackListHead,
> Link);) {
> -    CallbackEntry = CR (Link, SMM_RSC_HANDLER_CALLBACK_ENTRY, Node,
> SMM_RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE);
> +    CallbackEntry = CR (Link, MM_RSC_HANDLER_CALLBACK_ENTRY, Node,
> + MM_RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE);
>      //
>      // The handler may remove itself, so get the next handler in advance.
>      //
> @@ -197,9 +197,8 @@ ReportDispatcher (
>  **/
>  EFI_STATUS
>  EFIAPI
> -GenericStatusCodeSmmEntry (
> -  IN EFI_HANDLE         ImageHandle,
> -  IN EFI_SYSTEM_TABLE   *SystemTable
> +GenericStatusCodeCommonEntry (
> +  VOID
>    )


Could you help to remove the 'EFIAPI' for function GenericStatusCodeCommonEntry()?
And also update the function description comments for removed input parameters?


>  {
>    EFI_STATUS     Status;
> @@ -210,9 +209,9 @@ GenericStatusCodeSmmEntry (
>    //
>    // Install SmmRscHandler Protocol
>    //
> -  Status = gSmst->SmmInstallProtocolInterface (
> +  Status = gMmst->MmInstallProtocolInterface (
>                      &Handle,
> -                    &gEfiSmmRscHandlerProtocolGuid,
> +                    &gEfiMmRscHandlerProtocolGuid,
>                      EFI_NATIVE_INTERFACE,
>                      &mSmmRscHandlerProtocol
>                      );
> @@ -221,9 +220,9 @@ GenericStatusCodeSmmEntry (
>    //
>    // Install SmmStatusCode Protocol
>    //
> -  Status = gSmst->SmmInstallProtocolInterface (
> +  Status = gMmst->MmInstallProtocolInterface (
>                      &Handle,
> -                    &gEfiSmmStatusCodeProtocolGuid,
> +                    &gEfiMmStatusCodeProtocolGuid,
>                      EFI_NATIVE_INTERFACE,
>                      &mSmmStatusCodeProtocol
>                      );
> diff --git
> a/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusC
> odeRouterStandaloneMm.c
> b/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusC
> odeRouterStandaloneMm.c
> new file mode 100644
> index 000000000000..501572719fdc
> --- /dev/null
> +++
> b/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusC
> ode
> +++ RouterStandaloneMm.c
> @@ -0,0 +1,33 @@
> +/** @file
> +  Report Status Code Router Driver which produces SMM Report Stataus
> +Code Handler Protocol
> +  and SMM Status Code Protocol.
> +
> +  Copyright (c) 2009 - 2018, Intel Corporation. All rights
> + reserved.<BR>  Copyright (c) Microsoft Corporation.
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include "ReportStatusCodeRouterCommon.h"
> +
> +/**
> +  Entry point of Generic Status Code Driver.
> +
> +  This function is the entry point of SMM Status Code Router .
> +  It produces SMM Report Stataus Code Handler and Status Code protocol.
> +
> +  @param  ImageHandle       The firmware allocated handle for the EFI image.
> +  @param  SystemTable       A pointer to the EFI System Table.
> +
> +  @retval EFI_SUCCESS       The entry point is executed successfully.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +GenericStatusCodeStandaloneMmEntry (
> +  IN EFI_HANDLE             ImageHandle,
> +  IN EFI_MM_SYSTEM_TABLE    *SystemTable
> +  )
> +{
> +  return GenericStatusCodeCommonEntry (); }
> diff --git
> a/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusC
> odeRouterTraditional.c
> b/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusC
> odeRouterTraditional.c
> new file mode 100644
> index 000000000000..360a0eef6b6d
> --- /dev/null
> +++
> b/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusC
> ode
> +++ RouterTraditional.c
> @@ -0,0 +1,33 @@
> +/** @file
> +  Report Status Code Router Driver which produces MM Report Stataus
> +Code Handler Protocol
> +  and MM Status Code Protocol.
> +
> +  Copyright (c) 2009 - 2018, Intel Corporation. All rights
> + reserved.<BR>  Copyright (c) Microsoft Corporation.
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include "ReportStatusCodeRouterCommon.h"
> +
> +/**
> +  Entry point of Generic Status Code Driver.
> +
> +  This function is the entry point of SMM Status Code Router .
> +  It produces SMM Report Stataus Code Handler and Status Code protocol.
> +
> +  @param  ImageHandle       The firmware allocated handle for the EFI image.
> +  @param  SystemTable       A pointer to the EFI System Table.
> +
> +  @retval EFI_SUCCESS       The entry point is executed successfully.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +GenericStatusCodeTraditionalEntry (
> +  IN EFI_HANDLE         ImageHandle,
> +  IN EFI_SYSTEM_TABLE   *SystemTable
> +  )
> +{
> +  return GenericStatusCodeCommonEntry (); }
> diff --git a/MdeModulePkg/MdeModulePkg.dsc
> b/MdeModulePkg/MdeModulePkg.dsc index dc85d108d958..84ad577c2851
> 100644
> --- a/MdeModulePkg/MdeModulePkg.dsc
> +++ b/MdeModulePkg/MdeModulePkg.dsc
> @@ -477,6 +477,7 @@ [Components.IA32, Components.X64]
> 
> MdeModulePkg/Library/SmmReportStatusCodeLib/StandaloneMmReportSt
> atusCodeLib.inf
> 
> MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSm
> m.inf
> 
> MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCod
> eRouterSmm.inf
> +
> +
> MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCod
> eRout
> + erStandaloneMm.inf
>    MdeModulePkg/Universal/LockBox/SmmLockBox/SmmLockBox.inf
> 
> MdeModulePkg/Library/SmmMemoryAllocationProfileLib/SmmMemoryAllo
> cationProfileLib.inf
> 
> MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/PiSmmCoreMem
> oryAllocationProfileLib.inf
> diff --git
> a/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusC
> odeRouterSmm.h
> b/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusC
> odeRouterCommon.h
> similarity index 70%
> rename from
> MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCod
> eRouterSmm.h
> rename to
> MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCod
> eRouterCommon.h
> index f8c48c62e790..f7962e773bb3 100644
> ---
> a/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusC
> odeRouterSmm.h
> +++
> b/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusC
> ode
> +++ RouterCommon.h
> @@ -6,28 +6,26 @@
> 
>  **/
> 
> -#ifndef __REPORT_STATUS_CODE_ROUTER_SMM_H__
> -#define __REPORT_STATUS_CODE_ROUTER_SMM_H__
> +#ifndef __REPORT_STATUS_CODE_ROUTER_COMMON_H__
> +#define __REPORT_STATUS_CODE_ROUTER_COMMON_H__
> 
> -
> -#include <Protocol/SmmReportStatusCodeHandler.h>
> -#include <Protocol/SmmStatusCode.h>
> +#include <Protocol/MmReportStatusCodeHandler.h>
> +#include <Protocol/MmStatusCode.h>
> 
>  #include <Library/BaseLib.h>
>  #include <Library/SynchronizationLib.h>  #include <Library/DebugLib.h>
> #include <Library/PcdLib.h> -#include <Library/UefiDriverEntryPoint.h> -
> #include <Library/SmmServicesTableLib.h>
> +#include <Library/MmServicesTableLib.h>
>  #include <Library/MemoryAllocationLib.h>
> 
> -#define SMM_RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE
> SIGNATURE_32 ('s', 'h', 'c', 'e')
> +#define MM_RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE
> SIGNATURE_32 ('s',
> +'h', 'c', 'e')
> 
>  typedef struct {
>    UINTN                         Signature;
> -  EFI_SMM_RSC_HANDLER_CALLBACK  RscHandlerCallback;
> +  EFI_MM_RSC_HANDLER_CALLBACK   RscHandlerCallback;
>    LIST_ENTRY                    Node;
> -} SMM_RSC_HANDLER_CALLBACK_ENTRY;
> +} MM_RSC_HANDLER_CALLBACK_ENTRY;
> 
>  /**
>    Register the callback function for ReportStatusCode() notification.
> @@ -48,7 +46,7 @@ typedef struct {
>  EFI_STATUS
>  EFIAPI
>  Register (
> -  IN EFI_SMM_RSC_HANDLER_CALLBACK   Callback
> +  IN EFI_MM_RSC_HANDLER_CALLBACK    Callback
>    );
> 
>  /**
> @@ -67,13 +65,13 @@ Register (
>  EFI_STATUS
>  EFIAPI
>  Unregister (
> -  IN EFI_SMM_RSC_HANDLER_CALLBACK Callback
> +  IN EFI_MM_RSC_HANDLER_CALLBACK  Callback
>    );
> 
>  /**
>    Provides an interface that a software module can call to report a status
> code.
> 
> -  @param  This             EFI_SMM_STATUS_CODE_PROTOCOL instance.
> +  @param  This             EFI_MM_RSC_HANDLER_CALLBACK instance.
>    @param  Type             Indicates the type of status code being reported.
>    @param  Value            Describes the current status of a hardware or
> software entity.
>                             This included information about the class and subclass that is
> used to @@ -92,12 +90,30 @@ Unregister (  EFI_STATUS  EFIAPI
> ReportDispatcher (
> -  IN CONST EFI_SMM_STATUS_CODE_PROTOCOL  *This,
> -  IN EFI_STATUS_CODE_TYPE                Type,
> +  IN CONST EFI_MM_STATUS_CODE_PROTOCOL   *This,
> +  IN EFI_STATUS_CODE_TYPE                CodeType,


I found that the above parameter does not match the name with its implementation in .C files.
Could you help to update it?


>    IN EFI_STATUS_CODE_VALUE               Value,
>    IN UINT32                              Instance,
> -  IN CONST EFI_GUID                      *CallerId  OPTIONAL,
> -  IN EFI_STATUS_CODE_DATA                *Data      OPTIONAL
> +  IN CONST EFI_GUID                      *CallerId,
> +  IN EFI_STATUS_CODE_DATA                *Data OPTIONAL
> +  );
> +
> +/**
> +  Entry point of Generic Status Code Driver.
> +
> +  This function is the entry point of SMM Status Code Router .
> +  It produces SMM Report Stataus Code Handler and Status Code protocol.
> +
> +  @param  ImageHandle       The firmware allocated handle for the EFI image.
> +  @param  SystemTable       A pointer to the EFI System Table.
> +
> +  @retval EFI_SUCCESS       The entry point is executed successfully.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +GenericStatusCodeCommonEntry (
> +  VOID
>    );


Could you help to remove the 'EFIAPI' for function GenericStatusCodeCommonEntry()?
And also update the function description comments for removed input parameters?

Best Regards,
Hao Wu


> 
>  #endif
> diff --git
> a/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusC
> odeRouterSmm.inf
> b/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusC
> odeRouterSmm.inf
> index 46fdcb7bf959..539badc4c755 100644
> ---
> a/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusC
> odeRouterSmm.inf
> +++
> b/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusC
> ode
> +++ RouterSmm.inf
> @@ -16,7 +16,7 @@ [Defines]
>    MODULE_TYPE                    = DXE_SMM_DRIVER
>    PI_SPECIFICATION_VERSION       = 0x0001000A
>    VERSION_STRING                 = 1.0
> -  ENTRY_POINT                    = GenericStatusCodeSmmEntry
> +  ENTRY_POINT                    = GenericStatusCodeTraditionalEntry
> 
>  #
>  # The following information is for reference only and not required by the
> build tools.
> @@ -25,15 +25,16 @@ [Defines]
>  #
> 
>  [Sources]
> -  ReportStatusCodeRouterSmm.c
> -  ReportStatusCodeRouterSmm.h
> +  ReportStatusCodeRouterCommon.c
> +  ReportStatusCodeRouterCommon.h
> +  ReportStatusCodeRouterTraditional.c
> 
>  [Packages]
>    MdePkg/MdePkg.dec
>    MdeModulePkg/MdeModulePkg.dec
> 
>  [LibraryClasses]
> -  SmmServicesTableLib
> +  MmServicesTableLib
>    UefiDriverEntryPoint
>    DebugLib
>    BaseLib
> @@ -41,8 +42,8 @@ [LibraryClasses]
>    MemoryAllocationLib
> 
>  [Protocols]
> -  gEfiSmmRscHandlerProtocolGuid               ## PRODUCES
> -  gEfiSmmStatusCodeProtocolGuid               ## PRODUCES
> +  gEfiMmRscHandlerProtocolGuid               ## PRODUCES
> +  gEfiMmStatusCodeProtocolGuid               ## PRODUCES
> 
>  [Depex]
>    TRUE
> diff --git
> a/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusC
> odeRouterStandaloneMm.inf
> b/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusC
> odeRouterStandaloneMm.inf
> new file mode 100644
> index 000000000000..f34b3e29d4ad
> --- /dev/null
> +++
> b/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusC
> ode
> +++ RouterStandaloneMm.inf
> @@ -0,0 +1,49 @@
> +## @file
> +#  Report Status Code Router Driver which produces SMM Report Stataus
> Code Handler Protocol and SMM Status Code Protocol.
> +#
> +#  Copyright (c) 2009 - 2018, Intel Corporation. All rights
> +reserved.<BR> #  Copyright (c) Microsoft Corporation.
> +#
> +#  SPDX-License-Identifier: BSD-2-Clause-Patent # # ##
> +
> +[Defines]
> +  INF_VERSION                    = 0x00010005
> +  BASE_NAME                      = ReportStatusCodeRouterStandaloneMm
> +  FILE_GUID                      = EAEEDEF9-ABE7-4B95-82B0-5A534C899B46
> +  MODULE_TYPE                    = MM_STANDALONE
> +  PI_SPECIFICATION_VERSION       = 0x00010032
> +  VERSION_STRING                 = 1.0
> +  ENTRY_POINT                    = GenericStatusCodeStandaloneMmEntry
> +
> +#
> +# The following information is for reference only and not required by the
> build tools.
> +#
> +#  VALID_ARCHITECTURES           = IA32 X64
> +#
> +
> +[Sources]
> +  ReportStatusCodeRouterCommon.c
> +  ReportStatusCodeRouterCommon.h
> +  ReportStatusCodeRouterStandaloneMm.c
> +
> +[Packages]
> +  MdePkg/MdePkg.dec
> +  MdeModulePkg/MdeModulePkg.dec
> +
> +[LibraryClasses]
> +  MmServicesTableLib
> +  StandaloneMmDriverEntryPoint
> +  DebugLib
> +  BaseLib
> +  SynchronizationLib
> +  MemoryAllocationLib
> +
> +[Protocols]
> +  gEfiMmRscHandlerProtocolGuid               ## PRODUCES
> +  gEfiMmStatusCodeProtocolGuid               ## PRODUCES
> +
> +[Depex]
> +  TRUE
> --
> 2.28.0.windows.1


^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [edk2-devel] [PATCH v1 06/15] MdeModulePkg: SmmReportStatusCodeLib: ReportStatusCodeLib in StandaloneMm
  2020-12-22  8:35   ` [edk2-devel] " Wu, Hao A
@ 2020-12-22 19:15     ` Kun Qin
  2020-12-23  6:09       ` Wu, Hao A
  0 siblings, 1 reply; 44+ messages in thread
From: Kun Qin @ 2020-12-22 19:15 UTC (permalink / raw)
  To: devel@edk2.groups.io, hao.a.wu@intel.com
  Cc: Wang, Jian J, Bi, Dandan, Liming Gao, Yao, Jiewen

[-- Attachment #1: Type: text/plain, Size: 14735 bytes --]

Hi Hao,

That was my original plan, but doing it might require a MmServiceTableLib instance for SMM_CORE type if PiSmmCore links in RSC lib (similar to PiSmmCoreSmmServicesTableLib). We can create such an instance just like PiSmmCoreSmmServicesTableLib, but the implementation will pull in gSmmCoreSmst as an external variable and cast it from `EFI_SMM_SYSTEM_TABLE2` to `EFI_MM_SYSTEM_TABLE`, which does not look clean. Thus I just abstract the routine to avoid it.

Please let me know if you have better ideas, I can add the change for next patch series.

Thanks,
Kun

From: Wu, Hao A<mailto:hao.a.wu@intel.com>
Sent: Tuesday, December 22, 2020 00:35
To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>; kun.q@outlook.com<mailto:kun.q@outlook.com>
Cc: Wang, Jian J<mailto:jian.j.wang@intel.com>; Bi, Dandan<mailto:dandan.bi@intel.com>; Liming Gao<mailto:gaoliming@byosoft.com.cn>; Yao, Jiewen<mailto:jiewen.yao@intel.com>
Subject: Re: [edk2-devel] [PATCH v1 06/15] MdeModulePkg: SmmReportStatusCodeLib: ReportStatusCodeLib in StandaloneMm

> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Kun Qin
> Sent: Saturday, December 19, 2020 2:50 AM
> To: devel@edk2.groups.io
> Cc: Wang, Jian J <jian.j.wang@intel.com>; Wu, Hao A <hao.a.wu@intel.com>;
> Bi, Dandan <dandan.bi@intel.com>; Liming Gao <gaoliming@byosoft.com.cn>
> Subject: [edk2-devel] [PATCH v1 06/15] MdeModulePkg:
> SmmReportStatusCodeLib: ReportStatusCodeLib in StandaloneMm
>
> This change added support of StandaloneMm for ReportStatusCodeLib. It
> adds a new instance of ReportStatusCodeLib for MM_STANDALONE type,
> and abstracts the references of gMmst and gSmst functionalities into
> separate files in order to link in proper Service Table for SMM core/drivers.


Sorry for a question.

Do you think it is feasible to use:
gMmst->MmLocateProtocol to locate gEfiMmStatusCodeProtocolGuid
and avoid introducing 2 separate implementations for internal function InternalLocateProtocol()?

Since I found that the definitions for gEfiMmStatusCodeProtocolGuid an gEfiSmmStatusCodeProtocolGuid are identical.

Best Regards,
Hao Wu


>
> Cc: Jian J Wang <jian.j.wang@intel.com>
> Cc: Hao A Wu <hao.a.wu@intel.com>
> Cc: Dandan Bi <dandan.bi@intel.com>
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
>
> Signed-off-by: Kun Qin <kun.q@outlook.com>
> ---
>  MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.c
> | 16 ++++----
>
> MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibSta
> ndaloneMm.c                                   | 39 ++++++++++++++++++++
>
> MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibTra
> ditional.c                                    | 39 ++++++++++++++++++++
>  MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.h
> | 37 +++++++++++++++++++
>
> MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLi
> b.inf                                          |  4 +-
>
> MdeModulePkg/Library/SmmReportStatusCodeLib/{SmmReportStatusCode
> Lib.inf => StandaloneMmReportStatusCodeLib.inf} | 17 +++++----
>  MdeModulePkg/MdeModulePkg.dsc
> |  1 +
>  7 files changed, 137 insertions(+), 16 deletions(-)
>
> diff --git
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.c
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.
> c
> index 3a1772538cdf..fb1769db9223 100644
> ---
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.c
> +++
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.
> c
> @@ -1,5 +1,5 @@
>  /** @file
> -  Report Status Code Library for SMM Phase.
> +  Report Status Code Library for MM Phase.
>
>    Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
>    SPDX-License-Identifier: BSD-2-Clause-Patent @@ -8,7 +8,7 @@
>
>  #include <Library/ReportStatusCodeLib.h>  #include <Library/DebugLib.h> -
> #include <Library/SmmServicesTableLib.h>
> +#include <Library/MmServicesTableLib.h>
>  #include <Library/BaseLib.h>
>  #include <Library/BaseMemoryLib.h>
>  #include <Library/PcdLib.h>
> @@ -16,10 +16,12 @@
>
>  #include <Guid/StatusCodeDataTypeId.h>
>  #include <Guid/StatusCodeDataTypeDebug.h> -#include
> <Protocol/SmmStatusCode.h>
> +#include <Protocol/MmStatusCode.h>
>
> -EFI_SMM_REPORT_STATUS_CODE     mReportStatusCode = NULL;
> -EFI_SMM_STATUS_CODE_PROTOCOL   *mStatusCodeProtocol = NULL;
> +#include "ReportStatusCodeLib.h"
> +
> +EFI_MM_REPORT_STATUS_CODE     mReportStatusCode = NULL;
> +EFI_MM_STATUS_CODE_PROTOCOL   *mStatusCodeProtocol = NULL;
>
>
>  /**
> @@ -29,14 +31,14 @@ EFI_SMM_STATUS_CODE_PROTOCOL
> *mStatusCodeProtocol = NULL;
>              NULL is returned if no status code service is available.
>
>  **/
> -EFI_SMM_REPORT_STATUS_CODE
> +EFI_MM_REPORT_STATUS_CODE
>  InternalGetReportStatusCode (
>    VOID
>    )
>  {
>    EFI_STATUS                    Status;
>
> -  Status = gSmst->SmmLocateProtocol (&gEfiSmmStatusCodeProtocolGuid,
> NULL, (VOID**)&mStatusCodeProtocol);
> +  Status = InternalLocateProtocol (&gEfiMmStatusCodeProtocolGuid, NULL,
> + (VOID**)&mStatusCodeProtocol);
>    if (!EFI_ERROR (Status) && mStatusCodeProtocol != NULL) {
>      return mStatusCodeProtocol->ReportStatusCode;
>    }
> diff --git
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibS
> tandaloneMm.c
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibS
> tandaloneMm.c
> new file mode 100644
> index 000000000000..fc47dffe9ffb
> --- /dev/null
> +++
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibS
> ta
> +++ ndaloneMm.c
> @@ -0,0 +1,39 @@
> +/** @file
> +  Abstraction layer for MM service table used by MM ReportStatusCodeLib.
> +
> +  Copyright (c) Microsoft Corporation.
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <PiMm.h>
> +
> +#include <Library/MmServicesTableLib.h>
> +
> +/**
> +  Returns the first protocol instance that matches the given protocol.
> +
> +  @param[in]  Protocol          Provides the protocol to search for.
> +  @param[in]  Registration      Optional registration key returned from
> +                                RegisterProtocolNotify().
> +  @param[out]  Interface        On return, a pointer to the first interface that
> matches Protocol and
> +                                Registration.
> +
> +  @retval EFI_SUCCESS           A protocol instance matching Protocol was
> found and returned in
> +                                Interface.
> +  @retval EFI_NOT_FOUND         No protocol instances were found that
> match Protocol and
> +                                Registration.
> +  @retval EFI_INVALID_PARAMETER Interface is NULL.
> +                                Protocol is NULL.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +InternalLocateProtocol (
> +  IN  EFI_GUID  *Protocol,
> +  IN  VOID      *Registration, OPTIONAL
> +  OUT VOID      **Interface
> +  )
> +{
> +  return gMmst->MmLocateProtocol (Protocol, Registration, Interface); }
> diff --git
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibT
> raditional.c
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibT
> raditional.c
> new file mode 100644
> index 000000000000..6b3a7c6051c5
> --- /dev/null
> +++
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibT
> ra
> +++ ditional.c
> @@ -0,0 +1,39 @@
> +/** @file
> +  Abstraction layer for SMM service table used by SMM
> ReportStatusCodeLib.
> +
> +  Copyright (c) Microsoft Corporation.
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <PiMm.h>
> +
> +#include <Library/SmmServicesTableLib.h>
> +
> +/**
> +  Returns the first protocol instance that matches the given protocol.
> +
> +  @param[in]  Protocol          Provides the protocol to search for.
> +  @param[in]  Registration      Optional registration key returned from
> +                                RegisterProtocolNotify().
> +  @param[out]  Interface        On return, a pointer to the first interface that
> matches Protocol and
> +                                Registration.
> +
> +  @retval EFI_SUCCESS           A protocol instance matching Protocol was
> found and returned in
> +                                Interface.
> +  @retval EFI_NOT_FOUND         No protocol instances were found that
> match Protocol and
> +                                Registration.
> +  @retval EFI_INVALID_PARAMETER Interface is NULL.
> +                                Protocol is NULL.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +InternalLocateProtocol (
> +  IN  EFI_GUID  *Protocol,
> +  IN  VOID      *Registration, OPTIONAL
> +  OUT VOID      **Interface
> +  )
> +{
> +  return gSmst->SmmLocateProtocol (Protocol, Registration, Interface);
> +}
> diff --git
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.
> h
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.
> h
> new file mode 100644
> index 000000000000..9a16741e64f6
> --- /dev/null
> +++
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.
> h
> @@ -0,0 +1,37 @@
> +/** @file
> +  Report Status Code Library for MM Phase.
> +
> +  Copyright (c) 2009 - 2018, Intel Corporation. All rights
> + reserved.<BR>
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#ifndef _MM_RSC_LIB_H_
> +#define _MM_RSC_LIB_H_
> +
> +/**
> +  Returns the first protocol instance that matches the given protocol.
> +
> +  @param[in]  Protocol          Provides the protocol to search for.
> +  @param[in]  Registration      Optional registration key returned from
> +                                RegisterProtocolNotify().
> +  @param[out]  Interface        On return, a pointer to the first interface that
> matches Protocol and
> +                                Registration.
> +
> +  @retval EFI_SUCCESS           A protocol instance matching Protocol was
> found and returned in
> +                                Interface.
> +  @retval EFI_NOT_FOUND         No protocol instances were found that
> match Protocol and
> +                                Registration.
> +  @retval EFI_INVALID_PARAMETER Interface is NULL.
> +                                Protocol is NULL.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +InternalLocateProtocol (
> +  IN  EFI_GUID  *Protocol,
> +  IN  VOID      *Registration, OPTIONAL
> +  OUT VOID      **Interface
> +  );
> +
> +#endif // _MM_RSC_LIB_H_
> diff --git
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCod
> eLib.inf
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCod
> eLib.inf
> index 72496bfababd..02dce09a199d 100644
> ---
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCod
> eLib.inf
> +++
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCod
> eLib
> +++ .inf
> @@ -28,6 +28,8 @@ [Defines]
>
>  [Sources]
>    ReportStatusCodeLib.c
> +  ReportStatusCodeLib.h
> +  ReportStatusCodeLibTraditional.c
>
>  [Packages]
>    MdePkg/MdePkg.dec
> @@ -45,7 +47,7 @@ [Guids]
>    gEfiStatusCodeDataTypeDebugGuid               ## SOMETIMES_CONSUMES
> ## UNDEFINED
>
>  [Protocols]
> -  gEfiSmmStatusCodeProtocolGuid                 ## CONSUMES
> +  gEfiMmStatusCodeProtocolGuid                  ## CONSUMES
>
>  [Pcd]
>    gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask  ##
> CONSUMES diff --git
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCod
> eLib.inf
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/StandaloneMmReport
> StatusCodeLib.inf
> similarity index 64%
> copy from
> MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLi
> b.inf
> copy to
> MdeModulePkg/Library/SmmReportStatusCodeLib/StandaloneMmReportSt
> atusCodeLib.inf
> index 72496bfababd..11ecc67fc4fa 100644
> ---
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCod
> eLib.inf
> +++
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/StandaloneMmReport
> Stat
> +++ usCodeLib.inf
> @@ -12,13 +12,12 @@
>
>  [Defines]
>    INF_VERSION                    = 0x00010005
> -  BASE_NAME                      = SmmReportStatusCodeLib
> -  MODULE_UNI_FILE                = SmmReportStatusCodeLib.uni
> -  FILE_GUID                      = 67089D19-B3D6-4d9e-A0EB-FEDC1F83A1EE
> -  MODULE_TYPE                    = DXE_SMM_DRIVER
> +  BASE_NAME                      = StandaloneMmReportStatusCodeLib
> +  FILE_GUID                      = 17C7FC8C-8C5D-497E-9C0E-C21255B30E04
> +  MODULE_TYPE                    = MM_STANDALONE
>    VERSION_STRING                 = 1.0
> -  PI_SPECIFICATION_VERSION       = 0x0001000A
> -  LIBRARY_CLASS                  = ReportStatusCodeLib|DXE_SMM_DRIVER
> SMM_CORE
> +  PI_SPECIFICATION_VERSION       = 0x00010032
> +  LIBRARY_CLASS                  = ReportStatusCodeLib|MM_STANDALONE
>
>  #
>  # The following information is for reference only and not required by the
> build tools.
> @@ -28,6 +27,8 @@ [Defines]
>
>  [Sources]
>    ReportStatusCodeLib.c
> +  ReportStatusCodeLib.h
> +  ReportStatusCodeLibStandaloneMm.c
>
>  [Packages]
>    MdePkg/MdePkg.dec
> @@ -36,7 +37,7 @@ [Packages]
>  [LibraryClasses]
>    PcdLib
>    BaseMemoryLib
> -  SmmServicesTableLib
> +  MmServicesTableLib
>    DebugLib
>    MemoryAllocationLib
>
> @@ -45,7 +46,7 @@ [Guids]
>    gEfiStatusCodeDataTypeDebugGuid               ## SOMETIMES_CONSUMES
> ## UNDEFINED
>
>  [Protocols]
> -  gEfiSmmStatusCodeProtocolGuid                 ## CONSUMES
> +  gEfiMmStatusCodeProtocolGuid                  ## CONSUMES
>
>  [Pcd]
>    gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask  ##
> CONSUMES diff --git a/MdeModulePkg/MdeModulePkg.dsc
> b/MdeModulePkg/MdeModulePkg.dsc index cd91a70b4fdd..05bf5fe08094
> 100644
> --- a/MdeModulePkg/MdeModulePkg.dsc
> +++ b/MdeModulePkg/MdeModulePkg.dsc
> @@ -473,6 +473,7 @@ [Components.IA32, Components.X64]
>    }
>
> MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.i
> nf
>
> MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLi
> b.inf
> +
> +
> MdeModulePkg/Library/SmmReportStatusCodeLib/StandaloneMmReportSt
> atusCo
> + deLib.inf
>
> MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSm
> m.inf
>
> MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCod
> eRouterSmm.inf
>    MdeModulePkg/Universal/LockBox/SmmLockBox/SmmLockBox.inf
> --
> 2.28.0.windows.1
>
>
>
>
>







[-- Attachment #2: Type: text/html, Size: 26241 bytes --]

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [edk2-devel] [PATCH v1 07/15] MdeModulePkg: FirmwarePerformanceDataTable: Added StandaloneMm support
  2020-12-22  8:36   ` Wu, Hao A
@ 2020-12-22 20:06     ` Kun Qin
  0 siblings, 0 replies; 44+ messages in thread
From: Kun Qin @ 2020-12-22 20:06 UTC (permalink / raw)
  To: devel@edk2.groups.io, hao.a.wu@intel.com
  Cc: Wang, Jian J, Bi, Dandan, Liming Gao, Yao, Jiewen


[-- Attachment #1.1: Type: text/plain, Size: 26640 bytes --]

Hi Hao,

Thanks for the feedback, I will remove the EFIAPI for this patch (as well as others you noted in other patches).

As per listing the driver under [Component.X64], this is because listing the driver under other section will trigger IA32 build, which needs a IA32 version of `MemLib`. I will modify “[PATCH v1 04/15] StandaloneMmPkg: StandaloneMmMemLib: Extends support for X64 architecture” accordingly to make MemLib cover IA32 architecture as well.

Thanks,
Kun


From: devel@edk2.groups.io <devel@edk2.groups.io> on behalf of Wu, Hao A <hao.a.wu@intel.com>
Sent: Tuesday, December 22, 2020 12:36:03 AM
To: Kun Qin <kun.q@outlook.com>; devel@edk2.groups.io <devel@edk2.groups.io>
Cc: Wang, Jian J <jian.j.wang@intel.com>; Bi, Dandan <dandan.bi@intel.com>; Liming Gao <gaoliming@byosoft.com.cn>; Yao, Jiewen <jiewen.yao@intel.com>
Subject: Re: [edk2-devel] [PATCH v1 07/15] MdeModulePkg: FirmwarePerformanceDataTable: Added StandaloneMm support

> -----Original Message-----
> From: Kun Qin <kun.q@outlook.com>
> Sent: Saturday, December 19, 2020 2:50 AM
> To: devel@edk2.groups.io
> Cc: Wang, Jian J <jian.j.wang@intel.com>; Wu, Hao A <hao.a.wu@intel.com>;
> Bi, Dandan <dandan.bi@intel.com>; Liming Gao <gaoliming@byosoft.com.cn>
> Subject: [PATCH v1 07/15] MdeModulePkg: FirmwarePerformanceDataTable:
> Added StandaloneMm support
>
> This change added support of FPDT driver under StandaloneMm. It replaces
> SMM version ReportStatusCode protocol with MM version. This patch also
> abstracts standalone and traditional MM interfaces into separate files to
> support each corresponding function prototypes and implementations.


Could you help to remove the 'EFIAPI' for functions:
  FirmwarePerformanceCommonEntryPoint()
  IsBufferOutsideMmValid()
I found that they are internal functions.

Another question I have is that is there any special consideration to list FirmwarePerformanceStandaloneMm.inf
under the [Components.X64] section in the DSC file?

Best Regards,
Hao Wu


>
> Cc: Jian J Wang <jian.j.wang@intel.com>
> Cc: Hao A Wu <hao.a.wu@intel.com>
> Cc: Dandan Bi <dandan.bi@intel.com>
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
>
> Signed-off-by: Kun Qin <kun.q@outlook.com>
> ---
>
> MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/{Firm
> warePerformanceSmm.c => FirmwarePerformanceCommon.c}           | 72
> ++++++++++----------
>
> MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Firm
> warePerformanceStandaloneMm.c                                   | 62
> +++++++++++++++++
>
> MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Firm
> warePerformanceTraditional.c                                    | 62 +++++++++++++++++
>  MdeModulePkg/MdeModulePkg.dsc
> |  2 +
>
> MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Firm
> warePerformanceCommon.h                                         | 55 +++++++++++++++
>
> MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Firm
> warePerformanceSmm.inf                                          | 11 +--
>
> MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/{Firm
> warePerformanceSmm.inf => FirmwarePerformanceStandaloneMm.inf} | 31
> ++++-----
>  7 files changed, 237 insertions(+), 58 deletions(-)
>
> diff --git
> a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fir
> mwarePerformanceSmm.c
> b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fir
> mwarePerformanceCommon.c
> similarity index 77%
> rename from
> MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Firm
> warePerformanceSmm.c
> rename to
> MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Firm
> warePerformanceCommon.c
> index d6c6e7693e4d..c2aa9455f9c4 100644
> ---
> a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fir
> mwarePerformanceSmm.c
> +++
> b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fir
> mwa
> +++ rePerformanceCommon.c
> @@ -1,11 +1,11 @@
>  /** @file
> -  This module collects performance data for SMM driver boot records and S3
> Suspend Performance Record.
> +  This module collects performance data for MM driver boot records and S3
> Suspend Performance Record.
>
>    This module registers report status code listener to collect performance
> data
> -  for SMM driver boot records and S3 Suspend Performance Record.
> +  for MM driver boot records and S3 Suspend Performance Record.
>
>    Caution: This module requires additional review when modified.
> -  This driver will have external input - communicate buffer in SMM mode.
> +  This driver will have external input - communicate buffer in MM mode.
>    This external input must be validated carefully to avoid security issue like
>    buffer overflow, integer overflow.
>
> @@ -16,13 +16,13 @@
>
>  **/
>
> -#include <PiSmm.h>
> +#include <PiMm.h>
>
> -#include <Protocol/SmmReportStatusCodeHandler.h>
> +#include <Protocol/MmReportStatusCodeHandler.h>
>
>  #include <Guid/FirmwarePerformance.h>
>
> -#include <Library/SmmServicesTableLib.h>
> +#include <Library/MmServicesTableLib.h>
>  #include <Library/BaseLib.h>
>  #include <Library/DebugLib.h>
>  #include <Library/TimerLib.h>
> @@ -30,23 +30,22 @@
>  #include <Library/PcdLib.h>
>  #include <Library/BaseMemoryLib.h>
>  #include <Library/MemoryAllocationLib.h> -#include
> <Library/UefiBootServicesTableLib.h>
>  #include <Library/SynchronizationLib.h> -#include <Library/SmmMemLib.h>
> +#include "FirmwarePerformanceCommon.h"
>
> -SMM_BOOT_PERFORMANCE_TABLE    *mSmmBootPerformanceTable =
> NULL;
> +SMM_BOOT_PERFORMANCE_TABLE    *mMmBootPerformanceTable =
> NULL;
>
> -EFI_SMM_RSC_HANDLER_PROTOCOL  *mRscHandlerProtocol    = NULL;
> +EFI_MM_RSC_HANDLER_PROTOCOL   *mRscHandlerProtocol    = NULL;
>  UINT64                        mSuspendStartTime       = 0;
>  BOOLEAN                       mS3SuspendLockBoxSaved  = FALSE;
>  UINT32                        mBootRecordSize = 0;
>  UINT8                         *mBootRecordBuffer = NULL;
>
> -SPIN_LOCK                     mSmmFpdtLock;
> -BOOLEAN                       mSmramIsOutOfResource = FALSE;
> +SPIN_LOCK                     mMmFpdtLock;
> +BOOLEAN                       mMmramIsOutOfResource = FALSE;
>
>  /**
> -  Report status code listener for SMM. This is used to record the
> performance
> +  Report status code listener for MM. This is used to record the
> + performance
>    data for S3 Suspend Start and S3 Suspend End in FPDT.
>
>    @param[in]  CodeType            Indicates the type of status code being
> reported.
> @@ -66,7 +65,7 @@ BOOLEAN                       mSmramIsOutOfResource = FALSE;
>  **/
>  EFI_STATUS
>  EFIAPI
> -FpdtStatusCodeListenerSmm (
> +FpdtStatusCodeListenerMm (
>    IN EFI_STATUS_CODE_TYPE     CodeType,
>    IN EFI_STATUS_CODE_VALUE    Value,
>    IN UINT32                   Instance,
> @@ -89,19 +88,19 @@ FpdtStatusCodeListenerSmm (
>    // Collect one or more Boot records in boot time
>    //
>    if (Data != NULL && CompareGuid (&Data->Type,
> &gEdkiiFpdtExtendedFirmwarePerformanceGuid)) {
> -    AcquireSpinLock (&mSmmFpdtLock);
> +    AcquireSpinLock (&mMmFpdtLock);
>      //
>      // Get the boot performance data.
>      //
> -    CopyMem (&mSmmBootPerformanceTable, Data + 1, Data->Size);
> -    mBootRecordBuffer = ((UINT8 *) (mSmmBootPerformanceTable)) +
> sizeof (SMM_BOOT_PERFORMANCE_TABLE);
> +    CopyMem (&mMmBootPerformanceTable, Data + 1, Data->Size);
> +    mBootRecordBuffer = ((UINT8 *) (mMmBootPerformanceTable)) + sizeof
> + (SMM_BOOT_PERFORMANCE_TABLE);
>
> -    ReleaseSpinLock (&mSmmFpdtLock);
> +    ReleaseSpinLock (&mMmFpdtLock);
>      return EFI_SUCCESS;
>    }
>
>    if (Data != NULL && CompareGuid (&Data->Type,
> &gEfiFirmwarePerformanceGuid)) {
> -    DEBUG ((DEBUG_ERROR, "FpdtStatusCodeListenerSmm: Performance
> data reported through gEfiFirmwarePerformanceGuid will not be collected
> by FirmwarePerformanceDataTableSmm\n"));
> +    DEBUG ((DEBUG_ERROR, "FpdtStatusCodeListenerMm: Performance
> data
> + reported through gEfiFirmwarePerformanceGuid will not be collected by
> + FirmwarePerformanceDataTableMm\n"));
>      return EFI_UNSUPPORTED;
>    }
>
> @@ -157,7 +156,7 @@ FpdtStatusCodeListenerSmm (
>  /**
>    Communication service SMI Handler entry.
>
> -  This SMI handler provides services for report SMM boot records.
> +  This SMI handler provides services for report MM boot records.
>
>    Caution: This function may receive untrusted input.
>    Communicate buffer and buffer size are external input, so this function will
> do basic validation.
> @@ -166,7 +165,7 @@ FpdtStatusCodeListenerSmm (
>    @param[in]     RegisterContext Points to an optional handler context which
> was specified when the
>                                   handler was registered.
>    @param[in, out] CommBuffer     A pointer to a collection of data in memory
> that will
> -                                 be conveyed from a non-SMM environment into an SMM
> environment.
> +                                 be conveyed from a non-MM environment into an MM
> environment.
>    @param[in, out] CommBufferSize The size of the CommBuffer.
>
>    @retval EFI_SUCCESS                         The interrupt was handled and quiesced.
> No other handlers
> @@ -207,8 +206,8 @@ FpdtSmiHandler (
>      return EFI_SUCCESS;
>    }
>
> -  if (!SmmIsBufferOutsideSmmValid ((UINTN)CommBuffer,
> TempCommBufferSize)) {
> -    DEBUG ((EFI_D_ERROR, "FpdtSmiHandler: SMM communication data
> buffer in SMRAM or overflow!\n"));
> +  if (!IsBufferOutsideMmValid ((UINTN)CommBuffer,
> TempCommBufferSize)) {
> +    DEBUG ((DEBUG_ERROR, "FpdtSmiHandler: MM communication data
> buffer
> + in MMRAM or overflow!\n"));
>      return EFI_SUCCESS;
>    }
>
> @@ -218,8 +217,8 @@ FpdtSmiHandler (
>
>    switch (SmmCommData->Function) {
>      case SMM_FPDT_FUNCTION_GET_BOOT_RECORD_SIZE :
> -      if (mSmmBootPerformanceTable != NULL) {
> -        mBootRecordSize = mSmmBootPerformanceTable->Header.Length -
> sizeof (SMM_BOOT_PERFORMANCE_TABLE);
> +      if (mMmBootPerformanceTable != NULL) {
> +        mBootRecordSize = mMmBootPerformanceTable->Header.Length -
> + sizeof (SMM_BOOT_PERFORMANCE_TABLE);
>        }
>        SmmCommData->BootRecordSize = mBootRecordSize;
>        break;
> @@ -244,8 +243,8 @@ FpdtSmiHandler (
>          BootRecordSize = mBootRecordSize - BootRecordOffset;
>        }
>        SmmCommData->BootRecordSize = BootRecordSize;
> -      if (!SmmIsBufferOutsideSmmValid ((UINTN)BootRecordData,
> BootRecordSize)) {
> -        DEBUG ((EFI_D_ERROR, "FpdtSmiHandler: SMM Data buffer in SMRAM
> or overflow!\n"));
> +      if (!IsBufferOutsideMmValid ((UINTN)BootRecordData, BootRecordSize))
> {
> +        DEBUG ((DEBUG_ERROR, "FpdtSmiHandler: MM Data buffer in
> MMRAM
> + or overflow!\n"));
>          Status = EFI_ACCESS_DENIED;
>          break;
>        }
> @@ -267,7 +266,7 @@ FpdtSmiHandler (
>  }
>
>  /**
> -  The module Entry Point of the Firmware Performance Data Table SMM
> driver.
> +  The module Entry Point of the Firmware Performance Data Table MM
> driver.
>
>    @param[in]  ImageHandle    The firmware allocated handle for the EFI
> image.
>    @param[in]  SystemTable    A pointer to the EFI System Table.
> @@ -278,9 +277,8 @@ FpdtSmiHandler (
>  **/
>  EFI_STATUS
>  EFIAPI
> -FirmwarePerformanceSmmEntryPoint (
> -  IN EFI_HANDLE          ImageHandle,
> -  IN EFI_SYSTEM_TABLE    *SystemTable
> +FirmwarePerformanceCommonEntryPoint (
> +  VOID
>    )
>  {
>    EFI_STATUS                Status;
> @@ -289,13 +287,13 @@ FirmwarePerformanceSmmEntryPoint (
>    //
>    // Initialize spin lock
>    //
> -  InitializeSpinLock (&mSmmFpdtLock);
> +  InitializeSpinLock (&mMmFpdtLock);
>
>    //
> -  // Get SMM Report Status Code Handler Protocol.
> +  // Get MM Report Status Code Handler Protocol.
>    //
> -  Status = gSmst->SmmLocateProtocol (
> -                    &gEfiSmmRscHandlerProtocolGuid,
> +  Status = gMmst->MmLocateProtocol (
> +                    &gEfiMmRscHandlerProtocolGuid,
>                      NULL,
>                      (VOID **) &mRscHandlerProtocol
>                      );
> @@ -304,14 +302,14 @@ FirmwarePerformanceSmmEntryPoint (
>    //
>    // Register report status code listener for BootRecords and S3 Suspend
> Start and End.
>    //
> -  Status = mRscHandlerProtocol->Register (FpdtStatusCodeListenerSmm);
> +  Status = mRscHandlerProtocol->Register (FpdtStatusCodeListenerMm);
>    ASSERT_EFI_ERROR (Status);
>
>    //
>    // Register SMI handler.
>    //
>    Handle = NULL;
> -  Status = gSmst->SmiHandlerRegister (FpdtSmiHandler,
> &gEfiFirmwarePerformanceGuid, &Handle);
> +  Status = gMmst->MmiHandlerRegister (FpdtSmiHandler,
> + &gEfiFirmwarePerformanceGuid, &Handle);
>    ASSERT_EFI_ERROR (Status);
>
>    return Status;
> diff --git
> a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fir
> mwarePerformanceStandaloneMm.c
> b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fir
> mwarePerformanceStandaloneMm.c
> new file mode 100644
> index 000000000000..2c4f40eceaea
> --- /dev/null
> +++
> b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fir
> mwa
> +++ rePerformanceStandaloneMm.c
> @@ -0,0 +1,62 @@
> +/** @file
> +  This module collects performance data for MM driver boot records and S3
> Suspend Performance Record.
> +
> +  This module registers report status code listener to collect
> + performance data  for MM driver boot records and S3 Suspend
> Performance Record.
> +
> +  Caution: This module requires additional review when modified.
> +  This driver will have external input - communicate buffer in MM mode.
> +  This external input must be validated carefully to avoid security
> + issue like  buffer overflow, integer overflow.
> +
> +  FpdtSmiHandler() will receive untrusted input and do basic validation.
> +
> +  Copyright (c) 2011 - 2018, Intel Corporation. All rights
> + reserved.<BR>  Copyright (c), Microsoft Corporation.
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <PiMm.h>
> +
> +#include <Library/StandaloneMmMemLib.h> #include
> +"FirmwarePerformanceCommon.h"
> +
> +/**
> +  This function is an abstraction layer for implementation specific Mm buffer
> validation routine.
> +
> +  @param Buffer  The buffer start address to be checked.
> +  @param Length  The buffer length to be checked.
> +
> +  @retval TRUE  This buffer is valid per processor architecture and not
> overlap with SMRAM.
> +  @retval FALSE This buffer is not valid per processor architecture or overlap
> with SMRAM.
> +**/
> +BOOLEAN
> +EFIAPI
> +IsBufferOutsideMmValid (
> +  IN EFI_PHYSICAL_ADDRESS  Buffer,
> +  IN UINT64                Length
> +  )
> +{
> +  return MmIsBufferOutsideMmValid (Buffer, Length); }
> +
> +/**
> +  The module Entry Point of the Firmware Performance Data Table MM
> driver.
> +
> +  @param[in]  ImageHandle    The firmware allocated handle for the EFI
> image.
> +  @param[in]  SystemTable    A pointer to the EFI System Table.
> +
> +  @retval EFI_SUCCESS    The entry point is executed successfully.
> +  @retval Other          Some error occurs when executing this entry point.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +FirmwarePerformanceStandaloneMmEntryPoint (
> +  IN EFI_HANDLE             ImageHandle,
> +  IN EFI_MM_SYSTEM_TABLE    *SystemTable
> +  )
> +{
> +  return FirmwarePerformanceCommonEntryPoint (); }
> diff --git
> a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fir
> mwarePerformanceTraditional.c
> b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fir
> mwarePerformanceTraditional.c
> new file mode 100644
> index 000000000000..507aabcb4e88
> --- /dev/null
> +++
> b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fir
> mwa
> +++ rePerformanceTraditional.c
> @@ -0,0 +1,62 @@
> +/** @file
> +  This module collects performance data for MM driver boot records and S3
> Suspend Performance Record.
> +
> +  This module registers report status code listener to collect
> + performance data  for MM driver boot records and S3 Suspend
> Performance Record.
> +
> +  Caution: This module requires additional review when modified.
> +  This driver will have external input - communicate buffer in MM mode.
> +  This external input must be validated carefully to avoid security
> + issue like  buffer overflow, integer overflow.
> +
> +  FpdtSmiHandler() will receive untrusted input and do basic validation.
> +
> +  Copyright (c) 2011 - 2018, Intel Corporation. All rights
> + reserved.<BR>  Copyright (c), Microsoft Corporation.
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <PiSmm.h>
> +
> +#include <Library/SmmMemLib.h>
> +#include "FirmwarePerformanceCommon.h"
> +
> +/**
> +  This function is an abstraction layer for implementation specific Mm buffer
> validation routine.
> +
> +  @param Buffer  The buffer start address to be checked.
> +  @param Length  The buffer length to be checked.
> +
> +  @retval TRUE  This buffer is valid per processor architecture and not
> overlap with SMRAM.
> +  @retval FALSE This buffer is not valid per processor architecture or overlap
> with SMRAM.
> +**/
> +BOOLEAN
> +EFIAPI
> +IsBufferOutsideMmValid (
> +  IN EFI_PHYSICAL_ADDRESS  Buffer,
> +  IN UINT64                Length
> +  )
> +{
> +  return SmmIsBufferOutsideSmmValid (Buffer, Length); }
> +
> +/**
> +  The module Entry Point of the Firmware Performance Data Table MM
> driver.
> +
> +  @param[in]  ImageHandle    The firmware allocated handle for the EFI
> image.
> +  @param[in]  SystemTable    A pointer to the EFI System Table.
> +
> +  @retval EFI_SUCCESS    The entry point is executed successfully.
> +  @retval Other          Some error occurs when executing this entry point.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +FirmwarePerformanceSmmEntryPoint (
> +  IN EFI_HANDLE          ImageHandle,
> +  IN EFI_SYSTEM_TABLE    *SystemTable
> +  )
> +{
> +  return FirmwarePerformanceCommonEntryPoint (); }
> diff --git a/MdeModulePkg/MdeModulePkg.dsc
> b/MdeModulePkg/MdeModulePkg.dsc index 05bf5fe08094..dc85d108d958
> 100644
> --- a/MdeModulePkg/MdeModulePkg.dsc
> +++ b/MdeModulePkg/MdeModulePkg.dsc
> @@ -168,6 +168,7 @@ [LibraryClasses.common.MM_STANDALONE]
>
> StandaloneMmDriverEntryPoint|MdePkg/Library/StandaloneMmDriverEntry
> Point/StandaloneMmDriverEntryPoint.inf
>
> MmServicesTableLib|MdePkg/Library/StandaloneMmServicesTableLib/Stan
> daloneMmServicesTableLib.inf
>
> LockBoxLib|MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxStandalo
> neMmLib.inf
> +
> +
> MemLib|StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMm
> MemLib.i
> + nf
>
>  [LibraryClasses.ARM, LibraryClasses.AARCH64]
>    ArmLib|ArmPkg/Library/ArmLib/ArmBaseLib.inf
> @@ -501,6 +502,7 @@ [Components.IA32, Components.X64]
>
>  [Components.X64]
>    MdeModulePkg/Universal/CapsulePei/CapsuleX64.inf
> +
> +
> MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Firm
> warePe
> + rformanceStandaloneMm.inf
>
>  [BuildOptions]
>
> diff --git
> a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fir
> mwarePerformanceCommon.h
> b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fir
> mwarePerformanceCommon.h
> new file mode 100644
> index 000000000000..ba01e28f2493
> --- /dev/null
> +++
> b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fir
> mwa
> +++ rePerformanceCommon.h
> @@ -0,0 +1,55 @@
> +/** @file
> +  This module collects performance data for SMM driver boot records and S3
> Suspend Performance Record.
> +
> +  This module registers report status code listener to collect
> + performance data  for SMM driver boot records and S3 Suspend
> Performance Record.
> +
> +  Caution: This module requires additional review when modified.
> +  This driver will have external input - communicate buffer in SMM mode.
> +  This external input must be validated carefully to avoid security
> + issue like  buffer overflow, integer overflow.
> +
> +  FpdtSmiHandler() will receive untrusted input and do basic validation.
> +
> +  Copyright (c) 2011 - 2018, Intel Corporation. All rights
> + reserved.<BR>  Copyright (c), Microsoft Corporation.
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#ifndef _FW_PERF_COMMON_H_
> +#define _FW_PERF_COMMON_H_
> +
> +/**
> +  This function is an abstraction layer for implementation specific Mm buffer
> validation routine.
> +
> +  @param Buffer  The buffer start address to be checked.
> +  @param Length  The buffer length to be checked.
> +
> +  @retval TRUE  This buffer is valid per processor architecture and not
> overlap with SMRAM.
> +  @retval FALSE This buffer is not valid per processor architecture or overlap
> with SMRAM.
> +**/
> +BOOLEAN
> +EFIAPI
> +IsBufferOutsideMmValid (
> +  IN EFI_PHYSICAL_ADDRESS  Buffer,
> +  IN UINT64                Length
> +  );
> +
> +/**
> +  The module Entry Point of the Firmware Performance Data Table MM
> driver.
> +
> +  @param[in]  ImageHandle    The firmware allocated handle for the EFI
> image.
> +  @param[in]  SystemTable    A pointer to the EFI System Table.
> +
> +  @retval EFI_SUCCESS    The entry point is executed successfully.
> +  @retval Other          Some error occurs when executing this entry point.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +FirmwarePerformanceCommonEntryPoint (
> +  VOID
> +  );
> +
> +#endif // _FW_PERF_COMMON_H_
> diff --git
> a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fir
> mwarePerformanceSmm.inf
> b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fir
> mwarePerformanceSmm.inf
> index 618cbd56ca59..b7194bd899dd 100644
> ---
> a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fir
> mwarePerformanceSmm.inf
> +++
> b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fir
> mwa
> +++ rePerformanceSmm.inf
> @@ -26,7 +26,9 @@ [Defines]
>  #
>
>  [Sources]
> -  FirmwarePerformanceSmm.c
> +  FirmwarePerformanceCommon.c
> +  FirmwarePerformanceCommon.h
> +  FirmwarePerformanceTraditional.c
>
>  [Packages]
>    MdePkg/MdePkg.dec
> @@ -34,7 +36,7 @@ [Packages]
>
>  [LibraryClasses]
>    UefiDriverEntryPoint
> -  SmmServicesTableLib
> +  MmServicesTableLib
>    BaseLib
>    DebugLib
>    TimerLib
> @@ -42,12 +44,11 @@ [LibraryClasses]
>    PcdLib
>    BaseMemoryLib
>    MemoryAllocationLib
> -  UefiBootServicesTableLib
>    SynchronizationLib
>    SmmMemLib
>
>  [Protocols]
> -  gEfiSmmRscHandlerProtocolGuid                 ## CONSUMES
> +  gEfiMmRscHandlerProtocolGuid                 ## CONSUMES
>
>  [Guids]
>    ## SOMETIMES_PRODUCES   ## UNDEFINED # SaveLockBox
> @@ -61,7 +62,7 @@ [Pcd]
>    gEfiMdeModulePkgTokenSpaceGuid.PcdProgressCodeS3SuspendEnd    ##
> CONSUMES
>
>  [Depex]
> -  gEfiSmmRscHandlerProtocolGuid
> +  gEfiMmRscHandlerProtocolGuid
>
>  [UserExtensions.TianoCore."ExtraFiles"]
>    FirmwarePerformanceSmmExtra.uni
> diff --git
> a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fir
> mwarePerformanceSmm.inf
> b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fir
> mwarePerformanceStandaloneMm.inf
> similarity index 65%
> copy from
> MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Firm
> warePerformanceSmm.inf
> copy to
> MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Firm
> warePerformanceStandaloneMm.inf
> index 618cbd56ca59..e6aad88be0ef 100644
> ---
> a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fir
> mwarePerformanceSmm.inf
> +++
> b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/Fir
> mwa
> +++ rePerformanceStandaloneMm.inf
> @@ -5,19 +5,19 @@
>  #  for SMM boot performance records and S3 Suspend Performance Record.
>  #
>  #  Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
> +#  Copyright (c) Microsoft Corporation.
>  #  SPDX-License-Identifier: BSD-2-Clause-Patent  #  ##
>
>  [Defines]
>    INF_VERSION                    = 0x00010005
> -  BASE_NAME                      = FirmwarePerformanceSmm
> -  MODULE_UNI_FILE                = FirmwarePerformanceSmm.uni
> -  FILE_GUID                      = 044310AB-77FD-402a-AF1A-87D4120E7329
> -  MODULE_TYPE                    = DXE_SMM_DRIVER
> +  BASE_NAME                      = FirmwarePerformanceStandaloneMm
> +  FILE_GUID                      = 827AC29D-E52D-4B1A-874A-C6577E0699CF
> +  MODULE_TYPE                    = MM_STANDALONE
>    VERSION_STRING                 = 1.0
> -  PI_SPECIFICATION_VERSION       = 0x0001000A
> -  ENTRY_POINT                    = FirmwarePerformanceSmmEntryPoint
> +  PI_SPECIFICATION_VERSION       = 0x00010032
> +  ENTRY_POINT                    = FirmwarePerformanceStandaloneMmEntryPoint
>
>  #
>  # The following information is for reference only and not required by the
> build tools.
> @@ -26,15 +26,18 @@ [Defines]
>  #
>
>  [Sources]
> -  FirmwarePerformanceSmm.c
> +  FirmwarePerformanceCommon.c
> +  FirmwarePerformanceCommon.h
> +  FirmwarePerformanceStandaloneMm.c
>
>  [Packages]
>    MdePkg/MdePkg.dec
>    MdeModulePkg/MdeModulePkg.dec
> +  StandaloneMmPkg/StandaloneMmPkg.dec
>
>  [LibraryClasses]
> -  UefiDriverEntryPoint
> -  SmmServicesTableLib
> +  StandaloneMmDriverEntryPoint
> +  MmServicesTableLib
>    BaseLib
>    DebugLib
>    TimerLib
> @@ -42,12 +45,11 @@ [LibraryClasses]
>    PcdLib
>    BaseMemoryLib
>    MemoryAllocationLib
> -  UefiBootServicesTableLib
>    SynchronizationLib
> -  SmmMemLib
> +  MemLib
>
>  [Protocols]
> -  gEfiSmmRscHandlerProtocolGuid                 ## CONSUMES
> +  gEfiMmRscHandlerProtocolGuid                 ## CONSUMES
>
>  [Guids]
>    ## SOMETIMES_PRODUCES   ## UNDEFINED # SaveLockBox
> @@ -61,7 +63,4 @@ [Pcd]
>    gEfiMdeModulePkgTokenSpaceGuid.PcdProgressCodeS3SuspendEnd    ##
> CONSUMES
>
>  [Depex]
> -  gEfiSmmRscHandlerProtocolGuid
> -
> -[UserExtensions.TianoCore."ExtraFiles"]
> -  FirmwarePerformanceSmmExtra.uni
> +  gEfiMmRscHandlerProtocolGuid
> --
> 2.28.0.windows.1






[-- Attachment #1.2: Type: text/html, Size: 43361 bytes --]

[-- Attachment #2: E86BA3DA0C6844F8BBD99EC4C8136AF2.png --]
[-- Type: image/png, Size: 136 bytes --]

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [edk2-devel] [PATCH v1 06/15] MdeModulePkg: SmmReportStatusCodeLib: ReportStatusCodeLib in StandaloneMm
  2020-12-22 19:15     ` Kun Qin
@ 2020-12-23  6:09       ` Wu, Hao A
  2020-12-24  1:53         ` 回复: " gaoliming
  0 siblings, 1 reply; 44+ messages in thread
From: Wu, Hao A @ 2020-12-23  6:09 UTC (permalink / raw)
  To: devel@edk2.groups.io, kun.q@outlook.com, Liming Gao, Yao, Jiewen
  Cc: Wang, Jian J, Bi, Dandan

[-- Attachment #1: Type: text/plain, Size: 15762 bytes --]

Hello Kun,

Got it, thanks for the explanation. My preference is the same with your current proposal in the patch.


Hello Liming and Jiewen,

Do you have comments for this case? Thanks in advance.

Best Regards,
Hao Wu

From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Kun Qin
Sent: Wednesday, December 23, 2020 3:15 AM
To: devel@edk2.groups.io; Wu, Hao A <hao.a.wu@intel.com>
Cc: Wang, Jian J <jian.j.wang@intel.com>; Bi, Dandan <dandan.bi@intel.com>; Liming Gao <gaoliming@byosoft.com.cn>; Yao, Jiewen <jiewen.yao@intel.com>
Subject: Re: [edk2-devel] [PATCH v1 06/15] MdeModulePkg: SmmReportStatusCodeLib: ReportStatusCodeLib in StandaloneMm

Hi Hao,

That was my original plan, but doing it might require a MmServiceTableLib instance for SMM_CORE type if PiSmmCore links in RSC lib (similar to PiSmmCoreSmmServicesTableLib). We can create such an instance just like PiSmmCoreSmmServicesTableLib, but the implementation will pull in gSmmCoreSmst as an external variable and cast it from `EFI_SMM_SYSTEM_TABLE2` to `EFI_MM_SYSTEM_TABLE`, which does not look clean. Thus I just abstract the routine to avoid it.

Please let me know if you have better ideas, I can add the change for next patch series.

Thanks,
Kun

From: Wu, Hao A<mailto:hao.a.wu@intel.com>
Sent: Tuesday, December 22, 2020 00:35
To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>; kun.q@outlook.com<mailto:kun.q@outlook.com>
Cc: Wang, Jian J<mailto:jian.j.wang@intel.com>; Bi, Dandan<mailto:dandan.bi@intel.com>; Liming Gao<mailto:gaoliming@byosoft.com.cn>; Yao, Jiewen<mailto:jiewen.yao@intel.com>
Subject: Re: [edk2-devel] [PATCH v1 06/15] MdeModulePkg: SmmReportStatusCodeLib: ReportStatusCodeLib in StandaloneMm

> -----Original Message-----
> From: devel@edk2.groups.io<mailto:devel@edk2.groups.io> <devel@edk2.groups.io<mailto:devel@edk2.groups.io>> On Behalf Of Kun Qin
> Sent: Saturday, December 19, 2020 2:50 AM
> To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>
> Cc: Wang, Jian J <jian.j.wang@intel.com<mailto:jian.j.wang@intel.com>>; Wu, Hao A <hao.a.wu@intel.com<mailto:hao.a.wu@intel.com>>;
> Bi, Dandan <dandan.bi@intel.com<mailto:dandan.bi@intel.com>>; Liming Gao <gaoliming@byosoft.com.cn<mailto:gaoliming@byosoft.com.cn>>
> Subject: [edk2-devel] [PATCH v1 06/15] MdeModulePkg:
> SmmReportStatusCodeLib: ReportStatusCodeLib in StandaloneMm
>
> This change added support of StandaloneMm for ReportStatusCodeLib. It
> adds a new instance of ReportStatusCodeLib for MM_STANDALONE type,
> and abstracts the references of gMmst and gSmst functionalities into
> separate files in order to link in proper Service Table for SMM core/drivers.


Sorry for a question.

Do you think it is feasible to use:
gMmst->MmLocateProtocol to locate gEfiMmStatusCodeProtocolGuid
and avoid introducing 2 separate implementations for internal function InternalLocateProtocol()?

Since I found that the definitions for gEfiMmStatusCodeProtocolGuid an gEfiSmmStatusCodeProtocolGuid are identical.

Best Regards,
Hao Wu


>
> Cc: Jian J Wang <jian.j.wang@intel.com<mailto:jian.j.wang@intel.com>>
> Cc: Hao A Wu <hao.a.wu@intel.com<mailto:hao.a.wu@intel.com>>
> Cc: Dandan Bi <dandan.bi@intel.com<mailto:dandan.bi@intel.com>>
> Cc: Liming Gao <gaoliming@byosoft.com.cn<mailto:gaoliming@byosoft.com.cn>>
>
> Signed-off-by: Kun Qin <kun.q@outlook.com<mailto:kun.q@outlook.com>>
> ---
>  MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.c
> | 16 ++++----
>
> MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibSta
> ndaloneMm.c                                   | 39 ++++++++++++++++++++
>
> MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibTra
> ditional.c                                    | 39 ++++++++++++++++++++
>  MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.h
> | 37 +++++++++++++++++++
>
> MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLi
> b.inf                                          |  4 +-
>
> MdeModulePkg/Library/SmmReportStatusCodeLib/{SmmReportStatusCode
> Lib.inf => StandaloneMmReportStatusCodeLib.inf} | 17 +++++----
>  MdeModulePkg/MdeModulePkg.dsc
> |  1 +
>  7 files changed, 137 insertions(+), 16 deletions(-)
>
> diff --git
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.c
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.
> c
> index 3a1772538cdf..fb1769db9223 100644
> ---
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.c
> +++
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.
> c
> @@ -1,5 +1,5 @@
>  /** @file
> -  Report Status Code Library for SMM Phase.
> +  Report Status Code Library for MM Phase.
>
>    Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
>    SPDX-License-Identifier: BSD-2-Clause-Patent @@ -8,7 +8,7 @@
>
>  #include <Library/ReportStatusCodeLib.h>  #include <Library/DebugLib.h> -
> #include <Library/SmmServicesTableLib.h>
> +#include <Library/MmServicesTableLib.h>
>  #include <Library/BaseLib.h>
>  #include <Library/BaseMemoryLib.h>
>  #include <Library/PcdLib.h>
> @@ -16,10 +16,12 @@
>
>  #include <Guid/StatusCodeDataTypeId.h>
>  #include <Guid/StatusCodeDataTypeDebug.h> -#include
> <Protocol/SmmStatusCode.h>
> +#include <Protocol/MmStatusCode.h>
>
> -EFI_SMM_REPORT_STATUS_CODE     mReportStatusCode = NULL;
> -EFI_SMM_STATUS_CODE_PROTOCOL   *mStatusCodeProtocol = NULL;
> +#include "ReportStatusCodeLib.h"
> +
> +EFI_MM_REPORT_STATUS_CODE     mReportStatusCode = NULL;
> +EFI_MM_STATUS_CODE_PROTOCOL   *mStatusCodeProtocol = NULL;
>
>
>  /**
> @@ -29,14 +31,14 @@ EFI_SMM_STATUS_CODE_PROTOCOL
> *mStatusCodeProtocol = NULL;
>              NULL is returned if no status code service is available.
>
>  **/
> -EFI_SMM_REPORT_STATUS_CODE
> +EFI_MM_REPORT_STATUS_CODE
>  InternalGetReportStatusCode (
>    VOID
>    )
>  {
>    EFI_STATUS                    Status;
>
> -  Status = gSmst->SmmLocateProtocol (&gEfiSmmStatusCodeProtocolGuid,
> NULL, (VOID**)&mStatusCodeProtocol);
> +  Status = InternalLocateProtocol (&gEfiMmStatusCodeProtocolGuid, NULL,
> + (VOID**)&mStatusCodeProtocol);
>    if (!EFI_ERROR (Status) && mStatusCodeProtocol != NULL) {
>      return mStatusCodeProtocol->ReportStatusCode;
>    }
> diff --git
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibS
> tandaloneMm.c
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibS
> tandaloneMm.c
> new file mode 100644
> index 000000000000..fc47dffe9ffb
> --- /dev/null
> +++
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibS
> ta
> +++ ndaloneMm.c
> @@ -0,0 +1,39 @@
> +/** @file
> +  Abstraction layer for MM service table used by MM ReportStatusCodeLib.
> +
> +  Copyright (c) Microsoft Corporation.
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <PiMm.h>
> +
> +#include <Library/MmServicesTableLib.h>
> +
> +/**
> +  Returns the first protocol instance that matches the given protocol.
> +
> +  @param[in]  Protocol          Provides the protocol to search for.
> +  @param[in]  Registration      Optional registration key returned from
> +                                RegisterProtocolNotify().
> +  @param[out]  Interface        On return, a pointer to the first interface that
> matches Protocol and
> +                                Registration.
> +
> +  @retval EFI_SUCCESS           A protocol instance matching Protocol was
> found and returned in
> +                                Interface.
> +  @retval EFI_NOT_FOUND         No protocol instances were found that
> match Protocol and
> +                                Registration.
> +  @retval EFI_INVALID_PARAMETER Interface is NULL.
> +                                Protocol is NULL.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +InternalLocateProtocol (
> +  IN  EFI_GUID  *Protocol,
> +  IN  VOID      *Registration, OPTIONAL
> +  OUT VOID      **Interface
> +  )
> +{
> +  return gMmst->MmLocateProtocol (Protocol, Registration, Interface); }
> diff --git
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibT
> raditional.c
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibT
> raditional.c
> new file mode 100644
> index 000000000000..6b3a7c6051c5
> --- /dev/null
> +++
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibT
> ra
> +++ ditional.c
> @@ -0,0 +1,39 @@
> +/** @file
> +  Abstraction layer for SMM service table used by SMM
> ReportStatusCodeLib.
> +
> +  Copyright (c) Microsoft Corporation.
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <PiMm.h>
> +
> +#include <Library/SmmServicesTableLib.h>
> +
> +/**
> +  Returns the first protocol instance that matches the given protocol.
> +
> +  @param[in]  Protocol          Provides the protocol to search for.
> +  @param[in]  Registration      Optional registration key returned from
> +                                RegisterProtocolNotify().
> +  @param[out]  Interface        On return, a pointer to the first interface that
> matches Protocol and
> +                                Registration.
> +
> +  @retval EFI_SUCCESS           A protocol instance matching Protocol was
> found and returned in
> +                                Interface.
> +  @retval EFI_NOT_FOUND         No protocol instances were found that
> match Protocol and
> +                                Registration.
> +  @retval EFI_INVALID_PARAMETER Interface is NULL.
> +                                Protocol is NULL.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +InternalLocateProtocol (
> +  IN  EFI_GUID  *Protocol,
> +  IN  VOID      *Registration, OPTIONAL
> +  OUT VOID      **Interface
> +  )
> +{
> +  return gSmst->SmmLocateProtocol (Protocol, Registration, Interface);
> +}
> diff --git
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.
> h
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.
> h
> new file mode 100644
> index 000000000000..9a16741e64f6
> --- /dev/null
> +++
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.
> h
> @@ -0,0 +1,37 @@
> +/** @file
> +  Report Status Code Library for MM Phase.
> +
> +  Copyright (c) 2009 - 2018, Intel Corporation. All rights
> + reserved.<BR>
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#ifndef _MM_RSC_LIB_H_
> +#define _MM_RSC_LIB_H_
> +
> +/**
> +  Returns the first protocol instance that matches the given protocol.
> +
> +  @param[in]  Protocol          Provides the protocol to search for.
> +  @param[in]  Registration      Optional registration key returned from
> +                                RegisterProtocolNotify().
> +  @param[out]  Interface        On return, a pointer to the first interface that
> matches Protocol and
> +                                Registration.
> +
> +  @retval EFI_SUCCESS           A protocol instance matching Protocol was
> found and returned in
> +                                Interface.
> +  @retval EFI_NOT_FOUND         No protocol instances were found that
> match Protocol and
> +                                Registration.
> +  @retval EFI_INVALID_PARAMETER Interface is NULL.
> +                                Protocol is NULL.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +InternalLocateProtocol (
> +  IN  EFI_GUID  *Protocol,
> +  IN  VOID      *Registration, OPTIONAL
> +  OUT VOID      **Interface
> +  );
> +
> +#endif // _MM_RSC_LIB_H_
> diff --git
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCod
> eLib.inf
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCod
> eLib.inf
> index 72496bfababd..02dce09a199d 100644
> ---
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCod
> eLib.inf
> +++
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCod
> eLib
> +++ .inf
> @@ -28,6 +28,8 @@ [Defines]
>
>  [Sources]
>    ReportStatusCodeLib.c
> +  ReportStatusCodeLib.h
> +  ReportStatusCodeLibTraditional.c
>
>  [Packages]
>    MdePkg/MdePkg.dec
> @@ -45,7 +47,7 @@ [Guids]
>    gEfiStatusCodeDataTypeDebugGuid               ## SOMETIMES_CONSUMES
> ## UNDEFINED
>
>  [Protocols]
> -  gEfiSmmStatusCodeProtocolGuid                 ## CONSUMES
> +  gEfiMmStatusCodeProtocolGuid                  ## CONSUMES
>
>  [Pcd]
>    gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask  ##
> CONSUMES diff --git
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCod
> eLib.inf
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/StandaloneMmReport
> StatusCodeLib.inf
> similarity index 64%
> copy from
> MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLi
> b.inf
> copy to
> MdeModulePkg/Library/SmmReportStatusCodeLib/StandaloneMmReportSt
> atusCodeLib.inf
> index 72496bfababd..11ecc67fc4fa 100644
> ---
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCod
> eLib.inf
> +++
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/StandaloneMmReport
> Stat
> +++ usCodeLib.inf
> @@ -12,13 +12,12 @@
>
>  [Defines]
>    INF_VERSION                    = 0x00010005
> -  BASE_NAME                      = SmmReportStatusCodeLib
> -  MODULE_UNI_FILE                = SmmReportStatusCodeLib.uni
> -  FILE_GUID                      = 67089D19-B3D6-4d9e-A0EB-FEDC1F83A1EE
> -  MODULE_TYPE                    = DXE_SMM_DRIVER
> +  BASE_NAME                      = StandaloneMmReportStatusCodeLib
> +  FILE_GUID                      = 17C7FC8C-8C5D-497E-9C0E-C21255B30E04
> +  MODULE_TYPE                    = MM_STANDALONE
>    VERSION_STRING                 = 1.0
> -  PI_SPECIFICATION_VERSION       = 0x0001000A
> -  LIBRARY_CLASS                  = ReportStatusCodeLib|DXE_SMM_DRIVER
> SMM_CORE
> +  PI_SPECIFICATION_VERSION       = 0x00010032
> +  LIBRARY_CLASS                  = ReportStatusCodeLib|MM_STANDALONE
>
>  #
>  # The following information is for reference only and not required by the
> build tools.
> @@ -28,6 +27,8 @@ [Defines]
>
>  [Sources]
>    ReportStatusCodeLib.c
> +  ReportStatusCodeLib.h
> +  ReportStatusCodeLibStandaloneMm.c
>
>  [Packages]
>    MdePkg/MdePkg.dec
> @@ -36,7 +37,7 @@ [Packages]
>  [LibraryClasses]
>    PcdLib
>    BaseMemoryLib
> -  SmmServicesTableLib
> +  MmServicesTableLib
>    DebugLib
>    MemoryAllocationLib
>
> @@ -45,7 +46,7 @@ [Guids]
>    gEfiStatusCodeDataTypeDebugGuid               ## SOMETIMES_CONSUMES
> ## UNDEFINED
>
>  [Protocols]
> -  gEfiSmmStatusCodeProtocolGuid                 ## CONSUMES
> +  gEfiMmStatusCodeProtocolGuid                  ## CONSUMES
>
>  [Pcd]
>    gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask  ##
> CONSUMES diff --git a/MdeModulePkg/MdeModulePkg.dsc
> b/MdeModulePkg/MdeModulePkg.dsc index cd91a70b4fdd..05bf5fe08094
> 100644
> --- a/MdeModulePkg/MdeModulePkg.dsc
> +++ b/MdeModulePkg/MdeModulePkg.dsc
> @@ -473,6 +473,7 @@ [Components.IA32, Components.X64]
>    }
>
> MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.i
> nf
>
> MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLi
> b.inf
> +
> +
> MdeModulePkg/Library/SmmReportStatusCodeLib/StandaloneMmReportSt
> atusCo
> + deLib.inf
>
> MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSm
> m.inf
>
> MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCod
> eRouterSmm.inf
>    MdeModulePkg/Universal/LockBox/SmmLockBox/SmmLockBox.inf
> --
> 2.28.0.windows.1
>
>
>
>
>







[-- Attachment #2: Type: text/html, Size: 28781 bytes --]

^ permalink raw reply	[flat|nested] 44+ messages in thread

* 回复: [edk2-devel] [PATCH v1 06/15] MdeModulePkg: SmmReportStatusCodeLib: ReportStatusCodeLib in StandaloneMm
  2020-12-23  6:09       ` Wu, Hao A
@ 2020-12-24  1:53         ` gaoliming
  2020-12-24  9:11           ` Kun Qin
  0 siblings, 1 reply; 44+ messages in thread
From: gaoliming @ 2020-12-24  1:53 UTC (permalink / raw)
  To: devel, hao.a.wu, kun.q, 'Yao, Jiewen'
  Cc: 'Wang, Jian J', 'Bi, Dandan'

[-- Attachment #1: Type: text/plain, Size: 16767 bytes --]

Kun:

 I am OK for this solution. Have you plan to update StatusCodeHandlerSmm?

 

Thanks

Liming

发件人: bounce+27952+69397+4905953+8761045@groups.io
<bounce+27952+69397+4905953+8761045@groups.io> 代表 Wu, Hao A
发送时间: 2020年12月23日 14:10
收件人: devel@edk2.groups.io; kun.q@outlook.com; Liming Gao
<gaoliming@byosoft.com.cn>; Yao, Jiewen <jiewen.yao@intel.com>
抄送: Wang, Jian J <jian.j.wang@intel.com>; Bi, Dandan <dandan.bi@intel.com>
主题: Re: [edk2-devel] [PATCH v1 06/15] MdeModulePkg:
SmmReportStatusCodeLib: ReportStatusCodeLib in StandaloneMm

 

Hello Kun,

 

Got it, thanks for the explanation. My preference is the same with your
current proposal in the patch.

 

 

Hello Liming and Jiewen,

 

Do you have comments for this case? Thanks in advance.

 

Best Regards,

Hao Wu

 

From: devel@edk2.groups.io <mailto:devel@edk2.groups.io>
<devel@edk2.groups.io <mailto:devel@edk2.groups.io> > On Behalf Of Kun Qin
Sent: Wednesday, December 23, 2020 3:15 AM
To: devel@edk2.groups.io <mailto:devel@edk2.groups.io> ; Wu, Hao A
<hao.a.wu@intel.com <mailto:hao.a.wu@intel.com> >
Cc: Wang, Jian J <jian.j.wang@intel.com <mailto:jian.j.wang@intel.com> >;
Bi, Dandan <dandan.bi@intel.com <mailto:dandan.bi@intel.com> >; Liming Gao
<gaoliming@byosoft.com.cn <mailto:gaoliming@byosoft.com.cn> >; Yao, Jiewen
<jiewen.yao@intel.com <mailto:jiewen.yao@intel.com> >
Subject: Re: [edk2-devel] [PATCH v1 06/15] MdeModulePkg:
SmmReportStatusCodeLib: ReportStatusCodeLib in StandaloneMm

 

Hi Hao,

 

That was my original plan, but doing it might require a MmServiceTableLib
instance for SMM_CORE type if PiSmmCore links in RSC lib (similar to
PiSmmCoreSmmServicesTableLib). We can create such an instance just like
PiSmmCoreSmmServicesTableLib, but the implementation will pull in
gSmmCoreSmst as an external variable and cast it from
`EFI_SMM_SYSTEM_TABLE2` to `EFI_MM_SYSTEM_TABLE`, which does not look clean.
Thus I just abstract the routine to avoid it.

 

Please let me know if you have better ideas, I can add the change for next
patch series.

 

Thanks,

Kun

 

From: Wu, Hao A <mailto:hao.a.wu@intel.com> 
Sent: Tuesday, December 22, 2020 00:35
To: devel@edk2.groups.io <mailto:devel@edk2.groups.io> ; kun.q@outlook.com
<mailto:kun.q@outlook.com> 
Cc: Wang, Jian J <mailto:jian.j.wang@intel.com> ; Bi, Dandan <mailto:dandan.
bi@intel.com> ; Liming Gao <mailto:gaoliming@byosoft.com.cn> ; Yao, Jiewen
<mailto:jiewen.yao@intel.com> 
Subject: Re: [edk2-devel] [PATCH v1 06/15] MdeModulePkg:
SmmReportStatusCodeLib: ReportStatusCodeLib in StandaloneMm

 

> -----Original Message-----
> From: devel@edk2.groups.io <mailto:devel@edk2.groups.io>
<devel@edk2.groups.io <mailto:devel@edk2.groups.io> > On Behalf Of Kun Qin
> Sent: Saturday, December 19, 2020 2:50 AM
> To: devel@edk2.groups.io <mailto:devel@edk2.groups.io> 
> Cc: Wang, Jian J <jian.j.wang@intel.com <mailto:jian.j.wang@intel.com> >;
Wu, Hao A <hao.a.wu@intel.com <mailto:hao.a.wu@intel.com> >;
> Bi, Dandan <dandan.bi@intel.com <mailto:dandan.bi@intel.com> >; Liming Gao
<gaoliming@byosoft.com.cn <mailto:gaoliming@byosoft.com.cn> >
> Subject: [edk2-devel] [PATCH v1 06/15] MdeModulePkg:
> SmmReportStatusCodeLib: ReportStatusCodeLib in StandaloneMm
> 
> This change added support of StandaloneMm for ReportStatusCodeLib. It
> adds a new instance of ReportStatusCodeLib for MM_STANDALONE type,
> and abstracts the references of gMmst and gSmst functionalities into
> separate files in order to link in proper Service Table for SMM
core/drivers.


Sorry for a question.

Do you think it is feasible to use:
gMmst->MmLocateProtocol to locate gEfiMmStatusCodeProtocolGuid
and avoid introducing 2 separate implementations for internal function
InternalLocateProtocol()?

Since I found that the definitions for gEfiMmStatusCodeProtocolGuid an
gEfiSmmStatusCodeProtocolGuid are identical.

Best Regards,
Hao Wu


> 
> Cc: Jian J Wang <jian.j.wang@intel.com <mailto:jian.j.wang@intel.com> >
> Cc: Hao A Wu <hao.a.wu@intel.com <mailto:hao.a.wu@intel.com> >
> Cc: Dandan Bi <dandan.bi@intel.com <mailto:dandan.bi@intel.com> >
> Cc: Liming Gao <gaoliming@byosoft.com.cn <mailto:gaoliming@byosoft.com.cn>
>
> 
> Signed-off-by: Kun Qin <kun.q@outlook.com <mailto:kun.q@outlook.com> >
> ---
>  MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.c
> | 16 ++++----
> 
> MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibSta
> ndaloneMm.c                                   | 39 ++++++++++++++++++++
> 
> MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibTra
> ditional.c                                    | 39 ++++++++++++++++++++
>  MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.h
> | 37 +++++++++++++++++++
> 
> MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLi
> b.inf                                          |  4 +-
> 
> MdeModulePkg/Library/SmmReportStatusCodeLib/{SmmReportStatusCode
> Lib.inf => StandaloneMmReportStatusCodeLib.inf} | 17 +++++----
>  MdeModulePkg/MdeModulePkg.dsc
> |  1 +
>  7 files changed, 137 insertions(+), 16 deletions(-)
> 
> diff --git
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.c
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.
> c
> index 3a1772538cdf..fb1769db9223 100644
> ---
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.c
> +++
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.
> c
> @@ -1,5 +1,5 @@
>  /** @file
> -  Report Status Code Library for SMM Phase.
> +  Report Status Code Library for MM Phase.
> 
>    Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
>    SPDX-License-Identifier: BSD-2-Clause-Patent @@ -8,7 +8,7 @@
> 
>  #include <Library/ReportStatusCodeLib.h>  #include <Library/DebugLib.h> -
> #include <Library/SmmServicesTableLib.h>
> +#include <Library/MmServicesTableLib.h>
>  #include <Library/BaseLib.h>
>  #include <Library/BaseMemoryLib.h>
>  #include <Library/PcdLib.h>
> @@ -16,10 +16,12 @@
> 
>  #include <Guid/StatusCodeDataTypeId.h>
>  #include <Guid/StatusCodeDataTypeDebug.h> -#include
> <Protocol/SmmStatusCode.h>
> +#include <Protocol/MmStatusCode.h>
> 
> -EFI_SMM_REPORT_STATUS_CODE     mReportStatusCode = NULL;
> -EFI_SMM_STATUS_CODE_PROTOCOL   *mStatusCodeProtocol = NULL;
> +#include "ReportStatusCodeLib.h"
> +
> +EFI_MM_REPORT_STATUS_CODE     mReportStatusCode = NULL;
> +EFI_MM_STATUS_CODE_PROTOCOL   *mStatusCodeProtocol = NULL;
> 
> 
>  /**
> @@ -29,14 +31,14 @@ EFI_SMM_STATUS_CODE_PROTOCOL
> *mStatusCodeProtocol = NULL;
>              NULL is returned if no status code service is available.
> 
>  **/
> -EFI_SMM_REPORT_STATUS_CODE
> +EFI_MM_REPORT_STATUS_CODE
>  InternalGetReportStatusCode (
>    VOID
>    )
>  {
>    EFI_STATUS                    Status;
> 
> -  Status = gSmst->SmmLocateProtocol (&gEfiSmmStatusCodeProtocolGuid,
> NULL, (VOID**)&mStatusCodeProtocol);
> +  Status = InternalLocateProtocol (&gEfiMmStatusCodeProtocolGuid, NULL,
> + (VOID**)&mStatusCodeProtocol);
>    if (!EFI_ERROR (Status) && mStatusCodeProtocol != NULL) {
>      return mStatusCodeProtocol->ReportStatusCode;
>    }
> diff --git
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibS
> tandaloneMm.c
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibS
> tandaloneMm.c
> new file mode 100644
> index 000000000000..fc47dffe9ffb
> --- /dev/null
> +++
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibS
> ta
> +++ ndaloneMm.c
> @@ -0,0 +1,39 @@
> +/** @file
> +  Abstraction layer for MM service table used by MM ReportStatusCodeLib.
> +
> +  Copyright (c) Microsoft Corporation.
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <PiMm.h>
> +
> +#include <Library/MmServicesTableLib.h>
> +
> +/**
> +  Returns the first protocol instance that matches the given protocol.
> +
> +  @param[in]  Protocol          Provides the protocol to search for.
> +  @param[in]  Registration      Optional registration key returned from
> +                                RegisterProtocolNotify().
> +  @param[out]  Interface        On return, a pointer to the first
interface that
> matches Protocol and
> +                                Registration.
> +
> +  @retval EFI_SUCCESS           A protocol instance matching Protocol was
> found and returned in
> +                                Interface.
> +  @retval EFI_NOT_FOUND         No protocol instances were found that
> match Protocol and
> +                                Registration.
> +  @retval EFI_INVALID_PARAMETER Interface is NULL.
> +                                Protocol is NULL.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +InternalLocateProtocol (
> +  IN  EFI_GUID  *Protocol,
> +  IN  VOID      *Registration, OPTIONAL
> +  OUT VOID      **Interface
> +  )
> +{
> +  return gMmst->MmLocateProtocol (Protocol, Registration, Interface); }
> diff --git
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibT
> raditional.c
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibT
> raditional.c
> new file mode 100644
> index 000000000000..6b3a7c6051c5
> --- /dev/null
> +++
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibT
> ra
> +++ ditional.c
> @@ -0,0 +1,39 @@
> +/** @file
> +  Abstraction layer for SMM service table used by SMM
> ReportStatusCodeLib.
> +
> +  Copyright (c) Microsoft Corporation.
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <PiMm.h>
> +
> +#include <Library/SmmServicesTableLib.h>
> +
> +/**
> +  Returns the first protocol instance that matches the given protocol.
> +
> +  @param[in]  Protocol          Provides the protocol to search for.
> +  @param[in]  Registration      Optional registration key returned from
> +                                RegisterProtocolNotify().
> +  @param[out]  Interface        On return, a pointer to the first
interface that
> matches Protocol and
> +                                Registration.
> +
> +  @retval EFI_SUCCESS           A protocol instance matching Protocol was
> found and returned in
> +                                Interface.
> +  @retval EFI_NOT_FOUND         No protocol instances were found that
> match Protocol and
> +                                Registration.
> +  @retval EFI_INVALID_PARAMETER Interface is NULL.
> +                                Protocol is NULL.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +InternalLocateProtocol (
> +  IN  EFI_GUID  *Protocol,
> +  IN  VOID      *Registration, OPTIONAL
> +  OUT VOID      **Interface
> +  )
> +{
> +  return gSmst->SmmLocateProtocol (Protocol, Registration, Interface);
> +}
> diff --git
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.
> h
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.
> h
> new file mode 100644
> index 000000000000..9a16741e64f6
> --- /dev/null
> +++
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.
> h
> @@ -0,0 +1,37 @@
> +/** @file
> +  Report Status Code Library for MM Phase.
> +
> +  Copyright (c) 2009 - 2018, Intel Corporation. All rights
> + reserved.<BR>
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#ifndef _MM_RSC_LIB_H_
> +#define _MM_RSC_LIB_H_
> +
> +/**
> +  Returns the first protocol instance that matches the given protocol.
> +
> +  @param[in]  Protocol          Provides the protocol to search for.
> +  @param[in]  Registration      Optional registration key returned from
> +                                RegisterProtocolNotify().
> +  @param[out]  Interface        On return, a pointer to the first
interface that
> matches Protocol and
> +                                Registration.
> +
> +  @retval EFI_SUCCESS           A protocol instance matching Protocol was
> found and returned in
> +                                Interface.
> +  @retval EFI_NOT_FOUND         No protocol instances were found that
> match Protocol and
> +                                Registration.
> +  @retval EFI_INVALID_PARAMETER Interface is NULL.
> +                                Protocol is NULL.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +InternalLocateProtocol (
> +  IN  EFI_GUID  *Protocol,
> +  IN  VOID      *Registration, OPTIONAL
> +  OUT VOID      **Interface
> +  );
> +
> +#endif // _MM_RSC_LIB_H_
> diff --git
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCod
> eLib.inf
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCod
> eLib.inf
> index 72496bfababd..02dce09a199d 100644
> ---
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCod
> eLib.inf
> +++
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCod
> eLib
> +++ .inf
> @@ -28,6 +28,8 @@ [Defines]
> 
>  [Sources]
>    ReportStatusCodeLib.c
> +  ReportStatusCodeLib.h
> +  ReportStatusCodeLibTraditional.c
> 
>  [Packages]
>    MdePkg/MdePkg.dec
> @@ -45,7 +47,7 @@ [Guids]
>    gEfiStatusCodeDataTypeDebugGuid               ## SOMETIMES_CONSUMES
> ## UNDEFINED
> 
>  [Protocols]
> -  gEfiSmmStatusCodeProtocolGuid                 ## CONSUMES
> +  gEfiMmStatusCodeProtocolGuid                  ## CONSUMES
> 
>  [Pcd]
>    gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask  ##
> CONSUMES diff --git
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCod
> eLib.inf
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/StandaloneMmReport
> StatusCodeLib.inf
> similarity index 64%
> copy from
> MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLi
> b.inf
> copy to
> MdeModulePkg/Library/SmmReportStatusCodeLib/StandaloneMmReportSt
> atusCodeLib.inf
> index 72496bfababd..11ecc67fc4fa 100644
> ---
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCod
> eLib.inf
> +++
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/StandaloneMmReport
> Stat
> +++ usCodeLib.inf
> @@ -12,13 +12,12 @@
> 
>  [Defines]
>    INF_VERSION                    = 0x00010005
> -  BASE_NAME                      = SmmReportStatusCodeLib
> -  MODULE_UNI_FILE                = SmmReportStatusCodeLib.uni
> -  FILE_GUID                      = 67089D19-B3D6-4d9e-A0EB-FEDC1F83A1EE
> -  MODULE_TYPE                    = DXE_SMM_DRIVER
> +  BASE_NAME                      = StandaloneMmReportStatusCodeLib
> +  FILE_GUID                      = 17C7FC8C-8C5D-497E-9C0E-C21255B30E04
> +  MODULE_TYPE                    = MM_STANDALONE
>    VERSION_STRING                 = 1.0
> -  PI_SPECIFICATION_VERSION       = 0x0001000A
> -  LIBRARY_CLASS                  = ReportStatusCodeLib|DXE_SMM_DRIVER
> SMM_CORE
> +  PI_SPECIFICATION_VERSION       = 0x00010032
> +  LIBRARY_CLASS                  = ReportStatusCodeLib|MM_STANDALONE
> 
>  #
>  # The following information is for reference only and not required by the
> build tools.
> @@ -28,6 +27,8 @@ [Defines]
> 
>  [Sources]
>    ReportStatusCodeLib.c
> +  ReportStatusCodeLib.h
> +  ReportStatusCodeLibStandaloneMm.c
> 
>  [Packages]
>    MdePkg/MdePkg.dec
> @@ -36,7 +37,7 @@ [Packages]
>  [LibraryClasses]
>    PcdLib
>    BaseMemoryLib
> -  SmmServicesTableLib
> +  MmServicesTableLib
>    DebugLib
>    MemoryAllocationLib
> 
> @@ -45,7 +46,7 @@ [Guids]
>    gEfiStatusCodeDataTypeDebugGuid               ## SOMETIMES_CONSUMES
> ## UNDEFINED
> 
>  [Protocols]
> -  gEfiSmmStatusCodeProtocolGuid                 ## CONSUMES
> +  gEfiMmStatusCodeProtocolGuid                  ## CONSUMES
> 
>  [Pcd]
>    gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask  ##
> CONSUMES diff --git a/MdeModulePkg/MdeModulePkg.dsc
> b/MdeModulePkg/MdeModulePkg.dsc index cd91a70b4fdd..05bf5fe08094
> 100644
> --- a/MdeModulePkg/MdeModulePkg.dsc
> +++ b/MdeModulePkg/MdeModulePkg.dsc
> @@ -473,6 +473,7 @@ [Components.IA32, Components.X64]
>    }
> 
> MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.i
> nf
> 
> MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLi
> b.inf
> +
> +
> MdeModulePkg/Library/SmmReportStatusCodeLib/StandaloneMmReportSt
> atusCo
> + deLib.inf
> 
> MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSm
> m.inf
> 
> MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCod
> eRouterSmm.inf
>    MdeModulePkg/Universal/LockBox/SmmLockBox/SmmLockBox.inf
> --
> 2.28.0.windows.1
> 
> 
> 
> 
> 





 




[-- Attachment #2: Type: text/html, Size: 30739 bytes --]

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [edk2-devel] [PATCH v1 06/15] MdeModulePkg: SmmReportStatusCodeLib: ReportStatusCodeLib in StandaloneMm
  2020-12-24  1:53         ` 回复: " gaoliming
@ 2020-12-24  9:11           ` Kun Qin
  2020-12-29  1:23             ` 回复: " gaoliming
  0 siblings, 1 reply; 44+ messages in thread
From: Kun Qin @ 2020-12-24  9:11 UTC (permalink / raw)
  To: devel@edk2.groups.io, gaoliming@byosoft.com.cn,
	hao.a.wu@intel.com, 'Yao, Jiewen'
  Cc: 'Wang, Jian J', 'Bi, Dandan'


[-- Attachment #1.1: Type: text/plain, Size: 17447 bytes --]

Liming,

I have not had a plan for StatusCodeHandlerSmm because our platforms are not using it currently (we used a MU version instead). So it would be difficult to fully validate the functionality after updates. Please let me know if you prefer to have this driver updated in this patch series, I can try to update it locally with some fundamental sanity checks.

Regards,
Kun

From: gaoliming<mailto:gaoliming@byosoft.com.cn>
Sent: Wednesday, December 23, 2020 17:53
To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>; hao.a.wu@intel.com<mailto:hao.a.wu@intel.com>; kun.q@outlook.com<mailto:kun.q@outlook.com>; 'Yao, Jiewen'<mailto:jiewen.yao@intel.com>
Cc: 'Wang, Jian J'<mailto:jian.j.wang@intel.com>; 'Bi, Dandan'<mailto:dandan.bi@intel.com>
Subject: 回复: [edk2-devel] [PATCH v1 06/15] MdeModulePkg: SmmReportStatusCodeLib: ReportStatusCodeLib in StandaloneMm

Kun:
 I am OK for this solution. Have you plan to update StatusCodeHandlerSmm?

Thanks
Liming
发件人: bounce+27952+69397+4905953+8761045@groups.io <bounce+27952+69397+4905953+8761045@groups.io> 代表 Wu, Hao A
发送时间: 2020年12月23日 14:10
收件人: devel@edk2.groups.io; kun.q@outlook.com; Liming Gao <gaoliming@byosoft.com.cn>; Yao, Jiewen <jiewen.yao@intel.com>
抄送: Wang, Jian J <jian.j.wang@intel.com>; Bi, Dandan <dandan.bi@intel.com>
主题: Re: [edk2-devel] [PATCH v1 06/15] MdeModulePkg: SmmReportStatusCodeLib: ReportStatusCodeLib in StandaloneMm

Hello Kun,

Got it, thanks for the explanation. My preference is the same with your current proposal in the patch.


Hello Liming and Jiewen,

Do you have comments for this case? Thanks in advance.

Best Regards,
Hao Wu

From: devel@edk2.groups.io<mailto:devel@edk2.groups.io> <devel@edk2.groups.io<mailto:devel@edk2.groups.io>> On Behalf Of Kun Qin
Sent: Wednesday, December 23, 2020 3:15 AM
To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>; Wu, Hao A <hao.a.wu@intel.com<mailto:hao.a.wu@intel.com>>
Cc: Wang, Jian J <jian.j.wang@intel.com<mailto:jian.j.wang@intel.com>>; Bi, Dandan <dandan.bi@intel.com<mailto:dandan.bi@intel.com>>; Liming Gao <gaoliming@byosoft.com.cn<mailto:gaoliming@byosoft.com.cn>>; Yao, Jiewen <jiewen.yao@intel.com<mailto:jiewen.yao@intel.com>>
Subject: Re: [edk2-devel] [PATCH v1 06/15] MdeModulePkg: SmmReportStatusCodeLib: ReportStatusCodeLib in StandaloneMm

Hi Hao,

That was my original plan, but doing it might require a MmServiceTableLib instance for SMM_CORE type if PiSmmCore links in RSC lib (similar to PiSmmCoreSmmServicesTableLib). We can create such an instance just like PiSmmCoreSmmServicesTableLib, but the implementation will pull in gSmmCoreSmst as an external variable and cast it from `EFI_SMM_SYSTEM_TABLE2` to `EFI_MM_SYSTEM_TABLE`, which does not look clean. Thus I just abstract the routine to avoid it.

Please let me know if you have better ideas, I can add the change for next patch series.

Thanks,
Kun

From: Wu, Hao A<mailto:hao.a.wu@intel.com>
Sent: Tuesday, December 22, 2020 00:35
To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>; kun.q@outlook.com<mailto:kun.q@outlook.com>
Cc: Wang, Jian J<mailto:jian.j.wang@intel.com>; Bi, Dandan<mailto:dandan.bi@intel.com>; Liming Gao<mailto:gaoliming@byosoft.com.cn>; Yao, Jiewen<mailto:jiewen.yao@intel.com>
Subject: Re: [edk2-devel] [PATCH v1 06/15] MdeModulePkg: SmmReportStatusCodeLib: ReportStatusCodeLib in StandaloneMm

> -----Original Message-----
> From: devel@edk2.groups.io<mailto:devel@edk2.groups.io> <devel@edk2.groups.io<mailto:devel@edk2.groups.io>> On Behalf Of Kun Qin
> Sent: Saturday, December 19, 2020 2:50 AM
> To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>
> Cc: Wang, Jian J <jian.j.wang@intel.com<mailto:jian.j.wang@intel.com>>; Wu, Hao A <hao.a.wu@intel.com<mailto:hao.a.wu@intel.com>>;
> Bi, Dandan <dandan.bi@intel.com<mailto:dandan.bi@intel.com>>; Liming Gao <gaoliming@byosoft.com.cn<mailto:gaoliming@byosoft.com.cn>>
> Subject: [edk2-devel] [PATCH v1 06/15] MdeModulePkg:
> SmmReportStatusCodeLib: ReportStatusCodeLib in StandaloneMm
>
> This change added support of StandaloneMm for ReportStatusCodeLib. It
> adds a new instance of ReportStatusCodeLib for MM_STANDALONE type,
> and abstracts the references of gMmst and gSmst functionalities into
> separate files in order to link in proper Service Table for SMM core/drivers.


Sorry for a question.

Do you think it is feasible to use:
gMmst->MmLocateProtocol to locate gEfiMmStatusCodeProtocolGuid
and avoid introducing 2 separate implementations for internal function InternalLocateProtocol()?

Since I found that the definitions for gEfiMmStatusCodeProtocolGuid an gEfiSmmStatusCodeProtocolGuid are identical.

Best Regards,
Hao Wu


>
> Cc: Jian J Wang <jian.j.wang@intel.com<mailto:jian.j.wang@intel.com>>
> Cc: Hao A Wu <hao.a.wu@intel.com<mailto:hao.a.wu@intel.com>>
> Cc: Dandan Bi <dandan.bi@intel.com<mailto:dandan.bi@intel.com>>
> Cc: Liming Gao <gaoliming@byosoft.com.cn<mailto:gaoliming@byosoft.com.cn>>
>
> Signed-off-by: Kun Qin <kun.q@outlook.com<mailto:kun.q@outlook.com>>
> ---
>  MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.c
> | 16 ++++----
>
> MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibSta
> ndaloneMm.c                                   | 39 ++++++++++++++++++++
>
> MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibTra
> ditional.c                                    | 39 ++++++++++++++++++++
>  MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.h
> | 37 +++++++++++++++++++
>
> MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLi
> b.inf                                          |  4 +-
>
> MdeModulePkg/Library/SmmReportStatusCodeLib/{SmmReportStatusCode
> Lib.inf => StandaloneMmReportStatusCodeLib.inf} | 17 +++++----
>  MdeModulePkg/MdeModulePkg.dsc
> |  1 +
>  7 files changed, 137 insertions(+), 16 deletions(-)
>
> diff --git
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.c
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.
> c
> index 3a1772538cdf..fb1769db9223 100644
> ---
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.c
> +++
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.
> c
> @@ -1,5 +1,5 @@
>  /** @file
> -  Report Status Code Library for SMM Phase.
> +  Report Status Code Library for MM Phase.
>
>    Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
>    SPDX-License-Identifier: BSD-2-Clause-Patent @@ -8,7 +8,7 @@
>
>  #include <Library/ReportStatusCodeLib.h>  #include <Library/DebugLib.h> -
> #include <Library/SmmServicesTableLib.h>
> +#include <Library/MmServicesTableLib.h>
>  #include <Library/BaseLib.h>
>  #include <Library/BaseMemoryLib.h>
>  #include <Library/PcdLib.h>
> @@ -16,10 +16,12 @@
>
>  #include <Guid/StatusCodeDataTypeId.h>
>  #include <Guid/StatusCodeDataTypeDebug.h> -#include
> <Protocol/SmmStatusCode.h>
> +#include <Protocol/MmStatusCode.h>
>
> -EFI_SMM_REPORT_STATUS_CODE     mReportStatusCode = NULL;
> -EFI_SMM_STATUS_CODE_PROTOCOL   *mStatusCodeProtocol = NULL;
> +#include "ReportStatusCodeLib.h"
> +
> +EFI_MM_REPORT_STATUS_CODE     mReportStatusCode = NULL;
> +EFI_MM_STATUS_CODE_PROTOCOL   *mStatusCodeProtocol = NULL;
>
>
>  /**
> @@ -29,14 +31,14 @@ EFI_SMM_STATUS_CODE_PROTOCOL
> *mStatusCodeProtocol = NULL;
>              NULL is returned if no status code service is available.
>
>  **/
> -EFI_SMM_REPORT_STATUS_CODE
> +EFI_MM_REPORT_STATUS_CODE
>  InternalGetReportStatusCode (
>    VOID
>    )
>  {
>    EFI_STATUS                    Status;
>
> -  Status = gSmst->SmmLocateProtocol (&gEfiSmmStatusCodeProtocolGuid,
> NULL, (VOID**)&mStatusCodeProtocol);
> +  Status = InternalLocateProtocol (&gEfiMmStatusCodeProtocolGuid, NULL,
> + (VOID**)&mStatusCodeProtocol);
>    if (!EFI_ERROR (Status) && mStatusCodeProtocol != NULL) {
>      return mStatusCodeProtocol->ReportStatusCode;
>    }
> diff --git
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibS
> tandaloneMm.c
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibS
> tandaloneMm.c
> new file mode 100644
> index 000000000000..fc47dffe9ffb
> --- /dev/null
> +++
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibS
> ta
> +++ ndaloneMm.c
> @@ -0,0 +1,39 @@
> +/** @file
> +  Abstraction layer for MM service table used by MM ReportStatusCodeLib.
> +
> +  Copyright (c) Microsoft Corporation.
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <PiMm.h>
> +
> +#include <Library/MmServicesTableLib.h>
> +
> +/**
> +  Returns the first protocol instance that matches the given protocol.
> +
> +  @param[in]  Protocol          Provides the protocol to search for.
> +  @param[in]  Registration      Optional registration key returned from
> +                                RegisterProtocolNotify().
> +  @param[out]  Interface        On return, a pointer to the first interface that
> matches Protocol and
> +                                Registration.
> +
> +  @retval EFI_SUCCESS           A protocol instance matching Protocol was
> found and returned in
> +                                Interface.
> +  @retval EFI_NOT_FOUND         No protocol instances were found that
> match Protocol and
> +                                Registration.
> +  @retval EFI_INVALID_PARAMETER Interface is NULL.
> +                                Protocol is NULL.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +InternalLocateProtocol (
> +  IN  EFI_GUID  *Protocol,
> +  IN  VOID      *Registration, OPTIONAL
> +  OUT VOID      **Interface
> +  )
> +{
> +  return gMmst->MmLocateProtocol (Protocol, Registration, Interface); }
> diff --git
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibT
> raditional.c
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibT
> raditional.c
> new file mode 100644
> index 000000000000..6b3a7c6051c5
> --- /dev/null
> +++
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibT
> ra
> +++ ditional.c
> @@ -0,0 +1,39 @@
> +/** @file
> +  Abstraction layer for SMM service table used by SMM
> ReportStatusCodeLib.
> +
> +  Copyright (c) Microsoft Corporation.
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <PiMm.h>
> +
> +#include <Library/SmmServicesTableLib.h>
> +
> +/**
> +  Returns the first protocol instance that matches the given protocol.
> +
> +  @param[in]  Protocol          Provides the protocol to search for.
> +  @param[in]  Registration      Optional registration key returned from
> +                                RegisterProtocolNotify().
> +  @param[out]  Interface        On return, a pointer to the first interface that
> matches Protocol and
> +                                Registration.
> +
> +  @retval EFI_SUCCESS           A protocol instance matching Protocol was
> found and returned in
> +                                Interface.
> +  @retval EFI_NOT_FOUND         No protocol instances were found that
> match Protocol and
> +                                Registration.
> +  @retval EFI_INVALID_PARAMETER Interface is NULL.
> +                                Protocol is NULL.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +InternalLocateProtocol (
> +  IN  EFI_GUID  *Protocol,
> +  IN  VOID      *Registration, OPTIONAL
> +  OUT VOID      **Interface
> +  )
> +{
> +  return gSmst->SmmLocateProtocol (Protocol, Registration, Interface);
> +}
> diff --git
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.
> h
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.
> h
> new file mode 100644
> index 000000000000..9a16741e64f6
> --- /dev/null
> +++
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.
> h
> @@ -0,0 +1,37 @@
> +/** @file
> +  Report Status Code Library for MM Phase.
> +
> +  Copyright (c) 2009 - 2018, Intel Corporation. All rights
> + reserved.<BR>
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#ifndef _MM_RSC_LIB_H_
> +#define _MM_RSC_LIB_H_
> +
> +/**
> +  Returns the first protocol instance that matches the given protocol.
> +
> +  @param[in]  Protocol          Provides the protocol to search for.
> +  @param[in]  Registration      Optional registration key returned from
> +                                RegisterProtocolNotify().
> +  @param[out]  Interface        On return, a pointer to the first interface that
> matches Protocol and
> +                                Registration.
> +
> +  @retval EFI_SUCCESS           A protocol instance matching Protocol was
> found and returned in
> +                                Interface.
> +  @retval EFI_NOT_FOUND         No protocol instances were found that
> match Protocol and
> +                                Registration.
> +  @retval EFI_INVALID_PARAMETER Interface is NULL.
> +                                Protocol is NULL.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +InternalLocateProtocol (
> +  IN  EFI_GUID  *Protocol,
> +  IN  VOID      *Registration, OPTIONAL
> +  OUT VOID      **Interface
> +  );
> +
> +#endif // _MM_RSC_LIB_H_
> diff --git
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCod
> eLib.inf
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCod
> eLib.inf
> index 72496bfababd..02dce09a199d 100644
> ---
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCod
> eLib.inf
> +++
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCod
> eLib
> +++ .inf
> @@ -28,6 +28,8 @@ [Defines]
>
>  [Sources]
>    ReportStatusCodeLib.c
> +  ReportStatusCodeLib.h
> +  ReportStatusCodeLibTraditional.c
>
>  [Packages]
>    MdePkg/MdePkg.dec
> @@ -45,7 +47,7 @@ [Guids]
>    gEfiStatusCodeDataTypeDebugGuid               ## SOMETIMES_CONSUMES
> ## UNDEFINED
>
>  [Protocols]
> -  gEfiSmmStatusCodeProtocolGuid                 ## CONSUMES
> +  gEfiMmStatusCodeProtocolGuid                  ## CONSUMES
>
>  [Pcd]
>    gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask  ##
> CONSUMES diff --git
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCod
> eLib.inf
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/StandaloneMmReport
> StatusCodeLib.inf
> similarity index 64%
> copy from
> MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLi
> b.inf
> copy to
> MdeModulePkg/Library/SmmReportStatusCodeLib/StandaloneMmReportSt
> atusCodeLib.inf
> index 72496bfababd..11ecc67fc4fa 100644
> ---
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCod
> eLib.inf
> +++
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/StandaloneMmReport
> Stat
> +++ usCodeLib.inf
> @@ -12,13 +12,12 @@
>
>  [Defines]
>    INF_VERSION                    = 0x00010005
> -  BASE_NAME                      = SmmReportStatusCodeLib
> -  MODULE_UNI_FILE                = SmmReportStatusCodeLib.uni
> -  FILE_GUID                      = 67089D19-B3D6-4d9e-A0EB-FEDC1F83A1EE
> -  MODULE_TYPE                    = DXE_SMM_DRIVER
> +  BASE_NAME                      = StandaloneMmReportStatusCodeLib
> +  FILE_GUID                      = 17C7FC8C-8C5D-497E-9C0E-C21255B30E04
> +  MODULE_TYPE                    = MM_STANDALONE
>    VERSION_STRING                 = 1.0
> -  PI_SPECIFICATION_VERSION       = 0x0001000A
> -  LIBRARY_CLASS                  = ReportStatusCodeLib|DXE_SMM_DRIVER
> SMM_CORE
> +  PI_SPECIFICATION_VERSION       = 0x00010032
> +  LIBRARY_CLASS                  = ReportStatusCodeLib|MM_STANDALONE
>
>  #
>  # The following information is for reference only and not required by the
> build tools.
> @@ -28,6 +27,8 @@ [Defines]
>
>  [Sources]
>    ReportStatusCodeLib.c
> +  ReportStatusCodeLib.h
> +  ReportStatusCodeLibStandaloneMm.c
>
>  [Packages]
>    MdePkg/MdePkg.dec
> @@ -36,7 +37,7 @@ [Packages]
>  [LibraryClasses]
>    PcdLib
>    BaseMemoryLib
> -  SmmServicesTableLib
> +  MmServicesTableLib
>    DebugLib
>    MemoryAllocationLib
>
> @@ -45,7 +46,7 @@ [Guids]
>    gEfiStatusCodeDataTypeDebugGuid               ## SOMETIMES_CONSUMES
> ## UNDEFINED
>
>  [Protocols]
> -  gEfiSmmStatusCodeProtocolGuid                 ## CONSUMES
> +  gEfiMmStatusCodeProtocolGuid                  ## CONSUMES
>
>  [Pcd]
>    gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask  ##
> CONSUMES diff --git a/MdeModulePkg/MdeModulePkg.dsc
> b/MdeModulePkg/MdeModulePkg.dsc index cd91a70b4fdd..05bf5fe08094
> 100644
> --- a/MdeModulePkg/MdeModulePkg.dsc
> +++ b/MdeModulePkg/MdeModulePkg.dsc
> @@ -473,6 +473,7 @@ [Components.IA32, Components.X64]
>    }
>
> MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.i
> nf
>
> MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLi
> b.inf
> +
> +
> MdeModulePkg/Library/SmmReportStatusCodeLib/StandaloneMmReportSt
> atusCo
> + deLib.inf
>
> MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSm
> m.inf
>
> MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCod
> eRouterSmm.inf
>    MdeModulePkg/Universal/LockBox/SmmLockBox/SmmLockBox.inf
> --
> 2.28.0.windows.1
>
>
>
>
>








[-- Attachment #1.2: Type: text/html, Size: 32019 bytes --]

[-- Attachment #2: EAEEDEA3E735495E93D05EB5B8C6E1D2.png --]
[-- Type: image/png, Size: 140 bytes --]

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v1 11/15] SecurityPkg: Tcg2PhysicalPresenceLib: Introduce StandaloneMm instance
  2020-12-18 18:50 ` [PATCH v1 11/15] SecurityPkg: Tcg2PhysicalPresenceLib: Introduce StandaloneMm instance Kun Qin
@ 2020-12-28  0:08   ` Yao, Jiewen
  0 siblings, 0 replies; 44+ messages in thread
From: Yao, Jiewen @ 2020-12-28  0:08 UTC (permalink / raw)
  To: Kun Qin, devel@edk2.groups.io; +Cc: Wang, Jian J, Zhang, Qi1, Kumar, Rahul1

Reviewed-by: Jiewen Yao <Jiewen.yao@intel.com>

> -----Original Message-----
> From: Kun Qin <kun.q@outlook.com>
> Sent: Saturday, December 19, 2020 2:50 AM
> To: devel@edk2.groups.io
> Cc: Yao, Jiewen <jiewen.yao@intel.com>; Wang, Jian J
> <jian.j.wang@intel.com>; Zhang, Qi1 <qi1.zhang@intel.com>; Kumar,
> Rahul1 <rahul1.kumar@intel.com>
> Subject: [PATCH v1 11/15] SecurityPkg: Tcg2PhysicalPresenceLib: Introduce
> StandaloneMm instance
> 
> This change added a new instance of Tcg2PhysicalPresenceLib to support
> MM_STANDALONE type drivers. It centralizes the common routines into
> shared files and abstract the library constructor into corresponding
> files to implement each constructor function prototypes.
> 
> Cc: Jiewen Yao <jiewen.yao@intel.com>
> Cc: Jian J Wang <jian.j.wang@intel.com>
> Cc: Qi Zhang <qi1.zhang@intel.com>
> Cc: Rahul Kumar <rahul1.kumar@intel.com>
> 
> Signed-off-by: Kun Qin <kun.q@outlook.com>
> ---
> 
> SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/{SmmTcg2PhysicalPrese
> nceLib.c => MmTcg2PhysicalPresenceLibCommon.c}         |  29 +-
> 
> SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresen
> ceLib.c                                                | 368 +-------------------
> 
> SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/StandaloneMmTcg2Phys
> icalPresenceLib.c                                       |  42 +++
> 
> SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/MmTcg2PhysicalPresenc
> eLibCommon.h                                           |  35 ++
> 
> SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresen
> ceLib.inf                                              |   6 +-
> 
> SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/{SmmTcg2PhysicalPrese
> nceLib.inf => StandaloneMmTcg2PhysicalPresenceLib.inf} |  22 +-
>  SecurityPkg/SecurityPkg.dsc
> |   2 +
>  7 files changed, 114 insertions(+), 390 deletions(-)
> 
> diff --git
> a/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPres
> enceLib.c
> b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/MmTcg2PhysicalPrese
> nceLibCommon.c
> similarity index 91%
> copy from
> SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresen
> ceLib.c
> copy to
> SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/MmTcg2PhysicalPresenc
> eLibCommon.c
> index 8afaa0a7857d..90023f09a042 100644
> ---
> a/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPres
> enceLib.c
> +++
> b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/MmTcg2PhysicalPrese
> nceLibCommon.c
> @@ -15,7 +15,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
> 
>  **/
> 
> -#include <PiSmm.h>
> +#include <PiMm.h>
> 
>  #include <Guid/Tcg2PhysicalPresenceData.h>
> 
> @@ -25,7 +25,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
>  #include <Library/DebugLib.h>
>  #include <Library/BaseMemoryLib.h>
>  #include <Library/Tcg2PpVendorLib.h>
> -#include <Library/SmmServicesTableLib.h>
> +#include <Library/MmServicesTableLib.h>
> 
>  #define     PP_INF_VERSION_1_2    "1.2"
> 
> @@ -55,7 +55,7 @@
> Tcg2PhysicalPresenceLibReturnOperationResponseToOsFunction (
>    UINTN                             DataSize;
>    EFI_TCG2_PHYSICAL_PRESENCE        PpData;
> 
> -  DEBUG ((EFI_D_INFO, "[TPM2]
> ReturnOperationResponseToOsFunction\n"));
> +  DEBUG ((DEBUG_INFO, "[TPM2]
> ReturnOperationResponseToOsFunction\n"));
> 
>    //
>    // Get the Physical Presence variable
> @@ -71,7 +71,7 @@
> Tcg2PhysicalPresenceLibReturnOperationResponseToOsFunction (
>    if (EFI_ERROR (Status)) {
>      *MostRecentRequest = 0;
>      *Response          = 0;
> -    DEBUG ((EFI_D_ERROR, "[TPM2] Get PP variable failure! Status = %r\n",
> Status));
> +    DEBUG ((DEBUG_ERROR, "[TPM2] Get PP variable failure! Status = %r\n",
> Status));
>      return TCG_PP_RETURN_TPM_OPERATION_RESPONSE_FAILURE;
>    }
> 
> @@ -108,7 +108,7 @@
> Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunctionEx (
>    EFI_TCG2_PHYSICAL_PRESENCE        PpData;
>    EFI_TCG2_PHYSICAL_PRESENCE_FLAGS  Flags;
> 
> -  DEBUG ((EFI_D_INFO, "[TPM2] SubmitRequestToPreOSFunction, Request
> = %x, %x\n", *OperationRequest, *RequestParameter));
> +  DEBUG ((DEBUG_INFO, "[TPM2] SubmitRequestToPreOSFunction,
> Request = %x, %x\n", *OperationRequest, *RequestParameter));
>    ReturnCode = TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS;
> 
>    //
> @@ -123,7 +123,7 @@
> Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunctionEx (
>                                   &PpData
>                                   );
>    if (EFI_ERROR (Status)) {
> -    DEBUG ((EFI_D_ERROR, "[TPM2] Get PP variable failure! Status = %r\n",
> Status));
> +    DEBUG ((DEBUG_ERROR, "[TPM2] Get PP variable failure! Status = %r\n",
> Status));
>      ReturnCode =
> TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE;
>      goto EXIT;
>    }
> @@ -147,7 +147,7 @@
> Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunctionEx (
>                                     &PpData
>                                     );
>      if (EFI_ERROR (Status)) {
> -      DEBUG ((EFI_D_ERROR, "[TPM2] Set PP variable failure! Status = %r\n",
> Status));
> +      DEBUG ((DEBUG_ERROR, "[TPM2] Set PP variable failure! Status
> = %r\n", Status));
>        ReturnCode =
> TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE;
>        goto EXIT;
>      }
> @@ -173,7 +173,7 @@
> Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunctionEx (
>    // Sync PPRQ/PPRM from PP Variable if PP submission fails
>    //
>    if (ReturnCode != TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS) {
> -    DEBUG ((EFI_D_ERROR, "[TPM2] Submit PP Request failure! Sync
> PPRQ/PPRM with PP variable.\n", Status));
> +    DEBUG ((DEBUG_ERROR, "[TPM2] Submit PP Request failure! Sync
> PPRQ/PPRM with PP variable.\n", Status));
>      DataSize = sizeof (EFI_TCG2_PHYSICAL_PRESENCE);
>      ZeroMem(&PpData, DataSize);
>      Status = mTcg2PpSmmVariable->SmmGetVariable (
> @@ -245,7 +245,7 @@
> Tcg2PhysicalPresenceLibGetUserConfirmationStatusFunction (
>    EFI_TCG2_PHYSICAL_PRESENCE_FLAGS  Flags;
>    BOOLEAN                           RequestConfirmed;
> 
> -  DEBUG ((EFI_D_INFO, "[TPM2] GetUserConfirmationStatusFunction,
> Request = %x\n", OperationRequest));
> +  DEBUG ((DEBUG_INFO, "[TPM2] GetUserConfirmationStatusFunction,
> Request = %x\n", OperationRequest));
> 
>    //
>    // Get the Physical Presence variable
> @@ -259,7 +259,7 @@
> Tcg2PhysicalPresenceLibGetUserConfirmationStatusFunction (
>                                   &PpData
>                                   );
>    if (EFI_ERROR (Status)) {
> -    DEBUG ((EFI_D_ERROR, "[TPM2] Get PP variable failure! Status = %r\n",
> Status));
> +    DEBUG ((DEBUG_ERROR, "[TPM2] Get PP variable failure! Status = %r\n",
> Status));
>      return
> TCG_PP_GET_USER_CONFIRMATION_BLOCKED_BY_BIOS_CONFIGURATION;
>    }
>    //
> @@ -274,7 +274,7 @@
> Tcg2PhysicalPresenceLibGetUserConfirmationStatusFunction (
>                                   &Flags
>                                   );
>    if (EFI_ERROR (Status)) {
> -    DEBUG ((EFI_D_ERROR, "[TPM2] Get PP flags failure! Status = %r\n",
> Status));
> +    DEBUG ((DEBUG_ERROR, "[TPM2] Get PP flags failure! Status = %r\n",
> Status));
>      return
> TCG_PP_GET_USER_CONFIRMATION_BLOCKED_BY_BIOS_CONFIGURATION;
>    }
> 
> @@ -380,9 +380,8 @@
> Tcg2PhysicalPresenceLibGetUserConfirmationStatusFunction (
>  **/
>  EFI_STATUS
>  EFIAPI
> -Tcg2PhysicalPresenceLibConstructor (
> -  IN EFI_HANDLE        ImageHandle,
> -  IN EFI_SYSTEM_TABLE  *SystemTable
> +Tcg2PhysicalPresenceLibCommonConstructor (
> +  VOID
>    )
>  {
>    EFI_STATUS  Status;
> @@ -394,7 +393,7 @@ Tcg2PhysicalPresenceLibConstructor (
>    //
>    // Locate SmmVariableProtocol.
>    //
> -  Status = gSmst->SmmLocateProtocol (&gEfiSmmVariableProtocolGuid,
> NULL, (VOID**)&mTcg2PpSmmVariable);
> +  Status = gMmst->MmLocateProtocol (&gEfiSmmVariableProtocolGuid,
> NULL, (VOID**)&mTcg2PpSmmVariable);
>    ASSERT_EFI_ERROR (Status);
> 
>    mTcg2PhysicalPresenceFlags = PcdGet32(PcdTcg2PhysicalPresenceFlags);
> diff --git
> a/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPres
> enceLib.c
> b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPres
> enceLib.c
> index 8afaa0a7857d..36d8b89dcdd9 100644
> ---
> a/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPres
> enceLib.c
> +++
> b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPres
> enceLib.c
> @@ -17,355 +17,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
> 
>  #include <PiSmm.h>
> 
> -#include <Guid/Tcg2PhysicalPresenceData.h>
> -
> -#include <Protocol/SmmVariable.h>
> -
> -#include <Library/BaseLib.h>
> -#include <Library/DebugLib.h>
> -#include <Library/BaseMemoryLib.h>
> -#include <Library/Tcg2PpVendorLib.h>
> -#include <Library/SmmServicesTableLib.h>
> -
> -#define     PP_INF_VERSION_1_2    "1.2"
> -
> -EFI_SMM_VARIABLE_PROTOCOL  *mTcg2PpSmmVariable;
> -BOOLEAN                    mIsTcg2PPVerLowerThan_1_3 = FALSE;
> -UINT32                     mTcg2PhysicalPresenceFlags;
> -
> -/**
> -  The handler for TPM physical presence function:
> -  Return TPM Operation Response to OS Environment.
> -
> -  This API should be invoked in OS runtime phase to interface with ACPI
> method.
> -
> -  @param[out]     MostRecentRequest Most recent operation request.
> -  @param[out]     Response          Response to the most recent operation
> request.
> -
> -  @return Return Code for Return TPM Operation Response to OS
> Environment.
> -**/
> -UINT32
> -EFIAPI
> -Tcg2PhysicalPresenceLibReturnOperationResponseToOsFunction (
> -  OUT UINT32                *MostRecentRequest,
> -  OUT UINT32                *Response
> -  )
> -{
> -  EFI_STATUS                        Status;
> -  UINTN                             DataSize;
> -  EFI_TCG2_PHYSICAL_PRESENCE        PpData;
> -
> -  DEBUG ((EFI_D_INFO, "[TPM2]
> ReturnOperationResponseToOsFunction\n"));
> -
> -  //
> -  // Get the Physical Presence variable
> -  //
> -  DataSize = sizeof (EFI_TCG2_PHYSICAL_PRESENCE);
> -  Status = mTcg2PpSmmVariable->SmmGetVariable (
> -                                 TCG2_PHYSICAL_PRESENCE_VARIABLE,
> -                                 &gEfiTcg2PhysicalPresenceGuid,
> -                                 NULL,
> -                                 &DataSize,
> -                                 &PpData
> -                                 );
> -  if (EFI_ERROR (Status)) {
> -    *MostRecentRequest = 0;
> -    *Response          = 0;
> -    DEBUG ((EFI_D_ERROR, "[TPM2] Get PP variable failure! Status = %r\n",
> Status));
> -    return TCG_PP_RETURN_TPM_OPERATION_RESPONSE_FAILURE;
> -  }
> -
> -  *MostRecentRequest = PpData.LastPPRequest;
> -  *Response          = PpData.PPResponse;
> -
> -  return TCG_PP_RETURN_TPM_OPERATION_RESPONSE_SUCCESS;
> -}
> -
> -/**
> -  The handler for TPM physical presence function:
> -  Submit TPM Operation Request to Pre-OS Environment and
> -  Submit TPM Operation Request to Pre-OS Environment 2.
> -
> -  This API should be invoked in OS runtime phase to interface with ACPI
> method.
> -
> -  Caution: This function may receive untrusted input.
> -
> -  @param[in, out]  Pointer to OperationRequest TPM physical presence
> operation request.
> -  @param[in, out]  Pointer to RequestParameter TPM physical presence
> operation request parameter.
> -
> -  @return Return Code for Submit TPM Operation Request to Pre-OS
> Environment and
> -        Submit TPM Operation Request to Pre-OS Environment 2.
> -  **/
> -UINT32
> -Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunctionEx (
> -  IN OUT UINT32               *OperationRequest,
> -  IN OUT UINT32               *RequestParameter
> -  )
> -{
> -  EFI_STATUS                        Status;
> -  UINT32                            ReturnCode;
> -  UINTN                             DataSize;
> -  EFI_TCG2_PHYSICAL_PRESENCE        PpData;
> -  EFI_TCG2_PHYSICAL_PRESENCE_FLAGS  Flags;
> -
> -  DEBUG ((EFI_D_INFO, "[TPM2] SubmitRequestToPreOSFunction, Request
> = %x, %x\n", *OperationRequest, *RequestParameter));
> -  ReturnCode = TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS;
> -
> -  //
> -  // Get the Physical Presence variable
> -  //
> -  DataSize = sizeof (EFI_TCG2_PHYSICAL_PRESENCE);
> -  Status = mTcg2PpSmmVariable->SmmGetVariable (
> -                                 TCG2_PHYSICAL_PRESENCE_VARIABLE,
> -                                 &gEfiTcg2PhysicalPresenceGuid,
> -                                 NULL,
> -                                 &DataSize,
> -                                 &PpData
> -                                 );
> -  if (EFI_ERROR (Status)) {
> -    DEBUG ((EFI_D_ERROR, "[TPM2] Get PP variable failure! Status = %r\n",
> Status));
> -    ReturnCode =
> TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE;
> -    goto EXIT;
> -  }
> -
> -  if ((*OperationRequest > TCG2_PHYSICAL_PRESENCE_NO_ACTION_MAX)
> &&
> -      (*OperationRequest <
> TCG2_PHYSICAL_PRESENCE_STORAGE_MANAGEMENT_BEGIN) ) {
> -    ReturnCode =
> TCG_PP_SUBMIT_REQUEST_TO_PREOS_NOT_IMPLEMENTED;
> -    goto EXIT;
> -  }
> -
> -  if ((PpData.PPRequest != *OperationRequest) ||
> -      (PpData.PPRequestParameter != *RequestParameter)) {
> -    PpData.PPRequest = (UINT8)*OperationRequest;
> -    PpData.PPRequestParameter = *RequestParameter;
> -    DataSize = sizeof (EFI_TCG2_PHYSICAL_PRESENCE);
> -    Status = mTcg2PpSmmVariable->SmmSetVariable (
> -                                   TCG2_PHYSICAL_PRESENCE_VARIABLE,
> -                                   &gEfiTcg2PhysicalPresenceGuid,
> -                                   EFI_VARIABLE_NON_VOLATILE |
> EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
> -                                   DataSize,
> -                                   &PpData
> -                                   );
> -    if (EFI_ERROR (Status)) {
> -      DEBUG ((EFI_D_ERROR, "[TPM2] Set PP variable failure! Status = %r\n",
> Status));
> -      ReturnCode =
> TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE;
> -      goto EXIT;
> -    }
> -  }
> -
> -  if (*OperationRequest >=
> TCG2_PHYSICAL_PRESENCE_VENDOR_SPECIFIC_OPERATION) {
> -    DataSize = sizeof (EFI_TCG2_PHYSICAL_PRESENCE_FLAGS);
> -    Status = mTcg2PpSmmVariable->SmmGetVariable (
> -                                   TCG2_PHYSICAL_PRESENCE_FLAGS_VARIABLE,
> -                                   &gEfiTcg2PhysicalPresenceGuid,
> -                                   NULL,
> -                                   &DataSize,
> -                                   &Flags
> -                                   );
> -    if (EFI_ERROR (Status)) {
> -      Flags.PPFlags = mTcg2PhysicalPresenceFlags;
> -    }
> -    ReturnCode = Tcg2PpVendorLibSubmitRequestToPreOSFunction
> (*OperationRequest, Flags.PPFlags, *RequestParameter);
> -  }
> -
> -EXIT:
> -  //
> -  // Sync PPRQ/PPRM from PP Variable if PP submission fails
> -  //
> -  if (ReturnCode != TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS) {
> -    DEBUG ((EFI_D_ERROR, "[TPM2] Submit PP Request failure! Sync
> PPRQ/PPRM with PP variable.\n", Status));
> -    DataSize = sizeof (EFI_TCG2_PHYSICAL_PRESENCE);
> -    ZeroMem(&PpData, DataSize);
> -    Status = mTcg2PpSmmVariable->SmmGetVariable (
> -                                   TCG2_PHYSICAL_PRESENCE_VARIABLE,
> -                                   &gEfiTcg2PhysicalPresenceGuid,
> -                                   NULL,
> -                                   &DataSize,
> -                                   &PpData
> -                                   );
> -    *OperationRequest = (UINT32)PpData.PPRequest;
> -    *RequestParameter = PpData.PPRequestParameter;
> -  }
> -
> -  return ReturnCode;
> -}
> -
> -/**
> -  The handler for TPM physical presence function:
> -  Submit TPM Operation Request to Pre-OS Environment and
> -  Submit TPM Operation Request to Pre-OS Environment 2.
> -
> -  This API should be invoked in OS runtime phase to interface with ACPI
> method.
> -
> -  Caution: This function may receive untrusted input.
> -
> -  @param[in]      OperationRequest TPM physical presence operation
> request.
> -  @param[in]      RequestParameter TPM physical presence operation
> request parameter.
> -
> -  @return Return Code for Submit TPM Operation Request to Pre-OS
> Environment and
> -          Submit TPM Operation Request to Pre-OS Environment 2.
> -**/
> -UINT32
> -EFIAPI
> -Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction (
> -  IN UINT32                 OperationRequest,
> -  IN UINT32                 RequestParameter
> -  )
> -{
> -  UINT32                 TempOperationRequest;
> -  UINT32                 TempRequestParameter;
> -
> -  TempOperationRequest = OperationRequest;
> -  TempRequestParameter = RequestParameter;
> -
> -  return
> Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunctionEx(&TempOperatio
> nRequest, &TempRequestParameter);
> -}
> -
> -/**
> -  The handler for TPM physical presence function:
> -  Get User Confirmation Status for Operation.
> -
> -  This API should be invoked in OS runtime phase to interface with ACPI
> method.
> -
> -  Caution: This function may receive untrusted input.
> -
> -  @param[in]      OperationRequest TPM physical presence operation
> request.
> -
> -  @return Return Code for Get User Confirmation Status for Operation.
> -**/
> -UINT32
> -EFIAPI
> -Tcg2PhysicalPresenceLibGetUserConfirmationStatusFunction (
> -  IN UINT32                 OperationRequest
> -  )
> -{
> -  EFI_STATUS                        Status;
> -  UINTN                             DataSize;
> -  EFI_TCG2_PHYSICAL_PRESENCE        PpData;
> -  EFI_TCG2_PHYSICAL_PRESENCE_FLAGS  Flags;
> -  BOOLEAN                           RequestConfirmed;
> -
> -  DEBUG ((EFI_D_INFO, "[TPM2] GetUserConfirmationStatusFunction,
> Request = %x\n", OperationRequest));
> -
> -  //
> -  // Get the Physical Presence variable
> -  //
> -  DataSize = sizeof (EFI_TCG2_PHYSICAL_PRESENCE);
> -  Status = mTcg2PpSmmVariable->SmmGetVariable (
> -                                 TCG2_PHYSICAL_PRESENCE_VARIABLE,
> -                                 &gEfiTcg2PhysicalPresenceGuid,
> -                                 NULL,
> -                                 &DataSize,
> -                                 &PpData
> -                                 );
> -  if (EFI_ERROR (Status)) {
> -    DEBUG ((EFI_D_ERROR, "[TPM2] Get PP variable failure! Status = %r\n",
> Status));
> -    return
> TCG_PP_GET_USER_CONFIRMATION_BLOCKED_BY_BIOS_CONFIGURATION;
> -  }
> -  //
> -  // Get the Physical Presence flags
> -  //
> -  DataSize = sizeof (EFI_TCG2_PHYSICAL_PRESENCE_FLAGS);
> -  Status = mTcg2PpSmmVariable->SmmGetVariable (
> -                                 TCG2_PHYSICAL_PRESENCE_FLAGS_VARIABLE,
> -                                 &gEfiTcg2PhysicalPresenceGuid,
> -                                 NULL,
> -                                 &DataSize,
> -                                 &Flags
> -                                 );
> -  if (EFI_ERROR (Status)) {
> -    DEBUG ((EFI_D_ERROR, "[TPM2] Get PP flags failure! Status = %r\n",
> Status));
> -    return
> TCG_PP_GET_USER_CONFIRMATION_BLOCKED_BY_BIOS_CONFIGURATION;
> -  }
> -
> -  RequestConfirmed = FALSE;
> -
> -  switch (OperationRequest) {
> -    case TCG2_PHYSICAL_PRESENCE_CLEAR:
> -    case TCG2_PHYSICAL_PRESENCE_ENABLE_CLEAR:
> -    case TCG2_PHYSICAL_PRESENCE_ENABLE_CLEAR_2:
> -    case TCG2_PHYSICAL_PRESENCE_ENABLE_CLEAR_3:
> -      if ((Flags.PPFlags &
> TCG2_BIOS_TPM_MANAGEMENT_FLAG_PP_REQUIRED_FOR_CLEAR) == 0) {
> -        RequestConfirmed = TRUE;
> -      }
> -      break;
> -
> -    case TCG2_PHYSICAL_PRESENCE_NO_ACTION:
> -    case TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_CLEAR_TRUE:
> -      RequestConfirmed = TRUE;
> -      break;
> -
> -    case TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_CLEAR_FALSE:
> -      break;
> -
> -    case TCG2_PHYSICAL_PRESENCE_SET_PCR_BANKS:
> -      if ((Flags.PPFlags &
> TCG2_BIOS_TPM_MANAGEMENT_FLAG_PP_REQUIRED_FOR_CHANGE_PCR
> S) == 0) {
> -        RequestConfirmed = TRUE;
> -      }
> -      break;
> -
> -    case TCG2_PHYSICAL_PRESENCE_CHANGE_EPS:
> -      if ((Flags.PPFlags &
> TCG2_BIOS_TPM_MANAGEMENT_FLAG_PP_REQUIRED_FOR_CHANGE_EPS)
> == 0) {
> -        RequestConfirmed = TRUE;
> -      }
> -      break;
> -
> -    case TCG2_PHYSICAL_PRESENCE_LOG_ALL_DIGESTS:
> -      RequestConfirmed = TRUE;
> -      break;
> -
> -    case TCG2_PHYSICAL_PRESENCE_ENABLE_BLOCK_SID:
> -      if ((Flags.PPFlags &
> TCG2_BIOS_STORAGE_MANAGEMENT_FLAG_PP_REQUIRED_FOR_ENABLE_
> BLOCK_SID) == 0) {
> -        RequestConfirmed = TRUE;
> -      }
> -      break;
> -
> -    case TCG2_PHYSICAL_PRESENCE_DISABLE_BLOCK_SID:
> -      if ((Flags.PPFlags &
> TCG2_BIOS_STORAGE_MANAGEMENT_FLAG_PP_REQUIRED_FOR_DISABLE
> _BLOCK_SID) == 0) {
> -        RequestConfirmed = TRUE;
> -      }
> -      break;
> -
> -    case
> TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_ENABLE_BLOCK_SID_
> FUNC_TRUE:
> -    case
> TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_DISABLE_BLOCK_SID_
> FUNC_TRUE:
> -      RequestConfirmed = TRUE;
> -      break;
> -
> -    case
> TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_ENABLE_BLOCK_SID_
> FUNC_FALSE:
> -    case
> TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_DISABLE_BLOCK_SID_
> FUNC_FALSE:
> -      break;
> -
> -    default:
> -      if (!mIsTcg2PPVerLowerThan_1_3) {
> -        if (OperationRequest <
> TCG2_PHYSICAL_PRESENCE_VENDOR_SPECIFIC_OPERATION) {
> -          //
> -          // TCG2 PP1.3 spec defined operations that are reserved or un-
> implemented
> -          //
> -          return TCG_PP_GET_USER_CONFIRMATION_NOT_IMPLEMENTED;
> -        }
> -      } else {
> -       //
> -       // TCG PP lower than 1.3. (1.0, 1.1, 1.2)
> -       //
> -       if (OperationRequest <=
> TCG2_PHYSICAL_PRESENCE_NO_ACTION_MAX) {
> -         RequestConfirmed = TRUE;
> -       } else if (OperationRequest <
> TCG2_PHYSICAL_PRESENCE_VENDOR_SPECIFIC_OPERATION) {
> -         return TCG_PP_GET_USER_CONFIRMATION_NOT_IMPLEMENTED;
> -       }
> -      }
> -      break;
> -  }
> -
> -  if (OperationRequest >=
> TCG2_PHYSICAL_PRESENCE_VENDOR_SPECIFIC_OPERATION) {
> -    return Tcg2PpVendorLibGetUserConfirmationStatusFunction
> (OperationRequest, Flags.PPFlags);
> -  }
> -
> -  if (RequestConfirmed) {
> -    return
> TCG_PP_GET_USER_CONFIRMATION_ALLOWED_AND_PPUSER_NOT_REQUI
> RED;
> -  } else {
> -    return
> TCG_PP_GET_USER_CONFIRMATION_ALLOWED_AND_PPUSER_REQUIRED;
> -  }
> -}
> +#include "MmTcg2PhysicalPresenceLibCommon.h"
> 
>  /**
>    The constructor function locates SmmVariable protocol.
> @@ -380,24 +32,10 @@
> Tcg2PhysicalPresenceLibGetUserConfirmationStatusFunction (
>  **/
>  EFI_STATUS
>  EFIAPI
> -Tcg2PhysicalPresenceLibConstructor (
> +Tcg2PhysicalPresenceLibTraditionalConstructor (
>    IN EFI_HANDLE        ImageHandle,
>    IN EFI_SYSTEM_TABLE  *SystemTable
>    )
>  {
> -  EFI_STATUS  Status;
> -
> -  if (AsciiStrnCmp(PP_INF_VERSION_1_2, (CHAR8
> *)PcdGetPtr(PcdTcgPhysicalPresenceInterfaceVer),
> sizeof(PP_INF_VERSION_1_2) - 1) >= 0) {
> -    mIsTcg2PPVerLowerThan_1_3 = TRUE;
> -  }
> -
> -  //
> -  // Locate SmmVariableProtocol.
> -  //
> -  Status = gSmst->SmmLocateProtocol (&gEfiSmmVariableProtocolGuid,
> NULL, (VOID**)&mTcg2PpSmmVariable);
> -  ASSERT_EFI_ERROR (Status);
> -
> -  mTcg2PhysicalPresenceFlags = PcdGet32(PcdTcg2PhysicalPresenceFlags);
> -
> -  return EFI_SUCCESS;
> +  return Tcg2PhysicalPresenceLibCommonConstructor ();
>  }
> diff --git
> a/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/StandaloneMmTcg2Ph
> ysicalPresenceLib.c
> b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/StandaloneMmTcg2Ph
> ysicalPresenceLib.c
> new file mode 100644
> index 000000000000..5c298a8d5720
> --- /dev/null
> +++
> b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/StandaloneMmTcg2Ph
> ysicalPresenceLib.c
> @@ -0,0 +1,42 @@
> +/** @file
> +  Handle TPM 2.0 physical presence requests from OS.
> +
> +  This library will handle TPM 2.0 physical presence request from OS.
> +
> +  Caution: This module requires additional review when modified.
> +  This driver will have external input - variable.
> +  This external input must be validated carefully to avoid security issue.
> +
> +  Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction() and
> Tcg2PhysicalPresenceLibGetUserConfirmationStatusFunction()
> +  will receive untrusted input and do validation.
> +
> +Copyright (c) 2015 - 2020, Intel Corporation. All rights reserved.<BR>
> +Copyright (c) Microsoft Corporation.
> +SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <PiMm.h>
> +
> +#include "MmTcg2PhysicalPresenceLibCommon.h"
> +
> +/**
> +  The constructor function locates SmmVariable protocol.
> +
> +  It will ASSERT() if that operation fails and it will always return
> EFI_SUCCESS.
> +
> +  @param  ImageHandle   The firmware allocated handle for the EFI image.
> +  @param  SystemTable   A pointer to the EFI System Table.
> +
> +  @retval EFI_SUCCESS   The constructor successfully added string package.
> +  @retval Other value   The constructor can't add string package.
> +**/
> +EFI_STATUS
> +EFIAPI
> +Tcg2PhysicalPresenceLibStandaloneMmConstructor (
> +  IN EFI_HANDLE           ImageHandle,
> +  IN EFI_MM_SYSTEM_TABLE  *SystemTable
> +  )
> +{
> +  return Tcg2PhysicalPresenceLibCommonConstructor ();
> +}
> diff --git
> a/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/MmTcg2PhysicalPrese
> nceLibCommon.h
> b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/MmTcg2PhysicalPrese
> nceLibCommon.h
> new file mode 100644
> index 000000000000..c53674d37f12
> --- /dev/null
> +++
> b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/MmTcg2PhysicalPrese
> nceLibCommon.h
> @@ -0,0 +1,35 @@
> +/** @file
> +  Handle TPM 2.0 physical presence requests from OS.
> +
> +  This library will handle TPM 2.0 physical presence request from OS.
> +
> +  Caution: This module requires additional review when modified.
> +  This driver will have external input - variable.
> +  This external input must be validated carefully to avoid security issue.
> +
> +  Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction() and
> Tcg2PhysicalPresenceLibGetUserConfirmationStatusFunction()
> +  will receive untrusted input and do validation.
> +
> +Copyright (c) 2015 - 2020, Intel Corporation. All rights reserved.<BR>
> +SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#ifndef _MM_TCG2_PHYSICAL_PRESENCE_LIB_COMMON_H_
> +#define _MM_TCG2_PHYSICAL_PRESENCE_LIB_COMMON_H_
> +
> +/**
> +  The constructor function locates MmVariable protocol.
> +
> +  It will ASSERT() if that operation fails and it will always return
> EFI_SUCCESS.
> +
> +  @retval EFI_SUCCESS   The constructor successfully added string package.
> +  @retval Other value   The constructor can't add string package.
> +**/
> +EFI_STATUS
> +EFIAPI
> +Tcg2PhysicalPresenceLibCommonConstructor (
> +  VOID
> +  );
> +
> +#endif
> diff --git
> a/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPres
> enceLib.inf
> b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPres
> enceLib.inf
> index 6a9bdf66f0a6..d911adbdb648 100644
> ---
> a/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPres
> enceLib.inf
> +++
> b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPres
> enceLib.inf
> @@ -20,7 +20,7 @@ [Defines]
>    MODULE_TYPE                    = DXE_SMM_DRIVER
>    VERSION_STRING                 = 1.0
>    LIBRARY_CLASS                  = Tcg2PhysicalPresenceLib|DXE_SMM_DRIVER
> -  CONSTRUCTOR                    = Tcg2PhysicalPresenceLibConstructor
> +  CONSTRUCTOR                    =
> Tcg2PhysicalPresenceLibTraditionalConstructor
> 
>  #
>  # The following information is for reference only and not required by the
> build tools.
> @@ -30,6 +30,8 @@ [Defines]
> 
>  [Sources]
>    SmmTcg2PhysicalPresenceLib.c
> +  MmTcg2PhysicalPresenceLibCommon.c
> +  MmTcg2PhysicalPresenceLibCommon.h
> 
>  [Packages]
>    MdePkg/MdePkg.dec
> @@ -39,7 +41,7 @@ [Packages]
>  [LibraryClasses]
>    DebugLib
>    Tcg2PpVendorLib
> -  SmmServicesTableLib
> +  MmServicesTableLib
>    BaseMemoryLib
> 
>  [Guids]
> diff --git
> a/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPres
> enceLib.inf
> b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/StandaloneMmTcg2Ph
> ysicalPresenceLib.inf
> similarity index 64%
> copy from
> SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresen
> ceLib.inf
> copy to
> SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/StandaloneMmTcg2Phys
> icalPresenceLib.inf
> index 6a9bdf66f0a6..6d11b6b9f198 100644
> ---
> a/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPres
> enceLib.inf
> +++
> b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/StandaloneMmTcg2Ph
> ysicalPresenceLib.inf
> @@ -8,19 +8,20 @@
>  #  This external input must be validated carefully to avoid security issue.
>  #
>  # Copyright (c) 2015 - 2020, Intel Corporation. All rights reserved.<BR>
> +# Copyright (c) Microsoft Corporation.
>  # SPDX-License-Identifier: BSD-2-Clause-Patent
>  #
>  ##
> 
>  [Defines]
>    INF_VERSION                    = 0x00010005
> -  BASE_NAME                      = SmmTcg2PhysicalPresenceLib
> -  MODULE_UNI_FILE                = SmmTcg2PhysicalPresenceLib.uni
> -  FILE_GUID                      = AAE02741-858B-4964-9887-CA870489D944
> -  MODULE_TYPE                    = DXE_SMM_DRIVER
> +  BASE_NAME                      = StandaloneMmTcg2PhysicalPresenceLib
> +  FILE_GUID                      = 75E3D07B-689C-4F42-A8A0-46AFAE868A6F
> +  MODULE_TYPE                    = MM_STANDALONE
> +  PI_SPECIFICATION_VERSION       = 0x00010032
>    VERSION_STRING                 = 1.0
> -  LIBRARY_CLASS                  = Tcg2PhysicalPresenceLib|DXE_SMM_DRIVER
> -  CONSTRUCTOR                    = Tcg2PhysicalPresenceLibConstructor
> +  LIBRARY_CLASS                  = Tcg2PhysicalPresenceLib|MM_STANDALONE
> +  CONSTRUCTOR                    =
> Tcg2PhysicalPresenceLibStandaloneMmConstructor
> 
>  #
>  # The following information is for reference only and not required by the
> build tools.
> @@ -29,7 +30,9 @@ [Defines]
>  #
> 
>  [Sources]
> -  SmmTcg2PhysicalPresenceLib.c
> +  StandaloneMmTcg2PhysicalPresenceLib.c
> +  MmTcg2PhysicalPresenceLibCommon.c
> +  MmTcg2PhysicalPresenceLibCommon.h
> 
>  [Packages]
>    MdePkg/MdePkg.dec
> @@ -39,7 +42,7 @@ [Packages]
>  [LibraryClasses]
>    DebugLib
>    Tcg2PpVendorLib
> -  SmmServicesTableLib
> +  MmServicesTableLib
>    BaseMemoryLib
> 
>  [Guids]
> @@ -48,6 +51,9 @@ [Guids]
>    ## SOMETIMES_CONSUMES ## Variable:L"PhysicalPresenceFlags"
>    gEfiTcg2PhysicalPresenceGuid
> 
> +[Protocols]
> +  gEfiSmmVariableProtocolGuid                                       ## CONSUMES
> +
>  [Pcd]
>    gEfiSecurityPkgTokenSpaceGuid.PcdTcgPhysicalPresenceInterfaceVer  ##
> CONSUMES
>    gEfiSecurityPkgTokenSpaceGuid.PcdTcg2PhysicalPresenceFlags        ##
> SOMETIMES_CONSUMES
> diff --git a/SecurityPkg/SecurityPkg.dsc b/SecurityPkg/SecurityPkg.dsc
> index 36d15b79f928..7240b2573e4e 100644
> --- a/SecurityPkg/SecurityPkg.dsc
> +++ b/SecurityPkg/SecurityPkg.dsc
> @@ -150,6 +150,7 @@ [LibraryClasses.common.UEFI_DRIVER,
> LibraryClasses.common.UEFI_APPLICATION]
>  [LibraryClasses.common.DXE_SMM_DRIVER]
>    HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
> 
> SmmServicesTableLib|MdePkg/Library/SmmServicesTableLib/SmmServices
> TableLib.inf
> +
> MmServicesTableLib|MdePkg/Library/MmServicesTableLib/MmServicesTab
> leLib.inf
> 
> MemoryAllocationLib|MdePkg/Library/SmmMemoryAllocationLib/SmmMe
> moryAllocationLib.inf
> 
> ReportStatusCodeLib|MdeModulePkg/Library/SmmReportStatusCodeLib/S
> mmReportStatusCodeLib.inf
>    SmmMemLib|MdePkg/Library/SmmMemLib/SmmMemLib.inf
> @@ -316,6 +317,7 @@ [Components.IA32, Components.X64]
>    SecurityPkg/Tcg/TcgSmm/TcgSmm.inf
>    SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.inf
> 
> SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresen
> ceLib.inf
> +
> SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/StandaloneMmTcg2Phys
> icalPresenceLib.inf
> 
>    #
>    # Random Number Generator
> --
> 2.28.0.windows.1


^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v1 12/15] SecurityPkg: Tcg2PpVendorLibNull: Added support for MM_STANDALONE type
  2020-12-18 18:50 ` [PATCH v1 12/15] SecurityPkg: Tcg2PpVendorLibNull: Added support for MM_STANDALONE type Kun Qin
@ 2020-12-28  0:08   ` Yao, Jiewen
  0 siblings, 0 replies; 44+ messages in thread
From: Yao, Jiewen @ 2020-12-28  0:08 UTC (permalink / raw)
  To: Kun Qin, devel@edk2.groups.io; +Cc: Wang, Jian J, Zhang, Qi1, Kumar, Rahul1

Reviewed-by: Jiewen Yao <Jiewen.yao@intel.com>

> -----Original Message-----
> From: Kun Qin <kun.q@outlook.com>
> Sent: Saturday, December 19, 2020 2:50 AM
> To: devel@edk2.groups.io
> Cc: Yao, Jiewen <jiewen.yao@intel.com>; Wang, Jian J
> <jian.j.wang@intel.com>; Zhang, Qi1 <qi1.zhang@intel.com>; Kumar,
> Rahul1 <rahul1.kumar@intel.com>
> Subject: [PATCH v1 12/15] SecurityPkg: Tcg2PpVendorLibNull: Added
> support for MM_STANDALONE type
> 
> This change extends this null instance of Tcg2PpVendorLib to support
> MM_STANDALONE drivers.
> 
> Cc: Jiewen Yao <jiewen.yao@intel.com>
> Cc: Jian J Wang <jian.j.wang@intel.com>
> Cc: Qi Zhang <qi1.zhang@intel.com>
> Cc: Rahul Kumar <rahul1.kumar@intel.com>
> 
> Signed-off-by: Kun Qin <kun.q@outlook.com>
> ---
>  SecurityPkg/Library/Tcg2PpVendorLibNull/Tcg2PpVendorLibNull.inf | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git
> a/SecurityPkg/Library/Tcg2PpVendorLibNull/Tcg2PpVendorLibNull.inf
> b/SecurityPkg/Library/Tcg2PpVendorLibNull/Tcg2PpVendorLibNull.inf
> index b969cbf9afff..9b18a1ab82f1 100644
> --- a/SecurityPkg/Library/Tcg2PpVendorLibNull/Tcg2PpVendorLibNull.inf
> +++ b/SecurityPkg/Library/Tcg2PpVendorLibNull/Tcg2PpVendorLibNull.inf
> @@ -13,7 +13,7 @@ [Defines]
>    FILE_GUID                      = 51924AE9-BE81-4820-94BA-7C9546E702D0
>    MODULE_TYPE                    = DXE_DRIVER
>    VERSION_STRING                 = 1.0
> -  LIBRARY_CLASS                  = Tcg2PpVendorLib|DXE_RUNTIME_DRIVER
> DXE_SMM_DRIVER DXE_DRIVER
> +  LIBRARY_CLASS                  = Tcg2PpVendorLib|DXE_RUNTIME_DRIVER
> DXE_SMM_DRIVER DXE_DRIVER MM_STANDALONE
> 
>  #
>  # The following information is for reference only and not required by the
> build tools.
> --
> 2.28.0.windows.1


^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v1 13/15] SecurityPkg: Tpm2DeviceLibDTpm: Introduce StandaloneMm instance
  2020-12-18 18:50 ` [PATCH v1 13/15] SecurityPkg: Tpm2DeviceLibDTpm: Introduce StandaloneMm instance Kun Qin
@ 2020-12-28  0:08   ` Yao, Jiewen
  0 siblings, 0 replies; 44+ messages in thread
From: Yao, Jiewen @ 2020-12-28  0:08 UTC (permalink / raw)
  To: Kun Qin, devel@edk2.groups.io; +Cc: Wang, Jian J, Zhang, Qi1, Kumar, Rahul1

Reviewed-by: Jiewen Yao <Jiewen.yao@intel.com>

> -----Original Message-----
> From: Kun Qin <kun.q@outlook.com>
> Sent: Saturday, December 19, 2020 2:50 AM
> To: devel@edk2.groups.io
> Cc: Yao, Jiewen <jiewen.yao@intel.com>; Wang, Jian J
> <jian.j.wang@intel.com>; Zhang, Qi1 <qi1.zhang@intel.com>; Kumar,
> Rahul1 <rahul1.kumar@intel.com>
> Subject: [PATCH v1 13/15] SecurityPkg: Tpm2DeviceLibDTpm: Introduce
> StandaloneMm instance
> 
> This change added a new instance of Tpm2DeviceLibDTpm to support
> drivers
> of type MM_STANDALONE. It abstracts dynamic Pcd access into separate
> file
> for different instances to avoid dynamic usage for StandaloneMm modules.
> 
> Cc: Jiewen Yao <jiewen.yao@intel.com>
> Cc: Jian J Wang <jian.j.wang@intel.com>
> Cc: Qi Zhang <qi1.zhang@intel.com>
> Cc: Rahul Kumar <rahul1.kumar@intel.com>
> 
> Signed-off-by: Kun Qin <kun.q@outlook.com>
> ---
>  SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.c
> | 42 +-----------
>  SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmBase.c
> | 69 ++++++++++++++++++++
> 
> SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmStandalone
> Mm.c                              | 67 +++++++++++++++++++
>  SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.c
> | 40 +-----------
>  SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Ptp.c
> | 15 +++--
>  SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.h
> | 68 +++++++++++++++++++
>  SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf
> |  3 +
>  SecurityPkg/Library/Tpm2DeviceLibDTpm/{Tpm2DeviceLibDTpm.inf =>
> Tpm2DeviceLibDTpmStandaloneMm.inf} | 13 ++--
>  SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.inf
> |  3 +
>  SecurityPkg/SecurityPkg.dsc                                                                        |  1 +
>  10 files changed, 231 insertions(+), 90 deletions(-)
> 
> diff --git a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.c
> b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.c
> index 42e1ecbce95a..238389dbdb1b 100644
> --- a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.c
> +++ b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.c
> @@ -13,29 +13,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
>  #include <Library/Tpm2DeviceLib.h>
>  #include <Library/PcdLib.h>
> 
> -/**
> -  Return PTP interface type.
> -
> -  @param[in] Register                Pointer to PTP register.
> -
> -  @return PTP interface type.
> -**/
> -TPM2_PTP_INTERFACE_TYPE
> -Tpm2GetPtpInterface (
> -  IN VOID *Register
> -  );
> -
> -/**
> -  Return PTP CRB interface IdleByPass state.
> -
> -  @param[in] Register                Pointer to PTP register.
> -
> -  @return PTP CRB interface IdleByPass state.
> -**/
> -UINT8
> -Tpm2GetIdleByPass (
> -  IN VOID *Register
> -  );
> +#include "Tpm2DeviceLibDTpm.h"
> 
>  /**
>    This service enables the sending of commands to the TPM2.
> @@ -145,21 +123,5 @@ Tpm2DeviceLibConstructor (
>    VOID
>    )
>  {
> -  TPM2_PTP_INTERFACE_TYPE  PtpInterface;
> -  UINT8                    IdleByPass;
> -
> -  //
> -  // Cache current active TpmInterfaceType only when needed
> -  //
> -  if (PcdGet8(PcdActiveTpmInterfaceType) == 0xFF) {
> -    PtpInterface = Tpm2GetPtpInterface ((VOID *) (UINTN) PcdGet64
> (PcdTpmBaseAddress));
> -    PcdSet8S(PcdActiveTpmInterfaceType, PtpInterface);
> -  }
> -
> -  if (PcdGet8(PcdActiveTpmInterfaceType) == Tpm2PtpInterfaceCrb &&
> PcdGet8(PcdCRBIdleByPass) == 0xFF) {
> -    IdleByPass = Tpm2GetIdleByPass((VOID *) (UINTN) PcdGet64
> (PcdTpmBaseAddress));
> -    PcdSet8S(PcdCRBIdleByPass, IdleByPass);
> -  }
> -
> -  return EFI_SUCCESS;
> +  return InternalTpm2DeviceLibDTpmCommonConstructor ();
>  }
> diff --git
> a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmBase.c
> b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmBase.c
> new file mode 100644
> index 000000000000..aaa215eee9f7
> --- /dev/null
> +++
> b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmBase.c
> @@ -0,0 +1,69 @@
> +/** @file
> +  This file abstract internal interfaces of which implementation differs per
> library instance.
> +
> +Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved. <BR>
> +Copyright (c) Microsoft Corporation.
> +SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <Library/Tpm2DeviceLib.h>
> +#include <Library/PcdLib.h>
> +
> +#include "Tpm2DeviceLibDTpm.h"
> +
> +/**
> +  Return cached PTP CRB interface IdleByPass state.
> +
> +  @return Cached PTP CRB interface IdleByPass state.
> +**/
> +UINT8
> +GetCachedIdleByPass (
> +  VOID
> +  )
> +{
> +  return PcdGet8(PcdCRBIdleByPass);
> +}
> +
> +/**
> +  Return cached PTP interface type.
> +
> +  @return Cached PTP interface type.
> +**/
> +TPM2_PTP_INTERFACE_TYPE
> +GetCachedPtpInterface (
> +  VOID
> +  )
> +{
> +  return PcdGet8(PcdActiveTpmInterfaceType);
> +}
> +
> +/**
> +  The common function cache current active TpmInterfaceType when
> needed.
> +
> +  @retval EFI_SUCCESS   DTPM2.0 instance is registered, or system does
> not support register DTPM2.0 instance
> +**/
> +EFI_STATUS
> +EFIAPI
> +InternalTpm2DeviceLibDTpmCommonConstructor (
> +  VOID
> +  )
> +{
> +  TPM2_PTP_INTERFACE_TYPE  PtpInterface;
> +  UINT8                    IdleByPass;
> +
> +  //
> +  // Cache current active TpmInterfaceType only when needed
> +  //
> +  if (PcdGet8(PcdActiveTpmInterfaceType) == 0xFF) {
> +    PtpInterface = Tpm2GetPtpInterface ((VOID *) (UINTN) PcdGet64
> (PcdTpmBaseAddress));
> +    PcdSet8S(PcdActiveTpmInterfaceType, PtpInterface);
> +  }
> +
> +  if (PcdGet8(PcdActiveTpmInterfaceType) == Tpm2PtpInterfaceCrb &&
> PcdGet8(PcdCRBIdleByPass) == 0xFF) {
> +    IdleByPass = Tpm2GetIdleByPass((VOID *) (UINTN) PcdGet64
> (PcdTpmBaseAddress));
> +    PcdSet8S(PcdCRBIdleByPass, IdleByPass);
> +  }
> +
> +  return EFI_SUCCESS;
> +}
> diff --git
> a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmStandalon
> eMm.c
> b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmStandalon
> eMm.c
> new file mode 100644
> index 000000000000..9e3d3f0a8e9d
> --- /dev/null
> +++
> b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmStandalon
> eMm.c
> @@ -0,0 +1,67 @@
> +/** @file
> +  This file abstract internal interfaces of which implementation differs per
> library instance.
> +
> +Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved. <BR>
> +Copyright (c) Microsoft Corporation.
> +SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <Library/Tpm2DeviceLib.h>
> +
> +#include "Tpm2DeviceLibDTpm.h"
> +
> +TPM2_PTP_INTERFACE_TYPE  mActiveTpmInterfaceType;
> +UINT8                    mCRBIdleByPass;
> +
> +/**
> +  Return cached PTP CRB interface IdleByPass state.
> +
> +  @return Cached PTP CRB interface IdleByPass state.
> +**/
> +UINT8
> +GetCachedIdleByPass (
> +  VOID
> +  )
> +{
> +  return mCRBIdleByPass;
> +}
> +
> +/**
> +  Return cached PTP interface type.
> +
> +  @return Cached PTP interface type.
> +**/
> +TPM2_PTP_INTERFACE_TYPE
> +GetCachedPtpInterface (
> +  VOID
> +  )
> +{
> +  return mActiveTpmInterfaceType;
> +}
> +
> +/**
> +  The common function cache current active TpmInterfaceType when
> needed.
> +
> +  @retval EFI_SUCCESS   DTPM2.0 instance is registered, or system does
> not support register DTPM2.0 instance
> +**/
> +EFI_STATUS
> +EFIAPI
> +InternalTpm2DeviceLibDTpmCommonConstructor (
> +  VOID
> +  )
> +{
> +  mActiveTpmInterfaceType = 0xFF;
> +  mCRBIdleByPass = 0xFF;
> +
> +  //
> +  // Always cache current active TpmInterfaceType for StandaloneMm
> implementation
> +  //
> +  mActiveTpmInterfaceType = Tpm2GetPtpInterface ((VOID *) (UINTN)
> PcdGet64 (PcdTpmBaseAddress));
> +
> +  if (mActiveTpmInterfaceType == Tpm2PtpInterfaceCrb) {
> +    mCRBIdleByPass = Tpm2GetIdleByPass((VOID *) (UINTN) PcdGet64
> (PcdTpmBaseAddress));
> +  }
> +
> +  return EFI_SUCCESS;
> +}
> diff --git
> a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.c
> b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.c
> index 691eaa40c045..053e597d2ee2 100644
> --- a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.c
> +++ b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.c
> @@ -16,29 +16,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
> 
>  #include <Guid/TpmInstance.h>
> 
> -/**
> -  Return PTP interface type.
> -
> -  @param[in] Register                Pointer to PTP register.
> -
> -  @return PTP interface type.
> -**/
> -TPM2_PTP_INTERFACE_TYPE
> -Tpm2GetPtpInterface (
> -  IN VOID *Register
> -  );
> -
> -/**
> -  Return PTP CRB interface IdleByPass state.
> -
> -  @param[in] Register                Pointer to PTP register.
> -
> -  @return PTP CRB interface IdleByPass state.
> -**/
> -UINT8
> -Tpm2GetIdleByPass (
> -  IN VOID *Register
> -  );
> +#include "Tpm2DeviceLibDTpm.h"
> 
>  /**
>    Dump PTP register information.
> @@ -102,8 +80,6 @@ Tpm2InstanceLibDTpmConstructor (
>    )
>  {
>    EFI_STATUS               Status;
> -  TPM2_PTP_INTERFACE_TYPE  PtpInterface;
> -  UINT8                    IdleByPass;
> 
>    Status = Tpm2RegisterTpm2DeviceLib (&mDTpm2InternalTpm2Device);
>    if ((Status == EFI_SUCCESS) || (Status == EFI_UNSUPPORTED)) {
> @@ -111,19 +87,7 @@ Tpm2InstanceLibDTpmConstructor (
>      // Unsupported means platform policy does not need this instance
> enabled.
>      //
>      if (Status == EFI_SUCCESS) {
> -      //
> -      // Cache current active TpmInterfaceType only when needed
> -      //
> -      if (PcdGet8(PcdActiveTpmInterfaceType) == 0xFF) {
> -        PtpInterface = Tpm2GetPtpInterface ((VOID *) (UINTN) PcdGet64
> (PcdTpmBaseAddress));
> -        PcdSet8S(PcdActiveTpmInterfaceType, PtpInterface);
> -      }
> -
> -      if (PcdGet8(PcdActiveTpmInterfaceType) == Tpm2PtpInterfaceCrb &&
> PcdGet8(PcdCRBIdleByPass) == 0xFF) {
> -        IdleByPass = Tpm2GetIdleByPass((VOID *) (UINTN) PcdGet64
> (PcdTpmBaseAddress));
> -        PcdSet8S(PcdCRBIdleByPass, IdleByPass);
> -      }
> -
> +      Status = InternalTpm2DeviceLibDTpmCommonConstructor ();
>        DumpPtpInfo ((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));
>      }
>      return EFI_SUCCESS;
> diff --git a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Ptp.c
> b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Ptp.c
> index 2c73385b6ce5..f1f80916834f 100644
> --- a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Ptp.c
> +++ b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Ptp.c
> @@ -2,6 +2,7 @@
>    PTP (Platform TPM Profile) CRB (Command Response Buffer) interface
> used by dTPM2.0 library.
> 
>  Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>
> +Copyright (c), Microsoft Corporation.
>  SPDX-License-Identifier: BSD-2-Clause-Patent
> 
>  **/
> @@ -19,6 +20,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
>  #include <IndustryStandard/TpmPtp.h>
>  #include <IndustryStandard/TpmTis.h>
> 
> +#include "Tpm2DeviceLibDTpm.h"
> +
>  //
>  // Execution of the command may take from several seconds to minutes
> for certain
>  // commands, such as key generation.
> @@ -174,7 +177,7 @@ PtpCrbTpmCommand (
>    // STEP 0:
>    // if CapCRbIdelByPass == 0, enforce Idle state before sending command
>    //
> -  if (PcdGet8(PcdCRBIdleByPass) == 0 && (MmioRead32((UINTN)&CrbReg-
> >CrbControlStatus) & PTP_CRB_CONTROL_AREA_STATUS_TPM_IDLE) == 0){
> +  if (GetCachedIdleByPass () == 0 && (MmioRead32((UINTN)&CrbReg-
> >CrbControlStatus) & PTP_CRB_CONTROL_AREA_STATUS_TPM_IDLE) == 0){
>      Status = PtpCrbWaitRegisterBits (
>                &CrbReg->CrbControlStatus,
>                PTP_CRB_CONTROL_AREA_STATUS_TPM_IDLE,
> @@ -330,7 +333,7 @@ PtpCrbTpmCommand (
>    // Goto Ready State if command is completed successfully and TPM
> support IdleBypass
>    // If not supported. flow down to GoIdle
>    //
> -  if (PcdGet8(PcdCRBIdleByPass) == 1) {
> +  if (GetCachedIdleByPass () == 1) {
>      MmioWrite32((UINTN)&CrbReg->CrbControlRequest,
> PTP_CRB_CONTROL_AREA_REQUEST_COMMAND_READY);
>      return Status;
>    }
> @@ -350,7 +353,7 @@ PtpCrbTpmCommand (
>    // Only enforce Idle state transition if execution fails when
> CRBIdleBypass==1
>    // Leave regular Idle delay at the beginning of next command execution
>    //
> -  if (PcdGet8(PcdCRBIdleByPass) == 1){
> +  if (GetCachedIdleByPass () == 1){
>      Status = PtpCrbWaitRegisterBits (
>                 &CrbReg->CrbControlStatus,
>                 PTP_CRB_CONTROL_AREA_STATUS_TPM_IDLE,
> @@ -519,7 +522,7 @@ DumpPtpInfo (
>    Vid = 0xFFFF;
>    Did = 0xFFFF;
>    Rid = 0xFF;
> -  PtpInterface = PcdGet8(PcdActiveTpmInterfaceType);
> +  PtpInterface = GetCachedPtpInterface ();
>    DEBUG ((EFI_D_INFO, "PtpInterface - %x\n", PtpInterface));
>    switch (PtpInterface) {
>    case Tpm2PtpInterfaceCrb:
> @@ -564,7 +567,7 @@ DTpm2SubmitCommand (
>  {
>    TPM2_PTP_INTERFACE_TYPE  PtpInterface;
> 
> -  PtpInterface = PcdGet8(PcdActiveTpmInterfaceType);
> +  PtpInterface = GetCachedPtpInterface ();
>    switch (PtpInterface) {
>    case Tpm2PtpInterfaceCrb:
>      return PtpCrbTpmCommand (
> @@ -603,7 +606,7 @@ DTpm2RequestUseTpm (
>  {
>    TPM2_PTP_INTERFACE_TYPE  PtpInterface;
> 
> -  PtpInterface = PcdGet8(PcdActiveTpmInterfaceType);
> +  PtpInterface = GetCachedPtpInterface ();
>    switch (PtpInterface) {
>    case Tpm2PtpInterfaceCrb:
>      return PtpCrbRequestUseTpm ((PTP_CRB_REGISTERS_PTR) (UINTN)
> PcdGet64 (PcdTpmBaseAddress));
> diff --git a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.h
> b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.h
> new file mode 100644
> index 000000000000..4eabb6cd182e
> --- /dev/null
> +++ b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.h
> @@ -0,0 +1,68 @@
> +/** @file
> +  This header file includes common internal fuction prototypes.
> +
> +Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved. <BR>
> +Copyright (c) Microsoft Corporation.
> +SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#ifndef _TPM2_DEVICE_LIB_DTPM_H_
> +#define _TPM2_DEVICE_LIB_DTPM_H_
> +
> +/**
> +  Return PTP interface type.
> +
> +  @param[in] Register                Pointer to PTP register.
> +
> +  @return PTP interface type.
> +**/
> +TPM2_PTP_INTERFACE_TYPE
> +Tpm2GetPtpInterface (
> +  IN VOID *Register
> +  );
> +
> +/**
> +  Return PTP CRB interface IdleByPass state.
> +
> +  @param[in] Register                Pointer to PTP register.
> +
> +  @return PTP CRB interface IdleByPass state.
> +**/
> +UINT8
> +Tpm2GetIdleByPass (
> +  IN VOID *Register
> +  );
> +
> +/**
> +  Return cached PTP interface type.
> +
> +  @return Cached PTP interface type.
> +**/
> +TPM2_PTP_INTERFACE_TYPE
> +GetCachedPtpInterface (
> +  VOID
> +  );
> +
> +/**
> +  Return cached PTP CRB interface IdleByPass state.
> +
> +  @return Cached PTP CRB interface IdleByPass state.
> +**/
> +UINT8
> +GetCachedIdleByPass (
> +  VOID
> +  );
> +
> +/**
> +  The common function cache current active TpmInterfaceType when
> needed.
> +
> +  @retval EFI_SUCCESS   DTPM2.0 instance is registered, or system does
> not support register DTPM2.0 instance
> +**/
> +EFI_STATUS
> +EFIAPI
> +InternalTpm2DeviceLibDTpmCommonConstructor (
> +  VOID
> +  );
> +
> +#endif // _TPM2_DEVICE_LIB_DTPM_H_
> diff --git
> a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf
> b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf
> index 2b627504634d..be3a0053ccce 100644
> --- a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf
> +++ b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf
> @@ -11,6 +11,7 @@
>  #  only uses TPM 2.0 DTPM device.
>  #
>  # Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
> +# Copyright (c) Microsoft Corporation.
>  # SPDX-License-Identifier: BSD-2-Clause-Patent
>  #
>  ##
> @@ -34,6 +35,8 @@ [Sources]
>    Tpm2Tis.c
>    Tpm2Ptp.c
>    Tpm2DeviceLibDTpm.c
> +  Tpm2DeviceLibDTpmBase.c
> +  Tpm2DeviceLibDTpm.h
> 
>  [Packages]
>    MdePkg/MdePkg.dec
> diff --git
> a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf
> b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmStandalon
> eMm.inf
> similarity index 70%
> copy from
> SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf
> copy to
> SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmStandalone
> Mm.inf
> index 2b627504634d..18c08ad8bdcc 100644
> --- a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf
> +++
> b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmStandalon
> eMm.inf
> @@ -11,19 +11,20 @@
>  #  only uses TPM 2.0 DTPM device.
>  #
>  # Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
> +# Copyright (c) Microsoft Corporation.
>  # SPDX-License-Identifier: BSD-2-Clause-Patent
>  #
>  ##
> 
>  [Defines]
>    INF_VERSION                    = 0x00010005
> -  BASE_NAME                      = Tpm2DeviceLibDTpm
> -  MODULE_UNI_FILE                = Tpm2DeviceLibDTpm.uni
> -  FILE_GUID                      = E54A3327-A345-4068-8842-70AC0D519855
> +  BASE_NAME                      = Tpm2DeviceLibDTpmStandaloneMm
> +  FILE_GUID                      = 9A5DB21A-FF0B-46D0-8672-B4F83FEF1F0E
>    MODULE_TYPE                    = BASE
>    VERSION_STRING                 = 1.0
> -  LIBRARY_CLASS                  = Tpm2DeviceLib|PEIM DXE_DRIVER
> DXE_RUNTIME_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER
> +  LIBRARY_CLASS                  = Tpm2DeviceLib|MM_STANDALONE
>    CONSTRUCTOR                    = Tpm2DeviceLibConstructor
> +
>  #
>  # The following information is for reference only and not required by the
> build tools.
>  #
> @@ -34,6 +35,8 @@ [Sources]
>    Tpm2Tis.c
>    Tpm2Ptp.c
>    Tpm2DeviceLibDTpm.c
> +  Tpm2DeviceLibDTpmStandaloneMm.c
> +  Tpm2DeviceLibDTpm.h
> 
>  [Packages]
>    MdePkg/MdePkg.dec
> @@ -49,5 +52,3 @@ [LibraryClasses]
> 
>  [Pcd]
>    gEfiSecurityPkgTokenSpaceGuid.PcdTpmBaseAddress            ##
> CONSUMES
> -  gEfiSecurityPkgTokenSpaceGuid.PcdActiveTpmInterfaceType    ##
> PRODUCES
> -  gEfiSecurityPkgTokenSpaceGuid.PcdCRBIdleByPass             ## PRODUCES
> diff --git
> a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.inf
> b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.inf
> index 5f267f552ce3..31113d93ee41 100644
> --- a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.inf
> +++ b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.inf
> @@ -6,6 +6,7 @@
>  #  and PTP (Platform TPM Profile) functions.
>  #
>  # Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
> +# Copyright (c) Microsoft Corporation
>  # SPDX-License-Identifier: BSD-2-Clause-Patent
>  #
>  ##
> @@ -30,6 +31,8 @@ [Sources]
>    Tpm2Tis.c
>    Tpm2Ptp.c
>    Tpm2InstanceLibDTpm.c
> +  Tpm2DeviceLibDTpmBase.c
> +  Tpm2DeviceLibDTpm.h
> 
>  [Packages]
>    MdePkg/MdePkg.dec
> diff --git a/SecurityPkg/SecurityPkg.dsc b/SecurityPkg/SecurityPkg.dsc
> index 7240b2573e4e..618420a56c33 100644
> --- a/SecurityPkg/SecurityPkg.dsc
> +++ b/SecurityPkg/SecurityPkg.dsc
> @@ -211,6 +211,7 @@ [Components]
>    SecurityPkg/Library/Tpm2DeviceLibTcg2/Tpm2DeviceLibTcg2.inf
>    SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf
>    SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.inf
> +
> SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmStandalone
> Mm.inf
>    SecurityPkg/Library/Tpm2DeviceLibRouter/Tpm2DeviceLibRouterDxe.inf
>    SecurityPkg/Library/Tpm2DeviceLibRouter/Tpm2DeviceLibRouterPei.inf
> 
> --
> 2.28.0.windows.1


^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [edk2-devel] [PATCH v1 01/15] StandaloneMmPkg: StandaloneMmCoreEntryPoint: Extends support for X64
  2020-12-18 18:49 ` [PATCH v1 01/15] StandaloneMmPkg: StandaloneMmCoreEntryPoint: Extends support for X64 Kun Qin
@ 2020-12-28  0:11   ` Yao, Jiewen
  0 siblings, 0 replies; 44+ messages in thread
From: Yao, Jiewen @ 2020-12-28  0:11 UTC (permalink / raw)
  To: devel@edk2.groups.io, kun.q@outlook.com
  Cc: Ard Biesheuvel, Sami Mujawar, Supreeth Venkatesh

Reviewed-by: Jiewen Yao <Jiewen.yao@intel.com>

> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Kun Qin
> Sent: Saturday, December 19, 2020 2:50 AM
> To: devel@edk2.groups.io
> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>; Sami Mujawar
> <sami.mujawar@arm.com>; Yao, Jiewen <jiewen.yao@intel.com>; Supreeth
> Venkatesh <supreeth.venkatesh@arm.com>
> Subject: [edk2-devel] [PATCH v1 01/15] StandaloneMmPkg:
> StandaloneMmCoreEntryPoint: Extends support for X64
> 
> This change extends StandaloneMmCoreEntryPoint library to support X64
> architecture.
> 
> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
> Cc: Sami Mujawar <sami.mujawar@arm.com>
> Cc: Jiewen Yao <jiewen.yao@intel.com>
> Cc: Supreeth Venkatesh <supreeth.venkatesh@arm.com>
> 
> Signed-off-by: Kun Qin <kun.q@outlook.com>
> ---
> 
> StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/X64/Standalone
> MmCoreEntryPoint.c | 71 ++++++++++++++++++++
> 
> StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMm
> CoreEntryPoint.inf   |  3 +
>  2 files changed, 74 insertions(+)
> 
> diff --git
> a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/X64/Standalo
> neMmCoreEntryPoint.c
> b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/X64/Standalo
> neMmCoreEntryPoint.c
> new file mode 100644
> index 000000000000..dffa965b8425
> --- /dev/null
> +++
> b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/X64/Standalo
> neMmCoreEntryPoint.c
> @@ -0,0 +1,71 @@
> +/** @file
> +  Entry point to the Standalone Mm Core.
> +
> +Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
> +Copyright (c) Microsoft Corporation.
> +SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +
> +#include <PiMm.h>
> +
> +#include <Library/StandaloneMmCoreEntryPoint.h>
> +#include <Library/DebugLib.h>
> +#include <Library/BaseLib.h>
> +
> +//
> +// Cache copy of HobList pointer.
> +//
> +VOID *gHobList = NULL;
> +
> +/**
> +  The entry point of PE/COFF Image for the STANDALONE MM Core.
> +
> +  This function is the entry point for the STANDALONE MM Core. This
> function is required to call
> +  ProcessModuleEntryPointList() and ProcessModuleEntryPointList() is
> never expected to return.
> +  The STANDALONE MM Core is responsible for calling
> ProcessLibraryConstructorList() as soon as the EFI
> +  System Table and the image handle for the STANDALONE MM Core itself
> have been established.
> +  If ProcessModuleEntryPointList() returns, then ASSERT() and halt the
> system.
> +
> +  @param  HobStart  Pointer to the beginning of the HOB List passed in
> from the PEI Phase.
> +
> +**/
> +VOID
> +EFIAPI
> +_ModuleEntryPoint (
> +  IN VOID  *HobStart
> +  )
> +{
> +  //
> +  // Cache a pointer to the HobList
> +  //
> +  gHobList = HobStart;
> +
> +  //
> +  // Call the Standalone MM Core entry point
> +  //
> +  ProcessModuleEntryPointList (HobStart);
> +
> +  //
> +  // TODO: Set page table here?? AARCH64 has this step for some reason
> +  //
> +}
> +
> +
> +/**
> +  Required by the EBC compiler and identical in functionality to
> _ModuleEntryPoint().
> +
> +  This function is required to call _ModuleEntryPoint() passing in HobStart.
> +
> +  @param  HobStart  Pointer to the beginning of the HOB List passed in
> from the PEI Phase.
> +
> +**/
> +VOID
> +EFIAPI
> +EfiMain (
> +  IN VOID  *HobStart
> +  )
> +{
> +  _ModuleEntryPoint (HobStart);
> +}
> diff --git
> a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneM
> mCoreEntryPoint.inf
> b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneM
> mCoreEntryPoint.inf
> index 7d6ee4e08ecb..3b7629bc8fb9 100644
> ---
> a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneM
> mCoreEntryPoint.inf
> +++
> b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneM
> mCoreEntryPoint.inf
> @@ -26,6 +26,9 @@ [Sources.AARCH64]
>    AArch64/SetPermissions.c
>    AArch64/CreateHobList.c
> 
> +[Sources.X64]
> +  X64/StandaloneMmCoreEntryPoint.c
> +
>  [Packages]
>    MdePkg/MdePkg.dec
>    MdeModulePkg/MdeModulePkg.dec
> --
> 2.28.0.windows.1
> 
> 
> 
> 
> 


^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v1 02/15] StandaloneMmPkg: StandaloneMmCoreHobLib: Extend support for x64 Mm Core
  2020-12-18 18:49 ` [PATCH v1 02/15] StandaloneMmPkg: StandaloneMmCoreHobLib: Extend support for x64 Mm Core Kun Qin
@ 2020-12-28  0:12   ` Yao, Jiewen
  2021-03-24 20:33     ` [edk2-devel] " Dawn
  0 siblings, 1 reply; 44+ messages in thread
From: Yao, Jiewen @ 2020-12-28  0:12 UTC (permalink / raw)
  To: Kun Qin, devel@edk2.groups.io
  Cc: Ard Biesheuvel, Sami Mujawar, Supreeth Venkatesh

Can we merge the common part between X64 and AArch64 into one Common.c?

> -----Original Message-----
> From: Kun Qin <kun.q@outlook.com>
> Sent: Saturday, December 19, 2020 2:50 AM
> To: devel@edk2.groups.io
> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>; Sami Mujawar
> <sami.mujawar@arm.com>; Yao, Jiewen <jiewen.yao@intel.com>; Supreeth
> Venkatesh <supreeth.venkatesh@arm.com>
> Subject: [PATCH v1 02/15] StandaloneMmPkg: StandaloneMmCoreHobLib:
> Extend support for x64 Mm Core
> 
> This change adds support of x64 version of StandaloneMmCoreHobLib. It
> brings in global variable "gHobList" through StandaloneMmCoreEntryPoint
> and imports implementation from DxeCoreHobLib.inf to support x64 Mm
> Core.
> 
> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
> Cc: Sami Mujawar <sami.mujawar@arm.com>
> Cc: Jiewen Yao <jiewen.yao@intel.com>
> Cc: Supreeth Venkatesh <supreeth.venkatesh@arm.com>
> 
> Signed-off-by: Kun Qin <kun.q@outlook.com>
> ---
>  StandaloneMmPkg/Library/StandaloneMmCoreHobLib/{ =>
> AArch64}/StandaloneMmCoreHobLib.c |   6 +-
>  StandaloneMmPkg/Library/StandaloneMmCoreHobLib/{ =>
> X64}/StandaloneMmCoreHobLib.c     | 426 ++++++++++----------
> 
> StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmCore
> HobLib.inf             |   8 +-
>  3 files changed, 215 insertions(+), 225 deletions(-)
> 
> diff --git
> a/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmCo
> reHobLib.c
> b/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/AArch64/Standal
> oneMmCoreHobLib.c
> similarity index 96%
> copy from
> StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmCore
> HobLib.c
> copy to
> StandaloneMmPkg/Library/StandaloneMmCoreHobLib/AArch64/Standalon
> eMmCoreHobLib.c
> index e3d4743b63f2..006bff816e39 100644
> ---
> a/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmCo
> reHobLib.c
> +++
> b/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/AArch64/Standal
> oneMmCoreHobLib.c
> @@ -13,14 +13,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
>  #include <Library/HobLib.h>
>  #include <Library/DebugLib.h>
>  #include <Library/BaseMemoryLib.h>
> +#include <Library/StandaloneMmCoreEntryPoint.h>
> 
>  #include <Guid/MemoryAllocationHob.h>
> 
> -//
> -// Cache copy of HobList pointer.
> -//
> -VOID *gHobList = NULL;
> -
>  /**
>    Returns the pointer to the HOB list.
> 
> diff --git
> a/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmCo
> reHobLib.c
> b/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/X64/Standalone
> MmCoreHobLib.c
> similarity index 70%
> rename from
> StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmCore
> HobLib.c
> rename to
> StandaloneMmPkg/Library/StandaloneMmCoreHobLib/X64/StandaloneM
> mCoreHobLib.c
> index e3d4743b63f2..69b20bf07a21 100644
> ---
> a/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmCo
> reHobLib.c
> +++
> b/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/X64/Standalone
> MmCoreHobLib.c
> @@ -13,14 +13,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
>  #include <Library/HobLib.h>
>  #include <Library/DebugLib.h>
>  #include <Library/BaseMemoryLib.h>
> +#include <Library/StandaloneMmCoreEntryPoint.h>
> 
>  #include <Guid/MemoryAllocationHob.h>
> 
> -//
> -// Cache copy of HobList pointer.
> -//
> -VOID *gHobList = NULL;
> -
>  /**
>    Returns the pointer to the HOB list.
> 
> @@ -203,48 +199,13 @@ GetBootModeHob (
>    return HandOffHob->BootMode;
>  }
> 
> -VOID *
> -CreateHob (
> -  IN  UINT16    HobType,
> -  IN  UINT16    HobLength
> -  )
> -{
> -  EFI_HOB_HANDOFF_INFO_TABLE  *HandOffHob;
> -  EFI_HOB_GENERIC_HEADER      *HobEnd;
> -  EFI_PHYSICAL_ADDRESS        FreeMemory;
> -  VOID                        *Hob;
> -
> -  HandOffHob = GetHobList ();
> -
> -  HobLength = (UINT16)((HobLength + 0x7) & (~0x7));
> -
> -  FreeMemory = HandOffHob->EfiFreeMemoryTop - HandOffHob-
> >EfiFreeMemoryBottom;
> -
> -  if (FreeMemory < HobLength) {
> -    return NULL;
> -  }
> -
> -  Hob = (VOID*) (UINTN) HandOffHob->EfiEndOfHobList;
> -  ((EFI_HOB_GENERIC_HEADER*) Hob)->HobType = HobType;
> -  ((EFI_HOB_GENERIC_HEADER*) Hob)->HobLength = HobLength;
> -  ((EFI_HOB_GENERIC_HEADER*) Hob)->Reserved = 0;
> -
> -  HobEnd = (EFI_HOB_GENERIC_HEADER*) ((UINTN)Hob + HobLength);
> -  HandOffHob->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN)
> HobEnd;
> -
> -  HobEnd->HobType   = EFI_HOB_TYPE_END_OF_HOB_LIST;
> -  HobEnd->HobLength = sizeof (EFI_HOB_GENERIC_HEADER);
> -  HobEnd->Reserved  = 0;
> -  HobEnd++;
> -  HandOffHob->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN)
> HobEnd;
> -
> -  return Hob;
> -}
> -
>  /**
>    Builds a HOB for a loaded PE32 module.
> 
>    This function builds a HOB for a loaded PE32 module.
> +  It can only be invoked during PEI phase;
> +  for MM phase, it will ASSERT() because PEI HOB is read-only for MM
> phase.
> +
>    If ModuleName is NULL, then ASSERT().
>    If there is no additional space for HOB creation, then ASSERT().
> 
> @@ -263,31 +224,51 @@ BuildModuleHob (
>    IN EFI_PHYSICAL_ADDRESS   EntryPoint
>    )
>  {
> -  EFI_HOB_MEMORY_ALLOCATION_MODULE  *Hob;
> +  //
> +  // PEI HOB is read only for MM phase
> +  //
> +  ASSERT (FALSE);
> +}
> 
> -  ASSERT (((MemoryAllocationModule & (EFI_PAGE_SIZE - 1)) == 0) &&
> -          ((ModuleLength & (EFI_PAGE_SIZE - 1)) == 0));
> +/**
> +  Builds a HOB that describes a chunk of system memory with Owner GUID.
> 
> -  Hob = CreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, sizeof
> (EFI_HOB_MEMORY_ALLOCATION_MODULE));
> +  This function builds a HOB that describes a chunk of system memory.
> +  It can only be invoked during PEI phase;
> +  for MM phase, it will ASSERT() since PEI HOB is read-only for MM phase.
> 
> -  CopyGuid (&(Hob->MemoryAllocationHeader.Name),
> &gEfiHobMemoryAllocModuleGuid);
> -  Hob->MemoryAllocationHeader.MemoryBaseAddress =
> MemoryAllocationModule;
> -  Hob->MemoryAllocationHeader.MemoryLength      = ModuleLength;
> -  Hob->MemoryAllocationHeader.MemoryType        = EfiBootServicesCode;
> +  If there is no additional space for HOB creation, then ASSERT().
> 
> +  @param  ResourceType        The type of resource described by this HOB.
> +  @param  ResourceAttribute   The resource attributes of the memory
> described by this HOB.
> +  @param  PhysicalStart       The 64 bit physical address of memory
> described by this HOB.
> +  @param  NumberOfBytes       The length of the memory described by this
> HOB in bytes.
> +  @param  OwnerGUID           GUID for the owner of this resource.
> +
> +**/
> +VOID
> +EFIAPI
> +BuildResourceDescriptorWithOwnerHob (
> +  IN EFI_RESOURCE_TYPE            ResourceType,
> +  IN EFI_RESOURCE_ATTRIBUTE_TYPE  ResourceAttribute,
> +  IN EFI_PHYSICAL_ADDRESS         PhysicalStart,
> +  IN UINT64                       NumberOfBytes,
> +  IN EFI_GUID                     *OwnerGUID
> +  )
> +{
>    //
> -  // Zero the reserved space to match HOB spec
> +  // PEI HOB is read only for MM phase
>    //
> -  ZeroMem (Hob->MemoryAllocationHeader.Reserved, sizeof (Hob-
> >MemoryAllocationHeader.Reserved));
> -
> -  CopyGuid (&Hob->ModuleName, ModuleName);
> -  Hob->EntryPoint = EntryPoint;
> +  ASSERT (FALSE);
>  }
> 
>  /**
>    Builds a HOB that describes a chunk of system memory.
> 
>    This function builds a HOB that describes a chunk of system memory.
> +  It can only be invoked during PEI phase;
> +  for MM phase, it will ASSERT() because PEI HOB is read-only for MM
> phase.
> +
>    If there is no additional space for HOB creation, then ASSERT().
> 
>    @param  ResourceType        The type of resource described by this HOB.
> @@ -305,31 +286,32 @@ BuildResourceDescriptorHob (
>    IN UINT64                       NumberOfBytes
>    )
>  {
> -  EFI_HOB_RESOURCE_DESCRIPTOR  *Hob;
> -
> -  Hob = CreateHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, sizeof
> (EFI_HOB_RESOURCE_DESCRIPTOR));
> -  ASSERT (Hob != NULL);
> -
> -  Hob->ResourceType      = ResourceType;
> -  Hob->ResourceAttribute = ResourceAttribute;
> -  Hob->PhysicalStart     = PhysicalStart;
> -  Hob->ResourceLength    = NumberOfBytes;
> +  //
> +  // PEI HOB is read only for MM phase
> +  //
> +  ASSERT (FALSE);
>  }
> 
>  /**
> -  Builds a GUID HOB with a certain data length.
> +  Builds a customized HOB tagged with a GUID for identification and
> returns
> +  the start address of GUID HOB data.
> 
>    This function builds a customized HOB tagged with a GUID for
> identification
>    and returns the start address of GUID HOB data so that caller can fill the
> customized data.
>    The HOB Header and Name field is already stripped.
> +  It can only be invoked during PEI phase.
> +  For MM phase, it will ASSERT() because PEI HOB is read-only for MM
> phase.
> +
>    If Guid is NULL, then ASSERT().
>    If there is no additional space for HOB creation, then ASSERT().
> -  If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
> +  If DataLength > (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
> +  HobLength is UINT16 and multiples of 8 bytes, so the max HobLength is
> 0xFFF8.
> 
>    @param  Guid          The GUID to tag the customized HOB.
>    @param  DataLength    The size of the data payload for the GUID HOB.
> 
> -  @return The start address of GUID HOB data.
> +  @retval  NULL         The GUID HOB could not be allocated.
> +  @retval  others       The start address of GUID HOB data.
> 
>  **/
>  VOID *
> @@ -339,35 +321,36 @@ BuildGuidHob (
>    IN UINTN                       DataLength
>    )
>  {
> -  EFI_HOB_GUID_TYPE *Hob;
> -
>    //
> -  // Make sure that data length is not too long.
> +  // PEI HOB is read only for MM phase
>    //
> -  ASSERT (DataLength <= (0xffff - sizeof (EFI_HOB_GUID_TYPE)));
> -
> -  Hob = CreateHob (EFI_HOB_TYPE_GUID_EXTENSION, (UINT16) (sizeof
> (EFI_HOB_GUID_TYPE) + DataLength));
> -  CopyGuid (&Hob->Name, Guid);
> -  return Hob + 1;
> +  ASSERT (FALSE);
> +  return NULL;
>  }
> 
> -
>  /**
> -  Copies a data buffer to a newly-built HOB.
> +  Builds a customized HOB tagged with a GUID for identification, copies the
> input data to the HOB
> +  data field, and returns the start address of the GUID HOB data.
> 
> -  This function builds a customized HOB tagged with a GUID for
> identification,
> -  copies the input data to the HOB data field and returns the start address
> of the GUID HOB data.
> +  This function builds a customized HOB tagged with a GUID for
> identification and copies the input
> +  data to the HOB data field and returns the start address of the GUID HOB
> data.  It can only be
> +  invoked during PEI phase; for MM phase, it will ASSERT() because PEI
> HOB is read-only for MM phase.
>    The HOB Header and Name field is already stripped.
> +  It can only be invoked during PEI phase.
> +  For MM phase, it will ASSERT() because PEI HOB is read-only for MM
> phase.
> +
>    If Guid is NULL, then ASSERT().
>    If Data is NULL and DataLength > 0, then ASSERT().
>    If there is no additional space for HOB creation, then ASSERT().
> -  If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
> +  If DataLength > (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
> +  HobLength is UINT16 and multiples of 8 bytes, so the max HobLength is
> 0xFFF8.
> 
>    @param  Guid          The GUID to tag the customized HOB.
>    @param  Data          The data to be copied into the data field of the GUID
> HOB.
>    @param  DataLength    The size of the data payload for the GUID HOB.
> 
> -  @return The start address of GUID HOB data.
> +  @retval  NULL         The GUID HOB could not be allocated.
> +  @retval  others       The start address of GUID HOB data.
> 
>  **/
>  VOID *
> @@ -378,20 +361,22 @@ BuildGuidDataHob (
>    IN UINTN                       DataLength
>    )
>  {
> -  VOID  *HobData;
> -
> -  ASSERT (Data != NULL || DataLength == 0);
> -
> -  HobData = BuildGuidHob (Guid, DataLength);
> -
> -  return CopyMem (HobData, Data, DataLength);
> +  //
> +  // PEI HOB is read only for MM phase
> +  //
> +  ASSERT (FALSE);
> +  return NULL;
>  }
> 
>  /**
>    Builds a Firmware Volume HOB.
> 
>    This function builds a Firmware Volume HOB.
> +  It can only be invoked during PEI phase;
> +  for MM phase, it will ASSERT() because PEI HOB is read-only for MM
> phase.
> +
>    If there is no additional space for HOB creation, then ASSERT().
> +  If the FvImage buffer is not at its required alignment, then ASSERT().
> 
>    @param  BaseAddress   The base address of the Firmware Volume.
>    @param  Length        The size of the Firmware Volume in bytes.
> @@ -404,24 +389,25 @@ BuildFvHob (
>    IN UINT64                      Length
>    )
>  {
> -  EFI_HOB_FIRMWARE_VOLUME  *Hob;
> -
> -  Hob = CreateHob (EFI_HOB_TYPE_FV, sizeof
> (EFI_HOB_FIRMWARE_VOLUME));
> -
> -  Hob->BaseAddress = BaseAddress;
> -  Hob->Length      = Length;
> +  //
> +  // PEI HOB is read only for MM phase
> +  //
> +  ASSERT (FALSE);
>  }
> 
> -
>  /**
>    Builds a EFI_HOB_TYPE_FV2 HOB.
> 
>    This function builds a EFI_HOB_TYPE_FV2 HOB.
> +  It can only be invoked during PEI phase;
> +  for MM phase, it will ASSERT() because PEI HOB is read-only for MM
> phase.
> +
>    If there is no additional space for HOB creation, then ASSERT().
> +  If the FvImage buffer is not at its required alignment, then ASSERT().
> 
>    @param  BaseAddress   The base address of the Firmware Volume.
>    @param  Length        The size of the Firmware Volume in bytes.
> -  @param  FvName       The name of the Firmware Volume.
> +  @param  FvName        The name of the Firmware Volume.
>    @param  FileName      The name of the file.
> 
>  **/
> @@ -434,21 +420,78 @@ BuildFv2Hob (
>    IN CONST    EFI_GUID                    *FileName
>    )
>  {
> -  EFI_HOB_FIRMWARE_VOLUME2  *Hob;
> +  ASSERT (FALSE);
> +}
> +
> +/**
> +  Builds a EFI_HOB_TYPE_FV3 HOB.
> +
> +  This function builds a EFI_HOB_TYPE_FV3 HOB.
> +  It can only be invoked during PEI phase;
> +  for MM phase, it will ASSERT() since PEI HOB is read-only for MM phase.
> 
> -  Hob = CreateHob (EFI_HOB_TYPE_FV2, sizeof
> (EFI_HOB_FIRMWARE_VOLUME2));
> +  If there is no additional space for HOB creation, then ASSERT().
> +  If the FvImage buffer is not at its required alignment, then ASSERT().
> 
> -  Hob->BaseAddress = BaseAddress;
> -  Hob->Length      = Length;
> -  CopyGuid (&Hob->FvName, FvName);
> -  CopyGuid (&Hob->FileName, FileName);
> +  @param BaseAddress            The base address of the Firmware Volume.
> +  @param Length                 The size of the Firmware Volume in bytes.
> +  @param AuthenticationStatus   The authentication status.
> +  @param ExtractedFv            TRUE if the FV was extracted as a file within
> +                                another firmware volume. FALSE otherwise.
> +  @param FvName                 The name of the Firmware Volume.
> +                                Valid only if IsExtractedFv is TRUE.
> +  @param FileName               The name of the file.
> +                                Valid only if IsExtractedFv is TRUE.
> +
> +**/
> +VOID
> +EFIAPI
> +BuildFv3Hob (
> +  IN          EFI_PHYSICAL_ADDRESS        BaseAddress,
> +  IN          UINT64                      Length,
> +  IN          UINT32                      AuthenticationStatus,
> +  IN          BOOLEAN                     ExtractedFv,
> +  IN CONST    EFI_GUID                    *FvName, OPTIONAL
> +  IN CONST    EFI_GUID                    *FileName OPTIONAL
> +  )
> +{
> +  ASSERT (FALSE);
>  }
> 
> +/**
> +  Builds a Capsule Volume HOB.
> +
> +  This function builds a Capsule Volume HOB.
> +  It can only be invoked during PEI phase;
> +  for MM phase, it will ASSERT() because PEI HOB is read-only for MM
> phase.
> +
> +  If the platform does not support Capsule Volume HOBs, then ASSERT().
> +  If there is no additional space for HOB creation, then ASSERT().
> +
> +  @param  BaseAddress   The base address of the Capsule Volume.
> +  @param  Length        The size of the Capsule Volume in bytes.
> +
> +**/
> +VOID
> +EFIAPI
> +BuildCvHob (
> +  IN EFI_PHYSICAL_ADDRESS        BaseAddress,
> +  IN UINT64                      Length
> +  )
> +{
> +  //
> +  // PEI HOB is read only for MM phase
> +  //
> +  ASSERT (FALSE);
> +}
> 
>  /**
>    Builds a HOB for the CPU.
> 
>    This function builds a HOB for the CPU.
> +  It can only be invoked during PEI phase;
> +  for MM phase, it will ASSERT() because PEI HOB is read-only for MM
> phase.
> +
>    If there is no additional space for HOB creation, then ASSERT().
> 
>    @param  SizeOfMemorySpace   The maximum physical memory
> addressability of the processor.
> @@ -462,122 +505,9 @@ BuildCpuHob (
>    IN UINT8                       SizeOfIoSpace
>    )
>  {
> -  EFI_HOB_CPU  *Hob;
> -
> -  Hob = CreateHob (EFI_HOB_TYPE_CPU, sizeof (EFI_HOB_CPU));
> -
> -  Hob->SizeOfMemorySpace = SizeOfMemorySpace;
> -  Hob->SizeOfIoSpace     = SizeOfIoSpace;
> -
>    //
> -  // Zero the reserved space to match HOB spec
> +  // PEI HOB is read only for MM phase
>    //
> -  ZeroMem (Hob->Reserved, sizeof (Hob->Reserved));
> -}
> -
> -/**
> -  Builds a HOB for the memory allocation.
> -
> -  This function builds a HOB for the memory allocation.
> -  If there is no additional space for HOB creation, then ASSERT().
> -
> -  @param  BaseAddress   The 64 bit physical address of the memory.
> -  @param  Length        The length of the memory allocation in bytes.
> -  @param  MemoryType    Type of memory allocated by this HOB.
> -
> -**/
> -VOID
> -EFIAPI
> -BuildMemoryAllocationHob (
> -  IN EFI_PHYSICAL_ADDRESS        BaseAddress,
> -  IN UINT64                      Length,
> -  IN EFI_MEMORY_TYPE             MemoryType
> -  )
> -{
> -  EFI_HOB_MEMORY_ALLOCATION  *Hob;
> -
> -  ASSERT (((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) &&
> -          ((Length & (EFI_PAGE_SIZE - 1)) == 0));
> -
> -  Hob = CreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, sizeof
> (EFI_HOB_MEMORY_ALLOCATION));
> -
> -  ZeroMem (&(Hob->AllocDescriptor.Name), sizeof (EFI_GUID));
> -  Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;
> -  Hob->AllocDescriptor.MemoryLength      = Length;
> -  Hob->AllocDescriptor.MemoryType        = MemoryType;
> -  //
> -  // Zero the reserved space to match HOB spec
> -  //
> -  ZeroMem (Hob->AllocDescriptor.Reserved, sizeof (Hob-
> >AllocDescriptor.Reserved));
> -}
> -
> -/**
> -  Builds a HOB that describes a chunk of system memory with Owner GUID.
> -
> -  This function builds a HOB that describes a chunk of system memory.
> -  If there is no additional space for HOB creation, then ASSERT().
> -
> -  @param  ResourceType        The type of resource described by this HOB.
> -  @param  ResourceAttribute   The resource attributes of the memory
> described by this HOB.
> -  @param  PhysicalStart       The 64 bit physical address of memory
> described by this HOB.
> -  @param  NumberOfBytes       The length of the memory described by this
> HOB in bytes.
> -  @param  OwnerGUID           GUID for the owner of this resource.
> -
> -**/
> -VOID
> -EFIAPI
> -BuildResourceDescriptorWithOwnerHob (
> -  IN EFI_RESOURCE_TYPE            ResourceType,
> -  IN EFI_RESOURCE_ATTRIBUTE_TYPE  ResourceAttribute,
> -  IN EFI_PHYSICAL_ADDRESS         PhysicalStart,
> -  IN UINT64                       NumberOfBytes,
> -  IN EFI_GUID                     *OwnerGUID
> -  )
> -{
> -  ASSERT (FALSE);
> -}
> -
> -/**
> -  Builds a Capsule Volume HOB.
> -
> -  This function builds a Capsule Volume HOB.
> -  If the platform does not support Capsule Volume HOBs, then ASSERT().
> -  If there is no additional space for HOB creation, then ASSERT().
> -
> -  @param  BaseAddress   The base address of the Capsule Volume.
> -  @param  Length        The size of the Capsule Volume in bytes.
> -
> -**/
> -VOID
> -EFIAPI
> -BuildCvHob (
> -  IN EFI_PHYSICAL_ADDRESS        BaseAddress,
> -  IN UINT64                      Length
> -  )
> -{
> -  ASSERT (FALSE);
> -}
> -
> -
> -/**
> -  Builds a HOB for the BSP store.
> -
> -  This function builds a HOB for BSP store.
> -  If there is no additional space for HOB creation, then ASSERT().
> -
> -  @param  BaseAddress   The 64 bit physical address of the BSP.
> -  @param  Length        The length of the BSP store in bytes.
> -  @param  MemoryType    Type of memory allocated by this HOB.
> -
> -**/
> -VOID
> -EFIAPI
> -BuildBspStoreHob (
> -  IN EFI_PHYSICAL_ADDRESS        BaseAddress,
> -  IN UINT64                      Length,
> -  IN EFI_MEMORY_TYPE             MemoryType
> -  )
> -{
>    ASSERT (FALSE);
>  }
> 
> @@ -585,6 +515,9 @@ BuildBspStoreHob (
>    Builds a HOB for the Stack.
> 
>    This function builds a HOB for the stack.
> +  It can only be invoked during PEI phase;
> +  for MM phase, it will ASSERT() because PEI HOB is read-only for MM
> phase.
> +
>    If there is no additional space for HOB creation, then ASSERT().
> 
>    @param  BaseAddress   The 64 bit physical address of the Stack.
> @@ -598,5 +531,64 @@ BuildStackHob (
>    IN UINT64                      Length
>    )
>  {
> +  //
> +  // PEI HOB is read only for MM phase
> +  //
> +  ASSERT (FALSE);
> +}
> +
> +/**
> +  Builds a HOB for the BSP store.
> +
> +  This function builds a HOB for BSP store.
> +  It can only be invoked during PEI phase;
> +  for MM phase, it will ASSERT() because PEI HOB is read-only for MM
> phase.
> +
> +  If there is no additional space for HOB creation, then ASSERT().
> +
> +  @param  BaseAddress   The 64 bit physical address of the BSP.
> +  @param  Length        The length of the BSP store in bytes.
> +  @param  MemoryType    Type of memory allocated by this HOB.
> +
> +**/
> +VOID
> +EFIAPI
> +BuildBspStoreHob (
> +  IN EFI_PHYSICAL_ADDRESS        BaseAddress,
> +  IN UINT64                      Length,
> +  IN EFI_MEMORY_TYPE             MemoryType
> +  )
> +{
> +  //
> +  // PEI HOB is read only for MM phase
> +  //
> +  ASSERT (FALSE);
> +}
> +
> +/**
> +  Builds a HOB for the memory allocation.
> +
> +  This function builds a HOB for the memory allocation.
> +  It can only be invoked during PEI phase;
> +  for MM phase, it will ASSERT() because PEI HOB is read-only for MM
> phase.
> +
> +  If there is no additional space for HOB creation, then ASSERT().
> +
> +  @param  BaseAddress   The 64 bit physical address of the memory.
> +  @param  Length        The length of the memory allocation in bytes.
> +  @param  MemoryType    Type of memory allocated by this HOB.
> +
> +**/
> +VOID
> +EFIAPI
> +BuildMemoryAllocationHob (
> +  IN EFI_PHYSICAL_ADDRESS        BaseAddress,
> +  IN UINT64                      Length,
> +  IN EFI_MEMORY_TYPE             MemoryType
> +  )
> +{
> +  //
> +  // PEI HOB is read only for MM phase
> +  //
>    ASSERT (FALSE);
>  }
> diff --git
> a/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmCo
> reHobLib.inf
> b/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmC
> oreHobLib.inf
> index 0046cd804def..e43a1e63bf14 100644
> ---
> a/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmCo
> reHobLib.inf
> +++
> b/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmC
> oreHobLib.inf
> @@ -22,16 +22,18 @@ [Defines]
>    LIBRARY_CLASS                  = HobLib|MM_CORE_STANDALONE
> 
>  #
> -#  VALID_ARCHITECTURES           = AARCH64
> +#  VALID_ARCHITECTURES           = X64 AARCH64
>  #
> -[Sources.Common]
> -  StandaloneMmCoreHobLib.c
> +[Sources.X64]
> +  X64/StandaloneMmCoreHobLib.c
> 
>  [Sources.AARCH64]
> +  AArch64/StandaloneMmCoreHobLib.c
>    AArch64/StandaloneMmCoreHobLibInternal.c
> 
>  [Packages]
>    MdePkg/MdePkg.dec
> +  StandaloneMmPkg/StandaloneMmPkg.dec
> 
> 
>  [LibraryClasses]
> --
> 2.28.0.windows.1


^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v1 03/15] StandaloneMmPkg: StandaloneMmCoreMemoryAllocationLib: Fix compiler warning
  2020-12-18 18:49 ` [PATCH v1 03/15] StandaloneMmPkg: StandaloneMmCoreMemoryAllocationLib: Fix compiler warning Kun Qin
@ 2020-12-28  0:14   ` Yao, Jiewen
  2020-12-28  4:07     ` Kun Qin
  0 siblings, 1 reply; 44+ messages in thread
From: Yao, Jiewen @ 2020-12-28  0:14 UTC (permalink / raw)
  To: Kun Qin, devel@edk2.groups.io
  Cc: Ard Biesheuvel, Sami Mujawar, Supreeth Venkatesh

Since below code is using (UINTN)MmramRangeCount,

MmInitializeMemoryServices ((UINTN)MmramRangeCount, (VOID *)(UINTN)MmramRanges);

I recommend to UINTN for MmramRangeCount, and use (UINTN) cast.

> -----Original Message-----
> From: Kun Qin <kun.q@outlook.com>
> Sent: Saturday, December 19, 2020 2:50 AM
> To: devel@edk2.groups.io
> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>; Sami Mujawar
> <sami.mujawar@arm.com>; Yao, Jiewen <jiewen.yao@intel.com>; Supreeth
> Venkatesh <supreeth.venkatesh@arm.com>
> Subject: [PATCH v1 03/15] StandaloneMmPkg:
> StandaloneMmCoreMemoryAllocationLib: Fix compiler warning
> 
> Assigning MmramRangeCount from MmCorePrivate (UINT64) to local
> variable
> MmramRangeCount (UINT32) will cause compilation failure due to "warning
> C4244: '=': conversion from 'UINT64' to 'UINT32', possible loss of data".
> This changes defines local MmramRangeCount as UINT64 type.
> 
> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
> Cc: Sami Mujawar <sami.mujawar@arm.com>
> Cc: Jiewen Yao <jiewen.yao@intel.com>
> Cc: Supreeth Venkatesh <supreeth.venkatesh@arm.com>
> 
> Signed-off-by: Kun Qin <kun.q@outlook.com>
> ---
> 
> StandaloneMmPkg/Library/StandaloneMmCoreMemoryAllocationLib/Stan
> daloneMmCoreMemoryAllocationLib.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git
> a/StandaloneMmPkg/Library/StandaloneMmCoreMemoryAllocationLib/Sta
> ndaloneMmCoreMemoryAllocationLib.c
> b/StandaloneMmPkg/Library/StandaloneMmCoreMemoryAllocationLib/Sta
> ndaloneMmCoreMemoryAllocationLib.c
> index eb3d772e18c5..798d546a2037 100644
> ---
> a/StandaloneMmPkg/Library/StandaloneMmCoreMemoryAllocationLib/Sta
> ndaloneMmCoreMemoryAllocationLib.c
> +++
> b/StandaloneMmPkg/Library/StandaloneMmCoreMemoryAllocationLib/Sta
> ndaloneMmCoreMemoryAllocationLib.c
> @@ -841,7 +841,7 @@ MemoryAllocationLibConstructor (
>    VOID                            *HobStart;
>    EFI_MMRAM_HOB_DESCRIPTOR_BLOCK  *MmramRangesHobData;
>    EFI_MMRAM_DESCRIPTOR            *MmramRanges;
> -  UINT32                           MmramRangeCount;
> +  UINT64                           MmramRangeCount;
>    EFI_HOB_GUID_TYPE               *MmramRangesHob;
> 
>    HobStart = GetHobList ();
> --
> 2.28.0.windows.1


^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v1 04/15] StandaloneMmPkg: StandaloneMmMemLib: Extends support for X64 architecture
  2020-12-18 18:50 ` [PATCH v1 04/15] StandaloneMmPkg: StandaloneMmMemLib: Extends support for X64 architecture Kun Qin
@ 2020-12-28  0:18   ` Yao, Jiewen
  2020-12-28  4:15     ` Kun Qin
  0 siblings, 1 reply; 44+ messages in thread
From: Yao, Jiewen @ 2020-12-28  0:18 UTC (permalink / raw)
  To: Kun Qin, devel@edk2.groups.io
  Cc: Ard Biesheuvel, Sami Mujawar, Supreeth Venkatesh

May I know where is the code to fill below?
EFI_MMRAM_DESCRIPTOR *mMmMemLibInternalMmramRanges;
UINTN                mMmMemLibInternalMmramCount;



> -----Original Message-----
> From: Kun Qin <kun.q@outlook.com>
> Sent: Saturday, December 19, 2020 2:50 AM
> To: devel@edk2.groups.io
> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>; Sami Mujawar
> <sami.mujawar@arm.com>; Yao, Jiewen <jiewen.yao@intel.com>; Supreeth
> Venkatesh <supreeth.venkatesh@arm.com>
> Subject: [PATCH v1 04/15] StandaloneMmPkg: StandaloneMmMemLib:
> Extends support for X64 architecture
> 
> This change extends StandaloneMmMemLib library to support X64
> architecture. The implementation is ported from
> MdePkg/Library/SmmMemLib.
> 
> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
> Cc: Sami Mujawar <sami.mujawar@arm.com>
> Cc: Jiewen Yao <jiewen.yao@intel.com>
> Cc: Supreeth Venkatesh <supreeth.venkatesh@arm.com>
> 
> Signed-off-by: Kun Qin <kun.q@outlook.com>
> ---
> 
> StandaloneMmPkg/Library/StandaloneMmMemLib/X64/StandaloneMmMe
> mLibInternal.c | 67 ++++++++++++++++++++
> 
> StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib
> .inf           |  6 +-
>  2 files changed, 72 insertions(+), 1 deletion(-)
> 
> diff --git
> a/StandaloneMmPkg/Library/StandaloneMmMemLib/X64/StandaloneMm
> MemLibInternal.c
> b/StandaloneMmPkg/Library/StandaloneMmMemLib/X64/StandaloneMm
> MemLibInternal.c
> new file mode 100644
> index 000000000000..c5e21c583f44
> --- /dev/null
> +++
> b/StandaloneMmPkg/Library/StandaloneMmMemLib/X64/StandaloneMm
> MemLibInternal.c
> @@ -0,0 +1,67 @@
> +/** @file
> +  Internal ARCH Specific file of MM memory check library.
> +
> +  MM memory check library implementation. This library consumes
> MM_ACCESS_PROTOCOL
> +  to get MMRAM information. In order to use this library instance, the
> platform should produce
> +  all MMRAM range via MM_ACCESS_PROTOCOL, including the range for
> firmware (like MM Core
> +  and MM driver) and/or specific dedicated hardware.
> +
> +  Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
> +  Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.<BR>
> +
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +#include <Library/BaseLib.h>
> +#include <Library/BaseMemoryLib.h>
> +#include <Library/DebugLib.h>
> +#include <Library/HobLib.h>
> +//
> +// Maximum support address used to check input buffer
> +//
> +extern EFI_PHYSICAL_ADDRESS
> mMmMemLibInternalMaximumSupportAddress;
> +
> +/**
> +  Calculate and save the maximum support address.
> +
> +**/
> +VOID
> +MmMemLibInternalCalculateMaximumSupportAddress (
> +  VOID
> +  )
> +{
> +  VOID         *Hob;
> +  UINT32       RegEax;
> +  UINT8        PhysicalAddressBits;
> +
> +  //
> +  // Get physical address bits supported.
> +  //
> +  Hob = GetFirstHob (EFI_HOB_TYPE_CPU);
> +  if (Hob != NULL) {
> +    PhysicalAddressBits = ((EFI_HOB_CPU *) Hob)->SizeOfMemorySpace;
> +  } else {
> +    AsmCpuid (0x80000000, &RegEax, NULL, NULL, NULL);
> +    if (RegEax >= 0x80000008) {
> +      AsmCpuid (0x80000008, &RegEax, NULL, NULL, NULL);
> +      PhysicalAddressBits = (UINT8) RegEax;
> +    } else {
> +      PhysicalAddressBits = 36;
> +    }
> +  }
> +  //
> +  // IA-32e paging translates 48-bit linear addresses to 52-bit physical
> addresses.
> +  //
> +  ASSERT (PhysicalAddressBits <= 52);
> +  if (PhysicalAddressBits > 48) {
> +    PhysicalAddressBits = 48;
> +  }
> +
> +  //
> +  // Save the maximum support address in one global variable
> +  //
> +  mMmMemLibInternalMaximumSupportAddress =
> (EFI_PHYSICAL_ADDRESS)(UINTN)(LShiftU64 (1, PhysicalAddressBits) - 1);
> +  DEBUG ((DEBUG_INFO, "mMmMemLibInternalMaximumSupportAddress
> = 0x%lx\n", mMmMemLibInternalMaximumSupportAddress));
> +}
> +
> +
> diff --git
> a/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMem
> Lib.inf
> b/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMem
> Lib.inf
> index 49da02e54e6d..65ad0a48905c 100644
> ---
> a/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMem
> Lib.inf
> +++
> b/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMem
> Lib.inf
> @@ -26,12 +26,15 @@ [Defines]
>  #
>  # The following information is for reference only and not required by the
> build tools.
>  #
> -#  VALID_ARCHITECTURES           = AARCH64
> +#  VALID_ARCHITECTURES           = X64 AARCH64
>  #
> 
>  [Sources.Common]
>    StandaloneMmMemLib.c
> 
> +[Sources.X64]
> +  X64/StandaloneMmMemLibInternal.c
> +
>  [Sources.AARCH64]
>    AArch64/StandaloneMmMemLibInternal.c
> 
> @@ -42,3 +45,4 @@ [Packages]
>  [LibraryClasses]
>    BaseMemoryLib
>    DebugLib
> +  HobLib
> --
> 2.28.0.windows.1


^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v1 03/15] StandaloneMmPkg: StandaloneMmCoreMemoryAllocationLib: Fix compiler warning
  2020-12-28  0:14   ` Yao, Jiewen
@ 2020-12-28  4:07     ` Kun Qin
  0 siblings, 0 replies; 44+ messages in thread
From: Kun Qin @ 2020-12-28  4:07 UTC (permalink / raw)
  To: Yao, Jiewen, devel@edk2.groups.io
  Cc: Ard Biesheuvel, Sami Mujawar, Supreeth Venkatesh

[-- Attachment #1: Type: text/plain, Size: 2787 bytes --]

Jiewen,

Good point. Will update this in v2 patches.

Thanks,
Kun

From: Yao, Jiewen<mailto:jiewen.yao@intel.com>
Sent: Sunday, December 27, 2020 16:14
To: Kun Qin<mailto:kun.q@outlook.com>; devel@edk2.groups.io<mailto:devel@edk2.groups.io>
Cc: Ard Biesheuvel<mailto:ard.biesheuvel@arm.com>; Sami Mujawar<mailto:sami.mujawar@arm.com>; Supreeth Venkatesh<mailto:supreeth.venkatesh@arm.com>
Subject: RE: [PATCH v1 03/15] StandaloneMmPkg: StandaloneMmCoreMemoryAllocationLib: Fix compiler warning

Since below code is using (UINTN)MmramRangeCount,

MmInitializeMemoryServices ((UINTN)MmramRangeCount, (VOID *)(UINTN)MmramRanges);

I recommend to UINTN for MmramRangeCount, and use (UINTN) cast.

> -----Original Message-----
> From: Kun Qin <kun.q@outlook.com>
> Sent: Saturday, December 19, 2020 2:50 AM
> To: devel@edk2.groups.io
> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>; Sami Mujawar
> <sami.mujawar@arm.com>; Yao, Jiewen <jiewen.yao@intel.com>; Supreeth
> Venkatesh <supreeth.venkatesh@arm.com>
> Subject: [PATCH v1 03/15] StandaloneMmPkg:
> StandaloneMmCoreMemoryAllocationLib: Fix compiler warning
>
> Assigning MmramRangeCount from MmCorePrivate (UINT64) to local
> variable
> MmramRangeCount (UINT32) will cause compilation failure due to "warning
> C4244: '=': conversion from 'UINT64' to 'UINT32', possible loss of data".
> This changes defines local MmramRangeCount as UINT64 type.
>
> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
> Cc: Sami Mujawar <sami.mujawar@arm.com>
> Cc: Jiewen Yao <jiewen.yao@intel.com>
> Cc: Supreeth Venkatesh <supreeth.venkatesh@arm.com>
>
> Signed-off-by: Kun Qin <kun.q@outlook.com>
> ---
>
> StandaloneMmPkg/Library/StandaloneMmCoreMemoryAllocationLib/Stan
> daloneMmCoreMemoryAllocationLib.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git
> a/StandaloneMmPkg/Library/StandaloneMmCoreMemoryAllocationLib/Sta
> ndaloneMmCoreMemoryAllocationLib.c
> b/StandaloneMmPkg/Library/StandaloneMmCoreMemoryAllocationLib/Sta
> ndaloneMmCoreMemoryAllocationLib.c
> index eb3d772e18c5..798d546a2037 100644
> ---
> a/StandaloneMmPkg/Library/StandaloneMmCoreMemoryAllocationLib/Sta
> ndaloneMmCoreMemoryAllocationLib.c
> +++
> b/StandaloneMmPkg/Library/StandaloneMmCoreMemoryAllocationLib/Sta
> ndaloneMmCoreMemoryAllocationLib.c
> @@ -841,7 +841,7 @@ MemoryAllocationLibConstructor (
>    VOID                            *HobStart;
>    EFI_MMRAM_HOB_DESCRIPTOR_BLOCK  *MmramRangesHobData;
>    EFI_MMRAM_DESCRIPTOR            *MmramRanges;
> -  UINT32                           MmramRangeCount;
> +  UINT64                           MmramRangeCount;
>    EFI_HOB_GUID_TYPE               *MmramRangesHob;
>
>    HobStart = GetHobList ();
> --
> 2.28.0.windows.1


[-- Attachment #2: Type: text/html, Size: 5779 bytes --]

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v1 04/15] StandaloneMmPkg: StandaloneMmMemLib: Extends support for X64 architecture
  2020-12-28  0:18   ` Yao, Jiewen
@ 2020-12-28  4:15     ` Kun Qin
  2020-12-28  6:24       ` Yao, Jiewen
  0 siblings, 1 reply; 44+ messages in thread
From: Kun Qin @ 2020-12-28  4:15 UTC (permalink / raw)
  To: Yao, Jiewen, devel@edk2.groups.io
  Cc: Ard Biesheuvel, Sami Mujawar, Supreeth Venkatesh

[-- Attachment #1: Type: text/plain, Size: 5673 bytes --]

Hi Jiewen,

I did not fill these 2 variables for this patch because I thought to follow up fix for this issue separately because the AARCH64 instance does not fill it either and I meant for this patch to solely extends the coverage to x64 (and IA32). But please let me know if you think otherwise, I can add the x64 fix in this patch as well. But I do not have fix for AARCH64 since I am not familiar with how it should work.

Thanks,
Kun

From: Yao, Jiewen<mailto:jiewen.yao@intel.com>
Sent: Sunday, December 27, 2020 16:18
To: Kun Qin<mailto:kun.q@outlook.com>; devel@edk2.groups.io<mailto:devel@edk2.groups.io>
Cc: Ard Biesheuvel<mailto:ard.biesheuvel@arm.com>; Sami Mujawar<mailto:sami.mujawar@arm.com>; Supreeth Venkatesh<mailto:supreeth.venkatesh@arm.com>
Subject: RE: [PATCH v1 04/15] StandaloneMmPkg: StandaloneMmMemLib: Extends support for X64 architecture

May I know where is the code to fill below?
EFI_MMRAM_DESCRIPTOR *mMmMemLibInternalMmramRanges;
UINTN                mMmMemLibInternalMmramCount;



> -----Original Message-----
> From: Kun Qin <kun.q@outlook.com>
> Sent: Saturday, December 19, 2020 2:50 AM
> To: devel@edk2.groups.io
> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>; Sami Mujawar
> <sami.mujawar@arm.com>; Yao, Jiewen <jiewen.yao@intel.com>; Supreeth
> Venkatesh <supreeth.venkatesh@arm.com>
> Subject: [PATCH v1 04/15] StandaloneMmPkg: StandaloneMmMemLib:
> Extends support for X64 architecture
>
> This change extends StandaloneMmMemLib library to support X64
> architecture. The implementation is ported from
> MdePkg/Library/SmmMemLib.
>
> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
> Cc: Sami Mujawar <sami.mujawar@arm.com>
> Cc: Jiewen Yao <jiewen.yao@intel.com>
> Cc: Supreeth Venkatesh <supreeth.venkatesh@arm.com>
>
> Signed-off-by: Kun Qin <kun.q@outlook.com>
> ---
>
> StandaloneMmPkg/Library/StandaloneMmMemLib/X64/StandaloneMmMe
> mLibInternal.c | 67 ++++++++++++++++++++
>
> StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib
> .inf           |  6 +-
>  2 files changed, 72 insertions(+), 1 deletion(-)
>
> diff --git
> a/StandaloneMmPkg/Library/StandaloneMmMemLib/X64/StandaloneMm
> MemLibInternal.c
> b/StandaloneMmPkg/Library/StandaloneMmMemLib/X64/StandaloneMm
> MemLibInternal.c
> new file mode 100644
> index 000000000000..c5e21c583f44
> --- /dev/null
> +++
> b/StandaloneMmPkg/Library/StandaloneMmMemLib/X64/StandaloneMm
> MemLibInternal.c
> @@ -0,0 +1,67 @@
> +/** @file
> +  Internal ARCH Specific file of MM memory check library.
> +
> +  MM memory check library implementation. This library consumes
> MM_ACCESS_PROTOCOL
> +  to get MMRAM information. In order to use this library instance, the
> platform should produce
> +  all MMRAM range via MM_ACCESS_PROTOCOL, including the range for
> firmware (like MM Core
> +  and MM driver) and/or specific dedicated hardware.
> +
> +  Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
> +  Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.<BR>
> +
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +#include <Library/BaseLib.h>
> +#include <Library/BaseMemoryLib.h>
> +#include <Library/DebugLib.h>
> +#include <Library/HobLib.h>
> +//
> +// Maximum support address used to check input buffer
> +//
> +extern EFI_PHYSICAL_ADDRESS
> mMmMemLibInternalMaximumSupportAddress;
> +
> +/**
> +  Calculate and save the maximum support address.
> +
> +**/
> +VOID
> +MmMemLibInternalCalculateMaximumSupportAddress (
> +  VOID
> +  )
> +{
> +  VOID         *Hob;
> +  UINT32       RegEax;
> +  UINT8        PhysicalAddressBits;
> +
> +  //
> +  // Get physical address bits supported.
> +  //
> +  Hob = GetFirstHob (EFI_HOB_TYPE_CPU);
> +  if (Hob != NULL) {
> +    PhysicalAddressBits = ((EFI_HOB_CPU *) Hob)->SizeOfMemorySpace;
> +  } else {
> +    AsmCpuid (0x80000000, &RegEax, NULL, NULL, NULL);
> +    if (RegEax >= 0x80000008) {
> +      AsmCpuid (0x80000008, &RegEax, NULL, NULL, NULL);
> +      PhysicalAddressBits = (UINT8) RegEax;
> +    } else {
> +      PhysicalAddressBits = 36;
> +    }
> +  }
> +  //
> +  // IA-32e paging translates 48-bit linear addresses to 52-bit physical
> addresses.
> +  //
> +  ASSERT (PhysicalAddressBits <= 52);
> +  if (PhysicalAddressBits > 48) {
> +    PhysicalAddressBits = 48;
> +  }
> +
> +  //
> +  // Save the maximum support address in one global variable
> +  //
> +  mMmMemLibInternalMaximumSupportAddress =
> (EFI_PHYSICAL_ADDRESS)(UINTN)(LShiftU64 (1, PhysicalAddressBits) - 1);
> +  DEBUG ((DEBUG_INFO, "mMmMemLibInternalMaximumSupportAddress
> = 0x%lx\n", mMmMemLibInternalMaximumSupportAddress));
> +}
> +
> +
> diff --git
> a/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMem
> Lib.inf
> b/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMem
> Lib.inf
> index 49da02e54e6d..65ad0a48905c 100644
> ---
> a/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMem
> Lib.inf
> +++
> b/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMem
> Lib.inf
> @@ -26,12 +26,15 @@ [Defines]
>  #
>  # The following information is for reference only and not required by the
> build tools.
>  #
> -#  VALID_ARCHITECTURES           = AARCH64
> +#  VALID_ARCHITECTURES           = X64 AARCH64
>  #
>
>  [Sources.Common]
>    StandaloneMmMemLib.c
>
> +[Sources.X64]
> +  X64/StandaloneMmMemLibInternal.c
> +
>  [Sources.AARCH64]
>    AArch64/StandaloneMmMemLibInternal.c
>
> @@ -42,3 +45,4 @@ [Packages]
>  [LibraryClasses]
>    BaseMemoryLib
>    DebugLib
> +  HobLib
> --
> 2.28.0.windows.1


[-- Attachment #2: Type: text/html, Size: 9598 bytes --]

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v1 04/15] StandaloneMmPkg: StandaloneMmMemLib: Extends support for X64 architecture
  2020-12-28  4:15     ` Kun Qin
@ 2020-12-28  6:24       ` Yao, Jiewen
  2020-12-28  6:36         ` Kun Qin
  0 siblings, 1 reply; 44+ messages in thread
From: Yao, Jiewen @ 2020-12-28  6:24 UTC (permalink / raw)
  To: Kun Qin, devel@edk2.groups.io
  Cc: Ard Biesheuvel, Sami Mujawar, Supreeth Venkatesh

[-- Attachment #1: Type: text/plain, Size: 6695 bytes --]

I am not familiar with AArch64. So I will let ARM people comment it.

For X86, I think it is security hole, if we do not fill mMmMemLibInternalMmramRanges.

A partial fix with known security vulnerability is not the best idea.

I prefer to we give a full fix, or no fix it in V2.

Thank you
Yao Jiewen


From: Kun Qin <kun.q@outlook.com>
Sent: Monday, December 28, 2020 12:15 PM
To: Yao, Jiewen <jiewen.yao@intel.com>; devel@edk2.groups.io
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>; Sami Mujawar <sami.mujawar@arm.com>; Supreeth Venkatesh <supreeth.venkatesh@arm.com>
Subject: RE: [PATCH v1 04/15] StandaloneMmPkg: StandaloneMmMemLib: Extends support for X64 architecture

Hi Jiewen,

I did not fill these 2 variables for this patch because I thought to follow up fix for this issue separately because the AARCH64 instance does not fill it either and I meant for this patch to solely extends the coverage to x64 (and IA32). But please let me know if you think otherwise, I can add the x64 fix in this patch as well. But I do not have fix for AARCH64 since I am not familiar with how it should work.

Thanks,
Kun

From: Yao, Jiewen<mailto:jiewen.yao@intel.com>
Sent: Sunday, December 27, 2020 16:18
To: Kun Qin<mailto:kun.q@outlook.com>; devel@edk2.groups.io<mailto:devel@edk2.groups.io>
Cc: Ard Biesheuvel<mailto:ard.biesheuvel@arm.com>; Sami Mujawar<mailto:sami.mujawar@arm.com>; Supreeth Venkatesh<mailto:supreeth.venkatesh@arm.com>
Subject: RE: [PATCH v1 04/15] StandaloneMmPkg: StandaloneMmMemLib: Extends support for X64 architecture

May I know where is the code to fill below?
EFI_MMRAM_DESCRIPTOR *mMmMemLibInternalMmramRanges;
UINTN                mMmMemLibInternalMmramCount;



> -----Original Message-----
> From: Kun Qin <kun.q@outlook.com<mailto:kun.q@outlook.com>>
> Sent: Saturday, December 19, 2020 2:50 AM
> To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>
> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com<mailto:ard.biesheuvel@arm.com>>; Sami Mujawar
> <sami.mujawar@arm.com<mailto:sami.mujawar@arm.com>>; Yao, Jiewen <jiewen.yao@intel.com<mailto:jiewen.yao@intel.com>>; Supreeth
> Venkatesh <supreeth.venkatesh@arm.com<mailto:supreeth.venkatesh@arm.com>>
> Subject: [PATCH v1 04/15] StandaloneMmPkg: StandaloneMmMemLib:
> Extends support for X64 architecture
>
> This change extends StandaloneMmMemLib library to support X64
> architecture. The implementation is ported from
> MdePkg/Library/SmmMemLib.
>
> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com<mailto:ard.biesheuvel@arm.com>>
> Cc: Sami Mujawar <sami.mujawar@arm.com<mailto:sami.mujawar@arm.com>>
> Cc: Jiewen Yao <jiewen.yao@intel.com<mailto:jiewen.yao@intel.com>>
> Cc: Supreeth Venkatesh <supreeth.venkatesh@arm.com<mailto:supreeth.venkatesh@arm.com>>
>
> Signed-off-by: Kun Qin <kun.q@outlook.com<mailto:kun.q@outlook.com>>
> ---
>
> StandaloneMmPkg/Library/StandaloneMmMemLib/X64/StandaloneMmMe
> mLibInternal.c | 67 ++++++++++++++++++++
>
> StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib
> .inf           |  6 +-
>  2 files changed, 72 insertions(+), 1 deletion(-)
>
> diff --git
> a/StandaloneMmPkg/Library/StandaloneMmMemLib/X64/StandaloneMm
> MemLibInternal.c
> b/StandaloneMmPkg/Library/StandaloneMmMemLib/X64/StandaloneMm
> MemLibInternal.c
> new file mode 100644
> index 000000000000..c5e21c583f44
> --- /dev/null
> +++
> b/StandaloneMmPkg/Library/StandaloneMmMemLib/X64/StandaloneMm
> MemLibInternal.c
> @@ -0,0 +1,67 @@
> +/** @file
> +  Internal ARCH Specific file of MM memory check library.
> +
> +  MM memory check library implementation. This library consumes
> MM_ACCESS_PROTOCOL
> +  to get MMRAM information. In order to use this library instance, the
> platform should produce
> +  all MMRAM range via MM_ACCESS_PROTOCOL, including the range for
> firmware (like MM Core
> +  and MM driver) and/or specific dedicated hardware.
> +
> +  Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
> +  Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.<BR>
> +
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +#include <Library/BaseLib.h>
> +#include <Library/BaseMemoryLib.h>
> +#include <Library/DebugLib.h>
> +#include <Library/HobLib.h>
> +//
> +// Maximum support address used to check input buffer
> +//
> +extern EFI_PHYSICAL_ADDRESS
> mMmMemLibInternalMaximumSupportAddress;
> +
> +/**
> +  Calculate and save the maximum support address.
> +
> +**/
> +VOID
> +MmMemLibInternalCalculateMaximumSupportAddress (
> +  VOID
> +  )
> +{
> +  VOID         *Hob;
> +  UINT32       RegEax;
> +  UINT8        PhysicalAddressBits;
> +
> +  //
> +  // Get physical address bits supported.
> +  //
> +  Hob = GetFirstHob (EFI_HOB_TYPE_CPU);
> +  if (Hob != NULL) {
> +    PhysicalAddressBits = ((EFI_HOB_CPU *) Hob)->SizeOfMemorySpace;
> +  } else {
> +    AsmCpuid (0x80000000, &RegEax, NULL, NULL, NULL);
> +    if (RegEax >= 0x80000008) {
> +      AsmCpuid (0x80000008, &RegEax, NULL, NULL, NULL);
> +      PhysicalAddressBits = (UINT8) RegEax;
> +    } else {
> +      PhysicalAddressBits = 36;
> +    }
> +  }
> +  //
> +  // IA-32e paging translates 48-bit linear addresses to 52-bit physical
> addresses.
> +  //
> +  ASSERT (PhysicalAddressBits <= 52);
> +  if (PhysicalAddressBits > 48) {
> +    PhysicalAddressBits = 48;
> +  }
> +
> +  //
> +  // Save the maximum support address in one global variable
> +  //
> +  mMmMemLibInternalMaximumSupportAddress =
> (EFI_PHYSICAL_ADDRESS)(UINTN)(LShiftU64 (1, PhysicalAddressBits) - 1);
> +  DEBUG ((DEBUG_INFO, "mMmMemLibInternalMaximumSupportAddress
> = 0x%lx\n", mMmMemLibInternalMaximumSupportAddress));
> +}
> +
> +
> diff --git
> a/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMem
> Lib.inf
> b/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMem
> Lib.inf
> index 49da02e54e6d..65ad0a48905c 100644
> ---
> a/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMem
> Lib.inf
> +++
> b/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMem
> Lib.inf
> @@ -26,12 +26,15 @@ [Defines]
>  #
>  # The following information is for reference only and not required by the
> build tools.
>  #
> -#  VALID_ARCHITECTURES           = AARCH64
> +#  VALID_ARCHITECTURES           = X64 AARCH64
>  #
>
>  [Sources.Common]
>    StandaloneMmMemLib.c
>
> +[Sources.X64]
> +  X64/StandaloneMmMemLibInternal.c
> +
>  [Sources.AARCH64]
>    AArch64/StandaloneMmMemLibInternal.c
>
> @@ -42,3 +45,4 @@ [Packages]
>  [LibraryClasses]
>    BaseMemoryLib
>    DebugLib
> +  HobLib
> --
> 2.28.0.windows.1


[-- Attachment #2: Type: text/html, Size: 11967 bytes --]

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [PATCH v1 04/15] StandaloneMmPkg: StandaloneMmMemLib: Extends support for X64 architecture
  2020-12-28  6:24       ` Yao, Jiewen
@ 2020-12-28  6:36         ` Kun Qin
  2020-12-28  6:37           ` [edk2-devel] " Yao, Jiewen
  0 siblings, 1 reply; 44+ messages in thread
From: Kun Qin @ 2020-12-28  6:36 UTC (permalink / raw)
  To: Yao, Jiewen, devel@edk2.groups.io
  Cc: Ard Biesheuvel, Sami Mujawar, Supreeth Venkatesh

[-- Attachment #1: Type: text/plain, Size: 7345 bytes --]

Understood, not including this library for x86 will fail CI build on some new drivers in this patch series, so we will need to give it a full fix. I will add the fix at least for x86 in patch v2.

Thanks,
Kun

From: Yao, Jiewen<mailto:jiewen.yao@intel.com>
Sent: Sunday, December 27, 2020 22:24
To: Kun Qin<mailto:kun.q@outlook.com>; devel@edk2.groups.io<mailto:devel@edk2.groups.io>
Cc: Ard Biesheuvel<mailto:ard.biesheuvel@arm.com>; Sami Mujawar<mailto:sami.mujawar@arm.com>; Supreeth Venkatesh<mailto:supreeth.venkatesh@arm.com>
Subject: RE: [PATCH v1 04/15] StandaloneMmPkg: StandaloneMmMemLib: Extends support for X64 architecture

I am not familiar with AArch64. So I will let ARM people comment it.

For X86, I think it is security hole, if we do not fill mMmMemLibInternalMmramRanges.

A partial fix with known security vulnerability is not the best idea.

I prefer to we give a full fix, or no fix it in V2.

Thank you
Yao Jiewen


From: Kun Qin <kun.q@outlook.com>
Sent: Monday, December 28, 2020 12:15 PM
To: Yao, Jiewen <jiewen.yao@intel.com>; devel@edk2.groups.io
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>; Sami Mujawar <sami.mujawar@arm.com>; Supreeth Venkatesh <supreeth.venkatesh@arm.com>
Subject: RE: [PATCH v1 04/15] StandaloneMmPkg: StandaloneMmMemLib: Extends support for X64 architecture

Hi Jiewen,

I did not fill these 2 variables for this patch because I thought to follow up fix for this issue separately because the AARCH64 instance does not fill it either and I meant for this patch to solely extends the coverage to x64 (and IA32). But please let me know if you think otherwise, I can add the x64 fix in this patch as well. But I do not have fix for AARCH64 since I am not familiar with how it should work.

Thanks,
Kun

From: Yao, Jiewen<mailto:jiewen.yao@intel.com>
Sent: Sunday, December 27, 2020 16:18
To: Kun Qin<mailto:kun.q@outlook.com>; devel@edk2.groups.io<mailto:devel@edk2.groups.io>
Cc: Ard Biesheuvel<mailto:ard.biesheuvel@arm.com>; Sami Mujawar<mailto:sami.mujawar@arm.com>; Supreeth Venkatesh<mailto:supreeth.venkatesh@arm.com>
Subject: RE: [PATCH v1 04/15] StandaloneMmPkg: StandaloneMmMemLib: Extends support for X64 architecture

May I know where is the code to fill below?
EFI_MMRAM_DESCRIPTOR *mMmMemLibInternalMmramRanges;
UINTN                mMmMemLibInternalMmramCount;



> -----Original Message-----
> From: Kun Qin <kun.q@outlook.com<mailto:kun.q@outlook.com>>
> Sent: Saturday, December 19, 2020 2:50 AM
> To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>
> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com<mailto:ard.biesheuvel@arm.com>>; Sami Mujawar
> <sami.mujawar@arm.com<mailto:sami.mujawar@arm.com>>; Yao, Jiewen <jiewen.yao@intel.com<mailto:jiewen.yao@intel.com>>; Supreeth
> Venkatesh <supreeth.venkatesh@arm.com<mailto:supreeth.venkatesh@arm.com>>
> Subject: [PATCH v1 04/15] StandaloneMmPkg: StandaloneMmMemLib:
> Extends support for X64 architecture
>
> This change extends StandaloneMmMemLib library to support X64
> architecture. The implementation is ported from
> MdePkg/Library/SmmMemLib.
>
> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com<mailto:ard.biesheuvel@arm.com>>
> Cc: Sami Mujawar <sami.mujawar@arm.com<mailto:sami.mujawar@arm.com>>
> Cc: Jiewen Yao <jiewen.yao@intel.com<mailto:jiewen.yao@intel.com>>
> Cc: Supreeth Venkatesh <supreeth.venkatesh@arm.com<mailto:supreeth.venkatesh@arm.com>>
>
> Signed-off-by: Kun Qin <kun.q@outlook.com<mailto:kun.q@outlook.com>>
> ---
>
> StandaloneMmPkg/Library/StandaloneMmMemLib/X64/StandaloneMmMe
> mLibInternal.c | 67 ++++++++++++++++++++
>
> StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib
> .inf           |  6 +-
>  2 files changed, 72 insertions(+), 1 deletion(-)
>
> diff --git
> a/StandaloneMmPkg/Library/StandaloneMmMemLib/X64/StandaloneMm
> MemLibInternal.c
> b/StandaloneMmPkg/Library/StandaloneMmMemLib/X64/StandaloneMm
> MemLibInternal.c
> new file mode 100644
> index 000000000000..c5e21c583f44
> --- /dev/null
> +++
> b/StandaloneMmPkg/Library/StandaloneMmMemLib/X64/StandaloneMm
> MemLibInternal.c
> @@ -0,0 +1,67 @@
> +/** @file
> +  Internal ARCH Specific file of MM memory check library.
> +
> +  MM memory check library implementation. This library consumes
> MM_ACCESS_PROTOCOL
> +  to get MMRAM information. In order to use this library instance, the
> platform should produce
> +  all MMRAM range via MM_ACCESS_PROTOCOL, including the range for
> firmware (like MM Core
> +  and MM driver) and/or specific dedicated hardware.
> +
> +  Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
> +  Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.<BR>
> +
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +#include <Library/BaseLib.h>
> +#include <Library/BaseMemoryLib.h>
> +#include <Library/DebugLib.h>
> +#include <Library/HobLib.h>
> +//
> +// Maximum support address used to check input buffer
> +//
> +extern EFI_PHYSICAL_ADDRESS
> mMmMemLibInternalMaximumSupportAddress;
> +
> +/**
> +  Calculate and save the maximum support address.
> +
> +**/
> +VOID
> +MmMemLibInternalCalculateMaximumSupportAddress (
> +  VOID
> +  )
> +{
> +  VOID         *Hob;
> +  UINT32       RegEax;
> +  UINT8        PhysicalAddressBits;
> +
> +  //
> +  // Get physical address bits supported.
> +  //
> +  Hob = GetFirstHob (EFI_HOB_TYPE_CPU);
> +  if (Hob != NULL) {
> +    PhysicalAddressBits = ((EFI_HOB_CPU *) Hob)->SizeOfMemorySpace;
> +  } else {
> +    AsmCpuid (0x80000000, &RegEax, NULL, NULL, NULL);
> +    if (RegEax >= 0x80000008) {
> +      AsmCpuid (0x80000008, &RegEax, NULL, NULL, NULL);
> +      PhysicalAddressBits = (UINT8) RegEax;
> +    } else {
> +      PhysicalAddressBits = 36;
> +    }
> +  }
> +  //
> +  // IA-32e paging translates 48-bit linear addresses to 52-bit physical
> addresses.
> +  //
> +  ASSERT (PhysicalAddressBits <= 52);
> +  if (PhysicalAddressBits > 48) {
> +    PhysicalAddressBits = 48;
> +  }
> +
> +  //
> +  // Save the maximum support address in one global variable
> +  //
> +  mMmMemLibInternalMaximumSupportAddress =
> (EFI_PHYSICAL_ADDRESS)(UINTN)(LShiftU64 (1, PhysicalAddressBits) - 1);
> +  DEBUG ((DEBUG_INFO, "mMmMemLibInternalMaximumSupportAddress
> = 0x%lx\n", mMmMemLibInternalMaximumSupportAddress));
> +}
> +
> +
> diff --git
> a/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMem
> Lib.inf
> b/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMem
> Lib.inf
> index 49da02e54e6d..65ad0a48905c 100644
> ---
> a/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMem
> Lib.inf
> +++
> b/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMem
> Lib.inf
> @@ -26,12 +26,15 @@ [Defines]
>  #
>  # The following information is for reference only and not required by the
> build tools.
>  #
> -#  VALID_ARCHITECTURES           = AARCH64
> +#  VALID_ARCHITECTURES           = X64 AARCH64
>  #
>
>  [Sources.Common]
>    StandaloneMmMemLib.c
>
> +[Sources.X64]
> +  X64/StandaloneMmMemLibInternal.c
> +
>  [Sources.AARCH64]
>    AArch64/StandaloneMmMemLibInternal.c
>
> @@ -42,3 +45,4 @@ [Packages]
>  [LibraryClasses]
>    BaseMemoryLib
>    DebugLib
> +  HobLib
> --
> 2.28.0.windows.1



[-- Attachment #2: Type: text/html, Size: 12786 bytes --]

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [edk2-devel] [PATCH v1 04/15] StandaloneMmPkg: StandaloneMmMemLib: Extends support for X64 architecture
  2020-12-28  6:36         ` Kun Qin
@ 2020-12-28  6:37           ` Yao, Jiewen
  0 siblings, 0 replies; 44+ messages in thread
From: Yao, Jiewen @ 2020-12-28  6:37 UTC (permalink / raw)
  To: devel@edk2.groups.io, kun.q@outlook.com
  Cc: Ard Biesheuvel, Sami Mujawar, Supreeth Venkatesh

[-- Attachment #1: Type: text/plain, Size: 7979 bytes --]

Sounds good. Thank you!

From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Kun Qin
Sent: Monday, December 28, 2020 2:36 PM
To: Yao, Jiewen <jiewen.yao@intel.com>; devel@edk2.groups.io
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>; Sami Mujawar <sami.mujawar@arm.com>; Supreeth Venkatesh <supreeth.venkatesh@arm.com>
Subject: Re: [edk2-devel] [PATCH v1 04/15] StandaloneMmPkg: StandaloneMmMemLib: Extends support for X64 architecture

Understood, not including this library for x86 will fail CI build on some new drivers in this patch series, so we will need to give it a full fix. I will add the fix at least for x86 in patch v2.

Thanks,
Kun

From: Yao, Jiewen<mailto:jiewen.yao@intel.com>
Sent: Sunday, December 27, 2020 22:24
To: Kun Qin<mailto:kun.q@outlook.com>; devel@edk2.groups.io<mailto:devel@edk2.groups.io>
Cc: Ard Biesheuvel<mailto:ard.biesheuvel@arm.com>; Sami Mujawar<mailto:sami.mujawar@arm.com>; Supreeth Venkatesh<mailto:supreeth.venkatesh@arm.com>
Subject: RE: [PATCH v1 04/15] StandaloneMmPkg: StandaloneMmMemLib: Extends support for X64 architecture

I am not familiar with AArch64. So I will let ARM people comment it.

For X86, I think it is security hole, if we do not fill mMmMemLibInternalMmramRanges.

A partial fix with known security vulnerability is not the best idea.

I prefer to we give a full fix, or no fix it in V2.

Thank you
Yao Jiewen


From: Kun Qin <kun.q@outlook.com<mailto:kun.q@outlook.com>>
Sent: Monday, December 28, 2020 12:15 PM
To: Yao, Jiewen <jiewen.yao@intel.com<mailto:jiewen.yao@intel.com>>; devel@edk2.groups.io<mailto:devel@edk2.groups.io>
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com<mailto:ard.biesheuvel@arm.com>>; Sami Mujawar <sami.mujawar@arm.com<mailto:sami.mujawar@arm.com>>; Supreeth Venkatesh <supreeth.venkatesh@arm.com<mailto:supreeth.venkatesh@arm.com>>
Subject: RE: [PATCH v1 04/15] StandaloneMmPkg: StandaloneMmMemLib: Extends support for X64 architecture

Hi Jiewen,

I did not fill these 2 variables for this patch because I thought to follow up fix for this issue separately because the AARCH64 instance does not fill it either and I meant for this patch to solely extends the coverage to x64 (and IA32). But please let me know if you think otherwise, I can add the x64 fix in this patch as well. But I do not have fix for AARCH64 since I am not familiar with how it should work.

Thanks,
Kun

From: Yao, Jiewen<mailto:jiewen.yao@intel.com>
Sent: Sunday, December 27, 2020 16:18
To: Kun Qin<mailto:kun.q@outlook.com>; devel@edk2.groups.io<mailto:devel@edk2.groups.io>
Cc: Ard Biesheuvel<mailto:ard.biesheuvel@arm.com>; Sami Mujawar<mailto:sami.mujawar@arm.com>; Supreeth Venkatesh<mailto:supreeth.venkatesh@arm.com>
Subject: RE: [PATCH v1 04/15] StandaloneMmPkg: StandaloneMmMemLib: Extends support for X64 architecture

May I know where is the code to fill below?
EFI_MMRAM_DESCRIPTOR *mMmMemLibInternalMmramRanges;
UINTN                mMmMemLibInternalMmramCount;



> -----Original Message-----
> From: Kun Qin <kun.q@outlook.com<mailto:kun.q@outlook.com>>
> Sent: Saturday, December 19, 2020 2:50 AM
> To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>
> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com<mailto:ard.biesheuvel@arm.com>>; Sami Mujawar
> <sami.mujawar@arm.com<mailto:sami.mujawar@arm.com>>; Yao, Jiewen <jiewen.yao@intel.com<mailto:jiewen.yao@intel.com>>; Supreeth
> Venkatesh <supreeth.venkatesh@arm.com<mailto:supreeth.venkatesh@arm.com>>
> Subject: [PATCH v1 04/15] StandaloneMmPkg: StandaloneMmMemLib:
> Extends support for X64 architecture
>
> This change extends StandaloneMmMemLib library to support X64
> architecture. The implementation is ported from
> MdePkg/Library/SmmMemLib.
>
> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com<mailto:ard.biesheuvel@arm.com>>
> Cc: Sami Mujawar <sami.mujawar@arm.com<mailto:sami.mujawar@arm.com>>
> Cc: Jiewen Yao <jiewen.yao@intel.com<mailto:jiewen.yao@intel.com>>
> Cc: Supreeth Venkatesh <supreeth.venkatesh@arm.com<mailto:supreeth.venkatesh@arm.com>>
>
> Signed-off-by: Kun Qin <kun.q@outlook.com<mailto:kun.q@outlook.com>>
> ---
>
> StandaloneMmPkg/Library/StandaloneMmMemLib/X64/StandaloneMmMe
> mLibInternal.c | 67 ++++++++++++++++++++
>
> StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib
> .inf           |  6 +-
>  2 files changed, 72 insertions(+), 1 deletion(-)
>
> diff --git
> a/StandaloneMmPkg/Library/StandaloneMmMemLib/X64/StandaloneMm
> MemLibInternal.c
> b/StandaloneMmPkg/Library/StandaloneMmMemLib/X64/StandaloneMm
> MemLibInternal.c
> new file mode 100644
> index 000000000000..c5e21c583f44
> --- /dev/null
> +++
> b/StandaloneMmPkg/Library/StandaloneMmMemLib/X64/StandaloneMm
> MemLibInternal.c
> @@ -0,0 +1,67 @@
> +/** @file
> +  Internal ARCH Specific file of MM memory check library.
> +
> +  MM memory check library implementation. This library consumes
> MM_ACCESS_PROTOCOL
> +  to get MMRAM information. In order to use this library instance, the
> platform should produce
> +  all MMRAM range via MM_ACCESS_PROTOCOL, including the range for
> firmware (like MM Core
> +  and MM driver) and/or specific dedicated hardware.
> +
> +  Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
> +  Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.<BR>
> +
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +#include <Library/BaseLib.h>
> +#include <Library/BaseMemoryLib.h>
> +#include <Library/DebugLib.h>
> +#include <Library/HobLib.h>
> +//
> +// Maximum support address used to check input buffer
> +//
> +extern EFI_PHYSICAL_ADDRESS
> mMmMemLibInternalMaximumSupportAddress;
> +
> +/**
> +  Calculate and save the maximum support address.
> +
> +**/
> +VOID
> +MmMemLibInternalCalculateMaximumSupportAddress (
> +  VOID
> +  )
> +{
> +  VOID         *Hob;
> +  UINT32       RegEax;
> +  UINT8        PhysicalAddressBits;
> +
> +  //
> +  // Get physical address bits supported.
> +  //
> +  Hob = GetFirstHob (EFI_HOB_TYPE_CPU);
> +  if (Hob != NULL) {
> +    PhysicalAddressBits = ((EFI_HOB_CPU *) Hob)->SizeOfMemorySpace;
> +  } else {
> +    AsmCpuid (0x80000000, &RegEax, NULL, NULL, NULL);
> +    if (RegEax >= 0x80000008) {
> +      AsmCpuid (0x80000008, &RegEax, NULL, NULL, NULL);
> +      PhysicalAddressBits = (UINT8) RegEax;
> +    } else {
> +      PhysicalAddressBits = 36;
> +    }
> +  }
> +  //
> +  // IA-32e paging translates 48-bit linear addresses to 52-bit physical
> addresses.
> +  //
> +  ASSERT (PhysicalAddressBits <= 52);
> +  if (PhysicalAddressBits > 48) {
> +    PhysicalAddressBits = 48;
> +  }
> +
> +  //
> +  // Save the maximum support address in one global variable
> +  //
> +  mMmMemLibInternalMaximumSupportAddress =
> (EFI_PHYSICAL_ADDRESS)(UINTN)(LShiftU64 (1, PhysicalAddressBits) - 1);
> +  DEBUG ((DEBUG_INFO, "mMmMemLibInternalMaximumSupportAddress
> = 0x%lx\n", mMmMemLibInternalMaximumSupportAddress));
> +}
> +
> +
> diff --git
> a/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMem
> Lib.inf
> b/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMem
> Lib.inf
> index 49da02e54e6d..65ad0a48905c 100644
> ---
> a/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMem
> Lib.inf
> +++
> b/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMem
> Lib.inf
> @@ -26,12 +26,15 @@ [Defines]
>  #
>  # The following information is for reference only and not required by the
> build tools.
>  #
> -#  VALID_ARCHITECTURES           = AARCH64
> +#  VALID_ARCHITECTURES           = X64 AARCH64
>  #
>
>  [Sources.Common]
>    StandaloneMmMemLib.c
>
> +[Sources.X64]
> +  X64/StandaloneMmMemLibInternal.c
> +
>  [Sources.AARCH64]
>    AArch64/StandaloneMmMemLibInternal.c
>
> @@ -42,3 +45,4 @@ [Packages]
>  [LibraryClasses]
>    BaseMemoryLib
>    DebugLib
> +  HobLib
> --
> 2.28.0.windows.1




[-- Attachment #2: Type: text/html, Size: 14461 bytes --]

^ permalink raw reply	[flat|nested] 44+ messages in thread

* 回复: [edk2-devel] [PATCH v1 06/15] MdeModulePkg: SmmReportStatusCodeLib: ReportStatusCodeLib in StandaloneMm
  2020-12-24  9:11           ` Kun Qin
@ 2020-12-29  1:23             ` gaoliming
  2020-12-29  1:31               ` Kun Qin
  0 siblings, 1 reply; 44+ messages in thread
From: gaoliming @ 2020-12-29  1:23 UTC (permalink / raw)
  To: devel, kun.q, hao.a.wu, 'Yao, Jiewen'
  Cc: 'Wang, Jian J', 'Bi, Dandan'

[-- Attachment #1: Type: text/plain, Size: 18628 bytes --]

Kun:

 I prefer to include StatusCodeHandlerSmm with the basic check. If so, the
complete statuscode solution can be provided. 

 

Thanks

Liming

发件人: bounce+27952+69443+4905953+8761045@groups.io
<bounce+27952+69443+4905953+8761045@groups.io> 代表 Kun Qin
发送时间: 2020年12月24日 17:12
收件人: devel@edk2.groups.io; gaoliming@byosoft.com.cn; hao.a.wu@intel.com;
'Yao, Jiewen' <jiewen.yao@intel.com>
抄送: 'Wang, Jian J' <jian.j.wang@intel.com>; 'Bi, Dandan' <dandan.bi@intel.
com>
主题: Re: [edk2-devel] [PATCH v1 06/15] MdeModulePkg:
SmmReportStatusCodeLib: ReportStatusCodeLib in StandaloneMm

 

Liming,

 

I have not had a plan for StatusCodeHandlerSmm because our platforms are not
using it currently (we used a MU version instead). So it would be difficult
to fully validate the functionality after updates. Please let me know if you
prefer to have this driver updated in this patch series, I can try to update
it locally with some fundamental sanity checks.

 

Regards,

Kun

 

From: gaoliming <mailto:gaoliming@byosoft.com.cn> 
Sent: Wednesday, December 23, 2020 17:53
To: devel@edk2.groups.io <mailto:devel@edk2.groups.io> ; hao.a.wu@intel.com
<mailto:hao.a.wu@intel.com> ; kun.q@outlook.com <mailto:kun.q@outlook.com> ;
'Yao, Jiewen' <mailto:jiewen.yao@intel.com> 
Cc: 'Wang, Jian J' <mailto:jian.j.wang@intel.com> ; 'Bi, Dandan'
<mailto:dandan.bi@intel.com> 
Subject: 回复: [edk2-devel] [PATCH v1 06/15] MdeModulePkg:
SmmReportStatusCodeLib: ReportStatusCodeLib in StandaloneMm

 

Kun:

 I am OK for this solution. Have you plan to update StatusCodeHandlerSmm?

 

Thanks

Liming

发件人: bounce+27952+69397+4905953+8761045@groups.io
<mailto:bounce+27952+69397+4905953+8761045@groups.io>
<bounce+27952+69397+4905953+8761045@groups.io
<mailto:bounce+27952+69397+4905953+8761045@groups.io> > 代表 Wu, Hao A
发送时间: 2020年12月23日 14:10
收件人: devel@edk2.groups.io <mailto:devel@edk2.groups.io> ;
kun.q@outlook.com <mailto:kun.q@outlook.com> ; Liming Gao
<gaoliming@byosoft.com.cn <mailto:gaoliming@byosoft.com.cn> >; Yao, Jiewen
<jiewen.yao@intel.com <mailto:jiewen.yao@intel.com> >
抄送: Wang, Jian J <jian.j.wang@intel.com <mailto:jian.j.wang@intel.com> >;
Bi, Dandan <dandan.bi@intel.com <mailto:dandan.bi@intel.com> >
主题: Re: [edk2-devel] [PATCH v1 06/15] MdeModulePkg:
SmmReportStatusCodeLib: ReportStatusCodeLib in StandaloneMm

 

Hello Kun,

 

Got it, thanks for the explanation. My preference is the same with your
current proposal in the patch.

 

 

Hello Liming and Jiewen,

 

Do you have comments for this case? Thanks in advance.

 

Best Regards,

Hao Wu

 

From: devel@edk2.groups.io <mailto:devel@edk2.groups.io>
<devel@edk2.groups.io <mailto:devel@edk2.groups.io> > On Behalf Of Kun Qin
Sent: Wednesday, December 23, 2020 3:15 AM
To: devel@edk2.groups.io <mailto:devel@edk2.groups.io> ; Wu, Hao A
<hao.a.wu@intel.com <mailto:hao.a.wu@intel.com> >
Cc: Wang, Jian J <jian.j.wang@intel.com <mailto:jian.j.wang@intel.com> >;
Bi, Dandan <dandan.bi@intel.com <mailto:dandan.bi@intel.com> >; Liming Gao
<gaoliming@byosoft.com.cn <mailto:gaoliming@byosoft.com.cn> >; Yao, Jiewen
<jiewen.yao@intel.com <mailto:jiewen.yao@intel.com> >
Subject: Re: [edk2-devel] [PATCH v1 06/15] MdeModulePkg:
SmmReportStatusCodeLib: ReportStatusCodeLib in StandaloneMm

 

Hi Hao,

 

That was my original plan, but doing it might require a MmServiceTableLib
instance for SMM_CORE type if PiSmmCore links in RSC lib (similar to
PiSmmCoreSmmServicesTableLib). We can create such an instance just like
PiSmmCoreSmmServicesTableLib, but the implementation will pull in
gSmmCoreSmst as an external variable and cast it from
`EFI_SMM_SYSTEM_TABLE2` to `EFI_MM_SYSTEM_TABLE`, which does not look clean.
Thus I just abstract the routine to avoid it.

 

Please let me know if you have better ideas, I can add the change for next
patch series.

 

Thanks,

Kun

 

From: Wu, Hao A <mailto:hao.a.wu@intel.com> 
Sent: Tuesday, December 22, 2020 00:35
To: devel@edk2.groups.io <mailto:devel@edk2.groups.io> ; kun.q@outlook.com
<mailto:kun.q@outlook.com> 
Cc: Wang, Jian J <mailto:jian.j.wang@intel.com> ; Bi, Dandan <mailto:dandan.
bi@intel.com> ; Liming Gao <mailto:gaoliming@byosoft.com.cn> ; Yao, Jiewen
<mailto:jiewen.yao@intel.com> 
Subject: Re: [edk2-devel] [PATCH v1 06/15] MdeModulePkg:
SmmReportStatusCodeLib: ReportStatusCodeLib in StandaloneMm

 

> -----Original Message-----
> From: devel@edk2.groups.io <mailto:devel@edk2.groups.io>
<devel@edk2.groups.io <mailto:devel@edk2.groups.io> > On Behalf Of Kun Qin
> Sent: Saturday, December 19, 2020 2:50 AM
> To: devel@edk2.groups.io <mailto:devel@edk2.groups.io> 
> Cc: Wang, Jian J <jian.j.wang@intel.com <mailto:jian.j.wang@intel.com> >;
Wu, Hao A <hao.a.wu@intel.com <mailto:hao.a.wu@intel.com> >;
> Bi, Dandan <dandan.bi@intel.com <mailto:dandan.bi@intel.com> >; Liming Gao
<gaoliming@byosoft.com.cn <mailto:gaoliming@byosoft.com.cn> >
> Subject: [edk2-devel] [PATCH v1 06/15] MdeModulePkg:
> SmmReportStatusCodeLib: ReportStatusCodeLib in StandaloneMm
> 
> This change added support of StandaloneMm for ReportStatusCodeLib. It
> adds a new instance of ReportStatusCodeLib for MM_STANDALONE type,
> and abstracts the references of gMmst and gSmst functionalities into
> separate files in order to link in proper Service Table for SMM
core/drivers.


Sorry for a question.

Do you think it is feasible to use:
gMmst->MmLocateProtocol to locate gEfiMmStatusCodeProtocolGuid
and avoid introducing 2 separate implementations for internal function
InternalLocateProtocol()?

Since I found that the definitions for gEfiMmStatusCodeProtocolGuid an
gEfiSmmStatusCodeProtocolGuid are identical.

Best Regards,
Hao Wu


> 
> Cc: Jian J Wang <jian.j.wang@intel.com <mailto:jian.j.wang@intel.com> >
> Cc: Hao A Wu <hao.a.wu@intel.com <mailto:hao.a.wu@intel.com> >
> Cc: Dandan Bi <dandan.bi@intel.com <mailto:dandan.bi@intel.com> >
> Cc: Liming Gao <gaoliming@byosoft.com.cn <mailto:gaoliming@byosoft.com.cn>
>
> 
> Signed-off-by: Kun Qin <kun.q@outlook.com <mailto:kun.q@outlook.com> >
> ---
>  MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.c
> | 16 ++++----
> 
> MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibSta
> ndaloneMm.c                                   | 39 ++++++++++++++++++++
> 
> MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibTra
> ditional.c                                    | 39 ++++++++++++++++++++
>  MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.h
> | 37 +++++++++++++++++++
> 
> MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLi
> b.inf                                          |  4 +-
> 
> MdeModulePkg/Library/SmmReportStatusCodeLib/{SmmReportStatusCode
> Lib.inf => StandaloneMmReportStatusCodeLib.inf} | 17 +++++----
>  MdeModulePkg/MdeModulePkg.dsc
> |  1 +
>  7 files changed, 137 insertions(+), 16 deletions(-)
> 
> diff --git
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.c
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.
> c
> index 3a1772538cdf..fb1769db9223 100644
> ---
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.c
> +++
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.
> c
> @@ -1,5 +1,5 @@
>  /** @file
> -  Report Status Code Library for SMM Phase.
> +  Report Status Code Library for MM Phase.
> 
>    Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
>    SPDX-License-Identifier: BSD-2-Clause-Patent @@ -8,7 +8,7 @@
> 
>  #include <Library/ReportStatusCodeLib.h>  #include <Library/DebugLib.h> -
> #include <Library/SmmServicesTableLib.h>
> +#include <Library/MmServicesTableLib.h>
>  #include <Library/BaseLib.h>
>  #include <Library/BaseMemoryLib.h>
>  #include <Library/PcdLib.h>
> @@ -16,10 +16,12 @@
> 
>  #include <Guid/StatusCodeDataTypeId.h>
>  #include <Guid/StatusCodeDataTypeDebug.h> -#include
> <Protocol/SmmStatusCode.h>
> +#include <Protocol/MmStatusCode.h>
> 
> -EFI_SMM_REPORT_STATUS_CODE     mReportStatusCode = NULL;
> -EFI_SMM_STATUS_CODE_PROTOCOL   *mStatusCodeProtocol = NULL;
> +#include "ReportStatusCodeLib.h"
> +
> +EFI_MM_REPORT_STATUS_CODE     mReportStatusCode = NULL;
> +EFI_MM_STATUS_CODE_PROTOCOL   *mStatusCodeProtocol = NULL;
> 
> 
>  /**
> @@ -29,14 +31,14 @@ EFI_SMM_STATUS_CODE_PROTOCOL
> *mStatusCodeProtocol = NULL;
>              NULL is returned if no status code service is available.
> 
>  **/
> -EFI_SMM_REPORT_STATUS_CODE
> +EFI_MM_REPORT_STATUS_CODE
>  InternalGetReportStatusCode (
>    VOID
>    )
>  {
>    EFI_STATUS                    Status;
> 
> -  Status = gSmst->SmmLocateProtocol (&gEfiSmmStatusCodeProtocolGuid,
> NULL, (VOID**)&mStatusCodeProtocol);
> +  Status = InternalLocateProtocol (&gEfiMmStatusCodeProtocolGuid, NULL,
> + (VOID**)&mStatusCodeProtocol);
>    if (!EFI_ERROR (Status) && mStatusCodeProtocol != NULL) {
>      return mStatusCodeProtocol->ReportStatusCode;
>    }
> diff --git
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibS
> tandaloneMm.c
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibS
> tandaloneMm.c
> new file mode 100644
> index 000000000000..fc47dffe9ffb
> --- /dev/null
> +++
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibS
> ta
> +++ ndaloneMm.c
> @@ -0,0 +1,39 @@
> +/** @file
> +  Abstraction layer for MM service table used by MM ReportStatusCodeLib.
> +
> +  Copyright (c) Microsoft Corporation.
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <PiMm.h>
> +
> +#include <Library/MmServicesTableLib.h>
> +
> +/**
> +  Returns the first protocol instance that matches the given protocol.
> +
> +  @param[in]  Protocol          Provides the protocol to search for.
> +  @param[in]  Registration      Optional registration key returned from
> +                                RegisterProtocolNotify().
> +  @param[out]  Interface        On return, a pointer to the first
interface that
> matches Protocol and
> +                                Registration.
> +
> +  @retval EFI_SUCCESS           A protocol instance matching Protocol was
> found and returned in
> +                                Interface.
> +  @retval EFI_NOT_FOUND         No protocol instances were found that
> match Protocol and
> +                                Registration.
> +  @retval EFI_INVALID_PARAMETER Interface is NULL.
> +                                Protocol is NULL.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +InternalLocateProtocol (
> +  IN  EFI_GUID  *Protocol,
> +  IN  VOID      *Registration, OPTIONAL
> +  OUT VOID      **Interface
> +  )
> +{
> +  return gMmst->MmLocateProtocol (Protocol, Registration, Interface); }
> diff --git
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibT
> raditional.c
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibT
> raditional.c
> new file mode 100644
> index 000000000000..6b3a7c6051c5
> --- /dev/null
> +++
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibT
> ra
> +++ ditional.c
> @@ -0,0 +1,39 @@
> +/** @file
> +  Abstraction layer for SMM service table used by SMM
> ReportStatusCodeLib.
> +
> +  Copyright (c) Microsoft Corporation.
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <PiMm.h>
> +
> +#include <Library/SmmServicesTableLib.h>
> +
> +/**
> +  Returns the first protocol instance that matches the given protocol.
> +
> +  @param[in]  Protocol          Provides the protocol to search for.
> +  @param[in]  Registration      Optional registration key returned from
> +                                RegisterProtocolNotify().
> +  @param[out]  Interface        On return, a pointer to the first
interface that
> matches Protocol and
> +                                Registration.
> +
> +  @retval EFI_SUCCESS           A protocol instance matching Protocol was
> found and returned in
> +                                Interface.
> +  @retval EFI_NOT_FOUND         No protocol instances were found that
> match Protocol and
> +                                Registration.
> +  @retval EFI_INVALID_PARAMETER Interface is NULL.
> +                                Protocol is NULL.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +InternalLocateProtocol (
> +  IN  EFI_GUID  *Protocol,
> +  IN  VOID      *Registration, OPTIONAL
> +  OUT VOID      **Interface
> +  )
> +{
> +  return gSmst->SmmLocateProtocol (Protocol, Registration, Interface);
> +}
> diff --git
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.
> h
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.
> h
> new file mode 100644
> index 000000000000..9a16741e64f6
> --- /dev/null
> +++
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.
> h
> @@ -0,0 +1,37 @@
> +/** @file
> +  Report Status Code Library for MM Phase.
> +
> +  Copyright (c) 2009 - 2018, Intel Corporation. All rights
> + reserved.<BR>
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#ifndef _MM_RSC_LIB_H_
> +#define _MM_RSC_LIB_H_
> +
> +/**
> +  Returns the first protocol instance that matches the given protocol.
> +
> +  @param[in]  Protocol          Provides the protocol to search for.
> +  @param[in]  Registration      Optional registration key returned from
> +                                RegisterProtocolNotify().
> +  @param[out]  Interface        On return, a pointer to the first
interface that
> matches Protocol and
> +                                Registration.
> +
> +  @retval EFI_SUCCESS           A protocol instance matching Protocol was
> found and returned in
> +                                Interface.
> +  @retval EFI_NOT_FOUND         No protocol instances were found that
> match Protocol and
> +                                Registration.
> +  @retval EFI_INVALID_PARAMETER Interface is NULL.
> +                                Protocol is NULL.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +InternalLocateProtocol (
> +  IN  EFI_GUID  *Protocol,
> +  IN  VOID      *Registration, OPTIONAL
> +  OUT VOID      **Interface
> +  );
> +
> +#endif // _MM_RSC_LIB_H_
> diff --git
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCod
> eLib.inf
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCod
> eLib.inf
> index 72496bfababd..02dce09a199d 100644
> ---
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCod
> eLib.inf
> +++
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCod
> eLib
> +++ .inf
> @@ -28,6 +28,8 @@ [Defines]
> 
>  [Sources]
>    ReportStatusCodeLib.c
> +  ReportStatusCodeLib.h
> +  ReportStatusCodeLibTraditional.c
> 
>  [Packages]
>    MdePkg/MdePkg.dec
> @@ -45,7 +47,7 @@ [Guids]
>    gEfiStatusCodeDataTypeDebugGuid               ## SOMETIMES_CONSUMES
> ## UNDEFINED
> 
>  [Protocols]
> -  gEfiSmmStatusCodeProtocolGuid                 ## CONSUMES
> +  gEfiMmStatusCodeProtocolGuid                  ## CONSUMES
> 
>  [Pcd]
>    gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask  ##
> CONSUMES diff --git
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCod
> eLib.inf
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/StandaloneMmReport
> StatusCodeLib.inf
> similarity index 64%
> copy from
> MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLi
> b.inf
> copy to
> MdeModulePkg/Library/SmmReportStatusCodeLib/StandaloneMmReportSt
> atusCodeLib.inf
> index 72496bfababd..11ecc67fc4fa 100644
> ---
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCod
> eLib.inf
> +++
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/StandaloneMmReport
> Stat
> +++ usCodeLib.inf
> @@ -12,13 +12,12 @@
> 
>  [Defines]
>    INF_VERSION                    = 0x00010005
> -  BASE_NAME                      = SmmReportStatusCodeLib
> -  MODULE_UNI_FILE                = SmmReportStatusCodeLib.uni
> -  FILE_GUID                      = 67089D19-B3D6-4d9e-A0EB-FEDC1F83A1EE
> -  MODULE_TYPE                    = DXE_SMM_DRIVER
> +  BASE_NAME                      = StandaloneMmReportStatusCodeLib
> +  FILE_GUID                      = 17C7FC8C-8C5D-497E-9C0E-C21255B30E04
> +  MODULE_TYPE                    = MM_STANDALONE
>    VERSION_STRING                 = 1.0
> -  PI_SPECIFICATION_VERSION       = 0x0001000A
> -  LIBRARY_CLASS                  = ReportStatusCodeLib|DXE_SMM_DRIVER
> SMM_CORE
> +  PI_SPECIFICATION_VERSION       = 0x00010032
> +  LIBRARY_CLASS                  = ReportStatusCodeLib|MM_STANDALONE
> 
>  #
>  # The following information is for reference only and not required by the
> build tools.
> @@ -28,6 +27,8 @@ [Defines]
> 
>  [Sources]
>    ReportStatusCodeLib.c
> +  ReportStatusCodeLib.h
> +  ReportStatusCodeLibStandaloneMm.c
> 
>  [Packages]
>    MdePkg/MdePkg.dec
> @@ -36,7 +37,7 @@ [Packages]
>  [LibraryClasses]
>    PcdLib
>    BaseMemoryLib
> -  SmmServicesTableLib
> +  MmServicesTableLib
>    DebugLib
>    MemoryAllocationLib
> 
> @@ -45,7 +46,7 @@ [Guids]
>    gEfiStatusCodeDataTypeDebugGuid               ## SOMETIMES_CONSUMES
> ## UNDEFINED
> 
>  [Protocols]
> -  gEfiSmmStatusCodeProtocolGuid                 ## CONSUMES
> +  gEfiMmStatusCodeProtocolGuid                  ## CONSUMES
> 
>  [Pcd]
>    gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask  ##
> CONSUMES diff --git a/MdeModulePkg/MdeModulePkg.dsc
> b/MdeModulePkg/MdeModulePkg.dsc index cd91a70b4fdd..05bf5fe08094
> 100644
> --- a/MdeModulePkg/MdeModulePkg.dsc
> +++ b/MdeModulePkg/MdeModulePkg.dsc
> @@ -473,6 +473,7 @@ [Components.IA32, Components.X64]
>    }
> 
> MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.i
> nf
> 
> MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLi
> b.inf
> +
> +
> MdeModulePkg/Library/SmmReportStatusCodeLib/StandaloneMmReportSt
> atusCo
> + deLib.inf
> 
> MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSm
> m.inf
> 
> MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCod
> eRouterSmm.inf
>    MdeModulePkg/Universal/LockBox/SmmLockBox/SmmLockBox.inf
> --
> 2.28.0.windows.1
> 
> 
> 
> 
> 





 

 




[-- Attachment #2: Type: text/html, Size: 35165 bytes --]

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [edk2-devel] [PATCH v1 06/15] MdeModulePkg: SmmReportStatusCodeLib: ReportStatusCodeLib in StandaloneMm
  2020-12-29  1:23             ` 回复: " gaoliming
@ 2020-12-29  1:31               ` Kun Qin
  0 siblings, 0 replies; 44+ messages in thread
From: Kun Qin @ 2020-12-29  1:31 UTC (permalink / raw)
  To: devel@edk2.groups.io, gaoliming@byosoft.com.cn,
	hao.a.wu@intel.com, 'Yao, Jiewen'
  Cc: 'Wang, Jian J', 'Bi, Dandan'


[-- Attachment #1.1: Type: text/plain, Size: 18936 bytes --]

Hi Liming,

Noted, I will add the driver of StatusCodeHandlerStandaloneMm in v2 patches.

Regards,
Kun

From: gaoliming<mailto:gaoliming@byosoft.com.cn>
Sent: Monday, December 28, 2020 17:24
To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>; kun.q@outlook.com<mailto:kun.q@outlook.com>; hao.a.wu@intel.com<mailto:hao.a.wu@intel.com>; 'Yao, Jiewen'<mailto:jiewen.yao@intel.com>
Cc: 'Wang, Jian J'<mailto:jian.j.wang@intel.com>; 'Bi, Dandan'<mailto:dandan.bi@intel.com>
Subject: 回复: [edk2-devel] [PATCH v1 06/15] MdeModulePkg: SmmReportStatusCodeLib: ReportStatusCodeLib in StandaloneMm

Kun:
 I prefer to include StatusCodeHandlerSmm with the basic check. If so, the complete statuscode solution can be provided.

Thanks
Liming
发件人: bounce+27952+69443+4905953+8761045@groups.io <bounce+27952+69443+4905953+8761045@groups.io> 代表 Kun Qin
发送时间: 2020年12月24日 17:12
收件人: devel@edk2.groups.io; gaoliming@byosoft.com.cn; hao.a.wu@intel.com; 'Yao, Jiewen' <jiewen.yao@intel.com>
抄送: 'Wang, Jian J' <jian.j.wang@intel.com>; 'Bi, Dandan' <dandan.bi@intel.com>
主题: Re: [edk2-devel] [PATCH v1 06/15] MdeModulePkg: SmmReportStatusCodeLib: ReportStatusCodeLib in StandaloneMm

Liming,

I have not had a plan for StatusCodeHandlerSmm because our platforms are not using it currently (we used a MU version instead). So it would be difficult to fully validate the functionality after updates. Please let me know if you prefer to have this driver updated in this patch series, I can try to update it locally with some fundamental sanity checks.

Regards,
Kun

From: gaoliming<mailto:gaoliming@byosoft.com.cn>
Sent: Wednesday, December 23, 2020 17:53
To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>; hao.a.wu@intel.com<mailto:hao.a.wu@intel.com>; kun.q@outlook.com<mailto:kun.q@outlook.com>; 'Yao, Jiewen'<mailto:jiewen.yao@intel.com>
Cc: 'Wang, Jian J'<mailto:jian.j.wang@intel.com>; 'Bi, Dandan'<mailto:dandan.bi@intel.com>
Subject: 回复: [edk2-devel] [PATCH v1 06/15] MdeModulePkg: SmmReportStatusCodeLib: ReportStatusCodeLib in StandaloneMm

Kun:
 I am OK for this solution. Have you plan to update StatusCodeHandlerSmm?

Thanks
Liming
发件人: bounce+27952+69397+4905953+8761045@groups.io<mailto:bounce+27952+69397+4905953+8761045@groups.io> <bounce+27952+69397+4905953+8761045@groups.io<mailto:bounce+27952+69397+4905953+8761045@groups.io>> 代表 Wu, Hao A
发送时间: 2020年12月23日 14:10
收件人: devel@edk2.groups.io<mailto:devel@edk2.groups.io>; kun.q@outlook.com<mailto:kun.q@outlook.com>; Liming Gao <gaoliming@byosoft.com.cn<mailto:gaoliming@byosoft.com.cn>>; Yao, Jiewen <jiewen.yao@intel.com<mailto:jiewen.yao@intel.com>>
抄送: Wang, Jian J <jian.j.wang@intel.com<mailto:jian.j.wang@intel.com>>; Bi, Dandan <dandan.bi@intel.com<mailto:dandan.bi@intel.com>>
主题: Re: [edk2-devel] [PATCH v1 06/15] MdeModulePkg: SmmReportStatusCodeLib: ReportStatusCodeLib in StandaloneMm

Hello Kun,

Got it, thanks for the explanation. My preference is the same with your current proposal in the patch.


Hello Liming and Jiewen,

Do you have comments for this case? Thanks in advance.

Best Regards,
Hao Wu

From: devel@edk2.groups.io<mailto:devel@edk2.groups.io> <devel@edk2.groups.io<mailto:devel@edk2.groups.io>> On Behalf Of Kun Qin
Sent: Wednesday, December 23, 2020 3:15 AM
To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>; Wu, Hao A <hao.a.wu@intel.com<mailto:hao.a.wu@intel.com>>
Cc: Wang, Jian J <jian.j.wang@intel.com<mailto:jian.j.wang@intel.com>>; Bi, Dandan <dandan.bi@intel.com<mailto:dandan.bi@intel.com>>; Liming Gao <gaoliming@byosoft.com.cn<mailto:gaoliming@byosoft.com.cn>>; Yao, Jiewen <jiewen.yao@intel.com<mailto:jiewen.yao@intel.com>>
Subject: Re: [edk2-devel] [PATCH v1 06/15] MdeModulePkg: SmmReportStatusCodeLib: ReportStatusCodeLib in StandaloneMm

Hi Hao,

That was my original plan, but doing it might require a MmServiceTableLib instance for SMM_CORE type if PiSmmCore links in RSC lib (similar to PiSmmCoreSmmServicesTableLib). We can create such an instance just like PiSmmCoreSmmServicesTableLib, but the implementation will pull in gSmmCoreSmst as an external variable and cast it from `EFI_SMM_SYSTEM_TABLE2` to `EFI_MM_SYSTEM_TABLE`, which does not look clean. Thus I just abstract the routine to avoid it.

Please let me know if you have better ideas, I can add the change for next patch series.

Thanks,
Kun

From: Wu, Hao A<mailto:hao.a.wu@intel.com>
Sent: Tuesday, December 22, 2020 00:35
To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>; kun.q@outlook.com<mailto:kun.q@outlook.com>
Cc: Wang, Jian J<mailto:jian.j.wang@intel.com>; Bi, Dandan<mailto:dandan.bi@intel.com>; Liming Gao<mailto:gaoliming@byosoft.com.cn>; Yao, Jiewen<mailto:jiewen.yao@intel.com>
Subject: Re: [edk2-devel] [PATCH v1 06/15] MdeModulePkg: SmmReportStatusCodeLib: ReportStatusCodeLib in StandaloneMm

> -----Original Message-----
> From: devel@edk2.groups.io<mailto:devel@edk2.groups.io> <devel@edk2.groups.io<mailto:devel@edk2.groups.io>> On Behalf Of Kun Qin
> Sent: Saturday, December 19, 2020 2:50 AM
> To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>
> Cc: Wang, Jian J <jian.j.wang@intel.com<mailto:jian.j.wang@intel.com>>; Wu, Hao A <hao.a.wu@intel.com<mailto:hao.a.wu@intel.com>>;
> Bi, Dandan <dandan.bi@intel.com<mailto:dandan.bi@intel.com>>; Liming Gao <gaoliming@byosoft.com.cn<mailto:gaoliming@byosoft.com.cn>>
> Subject: [edk2-devel] [PATCH v1 06/15] MdeModulePkg:
> SmmReportStatusCodeLib: ReportStatusCodeLib in StandaloneMm
>
> This change added support of StandaloneMm for ReportStatusCodeLib. It
> adds a new instance of ReportStatusCodeLib for MM_STANDALONE type,
> and abstracts the references of gMmst and gSmst functionalities into
> separate files in order to link in proper Service Table for SMM core/drivers.


Sorry for a question.

Do you think it is feasible to use:
gMmst->MmLocateProtocol to locate gEfiMmStatusCodeProtocolGuid
and avoid introducing 2 separate implementations for internal function InternalLocateProtocol()?

Since I found that the definitions for gEfiMmStatusCodeProtocolGuid an gEfiSmmStatusCodeProtocolGuid are identical.

Best Regards,
Hao Wu


>
> Cc: Jian J Wang <jian.j.wang@intel.com<mailto:jian.j.wang@intel.com>>
> Cc: Hao A Wu <hao.a.wu@intel.com<mailto:hao.a.wu@intel.com>>
> Cc: Dandan Bi <dandan.bi@intel.com<mailto:dandan.bi@intel.com>>
> Cc: Liming Gao <gaoliming@byosoft.com.cn<mailto:gaoliming@byosoft.com.cn>>
>
> Signed-off-by: Kun Qin <kun.q@outlook.com<mailto:kun.q@outlook.com>>
> ---
>  MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.c
> | 16 ++++----
>
> MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibSta
> ndaloneMm.c                                   | 39 ++++++++++++++++++++
>
> MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibTra
> ditional.c                                    | 39 ++++++++++++++++++++
>  MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.h
> | 37 +++++++++++++++++++
>
> MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLi
> b.inf                                          |  4 +-
>
> MdeModulePkg/Library/SmmReportStatusCodeLib/{SmmReportStatusCode
> Lib.inf => StandaloneMmReportStatusCodeLib.inf} | 17 +++++----
>  MdeModulePkg/MdeModulePkg.dsc
> |  1 +
>  7 files changed, 137 insertions(+), 16 deletions(-)
>
> diff --git
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.c
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.
> c
> index 3a1772538cdf..fb1769db9223 100644
> ---
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.c
> +++
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.
> c
> @@ -1,5 +1,5 @@
>  /** @file
> -  Report Status Code Library for SMM Phase.
> +  Report Status Code Library for MM Phase.
>
>    Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
>    SPDX-License-Identifier: BSD-2-Clause-Patent @@ -8,7 +8,7 @@
>
>  #include <Library/ReportStatusCodeLib.h>  #include <Library/DebugLib.h> -
> #include <Library/SmmServicesTableLib.h>
> +#include <Library/MmServicesTableLib.h>
>  #include <Library/BaseLib.h>
>  #include <Library/BaseMemoryLib.h>
>  #include <Library/PcdLib.h>
> @@ -16,10 +16,12 @@
>
>  #include <Guid/StatusCodeDataTypeId.h>
>  #include <Guid/StatusCodeDataTypeDebug.h> -#include
> <Protocol/SmmStatusCode.h>
> +#include <Protocol/MmStatusCode.h>
>
> -EFI_SMM_REPORT_STATUS_CODE     mReportStatusCode = NULL;
> -EFI_SMM_STATUS_CODE_PROTOCOL   *mStatusCodeProtocol = NULL;
> +#include "ReportStatusCodeLib.h"
> +
> +EFI_MM_REPORT_STATUS_CODE     mReportStatusCode = NULL;
> +EFI_MM_STATUS_CODE_PROTOCOL   *mStatusCodeProtocol = NULL;
>
>
>  /**
> @@ -29,14 +31,14 @@ EFI_SMM_STATUS_CODE_PROTOCOL
> *mStatusCodeProtocol = NULL;
>              NULL is returned if no status code service is available.
>
>  **/
> -EFI_SMM_REPORT_STATUS_CODE
> +EFI_MM_REPORT_STATUS_CODE
>  InternalGetReportStatusCode (
>    VOID
>    )
>  {
>    EFI_STATUS                    Status;
>
> -  Status = gSmst->SmmLocateProtocol (&gEfiSmmStatusCodeProtocolGuid,
> NULL, (VOID**)&mStatusCodeProtocol);
> +  Status = InternalLocateProtocol (&gEfiMmStatusCodeProtocolGuid, NULL,
> + (VOID**)&mStatusCodeProtocol);
>    if (!EFI_ERROR (Status) && mStatusCodeProtocol != NULL) {
>      return mStatusCodeProtocol->ReportStatusCode;
>    }
> diff --git
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibS
> tandaloneMm.c
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibS
> tandaloneMm.c
> new file mode 100644
> index 000000000000..fc47dffe9ffb
> --- /dev/null
> +++
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibS
> ta
> +++ ndaloneMm.c
> @@ -0,0 +1,39 @@
> +/** @file
> +  Abstraction layer for MM service table used by MM ReportStatusCodeLib.
> +
> +  Copyright (c) Microsoft Corporation.
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <PiMm.h>
> +
> +#include <Library/MmServicesTableLib.h>
> +
> +/**
> +  Returns the first protocol instance that matches the given protocol.
> +
> +  @param[in]  Protocol          Provides the protocol to search for.
> +  @param[in]  Registration      Optional registration key returned from
> +                                RegisterProtocolNotify().
> +  @param[out]  Interface        On return, a pointer to the first interface that
> matches Protocol and
> +                                Registration.
> +
> +  @retval EFI_SUCCESS           A protocol instance matching Protocol was
> found and returned in
> +                                Interface.
> +  @retval EFI_NOT_FOUND         No protocol instances were found that
> match Protocol and
> +                                Registration.
> +  @retval EFI_INVALID_PARAMETER Interface is NULL.
> +                                Protocol is NULL.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +InternalLocateProtocol (
> +  IN  EFI_GUID  *Protocol,
> +  IN  VOID      *Registration, OPTIONAL
> +  OUT VOID      **Interface
> +  )
> +{
> +  return gMmst->MmLocateProtocol (Protocol, Registration, Interface); }
> diff --git
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibT
> raditional.c
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibT
> raditional.c
> new file mode 100644
> index 000000000000..6b3a7c6051c5
> --- /dev/null
> +++
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibT
> ra
> +++ ditional.c
> @@ -0,0 +1,39 @@
> +/** @file
> +  Abstraction layer for SMM service table used by SMM
> ReportStatusCodeLib.
> +
> +  Copyright (c) Microsoft Corporation.
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <PiMm.h>
> +
> +#include <Library/SmmServicesTableLib.h>
> +
> +/**
> +  Returns the first protocol instance that matches the given protocol.
> +
> +  @param[in]  Protocol          Provides the protocol to search for.
> +  @param[in]  Registration      Optional registration key returned from
> +                                RegisterProtocolNotify().
> +  @param[out]  Interface        On return, a pointer to the first interface that
> matches Protocol and
> +                                Registration.
> +
> +  @retval EFI_SUCCESS           A protocol instance matching Protocol was
> found and returned in
> +                                Interface.
> +  @retval EFI_NOT_FOUND         No protocol instances were found that
> match Protocol and
> +                                Registration.
> +  @retval EFI_INVALID_PARAMETER Interface is NULL.
> +                                Protocol is NULL.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +InternalLocateProtocol (
> +  IN  EFI_GUID  *Protocol,
> +  IN  VOID      *Registration, OPTIONAL
> +  OUT VOID      **Interface
> +  )
> +{
> +  return gSmst->SmmLocateProtocol (Protocol, Registration, Interface);
> +}
> diff --git
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.
> h
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.
> h
> new file mode 100644
> index 000000000000..9a16741e64f6
> --- /dev/null
> +++
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.
> h
> @@ -0,0 +1,37 @@
> +/** @file
> +  Report Status Code Library for MM Phase.
> +
> +  Copyright (c) 2009 - 2018, Intel Corporation. All rights
> + reserved.<BR>
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#ifndef _MM_RSC_LIB_H_
> +#define _MM_RSC_LIB_H_
> +
> +/**
> +  Returns the first protocol instance that matches the given protocol.
> +
> +  @param[in]  Protocol          Provides the protocol to search for.
> +  @param[in]  Registration      Optional registration key returned from
> +                                RegisterProtocolNotify().
> +  @param[out]  Interface        On return, a pointer to the first interface that
> matches Protocol and
> +                                Registration.
> +
> +  @retval EFI_SUCCESS           A protocol instance matching Protocol was
> found and returned in
> +                                Interface.
> +  @retval EFI_NOT_FOUND         No protocol instances were found that
> match Protocol and
> +                                Registration.
> +  @retval EFI_INVALID_PARAMETER Interface is NULL.
> +                                Protocol is NULL.
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +InternalLocateProtocol (
> +  IN  EFI_GUID  *Protocol,
> +  IN  VOID      *Registration, OPTIONAL
> +  OUT VOID      **Interface
> +  );
> +
> +#endif // _MM_RSC_LIB_H_
> diff --git
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCod
> eLib.inf
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCod
> eLib.inf
> index 72496bfababd..02dce09a199d 100644
> ---
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCod
> eLib.inf
> +++
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCod
> eLib
> +++ .inf
> @@ -28,6 +28,8 @@ [Defines]
>
>  [Sources]
>    ReportStatusCodeLib.c
> +  ReportStatusCodeLib.h
> +  ReportStatusCodeLibTraditional.c
>
>  [Packages]
>    MdePkg/MdePkg.dec
> @@ -45,7 +47,7 @@ [Guids]
>    gEfiStatusCodeDataTypeDebugGuid               ## SOMETIMES_CONSUMES
> ## UNDEFINED
>
>  [Protocols]
> -  gEfiSmmStatusCodeProtocolGuid                 ## CONSUMES
> +  gEfiMmStatusCodeProtocolGuid                  ## CONSUMES
>
>  [Pcd]
>    gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask  ##
> CONSUMES diff --git
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCod
> eLib.inf
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/StandaloneMmReport
> StatusCodeLib.inf
> similarity index 64%
> copy from
> MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLi
> b.inf
> copy to
> MdeModulePkg/Library/SmmReportStatusCodeLib/StandaloneMmReportSt
> atusCodeLib.inf
> index 72496bfababd..11ecc67fc4fa 100644
> ---
> a/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCod
> eLib.inf
> +++
> b/MdeModulePkg/Library/SmmReportStatusCodeLib/StandaloneMmReport
> Stat
> +++ usCodeLib.inf
> @@ -12,13 +12,12 @@
>
>  [Defines]
>    INF_VERSION                    = 0x00010005
> -  BASE_NAME                      = SmmReportStatusCodeLib
> -  MODULE_UNI_FILE                = SmmReportStatusCodeLib.uni
> -  FILE_GUID                      = 67089D19-B3D6-4d9e-A0EB-FEDC1F83A1EE
> -  MODULE_TYPE                    = DXE_SMM_DRIVER
> +  BASE_NAME                      = StandaloneMmReportStatusCodeLib
> +  FILE_GUID                      = 17C7FC8C-8C5D-497E-9C0E-C21255B30E04
> +  MODULE_TYPE                    = MM_STANDALONE
>    VERSION_STRING                 = 1.0
> -  PI_SPECIFICATION_VERSION       = 0x0001000A
> -  LIBRARY_CLASS                  = ReportStatusCodeLib|DXE_SMM_DRIVER
> SMM_CORE
> +  PI_SPECIFICATION_VERSION       = 0x00010032
> +  LIBRARY_CLASS                  = ReportStatusCodeLib|MM_STANDALONE
>
>  #
>  # The following information is for reference only and not required by the
> build tools.
> @@ -28,6 +27,8 @@ [Defines]
>
>  [Sources]
>    ReportStatusCodeLib.c
> +  ReportStatusCodeLib.h
> +  ReportStatusCodeLibStandaloneMm.c
>
>  [Packages]
>    MdePkg/MdePkg.dec
> @@ -36,7 +37,7 @@ [Packages]
>  [LibraryClasses]
>    PcdLib
>    BaseMemoryLib
> -  SmmServicesTableLib
> +  MmServicesTableLib
>    DebugLib
>    MemoryAllocationLib
>
> @@ -45,7 +46,7 @@ [Guids]
>    gEfiStatusCodeDataTypeDebugGuid               ## SOMETIMES_CONSUMES
> ## UNDEFINED
>
>  [Protocols]
> -  gEfiSmmStatusCodeProtocolGuid                 ## CONSUMES
> +  gEfiMmStatusCodeProtocolGuid                  ## CONSUMES
>
>  [Pcd]
>    gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask  ##
> CONSUMES diff --git a/MdeModulePkg/MdeModulePkg.dsc
> b/MdeModulePkg/MdeModulePkg.dsc index cd91a70b4fdd..05bf5fe08094
> 100644
> --- a/MdeModulePkg/MdeModulePkg.dsc
> +++ b/MdeModulePkg/MdeModulePkg.dsc
> @@ -473,6 +473,7 @@ [Components.IA32, Components.X64]
>    }
>
> MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.i
> nf
>
> MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLi
> b.inf
> +
> +
> MdeModulePkg/Library/SmmReportStatusCodeLib/StandaloneMmReportSt
> atusCo
> + deLib.inf
>
> MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSm
> m.inf
>
> MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCod
> eRouterSmm.inf
>    MdeModulePkg/Universal/LockBox/SmmLockBox/SmmLockBox.inf
> --
> 2.28.0.windows.1
>
>
>
>
>







[-- Attachment #1.2: Type: text/html, Size: 35475 bytes --]

[-- Attachment #2: B046D1591A6846FF9FDD441CA8CBB1DE.png --]
[-- Type: image/png, Size: 140 bytes --]

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [edk2-devel] [PATCH v1 15/15] UefiCpuPkg: SmmCpuExceptionHandlerLib: Added StandaloneMm module support
  2020-12-18 18:50 ` [PATCH v1 15/15] UefiCpuPkg: SmmCpuExceptionHandlerLib: Added StandaloneMm module support Kun Qin
@ 2021-01-04 18:30   ` Kun Qin
  0 siblings, 0 replies; 44+ messages in thread
From: Kun Qin @ 2021-01-04 18:30 UTC (permalink / raw)
  To: Kun Qin, devel

[-- Attachment #1: Type: text/plain, Size: 84 bytes --]

Hi All,

Is there feedback on this before I send out v2 patches?

Thanks,
Kun

[-- Attachment #2: Type: text/html, Size: 104 bytes --]

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [edk2-devel] [PATCH v1 10/15] PcAtChipsetPkg: AcpiTimerLib: Added StandaloneMm instance of AcpiTimerLib
  2020-12-18 18:50 ` [PATCH v1 10/15] PcAtChipsetPkg: AcpiTimerLib: Added StandaloneMm instance of AcpiTimerLib Kun Qin
@ 2021-01-04 18:30   ` Kun Qin
  0 siblings, 0 replies; 44+ messages in thread
From: Kun Qin @ 2021-01-04 18:30 UTC (permalink / raw)
  To: Kun Qin, devel

[-- Attachment #1: Type: text/plain, Size: 84 bytes --]

Hi All,

Is there feedback on this before I send out v2 patches?

Thanks,
Kun

[-- Attachment #2: Type: text/html, Size: 104 bytes --]

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [edk2-devel] [PATCH v1 14/15] UefiCpuPkg: CpuIo2Smm: Support of CpuIo driver under StandaloneMm
  2020-12-18 18:50 ` [PATCH v1 14/15] UefiCpuPkg: CpuIo2Smm: Support of CpuIo driver under StandaloneMm Kun Qin
@ 2021-01-04 18:31   ` Kun Qin
  0 siblings, 0 replies; 44+ messages in thread
From: Kun Qin @ 2021-01-04 18:31 UTC (permalink / raw)
  To: Kun Qin, devel

[-- Attachment #1: Type: text/plain, Size: 84 bytes --]

Hi All,

Is there feedback on this before I send out v2 patches?

Thanks,
Kun

[-- Attachment #2: Type: text/html, Size: 104 bytes --]

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [edk2-devel] [PATCH v1 09/15] MdePkg: UefiDevicePathLib: Support UefiDevicePathLib under StandaloneMm
  2020-12-18 18:50 ` [PATCH v1 09/15] MdePkg: UefiDevicePathLib: Support UefiDevicePathLib under StandaloneMm Kun Qin
@ 2021-01-04 18:32   ` Kun Qin
  2021-01-05 13:25     ` 回复: " gaoliming
  0 siblings, 1 reply; 44+ messages in thread
From: Kun Qin @ 2021-01-04 18:32 UTC (permalink / raw)
  To: Kun Qin, devel

[-- Attachment #1: Type: text/plain, Size: 84 bytes --]

Hi All,

Is there feedback on this before I send out v2 patches?

Thanks,
Kun

[-- Attachment #2: Type: text/html, Size: 104 bytes --]

^ permalink raw reply	[flat|nested] 44+ messages in thread

* 回复: [edk2-devel] [PATCH v1 09/15] MdePkg: UefiDevicePathLib: Support UefiDevicePathLib under StandaloneMm
  2021-01-04 18:32   ` [edk2-devel] " Kun Qin
@ 2021-01-05 13:25     ` gaoliming
  0 siblings, 0 replies; 44+ messages in thread
From: gaoliming @ 2021-01-05 13:25 UTC (permalink / raw)
  To: devel, kun.q

[-- Attachment #1: Type: text/plain, Size: 515 bytes --]

This patch is good to me. Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>

 

发件人: bounce+27952+69621+4905953+8761045@groups.io <bounce+27952+69621+4905953+8761045@groups.io> 代表 Kun Qin
发送时间: 2021年1月5日 2:32
收件人: Kun Qin <kun.q@outlook.com>; devel@edk2.groups.io
主题: Re: [edk2-devel] [PATCH v1 09/15] MdePkg: UefiDevicePathLib: Support UefiDevicePathLib under StandaloneMm

 

Hi All,

Is there feedback on this before I send out v2 patches?

Thanks,
Kun 




[-- Attachment #2: Type: text/html, Size: 3629 bytes --]

^ permalink raw reply	[flat|nested] 44+ messages in thread

* Re: [edk2-devel] [PATCH v1 02/15] StandaloneMmPkg: StandaloneMmCoreHobLib: Extend support for x64 Mm Core
  2020-12-28  0:12   ` Yao, Jiewen
@ 2021-03-24 20:33     ` Dawn
  0 siblings, 0 replies; 44+ messages in thread
From: Dawn @ 2021-03-24 20:33 UTC (permalink / raw)
  To: devel, jiewen.yao, Yao, Jiewen, Kun Qin, devel@edk2.groups.io
  Cc: Ard Biesheuvel, Sami Mujawar, Supreeth Venkatesh

[-- Attachment #1: Type: text/plain, Size: 13293 bytes --]

Importing spamReporting Tracking successful 
  On Fri, Mar 12, 2021 at 4:46 AM, Yao, Jiewen<jiewen.yao@intel.com> wrote:   Can we merge the common part between X64 and AArch64 into one Common.c?

> -----Original Message-----
> From: Kun Qin <kun.q@outlook.com>
> Sent: Saturday, December 19, 2020 2:50 AM
> To: devel@edk2.groups.io
> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>; Sami Mujawar
> <sami.mujawar@arm.com>; Yao, Jiewen <jiewen.yao@intel.com>; Supreeth
> Venkatesh <supreeth.venkatesh@arm.com>
> Subject: [PATCH v1 02/15] StandaloneMmPkg: StandaloneMmCoreHobLib:
> Extend support for x64 Mm Core
> 
> This change adds support of x64 version of StandaloneMmCoreHobLib. It
> brings in global variable "gHobList" through StandaloneMmCoreEntryPoint
> and imports implementation from DxeCoreHobLib.inf to support x64 Mm
> Core.
> 
> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
> Cc: Sami Mujawar <sami.mujawar@arm.com>
> Cc: Jiewen Yao <jiewen.yao@intel.com>
> Cc: Supreeth Venkatesh <supreeth.venkatesh@arm.com>
> 
> Signed-off-by: Kun Qin <kun.q@outlook.com>
> ---
>  StandaloneMmPkg/Library/StandaloneMmCoreHobLib/{ =>
> AArch64}/StandaloneMmCoreHobLib.c |  6 +-
>  StandaloneMmPkg/Library/StandaloneMmCoreHobLib/{ =>
> X64}/StandaloneMmCoreHobLib.c    | 426 ++++++++++----------
> 
> StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmCore
> HobLib.inf            |  8 +-
>  3 files changed, 215 insertions(+), 225 deletions(-)
> 
> diff --git
> a/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmCo
> reHobLib.c
> b/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/AArch64/Standal
> oneMmCoreHobLib.c
> similarity index 96%
> copy from
> StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmCore
> HobLib.c
> copy to
> StandaloneMmPkg/Library/StandaloneMmCoreHobLib/AArch64/Standalon
> eMmCoreHobLib.c
> index e3d4743b63f2..006bff816e39 100644
> ---
> a/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmCo
> reHobLib.c
> +++
> b/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/AArch64/Standal
> oneMmCoreHobLib.c
> @@ -13,14 +13,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
>  #include <Library/HobLib.h>
>  #include <Library/DebugLib.h>
>  #include <Library/BaseMemoryLib.h>
> +#include <Library/StandaloneMmCoreEntryPoint.h>
> 
>  #include <Guid/MemoryAllocationHob.h>
> 
> -//
> -// Cache copy of HobList pointer.
> -//
> -VOID *gHobList = NULL;
> -
>  /**
>    Returns the pointer to the HOB list.
> 
> diff --git
> a/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmCo
> reHobLib.c
> b/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/X64/Standalone
> MmCoreHobLib.c
> similarity index 70%
> rename from
> StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmCore
> HobLib.c
> rename to
> StandaloneMmPkg/Library/StandaloneMmCoreHobLib/X64/StandaloneM
> mCoreHobLib.c
> index e3d4743b63f2..69b20bf07a21 100644
> ---
> a/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmCo
> reHobLib.c
> +++
> b/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/X64/Standalone
> MmCoreHobLib.c
> @@ -13,14 +13,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
>  #include <Library/HobLib.h>
>  #include <Library/DebugLib.h>
>  #include <Library/BaseMemoryLib.h>
> +#include <Library/StandaloneMmCoreEntryPoint.h>
> 
>  #include <Guid/MemoryAllocationHob.h>
> 
> -//
> -// Cache copy of HobList pointer.
> -//
> -VOID *gHobList = NULL;
> -
>  /**
>    Returns the pointer to the HOB list.
> 
> @@ -203,48 +199,13 @@ GetBootModeHob (
>    return HandOffHob->BootMode;
>  }
> 
> -VOID *
> -CreateHob (
> -  IN  UINT16    HobType,
> -  IN  UINT16    HobLength
> -  )
> -{
> -  EFI_HOB_HANDOFF_INFO_TABLE  *HandOffHob;
> -  EFI_HOB_GENERIC_HEADER      *HobEnd;
> -  EFI_PHYSICAL_ADDRESS        FreeMemory;
> -  VOID                        *Hob;
> -
> -  HandOffHob = GetHobList ();
> -
> -  HobLength = (UINT16)((HobLength + 0x7) & (~0x7));
> -
> -  FreeMemory = HandOffHob->EfiFreeMemoryTop - HandOffHob-
> >EfiFreeMemoryBottom;
> -
> -  if (FreeMemory < HobLength) {
> -    return NULL;
> -  }
> -
> -  Hob = (VOID*) (UINTN) HandOffHob->EfiEndOfHobList;
> -  ((EFI_HOB_GENERIC_HEADER*) Hob)->HobType = HobType;
> -  ((EFI_HOB_GENERIC_HEADER*) Hob)->HobLength = HobLength;
> -  ((EFI_HOB_GENERIC_HEADER*) Hob)->Reserved = 0;
> -
> -  HobEnd = (EFI_HOB_GENERIC_HEADER*) ((UINTN)Hob + HobLength);
> -  HandOffHob->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN)
> HobEnd;
> -
> -  HobEnd->HobType  = EFI_HOB_TYPE_END_OF_HOB_LIST;
> -  HobEnd->HobLength = sizeof (EFI_HOB_GENERIC_HEADER);
> -  HobEnd->Reserved  = 0;
> -  HobEnd++;
> -  HandOffHob->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN)
> HobEnd;
> -
> -  return Hob;
> -}
> -
>  /**
>    Builds a HOB for a loaded PE32 module.
> 
>    This function builds a HOB for a loaded PE32 module.
> +  It can only be invoked during PEI phase;
> +  for MM phase, it will ASSERT() because PEI HOB is read-only for MM
> phase.
> +
>    If ModuleName is NULL, then ASSERT().
>    If there is no additional space for HOB creation, then ASSERT().
> 
> @@ -263,31 +224,51 @@ BuildModuleHob (
>    IN EFI_PHYSICAL_ADDRESS  EntryPoint
>    )
>  {
> -  EFI_HOB_MEMORY_ALLOCATION_MODULE  *Hob;
> +  //
> +  // PEI HOB is read only for MM phase
> +  //
> +  ASSERT (FALSE);
> +}
> 
> -  ASSERT (((MemoryAllocationModule & (EFI_PAGE_SIZE - 1)) == 0) &&
> -          ((ModuleLength & (EFI_PAGE_SIZE - 1)) == 0));
> +/**
> +  Builds a HOB that describes a chunk of system memory with Owner GUID.
> 
> -  Hob = CreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, sizeof
> (EFI_HOB_MEMORY_ALLOCATION_MODULE));
> +  This function builds a HOB that describes a chunk of system memory.
> +  It can only be invoked during PEI phase;
> +  for MM phase, it will ASSERT() since PEI HOB is read-only for MM phase.
> 
> -  CopyGuid (&(Hob->MemoryAllocationHeader.Name),
> &gEfiHobMemoryAllocModuleGuid);
> -  Hob->MemoryAllocationHeader.MemoryBaseAddress =
> MemoryAllocationModule;
> -  Hob->MemoryAllocationHeader.MemoryLength      = ModuleLength;
> -  Hob->MemoryAllocationHeader.MemoryType        = EfiBootServicesCode;
> +  If there is no additional space for HOB creation, then ASSERT().
> 
> +  @param  ResourceType        The type of resource described by this HOB.
> +  @param  ResourceAttribute  The resource attributes of the memory
> described by this HOB.
> +  @param  PhysicalStart      The 64 bit physical address of memory
> described by this HOB.
> +  @param  NumberOfBytes      The length of the memory described by this
> HOB in bytes.
> +  @param  OwnerGUID          GUID for the owner of this resource.
> +
> +**/
> +VOID
> +EFIAPI
> +BuildResourceDescriptorWithOwnerHob (
> +  IN EFI_RESOURCE_TYPE            ResourceType,
> +  IN EFI_RESOURCE_ATTRIBUTE_TYPE  ResourceAttribute,
> +  IN EFI_PHYSICAL_ADDRESS        PhysicalStart,
> +  IN UINT64                      NumberOfBytes,
> +  IN EFI_GUID                    *OwnerGUID
> +  )
> +{
>    //
> -  // Zero the reserved space to match HOB spec
> +  // PEI HOB is read only for MM phase
>    //
> -  ZeroMem (Hob->MemoryAllocationHeader.Reserved, sizeof (Hob-
> >MemoryAllocationHeader.Reserved));
> -
> -  CopyGuid (&Hob->ModuleName, ModuleName);
> -  Hob->EntryPoint = EntryPoint;
> +  ASSERT (FALSE);
>  }
> 
>  /**
>    Builds a HOB that describes a chunk of system memory.
> 
>    This function builds a HOB that describes a chunk of system memory.
> +  It can only be invoked during PEI phase;
> +  for MM phase, it will ASSERT() because PEI HOB is read-only for MM
> phase.
> +
>    If there is no additional space for HOB creation, then ASSERT().
> 
>    @param  ResourceType        The type of resource described by this HOB.
> @@ -305,31 +286,32 @@ BuildResourceDescriptorHob (
>    IN UINT64                      NumberOfBytes
>    )
>  {
> -  EFI_HOB_RESOURCE_DESCRIPTOR  *Hob;
> -
> -  Hob = CreateHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, sizeof
> (EFI_HOB_RESOURCE_DESCRIPTOR));
> -  ASSERT (Hob != NULL);
> -
> -  Hob->ResourceType      = ResourceType;
> -  Hob->ResourceAttribute = ResourceAttribute;
> -  Hob->PhysicalStart    = PhysicalStart;
> -  Hob->ResourceLength    = NumberOfBytes;
> +  //
> +  // PEI HOB is read only for MM phase
> +  //
> +  ASSERT (FALSE);
>  }
> 
>  /**
> -  Builds a GUID HOB with a certain data length.
> +  Builds a customized HOB tagged with a GUID for identification and
> returns
> +  the start address of GUID HOB data.
> 
>    This function builds a customized HOB tagged with a GUID for
> identification
>    and returns the start address of GUID HOB data so that caller can fill the
> customized data.
>    The HOB Header and Name field is already stripped.
> +  It can only be invoked during PEI phase.
> +  For MM phase, it will ASSERT() because PEI HOB is read-only for MM
> phase.
> +
>    If Guid is NULL, then ASSERT().
>    If there is no additional space for HOB creation, then ASSERT().
> -  If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
> +  If DataLength > (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
> +  HobLength is UINT16 and multiples of 8 bytes, so the max HobLength is
> 0xFFF8.
> 
>    @param  Guid          The GUID to tag the customized HOB.
>    @param  DataLength    The size of the data payload for the GUID HOB.
> 
> -  @return The start address of GUID HOB data.
> +  @retval  NULL        The GUID HOB could not be allocated.
> +  @retval  others      The start address of GUID HOB data.
> 
>  **/
>  VOID *
> @@ -339,35 +321,36 @@ BuildGuidHob (
>    IN UINTN                      DataLength
>    )
>  {
> -  EFI_HOB_GUID_TYPE *Hob;
> -
>    //
> -  // Make sure that data length is not too long.
> +  // PEI HOB is read only for MM phase
>    //
> -  ASSERT (DataLength <= (0xffff - sizeof (EFI_HOB_GUID_TYPE)));
> -
> -  Hob = CreateHob (EFI_HOB_TYPE_GUID_EXTENSION, (UINT16) (sizeof
> (EFI_HOB_GUID_TYPE) + DataLength));
> -  CopyGuid (&Hob->Name, Guid);
> -  return Hob + 1;
> +  ASSERT (FALSE);
> +  return NULL;
>  }
> 
> -
>  /**
> -  Copies a data buffer to a newly-built HOB.
> +  Builds a customized HOB tagged with a GUID for identification, copies the
> input data to the HOB
> +  data field, and returns the start address of the GUID HOB data.
> 
> -  This function builds a customized HOB tagged with a GUID for
> identification,
> -  copies the input data to the HOB data field and returns the start address
> of the GUID HOB data.
> +  This function builds a customized HOB tagged with a GUID for
> identification and copies the input
> +  data to the HOB data field and returns the start address of the GUID HOB
> data.  It can only be
> +  invoked during PEI phase; for MM phase, it will ASSERT() because PEI
> HOB is read-only for MM phase.
>    The HOB Header and Name field is already stripped.
> +  It can only be invoked during PEI phase.
> +  For MM phase, it will ASSERT() because PEI HOB is read-only for MM
> phase.
> +
>    If Guid is NULL, then ASSERT().
>    If Data is NULL and DataLength > 0, then ASSERT().
>    If there is no additional space for HOB creation, then ASSERT().
> -  If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
> +  If DataLength > (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
> +  HobLength is UINT16 and multiples of 8 bytes, so the max HobLength is
> 0xFFF8.
> 
>    @param  Guid          The GUID to tag the customized HOB.
>    @param  Data          The data to be copied into the data field of the GUID
> HOB.
>    @param  DataLength    The size of the data payload for the GUID HOB.
> 
> -  @return The start address of GUID HOB data.
> +  @retval  NULL        The GUID HOB could not be allocated.
> +  @retval  others      The start address of GUID HOB data.
> 
>  **/
>  VOID *
> @@ -378,20 +361,22 @@ BuildGuidDataHob (
>    IN UINTN                      DataLength
>    )
>  {
> -  VOID  *HobData;
> -
> -  ASSERT (Data != NULL || DataLength == 0);
> -
> -  HobData = BuildGuidHob (Guid, DataLength);
> -
> -  return CopyMem (HobData, Data, DataLength);
> +  //
> +  // PEI HOB is read only for MM phase
> +  //
> +  ASSERT (FALSE);
> +  return NULL;
>  }
> 
>  /**
>    Builds a Firmware Volume HOB.
> 
>    This function builds a Firmware Volume HOB.
> +  It can only be invoked during PEI phase;
> +  for MM phase, it will ASSERT() because PEI HOB is read-only for MM
> phase.
> +
>    If there is no additional space for HOB creation, then ASSERT().
> +  If the FvImage buffer is not at its required alignment, then ASSERT()

[-- Attachment #2: Type: text/html, Size: 26508 bytes --]

^ permalink raw reply	[flat|nested] 44+ messages in thread

end of thread, other threads:[~2021-03-24 20:33 UTC | newest]

Thread overview: 44+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20201218185011.1366-1-kun.q@outlook.com>
2020-12-18 18:49 ` [PATCH v1 01/15] StandaloneMmPkg: StandaloneMmCoreEntryPoint: Extends support for X64 Kun Qin
2020-12-28  0:11   ` [edk2-devel] " Yao, Jiewen
2020-12-18 18:49 ` [PATCH v1 02/15] StandaloneMmPkg: StandaloneMmCoreHobLib: Extend support for x64 Mm Core Kun Qin
2020-12-28  0:12   ` Yao, Jiewen
2021-03-24 20:33     ` [edk2-devel] " Dawn
2020-12-18 18:49 ` [PATCH v1 03/15] StandaloneMmPkg: StandaloneMmCoreMemoryAllocationLib: Fix compiler warning Kun Qin
2020-12-28  0:14   ` Yao, Jiewen
2020-12-28  4:07     ` Kun Qin
2020-12-18 18:50 ` [PATCH v1 04/15] StandaloneMmPkg: StandaloneMmMemLib: Extends support for X64 architecture Kun Qin
2020-12-28  0:18   ` Yao, Jiewen
2020-12-28  4:15     ` Kun Qin
2020-12-28  6:24       ` Yao, Jiewen
2020-12-28  6:36         ` Kun Qin
2020-12-28  6:37           ` [edk2-devel] " Yao, Jiewen
2020-12-18 18:50 ` [PATCH v1 05/15] MdeModulePkg: SmmLockBoxSmmLib: Support StandaloneMm for SmmLockBoxLib Kun Qin
2020-12-22  8:35   ` [edk2-devel] " Wu, Hao A
2020-12-18 18:50 ` [PATCH v1 06/15] MdeModulePkg: SmmReportStatusCodeLib: ReportStatusCodeLib in StandaloneMm Kun Qin
2020-12-22  8:35   ` [edk2-devel] " Wu, Hao A
2020-12-22 19:15     ` Kun Qin
2020-12-23  6:09       ` Wu, Hao A
2020-12-24  1:53         ` 回复: " gaoliming
2020-12-24  9:11           ` Kun Qin
2020-12-29  1:23             ` 回复: " gaoliming
2020-12-29  1:31               ` Kun Qin
2020-12-18 18:50 ` [PATCH v1 07/15] MdeModulePkg: FirmwarePerformanceDataTable: Added StandaloneMm support Kun Qin
2020-12-22  8:36   ` Wu, Hao A
2020-12-22 20:06     ` [edk2-devel] " Kun Qin
2020-12-18 18:50 ` [PATCH v1 08/15] MdeModulePkg: ReportStatusCodeRouter: Support StandaloneMm RSC Router Kun Qin
2020-12-22  8:42   ` Wu, Hao A
2020-12-18 18:50 ` [PATCH v1 09/15] MdePkg: UefiDevicePathLib: Support UefiDevicePathLib under StandaloneMm Kun Qin
2021-01-04 18:32   ` [edk2-devel] " Kun Qin
2021-01-05 13:25     ` 回复: " gaoliming
2020-12-18 18:50 ` [PATCH v1 10/15] PcAtChipsetPkg: AcpiTimerLib: Added StandaloneMm instance of AcpiTimerLib Kun Qin
2021-01-04 18:30   ` [edk2-devel] " Kun Qin
2020-12-18 18:50 ` [PATCH v1 11/15] SecurityPkg: Tcg2PhysicalPresenceLib: Introduce StandaloneMm instance Kun Qin
2020-12-28  0:08   ` Yao, Jiewen
2020-12-18 18:50 ` [PATCH v1 12/15] SecurityPkg: Tcg2PpVendorLibNull: Added support for MM_STANDALONE type Kun Qin
2020-12-28  0:08   ` Yao, Jiewen
2020-12-18 18:50 ` [PATCH v1 13/15] SecurityPkg: Tpm2DeviceLibDTpm: Introduce StandaloneMm instance Kun Qin
2020-12-28  0:08   ` Yao, Jiewen
2020-12-18 18:50 ` [PATCH v1 14/15] UefiCpuPkg: CpuIo2Smm: Support of CpuIo driver under StandaloneMm Kun Qin
2021-01-04 18:31   ` [edk2-devel] " Kun Qin
2020-12-18 18:50 ` [PATCH v1 15/15] UefiCpuPkg: SmmCpuExceptionHandlerLib: Added StandaloneMm module support Kun Qin
2021-01-04 18:30   ` [edk2-devel] " Kun Qin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox