public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Sughosh Ganu <sughosh.ganu@arm.com>
To: edk2-devel@lists.01.org
Cc: Achin Gupta <achin.gupta@arm.com>,
	Jiewen Yao <jiewen.yao@intel.com>,
	Supreeth Venkatesh <supreeth.venkatesh@arm.com>,
	Sughosh Ganu <sughosh.ganu@arm.com>
Subject: [PATCH v2 03/10] StandaloneMmPkg/MemLib: Add Standalone MM instance of memory check library.
Date: Fri, 13 Jul 2018 20:35:23 +0530	[thread overview]
Message-ID: <1531494330-1280-4-git-send-email-sughosh.ganu@arm.com> (raw)
In-Reply-To: <1531494330-1280-1-git-send-email-sughosh.ganu@arm.com>

From: Supreeth Venkatesh <supreeth.venkatesh@arm.com>

MM memory check library library implementation. This library consumes
MM_ACCESS_PROTOCOL to get MMRAM information. In order to use this
library instance, the platform should produce all MMRAM range via
MM_ACCESS_PROTOCOL, including the range for firmware (like MM Core
and MM driver) and/or specific dedicated hardware.

This patch provides services for MM Memory Operation.
The management mode Mem Library provides function for checking if buffer
is outside MMRAM and valid. It also provides functions for copy data
from MMRAM to non-MMRAM, from non-MMRAM to MMRAM,
from non-MMRAM to non-MMRAM, or set data in non-MMRAM.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Supreeth Venkatesh <supreeth.venkatesh@arm.com>
Reviewed-by: Achin Gupta <achin.gupta@arm.com>
Reviewed-by: Jiewen Yao <Jiewen.yao@intel.com>
Signed-off-by: Sughosh Ganu <sughosh.ganu@arm.com>
---
 .../Include/Library/StandaloneMmMemLib.h           |  66 ++---
 .../AArch64/StandaloneMmMemLibInternal.c           |  49 ++++
 .../StandaloneMmMemLib/StandaloneMmMemLib.c        | 269 +++++++++++++++++++++
 .../StandaloneMmMemLib/StandaloneMmMemLib.inf      |  50 ++++
 4 files changed, 402 insertions(+), 32 deletions(-)
 copy MdePkg/Include/Library/SmmMemLib.h => StandaloneMmPkg/Include/Library/StandaloneMmMemLib.h (68%)
 create mode 100644 StandaloneMmPkg/Library/StandaloneMmMemLib/AArch64/StandaloneMmMemLibInternal.c
 create mode 100644 StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.c
 create mode 100644 StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.inf

diff --git a/MdePkg/Include/Library/SmmMemLib.h b/StandaloneMmPkg/Include/Library/StandaloneMmMemLib.h
similarity index 68%
copy from MdePkg/Include/Library/SmmMemLib.h
copy to StandaloneMmPkg/Include/Library/StandaloneMmMemLib.h
index e7848b2bce73..8e3f2801aa61 100644
--- a/MdePkg/Include/Library/SmmMemLib.h
+++ b/StandaloneMmPkg/Include/Library/StandaloneMmMemLib.h
@@ -1,11 +1,13 @@
 /** @file
-  Provides services for SMM Memory Operation.
+  Provides services for MM Memory Operation.
 
-  The SMM Mem Library provides function for checking if buffer is outside SMRAM and valid.
-  It also provides functions for copy data from SMRAM to non-SMRAM, from non-SMRAM to SMRAM,
-  from non-SMRAM to non-SMRAM, or set data in non-SMRAM.
+  The MM Mem Library provides function for checking if buffer is outside MMRAM and valid.
+  It also provides functions for copy data from MMRAM to non-MMRAM, from non-MMRAM to MMRAM,
+  from non-MMRAM to non-MMRAM, or set data in non-MMRAM.
+
+  Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.<BR>
 
-  Copyright (c) 2015 - 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
@@ -16,30 +18,30 @@
 
 **/
 
