2 EFI PEI Core dispatch services
4 Copyright (c) 2006 - 2013, 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_FILE_HANDLE FileHandle
;
45 EFI_PEI_FILE_HANDLE AprioriFileHandle
;
52 EFI_PEI_FILE_HANDLE TempFileHandles
[FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv
) + 1];
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 Status
= EFI_NOT_FOUND
;
79 for (PeimCount
= 0; PeimCount
<= FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv
); PeimCount
++) {
80 Status
= FvPpi
->FindFileByType (FvPpi
, PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE
, CoreFileHandle
->FvHandle
, &FileHandle
);
81 if (Status
!= EFI_SUCCESS
|| PeimCount
== FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv
)) {
85 Private
->CurrentFvFileHandles
[PeimCount
] = FileHandle
;
89 // Check whether the count of Peims exceeds the max support PEIMs in a FV image
90 // If more Peims are required in a FV image, PcdPeiCoreMaxPeimPerFv can be set to a larger value in DSC file.
92 ASSERT ((Status
!= EFI_SUCCESS
) || (PeimCount
< FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv
)));
95 // Get Apriori File handle
97 Private
->AprioriCount
= 0;
98 Status
= FvPpi
->FindFileByName (FvPpi
, &gPeiAprioriFileNameGuid
, &CoreFileHandle
->FvHandle
, &AprioriFileHandle
);
99 if (!EFI_ERROR(Status
) && AprioriFileHandle
!= NULL
) {
101 // Read the Apriori file
103 Status
= FvPpi
->FindSectionByType (FvPpi
, EFI_SECTION_RAW
, AprioriFileHandle
, (VOID
**) &Apriori
);
104 if (!EFI_ERROR (Status
)) {
106 // Calculate the number of PEIMs in the A Priori list
108 Status
= FvPpi
->GetFileInfo (FvPpi
, AprioriFileHandle
, &FileInfo
);
109 ASSERT_EFI_ERROR (Status
);
110 Private
->AprioriCount
= FileInfo
.BufferSize
;
111 if (IS_SECTION2 (FileInfo
.Buffer
)) {
112 Private
->AprioriCount
-= sizeof (EFI_COMMON_SECTION_HEADER2
);
114 Private
->AprioriCount
-= sizeof (EFI_COMMON_SECTION_HEADER
);
116 Private
->AprioriCount
/= sizeof (EFI_GUID
);
118 ZeroMem (FileGuid
, sizeof (FileGuid
));
119 for (Index
= 0; Index
< PeimCount
; Index
++) {
121 // Make an array of file name guids that matches the FileHandle array so we can convert
122 // quickly from file name to file handle
124 Status
= FvPpi
->GetFileInfo (FvPpi
, Private
->CurrentFvFileHandles
[Index
], &FileInfo
);
125 CopyMem (&FileGuid
[Index
], &FileInfo
.FileName
, sizeof(EFI_GUID
));
129 // Walk through FileGuid array to find out who is invalid PEIM guid in Apriori file.
130 // Add available PEIMs in Apriori file into TempFileHandles array at first.
133 for (Index
= 0; Index2
< Private
->AprioriCount
; Index
++) {
134 while (Index2
< Private
->AprioriCount
) {
135 Guid
= ScanGuid (FileGuid
, PeimCount
* sizeof (EFI_GUID
), &Apriori
[Index2
++]);
143 PeimIndex
= ((UINTN
)Guid
- (UINTN
)&FileGuid
[0])/sizeof (EFI_GUID
);
144 TempFileHandles
[Index
] = Private
->CurrentFvFileHandles
[PeimIndex
];
147 // Since we have copied the file handle we can remove it from this list.
149 Private
->CurrentFvFileHandles
[PeimIndex
] = NULL
;
153 // Update valid Aprioricount
155 Private
->AprioriCount
= Index
;
158 // Add in any PEIMs not in the Apriori file
160 for (;Index
< PeimCount
; Index
++) {
161 for (Index2
= 0; Index2
< PeimCount
; Index2
++) {
162 if (Private
->CurrentFvFileHandles
[Index2
] != NULL
) {
163 TempFileHandles
[Index
] = Private
->CurrentFvFileHandles
[Index2
];
164 Private
->CurrentFvFileHandles
[Index2
] = NULL
;
170 //Index the end of array contains re-range Pei moudle.
172 TempFileHandles
[Index
] = NULL
;
175 // Private->CurrentFvFileHandles is currently in PEIM in the FV order.
176 // We need to update it to start with files in the A Priori list and
177 // then the remaining files in PEIM order.
179 CopyMem (Private
->CurrentFvFileHandles
, TempFileHandles
, sizeof (Private
->CurrentFvFileHandles
));
183 // Cache the current Fv File Handle. So that we don't have to scan the Fv again.
184 // Instead, we can retrieve the file handles within this Fv from cachable data.
186 Private
->Fv
[Private
->CurrentPeimFvCount
].ScanFv
= TRUE
;
187 CopyMem (Private
->Fv
[Private
->CurrentPeimFvCount
].FvFileHandles
, Private
->CurrentFvFileHandles
, sizeof (Private
->CurrentFvFileHandles
));
192 // This is the minimum memory required by DxeCore initialization. When LMFA feature enabled,
193 // This part of memory still need reserved on the very top of memory so that the DXE Core could
194 // use these memory for data initialization. This macro should be sync with the same marco
195 // defined in DXE Core.
197 #define MINIMUM_INITIAL_MEMORY_SIZE 0x10000
199 This function is to test if the memory range described in resource HOB is available or not.
201 This function should only be invoked when Loading Module at Fixed Address(LMFA) feature is enabled. Some platform may allocate the
202 memory before PeiLoadFixAddressHook in invoked. so this function is to test if the memory range described by the input resource HOB is
205 @param PrivateData Pointer to the private data passed in from caller
206 @param ResourceHob Pointer to a resource HOB which described the memory range described by the input resource HOB
209 PeiLoadFixAddressIsMemoryRangeAvailable (
210 IN PEI_CORE_INSTANCE
*PrivateData
,
211 IN EFI_HOB_RESOURCE_DESCRIPTOR
*ResourceHob
214 EFI_HOB_MEMORY_ALLOCATION
*MemoryHob
;
216 EFI_PEI_HOB_POINTERS Hob
;
219 if (PrivateData
== NULL
|| ResourceHob
== NULL
) {
223 // test if the memory range describe in the HOB is already allocated.
225 for (Hob
.Raw
= PrivateData
->HobList
.Raw
; !END_OF_HOB_LIST(Hob
); Hob
.Raw
= GET_NEXT_HOB(Hob
)) {
227 // See if this is a memory allocation HOB
229 if (GET_HOB_TYPE (Hob
) == EFI_HOB_TYPE_MEMORY_ALLOCATION
) {
230 MemoryHob
= Hob
.MemoryAllocation
;
231 if(MemoryHob
->AllocDescriptor
.MemoryBaseAddress
== ResourceHob
->PhysicalStart
&&
232 MemoryHob
->AllocDescriptor
.MemoryBaseAddress
+ MemoryHob
->AllocDescriptor
.MemoryLength
== ResourceHob
->PhysicalStart
+ ResourceHob
->ResourceLength
) {
243 Hook function for Loading Module at Fixed Address feature
245 This function should only be invoked when Loading Module at Fixed Address(LMFA) feature is enabled. When feature is
246 configured as Load Modules at Fix Absolute Address, this function is to validate the top address assigned by user. When
247 feature is configured as Load Modules at Fixed Offset, the functino is to find the top address which is TOLM-TSEG in general.
248 And also the function will re-install PEI memory.
250 @param PrivateData Pointer to the private data passed in from caller
254 PeiLoadFixAddressHook(
255 IN PEI_CORE_INSTANCE
*PrivateData
258 EFI_PHYSICAL_ADDRESS TopLoadingAddress
;
259 UINT64 PeiMemorySize
;
260 UINT64 TotalReservedMemorySize
;
261 UINT64 MemoryRangeEnd
;
262 EFI_PHYSICAL_ADDRESS HighAddress
;
263 EFI_HOB_RESOURCE_DESCRIPTOR
*ResourceHob
;
264 EFI_HOB_RESOURCE_DESCRIPTOR
*NextResourceHob
;
265 EFI_HOB_RESOURCE_DESCRIPTOR
*CurrentResourceHob
;
266 EFI_PEI_HOB_POINTERS CurrentHob
;
267 EFI_PEI_HOB_POINTERS Hob
;
268 EFI_PEI_HOB_POINTERS NextHob
;
269 EFI_HOB_MEMORY_ALLOCATION
*MemoryHob
;
271 // Initialize Local Variables
273 CurrentResourceHob
= NULL
;
275 NextResourceHob
= NULL
;
277 TopLoadingAddress
= 0;
279 CurrentHob
.Raw
= PrivateData
->HobList
.Raw
;
280 PeiMemorySize
= PrivateData
->PhysicalMemoryLength
;
282 // The top reserved memory include 3 parts: the topest range is for DXE core initialization with the size MINIMUM_INITIAL_MEMORY_SIZE
283 // then RuntimeCodePage range and Boot time code range.
285 TotalReservedMemorySize
= MINIMUM_INITIAL_MEMORY_SIZE
+ EFI_PAGES_TO_SIZE(PcdGet32(PcdLoadFixAddressRuntimeCodePageNumber
));
286 TotalReservedMemorySize
+= EFI_PAGES_TO_SIZE(PcdGet32(PcdLoadFixAddressBootTimeCodePageNumber
)) ;
288 // PEI memory range lies below the top reserved memory
290 TotalReservedMemorySize
+= PeiMemorySize
;
292 DEBUG ((EFI_D_INFO
, "LOADING MODULE FIXED INFO: PcdLoadFixAddressRuntimeCodePageNumber= 0x%x.\n", PcdGet32(PcdLoadFixAddressRuntimeCodePageNumber
)));
293 DEBUG ((EFI_D_INFO
, "LOADING MODULE FIXED INFO: PcdLoadFixAddressBootTimeCodePageNumber= 0x%x.\n", PcdGet32(PcdLoadFixAddressBootTimeCodePageNumber
)));
294 DEBUG ((EFI_D_INFO
, "LOADING MODULE FIXED INFO: PcdLoadFixAddressPeiCodePageNumber= 0x%x.\n", PcdGet32(PcdLoadFixAddressPeiCodePageNumber
)));
295 DEBUG ((EFI_D_INFO
, "LOADING MODULE FIXED INFO: Total Reserved Memory Size = 0x%lx.\n", TotalReservedMemorySize
));
297 // Loop through the system memory typed hob to merge the adjacent memory range
299 for (Hob
.Raw
= PrivateData
->HobList
.Raw
; !END_OF_HOB_LIST(Hob
); Hob
.Raw
= GET_NEXT_HOB(Hob
)) {
301 // See if this is a resource descriptor HOB
303 if (GET_HOB_TYPE (Hob
) == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR
) {
305 ResourceHob
= Hob
.ResourceDescriptor
;
307 // If range described in this hob is not system memory or heigher than MAX_ADDRESS, ignored.
309 if (ResourceHob
->ResourceType
!= EFI_RESOURCE_SYSTEM_MEMORY
||
310 ResourceHob
->PhysicalStart
+ ResourceHob
->ResourceLength
> MAX_ADDRESS
) {
314 for (NextHob
.Raw
= PrivateData
->HobList
.Raw
; !END_OF_HOB_LIST(NextHob
); NextHob
.Raw
= GET_NEXT_HOB(NextHob
)) {
315 if (NextHob
.Raw
== Hob
.Raw
){
319 // See if this is a resource descriptor HOB
321 if (GET_HOB_TYPE (NextHob
) == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR
) {
323 NextResourceHob
= NextHob
.ResourceDescriptor
;
325 // test if range described in this NextResourceHob is system memory and have the same attribute.
326 // Note: Here is a assumption that system memory should always be healthy even without test.
328 if (NextResourceHob
->ResourceType
== EFI_RESOURCE_SYSTEM_MEMORY
&&
329 (((NextResourceHob
->ResourceAttribute
^ResourceHob
->ResourceAttribute
)&(~EFI_RESOURCE_ATTRIBUTE_TESTED
)) == 0)){
332 // See if the memory range described in ResourceHob and NextResourceHob is adjacent
334 if ((ResourceHob
->PhysicalStart
<= NextResourceHob
->PhysicalStart
&&
335 ResourceHob
->PhysicalStart
+ ResourceHob
->ResourceLength
>= NextResourceHob
->PhysicalStart
)||
336 (ResourceHob
->PhysicalStart
>= NextResourceHob
->PhysicalStart
&&
337 ResourceHob
->PhysicalStart
<= NextResourceHob
->PhysicalStart
+ NextResourceHob
->ResourceLength
)) {
339 MemoryRangeEnd
= ((ResourceHob
->PhysicalStart
+ ResourceHob
->ResourceLength
)>(NextResourceHob
->PhysicalStart
+ NextResourceHob
->ResourceLength
)) ?
340 (ResourceHob
->PhysicalStart
+ ResourceHob
->ResourceLength
):(NextResourceHob
->PhysicalStart
+ NextResourceHob
->ResourceLength
);
342 ResourceHob
->PhysicalStart
= (ResourceHob
->PhysicalStart
< NextResourceHob
->PhysicalStart
) ?
343 ResourceHob
->PhysicalStart
: NextResourceHob
->PhysicalStart
;
346 ResourceHob
->ResourceLength
= (MemoryRangeEnd
- ResourceHob
->PhysicalStart
);
348 ResourceHob
->ResourceAttribute
= ResourceHob
->ResourceAttribute
& (~EFI_RESOURCE_ATTRIBUTE_TESTED
);
350 // Delete the NextResourceHob by marking it as unused.
352 GET_HOB_TYPE (NextHob
) = EFI_HOB_TYPE_UNUSED
;
361 // Some platform is already allocated pages before the HOB re-org. Here to build dedicated resource HOB to describe
362 // the allocated memory range
364 for (Hob
.Raw
= PrivateData
->HobList
.Raw
; !END_OF_HOB_LIST(Hob
); Hob
.Raw
= GET_NEXT_HOB(Hob
)) {
366 // See if this is a memory allocation HOB
368 if (GET_HOB_TYPE (Hob
) == EFI_HOB_TYPE_MEMORY_ALLOCATION
) {
369 MemoryHob
= Hob
.MemoryAllocation
;
370 for (NextHob
.Raw
= PrivateData
->HobList
.Raw
; !END_OF_HOB_LIST(NextHob
); NextHob
.Raw
= GET_NEXT_HOB(NextHob
)) {
372 // See if this is a resource descriptor HOB
374 if (GET_HOB_TYPE (NextHob
) == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR
) {
375 NextResourceHob
= NextHob
.ResourceDescriptor
;
377 // If range described in this hob is not system memory or heigher than MAX_ADDRESS, ignored.
379 if (NextResourceHob
->ResourceType
!= EFI_RESOURCE_SYSTEM_MEMORY
|| NextResourceHob
->PhysicalStart
+ NextResourceHob
->ResourceLength
> MAX_ADDRESS
) {
383 // If the range describe in memory allocation HOB belongs to the memroy range described by the resource hob
385 if (MemoryHob
->AllocDescriptor
.MemoryBaseAddress
>= NextResourceHob
->PhysicalStart
&&
386 MemoryHob
->AllocDescriptor
.MemoryBaseAddress
+ MemoryHob
->AllocDescriptor
.MemoryLength
<= NextResourceHob
->PhysicalStart
+ NextResourceHob
->ResourceLength
) {
388 // Build seperate resource hob for this allocated range
390 if (MemoryHob
->AllocDescriptor
.MemoryBaseAddress
> NextResourceHob
->PhysicalStart
) {
391 BuildResourceDescriptorHob (
392 EFI_RESOURCE_SYSTEM_MEMORY
,
393 NextResourceHob
->ResourceAttribute
,
394 NextResourceHob
->PhysicalStart
,
395 (MemoryHob
->AllocDescriptor
.MemoryBaseAddress
- NextResourceHob
->PhysicalStart
)
398 if (MemoryHob
->AllocDescriptor
.MemoryBaseAddress
+ MemoryHob
->AllocDescriptor
.MemoryLength
< NextResourceHob
->PhysicalStart
+ NextResourceHob
->ResourceLength
) {
399 BuildResourceDescriptorHob (
400 EFI_RESOURCE_SYSTEM_MEMORY
,
401 NextResourceHob
->ResourceAttribute
,
402 MemoryHob
->AllocDescriptor
.MemoryBaseAddress
+ MemoryHob
->AllocDescriptor
.MemoryLength
,
403 (NextResourceHob
->PhysicalStart
+ NextResourceHob
->ResourceLength
-(MemoryHob
->AllocDescriptor
.MemoryBaseAddress
+ MemoryHob
->AllocDescriptor
.MemoryLength
))
406 NextResourceHob
->PhysicalStart
= MemoryHob
->AllocDescriptor
.MemoryBaseAddress
;
407 NextResourceHob
->ResourceLength
= MemoryHob
->AllocDescriptor
.MemoryLength
;
416 // Try to find and validate the TOP address.
418 if ((INT64
)PcdGet64(PcdLoadModuleAtFixAddressEnable
) > 0 ) {
420 // The LMFA feature is enabled as load module at fixed absolute address.
422 TopLoadingAddress
= (EFI_PHYSICAL_ADDRESS
)PcdGet64(PcdLoadModuleAtFixAddressEnable
);
423 DEBUG ((EFI_D_INFO
, "LOADING MODULE FIXED INFO: Loading module at fixed absolute address.\n"));
425 // validate the Address. Loop the resource descriptor HOB to make sure the address is in valid memory range
427 if ((TopLoadingAddress
& EFI_PAGE_MASK
) != 0) {
428 DEBUG ((EFI_D_INFO
, "LOADING MODULE FIXED ERROR:Top Address 0x%lx is invalid since top address should be page align. \n", TopLoadingAddress
));
432 // Search for a memory region that is below MAX_ADDRESS and in which TopLoadingAddress lies
434 for (Hob
.Raw
= PrivateData
->HobList
.Raw
; !END_OF_HOB_LIST(Hob
); Hob
.Raw
= GET_NEXT_HOB(Hob
)) {
436 // See if this is a resource descriptor HOB
438 if (GET_HOB_TYPE (Hob
) == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR
) {
440 ResourceHob
= Hob
.ResourceDescriptor
;
442 // See if this resource descrior HOB describes tested system memory below MAX_ADDRESS
444 if (ResourceHob
->ResourceType
== EFI_RESOURCE_SYSTEM_MEMORY
&&
445 ResourceHob
->PhysicalStart
+ ResourceHob
->ResourceLength
<= MAX_ADDRESS
) {
447 // See if Top address specified by user is valid.
449 if (ResourceHob
->PhysicalStart
+ TotalReservedMemorySize
< TopLoadingAddress
&&
450 (ResourceHob
->PhysicalStart
+ ResourceHob
->ResourceLength
- MINIMUM_INITIAL_MEMORY_SIZE
) >= TopLoadingAddress
&&
451 PeiLoadFixAddressIsMemoryRangeAvailable(PrivateData
, ResourceHob
)) {
452 CurrentResourceHob
= ResourceHob
;
459 if (CurrentResourceHob
!= NULL
) {
460 DEBUG ((EFI_D_INFO
, "LOADING MODULE FIXED INFO:Top Address 0x%lx is valid \n", TopLoadingAddress
));
461 TopLoadingAddress
+= MINIMUM_INITIAL_MEMORY_SIZE
;
463 DEBUG ((EFI_D_INFO
, "LOADING MODULE FIXED ERROR:Top Address 0x%lx is invalid \n", TopLoadingAddress
));
464 DEBUG ((EFI_D_INFO
, "LOADING MODULE FIXED ERROR:The recommended Top Address for the platform is: \n"));
466 // Print the recomended Top address range.
468 for (Hob
.Raw
= PrivateData
->HobList
.Raw
; !END_OF_HOB_LIST(Hob
); Hob
.Raw
= GET_NEXT_HOB(Hob
)) {
470 // See if this is a resource descriptor HOB
472 if (GET_HOB_TYPE (Hob
) == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR
) {
474 ResourceHob
= Hob
.ResourceDescriptor
;
476 // See if this resource descrior HOB describes tested system memory below MAX_ADDRESS
478 if (ResourceHob
->ResourceType
== EFI_RESOURCE_SYSTEM_MEMORY
&&
479 ResourceHob
->PhysicalStart
+ ResourceHob
->ResourceLength
<= MAX_ADDRESS
) {
481 // See if Top address specified by user is valid.
483 if (ResourceHob
->ResourceLength
> TotalReservedMemorySize
&& PeiLoadFixAddressIsMemoryRangeAvailable(PrivateData
, ResourceHob
)) {
484 DEBUG ((EFI_D_INFO
, "(0x%lx, 0x%lx)\n",
485 (ResourceHob
->PhysicalStart
+ TotalReservedMemorySize
-MINIMUM_INITIAL_MEMORY_SIZE
),
486 (ResourceHob
->PhysicalStart
+ ResourceHob
->ResourceLength
-MINIMUM_INITIAL_MEMORY_SIZE
)
500 // The LMFA feature is enabled as load module at fixed offset relative to TOLM
501 // Parse the Hob list to find the topest available memory. Generally it is (TOLM - TSEG)
504 // Search for a tested memory region that is below MAX_ADDRESS
506 for (Hob
.Raw
= PrivateData
->HobList
.Raw
; !END_OF_HOB_LIST(Hob
); Hob
.Raw
= GET_NEXT_HOB(Hob
)) {
508 // See if this is a resource descriptor HOB
510 if (GET_HOB_TYPE (Hob
) == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR
) {
512 ResourceHob
= Hob
.ResourceDescriptor
;
514 // See if this resource descrior HOB describes tested system memory below MAX_ADDRESS
516 if (ResourceHob
->ResourceType
== EFI_RESOURCE_SYSTEM_MEMORY
&&
517 ResourceHob
->PhysicalStart
+ ResourceHob
->ResourceLength
<= MAX_ADDRESS
&&
518 ResourceHob
->ResourceLength
> TotalReservedMemorySize
&& PeiLoadFixAddressIsMemoryRangeAvailable(PrivateData
, ResourceHob
)) {
520 // See if this is the highest largest system memory region below MaxAddress
522 if (ResourceHob
->PhysicalStart
> HighAddress
) {
523 CurrentResourceHob
= ResourceHob
;
525 HighAddress
= CurrentResourceHob
->PhysicalStart
;
530 if (CurrentResourceHob
== NULL
) {
531 DEBUG ((EFI_D_INFO
, "LOADING MODULE FIXED ERROR:The System Memory is too small\n"));
538 TopLoadingAddress
= CurrentResourceHob
->PhysicalStart
+ CurrentResourceHob
->ResourceLength
;
542 if (CurrentResourceHob
!= NULL
) {
544 // rebuild resource HOB for PEI memmory and reserved memory
546 BuildResourceDescriptorHob (
547 EFI_RESOURCE_SYSTEM_MEMORY
,
549 EFI_RESOURCE_ATTRIBUTE_PRESENT
|
550 EFI_RESOURCE_ATTRIBUTE_INITIALIZED
|
551 EFI_RESOURCE_ATTRIBUTE_TESTED
|
552 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE
|
553 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE
|
554 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE
|
555 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE
557 (TopLoadingAddress
- TotalReservedMemorySize
),
558 TotalReservedMemorySize
561 // rebuild resource for the remain memory if necessary
563 if (CurrentResourceHob
->PhysicalStart
< TopLoadingAddress
- TotalReservedMemorySize
) {
564 BuildResourceDescriptorHob (
565 EFI_RESOURCE_SYSTEM_MEMORY
,
567 EFI_RESOURCE_ATTRIBUTE_PRESENT
|
568 EFI_RESOURCE_ATTRIBUTE_INITIALIZED
|
569 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE
|
570 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE
|
571 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE
|
572 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE
574 CurrentResourceHob
->PhysicalStart
,
575 (TopLoadingAddress
- TotalReservedMemorySize
- CurrentResourceHob
->PhysicalStart
)
578 if (CurrentResourceHob
->PhysicalStart
+ CurrentResourceHob
->ResourceLength
> TopLoadingAddress
) {
579 BuildResourceDescriptorHob (
580 EFI_RESOURCE_SYSTEM_MEMORY
,
582 EFI_RESOURCE_ATTRIBUTE_PRESENT
|
583 EFI_RESOURCE_ATTRIBUTE_INITIALIZED
|
584 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE
|
585 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE
|
586 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE
|
587 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE
590 (CurrentResourceHob
->PhysicalStart
+ CurrentResourceHob
->ResourceLength
- TopLoadingAddress
)
594 // Delete CurrentHob by marking it as unused since the the memory range described by is rebuilt.
596 GET_HOB_TYPE (CurrentHob
) = EFI_HOB_TYPE_UNUSED
;
600 // Cache the top address for Loading Module at Fixed Address feature
602 PrivateData
->LoadModuleAtFixAddressTopAddress
= TopLoadingAddress
- MINIMUM_INITIAL_MEMORY_SIZE
;
603 DEBUG ((EFI_D_INFO
, "LOADING MODULE FIXED INFO: Top address = 0x%lx\n", PrivateData
->LoadModuleAtFixAddressTopAddress
));
605 // reinstall the PEI memory relative to TopLoadingAddress
607 PrivateData
->PhysicalMemoryBegin
= TopLoadingAddress
- TotalReservedMemorySize
;
608 PrivateData
->FreePhysicalMemoryTop
= PrivateData
->PhysicalMemoryBegin
+ PeiMemorySize
;
612 This routine is invoked in switch stack as PeiCore Entry.
614 @param SecCoreData Points to a data structure containing information about the PEI core's operating
615 environment, such as the size and location of temporary RAM, the stack location and
617 @param Private Pointer to old core data that is used to initialize the
623 IN CONST EFI_SEC_PEI_HAND_OFF
*SecCoreData
,
624 IN PEI_CORE_INSTANCE
*Private
630 PeiCore (SecCoreData
, NULL
, Private
);
634 Conduct PEIM dispatch.
636 @param SecCoreData Points to a data structure containing information about the PEI core's operating
637 environment, such as the size and location of temporary RAM, the stack location and
639 @param Private Pointer to the private data passed in from caller
644 IN CONST EFI_SEC_PEI_HAND_OFF
*SecCoreData
,
645 IN PEI_CORE_INSTANCE
*Private
651 CONST EFI_PEI_SERVICES
**PeiServices
;
652 EFI_PEI_FILE_HANDLE PeimFileHandle
;
655 UINT32 AuthenticationState
;
656 EFI_PHYSICAL_ADDRESS EntryPoint
;
657 EFI_PEIM_ENTRY_POINT2 PeimEntryPoint
;
658 UINTN SaveCurrentPeimCount
;
659 UINTN SaveCurrentFvCount
;
660 EFI_PEI_FILE_HANDLE SaveCurrentFileHandle
;
661 PEIM_FILE_HANDLE_EXTENDED_DATA ExtendedData
;
662 EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI
*TemporaryRamSupportPpi
;
664 EFI_PHYSICAL_ADDRESS BaseOfNewHeap
;
665 EFI_PHYSICAL_ADDRESS TopOfNewStack
;
666 EFI_PHYSICAL_ADDRESS TopOfOldStack
;
667 EFI_PHYSICAL_ADDRESS TemporaryRamBase
;
668 UINTN TemporaryRamSize
;
669 UINTN TemporaryStackSize
;
670 VOID
*TemporaryStackBase
;
671 UINTN PeiTemporaryRamSize
;
672 VOID
*PeiTemporaryRamBase
;
674 BOOLEAN StackOffsetPositive
;
675 EFI_PHYSICAL_ADDRESS HoleMemBase
;
677 EFI_FV_FILE_INFO FvFileInfo
;
678 PEI_CORE_FV_HANDLE
*CoreFvHandle
;
679 VOID
*LoadFixPeiCodeBegin
;
680 EFI_PHYSICAL_ADDRESS TempBase1
;
682 EFI_PHYSICAL_ADDRESS TempBase2
;
686 PeiServices
= (CONST EFI_PEI_SERVICES
**) &Private
->Ps
;
687 PeimEntryPoint
= NULL
;
688 PeimFileHandle
= NULL
;
691 if ((Private
->PeiMemoryInstalled
) && (Private
->HobList
.HandoffInformationTable
->BootMode
!= BOOT_ON_S3_RESUME
|| PcdGetBool (PcdShadowPeimOnS3Boot
))) {
693 // Once real memory is available, shadow the RegisterForShadow modules. And meanwhile
694 // update the modules' status from PEIM_STATE_REGISITER_FOR_SHADOW to PEIM_STATE_DONE.
696 SaveCurrentPeimCount
= Private
->CurrentPeimCount
;
697 SaveCurrentFvCount
= Private
->CurrentPeimFvCount
;
698 SaveCurrentFileHandle
= Private
->CurrentFileHandle
;
700 for (Index1
= 0; Index1
<= SaveCurrentFvCount
; Index1
++) {
701 for (Index2
= 0; (Index2
< FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv
)) && (Private
->Fv
[Index1
].FvFileHandles
[Index2
] != NULL
); Index2
++) {
702 if (Private
->Fv
[Index1
].PeimState
[Index2
] == PEIM_STATE_REGISITER_FOR_SHADOW
) {
703 PeimFileHandle
= Private
->Fv
[Index1
].FvFileHandles
[Index2
];
704 Status
= PeiLoadImage (
705 (CONST EFI_PEI_SERVICES
**) &Private
->Ps
,
707 PEIM_STATE_REGISITER_FOR_SHADOW
,
711 if (Status
== EFI_SUCCESS
) {
713 // PEIM_STATE_REGISITER_FOR_SHADOW move to PEIM_STATE_DONE
715 Private
->Fv
[Index1
].PeimState
[Index2
]++;
716 Private
->CurrentFileHandle
= PeimFileHandle
;
717 Private
->CurrentPeimFvCount
= Index1
;
718 Private
->CurrentPeimCount
= Index2
;
720 // Call the PEIM entry point
722 PeimEntryPoint
= (EFI_PEIM_ENTRY_POINT2
)(UINTN
)EntryPoint
;
724 PERF_START (PeimFileHandle
, "PEIM", NULL
, 0);
725 PeimEntryPoint(PeimFileHandle
, (const EFI_PEI_SERVICES
**) &Private
->Ps
);
726 PERF_END (PeimFileHandle
, "PEIM", NULL
, 0);
730 // Process the Notify list and dispatch any notifies for
731 // newly installed PPIs.
733 ProcessNotifyList (Private
);
737 Private
->CurrentFileHandle
= SaveCurrentFileHandle
;
738 Private
->CurrentPeimFvCount
= SaveCurrentFvCount
;
739 Private
->CurrentPeimCount
= SaveCurrentPeimCount
;
743 // This is the main dispatch loop. It will search known FVs for PEIMs and
744 // attempt to dispatch them. If any PEIM gets dispatched through a single
745 // pass of the dispatcher, it will start over from the Bfv again to see
746 // if any new PEIMs dependencies got satisfied. With a well ordered
747 // FV where PEIMs are found in the order their dependencies are also
748 // satisfied, this dipatcher should run only once.
752 // In case that reenter PeiCore happens, the last pass record is still available.
754 if (!Private
->PeimDispatcherReenter
) {
755 Private
->PeimNeedingDispatch
= FALSE
;
756 Private
->PeimDispatchOnThisPass
= FALSE
;
758 Private
->PeimDispatcherReenter
= FALSE
;
761 for (FvCount
= Private
->CurrentPeimFvCount
; FvCount
< Private
->FvCount
; FvCount
++) {
762 CoreFvHandle
= FindNextCoreFvHandle (Private
, FvCount
);
763 ASSERT (CoreFvHandle
!= NULL
);
766 // If the FV has corresponding EFI_PEI_FIRMWARE_VOLUME_PPI instance, then dispatch it.
768 if (CoreFvHandle
->FvPpi
== NULL
) {
772 Private
->CurrentPeimFvCount
= FvCount
;
774 if (Private
->CurrentPeimCount
== 0) {
776 // When going through each FV, at first, search Apriori file to
777 // reorder all PEIMs to ensure the PEIMs in Apriori file to get
778 // dispatch at first.
780 DiscoverPeimsAndOrderWithApriori (Private
, CoreFvHandle
);
784 // Start to dispatch all modules within the current Fv.
786 for (PeimCount
= Private
->CurrentPeimCount
;
787 (PeimCount
< FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv
)) && (Private
->CurrentFvFileHandles
[PeimCount
] != NULL
);
789 Private
->CurrentPeimCount
= PeimCount
;
790 PeimFileHandle
= Private
->CurrentFileHandle
= Private
->CurrentFvFileHandles
[PeimCount
];
792 if (Private
->Fv
[FvCount
].PeimState
[PeimCount
] == PEIM_STATE_NOT_DISPATCHED
) {
793 if (!DepexSatisfied (Private
, PeimFileHandle
, PeimCount
)) {
794 Private
->PeimNeedingDispatch
= TRUE
;
796 Status
= CoreFvHandle
->FvPpi
->GetFileInfo (CoreFvHandle
->FvPpi
, PeimFileHandle
, &FvFileInfo
);
797 ASSERT_EFI_ERROR (Status
);
798 if (FvFileInfo
.FileType
== EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
) {
800 // For Fv type file, Produce new FV PPI and FV hob
802 Status
= ProcessFvFile (Private
, &Private
->Fv
[FvCount
], PeimFileHandle
);
803 if (Status
== EFI_SUCCESS
) {
805 // PEIM_STATE_NOT_DISPATCHED move to PEIM_STATE_DISPATCHED
807 Private
->Fv
[FvCount
].PeimState
[PeimCount
]++;
808 Private
->PeimDispatchOnThisPass
= TRUE
;
812 // For PEIM driver, Load its entry point
814 Status
= PeiLoadImage (
817 PEIM_STATE_NOT_DISPATCHED
,
821 if (Status
== EFI_SUCCESS
) {
823 // The PEIM has its dependencies satisfied, and its entry point
824 // has been found, so invoke it.
826 PERF_START (PeimFileHandle
, "PEIM", NULL
, 0);
828 ExtendedData
.Handle
= (EFI_HANDLE
)PeimFileHandle
;
830 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (
832 (EFI_SOFTWARE_PEI_CORE
| EFI_SW_PC_INIT_BEGIN
),
833 (VOID
*)(&ExtendedData
),
834 sizeof (ExtendedData
)
837 Status
= VerifyPeim (Private
, CoreFvHandle
->FvHandle
, PeimFileHandle
, AuthenticationState
);
838 if (Status
!= EFI_SECURITY_VIOLATION
) {
840 // PEIM_STATE_NOT_DISPATCHED move to PEIM_STATE_DISPATCHED
842 Private
->Fv
[FvCount
].PeimState
[PeimCount
]++;
844 // Call the PEIM entry point for PEIM driver
846 PeimEntryPoint
= (EFI_PEIM_ENTRY_POINT2
)(UINTN
)EntryPoint
;
847 PeimEntryPoint (PeimFileHandle
, (const EFI_PEI_SERVICES
**) PeiServices
);
848 Private
->PeimDispatchOnThisPass
= TRUE
;
851 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (
853 (EFI_SOFTWARE_PEI_CORE
| EFI_SW_PC_INIT_END
),
854 (VOID
*)(&ExtendedData
),
855 sizeof (ExtendedData
)
857 PERF_END (PeimFileHandle
, "PEIM", NULL
, 0);
862 if (Private
->SwitchStackSignal
) {
864 // Before switch stack from temporary memory to permenent memory, caculate the heap and stack
865 // usage in temporary memory for debuging.
868 UINT32
*StackPointer
;
870 for (StackPointer
= (UINT32
*)SecCoreData
->StackBase
;
871 (StackPointer
< (UINT32
*)((UINTN
)SecCoreData
->StackBase
+ SecCoreData
->StackSize
)) \
872 && (*StackPointer
== INIT_CAR_VALUE
);
875 DEBUG ((EFI_D_INFO
, "Temp Stack : BaseAddress=0x%p Length=0x%X\n", SecCoreData
->StackBase
, (UINT32
)SecCoreData
->StackSize
));
876 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
)));
877 DEBUG ((EFI_D_INFO
, "Total temporary memory: %d bytes.\n", (UINT32
)SecCoreData
->TemporaryRamSize
));
878 DEBUG ((EFI_D_INFO
, " temporary memory stack ever used: %d bytes.\n",
879 (UINT32
)(SecCoreData
->StackSize
- ((UINTN
) StackPointer
- (UINTN
)SecCoreData
->StackBase
))
881 DEBUG ((EFI_D_INFO
, " temporary memory heap used: %d bytes.\n",
882 (UINT32
)((UINTN
)Private
->HobList
.HandoffInformationTable
->EfiFreeMemoryBottom
- (UINTN
)Private
->HobList
.Raw
)
886 if (PcdGet64(PcdLoadModuleAtFixAddressEnable
) != 0 && (Private
->HobList
.HandoffInformationTable
->BootMode
!= BOOT_ON_S3_RESUME
)) {
888 // Loading Module at Fixed Address is enabled
890 PeiLoadFixAddressHook (Private
);
893 // If Loading Module at Fixed Address is enabled, Allocating memory range for Pei code range.
895 LoadFixPeiCodeBegin
= AllocatePages((UINTN
)PcdGet32(PcdLoadFixAddressPeiCodePageNumber
));
896 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
)));
900 // Reserve the size of new stack at bottom of physical memory
902 // The size of new stack in permenent memory must be the same size
903 // or larger than the size of old stack in temporary memory.
904 // But if new stack is smaller than the size of old stack, we also reserve
905 // the size of old stack at bottom of permenent memory.
907 NewStackSize
= RShiftU64 (Private
->PhysicalMemoryLength
, 1);
908 NewStackSize
= ALIGN_VALUE (NewStackSize
, EFI_PAGE_SIZE
);
909 NewStackSize
= MIN (PcdGet32(PcdPeiCoreMaxPeiStackSize
), NewStackSize
);
910 DEBUG ((EFI_D_INFO
, "Old Stack size %d, New stack size %d\n", (UINT32
)SecCoreData
->StackSize
, (UINT32
)NewStackSize
));
911 ASSERT (NewStackSize
>= SecCoreData
->StackSize
);
914 // Caculate stack offset and heap offset between temporary memory and new permement
915 // memory seperately.
917 TopOfOldStack
= (UINTN
)SecCoreData
->StackBase
+ SecCoreData
->StackSize
;
918 TopOfNewStack
= Private
->PhysicalMemoryBegin
+ NewStackSize
;
919 if (TopOfNewStack
>= TopOfOldStack
) {
920 StackOffsetPositive
= TRUE
;
921 StackOffset
= (UINTN
)(TopOfNewStack
- TopOfOldStack
);
923 StackOffsetPositive
= FALSE
;
924 StackOffset
= (UINTN
)(TopOfOldStack
- TopOfNewStack
);
926 Private
->StackOffsetPositive
= StackOffsetPositive
;
927 Private
->StackOffset
= StackOffset
;
929 DEBUG ((EFI_D_INFO
, "Heap Offset = 0x%lX Stack Offset = 0x%lX\n", (UINT64
)Private
->HeapOffset
, (UINT64
)(StackOffset
)));
932 // Build Stack HOB that describes the permanent memory stack
934 DEBUG ((EFI_D_INFO
, "Stack Hob: BaseAddress=0x%lX Length=0x%lX\n", TopOfNewStack
- NewStackSize
, NewStackSize
));
935 BuildStackHob (TopOfNewStack
- NewStackSize
, NewStackSize
);
938 // Cache information from SecCoreData into locals before SecCoreData is converted to a permanent memory address
940 TemporaryRamBase
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)SecCoreData
->TemporaryRamBase
;
941 TemporaryRamSize
= SecCoreData
->TemporaryRamSize
;
942 TemporaryStackSize
= SecCoreData
->StackSize
;
943 TemporaryStackBase
= SecCoreData
->StackBase
;
944 PeiTemporaryRamSize
= SecCoreData
->PeiTemporaryRamSize
;
945 PeiTemporaryRamBase
= SecCoreData
->PeiTemporaryRamBase
;
948 // TemporaryRamSupportPpi is produced by platform's SEC
950 Status
= PeiServicesLocatePpi (
951 &gEfiTemporaryRamSupportPpiGuid
,
954 (VOID
**)&TemporaryRamSupportPpi
956 if (!EFI_ERROR (Status
)) {
960 BaseOfNewHeap
= TopOfNewStack
;
961 if (BaseOfNewHeap
>= (UINTN
)SecCoreData
->PeiTemporaryRamBase
) {
962 Private
->HeapOffsetPositive
= TRUE
;
963 Private
->HeapOffset
= (UINTN
)(BaseOfNewHeap
- (UINTN
)SecCoreData
->PeiTemporaryRamBase
);
965 Private
->HeapOffsetPositive
= FALSE
;
966 Private
->HeapOffset
= (UINTN
)((UINTN
)SecCoreData
->PeiTemporaryRamBase
- BaseOfNewHeap
);
970 // Caculate new HandOffTable and PrivateData address in permanent memory's stack
972 if (StackOffsetPositive
) {
973 SecCoreData
= (CONST EFI_SEC_PEI_HAND_OFF
*)((UINTN
)(VOID
*)SecCoreData
+ StackOffset
);
974 Private
= (PEI_CORE_INSTANCE
*)((UINTN
)(VOID
*)Private
+ StackOffset
);
976 SecCoreData
= (CONST EFI_SEC_PEI_HAND_OFF
*)((UINTN
)(VOID
*)SecCoreData
- StackOffset
);
977 Private
= (PEI_CORE_INSTANCE
*)((UINTN
)(VOID
*)Private
- StackOffset
);
981 // Temporary Ram Support PPI is provided by platform, it will copy
982 // temporary memory to permenent memory and do stack switching.
983 // After invoking Temporary Ram Support PPI, the following code's
984 // stack is in permanent memory.
986 TemporaryRamSupportPpi
->TemporaryRamMigration (
989 (EFI_PHYSICAL_ADDRESS
)(UINTN
)(TopOfNewStack
- TemporaryStackSize
),
996 PeiCore (SecCoreData
, NULL
, Private
);
1001 BaseOfNewHeap
= TopOfNewStack
;
1002 HoleMemBase
= TopOfNewStack
;
1003 HoleMemSize
= TemporaryRamSize
- PeiTemporaryRamSize
- TemporaryStackSize
;
1004 if (HoleMemSize
!= 0) {
1006 // Make sure HOB List start address is 8 byte alignment.
1008 BaseOfNewHeap
= ALIGN_VALUE (BaseOfNewHeap
+ HoleMemSize
, 8);
1010 if (BaseOfNewHeap
>= (UINTN
)SecCoreData
->PeiTemporaryRamBase
) {
1011 Private
->HeapOffsetPositive
= TRUE
;
1012 Private
->HeapOffset
= (UINTN
)(BaseOfNewHeap
- (UINTN
)SecCoreData
->PeiTemporaryRamBase
);
1014 Private
->HeapOffsetPositive
= FALSE
;
1015 Private
->HeapOffset
= (UINTN
)((UINTN
)SecCoreData
->PeiTemporaryRamBase
- BaseOfNewHeap
);
1021 CopyMem ((UINT8
*) (UINTN
) BaseOfNewHeap
, (UINT8
*) PeiTemporaryRamBase
, PeiTemporaryRamSize
);
1026 CopyMem ((UINT8
*) (UINTN
) (TopOfNewStack
- TemporaryStackSize
), TemporaryStackBase
, TemporaryStackSize
);
1029 // Copy Hole Range Data
1030 // Convert PPI from Hole.
1032 if (HoleMemSize
!= 0) {
1036 if (PeiTemporaryRamBase
< TemporaryStackBase
) {
1037 TempBase1
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) PeiTemporaryRamBase
;
1038 TempSize1
= PeiTemporaryRamSize
;
1039 TempBase2
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) TemporaryStackBase
;
1040 TempSize2
= TemporaryStackSize
;
1042 TempBase1
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) TemporaryStackBase
;
1043 TempSize1
= TemporaryStackSize
;
1044 TempBase2
=(EFI_PHYSICAL_ADDRESS
) (UINTN
) PeiTemporaryRamBase
;
1045 TempSize2
= PeiTemporaryRamSize
;
1047 if (TemporaryRamBase
< TempBase1
) {
1048 Private
->HoleData
[0].Base
= TemporaryRamBase
;
1049 Private
->HoleData
[0].Size
= (UINTN
) (TempBase1
- TemporaryRamBase
);
1051 if (TempBase1
+ TempSize1
< TempBase2
) {
1052 Private
->HoleData
[1].Base
= TempBase1
+ TempSize1
;
1053 Private
->HoleData
[1].Size
= (UINTN
) (TempBase2
- TempBase1
- TempSize1
);
1055 if (TempBase2
+ TempSize2
< TemporaryRamBase
+ TemporaryRamSize
) {
1056 Private
->HoleData
[2].Base
= TempBase2
+ TempSize2
;
1057 Private
->HoleData
[2].Size
= (UINTN
) (TemporaryRamBase
+ TemporaryRamSize
- TempBase2
- TempSize2
);
1061 // Copy Hole Range data.
1063 for (Index
= 0; Index
< HOLE_MAX_NUMBER
; Index
++) {
1064 if (Private
->HoleData
[Index
].Size
> 0) {
1065 if (HoleMemBase
> Private
->HoleData
[Index
].Base
) {
1066 Private
->HoleData
[Index
].OffsetPositive
= TRUE
;
1067 Private
->HoleData
[Index
].Offset
= (UINTN
) (HoleMemBase
- Private
->HoleData
[Index
].Base
);
1069 Private
->HoleData
[Index
].OffsetPositive
= FALSE
;
1070 Private
->HoleData
[Index
].Offset
= (UINTN
) (Private
->HoleData
[Index
].Base
- HoleMemBase
);
1072 CopyMem ((VOID
*) (UINTN
) HoleMemBase
, (VOID
*) (UINTN
) Private
->HoleData
[Index
].Base
, Private
->HoleData
[Index
].Size
);
1073 HoleMemBase
= HoleMemBase
+ Private
->HoleData
[Index
].Size
;
1082 (SWITCH_STACK_ENTRY_POINT
)(UINTN
)PeiCoreEntry
,
1083 (VOID
*) SecCoreData
,
1085 (VOID
*) (UINTN
) TopOfNewStack
1090 // Code should not come here
1096 // Process the Notify list and dispatch any notifies for
1097 // newly installed PPIs.
1099 ProcessNotifyList (Private
);
1101 if ((Private
->PeiMemoryInstalled
) && (Private
->Fv
[FvCount
].PeimState
[PeimCount
] == PEIM_STATE_REGISITER_FOR_SHADOW
) && \
1102 (Private
->HobList
.HandoffInformationTable
->BootMode
!= BOOT_ON_S3_RESUME
|| PcdGetBool (PcdShadowPeimOnS3Boot
))) {
1104 // If memory is availble we shadow images by default for performance reasons.
1105 // We call the entry point a 2nd time so the module knows it's shadowed.
1107 //PERF_START (PeiServices, L"PEIM", PeimFileHandle, 0);
1108 ASSERT (PeimEntryPoint
!= NULL
);
1109 PeimEntryPoint (PeimFileHandle
, (const EFI_PEI_SERVICES
**) PeiServices
);
1110 //PERF_END (PeiServices, L"PEIM", PeimFileHandle, 0);
1113 // PEIM_STATE_REGISITER_FOR_SHADOW move to PEIM_STATE_DONE
1115 Private
->Fv
[FvCount
].PeimState
[PeimCount
]++;
1118 // Process the Notify list and dispatch any notifies for
1119 // newly installed PPIs.
1121 ProcessNotifyList (Private
);
1128 // We set to NULL here to optimize the 2nd entry to this routine after
1129 // memory is found. This reprevents rescanning of the FV. We set to
1130 // NULL here so we start at the begining of the next FV
1132 Private
->CurrentFileHandle
= NULL
;
1133 Private
->CurrentPeimCount
= 0;
1135 // Before walking through the next FV,Private->CurrentFvFileHandles[]should set to NULL
1137 SetMem (Private
->CurrentFvFileHandles
, sizeof (Private
->CurrentFvFileHandles
), 0);
1141 // Before making another pass, we should set Private->CurrentPeimFvCount =0 to go
1142 // through all the FV.
1144 Private
->CurrentPeimFvCount
= 0;
1147 // PeimNeedingDispatch being TRUE means we found a PEIM that did not get
1148 // dispatched. So we need to make another pass
1150 // PeimDispatchOnThisPass being TRUE means we dispatched a PEIM on this
1151 // pass. If we did not dispatch a PEIM there is no point in trying again
1152 // as it will fail the next time too (nothing has changed).
1154 } while (Private
->PeimNeedingDispatch
&& Private
->PeimDispatchOnThisPass
);
1159 Initialize the Dispatcher's data members
1161 @param PrivateData PeiCore's private data structure
1162 @param OldCoreData Old data from SecCore
1163 NULL if being run in non-permament memory mode.
1164 @param SecCoreData Points to a data structure containing information about the PEI core's operating
1165 environment, such as the size and location of temporary RAM, the stack location and
1172 InitializeDispatcherData (
1173 IN PEI_CORE_INSTANCE
*PrivateData
,
1174 IN PEI_CORE_INSTANCE
*OldCoreData
,
1175 IN CONST EFI_SEC_PEI_HAND_OFF
*SecCoreData
1178 if (OldCoreData
== NULL
) {
1179 PrivateData
->PeimDispatcherReenter
= FALSE
;
1180 PeiInitializeFv (PrivateData
, SecCoreData
);
1182 PeiReinitializeFv (PrivateData
);
1189 This routine parses the Dependency Expression, if available, and
1190 decides if the module can be executed.
1193 @param Private PeiCore's private data structure
1194 @param FileHandle PEIM's file handle
1195 @param PeimCount Peim count in all dispatched PEIMs.
1197 @retval TRUE Can be dispatched
1198 @retval FALSE Cannot be dispatched
1203 IN PEI_CORE_INSTANCE
*Private
,
1204 IN EFI_PEI_FILE_HANDLE FileHandle
,
1210 EFI_FV_FILE_INFO FileInfo
;
1212 Status
= PeiServicesFfsGetFileInfo (FileHandle
, &FileInfo
);
1213 if (EFI_ERROR (Status
)) {
1214 DEBUG ((DEBUG_DISPATCH
, "Evaluate PEI DEPEX for FFS(Unknown)\n"));
1216 DEBUG ((DEBUG_DISPATCH
, "Evaluate PEI DEPEX for FFS(%g)\n", &FileInfo
.FileName
));
1219 if (PeimCount
< Private
->AprioriCount
) {
1221 // If its in the A priori file then we set Depex to TRUE
1223 DEBUG ((DEBUG_DISPATCH
, " RESULT = TRUE (Apriori)\n"));
1228 // Depex section not in the encapsulated section.
1230 Status
= PeiServicesFfsFindSectionData (
1231 EFI_SECTION_PEI_DEPEX
,
1236 if (EFI_ERROR (Status
)) {
1238 // If there is no DEPEX, assume the module can be executed
1240 DEBUG ((DEBUG_DISPATCH
, " RESULT = TRUE (No DEPEX)\n"));
1245 // Evaluate a given DEPEX
1247 return PeimDispatchReadiness (&Private
->Ps
, DepexData
);
1251 This routine enable a PEIM to register itself to shadow when PEI Foundation
1252 discovery permanent memory.
1254 @param FileHandle File handle of a PEIM.
1256 @retval EFI_NOT_FOUND The file handle doesn't point to PEIM itself.
1257 @retval EFI_ALREADY_STARTED Indicate that the PEIM has been registered itself.
1258 @retval EFI_SUCCESS Successfully to register itself.
1263 PeiRegisterForShadow (
1264 IN EFI_PEI_FILE_HANDLE FileHandle
1267 PEI_CORE_INSTANCE
*Private
;
1268 Private
= PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer ());
1270 if (Private
->CurrentFileHandle
!= FileHandle
) {
1272 // The FileHandle must be for the current PEIM
1274 return EFI_NOT_FOUND
;
1277 if (Private
->Fv
[Private
->CurrentPeimFvCount
].PeimState
[Private
->CurrentPeimCount
] >= PEIM_STATE_REGISITER_FOR_SHADOW
) {
1279 // If the PEIM has already entered the PEIM_STATE_REGISTER_FOR_SHADOW or PEIM_STATE_DONE then it's already been started
1281 return EFI_ALREADY_STARTED
;
1284 Private
->Fv
[Private
->CurrentPeimFvCount
].PeimState
[Private
->CurrentPeimCount
] = PEIM_STATE_REGISITER_FOR_SHADOW
;