]> git.proxmox.com Git - mirror_edk2.git/blame - EdkModulePkg/Core/Pei/Dispatcher/Dispatcher.c
Clean up MSA file of the checked in modules which include:
[mirror_edk2.git] / EdkModulePkg / Core / Pei / Dispatcher / Dispatcher.c
CommitLineData
878ddf1f 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
24#include <PeiMain.h>\r
25\r
92dda53e 26STATIC\r
878ddf1f 27VOID *\r
28TransferOldDataToNewDataRange (\r
29 IN PEI_CORE_INSTANCE *PrivateData\r
30 );\r
31\r
878ddf1f 32EFI_STATUS\r
33PeiDispatcher (\r
34 IN EFI_PEI_STARTUP_DESCRIPTOR *PeiStartupDescriptor,\r
35 IN PEI_CORE_INSTANCE *PrivateData,\r
36 IN PEI_CORE_DISPATCH_DATA *DispatchData\r
37 )\r
38\r
39/*++\r
40\r
41Routine Description:\r
42\r
43 Conduct PEIM dispatch.\r
44\r
45Arguments:\r
46\r
47 PeiStartupDescriptor - Pointer to IN EFI_PEI_STARTUP_DESCRIPTOR\r
48 PrivateData - Pointer to the private data passed in from caller\r
49 DispatchData - Pointer to PEI_CORE_DISPATCH_DATA data.\r
50\r
51Returns:\r
52\r
53 EFI_SUCCESS - Successfully dispatched PEIM.\r
54 EFI_NOT_FOUND - The dispatch failed.\r
55\r
56--*/\r
57{\r
58 EFI_STATUS Status;\r
59 PEI_CORE_TEMP_POINTERS TempPtr;\r
60 UINTN PrivateDataInMem;\r
61 BOOLEAN NextFvFound;\r
62 EFI_FIRMWARE_VOLUME_HEADER *NextFvAddress;\r
63 EFI_FIRMWARE_VOLUME_HEADER *DefaultFvAddress;\r
62332e5d 64 VOID *TopOfStack;\r
878ddf1f 65 //\r
66 // Debug data for uninstalled Peim list\r
67 //\r
68 EFI_GUID DebugFoundPeimList[32];\r
69 REPORT_STATUS_CODE_LIBRARY_DEVICE_HANDLE_EXTENDED_DATA ExtendedData;\r
70\r
71 //\r
72 // save the Current FV Address so that we will not process it again if FindFv returns it later\r
73 //\r
74 DefaultFvAddress = DispatchData->BootFvAddress;\r
75\r
76 //\r
77 // This is the main dispatch loop. It will search known FVs for PEIMs and\r
78 // attempt to dispatch them. If any PEIM gets dispatched through a single\r
79 // pass of the dispatcher, it will start over from the Bfv again to see\r
80 // if any new PEIMs dependencies got satisfied. With a well ordered\r
81 // FV where PEIMs are found in the order their dependencies are also\r
82 // satisfied, this dipatcher should run only once.\r
83 //\r
84 for (;;) {\r
85 //\r
86 // This is the PEIM search loop. It will scan through all PEIMs it can find\r
87 // looking for PEIMs to dispatch, and will dipatch them if they have not\r
88 // already been dispatched and all of their dependencies are met.\r
89 // If no more PEIMs can be found in this pass through all known FVs,\r
90 // then it will break out of this loop.\r
91 //\r
92 for (;;) {\r
93\r
94 Status = FindNextPeim (\r
95 &PrivateData->PS,\r
96 DispatchData->CurrentFvAddress,\r
97 &DispatchData->CurrentPeimAddress\r
98 );\r
99\r
100 //\r
101 // If we found a PEIM, check if it is dispatched. If so, go to the\r
102 // next PEIM. If not, dispatch it if its dependencies are satisfied.\r
103 // If its dependencies are not satisfied, go to the next PEIM.\r
104 //\r
105 if (Status == EFI_SUCCESS) {\r
106\r
2ce31132 107 DEBUG_CODE_BEGIN ();\r
878ddf1f 108\r
109 //\r
110 // Fill list of found Peims for later list of those not installed\r
111 //\r
112 CopyMem (\r
113 &DebugFoundPeimList[DispatchData->CurrentPeim],\r
114 &DispatchData->CurrentPeimAddress->Name,\r
115 sizeof (EFI_GUID)\r
116 );\r
117\r
2ce31132 118 DEBUG_CODE_END ();\r
878ddf1f 119\r
120 if (!Dispatched (\r
121 DispatchData->CurrentPeim,\r
122 DispatchData->DispatchedPeimBitMap\r
123 )) {\r
124 if (DepexSatisfied (&PrivateData->PS, DispatchData->CurrentPeimAddress)) {\r
125 Status = PeiLoadImage (\r
126 &PrivateData->PS,\r
127 DispatchData->CurrentPeimAddress,\r
128 &TempPtr.Raw\r
129 );\r
130 if (Status == EFI_SUCCESS) {\r
131\r
132 //\r
133 // The PEIM has its dependencies satisfied, and its entry point\r
134 // has been found, so invoke it.\r
135 //\r
136 PERF_START (\r
137 (VOID *) (UINTN) (DispatchData->CurrentPeimAddress),\r
138 "PEIM",\r
139 NULL,\r
140 0\r
141 );\r
142\r
143 //\r
144 // BUGBUG: Used to be EFI_PEI_REPORT_STATUS_CODE_CODE\r
145 //\r
146 ExtendedData.Handle = (EFI_HANDLE)DispatchData->CurrentPeimAddress;\r
147\r
148 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (\r
149 EFI_PROGRESS_CODE,\r
150 EFI_SOFTWARE_PEI_CORE | EFI_SW_PC_INIT_BEGIN,\r
151 (VOID *)(&ExtendedData),\r
152 sizeof (ExtendedData)\r
153 );\r
154\r
155 //\r
156 // Is this a authentic image\r
157 //\r
158 Status = VerifyPeim (\r
159 &PrivateData->PS,\r
160 DispatchData->CurrentPeimAddress\r
161 );\r
162\r
163 if (Status != EFI_SECURITY_VIOLATION) {\r
164\r
165 Status = TempPtr.PeimEntry (\r
166 DispatchData->CurrentPeimAddress,\r
167 &PrivateData->PS\r
168 );\r
169 }\r
170\r
171 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (\r
172 EFI_PROGRESS_CODE,\r
173 EFI_SOFTWARE_PEI_CORE | EFI_SW_PC_INIT_END,\r
174 (VOID *)(&ExtendedData),\r
175 sizeof (ExtendedData)\r
176 );\r
177\r
178 PERF_END ((VOID *) (UINTN) (DispatchData->CurrentPeimAddress), "PEIM", NULL, 0);\r
179\r
180 //\r
181 // Mark the PEIM as dispatched so we don't attempt to run it again\r
182 //\r
183 SetDispatched (\r
184 &PrivateData->PS,\r
185 DispatchData->CurrentPeim,\r
186 &DispatchData->DispatchedPeimBitMap\r
187 );\r
188\r
189 //\r
190 // Process the Notify list and dispatch any notifies for\r
191 // newly installed PPIs.\r
192 //\r
193 ProcessNotifyList (&PrivateData->PS);\r
194\r
195 //\r
196 // If real system memory was discovered and installed by this\r
197 // PEIM, switch the stacks to the new memory. Since we are\r
198 // at dispatch level, only the Core's private data is preserved,\r
199 // nobody else should have any data on the stack.\r
200 //\r
201 if (PrivateData->SwitchStackSignal) {\r
202 TempPtr.PeiCore = (PEI_CORE_ENTRY_POINT)PeiCore;\r
203 PrivateDataInMem = (UINTN) TransferOldDataToNewDataRange (PrivateData);\r
204 ASSERT (PrivateDataInMem != 0);\r
205 //\r
62332e5d 206 // Adjust the top of stack to be aligned at CPU_STACK_ALIGNMENT\r
878ddf1f 207 //\r
62332e5d 208 TopOfStack = (VOID *)((UINTN)PrivateData->StackBase + (UINTN)PrivateData->StackSize - CPU_STACK_ALIGNMENT);\r
209 TopOfStack = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);\r
210\r
eeb1cd5a 211 PeiSwitchStacks (\r
878ddf1f 212 (SWITCH_STACK_ENTRY_POINT)(UINTN)TempPtr.Raw,\r
213 PeiStartupDescriptor,\r
214 (VOID*)PrivateDataInMem,\r
62332e5d 215 TopOfStack,\r
eeb1cd5a 216 (VOID*)(UINTN)PrivateData->StackBase\r
217 );\r
878ddf1f 218 }\r
219 }\r
220 }\r
221 }\r
222 DispatchData->CurrentPeim++;\r
223 continue;\r
224\r
225 } else {\r
226\r
227 //\r
228 // If we could not find another PEIM in the current FV, go try\r
229 // the FindFv PPI to look in other FVs for more PEIMs. If we can\r
230 // not locate the FindFv PPI, or if the FindFv PPI can not find\r
231 // anymore FVs, then exit the PEIM search loop.\r
232 //\r
233 if (DispatchData->FindFv == NULL) {\r
84a99d48 234 Status = PeiServicesLocatePpi (\r
878ddf1f 235 &gEfiFindFvPpiGuid,\r
236 0,\r
237 NULL,\r
238 (VOID **)&DispatchData->FindFv\r
239 );\r
240 if (Status != EFI_SUCCESS) {\r
241 break;\r
242 }\r
243 }\r
244 NextFvFound = FALSE;\r
245 while (!NextFvFound) {\r
246 Status = DispatchData->FindFv->FindFv (\r
247 DispatchData->FindFv,\r
248 &PrivateData->PS,\r
249 &DispatchData->CurrentFv,\r
250 &NextFvAddress\r
251 );\r
252 //\r
253 // if there is no next fv, get out of this loop of finding FVs\r
254 //\r
255 if (Status != EFI_SUCCESS) {\r
256 break;\r
257 }\r
258 //\r
259 // don't process the default Fv again. (we don't know the order in which the hobs were created)\r
260 //\r
261 if ((NextFvAddress != DefaultFvAddress) &&\r
262 (NextFvAddress != DispatchData->CurrentFvAddress)) {\r
263\r
264 //\r
265 // VerifyFv() is currently returns SUCCESS all the time, add code to it to\r
266 // actually verify the given FV\r
267 //\r
268 Status = VerifyFv (NextFvAddress);\r
269 if (Status == EFI_SUCCESS) {\r
270 NextFvFound = TRUE;\r
271 DispatchData->CurrentFvAddress = NextFvAddress;\r
272 DispatchData->CurrentPeimAddress = NULL;\r
273 //\r
274 // current PRIM number (CurrentPeim) must continue as is, don't reset it here\r
275 //\r
276 }\r
277 }\r
278 }\r
279 //\r
280 // if there is no next fv, get out of this loop of dispatching PEIMs\r
281 //\r
282 if (!NextFvFound) {\r
283 break;\r
284 }\r
285 //\r
286 // continue in the inner for(;;) loop with a new FV;\r
287 //\r
288 }\r
289 }\r
290\r
291 //\r
292 // If all the PEIMs that we have found have been dispatched, then\r
293 // there is nothing left to dispatch and we don't need to go search\r
294 // through all PEIMs again.\r
295 //\r
296 if ((~(DispatchData->DispatchedPeimBitMap) &\r
297 ((1 << DispatchData->CurrentPeim)-1)) == 0) {\r
298 break;\r
299 }\r
300\r
301 //\r
302 // Check if no more PEIMs that depex was satisfied\r
303 //\r
304 if (DispatchData->DispatchedPeimBitMap == DispatchData->PreviousPeimBitMap) {\r
305 break;\r
306 }\r
307\r
308 //\r
309 // Case when Depex is not satisfied and has to traverse the list again\r
310 //\r
311 DispatchData->CurrentPeim = 0;\r
312 DispatchData->CurrentPeimAddress = 0;\r
313 DispatchData->PreviousPeimBitMap = DispatchData->DispatchedPeimBitMap;\r
314\r
315 //\r
316 // don't go back to the loop without making sure that the CurrentFvAddress is the\r
317 // same as the 1st (or default) FV we started with. otherwise we will interpret the bimap wrongly and\r
318 // mess it up, always start processing the PEIMs from the default FV just like in the first time around.\r
319 //\r
320 DispatchData->CurrentFv = 0;\r
321 DispatchData->CurrentFvAddress = DefaultFvAddress;\r
322 }\r
323\r
2ce31132 324 DEBUG_CODE_BEGIN ();\r
878ddf1f 325 //\r
326 // Debug data for uninstalled Peim list\r
327 //\r
328 UINT32 DebugNotDispatchedBitmap;\r
329 UINT8 DebugFoundPeimPoint;\r
330\r
331 DebugFoundPeimPoint = 0;\r
332 //\r
333 // Get bitmap of Peims that were not dispatched,\r
334 //\r
335\r
336 DebugNotDispatchedBitmap = ((DispatchData->DispatchedPeimBitMap) ^ ((1 << DispatchData->CurrentPeim)-1));\r
337 //\r
338 // Scan bitmap of Peims not installed and print GUIDS\r
339 //\r
340 while (DebugNotDispatchedBitmap != 0) {\r
341 if ((DebugNotDispatchedBitmap & 1) != 0) {\r
342 DEBUG ((EFI_D_INFO, "WARNING -> InstallPpi: Not Installed: %g\n",\r
343 &DebugFoundPeimList[DebugFoundPeimPoint]\r
344 ));\r
345 }\r
346 DebugFoundPeimPoint++;\r
347 DebugNotDispatchedBitmap >>= 1;\r
348 }\r
eeb1cd5a 349\r
2ce31132 350 DEBUG_CODE_END ();\r
878ddf1f 351\r
2ce31132 352 return EFI_NOT_FOUND;\r
878ddf1f 353}\r
354\r
355VOID\r
356InitializeDispatcherData (\r
357 IN EFI_PEI_SERVICES **PeiServices,\r
358 IN PEI_CORE_INSTANCE *OldCoreData,\r
359 IN EFI_PEI_STARTUP_DESCRIPTOR *PeiStartupDescriptor\r
360 )\r
361/*++\r
362\r
363Routine Description:\r
364\r
365 Initialize the Dispatcher's data members\r
366\r
367Arguments:\r
368\r
369 PeiServices - The PEI core services table.\r
370 OldCoreData - Pointer to old core data (before switching stack).\r
371 NULL if being run in non-permament memory mode.\r
372 PeiStartupDescriptor - Information and services provided by SEC phase.\r
373\r
374Returns:\r
375\r
376 None.\r
377\r
378--*/\r
379{\r
380 PEI_CORE_INSTANCE *PrivateData;\r
381\r
382 PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r
383\r
384 if (OldCoreData == NULL) {\r
385 PrivateData->DispatchData.CurrentFvAddress = (EFI_FIRMWARE_VOLUME_HEADER *) PeiStartupDescriptor->BootFirmwareVolume;\r
386 PrivateData->DispatchData.BootFvAddress = (EFI_FIRMWARE_VOLUME_HEADER *) PeiStartupDescriptor->BootFirmwareVolume;\r
387 } else {\r
388\r
389 //\r
390 // Current peim has been dispatched, but not count\r
391 //\r
392 PrivateData->DispatchData.CurrentPeim = (UINT8)(OldCoreData->DispatchData.CurrentPeim + 1);\r
393 }\r
394\r
395 return;\r
396}\r
397\r
398\r
399BOOLEAN\r
400Dispatched (\r
401 IN UINT8 CurrentPeim,\r
402 IN UINT32 DispatchedPeimBitMap\r
403 )\r
404/*++\r
405\r
406Routine Description:\r
407\r
408 This routine checks to see if a particular PEIM has been dispatched during\r
409 the PEI core dispatch.\r
410\r
411Arguments:\r
412 CurrentPeim - The PEIM/FV in the bit array to check.\r
413 DispatchedPeimBitMap - Bit array, each bit corresponds to a PEIM/FV.\r
414\r
415Returns:\r
416 TRUE - PEIM already dispatched\r
417 FALSE - Otherwise\r
418\r
419--*/\r
420{\r
421 return (BOOLEAN)((DispatchedPeimBitMap & (1 << CurrentPeim)) != 0);\r
422}\r
423\r
424VOID\r
425SetDispatched (\r
426 IN EFI_PEI_SERVICES **PeiServices,\r
427 IN UINT8 CurrentPeim,\r
428 OUT UINT32 *DispatchedPeimBitMap\r
429 )\r
430/*++\r
431\r
432Routine Description:\r
433\r
434 This routine sets a PEIM as having been dispatched once its entry\r
435 point has been invoked.\r
436\r
437Arguments:\r
438\r
439 PeiServices - The PEI core services table.\r
440 CurrentPeim - The PEIM/FV in the bit array to check.\r
441 DispatchedPeimBitMap - Bit array, each bit corresponds to a PEIM/FV.\r
442\r
443Returns:\r
444 None\r
445\r
446--*/\r
447{\r
448 //\r
449 // Check if the total number of PEIMs exceed the bitmap.\r
450 // CurrentPeim is 0-based\r
451 //\r
4ba61e5e 452 ASSERT (CurrentPeim < (sizeof (*DispatchedPeimBitMap) * 8));\r
878ddf1f 453 *DispatchedPeimBitMap |= (1 << CurrentPeim);\r
454 return;\r
455}\r
456\r
457BOOLEAN\r
458DepexSatisfied (\r
459 IN EFI_PEI_SERVICES **PeiServices,\r
460 IN VOID *CurrentPeimAddress\r
461 )\r
462/*++\r
463\r
464Routine Description:\r
465\r
466 This routine parses the Dependency Expression, if available, and\r
467 decides if the module can be executed.\r
468\r
469Arguments:\r
470 PeiServices - The PEI Service Table\r
471 CurrentPeimAddress - Address of the PEIM Firmware File under investigation\r
472\r
473Returns:\r
474 TRUE - Can be dispatched\r
475 FALSE - Cannot be dispatched\r
476\r
477--*/\r
478{\r
479 EFI_STATUS Status;\r
480 INT8 *DepexData;\r
481 BOOLEAN Runnable;\r
482\r
84a99d48 483 Status = PeiServicesFfsFindSectionData (\r
878ddf1f 484 EFI_SECTION_PEI_DEPEX,\r
485 CurrentPeimAddress,\r
486 (VOID **)&DepexData\r
487 );\r
488 //\r
489 // If there is no DEPEX, assume the module can be executed\r
490 //\r
491 if (EFI_ERROR (Status)) {\r
492 return TRUE;\r
493 }\r
494\r
495 //\r
496 // Evaluate a given DEPEX\r
497 //\r
498 Status = PeimDispatchReadiness (\r
499 PeiServices,\r
500 DepexData,\r
501 &Runnable\r
502 );\r
503\r
504 return Runnable;\r
505}\r
506\r
92dda53e 507STATIC\r
878ddf1f 508VOID *\r
509TransferOldDataToNewDataRange (\r
510 IN PEI_CORE_INSTANCE *PrivateData\r
511 )\r
512/*++\r
513\r
514Routine Description:\r
515\r
516 This routine transfers the contents of the pre-permanent memory\r
517 PEI Core private data to a post-permanent memory data location.\r
518\r
519Arguments:\r
520\r
521 PrivateData - Pointer to the current PEI Core private data pre-permanent memory\r
522\r
523Returns:\r
524\r
525 Pointer to the PrivateData once the private data has been transferred to permanent memory\r
526\r
527--*/\r
528{\r
bc2693a8 529 //\r
530 //Build private HOB to PEI core to transfer old NEM-range data to new NEM-range\r
531 //\r
878ddf1f 532 return BuildGuidDataHob (&gEfiPeiCorePrivateGuid, PrivateData, sizeof (PEI_CORE_INSTANCE));\r
533}\r
534\r