public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v3 06/18] MdeModulePkg: SmmLockBoxSmmLib: Support StandaloneMm for SmmLockBoxLib
       [not found] <20210114223637.2737-1-kun.q@outlook.com>
@ 2021-01-14 22:36 ` Kun Qin
  2021-01-14 22:36 ` [PATCH v3 07/18] MdeModulePkg: SmmReportStatusCodeLib: ReportStatusCodeLib in StandaloneMm Kun Qin
                   ` (12 subsequent siblings)
  13 siblings, 0 replies; 25+ messages in thread
From: Kun Qin @ 2021-01-14 22:36 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>
Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
---

Notes:
    v3:
    - Previously reviewed. No change.
    
    v2:
    - Removed "EFIAPI" for internal library functions [Hao]
    - Added Reviewed-by tag [Hao]

 MdeModulePkg/Library/SmmLockBoxLib/{SmmLockBoxSmmLib.c => SmmLockBoxMmLib.c}               | 82 +++++++++-----------
 MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxStandaloneMmLib.c                             | 53 +++++++++++++
 MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxTraditionalMmLib.c                            | 53 +++++++++++++
 MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxLibPrivate.h                                  | 25 ++++++
 MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.inf                                    | 15 ++--
 MdeModulePkg/Library/SmmLockBoxLib/{SmmLockBoxSmmLib.inf => SmmLockBoxStandaloneMmLib.inf} | 26 ++++---
 MdeModulePkg/MdeModulePkg.dsc                                                              |  2 +
 7 files changed, 191 insertions(+), 65 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..a709851806eb 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,24 @@ 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 +217,8 @@ SmmLockBoxSmmConstructor (
   //
   // Register SmmEndOfDxe notification.
   //
-  Status = gSmst->SmmRegisterProtocolNotify (
-                    &gEfiSmmEndOfDxeProtocolGuid,
+  Status = gMmst->MmRegisterProtocolNotify (
+                    &gEfiMmEndOfDxeProtocolGuid,
                     SmmLockBoxSmmEndOfDxeNotify,
                     &mSmmLockBoxRegistrationSmmEndOfDxe
                     );
@@ -232,7 +227,7 @@ SmmLockBoxSmmConstructor (
   //
   // Register EndOfS3Resume notification.
   //
-  Status = gSmst->SmmRegisterProtocolNotify (
+  Status = gMmst->MmRegisterProtocolNotify (
                     &gEdkiiEndOfS3ResumeGuid,
                     SmmLockBoxEndOfS3ResumeNotify,
                     &mSmmLockBoxRegistrationEndOfS3Resume
@@ -249,7 +244,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 +258,8 @@ SmmLockBoxSmmConstructor (
   }
   mSmmLockBoxContext.LockBoxDataAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)&mLockBoxQueue;
 
-  Status = gSmst->SmmInstallConfigurationTable (
-                    gSmst,
+  Status = gMmst->MmInstallConfigurationTable (
+                    gMmst,
                     &gEfiSmmLockBoxCommunicationGuid,
                     &mSmmLockBoxContext,
                     sizeof(mSmmLockBoxContext)
@@ -274,7 +269,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;
 }
@@ -284,26 +279,21 @@ SmmLockBoxSmmConstructor (
   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
-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 +306,8 @@ SmmLockBoxSmmDestructor (
     //
     // Unregister SmmReadyToLock notification.
     //
-    Status = gSmst->SmmRegisterProtocolNotify (
-                      &gEfiSmmReadyToLockProtocolGuid,
+    Status = gMmst->MmRegisterProtocolNotify (
+                      &gEfiMmReadyToLockProtocolGuid,
                       NULL,
                       &mSmmLockBoxRegistrationSmmReadyToLock
                       );
@@ -327,8 +317,8 @@ SmmLockBoxSmmDestructor (
     //
     // Unregister SmmEndOfDxe notification.
     //
-    Status = gSmst->SmmRegisterProtocolNotify (
-                      &gEfiSmmEndOfDxeProtocolGuid,
+    Status = gMmst->MmRegisterProtocolNotify (
+                      &gEfiMmEndOfDxeProtocolGuid,
                       NULL,
                       &mSmmLockBoxRegistrationSmmEndOfDxe
                       );
@@ -338,7 +328,7 @@ SmmLockBoxSmmDestructor (
     //
     // Unregister EndOfS3Resume notification.
     //
-    Status = gSmst->SmmRegisterProtocolNotify (
+    Status = gMmst->MmRegisterProtocolNotify (
                       &gEdkiiEndOfS3ResumeGuid,
                       NULL,
                       &mSmmLockBoxRegistrationEndOfS3Resume
@@ -453,7 +443,7 @@ SaveLockBox (
   //
   // Allocate SMRAM buffer
   //
-  Status = gSmst->SmmAllocatePages (
+  Status = gMmst->MmAllocatePages (
                     AllocateAnyPages,
                     EfiRuntimeServicesData,
                     EFI_SIZE_TO_PAGES (Length),
@@ -468,14 +458,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 +652,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 +669,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..449333e94bc6 100644
--- a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxLibPrivate.h
+++ b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxLibPrivate.h
@@ -43,5 +43,30 @@ 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
+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
+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 6d4e361afd51..9afd40eeed46 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
@@ -484,6 +485,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.30.0.windows.1


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

* [PATCH v3 07/18] MdeModulePkg: SmmReportStatusCodeLib: ReportStatusCodeLib in StandaloneMm
       [not found] <20210114223637.2737-1-kun.q@outlook.com>
  2021-01-14 22:36 ` [PATCH v3 06/18] MdeModulePkg: SmmLockBoxSmmLib: Support StandaloneMm for SmmLockBoxLib Kun Qin
@ 2021-01-14 22:36 ` Kun Qin
  2021-01-14 22:36 ` [PATCH v3 08/18] MdeModulePkg: StatusCodeHandler: StatusCodeHandler driver " Kun Qin
                   ` (11 subsequent siblings)
  13 siblings, 0 replies; 25+ messages in thread
From: Kun Qin @ 2021-01-14 22:36 UTC (permalink / raw)
  To: devel; +Cc: Jian J Wang, Hao A Wu, Dandan Bi, Liming Gao, Jiewen Yao

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>
Cc: Jiewen Yao <jiewen.yao@intel.com>

Signed-off-by: Kun Qin <kun.q@outlook.com>
Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
---

Notes:
    v3:
    - Added reviewed-by tag [Hao]
    
    v2:
    - Removed "EFIAPI" for internal functions.
    - Minor new file description update.

 MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.c                                               | 16 +++++----
 MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibStandaloneMm.c                                   | 38 ++++++++++++++++++++
 MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibTraditional.c                                    | 38 ++++++++++++++++++++
 MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.h                                               | 36 +++++++++++++++++++
 MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLib.inf                                          |  4 ++-
 MdeModulePkg/Library/SmmReportStatusCodeLib/{SmmReportStatusCodeLib.inf => StandaloneMmReportStatusCodeLib.inf} | 22 ++++++------
 MdeModulePkg/MdeModulePkg.dsc                                                                                   |  1 +
 7 files changed, 137 insertions(+), 18 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..a4c428dc88a9
--- /dev/null
+++ b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibStandaloneMm.c
@@ -0,0 +1,38 @@
+/** @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
+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..603e222f5508
--- /dev/null
+++ b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibTraditional.c
@@ -0,0 +1,38 @@
+/** @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
+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..2820e40dde19
--- /dev/null
+++ b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.h
@@ -0,0 +1,36 @@
+/** @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
+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 56%
copy from MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLib.inf
copy to MdeModulePkg/Library/SmmReportStatusCodeLib/StandaloneMmReportStatusCodeLib.inf
index 72496bfababd..866e09249a6a 100644
--- a/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLib.inf
+++ b/MdeModulePkg/Library/SmmReportStatusCodeLib/StandaloneMmReportStatusCodeLib.inf
@@ -1,9 +1,10 @@
 ## @file
-#  SMM report status code library.
+#  Standalone MM report status code library.
 #
-#  Retrieve status code and report status code in SMM phase.
+#  Retrieve status code and report status code in MM phase.
 #
 #  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
+#  Copyright (c) Microsoft Corporation.
 #
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -12,13 +13,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 +28,8 @@ [Defines]
 
 [Sources]
   ReportStatusCodeLib.c
+  ReportStatusCodeLib.h
+  ReportStatusCodeLibStandaloneMm.c
 
 [Packages]
   MdePkg/MdePkg.dec
@@ -36,7 +38,7 @@ [Packages]
 [LibraryClasses]
   PcdLib
   BaseMemoryLib
-  SmmServicesTableLib
+  MmServicesTableLib
   DebugLib
   MemoryAllocationLib
 
@@ -45,7 +47,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 9afd40eeed46..200fbcc18a18 100644
--- a/MdeModulePkg/MdeModulePkg.dsc
+++ b/MdeModulePkg/MdeModulePkg.dsc
@@ -474,6 +474,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.30.0.windows.1


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

* [PATCH v3 08/18] MdeModulePkg: StatusCodeHandler: StatusCodeHandler driver in StandaloneMm
       [not found] <20210114223637.2737-1-kun.q@outlook.com>
  2021-01-14 22:36 ` [PATCH v3 06/18] MdeModulePkg: SmmLockBoxSmmLib: Support StandaloneMm for SmmLockBoxLib Kun Qin
  2021-01-14 22:36 ` [PATCH v3 07/18] MdeModulePkg: SmmReportStatusCodeLib: ReportStatusCodeLib in StandaloneMm Kun Qin
@ 2021-01-14 22:36 ` Kun Qin
  2021-01-14 22:36 ` [PATCH v3 09/18] MdeModulePkg: FirmwarePerformanceDataTable: Added StandaloneMm support Kun Qin
                   ` (10 subsequent siblings)
  13 siblings, 0 replies; 25+ messages in thread
From: Kun Qin @ 2021-01-14 22:36 UTC (permalink / raw)
  To: devel; +Cc: Jian J Wang, Hao A Wu, Dandan Bi, Liming Gao, Jiewen Yao

This change added support of StandaloneMm for StatusCodeHandler. It
adds a new instance of StatusCodeHandler of MM_STANDALONE type, and
abstracts the driver entrypoint into separate files, replaced gSmst with
gMmst, and switched to MM version of RscHandlerProtocol.

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>
Cc: Jiewen Yao <jiewen.yao@intel.com>

Signed-off-by: Kun Qin <kun.q@outlook.com>
Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
---

Notes:
    v3:
    - Added reviewed-by tag [Hao]
    
    v2:
    - New patch to support StatusCodeHandler in standalone mm [Liming]

 MdeModulePkg/Universal/StatusCodeHandler/Smm/MemoryStatusCodeWorker.c                                        | 36 ++++++++++----------
 MdeModulePkg/Universal/StatusCodeHandler/Smm/SerialStatusCodeWorker.c                                        |  2 +-
 MdeModulePkg/Universal/StatusCodeHandler/Smm/{StatusCodeHandlerSmm.c => StatusCodeHandlerMm.c}               | 23 +++++--------
 MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerStandalone.c                                   | 31 +++++++++++++++++
 MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerTraditional.c                                  | 31 +++++++++++++++++
 MdeModulePkg/MdeModulePkg.dsc                                                                                |  1 +
 MdeModulePkg/Universal/StatusCodeHandler/Smm/{StatusCodeHandlerSmm.h => StatusCodeHandlerMm.h}               | 23 ++++++++++---
 MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSmm.inf                                        | 15 ++++----
 MdeModulePkg/Universal/StatusCodeHandler/Smm/{StatusCodeHandlerSmm.inf => StatusCodeHandlerStandaloneMm.inf} | 32 ++++++++---------
 9 files changed, 132 insertions(+), 62 deletions(-)

diff --git a/MdeModulePkg/Universal/StatusCodeHandler/Smm/MemoryStatusCodeWorker.c b/MdeModulePkg/Universal/StatusCodeHandler/Smm/MemoryStatusCodeWorker.c
index c9b43fd2468f..14bac8ec3c18 100644
--- a/MdeModulePkg/Universal/StatusCodeHandler/Smm/MemoryStatusCodeWorker.c
+++ b/MdeModulePkg/Universal/StatusCodeHandler/Smm/MemoryStatusCodeWorker.c
@@ -7,15 +7,15 @@
 
 **/
 
-#include "StatusCodeHandlerSmm.h"
+#include "StatusCodeHandlerMm.h"
 
