From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.1273.1689086245339188894 for ; Tue, 11 Jul 2023 07:37:25 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: nishant.sharma@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4316C1FB; Tue, 11 Jul 2023 07:38:07 -0700 (PDT) Received: from usa.arm.com (iss-desktop02.cambridge.arm.com [10.1.196.79]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 255CF3F740; Tue, 11 Jul 2023 07:37:24 -0700 (PDT) From: "Nishant Sharma" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Sami Mujawar , Thomas Abraham , Sayanta Pattanayak , Achin Gupta Subject: [edk2-platforms][PATCH V1 10/20] StandaloneMmPkg: Populate Hoblist for SP init from StMM boot information Date: Tue, 11 Jul 2023 15:36:48 +0100 Message-Id: <20230711143658.781597-11-nishant.sharma@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230711143658.781597-1-nishant.sharma@arm.com> References: <20230711143658.781597-1-nishant.sharma@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Achin Gupta This patch adds support for creating a hoblist from the reduced boot information retrieved from the SP manifest. Signed-off-by: Achin Gupta Signed-off-by: Nishant Sharma --- StandaloneMmPkg/Include/Library/Arm/StandaloneMmCoreEntryPoint.h = | 16 ++ StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateHobList.c = | 186 +++++++++++++++++++- StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMmCoreE= ntryPoint.c | 6 +- 3 files changed, 206 insertions(+), 2 deletions(-) diff --git a/StandaloneMmPkg/Include/Library/Arm/StandaloneMmCoreEntryPoi= nt.h b/StandaloneMmPkg/Include/Library/Arm/StandaloneMmCoreEntryPoint.h index 90d67a2f25b5..9daa76324221 100644 --- a/StandaloneMmPkg/Include/Library/Arm/StandaloneMmCoreEntryPoint.h +++ b/StandaloneMmPkg/Include/Library/Arm/StandaloneMmCoreEntryPoint.h @@ -170,6 +170,22 @@ CreateHobListFromBootInfo ( IN EFI_SECURE_PARTITION_BOOT_INFO *PayloadBootInfo ); =20 +/** + Use the boot information passed by the SPMC to populate a HOB list + suitable for consumption by the MM Core and drivers. + + @param [in, out] CpuDriverEntryPoint Address of MM CPU driver entry= point + @param [in] StmmBootInfo Boot information passed by pri= vileged + firmware + +**/ +VOID * +EFIAPI +CreateHobListFromStmmBootInfo ( + IN OUT PI_MM_ARM_TF_CPU_DRIVER_ENTRYPOINT *CpuDriverEntryPoint, + IN EFI_STMM_BOOT_INFO *StmmBootInfo + ); + /** The entry point of Standalone MM Foundation. =20 diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/Creat= eHobList.c b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/Creat= eHobList.c index 2ac2d354f06a..4592089a6020 100644 --- a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateHobLis= t.c +++ b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateHobLis= t.c @@ -2,7 +2,7 @@ Creates HOB during Standalone MM Foundation entry point on ARM platforms. =20 -Copyright (c) 2017 - 2021, Arm Ltd. All rights reserved.
+Copyright (c) 2017 - 2023, Arm Ltd. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ @@ -203,3 +203,187 @@ CreateHobListFromBootInfo ( =20 return HobStart; } + +STATIC +VOID +CreateMmramInformationHobFromImageLayout ( + IN EFI_STMM_BOOT_INFO *StmmBootInfo, + IN EFI_HOB_HANDOFF_INFO_TABLE *HobStart +) +{ + UINT32 *Idx; + UINT32 BufferSize; + EFI_MMRAM_HOB_DESCRIPTOR_BLOCK *MmramRangesHob; + EFI_MMRAM_DESCRIPTOR *MmramRanges; + + // Find the size of the GUIDed HOB with SRAM ranges. This excludes any= memory + // shared with the normal world or the SPMC. It includes the memory al= located + // to the SP image, used and unused heap. + BufferSize =3D sizeof (EFI_MMRAM_HOB_DESCRIPTOR_BLOCK); + BufferSize +=3D 4 * sizeof (EFI_MMRAM_DESCRIPTOR); + + // Create a GUIDed HOB with SRAM ranges + MmramRangesHob =3D BuildGuidHob (&gEfiMmPeiMmramMemoryReserveGuid, Buf= ferSize); + + // Initialise the number of MMRAM memory regions + MmramRangesHob->NumberOfMmReservedRegions =3D 0; + Idx =3D &MmramRangesHob->NumberOfMmReservedRegions ; + + // Fill up the MMRAM ranges + MmramRanges =3D &MmramRangesHob->Descriptor[0]; + + // Base and size of memory occupied by the Standalone MM image + MmramRanges[*Idx].PhysicalStart =3D StmmBootInfo->SpMemBase; + MmramRanges[*Idx].CpuStart =3D StmmBootInfo->SpMemBase; + MmramRanges[*Idx].PhysicalSize =3D StmmBootInfo->SpMemSize; + MmramRanges[*Idx].RegionState =3D EFI_CACHEABLE | EFI_ALLOCATED; + (*Idx)++; + + // Base and size of memory occupied by the Standalone MM image + MmramRanges[*Idx].PhysicalStart =3D StmmBootInfo->SpSharedBufBase; + MmramRanges[*Idx].CpuStart =3D StmmBootInfo->SpSharedBufBase; + MmramRanges[*Idx].PhysicalSize =3D StmmBootInfo->SpSharedBufSize; + MmramRanges[*Idx].RegionState =3D EFI_CACHEABLE | EFI_ALLOCATED; + (*Idx)++; + + // Base and size of memory occupied by the hoblist + MmramRanges[*Idx].PhysicalStart =3D (EFI_PHYSICAL_ADDRESS) (UINTN) Hob= Start; + MmramRanges[*Idx].CpuStart =3D (EFI_PHYSICAL_ADDRESS) (UINTN) Hob= Start; + MmramRanges[*Idx].PhysicalSize =3D HobStart->EfiFreeMemoryBottom - (E= FI_PHYSICAL_ADDRESS) (UINTN) HobStart; + MmramRanges[*Idx].RegionState =3D EFI_CACHEABLE | EFI_ALLOCATED; + (*Idx)++; + + // Base and size of heap memory shared by all cpus + MmramRanges[*Idx].PhysicalStart =3D HobStart->EfiFreeMemoryBottom; + MmramRanges[*Idx].CpuStart =3D HobStart->EfiFreeMemoryBottom; + MmramRanges[*Idx].PhysicalSize =3D HobStart->EfiFreeMemoryTop - HobSt= art->EfiFreeMemoryBottom; + MmramRanges[*Idx].RegionState =3D EFI_CACHEABLE; + (*Idx)++; + + // Sanity check number of MMRAM regions + ASSERT (MmramRangesHob->NumberOfMmReservedRegions =3D=3D 3); + + return; +} + +STATIC +VOID +CreateMpInformationHobFromCpuInfo ( + IN EFI_SECURE_PARTITION_CPU_INFO *CpuInfo +) +{ + MP_INFORMATION_HOB_DATA *MpInformationHobData; + EFI_PROCESSOR_INFORMATION *ProcInfoBuffer; + UINT32 BufferSize; + UINT32 Flags; + + // Find the size of the GUIDed HOB with MP information + BufferSize =3D sizeof (MP_INFORMATION_HOB_DATA); + BufferSize +=3D sizeof (EFI_PROCESSOR_INFORMATION); + + // Create a Guided MP information HOB to enable the ARM TF CPU driver = to + // perform per-cpu allocations. + MpInformationHobData =3D BuildGuidHob (&gMpInformationHobGuid, BufferS= ize); + + // Populate the MP information HOB under the assumption that this is a + // uniprocessor partition. Hence, only a single CPU is exposed to the = MM Core. + MpInformationHobData->NumberOfProcessors =3D 1; + MpInformationHobData->NumberOfEnabledProcessors =3D 1; + + // Populate the processor information + ProcInfoBuffer =3D MpInformationHobData->ProcessorInfoBuffer; + ProcInfoBuffer[0].ProcessorId =3D CpuInfo[0].Mpidr; + ProcInfoBuffer[0].Location.Package =3D GET_CLUSTER_ID(CpuInfo[0].Mpidr= ); + ProcInfoBuffer[0].Location.Core =3D GET_CORE_ID(CpuInfo[0].Mpidr); + ProcInfoBuffer[0].Location.Thread =3D GET_CORE_ID(CpuInfo[0].Mpidr); + + // Populate the processor information flags + Flags =3D PROCESSOR_ENABLED_BIT | PROCESSOR_HEALTH_STATUS_BIT | PROCES= SOR_AS_BSP_BIT; + ProcInfoBuffer[0].StatusFlag =3D Flags; + + return; +} + +/** + Use the FF-A boot information passed by the SPMC to populate a HOB lis= t + suitable for consumption by the MM Core and drivers. + + @param [in, out] CpuDriverEntryPoint Address of MM CPU driver entry= point + @param [in] StmmBootInfo Boot information passed by the= SPMC + +**/ +VOID * +CreateHobListFromStmmBootInfo ( + IN OUT PI_MM_ARM_TF_CPU_DRIVER_ENTRYPOINT *CpuDriverEntryPoint, + IN EFI_STMM_BOOT_INFO *StmmBootInfo +) +{ + EFI_HOB_HANDOFF_INFO_TABLE *HobStart; + EFI_RESOURCE_ATTRIBUTE_TYPE Attributes; + EFI_MMRAM_DESCRIPTOR *NsCommBufMmramRange; + ARM_TF_CPU_DRIVER_EP_DESCRIPTOR *CpuDriverEntryPointDesc; + + // Create a hoblist with a PHIT and EOH + HobStart =3D HobConstructor ( + (VOID *) (UINTN) StmmBootInfo->SpMemBase, + (UINTN) StmmBootInfo->SpMemSize, + (VOID *) (UINTN) StmmBootInfo->SpHeapBase, + (VOID *) (UINTN) (StmmBootInfo->SpHeapBase + StmmBootInfo= ->SpHeapSize) + ); + + // Check that the Hoblist starts at the bottom of the Heap + ASSERT (HobStart =3D=3D (VOID *) (UINTN) StmmBootInfo->SpHeapBase); + + // Build a Boot Firmware Volume HOB + BuildFvHob (StmmBootInfo->SpMemBase, StmmBootInfo->SpMemSize); + + // Build a resource descriptor Hob that describes the available physic= al + // memory range + Attributes =3D ( + EFI_RESOURCE_ATTRIBUTE_PRESENT | + EFI_RESOURCE_ATTRIBUTE_INITIALIZED | + EFI_RESOURCE_ATTRIBUTE_TESTED | + EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE | + EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE | + EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE | + EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE + ); + + BuildResourceDescriptorHob ( + EFI_RESOURCE_SYSTEM_MEMORY, + Attributes, + (UINTN) StmmBootInfo->SpMemBase, + StmmBootInfo->SpMemSize + ); + + // Create an MP information hob from cpu information passed in the boo= t + // information structure + CreateMpInformationHobFromCpuInfo(&StmmBootInfo->CpuInfo); + + // Create a Guided HOB to tell the ARM TF CPU driver the location and = length + // of the communication buffer shared with the Normal world. + NsCommBufMmramRange =3D (EFI_MMRAM_DESCRIPTOR *) BuildGuidHob ( + &gEfiStandaloneMmNonS= ecureBufferGuid, + sizeof (EFI_MMRAM_DES= CRIPTOR) + ); + NsCommBufMmramRange->PhysicalStart =3D StmmBootInfo->SpNsCommBufBase; + NsCommBufMmramRange->CpuStart =3D StmmBootInfo->SpNsCommBufBase; + NsCommBufMmramRange->PhysicalSize =3D StmmBootInfo->SpNsCommBufSize; + NsCommBufMmramRange->RegionState =3D EFI_CACHEABLE | EFI_ALLOCATED; + + // Create a Guided HOB to enable the ARM TF CPU driver to share its en= try + // point and populate it with the address of the shared buffer + CpuDriverEntryPointDesc =3D + (ARM_TF_CPU_DRIVER_EP_DESCRIPTOR *) BuildGuidHob ( + &gEfiArmTfCpuDriverEpDescriptorGuid, + sizeof (ARM_TF_CPU_DRIVER_EP_DESCRIPTOR) + ); + + *CpuDriverEntryPoint =3D NULL; + CpuDriverEntryPointDesc->ArmTfCpuDriverEpPtr =3D CpuDriverEntryPoint; + + // Create Mmram range hob from SP image layout + CreateMmramInformationHobFromImageLayout(StmmBootInfo, HobStart); + + return HobStart; +} diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/Stand= aloneMmCoreEntryPoint.c b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPo= int/Arm/StandaloneMmCoreEntryPoint.c index 505786aff07c..8131b1984969 100644 --- a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMm= CoreEntryPoint.c +++ b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMm= CoreEntryPoint.c @@ -823,7 +823,11 @@ ModuleEntryPoint ( // // Create Hoblist based upon boot information passed by privileged sof= tware // - HobStart =3D CreateHobListFromBootInfo (&CpuDriverEntryPoint, PayloadB= ootInfo); + if (UseOnlyFfaAbis) { + HobStart =3D CreateHobListFromStmmBootInfo (&CpuDriverEntryPoint, &S= tmmBootInfo); + } else { + HobStart =3D CreateHobListFromBootInfo (&CpuDriverEntryPoint, Payloa= dBootInfo); + } =20 // // Call the MM Core entry point --=20 2.34.1