/** @file\r
Instance of MM memory check library.\r
\r
- MM memory check library library implementation. This library consumes MM_ACCESS_PROTOCOL\r
+ MM memory check library implementation. This library consumes MM_ACCESS_PROTOCOL\r
to get MMRAM information. In order to use this library instance, the platform should produce\r
all MMRAM range via MM_ACCESS_PROTOCOL, including the range for firmware (like MM Core\r
and MM driver) and/or specific dedicated hardware.\r
\r
Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
- Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.<BR>\r
+ Copyright (c) 2016 - 2021, Arm Limited. All rights reserved.<BR>\r
\r
SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
**/\r
\r
-\r
#include <PiMm.h>\r
\r
#include <Library/BaseLib.h>\r
#include <Library/BaseMemoryLib.h>\r
#include <Library/DebugLib.h>\r
\r
-EFI_MMRAM_DESCRIPTOR *mMmMemLibInternalMmramRanges;\r
-UINTN mMmMemLibInternalMmramCount;\r
+EFI_MMRAM_DESCRIPTOR *mMmMemLibInternalMmramRanges;\r
+UINTN mMmMemLibInternalMmramCount;\r
\r
//\r
// Maximum support address used to check input buffer\r
VOID\r
);\r
\r
+/**\r
+ Initialize cached Mmram Ranges from HOB.\r
+\r
+ @retval EFI_UNSUPPORTED The routine is unable to extract MMRAM information.\r
+ @retval EFI_SUCCESS MmRanges are populated successfully.\r
+\r
+**/\r
+EFI_STATUS\r
+MmMemLibInternalPopulateMmramRanges (\r
+ VOID\r
+ );\r
+\r
+/**\r
+ Deinitialize cached Mmram Ranges.\r
+\r
+**/\r
+VOID\r
+MmMemLibInternalFreeMmramRanges (\r
+ VOID\r
+ );\r
+\r
/**\r
This function check if the buffer is valid per processor architecture and not overlap with MMRAM.\r
\r
//\r
if ((Length > mMmMemLibInternalMaximumSupportAddress) ||\r
(Buffer > mMmMemLibInternalMaximumSupportAddress) ||\r
- ((Length != 0) && (Buffer > (mMmMemLibInternalMaximumSupportAddress - (Length - 1)))) ) {\r
+ ((Length != 0) && (Buffer > (mMmMemLibInternalMaximumSupportAddress - (Length - 1)))))\r
+ {\r
//\r
// Overflow happen\r
//\r
return FALSE;\r
}\r
\r
- for (Index = 0; Index < mMmMemLibInternalMmramCount; Index ++) {\r
+ for (Index = 0; Index < mMmMemLibInternalMmramCount; Index++) {\r
if (((Buffer >= mMmMemLibInternalMmramRanges[Index].CpuStart) &&\r
(Buffer < mMmMemLibInternalMmramRanges[Index].CpuStart + mMmMemLibInternalMmramRanges[Index].PhysicalSize)) ||\r
((mMmMemLibInternalMmramRanges[Index].CpuStart >= Buffer) &&\r
- (mMmMemLibInternalMmramRanges[Index].CpuStart < Buffer + Length))) {\r
+ (mMmMemLibInternalMmramRanges[Index].CpuStart < Buffer + Length)))\r
+ {\r
DEBUG ((\r
DEBUG_ERROR,\r
"MmIsBufferOutsideMmValid: Overlap: Buffer (0x%lx) - Length (0x%lx), ",\r
DEBUG ((DEBUG_ERROR, "MmCopyMemToMmram: Security Violation: Source (0x%x), Length (0x%x)\n", SourceBuffer, Length));\r
return EFI_SECURITY_VIOLATION;\r
}\r
+\r
CopyMem (DestinationBuffer, SourceBuffer, Length);\r
return EFI_SUCCESS;\r
}\r
@param SourceBuffer The pointer to the source buffer of the memory copy.\r
@param Length The number of bytes to copy from SourceBuffer to DestinationBuffer.\r
\r
- @retval EFI_SECURITY_VIOLATION The DesinationBuffer is invalid per processor architecture or overlap with MMRAM.\r
+ @retval EFI_SECURITY_VIOLATION The DestinationBuffer is invalid per processor architecture or overlap with MMRAM.\r
@retval EFI_SUCCESS Memory is copied.\r
\r
**/\r
)\r
{\r
if (!MmIsBufferOutsideMmValid ((EFI_PHYSICAL_ADDRESS)(UINTN)DestinationBuffer, Length)) {\r
- DEBUG ((DEBUG_ERROR, "MmCopyMemFromMmram: Security Violation: Destination (0x%x), Length (0x%x)\n",\r
- DestinationBuffer, Length));\r
+ DEBUG ((\r
+ DEBUG_ERROR,\r
+ "MmCopyMemFromMmram: Security Violation: Destination (0x%x), Length (0x%x)\n",\r
+ DestinationBuffer,\r
+ Length\r
+ ));\r
return EFI_SECURITY_VIOLATION;\r
}\r
+\r
CopyMem (DestinationBuffer, SourceBuffer, Length);\r
return EFI_SUCCESS;\r
}\r
@param SourceBuffer The pointer to the source buffer of the memory copy.\r
@param Length The number of bytes to copy from SourceBuffer to DestinationBuffer.\r
\r
- @retval EFI_SECURITY_VIOLATION The DesinationBuffer is invalid per processor architecture or overlap with MMRAM.\r
+ @retval EFI_SECURITY_VIOLATION The DestinationBuffer is invalid per processor architecture or overlap with MMRAM.\r
@retval EFI_SECURITY_VIOLATION The SourceBuffer is invalid per processor architecture or overlap with MMRAM.\r
@retval EFI_SUCCESS Memory is copied.\r
\r
)\r
{\r
if (!MmIsBufferOutsideMmValid ((EFI_PHYSICAL_ADDRESS)(UINTN)DestinationBuffer, Length)) {\r
- DEBUG ((DEBUG_ERROR, "MmCopyMem: Security Violation: Destination (0x%x), Length (0x%x)\n",\r
- DestinationBuffer, Length));\r
+ DEBUG ((\r
+ DEBUG_ERROR,\r
+ "MmCopyMem: Security Violation: Destination (0x%x), Length (0x%x)\n",\r
+ DestinationBuffer,\r
+ Length\r
+ ));\r
return EFI_SECURITY_VIOLATION;\r
}\r
+\r
if (!MmIsBufferOutsideMmValid ((EFI_PHYSICAL_ADDRESS)(UINTN)SourceBuffer, Length)) {\r
DEBUG ((DEBUG_ERROR, "MmCopyMem: Security Violation: Source (0x%x), Length (0x%x)\n", SourceBuffer, Length));\r
return EFI_SECURITY_VIOLATION;\r
}\r
+\r
CopyMem (DestinationBuffer, SourceBuffer, Length);\r
return EFI_SUCCESS;\r
}\r
DEBUG ((DEBUG_ERROR, "MmSetMem: Security Violation: Source (0x%x), Length (0x%x)\n", Buffer, Length));\r
return EFI_SECURITY_VIOLATION;\r
}\r
+\r
SetMem (Buffer, Length, Value);\r
return EFI_SUCCESS;\r
}\r
/**\r
The constructor function initializes the Mm Mem library\r
\r
- @param ImageHandle The firmware allocated handle for the EFI image.\r
- @param SystemTable A pointer to the EFI System Table.\r
+ @param [in] ImageHandle The firmware allocated handle for the EFI image.\r
+ @param [in] MmSystemTable A pointer to the EFI System Table.\r
\r
@retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r
\r
EFI_STATUS\r
EFIAPI\r
MemLibConstructor (\r
- IN EFI_HANDLE ImageHandle,\r
- IN EFI_MM_SYSTEM_TABLE *MmSystemTable\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_MM_SYSTEM_TABLE *MmSystemTable\r
)\r
{\r
+ EFI_STATUS Status;\r
\r
//\r
// Calculate and save maximum support address\r
//\r
MmMemLibInternalCalculateMaximumSupportAddress ();\r
\r
+ //\r
+ // Initialize cached Mmram Ranges from HOB.\r
+ //\r
+ Status = MmMemLibInternalPopulateMmramRanges ();\r
+\r
+ return Status;\r
+}\r
+\r
+/**\r
+ Destructor for Mm Mem library.\r
+\r
+ @param ImageHandle The image handle of the process.\r
+ @param MmSystemTable The EFI System Table pointer.\r
+\r
+ @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+MemLibDestructor (\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_MM_SYSTEM_TABLE *MmSystemTable\r
+ )\r
+{\r
+ //\r
+ // Deinitialize cached Mmram Ranges.\r
+ //\r
+ MmMemLibInternalFreeMmramRanges ();\r
+\r
return EFI_SUCCESS;\r
}\r