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
Subject: [RFC PATCH v3 02/11] StandaloneMmPkg: Pull in additonal libraries from staging branch
Date: Wed, 28 Nov 2018 15:05:00 +0530	[thread overview]
Message-ID: <1543397709-31847-3-git-send-email-jagadeesh.ujja@arm.com> (raw)
In-Reply-To: <1543397709-31847-1-git-send-email-jagadeesh.ujja@arm.com>

Three additional library packages are being pulled into StandaloneMmPkg
from the staging area in order to support the secure variable service.
The three packages being pulled in are
  - StandaloneMmHobLib
  - StandaloneMmMemoryAllocationLib
  - StandaloneMmServicesTableLib

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jagadeesh Ujja <jagadeesh.ujja@arm.com>
---
 StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmCoreHobLib.inf                                                                                                    |  2 +-
 StandaloneMmPkg/Library/{StandaloneMmCoreHobLib/StandaloneMmCoreHobLib.inf => StandaloneMmHobLib/StandaloneMmHobLib.inf}                                                     | 11 +--
 StandaloneMmPkg/Library/{StandaloneMmCoreMemoryAllocationLib/StandaloneMmCoreMemoryAllocationLib.inf => StandaloneMmMemoryAllocationLib/StandaloneMmMemoryAllocationLib.inf} | 14 ++-
 StandaloneMmPkg/Library/StandaloneMmServicesTableLib/StandaloneMmServicesTableLib.inf                                                                                        | 36 ++++++++
 MdePkg/Include/Library/SmmServicesTableLib.h => StandaloneMmPkg/Include/Library/StandaloneMmServicesTableLib.h                                                               | 90 ++++++++++----------
 StandaloneMmPkg/Library/{StandaloneMmCoreHobLib => StandaloneMmHobLib}/AArch64/StandaloneMmCoreHobLibInternal.c                                                              |  4 +-
 StandaloneMmPkg/Library/{StandaloneMmCoreHobLib/StandaloneMmCoreHobLib.c => StandaloneMmHobLib/StandaloneMmHobLib.c}                                                         | 55 +++++++++++-
 MdePkg/Library/UefiMemoryAllocationLib/MemoryAllocationLib.c => StandaloneMmPkg/Library/StandaloneMmMemoryAllocationLib/StandaloneMmMemoryAllocationLib.c                    | 69 ++++++++-------
 MdeModulePkg/Library/PiSmmCoreSmmServicesTableLib/PiSmmCoreSmmServicesTableLib.c => StandaloneMmPkg/Library/StandaloneMmServicesTableLib/StandaloneMmServicesTableLib.c      | 34 ++++----
 9 files changed, 203 insertions(+), 112 deletions(-)

diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmCoreHobLib.inf b/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmCoreHobLib.inf
index db19d3c926e8..ac036e31cf5e 100644
--- a/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmCoreHobLib.inf
+++ b/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmCoreHobLib.inf
@@ -24,7 +24,7 @@ [Defines]
   MODULE_TYPE                    = MM_CORE_STANDALONE
   VERSION_STRING                 = 1.0
   PI_SPECIFICATION_VERSION       = 0x00010032
-  LIBRARY_CLASS                  = HobLib|MM_CORE_STANDALONE MM_STANDALONE
+  LIBRARY_CLASS                  = HobLib|MM_CORE_STANDALONE
 
 #
 #  VALID_ARCHITECTURES           = AARCH64
diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmCoreHobLib.inf b/StandaloneMmPkg/Library/StandaloneMmHobLib/StandaloneMmHobLib.inf
similarity index 79%
copy from StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmCoreHobLib.inf
copy to StandaloneMmPkg/Library/StandaloneMmHobLib/StandaloneMmHobLib.inf
index db19d3c926e8..d73188ec1b57 100644
--- a/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmCoreHobLib.inf
+++ b/StandaloneMmPkg/Library/StandaloneMmHobLib/StandaloneMmHobLib.inf
@@ -20,17 +20,17 @@
 [Defines]
   INF_VERSION                    = 0x0001001A
   BASE_NAME                      = HobLib
