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
25 // Include common header file for this module.
27 #include "CommonHeader.h"
32 //CAR is filled with this initial value during SEC phase
34 #define INIT_CAR_VALUE 0x5AA55AA5
36 static EFI_PEI_PPI_DESCRIPTOR mMemoryDiscoveredPpi
= {
37 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
38 &gEfiPeiMemoryDiscoveredPpiGuid
,
43 // Pei Core Module Variables
46 static EFI_PEI_SERVICES mPS
= {
48 PEI_SERVICES_SIGNATURE
,
49 PEI_SERVICES_REVISION
,
50 sizeof (EFI_PEI_SERVICES
),
67 PeiFfsFindSectionData
,
72 (EFI_PEI_COPY_MEM
)CopyMem
,
73 (EFI_PEI_SET_MEM
)SetMem
,
83 IN EFI_PEI_STARTUP_DESCRIPTOR
*PeiStartupDescriptor
,
90 The entry routine to Pei Core, invoked by PeiMain during transition
91 from SEC to PEI. After switching stack in the PEI core, it will restart
92 with the old core data.
96 PeiStartupDescriptor - Information and services provided by SEC phase.
97 OldCoreData - Pointer to old core data that is used to initialize the
102 This function never returns
103 EFI_NOT_FOUND - Never reach
107 PEI_CORE_INSTANCE PrivateData
;
109 PEI_CORE_TEMP_POINTERS TempPtr
;
110 PEI_CORE_DISPATCH_DATA
*DispatchData
;
112 PEI_CORE_INSTANCE
*OldCoreData
;
115 OldCoreData
= (PEI_CORE_INSTANCE
*) Data
;
117 if (PerformanceMeasurementEnabled()) {
118 if (OldCoreData
== NULL
) {
119 mTick
= GetPerformanceCounter ();
124 // For IPF in CAR mode the real memory access is uncached,in InstallPeiMemory()
125 // the 63-bit of address is set to 1.
127 SWITCH_TO_CACHE_MODE (OldCoreData
);
129 if (OldCoreData
!= NULL
) {
130 CopyMem (&PrivateData
, OldCoreData
, sizeof (PEI_CORE_INSTANCE
));
132 ZeroMem (&PrivateData
, sizeof (PEI_CORE_INSTANCE
));
135 PrivateData
.Signature
= PEI_CORE_HANDLE_SIGNATURE
;
136 PrivateData
.PS
= &mPS
;
139 // Initialize libraries that the PeiCore is linked against
140 // BUGBUG: The FfsHeader is passed in as NULL. Do we look it up or remove it from the lib init?
142 ProcessLibraryConstructorList (NULL
, &PrivateData
.PS
);
144 InitializeMemoryServices (&PrivateData
.PS
, PeiStartupDescriptor
, OldCoreData
);
146 InitializePpiServices (&PrivateData
.PS
, OldCoreData
);
148 InitializeSecurityServices (&PrivateData
.PS
, OldCoreData
);
150 InitializeDispatcherData (&PrivateData
.PS
, OldCoreData
, PeiStartupDescriptor
);
152 if (OldCoreData
!= NULL
) {
154 PERF_END (NULL
,"PreMem", NULL
, 0);
155 PERF_START (NULL
,"PostMem", NULL
, 0);
158 // The following code dumps out interesting cache as RAM usage information
159 // so we can keep tabs on how the cache as RAM is being utilized. The
160 // DEBUG_CODE_BEGIN macro is used to prevent this code from being compiled
167 StackValue
= INIT_CAR_VALUE
;
168 for (StackPointer
= (UINTN
*) OldCoreData
->MaxTopOfCarHeap
;
169 ((UINTN
) StackPointer
< ((UINTN
) OldCoreData
->BottomOfCarHeap
+ OldCoreData
->SizeOfCacheAsRam
))
170 && StackValue
== INIT_CAR_VALUE
;
172 StackValue
= *StackPointer
;
175 DEBUG ((EFI_D_INFO
, "Total Cache as RAM: %d bytes.\n", OldCoreData
->SizeOfCacheAsRam
));
176 DEBUG ((EFI_D_INFO
, " CAR stack ever used: %d bytes.\n",
177 ((UINTN
) OldCoreData
->TopOfCarHeap
- (UINTN
) StackPointer
)
179 DEBUG ((EFI_D_INFO
, " CAR heap used: %d bytes.\n",
180 ((UINTN
) OldCoreData
->HobList
.HandoffInformationTable
->EfiFreeMemoryBottom
-
181 (UINTN
) OldCoreData
->HobList
.Raw
)
186 // Alert any listeners that there is permanent memory available
189 PERF_START (NULL
,"DisMem", NULL
, 0);
190 Status
= PeiServicesInstallPpi (&mMemoryDiscoveredPpi
);
191 PERF_END (NULL
,"DisMem", NULL
, 0);
196 // Report Status Code EFI_SW_PC_INIT
200 EFI_SOFTWARE_PEI_CORE
| EFI_SW_PC_INIT
203 PERF_START (NULL
,"PEI", NULL
, mTick
);
205 // If first pass, start performance measurement.
207 PERF_START (NULL
,"PreMem", NULL
, mTick
);
210 // If SEC provided any PPI services to PEI, install them.
212 if (PeiStartupDescriptor
->DispatchTable
!= NULL
) {
213 Status
= PeiServicesInstallPpi (PeiStartupDescriptor
->DispatchTable
);
214 ASSERT_EFI_ERROR (Status
);
218 DispatchData
= &PrivateData
.DispatchData
;
221 // Call PEIM dispatcher
223 PeiDispatcher (PeiStartupDescriptor
, &PrivateData
, DispatchData
);
226 // Check if InstallPeiMemory service was called.
228 ASSERT(PrivateData
.PeiMemoryInstalled
== TRUE
);
230 PERF_END (NULL
, "PostMem", NULL
, 0);
232 Status
= PeiServicesLocatePpi (
236 (VOID
**)&TempPtr
.DxeIpl
238 ASSERT_EFI_ERROR (Status
);
240 DEBUG ((EFI_D_INFO
, "DXE IPL Entry\n"));
241 Status
= TempPtr
.DxeIpl
->Entry (
247 ASSERT_EFI_ERROR (Status
);
249 return EFI_NOT_FOUND
;