]> git.proxmox.com Git - mirror_edk2.git/blob - EdkModulePkg/Core/Pei/PeiMain/PeiMain.c
Added comment about using -emacs to turn off adding [cc] characters in error messages
[mirror_edk2.git] / EdkModulePkg / 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 };
74
75 EFI_STATUS
76 EFIAPI
77 PeiCore (
78 IN EFI_PEI_STARTUP_DESCRIPTOR *PeiStartupDescriptor,
79 IN PEI_CORE_INSTANCE *OldCoreData
80 )
81 /*++
82
83 Routine Description:
84
85 The entry routine to Pei Core, invoked by PeiMain during transition
86 from SEC to PEI. After switching stack in the PEI core, it will restart
87 with the old core data.
88
89 Arguments:
90
91 PeiStartupDescriptor - Information and services provided by SEC phase.
92 OldCoreData - Pointer to old core data that is used to initialize the
93 core's data areas.
94
95 Returns:
96
97 This function never returns
98 EFI_NOT_FOUND - Never reach
99
100 --*/
101 {
102 PEI_CORE_INSTANCE PrivateData;
103 EFI_STATUS Status;
104 PEI_CORE_TEMP_POINTERS TempPtr;
105 PEI_CORE_DISPATCH_DATA *DispatchData;
106 UINT64 mTick;
107
108 mTick = 0;
109
110 if (PerformanceMeasurementEnabled()) {
111 if (OldCoreData == NULL) {
112 mTick = GetPerformanceCounter ();
113 }
114 }
115
116 //
117 // For IPF in CAR mode the real memory access is uncached,in InstallPeiMemory()
118 // the 63-bit of address is set to 1.
119 //
120 SWITCH_TO_CACHE_MODE (OldCoreData);
121
122 if (OldCoreData != NULL) {
123 CopyMem (&PrivateData, OldCoreData, sizeof (PEI_CORE_INSTANCE));
124 } else {
125 ZeroMem (&PrivateData, sizeof (PEI_CORE_INSTANCE));
126 }
127
128 PrivateData.Signature = PEI_CORE_HANDLE_SIGNATURE;
129 PrivateData.PS = &mPS;
130
131 //
132 // Initialize libraries that the PeiCore is linked against
133 // BUGBUG: The FfsHeader is passed in as NULL. Do we look it up or remove it from the lib init?
134 //
135 ProcessLibraryConstructorList (NULL, &PrivateData.PS);
136
137 InitializeMemoryServices (&PrivateData.PS, PeiStartupDescriptor, OldCoreData);
138
139 InitializePpiServices (&PrivateData.PS, OldCoreData);
140
141 InitializeSecurityServices (&PrivateData.PS, OldCoreData);
142
143 InitializeDispatcherData (&PrivateData.PS, OldCoreData, PeiStartupDescriptor);
144
145 if (OldCoreData != NULL) {
146
147 PERF_END (NULL,"PreMem", NULL, 0);
148 PERF_START (NULL,"PostMem", NULL, 0);
149
150 //
151 // The following code dumps out interesting cache as RAM usage information
152 // so we can keep tabs on how the cache as RAM is being utilized. The
153 // DEBUG_CODE_BEGIN macro is used to prevent this code from being compiled
154 // on a debug build.
155 //
156 DEBUG_CODE_BEGIN ();
157 UINTN *StackPointer;
158 UINTN StackValue;
159
160 StackValue = INIT_CAR_VALUE;
161 for (StackPointer = (UINTN *) OldCoreData->MaxTopOfCarHeap;
162 ((UINTN) StackPointer < ((UINTN) OldCoreData->BottomOfCarHeap + OldCoreData->SizeOfCacheAsRam))
163 && StackValue == INIT_CAR_VALUE;
164 StackPointer++) {
165 StackValue = *StackPointer;
166 }
167
168 DEBUG ((EFI_D_INFO, "Total Cache as RAM: %d bytes.\n", OldCoreData->SizeOfCacheAsRam));
169 DEBUG ((EFI_D_INFO, " CAR stack ever used: %d bytes.\n",
170 ((UINTN) OldCoreData->TopOfCarHeap - (UINTN) StackPointer)
171 ));
172 DEBUG ((EFI_D_INFO, " CAR heap used: %d bytes.\n",
173 ((UINTN) OldCoreData->HobList.HandoffInformationTable->EfiFreeMemoryBottom -
174 (UINTN) OldCoreData->HobList.Raw)
175 ));
176 DEBUG_CODE_END ();
177
178 //
179 // Alert any listeners that there is permanent memory available
180 //
181
182 PERF_START (NULL,"DisMem", NULL, 0);
183 Status = PeiServicesInstallPpi (&mMemoryDiscoveredPpi);
184 PERF_END (NULL,"DisMem", NULL, 0);
185
186 } else {
187
188 //
189 // Report Status Code EFI_SW_PC_INIT
190 //
191 REPORT_STATUS_CODE (
192 EFI_PROGRESS_CODE,
193 EFI_SOFTWARE_PEI_CORE | EFI_SW_PC_INIT
194 );
195
196 PERF_START (NULL,"PEI", NULL, mTick);
197 //
198 // If first pass, start performance measurement.
199 //
200 PERF_START (NULL,"PreMem", NULL, mTick);
201
202 //
203 // If SEC provided any PPI services to PEI, install them.
204 //
205 if (PeiStartupDescriptor->DispatchTable != NULL) {
206 Status = PeiServicesInstallPpi (PeiStartupDescriptor->DispatchTable);
207 ASSERT_EFI_ERROR (Status);
208 }
209 }
210
211 DispatchData = &PrivateData.DispatchData;
212
213 //
214 // Call PEIM dispatcher
215 //
216 PeiDispatcher (PeiStartupDescriptor, &PrivateData, DispatchData);
217
218 //
219 // Check if InstallPeiMemory service was called.
220 //
221 ASSERT(PrivateData.PeiMemoryInstalled == TRUE);
222
223 PERF_END (NULL, "PostMem", NULL, 0);
224
225 Status = PeiServicesLocatePpi (
226 &gEfiDxeIplPpiGuid,
227 0,
228 NULL,
229 (VOID **)&TempPtr.DxeIpl
230 );
231 ASSERT_EFI_ERROR (Status);
232
233 DEBUG ((EFI_D_INFO, "DXE IPL Entry\n"));
234 Status = TempPtr.DxeIpl->Entry (
235 TempPtr.DxeIpl,
236 &PrivateData.PS,
237 PrivateData.HobList
238 );
239
240 ASSERT_EFI_ERROR (Status);
241
242 return EFI_NOT_FOUND;
243 }
244