]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | *\r | |
3 | * Copyright (c) 2011-2013, 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 | |
18 | #include <Library/PrePiLib.h>\r | |
19 | #include <Library/PrintLib.h>\r | |
20 | #include <Library/PeCoffGetEntryPointLib.h>\r | |
21 | #include <Library/PrePiHobListPointerLib.h>\r | |
22 | #include <Library/TimerLib.h>\r | |
23 | #include <Library/PerformanceLib.h>\r | |
24 | \r | |
25 | #include <Ppi/GuidedSectionExtraction.h>\r | |
26 | #include <Ppi/ArmMpCoreInfo.h>\r | |
27 | #include <Guid/LzmaDecompress.h>\r | |
28 | #include <Guid/ArmGlobalVariableHob.h>\r | |
29 | \r | |
30 | #include "PrePi.h"\r | |
31 | #include "LzmaDecompress.h"\r | |
32 | \r | |
33 | #define IS_XIP() (((UINT32)FixedPcdGet32 (PcdFdBaseAddress) > (UINT32)(FixedPcdGet32 (PcdSystemMemoryBase) + FixedPcdGet32 (PcdSystemMemorySize))) || \\r | |
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 | |
39 | EFI_STATUS\r | |
40 | EFIAPI\r | |
41 | ExtractGuidedSectionLibConstructor (\r | |
42 | VOID\r | |
43 | );\r | |
44 | \r | |
45 | EFI_STATUS\r | |
46 | EFIAPI\r | |
47 | LzmaDecompressLibConstructor (\r | |
48 | VOID\r | |
49 | );\r | |
50 | \r | |
51 | VOID\r | |
52 | EFIAPI\r | |
53 | BuildGlobalVariableHob (\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 | |
68 | EFI_STATUS\r | |
69 | GetPlatformPpi (\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 | |
92 | VOID\r | |
93 | PrePiMain (\r | |
94 | IN UINTN UefiMemoryBase,\r | |
95 | IN UINTN StacksBase,\r | |
96 | IN UINTN GlobalVariableBase,\r | |
97 | IN UINT64 StartTimeStamp\r | |
98 | )\r | |
99 | {\r | |
100 | EFI_HOB_HANDOFF_INFO_TABLE* HobList;\r | |
101 | ARM_MP_CORE_INFO_PPI* ArmMpCoreInfoPpi;\r | |
102 | UINTN ArmCoreCount;\r | |
103 | ARM_CORE_INFO* ArmCoreInfoTable;\r | |
104 | EFI_STATUS Status;\r | |
105 | CHAR8 Buffer[100];\r | |
106 | UINTN CharCount;\r | |
107 | UINTN StacksSize;\r | |
108 | \r | |
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 | |
112 | ((UINT32)(FixedPcdGet32 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) <= (UINT32)(FixedPcdGet32 (PcdSystemMemoryBase) + FixedPcdGet32 (PcdSystemMemorySize)))));\r | |
113 | \r | |
114 | // Initialize the architecture specific bits\r | |
115 | ArchInitialize ();\r | |
116 | \r | |
117 | // Initialize the Serial Port\r | |
118 | SerialPortInitialize ();\r | |
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 | |
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 | |
126 | \r | |
127 | // Declare the PI/UEFI memory region\r | |
128 | HobList = HobConstructor (\r | |
129 | (VOID*)UefiMemoryBase,\r | |
130 | FixedPcdGet32 (PcdSystemMemoryUefiRegionSize),\r | |
131 | (VOID*)UefiMemoryBase,\r | |
132 | (VOID*)StacksBase // The top of the UEFI Memory is reserved for the stacks\r | |
133 | );\r | |
134 | PrePeiSetHobList (HobList);\r | |
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 | |
140 | // Create the Stacks HOB (reserve the memory for all stacks)\r | |
141 | if (ArmIsMpCore ()) {\r | |
142 | StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize) + (FixedPcdGet32(PcdClusterCount) * 4 * FixedPcdGet32(PcdCPUCoreSecondaryStackSize));\r | |
143 | } else {\r | |
144 | StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize);\r | |
145 | }\r | |
146 | BuildStackHob (StacksBase, StacksSize);\r | |
147 | \r | |
148 | // Declare the Global Variable HOB\r | |
149 | BuildGlobalVariableHob (GlobalVariableBase, FixedPcdGet32 (PcdPeiGlobalVariableSize));\r | |
150 | \r | |
151 | //TODO: Call CpuPei as a library\r | |
152 | BuildCpuHob (PcdGet8 (PcdPrePiCpuMemorySize), PcdGet8 (PcdPrePiCpuIoSize));\r | |
153 | \r | |
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 | |
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 | |
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 | |
201 | VOID\r | |
202 | CEntryPoint (\r | |
203 | IN UINTN MpId,\r | |
204 | IN UINTN UefiMemoryBase,\r | |
205 | IN UINTN StacksBase,\r | |
206 | IN UINTN GlobalVariableBase\r | |
207 | )\r | |
208 | {\r | |
209 | UINT64 StartTimeStamp;\r | |
210 | \r | |
211 | ASSERT(!ArmIsMpCore() || (PcdGet32 (PcdCoreCount) > 1));\r | |
212 | \r | |
213 | // Initialize the platform specific controllers\r | |
214 | ArmPlatformInitialize (MpId);\r | |
215 | \r | |
216 | if (ArmPlatformIsPrimaryCore (MpId) && PerformanceMeasurementEnabled ()) {\r | |
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 | |
221 | } else {\r | |
222 | StartTimeStamp = 0;\r | |
223 | }\r | |
224 | \r | |
225 | // Data Cache enabled on Primary core when MMU is enabled.\r | |
226 | ArmDisableDataCache ();\r | |
227 | // Invalidate Data cache\r | |
228 | ArmInvalidateDataCache ();\r | |
229 | // Invalidate instruction cache\r | |
230 | ArmInvalidateInstructionCache ();\r | |
231 | // Enable Instruction Caches on all cores.\r | |
232 | ArmEnableInstructionCache ();\r | |
233 | \r | |
234 | // Define the Global Variable region when we are not running in XIP\r | |
235 | if (!IS_XIP()) {\r | |
236 | if (ArmPlatformIsPrimaryCore (MpId)) {\r | |
237 | mGlobalVariableBase = GlobalVariableBase;\r | |
238 | if (ArmIsMpCore()) {\r | |
239 | // Signal the Global Variable Region is defined (event: ARM_CPU_EVENT_DEFAULT)\r | |
240 | ArmCallSEV ();\r | |
241 | }\r | |
242 | } else {\r | |
243 | // Wait the Primay core has defined the address of the Global Variable region (event: ARM_CPU_EVENT_DEFAULT)\r | |
244 | ArmCallWFE ();\r | |
245 | }\r | |
246 | }\r | |
247 | \r | |
248 | // If not primary Jump to Secondary Main\r | |
249 | if (ArmPlatformIsPrimaryCore (MpId)) {\r | |
250 | // Goto primary Main.\r | |
251 | PrimaryMain (UefiMemoryBase, StacksBase, GlobalVariableBase, StartTimeStamp);\r | |
252 | } else {\r | |
253 | SecondaryMain (MpId);\r | |
254 | }\r | |
255 | \r | |
256 | // DXE Core should always load and never return\r | |
257 | ASSERT (FALSE);\r | |
258 | }\r | |
259 | \r |