2 EFI PEI Core dispatch services
4 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
5 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 // This is the minimum memory required by DxeCore initialization. When LMFA feature enabled,
188 // This part of memory still need reserved on the very top of memory so that the DXE Core could
189 // use these memory for data initialization. This macro should be sync with the same marco
190 // defined in DXE Core.
192 #define MINIMUM_INITIAL_MEMORY_SIZE 0x10000
194 This function is to test if the memory range described in resource HOB is available or not.
196 This function should only be invoked when Loading Module at Fixed Address(LMFA) feature is enabled. Some platform may allocate the
197 memory before PeiLoadFixAddressHook in invoked. so this function is to test if the memory range described by the input resource HOB is
200 @param PrivateData Pointer to the private data passed in from caller
201 @param ResourceHob Pointer to a resource HOB which described the memory range described by the input resource HOB
204 PeiLoadFixAddressIsMemoryRangeAvailable (
205 IN PEI_CORE_INSTANCE
*PrivateData
,
206 IN EFI_HOB_RESOURCE_DESCRIPTOR
*ResourceHob
209 EFI_HOB_MEMORY_ALLOCATION
*MemoryHob
;
211 EFI_PEI_HOB_POINTERS Hob
;
214 if (PrivateData
== NULL
|| ResourceHob
== NULL
) {
218 // test if the memory range describe in the HOB is already allocated.
220 for (Hob
.Raw
= PrivateData
->HobList
.Raw
; !END_OF_HOB_LIST(Hob
); Hob
.Raw
= GET_NEXT_HOB(Hob
)) {
222 // See if this is a memory allocation HOB
224 if (GET_HOB_TYPE (Hob
) == EFI_HOB_TYPE_MEMORY_ALLOCATION
) {
225 MemoryHob
= Hob
.MemoryAllocation
;
226 if(MemoryHob
->AllocDescriptor
.MemoryBaseAddress
== ResourceHob
->PhysicalStart
&&
227 MemoryHob
->AllocDescriptor
.MemoryBaseAddress
+ MemoryHob
->AllocDescriptor
.MemoryLength
== ResourceHob
->PhysicalStart
+ ResourceHob
->ResourceLength
) {
238 Hook function for Loading Module at Fixed Address feature
240 This function should only be invoked when Loading Module at Fixed Address(LMFA) feature is enabled. When feature is
241 configured as Load Modules at Fix Absolute Address, this function is to validate the top address assigned by user. When
242 feature is configured as Load Modules at Fixed Offset, the functino is to find the top address which is TOLM-TSEG in general.
243 And also the function will re-install PEI memory.
245 @param PrivateData Pointer to the private data passed in from caller
249 PeiLoadFixAddressHook(
250 IN PEI_CORE_INSTANCE
*PrivateData
253 EFI_PHYSICAL_ADDRESS TopLoadingAddress
;
254 UINT64 PeiMemorySize
;
255 UINT64 TotalReservedMemorySize
;
256 UINT64 MemoryRangeEnd
;
257 EFI_PHYSICAL_ADDRESS HighAddress
;
258 EFI_HOB_RESOURCE_DESCRIPTOR
*ResourceHob
;
259 EFI_HOB_RESOURCE_DESCRIPTOR
*NextResourceHob
;
260 EFI_HOB_RESOURCE_DESCRIPTOR
*CurrentResourceHob
;
261 EFI_PEI_HOB_POINTERS CurrentHob
;
262 EFI_PEI_HOB_POINTERS Hob
;
263 EFI_PEI_HOB_POINTERS NextHob
;
264 EFI_PHYSICAL_ADDRESS MaxMemoryBaseAddress
;
265 UINT64 MaxMemoryLength
;
266 EFI_HOB_MEMORY_ALLOCATION
*MemoryHob
;
268 // Initialize Local Variables
270 CurrentResourceHob
= NULL
;
272 NextResourceHob
= NULL
;
273 MaxMemoryBaseAddress
= 0;
276 TopLoadingAddress
= 0;
278 CurrentHob
.Raw
= PrivateData
->HobList
.Raw
;
279 PeiMemorySize
= PrivateData
->PhysicalMemoryLength
;
281 // The top reserved memory include 3 parts: the topest range is for DXE core initialization with the size MINIMUM_INITIAL_MEMORY_SIZE
282 // then RuntimeCodePage range and Boot time code range.
284 TotalReservedMemorySize
= MINIMUM_INITIAL_MEMORY_SIZE
+ EFI_PAGES_TO_SIZE(PcdGet32(PcdLoadFixAddressRuntimeCodePageNumber
));
285 TotalReservedMemorySize
+= EFI_PAGES_TO_SIZE(PcdGet32(PcdLoadFixAddressBootTimeCodePageNumber
)) ;
287 // PEI memory range lies below the top reserved memory
289 TotalReservedMemorySize
+= PeiMemorySize
;
291 DEBUG ((EFI_D_INFO
, "LOADING MODULE FIXED INFO: PcdLoadFixAddressRuntimeCodePageNumber= 0x%x.\n", PcdGet32(PcdLoadFixAddressRuntimeCodePageNumber
)));
292 DEBUG ((EFI_D_INFO
, "LOADING MODULE FIXED INFO: PcdLoadFixAddressBootTimeCodePageNumber= 0x%x.\n", PcdGet32(PcdLoadFixAddressBootTimeCodePageNumber
)));
293 DEBUG ((EFI_D_INFO
, "LOADING MODULE FIXED INFO: PcdLoadFixAddressPeiCodePageNumber= 0x%x.\n", PcdGet32(PcdLoadFixAddressPeiCodePageNumber
)));
294 DEBUG ((EFI_D_INFO
, "LOADING MODULE FIXED INFO: Total Reserved Memory Size = 0x%lx.\n", TotalReservedMemorySize
));
296 // Loop through the system memory typed hob to merge the adjacent memory range
298 for (Hob
.Raw
= PrivateData
->HobList
.Raw
; !END_OF_HOB_LIST(Hob
); Hob
.Raw
= GET_NEXT_HOB(Hob
)) {
300 // See if this is a resource descriptor HOB
302 if (GET_HOB_TYPE (Hob
) == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR
) {
304 ResourceHob
= Hob
.ResourceDescriptor
;
306 // If range described in this hob is not system memory or heigher than MAX_ADDRESS, ignored.
308 if (ResourceHob
->ResourceType
!= EFI_RESOURCE_SYSTEM_MEMORY
&&
309 ResourceHob
->PhysicalStart
+ ResourceHob
->ResourceLength
> MAX_ADDRESS
) {
313 for (NextHob
.Raw
= PrivateData
->HobList
.Raw
; !END_OF_HOB_LIST(NextHob
); NextHob
.Raw
= GET_NEXT_HOB(NextHob
)) {
314 if (NextHob
.Raw
== Hob
.Raw
){
318 // See if this is a resource descriptor HOB
320 if (GET_HOB_TYPE (NextHob
) == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR
) {
322 NextResourceHob
= NextHob
.ResourceDescriptor
;
324 // test if range described in this NextResourceHob is system memory and have the same attribute.
325 // Note: Here is a assumption that system memory should always be healthy even without test.
327 if (NextResourceHob
->ResourceType
== EFI_RESOURCE_SYSTEM_MEMORY
&&
328 (((NextResourceHob
->ResourceAttribute
^ResourceHob
->ResourceAttribute
)&(~EFI_RESOURCE_ATTRIBUTE_TESTED
)) == 0)){
331 // See if the memory range described in ResourceHob and NextResourceHob is adjacent
333 if ((ResourceHob
->PhysicalStart
<= NextResourceHob
->PhysicalStart
&&
334 ResourceHob
->PhysicalStart
+ ResourceHob
->ResourceLength
>= NextResourceHob
->PhysicalStart
)||
335 (ResourceHob
->PhysicalStart
>= NextResourceHob
->PhysicalStart
&&
336 ResourceHob
->PhysicalStart
<= NextResourceHob
->PhysicalStart
+ NextResourceHob
->ResourceLength
)) {
338 MemoryRangeEnd
= ((ResourceHob
->PhysicalStart
+ ResourceHob
->ResourceLength
)>(NextResourceHob
->PhysicalStart
+ NextResourceHob
->ResourceLength
)) ?
339 (ResourceHob
->PhysicalStart
+ ResourceHob
->ResourceLength
):(NextResourceHob
->PhysicalStart
+ NextResourceHob
->ResourceLength
);
341 ResourceHob
->PhysicalStart
= (ResourceHob
->PhysicalStart
< NextResourceHob
->PhysicalStart
) ?
342 ResourceHob
->PhysicalStart
: NextResourceHob
->PhysicalStart
;
345 ResourceHob
->ResourceLength
= (MemoryRangeEnd
- ResourceHob
->PhysicalStart
);
347 ResourceHob
->ResourceAttribute
= ResourceHob
->ResourceAttribute
& (~EFI_RESOURCE_ATTRIBUTE_TESTED
);
349 // Delete the NextResourceHob by marking it as unused.
351 GET_HOB_TYPE (NextHob
) = EFI_HOB_TYPE_UNUSED
;
360 // Some platform is already allocated pages before the HOB re-org. Here to build dedicated resource HOB to describe
361 // the allocated memory range
363 for (Hob
.Raw
= PrivateData
->HobList
.Raw
; !END_OF_HOB_LIST(Hob
); Hob
.Raw
= GET_NEXT_HOB(Hob
)) {
365 // See if this is a memory allocation HOB
367 if (GET_HOB_TYPE (Hob
) == EFI_HOB_TYPE_MEMORY_ALLOCATION
) {
368 MemoryHob
= Hob
.MemoryAllocation
;
369 for (NextHob
.Raw
= PrivateData
->HobList
.Raw
; !END_OF_HOB_LIST(NextHob
); NextHob
.Raw
= GET_NEXT_HOB(NextHob
)) {
371 // See if this is a resource descriptor HOB
373 if (GET_HOB_TYPE (NextHob
) == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR
) {
374 NextResourceHob
= NextHob
.ResourceDescriptor
;
376 // If range described in this hob is not system memory or heigher than MAX_ADDRESS, ignored.
378 if (NextResourceHob
->ResourceType
== EFI_RESOURCE_SYSTEM_MEMORY
&& NextResourceHob
->PhysicalStart
+ NextResourceHob
->ResourceLength
> MAX_ADDRESS
) {
382 // If the range describe in memory allocation HOB belongs to the memroy range described by the resource hob
384 if (MemoryHob
->AllocDescriptor
.MemoryBaseAddress
>= NextResourceHob
->PhysicalStart
&&
385 MemoryHob
->AllocDescriptor
.MemoryBaseAddress
+ MemoryHob
->AllocDescriptor
.MemoryLength
<= NextResourceHob
->PhysicalStart
+ NextResourceHob
->ResourceLength
) {
387 // Build seperate resource hob for this allocated range
389 if (MemoryHob
->AllocDescriptor
.MemoryBaseAddress
> NextResourceHob
->PhysicalStart
) {
390 BuildResourceDescriptorHob (
391 EFI_RESOURCE_SYSTEM_MEMORY
,
392 NextResourceHob
->ResourceAttribute
,
393 NextResourceHob
->PhysicalStart
,
394 (MemoryHob
->AllocDescriptor
.MemoryBaseAddress
- NextResourceHob
->PhysicalStart
)
397 if (MemoryHob
->AllocDescriptor
.MemoryBaseAddress
+ MemoryHob
->AllocDescriptor
.MemoryLength
< NextResourceHob
->PhysicalStart
+ NextResourceHob
->ResourceLength
) {
398 BuildResourceDescriptorHob (
399 EFI_RESOURCE_SYSTEM_MEMORY
,
400 NextResourceHob
->ResourceAttribute
,
401 MemoryHob
->AllocDescriptor
.MemoryBaseAddress
+ MemoryHob
->AllocDescriptor
.MemoryLength
,
402 (NextResourceHob
->PhysicalStart
+ NextResourceHob
->ResourceLength
-(MemoryHob
->AllocDescriptor
.MemoryBaseAddress
+ MemoryHob
->AllocDescriptor
.MemoryLength
))
405 NextResourceHob
->PhysicalStart
= MemoryHob
->AllocDescriptor
.MemoryBaseAddress
;
406 NextResourceHob
->ResourceLength
= MemoryHob
->AllocDescriptor
.MemoryLength
;
415 // Try to find and validate the TOP address.
417 if ((INT64
)PcdGet64(PcdLoadModuleAtFixAddressEnable
) > 0 ) {
419 // The LMFA feature is enabled as load module at fixed absolute address.
421 TopLoadingAddress
= (EFI_PHYSICAL_ADDRESS
)PcdGet64(PcdLoadModuleAtFixAddressEnable
);
422 DEBUG ((EFI_D_INFO
, "LOADING MODULE FIXED INFO: Loading module at fixed absolute address.\n"));
424 // validate the Address. Loop the resource descriptor HOB to make sure the address is in valid memory range
426 if ((TopLoadingAddress
& EFI_PAGE_MASK
) != 0) {
427 DEBUG ((EFI_D_INFO
, "LOADING MODULE FIXED ERROR:Top Address 0x%lx is invalid since top address should be page align. \n", TopLoadingAddress
));
431 // Search for a memory region that is below MAX_ADDRESS and in which TopLoadingAddress lies
433 for (Hob
.Raw
= PrivateData
->HobList
.Raw
; !END_OF_HOB_LIST(Hob
); Hob
.Raw
= GET_NEXT_HOB(Hob
)) {
435 // See if this is a resource descriptor HOB
437 if (GET_HOB_TYPE (Hob
) == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR
) {
439 ResourceHob
= Hob
.ResourceDescriptor
;
441 // See if this resource descrior HOB describes tested system memory below MAX_ADDRESS
443 if (ResourceHob
->ResourceType
== EFI_RESOURCE_SYSTEM_MEMORY
&&
444 ResourceHob
->PhysicalStart
+ ResourceHob
->ResourceLength
<= MAX_ADDRESS
) {
446 // See if Top address specified by user is valid.
448 if (ResourceHob
->PhysicalStart
+ TotalReservedMemorySize
< TopLoadingAddress
&&
449 (ResourceHob
->PhysicalStart
+ ResourceHob
->ResourceLength
- MINIMUM_INITIAL_MEMORY_SIZE
) >= TopLoadingAddress
&&
450 PeiLoadFixAddressIsMemoryRangeAvailable(PrivateData
, ResourceHob
)) {
451 CurrentResourceHob
= ResourceHob
;
458 if (CurrentResourceHob
!= NULL
) {
459 DEBUG ((EFI_D_INFO
, "LOADING MODULE FIXED INFO:Top Address 0x%lx is valid \n", TopLoadingAddress
));
460 TopLoadingAddress
+= MINIMUM_INITIAL_MEMORY_SIZE
;
462 DEBUG ((EFI_D_INFO
, "LOADING MODULE FIXED ERROR:Top Address 0x%lx is invalid \n", TopLoadingAddress
));
463 DEBUG ((EFI_D_INFO
, "LOADING MODULE FIXED ERROR:The recommended Top Address for the platform is: \n"));
465 // Print the recomended Top address range.
467 for (Hob
.Raw
= PrivateData
->HobList
.Raw
; !END_OF_HOB_LIST(Hob
); Hob
.Raw
= GET_NEXT_HOB(Hob
)) {
469 // See if this is a resource descriptor HOB
471 if (GET_HOB_TYPE (Hob
) == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR
) {
473 ResourceHob
= Hob
.ResourceDescriptor
;
475 // See if this resource descrior HOB describes tested system memory below MAX_ADDRESS
477 if (ResourceHob
->ResourceType
== EFI_RESOURCE_SYSTEM_MEMORY
&&
478 ResourceHob
->PhysicalStart
+ ResourceHob
->ResourceLength
<= MAX_ADDRESS
) {
480 // See if Top address specified by user is valid.
482 if (ResourceHob
->ResourceLength
> TotalReservedMemorySize
&& PeiLoadFixAddressIsMemoryRangeAvailable(PrivateData
, ResourceHob
)) {
483 DEBUG ((EFI_D_INFO
, "(0x%lx, 0x%lx)\n",
484 (ResourceHob
->PhysicalStart
+ TotalReservedMemorySize
-MINIMUM_INITIAL_MEMORY_SIZE
),
485 (ResourceHob
->PhysicalStart
+ ResourceHob
->ResourceLength
-MINIMUM_INITIAL_MEMORY_SIZE
)
499 // The LMFA feature is enabled as load module at fixed offset relative to TOLM
500 // Parse the Hob list to find the topest available memory. Generally it is (TOLM - TSEG)
503 // Search for a tested memory region that is below MAX_ADDRESS
505 for (Hob
.Raw
= PrivateData
->HobList
.Raw
; !END_OF_HOB_LIST(Hob
); Hob
.Raw
= GET_NEXT_HOB(Hob
)) {
507 // See if this is a resource descriptor HOB
509 if (GET_HOB_TYPE (Hob
) == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR
) {
511 ResourceHob
= Hob
.ResourceDescriptor
;
513 // See if this resource descrior HOB describes tested system memory below MAX_ADDRESS
515 if (ResourceHob
->ResourceType
== EFI_RESOURCE_SYSTEM_MEMORY
&&
516 ResourceHob
->PhysicalStart
+ ResourceHob
->ResourceLength
<= MAX_ADDRESS
&&
517 ResourceHob
->ResourceLength
> TotalReservedMemorySize
&& PeiLoadFixAddressIsMemoryRangeAvailable(PrivateData
, ResourceHob
)) {
519 // See if this is the highest largest system memory region below MaxAddress
521 if (ResourceHob
->PhysicalStart
> HighAddress
) {
522 CurrentResourceHob
= ResourceHob
;
524 HighAddress
= CurrentResourceHob
->PhysicalStart
;
529 if (CurrentResourceHob
== NULL
) {
530 DEBUG ((EFI_D_INFO
, "LOADING MODULE FIXED ERROR:The System Memory is too small\n"));
537 TopLoadingAddress
= CurrentResourceHob
->PhysicalStart
+ CurrentResourceHob
->ResourceLength
;
541 if (CurrentResourceHob
!= NULL
) {
543 // rebuild resource HOB for PEI memmory and reserved memory
545 BuildResourceDescriptorHob (
546 EFI_RESOURCE_SYSTEM_MEMORY
,
548 EFI_RESOURCE_ATTRIBUTE_PRESENT
|
549 EFI_RESOURCE_ATTRIBUTE_INITIALIZED
|
550 EFI_RESOURCE_ATTRIBUTE_TESTED
|
551 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE
|
552 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE
|
553 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE
|
554 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE
556 (TopLoadingAddress
- TotalReservedMemorySize
),
557 TotalReservedMemorySize
560 // rebuild resource for the remain memory if necessary
562 if (CurrentResourceHob
->PhysicalStart
< TopLoadingAddress
- TotalReservedMemorySize
) {
563 BuildResourceDescriptorHob (
564 EFI_RESOURCE_SYSTEM_MEMORY
,
566 EFI_RESOURCE_ATTRIBUTE_PRESENT
|
567 EFI_RESOURCE_ATTRIBUTE_INITIALIZED
|
568 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE
|
569 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE
|
570 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE
|
571 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE
573 CurrentResourceHob
->PhysicalStart
,
574 (TopLoadingAddress
- TotalReservedMemorySize
- CurrentResourceHob
->PhysicalStart
)
577 if (CurrentResourceHob
->PhysicalStart
+ CurrentResourceHob
->ResourceLength
> TopLoadingAddress
) {
578 BuildResourceDescriptorHob (
579 EFI_RESOURCE_SYSTEM_MEMORY
,
581 EFI_RESOURCE_ATTRIBUTE_PRESENT
|
582 EFI_RESOURCE_ATTRIBUTE_INITIALIZED
|
583 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE
|
584 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE
|
585 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE
|
586 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE
589 (CurrentResourceHob
->PhysicalStart
+ CurrentResourceHob
->ResourceLength
- TopLoadingAddress
)
593 // Delete CurrentHob by marking it as unused since the the memory range described by is rebuilt.
595 GET_HOB_TYPE (CurrentHob
) = EFI_HOB_TYPE_UNUSED
;
599 // Cache the top address for Loading Module at Fixed Address feature
601 PrivateData
->LoadModuleAtFixAddressTopAddress
= TopLoadingAddress
- MINIMUM_INITIAL_MEMORY_SIZE
;
602 DEBUG ((EFI_D_INFO
, "LOADING MODULE FIXED INFO: Top address = 0x%lx\n", PrivateData
->LoadModuleAtFixAddressTopAddress
));
604 // reinstall the PEI memory relative to TopLoadingAddress
606 PrivateData
->PhysicalMemoryBegin
= TopLoadingAddress
- TotalReservedMemorySize
;
607 PrivateData
->FreePhysicalMemoryTop
= PrivateData
->PhysicalMemoryBegin
+ PeiMemorySize
;
610 Conduct PEIM dispatch.
612 @param SecCoreData Points to a data structure containing information about the PEI core's operating
613 environment, such as the size and location of temporary RAM, the stack location and
615 @param Private Pointer to the private data passed in from caller
620 IN CONST EFI_SEC_PEI_HAND_OFF
*SecCoreData
,
621 IN PEI_CORE_INSTANCE
*Private
627 CONST EFI_PEI_SERVICES
**PeiServices
;
628 EFI_PEI_FILE_HANDLE PeimFileHandle
;
631 UINT32 AuthenticationState
;
632 EFI_PHYSICAL_ADDRESS EntryPoint
;
633 EFI_PEIM_ENTRY_POINT2 PeimEntryPoint
;
634 UINTN SaveCurrentPeimCount
;
635 UINTN SaveCurrentFvCount
;
636 EFI_PEI_FILE_HANDLE SaveCurrentFileHandle
;
637 PEIM_FILE_HANDLE_EXTENDED_DATA ExtendedData
;
638 TEMPORARY_RAM_SUPPORT_PPI
*TemporaryRamSupportPpi
;
640 EFI_PHYSICAL_ADDRESS TopOfNewStack
;
641 EFI_PHYSICAL_ADDRESS TopOfOldStack
;
642 EFI_PHYSICAL_ADDRESS TemporaryRamBase
;
643 UINTN TemporaryRamSize
;
644 EFI_PHYSICAL_ADDRESS TemporaryStackSize
;
646 BOOLEAN StackOffsetPositive
;
647 EFI_FV_FILE_INFO FvFileInfo
;
648 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
649 VOID
*LoadFixPeiCodeBegin
;
651 PeiServices
= (CONST EFI_PEI_SERVICES
**) &Private
->Ps
;
652 PeimEntryPoint
= NULL
;
653 PeimFileHandle
= NULL
;
656 if ((Private
->PeiMemoryInstalled
) && (Private
->HobList
.HandoffInformationTable
->BootMode
!= BOOT_ON_S3_RESUME
)) {
658 // Once real memory is available, shadow the RegisterForShadow modules. And meanwhile
659 // update the modules' status from PEIM_STATE_REGISITER_FOR_SHADOW to PEIM_STATE_DONE.
661 SaveCurrentPeimCount
= Private
->CurrentPeimCount
;
662 SaveCurrentFvCount
= Private
->CurrentPeimFvCount
;
663 SaveCurrentFileHandle
= Private
->CurrentFileHandle
;
665 for (Index1
= 0; Index1
<= SaveCurrentFvCount
; Index1
++) {
666 for (Index2
= 0; (Index2
< FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv
)) && (Private
->Fv
[Index1
].FvFileHandles
[Index2
] != NULL
); Index2
++) {
667 if (Private
->Fv
[Index1
].PeimState
[Index2
] == PEIM_STATE_REGISITER_FOR_SHADOW
) {
668 PeimFileHandle
= Private
->Fv
[Index1
].FvFileHandles
[Index2
];
669 Status
= PeiLoadImage (
670 (CONST EFI_PEI_SERVICES
**) &Private
->Ps
,
672 PEIM_STATE_REGISITER_FOR_SHADOW
,
676 if (Status
== EFI_SUCCESS
) {
678 // PEIM_STATE_REGISITER_FOR_SHADOW move to PEIM_STATE_DONE
680 Private
->Fv
[Index1
].PeimState
[Index2
]++;
681 Private
->CurrentFileHandle
= PeimFileHandle
;
682 Private
->CurrentPeimFvCount
= Index1
;
683 Private
->CurrentPeimCount
= Index2
;
685 // Call the PEIM entry point
687 PeimEntryPoint
= (EFI_PEIM_ENTRY_POINT2
)(UINTN
)EntryPoint
;
689 PERF_START (PeimFileHandle
, "PEIM", NULL
, 0);
690 PeimEntryPoint(PeimFileHandle
, (const EFI_PEI_SERVICES
**) &Private
->Ps
);
691 PERF_END (PeimFileHandle
, "PEIM", NULL
, 0);
695 // Process the Notify list and dispatch any notifies for
696 // newly installed PPIs.
698 ProcessNotifyList (Private
);
702 Private
->CurrentFileHandle
= SaveCurrentFileHandle
;
703 Private
->CurrentPeimFvCount
= SaveCurrentFvCount
;
704 Private
->CurrentPeimCount
= SaveCurrentPeimCount
;
708 // This is the main dispatch loop. It will search known FVs for PEIMs and
709 // attempt to dispatch them. If any PEIM gets dispatched through a single
710 // pass of the dispatcher, it will start over from the Bfv again to see
711 // if any new PEIMs dependencies got satisfied. With a well ordered
712 // FV where PEIMs are found in the order their dependencies are also
713 // satisfied, this dipatcher should run only once.
717 // In case that reenter PeiCore happens, the last pass record is still available.
719 if (!Private
->PeimDispatcherReenter
) {
720 Private
->PeimNeedingDispatch
= FALSE
;
721 Private
->PeimDispatchOnThisPass
= FALSE
;
723 Private
->PeimDispatcherReenter
= FALSE
;
726 for (FvCount
= Private
->CurrentPeimFvCount
; FvCount
< Private
->FvCount
; FvCount
++) {
727 CoreFvHandle
= FindNextCoreFvHandle (Private
, FvCount
);
728 ASSERT (CoreFvHandle
!= NULL
);
731 // If the FV has corresponding EFI_PEI_FIRMWARE_VOLUME_PPI instance, then dispatch it.
733 if (CoreFvHandle
->FvPpi
== NULL
) {
737 Private
->CurrentPeimFvCount
= FvCount
;
739 if (Private
->CurrentPeimCount
== 0) {
741 // When going through each FV, at first, search Apriori file to
742 // reorder all PEIMs to ensure the PEIMs in Apriori file to get
743 // dispatch at first.
745 DiscoverPeimsAndOrderWithApriori (Private
, CoreFvHandle
);
749 // Start to dispatch all modules within the current Fv.
751 for (PeimCount
= Private
->CurrentPeimCount
;
752 (PeimCount
< FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv
)) && (Private
->CurrentFvFileHandles
[PeimCount
] != NULL
);
754 Private
->CurrentPeimCount
= PeimCount
;
755 PeimFileHandle
= Private
->CurrentFileHandle
= Private
->CurrentFvFileHandles
[PeimCount
];
757 if (Private
->Fv
[FvCount
].PeimState
[PeimCount
] == PEIM_STATE_NOT_DISPATCHED
) {
758 if (!DepexSatisfied (Private
, PeimFileHandle
, PeimCount
)) {
759 Private
->PeimNeedingDispatch
= TRUE
;
761 Status
= CoreFvHandle
->FvPpi
->GetFileInfo (CoreFvHandle
->FvPpi
, PeimFileHandle
, &FvFileInfo
);
762 ASSERT_EFI_ERROR (Status
);
763 if (FvFileInfo
.FileType
== EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
) {
765 // For Fv type file, Produce new FV PPI and FV hob
767 Status
= ProcessFvFile (&Private
->Fv
[FvCount
], PeimFileHandle
);
768 AuthenticationState
= 0;
771 // For PEIM driver, Load its entry point
773 Status
= PeiLoadImage (
776 PEIM_STATE_NOT_DISPATCHED
,
782 if ((Status
== EFI_SUCCESS
)) {
784 // The PEIM has its dependencies satisfied, and its entry point
785 // has been found, so invoke it.
787 PERF_START (PeimFileHandle
, "PEIM", NULL
, 0);
789 ExtendedData
.Handle
= (EFI_HANDLE
)PeimFileHandle
;
791 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (
793 (EFI_SOFTWARE_PEI_CORE
| EFI_SW_PC_INIT_BEGIN
),
794 (VOID
*)(&ExtendedData
),
795 sizeof (ExtendedData
)
798 Status
= VerifyPeim (Private
, CoreFvHandle
->FvHandle
, PeimFileHandle
);
799 if (Status
!= EFI_SECURITY_VIOLATION
&& (AuthenticationState
== 0)) {
801 // PEIM_STATE_NOT_DISPATCHED move to PEIM_STATE_DISPATCHED
803 Private
->Fv
[FvCount
].PeimState
[PeimCount
]++;
805 if (FvFileInfo
.FileType
!= EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
) {
807 // Call the PEIM entry point for PEIM driver
809 PeimEntryPoint
= (EFI_PEIM_ENTRY_POINT2
)(UINTN
)EntryPoint
;
810 PeimEntryPoint (PeimFileHandle
, (const EFI_PEI_SERVICES
**) PeiServices
);
813 Private
->PeimDispatchOnThisPass
= TRUE
;
816 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (
818 (EFI_SOFTWARE_PEI_CORE
| EFI_SW_PC_INIT_BEGIN
),
819 (VOID
*)(&ExtendedData
),
820 sizeof (ExtendedData
)
822 PERF_END (PeimFileHandle
, "PEIM", NULL
, 0);
826 if (Private
->SwitchStackSignal
) {
828 // Before switch stack from temporary memory to permenent memory, caculate the heap and stack
829 // usage in temporary memory for debuging.
832 UINT32
*StackPointer
;
834 for (StackPointer
= (UINT32
*)SecCoreData
->StackBase
;
835 (StackPointer
< (UINT32
*)((UINTN
)SecCoreData
->StackBase
+ SecCoreData
->StackSize
)) \
836 && (*StackPointer
== INIT_CAR_VALUE
);
839 DEBUG ((EFI_D_INFO
, "Temp Stack : BaseAddress=0x%p Length=0x%X\n", SecCoreData
->StackBase
, (UINT32
)SecCoreData
->StackSize
));
840 DEBUG ((EFI_D_INFO
, "Temp Heap : BaseAddress=0x%p Length=0x%X\n", Private
->HobList
.Raw
, (UINT32
)((UINTN
) Private
->HobList
.HandoffInformationTable
->EfiFreeMemoryBottom
- (UINTN
) Private
->HobList
.Raw
)));
841 DEBUG ((EFI_D_INFO
, "Total temporary memory: %d bytes.\n", (UINT32
)SecCoreData
->TemporaryRamSize
));
842 DEBUG ((EFI_D_INFO
, " temporary memory stack ever used: %d bytes.\n",
843 (UINT32
)(SecCoreData
->StackSize
- ((UINTN
) StackPointer
- (UINTN
)SecCoreData
->StackBase
))
845 DEBUG ((EFI_D_INFO
, " temporary memory heap used: %d bytes.\n",
846 (UINT32
)((UINTN
)Private
->HobList
.HandoffInformationTable
->EfiFreeMemoryBottom
- (UINTN
)Private
->HobList
.Raw
)
850 if (PcdGet64(PcdLoadModuleAtFixAddressEnable
) != 0 && (Private
->HobList
.HandoffInformationTable
->BootMode
!= BOOT_ON_S3_RESUME
)) {
852 // Loading Module at Fixed Address is enabled
854 PeiLoadFixAddressHook (Private
);
857 // If Loading Module at Fixed Address is enabled, Allocating memory range for Pei code range.
859 LoadFixPeiCodeBegin
= AllocatePages((UINTN
)PcdGet32(PcdLoadFixAddressPeiCodePageNumber
));
860 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
)));
864 // Reserve the size of new stack at bottom of physical memory
866 // The size of new stack in permenent memory must be the same size
867 // or larger than the size of old stack in temporary memory.
868 // But if new stack is smaller than the size of old stack, we also reserve
869 // the size of old stack at bottom of permenent memory.
871 NewStackSize
= RShiftU64 (Private
->PhysicalMemoryLength
, 1);
872 NewStackSize
= ALIGN_VALUE (NewStackSize
, EFI_PAGE_SIZE
);
873 NewStackSize
= MIN (PcdGet32(PcdPeiCoreMaxPeiStackSize
), NewStackSize
);
874 DEBUG ((EFI_D_INFO
, "Old Stack size %d, New stack size %d\n", (UINT32
)SecCoreData
->StackSize
, (UINT32
)NewStackSize
));
875 ASSERT (NewStackSize
>= SecCoreData
->StackSize
);
878 // Caculate stack offset and heap offset between temporary memory and new permement
879 // memory seperately.
881 TopOfOldStack
= (UINTN
)SecCoreData
->StackBase
+ SecCoreData
->StackSize
;
882 TopOfNewStack
= Private
->PhysicalMemoryBegin
+ NewStackSize
;
883 if (TopOfNewStack
>= (UINTN
)SecCoreData
->PeiTemporaryRamBase
) {
884 Private
->HeapOffsetPositive
= TRUE
;
885 Private
->HeapOffset
= (UINTN
)(TopOfNewStack
- (UINTN
)SecCoreData
->PeiTemporaryRamBase
);
887 Private
->HeapOffsetPositive
= FALSE
;
888 Private
->HeapOffset
= (UINTN
)((UINTN
)SecCoreData
->PeiTemporaryRamBase
- TopOfNewStack
);
890 if (TopOfNewStack
>= TopOfOldStack
) {
891 StackOffsetPositive
= TRUE
;
892 StackOffset
= (UINTN
)(TopOfNewStack
- TopOfOldStack
);
894 StackOffsetPositive
= FALSE
;
895 StackOffset
= (UINTN
)(TopOfOldStack
- TopOfNewStack
);
898 DEBUG ((EFI_D_INFO
, "Heap Offset = 0x%lX Stack Offset = 0x%lX\n", (UINT64
)Private
->HeapOffset
, (UINT64
)(StackOffset
)));
901 // Build Stack HOB that describes the permanent memory stack
903 DEBUG ((EFI_D_INFO
, "Stack Hob: BaseAddress=0x%lX Length=0x%lX\n", TopOfNewStack
- NewStackSize
, NewStackSize
));
904 BuildStackHob (TopOfNewStack
- NewStackSize
, NewStackSize
);
907 // Cache information from SecCoreData into locals before SecCoreData is converted to a permanent memory address
909 TemporaryRamBase
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)SecCoreData
->TemporaryRamBase
;
910 TemporaryRamSize
= SecCoreData
->TemporaryRamSize
;
911 TemporaryStackSize
= SecCoreData
->StackSize
;
914 // Caculate new HandOffTable and PrivateData address in permanent memory's stack
916 if (StackOffsetPositive
) {
917 SecCoreData
= (CONST EFI_SEC_PEI_HAND_OFF
*)((UINTN
)(VOID
*)SecCoreData
+ StackOffset
);
918 Private
= (PEI_CORE_INSTANCE
*)((UINTN
)(VOID
*)Private
+ StackOffset
);
920 SecCoreData
= (CONST EFI_SEC_PEI_HAND_OFF
*)((UINTN
)(VOID
*)SecCoreData
- StackOffset
);
921 Private
= (PEI_CORE_INSTANCE
*)((UINTN
)(VOID
*)Private
- StackOffset
);
925 // TemporaryRamSupportPpi is produced by platform's SEC
927 Status
= PeiServicesLocatePpi (
928 &gEfiTemporaryRamSupportPpiGuid
,
931 (VOID
**)&TemporaryRamSupportPpi
933 if (!EFI_ERROR (Status
)) {
935 // Temporary Ram Support PPI is provided by platform, it will copy
936 // temporary memory to permenent memory and do stack switching.
937 // After invoking Temporary Ram Support PPI, the following code's
938 // stack is in permanent memory.
940 TemporaryRamSupportPpi
->TemporaryRamMigration (
943 (EFI_PHYSICAL_ADDRESS
)(UINTN
)(TopOfNewStack
- TemporaryStackSize
),
949 // In IA32/x64/Itanium architecture, we need platform provide
950 // TEMPORARY_RAM_MIGRATION_PPI.
958 PeiCore (SecCoreData
, NULL
, Private
);
961 // Code should not come here
967 // Process the Notify list and dispatch any notifies for
968 // newly installed PPIs.
970 ProcessNotifyList (Private
);
972 if ((Private
->PeiMemoryInstalled
) && (Private
->Fv
[FvCount
].PeimState
[PeimCount
] == PEIM_STATE_REGISITER_FOR_SHADOW
) && \
973 (Private
->HobList
.HandoffInformationTable
->BootMode
!= BOOT_ON_S3_RESUME
)) {
975 // If memory is availble we shadow images by default for performance reasons.
976 // We call the entry point a 2nd time so the module knows it's shadowed.
978 //PERF_START (PeiServices, L"PEIM", PeimFileHandle, 0);
979 ASSERT (PeimEntryPoint
!= NULL
);
980 PeimEntryPoint (PeimFileHandle
, (const EFI_PEI_SERVICES
**) PeiServices
);
981 //PERF_END (PeiServices, L"PEIM", PeimFileHandle, 0);
984 // PEIM_STATE_REGISITER_FOR_SHADOW move to PEIM_STATE_DONE
986 Private
->Fv
[FvCount
].PeimState
[PeimCount
]++;
989 // Process the Notify list and dispatch any notifies for
990 // newly installed PPIs.
992 ProcessNotifyList (Private
);
999 // We set to NULL here to optimize the 2nd entry to this routine after
1000 // memory is found. This reprevents rescanning of the FV. We set to
1001 // NULL here so we start at the begining of the next FV
1003 Private
->CurrentFileHandle
= NULL
;
1004 Private
->CurrentPeimCount
= 0;
1006 // Before walking through the next FV,Private->CurrentFvFileHandles[]should set to NULL
1008 SetMem (Private
->CurrentFvFileHandles
, sizeof (Private
->CurrentFvFileHandles
), 0);
1012 // Before making another pass, we should set Private->CurrentPeimFvCount =0 to go
1013 // through all the FV.
1015 Private
->CurrentPeimFvCount
= 0;
1018 // PeimNeedingDispatch being TRUE means we found a PEIM that did not get
1019 // dispatched. So we need to make another pass
1021 // PeimDispatchOnThisPass being TRUE means we dispatched a PEIM on this
1022 // pass. If we did not dispatch a PEIM there is no point in trying again
1023 // as it will fail the next time too (nothing has changed).
1025 } while (Private
->PeimNeedingDispatch
&& Private
->PeimDispatchOnThisPass
);
1030 Initialize the Dispatcher's data members
1032 @param PrivateData PeiCore's private data structure
1033 @param OldCoreData Old data from SecCore
1034 NULL if being run in non-permament memory mode.
1035 @param SecCoreData Points to a data structure containing information about the PEI core's operating
1036 environment, such as the size and location of temporary RAM, the stack location and
1043 InitializeDispatcherData (
1044 IN PEI_CORE_INSTANCE
*PrivateData
,
1045 IN PEI_CORE_INSTANCE
*OldCoreData
,
1046 IN CONST EFI_SEC_PEI_HAND_OFF
*SecCoreData
1049 if (OldCoreData
== NULL
) {
1050 PrivateData
->PeimDispatcherReenter
= FALSE
;
1051 PeiInitializeFv (PrivateData
, SecCoreData
);
1053 PeiReinitializeFv (PrivateData
);
1060 This routine parses the Dependency Expression, if available, and
1061 decides if the module can be executed.
1064 @param Private PeiCore's private data structure
1065 @param FileHandle PEIM's file handle
1066 @param PeimCount Peim count in all dispatched PEIMs.
1068 @retval TRUE Can be dispatched
1069 @retval FALSE Cannot be dispatched
1074 IN PEI_CORE_INSTANCE
*Private
,
1075 IN EFI_PEI_FILE_HANDLE FileHandle
,
1082 if (PeimCount
< Private
->AprioriCount
) {
1084 // If its in the A priori file then we set Depex to TRUE
1090 // Depex section not in the encapsulated section.
1092 Status
= PeiServicesFfsFindSectionData (
1093 EFI_SECTION_PEI_DEPEX
,
1098 if (EFI_ERROR (Status
)) {
1100 // If there is no DEPEX, assume the module can be executed
1106 // Evaluate a given DEPEX
1108 return PeimDispatchReadiness (&Private
->Ps
, DepexData
);
1112 This routine enable a PEIM to register itself to shadow when PEI Foundation
1113 discovery permanent memory.
1115 @param FileHandle File handle of a PEIM.
1117 @retval EFI_NOT_FOUND The file handle doesn't point to PEIM itself.
1118 @retval EFI_ALREADY_STARTED Indicate that the PEIM has been registered itself.
1119 @retval EFI_SUCCESS Successfully to register itself.
1124 PeiRegisterForShadow (
1125 IN EFI_PEI_FILE_HANDLE FileHandle
1128 PEI_CORE_INSTANCE
*Private
;
1129 Private
= PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer ());
1131 if (Private
->CurrentFileHandle
!= FileHandle
) {
1133 // The FileHandle must be for the current PEIM
1135 return EFI_NOT_FOUND
;
1138 if (Private
->Fv
[Private
->CurrentPeimFvCount
].PeimState
[Private
->CurrentPeimCount
] >= PEIM_STATE_REGISITER_FOR_SHADOW
) {
1140 // If the PEIM has already entered the PEIM_STATE_REGISTER_FOR_SHADOW or PEIM_STATE_DONE then it's already been started
1142 return EFI_ALREADY_STARTED
;
1145 Private
->Fv
[Private
->CurrentPeimFvCount
].PeimState
[Private
->CurrentPeimCount
] = PEIM_STATE_REGISITER_FOR_SHADOW
;