]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Core/Pei/PeiMain/PeiMain.c
Patch to remove STATIC modifier. This is on longer recommended by EFI Framework codin...
[mirror_edk2.git] / MdeModulePkg / Core / Pei / PeiMain / PeiMain.c
CommitLineData
615c6dd0 1/** @file\r
b1f6a7c6 2 Pei Core Main Entry Point\r
3 \r
192f6d4c 4Copyright (c) 2006, Intel Corporation\r
5All rights reserved. This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
615c6dd0 13**/\r
192f6d4c 14\r
192f6d4c 15#include <PeiMain.h>\r
16\r
b1f6a7c6 17STATIC EFI_PEI_PPI_DESCRIPTOR mMemoryDiscoveredPpi = {\r
192f6d4c 18 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
19 &gEfiPeiMemoryDiscoveredPpiGuid,\r
20 NULL\r
21};\r
22\r
40f26b8f 23///\r
82b8c8df 24/// Pei service instance\r
40f26b8f 25///\r
b1f6a7c6 26STATIC EFI_PEI_SERVICES gPs = {\r
192f6d4c 27 {\r
28 PEI_SERVICES_SIGNATURE,\r
29 PEI_SERVICES_REVISION,\r
30 sizeof (EFI_PEI_SERVICES),\r
31 0,\r
32 0\r
33 },\r
34 PeiInstallPpi,\r
35 PeiReInstallPpi,\r
36 PeiLocatePpi,\r
37 PeiNotifyPpi,\r
38\r
39 PeiGetBootMode,\r
40 PeiSetBootMode,\r
41\r
42 PeiGetHobList,\r
43 PeiCreateHob,\r
44\r
45 PeiFvFindNextVolume,\r
46 PeiFfsFindNextFile,\r
47 PeiFfsFindSectionData,\r
48\r
b0d803fe 49 PeiInstallPeiMemory, \r
192f6d4c 50 PeiAllocatePages,\r
51 PeiAllocatePool,\r
52 (EFI_PEI_COPY_MEM)CopyMem,\r
53 (EFI_PEI_SET_MEM)SetMem,\r
54\r
55 PeiReportStatusCode,\r
14e8823a 56 PeiResetSystem,\r
b0d803fe 57\r
14e8823a 58 NULL,\r
59 NULL,\r
b0d803fe 60\r
61 PeiFfsFindFileByName,\r
62 PeiFfsGetFileInfo,\r
63 PeiFfsGetVolumeInfo,\r
14e8823a 64 PeiRegisterForShadow\r
192f6d4c 65};\r
66\r
b1f6a7c6 67/**\r
192f6d4c 68\r
82b8c8df 69 This routine is invoked by main entry of PeiMain module during transition\r
192f6d4c 70 from SEC to PEI. After switching stack in the PEI core, it will restart\r
71 with the old core data.\r
72\r
b1f6a7c6 73 @param SecCoreData Points to a data structure containing information about the PEI core's operating\r
5aae0aa7 74 environment, such as the size and location of temporary RAM, the stack location and\r
75 the BFV location.\r
b1f6a7c6 76 @param PpiList Points to a list of one or more PPI descriptors to be installed initially by the PEI core.\r
5aae0aa7 77 An empty PPI list consists of a single descriptor with the end-tag\r
78 EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST. As part of its initialization\r
79 phase, the PEI Foundation will add these SEC-hosted PPIs to its PPI database such\r
80 that both the PEI Foundation and any modules can leverage the associated service\r
81 calls and/or code in these early PPIs\r
b1f6a7c6 82 @param Data Pointer to old core data that is used to initialize the\r
192f6d4c 83 core's data areas.\r
82b8c8df 84 If NULL, it is first PeiCore entering.\r
192f6d4c 85\r
b1f6a7c6 86 @retval EFI_NOT_FOUND Never reach\r
192f6d4c 87\r
b1f6a7c6 88**/\r
0308e20d 89VOID\r
b1f6a7c6 90EFIAPI\r
91PeiCore (\r
92 IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData,\r
93 IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList,\r
94 IN VOID *Data\r
95 )\r
192f6d4c 96{\r
97 PEI_CORE_INSTANCE PrivateData;\r
98 EFI_STATUS Status;\r
99 PEI_CORE_TEMP_POINTERS TempPtr;\r
82b8c8df 100 UINT64 Tick;\r
192f6d4c 101 PEI_CORE_INSTANCE *OldCoreData;\r
b0d803fe 102 EFI_PEI_CPU_IO_PPI *CpuIo;\r
103 EFI_PEI_PCI_CFG2_PPI *PciCfg;\r
15273993 104 PEICORE_FUNCTION_POINTER ShadowedPeiCore;\r
192f6d4c 105\r
82b8c8df 106 Tick = 0;\r
192f6d4c 107 OldCoreData = (PEI_CORE_INSTANCE *) Data;\r
108\r
40f26b8f 109 //\r
110 // Record the system tick for first entering PeiCore.\r
111 // This tick is duration of executing platform seccore module.\r
112 // \r
192f6d4c 113 if (PerformanceMeasurementEnabled()) {\r
114 if (OldCoreData == NULL) {\r
82b8c8df 115 Tick = GetPerformanceCounter ();\r
192f6d4c 116 }\r
117 }\r
118\r
192f6d4c 119 if (OldCoreData != NULL) {\r
15273993 120 ShadowedPeiCore = (PEICORE_FUNCTION_POINTER) (UINTN) OldCoreData->ShadowedPeiCore;\r
82b8c8df 121 \r
122 //\r
123 // PeiCore has been shadowed to memory for first entering, so\r
124 // just jump to PeiCore in memory here.\r
125 //\r
58dcdada 126 if (ShadowedPeiCore != NULL) {\r
127 OldCoreData->ShadowedPeiCore = NULL;\r
128 ShadowedPeiCore (\r
129 SecCoreData,\r
130 PpiList,\r
131 OldCoreData\r
132 );\r
133 }\r
134\r
192f6d4c 135 CopyMem (&PrivateData, OldCoreData, sizeof (PEI_CORE_INSTANCE));\r
b0d803fe 136 \r
137 CpuIo = (VOID*)PrivateData.ServiceTableShadow.CpuIo;\r
138 PciCfg = (VOID*)PrivateData.ServiceTableShadow.PciCfg;\r
139 \r
b1f6a7c6 140 CopyMem (&PrivateData.ServiceTableShadow, &gPs, sizeof (gPs));\r
b0d803fe 141 \r
142 PrivateData.ServiceTableShadow.CpuIo = CpuIo;\r
143 PrivateData.ServiceTableShadow.PciCfg = PciCfg;\r
192f6d4c 144 } else {\r
82b8c8df 145 //\r
146 // If OldCoreData is NULL, means current is first Peicore's entering.\r
147 //\r
148 \r
192f6d4c 149 ZeroMem (&PrivateData, sizeof (PEI_CORE_INSTANCE));\r
b0d803fe 150 PrivateData.Signature = PEI_CORE_HANDLE_SIGNATURE;\r
b1f6a7c6 151 CopyMem (&PrivateData.ServiceTableShadow, &gPs, sizeof (gPs));\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
192f6d4c 158 //\r
0308e20d 159 ProcessLibraryConstructorList (NULL, (CONST EFI_PEI_SERVICES **)&PrivateData.PS);\r
192f6d4c 160\r
b0d803fe 161 InitializeMemoryServices (&PrivateData, SecCoreData, OldCoreData);\r
192f6d4c 162\r
b0d803fe 163 InitializePpiServices (&PrivateData, OldCoreData);\r
192f6d4c 164\r
81c7803c 165 //\r
166 // Save PeiServicePointer so that it can be retrieved anywhere.\r
167 //\r
6c7a807a 168 SetPeiServicesTablePointer((CONST EFI_PEI_SERVICES **) &PrivateData.PS);\r
81c7803c 169 \r
192f6d4c 170 if (OldCoreData != NULL) {\r
171\r
172 PERF_END (NULL,"PreMem", NULL, 0);\r
173 PERF_START (NULL,"PostMem", NULL, 0);\r
174\r
192f6d4c 175 //\r
176 // Alert any listeners that there is permanent memory available\r
177 //\r
178 \r
179 PERF_START (NULL,"DisMem", NULL, 0);\r
180 Status = PeiServicesInstallPpi (&mMemoryDiscoveredPpi);\r
181 PERF_END (NULL,"DisMem", NULL, 0);\r
182\r
183 } else {\r
184\r
185 //\r
186 // Report Status Code EFI_SW_PC_INIT\r
187 //\r
188 REPORT_STATUS_CODE (\r
189 EFI_PROGRESS_CODE,\r
797a9d67 190 FixedPcdGet32 (PcdStatusCodeValuePeiCoreEntry)\r
192f6d4c 191 );\r
008d4018 192 \r
193 PERF_START (NULL, "SEC", NULL, 1);\r
194 PERF_END (NULL, "SEC", NULL, Tick);\r
192f6d4c 195\r
82b8c8df 196 PERF_START (NULL,"PEI", NULL, Tick);\r
192f6d4c 197 //\r
198 // If first pass, start performance measurement.\r
199 //\r
82b8c8df 200 PERF_START (NULL,"PreMem", NULL, Tick);\r
192f6d4c 201\r
202 //\r
203 // If SEC provided any PPI services to PEI, install them.\r
204 //\r
5088e385 205 if (PpiList != NULL) {\r
206 Status = PeiServicesInstallPpi (PpiList);\r
192f6d4c 207 ASSERT_EFI_ERROR (Status);\r
208 }\r
209 }\r
210\r
b0d803fe 211 InitializeSecurityServices (&PrivateData.PS, OldCoreData);\r
212\r
213 InitializeDispatcherData (&PrivateData, OldCoreData, SecCoreData);\r
214\r
215 //\r
216 // Install Pei Load File PPI. \r
217 //\r
218 InitializeImageServices (&PrivateData, OldCoreData);\r
192f6d4c 219\r
220 //\r
221 // Call PEIM dispatcher\r
222 //\r
b0d803fe 223 PeiDispatcher (SecCoreData, &PrivateData);\r
192f6d4c 224\r
225 //\r
226 // Check if InstallPeiMemory service was called.\r
227 //\r
228 ASSERT(PrivateData.PeiMemoryInstalled == TRUE);\r
229\r
40f26b8f 230 //\r
231 // Till now, PEI phase will be finished, get performace count\r
232 // for computing duration of PEI phase\r
233 //\r
192f6d4c 234 PERF_END (NULL, "PostMem", NULL, 0);\r
235\r
236 Status = PeiServicesLocatePpi (\r
237 &gEfiDxeIplPpiGuid,\r
238 0,\r
239 NULL,\r
240 (VOID **)&TempPtr.DxeIpl\r
241 );\r
242 ASSERT_EFI_ERROR (Status);\r
243\r
40f26b8f 244 //\r
245 // Enter DxeIpl to load Dxe core.\r
246 //\r
192f6d4c 247 DEBUG ((EFI_D_INFO, "DXE IPL Entry\n"));\r
248 Status = TempPtr.DxeIpl->Entry (\r
249 TempPtr.DxeIpl,\r
250 &PrivateData.PS,\r
251 PrivateData.HobList\r
252 );\r
0308e20d 253 //\r
254 // Should never reach here.\r
255 //\r
192f6d4c 256 ASSERT_EFI_ERROR (Status);\r
0308e20d 257 CpuDeadLoop();\r
192f6d4c 258}\r
259\r
a3a15d21 260\r