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