]>
Commit | Line | Data |
---|---|---|
1 | /*++\r | |
2 | \r | |
3 | Copyright (c) 2006, Intel Corporation\r | |
4 | All rights reserved. This program and the accompanying materials\r | |
5 | are licensed and made available under the terms and conditions of the BSD License\r | |
6 | which accompanies this distribution. The full text of the license may be found at\r | |
7 | http://opensource.org/licenses/bsd-license.php\r | |
8 | \r | |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
11 | \r | |
12 | Module Name:\r | |
13 | \r | |
14 | Dispatcher.c\r | |
15 | \r | |
16 | Abstract:\r | |
17 | \r | |
18 | EFI PEI Core dispatch services\r | |
19 | \r | |
20 | Revision History\r | |
21 | \r | |
22 | --*/\r | |
23 | \r | |
24 | #include <PeiMain.h>\r | |
25 | \r | |
26 | STATIC\r | |
27 | VOID *\r | |
28 | TransferOldDataToNewDataRange (\r | |
29 | IN PEI_CORE_INSTANCE *PrivateData\r | |
30 | );\r | |
31 | \r | |
32 | STATIC\r | |
33 | VOID\r | |
34 | InvokePeiCore (\r | |
35 | VOID *Context1,\r | |
36 | VOID *Context2\r | |
37 | );\r | |
38 | \r | |
39 | EFI_STATUS\r | |
40 | PeiDispatcher (\r | |
41 | IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData,\r | |
42 | IN PEI_CORE_INSTANCE *PrivateData,\r | |
43 | IN PEI_CORE_DISPATCH_DATA *DispatchData\r | |
44 | )\r | |
45 | \r | |
46 | /*++\r | |
47 | \r | |
48 | Routine Description:\r | |
49 | \r | |
50 | Conduct PEIM dispatch.\r | |
51 | \r | |
52 | Arguments:\r | |
53 | \r | |
54 | SecCoreData - Points to a data structure containing information about the PEI core's operating\r | |
55 | environment, such as the size and location of temporary RAM, the stack location and\r | |
56 | the BFV location.\r | |
57 | PrivateData - Pointer to the private data passed in from caller\r | |
58 | DispatchData - Pointer to PEI_CORE_DISPATCH_DATA data.\r | |
59 | \r | |
60 | Returns:\r | |
61 | \r | |
62 | EFI_SUCCESS - Successfully dispatched PEIM.\r | |
63 | EFI_NOT_FOUND - The dispatch failed.\r | |
64 | \r | |
65 | --*/\r | |
66 | {\r | |
67 | EFI_STATUS Status;\r | |
68 | PEI_CORE_TEMP_POINTERS TempPtr;\r | |
69 | BOOLEAN NextFvFound;\r | |
70 | EFI_FIRMWARE_VOLUME_HEADER *NextFvAddress;\r | |
71 | EFI_FIRMWARE_VOLUME_HEADER *DefaultFvAddress;\r | |
72 | VOID *TopOfStack;\r | |
73 | PEI_CORE_PARAMETERS PeiCoreParameters;\r | |
74 | \r | |
75 | //\r | |
76 | // Debug data for uninstalled Peim list\r | |
77 | //\r | |
78 | EFI_GUID DebugFoundPeimList[32];\r | |
79 | EFI_DEVICE_HANDLE_EXTENDED_DATA ExtendedData;\r | |
80 | \r | |
81 | //\r | |
82 | // save the Current FV Address so that we will not process it again if FindFv returns it later\r | |
83 | //\r | |
84 | DefaultFvAddress = DispatchData->BootFvAddress;\r | |
85 | \r | |
86 | //\r | |
87 | // This is the main dispatch loop. It will search known FVs for PEIMs and\r | |
88 | // attempt to dispatch them. If any PEIM gets dispatched through a single\r | |
89 | // pass of the dispatcher, it will start over from the Bfv again to see\r | |
90 | // if any new PEIMs dependencies got satisfied. With a well ordered\r | |
91 | // FV where PEIMs are found in the order their dependencies are also\r | |
92 | // satisfied, this dipatcher should run only once.\r | |
93 | //\r | |
94 | for (;;) {\r | |
95 | //\r | |
96 | // This is the PEIM search loop. It will scan through all PEIMs it can find\r | |
97 | // looking for PEIMs to dispatch, and will dipatch them if they have not\r | |
98 | // already been dispatched and all of their dependencies are met.\r | |
99 | // If no more PEIMs can be found in this pass through all known FVs,\r | |
100 | // then it will break out of this loop.\r | |
101 | //\r | |
102 | for (;;) {\r | |
103 | \r | |
104 | Status = FindNextPeim (\r | |
105 | &PrivateData->PS,\r | |
106 | DispatchData->CurrentFvAddress,\r | |
107 | &DispatchData->CurrentPeimAddress\r | |
108 | );\r | |
109 | \r | |
110 | //\r | |
111 | // If we found a PEIM, check if it is dispatched. If so, go to the\r | |
112 | // next PEIM. If not, dispatch it if its dependencies are satisfied.\r | |
113 | // If its dependencies are not satisfied, go to the next PEIM.\r | |
114 | //\r | |
115 | if (Status == EFI_SUCCESS) {\r | |
116 | \r | |
117 | DEBUG_CODE_BEGIN ();\r | |
118 | \r | |
119 | //\r | |
120 | // Fill list of found Peims for later list of those not installed\r | |
121 | //\r | |
122 | CopyMem (\r | |
123 | &DebugFoundPeimList[DispatchData->CurrentPeim],\r | |
124 | &DispatchData->CurrentPeimAddress->Name,\r | |
125 | sizeof (EFI_GUID)\r | |
126 | );\r | |
127 | \r | |
128 | DEBUG_CODE_END ();\r | |
129 | \r | |
130 | if (!Dispatched (\r | |
131 | DispatchData->CurrentPeim,\r | |
132 | DispatchData->DispatchedPeimBitMap\r | |
133 | )) {\r | |
134 | if (DepexSatisfied (&PrivateData->PS, DispatchData->CurrentPeimAddress)) {\r | |
135 | Status = PeiLoadImage (\r | |
136 | &PrivateData->PS,\r | |
137 | DispatchData->CurrentPeimAddress,\r | |
138 | &TempPtr.Raw\r | |
139 | );\r | |
140 | if (Status == EFI_SUCCESS) {\r | |
141 | \r | |
142 | //\r | |
143 | // The PEIM has its dependencies satisfied, and its entry point\r | |
144 | // has been found, so invoke it.\r | |
145 | //\r | |
146 | PERF_START (\r | |
147 | (VOID *) (UINTN) (DispatchData->CurrentPeimAddress),\r | |
148 | "PEIM",\r | |
149 | NULL,\r | |
150 | 0\r | |
151 | );\r | |
152 | \r | |
153 | //\r | |
154 | // BUGBUG: Used to be EFI_PEI_REPORT_STATUS_CODE_CODE\r | |
155 | //\r | |
156 | ExtendedData.Handle = (EFI_HANDLE)DispatchData->CurrentPeimAddress;\r | |
157 | \r | |
158 | REPORT_STATUS_CODE_WITH_EXTENDED_DATA (\r | |
159 | EFI_PROGRESS_CODE,\r | |
160 | EFI_SOFTWARE_PEI_CORE | EFI_SW_PC_INIT_BEGIN,\r | |
161 | (VOID *)(&ExtendedData),\r | |
162 | sizeof (ExtendedData)\r | |
163 | );\r | |
164 | \r | |
165 | //\r | |
166 | // Is this a authentic image\r | |
167 | //\r | |
168 | Status = VerifyPeim (\r | |
169 | &PrivateData->PS,\r | |
170 | DispatchData->CurrentPeimAddress\r | |
171 | );\r | |
172 | \r | |
173 | if (Status != EFI_SECURITY_VIOLATION) {\r | |
174 | \r | |
175 | //\r | |
176 | // BUGBUG: Before enable PI, we need cast EFI_FFS_FILE_HEADER* to EFI_PEI_FILE_HANDLE*\r | |
177 | // Because we use new MdePkg's definition, but they are binary compatible in fact.\r | |
178 | //\r | |
179 | Status = TempPtr.PeimEntry (\r | |
180 | (EFI_PEI_FILE_HANDLE*)DispatchData->CurrentPeimAddress,\r | |
181 | &PrivateData->PS\r | |
182 | );\r | |
183 | }\r | |
184 | \r | |
185 | REPORT_STATUS_CODE_WITH_EXTENDED_DATA (\r | |
186 | EFI_PROGRESS_CODE,\r | |
187 | EFI_SOFTWARE_PEI_CORE | EFI_SW_PC_INIT_END,\r | |
188 | (VOID *)(&ExtendedData),\r | |
189 | sizeof (ExtendedData)\r | |
190 | );\r | |
191 | \r | |
192 | PERF_END ((VOID *) (UINTN) (DispatchData->CurrentPeimAddress), "PEIM", NULL, 0);\r | |
193 | \r | |
194 | //\r | |
195 | // Mark the PEIM as dispatched so we don't attempt to run it again\r | |
196 | //\r | |
197 | SetDispatched (\r | |
198 | &PrivateData->PS,\r | |
199 | DispatchData->CurrentPeim,\r | |
200 | &DispatchData->DispatchedPeimBitMap\r | |
201 | );\r | |
202 | \r | |
203 | //\r | |
204 | // Process the Notify list and dispatch any notifies for\r | |
205 | // newly installed PPIs.\r | |
206 | //\r | |
207 | ProcessNotifyList (&PrivateData->PS);\r | |
208 | \r | |
209 | //\r | |
210 | // If real system memory was discovered and installed by this\r | |
211 | // PEIM, switch the stacks to the new memory. Since we are\r | |
212 | // at dispatch level, only the Core's private data is preserved,\r | |
213 | // nobody else should have any data on the stack.\r | |
214 | //\r | |
215 | if (PrivateData->SwitchStackSignal) {\r | |
216 | //\r | |
217 | // Adjust the top of stack to be aligned at CPU_STACK_ALIGNMENT\r | |
218 | //\r | |
219 | TopOfStack = (VOID *)((UINTN)PrivateData->StackBase + (UINTN)PrivateData->StackSize - CPU_STACK_ALIGNMENT);\r | |
220 | TopOfStack = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);\r | |
221 | \r | |
222 | PeiCoreParameters.SecCoreData = SecCoreData;\r | |
223 | PeiCoreParameters.PpiList = NULL;\r | |
224 | PeiCoreParameters.Data = TransferOldDataToNewDataRange (PrivateData);\r | |
225 | ASSERT (PeiCoreParameters.Data != 0);\r | |
226 | \r | |
227 | PeiSwitchStacks (\r | |
228 | InvokePeiCore,\r | |
229 | (VOID*) (UINTN) PeiCore,\r | |
230 | (VOID*) &PeiCoreParameters, \r | |
231 | TopOfStack,\r | |
232 | (VOID*)(UINTN)PrivateData->StackBase\r | |
233 | );\r | |
234 | }\r | |
235 | }\r | |
236 | }\r | |
237 | }\r | |
238 | DispatchData->CurrentPeim++;\r | |
239 | continue;\r | |
240 | \r | |
241 | } else {\r | |
242 | \r | |
243 | //\r | |
244 | // If we could not find another PEIM in the current FV, go try\r | |
245 | // the FindFv PPI to look in other FVs for more PEIMs. If we can\r | |
246 | // not locate the FindFv PPI, or if the FindFv PPI can not find\r | |
247 | // anymore FVs, then exit the PEIM search loop.\r | |
248 | //\r | |
249 | if (DispatchData->FindFv == NULL) {\r | |
250 | Status = PeiServicesLocatePpi (\r | |
251 | &gEfiFindFvPpiGuid,\r | |
252 | 0,\r | |
253 | NULL,\r | |
254 | (VOID **)&DispatchData->FindFv\r | |
255 | );\r | |
256 | if (Status != EFI_SUCCESS) {\r | |
257 | break;\r | |
258 | }\r | |
259 | }\r | |
260 | NextFvFound = FALSE;\r | |
261 | while (!NextFvFound) {\r | |
262 | Status = DispatchData->FindFv->FindFv (\r | |
263 | DispatchData->FindFv,\r | |
264 | &PrivateData->PS,\r | |
265 | &DispatchData->CurrentFv,\r | |
266 | &NextFvAddress\r | |
267 | );\r | |
268 | //\r | |
269 | // if there is no next fv, get out of this loop of finding FVs\r | |
270 | //\r | |
271 | if (Status != EFI_SUCCESS) {\r | |
272 | break;\r | |
273 | }\r | |
274 | //\r | |
275 | // don't process the default Fv again. (we don't know the order in which the hobs were created)\r | |
276 | //\r | |
277 | if ((NextFvAddress != DefaultFvAddress) &&\r | |
278 | (NextFvAddress != DispatchData->CurrentFvAddress)) {\r | |
279 | \r | |
280 | //\r | |
281 | // VerifyFv() is currently returns SUCCESS all the time, add code to it to\r | |
282 | // actually verify the given FV\r | |
283 | //\r | |
284 | Status = VerifyFv (NextFvAddress);\r | |
285 | if (Status == EFI_SUCCESS) {\r | |
286 | NextFvFound = TRUE;\r | |
287 | DispatchData->CurrentFvAddress = NextFvAddress;\r | |
288 | DispatchData->CurrentPeimAddress = NULL;\r | |
289 | //\r | |
290 | // current PRIM number (CurrentPeim) must continue as is, don't reset it here\r | |
291 | //\r | |
292 | }\r | |
293 | }\r | |
294 | }\r | |
295 | //\r | |
296 | // if there is no next fv, get out of this loop of dispatching PEIMs\r | |
297 | //\r | |
298 | if (!NextFvFound) {\r | |
299 | break;\r | |
300 | }\r | |
301 | //\r | |
302 | // continue in the inner for(;;) loop with a new FV;\r | |
303 | //\r | |
304 | }\r | |
305 | }\r | |
306 | \r | |
307 | //\r | |
308 | // If all the PEIMs that we have found have been dispatched, then\r | |
309 | // there is nothing left to dispatch and we don't need to go search\r | |
310 | // through all PEIMs again.\r | |
311 | //\r | |
312 | if ((~(DispatchData->DispatchedPeimBitMap) &\r | |
313 | ((1 << DispatchData->CurrentPeim)-1)) == 0) {\r | |
314 | break;\r | |
315 | }\r | |
316 | \r | |
317 | //\r | |
318 | // Check if no more PEIMs that depex was satisfied\r | |
319 | //\r | |
320 | if (DispatchData->DispatchedPeimBitMap == DispatchData->PreviousPeimBitMap) {\r | |
321 | break;\r | |
322 | }\r | |
323 | \r | |
324 | //\r | |
325 | // Case when Depex is not satisfied and has to traverse the list again\r | |
326 | //\r | |
327 | DispatchData->CurrentPeim = 0;\r | |
328 | DispatchData->CurrentPeimAddress = 0;\r | |
329 | DispatchData->PreviousPeimBitMap = DispatchData->DispatchedPeimBitMap;\r | |
330 | \r | |
331 | //\r | |
332 | // don't go back to the loop without making sure that the CurrentFvAddress is the\r | |
333 | // same as the 1st (or default) FV we started with. otherwise we will interpret the bimap wrongly and\r | |
334 | // mess it up, always start processing the PEIMs from the default FV just like in the first time around.\r | |
335 | //\r | |
336 | DispatchData->CurrentFv = 0;\r | |
337 | DispatchData->CurrentFvAddress = DefaultFvAddress;\r | |
338 | }\r | |
339 | \r | |
340 | DEBUG_CODE_BEGIN ();\r | |
341 | //\r | |
342 | // Debug data for uninstalled Peim list\r | |
343 | //\r | |
344 | UINT32 DebugNotDispatchedBitmap;\r | |
345 | UINT8 DebugFoundPeimPoint;\r | |
346 | \r | |
347 | DebugFoundPeimPoint = 0;\r | |
348 | //\r | |
349 | // Get bitmap of Peims that were not dispatched,\r | |
350 | //\r | |
351 | \r | |
352 | DebugNotDispatchedBitmap = ((DispatchData->DispatchedPeimBitMap) ^ ((1 << DispatchData->CurrentPeim)-1));\r | |
353 | //\r | |
354 | // Scan bitmap of Peims not installed and print GUIDS\r | |
355 | //\r | |
356 | while (DebugNotDispatchedBitmap != 0) {\r | |
357 | if ((DebugNotDispatchedBitmap & 1) != 0) {\r | |
358 | DEBUG ((EFI_D_INFO, "WARNING -> InstallPpi: Not Installed: %g\n",\r | |
359 | &DebugFoundPeimList[DebugFoundPeimPoint]\r | |
360 | ));\r | |
361 | }\r | |
362 | DebugFoundPeimPoint++;\r | |
363 | DebugNotDispatchedBitmap >>= 1;\r | |
364 | }\r | |
365 | \r | |
366 | DEBUG_CODE_END ();\r | |
367 | \r | |
368 | return EFI_NOT_FOUND;\r | |
369 | }\r | |
370 | \r | |
371 | VOID\r | |
372 | InitializeDispatcherData (\r | |
373 | IN EFI_PEI_SERVICES **PeiServices,\r | |
374 | IN PEI_CORE_INSTANCE *OldCoreData,\r | |
375 | IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData\r | |
376 | )\r | |
377 | /*++\r | |
378 | \r | |
379 | Routine Description:\r | |
380 | \r | |
381 | Initialize the Dispatcher's data members\r | |
382 | \r | |
383 | Arguments:\r | |
384 | \r | |
385 | PeiServices - The PEI core services table.\r | |
386 | OldCoreData - Pointer to old core data (before switching stack).\r | |
387 | NULL if being run in non-permament memory mode.\r | |
388 | SecCoreData - Points to a data structure containing information about the PEI core's operating\r | |
389 | environment, such as the size and location of temporary RAM, the stack location and\r | |
390 | the BFV location.\r | |
391 | \r | |
392 | Returns:\r | |
393 | \r | |
394 | None.\r | |
395 | \r | |
396 | --*/\r | |
397 | {\r | |
398 | PEI_CORE_INSTANCE *PrivateData;\r | |
399 | \r | |
400 | PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r | |
401 | \r | |
402 | if (OldCoreData == NULL) {\r | |
403 | PrivateData->DispatchData.CurrentFvAddress = (EFI_FIRMWARE_VOLUME_HEADER *) SecCoreData->BootFirmwareVolumeBase;\r | |
404 | PrivateData->DispatchData.BootFvAddress = (EFI_FIRMWARE_VOLUME_HEADER *) SecCoreData->BootFirmwareVolumeBase;\r | |
405 | } else {\r | |
406 | \r | |
407 | //\r | |
408 | // Current peim has been dispatched, but not count\r | |
409 | //\r | |
410 | PrivateData->DispatchData.CurrentPeim = (UINT8)(OldCoreData->DispatchData.CurrentPeim + 1);\r | |
411 | }\r | |
412 | \r | |
413 | return;\r | |
414 | }\r | |
415 | \r | |
416 | \r | |
417 | BOOLEAN\r | |
418 | Dispatched (\r | |
419 | IN UINT8 CurrentPeim,\r | |
420 | IN UINT32 DispatchedPeimBitMap\r | |
421 | )\r | |
422 | /*++\r | |
423 | \r | |
424 | Routine Description:\r | |
425 | \r | |
426 | This routine checks to see if a particular PEIM has been dispatched during\r | |
427 | the PEI core dispatch.\r | |
428 | \r | |
429 | Arguments:\r | |
430 | CurrentPeim - The PEIM/FV in the bit array to check.\r | |
431 | DispatchedPeimBitMap - Bit array, each bit corresponds to a PEIM/FV.\r | |
432 | \r | |
433 | Returns:\r | |
434 | TRUE - PEIM already dispatched\r | |
435 | FALSE - Otherwise\r | |
436 | \r | |
437 | --*/\r | |
438 | {\r | |
439 | return (BOOLEAN)((DispatchedPeimBitMap & (1 << CurrentPeim)) != 0);\r | |
440 | }\r | |
441 | \r | |
442 | VOID\r | |
443 | SetDispatched (\r | |
444 | IN EFI_PEI_SERVICES **PeiServices,\r | |
445 | IN UINT8 CurrentPeim,\r | |
446 | OUT UINT32 *DispatchedPeimBitMap\r | |
447 | )\r | |
448 | /*++\r | |
449 | \r | |
450 | Routine Description:\r | |
451 | \r | |
452 | This routine sets a PEIM as having been dispatched once its entry\r | |
453 | point has been invoked.\r | |
454 | \r | |
455 | Arguments:\r | |
456 | \r | |
457 | PeiServices - The PEI core services table.\r | |
458 | CurrentPeim - The PEIM/FV in the bit array to check.\r | |
459 | DispatchedPeimBitMap - Bit array, each bit corresponds to a PEIM/FV.\r | |
460 | \r | |
461 | Returns:\r | |
462 | None\r | |
463 | \r | |
464 | --*/\r | |
465 | {\r | |
466 | //\r | |
467 | // Check if the total number of PEIMs exceed the bitmap.\r | |
468 | // CurrentPeim is 0-based\r | |
469 | //\r | |
470 | ASSERT (CurrentPeim < (sizeof (*DispatchedPeimBitMap) * 8));\r | |
471 | *DispatchedPeimBitMap |= (1 << CurrentPeim);\r | |
472 | return;\r | |
473 | }\r | |
474 | \r | |
475 | BOOLEAN\r | |
476 | DepexSatisfied (\r | |
477 | IN EFI_PEI_SERVICES **PeiServices,\r | |
478 | IN VOID *CurrentPeimAddress\r | |
479 | )\r | |
480 | /*++\r | |
481 | \r | |
482 | Routine Description:\r | |
483 | \r | |
484 | This routine parses the Dependency Expression, if available, and\r | |
485 | decides if the module can be executed.\r | |
486 | \r | |
487 | Arguments:\r | |
488 | PeiServices - The PEI Service Table\r | |
489 | CurrentPeimAddress - Address of the PEIM Firmware File under investigation\r | |
490 | \r | |
491 | Returns:\r | |
492 | TRUE - Can be dispatched\r | |
493 | FALSE - Cannot be dispatched\r | |
494 | \r | |
495 | --*/\r | |
496 | {\r | |
497 | EFI_STATUS Status;\r | |
498 | INT8 *DepexData;\r | |
499 | BOOLEAN Runnable;\r | |
500 | \r | |
501 | Status = PeiServicesFfsFindSectionData (\r | |
502 | EFI_SECTION_PEI_DEPEX,\r | |
503 | CurrentPeimAddress,\r | |
504 | (VOID **)&DepexData\r | |
505 | );\r | |
506 | //\r | |
507 | // If there is no DEPEX, assume the module can be executed\r | |
508 | //\r | |
509 | if (EFI_ERROR (Status)) {\r | |
510 | return TRUE;\r | |
511 | }\r | |
512 | \r | |
513 | //\r | |
514 | // Evaluate a given DEPEX\r | |
515 | //\r | |
516 | Status = PeimDispatchReadiness (\r | |
517 | PeiServices,\r | |
518 | DepexData,\r | |
519 | &Runnable\r | |
520 | );\r | |
521 | \r | |
522 | return Runnable;\r | |
523 | }\r | |
524 | \r | |
525 | STATIC\r | |
526 | VOID *\r | |
527 | TransferOldDataToNewDataRange (\r | |
528 | IN PEI_CORE_INSTANCE *PrivateData\r | |
529 | )\r | |
530 | /*++\r | |
531 | \r | |
532 | Routine Description:\r | |
533 | \r | |
534 | This routine transfers the contents of the pre-permanent memory\r | |
535 | PEI Core private data to a post-permanent memory data location.\r | |
536 | \r | |
537 | Arguments:\r | |
538 | \r | |
539 | PrivateData - Pointer to the current PEI Core private data pre-permanent memory\r | |
540 | \r | |
541 | Returns:\r | |
542 | \r | |
543 | Pointer to the PrivateData once the private data has been transferred to permanent memory\r | |
544 | \r | |
545 | --*/\r | |
546 | {\r | |
547 | //\r | |
548 | //Build private HOB to PEI core to transfer old NEM-range data to new NEM-range\r | |
549 | //\r | |
550 | return BuildGuidDataHob (&gEfiPeiCorePrivateGuid, PrivateData, sizeof (PEI_CORE_INSTANCE));\r | |
551 | }\r | |
552 | \r | |
553 | /**\r | |
554 | This routine enable a PEIM to register itself to shadow when PEI Foundation\r | |
555 | discovery permanent memory.\r | |
556 | \r | |
557 | @param FileHandle File handle of a PEIM.\r | |
558 | \r | |
559 | @retval EFI_NOT_FOUND The file handle doesn't point to PEIM itself.\r | |
560 | @retval EFI_ALREADY_STARTED Indicate that the PEIM has been registered itself.\r | |
561 | @retval EFI_SUCCESS Successfully to register itself.\r | |
562 | \r | |
563 | **/ \r | |
564 | EFI_STATUS\r | |
565 | EFIAPI\r | |
566 | PeiRegisterForShadow (\r | |
567 | IN EFI_PEI_FILE_HANDLE FileHandle\r | |
568 | )\r | |
569 | {\r | |
570 | PEI_CORE_INSTANCE *Private;\r | |
571 | Private = PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer ());\r | |
572 | \r | |
573 | if (Private->CurrentFileHandle != FileHandle) {\r | |
574 | //\r | |
575 | // The FileHandle must be for the current PEIM\r | |
576 | //\r | |
577 | return EFI_NOT_FOUND;\r | |
578 | }\r | |
579 | \r | |
580 | if (Private->Fv[Private->CurrentPeimFvCount].PeimState[Private->CurrentPeimCount] >= PEIM_STATE_REGISITER_FOR_SHADOW) {\r | |
581 | //\r | |
582 | // If the PEIM has already entered the PEIM_STATE_REGISTER_FOR_SHADOW or PEIM_STATE_DONE then it's already been started\r | |
583 | //\r | |
584 | return EFI_ALREADY_STARTED;\r | |
585 | }\r | |
586 | \r | |
587 | Private->Fv[Private->CurrentPeimFvCount].PeimState[Private->CurrentPeimCount] = PEIM_STATE_REGISITER_FOR_SHADOW;\r | |
588 | \r | |
589 | return EFI_SUCCESS;\r | |
590 | }\r | |
591 | \r | |
592 | /**\r | |
593 | This routine invoke the PeiCore's entry in new stack environment.\r | |
594 | \r | |
595 | @param Context1 The first context parameter is entry of PeiCore\r | |
596 | @param Context2 The second context parameter is parameter structure point for PeiCore\r | |
597 | \r | |
598 | **/ \r | |
599 | STATIC\r | |
600 | VOID\r | |
601 | InvokePeiCore (\r | |
602 | VOID *Context1,\r | |
603 | VOID *Context2\r | |
604 | )\r | |
605 | {\r | |
606 | PEI_CORE_ENTRY_POINT PeiCoreEntryPoint;\r | |
607 | PEI_CORE_PARAMETERS *PeiCoreParameters;\r | |
608 | \r | |
609 | //\r | |
610 | // Running on new stack in SEC Core\r | |
611 | //\r | |
612 | \r | |
613 | PeiCoreEntryPoint = (PEI_CORE_ENTRY_POINT) (UINTN) Context1;\r | |
614 | PeiCoreParameters = (PEI_CORE_PARAMETERS *)Context2;\r | |
615 | \r | |
616 | //\r | |
617 | // Call PEI Core using new stack\r | |
618 | //\r | |
619 | PeiCoreEntryPoint (\r | |
620 | PeiCoreParameters->SecCoreData,\r | |
621 | PeiCoreParameters->PpiList,\r | |
622 | PeiCoreParameters->Data\r | |
623 | );\r | |
624 | \r | |
625 | //\r | |
626 | // Never returns\r | |
627 | //\r | |
628 | ASSERT_EFI_ERROR (FALSE);\r | |
629 | }\r | |
630 | \r | |
631 | \r | |
632 | \r | |
633 | \r |