public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Ard Biesheuvel <ard.biesheuvel@linaro.org>
To: edk2-devel@lists.01.org
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>,
	Jian J Wang <jian.j.wang@intel.com>, Hao Wu <hao.a.wu@intel.com>,
	Star Zeng <star.zeng@intel.com>,
	Michael D Kinney <michael.d.kinney@intel.com>,
	Liming Gao <liming.gao@intel.com>,
	Achin Gupta <achin.gupta@arm.com>,
	Jiewen Yao <jiewen.yao@intel.com>,
	Supreeth Venkatesh <supreeth.venkatesh@arm.com>,
	Jagadeesh Ujja <jagadeesh.ujja@arm.com>
Subject: [PATCH 3/4] StandaloneMmPkg: add implementation of MmCommunicateLib
Date: Mon, 11 Mar 2019 16:36:07 +0100	[thread overview]
Message-ID: <20190311153608.3251-4-ard.biesheuvel@linaro.org> (raw)
In-Reply-To: <20190311153608.3251-1-ard.biesheuvel@linaro.org>

Add an implementation of MmCommunicateLib based on standalone MM.
This version passes the virtual address of the communication buffer
into the MM communicate protocol method.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 StandaloneMmPkg/Library/RuntimeDxeMmCommunicateLib/RuntimeDxeMmCommunicateLib.inf |  51 +++++++++
 StandaloneMmPkg/Library/RuntimeDxeMmCommunicateLib/RuntimeDxeMmCommunicateLib.c   | 113 ++++++++++++++++++++
 StandaloneMmPkg/Library/RuntimeDxeMmCommunicateLib/RuntimeDxeMmCommunicateLib.uni |  19 ++++
 3 files changed, 183 insertions(+)

