From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=217.140.101.70; helo=foss.arm.com; envelope-from=jagadeesh.ujja@arm.com; receiver=edk2-devel@lists.01.org Received: from foss.arm.com (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by ml01.01.org (Postfix) with ESMTP id A267821959CB2 for ; Mon, 7 Jan 2019 05:09:54 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5CA2080D; Mon, 7 Jan 2019 05:09:54 -0800 (PST) Received: from usa.arm.com (a075555-lin.blr.arm.com [10.162.2.152]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 95A7B3F5AF; Mon, 7 Jan 2019 05:09:51 -0800 (PST) From: Jagadeesh Ujja To: edk2-devel@lists.01.org, liming.gao@intel.com, chao.b.zhang@intel.com, leif.lindholm@linaro.org, ard.biesheuvel@linaro.org, thomas.abraham@arm.com, Achin.Gupta@arm.com, Supreeth.Venkatesh@arm.com, jian.j.wang@intel.com Date: Mon, 7 Jan 2019 18:39:20 +0530 Message-Id: <1546866566-21085-6-git-send-email-jagadeesh.ujja@arm.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1546866566-21085-1-git-send-email-jagadeesh.ujja@arm.com> References: <1546866566-21085-1-git-send-email-jagadeesh.ujja@arm.com> Subject: [PATCH v3 05/11] MdePkg/Library: Add CommonMmServicesLib library 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, 07 Jan 2019 13:09:54 -0000 X-List-Received-Date: Mon, 07 Jan 2019 13:09:54 -0000 X-List-Received-Date: Mon, 07 Jan 2019 13:09:54 -0000 X-List-Received-Date: Mon, 07 Jan 2019 13:09:54 -0000 X-List-Received-Date: Mon, 07 Jan 2019 13:09:54 -0000 X-List-Received-Date: Mon, 07 Jan 2019 13:09:54 -0000 X-List-Received-Date: Mon, 07 Jan 2019 13:09:54 -0000 X-List-Received-Date: Mon, 07 Jan 2019 13:09:54 -0000 X-List-Received-Date: Mon, 07 Jan 2019 13:09:54 -0000 X-List-Received-Date: Mon, 07 Jan 2019 13:09:54 -0000 X-List-Received-Date: Mon, 07 Jan 2019 13:09:54 -0000 X-List-Received-Date: Mon, 07 Jan 2019 13:09:54 -0000 X-List-Received-Date: Mon, 07 Jan 2019 13:09:54 -0000 X-List-Received-Date: Mon, 07 Jan 2019 13:09:54 -0000 X-List-Received-Date: Mon, 07 Jan 2019 13:09:54 -0000 X-List-Received-Date: Mon, 07 Jan 2019 13:09:54 -0000 X-List-Received-Date: Mon, 07 Jan 2019 13:09:54 -0000 X-List-Received-Date: Mon, 07 Jan 2019 13:09:54 -0000 X-List-Received-Date: Mon, 07 Jan 2019 13:09:54 -0000 X-List-Received-Date: Mon, 07 Jan 2019 13:09:54 -0000 X-List-Received-Date: Mon, 07 Jan 2019 13:09:54 -0000 X-List-Received-Date: Mon, 07 Jan 2019 13:09:54 -0000 X-List-Received-Date: Mon, 07 Jan 2019 13:09:54 -0000 X-List-Received-Date: Mon, 07 Jan 2019 13:09:54 -0000 X-List-Received-Date: Mon, 07 Jan 2019 13:09:54 -0000 X-List-Received-Date: Mon, 07 Jan 2019 13:09:54 -0000 X-List-Received-Date: Mon, 07 Jan 2019 13:09:54 -0000 X-List-Received-Date: Mon, 07 Jan 2019 13:09:54 -0000 X-List-Received-Date: Mon, 07 Jan 2019 13:09:54 -0000 X-List-Received-Date: Mon, 07 Jan 2019 13:09:54 -0000 X-List-Received-Date: Mon, 07 Jan 2019 13:09:54 -0000 X-List-Received-Date: Mon, 07 Jan 2019 13:09:54 -0000 X-List-Received-Date: Mon, 07 Jan 2019 13:09:54 -0000 X-List-Received-Date: Mon, 07 Jan 2019 13:09:54 -0000 X-List-Received-Date: Mon, 07 Jan 2019 13:09:54 -0000 X-List-Received-Date: Mon, 07 Jan 2019 13:09:54 -0000 X-List-Received-Date: Mon, 07 Jan 2019 13:09:54 -0000 X-List-Received-Date: Mon, 07 Jan 2019 13:09:54 -0000 X-List-Received-Date: Mon, 07 Jan 2019 13:09:54 -0000 X-List-Received-Date: Mon, 07 Jan 2019 13:09:54 -0000 X-List-Received-Date: Mon, 07 Jan 2019 13:09:54 -0000 X-List-Received-Date: Mon, 07 Jan 2019 13:09:54 -0000 Add a CommonMmServicesLib library will be used by both traditional SMM and Standalone MM drivers Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jagadeesh Ujja --- MdePkg/Include/Library/CommonMmServicesLibrary.h | 131 ++++++++++++ MdePkg/Library/CommonMmServicesLibrary/CommonMmServicesLibrary.c | 224 ++++++++++++++++++++ MdePkg/Library/CommonMmServicesLibrary/CommonMmServicesLibrary.inf | 42 ++++ 3 files changed, 397 insertions(+) diff --git a/MdePkg/Include/Library/CommonMmServicesLibrary.h b/MdePkg/Include/Library/CommonMmServicesLibrary.h new file mode 100644 index 0000000..0ed7572 --- /dev/null +++ b/MdePkg/Include/Library/CommonMmServicesLibrary.h @@ -0,0 +1,131 @@ +/** @file + Wrapper functions consumed by traditional SMM drivers and + Standalone MM Drivers + + Copyright (c) 2018, ARM Limited. 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 + +/** + Return the first Protocol Interface that matches the Protocol GUID. If + Registration is pasased in return a Protocol Instance that was just add + to the system. If Retistration is NULL return the first Protocol Interface + you find. + + @param Protocol The protocol to search for + @param Registration Optional Registration Key returned from + RegisterProtocolNotify() + @param Interface Return the Protocol interface (instance). + + @retval EFI_SUCCESS If a valid Interface is returned + @retval EFI_INVALID_PARAMETER Invalid parameter + @retval EFI_NOT_FOUND Protocol interface not found + +**/ +EFI_STATUS +EFIAPI +MmstLocateProtocol( + IN EFI_GUID *Protocol, + IN VOID *Registration, OPTIONAL + OUT VOID **Interface + ); + + +/** + Registers a handler to execute within MM. + + @param Handler Handler service funtion pointer. + @param HandlerType Points to the handler type or NULL for root MI handlers. + @param DispatchHandle On return, contains a unique handle which can be used to + later unregister the handler function. + + @retval EFI_SUCCESS Handler register success. + @retval EFI_INVALID_PARAMETER Handler or DispatchHandle is NULL. + +**/ +EFI_STATUS +EFIAPI +MmstiHandlerRegister ( + IN EFI_MM_HANDLER_ENTRY_POINT Handler, + IN CONST EFI_GUID *HandlerType OPTIONAL, + OUT EFI_HANDLE *DispatchHandle + ); + +/** + Locates the requested handle(s) and returns them in Buffer. + + @param SearchType The type of search to perform to locate the + handles + @param Protocol The protocol to search for + @param SearchKey Dependant on SearchType + @param BufferSize On input the size of Buffer. On output the + size of data returned. + @param Buffer The buffer to return the results in + + @retval EFI_BUFFER_TOO_SMALL Buffer too small, required buffer size is + returned in BufferSize. + @retval EFI_INVALID_PARAMETER Invalid parameter + @retval EFI_SUCCESS Successfully found the requested handle(s) and + returns them in Buffer. + +**/ +EFI_STATUS +EFIAPI +MmstLocateHandle ( + IN EFI_LOCATE_SEARCH_TYPE SearchType, + IN EFI_GUID *Protocol OPTIONAL, + IN VOID *SearchKey OPTIONAL, + IN OUT UINTN *BufferSize, + OUT EFI_HANDLE *Buffer + ); + +/** + Queries a handle to determine if it supports a specified protocol. + + @param UserHandle The handle being queried. + @param Protocol The published unique identifier of the protocol. + @param Interface Supplies the address where a pointer to the + corresponding Protocol Interface is returned. + + @return The requested protocol interface for the handle + +**/ +EFI_STATUS +EFIAPI +MmstHandleProtocol ( + IN EFI_HANDLE UserHandle, + IN EFI_GUID *Protocol, + OUT VOID **Interface + ); + +/** + Wrapper function to Smm/MmInstallProtocolInterfaceNotify. This is the public API which + Calls the private one which contains a BOOLEAN parameter for notifications + + @param UserHandle The handle to install the protocol handler on, + or NULL if a new handle is to be allocated + @param Protocol The protocol to add to the handle + @param InterfaceType Indicates whether Interface is supplied in + native form. + @param Interface The interface for the protocol being added + + @return Status code + +**/ +EFI_STATUS +EFIAPI +MmstInstallProtocolInterface ( + IN OUT EFI_HANDLE *UserHandle, + IN EFI_GUID *Protocol, + IN EFI_INTERFACE_TYPE InterfaceType, + IN VOID *Interface + ); diff --git a/MdePkg/Library/CommonMmServicesLibrary/CommonMmServicesLibrary.c b/MdePkg/Library/CommonMmServicesLibrary/CommonMmServicesLibrary.c new file mode 100644 index 0000000..59ebd90 --- /dev/null +++ b/MdePkg/Library/CommonMmServicesLibrary/CommonMmServicesLibrary.c @@ -0,0 +1,224 @@ +/** @file + Wrapper functions consumed by traditional SMM drivers and + Standalone MM Drivers + + Copyright (c) 2018, ARM Limited. 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 + +/** + Return the first Protocol Interface that matches the Protocol GUID. If + Registration is pasased in return a Protocol Instance that was just add + to the system. If Retistration is NULL return the first Protocol Interface + you find. + + @param Protocol The protocol to search for + @param Registration Optional Registration Key returned from + RegisterProtocolNotify() + @param Interface Return the Protocol interface (instance). + + @retval EFI_SUCCESS If a valid Interface is returned + @retval EFI_INVALID_PARAMETER Invalid parameter + @retval EFI_NOT_FOUND Protocol interface not found + +**/ +EFI_STATUS +EFIAPI +MmstLocateProtocol( + IN EFI_GUID *Protocol, + IN VOID *Registration, OPTIONAL + OUT VOID **Interface + ) +{ + EFI_STATUS Status; + + if (!PcdGetBool (PcdStandaloneMmVariableEnabled)) { + Status = gSmst->SmmLocateProtocol ( + Protocol, + Registration, + Interface); + } else { + Status = gMmst->MmLocateProtocol ( + Protocol, + Registration, + Interface); + } + + return Status; +} + +/** + Registers a handler to execute within MM. + + @param Handler Handler service funtion pointer. + @param HandlerType Points to the handler type or NULL for root MI handlers. + @param DispatchHandle On return, contains a unique handle which can be used to later + unregister the handler function. + + @retval EFI_SUCCESS Handler register success. + @retval EFI_INVALID_PARAMETER Handler or DispatchHandle is NULL. + +**/ + +EFI_STATUS +EFIAPI +MmstiHandlerRegister ( + IN EFI_MM_HANDLER_ENTRY_POINT Handler, + IN CONST EFI_GUID *HandlerType OPTIONAL, + OUT EFI_HANDLE *DispatchHandle + ) +{ + EFI_STATUS Status; + + if (!PcdGetBool (PcdStandaloneMmVariableEnabled)) { + Status = gSmst->SmiHandlerRegister ( + Handler, + HandlerType, + DispatchHandle); + } else { + Status = gMmst->MmiHandlerRegister ( + Handler, + HandlerType, + DispatchHandle); + } + return Status; +} + +/** + Locates the requested handle(s) and returns them in Buffer. + + @param SearchType The type of search to perform to locate the + handles + @param Protocol The protocol to search for + @param SearchKey Dependant on SearchType + @param BufferSize On input the size of Buffer. On output the + size of data returned. + @param Buffer The buffer to return the results in + + @retval EFI_BUFFER_TOO_SMALL Buffer too small, required buffer size is + returned in BufferSize. + @retval EFI_INVALID_PARAMETER Invalid parameter + @retval EFI_SUCCESS Successfully found the requested handle(s) and + returns them in Buffer. + +**/ +EFI_STATUS +EFIAPI +MmstLocateHandle ( + IN EFI_LOCATE_SEARCH_TYPE SearchType, + IN EFI_GUID *Protocol OPTIONAL, + IN VOID *SearchKey OPTIONAL, + IN OUT UINTN *BufferSize, + OUT EFI_HANDLE *Buffer + ) +{ + EFI_STATUS Status; + + if (PcdGetBool (PcdStandaloneMmVariableEnabled)) { + Status = gMmst->MmLocateHandle ( + SearchType, + Protocol, + SearchKey, + BufferSize, + Buffer + ); + } else { + Status = gSmst->SmmLocateHandle ( + SearchType, + Protocol, + SearchKey, + BufferSize, + Buffer + ); + } + return Status; +} + +/** + Queries a handle to determine if it supports a specified protocol. + + @param UserHandle The handle being queried. + @param Protocol The published unique identifier of the protocol. + @param Interface Supplies the address where a pointer to the + corresponding Protocol Interface is returned. + + @return The requested protocol interface for the handle + +**/ +EFI_STATUS +EFIAPI +MmstHandleProtocol ( + IN EFI_HANDLE UserHandle, + IN EFI_GUID *Protocol, + OUT VOID **Interface + ) +{ + if (PcdGetBool (PcdStandaloneMmVariableEnabled)) { + return gMmst->MmHandleProtocol ( + UserHandle, + Protocol, + Interface + ); + } else { + return gSmst->SmmHandleProtocol ( + UserHandle, + Protocol, + Interface + ); + } +} + +/** + Wrapper function to Smm/MmInstallProtocolInterfaceNotify. This is the public API which + Calls the private one which contains a BOOLEAN parameter for notifications + + @param UserHandle The handle to install the protocol handler on, + or NULL if a new handle is to be allocated + @param Protocol The protocol to add to the handle + @param InterfaceType Indicates whether Interface is supplied in + native form. + @param Interface The interface for the protocol being added + + @return Status code + +**/ + +EFI_STATUS +EFIAPI +MmstInstallProtocolInterface ( + IN OUT EFI_HANDLE *UserHandle, + IN EFI_GUID *Protocol, + IN EFI_INTERFACE_TYPE InterfaceType, + IN VOID *Interface + ) +{ + EFI_STATUS Status; + + if (!PcdGetBool (PcdStandaloneMmVariableEnabled)) { + Status = gSmst->SmmInstallProtocolInterface ( + UserHandle, + Protocol, + InterfaceType, + Interface + ); + } else { + Status = gMmst->MmInstallProtocolInterface ( + UserHandle, + Protocol, + InterfaceType, + Interface + ); + } + return Status; +} diff --git a/MdePkg/Library/CommonMmServicesLibrary/CommonMmServicesLibrary.inf b/MdePkg/Library/CommonMmServicesLibrary/CommonMmServicesLibrary.inf new file mode 100644 index 0000000..8604474 --- /dev/null +++ b/MdePkg/Library/CommonMmServicesLibrary/CommonMmServicesLibrary.inf @@ -0,0 +1,42 @@ +## @file +# Wrapper functions consumed by traditional SMM drivers and +# Standalone MM Drivers +# +# Copyright (c) 2018, ARM Limited. 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 = 0x00010005 + BASE_NAME = CommonMmServicesLib + MODULE_UNI_FILE = CommonMmServicesLib.uni + FILE_GUID = 2FF370E4-8B93-4EDA-A177-91296322E3B3 + MODULE_TYPE = DXE_RUNTIME_DRIVER + VERSION_STRING = 1.0 + LIBRARY_CLASS = CommonMmServicesLib|DXE_RUNTIME_DRIVER DXE_SMM_DRIVER MM_STANDALONE + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 AARCH64 +# + +[Sources] + CommonMmServicesLibrary.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[LibraryClasses] + PcdLib + +[Pcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdStandaloneMmVariableEnabled -- 2.7.4