-  FILE_GUID                      = CF56EF2C-68D8-4BD5-9A8B-8A7BFCFF751C
-  MODULE_TYPE                    = MM_CORE_STANDALONE
+  FILE_GUID                      = 8262551B-AB2D-4E76-99FC-5EBB83F4988E
+  MODULE_TYPE                    = MM_STANDALONE
   VERSION_STRING                 = 1.0
   PI_SPECIFICATION_VERSION       = 0x00010032
-  LIBRARY_CLASS                  = HobLib|MM_CORE_STANDALONE MM_STANDALONE
-
+  LIBRARY_CLASS                  = HobLib|MM_STANDALONE
+  CONSTRUCTOR                    = HobLibConstructor
 #
 #  VALID_ARCHITECTURES           = AARCH64
 #
 [Sources.Common]
-  StandaloneMmCoreHobLib.c
+  StandaloneMmHobLib.c
 
 [Sources.AARCH64]
   AArch64/StandaloneMmCoreHobLibInternal.c
@@ -42,6 +42,7 @@ [Packages]
 [LibraryClasses]
   BaseMemoryLib
   DebugLib
+  MmServicesTableLib
 
 [Guids]
   gEfiHobListGuid                               ## CONSUMES  ## SystemTable
diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreMemoryAllocationLib/StandaloneMmCoreMemoryAllocationLib.inf b/StandaloneMmPkg/Library/StandaloneMmMemoryAllocationLib/StandaloneMmMemoryAllocationLib.inf
similarity index 76%
copy from StandaloneMmPkg/Library/StandaloneMmCoreMemoryAllocationLib/StandaloneMmCoreMemoryAllocationLib.inf
copy to StandaloneMmPkg/Library/StandaloneMmMemoryAllocationLib/StandaloneMmMemoryAllocationLib.inf
index 3958655cb4cf..9ac03df4caad 100644
--- a/StandaloneMmPkg/Library/StandaloneMmCoreMemoryAllocationLib/StandaloneMmCoreMemoryAllocationLib.inf
+++ b/StandaloneMmPkg/Library/StandaloneMmMemoryAllocationLib/StandaloneMmMemoryAllocationLib.inf
@@ -19,22 +19,20 @@
 [Defines]
   INF_VERSION                    = 0x0001001A
   BASE_NAME                      = MemoryAllocationLib
-  FILE_GUID                      = DCDCBE1D-E760-4E1D-85B4-96E3F0439C41
+  FILE_GUID                      = 54646378-A9DC-473F-9BE1-BD027C4C76DE
   MODULE_TYPE                    = MM_CORE_STANDALONE
   VERSION_STRING                 = 1.0
   PI_SPECIFICATION_VERSION       = 0x00010032
-  LIBRARY_CLASS                  = MemoryAllocationLib|MM_CORE_STANDALONE
-  CONSTRUCTOR                    = MemoryAllocationLibConstructor
+  LIBRARY_CLASS                  = MemoryAllocationLib|MM_STANDALONE
 
 #
 # The following information is for reference only and not required by the build tools.
 #
-#  VALID_ARCHITECTURES           = IA32 X64
+#  VALID_ARCHITECTURES           = IA32 X64 AARCH64
 #
 
 [Sources]
-  StandaloneMmCoreMemoryAllocationLib.c
-  StandaloneMmCoreMemoryAllocationServices.h
+  StandaloneMmMemoryAllocationLib.c
 
 [Packages]
   MdePkg/MdePkg.dec
@@ -43,7 +41,5 @@ [Packages]
 [LibraryClasses]
   BaseMemoryLib
   DebugLib
+  MmServicesTableLib
   HobLib
