3 * Copyright (c) 2011-2014, ARM Limited. All rights reserved.
5 * This program and the accompanying materials
6 * are licensed and made available under the terms and conditions of the BSD License
7 * which accompanies this distribution. The full text of the license may be found at
8 * http://opensource.org/licenses/bsd-license.php
10 * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include <Library/PrePiLib.h>
18 #include <Library/PrintLib.h>
19 #include <Library/PeCoffGetEntryPointLib.h>
20 #include <Library/PrePiHobListPointerLib.h>
21 #include <Library/TimerLib.h>
22 #include <Library/PerformanceLib.h>
23 #include <Library/CacheMaintenanceLib.h>
25 #include <Ppi/GuidedSectionExtraction.h>
26 #include <Ppi/ArmMpCoreInfo.h>
27 #include <Guid/LzmaDecompress.h>
28 #include <Guid/ArmGlobalVariableHob.h>
31 #include "LzmaDecompress.h"
33 // Not used when PrePi in run in XIP mode
34 UINTN mGlobalVariableBase
= 0;
38 ExtractGuidedSectionLibConstructor (
44 LzmaDecompressLibConstructor (
50 BuildGlobalVariableHob (
51 IN EFI_PHYSICAL_ADDRESS GlobalVariableBase
,
52 IN UINT32 GlobalVariableSize
55 ARM_HOB_GLOBAL_VARIABLE
*Hob
;
57 Hob
= CreateHob (EFI_HOB_TYPE_GUID_EXTENSION
, sizeof (ARM_HOB_GLOBAL_VARIABLE
));
60 CopyGuid (&(Hob
->Header
.Name
), &gArmGlobalVariableGuid
);
61 Hob
->GlobalVariableBase
= GlobalVariableBase
;
62 Hob
->GlobalVariableSize
= GlobalVariableSize
;
73 EFI_PEI_PPI_DESCRIPTOR
*PpiList
;
77 ArmPlatformGetPlatformPpiList (&PpiListSize
, &PpiList
);
78 PpiListCount
= PpiListSize
/ sizeof(EFI_PEI_PPI_DESCRIPTOR
);
79 for (Index
= 0; Index
< PpiListCount
; Index
++, PpiList
++) {
80 if (CompareGuid (PpiList
->Guid
, PpiGuid
) == TRUE
) {
91 IN UINTN UefiMemoryBase
,
93 IN UINTN GlobalVariableBase
,
94 IN UINT64 StartTimeStamp
97 EFI_HOB_HANDOFF_INFO_TABLE
* HobList
;
103 // Initialize the architecture specific bits
106 // Declare the PI/UEFI memory region
107 HobList
= HobConstructor (
108 (VOID
*)UefiMemoryBase
,
109 FixedPcdGet32 (PcdSystemMemoryUefiRegionSize
),
110 (VOID
*)UefiMemoryBase
,
111 (VOID
*)StacksBase
// The top of the UEFI Memory is reserved for the stacks
113 PrePeiSetHobList (HobList
);
116 // Ensure that the loaded image is invalidated in the caches, so that any
117 // modifications we made with the caches and MMU off (such as the applied
118 // relocations) don't become invisible once we turn them on.
120 InvalidateDataCacheRange((VOID
*)(UINTN
)PcdGet64 (PcdFdBaseAddress
), PcdGet32 (PcdFdSize
));
122 // Initialize MMU and Memory HOBs (Resource Descriptor HOBs)
123 Status
= MemoryPeim (UefiMemoryBase
, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize
));
124 ASSERT_EFI_ERROR (Status
);
126 // Initialize the Serial Port
127 SerialPortInitialize ();
128 CharCount
= AsciiSPrint (Buffer
,sizeof (Buffer
),"UEFI firmware (version %s built at %a on %a)\n\r",
129 (CHAR16
*)PcdGetPtr(PcdFirmwareVersionString
), __TIME__
, __DATE__
);
130 SerialPortWrite ((UINT8
*) Buffer
, CharCount
);
132 // Create the Stacks HOB (reserve the memory for all stacks)
133 StacksSize
= PcdGet32 (PcdCPUCorePrimaryStackSize
);
134 BuildStackHob (StacksBase
, StacksSize
);
136 // Declare the Global Variable HOB
137 BuildGlobalVariableHob (GlobalVariableBase
, FixedPcdGet32 (PcdPeiGlobalVariableSize
));
139 //TODO: Call CpuPei as a library
140 BuildCpuHob (PcdGet8 (PcdPrePiCpuMemorySize
), PcdGet8 (PcdPrePiCpuIoSize
));
143 SetBootMode (ArmPlatformGetBootMode ());
145 // Initialize Platform HOBs (CpuHob and FvHob)
146 Status
= PlatformPeim ();
147 ASSERT_EFI_ERROR (Status
);
149 // Now, the HOB List has been initialized, we can register performance information
150 PERF_START (NULL
, "PEI", NULL
, StartTimeStamp
);
152 // SEC phase needs to run library constructors by hand.
153 ExtractGuidedSectionLibConstructor ();
154 LzmaDecompressLibConstructor ();
156 // Build HOBs to pass up our version of stuff the DXE Core needs to save space
157 BuildPeCoffLoaderHob ();
158 BuildExtractSectionHob (
159 &gLzmaCustomDecompressGuid
,
160 LzmaGuidedSectionGetInfo
,
161 LzmaGuidedSectionExtraction
164 // Assume the FV that contains the SEC (our code) also contains a compressed FV.
165 Status
= DecompressFirstFv ();
166 ASSERT_EFI_ERROR (Status
);
168 // Load the DXE Core and transfer control to it
169 Status
= LoadDxeCoreFromFv (NULL
, 0);
170 ASSERT_EFI_ERROR (Status
);
176 IN UINTN UefiMemoryBase
,
178 IN UINTN GlobalVariableBase
181 UINT64 StartTimeStamp
;
183 // Initialize the platform specific controllers
184 ArmPlatformInitialize (MpId
);
186 if (PerformanceMeasurementEnabled ()) {
187 // Initialize the Timer Library to setup the Timer HW controller
189 // We cannot call yet the PerformanceLib because the HOB List has not been initialized
190 StartTimeStamp
= GetPerformanceCounter ();
195 // Data Cache enabled on Primary core when MMU is enabled.
196 ArmDisableDataCache ();
197 // Invalidate Data cache
198 ArmInvalidateDataCache ();
199 // Invalidate instruction cache
200 ArmInvalidateInstructionCache ();
201 // Enable Instruction Caches on all cores.
202 ArmEnableInstructionCache ();
204 // Define the Global Variable region
205 mGlobalVariableBase
= GlobalVariableBase
;
207 PrePiMain (UefiMemoryBase
, StacksBase
, GlobalVariableBase
, StartTimeStamp
);
209 // DXE Core should always load and never return