3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 EFI PEI Core dispatch services
27 TransferOldDataToNewDataRange (
28 IN PEI_CORE_INSTANCE
*PrivateData
31 EFI_GUID gEfiPeiCorePrivateGuid
= EFI_PEI_CORE_PRIVATE_GUID
;
36 IN EFI_PEI_STARTUP_DESCRIPTOR
*PeiStartupDescriptor
,
37 IN PEI_CORE_INSTANCE
*PrivateData
,
38 IN PEI_CORE_DISPATCH_DATA
*DispatchData
45 Conduct PEIM dispatch.
49 PeiStartupDescriptor - Pointer to IN EFI_PEI_STARTUP_DESCRIPTOR
50 PrivateData - Pointer to the private data passed in from caller
51 DispatchData - Pointer to PEI_CORE_DISPATCH_DATA data.
55 EFI_SUCCESS - Successfully dispatched PEIM.
56 EFI_NOT_FOUND - The dispatch failed.
61 PEI_CORE_TEMP_POINTERS TempPtr
;
62 UINTN PrivateDataInMem
;
64 EFI_FIRMWARE_VOLUME_HEADER
*NextFvAddress
;
65 EFI_FIRMWARE_VOLUME_HEADER
*DefaultFvAddress
;
67 // Debug data for uninstalled Peim list
69 EFI_GUID DebugFoundPeimList
[32];
70 REPORT_STATUS_CODE_LIBRARY_DEVICE_HANDLE_EXTENDED_DATA ExtendedData
;
73 // save the Current FV Address so that we will not process it again if FindFv returns it later
75 DefaultFvAddress
= DispatchData
->BootFvAddress
;
78 // This is the main dispatch loop. It will search known FVs for PEIMs and
79 // attempt to dispatch them. If any PEIM gets dispatched through a single
80 // pass of the dispatcher, it will start over from the Bfv again to see
81 // if any new PEIMs dependencies got satisfied. With a well ordered
82 // FV where PEIMs are found in the order their dependencies are also
83 // satisfied, this dipatcher should run only once.
87 // This is the PEIM search loop. It will scan through all PEIMs it can find
88 // looking for PEIMs to dispatch, and will dipatch them if they have not
89 // already been dispatched and all of their dependencies are met.
90 // If no more PEIMs can be found in this pass through all known FVs,
91 // then it will break out of this loop.
95 Status
= FindNextPeim (
97 DispatchData
->CurrentFvAddress
,
98 &DispatchData
->CurrentPeimAddress
102 // If we found a PEIM, check if it is dispatched. If so, go to the
103 // next PEIM. If not, dispatch it if its dependencies are satisfied.
104 // If its dependencies are not satisfied, go to the next PEIM.
106 if (Status
== EFI_SUCCESS
) {
111 // Fill list of found Peims for later list of those not installed
114 &DebugFoundPeimList
[DispatchData
->CurrentPeim
],
115 &DispatchData
->CurrentPeimAddress
->Name
,
122 DispatchData
->CurrentPeim
,
123 DispatchData
->DispatchedPeimBitMap
125 if (DepexSatisfied (&PrivateData
->PS
, DispatchData
->CurrentPeimAddress
)) {
126 Status
= PeiLoadImage (
128 DispatchData
->CurrentPeimAddress
,
131 if (Status
== EFI_SUCCESS
) {
134 // The PEIM has its dependencies satisfied, and its entry point
135 // has been found, so invoke it.
138 (VOID
*) (UINTN
) (DispatchData
->CurrentPeimAddress
),
145 // BUGBUG: Used to be EFI_PEI_REPORT_STATUS_CODE_CODE
147 ExtendedData
.Handle
= (EFI_HANDLE
)DispatchData
->CurrentPeimAddress
;
149 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (
151 EFI_SOFTWARE_PEI_CORE
| EFI_SW_PC_INIT_BEGIN
,
152 (VOID
*)(&ExtendedData
),
153 sizeof (ExtendedData
)
157 // Is this a authentic image
159 Status
= VerifyPeim (
161 DispatchData
->CurrentPeimAddress
164 if (Status
!= EFI_SECURITY_VIOLATION
) {
166 Status
= TempPtr
.PeimEntry (
167 DispatchData
->CurrentPeimAddress
,
172 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (
174 EFI_SOFTWARE_PEI_CORE
| EFI_SW_PC_INIT_END
,
175 (VOID
*)(&ExtendedData
),
176 sizeof (ExtendedData
)
179 PERF_END ((VOID
*) (UINTN
) (DispatchData
->CurrentPeimAddress
), "PEIM", NULL
, 0);
182 // Mark the PEIM as dispatched so we don't attempt to run it again
186 DispatchData
->CurrentPeim
,
187 &DispatchData
->DispatchedPeimBitMap
191 // Process the Notify list and dispatch any notifies for
192 // newly installed PPIs.
194 ProcessNotifyList (&PrivateData
->PS
);
197 // If real system memory was discovered and installed by this
198 // PEIM, switch the stacks to the new memory. Since we are
199 // at dispatch level, only the Core's private data is preserved,
200 // nobody else should have any data on the stack.
202 if (PrivateData
->SwitchStackSignal
) {
203 TempPtr
.PeiCore
= (PEI_CORE_ENTRY_POINT
)PeiCore
;
204 PrivateDataInMem
= (UINTN
) TransferOldDataToNewDataRange (PrivateData
);
205 ASSERT (PrivateDataInMem
!= 0);
207 //Subtract 0x10 from the 4th parameter indicating the new stack base,
208 //in order to provide buffer protection against possible illegal stack
209 //access that might corrupt the stack.
212 (SWITCH_STACK_ENTRY_POINT
)(UINTN
)TempPtr
.Raw
,
213 PeiStartupDescriptor
,
214 (VOID
*)PrivateDataInMem
,
215 (VOID
*)((UINTN
)PrivateData
->StackBase
+ (UINTN
)PrivateData
->StackSize
)
221 DispatchData
->CurrentPeim
++;
227 // If we could not find another PEIM in the current FV, go try
228 // the FindFv PPI to look in other FVs for more PEIMs. If we can
229 // not locate the FindFv PPI, or if the FindFv PPI can not find
230 // anymore FVs, then exit the PEIM search loop.
232 if (DispatchData
->FindFv
== NULL
) {
233 Status
= PeiServicesLocatePpi (
237 (VOID
**)&DispatchData
->FindFv
239 if (Status
!= EFI_SUCCESS
) {
244 while (!NextFvFound
) {
245 Status
= DispatchData
->FindFv
->FindFv (
246 DispatchData
->FindFv
,
248 &DispatchData
->CurrentFv
,
252 // if there is no next fv, get out of this loop of finding FVs
254 if (Status
!= EFI_SUCCESS
) {
258 // don't process the default Fv again. (we don't know the order in which the hobs were created)
260 if ((NextFvAddress
!= DefaultFvAddress
) &&
261 (NextFvAddress
!= DispatchData
->CurrentFvAddress
)) {
264 // VerifyFv() is currently returns SUCCESS all the time, add code to it to
265 // actually verify the given FV
267 Status
= VerifyFv (NextFvAddress
);
268 if (Status
== EFI_SUCCESS
) {
270 DispatchData
->CurrentFvAddress
= NextFvAddress
;
271 DispatchData
->CurrentPeimAddress
= NULL
;
273 // current PRIM number (CurrentPeim) must continue as is, don't reset it here
279 // if there is no next fv, get out of this loop of dispatching PEIMs
285 // continue in the inner for(;;) loop with a new FV;
291 // If all the PEIMs that we have found have been dispatched, then
292 // there is nothing left to dispatch and we don't need to go search
293 // through all PEIMs again.
295 if ((~(DispatchData
->DispatchedPeimBitMap
) &
296 ((1 << DispatchData
->CurrentPeim
)-1)) == 0) {
301 // Check if no more PEIMs that depex was satisfied
303 if (DispatchData
->DispatchedPeimBitMap
== DispatchData
->PreviousPeimBitMap
) {
308 // Case when Depex is not satisfied and has to traverse the list again
310 DispatchData
->CurrentPeim
= 0;
311 DispatchData
->CurrentPeimAddress
= 0;
312 DispatchData
->PreviousPeimBitMap
= DispatchData
->DispatchedPeimBitMap
;
315 // don't go back to the loop without making sure that the CurrentFvAddress is the
316 // same as the 1st (or default) FV we started with. otherwise we will interpret the bimap wrongly and
317 // mess it up, always start processing the PEIMs from the default FV just like in the first time around.
319 DispatchData
->CurrentFv
= 0;
320 DispatchData
->CurrentFvAddress
= DefaultFvAddress
;
325 // Debug data for uninstalled Peim list
327 UINT32 DebugNotDispatchedBitmap
;
328 UINT8 DebugFoundPeimPoint
;
330 DebugFoundPeimPoint
= 0;
332 // Get bitmap of Peims that were not dispatched,
335 DebugNotDispatchedBitmap
= ((DispatchData
->DispatchedPeimBitMap
) ^ ((1 << DispatchData
->CurrentPeim
)-1));
337 // Scan bitmap of Peims not installed and print GUIDS
339 while (DebugNotDispatchedBitmap
!= 0) {
340 if ((DebugNotDispatchedBitmap
& 1) != 0) {
341 DEBUG ((EFI_D_INFO
, "WARNING -> InstallPpi: Not Installed: %g\n",
342 &DebugFoundPeimList
[DebugFoundPeimPoint
]
345 DebugFoundPeimPoint
++;
346 DebugNotDispatchedBitmap
>>= 1;
351 return EFI_NOT_FOUND
;
355 InitializeDispatcherData (
356 IN EFI_PEI_SERVICES
**PeiServices
,
357 IN PEI_CORE_INSTANCE
*OldCoreData
,
358 IN EFI_PEI_STARTUP_DESCRIPTOR
*PeiStartupDescriptor
364 Initialize the Dispatcher's data members
368 PeiServices - The PEI core services table.
369 OldCoreData - Pointer to old core data (before switching stack).
370 NULL if being run in non-permament memory mode.
371 PeiStartupDescriptor - Information and services provided by SEC phase.
379 PEI_CORE_INSTANCE
*PrivateData
;
381 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices
);
383 if (OldCoreData
== NULL
) {
384 PrivateData
->DispatchData
.CurrentFvAddress
= (EFI_FIRMWARE_VOLUME_HEADER
*) PeiStartupDescriptor
->BootFirmwareVolume
;
385 PrivateData
->DispatchData
.BootFvAddress
= (EFI_FIRMWARE_VOLUME_HEADER
*) PeiStartupDescriptor
->BootFirmwareVolume
;
389 // Current peim has been dispatched, but not count
391 PrivateData
->DispatchData
.CurrentPeim
= (UINT8
)(OldCoreData
->DispatchData
.CurrentPeim
+ 1);
400 IN UINT8 CurrentPeim
,
401 IN UINT32 DispatchedPeimBitMap
407 This routine checks to see if a particular PEIM has been dispatched during
408 the PEI core dispatch.
411 CurrentPeim - The PEIM/FV in the bit array to check.
412 DispatchedPeimBitMap - Bit array, each bit corresponds to a PEIM/FV.
415 TRUE - PEIM already dispatched
420 return (BOOLEAN
)((DispatchedPeimBitMap
& (1 << CurrentPeim
)) != 0);
425 IN EFI_PEI_SERVICES
**PeiServices
,
426 IN UINT8 CurrentPeim
,
427 OUT UINT32
*DispatchedPeimBitMap
433 This routine sets a PEIM as having been dispatched once its entry
434 point has been invoked.
438 PeiServices - The PEI core services table.
439 CurrentPeim - The PEIM/FV in the bit array to check.
440 DispatchedPeimBitMap - Bit array, each bit corresponds to a PEIM/FV.
448 // Check if the total number of PEIMs exceed the bitmap.
449 // CurrentPeim is 0-based
451 ASSERT (CurrentPeim
< (sizeof (*DispatchedPeimBitMap
) * 8));
452 *DispatchedPeimBitMap
|= (1 << CurrentPeim
);
458 IN EFI_PEI_SERVICES
**PeiServices
,
459 IN VOID
*CurrentPeimAddress
465 This routine parses the Dependency Expression, if available, and
466 decides if the module can be executed.
469 PeiServices - The PEI Service Table
470 CurrentPeimAddress - Address of the PEIM Firmware File under investigation
473 TRUE - Can be dispatched
474 FALSE - Cannot be dispatched
482 Status
= PeiServicesFfsFindSectionData (
483 EFI_SECTION_PEI_DEPEX
,
488 // If there is no DEPEX, assume the module can be executed
490 if (EFI_ERROR (Status
)) {
495 // Evaluate a given DEPEX
497 Status
= PeimDispatchReadiness (
508 TransferOldDataToNewDataRange (
509 IN PEI_CORE_INSTANCE
*PrivateData
515 This routine transfers the contents of the pre-permanent memory
516 PEI Core private data to a post-permanent memory data location.
520 PrivateData - Pointer to the current PEI Core private data pre-permanent memory
524 Pointer to the PrivateData once the private data has been transferred to permanent memory
528 return BuildGuidDataHob (&gEfiPeiCorePrivateGuid
, PrivateData
, sizeof (PEI_CORE_INSTANCE
));