2 EFI PEI Core dispatch services
4 Copyright (c) 2006 - 2010, 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
),
224 PEIM_STATE_REGISITER_FOR_SHADOW
,
228 ASSERT_EFI_ERROR (Status
);
231 // Compute the PeiCore's function address after shaowed PeiCore.
232 // _ModuleEntryPoint is PeiCore main function entry
234 return (VOID
*) ((UINTN
) EntryPoint
+ (UINTN
) PeiCore
- (UINTN
) _ModuleEntryPoint
);
237 // This is the minimum memory required by DxeCore initialization. When LMFA feature enabled,
238 // This part of memory still need reserved on the very top of memory so that the DXE Core could
239 // use these memory for data initialization. This macro should be sync with the same marco
240 // defined in DXE Core.
242 #define MINIMUM_INITIAL_MEMORY_SIZE 0x10000
244 This function is to test if the memory range described in resource HOB is available or not.
246 This function should only be invoked when Loading Module at Fixed Address(LMFA) feature is enabled. Some platform may allocate the
247 memory before PeiLoadFixAddressHook in invoked. so this function is to test if the memory range described by the input resource HOB is
250 @param PrivateData Pointer to the private data passed in from caller
251 @param ResourceHob Pointer to a resource HOB which described the memory range described by the input resource HOB
254 PeiLoadFixAddressIsMemoryRangeAvailable (
255 IN PEI_CORE_INSTANCE
*PrivateData
,
256 IN EFI_HOB_RESOURCE_DESCRIPTOR
*ResourceHob
259 EFI_HOB_MEMORY_ALLOCATION
*MemoryHob
;
261 EFI_PEI_HOB_POINTERS Hob
;
264 if (PrivateData
== NULL
|| ResourceHob
== NULL
) {
268 // test if the memory range describe in the HOB is already allocated.
270 for (Hob
.Raw
= PrivateData
->HobList
.Raw
; !END_OF_HOB_LIST(Hob
); Hob
.Raw
= GET_NEXT_HOB(Hob
)) {
272 // See if this is a memory allocation HOB
274 if (GET_HOB_TYPE (Hob
) == EFI_HOB_TYPE_MEMORY_ALLOCATION
) {
275 MemoryHob
= Hob
.MemoryAllocation
;
276 if(MemoryHob
->AllocDescriptor
.MemoryBaseAddress
== ResourceHob
->PhysicalStart
&&
277 MemoryHob
->AllocDescriptor
.MemoryBaseAddress
+ MemoryHob
->AllocDescriptor
.MemoryLength
== ResourceHob
->PhysicalStart
+ ResourceHob
->ResourceLength
) {
288 Hook function for Loading Module at Fixed Address feature
290 This function should only be invoked when Loading Module at Fixed Address(LMFA) feature is enabled. When feature is
291 configured as Load Modules at Fix Absolute Address, this function is to validate the top address assigned by user. When
292 feature is configured as Load Modules at Fixed Offset, the functino is to find the top address which is TOLM-TSEG in general.
293 And also the function will re-install PEI memory.
295 @param PrivateData Pointer to the private data passed in from caller
299 PeiLoadFixAddressHook(
300 IN PEI_CORE_INSTANCE
*PrivateData
303 EFI_PHYSICAL_ADDRESS TopLoadingAddress
;
304 UINT64 PeiMemorySize
;
305 UINT64 TotalReservedMemorySize
;
306 UINT64 MemoryRangeEnd
;
307 EFI_PHYSICAL_ADDRESS HighAddress
;
308 EFI_HOB_RESOURCE_DESCRIPTOR
*ResourceHob
;
309 EFI_HOB_RESOURCE_DESCRIPTOR
*NextResourceHob
;
310 EFI_HOB_RESOURCE_DESCRIPTOR
*CurrentResourceHob
;
311 EFI_PEI_HOB_POINTERS CurrentHob
;
312 EFI_PEI_HOB_POINTERS Hob
;
313 EFI_PEI_HOB_POINTERS NextHob
;
314 EFI_PHYSICAL_ADDRESS MaxMemoryBaseAddress
;
315 UINT64 MaxMemoryLength
;
316 EFI_HOB_MEMORY_ALLOCATION
*MemoryHob
;
318 // Initialize Local Variables
320 CurrentResourceHob
= NULL
;
322 NextResourceHob
= NULL
;
323 MaxMemoryBaseAddress
= 0;
326 TopLoadingAddress
= 0;
328 CurrentHob
.Raw
= PrivateData
->HobList
.Raw
;
329 PeiMemorySize
= PrivateData
->PhysicalMemoryLength
;
331 // The top reserved memory include 3 parts: the topest range is for DXE core initialization with the size MINIMUM_INITIAL_MEMORY_SIZE
332 // then RuntimeCodePage range and Boot time code range.
334 TotalReservedMemorySize
= MINIMUM_INITIAL_MEMORY_SIZE
+ EFI_PAGES_TO_SIZE(PcdGet32(PcdLoadFixAddressRuntimeCodePageNumber
));
335 TotalReservedMemorySize
+= EFI_PAGES_TO_SIZE(PcdGet32(PcdLoadFixAddressBootTimeCodePageNumber
)) ;
337 // PEI memory range lies below the top reserved memory
339 TotalReservedMemorySize
+= PeiMemorySize
;
341 DEBUG ((EFI_D_INFO
, "LOADING MODULE FIXED INFO: PcdLoadFixAddressRuntimeCodePageNumber= 0x%x.\n", PcdGet32(PcdLoadFixAddressRuntimeCodePageNumber
)));
342 DEBUG ((EFI_D_INFO
, "LOADING MODULE FIXED INFO: PcdLoadFixAddressBootTimeCodePageNumber= 0x%x.\n", PcdGet32(PcdLoadFixAddressBootTimeCodePageNumber
)));
343 DEBUG ((EFI_D_INFO
, "LOADING MODULE FIXED INFO: PcdLoadFixAddressPeiCodePageNumber= 0x%x.\n", PcdGet32(PcdLoadFixAddressPeiCodePageNumber
)));
344 DEBUG ((EFI_D_INFO
, "LOADING MODULE FIXED INFO: Total Reserved Memory Size = 0x%lx.\n", TotalReservedMemorySize
));
346 // Loop through the system memory typed hob to merge the adjacent memory range
348 for (Hob
.Raw
= PrivateData
->HobList
.Raw
; !END_OF_HOB_LIST(Hob
); Hob
.Raw
= GET_NEXT_HOB(Hob
)) {
350 // See if this is a resource descriptor HOB
352 if (GET_HOB_TYPE (Hob
) == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR
) {
354 ResourceHob
= Hob
.ResourceDescriptor
;
356 // If range described in this hob is not system memory or heigher than MAX_ADDRESS, ignored.
358 if (ResourceHob
->ResourceType
!= EFI_RESOURCE_SYSTEM_MEMORY
&&
359 ResourceHob
->PhysicalStart
+ ResourceHob
->ResourceLength
> MAX_ADDRESS
) {
363 for (NextHob
.Raw
= PrivateData
->HobList
.Raw
; !END_OF_HOB_LIST(NextHob
); NextHob
.Raw
= GET_NEXT_HOB(NextHob
)) {
364 if (NextHob
.Raw
== Hob
.Raw
){
368 // See if this is a resource descriptor HOB
370 if (GET_HOB_TYPE (NextHob
) == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR
) {
372 NextResourceHob
= NextHob
.ResourceDescriptor
;
374 // test if range described in this NextResourceHob is system memory and have the same attribute.
375 // Note: Here is a assumption that system memory should always be healthy even without test.
377 if (NextResourceHob
->ResourceType
== EFI_RESOURCE_SYSTEM_MEMORY
&&
378 (((NextResourceHob
->ResourceAttribute
^ResourceHob
->ResourceAttribute
)&(~EFI_RESOURCE_ATTRIBUTE_TESTED
)) == 0)){
381 // See if the memory range described in ResourceHob and NextResourceHob is adjacent
383 if ((ResourceHob
->PhysicalStart
<= NextResourceHob
->PhysicalStart
&&
384 ResourceHob
->PhysicalStart
+ ResourceHob
->ResourceLength
>= NextResourceHob
->PhysicalStart
)||
385 (ResourceHob
->PhysicalStart
>= NextResourceHob
->PhysicalStart
&&
386 ResourceHob
->PhysicalStart
<= NextResourceHob
->PhysicalStart
+ NextResourceHob
->ResourceLength
)) {
388 MemoryRangeEnd
= ((ResourceHob
->PhysicalStart
+ ResourceHob
->ResourceLength
)>(NextResourceHob
->PhysicalStart
+ NextResourceHob
->ResourceLength
)) ?
389 (ResourceHob
->PhysicalStart
+ ResourceHob
->ResourceLength
):(NextResourceHob
->PhysicalStart
+ NextResourceHob
->ResourceLength
);
391 ResourceHob
->PhysicalStart
= (ResourceHob
->PhysicalStart
< NextResourceHob
->PhysicalStart
) ?
392 ResourceHob
->PhysicalStart
: NextResourceHob
->PhysicalStart
;
395 ResourceHob
->ResourceLength
= (MemoryRangeEnd
- ResourceHob
->PhysicalStart
);
397 ResourceHob
->ResourceAttribute
= ResourceHob
->ResourceAttribute
& (~EFI_RESOURCE_ATTRIBUTE_TESTED
);
399 // Delete the NextResourceHob by marking it as unused.
401 GET_HOB_TYPE (NextHob
) = EFI_HOB_TYPE_UNUSED
;
410 // Some platform is already allocated pages before the HOB re-org. Here to build dedicated resource HOB to describe
411 // the allocated memory range
413 for (Hob
.Raw
= PrivateData
->HobList
.Raw
; !END_OF_HOB_LIST(Hob
); Hob
.Raw
= GET_NEXT_HOB(Hob
)) {
415 // See if this is a memory allocation HOB
417 if (GET_HOB_TYPE (Hob
) == EFI_HOB_TYPE_MEMORY_ALLOCATION
) {
418 MemoryHob
= Hob
.MemoryAllocation
;
419 for (NextHob
.Raw
= PrivateData
->HobList
.Raw
; !END_OF_HOB_LIST(NextHob
); NextHob
.Raw
= GET_NEXT_HOB(NextHob
)) {
421 // See if this is a resource descriptor HOB
423 if (GET_HOB_TYPE (NextHob
) == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR
) {
424 NextResourceHob
= NextHob
.ResourceDescriptor
;
426 // If range described in this hob is not system memory or heigher than MAX_ADDRESS, ignored.
428 if (NextResourceHob
->ResourceType
== EFI_RESOURCE_SYSTEM_MEMORY
&& NextResourceHob
->PhysicalStart
+ NextResourceHob
->ResourceLength
> MAX_ADDRESS
) {
432 // If the range describe in memory allocation HOB belongs to the memroy range described by the resource hob
434 if (MemoryHob
->AllocDescriptor
.MemoryBaseAddress
>= NextResourceHob
->PhysicalStart
&&
435 MemoryHob
->AllocDescriptor
.MemoryBaseAddress
+ MemoryHob
->AllocDescriptor
.MemoryLength
<= NextResourceHob
->PhysicalStart
+ NextResourceHob
->ResourceLength
) {
437 // Build seperate resource hob for this allocated range
439 if (MemoryHob
->AllocDescriptor
.MemoryBaseAddress
> NextResourceHob
->PhysicalStart
) {
440 BuildResourceDescriptorHob (
441 EFI_RESOURCE_SYSTEM_MEMORY
,
442 NextResourceHob
->ResourceAttribute
,
443 NextResourceHob
->PhysicalStart
,
444 (MemoryHob
->AllocDescriptor
.MemoryBaseAddress
- NextResourceHob
->PhysicalStart
)
447 if (MemoryHob
->AllocDescriptor
.MemoryBaseAddress
+ MemoryHob
->AllocDescriptor
.MemoryLength
< NextResourceHob
->PhysicalStart
+ NextResourceHob
->ResourceLength
) {
448 BuildResourceDescriptorHob (
449 EFI_RESOURCE_SYSTEM_MEMORY
,
450 NextResourceHob
->ResourceAttribute
,
451 MemoryHob
->AllocDescriptor
.MemoryBaseAddress
+ MemoryHob
->AllocDescriptor
.MemoryLength
,
452 (NextResourceHob
->PhysicalStart
+ NextResourceHob
->ResourceLength
-(MemoryHob
->AllocDescriptor
.MemoryBaseAddress
+ MemoryHob
->AllocDescriptor
.MemoryLength
))
455 NextResourceHob
->PhysicalStart
= MemoryHob
->AllocDescriptor
.MemoryBaseAddress
;
456 NextResourceHob
->ResourceLength
= MemoryHob
->AllocDescriptor
.MemoryLength
;
465 // Try to find and validate the TOP address.
467 if ((INT64
)PcdGet64(PcdLoadModuleAtFixAddressEnable
) > 0 ) {
469 // The LMFA feature is enabled as load module at fixed absolute address.
471 TopLoadingAddress
= (EFI_PHYSICAL_ADDRESS
)PcdGet64(PcdLoadModuleAtFixAddressEnable
);
472 DEBUG ((EFI_D_INFO
, "LOADING MODULE FIXED INFO: Loading module at fixed absolute address.\n"));
474 // validate the Address. Loop the resource descriptor HOB to make sure the address is in valid memory range
476 if ((TopLoadingAddress
& EFI_PAGE_MASK
) != 0) {
477 DEBUG ((EFI_D_INFO
, "LOADING MODULE FIXED ERROR:Top Address 0x%lx is invalid since top address should be page align. \n", TopLoadingAddress
));
481 // Search for a memory region that is below MAX_ADDRESS and in which TopLoadingAddress lies
483 for (Hob
.Raw
= PrivateData
->HobList
.Raw
; !END_OF_HOB_LIST(Hob
); Hob
.Raw
= GET_NEXT_HOB(Hob
)) {
485 // See if this is a resource descriptor HOB
487 if (GET_HOB_TYPE (Hob
) == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR
) {
489 ResourceHob
= Hob
.ResourceDescriptor
;
491 // See if this resource descrior HOB describes tested system memory below MAX_ADDRESS
493 if (ResourceHob
->ResourceType
== EFI_RESOURCE_SYSTEM_MEMORY
&&
494 ResourceHob
->PhysicalStart
+ ResourceHob
->ResourceLength
<= MAX_ADDRESS
) {
496 // See if Top address specified by user is valid.
498 if (ResourceHob
->PhysicalStart
+ TotalReservedMemorySize
< TopLoadingAddress
&&
499 (ResourceHob
->PhysicalStart
+ ResourceHob
->ResourceLength
- MINIMUM_INITIAL_MEMORY_SIZE
) >= TopLoadingAddress
&&
500 PeiLoadFixAddressIsMemoryRangeAvailable(PrivateData
, ResourceHob
)) {
501 CurrentResourceHob
= ResourceHob
;
508 if (CurrentResourceHob
!= NULL
) {
509 DEBUG ((EFI_D_INFO
, "LOADING MODULE FIXED INFO:Top Address 0x%lx is valid \n", TopLoadingAddress
));
510 TopLoadingAddress
+= MINIMUM_INITIAL_MEMORY_SIZE
;
512 DEBUG ((EFI_D_INFO
, "LOADING MODULE FIXED ERROR:Top Address 0x%lx is invalid \n", TopLoadingAddress
));
513 DEBUG ((EFI_D_INFO
, "LOADING MODULE FIXED ERROR:The recommended Top Address for the platform is: \n"));
515 // Print the recomended Top address range.
517 for (Hob
.Raw
= PrivateData
->HobList
.Raw
; !END_OF_HOB_LIST(Hob
); Hob
.Raw
= GET_NEXT_HOB(Hob
)) {
519 // See if this is a resource descriptor HOB
521 if (GET_HOB_TYPE (Hob
) == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR
) {
523 ResourceHob
= Hob
.ResourceDescriptor
;
525 // See if this resource descrior HOB describes tested system memory below MAX_ADDRESS
527 if (ResourceHob
->ResourceType
== EFI_RESOURCE_SYSTEM_MEMORY
&&
528 ResourceHob
->PhysicalStart
+ ResourceHob
->ResourceLength
<= MAX_ADDRESS
) {
530 // See if Top address specified by user is valid.
532 if (ResourceHob
->ResourceLength
> TotalReservedMemorySize
&& PeiLoadFixAddressIsMemoryRangeAvailable(PrivateData
, ResourceHob
)) {
533 DEBUG ((EFI_D_INFO
, "(0x%lx, 0x%lx)\n",
534 (ResourceHob
->PhysicalStart
+ TotalReservedMemorySize
-MINIMUM_INITIAL_MEMORY_SIZE
),
535 (ResourceHob
->PhysicalStart
+ ResourceHob
->ResourceLength
-MINIMUM_INITIAL_MEMORY_SIZE
)
549 // The LMFA feature is enabled as load module at fixed offset relative to TOLM
550 // Parse the Hob list to find the topest available memory. Generally it is (TOLM - TSEG)
553 // Search for a tested memory region that is below MAX_ADDRESS
555 for (Hob
.Raw
= PrivateData
->HobList
.Raw
; !END_OF_HOB_LIST(Hob
); Hob
.Raw
= GET_NEXT_HOB(Hob
)) {
557 // See if this is a resource descriptor HOB
559 if (GET_HOB_TYPE (Hob
) == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR
) {
561 ResourceHob
= Hob
.ResourceDescriptor
;
563 // See if this resource descrior HOB describes tested system memory below MAX_ADDRESS
565 if (ResourceHob
->ResourceType
== EFI_RESOURCE_SYSTEM_MEMORY
&&
566 ResourceHob
->PhysicalStart
+ ResourceHob
->ResourceLength
<= MAX_ADDRESS
&&
567 ResourceHob
->ResourceLength
> TotalReservedMemorySize
&& PeiLoadFixAddressIsMemoryRangeAvailable(PrivateData
, ResourceHob
)) {
569 // See if this is the highest largest system memory region below MaxAddress
571 if (ResourceHob
->PhysicalStart
> HighAddress
) {
572 CurrentResourceHob
= ResourceHob
;
574 HighAddress
= CurrentResourceHob
->PhysicalStart
;
579 if (CurrentResourceHob
== NULL
) {
580 DEBUG ((EFI_D_INFO
, "LOADING MODULE FIXED ERROR:The System Memory is too small\n"));
587 TopLoadingAddress
= CurrentResourceHob
->PhysicalStart
+ CurrentResourceHob
->ResourceLength
;
591 if (CurrentResourceHob
!= NULL
) {
593 // rebuild resource HOB for PEI memmory and reserved memory
595 BuildResourceDescriptorHob (
596 EFI_RESOURCE_SYSTEM_MEMORY
,
598 EFI_RESOURCE_ATTRIBUTE_PRESENT
|
599 EFI_RESOURCE_ATTRIBUTE_INITIALIZED
|
600 EFI_RESOURCE_ATTRIBUTE_TESTED
|
601 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE
|
602 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE
|
603 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE
|
604 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE
606 (TopLoadingAddress
- TotalReservedMemorySize
),
607 TotalReservedMemorySize
610 // rebuild resource for the remain memory if necessary
612 if (CurrentResourceHob
->PhysicalStart
< TopLoadingAddress
- TotalReservedMemorySize
) {
613 BuildResourceDescriptorHob (
614 EFI_RESOURCE_SYSTEM_MEMORY
,
616 EFI_RESOURCE_ATTRIBUTE_PRESENT
|
617 EFI_RESOURCE_ATTRIBUTE_INITIALIZED
|
618 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE
|
619 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE
|
620 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE
|
621 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE
623 CurrentResourceHob
->PhysicalStart
,
624 (TopLoadingAddress
- TotalReservedMemorySize
- CurrentResourceHob
->PhysicalStart
)
627 if (CurrentResourceHob
->PhysicalStart
+ CurrentResourceHob
->ResourceLength
> TopLoadingAddress
) {
628 BuildResourceDescriptorHob (
629 EFI_RESOURCE_SYSTEM_MEMORY
,
631 EFI_RESOURCE_ATTRIBUTE_PRESENT
|
632 EFI_RESOURCE_ATTRIBUTE_INITIALIZED
|
633 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE
|
634 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE
|
635 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE
|
636 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE
639 (CurrentResourceHob
->PhysicalStart
+ CurrentResourceHob
->ResourceLength
- TopLoadingAddress
)
643 // Delete CurrentHob by marking it as unused since the the memory range described by is rebuilt.
645 GET_HOB_TYPE (CurrentHob
) = EFI_HOB_TYPE_UNUSED
;
649 // Cache the top address for Loading Module at Fixed Address feature
651 PrivateData
->LoadModuleAtFixAddressTopAddress
= TopLoadingAddress
- MINIMUM_INITIAL_MEMORY_SIZE
;
652 DEBUG ((EFI_D_INFO
, "LOADING MODULE FIXED INFO: Top address = 0x%lx\n", PrivateData
->LoadModuleAtFixAddressTopAddress
));
654 // reinstall the PEI memory relative to TopLoadingAddress
656 PrivateData
->PhysicalMemoryBegin
= TopLoadingAddress
- TotalReservedMemorySize
;
657 PrivateData
->FreePhysicalMemoryTop
= PrivateData
->PhysicalMemoryBegin
+ PeiMemorySize
;
660 Conduct PEIM dispatch.
662 @param SecCoreData Points to a data structure containing information about the PEI core's operating
663 environment, such as the size and location of temporary RAM, the stack location and
665 @param Private Pointer to the private data passed in from caller
670 IN CONST EFI_SEC_PEI_HAND_OFF
*SecCoreData
,
671 IN PEI_CORE_INSTANCE
*Private
677 CONST EFI_PEI_SERVICES
**PeiServices
;
678 EFI_PEI_FILE_HANDLE PeimFileHandle
;
681 UINT32 AuthenticationState
;
682 EFI_PHYSICAL_ADDRESS EntryPoint
;
683 EFI_PEIM_ENTRY_POINT2 PeimEntryPoint
;
684 UINTN SaveCurrentPeimCount
;
685 UINTN SaveCurrentFvCount
;
686 EFI_PEI_FILE_HANDLE SaveCurrentFileHandle
;
687 PEIM_FILE_HANDLE_EXTENDED_DATA ExtendedData
;
688 EFI_PHYSICAL_ADDRESS NewPermenentMemoryBase
;
689 TEMPORARY_RAM_SUPPORT_PPI
*TemporaryRamSupportPpi
;
690 EFI_HOB_HANDOFF_INFO_TABLE
*OldHandOffTable
;
691 EFI_HOB_HANDOFF_INFO_TABLE
*NewHandOffTable
;
694 PEI_CORE_INSTANCE
*PrivateInMem
;
695 UINT64 NewPeiStackSize
;
696 UINT64 OldPeiStackSize
;
698 EFI_FV_FILE_INFO FvFileInfo
;
699 UINTN OldCheckingTop
;
700 UINTN OldCheckingBottom
;
701 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
702 VOID
*LoadFixPeiCodeBegin
;
704 PeiServices
= (CONST EFI_PEI_SERVICES
**) &Private
->Ps
;
705 PeimEntryPoint
= NULL
;
706 PeimFileHandle
= NULL
;
709 if ((Private
->PeiMemoryInstalled
) && (Private
->HobList
.HandoffInformationTable
->BootMode
!= BOOT_ON_S3_RESUME
)) {
711 // Once real memory is available, shadow the RegisterForShadow modules. And meanwhile
712 // update the modules' status from PEIM_STATE_REGISITER_FOR_SHADOW to PEIM_STATE_DONE.
714 SaveCurrentPeimCount
= Private
->CurrentPeimCount
;
715 SaveCurrentFvCount
= Private
->CurrentPeimFvCount
;
716 SaveCurrentFileHandle
= Private
->CurrentFileHandle
;
718 for (Index1
= 0; Index1
<= SaveCurrentFvCount
; Index1
++) {
719 for (Index2
= 0; (Index2
< FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv
)) && (Private
->Fv
[Index1
].FvFileHandles
[Index2
] != NULL
); Index2
++) {
720 if (Private
->Fv
[Index1
].PeimState
[Index2
] == PEIM_STATE_REGISITER_FOR_SHADOW
) {
721 PeimFileHandle
= Private
->Fv
[Index1
].FvFileHandles
[Index2
];
722 Status
= PeiLoadImage (
723 (CONST EFI_PEI_SERVICES
**) &Private
->Ps
,
725 PEIM_STATE_REGISITER_FOR_SHADOW
,
729 if (Status
== EFI_SUCCESS
) {
731 // PEIM_STATE_REGISITER_FOR_SHADOW move to PEIM_STATE_DONE
733 Private
->Fv
[Index1
].PeimState
[Index2
]++;
734 Private
->CurrentFileHandle
= PeimFileHandle
;
735 Private
->CurrentPeimFvCount
= Index1
;
736 Private
->CurrentPeimCount
= Index2
;
738 // Call the PEIM entry point
740 PeimEntryPoint
= (EFI_PEIM_ENTRY_POINT2
)(UINTN
)EntryPoint
;
742 PERF_START (PeimFileHandle
, "PEIM", NULL
, 0);
743 PeimEntryPoint(PeimFileHandle
, (const EFI_PEI_SERVICES
**) &Private
->Ps
);
744 PERF_END (PeimFileHandle
, "PEIM", NULL
, 0);
748 // Process the Notify list and dispatch any notifies for
749 // newly installed PPIs.
751 ProcessNotifyList (Private
);
755 Private
->CurrentFileHandle
= SaveCurrentFileHandle
;
756 Private
->CurrentPeimFvCount
= SaveCurrentFvCount
;
757 Private
->CurrentPeimCount
= SaveCurrentPeimCount
;
761 // This is the main dispatch loop. It will search known FVs for PEIMs and
762 // attempt to dispatch them. If any PEIM gets dispatched through a single
763 // pass of the dispatcher, it will start over from the Bfv again to see
764 // if any new PEIMs dependencies got satisfied. With a well ordered
765 // FV where PEIMs are found in the order their dependencies are also
766 // satisfied, this dipatcher should run only once.
770 // In case that reenter PeiCore happens, the last pass record is still available.
772 if (!Private
->PeimDispatcherReenter
) {
773 Private
->PeimNeedingDispatch
= FALSE
;
774 Private
->PeimDispatchOnThisPass
= FALSE
;
776 Private
->PeimDispatcherReenter
= FALSE
;
779 for (FvCount
= Private
->CurrentPeimFvCount
; FvCount
< Private
->FvCount
; FvCount
++) {
780 CoreFvHandle
= FindNextCoreFvHandle (Private
, FvCount
);
781 ASSERT (CoreFvHandle
!= NULL
);
784 // If the FV has corresponding EFI_PEI_FIRMWARE_VOLUME_PPI instance, then dispatch it.
786 if (CoreFvHandle
->FvPpi
== NULL
) {
790 Private
->CurrentPeimFvCount
= FvCount
;
792 if (Private
->CurrentPeimCount
== 0) {
794 // When going through each FV, at first, search Apriori file to
795 // reorder all PEIMs to ensure the PEIMs in Apriori file to get
796 // dispatch at first.
798 DiscoverPeimsAndOrderWithApriori (Private
, CoreFvHandle
);
802 // Start to dispatch all modules within the current Fv.
804 for (PeimCount
= Private
->CurrentPeimCount
;
805 (PeimCount
< FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv
)) && (Private
->CurrentFvFileHandles
[PeimCount
] != NULL
);
807 Private
->CurrentPeimCount
= PeimCount
;
808 PeimFileHandle
= Private
->CurrentFileHandle
= Private
->CurrentFvFileHandles
[PeimCount
];
810 if (Private
->Fv
[FvCount
].PeimState
[PeimCount
] == PEIM_STATE_NOT_DISPATCHED
) {
811 if (!DepexSatisfied (Private
, PeimFileHandle
, PeimCount
)) {
812 Private
->PeimNeedingDispatch
= TRUE
;
814 Status
= CoreFvHandle
->FvPpi
->GetFileInfo (CoreFvHandle
->FvPpi
, PeimFileHandle
, &FvFileInfo
);
815 ASSERT_EFI_ERROR (Status
);
816 if (FvFileInfo
.FileType
== EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
) {
818 // For Fv type file, Produce new FV PPI and FV hob
820 Status
= ProcessFvFile (&Private
->Fv
[FvCount
], PeimFileHandle
);
821 AuthenticationState
= 0;
824 // For PEIM driver, Load its entry point
826 Status
= PeiLoadImage (
829 PEIM_STATE_NOT_DISPATCHED
,
835 if ((Status
== EFI_SUCCESS
)) {
837 // The PEIM has its dependencies satisfied, and its entry point
838 // has been found, so invoke it.
840 PERF_START (PeimFileHandle
, "PEIM", NULL
, 0);
842 ExtendedData
.Handle
= (EFI_HANDLE
)PeimFileHandle
;
844 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (
846 (EFI_SOFTWARE_PEI_CORE
| EFI_SW_PC_INIT_BEGIN
),
847 (VOID
*)(&ExtendedData
),
848 sizeof (ExtendedData
)
851 Status
= VerifyPeim (Private
, CoreFvHandle
->FvHandle
, PeimFileHandle
);
852 if (Status
!= EFI_SECURITY_VIOLATION
&& (AuthenticationState
== 0)) {
854 // PEIM_STATE_NOT_DISPATCHED move to PEIM_STATE_DISPATCHED
856 Private
->Fv
[FvCount
].PeimState
[PeimCount
]++;
858 if (FvFileInfo
.FileType
!= EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
) {
860 // Call the PEIM entry point for PEIM driver
862 PeimEntryPoint
= (EFI_PEIM_ENTRY_POINT2
)(UINTN
)EntryPoint
;
863 PeimEntryPoint (PeimFileHandle
, (const EFI_PEI_SERVICES
**) PeiServices
);
866 Private
->PeimDispatchOnThisPass
= TRUE
;
869 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (
871 (EFI_SOFTWARE_PEI_CORE
| EFI_SW_PC_INIT_BEGIN
),
872 (VOID
*)(&ExtendedData
),
873 sizeof (ExtendedData
)
875 PERF_END (PeimFileHandle
, "PEIM", NULL
, 0);
879 if (Private
->SwitchStackSignal
) {
881 // Before switch stack from temporary memory to permenent memory, caculate the heap and stack
882 // usage in temporary memory for debuging.
885 UINT32
*StackPointer
;
887 for (StackPointer
= (UINT32
*)SecCoreData
->StackBase
;
888 (StackPointer
< (UINT32
*)((UINTN
)SecCoreData
->StackBase
+ SecCoreData
->StackSize
)) \
889 && (*StackPointer
== INIT_CAR_VALUE
);
892 DEBUG ((EFI_D_INFO
, "Total temporary memory: %d bytes.\n", (UINT32
)SecCoreData
->TemporaryRamSize
));
893 DEBUG ((EFI_D_INFO
, " temporary memory stack ever used: %d bytes.\n",
894 (SecCoreData
->StackSize
- ((UINTN
) StackPointer
- (UINTN
)SecCoreData
->StackBase
))
896 DEBUG ((EFI_D_INFO
, " temporary memory heap used: %d bytes.\n",
897 ((UINTN
) Private
->HobList
.HandoffInformationTable
->EfiFreeMemoryBottom
-
898 (UINTN
) Private
->HobList
.Raw
)
902 if (PcdGet64(PcdLoadModuleAtFixAddressEnable
) != 0 && (Private
->HobList
.HandoffInformationTable
->BootMode
!= BOOT_ON_S3_RESUME
)) {
904 // Loading Module at Fixed Address is enabled
906 PeiLoadFixAddressHook(Private
);
908 // if Loading Module at Fixed Address is enabled, Allocating memory range for Pei code range.
910 LoadFixPeiCodeBegin
= AllocatePages((UINTN
)PcdGet32(PcdLoadFixAddressPeiCodePageNumber
));
911 DEBUG ((EFI_D_INFO
, "LOADING MODULE FIXED INFO: PeiCodeBegin = 0x%lX, PeiCodeTop= 0x%lX\n", (UINT64
)(UINTN
)LoadFixPeiCodeBegin
, (UINT64
)((UINTN
)LoadFixPeiCodeBegin
+ PcdGet32(PcdLoadFixAddressPeiCodePageNumber
) * EFI_PAGE_SIZE
)));
915 // Reserve the size of new stack at bottom of physical memory
917 OldPeiStackSize
= (UINT64
) SecCoreData
->StackSize
;
918 NewPeiStackSize
= (RShiftU64 (Private
->PhysicalMemoryLength
, 1) + EFI_PAGE_MASK
) & ~EFI_PAGE_MASK
;
919 if (PcdGet32(PcdPeiCoreMaxPeiStackSize
) > (UINT32
) NewPeiStackSize
) {
920 Private
->StackSize
= NewPeiStackSize
;
922 Private
->StackSize
= PcdGet32(PcdPeiCoreMaxPeiStackSize
);
926 // In theory, the size of new stack in permenent memory should large than
927 // size of old stack in temporary memory.
928 // But if new stack is smaller than the size of old stack, we also reserve
929 // the size of old stack at bottom of permenent memory.
931 DEBUG ((EFI_D_INFO
, "Old Stack size %d, New stack size %d\n", (INT32
) OldPeiStackSize
, (INT32
) Private
->StackSize
));
932 ASSERT (Private
->StackSize
>= OldPeiStackSize
);
933 StackGap
= Private
->StackSize
- OldPeiStackSize
;
936 // Update HandOffHob for new installed permenent memory
938 OldHandOffTable
= Private
->HobList
.HandoffInformationTable
;
939 OldCheckingBottom
= (UINTN
)(SecCoreData
->TemporaryRamBase
);
940 OldCheckingTop
= (UINTN
)(OldCheckingBottom
+ SecCoreData
->TemporaryRamSize
);
943 // The whole temporary memory will be migrated to physical memory.
944 // CAUTION: The new base is computed accounding to gap of new stack.
946 NewPermenentMemoryBase
= Private
->PhysicalMemoryBegin
+ StackGap
;
949 // Caculate stack offset and heap offset between temporary memory and new permement
950 // memory seperately.
952 StackOffset
= (UINTN
) NewPermenentMemoryBase
- (UINTN
) SecCoreData
->StackBase
;
953 HeapOffset
= (INTN
) ((UINTN
) Private
->PhysicalMemoryBegin
+ Private
->StackSize
- \
954 (UINTN
) SecCoreData
->PeiTemporaryRamBase
);
955 DEBUG ((EFI_D_INFO
, "Heap Offset = 0x%lX Stack Offset = 0x%lX\n", (INT64
)HeapOffset
, (INT64
)StackOffset
));
958 // Caculate new HandOffTable and PrivateData address in permenet memory's stack
960 NewHandOffTable
= (EFI_HOB_HANDOFF_INFO_TABLE
*)((UINTN
)OldHandOffTable
+ HeapOffset
);
961 PrivateInMem
= (PEI_CORE_INSTANCE
*)((UINTN
) (VOID
*) Private
+ StackOffset
);
964 // TemporaryRamSupportPpi is produced by platform's SEC
966 Status
= PeiLocatePpi (
967 (CONST EFI_PEI_SERVICES
**) PeiServices
,
968 &gEfiTemporaryRamSupportPpiGuid
,
971 (VOID
**)&TemporaryRamSupportPpi
975 if (!EFI_ERROR (Status
)) {
977 // Temporary Ram support Ppi is provided by platform, it will copy
978 // temporary memory to permenent memory and do stack switching.
979 // After invoken temporary Ram support, following code's stack is in
980 // memory but not in temporary memory.
982 TemporaryRamSupportPpi
->TemporaryRamMigration (
983 (CONST EFI_PEI_SERVICES
**) PeiServices
,
984 (EFI_PHYSICAL_ADDRESS
)(UINTN
) SecCoreData
->TemporaryRamBase
,
985 (EFI_PHYSICAL_ADDRESS
)(UINTN
) NewPermenentMemoryBase
,
986 SecCoreData
->TemporaryRamSize
991 // In IA32/x64/Itanium architecture, we need platform provide
992 // TEMPORAY_RAM_MIGRATION_PPI.
1000 // Fixup the PeiCore's private data
1002 PrivateInMem
->Ps
= &PrivateInMem
->ServiceTableShadow
;
1003 PrivateInMem
->CpuIo
= &PrivateInMem
->ServiceTableShadow
.CpuIo
;
1004 PrivateInMem
->HobList
.Raw
= (VOID
*) ((UINTN
) PrivateInMem
->HobList
.Raw
+ HeapOffset
);
1005 PrivateInMem
->StackBase
= (EFI_PHYSICAL_ADDRESS
)(((UINTN
)PrivateInMem
->PhysicalMemoryBegin
+ EFI_PAGE_MASK
) & ~EFI_PAGE_MASK
);
1007 PeiServices
= (CONST EFI_PEI_SERVICES
**) &PrivateInMem
->Ps
;
1010 // Fixup for PeiService's address
1012 SetPeiServicesTablePointer(PeiServices
);
1015 // Update HandOffHob for new installed permenent memory
1017 NewHandOffTable
->EfiEndOfHobList
=
1018 (EFI_PHYSICAL_ADDRESS
)((UINTN
) NewHandOffTable
->EfiEndOfHobList
+ HeapOffset
);
1019 NewHandOffTable
->EfiMemoryTop
= PrivateInMem
->PhysicalMemoryBegin
+
1020 PrivateInMem
->PhysicalMemoryLength
;
1021 NewHandOffTable
->EfiMemoryBottom
= PrivateInMem
->PhysicalMemoryBegin
;
1022 NewHandOffTable
->EfiFreeMemoryTop
= PrivateInMem
->FreePhysicalMemoryTop
;
1023 NewHandOffTable
->EfiFreeMemoryBottom
= NewHandOffTable
->EfiEndOfHobList
+
1024 sizeof (EFI_HOB_GENERIC_HEADER
);
1027 // We need convert the PPI desciptor's pointer
1029 ConvertPpiPointers (PrivateInMem
,
1035 DEBUG ((EFI_D_INFO
, "Stack Hob: BaseAddress=0x%lX Length=0x%lX\n",
1036 PrivateInMem
->StackBase
,
1037 PrivateInMem
->StackSize
));
1038 BuildStackHob (PrivateInMem
->StackBase
, PrivateInMem
->StackSize
);
1041 // After the whole temporary memory is migrated, then we can allocate page in
1042 // permenent memory.
1044 PrivateInMem
->PeiMemoryInstalled
= TRUE
;
1047 // Indicate that PeiCore reenter
1049 PrivateInMem
->PeimDispatcherReenter
= TRUE
;
1051 if (PcdGet64(PcdLoadModuleAtFixAddressEnable
) != 0 && (PrivateInMem
->HobList
.HandoffInformationTable
->BootMode
!= BOOT_ON_S3_RESUME
)) {
1053 // if Loading Module at Fixed Address is enabled, allocate the PEI code memory range usage bit map array.
1054 // Every bit in the array indicate the status of the corresponding memory page available or not
1056 PrivateInMem
->PeiCodeMemoryRangeUsageBitMap
= AllocateZeroPool (((PcdGet32(PcdLoadFixAddressPeiCodePageNumber
)>>6) + 1)*sizeof(UINT64
));
1059 // Shadow PEI Core. When permanent memory is avaiable, shadow
1060 // PEI Core and PEIMs to get high performance.
1062 PrivateInMem
->ShadowedPeiCore
= ShadowPeiCore (
1067 // Process the Notify list and dispatch any notifies for
1068 // newly installed PPIs.
1070 ProcessNotifyList (PrivateInMem
);
1073 // Entry PEI Phase 2
1075 PeiCore (SecCoreData
, NULL
, PrivateInMem
);
1078 // Code should not come here
1080 ASSERT_EFI_ERROR(FALSE
);
1084 // Process the Notify list and dispatch any notifies for
1085 // newly installed PPIs.
1087 ProcessNotifyList (Private
);
1089 if ((Private
->PeiMemoryInstalled
) && (Private
->Fv
[FvCount
].PeimState
[PeimCount
] == PEIM_STATE_REGISITER_FOR_SHADOW
) && \
1090 (Private
->HobList
.HandoffInformationTable
->BootMode
!= BOOT_ON_S3_RESUME
)) {
1092 // If memory is availble we shadow images by default for performance reasons.
1093 // We call the entry point a 2nd time so the module knows it's shadowed.
1095 //PERF_START (PeiServices, L"PEIM", PeimFileHandle, 0);
1096 ASSERT (PeimEntryPoint
!= NULL
);
1097 PeimEntryPoint (PeimFileHandle
, (const EFI_PEI_SERVICES
**) PeiServices
);
1098 //PERF_END (PeiServices, L"PEIM", PeimFileHandle, 0);
1101 // PEIM_STATE_REGISITER_FOR_SHADOW move to PEIM_STATE_DONE
1103 Private
->Fv
[FvCount
].PeimState
[PeimCount
]++;
1106 // Process the Notify list and dispatch any notifies for
1107 // newly installed PPIs.
1109 ProcessNotifyList (Private
);
1116 // We set to NULL here to optimize the 2nd entry to this routine after
1117 // memory is found. This reprevents rescanning of the FV. We set to
1118 // NULL here so we start at the begining of the next FV
1120 Private
->CurrentFileHandle
= NULL
;
1121 Private
->CurrentPeimCount
= 0;
1123 // Before walking through the next FV,Private->CurrentFvFileHandles[]should set to NULL
1125 SetMem (Private
->CurrentFvFileHandles
, sizeof (Private
->CurrentFvFileHandles
), 0);
1129 // Before making another pass, we should set Private->CurrentPeimFvCount =0 to go
1130 // through all the FV.
1132 Private
->CurrentPeimFvCount
= 0;
1135 // PeimNeedingDispatch being TRUE means we found a PEIM that did not get
1136 // dispatched. So we need to make another pass
1138 // PeimDispatchOnThisPass being TRUE means we dispatched a PEIM on this
1139 // pass. If we did not dispatch a PEIM there is no point in trying again
1140 // as it will fail the next time too (nothing has changed).
1142 } while (Private
->PeimNeedingDispatch
&& Private
->PeimDispatchOnThisPass
);
1147 Initialize the Dispatcher's data members
1149 @param PrivateData PeiCore's private data structure
1150 @param OldCoreData Old data from SecCore
1151 NULL if being run in non-permament memory mode.
1152 @param SecCoreData Points to a data structure containing information about the PEI core's operating
1153 environment, such as the size and location of temporary RAM, the stack location and
1160 InitializeDispatcherData (
1161 IN PEI_CORE_INSTANCE
*PrivateData
,
1162 IN PEI_CORE_INSTANCE
*OldCoreData
,
1163 IN CONST EFI_SEC_PEI_HAND_OFF
*SecCoreData
1166 if (OldCoreData
== NULL
) {
1167 PrivateData
->PeimDispatcherReenter
= FALSE
;
1168 PeiInitializeFv (PrivateData
, SecCoreData
);
1170 PeiReinitializeFv (PrivateData
);
1177 This routine parses the Dependency Expression, if available, and
1178 decides if the module can be executed.
1181 @param Private PeiCore's private data structure
1182 @param FileHandle PEIM's file handle
1183 @param PeimCount Peim count in all dispatched PEIMs.
1185 @retval TRUE Can be dispatched
1186 @retval FALSE Cannot be dispatched
1191 IN PEI_CORE_INSTANCE
*Private
,
1192 IN EFI_PEI_FILE_HANDLE FileHandle
,
1199 if (PeimCount
< Private
->AprioriCount
) {
1201 // If its in the A priori file then we set Depex to TRUE
1207 // Depex section not in the encapsulated section.
1209 Status
= PeiServicesFfsFindSectionData (
1210 EFI_SECTION_PEI_DEPEX
,
1215 if (EFI_ERROR (Status
)) {
1217 // If there is no DEPEX, assume the module can be executed
1223 // Evaluate a given DEPEX
1225 return PeimDispatchReadiness (&Private
->Ps
, DepexData
);
1229 This routine enable a PEIM to register itself to shadow when PEI Foundation
1230 discovery permanent memory.
1232 @param FileHandle File handle of a PEIM.
1234 @retval EFI_NOT_FOUND The file handle doesn't point to PEIM itself.
1235 @retval EFI_ALREADY_STARTED Indicate that the PEIM has been registered itself.
1236 @retval EFI_SUCCESS Successfully to register itself.
1241 PeiRegisterForShadow (
1242 IN EFI_PEI_FILE_HANDLE FileHandle
1245 PEI_CORE_INSTANCE
*Private
;
1246 Private
= PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer ());
1248 if (Private
->CurrentFileHandle
!= FileHandle
) {
1250 // The FileHandle must be for the current PEIM
1252 return EFI_NOT_FOUND
;
1255 if (Private
->Fv
[Private
->CurrentPeimFvCount
].PeimState
[Private
->CurrentPeimCount
] >= PEIM_STATE_REGISITER_FOR_SHADOW
) {
1257 // If the PEIM has already entered the PEIM_STATE_REGISTER_FOR_SHADOW or PEIM_STATE_DONE then it's already been started
1259 return EFI_ALREADY_STARTED
;
1262 Private
->Fv
[Private
->CurrentPeimFvCount
].PeimState
[Private
->CurrentPeimCount
] = PEIM_STATE_REGISITER_FOR_SHADOW
;