]>
Commit | Line | Data |
---|---|---|
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 | |
37 | UINTN mGlobalVariableBase = 0;\r | |
38 | \r | |
cd872e40 | 39 | VOID\r |
40 | PrePiCommonExceptionEntry (\r | |
41 | IN UINT32 Entry,\r | |
42 | IN UINT32 LR\r | |
43 | );\r | |
44 | \r | |
45 | EFI_STATUS\r | |
46 | EFIAPI\r | |
47 | ExtractGuidedSectionLibConstructor (\r | |
48 | VOID\r | |
49 | );\r | |
50 | \r | |
51 | EFI_STATUS\r | |
52 | EFIAPI\r | |
53 | LzmaDecompressLibConstructor (\r | |
54 | VOID\r | |
55 | );\r | |
56 | \r | |
8fc38a3f | 57 | VOID\r |
58 | EFIAPI\r | |
59 | BuildGlobalVariableHob (\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 | |
0dbbacdf | 74 | EFI_STATUS\r |
75 | GetPlatformPpi (\r | |
76 | IN EFI_GUID *PpiGuid,\r | |
77 | OUT VOID **Ppi\r | |
78 | )\r | |
79 | {\r | |
80 | UINTN PpiListSize;\r | |
81 | UINTN PpiListCount;\r | |
82 | EFI_PEI_PPI_DESCRIPTOR *PpiList;\r | |
83 | UINTN Index;\r | |
84 | \r | |
85 | PpiListSize = 0;\r | |
86 | ArmPlatformGetPlatformPpiList (&PpiListSize, &PpiList);\r | |
87 | PpiListCount = PpiListSize / sizeof(EFI_PEI_PPI_DESCRIPTOR);\r | |
88 | for (Index = 0; Index < PpiListCount; Index++, PpiList++) {\r | |
89 | if (CompareGuid (PpiList->Guid, PpiGuid) == TRUE) {\r | |
90 | *Ppi = PpiList->Ppi;\r | |
91 | return EFI_SUCCESS;\r | |
92 | }\r | |
93 | }\r | |
94 | \r | |
95 | return EFI_NOT_FOUND;\r | |
96 | }\r | |
97 | \r | |
cd872e40 | 98 | VOID\r |
99 | PrePiMain (\r | |
100 | IN UINTN UefiMemoryBase,\r | |
c524ffbb | 101 | IN UINTN StacksBase,\r |
102 | IN UINTN GlobalVariableBase,\r | |
cd872e40 | 103 | IN UINT64 StartTimeStamp\r |
104 | )\r | |
105 | {\r | |
37573927 | 106 | EFI_HOB_HANDOFF_INFO_TABLE* HobList;\r |
0dbbacdf | 107 | ARM_MP_CORE_INFO_PPI* ArmMpCoreInfoPpi;\r |
108 | UINTN ArmCoreCount;\r | |
109 | ARM_CORE_INFO* ArmCoreInfoTable;\r | |
cd872e40 | 110 | EFI_STATUS Status;\r |
111 | CHAR8 Buffer[100];\r | |
112 | UINTN CharCount;\r | |
d269095b | 113 | UINTN StacksSize;\r |
cd872e40 | 114 | \r |
8fc38a3f | 115 | // If ensure the FD is either part of the System Memory or totally outside of the System Memory (XIP)\r |
116 | ASSERT (IS_XIP() || \r | |
117 | ((FixedPcdGet32 (PcdFdBaseAddress) >= FixedPcdGet32 (PcdSystemMemoryBase)) &&\r | |
99565b88 | 118 | ((UINT32)(FixedPcdGet32 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) <= (UINT32)(FixedPcdGet32 (PcdSystemMemoryBase) + FixedPcdGet32 (PcdSystemMemorySize)))));\r |
8fc38a3f | 119 | \r |
cd872e40 | 120 | // Enable program flow prediction, if supported.\r |
121 | ArmEnableBranchPrediction ();\r | |
122 | \r | |
123 | if (FixedPcdGet32(PcdVFPEnabled)) {\r | |
124 | ArmEnableVFP();\r | |
125 | }\r | |
126 | \r | |
127 | // Initialize the Serial Port\r | |
128 | SerialPortInitialize ();\r | |
37363dff | 129 | CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"UEFI firmware (version %s built at %a on %a)\n\r",\r |
130 | (CHAR16*)PcdGetPtr(PcdFirmwareVersionString), __TIME__, __DATE__);\r | |
cd872e40 | 131 | SerialPortWrite ((UINT8 *) Buffer, CharCount);\r |
132 | \r | |
133 | // Initialize the Debug Agent for Source Level Debugging\r | |
134 | InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC, NULL, NULL);\r | |
135 | SaveAndSetDebugTimerInterrupt (TRUE);\r | |
2ee85366 | 136 | \r |
d269095b | 137 | // Declare the PI/UEFI memory region\r |
37573927 | 138 | HobList = HobConstructor (\r |
cd872e40 | 139 | (VOID*)UefiMemoryBase,\r |
140 | FixedPcdGet32 (PcdSystemMemoryUefiRegionSize),\r | |
141 | (VOID*)UefiMemoryBase,\r | |
d269095b | 142 | (VOID*)StacksBase // The top of the UEFI Memory is reserved for the stacks\r |
143 | );\r | |
37573927 | 144 | PrePeiSetHobList (HobList);\r |
cd872e40 | 145 | \r |
146 | // Initialize MMU and Memory HOBs (Resource Descriptor HOBs)\r | |
147 | Status = MemoryPeim (UefiMemoryBase, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize));\r | |
148 | ASSERT_EFI_ERROR (Status);\r | |
149 | \r | |
d269095b | 150 | // Create the Stacks HOB (reserve the memory for all stacks)\r |
99565b88 | 151 | if (ArmIsMpCore ()) {\r |
152 | StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize) + (FixedPcdGet32(PcdClusterCount) * 4 * FixedPcdGet32(PcdCPUCoreSecondaryStackSize));\r | |
153 | } else {\r | |
154 | StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize);\r | |
155 | }\r | |
d269095b | 156 | BuildStackHob (StacksBase, StacksSize);\r |
cd872e40 | 157 | \r |
8fc38a3f | 158 | // Declare the Global Variable HOB\r |
159 | BuildGlobalVariableHob (GlobalVariableBase, FixedPcdGet32 (PcdPeiGlobalVariableSize));\r | |
160 | \r | |
44788bae | 161 | //TODO: Call CpuPei as a library\r |
162 | BuildCpuHob (PcdGet8 (PcdPrePiCpuMemorySize), PcdGet8 (PcdPrePiCpuIoSize));\r | |
163 | \r | |
0dbbacdf | 164 | if (ArmIsMpCore ()) {\r |
165 | // Only MP Core platform need to produce gArmMpCoreInfoPpiGuid\r | |
166 | Status = GetPlatformPpi (&gArmMpCoreInfoPpiGuid, (VOID**)&ArmMpCoreInfoPpi);\r | |
167 | \r | |
168 | // On MP Core Platform we must implement the ARM MP Core Info PPI (gArmMpCoreInfoPpiGuid)\r | |
169 | ASSERT_EFI_ERROR (Status);\r | |
170 | \r | |
171 | // Build the MP Core Info Table\r | |
172 | ArmCoreCount = 0;\r | |
173 | Status = ArmMpCoreInfoPpi->GetMpCoreInfo (&ArmCoreCount, &ArmCoreInfoTable);\r | |
174 | if (!EFI_ERROR(Status) && (ArmCoreCount > 0)) {\r | |
175 | // Build MPCore Info HOB\r | |
176 | BuildGuidDataHob (&gArmMpCoreInfoGuid, ArmCoreInfoTable, sizeof (ARM_CORE_INFO) * ArmCoreCount);\r | |
177 | }\r | |
178 | }\r | |
179 | \r | |
cd872e40 | 180 | // Set the Boot Mode\r |
181 | SetBootMode (ArmPlatformGetBootMode ());\r | |
182 | \r | |
183 | // Initialize Platform HOBs (CpuHob and FvHob)\r | |
184 | Status = PlatformPeim ();\r | |
185 | ASSERT_EFI_ERROR (Status);\r | |
186 | \r | |
cd872e40 | 187 | // Now, the HOB List has been initialized, we can register performance information\r |
188 | PERF_START (NULL, "PEI", NULL, StartTimeStamp);\r | |
189 | \r | |
190 | // SEC phase needs to run library constructors by hand.\r | |
191 | ExtractGuidedSectionLibConstructor ();\r | |
192 | LzmaDecompressLibConstructor ();\r | |
193 | \r | |
194 | // Build HOBs to pass up our version of stuff the DXE Core needs to save space\r | |
195 | BuildPeCoffLoaderHob ();\r | |
196 | BuildExtractSectionHob (\r | |
197 | &gLzmaCustomDecompressGuid,\r | |
198 | LzmaGuidedSectionGetInfo,\r | |
199 | LzmaGuidedSectionExtraction\r | |
200 | );\r | |
201 | \r | |
202 | // Assume the FV that contains the SEC (our code) also contains a compressed FV.\r | |
203 | Status = DecompressFirstFv ();\r | |
204 | ASSERT_EFI_ERROR (Status);\r | |
205 | \r | |
206 | // Load the DXE Core and transfer control to it\r | |
207 | Status = LoadDxeCoreFromFv (NULL, 0);\r | |
208 | ASSERT_EFI_ERROR (Status);\r | |
209 | }\r | |
210 | \r | |
211 | VOID\r | |
212 | CEntryPoint (\r | |
0787bc61 | 213 | IN UINTN MpId,\r |
c524ffbb | 214 | IN UINTN UefiMemoryBase,\r |
215 | IN UINTN StacksBase,\r | |
216 | IN UINTN GlobalVariableBase\r | |
cd872e40 | 217 | )\r |
218 | {\r | |
219 | UINT64 StartTimeStamp;\r | |
2ee85366 | 220 | \r |
f437141a | 221 | // Initialize the platform specific controllers\r |
222 | ArmPlatformInitialize (MpId);\r | |
223 | \r | |
0787bc61 | 224 | if (IS_PRIMARY_CORE(MpId) && PerformanceMeasurementEnabled ()) {\r |
cd872e40 | 225 | // Initialize the Timer Library to setup the Timer HW controller\r |
226 | TimerConstructor ();\r | |
227 | // We cannot call yet the PerformanceLib because the HOB List has not been initialized\r | |
228 | StartTimeStamp = GetPerformanceCounter ();\r | |
2ee85366 | 229 | } else {\r |
230 | StartTimeStamp = 0;\r | |
cd872e40 | 231 | }\r |
232 | \r | |
d269095b | 233 | // Clean Data cache\r |
234 | ArmCleanInvalidateDataCache ();\r | |
cd872e40 | 235 | \r |
d269095b | 236 | // Invalidate instruction cache\r |
237 | ArmInvalidateInstructionCache ();\r | |
cd872e40 | 238 | \r |
239 | //TODO:Drain Write Buffer\r | |
240 | \r | |
241 | // Enable Instruction & Data caches\r | |
d269095b | 242 | ArmEnableDataCache ();\r |
243 | ArmEnableInstructionCache ();\r | |
cd872e40 | 244 | \r |
99565b88 | 245 | // Define the Global Variable region when we are not running in XIP\r |
246 | if (!IS_XIP()) {\r | |
247 | if (IS_PRIMARY_CORE(MpId)) {\r | |
248 | mGlobalVariableBase = GlobalVariableBase;\r | |
1aa9860e | 249 | if (ArmIsMpCore()) {\r |
b1d41be7 | 250 | // Signal the Global Variable Region is defined (event: ARM_CPU_EVENT_DEFAULT)\r |
251 | ArmCallSEV ();\r | |
1aa9860e | 252 | }\r |
99565b88 | 253 | } else {\r |
b1d41be7 | 254 | // Wait the Primay core has defined the address of the Global Variable region (event: ARM_CPU_EVENT_DEFAULT)\r |
255 | ArmCallWFE ();\r | |
99565b88 | 256 | }\r |
257 | }\r | |
258 | \r | |
cd872e40 | 259 | // Write VBAR - The Vector table must be 32-byte aligned\r |
d269095b | 260 | ASSERT (((UINT32)PrePiVectorTable & ((1 << 5)-1)) == 0);\r |
261 | ArmWriteVBar ((UINT32)PrePiVectorTable);\r | |
cd872e40 | 262 | \r |
d269095b | 263 | // If not primary Jump to Secondary Main\r |
0787bc61 | 264 | if (IS_PRIMARY_CORE(MpId)) {\r |
cd872e40 | 265 | // Goto primary Main.\r |
c524ffbb | 266 | PrimaryMain (UefiMemoryBase, StacksBase, GlobalVariableBase, StartTimeStamp);\r |
cd872e40 | 267 | } else {\r |
0787bc61 | 268 | SecondaryMain (MpId);\r |
cd872e40 | 269 | }\r |
270 | \r | |
271 | // DXE Core should always load and never return\r | |
272 | ASSERT (FALSE);\r | |
273 | }\r | |
274 | \r | |
275 | VOID\r | |
276 | PrePiCommonExceptionEntry (\r | |
277 | IN UINT32 Entry,\r | |
278 | IN UINT32 LR\r | |
279 | )\r | |
280 | {\r | |
281 | CHAR8 Buffer[100];\r | |
282 | UINTN CharCount;\r | |
283 | \r | |
284 | switch (Entry) {\r | |
285 | case 0:\r | |
286 | CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Reset Exception at 0x%X\n\r",LR);\r | |
287 | break;\r | |
288 | case 1:\r | |
289 | CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Undefined Exception at 0x%X\n\r",LR);\r | |
290 | break;\r | |
291 | case 2:\r | |
292 | CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"SWI Exception at 0x%X\n\r",LR);\r | |
293 | break;\r | |
294 | case 3:\r | |
295 | CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"PrefetchAbort Exception at 0x%X\n\r",LR);\r | |
296 | break;\r | |
297 | case 4:\r | |
298 | CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"DataAbort Exception at 0x%X\n\r",LR);\r | |
299 | break;\r | |
300 | case 5:\r | |
301 | CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Reserved Exception at 0x%X\n\r",LR);\r | |
302 | break;\r | |
303 | case 6:\r | |
304 | CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"IRQ Exception at 0x%X\n\r",LR);\r | |
305 | break;\r | |
306 | case 7:\r | |
307 | CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"FIQ Exception at 0x%X\n\r",LR);\r | |
308 | break;\r | |
309 | default:\r | |
310 | CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Unknown Exception at 0x%X\n\r",LR);\r | |
311 | break;\r | |
312 | }\r | |
313 | SerialPortWrite ((UINT8 *) Buffer, CharCount);\r | |
314 | while(1);\r | |
315 | }\r |