diff --git a/StandaloneMmPkg/Library/RuntimeDxeMmCommunicateLib/RuntimeDxeMmCommunicateLib.inf b/StandaloneMmPkg/Library/RuntimeDxeMmCommunicateLib/RuntimeDxeMmCommunicateLib.inf
new file mode 100644
index 000000000000..c29a8618b3c2
--- /dev/null
+++ b/StandaloneMmPkg/Library/RuntimeDxeMmCommunicateLib/RuntimeDxeMmCommunicateLib.inf
@@ -0,0 +1,51 @@
+## @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.
+#
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x0001001B
+  BASE_NAME                      = RuntimeDxeMmCommunicateLib
+  MODULE_UNI_FILE                = RuntimeDxeMmCommunicateLib.uni
+  FILE_GUID                      = 15cd7ca8-ca1a-43a2-8f9c-eabbd3e7e5b5
+  MODULE_TYPE                    = DXE_RUNTIME_DRIVER
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = MmCommunicateLib|DXE_RUNTIME_DRIVER
+  CONSTRUCTOR                    = RuntimeDxeMmCommunicateLibConstructor
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+#  VALID_ARCHITECTURES           = ARM AARCH64 IA32 X64
+#
+
+[Sources]
+  RuntimeDxeMmCommunicateLib.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+
+[LibraryClasses]
+  DebugLib
+  UefiBootServicesTableLib
+  UefiRuntimeLib
+
+[Guids]
+  gEfiEventVirtualAddressChangeGuid             ## CONSUMES ## Event
+
+[Protocols]
+  gEfiMmCommunicationProtocolGuid               ## CONSUMES
+
+[Depex]
+  gEfiMmCommunicationProtocolGuid
diff --git a/StandaloneMmPkg/Library/RuntimeDxeMmCommunicateLib/RuntimeDxeMmCommunicateLib.c b/StandaloneMmPkg/Library/RuntimeDxeMmCommunicateLib/RuntimeDxeMmCommunicateLib.c
new file mode 100644
index 000000000000..b5a203865360
--- /dev/null
+++ b/StandaloneMmPkg/Library/RuntimeDxeMmCommunicateLib/RuntimeDxeMmCommunicateLib.c
@@ -0,0 +1,113 @@
+/** @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.
+
+**/
+
+#include <PiDxe.h>
+
+#include <Library/DebugLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiRuntimeLib.h>
+
+#include <Protocol/MmCommunication.h>
+
+STATIC EFI_MM_COMMUNICATION_PROTOCOL    *mMmCommunication;
+STATIC EFI_EVENT                        mVirtualAddressChangeEvent;
+
+/**
+  Invoke the MM communication protocol
+
+  @param[in] CommBuffer          A pointer to the buffer to convey into MMRAM.
+  @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
+  )
+{
+  ASSERT (EfiAtRuntime () || (PhysicalCommBuffer == VirtualCommBuffer));
+
+  return mMmCommunication->Communicate (mMmCommunication, VirtualCommBuffer,
+                             CommSize);
+}
+
+/**
+  Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.
+
+  @param[in]  Event        Event whose notification function is being invoked.
+  @param[in]  Context      Pointer to the notification function's context.
+
+**/
+STATIC
+VOID
+EFIAPI
+VariableAddressChangeEvent (
+  IN EFI_EVENT                              Event,
+  IN VOID                                   *Context
+  )
+{
+  EfiConvertPointer (0x0, (VOID **)&mMmCommunication);
+}
+
+/**
+  Library entry point
+
+  @param[in] ImageHandle    The firmware allocated handle for the EFI image.
+  @param[in] SystemTable    A pointer to the EFI System Table.
+
+  @retval EFI_SUCCESS       Library successfully initialized.
+
+**/
+EFI_STATUS
+EFIAPI
+RuntimeDxeMmCommunicateLibConstructor (
+  IN EFI_HANDLE                             ImageHandle,
+  IN EFI_SYSTEM_TABLE                       *SystemTable
+  )
+{
+  EFI_STATUS        Status;
+
+  Status = gBS->LocateProtocol (&gEfiMmCommunicationProtocolGuid, NULL,
+                  (VOID **)&mMmCommunication);
+  ASSERT_EFI_ERROR (Status);
+
+  //
+  // Register the event to convert the pointer for runtime.
+  //
+  Status = gBS->CreateEventEx (EVT_NOTIFY_SIGNAL, TPL_NOTIFY,
+                  VariableAddressChangeEvent, NULL,
+                  &gEfiEventVirtualAddressChangeGuid,
+                  &mVirtualAddressChangeEvent);
+  ASSERT_EFI_ERROR (Status);
+
+  return EFI_SUCCESS;
+}
diff --git a/StandaloneMmPkg/Library/RuntimeDxeMmCommunicateLib/RuntimeDxeMmCommunicateLib.uni b/StandaloneMmPkg/Library/RuntimeDxeMmCommunicateLib/RuntimeDxeMmCommunicateLib.uni
new file mode 100644
index 000000000000..1e3332a649b0
--- /dev/null
+++ b/StandaloneMmPkg/Library/RuntimeDxeMmCommunicateLib/RuntimeDxeMmCommunicateLib.uni
@@ -0,0 +1,19 @@
+///** @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.
+//
+//**/
+
+
+#string STR_MODULE_ABSTRACT             #language en-US "Abstraction library for calls to EFI_MM_COMMUNICATE_PROTOCOL::Communicate"
+
+#string STR_MODULE_DESCRIPTION          #language en-US "Abstraction library for calls to EFI_MM_COMMUNICATE_PROTOCOL::Communicate."
+
-- 
2.20.1



  parent reply	other threads:[~2019-03-11 15:37 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-11 15:36 [PATCH 0/4] MdeModulePkg, StandaloneMmPkg: work around VA vs PA ambiguity Ard Biesheuvel
2019-03-11 15:36 ` [PATCH 1/4] MdeModulePkg: introduce MmCommunicationLib library class Ard Biesheuvel
2019-03-11 15:36 ` [PATCH 2/4] MdeModulePkg: add implementation of MmCommunicateLib Ard Biesheuvel
2019-03-11 15:36 ` Ard Biesheuvel [this message]
2019-03-11 15:36 ` [PATCH 4/4] MdeModulePkg/VariableSmmRuntimeDxe: switch to MmCommunicateLib library Ard Biesheuvel
2019-03-15  2:15 ` [PATCH 0/4] MdeModulePkg, StandaloneMmPkg: work around VA vs PA ambiguity Wu, Hao A
2019-03-15  8:12   ` Ard Biesheuvel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190311153608.3251-4-ard.biesheuvel@linaro.org \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox