X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=ArmPlatformPkg%2FPrePi%2FPrePi.c;h=02cff7ddc20444a12389abd2b90a3d1c528464fa;hb=42e8bc7d16aa2ef8d65a19b327d33c64cae54a9c;hp=5a88b47fe92d0d52c24a25a03a7e2f768a2ce20a;hpb=d269095b712ba45fd4aca55331b5e6f3045ce1ad;p=mirror_edk2.git diff --git a/ArmPlatformPkg/PrePi/PrePi.c b/ArmPlatformPkg/PrePi/PrePi.c old mode 100755 new mode 100644 index 5a88b47fe9..02cff7ddc2 --- a/ArmPlatformPkg/PrePi/PrePi.c +++ b/ArmPlatformPkg/PrePi/PrePi.c @@ -1,6 +1,6 @@ /** @file * -* Copyright (c) 2011, ARM Limited. All rights reserved. +* Copyright (c) 2011-2017, ARM Limited. All rights reserved. * * This program and the accompanying materials * are licensed and made available under the terms and conditions of the BSD License @@ -16,87 +16,129 @@ #include #include -#include #include -#include +#include #include #include #include -#include +#include +#include #include "PrePi.h" -#include "LzmaDecompress.h" -VOID -PrePiCommonExceptionEntry ( - IN UINT32 Entry, - IN UINT32 LR - ); +#define IS_XIP() (((UINT64)FixedPcdGet64 (PcdFdBaseAddress) > mSystemMemoryEnd) || \ + ((FixedPcdGet64 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) < FixedPcdGet64 (PcdSystemMemoryBase))) -EFI_STATUS -EFIAPI -ExtractGuidedSectionLibConstructor ( - VOID - ); +UINT64 mSystemMemoryEnd = FixedPcdGet64(PcdSystemMemoryBase) + + FixedPcdGet64(PcdSystemMemorySize) - 1; EFI_STATUS -EFIAPI -LzmaDecompressLibConstructor ( - VOID - ); +GetPlatformPpi ( + IN EFI_GUID *PpiGuid, + OUT VOID **Ppi + ) +{ + UINTN PpiListSize; + UINTN PpiListCount; + EFI_PEI_PPI_DESCRIPTOR *PpiList; + UINTN Index; + + PpiListSize = 0; + ArmPlatformGetPlatformPpiList (&PpiListSize, &PpiList); + PpiListCount = PpiListSize / sizeof(EFI_PEI_PPI_DESCRIPTOR); + for (Index = 0; Index < PpiListCount; Index++, PpiList++) { + if (CompareGuid (PpiList->Guid, PpiGuid) == TRUE) { + *Ppi = PpiList->Ppi; + return EFI_SUCCESS; + } + } + + return EFI_NOT_FOUND; +} VOID PrePiMain ( IN UINTN UefiMemoryBase, + IN UINTN StacksBase, IN UINT64 StartTimeStamp ) { - EFI_HOB_HANDOFF_INFO_TABLE** PrePiHobBase; + EFI_HOB_HANDOFF_INFO_TABLE* HobList; + ARM_MP_CORE_INFO_PPI* ArmMpCoreInfoPpi; + UINTN ArmCoreCount; + ARM_CORE_INFO* ArmCoreInfoTable; EFI_STATUS Status; CHAR8 Buffer[100]; UINTN CharCount; - UINTN UefiMemoryTop; UINTN StacksSize; - UINTN StacksBase; + FIRMWARE_SEC_PERFORMANCE Performance; - // Enable program flow prediction, if supported. - ArmEnableBranchPrediction (); + // If ensure the FD is either part of the System Memory or totally outside of the System Memory (XIP) + ASSERT (IS_XIP() || + ((FixedPcdGet64 (PcdFdBaseAddress) >= FixedPcdGet64 (PcdSystemMemoryBase)) && + ((UINT64)(FixedPcdGet64 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) <= (UINT64)mSystemMemoryEnd))); - if (FixedPcdGet32(PcdVFPEnabled)) { - ArmEnableVFP(); - } + // Initialize the architecture specific bits + ArchInitialize (); // Initialize the Serial Port SerialPortInitialize (); - CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"UEFI firmware built at %a on %a\n\r",__TIME__, __DATE__); + CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"UEFI firmware (version %s built at %a on %a)\n\r", + (CHAR16*)PcdGetPtr(PcdFirmwareVersionString), __TIME__, __DATE__); SerialPortWrite ((UINT8 *) Buffer, CharCount); // Initialize the Debug Agent for Source Level Debugging InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC, NULL, NULL); SaveAndSetDebugTimerInterrupt (TRUE); - PrePiHobBase = (EFI_HOB_HANDOFF_INFO_TABLE**)(PcdGet32 (PcdCPUCoresNonSecStackBase) + (PcdGet32 (PcdCPUCoresNonSecStackSize) / 2) - PcdGet32 (PcdHobListPtrGlobalOffset)); - - UefiMemoryTop = UefiMemoryBase + FixedPcdGet32 (PcdSystemMemoryUefiRegionSize); - StacksSize = PcdGet32 (PcdCPUCoresNonSecStackSize) * PcdGet32 (PcdMPCoreMaxCores); - StacksBase = UefiMemoryTop - StacksSize; - // Declare the PI/UEFI memory region - *PrePiHobBase = HobConstructor ( + HobList = HobConstructor ( (VOID*)UefiMemoryBase, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize), (VOID*)UefiMemoryBase, (VOID*)StacksBase // The top of the UEFI Memory is reserved for the stacks ); + PrePeiSetHobList (HobList); // Initialize MMU and Memory HOBs (Resource Descriptor HOBs) Status = MemoryPeim (UefiMemoryBase, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize)); ASSERT_EFI_ERROR (Status); // Create the Stacks HOB (reserve the memory for all stacks) + if (ArmIsMpCore ()) { + StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize) + + ((FixedPcdGet32 (PcdCoreCount) - 1) * FixedPcdGet32 (PcdCPUCoreSecondaryStackSize)); + } else { + StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize); + } BuildStackHob (StacksBase, StacksSize); + //TODO: Call CpuPei as a library + BuildCpuHob (PcdGet8 (PcdPrePiCpuMemorySize), PcdGet8 (PcdPrePiCpuIoSize)); + + if (ArmIsMpCore ()) { + // Only MP Core platform need to produce gArmMpCoreInfoPpiGuid + Status = GetPlatformPpi (&gArmMpCoreInfoPpiGuid, (VOID**)&ArmMpCoreInfoPpi); + + // On MP Core Platform we must implement the ARM MP Core Info PPI (gArmMpCoreInfoPpiGuid) + ASSERT_EFI_ERROR (Status); + + // Build the MP Core Info Table + ArmCoreCount = 0; + Status = ArmMpCoreInfoPpi->GetMpCoreInfo (&ArmCoreCount, &ArmCoreInfoTable); + if (!EFI_ERROR(Status) && (ArmCoreCount > 0)) { + // Build MPCore Info HOB + BuildGuidDataHob (&gArmMpCoreInfoGuid, ArmCoreInfoTable, sizeof (ARM_CORE_INFO) * ArmCoreCount); + } + } + + // Store timer value logged at the beginning of firmware image execution + Performance.ResetEnd = GetTimeInNanoSecond (StartTimeStamp); + + // Build SEC Performance Data Hob + BuildGuidDataHob (&gEfiFirmwarePerformanceGuid, &Performance, sizeof (Performance)); + // Set the Boot Mode SetBootMode (ArmPlatformGetBootMode ()); @@ -104,25 +146,11 @@ PrePiMain ( Status = PlatformPeim (); ASSERT_EFI_ERROR (Status); - BuildMemoryTypeInformationHob (); - - InitializeDebugAgent (DEBUG_AGENT_INIT_PREMEM_SEC, NULL, NULL); - SaveAndSetDebugTimerInterrupt (TRUE); - // Now, the HOB List has been initialized, we can register performance information PERF_START (NULL, "PEI", NULL, StartTimeStamp); // SEC phase needs to run library constructors by hand. - ExtractGuidedSectionLibConstructor (); - LzmaDecompressLibConstructor (); - - // Build HOBs to pass up our version of stuff the DXE Core needs to save space - BuildPeCoffLoaderHob (); - BuildExtractSectionHob ( - &gLzmaCustomDecompressGuid, - LzmaGuidedSectionGetInfo, - LzmaGuidedSectionExtraction - ); + ProcessLibraryConstructorList (); // Assume the FV that contains the SEC (our code) also contains a compressed FV. Status = DecompressFirstFv (); @@ -135,85 +163,56 @@ PrePiMain ( VOID CEntryPoint ( - IN UINTN CoreId, - IN UINTN UefiMemoryBase + IN UINTN MpId, + IN UINTN UefiMemoryBase, + IN UINTN StacksBase ) { UINT64 StartTimeStamp; - if ((CoreId == ARM_PRIMARY_CORE) && PerformanceMeasurementEnabled ()) { + // Initialize the platform specific controllers + ArmPlatformInitialize (MpId); + + if (ArmPlatformIsPrimaryCore (MpId) && PerformanceMeasurementEnabled ()) { // Initialize the Timer Library to setup the Timer HW controller TimerConstructor (); // We cannot call yet the PerformanceLib because the HOB List has not been initialized StartTimeStamp = GetPerformanceCounter (); + } else { + StartTimeStamp = 0; } - // Clean Data cache - ArmCleanInvalidateDataCache (); - + // Data Cache enabled on Primary core when MMU is enabled. + ArmDisableDataCache (); + // Invalidate Data cache + ArmInvalidateDataCache (); // Invalidate instruction cache ArmInvalidateInstructionCache (); - - //TODO:Drain Write Buffer - - // Enable Instruction & Data caches - ArmEnableDataCache (); + // Enable Instruction Caches on all cores. ArmEnableInstructionCache (); - // Write VBAR - The Vector table must be 32-byte aligned - ASSERT (((UINT32)PrePiVectorTable & ((1 << 5)-1)) == 0); - ArmWriteVBar ((UINT32)PrePiVectorTable); + // Define the Global Variable region when we are not running in XIP + if (!IS_XIP()) { + if (ArmPlatformIsPrimaryCore (MpId)) { + if (ArmIsMpCore()) { + // Signal the Global Variable Region is defined (event: ARM_CPU_EVENT_DEFAULT) + ArmCallSEV (); + } + } else { + // Wait the Primay core has defined the address of the Global Variable region (event: ARM_CPU_EVENT_DEFAULT) + ArmCallWFE (); + } + } // If not primary Jump to Secondary Main - if (CoreId == ARM_PRIMARY_CORE) { + if (ArmPlatformIsPrimaryCore (MpId)) { // Goto primary Main. - PrimaryMain (UefiMemoryBase, StartTimeStamp); + PrimaryMain (UefiMemoryBase, StacksBase, StartTimeStamp); } else { - SecondaryMain (CoreId); + SecondaryMain (MpId); } // DXE Core should always load and never return ASSERT (FALSE); } -VOID -PrePiCommonExceptionEntry ( - IN UINT32 Entry, - IN UINT32 LR - ) -{ - CHAR8 Buffer[100]; - UINTN CharCount; - - switch (Entry) { - case 0: - CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Reset Exception at 0x%X\n\r",LR); - break; - case 1: - CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Undefined Exception at 0x%X\n\r",LR); - break; - case 2: - CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"SWI Exception at 0x%X\n\r",LR); - break; - case 3: - CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"PrefetchAbort Exception at 0x%X\n\r",LR); - break; - case 4: - CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"DataAbort Exception at 0x%X\n\r",LR); - break; - case 5: - CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Reserved Exception at 0x%X\n\r",LR); - break; - case 6: - CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"IRQ Exception at 0x%X\n\r",LR); - break; - case 7: - CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"FIQ Exception at 0x%X\n\r",LR); - break; - default: - CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Unknown Exception at 0x%X\n\r",LR); - break; - } - SerialPortWrite ((UINT8 *) Buffer, CharCount); - while(1); -}