public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH 0/6] PIWG M1993 - implement EFI_MM_COMMUNICATE2_PROTOCOL
@ 2019-11-22  8:32 Ard Biesheuvel
  2019-11-22  8:32 ` [PATCH 1/6] MdePkg: introduce MM communicate 2 protocol Ard Biesheuvel
                   ` (6 more replies)
  0 siblings, 7 replies; 9+ messages in thread
From: Ard Biesheuvel @ 2019-11-22  8:32 UTC (permalink / raw)
  To: devel; +Cc: leif.lindholm, Ard Biesheuvel, piwg, kimon.berlin, eugene

As discussed in the PIWG call on 21 November, I am sending out my
implementation of the MM communicate 2 protocol for review. It is
intended to work around the impedance mismatch between traditional
SMM (which uses physical addresses in the communication between DXE
components) and standalone MM (which uses virtual addresses)

The solution presented here is to introduce a new protocol that takes
both addresses, forcing the clients to pass both, but freeing them
from the responsibility to reason about which kind of address to pass:
this becomes the responsibility of the MM_COMMUNICATE implementation,
which is where it belongs.

Cc: piwg@uefi.org
Cc: kimon.berlin@hp.com 
Cc: eugene@hp.com

Ard Biesheuvel (6):
  MdePkg: introduce MM communicate 2 protocol
  MdeModulePkg/SmmIpl: expose MM communicate 2 protocol
  ArmPkg/MmCommunicationDxe: expose MM Communicate 2 protocol
  MdeModulePkg/VariableInfo: switch to MM communicate 2 protocol
  MdeModulePkg/FaultTolerantWriteSmmDxe: switch to MM communicate 2
    protocol
  MdeModulePkg/VariableSmmRuntimeDxe: switch to MM communicate 2
    protocol

 ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c                        | 83 +++++++++-----------
 ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.inf                      |  6 +-
 MdeModulePkg/Application/VariableInfo/VariableInfo.c                       | 19 +++--
 MdeModulePkg/Application/VariableInfo/VariableInfo.inf                     |  2 +-
 MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c                                     | 79 +++++++++++++++++++
 MdeModulePkg/Core/PiSmmCore/PiSmmIpl.inf                                   |  1 +
 MdeModulePkg/Include/Guid/SmmVariableCommon.h                              |  6 +-
 MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmCommon.h |  2 +-
 MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmDxe.c    | 25 +++---
 MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmDxe.h    |  2 +-
 MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmDxe.inf  |  4 +-
 MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c         | 39 ++++-----
 MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.inf       |  4 +-
 MdePkg/Include/Protocol/MmCommunication2.h                                 | 69 ++++++++++++++++
 MdePkg/MdePkg.dec                                                          |  7 ++
 15 files changed, 254 insertions(+), 94 deletions(-)
 create mode 100644 MdePkg/Include/Protocol/MmCommunication2.h

-- 
2.20.1


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

* [PATCH 1/6] MdePkg: introduce MM communicate 2 protocol
  2019-11-22  8:32 [PATCH 0/6] PIWG M1993 - implement EFI_MM_COMMUNICATE2_PROTOCOL Ard Biesheuvel
@ 2019-11-22  8:32 ` Ard Biesheuvel
  2019-11-22  8:32 ` [PATCH 2/6] MdeModulePkg/SmmIpl: expose " Ard Biesheuvel
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Ard Biesheuvel @ 2019-11-22  8:32 UTC (permalink / raw)
  To: devel; +Cc: leif.lindholm, Ard Biesheuvel, piwg, kimon.berlin, eugene

Add the protocol definition of the MM communicate 2 protocol,
which has been introduced by version 1.7 errata A of the PI spec.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 MdePkg/Include/Protocol/MmCommunication2.h | 69 ++++++++++++++++++++
 MdePkg/MdePkg.dec                          |  7 ++
 2 files changed, 76 insertions(+)

diff --git a/MdePkg/Include/Protocol/MmCommunication2.h b/MdePkg/Include/Protocol/MmCommunication2.h
new file mode 100644
index 000000000000..05f56dcae53e
--- /dev/null
+++ b/MdePkg/Include/Protocol/MmCommunication2.h
@@ -0,0 +1,69 @@
+/** @file
+  EFI MM Communication Protocol 2 as defined in the PI 1.7 errata A specification.
+
+  This protocol provides a means of communicating between drivers outside of MM and MMI
+  handlers inside of MM.
+
+  Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2019, Arm Limited. All rights reserved.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef _MM_COMMUNICATION2_H_
+#define _MM_COMMUNICATION2_H_
+
+#include <Protocol/MmCommunication.h>
+
+#define EFI_MM_COMMUNICATION2_PROTOCOL_GUID \
+  { \
+    0x378daedc, 0xf06b, 0x4446, { 0x83, 0x14, 0x40, 0xab, 0x93, 0x3c, 0x87, 0xa3 } \
+  }
+
+typedef struct _EFI_MM_COMMUNICATION2_PROTOCOL  EFI_MM_COMMUNICATION2_PROTOCOL;
+
+/**
+  Communicates with a registered handler.
+
+  This function provides a service to send and receive messages from a registered UEFI service.
+
+  @param[in] This                The EFI_MM_COMMUNICATION_PROTOCOL instance.
+  @param[in] CommBufferPhysical  Physical address of the MM communication buffer
+  @param[in] CommBufferVirtual   Virtual address of the MM communication buffer
+  @param[in] CommSize            The size of the data buffer being passed in. On exit, the size of data
+                                 being returned. Zero if the handler does not wish to reply with any data.
+                                 This parameter is optional and may be NULL.
+
+  @retval EFI_SUCCESS            The message was successfully posted.
+  @retval EFI_INVALID_PARAMETER  CommBufferPhysical was NULL or CommBufferVirtual was NULL.
+  @retval EFI_BAD_BUFFER_SIZE    The buffer is too large for the MM implementation.
+                                 If this error is returned, the MessageLength field
+                                 in the CommBuffer header or the integer pointed by
+                                 CommSize, are updated to reflect the maximum payload
+                                 size the implementation can accommodate.
+  @retval EFI_ACCESS_DENIED      The CommunicateBuffer parameter or CommSize parameter,
+                                 if not omitted, are in address range that cannot be
+                                 accessed by the MM environment.
+
+**/
+typedef
+EFI_STATUS
+(EFIAPI *EFI_MM_COMMUNICATE2)(
+  IN CONST EFI_MM_COMMUNICATION2_PROTOCOL   *This,
+  IN OUT VOID                               *CommBufferPhysical,
+  IN OUT VOID                               *CommBufferVirtual,
+  IN OUT UINTN                              *CommSize OPTIONAL
+  );
+
+///
+/// EFI MM Communication Protocol provides runtime services for communicating
+/// between DXE drivers and a registered MMI handler.
+///
+struct _EFI_MM_COMMUNICATION2_PROTOCOL {
+  EFI_MM_COMMUNICATE2  Communicate;
+};
+
+extern EFI_GUID gEfiMmCommunication2ProtocolGuid;
+
+#endif
+
diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec
index d022cc5e3ef2..93037e0e6c61 100644
--- a/MdePkg/MdePkg.dec
+++ b/MdePkg/MdePkg.dec
@@ -1276,6 +1276,13 @@
   ## Include/Protocol/SpiSmmNorFlash.h
   gEfiSpiSmmNorFlashProtocolGuid         = { 0xaab18f19, 0xfe14, 0x4666, { 0x86, 0x04, 0x87, 0xff, 0x6d, 0x66, 0x2c, 0x9a }}
 
+  #
+  # Protocols defined in PI 1.7.
+  #
+
+  ## Include/Protocol/MmCommunication2.h
+  gEfiMmCommunication2ProtocolGuid  = { 0x378daedc, 0xf06b, 0x4446, { 0x83, 0x14, 0x40, 0xab, 0x93, 0x3c, 0x87, 0xa3 }}
+
   #
   # Protocols defined in UEFI2.1/UEFI2.0/EFI1.1
   #
-- 
2.20.1


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

