]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdeModulePkg/Core/Pei/PeiMain/PeiMain.c
Correct comments.
[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, 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
13**/\r
14\r
15#include <PeiMain.h>\r
16\r
17STATIC EFI_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 Core Module Variables\r
25///\r
26///\r
27STATIC EFI_PEI_SERVICES gPs = {\r
28 {\r
29 PEI_SERVICES_SIGNATURE,\r
30 PEI_SERVICES_REVISION,\r
31 sizeof (EFI_PEI_SERVICES),\r
32 0,\r
33 0\r
34 },\r
35 PeiInstallPpi,\r
36 PeiReInstallPpi,\r
37 PeiLocatePpi,\r
38 PeiNotifyPpi,\r
39\r
40 PeiGetBootMode,\r
41 PeiSetBootMode,\r
42\r
43 PeiGetHobList,\r
44 PeiCreateHob,\r
45\r
46 PeiFvFindNextVolume,\r
47 PeiFfsFindNextFile,\r
48 PeiFfsFindSectionData,\r
49\r
50 PeiInstallPeiMemory, \r
51 PeiAllocatePages,\r
52 PeiAllocatePool,\r
53 (EFI_PEI_COPY_MEM)CopyMem,\r
54 (EFI_PEI_SET_MEM)SetMem,\r
55\r
56 PeiReportStatusCode,\r
57 PeiResetSystem,\r
58\r
59 NULL,\r
60 NULL,\r
61\r
62 PeiFfsFindFileByName,\r
63 PeiFfsGetFileInfo,\r
64 PeiFfsGetVolumeInfo,\r
65 PeiRegisterForShadow\r
66};\r
67\r
68/**\r
69\r
70 The entry routine to Pei Core, invoked by PeiMain during transition\r
71 from SEC to PEI. After switching stack in the PEI core, it will restart\r
72 with the old core data.\r
73\r
74\r
75 @param SecCoreData Points to a data structure containing information about the PEI core's operating\r
76 environment, such as the size and location of temporary RAM, the stack location and\r
77 the BFV location.\r
78 @param PpiList Points to a list of one or more PPI descriptors to be installed initially by the PEI core.\r
79 An empty PPI list consists of a single descriptor with the end-tag\r
80 EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST. As part of its initialization\r
81 phase, the PEI Foundation will add these SEC-hosted PPIs to its PPI database such\r
82 that both the PEI Foundation and any modules can leverage the associated service\r
83 calls and/or code in these early PPIs\r
84 @param Data Pointer to old core data that is used to initialize the\r
85 core's data areas.\r
86\r
87 @retval EFI_NOT_FOUND Never reach\r
88\r
89**/\r
90EFI_STATUS\r
91EFIAPI\r
92PeiCore (\r
93 IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData,\r
94 IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList,\r
95 IN VOID *Data\r
96 )\r
97{\r
98 PEI_CORE_INSTANCE PrivateData;\r
99 EFI_STATUS Status;\r
100 PEI_CORE_TEMP_POINTERS TempPtr;\r
101 UINT64 mTick;\r
102 PEI_CORE_INSTANCE *OldCoreData;\r
103 EFI_PEI_CPU_IO_PPI *CpuIo;\r
104 EFI_PEI_PCI_CFG2_PPI *PciCfg;\r
105 PEICORE_FUNCTION_POINTER ShadowedPeiCore;\r
106\r
107 mTick = 0;\r
108 OldCoreData = (PEI_CORE_INSTANCE *) Data;\r
109\r
110 //\r
111 // Record the system tick for first entering PeiCore.\r
112 // This tick is duration of executing platform seccore module.\r
113 // \r
114 if (PerformanceMeasurementEnabled()) {\r
115 if (OldCoreData == NULL) {\r
116 mTick = GetPerformanceCounter ();\r
117 }\r
118 }\r
119\r
120 //\r
121 // PeiCore has been shadowed to memory for first entering, so\r
122 // just jump to PeiCore in memory here.\r
123 //\r
124 if (OldCoreData != NULL) {\r
125 ShadowedPeiCore = (PEICORE_FUNCTION_POINTER) (UINTN) OldCoreData->ShadowedPeiCore;\r
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
135 CopyMem (&PrivateData, OldCoreData, sizeof (PEI_CORE_INSTANCE));\r
136 \r
137 CpuIo = (VOID*)PrivateData.ServiceTableShadow.CpuIo;\r
138 PciCfg = (VOID*)PrivateData.ServiceTableShadow.PciCfg;\r
139 \r
140 CopyMem (&PrivateData.ServiceTableShadow, &gPs, sizeof (gPs));\r
141 \r
142 PrivateData.ServiceTableShadow.CpuIo = CpuIo;\r
143 PrivateData.ServiceTableShadow.PciCfg = PciCfg;\r
144 } else {\r
145 ZeroMem (&PrivateData, sizeof (PEI_CORE_INSTANCE));\r
146 PrivateData.Signature = PEI_CORE_HANDLE_SIGNATURE;\r
147 CopyMem (&PrivateData.ServiceTableShadow, &gPs, sizeof (gPs));\r
148 }\r
149\r
150 PrivateData.PS = &PrivateData.ServiceTableShadow;\r
151\r
152 //\r
153 // Initialize libraries that the PeiCore is linked against\r
154 //\r
155 ProcessLibraryConstructorList (NULL, &PrivateData.PS);\r
156\r
157 InitializeMemoryServices (&PrivateData, SecCoreData, OldCoreData);\r
158\r
159 InitializePpiServices (&PrivateData, OldCoreData);\r
160\r
161 //\r
162 // Save PeiServicePointer so that it can be retrieved anywhere.\r
163 //\r
164 SetPeiServicesTablePointer(&PrivateData.PS);\r
165 \r
166 if (OldCoreData != NULL) {\r
167\r
168 PERF_END (NULL,"PreMem", NULL, 0);\r
169 PERF_START (NULL,"PostMem", NULL, 0);\r
170\r
171 //\r
172 // Alert any listeners that there is permanent memory available\r
173 //\r
174 \r
175 PERF_START (NULL,"DisMem", NULL, 0);\r
176 Status = PeiServicesInstallPpi (&mMemoryDiscoveredPpi);\r
177 PERF_END (NULL,"DisMem", NULL, 0);\r
178\r
179 } else {\r
180\r
181 //\r
182 // Report Status Code EFI_SW_PC_INIT\r
183 //\r
184 REPORT_STATUS_CODE (\r
185 EFI_PROGRESS_CODE,\r
186 FixedPcdGet32 (PcdStatusCodeValuePeiCoreEntry)\r
187 );\r
188\r
189 PERF_START (NULL,"PEI", NULL, mTick);\r
190 //\r
191 // If first pass, start performance measurement.\r
192 //\r
193 PERF_START (NULL,"PreMem", NULL, mTick);\r
194\r
195 //\r
196 // If SEC provided any PPI services to PEI, install them.\r
197 //\r
198 if (PpiList != NULL) {\r
199 Status = PeiServicesInstallPpi (PpiList);\r
200 ASSERT_EFI_ERROR (Status);\r
201 }\r
202 }\r
203\r
204 InitializeSecurityServices (&PrivateData.PS, OldCoreData);\r
205\r
206 InitializeDispatcherData (&PrivateData, OldCoreData, SecCoreData);\r
207\r
208 //\r
209 // Install Pei Load File PPI. \r
210 //\r
211 InitializeImageServices (&PrivateData, OldCoreData);\r
212\r
213 //\r
214 // Call PEIM dispatcher\r
215 //\r
216 PeiDispatcher (SecCoreData, &PrivateData);\r
217\r
218 //\r
219 // Check if InstallPeiMemory service was called.\r
220 //\r
221 ASSERT(PrivateData.PeiMemoryInstalled == TRUE);\r
222\r
223 //\r
224 // Till now, PEI phase will be finished, get performace count\r
225 // for computing duration of PEI phase\r
226 //\r
227 PERF_END (NULL, "PostMem", NULL, 0);\r
228\r
229 Status = PeiServicesLocatePpi (\r
230 &gEfiDxeIplPpiGuid,\r
231 0,\r
232 NULL,\r
233 (VOID **)&TempPtr.DxeIpl\r
234 );\r
235 ASSERT_EFI_ERROR (Status);\r
236\r
237 //\r
238 // Enter DxeIpl to load Dxe core.\r
239 //\r
240 DEBUG ((EFI_D_INFO, "DXE IPL Entry\n"));\r
241 Status = TempPtr.DxeIpl->Entry (\r
242 TempPtr.DxeIpl,\r
243 &PrivateData.PS,\r
244 PrivateData.HobList\r
245 );\r
246\r
247 ASSERT_EFI_ERROR (Status);\r
248\r
249 return EFI_NOT_FOUND;\r
250}\r
251\r
252\r