2 EFI PEI Core dispatch services
4 Copyright (c) 2006 - 2009, 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 /// temporary memory 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 CoreFileHandle The instance of PEI_CORE_FV_HANDLE.
38 DiscoverPeimsAndOrderWithApriori (
39 IN PEI_CORE_INSTANCE
*Private
,
40 IN PEI_CORE_FV_HANDLE
*CoreFileHandle
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
)];
54 EFI_PEI_FIRMWARE_VOLUME_PPI
*FvPpi
;
55 EFI_FV_FILE_INFO FileInfo
;
57 FvPpi
= CoreFileHandle
->FvPpi
;
60 // Walk the FV and find all the PEIMs and the Apriori file.
62 AprioriFileHandle
= NULL
;
63 Private
->CurrentFvFileHandles
[0] = NULL
;
68 // If the current Fv has been scanned, directly get its cachable record.
70 if (Private
->Fv
[Private
->CurrentPeimFvCount
].ScanFv
) {
71 CopyMem (Private
->CurrentFvFileHandles
, Private
->Fv
[Private
->CurrentPeimFvCount
].FvFileHandles
, sizeof (Private
->CurrentFvFileHandles
));
76 // Go ahead to scan this Fv, and cache FileHandles within it.
78 for (PeimCount
= 0; PeimCount
< FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv
); PeimCount
++) {
79 Status
= FvPpi
->FindFileByType (FvPpi
, PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE
, CoreFileHandle
->FvHandle
, &FileHandle
);
80 if (Status
!= EFI_SUCCESS
) {
84 Private
->CurrentFvFileHandles
[PeimCount
] = FileHandle
;
88 // Check whether the count of Peims exceeds the max support PEIMs in a FV image
89 // If more Peims are required in a FV image, PcdPeiCoreMaxPeimPerFv can be set to a larger value in DSC file.
91 ASSERT (PeimCount
< FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv
));
94 // Get Apriori File handle
96 Private
->AprioriCount
= 0;
97 Status
= FvPpi
->FindFileByName (FvPpi
, &gPeiAprioriFileNameGuid
, &CoreFileHandle
->FvHandle
, &AprioriFileHandle
);
98 if (!EFI_ERROR(Status
) && AprioriFileHandle
!= NULL
) {
100 // Read the Apriori file
102 Status
= FvPpi
->FindSectionByType (FvPpi
, EFI_SECTION_RAW
, AprioriFileHandle
, (VOID
**) &Apriori
);
103 if (!EFI_ERROR (Status
)) {
105 // Calculate the number of PEIMs in the A Priori list
107 Status
= FvPpi
->GetFileInfo (FvPpi
, AprioriFileHandle
, &FileInfo
);
108 ASSERT_EFI_ERROR (Status
);
109 Private
->AprioriCount
= FileInfo
.BufferSize
& 0x00FFFFFF;
110 Private
->AprioriCount
-= sizeof (EFI_COMMON_SECTION_HEADER
);
111 Private
->AprioriCount
/= sizeof (EFI_GUID
);
113 ZeroMem (FileGuid
, sizeof (FileGuid
));
114 for (Index
= 0; Index
< PeimCount
; Index
++) {
116 // Make an array of file name guids that matches the FileHandle array so we can convert
117 // quickly from file name to file handle
119 Status
= FvPpi
->GetFileInfo (FvPpi
, Private
->CurrentFvFileHandles
[Index
], &FileInfo
);
120 CopyMem (&FileGuid
[Index
], &FileInfo
.FileName
, sizeof(EFI_GUID
));
124 // Walk through FileGuid array to find out who is invalid PEIM guid in Apriori file.
125 // Add avalible PEIMs in Apriori file into TempFileHandles array at first.
128 for (Index
= 0; Index2
< Private
->AprioriCount
; Index
++) {
129 while (Index2
< Private
->AprioriCount
) {
130 Guid
= ScanGuid (FileGuid
, PeimCount
* sizeof (EFI_GUID
), &Apriori
[Index2
++]);
138 PeimIndex
= ((UINTN
)Guid
- (UINTN
)&FileGuid
[0])/sizeof (EFI_GUID
);
139 TempFileHandles
[Index
] = Private
->CurrentFvFileHandles
[PeimIndex
];
142 // Since we have copied the file handle we can remove it from this list.
144 Private
->CurrentFvFileHandles
[PeimIndex
] = NULL
;
148 // Update valid Aprioricount
150 Private
->AprioriCount
= Index
;
153 // Add in any PEIMs not in the Apriori file
155 for (;Index
< PeimCount
; Index
++) {
156 for (Index2
= 0; Index2
< PeimCount
; Index2
++) {
157 if (Private
->CurrentFvFileHandles
[Index2
] != NULL
) {
158 TempFileHandles
[Index
] = Private
->CurrentFvFileHandles
[Index2
];
159 Private
->CurrentFvFileHandles
[Index2
] = NULL
;
165 //Index the end of array contains re-range Pei moudle.
167 TempFileHandles
[Index
] = NULL
;
170 // Private->CurrentFvFileHandles is currently in PEIM in the FV order.
171 // We need to update it to start with files in the A Priori list and
172 // then the remaining files in PEIM order.
174 CopyMem (Private
->CurrentFvFileHandles
, TempFileHandles
, sizeof (Private
->CurrentFvFileHandles
));
178 // Cache the current Fv File Handle. So that we don't have to scan the Fv again.
179 // Instead, we can retrieve the file handles within this Fv from cachable data.
181 Private
->Fv
[Private
->CurrentPeimFvCount
].ScanFv
= TRUE
;
182 CopyMem (Private
->Fv
[Private
->CurrentPeimFvCount
].FvFileHandles
, Private
->CurrentFvFileHandles
, sizeof (Private
->CurrentFvFileHandles
));
187 Shadow PeiCore module from flash to installed memory.
189 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
190 @param PrivateInMem PeiCore's private data structure
192 @return PeiCore function address after shadowing.
196 IN CONST EFI_PEI_SERVICES
**PeiServices
,
197 IN PEI_CORE_INSTANCE
*PrivateInMem
200 EFI_PEI_FILE_HANDLE PeiCoreFileHandle
;
201 EFI_PHYSICAL_ADDRESS EntryPoint
;
203 UINT32 AuthenticationState
;
205 PeiCoreFileHandle
= NULL
;
208 // Find the PEI Core in the BFV
210 Status
= PrivateInMem
->Fv
[0].FvPpi
->FindFileByType (
211 PrivateInMem
->Fv
[0].FvPpi
,
212 EFI_FV_FILETYPE_PEI_CORE
,
213 PrivateInMem
->Fv
[0].FvHandle
,
216 ASSERT_EFI_ERROR (Status
);
219 // Shadow PEI Core into memory so it will run faster
221 Status
= PeiLoadImage (
223 *((EFI_PEI_FILE_HANDLE
*)&PeiCoreFileHandle
),
227 ASSERT_EFI_ERROR (Status
);
230 // Compute the PeiCore's function address after shaowed PeiCore.
231 // _ModuleEntryPoint is PeiCore main function entry
233 return (VOID
*) ((UINTN
) EntryPoint
+ (UINTN
) PeiCore
- (UINTN
) _ModuleEntryPoint
);
237 Conduct PEIM dispatch.
239 @param SecCoreData Points to a data structure containing information about the PEI core's operating
240 environment, such as the size and location of temporary RAM, the stack location and
242 @param Private Pointer to the private data passed in from caller
247 IN CONST EFI_SEC_PEI_HAND_OFF
*SecCoreData
,
248 IN PEI_CORE_INSTANCE
*Private
254 CONST EFI_PEI_SERVICES
**PeiServices
;
255 EFI_PEI_FILE_HANDLE PeimFileHandle
;
258 UINT32 AuthenticationState
;
259 EFI_PHYSICAL_ADDRESS EntryPoint
;
260 EFI_PEIM_ENTRY_POINT2 PeimEntryPoint
;
261 UINTN SaveCurrentPeimCount
;
262 UINTN SaveCurrentFvCount
;
263 EFI_PEI_FILE_HANDLE SaveCurrentFileHandle
;
264 PEIM_FILE_HANDLE_EXTENDED_DATA ExtendedData
;
265 EFI_PHYSICAL_ADDRESS NewPermenentMemoryBase
;
266 TEMPORARY_RAM_SUPPORT_PPI
*TemporaryRamSupportPpi
;
267 EFI_HOB_HANDOFF_INFO_TABLE
*OldHandOffTable
;
268 EFI_HOB_HANDOFF_INFO_TABLE
*NewHandOffTable
;
271 PEI_CORE_INSTANCE
*PrivateInMem
;
272 UINT64 NewPeiStackSize
;
273 UINT64 OldPeiStackSize
;
275 EFI_FV_FILE_INFO FvFileInfo
;
276 UINTN OldCheckingTop
;
277 UINTN OldCheckingBottom
;
278 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
280 PeiServices
= (CONST EFI_PEI_SERVICES
**) &Private
->PS
;
281 PeimEntryPoint
= NULL
;
282 PeimFileHandle
= NULL
;
285 if ((Private
->PeiMemoryInstalled
) && (Private
->HobList
.HandoffInformationTable
->BootMode
!= BOOT_ON_S3_RESUME
)) {
287 // Once real memory is available, shadow the RegisterForShadow modules. And meanwhile
288 // update the modules' status from PEIM_STATE_REGISITER_FOR_SHADOW to PEIM_STATE_DONE.
290 SaveCurrentPeimCount
= Private
->CurrentPeimCount
;
291 SaveCurrentFvCount
= Private
->CurrentPeimFvCount
;
292 SaveCurrentFileHandle
= Private
->CurrentFileHandle
;
294 for (Index1
= 0; Index1
<= SaveCurrentFvCount
; Index1
++) {
295 for (Index2
= 0; (Index2
< FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv
)) && (Private
->Fv
[Index1
].FvFileHandles
[Index2
] != NULL
); Index2
++) {
296 if (Private
->Fv
[Index1
].PeimState
[Index2
] == PEIM_STATE_REGISITER_FOR_SHADOW
) {
297 PeimFileHandle
= Private
->Fv
[Index1
].FvFileHandles
[Index2
];
298 Status
= PeiLoadImage (
299 (CONST EFI_PEI_SERVICES
**) &Private
->PS
,
304 if (Status
== EFI_SUCCESS
) {
306 // PEIM_STATE_REGISITER_FOR_SHADOW move to PEIM_STATE_DONE
308 Private
->Fv
[Index1
].PeimState
[Index2
]++;
309 Private
->CurrentFileHandle
= PeimFileHandle
;
310 Private
->CurrentPeimFvCount
= Index1
;
311 Private
->CurrentPeimCount
= Index2
;
313 // Call the PEIM entry point
315 PeimEntryPoint
= (EFI_PEIM_ENTRY_POINT2
)(UINTN
)EntryPoint
;
317 PERF_START (0, "PEIM", NULL
, 0);
318 PeimEntryPoint(PeimFileHandle
, (const EFI_PEI_SERVICES
**) &Private
->PS
);
319 PERF_END (0, "PEIM", NULL
, 0);
323 // Process the Notify list and dispatch any notifies for
324 // newly installed PPIs.
326 ProcessNotifyList (Private
);
330 Private
->CurrentFileHandle
= SaveCurrentFileHandle
;
331 Private
->CurrentPeimFvCount
= SaveCurrentFvCount
;
332 Private
->CurrentPeimCount
= SaveCurrentPeimCount
;
336 // This is the main dispatch loop. It will search known FVs for PEIMs and
337 // attempt to dispatch them. If any PEIM gets dispatched through a single
338 // pass of the dispatcher, it will start over from the Bfv again to see
339 // if any new PEIMs dependencies got satisfied. With a well ordered
340 // FV where PEIMs are found in the order their dependencies are also
341 // satisfied, this dipatcher should run only once.
345 // In case that reenter PeiCore happens, the last pass record is still available.
347 if (!Private
->PeimDispatcherReenter
) {
348 Private
->PeimNeedingDispatch
= FALSE
;
349 Private
->PeimDispatchOnThisPass
= FALSE
;
351 Private
->PeimDispatcherReenter
= FALSE
;
354 for (FvCount
= Private
->CurrentPeimFvCount
; FvCount
< Private
->FvCount
; FvCount
++) {
355 CoreFvHandle
= FindNextCoreFvHandle (Private
, FvCount
);
356 ASSERT (CoreFvHandle
!= NULL
);
359 // If the FV has corresponding EFI_PEI_FIRMWARE_VOLUME_PPI instance, then dispatch it.
361 if (CoreFvHandle
->FvPpi
== NULL
) {
365 Private
->CurrentPeimFvCount
= FvCount
;
367 if (Private
->CurrentPeimCount
== 0) {
369 // When going through each FV, at first, search Apriori file to
370 // reorder all PEIMs to ensure the PEIMs in Apriori file to get
371 // dispatch at first.
373 DiscoverPeimsAndOrderWithApriori (Private
, CoreFvHandle
);
377 // Start to dispatch all modules within the current Fv.
379 for (PeimCount
= Private
->CurrentPeimCount
;
380 (PeimCount
< FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv
)) && (Private
->CurrentFvFileHandles
[PeimCount
] != NULL
);
382 Private
->CurrentPeimCount
= PeimCount
;
383 PeimFileHandle
= Private
->CurrentFileHandle
= Private
->CurrentFvFileHandles
[PeimCount
];
385 if (Private
->Fv
[FvCount
].PeimState
[PeimCount
] == PEIM_STATE_NOT_DISPATCHED
) {
386 if (!DepexSatisfied (Private
, PeimFileHandle
, PeimCount
)) {
387 Private
->PeimNeedingDispatch
= TRUE
;
389 Status
= CoreFvHandle
->FvPpi
->GetFileInfo (CoreFvHandle
->FvPpi
, PeimFileHandle
, &FvFileInfo
);
390 ASSERT_EFI_ERROR (Status
);
391 if (FvFileInfo
.FileType
== EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
) {
393 // For Fv type file, Produce new FV PPI and FV hob
395 Status
= ProcessFvFile (&Private
->Fv
[FvCount
], PeimFileHandle
);
396 AuthenticationState
= 0;
399 // For PEIM driver, Load its entry point
401 Status
= PeiLoadImage (
409 if ((Status
== EFI_SUCCESS
)) {
411 // The PEIM has its dependencies satisfied, and its entry point
412 // has been found, so invoke it.
414 PERF_START (0, "PEIM", NULL
, 0);
416 ExtendedData
.Handle
= (EFI_HANDLE
)PeimFileHandle
;
418 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (
420 FixedPcdGet32(PcdStatusCodeValuePeimDispatch
),
421 (VOID
*)(&ExtendedData
),
422 sizeof (ExtendedData
)
425 Status
= VerifyPeim (Private
, CoreFvHandle
->FvHandle
, PeimFileHandle
);
426 if (Status
!= EFI_SECURITY_VIOLATION
&& (AuthenticationState
== 0)) {
428 // PEIM_STATE_NOT_DISPATCHED move to PEIM_STATE_DISPATCHED
430 Private
->Fv
[FvCount
].PeimState
[PeimCount
]++;
432 if (FvFileInfo
.FileType
!= EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
) {
434 // Call the PEIM entry point for PEIM driver
436 PeimEntryPoint
= (EFI_PEIM_ENTRY_POINT2
)(UINTN
)EntryPoint
;
437 PeimEntryPoint (PeimFileHandle
, (const EFI_PEI_SERVICES
**) PeiServices
);
440 Private
->PeimDispatchOnThisPass
= TRUE
;
443 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (
445 FixedPcdGet32(PcdStatusCodeValuePeimDispatch
),
446 (VOID
*)(&ExtendedData
),
447 sizeof (ExtendedData
)
449 PERF_END (0, "PEIM", NULL
, 0);
453 if (Private
->SwitchStackSignal
) {
455 // Before switch stack from temporary memory to permenent memory, caculate the heap and stack
456 // usage in temporary memory for debuging.
459 UINT32
*StackPointer
;
461 for (StackPointer
= (UINT32
*)SecCoreData
->StackBase
;
462 (StackPointer
< (UINT32
*)((UINTN
)SecCoreData
->StackBase
+ SecCoreData
->StackSize
)) \
463 && (*StackPointer
== INIT_CAR_VALUE
);
466 DEBUG ((EFI_D_INFO
, "Total temporary memory: %d bytes.\n", (UINT32
)SecCoreData
->TemporaryRamSize
));
467 DEBUG ((EFI_D_INFO
, " temporary memory stack ever used: %d bytes.\n",
468 (SecCoreData
->StackSize
- ((UINTN
) StackPointer
- (UINTN
)SecCoreData
->StackBase
))
470 DEBUG ((EFI_D_INFO
, " temporary memory heap used: %d bytes.\n",
471 ((UINTN
) Private
->HobList
.HandoffInformationTable
->EfiFreeMemoryBottom
-
472 (UINTN
) Private
->HobList
.Raw
)
477 // Reserve the size of new stack at bottom of physical memory
479 OldPeiStackSize
= (UINT64
) SecCoreData
->StackSize
;
480 NewPeiStackSize
= (RShiftU64 (Private
->PhysicalMemoryLength
, 1) + EFI_PAGE_MASK
) & ~EFI_PAGE_MASK
;
481 if (FixedPcdGet32(PcdPeiCoreMaxPeiStackSize
) > (UINT32
) NewPeiStackSize
) {
482 Private
->StackSize
= NewPeiStackSize
;
484 Private
->StackSize
= FixedPcdGet32(PcdPeiCoreMaxPeiStackSize
);
488 // In theory, the size of new stack in permenent memory should large than
489 // size of old stack in temporary memory.
490 // But if new stack is smaller than the size of old stack, we also reserve
491 // the size of old stack at bottom of permenent memory.
493 DEBUG ((EFI_D_INFO
, "Old Stack size %d, New stack size %d\n", (INT32
) OldPeiStackSize
, (INT32
) Private
->StackSize
));
494 ASSERT (Private
->StackSize
>= OldPeiStackSize
);
495 StackGap
= Private
->StackSize
- OldPeiStackSize
;
498 // Update HandOffHob for new installed permenent memory
500 OldHandOffTable
= Private
->HobList
.HandoffInformationTable
;
501 OldCheckingBottom
= (UINTN
)(SecCoreData
->TemporaryRamBase
);
502 OldCheckingTop
= (UINTN
)(OldCheckingBottom
+ SecCoreData
->TemporaryRamSize
);
505 // The whole temporary memory will be migrated to physical memory.
506 // CAUTION: The new base is computed accounding to gap of new stack.
508 NewPermenentMemoryBase
= Private
->PhysicalMemoryBegin
+ StackGap
;
511 // Caculate stack offset and heap offset between temporary memory and new permement
512 // memory seperately.
514 StackOffset
= (UINTN
) NewPermenentMemoryBase
- (UINTN
) SecCoreData
->StackBase
;
515 HeapOffset
= (INTN
) ((UINTN
) Private
->PhysicalMemoryBegin
+ Private
->StackSize
- \
516 (UINTN
) SecCoreData
->PeiTemporaryRamBase
);
517 DEBUG ((EFI_D_INFO
, "Heap Offset = 0x%lX Stack Offset = 0x%lX\n", (INT64
)HeapOffset
, (INT64
)StackOffset
));
520 // Caculate new HandOffTable and PrivateData address in permenet memory's stack
522 NewHandOffTable
= (EFI_HOB_HANDOFF_INFO_TABLE
*)((UINTN
)OldHandOffTable
+ HeapOffset
);
523 PrivateInMem
= (PEI_CORE_INSTANCE
*)((UINTN
) (VOID
*) Private
+ StackOffset
);
526 // TemporaryRamSupportPpi is produced by platform's SEC
528 Status
= PeiLocatePpi (
529 (CONST EFI_PEI_SERVICES
**) PeiServices
,
530 &gEfiTemporaryRamSupportPpiGuid
,
533 (VOID
**)&TemporaryRamSupportPpi
537 if (!EFI_ERROR (Status
)) {
539 // Temporary Ram support Ppi is provided by platform, it will copy
540 // temporary memory to permenent memory and do stack switching.
541 // After invoken temporary Ram support, following code's stack is in
542 // memory but not in temporary memory.
544 TemporaryRamSupportPpi
->TemporaryRamMigration (
545 (CONST EFI_PEI_SERVICES
**) PeiServices
,
546 (EFI_PHYSICAL_ADDRESS
)(UINTN
) SecCoreData
->TemporaryRamBase
,
547 (EFI_PHYSICAL_ADDRESS
)(UINTN
) NewPermenentMemoryBase
,
548 SecCoreData
->TemporaryRamSize
553 // In IA32/x64/Itanium architecture, we need platform provide
554 // TEMPORAY_RAM_MIGRATION_PPI.
562 // Fixup the PeiCore's private data
564 PrivateInMem
->PS
= &PrivateInMem
->ServiceTableShadow
;
565 PrivateInMem
->CpuIo
= &PrivateInMem
->ServiceTableShadow
.CpuIo
;
566 PrivateInMem
->HobList
.Raw
= (VOID
*) ((UINTN
) PrivateInMem
->HobList
.Raw
+ HeapOffset
);
567 PrivateInMem
->StackBase
= (EFI_PHYSICAL_ADDRESS
)(((UINTN
)PrivateInMem
->PhysicalMemoryBegin
+ EFI_PAGE_MASK
) & ~EFI_PAGE_MASK
);
569 PeiServices
= (CONST EFI_PEI_SERVICES
**) &PrivateInMem
->PS
;
572 // Fixup for PeiService's address
574 SetPeiServicesTablePointer(PeiServices
);
577 // Update HandOffHob for new installed permenent memory
579 NewHandOffTable
->EfiEndOfHobList
=
580 (EFI_PHYSICAL_ADDRESS
)((UINTN
) NewHandOffTable
->EfiEndOfHobList
+ HeapOffset
);
581 NewHandOffTable
->EfiMemoryTop
= PrivateInMem
->PhysicalMemoryBegin
+
582 PrivateInMem
->PhysicalMemoryLength
;
583 NewHandOffTable
->EfiMemoryBottom
= PrivateInMem
->PhysicalMemoryBegin
;
584 NewHandOffTable
->EfiFreeMemoryTop
= PrivateInMem
->FreePhysicalMemoryTop
;
585 NewHandOffTable
->EfiFreeMemoryBottom
= NewHandOffTable
->EfiEndOfHobList
+
586 sizeof (EFI_HOB_GENERIC_HEADER
);
589 // We need convert the PPI desciptor's pointer
591 ConvertPpiPointers (PrivateInMem
,
597 DEBUG ((EFI_D_INFO
, "Stack Hob: BaseAddress=0x%lX Length=0x%lX\n",
598 PrivateInMem
->StackBase
,
599 PrivateInMem
->StackSize
));
600 BuildStackHob (PrivateInMem
->StackBase
, PrivateInMem
->StackSize
);
603 // After the whole temporary memory is migrated, then we can allocate page in
606 PrivateInMem
->PeiMemoryInstalled
= TRUE
;
609 // Indicate that PeiCore reenter
611 PrivateInMem
->PeimDispatcherReenter
= TRUE
;
614 // Shadow PEI Core. When permanent memory is avaiable, shadow
615 // PEI Core and PEIMs to get high performance.
617 PrivateInMem
->ShadowedPeiCore
= ShadowPeiCore (
622 // Process the Notify list and dispatch any notifies for
623 // newly installed PPIs.
625 ProcessNotifyList (PrivateInMem
);
630 PeiCore (SecCoreData
, NULL
, PrivateInMem
);
633 // Code should not come here
635 ASSERT_EFI_ERROR(FALSE
);
639 // Process the Notify list and dispatch any notifies for
640 // newly installed PPIs.
642 ProcessNotifyList (Private
);
644 if ((Private
->PeiMemoryInstalled
) && (Private
->Fv
[FvCount
].PeimState
[PeimCount
] == PEIM_STATE_REGISITER_FOR_SHADOW
) && \
645 (Private
->HobList
.HandoffInformationTable
->BootMode
!= BOOT_ON_S3_RESUME
)) {
647 // If memory is availble we shadow images by default for performance reasons.
648 // We call the entry point a 2nd time so the module knows it's shadowed.
650 //PERF_START (PeiServices, L"PEIM", PeimFileHandle, 0);
651 ASSERT (PeimEntryPoint
!= NULL
);
652 PeimEntryPoint (PeimFileHandle
, (const EFI_PEI_SERVICES
**) PeiServices
);
653 //PERF_END (PeiServices, L"PEIM", PeimFileHandle, 0);
656 // PEIM_STATE_REGISITER_FOR_SHADOW move to PEIM_STATE_DONE
658 Private
->Fv
[FvCount
].PeimState
[PeimCount
]++;
661 // Process the Notify list and dispatch any notifies for
662 // newly installed PPIs.
664 ProcessNotifyList (Private
);
671 // We set to NULL here to optimize the 2nd entry to this routine after
672 // memory is found. This reprevents rescanning of the FV. We set to
673 // NULL here so we start at the begining of the next FV
675 Private
->CurrentFileHandle
= NULL
;
676 Private
->CurrentPeimCount
= 0;
678 // Before walking through the next FV,Private->CurrentFvFileHandles[]should set to NULL
680 SetMem (Private
->CurrentFvFileHandles
, sizeof (Private
->CurrentFvFileHandles
), 0);
684 // Before making another pass, we should set Private->CurrentPeimFvCount =0 to go
685 // through all the FV.
687 Private
->CurrentPeimFvCount
= 0;
690 // PeimNeedingDispatch being TRUE means we found a PEIM that did not get
691 // dispatched. So we need to make another pass
693 // PeimDispatchOnThisPass being TRUE means we dispatched a PEIM on this
694 // pass. If we did not dispatch a PEIM there is no point in trying again
695 // as it will fail the next time too (nothing has changed).
697 } while (Private
->PeimNeedingDispatch
&& Private
->PeimDispatchOnThisPass
);
702 Initialize the Dispatcher's data members
704 @param PrivateData PeiCore's private data structure
705 @param OldCoreData Old data from SecCore
706 NULL if being run in non-permament memory mode.
707 @param SecCoreData Points to a data structure containing information about the PEI core's operating
708 environment, such as the size and location of temporary RAM, the stack location and
715 InitializeDispatcherData (
716 IN PEI_CORE_INSTANCE
*PrivateData
,
717 IN PEI_CORE_INSTANCE
*OldCoreData
,
718 IN CONST EFI_SEC_PEI_HAND_OFF
*SecCoreData
721 if (OldCoreData
== NULL
) {
722 PrivateData
->PeimDispatcherReenter
= FALSE
;
723 PeiInitializeFv (PrivateData
, SecCoreData
);
725 PeiReinitializeFv (PrivateData
);
732 This routine parses the Dependency Expression, if available, and
733 decides if the module can be executed.
736 @param Private PeiCore's private data structure
737 @param FileHandle PEIM's file handle
738 @param PeimCount Peim count in all dispatched PEIMs.
740 @retval TRUE Can be dispatched
741 @retval FALSE Cannot be dispatched
746 IN PEI_CORE_INSTANCE
*Private
,
747 IN EFI_PEI_FILE_HANDLE FileHandle
,
754 if (PeimCount
< Private
->AprioriCount
) {
756 // If its in the A priori file then we set Depex to TRUE
762 // Depex section not in the encapsulated section.
764 Status
= PeiServicesFfsFindSectionData (
765 EFI_SECTION_PEI_DEPEX
,
770 if (EFI_ERROR (Status
)) {
772 // If there is no DEPEX, assume the module can be executed
778 // Evaluate a given DEPEX
780 return PeimDispatchReadiness (&Private
->PS
, DepexData
);
784 This routine enable a PEIM to register itself to shadow when PEI Foundation
785 discovery permanent memory.
787 @param FileHandle File handle of a PEIM.
789 @retval EFI_NOT_FOUND The file handle doesn't point to PEIM itself.
790 @retval EFI_ALREADY_STARTED Indicate that the PEIM has been registered itself.
791 @retval EFI_SUCCESS Successfully to register itself.
796 PeiRegisterForShadow (
797 IN EFI_PEI_FILE_HANDLE FileHandle
800 PEI_CORE_INSTANCE
*Private
;
801 Private
= PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer ());
803 if (Private
->CurrentFileHandle
!= FileHandle
) {
805 // The FileHandle must be for the current PEIM
807 return EFI_NOT_FOUND
;
810 if (Private
->Fv
[Private
->CurrentPeimFvCount
].PeimState
[Private
->CurrentPeimCount
] >= PEIM_STATE_REGISITER_FOR_SHADOW
) {
812 // If the PEIM has already entered the PEIM_STATE_REGISTER_FOR_SHADOW or PEIM_STATE_DONE then it's already been started
814 return EFI_ALREADY_STARTED
;
817 Private
->Fv
[Private
->CurrentPeimFvCount
].PeimState
[Private
->CurrentPeimCount
] = PEIM_STATE_REGISITER_FOR_SHADOW
;