-
-[Guids]
-  gEfiMmPeiMmramMemoryReserveGuid
diff --git a/StandaloneMmPkg/Library/StandaloneMmServicesTableLib/StandaloneMmServicesTableLib.inf b/StandaloneMmPkg/Library/StandaloneMmServicesTableLib/StandaloneMmServicesTableLib.inf
new file mode 100644
index 000000000000..c36242914229
--- /dev/null
+++ b/StandaloneMmPkg/Library/StandaloneMmServicesTableLib/StandaloneMmServicesTableLib.inf
@@ -0,0 +1,36 @@
+## @file
+# MM Core MM Services Table Library.
+#
+# Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2016 - 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                      = StandaloneMmServicesTableLib
+  FILE_GUID                      = BEE33A2F-F49D-4B71-AF3E-FFCCB9885DEA
+  MODULE_TYPE                    = MM_STANDALONE
+  VERSION_STRING                 = 1.0
+  PI_SPECIFICATION_VERSION       = 0x00010032
+  LIBRARY_CLASS                  = MmServicesTableLib|MM_STANDALONE
+  CONSTRUCTOR                    = StandaloneMmServicesTableLibConstructor
+
+#
+#  VALID_ARCHITECTURES           = IA32 X64 AARCH64
+#
+
+[Sources]
+  StandaloneMmServicesTableLib.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+
diff --git a/MdePkg/Include/Library/SmmServicesTableLib.h b/StandaloneMmPkg/Include/Library/StandaloneMmServicesTableLib.h
similarity index 55%
copy from MdePkg/Include/Library/SmmServicesTableLib.h
copy to StandaloneMmPkg/Include/Library/StandaloneMmServicesTableLib.h
index 01e999d234e7..e7a670d3636d 100644
--- a/MdePkg/Include/Library/SmmServicesTableLib.h
+++ b/StandaloneMmPkg/Include/Library/StandaloneMmServicesTableLib.h
@@ -1,43 +1,47 @@
-/** @file
-  Provides a service to retrieve a pointer to the SMM Services Table.
-  Only available to SMM module types.
-
-Copyright (c) 2009 - 2018, Intel Corporation. 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.
-
-**/
-
-#ifndef __SMM_SERVICES_TABLE_LIB_H__
-#define __SMM_SERVICES_TABLE_LIB_H__
-
-#include <PiSmm.h>
-
-///
-/// Cache pointer to the SMM Services Table
-///
-extern EFI_SMM_SYSTEM_TABLE2   *gSmst;
-
-/**
-  This function allows the caller to determine if the driver is executing in
-  System Management Mode(SMM).
-
-  This function returns TRUE if the driver is executing in SMM and FALSE if the
-  driver is not executing in SMM.
-
-  @retval  TRUE  The driver is executing in System Management Mode (SMM).
-  @retval  FALSE The driver is not executing in System Management Mode (SMM).
-
-**/
-BOOLEAN
-EFIAPI
-InSmm (
-  VOID
-  );
-
-#endif
+/** @file
+  Provides a service to retrieve a pointer to the Standalone MM Services Table.
+  Only available to Standalone MM module types.
+
+Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2016 - 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.
+
+**/
+
+#ifndef __MM_SERVICES_TABLE_LIB_H__
+#define __MM_SERVICES_TABLE_LIB_H__
+
+#include <PiMm.h>
+#include <Library/DebugLib.h>
+
+///
+/// Cache pointer to the Standalone MM Services Table
+
+extern EFI_MM_SYSTEM_TABLE         *gMmst;
+
+
+/**
+  This function allows the caller to determine if the driver is executing in
+  Standalone Management Mode(SMM).
+
+  This function returns TRUE if the driver is executing in SMM and FALSE if the
+  driver is not executing in SMM.
+
+  @retval  TRUE  The driver is executing in Standalone Management Mode (SMM).
+  @retval  FALSE The driver is not executing in Standalone Management Mode (SMM).
+
+**/
+BOOLEAN
+EFIAPI
+InMm (
+  VOID
+  );
+
+#endif
diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/AArch64/StandaloneMmCoreHobLibInternal.c b/StandaloneMmPkg/Library/StandaloneMmHobLib/AArch64/StandaloneMmCoreHobLibInternal.c
similarity index 90%
copy from StandaloneMmPkg/Library/StandaloneMmCoreHobLib/AArch64/StandaloneMmCoreHobLibInternal.c
copy to StandaloneMmPkg/Library/StandaloneMmHobLib/AArch64/StandaloneMmCoreHobLibInternal.c
index 90e1cd479cb2..ac5a1c039f6a 100644
--- a/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/AArch64/StandaloneMmCoreHobLibInternal.c
+++ b/StandaloneMmPkg/Library/StandaloneMmHobLib/AArch64/StandaloneMmCoreHobLibInternal.c
@@ -42,11 +42,11 @@ HobConstructor (
   HobEnd = (EFI_HOB_GENERIC_HEADER *)(Hob+1);
 
   Hob->Header.HobType     = EFI_HOB_TYPE_HANDOFF;
-  Hob->Header.HobLength   = sizeof (EFI_HOB_HANDOFF_INFO_TABLE);
+  Hob->Header.HobLength   = sizeof(EFI_HOB_HANDOFF_INFO_TABLE);
   Hob->Header.Reserved    = 0;
 
   HobEnd->HobType     = EFI_HOB_TYPE_END_OF_HOB_LIST;
-  HobEnd->HobLength   = sizeof (EFI_HOB_GENERIC_HEADER);
+  HobEnd->HobLength   = sizeof(EFI_HOB_GENERIC_HEADER);
   HobEnd->Reserved    = 0;
 
   Hob->Version             = EFI_HOB_HANDOFF_TABLE_VERSION;
diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmCoreHobLib.c b/StandaloneMmPkg/Library/StandaloneMmHobLib/StandaloneMmHobLib.c
similarity index 88%
copy from StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmCoreHobLib.c
copy to StandaloneMmPkg/Library/StandaloneMmHobLib/StandaloneMmHobLib.c
index e2fcda813d1b..591a78c7f3b6 100644
--- a/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmCoreHobLib.c
+++ b/StandaloneMmPkg/Library/StandaloneMmHobLib/StandaloneMmHobLib.c
@@ -27,6 +27,43 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 //
 VOID *gHobList = NULL;
 
+EFI_MM_SYSTEM_TABLE   *gMmst = NULL;
+
+/**
+  The constructor function caches the pointer to HOB list.
+
+  The constructor function gets the start address of HOB list from system configuration table.
+  It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.
+
+  @param  ImageHandle   The firmware allocated handle for the EFI image.
+  @param  SystemTable   A pointer to the EFI System Table.
+
+  @retval EFI_SUCCESS   The constructor successfully gets HobList.
+  @retval Other value   The constructor can't get HobList.
+
+**/
+EFI_STATUS
+EFIAPI
+HobLibConstructor (
+  IN EFI_HANDLE             ImageHandle,
+  IN EFI_MM_SYSTEM_TABLE  *SmmSystemTable
+  )
+{
+  UINTN       Index;
+
+  for (Index = 0; Index < gMmst->NumberOfTableEntries; Index++) {
+    if (CompareGuid (&gEfiHobListGuid, &gMmst->MmConfigurationTable[Index].VendorGuid)) {
+      gHobList = gMmst->MmConfigurationTable[Index].VendorTable;
+      break;
+    }
+  }
+
+  /* HACK: Use the ImageHandle to smuggle the hoblist into the library constructor */
+  if (ImageHandle)
+	  gHobList = (VOID *) ImageHandle;
+
+  return EFI_SUCCESS;
+}
 /**
   Returns the pointer to the HOB list.
 
@@ -42,6 +79,16 @@ GetHobList (
   VOID
   )
 {
+  UINTN       Index;
+
+  if (gHobList == NULL) {
+    for (Index = 0; Index < gMmst->NumberOfTableEntries; Index++) {
+      if (CompareGuid (&gEfiHobListGuid, &gMmst->MmConfigurationTable[Index].VendorGuid)) {
+        gHobList = gMmst->MmConfigurationTable[Index].VendorTable;
+        break;
+      }
+    }
+  }
   ASSERT (gHobList != NULL);
   return gHobList;
 }
@@ -206,7 +253,7 @@ GetBootModeHob (
 
   HandOffHob = (EFI_HOB_HANDOFF_INFO_TABLE *) GetHobList ();
 
-  return HandOffHob->BootMode;
+  return  HandOffHob->BootMode;
 }
 
 VOID *
@@ -227,7 +274,7 @@ CreateHob (
   FreeMemory = HandOffHob->EfiFreeMemoryTop - HandOffHob->EfiFreeMemoryBottom;
 
   if (FreeMemory < HobLength) {
-    return NULL;
+      return NULL;
   }
 
   Hob = (VOID*) (UINTN) HandOffHob->EfiEndOfHobList;
@@ -239,7 +286,7 @@ CreateHob (
   HandOffHob->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd;
 
   HobEnd->HobType   = EFI_HOB_TYPE_END_OF_HOB_LIST;
-  HobEnd->HobLength = sizeof (EFI_HOB_GENERIC_HEADER);
+  HobEnd->HobLength = sizeof(EFI_HOB_GENERIC_HEADER);
   HobEnd->Reserved  = 0;
   HobEnd++;
   HandOffHob->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd;
@@ -314,7 +361,7 @@ BuildResourceDescriptorHob (
   EFI_HOB_RESOURCE_DESCRIPTOR  *Hob;
 
   Hob = CreateHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, sizeof (EFI_HOB_RESOURCE_DESCRIPTOR));
-  ASSERT (Hob != NULL);
+  ASSERT(Hob != NULL);
 
   Hob->ResourceType      = ResourceType;
   Hob->ResourceAttribute = ResourceAttribute;
diff --git a/MdePkg/Library/UefiMemoryAllocationLib/MemoryAllocationLib.c b/StandaloneMmPkg/Library/StandaloneMmMemoryAllocationLib/StandaloneMmMemoryAllocationLib.c
similarity index 89%
copy from MdePkg/Library/UefiMemoryAllocationLib/MemoryAllocationLib.c
copy to StandaloneMmPkg/Library/StandaloneMmMemoryAllocationLib/StandaloneMmMemoryAllocationLib.c
index dce13bbdf5e6..e989f277c159 100644
--- a/MdePkg/Library/UefiMemoryAllocationLib/MemoryAllocationLib.c
+++ b/StandaloneMmPkg/Library/StandaloneMmMemoryAllocationLib/StandaloneMmMemoryAllocationLib.c
@@ -1,27 +1,28 @@
 /** @file
-  Support routines for memory allocation routines based
-  on boot services for Dxe phase drivers.
+  Support routines for memory allocation routines based on Standalone MM Core internal functions.
+
+  Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.<BR>
 
-  Copyright (c) 2006 - 2018, Intel Corporation. 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.
+  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 <PiMm.h>
 
-#include <Uefi.h>
-
-
+#include <Guid/MmramMemoryReserve.h>
 #include <Library/MemoryAllocationLib.h>
-#include <Library/UefiBootServicesTableLib.h>
 #include <Library/BaseMemoryLib.h>
 #include <Library/DebugLib.h>
 
+extern EFI_MM_SYSTEM_TABLE   *gMmst;
+
 /**
   Allocates one or more 4KB pages of a certain memory type.
 
@@ -48,7 +49,7 @@ InternalAllocatePages (
     return NULL;
   }
 
-  Status = gBS->AllocatePages (AllocateAnyPages, MemoryType, Pages, &Memory);
+  Status = gMmst->MmAllocatePages (AllocateAnyPages, MemoryType, Pages, &Memory);
   if (EFI_ERROR (Status)) {
     return NULL;
   }
@@ -74,7 +75,7 @@ AllocatePages (
   IN UINTN  Pages
   )
 {
-  return InternalAllocatePages (EfiBootServicesData, Pages);
+  return InternalAllocatePages (EfiRuntimeServicesData, Pages);
 }
 
 /**
@@ -118,7 +119,7 @@ AllocateReservedPages (
   IN UINTN  Pages
   )
 {
-  return InternalAllocatePages (EfiReservedMemoryType, Pages);
+  return NULL;
 }
 
 /**
@@ -134,7 +135,7 @@ AllocateReservedPages (
   then ASSERT().
   If Pages is zero, then ASSERT().
 
-  @param  Buffer                The pointer to the buffer of pages to free.
+  @param  Buffer                Pointer to the buffer of pages to free.
   @param  Pages                 The number of 4 KB pages to free.
 
 **/
@@ -148,7 +149,7 @@ FreePages (
   EFI_STATUS  Status;
 
   ASSERT (Pages != 0);
-  Status = gBS->FreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) Buffer, Pages);
+  Status = gMmst->MmFreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) Buffer, Pages);
   ASSERT_EFI_ERROR (Status);
 }
 
