]>
Commit | Line | Data |
---|---|---|
192f6d4c | 1 | /*++\r |
2 | \r | |
3 | Copyright (c) 2006, Intel Corporation\r | |
4 | All rights reserved. This program and the accompanying materials\r | |
5 | are licensed and made available under the terms and conditions of the BSD License\r | |
6 | which accompanies this distribution. The full text of the license may be found at\r | |
7 | http://opensource.org/licenses/bsd-license.php\r | |
8 | \r | |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
11 | \r | |
12 | Module Name:\r | |
13 | \r | |
14 | Dispatcher.c\r | |
15 | \r | |
16 | Abstract:\r | |
17 | \r | |
18 | EFI PEI Core dispatch services\r | |
19 | \r | |
20 | Revision History\r | |
21 | \r | |
22 | --*/\r | |
23 | \r | |
192f6d4c | 24 | #include <PeiMain.h>\r |
25 | \r | |
b98c2ab7 | 26 | STATIC\r |
27 | VOID\r | |
28 | InvokePeiCore (\r | |
29 | VOID *Context1,\r | |
30 | VOID *Context2\r | |
31 | );\r | |
32 | \r | |
b0d803fe | 33 | VOID\r |
34 | DiscoverPeimsAndOrderWithApriori (\r | |
35 | IN PEI_CORE_INSTANCE *Private,\r | |
36 | IN EFI_PEI_FV_HANDLE VolumeHandle\r | |
37 | )\r | |
38 | /*++\r | |
39 | \r | |
40 | Routine Description:\r | |
41 | \r | |
42 | Discover all Peims and optional Apriori file in one FV. There is at most one\r | |
43 | Apriori file in one FV.\r | |
44 | \r | |
45 | Arguments:\r | |
46 | \r | |
47 | Private - Pointer to the private data passed in from caller\r | |
48 | VolumeHandle - Fv handle.\r | |
49 | Returns:\r | |
50 | \r | |
51 | NONE\r | |
52 | \r | |
53 | --*/ \r | |
54 | {\r | |
55 | EFI_STATUS Status;\r | |
56 | EFI_PEI_FV_HANDLE FileHandle;\r | |
177aabe6 | 57 | EFI_PEI_FILE_HANDLE AprioriFileHandle;\r |
b0d803fe | 58 | EFI_GUID *Apriori;\r |
59 | UINTN Index;\r | |
60 | UINTN Index2;\r | |
61 | UINTN PeimIndex;\r | |
62 | UINTN PeimCount;\r | |
63 | EFI_GUID *Guid;\r | |
177aabe6 | 64 | EFI_PEI_FV_HANDLE TempFileHandles[FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv)];\r |
65 | EFI_GUID FileGuid[FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv)];\r | |
b0d803fe | 66 | \r |
67 | //\r | |
68 | // Walk the FV and find all the PEIMs and the Apriori file.\r | |
69 | //\r | |
70 | AprioriFileHandle = NULL;\r | |
71 | Private->CurrentFvFileHandles[0] = NULL;\r | |
72 | Guid = NULL;\r | |
73 | FileHandle = NULL;\r | |
74 | \r | |
75 | //\r | |
76 | // If the current Fv has been scanned, directly get its cachable record.\r | |
77 | //\r | |
78 | if (Private->Fv[Private->CurrentPeimFvCount].ScanFv) {\r | |
79 | CopyMem (Private->CurrentFvFileHandles, Private->Fv[Private->CurrentPeimFvCount].FvFileHandles, sizeof (Private->CurrentFvFileHandles));\r | |
80 | return;\r | |
81 | }\r | |
82 | \r | |
83 | //\r | |
84 | // Go ahead to scan this Fv, and cache FileHandles within it.\r | |
85 | //\r | |
177aabe6 | 86 | for (PeimCount = 0; PeimCount < FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv); PeimCount++) {\r |
b0d803fe | 87 | Status = PeiFindFileEx (\r |
88 | VolumeHandle, \r | |
89 | NULL, \r | |
90 | PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE, \r | |
91 | &FileHandle,\r | |
92 | &AprioriFileHandle\r | |
93 | );\r | |
94 | if (Status != EFI_SUCCESS) {\r | |
95 | break;\r | |
96 | }\r | |
97 | \r | |
98 | Private->CurrentFvFileHandles[PeimCount] = FileHandle;\r | |
99 | }\r | |
100 | \r | |
101 | Private->AprioriCount = 0; \r | |
102 | if (AprioriFileHandle != NULL) {\r | |
103 | //\r | |
104 | // Read the Apriori file\r | |
105 | //\r | |
177aabe6 | 106 | Status = PeiServicesFfsFindSectionData (EFI_SECTION_RAW, AprioriFileHandle, (VOID **) &Apriori);\r |
b0d803fe | 107 | if (!EFI_ERROR (Status)) {\r |
108 | //\r | |
109 | // Calculate the number of PEIMs in the A Priori list\r | |
110 | //\r | |
111 | Private->AprioriCount = *(UINT32 *)(((EFI_FFS_FILE_HEADER *)AprioriFileHandle)->Size) & 0x00FFFFFF;\r | |
112 | Private->AprioriCount -= sizeof (EFI_FFS_FILE_HEADER) - sizeof (EFI_COMMON_SECTION_HEADER); \r | |
113 | Private->AprioriCount /= sizeof (EFI_GUID);\r | |
114 | \r | |
115 | SetMem (FileGuid, sizeof (FileGuid), 0);\r | |
116 | for (Index = 0; Index < PeimCount; Index++) {\r | |
117 | //\r | |
118 | // Make an array of file name guids that matches the FileHandle array so we can convert\r | |
119 | // quickly from file name to file handle\r | |
120 | //\r | |
121 | CopyMem (&FileGuid[Index], &((EFI_FFS_FILE_HEADER *)Private->CurrentFvFileHandles[Index])->Name,sizeof(EFI_GUID)); \r | |
122 | }\r | |
123 | \r | |
124 | //\r | |
125 | // Walk through FileGuid array to find out who is invalid PEIM guid in Apriori file.\r | |
126 | // Add avalible PEIMs in Apriori file into TempFileHandles array at first. \r | |
127 | //\r | |
128 | Index2 = 0;\r | |
129 | for (Index = 0; Index2 < Private->AprioriCount; Index++) {\r | |
130 | while (Index2 < Private->AprioriCount) {\r | |
131 | Guid = ScanGuid (FileGuid, PeimCount * sizeof (EFI_GUID), &Apriori[Index2++]);\r | |
132 | if (Guid != NULL) {\r | |
133 | break;\r | |
134 | }\r | |
135 | }\r | |
136 | if (Guid == NULL) {\r | |
137 | break; \r | |
138 | }\r | |
139 | PeimIndex = ((UINTN)Guid - (UINTN)&FileGuid[0])/sizeof (EFI_GUID);\r | |
140 | TempFileHandles[Index] = Private->CurrentFvFileHandles[PeimIndex];\r | |
141 | \r | |
142 | //\r | |
143 | // Since we have copied the file handle we can remove it from this list.\r | |
144 | //\r | |
145 | Private->CurrentFvFileHandles[PeimIndex] = NULL;\r | |
146 | }\r | |
147 | \r | |
148 | //\r | |
149 | // Update valid Aprioricount\r | |
150 | //\r | |
151 | Private->AprioriCount = Index;\r | |
152 | \r | |
153 | //\r | |
154 | // Add in any PEIMs not in the Apriori file\r | |
155 | //\r | |
156 | for (;Index < PeimCount; Index++) {\r | |
157 | for (Index2 = 0; Index2 < PeimCount; Index2++) {\r | |
158 | if (Private->CurrentFvFileHandles[Index2] != NULL) {\r | |
159 | TempFileHandles[Index] = Private->CurrentFvFileHandles[Index2];\r | |
160 | Private->CurrentFvFileHandles[Index2] = NULL;\r | |
161 | break;\r | |
162 | }\r | |
163 | }\r | |
164 | }\r | |
165 | //\r | |
166 | //Index the end of array contains re-range Pei moudle.\r | |
167 | //\r | |
168 | TempFileHandles[Index] = NULL;\r | |
169 | \r | |
170 | //\r | |
171 | // Private->CurrentFvFileHandles is currently in PEIM in the FV order.\r | |
172 | // We need to update it to start with files in the A Priori list and \r | |
173 | // then the remaining files in PEIM order. \r | |
174 | //\r | |
175 | CopyMem (Private->CurrentFvFileHandles, TempFileHandles, sizeof (Private->CurrentFvFileHandles));\r | |
176 | }\r | |
177 | }\r | |
178 | //\r | |
179 | // Cache the current Fv File Handle. So that we don't have to scan the Fv again.\r | |
180 | // Instead, we can retrieve the file handles within this Fv from cachable data.\r | |
181 | //\r | |
182 | Private->Fv[Private->CurrentPeimFvCount].ScanFv = TRUE;\r | |
183 | CopyMem (Private->Fv[Private->CurrentPeimFvCount].FvFileHandles, Private->CurrentFvFileHandles, sizeof (Private->CurrentFvFileHandles));\r | |
184 | \r | |
185 | }\r | |
186 | \r | |
187 | VOID\r | |
192f6d4c | 188 | PeiDispatcher (\r |
5aae0aa7 | 189 | IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData,\r |
b0d803fe | 190 | IN PEI_CORE_INSTANCE *Private\r |
192f6d4c | 191 | )\r |
192 | \r | |
193 | /*++\r | |
194 | \r | |
195 | Routine Description:\r | |
196 | \r | |
197 | Conduct PEIM dispatch.\r | |
198 | \r | |
199 | Arguments:\r | |
200 | \r | |
5aae0aa7 | 201 | SecCoreData - Points to a data structure containing information about the PEI core's operating\r |
202 | environment, such as the size and location of temporary RAM, the stack location and\r | |
203 | the BFV location.\r | |
192f6d4c | 204 | PrivateData - Pointer to the private data passed in from caller\r |
205 | DispatchData - Pointer to PEI_CORE_DISPATCH_DATA data.\r | |
206 | \r | |
207 | Returns:\r | |
208 | \r | |
209 | EFI_SUCCESS - Successfully dispatched PEIM.\r | |
210 | EFI_NOT_FOUND - The dispatch failed.\r | |
211 | \r | |
212 | --*/\r | |
213 | {\r | |
b0d803fe | 214 | EFI_STATUS Status;\r |
215 | UINT32 Index1;\r | |
216 | UINT32 Index2;\r | |
217 | EFI_PEI_SERVICES **PeiServices;\r | |
218 | VOID *PrivateInMem;\r | |
219 | EFI_PEI_FV_HANDLE VolumeHandle; \r | |
220 | EFI_PEI_FILE_HANDLE PeiCoreFileHandle;\r | |
221 | EFI_PEI_FILE_HANDLE PeimFileHandle;\r | |
222 | UINTN FvCount;\r | |
223 | UINTN PeimCount;\r | |
224 | UINT32 AuthenticationState;\r | |
225 | EFI_PHYSICAL_ADDRESS EntryPoint;\r | |
226 | EFI_PEIM_ENTRY_POINT PeimEntryPoint;\r | |
227 | BOOLEAN PeimNeedingDispatch;\r | |
228 | BOOLEAN PeimDispatchOnThisPass;\r | |
229 | UINTN SaveCurrentPeimCount;\r | |
1053e0c5 | 230 | UINTN SaveCurrentFvCount;\r |
b0d803fe | 231 | EFI_PEI_FILE_HANDLE SaveCurrentFileHandle;\r |
232 | VOID *TopOfStack;\r | |
233 | PEI_CORE_PARAMETERS PeiCoreParameters;\r | |
234 | EFI_DEVICE_HANDLE_EXTENDED_DATA ExtendedData;\r | |
288f9b38 | 235 | EFI_FV_FILE_INFO FvFileInfo;\r |
b0d803fe | 236 | \r |
237 | \r | |
238 | PeiServices = &Private->PS;\r | |
239 | PeimEntryPoint = NULL;\r | |
240 | PeimFileHandle = NULL;\r | |
288f9b38 | 241 | EntryPoint = 0;\r |
b0d803fe | 242 | \r |
243 | if ((Private->PeiMemoryInstalled) && (Private->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME)) {\r | |
244 | //\r | |
245 | // Once real memory is available, shadow the RegisterForShadow modules. And meanwhile\r | |
246 | // update the modules' status from PEIM_STATE_REGISITER_FOR_SHADOW to PEIM_STATE_DONE.\r | |
247 | //\r | |
248 | SaveCurrentPeimCount = Private->CurrentPeimCount;\r | |
1053e0c5 | 249 | SaveCurrentFvCount = Private->CurrentPeimFvCount;\r |
b0d803fe | 250 | SaveCurrentFileHandle = Private->CurrentFileHandle;\r |
251 | \r | |
1053e0c5 | 252 | for (Index1 = 0; Index1 <= SaveCurrentFvCount; Index1++) {\r |
177aabe6 | 253 | for (Index2 = 0; (Index2 < FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv)) && (Private->Fv[Index1].FvFileHandles[Index2] != NULL); Index2++) {\r |
b0d803fe | 254 | if (Private->Fv[Index1].PeimState[Index2] == PEIM_STATE_REGISITER_FOR_SHADOW) {\r |
255 | PeimFileHandle = Private->Fv[Index1].FvFileHandles[Index2]; \r | |
256 | Status = PeiLoadImage (\r | |
257 | &Private->PS, \r | |
258 | PeimFileHandle, \r | |
259 | &EntryPoint, \r | |
260 | &AuthenticationState\r | |
261 | );\r | |
262 | if (Status == EFI_SUCCESS) {\r | |
263 | //\r | |
264 | // PEIM_STATE_REGISITER_FOR_SHADOW move to PEIM_STATE_DONE\r | |
265 | //\r | |
266 | Private->Fv[Index1].PeimState[Index2]++;\r | |
1053e0c5 | 267 | Private->CurrentFileHandle = PeimFileHandle;\r |
268 | Private->CurrentPeimFvCount = Index1; \r | |
269 | Private->CurrentPeimCount = Index2; \r | |
b0d803fe | 270 | //\r |
271 | // Call the PEIM entry point\r | |
272 | //\r | |
273 | PeimEntryPoint = (EFI_PEIM_ENTRY_POINT)(UINTN)EntryPoint;\r | |
274 | \r | |
275 | PERF_START (0, "PEIM", NULL, 0);\r | |
276 | PeimEntryPoint(PeimFileHandle, &Private->PS);\r | |
277 | PERF_END (0, "PEIM", NULL, 0);\r | |
278 | } \r | |
279 | \r | |
280 | //\r | |
281 | // Process the Notify list and dispatch any notifies for\r | |
282 | // newly installed PPIs.\r | |
283 | //\r | |
284 | ProcessNotifyList (Private);\r | |
285 | }\r | |
286 | }\r | |
287 | }\r | |
1053e0c5 | 288 | Private->CurrentFileHandle = SaveCurrentFileHandle; \r |
289 | Private->CurrentPeimFvCount = SaveCurrentFvCount; \r | |
290 | Private->CurrentPeimCount = SaveCurrentPeimCount; \r | |
b0d803fe | 291 | }\r |
192f6d4c | 292 | \r |
293 | //\r | |
294 | // This is the main dispatch loop. It will search known FVs for PEIMs and\r | |
295 | // attempt to dispatch them. If any PEIM gets dispatched through a single\r | |
296 | // pass of the dispatcher, it will start over from the Bfv again to see\r | |
297 | // if any new PEIMs dependencies got satisfied. With a well ordered\r | |
298 | // FV where PEIMs are found in the order their dependencies are also\r | |
299 | // satisfied, this dipatcher should run only once.\r | |
300 | //\r | |
b0d803fe | 301 | do {\r |
302 | PeimNeedingDispatch = FALSE;\r | |
303 | PeimDispatchOnThisPass = FALSE;\r | |
304 | \r | |
305 | for (FvCount = Private->CurrentPeimFvCount; FvCount < Private->FvCount; FvCount++) {\r | |
306 | Private->CurrentPeimFvCount = FvCount;\r | |
307 | VolumeHandle = Private->Fv[FvCount].FvHeader;\r | |
192f6d4c | 308 | \r |
b0d803fe | 309 | if (Private->CurrentPeimCount == 0) {\r |
310 | //\r | |
311 | // When going through each FV, at first, search Apriori file to\r | |
312 | // reorder all PEIMs to ensure the PEIMs in Apriori file to get \r | |
313 | // dispatch at first.\r | |
314 | //\r | |
315 | DiscoverPeimsAndOrderWithApriori (Private, VolumeHandle);\r | |
316 | }\r | |
192f6d4c | 317 | \r |
318 | //\r | |
b0d803fe | 319 | // Start to dispatch all modules within the current Fv.\r |
192f6d4c | 320 | //\r |
b0d803fe | 321 | for (PeimCount = Private->CurrentPeimCount; \r |
177aabe6 | 322 | (PeimCount < FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv)) && (Private->CurrentFvFileHandles[PeimCount] != NULL); \r |
b0d803fe | 323 | PeimCount++) {\r |
324 | Private->CurrentPeimCount = PeimCount;\r | |
325 | PeimFileHandle = Private->CurrentFileHandle = Private->CurrentFvFileHandles[PeimCount];\r | |
326 | \r | |
327 | if (Private->Fv[FvCount].PeimState[PeimCount] == PEIM_STATE_NOT_DISPATCHED) {\r | |
328 | if (!DepexSatisfied (Private, PeimFileHandle, PeimCount)) {\r | |
329 | PeimNeedingDispatch = TRUE;\r | |
330 | } else {\r | |
288f9b38 LG |
331 | Status = PeiFfsGetFileInfo (PeimFileHandle, &FvFileInfo);\r |
332 | ASSERT_EFI_ERROR (Status);\r | |
333 | if (FvFileInfo.FileType == EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE) {\r | |
334 | //\r | |
335 | // For Fv type file, Produce new FV PPI and FV hob\r | |
336 | //\r | |
337 | Status = ProcessFvFile (PeiServices, PeimFileHandle, &AuthenticationState);\r | |
338 | } else {\r | |
339 | //\r | |
340 | // For PEIM driver, Load its entry point\r | |
341 | //\r | |
342 | Status = PeiLoadImage (\r | |
343 | PeiServices, \r | |
344 | PeimFileHandle, \r | |
345 | &EntryPoint, \r | |
346 | &AuthenticationState\r | |
347 | );\r | |
348 | }\r | |
349 | \r | |
b0d803fe | 350 | if ((Status == EFI_SUCCESS)) {\r |
192f6d4c | 351 | //\r |
288f9b38 | 352 | // The PEIM has its dependencies satisfied, and is processed.\r |
192f6d4c | 353 | //\r |
b0d803fe | 354 | PERF_START (0, "PEIM", NULL, 0);\r |
192f6d4c | 355 | \r |
b0d803fe | 356 | ExtendedData.Handle = (EFI_HANDLE)PeimFileHandle;\r |
192f6d4c | 357 | \r |
358 | REPORT_STATUS_CODE_WITH_EXTENDED_DATA (\r | |
359 | EFI_PROGRESS_CODE,\r | |
360 | EFI_SOFTWARE_PEI_CORE | EFI_SW_PC_INIT_BEGIN,\r | |
361 | (VOID *)(&ExtendedData),\r | |
362 | sizeof (ExtendedData)\r | |
363 | );\r | |
364 | \r | |
b0d803fe | 365 | Status = VerifyPeim (Private, VolumeHandle, PeimFileHandle);\r |
366 | if (Status != EFI_SECURITY_VIOLATION && (AuthenticationState == 0)) {\r | |
367 | //\r | |
368 | // PEIM_STATE_NOT_DISPATCHED move to PEIM_STATE_DISPATCHED\r | |
369 | //\r | |
370 | Private->Fv[FvCount].PeimState[PeimCount]++;\r | |
288f9b38 LG |
371 | \r |
372 | if (FvFileInfo.FileType != EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE) {\r | |
373 | //\r | |
374 | // Call the PEIM entry point for PEIM driver\r | |
375 | //\r | |
376 | PeimEntryPoint = (EFI_PEIM_ENTRY_POINT)(UINTN)EntryPoint;\r | |
377 | PeimEntryPoint (PeimFileHandle, PeiServices);\r | |
378 | }\r | |
192f6d4c | 379 | //\r |
288f9b38 | 380 | // One module has been dispatched.\r |
192f6d4c | 381 | //\r |
b0d803fe | 382 | PeimDispatchOnThisPass = TRUE;\r |
192f6d4c | 383 | }\r |
384 | \r | |
385 | REPORT_STATUS_CODE_WITH_EXTENDED_DATA (\r | |
386 | EFI_PROGRESS_CODE,\r | |
387 | EFI_SOFTWARE_PEI_CORE | EFI_SW_PC_INIT_END,\r | |
388 | (VOID *)(&ExtendedData),\r | |
389 | sizeof (ExtendedData)\r | |
390 | );\r | |
b0d803fe | 391 | PERF_END (0, "PEIM", NULL, 0);\r |
392 | \r | |
a3a15d21 | 393 | } else {\r |
394 | //\r | |
395 | // If PeiLoadImage fails, the section extraction PPI or Decompress PPI may not be ready,\r | |
396 | // we flag that more Peims need to be dispatched.\r | |
397 | //\r | |
398 | PeimNeedingDispatch = TRUE;\r | |
b0d803fe | 399 | }\r |
192f6d4c | 400 | \r |
b0d803fe | 401 | //\r |
402 | // Process the Notify list and dispatch any notifies for\r | |
403 | // newly installed PPIs.\r | |
404 | //\r | |
405 | ProcessNotifyList (Private);\r | |
406 | \r | |
407 | //\r | |
408 | // If permanent memory was discovered and installed by this\r | |
409 | // PEIM, shadow PEI Core and switch the stacks to the new memory. \r | |
410 | //\r | |
411 | if (Private->SwitchStackSignal) {\r | |
192f6d4c | 412 | \r |
413 | //\r | |
b0d803fe | 414 | // Make sure we don't retry the same PEIM that added memory\r |
192f6d4c | 415 | //\r |
b0d803fe | 416 | Private->CurrentPeimCount++;\r |
192f6d4c | 417 | \r |
418 | //\r | |
b0d803fe | 419 | // Migrate IDT from CAR into real memory, so after stack switches to\r |
420 | // the new memory, the caller can get memory version PeiServiceTable. \r | |
192f6d4c | 421 | //\r |
81c7803c | 422 | MigrateIdtTable (PeiServices);\r |
423 | \r | |
b0d803fe | 424 | //\r |
425 | // Since we are at dispatch level, only the Core's private data \r | |
426 | // is preserved, nobody else should have any data on the stack. \r | |
427 | // So we need to copy PEI core instance data to memory.\r | |
428 | //\r | |
429 | PrivateInMem = AllocateCopyPool (sizeof (PEI_CORE_INSTANCE), Private);\r | |
430 | ASSERT (PrivateInMem != NULL);\r | |
192f6d4c | 431 | \r |
432 | //\r | |
b0d803fe | 433 | // Shadow PEI Core. When permanent memory is avaiable, shadow\r |
434 | // PEI Core and PEIMs to get high performance.\r | |
192f6d4c | 435 | //\r |
b0d803fe | 436 | PeiCoreFileHandle = NULL;\r |
437 | //\r | |
438 | // Find the PEI Core in the BFV\r | |
439 | //\r | |
440 | Status = PeiFindFileEx (\r | |
441 | (EFI_PEI_FV_HANDLE)Private->Fv[0].FvHeader, \r | |
442 | NULL, \r | |
443 | EFI_FV_FILETYPE_PEI_CORE, \r | |
444 | &PeiCoreFileHandle,\r | |
445 | NULL\r | |
446 | );\r | |
447 | ASSERT_EFI_ERROR (Status);\r | |
448 | \r | |
449 | //\r | |
450 | // Shadow PEI Core into memory so it will run faster\r | |
451 | //\r | |
452 | Status = PeiLoadImage (PeiServices, PeiCoreFileHandle, &EntryPoint, &AuthenticationState);\r | |
453 | ASSERT_EFI_ERROR (Status);\r | |
454 | \r | |
455 | //\r | |
456 | // Switch to memory based stack and reenter PEI Core that has been\r | |
457 | // shadowed to memory.\r | |
458 | //\r | |
459 | //\r | |
460 | // Adjust the top of stack to be aligned at CPU_STACK_ALIGNMENT\r | |
461 | //\r | |
462 | TopOfStack = (VOID *)((UINTN)Private->StackBase + (UINTN)Private->StackSize - CPU_STACK_ALIGNMENT);\r | |
463 | TopOfStack = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);\r | |
464 | \r | |
465 | PeiCoreParameters.SecCoreData = SecCoreData;\r | |
466 | PeiCoreParameters.PpiList = NULL;\r | |
467 | PeiCoreParameters.Data = PrivateInMem;\r | |
468 | ASSERT (PeiCoreParameters.Data != 0);\r | |
469 | \r | |
470 | PeiSwitchStacks (\r | |
471 | InvokePeiCore,\r | |
e83327a8 | 472 | (VOID*) ((UINTN) EntryPoint + ((UINTN) PeiCore - (UINTN) _ModuleEntryPoint)),\r |
b0d803fe | 473 | (VOID*) &PeiCoreParameters, \r |
474 | TopOfStack,\r | |
475 | (VOID*)(UINTN)Private->StackBase\r | |
476 | );\r | |
192f6d4c | 477 | }\r |
192f6d4c | 478 | \r |
b0d803fe | 479 | if ((Private->PeiMemoryInstalled) && (Private->Fv[FvCount].PeimState[PeimCount] == PEIM_STATE_REGISITER_FOR_SHADOW) && \\r |
480 | (Private->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME)) {\r | |
481 | //\r | |
482 | // If memory is availble we shadow images by default for performance reasons. \r | |
483 | // We call the entry point a 2nd time so the module knows it's shadowed. \r | |
484 | //\r | |
485 | //PERF_START (PeiServices, L"PEIM", PeimFileHandle, 0);\r | |
486 | PeimEntryPoint (PeimFileHandle, PeiServices);\r | |
487 | //PERF_END (PeiServices, L"PEIM", PeimFileHandle, 0);\r | |
488 | \r | |
489 | //\r | |
490 | // PEIM_STATE_REGISITER_FOR_SHADOW move to PEIM_STATE_DONE\r | |
491 | //\r | |
492 | Private->Fv[FvCount].PeimState[PeimCount]++;\r | |
192f6d4c | 493 | \r |
192f6d4c | 494 | //\r |
b0d803fe | 495 | // Process the Notify list and dispatch any notifies for\r |
496 | // newly installed PPIs.\r | |
192f6d4c | 497 | //\r |
b0d803fe | 498 | ProcessNotifyList (Private);\r |
192f6d4c | 499 | }\r |
500 | }\r | |
501 | }\r | |
192f6d4c | 502 | }\r |
192f6d4c | 503 | \r |
b0d803fe | 504 | //\r |
505 | // We set to NULL here to optimize the 2nd entry to this routine after\r | |
506 | // memory is found. This reprevents rescanning of the FV. We set to\r | |
507 | // NULL here so we start at the begining of the next FV\r | |
508 | //\r | |
509 | Private->CurrentFileHandle = NULL;\r | |
510 | Private->CurrentPeimCount = 0;\r | |
511 | //\r | |
512 | // Before walking through the next FV,Private->CurrentFvFileHandles[]should set to NULL\r | |
513 | //\r | |
514 | SetMem (Private->CurrentFvFileHandles, sizeof (Private->CurrentFvFileHandles), 0);\r | |
192f6d4c | 515 | }\r |
516 | \r | |
517 | //\r | |
b0d803fe | 518 | // Before making another pass, we should set Private->CurrentPeimFvCount =0 to go \r |
519 | // through all the FV.\r | |
192f6d4c | 520 | //\r |
b0d803fe | 521 | Private->CurrentPeimFvCount = 0;\r |
192f6d4c | 522 | \r |
523 | //\r | |
b0d803fe | 524 | // PeimNeedingDispatch being TRUE means we found a PEIM that did not get \r |
525 | // dispatched. So we need to make another pass\r | |
192f6d4c | 526 | //\r |
b0d803fe | 527 | // PeimDispatchOnThisPass being TRUE means we dispatched a PEIM on this \r |
528 | // pass. If we did not dispatch a PEIM there is no point in trying again\r | |
529 | // as it will fail the next time too (nothing has changed).\r | |
192f6d4c | 530 | //\r |
b0d803fe | 531 | } while (PeimNeedingDispatch && PeimDispatchOnThisPass);\r |
192f6d4c | 532 | \r |
192f6d4c | 533 | }\r |
534 | \r | |
535 | VOID\r | |
536 | InitializeDispatcherData (\r | |
b0d803fe | 537 | IN PEI_CORE_INSTANCE *PrivateData,\r |
192f6d4c | 538 | IN PEI_CORE_INSTANCE *OldCoreData,\r |
5aae0aa7 | 539 | IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData\r |
192f6d4c | 540 | )\r |
541 | /*++\r | |
542 | \r | |
543 | Routine Description:\r | |
544 | \r | |
545 | Initialize the Dispatcher's data members\r | |
546 | \r | |
547 | Arguments:\r | |
548 | \r | |
549 | PeiServices - The PEI core services table.\r | |
550 | OldCoreData - Pointer to old core data (before switching stack).\r | |
551 | NULL if being run in non-permament memory mode.\r | |
5aae0aa7 | 552 | SecCoreData - Points to a data structure containing information about the PEI core's operating\r |
553 | environment, such as the size and location of temporary RAM, the stack location and\r | |
554 | the BFV location.\r | |
192f6d4c | 555 | \r |
556 | Returns:\r | |
557 | \r | |
558 | None.\r | |
559 | \r | |
560 | --*/\r | |
561 | {\r | |
192f6d4c | 562 | if (OldCoreData == NULL) {\r |
b0d803fe | 563 | PeiInitializeFv (PrivateData, SecCoreData);\r |
192f6d4c | 564 | }\r |
565 | \r | |
566 | return;\r | |
567 | }\r | |
568 | \r | |
569 | \r | |
192f6d4c | 570 | BOOLEAN\r |
571 | DepexSatisfied (\r | |
b0d803fe | 572 | IN PEI_CORE_INSTANCE *Private,\r |
573 | IN EFI_PEI_FILE_HANDLE FileHandle,\r | |
574 | IN UINTN PeimCount\r | |
192f6d4c | 575 | )\r |
576 | /*++\r | |
577 | \r | |
578 | Routine Description:\r | |
579 | \r | |
580 | This routine parses the Dependency Expression, if available, and\r | |
581 | decides if the module can be executed.\r | |
582 | \r | |
583 | Arguments:\r | |
584 | PeiServices - The PEI Service Table\r | |
585 | CurrentPeimAddress - Address of the PEIM Firmware File under investigation\r | |
586 | \r | |
587 | Returns:\r | |
588 | TRUE - Can be dispatched\r | |
589 | FALSE - Cannot be dispatched\r | |
590 | \r | |
591 | --*/\r | |
592 | {\r | |
288f9b38 LG |
593 | EFI_STATUS Status;\r |
594 | VOID *DepexData;\r | |
b0d803fe | 595 | \r |
596 | if (PeimCount < Private->AprioriCount) {\r | |
597 | //\r | |
598 | // If its in the A priori file then we set Depex to TRUE\r | |
599 | //\r | |
600 | return TRUE;\r | |
601 | }\r | |
288f9b38 LG |
602 | \r |
603 | //\r | |
604 | // Depex section not in the encapsulated section. \r | |
605 | //\r | |
606 | Status = PeiServicesFfsFindSectionData (\r | |
607 | EFI_SECTION_PEI_DEPEX,\r | |
608 | FileHandle, \r | |
609 | (VOID **)&DepexData\r | |
610 | );\r | |
b0d803fe | 611 | \r |
192f6d4c | 612 | if (EFI_ERROR (Status)) {\r |
b0d803fe | 613 | //\r |
614 | // If there is no DEPEX, assume the module can be executed\r | |
615 | //\r | |
192f6d4c | 616 | return TRUE;\r |
617 | }\r | |
618 | \r | |
619 | //\r | |
620 | // Evaluate a given DEPEX\r | |
621 | //\r | |
b0d803fe | 622 | return PeimDispatchReadiness (&Private->PS, DepexData);\r |
192f6d4c | 623 | }\r |
624 | \r | |
14e8823a | 625 | /**\r |
626 | This routine enable a PEIM to register itself to shadow when PEI Foundation\r | |
627 | discovery permanent memory.\r | |
628 | \r | |
629 | @param FileHandle File handle of a PEIM.\r | |
630 | \r | |
631 | @retval EFI_NOT_FOUND The file handle doesn't point to PEIM itself.\r | |
632 | @retval EFI_ALREADY_STARTED Indicate that the PEIM has been registered itself.\r | |
633 | @retval EFI_SUCCESS Successfully to register itself.\r | |
634 | \r | |
635 | **/ \r | |
636 | EFI_STATUS\r | |
637 | EFIAPI\r | |
638 | PeiRegisterForShadow (\r | |
639 | IN EFI_PEI_FILE_HANDLE FileHandle\r | |
640 | )\r | |
641 | {\r | |
642 | PEI_CORE_INSTANCE *Private;\r | |
643 | Private = PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer ());\r | |
644 | \r | |
645 | if (Private->CurrentFileHandle != FileHandle) {\r | |
646 | //\r | |
647 | // The FileHandle must be for the current PEIM\r | |
648 | //\r | |
649 | return EFI_NOT_FOUND;\r | |
650 | }\r | |
651 | \r | |
652 | if (Private->Fv[Private->CurrentPeimFvCount].PeimState[Private->CurrentPeimCount] >= PEIM_STATE_REGISITER_FOR_SHADOW) {\r | |
653 | //\r | |
654 | // If the PEIM has already entered the PEIM_STATE_REGISTER_FOR_SHADOW or PEIM_STATE_DONE then it's already been started\r | |
655 | //\r | |
656 | return EFI_ALREADY_STARTED;\r | |
657 | }\r | |
658 | \r | |
659 | Private->Fv[Private->CurrentPeimFvCount].PeimState[Private->CurrentPeimCount] = PEIM_STATE_REGISITER_FOR_SHADOW;\r | |
660 | \r | |
661 | return EFI_SUCCESS;\r | |
662 | }\r | |
663 | \r | |
b0d803fe | 664 | \r |
b98c2ab7 | 665 | /**\r |
666 | This routine invoke the PeiCore's entry in new stack environment.\r | |
667 | \r | |
668 | @param Context1 The first context parameter is entry of PeiCore\r | |
669 | @param Context2 The second context parameter is parameter structure point for PeiCore\r | |
670 | \r | |
671 | **/ \r | |
672 | STATIC\r | |
673 | VOID\r | |
674 | InvokePeiCore (\r | |
675 | VOID *Context1,\r | |
676 | VOID *Context2\r | |
677 | )\r | |
678 | {\r | |
679 | PEI_CORE_ENTRY_POINT PeiCoreEntryPoint;\r | |
680 | PEI_CORE_PARAMETERS *PeiCoreParameters;\r | |
681 | \r | |
682 | //\r | |
683 | // Running on new stack in SEC Core\r | |
684 | //\r | |
685 | \r | |
686 | PeiCoreEntryPoint = (PEI_CORE_ENTRY_POINT) (UINTN) Context1;\r | |
687 | PeiCoreParameters = (PEI_CORE_PARAMETERS *)Context2;\r | |
688 | \r | |
689 | //\r | |
690 | // Call PEI Core using new stack\r | |
691 | //\r | |
692 | PeiCoreEntryPoint (\r | |
693 | PeiCoreParameters->SecCoreData,\r | |
694 | PeiCoreParameters->PpiList,\r | |
695 | PeiCoreParameters->Data\r | |
696 | );\r | |
697 | \r | |
698 | //\r | |
699 | // Never returns\r | |
700 | //\r | |
096cdcaa | 701 | ASSERT (FALSE);\r |
702 | CpuDeadLoop ();\r | |
b98c2ab7 | 703 | }\r |
288f9b38 LG |
704 | \r |
705 | /**\r | |
706 | Get Fv image from the FV type file, then install FV INFO ppi, Build FV hob.\r | |
707 | \r | |
708 | @param PeiServices Pointer to the PEI Core Services Table.\r | |
709 | @param FileHandle File handle of a Fv type file.\r | |
710 | @param AuthenticationState Pointer to attestation authentication state of image.\r | |
711 | \r | |
712 | \r | |
713 | @retval EFI_NOT_FOUND FV image can't be found.\r | |
714 | @retval EFI_SUCCESS Successfully to process it.\r | |
715 | \r | |
716 | **/\r | |
717 | EFI_STATUS\r | |
718 | ProcessFvFile (\r | |
719 | IN EFI_PEI_SERVICES **PeiServices,\r | |
720 | IN EFI_PEI_FILE_HANDLE FvFileHandle,\r | |
721 | OUT UINT32 *AuthenticationState\r | |
722 | )\r | |
723 | {\r | |
724 | EFI_STATUS Status;\r | |
725 | EFI_PEI_FV_HANDLE FvImageHandle;\r | |
726 | EFI_FV_INFO FvImageInfo;\r | |
727 | UINT32 FvAlignment;\r | |
728 | VOID *FvBuffer;\r | |
729 | EFI_PEI_HOB_POINTERS HobFv2;\r | |
730 | \r | |
731 | FvBuffer = NULL;\r | |
732 | *AuthenticationState = 0;\r | |
733 | \r | |
734 | //\r | |
735 | // Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has already \r | |
736 | // been extracted.\r | |
737 | //\r | |
738 | HobFv2.Raw = GetHobList ();\r | |
739 | while ((HobFv2.Raw = GetNextHob (EFI_HOB_TYPE_FV2, HobFv2.Raw)) != NULL) {\r | |
740 | if (CompareGuid (&(((EFI_FFS_FILE_HEADER *)FvFileHandle)->Name), &HobFv2.FirmwareVolume2->FileName)) {\r | |
741 | //\r | |
742 | // this FILE has been dispatched, it will not be dispatched again.\r | |
743 | //\r | |
744 | return EFI_SUCCESS;\r | |
745 | }\r | |
746 | HobFv2.Raw = GET_NEXT_HOB (HobFv2);\r | |
747 | }\r | |
748 | \r | |
749 | //\r | |
750 | // Find FvImage in FvFile\r | |
751 | //\r | |
752 | Status = PeiFfsFindSectionData (\r | |
753 | (CONST EFI_PEI_SERVICES **) PeiServices,\r | |
754 | EFI_SECTION_FIRMWARE_VOLUME_IMAGE,\r | |
755 | FvFileHandle,\r | |
756 | (VOID **)&FvImageHandle\r | |
757 | );\r | |
758 | \r | |
759 | if (EFI_ERROR (Status)) {\r | |
760 | return Status;\r | |
761 | }\r | |
762 | //\r | |
763 | // Collect FvImage Info.\r | |
764 | //\r | |
765 | Status = PeiFfsGetVolumeInfo (FvImageHandle, &FvImageInfo);\r | |
766 | ASSERT_EFI_ERROR (Status);\r | |
767 | //\r | |
768 | // FvAlignment must be more than 8 bytes required by FvHeader structure.\r | |
769 | //\r | |
770 | FvAlignment = 1 << ((FvImageInfo.FvAttributes & EFI_FVB2_ALIGNMENT) >> 16);\r | |
771 | if (FvAlignment < 8) {\r | |
772 | FvAlignment = 8;\r | |
773 | }\r | |
774 | // \r | |
775 | // Check FvImage\r | |
776 | //\r | |
777 | if ((UINTN) FvImageInfo.FvStart % FvAlignment != 0) {\r | |
778 | FvBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES ((UINT32) FvImageInfo.FvSize), FvAlignment);\r | |
779 | if (FvBuffer == NULL) {\r | |
780 | return EFI_OUT_OF_RESOURCES;\r | |
781 | }\r | |
782 | CopyMem (FvBuffer, FvImageInfo.FvStart, (UINTN) FvImageInfo.FvSize);\r | |
783 | //\r | |
784 | // Update FvImageInfo after reload FvImage to new aligned memory\r | |
785 | //\r | |
786 | PeiFfsGetVolumeInfo ((EFI_PEI_FV_HANDLE) FvBuffer, &FvImageInfo);\r | |
787 | }\r | |
788 | \r | |
789 | //\r | |
790 | // Install FvPpi and Build FvHob\r | |
791 | //\r | |
792 | PiLibInstallFvInfoPpi (\r | |
793 | NULL,\r | |
794 | FvImageInfo.FvStart,\r | |
795 | (UINT32) FvImageInfo.FvSize,\r | |
796 | &(FvImageInfo.FvName),\r | |
797 | &(((EFI_FFS_FILE_HEADER*)FvFileHandle)->Name)\r | |
798 | );\r | |
799 | \r | |
800 | //\r | |
801 | // Inform HOB consumer phase, i.e. DXE core, the existance of this FV\r | |
802 | //\r | |
803 | BuildFvHob (\r | |
804 | (EFI_PHYSICAL_ADDRESS) (UINTN) FvImageInfo.FvStart,\r | |
805 | FvImageInfo.FvSize\r | |
806 | );\r | |
807 | //\r | |
808 | // Makes the encapsulated volume show up in DXE phase to skip processing of\r | |
809 | // encapsulated file again.\r | |
810 | //\r | |
811 | BuildFv2Hob (\r | |
812 | (EFI_PHYSICAL_ADDRESS) (UINTN) FvImageInfo.FvStart,\r | |
813 | FvImageInfo.FvSize,\r | |
814 | &FvImageInfo.FvName,\r | |
815 | &(((EFI_FFS_FILE_HEADER *)FvFileHandle)->Name)\r | |
816 | );\r | |
817 | \r | |
818 | return EFI_SUCCESS;\r | |
819 | }\r |