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
,
78 IN EFI_PEI_STARTUP_DESCRIPTOR
*PeiStartupDescriptor
,
85 The entry routine to Pei Core, invoked by PeiMain during transition
86 from SEC to PEI. After switching stack in the PEI core, it will restart
87 with the old core data.
91 PeiStartupDescriptor - Information and services provided by SEC phase.
92 OldCoreData - Pointer to old core data that is used to initialize the
97 This function never returns
98 EFI_NOT_FOUND - Never reach
102 PEI_CORE_INSTANCE PrivateData
;
104 PEI_CORE_TEMP_POINTERS TempPtr
;
105 PEI_CORE_DISPATCH_DATA
*DispatchData
;
107 PEI_CORE_INSTANCE
*OldCoreData
;
110 OldCoreData
= (PEI_CORE_INSTANCE
*) Data
;
112 if (PerformanceMeasurementEnabled()) {
113 if (OldCoreData
== NULL
) {
114 mTick
= GetPerformanceCounter ();
119 // For IPF in CAR mode the real memory access is uncached,in InstallPeiMemory()
120 // the 63-bit of address is set to 1.
122 SWITCH_TO_CACHE_MODE (OldCoreData
);
124 if (OldCoreData
!= NULL
) {
125 CopyMem (&PrivateData
, OldCoreData
, sizeof (PEI_CORE_INSTANCE
));
127 ZeroMem (&PrivateData
, sizeof (PEI_CORE_INSTANCE
));
130 PrivateData
.Signature
= PEI_CORE_HANDLE_SIGNATURE
;
131 PrivateData
.PS
= &mPS
;
134 // Initialize libraries that the PeiCore is linked against
135 // BUGBUG: The FfsHeader is passed in as NULL. Do we look it up or remove it from the lib init?
137 ProcessLibraryConstructorList (NULL
, &PrivateData
.PS
);
139 InitializeMemoryServices (&PrivateData
.PS
, PeiStartupDescriptor
, OldCoreData
);
141 InitializePpiServices (&PrivateData
.PS
, OldCoreData
);
143 InitializeSecurityServices (&PrivateData
.PS
, OldCoreData
);
145 InitializeDispatcherData (&PrivateData
.PS
, OldCoreData
, PeiStartupDescriptor
);
147 if (OldCoreData
!= NULL
) {
149 PERF_END (NULL
,"PreMem", NULL
, 0);
150 PERF_START (NULL
,"PostMem", NULL
, 0);
153 // The following code dumps out interesting cache as RAM usage information
154 // so we can keep tabs on how the cache as RAM is being utilized. The
155 // DEBUG_CODE_BEGIN macro is used to prevent this code from being compiled
162 StackValue
= INIT_CAR_VALUE
;
163 for (StackPointer
= (UINTN
*) OldCoreData
->MaxTopOfCarHeap
;
164 ((UINTN
) StackPointer
< ((UINTN
) OldCoreData
->BottomOfCarHeap
+ OldCoreData
->SizeOfCacheAsRam
))
165 && StackValue
== INIT_CAR_VALUE
;
167 StackValue
= *StackPointer
;
170 DEBUG ((EFI_D_INFO
, "Total Cache as RAM: %d bytes.\n", OldCoreData
->SizeOfCacheAsRam
));
171 DEBUG ((EFI_D_INFO
, " CAR stack ever used: %d bytes.\n",
172 ((UINTN
) OldCoreData
->TopOfCarHeap
- (UINTN
) StackPointer
)
174 DEBUG ((EFI_D_INFO
, " CAR heap used: %d bytes.\n",
175 ((UINTN
) OldCoreData
->HobList
.HandoffInformationTable
->EfiFreeMemoryBottom
-
176 (UINTN
) OldCoreData
->HobList
.Raw
)
181 // Alert any listeners that there is permanent memory available
184 PERF_START (NULL
,"DisMem", NULL
, 0);
185 Status
= PeiServicesInstallPpi (&mMemoryDiscoveredPpi
);
186 PERF_END (NULL
,"DisMem", NULL
, 0);
191 // Report Status Code EFI_SW_PC_INIT
195 EFI_SOFTWARE_PEI_CORE
| EFI_SW_PC_INIT
198 PERF_START (NULL
,"PEI", NULL
, mTick
);
200 // If first pass, start performance measurement.
202 PERF_START (NULL
,"PreMem", NULL
, mTick
);
205 // If SEC provided any PPI services to PEI, install them.
207 if (PeiStartupDescriptor
->DispatchTable
!= NULL
) {
208 Status
= PeiServicesInstallPpi (PeiStartupDescriptor
->DispatchTable
);
209 ASSERT_EFI_ERROR (Status
);
213 DispatchData
= &PrivateData
.DispatchData
;
216 // Call PEIM dispatcher
218 PeiDispatcher (PeiStartupDescriptor
, &PrivateData
, DispatchData
);
221 // Check if InstallPeiMemory service was called.
223 ASSERT(PrivateData
.PeiMemoryInstalled
== TRUE
);
225 PERF_END (NULL
, "PostMem", NULL
, 0);
227 Status
= PeiServicesLocatePpi (
231 (VOID
**)&TempPtr
.DxeIpl
233 ASSERT_EFI_ERROR (Status
);
235 DEBUG ((EFI_D_INFO
, "DXE IPL Entry\n"));
236 Status
= TempPtr
.DxeIpl
->Entry (
242 ASSERT_EFI_ERROR (Status
);
244 return EFI_NOT_FOUND
;