]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c
Fix the cast issue
[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
58 EFI_PEI_FV_HANDLE AprioriFileHandle;\r
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
65 EFI_PEI_FV_HANDLE TempFileHandles[PEI_CORE_MAX_PEIM_PER_FV];\r
66 EFI_GUID FileGuid[PEI_CORE_MAX_PEIM_PER_FV];\r
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
87 for (PeimCount = 0; PeimCount < PEI_CORE_MAX_PEIM_PER_FV; PeimCount++) {\r
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
107 Status = PeiServicesFfsFindSectionData (EFI_SECTION_RAW, &AprioriFileHandle, (VOID **) &Apriori);\r
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
231 EFI_PEI_FILE_HANDLE SaveCurrentFileHandle;\r
232 VOID *TopOfStack;\r
233 PEI_CORE_PARAMETERS PeiCoreParameters;\r
234 EFI_DEVICE_HANDLE_EXTENDED_DATA ExtendedData;\r
235\r
236\r
237 PeiServices = &Private->PS;\r
238 PeimEntryPoint = NULL;\r
239 PeimFileHandle = NULL;\r
240\r
241 if ((Private->PeiMemoryInstalled) && (Private->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME)) {\r
242 //\r
243 // Once real memory is available, shadow the RegisterForShadow modules. And meanwhile\r
244 // update the modules' status from PEIM_STATE_REGISITER_FOR_SHADOW to PEIM_STATE_DONE.\r
245 //\r
246 SaveCurrentPeimCount = Private->CurrentPeimCount;\r
247 SaveCurrentFileHandle = Private->CurrentFileHandle;\r
248\r
249 for (Index1 = 0;Index1 <= Private->CurrentPeimFvCount; Index1++) {\r
250 for (Index2 = 0; (Index2 < PEI_CORE_MAX_PEIM_PER_FV) && (Private->Fv[Index1].FvFileHandles[Index2] != NULL); Index2++) {\r
251 if (Private->Fv[Index1].PeimState[Index2] == PEIM_STATE_REGISITER_FOR_SHADOW) {\r
252 PeimFileHandle = Private->Fv[Index1].FvFileHandles[Index2]; \r
253 Status = PeiLoadImage (\r
254 &Private->PS, \r
255 PeimFileHandle, \r
256 &EntryPoint, \r
257 &AuthenticationState\r
258 );\r
259 if (Status == EFI_SUCCESS) {\r
260 //\r
261 // PEIM_STATE_REGISITER_FOR_SHADOW move to PEIM_STATE_DONE\r
262 //\r
263 Private->Fv[Index1].PeimState[Index2]++;\r
264 Private->CurrentFileHandle = PeimFileHandle;\r
265 Private->CurrentPeimCount = Index2; \r
266 //\r
267 // Call the PEIM entry point\r
268 //\r
269 PeimEntryPoint = (EFI_PEIM_ENTRY_POINT)(UINTN)EntryPoint;\r
270 \r
271 PERF_START (0, "PEIM", NULL, 0);\r
272 PeimEntryPoint(PeimFileHandle, &Private->PS);\r
273 PERF_END (0, "PEIM", NULL, 0);\r
274 } \r
275 \r
276 //\r
277 // Process the Notify list and dispatch any notifies for\r
278 // newly installed PPIs.\r
279 //\r
280 ProcessNotifyList (Private);\r
281 }\r
282 }\r
283 }\r
284 Private->CurrentFileHandle = SaveCurrentFileHandle; \r
285 Private->CurrentPeimCount = SaveCurrentPeimCount; \r
286 }\r
192f6d4c 287\r
288 //\r
289 // This is the main dispatch loop. It will search known FVs for PEIMs and\r
290 // attempt to dispatch them. If any PEIM gets dispatched through a single\r
291 // pass of the dispatcher, it will start over from the Bfv again to see\r
292 // if any new PEIMs dependencies got satisfied. With a well ordered\r
293 // FV where PEIMs are found in the order their dependencies are also\r
294 // satisfied, this dipatcher should run only once.\r
295 //\r
b0d803fe 296 do {\r
297 PeimNeedingDispatch = FALSE;\r
298 PeimDispatchOnThisPass = FALSE;\r
299\r
300 for (FvCount = Private->CurrentPeimFvCount; FvCount < Private->FvCount; FvCount++) {\r
301 Private->CurrentPeimFvCount = FvCount;\r
302 VolumeHandle = Private->Fv[FvCount].FvHeader;\r
192f6d4c 303\r
b0d803fe 304 if (Private->CurrentPeimCount == 0) {\r
305 //\r
306 // When going through each FV, at first, search Apriori file to\r
307 // reorder all PEIMs to ensure the PEIMs in Apriori file to get \r
308 // dispatch at first.\r
309 //\r
310 DiscoverPeimsAndOrderWithApriori (Private, VolumeHandle);\r
311 }\r
192f6d4c 312\r
313 //\r
b0d803fe 314 // Start to dispatch all modules within the current Fv.\r
192f6d4c 315 //\r
b0d803fe 316 for (PeimCount = Private->CurrentPeimCount; \r
317 (PeimCount < PEI_CORE_MAX_PEIM_PER_FV) && (Private->CurrentFvFileHandles[PeimCount] != NULL); \r
318 PeimCount++) {\r
319 Private->CurrentPeimCount = PeimCount;\r
320 PeimFileHandle = Private->CurrentFileHandle = Private->CurrentFvFileHandles[PeimCount];\r
321\r
322 if (Private->Fv[FvCount].PeimState[PeimCount] == PEIM_STATE_NOT_DISPATCHED) {\r
323 if (!DepexSatisfied (Private, PeimFileHandle, PeimCount)) {\r
324 PeimNeedingDispatch = TRUE;\r
325 } else {\r
192f6d4c 326 Status = PeiLoadImage (\r
b0d803fe 327 PeiServices, \r
328 PeimFileHandle, \r
329 &EntryPoint, \r
330 &AuthenticationState\r
192f6d4c 331 );\r
b0d803fe 332 if ((Status == EFI_SUCCESS)) {\r
192f6d4c 333 //\r
334 // The PEIM has its dependencies satisfied, and its entry point\r
335 // has been found, so invoke it.\r
336 //\r
b0d803fe 337 PERF_START (0, "PEIM", NULL, 0);\r
192f6d4c 338\r
b0d803fe 339 ExtendedData.Handle = (EFI_HANDLE)PeimFileHandle;\r
192f6d4c 340\r
341 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (\r
342 EFI_PROGRESS_CODE,\r
343 EFI_SOFTWARE_PEI_CORE | EFI_SW_PC_INIT_BEGIN,\r
344 (VOID *)(&ExtendedData),\r
345 sizeof (ExtendedData)\r
346 );\r
347\r
b0d803fe 348 Status = VerifyPeim (Private, VolumeHandle, PeimFileHandle);\r
349 if (Status != EFI_SECURITY_VIOLATION && (AuthenticationState == 0)) {\r
350 //\r
351 // PEIM_STATE_NOT_DISPATCHED move to PEIM_STATE_DISPATCHED\r
352 //\r
353 Private->Fv[FvCount].PeimState[PeimCount]++;\r
192f6d4c 354\r
355 //\r
b0d803fe 356 // Call the PEIM entry point\r
192f6d4c 357 //\r
b0d803fe 358 PeimEntryPoint = (EFI_PEIM_ENTRY_POINT)(UINTN)EntryPoint;\r
359 PeimEntryPoint (PeimFileHandle, PeiServices);\r
360 PeimDispatchOnThisPass = TRUE;\r
192f6d4c 361 }\r
362\r
363 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (\r
364 EFI_PROGRESS_CODE,\r
365 EFI_SOFTWARE_PEI_CORE | EFI_SW_PC_INIT_END,\r
366 (VOID *)(&ExtendedData),\r
367 sizeof (ExtendedData)\r
368 );\r
b0d803fe 369 PERF_END (0, "PEIM", NULL, 0);\r
370\r
371 }\r
192f6d4c 372\r
b0d803fe 373 //\r
374 // Process the Notify list and dispatch any notifies for\r
375 // newly installed PPIs.\r
376 //\r
377 ProcessNotifyList (Private);\r
378\r
379 //\r
380 // If permanent memory was discovered and installed by this\r
381 // PEIM, shadow PEI Core and switch the stacks to the new memory. \r
382 //\r
383 if (Private->SwitchStackSignal) {\r
192f6d4c 384\r
385 //\r
b0d803fe 386 // Make sure we don't retry the same PEIM that added memory\r
192f6d4c 387 //\r
b0d803fe 388 Private->CurrentPeimCount++;\r
192f6d4c 389\r
390 //\r
b0d803fe 391 // Migrate IDT from CAR into real memory, so after stack switches to\r
392 // the new memory, the caller can get memory version PeiServiceTable. \r
192f6d4c 393 //\r
b0d803fe 394 //MigrateIdtTable (PeiServices); \r
395 //\r
396 // Since we are at dispatch level, only the Core's private data \r
397 // is preserved, nobody else should have any data on the stack. \r
398 // So we need to copy PEI core instance data to memory.\r
399 //\r
400 PrivateInMem = AllocateCopyPool (sizeof (PEI_CORE_INSTANCE), Private);\r
401 ASSERT (PrivateInMem != NULL);\r
192f6d4c 402\r
403 //\r
b0d803fe 404 // Shadow PEI Core. When permanent memory is avaiable, shadow\r
405 // PEI Core and PEIMs to get high performance.\r
192f6d4c 406 //\r
b0d803fe 407 PeiCoreFileHandle = NULL;\r
408 //\r
409 // Find the PEI Core in the BFV\r
410 //\r
411 Status = PeiFindFileEx (\r
412 (EFI_PEI_FV_HANDLE)Private->Fv[0].FvHeader, \r
413 NULL, \r
414 EFI_FV_FILETYPE_PEI_CORE, \r
415 &PeiCoreFileHandle,\r
416 NULL\r
417 );\r
418 ASSERT_EFI_ERROR (Status);\r
419 \r
420 //\r
421 // Shadow PEI Core into memory so it will run faster\r
422 //\r
423 Status = PeiLoadImage (PeiServices, PeiCoreFileHandle, &EntryPoint, &AuthenticationState);\r
424 ASSERT_EFI_ERROR (Status);\r
425 \r
426 //\r
427 // Switch to memory based stack and reenter PEI Core that has been\r
428 // shadowed to memory.\r
429 //\r
430 //\r
431 // Adjust the top of stack to be aligned at CPU_STACK_ALIGNMENT\r
432 //\r
433 TopOfStack = (VOID *)((UINTN)Private->StackBase + (UINTN)Private->StackSize - CPU_STACK_ALIGNMENT);\r
434 TopOfStack = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);\r
435 \r
436 PeiCoreParameters.SecCoreData = SecCoreData;\r
437 PeiCoreParameters.PpiList = NULL;\r
438 PeiCoreParameters.Data = PrivateInMem;\r
439 ASSERT (PeiCoreParameters.Data != 0);\r
440\r
441 PeiSwitchStacks (\r
442 InvokePeiCore,\r
443 (VOID*) (UINTN) PeiCore,\r
444 (VOID*) &PeiCoreParameters, \r
445 TopOfStack,\r
446 (VOID*)(UINTN)Private->StackBase\r
447 );\r
192f6d4c 448 }\r
192f6d4c 449\r
b0d803fe 450 if ((Private->PeiMemoryInstalled) && (Private->Fv[FvCount].PeimState[PeimCount] == PEIM_STATE_REGISITER_FOR_SHADOW) && \\r
451 (Private->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME)) {\r
452 //\r
453 // If memory is availble we shadow images by default for performance reasons. \r
454 // We call the entry point a 2nd time so the module knows it's shadowed. \r
455 //\r
456 //PERF_START (PeiServices, L"PEIM", PeimFileHandle, 0);\r
457 PeimEntryPoint (PeimFileHandle, PeiServices);\r
458 //PERF_END (PeiServices, L"PEIM", PeimFileHandle, 0);\r
459 \r
460 //\r
461 // PEIM_STATE_REGISITER_FOR_SHADOW move to PEIM_STATE_DONE\r
462 //\r
463 Private->Fv[FvCount].PeimState[PeimCount]++;\r
192f6d4c 464\r
192f6d4c 465 //\r
b0d803fe 466 // Process the Notify list and dispatch any notifies for\r
467 // newly installed PPIs.\r
192f6d4c 468 //\r
b0d803fe 469 ProcessNotifyList (Private);\r
192f6d4c 470 }\r
471 }\r
472 }\r
192f6d4c 473 }\r
192f6d4c 474\r
b0d803fe 475 //\r
476 // We set to NULL here to optimize the 2nd entry to this routine after\r
477 // memory is found. This reprevents rescanning of the FV. We set to\r
478 // NULL here so we start at the begining of the next FV\r
479 //\r
480 Private->CurrentFileHandle = NULL;\r
481 Private->CurrentPeimCount = 0;\r
482 //\r
483 // Before walking through the next FV,Private->CurrentFvFileHandles[]should set to NULL\r
484 //\r
485 SetMem (Private->CurrentFvFileHandles, sizeof (Private->CurrentFvFileHandles), 0);\r
192f6d4c 486 }\r
487\r
488 //\r
b0d803fe 489 // Before making another pass, we should set Private->CurrentPeimFvCount =0 to go \r
490 // through all the FV.\r
192f6d4c 491 //\r
b0d803fe 492 Private->CurrentPeimFvCount = 0;\r
192f6d4c 493\r
494 //\r
b0d803fe 495 // PeimNeedingDispatch being TRUE means we found a PEIM that did not get \r
496 // dispatched. So we need to make another pass\r
192f6d4c 497 //\r
b0d803fe 498 // PeimDispatchOnThisPass being TRUE means we dispatched a PEIM on this \r
499 // pass. If we did not dispatch a PEIM there is no point in trying again\r
500 // as it will fail the next time too (nothing has changed).\r
192f6d4c 501 //\r
b0d803fe 502 } while (PeimNeedingDispatch && PeimDispatchOnThisPass);\r
192f6d4c 503\r
192f6d4c 504}\r
505\r
506VOID\r
507InitializeDispatcherData (\r
b0d803fe 508 IN PEI_CORE_INSTANCE *PrivateData,\r
192f6d4c 509 IN PEI_CORE_INSTANCE *OldCoreData,\r
5aae0aa7 510 IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData\r
192f6d4c 511 )\r
512/*++\r
513\r
514Routine Description:\r
515\r
516 Initialize the Dispatcher's data members\r
517\r
518Arguments:\r
519\r
520 PeiServices - The PEI core services table.\r
521 OldCoreData - Pointer to old core data (before switching stack).\r
522 NULL if being run in non-permament memory mode.\r
5aae0aa7 523 SecCoreData - Points to a data structure containing information about the PEI core's operating\r
524 environment, such as the size and location of temporary RAM, the stack location and\r
525 the BFV location.\r
192f6d4c 526\r
527Returns:\r
528\r
529 None.\r
530\r
531--*/\r
532{\r
192f6d4c 533 if (OldCoreData == NULL) {\r
b0d803fe 534 PeiInitializeFv (PrivateData, SecCoreData);\r
192f6d4c 535 }\r
536\r
537 return;\r
538}\r
539\r
540\r
192f6d4c 541BOOLEAN\r
542DepexSatisfied (\r
b0d803fe 543 IN PEI_CORE_INSTANCE *Private,\r
544 IN EFI_PEI_FILE_HANDLE FileHandle,\r
545 IN UINTN PeimCount\r
192f6d4c 546 )\r
547/*++\r
548\r
549Routine Description:\r
550\r
551 This routine parses the Dependency Expression, if available, and\r
552 decides if the module can be executed.\r
553\r
554Arguments:\r
555 PeiServices - The PEI Service Table\r
556 CurrentPeimAddress - Address of the PEIM Firmware File under investigation\r
557\r
558Returns:\r
559 TRUE - Can be dispatched\r
560 FALSE - Cannot be dispatched\r
561\r
562--*/\r
563{\r
564 EFI_STATUS Status;\r
b0d803fe 565 VOID *DepexData;\r
566\r
567 if (PeimCount < Private->AprioriCount) {\r
568 //\r
569 // If its in the A priori file then we set Depex to TRUE\r
570 //\r
571 return TRUE;\r
572 }\r
573\r
574 Status = PeiServicesFfsFindSectionData (EFI_SECTION_PEI_DEPEX, FileHandle, (VOID **) &DepexData);\r
192f6d4c 575 if (EFI_ERROR (Status)) {\r
b0d803fe 576 //\r
577 // If there is no DEPEX, assume the module can be executed\r
578 //\r
192f6d4c 579 return TRUE;\r
580 }\r
581\r
582 //\r
583 // Evaluate a given DEPEX\r
584 //\r
b0d803fe 585 return PeimDispatchReadiness (&Private->PS, DepexData);\r
192f6d4c 586}\r
587\r
14e8823a 588/**\r
589 This routine enable a PEIM to register itself to shadow when PEI Foundation\r
590 discovery permanent memory.\r
591\r
592 @param FileHandle File handle of a PEIM.\r
593 \r
594 @retval EFI_NOT_FOUND The file handle doesn't point to PEIM itself.\r
595 @retval EFI_ALREADY_STARTED Indicate that the PEIM has been registered itself.\r
596 @retval EFI_SUCCESS Successfully to register itself.\r
597\r
598**/ \r
599EFI_STATUS\r
600EFIAPI\r
601PeiRegisterForShadow (\r
602 IN EFI_PEI_FILE_HANDLE FileHandle\r
603 )\r
604{\r
605 PEI_CORE_INSTANCE *Private;\r
606 Private = PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer ());\r
607\r
608 if (Private->CurrentFileHandle != FileHandle) {\r
609 //\r
610 // The FileHandle must be for the current PEIM\r
611 //\r
612 return EFI_NOT_FOUND;\r
613 }\r
614\r
615 if (Private->Fv[Private->CurrentPeimFvCount].PeimState[Private->CurrentPeimCount] >= PEIM_STATE_REGISITER_FOR_SHADOW) {\r
616 //\r
617 // If the PEIM has already entered the PEIM_STATE_REGISTER_FOR_SHADOW or PEIM_STATE_DONE then it's already been started\r
618 //\r
619 return EFI_ALREADY_STARTED;\r
620 }\r
621 \r
622 Private->Fv[Private->CurrentPeimFvCount].PeimState[Private->CurrentPeimCount] = PEIM_STATE_REGISITER_FOR_SHADOW;\r
623\r
624 return EFI_SUCCESS;\r
625}\r
626\r
b0d803fe 627\r
b98c2ab7 628/**\r
629 This routine invoke the PeiCore's entry in new stack environment.\r
630\r
631 @param Context1 The first context parameter is entry of PeiCore\r
632 @param Context2 The second context parameter is parameter structure point for PeiCore\r
633\r
634**/ \r
635STATIC\r
636VOID\r
637InvokePeiCore (\r
638 VOID *Context1,\r
639 VOID *Context2\r
640 )\r
641{\r
642 PEI_CORE_ENTRY_POINT PeiCoreEntryPoint;\r
643 PEI_CORE_PARAMETERS *PeiCoreParameters;\r
644\r
645 //\r
646 // Running on new stack in SEC Core\r
647 //\r
648\r
649 PeiCoreEntryPoint = (PEI_CORE_ENTRY_POINT) (UINTN) Context1;\r
650 PeiCoreParameters = (PEI_CORE_PARAMETERS *)Context2;\r
651\r
652 //\r
653 // Call PEI Core using new stack\r
654 //\r
655 PeiCoreEntryPoint (\r
656 PeiCoreParameters->SecCoreData,\r
657 PeiCoreParameters->PpiList,\r
658 PeiCoreParameters->Data\r
659 );\r
660\r
661 //\r
662 // Never returns\r
663 //\r
664 ASSERT_EFI_ERROR (FALSE);\r
665}\r