]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Core/Pei/PeiMain/PeiMain.c
Update Mde/MdeModulePkg to support ICC build for IA32/X64.
[mirror_edk2.git] / MdeModulePkg / Core / Pei / PeiMain / PeiMain.c
1 /*++
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 //
27 //CAR is filled with this initial value during SEC phase
28 //
29 #define INIT_CAR_VALUE 0x5AA55AA5
30
31 static EFI_PEI_PPI_DESCRIPTOR mMemoryDiscoveredPpi = {
32 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
33 &gEfiPeiMemoryDiscoveredPpiGuid,
34 NULL
35 };
36
37 //
38 // Pei Core Module Variables
39 //
40 //
41 static EFI_PEI_SERVICES mPS = {
42 {
43 PEI_SERVICES_SIGNATURE,
44 PEI_SERVICES_REVISION,
45 sizeof (EFI_PEI_SERVICES),
46 0,
47 0
48 },
49 PeiInstallPpi,
50 PeiReInstallPpi,
51 PeiLocatePpi,
52 PeiNotifyPpi,
53
54 PeiGetBootMode,
55 PeiSetBootMode,
56
57 PeiGetHobList,
58 PeiCreateHob,
59
60 PeiFvFindNextVolume,
61 PeiFfsFindNextFile,
62 PeiFfsFindSectionData,
63
64 PeiInstallPeiMemory,
65 PeiAllocatePages,
66 PeiAllocatePool,
67 (EFI_PEI_COPY_MEM)CopyMem,
68 (EFI_PEI_SET_MEM)SetMem,
69
70 PeiReportStatusCode,
71
72 PeiResetSystem,
73 NULL,
74 NULL,
75 NULL,
76 NULL,
77 NULL,
78 PeiRegisterForShadow
79 };
80
81 EFI_STATUS
82 EFIAPI
83 PeiCore (
84 IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData,
85 IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList,
86 IN VOID *Data
87 )
88 /*++
89
90 Routine Description:
91
92 The entry routine to Pei Core, invoked by PeiMain during transition
93 from SEC to PEI. After switching stack in the PEI core, it will restart
94 with the old core data.
95
96 Arguments:
97
98 SecCoreData - Points to a data structure containing information about the PEI core's operating
99 environment, such as the size and location of temporary RAM, the stack location and
100 the BFV location.
101 PpiList - Points to a list of one or more PPI descriptors to be installed initially by the PEI core.
102 An empty PPI list consists of a single descriptor with the end-tag
103 EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST. As part of its initialization
104 phase, the PEI Foundation will add these SEC-hosted PPIs to its PPI database such
105 that both the PEI Foundation and any modules can leverage the associated service
106 calls and/or code in these early PPIs
107 Data - Pointer to old core data that is used to initialize the
108 core's data areas.
109
110 Returns:
111
112 This function never returns
113 EFI_NOT_FOUND - Never reach
114
115 --*/
116 {
117 PEI_CORE_INSTANCE PrivateData;
118 EFI_STATUS Status;
119 PEI_CORE_TEMP_POINTERS TempPtr;
120 PEI_CORE_DISPATCH_DATA *DispatchData;
121 UINT64 mTick;
122 PEI_CORE_INSTANCE *OldCoreData;
123
124 mTick = 0;
125 OldCoreData = (PEI_CORE_INSTANCE *) Data;
126
127 if (PerformanceMeasurementEnabled()) {
128 if (OldCoreData == NULL) {
129 mTick = GetPerformanceCounter ();
130 }
131 }
132
133 //
134 // For IPF in CAR mode the real memory access is uncached,in InstallPeiMemory()
135 // the 63-bit of address is set to 1.
136 //
137 SWITCH_TO_CACHE_MODE (OldCoreData);
138
139 if (OldCoreData != NULL) {
140 CopyMem (&PrivateData, OldCoreData, sizeof (PEI_CORE_INSTANCE));
141 } else {
142 ZeroMem (&PrivateData, sizeof (PEI_CORE_INSTANCE));
143 }
144
145 PrivateData.Signature = PEI_CORE_HANDLE_SIGNATURE;
146 PrivateData.PS = &mPS;
147
148 //
149 // Initialize libraries that the PeiCore is linked against
150 // BUGBUG: The FfsHeader is passed in as NULL. Do we look it up or remove it from the lib init?
151 //
152 ProcessLibraryConstructorList (NULL, &PrivateData.PS);
153
154 InitializeMemoryServices (&PrivateData.PS, SecCoreData, OldCoreData);
155
156 InitializePpiServices (&PrivateData.PS, OldCoreData);
157
158 InitializeSecurityServices (&PrivateData.PS, OldCoreData);
159
160 InitializeDispatcherData (&PrivateData.PS, OldCoreData, SecCoreData);
161
162 if (OldCoreData != NULL) {
163
164 PERF_END (NULL,"PreMem", NULL, 0);
165 PERF_START (NULL,"PostMem", NULL, 0);
166
167 //
168 // The following code dumps out interesting cache as RAM usage information
169 // so we can keep tabs on how the cache as RAM is being utilized. The
170 // DEBUG_CODE_BEGIN macro is used to prevent this code from being compiled
171 // on a debug build.
172 //
173 DEBUG_CODE_BEGIN ();
174 UINTN *StackPointer;
175 UINTN StackValue;
176
177 StackValue = INIT_CAR_VALUE;
178 for (StackPointer = (UINTN *) OldCoreData->MaxTopOfCarHeap;
179 ((UINTN) StackPointer < ((UINTN) OldCoreData->BottomOfCarHeap + OldCoreData->SizeOfCacheAsRam))
180 && StackValue == INIT_CAR_VALUE;
181 StackPointer++) {
182 StackValue = *StackPointer;
183 }
184
185 DEBUG ((EFI_D_INFO, "Total Cache as RAM: %d bytes.\n", OldCoreData->SizeOfCacheAsRam));
186 DEBUG ((EFI_D_INFO, " CAR stack ever used: %d bytes.\n",
187 ((UINTN) OldCoreData->TopOfCarHeap - (UINTN) StackPointer)
188 ));
189 DEBUG ((EFI_D_INFO, " CAR heap used: %d bytes.\n",
190 ((UINTN) OldCoreData->HobList.HandoffInformationTable->EfiFreeMemoryBottom -
191 (UINTN) OldCoreData->HobList.Raw)
192 ));
193 DEBUG_CODE_END ();
194
195 //
196 // Alert any listeners that there is permanent memory available
197 //
198
199 PERF_START (NULL,"DisMem", NULL, 0);
200 Status = PeiServicesInstallPpi (&mMemoryDiscoveredPpi);
201 PERF_END (NULL,"DisMem", NULL, 0);
202
203 } else {
204
205 //
206 // Report Status Code EFI_SW_PC_INIT
207 //
208 REPORT_STATUS_CODE (
209 EFI_PROGRESS_CODE,
210 EFI_SOFTWARE_PEI_CORE | EFI_SW_PC_INIT
211 );
212
213 PERF_START (NULL,"PEI", NULL, mTick);
214 //
215 // If first pass, start performance measurement.
216 //
217 PERF_START (NULL,"PreMem", NULL, mTick);
218
219 //
220 // If SEC provided any PPI services to PEI, install them.
221 //
222 if (PpiList != NULL) {
223 Status = PeiServicesInstallPpi (PpiList);
224 ASSERT_EFI_ERROR (Status);
225 }
226 }
227
228 DispatchData = &PrivateData.DispatchData;
229
230 //
231 // Call PEIM dispatcher
232 //
233 PeiDispatcher (SecCoreData, &PrivateData, DispatchData);
234
235 //
236 // Check if InstallPeiMemory service was called.
237 //
238 ASSERT(PrivateData.PeiMemoryInstalled == TRUE);
239
240 PERF_END (NULL, "PostMem", NULL, 0);
241
242 Status = PeiServicesLocatePpi (
243 &gEfiDxeIplPpiGuid,
244 0,
245 NULL,
246 (VOID **)&TempPtr.DxeIpl
247 );
248 ASSERT_EFI_ERROR (Status);
249
250 DEBUG ((EFI_D_INFO, "DXE IPL Entry\n"));
251 Status = TempPtr.DxeIpl->Entry (
252 TempPtr.DxeIpl,
253 &PrivateData.PS,
254 PrivateData.HobList
255 );
256
257 ASSERT_EFI_ERROR (Status);
258
259 return EFI_NOT_FOUND;
260 }
261