From: Michael Kubacki Date: Sun, 5 Dec 2021 22:54:16 +0000 (-0800) Subject: StandaloneMmPkg: Apply uncrustify changes X-Git-Tag: edk2-stable202202~212 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=91415a36ae7aaeabb2bbab3762f39544f9aed683 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 --- diff --git a/StandaloneMmPkg/Core/Dependency.c b/StandaloneMmPkg/Core/Dependency.c index eb4baa4086..440fe3e452 100644 --- a/StandaloneMmPkg/Core/Dependency.c +++ b/StandaloneMmPkg/Core/Dependency.c @@ -47,8 +47,8 @@ GrowDepexStack ( VOID ) { - BOOLEAN *NewStack; - UINTN Size; + BOOLEAN *NewStack; + UINTN Size; Size = DEPEX_STACK_SIZE_INCREMENT; if (mDepexEvaluationStack != NULL) { @@ -167,7 +167,7 @@ PopBool ( **/ BOOLEAN MmIsSchedulable ( - IN EFI_MM_DRIVER_ENTRY *DriverEntry + IN EFI_MM_DRIVER_ENTRY *DriverEntry ) { EFI_STATUS Status; @@ -177,7 +177,7 @@ MmIsSchedulable ( EFI_GUID DriverGuid; VOID *Interface; - Operator = FALSE; + Operator = FALSE; Operator2 = FALSE; if (DriverEntry->After || DriverEntry->Before) { @@ -206,7 +206,6 @@ MmIsSchedulable ( // mDepexEvaluationStackPointer = mDepexEvaluationStack; - Iterator = DriverEntry->Depex; while (TRUE) { @@ -223,148 +222,155 @@ MmIsSchedulable ( // Look at the opcode of the dependency expression instruction. // switch (*Iterator) { - case EFI_DEP_BEFORE: - case EFI_DEP_AFTER: - // - // For a well-formed Dependency Expression, the code should never get here. - // The BEFORE and AFTER are processed prior to this routine's invocation. - // If the code flow arrives at this point, there was a BEFORE or AFTER - // that were not the first opcodes. - // - DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected BEFORE or AFTER opcode)\n")); - ASSERT (FALSE); - - case EFI_DEP_PUSH: - // - // Push operator is followed by a GUID. Test to see if the GUID protocol - // is installed and push the boolean result on the stack. - // - CopyMem (&DriverGuid, Iterator + 1, sizeof (EFI_GUID)); - - Status = MmLocateProtocol (&DriverGuid, NULL, &Interface); - if (EFI_ERROR (Status) && (mEfiSystemTable != NULL)) { + case EFI_DEP_BEFORE: + case EFI_DEP_AFTER: + // + // For a well-formed Dependency Expression, the code should never get here. + // The BEFORE and AFTER are processed prior to this routine's invocation. + // If the code flow arrives at this point, there was a BEFORE or AFTER + // that were not the first opcodes. + // + DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected BEFORE or AFTER opcode)\n")); + ASSERT (FALSE); + + case EFI_DEP_PUSH: // - // For MM Driver, it may depend on uefi protocols + // Push operator is followed by a GUID. Test to see if the GUID protocol + // is installed and push the boolean result on the stack. // - Status = mEfiSystemTable->BootServices->LocateProtocol (&DriverGuid, NULL, &Interface); - } + CopyMem (&DriverGuid, Iterator + 1, sizeof (EFI_GUID)); + + Status = MmLocateProtocol (&DriverGuid, NULL, &Interface); + if (EFI_ERROR (Status) && (mEfiSystemTable != NULL)) { + // + // For MM Driver, it may depend on uefi protocols + // + Status = mEfiSystemTable->BootServices->LocateProtocol (&DriverGuid, NULL, &Interface); + } + + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_DISPATCH, " PUSH GUID(%g) = FALSE\n", &DriverGuid)); + Status = PushBool (FALSE); + } else { + DEBUG ((DEBUG_DISPATCH, " PUSH GUID(%g) = TRUE\n", &DriverGuid)); + *Iterator = EFI_DEP_REPLACE_TRUE; + Status = PushBool (TRUE); + } + + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n")); + return FALSE; + } + + Iterator += sizeof (EFI_GUID); + break; + + case EFI_DEP_AND: + DEBUG ((DEBUG_DISPATCH, " AND\n")); + Status = PopBool (&Operator); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n")); + return FALSE; + } + + Status = PopBool (&Operator2); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n")); + return FALSE; + } + + Status = PushBool ((BOOLEAN)(Operator && Operator2)); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n")); + return FALSE; + } + + break; + + case EFI_DEP_OR: + DEBUG ((DEBUG_DISPATCH, " OR\n")); + Status = PopBool (&Operator); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n")); + return FALSE; + } + + Status = PopBool (&Operator2); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n")); + return FALSE; + } + + Status = PushBool ((BOOLEAN)(Operator || Operator2)); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n")); + return FALSE; + } + + break; + + case EFI_DEP_NOT: + DEBUG ((DEBUG_DISPATCH, " NOT\n")); + Status = PopBool (&Operator); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n")); + return FALSE; + } + + Status = PushBool ((BOOLEAN)(!Operator)); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n")); + return FALSE; + } + + break; + + case EFI_DEP_TRUE: + DEBUG ((DEBUG_DISPATCH, " TRUE\n")); + Status = PushBool (TRUE); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n")); + return FALSE; + } + + break; - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_DISPATCH, " PUSH GUID(%g) = FALSE\n", &DriverGuid)); + case EFI_DEP_FALSE: + DEBUG ((DEBUG_DISPATCH, " FALSE\n")); Status = PushBool (FALSE); - } else { + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n")); + return FALSE; + } + + break; + + case EFI_DEP_END: + DEBUG ((DEBUG_DISPATCH, " END\n")); + Status = PopBool (&Operator); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n")); + return FALSE; + } + + DEBUG ((DEBUG_DISPATCH, " RESULT = %a\n", Operator ? "TRUE" : "FALSE")); + return Operator; + + case EFI_DEP_REPLACE_TRUE: + CopyMem (&DriverGuid, Iterator + 1, sizeof (EFI_GUID)); DEBUG ((DEBUG_DISPATCH, " PUSH GUID(%g) = TRUE\n", &DriverGuid)); - *Iterator = EFI_DEP_REPLACE_TRUE; Status = PushBool (TRUE); - } - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n")); - return FALSE; - } - - Iterator += sizeof (EFI_GUID); - break; - - case EFI_DEP_AND: - DEBUG ((DEBUG_DISPATCH, " AND\n")); - Status = PopBool (&Operator); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n")); - return FALSE; - } - - Status = PopBool (&Operator2); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n")); - return FALSE; - } - - Status = PushBool ((BOOLEAN)(Operator && Operator2)); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n")); - return FALSE; - } - break; - - case EFI_DEP_OR: - DEBUG ((DEBUG_DISPATCH, " OR\n")); - Status = PopBool (&Operator); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n")); - return FALSE; - } - - Status = PopBool (&Operator2); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n")); - return FALSE; - } - - Status = PushBool ((BOOLEAN)(Operator || Operator2)); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n")); - return FALSE; - } - break; - - case EFI_DEP_NOT: - DEBUG ((DEBUG_DISPATCH, " NOT\n")); - Status = PopBool (&Operator); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n")); - return FALSE; - } - - Status = PushBool ((BOOLEAN)(!Operator)); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n")); - return FALSE; - } - break; - - case EFI_DEP_TRUE: - DEBUG ((DEBUG_DISPATCH, " TRUE\n")); - Status = PushBool (TRUE); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n")); - return FALSE; - } - break; - - case EFI_DEP_FALSE: - DEBUG ((DEBUG_DISPATCH, " FALSE\n")); - Status = PushBool (FALSE); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n")); - return FALSE; - } - break; - - case EFI_DEP_END: - DEBUG ((DEBUG_DISPATCH, " END\n")); - Status = PopBool (&Operator); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n")); - return FALSE; - } - DEBUG ((DEBUG_DISPATCH, " RESULT = %a\n", Operator ? "TRUE" : "FALSE")); - return Operator; - - case EFI_DEP_REPLACE_TRUE: - CopyMem (&DriverGuid, Iterator + 1, sizeof (EFI_GUID)); - DEBUG ((DEBUG_DISPATCH, " PUSH GUID(%g) = TRUE\n", &DriverGuid)); - Status = PushBool (TRUE); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n")); - return FALSE; - } - - Iterator += sizeof (EFI_GUID); - break; - - default: - DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unknown opcode)\n")); - goto Done; + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unexpected error)\n")); + return FALSE; + } + + Iterator += sizeof (EFI_GUID); + break; + + default: + DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Unknown opcode)\n")); + goto Done; } // diff --git a/StandaloneMmPkg/Core/Dispatcher.c b/StandaloneMmPkg/Core/Dispatcher.c index 7e4bf5e940..b1ccba15b0 100644 --- a/StandaloneMmPkg/Core/Dispatcher.c +++ b/StandaloneMmPkg/Core/Dispatcher.c @@ -44,9 +44,9 @@ #define KNOWN_FWVOL_SIGNATURE SIGNATURE_32('k','n','o','w') typedef struct { - UINTN Signature; - LIST_ENTRY Link; // mFwVolList - EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader; + UINTN Signature; + LIST_ENTRY Link; // mFwVolList + EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader; } KNOWN_FWVOL; // @@ -71,7 +71,7 @@ MmCoreFfsFindMmDriver ( **/ VOID MmInsertOnScheduledQueueWhileProcessingBeforeAndAfter ( - IN EFI_MM_DRIVER_ENTRY *InsertedDriverEntry + IN EFI_MM_DRIVER_ENTRY *InsertedDriverEntry ); // @@ -107,7 +107,7 @@ BOOLEAN gRequestDispatch = FALSE; // memory range usage. It is a bit mapped array in which every bit indicates the correspoding // memory page available or not. // -GLOBAL_REMOVE_IF_UNREFERENCED UINT64 *mMmCodeMemoryRangeUsageBitMap=NULL; +GLOBAL_REMOVE_IF_UNREFERENCED UINT64 *mMmCodeMemoryRangeUsageBitMap = NULL; /** To check memory usage bit map array to figure out if the memory range in which the image will be loaded @@ -123,23 +123,23 @@ GLOBAL_REMOVE_IF_UNREFERENCED UINT64 *mMmCodeMemoryRangeUsageB **/ EFI_STATUS CheckAndMarkFixLoadingMemoryUsageBitMap ( - IN EFI_PHYSICAL_ADDRESS ImageBase, - IN UINTN ImageSize + IN EFI_PHYSICAL_ADDRESS ImageBase, + IN UINTN ImageSize ) { - UINT32 MmCodePageNumber; - UINT64 MmCodeSize; - EFI_PHYSICAL_ADDRESS MmCodeBase; - UINTN BaseOffsetPageNumber; - UINTN TopOffsetPageNumber; - UINTN Index; + UINT32 MmCodePageNumber; + UINT64 MmCodeSize; + EFI_PHYSICAL_ADDRESS MmCodeBase; + UINTN BaseOffsetPageNumber; + UINTN TopOffsetPageNumber; + UINTN Index; // // Build tool will calculate the smm code size and then patch the PcdLoadFixAddressMmCodePageNumber // MmCodePageNumber = 0; - MmCodeSize = EFI_PAGES_TO_SIZE (MmCodePageNumber); - MmCodeBase = gLoadModuleAtFixAddressMmramBase; + MmCodeSize = EFI_PAGES_TO_SIZE (MmCodePageNumber); + MmCodeBase = gLoadModuleAtFixAddressMmramBase; // // If the memory usage bit map is not initialized, do it. Every bit in the array @@ -159,7 +159,7 @@ CheckAndMarkFixLoadingMemoryUsageBitMap ( // // see if the memory range for loading the image is in the MM code range. // - if (MmCodeBase + MmCodeSize < ImageBase + ImageSize || MmCodeBase > ImageBase) { + if ((MmCodeBase + MmCodeSize < ImageBase + ImageSize) || (MmCodeBase > ImageBase)) { return EFI_NOT_FOUND; } @@ -168,7 +168,7 @@ CheckAndMarkFixLoadingMemoryUsageBitMap ( // BaseOffsetPageNumber = (UINTN)EFI_SIZE_TO_PAGES ((UINT32)(ImageBase - MmCodeBase)); TopOffsetPageNumber = (UINTN)EFI_SIZE_TO_PAGES ((UINT32)(ImageBase + ImageSize - MmCodeBase)); - for (Index = BaseOffsetPageNumber; Index < TopOffsetPageNumber; Index ++) { + for (Index = BaseOffsetPageNumber; Index < TopOffsetPageNumber; Index++) { if ((mMmCodeMemoryRangeUsageBitMap[Index / 64] & LShiftU64 (1, (Index % 64))) != 0) { // // This page is already used. @@ -180,10 +180,11 @@ CheckAndMarkFixLoadingMemoryUsageBitMap ( // // Being here means the memory range is available. So mark the bits for the memory range // - for (Index = BaseOffsetPageNumber; Index < TopOffsetPageNumber; Index ++) { + for (Index = BaseOffsetPageNumber; Index < TopOffsetPageNumber; Index++) { mMmCodeMemoryRangeUsageBitMap[Index / 64] |= LShiftU64 (1, (Index % 64)); } - return EFI_SUCCESS; + + return EFI_SUCCESS; } /** @@ -197,29 +198,29 @@ CheckAndMarkFixLoadingMemoryUsageBitMap ( **/ EFI_STATUS -GetPeCoffImageFixLoadingAssignedAddress( +GetPeCoffImageFixLoadingAssignedAddress ( IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext ) { - UINTN SectionHeaderOffset; - EFI_STATUS Status; - EFI_IMAGE_SECTION_HEADER SectionHeader; - EFI_IMAGE_OPTIONAL_HEADER_UNION *ImgHdr; - EFI_PHYSICAL_ADDRESS FixLoadingAddress; - UINT16 Index; - UINTN Size; - UINT16 NumberOfSections; - UINT64 ValueInSectionHeader; + UINTN SectionHeaderOffset; + EFI_STATUS Status; + EFI_IMAGE_SECTION_HEADER SectionHeader; + EFI_IMAGE_OPTIONAL_HEADER_UNION *ImgHdr; + EFI_PHYSICAL_ADDRESS FixLoadingAddress; + UINT16 Index; + UINTN Size; + UINT16 NumberOfSections; + UINT64 ValueInSectionHeader; FixLoadingAddress = 0; - Status = EFI_NOT_FOUND; + Status = EFI_NOT_FOUND; // // Get PeHeader pointer // - ImgHdr = (EFI_IMAGE_OPTIONAL_HEADER_UNION *)((CHAR8* )ImageContext->Handle + ImageContext->PeCoffHeaderOffset); + ImgHdr = (EFI_IMAGE_OPTIONAL_HEADER_UNION *)((CHAR8 *)ImageContext->Handle + ImageContext->PeCoffHeaderOffset); SectionHeaderOffset = ImageContext->PeCoffHeaderOffset + sizeof (UINT32) + sizeof (EFI_IMAGE_FILE_HEADER) + - ImgHdr->Pe32.FileHeader.SizeOfOptionalHeader; + ImgHdr->Pe32.FileHeader.SizeOfOptionalHeader; NumberOfSections = ImgHdr->Pe32.FileHeader.NumberOfSections; // @@ -229,7 +230,7 @@ GetPeCoffImageFixLoadingAssignedAddress( // // Read section header from file // - Size = sizeof (EFI_IMAGE_SECTION_HEADER); + Size = sizeof (EFI_IMAGE_SECTION_HEADER); Status = ImageContext->ImageRead ( ImageContext->Handle, SectionHeaderOffset, @@ -250,7 +251,7 @@ GetPeCoffImageFixLoadingAssignedAddress( // assigned by tools, the PointerToRelocations & PointerToLineNumbers fields should not be // Zero, or else, these 2 fields should be set to Zero // - ValueInSectionHeader = ReadUnaligned64 ((UINT64*)&SectionHeader.PointerToRelocations); + ValueInSectionHeader = ReadUnaligned64 ((UINT64 *)&SectionHeader.PointerToRelocations); if (ValueInSectionHeader != 0) { // // Found first section header that doesn't point to code section in which build tool saves the @@ -261,21 +262,29 @@ GetPeCoffImageFixLoadingAssignedAddress( // Check if the memory range is available. // Status = CheckAndMarkFixLoadingMemoryUsageBitMap (FixLoadingAddress, (UINTN)(ImageContext->ImageSize + ImageContext->SectionAlignment)); - if (!EFI_ERROR(Status)) { + if (!EFI_ERROR (Status)) { // // The assigned address is valid. Return the specified loading address // ImageContext->ImageAddress = FixLoadingAddress; } } + break; } + SectionHeaderOffset += sizeof (EFI_IMAGE_SECTION_HEADER); } - DEBUG ((DEBUG_INFO|DEBUG_LOAD, "LOADING MODULE FIXED INFO: Loading module at fixed address %x, Status = %r\n", - FixLoadingAddress, Status)); + + DEBUG (( + DEBUG_INFO|DEBUG_LOAD, + "LOADING MODULE FIXED INFO: Loading module at fixed address %x, Status = %r\n", + FixLoadingAddress, + Status + )); return Status; } + /** Loads an EFI image into SMRAM. @@ -290,19 +299,19 @@ MmLoadImage ( IN OUT EFI_MM_DRIVER_ENTRY *DriverEntry ) { - UINTN PageCount; - EFI_STATUS Status; - EFI_PHYSICAL_ADDRESS DstBuffer; - PE_COFF_LOADER_IMAGE_CONTEXT ImageContext; + UINTN PageCount; + EFI_STATUS Status; + EFI_PHYSICAL_ADDRESS DstBuffer; + PE_COFF_LOADER_IMAGE_CONTEXT ImageContext; DEBUG ((DEBUG_INFO, "MmLoadImage - %g\n", &DriverEntry->FileName)); - Status = EFI_SUCCESS; + Status = EFI_SUCCESS; // // Initialize ImageContext // - ImageContext.Handle = DriverEntry->Pe32Data; + ImageContext.Handle = DriverEntry->Pe32Data; ImageContext.ImageRead = PeCoffLoaderImageReadFromMemory; // @@ -355,14 +364,14 @@ MmLoadImage ( // // Flush the instruction cache so the image data are written before we execute it // - InvalidateInstructionCacheRange ((VOID *)(UINTN) ImageContext.ImageAddress, (UINTN) ImageContext.ImageSize); + InvalidateInstructionCacheRange ((VOID *)(UINTN)ImageContext.ImageAddress, (UINTN)ImageContext.ImageSize); // // Save Image EntryPoint in DriverEntry // - DriverEntry->ImageEntryPoint = ImageContext.EntryPoint; - DriverEntry->ImageBuffer = DstBuffer; - DriverEntry->NumberOfPage = PageCount; + DriverEntry->ImageEntryPoint = ImageContext.EntryPoint; + DriverEntry->ImageBuffer = DstBuffer; + DriverEntry->NumberOfPage = PageCount; if (mEfiSystemTable != NULL) { Status = mEfiSystemTable->BootServices->AllocatePool ( @@ -380,11 +389,11 @@ MmLoadImage ( // Fill in the remaining fields of the Loaded Image Protocol instance. // Note: ImageBase is an SMRAM address that can not be accessed outside of SMRAM if SMRAM window is closed. // - DriverEntry->LoadedImage->Revision = EFI_LOADED_IMAGE_PROTOCOL_REVISION; - DriverEntry->LoadedImage->ParentHandle = NULL; - DriverEntry->LoadedImage->SystemTable = mEfiSystemTable; - DriverEntry->LoadedImage->DeviceHandle = NULL; - DriverEntry->LoadedImage->FilePath = NULL; + DriverEntry->LoadedImage->Revision = EFI_LOADED_IMAGE_PROTOCOL_REVISION; + DriverEntry->LoadedImage->ParentHandle = NULL; + DriverEntry->LoadedImage->SystemTable = mEfiSystemTable; + DriverEntry->LoadedImage->DeviceHandle = NULL; + DriverEntry->LoadedImage->FilePath = NULL; DriverEntry->LoadedImage->ImageBase = (VOID *)(UINTN)DriverEntry->ImageBuffer; DriverEntry->LoadedImage->ImageSize = ImageContext.ImageSize; @@ -395,12 +404,12 @@ MmLoadImage ( // Create a new image handle in the UEFI handle database for the MM Driver // DriverEntry->ImageHandle = NULL; - Status = mEfiSystemTable->BootServices->InstallMultipleProtocolInterfaces ( - &DriverEntry->ImageHandle, - &gEfiLoadedImageProtocolGuid, - DriverEntry->LoadedImage, - NULL - ); + Status = mEfiSystemTable->BootServices->InstallMultipleProtocolInterfaces ( + &DriverEntry->ImageHandle, + &gEfiLoadedImageProtocolGuid, + DriverEntry->LoadedImage, + NULL + ); } // @@ -408,14 +417,16 @@ MmLoadImage ( // DEBUG_CODE_BEGIN (); - UINTN Index; - UINTN StartIndex; - CHAR8 EfiFileName[256]; + UINTN Index; + UINTN StartIndex; + CHAR8 EfiFileName[256]; - DEBUG ((DEBUG_INFO | DEBUG_LOAD, - "Loading MM driver at 0x%11p EntryPoint=0x%11p ", - (VOID *)(UINTN) ImageContext.ImageAddress, - FUNCTION_ENTRY_POINT (ImageContext.EntryPoint))); + DEBUG (( + DEBUG_INFO | DEBUG_LOAD, + "Loading MM driver at 0x%11p EntryPoint=0x%11p ", + (VOID *)(UINTN)ImageContext.ImageAddress, + FUNCTION_ENTRY_POINT (ImageContext.EntryPoint) + )); // // Print Module Name by Pdb file path. @@ -439,6 +450,7 @@ MmLoadImage ( if (EfiFileName[Index] == 0) { EfiFileName[Index] = '.'; } + if (EfiFileName[Index] == '.') { EfiFileName[Index + 1] = 'e'; EfiFileName[Index + 2] = 'f'; @@ -451,8 +463,10 @@ MmLoadImage ( if (Index == sizeof (EfiFileName) - 4) { EfiFileName[Index] = 0; } + DEBUG ((DEBUG_INFO | DEBUG_LOAD, "%a", EfiFileName)); } + DEBUG ((DEBUG_INFO | DEBUG_LOAD, "\n")); DEBUG_CODE_END (); @@ -477,7 +491,7 @@ MmPreProcessDepex ( { UINT8 *Iterator; - Iterator = DriverEntry->Depex; + Iterator = DriverEntry->Depex; DriverEntry->Dependent = TRUE; if (*Iterator == EFI_DEP_BEFORE) { @@ -510,7 +524,7 @@ MmGetDepexSectionAndPreProccess ( IN EFI_MM_DRIVER_ENTRY *DriverEntry ) { - EFI_STATUS Status; + EFI_STATUS Status; // // Data already read @@ -520,6 +534,7 @@ MmGetDepexSectionAndPreProccess ( } else { Status = EFI_SUCCESS; } + if (EFI_ERROR (Status)) { if (Status == EFI_PROTOCOL_ERROR) { // @@ -530,8 +545,8 @@ MmGetDepexSectionAndPreProccess ( // // If no Depex assume depend on all architectural protocols // - DriverEntry->Depex = NULL; - DriverEntry->Dependent = TRUE; + DriverEntry->Depex = NULL; + DriverEntry->Dependent = TRUE; DriverEntry->DepexProtocolError = FALSE; } } else { @@ -567,10 +582,10 @@ MmDispatcher ( VOID ) { - EFI_STATUS Status; - LIST_ENTRY *Link; + EFI_STATUS Status; + LIST_ENTRY *Link; EFI_MM_DRIVER_ENTRY *DriverEntry; - BOOLEAN ReadyToRun; + BOOLEAN ReadyToRun; DEBUG ((DEBUG_INFO, "MmDispatcher\n")); @@ -619,8 +634,8 @@ MmDispatcher ( // The MM Driver could not be loaded, and do not attempt to load or start it again. // Take driver from Scheduled to Initialized. // - DriverEntry->Initialized = TRUE; - DriverEntry->Scheduled = FALSE; + DriverEntry->Initialized = TRUE; + DriverEntry->Scheduled = FALSE; RemoveEntryList (&DriverEntry->ScheduledLink); // @@ -630,8 +645,8 @@ MmDispatcher ( } } - DriverEntry->Scheduled = FALSE; - DriverEntry->Initialized = TRUE; + DriverEntry->Scheduled = FALSE; + DriverEntry->Initialized = TRUE; RemoveEntryList (&DriverEntry->ScheduledLink); // @@ -639,17 +654,18 @@ MmDispatcher ( // if (mEfiSystemTable == NULL) { DEBUG ((DEBUG_INFO, "StartImage - 0x%x (Standalone Mode)\n", DriverEntry->ImageEntryPoint)); - Status = ((MM_IMAGE_ENTRY_POINT)(UINTN)DriverEntry->ImageEntryPoint) (DriverEntry->ImageHandle, &gMmCoreMmst); + Status = ((MM_IMAGE_ENTRY_POINT)(UINTN)DriverEntry->ImageEntryPoint)(DriverEntry->ImageHandle, &gMmCoreMmst); } else { DEBUG ((DEBUG_INFO, "StartImage - 0x%x (Tradition Mode)\n", DriverEntry->ImageEntryPoint)); - Status = ((EFI_IMAGE_ENTRY_POINT)(UINTN)DriverEntry->ImageEntryPoint) ( - DriverEntry->ImageHandle, - mEfiSystemTable - ); + Status = ((EFI_IMAGE_ENTRY_POINT)(UINTN)DriverEntry->ImageEntryPoint)( + DriverEntry->ImageHandle, + mEfiSystemTable + ); } - if (EFI_ERROR(Status)) { + + if (EFI_ERROR (Status)) { DEBUG ((DEBUG_INFO, "StartImage Status - %r\n", Status)); - MmFreePages(DriverEntry->ImageBuffer, DriverEntry->NumberOfPage); + MmFreePages (DriverEntry->ImageBuffer, DriverEntry->NumberOfPage); } } @@ -714,18 +730,18 @@ MmDispatcher ( **/ VOID MmInsertOnScheduledQueueWhileProcessingBeforeAndAfter ( - IN EFI_MM_DRIVER_ENTRY *InsertedDriverEntry + IN EFI_MM_DRIVER_ENTRY *InsertedDriverEntry ) { - LIST_ENTRY *Link; - EFI_MM_DRIVER_ENTRY *DriverEntry; + LIST_ENTRY *Link; + EFI_MM_DRIVER_ENTRY *DriverEntry; // // Process Before Dependency // for (Link = mDiscoveredList.ForwardLink; Link != &mDiscoveredList; Link = Link->ForwardLink) { - DriverEntry = CR(Link, EFI_MM_DRIVER_ENTRY, Link, EFI_MM_DRIVER_ENTRY_SIGNATURE); - if (DriverEntry->Before && DriverEntry->Dependent && DriverEntry != InsertedDriverEntry) { + DriverEntry = CR (Link, EFI_MM_DRIVER_ENTRY, Link, EFI_MM_DRIVER_ENTRY_SIGNATURE); + if (DriverEntry->Before && DriverEntry->Dependent && (DriverEntry != InsertedDriverEntry)) { DEBUG ((DEBUG_DISPATCH, "Evaluate MM DEPEX for FFS(%g)\n", &DriverEntry->FileName)); DEBUG ((DEBUG_DISPATCH, " BEFORE FFS(%g) = ", &DriverEntry->BeforeAfterGuid)); if (CompareGuid (&InsertedDriverEntry->FileName, &DriverEntry->BeforeAfterGuid)) { @@ -748,13 +764,12 @@ MmInsertOnScheduledQueueWhileProcessingBeforeAndAfter ( InsertedDriverEntry->Scheduled = TRUE; InsertTailList (&mScheduledQueue, &InsertedDriverEntry->ScheduledLink); - // // Process After Dependency // for (Link = mDiscoveredList.ForwardLink; Link != &mDiscoveredList; Link = Link->ForwardLink) { - DriverEntry = CR(Link, EFI_MM_DRIVER_ENTRY, Link, EFI_MM_DRIVER_ENTRY_SIGNATURE); - if (DriverEntry->After && DriverEntry->Dependent && DriverEntry != InsertedDriverEntry) { + DriverEntry = CR (Link, EFI_MM_DRIVER_ENTRY, Link, EFI_MM_DRIVER_ENTRY_SIGNATURE); + if (DriverEntry->After && DriverEntry->Dependent && (DriverEntry != InsertedDriverEntry)) { DEBUG ((DEBUG_DISPATCH, "Evaluate MM DEPEX for FFS(%g)\n", &DriverEntry->FileName)); DEBUG ((DEBUG_DISPATCH, " AFTER FFS(%g) = ", &DriverEntry->BeforeAfterGuid)); if (CompareGuid (&InsertedDriverEntry->FileName, &DriverEntry->BeforeAfterGuid)) { @@ -784,20 +799,22 @@ MmInsertOnScheduledQueueWhileProcessingBeforeAndAfter ( **/ BOOLEAN FvHasBeenProcessed ( - IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader + IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader ) { - LIST_ENTRY *Link; - KNOWN_FWVOL *KnownFwVol; + LIST_ENTRY *Link; + KNOWN_FWVOL *KnownFwVol; for (Link = mFwVolList.ForwardLink; Link != &mFwVolList; - Link = Link->ForwardLink) { + Link = Link->ForwardLink) + { KnownFwVol = CR (Link, KNOWN_FWVOL, Link, KNOWN_FWVOL_SIGNATURE); if (KnownFwVol->FwVolHeader == FwVolHeader) { return TRUE; } } + return FALSE; } @@ -812,17 +829,17 @@ FvHasBeenProcessed ( **/ VOID FvIsBeingProcessed ( - IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader + IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader ) { - KNOWN_FWVOL *KnownFwVol; + KNOWN_FWVOL *KnownFwVol; DEBUG ((DEBUG_INFO, "FvIsBeingProcessed - 0x%08x\n", FwVolHeader)); KnownFwVol = AllocatePool (sizeof (KNOWN_FWVOL)); ASSERT (KnownFwVol != NULL); - KnownFwVol->Signature = KNOWN_FWVOL_SIGNATURE; + KnownFwVol->Signature = KNOWN_FWVOL_SIGNATURE; KnownFwVol->FwVolHeader = FwVolHeader; InsertTailList (&mFwVolList, &KnownFwVol->Link); } @@ -845,12 +862,12 @@ FvIsBeingProcessed ( **/ EFI_STATUS MmAddToDriverList ( - IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader, - IN VOID *Pe32Data, - IN UINTN Pe32DataSize, - IN VOID *Depex, - IN UINTN DepexSize, - IN EFI_GUID *DriverName + IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader, + IN VOID *Pe32Data, + IN UINTN Pe32DataSize, + IN VOID *Depex, + IN UINTN DepexSize, + IN EFI_GUID *DriverName ) { EFI_MM_DRIVER_ENTRY *DriverEntry; @@ -864,13 +881,13 @@ MmAddToDriverList ( DriverEntry = AllocateZeroPool (sizeof (EFI_MM_DRIVER_ENTRY)); ASSERT (DriverEntry != NULL); - DriverEntry->Signature = EFI_MM_DRIVER_ENTRY_SIGNATURE; + DriverEntry->Signature = EFI_MM_DRIVER_ENTRY_SIGNATURE; CopyGuid (&DriverEntry->FileName, DriverName); - DriverEntry->FwVolHeader = FwVolHeader; - DriverEntry->Pe32Data = Pe32Data; - DriverEntry->Pe32DataSize = Pe32DataSize; - DriverEntry->Depex = Depex; - DriverEntry->DepexSize = DepexSize; + DriverEntry->FwVolHeader = FwVolHeader; + DriverEntry->Pe32Data = Pe32Data; + DriverEntry->Pe32DataSize = Pe32DataSize; + DriverEntry->Depex = Depex; + DriverEntry->DepexSize = DepexSize; MmGetDepexSectionAndPreProccess (DriverEntry); @@ -890,10 +907,10 @@ MmDisplayDiscoveredNotDispatched ( VOID ) { - LIST_ENTRY *Link; - EFI_MM_DRIVER_ENTRY *DriverEntry; + LIST_ENTRY *Link; + EFI_MM_DRIVER_ENTRY *DriverEntry; - for (Link = mDiscoveredList.ForwardLink;Link !=&mDiscoveredList; Link = Link->ForwardLink) { + for (Link = mDiscoveredList.ForwardLink; Link != &mDiscoveredList; Link = Link->ForwardLink) { DriverEntry = CR (Link, EFI_MM_DRIVER_ENTRY, Link, EFI_MM_DRIVER_ENTRY_SIGNATURE); if (DriverEntry->Dependent) { DEBUG ((DEBUG_LOAD, "MM Driver %g was discovered but not loaded!!\n", &DriverEntry->FileName)); diff --git a/StandaloneMmPkg/Core/FwVol.c b/StandaloneMmPkg/Core/FwVol.c index 70cb8e71df..1f6d7714ba 100644 --- a/StandaloneMmPkg/Core/FwVol.c +++ b/StandaloneMmPkg/Core/FwVol.c @@ -14,9 +14,9 @@ // // List of file types supported by dispatcher // -EFI_FV_FILETYPE mMmFileTypes[] = { +EFI_FV_FILETYPE mMmFileTypes[] = { EFI_FV_FILETYPE_MM, - 0xE, //EFI_FV_FILETYPE_MM_STANDALONE, + 0xE, // EFI_FV_FILETYPE_MM_STANDALONE, // // Note: DXE core will process the FV image file, so skip it in MM core // EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE @@ -25,22 +25,22 @@ EFI_FV_FILETYPE mMmFileTypes[] = { EFI_STATUS MmAddToDriverList ( - IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader, - IN VOID *Pe32Data, - IN UINTN Pe32DataSize, - IN VOID *Depex, - IN UINTN DepexSize, - IN EFI_GUID *DriverName + IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader, + IN VOID *Pe32Data, + IN UINTN Pe32DataSize, + IN VOID *Depex, + IN UINTN DepexSize, + IN EFI_GUID *DriverName ); BOOLEAN FvHasBeenProcessed ( - IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader + IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader ); VOID FvIsBeingProcessed ( - IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader + IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader ); /** @@ -62,25 +62,25 @@ MmCoreFfsFindMmDriver ( IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader ) { - EFI_STATUS Status; - EFI_STATUS DepexStatus; - EFI_FFS_FILE_HEADER *FileHeader; - EFI_FV_FILETYPE FileType; - VOID *Pe32Data; - UINTN Pe32DataSize; - VOID *Depex; - UINTN DepexSize; - UINTN Index; - EFI_COMMON_SECTION_HEADER *Section; - VOID *SectionData; - UINTN SectionDataSize; - UINT32 DstBufferSize; - VOID *ScratchBuffer; - UINT32 ScratchBufferSize; - VOID *DstBuffer; - UINT16 SectionAttribute; - UINT32 AuthenticationStatus; - EFI_FIRMWARE_VOLUME_HEADER *InnerFvHeader; + EFI_STATUS Status; + EFI_STATUS DepexStatus; + EFI_FFS_FILE_HEADER *FileHeader; + EFI_FV_FILETYPE FileType; + VOID *Pe32Data; + UINTN Pe32DataSize; + VOID *Depex; + UINTN DepexSize; + UINTN Index; + EFI_COMMON_SECTION_HEADER *Section; + VOID *SectionData; + UINTN SectionDataSize; + UINT32 DstBufferSize; + VOID *ScratchBuffer; + UINT32 ScratchBufferSize; + VOID *DstBuffer; + UINT16 SectionAttribute; + UINT32 AuthenticationStatus; + EFI_FIRMWARE_VOLUME_HEADER *InnerFvHeader; DEBUG ((DEBUG_INFO, "MmCoreFfsFindMmDriver - 0x%x\n", FwVolHeader)); @@ -95,19 +95,32 @@ MmCoreFfsFindMmDriver ( // FileHeader = NULL; do { - Status = FfsFindNextFile (EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE, - FwVolHeader, &FileHeader); + Status = FfsFindNextFile ( + EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE, + FwVolHeader, + &FileHeader + ); if (EFI_ERROR (Status)) { break; } - Status = FfsFindSectionData (EFI_SECTION_GUID_DEFINED, FileHeader, - &SectionData, &SectionDataSize); + + Status = FfsFindSectionData ( + EFI_SECTION_GUID_DEFINED, + FileHeader, + &SectionData, + &SectionDataSize + ); if (EFI_ERROR (Status)) { break; } + Section = (EFI_COMMON_SECTION_HEADER *)(FileHeader + 1); - Status = ExtractGuidedSectionGetInfo (Section, &DstBufferSize, - &ScratchBufferSize, &SectionAttribute); + Status = ExtractGuidedSectionGetInfo ( + Section, + &DstBufferSize, + &ScratchBufferSize, + &SectionAttribute + ); if (EFI_ERROR (Status)) { break; } @@ -131,25 +144,35 @@ MmCoreFfsFindMmDriver ( // // Call decompress function // - Status = ExtractGuidedSectionDecode (Section, &DstBuffer, ScratchBuffer, - &AuthenticationStatus); + Status = ExtractGuidedSectionDecode ( + Section, + &DstBuffer, + ScratchBuffer, + &AuthenticationStatus + ); FreePages (ScratchBuffer, EFI_SIZE_TO_PAGES (ScratchBufferSize)); if (EFI_ERROR (Status)) { goto FreeDstBuffer; } - DEBUG ((DEBUG_INFO, + DEBUG (( + DEBUG_INFO, "Processing compressed firmware volume (AuthenticationStatus == %x)\n", - AuthenticationStatus)); - - Status = FindFfsSectionInSections (DstBuffer, DstBufferSize, - EFI_SECTION_FIRMWARE_VOLUME_IMAGE, &Section); + AuthenticationStatus + )); + + Status = FindFfsSectionInSections ( + DstBuffer, + DstBufferSize, + EFI_SECTION_FIRMWARE_VOLUME_IMAGE, + &Section + ); if (EFI_ERROR (Status)) { goto FreeDstBuffer; } InnerFvHeader = (VOID *)(Section + 1); - Status = MmCoreFfsFindMmDriver (InnerFvHeader); + Status = MmCoreFfsFindMmDriver (InnerFvHeader); if (EFI_ERROR (Status)) { goto FreeDstBuffer; } @@ -157,7 +180,7 @@ MmCoreFfsFindMmDriver ( for (Index = 0; Index < sizeof (mMmFileTypes) / sizeof (mMmFileTypes[0]); Index++) { DEBUG ((DEBUG_INFO, "Check MmFileTypes - 0x%x\n", mMmFileTypes[Index])); - FileType = mMmFileTypes[Index]; + FileType = mMmFileTypes[Index]; FileHeader = NULL; do { Status = FfsFindNextFile (FileType, FwVolHeader, &FileHeader); diff --git a/StandaloneMmPkg/Core/Handle.c b/StandaloneMmPkg/Core/Handle.c index 3a9cec7a70..7df4629cf2 100644 --- a/StandaloneMmPkg/Core/Handle.c +++ b/StandaloneMmPkg/Core/Handle.c @@ -13,8 +13,8 @@ // mProtocolDatabase - A list of all protocols in the system. (simple list for now) // gHandleList - A list of all the handles in the system // -LIST_ENTRY mProtocolDatabase = INITIALIZE_LIST_HEAD_VARIABLE (mProtocolDatabase); -LIST_ENTRY gHandleList = INITIALIZE_LIST_HEAD_VARIABLE (gHandleList); +LIST_ENTRY mProtocolDatabase = INITIALIZE_LIST_HEAD_VARIABLE (mProtocolDatabase); +LIST_ENTRY gHandleList = INITIALIZE_LIST_HEAD_VARIABLE (gHandleList); /** Check whether a handle is a valid EFI_HANDLE @@ -36,9 +36,11 @@ MmValidateHandle ( if (Handle == NULL) { return EFI_INVALID_PARAMETER; } + if (Handle->Signature != EFI_HANDLE_SIGNATURE) { return EFI_INVALID_PARAMETER; } + return EFI_SUCCESS; } @@ -53,13 +55,13 @@ MmValidateHandle ( **/ PROTOCOL_ENTRY * MmFindProtocolEntry ( - IN EFI_GUID *Protocol, - IN BOOLEAN Create + IN EFI_GUID *Protocol, + IN BOOLEAN Create ) { - LIST_ENTRY *Link; - PROTOCOL_ENTRY *Item; - PROTOCOL_ENTRY *ProtEntry; + LIST_ENTRY *Link; + PROTOCOL_ENTRY *Item; + PROTOCOL_ENTRY *ProtEntry; // // Search the database for the matching GUID @@ -68,8 +70,8 @@ MmFindProtocolEntry ( ProtEntry = NULL; for (Link = mProtocolDatabase.ForwardLink; Link != &mProtocolDatabase; - Link = Link->ForwardLink) { - + Link = Link->ForwardLink) + { Item = CR (Link, PROTOCOL_ENTRY, AllEntries, PROTOCOL_ENTRY_SIGNATURE); if (CompareGuid (&Item->ProtocolID, Protocol)) { // @@ -85,7 +87,7 @@ MmFindProtocolEntry ( // allocate a new entry // if ((ProtEntry == NULL) && Create) { - ProtEntry = AllocatePool (sizeof(PROTOCOL_ENTRY)); + ProtEntry = AllocatePool (sizeof (PROTOCOL_ENTRY)); if (ProtEntry != NULL) { // // Initialize new protocol entry structure @@ -101,6 +103,7 @@ MmFindProtocolEntry ( InsertTailList (&mProtocolDatabase, &ProtEntry->AllEntries); } } + return ProtEntry; } @@ -137,17 +140,19 @@ MmFindProtocolInterface ( // // Look at each protocol interface for any matches // - for (Link = Handle->Protocols.ForwardLink; Link != &Handle->Protocols; Link=Link->ForwardLink) { + for (Link = Handle->Protocols.ForwardLink; Link != &Handle->Protocols; Link = Link->ForwardLink) { // // If this protocol interface matches, remove it // Prot = CR (Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_SIGNATURE); - if (Prot->Interface == Interface && Prot->Protocol == ProtEntry) { + if ((Prot->Interface == Interface) && (Prot->Protocol == ProtEntry)) { break; } + Prot = NULL; } } + return Prot; } @@ -219,7 +224,7 @@ MmInstallProtocolInterfaceNotify ( // returns EFI_INVALID_PARAMETER if InterfaceType is invalid. // Also added check for invalid UserHandle and Protocol pointers. // - if (UserHandle == NULL || Protocol == NULL) { + if ((UserHandle == NULL) || (Protocol == NULL)) { return EFI_INVALID_PARAMETER; } @@ -233,7 +238,7 @@ MmInstallProtocolInterfaceNotify ( DEBUG ((DEBUG_LOAD | DEBUG_INFO, "MmInstallProtocolInterface: %g %p\n", Protocol, Interface)); Status = EFI_OUT_OF_RESOURCES; - Prot = NULL; + Prot = NULL; Handle = NULL; if (*UserHandle != NULL) { @@ -298,8 +303,8 @@ MmInstallProtocolInterfaceNotify ( // Initialize the protocol interface structure // Prot->Signature = PROTOCOL_INTERFACE_SIGNATURE; - Prot->Handle = Handle; - Prot->Protocol = ProtEntry; + Prot->Handle = Handle; + Prot->Protocol = ProtEntry; Prot->Interface = Interface; // @@ -320,6 +325,7 @@ MmInstallProtocolInterfaceNotify ( if (Notify) { MmNotifyProtocol (Prot); } + Status = EFI_SUCCESS; Done: @@ -336,6 +342,7 @@ Done: FreePool (Prot); } } + return Status; } @@ -416,6 +423,7 @@ MmUninstallProtocolInterface ( RemoveEntryList (&Handle->AllHandles); FreePool (Handle); } + return Status; } @@ -451,12 +459,13 @@ MmGetProtocolInterface ( // Look at each protocol interface for a match // for (Link = Handle->Protocols.ForwardLink; Link != &Handle->Protocols; Link = Link->ForwardLink) { - Prot = CR (Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_SIGNATURE); + Prot = CR (Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_SIGNATURE); ProtEntry = Prot->Protocol; if (CompareGuid (&ProtEntry->ProtocolID, Protocol)) { return Prot; } } + return NULL; } diff --git a/StandaloneMmPkg/Core/InstallConfigurationTable.c b/StandaloneMmPkg/Core/InstallConfigurationTable.c index b3fc0efc4b..a4a2de7cd3 100644 --- a/StandaloneMmPkg/Core/InstallConfigurationTable.c +++ b/StandaloneMmPkg/Core/InstallConfigurationTable.c @@ -9,7 +9,7 @@ #include "StandaloneMmCore.h" -#define CONFIG_TABLE_SIZE_INCREASED 0x10 +#define CONFIG_TABLE_SIZE_INCREASED 0x10 UINTN mMmSystemTableAllocateSize = 0; @@ -33,10 +33,10 @@ UINTN mMmSystemTableAllocateSize = 0; EFI_STATUS EFIAPI MmInstallConfigurationTable ( - IN CONST EFI_MM_SYSTEM_TABLE *SystemTable, - IN CONST EFI_GUID *Guid, - IN VOID *Table, - IN UINTN TableSize + IN CONST EFI_MM_SYSTEM_TABLE *SystemTable, + IN CONST EFI_GUID *Guid, + IN VOID *Table, + IN UINTN TableSize ) { UINTN Index; @@ -87,7 +87,6 @@ MmInstallConfigurationTable ( &(ConfigurationTable[Index + 1]), (gMmCoreMmst.NumberOfTableEntries - Index) * sizeof (EFI_CONFIGURATION_TABLE) ); - } else { // // No matching GUIDs were found, so this is an add operation. @@ -107,7 +106,7 @@ MmInstallConfigurationTable ( // Allocate a table with one additional entry. // mMmSystemTableAllocateSize += (CONFIG_TABLE_SIZE_INCREASED * sizeof (EFI_CONFIGURATION_TABLE)); - ConfigurationTable = AllocatePool (mMmSystemTableAllocateSize); + ConfigurationTable = AllocatePool (mMmSystemTableAllocateSize); if (ConfigurationTable == NULL) { // // If a new table could not be allocated, then return an error. diff --git a/StandaloneMmPkg/Core/Locate.c b/StandaloneMmPkg/Core/Locate.c index 95c40ca7be..0cf04b9c8d 100644 --- a/StandaloneMmPkg/Core/Locate.c +++ b/StandaloneMmPkg/Core/Locate.c @@ -12,24 +12,24 @@ // // ProtocolRequest - Last LocateHandle request ID // -UINTN mEfiLocateHandleRequest = 0; +UINTN mEfiLocateHandleRequest = 0; // // Internal prototypes // typedef struct { - EFI_GUID *Protocol; - VOID *SearchKey; - LIST_ENTRY *Position; - PROTOCOL_ENTRY *ProtEntry; + EFI_GUID *Protocol; + VOID *SearchKey; + LIST_ENTRY *Position; + PROTOCOL_ENTRY *ProtEntry; } LOCATE_POSITION; typedef IHANDLE * -(* CORE_GET_NEXT) ( - IN OUT LOCATE_POSITION *Position, - OUT VOID **Interface +(*CORE_GET_NEXT) ( + IN OUT LOCATE_POSITION *Position, + OUT VOID **Interface ); /** @@ -49,7 +49,7 @@ MmGetNextLocateAllHandles ( OUT VOID **Interface ) { - IHANDLE *Handle; + IHANDLE *Handle; // // Next handle @@ -59,11 +59,12 @@ MmGetNextLocateAllHandles ( // // If not at the end of the list, get the handle // - Handle = NULL; - *Interface = NULL; + Handle = NULL; + *Interface = NULL; if (Position->Position != &gHandleList) { Handle = CR (Position->Position, IHANDLE, AllHandles, EFI_HANDLE_SIGNATURE); } + return Handle; } @@ -90,8 +91,8 @@ MmGetNextLocateByRegisterNotify ( PROTOCOL_INTERFACE *Prot; LIST_ENTRY *Link; - Handle = NULL; - *Interface = NULL; + Handle = NULL; + *Interface = NULL; ProtNotify = Position->SearchKey; // @@ -106,11 +107,12 @@ MmGetNextLocateByRegisterNotify ( // Link = ProtNotify->Position->ForwardLink; if (Link != &ProtNotify->Protocol->Protocols) { - Prot = CR (Link, PROTOCOL_INTERFACE, ByProtocol, PROTOCOL_INTERFACE_SIGNATURE); - Handle = Prot->Handle; + Prot = CR (Link, PROTOCOL_INTERFACE, ByProtocol, PROTOCOL_INTERFACE_SIGNATURE); + Handle = Prot->Handle; *Interface = Prot->Interface; } } + return Handle; } @@ -135,13 +137,13 @@ MmGetNextLocateByProtocol ( LIST_ENTRY *Link; PROTOCOL_INTERFACE *Prot; - Handle = NULL; - *Interface = NULL; - for (; ;) { + Handle = NULL; + *Interface = NULL; + for ( ; ;) { // // Next entry // - Link = Position->Position->ForwardLink; + Link = Position->Position->ForwardLink; Position->Position = Link; // @@ -155,8 +157,8 @@ MmGetNextLocateByProtocol ( // // Get the handle // - Prot = CR (Link, PROTOCOL_INTERFACE, ByProtocol, PROTOCOL_INTERFACE_SIGNATURE); - Handle = Prot->Handle; + Prot = CR (Link, PROTOCOL_INTERFACE, ByProtocol, PROTOCOL_INTERFACE_SIGNATURE); + Handle = Prot->Handle; *Interface = Prot->Interface; // @@ -168,6 +170,7 @@ MmGetNextLocateByProtocol ( break; } } + return Handle; } @@ -195,17 +198,17 @@ MmLocateProtocol ( OUT VOID **Interface ) { - EFI_STATUS Status; - LOCATE_POSITION Position; - PROTOCOL_NOTIFY *ProtNotify; - IHANDLE *Handle; + EFI_STATUS Status; + LOCATE_POSITION Position; + PROTOCOL_NOTIFY *ProtNotify; + IHANDLE *Handle; if ((Interface == NULL) || (Protocol == NULL)) { return EFI_INVALID_PARAMETER; } *Interface = NULL; - Status = EFI_SUCCESS; + Status = EFI_SUCCESS; // // Set initial position @@ -224,6 +227,7 @@ MmLocateProtocol ( if (Position.ProtEntry == NULL) { return EFI_NOT_FOUND; } + Position.Position = &Position.ProtEntry->Protocols; Handle = MmGetNextLocateByProtocol (&Position, Interface); @@ -238,7 +242,7 @@ MmLocateProtocol ( // If this is a search by register notify and a handle was // returned, update the register notification position // - ProtNotify = Registration; + ProtNotify = Registration; ProtNotify->Position = ProtNotify->Position->ForwardLink; } @@ -299,48 +303,51 @@ MmLocateHandle ( Position.SearchKey = SearchKey; Position.Position = &gHandleList; - ResultSize = 0; - ResultBuffer = (IHANDLE **) Buffer; - Status = EFI_SUCCESS; + ResultSize = 0; + ResultBuffer = (IHANDLE **)Buffer; + Status = EFI_SUCCESS; // // Get the search function based on type // switch (SearchType) { - case AllHandles: - GetNext = MmGetNextLocateAllHandles; - break; + case AllHandles: + GetNext = MmGetNextLocateAllHandles; + break; - case ByRegisterNotify: - GetNext = MmGetNextLocateByRegisterNotify; - // - // Must have SearchKey for locate ByRegisterNotify - // - if (SearchKey == NULL) { - Status = EFI_INVALID_PARAMETER; - } - break; + case ByRegisterNotify: + GetNext = MmGetNextLocateByRegisterNotify; + // + // Must have SearchKey for locate ByRegisterNotify + // + if (SearchKey == NULL) { + Status = EFI_INVALID_PARAMETER; + } - case ByProtocol: - GetNext = MmGetNextLocateByProtocol; - if (Protocol == NULL) { - Status = EFI_INVALID_PARAMETER; break; - } - // - // Look up the protocol entry and set the head pointer - // - Position.ProtEntry = MmFindProtocolEntry (Protocol, FALSE); - if (Position.ProtEntry == NULL) { - Status = EFI_NOT_FOUND; + + case ByProtocol: + GetNext = MmGetNextLocateByProtocol; + if (Protocol == NULL) { + Status = EFI_INVALID_PARAMETER; + break; + } + + // + // Look up the protocol entry and set the head pointer + // + Position.ProtEntry = MmFindProtocolEntry (Protocol, FALSE); + if (Position.ProtEntry == NULL) { + Status = EFI_NOT_FOUND; + break; + } + + Position.Position = &Position.ProtEntry->Protocols; break; - } - Position.Position = &Position.ProtEntry->Protocols; - break; - default: - Status = EFI_INVALID_PARAMETER; - break; + default: + Status = EFI_INVALID_PARAMETER; + break; } if (EFI_ERROR (Status)) { @@ -351,7 +358,7 @@ MmLocateHandle ( // Enumerate out the matching handles // mEfiLocateHandleRequest += 1; - for (; ;) { + for ( ; ;) { // // Get the next handle. If no more handles, stop // @@ -366,8 +373,8 @@ MmLocateHandle ( // ResultSize += sizeof (Handle); if (ResultSize <= *BufferSize) { - *ResultBuffer = Handle; - ResultBuffer += 1; + *ResultBuffer = Handle; + ResultBuffer += 1; } } @@ -388,13 +395,13 @@ MmLocateHandle ( *BufferSize = ResultSize; - if (SearchType == ByRegisterNotify && !EFI_ERROR (Status)) { + if ((SearchType == ByRegisterNotify) && !EFI_ERROR (Status)) { ASSERT (SearchKey != NULL); // // If this is a search by register notify and a handle was // returned, update the register notification position // - ProtNotify = SearchKey; + ProtNotify = SearchKey; ProtNotify->Position = ProtNotify->Position->ForwardLink; } } @@ -445,26 +452,27 @@ MmLocateHandleBuffer ( return EFI_INVALID_PARAMETER; } - BufferSize = 0; + BufferSize = 0; *NumberHandles = 0; - *Buffer = NULL; - Status = MmLocateHandle ( - SearchType, - Protocol, - SearchKey, - &BufferSize, - *Buffer - ); + *Buffer = NULL; + Status = MmLocateHandle ( + SearchType, + Protocol, + SearchKey, + &BufferSize, + *Buffer + ); // // LocateHandleBuffer() returns incorrect status code if SearchType is // invalid. // // Add code to correctly handle expected errors from MmLocateHandle(). // - if (EFI_ERROR (Status) && Status != EFI_BUFFER_TOO_SMALL) { + if (EFI_ERROR (Status) && (Status != EFI_BUFFER_TOO_SMALL)) { if (Status != EFI_INVALID_PARAMETER) { Status = EFI_NOT_FOUND; } + return Status; } @@ -481,7 +489,7 @@ MmLocateHandleBuffer ( *Buffer ); - *NumberHandles = BufferSize / sizeof(EFI_HANDLE); + *NumberHandles = BufferSize / sizeof (EFI_HANDLE); if (EFI_ERROR (Status)) { *NumberHandles = 0; } diff --git a/StandaloneMmPkg/Core/Mmi.c b/StandaloneMmPkg/Core/Mmi.c index fed8480020..8252355a48 100644 --- a/StandaloneMmPkg/Core/Mmi.c +++ b/StandaloneMmPkg/Core/Mmi.c @@ -20,11 +20,11 @@ #define MMI_ENTRY_SIGNATURE SIGNATURE_32('m','m','i','e') typedef struct { - UINTN Signature; - LIST_ENTRY AllEntries; // All entries + UINTN Signature; + LIST_ENTRY AllEntries; // All entries - EFI_GUID HandlerType; // Type of interrupt - LIST_ENTRY MmiHandlers; // All handlers + EFI_GUID HandlerType; // Type of interrupt + LIST_ENTRY MmiHandlers; // All handlers } MMI_ENTRY; #define MMI_HANDLER_SIGNATURE SIGNATURE_32('m','m','i','h') @@ -65,8 +65,8 @@ MmCoreFindMmiEntry ( MmiEntry = NULL; for (Link = mMmiEntryList.ForwardLink; Link != &mMmiEntryList; - Link = Link->ForwardLink) { - + Link = Link->ForwardLink) + { Item = CR (Link, MMI_ENTRY, AllEntries, MMI_ENTRY_SIGNATURE); if (CompareGuid (&Item->HandlerType, HandlerType)) { // @@ -97,6 +97,7 @@ MmCoreFindMmiEntry ( InsertTailList (&mMmiEntryList, &MmiEntry->AllEntries); } } + return MmiEntry; } @@ -130,7 +131,7 @@ MmiManage ( BOOLEAN SuccessReturn; EFI_STATUS Status; - Status = EFI_NOT_FOUND; + Status = EFI_NOT_FOUND; SuccessReturn = FALSE; if (HandlerType == NULL) { // @@ -142,7 +143,7 @@ MmiManage ( // // Non-root MMI handler // - MmiEntry = MmCoreFindMmiEntry ((EFI_GUID *) HandlerType, FALSE); + MmiEntry = MmCoreFindMmiEntry ((EFI_GUID *)HandlerType, FALSE); if (MmiEntry == NULL) { // // There is no handler registered for this interrupt source @@ -157,56 +158,58 @@ MmiManage ( MmiHandler = CR (Link, MMI_HANDLER, Link, MMI_HANDLER_SIGNATURE); Status = MmiHandler->Handler ( - (EFI_HANDLE) MmiHandler, - Context, - CommBuffer, - CommBufferSize - ); + (EFI_HANDLE)MmiHandler, + Context, + CommBuffer, + CommBufferSize + ); switch (Status) { - case EFI_INTERRUPT_PENDING: - // - // If a handler returns EFI_INTERRUPT_PENDING and HandlerType is not NULL then - // no additional handlers will be processed and EFI_INTERRUPT_PENDING will be returned. - // - if (HandlerType != NULL) { - return EFI_INTERRUPT_PENDING; - } - break; - - case EFI_SUCCESS: - // - // If at least one of the handlers returns EFI_SUCCESS then the function will return - // EFI_SUCCESS. If a handler returns EFI_SUCCESS and HandlerType is not NULL then no - // additional handlers will be processed. - // - if (HandlerType != NULL) { - return EFI_SUCCESS; - } - SuccessReturn = TRUE; - break; - - case EFI_WARN_INTERRUPT_SOURCE_QUIESCED: - // - // If at least one of the handlers returns EFI_WARN_INTERRUPT_SOURCE_QUIESCED - // then the function will return EFI_SUCCESS. - // - SuccessReturn = TRUE; - break; - - case EFI_WARN_INTERRUPT_SOURCE_PENDING: - // - // If all the handlers returned EFI_WARN_INTERRUPT_SOURCE_PENDING - // then EFI_WARN_INTERRUPT_SOURCE_PENDING will be returned. - // - break; - - default: - // - // Unexpected status code returned. - // - ASSERT (FALSE); - break; + case EFI_INTERRUPT_PENDING: + // + // If a handler returns EFI_INTERRUPT_PENDING and HandlerType is not NULL then + // no additional handlers will be processed and EFI_INTERRUPT_PENDING will be returned. + // + if (HandlerType != NULL) { + return EFI_INTERRUPT_PENDING; + } + + break; + + case EFI_SUCCESS: + // + // If at least one of the handlers returns EFI_SUCCESS then the function will return + // EFI_SUCCESS. If a handler returns EFI_SUCCESS and HandlerType is not NULL then no + // additional handlers will be processed. + // + if (HandlerType != NULL) { + return EFI_SUCCESS; + } + + SuccessReturn = TRUE; + break; + + case EFI_WARN_INTERRUPT_SOURCE_QUIESCED: + // + // If at least one of the handlers returns EFI_WARN_INTERRUPT_SOURCE_QUIESCED + // then the function will return EFI_SUCCESS. + // + SuccessReturn = TRUE; + break; + + case EFI_WARN_INTERRUPT_SOURCE_PENDING: + // + // If all the handlers returned EFI_WARN_INTERRUPT_SOURCE_PENDING + // then EFI_WARN_INTERRUPT_SOURCE_PENDING will be returned. + // + break; + + default: + // + // Unexpected status code returned. + // + ASSERT (FALSE); + break; } } @@ -231,16 +234,16 @@ MmiManage ( EFI_STATUS EFIAPI MmiHandlerRegister ( - IN EFI_MM_HANDLER_ENTRY_POINT Handler, - IN CONST EFI_GUID *HandlerType OPTIONAL, - OUT EFI_HANDLE *DispatchHandle + IN EFI_MM_HANDLER_ENTRY_POINT Handler, + IN CONST EFI_GUID *HandlerType OPTIONAL, + OUT EFI_HANDLE *DispatchHandle ) { MMI_HANDLER *MmiHandler; MMI_ENTRY *MmiEntry; LIST_ENTRY *List; - if (Handler == NULL || DispatchHandle == NULL) { + if ((Handler == NULL) || (DispatchHandle == NULL)) { return EFI_INVALID_PARAMETER; } @@ -250,19 +253,19 @@ MmiHandlerRegister ( } MmiHandler->Signature = MMI_HANDLER_SIGNATURE; - MmiHandler->Handler = Handler; + MmiHandler->Handler = Handler; if (HandlerType == NULL) { // // This is root MMI handler // MmiEntry = NULL; - List = &mRootMmiHandlerList; + List = &mRootMmiHandlerList; } else { // // None root MMI handler // - MmiEntry = MmCoreFindMmiEntry ((EFI_GUID *) HandlerType, TRUE); + MmiEntry = MmCoreFindMmiEntry ((EFI_GUID *)HandlerType, TRUE); if (MmiEntry == NULL) { return EFI_OUT_OF_RESOURCES; } @@ -273,7 +276,7 @@ MmiHandlerRegister ( MmiHandler->MmiEntry = MmiEntry; InsertTailList (List, &MmiHandler->Link); - *DispatchHandle = (EFI_HANDLE) MmiHandler; + *DispatchHandle = (EFI_HANDLE)MmiHandler; return EFI_SUCCESS; } @@ -296,7 +299,7 @@ MmiHandlerUnRegister ( MMI_HANDLER *MmiHandler; MMI_ENTRY *MmiEntry; - MmiHandler = (MMI_HANDLER *) DispatchHandle; + MmiHandler = (MMI_HANDLER *)DispatchHandle; if (MmiHandler == NULL) { return EFI_INVALID_PARAMETER; diff --git a/StandaloneMmPkg/Core/Notify.c b/StandaloneMmPkg/Core/Notify.c index 9aafd635f4..83e4f3ab4c 100644 --- a/StandaloneMmPkg/Core/Notify.c +++ b/StandaloneMmPkg/Core/Notify.c @@ -25,7 +25,7 @@ MmNotifyProtocol ( LIST_ENTRY *Link; ProtEntry = Prot->Protocol; - for (Link=ProtEntry->Notify.ForwardLink; Link != &ProtEntry->Notify; Link=Link->ForwardLink) { + for (Link = ProtEntry->Notify.ForwardLink; Link != &ProtEntry->Notify; Link = Link->ForwardLink) { ProtNotify = CR (Link, PROTOCOL_NOTIFY, Link, PROTOCOL_NOTIFY_SIGNATURE); ProtNotify->Function (&ProtEntry->ProtocolID, Prot->Interface, Prot->Handle); } @@ -55,7 +55,6 @@ MmRemoveInterfaceFromProtocol ( Prot = MmFindProtocolInterface (Handle, Protocol, Interface); if (Prot != NULL) { - ProtEntry = Prot->Protocol; // @@ -96,9 +95,9 @@ MmRemoveInterfaceFromProtocol ( EFI_STATUS EFIAPI MmRegisterProtocolNotify ( - IN CONST EFI_GUID *Protocol, + IN CONST EFI_GUID *Protocol, IN EFI_MM_NOTIFY_FN Function, - OUT VOID **Registration + OUT VOID **Registration ) { PROTOCOL_ENTRY *ProtEntry; @@ -106,7 +105,7 @@ MmRegisterProtocolNotify ( LIST_ENTRY *Link; EFI_STATUS Status; - if (Protocol == NULL || Registration == NULL) { + if ((Protocol == NULL) || (Registration == NULL)) { return EFI_INVALID_PARAMETER; } @@ -114,12 +113,13 @@ MmRegisterProtocolNotify ( // // Get the protocol entry per Protocol // - ProtEntry = MmFindProtocolEntry ((EFI_GUID *) Protocol, FALSE); + ProtEntry = MmFindProtocolEntry ((EFI_GUID *)Protocol, FALSE); if (ProtEntry != NULL) { - ProtNotify = (PROTOCOL_NOTIFY * )*Registration; + ProtNotify = (PROTOCOL_NOTIFY *)*Registration; for (Link = ProtEntry->Notify.ForwardLink; Link != &ProtEntry->Notify; - Link = Link->ForwardLink) { + Link = Link->ForwardLink) + { // // Compare the notification record // @@ -134,6 +134,7 @@ MmRegisterProtocolNotify ( } } } + // // If the registration is not found // @@ -145,19 +146,19 @@ MmRegisterProtocolNotify ( // // Get the protocol entry to add the notification too // - ProtEntry = MmFindProtocolEntry ((EFI_GUID *) Protocol, TRUE); + ProtEntry = MmFindProtocolEntry ((EFI_GUID *)Protocol, TRUE); if (ProtEntry != NULL) { // // Find whether notification already exist // for (Link = ProtEntry->Notify.ForwardLink; Link != &ProtEntry->Notify; - Link = Link->ForwardLink) { - + Link = Link->ForwardLink) + { ProtNotify = CR (Link, PROTOCOL_NOTIFY, Link, PROTOCOL_NOTIFY_SIGNATURE); if (CompareGuid (&ProtNotify->Protocol->ProtocolID, Protocol) && - (ProtNotify->Function == Function)) { - + (ProtNotify->Function == Function)) + { // // Notification already exist // @@ -173,8 +174,8 @@ MmRegisterProtocolNotify ( ProtNotify = AllocatePool (sizeof (PROTOCOL_NOTIFY)); if (ProtNotify != NULL) { ProtNotify->Signature = PROTOCOL_NOTIFY_SIGNATURE; - ProtNotify->Protocol = ProtEntry; - ProtNotify->Function = Function; + ProtNotify->Protocol = ProtEntry; + ProtNotify->Function = Function; // // Start at the ending // @@ -191,7 +192,8 @@ MmRegisterProtocolNotify ( Status = EFI_OUT_OF_RESOURCES; if (ProtNotify != NULL) { *Registration = ProtNotify; - Status = EFI_SUCCESS; + Status = EFI_SUCCESS; } + return Status; } diff --git a/StandaloneMmPkg/Core/Page.c b/StandaloneMmPkg/Core/Page.c index a9bdd73cdc..8ee85d19db 100644 --- a/StandaloneMmPkg/Core/Page.c +++ b/StandaloneMmPkg/Core/Page.c @@ -16,7 +16,7 @@ LIST_ENTRY mMmMemoryMap = INITIALIZE_LIST_HEAD_VARIABLE (mMmMemoryMap); -UINTN mMapKey; +UINTN mMapKey; /** Internal Function. Allocate n pages from given free page node. @@ -43,10 +43,11 @@ InternalAllocPagesOnOneNode ( if (Top > Pages->NumberOfPages) { Top = Pages->NumberOfPages; } + Bottom = Top - NumberOfPages; if (Top < Pages->NumberOfPages) { - Node = (FREE_PAGE_LIST*)((UINTN)Pages + EFI_PAGES_TO_SIZE (Top)); + Node = (FREE_PAGE_LIST *)((UINTN)Pages + EFI_PAGES_TO_SIZE (Top)); Node->NumberOfPages = Pages->NumberOfPages - Top; InsertHeadList (&Pages->Link, &Node->Link); } @@ -82,11 +83,13 @@ InternalAllocMaxAddress ( for (Node = FreePageList->BackLink; Node != FreePageList; Node = Node->BackLink) { Pages = BASE_CR (Node, FREE_PAGE_LIST, Link); - if (Pages->NumberOfPages >= NumberOfPages && - (UINTN)Pages + EFI_PAGES_TO_SIZE (NumberOfPages) - 1 <= MaxAddress) { + if ((Pages->NumberOfPages >= NumberOfPages) && + ((UINTN)Pages + EFI_PAGES_TO_SIZE (NumberOfPages) - 1 <= MaxAddress)) + { return InternalAllocPagesOnOneNode (Pages, NumberOfPages, MaxAddress); } } + return (UINTN)(-1); } @@ -116,15 +119,17 @@ InternalAllocAddress ( } EndAddress = Address + EFI_PAGES_TO_SIZE (NumberOfPages); - for (Node = FreePageList->BackLink; Node!= FreePageList; Node = Node->BackLink) { + for (Node = FreePageList->BackLink; Node != FreePageList; Node = Node->BackLink) { Pages = BASE_CR (Node, FREE_PAGE_LIST, Link); if ((UINTN)Pages <= Address) { if ((UINTN)Pages + EFI_PAGES_TO_SIZE (Pages->NumberOfPages) < EndAddress) { break; } + return InternalAllocPagesOnOneNode (Pages, NumberOfPages, EndAddress); } } + return ~Address; } @@ -155,8 +160,9 @@ MmInternalAllocatePages ( { UINTN RequestedAddress; - if (MemoryType != EfiRuntimeServicesCode && - MemoryType != EfiRuntimeServicesData) { + if ((MemoryType != EfiRuntimeServicesCode) && + (MemoryType != EfiRuntimeServicesData)) + { return EFI_INVALID_PARAMETER; } @@ -180,6 +186,7 @@ MmInternalAllocatePages ( if (*Memory == (UINTN)-1) { return EFI_OUT_OF_RESOURCES; } + break; case AllocateAddress: *Memory = InternalAllocAddress ( @@ -190,10 +197,12 @@ MmInternalAllocatePages ( if (*Memory != RequestedAddress) { return EFI_NOT_FOUND; } + break; default: return EFI_INVALID_PARAMETER; } + return EFI_SUCCESS; } @@ -245,13 +254,15 @@ InternalMergeNodes ( Next = BASE_CR (First->Link.ForwardLink, FREE_PAGE_LIST, Link); ASSERT ( - TRUNCATE_TO_PAGES ((UINTN)Next - (UINTN)First) >= First->NumberOfPages); + TRUNCATE_TO_PAGES ((UINTN)Next - (UINTN)First) >= First->NumberOfPages + ); if (TRUNCATE_TO_PAGES ((UINTN)Next - (UINTN)First) == First->NumberOfPages) { First->NumberOfPages += Next->NumberOfPages; RemoveEntryList (&Next->Link); Next = First; } + return Next; } @@ -281,17 +292,19 @@ MmInternalFreePages ( } Pages = NULL; - Node = mMmMemoryMap.ForwardLink; + Node = mMmMemoryMap.ForwardLink; while (Node != &mMmMemoryMap) { Pages = BASE_CR (Node, FREE_PAGE_LIST, Link); if (Memory < (UINTN)Pages) { break; } + Node = Node->ForwardLink; } - if (Node != &mMmMemoryMap && - Memory + EFI_PAGES_TO_SIZE (NumberOfPages) > (UINTN)Pages) { + if ((Node != &mMmMemoryMap) && + (Memory + EFI_PAGES_TO_SIZE (NumberOfPages) > (UINTN)Pages)) + { return EFI_INVALID_PARAMETER; } @@ -302,7 +315,7 @@ MmInternalFreePages ( } } - Pages = (FREE_PAGE_LIST*)(UINTN)Memory; + Pages = (FREE_PAGE_LIST *)(UINTN)Memory; Pages->NumberOfPages = NumberOfPages; InsertTailList (Node, &Pages->Link); @@ -373,6 +386,6 @@ MmAddMemoryRegion ( // Align range on an EFI_PAGE_SIZE boundary // AlignedMemBase = (UINTN)(MemBase + EFI_PAGE_MASK) & ~EFI_PAGE_MASK; - MemLength -= AlignedMemBase - MemBase; + MemLength -= AlignedMemBase - MemBase; MmFreePages (AlignedMemBase, TRUNCATE_TO_PAGES ((UINTN)MemLength)); } diff --git a/StandaloneMmPkg/Core/Pool.c b/StandaloneMmPkg/Core/Pool.c index 34371d8dc3..282caa9869 100644 --- a/StandaloneMmPkg/Core/Pool.c +++ b/StandaloneMmPkg/Core/Pool.c @@ -14,7 +14,7 @@ LIST_ENTRY mMmPoolLists[MAX_POOL_INDEX]; // To cache the MMRAM base since when Loading modules At fixed address feature is enabled, // all module is assigned an offset relative the MMRAM base in build time. // -GLOBAL_REMOVE_IF_UNREFERENCED EFI_PHYSICAL_ADDRESS gLoadModuleAtFixAddressMmramBase = 0; +GLOBAL_REMOVE_IF_UNREFERENCED EFI_PHYSICAL_ADDRESS gLoadModuleAtFixAddressMmramBase = 0; /** Called to initialize the memory service. @@ -29,7 +29,7 @@ MmInitializeMemoryServices ( IN EFI_MMRAM_DESCRIPTOR *MmramRanges ) { - UINTN Index; + UINTN Index; // // Initialize Pool list @@ -38,7 +38,6 @@ MmInitializeMemoryServices ( InitializeListHead (&mMmPoolLists[--Index]); } - // // Initialize free MMRAM regions // @@ -49,8 +48,14 @@ MmInitializeMemoryServices ( if (MmramRanges[Index].CpuStart < BASE_1MB) { continue; } - DEBUG ((DEBUG_INFO, "MmAddMemoryRegion %d : 0x%016lx - 0x%016lx\n", - Index, MmramRanges[Index].CpuStart, MmramRanges[Index].PhysicalSize)); + + DEBUG (( + DEBUG_INFO, + "MmAddMemoryRegion %d : 0x%016lx - 0x%016lx\n", + Index, + MmramRanges[Index].CpuStart, + MmramRanges[Index].PhysicalSize + )); MmAddMemoryRegion ( MmramRanges[Index].CpuStart, MmramRanges[Index].PhysicalSize, @@ -58,7 +63,6 @@ MmInitializeMemoryServices ( MmramRanges[Index].RegionState ); } - } /** @@ -83,7 +87,7 @@ InternalAllocPoolByIndex ( ASSERT (PoolIndex <= MAX_POOL_INDEX); Status = EFI_SUCCESS; - Hdr = NULL; + Hdr = NULL; if (PoolIndex == MAX_POOL_INDEX) { Status = MmInternalAllocatePages ( AllocateAnyPages, @@ -94,22 +98,23 @@ InternalAllocPoolByIndex ( if (EFI_ERROR (Status)) { return EFI_OUT_OF_RESOURCES; } - Hdr = (FREE_POOL_HEADER *) (UINTN) Address; + + Hdr = (FREE_POOL_HEADER *)(UINTN)Address; } else if (!IsListEmpty (&mMmPoolLists[PoolIndex])) { Hdr = BASE_CR (GetFirstNode (&mMmPoolLists[PoolIndex]), FREE_POOL_HEADER, Link); RemoveEntryList (&Hdr->Link); } else { Status = InternalAllocPoolByIndex (PoolIndex + 1, &Hdr); if (!EFI_ERROR (Status)) { - Hdr->Header.Size >>= 1; + Hdr->Header.Size >>= 1; Hdr->Header.Available = TRUE; InsertHeadList (&mMmPoolLists[PoolIndex], &Hdr->Link); - Hdr = (FREE_POOL_HEADER*)((UINT8*)Hdr + Hdr->Header.Size); + Hdr = (FREE_POOL_HEADER *)((UINT8 *)Hdr + Hdr->Header.Size); } } if (!EFI_ERROR (Status)) { - Hdr->Header.Size = MIN_POOL_SIZE << PoolIndex; + Hdr->Header.Size = MIN_POOL_SIZE << PoolIndex; Hdr->Header.Available = FALSE; } @@ -136,7 +141,7 @@ InternalFreePoolByIndex ( ASSERT (((UINTN)FreePoolHdr & (FreePoolHdr->Header.Size - 1)) == 0); ASSERT (FreePoolHdr->Header.Size >= MIN_POOL_SIZE); - PoolIndex = (UINTN) (HighBitSet32 ((UINT32)FreePoolHdr->Header.Size) - MIN_POOL_SHIFT); + PoolIndex = (UINTN)(HighBitSet32 ((UINT32)FreePoolHdr->Header.Size) - MIN_POOL_SHIFT); FreePoolHdr->Header.Available = TRUE; ASSERT (PoolIndex < MAX_POOL_INDEX); InsertHeadList (&mMmPoolLists[PoolIndex], &FreePoolHdr->Link); @@ -170,28 +175,29 @@ MmInternalAllocatePool ( EFI_PHYSICAL_ADDRESS Address; UINTN PoolIndex; - if (PoolType != EfiRuntimeServicesCode && - PoolType != EfiRuntimeServicesData) { + if ((PoolType != EfiRuntimeServicesCode) && + (PoolType != EfiRuntimeServicesData)) + { return EFI_INVALID_PARAMETER; } Size += sizeof (*PoolHdr); if (Size > MAX_POOL_SIZE) { - Size = EFI_SIZE_TO_PAGES (Size); + Size = EFI_SIZE_TO_PAGES (Size); Status = MmInternalAllocatePages (AllocateAnyPages, PoolType, Size, &Address); if (EFI_ERROR (Status)) { return Status; } - PoolHdr = (POOL_HEADER*)(UINTN)Address; - PoolHdr->Size = EFI_PAGES_TO_SIZE (Size); + PoolHdr = (POOL_HEADER *)(UINTN)Address; + PoolHdr->Size = EFI_PAGES_TO_SIZE (Size); PoolHdr->Available = FALSE; - *Buffer = PoolHdr + 1; + *Buffer = PoolHdr + 1; return Status; } - Size = (Size + MIN_POOL_SIZE - 1) >> MIN_POOL_SHIFT; - PoolIndex = (UINTN) HighBitSet32 ((UINT32)Size); + Size = (Size + MIN_POOL_SIZE - 1) >> MIN_POOL_SHIFT; + PoolIndex = (UINTN)HighBitSet32 ((UINT32)Size); if ((Size & (Size - 1)) != 0) { PoolIndex++; } @@ -200,6 +206,7 @@ MmInternalAllocatePool ( if (!EFI_ERROR (Status)) { *Buffer = &FreePoolHdr->Header + 1; } + return Status; } @@ -251,7 +258,7 @@ MmInternalFreePool ( return EFI_INVALID_PARAMETER; } - FreePoolHdr = (FREE_POOL_HEADER*)((POOL_HEADER*)Buffer - 1); + FreePoolHdr = (FREE_POOL_HEADER *)((POOL_HEADER *)Buffer - 1); ASSERT (!FreePoolHdr->Header.Available); if (FreePoolHdr->Header.Size > MAX_POOL_SIZE) { @@ -262,6 +269,7 @@ MmInternalFreePool ( EFI_SIZE_TO_PAGES (FreePoolHdr->Header.Size) ); } + return InternalFreePoolByIndex (FreePoolHdr); } diff --git a/StandaloneMmPkg/Core/StandaloneMmCore.c b/StandaloneMmPkg/Core/StandaloneMmCore.c index 3a4a280271..d221f1d111 100644 --- a/StandaloneMmPkg/Core/StandaloneMmCore.c +++ b/StandaloneMmPkg/Core/StandaloneMmCore.c @@ -22,7 +22,7 @@ MmDispatcher ( // // Globals used to initialize the protocol // -EFI_HANDLE mMmCpuHandle = NULL; +EFI_HANDLE mMmCpuHandle = NULL; // // Physical pointer to private structure shared between MM IPL and the MM Core @@ -33,7 +33,6 @@ MM_CORE_PRIVATE_DATA *gMmCorePrivate; // MM Core global variable for MM System Table. Only accessed as a physical structure in MMRAM. // EFI_MM_SYSTEM_TABLE gMmCoreMmst = { - // The table header for the MMST. { MM_MMST_SIGNATURE, @@ -49,12 +48,12 @@ EFI_MM_SYSTEM_TABLE gMmCoreMmst = { // I/O Service { { - (EFI_MM_CPU_IO) MmEfiNotAvailableYetArg5, // MmMemRead - (EFI_MM_CPU_IO) MmEfiNotAvailableYetArg5 // MmMemWrite + (EFI_MM_CPU_IO)MmEfiNotAvailableYetArg5, // MmMemRead + (EFI_MM_CPU_IO)MmEfiNotAvailableYetArg5 // MmMemWrite }, { - (EFI_MM_CPU_IO) MmEfiNotAvailableYetArg5, // MmIoRead - (EFI_MM_CPU_IO) MmEfiNotAvailableYetArg5 // MmIoWrite + (EFI_MM_CPU_IO)MmEfiNotAvailableYetArg5, // MmIoRead + (EFI_MM_CPU_IO)MmEfiNotAvailableYetArg5 // MmIoWrite } }, // Runtime memory services @@ -85,16 +84,16 @@ EFI_MM_SYSTEM_TABLE gMmCoreMmst = { // Table of MMI Handlers that are registered by the MM Core when it is initialized // MM_CORE_MMI_HANDLERS mMmCoreMmiHandlers[] = { - { MmReadyToLockHandler, &gEfiDxeMmReadyToLockProtocolGuid, NULL, TRUE }, - { MmEndOfDxeHandler, &gEfiEndOfDxeEventGroupGuid, NULL, FALSE }, - { MmExitBootServiceHandler,&gEfiEventExitBootServicesGuid, NULL, FALSE }, - { MmReadyToBootHandler, &gEfiEventReadyToBootGuid, NULL, FALSE }, - { NULL, NULL, NULL, FALSE }, + { MmReadyToLockHandler, &gEfiDxeMmReadyToLockProtocolGuid, NULL, TRUE }, + { MmEndOfDxeHandler, &gEfiEndOfDxeEventGroupGuid, NULL, FALSE }, + { MmExitBootServiceHandler, &gEfiEventExitBootServicesGuid, NULL, FALSE }, + { MmReadyToBootHandler, &gEfiEventReadyToBootGuid, NULL, FALSE }, + { NULL, NULL, NULL, FALSE }, }; -EFI_SYSTEM_TABLE *mEfiSystemTable; -UINTN mMmramRangeCount; -EFI_MMRAM_DESCRIPTOR *mMmramRanges; +EFI_SYSTEM_TABLE *mEfiSystemTable; +UINTN mMmramRangeCount; +EFI_MMRAM_DESCRIPTOR *mMmramRanges; /** Place holder function until all the MM System Table Service are available. @@ -113,11 +112,11 @@ EFI_MMRAM_DESCRIPTOR *mMmramRanges; EFI_STATUS EFIAPI MmEfiNotAvailableYetArg5 ( - UINTN Arg1, - UINTN Arg2, - UINTN Arg3, - UINTN Arg4, - UINTN Arg5 + UINTN Arg1, + UINTN Arg2, + UINTN Arg3, + UINTN Arg4, + UINTN Arg5 ) { // @@ -148,20 +147,21 @@ MmExitBootServiceHandler ( IN OUT UINTN *CommBufferSize OPTIONAL ) { - EFI_HANDLE MmHandle; - EFI_STATUS Status; - STATIC BOOLEAN mInExitBootServices = FALSE; + EFI_HANDLE MmHandle; + EFI_STATUS Status; + STATIC BOOLEAN mInExitBootServices = FALSE; Status = EFI_SUCCESS; if (!mInExitBootServices) { MmHandle = NULL; - Status = MmInstallProtocolInterface ( - &MmHandle, - &gEfiEventExitBootServicesGuid, - EFI_NATIVE_INTERFACE, - NULL - ); + Status = MmInstallProtocolInterface ( + &MmHandle, + &gEfiEventExitBootServicesGuid, + EFI_NATIVE_INTERFACE, + NULL + ); } + mInExitBootServices = TRUE; return Status; } @@ -187,20 +187,21 @@ MmReadyToBootHandler ( IN OUT UINTN *CommBufferSize OPTIONAL ) { - EFI_HANDLE MmHandle; - EFI_STATUS Status; - STATIC BOOLEAN mInReadyToBoot = FALSE; + EFI_HANDLE MmHandle; + EFI_STATUS Status; + STATIC BOOLEAN mInReadyToBoot = FALSE; Status = EFI_SUCCESS; if (!mInReadyToBoot) { MmHandle = NULL; - Status = MmInstallProtocolInterface ( - &MmHandle, - &gEfiEventReadyToBootGuid, - EFI_NATIVE_INTERFACE, - NULL - ); + Status = MmInstallProtocolInterface ( + &MmHandle, + &gEfiEventReadyToBootGuid, + EFI_NATIVE_INTERFACE, + NULL + ); } + mInReadyToBoot = TRUE; return Status; } @@ -249,36 +250,35 @@ MmReadyToLockHandler ( // Install MM Ready to lock protocol // MmHandle = NULL; - Status = MmInstallProtocolInterface ( - &MmHandle, - &gEfiMmReadyToLockProtocolGuid, - EFI_NATIVE_INTERFACE, - NULL - ); + Status = MmInstallProtocolInterface ( + &MmHandle, + &gEfiMmReadyToLockProtocolGuid, + EFI_NATIVE_INTERFACE, + NULL + ); // // Make sure MM CPU I/O 2 Protocol has been installed into the handle database // - //Status = MmLocateProtocol (&EFI_MM_CPU_IO_PROTOCOL_GUID, NULL, &Interface); + // Status = MmLocateProtocol (&EFI_MM_CPU_IO_PROTOCOL_GUID, NULL, &Interface); // // Print a message on a debug build if the MM CPU I/O 2 Protocol is not installed // - //if (EFI_ERROR (Status)) { - //DEBUG ((DEBUG_ERROR, "\nSMM: SmmCpuIo Arch Protocol not present!!\n")); - //} - + // if (EFI_ERROR (Status)) { + // DEBUG ((DEBUG_ERROR, "\nSMM: SmmCpuIo Arch Protocol not present!!\n")); + // } // // Assert if the CPU I/O 2 Protocol is not installed // - //ASSERT_EFI_ERROR (Status); + // ASSERT_EFI_ERROR (Status); // // Display any drivers that were not dispatched because dependency expression // evaluated to false if this is a debug build // - //MmDisplayDiscoveredNotDispatched (); + // MmDisplayDiscoveredNotDispatched (); return Status; } @@ -314,17 +314,15 @@ MmEndOfDxeHandler ( // Install MM EndOfDxe protocol // MmHandle = NULL; - Status = MmInstallProtocolInterface ( - &MmHandle, - &gEfiMmEndOfDxeProtocolGuid, - EFI_NATIVE_INTERFACE, - NULL - ); + Status = MmInstallProtocolInterface ( + &MmHandle, + &gEfiMmEndOfDxeProtocolGuid, + EFI_NATIVE_INTERFACE, + NULL + ); return Status; } - - /** The main entry point to MM Foundation. @@ -338,9 +336,9 @@ VOID EFIAPI MmEntryPoint ( IN CONST EFI_MM_ENTRY_CONTEXT *MmEntryContext -) + ) { - EFI_STATUS Status; + EFI_STATUS Status; EFI_MM_COMMUNICATE_HEADER *CommunicateHeader; DEBUG ((DEBUG_INFO, "MmEntryPoint ...\n")); @@ -353,7 +351,7 @@ MmEntryPoint ( // // Call platform hook before Mm Dispatch // - //PlatformHookBeforeMmDispatch (); + // PlatformHookBeforeMmDispatch (); // // If a legacy boot has occurred, then make sure gMmCorePrivate is not accessed @@ -377,23 +375,23 @@ MmEntryPoint ( // If CommunicationBuffer is not in valid address scope, return EFI_INVALID_PARAMETER // gMmCorePrivate->CommunicationBuffer = 0; - gMmCorePrivate->ReturnStatus = EFI_INVALID_PARAMETER; + gMmCorePrivate->ReturnStatus = EFI_INVALID_PARAMETER; } else { - CommunicateHeader = (EFI_MM_COMMUNICATE_HEADER *)(UINTN)gMmCorePrivate->CommunicationBuffer; + CommunicateHeader = (EFI_MM_COMMUNICATE_HEADER *)(UINTN)gMmCorePrivate->CommunicationBuffer; gMmCorePrivate->BufferSize -= OFFSET_OF (EFI_MM_COMMUNICATE_HEADER, Data); - Status = MmiManage ( - &CommunicateHeader->HeaderGuid, - NULL, - CommunicateHeader->Data, - (UINTN *)&gMmCorePrivate->BufferSize - ); + Status = MmiManage ( + &CommunicateHeader->HeaderGuid, + NULL, + CommunicateHeader->Data, + (UINTN *)&gMmCorePrivate->BufferSize + ); // // Update CommunicationBuffer, BufferSize and ReturnStatus // Communicate service finished, reset the pointer to CommBuffer to NULL // - gMmCorePrivate->BufferSize += OFFSET_OF (EFI_MM_COMMUNICATE_HEADER, Data); + gMmCorePrivate->BufferSize += OFFSET_OF (EFI_MM_COMMUNICATE_HEADER, Data); gMmCorePrivate->CommunicationBuffer = 0; - gMmCorePrivate->ReturnStatus = (Status == EFI_SUCCESS) ? EFI_SUCCESS : EFI_NOT_FOUND; + gMmCorePrivate->ReturnStatus = (Status == EFI_SUCCESS) ? EFI_SUCCESS : EFI_NOT_FOUND; } } @@ -426,12 +424,12 @@ MmEntryPoint ( EFI_STATUS EFIAPI MmConfigurationMmNotify ( - IN CONST EFI_GUID *Protocol, - IN VOID *Interface, + IN CONST EFI_GUID *Protocol, + IN VOID *Interface, IN EFI_HANDLE Handle ) { - EFI_STATUS Status; + EFI_STATUS Status; EFI_MM_CONFIGURATION_PROTOCOL *MmConfiguration; DEBUG ((DEBUG_INFO, "MmConfigurationMmNotify(%g) - %x\n", Protocol, Interface)); @@ -465,17 +463,18 @@ MmConfigurationMmNotify ( **/ UINTN GetHobListSize ( - IN VOID *HobStart + IN VOID *HobStart ) { EFI_PEI_HOB_POINTERS Hob; ASSERT (HobStart != NULL); - Hob.Raw = (UINT8 *) HobStart; + Hob.Raw = (UINT8 *)HobStart; while (!END_OF_HOB_LIST (Hob)) { Hob.Raw = GET_NEXT_HOB (Hob); } + // // Need plus END_OF_HOB_LIST // @@ -529,23 +528,24 @@ StandaloneMmMain ( // Allocate and zero memory for a MM_CORE_PRIVATE_DATA table and then // initialise it // - gMmCorePrivate = (MM_CORE_PRIVATE_DATA *) AllocateRuntimePages(EFI_SIZE_TO_PAGES(sizeof (MM_CORE_PRIVATE_DATA))); + gMmCorePrivate = (MM_CORE_PRIVATE_DATA *)AllocateRuntimePages (EFI_SIZE_TO_PAGES (sizeof (MM_CORE_PRIVATE_DATA))); SetMem ((VOID *)(UINTN)gMmCorePrivate, sizeof (MM_CORE_PRIVATE_DATA), 0); - gMmCorePrivate->Signature = MM_CORE_PRIVATE_DATA_SIGNATURE; + gMmCorePrivate->Signature = MM_CORE_PRIVATE_DATA_SIGNATURE; gMmCorePrivate->MmEntryPointRegistered = FALSE; - gMmCorePrivate->InMm = FALSE; - gMmCorePrivate->ReturnStatus = EFI_SUCCESS; + gMmCorePrivate->InMm = FALSE; + gMmCorePrivate->ReturnStatus = EFI_SUCCESS; // // Extract the MMRAM ranges from the MMRAM descriptor HOB // MmramRangesHob = GetNextGuidHob (&gEfiMmPeiMmramMemoryReserveGuid, HobStart); - if (MmramRangesHob == NULL) + if (MmramRangesHob == NULL) { return EFI_UNSUPPORTED; + } MmramRangesHobData = GET_GUID_HOB_DATA (MmramRangesHob); ASSERT (MmramRangesHobData != NULL); - MmramRanges = MmramRangesHobData->Descriptor; + MmramRanges = MmramRangesHobData->Descriptor; MmramRangeCount = (UINTN)MmramRangesHobData->NumberOfMmReservedRegions; ASSERT (MmramRanges); ASSERT (MmramRangeCount); @@ -555,7 +555,7 @@ StandaloneMmMain ( // code relies on them being present there // gMmCorePrivate->MmramRangeCount = (UINT64)MmramRangeCount; - gMmCorePrivate->MmramRanges = + gMmCorePrivate->MmramRanges = (EFI_PHYSICAL_ADDRESS)(UINTN)AllocatePool (MmramRangeCount * sizeof (EFI_MMRAM_DESCRIPTOR)); ASSERT (gMmCorePrivate->MmramRanges != 0); CopyMem ( @@ -565,7 +565,7 @@ StandaloneMmMain ( ); } else { DataInHob = GET_GUID_HOB_DATA (GuidHob); - gMmCorePrivate = (MM_CORE_PRIVATE_DATA *)(UINTN)DataInHob->Address; + gMmCorePrivate = (MM_CORE_PRIVATE_DATA *)(UINTN)DataInHob->Address; MmramRanges = (EFI_MMRAM_DESCRIPTOR *)(UINTN)gMmCorePrivate->MmramRanges; MmramRangeCount = (UINTN)gMmCorePrivate->MmramRangeCount; } @@ -575,9 +575,13 @@ StandaloneMmMain ( // DEBUG ((DEBUG_INFO, "MmramRangeCount - 0x%x\n", MmramRangeCount)); for (Index = 0; Index < MmramRangeCount; Index++) { - DEBUG ((DEBUG_INFO, "MmramRanges[%d]: 0x%016lx - 0x%lx\n", Index, - MmramRanges[Index].CpuStart, - MmramRanges[Index].PhysicalSize)); + DEBUG (( + DEBUG_INFO, + "MmramRanges[%d]: 0x%016lx - 0x%lx\n", + Index, + MmramRanges[Index].CpuStart, + MmramRanges[Index].PhysicalSize + )); } // @@ -600,7 +604,7 @@ StandaloneMmMain ( gMmCorePrivate->StandaloneBfvAddress = BfvHob->BaseAddress; } - gMmCorePrivate->Mmst = (EFI_PHYSICAL_ADDRESS)(UINTN)&gMmCoreMmst; + gMmCorePrivate->Mmst = (EFI_PHYSICAL_ADDRESS)(UINTN)&gMmCoreMmst; gMmCorePrivate->MmEntryPoint = (EFI_PHYSICAL_ADDRESS)(UINTN)MmEntryPoint; // diff --git a/StandaloneMmPkg/Core/StandaloneMmCore.h b/StandaloneMmPkg/Core/StandaloneMmCore.h index 17c97c19cc..822d95358c 100644 --- a/StandaloneMmPkg/Core/StandaloneMmCore.h +++ b/StandaloneMmPkg/Core/StandaloneMmCore.h @@ -59,64 +59,64 @@ typedef struct { // // Structure for recording the state of an MM Driver // -#define EFI_MM_DRIVER_ENTRY_SIGNATURE SIGNATURE_32('s', 'd','r','v') +#define EFI_MM_DRIVER_ENTRY_SIGNATURE SIGNATURE_32('s', 'd','r','v') typedef struct { - UINTN Signature; - LIST_ENTRY Link; // mDriverList + UINTN Signature; + LIST_ENTRY Link; // mDriverList - LIST_ENTRY ScheduledLink; // mScheduledQueue + LIST_ENTRY ScheduledLink; // mScheduledQueue - EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader; - EFI_GUID FileName; - VOID *Pe32Data; - UINTN Pe32DataSize; + EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader; + EFI_GUID FileName; + VOID *Pe32Data; + UINTN Pe32DataSize; - VOID *Depex; - UINTN DepexSize; + VOID *Depex; + UINTN DepexSize; - BOOLEAN Before; - BOOLEAN After; - EFI_GUID BeforeAfterGuid; + BOOLEAN Before; + BOOLEAN After; + EFI_GUID BeforeAfterGuid; - BOOLEAN Dependent; - BOOLEAN Scheduled; - BOOLEAN Initialized; - BOOLEAN DepexProtocolError; + BOOLEAN Dependent; + BOOLEAN Scheduled; + BOOLEAN Initialized; + BOOLEAN DepexProtocolError; - EFI_HANDLE ImageHandle; - EFI_LOADED_IMAGE_PROTOCOL *LoadedImage; + EFI_HANDLE ImageHandle; + EFI_LOADED_IMAGE_PROTOCOL *LoadedImage; // // Image EntryPoint in MMRAM // - PHYSICAL_ADDRESS ImageEntryPoint; + PHYSICAL_ADDRESS ImageEntryPoint; // // Image Buffer in MMRAM // - PHYSICAL_ADDRESS ImageBuffer; + PHYSICAL_ADDRESS ImageBuffer; // // Image Page Number // - UINTN NumberOfPage; + UINTN NumberOfPage; } EFI_MM_DRIVER_ENTRY; -#define EFI_HANDLE_SIGNATURE SIGNATURE_32('h','n','d','l') +#define EFI_HANDLE_SIGNATURE SIGNATURE_32('h','n','d','l') /// /// IHANDLE - contains a list of protocol handles /// typedef struct { - UINTN Signature; + UINTN Signature; /// All handles list of IHANDLE - LIST_ENTRY AllHandles; + LIST_ENTRY AllHandles; /// List of PROTOCOL_INTERFACE's for this handle - LIST_ENTRY Protocols; - UINTN LocateRequest; + LIST_ENTRY Protocols; + UINTN LocateRequest; } IHANDLE; #define ASSERT_IS_HANDLE(a) ASSERT((a)->Signature == EFI_HANDLE_SIGNATURE) -#define PROTOCOL_ENTRY_SIGNATURE SIGNATURE_32('p','r','t','e') +#define PROTOCOL_ENTRY_SIGNATURE SIGNATURE_32('p','r','t','e') /// /// PROTOCOL_ENTRY - each different protocol has 1 entry in the protocol @@ -124,15 +124,15 @@ typedef struct { /// with a list of registered notifies. /// typedef struct { - UINTN Signature; + UINTN Signature; /// Link Entry inserted to mProtocolDatabase - LIST_ENTRY AllEntries; + LIST_ENTRY AllEntries; /// ID of the protocol - EFI_GUID ProtocolID; + EFI_GUID ProtocolID; /// All protocol interfaces - LIST_ENTRY Protocols; + LIST_ENTRY Protocols; /// Registered notification handlers - LIST_ENTRY Notify; + LIST_ENTRY Notify; } PROTOCOL_ENTRY; #define PROTOCOL_INTERFACE_SIGNATURE SIGNATURE_32('p','i','f','c') @@ -142,20 +142,20 @@ typedef struct { /// with a protocol interface structure /// typedef struct { - UINTN Signature; + UINTN Signature; /// Link on IHANDLE.Protocols - LIST_ENTRY Link; + LIST_ENTRY Link; /// Back pointer - IHANDLE *Handle; + IHANDLE *Handle; /// Link on PROTOCOL_ENTRY.Protocols - LIST_ENTRY ByProtocol; + LIST_ENTRY ByProtocol; /// The protocol ID - PROTOCOL_ENTRY *Protocol; + PROTOCOL_ENTRY *Protocol; /// The interface value - VOID *Interface; + VOID *Interface; } PROTOCOL_INTERFACE; -#define PROTOCOL_NOTIFY_SIGNATURE SIGNATURE_32('p','r','t','n') +#define PROTOCOL_NOTIFY_SIGNATURE SIGNATURE_32('p','r','t','n') /// /// PROTOCOL_NOTIFY - used for each register notification for a protocol @@ -166,7 +166,7 @@ typedef struct { /// All notifications for this protocol LIST_ENTRY Link; /// Notification function - EFI_MM_NOTIFY_FN Function; + EFI_MM_NOTIFY_FN Function; /// Last position notified LIST_ENTRY *Position; } PROTOCOL_NOTIFY; @@ -213,9 +213,9 @@ EFI_STATUS EFIAPI MmInstallConfigurationTable ( IN CONST EFI_MM_SYSTEM_TABLE *SystemTable, - IN CONST EFI_GUID *Guid, - IN VOID *Table, - IN UINTN TableSize + IN CONST EFI_GUID *Guid, + IN VOID *Table, + IN UINTN TableSize ); /** @@ -235,10 +235,10 @@ MmInstallConfigurationTable ( EFI_STATUS EFIAPI MmInstallProtocolInterface ( - IN OUT EFI_HANDLE *UserHandle, - IN EFI_GUID *Protocol, - IN EFI_INTERFACE_TYPE InterfaceType, - IN VOID *Interface + IN OUT EFI_HANDLE *UserHandle, + IN EFI_GUID *Protocol, + IN EFI_INTERFACE_TYPE InterfaceType, + IN VOID *Interface ); /** @@ -260,10 +260,10 @@ MmInstallProtocolInterface ( EFI_STATUS EFIAPI MmAllocatePages ( - IN EFI_ALLOCATE_TYPE Type, - IN EFI_MEMORY_TYPE MemoryType, - IN UINTN NumberOfPages, - OUT EFI_PHYSICAL_ADDRESS *Memory + IN EFI_ALLOCATE_TYPE Type, + IN EFI_MEMORY_TYPE MemoryType, + IN UINTN NumberOfPages, + OUT EFI_PHYSICAL_ADDRESS *Memory ); /** @@ -285,10 +285,10 @@ MmAllocatePages ( EFI_STATUS EFIAPI MmInternalAllocatePages ( - IN EFI_ALLOCATE_TYPE Type, - IN EFI_MEMORY_TYPE MemoryType, - IN UINTN NumberOfPages, - OUT EFI_PHYSICAL_ADDRESS *Memory + IN EFI_ALLOCATE_TYPE Type, + IN EFI_MEMORY_TYPE MemoryType, + IN UINTN NumberOfPages, + OUT EFI_PHYSICAL_ADDRESS *Memory ); /** @@ -305,8 +305,8 @@ MmInternalAllocatePages ( EFI_STATUS EFIAPI MmFreePages ( - IN EFI_PHYSICAL_ADDRESS Memory, - IN UINTN NumberOfPages + IN EFI_PHYSICAL_ADDRESS Memory, + IN UINTN NumberOfPages ); /** @@ -323,8 +323,8 @@ MmFreePages ( EFI_STATUS EFIAPI MmInternalFreePages ( - IN EFI_PHYSICAL_ADDRESS Memory, - IN UINTN NumberOfPages + IN EFI_PHYSICAL_ADDRESS Memory, + IN UINTN NumberOfPages ); /** @@ -343,9 +343,9 @@ MmInternalFreePages ( EFI_STATUS EFIAPI MmAllocatePool ( - IN EFI_MEMORY_TYPE PoolType, - IN UINTN Size, - OUT VOID **Buffer + IN EFI_MEMORY_TYPE PoolType, + IN UINTN Size, + OUT VOID **Buffer ); /** @@ -364,9 +364,9 @@ MmAllocatePool ( EFI_STATUS EFIAPI MmInternalAllocatePool ( - IN EFI_MEMORY_TYPE PoolType, - IN UINTN Size, - OUT VOID **Buffer + IN EFI_MEMORY_TYPE PoolType, + IN UINTN Size, + OUT VOID **Buffer ); /** @@ -381,7 +381,7 @@ MmInternalAllocatePool ( EFI_STATUS EFIAPI MmFreePool ( - IN VOID *Buffer + IN VOID *Buffer ); /** @@ -396,7 +396,7 @@ MmFreePool ( EFI_STATUS EFIAPI MmInternalFreePool ( - IN VOID *Buffer + IN VOID *Buffer ); /** @@ -418,11 +418,11 @@ MmInternalFreePool ( **/ EFI_STATUS MmInstallProtocolInterfaceNotify ( - IN OUT EFI_HANDLE *UserHandle, - IN EFI_GUID *Protocol, - IN EFI_INTERFACE_TYPE InterfaceType, - IN VOID *Interface, - IN BOOLEAN Notify + IN OUT EFI_HANDLE *UserHandle, + IN EFI_GUID *Protocol, + IN EFI_INTERFACE_TYPE InterfaceType, + IN VOID *Interface, + IN BOOLEAN Notify ); /** @@ -441,9 +441,9 @@ MmInstallProtocolInterfaceNotify ( EFI_STATUS EFIAPI MmUninstallProtocolInterface ( - IN EFI_HANDLE UserHandle, - IN EFI_GUID *Protocol, - IN VOID *Interface + IN EFI_HANDLE UserHandle, + IN EFI_GUID *Protocol, + IN VOID *Interface ); /** @@ -460,9 +460,9 @@ MmUninstallProtocolInterface ( EFI_STATUS EFIAPI MmHandleProtocol ( - IN EFI_HANDLE UserHandle, - IN EFI_GUID *Protocol, - OUT VOID **Interface + IN EFI_HANDLE UserHandle, + IN EFI_GUID *Protocol, + OUT VOID **Interface ); /** @@ -481,9 +481,9 @@ MmHandleProtocol ( EFI_STATUS EFIAPI MmRegisterProtocolNotify ( - IN CONST EFI_GUID *Protocol, - IN EFI_MM_NOTIFY_FN Function, - OUT VOID **Registration + IN CONST EFI_GUID *Protocol, + IN EFI_MM_NOTIFY_FN Function, + OUT VOID **Registration ); /** @@ -507,11 +507,11 @@ MmRegisterProtocolNotify ( EFI_STATUS EFIAPI MmLocateHandle ( - IN EFI_LOCATE_SEARCH_TYPE SearchType, - IN EFI_GUID *Protocol OPTIONAL, - IN VOID *SearchKey OPTIONAL, - IN OUT UINTN *BufferSize, - OUT EFI_HANDLE *Buffer + IN EFI_LOCATE_SEARCH_TYPE SearchType, + IN EFI_GUID *Protocol OPTIONAL, + IN VOID *SearchKey OPTIONAL, + IN OUT UINTN *BufferSize, + OUT EFI_HANDLE *Buffer ); /** @@ -555,10 +555,10 @@ MmLocateProtocol ( EFI_STATUS EFIAPI MmiManage ( - IN CONST EFI_GUID *HandlerType, - IN CONST VOID *Context OPTIONAL, - IN OUT VOID *CommBuffer OPTIONAL, - IN OUT UINTN *CommBufferSize OPTIONAL + IN CONST EFI_GUID *HandlerType, + IN CONST VOID *Context OPTIONAL, + IN OUT VOID *CommBuffer OPTIONAL, + IN OUT UINTN *CommBufferSize OPTIONAL ); /** @@ -575,9 +575,9 @@ MmiManage ( EFI_STATUS EFIAPI MmiHandlerRegister ( - IN EFI_MM_HANDLER_ENTRY_POINT Handler, - IN CONST EFI_GUID *HandlerType OPTIONAL, - OUT EFI_HANDLE *DispatchHandle + IN EFI_MM_HANDLER_ENTRY_POINT Handler, + IN CONST EFI_GUID *HandlerType OPTIONAL, + OUT EFI_HANDLE *DispatchHandle ); /** @@ -592,7 +592,7 @@ MmiHandlerRegister ( EFI_STATUS EFIAPI MmiHandlerUnRegister ( - IN EFI_HANDLE DispatchHandle + IN EFI_HANDLE DispatchHandle ); /** @@ -611,10 +611,10 @@ MmiHandlerUnRegister ( EFI_STATUS EFIAPI MmDriverDispatchHandler ( - IN EFI_HANDLE DispatchHandle, - IN CONST VOID *Context OPTIONAL, - IN OUT VOID *CommBuffer OPTIONAL, - IN OUT UINTN *CommBufferSize OPTIONAL + IN EFI_HANDLE DispatchHandle, + IN CONST VOID *Context OPTIONAL, + IN OUT VOID *CommBuffer OPTIONAL, + IN OUT UINTN *CommBufferSize OPTIONAL ); /** @@ -633,10 +633,10 @@ MmDriverDispatchHandler ( EFI_STATUS EFIAPI MmExitBootServiceHandler ( - IN EFI_HANDLE DispatchHandle, - IN CONST VOID *Context OPTIONAL, - IN OUT VOID *CommBuffer OPTIONAL, - IN OUT UINTN *CommBufferSize OPTIONAL + IN EFI_HANDLE DispatchHandle, + IN CONST VOID *Context OPTIONAL, + IN OUT VOID *CommBuffer OPTIONAL, + IN OUT UINTN *CommBufferSize OPTIONAL ); /** @@ -655,10 +655,10 @@ MmExitBootServiceHandler ( EFI_STATUS EFIAPI MmReadyToBootHandler ( - IN EFI_HANDLE DispatchHandle, - IN CONST VOID *Context OPTIONAL, - IN OUT VOID *CommBuffer OPTIONAL, - IN OUT UINTN *CommBufferSize OPTIONAL + IN EFI_HANDLE DispatchHandle, + IN CONST VOID *Context OPTIONAL, + IN OUT VOID *CommBuffer OPTIONAL, + IN OUT UINTN *CommBufferSize OPTIONAL ); /** @@ -677,10 +677,10 @@ MmReadyToBootHandler ( EFI_STATUS EFIAPI MmReadyToLockHandler ( - IN EFI_HANDLE DispatchHandle, - IN CONST VOID *Context OPTIONAL, - IN OUT VOID *CommBuffer OPTIONAL, - IN OUT UINTN *CommBufferSize OPTIONAL + IN EFI_HANDLE DispatchHandle, + IN CONST VOID *Context OPTIONAL, + IN OUT VOID *CommBuffer OPTIONAL, + IN OUT UINTN *CommBufferSize OPTIONAL ); /** @@ -699,10 +699,10 @@ MmReadyToLockHandler ( EFI_STATUS EFIAPI MmEndOfDxeHandler ( - IN EFI_HANDLE DispatchHandle, - IN CONST VOID *Context OPTIONAL, - IN OUT VOID *CommBuffer OPTIONAL, - IN OUT UINTN *CommBufferSize OPTIONAL + IN EFI_HANDLE DispatchHandle, + IN CONST VOID *Context OPTIONAL, + IN OUT VOID *CommBuffer OPTIONAL, + IN OUT UINTN *CommBufferSize OPTIONAL ); /** @@ -720,15 +720,15 @@ MmEndOfDxeHandler ( EFI_STATUS EFIAPI MmEfiNotAvailableYetArg5 ( - UINTN Arg1, - UINTN Arg2, - UINTN Arg3, - UINTN Arg4, - UINTN Arg5 + UINTN Arg1, + UINTN Arg2, + UINTN Arg3, + UINTN Arg4, + UINTN Arg5 ); // -//Functions used during debug builds +// Functions used during debug builds // /** @@ -752,10 +752,10 @@ MmDisplayDiscoveredNotDispatched ( **/ VOID MmAddMemoryRegion ( - IN EFI_PHYSICAL_ADDRESS MemBase, - IN UINT64 MemLength, - IN EFI_MEMORY_TYPE Type, - IN UINT64 Attributes + IN EFI_PHYSICAL_ADDRESS MemBase, + IN UINT64 MemLength, + IN EFI_MEMORY_TYPE Type, + IN UINT64 Attributes ); /** @@ -769,8 +769,8 @@ MmAddMemoryRegion ( **/ PROTOCOL_ENTRY * MmFindProtocolEntry ( - IN EFI_GUID *Protocol, - IN BOOLEAN Create + IN EFI_GUID *Protocol, + IN BOOLEAN Create ); /** @@ -781,7 +781,7 @@ MmFindProtocolEntry ( **/ VOID MmNotifyProtocol ( - IN PROTOCOL_INTERFACE *Prot + IN PROTOCOL_INTERFACE *Prot ); /** @@ -798,9 +798,9 @@ MmNotifyProtocol ( **/ PROTOCOL_INTERFACE * MmFindProtocolInterface ( - IN IHANDLE *Handle, - IN EFI_GUID *Protocol, - IN VOID *Interface + IN IHANDLE *Handle, + IN EFI_GUID *Protocol, + IN VOID *Interface ); /** @@ -815,9 +815,9 @@ MmFindProtocolInterface ( **/ PROTOCOL_INTERFACE * MmRemoveInterfaceFromProtocol ( - IN IHANDLE *Handle, - IN EFI_GUID *Protocol, - IN VOID *Interface + IN IHANDLE *Handle, + IN EFI_GUID *Protocol, + IN VOID *Interface ); /** @@ -834,7 +834,7 @@ MmRemoveInterfaceFromProtocol ( **/ BOOLEAN MmIsSchedulable ( - IN EFI_MM_DRIVER_ENTRY *DriverEntry + IN EFI_MM_DRIVER_ENTRY *DriverEntry ); /** @@ -846,8 +846,8 @@ DumpMmramInfo ( VOID ); -extern UINTN mMmramRangeCount; -extern EFI_MMRAM_DESCRIPTOR *mMmramRanges; -extern EFI_SYSTEM_TABLE *mEfiSystemTable; +extern UINTN mMmramRangeCount; +extern EFI_MMRAM_DESCRIPTOR *mMmramRanges; +extern EFI_SYSTEM_TABLE *mEfiSystemTable; #endif diff --git a/StandaloneMmPkg/Core/StandaloneMmCorePrivateData.h b/StandaloneMmPkg/Core/StandaloneMmCorePrivateData.h index f10ed6ffeb..58d3bc3803 100644 --- a/StandaloneMmPkg/Core/StandaloneMmCorePrivateData.h +++ b/StandaloneMmPkg/Core/StandaloneMmCorePrivateData.h @@ -18,8 +18,8 @@ // typedef struct { - LIST_ENTRY Link; - UINTN NumberOfPages; + LIST_ENTRY Link; + UINTN NumberOfPages; } FREE_PAGE_LIST; extern LIST_ENTRY mMmMemoryMap; @@ -46,13 +46,13 @@ extern LIST_ENTRY mMmMemoryMap; #define MAX_POOL_INDEX (MAX_POOL_SHIFT - MIN_POOL_SHIFT + 1) typedef struct { - UINTN Size; - BOOLEAN Available; + UINTN Size; + BOOLEAN Available; } POOL_HEADER; typedef struct { - POOL_HEADER Header; - LIST_ENTRY Link; + POOL_HEADER Header; + LIST_ENTRY Link; } FREE_POOL_HEADER; extern LIST_ENTRY mMmPoolLists[MAX_POOL_INDEX]; diff --git a/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c b/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c index d9d1fe1551..1ac15ddda2 100644 --- a/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c +++ b/StandaloneMmPkg/Drivers/StandaloneMmCpu/EventHandle.c @@ -11,7 +11,6 @@ #include #include - #include #include #include @@ -32,7 +31,7 @@ EFI_STATUS EFIAPI MmFoundationEntryRegister ( IN CONST EFI_MM_CONFIGURATION_PROTOCOL *This, - IN EFI_MM_ENTRY_POINT MmEntryPoint + IN EFI_MM_ENTRY_POINT MmEntryPoint ); // @@ -46,19 +45,19 @@ MmFoundationEntryRegister ( // number of CPUs in the system are made known through the // MP_INFORMATION_HOB_DATA. // -EFI_MM_COMMUNICATE_HEADER **PerCpuGuidedEventContext = NULL; +EFI_MM_COMMUNICATE_HEADER **PerCpuGuidedEventContext = NULL; // Descriptor with whereabouts of memory used for communication with the normal world EFI_MMRAM_DESCRIPTOR mNsCommBuffer; -MP_INFORMATION_HOB_DATA *mMpInformationHobData; +MP_INFORMATION_HOB_DATA *mMpInformationHobData; -EFI_MM_CONFIGURATION_PROTOCOL mMmConfig = { +EFI_MM_CONFIGURATION_PROTOCOL mMmConfig = { 0, MmFoundationEntryRegister }; -STATIC EFI_MM_ENTRY_POINT mMmEntryPoint = NULL; +STATIC EFI_MM_ENTRY_POINT mMmEntryPoint = NULL; /** The PI Standalone MM entry point for the TF-A CPU driver. @@ -75,15 +74,15 @@ STATIC EFI_MM_ENTRY_POINT mMmEntryPoint = NULL; **/ EFI_STATUS PiMmStandaloneArmTfCpuDriverEntry ( - IN UINTN EventId, - IN UINTN CpuNumber, - IN UINTN NsCommBufferAddr + IN UINTN EventId, + IN UINTN CpuNumber, + IN UINTN NsCommBufferAddr ) { - EFI_MM_COMMUNICATE_HEADER *GuidedEventContext; - EFI_MM_ENTRY_CONTEXT MmEntryPointContext; - EFI_STATUS Status; - UINTN NsCommBufferSize; + EFI_MM_COMMUNICATE_HEADER *GuidedEventContext; + EFI_MM_ENTRY_CONTEXT MmEntryPointContext; + EFI_STATUS Status; + UINTN NsCommBufferSize; DEBUG ((DEBUG_INFO, "Received event - 0x%x on cpu %d\n", EventId, CpuNumber)); @@ -94,7 +93,8 @@ PiMmStandaloneArmTfCpuDriverEntry ( // between synchronous and asynchronous events. // if ((ARM_SMC_ID_MM_COMMUNICATE != EventId) && - (ARM_SVC_ID_FFA_MSG_SEND_DIRECT_REQ != EventId)) { + (ARM_SVC_ID_FFA_MSG_SEND_DIRECT_REQ != EventId)) + { DEBUG ((DEBUG_INFO, "UnRecognized Event - 0x%x\n", EventId)); return EFI_INVALID_PARAMETER; } @@ -109,17 +109,19 @@ PiMmStandaloneArmTfCpuDriverEntry ( } if ((NsCommBufferAddr + sizeof (EFI_MM_COMMUNICATE_HEADER)) >= - (mNsCommBuffer.PhysicalStart + mNsCommBuffer.PhysicalSize)) { + (mNsCommBuffer.PhysicalStart + mNsCommBuffer.PhysicalSize)) + { return EFI_INVALID_PARAMETER; } // Find out the size of the buffer passed - NsCommBufferSize = ((EFI_MM_COMMUNICATE_HEADER *) NsCommBufferAddr)->MessageLength + - sizeof (EFI_MM_COMMUNICATE_HEADER); + NsCommBufferSize = ((EFI_MM_COMMUNICATE_HEADER *)NsCommBufferAddr)->MessageLength + + sizeof (EFI_MM_COMMUNICATE_HEADER); // perform bounds check. if (NsCommBufferAddr + NsCommBufferSize >= - mNsCommBuffer.PhysicalStart + mNsCommBuffer.PhysicalSize) { + mNsCommBuffer.PhysicalStart + mNsCommBuffer.PhysicalSize) + { return EFI_ACCESS_DENIED; } @@ -129,7 +131,7 @@ PiMmStandaloneArmTfCpuDriverEntry ( Status = mMmst->MmAllocatePool ( EfiRuntimeServicesData, NsCommBufferSize, - (VOID **) &GuidedEventContext + (VOID **)&GuidedEventContext ); if (Status != EFI_SUCCESS) { @@ -139,7 +141,7 @@ PiMmStandaloneArmTfCpuDriverEntry ( // X1 contains the VA of the normal world memory accessible from // S-EL0 - CopyMem (GuidedEventContext, (CONST VOID *) NsCommBufferAddr, NsCommBufferSize); + CopyMem (GuidedEventContext, (CONST VOID *)NsCommBufferAddr, NsCommBufferSize); // Stash the pointer to the allocated Event Context for this CPU PerCpuGuidedEventContext[CpuNumber] = GuidedEventContext; @@ -147,13 +149,13 @@ PiMmStandaloneArmTfCpuDriverEntry ( ZeroMem (&MmEntryPointContext, sizeof (EFI_MM_ENTRY_CONTEXT)); MmEntryPointContext.CurrentlyExecutingCpu = CpuNumber; - MmEntryPointContext.NumberOfCpus = mMpInformationHobData->NumberOfProcessors; + MmEntryPointContext.NumberOfCpus = mMpInformationHobData->NumberOfProcessors; // Populate the MM system table with MP and state information mMmst->CurrentlyExecutingCpu = CpuNumber; - mMmst->NumberOfCpus = mMpInformationHobData->NumberOfProcessors; - mMmst->CpuSaveStateSize = 0; - mMmst->CpuSaveState = NULL; + mMmst->NumberOfCpus = mMpInformationHobData->NumberOfProcessors; + mMmst->CpuSaveStateSize = 0; + mMmst->CpuSaveState = NULL; if (mMmEntryPoint == NULL) { DEBUG ((DEBUG_INFO, "Mm Entry point Not Found\n")); @@ -164,12 +166,13 @@ PiMmStandaloneArmTfCpuDriverEntry ( // Free the memory allocation done earlier and reset the per-cpu context ASSERT (GuidedEventContext); - CopyMem ((VOID *)NsCommBufferAddr, (CONST VOID *) GuidedEventContext, NsCommBufferSize); + CopyMem ((VOID *)NsCommBufferAddr, (CONST VOID *)GuidedEventContext, NsCommBufferSize); - Status = mMmst->MmFreePool ((VOID *) GuidedEventContext); + Status = mMmst->MmFreePool ((VOID *)GuidedEventContext); if (Status != EFI_SUCCESS) { return EFI_OUT_OF_RESOURCES; } + PerCpuGuidedEventContext[CpuNumber] = NULL; return Status; @@ -187,7 +190,7 @@ EFI_STATUS EFIAPI MmFoundationEntryRegister ( IN CONST EFI_MM_CONFIGURATION_PROTOCOL *This, - IN EFI_MM_ENTRY_POINT MmEntryPoint + IN EFI_MM_ENTRY_POINT MmEntryPoint ) { // store the entry point in a global @@ -214,14 +217,14 @@ MmFoundationEntryRegister ( EFI_STATUS EFIAPI PiMmCpuTpFwRootMmiHandler ( - IN EFI_HANDLE DispatchHandle, - IN CONST VOID *Context OPTIONAL, - IN OUT VOID *CommBuffer OPTIONAL, - IN OUT UINTN *CommBufferSize OPTIONAL + IN EFI_HANDLE DispatchHandle, + IN CONST VOID *Context OPTIONAL, + IN OUT VOID *CommBuffer OPTIONAL, + IN OUT UINTN *CommBufferSize OPTIONAL ) { - EFI_STATUS Status; - UINTN CpuNumber; + EFI_STATUS Status; + UINTN CpuNumber; ASSERT (Context == NULL); ASSERT (CommBuffer == NULL); @@ -232,9 +235,12 @@ PiMmCpuTpFwRootMmiHandler ( return EFI_NOT_FOUND; } - DEBUG ((DEBUG_INFO, "CommBuffer - 0x%x, CommBufferSize - 0x%x\n", - PerCpuGuidedEventContext[CpuNumber], - PerCpuGuidedEventContext[CpuNumber]->MessageLength)); + DEBUG (( + DEBUG_INFO, + "CommBuffer - 0x%x, CommBufferSize - 0x%x\n", + PerCpuGuidedEventContext[CpuNumber], + PerCpuGuidedEventContext[CpuNumber]->MessageLength + )); Status = mMmst->MmiManage ( &PerCpuGuidedEventContext[CpuNumber]->HeaderGuid, diff --git a/StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.c b/StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.c index 10097f792f..24dff82268 100644 --- a/StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.c +++ b/StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.c @@ -22,27 +22,26 @@ #include #include - #include "StandaloneMmCpu.h" // 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 this CPU driver will be // populated to allow the entry point driver to invoke it upon receipt of an // event -extern EFI_GUID gEfiArmTfCpuDriverEpDescriptorGuid; +extern EFI_GUID gEfiArmTfCpuDriverEpDescriptorGuid; // // Private copy of the MM system table for future use // -EFI_MM_SYSTEM_TABLE *mMmst = NULL; +EFI_MM_SYSTEM_TABLE *mMmst = NULL; // // Globals used to initialize the protocol // -STATIC EFI_HANDLE mMmCpuHandle = NULL; +STATIC EFI_HANDLE mMmCpuHandle = NULL; /** Returns the HOB data for the matching HOB GUID. @@ -56,12 +55,12 @@ STATIC EFI_HANDLE mMmCpuHandle = NULL; **/ EFI_STATUS GetGuidedHobData ( - IN VOID *HobList, - IN CONST EFI_GUID *HobGuid, - OUT VOID **HobData + IN VOID *HobList, + IN CONST EFI_GUID *HobGuid, + OUT VOID **HobData ) { - EFI_HOB_GUID_TYPE *Hob; + EFI_HOB_GUID_TYPE *Hob; if ((HobList == NULL) || (HobGuid == NULL) || (HobData == NULL)) { return EFI_INVALID_PARAMETER; @@ -93,20 +92,20 @@ GetGuidedHobData ( **/ EFI_STATUS StandaloneMmCpuInitialize ( - IN EFI_HANDLE ImageHandle, // not actual imagehandle - IN EFI_MM_SYSTEM_TABLE *SystemTable // not actual systemtable + IN EFI_HANDLE ImageHandle, // not actual imagehandle + IN EFI_MM_SYSTEM_TABLE *SystemTable // not actual systemtable ) { - ARM_TF_CPU_DRIVER_EP_DESCRIPTOR *CpuDriverEntryPointDesc; - EFI_CONFIGURATION_TABLE *ConfigurationTable; - MP_INFORMATION_HOB_DATA *MpInformationHobData; - EFI_MMRAM_DESCRIPTOR *NsCommBufMmramRange; + ARM_TF_CPU_DRIVER_EP_DESCRIPTOR *CpuDriverEntryPointDesc; + EFI_CONFIGURATION_TABLE *ConfigurationTable; + MP_INFORMATION_HOB_DATA *MpInformationHobData; + EFI_MMRAM_DESCRIPTOR *NsCommBufMmramRange; EFI_STATUS Status; EFI_HANDLE DispatchHandle; UINT32 MpInfoSize; UINTN Index; UINTN ArraySize; - VOID *HobStart; + VOID *HobStart; ASSERT (SystemTable != NULL); mMmst = SystemTable; @@ -155,7 +154,7 @@ StandaloneMmCpuInitialize ( Status = GetGuidedHobData ( HobStart, &gEfiArmTfCpuDriverEpDescriptorGuid, - (VOID **) &CpuDriverEntryPointDesc + (VOID **)&CpuDriverEntryPointDesc ); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_INFO, "ArmTfCpuDriverEpDesc HOB data extraction failed - 0x%x\n", Status)); @@ -163,9 +162,12 @@ StandaloneMmCpuInitialize ( } // Share the entry point of the CPU driver - DEBUG ((DEBUG_INFO, "Sharing Cpu Driver EP *0x%lx = 0x%lx\n", - (UINTN) CpuDriverEntryPointDesc->ArmTfCpuDriverEpPtr, - (UINTN) PiMmStandaloneArmTfCpuDriverEntry)); + DEBUG (( + DEBUG_INFO, + "Sharing Cpu Driver EP *0x%lx = 0x%lx\n", + (UINTN)CpuDriverEntryPointDesc->ArmTfCpuDriverEpPtr, + (UINTN)PiMmStandaloneArmTfCpuDriverEntry + )); *(CpuDriverEntryPointDesc->ArmTfCpuDriverEpPtr) = PiMmStandaloneArmTfCpuDriverEntry; // Find the descriptor that contains the whereabouts of the buffer for @@ -173,17 +175,17 @@ StandaloneMmCpuInitialize ( Status = GetGuidedHobData ( HobStart, &gEfiStandaloneMmNonSecureBufferGuid, - (VOID **) &NsCommBufMmramRange + (VOID **)&NsCommBufMmramRange ); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_INFO, "NsCommBufMmramRange HOB data extraction failed - 0x%x\n", Status)); return Status; } - DEBUG ((DEBUG_INFO, "mNsCommBuffer.PhysicalStart - 0x%lx\n", (UINTN) NsCommBufMmramRange->PhysicalStart)); - DEBUG ((DEBUG_INFO, "mNsCommBuffer.PhysicalSize - 0x%lx\n", (UINTN) NsCommBufMmramRange->PhysicalSize)); + DEBUG ((DEBUG_INFO, "mNsCommBuffer.PhysicalStart - 0x%lx\n", (UINTN)NsCommBufMmramRange->PhysicalStart)); + DEBUG ((DEBUG_INFO, "mNsCommBuffer.PhysicalSize - 0x%lx\n", (UINTN)NsCommBufMmramRange->PhysicalSize)); - CopyMem (&mNsCommBuffer, NsCommBufMmramRange, sizeof(EFI_MMRAM_DESCRIPTOR)); + CopyMem (&mNsCommBuffer, NsCommBufMmramRange, sizeof (EFI_MMRAM_DESCRIPTOR)); DEBUG ((DEBUG_INFO, "mNsCommBuffer: 0x%016lx - 0x%lx\n", mNsCommBuffer.CpuStart, mNsCommBuffer.PhysicalSize)); // @@ -192,7 +194,7 @@ StandaloneMmCpuInitialize ( Status = GetGuidedHobData ( HobStart, &gMpInformationHobGuid, - (VOID **) &MpInformationHobData + (VOID **)&MpInformationHobData ); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_INFO, "MpInformationHob extraction failed - 0x%x\n", Status)); @@ -206,11 +208,11 @@ StandaloneMmCpuInitialize ( // MpInfoSize = sizeof (MP_INFORMATION_HOB_DATA) + (sizeof (EFI_PROCESSOR_INFORMATION) * - MpInformationHobData->NumberOfProcessors); + MpInformationHobData->NumberOfProcessors); Status = mMmst->MmAllocatePool ( EfiRuntimeServicesData, MpInfoSize, - (VOID **) &mMpInformationHobData + (VOID **)&mMpInformationHobData ); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_INFO, "mMpInformationHobData mem alloc failed - 0x%x\n", Status)); @@ -220,15 +222,21 @@ StandaloneMmCpuInitialize ( CopyMem (mMpInformationHobData, MpInformationHobData, MpInfoSize); // Print MP information - DEBUG ((DEBUG_INFO, "mMpInformationHobData: 0x%016lx - 0x%lx\n", - mMpInformationHobData->NumberOfProcessors, - mMpInformationHobData->NumberOfEnabledProcessors)); + DEBUG (( + DEBUG_INFO, + "mMpInformationHobData: 0x%016lx - 0x%lx\n", + mMpInformationHobData->NumberOfProcessors, + mMpInformationHobData->NumberOfEnabledProcessors + )); for (Index = 0; Index < mMpInformationHobData->NumberOfProcessors; Index++) { - DEBUG ((DEBUG_INFO, "mMpInformationHobData[0x%lx]: %d, %d, %d\n", - mMpInformationHobData->ProcessorInfoBuffer[Index].ProcessorId, - mMpInformationHobData->ProcessorInfoBuffer[Index].Location.Package, - mMpInformationHobData->ProcessorInfoBuffer[Index].Location.Core, - mMpInformationHobData->ProcessorInfoBuffer[Index].Location.Thread)); + DEBUG (( + DEBUG_INFO, + "mMpInformationHobData[0x%lx]: %d, %d, %d\n", + mMpInformationHobData->ProcessorInfoBuffer[Index].ProcessorId, + mMpInformationHobData->ProcessorInfoBuffer[Index].Location.Package, + mMpInformationHobData->ProcessorInfoBuffer[Index].Location.Core, + mMpInformationHobData->ProcessorInfoBuffer[Index].Location.Thread + )); } // @@ -240,11 +248,12 @@ StandaloneMmCpuInitialize ( Status = mMmst->MmAllocatePool ( EfiRuntimeServicesData, ArraySize, - (VOID **) &PerCpuGuidedEventContext + (VOID **)&PerCpuGuidedEventContext ); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_INFO, "PerCpuGuidedEventContext mem alloc failed - 0x%x\n", Status)); return Status; } + return Status; } diff --git a/StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.h b/StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.h index 6f7a3ccd9c..251765eddf 100644 --- a/StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.h +++ b/StandaloneMmPkg/Drivers/StandaloneMmCpu/StandaloneMmCpu.h @@ -18,20 +18,20 @@ // // CPU driver initialization specific declarations // -extern EFI_MM_SYSTEM_TABLE *mMmst; +extern EFI_MM_SYSTEM_TABLE *mMmst; // // CPU State Save protocol specific declarations // -extern EFI_MM_CPU_PROTOCOL mMmCpuState; +extern EFI_MM_CPU_PROTOCOL mMmCpuState; // // MM event handling specific declarations // -extern EFI_MM_COMMUNICATE_HEADER **PerCpuGuidedEventContext; -extern EFI_MMRAM_DESCRIPTOR mNsCommBuffer; -extern MP_INFORMATION_HOB_DATA *mMpInformationHobData; -extern EFI_MM_CONFIGURATION_PROTOCOL mMmConfig; +extern EFI_MM_COMMUNICATE_HEADER **PerCpuGuidedEventContext; +extern EFI_MMRAM_DESCRIPTOR mNsCommBuffer; +extern MP_INFORMATION_HOB_DATA *mMpInformationHobData; +extern EFI_MM_CONFIGURATION_PROTOCOL mMmConfig; /** The PI Standalone MM entry point for the TF-A CPU driver. @@ -48,9 +48,9 @@ extern EFI_MM_CONFIGURATION_PROTOCOL mMmConfig; **/ EFI_STATUS PiMmStandaloneArmTfCpuDriverEntry ( - IN UINTN EventId, - IN UINTN CpuNumber, - IN UINTN NsCommBufferAddr + IN UINTN EventId, + IN UINTN CpuNumber, + IN UINTN NsCommBufferAddr ); /** @@ -72,10 +72,10 @@ PiMmStandaloneArmTfCpuDriverEntry ( EFI_STATUS EFIAPI PiMmCpuTpFwRootMmiHandler ( - IN EFI_HANDLE DispatchHandle, - IN CONST VOID *Context OPTIONAL, - IN OUT VOID *CommBuffer OPTIONAL, - IN OUT UINTN *CommBufferSize OPTIONAL + IN EFI_HANDLE DispatchHandle, + IN CONST VOID *Context OPTIONAL, + IN OUT VOID *CommBuffer OPTIONAL, + IN OUT UINTN *CommBufferSize OPTIONAL ); #endif diff --git a/StandaloneMmPkg/Include/Guid/MmCoreData.h b/StandaloneMmPkg/Include/Guid/MmCoreData.h index f112a752c3..b8be92c6ab 100644 --- a/StandaloneMmPkg/Include/Guid/MmCoreData.h +++ b/StandaloneMmPkg/Include/Guid/MmCoreData.h @@ -13,16 +13,15 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #define MM_CORE_DATA_HOB_GUID \ { 0xa160bf99, 0x2aa4, 0x4d7d, { 0x99, 0x93, 0x89, 0x9c, 0xb1, 0x2d, 0xf3, 0x76 }} -extern EFI_GUID gMmCoreDataHobGuid; +extern EFI_GUID gMmCoreDataHobGuid; typedef struct { // // Address pointer to MM_CORE_PRIVATE_DATA // - EFI_PHYSICAL_ADDRESS Address; + EFI_PHYSICAL_ADDRESS Address; } MM_CORE_DATA_HOB_DATA; - /// /// Define values for the communications buffer used when gEfiEventDxeDispatchGuid is /// event signaled. This event is signaled by the DXE Core each time the DXE Core @@ -55,19 +54,19 @@ typedef struct { /// thos structure. /// typedef struct { - UINT64 Signature; + UINT64 Signature; /// /// The number of MMRAM ranges passed from the MM IPL to the MM Core. The MM /// Core uses these ranges of MMRAM to initialize the MM Core memory manager. /// - UINT64 MmramRangeCount; + UINT64 MmramRangeCount; /// /// A table of MMRAM ranges passed from the MM IPL to the MM Core. The MM /// Core uses these ranges of MMRAM to initialize the MM Core memory manager. /// - EFI_PHYSICAL_ADDRESS MmramRanges; + EFI_PHYSICAL_ADDRESS MmramRanges; /// /// The MM Foundation Entry Point. The MM Core fills in this field when the @@ -78,50 +77,50 @@ typedef struct { /// the MM Foundation Entry Point as soon as the MM Configuration Protocol is /// available. /// - EFI_PHYSICAL_ADDRESS MmEntryPoint; + EFI_PHYSICAL_ADDRESS MmEntryPoint; /// /// Boolean flag set to TRUE while an MMI is being processed by the MM Core. /// - BOOLEAN MmEntryPointRegistered; + BOOLEAN MmEntryPointRegistered; /// /// Boolean flag set to TRUE while an MMI is being processed by the MM Core. /// - BOOLEAN InMm; + BOOLEAN InMm; /// /// This field is set by the MM Core then the MM Core is initialized. This field is /// used by the MM Base 2 Protocol and MM Communication Protocol implementations in /// the MM IPL. /// - EFI_PHYSICAL_ADDRESS Mmst; + EFI_PHYSICAL_ADDRESS Mmst; /// /// This field is used by the MM Communication Protocol to pass a buffer into /// a software MMI handler and for the software MMI handler to pass a buffer back to /// the caller of the MM Communication Protocol. /// - EFI_PHYSICAL_ADDRESS CommunicationBuffer; + EFI_PHYSICAL_ADDRESS CommunicationBuffer; /// /// This field is used by the MM Communication Protocol to pass the size of a buffer, /// in bytes, into a software MMI handler and for the software MMI handler to pass the /// size, in bytes, of a buffer back to the caller of the MM Communication Protocol. /// - UINT64 BufferSize; + UINT64 BufferSize; /// /// This field is used by the MM Communication Protocol to pass the return status from /// a software MMI handler back to the caller of the MM Communication Protocol. /// - UINT64 ReturnStatus; + UINT64 ReturnStatus; - EFI_PHYSICAL_ADDRESS MmCoreImageBase; - UINT64 MmCoreImageSize; - EFI_PHYSICAL_ADDRESS MmCoreEntryPoint; + EFI_PHYSICAL_ADDRESS MmCoreImageBase; + UINT64 MmCoreImageSize; + EFI_PHYSICAL_ADDRESS MmCoreEntryPoint; - EFI_PHYSICAL_ADDRESS StandaloneBfvAddress; + EFI_PHYSICAL_ADDRESS StandaloneBfvAddress; } MM_CORE_PRIVATE_DATA; #endif diff --git a/StandaloneMmPkg/Include/Guid/MmFvDispatch.h b/StandaloneMmPkg/Include/Guid/MmFvDispatch.h index 643f6e65f9..6ddc89bb87 100644 --- a/StandaloneMmPkg/Include/Guid/MmFvDispatch.h +++ b/StandaloneMmPkg/Include/Guid/MmFvDispatch.h @@ -14,19 +14,19 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #define MM_FV_DISPATCH_GUID \ { 0xb65694cc, 0x9e3, 0x4c3b, { 0xb5, 0xcd, 0x5, 0xf4, 0x4d, 0x3c, 0xdb, 0xff }} -extern EFI_GUID gMmFvDispatchGuid; +extern EFI_GUID gMmFvDispatchGuid; #pragma pack(1) typedef struct { - EFI_PHYSICAL_ADDRESS Address; - UINT64 Size; + EFI_PHYSICAL_ADDRESS Address; + UINT64 Size; } EFI_MM_COMMUNICATE_FV_DISPATCH_DATA; typedef struct { - EFI_GUID HeaderGuid; - UINTN MessageLength; - EFI_MM_COMMUNICATE_FV_DISPATCH_DATA Data; + EFI_GUID HeaderGuid; + UINTN MessageLength; + EFI_MM_COMMUNICATE_FV_DISPATCH_DATA Data; } EFI_MM_COMMUNICATE_FV_DISPATCH; #pragma pack() diff --git a/StandaloneMmPkg/Include/Guid/MmramMemoryReserve.h b/StandaloneMmPkg/Include/Guid/MmramMemoryReserve.h index 898865ae6e..1159d3adcf 100644 --- a/StandaloneMmPkg/Include/Guid/MmramMemoryReserve.h +++ b/StandaloneMmPkg/Include/Guid/MmramMemoryReserve.h @@ -42,15 +42,14 @@ typedef struct { /// In Framework MM CIS 0.91 specification, it defines the field type as UINTN. /// However, HOBs are supposed to be CPU neutral, so UINT32 should be used instead. /// - UINT32 NumberOfMmReservedRegions; + UINT32 NumberOfMmReservedRegions; /// /// Used throughout this protocol to describe the candidate /// regions for MMRAM that are supported by this platform. /// - EFI_MMRAM_DESCRIPTOR Descriptor[1]; + EFI_MMRAM_DESCRIPTOR Descriptor[1]; } EFI_MMRAM_HOB_DESCRIPTOR_BLOCK; -extern EFI_GUID gEfiMmPeiSmramMemoryReserveGuid; +extern EFI_GUID gEfiMmPeiSmramMemoryReserveGuid; #endif - diff --git a/StandaloneMmPkg/Include/Guid/MpInformation.h b/StandaloneMmPkg/Include/Guid/MpInformation.h index e3a916dfc5..dbf88d12de 100644 --- a/StandaloneMmPkg/Include/Guid/MpInformation.h +++ b/StandaloneMmPkg/Include/Guid/MpInformation.h @@ -24,12 +24,12 @@ #pragma pack(1) typedef struct { - UINT64 NumberOfProcessors; - UINT64 NumberOfEnabledProcessors; - EFI_PROCESSOR_INFORMATION ProcessorInfoBuffer[]; + UINT64 NumberOfProcessors; + UINT64 NumberOfEnabledProcessors; + EFI_PROCESSOR_INFORMATION ProcessorInfoBuffer[]; } MP_INFORMATION_HOB_DATA; #pragma pack() -extern EFI_GUID gMpInformationHobGuid; +extern EFI_GUID gMpInformationHobGuid; #endif diff --git a/StandaloneMmPkg/Include/Library/Arm/StandaloneMmCoreEntryPoint.h b/StandaloneMmPkg/Include/Library/Arm/StandaloneMmCoreEntryPoint.h index c44f7066c6..4593609dfc 100644 --- a/StandaloneMmPkg/Include/Library/Arm/StandaloneMmCoreEntryPoint.h +++ b/StandaloneMmPkg/Include/Library/Arm/StandaloneMmCoreEntryPoint.h @@ -16,52 +16,52 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #define CPU_INFO_FLAG_PRIMARY_CPU 0x00000001 typedef struct { - UINT8 Type; /* type of the structure */ - UINT8 Version; /* version of this structure */ - UINT16 Size; /* size of this structure in bytes */ - UINT32 Attr; /* attributes: unused bits SBZ */ + UINT8 Type; /* type of the structure */ + UINT8 Version; /* version of this structure */ + UINT16 Size; /* size of this structure in bytes */ + UINT32 Attr; /* attributes: unused bits SBZ */ } EFI_PARAM_HEADER; typedef struct { - UINT64 Mpidr; - UINT32 LinearId; - UINT32 Flags; + UINT64 Mpidr; + UINT32 LinearId; + UINT32 Flags; } EFI_SECURE_PARTITION_CPU_INFO; typedef struct { - EFI_PARAM_HEADER Header; - UINT64 SpMemBase; - UINT64 SpMemLimit; - UINT64 SpImageBase; - UINT64 SpStackBase; - UINT64 SpHeapBase; - UINT64 SpNsCommBufBase; - UINT64 SpSharedBufBase; - UINT64 SpImageSize; - UINT64 SpPcpuStackSize; - UINT64 SpHeapSize; - UINT64 SpNsCommBufSize; - UINT64 SpPcpuSharedBufSize; - UINT32 NumSpMemRegions; - UINT32 NumCpus; - EFI_SECURE_PARTITION_CPU_INFO *CpuInfo; + EFI_PARAM_HEADER Header; + UINT64 SpMemBase; + UINT64 SpMemLimit; + UINT64 SpImageBase; + UINT64 SpStackBase; + UINT64 SpHeapBase; + UINT64 SpNsCommBufBase; + UINT64 SpSharedBufBase; + UINT64 SpImageSize; + UINT64 SpPcpuStackSize; + UINT64 SpHeapSize; + UINT64 SpNsCommBufSize; + UINT64 SpPcpuSharedBufSize; + UINT32 NumSpMemRegions; + UINT32 NumCpus; + EFI_SECURE_PARTITION_CPU_INFO *CpuInfo; } EFI_SECURE_PARTITION_BOOT_INFO; typedef EFI_STATUS (*PI_MM_ARM_TF_CPU_DRIVER_ENTRYPOINT) ( - IN UINTN EventId, - IN UINTN CpuNumber, - IN UINTN NsCommBufferAddr + IN UINTN EventId, + IN UINTN CpuNumber, + IN UINTN NsCommBufferAddr ); typedef struct { - PI_MM_ARM_TF_CPU_DRIVER_ENTRYPOINT *ArmTfCpuDriverEpPtr; + PI_MM_ARM_TF_CPU_DRIVER_ENTRYPOINT *ArmTfCpuDriverEpPtr; } ARM_TF_CPU_DRIVER_EP_DESCRIPTOR; typedef RETURN_STATUS (*REGION_PERMISSION_UPDATE_FUNC) ( - IN EFI_PHYSICAL_ADDRESS BaseAddress, - IN UINT64 Length + IN EFI_PHYSICAL_ADDRESS BaseAddress, + IN UINT64 Length ); /** @@ -82,16 +82,15 @@ typedef RETURN_STATUS (*REGION_PERMISSION_UPDATE_FUNC) ( 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 ); - /** Privileged firmware assigns RO & Executable attributes to all memory occupied by the Boot Firmware Volume. This function locates the section information of @@ -108,14 +107,13 @@ UpdateMmFoundationPeCoffPermissions ( 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 ); - /** Privileged firmware assigns RO & Executable attributes to all memory occupied by the Boot Firmware Volume. This function locates the Standalone MM Core @@ -130,12 +128,11 @@ GetStandaloneMmCorePeCoffSections ( 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 ); - /** Use the boot information passed by privileged firmware to populate a HOB list suitable for consumption by the MM Core and drivers. @@ -148,11 +145,10 @@ LocateStandaloneMmCorePeCoffData ( VOID * EFIAPI 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 ); - /** The entry point of Standalone MM Foundation. @@ -171,7 +167,6 @@ _ModuleEntryPoint ( IN UINT64 cookie2 ); - /** Auto generated function that calls the library constructors for all of the module's dependent libraries. @@ -191,11 +186,10 @@ _ModuleEntryPoint ( VOID EFIAPI ProcessLibraryConstructorList ( - IN EFI_HANDLE ImageHandle, + IN EFI_HANDLE ImageHandle, IN EFI_MM_SYSTEM_TABLE *MmSystemTable ); - /** Auto generated function that calls a set of module entry points. diff --git a/StandaloneMmPkg/Include/Library/FvLib.h b/StandaloneMmPkg/Include/Library/FvLib.h index 4ef2c8540a..1eb9ea7e04 100644 --- a/StandaloneMmPkg/Include/Library/FvLib.h +++ b/StandaloneMmPkg/Include/Library/FvLib.h @@ -52,9 +52,9 @@ FfsFindNextFile ( 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 ); /** @@ -73,10 +73,10 @@ FfsFindSection ( 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 ); /** @@ -95,10 +95,10 @@ FindFfsSectionInSections ( EFI_STATUS EFIAPI FfsFindSectionData ( - IN EFI_SECTION_TYPE SectionType, - IN EFI_FFS_FILE_HEADER *FfsFileHeader, - OUT VOID **SectionData, - OUT UINTN *SectionDataSize + IN EFI_SECTION_TYPE SectionType, + IN EFI_FFS_FILE_HEADER *FfsFileHeader, + OUT VOID **SectionData, + OUT UINTN *SectionDataSize ); #endif diff --git a/StandaloneMmPkg/Include/Library/StandaloneMmCoreEntryPoint.h b/StandaloneMmPkg/Include/Library/StandaloneMmCoreEntryPoint.h index 9799604e85..4e88482230 100644 --- a/StandaloneMmPkg/Include/Library/StandaloneMmCoreEntryPoint.h +++ b/StandaloneMmPkg/Include/Library/StandaloneMmCoreEntryPoint.h @@ -16,7 +16,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent /// extern VOID *gHobList; - /** The entry point of PE/COFF Image for the STANDALONE MM Core. @@ -35,7 +34,6 @@ _ModuleEntryPoint ( IN VOID *HobStart ); - /** Required by the EBC compiler and identical in functionality to _ModuleEntryPoint(). @@ -50,7 +48,6 @@ EfiMain ( IN VOID *HobStart ); - /** Auto generated function that calls the library constructors for all of the module's dependent libraries. @@ -70,11 +67,10 @@ EfiMain ( VOID EFIAPI ProcessLibraryConstructorList ( - IN EFI_HANDLE ImageHandle, - IN EFI_MM_SYSTEM_TABLE *MmSystemTable + IN EFI_HANDLE ImageHandle, + IN EFI_MM_SYSTEM_TABLE *MmSystemTable ); - /** Autogenerated function that calls a set of module entry points. diff --git a/StandaloneMmPkg/Include/StandaloneMm.h b/StandaloneMmPkg/Include/StandaloneMm.h index 2968b32b33..05f1da593a 100644 --- a/StandaloneMmPkg/Include/StandaloneMm.h +++ b/StandaloneMmPkg/Include/StandaloneMm.h @@ -15,14 +15,14 @@ SPDX-License-Identifier: BSD-2-Clause-Patent typedef EFI_STATUS -(EFIAPI *MM_IMAGE_ENTRY_POINT) ( +(EFIAPI *MM_IMAGE_ENTRY_POINT)( IN EFI_HANDLE ImageHandle, IN EFI_MM_SYSTEM_TABLE *MmSystemTable ); typedef EFI_STATUS -(EFIAPI *STANDALONE_MM_FOUNDATION_ENTRY_POINT) ( +(EFIAPI *STANDALONE_MM_FOUNDATION_ENTRY_POINT)( IN VOID *HobStart ); diff --git a/StandaloneMmPkg/Library/FvLib/FvLib.c b/StandaloneMmPkg/Library/FvLib/FvLib.c index 94139ae389..aa36a35eff 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 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(). diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/Arm/StandaloneMmCoreHobLib.c b/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/Arm/StandaloneMmCoreHobLib.c index 0ec2d4ad6f..1550e1babc 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 3f1e0cb749..1b7141a3e3 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 8c53503231..df5416bc2a 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 333ed40469..3c5baa1e5b 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 ba5470dd71..2246823886 100644 --- a/StandaloneMmPkg/Library/StandaloneMmCoreMemoryAllocationLib/StandaloneMmCoreMemoryAllocationLib.c +++ b/StandaloneMmPkg/Library/StandaloneMmCoreMemoryAllocationLib/StandaloneMmCoreMemoryAllocationLib.c @@ -17,7 +17,7 @@ #include #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 ca7e2f84cd..ee61bdd227 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 fa7df46413..297cfae916 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 2737f95315..e639327251 100644 --- a/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.c +++ b/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.c @@ -13,15 +13,14 @@ **/ - #include #include #include #include -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 1a97854171..c309d1bc6a 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 a2819e1967..b38b32b27f 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 ca8b1244a3..426fd8dd74 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 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 9ab7b106da..f647fc5258 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 (