]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/PrePi/PrePi.c
ArmPlatformPkg: Renamed and Invoked earlier ArmPlatformNormalInitialize()
[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
99565b88 17#include <Library/ArmCpuLib.h>\r
cd872e40 18#include <Library/DebugAgentLib.h>\r
19#include <Library/PrePiLib.h>\r
cd872e40 20#include <Library/PrintLib.h>\r
21#include <Library/PeCoffGetEntryPointLib.h>\r
37573927 22#include <Library/PrePiHobListPointerLib.h>\r
cd872e40 23#include <Library/TimerLib.h>\r
24#include <Library/PerformanceLib.h>\r
25\r
26#include <Ppi/GuidedSectionExtraction.h>\r
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 39VOID\r
40PrePiCommonExceptionEntry (\r
41 IN UINT32 Entry,\r
42 IN UINT32 LR\r
43 );\r
44\r
45EFI_STATUS\r
46EFIAPI\r
47ExtractGuidedSectionLibConstructor (\r
48 VOID\r
49 );\r
50\r
51EFI_STATUS\r
52EFIAPI\r
53LzmaDecompressLibConstructor (\r
54 VOID\r
55 );\r
56\r
8fc38a3f 57VOID\r
58EFIAPI\r
59BuildGlobalVariableHob (\r
60 IN EFI_PHYSICAL_ADDRESS GlobalVariableBase,\r
61 IN UINT32 GlobalVariableSize\r
62 )\r
63{\r
64 ARM_HOB_GLOBAL_VARIABLE *Hob;\r
65\r
66 Hob = CreateHob (EFI_HOB_TYPE_GUID_EXTENSION, sizeof (ARM_HOB_GLOBAL_VARIABLE));\r
67 ASSERT(Hob != NULL);\r
68\r
69 CopyGuid (&(Hob->Header.Name), &gArmGlobalVariableGuid);\r
70 Hob->GlobalVariableBase = GlobalVariableBase;\r
71 Hob->GlobalVariableSize = GlobalVariableSize;\r
72}\r
73\r
cd872e40 74VOID\r
75PrePiMain (\r
76 IN UINTN UefiMemoryBase,\r
c524ffbb 77 IN UINTN StacksBase,\r
78 IN UINTN GlobalVariableBase,\r
cd872e40 79 IN UINT64 StartTimeStamp\r
80 )\r
81{\r
37573927 82 EFI_HOB_HANDOFF_INFO_TABLE* HobList;\r
cd872e40 83 EFI_STATUS Status;\r
84 CHAR8 Buffer[100];\r
85 UINTN CharCount;\r
d269095b 86 UINTN StacksSize;\r
cd872e40 87\r
8fc38a3f 88 // If ensure the FD is either part of the System Memory or totally outside of the System Memory (XIP)\r
89 ASSERT (IS_XIP() || \r
90 ((FixedPcdGet32 (PcdFdBaseAddress) >= FixedPcdGet32 (PcdSystemMemoryBase)) &&\r
99565b88 91 ((UINT32)(FixedPcdGet32 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) <= (UINT32)(FixedPcdGet32 (PcdSystemMemoryBase) + FixedPcdGet32 (PcdSystemMemorySize)))));\r
8fc38a3f 92\r
cd872e40 93 // Enable program flow prediction, if supported.\r
94 ArmEnableBranchPrediction ();\r
95\r
96 if (FixedPcdGet32(PcdVFPEnabled)) {\r
97 ArmEnableVFP();\r
98 }\r
99\r
100 // Initialize the Serial Port\r
101 SerialPortInitialize ();\r
37363dff 102 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"UEFI firmware (version %s built at %a on %a)\n\r",\r
103 (CHAR16*)PcdGetPtr(PcdFirmwareVersionString), __TIME__, __DATE__);\r
cd872e40 104 SerialPortWrite ((UINT8 *) Buffer, CharCount);\r
105\r
106 // Initialize the Debug Agent for Source Level Debugging\r
107 InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC, NULL, NULL);\r
108 SaveAndSetDebugTimerInterrupt (TRUE);\r
2ee85366 109 \r
d269095b 110 // Declare the PI/UEFI memory region\r
37573927 111 HobList = HobConstructor (\r
cd872e40 112 (VOID*)UefiMemoryBase,\r
113 FixedPcdGet32 (PcdSystemMemoryUefiRegionSize),\r
114 (VOID*)UefiMemoryBase,\r
d269095b 115 (VOID*)StacksBase // The top of the UEFI Memory is reserved for the stacks\r
116 );\r
37573927 117 PrePeiSetHobList (HobList);\r
cd872e40 118\r
119 // Initialize MMU and Memory HOBs (Resource Descriptor HOBs)\r
120 Status = MemoryPeim (UefiMemoryBase, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize));\r
121 ASSERT_EFI_ERROR (Status);\r
122\r
d269095b 123 // Create the Stacks HOB (reserve the memory for all stacks)\r
99565b88 124 if (ArmIsMpCore ()) {\r
125 StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize) + (FixedPcdGet32(PcdClusterCount) * 4 * FixedPcdGet32(PcdCPUCoreSecondaryStackSize));\r
126 } else {\r
127 StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize);\r
128 }\r
d269095b 129 BuildStackHob (StacksBase, StacksSize);\r
cd872e40 130\r
8fc38a3f 131 // Declare the Global Variable HOB\r
132 BuildGlobalVariableHob (GlobalVariableBase, FixedPcdGet32 (PcdPeiGlobalVariableSize));\r
133\r
44788bae 134 //TODO: Call CpuPei as a library\r
135 BuildCpuHob (PcdGet8 (PcdPrePiCpuMemorySize), PcdGet8 (PcdPrePiCpuIoSize));\r
136\r
cd872e40 137 // Set the Boot Mode\r
138 SetBootMode (ArmPlatformGetBootMode ());\r
139\r
140 // Initialize Platform HOBs (CpuHob and FvHob)\r
141 Status = PlatformPeim ();\r
142 ASSERT_EFI_ERROR (Status);\r
143\r
cd872e40 144 // Now, the HOB List has been initialized, we can register performance information\r
145 PERF_START (NULL, "PEI", NULL, StartTimeStamp);\r
146\r
147 // SEC phase needs to run library constructors by hand.\r
148 ExtractGuidedSectionLibConstructor ();\r
149 LzmaDecompressLibConstructor ();\r
150\r
151 // Build HOBs to pass up our version of stuff the DXE Core needs to save space\r
152 BuildPeCoffLoaderHob ();\r
153 BuildExtractSectionHob (\r
154 &gLzmaCustomDecompressGuid,\r
155 LzmaGuidedSectionGetInfo,\r
156 LzmaGuidedSectionExtraction\r
157 );\r
158\r
159 // Assume the FV that contains the SEC (our code) also contains a compressed FV.\r
160 Status = DecompressFirstFv ();\r
161 ASSERT_EFI_ERROR (Status);\r
162\r
163 // Load the DXE Core and transfer control to it\r
164 Status = LoadDxeCoreFromFv (NULL, 0);\r
165 ASSERT_EFI_ERROR (Status);\r
166}\r
167\r
168VOID\r
169CEntryPoint (\r
0787bc61 170 IN UINTN MpId,\r
c524ffbb 171 IN UINTN UefiMemoryBase,\r
172 IN UINTN StacksBase,\r
173 IN UINTN GlobalVariableBase\r
cd872e40 174 )\r
175{\r
176 UINT64 StartTimeStamp;\r
2ee85366 177 \r
f437141a 178 // Initialize the platform specific controllers\r
179 ArmPlatformInitialize (MpId);\r
180\r
0787bc61 181 if (IS_PRIMARY_CORE(MpId) && PerformanceMeasurementEnabled ()) {\r
cd872e40 182 // Initialize the Timer Library to setup the Timer HW controller\r
183 TimerConstructor ();\r
184 // We cannot call yet the PerformanceLib because the HOB List has not been initialized\r
185 StartTimeStamp = GetPerformanceCounter ();\r
2ee85366 186 } else {\r
187 StartTimeStamp = 0;\r
cd872e40 188 }\r
189\r
d269095b 190 // Clean Data cache\r
191 ArmCleanInvalidateDataCache ();\r
cd872e40 192\r
d269095b 193 // Invalidate instruction cache\r
194 ArmInvalidateInstructionCache ();\r
cd872e40 195\r
196 //TODO:Drain Write Buffer\r
197\r
198 // Enable Instruction & Data caches\r
d269095b 199 ArmEnableDataCache ();\r
200 ArmEnableInstructionCache ();\r
cd872e40 201\r
99565b88 202 // Define the Global Variable region when we are not running in XIP\r
203 if (!IS_XIP()) {\r
204 if (IS_PRIMARY_CORE(MpId)) {\r
205 mGlobalVariableBase = GlobalVariableBase;\r
1aa9860e 206 if (ArmIsMpCore()) {\r
207 ArmCpuSynchronizeSignal (ARM_CPU_EVENT_DEFAULT);\r
208 }\r
99565b88 209 } else {\r
1aa9860e 210 // Wait the Primay core has defined the address of the Global Variable region\r
211 ArmCpuSynchronizeWait (ARM_CPU_EVENT_DEFAULT);\r
99565b88 212 }\r
213 }\r
214 \r
cd872e40 215 // Write VBAR - The Vector table must be 32-byte aligned\r
d269095b 216 ASSERT (((UINT32)PrePiVectorTable & ((1 << 5)-1)) == 0);\r
217 ArmWriteVBar ((UINT32)PrePiVectorTable);\r
cd872e40 218\r
d269095b 219 // If not primary Jump to Secondary Main\r
0787bc61 220 if (IS_PRIMARY_CORE(MpId)) {\r
cd872e40 221 // Goto primary Main.\r
c524ffbb 222 PrimaryMain (UefiMemoryBase, StacksBase, GlobalVariableBase, StartTimeStamp);\r
cd872e40 223 } else {\r
0787bc61 224 SecondaryMain (MpId);\r
cd872e40 225 }\r
226\r
227 // DXE Core should always load and never return\r
228 ASSERT (FALSE);\r
229}\r
230\r
231VOID\r
232PrePiCommonExceptionEntry (\r
233 IN UINT32 Entry,\r
234 IN UINT32 LR\r
235 )\r
236{\r
237 CHAR8 Buffer[100];\r
238 UINTN CharCount;\r
239\r
240 switch (Entry) {\r
241 case 0:\r
242 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Reset Exception at 0x%X\n\r",LR);\r
243 break;\r
244 case 1:\r
245 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Undefined Exception at 0x%X\n\r",LR);\r
246 break;\r
247 case 2:\r
248 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"SWI Exception at 0x%X\n\r",LR);\r
249 break;\r
250 case 3:\r
251 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"PrefetchAbort Exception at 0x%X\n\r",LR);\r
252 break;\r
253 case 4:\r
254 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"DataAbort Exception at 0x%X\n\r",LR);\r
255 break;\r
256 case 5:\r
257 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Reserved Exception at 0x%X\n\r",LR);\r
258 break;\r
259 case 6:\r
260 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"IRQ Exception at 0x%X\n\r",LR);\r
261 break;\r
262 case 7:\r
263 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"FIQ Exception at 0x%X\n\r",LR);\r
264 break;\r
265 default:\r
266 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Unknown Exception at 0x%X\n\r",LR);\r
267 break;\r
268 }\r
269 SerialPortWrite ((UINT8 *) Buffer, CharCount);\r
270 while(1);\r
271}\r