2 Pei Core Main Entry Point
4 Copyright (c) 2006, Intel Corporation
5 All rights reserved. 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
,
69 This routine is invoked by main entry of PeiMain module during transition
70 from SEC to PEI. After switching stack in the PEI core, it will restart
71 with the old core data.
73 @param SecCoreData Points to a data structure containing information about the PEI core's operating
74 environment, such as the size and location of temporary RAM, the stack location and
76 @param PpiList Points to a list of one or more PPI descriptors to be installed initially by the PEI core.
77 An empty PPI list consists of a single descriptor with the end-tag
78 EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST. As part of its initialization
79 phase, the PEI Foundation will add these SEC-hosted PPIs to its PPI database such
80 that both the PEI Foundation and any modules can leverage the associated service
81 calls and/or code in these early PPIs
82 @param Data Pointer to old core data that is used to initialize the
84 If NULL, it is first PeiCore entering.
86 @retval EFI_NOT_FOUND Never reach
92 IN CONST EFI_SEC_PEI_HAND_OFF
*SecCoreData
,
93 IN CONST EFI_PEI_PPI_DESCRIPTOR
*PpiList
,
97 PEI_CORE_INSTANCE PrivateData
;
99 PEI_CORE_TEMP_POINTERS TempPtr
;
101 PEI_CORE_INSTANCE
*OldCoreData
;
102 EFI_PEI_CPU_IO_PPI
*CpuIo
;
103 EFI_PEI_PCI_CFG2_PPI
*PciCfg
;
104 PEICORE_FUNCTION_POINTER ShadowedPeiCore
;
107 OldCoreData
= (PEI_CORE_INSTANCE
*) Data
;
110 // Record the system tick for first entering PeiCore.
111 // This tick is duration of executing platform seccore module.
113 if (PerformanceMeasurementEnabled()) {
114 if (OldCoreData
== NULL
) {
115 Tick
= GetPerformanceCounter ();
119 if (OldCoreData
!= NULL
) {
120 ShadowedPeiCore
= (PEICORE_FUNCTION_POINTER
) (UINTN
) OldCoreData
->ShadowedPeiCore
;
123 // PeiCore has been shadowed to memory for first entering, so
124 // just jump to PeiCore in memory here.
126 if (ShadowedPeiCore
!= NULL
) {
127 OldCoreData
->ShadowedPeiCore
= NULL
;
135 CopyMem (&PrivateData
, OldCoreData
, sizeof (PEI_CORE_INSTANCE
));
137 CpuIo
= (VOID
*)PrivateData
.ServiceTableShadow
.CpuIo
;
138 PciCfg
= (VOID
*)PrivateData
.ServiceTableShadow
.PciCfg
;
140 CopyMem (&PrivateData
.ServiceTableShadow
, &gPs
, sizeof (gPs
));
142 PrivateData
.ServiceTableShadow
.CpuIo
= CpuIo
;
143 PrivateData
.ServiceTableShadow
.PciCfg
= PciCfg
;
146 // If OldCoreData is NULL, means current is first Peicore's entering.
149 ZeroMem (&PrivateData
, sizeof (PEI_CORE_INSTANCE
));
150 PrivateData
.Signature
= PEI_CORE_HANDLE_SIGNATURE
;
151 CopyMem (&PrivateData
.ServiceTableShadow
, &gPs
, sizeof (gPs
));
154 PrivateData
.PS
= &PrivateData
.ServiceTableShadow
;
157 // Initialize libraries that the PeiCore is linked against
159 ProcessLibraryConstructorList (NULL
, (CONST EFI_PEI_SERVICES
**)&PrivateData
.PS
);
161 InitializeMemoryServices (&PrivateData
, SecCoreData
, OldCoreData
);
163 InitializePpiServices (&PrivateData
, OldCoreData
);
166 // Save PeiServicePointer so that it can be retrieved anywhere.
168 SetPeiServicesTablePointer((CONST EFI_PEI_SERVICES
**) &PrivateData
.PS
);
170 if (OldCoreData
!= NULL
) {
172 PERF_END (NULL
,"PreMem", NULL
, 0);
173 PERF_START (NULL
,"PostMem", NULL
, 0);
176 // Alert any listeners that there is permanent memory available
179 PERF_START (NULL
,"DisMem", NULL
, 0);
180 Status
= PeiServicesInstallPpi (&mMemoryDiscoveredPpi
);
181 PERF_END (NULL
,"DisMem", NULL
, 0);
186 // Report Status Code EFI_SW_PC_INIT
190 FixedPcdGet32 (PcdStatusCodeValuePeiCoreEntry
)
193 PERF_START (NULL
, "SEC", NULL
, 1);
194 PERF_END (NULL
, "SEC", NULL
, Tick
);
196 PERF_START (NULL
,"PEI", NULL
, Tick
);
198 // If first pass, start performance measurement.
200 PERF_START (NULL
,"PreMem", NULL
, Tick
);
203 // If SEC provided any PPI services to PEI, install them.
205 if (PpiList
!= NULL
) {
206 Status
= PeiServicesInstallPpi (PpiList
);
207 ASSERT_EFI_ERROR (Status
);
211 InitializeSecurityServices (&PrivateData
.PS
, OldCoreData
);
213 InitializeDispatcherData (&PrivateData
, OldCoreData
, SecCoreData
);
216 // Install Pei Load File PPI.
218 InitializeImageServices (&PrivateData
, OldCoreData
);
221 // Call PEIM dispatcher
223 PeiDispatcher (SecCoreData
, &PrivateData
);
226 // Check if InstallPeiMemory service was called.
228 ASSERT(PrivateData
.PeiMemoryInstalled
== TRUE
);
231 // Till now, PEI phase will be finished, get performace count
232 // for computing duration of PEI phase
234 PERF_END (NULL
, "PostMem", NULL
, 0);
236 Status
= PeiServicesLocatePpi (
240 (VOID
**)&TempPtr
.DxeIpl
242 ASSERT_EFI_ERROR (Status
);
245 // Enter DxeIpl to load Dxe core.
247 DEBUG ((EFI_D_INFO
, "DXE IPL Entry\n"));
248 Status
= TempPtr
.DxeIpl
->Entry (
254 // Should never reach here.
256 ASSERT_EFI_ERROR (Status
);