-#ifndef _SMM_MEM_LIB_H_
-#define _SMM_MEM_LIB_H_
+#ifndef _MM_MEM_LIB_H_
+#define _MM_MEM_LIB_H_
 
 /**
-  This function check if the buffer is valid per processor architecture and not overlap with SMRAM.
+  This function check if the buffer is valid per processor architecture and not overlap with MMRAM.
 
   @param Buffer  The buffer start address to be checked.
   @param Length  The buffer length to be checked.
 
-  @retval TRUE  This buffer is valid per processor architecture and not overlap with SMRAM.
-  @retval FALSE This buffer is not valid per processor architecture or overlap with SMRAM.
+  @retval TRUE  This buffer is valid per processor architecture and not overlap with MMRAM.
+  @retval FALSE This buffer is not valid per processor architecture or overlap with MMRAM.
 **/
 BOOLEAN
 EFIAPI
-SmmIsBufferOutsideSmmValid (
+MmIsBufferOutsideMmValid (
   IN EFI_PHYSICAL_ADDRESS  Buffer,
   IN UINT64                Length
   );
 
 /**
-  Copies a source buffer (non-SMRAM) to a destination buffer (SMRAM).
+  Copies a source buffer (non-MMRAM) to a destination buffer (MMRAM).
 
-  This function copies a source buffer (non-SMRAM) to a destination buffer (SMRAM).
-  It checks if source buffer is valid per processor architecture and not overlap with SMRAM.
+  This function copies a source buffer (non-MMRAM) to a destination buffer (MMRAM).
+  It checks if source buffer is valid per processor architecture and not overlap with MMRAM.
   If the check passes, it copies memory and returns EFI_SUCCESS.
   If the check fails, it return EFI_SECURITY_VIOLATION.
   The implementation must be reentrant.
@@ -48,23 +50,23 @@ SmmIsBufferOutsideSmmValid (
   @param  SourceBuffer        The pointer to the source buffer of the memory copy.
   @param  Length              The number of bytes to copy from SourceBuffer to DestinationBuffer.
 
-  @retval EFI_SECURITY_VIOLATION The SourceBuffer is invalid per processor architecture or overlap with SMRAM.
+  @retval EFI_SECURITY_VIOLATION The SourceBuffer is invalid per processor architecture or overlap with MMRAM.
   @retval EFI_SUCCESS            Memory is copied.
 
 **/
 EFI_STATUS
 EFIAPI
-SmmCopyMemToSmram (
+MmCopyMemToMmram (
   OUT VOID       *DestinationBuffer,
   IN CONST VOID  *SourceBuffer,
   IN UINTN       Length
   );
 
 /**
-  Copies a source buffer (SMRAM) to a destination buffer (NON-SMRAM).
+  Copies a source buffer (MMRAM) to a destination buffer (NON-MMRAM).
 
-  This function copies a source buffer (non-SMRAM) to a destination buffer (SMRAM).
-  It checks if destination buffer is valid per processor architecture and not overlap with SMRAM.
+  This function copies a source buffer (non-MMRAM) to a destination buffer (MMRAM).
+  It checks if destination buffer is valid per processor architecture and not overlap with MMRAM.
   If the check passes, it copies memory and returns EFI_SUCCESS.
   If the check fails, it returns EFI_SECURITY_VIOLATION.
   The implementation must be reentrant.
@@ -73,23 +75,23 @@ SmmCopyMemToSmram (
   @param  SourceBuffer        The pointer to the source buffer of the memory copy.
   @param  Length              The number of bytes to copy from SourceBuffer to DestinationBuffer.
 
-  @retval EFI_SECURITY_VIOLATION The DesinationBuffer is invalid per processor architecture or overlap with SMRAM.
+  @retval EFI_SECURITY_VIOLATION The DesinationBuffer is invalid per processor architecture or overlap with MMRAM.
   @retval EFI_SUCCESS            Memory is copied.
 
 **/
 EFI_STATUS
 EFIAPI
-SmmCopyMemFromSmram (
+MmCopyMemFromMmram (
   OUT VOID       *DestinationBuffer,
   IN CONST VOID  *SourceBuffer,
   IN UINTN       Length
   );
 
 /**
-  Copies a source buffer (NON-SMRAM) to a destination buffer (NON-SMRAM).
+  Copies a source buffer (NON-MMRAM) to a destination buffer (NON-MMRAM).
 
-  This function copies a source buffer (non-SMRAM) to a destination buffer (SMRAM).
-  It checks if source buffer and destination buffer are valid per processor architecture and not overlap with SMRAM.
+  This function copies a source buffer (non-MMRAM) to a destination buffer (MMRAM).
+  It checks if source buffer and destination buffer are valid per processor architecture and not overlap with MMRAM.
   If the check passes, it copies memory and returns EFI_SUCCESS.
   If the check fails, it returns EFI_SECURITY_VIOLATION.
   The implementation must be reentrant, and it must handle the case where source buffer overlaps destination buffer.
@@ -98,24 +100,24 @@ SmmCopyMemFromSmram (
   @param  SourceBuffer        The pointer to the source buffer of the memory copy.
   @param  Length              The number of bytes to copy from SourceBuffer to DestinationBuffer.
 
-  @retval EFI_SECURITY_VIOLATION The DesinationBuffer is invalid per processor architecture or overlap with SMRAM.
-  @retval EFI_SECURITY_VIOLATION The SourceBuffer is invalid per processor architecture or overlap with SMRAM.
+  @retval EFI_SECURITY_VIOLATION The DesinationBuffer is invalid per processor architecture or overlap with MMRAM.
+  @retval EFI_SECURITY_VIOLATION The SourceBuffer is invalid per processor architecture or overlap with MMRAM.
   @retval EFI_SUCCESS            Memory is copied.
 
 **/
 EFI_STATUS
 EFIAPI
-SmmCopyMem (
+MmCopyMem (
   OUT VOID       *DestinationBuffer,
   IN CONST VOID  *SourceBuffer,
   IN UINTN       Length
   );
 
 /**
-  Fills a target buffer (NON-SMRAM) with a byte value.
+  Fills a target buffer (NON-MMRAM) with a byte value.
 
-  This function fills a target buffer (non-SMRAM) with a byte value.
-  It checks if target buffer is valid per processor architecture and not overlap with SMRAM.
+  This function fills a target buffer (non-MMRAM) with a byte value.
+  It checks if target buffer is valid per processor architecture and not overlap with MMRAM.
   If the check passes, it fills memory and returns EFI_SUCCESS.
   If the check fails, it returns EFI_SECURITY_VIOLATION.
 
@@ -123,13 +125,13 @@ SmmCopyMem (
   @param  Length    The number of bytes to set.
   @param  Value     The value with which to fill Length bytes of Buffer.
 
-  @retval EFI_SECURITY_VIOLATION The Buffer is invalid per processor architecture or overlap with SMRAM.
+  @retval EFI_SECURITY_VIOLATION The Buffer is invalid per processor architecture or overlap with MMRAM.
   @retval EFI_SUCCESS            Memory is set.
 
 **/
 EFI_STATUS
 EFIAPI
-SmmSetMem (
+MmSetMem (
   OUT VOID  *Buffer,
   IN UINTN  Length,
   IN UINT8  Value
diff --git a/StandaloneMmPkg/Library/StandaloneMmMemLib/AArch64/StandaloneMmMemLibInternal.c b/StandaloneMmPkg/Library/StandaloneMmMemLib/AArch64/StandaloneMmMemLibInternal.c
new file mode 100644
index 000000000000..b3a586142cbd
--- /dev/null
+++ b/StandaloneMmPkg/Library/StandaloneMmMemLib/AArch64/StandaloneMmMemLibInternal.c
@@ -0,0 +1,49 @@
+/** @file
+  Internal ARCH Specific file of MM memory check library.
+
+  MM memory check library implementation. This library consumes MM_ACCESS_PROTOCOL
+  to get MMRAM information. In order to use this library instance, the platform should produce
+  all MMRAM range via MM_ACCESS_PROTOCOL, including the range for firmware (like MM Core
+  and MM driver) and/or specific dedicated hardware.
+
+  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.
+
+**/
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+//
+// Maximum support address used to check input buffer
+//
+extern EFI_PHYSICAL_ADDRESS  mMmMemLibInternalMaximumSupportAddress;
+
+/**
+  Calculate and save the maximum support address.
+
+**/
+VOID
+MmMemLibInternalCalculateMaximumSupportAddress (
+  VOID
+  )
+{
+  UINT8        PhysicalAddressBits;
+
+  PhysicalAddressBits = 36;
+
+  //
+  // Save the maximum support address in one global variable
+  //
+  mMmMemLibInternalMaximumSupportAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)(LShiftU64 (1, PhysicalAddressBits) - 1);
+  DEBUG ((DEBUG_INFO, "mMmMemLibInternalMaximumSupportAddress = 0x%lx\n", mMmMemLibInternalMaximumSupportAddress));
+}
+
+
diff --git a/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.c b/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.c
new file mode 100644
index 000000000000..ba1a57df96b7
--- /dev/null
+++ b/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.c
@@ -0,0 +1,269 @@
+/** @file
+  Instance of MM memory check library.
+
+  MM memory check library library implementation. This library consumes MM_ACCESS_PROTOCOL
+  to get MMRAM information. In order to use this library instance, the platform should produce
+  all MMRAM range via MM_ACCESS_PROTOCOL, including the range for firmware (like MM Core
+  and MM driver) and/or specific dedicated hardware.
+
+  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.
+
+**/
+
+
+#include <PiMm.h>
+
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+
+EFI_MMRAM_DESCRIPTOR *mMmMemLibInternalMmramRanges;
+UINTN                mMmMemLibInternalMmramCount;
+
+//
+// Maximum support address used to check input buffer
+//
+EFI_PHYSICAL_ADDRESS  mMmMemLibInternalMaximumSupportAddress = 0;
+
+/**
+  Calculate and save the maximum support address.
+
+**/
+VOID
+MmMemLibInternalCalculateMaximumSupportAddress (
+  VOID
+  );
+
+/**
+  This function check if the buffer is valid per processor architecture and not overlap with MMRAM.
+
+  @param Buffer  The buffer start address to be checked.
+  @param Length  The buffer length to be checked.
+
+  @retval TRUE  This buffer is valid per processor architecture and not overlap with MMRAM.
+  @retval FALSE This buffer is not valid per processor architecture or overlap with MMRAM.
+**/
+BOOLEAN
+EFIAPI
+MmIsBufferOutsideMmValid (
+  IN EFI_PHYSICAL_ADDRESS  Buffer,
+  IN UINT64                Length
+  )
+{
+  UINTN  Index;
+
+  //
+  // Check override.
+  // NOTE: (B:0->L:4G) is invalid for IA32, but (B:1->L:4G-1)/(B:4G-1->L:1) is valid.
+  //
+  if ((Length > mMmMemLibInternalMaximumSupportAddress) ||
+      (Buffer > mMmMemLibInternalMaximumSupportAddress) ||
+      ((Length != 0) && (Buffer > (mMmMemLibInternalMaximumSupportAddress - (Length - 1)))) ) {
+    //
+    // Overflow happen
+    //
+    DEBUG ((
+      DEBUG_ERROR,
+      "MmIsBufferOutsideMmValid: Overflow: Buffer (0x%lx) - Length (0x%lx), MaximumSupportAddress (0x%lx)\n",
+      Buffer,
+      Length,
+      mMmMemLibInternalMaximumSupportAddress
+      ));
+    return FALSE;
+  }
+
+  for (Index = 0; Index < mMmMemLibInternalMmramCount; Index ++) {
+    if (((Buffer >= mMmMemLibInternalMmramRanges[Index].CpuStart) &&
+         (Buffer < mMmMemLibInternalMmramRanges[Index].CpuStart + mMmMemLibInternalMmramRanges[Index].PhysicalSize)) ||
+        ((mMmMemLibInternalMmramRanges[Index].CpuStart >= Buffer) &&
+         (mMmMemLibInternalMmramRanges[Index].CpuStart < Buffer + Length))) {
+      DEBUG ((
+        DEBUG_ERROR,
+        "MmIsBufferOutsideMmValid: Overlap: Buffer (0x%lx) - Length (0x%lx), ",
+        Buffer,
+        Length
+        ));
+      DEBUG ((
+        DEBUG_ERROR,
+        "CpuStart (0x%lx) - PhysicalSize (0x%lx)\n",
+        mMmMemLibInternalMmramRanges[Index].CpuStart,
+        mMmMemLibInternalMmramRanges[Index].PhysicalSize
+        ));
+      return FALSE;
+    }
+  }
+
+  return TRUE;
+}
+
+/**
+  Copies a source buffer (non-MMRAM) to a destination buffer (MMRAM).
+
+  This function copies a source buffer (non-MMRAM) to a destination buffer (MMRAM).
+  It checks if source buffer is valid per processor architecture and not overlap with MMRAM.
+  If the check passes, it copies memory and returns EFI_SUCCESS.
+  If the check fails, it return EFI_SECURITY_VIOLATION.
+  The implementation must be reentrant.
+
+  @param  DestinationBuffer   The pointer to the destination buffer of the memory copy.
+  @param  SourceBuffer        The pointer to the source buffer of the memory copy.
+  @param  Length              The number of bytes to copy from SourceBuffer to DestinationBuffer.
+
+  @retval EFI_SECURITY_VIOLATION The SourceBuffer is invalid per processor architecture or overlap with MMRAM.
+  @retval EFI_SUCCESS            Memory is copied.
+
+**/
+EFI_STATUS
+EFIAPI
+MmCopyMemToMmram (
+  OUT VOID       *DestinationBuffer,
+  IN CONST VOID  *SourceBuffer,
+  IN UINTN       Length
+  )
+{
+  if (!MmIsBufferOutsideMmValid ((EFI_PHYSICAL_ADDRESS)(UINTN)SourceBuffer, Length)) {
+    DEBUG ((DEBUG_ERROR, "MmCopyMemToMmram: Security Violation: Source (0x%x), Length (0x%x)\n", SourceBuffer, Length));
+    return EFI_SECURITY_VIOLATION;
+  }
+  CopyMem (DestinationBuffer, SourceBuffer, Length);
+  return EFI_SUCCESS;
+}
+
+/**
+  Copies a source buffer (MMRAM) to a destination buffer (NON-MMRAM).
+
+  This function copies a source buffer (non-MMRAM) to a destination buffer (MMRAM).
+  It checks if destination buffer is valid per processor architecture and not overlap with MMRAM.
+  If the check passes, it copies memory and returns EFI_SUCCESS.
+  If the check fails, it returns EFI_SECURITY_VIOLATION.
+  The implementation must be reentrant.
+
+  @param  DestinationBuffer   The pointer to the destination buffer of the memory copy.
+  @param  SourceBuffer        The pointer to the source buffer of the memory copy.
+  @param  Length              The number of bytes to copy from SourceBuffer to DestinationBuffer.
+
+  @retval EFI_SECURITY_VIOLATION The DesinationBuffer is invalid per processor architecture or overlap with MMRAM.
+  @retval EFI_SUCCESS            Memory is copied.
+
+**/
+EFI_STATUS
+EFIAPI
+MmCopyMemFromMmram (
+  OUT VOID       *DestinationBuffer,
+  IN CONST VOID  *SourceBuffer,
+  IN UINTN       Length
+  )
+{
+  if (!MmIsBufferOutsideMmValid ((EFI_PHYSICAL_ADDRESS)(UINTN)DestinationBuffer, Length)) {
+    DEBUG ((DEBUG_ERROR, "MmCopyMemFromMmram: Security Violation: Destination (0x%x), Length (0x%x)\n",
+            DestinationBuffer, Length));
+    return EFI_SECURITY_VIOLATION;
+  }
+  CopyMem (DestinationBuffer, SourceBuffer, Length);
+  return EFI_SUCCESS;
+}
+
+/**
+  Copies a source buffer (NON-MMRAM) to a destination buffer (NON-MMRAM).
+
+  This function copies a source buffer (non-MMRAM) to a destination buffer (MMRAM).
+  It checks if source buffer and destination buffer are valid per processor architecture and not overlap with MMRAM.
+  If the check passes, it copies memory and returns EFI_SUCCESS.
+  If the check fails, it returns EFI_SECURITY_VIOLATION.
+  The implementation must be reentrant, and it must handle the case where source buffer overlaps destination buffer.
+
+  @param  DestinationBuffer   The pointer to the destination buffer of the memory copy.
+  @param  SourceBuffer        The pointer to the source buffer of the memory copy.
+  @param  Length              The number of bytes to copy from SourceBuffer to DestinationBuffer.
+
+  @retval EFI_SECURITY_VIOLATION The DesinationBuffer is invalid per processor architecture or overlap with MMRAM.
+  @retval EFI_SECURITY_VIOLATION The SourceBuffer is invalid per processor architecture or overlap with MMRAM.
+  @retval EFI_SUCCESS            Memory is copied.
+
+**/
+EFI_STATUS
+EFIAPI
+MmCopyMem (
+  OUT VOID       *DestinationBuffer,
+  IN CONST VOID  *SourceBuffer,
+  IN UINTN       Length
+  )
+{
+  if (!MmIsBufferOutsideMmValid ((EFI_PHYSICAL_ADDRESS)(UINTN)DestinationBuffer, Length)) {
+    DEBUG ((DEBUG_ERROR, "MmCopyMem: Security Violation: Destination (0x%x), Length (0x%x)\n",
+            DestinationBuffer, Length));
+    return EFI_SECURITY_VIOLATION;
+  }
+  if (!MmIsBufferOutsideMmValid ((EFI_PHYSICAL_ADDRESS)(UINTN)SourceBuffer, Length)) {
+    DEBUG ((DEBUG_ERROR, "MmCopyMem: Security Violation: Source (0x%x), Length (0x%x)\n", SourceBuffer, Length));
+    return EFI_SECURITY_VIOLATION;
+  }
+  CopyMem (DestinationBuffer, SourceBuffer, Length);
+  return EFI_SUCCESS;
+}
+
+/**
+  Fills a target buffer (NON-MMRAM) with a byte value.
+
+  This function fills a target buffer (non-MMRAM) with a byte value.
+  It checks if target buffer is valid per processor architecture and not overlap with MMRAM.
+  If the check passes, it fills memory and returns EFI_SUCCESS.
+  If the check fails, it returns EFI_SECURITY_VIOLATION.
+
+  @param  Buffer    The memory to set.
+  @param  Length    The number of bytes to set.
+  @param  Value     The value with which to fill Length bytes of Buffer.
+
+  @retval EFI_SECURITY_VIOLATION The Buffer is invalid per processor architecture or overlap with MMRAM.
+  @retval EFI_SUCCESS            Memory is set.
+
+**/
+EFI_STATUS
+EFIAPI
+MmSetMem (
+  OUT VOID  *Buffer,
+  IN UINTN  Length,
+  IN UINT8  Value
+  )
+{
+  if (!MmIsBufferOutsideMmValid ((EFI_PHYSICAL_ADDRESS)(UINTN)Buffer, Length)) {
+    DEBUG ((DEBUG_ERROR, "MmSetMem: Security Violation: Source (0x%x), Length (0x%x)\n", Buffer, Length));
+    return EFI_SECURITY_VIOLATION;
+  }
+  SetMem (Buffer, Length, Value);
+  return EFI_SUCCESS;
+}
+
+/**
+  The constructor function initializes the Mm Mem library
+
+  @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
+MemLibConstructor (
+  IN EFI_HANDLE             ImageHandle,
+  IN EFI_MM_SYSTEM_TABLE    *MmSystemTable
+  )
+{
+
+  //
+  // Calculate and save maximum support address
+  //
+  MmMemLibInternalCalculateMaximumSupportAddress ();
+
+  return EFI_SUCCESS;
+}
diff --git a/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.inf b/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.inf
new file mode 100644
index 000000000000..db1041c503c9
--- /dev/null
+++ b/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.inf
@@ -0,0 +1,50 @@
+## @file
+#  Instance of MM memory check library.
+#
+#  MM memory check library library implementation. This library consumes MM_ACCESS_PROTOCOL
+#  to get MMRAM information. In order to use this library instance, the platform should produce
+#  all MMRAM range via MM_ACCESS_PROTOCOL, including the range for firmware (like MM Core
+#  and MM driver) and/or specific dedicated hardware.
+#
+#  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                    = 0x0001001A
+  BASE_NAME                      = MemLib
+  FILE_GUID                      = EA355F14-6409-4716-829F-37B3BC7C7F26
+  MODULE_TYPE                    = MM_STANDALONE
+  VERSION_STRING                 = 1.0
+  PI_SPECIFICATION_VERSION       = 0x00010032
+  LIBRARY_CLASS                  = MemLib|MM_STANDALONE MM_CORE_STANDALONE
+  CONSTRUCTOR                    = MemLibConstructor
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+#  VALID_ARCHITECTURES           = AARCH64
+#
+
+[Sources.Common]
+  StandaloneMmMemLib.c
+
+[Sources.AARCH64]
+  AArch64/StandaloneMmMemLibInternal.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  StandaloneMmPkg/StandaloneMmPkg.dec
+
+[LibraryClasses]
+  BaseMemoryLib
+  DebugLib
-- 
2.7.4



  parent reply	other threads:[~2018-07-13 15:05 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-13 15:05 [PATCH v2 00/10] Standalone Management Mode Core Interface for AARCH64 Platforms Sughosh Ganu
2018-07-13 15:05 ` [PATCH v2 01/10] StandaloneMmPkg: Delete StandaloneMmPkg file Sughosh Ganu
2018-07-13 15:05 ` [PATCH v2 02/10] StandaloneMmPkg/FvLib: Add a common FV Library for management mode Sughosh Ganu
2018-07-13 15:05 ` Sughosh Ganu [this message]
2018-07-13 15:05 ` [PATCH v2 04/10] StandaloneMmPkg/MemoryAllocationLib: Add MM memory allocation library Sughosh Ganu
2018-07-13 15:05 ` [PATCH v2 05/10] StandaloneMmPkg/HobLib: Add HOB Library for management mode Sughosh Ganu
2018-07-13 15:05 ` [PATCH v2 06/10] StandaloneMmPkg: MM driver entry point library Sughosh Ganu
2018-07-13 15:05 ` [PATCH v2 07/10] StandaloneMmPkg/Core: Implementation of Standalone MM Core Module Sughosh Ganu
2018-07-13 15:05 ` [PATCH v2 08/10] StandaloneMmPkg: Add an AArch64 specific entry point library Sughosh Ganu
2018-07-19 19:03   ` Achin Gupta
2018-07-13 15:05 ` [PATCH v2 09/10] StandaloneMmPkg: Add CPU driver suitable for ARM Platforms Sughosh Ganu
2018-07-19 19:05   ` Achin Gupta
2018-07-23 19:27     ` Supreeth Venkatesh
2018-07-13 15:05 ` [PATCH v2 10/10] StandaloneMmPkg: Describe the declaration and definition files Sughosh Ganu
2018-07-20  3:07 ` [PATCH v2 00/10] Standalone Management Mode Core Interface for AARCH64 Platforms Yao, Jiewen

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=1531494330-1280-4-git-send-email-sughosh.ganu@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