From patchwork Mon Mar 11 15:36:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 160045 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp12061600jad; Mon, 11 Mar 2019 08:38:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqyrZiERp1uzPCskA3u5y0nW7UwsUI/gK2X845sCCAuLxsKTQGUrrLN0i64G7CX4ZxbSIyCe X-Received: by 2002:a63:720f:: with SMTP id n15mr29761310pgc.216.1552318701665; Mon, 11 Mar 2019 08:38:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552318701; cv=none; d=google.com; s=arc-20160816; b=bhnMpw/w02ei8Lyli1nui8nWsqGD1gpTig63raAvuacwuTxbQJ2cKyztObb8Nq1irI KIMG+b4NvyodYv+s3MehqELWxUH9oC1zPgBGkFumn3jEd8Mv5jzXu4RcsvOql92n9+qr c7IkEYjNWi/o+o2OjgiqT+w5dIXOoTkMhCohZgTClTFfwoOMoa55gi6ih0R87TIqfeHy IG9BcfXZihGeFg2zIJKyXl2CREoRK/sGmvpp53NY17Khe4n16Cu+lCwzL9deF01R6i7v vVZDUDIDaifXigOGIQ3RXQhmpEinNB6Br0fN1eUKawy+1myUsIkwjD7F9fIf+vY19MId TptA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=V4IqFXYBD6QrIF3PtLASFN+AExkCTDJCJMmRwBcACqQ=; b=RKnQyqsqPirShPg6gDPkiKK9S4XIQb3R4/IhcvprtjT6StYOgv4rQ7+IPCxIntpa9q Uju+wOMmBWHLeKK8fBIr0d7dRtSJv38vutH811du0kW2jPZCDzCE8ISCCQPlgyPtces+ ejYBG3kfxnIXVho3hL5MwLk6Y4L1JWgM5H/nJySxuPeXUPUk1CbZWKURt9Mxyz+kkOa/ YsV2EPgvXN59oM4QHtoBPHK0jhWZDrIJmMY9yb/ewoyHMQA/njLAt/6kLo3fzVHTG5j6 4ikdzmJl2NVyV73Sbxjybtr7y4dJv2qHav9ydIR4Yvhih5lGUubLPT9L9lIdE4zZEgy5 PFDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=b2xe9ViP; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id a2si5177342pga.476.2019.03.11.08.38.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Mar 2019 08:38:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=b2xe9ViP; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 9886A211DB41F; Mon, 11 Mar 2019 08:37:21 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=209.85.128.54; helo=mail-wm1-f54.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (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 5E3FB211DB41A for ; Mon, 11 Mar 2019 08:37:20 -0700 (PDT) Received: by mail-wm1-f54.google.com with SMTP id f65so5011933wma.2 for ; Mon, 11 Mar 2019 08:37:20 -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=GBdWU2SPMEvlK802syGTeSqu+DDV8HRducYlzcGsKFo=; b=b2xe9ViPjF45Z+G5UCic3ukunNuRgnU0O324htzu7O43KWLnGY+vI9oFmi+r5If43I Dhy6tTerDmEJ4Pe/wu6uu1rI5aTELdPlOGMqREoCji9zdlSZ57y781mYbwA5VavEJVqW mXfIromYOABRFn3UPLIx1tQQpr7cveuMDa8AuNNBXHMfZxNqi2aQwDkls+YvDOikyGlj 5mT65L9QG6L2OuPG6U0fyso1JLKd+kDlYu6s9EdMFIur0AoFWr9EpMGloF5jbzLADLMf 4ehhhlaCZVay2ottZDHQPSR5e6lvdKoG4CnYy19leSW3oPginrhP1AzFY53+5cMIT0/J 132w== 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=GBdWU2SPMEvlK802syGTeSqu+DDV8HRducYlzcGsKFo=; b=maD2bJcMjf8shRndaMp3zRPqPXWmCS+xjBelWciypC+ivOPwePZUImo+M6eGBjcPOA ao+7ajcpVqmcZV/EYXDxnzTCvyYUFi6OnIcUFbRxIYEYpClfdH72eKUmVhtpZw6UiEy3 4cp2fC7Hh6ioP3gkSFl3urWtRC0eN9C28XRrL5LNwADJE90hcDOswc8Zj+AMrAC3P4Eu tB9606QyNpbtbxFsgdRp7/Fb7M34I/El9Tiy0dZJlxk+kAs7j8VvGjToX8eCGpBDCxkL liiC88Q9X/tFwnd9MPhajom25dI3B2rZB2uzgo5DSofsVZnrOwZ++/2VEaE9+GUfBPzR QDFQ== X-Gm-Message-State: APjAAAUbdo856nw+0FWUyduQMQVNwAr5fYLyu/mGEz/mvJkXqQasZzme rtq0Z+PW+aJrGUmDAyZt/tUfIzTA8Y0= X-Received: by 2002:a1c:230e:: with SMTP id j14mr210910wmj.9.1552318578407; Mon, 11 Mar 2019 08:36:18 -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.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Mar 2019 08:36:17 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Mon, 11 Mar 2019 16:36:07 +0100 Message-Id: <20190311153608.3251-4-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: [edk2] [PATCH 3/4] StandaloneMmPkg: 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: , Cc: Hao Wu , Liming Gao , Jiewen Yao , Michael D Kinney , Star Zeng Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" 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 --- StandaloneMmPkg/Library/RuntimeDxeMmCommunicateLib/RuntimeDxeMmCommunicateLib.inf | 51 +++++++++ StandaloneMmPkg/Library/RuntimeDxeMmCommunicateLib/RuntimeDxeMmCommunicateLib.c | 113 ++++++++++++++++++++ StandaloneMmPkg/Library/RuntimeDxeMmCommunicateLib/RuntimeDxeMmCommunicateLib.uni | 19 ++++ 3 files changed, 183 insertions(+) -- 2.20.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel 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.
+# +# 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.
+ + 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] 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.
+// +// 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." +