From 91415a36ae7aaeabb2bbab3762f39544f9aed683 Mon Sep 17 00:00:00 2001 From: Michael Kubacki Date: Sun, 5 Dec 2021 14:54:16 -0800 Subject: StandaloneMmPkg: Apply uncrustify changes REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3737 Apply uncrustify changes to .c/.h files in the StandaloneMmPkg package Cc: Andrew Fish Cc: Leif Lindholm Cc: Michael D Kinney Signed-off-by: Michael Kubacki Reviewed-by: Sami Mujawar --- .../StandaloneMmCoreEntryPoint/Arm/CreateHobList.c | 106 ++++---- .../Arm/SetPermissions.c | 277 +++++++++++++-------- .../Arm/StandaloneMmCoreEntryPoint.c | 204 ++++++++------- .../X64/StandaloneMmCoreEntryPoint.c | 4 +- 4 files changed, 336 insertions(+), 255 deletions(-) (limited to 'StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint') diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateHobList.c b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateHobList.c index 85f8194687..eb0c1f82db 100644 --- a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateHobList.c +++ b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateHobList.c @@ -7,7 +7,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ - #include #include @@ -25,7 +24,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include -extern EFI_HOB_HANDOFF_INFO_TABLE* +extern EFI_HOB_HANDOFF_INFO_TABLE * HobConstructor ( IN VOID *EfiMemoryBegin, IN UINTN EfiMemoryLength, @@ -35,12 +34,12 @@ HobConstructor ( // GUID to identify HOB with whereabouts of communication buffer with Normal // World -extern EFI_GUID gEfiStandaloneMmNonSecureBufferGuid; +extern EFI_GUID gEfiStandaloneMmNonSecureBufferGuid; // GUID to identify HOB where the entry point of the CPU driver will be // populated to allow this entry point driver to invoke it upon receipt of an // event -extern EFI_GUID gEfiArmTfCpuDriverEpDescriptorGuid; +extern EFI_GUID gEfiArmTfCpuDriverEpDescriptorGuid; /** Use the boot information passed by privileged firmware to populate a HOB list @@ -53,33 +52,33 @@ extern EFI_GUID gEfiArmTfCpuDriverEpDescriptorGuid; **/ VOID * CreateHobListFromBootInfo ( - IN OUT PI_MM_ARM_TF_CPU_DRIVER_ENTRYPOINT *CpuDriverEntryPoint, - IN EFI_SECURE_PARTITION_BOOT_INFO *PayloadBootInfo -) + IN OUT PI_MM_ARM_TF_CPU_DRIVER_ENTRYPOINT *CpuDriverEntryPoint, + IN EFI_SECURE_PARTITION_BOOT_INFO *PayloadBootInfo + ) { - EFI_HOB_HANDOFF_INFO_TABLE *HobStart; - EFI_RESOURCE_ATTRIBUTE_TYPE Attributes; - UINT32 Index; - UINT32 BufferSize; - UINT32 Flags; - EFI_MMRAM_HOB_DESCRIPTOR_BLOCK *MmramRangesHob; - EFI_MMRAM_DESCRIPTOR *MmramRanges; - EFI_MMRAM_DESCRIPTOR *NsCommBufMmramRange; - MP_INFORMATION_HOB_DATA *MpInformationHobData; - EFI_PROCESSOR_INFORMATION *ProcInfoBuffer; - EFI_SECURE_PARTITION_CPU_INFO *CpuInfo; - ARM_TF_CPU_DRIVER_EP_DESCRIPTOR *CpuDriverEntryPointDesc; + EFI_HOB_HANDOFF_INFO_TABLE *HobStart; + EFI_RESOURCE_ATTRIBUTE_TYPE Attributes; + UINT32 Index; + UINT32 BufferSize; + UINT32 Flags; + EFI_MMRAM_HOB_DESCRIPTOR_BLOCK *MmramRangesHob; + EFI_MMRAM_DESCRIPTOR *MmramRanges; + EFI_MMRAM_DESCRIPTOR *NsCommBufMmramRange; + MP_INFORMATION_HOB_DATA *MpInformationHobData; + EFI_PROCESSOR_INFORMATION *ProcInfoBuffer; + EFI_SECURE_PARTITION_CPU_INFO *CpuInfo; + ARM_TF_CPU_DRIVER_EP_DESCRIPTOR *CpuDriverEntryPointDesc; // Create a hoblist with a PHIT and EOH HobStart = HobConstructor ( - (VOID *) (UINTN) PayloadBootInfo->SpMemBase, - (UINTN) PayloadBootInfo->SpMemLimit - PayloadBootInfo->SpMemBase, - (VOID *) (UINTN) PayloadBootInfo->SpHeapBase, - (VOID *) (UINTN) (PayloadBootInfo->SpHeapBase + PayloadBootInfo->SpHeapSize) + (VOID *)(UINTN)PayloadBootInfo->SpMemBase, + (UINTN)PayloadBootInfo->SpMemLimit - PayloadBootInfo->SpMemBase, + (VOID *)(UINTN)PayloadBootInfo->SpHeapBase, + (VOID *)(UINTN)(PayloadBootInfo->SpHeapBase + PayloadBootInfo->SpHeapSize) ); // Check that the Hoblist starts at the bottom of the Heap - ASSERT (HobStart == (VOID *) (UINTN) PayloadBootInfo->SpHeapBase); + ASSERT (HobStart == (VOID *)(UINTN)PayloadBootInfo->SpHeapBase); // Build a Boot Firmware Volume HOB BuildFvHob (PayloadBootInfo->SpImageBase, PayloadBootInfo->SpImageSize); @@ -87,24 +86,24 @@ CreateHobListFromBootInfo ( // Build a resource descriptor Hob that describes the available physical // memory range Attributes = ( - 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 - ); + 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) PayloadBootInfo->SpMemBase, + (UINTN)PayloadBootInfo->SpMemBase, PayloadBootInfo->SpMemLimit - PayloadBootInfo->SpMemBase ); // Find the size of the GUIDed HOB with MP information - BufferSize = sizeof (MP_INFORMATION_HOB_DATA); + BufferSize = sizeof (MP_INFORMATION_HOB_DATA); BufferSize += sizeof (EFI_PROCESSOR_INFORMATION) * PayloadBootInfo->NumCpus; // Create a Guided MP information HOB to enable the ARM TF CPU driver to @@ -113,30 +112,31 @@ CreateHobListFromBootInfo ( // Populate the MP information HOB with the topology information passed by // privileged firmware - MpInformationHobData->NumberOfProcessors = PayloadBootInfo->NumCpus; + MpInformationHobData->NumberOfProcessors = PayloadBootInfo->NumCpus; MpInformationHobData->NumberOfEnabledProcessors = PayloadBootInfo->NumCpus; - ProcInfoBuffer = MpInformationHobData->ProcessorInfoBuffer; - CpuInfo = PayloadBootInfo->CpuInfo; + ProcInfoBuffer = MpInformationHobData->ProcessorInfoBuffer; + CpuInfo = PayloadBootInfo->CpuInfo; for (Index = 0; Index < PayloadBootInfo->NumCpus; Index++) { ProcInfoBuffer[Index].ProcessorId = CpuInfo[Index].Mpidr; - ProcInfoBuffer[Index].Location.Package = GET_CLUSTER_ID(CpuInfo[Index].Mpidr); - ProcInfoBuffer[Index].Location.Core = GET_CORE_ID(CpuInfo[Index].Mpidr); - ProcInfoBuffer[Index].Location.Thread = GET_CORE_ID(CpuInfo[Index].Mpidr); + ProcInfoBuffer[Index].Location.Package = GET_CLUSTER_ID (CpuInfo[Index].Mpidr); + ProcInfoBuffer[Index].Location.Core = GET_CORE_ID (CpuInfo[Index].Mpidr); + ProcInfoBuffer[Index].Location.Thread = GET_CORE_ID (CpuInfo[Index].Mpidr); Flags = PROCESSOR_ENABLED_BIT | PROCESSOR_HEALTH_STATUS_BIT; if (CpuInfo[Index].Flags & CPU_INFO_FLAG_PRIMARY_CPU) { Flags |= PROCESSOR_AS_BSP_BIT; } + ProcInfoBuffer[Index].StatusFlag = Flags; } // 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 = (EFI_MMRAM_DESCRIPTOR *) BuildGuidHob ( - &gEfiStandaloneMmNonSecureBufferGuid, - sizeof (EFI_MMRAM_DESCRIPTOR) - ); + NsCommBufMmramRange = (EFI_MMRAM_DESCRIPTOR *)BuildGuidHob ( + &gEfiStandaloneMmNonSecureBufferGuid, + sizeof (EFI_MMRAM_DESCRIPTOR) + ); NsCommBufMmramRange->PhysicalStart = PayloadBootInfo->SpNsCommBufBase; NsCommBufMmramRange->CpuStart = PayloadBootInfo->SpNsCommBufBase; NsCommBufMmramRange->PhysicalSize = PayloadBootInfo->SpNsCommBufSize; @@ -144,16 +144,16 @@ CreateHobListFromBootInfo ( // Create a Guided HOB to enable the ARM TF CPU driver to share its entry // point and populate it with the address of the shared buffer - CpuDriverEntryPointDesc = (ARM_TF_CPU_DRIVER_EP_DESCRIPTOR *) BuildGuidHob ( - &gEfiArmTfCpuDriverEpDescriptorGuid, - sizeof (ARM_TF_CPU_DRIVER_EP_DESCRIPTOR) - ); + CpuDriverEntryPointDesc = (ARM_TF_CPU_DRIVER_EP_DESCRIPTOR *)BuildGuidHob ( + &gEfiArmTfCpuDriverEpDescriptorGuid, + sizeof (ARM_TF_CPU_DRIVER_EP_DESCRIPTOR) + ); - *CpuDriverEntryPoint = NULL; + *CpuDriverEntryPoint = NULL; CpuDriverEntryPointDesc->ArmTfCpuDriverEpPtr = CpuDriverEntryPoint; // Find the size of the GUIDed HOB with SRAM ranges - BufferSize = sizeof (EFI_MMRAM_HOB_DESCRIPTOR_BLOCK); + BufferSize = sizeof (EFI_MMRAM_HOB_DESCRIPTOR_BLOCK); BufferSize += PayloadBootInfo->NumSpMemRegions * sizeof (EFI_MMRAM_DESCRIPTOR); // Create a GUIDed HOB with SRAM ranges @@ -190,9 +190,9 @@ CreateHobListFromBootInfo ( MmramRanges[3].RegionState = EFI_CACHEABLE | EFI_ALLOCATED; // Base and size of heap memory shared by all cpus - MmramRanges[4].PhysicalStart = (EFI_PHYSICAL_ADDRESS) (UINTN) HobStart; - MmramRanges[4].CpuStart = (EFI_PHYSICAL_ADDRESS) (UINTN) HobStart; - MmramRanges[4].PhysicalSize = HobStart->EfiFreeMemoryBottom - (EFI_PHYSICAL_ADDRESS) (UINTN) HobStart; + MmramRanges[4].PhysicalStart = (EFI_PHYSICAL_ADDRESS)(UINTN)HobStart; + MmramRanges[4].CpuStart = (EFI_PHYSICAL_ADDRESS)(UINTN)HobStart; + MmramRanges[4].PhysicalSize = HobStart->EfiFreeMemoryBottom - (EFI_PHYSICAL_ADDRESS)(UINTN)HobStart; MmramRanges[4].RegionState = EFI_CACHEABLE | EFI_ALLOCATED; // Base and size of heap memory shared by all cpus diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/SetPermissions.c b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/SetPermissions.c index cd4b90823e..8f2833a135 100644 --- a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/SetPermissions.c +++ b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/SetPermissions.c @@ -7,7 +7,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ - #include #include @@ -43,21 +42,21 @@ SPDX-License-Identifier: BSD-2-Clause-Patent EFI_STATUS EFIAPI UpdateMmFoundationPeCoffPermissions ( - IN CONST PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext, - IN EFI_PHYSICAL_ADDRESS ImageBase, - IN UINT32 SectionHeaderOffset, - IN CONST UINT16 NumberOfSections, - IN REGION_PERMISSION_UPDATE_FUNC TextUpdater, - IN REGION_PERMISSION_UPDATE_FUNC ReadOnlyUpdater, - IN REGION_PERMISSION_UPDATE_FUNC ReadWriteUpdater + IN CONST PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext, + IN EFI_PHYSICAL_ADDRESS ImageBase, + IN UINT32 SectionHeaderOffset, + IN CONST UINT16 NumberOfSections, + IN REGION_PERMISSION_UPDATE_FUNC TextUpdater, + IN REGION_PERMISSION_UPDATE_FUNC ReadOnlyUpdater, + IN REGION_PERMISSION_UPDATE_FUNC ReadWriteUpdater ) { - EFI_IMAGE_SECTION_HEADER SectionHeader; - RETURN_STATUS Status; - EFI_PHYSICAL_ADDRESS Base; - UINTN Size; - UINTN ReadSize; - UINTN Index; + EFI_IMAGE_SECTION_HEADER SectionHeader; + RETURN_STATUS Status; + EFI_PHYSICAL_ADDRESS Base; + UINTN Size; + UINTN ReadSize; + UINTN Index; ASSERT (ImageContext != NULL); @@ -68,35 +67,57 @@ UpdateMmFoundationPeCoffPermissions ( // // Read section header from file // - Size = sizeof (EFI_IMAGE_SECTION_HEADER); + Size = sizeof (EFI_IMAGE_SECTION_HEADER); ReadSize = Size; - Status = ImageContext->ImageRead ( - ImageContext->Handle, - SectionHeaderOffset, - &Size, - &SectionHeader - ); + Status = ImageContext->ImageRead ( + ImageContext->Handle, + SectionHeaderOffset, + &Size, + &SectionHeader + ); if (RETURN_ERROR (Status) || (Size != ReadSize)) { - DEBUG ((DEBUG_ERROR, - "%a: ImageContext->ImageRead () failed (Status = %r)\n", - __FUNCTION__, Status)); + DEBUG (( + DEBUG_ERROR, + "%a: ImageContext->ImageRead () failed (Status = %r)\n", + __FUNCTION__, + Status + )); return Status; } - DEBUG ((DEBUG_INFO, - "%a: Section %d of image at 0x%lx has 0x%x permissions\n", - __FUNCTION__, Index, ImageContext->ImageAddress, SectionHeader.Characteristics)); - DEBUG ((DEBUG_INFO, - "%a: Section %d of image at 0x%lx has %a name\n", - __FUNCTION__, Index, ImageContext->ImageAddress, SectionHeader.Name)); - DEBUG ((DEBUG_INFO, - "%a: Section %d of image at 0x%lx has 0x%x address\n", - __FUNCTION__, Index, ImageContext->ImageAddress, - ImageContext->ImageAddress + SectionHeader.VirtualAddress)); - DEBUG ((DEBUG_INFO, - "%a: Section %d of image at 0x%lx has 0x%x data\n", - __FUNCTION__, Index, ImageContext->ImageAddress, SectionHeader.PointerToRawData)); + DEBUG (( + DEBUG_INFO, + "%a: Section %d of image at 0x%lx has 0x%x permissions\n", + __FUNCTION__, + Index, + ImageContext->ImageAddress, + SectionHeader.Characteristics + )); + DEBUG (( + DEBUG_INFO, + "%a: Section %d of image at 0x%lx has %a name\n", + __FUNCTION__, + Index, + ImageContext->ImageAddress, + SectionHeader.Name + )); + DEBUG (( + DEBUG_INFO, + "%a: Section %d of image at 0x%lx has 0x%x address\n", + __FUNCTION__, + Index, + ImageContext->ImageAddress, + ImageContext->ImageAddress + SectionHeader.VirtualAddress + )); + DEBUG (( + DEBUG_INFO, + "%a: Section %d of image at 0x%lx has 0x%x data\n", + __FUNCTION__, + Index, + ImageContext->ImageAddress, + SectionHeader.PointerToRawData + )); // // If the section is marked as XN then remove the X attribute. Furthermore, @@ -109,19 +130,33 @@ UpdateMmFoundationPeCoffPermissions ( if ((SectionHeader.Characteristics & EFI_IMAGE_SCN_MEM_WRITE) != 0) { ReadWriteUpdater (Base, SectionHeader.Misc.VirtualSize); - DEBUG ((DEBUG_INFO, - "%a: Mapping section %d of image at 0x%lx with RW-XN permissions\n", - __FUNCTION__, Index, ImageContext->ImageAddress)); + DEBUG (( + DEBUG_INFO, + "%a: Mapping section %d of image at 0x%lx with RW-XN permissions\n", + __FUNCTION__, + Index, + ImageContext->ImageAddress + )); } else { - DEBUG ((DEBUG_INFO, - "%a: Mapping section %d of image at 0x%lx with RO-XN permissions\n", - __FUNCTION__, Index, ImageContext->ImageAddress)); + DEBUG (( + DEBUG_INFO, + "%a: Mapping section %d of image at 0x%lx with RO-XN permissions\n", + __FUNCTION__, + Index, + ImageContext->ImageAddress + )); } } else { - DEBUG ((DEBUG_INFO, - "%a: Ignoring section %d of image at 0x%lx with 0x%x permissions\n", - __FUNCTION__, Index, ImageContext->ImageAddress, SectionHeader.Characteristics)); + DEBUG (( + DEBUG_INFO, + "%a: Ignoring section %d of image at 0x%lx with 0x%x permissions\n", + __FUNCTION__, + Index, + ImageContext->ImageAddress, + SectionHeader.Characteristics + )); } + SectionHeaderOffset += sizeof (EFI_IMAGE_SECTION_HEADER); } @@ -142,24 +177,27 @@ UpdateMmFoundationPeCoffPermissions ( EFI_STATUS EFIAPI LocateStandaloneMmCorePeCoffData ( - IN EFI_FIRMWARE_VOLUME_HEADER *BfvAddress, - IN OUT VOID **TeData, - IN OUT UINTN *TeDataSize + IN EFI_FIRMWARE_VOLUME_HEADER *BfvAddress, + IN OUT VOID **TeData, + IN OUT UINTN *TeDataSize ) { - EFI_FFS_FILE_HEADER *FileHeader; - EFI_STATUS Status; + EFI_FFS_FILE_HEADER *FileHeader; + EFI_STATUS Status; FileHeader = NULL; - Status = FfsFindNextFile ( - EFI_FV_FILETYPE_SECURITY_CORE, - BfvAddress, - &FileHeader - ); + Status = FfsFindNextFile ( + EFI_FV_FILETYPE_SECURITY_CORE, + BfvAddress, + &FileHeader + ); if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "Unable to locate Standalone MM FFS file - 0x%x\n", - Status)); + DEBUG (( + DEBUG_ERROR, + "Unable to locate Standalone MM FFS file - 0x%x\n", + Status + )); return Status; } @@ -167,8 +205,11 @@ LocateStandaloneMmCorePeCoffData ( if (EFI_ERROR (Status)) { Status = FfsFindSectionData (EFI_SECTION_TE, FileHeader, TeData, TeDataSize); if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "Unable to locate Standalone MM Section data - %r\n", - Status)); + DEBUG (( + DEBUG_ERROR, + "Unable to locate Standalone MM Section data - %r\n", + Status + )); return Status; } } @@ -189,17 +230,17 @@ LocateStandaloneMmCorePeCoffData ( STATIC EFI_STATUS GetPeCoffSectionInformation ( - IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext, - OUT EFI_PHYSICAL_ADDRESS *ImageBase, - OUT UINT32 *SectionHeaderOffset, - OUT UINT16 *NumberOfSections + IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext, + OUT EFI_PHYSICAL_ADDRESS *ImageBase, + OUT UINT32 *SectionHeaderOffset, + OUT UINT16 *NumberOfSections ) { - RETURN_STATUS Status; - EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr; - EFI_IMAGE_OPTIONAL_HEADER_UNION HdrData; - UINTN Size; - UINTN ReadSize; + RETURN_STATUS Status; + EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr; + EFI_IMAGE_OPTIONAL_HEADER_UNION HdrData; + UINTN Size; + UINTN ReadSize; ASSERT (ImageContext != NULL); ASSERT (SectionHeaderOffset != NULL); @@ -207,9 +248,12 @@ GetPeCoffSectionInformation ( Status = PeCoffLoaderGetImageInfo (ImageContext); if (RETURN_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, - "%a: PeCoffLoaderGetImageInfo () failed (Status == %r)\n", - __FUNCTION__, Status)); + DEBUG (( + DEBUG_ERROR, + "%a: PeCoffLoaderGetImageInfo () failed (Status == %r)\n", + __FUNCTION__, + Status + )); return Status; } @@ -219,11 +263,16 @@ GetPeCoffSectionInformation ( // granularity at which we can tighten permissions. // if (!ImageContext->IsTeImage) { - DEBUG ((DEBUG_WARN, - "%a: non-TE Image at 0x%lx has SectionAlignment < 4 KB (%lu)\n", - __FUNCTION__, ImageContext->ImageAddress, ImageContext->SectionAlignment)); + DEBUG (( + DEBUG_WARN, + "%a: non-TE Image at 0x%lx has SectionAlignment < 4 KB (%lu)\n", + __FUNCTION__, + ImageContext->ImageAddress, + ImageContext->SectionAlignment + )); return RETURN_UNSUPPORTED; } + ImageContext->SectionAlignment = EFI_PAGE_SIZE; } @@ -234,19 +283,22 @@ GetPeCoffSectionInformation ( // location in both images. // Hdr.Union = &HdrData; - Size = sizeof (EFI_IMAGE_OPTIONAL_HEADER_UNION); - ReadSize = Size; - Status = ImageContext->ImageRead ( - ImageContext->Handle, - ImageContext->PeCoffHeaderOffset, - &Size, - Hdr.Pe32 - ); + Size = sizeof (EFI_IMAGE_OPTIONAL_HEADER_UNION); + ReadSize = Size; + Status = ImageContext->ImageRead ( + ImageContext->Handle, + ImageContext->PeCoffHeaderOffset, + &Size, + Hdr.Pe32 + ); if (RETURN_ERROR (Status) || (Size != ReadSize)) { - DEBUG ((DEBUG_ERROR, - "%a: TmpContext->ImageRead () failed (Status = %r)\n", - __FUNCTION__, Status)); + DEBUG (( + DEBUG_ERROR, + "%a: TmpContext->ImageRead () failed (Status = %r)\n", + __FUNCTION__, + Status + )); return Status; } @@ -255,24 +307,25 @@ GetPeCoffSectionInformation ( ASSERT (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE); *SectionHeaderOffset = ImageContext->PeCoffHeaderOffset + sizeof (UINT32) + - sizeof (EFI_IMAGE_FILE_HEADER); - *NumberOfSections = Hdr.Pe32->FileHeader.NumberOfSections; + sizeof (EFI_IMAGE_FILE_HEADER); + *NumberOfSections = Hdr.Pe32->FileHeader.NumberOfSections; switch (Hdr.Pe32->OptionalHeader.Magic) { - case EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC: - *SectionHeaderOffset += Hdr.Pe32->FileHeader.SizeOfOptionalHeader; - break; - case EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC: - *SectionHeaderOffset += Hdr.Pe32Plus->FileHeader.SizeOfOptionalHeader; - break; - default: - ASSERT (FALSE); + case EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC: + *SectionHeaderOffset += Hdr.Pe32->FileHeader.SizeOfOptionalHeader; + break; + case EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC: + *SectionHeaderOffset += Hdr.Pe32Plus->FileHeader.SizeOfOptionalHeader; + break; + default: + ASSERT (FALSE); } } else { *SectionHeaderOffset = (UINTN)(sizeof (EFI_TE_IMAGE_HEADER)); - *NumberOfSections = Hdr.Te->NumberOfSections; - *ImageBase -= (UINT32)Hdr.Te->StrippedSize - sizeof (EFI_TE_IMAGE_HEADER); + *NumberOfSections = Hdr.Te->NumberOfSections; + *ImageBase -= (UINT32)Hdr.Te->StrippedSize - sizeof (EFI_TE_IMAGE_HEADER); } + return RETURN_SUCCESS; } @@ -292,14 +345,14 @@ GetPeCoffSectionInformation ( EFI_STATUS EFIAPI GetStandaloneMmCorePeCoffSections ( - IN VOID *TeData, - IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext, - OUT EFI_PHYSICAL_ADDRESS *ImageBase, - IN OUT UINT32 *SectionHeaderOffset, - IN OUT UINT16 *NumberOfSections + IN VOID *TeData, + IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext, + OUT EFI_PHYSICAL_ADDRESS *ImageBase, + IN OUT UINT32 *SectionHeaderOffset, + IN OUT UINT16 *NumberOfSections ) { - EFI_STATUS Status; + EFI_STATUS Status; // Initialize the Image Context ZeroMem (ImageContext, sizeof (PE_COFF_LOADER_IMAGE_CONTEXT)); @@ -308,15 +361,23 @@ GetStandaloneMmCorePeCoffSections ( DEBUG ((DEBUG_INFO, "Found Standalone MM PE data - 0x%x\n", TeData)); - Status = GetPeCoffSectionInformation (ImageContext, ImageBase, - SectionHeaderOffset, NumberOfSections); + Status = GetPeCoffSectionInformation ( + ImageContext, + ImageBase, + SectionHeaderOffset, + NumberOfSections + ); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "Unable to locate Standalone MM Core PE-COFF Section information - %r\n", Status)); return Status; } - DEBUG ((DEBUG_INFO, "Standalone MM Core PE-COFF SectionHeaderOffset - 0x%x, NumberOfSections - %d\n", - *SectionHeaderOffset, *NumberOfSections)); + DEBUG (( + DEBUG_INFO, + "Standalone MM Core PE-COFF SectionHeaderOffset - 0x%x, NumberOfSections - %d\n", + *SectionHeaderOffset, + *NumberOfSections + )); return Status; } diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMmCoreEntryPoint.c b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMmCoreEntryPoint.c index 49cf51a789..9163025bca 100644 --- a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMmCoreEntryPoint.c +++ b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMmCoreEntryPoint.c @@ -7,7 +7,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ - #include #include @@ -29,20 +28,20 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include -#define SPM_MAJOR_VER_MASK 0xFFFF0000 -#define SPM_MINOR_VER_MASK 0x0000FFFF -#define SPM_MAJOR_VER_SHIFT 16 -#define FFA_NOT_SUPPORTED -1 +#define SPM_MAJOR_VER_MASK 0xFFFF0000 +#define SPM_MINOR_VER_MASK 0x0000FFFF +#define SPM_MAJOR_VER_SHIFT 16 +#define FFA_NOT_SUPPORTED -1 -STATIC CONST UINT32 mSpmMajorVer = SPM_MAJOR_VERSION; -STATIC CONST UINT32 mSpmMinorVer = SPM_MINOR_VERSION; +STATIC CONST UINT32 mSpmMajorVer = SPM_MAJOR_VERSION; +STATIC CONST UINT32 mSpmMinorVer = SPM_MINOR_VERSION; -STATIC CONST UINT32 mSpmMajorVerFfa = SPM_MAJOR_VERSION_FFA; -STATIC CONST UINT32 mSpmMinorVerFfa = SPM_MINOR_VERSION_FFA; +STATIC CONST UINT32 mSpmMajorVerFfa = SPM_MAJOR_VERSION_FFA; +STATIC CONST UINT32 mSpmMinorVerFfa = SPM_MINOR_VERSION_FFA; -#define BOOT_PAYLOAD_VERSION 1 +#define BOOT_PAYLOAD_VERSION 1 -PI_MM_ARM_TF_CPU_DRIVER_ENTRYPOINT CpuDriverEntryPoint = NULL; +PI_MM_ARM_TF_CPU_DRIVER_ENTRYPOINT CpuDriverEntryPoint = NULL; /** Retrieve a pointer to and print the boot information passed by privileged @@ -54,14 +53,14 @@ PI_MM_ARM_TF_CPU_DRIVER_ENTRYPOINT CpuDriverEntryPoint = NULL; **/ EFI_SECURE_PARTITION_BOOT_INFO * GetAndPrintBootinformation ( - IN VOID *SharedBufAddress -) + IN VOID *SharedBufAddress + ) { - EFI_SECURE_PARTITION_BOOT_INFO *PayloadBootInfo; - EFI_SECURE_PARTITION_CPU_INFO *PayloadCpuInfo; - UINTN Index; + EFI_SECURE_PARTITION_BOOT_INFO *PayloadBootInfo; + EFI_SECURE_PARTITION_CPU_INFO *PayloadCpuInfo; + UINTN Index; - PayloadBootInfo = (EFI_SECURE_PARTITION_BOOT_INFO *) SharedBufAddress; + PayloadBootInfo = (EFI_SECURE_PARTITION_BOOT_INFO *)SharedBufAddress; if (PayloadBootInfo == NULL) { DEBUG ((DEBUG_ERROR, "PayloadBootInfo NULL\n")); @@ -69,8 +68,12 @@ GetAndPrintBootinformation ( } if (PayloadBootInfo->Header.Version != BOOT_PAYLOAD_VERSION) { - DEBUG ((DEBUG_ERROR, "Boot Information Version Mismatch. Current=0x%x, Expected=0x%x.\n", - PayloadBootInfo->Header.Version, BOOT_PAYLOAD_VERSION)); + DEBUG (( + DEBUG_ERROR, + "Boot Information Version Mismatch. Current=0x%x, Expected=0x%x.\n", + PayloadBootInfo->Header.Version, + BOOT_PAYLOAD_VERSION + )); return NULL; } @@ -92,7 +95,7 @@ GetAndPrintBootinformation ( DEBUG ((DEBUG_INFO, "NumCpus - 0x%x\n", PayloadBootInfo->NumCpus)); DEBUG ((DEBUG_INFO, "CpuInfo - 0x%p\n", PayloadBootInfo->CpuInfo)); - PayloadCpuInfo = (EFI_SECURE_PARTITION_CPU_INFO *) PayloadBootInfo->CpuInfo; + PayloadCpuInfo = (EFI_SECURE_PARTITION_CPU_INFO *)PayloadBootInfo->CpuInfo; if (PayloadCpuInfo == NULL) { DEBUG ((DEBUG_ERROR, "PayloadCpuInfo NULL\n")); @@ -117,25 +120,25 @@ GetAndPrintBootinformation ( VOID EFIAPI DelegatedEventLoop ( - IN ARM_SVC_ARGS *EventCompleteSvcArgs + IN ARM_SVC_ARGS *EventCompleteSvcArgs ) { - BOOLEAN FfaEnabled; - EFI_STATUS Status; - UINTN SvcStatus; + BOOLEAN FfaEnabled; + EFI_STATUS Status; + UINTN SvcStatus; while (TRUE) { ArmCallSvc (EventCompleteSvcArgs); DEBUG ((DEBUG_INFO, "Received delegated event\n")); - DEBUG ((DEBUG_INFO, "X0 : 0x%x\n", (UINT32) EventCompleteSvcArgs->Arg0)); - DEBUG ((DEBUG_INFO, "X1 : 0x%x\n", (UINT32) EventCompleteSvcArgs->Arg1)); - DEBUG ((DEBUG_INFO, "X2 : 0x%x\n", (UINT32) EventCompleteSvcArgs->Arg2)); - DEBUG ((DEBUG_INFO, "X3 : 0x%x\n", (UINT32) EventCompleteSvcArgs->Arg3)); - DEBUG ((DEBUG_INFO, "X4 : 0x%x\n", (UINT32) EventCompleteSvcArgs->Arg4)); - DEBUG ((DEBUG_INFO, "X5 : 0x%x\n", (UINT32) EventCompleteSvcArgs->Arg5)); - DEBUG ((DEBUG_INFO, "X6 : 0x%x\n", (UINT32) EventCompleteSvcArgs->Arg6)); - DEBUG ((DEBUG_INFO, "X7 : 0x%x\n", (UINT32) EventCompleteSvcArgs->Arg7)); + DEBUG ((DEBUG_INFO, "X0 : 0x%x\n", (UINT32)EventCompleteSvcArgs->Arg0)); + DEBUG ((DEBUG_INFO, "X1 : 0x%x\n", (UINT32)EventCompleteSvcArgs->Arg1)); + DEBUG ((DEBUG_INFO, "X2 : 0x%x\n", (UINT32)EventCompleteSvcArgs->Arg2)); + DEBUG ((DEBUG_INFO, "X3 : 0x%x\n", (UINT32)EventCompleteSvcArgs->Arg3)); + DEBUG ((DEBUG_INFO, "X4 : 0x%x\n", (UINT32)EventCompleteSvcArgs->Arg4)); + DEBUG ((DEBUG_INFO, "X5 : 0x%x\n", (UINT32)EventCompleteSvcArgs->Arg5)); + DEBUG ((DEBUG_INFO, "X6 : 0x%x\n", (UINT32)EventCompleteSvcArgs->Arg6)); + DEBUG ((DEBUG_INFO, "X7 : 0x%x\n", (UINT32)EventCompleteSvcArgs->Arg7)); FfaEnabled = FeaturePcdGet (PcdFfaEnable); if (FfaEnabled) { @@ -145,8 +148,12 @@ DelegatedEventLoop ( EventCompleteSvcArgs->Arg3 ); if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "Failed delegated event 0x%x, Status 0x%x\n", - EventCompleteSvcArgs->Arg3, Status)); + DEBUG (( + DEBUG_ERROR, + "Failed delegated event 0x%x, Status 0x%x\n", + EventCompleteSvcArgs->Arg3, + Status + )); } } else { Status = CpuDriverEntryPoint ( @@ -155,30 +162,34 @@ DelegatedEventLoop ( EventCompleteSvcArgs->Arg1 ); if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "Failed delegated event 0x%x, Status 0x%x\n", - EventCompleteSvcArgs->Arg0, Status)); + DEBUG (( + DEBUG_ERROR, + "Failed delegated event 0x%x, Status 0x%x\n", + EventCompleteSvcArgs->Arg0, + Status + )); } } switch (Status) { - case EFI_SUCCESS: - SvcStatus = ARM_SVC_SPM_RET_SUCCESS; - break; - case EFI_INVALID_PARAMETER: - SvcStatus = ARM_SVC_SPM_RET_INVALID_PARAMS; - break; - case EFI_ACCESS_DENIED: - SvcStatus = ARM_SVC_SPM_RET_DENIED; - break; - case EFI_OUT_OF_RESOURCES: - SvcStatus = ARM_SVC_SPM_RET_NO_MEMORY; - break; - case EFI_UNSUPPORTED: - SvcStatus = ARM_SVC_SPM_RET_NOT_SUPPORTED; - break; - default: - SvcStatus = ARM_SVC_SPM_RET_NOT_SUPPORTED; - break; + case EFI_SUCCESS: + SvcStatus = ARM_SVC_SPM_RET_SUCCESS; + break; + case EFI_INVALID_PARAMETER: + SvcStatus = ARM_SVC_SPM_RET_INVALID_PARAMS; + break; + case EFI_ACCESS_DENIED: + SvcStatus = ARM_SVC_SPM_RET_DENIED; + break; + case EFI_OUT_OF_RESOURCES: + SvcStatus = ARM_SVC_SPM_RET_NO_MEMORY; + break; + case EFI_UNSUPPORTED: + SvcStatus = ARM_SVC_SPM_RET_NOT_SUPPORTED; + break; + default: + SvcStatus = ARM_SVC_SPM_RET_NOT_SUPPORTED; + break; } if (FfaEnabled) { @@ -202,26 +213,28 @@ DelegatedEventLoop ( **/ STATIC EFI_STATUS -GetSpmVersion (VOID) +GetSpmVersion ( + VOID + ) { - EFI_STATUS Status; - UINT16 CalleeSpmMajorVer; - UINT16 CallerSpmMajorVer; - UINT16 CalleeSpmMinorVer; - UINT16 CallerSpmMinorVer; - UINT32 SpmVersion; - ARM_SVC_ARGS SpmVersionArgs; + EFI_STATUS Status; + UINT16 CalleeSpmMajorVer; + UINT16 CallerSpmMajorVer; + UINT16 CalleeSpmMinorVer; + UINT16 CallerSpmMinorVer; + UINT32 SpmVersion; + ARM_SVC_ARGS SpmVersionArgs; if (FeaturePcdGet (PcdFfaEnable)) { - SpmVersionArgs.Arg0 = ARM_SVC_ID_FFA_VERSION_AARCH32; - SpmVersionArgs.Arg1 = mSpmMajorVerFfa << SPM_MAJOR_VER_SHIFT; + SpmVersionArgs.Arg0 = ARM_SVC_ID_FFA_VERSION_AARCH32; + SpmVersionArgs.Arg1 = mSpmMajorVerFfa << SPM_MAJOR_VER_SHIFT; SpmVersionArgs.Arg1 |= mSpmMinorVerFfa; - CallerSpmMajorVer = mSpmMajorVerFfa; - CallerSpmMinorVer = mSpmMinorVerFfa; + CallerSpmMajorVer = mSpmMajorVerFfa; + CallerSpmMinorVer = mSpmMinorVerFfa; } else { SpmVersionArgs.Arg0 = ARM_SVC_ID_SPM_VERSION_AARCH32; - CallerSpmMajorVer = mSpmMajorVer; - CallerSpmMinorVer = mSpmMinorVer; + CallerSpmMajorVer = mSpmMajorVer; + CallerSpmMinorVer = mSpmMinorVer; } ArmCallSvc (&SpmVersionArgs); @@ -244,14 +257,22 @@ GetSpmVersion (VOID) if ((CalleeSpmMajorVer == CallerSpmMajorVer) && (CalleeSpmMinorVer >= CallerSpmMinorVer)) { - DEBUG ((DEBUG_INFO, "SPM Version: Major=0x%x, Minor=0x%x\n", - CalleeSpmMajorVer, CalleeSpmMinorVer)); + DEBUG (( + DEBUG_INFO, + "SPM Version: Major=0x%x, Minor=0x%x\n", + CalleeSpmMajorVer, + CalleeSpmMinorVer + )); Status = EFI_SUCCESS; - } - else - { - DEBUG ((DEBUG_INFO, "Incompatible SPM Versions.\n Callee Version: Major=0x%x, Minor=0x%x.\n Caller: Major=0x%x, Minor>=0x%x.\n", - CalleeSpmMajorVer, CalleeSpmMinorVer, CallerSpmMajorVer, CallerSpmMinorVer)); + } else { + DEBUG (( + DEBUG_INFO, + "Incompatible SPM Versions.\n Callee Version: Major=0x%x, Minor=0x%x.\n Caller: Major=0x%x, Minor>=0x%x.\n", + CalleeSpmMajorVer, + CalleeSpmMinorVer, + CallerSpmMajorVer, + CallerSpmMinorVer + )); Status = EFI_UNSUPPORTED; } @@ -268,8 +289,8 @@ GetSpmVersion (VOID) STATIC VOID InitArmSvcArgs ( - OUT ARM_SVC_ARGS *InitMmFoundationSvcArgs, - OUT INT32 *Ret + OUT ARM_SVC_ARGS *InitMmFoundationSvcArgs, + OUT INT32 *Ret ) { if (FeaturePcdGet (PcdFfaEnable)) { @@ -302,17 +323,17 @@ _ModuleEntryPoint ( IN UINT64 cookie2 ) { - PE_COFF_LOADER_IMAGE_CONTEXT ImageContext; - EFI_SECURE_PARTITION_BOOT_INFO *PayloadBootInfo; - ARM_SVC_ARGS InitMmFoundationSvcArgs; - EFI_STATUS Status; - INT32 Ret; - UINT32 SectionHeaderOffset; - UINT16 NumberOfSections; - VOID *HobStart; - VOID *TeData; - UINTN TeDataSize; - EFI_PHYSICAL_ADDRESS ImageBase; + PE_COFF_LOADER_IMAGE_CONTEXT ImageContext; + EFI_SECURE_PARTITION_BOOT_INFO *PayloadBootInfo; + ARM_SVC_ARGS InitMmFoundationSvcArgs; + EFI_STATUS Status; + INT32 Ret; + UINT32 SectionHeaderOffset; + UINT16 NumberOfSections; + VOID *HobStart; + VOID *TeData; + UINTN TeDataSize; + EFI_PHYSICAL_ADDRESS ImageBase; // Get Secure Partition Manager Version Information Status = GetSpmVersion (); @@ -328,7 +349,7 @@ _ModuleEntryPoint ( // Locate PE/COFF File information for the Standalone MM core module Status = LocateStandaloneMmCorePeCoffData ( - (EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) PayloadBootInfo->SpImageBase, + (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)PayloadBootInfo->SpImageBase, &TeData, &TeDataSize ); @@ -395,7 +416,7 @@ _ModuleEntryPoint ( // ProcessModuleEntryPointList (HobStart); - DEBUG ((DEBUG_INFO, "Shared Cpu Driver EP %p\n", (VOID *) CpuDriverEntryPoint)); + DEBUG ((DEBUG_INFO, "Shared Cpu Driver EP %p\n", (VOID *)CpuDriverEntryPoint)); finish: if (Status == RETURN_UNSUPPORTED) { @@ -407,7 +428,8 @@ finish: } else { Ret = 0; } - ZeroMem (&InitMmFoundationSvcArgs, sizeof(InitMmFoundationSvcArgs)); + + ZeroMem (&InitMmFoundationSvcArgs, sizeof (InitMmFoundationSvcArgs)); InitArmSvcArgs (&InitMmFoundationSvcArgs, &Ret); DelegatedEventLoop (&InitMmFoundationSvcArgs); } diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/X64/StandaloneMmCoreEntryPoint.c b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/X64/StandaloneMmCoreEntryPoint.c index dffa965b84..98e6c0d766 100644 --- a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/X64/StandaloneMmCoreEntryPoint.c +++ b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/X64/StandaloneMmCoreEntryPoint.c @@ -7,7 +7,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ - #include #include @@ -17,7 +16,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent // // Cache copy of HobList pointer. // -VOID *gHobList = NULL; +VOID *gHobList = NULL; /** The entry point of PE/COFF Image for the STANDALONE MM Core. @@ -52,7 +51,6 @@ _ModuleEntryPoint ( // } - /** Required by the EBC compiler and identical in functionality to _ModuleEntryPoint(). -- cgit v1.2.3