]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c
ArmPkg/MmCommunicationDxe: expose MM Communicate 2 protocol
[mirror_edk2.git] / ArmPkg / Drivers / MmCommunicationDxe / MmCommunication.c
index a9e06be1adc2d60e84e4ea9d91f558891c98db53..9457eaf1d809224a64b0225960f6f3ae083dbb4b 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
-  Copyright (c) 2016-2018, ARM Limited. All rights reserved.\r
+  Copyright (c) 2016-2019, ARM Limited. All rights reserved.\r
 \r
   SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
@@ -16,7 +16,7 @@
 #include <Library/UefiBootServicesTableLib.h>\r
 #include <Library/UefiRuntimeServicesTableLib.h>\r
 \r
-#include <Protocol/MmCommunication.h>\r
+#include <Protocol/MmCommunication2.h>\r
 \r
 #include <IndustryStandard/ArmStdSmc.h>\r
 \r
@@ -39,39 +39,34 @@ STATIC EFI_HANDLE  mMmCommunicateHandle;
 /**\r
   Communicates with a registered handler.\r
 \r
-  This function provides an interface to send and receive messages to the\r
-  Standalone MM environment on behalf of UEFI services.  This function is part\r
-  of the MM Communication Protocol that may be called in physical mode prior to\r
-  SetVirtualAddressMap() and in virtual mode after SetVirtualAddressMap().\r
-\r
-  @param[in]      This                The EFI_MM_COMMUNICATION_PROTOCOL\r
-                                      instance.\r
-  @param[in, out] CommBuffer          A pointer to the buffer to convey\r
-                                      into MMRAM.\r
-  @param[in, out] CommSize            The size of the data buffer being\r
-                                      passed in. This is optional.\r
-\r
-  @retval EFI_SUCCESS                 The message was successfully posted.\r
-  @retval EFI_INVALID_PARAMETER       The CommBuffer was NULL.\r
-  @retval EFI_BAD_BUFFER_SIZE         The buffer size is incorrect for the MM\r
-                                      implementation. If this error is\r
-                                      returned, the MessageLength field in\r
-                                      the CommBuffer header or the integer\r
-                                      pointed by CommSize are updated to reflect\r
-                                      the maximum payload size the\r
-                                      implementation can accommodate.\r
-  @retval EFI_ACCESS_DENIED           The CommunicateBuffer parameter\r
-                                      or CommSize parameter, if not omitted,\r
-                                      are in address range that cannot be\r
-                                      accessed by the MM environment\r
+  This function provides a service to send and receive messages from a registered UEFI service.\r
+\r
+  @param[in] This                The EFI_MM_COMMUNICATION_PROTOCOL instance.\r
+  @param[in] CommBufferPhysical  Physical address of the MM communication buffer\r
+  @param[in] CommBufferVirtual   Virtual address of the MM communication buffer\r
+  @param[in] CommSize            The size of the data buffer being passed in. On exit, the size of data\r
+                                 being returned. Zero if the handler does not wish to reply with any data.\r
+                                 This parameter is optional and may be NULL.\r
+\r
+  @retval EFI_SUCCESS            The message was successfully posted.\r
+  @retval EFI_INVALID_PARAMETER  CommBufferPhysical was NULL or CommBufferVirtual was NULL.\r
+  @retval EFI_BAD_BUFFER_SIZE    The buffer is too large for the MM implementation.\r
+                                 If this error is returned, the MessageLength field\r
+                                 in the CommBuffer header or the integer pointed by\r
+                                 CommSize, are updated to reflect the maximum payload\r
+                                 size the implementation can accommodate.\r
+  @retval EFI_ACCESS_DENIED      The CommunicateBuffer parameter or CommSize parameter,\r
+                                 if not omitted, are in address range that cannot be\r
+                                 accessed by the MM environment.\r
+\r
 **/\r
-STATIC\r
 EFI_STATUS\r
 EFIAPI\r
