MdePkg: implement MmServicesTableLib based on traditional SMM
authorArd Biesheuvel <>
Thu, 3 Jan 2019 18:28:21 +0000 (19:28 +0100)
committerArd Biesheuvel <>
Mon, 14 Jan 2019 08:20:36 +0000 (09:20 +0100)
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 <>
Reviewed-by: Star Zeng <>
Reviewed-by: Liming Gao <>
MdePkg/Library/MmServicesTableLib/MmServicesTableLib.c [new file with mode: 0644]
MdePkg/Library/MmServicesTableLib/MmServicesTableLib.inf [new file with mode: 0644]
MdePkg/Library/MmServicesTableLib/MmServicesTableLib.uni [new file with mode: 0644]

diff --git a/MdePkg/Library/MmServicesTableLib/MmServicesTableLib.c b/MdePkg/Library/MmServicesTableLib/MmServicesTableLib.c
new file mode 100644 (file)
index 0000000..f3af1cc
--- /dev/null
@@ -0,0 +1,63 @@
+/** @file\r
+  MM Services Table Library.\r
+  Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2018, Linaro, Ltd. All rights reserved.<BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+#include <PiMm.h>\r
+#include <Protocol/MmBase.h>\r
+#include <Library/MmServicesTableLib.h>\r
+#include <Library/DebugLib.h>\r
+EFI_MM_SYSTEM_TABLE   *gMmst             = NULL;\r
+  The constructor function caches the pointer of the MM Services Table.\r
+  @param  ImageHandle   The firmware allocated handle for the EFI image.\r
+  @param  SystemTable   A pointer to the EFI System Table.\r
+  @retval EFI_SUCCESS   The constructor always returns EFI_SUCCESS.\r
+MmServicesTableLibConstructor (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+  EFI_STATUS              Status;\r
+  EFI_MM_BASE_PROTOCOL    *InternalMmBase;\r
+  InternalMmBase = NULL;\r
+  //\r
+  // Retrieve MM Base Protocol,  Do not use gBS from UefiBootServicesTableLib on purpose\r
+  // to prevent inclusion of gBS, gST, and gImageHandle from SMM Drivers unless the\r
+  // MM driver explicity declares that dependency.\r
+  //\r
+  Status = SystemTable->BootServices->LocateProtocol (\r
+                                        &gEfiMmBaseProtocolGuid,\r
+                                        NULL,\r
+                                        (VOID **)&InternalMmBase\r
+                                        );\r
+  ASSERT_EFI_ERROR (Status);\r
+  ASSERT (InternalMmBase != NULL);\r
+  //\r
+  // We are in MM, retrieve the pointer to MM System Table\r
+  //\r
+  InternalMmBase->GetMmstLocation (InternalMmBase, &gMmst);\r
+  ASSERT (gMmst != NULL);\r
+  return EFI_SUCCESS;\r
diff --git a/MdePkg/Library/MmServicesTableLib/MmServicesTableLib.inf b/MdePkg/Library/MmServicesTableLib/MmServicesTableLib.inf
new file mode 100644 (file)
index 0000000..4418cc2
--- /dev/null
@@ -0,0 +1,45 @@
+## @file\r
+# MM Services Table Library.\r
+# Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2018, Linaro, Ltd. All rights reserved.<BR>\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+  INF_VERSION                    = 0x0001001B\r
+  BASE_NAME                      = MmServicesTableLib\r
+  MODULE_UNI_FILE                = MmServicesTableLib.uni\r
+  FILE_GUID                      = 9508ECFD-66D1-4B4C-9415-F25F0FFF9E93\r
+  MODULE_TYPE                    = DXE_SMM_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = MmServicesTableLib|DXE_SMM_DRIVER\r
+  PI_SPECIFICATION_VERSION       = 0x00010032\r
+  CONSTRUCTOR                    = MmServicesTableLibConstructor\r
+#  VALID_ARCHITECTURES           = IA32 X64 ARM AARCH64\r
+  MmServicesTableLib.c\r
+  MdePkg/MdePkg.dec\r
+  DebugLib\r
+  gEfiMmBaseProtocolGuid                      ## CONSUMES\r
+  gEfiMmBaseProtocolGuid\r
diff --git a/MdePkg/Library/MmServicesTableLib/MmServicesTableLib.uni b/MdePkg/Library/MmServicesTableLib/MmServicesTableLib.uni
new file mode 100644 (file)
index 0000000..8a96793
--- /dev/null
@@ -0,0 +1,23 @@
+// /** @file\r
+// MM Services Table Library.\r
+// It implements MmServicesTableLib based on gEfiMmBaseProtocolGuid, which\r
+// is simply gEfiSmmBase2ProtocolGuid under the hood.\r
+// Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r
+// Copyright (c) 2018, Linaro, Ltd. All rights reserved.<BR>\r
+// This program and the accompanying materials\r
+// are licensed and made available under the terms and conditions of the BSD License\r
+// which accompanies this distribution. The full text of the license may be found at\r
+// **/\r
+#string STR_MODULE_ABSTRACT             #language en-US "MM Services Table Library"\r
+#string STR_MODULE_DESCRIPTION          #language en-US "MM Services Table Library."\r
index d43ffe4..428b14e 100644 (file)
+  MdePkg/Library/MmServicesTableLib/MmServicesTableLib.inf\r