]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - EdkModulePkg/Core/Pei/PeiMain/PeiMain.c
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@430 6f19259b...
[mirror_edk2.git] / EdkModulePkg / Core / Pei / PeiMain / PeiMain.c
... / ...
CommitLineData
1/*++
2
3Copyright (c) 2006, Intel Corporation
4All rights reserved. This program and the accompanying materials
5are licensed and made available under the terms and conditions of the BSD License
6which accompanies this distribution. The full text of the license may be found at
7http://opensource.org/licenses/bsd-license.php
8
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12Module Name:
13
14 PeiMain.c
15
16Abstract:
17
18 Pei Core Main Entry Point
19
20Revision History
21
22--*/
23
24#include <PeiMain.h>
25
26//
27//CAR is filled with this initial value during SEC phase
28//
29#define INIT_CAR_VALUE 0x5AA55AA5
30
31static EFI_PEI_PPI_DESCRIPTOR mMemoryDiscoveredPpi = {
32 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
33 &gEfiPeiMemoryDiscoveredPpiGuid,
34 NULL
35};
36
37//
38// Pei Core Module Variables
39//
40//
41static EFI_PEI_SERVICES mPS = {
42 {
43 PEI_SERVICES_SIGNATURE,
44 PEI_SERVICES_REVISION,
45 sizeof (EFI_PEI_SERVICES),
46 0,
47 0
48 },
49 PeiInstallPpi,
50 PeiReInstallPpi,
51 PeiLocatePpi,
52 PeiNotifyPpi,
53
54 PeiGetBootMode,
55 PeiSetBootMode,
56
57 PeiGetHobList,
58 PeiCreateHob,
59
60 PeiFvFindNextVolume,
61 PeiFfsFindNextFile,
62 PeiFfsFindSectionData,
63
64 PeiInstallPeiMemory,
65 PeiAllocatePages,
66 PeiAllocatePool,
67 (EFI_PEI_COPY_MEM)CopyMem,
68 (EFI_PEI_SET_MEM)SetMem,
69
70 PeiReportStatusCode,
71
72 PeiResetSystem
73};
74
75EFI_STATUS
76EFIAPI
77PeiCore (
78 IN EFI_PEI_STARTUP_DESCRIPTOR *PeiStartupDescriptor,
79 IN PEI_CORE_INSTANCE *OldCoreData
80 )
81/*++
82
83Routine Description:
84
85 Main entry point to Pei Core. After switching stack in the PEI core,
86 it will restart with the old core data.
87
88Arguments:
89
90 PeiStartupDescriptor - Information and services provided by SEC phase.
91 OldCoreData - Pointer to old core data that is used to initialize the
92 core's data areas.
93
94Returns:
95
96 This function never returns
97 EFI_NOT_FOUND - Never reach
98
99--*/
100{
101 PEI_CORE_INSTANCE PrivateData;
102 EFI_STATUS Status;
103 PEI_CORE_TEMP_POINTERS TempPtr;
104 PEI_CORE_DISPATCH_DATA *DispatchData;
105 UINT64 mTick;
106
107 mTick = 0;
108
109#ifdef EFI_PEI_PERFORMANCE
110 if (OldCoreData == NULL) {
111 mTick = GetPerformanceCounter ();
112 }
113#endif
114
115 //
116 // For IPF in CAR mode the real memory access is uncached,in InstallPeiMemory()
117 // the 63-bit of address is set to 1.
118 //
119 SWITCH_TO_CACHE_MODE (OldCoreData);
120
121 if (OldCoreData != NULL) {
122 CopyMem (&PrivateData, OldCoreData, sizeof (PEI_CORE_INSTANCE));
123 } else {
124 ZeroMem (&PrivateData, sizeof (PEI_CORE_INSTANCE));
125 }
126
127 PrivateData.Signature = PEI_CORE_HANDLE_SIGNATURE;
128 PrivateData.PS = &mPS;
129
130 //
131 // Initialize libraries that the PeiCore is linked against
132 // BUGBUG: The FfsHeader is passed in as NULL. Do we look it up or remove it from the lib init?
133 //
134 ProcessLibraryConstructorList (NULL, &PrivateData.PS);
135
136 InitializeMemoryServices (&PrivateData.PS, PeiStartupDescriptor, OldCoreData);
137
138 InitializePpiServices (&PrivateData.PS, OldCoreData);
139
140 InitializeSecurityServices (&PrivateData.PS, OldCoreData);
141
142 InitializeDispatcherData (&PrivateData.PS, OldCoreData, PeiStartupDescriptor);
143
144 if (OldCoreData != NULL) {
145
146 PERF_END (NULL,"PreMem", NULL, 0);
147 PERF_START (NULL,"PostMem", NULL, 0);
148
149 //
150 // The following code dumps out interesting cache as RAM usage information
151 // so we can keep tabs on how the cache as RAM is being utilized. The
152 // DEBUG_CODE macro is used to prevent this code from being compiled
153 // on a debug build.
154 //
155 DEBUG_CODE (
156 UINTN *StackPointer;
157 UINTN StackValue;
158
159 StackValue = INIT_CAR_VALUE;
160 for (StackPointer = (UINTN *) OldCoreData->MaxTopOfCarHeap;
161 ((UINTN) StackPointer < ((UINTN) OldCoreData->BottomOfCarHeap + OldCoreData->SizeOfCacheAsRam))
162 && StackValue == INIT_CAR_VALUE;
163 StackPointer++) {
164 StackValue = *StackPointer;
165 }
166
167 DEBUG ((EFI_D_INFO, "Total Cache as RAM: %d bytes.\n", OldCoreData->SizeOfCacheAsRam));
168 DEBUG ((EFI_D_INFO, " CAR stack ever used: %d bytes.\n",
169 ((UINTN) OldCoreData->TopOfCarHeap - (UINTN) StackPointer)
170 ));
171 DEBUG ((EFI_D_INFO, " CAR heap used: %d bytes.\n",
172 ((UINTN) OldCoreData->HobList.HandoffInformationTable->EfiFreeMemoryBottom -
173 (UINTN) OldCoreData->HobList.Raw)
174 ));
175 );
176
177 //
178 // Alert any listeners that there is permanent memory available
179 //
180 PERF_START (NULL,"DisMem", NULL, 0);
181 Status = PeiCoreInstallPpi (&mMemoryDiscoveredPpi);
182 PERF_END (NULL,"DisMem", NULL, 0);
183
184 } else {
185
186 //
187 // Report Status Code EFI_SW_PC_INIT
188 //
189 REPORT_STATUS_CODE (
190 EFI_PROGRESS_CODE,
191 EFI_SOFTWARE_PEI_CORE | EFI_SW_PC_INIT
192 );
193
194 //
195 // If first pass, start performance measurement.
196 //
197 PERF_START (NULL,"PreMem", NULL, mTick);
198
199 //
200 // If SEC provided any PPI services to PEI, install them.
201 //
202 if (PeiStartupDescriptor->DispatchTable != NULL) {
203 Status = PeiCoreInstallPpi (PeiStartupDescriptor->DispatchTable);
204 ASSERT_EFI_ERROR (Status);
205 }
206 }
207
208 DispatchData = &PrivateData.DispatchData;
209
210 //
211 // Call PEIM dispatcher
212 //
213 PeiDispatcher (PeiStartupDescriptor, &PrivateData, DispatchData);
214
215 //
216 // Check if InstallPeiMemory service was called.
217 //
218 ASSERT(PrivateData.PeiMemoryInstalled == TRUE);
219
220 PERF_END (NULL, "PostMem", NULL, 0);
221
222 Status = PeiCoreLocatePpi (
223 &gEfiDxeIplPpiGuid,
224 0,
225 NULL,
226 (VOID **)&TempPtr.DxeIpl
227 );
228 ASSERT_EFI_ERROR (Status);
229
230 DEBUG ((EFI_D_INFO, "DXE IPL Entry\n"));
231 Status = TempPtr.DxeIpl->Entry (
232 TempPtr.DxeIpl,
233 &PrivateData.PS,
234 PrivateData.HobList
235 );
236
237 ASSERT_EFI_ERROR (Status);
238
239 return EFI_NOT_FOUND;
240}
241