diff options
Diffstat (limited to 'StandaloneMmPkg/Library')
17 files changed, 814 insertions, 646 deletions
diff --git a/StandaloneMmPkg/Library/FvLib/FvLib.c b/StandaloneMmPkg/Library/FvLib/FvLib.c index 94139ae..aa36a35 100644 --- a/StandaloneMmPkg/Library/FvLib/FvLib.c +++ b/StandaloneMmPkg/Library/FvLib/FvLib.c @@ -37,7 +37,7 @@ GetFileState ( FileState = FfsHeader->State;
if (ErasePolarity != 0) {
- FileState = (EFI_FFS_FILE_STATE)~FileState;
+ FileState = (EFI_FFS_FILE_STATE) ~FileState;
}
HighestBit = 0x80;
@@ -60,31 +60,32 @@ CalculateHeaderChecksum ( IN EFI_FFS_FILE_HEADER *FileHeader
)
{
- UINT8 *ptr;
- UINTN Index;
- UINT8 Sum;
+ UINT8 *ptr;
+ UINTN Index;
+ UINT8 Sum;
Sum = 0;
- ptr = (UINT8 *) FileHeader;
+ ptr = (UINT8 *)FileHeader;
for (Index = 0; Index < sizeof (EFI_FFS_FILE_HEADER) - 3; Index += 4) {
- Sum = (UINT8) (Sum + ptr[Index]);
- Sum = (UINT8) (Sum + ptr[Index + 1]);
- Sum = (UINT8) (Sum + ptr[Index + 2]);
- Sum = (UINT8) (Sum + ptr[Index + 3]);
+ Sum = (UINT8)(Sum + ptr[Index]);
+ Sum = (UINT8)(Sum + ptr[Index + 1]);
+ Sum = (UINT8)(Sum + ptr[Index + 2]);
+ Sum = (UINT8)(Sum + ptr[Index + 3]);
}
- for (; Index < sizeof (EFI_FFS_FILE_HEADER); Index++) {
- Sum = (UINT8) (Sum + ptr[Index]);
+ for ( ; Index < sizeof (EFI_FFS_FILE_HEADER); Index++) {
+ Sum = (UINT8)(Sum + ptr[Index]);
}
+
//
// State field (since this indicates the different state of file).
//
- Sum = (UINT8) (Sum - FileHeader->State);
+ Sum = (UINT8)(Sum - FileHeader->State);
//
// Checksum field of the file is not part of the header checksum.
//
- Sum = (UINT8) (Sum - FileHeader->IntegrityCheck.Checksum.File);
+ Sum = (UINT8)(Sum - FileHeader->IntegrityCheck.Checksum.File);
return Sum;
}
@@ -112,15 +113,15 @@ FfsFindNextFile ( IN OUT EFI_FFS_FILE_HEADER **FileHeader
)
{
- EFI_FIRMWARE_VOLUME_EXT_HEADER *FvExtHeader;
+ EFI_FIRMWARE_VOLUME_EXT_HEADER *FvExtHeader;
- EFI_FFS_FILE_HEADER *FfsFileHeader;
- UINT32 FileLength;
- UINT32 FileOccupiedSize;
- UINT32 FileOffset;
- UINT64 FvLength;
- UINT8 ErasePolarity;
- UINT8 FileState;
+ EFI_FFS_FILE_HEADER *FfsFileHeader;
+ UINT32 FileLength;
+ UINT32 FileOccupiedSize;
+ UINT32 FileOffset;
+ UINT64 FvLength;
+ UINT8 ErasePolarity;
+ UINT8 FileState;
FvLength = FwVolHeader->FvLength;
if (FwVolHeader->Attributes & EFI_FVB2_ERASE_POLARITY) {
@@ -128,41 +129,40 @@ FfsFindNextFile ( } else {
ErasePolarity = 0;
}
+
//
// If FileHeader is not specified (NULL) start with the first file in the
// firmware volume. Otherwise, start from the FileHeader.
//
if (*FileHeader == NULL) {
-
if (FwVolHeader->ExtHeaderOffset != 0) {
-
FvExtHeader = (EFI_FIRMWARE_VOLUME_EXT_HEADER *)((UINT8 *)FwVolHeader +
FwVolHeader->ExtHeaderOffset);
FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FvExtHeader +
FvExtHeader->ExtHeaderSize);
-
} else {
-
FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FwVolHeader +
FwVolHeader->HeaderLength);
-
}
FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINTN)FwVolHeader +
- ALIGN_VALUE((UINTN)FfsFileHeader -
- (UINTN)FwVolHeader, 8));
+ ALIGN_VALUE (
+ (UINTN)FfsFileHeader -
+ (UINTN)FwVolHeader,
+ 8
+ ));
} else {
//
// Length is 24 bits wide so mask upper 8 bits
// FileLength is adjusted to FileOccupiedSize as it is 8 byte aligned.
//
- FileLength = FFS_FILE_SIZE(*FileHeader);
- FileOccupiedSize = GET_OCCUPIED_SIZE (FileLength, 8);
- FfsFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) *FileHeader + FileOccupiedSize);
+ FileLength = FFS_FILE_SIZE (*FileHeader);
+ FileOccupiedSize = GET_OCCUPIED_SIZE (FileLength, 8);
+ FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)*FileHeader + FileOccupiedSize);
}
- FileOffset = (UINT32) ((UINT8 *) FfsFileHeader - (UINT8 *) FwVolHeader);
+ FileOffset = (UINT32)((UINT8 *)FfsFileHeader - (UINT8 *)FwVolHeader);
while (FileOffset < (FvLength - sizeof (EFI_FFS_FILE_HEADER))) {
//
@@ -171,42 +171,40 @@ FfsFindNextFile ( FileState = GetFileState (ErasePolarity, FfsFileHeader);
switch (FileState) {
-
- case EFI_FILE_HEADER_INVALID:
- FileOffset += sizeof (EFI_FFS_FILE_HEADER);
- FfsFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsFileHeader + sizeof (EFI_FFS_FILE_HEADER));
- break;
-
- case EFI_FILE_DATA_VALID:
- case EFI_FILE_MARKED_FOR_UPDATE:
- if (CalculateHeaderChecksum (FfsFileHeader) == 0) {
- FileLength = FFS_FILE_SIZE(FfsFileHeader);
- FileOccupiedSize = GET_OCCUPIED_SIZE (FileLength, 8);
-
- if ((SearchType == FfsFileHeader->Type) || (SearchType == EFI_FV_FILETYPE_ALL)) {
-
- *FileHeader = FfsFileHeader;
-
- return EFI_SUCCESS;
+ case EFI_FILE_HEADER_INVALID:
+ FileOffset += sizeof (EFI_FFS_FILE_HEADER);
+ FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsFileHeader + sizeof (EFI_FFS_FILE_HEADER));
+ break;
+
+ case EFI_FILE_DATA_VALID:
+ case EFI_FILE_MARKED_FOR_UPDATE:
+ if (CalculateHeaderChecksum (FfsFileHeader) == 0) {
+ FileLength = FFS_FILE_SIZE (FfsFileHeader);
+ FileOccupiedSize = GET_OCCUPIED_SIZE (FileLength, 8);
+
+ if ((SearchType == FfsFileHeader->Type) || (SearchType == EFI_FV_FILETYPE_ALL)) {
+ *FileHeader = FfsFileHeader;
+
+ return EFI_SUCCESS;
+ }
+
+ FileOffset += FileOccupiedSize;
+ FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsFileHeader + FileOccupiedSize);
+ } else {
+ return EFI_NOT_FOUND;
}
- FileOffset += FileOccupiedSize;
- FfsFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsFileHeader + FileOccupiedSize);
- } else {
- return EFI_NOT_FOUND;
- }
- break;
-
- case EFI_FILE_DELETED:
- FileLength = FFS_FILE_SIZE(FfsFileHeader);
- FileOccupiedSize = GET_OCCUPIED_SIZE (FileLength, 8);
- FileOffset += FileOccupiedSize;
- FfsFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsFileHeader + FileOccupiedSize);
- break;
+ break;
- default:
- return EFI_NOT_FOUND;
+ case EFI_FILE_DELETED:
+ FileLength = FFS_FILE_SIZE (FfsFileHeader);
+ FileOccupiedSize = GET_OCCUPIED_SIZE (FileLength, 8);
+ FileOffset += FileOccupiedSize;
+ FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsFileHeader + FileOccupiedSize);
+ break;
+ default:
+ return EFI_NOT_FOUND;
}
}
@@ -229,30 +227,31 @@ FfsFindNextFile ( EFI_STATUS
EFIAPI
FindFfsSectionInSections (
- IN VOID *Sections,
- IN UINTN SizeOfSections,
- IN EFI_SECTION_TYPE SectionType,
- OUT EFI_COMMON_SECTION_HEADER **FoundSection
+ IN VOID *Sections,
+ IN UINTN SizeOfSections,
+ IN EFI_SECTION_TYPE SectionType,
+ OUT EFI_COMMON_SECTION_HEADER **FoundSection
)
{
- EFI_PHYSICAL_ADDRESS CurrentAddress;
- UINT32 Size;
- EFI_PHYSICAL_ADDRESS EndOfSections;
- EFI_COMMON_SECTION_HEADER *Section;
- EFI_PHYSICAL_ADDRESS EndOfSection;
+ EFI_PHYSICAL_ADDRESS CurrentAddress;
+ UINT32 Size;
+ EFI_PHYSICAL_ADDRESS EndOfSections;
+ EFI_COMMON_SECTION_HEADER *Section;
+ EFI_PHYSICAL_ADDRESS EndOfSection;
//
// Loop through the FFS file sections
//
- EndOfSection = (EFI_PHYSICAL_ADDRESS)(UINTN) Sections;
+ EndOfSection = (EFI_PHYSICAL_ADDRESS)(UINTN)Sections;
EndOfSections = EndOfSection + SizeOfSections;
- for (;;) {
+ for ( ; ;) {
if (EndOfSection == EndOfSections) {
break;
}
+
CurrentAddress = EndOfSection;
- Section = (EFI_COMMON_SECTION_HEADER*)(UINTN) CurrentAddress;
+ Section = (EFI_COMMON_SECTION_HEADER *)(UINTN)CurrentAddress;
Size = SECTION_SIZE (Section);
if (Size < sizeof (*Section)) {
@@ -263,6 +262,7 @@ FindFfsSectionInSections ( if (EndOfSection > EndOfSections) {
return EFI_VOLUME_CORRUPTED;
}
+
Size = GET_OCCUPIED_SIZE (Size, 4);
//
@@ -292,22 +292,22 @@ FindFfsSectionInSections ( EFI_STATUS
EFIAPI
FfsFindSection (
- IN EFI_SECTION_TYPE SectionType,
- IN EFI_FFS_FILE_HEADER *FfsFileHeader,
- IN OUT EFI_COMMON_SECTION_HEADER **SectionHeader
+ IN EFI_SECTION_TYPE SectionType,
+ IN EFI_FFS_FILE_HEADER *FfsFileHeader,
+ IN OUT EFI_COMMON_SECTION_HEADER **SectionHeader
)
{
- UINT32 FileSize;
- EFI_COMMON_SECTION_HEADER *Section;
- EFI_STATUS Status;
+ UINT32 FileSize;
+ EFI_COMMON_SECTION_HEADER *Section;
+ EFI_STATUS Status;
//
// Size is 24 bits wide so mask upper 8 bits.
// Does not include FfsFileHeader header size
// FileSize is adjusted to FileOccupiedSize as it is 8 byte aligned.
//
- Section = (EFI_COMMON_SECTION_HEADER *) (FfsFileHeader + 1);
- FileSize = FFS_FILE_SIZE(FfsFileHeader);
+ Section = (EFI_COMMON_SECTION_HEADER *)(FfsFileHeader + 1);
+ FileSize = FFS_FILE_SIZE (FfsFileHeader);
FileSize -= sizeof (EFI_FFS_FILE_HEADER);
Status = FindFfsSectionInSections (
@@ -335,44 +335,45 @@ FfsFindSection ( EFI_STATUS
EFIAPI
FfsFindSectionData (
- IN EFI_SECTION_TYPE SectionType,
- IN EFI_FFS_FILE_HEADER *FfsFileHeader,
- IN OUT VOID **SectionData,
- IN OUT UINTN *SectionDataSize
+ IN EFI_SECTION_TYPE SectionType,
+ IN EFI_FFS_FILE_HEADER *FfsFileHeader,
+ IN OUT VOID **SectionData,
+ IN OUT UINTN *SectionDataSize
)
{
- UINT32 FileSize;
- EFI_COMMON_SECTION_HEADER *Section;
- UINT32 SectionLength;
- UINT32 ParsedLength;
+ UINT32 FileSize;
+ EFI_COMMON_SECTION_HEADER *Section;
+ UINT32 SectionLength;
+ UINT32 ParsedLength;
//
// Size is 24 bits wide so mask upper 8 bits.
// Does not include FfsFileHeader header size
// FileSize is adjusted to FileOccupiedSize as it is 8 byte aligned.
//
- Section = (EFI_COMMON_SECTION_HEADER *) (FfsFileHeader + 1);
- FileSize = FFS_FILE_SIZE(FfsFileHeader);
+ Section = (EFI_COMMON_SECTION_HEADER *)(FfsFileHeader + 1);
+ FileSize = FFS_FILE_SIZE (FfsFileHeader);
FileSize -= sizeof (EFI_FFS_FILE_HEADER);
- *SectionData = NULL;
- ParsedLength = 0;
+ *SectionData = NULL;
+ ParsedLength = 0;
while (ParsedLength < FileSize) {
if (Section->Type == SectionType) {
- *SectionData = (VOID *) (Section + 1);
- *SectionDataSize = SECTION_SIZE(Section);
+ *SectionData = (VOID *)(Section + 1);
+ *SectionDataSize = SECTION_SIZE (Section);
return EFI_SUCCESS;
}
+
//
// Size is 24 bits wide so mask upper 8 bits.
// SectionLength is adjusted it is 4 byte aligned.
// Go to the next section
//
- SectionLength = SECTION_SIZE(Section);
+ SectionLength = SECTION_SIZE (Section);
SectionLength = GET_OCCUPIED_SIZE (SectionLength, 4);
ParsedLength += SectionLength;
- Section = (EFI_COMMON_SECTION_HEADER *) ((UINT8 *) Section + SectionLength);
+ Section = (EFI_COMMON_SECTION_HEADER *)((UINT8 *)Section + SectionLength);
}
return EFI_NOT_FOUND;
diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateHobList.c b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateHobList.c index 85f8194..eb0c1f8 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 <PiMm.h>
#include <PiPei.h>
@@ -25,7 +24,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include <IndustryStandard/ArmStdSmc.h>
-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 cd4b908..8f2833a 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 <PiMm.h>
#include <PiPei.h>
@@ -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 49cf51a..9163025 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 <PiMm.h>
#include <Library/Arm/StandaloneMmCoreEntryPoint.h>
@@ -29,20 +28,20 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include <IndustryStandard/ArmMmSvc.h>
#include <IndustryStandard/ArmFfaSvc.h>
-#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 dffa965..98e6c0d 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 <PiMm.h>
#include <Library/StandaloneMmCoreEntryPoint.h>
@@ -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().
diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/Arm/StandaloneMmCoreHobLib.c b/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/Arm/StandaloneMmCoreHobLib.c index 0ec2d4a..1550e1b 100644 --- a/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/Arm/StandaloneMmCoreHobLib.c +++ b/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/Arm/StandaloneMmCoreHobLib.c @@ -19,12 +19,12 @@ SPDX-License-Identifier: BSD-2-Clause-Patent //
// Cache copy of HobList pointer.
//
-VOID *gHobList = NULL;
+VOID *gHobList = NULL;
VOID *
CreateHob (
- IN UINT16 HobType,
- IN UINT16 HobLength
+ IN UINT16 HobType,
+ IN UINT16 HobLength
)
{
EFI_HOB_HANDOFF_INFO_TABLE *HandOffHob;
@@ -42,19 +42,19 @@ CreateHob ( return NULL;
}
- Hob = (VOID*) (UINTN) HandOffHob->EfiEndOfHobList;
- ((EFI_HOB_GENERIC_HEADER*) Hob)->HobType = HobType;
- ((EFI_HOB_GENERIC_HEADER*) Hob)->HobLength = HobLength;
- ((EFI_HOB_GENERIC_HEADER*) Hob)->Reserved = 0;
+ Hob = (VOID *)(UINTN)HandOffHob->EfiEndOfHobList;
+ ((EFI_HOB_GENERIC_HEADER *)Hob)->HobType = HobType;
+ ((EFI_HOB_GENERIC_HEADER *)Hob)->HobLength = HobLength;
+ ((EFI_HOB_GENERIC_HEADER *)Hob)->Reserved = 0;
- HobEnd = (EFI_HOB_GENERIC_HEADER*) ((UINTN)Hob + HobLength);
- HandOffHob->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd;
+ HobEnd = (EFI_HOB_GENERIC_HEADER *)((UINTN)Hob + HobLength);
+ HandOffHob->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS)(UINTN)HobEnd;
HobEnd->HobType = EFI_HOB_TYPE_END_OF_HOB_LIST;
HobEnd->HobLength = sizeof (EFI_HOB_GENERIC_HEADER);
HobEnd->Reserved = 0;
HobEnd++;
- HandOffHob->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd;
+ HandOffHob->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS)(UINTN)HobEnd;
return Hob;
}
@@ -75,16 +75,18 @@ CreateHob ( VOID
EFIAPI
BuildModuleHob (
- IN CONST EFI_GUID *ModuleName,
- IN EFI_PHYSICAL_ADDRESS MemoryAllocationModule,
- IN UINT64 ModuleLength,
- IN EFI_PHYSICAL_ADDRESS EntryPoint
+ IN CONST EFI_GUID *ModuleName,
+ IN EFI_PHYSICAL_ADDRESS MemoryAllocationModule,
+ IN UINT64 ModuleLength,
+ IN EFI_PHYSICAL_ADDRESS EntryPoint
)
{
EFI_HOB_MEMORY_ALLOCATION_MODULE *Hob;
- ASSERT (((MemoryAllocationModule & (EFI_PAGE_SIZE - 1)) == 0) &&
- ((ModuleLength & (EFI_PAGE_SIZE - 1)) == 0));
+ ASSERT (
+ ((MemoryAllocationModule & (EFI_PAGE_SIZE - 1)) == 0) &&
+ ((ModuleLength & (EFI_PAGE_SIZE - 1)) == 0)
+ );
Hob = CreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, sizeof (EFI_HOB_MEMORY_ALLOCATION_MODULE));
@@ -153,23 +155,22 @@ BuildResourceDescriptorHob ( VOID *
EFIAPI
BuildGuidHob (
- IN CONST EFI_GUID *Guid,
- IN UINTN DataLength
+ IN CONST EFI_GUID *Guid,
+ IN UINTN DataLength
)
{
- EFI_HOB_GUID_TYPE *Hob;
+ EFI_HOB_GUID_TYPE *Hob;
//
// Make sure that data length is not too long.
//
ASSERT (DataLength <= (0xffff - sizeof (EFI_HOB_GUID_TYPE)));
- Hob = CreateHob (EFI_HOB_TYPE_GUID_EXTENSION, (UINT16) (sizeof (EFI_HOB_GUID_TYPE) + DataLength));
+ Hob = CreateHob (EFI_HOB_TYPE_GUID_EXTENSION, (UINT16)(sizeof (EFI_HOB_GUID_TYPE) + DataLength));
CopyGuid (&Hob->Name, Guid);
return Hob + 1;
}
-
/**
Copies a data buffer to a newly-built HOB.
@@ -191,9 +192,9 @@ BuildGuidHob ( VOID *
EFIAPI
BuildGuidDataHob (
- IN CONST EFI_GUID *Guid,
- IN VOID *Data,
- IN UINTN DataLength
+ IN CONST EFI_GUID *Guid,
+ IN VOID *Data,
+ IN UINTN DataLength
)
{
VOID *HobData;
@@ -218,8 +219,8 @@ BuildGuidDataHob ( VOID
EFIAPI
BuildFvHob (
- IN EFI_PHYSICAL_ADDRESS BaseAddress,
- IN UINT64 Length
+ IN EFI_PHYSICAL_ADDRESS BaseAddress,
+ IN UINT64 Length
)
{
EFI_HOB_FIRMWARE_VOLUME *Hob;
@@ -230,7 +231,6 @@ BuildFvHob ( Hob->Length = Length;
}
-
/**
Builds a EFI_HOB_TYPE_FV2 HOB.
@@ -246,10 +246,10 @@ BuildFvHob ( VOID
EFIAPI
BuildFv2Hob (
- IN EFI_PHYSICAL_ADDRESS BaseAddress,
- IN UINT64 Length,
- IN CONST EFI_GUID *FvName,
- IN CONST EFI_GUID *FileName
+ IN EFI_PHYSICAL_ADDRESS BaseAddress,
+ IN UINT64 Length,
+ IN CONST EFI_GUID *FvName,
+ IN CONST EFI_GUID *FileName
)
{
EFI_HOB_FIRMWARE_VOLUME2 *Hob;
@@ -262,7 +262,6 @@ BuildFv2Hob ( CopyGuid (&Hob->FileName, FileName);
}
-
/**
Builds a HOB for the CPU.
@@ -276,8 +275,8 @@ BuildFv2Hob ( VOID
EFIAPI
BuildCpuHob (
- IN UINT8 SizeOfMemorySpace,
- IN UINT8 SizeOfIoSpace
+ IN UINT8 SizeOfMemorySpace,
+ IN UINT8 SizeOfIoSpace
)
{
EFI_HOB_CPU *Hob;
@@ -307,15 +306,17 @@ BuildCpuHob ( VOID
EFIAPI
BuildMemoryAllocationHob (
- IN EFI_PHYSICAL_ADDRESS BaseAddress,
- IN UINT64 Length,
- IN EFI_MEMORY_TYPE MemoryType
+ IN EFI_PHYSICAL_ADDRESS BaseAddress,
+ IN UINT64 Length,
+ IN EFI_MEMORY_TYPE MemoryType
)
{
EFI_HOB_MEMORY_ALLOCATION *Hob;
- ASSERT (((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) &&
- ((Length & (EFI_PAGE_SIZE - 1)) == 0));
+ ASSERT (
+ ((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) &&
+ ((Length & (EFI_PAGE_SIZE - 1)) == 0)
+ );
Hob = CreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, sizeof (EFI_HOB_MEMORY_ALLOCATION));
diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/Arm/StandaloneMmCoreHobLibInternal.c b/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/Arm/StandaloneMmCoreHobLibInternal.c index 3f1e0cb..1b7141a 100644 --- a/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/Arm/StandaloneMmCoreHobLibInternal.c +++ b/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/Arm/StandaloneMmCoreHobLibInternal.c @@ -19,9 +19,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent //
// Cache copy of HobList pointer.
//
-extern VOID *gHobList;
+extern VOID *gHobList;
-EFI_HOB_HANDOFF_INFO_TABLE*
+EFI_HOB_HANDOFF_INFO_TABLE *
HobConstructor (
IN VOID *EfiMemoryBegin,
IN UINTN EfiMemoryLength,
@@ -35,16 +35,16 @@ HobConstructor ( Hob = EfiFreeMemoryBottom;
HobEnd = (EFI_HOB_GENERIC_HEADER *)(Hob+1);
- Hob->Header.HobType = EFI_HOB_TYPE_HANDOFF;
- Hob->Header.HobLength = sizeof (EFI_HOB_HANDOFF_INFO_TABLE);
- Hob->Header.Reserved = 0;
+ Hob->Header.HobType = EFI_HOB_TYPE_HANDOFF;
+ Hob->Header.HobLength = sizeof (EFI_HOB_HANDOFF_INFO_TABLE);
+ Hob->Header.Reserved = 0;
- HobEnd->HobType = EFI_HOB_TYPE_END_OF_HOB_LIST;
- HobEnd->HobLength = sizeof (EFI_HOB_GENERIC_HEADER);
- HobEnd->Reserved = 0;
+ HobEnd->HobType = EFI_HOB_TYPE_END_OF_HOB_LIST;
+ HobEnd->HobLength = sizeof (EFI_HOB_GENERIC_HEADER);
+ HobEnd->Reserved = 0;
- Hob->Version = EFI_HOB_HANDOFF_TABLE_VERSION;
- Hob->BootMode = BOOT_WITH_FULL_CONFIGURATION;
+ Hob->Version = EFI_HOB_HANDOFF_TABLE_VERSION;
+ Hob->BootMode = BOOT_WITH_FULL_CONFIGURATION;
Hob->EfiMemoryTop = (UINTN)EfiMemoryBegin + EfiMemoryLength;
Hob->EfiMemoryBottom = (UINTN)EfiMemoryBegin;
diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/Common.c b/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/Common.c index 8c53503..df5416b 100644 --- a/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/Common.c +++ b/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/Common.c @@ -56,15 +56,15 @@ GetHobList ( VOID *
EFIAPI
GetNextHob (
- IN UINT16 Type,
- IN CONST VOID *HobStart
+ IN UINT16 Type,
+ IN CONST VOID *HobStart
)
{
EFI_PEI_HOB_POINTERS Hob;
ASSERT (HobStart != NULL);
- Hob.Raw = (UINT8 *) HobStart;
+ Hob.Raw = (UINT8 *)HobStart;
//
// Parse the HOB list until end of list or matching type is found.
//
@@ -72,8 +72,10 @@ GetNextHob ( if (Hob.Header->HobType == Type) {
return Hob.Raw;
}
+
Hob.Raw = GET_NEXT_HOB (Hob);
}
+
return NULL;
}
@@ -93,10 +95,10 @@ GetNextHob ( VOID *
EFIAPI
GetFirstHob (
- IN UINT16 Type
+ IN UINT16 Type
)
{
- VOID *HobList;
+ VOID *HobList;
HobList = GetHobList ();
return GetNextHob (Type, HobList);
@@ -127,19 +129,21 @@ GetFirstHob ( VOID *
EFIAPI
GetNextGuidHob (
- IN CONST EFI_GUID *Guid,
- IN CONST VOID *HobStart
+ IN CONST EFI_GUID *Guid,
+ IN CONST VOID *HobStart
)
{
EFI_PEI_HOB_POINTERS GuidHob;
- GuidHob.Raw = (UINT8 *) HobStart;
+ GuidHob.Raw = (UINT8 *)HobStart;
while ((GuidHob.Raw = GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION, GuidHob.Raw)) != NULL) {
if (CompareGuid (Guid, &GuidHob.Guid->Name)) {
break;
}
+
GuidHob.Raw = GET_NEXT_HOB (GuidHob);
}
+
return GuidHob.Raw;
}
@@ -164,10 +168,10 @@ GetNextGuidHob ( VOID *
EFIAPI
GetFirstGuidHob (
- IN CONST EFI_GUID *Guid
+ IN CONST EFI_GUID *Guid
)
{
- VOID *HobList;
+ VOID *HobList;
HobList = GetHobList ();
return GetNextGuidHob (Guid, HobList);
@@ -192,14 +196,13 @@ GetBootModeHob ( VOID
)
{
- EFI_HOB_HANDOFF_INFO_TABLE *HandOffHob;
+ EFI_HOB_HANDOFF_INFO_TABLE *HandOffHob;
- HandOffHob = (EFI_HOB_HANDOFF_INFO_TABLE *) GetHobList ();
+ HandOffHob = (EFI_HOB_HANDOFF_INFO_TABLE *)GetHobList ();
return HandOffHob->BootMode;
}
-
/**
Builds a HOB that describes a chunk of system memory with Owner GUID.
@@ -240,14 +243,13 @@ BuildResourceDescriptorWithOwnerHob ( VOID
EFIAPI
BuildCvHob (
- IN EFI_PHYSICAL_ADDRESS BaseAddress,
- IN UINT64 Length
+ IN EFI_PHYSICAL_ADDRESS BaseAddress,
+ IN UINT64 Length
)
{
ASSERT (FALSE);
}
-
/**
Builds a HOB for the BSP store.
@@ -262,9 +264,9 @@ BuildCvHob ( VOID
EFIAPI
BuildBspStoreHob (
- IN EFI_PHYSICAL_ADDRESS BaseAddress,
- IN UINT64 Length,
- IN EFI_MEMORY_TYPE MemoryType
+ IN EFI_PHYSICAL_ADDRESS BaseAddress,
+ IN UINT64 Length,
+ IN EFI_MEMORY_TYPE MemoryType
)
{
ASSERT (FALSE);
@@ -283,8 +285,8 @@ BuildBspStoreHob ( VOID
EFIAPI
BuildStackHob (
- IN EFI_PHYSICAL_ADDRESS BaseAddress,
- IN UINT64 Length
+ IN EFI_PHYSICAL_ADDRESS BaseAddress,
+ IN UINT64 Length
)
{
ASSERT (FALSE);
diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/X64/StandaloneMmCoreHobLib.c b/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/X64/StandaloneMmCoreHobLib.c index 333ed40..3c5baa1 100644 --- a/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/X64/StandaloneMmCoreHobLib.c +++ b/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/X64/StandaloneMmCoreHobLib.c @@ -35,10 +35,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent VOID
EFIAPI
BuildModuleHob (
- IN CONST EFI_GUID *ModuleName,
- IN EFI_PHYSICAL_ADDRESS MemoryAllocationModule,
- IN UINT64 ModuleLength,
- IN EFI_PHYSICAL_ADDRESS EntryPoint
+ IN CONST EFI_GUID *ModuleName,
+ IN EFI_PHYSICAL_ADDRESS MemoryAllocationModule,
+ IN UINT64 ModuleLength,
+ IN EFI_PHYSICAL_ADDRESS EntryPoint
)
{
//
@@ -102,8 +102,8 @@ BuildResourceDescriptorHob ( VOID *
EFIAPI
BuildGuidHob (
- IN CONST EFI_GUID *Guid,
- IN UINTN DataLength
+ IN CONST EFI_GUID *Guid,
+ IN UINTN DataLength
)
{
//
@@ -141,9 +141,9 @@ BuildGuidHob ( VOID *
EFIAPI
BuildGuidDataHob (
- IN CONST EFI_GUID *Guid,
- IN VOID *Data,
- IN UINTN DataLength
+ IN CONST EFI_GUID *Guid,
+ IN VOID *Data,
+ IN UINTN DataLength
)
{
//
@@ -170,8 +170,8 @@ BuildGuidDataHob ( VOID
EFIAPI
BuildFvHob (
- IN EFI_PHYSICAL_ADDRESS BaseAddress,
- IN UINT64 Length
+ IN EFI_PHYSICAL_ADDRESS BaseAddress,
+ IN UINT64 Length
)
{
//
@@ -199,10 +199,10 @@ BuildFvHob ( VOID
EFIAPI
BuildFv2Hob (
- IN EFI_PHYSICAL_ADDRESS BaseAddress,
- IN UINT64 Length,
- IN CONST EFI_GUID *FvName,
- IN CONST EFI_GUID *FileName
+ IN EFI_PHYSICAL_ADDRESS BaseAddress,
+ IN UINT64 Length,
+ IN CONST EFI_GUID *FvName,
+ IN CONST EFI_GUID *FileName
)
{
ASSERT (FALSE);
@@ -232,12 +232,12 @@ BuildFv2Hob ( VOID
EFIAPI
BuildFv3Hob (
- IN EFI_PHYSICAL_ADDRESS BaseAddress,
- IN UINT64 Length,
- IN UINT32 AuthenticationStatus,
- IN BOOLEAN ExtractedFv,
- IN CONST EFI_GUID *FvName OPTIONAL,
- IN CONST EFI_GUID *FileName OPTIONAL
+ IN EFI_PHYSICAL_ADDRESS BaseAddress,
+ IN UINT64 Length,
+ IN UINT32 AuthenticationStatus,
+ IN BOOLEAN ExtractedFv,
+ IN CONST EFI_GUID *FvName OPTIONAL,
+ IN CONST EFI_GUID *FileName OPTIONAL
)
{
ASSERT (FALSE);
@@ -259,8 +259,8 @@ BuildFv3Hob ( VOID
EFIAPI
BuildCpuHob (
- IN UINT8 SizeOfMemorySpace,
- IN UINT8 SizeOfIoSpace
+ IN UINT8 SizeOfMemorySpace,
+ IN UINT8 SizeOfIoSpace
)
{
//
@@ -286,9 +286,9 @@ BuildCpuHob ( VOID
EFIAPI
BuildMemoryAllocationHob (
- IN EFI_PHYSICAL_ADDRESS BaseAddress,
- IN UINT64 Length,
- IN EFI_MEMORY_TYPE MemoryType
+ IN EFI_PHYSICAL_ADDRESS BaseAddress,
+ IN UINT64 Length,
+ IN EFI_MEMORY_TYPE MemoryType
)
{
//
diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreMemoryAllocationLib/StandaloneMmCoreMemoryAllocationLib.c b/StandaloneMmPkg/Library/StandaloneMmCoreMemoryAllocationLib/StandaloneMmCoreMemoryAllocationLib.c index ba5470d..2246823 100644 --- a/StandaloneMmPkg/Library/StandaloneMmCoreMemoryAllocationLib/StandaloneMmCoreMemoryAllocationLib.c +++ b/StandaloneMmPkg/Library/StandaloneMmCoreMemoryAllocationLib/StandaloneMmCoreMemoryAllocationLib.c @@ -17,7 +17,7 @@ #include <Library/HobLib.h>
#include "StandaloneMmCoreMemoryAllocationServices.h"
-EFI_MM_SYSTEM_TABLE *gMmst = NULL;
+EFI_MM_SYSTEM_TABLE *gMmst = NULL;
/**
Allocates one or more 4KB pages of a certain memory type.
@@ -49,7 +49,8 @@ InternalAllocatePages ( if (EFI_ERROR (Status)) {
return NULL;
}
- return (VOID *) (UINTN) Memory;
+
+ return (VOID *)(UINTN)Memory;
}
/**
@@ -145,7 +146,7 @@ FreePages ( EFI_STATUS Status;
ASSERT (Pages != 0);
- Status = gMmst->MmFreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) Buffer, Pages);
+ Status = gMmst->MmFreePages ((EFI_PHYSICAL_ADDRESS)(UINTN)Buffer, Pages);
ASSERT_EFI_ERROR (Status);
}
@@ -189,12 +190,13 @@ InternalAllocateAlignedPages ( if (Pages == 0) {
return NULL;
}
+
if (Alignment > EFI_PAGE_SIZE) {
//
// Calculate the total number of pages since alignment is larger than page size.
//
- AlignmentMask = Alignment - 1;
- RealPages = Pages + EFI_SIZE_TO_PAGES (Alignment);
+ AlignmentMask = Alignment - 1;
+ RealPages = Pages + EFI_SIZE_TO_PAGES (Alignment);
//
// Make sure that Pages plus EFI_SIZE_TO_PAGES (Alignment) does not overflow.
//
@@ -204,8 +206,9 @@ InternalAllocateAlignedPages ( if (EFI_ERROR (Status)) {
return NULL;
}
- AlignedMemory = ((UINTN) Memory + AlignmentMask) & ~AlignmentMask;
- UnalignedPages = EFI_SIZE_TO_PAGES (AlignedMemory - (UINTN) Memory);
+
+ AlignedMemory = ((UINTN)Memory + AlignmentMask) & ~AlignmentMask;
+ UnalignedPages = EFI_SIZE_TO_PAGES (AlignedMemory - (UINTN)Memory);
if (UnalignedPages > 0) {
//
// Free first unaligned page(s).
@@ -213,7 +216,8 @@ InternalAllocateAlignedPages ( Status = gMmst->MmFreePages (Memory, UnalignedPages);
ASSERT_EFI_ERROR (Status);
}
- Memory = (EFI_PHYSICAL_ADDRESS) (AlignedMemory + EFI_PAGES_TO_SIZE (Pages));
+
+ Memory = (EFI_PHYSICAL_ADDRESS)(AlignedMemory + EFI_PAGES_TO_SIZE (Pages));
UnalignedPages = RealPages - Pages - UnalignedPages;
if (UnalignedPages > 0) {
//
@@ -230,9 +234,11 @@ InternalAllocateAlignedPages ( if (EFI_ERROR (Status)) {
return NULL;
}
- AlignedMemory = (UINTN) Memory;
+
+ AlignedMemory = (UINTN)Memory;
}
- return (VOID *) AlignedMemory;
+
+ return (VOID *)AlignedMemory;
}
/**
@@ -346,7 +352,7 @@ FreeAlignedPages ( EFI_STATUS Status;
ASSERT (Pages != 0);
- Status = gMmst->MmFreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) Buffer, Pages);
+ Status = gMmst->MmFreePages ((EFI_PHYSICAL_ADDRESS)(UINTN)Buffer, Pages);
ASSERT_EFI_ERROR (Status);
}
@@ -378,6 +384,7 @@ InternalAllocatePool ( if (EFI_ERROR (Status)) {
Memory = NULL;
}
+
return Memory;
}
@@ -470,6 +477,7 @@ InternalAllocateZeroPool ( if (Memory != NULL) {
Memory = ZeroMem (Memory, AllocationSize);
}
+
return Memory;
}
@@ -566,12 +574,13 @@ InternalAllocateCopyPool ( VOID *Memory;
ASSERT (Buffer != NULL);
- ASSERT (AllocationSize <= (MAX_ADDRESS - (UINTN) Buffer + 1));
+ ASSERT (AllocationSize <= (MAX_ADDRESS - (UINTN)Buffer + 1));
Memory = InternalAllocatePool (PoolType, AllocationSize);
if (Memory != NULL) {
Memory = CopyMem (Memory, Buffer, AllocationSize);
}
+
return Memory;
}
@@ -689,10 +698,11 @@ InternalReallocatePool ( VOID *NewBuffer;
NewBuffer = InternalAllocateZeroPool (PoolType, NewSize);
- if (NewBuffer != NULL && OldBuffer != NULL) {
+ if ((NewBuffer != NULL) && (OldBuffer != NULL)) {
CopyMem (NewBuffer, OldBuffer, MIN (OldSize, NewSize));
FreePool (OldBuffer);
}
+
return NewBuffer;
}
@@ -809,10 +819,10 @@ ReallocateReservedPool ( VOID
EFIAPI
FreePool (
- IN VOID *Buffer
+ IN VOID *Buffer
)
{
- EFI_STATUS Status;
+ EFI_STATUS Status;
Status = gMmst->MmFreePool (Buffer);
ASSERT_EFI_ERROR (Status);
@@ -831,17 +841,17 @@ FreePool ( EFI_STATUS
EFIAPI
MemoryAllocationLibConstructor (
- IN EFI_HANDLE ImageHandle,
- IN EFI_MM_SYSTEM_TABLE *MmSystemTable
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_MM_SYSTEM_TABLE *MmSystemTable
)
{
- MM_CORE_PRIVATE_DATA *MmCorePrivate;
+ MM_CORE_PRIVATE_DATA *MmCorePrivate;
EFI_HOB_GUID_TYPE *GuidHob;
- MM_CORE_DATA_HOB_DATA *DataInHob;
+ MM_CORE_DATA_HOB_DATA *DataInHob;
VOID *HobStart;
EFI_MMRAM_HOB_DESCRIPTOR_BLOCK *MmramRangesHobData;
EFI_MMRAM_DESCRIPTOR *MmramRanges;
- UINTN MmramRangeCount;
+ UINTN MmramRangeCount;
EFI_HOB_GUID_TYPE *MmramRangesHob;
HobStart = GetHobList ();
@@ -868,25 +878,29 @@ MemoryAllocationLibConstructor ( return EFI_UNSUPPORTED;
}
- MmramRangeCount = (UINTN) MmramRangesHobData->NumberOfMmReservedRegions;
+ MmramRangeCount = (UINTN)MmramRangesHobData->NumberOfMmReservedRegions;
if (MmramRanges == NULL) {
return EFI_UNSUPPORTED;
}
-
} else {
- DataInHob = GET_GUID_HOB_DATA (GuidHob);
- MmCorePrivate = (MM_CORE_PRIVATE_DATA *)(UINTN)DataInHob->Address;
+ DataInHob = GET_GUID_HOB_DATA (GuidHob);
+ MmCorePrivate = (MM_CORE_PRIVATE_DATA *)(UINTN)DataInHob->Address;
MmramRanges = (EFI_MMRAM_DESCRIPTOR *)(UINTN)MmCorePrivate->MmramRanges;
- MmramRangeCount = (UINTN) MmCorePrivate->MmramRangeCount;
+ MmramRangeCount = (UINTN)MmCorePrivate->MmramRangeCount;
}
{
- UINTN Index;
+ UINTN Index;
DEBUG ((DEBUG_INFO, "MmramRangeCount - 0x%x\n", MmramRangeCount));
for (Index = 0; Index < MmramRangeCount; Index++) {
- DEBUG ((DEBUG_INFO, "MmramRanges[%d]: 0x%016lx - 0x%016lx\n",
- Index, MmramRanges[Index].CpuStart, MmramRanges[Index].PhysicalSize));
+ DEBUG ((
+ DEBUG_INFO,
+ "MmramRanges[%d]: 0x%016lx - 0x%016lx\n",
+ Index,
+ MmramRanges[Index].CpuStart,
+ MmramRanges[Index].PhysicalSize
+ ));
}
}
diff --git a/StandaloneMmPkg/Library/StandaloneMmHobLib/StandaloneMmHobLib.c b/StandaloneMmPkg/Library/StandaloneMmHobLib/StandaloneMmHobLib.c index ca7e2f8..ee61bdd 100644 --- a/StandaloneMmPkg/Library/StandaloneMmHobLib/StandaloneMmHobLib.c +++ b/StandaloneMmPkg/Library/StandaloneMmHobLib/StandaloneMmHobLib.c @@ -19,7 +19,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent //
// Cache copy of HobList pointer.
//
-STATIC VOID *gHobList = NULL;
+STATIC VOID *gHobList = NULL;
/**
The constructor function caches the pointer to HOB list.
@@ -37,11 +37,11 @@ STATIC VOID *gHobList = NULL; EFI_STATUS
EFIAPI
HobLibConstructor (
- IN EFI_HANDLE ImageHandle,
- IN EFI_MM_SYSTEM_TABLE *MmSystemTable
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_MM_SYSTEM_TABLE *MmSystemTable
)
{
- UINTN Index;
+ UINTN Index;
for (Index = 0; Index < gMmst->NumberOfTableEntries; Index++) {
if (CompareGuid (&gEfiHobListGuid, &gMmst->MmConfigurationTable[Index].VendorGuid)) {
@@ -49,6 +49,7 @@ HobLibConstructor ( break;
}
}
+
return EFI_SUCCESS;
}
@@ -67,7 +68,7 @@ GetHobList ( VOID
)
{
- UINTN Index;
+ UINTN Index;
if (gHobList == NULL) {
for (Index = 0; Index < gMmst->NumberOfTableEntries; Index++) {
@@ -77,6 +78,7 @@ GetHobList ( }
}
}
+
ASSERT (gHobList != NULL);
return gHobList;
}
@@ -101,15 +103,15 @@ GetHobList ( VOID *
EFIAPI
GetNextHob (
- IN UINT16 Type,
- IN CONST VOID *HobStart
+ IN UINT16 Type,
+ IN CONST VOID *HobStart
)
{
EFI_PEI_HOB_POINTERS Hob;
ASSERT (HobStart != NULL);
- Hob.Raw = (UINT8 *) HobStart;
+ Hob.Raw = (UINT8 *)HobStart;
//
// Parse the HOB list until end of list or matching type is found.
//
@@ -117,8 +119,10 @@ GetNextHob ( if (Hob.Header->HobType == Type) {
return Hob.Raw;
}
+
Hob.Raw = GET_NEXT_HOB (Hob);
}
+
return NULL;
}
@@ -138,10 +142,10 @@ GetNextHob ( VOID *
EFIAPI
GetFirstHob (
- IN UINT16 Type
+ IN UINT16 Type
)
{
- VOID *HobList;
+ VOID *HobList;
HobList = GetHobList ();
return GetNextHob (Type, HobList);
@@ -172,19 +176,21 @@ GetFirstHob ( VOID *
EFIAPI
GetNextGuidHob (
- IN CONST EFI_GUID *Guid,
- IN CONST VOID *HobStart
+ IN CONST EFI_GUID *Guid,
+ IN CONST VOID *HobStart
)
{
EFI_PEI_HOB_POINTERS GuidHob;
- GuidHob.Raw = (UINT8 *) HobStart;
+ GuidHob.Raw = (UINT8 *)HobStart;
while ((GuidHob.Raw = GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION, GuidHob.Raw)) != NULL) {
if (CompareGuid (Guid, &GuidHob.Guid->Name)) {
break;
}
+
GuidHob.Raw = GET_NEXT_HOB (GuidHob);
}
+
return GuidHob.Raw;
}
@@ -209,10 +215,10 @@ GetNextGuidHob ( VOID *
EFIAPI
GetFirstGuidHob (
- IN CONST EFI_GUID *Guid
+ IN CONST EFI_GUID *Guid
)
{
- VOID *HobList;
+ VOID *HobList;
HobList = GetHobList ();
return GetNextGuidHob (Guid, HobList);
@@ -237,17 +243,17 @@ GetBootModeHob ( VOID
)
{
- EFI_HOB_HANDOFF_INFO_TABLE *HandOffHob;
+ EFI_HOB_HANDOFF_INFO_TABLE *HandOffHob;
- HandOffHob = (EFI_HOB_HANDOFF_INFO_TABLE *) GetHobList ();
+ HandOffHob = (EFI_HOB_HANDOFF_INFO_TABLE *)GetHobList ();
- return HandOffHob->BootMode;
+ return HandOffHob->BootMode;
}
VOID *
CreateHob (
- IN UINT16 HobType,
- IN UINT16 HobLength
+ IN UINT16 HobType,
+ IN UINT16 HobLength
)
{
EFI_HOB_HANDOFF_INFO_TABLE *HandOffHob;
@@ -262,22 +268,22 @@ CreateHob ( FreeMemory = HandOffHob->EfiFreeMemoryTop - HandOffHob->EfiFreeMemoryBottom;
if (FreeMemory < HobLength) {
- return NULL;
+ return NULL;
}
- Hob = (VOID*) (UINTN) HandOffHob->EfiEndOfHobList;
- ((EFI_HOB_GENERIC_HEADER*) Hob)->HobType = HobType;
- ((EFI_HOB_GENERIC_HEADER*) Hob)->HobLength = HobLength;
- ((EFI_HOB_GENERIC_HEADER*) Hob)->Reserved = 0;
+ Hob = (VOID *)(UINTN)HandOffHob->EfiEndOfHobList;
+ ((EFI_HOB_GENERIC_HEADER *)Hob)->HobType = HobType;
+ ((EFI_HOB_GENERIC_HEADER *)Hob)->HobLength = HobLength;
+ ((EFI_HOB_GENERIC_HEADER *)Hob)->Reserved = 0;
- HobEnd = (EFI_HOB_GENERIC_HEADER*) ((UINTN)Hob + HobLength);
- HandOffHob->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd;
+ HobEnd = (EFI_HOB_GENERIC_HEADER *)((UINTN)Hob + HobLength);
+ HandOffHob->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS)(UINTN)HobEnd;
HobEnd->HobType = EFI_HOB_TYPE_END_OF_HOB_LIST;
- HobEnd->HobLength = sizeof(EFI_HOB_GENERIC_HEADER);
+ HobEnd->HobLength = sizeof (EFI_HOB_GENERIC_HEADER);
HobEnd->Reserved = 0;
HobEnd++;
- HandOffHob->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd;
+ HandOffHob->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS)(UINTN)HobEnd;
return Hob;
}
@@ -298,16 +304,18 @@ CreateHob ( VOID
EFIAPI
BuildModuleHob (
- IN CONST EFI_GUID *ModuleName,
- IN EFI_PHYSICAL_ADDRESS MemoryAllocationModule,
- IN UINT64 ModuleLength,
- IN EFI_PHYSICAL_ADDRESS EntryPoint
+ IN CONST EFI_GUID *ModuleName,
+ IN EFI_PHYSICAL_ADDRESS MemoryAllocationModule,
+ IN UINT64 ModuleLength,
+ IN EFI_PHYSICAL_ADDRESS EntryPoint
)
{
EFI_HOB_MEMORY_ALLOCATION_MODULE *Hob;
- ASSERT (((MemoryAllocationModule & (EFI_PAGE_SIZE - 1)) == 0) &&
- ((ModuleLength & (EFI_PAGE_SIZE - 1)) == 0));
+ ASSERT (
+ ((MemoryAllocationModule & (EFI_PAGE_SIZE - 1)) == 0) &&
+ ((ModuleLength & (EFI_PAGE_SIZE - 1)) == 0)
+ );
Hob = CreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, sizeof (EFI_HOB_MEMORY_ALLOCATION_MODULE));
@@ -349,7 +357,7 @@ BuildResourceDescriptorHob ( EFI_HOB_RESOURCE_DESCRIPTOR *Hob;
Hob = CreateHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, sizeof (EFI_HOB_RESOURCE_DESCRIPTOR));
- ASSERT(Hob != NULL);
+ ASSERT (Hob != NULL);
Hob->ResourceType = ResourceType;
Hob->ResourceAttribute = ResourceAttribute;
@@ -376,23 +384,22 @@ BuildResourceDescriptorHob ( VOID *
EFIAPI
BuildGuidHob (
- IN CONST EFI_GUID *Guid,
- IN UINTN DataLength
+ IN CONST EFI_GUID *Guid,
+ IN UINTN DataLength
)
{
- EFI_HOB_GUID_TYPE *Hob;
+ EFI_HOB_GUID_TYPE *Hob;
//
// Make sure that data length is not too long.
//
ASSERT (DataLength <= (0xffff - sizeof (EFI_HOB_GUID_TYPE)));
- Hob = CreateHob (EFI_HOB_TYPE_GUID_EXTENSION, (UINT16) (sizeof (EFI_HOB_GUID_TYPE) + DataLength));
+ Hob = CreateHob (EFI_HOB_TYPE_GUID_EXTENSION, (UINT16)(sizeof (EFI_HOB_GUID_TYPE) + DataLength));
CopyGuid (&Hob->Name, Guid);
return Hob + 1;
}
-
/**
Copies a data buffer to a newly-built HOB.
@@ -414,9 +421,9 @@ BuildGuidHob ( VOID *
EFIAPI
BuildGuidDataHob (
- IN CONST EFI_GUID *Guid,
- IN VOID *Data,
- IN UINTN DataLength
+ IN CONST EFI_GUID *Guid,
+ IN VOID *Data,
+ IN UINTN DataLength
)
{
VOID *HobData;
@@ -441,8 +448,8 @@ BuildGuidDataHob ( VOID
EFIAPI
BuildFvHob (
- IN EFI_PHYSICAL_ADDRESS BaseAddress,
- IN UINT64 Length
+ IN EFI_PHYSICAL_ADDRESS BaseAddress,
+ IN UINT64 Length
)
{
EFI_HOB_FIRMWARE_VOLUME *Hob;
@@ -453,7 +460,6 @@ BuildFvHob ( Hob->Length = Length;
}
-
/**
Builds a EFI_HOB_TYPE_FV2 HOB.
@@ -469,10 +475,10 @@ BuildFvHob ( VOID
EFIAPI
BuildFv2Hob (
- IN EFI_PHYSICAL_ADDRESS BaseAddress,
- IN UINT64 Length,
- IN CONST EFI_GUID *FvName,
- IN CONST EFI_GUID *FileName
+ IN EFI_PHYSICAL_ADDRESS BaseAddress,
+ IN UINT64 Length,
+ IN CONST EFI_GUID *FvName,
+ IN CONST EFI_GUID *FileName
)
{
EFI_HOB_FIRMWARE_VOLUME2 *Hob;
@@ -485,7 +491,6 @@ BuildFv2Hob ( CopyGuid (&Hob->FileName, FileName);
}
-
/**
Builds a HOB for the CPU.
@@ -499,8 +504,8 @@ BuildFv2Hob ( VOID
EFIAPI
BuildCpuHob (
- IN UINT8 SizeOfMemorySpace,
- IN UINT8 SizeOfIoSpace
+ IN UINT8 SizeOfMemorySpace,
+ IN UINT8 SizeOfIoSpace
)
{
EFI_HOB_CPU *Hob;
@@ -530,15 +535,17 @@ BuildCpuHob ( VOID
EFIAPI
BuildMemoryAllocationHob (
- IN EFI_PHYSICAL_ADDRESS BaseAddress,
- IN UINT64 Length,
- IN EFI_MEMORY_TYPE MemoryType
+ IN EFI_PHYSICAL_ADDRESS BaseAddress,
+ IN UINT64 Length,
+ IN EFI_MEMORY_TYPE MemoryType
)
{
EFI_HOB_MEMORY_ALLOCATION *Hob;
- ASSERT (((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) &&
- ((Length & (EFI_PAGE_SIZE - 1)) == 0));
+ ASSERT (
+ ((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) &&
+ ((Length & (EFI_PAGE_SIZE - 1)) == 0)
+ );
Hob = CreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, sizeof (EFI_HOB_MEMORY_ALLOCATION));
@@ -592,14 +599,13 @@ BuildResourceDescriptorWithOwnerHob ( VOID
EFIAPI
BuildCvHob (
- IN EFI_PHYSICAL_ADDRESS BaseAddress,
- IN UINT64 Length
+ IN EFI_PHYSICAL_ADDRESS BaseAddress,
+ IN UINT64 Length
)
{
ASSERT (FALSE);
}
-
/**
Builds a HOB for the BSP store.
@@ -614,9 +620,9 @@ BuildCvHob ( VOID
EFIAPI
BuildBspStoreHob (
- IN EFI_PHYSICAL_ADDRESS BaseAddress,
- IN UINT64 Length,
- IN EFI_MEMORY_TYPE MemoryType
+ IN EFI_PHYSICAL_ADDRESS BaseAddress,
+ IN UINT64 Length,
+ IN EFI_MEMORY_TYPE MemoryType
)
{
ASSERT (FALSE);
@@ -635,8 +641,8 @@ BuildBspStoreHob ( VOID
EFIAPI
BuildStackHob (
- IN EFI_PHYSICAL_ADDRESS BaseAddress,
- IN UINT64 Length
+ IN EFI_PHYSICAL_ADDRESS BaseAddress,
+ IN UINT64 Length
)
{
ASSERT (FALSE);
diff --git a/StandaloneMmPkg/Library/StandaloneMmMemLib/ArmStandaloneMmMemLibInternal.c b/StandaloneMmPkg/Library/StandaloneMmMemLib/ArmStandaloneMmMemLibInternal.c index fa7df46..297cfae 100644 --- a/StandaloneMmPkg/Library/StandaloneMmMemLib/ArmStandaloneMmMemLibInternal.c +++ b/StandaloneMmPkg/Library/StandaloneMmMemLib/ArmStandaloneMmMemLibInternal.c @@ -21,10 +21,10 @@ extern EFI_PHYSICAL_ADDRESS mMmMemLibInternalMaximumSupportAddress;
#ifdef MDE_CPU_AARCH64
-#define ARM_PHYSICAL_ADDRESS_BITS 36
+#define ARM_PHYSICAL_ADDRESS_BITS 36
#endif
#ifdef MDE_CPU_ARM
-#define ARM_PHYSICAL_ADDRESS_BITS 32
+#define ARM_PHYSICAL_ADDRESS_BITS 32
#endif
/**
@@ -36,7 +36,7 @@ MmMemLibInternalCalculateMaximumSupportAddress ( VOID
)
{
- UINT8 PhysicalAddressBits;
+ UINT8 PhysicalAddressBits;
PhysicalAddressBits = ARM_PHYSICAL_ADDRESS_BITS;
@@ -74,4 +74,3 @@ MmMemLibInternalFreeMmramRanges ( {
// Not implemented for AARCH64.
}
-
diff --git a/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.c b/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.c index 2737f95..e639327 100644 --- a/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.c +++ b/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.c @@ -13,15 +13,14 @@ **/
-
#include <PiMm.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
-EFI_MMRAM_DESCRIPTOR *mMmMemLibInternalMmramRanges;
-UINTN mMmMemLibInternalMmramCount;
+EFI_MMRAM_DESCRIPTOR *mMmMemLibInternalMmramRanges;
+UINTN mMmMemLibInternalMmramCount;
//
// Maximum support address used to check input buffer
@@ -82,7 +81,8 @@ MmIsBufferOutsideMmValid ( //
if ((Length > mMmMemLibInternalMaximumSupportAddress) ||
(Buffer > mMmMemLibInternalMaximumSupportAddress) ||
- ((Length != 0) && (Buffer > (mMmMemLibInternalMaximumSupportAddress - (Length - 1)))) ) {
+ ((Length != 0) && (Buffer > (mMmMemLibInternalMaximumSupportAddress - (Length - 1)))))
+ {
//
// Overflow happen
//
@@ -96,11 +96,12 @@ MmIsBufferOutsideMmValid ( return FALSE;
}
- for (Index = 0; Index < mMmMemLibInternalMmramCount; Index ++) {
+ 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))) {
+ (mMmMemLibInternalMmramRanges[Index].CpuStart < Buffer + Length)))
+ {
DEBUG ((
DEBUG_ERROR,
"MmIsBufferOutsideMmValid: Overlap: Buffer (0x%lx) - Length (0x%lx), ",
@@ -149,6 +150,7 @@ MmCopyMemToMmram ( DEBUG ((DEBUG_ERROR, "MmCopyMemToMmram: Security Violation: Source (0x%x), Length (0x%x)\n", SourceBuffer, Length));
return EFI_SECURITY_VIOLATION;
}
+
CopyMem (DestinationBuffer, SourceBuffer, Length);
return EFI_SUCCESS;
}
@@ -179,10 +181,15 @@ MmCopyMemFromMmram ( )
{
if (!MmIsBufferOutsideMmValid ((EFI_PHYSICAL_ADDRESS)(UINTN)DestinationBuffer, Length)) {
- DEBUG ((DEBUG_ERROR, "MmCopyMemFromMmram: Security Violation: Destination (0x%x), Length (0x%x)\n",
- DestinationBuffer, Length));
+ DEBUG ((
+ DEBUG_ERROR,
+ "MmCopyMemFromMmram: Security Violation: Destination (0x%x), Length (0x%x)\n",
+ DestinationBuffer,
+ Length
+ ));
return EFI_SECURITY_VIOLATION;
}
+
CopyMem (DestinationBuffer, SourceBuffer, Length);
return EFI_SUCCESS;
}
@@ -214,14 +221,20 @@ MmCopyMem ( )
{
if (!MmIsBufferOutsideMmValid ((EFI_PHYSICAL_ADDRESS)(UINTN)DestinationBuffer, Length)) {
- DEBUG ((DEBUG_ERROR, "MmCopyMem: Security Violation: Destination (0x%x), Length (0x%x)\n",
- DestinationBuffer, Length));
+ DEBUG ((
+ DEBUG_ERROR,
+ "MmCopyMem: Security Violation: Destination (0x%x), Length (0x%x)\n",
+ DestinationBuffer,
+ Length
+ ));
return EFI_SECURITY_VIOLATION;
}
+
if (!MmIsBufferOutsideMmValid ((EFI_PHYSICAL_ADDRESS)(UINTN)SourceBuffer, Length)) {
DEBUG ((DEBUG_ERROR, "MmCopyMem: Security Violation: Source (0x%x), Length (0x%x)\n", SourceBuffer, Length));
return EFI_SECURITY_VIOLATION;
}
+
CopyMem (DestinationBuffer, SourceBuffer, Length);
return EFI_SUCCESS;
}
@@ -254,6 +267,7 @@ MmSetMem ( DEBUG ((DEBUG_ERROR, "MmSetMem: Security Violation: Source (0x%x), Length (0x%x)\n", Buffer, Length));
return EFI_SECURITY_VIOLATION;
}
+
SetMem (Buffer, Length, Value);
return EFI_SUCCESS;
}
@@ -270,11 +284,11 @@ MmSetMem ( EFI_STATUS
EFIAPI
MemLibConstructor (
- IN EFI_HANDLE ImageHandle,
- IN EFI_MM_SYSTEM_TABLE *MmSystemTable
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_MM_SYSTEM_TABLE *MmSystemTable
)
{
- EFI_STATUS Status;
+ EFI_STATUS Status;
//
// Calculate and save maximum support address
@@ -301,11 +315,10 @@ MemLibConstructor ( EFI_STATUS
EFIAPI
MemLibDestructor (
- IN EFI_HANDLE ImageHandle,
- IN EFI_MM_SYSTEM_TABLE *MmSystemTable
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_MM_SYSTEM_TABLE *MmSystemTable
)
{
-
//
// Deinitialize cached Mmram Ranges.
//
diff --git a/StandaloneMmPkg/Library/StandaloneMmMemLib/X86StandaloneMmMemLibInternal.c b/StandaloneMmPkg/Library/StandaloneMmMemLib/X86StandaloneMmMemLibInternal.c index 1a97854..c309d1b 100644 --- a/StandaloneMmPkg/Library/StandaloneMmMemLib/X86StandaloneMmMemLibInternal.c +++ b/StandaloneMmPkg/Library/StandaloneMmMemLib/X86StandaloneMmMemLibInternal.c @@ -27,7 +27,7 @@ // Maximum support address used to check input buffer
//
extern EFI_PHYSICAL_ADDRESS mMmMemLibInternalMaximumSupportAddress;
-extern EFI_MMRAM_DESCRIPTOR *mMmMemLibInternalMmramRanges;
+extern EFI_MMRAM_DESCRIPTOR *mMmMemLibInternalMmramRanges;
extern UINTN mMmMemLibInternalMmramCount;
/**
@@ -39,25 +39,26 @@ MmMemLibInternalCalculateMaximumSupportAddress ( VOID
)
{
- VOID *Hob;
- UINT32 RegEax;
- UINT8 PhysicalAddressBits;
+ VOID *Hob;
+ UINT32 RegEax;
+ UINT8 PhysicalAddressBits;
//
// Get physical address bits supported.
//
Hob = GetFirstHob (EFI_HOB_TYPE_CPU);
if (Hob != NULL) {
- PhysicalAddressBits = ((EFI_HOB_CPU *) Hob)->SizeOfMemorySpace;
+ PhysicalAddressBits = ((EFI_HOB_CPU *)Hob)->SizeOfMemorySpace;
} else {
AsmCpuid (0x80000000, &RegEax, NULL, NULL, NULL);
if (RegEax >= 0x80000008) {
AsmCpuid (0x80000008, &RegEax, NULL, NULL, NULL);
- PhysicalAddressBits = (UINT8) RegEax;
+ PhysicalAddressBits = (UINT8)RegEax;
} else {
PhysicalAddressBits = 36;
}
}
+
//
// IA-32e paging translates 48-bit linear addresses to 52-bit physical addresses.
//
@@ -108,32 +109,34 @@ MmMemLibInternalPopulateMmramRanges ( }
MmramRangesHobData = GET_GUID_HOB_DATA (MmramRangesHob);
- if (MmramRangesHobData == NULL || MmramRangesHobData->Descriptor == NULL) {
+ if ((MmramRangesHobData == NULL) || (MmramRangesHobData->Descriptor == NULL)) {
return EFI_UNSUPPORTED;
}
mMmMemLibInternalMmramCount = MmramRangesHobData->NumberOfMmReservedRegions;
- MmramDescriptors = MmramRangesHobData->Descriptor;
+ MmramDescriptors = MmramRangesHobData->Descriptor;
} else {
DataInHob = GET_GUID_HOB_DATA (GuidHob);
if (DataInHob == NULL) {
return EFI_UNSUPPORTED;
}
- MmCorePrivateData = (MM_CORE_PRIVATE_DATA *) (UINTN) DataInHob->Address;
- if (MmCorePrivateData == NULL || MmCorePrivateData->MmramRanges == 0) {
+ MmCorePrivateData = (MM_CORE_PRIVATE_DATA *)(UINTN)DataInHob->Address;
+ if ((MmCorePrivateData == NULL) || (MmCorePrivateData->MmramRanges == 0)) {
return EFI_UNSUPPORTED;
}
- mMmMemLibInternalMmramCount = (UINTN) MmCorePrivateData->MmramRangeCount;
- MmramDescriptors = (EFI_MMRAM_DESCRIPTOR *) (UINTN) MmCorePrivateData->MmramRanges;
+ mMmMemLibInternalMmramCount = (UINTN)MmCorePrivateData->MmramRangeCount;
+ MmramDescriptors = (EFI_MMRAM_DESCRIPTOR *)(UINTN)MmCorePrivateData->MmramRanges;
}
mMmMemLibInternalMmramRanges = AllocatePool (mMmMemLibInternalMmramCount * sizeof (EFI_MMRAM_DESCRIPTOR));
if (mMmMemLibInternalMmramRanges) {
- CopyMem (mMmMemLibInternalMmramRanges,
- MmramDescriptors,
- mMmMemLibInternalMmramCount * sizeof (EFI_MMRAM_DESCRIPTOR));
+ CopyMem (
+ mMmMemLibInternalMmramRanges,
+ MmramDescriptors,
+ mMmMemLibInternalMmramCount * sizeof (EFI_MMRAM_DESCRIPTOR)
+ );
}
return EFI_SUCCESS;
@@ -152,4 +155,3 @@ MmMemLibInternalFreeMmramRanges ( FreePool (mMmMemLibInternalMmramRanges);
}
}
-
diff --git a/StandaloneMmPkg/Library/StandaloneMmMemoryAllocationLib/StandaloneMmMemoryAllocationLib.c b/StandaloneMmPkg/Library/StandaloneMmMemoryAllocationLib/StandaloneMmMemoryAllocationLib.c index a2819e1..b38b32b 100644 --- a/StandaloneMmPkg/Library/StandaloneMmMemoryAllocationLib/StandaloneMmMemoryAllocationLib.c +++ b/StandaloneMmPkg/Library/StandaloneMmMemoryAllocationLib/StandaloneMmMemoryAllocationLib.c @@ -45,6 +45,7 @@ InternalAllocatePages ( if (EFI_ERROR (Status)) {
return NULL;
}
+
return (VOID *)(UINTN)Memory;
}
@@ -141,7 +142,7 @@ FreePages ( EFI_STATUS Status;
ASSERT (Pages != 0);
- Status = gMmst->MmFreePages ((EFI_PHYSICAL_ADDRESS) (UINTN)Buffer, Pages);
+ Status = gMmst->MmFreePages ((EFI_PHYSICAL_ADDRESS)(UINTN)Buffer, Pages);
ASSERT_EFI_ERROR (Status);
}
@@ -185,23 +186,25 @@ InternalAllocateAlignedPages ( if (Pages == 0) {
return NULL;
}
+
if (Alignment > EFI_PAGE_SIZE) {
//
// Calculate the total number of pages since alignment is larger than page size.
//
- AlignmentMask = Alignment - 1;
- RealPages = Pages + EFI_SIZE_TO_PAGES (Alignment);
+ AlignmentMask = Alignment - 1;
+ RealPages = Pages + EFI_SIZE_TO_PAGES (Alignment);
//
// Make sure that Pages plus EFI_SIZE_TO_PAGES (Alignment) does not overflow.
//
ASSERT (RealPages > Pages);
- Status = gMmst->MmAllocatePages (AllocateAnyPages, MemoryType, RealPages, &Memory);
+ Status = gMmst->MmAllocatePages (AllocateAnyPages, MemoryType, RealPages, &Memory);
if (EFI_ERROR (Status)) {
return NULL;
}
+
AlignedMemory = ((UINTN)Memory + AlignmentMask) & ~AlignmentMask;
- UnalignedPages = EFI_SIZE_TO_PAGES (AlignedMemory - (UINTN) Memory);
+ UnalignedPages = EFI_SIZE_TO_PAGES (AlignedMemory - (UINTN)Memory);
if (UnalignedPages > 0) {
//
// Free first unaligned page(s).
@@ -209,6 +212,7 @@ InternalAllocateAlignedPages ( Status = gMmst->MmFreePages (Memory, UnalignedPages);
ASSERT_EFI_ERROR (Status);
}
+
Memory = (EFI_PHYSICAL_ADDRESS)(AlignedMemory + EFI_PAGES_TO_SIZE (Pages));
UnalignedPages = RealPages - Pages - UnalignedPages;
if (UnalignedPages > 0) {
@@ -226,9 +230,11 @@ InternalAllocateAlignedPages ( if (EFI_ERROR (Status)) {
return NULL;
}
- AlignedMemory = (UINTN) Memory;
+
+ AlignedMemory = (UINTN)Memory;
}
- return (VOID *) AlignedMemory;
+
+ return (VOID *)AlignedMemory;
}
/**
@@ -374,6 +380,7 @@ InternalAllocatePool ( if (EFI_ERROR (Status)) {
Memory = NULL;
}
+
return Memory;
}
@@ -466,6 +473,7 @@ InternalAllocateZeroPool ( if (Memory != NULL) {
Memory = ZeroMem (Memory, AllocationSize);
}
+
return Memory;
}
@@ -562,12 +570,13 @@ InternalAllocateCopyPool ( VOID *Memory;
ASSERT (Buffer != NULL);
- ASSERT (AllocationSize <= (MAX_ADDRESS - (UINTN) Buffer + 1));
+ ASSERT (AllocationSize <= (MAX_ADDRESS - (UINTN)Buffer + 1));
Memory = InternalAllocatePool (PoolType, AllocationSize);
if (Memory != NULL) {
- Memory = CopyMem (Memory, Buffer, AllocationSize);
+ Memory = CopyMem (Memory, Buffer, AllocationSize);
}
+
return Memory;
}
@@ -685,10 +694,11 @@ InternalReallocatePool ( VOID *NewBuffer;
NewBuffer = InternalAllocateZeroPool (PoolType, NewSize);
- if (NewBuffer != NULL && OldBuffer != NULL) {
+ if ((NewBuffer != NULL) && (OldBuffer != NULL)) {
CopyMem (NewBuffer, OldBuffer, MIN (OldSize, NewSize));
FreePool (OldBuffer);
}
+
return NewBuffer;
}
@@ -805,10 +815,10 @@ ReallocateReservedPool ( VOID
EFIAPI
FreePool (
- IN VOID *Buffer
+ IN VOID *Buffer
)
{
- EFI_STATUS Status;
+ EFI_STATUS Status;
Status = gMmst->MmFreePool (Buffer);
ASSERT_EFI_ERROR (Status);
diff --git a/StandaloneMmPkg/Library/StandaloneMmPeCoffExtraActionLib/AArch64/StandaloneMmPeCoffExtraActionLib.c b/StandaloneMmPkg/Library/StandaloneMmPeCoffExtraActionLib/AArch64/StandaloneMmPeCoffExtraActionLib.c index ca8b124..426fd8d 100644 --- a/StandaloneMmPkg/Library/StandaloneMmPeCoffExtraActionLib/AArch64/StandaloneMmPeCoffExtraActionLib.c +++ b/StandaloneMmPkg/Library/StandaloneMmPeCoffExtraActionLib/AArch64/StandaloneMmPeCoffExtraActionLib.c @@ -19,29 +19,29 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include <Library/PeCoffExtraActionLib.h>
typedef RETURN_STATUS (*REGION_PERMISSION_UPDATE_FUNC) (
- IN EFI_PHYSICAL_ADDRESS BaseAddress,
- IN UINT64 Length
+ IN EFI_PHYSICAL_ADDRESS BaseAddress,
+ IN UINT64 Length
);
STATIC
RETURN_STATUS
UpdatePeCoffPermissions (
- IN CONST PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext,
- IN REGION_PERMISSION_UPDATE_FUNC NoExecUpdater,
- IN REGION_PERMISSION_UPDATE_FUNC ReadOnlyUpdater
+ IN CONST PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext,
+ IN REGION_PERMISSION_UPDATE_FUNC NoExecUpdater,
+ IN REGION_PERMISSION_UPDATE_FUNC ReadOnlyUpdater
)
{
- RETURN_STATUS Status;
- EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;
- EFI_IMAGE_OPTIONAL_HEADER_UNION HdrData;
- UINTN Size;
- UINTN ReadSize;
- UINT32 SectionHeaderOffset;
- UINTN NumberOfSections;
- UINTN Index;
- EFI_IMAGE_SECTION_HEADER SectionHeader;
- PE_COFF_LOADER_IMAGE_CONTEXT TmpContext;
- EFI_PHYSICAL_ADDRESS Base;
+ RETURN_STATUS Status;
+ EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;
+ EFI_IMAGE_OPTIONAL_HEADER_UNION HdrData;
+ UINTN Size;
+ UINTN ReadSize;
+ UINT32 SectionHeaderOffset;
+ UINTN NumberOfSections;
+ UINTN Index;
+ EFI_IMAGE_SECTION_HEADER SectionHeader;
+ PE_COFF_LOADER_IMAGE_CONTEXT TmpContext;
+ EFI_PHYSICAL_ADDRESS Base;
//
// We need to copy ImageContext since PeCoffLoaderGetImageInfo ()
@@ -52,17 +52,25 @@ UpdatePeCoffPermissions ( if (TmpContext.PeCoffHeaderOffset == 0) {
Status = PeCoffLoaderGetImageInfo (&TmpContext);
if (RETURN_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR,
+ DEBUG ((
+ DEBUG_ERROR,
"%a: PeCoffLoaderGetImageInfo () failed (Status = %r)\n",
- __FUNCTION__, Status));
+ __FUNCTION__,
+ Status
+ ));
return Status;
}
}
if (TmpContext.IsTeImage &&
- TmpContext.ImageAddress == ImageContext->ImageAddress) {
- DEBUG ((DEBUG_INFO, "%a: ignoring XIP TE image at 0x%lx\n", __FUNCTION__,
- ImageContext->ImageAddress));
+ (TmpContext.ImageAddress == ImageContext->ImageAddress))
+ {
+ DEBUG ((
+ DEBUG_INFO,
+ "%a: ignoring XIP TE image at 0x%lx\n",
+ __FUNCTION__,
+ ImageContext->ImageAddress
+ ));
return RETURN_SUCCESS;
}
@@ -73,10 +81,15 @@ UpdatePeCoffPermissions ( // noexec permissions on the entire region.
//
if (!TmpContext.IsTeImage) {
- DEBUG ((DEBUG_WARN,
+ DEBUG ((
+ DEBUG_WARN,
"%a: non-TE Image at 0x%lx has SectionAlignment < 4 KB (%lu)\n",
- __FUNCTION__, ImageContext->ImageAddress, TmpContext.SectionAlignment));
+ __FUNCTION__,
+ ImageContext->ImageAddress,
+ TmpContext.SectionAlignment
+ ));
}
+
Base = ImageContext->ImageAddress & ~(EFI_PAGE_SIZE - 1);
Size = ImageContext->ImageAddress - Base + ImageContext->ImageSize;
return NoExecUpdater (Base, ALIGN_VALUE (Size, EFI_PAGE_SIZE));
@@ -89,14 +102,21 @@ UpdatePeCoffPermissions ( // location in both images.
//
Hdr.Union = &HdrData;
- Size = sizeof (EFI_IMAGE_OPTIONAL_HEADER_UNION);
- ReadSize = Size;
- Status = TmpContext.ImageRead (TmpContext.Handle,
- TmpContext.PeCoffHeaderOffset, &Size, Hdr.Pe32);
+ Size = sizeof (EFI_IMAGE_OPTIONAL_HEADER_UNION);
+ ReadSize = Size;
+ Status = TmpContext.ImageRead (
+ TmpContext.Handle,
+ TmpContext.PeCoffHeaderOffset,
+ &Size,
+ Hdr.Pe32
+ );
if (RETURN_ERROR (Status) || (Size != ReadSize)) {
- DEBUG ((DEBUG_ERROR,
+ DEBUG ((
+ DEBUG_ERROR,
"%a: TmpContext.ImageRead () failed (Status = %r)\n",
- __FUNCTION__, Status));
+ __FUNCTION__,
+ Status
+ ));
return Status;
}
@@ -104,7 +124,7 @@ UpdatePeCoffPermissions ( SectionHeaderOffset = TmpContext.PeCoffHeaderOffset + sizeof (UINT32) +
sizeof (EFI_IMAGE_FILE_HEADER);
- NumberOfSections = (UINTN)(Hdr.Pe32->FileHeader.NumberOfSections);
+ NumberOfSections = (UINTN)(Hdr.Pe32->FileHeader.NumberOfSections);
switch (Hdr.Pe32->OptionalHeader.Magic) {
case EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC:
@@ -124,42 +144,63 @@ UpdatePeCoffPermissions ( //
// Read section header from file
//
- Size = sizeof (EFI_IMAGE_SECTION_HEADER);
+ Size = sizeof (EFI_IMAGE_SECTION_HEADER);
ReadSize = Size;
- Status = TmpContext.ImageRead (TmpContext.Handle, SectionHeaderOffset,
- &Size, &SectionHeader);
+ Status = TmpContext.ImageRead (
+ TmpContext.Handle,
+ SectionHeaderOffset,
+ &Size,
+ &SectionHeader
+ );
if (RETURN_ERROR (Status) || (Size != ReadSize)) {
- DEBUG ((DEBUG_ERROR,
+ DEBUG ((
+ DEBUG_ERROR,
"%a: TmpContext.ImageRead () failed (Status = %r)\n",
- __FUNCTION__, Status));
+ __FUNCTION__,
+ Status
+ ));
return Status;
}
Base = TmpContext.ImageAddress + SectionHeader.VirtualAddress;
if ((SectionHeader.Characteristics & EFI_IMAGE_SCN_MEM_EXECUTE) == 0) {
-
if ((SectionHeader.Characteristics & EFI_IMAGE_SCN_MEM_WRITE) == 0) {
-
- DEBUG ((DEBUG_INFO,
+ DEBUG ((
+ DEBUG_INFO,
"%a: Mapping section %d of image at 0x%lx with RO-XN permissions and size 0x%x\n",
- __FUNCTION__, Index, Base, SectionHeader.Misc.VirtualSize));
+ __FUNCTION__,
+ Index,
+ Base,
+ SectionHeader.Misc.VirtualSize
+ ));
ReadOnlyUpdater (Base, SectionHeader.Misc.VirtualSize);
} else {
- DEBUG ((DEBUG_WARN,
+ DEBUG ((
+ DEBUG_WARN,
"%a: Mapping section %d of image at 0x%lx with RW-XN permissions and size 0x%x\n",
- __FUNCTION__, Index, Base, SectionHeader.Misc.VirtualSize));
+ __FUNCTION__,
+ Index,
+ Base,
+ SectionHeader.Misc.VirtualSize
+ ));
}
} else {
- DEBUG ((DEBUG_INFO,
- "%a: Mapping section %d of image at 0x%lx with RO-X permissions and size 0x%x\n",
- __FUNCTION__, Index, Base, SectionHeader.Misc.VirtualSize));
- ReadOnlyUpdater (Base, SectionHeader.Misc.VirtualSize);
- NoExecUpdater (Base, SectionHeader.Misc.VirtualSize);
+ DEBUG ((
+ DEBUG_INFO,
+ "%a: Mapping section %d of image at 0x%lx with RO-X permissions and size 0x%x\n",
+ __FUNCTION__,
+ Index,
+ Base,
+ SectionHeader.Misc.VirtualSize
+ ));
+ ReadOnlyUpdater (Base, SectionHeader.Misc.VirtualSize);
+ NoExecUpdater (Base, SectionHeader.Misc.VirtualSize);
}
SectionHeaderOffset += sizeof (EFI_IMAGE_SECTION_HEADER);
}
+
return RETURN_SUCCESS;
}
@@ -185,8 +226,6 @@ PeCoffLoaderRelocateImageExtraAction ( );
}
-
-
/**
Performs additional actions just before a PE/COFF image is unloaded. Any resources
that were allocated by PeCoffLoaderRelocateImageExtraAction() must be freed.
diff --git a/StandaloneMmPkg/Library/VariableMmDependency/VariableMmDependency.c b/StandaloneMmPkg/Library/VariableMmDependency/VariableMmDependency.c index 9ab7b10..f647fc5 100644 --- a/StandaloneMmPkg/Library/VariableMmDependency/VariableMmDependency.c +++ b/StandaloneMmPkg/Library/VariableMmDependency/VariableMmDependency.c @@ -26,12 +26,12 @@ SPDX-License-Identifier: BSD-2-Clause-Patent EFI_STATUS
EFIAPI
VariableMmDependencyLibConstructor (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
)
{
- EFI_STATUS Status;
- EFI_HANDLE Handle;
+ EFI_STATUS Status;
+ EFI_HANDLE Handle;
Handle = NULL;
Status = gBS->InstallMultipleProtocolInterfaces (
|