@@ -203,7 +204,7 @@ InternalAllocateAlignedPages (
     //
     ASSERT (RealPages > Pages);
 
-    Status         = gBS->AllocatePages (AllocateAnyPages, MemoryType, RealPages, &Memory);
+    Status         = gMmst->MmAllocatePages (AllocateAnyPages, MemoryType, RealPages, &Memory);
     if (EFI_ERROR (Status)) {
       return NULL;
     }
@@ -213,23 +214,23 @@ InternalAllocateAlignedPages (
       //
       // Free first unaligned page(s).
       //
-      Status = gBS->FreePages (Memory, UnalignedPages);
+      Status = gMmst->MmFreePages (Memory, UnalignedPages);
       ASSERT_EFI_ERROR (Status);
     }
-    Memory         = AlignedMemory + EFI_PAGES_TO_SIZE (Pages);
+    Memory         = (EFI_PHYSICAL_ADDRESS) (AlignedMemory + EFI_PAGES_TO_SIZE (Pages));
     UnalignedPages = RealPages - Pages - UnalignedPages;
     if (UnalignedPages > 0) {
       //
       // Free last unaligned page(s).
       //
-      Status = gBS->FreePages (Memory, UnalignedPages);
+      Status = gMmst->MmFreePages (Memory, UnalignedPages);
       ASSERT_EFI_ERROR (Status);
     }
   } else {
     //
     // Do not over-allocate pages in this case.
     //
-    Status = gBS->AllocatePages (AllocateAnyPages, MemoryType, Pages, &Memory);
+    Status = gMmst->MmAllocatePages (AllocateAnyPages, MemoryType, Pages, &Memory);
     if (EFI_ERROR (Status)) {
       return NULL;
     }
@@ -263,7 +264,7 @@ AllocateAlignedPages (
   IN UINTN  Alignment
   )
 {
-  return InternalAllocateAlignedPages (EfiBootServicesData, Pages, Alignment);
+  return InternalAllocateAlignedPages (EfiRuntimeServicesData, Pages, Alignment);
 }
 
 /**
@@ -319,7 +320,7 @@ AllocateAlignedReservedPages (
   IN UINTN  Alignment
   )
 {
-  return InternalAllocateAlignedPages (EfiReservedMemoryType, Pages, Alignment);
+  return NULL;
 }
 
 /**
@@ -335,7 +336,7 @@ AllocateAlignedReservedPages (
   Library, then ASSERT().
   If Pages is zero, then ASSERT().
 
-  @param  Buffer                The pointer to the buffer of pages to free.
+  @param  Buffer                Pointer to the buffer of pages to free.
   @param  Pages                 The number of 4 KB pages to free.
 
 **/
@@ -349,7 +350,7 @@ FreeAlignedPages (
   EFI_STATUS  Status;
 
   ASSERT (Pages != 0);
-  Status = gBS->FreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) Buffer, Pages);
+  Status = gMmst->MmFreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) Buffer, Pages);
   ASSERT_EFI_ERROR (Status);
 }
 
