3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 Pei Core Main Entry Point
27 //CAR is filled with this initial value during SEC phase
29 #define INIT_CAR_VALUE 0x5AA55AA5
31 static EFI_PEI_PPI_DESCRIPTOR mMemoryDiscoveredPpi
= {
32 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
33 &gEfiPeiMemoryDiscoveredPpiGuid
,
38 // Pei Core Module Variables
41 static EFI_PEI_SERVICES mPS
= {
43 PEI_SERVICES_SIGNATURE
,
44 PEI_SERVICES_REVISION
,
45 sizeof (EFI_PEI_SERVICES
),
62 PeiFfsFindSectionData
,
67 (EFI_PEI_COPY_MEM
)CopyMem
,
68 (EFI_PEI_SET_MEM
)SetMem
,
85 IN CONST EFI_SEC_PEI_HAND_OFF
*SecCoreData
,
86 IN CONST EFI_PEI_PPI_DESCRIPTOR
*PpiList
,
93 The entry routine to Pei Core, invoked by PeiMain during transition
94 from SEC to PEI. After switching stack in the PEI core, it will restart
95 with the old core data.
99 SecCoreData - Points to a data structure containing information about the PEI core's operating
100 environment, such as the size and location of temporary RAM, the stack location and
102 PpiList - Points to a list of one or more PPI descriptors to be installed initially by the PEI core.
103 An empty PPI list consists of a single descriptor with the end-tag
104 EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST. As part of its initialization
105 phase, the PEI Foundation will add these SEC-hosted PPIs to its PPI database such
106 that both the PEI Foundation and any modules can leverage the associated service
107 calls and/or code in these early PPIs
108 Data - Pointer to old core data that is used to initialize the
113 This function never returns
114 EFI_NOT_FOUND - Never reach
118 PEI_CORE_INSTANCE PrivateData
;
120 PEI_CORE_TEMP_POINTERS TempPtr
;
122 PEI_CORE_INSTANCE
*OldCoreData
;
123 EFI_PEI_CPU_IO_PPI
*CpuIo
;
124 EFI_PEI_PCI_CFG2_PPI
*PciCfg
;
125 UINT64 SecPlatformInfoRecordSize
;
126 EFI_SEC_PLATFORM_INFORMATION_PPI
*SecPlatformInfoPpi
;
127 EFI_SEC_PLATFORM_INFORMATION_RECORD
*SecPlatformInfoRecord
;
130 OldCoreData
= (PEI_CORE_INSTANCE
*) Data
;
132 if (PerformanceMeasurementEnabled()) {
133 if (OldCoreData
== NULL
) {
134 mTick
= GetPerformanceCounter ();
139 // For IPF in CAR mode the real memory access is uncached,in InstallPeiMemory()
140 // the 63-bit of address is set to 1.
142 SWITCH_TO_CACHE_MODE (OldCoreData
);
144 if (OldCoreData
!= NULL
) {
145 CopyMem (&PrivateData
, OldCoreData
, sizeof (PEI_CORE_INSTANCE
));
147 CpuIo
= (VOID
*)PrivateData
.ServiceTableShadow
.CpuIo
;
148 PciCfg
= (VOID
*)PrivateData
.ServiceTableShadow
.PciCfg
;
150 CopyMem (&PrivateData
.ServiceTableShadow
, &mPS
, sizeof (mPS
));
152 PrivateData
.ServiceTableShadow
.CpuIo
= CpuIo
;
153 PrivateData
.ServiceTableShadow
.PciCfg
= PciCfg
;
155 ZeroMem (&PrivateData
, sizeof (PEI_CORE_INSTANCE
));
156 PrivateData
.Signature
= PEI_CORE_HANDLE_SIGNATURE
;
157 CopyMem (&PrivateData
.ServiceTableShadow
, &mPS
, sizeof (mPS
));
160 PrivateData
.PS
= &PrivateData
.ServiceTableShadow
;
163 // Initialize libraries that the PeiCore is linked against
164 // BUGBUG: The FileHandle is passed in as NULL. Do we look it up or remove it from the lib init?
166 ProcessLibraryConstructorList (NULL
, &PrivateData
.PS
);
168 InitializeMemoryServices (&PrivateData
, SecCoreData
, OldCoreData
);
170 InitializePpiServices (&PrivateData
, OldCoreData
);
173 // Save PeiServicePointer so that it can be retrieved anywhere.
175 SetPeiServicesTablePointer(&PrivateData
.PS
);
177 if (OldCoreData
!= NULL
) {
179 PERF_END (NULL
,"PreMem", NULL
, 0);
180 PERF_START (NULL
,"PostMem", NULL
, 0);
183 // The following code dumps out interesting cache as RAM usage information
184 // so we can keep tabs on how the cache as RAM is being utilized. The
185 // DEBUG_CODE_BEGIN macro is used to prevent this code from being compiled
192 StackValue
= INIT_CAR_VALUE
;
193 for (StackPointer
= (UINTN
*) OldCoreData
->TopOfCarHeap
;
194 ((UINTN
) StackPointer
< ((UINTN
) OldCoreData
->MaxTopOfCarHeap
))
195 && StackValue
== INIT_CAR_VALUE
;
197 StackValue
= *StackPointer
;
200 DEBUG ((EFI_D_INFO
, "Total Cache as RAM: %d bytes.\n", OldCoreData
->SizeOfCacheAsRam
));
201 DEBUG ((EFI_D_INFO
, " CAR stack ever used: %d bytes.\n",
202 ((UINTN
) OldCoreData
->MaxTopOfCarHeap
- (UINTN
) StackPointer
)
204 DEBUG ((EFI_D_INFO
, " CAR heap used: %d bytes.\n",
205 ((UINTN
) OldCoreData
->HobList
.HandoffInformationTable
->EfiFreeMemoryBottom
-
206 (UINTN
) OldCoreData
->HobList
.Raw
)
211 // Alert any listeners that there is permanent memory available
214 PERF_START (NULL
,"DisMem", NULL
, 0);
215 Status
= PeiServicesInstallPpi (&mMemoryDiscoveredPpi
);
216 PERF_END (NULL
,"DisMem", NULL
, 0);
221 // Report Status Code EFI_SW_PC_INIT
225 EFI_SOFTWARE_PEI_CORE
| EFI_SW_PC_INIT
228 PERF_START (NULL
,"PEI", NULL
, mTick
);
230 // If first pass, start performance measurement.
232 PERF_START (NULL
,"PreMem", NULL
, mTick
);
235 // If SEC provided any PPI services to PEI, install them.
237 if (PpiList
!= NULL
) {
238 Status
= PeiServicesInstallPpi (PpiList
);
239 ASSERT_EFI_ERROR (Status
);
242 // PI spec Vol 1, 7.3.1 specifies that this same information reported by EFI_SEC_PLATFORM_INFORMATION_PPI
243 // will be placed in a GUIDed HOB with the PPI GUID as the HOB GUID for HOB consumer phase.
245 Status
= PeiServicesLocatePpi (
246 &gEfiSecPlatformInformationPpiGuid
,
249 (VOID
**) &SecPlatformInfoPpi
251 if (!EFI_ERROR (Status
)) {
252 SecPlatformInfoRecord
= AllocateZeroPool (sizeof(*SecPlatformInfoRecord
));
253 ASSERT (SecPlatformInfoRecord
!= NULL
);
255 SecPlatformInfoRecordSize
= sizeof(*SecPlatformInfoRecord
);
257 Status
= SecPlatformInfoPpi
->PlatformInformation (
258 (CONST EFI_PEI_SERVICES
**) GetPeiServicesTablePointer (),
259 &SecPlatformInfoRecordSize
,
260 SecPlatformInfoRecord
263 if (!EFI_ERROR (Status
)) {
265 &gEfiSecPlatformInformationPpiGuid
,
266 SecPlatformInfoRecord
,
267 sizeof (*SecPlatformInfoRecord
)
274 InitializeSecurityServices (&PrivateData
.PS
, OldCoreData
);
276 InitializeDispatcherData (&PrivateData
, OldCoreData
, SecCoreData
);
279 // Install Pei Load File PPI.
281 InitializeImageServices (&PrivateData
, OldCoreData
);
284 // Call PEIM dispatcher
286 PeiDispatcher (SecCoreData
, &PrivateData
);
289 // Check if InstallPeiMemory service was called.
291 ASSERT(PrivateData
.PeiMemoryInstalled
== TRUE
);
293 PERF_END (NULL
, "PostMem", NULL
, 0);
295 Status
= PeiServicesLocatePpi (
299 (VOID
**)&TempPtr
.DxeIpl
301 ASSERT_EFI_ERROR (Status
);
303 DEBUG ((EFI_D_INFO
, "DXE IPL Entry\n"));
304 Status
= TempPtr
.DxeIpl
->Entry (
310 ASSERT_EFI_ERROR (Status
);
312 return EFI_NOT_FOUND
;