* [PATCH 2/6] MdeModulePkg/SmmIpl: expose MM communicate 2 protocol
  2019-11-22  8:32 [PATCH 0/6] PIWG M1993 - implement EFI_MM_COMMUNICATE2_PROTOCOL Ard Biesheuvel
  2019-11-22  8:32 ` [PATCH 1/6] MdePkg: introduce MM communicate 2 protocol Ard Biesheuvel
@ 2019-11-22  8:32 ` Ard Biesheuvel
  2019-11-22  8:32 ` [PATCH 3/6] ArmPkg/MmCommunicationDxe: expose MM Communicate " Ard Biesheuvel
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Ard Biesheuvel @ 2019-11-22  8:32 UTC (permalink / raw)
  To: devel; +Cc: leif.lindholm, Ard Biesheuvel, piwg, kimon.berlin, eugene

The MM communicate 2 protocol was introduced to factor out the mismatch
between traditional MM, which requires the physical address of the MM
buffer to be passed, and standalone MM, which copies the MM communicate
buffer data into a separate buffer, requiring the virtual address. For
this reason, MM communicate 2 carries both addresses, allowing the
implementation to decide which address it needs.

This hides this implementation detail from the callers of the protocol,
which simply passes both addresses without having to reason about what the
implementation of the protocol actually needs.

Note that the old version of the protocol is retained, in order to support
existing implementations that don't require this flexibility.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c   | 79 ++++++++++++++++++++
 MdeModulePkg/Core/PiSmmCore/PiSmmIpl.inf |  1 +
 2 files changed, 80 insertions(+)

diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c b/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c
index 1cf8c93227a3..d86b8b4a6a29 100644
--- a/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c
+++ b/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c
@@ -10,6 +10,7 @@
 
 #include <Protocol/SmmBase2.h>
 #include <Protocol/SmmCommunication.h>
+#include <Protocol/MmCommunication2.h>
 #include <Protocol/SmmAccess2.h>
 #include <Protocol/SmmConfiguration.h>
 #include <Protocol/SmmControl2.h>
@@ -118,6 +119,39 @@ SmmCommunicationCommunicate (
   IN OUT UINTN                             *CommSize OPTIONAL
   );
 
+/**
+  Communicates with a registered handler.
+
+  This function provides a service to send and receive messages from a registered UEFI service.
+
+  @param[in] This                The EFI_MM_COMMUNICATION_PROTOCOL instance.
+  @param[in] CommBufferPhysical  Physical address of the MM communication buffer
+  @param[in] CommBufferVirtual   Virtual address of the MM communication buffer
+  @param[in] CommSize            The size of the data buffer being passed in. On exit, the size of data
+                                 being returned. Zero if the handler does not wish to reply with any data.
+                                 This parameter is optional and may be NULL.
+
+  @retval EFI_SUCCESS            The message was successfully posted.
+  @retval EFI_INVALID_PARAMETER  The CommBuffer was NULL.
+  @retval EFI_BAD_BUFFER_SIZE    The buffer is too large for the MM implementation.
+                                 If this error is returned, the MessageLength field
+                                 in the CommBuffer header or the integer pointed by
+                                 CommSize, are updated to reflect the maximum payload
+                                 size the implementation can accommodate.
+  @retval EFI_ACCESS_DENIED      The CommunicateBuffer parameter or CommSize parameter,
+                                 if not omitted, are in address range that cannot be
+                                 accessed by the MM environment.
+
+**/
+EFI_STATUS
+EFIAPI
+SmmCommunicationMmCommunicate2 (
+  IN CONST EFI_MM_COMMUNICATION2_PROTOCOL   *This,
+  IN OUT VOID                               *CommBufferPhysical,
+  IN OUT VOID                               *CommBufferVirtual,
+  IN OUT UINTN                              *CommSize OPTIONAL
+  );
+
 /**
   Event notification that is fired every time a gEfiSmmConfigurationProtocol installs.
 
@@ -240,6 +274,13 @@ EFI_SMM_COMMUNICATION_PROTOCOL  mSmmCommunication = {
   SmmCommunicationCommunicate
 };
 
+//
+// PI 1.7 MM Communication Protocol 2 instance
+//
+EFI_MM_COMMUNICATION2_PROTOCOL  mMmCommunication2 = {
+  SmmCommunicationMmCommunicate2
+};
+
 //
 // SMM Core Private Data structure that contains the data shared between
 // the SMM IPL and the SMM Core.
@@ -576,6 +617,44 @@ SmmCommunicationCommunicate (
   return (Status == EFI_SUCCESS) ? EFI_SUCCESS : EFI_NOT_FOUND;
 }
 
+/**
+  Communicates with a registered handler.
+
+  This function provides a service to send and receive messages from a registered UEFI service.
+
+  @param[in] This                The EFI_MM_COMMUNICATION_PROTOCOL instance.
+  @param[in] CommBufferPhysical  Physical address of the MM communication buffer
+  @param[in] CommBufferVirtual   Virtual address of the MM communication buffer
+  @param[in] CommSize            The size of the data buffer being passed in. On exit, the size of data
+                                 being returned. Zero if the handler does not wish to reply with any data.
+                                 This parameter is optional and may be NULL.
+
+  @retval EFI_SUCCESS            The message was successfully posted.
+  @retval EFI_INVALID_PARAMETER  The CommBuffer was NULL.
+  @retval EFI_BAD_BUFFER_SIZE    The buffer is too large for the MM implementation.
+                                 If this error is returned, the MessageLength field
+                                 in the CommBuffer header or the integer pointed by
+                                 CommSize, are updated to reflect the maximum payload
+                                 size the implementation can accommodate.
+  @retval EFI_ACCESS_DENIED      The CommunicateBuffer parameter or CommSize parameter,
+                                 if not omitted, are in address range that cannot be
+                                 accessed by the MM environment.
+
+**/
+EFI_STATUS
+EFIAPI
+SmmCommunicationMmCommunicate2 (
+  IN CONST EFI_MM_COMMUNICATION2_PROTOCOL   *This,
+  IN OUT VOID                               *CommBufferPhysical,
+  IN OUT VOID                               *CommBufferVirtual,
+  IN OUT UINTN                              *CommSize OPTIONAL
+  )
+{
+  return SmmCommunicationCommunicate (&mSmmCommunication,
+                                      CommBufferPhysical,
+                                      CommSize);
+}
+
 /**
   Event notification that is fired when GUIDed Event Group is signaled.
 
diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.inf b/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.inf
index b6b1bbcdac51..0a05d593522e 100644
--- a/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.inf
+++ b/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.inf
@@ -50,6 +50,7 @@
 [Protocols]
   gEfiSmmBase2ProtocolGuid                      ## PRODUCES
   gEfiSmmCommunicationProtocolGuid              ## PRODUCES
+  gEfiMmCommunication2ProtocolGuid              ## PRODUCES
   gEfiSmmAccess2ProtocolGuid                    ## CONSUMES
   ## NOTIFY
   ## CONSUMES
-- 
2.20.1


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

* [PATCH 3/6] ArmPkg/MmCommunicationDxe: expose MM Communicate 2 protocol
  2019-11-22  8:32 [PATCH 0/6] PIWG M1993 - implement EFI_MM_COMMUNICATE2_PROTOCOL Ard Biesheuvel
  2019-11-22  8:32 ` [PATCH 1/6] MdePkg: introduce MM communicate 2 protocol Ard Biesheuvel
  2019-11-22  8:32 ` [PATCH 2/6] MdeModulePkg/SmmIpl: expose " Ard Biesheuvel
@ 2019-11-22  8:32 ` Ard Biesheuvel
  2019-11-22  8:32 ` [PATCH 4/6] MdeModulePkg/VariableInfo: switch to MM communicate " Ard Biesheuvel
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Ard Biesheuvel @ 2019-11-22  8:32 UTC (permalink / raw)
  To: devel; +Cc: leif.lindholm, Ard Biesheuvel, piwg, kimon.berlin, eugene

Implement the new MmCommunication2 protocol which supports the use
of standalone MM at runtime inside an address space that has been
virtually remapped by the OS.

Note that the implementation of the old MM Communicate protocol is
removed: it never worked correctly so there is no point in keeping it.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c   | 83 +++++++++-----------
 ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.inf |  6 +-
 2 files changed, 42 insertions(+), 47 deletions(-)

diff --git a/ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c b/ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c
index d06dcc4d2080..dc2af35f8617 100644
--- a/ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c
+++ b/ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c
@@ -1,6 +1,6 @@
 /** @file
 
-  Copyright (c) 2016-2018, ARM Limited. All rights reserved.
+  Copyright (c) 2016-2019, ARM Limited. All rights reserved.
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -16,7 +16,7 @@
 #include <Library/UefiBootServicesTableLib.h>
 #include <Library/UefiRuntimeServicesTableLib.h>
 
-#include <Protocol/MmCommunication.h>
+#include <Protocol/MmCommunication2.h>
 
 #include <IndustryStandard/ArmStdSmc.h>
 
@@ -39,39 +39,34 @@ STATIC EFI_HANDLE  mMmCommunicateHandle;
 /**
   Communicates with a registered handler.
 
-  This function provides an interface to send and receive messages to the
-  Standalone MM environment on behalf of UEFI services.  This function is part
-  of the MM Communication Protocol that may be called in physical mode prior to
-  SetVirtualAddressMap() and in virtual mode after SetVirtualAddressMap().
-
-  @param[in]      This                The EFI_MM_COMMUNICATION_PROTOCOL
-                                      instance.
-  @param[in, out] CommBuffer          A pointer to the buffer to convey
-                                      into MMRAM.
-  @param[in, out] CommSize            The size of the data buffer being
-                                      passed in. This is optional.
-
-  @retval EFI_SUCCESS                 The message was successfully posted.
-  @retval EFI_INVALID_PARAMETER       The CommBuffer was NULL.
-  @retval EFI_BAD_BUFFER_SIZE         The buffer size is incorrect for the MM
-                                      implementation. If this error is
-                                      returned, the MessageLength field in
-                                      the CommBuffer header or the integer
-                                      pointed by CommSize are updated to reflect
-                                      the maximum payload size the
-                                      implementation can accommodate.
-  @retval EFI_ACCESS_DENIED           The CommunicateBuffer parameter
-                                      or CommSize parameter, if not omitted,
-                                      are in address range that cannot be
-                                      accessed by the MM environment
+  This function provides a service to send and receive messages from a registered UEFI service.
+
+  @param[in] This                The EFI_MM_COMMUNICATION_PROTOCOL instance.
+  @param[in] CommBufferPhysical  Physical address of the MM communication buffer
+  @param[in] CommBufferVirtual   Virtual address of the MM communication buffer
+  @param[in] CommSize            The size of the data buffer being passed in. On exit, the size of data
+                                 being returned. Zero if the handler does not wish to reply with any data.
+                                 This parameter is optional and may be NULL.
+
+  @retval EFI_SUCCESS            The message was successfully posted.
+  @retval EFI_INVALID_PARAMETER  CommBufferPhysical was NULL or CommBufferVirtual was NULL.
+  @retval EFI_BAD_BUFFER_SIZE    The buffer is too large for the MM implementation.
+                                 If this error is returned, the MessageLength field
+                                 in the CommBuffer header or the integer pointed by
+                                 CommSize, are updated to reflect the maximum payload
+                                 size the implementation can accommodate.
+  @retval EFI_ACCESS_DENIED      The CommunicateBuffer parameter or CommSize parameter,
+                                 if not omitted, are in address range that cannot be
+                                 accessed by the MM environment.
+
 **/
-STATIC
 EFI_STATUS
 EFIAPI
-MmCommunicationCommunicate (
-  IN CONST EFI_MM_COMMUNICATION_PROTOCOL  *This,
-  IN OUT VOID                             *CommBuffer,
-  IN OUT UINTN                            *CommSize OPTIONAL
+MmCommunication2Communicate (
+  IN CONST EFI_MM_COMMUNICATION2_PROTOCOL   *This,
+  IN OUT VOID                               *CommBufferPhysical,
+  IN OUT VOID                               *CommBufferVirtual,
+  IN OUT UINTN                              *CommSize OPTIONAL
   )
 {
   EFI_MM_COMMUNICATE_HEADER   *CommunicateHeader;
@@ -87,11 +82,11 @@ MmCommunicationCommunicate (
   //
   // Check parameters
   //
-  if (CommBuffer == NULL) {
+  if (CommBufferVirtual == NULL) {
     return EFI_INVALID_PARAMETER;
   }
 
-  CommunicateHeader = CommBuffer;
+  CommunicateHeader = CommBufferVirtual;
   // CommBuffer is a mandatory parameter. Hence, Rely on
   // MessageLength + Header to ascertain the
   // total size of the communication payload rather than
@@ -136,7 +131,7 @@ MmCommunicationCommunicate (
   CommunicateSmcArgs.Arg1 = 0;
 
   // Copy Communication Payload
-  CopyMem ((VOID *)mNsCommBuffMemRegion.VirtualBase, CommBuffer, BufferSize);
+  CopyMem ((VOID *)mNsCommBuffMemRegion.VirtualBase, CommBufferVirtual, BufferSize);
 
   // comm_buffer_address (64-bit physical address)
   CommunicateSmcArgs.Arg2 = (UINTN)mNsCommBuffMemRegion.PhysicalBase;
@@ -149,7 +144,7 @@ MmCommunicationCommunicate (
 
   switch (CommunicateSmcArgs.Arg0) {
   case ARM_SMC_MM_RET_SUCCESS:
-    ZeroMem (CommBuffer, BufferSize);
+    ZeroMem (CommBufferVirtual, BufferSize);
     // On successful return, the size of data being returned is inferred from
     // MessageLength + Header.
     CommunicateHeader = (EFI_MM_COMMUNICATE_HEADER *)mNsCommBuffMemRegion.VirtualBase;
@@ -158,7 +153,7 @@ MmCommunicationCommunicate (
                  sizeof (CommunicateHeader->MessageLength);
 
     CopyMem (
-      CommBuffer,
+      CommBufferVirtual,
       (VOID *)mNsCommBuffMemRegion.VirtualBase,
       BufferSize
       );
@@ -191,8 +186,8 @@ MmCommunicationCommunicate (
 //
 // MM Communication Protocol instance
 //
-EFI_MM_COMMUNICATION_PROTOCOL  mMmCommunication = {
-  MmCommunicationCommunicate
+STATIC EFI_MM_COMMUNICATION2_PROTOCOL  mMmCommunication2 = {
+  MmCommunication2Communicate
 };
 
 /**
@@ -275,7 +270,7 @@ GetMmCompatibility ()
 **/
 EFI_STATUS
 EFIAPI
-MmCommunicationInitialize (
+MmCommunication2Initialize (
   IN EFI_HANDLE         ImageHandle,
   IN EFI_SYSTEM_TABLE  *SystemTable
   )
@@ -325,9 +320,9 @@ MmCommunicationInitialize (
   // Install the communication protocol
   Status = gBS->InstallProtocolInterface (
                   &mMmCommunicateHandle,
-                  &gEfiMmCommunicationProtocolGuid,
+                  &gEfiMmCommunication2ProtocolGuid,
                   EFI_NATIVE_INTERFACE,
-                  &mMmCommunication
+                  &mMmCommunication2
                   );
   if (EFI_ERROR(Status)) {
     DEBUG ((DEBUG_ERROR, "MmCommunicationInitialize: "
@@ -351,8 +346,8 @@ MmCommunicationInitialize (
 
   gBS->UninstallProtocolInterface (
          mMmCommunicateHandle,
-         &gEfiMmCommunicationProtocolGuid,
-         &mMmCommunication
+         &gEfiMmCommunication2ProtocolGuid,
+         &mMmCommunication2
          );
 
 CleanAddedMemorySpace:
diff --git a/ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.inf b/ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.inf
index 450fc9bb5414..9612cfbe5b6c 100644
--- a/ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.inf
+++ b/ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.inf
@@ -2,7 +2,7 @@
 #
 #  DXE MM Communicate driver
 #
-#  Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.
+#  Copyright (c) 2016 - 2019, ARM Limited. All rights reserved.
 #
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -14,7 +14,7 @@
   FILE_GUID                      = 09EE81D3-F15E-43F4-85B4-CB9873DA5D6B
   MODULE_TYPE                    = DXE_RUNTIME_DRIVER
   VERSION_STRING                 = 1.0
-  ENTRY_POINT                    = MmCommunicationInitialize
+  ENTRY_POINT                    = MmCommunication2Initialize
 
 #
 # The following is for reference only and not required by
@@ -40,7 +40,7 @@
   UefiDriverEntryPoint
 
 [Protocols]
-  gEfiMmCommunicationProtocolGuid              ## PRODUCES
+  gEfiMmCommunication2ProtocolGuid              ## PRODUCES
 
 [Pcd.common]
   gArmTokenSpaceGuid.PcdMmBufferBase
-- 
2.20.1


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

* [PATCH 4/6] MdeModulePkg/VariableInfo: switch to MM communicate 2 protocol
  2019-11-22  8:32 [PATCH 0/6] PIWG M1993 - implement EFI_MM_COMMUNICATE2_PROTOCOL Ard Biesheuvel
                   ` (2 preceding siblings ...)
  2019-11-22  8:32 ` [PATCH 3/6] ArmPkg/MmCommunicationDxe: expose MM Communicate " Ard Biesheuvel
@ 2019-11-22  8:32 ` Ard Biesheuvel
  2019-11-22  8:32 ` [PATCH 5/6] MdeModulePkg/FaultTolerantWriteSmmDxe: " Ard Biesheuvel
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Ard Biesheuvel @ 2019-11-22  8:32 UTC (permalink / raw)
  To: devel; +Cc: leif.lindholm, Ard Biesheuvel, piwg, kimon.berlin, eugene

Switch to the new MM communicate 2 protocol which supports both
traditional and standalone MM.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 MdeModulePkg/Application/VariableInfo/VariableInfo.c   | 19 +++++++++++--------
 MdeModulePkg/Application/VariableInfo/VariableInfo.inf |  2 +-
 2 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/MdeModulePkg/Application/VariableInfo/VariableInfo.c b/MdeModulePkg/Application/VariableInfo/VariableInfo.c
index c04ba182132f..a7df365b5895 100644
--- a/MdeModulePkg/Application/VariableInfo/VariableInfo.c
+++ b/MdeModulePkg/Application/VariableInfo/VariableInfo.c
@@ -20,10 +20,10 @@
 #include <Guid/VariableFormat.h>
 #include <Guid/SmmVariableCommon.h>
 #include <Guid/PiSmmCommunicationRegionTable.h>
-#include <Protocol/SmmCommunication.h>
+#include <Protocol/MmCommunication2.h>
 #include <Protocol/SmmVariable.h>
 
-EFI_SMM_COMMUNICATION_PROTOCOL  *mSmmCommunication = NULL;
+EFI_MM_COMMUNICATION2_PROTOCOL  *mMmCommunication2 = NULL;
 
 /**
   This function get the variable statistics data from SMM variable driver.
@@ -41,7 +41,7 @@ EFI_SMM_COMMUNICATION_PROTOCOL  *mSmmCommunication = NULL;
 EFI_STATUS
 EFIAPI
 GetVariableStatisticsData (
-  IN OUT  EFI_SMM_COMMUNICATE_HEADER  *SmmCommunicateHeader,
+  IN OUT  EFI_MM_COMMUNICATE_HEADER   *SmmCommunicateHeader,
   IN OUT  UINTN                       *SmmCommunicateSize
   )
 {
@@ -49,12 +49,15 @@ GetVariableStatisticsData (
   SMM_VARIABLE_COMMUNICATE_HEADER     *SmmVariableFunctionHeader;
 
   CopyGuid (&SmmCommunicateHeader->HeaderGuid, &gEfiSmmVariableProtocolGuid);
-  SmmCommunicateHeader->MessageLength = *SmmCommunicateSize - OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data);
+  SmmCommunicateHeader->MessageLength = *SmmCommunicateSize - OFFSET_OF (EFI_MM_COMMUNICATE_HEADER, Data);
 
   SmmVariableFunctionHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *) &SmmCommunicateHeader->Data[0];
   SmmVariableFunctionHeader->Function = SMM_VARIABLE_FUNCTION_GET_STATISTICS;
 
-  Status = mSmmCommunication->Communicate (mSmmCommunication, SmmCommunicateHeader, SmmCommunicateSize);
+  Status = mMmCommunication2->Communicate (mMmCommunication2,
+                                           SmmCommunicateHeader,
+                                           SmmCommunicateHeader,
+                                           SmmCommunicateSize);
   ASSERT_EFI_ERROR (Status);
 
   Status = SmmVariableFunctionHeader->ReturnStatus;
@@ -76,7 +79,7 @@ PrintInfoFromSmm (
 {
   EFI_STATUS                                     Status;
   VARIABLE_INFO_ENTRY                            *VariableInfo;
-  EFI_SMM_COMMUNICATE_HEADER                     *CommBuffer;
+  EFI_MM_COMMUNICATE_HEADER                      *CommBuffer;
   UINTN                                          RealCommSize;
   UINTN                                          CommSize;
   SMM_VARIABLE_COMMUNICATE_HEADER                *FunctionHeader;
@@ -92,7 +95,7 @@ PrintInfoFromSmm (
     return Status;
   }
 
-  Status = gBS->LocateProtocol (&gEfiSmmCommunicationProtocolGuid, NULL, (VOID **) &mSmmCommunication);
+  Status = gBS->LocateProtocol (&gEfiMmCommunication2ProtocolGuid, NULL, (VOID **) &mMmCommunication2);
   if (EFI_ERROR (Status)) {
     return Status;
   }
@@ -117,7 +120,7 @@ PrintInfoFromSmm (
         if (Size > MaxSize) {
           MaxSize = Size;
           RealCommSize = MaxSize;
-          CommBuffer = (EFI_SMM_COMMUNICATE_HEADER *) (UINTN) Entry->PhysicalStart;
+          CommBuffer = (EFI_MM_COMMUNICATE_HEADER *) (UINTN) Entry->PhysicalStart;
         }
       }
     }
diff --git a/MdeModulePkg/Application/VariableInfo/VariableInfo.inf b/MdeModulePkg/Application/VariableInfo/VariableInfo.inf
index 0706ea2ead59..f7c533b54641 100644
--- a/MdeModulePkg/Application/VariableInfo/VariableInfo.inf
+++ b/MdeModulePkg/Application/VariableInfo/VariableInfo.inf
@@ -41,7 +41,7 @@
   MemoryAllocationLib
 
 [Protocols]
-  gEfiSmmCommunicationProtocolGuid   ## SOMETIMES_CONSUMES
+  gEfiMmCommunication2ProtocolGuid   ## SOMETIMES_CONSUMES
 
   ## UNDEFINED            # Used to do smm communication
   ## SOMETIMES_CONSUMES
-- 
2.20.1


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

* [PATCH 5/6] MdeModulePkg/FaultTolerantWriteSmmDxe: switch to MM communicate 2 protocol
  2019-11-22  8:32 [PATCH 0/6] PIWG M1993 - implement EFI_MM_COMMUNICATE2_PROTOCOL Ard Biesheuvel
                   ` (3 preceding siblings ...)
  2019-11-22  8:32 ` [PATCH 4/6] MdeModulePkg/VariableInfo: switch to MM communicate " Ard Biesheuvel
@ 2019-11-22  8:32 ` Ard Biesheuvel
  2019-11-22  8:32 ` [PATCH 6/6] MdeModulePkg/VariableSmmRuntimeDxe: " Ard Biesheuvel
  2019-11-25 14:21 ` [edk2-devel] [PATCH 0/6] PIWG M1993 - implement EFI_MM_COMMUNICATE2_PROTOCOL Liming Gao
  6 siblings, 0 replies; 9+ messages in thread
