]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/PrePi/PrePi.c
ArmPkg: Create MpCoreInfo PPI and HOB to describe CPU Cores on a MPCore platform
[mirror_edk2.git] / ArmPlatformPkg / PrePi / PrePi.c
CommitLineData
cd872e40 1/** @file\r
2*\r
3* Copyright (c) 2011, ARM Limited. All rights reserved.\r
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
11c20f4e 18#include <Library/BaseMemoryLib.h>\r
cd872e40 19#include <Library/PrePiLib.h>\r
20#include <Library/IoLib.h>\r
21#include <Library/PrintLib.h>\r
22#include <Library/PeCoffGetEntryPointLib.h>\r
37573927 23#include <Library/PrePiHobListPointerLib.h>\r
cd872e40 24#include <Library/TimerLib.h>\r
25#include <Library/PerformanceLib.h>\r
26\r
27#include <Ppi/GuidedSectionExtraction.h>\r
28#include <Guid/LzmaDecompress.h>\r
8fc38a3f 29#include <Guid/ArmGlobalVariableHob.h>\r
cd872e40 30\r
31#include "PrePi.h"\r
32#include "LzmaDecompress.h"\r
33\r
8fc38a3f 34#define IS_XIP() ((FixedPcdGet32 (PcdFdBaseAddress) > (FixedPcdGet32 (PcdSystemMemoryBase) + FixedPcdGet32 (PcdSystemMemorySize))) || \\r
35 ((FixedPcdGet32 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) < FixedPcdGet32 (PcdSystemMemoryBase)))\r
36\r
37// Not used when PrePi in run in XIP mode\r
38UINTN mGlobalVariableBase = 0;\r
39\r
cd872e40 40VOID\r
41PrePiCommonExceptionEntry (\r
42 IN UINT32 Entry,\r
43 IN UINT32 LR\r
44 );\r
45\r
46EFI_STATUS\r
47EFIAPI\r
48ExtractGuidedSectionLibConstructor (\r
49 VOID\r
50 );\r
51\r
52EFI_STATUS\r
53EFIAPI\r
54LzmaDecompressLibConstructor (\r
55 VOID\r
56 );\r
57\r
8fc38a3f 58VOID\r
59EFIAPI\r
60BuildGlobalVariableHob (\r
61 IN EFI_PHYSICAL_ADDRESS GlobalVariableBase,\r
62 IN UINT32 GlobalVariableSize\r
63 )\r
64{\r
65 ARM_HOB_GLOBAL_VARIABLE *Hob;\r
66\r
67 Hob = CreateHob (EFI_HOB_TYPE_GUID_EXTENSION, sizeof (ARM_HOB_GLOBAL_VARIABLE));\r
68 ASSERT(Hob != NULL);\r
69\r
70 CopyGuid (&(Hob->Header.Name), &gArmGlobalVariableGuid);\r
71 Hob->GlobalVariableBase = GlobalVariableBase;\r
72 Hob->GlobalVariableSize = GlobalVariableSize;\r
73}\r
74\r
cd872e40 75VOID\r
76PrePiMain (\r
77 IN UINTN UefiMemoryBase,\r
c524ffbb 78 IN UINTN StacksBase,\r
79 IN UINTN GlobalVariableBase,\r
cd872e40 80 IN UINT64 StartTimeStamp\r
81 )\r
82{\r
37573927 83 EFI_HOB_HANDOFF_INFO_TABLE* HobList;\r
cd872e40 84 EFI_STATUS Status;\r
85 CHAR8 Buffer[100];\r
86 UINTN CharCount;\r
d269095b 87 UINTN StacksSize;\r
cd872e40 88\r
8fc38a3f 89 // If ensure the FD is either part of the System Memory or totally outside of the System Memory (XIP)\r
90 ASSERT (IS_XIP() || \r
91 ((FixedPcdGet32 (PcdFdBaseAddress) >= FixedPcdGet32 (PcdSystemMemoryBase)) &&\r
92 ((FixedPcdGet32 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) <= (FixedPcdGet32 (PcdSystemMemoryBase) + FixedPcdGet32 (PcdSystemMemorySize)))));\r
93\r
cd872e40 94 // Enable program flow prediction, if supported.\r
95 ArmEnableBranchPrediction ();\r
96\r
97 if (FixedPcdGet32(PcdVFPEnabled)) {\r
98 ArmEnableVFP();\r
99 }\r
100\r
101 // Initialize the Serial Port\r
102 SerialPortInitialize ();\r
103 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"UEFI firmware built at %a on %a\n\r",__TIME__, __DATE__);\r
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
8fc38a3f 109\r
110 if (!IS_XIP()) {\r
111 mGlobalVariableBase = GlobalVariableBase;\r
112 }\r
2ee85366 113 \r
d269095b 114 // Declare the PI/UEFI memory region\r
37573927 115 HobList = HobConstructor (\r
cd872e40 116 (VOID*)UefiMemoryBase,\r
117 FixedPcdGet32 (PcdSystemMemoryUefiRegionSize),\r
118 (VOID*)UefiMemoryBase,\r
d269095b 119 (VOID*)StacksBase // The top of the UEFI Memory is reserved for the stacks\r
120 );\r
37573927 121 PrePeiSetHobList (HobList);\r
cd872e40 122\r
123 // Initialize MMU and Memory HOBs (Resource Descriptor HOBs)\r
124 Status = MemoryPeim (UefiMemoryBase, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize));\r
125 ASSERT_EFI_ERROR (Status);\r
126\r
d269095b 127 // Create the Stacks HOB (reserve the memory for all stacks)\r
2dbcb8f0 128 StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize) + (FixedPcdGet32(PcdClusterCount) * 4 * FixedPcdGet32(PcdCPUCoreSecondaryStackSize));\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
144 BuildMemoryTypeInformationHob ();\r
145\r
cd872e40 146 // Now, the HOB List has been initialized, we can register performance information\r
147 PERF_START (NULL, "PEI", NULL, StartTimeStamp);\r
148\r
149 // SEC phase needs to run library constructors by hand.\r
150 ExtractGuidedSectionLibConstructor ();\r
151 LzmaDecompressLibConstructor ();\r
152\r
153 // Build HOBs to pass up our version of stuff the DXE Core needs to save space\r
154 BuildPeCoffLoaderHob ();\r
155 BuildExtractSectionHob (\r
156 &gLzmaCustomDecompressGuid,\r
157 LzmaGuidedSectionGetInfo,\r
158 LzmaGuidedSectionExtraction\r
159 );\r
160\r
161 // Assume the FV that contains the SEC (our code) also contains a compressed FV.\r
162 Status = DecompressFirstFv ();\r
163 ASSERT_EFI_ERROR (Status);\r
164\r
165 // Load the DXE Core and transfer control to it\r
166 Status = LoadDxeCoreFromFv (NULL, 0);\r
167 ASSERT_EFI_ERROR (Status);\r
168}\r
169\r
170VOID\r
171CEntryPoint (\r
0787bc61 172 IN UINTN MpId,\r
c524ffbb 173 IN UINTN UefiMemoryBase,\r
174 IN UINTN StacksBase,\r
175 IN UINTN GlobalVariableBase\r
cd872e40 176 )\r
177{\r
178 UINT64 StartTimeStamp;\r
2ee85366 179 \r
0787bc61 180 if (IS_PRIMARY_CORE(MpId) && PerformanceMeasurementEnabled ()) {\r
cd872e40 181 // Initialize the Timer Library to setup the Timer HW controller\r
182 TimerConstructor ();\r
183 // We cannot call yet the PerformanceLib because the HOB List has not been initialized\r
184 StartTimeStamp = GetPerformanceCounter ();\r
2ee85366 185 } else {\r
186 StartTimeStamp = 0;\r
cd872e40 187 }\r
188\r
d269095b 189 // Clean Data cache\r
190 ArmCleanInvalidateDataCache ();\r
cd872e40 191\r
d269095b 192 // Invalidate instruction cache\r
193 ArmInvalidateInstructionCache ();\r
cd872e40 194\r
195 //TODO:Drain Write Buffer\r
196\r
197 // Enable Instruction & Data caches\r
d269095b 198 ArmEnableDataCache ();\r
199 ArmEnableInstructionCache ();\r
cd872e40 200\r
201 // Write VBAR - The Vector table must be 32-byte aligned\r
d269095b 202 ASSERT (((UINT32)PrePiVectorTable & ((1 << 5)-1)) == 0);\r
203 ArmWriteVBar ((UINT32)PrePiVectorTable);\r
cd872e40 204\r
d269095b 205 // If not primary Jump to Secondary Main\r
0787bc61 206 if (IS_PRIMARY_CORE(MpId)) {\r
cd872e40 207 // Goto primary Main.\r
c524ffbb 208 PrimaryMain (UefiMemoryBase, StacksBase, GlobalVariableBase, StartTimeStamp);\r
cd872e40 209 } else {\r
0787bc61 210 SecondaryMain (MpId);\r
cd872e40 211 }\r
212\r
213 // DXE Core should always load and never return\r
214 ASSERT (FALSE);\r
215}\r
216\r
217VOID\r
218PrePiCommonExceptionEntry (\r
219 IN UINT32 Entry,\r
220 IN UINT32 LR\r
221 )\r
222{\r
223 CHAR8 Buffer[100];\r
224 UINTN CharCount;\r
225\r
226 switch (Entry) {\r
227 case 0:\r
228 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Reset Exception at 0x%X\n\r",LR);\r
229 break;\r
230 case 1:\r
231 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Undefined Exception at 0x%X\n\r",LR);\r
232 break;\r
233 case 2:\r
234 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"SWI Exception at 0x%X\n\r",LR);\r
235 break;\r
236 case 3:\r
237 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"PrefetchAbort Exception at 0x%X\n\r",LR);\r
238 break;\r
239 case 4:\r
240 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"DataAbort Exception at 0x%X\n\r",LR);\r
241 break;\r
242 case 5:\r
243 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Reserved Exception at 0x%X\n\r",LR);\r
244 break;\r
245 case 6:\r
246 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"IRQ Exception at 0x%X\n\r",LR);\r
247 break;\r
248 case 7:\r
249 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"FIQ Exception at 0x%X\n\r",LR);\r
250 break;\r
251 default:\r
252 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Unknown Exception at 0x%X\n\r",LR);\r
253 break;\r
254 }\r
255 SerialPortWrite ((UINT8 *) Buffer, CharCount);\r
256 while(1);\r
257}\r