]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdeModulePkg/Core/Pei/PeiMain/PeiMain.c
Update the copyright notice format
[mirror_edk2.git] / MdeModulePkg / Core / Pei / PeiMain / PeiMain.c
... / ...
CommitLineData
1/** @file\r
2 Pei Core Main Entry Point\r
3 \r
4Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
5This 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
13**/\r
14\r
15#include "PeiMain.h"\r
16\r
17EFI_PEI_PPI_DESCRIPTOR mMemoryDiscoveredPpi = {\r
18 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
19 &gEfiPeiMemoryDiscoveredPpiGuid,\r
20 NULL\r
21};\r
22\r
23///\r
24/// Pei service instance\r
25///\r
26EFI_PEI_SERVICES gPs = {\r
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 PeiFfsFindNextVolume,\r
46 PeiFfsFindNextFile,\r
47 PeiFfsFindSectionData,\r
48\r
49 PeiInstallPeiMemory, \r
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
56 PeiResetSystem,\r
57\r
58 &gPeiDefaultCpuIoPpi,\r
59 &gPeiDefaultPciCfg2Ppi,\r
60\r
61 PeiFfsFindFileByName,\r
62 PeiFfsGetFileInfo,\r
63 PeiFfsGetVolumeInfo,\r
64 PeiRegisterForShadow\r
65};\r
66\r
67/**\r
68 This routine is invoked by main entry of PeiMain module during transition\r
69 from SEC to PEI. After switching stack in the PEI core, it will restart\r
70 with the old core data.\r
71\r
72 @param SecCoreData Points to a data structure containing information about the PEI core's operating\r
73 environment, such as the size and location of temporary RAM, the stack location and\r
74 the BFV location.\r
75 @param PpiList Points to a list of one or more PPI descriptors to be installed initially by the PEI core.\r
76 An empty PPI list consists of a single descriptor with the end-tag\r
77 EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST. As part of its initialization\r
78 phase, the PEI Foundation will add these SEC-hosted PPIs to its PPI database such\r
79 that both the PEI Foundation and any modules can leverage the associated service\r
80 calls and/or code in these early PPIs\r
81 @param Data Pointer to old core data that is used to initialize the\r
82 core's data areas.\r
83 If NULL, it is first PeiCore entering.\r
84\r
85**/\r
86VOID\r
87EFIAPI\r
88PeiCore (\r
89 IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData,\r
90 IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList,\r
91 IN VOID *Data\r
92 )\r
93{\r
94 PEI_CORE_INSTANCE PrivateData;\r
95 EFI_STATUS Status;\r
96 PEI_CORE_TEMP_POINTERS TempPtr;\r
97 UINT64 Tick;\r
98 PEI_CORE_INSTANCE *OldCoreData;\r
99 EFI_PEI_CPU_IO_PPI *CpuIo;\r
100 EFI_PEI_PCI_CFG2_PPI *PciCfg;\r
101 PEICORE_FUNCTION_POINTER ShadowedPeiCore;\r
102\r
103 Tick = 0;\r
104 OldCoreData = (PEI_CORE_INSTANCE *) Data;\r
105\r
106 //\r
107 // Record the system tick for first entering PeiCore.\r
108 // This tick is duration of executing platform seccore module.\r
109 // \r
110 if (PerformanceMeasurementEnabled()) {\r
111 if (OldCoreData == NULL) {\r
112 Tick = GetPerformanceCounter ();\r
113 }\r
114 }\r
115\r
116 if (OldCoreData != NULL) {\r
117 ShadowedPeiCore = (PEICORE_FUNCTION_POINTER) (UINTN) OldCoreData->ShadowedPeiCore;\r
118 \r
119 //\r
120 // PeiCore has been shadowed to memory for first entering, so\r
121 // just jump to PeiCore in memory here.\r
122 //\r
123 if (ShadowedPeiCore != NULL) {\r
124 OldCoreData->ShadowedPeiCore = NULL;\r
125 ShadowedPeiCore (\r
126 SecCoreData,\r
127 PpiList,\r
128 OldCoreData\r
129 );\r
130 }\r
131\r
132 CopyMem (&PrivateData, OldCoreData, sizeof (PEI_CORE_INSTANCE));\r
133 \r
134 CpuIo = (VOID*)PrivateData.ServiceTableShadow.CpuIo;\r
135 PciCfg = (VOID*)PrivateData.ServiceTableShadow.PciCfg;\r
136 \r
137 CopyMem (&PrivateData.ServiceTableShadow, &gPs, sizeof (gPs));\r
138 \r
139 PrivateData.ServiceTableShadow.CpuIo = CpuIo;\r
140 PrivateData.ServiceTableShadow.PciCfg = PciCfg;\r
141 } else {\r
142 //\r
143 // If OldCoreData is NULL, means current is first Peicore's entering.\r
144 //\r
145 \r
146 ZeroMem (&PrivateData, sizeof (PEI_CORE_INSTANCE));\r
147 PrivateData.Signature = PEI_CORE_HANDLE_SIGNATURE;\r
148 CopyMem (&PrivateData.ServiceTableShadow, &gPs, sizeof (gPs));\r
149 }\r
150\r
151 PrivateData.Ps = &PrivateData.ServiceTableShadow;\r
152\r
153 //\r
154 // Initialize libraries that the PeiCore is linked against\r
155 //\r
156 ProcessLibraryConstructorList (NULL, (CONST EFI_PEI_SERVICES **)&PrivateData.Ps);\r
157\r
158 InitializeMemoryServices (&PrivateData, SecCoreData, OldCoreData);\r
159\r
160 InitializePpiServices (&PrivateData, OldCoreData);\r
161\r
162 //\r
163 // Save PeiServicePointer so that it can be retrieved anywhere.\r
164 //\r
165 SetPeiServicesTablePointer((CONST EFI_PEI_SERVICES **) &PrivateData.Ps);\r
166 \r
167 if (OldCoreData != NULL) {\r
168\r
169 PERF_END (NULL,"PreMem", NULL, 0);\r
170 PERF_START (NULL,"PostMem", NULL, 0);\r
171\r
172 //\r
173 // Alert any listeners that there is permanent memory available\r
174 //\r
175 \r
176 PERF_START (NULL,"DisMem", NULL, 0);\r
177 Status = PeiServicesInstallPpi (&mMemoryDiscoveredPpi);\r
178 PERF_END (NULL,"DisMem", NULL, 0);\r
179\r
180 } else {\r
181\r
182 //\r
183 // Report Status Code EFI_SW_PC_INIT\r
184 //\r
185 REPORT_STATUS_CODE (\r
186 EFI_PROGRESS_CODE,\r
187 (EFI_SOFTWARE_PEI_CORE | EFI_SW_PC_INIT)\r
188 );\r
189 \r
190 PERF_START (NULL, "SEC", NULL, 1);\r
191 PERF_END (NULL, "SEC", NULL, Tick);\r
192\r
193 PERF_START (NULL,"PEI", NULL, Tick);\r
194 //\r
195 // If first pass, start performance measurement.\r
196 //\r
197 PERF_START (NULL,"PreMem", NULL, Tick);\r
198\r
199 //\r
200 // If SEC provided any PPI services to PEI, install them.\r
201 //\r
202 if (PpiList != NULL) {\r
203 Status = PeiServicesInstallPpi (PpiList);\r
204 ASSERT_EFI_ERROR (Status);\r
205 }\r
206 }\r
207\r
208 InitializeSecurityServices (&PrivateData.Ps, OldCoreData);\r
209\r
210 InitializeDispatcherData (&PrivateData, OldCoreData, SecCoreData);\r
211\r
212 //\r
213 // Install Pei Load File PPI. \r
214 //\r
215 InitializeImageServices (&PrivateData, OldCoreData);\r
216\r
217 //\r
218 // Call PEIM dispatcher\r
219 //\r
220 PeiDispatcher (SecCoreData, &PrivateData);\r
221\r
222 //\r
223 // Check if InstallPeiMemory service was called.\r
224 //\r
225 ASSERT(PrivateData.PeiMemoryInstalled == TRUE);\r
226\r
227 //\r
228 // Till now, PEI phase will be finished, get performace count\r
229 // for computing duration of PEI phase\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 //\r
242 // Enter DxeIpl to load Dxe core.\r
243 //\r
244 DEBUG ((EFI_D_INFO, "DXE IPL Entry\n"));\r
245 Status = TempPtr.DxeIpl->Entry (\r
246 TempPtr.DxeIpl,\r
247 &PrivateData.Ps,\r
248 PrivateData.HobList\r
249 );\r
250 //\r
251 // Should never reach here.\r
252 //\r
253 ASSERT_EFI_ERROR (Status);\r
254 CpuDeadLoop();\r
255}\r
256\r
257\r