From c8a1295d3e98490b4e18522cb1752200ae73d324 Mon Sep 17 00:00:00 2001 From: Jiaxin Wu Date: Mon, 24 Jun 2024 20:49:23 +0800 Subject: UefiCpuPkg/PiSmmCpuDxeSmm: Get SMRAM info from gEfiSmmSmramMemoryGuid MM can not use the SMM Access Protocol, so get SMRAM info from gEfiSmmSmramMemoryGuid instead of via SMM Access Protocol for both SMM and MM. Signed-off-by: Jiaxin Wu Cc: Ray Ni Cc: Rahul Kumar Cc: Gerd Hoffmann Cc: Star Zeng Cc: Dun Tan Cc: Hongbin1 Zhang Cc: Wei6 Xu Cc: Yuanhao Xie --- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuCommon.c | 40 ++++++++++------------------ UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuCommon.h | 2 +- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf | 2 +- 3 files changed, 16 insertions(+), 28 deletions(-) (limited to 'UefiCpuPkg') diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuCommon.c b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuCommon.c index 5d2b9eefd3..1ba5967fd6 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuCommon.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuCommon.c @@ -1282,7 +1282,6 @@ CpuSmramRangeCompare ( } /** - Find out SMRAM information including SMRR base and SMRR size. @param SmrrBase SMRR base @@ -1295,35 +1294,24 @@ FindSmramInfo ( OUT UINT32 *SmrrSize ) { - EFI_STATUS Status; - UINTN Size; - EFI_SMM_ACCESS2_PROTOCOL *SmmAccess; - EFI_SMRAM_DESCRIPTOR *CurrentSmramRange; - UINTN Index; - UINT64 MaxSize; - BOOLEAN Found; - EFI_SMRAM_DESCRIPTOR SmramDescriptor; + VOID *GuidHob; + EFI_SMRAM_HOB_DESCRIPTOR_BLOCK *DescriptorBlock; + EFI_SMRAM_DESCRIPTOR *CurrentSmramRange; + UINTN Index; + UINT64 MaxSize; + BOOLEAN Found; + EFI_SMRAM_DESCRIPTOR SmramDescriptor; - // - // Get SMM Access Protocol - // - Status = gBS->LocateProtocol (&gEfiSmmAccess2ProtocolGuid, NULL, (VOID **)&SmmAccess); - ASSERT_EFI_ERROR (Status); + ASSERT (SmrrBase != NULL && SmrrSize != NULL); // // Get SMRAM information // - Size = 0; - Status = SmmAccess->GetCapabilities (SmmAccess, &Size, NULL); - ASSERT (Status == EFI_BUFFER_TOO_SMALL); - - mSmmCpuSmramRanges = (EFI_SMRAM_DESCRIPTOR *)AllocatePool (Size); - ASSERT (mSmmCpuSmramRanges != NULL); - - Status = SmmAccess->GetCapabilities (SmmAccess, &Size, mSmmCpuSmramRanges); - ASSERT_EFI_ERROR (Status); - - mSmmCpuSmramRangeCount = Size / sizeof (EFI_SMRAM_DESCRIPTOR); + GuidHob = GetFirstGuidHob (&gEfiSmmSmramMemoryGuid); + ASSERT (GuidHob != NULL); + DescriptorBlock = (EFI_SMRAM_HOB_DESCRIPTOR_BLOCK *)GET_GUID_HOB_DATA (GuidHob); + mSmmCpuSmramRangeCount = DescriptorBlock->NumberOfSmmReservedRegions; + mSmmCpuSmramRanges = DescriptorBlock->Descriptor; // // Sort the mSmmCpuSmramRanges @@ -1373,7 +1361,7 @@ FindSmramInfo ( } } while (Found); - DEBUG ((DEBUG_INFO, "SMRR Base: 0x%x, SMRR Size: 0x%x\n", *SmrrBase, *SmrrSize)); + DEBUG ((DEBUG_INFO, "%a: SMRR Base = 0x%x, SMRR Size = 0x%x\n", __func__, *SmrrBase, *SmrrSize)); } /** diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuCommon.h b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuCommon.h index 87fd7d9ba1..c75f0ea9d6 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuCommon.h +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuCommon.h @@ -16,7 +16,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include -#include #include #include #include @@ -25,6 +24,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include +#include #include #include diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf index d18e9e85f8..2705ca69ea 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf @@ -102,7 +102,6 @@ SmmCpuSyncLib [Protocols] - gEfiSmmAccess2ProtocolGuid ## CONSUMES gEfiSmmConfigurationProtocolGuid ## PRODUCES gEfiSmmCpuProtocolGuid ## PRODUCES gEfiSmmReadyToLockProtocolGuid ## NOTIFY @@ -118,6 +117,7 @@ gEfiMemoryAttributesTableGuid ## CONSUMES ## SystemTable gSmmBaseHobGuid ## CONSUMES gMpInformation2HobGuid ## CONSUMES # Assume the HOB must has been created + gEfiSmmSmramMemoryGuid [FeaturePcd] gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmDebug ## CONSUMES -- cgit v1.2.3