public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Jagadeesh Ujja <jagadeesh.ujja@arm.com>
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
Subject: [PATCH v3 05/11] MdePkg/Library: Add CommonMmServicesLib library
Date: Mon,  7 Jan 2019 18:39:20 +0530	[thread overview]
Message-ID: <1546866566-21085-6-git-send-email-jagadeesh.ujja@arm.com> (raw)
In-Reply-To: <1546866566-21085-1-git-send-email-jagadeesh.ujja@arm.com>

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 <jagadeesh.ujja@arm.com>
---
 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.<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 <PiSmm.h>
+#include <PiMm.h>
+
+/**
+  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.<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 <Library/CommonMmServicesLibrary.h>
+#include <Library/StandaloneMmServicesTableLib.h>
+#include <Library/SmmServicesTableLib.h>
+
+/**
+  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.<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                    = 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



  parent reply	other threads:[~2019-01-07 13:09 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-07 13:09 [PATCH v3 00/11] Extend secure variable service to be usable from Standalone MM Jagadeesh Ujja
2019-01-07 13:09 ` [PATCH v3 01/11] StandaloneMmPkg: Remove MM_STANDALONE LIBRARY_CLASS from StandaloneMmCoreHobLib Jagadeesh Ujja
2019-01-07 13:09 ` [PATCH v3 02/11] StandaloneMmPkg: Adding the library packages used by MM_STANDALONE drivers Jagadeesh Ujja
2019-01-07 13:09 ` [PATCH v3 03/11] MdeModulePkg: Add a PCD to indicate Standalone MM supports secure variable Jagadeesh Ujja
2019-01-07 13:09 ` [PATCH v3 04/11] MdePkg/Include: Add StandaloneMmServicesTableLib library Jagadeesh Ujja
2019-01-07 13:09 ` Jagadeesh Ujja [this message]
2019-01-07 13:09 ` [PATCH v3 06/11] MdeModulePkg/FaultTolerantWriteDxe: allow reusability as a MM driver Jagadeesh Ujja
2019-01-07 13:09 ` [PATCH v3 07/11] MdeModulePkg/Variable/RuntimeDxe: adapt for usability with MM Standalone Jagadeesh Ujja
2019-01-07 13:09 ` [PATCH v3 08/11] MdeModulePkg/Variable/RuntimeDxe: adapt as a MM Standalone driver Jagadeesh Ujja
2019-01-07 13:09 ` [PATCH v3 09/11] MdeModulePkg/VarCheckLib: allow MM_STANDALONE drivers to use this library Jagadeesh Ujja
2019-01-07 13:09 ` [PATCH v3 10/11] ArmPlatformPkg/NorFlashDxe: allow reusability as a MM driver Jagadeesh Ujja
2019-01-07 13:09 ` [PATCH v3 11/11] CryptoPkg/BaseCryptLib: allow MM_STANDALONE drivers to use SmmCryptLib Jagadeesh Ujja
2019-01-07 13:32 ` [PATCH v3 00/11] Extend secure variable service to be usable from Standalone MM 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=1546866566-21085-6-git-send-email-jagadeesh.ujja@arm.com \
    --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