From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=209.85.128.42; helo=mail-wm1-f42.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 004F62194EB7C for ; Mon, 11 Mar 2019 08:37:18 -0700 (PDT) Received: by mail-wm1-f42.google.com with SMTP id g20so4708011wmh.5 for ; Mon, 11 Mar 2019 08:37:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=U+fzMeF7VZjuRI2vh8g7zZNSKxP3oNphcE7jajRjzns=; b=DZ9SjbeeNGYFtO6Mj1NLxky5BSkOQDa++rDFqMN88QG90Y0Wwl4v4tIGNM1u0hFhqb R4x4+AwobqaKtpiVRCjZhsnnipUJO+yqQ/xZv0k8dSToMb7KP9fld+2T2RCVYbc7MgpL qYvZ/lsR4ICoOMlarivUCI3bkKOf11zy3RLCx0omvciFwmHnQmYhEw8raz3oDj97bW8B ba60ppAS+uayunDd+dWz2fx10lxx3/U02wk2b0d0tZ9JcTksJCGwSGEy2Y6kmK9EIn5J 6pPTCHyPYgb3KN+RcgjID1MO9DmJzxUqtXTA9OQuXnrrxU5nPwQlS0egvcYArZVAasxp 3pgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=U+fzMeF7VZjuRI2vh8g7zZNSKxP3oNphcE7jajRjzns=; b=ZckhLSbUkO+sogzKx8eao4cUczfx95RBXTbND2U2odN7CiGNlezXb7ZrLRX6Dh7w+b qo4vLqIDIwCMBktMBVKHLCHqP0mRRlAyP/wgqKt6jbSMj4fddW9kscb2fekIFzOJ/BjO M/FHMduaztosqpVGk2j2p/QJjWndWoLpefVotU5FXVSni4nRljkfVl/GWo0uXRwMMHvv hUWM+3Wwp0AsvMDXYIbL9tfQFWoDM/gOpzomTuSda082sTqz3zoKo4nR3bJ6EkMPSnpH IRgF279QMpZZlGPuSt/tbkRXRX6RHlSjwvWMT8FK4saJq3iubIaNNQvILTkpwNhjcjvu v5/w== X-Gm-Message-State: APjAAAWxHIKits851w6rsTmUlE3vqhYt3z8Q8vQAGZBPaOvc8AnzX914 G9Xoiw7BnpvXi440vlxeavs3PD80ry8= X-Google-Smtp-Source: APXvYqwhxrUWkUWKti5IPTwHuTRaU2eCBV0ephFrHU+hsxQkhR+sPiE8V//AcOJzJNuOwsKQlNg4cQ== X-Received: by 2002:a1c:20d3:: with SMTP id g202mr224782wmg.74.1552318577074; Mon, 11 Mar 2019 08:36:17 -0700 (PDT) Received: from localhost.localdomain (laubervilliers-657-1-83-120.w92-154.abo.wanadoo.fr. [92.154.90.120]) by smtp.gmail.com with ESMTPSA id u13sm34938965wmf.3.2019.03.11.08.36.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Mar 2019 08:36:16 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org Cc: Ard Biesheuvel , Jian J Wang , Hao Wu , Star Zeng , Michael D Kinney , Liming Gao , Achin Gupta , Jiewen Yao , Supreeth Venkatesh , Jagadeesh Ujja Date: Mon, 11 Mar 2019 16:36:06 +0100 Message-Id: <20190311153608.3251-3-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190311153608.3251-1-ard.biesheuvel@linaro.org> References: <20190311153608.3251-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 Subject: [PATCH 2/4] MdeModulePkg: add implementation of MmCommunicateLib X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Mar 2019 15:37:19 -0000 Content-Transfer-Encoding: 8bit Add an implementation of MmCommunicateLib based on traditional SMM. This version passes the physical address of the communication buffer into the MM communicate protocol method. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel --- MdeModulePkg/MdeModulePkg.dsc | 1 + MdeModulePkg/Library/RuntimeDxeMmCommunicateLib/RuntimeDxeMmCommunicateLib.inf | 51 +++++++++ MdeModulePkg/Library/RuntimeDxeMmCommunicateLib/RuntimeDxeMmCommunicateLib.c | 114 ++++++++++++++++++++ MdeModulePkg/Library/RuntimeDxeMmCommunicateLib/RuntimeDxeMmCommunicateLib.uni | 19 ++++ 4 files changed, 185 insertions(+) diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc index 6cd1727a0d61..84c2629d5adc 100644 --- a/MdeModulePkg/MdeModulePkg.dsc +++ b/MdeModulePkg/MdeModulePkg.dsc @@ -317,6 +317,7 @@ [Components] MdeModulePkg/Library/BaseBmpSupportLib/BaseBmpSupportLib.inf MdeModulePkg/Library/DisplayUpdateProgressLibGraphics/DisplayUpdateProgressLibGraphics.inf MdeModulePkg/Library/DisplayUpdateProgressLibText/DisplayUpdateProgressLibText.inf + MdeModulePkg/Library/RuntimeDxeMmCommunicateLib/RuntimeDxeMmCommunicateLib.inf MdeModulePkg/Universal/BdsDxe/BdsDxe.inf MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenuApp.inf diff --git a/MdeModulePkg/Library/RuntimeDxeMmCommunicateLib/RuntimeDxeMmCommunicateLib.inf b/MdeModulePkg/Library/RuntimeDxeMmCommunicateLib/RuntimeDxeMmCommunicateLib.inf new file mode 100644 index 000000000000..93b924d5eefb --- /dev/null +++ b/MdeModulePkg/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.
+# +# 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 = cb3ee7d3-ea6f-494c-ac57-c5f4dc0ab3b9 + 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 EBC +# + +[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/MdeModulePkg/Library/RuntimeDxeMmCommunicateLib/RuntimeDxeMmCommunicateLib.c b/MdeModulePkg/Library/RuntimeDxeMmCommunicateLib/RuntimeDxeMmCommunicateLib.c new file mode 100644 index 000000000000..b4ae5dd1fd9a --- /dev/null +++ b/MdeModulePkg/Library/RuntimeDxeMmCommunicateLib/RuntimeDxeMmCommunicateLib.c @@ -0,0 +1,114 @@ +/** @file + Abstraction library for calls to EFI_MM_COMMUNICATE_PROTOCOL::Communicate + + Copyright (c) 2019, Linaro Ltd. All rights reserved.
+ + 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 + +#include +#include +#include + +#include + +STATIC EFI_MM_COMMUNICATION_PROTOCOL *mMmCommunication; +STATIC EFI_EVENT mVirtualAddressChangeEvent; + +/** + 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 + ) +{ + ASSERT (EfiAtRuntime () || (PhysicalCommBuffer == VirtualCommBuffer)); + + return mMmCommunication->Communicate (mMmCommunication, PhysicalCommBuffer, + 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/MdeModulePkg/Library/RuntimeDxeMmCommunicateLib/RuntimeDxeMmCommunicateLib.uni b/MdeModulePkg/Library/RuntimeDxeMmCommunicateLib/RuntimeDxeMmCommunicateLib.uni new file mode 100644 index 000000000000..1e3332a649b0 --- /dev/null +++ b/MdeModulePkg/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.
+// +// 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