]> git.proxmox.com Git - mirror_edk2.git/blame - EdkModulePkg/Core/Pei/PeiMain/PeiMain.c
Initial import.
[mirror_edk2.git] / EdkModulePkg / Core / Pei / PeiMain / PeiMain.c
CommitLineData
878ddf1f 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 PEI_CORE_INSTANCE *OldCoreData\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\r
108 mTick = 0;\r
109\r
110#ifdef EFI_PEI_PERFORMANCE\r
111 if (OldCoreData == NULL) {\r
112 mTick = GetPerformanceCounter ();\r
113 }\r
114#endif\r
115\r
116\r
117 //\r
118 // For IPF in CAR mode the real memory access is uncached,in InstallPeiMemory()\r
119 // the 63-bit of address is set to 1.\r
120 //\r
121 SWITCH_TO_CACHE_MODE (OldCoreData);\r
122\r
123 if (OldCoreData != NULL) {\r
124 CopyMem (&PrivateData, OldCoreData, sizeof (PEI_CORE_INSTANCE));\r
125 } else {\r
126 ZeroMem (&PrivateData, sizeof (PEI_CORE_INSTANCE));\r
127 }\r
128\r
129 PrivateData.Signature = PEI_CORE_HANDLE_SIGNATURE;\r
130 PrivateData.PS = &mPS;\r
131\r
132 //\r
133 // Initialize libraries that the PeiCore is linked against\r
134 // BUGBUG: The FfsHeader is passed in as NULL. Do we look it up or remove it from the lib init?\r
135 //\r
136 ProcessLibraryConstructorList (NULL, &PrivateData.PS);\r
137\r
138 InitializeMemoryServices (&PrivateData.PS, PeiStartupDescriptor, OldCoreData);\r
139\r
140 InitializePpiServices (&PrivateData.PS, OldCoreData);\r
141\r
142 InitializeSecurityServices (&PrivateData.PS, OldCoreData);\r
143\r
144 InitializeDispatcherData (&PrivateData.PS, OldCoreData, PeiStartupDescriptor);\r
145\r
146 if (OldCoreData != NULL) {\r
147\r
148 PERF_END (NULL,"PreMem", NULL, 0);\r
149 PERF_START (NULL,"PostMem", NULL, 0);\r
150\r
151 //\r
152 // The following code dumps out interesting cache as RAM usage information\r
153 // so we can keep tabs on how the cache as RAM is being utilized. The\r
154 // DEBUG_CODE macro is used to prevent this code from being compiled\r
155 // on a debug build.\r
156 //\r
157 DEBUG_CODE (\r
158 UINTN *StackPointer;\r
159 UINTN StackValue;\r
160\r
161 StackValue = INIT_CAR_VALUE;\r
162 for (StackPointer = (UINTN *) OldCoreData->MaxTopOfCarHeap;\r
163 ((UINTN) StackPointer < ((UINTN) OldCoreData->BottomOfCarHeap + OldCoreData->SizeOfCacheAsRam))\r
164 && StackValue == INIT_CAR_VALUE;\r
165 StackPointer++) {\r
166 StackValue = *StackPointer;\r
167 }\r
168\r
169 DEBUG ((EFI_D_INFO, "Total Cache as RAM: %d bytes.\n", OldCoreData->SizeOfCacheAsRam));\r
170 DEBUG ((EFI_D_INFO, " CAR stack ever used: %d bytes.\n",\r
171 ((UINTN) OldCoreData->TopOfCarHeap - (UINTN) StackPointer)\r
172 ));\r
173 DEBUG ((EFI_D_INFO, " CAR heap used: %d bytes.\n",\r
174 ((UINTN) OldCoreData->HobList.HandoffInformationTable->EfiFreeMemoryBottom -\r
175 (UINTN) OldCoreData->HobList.Raw)\r
176 ));\r
177 );\r
178\r
179 //\r
180 // Alert any listeners that there is permanent memory available\r
181 //\r
182 PERF_START (NULL,"DisMem", NULL, 0);\r
183 Status = PeiCoreInstallPpi (&mMemoryDiscoveredPpi);\r
184 PERF_END (NULL,"DisMem", NULL, 0);\r
185\r
186 } else {\r
187\r
188 //\r
189 // Report Status Code EFI_SW_PC_INIT\r
190 //\r
191 REPORT_STATUS_CODE (\r
192 EFI_PROGRESS_CODE,\r
193 EFI_SOFTWARE_PEI_CORE | EFI_SW_PC_INIT\r
194 );\r
195\r
196 //\r
197 // If first pass, start performance measurement.\r
198 //\r
199 PERF_START (NULL,"PreMem", NULL, mTick);\r
200\r
201 //\r
202 // If SEC provided any PPI services to PEI, install them.\r
203 //\r
204 if (PeiStartupDescriptor->DispatchTable != NULL) {\r
205 Status = PeiCoreInstallPpi (PeiStartupDescriptor->DispatchTable);\r
206 ASSERT_EFI_ERROR (Status);\r
207 }\r
208 }\r
209\r
210 DispatchData = &PrivateData.DispatchData;\r
211\r
212 //\r
213 // Call PEIM dispatcher\r
214 //\r
215 PeiDispatcher (PeiStartupDescriptor, &PrivateData, DispatchData);\r
216\r
217 //\r
218 // Check if InstallPeiMemory service was called.\r
219 //\r
220 ASSERT(PrivateData.PeiMemoryInstalled == TRUE);\r
221\r
222 PERF_END (NULL, "PostMem", NULL, 0);\r
223\r
224 Status = PeiCoreLocatePpi (\r
225 &gEfiDxeIplPpiGuid,\r
226 0,\r
227 NULL,\r
228 (VOID **)&TempPtr.DxeIpl\r
229 );\r
230 ASSERT_EFI_ERROR (Status);\r
231\r
232 DEBUG ((EFI_D_INFO, "DXE IPL Entry\n"));\r
233 Status = TempPtr.DxeIpl->Entry (\r
234 TempPtr.DxeIpl,\r
235 &PrivateData.PS,\r
236 PrivateData.HobList\r
237 );\r
238\r
239 ASSERT_EFI_ERROR (Status);\r
240\r
241 return EFI_NOT_FOUND;\r
242}\r
243\r