3 * Copyright (c) 2011-2017, ARM Limited. All rights reserved.
5 * SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include <Library/CacheMaintenanceLib.h>
12 #include <Library/DebugAgentLib.h>
13 #include <Library/PrePiLib.h>
14 #include <Library/PrintLib.h>
15 #include <Library/PrePiHobListPointerLib.h>
16 #include <Library/TimerLib.h>
17 #include <Library/PerformanceLib.h>
19 #include <Ppi/GuidedSectionExtraction.h>
20 #include <Ppi/ArmMpCoreInfo.h>
21 #include <Ppi/SecPerformance.h>
25 #define IS_XIP() (((UINT64)FixedPcdGet64 (PcdFdBaseAddress) > mSystemMemoryEnd) || \
26 ((FixedPcdGet64 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) <= FixedPcdGet64 (PcdSystemMemoryBase)))
28 UINT64 mSystemMemoryEnd
= FixedPcdGet64(PcdSystemMemoryBase
) +
29 FixedPcdGet64(PcdSystemMemorySize
) - 1;
39 EFI_PEI_PPI_DESCRIPTOR
*PpiList
;
43 ArmPlatformGetPlatformPpiList (&PpiListSize
, &PpiList
);
44 PpiListCount
= PpiListSize
/ sizeof(EFI_PEI_PPI_DESCRIPTOR
);
45 for (Index
= 0; Index
< PpiListCount
; Index
++, PpiList
++) {
46 if (CompareGuid (PpiList
->Guid
, PpiGuid
) == TRUE
) {
57 IN UINTN UefiMemoryBase
,
59 IN UINT64 StartTimeStamp
62 EFI_HOB_HANDOFF_INFO_TABLE
* HobList
;
63 ARM_MP_CORE_INFO_PPI
* ArmMpCoreInfoPpi
;
65 ARM_CORE_INFO
* ArmCoreInfoTable
;
70 FIRMWARE_SEC_PERFORMANCE Performance
;
72 // If ensure the FD is either part of the System Memory or totally outside of the System Memory (XIP)
74 ((FixedPcdGet64 (PcdFdBaseAddress
) >= FixedPcdGet64 (PcdSystemMemoryBase
)) &&
75 ((UINT64
)(FixedPcdGet64 (PcdFdBaseAddress
) + FixedPcdGet32 (PcdFdSize
)) <= (UINT64
)mSystemMemoryEnd
)));
77 // Initialize the architecture specific bits
80 // Initialize the Serial Port
81 SerialPortInitialize ();
82 CharCount
= AsciiSPrint (Buffer
,sizeof (Buffer
),"UEFI firmware (version %s built at %a on %a)\n\r",
83 (CHAR16
*)PcdGetPtr(PcdFirmwareVersionString
), __TIME__
, __DATE__
);
84 SerialPortWrite ((UINT8
*) Buffer
, CharCount
);
86 // Initialize the Debug Agent for Source Level Debugging
87 InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC
, NULL
, NULL
);
88 SaveAndSetDebugTimerInterrupt (TRUE
);
90 // Declare the PI/UEFI memory region
91 HobList
= HobConstructor (
92 (VOID
*)UefiMemoryBase
,
93 FixedPcdGet32 (PcdSystemMemoryUefiRegionSize
),
94 (VOID
*)UefiMemoryBase
,
95 (VOID
*)StacksBase
// The top of the UEFI Memory is reserved for the stacks
97 PrePeiSetHobList (HobList
);
99 // Initialize MMU and Memory HOBs (Resource Descriptor HOBs)
100 Status
= MemoryPeim (UefiMemoryBase
, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize
));
101 ASSERT_EFI_ERROR (Status
);
103 // Create the Stacks HOB (reserve the memory for all stacks)
104 if (ArmIsMpCore ()) {
105 StacksSize
= PcdGet32 (PcdCPUCorePrimaryStackSize
) +
106 ((FixedPcdGet32 (PcdCoreCount
) - 1) * FixedPcdGet32 (PcdCPUCoreSecondaryStackSize
));
108 StacksSize
= PcdGet32 (PcdCPUCorePrimaryStackSize
);
110 BuildStackHob (StacksBase
, StacksSize
);
112 //TODO: Call CpuPei as a library
113 BuildCpuHob (ArmGetPhysicalAddressBits (), PcdGet8 (PcdPrePiCpuIoSize
));
115 if (ArmIsMpCore ()) {
116 // Only MP Core platform need to produce gArmMpCoreInfoPpiGuid
117 Status
= GetPlatformPpi (&gArmMpCoreInfoPpiGuid
, (VOID
**)&ArmMpCoreInfoPpi
);
119 // On MP Core Platform we must implement the ARM MP Core Info PPI (gArmMpCoreInfoPpiGuid)
120 ASSERT_EFI_ERROR (Status
);
122 // Build the MP Core Info Table
124 Status
= ArmMpCoreInfoPpi
->GetMpCoreInfo (&ArmCoreCount
, &ArmCoreInfoTable
);
125 if (!EFI_ERROR(Status
) && (ArmCoreCount
> 0)) {
126 // Build MPCore Info HOB
127 BuildGuidDataHob (&gArmMpCoreInfoGuid
, ArmCoreInfoTable
, sizeof (ARM_CORE_INFO
) * ArmCoreCount
);
131 // Store timer value logged at the beginning of firmware image execution
132 Performance
.ResetEnd
= GetTimeInNanoSecond (StartTimeStamp
);
134 // Build SEC Performance Data Hob
135 BuildGuidDataHob (&gEfiFirmwarePerformanceGuid
, &Performance
, sizeof (Performance
));
138 SetBootMode (ArmPlatformGetBootMode ());
140 // Initialize Platform HOBs (CpuHob and FvHob)
141 Status
= PlatformPeim ();
142 ASSERT_EFI_ERROR (Status
);
144 // Now, the HOB List has been initialized, we can register performance information
145 PERF_START (NULL
, "PEI", NULL
, StartTimeStamp
);
147 // SEC phase needs to run library constructors by hand.
148 ProcessLibraryConstructorList ();
150 // Assume the FV that contains the SEC (our code) also contains a compressed FV.
151 Status
= DecompressFirstFv ();
152 ASSERT_EFI_ERROR (Status
);
154 // Load the DXE Core and transfer control to it
155 Status
= LoadDxeCoreFromFv (NULL
, 0);
156 ASSERT_EFI_ERROR (Status
);
162 IN UINTN UefiMemoryBase
,
166 UINT64 StartTimeStamp
;
168 // Initialize the platform specific controllers
169 ArmPlatformInitialize (MpId
);
171 if (ArmPlatformIsPrimaryCore (MpId
) && PerformanceMeasurementEnabled ()) {
172 // Initialize the Timer Library to setup the Timer HW controller
174 // We cannot call yet the PerformanceLib because the HOB List has not been initialized
175 StartTimeStamp
= GetPerformanceCounter ();
180 // Data Cache enabled on Primary core when MMU is enabled.
181 ArmDisableDataCache ();
182 // Invalidate instruction cache
183 ArmInvalidateInstructionCache ();
184 // Enable Instruction Caches on all cores.
185 ArmEnableInstructionCache ();
187 // Define the Global Variable region when we are not running in XIP
189 if (ArmPlatformIsPrimaryCore (MpId
)) {
191 // Signal the Global Variable Region is defined (event: ARM_CPU_EVENT_DEFAULT)
195 // Wait the Primary core has defined the address of the Global Variable region (event: ARM_CPU_EVENT_DEFAULT)
200 // If not primary Jump to Secondary Main
201 if (ArmPlatformIsPrimaryCore (MpId
)) {
203 InvalidateDataCacheRange ((VOID
*)UefiMemoryBase
,
204 FixedPcdGet32 (PcdSystemMemoryUefiRegionSize
));
206 // Goto primary Main.
207 PrimaryMain (UefiMemoryBase
, StacksBase
, StartTimeStamp
);
209 SecondaryMain (MpId
);
212 // DXE Core should always load and never return