2 Pei Core Main Entry Point
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.
17 EFI_PEI_PPI_DESCRIPTOR mMemoryDiscoveredPpi
= {
18 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
19 &gEfiPeiMemoryDiscoveredPpiGuid
,
24 /// Pei service instance
26 EFI_PEI_SERVICES gPs
= {
28 PEI_SERVICES_SIGNATURE
,
29 PEI_SERVICES_REVISION
,
30 sizeof (EFI_PEI_SERVICES
),
47 PeiFfsFindSectionData
,
52 (EFI_PEI_COPY_MEM
)CopyMem
,
53 (EFI_PEI_SET_MEM
)SetMem
,
59 &gPeiDefaultPciCfg2Ppi
,
65 PeiFfsFindSectionData3
,
70 Shadow PeiCore module from flash to installed memory.
72 @param PrivateData PeiCore's private data structure
74 @return PeiCore function address after shadowing.
76 PEICORE_FUNCTION_POINTER
78 IN PEI_CORE_INSTANCE
*PrivateData
81 EFI_PEI_FILE_HANDLE PeiCoreFileHandle
;
82 EFI_PHYSICAL_ADDRESS EntryPoint
;
84 UINT32 AuthenticationState
;
86 PeiCoreFileHandle
= NULL
;
89 // Find the PEI Core in the BFV
91 Status
= PrivateData
->Fv
[0].FvPpi
->FindFileByType (
92 PrivateData
->Fv
[0].FvPpi
,
93 EFI_FV_FILETYPE_PEI_CORE
,
94 PrivateData
->Fv
[0].FvHandle
,
97 ASSERT_EFI_ERROR (Status
);
100 // Shadow PEI Core into memory so it will run faster
102 Status
= PeiLoadImage (
103 GetPeiServicesTablePointer (),
104 *((EFI_PEI_FILE_HANDLE
*)&PeiCoreFileHandle
),
105 PEIM_STATE_REGISITER_FOR_SHADOW
,
109 ASSERT_EFI_ERROR (Status
);
112 // Compute the PeiCore's function address after shaowed PeiCore.
113 // _ModuleEntryPoint is PeiCore main function entry
115 return (PEICORE_FUNCTION_POINTER
)((UINTN
) EntryPoint
+ (UINTN
) PeiCore
- (UINTN
) _ModuleEntryPoint
);
119 This routine is invoked by main entry of PeiMain module during transition
120 from SEC to PEI. After switching stack in the PEI core, it will restart
121 with the old core data.
123 @param SecCoreData Points to a data structure containing information about the PEI core's operating
124 environment, such as the size and location of temporary RAM, the stack location and
126 @param PpiList Points to a list of one or more PPI descriptors to be installed initially by the PEI core.
127 An empty PPI list consists of a single descriptor with the end-tag
128 EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST. As part of its initialization
129 phase, the PEI Foundation will add these SEC-hosted PPIs to its PPI database such
130 that both the PEI Foundation and any modules can leverage the associated service
131 calls and/or code in these early PPIs
132 @param Data Pointer to old core data that is used to initialize the
134 If NULL, it is first PeiCore entering.
140 IN CONST EFI_SEC_PEI_HAND_OFF
*SecCoreData
,
141 IN CONST EFI_PEI_PPI_DESCRIPTOR
*PpiList
,
145 PEI_CORE_INSTANCE PrivateData
;
147 PEI_CORE_TEMP_POINTERS TempPtr
;
148 PEI_CORE_INSTANCE
*OldCoreData
;
149 EFI_PEI_CPU_IO_PPI
*CpuIo
;
150 EFI_PEI_PCI_CFG2_PPI
*PciCfg
;
151 EFI_HOB_HANDOFF_INFO_TABLE
*HandoffInformationTable
;
154 // Retrieve context passed into PEI Core
156 OldCoreData
= (PEI_CORE_INSTANCE
*)Data
;
159 // Perform PEI Core phase specific actions.
161 if (OldCoreData
== NULL
) {
163 // If OldCoreData is NULL, means current is the first entry into the PEI Core before memory is available.
165 ZeroMem (&PrivateData
, sizeof (PEI_CORE_INSTANCE
));
166 PrivateData
.Signature
= PEI_CORE_HANDLE_SIGNATURE
;
167 CopyMem (&PrivateData
.ServiceTableShadow
, &gPs
, sizeof (gPs
));
170 // Memory is available to the PEI Core. See if the PEI Core has been shadowed to memory yet.
172 if (OldCoreData
->ShadowedPeiCore
== NULL
) {
174 // Fixup the PeiCore's private data
176 OldCoreData
->Ps
= &OldCoreData
->ServiceTableShadow
;
177 OldCoreData
->CpuIo
= &OldCoreData
->ServiceTableShadow
.CpuIo
;
178 if (OldCoreData
->HeapOffsetPositive
) {
179 OldCoreData
->HobList
.Raw
= (VOID
*)(OldCoreData
->HobList
.Raw
+ OldCoreData
->HeapOffset
);
181 OldCoreData
->HobList
.Raw
= (VOID
*)(OldCoreData
->HobList
.Raw
- OldCoreData
->HeapOffset
);
185 // Initialize libraries that the PEI Core is linked against
187 ProcessLibraryConstructorList (NULL
, (CONST EFI_PEI_SERVICES
**)&OldCoreData
->Ps
);
190 // Fixup for PeiService's address
192 SetPeiServicesTablePointer ((CONST EFI_PEI_SERVICES
**)&OldCoreData
->Ps
);
195 // Update HandOffHob for new installed permenent memory
197 HandoffInformationTable
= OldCoreData
->HobList
.HandoffInformationTable
;
198 if (OldCoreData
->HeapOffsetPositive
) {
199 HandoffInformationTable
->EfiEndOfHobList
= HandoffInformationTable
->EfiEndOfHobList
+ OldCoreData
->HeapOffset
;
201 HandoffInformationTable
->EfiEndOfHobList
= HandoffInformationTable
->EfiEndOfHobList
- OldCoreData
->HeapOffset
;
203 HandoffInformationTable
->EfiMemoryTop
= OldCoreData
->PhysicalMemoryBegin
+ OldCoreData
->PhysicalMemoryLength
;
204 HandoffInformationTable
->EfiMemoryBottom
= OldCoreData
->PhysicalMemoryBegin
;
205 HandoffInformationTable
->EfiFreeMemoryTop
= OldCoreData
->FreePhysicalMemoryTop
;
206 HandoffInformationTable
->EfiFreeMemoryBottom
= HandoffInformationTable
->EfiEndOfHobList
+ sizeof (EFI_HOB_GENERIC_HEADER
);
209 // We need convert the PPI descriptor's pointer
211 ConvertPpiPointers (SecCoreData
, OldCoreData
);
214 // After the whole temporary memory is migrated, then we can allocate page in
217 OldCoreData
->PeiMemoryInstalled
= TRUE
;
220 // Indicate that PeiCore reenter
222 OldCoreData
->PeimDispatcherReenter
= TRUE
;
224 if (PcdGet64(PcdLoadModuleAtFixAddressEnable
) != 0 && (OldCoreData
->HobList
.HandoffInformationTable
->BootMode
!= BOOT_ON_S3_RESUME
)) {
226 // if Loading Module at Fixed Address is enabled, allocate the PEI code memory range usage bit map array.
227 // Every bit in the array indicate the status of the corresponding memory page available or not
229 OldCoreData
->PeiCodeMemoryRangeUsageBitMap
= AllocateZeroPool (((PcdGet32(PcdLoadFixAddressPeiCodePageNumber
)>>6) + 1)*sizeof(UINT64
));
233 // Shadow PEI Core. When permanent memory is avaiable, shadow
234 // PEI Core and PEIMs to get high performance.
236 OldCoreData
->ShadowedPeiCore
= ShadowPeiCore (OldCoreData
);
239 // PEI Core has now been shadowed to memory. Restart PEI Core in memory.
241 OldCoreData
->ShadowedPeiCore (SecCoreData
, PpiList
, OldCoreData
);
244 // Should never reach here.
251 // Memory is available to the PEI Core and the PEI Core has been shadowed to memory.
254 CopyMem (&PrivateData
, OldCoreData
, sizeof (PrivateData
));
256 CpuIo
= (VOID
*)PrivateData
.ServiceTableShadow
.CpuIo
;
257 PciCfg
= (VOID
*)PrivateData
.ServiceTableShadow
.PciCfg
;
259 CopyMem (&PrivateData
.ServiceTableShadow
, &gPs
, sizeof (gPs
));
261 PrivateData
.ServiceTableShadow
.CpuIo
= CpuIo
;
262 PrivateData
.ServiceTableShadow
.PciCfg
= PciCfg
;
266 // Cache a pointer to the PEI Services Table that is either in temporary memory or permanent memory
268 PrivateData
.Ps
= &PrivateData
.ServiceTableShadow
;
271 // Initialize libraries that the PEI Core is linked against
273 ProcessLibraryConstructorList (NULL
, (CONST EFI_PEI_SERVICES
**)&PrivateData
.Ps
);
276 // Save PeiServicePointer so that it can be retrieved anywhere.
278 SetPeiServicesTablePointer ((CONST EFI_PEI_SERVICES
**)&PrivateData
.Ps
);
281 // Initialize PEI Core Services
283 InitializeMemoryServices (&PrivateData
, SecCoreData
, OldCoreData
);
284 InitializePpiServices (&PrivateData
, OldCoreData
);
287 // Update performance measurements
289 if (OldCoreData
== NULL
) {
290 PERF_START (NULL
, "SEC", NULL
, 1);
291 PERF_END (NULL
, "SEC", NULL
, 0);
294 // If first pass, start performance measurement.
296 PERF_START (NULL
,"PEI", NULL
, 0);
297 PERF_START (NULL
,"PreMem", NULL
, 0);
300 PERF_END (NULL
,"PreMem", NULL
, 0);
301 PERF_START (NULL
,"PostMem", NULL
, 0);
305 // Complete PEI Core Service initialization
307 InitializeSecurityServices (&PrivateData
.Ps
, OldCoreData
);
308 InitializeDispatcherData (&PrivateData
, OldCoreData
, SecCoreData
);
309 InitializeImageServices (&PrivateData
, OldCoreData
);
312 // Perform PEI Core Phase specific actions
314 if (OldCoreData
== NULL
) {
316 // Report Status Code EFI_SW_PC_INIT
320 (EFI_SOFTWARE_PEI_CORE
| EFI_SW_PC_INIT
)
324 // If SEC provided any PPI services to PEI, install them.
326 if (PpiList
!= NULL
) {
327 Status
= PeiServicesInstallPpi (PpiList
);
328 ASSERT_EFI_ERROR (Status
);
332 // Alert any listeners that there is permanent memory available
334 PERF_START (NULL
,"DisMem", NULL
, 0);
335 Status
= PeiServicesInstallPpi (&mMemoryDiscoveredPpi
);
338 // Process the Notify list and dispatch any notifies for the Memory Discovered PPI
340 ProcessNotifyList (&PrivateData
);
342 PERF_END (NULL
,"DisMem", NULL
, 0);
346 // Call PEIM dispatcher
348 PeiDispatcher (SecCoreData
, &PrivateData
);
351 // Check if InstallPeiMemory service was called.
353 ASSERT(PrivateData
.PeiMemoryInstalled
== TRUE
);
356 // Measure PEI Core execution time.
358 PERF_END (NULL
, "PostMem", NULL
, 0);
361 // Lookup DXE IPL PPI
363 Status
= PeiServicesLocatePpi (
367 (VOID
**)&TempPtr
.DxeIpl
369 ASSERT_EFI_ERROR (Status
);
372 // Enter DxeIpl to load Dxe core.
374 DEBUG ((EFI_D_INFO
, "DXE IPL Entry\n"));
375 Status
= TempPtr
.DxeIpl
->Entry (
381 // Should never reach here.
383 ASSERT_EFI_ERROR (Status
);