]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/PrePi/PrePi.c
ArmPlatformPkg: Added Aarch64 support
[mirror_edk2.git] / ArmPlatformPkg / PrePi / PrePi.c
CommitLineData
cd872e40 1/** @file\r
2*\r
f437141a 3* Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
cd872e40 4*\r
5* This program and the accompanying materials\r
6* are licensed and made available under the terms and conditions of the BSD License\r
7* which accompanies this distribution. The full text of the license may be found at\r
8* http://opensource.org/licenses/bsd-license.php\r
9*\r
10* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12*\r
13**/\r
14\r
15#include <PiPei.h>\r
16\r
17#include <Library/DebugAgentLib.h>\r
18#include <Library/PrePiLib.h>\r
cd872e40 19#include <Library/PrintLib.h>\r
20#include <Library/PeCoffGetEntryPointLib.h>\r
37573927 21#include <Library/PrePiHobListPointerLib.h>\r
cd872e40 22#include <Library/TimerLib.h>\r
23#include <Library/PerformanceLib.h>\r
24\r
25#include <Ppi/GuidedSectionExtraction.h>\r
0dbbacdf 26#include <Ppi/ArmMpCoreInfo.h>\r
cd872e40 27#include <Guid/LzmaDecompress.h>\r
8fc38a3f 28#include <Guid/ArmGlobalVariableHob.h>\r
cd872e40 29\r
30#include "PrePi.h"\r
31#include "LzmaDecompress.h"\r
32\r
99565b88 33#define IS_XIP() (((UINT32)FixedPcdGet32 (PcdFdBaseAddress) > (UINT32)(FixedPcdGet32 (PcdSystemMemoryBase) + FixedPcdGet32 (PcdSystemMemorySize))) || \\r
8fc38a3f 34 ((FixedPcdGet32 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) < FixedPcdGet32 (PcdSystemMemoryBase)))\r
35\r
36// Not used when PrePi in run in XIP mode\r
37UINTN mGlobalVariableBase = 0;\r
38\r
cd872e40 39EFI_STATUS\r
40EFIAPI\r
41ExtractGuidedSectionLibConstructor (\r
42 VOID\r
43 );\r
44\r
45EFI_STATUS\r
46EFIAPI\r
47LzmaDecompressLibConstructor (\r
48 VOID\r
49 );\r
50\r
8fc38a3f 51VOID\r
52EFIAPI\r
53BuildGlobalVariableHob (\r
54 IN EFI_PHYSICAL_ADDRESS GlobalVariableBase,\r
55 IN UINT32 GlobalVariableSize\r
56 )\r
57{\r
58 ARM_HOB_GLOBAL_VARIABLE *Hob;\r
59\r
60 Hob = CreateHob (EFI_HOB_TYPE_GUID_EXTENSION, sizeof (ARM_HOB_GLOBAL_VARIABLE));\r
61 ASSERT(Hob != NULL);\r
62\r
63 CopyGuid (&(Hob->Header.Name), &gArmGlobalVariableGuid);\r
64 Hob->GlobalVariableBase = GlobalVariableBase;\r
65 Hob->GlobalVariableSize = GlobalVariableSize;\r
66}\r
67\r
0dbbacdf 68EFI_STATUS\r
69GetPlatformPpi (\r
70 IN EFI_GUID *PpiGuid,\r
71 OUT VOID **Ppi\r
72 )\r
73{\r
74 UINTN PpiListSize;\r
75 UINTN PpiListCount;\r
76 EFI_PEI_PPI_DESCRIPTOR *PpiList;\r
77 UINTN Index;\r
78\r
79 PpiListSize = 0;\r
80 ArmPlatformGetPlatformPpiList (&PpiListSize, &PpiList);\r
81 PpiListCount = PpiListSize / sizeof(EFI_PEI_PPI_DESCRIPTOR);\r
82 for (Index = 0; Index < PpiListCount; Index++, PpiList++) {\r
83 if (CompareGuid (PpiList->Guid, PpiGuid) == TRUE) {\r
84 *Ppi = PpiList->Ppi;\r
85 return EFI_SUCCESS;\r
86 }\r
87 }\r
88\r
89 return EFI_NOT_FOUND;\r
90}\r
91\r
cd872e40 92VOID\r
93PrePiMain (\r
94 IN UINTN UefiMemoryBase,\r
c524ffbb 95 IN UINTN StacksBase,\r
96 IN UINTN GlobalVariableBase,\r
cd872e40 97 IN UINT64 StartTimeStamp\r
98 )\r
99{\r
37573927 100 EFI_HOB_HANDOFF_INFO_TABLE* HobList;\r
0dbbacdf 101 ARM_MP_CORE_INFO_PPI* ArmMpCoreInfoPpi;\r
102 UINTN ArmCoreCount;\r
103 ARM_CORE_INFO* ArmCoreInfoTable;\r
cd872e40 104 EFI_STATUS Status;\r
105 CHAR8 Buffer[100];\r
106 UINTN CharCount;\r
d269095b 107 UINTN StacksSize;\r
cd872e40 108\r
8fc38a3f 109 // If ensure the FD is either part of the System Memory or totally outside of the System Memory (XIP)\r
110 ASSERT (IS_XIP() || \r
111 ((FixedPcdGet32 (PcdFdBaseAddress) >= FixedPcdGet32 (PcdSystemMemoryBase)) &&\r
99565b88 112 ((UINT32)(FixedPcdGet32 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) <= (UINT32)(FixedPcdGet32 (PcdSystemMemoryBase) + FixedPcdGet32 (PcdSystemMemorySize)))));\r
8fc38a3f 113\r
1bc83266
HL
114 // Initialize the architecture specific bits\r
115 ArchInitialize ();\r
cd872e40 116\r
117 // Initialize the Serial Port\r
118 SerialPortInitialize ();\r
37363dff 119 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"UEFI firmware (version %s built at %a on %a)\n\r",\r
120 (CHAR16*)PcdGetPtr(PcdFirmwareVersionString), __TIME__, __DATE__);\r
cd872e40 121 SerialPortWrite ((UINT8 *) Buffer, CharCount);\r
122\r
123 // Initialize the Debug Agent for Source Level Debugging\r
124 InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC, NULL, NULL);\r
125 SaveAndSetDebugTimerInterrupt (TRUE);\r
2ee85366 126 \r
d269095b 127 // Declare the PI/UEFI memory region\r
37573927 128 HobList = HobConstructor (\r
cd872e40 129 (VOID*)UefiMemoryBase,\r
130 FixedPcdGet32 (PcdSystemMemoryUefiRegionSize),\r
131 (VOID*)UefiMemoryBase,\r
d269095b 132 (VOID*)StacksBase // The top of the UEFI Memory is reserved for the stacks\r
133 );\r
37573927 134 PrePeiSetHobList (HobList);\r
cd872e40 135\r
136 // Initialize MMU and Memory HOBs (Resource Descriptor HOBs)\r
137 Status = MemoryPeim (UefiMemoryBase, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize));\r
138 ASSERT_EFI_ERROR (Status);\r
139\r
d269095b 140 // Create the Stacks HOB (reserve the memory for all stacks)\r
99565b88 141 if (ArmIsMpCore ()) {\r
142 StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize) + (FixedPcdGet32(PcdClusterCount) * 4 * FixedPcdGet32(PcdCPUCoreSecondaryStackSize));\r
143 } else {\r
144 StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize);\r
145 }\r
d269095b 146 BuildStackHob (StacksBase, StacksSize);\r
cd872e40 147\r
8fc38a3f 148 // Declare the Global Variable HOB\r
149 BuildGlobalVariableHob (GlobalVariableBase, FixedPcdGet32 (PcdPeiGlobalVariableSize));\r
150\r
44788bae 151 //TODO: Call CpuPei as a library\r
152 BuildCpuHob (PcdGet8 (PcdPrePiCpuMemorySize), PcdGet8 (PcdPrePiCpuIoSize));\r
153\r
0dbbacdf 154 if (ArmIsMpCore ()) {\r
155 // Only MP Core platform need to produce gArmMpCoreInfoPpiGuid\r
156 Status = GetPlatformPpi (&gArmMpCoreInfoPpiGuid, (VOID**)&ArmMpCoreInfoPpi);\r
157\r
158 // On MP Core Platform we must implement the ARM MP Core Info PPI (gArmMpCoreInfoPpiGuid)\r
159 ASSERT_EFI_ERROR (Status);\r
160\r
161 // Build the MP Core Info Table\r
162 ArmCoreCount = 0;\r
163 Status = ArmMpCoreInfoPpi->GetMpCoreInfo (&ArmCoreCount, &ArmCoreInfoTable);\r
164 if (!EFI_ERROR(Status) && (ArmCoreCount > 0)) {\r
165 // Build MPCore Info HOB\r
166 BuildGuidDataHob (&gArmMpCoreInfoGuid, ArmCoreInfoTable, sizeof (ARM_CORE_INFO) * ArmCoreCount);\r
167 }\r
168 }\r
169\r
cd872e40 170 // Set the Boot Mode\r
171 SetBootMode (ArmPlatformGetBootMode ());\r
172\r
173 // Initialize Platform HOBs (CpuHob and FvHob)\r
174 Status = PlatformPeim ();\r
175 ASSERT_EFI_ERROR (Status);\r
176\r
cd872e40 177 // Now, the HOB List has been initialized, we can register performance information\r
178 PERF_START (NULL, "PEI", NULL, StartTimeStamp);\r
179\r
180 // SEC phase needs to run library constructors by hand.\r
181 ExtractGuidedSectionLibConstructor ();\r
182 LzmaDecompressLibConstructor ();\r
183\r
184 // Build HOBs to pass up our version of stuff the DXE Core needs to save space\r
185 BuildPeCoffLoaderHob ();\r
186 BuildExtractSectionHob (\r
187 &gLzmaCustomDecompressGuid,\r
188 LzmaGuidedSectionGetInfo,\r
189 LzmaGuidedSectionExtraction\r
190 );\r
191\r
192 // Assume the FV that contains the SEC (our code) also contains a compressed FV.\r
193 Status = DecompressFirstFv ();\r
194 ASSERT_EFI_ERROR (Status);\r
195\r
196 // Load the DXE Core and transfer control to it\r
197 Status = LoadDxeCoreFromFv (NULL, 0);\r
198 ASSERT_EFI_ERROR (Status);\r
199}\r
200\r
201VOID\r
202CEntryPoint (\r
0787bc61 203 IN UINTN MpId,\r
c524ffbb 204 IN UINTN UefiMemoryBase,\r
205 IN UINTN StacksBase,\r
206 IN UINTN GlobalVariableBase\r
cd872e40 207 )\r
208{\r
209 UINT64 StartTimeStamp;\r
2ee85366 210 \r
695df8ba 211 ASSERT(!ArmIsMpCore() || (PcdGet32 (PcdCoreCount) > 1));\r
212\r
f437141a 213 // Initialize the platform specific controllers\r
214 ArmPlatformInitialize (MpId);\r
215\r
bebda7ce 216 if (ArmPlatformIsPrimaryCore (MpId) && PerformanceMeasurementEnabled ()) {\r
cd872e40 217 // Initialize the Timer Library to setup the Timer HW controller\r
218 TimerConstructor ();\r
219 // We cannot call yet the PerformanceLib because the HOB List has not been initialized\r
220 StartTimeStamp = GetPerformanceCounter ();\r
2ee85366 221 } else {\r
222 StartTimeStamp = 0;\r
cd872e40 223 }\r
224\r
d269095b 225 // Clean Data cache\r
226 ArmCleanInvalidateDataCache ();\r
cd872e40 227\r
d269095b 228 // Invalidate instruction cache\r
229 ArmInvalidateInstructionCache ();\r
cd872e40 230\r
231 //TODO:Drain Write Buffer\r
232\r
233 // Enable Instruction & Data caches\r
d269095b 234 ArmEnableDataCache ();\r
235 ArmEnableInstructionCache ();\r
cd872e40 236\r
99565b88 237 // Define the Global Variable region when we are not running in XIP\r
238 if (!IS_XIP()) {\r
bebda7ce 239 if (ArmPlatformIsPrimaryCore (MpId)) {\r
99565b88 240 mGlobalVariableBase = GlobalVariableBase;\r
1aa9860e 241 if (ArmIsMpCore()) {\r
b1d41be7 242 // Signal the Global Variable Region is defined (event: ARM_CPU_EVENT_DEFAULT)\r
243 ArmCallSEV ();\r
1aa9860e 244 }\r
99565b88 245 } else {\r
b1d41be7 246 // Wait the Primay core has defined the address of the Global Variable region (event: ARM_CPU_EVENT_DEFAULT)\r
247 ArmCallWFE ();\r
99565b88 248 }\r
249 }\r
250 \r
d269095b 251 // If not primary Jump to Secondary Main\r
bebda7ce 252 if (ArmPlatformIsPrimaryCore (MpId)) {\r
cd872e40 253 // Goto primary Main.\r
c524ffbb 254 PrimaryMain (UefiMemoryBase, StacksBase, GlobalVariableBase, StartTimeStamp);\r
cd872e40 255 } else {\r
0787bc61 256 SecondaryMain (MpId);\r
cd872e40 257 }\r
258\r
259 // DXE Core should always load and never return\r
260 ASSERT (FALSE);\r
261}\r
262\r