From 836942fbadb629050b866a8052e6af755bcdf623 Mon Sep 17 00:00:00 2001 From: Dun Tan Date: Fri, 20 Sep 2024 15:09:01 +0800 Subject: [PATCH] StandaloneMmPkg/MemLib: remove unnecessary check Remove unnecessary check in API MmIsBufferOutsideMmValid of StandaloneMmMemLib. The API is used to check if a input buffer is outside MMRAM and inside a valid non-MMRAM range. Previously, the API only checks if the input buffer is overlapped with MMRAM range. In the last commit, we add logic to check if the input buffer is inside valid non-MMRAM ranges reported by the resource HOB. Since the resource HOB only covers valid non-MMRAM ranges, we doesn't need to check if the input buffer is inside the MMRAM anymore. Signed-off-by: Dun Tan --- .../ArmStandaloneMmMemLibInternal.c | 28 -------- .../StandaloneMmMemLib/StandaloneMmMemLib.c | 41 +---------- .../StandaloneMmMemLib/StandaloneMmMemLib.inf | 4 -- .../StandaloneMmMemLibInternal.h | 21 ------ .../X86StandaloneMmMemLibInternal.c | 69 ------------------- 5 files changed, 1 insertion(+), 162 deletions(-) diff --git a/StandaloneMmPkg/Library/StandaloneMmMemLib/ArmStandaloneMmMemLibInternal.c b/StandaloneMmPkg/Library/StandaloneMmMemLib/ArmStandaloneMmMemLibInternal.c index c3fa8b16744b..2f96ab094fea 100644 --- a/StandaloneMmPkg/Library/StandaloneMmMemLib/ArmStandaloneMmMemLibInternal.c +++ b/StandaloneMmPkg/Library/StandaloneMmMemLib/ArmStandaloneMmMemLibInternal.c @@ -32,34 +32,6 @@ MmMemLibCalculateMaximumSupportAddress ( DEBUG ((DEBUG_INFO, "mMmMemLibInternalMaximumSupportAddress = 0x%lx\n", mMmMemLibInternalMaximumSupportAddress)); } -/** - Initialize cached Mmram Ranges from HOB. - - @retval EFI_UNSUPPORTED The routine is unable to extract MMRAM information. - @retval EFI_SUCCESS MmRanges are populated successfully. - -**/ -EFI_STATUS -MmMemLibInternalPopulateMmramRanges ( - VOID - ) -{ - // Not implemented for AARCH64. - return EFI_SUCCESS; -} - -/** - Deinitialize cached Mmram Ranges. - -**/ -VOID -MmMemLibInternalFreeMmramRanges ( - VOID - ) -{ - // Not implemented for AARCH64. -} - /** Initialize valid non-Mmram Ranges from Resource HOB. diff --git a/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.c b/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.c index 0f5d6d1b109b..fab4503fe4df 100644 --- a/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.c +++ b/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.c @@ -15,9 +15,6 @@ #include "StandaloneMmMemLibInternal.h" -EFI_MMRAM_DESCRIPTOR *mMmMemLibInternalMmramRanges; -UINTN mMmMemLibInternalMmramCount; - // // Maximum support address used to check input buffer // @@ -39,8 +36,6 @@ MmIsBufferOutsideMmValid ( 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. @@ -62,28 +57,6 @@ MmIsBufferOutsideMmValid ( 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 MmMemLibIsValidNonMmramRange (Buffer, Length); } @@ -254,8 +227,6 @@ MemLibConstructor ( IN EFI_MM_SYSTEM_TABLE *MmSystemTable ) { - EFI_STATUS Status; - // // Calculate and save maximum support address // @@ -266,12 +237,7 @@ MemLibConstructor ( // MmMemLibInitializeValidNonMmramRanges (); - // - // Initialize cached Mmram Ranges from HOB. - // - Status = MmMemLibInternalPopulateMmramRanges (); - - return Status; + return EFI_SUCCESS; } /** @@ -290,11 +256,6 @@ MemLibDestructor ( IN EFI_MM_SYSTEM_TABLE *MmSystemTable ) { - // - // Deinitialize cached Mmram Ranges. - // - MmMemLibInternalFreeMmramRanges (); - // // Deinitialize cached non-Mmram Ranges. // diff --git a/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.inf b/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.inf index 54d9a7b10e36..4987deb8c9f2 100644 --- a/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.inf +++ b/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.inf @@ -50,7 +50,3 @@ DebugLib HobLib MemoryAllocationLib - -[Guids] - gEfiMmPeiMmramMemoryReserveGuid ## SOMETIMES_CONSUMES ## HOB - gEfiSmmSmramMemoryGuid ## SOMETIMES_CONSUMES ## HOB diff --git a/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLibInternal.h b/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLibInternal.h index 527f1ac9c4bc..bb3701a3a0a0 100644 --- a/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLibInternal.h +++ b/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLibInternal.h @@ -24,27 +24,6 @@ MmMemLibCalculateMaximumSupportAddress ( VOID ); -/** - Initialize cached Mmram Ranges from HOB. - - @retval EFI_UNSUPPORTED The routine is unable to extract MMRAM information. - @retval EFI_SUCCESS MmRanges are populated successfully. - -**/ -EFI_STATUS -MmMemLibInternalPopulateMmramRanges ( - VOID - ); - -/** - Deinitialize cached Mmram Ranges. - -**/ -VOID -MmMemLibInternalFreeMmramRanges ( - VOID - ); - /** Initialize valid non-Mmram Ranges from Resource HOB. diff --git a/StandaloneMmPkg/Library/StandaloneMmMemLib/X86StandaloneMmMemLibInternal.c b/StandaloneMmPkg/Library/StandaloneMmMemLib/X86StandaloneMmMemLibInternal.c index 8f87e7803d38..ee7aa7482562 100644 --- a/StandaloneMmPkg/Library/StandaloneMmMemLib/X86StandaloneMmMemLibInternal.c +++ b/StandaloneMmPkg/Library/StandaloneMmMemLib/X86StandaloneMmMemLibInternal.c @@ -18,8 +18,6 @@ #include #include -#include - typedef struct { EFI_PHYSICAL_ADDRESS Base; UINT64 Length; @@ -32,8 +30,6 @@ UINTN mValidNonMmramCount; // Maximum support address used to check input buffer // extern EFI_PHYSICAL_ADDRESS mMmMemLibInternalMaximumSupportAddress; -extern EFI_MMRAM_DESCRIPTOR *mMmMemLibInternalMmramRanges; -extern UINTN mMmMemLibInternalMmramCount; /** Calculate and save the maximum support address. @@ -79,71 +75,6 @@ MmMemLibCalculateMaximumSupportAddress ( DEBUG ((DEBUG_INFO, "mMmMemLibInternalMaximumSupportAddress = 0x%lx\n", mMmMemLibInternalMaximumSupportAddress)); } -/** - Initialize cached Mmram Ranges from HOB. - - @retval EFI_UNSUPPORTED The routine is unable to extract MMRAM information. - @retval EFI_SUCCESS MmRanges are populated successfully. - -**/ -EFI_STATUS -MmMemLibInternalPopulateMmramRanges ( - VOID - ) -{ - VOID *HobStart; - EFI_HOB_GUID_TYPE *MmramRangesHob; - EFI_MMRAM_HOB_DESCRIPTOR_BLOCK *MmramRangesHobData; - EFI_MMRAM_DESCRIPTOR *MmramDescriptors; - - HobStart = GetHobList (); - DEBUG ((DEBUG_INFO, "%a - 0x%x\n", __func__, HobStart)); - - // - // Search for a Hob containing the MMRAM ranges - // - MmramRangesHob = GetFirstGuidHob (&gEfiSmmSmramMemoryGuid); - if (MmramRangesHob == NULL) { - MmramRangesHob = GetFirstGuidHob (&gEfiMmPeiMmramMemoryReserveGuid); - if (MmramRangesHob == NULL) { - return EFI_UNSUPPORTED; - } - } - - MmramRangesHobData = GET_GUID_HOB_DATA (MmramRangesHob); - if ((MmramRangesHobData == NULL) || (MmramRangesHobData->Descriptor == NULL)) { - return EFI_UNSUPPORTED; - } - - mMmMemLibInternalMmramCount = MmramRangesHobData->NumberOfMmReservedRegions; - MmramDescriptors = MmramRangesHobData->Descriptor; - - mMmMemLibInternalMmramRanges = AllocatePool (mMmMemLibInternalMmramCount * sizeof (EFI_MMRAM_DESCRIPTOR)); - if (mMmMemLibInternalMmramRanges) { - CopyMem ( - mMmMemLibInternalMmramRanges, - MmramDescriptors, - mMmMemLibInternalMmramCount * sizeof (EFI_MMRAM_DESCRIPTOR) - ); - } - - return EFI_SUCCESS; -} - -/** - Deinitialize cached Mmram Ranges. - -**/ -VOID -MmMemLibInternalFreeMmramRanges ( - VOID - ) -{ - if (mMmMemLibInternalMmramRanges != NULL) { - FreePool (mMmMemLibInternalMmramRanges); - } -} - /** Merge the overlapped or continuous ranges in input MemoryRange. This function is to optimize the process of checking whether a buffer range belongs to the range reported by resource HOB,