]>
Commit | Line | Data |
---|---|---|
615c6dd0 | 1 | /** @file\r |
b1f6a7c6 | 2 | Pei Core Main Entry Point\r |
3 | \r | |
cd5ebaa0 HT |
4 | Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r |
5 | This program and the accompanying materials\r | |
192f6d4c | 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 | |
615c6dd0 | 13 | **/\r |
192f6d4c | 14 | \r |
0d516397 | 15 | #include "PeiMain.h"\r |
192f6d4c | 16 | \r |
fe1e36e5 | 17 | EFI_PEI_PPI_DESCRIPTOR mMemoryDiscoveredPpi = {\r |
192f6d4c | 18 | (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r |
19 | &gEfiPeiMemoryDiscoveredPpiGuid,\r | |
20 | NULL\r | |
21 | };\r | |
22 | \r | |
40f26b8f | 23 | ///\r |
82b8c8df | 24 | /// Pei service instance\r |
40f26b8f | 25 | ///\r |
fe1e36e5 | 26 | EFI_PEI_SERVICES gPs = {\r |
192f6d4c | 27 | {\r |
28 | PEI_SERVICES_SIGNATURE,\r | |
29 | PEI_SERVICES_REVISION,\r | |
30 | sizeof (EFI_PEI_SERVICES),\r | |
31 | 0,\r | |
32 | 0\r | |
33 | },\r | |
34 | PeiInstallPpi,\r | |
35 | PeiReInstallPpi,\r | |
36 | PeiLocatePpi,\r | |
37 | PeiNotifyPpi,\r | |
38 | \r | |
39 | PeiGetBootMode,\r | |
40 | PeiSetBootMode,\r | |
41 | \r | |
42 | PeiGetHobList,\r | |
43 | PeiCreateHob,\r | |
44 | \r | |
3b428ade | 45 | PeiFfsFindNextVolume,\r |
192f6d4c | 46 | PeiFfsFindNextFile,\r |
47 | PeiFfsFindSectionData,\r | |
48 | \r | |
b0d803fe | 49 | PeiInstallPeiMemory, \r |
192f6d4c | 50 | PeiAllocatePages,\r |
51 | PeiAllocatePool,\r | |
52 | (EFI_PEI_COPY_MEM)CopyMem,\r | |
53 | (EFI_PEI_SET_MEM)SetMem,\r | |
54 | \r | |
55 | PeiReportStatusCode,\r | |
14e8823a | 56 | PeiResetSystem,\r |
b0d803fe | 57 | \r |
8d415937 | 58 | &gPeiDefaultCpuIoPpi,\r |
59 | &gPeiDefaultPciCfg2Ppi,\r | |
b0d803fe | 60 | \r |
61 | PeiFfsFindFileByName,\r | |
62 | PeiFfsGetFileInfo,\r | |
63 | PeiFfsGetVolumeInfo,\r | |
14e8823a | 64 | PeiRegisterForShadow\r |
192f6d4c | 65 | };\r |
66 | \r | |
ef05e063 | 67 | /**\r |
68 | Shadow PeiCore module from flash to installed memory.\r | |
69 | \r | |
70 | @param PrivateData PeiCore's private data structure\r | |
71 | \r | |
72 | @return PeiCore function address after shadowing.\r | |
73 | **/\r | |
74 | PEICORE_FUNCTION_POINTER\r | |
75 | ShadowPeiCore (\r | |
76 | IN PEI_CORE_INSTANCE *PrivateData\r | |
77 | )\r | |
78 | {\r | |
79 | EFI_PEI_FILE_HANDLE PeiCoreFileHandle;\r | |
80 | EFI_PHYSICAL_ADDRESS EntryPoint;\r | |
81 | EFI_STATUS Status;\r | |
82 | UINT32 AuthenticationState;\r | |
83 | \r | |
84 | PeiCoreFileHandle = NULL;\r | |
85 | \r | |
86 | //\r | |
87 | // Find the PEI Core in the BFV\r | |
88 | //\r | |
89 | Status = PrivateData->Fv[0].FvPpi->FindFileByType (\r | |
90 | PrivateData->Fv[0].FvPpi,\r | |
91 | EFI_FV_FILETYPE_PEI_CORE,\r | |
92 | PrivateData->Fv[0].FvHandle,\r | |
93 | &PeiCoreFileHandle\r | |
94 | );\r | |
95 | ASSERT_EFI_ERROR (Status);\r | |
96 | \r | |
97 | //\r | |
98 | // Shadow PEI Core into memory so it will run faster\r | |
99 | //\r | |
100 | Status = PeiLoadImage (\r | |
101 | GetPeiServicesTablePointer (),\r | |
102 | *((EFI_PEI_FILE_HANDLE*)&PeiCoreFileHandle),\r | |
103 | PEIM_STATE_REGISITER_FOR_SHADOW,\r | |
104 | &EntryPoint,\r | |
105 | &AuthenticationState\r | |
106 | );\r | |
107 | ASSERT_EFI_ERROR (Status);\r | |
108 | \r | |
109 | //\r | |
110 | // Compute the PeiCore's function address after shaowed PeiCore.\r | |
111 | // _ModuleEntryPoint is PeiCore main function entry\r | |
112 | //\r | |
113 | return (PEICORE_FUNCTION_POINTER)((UINTN) EntryPoint + (UINTN) PeiCore - (UINTN) _ModuleEntryPoint);\r | |
114 | }\r | |
115 | \r | |
b1f6a7c6 | 116 | /**\r |
82b8c8df | 117 | This routine is invoked by main entry of PeiMain module during transition\r |
192f6d4c | 118 | from SEC to PEI. After switching stack in the PEI core, it will restart\r |
119 | with the old core data.\r | |
120 | \r | |
b1f6a7c6 | 121 | @param SecCoreData Points to a data structure containing information about the PEI core's operating\r |
5aae0aa7 | 122 | environment, such as the size and location of temporary RAM, the stack location and\r |
123 | the BFV location.\r | |
b1f6a7c6 | 124 | @param PpiList Points to a list of one or more PPI descriptors to be installed initially by the PEI core.\r |
5aae0aa7 | 125 | An empty PPI list consists of a single descriptor with the end-tag\r |
126 | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST. As part of its initialization\r | |
127 | phase, the PEI Foundation will add these SEC-hosted PPIs to its PPI database such\r | |
128 | that both the PEI Foundation and any modules can leverage the associated service\r | |
129 | calls and/or code in these early PPIs\r | |
b1f6a7c6 | 130 | @param Data Pointer to old core data that is used to initialize the\r |
192f6d4c | 131 | core's data areas.\r |
82b8c8df | 132 | If NULL, it is first PeiCore entering.\r |
192f6d4c | 133 | \r |
b1f6a7c6 | 134 | **/\r |
0308e20d | 135 | VOID\r |
b1f6a7c6 | 136 | EFIAPI\r |
137 | PeiCore (\r | |
138 | IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData,\r | |
139 | IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList,\r | |
140 | IN VOID *Data\r | |
141 | )\r | |
192f6d4c | 142 | {\r |
ef05e063 | 143 | PEI_CORE_INSTANCE PrivateData;\r |
144 | EFI_STATUS Status;\r | |
145 | PEI_CORE_TEMP_POINTERS TempPtr;\r | |
146 | UINT64 Tick;\r | |
147 | PEI_CORE_INSTANCE *OldCoreData;\r | |
148 | EFI_PEI_CPU_IO_PPI *CpuIo;\r | |
149 | EFI_PEI_PCI_CFG2_PPI *PciCfg;\r | |
150 | EFI_HOB_HANDOFF_INFO_TABLE *HandoffInformationTable;\r | |
192f6d4c | 151 | \r |
82b8c8df | 152 | Tick = 0;\r |
ef05e063 | 153 | OldCoreData = (PEI_CORE_INSTANCE *)Data;\r |
192f6d4c | 154 | \r |
40f26b8f | 155 | //\r |
156 | // Record the system tick for first entering PeiCore.\r | |
157 | // This tick is duration of executing platform seccore module.\r | |
158 | // \r | |
192f6d4c | 159 | if (PerformanceMeasurementEnabled()) {\r |
160 | if (OldCoreData == NULL) {\r | |
82b8c8df | 161 | Tick = GetPerformanceCounter ();\r |
192f6d4c | 162 | }\r |
163 | }\r | |
164 | \r | |
192f6d4c | 165 | if (OldCoreData != NULL) {\r |
ef05e063 | 166 | if (OldCoreData->ShadowedPeiCore == NULL) {\r |
167 | //\r | |
168 | //\r | |
169 | // Fixup the PeiCore's private data\r | |
170 | //\r | |
171 | OldCoreData->Ps = &OldCoreData->ServiceTableShadow;\r | |
172 | OldCoreData->CpuIo = &OldCoreData->ServiceTableShadow.CpuIo;\r | |
173 | if (OldCoreData->HeapOffsetPositive) {\r | |
174 | OldCoreData->HobList.Raw = (VOID *)(OldCoreData->HobList.Raw + OldCoreData->HeapOffset);\r | |
175 | } else {\r | |
176 | OldCoreData->HobList.Raw = (VOID *)(OldCoreData->HobList.Raw - OldCoreData->HeapOffset);\r | |
177 | }\r | |
178 | \r | |
179 | //\r | |
180 | // Fixup for PeiService's address\r | |
181 | //\r | |
182 | SetPeiServicesTablePointer ((CONST EFI_PEI_SERVICES **)&OldCoreData->Ps);\r | |
183 | \r | |
184 | //\r | |
185 | // Update HandOffHob for new installed permenent memory\r | |
186 | //\r | |
187 | HandoffInformationTable = OldCoreData->HobList.HandoffInformationTable;\r | |
188 | if (OldCoreData->HeapOffsetPositive) {\r | |
189 | HandoffInformationTable->EfiEndOfHobList = HandoffInformationTable->EfiEndOfHobList + OldCoreData->HeapOffset;\r | |
190 | } else {\r | |
191 | HandoffInformationTable->EfiEndOfHobList = HandoffInformationTable->EfiEndOfHobList - OldCoreData->HeapOffset;\r | |
192 | }\r | |
193 | HandoffInformationTable->EfiMemoryTop = OldCoreData->PhysicalMemoryBegin + OldCoreData->PhysicalMemoryLength;\r | |
194 | HandoffInformationTable->EfiMemoryBottom = OldCoreData->PhysicalMemoryBegin;\r | |
195 | HandoffInformationTable->EfiFreeMemoryTop = OldCoreData->FreePhysicalMemoryTop;\r | |
196 | HandoffInformationTable->EfiFreeMemoryBottom = HandoffInformationTable->EfiEndOfHobList + sizeof (EFI_HOB_GENERIC_HEADER);\r | |
197 | \r | |
198 | //\r | |
199 | // We need convert the PPI desciptor's pointer\r | |
200 | //\r | |
201 | ConvertPpiPointers (OldCoreData, (UINTN)SecCoreData->TemporaryRamBase, (UINTN)SecCoreData->TemporaryRamBase + SecCoreData->TemporaryRamSize, OldCoreData->HeapOffset, OldCoreData->HeapOffsetPositive);\r | |
202 | \r | |
203 | //\r | |
204 | // After the whole temporary memory is migrated, then we can allocate page in\r | |
205 | // permenent memory.\r | |
206 | //\r | |
207 | OldCoreData->PeiMemoryInstalled = TRUE;\r | |
208 | \r | |
209 | //\r | |
210 | // Indicate that PeiCore reenter\r | |
211 | //\r | |
212 | OldCoreData->PeimDispatcherReenter = TRUE;\r | |
213 | \r | |
214 | if (PcdGet64(PcdLoadModuleAtFixAddressEnable) != 0 && (OldCoreData->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME)) {\r | |
215 | //\r | |
216 | // if Loading Module at Fixed Address is enabled, allocate the PEI code memory range usage bit map array.\r | |
217 | // Every bit in the array indicate the status of the corresponding memory page available or not\r | |
218 | //\r | |
219 | OldCoreData->PeiCodeMemoryRangeUsageBitMap = AllocateZeroPool (((PcdGet32(PcdLoadFixAddressPeiCodePageNumber)>>6) + 1)*sizeof(UINT64));\r | |
220 | }\r | |
221 | \r | |
222 | //\r | |
223 | // Process the Notify list and dispatch any notifies for\r | |
224 | // newly installed PPIs.\r | |
225 | //\r | |
226 | ProcessNotifyList (OldCoreData);\r | |
227 | \r | |
228 | //\r | |
229 | // Shadow PEI Core. When permanent memory is avaiable, shadow\r | |
230 | // PEI Core and PEIMs to get high performance.\r | |
231 | //\r | |
232 | OldCoreData->ShadowedPeiCore = ShadowPeiCore (OldCoreData);\r | |
233 | \r | |
234 | //\r | |
235 | // PeiCore has been shadowed to memory for first entering, so\r | |
236 | // just jump to PeiCore in memory here.\r | |
237 | //\r | |
238 | OldCoreData->ShadowedPeiCore (SecCoreData, PpiList, OldCoreData);\r | |
58dcdada | 239 | }\r |
240 | \r | |
ef05e063 | 241 | CopyMem (&PrivateData, OldCoreData, sizeof (PrivateData));\r |
b0d803fe | 242 | \r |
243 | CpuIo = (VOID*)PrivateData.ServiceTableShadow.CpuIo;\r | |
244 | PciCfg = (VOID*)PrivateData.ServiceTableShadow.PciCfg;\r | |
245 | \r | |
b1f6a7c6 | 246 | CopyMem (&PrivateData.ServiceTableShadow, &gPs, sizeof (gPs));\r |
b0d803fe | 247 | \r |
248 | PrivateData.ServiceTableShadow.CpuIo = CpuIo;\r | |
249 | PrivateData.ServiceTableShadow.PciCfg = PciCfg;\r | |
192f6d4c | 250 | } else {\r |
82b8c8df | 251 | //\r |
252 | // If OldCoreData is NULL, means current is first Peicore's entering.\r | |
253 | //\r | |
254 | \r | |
192f6d4c | 255 | ZeroMem (&PrivateData, sizeof (PEI_CORE_INSTANCE));\r |
b0d803fe | 256 | PrivateData.Signature = PEI_CORE_HANDLE_SIGNATURE;\r |
b1f6a7c6 | 257 | CopyMem (&PrivateData.ServiceTableShadow, &gPs, sizeof (gPs));\r |
192f6d4c | 258 | }\r |
259 | \r | |
4140a663 | 260 | PrivateData.Ps = &PrivateData.ServiceTableShadow;\r |
192f6d4c | 261 | \r |
262 | //\r | |
263 | // Initialize libraries that the PeiCore is linked against\r | |
192f6d4c | 264 | //\r |
4140a663 | 265 | ProcessLibraryConstructorList (NULL, (CONST EFI_PEI_SERVICES **)&PrivateData.Ps);\r |
192f6d4c | 266 | \r |
b0d803fe | 267 | InitializeMemoryServices (&PrivateData, SecCoreData, OldCoreData);\r |
192f6d4c | 268 | \r |
b0d803fe | 269 | InitializePpiServices (&PrivateData, OldCoreData);\r |
192f6d4c | 270 | \r |
81c7803c | 271 | //\r |
272 | // Save PeiServicePointer so that it can be retrieved anywhere.\r | |
273 | //\r | |
4140a663 | 274 | SetPeiServicesTablePointer((CONST EFI_PEI_SERVICES **) &PrivateData.Ps);\r |
81c7803c | 275 | \r |
192f6d4c | 276 | if (OldCoreData != NULL) {\r |
277 | \r | |
278 | PERF_END (NULL,"PreMem", NULL, 0);\r | |
279 | PERF_START (NULL,"PostMem", NULL, 0);\r | |
280 | \r | |
192f6d4c | 281 | //\r |
282 | // Alert any listeners that there is permanent memory available\r | |
283 | //\r | |
284 | \r | |
285 | PERF_START (NULL,"DisMem", NULL, 0);\r | |
286 | Status = PeiServicesInstallPpi (&mMemoryDiscoveredPpi);\r | |
287 | PERF_END (NULL,"DisMem", NULL, 0);\r | |
288 | \r | |
289 | } else {\r | |
290 | \r | |
291 | //\r | |
292 | // Report Status Code EFI_SW_PC_INIT\r | |
293 | //\r | |
294 | REPORT_STATUS_CODE (\r | |
295 | EFI_PROGRESS_CODE,\r | |
f9876ecf | 296 | (EFI_SOFTWARE_PEI_CORE | EFI_SW_PC_INIT)\r |
192f6d4c | 297 | );\r |
008d4018 | 298 | \r |
299 | PERF_START (NULL, "SEC", NULL, 1);\r | |
300 | PERF_END (NULL, "SEC", NULL, Tick);\r | |
192f6d4c | 301 | \r |
82b8c8df | 302 | PERF_START (NULL,"PEI", NULL, Tick);\r |
192f6d4c | 303 | //\r |
304 | // If first pass, start performance measurement.\r | |
305 | //\r | |
82b8c8df | 306 | PERF_START (NULL,"PreMem", NULL, Tick);\r |
192f6d4c | 307 | \r |
308 | //\r | |
309 | // If SEC provided any PPI services to PEI, install them.\r | |
310 | //\r | |
5088e385 | 311 | if (PpiList != NULL) {\r |
312 | Status = PeiServicesInstallPpi (PpiList);\r | |
192f6d4c | 313 | ASSERT_EFI_ERROR (Status);\r |
314 | }\r | |
315 | }\r | |
316 | \r | |
4140a663 | 317 | InitializeSecurityServices (&PrivateData.Ps, OldCoreData);\r |
b0d803fe | 318 | \r |
319 | InitializeDispatcherData (&PrivateData, OldCoreData, SecCoreData);\r | |
320 | \r | |
321 | //\r | |
322 | // Install Pei Load File PPI. \r | |
323 | //\r | |
324 | InitializeImageServices (&PrivateData, OldCoreData);\r | |
192f6d4c | 325 | \r |
326 | //\r | |
327 | // Call PEIM dispatcher\r | |
328 | //\r | |
b0d803fe | 329 | PeiDispatcher (SecCoreData, &PrivateData);\r |
192f6d4c | 330 | \r |
331 | //\r | |
332 | // Check if InstallPeiMemory service was called.\r | |
333 | //\r | |
334 | ASSERT(PrivateData.PeiMemoryInstalled == TRUE);\r | |
335 | \r | |
40f26b8f | 336 | //\r |
337 | // Till now, PEI phase will be finished, get performace count\r | |
338 | // for computing duration of PEI phase\r | |
339 | //\r | |
192f6d4c | 340 | PERF_END (NULL, "PostMem", NULL, 0);\r |
341 | \r | |
342 | Status = PeiServicesLocatePpi (\r | |
343 | &gEfiDxeIplPpiGuid,\r | |
344 | 0,\r | |
345 | NULL,\r | |
346 | (VOID **)&TempPtr.DxeIpl\r | |
347 | );\r | |
348 | ASSERT_EFI_ERROR (Status);\r | |
349 | \r | |
40f26b8f | 350 | //\r |
351 | // Enter DxeIpl to load Dxe core.\r | |
352 | //\r | |
192f6d4c | 353 | DEBUG ((EFI_D_INFO, "DXE IPL Entry\n"));\r |
354 | Status = TempPtr.DxeIpl->Entry (\r | |
355 | TempPtr.DxeIpl,\r | |
4140a663 | 356 | &PrivateData.Ps,\r |
192f6d4c | 357 | PrivateData.HobList\r |
358 | );\r | |
0308e20d | 359 | //\r |
360 | // Should never reach here.\r | |
361 | //\r | |
192f6d4c | 362 | ASSERT_EFI_ERROR (Status);\r |
0308e20d | 363 | CpuDeadLoop();\r |
192f6d4c | 364 | }\r |
365 | \r | |
a3a15d21 | 366 | \r |