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
26 #define INIT_CAR_VALUE 0x5AA55AA5
29 EFI_STATUS_CODE_DATA DataHeader
;
31 } PEIM_FILE_HANDLE_EXTENDED_DATA
;
34 DiscoverPeimsAndOrderWithApriori (
35 IN PEI_CORE_INSTANCE
*Private
,
36 IN EFI_PEI_FV_HANDLE VolumeHandle
42 Discover all Peims and optional Apriori file in one FV. There is at most one
43 Apriori file in one FV.
47 Private - Pointer to the private data passed in from caller
48 VolumeHandle - Fv handle.
56 EFI_PEI_FV_HANDLE FileHandle
;
57 EFI_PEI_FILE_HANDLE AprioriFileHandle
;
64 EFI_PEI_FV_HANDLE TempFileHandles
[FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv
)];
65 EFI_GUID FileGuid
[FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv
)];
68 // Walk the FV and find all the PEIMs and the Apriori file.
70 AprioriFileHandle
= NULL
;
71 Private
->CurrentFvFileHandles
[0] = NULL
;
76 // If the current Fv has been scanned, directly get its cachable record.
78 if (Private
->Fv
[Private
->CurrentPeimFvCount
].ScanFv
) {
79 CopyMem (Private
->CurrentFvFileHandles
, Private
->Fv
[Private
->CurrentPeimFvCount
].FvFileHandles
, sizeof (Private
->CurrentFvFileHandles
));
84 // Go ahead to scan this Fv, and cache FileHandles within it.
86 for (PeimCount
= 0; PeimCount
< FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv
); PeimCount
++) {
87 Status
= PeiFindFileEx (
90 PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE
,
94 if (Status
!= EFI_SUCCESS
) {
98 Private
->CurrentFvFileHandles
[PeimCount
] = FileHandle
;
101 Private
->AprioriCount
= 0;
102 if (AprioriFileHandle
!= NULL
) {
104 // Read the Apriori file
106 Status
= PeiServicesFfsFindSectionData (EFI_SECTION_RAW
, AprioriFileHandle
, (VOID
**) &Apriori
);
107 if (!EFI_ERROR (Status
)) {
109 // Calculate the number of PEIMs in the A Priori list
111 Private
->AprioriCount
= *(UINT32
*)(((EFI_FFS_FILE_HEADER
*)AprioriFileHandle
)->Size
) & 0x00FFFFFF;
112 Private
->AprioriCount
-= sizeof (EFI_FFS_FILE_HEADER
) - sizeof (EFI_COMMON_SECTION_HEADER
);
113 Private
->AprioriCount
/= sizeof (EFI_GUID
);
115 SetMem (FileGuid
, sizeof (FileGuid
), 0);
116 for (Index
= 0; Index
< PeimCount
; Index
++) {
118 // Make an array of file name guids that matches the FileHandle array so we can convert
119 // quickly from file name to file handle
121 CopyMem (&FileGuid
[Index
], &((EFI_FFS_FILE_HEADER
*)Private
->CurrentFvFileHandles
[Index
])->Name
,sizeof(EFI_GUID
));
125 // Walk through FileGuid array to find out who is invalid PEIM guid in Apriori file.
126 // Add avalible PEIMs in Apriori file into TempFileHandles array at first.
129 for (Index
= 0; Index2
< Private
->AprioriCount
; Index
++) {
130 while (Index2
< Private
->AprioriCount
) {
131 Guid
= ScanGuid (FileGuid
, PeimCount
* sizeof (EFI_GUID
), &Apriori
[Index2
++]);
139 PeimIndex
= ((UINTN
)Guid
- (UINTN
)&FileGuid
[0])/sizeof (EFI_GUID
);
140 TempFileHandles
[Index
] = Private
->CurrentFvFileHandles
[PeimIndex
];
143 // Since we have copied the file handle we can remove it from this list.
145 Private
->CurrentFvFileHandles
[PeimIndex
] = NULL
;
149 // Update valid Aprioricount
151 Private
->AprioriCount
= Index
;
154 // Add in any PEIMs not in the Apriori file
156 for (;Index
< PeimCount
; Index
++) {
157 for (Index2
= 0; Index2
< PeimCount
; Index2
++) {
158 if (Private
->CurrentFvFileHandles
[Index2
] != NULL
) {
159 TempFileHandles
[Index
] = Private
->CurrentFvFileHandles
[Index2
];
160 Private
->CurrentFvFileHandles
[Index2
] = NULL
;
166 //Index the end of array contains re-range Pei moudle.
168 TempFileHandles
[Index
] = NULL
;
171 // Private->CurrentFvFileHandles is currently in PEIM in the FV order.
172 // We need to update it to start with files in the A Priori list and
173 // then the remaining files in PEIM order.
175 CopyMem (Private
->CurrentFvFileHandles
, TempFileHandles
, sizeof (Private
->CurrentFvFileHandles
));
179 // Cache the current Fv File Handle. So that we don't have to scan the Fv again.
180 // Instead, we can retrieve the file handles within this Fv from cachable data.
182 Private
->Fv
[Private
->CurrentPeimFvCount
].ScanFv
= TRUE
;
183 CopyMem (Private
->Fv
[Private
->CurrentPeimFvCount
].FvFileHandles
, Private
->CurrentFvFileHandles
, sizeof (Private
->CurrentFvFileHandles
));
189 EFI_PEI_SERVICES
**PeiServices
,
190 PEI_CORE_INSTANCE
*PrivateInMem
193 EFI_PEI_FILE_HANDLE PeiCoreFileHandle
;
194 EFI_PHYSICAL_ADDRESS EntryPoint
;
196 UINT32 AuthenticationState
;
198 PeiCoreFileHandle
= NULL
;
201 // Find the PEI Core in the BFV
203 Status
= PeiFindFileEx (
204 (EFI_PEI_FV_HANDLE
)PrivateInMem
->Fv
[0].FvHeader
,
206 EFI_FV_FILETYPE_PEI_CORE
,
210 ASSERT_EFI_ERROR (Status
);
213 // Shadow PEI Core into memory so it will run faster
215 Status
= PeiLoadImage (
217 *((EFI_PEI_FILE_HANDLE
*)&PeiCoreFileHandle
),
221 ASSERT_EFI_ERROR (Status
);
223 return (VOID
*) ((UINTN
) EntryPoint
+ (UINTN
) PeiCore
- (UINTN
) _ModuleEntryPoint
);
228 IN CONST EFI_SEC_PEI_HAND_OFF
*SecCoreData
,
229 IN PEI_CORE_INSTANCE
*Private
236 Conduct PEIM dispatch.
240 SecCoreData - Points to a data structure containing information about the PEI core's operating
241 environment, such as the size and location of temporary RAM, the stack location and
243 PrivateData - Pointer to the private data passed in from caller
244 DispatchData - Pointer to PEI_CORE_DISPATCH_DATA data.
248 EFI_SUCCESS - Successfully dispatched PEIM.
249 EFI_NOT_FOUND - The dispatch failed.
256 EFI_PEI_SERVICES
**PeiServices
;
257 EFI_PEI_FV_HANDLE VolumeHandle
;
258 //EFI_PHYSICAL_ADDRESS PeiCoreFileHandle;
259 EFI_PEI_FILE_HANDLE PeimFileHandle
;
262 UINT32 AuthenticationState
;
263 EFI_PHYSICAL_ADDRESS EntryPoint
;
264 EFI_PEIM_ENTRY_POINT2 PeimEntryPoint
;
265 BOOLEAN PeimNeedingDispatch
;
266 BOOLEAN PeimDispatchOnThisPass
;
267 UINTN SaveCurrentPeimCount
;
268 UINTN SaveCurrentFvCount
;
269 EFI_PEI_FILE_HANDLE SaveCurrentFileHandle
;
270 PEIM_FILE_HANDLE_EXTENDED_DATA ExtendedData
;
271 EFI_PHYSICAL_ADDRESS NewPermenentMemoryBase
;
272 TEMPORARY_RAM_SUPPORT_PPI
*TemporaryRamSupportPpi
;
273 EFI_HOB_HANDOFF_INFO_TABLE
*OldHandOffTable
;
274 EFI_HOB_HANDOFF_INFO_TABLE
*NewHandOffTable
;
276 PEI_CORE_INSTANCE
*PrivateInMem
;
277 UINT64 NewPeiStackSize
;
278 UINT64 OldPeiStackSize
;
280 EFI_FV_FILE_INFO FvFileInfo
;
281 UINTN OldCheckingTop
;
282 UINTN OldCheckingBottom
;
285 PeiServices
= &Private
->PS
;
286 PeimEntryPoint
= NULL
;
287 PeimFileHandle
= NULL
;
290 if ((Private
->PeiMemoryInstalled
) && (Private
->HobList
.HandoffInformationTable
->BootMode
!= BOOT_ON_S3_RESUME
)) {
292 // Once real memory is available, shadow the RegisterForShadow modules. And meanwhile
293 // update the modules' status from PEIM_STATE_REGISITER_FOR_SHADOW to PEIM_STATE_DONE.
295 SaveCurrentPeimCount
= Private
->CurrentPeimCount
;
296 SaveCurrentFvCount
= Private
->CurrentPeimFvCount
;
297 SaveCurrentFileHandle
= Private
->CurrentFileHandle
;
299 for (Index1
= 0; Index1
<= SaveCurrentFvCount
; Index1
++) {
300 for (Index2
= 0; (Index2
< FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv
)) && (Private
->Fv
[Index1
].FvFileHandles
[Index2
] != NULL
); Index2
++) {
301 if (Private
->Fv
[Index1
].PeimState
[Index2
] == PEIM_STATE_REGISITER_FOR_SHADOW
) {
302 PeimFileHandle
= Private
->Fv
[Index1
].FvFileHandles
[Index2
];
303 Status
= PeiLoadImage (
309 if (Status
== EFI_SUCCESS
) {
311 // PEIM_STATE_REGISITER_FOR_SHADOW move to PEIM_STATE_DONE
313 Private
->Fv
[Index1
].PeimState
[Index2
]++;
314 Private
->CurrentFileHandle
= PeimFileHandle
;
315 Private
->CurrentPeimFvCount
= Index1
;
316 Private
->CurrentPeimCount
= Index2
;
318 // Call the PEIM entry point
320 PeimEntryPoint
= (EFI_PEIM_ENTRY_POINT2
)(UINTN
)EntryPoint
;
322 PERF_START (0, "PEIM", NULL
, 0);
323 PeimEntryPoint(PeimFileHandle
, (const EFI_PEI_SERVICES
**) &Private
->PS
);
324 PERF_END (0, "PEIM", NULL
, 0);
328 // Process the Notify list and dispatch any notifies for
329 // newly installed PPIs.
331 ProcessNotifyList (Private
);
335 Private
->CurrentFileHandle
= SaveCurrentFileHandle
;
336 Private
->CurrentPeimFvCount
= SaveCurrentFvCount
;
337 Private
->CurrentPeimCount
= SaveCurrentPeimCount
;
341 // This is the main dispatch loop. It will search known FVs for PEIMs and
342 // attempt to dispatch them. If any PEIM gets dispatched through a single
343 // pass of the dispatcher, it will start over from the Bfv again to see
344 // if any new PEIMs dependencies got satisfied. With a well ordered
345 // FV where PEIMs are found in the order their dependencies are also
346 // satisfied, this dipatcher should run only once.
349 PeimNeedingDispatch
= FALSE
;
350 PeimDispatchOnThisPass
= FALSE
;
352 for (FvCount
= Private
->CurrentPeimFvCount
; FvCount
< Private
->FvCount
; FvCount
++) {
353 Private
->CurrentPeimFvCount
= FvCount
;
354 VolumeHandle
= Private
->Fv
[FvCount
].FvHeader
;
356 if (Private
->CurrentPeimCount
== 0) {
358 // When going through each FV, at first, search Apriori file to
359 // reorder all PEIMs to ensure the PEIMs in Apriori file to get
360 // dispatch at first.
362 DiscoverPeimsAndOrderWithApriori (Private
, VolumeHandle
);
366 // Start to dispatch all modules within the current Fv.
368 for (PeimCount
= Private
->CurrentPeimCount
;
369 (PeimCount
< FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv
)) && (Private
->CurrentFvFileHandles
[PeimCount
] != NULL
);
371 Private
->CurrentPeimCount
= PeimCount
;
372 PeimFileHandle
= Private
->CurrentFileHandle
= Private
->CurrentFvFileHandles
[PeimCount
];
374 if (Private
->Fv
[FvCount
].PeimState
[PeimCount
] == PEIM_STATE_NOT_DISPATCHED
) {
375 if (!DepexSatisfied (Private
, PeimFileHandle
, PeimCount
)) {
376 PeimNeedingDispatch
= TRUE
;
378 Status
= PeiFfsGetFileInfo (PeimFileHandle
, &FvFileInfo
);
379 ASSERT_EFI_ERROR (Status
);
380 if (FvFileInfo
.FileType
== EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
) {
382 // For Fv type file, Produce new FV PPI and FV hob
384 Status
= ProcessFvFile (PeiServices
, PeimFileHandle
, &AuthenticationState
);
387 // For PEIM driver, Load its entry point
389 Status
= PeiLoadImage (
397 if ((Status
== EFI_SUCCESS
)) {
399 // The PEIM has its dependencies satisfied, and its entry point
400 // has been found, so invoke it.
402 PERF_START (0, "PEIM", NULL
, 0);
404 ExtendedData
.Handle
= (EFI_HANDLE
)PeimFileHandle
;
406 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (
408 FixedPcdGet32(PcdStatusCodeValuePeimDispatch
),
409 (VOID
*)(&ExtendedData
),
410 sizeof (ExtendedData
)
413 Status
= VerifyPeim (Private
, VolumeHandle
, PeimFileHandle
);
414 if (Status
!= EFI_SECURITY_VIOLATION
&& (AuthenticationState
== 0)) {
416 // PEIM_STATE_NOT_DISPATCHED move to PEIM_STATE_DISPATCHED
418 Private
->Fv
[FvCount
].PeimState
[PeimCount
]++;
420 if (FvFileInfo
.FileType
!= EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
) {
422 // Call the PEIM entry point for PEIM driver
424 PeimEntryPoint
= (EFI_PEIM_ENTRY_POINT2
)(UINTN
)EntryPoint
;
425 PeimEntryPoint (PeimFileHandle
, (const EFI_PEI_SERVICES
**) PeiServices
);
428 PeimDispatchOnThisPass
= TRUE
;
431 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (
433 FixedPcdGet32(PcdStatusCodeValuePeimDispatch
),
434 (VOID
*)(&ExtendedData
),
435 sizeof (ExtendedData
)
437 PERF_END (0, "PEIM", NULL
, 0);
441 if (Private
->SwitchStackSignal
) {
443 // Before switch stack from CAR to permenent memory, caculate the heap and stack
444 // usage in temporary memory for debuging.
449 for (StackPointer
= (UINTN
*)SecCoreData
->StackBase
;
450 (StackPointer
< (UINTN
*)((UINTN
)SecCoreData
->StackBase
+ SecCoreData
->StackSize
)) \
451 && (*StackPointer
== INIT_CAR_VALUE
);
454 DEBUG ((EFI_D_INFO
, "Total Cache as RAM: %d bytes.\n", SecCoreData
->TemporaryRamSize
));
455 DEBUG ((EFI_D_INFO
, " CAR stack ever used: %d bytes.\n",
456 (SecCoreData
->StackSize
- ((UINTN
) StackPointer
- (UINTN
)SecCoreData
->StackBase
))
458 DEBUG ((EFI_D_INFO
, " CAR heap used: %d bytes.\n",
459 ((UINTN
) Private
->HobList
.HandoffInformationTable
->EfiFreeMemoryBottom
-
460 (UINTN
) Private
->HobList
.Raw
)
465 // Reserve the size of new stack at bottom of physical memory
467 OldPeiStackSize
= Private
->StackSize
;
468 NewPeiStackSize
= (RShiftU64 (Private
->PhysicalMemoryLength
, 1) + EFI_PAGE_MASK
) & ~EFI_PAGE_MASK
;
469 if (FixedPcdGet32(PcdPeiCoreMaxPeiStackSize
) > (UINT32
) NewPeiStackSize
) {
470 Private
->StackSize
= NewPeiStackSize
;
472 Private
->StackSize
= FixedPcdGet32(PcdPeiCoreMaxPeiStackSize
);
476 // In theory, the size of new stack in permenent memory should large than
477 // size of old stack in temporary memory.
478 // But if new stack is smaller than the size of old stack, we also reserve
479 // the size of old stack at bottom of permenent memory.
482 if (Private
->StackSize
> OldPeiStackSize
) {
483 StackGap
= Private
->StackSize
- OldPeiStackSize
;
487 // Update HandOffHob for new installed permenent memory
489 OldHandOffTable
= Private
->HobList
.HandoffInformationTable
;
490 OldCheckingBottom
= (UINTN
)OldHandOffTable
;
491 OldCheckingTop
= (UINTN
)(OldCheckingBottom
+ SecCoreData
->TemporaryRamSize
);
494 // The whole temporary memory will be migrated to physical memory.
495 // CAUTION: The new base is computed accounding to gap of new stack.
497 NewPermenentMemoryBase
= Private
->PhysicalMemoryBegin
+ StackGap
;
498 Offset
= (UINTN
) NewPermenentMemoryBase
- (UINTN
) SecCoreData
->TemporaryRamBase
;
499 NewHandOffTable
= (EFI_HOB_HANDOFF_INFO_TABLE
*)((UINTN
)OldHandOffTable
+ Offset
);
500 PrivateInMem
= (PEI_CORE_INSTANCE
*)((UINTN
) (VOID
*) Private
+ Offset
);
503 // TemporaryRamSupportPpi is produced by platform's SEC
505 Status
= PeiLocatePpi (
506 (CONST EFI_PEI_SERVICES
**) PeiServices
,
507 &gEfiTemporaryRamSupportPpiGuid
,
510 (VOID
**)&TemporaryRamSupportPpi
514 if (!EFI_ERROR (Status
)) {
515 TemporaryRamSupportPpi
->TemporaryRamMigration (
516 (CONST EFI_PEI_SERVICES
**) PeiServices
,
517 (EFI_PHYSICAL_ADDRESS
)(UINTN
) SecCoreData
->TemporaryRamBase
,
518 (EFI_PHYSICAL_ADDRESS
)(UINTN
) NewPermenentMemoryBase
,
519 SecCoreData
->TemporaryRamSize
524 (VOID
*)(UINTN
) NewPermenentMemoryBase
,
525 SecCoreData
->TemporaryRamBase
,
526 SecCoreData
->TemporaryRamSize
533 // Fixup the PeiCore's private data
535 PrivateInMem
->PS
= &PrivateInMem
->ServiceTableShadow
;
536 PrivateInMem
->CpuIo
= &PrivateInMem
->ServiceTableShadow
.CpuIo
;
537 PrivateInMem
->HobList
.Raw
= (VOID
*) ((UINTN
) PrivateInMem
->HobList
.Raw
+ Offset
);
538 PrivateInMem
->StackBase
= (EFI_PHYSICAL_ADDRESS
)(((UINTN
)PrivateInMem
->PhysicalMemoryBegin
+ EFI_PAGE_MASK
) & ~EFI_PAGE_MASK
);
540 PeiServices
= &PrivateInMem
->PS
;
543 // Fixup for PeiService's address
545 SetPeiServicesTablePointer(PeiServices
);
548 // Update HandOffHob for new installed permenent memory
550 NewHandOffTable
->EfiEndOfHobList
=
551 (EFI_PHYSICAL_ADDRESS
)(VOID
*)((UINTN
) NewHandOffTable
->EfiEndOfHobList
+ Offset
);
552 NewHandOffTable
->EfiMemoryTop
= PrivateInMem
->PhysicalMemoryBegin
+
553 PrivateInMem
->PhysicalMemoryLength
;
554 NewHandOffTable
->EfiMemoryBottom
= PrivateInMem
->PhysicalMemoryBegin
;
555 NewHandOffTable
->EfiFreeMemoryTop
= PrivateInMem
->FreePhysicalMemoryTop
;
556 NewHandOffTable
->EfiFreeMemoryBottom
= NewHandOffTable
->EfiEndOfHobList
+
557 sizeof (EFI_HOB_GENERIC_HEADER
);
560 // We need convert the PPI desciptor's pointer
562 ConvertPpiPointers ((CONST EFI_PEI_SERVICES
**)PeiServices
,
567 DEBUG ((EFI_D_INFO
, "Stack Hob: BaseAddress=0x%X Length=0x%X\n",
568 (UINTN
)PrivateInMem
->StackBase
,
569 PrivateInMem
->StackSize
));
570 BuildStackHob (PrivateInMem
->StackBase
, PrivateInMem
->StackSize
);
573 // After the whole temporary memory is migrated, then we can allocate page in
576 PrivateInMem
->PeiMemoryInstalled
= TRUE
;
579 // Make sure we don't retry the same PEIM that added memory
581 PrivateInMem
->CurrentPeimCount
++;
584 // Shadow PEI Core. When permanent memory is avaiable, shadow
585 // PEI Core and PEIMs to get high performance.
587 //PeiCoreFileHandle = 0;
589 // Find the PEI Core in the BFV
591 //Status = PeiFindFileEx (
592 // (EFI_PEI_FV_HANDLE)PrivateInMem->Fv[0].FvHeader,
594 // EFI_FV_FILETYPE_PEI_CORE,
595 // (EFI_PEI_FILE_HANDLE*)&PeiCoreFileHandle,
598 //ASSERT_EFI_ERROR (Status);
601 // Shadow PEI Core into memory so it will run faster
603 //Status = PeiLoadImage (
605 // *((EFI_PEI_FILE_HANDLE*)&PeiCoreFileHandle),
607 // &AuthenticationState
609 //ASSERT_EFI_ERROR (Status);
611 //PrivateInMem->ShadowedPeiCore = (VOID*) ((UINTN) EntryPoint +
613 // (UINTN) _ModuleEntryPoint);
614 PrivateInMem
->ShadowedPeiCore
= ShadowPeiCore (
619 // Process the Notify list and dispatch any notifies for
620 // newly installed PPIs.
622 ProcessNotifyList (PrivateInMem
);
627 PeiCore (SecCoreData
, NULL
, PrivateInMem
);
629 //((PEI_CORE_ENTRY_POINT) (UINTN) PrivateInMem->ShadowedPeiCore) (
636 // Code should not come here
638 ASSERT_EFI_ERROR(FALSE
);
642 // Process the Notify list and dispatch any notifies for
643 // newly installed PPIs.
645 ProcessNotifyList (Private
);
647 if ((Private
->PeiMemoryInstalled
) && (Private
->Fv
[FvCount
].PeimState
[PeimCount
] == PEIM_STATE_REGISITER_FOR_SHADOW
) && \
648 (Private
->HobList
.HandoffInformationTable
->BootMode
!= BOOT_ON_S3_RESUME
)) {
650 // If memory is availble we shadow images by default for performance reasons.
651 // We call the entry point a 2nd time so the module knows it's shadowed.
653 //PERF_START (PeiServices, L"PEIM", PeimFileHandle, 0);
654 PeimEntryPoint (PeimFileHandle
, (const EFI_PEI_SERVICES
**) PeiServices
);
655 //PERF_END (PeiServices, L"PEIM", PeimFileHandle, 0);
658 // PEIM_STATE_REGISITER_FOR_SHADOW move to PEIM_STATE_DONE
660 Private
->Fv
[FvCount
].PeimState
[PeimCount
]++;
663 // Process the Notify list and dispatch any notifies for
664 // newly installed PPIs.
666 ProcessNotifyList (Private
);
673 // We set to NULL here to optimize the 2nd entry to this routine after
674 // memory is found. This reprevents rescanning of the FV. We set to
675 // NULL here so we start at the begining of the next FV
677 Private
->CurrentFileHandle
= NULL
;
678 Private
->CurrentPeimCount
= 0;
680 // Before walking through the next FV,Private->CurrentFvFileHandles[]should set to NULL
682 SetMem (Private
->CurrentFvFileHandles
, sizeof (Private
->CurrentFvFileHandles
), 0);
686 // Before making another pass, we should set Private->CurrentPeimFvCount =0 to go
687 // through all the FV.
689 Private
->CurrentPeimFvCount
= 0;
692 // PeimNeedingDispatch being TRUE means we found a PEIM that did not get
693 // dispatched. So we need to make another pass
695 // PeimDispatchOnThisPass being TRUE means we dispatched a PEIM on this
696 // pass. If we did not dispatch a PEIM there is no point in trying again
697 // as it will fail the next time too (nothing has changed).
699 } while (PeimNeedingDispatch
&& PeimDispatchOnThisPass
);
704 InitializeDispatcherData (
705 IN PEI_CORE_INSTANCE
*PrivateData
,
706 IN PEI_CORE_INSTANCE
*OldCoreData
,
707 IN CONST EFI_SEC_PEI_HAND_OFF
*SecCoreData
713 Initialize the Dispatcher's data members
717 PeiServices - The PEI core services table.
718 OldCoreData - Pointer to old core data (before switching stack).
719 NULL if being run in non-permament memory mode.
720 SecCoreData - Points to a data structure containing information about the PEI core's operating
721 environment, such as the size and location of temporary RAM, the stack location and
730 if (OldCoreData
== NULL
) {
731 PeiInitializeFv (PrivateData
, SecCoreData
);
740 IN PEI_CORE_INSTANCE
*Private
,
741 IN EFI_PEI_FILE_HANDLE FileHandle
,
748 This routine parses the Dependency Expression, if available, and
749 decides if the module can be executed.
752 PeiServices - The PEI Service Table
753 CurrentPeimAddress - Address of the PEIM Firmware File under investigation
756 TRUE - Can be dispatched
757 FALSE - Cannot be dispatched
764 if (PeimCount
< Private
->AprioriCount
) {
766 // If its in the A priori file then we set Depex to TRUE
772 // Depex section not in the encapsulated section.
774 Status
= PeiServicesFfsFindSectionData (
775 EFI_SECTION_PEI_DEPEX
,
780 if (EFI_ERROR (Status
)) {
782 // If there is no DEPEX, assume the module can be executed
788 // Evaluate a given DEPEX
790 return PeimDispatchReadiness (&Private
->PS
, DepexData
);
794 This routine enable a PEIM to register itself to shadow when PEI Foundation
795 discovery permanent memory.
797 @param FileHandle File handle of a PEIM.
799 @retval EFI_NOT_FOUND The file handle doesn't point to PEIM itself.
800 @retval EFI_ALREADY_STARTED Indicate that the PEIM has been registered itself.
801 @retval EFI_SUCCESS Successfully to register itself.
806 PeiRegisterForShadow (
807 IN EFI_PEI_FILE_HANDLE FileHandle
810 PEI_CORE_INSTANCE
*Private
;
811 Private
= PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer ());
813 if (Private
->CurrentFileHandle
!= FileHandle
) {
815 // The FileHandle must be for the current PEIM
817 return EFI_NOT_FOUND
;
820 if (Private
->Fv
[Private
->CurrentPeimFvCount
].PeimState
[Private
->CurrentPeimCount
] >= PEIM_STATE_REGISITER_FOR_SHADOW
) {
822 // If the PEIM has already entered the PEIM_STATE_REGISTER_FOR_SHADOW or PEIM_STATE_DONE then it's already been started
824 return EFI_ALREADY_STARTED
;
827 Private
->Fv
[Private
->CurrentPeimFvCount
].PeimState
[Private
->CurrentPeimCount
] = PEIM_STATE_REGISITER_FOR_SHADOW
;
835 Get Fv image from the FV type file, then install FV INFO ppi, Build FV hob.
837 @param PeiServices Pointer to the PEI Core Services Table.
838 @param FileHandle File handle of a Fv type file.
839 @param AuthenticationState Pointer to attestation authentication state of image.
842 @retval EFI_NOT_FOUND FV image can't be found.
843 @retval EFI_SUCCESS Successfully to process it.
848 IN EFI_PEI_SERVICES
**PeiServices
,
849 IN EFI_PEI_FILE_HANDLE FvFileHandle
,
850 OUT UINT32
*AuthenticationState
854 EFI_PEI_FV_HANDLE FvImageHandle
;
855 EFI_FV_INFO FvImageInfo
;
858 EFI_PEI_HOB_POINTERS HobFv2
;
861 *AuthenticationState
= 0;
864 // Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has already
867 HobFv2
.Raw
= GetHobList ();
868 while ((HobFv2
.Raw
= GetNextHob (EFI_HOB_TYPE_FV2
, HobFv2
.Raw
)) != NULL
) {
869 if (CompareGuid (&(((EFI_FFS_FILE_HEADER
*)FvFileHandle
)->Name
), &HobFv2
.FirmwareVolume2
->FileName
)) {
871 // this FILE has been dispatched, it will not be dispatched again.
875 HobFv2
.Raw
= GET_NEXT_HOB (HobFv2
);
879 // Find FvImage in FvFile
881 Status
= PeiFfsFindSectionData (
882 (CONST EFI_PEI_SERVICES
**) PeiServices
,
883 EFI_SECTION_FIRMWARE_VOLUME_IMAGE
,
885 (VOID
**)&FvImageHandle
888 if (EFI_ERROR (Status
)) {
892 // Collect FvImage Info.
894 Status
= PeiFfsGetVolumeInfo (FvImageHandle
, &FvImageInfo
);
895 ASSERT_EFI_ERROR (Status
);
897 // FvAlignment must be more than 8 bytes required by FvHeader structure.
899 FvAlignment
= 1 << ((FvImageInfo
.FvAttributes
& EFI_FVB2_ALIGNMENT
) >> 16);
900 if (FvAlignment
< 8) {
906 if ((UINTN
) FvImageInfo
.FvStart
% FvAlignment
!= 0) {
907 FvBuffer
= AllocateAlignedPages (EFI_SIZE_TO_PAGES ((UINT32
) FvImageInfo
.FvSize
), FvAlignment
);
908 if (FvBuffer
== NULL
) {
909 return EFI_OUT_OF_RESOURCES
;
911 CopyMem (FvBuffer
, FvImageInfo
.FvStart
, (UINTN
) FvImageInfo
.FvSize
);
913 // Update FvImageInfo after reload FvImage to new aligned memory
915 PeiFfsGetVolumeInfo ((EFI_PEI_FV_HANDLE
) FvBuffer
, &FvImageInfo
);
919 // Install FvPpi and Build FvHob
921 PiLibInstallFvInfoPpi (
924 (UINT32
) FvImageInfo
.FvSize
,
925 &(FvImageInfo
.FvName
),
926 &(((EFI_FFS_FILE_HEADER
*)FvFileHandle
)->Name
)
930 // Inform HOB consumer phase, i.e. DXE core, the existance of this FV
933 (EFI_PHYSICAL_ADDRESS
) (UINTN
) FvImageInfo
.FvStart
,
937 // Makes the encapsulated volume show up in DXE phase to skip processing of
938 // encapsulated file again.
941 (EFI_PHYSICAL_ADDRESS
) (UINTN
) FvImageInfo
.FvStart
,
944 &(((EFI_FFS_FILE_HEADER
*)FvFileHandle
)->Name
)