]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Core/Pei/PeiMain/PeiMain.c
1) If PeiLoadImage fails, the section extraction PPI or Decompress PPI may not be...
[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
b0d803fe 64 PeiInstallPeiMemory, \r
192f6d4c 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
14e8823a 71 PeiResetSystem,\r
b0d803fe 72\r
14e8823a 73 NULL,\r
74 NULL,\r
b0d803fe 75\r
76 PeiFfsFindFileByName,\r
77 PeiFfsGetFileInfo,\r
78 PeiFfsGetVolumeInfo,\r
14e8823a 79 PeiRegisterForShadow\r
192f6d4c 80};\r
81\r
82EFI_STATUS\r
83EFIAPI\r
84PeiCore (\r
5aae0aa7 85 IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData,\r
5088e385 86 IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList,\r
5aae0aa7 87 IN VOID *Data\r
192f6d4c 88 )\r
89/*++\r
90\r
91Routine Description:\r
92\r
93 The entry routine to Pei Core, invoked by PeiMain during transition\r
94 from SEC to PEI. After switching stack in the PEI core, it will restart\r
95 with the old core data.\r
96\r
97Arguments:\r
98\r
5aae0aa7 99 SecCoreData - Points to a data structure containing information about the PEI core's operating\r
100 environment, such as the size and location of temporary RAM, the stack location and\r
101 the BFV location.\r
102 PpiList - Points to a list of one or more PPI descriptors to be installed initially by the PEI core.\r
103 An empty PPI list consists of a single descriptor with the end-tag\r
104 EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST. As part of its initialization\r
105 phase, the PEI Foundation will add these SEC-hosted PPIs to its PPI database such\r
106 that both the PEI Foundation and any modules can leverage the associated service\r
107 calls and/or code in these early PPIs\r
108 Data - Pointer to old core data that is used to initialize the\r
192f6d4c 109 core's data areas.\r
110\r
111Returns:\r
112\r
113 This function never returns\r
114 EFI_NOT_FOUND - Never reach\r
115\r
116--*/\r
117{\r
118 PEI_CORE_INSTANCE PrivateData;\r
119 EFI_STATUS Status;\r
120 PEI_CORE_TEMP_POINTERS TempPtr;\r
192f6d4c 121 UINT64 mTick;\r
122 PEI_CORE_INSTANCE *OldCoreData;\r
b0d803fe 123 EFI_PEI_CPU_IO_PPI *CpuIo;\r
124 EFI_PEI_PCI_CFG2_PPI *PciCfg;\r
02422d17 125 UINT64 SecPlatformInfoRecordSize;\r
126 EFI_SEC_PLATFORM_INFORMATION_PPI *SecPlatformInfoPpi;\r
127 EFI_SEC_PLATFORM_INFORMATION_RECORD *SecPlatformInfoRecord;\r
192f6d4c 128\r
129 mTick = 0;\r
130 OldCoreData = (PEI_CORE_INSTANCE *) Data;\r
131\r
132 if (PerformanceMeasurementEnabled()) {\r
133 if (OldCoreData == NULL) {\r
134 mTick = GetPerformanceCounter ();\r
135 }\r
136 }\r
137\r
192f6d4c 138 if (OldCoreData != NULL) {\r
139 CopyMem (&PrivateData, OldCoreData, sizeof (PEI_CORE_INSTANCE));\r
b0d803fe 140 \r
141 CpuIo = (VOID*)PrivateData.ServiceTableShadow.CpuIo;\r
142 PciCfg = (VOID*)PrivateData.ServiceTableShadow.PciCfg;\r
143 \r
144 CopyMem (&PrivateData.ServiceTableShadow, &mPS, sizeof (mPS));\r
145 \r
146 PrivateData.ServiceTableShadow.CpuIo = CpuIo;\r
147 PrivateData.ServiceTableShadow.PciCfg = PciCfg;\r
192f6d4c 148 } else {\r
149 ZeroMem (&PrivateData, sizeof (PEI_CORE_INSTANCE));\r
b0d803fe 150 PrivateData.Signature = PEI_CORE_HANDLE_SIGNATURE;\r
151 CopyMem (&PrivateData.ServiceTableShadow, &mPS, sizeof (mPS));\r
192f6d4c 152 }\r
153\r
b0d803fe 154 PrivateData.PS = &PrivateData.ServiceTableShadow;\r
192f6d4c 155\r
156 //\r
157 // Initialize libraries that the PeiCore is linked against\r
b0d803fe 158 // BUGBUG: The FileHandle is passed in as NULL. Do we look it up or remove it from the lib init?\r
192f6d4c 159 //\r
160 ProcessLibraryConstructorList (NULL, &PrivateData.PS);\r
161\r
b0d803fe 162 InitializeMemoryServices (&PrivateData, SecCoreData, OldCoreData);\r
192f6d4c 163\r
b0d803fe 164 InitializePpiServices (&PrivateData, OldCoreData);\r
192f6d4c 165\r
81c7803c 166 //\r
167 // Save PeiServicePointer so that it can be retrieved anywhere.\r
168 //\r
169 SetPeiServicesTablePointer(&PrivateData.PS);\r
170 \r
192f6d4c 171 if (OldCoreData != NULL) {\r
172\r
173 PERF_END (NULL,"PreMem", NULL, 0);\r
174 PERF_START (NULL,"PostMem", NULL, 0);\r
175\r
176 //\r
177 // The following code dumps out interesting cache as RAM usage information\r
178 // so we can keep tabs on how the cache as RAM is being utilized. The\r
179 // DEBUG_CODE_BEGIN macro is used to prevent this code from being compiled\r
180 // on a debug build.\r
181 //\r
182 DEBUG_CODE_BEGIN ();\r
183 UINTN *StackPointer;\r
184 UINTN StackValue;\r
185\r
186 StackValue = INIT_CAR_VALUE;\r
6797657e 187 for (StackPointer = (UINTN *) OldCoreData->TopOfCarHeap;\r
188 ((UINTN) StackPointer < ((UINTN) OldCoreData->MaxTopOfCarHeap))\r
192f6d4c 189 && StackValue == INIT_CAR_VALUE;\r
190 StackPointer++) {\r
191 StackValue = *StackPointer;\r
192 }\r
6797657e 193 \r
192f6d4c 194 DEBUG ((EFI_D_INFO, "Total Cache as RAM: %d bytes.\n", OldCoreData->SizeOfCacheAsRam));\r
195 DEBUG ((EFI_D_INFO, " CAR stack ever used: %d bytes.\n",\r
61f21f40 196 ((UINTN) OldCoreData->MaxTopOfCarHeap - (UINTN) StackPointer)\r
192f6d4c 197 ));\r
198 DEBUG ((EFI_D_INFO, " CAR heap used: %d bytes.\n",\r
199 ((UINTN) OldCoreData->HobList.HandoffInformationTable->EfiFreeMemoryBottom -\r
200 (UINTN) OldCoreData->HobList.Raw)\r
201 ));\r
202 DEBUG_CODE_END ();\r
203\r
204 //\r
205 // Alert any listeners that there is permanent memory available\r
206 //\r
207 \r
208 PERF_START (NULL,"DisMem", NULL, 0);\r
209 Status = PeiServicesInstallPpi (&mMemoryDiscoveredPpi);\r
210 PERF_END (NULL,"DisMem", NULL, 0);\r
211\r
212 } else {\r
213\r
214 //\r
215 // Report Status Code EFI_SW_PC_INIT\r
216 //\r
217 REPORT_STATUS_CODE (\r
218 EFI_PROGRESS_CODE,\r
219 EFI_SOFTWARE_PEI_CORE | EFI_SW_PC_INIT\r
220 );\r
221\r
222 PERF_START (NULL,"PEI", NULL, mTick);\r
223 //\r
224 // If first pass, start performance measurement.\r
225 //\r
226 PERF_START (NULL,"PreMem", NULL, mTick);\r
227\r
228 //\r
229 // If SEC provided any PPI services to PEI, install them.\r
230 //\r
5088e385 231 if (PpiList != NULL) {\r
232 Status = PeiServicesInstallPpi (PpiList);\r
192f6d4c 233 ASSERT_EFI_ERROR (Status);\r
02422d17 234 \r
235 //\r
236 // PI spec Vol 1, 7.3.1 specifies that this same information reported by EFI_SEC_PLATFORM_INFORMATION_PPI\r
237 // will be placed in a GUIDed HOB with the PPI GUID as the HOB GUID for HOB consumer phase.\r
238 //\r
239 Status = PeiServicesLocatePpi (\r
240 &gEfiSecPlatformInformationPpiGuid,\r
241 0,\r
242 NULL,\r
243 (VOID **) &SecPlatformInfoPpi\r
244 );\r
245 if (!EFI_ERROR (Status)) {\r
246 SecPlatformInfoRecord = AllocateZeroPool (sizeof(*SecPlatformInfoRecord));\r
247 ASSERT (SecPlatformInfoRecord != NULL);\r
248\r
249 SecPlatformInfoRecordSize = sizeof(*SecPlatformInfoRecord);\r
250 \r
251 Status = SecPlatformInfoPpi->PlatformInformation (\r
252 (CONST EFI_PEI_SERVICES **) GetPeiServicesTablePointer (),\r
253 &SecPlatformInfoRecordSize,\r
254 SecPlatformInfoRecord\r
255 );\r
256 \r
257 if (!EFI_ERROR (Status)) {\r
258 BuildGuidDataHob (\r
259 &gEfiSecPlatformInformationPpiGuid,\r
260 SecPlatformInfoRecord,\r
261 sizeof (*SecPlatformInfoRecord)\r
262 );\r
263 }\r
264 }\r
192f6d4c 265 }\r
266 }\r
267\r
b0d803fe 268 InitializeSecurityServices (&PrivateData.PS, OldCoreData);\r
269\r
270 InitializeDispatcherData (&PrivateData, OldCoreData, SecCoreData);\r
271\r
272 //\r
273 // Install Pei Load File PPI. \r
274 //\r
275 InitializeImageServices (&PrivateData, OldCoreData);\r
192f6d4c 276\r
277 //\r
278 // Call PEIM dispatcher\r
279 //\r
b0d803fe 280 PeiDispatcher (SecCoreData, &PrivateData);\r
192f6d4c 281\r
282 //\r
283 // Check if InstallPeiMemory service was called.\r
284 //\r
285 ASSERT(PrivateData.PeiMemoryInstalled == TRUE);\r
286\r
287 PERF_END (NULL, "PostMem", NULL, 0);\r
288\r
289 Status = PeiServicesLocatePpi (\r
290 &gEfiDxeIplPpiGuid,\r
291 0,\r
292 NULL,\r
293 (VOID **)&TempPtr.DxeIpl\r
294 );\r
295 ASSERT_EFI_ERROR (Status);\r
296\r
297 DEBUG ((EFI_D_INFO, "DXE IPL Entry\n"));\r
298 Status = TempPtr.DxeIpl->Entry (\r
299 TempPtr.DxeIpl,\r
300 &PrivateData.PS,\r
301 PrivateData.HobList\r
302 );\r
303\r
304 ASSERT_EFI_ERROR (Status);\r
305\r
306 return EFI_NOT_FOUND;\r
307}\r
308\r
a3a15d21 309\r