From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:4864:20::544; helo=mail-ed1-x544.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) (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 676A4211ADA3B for ; Thu, 3 Jan 2019 10:28:55 -0800 (PST) Received: by mail-ed1-x544.google.com with SMTP id b3so29889468ede.1 for ; Thu, 03 Jan 2019 10:28:55 -0800 (PST) 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; bh=MBiXcKoD/ZIdpRcJu1r2/wb9917ICJJbHxvZhq7nYhE=; b=YrSLKMJO6nz2nfmu7Ib/wx7AuCDMhOrM1jwaq83OqKQexnmapVuYx0tuTcvCCAUeTZ QviWuIOZ+mP0BBdUqqJ/ZjL7ce8BkajVADvyjqZ6qaJM26BFQJ2pCybjseXrxcAJf7Bo bDkx6DYvWefwmyiRTy5szVFhGFT04BhVdJV6Q= 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; bh=MBiXcKoD/ZIdpRcJu1r2/wb9917ICJJbHxvZhq7nYhE=; b=eM9kylTg8TkTczSoaPgSBbLFy5D+sMWE9HsyHj14HJ6Xb6QH9x3IAQ/RYKbGEAl2PZ yzhDIvORVWYmVJXTGIJHOt4Y+7kTCR53DFigD4zVXMyV+X7kgGXDzgLooe1B3C/RSOe5 dV30hAeFs83CAJVzO4Nx5+lYTD3XHqUDoXRfnu9K78vd1uFjiTKRGI9bl+0A5bFza5Hw LTfhKoQx3d4K/0nzpwFQg8kfa2M4qmkfkQSCnk7xATVXVkQSg4cttNoykMNFFuigiG1D hB0sU0MxvqViMkvRXlFBQTeXjxq2KMgXrC/kFwecN/zxGUYHGFfy8gFhLNnMwFr1X/6N qJgQ== X-Gm-Message-State: AA+aEWZHsff2y89Gwvc+T95I8voWohtgyeNa89OWbdrfxMrFSmMOSFCn SeNcSjhuAU04hVwn2j9R1v1z+ELjiyHc5w== X-Google-Smtp-Source: AFSGD/Xh4qIcikAT5uzVkOsvkQdsSSS12qv5G1ArhsBinVSgmwttTPArRd78+g8gZ5IvXIEcH86Jkg== X-Received: by 2002:a50:a844:: with SMTP id j62mr45121370edc.2.1546540132452; Thu, 03 Jan 2019 10:28:52 -0800 (PST) Received: from dogfood.home ([2a01:cb1d:112:6f00:704e:c241:dc88:597d]) by smtp.gmail.com with ESMTPSA id a11sm25707206edc.28.2019.01.03.10.28.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 03 Jan 2019 10:28:51 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.01.org Cc: Ard Biesheuvel , Laszlo Ersek , Leif Lindholm , Michael D Kinney , Liming Gao , Jian J Wang , Hao Wu , Jagadeesh Ujja , Achin Gupta , Thomas Panakamattam Abraham , Sami Mujawar Date: Thu, 3 Jan 2019 19:28:21 +0100 Message-Id: <20190103182825.32231-4-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190103182825.32231-1-ard.biesheuvel@linaro.org> References: <20190103182825.32231-1-ard.biesheuvel@linaro.org> Subject: [PATCH 2/6] MdePkg: implement MmServicesTableLib based on traditional SMM 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: Thu, 03 Jan 2019 18:28:55 -0000 The definitions of the rebranded MM protocol stack were chosen such that the existing SMM based core drivers can be reused. So let's implement MmServicesTableLib based on gEfiMmBaseProtocolGuid, which is simply gEfiSmmBase2ProtocolGuid under the hood. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel --- MdePkg/Library/MmServicesTableLib/MmServicesTableLib.c | 63 ++++++++++++++++++++ MdePkg/Library/MmServicesTableLib/MmServicesTableLib.inf | 45 ++++++++++++++ MdePkg/Library/MmServicesTableLib/MmServicesTableLib.uni | 22 +++++++ MdePkg/MdePkg.dsc | 1 + 4 files changed, 131 insertions(+) diff --git a/MdePkg/Library/MmServicesTableLib/MmServicesTableLib.c b/MdePkg/Library/MmServicesTableLib/MmServicesTableLib.c new file mode 100644 index 000000000000..f41d25e59805 --- /dev/null +++ b/MdePkg/Library/MmServicesTableLib/MmServicesTableLib.c @@ -0,0 +1,63 @@ +/** @file + MM Services Table Library. + + Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.
+ Copyright (c) 2018, 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 + +EFI_MM_SYSTEM_TABLE *gMmst = NULL; + +/** + The constructor function caches the pointer of SMM Services Table. + + @param ImageHandle The firmware allocated handle for the EFI image. + @param SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS. + +**/ +EFI_STATUS +EFIAPI +MmServicesTableLibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + EFI_MM_BASE_PROTOCOL *InternalMmBase; + + InternalMmBase = NULL; + // + // Retrieve MM Base Protocol, Do not use gBS from UefiBootServicesTableLib on purpose + // to prevent inclusion of gBS, gST, and gImageHandle from SMM Drivers unless the + // MM driver explicity declares that dependency. + // + Status = SystemTable->BootServices->LocateProtocol ( + &gEfiMmBaseProtocolGuid, + NULL, + (VOID **)&InternalMmBase + ); + ASSERT_EFI_ERROR (Status); + ASSERT (InternalMmBase != NULL); + + // + // We are in MM, retrieve the pointer to MM System Table + // + InternalMmBase->GetMmstLocation (InternalMmBase, &gMmst); + ASSERT (gMmst != NULL); + + return EFI_SUCCESS; +} diff --git a/MdePkg/Library/MmServicesTableLib/MmServicesTableLib.inf b/MdePkg/Library/MmServicesTableLib/MmServicesTableLib.inf new file mode 100644 index 000000000000..4418cc2f1464 --- /dev/null +++ b/MdePkg/Library/MmServicesTableLib/MmServicesTableLib.inf @@ -0,0 +1,45 @@ +## @file +# MM Services Table Library. +# +# Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.
+# Copyright (c) 2018, 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 = MmServicesTableLib + MODULE_UNI_FILE = MmServicesTableLib.uni + FILE_GUID = 9508ECFD-66D1-4B4C-9415-F25F0FFF9E93 + MODULE_TYPE = DXE_SMM_DRIVER + VERSION_STRING = 1.0 + LIBRARY_CLASS = MmServicesTableLib|DXE_SMM_DRIVER + PI_SPECIFICATION_VERSION = 0x00010032 + CONSTRUCTOR = MmServicesTableLibConstructor + +# +# VALID_ARCHITECTURES = IA32 X64 ARM AARCH64 +# + +[Sources] + MmServicesTableLib.c + +[Packages] + MdePkg/MdePkg.dec + +[LibraryClasses] + DebugLib + +[Protocols] + gEfiMmBaseProtocolGuid ## CONSUMES + +[Depex] + gEfiMmBaseProtocolGuid diff --git a/MdePkg/Library/MmServicesTableLib/MmServicesTableLib.uni b/MdePkg/Library/MmServicesTableLib/MmServicesTableLib.uni new file mode 100644 index 000000000000..2b2c7e14024c --- /dev/null +++ b/MdePkg/Library/MmServicesTableLib/MmServicesTableLib.uni @@ -0,0 +1,22 @@ +// /** @file +// MM Services Table Library. +// +// MM Services Table Library. +// +// Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.
+// Copyright (c) 2018, 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 "MM Services Table Library" + +#string STR_MODULE_DESCRIPTION #language en-US "MM Services Table Library." + diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc index d43ffe4deb49..428b14e6a4e0 100644 --- a/MdePkg/MdePkg.dsc +++ b/MdePkg/MdePkg.dsc @@ -141,6 +141,7 @@ [Components.IA32, Components.X64] MdePkg/Library/BaseRngLib/BaseRngLib.inf MdePkg/Library/SmmPciExpressLib/SmmPciExpressLib.inf MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.inf + MdePkg/Library/MmServicesTableLib/MmServicesTableLib.inf [Components.EBC] MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf -- 2.17.1