]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@4185 6f19259b...
[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
375 }\r
192f6d4c 376\r
b0d803fe 377 //\r
378 // Process the Notify list and dispatch any notifies for\r
379 // newly installed PPIs.\r
380 //\r
381 ProcessNotifyList (Private);\r
382\r
383 //\r
384 // If permanent memory was discovered and installed by this\r
385 // PEIM, shadow PEI Core and switch the stacks to the new memory. \r
386 //\r
387 if (Private->SwitchStackSignal) {\r
192f6d4c 388\r
389 //\r
b0d803fe 390 // Make sure we don't retry the same PEIM that added memory\r
192f6d4c 391 //\r
b0d803fe 392 Private->CurrentPeimCount++;\r
192f6d4c 393\r
394 //\r
b0d803fe 395 // Migrate IDT from CAR into real memory, so after stack switches to\r
396 // the new memory, the caller can get memory version PeiServiceTable. \r
192f6d4c 397 //\r
81c7803c 398 MigrateIdtTable (PeiServices);\r
399\r
b0d803fe 400 //\r
401 // Since we are at dispatch level, only the Core's private data \r
402 // is preserved, nobody else should have any data on the stack. \r
403 // So we need to copy PEI core instance data to memory.\r
404 //\r
405 PrivateInMem = AllocateCopyPool (sizeof (PEI_CORE_INSTANCE), Private);\r
406 ASSERT (PrivateInMem != NULL);\r
192f6d4c 407\r
408 //\r
b0d803fe 409 // Shadow PEI Core. When permanent memory is avaiable, shadow\r
410 // PEI Core and PEIMs to get high performance.\r
192f6d4c 411 //\r
b0d803fe 412 PeiCoreFileHandle = NULL;\r
413 //\r
414 // Find the PEI Core in the BFV\r
415 //\r
416 Status = PeiFindFileEx (\r
417 (EFI_PEI_FV_HANDLE)Private->Fv[0].FvHeader, \r
418 NULL, \r
419 EFI_FV_FILETYPE_PEI_CORE, \r
420 &PeiCoreFileHandle,\r
421 NULL\r
422 );\r
423 ASSERT_EFI_ERROR (Status);\r
424 \r
425 //\r
426 // Shadow PEI Core into memory so it will run faster\r
427 //\r
428 Status = PeiLoadImage (PeiServices, PeiCoreFileHandle, &EntryPoint, &AuthenticationState);\r
429 ASSERT_EFI_ERROR (Status);\r
430 \r
431 //\r
432 // Switch to memory based stack and reenter PEI Core that has been\r
433 // shadowed to memory.\r
434 //\r
435 //\r
436 // Adjust the top of stack to be aligned at CPU_STACK_ALIGNMENT\r
437 //\r
438 TopOfStack = (VOID *)((UINTN)Private->StackBase + (UINTN)Private->StackSize - CPU_STACK_ALIGNMENT);\r
439 TopOfStack = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);\r
440 \r
441 PeiCoreParameters.SecCoreData = SecCoreData;\r
442 PeiCoreParameters.PpiList = NULL;\r
443 PeiCoreParameters.Data = PrivateInMem;\r
444 ASSERT (PeiCoreParameters.Data != 0);\r
445\r
446 PeiSwitchStacks (\r
447 InvokePeiCore,\r
448 (VOID*) (UINTN) PeiCore,\r
449 (VOID*) &PeiCoreParameters, \r
450 TopOfStack,\r
451 (VOID*)(UINTN)Private->StackBase\r
452 );\r
192f6d4c 453 }\r
192f6d4c 454\r
b0d803fe 455 if ((Private->PeiMemoryInstalled) && (Private->Fv[FvCount].PeimState[PeimCount] == PEIM_STATE_REGISITER_FOR_SHADOW) && \\r
456 (Private->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME)) {\r
457 //\r
458 // If memory is availble we shadow images by default for performance reasons. \r
459 // We call the entry point a 2nd time so the module knows it's shadowed. \r
460 //\r
461 //PERF_START (PeiServices, L"PEIM", PeimFileHandle, 0);\r
462 PeimEntryPoint (PeimFileHandle, PeiServices);\r
463 //PERF_END (PeiServices, L"PEIM", PeimFileHandle, 0);\r
464 \r
465 //\r
466 // PEIM_STATE_REGISITER_FOR_SHADOW move to PEIM_STATE_DONE\r
467 //\r
468 Private->Fv[FvCount].PeimState[PeimCount]++;\r
192f6d4c 469\r
192f6d4c 470 //\r
b0d803fe 471 // Process the Notify list and dispatch any notifies for\r
472 // newly installed PPIs.\r
192f6d4c 473 //\r
b0d803fe 474 ProcessNotifyList (Private);\r
192f6d4c 475 }\r
476 }\r
477 }\r
192f6d4c 478 }\r
192f6d4c 479\r
b0d803fe 480 //\r
481 // We set to NULL here to optimize the 2nd entry to this routine after\r
482 // memory is found. This reprevents rescanning of the FV. We set to\r
483 // NULL here so we start at the begining of the next FV\r
484 //\r
485 Private->CurrentFileHandle = NULL;\r
486 Private->CurrentPeimCount = 0;\r
487 //\r
488 // Before walking through the next FV,Private->CurrentFvFileHandles[]should set to NULL\r
489 //\r
490 SetMem (Private->CurrentFvFileHandles, sizeof (Private->CurrentFvFileHandles), 0);\r
192f6d4c 491 }\r
492\r
493 //\r
b0d803fe 494 // Before making another pass, we should set Private->CurrentPeimFvCount =0 to go \r
495 // through all the FV.\r
192f6d4c 496 //\r
b0d803fe 497 Private->CurrentPeimFvCount = 0;\r
192f6d4c 498\r
499 //\r
b0d803fe 500 // PeimNeedingDispatch being TRUE means we found a PEIM that did not get \r
501 // dispatched. So we need to make another pass\r
192f6d4c 502 //\r
b0d803fe 503 // PeimDispatchOnThisPass being TRUE means we dispatched a PEIM on this \r
504 // pass. If we did not dispatch a PEIM there is no point in trying again\r
505 // as it will fail the next time too (nothing has changed).\r
192f6d4c 506 //\r
b0d803fe 507 } while (PeimNeedingDispatch && PeimDispatchOnThisPass);\r
192f6d4c 508\r
192f6d4c 509}\r
510\r
511VOID\r
512InitializeDispatcherData (\r
b0d803fe 513 IN PEI_CORE_INSTANCE *PrivateData,\r
192f6d4c 514 IN PEI_CORE_INSTANCE *OldCoreData,\r
5aae0aa7 515 IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData\r
192f6d4c 516 )\r
517/*++\r
518\r
519Routine Description:\r
520\r
521 Initialize the Dispatcher's data members\r
522\r
523Arguments:\r
524\r
525 PeiServices - The PEI core services table.\r
526 OldCoreData - Pointer to old core data (before switching stack).\r
527 NULL if being run in non-permament memory mode.\r
5aae0aa7 528 SecCoreData - Points to a data structure containing information about the PEI core's operating\r
529 environment, such as the size and location of temporary RAM, the stack location and\r
530 the BFV location.\r
192f6d4c 531\r
532Returns:\r
533\r
534 None.\r
535\r
536--*/\r
537{\r
192f6d4c 538 if (OldCoreData == NULL) {\r
b0d803fe 539 PeiInitializeFv (PrivateData, SecCoreData);\r
192f6d4c 540 }\r
541\r
542 return;\r
543}\r
544\r
545\r
192f6d4c 546BOOLEAN\r
547DepexSatisfied (\r
b0d803fe 548 IN PEI_CORE_INSTANCE *Private,\r
549 IN EFI_PEI_FILE_HANDLE FileHandle,\r
550 IN UINTN PeimCount\r
192f6d4c 551 )\r
552/*++\r
553\r
554Routine Description:\r
555\r
556 This routine parses the Dependency Expression, if available, and\r
557 decides if the module can be executed.\r
558\r
559Arguments:\r
560 PeiServices - The PEI Service Table\r
561 CurrentPeimAddress - Address of the PEIM Firmware File under investigation\r
562\r
563Returns:\r
564 TRUE - Can be dispatched\r
565 FALSE - Cannot be dispatched\r
566\r
567--*/\r
568{\r
569 EFI_STATUS Status;\r
b0d803fe 570 VOID *DepexData;\r
571\r
572 if (PeimCount < Private->AprioriCount) {\r
573 //\r
574 // If its in the A priori file then we set Depex to TRUE\r
575 //\r
576 return TRUE;\r
577 }\r
578\r
579 Status = PeiServicesFfsFindSectionData (EFI_SECTION_PEI_DEPEX, FileHandle, (VOID **) &DepexData);\r
192f6d4c 580 if (EFI_ERROR (Status)) {\r
b0d803fe 581 //\r
582 // If there is no DEPEX, assume the module can be executed\r
583 //\r
192f6d4c 584 return TRUE;\r
585 }\r
586\r
587 //\r
588 // Evaluate a given DEPEX\r
589 //\r
b0d803fe 590 return PeimDispatchReadiness (&Private->PS, DepexData);\r
192f6d4c 591}\r
592\r
14e8823a 593/**\r
594 This routine enable a PEIM to register itself to shadow when PEI Foundation\r
595 discovery permanent memory.\r
596\r
597 @param FileHandle File handle of a PEIM.\r
598 \r
599 @retval EFI_NOT_FOUND The file handle doesn't point to PEIM itself.\r
600 @retval EFI_ALREADY_STARTED Indicate that the PEIM has been registered itself.\r
601 @retval EFI_SUCCESS Successfully to register itself.\r
602\r
603**/ \r
604EFI_STATUS\r
605EFIAPI\r
606PeiRegisterForShadow (\r
607 IN EFI_PEI_FILE_HANDLE FileHandle\r
608 )\r
609{\r
610 PEI_CORE_INSTANCE *Private;\r
611 Private = PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer ());\r
612\r
613 if (Private->CurrentFileHandle != FileHandle) {\r
614 //\r
615 // The FileHandle must be for the current PEIM\r
616 //\r
617 return EFI_NOT_FOUND;\r
618 }\r
619\r
620 if (Private->Fv[Private->CurrentPeimFvCount].PeimState[Private->CurrentPeimCount] >= PEIM_STATE_REGISITER_FOR_SHADOW) {\r
621 //\r
622 // If the PEIM has already entered the PEIM_STATE_REGISTER_FOR_SHADOW or PEIM_STATE_DONE then it's already been started\r
623 //\r
624 return EFI_ALREADY_STARTED;\r
625 }\r
626 \r
627 Private->Fv[Private->CurrentPeimFvCount].PeimState[Private->CurrentPeimCount] = PEIM_STATE_REGISITER_FOR_SHADOW;\r
628\r
629 return EFI_SUCCESS;\r
630}\r
631\r
b0d803fe 632\r
b98c2ab7 633/**\r
634 This routine invoke the PeiCore's entry in new stack environment.\r
635\r
636 @param Context1 The first context parameter is entry of PeiCore\r
637 @param Context2 The second context parameter is parameter structure point for PeiCore\r
638\r
639**/ \r
640STATIC\r
641VOID\r
642InvokePeiCore (\r
643 VOID *Context1,\r
644 VOID *Context2\r
645 )\r
646{\r
647 PEI_CORE_ENTRY_POINT PeiCoreEntryPoint;\r
648 PEI_CORE_PARAMETERS *PeiCoreParameters;\r
649\r
650 //\r
651 // Running on new stack in SEC Core\r
652 //\r
653\r
654 PeiCoreEntryPoint = (PEI_CORE_ENTRY_POINT) (UINTN) Context1;\r
655 PeiCoreParameters = (PEI_CORE_PARAMETERS *)Context2;\r
656\r
657 //\r
658 // Call PEI Core using new stack\r
659 //\r
660 PeiCoreEntryPoint (\r
661 PeiCoreParameters->SecCoreData,\r
662 PeiCoreParameters->PpiList,\r
663 PeiCoreParameters->Data\r
664 );\r
665\r
666 //\r
667 // Never returns\r
668 //\r
669 ASSERT_EFI_ERROR (FALSE);\r
670}\r