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