-RUNTIME_MEMORY_STATUSCODE_HEADER  *mSmmMemoryStatusCodeTable;
+RUNTIME_MEMORY_STATUSCODE_HEADER  *mMmMemoryStatusCodeTable;
 
 /**
-  Initialize SMM memory status code table as initialization for memory status code worker
+  Initialize MM memory status code table as initialization for memory status code worker
 
-  @retval EFI_SUCCESS  SMM memory status code table successfully initialized.
-  @retval others       Errors from gSmst->SmmInstallConfigurationTable().
+  @retval EFI_SUCCESS  MM memory status code table successfully initialized.
+  @retval others       Errors from gMmst->MmInstallConfigurationTable().
 **/
 EFI_STATUS
 MemoryStatusCodeInitializeWorker (
@@ -25,17 +25,17 @@ MemoryStatusCodeInitializeWorker (
   EFI_STATUS                        Status;
 
   //
-  // Allocate SMM memory status code pool.
+  // Allocate MM memory status code pool.
   //
-  mSmmMemoryStatusCodeTable = (RUNTIME_MEMORY_STATUSCODE_HEADER *)AllocateZeroPool (sizeof (RUNTIME_MEMORY_STATUSCODE_HEADER) + PcdGet16 (PcdStatusCodeMemorySize) * 1024);
-  ASSERT (mSmmMemoryStatusCodeTable != NULL);
+  mMmMemoryStatusCodeTable = (RUNTIME_MEMORY_STATUSCODE_HEADER *)AllocateZeroPool (sizeof (RUNTIME_MEMORY_STATUSCODE_HEADER) + PcdGet16 (PcdStatusCodeMemorySize) * 1024);
+  ASSERT (mMmMemoryStatusCodeTable != NULL);
 
-  mSmmMemoryStatusCodeTable->MaxRecordsNumber = (PcdGet16 (PcdStatusCodeMemorySize) * 1024) / sizeof (MEMORY_STATUSCODE_RECORD);
-  Status = gSmst->SmmInstallConfigurationTable (
-                    gSmst,
+  mMmMemoryStatusCodeTable->MaxRecordsNumber = (PcdGet16 (PcdStatusCodeMemorySize) * 1024) / sizeof (MEMORY_STATUSCODE_RECORD);
+  Status = gMmst->MmInstallConfigurationTable (
+                    gMmst,
                     &gMemoryStatusCodeRecordGuid,
-                    &mSmmMemoryStatusCodeTable,
-                    sizeof (mSmmMemoryStatusCodeTable)
+                    &mMmMemoryStatusCodeTable,
+                    sizeof (mMmMemoryStatusCodeTable)
                     );
   return Status;
 }
@@ -74,8 +74,8 @@ MemoryStatusCodeReportWorker (
   //
   // Locate current record buffer.
   //
-  Record = (MEMORY_STATUSCODE_RECORD *) (mSmmMemoryStatusCodeTable + 1);
-  Record = &Record[mSmmMemoryStatusCodeTable->RecordIndex++];
+  Record = (MEMORY_STATUSCODE_RECORD *) (mMmMemoryStatusCodeTable + 1);
+  Record = &Record[mMmMemoryStatusCodeTable->RecordIndex++];
 
   //
   // Save status code.
@@ -92,12 +92,12 @@ MemoryStatusCodeReportWorker (
   // so the first record is pointed by record index.
   // If it is less then max number, index of the first record is zero.
   //
-  mSmmMemoryStatusCodeTable->NumberOfRecords++;
-  if (mSmmMemoryStatusCodeTable->RecordIndex == mSmmMemoryStatusCodeTable->MaxRecordsNumber) {
+  mMmMemoryStatusCodeTable->NumberOfRecords++;
+  if (mMmMemoryStatusCodeTable->RecordIndex == mMmMemoryStatusCodeTable->MaxRecordsNumber) {
     //
     // Wrap around record index.
     //
-    mSmmMemoryStatusCodeTable->RecordIndex = 0;
+    mMmMemoryStatusCodeTable->RecordIndex = 0;
   }
 
   return EFI_SUCCESS;
diff --git a/MdeModulePkg/Universal/StatusCodeHandler/Smm/SerialStatusCodeWorker.c b/MdeModulePkg/Universal/StatusCodeHandler/Smm/SerialStatusCodeWorker.c
index 3df0a6712611..bcb75bc7b170 100644
--- a/MdeModulePkg/Universal/StatusCodeHandler/Smm/SerialStatusCodeWorker.c
+++ b/MdeModulePkg/Universal/StatusCodeHandler/Smm/SerialStatusCodeWorker.c
@@ -6,7 +6,7 @@
 
 **/
 
-#include "StatusCodeHandlerSmm.h"
+#include "StatusCodeHandlerMm.h"
 
 /**
   Convert status code value and extended data to readable ASCII string, send string to serial I/O device.
diff --git a/MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSmm.c b/MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerMm.c
similarity index 69%
rename from MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSmm.c
rename to MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerMm.c
index 20271571ded4..4948d3d99ad6 100644
--- a/MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSmm.c
+++ b/MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerMm.c
@@ -1,15 +1,15 @@
 /** @file
   Status Code Handler Driver which produces general handlers and hook them
-  onto the SMM status code router.
+  onto the MM status code router.
 
   Copyright (c) 2009 - 2020, Intel Corporation. All rights reserved.<BR>
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
 
-#include "StatusCodeHandlerSmm.h"
+#include "StatusCodeHandlerMm.h"
 
-EFI_SMM_RSC_HANDLER_PROTOCOL  *mRscHandlerProtocol       = NULL;
+EFI_MM_RSC_HANDLER_PROTOCOL   *mRscHandlerProtocol       = NULL;
 
 
 /**
@@ -42,27 +42,22 @@ InitializationDispatcherWorker (
 }
 
 /**
-  Entry point of SMM Status Code Driver.
+  Entry point of Common MM Status Code Driver.
 
-  This function is the entry point of SMM Status Code Driver.
-
-  @param  ImageHandle       The firmware allocated handle for the EFI image.
-  @param  SystemTable       A pointer to the EFI System Table.
+  This function is the entry point of MM Status Code Driver.
 
   @retval EFI_SUCCESS       The entry point is executed successfully.
 
 **/
 EFI_STATUS
-EFIAPI
-StatusCodeHandlerSmmEntry (
-  IN EFI_HANDLE         ImageHandle,
-  IN EFI_SYSTEM_TABLE   *SystemTable
+StatusCodeHandlerCommonEntry (
+  VOID
   )
 {
   EFI_STATUS                Status;
 
-  Status = gSmst->SmmLocateProtocol (
-                    &gEfiSmmRscHandlerProtocolGuid,
+  Status = gMmst->MmLocateProtocol (
+                    &gEfiMmRscHandlerProtocolGuid,
                     NULL,
                     (VOID **) &mRscHandlerProtocol
                     );
diff --git a/MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerStandalone.c b/MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerStandalone.c
new file mode 100644
index 000000000000..11a61705d612
--- /dev/null
+++ b/MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerStandalone.c
@@ -0,0 +1,31 @@
+/** @file
+  Abstraction layer that contains Standalone MM specific implementation for
+  Status Code Handler Driver.
+
+  Copyright (c) Microsoft Corporation.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "StatusCodeHandlerMm.h"
+
+/**
+  Entry point of Standalone MM Status Code Driver.
+
+  This function is the entry point of Standalone MM Status Code Driver.
+
+  @param  ImageHandle       The firmware allocated handle for the EFI image.
+  @param  SystemTable       A pointer to the EFI MM System Table.
+
+  @retval EFI_SUCCESS       The entry point is executed successfully.
+
+**/
+EFI_STATUS
+EFIAPI
+StatusCodeHandlerStandaloneMmEntry (
+  IN EFI_HANDLE           ImageHandle,
+  IN EFI_MM_SYSTEM_TABLE  *SystemTable
+  )
+{
+  return StatusCodeHandlerCommonEntry ();
+}
diff --git a/MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerTraditional.c b/MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerTraditional.c
new file mode 100644
index 000000000000..1105f184b08e
--- /dev/null
+++ b/MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerTraditional.c
@@ -0,0 +1,31 @@
+/** @file
+  Abstraction layer that contains Standalone MM specific implementation for
+  Status Code Handler Driver.
+
+  Copyright (c) Microsoft Corporation.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "StatusCodeHandlerMm.h"
+
+/**
+  Entry point of Traditional MM Status Code Driver.
+
+  This function is the entry point of Traditional MM Status Code Driver.
+
+  @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
+StatusCodeHandlerTraditionalMmEntry (
+  IN EFI_HANDLE         ImageHandle,
+  IN EFI_SYSTEM_TABLE   *SystemTable
+  )
+{
+  return StatusCodeHandlerCommonEntry ();
+}
diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc
index 200fbcc18a18..098909490095 100644
--- a/MdeModulePkg/MdeModulePkg.dsc
+++ b/MdeModulePkg/MdeModulePkg.dsc
@@ -476,6 +476,7 @@ [Components.IA32, Components.X64]
   MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLib.inf
   MdeModulePkg/Library/SmmReportStatusCodeLib/StandaloneMmReportStatusCodeLib.inf
   MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSmm.inf
+  MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerStandaloneMm.inf
   MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterSmm.inf
   MdeModulePkg/Universal/LockBox/SmmLockBox/SmmLockBox.inf
   MdeModulePkg/Library/SmmMemoryAllocationProfileLib/SmmMemoryAllocationProfileLib.inf
diff --git a/MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSmm.h b/MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerMm.h
similarity index 87%
rename from MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSmm.h
rename to MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerMm.h
index 6b5d53a4fee3..7871ee404046 100644
--- a/MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSmm.h
+++ b/MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerMm.h
@@ -7,10 +7,10 @@
 
 **/
 
-#ifndef __STATUS_CODE_HANDLER_SMM_H__
-#define __STATUS_CODE_HANDLER_SMM_H__
+#ifndef __STATUS_CODE_HANDLER_MM_H__
+#define __STATUS_CODE_HANDLER_MM_H__
 
-#include <Protocol/SmmReportStatusCodeHandler.h>
+#include <Protocol/MmReportStatusCodeHandler.h>
 
 #include <Guid/MemoryStatusCodeRecord.h>
 #include <Guid/StatusCodeDataTypeId.h>
@@ -22,7 +22,7 @@
 #include <Library/PrintLib.h>
 #include <Library/PcdLib.h>
 #include <Library/UefiDriverEntryPoint.h>
-#include <Library/SmmServicesTableLib.h>
+#include <Library/MmServicesTableLib.h>
 #include <Library/SerialPortLib.h>
 #include <Library/MemoryAllocationLib.h>
 #include <Library/BaseMemoryLib.h>
@@ -32,7 +32,7 @@
 //
 #define MAX_DEBUG_MESSAGE_LENGTH 0x100
 
-extern RUNTIME_MEMORY_STATUSCODE_HEADER  *mSmmMemoryStatusCodeTable;
+extern RUNTIME_MEMORY_STATUSCODE_HEADER  *mMmMemoryStatusCodeTable;
 
 /**
   Locates Serial I/O Protocol as initialization for serial status code worker.
@@ -114,4 +114,17 @@ MemoryStatusCodeReportWorker (
   IN EFI_STATUS_CODE_DATA               *Data OPTIONAL
   );
 
+/**
+  Entry point of Common MM Status Code Driver.
+
+  This function is the entry point of MM Status Code Driver.
+
+  @retval EFI_SUCCESS       The entry point is executed successfully.
+
+**/
+EFI_STATUS
+StatusCodeHandlerCommonEntry (
+  VOID
+  );
+
 #endif
diff --git a/MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSmm.inf b/MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSmm.inf
index 4e24d87e55d1..90abe662d291 100644
--- a/MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSmm.inf
+++ b/MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSmm.inf
@@ -1,5 +1,5 @@
 ## @file
-#  Status Code Handler Driver which produces general handlers and hook them onto the SMM status code router.
+#  Status Code Handler Driver which produces general handlers and hook them onto the MM status code router.
 #
 #  Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
 #  (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
@@ -17,7 +17,7 @@ [Defines]
   MODULE_TYPE                    = DXE_SMM_DRIVER
   PI_SPECIFICATION_VERSION       = 0x0001000A
   VERSION_STRING                 = 1.0
-  ENTRY_POINT                    = StatusCodeHandlerSmmEntry
+  ENTRY_POINT                    = StatusCodeHandlerTraditionalMmEntry
 
 #
 # The following information is for reference only and not required by the build tools.
@@ -26,8 +26,9 @@ [Defines]
 #
 
 [Sources]
-  StatusCodeHandlerSmm.c
-  StatusCodeHandlerSmm.h
+  StatusCodeHandlerMm.c
+  StatusCodeHandlerMm.h
+  StatusCodeHandlerTraditional.c
   SerialStatusCodeWorker.c
   MemoryStatusCodeWorker.c
 
@@ -37,7 +38,7 @@ [Packages]
 
 [LibraryClasses]
   SerialPortLib
-  SmmServicesTableLib
+  MmServicesTableLib
   UefiDriverEntryPoint
   PcdLib
   PrintLib
@@ -51,7 +52,7 @@ [Guids]
   gMemoryStatusCodeRecordGuid                   ## SOMETIMES_PRODUCES   ## UNDEFINED # SmmSystemTable
 
 [Protocols]
-  gEfiSmmRscHandlerProtocolGuid                 ## CONSUMES
+  gEfiMmRscHandlerProtocolGuid                 ## CONSUMES
 
 [Pcd]
   gEfiMdeModulePkgTokenSpaceGuid.PcdStatusCodeUseSerial ## CONSUMES
@@ -59,7 +60,7 @@ [Pcd]
   gEfiMdeModulePkgTokenSpaceGuid.PcdStatusCodeMemorySize |128| gEfiMdeModulePkgTokenSpaceGuid.PcdStatusCodeUseMemory   ## SOMETIMES_CONSUMES
 
 [Depex]
-  gEfiSmmRscHandlerProtocolGuid
+  gEfiMmRscHandlerProtocolGuid
 
 [UserExtensions.TianoCore."ExtraFiles"]
   StatusCodeHandlerSmmExtra.uni
diff --git a/MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSmm.inf b/MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerStandaloneMm.inf
similarity index 62%
copy from MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSmm.inf
copy to MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerStandaloneMm.inf
index 4e24d87e55d1..d7c863bf064c 100644
--- a/MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSmm.inf
+++ b/MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerStandaloneMm.inf
@@ -1,8 +1,9 @@
 ## @file
-#  Status Code Handler Driver which produces general handlers and hook them onto the SMM status code router.
+#  Status Code Handler Driver which produces general handlers and hook them onto the MM status code router.
 #
 #  Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
 #  (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
+#  Copyright (c) Microsoft Corporation.
 #
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -11,13 +12,12 @@
 
 [Defines]
   INF_VERSION                    = 0x00010005
-  BASE_NAME                      = StatusCodeHandlerSmm
-  MODULE_UNI_FILE                = StatusCodeHandlerSmm.uni
-  FILE_GUID                      = 79CD78D8-6EDC-4978-BD02-3299C387AB17
-  MODULE_TYPE                    = DXE_SMM_DRIVER
-  PI_SPECIFICATION_VERSION       = 0x0001000A
+  BASE_NAME                      = StatusCodeHandlerStandaloneMm
+  FILE_GUID                      = EBE7802F-5E11-4D4E-B463-22D2425D156B
+  MODULE_TYPE                    = MM_STANDALONE
+  PI_SPECIFICATION_VERSION       = 0x00010032
   VERSION_STRING                 = 1.0
-  ENTRY_POINT                    = StatusCodeHandlerSmmEntry
+  ENTRY_POINT                    = StatusCodeHandlerStandaloneMmEntry
 
 #
 # The following information is for reference only and not required by the build tools.
@@ -26,8 +26,9 @@ [Defines]
 #
 
 [Sources]
-  StatusCodeHandlerSmm.c
-  StatusCodeHandlerSmm.h
+  StatusCodeHandlerMm.c
+  StatusCodeHandlerMm.h
+  StatusCodeHandlerStandalone.c
   SerialStatusCodeWorker.c
   MemoryStatusCodeWorker.c
 
@@ -37,8 +38,8 @@ [Packages]
 
 [LibraryClasses]
   SerialPortLib
-  SmmServicesTableLib
-  UefiDriverEntryPoint
+  MmServicesTableLib
+  StandaloneMmDriverEntryPoint
   PcdLib
   PrintLib
   ReportStatusCodeLib
@@ -48,10 +49,10 @@ [LibraryClasses]
 
 [Guids]
   gEfiStatusCodeDataTypeStringGuid              ## SOMETIMES_CONSUMES   ## UNDEFINED
-  gMemoryStatusCodeRecordGuid                   ## SOMETIMES_PRODUCES   ## UNDEFINED # SmmSystemTable
+  gMemoryStatusCodeRecordGuid                   ## SOMETIMES_PRODUCES   ## UNDEFINED # MmSystemTable
 
 [Protocols]
-  gEfiSmmRscHandlerProtocolGuid                 ## CONSUMES
+  gEfiMmRscHandlerProtocolGuid                  ## CONSUMES
 
 [Pcd]
   gEfiMdeModulePkgTokenSpaceGuid.PcdStatusCodeUseSerial ## CONSUMES
@@ -59,7 +60,4 @@ [Pcd]
   gEfiMdeModulePkgTokenSpaceGuid.PcdStatusCodeMemorySize |128| gEfiMdeModulePkgTokenSpaceGuid.PcdStatusCodeUseMemory   ## SOMETIMES_CONSUMES
 
 [Depex]
-  gEfiSmmRscHandlerProtocolGuid
-
-[UserExtensions.TianoCore."ExtraFiles"]
-  StatusCodeHandlerSmmExtra.uni
+  gEfiMmRscHandlerProtocolGuid
-- 
2.30.0.windows.1


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

* [PATCH v3 09/18] MdeModulePkg: FirmwarePerformanceDataTable: Added StandaloneMm support
       [not found] <20210114223637.2737-1-kun.q@outlook.com>
                   ` (2 preceding siblings ...)
  2021-01-14 22:36 ` [PATCH v3 08/18] MdeModulePkg: StatusCodeHandler: StatusCodeHandler driver " Kun Qin
@ 2021-01-14 22:36 ` Kun Qin
  2021-01-14 22:36 ` [PATCH v3 10/18] MdeModulePkg: ReportStatusCodeRouter: Support StandaloneMm RSC Router Kun Qin
                   ` (9 subsequent siblings)
  13 siblings, 0 replies; 25+ messages in thread
From: Kun Qin @ 2021-01-14 22:36 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>
Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
---

Notes:
    v3:
    - Added reviewed-by tag [Hao]
    
    v2:
    - Removed "EFIAPI" for internally abstracted functions [Hao]
    - Support driver for both IA32 and X64 in dsc file [Hao]

 MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/{FirmwarePerformanceSmm.c => FirmwarePerformanceCommon.c}           | 76 +++++++++-----------
 MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceStandaloneMm.c                                   | 61 ++++++++++++++++
 MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceTraditional.c                                    | 61 ++++++++++++++++
 MdeModulePkg/MdeModulePkg.dsc                                                                                                   |  2 +
 MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceCommon.h                                         | 50 +++++++++++++
 MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceSmm.inf                                          | 11 +--
 MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/{FirmwarePerformanceSmm.inf => FirmwarePerformanceStandaloneMm.inf} | 31 ++++----
 7 files changed, 230 insertions(+), 62 deletions(-)

diff --git a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceSmm.c b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceCommon.c
similarity index 75%
rename from MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceSmm.c
rename to MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceCommon.c
index d6c6e7693e4d..ecadef8711ed 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,20 +266,15 @@ FpdtSmiHandler (
 }
 
 /**
-  The module Entry Point of the Firmware Performance Data Table SMM driver.
-
-  @param[in]  ImageHandle    The firmware allocated handle for the EFI image.
-  @param[in]  SystemTable    A pointer to the EFI System Table.
+  The module Entry Point of the Firmware Performance Data Table MM driver.
 
   @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
+FirmwarePerformanceCommonEntryPoint (
+  VOID
   )
 {
   EFI_STATUS                Status;
@@ -289,13 +283,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 +298,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..d7da61c98c66
--- /dev/null
+++ b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceStandaloneMm.c
@@ -0,0 +1,61 @@
+/** @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
+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 MM 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..43c050d6b516
--- /dev/null
+++ b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceTraditional.c
@@ -0,0 +1,61 @@
+/** @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
+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 098909490095..34ca571ca662 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
@@ -495,6 +496,7 @@ [Components.IA32, Components.X64]
   MdeModulePkg/Universal/Acpi/S3SaveStateDxe/S3SaveStateDxe.inf
   MdeModulePkg/Universal/Acpi/SmmS3SaveState/SmmS3SaveState.inf
   MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceSmm.inf
+  MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceStandaloneMm.inf
   MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.inf
   MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmDxe.inf
   MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf
diff --git a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceCommon.h b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceCommon.h
new file mode 100644
index 000000000000..0fbdac02de4c
--- /dev/null
+++ b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceCommon.h
@@ -0,0 +1,50 @@
+/** @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
+IsBufferOutsideMmValid (
+  IN EFI_PHYSICAL_ADDRESS  Buffer,
+  IN UINT64                Length
+  );
+
+/**
+  The module Entry Point of the Firmware Performance Data Table MM driver.
+
+  @retval EFI_SUCCESS    The entry point is executed successfully.
+  @retval Other          Some error occurs when executing this entry point.
+
+**/
+EFI_STATUS
+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.30.0.windows.1


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

* [PATCH v3 10/18] MdeModulePkg: ReportStatusCodeRouter: Support StandaloneMm RSC Router
       [not found] <20210114223637.2737-1-kun.q@outlook.com>
                   ` (3 preceding siblings ...)
  2021-01-14 22:36 ` [PATCH v3 09/18] MdeModulePkg: FirmwarePerformanceDataTable: Added StandaloneMm support Kun Qin
@ 2021-01-14 22:36 ` Kun Qin
  2021-01-14 22:36 ` [PATCH v3 11/18] MdePkg: UefiDevicePathLib: Support UefiDevicePathLib under StandaloneMm Kun Qin
                   ` (8 subsequent siblings)
  13 siblings, 0 replies; 25+ messages in thread
From: Kun Qin @ 2021-01-14 22:36 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>
Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
---

Notes:
    v3:
    - Added reviewed-by tag [Hao]
    - Updated function descriptions to match function interface [Hao]
    
    v2:
    - Removed "EFIAPI" for internally abstracted functions [Hao]
    - Updated function descriptions [Hao]
    - Updated ReportDispatcher to make *.h and *.c consistent [Hao]

 MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/{ReportStatusCodeRouterSmm.c => ReportStatusCodeRouterCommon.c} | 59 +++++++++-----------
 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} | 46 +++++++++------
 MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterSmm.inf                                   | 13 +++--
 MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterStandaloneMm.inf                          | 49 ++++++++++++++++
 7 files changed, 179 insertions(+), 55 deletions(-)

diff --git a/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterSmm.c b/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterCommon.c
similarity index 74%
rename from MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterSmm.c
rename to MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterCommon.c
index c3ab5cd05045..c4843a745d69 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.
@@ -121,8 +121,8 @@ Unregister (
 /**
   Provides an interface that a software module can call to report a status code.
 
-  @param  This             EFI_SMM_STATUS_CODE_PROTOCOL instance.
-  @param  Type             Indicates the type of status code being reported.
+  @param  This             EFI_MM_STATUS_CODE_PROTOCOL instance.
+  @param  CodeType         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
                            classify the entity as well as an operation.
@@ -140,16 +140,16 @@ 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 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,13 +160,13 @@ 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.
     //
     Link = GetNextNode (&mCallbackListHead, Link);
     CallbackEntry->RscHandlerCallback (
-                     Type,
+                     CodeType,
                      Value,
                      Instance,
                      (EFI_GUID*)CallerId,
@@ -186,20 +186,15 @@ ReportDispatcher (
 /**
   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.
+  This function is the common entry point of MM Status Code Router.
+  It produces MM Report Status Code Handler and Status Code protocol.
 
   @retval EFI_SUCCESS       The entry point is executed successfully.
 
 **/
 EFI_STATUS
-EFIAPI
-GenericStatusCodeSmmEntry (
-  IN EFI_HANDLE         ImageHandle,
-  IN EFI_SYSTEM_TABLE   *SystemTable
+GenericStatusCodeCommonEntry (
+  VOID
   )
 {
   EFI_STATUS     Status;
@@ -210,9 +205,9 @@ GenericStatusCodeSmmEntry (
   //
   // Install SmmRscHandler Protocol
   //
-  Status = gSmst->SmmInstallProtocolInterface (
+  Status = gMmst->MmInstallProtocolInterface (
                     &Handle,
-                    &gEfiSmmRscHandlerProtocolGuid,
+                    &gEfiMmRscHandlerProtocolGuid,
                     EFI_NATIVE_INTERFACE,
                     &mSmmRscHandlerProtocol
                     );
@@ -221,9 +216,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..bd1519fa1506
--- /dev/null
+++ b/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterStandaloneMm.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 MM Status Code Router .
+  It produces MM 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 34ca571ca662..f95c7cd69ee1 100644
--- a/MdeModulePkg/MdeModulePkg.dsc
+++ b/MdeModulePkg/MdeModulePkg.dsc
@@ -479,6 +479,7 @@ [Components.IA32, Components.X64]
   MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSmm.inf
   MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerStandaloneMm.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 72%
rename from MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterSmm.h
rename to MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterCommon.h
index f8c48c62e790..4f4d055222d4 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,14 +65,14 @@ 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  Type             Indicates the type of status code being reported.
+  @param  This             EFI_MM_STATUS_CODE_PROTOCOL instance.
+  @param  CodeType         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
                            classify the entity as well as an operation.
@@ -92,12 +90,26 @@ 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 CONST EFI_GUID                      *CallerId,
   IN EFI_STATUS_CODE_DATA                *Data      OPTIONAL
   );
 
+/**
+  Entry point of Generic Status Code Driver.
+
+  This function is the common entry point of MM Status Code Router.
+  It produces MM Report Status Code Handler and Status Code protocol.
+
+  @retval EFI_SUCCESS       The entry point is executed successfully.
+
+**/
+EFI_STATUS
+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..7aa0127e0bec
--- /dev/null
+++ b/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterStandaloneMm.inf
@@ -0,0 +1,49 @@
+## @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
+#
+#
+##
+
+[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.30.0.windows.1


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

* [PATCH v3 11/18] MdePkg: UefiDevicePathLib: Support UefiDevicePathLib under StandaloneMm
       [not found] <20210114223637.2737-1-kun.q@outlook.com>
                   ` (4 preceding siblings ...)
  2021-01-14 22:36 ` [PATCH v3 10/18] MdeModulePkg: ReportStatusCodeRouter: Support StandaloneMm RSC Router Kun Qin
@ 2021-01-14 22:36 ` Kun Qin
  2021-01-14 22:36 ` [PATCH v3 12/18] PcAtChipsetPkg: AcpiTimerLib: Added StandaloneMm instance of AcpiTimerLib Kun Qin
                   ` (7 subsequent siblings)
  13 siblings, 0 replies; 25+ messages in thread
From: Kun Qin @ 2021-01-14 22:36 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>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
---

Notes:
    v3:
    - Added reviewed-by tag [Liming]
    
    v2:
    - No review, no change.

 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.30.0.windows.1


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

* [PATCH v3 12/18] PcAtChipsetPkg: AcpiTimerLib: Added StandaloneMm instance of AcpiTimerLib
       [not found] <20210114223637.2737-1-kun.q@outlook.com>
                   ` (5 preceding siblings ...)
  2021-01-14 22:36 ` [PATCH v3 11/18] MdePkg: UefiDevicePathLib: Support UefiDevicePathLib under StandaloneMm Kun Qin
@ 2021-01-14 22:36 ` Kun Qin
  2021-01-14 22:36 ` [PATCH v3 13/18] SecurityPkg: Tcg2PhysicalPresenceLib: Introduce StandaloneMm instance Kun Qin
                   ` (6 subsequent siblings)
  13 siblings, 0 replies; 25+ messages in thread
From: Kun Qin @ 2021-01-14 22:36 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>
---

Notes:
    v3:
    - Renamed "CommonAcpiTimerLib" to "DxeStandaloneMmAcpiTimerLib" to
    avoid confusion [Ray]
    - Renamed BASE NAME (and file name) to StandaloneMmAcpiTimerLib [Ray]
    
    v2:
    - Removed "EFIAPI" for internal functions.

 PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c                                     | 81 +-------------------
 PcAtChipsetPkg/Library/AcpiTimerLib/{DxeAcpiTimerLib.c => DxeStandaloneMmAcpiTimerLib.c}  |  9 +--
 PcAtChipsetPkg/Library/AcpiTimerLib/StandaloneMmAcpiTimerLib.c                            | 31 ++++++++
 PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf                                   |  2 +
 PcAtChipsetPkg/Library/AcpiTimerLib/DxeStandaloneMmAcpiTimerLib.h                         | 24 ++++++
 PcAtChipsetPkg/Library/AcpiTimerLib/{DxeAcpiTimerLib.inf => StandaloneMmAcpiTimerLib.inf} | 19 +++--
 PcAtChipsetPkg/PcAtChipsetPkg.dsc                                                         |  1 +
 7 files changed, 74 insertions(+), 93 deletions(-)

diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c
index 3ad831b15e8a..9ac2a446e365 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 "DxeStandaloneMmAcpiTimerLib.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/DxeAcpiTimerLib.c b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeStandaloneMmAcpiTimerLib.c
similarity index 86%
copy from PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c
copy to PcAtChipsetPkg/Library/AcpiTimerLib/DxeStandaloneMmAcpiTimerLib.c
index 3ad831b15e8a..0e401194d01d 100644
--- a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c
+++ b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeStandaloneMmAcpiTimerLib.c
@@ -72,17 +72,12 @@ 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/StandaloneMmAcpiTimerLib.c b/PcAtChipsetPkg/Library/AcpiTimerLib/StandaloneMmAcpiTimerLib.c
new file mode 100644
index 000000000000..97aca5606905
--- /dev/null
+++ b/PcAtChipsetPkg/Library/AcpiTimerLib/StandaloneMmAcpiTimerLib.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 "DxeStandaloneMmAcpiTimerLib.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/DxeAcpiTimerLib.inf b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf
index d86356f4ff17..93972e53c9c5 100644
--- a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf
+++ b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf
@@ -25,6 +25,8 @@ [Defines]
 [Sources]
   AcpiTimerLib.c
   DxeAcpiTimerLib.c
+  DxeStandaloneMmAcpiTimerLib.c
+  DxeStandaloneMmAcpiTimerLib.h
 
 [Packages]
   MdePkg/MdePkg.dec
diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeStandaloneMmAcpiTimerLib.h b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeStandaloneMmAcpiTimerLib.h
new file mode 100644
index 000000000000..6015d684e5bd
--- /dev/null
+++ b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeStandaloneMmAcpiTimerLib.h
@@ -0,0 +1,24 @@
+/** @file
+  Header file internal to ACPI TimerLib.
+
+Copyright (c) Microsoft Corporation.
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+
+#ifndef _DXE_STANDALONE_MM_ACPI_TIMER_LIB_H_
+#define _DXE_STANDALONE_MM_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
+CommonAcpiTimerLibConstructor (
+  VOID
+  );
+
+#endif
diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf b/PcAtChipsetPkg/Library/AcpiTimerLib/StandaloneMmAcpiTimerLib.inf
similarity index 70%
copy from PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf
copy to PcAtChipsetPkg/Library/AcpiTimerLib/StandaloneMmAcpiTimerLib.inf
index d86356f4ff17..c5efdd145d19 100644
--- a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf
+++ b/PcAtChipsetPkg/Library/AcpiTimerLib/StandaloneMmAcpiTimerLib.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                      = StandaloneMmAcpiTimerLib
+  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
+  StandaloneMmAcpiTimerLib.c
+  DxeStandaloneMmAcpiTimerLib.c
+  DxeStandaloneMmAcpiTimerLib.h
 
 [Packages]
   MdePkg/MdePkg.dec
diff --git a/PcAtChipsetPkg/PcAtChipsetPkg.dsc b/PcAtChipsetPkg/PcAtChipsetPkg.dsc
index b61b7d1f528e..3d1fb816f54f 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/StandaloneMmAcpiTimerLib.inf
   PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf
 
 [BuildOptions]
-- 
2.30.0.windows.1


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

* [PATCH v3 13/18] SecurityPkg: Tcg2PhysicalPresenceLib: Introduce StandaloneMm instance
       [not found] <20210114223637.2737-1-kun.q@outlook.com>
                   ` (6 preceding siblings ...)
  2021-01-14 22:36 ` [PATCH v3 12/18] PcAtChipsetPkg: AcpiTimerLib: Added StandaloneMm instance of AcpiTimerLib Kun Qin
@ 2021-01-14 22:36 ` Kun Qin
  2021-01-14 22:36 ` [PATCH v3 14/18] SecurityPkg: Tcg2PpVendorLibNull: Added support for MM_STANDALONE type Kun Qin
                   ` (5 subsequent siblings)
  13 siblings, 0 replies; 25+ messages in thread
From: Kun Qin @ 2021-01-14 22:36 UTC (permalink / raw)
  To: devel; +Cc: Jiewen Yao, Jian J Wang, Qi Zhang, Rahul Kumar, Jiewen Yao

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>
Reviewed-by: Jiewen Yao <Jiewen.yao@intel.com>
---

Notes:
    v3:
    - Previously reviewed. No change.
    
    v2:
    - Added Reviewed-by tag [Jiewen]
    - Removed "EFIAPI" for internal functions
    - Updated internal function description

 SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/{SmmTcg2PhysicalPresenceLib.c => MmTcg2PhysicalPresenceLibCommon.c}         |  33 +-
 SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenceLib.c                                                | 368 +-------------------
 SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/StandaloneMmTcg2PhysicalPresenceLib.c                                       |  42 +++
 SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/MmTcg2PhysicalPresenceLibCommon.h                                           |  34 ++
 SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenceLib.inf                                              |   6 +-
 SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/{SmmTcg2PhysicalPresenceLib.inf => StandaloneMmTcg2PhysicalPresenceLib.inf} |  22 +-
 SecurityPkg/SecurityPkg.dsc                                                                                                |   2 +
 7 files changed, 113 insertions(+), 394 deletions(-)

diff --git a/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenceLib.c b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/MmTcg2PhysicalPresenceLibCommon.c
similarity index 90%
copy from SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenceLib.c
copy to SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/MmTcg2PhysicalPresenceLibCommon.c
index 8afaa0a7857d..3788537db318 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;
   }
 
@@ -372,17 +372,12 @@ Tcg2PhysicalPresenceLibGetUserConfirmationStatusFunction (
 
   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
-Tcg2PhysicalPresenceLibConstructor (
-  IN EFI_HANDLE        ImageHandle,
-  IN EFI_SYSTEM_TABLE  *SystemTable
+Tcg2PhysicalPresenceLibCommonConstructor (
+  VOID
   )
 {
   EFI_STATUS  Status;
@@ -394,7 +389,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..a0182739e9c8
--- /dev/null
+++ b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/MmTcg2PhysicalPresenceLibCommon.h
@@ -0,0 +1,34 @@
+/** @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
+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.30.0.windows.1


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

* [PATCH v3 14/18] SecurityPkg: Tcg2PpVendorLibNull: Added support for MM_STANDALONE type
       [not found] <20210114223637.2737-1-kun.q@outlook.com>
                   ` (7 preceding siblings ...)
  2021-01-14 22:36 ` [PATCH v3 13/18] SecurityPkg: Tcg2PhysicalPresenceLib: Introduce StandaloneMm instance Kun Qin
@ 2021-01-14 22:36 ` Kun Qin
  2021-01-14 22:36 ` [PATCH v3 15/18] SecurityPkg: Tpm2DeviceLibDTpm: Introduce StandaloneMm instance Kun Qin
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 25+ messages in thread
From: Kun Qin @ 2021-01-14 22:36 UTC (permalink / raw)
  To: devel; +Cc: Jiewen Yao, Jian J Wang, Qi Zhang, Rahul Kumar, Jiewen Yao

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>
Reviewed-by: Jiewen Yao <Jiewen.yao@intel.com>
---

Notes:
    v3:
    - Previously reviewed. No change.
    
    v2:
    - Added Reviewed-by tag [Jiewen]

 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.30.0.windows.1


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

* [PATCH v3 15/18] SecurityPkg: Tpm2DeviceLibDTpm: Introduce StandaloneMm instance
       [not found] <20210114223637.2737-1-kun.q@outlook.com>
                   ` (8 preceding siblings ...)
  2021-01-14 22:36 ` [PATCH v3 14/18] SecurityPkg: Tcg2PpVendorLibNull: Added support for MM_STANDALONE type Kun Qin
@ 2021-01-14 22:36 ` Kun Qin
  2021-01-14 22:36 ` [PATCH v3 16/18] UefiCpuPkg: CpuIo2Smm: Move CpuIo2Smm driver to consume gMmst Kun Qin
                   ` (3 subsequent siblings)
  13 siblings, 0 replies; 25+ messages in thread
From: Kun Qin @ 2021-01-14 22:36 UTC (permalink / raw)
  To: devel; +Cc: Jiewen Yao, Jian J Wang, Qi Zhang, Rahul Kumar, Jiewen Yao

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>
Reviewed-by: Jiewen Yao <Jiewen.yao@intel.com>
---

Notes:
    v3:
    - Previously reviewed. No change.
    
    v2:
    - Added Reviewed-by tag [Jiewen]
    - Removed "EFIAPI" for internal functions

 SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.c                                          | 42 +-----------
 SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmBase.c                                      | 68 ++++++++++++++++++++
 SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmStandaloneMm.c                              | 66 +++++++++++++++++++
 SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.c                                        | 40 +-----------
 SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Ptp.c                                                    | 15 +++--
 SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.h                                          | 67 +++++++++++++++++++
 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, 228 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..bc35e257e105
--- /dev/null
+++ b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmBase.c
@@ -0,0 +1,68 @@
+/** @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
+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..eac866d2a77a
--- /dev/null
+++ b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmStandaloneMm.c
@@ -0,0 +1,66 @@
+/** @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
+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..9fff98952251
--- /dev/null
+++ b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.h
@@ -0,0 +1,67 @@
+/** @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
+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.30.0.windows.1


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

* [PATCH v3 16/18] UefiCpuPkg: CpuIo2Smm: Move CpuIo2Smm driver to consume gMmst
       [not found] <20210114223637.2737-1-kun.q@outlook.com>
                   ` (9 preceding siblings ...)
  2021-01-14 22:36 ` [PATCH v3 15/18] SecurityPkg: Tpm2DeviceLibDTpm: Introduce StandaloneMm instance Kun Qin
@ 2021-01-14 22:36 ` Kun Qin
  2021-01-15  7:12   ` Laszlo Ersek
  2021-01-14 22:36 ` [PATCH v3 17/18] UefiCpuPkg: CpuIo2Smm: Support of CpuIo driver under StandaloneMm Kun Qin
                   ` (2 subsequent siblings)
  13 siblings, 1 reply; 25+ messages in thread
From: Kun Qin @ 2021-01-14 22:36 UTC (permalink / raw)
  To: devel; +Cc: Eric Dong, Ray Ni, Laszlo Ersek, Rahul Kumar

This change replaced gSmst with gMmst to support broader compatibility
under MM environment for CpuIo2Smm driver.

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>
---

Notes:
    v3:
    - Break gMmst replacement into separate PR [Laszlo]
    
    v2:
    - Removed "EFIAPI" for internal functions.

 UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c   | 6 +++---
 UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.h   | 2 +-
 UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf | 2 +-
 UefiCpuPkg/UefiCpuPkg.dsc          | 1 +
 4 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c
index b840d3e10cae..c0a2baecee03 100644
--- a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c
+++ b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c
@@ -390,12 +390,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
+  // Install the SMM CPU I/O Protocol into the MM protocol database
   //
-  Status = gSmst->SmmInstallProtocolInterface (
+  Status = gMmst->MmInstallProtocolInterface (
                     &mHandle,
                     &gEfiSmmCpuIo2ProtocolGuid,
                     EFI_NATIVE_INTERFACE,
diff --git a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.h b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.h
index 4c133b58c9f4..c80261945f71 100644
--- a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.h
+++ b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.h
@@ -16,7 +16,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 #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
diff --git a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf
index bc78fa4e42d2..b743a5e0e316 100644
--- a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf
+++ b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf
@@ -34,7 +34,7 @@ [LibraryClasses]
   BaseLib
   DebugLib
   IoLib
-  SmmServicesTableLib
+  MmServicesTableLib
   BaseMemoryLib
 
 [Protocols]
diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc
index b2b6d78a71b0..9b56bcaabebe 100644
--- a/UefiCpuPkg/UefiCpuPkg.dsc
+++ b/UefiCpuPkg/UefiCpuPkg.dsc
@@ -89,6 +89,7 @@ [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
-- 
2.30.0.windows.1


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

* [PATCH v3 17/18] UefiCpuPkg: CpuIo2Smm: Support of CpuIo driver under StandaloneMm
       [not found] <20210114223637.2737-1-kun.q@outlook.com>
                   ` (10 preceding siblings ...)
  2021-01-14 22:36 ` [PATCH v3 16/18] UefiCpuPkg: CpuIo2Smm: Move CpuIo2Smm driver to consume gMmst Kun Qin
@ 2021-01-14 22:36 ` Kun Qin
  2021-01-15  7:16   ` Laszlo Ersek
  2021-01-22  4:17   ` [edk2-devel] " Ni, Ray
  2021-01-14 22:36 ` [PATCH v3 18/18] UefiCpuPkg: SmmCpuExceptionHandlerLib: Added StandaloneMm module support Kun Qin
       [not found] ` <165A3A3578F29D7F.16948@groups.io>
  13 siblings, 2 replies; 25+ messages in thread
From: Kun Qin @ 2021-01-14 22:36 UTC (permalink / raw)
  To: devel; +Cc: Eric Dong, Ray Ni, Laszlo Ersek, Rahul Kumar

This change abstracts standalone and traditional MM driver entrypoints
into separate files to match corresponding driver entrypoint interfaces.

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>
---

Notes:
    v3:
    - Revert file name change of "CpuIo2Smm" for review and git history
    concern [Laszlo]
    - Break driver entrypoint into separate patch [Laszlo]
    
    v2:
    - Removed "EFIAPI" for internal functions.

 UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c                               |  9 ++----
 UefiCpuPkg/CpuIo2Smm/CpuIo2StandaloneMm.c                      | 32 ++++++++++++++++++++
 UefiCpuPkg/CpuIo2Smm/CpuIo2TraditionalMm.c                     | 32 ++++++++++++++++++++
 UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.h                               | 12 ++++++++
 UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf                             |  3 +-
 UefiCpuPkg/CpuIo2Smm/{CpuIo2Smm.inf => CpuIo2StandaloneMm.inf} | 18 +++++------
 UefiCpuPkg/UefiCpuPkg.dsc                                      |  5 +++
 7 files changed, 93 insertions(+), 18 deletions(-)

diff --git a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c
index c0a2baecee03..cc99fd59a184 100644
--- a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c
+++ b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c
@@ -371,18 +371,13 @@ 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;
diff --git a/UefiCpuPkg/CpuIo2Smm/CpuIo2StandaloneMm.c b/UefiCpuPkg/CpuIo2Smm/CpuIo2StandaloneMm.c
new file mode 100644
index 000000000000..d6707d7bc8bc
--- /dev/null
+++ b/UefiCpuPkg/CpuIo2Smm/CpuIo2StandaloneMm.c
@@ -0,0 +1,32 @@
+/** @file
+  Produces the SMM CPU I/O Protocol.
+
+Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
+Copyright (c) Microsoft Corporation.
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <PiMm.h>
+
+#include "CpuIo2Smm.h"
+
+/**
+  The module Entry Point for Standalone MM CpuIoProtocol 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/CpuIo2TraditionalMm.c b/UefiCpuPkg/CpuIo2Smm/CpuIo2TraditionalMm.c
new file mode 100644
index 000000000000..5a4f41b160a4
--- /dev/null
+++ b/UefiCpuPkg/CpuIo2Smm/CpuIo2TraditionalMm.c
@@ -0,0 +1,32 @@
+/** @file
+  Produces the SMM CPU I/O Protocol.
+
+Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
+Copyright (c) Microsoft Corporation.
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <PiSmm.h>
+
+#include "CpuIo2Smm.h"
+
+/**
+  The module Entry Point for Traditional MM CpuIoProtocol 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
+TraditionalMmCpuIo2Initialize (
+  IN EFI_HANDLE        ImageHandle,
+  IN EFI_SYSTEM_TABLE  *SystemTable
+  )
+{
+  return CommonCpuIo2Initialize ();
+}
diff --git a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.h b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.h
index c80261945f71..eda9fbb090cd 100644
--- a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.h
+++ b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.h
@@ -153,4 +153,16 @@ 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
+CommonCpuIo2Initialize (
+  VOID
+  );
+
 #endif
diff --git a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf
index b743a5e0e316..8c5d0542e3da 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.
@@ -25,6 +25,7 @@ [Defines]
 [Sources]
   CpuIo2Smm.c
   CpuIo2Smm.h
+  CpuIo2TraditionalMm.c
 
 [Packages]
   MdePkg/MdePkg.dec
diff --git a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf b/UefiCpuPkg/CpuIo2Smm/CpuIo2StandaloneMm.inf
similarity index 60%
copy from UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf
copy to UefiCpuPkg/CpuIo2Smm/CpuIo2StandaloneMm.inf
index b743a5e0e316..c9fd3068cec4 100644
--- a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf
+++ b/UefiCpuPkg/CpuIo2Smm/CpuIo2StandaloneMm.inf
@@ -2,19 +2,19 @@
 #  Produces the SMM CPU I/O 2 Protocol by using the services of the I/O Library.
 #
 #  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                      = 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.
@@ -25,12 +25,13 @@ [Defines]
 [Sources]
   CpuIo2Smm.c
   CpuIo2Smm.h
+  CpuIo2StandaloneMm.c
 
 [Packages]
   MdePkg/MdePkg.dec
 
 [LibraryClasses]
-  UefiDriverEntryPoint
+  StandaloneMmDriverEntryPoint
   BaseLib
   DebugLib
   IoLib
@@ -42,6 +43,3 @@ [Protocols]
 
 [Depex]
   TRUE
-
-[UserExtensions.TianoCore."ExtraFiles"]
-  CpuIo2SmmExtra.uni
diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc
index 9b56bcaabebe..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
@@ -94,6 +95,9 @@ [LibraryClasses.common.DXE_SMM_DRIVER]
   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
@@ -122,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.30.0.windows.1


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

* [PATCH v3 18/18] UefiCpuPkg: SmmCpuExceptionHandlerLib: Added StandaloneMm module support
       [not found] <20210114223637.2737-1-kun.q@outlook.com>
                   ` (11 preceding siblings ...)
  2021-01-14 22:36 ` [PATCH v3 17/18] UefiCpuPkg: CpuIo2Smm: Support of CpuIo driver under StandaloneMm Kun Qin
@ 2021-01-14 22:36 ` Kun Qin
  2021-01-22  3:51   ` Ni, Ray
       [not found] ` <165A3A3578F29D7F.16948@groups.io>
  13 siblings, 1 reply; 25+ messages in thread
From: Kun Qin @ 2021-01-14 22:36 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>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
---

Notes:
    v3:
    - Added reviewed-by tag [Laszlo]
    
    v2:
    - No review, no change.

 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.30.0.windows.1


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

* Re: [PATCH v3 16/18] UefiCpuPkg: CpuIo2Smm: Move CpuIo2Smm driver to consume gMmst
  2021-01-14 22:36 ` [PATCH v3 16/18] UefiCpuPkg: CpuIo2Smm: Move CpuIo2Smm driver to consume gMmst Kun Qin
@ 2021-01-15  7:12   ` Laszlo Ersek
  2021-01-22  4:18     ` [edk2-devel] " Ni, Ray
  0 siblings, 1 reply; 25+ messages in thread
From: Laszlo Ersek @ 2021-01-15  7:12 UTC (permalink / raw)
  To: Kun Qin, devel; +Cc: Eric Dong, Ray Ni, Rahul Kumar

On 01/14/21 23:36, Kun Qin wrote:
> This change replaced gSmst with gMmst to support broader compatibility
> under MM environment for CpuIo2Smm driver.
> 
> 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>
> ---
> 
> Notes:
>     v3:
>     - Break gMmst replacement into separate PR [Laszlo]
>     
>     v2:
>     - Removed "EFIAPI" for internal functions.
> 
>  UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c   | 6 +++---
>  UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.h   | 2 +-
>  UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf | 2 +-
>  UefiCpuPkg/UefiCpuPkg.dsc          | 1 +
>  4 files changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c
> index b840d3e10cae..c0a2baecee03 100644
> --- a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c
> +++ b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c
> @@ -390,12 +390,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
> +  // Install the SMM CPU I/O Protocol into the MM protocol database
>    //
> -  Status = gSmst->SmmInstallProtocolInterface (
> +  Status = gMmst->MmInstallProtocolInterface (
>                      &mHandle,
>                      &gEfiSmmCpuIo2ProtocolGuid,
>                      EFI_NATIVE_INTERFACE,
> diff --git a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.h b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.h
> index 4c133b58c9f4..c80261945f71 100644
> --- a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.h
> +++ b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.h
> @@ -16,7 +16,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
>  #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
> diff --git a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf
> index bc78fa4e42d2..b743a5e0e316 100644
> --- a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf
> +++ b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf
> @@ -34,7 +34,7 @@ [LibraryClasses]
>    BaseLib
>    DebugLib
>    IoLib
> -  SmmServicesTableLib
> +  MmServicesTableLib
>    BaseMemoryLib
>  
>  [Protocols]
> diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc
> index b2b6d78a71b0..9b56bcaabebe 100644
> --- a/UefiCpuPkg/UefiCpuPkg.dsc
> +++ b/UefiCpuPkg/UefiCpuPkg.dsc
> @@ -89,6 +89,7 @@ [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
> 

Reviewed-by: Laszlo Ersek <lersek@redhat.com>


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

* Re: [PATCH v3 17/18] UefiCpuPkg: CpuIo2Smm: Support of CpuIo driver under StandaloneMm
  2021-01-14 22:36 ` [PATCH v3 17/18] UefiCpuPkg: CpuIo2Smm: Support of CpuIo driver under StandaloneMm Kun Qin
@ 2021-01-15  7:16   ` Laszlo Ersek
  2021-01-22  4:17   ` [edk2-devel] " Ni, Ray
  1 sibling, 0 replies; 25+ messages in thread
From: Laszlo Ersek @ 2021-01-15  7:16 UTC (permalink / raw)
  To: Kun Qin, devel; +Cc: Eric Dong, Ray Ni, Rahul Kumar

On 01/14/21 23:36, Kun Qin wrote:
> This change abstracts standalone and traditional MM driver entrypoints
> into separate files to match corresponding driver entrypoint interfaces.
> 
> 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>
> ---
> 
> Notes:
>     v3:
>     - Revert file name change of "CpuIo2Smm" for review and git history
>     concern [Laszlo]
>     - Break driver entrypoint into separate patch [Laszlo]
>     
>     v2:
>     - Removed "EFIAPI" for internal functions.
> 
>  UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c                               |  9 ++----
>  UefiCpuPkg/CpuIo2Smm/CpuIo2StandaloneMm.c                      | 32 ++++++++++++++++++++
>  UefiCpuPkg/CpuIo2Smm/CpuIo2TraditionalMm.c                     | 32 ++++++++++++++++++++
>  UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.h                               | 12 ++++++++
>  UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf                             |  3 +-
>  UefiCpuPkg/CpuIo2Smm/{CpuIo2Smm.inf => CpuIo2StandaloneMm.inf} | 18 +++++------
>  UefiCpuPkg/UefiCpuPkg.dsc                                      |  5 +++
>  7 files changed, 93 insertions(+), 18 deletions(-)
> 
> diff --git a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c
> index c0a2baecee03..cc99fd59a184 100644
> --- a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c
> +++ b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c
> @@ -371,18 +371,13 @@ 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;
> diff --git a/UefiCpuPkg/CpuIo2Smm/CpuIo2StandaloneMm.c b/UefiCpuPkg/CpuIo2Smm/CpuIo2StandaloneMm.c
> new file mode 100644
> index 000000000000..d6707d7bc8bc
> --- /dev/null
> +++ b/UefiCpuPkg/CpuIo2Smm/CpuIo2StandaloneMm.c
> @@ -0,0 +1,32 @@
> +/** @file
> +  Produces the SMM CPU I/O Protocol.
> +
> +Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
> +Copyright (c) Microsoft Corporation.
> +SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <PiMm.h>
> +
> +#include "CpuIo2Smm.h"
> +
> +/**
> +  The module Entry Point for Standalone MM CpuIoProtocol 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/CpuIo2TraditionalMm.c b/UefiCpuPkg/CpuIo2Smm/CpuIo2TraditionalMm.c
> new file mode 100644
> index 000000000000..5a4f41b160a4
> --- /dev/null
> +++ b/UefiCpuPkg/CpuIo2Smm/CpuIo2TraditionalMm.c
> @@ -0,0 +1,32 @@
> +/** @file
> +  Produces the SMM CPU I/O Protocol.
> +
> +Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
> +Copyright (c) Microsoft Corporation.
> +SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <PiSmm.h>
> +
> +#include "CpuIo2Smm.h"
> +
> +/**
> +  The module Entry Point for Traditional MM CpuIoProtocol 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
> +TraditionalMmCpuIo2Initialize (
> +  IN EFI_HANDLE        ImageHandle,
> +  IN EFI_SYSTEM_TABLE  *SystemTable
> +  )
> +{
> +  return CommonCpuIo2Initialize ();
> +}
> diff --git a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.h b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.h
> index c80261945f71..eda9fbb090cd 100644
> --- a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.h
> +++ b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.h
> @@ -153,4 +153,16 @@ 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
> +CommonCpuIo2Initialize (
> +  VOID
> +  );
> +
>  #endif
> diff --git a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf
> index b743a5e0e316..8c5d0542e3da 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.
> @@ -25,6 +25,7 @@ [Defines]
>  [Sources]
>    CpuIo2Smm.c
>    CpuIo2Smm.h
> +  CpuIo2TraditionalMm.c
>  
>  [Packages]
>    MdePkg/MdePkg.dec
> diff --git a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf b/UefiCpuPkg/CpuIo2Smm/CpuIo2StandaloneMm.inf
> similarity index 60%
> copy from UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf
> copy to UefiCpuPkg/CpuIo2Smm/CpuIo2StandaloneMm.inf
> index b743a5e0e316..c9fd3068cec4 100644
> --- a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf
> +++ b/UefiCpuPkg/CpuIo2Smm/CpuIo2StandaloneMm.inf
> @@ -2,19 +2,19 @@
>  #  Produces the SMM CPU I/O 2 Protocol by using the services of the I/O Library.
>  #
>  #  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                      = 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.
> @@ -25,12 +25,13 @@ [Defines]
>  [Sources]
>    CpuIo2Smm.c
>    CpuIo2Smm.h
> +  CpuIo2StandaloneMm.c
>  
>  [Packages]
>    MdePkg/MdePkg.dec
>  
>  [LibraryClasses]
> -  UefiDriverEntryPoint
> +  StandaloneMmDriverEntryPoint
>    BaseLib
>    DebugLib
>    IoLib
> @@ -42,6 +43,3 @@ [Protocols]
>  
>  [Depex]
>    TRUE
> -
> -[UserExtensions.TianoCore."ExtraFiles"]
> -  CpuIo2SmmExtra.uni

I'm unsure whether this section in the new INF file should be re-created
instead, with a customized UNI file. I think it may only matter for UPT
(the packaging tool); I'll let the other reviewers comment on that.

The patch looks OK to me.

Reviewed-by: Laszlo Ersek <lersek@redhat.com>

Thanks
Laszlo

> diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc
> index 9b56bcaabebe..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
> @@ -94,6 +95,9 @@ [LibraryClasses.common.DXE_SMM_DRIVER]
>    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
> @@ -122,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
> 


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

* Re: [edk2-devel] [PATCH v3 12/18] PcAtChipsetPkg: AcpiTimerLib: Added StandaloneMm instance of AcpiTimerLib
       [not found] ` <165A3A3578F29D7F.16948@groups.io>
@ 2021-01-21  1:46   ` Kun Qin
  2021-01-22  3:50     ` Ni, Ray
  0 siblings, 1 reply; 25+ messages in thread
From: Kun Qin @ 2021-01-21  1:46 UTC (permalink / raw)
  To: devel@edk2.groups.io, Ray Ni

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

Hi Ray,

I updated the file names as suggested on the previous round. Do you have any further comments/feedback?

Thanks,
Kun

From: Kun Qin<mailto:kun.q@outlook.com>
Sent: Thursday, January 14, 2021 14:37
To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>
Cc: Ray Ni<mailto:ray.ni@intel.com>
Subject: [edk2-devel] [PATCH v3 12/18] PcAtChipsetPkg: AcpiTimerLib: Added StandaloneMm instance of AcpiTimerLib

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>
---

Notes:
    v3:
    - Renamed "CommonAcpiTimerLib" to "DxeStandaloneMmAcpiTimerLib" to
    avoid confusion [Ray]
    - Renamed BASE NAME (and file name) to StandaloneMmAcpiTimerLib [Ray]

    v2:
    - Removed "EFIAPI" for internal functions.

 PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c                                     | 81 +-------------------
 PcAtChipsetPkg/Library/AcpiTimerLib/{DxeAcpiTimerLib.c => DxeStandaloneMmAcpiTimerLib.c}  |  9 +--
 PcAtChipsetPkg/Library/AcpiTimerLib/StandaloneMmAcpiTimerLib.c                            | 31 ++++++++
 PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf                                   |  2 +
 PcAtChipsetPkg/Library/AcpiTimerLib/DxeStandaloneMmAcpiTimerLib.h                         | 24 ++++++
 PcAtChipsetPkg/Library/AcpiTimerLib/{DxeAcpiTimerLib.inf => StandaloneMmAcpiTimerLib.inf} | 19 +++--
 PcAtChipsetPkg/PcAtChipsetPkg.dsc                                                         |  1 +
 7 files changed, 74 insertions(+), 93 deletions(-)

diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c
index 3ad831b15e8a..9ac2a446e365 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 "DxeStandaloneMmAcpiTimerLib.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/DxeAcpiTimerLib.c b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeStandaloneMmAcpiTimerLib.c
similarity index 86%
copy from PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c
copy to PcAtChipsetPkg/Library/AcpiTimerLib/DxeStandaloneMmAcpiTimerLib.c
index 3ad831b15e8a..0e401194d01d 100644
--- a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c
+++ b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeStandaloneMmAcpiTimerLib.c
@@ -72,17 +72,12 @@ 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/StandaloneMmAcpiTimerLib.c b/PcAtChipsetPkg/Library/AcpiTimerLib/StandaloneMmAcpiTimerLib.c
new file mode 100644
index 000000000000..97aca5606905
--- /dev/null
+++ b/PcAtChipsetPkg/Library/AcpiTimerLib/StandaloneMmAcpiTimerLib.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 "DxeStandaloneMmAcpiTimerLib.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/DxeAcpiTimerLib.inf b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf
index d86356f4ff17..93972e53c9c5 100644
--- a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf
+++ b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf
@@ -25,6 +25,8 @@ [Defines]
 [Sources]
   AcpiTimerLib.c
   DxeAcpiTimerLib.c
+  DxeStandaloneMmAcpiTimerLib.c
+  DxeStandaloneMmAcpiTimerLib.h

 [Packages]
   MdePkg/MdePkg.dec
diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeStandaloneMmAcpiTimerLib.h b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeStandaloneMmAcpiTimerLib.h
new file mode 100644
index 000000000000..6015d684e5bd
--- /dev/null
+++ b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeStandaloneMmAcpiTimerLib.h
@@ -0,0 +1,24 @@
+/** @file
+  Header file internal to ACPI TimerLib.
+
+Copyright (c) Microsoft Corporation.
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+
+#ifndef _DXE_STANDALONE_MM_ACPI_TIMER_LIB_H_
+#define _DXE_STANDALONE_MM_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
+CommonAcpiTimerLibConstructor (
+  VOID
+  );
+
+#endif
diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf b/PcAtChipsetPkg/Library/AcpiTimerLib/StandaloneMmAcpiTimerLib.inf
similarity index 70%
copy from PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf
copy to PcAtChipsetPkg/Library/AcpiTimerLib/StandaloneMmAcpiTimerLib.inf
index d86356f4ff17..c5efdd145d19 100644
--- a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf
+++ b/PcAtChipsetPkg/Library/AcpiTimerLib/StandaloneMmAcpiTimerLib.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                      = StandaloneMmAcpiTimerLib
+  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
+  StandaloneMmAcpiTimerLib.c
+  DxeStandaloneMmAcpiTimerLib.c
+  DxeStandaloneMmAcpiTimerLib.h

 [Packages]
   MdePkg/MdePkg.dec
diff --git a/PcAtChipsetPkg/PcAtChipsetPkg.dsc b/PcAtChipsetPkg/PcAtChipsetPkg.dsc
index b61b7d1f528e..3d1fb816f54f 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/StandaloneMmAcpiTimerLib.inf
   PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf

 [BuildOptions]
--
2.30.0.windows.1







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

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

* Re: [edk2-devel] [PATCH v3 12/18] PcAtChipsetPkg: AcpiTimerLib: Added StandaloneMm instance of AcpiTimerLib
  2021-01-21  1:46   ` [edk2-devel] [PATCH v3 12/18] PcAtChipsetPkg: AcpiTimerLib: Added StandaloneMm instance of AcpiTimerLib Kun Qin
@ 2021-01-22  3:50     ` Ni, Ray
  0 siblings, 0 replies; 25+ messages in thread
From: Ni, Ray @ 2021-01-22  3:50 UTC (permalink / raw)
  To: Kun Qin, devel@edk2.groups.io

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

Reviewed-by: Ray Ni <ray.ni@intel.com>

From: Kun Qin <kun.q@outlook.com>
Sent: Thursday, January 21, 2021 9:46 AM
To: devel@edk2.groups.io; Ni, Ray <ray.ni@intel.com>
Subject: RE: [edk2-devel] [PATCH v3 12/18] PcAtChipsetPkg: AcpiTimerLib: Added StandaloneMm instance of AcpiTimerLib

Hi Ray,

I updated the file names as suggested on the previous round. Do you have any further comments/feedback?

Thanks,
Kun

From: Kun Qin<mailto:kun.q@outlook.com>
Sent: Thursday, January 14, 2021 14:37
To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>
Cc: Ray Ni<mailto:ray.ni@intel.com>
Subject: [edk2-devel] [PATCH v3 12/18] PcAtChipsetPkg: AcpiTimerLib: Added StandaloneMm instance of AcpiTimerLib

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<mailto:ray.ni@intel.com>>

Signed-off-by: Kun Qin <kun.q@outlook.com<mailto:kun.q@outlook.com>>
---

Notes:
    v3:
    - Renamed "CommonAcpiTimerLib" to "DxeStandaloneMmAcpiTimerLib" to
    avoid confusion [Ray]
    - Renamed BASE NAME (and file name) to StandaloneMmAcpiTimerLib [Ray]

    v2:
    - Removed "EFIAPI" for internal functions.

 PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c                                     | 81 +-------------------
 PcAtChipsetPkg/Library/AcpiTimerLib/{DxeAcpiTimerLib.c => DxeStandaloneMmAcpiTimerLib.c}  |  9 +--
 PcAtChipsetPkg/Library/AcpiTimerLib/StandaloneMmAcpiTimerLib.c                            | 31 ++++++++
 PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf                                   |  2 +
 PcAtChipsetPkg/Library/AcpiTimerLib/DxeStandaloneMmAcpiTimerLib.h                         | 24 ++++++
 PcAtChipsetPkg/Library/AcpiTimerLib/{DxeAcpiTimerLib.inf => StandaloneMmAcpiTimerLib.inf} | 19 +++--
 PcAtChipsetPkg/PcAtChipsetPkg.dsc                                                         |  1 +
 7 files changed, 74 insertions(+), 93 deletions(-)

diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c
index 3ad831b15e8a..9ac2a446e365 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 "DxeStandaloneMmAcpiTimerLib.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/DxeAcpiTimerLib.c b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeStandaloneMmAcpiTimerLib.c
similarity index 86%
copy from PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c
copy to PcAtChipsetPkg/Library/AcpiTimerLib/DxeStandaloneMmAcpiTimerLib.c
index 3ad831b15e8a..0e401194d01d 100644
--- a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c
+++ b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeStandaloneMmAcpiTimerLib.c
@@ -72,17 +72,12 @@ 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/StandaloneMmAcpiTimerLib.c b/PcAtChipsetPkg/Library/AcpiTimerLib/StandaloneMmAcpiTimerLib.c
new file mode 100644
index 000000000000..97aca5606905
--- /dev/null
+++ b/PcAtChipsetPkg/Library/AcpiTimerLib/StandaloneMmAcpiTimerLib.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 "DxeStandaloneMmAcpiTimerLib.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/DxeAcpiTimerLib.inf b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf
index d86356f4ff17..93972e53c9c5 100644
--- a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf
+++ b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf
@@ -25,6 +25,8 @@ [Defines]
 [Sources]
   AcpiTimerLib.c
   DxeAcpiTimerLib.c
+  DxeStandaloneMmAcpiTimerLib.c
+  DxeStandaloneMmAcpiTimerLib.h

 [Packages]
   MdePkg/MdePkg.dec
diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeStandaloneMmAcpiTimerLib.h b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeStandaloneMmAcpiTimerLib.h
new file mode 100644
index 000000000000..6015d684e5bd
--- /dev/null
+++ b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeStandaloneMmAcpiTimerLib.h
@@ -0,0 +1,24 @@
+/** @file
+  Header file internal to ACPI TimerLib.
+
+Copyright (c) Microsoft Corporation.
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+
+#ifndef _DXE_STANDALONE_MM_ACPI_TIMER_LIB_H_
+#define _DXE_STANDALONE_MM_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
+CommonAcpiTimerLibConstructor (
+  VOID
+  );
+
+#endif
diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf b/PcAtChipsetPkg/Library/AcpiTimerLib/StandaloneMmAcpiTimerLib.inf
similarity index 70%
copy from PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf
copy to PcAtChipsetPkg/Library/AcpiTimerLib/StandaloneMmAcpiTimerLib.inf
index d86356f4ff17..c5efdd145d19 100644
--- a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf
+++ b/PcAtChipsetPkg/Library/AcpiTimerLib/StandaloneMmAcpiTimerLib.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                      = StandaloneMmAcpiTimerLib
+  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
+  StandaloneMmAcpiTimerLib.c
+  DxeStandaloneMmAcpiTimerLib.c
+  DxeStandaloneMmAcpiTimerLib.h

 [Packages]
   MdePkg/MdePkg.dec
diff --git a/PcAtChipsetPkg/PcAtChipsetPkg.dsc b/PcAtChipsetPkg/PcAtChipsetPkg.dsc
index b61b7d1f528e..3d1fb816f54f 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/StandaloneMmAcpiTimerLib.inf
   PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf

 [BuildOptions]
--
2.30.0.windows.1






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

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

* Re: [PATCH v3 18/18] UefiCpuPkg: SmmCpuExceptionHandlerLib: Added StandaloneMm module support
  2021-01-14 22:36 ` [PATCH v3 18/18] UefiCpuPkg: SmmCpuExceptionHandlerLib: Added StandaloneMm module support Kun Qin
@ 2021-01-22  3:51   ` Ni, Ray
  0 siblings, 0 replies; 25+ messages in thread
From: Ni, Ray @ 2021-01-22  3:51 UTC (permalink / raw)
  To: Kun Qin, devel@edk2.groups.io; +Cc: Dong, Eric, Laszlo Ersek, Kumar, Rahul1

Reviewed-by: Ray Ni <ray.ni@intel.com>

> -----Original Message-----
> From: Kun Qin <kun.q@outlook.com>
> Sent: Friday, January 15, 2021 6:37 AM
> To: devel@edk2.groups.io
> Cc: Dong, Eric <eric.dong@intel.com>; Ni, Ray <ray.ni@intel.com>; Laszlo Ersek
> <lersek@redhat.com>; Kumar, Rahul1 <rahul1.kumar@intel.com>
> Subject: [PATCH v3 18/18] UefiCpuPkg: SmmCpuExceptionHandlerLib: Added
> StandaloneMm module support
> 
> 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>
> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
> ---
> 
> Notes:
>     v3:
>     - Added reviewed-by tag [Laszlo]
> 
>     v2:
>     - No review, no change.
> 
>  UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf
> | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git
> a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.i
> nf
> b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.i
> nf
> index 4cdb11c04ea0..ea5b10b5c8e4 100644
> ---
> a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.i
> nf
> +++
> b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.i
> nf
> @@ -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.30.0.windows.1


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

* Re: [edk2-devel] [PATCH v3 17/18] UefiCpuPkg: CpuIo2Smm: Support of CpuIo driver under StandaloneMm
  2021-01-14 22:36 ` [PATCH v3 17/18] UefiCpuPkg: CpuIo2Smm: Support of CpuIo driver under StandaloneMm Kun Qin
  2021-01-15  7:16   ` Laszlo Ersek
@ 2021-01-22  4:17   ` Ni, Ray
  2021-01-22  4:40     ` Kun Qin
  1 sibling, 1 reply; 25+ messages in thread
From: Ni, Ray @ 2021-01-22  4:17 UTC (permalink / raw)
  To: devel@edk2.groups.io, kun.q@outlook.com
  Cc: Dong, Eric, Laszlo Ersek, Kumar, Rahul1

> 
>  UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c                               |  9 ++----
>  UefiCpuPkg/CpuIo2Smm/CpuIo2StandaloneMm.c                      | 32 ++++++++++++++++++++
>  UefiCpuPkg/CpuIo2Smm/CpuIo2TraditionalMm.c                     | 32 ++++++++++++++++++++
>  UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.h                               | 12 ++++++++
>  UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf                             |  3 +-
>  UefiCpuPkg/CpuIo2Smm/{CpuIo2Smm.inf => CpuIo2StandaloneMm.inf} | 18 +++++------
>  UefiCpuPkg/UefiCpuPkg.dsc                                      |  5 +++ 


How about do the file name change as below?
CpuIo2Smm.c/h --> CpuIo2Mm.c/h  # remove the "S"
CpuIo2TraditionalMm.c -> CpuIo2Smm.c # Traditional MM equals to SMM. It also matches to CpuIo2Smm.inf.
CpuIo2StandaloneMm.c/inf # looks good to me.



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

* Re: [edk2-devel] [PATCH v3 16/18] UefiCpuPkg: CpuIo2Smm: Move CpuIo2Smm driver to consume gMmst
  2021-01-15  7:12   ` Laszlo Ersek
@ 2021-01-22  4:18     ` Ni, Ray
  0 siblings, 0 replies; 25+ messages in thread
From: Ni, Ray @ 2021-01-22  4:18 UTC (permalink / raw)
  To: devel@edk2.groups.io, lersek@redhat.com, Kun Qin
  Cc: Dong, Eric, Kumar, Rahul1

Reviewed-by: Ray Ni <ray.ni@intel.com>

> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Laszlo
> Ersek
> Sent: Friday, January 15, 2021 3:12 PM
> To: Kun Qin <kun.q@outlook.com>; devel@edk2.groups.io
> Cc: Dong, Eric <eric.dong@intel.com>; Ni, Ray <ray.ni@intel.com>; Kumar,
> Rahul1 <rahul1.kumar@intel.com>
> Subject: Re: [edk2-devel] [PATCH v3 16/18] UefiCpuPkg: CpuIo2Smm: Move
> CpuIo2Smm driver to consume gMmst
> 
> On 01/14/21 23:36, Kun Qin wrote:
> > This change replaced gSmst with gMmst to support broader compatibility
> > under MM environment for CpuIo2Smm driver.
> >
> > 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>
> > ---
> >
> > Notes:
> >     v3:
> >     - Break gMmst replacement into separate PR [Laszlo]
> >
> >     v2:
> >     - Removed "EFIAPI" for internal functions.
> >
> >  UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c   | 6 +++---
> >  UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.h   | 2 +-
> >  UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf | 2 +-
> >  UefiCpuPkg/UefiCpuPkg.dsc          | 1 +
> >  4 files changed, 6 insertions(+), 5 deletions(-)
> >
> > diff --git a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c
> b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c
> > index b840d3e10cae..c0a2baecee03 100644
> > --- a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c
> > +++ b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c
> > @@ -390,12 +390,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
> > +  // Install the SMM CPU I/O Protocol into the MM protocol database
> >    //
> > -  Status = gSmst->SmmInstallProtocolInterface (
> > +  Status = gMmst->MmInstallProtocolInterface (
> >                      &mHandle,
> >                      &gEfiSmmCpuIo2ProtocolGuid,
> >                      EFI_NATIVE_INTERFACE,
> > diff --git a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.h
> b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.h
> > index 4c133b58c9f4..c80261945f71 100644
> > --- a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.h
> > +++ b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.h
> > @@ -16,7 +16,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
> >  #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
> > diff --git a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf
> b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf
> > index bc78fa4e42d2..b743a5e0e316 100644
> > --- a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf
> > +++ b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf
> > @@ -34,7 +34,7 @@ [LibraryClasses]
> >    BaseLib
> >    DebugLib
> >    IoLib
> > -  SmmServicesTableLib
> > +  MmServicesTableLib
> >    BaseMemoryLib
> >
> >  [Protocols]
> > diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc
> > index b2b6d78a71b0..9b56bcaabebe 100644
> > --- a/UefiCpuPkg/UefiCpuPkg.dsc
> > +++ b/UefiCpuPkg/UefiCpuPkg.dsc
> > @@ -89,6 +89,7 @@ [LibraryClasses.common.DXE_DRIVER]
> >
> >  [LibraryClasses.common.DXE_SMM_DRIVER]
> >
> SmmServicesTableLib|MdePkg/Library/SmmServicesTableLib/SmmServicesTab
> leLib.inf
> > +
> MmServicesTableLib|MdePkg/Library/MmServicesTableLib/MmServicesTableL
> ib.inf
> >
> MemoryAllocationLib|MdePkg/Library/SmmMemoryAllocationLib/SmmMemor
> yAllocationLib.inf
> >    HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
> >
> CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCp
> uExceptionHandlerLib.inf
> >
> 
> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
> 
> 
> 
> 
> 


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

* Re: [edk2-devel] [PATCH v3 17/18] UefiCpuPkg: CpuIo2Smm: Support of CpuIo driver under StandaloneMm
  2021-01-22  4:17   ` [edk2-devel] " Ni, Ray
@ 2021-01-22  4:40     ` Kun Qin
  2021-01-22  6:29       ` Ni, Ray
  2021-01-22 12:32       ` Laszlo Ersek
  0 siblings, 2 replies; 25+ messages in thread
From: Kun Qin @ 2021-01-22  4:40 UTC (permalink / raw)
  To: Ni, Ray, devel@edk2.groups.io; +Cc: Dong, Eric, Laszlo Ersek, Kumar, Rahul1

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

Hi Ray,

I was suggested not to rename the file for review easiness and git history concern during v2 patch. Thread here: Re: [PATCH v2 15/16] UefiCpuPkg: CpuIo2Smm: Support of CpuIo driver under StandaloneMm (groups.io)<https://edk2.groups.io/g/devel/message/69857>

Please let me know if you still recommend renaming the files. If so, would you suggest ```CpuIo2Smm.c/h --> CpuIo2Mm.c/h  # remove the "S"``` to be a separate patch between gSmst change and adding Standalone MM instance?

Thanks in advance.

Regards,
Kun

From: Ni, Ray<mailto:ray.ni@intel.com>
Sent: Thursday, January 21, 2021 20:17
To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>; kun.q@outlook.com<mailto:kun.q@outlook.com>
Cc: Dong, Eric<mailto:eric.dong@intel.com>; Laszlo Ersek<mailto:lersek@redhat.com>; Kumar, Rahul1<mailto:rahul1.kumar@intel.com>
Subject: RE: [edk2-devel] [PATCH v3 17/18] UefiCpuPkg: CpuIo2Smm: Support of CpuIo driver under StandaloneMm

>
>  UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c                               |  9 ++----
>  UefiCpuPkg/CpuIo2Smm/CpuIo2StandaloneMm.c                      | 32 ++++++++++++++++++++
>  UefiCpuPkg/CpuIo2Smm/CpuIo2TraditionalMm.c                     | 32 ++++++++++++++++++++
>  UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.h                               | 12 ++++++++
>  UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf                             |  3 +-
>  UefiCpuPkg/CpuIo2Smm/{CpuIo2Smm.inf => CpuIo2StandaloneMm.inf} | 18 +++++------
>  UefiCpuPkg/UefiCpuPkg.dsc                                      |  5 +++


How about do the file name change as below?
CpuIo2Smm.c/h --> CpuIo2Mm.c/h  # remove the "S"
CpuIo2TraditionalMm.c -> CpuIo2Smm.c # Traditional MM equals to SMM. It also matches to CpuIo2Smm.inf.
CpuIo2StandaloneMm.c/inf # looks good to me.



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

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

* Re: [edk2-devel] [PATCH v3 17/18] UefiCpuPkg: CpuIo2Smm: Support of CpuIo driver under StandaloneMm
  2021-01-22  4:40     ` Kun Qin
@ 2021-01-22  6:29       ` Ni, Ray
  2021-01-22  7:32         ` Kun Qin
  2021-01-22 12:32       ` Laszlo Ersek
  1 sibling, 1 reply; 25+ messages in thread
From: Ni, Ray @ 2021-01-22  6:29 UTC (permalink / raw)
  To: Kun Qin, devel@edk2.groups.io; +Cc: Dong, Eric, Laszlo Ersek, Kumar, Rahul1

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

Kun,
Yes. I recommend renaming the files. This can make future developers easy to understand which file stands for which purpose.
A separate rename patch looks good to me.

Thanks,
Ray

From: Kun Qin <kun.q@outlook.com>
Sent: Friday, January 22, 2021 12:41 PM
To: Ni, Ray <ray.ni@intel.com>; devel@edk2.groups.io
Cc: Dong, Eric <eric.dong@intel.com>; Laszlo Ersek <lersek@redhat.com>; Kumar, Rahul1 <rahul1.kumar@intel.com>
Subject: RE: [edk2-devel] [PATCH v3 17/18] UefiCpuPkg: CpuIo2Smm: Support of CpuIo driver under StandaloneMm

Hi Ray,

I was suggested not to rename the file for review easiness and git history concern during v2 patch. Thread here: Re: [PATCH v2 15/16] UefiCpuPkg: CpuIo2Smm: Support of CpuIo driver under StandaloneMm (groups.io)<https://edk2.groups.io/g/devel/message/69857>

Please let me know if you still recommend renaming the files. If so, would you suggest ```CpuIo2Smm.c/h --> CpuIo2Mm.c/h  # remove the "S"``` to be a separate patch between gSmst change and adding Standalone MM instance?

Thanks in advance.

Regards,
Kun

From: Ni, Ray<mailto:ray.ni@intel.com>
Sent: Thursday, January 21, 2021 20:17
To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>; kun.q@outlook.com<mailto:kun.q@outlook.com>
Cc: Dong, Eric<mailto:eric.dong@intel.com>; Laszlo Ersek<mailto:lersek@redhat.com>; Kumar, Rahul1<mailto:rahul1.kumar@intel.com>
Subject: RE: [edk2-devel] [PATCH v3 17/18] UefiCpuPkg: CpuIo2Smm: Support of CpuIo driver under StandaloneMm

>
>  UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c                               |  9 ++----
>  UefiCpuPkg/CpuIo2Smm/CpuIo2StandaloneMm.c                      | 32 ++++++++++++++++++++
>  UefiCpuPkg/CpuIo2Smm/CpuIo2TraditionalMm.c                     | 32 ++++++++++++++++++++
>  UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.h                               | 12 ++++++++
>  UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf                             |  3 +-
>  UefiCpuPkg/CpuIo2Smm/{CpuIo2Smm.inf => CpuIo2StandaloneMm.inf} | 18 +++++------
>  UefiCpuPkg/UefiCpuPkg.dsc                                      |  5 +++


How about do the file name change as below?
CpuIo2Smm.c/h --> CpuIo2Mm.c/h  # remove the "S"
CpuIo2TraditionalMm.c -> CpuIo2Smm.c # Traditional MM equals to SMM. It also matches to CpuIo2Smm.inf.
CpuIo2StandaloneMm.c/inf # looks good to me.


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

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

* Re: [edk2-devel] [PATCH v3 17/18] UefiCpuPkg: CpuIo2Smm: Support of CpuIo driver under StandaloneMm
  2021-01-22  6:29       ` Ni, Ray
@ 2021-01-22  7:32         ` Kun Qin
  0 siblings, 0 replies; 25+ messages in thread
From: Kun Qin @ 2021-01-22  7:32 UTC (permalink / raw)
  To: Ni, Ray, devel@edk2.groups.io; +Cc: Dong, Eric, Laszlo Ersek, Kumar, Rahul1

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

Ray,

Thanks for confirming. I will add the renaming patch in v4.

Regards,
Kun

From: Ni, Ray<mailto:ray.ni@intel.com>
Sent: Thursday, January 21, 2021 22:29
To: Kun Qin<mailto:kun.q@outlook.com>; devel@edk2.groups.io<mailto:devel@edk2.groups.io>
Cc: Dong, Eric<mailto:eric.dong@intel.com>; Laszlo Ersek<mailto:lersek@redhat.com>; Kumar, Rahul1<mailto:rahul1.kumar@intel.com>
Subject: RE: [edk2-devel] [PATCH v3 17/18] UefiCpuPkg: CpuIo2Smm: Support of CpuIo driver under StandaloneMm

Kun,
Yes. I recommend renaming the files. This can make future developers easy to understand which file stands for which purpose.
A separate rename patch looks good to me.

Thanks,
Ray

From: Kun Qin <kun.q@outlook.com>
Sent: Friday, January 22, 2021 12:41 PM
To: Ni, Ray <ray.ni@intel.com>; devel@edk2.groups.io
Cc: Dong, Eric <eric.dong@intel.com>; Laszlo Ersek <lersek@redhat.com>; Kumar, Rahul1 <rahul1.kumar@intel.com>
Subject: RE: [edk2-devel] [PATCH v3 17/18] UefiCpuPkg: CpuIo2Smm: Support of CpuIo driver under StandaloneMm

Hi Ray,

I was suggested not to rename the file for review easiness and git history concern during v2 patch. Thread here: Re: [PATCH v2 15/16] UefiCpuPkg: CpuIo2Smm: Support of CpuIo driver under StandaloneMm (groups.io)<https://edk2.groups.io/g/devel/message/69857>

Please let me know if you still recommend renaming the files. If so, would you suggest ```CpuIo2Smm.c/h --> CpuIo2Mm.c/h  # remove the "S"``` to be a separate patch between gSmst change and adding Standalone MM instance?

Thanks in advance.

Regards,
Kun

From: Ni, Ray<mailto:ray.ni@intel.com>
Sent: Thursday, January 21, 2021 20:17
To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>; kun.q@outlook.com<mailto:kun.q@outlook.com>
Cc: Dong, Eric<mailto:eric.dong@intel.com>; Laszlo Ersek<mailto:lersek@redhat.com>; Kumar, Rahul1<mailto:rahul1.kumar@intel.com>
Subject: RE: [edk2-devel] [PATCH v3 17/18] UefiCpuPkg: CpuIo2Smm: Support of CpuIo driver under StandaloneMm

>
>  UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c                               |  9 ++----
>  UefiCpuPkg/CpuIo2Smm/CpuIo2StandaloneMm.c                      | 32 ++++++++++++++++++++
>  UefiCpuPkg/CpuIo2Smm/CpuIo2TraditionalMm.c                     | 32 ++++++++++++++++++++
>  UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.h                               | 12 ++++++++
>  UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf                             |  3 +-
>  UefiCpuPkg/CpuIo2Smm/{CpuIo2Smm.inf => CpuIo2StandaloneMm.inf} | 18 +++++------
>  UefiCpuPkg/UefiCpuPkg.dsc                                      |  5 +++


How about do the file name change as below?
CpuIo2Smm.c/h --> CpuIo2Mm.c/h  # remove the "S"
CpuIo2TraditionalMm.c -> CpuIo2Smm.c # Traditional MM equals to SMM. It also matches to CpuIo2Smm.inf.
CpuIo2StandaloneMm.c/inf # looks good to me.



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

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

* Re: [edk2-devel] [PATCH v3 17/18] UefiCpuPkg: CpuIo2Smm: Support of CpuIo driver under StandaloneMm
  2021-01-22  4:40     ` Kun Qin
  2021-01-22  6:29       ` Ni, Ray
@ 2021-01-22 12:32       ` Laszlo Ersek
  2021-01-22 18:10         ` Kun Qin
  1 sibling, 1 reply; 25+ messages in thread
From: Laszlo Ersek @ 2021-01-22 12:32 UTC (permalink / raw)
  To: Kun Qin, Ni, Ray, devel@edk2.groups.io; +Cc: Dong, Eric, Kumar, Rahul1

Hi

On 01/22/21 05:40, Kun Qin wrote:
> Hi Ray,
> 
> I was suggested not to rename the file for review easiness and git history concern during v2 patch. Thread here: Re: [PATCH v2 15/16] UefiCpuPkg: CpuIo2Smm: Support of CpuIo driver under StandaloneMm (groups.io)<https://edk2.groups.io/g/devel/message/69857>

I think you misunderstood my v2 comments.

I requested that we please separate the renaming of *variables* to
dediacted patches. And, this referred primarily to the gSmst --> gMmst
replacement.

I didn't even *intend* to comment on the renaming of *files*, as far as
I can tell.

Renaming the *files*, as Ray suggests, seems reasonable. And if you can
split those actions to yet another patch, that's best.

Thanks
Laszlo


> 
> Please let me know if you still recommend renaming the files. If so, would you suggest ```CpuIo2Smm.c/h --> CpuIo2Mm.c/h  # remove the "S"``` to be a separate patch between gSmst change and adding Standalone MM instance?
> 
> Thanks in advance.
> 
> Regards,
> Kun
> 
> From: Ni, Ray<mailto:ray.ni@intel.com>
> Sent: Thursday, January 21, 2021 20:17
> To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>; kun.q@outlook.com<mailto:kun.q@outlook.com>
> Cc: Dong, Eric<mailto:eric.dong@intel.com>; Laszlo Ersek<mailto:lersek@redhat.com>; Kumar, Rahul1<mailto:rahul1.kumar@intel.com>
> Subject: RE: [edk2-devel] [PATCH v3 17/18] UefiCpuPkg: CpuIo2Smm: Support of CpuIo driver under StandaloneMm
> 
>>
>>  UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c                               |  9 ++----
>>  UefiCpuPkg/CpuIo2Smm/CpuIo2StandaloneMm.c                      | 32 ++++++++++++++++++++
>>  UefiCpuPkg/CpuIo2Smm/CpuIo2TraditionalMm.c                     | 32 ++++++++++++++++++++
>>  UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.h                               | 12 ++++++++
>>  UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf                             |  3 +-
>>  UefiCpuPkg/CpuIo2Smm/{CpuIo2Smm.inf => CpuIo2StandaloneMm.inf} | 18 +++++------
>>  UefiCpuPkg/UefiCpuPkg.dsc                                      |  5 +++
> 
> 
> How about do the file name change as below?
> CpuIo2Smm.c/h --> CpuIo2Mm.c/h  # remove the "S"
> CpuIo2TraditionalMm.c -> CpuIo2Smm.c # Traditional MM equals to SMM. It also matches to CpuIo2Smm.inf.
> CpuIo2StandaloneMm.c/inf # looks good to me.
> 
> 
> 


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

* Re: [edk2-devel] [PATCH v3 17/18] UefiCpuPkg: CpuIo2Smm: Support of CpuIo driver under StandaloneMm
  2021-01-22 12:32       ` Laszlo Ersek
@ 2021-01-22 18:10         ` Kun Qin
  0 siblings, 0 replies; 25+ messages in thread
From: Kun Qin @ 2021-01-22 18:10 UTC (permalink / raw)
  To: Laszlo Ersek, devel

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

Thanks for clarification. Will do.

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

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

end of thread, other threads:[~2021-01-22 18:10 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20210114223637.2737-1-kun.q@outlook.com>
2021-01-14 22:36 ` [PATCH v3 06/18] MdeModulePkg: SmmLockBoxSmmLib: Support StandaloneMm for SmmLockBoxLib Kun Qin
2021-01-14 22:36 ` [PATCH v3 07/18] MdeModulePkg: SmmReportStatusCodeLib: ReportStatusCodeLib in StandaloneMm Kun Qin
2021-01-14 22:36 ` [PATCH v3 08/18] MdeModulePkg: StatusCodeHandler: StatusCodeHandler driver " Kun Qin
2021-01-14 22:36 ` [PATCH v3 09/18] MdeModulePkg: FirmwarePerformanceDataTable: Added StandaloneMm support Kun Qin
2021-01-14 22:36 ` [PATCH v3 10/18] MdeModulePkg: ReportStatusCodeRouter: Support StandaloneMm RSC Router Kun Qin
2021-01-14 22:36 ` [PATCH v3 11/18] MdePkg: UefiDevicePathLib: Support UefiDevicePathLib under StandaloneMm Kun Qin
2021-01-14 22:36 ` [PATCH v3 12/18] PcAtChipsetPkg: AcpiTimerLib: Added StandaloneMm instance of AcpiTimerLib Kun Qin
2021-01-14 22:36 ` [PATCH v3 13/18] SecurityPkg: Tcg2PhysicalPresenceLib: Introduce StandaloneMm instance Kun Qin
2021-01-14 22:36 ` [PATCH v3 14/18] SecurityPkg: Tcg2PpVendorLibNull: Added support for MM_STANDALONE type Kun Qin
2021-01-14 22:36 ` [PATCH v3 15/18] SecurityPkg: Tpm2DeviceLibDTpm: Introduce StandaloneMm instance Kun Qin
2021-01-14 22:36 ` [PATCH v3 16/18] UefiCpuPkg: CpuIo2Smm: Move CpuIo2Smm driver to consume gMmst Kun Qin
2021-01-15  7:12   ` Laszlo Ersek
2021-01-22  4:18     ` [edk2-devel] " Ni, Ray
2021-01-14 22:36 ` [PATCH v3 17/18] UefiCpuPkg: CpuIo2Smm: Support of CpuIo driver under StandaloneMm Kun Qin
2021-01-15  7:16   ` Laszlo Ersek
2021-01-22  4:17   ` [edk2-devel] " Ni, Ray
2021-01-22  4:40     ` Kun Qin
2021-01-22  6:29       ` Ni, Ray
2021-01-22  7:32         ` Kun Qin
2021-01-22 12:32       ` Laszlo Ersek
2021-01-22 18:10         ` Kun Qin
2021-01-14 22:36 ` [PATCH v3 18/18] UefiCpuPkg: SmmCpuExceptionHandlerLib: Added StandaloneMm module support Kun Qin
2021-01-22  3:51   ` Ni, Ray
     [not found] ` <165A3A3578F29D7F.16948@groups.io>
2021-01-21  1:46   ` [edk2-devel] [PATCH v3 12/18] PcAtChipsetPkg: AcpiTimerLib: Added StandaloneMm instance of AcpiTimerLib Kun Qin
2021-01-22  3:50     ` Ni, Ray

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