]>
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 | |
ef05e063 | 146 | PEI_CORE_INSTANCE *OldCoreData;\r |
147 | EFI_PEI_CPU_IO_PPI *CpuIo;\r | |
148 | EFI_PEI_PCI_CFG2_PPI *PciCfg;\r | |
149 | EFI_HOB_HANDOFF_INFO_TABLE *HandoffInformationTable;\r | |
192f6d4c | 150 | \r |
6b22483f | 151 | //\r |
152 | // Retrieve context passed into PEI Core\r | |
153 | //\r | |
ef05e063 | 154 | OldCoreData = (PEI_CORE_INSTANCE *)Data;\r |
192f6d4c | 155 | \r |
40f26b8f | 156 | //\r |
6b22483f | 157 | // Perform PEI Core phase specific actions.\r |
158 | //\r | |
159 | if (OldCoreData == NULL) {\r | |
160 | //\r | |
161 | // If OldCoreData is NULL, means current is the first entry into the PEI Core before memory is available.\r | |
162 | //\r | |
163 | ZeroMem (&PrivateData, sizeof (PEI_CORE_INSTANCE));\r | |
164 | PrivateData.Signature = PEI_CORE_HANDLE_SIGNATURE;\r | |
165 | CopyMem (&PrivateData.ServiceTableShadow, &gPs, sizeof (gPs));\r | |
166 | } else {\r | |
167 | //\r | |
168 | // Memory is available to the PEI Core. See if the PEI Core has been shadowed to memory yet.\r | |
169 | //\r | |
ef05e063 | 170 | if (OldCoreData->ShadowedPeiCore == NULL) {\r |
ef05e063 | 171 | //\r |
172 | // Fixup the PeiCore's private data\r | |
173 | //\r | |
6b22483f | 174 | OldCoreData->Ps = &OldCoreData->ServiceTableShadow;\r |
175 | OldCoreData->CpuIo = &OldCoreData->ServiceTableShadow.CpuIo;\r | |
ef05e063 | 176 | if (OldCoreData->HeapOffsetPositive) {\r |
177 | OldCoreData->HobList.Raw = (VOID *)(OldCoreData->HobList.Raw + OldCoreData->HeapOffset);\r | |
178 | } else {\r | |
179 | OldCoreData->HobList.Raw = (VOID *)(OldCoreData->HobList.Raw - OldCoreData->HeapOffset);\r | |
180 | }\r | |
181 | \r | |
6b22483f | 182 | //\r |
183 | // Initialize libraries that the PEI Core is linked against\r | |
184 | //\r | |
185 | ProcessLibraryConstructorList (NULL, (CONST EFI_PEI_SERVICES **)&OldCoreData->Ps);\r | |
186 | \r | |
ef05e063 | 187 | //\r |
188 | // Fixup for PeiService's address\r | |
189 | //\r | |
190 | SetPeiServicesTablePointer ((CONST EFI_PEI_SERVICES **)&OldCoreData->Ps);\r | |
191 | \r | |
192 | //\r | |
193 | // Update HandOffHob for new installed permenent memory\r | |
194 | //\r | |
195 | HandoffInformationTable = OldCoreData->HobList.HandoffInformationTable;\r | |
196 | if (OldCoreData->HeapOffsetPositive) {\r | |
197 | HandoffInformationTable->EfiEndOfHobList = HandoffInformationTable->EfiEndOfHobList + OldCoreData->HeapOffset;\r | |
198 | } else {\r | |
199 | HandoffInformationTable->EfiEndOfHobList = HandoffInformationTable->EfiEndOfHobList - OldCoreData->HeapOffset;\r | |
200 | }\r | |
201 | HandoffInformationTable->EfiMemoryTop = OldCoreData->PhysicalMemoryBegin + OldCoreData->PhysicalMemoryLength;\r | |
202 | HandoffInformationTable->EfiMemoryBottom = OldCoreData->PhysicalMemoryBegin;\r | |
203 | HandoffInformationTable->EfiFreeMemoryTop = OldCoreData->FreePhysicalMemoryTop;\r | |
204 | HandoffInformationTable->EfiFreeMemoryBottom = HandoffInformationTable->EfiEndOfHobList + sizeof (EFI_HOB_GENERIC_HEADER);\r | |
205 | \r | |
206 | //\r | |
207 | // We need convert the PPI desciptor's pointer\r | |
208 | //\r | |
209 | ConvertPpiPointers (OldCoreData, (UINTN)SecCoreData->TemporaryRamBase, (UINTN)SecCoreData->TemporaryRamBase + SecCoreData->TemporaryRamSize, OldCoreData->HeapOffset, OldCoreData->HeapOffsetPositive);\r | |
210 | \r | |
211 | //\r | |
212 | // After the whole temporary memory is migrated, then we can allocate page in\r | |
213 | // permenent memory.\r | |
214 | //\r | |
215 | OldCoreData->PeiMemoryInstalled = TRUE;\r | |
216 | \r | |
217 | //\r | |
218 | // Indicate that PeiCore reenter\r | |
219 | //\r | |
220 | OldCoreData->PeimDispatcherReenter = TRUE;\r | |
221 | \r | |
222 | if (PcdGet64(PcdLoadModuleAtFixAddressEnable) != 0 && (OldCoreData->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME)) {\r | |
223 | //\r | |
224 | // if Loading Module at Fixed Address is enabled, allocate the PEI code memory range usage bit map array.\r | |
225 | // Every bit in the array indicate the status of the corresponding memory page available or not\r | |
226 | //\r | |
227 | OldCoreData->PeiCodeMemoryRangeUsageBitMap = AllocateZeroPool (((PcdGet32(PcdLoadFixAddressPeiCodePageNumber)>>6) + 1)*sizeof(UINT64));\r | |
228 | }\r | |
229 | \r | |
ef05e063 | 230 | //\r |
231 | // Shadow PEI Core. When permanent memory is avaiable, shadow\r | |
232 | // PEI Core and PEIMs to get high performance.\r | |
233 | //\r | |
234 | OldCoreData->ShadowedPeiCore = ShadowPeiCore (OldCoreData);\r | |
235 | \r | |
236 | //\r | |
6b22483f | 237 | // PEI Core has now been shadowed to memory. Restart PEI Core in memory.\r |
ef05e063 | 238 | //\r |
239 | OldCoreData->ShadowedPeiCore (SecCoreData, PpiList, OldCoreData);\r | |
6b22483f | 240 | \r |
241 | //\r | |
242 | // Should never reach here.\r | |
243 | //\r | |
244 | ASSERT (FALSE);\r | |
245 | CpuDeadLoop();\r | |
58dcdada | 246 | }\r |
247 | \r | |
6b22483f | 248 | //\r |
249 | // Memory is available to the PEI Core and the PEI Core has been shadowed to memory.\r | |
250 | //\r | |
251 | \r | |
ef05e063 | 252 | CopyMem (&PrivateData, OldCoreData, sizeof (PrivateData));\r |
b0d803fe | 253 | \r |
254 | CpuIo = (VOID*)PrivateData.ServiceTableShadow.CpuIo;\r | |
255 | PciCfg = (VOID*)PrivateData.ServiceTableShadow.PciCfg;\r | |
256 | \r | |
b1f6a7c6 | 257 | CopyMem (&PrivateData.ServiceTableShadow, &gPs, sizeof (gPs));\r |
b0d803fe | 258 | \r |
259 | PrivateData.ServiceTableShadow.CpuIo = CpuIo;\r | |
260 | PrivateData.ServiceTableShadow.PciCfg = PciCfg;\r | |
192f6d4c | 261 | }\r |
6b22483f | 262 | \r |
263 | //\r | |
264 | // Cache a pointer to the PEI Services Table that is either in temporary memory or permanent memory\r | |
265 | //\r | |
4140a663 | 266 | PrivateData.Ps = &PrivateData.ServiceTableShadow;\r |
192f6d4c | 267 | \r |
268 | //\r | |
6b22483f | 269 | // Initialize libraries that the PEI Core is linked against\r |
192f6d4c | 270 | //\r |
4140a663 | 271 | ProcessLibraryConstructorList (NULL, (CONST EFI_PEI_SERVICES **)&PrivateData.Ps);\r |
192f6d4c | 272 | \r |
81c7803c | 273 | //\r |
274 | // Save PeiServicePointer so that it can be retrieved anywhere.\r | |
275 | //\r | |
6b22483f | 276 | SetPeiServicesTablePointer ((CONST EFI_PEI_SERVICES **)&PrivateData.Ps);\r |
192f6d4c | 277 | \r |
6b22483f | 278 | //\r |
279 | // Initialize PEI Core Services\r | |
280 | // \r | |
281 | InitializeMemoryServices (&PrivateData, SecCoreData, OldCoreData);\r | |
282 | InitializePpiServices (&PrivateData, OldCoreData);\r | |
283 | \r | |
284 | //\r | |
285 | // Update performance measurements \r | |
286 | //\r | |
287 | if (OldCoreData == NULL) {\r | |
288 | PERF_START (NULL, "SEC", NULL, 1);\r | |
289 | PERF_END (NULL, "SEC", NULL, 0);\r | |
192f6d4c | 290 | \r |
192f6d4c | 291 | //\r |
6b22483f | 292 | // If first pass, start performance measurement.\r |
192f6d4c | 293 | //\r |
6b22483f | 294 | PERF_START (NULL,"PEI", NULL, 0);\r |
295 | PERF_START (NULL,"PreMem", NULL, 0);\r | |
192f6d4c | 296 | \r |
297 | } else {\r | |
6b22483f | 298 | PERF_END (NULL,"PreMem", NULL, 0);\r |
299 | PERF_START (NULL,"PostMem", NULL, 0);\r | |
300 | }\r | |
301 | \r | |
302 | //\r | |
303 | // Complete PEI Core Service initialization\r | |
304 | // \r | |
305 | InitializeSecurityServices (&PrivateData.Ps, OldCoreData);\r | |
306 | InitializeDispatcherData (&PrivateData, OldCoreData, SecCoreData);\r | |
307 | InitializeImageServices (&PrivateData, OldCoreData);\r | |
192f6d4c | 308 | \r |
6b22483f | 309 | //\r |
310 | // Perform PEI Core Phase specific actions\r | |
311 | // \r | |
312 | if (OldCoreData == NULL) {\r | |
192f6d4c | 313 | //\r |
314 | // Report Status Code EFI_SW_PC_INIT\r | |
315 | //\r | |
316 | REPORT_STATUS_CODE (\r | |
317 | EFI_PROGRESS_CODE,\r | |
f9876ecf | 318 | (EFI_SOFTWARE_PEI_CORE | EFI_SW_PC_INIT)\r |
192f6d4c | 319 | );\r |
008d4018 | 320 | \r |
192f6d4c | 321 | //\r |
322 | // If SEC provided any PPI services to PEI, install them.\r | |
323 | //\r | |
5088e385 | 324 | if (PpiList != NULL) {\r |
325 | Status = PeiServicesInstallPpi (PpiList);\r | |
192f6d4c | 326 | ASSERT_EFI_ERROR (Status);\r |
327 | }\r | |
6b22483f | 328 | } else {\r |
329 | //\r | |
330 | // Alert any listeners that there is permanent memory available\r | |
331 | //\r | |
332 | PERF_START (NULL,"DisMem", NULL, 0);\r | |
333 | Status = PeiServicesInstallPpi (&mMemoryDiscoveredPpi);\r | |
b0d803fe | 334 | \r |
6b22483f | 335 | //\r |
336 | // Process the Notify list and dispatch any notifies for the Memory Discovered PPI\r | |
337 | //\r | |
338 | ProcessNotifyList (&PrivateData);\r | |
b0d803fe | 339 | \r |
6b22483f | 340 | PERF_END (NULL,"DisMem", NULL, 0);\r |
341 | }\r | |
192f6d4c | 342 | \r |
343 | //\r | |
344 | // Call PEIM dispatcher\r | |
345 | //\r | |
b0d803fe | 346 | PeiDispatcher (SecCoreData, &PrivateData);\r |
192f6d4c | 347 | \r |
348 | //\r | |
349 | // Check if InstallPeiMemory service was called.\r | |
350 | //\r | |
351 | ASSERT(PrivateData.PeiMemoryInstalled == TRUE);\r | |
352 | \r | |
40f26b8f | 353 | //\r |
6b22483f | 354 | // Measure PEI Core execution time.\r |
40f26b8f | 355 | //\r |
192f6d4c | 356 | PERF_END (NULL, "PostMem", NULL, 0);\r |
357 | \r | |
6b22483f | 358 | //\r |
359 | // Lookup DXE IPL PPI\r | |
360 | //\r | |
192f6d4c | 361 | Status = PeiServicesLocatePpi (\r |
362 | &gEfiDxeIplPpiGuid,\r | |
363 | 0,\r | |
364 | NULL,\r | |
365 | (VOID **)&TempPtr.DxeIpl\r | |
366 | );\r | |
367 | ASSERT_EFI_ERROR (Status);\r | |
368 | \r | |
40f26b8f | 369 | //\r |
370 | // Enter DxeIpl to load Dxe core.\r | |
371 | //\r | |
192f6d4c | 372 | DEBUG ((EFI_D_INFO, "DXE IPL Entry\n"));\r |
373 | Status = TempPtr.DxeIpl->Entry (\r | |
374 | TempPtr.DxeIpl,\r | |
4140a663 | 375 | &PrivateData.Ps,\r |
192f6d4c | 376 | PrivateData.HobList\r |
377 | );\r | |
0308e20d | 378 | //\r |
379 | // Should never reach here.\r | |
380 | //\r | |
192f6d4c | 381 | ASSERT_EFI_ERROR (Status);\r |
0308e20d | 382 | CpuDeadLoop();\r |
192f6d4c | 383 | }\r |