@@ -375,7 +376,9 @@ InternalAllocatePool (
   EFI_STATUS  Status;
   VOID        *Memory;
 
-  Status = gBS->AllocatePool (MemoryType, AllocationSize, &Memory);
+  Memory = NULL;
+
+  Status = gMmst->MmAllocatePool (MemoryType, AllocationSize, &Memory);
   if (EFI_ERROR (Status)) {
     Memory = NULL;
   }
@@ -400,7 +403,7 @@ AllocatePool (
   IN UINTN  AllocationSize
   )
 {
-  return InternalAllocatePool (EfiBootServicesData, AllocationSize);
+  return InternalAllocatePool (EfiRuntimeServicesData, AllocationSize);
 }
 
 /**
@@ -442,7 +445,7 @@ AllocateReservedPool (
   IN UINTN  AllocationSize
   )
 {
-  return InternalAllocatePool (EfiReservedMemoryType, AllocationSize);
+  return NULL;
 }
 
 /**
@@ -493,7 +496,7 @@ AllocateZeroPool (
   IN UINTN  AllocationSize
   )
 {
-  return InternalAllocateZeroPool (EfiBootServicesData, AllocationSize);
+  return InternalAllocateZeroPool (EfiRuntimeServicesData, AllocationSize);
 }
 
 /**
@@ -537,7 +540,7 @@ AllocateReservedZeroPool (
   IN UINTN  AllocationSize
   )
 {
-  return InternalAllocateZeroPool (EfiReservedMemoryType, AllocationSize);
+  return NULL;
 }
 
 /**
@@ -600,7 +603,7 @@ AllocateCopyPool (
   IN CONST VOID  *Buffer
   )
 {
-  return InternalAllocateCopyPool (EfiBootServicesData, AllocationSize, Buffer);
+  return InternalAllocateCopyPool (EfiRuntimeServicesData, AllocationSize, Buffer);
 }
 
 /**
@@ -654,7 +657,7 @@ AllocateReservedCopyPool (
   IN CONST VOID  *Buffer
   )
 {
-  return InternalAllocateCopyPool (EfiReservedMemoryType, AllocationSize, Buffer);
+  return NULL;
 }
 
 /**
@@ -726,7 +729,7 @@ ReallocatePool (
   IN VOID   *OldBuffer  OPTIONAL
   )
 {
-  return InternalReallocatePool (EfiBootServicesData, OldSize, NewSize, OldBuffer);
+  return InternalReallocatePool (EfiRuntimeServicesData, OldSize, NewSize, OldBuffer);
 }
 
 /**
@@ -790,7 +793,7 @@ ReallocateReservedPool (
   IN VOID   *OldBuffer  OPTIONAL
   )
 {
-  return InternalReallocatePool (EfiReservedMemoryType, OldSize, NewSize, OldBuffer);
+  return NULL;
 }
 
 /**
@@ -804,7 +807,7 @@ ReallocateReservedPool (
   If Buffer was not allocated with a pool allocation function in the Memory Allocation Library,
   then ASSERT().
 
-  @param  Buffer                The pointer to the buffer to free.
+  @param  Buffer                Pointer to the buffer to free.
 
 **/
 VOID
@@ -815,7 +818,7 @@ FreePool (
 {
   EFI_STATUS    Status;
 
-  Status = gBS->FreePool (Buffer);
+  Status = gMmst->MmFreePool (Buffer);
   ASSERT_EFI_ERROR (Status);
 }
 
diff --git a/MdeModulePkg/Library/PiSmmCoreSmmServicesTableLib/PiSmmCoreSmmServicesTableLib.c b/StandaloneMmPkg/Library/StandaloneMmServicesTableLib/StandaloneMmServicesTableLib.c
similarity index 56%
copy from MdeModulePkg/Library/PiSmmCoreSmmServicesTableLib/PiSmmCoreSmmServicesTableLib.c
copy to StandaloneMmPkg/Library/StandaloneMmServicesTableLib/StandaloneMmServicesTableLib.c
index c1ea2944338d..e0e004406287 100644
--- a/MdeModulePkg/Library/PiSmmCoreSmmServicesTableLib/PiSmmCoreSmmServicesTableLib.c
+++ b/StandaloneMmPkg/Library/StandaloneMmServicesTableLib/StandaloneMmServicesTableLib.c
@@ -1,7 +1,9 @@
 /** @file
-  SMM Core SMM Services Table Library.
+  MM Core MM Services Table Library.
+
+  Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.<BR>
 
-  Copyright (c) 2010 - 2018, Intel Corporation. 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
@@ -12,15 +14,13 @@
 
 **/
 
-#include <PiSmm.h>
-#include <Library/SmmServicesTableLib.h>
+#include <PiMm.h>
 #include <Library/DebugLib.h>
 
-EFI_SMM_SYSTEM_TABLE2         *gSmst = NULL;
-extern EFI_SMM_SYSTEM_TABLE2  gSmmCoreSmst;
+extern EFI_MM_SYSTEM_TABLE         *gMmst;
 
 /**
-  The constructor function caches the pointer of SMM Services Table.
+  The constructor function caches the pointer of MM Services Table.
 
   @param  ImageHandle   The firmware allocated handle for the EFI image.
   @param  SystemTable   A pointer to the EFI System Table.
@@ -30,31 +30,35 @@ extern EFI_SMM_SYSTEM_TABLE2  gSmmCoreSmst;
 **/
 EFI_STATUS
 EFIAPI
-SmmCoreSmmServicesTableLibConstructor (
-  IN EFI_HANDLE        ImageHandle,
-  IN EFI_SYSTEM_TABLE  *SystemTable
+StandaloneMmServicesTableLibConstructor (
+  IN EFI_HANDLE             ImageHandle,
+  IN EFI_MM_SYSTEM_TABLE  *MmSystemTable
   )
 {
-  gSmst = &gSmmCoreSmst;
+  gMmst = MmSystemTable;
   return EFI_SUCCESS;
 }
 
 /**
   This function allows the caller to determine if the driver is executing in
-  System Management Mode(SMM).
+  Standalone Management Mode(SMM).
 
   This function returns TRUE if the driver is executing in SMM and FALSE if the
   driver is not executing in SMM.
 
-  @retval  TRUE  The driver is executing in System Management Mode (SMM).
-  @retval  FALSE The driver is not executing in System Management Mode (SMM).
+  @retval  TRUE  The driver is executing in Standalone Management Mode (SMM).
+  @retval  FALSE The driver is not executing in Standalone Management Mode (SMM).
 
 **/
 BOOLEAN
 EFIAPI
-InSmm (
+InMm (
   VOID
   )
 {
+  //
+  // We are already in Standalone MM
+  //
   return TRUE;
 }
+
-- 
2.7.4



  parent reply	other threads:[~2018-11-28  9:35 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-28  9:34 [RFC PATCH v3 00/11] Extend secure variable service to be usable from Standalone MM Jagadeesh Ujja
2018-11-28  9:34 ` [RFC PATCH v3 01/11] MdeModulePkg/Variable: replace all uses of AsmLfence with MemoryFence Jagadeesh Ujja
2018-11-28  9:35 ` Jagadeesh Ujja [this message]
2018-11-28  9:35 ` [RFC PATCH v3 03/11] MdeModulePkg/Library: Add StandaloneMmRuntimeDxe library Jagadeesh Ujja
2018-11-28  9:35 ` [RFC PATCH v3 04/11] ArmPlatformPkg/NorFlashDxe: allow reusability as a MM driver Jagadeesh Ujja
2018-11-28  9:35 ` [RFC PATCH v3 05/11] MdeModulePkg/FaultTolerantWriteDxe: " Jagadeesh Ujja
2018-11-28  9:35 ` [RFC PATCH v3 06/11] MdeModulePkg/Variable/RuntimeDxe: adapt for usability with MM Standalone Jagadeesh Ujja
2018-11-28  9:35 ` [RFC PATCH v3 07/11] MdeModulePkg/Variable/RuntimeDxe: adapt as a MM Standalone driver Jagadeesh Ujja
2018-11-28  9:35 ` [RFC PATCH v3 08/11] SecurityPkg/AuthVariableLib: allow MM_STANDALONE drivers to use this library Jagadeesh Ujja
2018-11-28  9:35 ` [RFC PATCH v3 09/11] MdeModulePkg/VarCheckLib: " Jagadeesh Ujja
2018-11-28  9:35 ` [RFC PATCH v3 10/11] CryptoPkg/BaseCryptLib: " Jagadeesh Ujja
2018-11-28  9:35 ` [RFC PATCH v3 11/11] CryptoPkg/BaseCryptLib: Hack to get time in MM Standalone mode Jagadeesh Ujja
2018-11-30  8:15   ` Ye, Ting
2018-11-29 15:57 ` [RFC PATCH v3 00/11] Extend secure variable service to be usable from Standalone MM Gao, Liming
2018-12-11  5:28   ` jagadeesh ujja

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=1543397709-31847-3-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