]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Core/Pei/PeiMain/PeiMain.c
[PI compatible enabling] Add PeiRegisterForShadow interface for PEI_SERVICE
[mirror_edk2.git] / MdeModulePkg / Core / Pei / PeiMain / PeiMain.c
1 /*++
2
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
8
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.
11
12 Module Name:
13
14 PeiMain.c
15
16 Abstract:
17
18 Pei Core Main Entry Point
19
20 Revision 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
31 static 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 //
41 static 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 NULL,
74 NULL,
75 NULL,
76 NULL,
77 NULL,
78 PeiRegisterForShadow
79 };
80
81 EFI_STATUS
82 EFIAPI
83 PeiCore (
84 IN EFI_PEI_STARTUP_DESCRIPTOR *PeiStartupDescriptor,
85 IN VOID *Data
86 )
87 /*++
88
89 Routine Description:
90
91 The entry routine to Pei Core, invoked by PeiMain during transition
92 from SEC to PEI. After switching stack in the PEI core, it will restart
93 with the old core data.
94
95 Arguments:
96
97 PeiStartupDescriptor - Information and services provided by SEC phase.
98 OldCoreData - Pointer to old core data that is used to initialize the
99 core's data areas.
100
101 Returns:
102
103 This function never returns
104 EFI_NOT_FOUND - Never reach
105
106 --*/
107 {
108 PEI_CORE_INSTANCE PrivateData;
109 EFI_STATUS Status;
110 PEI_CORE_TEMP_POINTERS TempPtr;
111 PEI_CORE_DISPATCH_DATA *DispatchData;
112 UINT64 mTick;
113 PEI_CORE_INSTANCE *OldCoreData;
114
115 mTick = 0;
116 OldCoreData = (PEI_CORE_INSTANCE *) Data;
117
118 if (PerformanceMeasurementEnabled()) {
119 if (OldCoreData == NULL) {
120 mTick = GetPerformanceCounter ();
121 }
122 }
123
124 //
125 // For IPF in CAR mode the real memory access is uncached,in InstallPeiMemory()
126 // the 63-bit of address is set to 1.
127 //
128 SWITCH_TO_CACHE_MODE (OldCoreData);
129
130 if (OldCoreData != NULL) {
131 CopyMem (&PrivateData, OldCoreData, sizeof (PEI_CORE_INSTANCE));
132 } else {
133 ZeroMem (&PrivateData, sizeof (PEI_CORE_INSTANCE));
134 }
135
136 PrivateData.Signature = PEI_CORE_HANDLE_SIGNATURE;
137 PrivateData.PS = &mPS;
138
139 //
140 // Initialize libraries that the PeiCore is linked against
141 // BUGBUG: The FfsHeader is passed in as NULL. Do we look it up or remove it from the lib init?
142 //
143 ProcessLibraryConstructorList (NULL, &PrivateData.PS);
144
145 InitializeMemoryServices (&PrivateData.PS, PeiStartupDescriptor, OldCoreData);
146
147 InitializePpiServices (&PrivateData.PS, OldCoreData);
148
149 InitializeSecurityServices (&PrivateData.PS, OldCoreData);
150
151 InitializeDispatcherData (&PrivateData.PS, OldCoreData, PeiStartupDescriptor);
152
153 if (OldCoreData != NULL) {
154
155 PERF_END (NULL,"PreMem", NULL, 0);
156 PERF_START (NULL,"PostMem", NULL, 0);
157
158 //
159 // The following code dumps out interesting cache as RAM usage information
160 // so we can keep tabs on how the cache as RAM is being utilized. The
161 // DEBUG_CODE_BEGIN macro is used to prevent this code from being compiled
162 // on a debug build.
163 //
164 DEBUG_CODE_BEGIN ();
165 UINTN *StackPointer;
166 UINTN StackValue;
167
168 StackValue = INIT_CAR_VALUE;
169 for (StackPointer = (UINTN *) OldCoreData->MaxTopOfCarHeap;
170 ((UINTN) StackPointer < ((UINTN) OldCoreData->BottomOfCarHeap + OldCoreData->SizeOfCacheAsRam))
171 && StackValue == INIT_CAR_VALUE;
172 StackPointer++) {
173 StackValue = *StackPointer;
174 }
175
176 DEBUG ((EFI_D_INFO, "Total Cache as RAM: %d bytes.\n", OldCoreData->SizeOfCacheAsRam));
177 DEBUG ((EFI_D_INFO, " CAR stack ever used: %d bytes.\n",
178 ((UINTN) OldCoreData->TopOfCarHeap - (UINTN) StackPointer)
179 ));
180 DEBUG ((EFI_D_INFO, " CAR heap used: %d bytes.\n",
181 ((UINTN) OldCoreData->HobList.HandoffInformationTable->EfiFreeMemoryBottom -
182 (UINTN) OldCoreData->HobList.Raw)
183 ));
184 DEBUG_CODE_END ();
185
186 //
187 // Alert any listeners that there is permanent memory available
188 //
189
190 PERF_START (NULL,"DisMem", NULL, 0);
191 Status = PeiServicesInstallPpi (&mMemoryDiscoveredPpi);
192 PERF_END (NULL,"DisMem", NULL, 0);
193
194 } else {
195
196 //
197 // Report Status Code EFI_SW_PC_INIT
198 //
199 REPORT_STATUS_CODE (
200 EFI_PROGRESS_CODE,
201 EFI_SOFTWARE_PEI_CORE | EFI_SW_PC_INIT
202 );
203
204 PERF_START (NULL,"PEI", NULL, mTick);
205 //
206 // If first pass, start performance measurement.
207 //
208 PERF_START (NULL,"PreMem", NULL, mTick);
209
210 //
211 // If SEC provided any PPI services to PEI, install them.
212 //
213 if (PeiStartupDescriptor->DispatchTable != NULL) {
214 Status = PeiServicesInstallPpi (PeiStartupDescriptor->DispatchTable);
215 ASSERT_EFI_ERROR (Status);
216 }
217 }
218
219 DispatchData = &PrivateData.DispatchData;
220
221 //
222 // Call PEIM dispatcher
223 //
224 PeiDispatcher (PeiStartupDescriptor, &PrivateData, DispatchData);
225
226 //
227 // Check if InstallPeiMemory service was called.
228 //
229 ASSERT(PrivateData.PeiMemoryInstalled == TRUE);
230
231 PERF_END (NULL, "PostMem", NULL, 0);
232
233 Status = PeiServicesLocatePpi (
234 &gEfiDxeIplPpiGuid,
235 0,
236 NULL,
237 (VOID **)&TempPtr.DxeIpl
238 );
239 ASSERT_EFI_ERROR (Status);
240
241 DEBUG ((EFI_D_INFO, "DXE IPL Entry\n"));
242 Status = TempPtr.DxeIpl->Entry (
243 TempPtr.DxeIpl,
244 &PrivateData.PS,
245 PrivateData.HobList
246 );
247
248 ASSERT_EFI_ERROR (Status);
249
250 return EFI_NOT_FOUND;
251 }
252