2 EFI PEI Core dispatch services
4 Copyright (c) 2006, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 /// CAR is filled with this initial value during SEC phase
20 #define INIT_CAR_VALUE 0x5AA55AA5
23 EFI_STATUS_CODE_DATA DataHeader
;
25 } PEIM_FILE_HANDLE_EXTENDED_DATA
;
29 Discover all Peims and optional Apriori file in one FV. There is at most one
30 Apriori file in one FV.
33 @param Private - Pointer to the private data passed in from caller
34 @param VolumeHandle - Fv handle.
38 DiscoverPeimsAndOrderWithApriori (
39 IN PEI_CORE_INSTANCE
*Private
,
40 IN EFI_PEI_FV_HANDLE VolumeHandle
44 EFI_PEI_FV_HANDLE FileHandle
;
45 EFI_PEI_FILE_HANDLE AprioriFileHandle
;
52 EFI_PEI_FV_HANDLE TempFileHandles
[FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv
)];
53 EFI_GUID FileGuid
[FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv
)];
56 // Walk the FV and find all the PEIMs and the Apriori file.
58 AprioriFileHandle
= NULL
;
59 Private
->CurrentFvFileHandles
[0] = NULL
;
64 // If the current Fv has been scanned, directly get its cachable record.
66 if (Private
->Fv
[Private
->CurrentPeimFvCount
].ScanFv
) {
67 CopyMem (Private
->CurrentFvFileHandles
, Private
->Fv
[Private
->CurrentPeimFvCount
].FvFileHandles
, sizeof (Private
->CurrentFvFileHandles
));
72 // Go ahead to scan this Fv, and cache FileHandles within it.
74 for (PeimCount
= 0; PeimCount
< FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv
); PeimCount
++) {
75 Status
= PeiFindFileEx (
78 PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE
,
82 if (Status
!= EFI_SUCCESS
) {
86 Private
->CurrentFvFileHandles
[PeimCount
] = FileHandle
;
89 Private
->AprioriCount
= 0;
90 if (AprioriFileHandle
!= NULL
) {
92 // Read the Apriori file
94 Status
= PeiServicesFfsFindSectionData (EFI_SECTION_RAW
, AprioriFileHandle
, (VOID
**) &Apriori
);
95 if (!EFI_ERROR (Status
)) {
97 // Calculate the number of PEIMs in the A Priori list
99 Private
->AprioriCount
= *(UINT32
*)(((EFI_FFS_FILE_HEADER
*)AprioriFileHandle
)->Size
) & 0x00FFFFFF;
100 Private
->AprioriCount
-= sizeof (EFI_FFS_FILE_HEADER
) - sizeof (EFI_COMMON_SECTION_HEADER
);
101 Private
->AprioriCount
/= sizeof (EFI_GUID
);
103 ZeroMem (FileGuid
, sizeof (FileGuid
));
104 for (Index
= 0; Index
< PeimCount
; Index
++) {
106 // Make an array of file name guids that matches the FileHandle array so we can convert
107 // quickly from file name to file handle
109 CopyMem (&FileGuid
[Index
], &((EFI_FFS_FILE_HEADER
*)Private
->CurrentFvFileHandles
[Index
])->Name
,sizeof(EFI_GUID
));
113 // Walk through FileGuid array to find out who is invalid PEIM guid in Apriori file.
114 // Add avalible PEIMs in Apriori file into TempFileHandles array at first.
117 for (Index
= 0; Index2
< Private
->AprioriCount
; Index
++) {
118 while (Index2
< Private
->AprioriCount
) {
119 Guid
= ScanGuid (FileGuid
, PeimCount
* sizeof (EFI_GUID
), &Apriori
[Index2
++]);
127 PeimIndex
= ((UINTN
)Guid
- (UINTN
)&FileGuid
[0])/sizeof (EFI_GUID
);
128 TempFileHandles
[Index
] = Private
->CurrentFvFileHandles
[PeimIndex
];
131 // Since we have copied the file handle we can remove it from this list.
133 Private
->CurrentFvFileHandles
[PeimIndex
] = NULL
;
137 // Update valid Aprioricount
139 Private
->AprioriCount
= Index
;
142 // Add in any PEIMs not in the Apriori file
144 for (;Index
< PeimCount
; Index
++) {
145 for (Index2
= 0; Index2
< PeimCount
; Index2
++) {
146 if (Private
->CurrentFvFileHandles
[Index2
] != NULL
) {
147 TempFileHandles
[Index
] = Private
->CurrentFvFileHandles
[Index2
];
148 Private
->CurrentFvFileHandles
[Index2
] = NULL
;
154 //Index the end of array contains re-range Pei moudle.
156 TempFileHandles
[Index
] = NULL
;
159 // Private->CurrentFvFileHandles is currently in PEIM in the FV order.
160 // We need to update it to start with files in the A Priori list and
161 // then the remaining files in PEIM order.
163 CopyMem (Private
->CurrentFvFileHandles
, TempFileHandles
, sizeof (Private
->CurrentFvFileHandles
));
167 // Cache the current Fv File Handle. So that we don't have to scan the Fv again.
168 // Instead, we can retrieve the file handles within this Fv from cachable data.
170 Private
->Fv
[Private
->CurrentPeimFvCount
].ScanFv
= TRUE
;
171 CopyMem (Private
->Fv
[Private
->CurrentPeimFvCount
].FvFileHandles
, Private
->CurrentFvFileHandles
, sizeof (Private
->CurrentFvFileHandles
));
176 Shadow PeiCore module from flash to installed memory.
178 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
179 @param PrivateInMem PeiCore's private data structure
181 @return PeiCore function address after shadowing.
185 IN CONST EFI_PEI_SERVICES
**PeiServices
,
186 IN PEI_CORE_INSTANCE
*PrivateInMem
189 EFI_PEI_FILE_HANDLE PeiCoreFileHandle
;
190 EFI_PHYSICAL_ADDRESS EntryPoint
;
192 UINT32 AuthenticationState
;
194 PeiCoreFileHandle
= NULL
;
197 // Find the PEI Core in the BFV
199 Status
= PeiFindFileEx (
200 (EFI_PEI_FV_HANDLE
)PrivateInMem
->Fv
[0].FvHeader
,
202 EFI_FV_FILETYPE_PEI_CORE
,
206 ASSERT_EFI_ERROR (Status
);
209 // Shadow PEI Core into memory so it will run faster
211 Status
= PeiLoadImage (
213 *((EFI_PEI_FILE_HANDLE
*)&PeiCoreFileHandle
),
217 ASSERT_EFI_ERROR (Status
);
220 // Compute the PeiCore's function address after shaowed PeiCore.
221 // _ModuleEntryPoint is PeiCore main function entry
223 return (VOID
*) ((UINTN
) EntryPoint
+ (UINTN
) PeiCore
- (UINTN
) _ModuleEntryPoint
);
227 Conduct PEIM dispatch.
229 @param SecCoreData Points to a data structure containing information about the PEI core's operating
230 environment, such as the size and location of temporary RAM, the stack location and
232 @param Private Pointer to the private data passed in from caller
237 IN CONST EFI_SEC_PEI_HAND_OFF
*SecCoreData
,
238 IN PEI_CORE_INSTANCE
*Private
244 CONST EFI_PEI_SERVICES
**PeiServices
;
245 EFI_PEI_FV_HANDLE VolumeHandle
;
246 EFI_PEI_FILE_HANDLE PeimFileHandle
;
249 UINT32 AuthenticationState
;
250 EFI_PHYSICAL_ADDRESS EntryPoint
;
251 EFI_PEIM_ENTRY_POINT2 PeimEntryPoint
;
252 UINTN SaveCurrentPeimCount
;
253 UINTN SaveCurrentFvCount
;
254 EFI_PEI_FILE_HANDLE SaveCurrentFileHandle
;
255 PEIM_FILE_HANDLE_EXTENDED_DATA ExtendedData
;
256 EFI_PHYSICAL_ADDRESS NewPermenentMemoryBase
;
257 TEMPORARY_RAM_SUPPORT_PPI
*TemporaryRamSupportPpi
;
258 EFI_HOB_HANDOFF_INFO_TABLE
*OldHandOffTable
;
259 EFI_HOB_HANDOFF_INFO_TABLE
*NewHandOffTable
;
262 PEI_CORE_INSTANCE
*PrivateInMem
;
263 UINT64 NewPeiStackSize
;
264 UINT64 OldPeiStackSize
;
266 EFI_FV_FILE_INFO FvFileInfo
;
267 UINTN OldCheckingTop
;
268 UINTN OldCheckingBottom
;
271 PeiServices
= (CONST EFI_PEI_SERVICES
**) &Private
->PS
;
272 PeimEntryPoint
= NULL
;
273 PeimFileHandle
= NULL
;
276 if ((Private
->PeiMemoryInstalled
) && (Private
->HobList
.HandoffInformationTable
->BootMode
!= BOOT_ON_S3_RESUME
)) {
278 // Once real memory is available, shadow the RegisterForShadow modules. And meanwhile
279 // update the modules' status from PEIM_STATE_REGISITER_FOR_SHADOW to PEIM_STATE_DONE.
281 SaveCurrentPeimCount
= Private
->CurrentPeimCount
;
282 SaveCurrentFvCount
= Private
->CurrentPeimFvCount
;
283 SaveCurrentFileHandle
= Private
->CurrentFileHandle
;
285 for (Index1
= 0; Index1
<= SaveCurrentFvCount
; Index1
++) {
286 for (Index2
= 0; (Index2
< FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv
)) && (Private
->Fv
[Index1
].FvFileHandles
[Index2
] != NULL
); Index2
++) {
287 if (Private
->Fv
[Index1
].PeimState
[Index2
] == PEIM_STATE_REGISITER_FOR_SHADOW
) {
288 PeimFileHandle
= Private
->Fv
[Index1
].FvFileHandles
[Index2
];
289 Status
= PeiLoadImage (
290 (CONST EFI_PEI_SERVICES
**) &Private
->PS
,
295 if (Status
== EFI_SUCCESS
) {
297 // PEIM_STATE_REGISITER_FOR_SHADOW move to PEIM_STATE_DONE
299 Private
->Fv
[Index1
].PeimState
[Index2
]++;
300 Private
->CurrentFileHandle
= PeimFileHandle
;
301 Private
->CurrentPeimFvCount
= Index1
;
302 Private
->CurrentPeimCount
= Index2
;
304 // Call the PEIM entry point
306 PeimEntryPoint
= (EFI_PEIM_ENTRY_POINT2
)(UINTN
)EntryPoint
;
308 PERF_START (0, "PEIM", NULL
, 0);
309 PeimEntryPoint(PeimFileHandle
, (const EFI_PEI_SERVICES
**) &Private
->PS
);
310 PERF_END (0, "PEIM", NULL
, 0);
314 // Process the Notify list and dispatch any notifies for
315 // newly installed PPIs.
317 ProcessNotifyList (Private
);
321 Private
->CurrentFileHandle
= SaveCurrentFileHandle
;
322 Private
->CurrentPeimFvCount
= SaveCurrentFvCount
;
323 Private
->CurrentPeimCount
= SaveCurrentPeimCount
;
327 // This is the main dispatch loop. It will search known FVs for PEIMs and
328 // attempt to dispatch them. If any PEIM gets dispatched through a single
329 // pass of the dispatcher, it will start over from the Bfv again to see
330 // if any new PEIMs dependencies got satisfied. With a well ordered
331 // FV where PEIMs are found in the order their dependencies are also
332 // satisfied, this dipatcher should run only once.
336 // In case that reenter PeiCore happens, the last pass record is still available.
338 if (!Private
->PeimDispatcherReenter
) {
339 Private
->PeimNeedingDispatch
= FALSE
;
340 Private
->PeimDispatchOnThisPass
= FALSE
;
342 Private
->PeimDispatcherReenter
= FALSE
;
345 for (FvCount
= Private
->CurrentPeimFvCount
; FvCount
< Private
->FvCount
; FvCount
++) {
346 Private
->CurrentPeimFvCount
= FvCount
;
348 // Get this Fv Handle by PeiService FvFindNextVolume.
350 PeiFvFindNextVolume (PeiServices
, FvCount
, &VolumeHandle
);
352 if (Private
->CurrentPeimCount
== 0) {
354 // When going through each FV, at first, search Apriori file to
355 // reorder all PEIMs to ensure the PEIMs in Apriori file to get
356 // dispatch at first.
358 DiscoverPeimsAndOrderWithApriori (Private
, VolumeHandle
);
362 // Start to dispatch all modules within the current Fv.
364 for (PeimCount
= Private
->CurrentPeimCount
;
365 (PeimCount
< FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv
)) && (Private
->CurrentFvFileHandles
[PeimCount
] != NULL
);
367 Private
->CurrentPeimCount
= PeimCount
;
368 PeimFileHandle
= Private
->CurrentFileHandle
= Private
->CurrentFvFileHandles
[PeimCount
];
370 if (Private
->Fv
[FvCount
].PeimState
[PeimCount
] == PEIM_STATE_NOT_DISPATCHED
) {
371 if (!DepexSatisfied (Private
, PeimFileHandle
, PeimCount
)) {
372 Private
->PeimNeedingDispatch
= TRUE
;
374 Status
= PeiFfsGetFileInfo (PeimFileHandle
, &FvFileInfo
);
375 ASSERT_EFI_ERROR (Status
);
376 if (FvFileInfo
.FileType
== EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
) {
378 // For Fv type file, Produce new FV PPI and FV hob
380 Status
= ProcessFvFile (PeiServices
, PeimFileHandle
, &AuthenticationState
);
383 // For PEIM driver, Load its entry point
385 Status
= PeiLoadImage (
393 if ((Status
== EFI_SUCCESS
)) {
395 // The PEIM has its dependencies satisfied, and its entry point
396 // has been found, so invoke it.
398 PERF_START (0, "PEIM", NULL
, 0);
400 ExtendedData
.Handle
= (EFI_HANDLE
)PeimFileHandle
;
402 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (
404 FixedPcdGet32(PcdStatusCodeValuePeimDispatch
),
405 (VOID
*)(&ExtendedData
),
406 sizeof (ExtendedData
)
409 Status
= VerifyPeim (Private
, VolumeHandle
, PeimFileHandle
);
410 if (Status
!= EFI_SECURITY_VIOLATION
&& (AuthenticationState
== 0)) {
412 // PEIM_STATE_NOT_DISPATCHED move to PEIM_STATE_DISPATCHED
414 Private
->Fv
[FvCount
].PeimState
[PeimCount
]++;
416 if (FvFileInfo
.FileType
!= EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
) {
418 // Call the PEIM entry point for PEIM driver
420 PeimEntryPoint
= (EFI_PEIM_ENTRY_POINT2
)(UINTN
)EntryPoint
;
421 PeimEntryPoint (PeimFileHandle
, (const EFI_PEI_SERVICES
**) PeiServices
);
424 Private
->PeimDispatchOnThisPass
= TRUE
;
427 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (
429 FixedPcdGet32(PcdStatusCodeValuePeimDispatch
),
430 (VOID
*)(&ExtendedData
),
431 sizeof (ExtendedData
)
433 PERF_END (0, "PEIM", NULL
, 0);
437 if (Private
->SwitchStackSignal
) {
439 // Before switch stack from CAR to permenent memory, caculate the heap and stack
440 // usage in temporary memory for debuging.
443 UINT32
*StackPointer
;
445 for (StackPointer
= (UINT32
*)SecCoreData
->StackBase
;
446 (StackPointer
< (UINT32
*)((UINTN
)SecCoreData
->StackBase
+ SecCoreData
->StackSize
)) \
447 && (*StackPointer
== INIT_CAR_VALUE
);
450 DEBUG ((EFI_D_INFO
, "Total Cache as RAM: %d bytes.\n", (UINT32
)SecCoreData
->TemporaryRamSize
));
451 DEBUG ((EFI_D_INFO
, " CAR stack ever used: %d bytes.\n",
452 (SecCoreData
->StackSize
- ((UINTN
) StackPointer
- (UINTN
)SecCoreData
->StackBase
))
454 DEBUG ((EFI_D_INFO
, " CAR heap used: %d bytes.\n",
455 ((UINTN
) Private
->HobList
.HandoffInformationTable
->EfiFreeMemoryBottom
-
456 (UINTN
) Private
->HobList
.Raw
)
461 // Reserve the size of new stack at bottom of physical memory
463 OldPeiStackSize
= (UINT64
) SecCoreData
->StackSize
;
464 NewPeiStackSize
= (RShiftU64 (Private
->PhysicalMemoryLength
, 1) + EFI_PAGE_MASK
) & ~EFI_PAGE_MASK
;
465 if (FixedPcdGet32(PcdPeiCoreMaxPeiStackSize
) > (UINT32
) NewPeiStackSize
) {
466 Private
->StackSize
= NewPeiStackSize
;
468 Private
->StackSize
= FixedPcdGet32(PcdPeiCoreMaxPeiStackSize
);
472 // In theory, the size of new stack in permenent memory should large than
473 // size of old stack in temporary memory.
474 // But if new stack is smaller than the size of old stack, we also reserve
475 // the size of old stack at bottom of permenent memory.
477 DEBUG ((EFI_D_ERROR
, "Old Stack Size%d, New stack size%d\n", (INT32
) Private
->StackSize
, (INT32
) OldPeiStackSize
));
478 ASSERT (Private
->StackSize
>= OldPeiStackSize
);
479 StackGap
= Private
->StackSize
- OldPeiStackSize
;
482 // Update HandOffHob for new installed permenent memory
484 OldHandOffTable
= Private
->HobList
.HandoffInformationTable
;
485 OldCheckingBottom
= (UINTN
)(SecCoreData
->TemporaryRamBase
);
486 OldCheckingTop
= (UINTN
)(OldCheckingBottom
+ SecCoreData
->TemporaryRamSize
);
489 // The whole temporary memory will be migrated to physical memory.
490 // CAUTION: The new base is computed accounding to gap of new stack.
492 NewPermenentMemoryBase
= Private
->PhysicalMemoryBegin
+ StackGap
;
495 // Caculate stack offset and heap offset between CAR and new permement
496 // memory seperately.
498 StackOffset
= (UINTN
) NewPermenentMemoryBase
- (UINTN
) SecCoreData
->StackBase
;
499 HeapOffset
= (INTN
) ((UINTN
) Private
->PhysicalMemoryBegin
+ Private
->StackSize
- \
500 (UINTN
) SecCoreData
->PeiTemporaryRamBase
);
501 DEBUG ((EFI_D_INFO
, "Heap Offset = 0x%lX Stack Offset = 0x%lX\n", (INT64
)HeapOffset
, (INT64
)StackOffset
));
504 // Caculate new HandOffTable and PrivateData address in permenet memory's stack
506 NewHandOffTable
= (EFI_HOB_HANDOFF_INFO_TABLE
*)((UINTN
)OldHandOffTable
+ HeapOffset
);
507 PrivateInMem
= (PEI_CORE_INSTANCE
*)((UINTN
) (VOID
*) Private
+ StackOffset
);
510 // TemporaryRamSupportPpi is produced by platform's SEC
512 Status
= PeiLocatePpi (
513 (CONST EFI_PEI_SERVICES
**) PeiServices
,
514 &gEfiTemporaryRamSupportPpiGuid
,
517 (VOID
**)&TemporaryRamSupportPpi
521 if (!EFI_ERROR (Status
)) {
523 // Temporary Ram support Ppi is provided by platform, it will copy
524 // temporary memory to permenent memory and do stack switching.
525 // After invoken temporary Ram support, following code's stack is in
526 // memory but not in CAR.
528 TemporaryRamSupportPpi
->TemporaryRamMigration (
529 (CONST EFI_PEI_SERVICES
**) PeiServices
,
530 (EFI_PHYSICAL_ADDRESS
)(UINTN
) SecCoreData
->TemporaryRamBase
,
531 (EFI_PHYSICAL_ADDRESS
)(UINTN
) NewPermenentMemoryBase
,
532 SecCoreData
->TemporaryRamSize
537 // In IA32/x64/Itanium architecture, we need platform provide
538 // TEMPORAY_RAM_MIGRATION_PPI.
546 // Fixup the PeiCore's private data
548 PrivateInMem
->PS
= &PrivateInMem
->ServiceTableShadow
;
549 PrivateInMem
->CpuIo
= &PrivateInMem
->ServiceTableShadow
.CpuIo
;
550 PrivateInMem
->HobList
.Raw
= (VOID
*) ((UINTN
) PrivateInMem
->HobList
.Raw
+ HeapOffset
);
551 PrivateInMem
->StackBase
= (EFI_PHYSICAL_ADDRESS
)(((UINTN
)PrivateInMem
->PhysicalMemoryBegin
+ EFI_PAGE_MASK
) & ~EFI_PAGE_MASK
);
553 PeiServices
= (CONST EFI_PEI_SERVICES
**) &PrivateInMem
->PS
;
556 // Fixup for PeiService's address
558 SetPeiServicesTablePointer(PeiServices
);
561 // Update HandOffHob for new installed permenent memory
563 NewHandOffTable
->EfiEndOfHobList
=
564 (EFI_PHYSICAL_ADDRESS
)((UINTN
) NewHandOffTable
->EfiEndOfHobList
+ HeapOffset
);
565 NewHandOffTable
->EfiMemoryTop
= PrivateInMem
->PhysicalMemoryBegin
+
566 PrivateInMem
->PhysicalMemoryLength
;
567 NewHandOffTable
->EfiMemoryBottom
= PrivateInMem
->PhysicalMemoryBegin
;
568 NewHandOffTable
->EfiFreeMemoryTop
= PrivateInMem
->FreePhysicalMemoryTop
;
569 NewHandOffTable
->EfiFreeMemoryBottom
= NewHandOffTable
->EfiEndOfHobList
+
570 sizeof (EFI_HOB_GENERIC_HEADER
);
573 // We need convert the PPI desciptor's pointer
575 ConvertPpiPointers (PrivateInMem
,
581 DEBUG ((EFI_D_INFO
, "Stack Hob: BaseAddress=0x%lX Length=0x%lX\n",
582 PrivateInMem
->StackBase
,
583 PrivateInMem
->StackSize
));
584 BuildStackHob (PrivateInMem
->StackBase
, PrivateInMem
->StackSize
);
587 // After the whole temporary memory is migrated, then we can allocate page in
590 PrivateInMem
->PeiMemoryInstalled
= TRUE
;
593 // Indicate that PeiCore reenter
595 PrivateInMem
->PeimDispatcherReenter
= TRUE
;
598 // Shadow PEI Core. When permanent memory is avaiable, shadow
599 // PEI Core and PEIMs to get high performance.
601 PrivateInMem
->ShadowedPeiCore
= ShadowPeiCore (
606 // Process the Notify list and dispatch any notifies for
607 // newly installed PPIs.
609 ProcessNotifyList (PrivateInMem
);
614 PeiCore (SecCoreData
, NULL
, PrivateInMem
);
617 // Code should not come here
619 ASSERT_EFI_ERROR(FALSE
);
623 // Process the Notify list and dispatch any notifies for
624 // newly installed PPIs.
626 ProcessNotifyList (Private
);
628 if ((Private
->PeiMemoryInstalled
) && (Private
->Fv
[FvCount
].PeimState
[PeimCount
] == PEIM_STATE_REGISITER_FOR_SHADOW
) && \
629 (Private
->HobList
.HandoffInformationTable
->BootMode
!= BOOT_ON_S3_RESUME
)) {
631 // If memory is availble we shadow images by default for performance reasons.
632 // We call the entry point a 2nd time so the module knows it's shadowed.
634 //PERF_START (PeiServices, L"PEIM", PeimFileHandle, 0);
635 PeimEntryPoint (PeimFileHandle
, (const EFI_PEI_SERVICES
**) PeiServices
);
636 //PERF_END (PeiServices, L"PEIM", PeimFileHandle, 0);
639 // PEIM_STATE_REGISITER_FOR_SHADOW move to PEIM_STATE_DONE
641 Private
->Fv
[FvCount
].PeimState
[PeimCount
]++;
644 // Process the Notify list and dispatch any notifies for
645 // newly installed PPIs.
647 ProcessNotifyList (Private
);
654 // We set to NULL here to optimize the 2nd entry to this routine after
655 // memory is found. This reprevents rescanning of the FV. We set to
656 // NULL here so we start at the begining of the next FV
658 Private
->CurrentFileHandle
= NULL
;
659 Private
->CurrentPeimCount
= 0;
661 // Before walking through the next FV,Private->CurrentFvFileHandles[]should set to NULL
663 SetMem (Private
->CurrentFvFileHandles
, sizeof (Private
->CurrentFvFileHandles
), 0);
667 // Before making another pass, we should set Private->CurrentPeimFvCount =0 to go
668 // through all the FV.
670 Private
->CurrentPeimFvCount
= 0;
673 // PeimNeedingDispatch being TRUE means we found a PEIM that did not get
674 // dispatched. So we need to make another pass
676 // PeimDispatchOnThisPass being TRUE means we dispatched a PEIM on this
677 // pass. If we did not dispatch a PEIM there is no point in trying again
678 // as it will fail the next time too (nothing has changed).
680 } while (Private
->PeimNeedingDispatch
&& Private
->PeimDispatchOnThisPass
);
685 Initialize the Dispatcher's data members
687 @param PrivateData PeiCore's private data structure
688 @param OldCoreData Old data from SecCore
689 NULL if being run in non-permament memory mode.
690 @param SecCoreData Points to a data structure containing information about the PEI core's operating
691 environment, such as the size and location of temporary RAM, the stack location and
698 InitializeDispatcherData (
699 IN PEI_CORE_INSTANCE
*PrivateData
,
700 IN PEI_CORE_INSTANCE
*OldCoreData
,
701 IN CONST EFI_SEC_PEI_HAND_OFF
*SecCoreData
704 if (OldCoreData
== NULL
) {
705 PrivateData
->PeimDispatcherReenter
= FALSE
;
706 PeiInitializeFv (PrivateData
, SecCoreData
);
713 This routine parses the Dependency Expression, if available, and
714 decides if the module can be executed.
717 @param Private PeiCore's private data structure
718 @param FileHandle PEIM's file handle
719 @param PeimCount Peim count in all dispatched PEIMs.
721 @retval TRUE Can be dispatched
722 @retval FALSE Cannot be dispatched
727 IN PEI_CORE_INSTANCE
*Private
,
728 IN EFI_PEI_FILE_HANDLE FileHandle
,
735 if (PeimCount
< Private
->AprioriCount
) {
737 // If its in the A priori file then we set Depex to TRUE
743 // Depex section not in the encapsulated section.
745 Status
= PeiServicesFfsFindSectionData (
746 EFI_SECTION_PEI_DEPEX
,
751 if (EFI_ERROR (Status
)) {
753 // If there is no DEPEX, assume the module can be executed
759 // Evaluate a given DEPEX
761 return PeimDispatchReadiness (&Private
->PS
, DepexData
);
765 This routine enable a PEIM to register itself to shadow when PEI Foundation
766 discovery permanent memory.
768 @param FileHandle File handle of a PEIM.
770 @retval EFI_NOT_FOUND The file handle doesn't point to PEIM itself.
771 @retval EFI_ALREADY_STARTED Indicate that the PEIM has been registered itself.
772 @retval EFI_SUCCESS Successfully to register itself.
777 PeiRegisterForShadow (
778 IN EFI_PEI_FILE_HANDLE FileHandle
781 PEI_CORE_INSTANCE
*Private
;
782 Private
= PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer ());
784 if (Private
->CurrentFileHandle
!= FileHandle
) {
786 // The FileHandle must be for the current PEIM
788 return EFI_NOT_FOUND
;
791 if (Private
->Fv
[Private
->CurrentPeimFvCount
].PeimState
[Private
->CurrentPeimCount
] >= PEIM_STATE_REGISITER_FOR_SHADOW
) {
793 // If the PEIM has already entered the PEIM_STATE_REGISTER_FOR_SHADOW or PEIM_STATE_DONE then it's already been started
795 return EFI_ALREADY_STARTED
;
798 Private
->Fv
[Private
->CurrentPeimFvCount
].PeimState
[Private
->CurrentPeimCount
] = PEIM_STATE_REGISITER_FOR_SHADOW
;