From: Ard Biesheuvel @ 2019-11-22  8:32 UTC (permalink / raw)
  To: devel; +Cc: leif.lindholm, Ard Biesheuvel, piwg, kimon.berlin, eugene

Switch to the new MM communicate 2 protocol which supports both
traditional and standalone MM.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmCommon.h |  2 +-
 MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmDxe.c    | 25 +++++++++++---------
 MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmDxe.h    |  2 +-
 MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmDxe.inf  |  4 ++--
 4 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmCommon.h b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmCommon.h
index 4546a1b445b9..5f0eec0506ed 100644
--- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmCommon.h
+++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmCommon.h
@@ -29,7 +29,7 @@ typedef struct {
 ///
 /// Size of SMM communicate header, without including the payload.
 ///
-#define SMM_COMMUNICATE_HEADER_SIZE  (OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data))
+#define SMM_COMMUNICATE_HEADER_SIZE  (OFFSET_OF (EFI_MM_COMMUNICATE_HEADER, Data))
 
 ///
 /// Size of SMM FTW communicate function header, without including the payload.
diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmDxe.c b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmDxe.c
index 6e3eb3b58b09..24c20950296d 100644
--- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmDxe.c
+++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmDxe.c
@@ -11,7 +11,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 #include "FaultTolerantWriteSmmDxe.h"
 
 EFI_HANDLE                         mHandle                   = NULL;
-EFI_SMM_COMMUNICATION_PROTOCOL     *mSmmCommunication        = NULL;
+EFI_MM_COMMUNICATION2_PROTOCOL     *mMmCommunication2        = NULL;
 UINTN                              mPrivateDataSize          = 0;
 
 EFI_FAULT_TOLERANT_WRITE_PROTOCOL  mFaultTolerantWriteDriver = {
@@ -40,7 +40,7 @@ InitCommunicateBuffer (
   IN      UINTN                             Function
   )
 {
-  EFI_SMM_COMMUNICATE_HEADER                *SmmCommunicateHeader;
+  EFI_MM_COMMUNICATE_HEADER                 *SmmCommunicateHeader;
   SMM_FTW_COMMUNICATE_FUNCTION_HEADER       *SmmFtwFunctionHeader;
 
   //
@@ -74,7 +74,7 @@ InitCommunicateBuffer (
 **/
 EFI_STATUS
 SendCommunicateBuffer (
-  IN OUT  EFI_SMM_COMMUNICATE_HEADER        *SmmCommunicateHeader,
+  IN OUT  EFI_MM_COMMUNICATE_HEADER         *SmmCommunicateHeader,
   IN      UINTN                             DataSize
   )
 {
@@ -83,7 +83,10 @@ SendCommunicateBuffer (
   SMM_FTW_COMMUNICATE_FUNCTION_HEADER       *SmmFtwFunctionHeader;
 
   CommSize = DataSize + SMM_COMMUNICATE_HEADER_SIZE + SMM_FTW_COMMUNICATE_HEADER_SIZE;
-  Status = mSmmCommunication->Communicate (mSmmCommunication, SmmCommunicateHeader, &CommSize);
+  Status = mMmCommunication2->Communicate (mMmCommunication2,
+                                           SmmCommunicateHeader,
+                                           SmmCommunicateHeader,
+                                           &CommSize);
   ASSERT_EFI_ERROR (Status);
 
   SmmFtwFunctionHeader = (SMM_FTW_COMMUNICATE_FUNCTION_HEADER *) SmmCommunicateHeader->Data;
@@ -148,7 +151,7 @@ FtwGetMaxBlockSize (
 {
   EFI_STATUS                                Status;
   UINTN                                     PayloadSize;
-  EFI_SMM_COMMUNICATE_HEADER                *SmmCommunicateHeader;
+  EFI_MM_COMMUNICATE_HEADER                 *SmmCommunicateHeader;
   SMM_FTW_GET_MAX_BLOCK_SIZE_HEADER         *SmmFtwBlockSizeHeader;
 
   //
@@ -204,7 +207,7 @@ FtwAllocate (
 {
   EFI_STATUS                                Status;
   UINTN                                     PayloadSize;
-  EFI_SMM_COMMUNICATE_HEADER                *SmmCommunicateHeader;
+  EFI_MM_COMMUNICATE_HEADER                 *SmmCommunicateHeader;
   SMM_FTW_ALLOCATE_HEADER                   *SmmFtwAllocateHeader;
 
   //
@@ -270,7 +273,7 @@ FtwWrite (
 {
   EFI_STATUS                                Status;
   UINTN                                     PayloadSize;
-  EFI_SMM_COMMUNICATE_HEADER                *SmmCommunicateHeader;
+  EFI_MM_COMMUNICATE_HEADER                 *SmmCommunicateHeader;
   SMM_FTW_WRITE_HEADER                      *SmmFtwWriteHeader;
 
   //
@@ -336,7 +339,7 @@ FtwRestart (
 {
   EFI_STATUS                                Status;
   UINTN                                     PayloadSize;
-  EFI_SMM_COMMUNICATE_HEADER                *SmmCommunicateHeader;
+  EFI_MM_COMMUNICATE_HEADER                 *SmmCommunicateHeader;
   SMM_FTW_RESTART_HEADER                    *SmmFtwRestartHeader;
 
   //
@@ -381,7 +384,7 @@ FtwAbort (
   )
 {
   EFI_STATUS                                Status;
-  EFI_SMM_COMMUNICATE_HEADER                *SmmCommunicateHeader;
+  EFI_MM_COMMUNICATE_HEADER                 *SmmCommunicateHeader;
 
   //
   // Initialize the communicate buffer.
@@ -438,7 +441,7 @@ FtwGetLastWrite (
 {
   EFI_STATUS                                Status;
   UINTN                                     PayloadSize;
-  EFI_SMM_COMMUNICATE_HEADER                *SmmCommunicateHeader;
+  EFI_MM_COMMUNICATE_HEADER                 *SmmCommunicateHeader;
   SMM_FTW_GET_LAST_WRITE_HEADER             *SmmFtwGetLastWriteHeader;
 
   //
@@ -501,7 +504,7 @@ SmmFtwReady (
     return;
   }
 
-  Status = gBS->LocateProtocol (&gEfiSmmCommunicationProtocolGuid, NULL, (VOID **) &mSmmCommunication);
+  Status = gBS->LocateProtocol (&gEfiMmCommunication2ProtocolGuid, NULL, (VOID **) &mMmCommunication2);
   ASSERT_EFI_ERROR (Status);
 
   //
diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmDxe.h b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmDxe.h
index 22df9103d21a..a15644abd731 100644
--- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmDxe.h
+++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmDxe.h
@@ -13,7 +13,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 
 #include <PiDxe.h>
 
-#include <Protocol/SmmCommunication.h>
+#include <Protocol/MmCommunication2.h>
 
 #include <Library/UefiBootServicesTableLib.h>
 #include <Library/UefiDriverEntryPoint.h>
diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmDxe.inf b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmDxe.inf
index f5dc4bb4fee3..f0dd829653f1 100644
--- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmDxe.inf
+++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmDxe.inf
@@ -45,7 +45,7 @@
 
 [Protocols]
   gEfiFaultTolerantWriteProtocolGuid            ## PRODUCES
-  gEfiSmmCommunicationProtocolGuid              ## CONSUMES
+  gEfiMmCommunication2ProtocolGuid              ## CONSUMES
   ## NOTIFY
   ## UNDEFINED # Used to do smm communication
   ## CONSUMES
@@ -53,7 +53,7 @@
   gEfiFirmwareVolumeBlockProtocolGuid           ## CONSUMES
 
 [Depex]
-  gEfiSmmCommunicationProtocolGuid
+  gEfiMmCommunication2ProtocolGuid
 
 [UserExtensions.TianoCore."ExtraFiles"]
   FaultTolerantWriteSmmDxeExtra.uni
-- 
2.20.1


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

* [PATCH 6/6] MdeModulePkg/VariableSmmRuntimeDxe: switch to MM communicate 2 protocol
  2019-11-22  8:32 [PATCH 0/6] PIWG M1993 - implement EFI_MM_COMMUNICATE2_PROTOCOL Ard Biesheuvel
                   ` (4 preceding siblings ...)
  2019-11-22  8:32 ` [PATCH 5/6] MdeModulePkg/FaultTolerantWriteSmmDxe: " Ard Biesheuvel
@ 2019-11-22  8:32 ` Ard Biesheuvel
  2019-11-25 14:21 ` [edk2-devel] [PATCH 0/6] PIWG M1993 - implement EFI_MM_COMMUNICATE2_PROTOCOL Liming Gao
  6 siblings, 0 replies; 9+ messages in thread
From: Ard Biesheuvel @ 2019-11-22  8:32 UTC (permalink / raw)
  To: devel; +Cc: leif.lindholm, Ard Biesheuvel, piwg, kimon.berlin, eugene

Switch to the new MM communicate 2 protocol which supports both
traditional and standalone MM.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 MdeModulePkg/Include/Guid/SmmVariableCommon.h                        |  6 +--
 MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c   | 39 +++++++++++---------
 MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.inf |  4 +-
 3 files changed, 26 insertions(+), 23 deletions(-)

diff --git a/MdeModulePkg/Include/Guid/SmmVariableCommon.h b/MdeModulePkg/Include/Guid/SmmVariableCommon.h
index ceef44dfd2d7..8ddc94b92da6 100644
--- a/MdeModulePkg/Include/Guid/SmmVariableCommon.h
+++ b/MdeModulePkg/Include/Guid/SmmVariableCommon.h
@@ -20,7 +20,7 @@ extern EFI_GUID gSmmVariableWriteGuid;
 //
 // This structure is used for SMM variable. the collected statistics data is saved in SMRAM. It can be got from
 // SMI handler. The communication buffer should be:
-// EFI_SMM_COMMUNICATE_HEADER + SMM_VARIABLE_COMMUNICATE_HEADER + payload.
+// EFI_MM_COMMUNICATE_HEADER + SMM_VARIABLE_COMMUNICATE_HEADER + payload.
 //
 typedef struct {
   UINTN       Function;
@@ -53,7 +53,7 @@ typedef struct {
 //
 #define SMM_VARIABLE_FUNCTION_EXIT_BOOT_SERVICE       6
 //
-// The payload for this function is VARIABLE_INFO_ENTRY. The GUID in EFI_SMM_COMMUNICATE_HEADER
+// The payload for this function is VARIABLE_INFO_ENTRY. The GUID in EFI_MM_COMMUNICATE_HEADER
 // is gEfiSmmVariableProtocolGuid.
 //
 #define SMM_VARIABLE_FUNCTION_GET_STATISTICS          7
@@ -81,7 +81,7 @@ typedef struct {
 ///
 /// Size of SMM communicate header, without including the payload.
 ///
-#define SMM_COMMUNICATE_HEADER_SIZE  (OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data))
+#define SMM_COMMUNICATE_HEADER_SIZE  (OFFSET_OF (EFI_MM_COMMUNICATE_HEADER, Data))
 
 ///
 /// Size of SMM variable communicate header, without including the payload.
diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c
index d525998ae301..f49e4a9664ae 100644
--- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c
+++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c
@@ -20,7 +20,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 #include <PiDxe.h>
 #include <Protocol/VariableWrite.h>
 #include <Protocol/Variable.h>
-#include <Protocol/SmmCommunication.h>
+#include <Protocol/MmCommunication2.h>
 #include <Protocol/SmmVariable.h>
 #include <Protocol/VariableLock.h>
 #include <Protocol/VarCheck.h>
@@ -44,7 +44,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 EFI_HANDLE                       mHandle                    = NULL;
 EFI_SMM_VARIABLE_PROTOCOL       *mSmmVariable               = NULL;
 EFI_EVENT                        mVirtualAddressChangeEvent = NULL;
-EFI_SMM_COMMUNICATION_PROTOCOL  *mSmmCommunication          = NULL;
+EFI_MM_COMMUNICATION2_PROTOCOL  *mMmCommunication2          = NULL;
 UINT8                           *mVariableBuffer            = NULL;
 UINT8                           *mVariableBufferPhysical    = NULL;
 VARIABLE_INFO_ENTRY             *mVariableInfo              = NULL;
@@ -209,7 +209,7 @@ InitCommunicateBuffer (
   IN      UINTN                             Function
   )
 {
-  EFI_SMM_COMMUNICATE_HEADER                *SmmCommunicateHeader;
+  EFI_MM_COMMUNICATE_HEADER                 *SmmCommunicateHeader;
   SMM_VARIABLE_COMMUNICATE_HEADER           *SmmVariableFunctionHeader;
 
 
@@ -217,7 +217,7 @@ InitCommunicateBuffer (
     return EFI_INVALID_PARAMETER;
   }
 
-  SmmCommunicateHeader = (EFI_SMM_COMMUNICATE_HEADER *) mVariableBuffer;
+  SmmCommunicateHeader = (EFI_MM_COMMUNICATE_HEADER *) mVariableBuffer;
   CopyGuid (&SmmCommunicateHeader->HeaderGuid, &gEfiSmmVariableProtocolGuid);
   SmmCommunicateHeader->MessageLength = DataSize + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE;
 
@@ -247,14 +247,17 @@ SendCommunicateBuffer (
 {
   EFI_STATUS                                Status;
   UINTN                                     CommSize;
-  EFI_SMM_COMMUNICATE_HEADER                *SmmCommunicateHeader;
+  EFI_MM_COMMUNICATE_HEADER                 *SmmCommunicateHeader;
   SMM_VARIABLE_COMMUNICATE_HEADER           *SmmVariableFunctionHeader;
 
   CommSize = DataSize + SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE;
-  Status = mSmmCommunication->Communicate (mSmmCommunication, mVariableBufferPhysical, &CommSize);
+  Status = mMmCommunication2->Communicate (mMmCommunication2,
+                                           mVariableBufferPhysical,
+                                           mVariableBuffer,
+                                           &CommSize);
   ASSERT_EFI_ERROR (Status);
 
-  SmmCommunicateHeader      = (EFI_SMM_COMMUNICATE_HEADER *) mVariableBuffer;
+  SmmCommunicateHeader      = (EFI_MM_COMMUNICATE_HEADER *) mVariableBuffer;
   SmmVariableFunctionHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *)SmmCommunicateHeader->Data;
   return  SmmVariableFunctionHeader->ReturnStatus;
 }
@@ -1305,7 +1308,7 @@ VariableAddressChangeEvent (
   )
 {
   EfiConvertPointer (0x0, (VOID **) &mVariableBuffer);
-  EfiConvertPointer (0x0, (VOID **) &mSmmCommunication);
+  EfiConvertPointer (0x0, (VOID **) &mMmCommunication2);
   EfiConvertPointer (EFI_OPTIONAL_PTR, (VOID **) &mVariableRuntimeHobCacheBuffer);
   EfiConvertPointer (EFI_OPTIONAL_PTR, (VOID **) &mVariableRuntimeNvCacheBuffer);
   EfiConvertPointer (EFI_OPTIONAL_PTR, (VOID **) &mVariableRuntimeVolatileCacheBuffer);
@@ -1328,7 +1331,7 @@ GetVariablePayloadSize (
 {
   EFI_STATUS                                Status;
   SMM_VARIABLE_COMMUNICATE_GET_PAYLOAD_SIZE *SmmGetPayloadSize;
-  EFI_SMM_COMMUNICATE_HEADER                *SmmCommunicateHeader;
+  EFI_MM_COMMUNICATE_HEADER                 *SmmCommunicateHeader;
   SMM_VARIABLE_COMMUNICATE_HEADER           *SmmVariableFunctionHeader;
   UINTN                                     CommSize;
   UINT8                                     *CommBuffer;
@@ -1353,7 +1356,7 @@ GetVariablePayloadSize (
     goto Done;
   }
 
-  SmmCommunicateHeader = (EFI_SMM_COMMUNICATE_HEADER *) CommBuffer;
+  SmmCommunicateHeader = (EFI_MM_COMMUNICATE_HEADER *) CommBuffer;
   CopyGuid (&SmmCommunicateHeader->HeaderGuid, &gEfiSmmVariableProtocolGuid);
   SmmCommunicateHeader->MessageLength = SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + sizeof (SMM_VARIABLE_COMMUNICATE_GET_PAYLOAD_SIZE);
 
@@ -1364,7 +1367,7 @@ GetVariablePayloadSize (
   //
   // Send data to SMM.
   //
-  Status = mSmmCommunication->Communicate (mSmmCommunication, CommBuffer, &CommSize);
+  Status = mMmCommunication2->Communicate (mMmCommunication2, CommBuffer, CommBuffer, &CommSize);
   ASSERT_EFI_ERROR (Status);
 
   Status = SmmVariableFunctionHeader->ReturnStatus;
@@ -1409,7 +1412,7 @@ GetRuntimeCacheInfo (
 {
   EFI_STATUS                                          Status;
   SMM_VARIABLE_COMMUNICATE_GET_RUNTIME_CACHE_INFO     *SmmGetRuntimeCacheInfo;
-  EFI_SMM_COMMUNICATE_HEADER                          *SmmCommunicateHeader;
+  EFI_MM_COMMUNICATE_HEADER                           *SmmCommunicateHeader;
   SMM_VARIABLE_COMMUNICATE_HEADER                     *SmmVariableFunctionHeader;
   UINTN                                               CommSize;
   UINT8                                               *CommBuffer;
@@ -1430,7 +1433,7 @@ GetRuntimeCacheInfo (
   CommSize = SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + sizeof (SMM_VARIABLE_COMMUNICATE_GET_RUNTIME_CACHE_INFO);
   ZeroMem (CommBuffer, CommSize);
 
-  SmmCommunicateHeader = (EFI_SMM_COMMUNICATE_HEADER *) CommBuffer;
+  SmmCommunicateHeader = (EFI_MM_COMMUNICATE_HEADER *) CommBuffer;
   CopyGuid (&SmmCommunicateHeader->HeaderGuid, &gEfiSmmVariableProtocolGuid);
   SmmCommunicateHeader->MessageLength = SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + sizeof (SMM_VARIABLE_COMMUNICATE_GET_RUNTIME_CACHE_INFO);
 
@@ -1441,7 +1444,7 @@ GetRuntimeCacheInfo (
   //
   // Send data to SMM.
   //
-  Status = mSmmCommunication->Communicate (mSmmCommunication, CommBuffer, &CommSize);
+  Status = mMmCommunication2->Communicate (mMmCommunication2, CommBuffer, CommBuffer, &CommSize);
   ASSERT_EFI_ERROR (Status);
   if (CommSize <= SMM_VARIABLE_COMMUNICATE_HEADER_SIZE) {
     Status = EFI_BAD_BUFFER_SIZE;
@@ -1482,7 +1485,7 @@ SendRuntimeVariableCacheContextToSmm (
 {
   EFI_STATUS                                                Status;
   SMM_VARIABLE_COMMUNICATE_RUNTIME_VARIABLE_CACHE_CONTEXT   *SmmRuntimeVarCacheContext;
-  EFI_SMM_COMMUNICATE_HEADER                                *SmmCommunicateHeader;
+  EFI_MM_COMMUNICATE_HEADER                                 *SmmCommunicateHeader;
   SMM_VARIABLE_COMMUNICATE_HEADER                           *SmmVariableFunctionHeader;
   UINTN                                                     CommSize;
   UINT8                                                     *CommBuffer;
@@ -1503,7 +1506,7 @@ SendRuntimeVariableCacheContextToSmm (
   CommSize = SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + sizeof (SMM_VARIABLE_COMMUNICATE_RUNTIME_VARIABLE_CACHE_CONTEXT);
   ZeroMem (CommBuffer, CommSize);
 
-  SmmCommunicateHeader = (EFI_SMM_COMMUNICATE_HEADER *) CommBuffer;
+  SmmCommunicateHeader = (EFI_MM_COMMUNICATE_HEADER *) CommBuffer;
   CopyGuid (&SmmCommunicateHeader->HeaderGuid, &gEfiSmmVariableProtocolGuid);
   SmmCommunicateHeader->MessageLength = SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + sizeof (SMM_VARIABLE_COMMUNICATE_RUNTIME_VARIABLE_CACHE_CONTEXT);
 
@@ -1521,7 +1524,7 @@ SendRuntimeVariableCacheContextToSmm (
   //
   // Send data to SMM.
   //
-  Status = mSmmCommunication->Communicate (mSmmCommunication, CommBuffer, &CommSize);
+  Status = mMmCommunication2->Communicate (mMmCommunication2, CommBuffer, CommBuffer, &CommSize);
   ASSERT_EFI_ERROR (Status);
   if (CommSize <= SMM_VARIABLE_COMMUNICATE_HEADER_SIZE) {
     Status = EFI_BAD_BUFFER_SIZE;
@@ -1559,7 +1562,7 @@ SmmVariableReady (
     return;
   }
 
-  Status = gBS->LocateProtocol (&gEfiSmmCommunicationProtocolGuid, NULL, (VOID **) &mSmmCommunication);
+  Status = gBS->LocateProtocol (&gEfiMmCommunication2ProtocolGuid, NULL, (VOID **) &mMmCommunication2);
   ASSERT_EFI_ERROR (Status);
 
   //
diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.inf b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.inf
index a250533a534f..0f3ec6a9a43d 100644
--- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.inf
+++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.inf
@@ -59,7 +59,7 @@
 [Protocols]
   gEfiVariableWriteArchProtocolGuid             ## PRODUCES
   gEfiVariableArchProtocolGuid                  ## PRODUCES
-  gEfiSmmCommunicationProtocolGuid              ## CONSUMES
+  gEfiMmCommunication2ProtocolGuid              ## CONSUMES
   ## CONSUMES
   ## NOTIFY
   ## UNDEFINED # Used to do smm communication
@@ -99,7 +99,7 @@
   gEfiImageSecurityDatabaseGuid
 
 [Depex]
-  gEfiSmmCommunicationProtocolGuid
+  gEfiMmCommunication2ProtocolGuid
 
 [UserExtensions.TianoCore."ExtraFiles"]
   VariableSmmRuntimeDxeExtra.uni
-- 
2.20.1


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

* Re: [edk2-devel] [PATCH 0/6] PIWG M1993 - implement EFI_MM_COMMUNICATE2_PROTOCOL
  2019-11-22  8:32 [PATCH 0/6] PIWG M1993 - implement EFI_MM_COMMUNICATE2_PROTOCOL Ard Biesheuvel
                   ` (5 preceding siblings ...)
  2019-11-22  8:32 ` [PATCH 6/6] MdeModulePkg/VariableSmmRuntimeDxe: " Ard Biesheuvel
@ 2019-11-25 14:21 ` Liming Gao
  2019-11-25 14:52   ` Ard Biesheuvel
  6 siblings, 1 reply; 9+ messages in thread
From: Liming Gao @ 2019-11-25 14:21 UTC (permalink / raw)
  To: devel@edk2.groups.io, ard.biesheuvel@linaro.org
  Cc: leif.lindholm@linaro.org, piwg@uefi.org, kimon.berlin@hp.com,
	eugene@hp.com

Ard:
  This change is about new protocol in 1.7 errata A of the PI spec. But, PI 1.7 errata A is not published yet. So, this patch set is for edk2-staging first?

  I review the code logic. For SMM part, SmmIpl still installs current SmmCommunication protocol. So, this change is totally compatible. Right?

Thanks
Liming
> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Ard Biesheuvel
> Sent: Friday, November 22, 2019 4:32 PM
> To: devel@edk2.groups.io
> Cc: leif.lindholm@linaro.org; Ard Biesheuvel <ard.biesheuvel@linaro.org>; piwg@uefi.org; kimon.berlin@hp.com; eugene@hp.com
> Subject: [edk2-devel] [PATCH 0/6] PIWG M1993 - implement EFI_MM_COMMUNICATE2_PROTOCOL
> 
> As discussed in the PIWG call on 21 November, I am sending out my
> implementation of the MM communicate 2 protocol for review. It is
> intended to work around the impedance mismatch between traditional
> SMM (which uses physical addresses in the communication between DXE
> components) and standalone MM (which uses virtual addresses)
> 
> The solution presented here is to introduce a new protocol that takes
> both addresses, forcing the clients to pass both, but freeing them
> from the responsibility to reason about which kind of address to pass:
> this becomes the responsibility of the MM_COMMUNICATE implementation,
> which is where it belongs.
> 
> Cc: piwg@uefi.org
> Cc: kimon.berlin@hp.com
> Cc: eugene@hp.com
> 
> Ard Biesheuvel (6):
>   MdePkg: introduce MM communicate 2 protocol
>   MdeModulePkg/SmmIpl: expose MM communicate 2 protocol
>   ArmPkg/MmCommunicationDxe: expose MM Communicate 2 protocol
>   MdeModulePkg/VariableInfo: switch to MM communicate 2 protocol
>   MdeModulePkg/FaultTolerantWriteSmmDxe: switch to MM communicate 2
>     protocol
>   MdeModulePkg/VariableSmmRuntimeDxe: switch to MM communicate 2
>     protocol
> 
>  ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c                        | 83 +++++++++-----------
>  ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.inf                      |  6 +-
>  MdeModulePkg/Application/VariableInfo/VariableInfo.c                       | 19 +++--
>  MdeModulePkg/Application/VariableInfo/VariableInfo.inf                     |  2 +-
>  MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c                                     | 79 +++++++++++++++++++
>  MdeModulePkg/Core/PiSmmCore/PiSmmIpl.inf                                   |  1 +
>  MdeModulePkg/Include/Guid/SmmVariableCommon.h                              |  6 +-
>  MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmCommon.h |  2 +-
>  MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmDxe.c    | 25 +++---
>  MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmDxe.h    |  2 +-
>  MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmDxe.inf  |  4 +-
>  MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c         | 39 ++++-----
>  MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.inf       |  4 +-
>  MdePkg/Include/Protocol/MmCommunication2.h                                 | 69 ++++++++++++++++
>  MdePkg/MdePkg.dec                                                          |  7 ++
>  15 files changed, 254 insertions(+), 94 deletions(-)
>  create mode 100644 MdePkg/Include/Protocol/MmCommunication2.h
> 
> --
> 2.20.1
> 
> 
> 


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

* Re: [edk2-devel] [PATCH 0/6] PIWG M1993 - implement EFI_MM_COMMUNICATE2_PROTOCOL
  2019-11-25 14:21 ` [edk2-devel] [PATCH 0/6] PIWG M1993 - implement EFI_MM_COMMUNICATE2_PROTOCOL Liming Gao
@ 2019-11-25 14:52   ` Ard Biesheuvel
  0 siblings, 0 replies; 9+ messages in thread
From: Ard Biesheuvel @ 2019-11-25 14:52 UTC (permalink / raw)
  To: Gao, Liming
  Cc: devel@edk2.groups.io, leif.lindholm@linaro.org, piwg@uefi.org,
	kimon.berlin@hp.com, eugene@hp.com

On Mon, 25 Nov 2019 at 15:21, Gao, Liming <liming.gao@intel.com> wrote:
>
> Ard:
>   This change is about new protocol in 1.7 errata A of the PI spec. But, PI 1.7 errata A is not published yet. So, this patch set is for edk2-staging first?
>

Not sure if it needs to go to staging. The patches are on the list,
and once we are ready to merge them, I will repost them with the
appropriate maintainers on cc. This posting was mostly for discussion
purpo

>   I review the code logic. For SMM part, SmmIpl still installs current SmmCommunication protocol. So, this change is totally compatible. Right?
>

Yes. SmmIpl will expose both the old and the new protocol, and some
clients of this protocol are getting updated so they can be shared
with standalone MM implementations. When we are ready to consider
these changes for merging, I will include some test reports on both
types of implementations.



> > -----Original Message-----
> > From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Ard Biesheuvel
> > Sent: Friday, November 22, 2019 4:32 PM
> > To: devel@edk2.groups.io
> > Cc: leif.lindholm@linaro.org; Ard Biesheuvel <ard.biesheuvel@linaro.org>; piwg@uefi.org; kimon.berlin@hp.com; eugene@hp.com
> > Subject: [edk2-devel] [PATCH 0/6] PIWG M1993 - implement EFI_MM_COMMUNICATE2_PROTOCOL
> >
> > As discussed in the PIWG call on 21 November, I am sending out my
> > implementation of the MM communicate 2 protocol for review. It is
> > intended to work around the impedance mismatch between traditional
> > SMM (which uses physical addresses in the communication between DXE
> > components) and standalone MM (which uses virtual addresses)
> >
> > The solution presented here is to introduce a new protocol that takes
> > both addresses, forcing the clients to pass both, but freeing them
> > from the responsibility to reason about which kind of address to pass:
> > this becomes the responsibility of the MM_COMMUNICATE implementation,
> > which is where it belongs.
> >
> > Cc: piwg@uefi.org
> > Cc: kimon.berlin@hp.com
> > Cc: eugene@hp.com
> >
> > Ard Biesheuvel (6):
> >   MdePkg: introduce MM communicate 2 protocol
> >   MdeModulePkg/SmmIpl: expose MM communicate 2 protocol
> >   ArmPkg/MmCommunicationDxe: expose MM Communicate 2 protocol
> >   MdeModulePkg/VariableInfo: switch to MM communicate 2 protocol
> >   MdeModulePkg/FaultTolerantWriteSmmDxe: switch to MM communicate 2
> >     protocol
> >   MdeModulePkg/VariableSmmRuntimeDxe: switch to MM communicate 2
> >     protocol
> >
> >  ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c                        | 83 +++++++++-----------
> >  ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.inf                      |  6 +-
> >  MdeModulePkg/Application/VariableInfo/VariableInfo.c                       | 19 +++--
> >  MdeModulePkg/Application/VariableInfo/VariableInfo.inf                     |  2 +-
> >  MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c                                     | 79 +++++++++++++++++++
> >  MdeModulePkg/Core/PiSmmCore/PiSmmIpl.inf                                   |  1 +
> >  MdeModulePkg/Include/Guid/SmmVariableCommon.h                              |  6 +-
> >  MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmCommon.h |  2 +-
> >  MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmDxe.c    | 25 +++---
> >  MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmDxe.h    |  2 +-
> >  MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmDxe.inf  |  4 +-
> >  MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c         | 39 ++++-----
> >  MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.inf       |  4 +-
> >  MdePkg/Include/Protocol/MmCommunication2.h                                 | 69 ++++++++++++++++
> >  MdePkg/MdePkg.dec                                                          |  7 ++
> >  15 files changed, 254 insertions(+), 94 deletions(-)
> >  create mode 100644 MdePkg/Include/Protocol/MmCommunication2.h
> >
> > --
> > 2.20.1
> >
> >
> > 
>

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

end of thread, other threads:[~2019-11-25 14:52 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-11-22  8:32 [PATCH 0/6] PIWG M1993 - implement EFI_MM_COMMUNICATE2_PROTOCOL Ard Biesheuvel
2019-11-22  8:32 ` [PATCH 1/6] MdePkg: introduce MM communicate 2 protocol Ard Biesheuvel
2019-11-22  8:32 ` [PATCH 2/6] MdeModulePkg/SmmIpl: expose " Ard Biesheuvel
2019-11-22  8:32 ` [PATCH 3/6] ArmPkg/MmCommunicationDxe: expose MM Communicate " Ard Biesheuvel
2019-11-22  8:32 ` [PATCH 4/6] MdeModulePkg/VariableInfo: switch to MM communicate " Ard Biesheuvel
2019-11-22  8:32 ` [PATCH 5/6] MdeModulePkg/FaultTolerantWriteSmmDxe: " Ard Biesheuvel
2019-11-22  8:32 ` [PATCH 6/6] MdeModulePkg/VariableSmmRuntimeDxe: " Ard Biesheuvel
2019-11-25 14:21 ` [edk2-devel] [PATCH 0/6] PIWG M1993 - implement EFI_MM_COMMUNICATE2_PROTOCOL Liming Gao
2019-11-25 14:52   ` Ard Biesheuvel

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