-MmCommunicationCommunicate (\r
-  IN CONST EFI_MM_COMMUNICATION_PROTOCOL  *This,\r
-  IN OUT VOID                             *CommBuffer,\r
-  IN OUT UINTN                            *CommSize OPTIONAL\r
+MmCommunication2Communicate (\r
+  IN CONST EFI_MM_COMMUNICATION2_PROTOCOL   *This,\r
+  IN OUT VOID                               *CommBufferPhysical,\r
+  IN OUT VOID                               *CommBufferVirtual,\r
+  IN OUT UINTN                              *CommSize OPTIONAL\r
   )\r
 {\r
   EFI_MM_COMMUNICATE_HEADER   *CommunicateHeader;\r
@@ -87,11 +82,11 @@ MmCommunicationCommunicate (
   //\r
   // Check parameters\r
   //\r
-  if (CommBuffer == NULL) {\r
+  if (CommBufferVirtual == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  CommunicateHeader = CommBuffer;\r
+  CommunicateHeader = CommBufferVirtual;\r
   // CommBuffer is a mandatory parameter. Hence, Rely on\r
   // MessageLength + Header to ascertain the\r
   // total size of the communication payload rather than\r
@@ -136,7 +131,7 @@ MmCommunicationCommunicate (
   CommunicateSmcArgs.Arg1 = 0;\r
 \r
   // Copy Communication Payload\r
-  CopyMem ((VOID *)mNsCommBuffMemRegion.VirtualBase, CommBuffer, BufferSize);\r
+  CopyMem ((VOID *)mNsCommBuffMemRegion.VirtualBase, CommBufferVirtual, BufferSize);\r
 \r
   // comm_buffer_address (64-bit physical address)\r
   CommunicateSmcArgs.Arg2 = (UINTN)mNsCommBuffMemRegion.PhysicalBase;\r
@@ -149,7 +144,7 @@ MmCommunicationCommunicate (
 \r
   switch (CommunicateSmcArgs.Arg0) {\r
   case ARM_SMC_MM_RET_SUCCESS:\r
-    ZeroMem (CommBuffer, BufferSize);\r
+    ZeroMem (CommBufferVirtual, BufferSize);\r
     // On successful return, the size of data being returned is inferred from\r
     // MessageLength + Header.\r
     CommunicateHeader = (EFI_MM_COMMUNICATE_HEADER *)mNsCommBuffMemRegion.VirtualBase;\r
@@ -158,7 +153,7 @@ MmCommunicationCommunicate (
                  sizeof (CommunicateHeader->MessageLength);\r
 \r
     CopyMem (\r
-      CommBuffer,\r
+      CommBufferVirtual,\r
       (VOID *)mNsCommBuffMemRegion.VirtualBase,\r
       BufferSize\r
       );\r
@@ -191,8 +186,8 @@ MmCommunicationCommunicate (
 //\r
 // MM Communication Protocol instance\r
 //\r
-EFI_MM_COMMUNICATION_PROTOCOL  mMmCommunication = {\r
-  MmCommunicationCommunicate\r
+STATIC EFI_MM_COMMUNICATION2_PROTOCOL  mMmCommunication2 = {\r
+  MmCommunication2Communicate\r
 };\r
 \r
 /**\r
@@ -293,7 +288,7 @@ MmGuidedEventNotify (
   Header.Data[0] = 0;\r
 \r
   Size = sizeof (Header);\r
-  MmCommunicationCommunicate (&mMmCommunication, &Header, &Size);\r
+  MmCommunication2Communicate (&mMmCommunication2, &Header, &Header, &Size);\r
 }\r
 \r
 /**\r
@@ -312,7 +307,7 @@ MmGuidedEventNotify (
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-MmCommunicationInitialize (\r
+MmCommunication2Initialize (\r
   IN EFI_HANDLE         ImageHandle,\r
   IN EFI_SYSTEM_TABLE  *SystemTable\r
   )\r
@@ -363,9 +358,9 @@ MmCommunicationInitialize (
   // Install the communication protocol\r
   Status = gBS->InstallProtocolInterface (\r
                   &mMmCommunicateHandle,\r
-                  &gEfiMmCommunicationProtocolGuid,\r
+                  &gEfiMmCommunication2ProtocolGuid,\r
                   EFI_NATIVE_INTERFACE,\r
-                  &mMmCommunication\r
+                  &mMmCommunication2\r
                   );\r
   if (EFI_ERROR(Status)) {\r
     DEBUG ((DEBUG_ERROR, "MmCommunicationInitialize: "\r
@@ -402,8 +397,8 @@ MmCommunicationInitialize (
 UninstallProtocol:\r
   gBS->UninstallProtocolInterface (\r
          mMmCommunicateHandle,\r
-         &gEfiMmCommunicationProtocolGuid,\r
-         &mMmCommunication\r
+         &gEfiMmCommunication2ProtocolGuid,\r
+         &mMmCommunication2\r
          );\r
 \r
 CleanAddedMemorySpace:\r