2 Pei Core Main Entry Point
4 Copyright (c) 2006 - 2011, 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
,
68 Shadow PeiCore module from flash to installed memory.
70 @param PrivateData PeiCore's private data structure
72 @return PeiCore function address after shadowing.
74 PEICORE_FUNCTION_POINTER
76 IN PEI_CORE_INSTANCE
*PrivateData
79 EFI_PEI_FILE_HANDLE PeiCoreFileHandle
;
80 EFI_PHYSICAL_ADDRESS EntryPoint
;
82 UINT32 AuthenticationState
;
84 PeiCoreFileHandle
= NULL
;
87 // Find the PEI Core in the BFV
89 Status
= PrivateData
->Fv
[0].FvPpi
->FindFileByType (
90 PrivateData
->Fv
[0].FvPpi
,
91 EFI_FV_FILETYPE_PEI_CORE
,
92 PrivateData
->Fv
[0].FvHandle
,
95 ASSERT_EFI_ERROR (Status
);
98 // Shadow PEI Core into memory so it will run faster
100 Status
= PeiLoadImage (
101 GetPeiServicesTablePointer (),
102 *((EFI_PEI_FILE_HANDLE
*)&PeiCoreFileHandle
),
103 PEIM_STATE_REGISITER_FOR_SHADOW
,
107 ASSERT_EFI_ERROR (Status
);
110 // Compute the PeiCore's function address after shaowed PeiCore.
111 // _ModuleEntryPoint is PeiCore main function entry
113 return (PEICORE_FUNCTION_POINTER
)((UINTN
) EntryPoint
+ (UINTN
) PeiCore
- (UINTN
) _ModuleEntryPoint
);
117 This routine is invoked by main entry of PeiMain module during transition
118 from SEC to PEI. After switching stack in the PEI core, it will restart
119 with the old core data.
121 @param SecCoreData Points to a data structure containing information about the PEI core's operating
122 environment, such as the size and location of temporary RAM, the stack location and
124 @param PpiList Points to a list of one or more PPI descriptors to be installed initially by the PEI core.
125 An empty PPI list consists of a single descriptor with the end-tag
126 EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST. As part of its initialization
127 phase, the PEI Foundation will add these SEC-hosted PPIs to its PPI database such
128 that both the PEI Foundation and any modules can leverage the associated service
129 calls and/or code in these early PPIs
130 @param Data Pointer to old core data that is used to initialize the
132 If NULL, it is first PeiCore entering.
138 IN CONST EFI_SEC_PEI_HAND_OFF
*SecCoreData
,
139 IN CONST EFI_PEI_PPI_DESCRIPTOR
*PpiList
,
143 PEI_CORE_INSTANCE PrivateData
;
145 PEI_CORE_TEMP_POINTERS TempPtr
;
146 PEI_CORE_INSTANCE
*OldCoreData
;
147 EFI_PEI_CPU_IO_PPI
*CpuIo
;
148 EFI_PEI_PCI_CFG2_PPI
*PciCfg
;
149 EFI_HOB_HANDOFF_INFO_TABLE
*HandoffInformationTable
;
152 // Retrieve context passed into PEI Core
154 OldCoreData
= (PEI_CORE_INSTANCE
*)Data
;
157 // Perform PEI Core phase specific actions.
159 if (OldCoreData
== NULL
) {
161 // If OldCoreData is NULL, means current is the first entry into the PEI Core before memory is available.
163 ZeroMem (&PrivateData
, sizeof (PEI_CORE_INSTANCE
));
164 PrivateData
.Signature
= PEI_CORE_HANDLE_SIGNATURE
;
165 CopyMem (&PrivateData
.ServiceTableShadow
, &gPs
, sizeof (gPs
));
168 // Memory is available to the PEI Core. See if the PEI Core has been shadowed to memory yet.
170 if (OldCoreData
->ShadowedPeiCore
== NULL
) {
172 // Fixup the PeiCore's private data
174 OldCoreData
->Ps
= &OldCoreData
->ServiceTableShadow
;
175 OldCoreData
->CpuIo
= &OldCoreData
->ServiceTableShadow
.CpuIo
;
176 if (OldCoreData
->HeapOffsetPositive
) {
177 OldCoreData
->HobList
.Raw
= (VOID
*)(OldCoreData
->HobList
.Raw
+ OldCoreData
->HeapOffset
);
179 OldCoreData
->HobList
.Raw
= (VOID
*)(OldCoreData
->HobList
.Raw
- OldCoreData
->HeapOffset
);
183 // Initialize libraries that the PEI Core is linked against
185 ProcessLibraryConstructorList (NULL
, (CONST EFI_PEI_SERVICES
**)&OldCoreData
->Ps
);
188 // Fixup for PeiService's address
190 SetPeiServicesTablePointer ((CONST EFI_PEI_SERVICES
**)&OldCoreData
->Ps
);
193 // Update HandOffHob for new installed permenent memory
195 HandoffInformationTable
= OldCoreData
->HobList
.HandoffInformationTable
;
196 if (OldCoreData
->HeapOffsetPositive
) {
197 HandoffInformationTable
->EfiEndOfHobList
= HandoffInformationTable
->EfiEndOfHobList
+ OldCoreData
->HeapOffset
;
199 HandoffInformationTable
->EfiEndOfHobList
= HandoffInformationTable
->EfiEndOfHobList
- OldCoreData
->HeapOffset
;
201 HandoffInformationTable
->EfiMemoryTop
= OldCoreData
->PhysicalMemoryBegin
+ OldCoreData
->PhysicalMemoryLength
;
202 HandoffInformationTable
->EfiMemoryBottom
= OldCoreData
->PhysicalMemoryBegin
;
203 HandoffInformationTable
->EfiFreeMemoryTop
= OldCoreData
->FreePhysicalMemoryTop
;
204 HandoffInformationTable
->EfiFreeMemoryBottom
= HandoffInformationTable
->EfiEndOfHobList
+ sizeof (EFI_HOB_GENERIC_HEADER
);
207 // We need convert the PPI descriptor's pointer
209 ConvertPpiPointers (SecCoreData
, OldCoreData
);
212 // After the whole temporary memory is migrated, then we can allocate page in
215 OldCoreData
->PeiMemoryInstalled
= TRUE
;
218 // Indicate that PeiCore reenter
220 OldCoreData
->PeimDispatcherReenter
= TRUE
;
222 if (PcdGet64(PcdLoadModuleAtFixAddressEnable
) != 0 && (OldCoreData
->HobList
.HandoffInformationTable
->BootMode
!= BOOT_ON_S3_RESUME
)) {
224 // if Loading Module at Fixed Address is enabled, allocate the PEI code memory range usage bit map array.
225 // Every bit in the array indicate the status of the corresponding memory page available or not
227 OldCoreData
->PeiCodeMemoryRangeUsageBitMap
= AllocateZeroPool (((PcdGet32(PcdLoadFixAddressPeiCodePageNumber
)>>6) + 1)*sizeof(UINT64
));
231 // Shadow PEI Core. When permanent memory is avaiable, shadow
232 // PEI Core and PEIMs to get high performance.
234 OldCoreData
->ShadowedPeiCore
= ShadowPeiCore (OldCoreData
);
237 // PEI Core has now been shadowed to memory. Restart PEI Core in memory.
239 OldCoreData
->ShadowedPeiCore (SecCoreData
, PpiList
, OldCoreData
);
242 // Should never reach here.
249 // Memory is available to the PEI Core and the PEI Core has been shadowed to memory.
252 CopyMem (&PrivateData
, OldCoreData
, sizeof (PrivateData
));
254 CpuIo
= (VOID
*)PrivateData
.ServiceTableShadow
.CpuIo
;
255 PciCfg
= (VOID
*)PrivateData
.ServiceTableShadow
.PciCfg
;
257 CopyMem (&PrivateData
.ServiceTableShadow
, &gPs
, sizeof (gPs
));
259 PrivateData
.ServiceTableShadow
.CpuIo
= CpuIo
;
260 PrivateData
.ServiceTableShadow
.PciCfg
= PciCfg
;
264 // Cache a pointer to the PEI Services Table that is either in temporary memory or permanent memory
266 PrivateData
.Ps
= &PrivateData
.ServiceTableShadow
;
269 // Initialize libraries that the PEI Core is linked against
271 ProcessLibraryConstructorList (NULL
, (CONST EFI_PEI_SERVICES
**)&PrivateData
.Ps
);
274 // Save PeiServicePointer so that it can be retrieved anywhere.
276 SetPeiServicesTablePointer ((CONST EFI_PEI_SERVICES
**)&PrivateData
.Ps
);
279 // Initialize PEI Core Services
281 InitializeMemoryServices (&PrivateData
, SecCoreData
, OldCoreData
);
282 InitializePpiServices (&PrivateData
, OldCoreData
);
285 // Update performance measurements
287 if (OldCoreData
== NULL
) {
288 PERF_START (NULL
, "SEC", NULL
, 1);
289 PERF_END (NULL
, "SEC", NULL
, 0);
292 // If first pass, start performance measurement.
294 PERF_START (NULL
,"PEI", NULL
, 0);
295 PERF_START (NULL
,"PreMem", NULL
, 0);
298 PERF_END (NULL
,"PreMem", NULL
, 0);
299 PERF_START (NULL
,"PostMem", NULL
, 0);
303 // Complete PEI Core Service initialization
305 InitializeSecurityServices (&PrivateData
.Ps
, OldCoreData
);
306 InitializeDispatcherData (&PrivateData
, OldCoreData
, SecCoreData
);
307 InitializeImageServices (&PrivateData
, OldCoreData
);
310 // Perform PEI Core Phase specific actions
312 if (OldCoreData
== NULL
) {
314 // Report Status Code EFI_SW_PC_INIT
318 (EFI_SOFTWARE_PEI_CORE
| EFI_SW_PC_INIT
)
322 // If SEC provided any PPI services to PEI, install them.
324 if (PpiList
!= NULL
) {
325 Status
= PeiServicesInstallPpi (PpiList
);
326 ASSERT_EFI_ERROR (Status
);
330 // Alert any listeners that there is permanent memory available
332 PERF_START (NULL
,"DisMem", NULL
, 0);
333 Status
= PeiServicesInstallPpi (&mMemoryDiscoveredPpi
);
336 // Process the Notify list and dispatch any notifies for the Memory Discovered PPI
338 ProcessNotifyList (&PrivateData
);
340 PERF_END (NULL
,"DisMem", NULL
, 0);
344 // Call PEIM dispatcher
346 PeiDispatcher (SecCoreData
, &PrivateData
);
349 // Check if InstallPeiMemory service was called.
351 ASSERT(PrivateData
.PeiMemoryInstalled
== TRUE
);
354 // Measure PEI Core execution time.
356 PERF_END (NULL
, "PostMem", NULL
, 0);
359 // Lookup DXE IPL PPI
361 Status
= PeiServicesLocatePpi (
365 (VOID
**)&TempPtr
.DxeIpl
367 ASSERT_EFI_ERROR (Status
);
370 // Enter DxeIpl to load Dxe core.
372 DEBUG ((EFI_D_INFO
, "DXE IPL Entry\n"));
373 Status
= TempPtr
.DxeIpl
->Entry (
379 // Should never reach here.
381 ASSERT_EFI_ERROR (Status
);