]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - EdkModulePkg/Core/Pei/PeiMain/PeiMain.c
Remove private data structure in PEI core entry point.
[mirror_edk2.git] / EdkModulePkg / Core / Pei / PeiMain / PeiMain.c
... / ...
CommitLineData
1/*++\r
2\r
3Copyright (c) 2006, Intel Corporation\r
4All rights reserved. This program and the accompanying materials\r
5are licensed and made available under the terms and conditions of the BSD License\r
6which accompanies this distribution. The full text of the license may be found at\r
7http://opensource.org/licenses/bsd-license.php\r
8\r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11\r
12Module Name:\r
13\r
14 PeiMain.c\r
15\r
16Abstract:\r
17\r
18 Pei Core Main Entry Point\r
19\r
20Revision History\r
21\r
22--*/\r
23\r
24#include <PeiMain.h>\r
25\r
26//\r
27//CAR is filled with this initial value during SEC phase\r
28//\r
29#define INIT_CAR_VALUE 0x5AA55AA5\r
30\r
31static EFI_PEI_PPI_DESCRIPTOR mMemoryDiscoveredPpi = {\r
32 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
33 &gEfiPeiMemoryDiscoveredPpiGuid,\r
34 NULL\r
35};\r
36\r
37//\r
38// Pei Core Module Variables\r
39//\r
40//\r
41static EFI_PEI_SERVICES mPS = {\r
42 {\r
43 PEI_SERVICES_SIGNATURE,\r
44 PEI_SERVICES_REVISION,\r
45 sizeof (EFI_PEI_SERVICES),\r
46 0,\r
47 0\r
48 },\r
49 PeiInstallPpi,\r
50 PeiReInstallPpi,\r
51 PeiLocatePpi,\r
52 PeiNotifyPpi,\r
53\r
54 PeiGetBootMode,\r
55 PeiSetBootMode,\r
56\r
57 PeiGetHobList,\r
58 PeiCreateHob,\r
59\r
60 PeiFvFindNextVolume,\r
61 PeiFfsFindNextFile,\r
62 PeiFfsFindSectionData,\r
63\r
64 PeiInstallPeiMemory,\r
65 PeiAllocatePages,\r
66 PeiAllocatePool,\r
67 (EFI_PEI_COPY_MEM)CopyMem,\r
68 (EFI_PEI_SET_MEM)SetMem,\r
69\r
70 PeiReportStatusCode,\r
71\r
72 PeiResetSystem\r
73};\r
74\r
75EFI_STATUS\r
76EFIAPI\r
77PeiCore (\r
78 IN EFI_PEI_STARTUP_DESCRIPTOR *PeiStartupDescriptor,\r
79 IN VOID *Data\r
80 )\r
81/*++\r
82\r
83Routine Description:\r
84\r
85 The entry routine to Pei Core, invoked by PeiMain during transition\r
86 from SEC to PEI. After switching stack in the PEI core, it will restart\r
87 with the old core data.\r
88\r
89Arguments:\r
90\r
91 PeiStartupDescriptor - Information and services provided by SEC phase.\r
92 OldCoreData - Pointer to old core data that is used to initialize the\r
93 core's data areas.\r
94\r
95Returns:\r
96\r
97 This function never returns\r
98 EFI_NOT_FOUND - Never reach\r
99\r
100--*/\r
101{\r
102 PEI_CORE_INSTANCE PrivateData;\r
103 EFI_STATUS Status;\r
104 PEI_CORE_TEMP_POINTERS TempPtr;\r
105 PEI_CORE_DISPATCH_DATA *DispatchData;\r
106 UINT64 mTick;\r
107 PEI_CORE_INSTANCE *OldCoreData;\r
108\r
109 mTick = 0;\r
110 OldCoreData = (PEI_CORE_INSTANCE *) Data;\r
111\r
112 if (PerformanceMeasurementEnabled()) {\r
113 if (OldCoreData == NULL) {\r
114 mTick = GetPerformanceCounter ();\r
115 }\r
116 }\r
117\r
118 //\r
119 // For IPF in CAR mode the real memory access is uncached,in InstallPeiMemory()\r
120 // the 63-bit of address is set to 1.\r
121 //\r
122 SWITCH_TO_CACHE_MODE (OldCoreData);\r
123\r
124 if (OldCoreData != NULL) {\r
125 CopyMem (&PrivateData, OldCoreData, sizeof (PEI_CORE_INSTANCE));\r
126 } else {\r
127 ZeroMem (&PrivateData, sizeof (PEI_CORE_INSTANCE));\r
128 }\r
129\r
130 PrivateData.Signature = PEI_CORE_HANDLE_SIGNATURE;\r
131 PrivateData.PS = &mPS;\r
132\r
133 //\r
134 // Initialize libraries that the PeiCore is linked against\r
135 // BUGBUG: The FfsHeader is passed in as NULL. Do we look it up or remove it from the lib init?\r
136 //\r
137 ProcessLibraryConstructorList (NULL, &PrivateData.PS);\r
138\r
139 InitializeMemoryServices (&PrivateData.PS, PeiStartupDescriptor, OldCoreData);\r
140\r
141 InitializePpiServices (&PrivateData.PS, OldCoreData);\r
142\r
143 InitializeSecurityServices (&PrivateData.PS, OldCoreData);\r
144\r
145 InitializeDispatcherData (&PrivateData.PS, OldCoreData, PeiStartupDescriptor);\r
146\r
147 if (OldCoreData != NULL) {\r
148\r
149 PERF_END (NULL,"PreMem", NULL, 0);\r
150 PERF_START (NULL,"PostMem", NULL, 0);\r
151\r
152 //\r
153 // The following code dumps out interesting cache as RAM usage information\r
154 // so we can keep tabs on how the cache as RAM is being utilized. The\r
155 // DEBUG_CODE_BEGIN macro is used to prevent this code from being compiled\r
156 // on a debug build.\r
157 //\r
158 DEBUG_CODE_BEGIN ();\r
159 UINTN *StackPointer;\r
160 UINTN StackValue;\r
161\r
162 StackValue = INIT_CAR_VALUE;\r
163 for (StackPointer = (UINTN *) OldCoreData->MaxTopOfCarHeap;\r
164 ((UINTN) StackPointer < ((UINTN) OldCoreData->BottomOfCarHeap + OldCoreData->SizeOfCacheAsRam))\r
165 && StackValue == INIT_CAR_VALUE;\r
166 StackPointer++) {\r
167 StackValue = *StackPointer;\r
168 }\r
169\r
170 DEBUG ((EFI_D_INFO, "Total Cache as RAM: %d bytes.\n", OldCoreData->SizeOfCacheAsRam));\r
171 DEBUG ((EFI_D_INFO, " CAR stack ever used: %d bytes.\n",\r
172 ((UINTN) OldCoreData->TopOfCarHeap - (UINTN) StackPointer)\r
173 ));\r
174 DEBUG ((EFI_D_INFO, " CAR heap used: %d bytes.\n",\r
175 ((UINTN) OldCoreData->HobList.HandoffInformationTable->EfiFreeMemoryBottom -\r
176 (UINTN) OldCoreData->HobList.Raw)\r
177 ));\r
178 DEBUG_CODE_END ();\r
179\r
180 //\r
181 // Alert any listeners that there is permanent memory available\r
182 //\r
183 \r
184 PERF_START (NULL,"DisMem", NULL, 0);\r
185 Status = PeiServicesInstallPpi (&mMemoryDiscoveredPpi);\r
186 PERF_END (NULL,"DisMem", NULL, 0);\r
187\r
188 } else {\r
189\r
190 //\r
191 // Report Status Code EFI_SW_PC_INIT\r
192 //\r
193 REPORT_STATUS_CODE (\r
194 EFI_PROGRESS_CODE,\r
195 EFI_SOFTWARE_PEI_CORE | EFI_SW_PC_INIT\r
196 );\r
197\r
198 PERF_START (NULL,"PEI", NULL, mTick);\r
199 //\r
200 // If first pass, start performance measurement.\r
201 //\r
202 PERF_START (NULL,"PreMem", NULL, mTick);\r
203\r
204 //\r
205 // If SEC provided any PPI services to PEI, install them.\r
206 //\r
207 if (PeiStartupDescriptor->DispatchTable != NULL) {\r
208 Status = PeiServicesInstallPpi (PeiStartupDescriptor->DispatchTable);\r
209 ASSERT_EFI_ERROR (Status);\r
210 }\r
211 }\r
212\r
213 DispatchData = &PrivateData.DispatchData;\r
214\r
215 //\r
216 // Call PEIM dispatcher\r
217 //\r
218 PeiDispatcher (PeiStartupDescriptor, &PrivateData, DispatchData);\r
219\r
220 //\r
221 // Check if InstallPeiMemory service was called.\r
222 //\r
223 ASSERT(PrivateData.PeiMemoryInstalled == TRUE);\r
224\r
225 PERF_END (NULL, "PostMem", NULL, 0);\r
226\r
227 Status = PeiServicesLocatePpi (\r
228 &gEfiDxeIplPpiGuid,\r
229 0,\r
230 NULL,\r
231 (VOID **)&TempPtr.DxeIpl\r
232 );\r
233 ASSERT_EFI_ERROR (Status);\r
234\r
235 DEBUG ((EFI_D_INFO, "DXE IPL Entry\n"));\r
236 Status = TempPtr.DxeIpl->Entry (\r
237 TempPtr.DxeIpl,\r
238 &PrivateData.PS,\r
239 PrivateData.HobList\r
240 );\r
241\r
242 ASSERT_EFI_ERROR (Status);\r
243\r
244 return EFI_NOT_FOUND;\r
245}\r
246\r