]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c
1) If PeiLoadImage fails, the section extraction PPI or Decompress PPI may not be...
[mirror_edk2.git] / MdeModulePkg / Core / Pei / Dispatcher / Dispatcher.c
CommitLineData
192f6d4c 1/*++\r
2\r
3Copyright (c) 2006, Intel Corporation\r
4All rights reserved. This program and the accompanying materials\r
5are licensed and made available under the terms and conditions of the BSD License\r
6which accompanies this distribution. The full text of the license may be found at\r
7http://opensource.org/licenses/bsd-license.php\r
8\r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11\r
12Module Name:\r
13\r
14 Dispatcher.c\r
15\r
16Abstract:\r
17\r
18 EFI PEI Core dispatch services\r
19\r
20Revision History\r
21\r
22--*/\r
23\r
192f6d4c 24#include <PeiMain.h>\r
25\r
b98c2ab7 26STATIC\r
27VOID\r
28InvokePeiCore (\r
29 VOID *Context1,\r
30 VOID *Context2\r
31 );\r
32\r
b0d803fe 33\r
34VOID\r
35DiscoverPeimsAndOrderWithApriori (\r
36 IN PEI_CORE_INSTANCE *Private,\r
37 IN EFI_PEI_FV_HANDLE VolumeHandle\r
38 )\r
39/*++\r
40\r
41Routine Description:\r
42\r
43 Discover all Peims and optional Apriori file in one FV. There is at most one\r
44 Apriori file in one FV.\r
45\r
46Arguments:\r
47\r
48 Private - Pointer to the private data passed in from caller\r
49 VolumeHandle - Fv handle.\r
50Returns:\r
51\r
52 NONE\r
53\r
54--*/ \r
55{\r
56 EFI_STATUS Status;\r
57 EFI_PEI_FV_HANDLE FileHandle;\r
177aabe6 58 EFI_PEI_FILE_HANDLE AprioriFileHandle;\r
b0d803fe 59 EFI_GUID *Apriori;\r
60 UINTN Index;\r
61 UINTN Index2;\r
62 UINTN PeimIndex;\r
63 UINTN PeimCount;\r
64 EFI_GUID *Guid;\r
177aabe6 65 EFI_PEI_FV_HANDLE TempFileHandles[FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv)];\r
66 EFI_GUID FileGuid[FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv)];\r
b0d803fe 67\r
68 //\r
69 // Walk the FV and find all the PEIMs and the Apriori file.\r
70 //\r
71 AprioriFileHandle = NULL;\r
72 Private->CurrentFvFileHandles[0] = NULL;\r
73 Guid = NULL;\r
74 FileHandle = NULL;\r
75\r
76 //\r
77 // If the current Fv has been scanned, directly get its cachable record.\r
78 //\r
79 if (Private->Fv[Private->CurrentPeimFvCount].ScanFv) {\r
80 CopyMem (Private->CurrentFvFileHandles, Private->Fv[Private->CurrentPeimFvCount].FvFileHandles, sizeof (Private->CurrentFvFileHandles));\r
81 return;\r
82 }\r
83\r
84 //\r
85 // Go ahead to scan this Fv, and cache FileHandles within it.\r
86 //\r
177aabe6 87 for (PeimCount = 0; PeimCount < FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv); PeimCount++) {\r
b0d803fe 88 Status = PeiFindFileEx (\r
89 VolumeHandle, \r
90 NULL, \r
91 PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE, \r
92 &FileHandle,\r
93 &AprioriFileHandle\r
94 );\r
95 if (Status != EFI_SUCCESS) {\r
96 break;\r
97 }\r
98 \r
99 Private->CurrentFvFileHandles[PeimCount] = FileHandle;\r
100 }\r
101\r
102 Private->AprioriCount = 0; \r
103 if (AprioriFileHandle != NULL) {\r
104 //\r
105 // Read the Apriori file\r
106 //\r
177aabe6 107 Status = PeiServicesFfsFindSectionData (EFI_SECTION_RAW, AprioriFileHandle, (VOID **) &Apriori);\r
b0d803fe 108 if (!EFI_ERROR (Status)) {\r
109 //\r
110 // Calculate the number of PEIMs in the A Priori list\r
111 //\r
112 Private->AprioriCount = *(UINT32 *)(((EFI_FFS_FILE_HEADER *)AprioriFileHandle)->Size) & 0x00FFFFFF;\r
113 Private->AprioriCount -= sizeof (EFI_FFS_FILE_HEADER) - sizeof (EFI_COMMON_SECTION_HEADER); \r
114 Private->AprioriCount /= sizeof (EFI_GUID);\r
115 \r
116 SetMem (FileGuid, sizeof (FileGuid), 0);\r
117 for (Index = 0; Index < PeimCount; Index++) {\r
118 //\r
119 // Make an array of file name guids that matches the FileHandle array so we can convert\r
120 // quickly from file name to file handle\r
121 //\r
122 CopyMem (&FileGuid[Index], &((EFI_FFS_FILE_HEADER *)Private->CurrentFvFileHandles[Index])->Name,sizeof(EFI_GUID)); \r
123 }\r
124\r
125 //\r
126 // Walk through FileGuid array to find out who is invalid PEIM guid in Apriori file.\r
127 // Add avalible PEIMs in Apriori file into TempFileHandles array at first. \r
128 //\r
129 Index2 = 0;\r
130 for (Index = 0; Index2 < Private->AprioriCount; Index++) {\r
131 while (Index2 < Private->AprioriCount) {\r
132 Guid = ScanGuid (FileGuid, PeimCount * sizeof (EFI_GUID), &Apriori[Index2++]);\r
133 if (Guid != NULL) {\r
134 break;\r
135 }\r
136 }\r
137 if (Guid == NULL) {\r
138 break; \r
139 }\r
140 PeimIndex = ((UINTN)Guid - (UINTN)&FileGuid[0])/sizeof (EFI_GUID);\r
141 TempFileHandles[Index] = Private->CurrentFvFileHandles[PeimIndex];\r
142\r
143 //\r
144 // Since we have copied the file handle we can remove it from this list.\r
145 //\r
146 Private->CurrentFvFileHandles[PeimIndex] = NULL;\r
147 }\r
148\r
149 //\r
150 // Update valid Aprioricount\r
151 //\r
152 Private->AprioriCount = Index;\r
153 \r
154 //\r
155 // Add in any PEIMs not in the Apriori file\r
156 //\r
157 for (;Index < PeimCount; Index++) {\r
158 for (Index2 = 0; Index2 < PeimCount; Index2++) {\r
159 if (Private->CurrentFvFileHandles[Index2] != NULL) {\r
160 TempFileHandles[Index] = Private->CurrentFvFileHandles[Index2];\r
161 Private->CurrentFvFileHandles[Index2] = NULL;\r
162 break;\r
163 }\r
164 }\r
165 }\r
166 //\r
167 //Index the end of array contains re-range Pei moudle.\r
168 //\r
169 TempFileHandles[Index] = NULL;\r
170 \r
171 //\r
172 // Private->CurrentFvFileHandles is currently in PEIM in the FV order.\r
173 // We need to update it to start with files in the A Priori list and \r
174 // then the remaining files in PEIM order. \r
175 //\r
176 CopyMem (Private->CurrentFvFileHandles, TempFileHandles, sizeof (Private->CurrentFvFileHandles));\r
177 }\r
178 }\r
179 //\r
180 // Cache the current Fv File Handle. So that we don't have to scan the Fv again.\r
181 // Instead, we can retrieve the file handles within this Fv from cachable data.\r
182 //\r
183 Private->Fv[Private->CurrentPeimFvCount].ScanFv = TRUE;\r
184 CopyMem (Private->Fv[Private->CurrentPeimFvCount].FvFileHandles, Private->CurrentFvFileHandles, sizeof (Private->CurrentFvFileHandles));\r
185 \r
186}\r
187\r
188VOID\r
192f6d4c 189PeiDispatcher (\r
5aae0aa7 190 IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData,\r
b0d803fe 191 IN PEI_CORE_INSTANCE *Private\r
192f6d4c 192 )\r
193\r
194/*++\r
195\r
196Routine Description:\r
197\r
198 Conduct PEIM dispatch.\r
199\r
200Arguments:\r
201\r
5aae0aa7 202 SecCoreData - Points to a data structure containing information about the PEI core's operating\r
203 environment, such as the size and location of temporary RAM, the stack location and\r
204 the BFV location.\r
192f6d4c 205 PrivateData - Pointer to the private data passed in from caller\r
206 DispatchData - Pointer to PEI_CORE_DISPATCH_DATA data.\r
207\r
208Returns:\r
209\r
210 EFI_SUCCESS - Successfully dispatched PEIM.\r
211 EFI_NOT_FOUND - The dispatch failed.\r
212\r
213--*/\r
214{\r
b0d803fe 215 EFI_STATUS Status;\r
216 UINT32 Index1;\r
217 UINT32 Index2;\r
218 EFI_PEI_SERVICES **PeiServices;\r
219 VOID *PrivateInMem;\r
220 EFI_PEI_FV_HANDLE VolumeHandle; \r
221 EFI_PEI_FILE_HANDLE PeiCoreFileHandle;\r
222 EFI_PEI_FILE_HANDLE PeimFileHandle;\r
223 UINTN FvCount;\r
224 UINTN PeimCount;\r
225 UINT32 AuthenticationState;\r
226 EFI_PHYSICAL_ADDRESS EntryPoint;\r
227 EFI_PEIM_ENTRY_POINT PeimEntryPoint;\r
228 BOOLEAN PeimNeedingDispatch;\r
229 BOOLEAN PeimDispatchOnThisPass;\r
230 UINTN SaveCurrentPeimCount;\r
1053e0c5 231 UINTN SaveCurrentFvCount;\r
b0d803fe 232 EFI_PEI_FILE_HANDLE SaveCurrentFileHandle;\r
233 VOID *TopOfStack;\r
234 PEI_CORE_PARAMETERS PeiCoreParameters;\r
235 EFI_DEVICE_HANDLE_EXTENDED_DATA ExtendedData;\r
236\r
237\r
238 PeiServices = &Private->PS;\r
239 PeimEntryPoint = NULL;\r
240 PeimFileHandle = NULL;\r
241\r
242 if ((Private->PeiMemoryInstalled) && (Private->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME)) {\r
243 //\r
244 // Once real memory is available, shadow the RegisterForShadow modules. And meanwhile\r
245 // update the modules' status from PEIM_STATE_REGISITER_FOR_SHADOW to PEIM_STATE_DONE.\r
246 //\r
247 SaveCurrentPeimCount = Private->CurrentPeimCount;\r
1053e0c5 248 SaveCurrentFvCount = Private->CurrentPeimFvCount;\r
b0d803fe 249 SaveCurrentFileHandle = Private->CurrentFileHandle;\r
250\r
1053e0c5 251 for (Index1 = 0; Index1 <= SaveCurrentFvCount; Index1++) {\r
177aabe6 252 for (Index2 = 0; (Index2 < FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv)) && (Private->Fv[Index1].FvFileHandles[Index2] != NULL); Index2++) {\r
b0d803fe 253 if (Private->Fv[Index1].PeimState[Index2] == PEIM_STATE_REGISITER_FOR_SHADOW) {\r
254 PeimFileHandle = Private->Fv[Index1].FvFileHandles[Index2]; \r
255 Status = PeiLoadImage (\r
256 &Private->PS, \r
257 PeimFileHandle, \r
258 &EntryPoint, \r
259 &AuthenticationState\r
260 );\r
261 if (Status == EFI_SUCCESS) {\r
262 //\r
263 // PEIM_STATE_REGISITER_FOR_SHADOW move to PEIM_STATE_DONE\r
264 //\r
265 Private->Fv[Index1].PeimState[Index2]++;\r
1053e0c5 266 Private->CurrentFileHandle = PeimFileHandle;\r
267 Private->CurrentPeimFvCount = Index1; \r
268 Private->CurrentPeimCount = Index2; \r
b0d803fe 269 //\r
270 // Call the PEIM entry point\r
271 //\r
272 PeimEntryPoint = (EFI_PEIM_ENTRY_POINT)(UINTN)EntryPoint;\r
273 \r
274 PERF_START (0, "PEIM", NULL, 0);\r
275 PeimEntryPoint(PeimFileHandle, &Private->PS);\r
276 PERF_END (0, "PEIM", NULL, 0);\r
277 } \r
278 \r
279 //\r
280 // Process the Notify list and dispatch any notifies for\r
281 // newly installed PPIs.\r
282 //\r
283 ProcessNotifyList (Private);\r
284 }\r
285 }\r
286 }\r
1053e0c5 287 Private->CurrentFileHandle = SaveCurrentFileHandle; \r
288 Private->CurrentPeimFvCount = SaveCurrentFvCount; \r
289 Private->CurrentPeimCount = SaveCurrentPeimCount; \r
b0d803fe 290 }\r
192f6d4c 291\r
292 //\r
293 // This is the main dispatch loop. It will search known FVs for PEIMs and\r
294 // attempt to dispatch them. If any PEIM gets dispatched through a single\r
295 // pass of the dispatcher, it will start over from the Bfv again to see\r
296 // if any new PEIMs dependencies got satisfied. With a well ordered\r
297 // FV where PEIMs are found in the order their dependencies are also\r
298 // satisfied, this dipatcher should run only once.\r
299 //\r
b0d803fe 300 do {\r
301 PeimNeedingDispatch = FALSE;\r
302 PeimDispatchOnThisPass = FALSE;\r
303\r
304 for (FvCount = Private->CurrentPeimFvCount; FvCount < Private->FvCount; FvCount++) {\r
305 Private->CurrentPeimFvCount = FvCount;\r
306 VolumeHandle = Private->Fv[FvCount].FvHeader;\r
192f6d4c 307\r
b0d803fe 308 if (Private->CurrentPeimCount == 0) {\r
309 //\r
310 // When going through each FV, at first, search Apriori file to\r
311 // reorder all PEIMs to ensure the PEIMs in Apriori file to get \r
312 // dispatch at first.\r
313 //\r
314 DiscoverPeimsAndOrderWithApriori (Private, VolumeHandle);\r
315 }\r
192f6d4c 316\r
317 //\r
b0d803fe 318 // Start to dispatch all modules within the current Fv.\r
192f6d4c 319 //\r
b0d803fe 320 for (PeimCount = Private->CurrentPeimCount; \r
177aabe6 321 (PeimCount < FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv)) && (Private->CurrentFvFileHandles[PeimCount] != NULL); \r
b0d803fe 322 PeimCount++) {\r
323 Private->CurrentPeimCount = PeimCount;\r
324 PeimFileHandle = Private->CurrentFileHandle = Private->CurrentFvFileHandles[PeimCount];\r
325\r
326 if (Private->Fv[FvCount].PeimState[PeimCount] == PEIM_STATE_NOT_DISPATCHED) {\r
327 if (!DepexSatisfied (Private, PeimFileHandle, PeimCount)) {\r
328 PeimNeedingDispatch = TRUE;\r
329 } else {\r
192f6d4c 330 Status = PeiLoadImage (\r
b0d803fe 331 PeiServices, \r
332 PeimFileHandle, \r
333 &EntryPoint, \r
334 &AuthenticationState\r
192f6d4c 335 );\r
b0d803fe 336 if ((Status == EFI_SUCCESS)) {\r
192f6d4c 337 //\r
338 // The PEIM has its dependencies satisfied, and its entry point\r
339 // has been found, so invoke it.\r
340 //\r
b0d803fe 341 PERF_START (0, "PEIM", NULL, 0);\r
192f6d4c 342\r
b0d803fe 343 ExtendedData.Handle = (EFI_HANDLE)PeimFileHandle;\r
192f6d4c 344\r
345 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (\r
346 EFI_PROGRESS_CODE,\r
347 EFI_SOFTWARE_PEI_CORE | EFI_SW_PC_INIT_BEGIN,\r
348 (VOID *)(&ExtendedData),\r
349 sizeof (ExtendedData)\r
350 );\r
351\r
b0d803fe 352 Status = VerifyPeim (Private, VolumeHandle, PeimFileHandle);\r
353 if (Status != EFI_SECURITY_VIOLATION && (AuthenticationState == 0)) {\r
354 //\r
355 // PEIM_STATE_NOT_DISPATCHED move to PEIM_STATE_DISPATCHED\r
356 //\r
357 Private->Fv[FvCount].PeimState[PeimCount]++;\r
192f6d4c 358\r
359 //\r
b0d803fe 360 // Call the PEIM entry point\r
192f6d4c 361 //\r
b0d803fe 362 PeimEntryPoint = (EFI_PEIM_ENTRY_POINT)(UINTN)EntryPoint;\r
363 PeimEntryPoint (PeimFileHandle, PeiServices);\r
364 PeimDispatchOnThisPass = TRUE;\r
192f6d4c 365 }\r
366\r
367 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (\r
368 EFI_PROGRESS_CODE,\r
369 EFI_SOFTWARE_PEI_CORE | EFI_SW_PC_INIT_END,\r
370 (VOID *)(&ExtendedData),\r
371 sizeof (ExtendedData)\r
372 );\r
b0d803fe 373 PERF_END (0, "PEIM", NULL, 0);\r
374\r
a3a15d21 375 } else {\r
376 //\r
377 // If PeiLoadImage fails, the section extraction PPI or Decompress PPI may not be ready,\r
378 // we flag that more Peims need to be dispatched.\r
379 //\r
380 PeimNeedingDispatch = TRUE;\r
b0d803fe 381 }\r
192f6d4c 382\r
b0d803fe 383 //\r
384 // Process the Notify list and dispatch any notifies for\r
385 // newly installed PPIs.\r
386 //\r
387 ProcessNotifyList (Private);\r
388\r
389 //\r
390 // If permanent memory was discovered and installed by this\r
391 // PEIM, shadow PEI Core and switch the stacks to the new memory. \r
392 //\r
393 if (Private->SwitchStackSignal) {\r
192f6d4c 394\r
395 //\r
b0d803fe 396 // Make sure we don't retry the same PEIM that added memory\r
192f6d4c 397 //\r
b0d803fe 398 Private->CurrentPeimCount++;\r
192f6d4c 399\r
400 //\r
b0d803fe 401 // Migrate IDT from CAR into real memory, so after stack switches to\r
402 // the new memory, the caller can get memory version PeiServiceTable. \r
192f6d4c 403 //\r
81c7803c 404 MigrateIdtTable (PeiServices);\r
405\r
b0d803fe 406 //\r
407 // Since we are at dispatch level, only the Core's private data \r
408 // is preserved, nobody else should have any data on the stack. \r
409 // So we need to copy PEI core instance data to memory.\r
410 //\r
411 PrivateInMem = AllocateCopyPool (sizeof (PEI_CORE_INSTANCE), Private);\r
412 ASSERT (PrivateInMem != NULL);\r
192f6d4c 413\r
414 //\r
b0d803fe 415 // Shadow PEI Core. When permanent memory is avaiable, shadow\r
416 // PEI Core and PEIMs to get high performance.\r
192f6d4c 417 //\r
b0d803fe 418 PeiCoreFileHandle = NULL;\r
419 //\r
420 // Find the PEI Core in the BFV\r
421 //\r
422 Status = PeiFindFileEx (\r
423 (EFI_PEI_FV_HANDLE)Private->Fv[0].FvHeader, \r
424 NULL, \r
425 EFI_FV_FILETYPE_PEI_CORE, \r
426 &PeiCoreFileHandle,\r
427 NULL\r
428 );\r
429 ASSERT_EFI_ERROR (Status);\r
430 \r
431 //\r
432 // Shadow PEI Core into memory so it will run faster\r
433 //\r
434 Status = PeiLoadImage (PeiServices, PeiCoreFileHandle, &EntryPoint, &AuthenticationState);\r
435 ASSERT_EFI_ERROR (Status);\r
436 \r
437 //\r
438 // Switch to memory based stack and reenter PEI Core that has been\r
439 // shadowed to memory.\r
440 //\r
441 //\r
442 // Adjust the top of stack to be aligned at CPU_STACK_ALIGNMENT\r
443 //\r
444 TopOfStack = (VOID *)((UINTN)Private->StackBase + (UINTN)Private->StackSize - CPU_STACK_ALIGNMENT);\r
445 TopOfStack = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);\r
446 \r
447 PeiCoreParameters.SecCoreData = SecCoreData;\r
448 PeiCoreParameters.PpiList = NULL;\r
449 PeiCoreParameters.Data = PrivateInMem;\r
450 ASSERT (PeiCoreParameters.Data != 0);\r
451\r
452 PeiSwitchStacks (\r
453 InvokePeiCore,\r
e83327a8 454 (VOID*) ((UINTN) EntryPoint + ((UINTN) PeiCore - (UINTN) _ModuleEntryPoint)),\r
b0d803fe 455 (VOID*) &PeiCoreParameters, \r
456 TopOfStack,\r
457 (VOID*)(UINTN)Private->StackBase\r
458 );\r
192f6d4c 459 }\r
192f6d4c 460\r
b0d803fe 461 if ((Private->PeiMemoryInstalled) && (Private->Fv[FvCount].PeimState[PeimCount] == PEIM_STATE_REGISITER_FOR_SHADOW) && \\r
462 (Private->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME)) {\r
463 //\r
464 // If memory is availble we shadow images by default for performance reasons. \r
465 // We call the entry point a 2nd time so the module knows it's shadowed. \r
466 //\r
467 //PERF_START (PeiServices, L"PEIM", PeimFileHandle, 0);\r
468 PeimEntryPoint (PeimFileHandle, PeiServices);\r
469 //PERF_END (PeiServices, L"PEIM", PeimFileHandle, 0);\r
470 \r
471 //\r
472 // PEIM_STATE_REGISITER_FOR_SHADOW move to PEIM_STATE_DONE\r
473 //\r
474 Private->Fv[FvCount].PeimState[PeimCount]++;\r
192f6d4c 475\r
192f6d4c 476 //\r
b0d803fe 477 // Process the Notify list and dispatch any notifies for\r
478 // newly installed PPIs.\r
192f6d4c 479 //\r
b0d803fe 480 ProcessNotifyList (Private);\r
192f6d4c 481 }\r
482 }\r
483 }\r
192f6d4c 484 }\r
192f6d4c 485\r
b0d803fe 486 //\r
487 // We set to NULL here to optimize the 2nd entry to this routine after\r
488 // memory is found. This reprevents rescanning of the FV. We set to\r
489 // NULL here so we start at the begining of the next FV\r
490 //\r
491 Private->CurrentFileHandle = NULL;\r
492 Private->CurrentPeimCount = 0;\r
493 //\r
494 // Before walking through the next FV,Private->CurrentFvFileHandles[]should set to NULL\r
495 //\r
496 SetMem (Private->CurrentFvFileHandles, sizeof (Private->CurrentFvFileHandles), 0);\r
192f6d4c 497 }\r
498\r
499 //\r
b0d803fe 500 // Before making another pass, we should set Private->CurrentPeimFvCount =0 to go \r
501 // through all the FV.\r
192f6d4c 502 //\r
b0d803fe 503 Private->CurrentPeimFvCount = 0;\r
192f6d4c 504\r
505 //\r
b0d803fe 506 // PeimNeedingDispatch being TRUE means we found a PEIM that did not get \r
507 // dispatched. So we need to make another pass\r
192f6d4c 508 //\r
b0d803fe 509 // PeimDispatchOnThisPass being TRUE means we dispatched a PEIM on this \r
510 // pass. If we did not dispatch a PEIM there is no point in trying again\r
511 // as it will fail the next time too (nothing has changed).\r
192f6d4c 512 //\r
b0d803fe 513 } while (PeimNeedingDispatch && PeimDispatchOnThisPass);\r
192f6d4c 514\r
192f6d4c 515}\r
516\r
517VOID\r
518InitializeDispatcherData (\r
b0d803fe 519 IN PEI_CORE_INSTANCE *PrivateData,\r
192f6d4c 520 IN PEI_CORE_INSTANCE *OldCoreData,\r
5aae0aa7 521 IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData\r
192f6d4c 522 )\r
523/*++\r
524\r
525Routine Description:\r
526\r
527 Initialize the Dispatcher's data members\r
528\r
529Arguments:\r
530\r
531 PeiServices - The PEI core services table.\r
532 OldCoreData - Pointer to old core data (before switching stack).\r
533 NULL if being run in non-permament memory mode.\r
5aae0aa7 534 SecCoreData - Points to a data structure containing information about the PEI core's operating\r
535 environment, such as the size and location of temporary RAM, the stack location and\r
536 the BFV location.\r
192f6d4c 537\r
538Returns:\r
539\r
540 None.\r
541\r
542--*/\r
543{\r
192f6d4c 544 if (OldCoreData == NULL) {\r
b0d803fe 545 PeiInitializeFv (PrivateData, SecCoreData);\r
192f6d4c 546 }\r
547\r
548 return;\r
549}\r
550\r
551\r
192f6d4c 552BOOLEAN\r
553DepexSatisfied (\r
b0d803fe 554 IN PEI_CORE_INSTANCE *Private,\r
555 IN EFI_PEI_FILE_HANDLE FileHandle,\r
556 IN UINTN PeimCount\r
192f6d4c 557 )\r
558/*++\r
559\r
560Routine Description:\r
561\r
562 This routine parses the Dependency Expression, if available, and\r
563 decides if the module can be executed.\r
564\r
565Arguments:\r
566 PeiServices - The PEI Service Table\r
567 CurrentPeimAddress - Address of the PEIM Firmware File under investigation\r
568\r
569Returns:\r
570 TRUE - Can be dispatched\r
571 FALSE - Cannot be dispatched\r
572\r
573--*/\r
574{\r
575 EFI_STATUS Status;\r
b0d803fe 576 VOID *DepexData;\r
577\r
578 if (PeimCount < Private->AprioriCount) {\r
579 //\r
580 // If its in the A priori file then we set Depex to TRUE\r
581 //\r
582 return TRUE;\r
583 }\r
584\r
585 Status = PeiServicesFfsFindSectionData (EFI_SECTION_PEI_DEPEX, FileHandle, (VOID **) &DepexData);\r
192f6d4c 586 if (EFI_ERROR (Status)) {\r
b0d803fe 587 //\r
588 // If there is no DEPEX, assume the module can be executed\r
589 //\r
192f6d4c 590 return TRUE;\r
591 }\r
592\r
593 //\r
594 // Evaluate a given DEPEX\r
595 //\r
b0d803fe 596 return PeimDispatchReadiness (&Private->PS, DepexData);\r
192f6d4c 597}\r
598\r
14e8823a 599/**\r
600 This routine enable a PEIM to register itself to shadow when PEI Foundation\r
601 discovery permanent memory.\r
602\r
603 @param FileHandle File handle of a PEIM.\r
604 \r
605 @retval EFI_NOT_FOUND The file handle doesn't point to PEIM itself.\r
606 @retval EFI_ALREADY_STARTED Indicate that the PEIM has been registered itself.\r
607 @retval EFI_SUCCESS Successfully to register itself.\r
608\r
609**/ \r
610EFI_STATUS\r
611EFIAPI\r
612PeiRegisterForShadow (\r
613 IN EFI_PEI_FILE_HANDLE FileHandle\r
614 )\r
615{\r
616 PEI_CORE_INSTANCE *Private;\r
617 Private = PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer ());\r
618\r
619 if (Private->CurrentFileHandle != FileHandle) {\r
620 //\r
621 // The FileHandle must be for the current PEIM\r
622 //\r
623 return EFI_NOT_FOUND;\r
624 }\r
625\r
626 if (Private->Fv[Private->CurrentPeimFvCount].PeimState[Private->CurrentPeimCount] >= PEIM_STATE_REGISITER_FOR_SHADOW) {\r
627 //\r
628 // If the PEIM has already entered the PEIM_STATE_REGISTER_FOR_SHADOW or PEIM_STATE_DONE then it's already been started\r
629 //\r
630 return EFI_ALREADY_STARTED;\r
631 }\r
632 \r
633 Private->Fv[Private->CurrentPeimFvCount].PeimState[Private->CurrentPeimCount] = PEIM_STATE_REGISITER_FOR_SHADOW;\r
634\r
635 return EFI_SUCCESS;\r
636}\r
637\r
b0d803fe 638\r
b98c2ab7 639/**\r
640 This routine invoke the PeiCore's entry in new stack environment.\r
641\r
642 @param Context1 The first context parameter is entry of PeiCore\r
643 @param Context2 The second context parameter is parameter structure point for PeiCore\r
644\r
645**/ \r
646STATIC\r
647VOID\r
648InvokePeiCore (\r
649 VOID *Context1,\r
650 VOID *Context2\r
651 )\r
652{\r
653 PEI_CORE_ENTRY_POINT PeiCoreEntryPoint;\r
654 PEI_CORE_PARAMETERS *PeiCoreParameters;\r
655\r
656 //\r
657 // Running on new stack in SEC Core\r
658 //\r
659\r
660 PeiCoreEntryPoint = (PEI_CORE_ENTRY_POINT) (UINTN) Context1;\r
661 PeiCoreParameters = (PEI_CORE_PARAMETERS *)Context2;\r
662\r
663 //\r
664 // Call PEI Core using new stack\r
665 //\r
666 PeiCoreEntryPoint (\r
667 PeiCoreParameters->SecCoreData,\r
668 PeiCoreParameters->PpiList,\r
669 PeiCoreParameters->Data\r
670 );\r
671\r
672 //\r
673 // Never returns\r
674 //\r
096cdcaa 675 ASSERT (FALSE);\r
676 CpuDeadLoop ();\r
b98c2ab7 677}\r