[edk2,1/4] MdeModulePkg: introduce MmCommunicationLib library class

Message ID 20190311153608.3251-2-ard.biesheuvel@linaro.org
State New
Headers show
Series
  • MdeModulePkg, StandaloneMmPkg: work around VA vs PA ambiguity
Related show

Commit Message

Ard Biesheuvel March 11, 2019, 3:36 p.m.
In order to abstract away the difference between traditional and
standalone MM implementations of the MM communicate protocol, which
have different requirements when it comes to the way the address of
the communication buffer is passed, introduce a library class that
can encapsulate calls to the MM communicate protocols, and which
takes both the physical and virtual adresses of the buffer. This
way, it is left up to the library implementation to decide which
address is passed.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

---
 MdeModulePkg/MdeModulePkg.dec                   |  4 ++
 MdeModulePkg/Include/Library/MmCommunicateLib.h | 50 ++++++++++++++++++++
 2 files changed, 54 insertions(+)

-- 
2.20.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Patch

diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec
index a2130bc43991..0778bf01edca 100644
--- a/MdeModulePkg/MdeModulePkg.dec
+++ b/MdeModulePkg/MdeModulePkg.dec
@@ -182,6 +182,10 @@  [LibraryClasses]
   #
   DisplayUpdateProgressLib|Include/Library/DisplayUpdateProgressLib.h
 
+  ## @libraryclass  Provides an abstraction for invoking the MM communicate protocol
+  #
+  MmCommunicateLib|Include/Library/MmCommunicateLib.h
+
 [Guids]
   ## MdeModule package token space guid
   # Include/Guid/MdeModulePkgTokenSpace.h
diff --git a/MdeModulePkg/Include/Library/MmCommunicateLib.h b/MdeModulePkg/Include/Library/MmCommunicateLib.h
new file mode 100644
index 000000000000..b302e47f6f8f
--- /dev/null
+++ b/MdeModulePkg/Include/Library/MmCommunicateLib.h
@@ -0,0 +1,50 @@ 
+/** @file
+  Abstraction library for calls to EFI_MM_COMMUNICATE_PROTOCOL::Communicate
+
+  Copyright (c) 2019, Linaro Ltd. All rights reserved.<BR>
+
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD License
+  which accompanies this distribution. The full text of the license may be found at
+  http://opensource.org/licenses/bsd-license.php
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#ifndef MM_COMMUNICATE_LIB_H__
+#define MM_COMMUNICATE_LIB_H__
+
+/**
+  Invoke the MM communication protocol
+
+  @param[in] PhysicalCommBuffer  Physical address of the communication buffer.
+  @param[in] VirtualCommBuffer   Virtual address of the 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(s) or CommSize
+                                 parameter, if not omitted, are in address range
+                                 that cannot be accessed by the MM environment.
+
+**/
+EFI_STATUS
+EFIAPI
+MmCommunicate (
+  IN OUT VOID                              *PhysicalCommBuffer,
+  IN OUT VOID                              *VirtualCommBuffer,
+  IN OUT UINTN                             *CommSize OPTIONAL
+  );
+
+#endif