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