]>
Commit | Line | Data |
---|---|---|
615c6dd0 | 1 | /** @file\r |
b1f6a7c6 | 2 | EFI PEI Core dispatch services\r |
3 | \r | |
192f6d4c | 4 | Copyright (c) 2006, Intel Corporation\r |
5 | All rights reserved. This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
615c6dd0 | 13 | **/\r |
192f6d4c | 14 | \r |
192f6d4c | 15 | #include <PeiMain.h>\r |
16 | \r | |
b1f6a7c6 | 17 | ///\r |
18 | /// CAR is filled with this initial value during SEC phase\r | |
19 | ///\r | |
a7715e73 | 20 | #define INIT_CAR_VALUE 0x5AA55AA5\r |
21 | \r | |
797a9d67 | 22 | typedef struct {\r |
23 | EFI_STATUS_CODE_DATA DataHeader;\r | |
24 | EFI_HANDLE Handle;\r | |
25 | } PEIM_FILE_HANDLE_EXTENDED_DATA;\r | |
26 | \r | |
b1f6a7c6 | 27 | /**\r |
b0d803fe | 28 | \r |
29 | Discover all Peims and optional Apriori file in one FV. There is at most one\r | |
30 | Apriori file in one FV.\r | |
31 | \r | |
b0d803fe | 32 | \r |
b1f6a7c6 | 33 | @param Private - Pointer to the private data passed in from caller\r |
34 | @param VolumeHandle - Fv handle.\r | |
b0d803fe | 35 | \r |
b1f6a7c6 | 36 | **/\r |
37 | VOID\r | |
38 | DiscoverPeimsAndOrderWithApriori (\r | |
39 | IN PEI_CORE_INSTANCE *Private,\r | |
40 | IN EFI_PEI_FV_HANDLE VolumeHandle\r | |
41 | )\r | |
b0d803fe | 42 | {\r |
43 | EFI_STATUS Status;\r | |
44 | EFI_PEI_FV_HANDLE FileHandle;\r | |
177aabe6 | 45 | EFI_PEI_FILE_HANDLE AprioriFileHandle;\r |
b0d803fe | 46 | EFI_GUID *Apriori;\r |
47 | UINTN Index;\r | |
48 | UINTN Index2;\r | |
49 | UINTN PeimIndex;\r | |
50 | UINTN PeimCount;\r | |
51 | EFI_GUID *Guid;\r | |
177aabe6 | 52 | EFI_PEI_FV_HANDLE TempFileHandles[FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv)];\r |
53 | EFI_GUID FileGuid[FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv)];\r | |
b0d803fe | 54 | \r |
55 | //\r | |
56 | // Walk the FV and find all the PEIMs and the Apriori file.\r | |
57 | //\r | |
58 | AprioriFileHandle = NULL;\r | |
59 | Private->CurrentFvFileHandles[0] = NULL;\r | |
60 | Guid = NULL;\r | |
61 | FileHandle = NULL;\r | |
62 | \r | |
63 | //\r | |
64 | // If the current Fv has been scanned, directly get its cachable record.\r | |
65 | //\r | |
66 | if (Private->Fv[Private->CurrentPeimFvCount].ScanFv) {\r | |
67 | CopyMem (Private->CurrentFvFileHandles, Private->Fv[Private->CurrentPeimFvCount].FvFileHandles, sizeof (Private->CurrentFvFileHandles));\r | |
68 | return;\r | |
69 | }\r | |
70 | \r | |
71 | //\r | |
72 | // Go ahead to scan this Fv, and cache FileHandles within it.\r | |
73 | //\r | |
177aabe6 | 74 | for (PeimCount = 0; PeimCount < FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv); PeimCount++) {\r |
b0d803fe | 75 | Status = PeiFindFileEx (\r |
58dcdada | 76 | VolumeHandle,\r |
77 | NULL,\r | |
78 | PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE,\r | |
b0d803fe | 79 | &FileHandle,\r |
80 | &AprioriFileHandle\r | |
81 | );\r | |
82 | if (Status != EFI_SUCCESS) {\r | |
83 | break;\r | |
84 | }\r | |
58dcdada | 85 | \r |
b0d803fe | 86 | Private->CurrentFvFileHandles[PeimCount] = FileHandle;\r |
87 | }\r | |
88 | \r | |
58dcdada | 89 | Private->AprioriCount = 0;\r |
b0d803fe | 90 | if (AprioriFileHandle != NULL) {\r |
91 | //\r | |
92 | // Read the Apriori file\r | |
93 | //\r | |
177aabe6 | 94 | Status = PeiServicesFfsFindSectionData (EFI_SECTION_RAW, AprioriFileHandle, (VOID **) &Apriori);\r |
b0d803fe | 95 | if (!EFI_ERROR (Status)) {\r |
96 | //\r | |
97 | // Calculate the number of PEIMs in the A Priori list\r | |
98 | //\r | |
99 | Private->AprioriCount = *(UINT32 *)(((EFI_FFS_FILE_HEADER *)AprioriFileHandle)->Size) & 0x00FFFFFF;\r | |
58dcdada | 100 | Private->AprioriCount -= sizeof (EFI_FFS_FILE_HEADER) - sizeof (EFI_COMMON_SECTION_HEADER);\r |
b0d803fe | 101 | Private->AprioriCount /= sizeof (EFI_GUID);\r |
58dcdada | 102 | \r |
82b8c8df | 103 | ZeroMem (FileGuid, sizeof (FileGuid));\r |
b0d803fe | 104 | for (Index = 0; Index < PeimCount; Index++) {\r |
105 | //\r | |
106 | // Make an array of file name guids that matches the FileHandle array so we can convert\r | |
107 | // quickly from file name to file handle\r | |
108 | //\r | |
58dcdada | 109 | CopyMem (&FileGuid[Index], &((EFI_FFS_FILE_HEADER *)Private->CurrentFvFileHandles[Index])->Name,sizeof(EFI_GUID));\r |
b0d803fe | 110 | }\r |
111 | \r | |
112 | //\r | |
113 | // Walk through FileGuid array to find out who is invalid PEIM guid in Apriori file.\r | |
58dcdada | 114 | // Add avalible PEIMs in Apriori file into TempFileHandles array at first.\r |
b0d803fe | 115 | //\r |
116 | Index2 = 0;\r | |
117 | for (Index = 0; Index2 < Private->AprioriCount; Index++) {\r | |
118 | while (Index2 < Private->AprioriCount) {\r | |
119 | Guid = ScanGuid (FileGuid, PeimCount * sizeof (EFI_GUID), &Apriori[Index2++]);\r | |
120 | if (Guid != NULL) {\r | |
121 | break;\r | |
122 | }\r | |
123 | }\r | |
124 | if (Guid == NULL) {\r | |
58dcdada | 125 | break;\r |
b0d803fe | 126 | }\r |
127 | PeimIndex = ((UINTN)Guid - (UINTN)&FileGuid[0])/sizeof (EFI_GUID);\r | |
128 | TempFileHandles[Index] = Private->CurrentFvFileHandles[PeimIndex];\r | |
129 | \r | |
130 | //\r | |
131 | // Since we have copied the file handle we can remove it from this list.\r | |
132 | //\r | |
133 | Private->CurrentFvFileHandles[PeimIndex] = NULL;\r | |
134 | }\r | |
135 | \r | |
136 | //\r | |
137 | // Update valid Aprioricount\r | |
138 | //\r | |
139 | Private->AprioriCount = Index;\r | |
58dcdada | 140 | \r |
b0d803fe | 141 | //\r |
142 | // Add in any PEIMs not in the Apriori file\r | |
143 | //\r | |
144 | for (;Index < PeimCount; Index++) {\r | |
145 | for (Index2 = 0; Index2 < PeimCount; Index2++) {\r | |
146 | if (Private->CurrentFvFileHandles[Index2] != NULL) {\r | |
147 | TempFileHandles[Index] = Private->CurrentFvFileHandles[Index2];\r | |
148 | Private->CurrentFvFileHandles[Index2] = NULL;\r | |
149 | break;\r | |
150 | }\r | |
151 | }\r | |
152 | }\r | |
153 | //\r | |
154 | //Index the end of array contains re-range Pei moudle.\r | |
155 | //\r | |
156 | TempFileHandles[Index] = NULL;\r | |
58dcdada | 157 | \r |
b0d803fe | 158 | //\r |
159 | // Private->CurrentFvFileHandles is currently in PEIM in the FV order.\r | |
58dcdada | 160 | // We need to update it to start with files in the A Priori list and\r |
161 | // then the remaining files in PEIM order.\r | |
b0d803fe | 162 | //\r |
163 | CopyMem (Private->CurrentFvFileHandles, TempFileHandles, sizeof (Private->CurrentFvFileHandles));\r | |
164 | }\r | |
165 | }\r | |
166 | //\r | |
167 | // Cache the current Fv File Handle. So that we don't have to scan the Fv again.\r | |
168 | // Instead, we can retrieve the file handles within this Fv from cachable data.\r | |
169 | //\r | |
170 | Private->Fv[Private->CurrentPeimFvCount].ScanFv = TRUE;\r | |
171 | CopyMem (Private->Fv[Private->CurrentPeimFvCount].FvFileHandles, Private->CurrentFvFileHandles, sizeof (Private->CurrentFvFileHandles));\r | |
58dcdada | 172 | \r |
173 | }\r | |
174 | \r | |
b1f6a7c6 | 175 | /**\r |
176 | Shadow PeiCore module from flash to installed memory.\r | |
177 | \r | |
d73d93c3 | 178 | @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.\r |
b1f6a7c6 | 179 | @param PrivateInMem PeiCore's private data structure\r |
180 | \r | |
82b8c8df | 181 | @return PeiCore function address after shadowing.\r |
b1f6a7c6 | 182 | **/\r |
58dcdada | 183 | VOID*\r |
184 | ShadowPeiCore(\r | |
185 | EFI_PEI_SERVICES **PeiServices,\r | |
186 | PEI_CORE_INSTANCE *PrivateInMem\r | |
187 | )\r | |
188 | {\r | |
189 | EFI_PEI_FILE_HANDLE PeiCoreFileHandle;\r | |
190 | EFI_PHYSICAL_ADDRESS EntryPoint;\r | |
191 | EFI_STATUS Status;\r | |
192 | UINT32 AuthenticationState;\r | |
193 | \r | |
194 | PeiCoreFileHandle = NULL;\r | |
195 | \r | |
196 | //\r | |
197 | // Find the PEI Core in the BFV\r | |
198 | //\r | |
199 | Status = PeiFindFileEx (\r | |
200 | (EFI_PEI_FV_HANDLE)PrivateInMem->Fv[0].FvHeader,\r | |
201 | NULL,\r | |
202 | EFI_FV_FILETYPE_PEI_CORE,\r | |
203 | &PeiCoreFileHandle,\r | |
204 | NULL\r | |
205 | );\r | |
206 | ASSERT_EFI_ERROR (Status);\r | |
207 | \r | |
208 | //\r | |
209 | // Shadow PEI Core into memory so it will run faster\r | |
210 | //\r | |
211 | Status = PeiLoadImage (\r | |
212 | PeiServices,\r | |
213 | *((EFI_PEI_FILE_HANDLE*)&PeiCoreFileHandle),\r | |
214 | &EntryPoint,\r | |
215 | &AuthenticationState\r | |
216 | );\r | |
217 | ASSERT_EFI_ERROR (Status);\r | |
218 | \r | |
82b8c8df | 219 | //\r |
220 | // Compute the PeiCore's function address after shaowed PeiCore.\r | |
221 | // _ModuleEntryPoint is PeiCore main function entry\r | |
222 | //\r | |
58dcdada | 223 | return (VOID*) ((UINTN) EntryPoint + (UINTN) PeiCore - (UINTN) _ModuleEntryPoint);\r |
b0d803fe | 224 | }\r |
225 | \r | |
b1f6a7c6 | 226 | /**\r |
192f6d4c | 227 | Conduct PEIM dispatch.\r |
228 | \r | |
b1f6a7c6 | 229 | @param SecCoreData Points to a data structure containing information about the PEI core's operating\r |
5aae0aa7 | 230 | environment, such as the size and location of temporary RAM, the stack location and\r |
231 | the BFV location.\r | |
b1f6a7c6 | 232 | @param Private Pointer to the private data passed in from caller\r |
192f6d4c | 233 | \r |
b1f6a7c6 | 234 | @retval EFI_SUCCESS - Successfully dispatched PEIM.\r |
235 | @retval EFI_NOT_FOUND - The dispatch failed.\r | |
192f6d4c | 236 | \r |
b1f6a7c6 | 237 | **/\r |
238 | VOID\r | |
239 | PeiDispatcher (\r | |
240 | IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData,\r | |
241 | IN PEI_CORE_INSTANCE *Private\r | |
242 | )\r | |
192f6d4c | 243 | {\r |
b0d803fe | 244 | EFI_STATUS Status;\r |
245 | UINT32 Index1;\r | |
246 | UINT32 Index2;\r | |
247 | EFI_PEI_SERVICES **PeiServices;\r | |
58dcdada | 248 | EFI_PEI_FV_HANDLE VolumeHandle;\r |
b0d803fe | 249 | EFI_PEI_FILE_HANDLE PeimFileHandle;\r |
250 | UINTN FvCount;\r | |
251 | UINTN PeimCount;\r | |
252 | UINT32 AuthenticationState;\r | |
253 | EFI_PHYSICAL_ADDRESS EntryPoint;\r | |
797a9d67 | 254 | EFI_PEIM_ENTRY_POINT2 PeimEntryPoint;\r |
b0d803fe | 255 | UINTN SaveCurrentPeimCount;\r |
1053e0c5 | 256 | UINTN SaveCurrentFvCount;\r |
b0d803fe | 257 | EFI_PEI_FILE_HANDLE SaveCurrentFileHandle;\r |
797a9d67 | 258 | PEIM_FILE_HANDLE_EXTENDED_DATA ExtendedData;\r |
58dcdada | 259 | EFI_PHYSICAL_ADDRESS NewPermenentMemoryBase;\r |
260 | TEMPORARY_RAM_SUPPORT_PPI *TemporaryRamSupportPpi;\r | |
261 | EFI_HOB_HANDOFF_INFO_TABLE *OldHandOffTable;\r | |
262 | EFI_HOB_HANDOFF_INFO_TABLE *NewHandOffTable;\r | |
66c69dea | 263 | INTN StackOffset;\r |
264 | INTN HeapOffset;\r | |
58dcdada | 265 | PEI_CORE_INSTANCE *PrivateInMem;\r |
266 | UINT64 NewPeiStackSize;\r | |
267 | UINT64 OldPeiStackSize;\r | |
268 | UINT64 StackGap;\r | |
288f9b38 | 269 | EFI_FV_FILE_INFO FvFileInfo;\r |
58dcdada | 270 | UINTN OldCheckingTop;\r |
271 | UINTN OldCheckingBottom;\r | |
b0d803fe | 272 | \r |
273 | \r | |
274 | PeiServices = &Private->PS;\r | |
275 | PeimEntryPoint = NULL;\r | |
276 | PeimFileHandle = NULL;\r | |
288f9b38 | 277 | EntryPoint = 0;\r |
b0d803fe | 278 | \r |
279 | if ((Private->PeiMemoryInstalled) && (Private->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME)) {\r | |
280 | //\r | |
281 | // Once real memory is available, shadow the RegisterForShadow modules. And meanwhile\r | |
282 | // update the modules' status from PEIM_STATE_REGISITER_FOR_SHADOW to PEIM_STATE_DONE.\r | |
283 | //\r | |
284 | SaveCurrentPeimCount = Private->CurrentPeimCount;\r | |
1053e0c5 | 285 | SaveCurrentFvCount = Private->CurrentPeimFvCount;\r |
b0d803fe | 286 | SaveCurrentFileHandle = Private->CurrentFileHandle;\r |
287 | \r | |
1053e0c5 | 288 | for (Index1 = 0; Index1 <= SaveCurrentFvCount; Index1++) {\r |
177aabe6 | 289 | for (Index2 = 0; (Index2 < FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv)) && (Private->Fv[Index1].FvFileHandles[Index2] != NULL); Index2++) {\r |
b0d803fe | 290 | if (Private->Fv[Index1].PeimState[Index2] == PEIM_STATE_REGISITER_FOR_SHADOW) {\r |
58dcdada | 291 | PeimFileHandle = Private->Fv[Index1].FvFileHandles[Index2];\r |
b0d803fe | 292 | Status = PeiLoadImage (\r |
58dcdada | 293 | &Private->PS,\r |
294 | PeimFileHandle,\r | |
295 | &EntryPoint,\r | |
b0d803fe | 296 | &AuthenticationState\r |
297 | );\r | |
298 | if (Status == EFI_SUCCESS) {\r | |
299 | //\r | |
300 | // PEIM_STATE_REGISITER_FOR_SHADOW move to PEIM_STATE_DONE\r | |
301 | //\r | |
302 | Private->Fv[Index1].PeimState[Index2]++;\r | |
1053e0c5 | 303 | Private->CurrentFileHandle = PeimFileHandle;\r |
58dcdada | 304 | Private->CurrentPeimFvCount = Index1;\r |
305 | Private->CurrentPeimCount = Index2;\r | |
b0d803fe | 306 | //\r |
307 | // Call the PEIM entry point\r | |
308 | //\r | |
797a9d67 | 309 | PeimEntryPoint = (EFI_PEIM_ENTRY_POINT2)(UINTN)EntryPoint;\r |
58dcdada | 310 | \r |
b0d803fe | 311 | PERF_START (0, "PEIM", NULL, 0);\r |
797a9d67 | 312 | PeimEntryPoint(PeimFileHandle, (const EFI_PEI_SERVICES **) &Private->PS);\r |
b0d803fe | 313 | PERF_END (0, "PEIM", NULL, 0);\r |
58dcdada | 314 | }\r |
315 | \r | |
b0d803fe | 316 | //\r |
317 | // Process the Notify list and dispatch any notifies for\r | |
318 | // newly installed PPIs.\r | |
319 | //\r | |
320 | ProcessNotifyList (Private);\r | |
321 | }\r | |
322 | }\r | |
323 | }\r | |
58dcdada | 324 | Private->CurrentFileHandle = SaveCurrentFileHandle;\r |
325 | Private->CurrentPeimFvCount = SaveCurrentFvCount;\r | |
326 | Private->CurrentPeimCount = SaveCurrentPeimCount;\r | |
b0d803fe | 327 | }\r |
192f6d4c | 328 | \r |
329 | //\r | |
330 | // This is the main dispatch loop. It will search known FVs for PEIMs and\r | |
331 | // attempt to dispatch them. If any PEIM gets dispatched through a single\r | |
332 | // pass of the dispatcher, it will start over from the Bfv again to see\r | |
333 | // if any new PEIMs dependencies got satisfied. With a well ordered\r | |
334 | // FV where PEIMs are found in the order their dependencies are also\r | |
335 | // satisfied, this dipatcher should run only once.\r | |
336 | //\r | |
b0d803fe | 337 | do {\r |
82b8c8df | 338 | //\r |
339 | // In case that reenter PeiCore happens, the last pass record is still available. \r | |
340 | //\r | |
341 | if (!Private->PeimDispatcherReenter) {\r | |
342 | Private->PeimNeedingDispatch = FALSE;\r | |
343 | Private->PeimDispatchOnThisPass = FALSE;\r | |
344 | } else {\r | |
345 | Private->PeimDispatcherReenter = FALSE;\r | |
346 | }\r | |
347 | \r | |
b0d803fe | 348 | for (FvCount = Private->CurrentPeimFvCount; FvCount < Private->FvCount; FvCount++) {\r |
349 | Private->CurrentPeimFvCount = FvCount;\r | |
2a00326e LG |
350 | //\r |
351 | // Get this Fv Handle by PeiService FvFindNextVolume.\r | |
352 | //\r | |
353 | PeiFvFindNextVolume (PeiServices, FvCount, &VolumeHandle);\r | |
192f6d4c | 354 | \r |
b0d803fe | 355 | if (Private->CurrentPeimCount == 0) {\r |
356 | //\r | |
357 | // When going through each FV, at first, search Apriori file to\r | |
58dcdada | 358 | // reorder all PEIMs to ensure the PEIMs in Apriori file to get\r |
b0d803fe | 359 | // dispatch at first.\r |
360 | //\r | |
361 | DiscoverPeimsAndOrderWithApriori (Private, VolumeHandle);\r | |
362 | }\r | |
192f6d4c | 363 | \r |
364 | //\r | |
b0d803fe | 365 | // Start to dispatch all modules within the current Fv.\r |
192f6d4c | 366 | //\r |
58dcdada | 367 | for (PeimCount = Private->CurrentPeimCount;\r |
368 | (PeimCount < FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv)) && (Private->CurrentFvFileHandles[PeimCount] != NULL);\r | |
b0d803fe | 369 | PeimCount++) {\r |
370 | Private->CurrentPeimCount = PeimCount;\r | |
371 | PeimFileHandle = Private->CurrentFileHandle = Private->CurrentFvFileHandles[PeimCount];\r | |
372 | \r | |
373 | if (Private->Fv[FvCount].PeimState[PeimCount] == PEIM_STATE_NOT_DISPATCHED) {\r | |
374 | if (!DepexSatisfied (Private, PeimFileHandle, PeimCount)) {\r | |
82b8c8df | 375 | Private->PeimNeedingDispatch = TRUE;\r |
b0d803fe | 376 | } else {\r |
288f9b38 LG |
377 | Status = PeiFfsGetFileInfo (PeimFileHandle, &FvFileInfo);\r |
378 | ASSERT_EFI_ERROR (Status);\r | |
379 | if (FvFileInfo.FileType == EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE) {\r | |
380 | //\r | |
381 | // For Fv type file, Produce new FV PPI and FV hob\r | |
382 | //\r | |
383 | Status = ProcessFvFile (PeiServices, PeimFileHandle, &AuthenticationState);\r | |
384 | } else {\r | |
385 | //\r | |
386 | // For PEIM driver, Load its entry point\r | |
387 | //\r | |
388 | Status = PeiLoadImage (\r | |
58dcdada | 389 | PeiServices,\r |
390 | PeimFileHandle,\r | |
391 | &EntryPoint,\r | |
288f9b38 LG |
392 | &AuthenticationState\r |
393 | );\r | |
394 | }\r | |
395 | \r | |
b0d803fe | 396 | if ((Status == EFI_SUCCESS)) {\r |
192f6d4c | 397 | //\r |
58dcdada | 398 | // The PEIM has its dependencies satisfied, and its entry point\r |
399 | // has been found, so invoke it.\r | |
192f6d4c | 400 | //\r |
b0d803fe | 401 | PERF_START (0, "PEIM", NULL, 0);\r |
192f6d4c | 402 | \r |
b0d803fe | 403 | ExtendedData.Handle = (EFI_HANDLE)PeimFileHandle;\r |
192f6d4c | 404 | \r |
405 | REPORT_STATUS_CODE_WITH_EXTENDED_DATA (\r | |
406 | EFI_PROGRESS_CODE,\r | |
797a9d67 | 407 | FixedPcdGet32(PcdStatusCodeValuePeimDispatch),\r |
192f6d4c | 408 | (VOID *)(&ExtendedData),\r |
409 | sizeof (ExtendedData)\r | |
410 | );\r | |
411 | \r | |
b0d803fe | 412 | Status = VerifyPeim (Private, VolumeHandle, PeimFileHandle);\r |
413 | if (Status != EFI_SECURITY_VIOLATION && (AuthenticationState == 0)) {\r | |
414 | //\r | |
415 | // PEIM_STATE_NOT_DISPATCHED move to PEIM_STATE_DISPATCHED\r | |
416 | //\r | |
417 | Private->Fv[FvCount].PeimState[PeimCount]++;\r | |
58dcdada | 418 | \r |
288f9b38 LG |
419 | if (FvFileInfo.FileType != EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE) {\r |
420 | //\r | |
421 | // Call the PEIM entry point for PEIM driver\r | |
422 | //\r | |
797a9d67 | 423 | PeimEntryPoint = (EFI_PEIM_ENTRY_POINT2)(UINTN)EntryPoint;\r |
424 | PeimEntryPoint (PeimFileHandle, (const EFI_PEI_SERVICES **) PeiServices);\r | |
288f9b38 | 425 | }\r |
797a9d67 | 426 | \r |
82b8c8df | 427 | Private->PeimDispatchOnThisPass = TRUE;\r |
192f6d4c | 428 | }\r |
429 | \r | |
430 | REPORT_STATUS_CODE_WITH_EXTENDED_DATA (\r | |
431 | EFI_PROGRESS_CODE,\r | |
797a9d67 | 432 | FixedPcdGet32(PcdStatusCodeValuePeimDispatch),\r |
192f6d4c | 433 | (VOID *)(&ExtendedData),\r |
434 | sizeof (ExtendedData)\r | |
435 | );\r | |
b0d803fe | 436 | PERF_END (0, "PEIM", NULL, 0);\r |
437 | \r | |
58dcdada | 438 | }\r |
439 | \r | |
440 | if (Private->SwitchStackSignal) {\r | |
a7715e73 | 441 | //\r |
442 | // Before switch stack from CAR to permenent memory, caculate the heap and stack\r | |
443 | // usage in temporary memory for debuging.\r | |
444 | //\r | |
445 | DEBUG_CODE_BEGIN ();\r | |
96317468 | 446 | UINT32 *StackPointer;\r |
a7715e73 | 447 | \r |
96317468 | 448 | for (StackPointer = (UINT32*)SecCoreData->StackBase;\r |
449 | (StackPointer < (UINT32*)((UINTN)SecCoreData->StackBase + SecCoreData->StackSize)) \\r | |
a7715e73 | 450 | && (*StackPointer == INIT_CAR_VALUE);\r |
451 | StackPointer ++);\r | |
452 | \r | |
453 | DEBUG ((EFI_D_INFO, "Total Cache as RAM: %d bytes.\n", SecCoreData->TemporaryRamSize));\r | |
454 | DEBUG ((EFI_D_INFO, " CAR stack ever used: %d bytes.\n",\r | |
455 | (SecCoreData->StackSize - ((UINTN) StackPointer - (UINTN)SecCoreData->StackBase))\r | |
456 | ));\r | |
457 | DEBUG ((EFI_D_INFO, " CAR heap used: %d bytes.\n",\r | |
458 | ((UINTN) Private->HobList.HandoffInformationTable->EfiFreeMemoryBottom -\r | |
459 | (UINTN) Private->HobList.Raw)\r | |
460 | ));\r | |
461 | DEBUG_CODE_END ();\r | |
462 | \r | |
a3a15d21 | 463 | //\r |
58dcdada | 464 | // Reserve the size of new stack at bottom of physical memory\r |
a3a15d21 | 465 | //\r |
58dcdada | 466 | OldPeiStackSize = Private->StackSize;\r |
467 | NewPeiStackSize = (RShiftU64 (Private->PhysicalMemoryLength, 1) + EFI_PAGE_MASK) & ~EFI_PAGE_MASK;\r | |
468 | if (FixedPcdGet32(PcdPeiCoreMaxPeiStackSize) > (UINT32) NewPeiStackSize) {\r | |
469 | Private->StackSize = NewPeiStackSize;\r | |
470 | } else {\r | |
471 | Private->StackSize = FixedPcdGet32(PcdPeiCoreMaxPeiStackSize);\r | |
472 | }\r | |
192f6d4c | 473 | \r |
58dcdada | 474 | //\r |
475 | // In theory, the size of new stack in permenent memory should large than\r | |
476 | // size of old stack in temporary memory.\r | |
477 | // But if new stack is smaller than the size of old stack, we also reserve\r | |
478 | // the size of old stack at bottom of permenent memory.\r | |
479 | //\r | |
480 | StackGap = 0;\r | |
481 | if (Private->StackSize > OldPeiStackSize) {\r | |
482 | StackGap = Private->StackSize - OldPeiStackSize;\r | |
483 | }\r | |
d74eeda8 | 484 | \r |
58dcdada | 485 | //\r |
486 | // Update HandOffHob for new installed permenent memory\r | |
487 | //\r | |
488 | OldHandOffTable = Private->HobList.HandoffInformationTable;\r | |
5c5a0601 | 489 | OldCheckingBottom = (UINTN)(SecCoreData->TemporaryRamBase);\r |
58dcdada | 490 | OldCheckingTop = (UINTN)(OldCheckingBottom + SecCoreData->TemporaryRamSize);\r |
192f6d4c | 491 | \r |
492 | //\r | |
58dcdada | 493 | // The whole temporary memory will be migrated to physical memory.\r |
494 | // CAUTION: The new base is computed accounding to gap of new stack.\r | |
192f6d4c | 495 | //\r |
58dcdada | 496 | NewPermenentMemoryBase = Private->PhysicalMemoryBegin + StackGap;\r |
40f26b8f | 497 | \r |
498 | //\r | |
499 | // Caculate stack offset and heap offset between CAR and new permement \r | |
500 | // memory seperately.\r | |
501 | //\r | |
d74eeda8 | 502 | StackOffset = (UINTN) NewPermenentMemoryBase - (UINTN) SecCoreData->StackBase;\r |
66c69dea | 503 | HeapOffset = (INTN) ((UINTN) Private->PhysicalMemoryBegin + Private->StackSize - \\r |
504 | (UINTN) SecCoreData->PeiTemporaryRamBase);\r | |
505 | DEBUG ((EFI_D_INFO, "Heap Offset = 0x%X Stack Offset = 0x%X\n", HeapOffset, StackOffset));\r | |
506 | \r | |
40f26b8f | 507 | //\r |
508 | // Caculate new HandOffTable and PrivateData address in permenet memory's stack\r | |
509 | //\r | |
66c69dea | 510 | NewHandOffTable = (EFI_HOB_HANDOFF_INFO_TABLE *)((UINTN)OldHandOffTable + HeapOffset);\r |
511 | PrivateInMem = (PEI_CORE_INSTANCE *)((UINTN) (VOID*) Private + StackOffset);\r | |
192f6d4c | 512 | \r |
513 | //\r | |
58dcdada | 514 | // TemporaryRamSupportPpi is produced by platform's SEC\r |
192f6d4c | 515 | //\r |
58dcdada | 516 | Status = PeiLocatePpi (\r |
517 | (CONST EFI_PEI_SERVICES **) PeiServices,\r | |
518 | &gEfiTemporaryRamSupportPpiGuid,\r | |
519 | 0,\r | |
520 | NULL,\r | |
521 | (VOID**)&TemporaryRamSupportPpi\r | |
522 | );\r | |
523 | \r | |
81c7803c | 524 | \r |
58dcdada | 525 | if (!EFI_ERROR (Status)) {\r |
40f26b8f | 526 | //\r |
527 | // Temporary Ram support Ppi is provided by platform, it will copy \r | |
528 | // temporary memory to permenent memory and do stack switching.\r | |
529 | // After invoken temporary Ram support, following code's stack is in \r | |
530 | // memory but not in CAR.\r | |
531 | //\r | |
58dcdada | 532 | TemporaryRamSupportPpi->TemporaryRamMigration (\r |
533 | (CONST EFI_PEI_SERVICES **) PeiServices,\r | |
534 | (EFI_PHYSICAL_ADDRESS)(UINTN) SecCoreData->TemporaryRamBase,\r | |
535 | (EFI_PHYSICAL_ADDRESS)(UINTN) NewPermenentMemoryBase,\r | |
536 | SecCoreData->TemporaryRamSize\r | |
537 | );\r | |
538 | \r | |
539 | } else {\r | |
b414ea4b | 540 | //\r |
541 | // In IA32/x64/Itanium architecture, we need platform provide\r | |
542 | // TEMPORAY_RAM_MIGRATION_PPI.\r | |
543 | //\r | |
544 | ASSERT (FALSE);\r | |
58dcdada | 545 | }\r |
546 | \r | |
547 | \r | |
548 | //\r | |
b0d803fe | 549 | //\r |
58dcdada | 550 | // Fixup the PeiCore's private data\r |
b0d803fe | 551 | //\r |
58dcdada | 552 | PrivateInMem->PS = &PrivateInMem->ServiceTableShadow;\r |
553 | PrivateInMem->CpuIo = &PrivateInMem->ServiceTableShadow.CpuIo;\r | |
66c69dea | 554 | PrivateInMem->HobList.Raw = (VOID*) ((UINTN) PrivateInMem->HobList.Raw + HeapOffset);\r |
58dcdada | 555 | PrivateInMem->StackBase = (EFI_PHYSICAL_ADDRESS)(((UINTN)PrivateInMem->PhysicalMemoryBegin + EFI_PAGE_MASK) & ~EFI_PAGE_MASK);\r |
556 | \r | |
557 | PeiServices = &PrivateInMem->PS;\r | |
558 | \r | |
559 | //\r | |
560 | // Fixup for PeiService's address\r | |
561 | //\r | |
562 | SetPeiServicesTablePointer(PeiServices);\r | |
563 | \r | |
564 | //\r | |
565 | // Update HandOffHob for new installed permenent memory\r | |
566 | //\r | |
567 | NewHandOffTable->EfiEndOfHobList =\r | |
66c69dea | 568 | (EFI_PHYSICAL_ADDRESS)((UINTN) NewHandOffTable->EfiEndOfHobList + HeapOffset);\r |
58dcdada | 569 | NewHandOffTable->EfiMemoryTop = PrivateInMem->PhysicalMemoryBegin +\r |
570 | PrivateInMem->PhysicalMemoryLength;\r | |
571 | NewHandOffTable->EfiMemoryBottom = PrivateInMem->PhysicalMemoryBegin;\r | |
572 | NewHandOffTable->EfiFreeMemoryTop = PrivateInMem->FreePhysicalMemoryTop;\r | |
573 | NewHandOffTable->EfiFreeMemoryBottom = NewHandOffTable->EfiEndOfHobList +\r | |
574 | sizeof (EFI_HOB_GENERIC_HEADER);\r | |
575 | \r | |
576 | //\r | |
577 | // We need convert the PPI desciptor's pointer\r | |
578 | //\r | |
40f26b8f | 579 | ConvertPpiPointers (PrivateInMem, \r |
58dcdada | 580 | OldCheckingBottom, \r |
581 | OldCheckingTop, \r | |
5c5a0601 | 582 | HeapOffset\r |
583 | );\r | |
58dcdada | 584 | \r |
585 | DEBUG ((EFI_D_INFO, "Stack Hob: BaseAddress=0x%X Length=0x%X\n",\r | |
586 | (UINTN)PrivateInMem->StackBase,\r | |
587 | PrivateInMem->StackSize));\r | |
588 | BuildStackHob (PrivateInMem->StackBase, PrivateInMem->StackSize);\r | |
589 | \r | |
590 | //\r | |
591 | // After the whole temporary memory is migrated, then we can allocate page in\r | |
592 | // permenent memory.\r | |
593 | //\r | |
594 | PrivateInMem->PeiMemoryInstalled = TRUE;\r | |
595 | \r | |
1bd90a4c | 596 | //\r |
82b8c8df | 597 | // Indicate that PeiCore reenter\r |
1bd90a4c | 598 | //\r |
82b8c8df | 599 | PrivateInMem->PeimDispatcherReenter = TRUE;\r |
600 | \r | |
192f6d4c | 601 | //\r |
b0d803fe | 602 | // Shadow PEI Core. When permanent memory is avaiable, shadow\r |
603 | // PEI Core and PEIMs to get high performance.\r | |
192f6d4c | 604 | //\r |
58dcdada | 605 | PrivateInMem->ShadowedPeiCore = ShadowPeiCore (\r |
606 | PeiServices,\r | |
607 | PrivateInMem\r | |
608 | );\r | |
b0d803fe | 609 | //\r |
58dcdada | 610 | // Process the Notify list and dispatch any notifies for\r |
611 | // newly installed PPIs.\r | |
b0d803fe | 612 | //\r |
58dcdada | 613 | ProcessNotifyList (PrivateInMem);\r |
614 | \r | |
b0d803fe | 615 | //\r |
58dcdada | 616 | // Entry PEI Phase 2\r |
b0d803fe | 617 | //\r |
58dcdada | 618 | PeiCore (SecCoreData, NULL, PrivateInMem);\r |
b0d803fe | 619 | \r |
58dcdada | 620 | //\r |
621 | // Code should not come here\r | |
622 | //\r | |
623 | ASSERT_EFI_ERROR(FALSE);\r | |
192f6d4c | 624 | }\r |
192f6d4c | 625 | \r |
58dcdada | 626 | //\r |
627 | // Process the Notify list and dispatch any notifies for\r | |
628 | // newly installed PPIs.\r | |
629 | //\r | |
630 | ProcessNotifyList (Private);\r | |
631 | \r | |
b0d803fe | 632 | if ((Private->PeiMemoryInstalled) && (Private->Fv[FvCount].PeimState[PeimCount] == PEIM_STATE_REGISITER_FOR_SHADOW) && \\r |
633 | (Private->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME)) {\r | |
634 | //\r | |
58dcdada | 635 | // If memory is availble we shadow images by default for performance reasons.\r |
636 | // We call the entry point a 2nd time so the module knows it's shadowed.\r | |
b0d803fe | 637 | //\r |
638 | //PERF_START (PeiServices, L"PEIM", PeimFileHandle, 0);\r | |
797a9d67 | 639 | PeimEntryPoint (PeimFileHandle, (const EFI_PEI_SERVICES **) PeiServices);\r |
b0d803fe | 640 | //PERF_END (PeiServices, L"PEIM", PeimFileHandle, 0);\r |
58dcdada | 641 | \r |
b0d803fe | 642 | //\r |
643 | // PEIM_STATE_REGISITER_FOR_SHADOW move to PEIM_STATE_DONE\r | |
644 | //\r | |
645 | Private->Fv[FvCount].PeimState[PeimCount]++;\r | |
192f6d4c | 646 | \r |
192f6d4c | 647 | //\r |
b0d803fe | 648 | // Process the Notify list and dispatch any notifies for\r |
649 | // newly installed PPIs.\r | |
192f6d4c | 650 | //\r |
b0d803fe | 651 | ProcessNotifyList (Private);\r |
192f6d4c | 652 | }\r |
653 | }\r | |
654 | }\r | |
192f6d4c | 655 | }\r |
192f6d4c | 656 | \r |
b0d803fe | 657 | //\r |
658 | // We set to NULL here to optimize the 2nd entry to this routine after\r | |
659 | // memory is found. This reprevents rescanning of the FV. We set to\r | |
660 | // NULL here so we start at the begining of the next FV\r | |
661 | //\r | |
662 | Private->CurrentFileHandle = NULL;\r | |
663 | Private->CurrentPeimCount = 0;\r | |
664 | //\r | |
665 | // Before walking through the next FV,Private->CurrentFvFileHandles[]should set to NULL\r | |
666 | //\r | |
667 | SetMem (Private->CurrentFvFileHandles, sizeof (Private->CurrentFvFileHandles), 0);\r | |
192f6d4c | 668 | }\r |
669 | \r | |
670 | //\r | |
58dcdada | 671 | // Before making another pass, we should set Private->CurrentPeimFvCount =0 to go\r |
b0d803fe | 672 | // through all the FV.\r |
192f6d4c | 673 | //\r |
b0d803fe | 674 | Private->CurrentPeimFvCount = 0;\r |
192f6d4c | 675 | \r |
676 | //\r | |
58dcdada | 677 | // PeimNeedingDispatch being TRUE means we found a PEIM that did not get\r |
b0d803fe | 678 | // dispatched. So we need to make another pass\r |
192f6d4c | 679 | //\r |
58dcdada | 680 | // PeimDispatchOnThisPass being TRUE means we dispatched a PEIM on this\r |
b0d803fe | 681 | // pass. If we did not dispatch a PEIM there is no point in trying again\r |
682 | // as it will fail the next time too (nothing has changed).\r | |
192f6d4c | 683 | //\r |
82b8c8df | 684 | } while (Private->PeimNeedingDispatch && Private->PeimDispatchOnThisPass);\r |
192f6d4c | 685 | \r |
192f6d4c | 686 | }\r |
687 | \r | |
b1f6a7c6 | 688 | /**\r |
192f6d4c | 689 | Initialize the Dispatcher's data members\r |
690 | \r | |
b1f6a7c6 | 691 | @param PrivateData PeiCore's private data structure\r |
692 | @param OldCoreData Old data from SecCore\r | |
192f6d4c | 693 | NULL if being run in non-permament memory mode.\r |
b1f6a7c6 | 694 | @param SecCoreData Points to a data structure containing information about the PEI core's operating\r |
5aae0aa7 | 695 | environment, such as the size and location of temporary RAM, the stack location and\r |
696 | the BFV location.\r | |
192f6d4c | 697 | \r |
b1f6a7c6 | 698 | @return None.\r |
192f6d4c | 699 | \r |
b1f6a7c6 | 700 | **/\r |
701 | VOID\r | |
702 | InitializeDispatcherData (\r | |
703 | IN PEI_CORE_INSTANCE *PrivateData,\r | |
704 | IN PEI_CORE_INSTANCE *OldCoreData,\r | |
705 | IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData\r | |
706 | )\r | |
192f6d4c | 707 | {\r |
192f6d4c | 708 | if (OldCoreData == NULL) {\r |
82b8c8df | 709 | PrivateData->PeimDispatcherReenter = FALSE;\r |
b0d803fe | 710 | PeiInitializeFv (PrivateData, SecCoreData);\r |
192f6d4c | 711 | }\r |
712 | \r | |
713 | return;\r | |
714 | }\r | |
715 | \r | |
b1f6a7c6 | 716 | /**\r |
717 | This routine parses the Dependency Expression, if available, and\r | |
718 | decides if the module can be executed.\r | |
719 | \r | |
720 | \r | |
721 | @param Private PeiCore's private data structure\r | |
722 | @param FileHandle PEIM's file handle\r | |
723 | @param PeimCount Peim count in all dispatched PEIMs.\r | |
192f6d4c | 724 | \r |
b1f6a7c6 | 725 | @retval TRUE Can be dispatched\r |
726 | @retval FALSE Cannot be dispatched\r | |
727 | \r | |
728 | **/\r | |
192f6d4c | 729 | BOOLEAN\r |
730 | DepexSatisfied (\r | |
b0d803fe | 731 | IN PEI_CORE_INSTANCE *Private,\r |
732 | IN EFI_PEI_FILE_HANDLE FileHandle,\r | |
733 | IN UINTN PeimCount\r | |
192f6d4c | 734 | )\r |
192f6d4c | 735 | {\r |
288f9b38 LG |
736 | EFI_STATUS Status;\r |
737 | VOID *DepexData;\r | |
b0d803fe | 738 | \r |
739 | if (PeimCount < Private->AprioriCount) {\r | |
740 | //\r | |
741 | // If its in the A priori file then we set Depex to TRUE\r | |
742 | //\r | |
743 | return TRUE;\r | |
744 | }\r | |
58dcdada | 745 | \r |
288f9b38 | 746 | //\r |
58dcdada | 747 | // Depex section not in the encapsulated section.\r |
288f9b38 LG |
748 | //\r |
749 | Status = PeiServicesFfsFindSectionData (\r | |
750 | EFI_SECTION_PEI_DEPEX,\r | |
58dcdada | 751 | FileHandle,\r |
288f9b38 LG |
752 | (VOID **)&DepexData\r |
753 | );\r | |
b0d803fe | 754 | \r |
192f6d4c | 755 | if (EFI_ERROR (Status)) {\r |
b0d803fe | 756 | //\r |
757 | // If there is no DEPEX, assume the module can be executed\r | |
758 | //\r | |
192f6d4c | 759 | return TRUE;\r |
760 | }\r | |
761 | \r | |
762 | //\r | |
763 | // Evaluate a given DEPEX\r | |
764 | //\r | |
b0d803fe | 765 | return PeimDispatchReadiness (&Private->PS, DepexData);\r |
192f6d4c | 766 | }\r |
767 | \r | |
14e8823a | 768 | /**\r |
769 | This routine enable a PEIM to register itself to shadow when PEI Foundation\r | |
770 | discovery permanent memory.\r | |
771 | \r | |
b1f6a7c6 | 772 | @param FileHandle File handle of a PEIM.\r |
58dcdada | 773 | \r |
b1f6a7c6 | 774 | @retval EFI_NOT_FOUND The file handle doesn't point to PEIM itself.\r |
775 | @retval EFI_ALREADY_STARTED Indicate that the PEIM has been registered itself.\r | |
776 | @retval EFI_SUCCESS Successfully to register itself.\r | |
14e8823a | 777 | \r |
58dcdada | 778 | **/\r |
14e8823a | 779 | EFI_STATUS\r |
780 | EFIAPI\r | |
781 | PeiRegisterForShadow (\r | |
782 | IN EFI_PEI_FILE_HANDLE FileHandle\r | |
783 | )\r | |
784 | {\r | |
785 | PEI_CORE_INSTANCE *Private;\r | |
786 | Private = PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer ());\r | |
787 | \r | |
788 | if (Private->CurrentFileHandle != FileHandle) {\r | |
789 | //\r | |
790 | // The FileHandle must be for the current PEIM\r | |
791 | //\r | |
792 | return EFI_NOT_FOUND;\r | |
793 | }\r | |
794 | \r | |
795 | if (Private->Fv[Private->CurrentPeimFvCount].PeimState[Private->CurrentPeimCount] >= PEIM_STATE_REGISITER_FOR_SHADOW) {\r | |
796 | //\r | |
797 | // If the PEIM has already entered the PEIM_STATE_REGISTER_FOR_SHADOW or PEIM_STATE_DONE then it's already been started\r | |
798 | //\r | |
799 | return EFI_ALREADY_STARTED;\r | |
800 | }\r | |
58dcdada | 801 | \r |
14e8823a | 802 | Private->Fv[Private->CurrentPeimFvCount].PeimState[Private->CurrentPeimCount] = PEIM_STATE_REGISITER_FOR_SHADOW;\r |
803 | \r | |
804 | return EFI_SUCCESS;\r | |
805 | }\r | |
806 | \r | |
288f9b38 LG |
807 | /**\r |
808 | Get Fv image from the FV type file, then install FV INFO ppi, Build FV hob.\r | |
809 | \r | |
d73d93c3 | 810 | @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.\r |
b1f6a7c6 | 811 | @param FvFileHandle File handle of a Fv type file.\r |
288f9b38 LG |
812 | @param AuthenticationState Pointer to attestation authentication state of image.\r |
813 | \r | |
58dcdada | 814 | \r |
82b8c8df | 815 | @retval EFI_NOT_FOUND FV image can't be found.\r |
816 | @retval EFI_SUCCESS Successfully to process it.\r | |
817 | @retval EFI_OUT_OF_RESOURCES Can not allocate page when aligning FV image\r | |
818 | @retval Others Can not find EFI_SECTION_FIRMWARE_VOLUME_IMAGE section\r | |
819 | \r | |
288f9b38 LG |
820 | **/\r |
821 | EFI_STATUS\r | |
822 | ProcessFvFile (\r | |
823 | IN EFI_PEI_SERVICES **PeiServices,\r | |
824 | IN EFI_PEI_FILE_HANDLE FvFileHandle,\r | |
825 | OUT UINT32 *AuthenticationState\r | |
826 | )\r | |
827 | {\r | |
828 | EFI_STATUS Status;\r | |
829 | EFI_PEI_FV_HANDLE FvImageHandle;\r | |
830 | EFI_FV_INFO FvImageInfo;\r | |
831 | UINT32 FvAlignment;\r | |
832 | VOID *FvBuffer;\r | |
6d2e8727 | 833 | EFI_PEI_HOB_POINTERS HobPtr;\r |
58dcdada | 834 | \r |
288f9b38 LG |
835 | FvBuffer = NULL;\r |
836 | *AuthenticationState = 0;\r | |
837 | \r | |
838 | //\r | |
58dcdada | 839 | // Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has already\r |
288f9b38 LG |
840 | // been extracted.\r |
841 | //\r | |
6d2e8727 | 842 | HobPtr.Raw = GetHobList ();\r |
843 | while ((HobPtr.Raw = GetNextHob (EFI_HOB_TYPE_FV2, HobPtr.Raw)) != NULL) {\r | |
844 | if (CompareGuid (&(((EFI_FFS_FILE_HEADER *)FvFileHandle)->Name), &HobPtr.FirmwareVolume2->FileName)) {\r | |
288f9b38 LG |
845 | //\r |
846 | // this FILE has been dispatched, it will not be dispatched again.\r | |
847 | //\r | |
848 | return EFI_SUCCESS;\r | |
849 | }\r | |
6d2e8727 | 850 | HobPtr.Raw = GET_NEXT_HOB (HobPtr);\r |
288f9b38 | 851 | }\r |
58dcdada | 852 | \r |
288f9b38 LG |
853 | //\r |
854 | // Find FvImage in FvFile\r | |
855 | //\r | |
856 | Status = PeiFfsFindSectionData (\r | |
857 | (CONST EFI_PEI_SERVICES **) PeiServices,\r | |
858 | EFI_SECTION_FIRMWARE_VOLUME_IMAGE,\r | |
859 | FvFileHandle,\r | |
860 | (VOID **)&FvImageHandle\r | |
861 | );\r | |
58dcdada | 862 | \r |
288f9b38 LG |
863 | if (EFI_ERROR (Status)) {\r |
864 | return Status;\r | |
865 | }\r | |
82b8c8df | 866 | \r |
288f9b38 LG |
867 | //\r |
868 | // Collect FvImage Info.\r | |
869 | //\r | |
870 | Status = PeiFfsGetVolumeInfo (FvImageHandle, &FvImageInfo);\r | |
871 | ASSERT_EFI_ERROR (Status);\r | |
82b8c8df | 872 | \r |
288f9b38 LG |
873 | //\r |
874 | // FvAlignment must be more than 8 bytes required by FvHeader structure.\r | |
875 | //\r | |
876 | FvAlignment = 1 << ((FvImageInfo.FvAttributes & EFI_FVB2_ALIGNMENT) >> 16);\r | |
877 | if (FvAlignment < 8) {\r | |
878 | FvAlignment = 8;\r | |
879 | }\r | |
82b8c8df | 880 | \r |
58dcdada | 881 | //\r |
288f9b38 LG |
882 | // Check FvImage\r |
883 | //\r | |
884 | if ((UINTN) FvImageInfo.FvStart % FvAlignment != 0) {\r | |
885 | FvBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES ((UINT32) FvImageInfo.FvSize), FvAlignment);\r | |
886 | if (FvBuffer == NULL) {\r | |
887 | return EFI_OUT_OF_RESOURCES;\r | |
888 | }\r | |
889 | CopyMem (FvBuffer, FvImageInfo.FvStart, (UINTN) FvImageInfo.FvSize);\r | |
890 | //\r | |
891 | // Update FvImageInfo after reload FvImage to new aligned memory\r | |
892 | //\r | |
893 | PeiFfsGetVolumeInfo ((EFI_PEI_FV_HANDLE) FvBuffer, &FvImageInfo);\r | |
894 | }\r | |
58dcdada | 895 | \r |
288f9b38 LG |
896 | //\r |
897 | // Install FvPpi and Build FvHob\r | |
898 | //\r | |
899 | PiLibInstallFvInfoPpi (\r | |
900 | NULL,\r | |
901 | FvImageInfo.FvStart,\r | |
902 | (UINT32) FvImageInfo.FvSize,\r | |
903 | &(FvImageInfo.FvName),\r | |
904 | &(((EFI_FFS_FILE_HEADER*)FvFileHandle)->Name)\r | |
905 | );\r | |
906 | \r | |
907 | //\r | |
6d2e8727 | 908 | // Inform the extracted FvImage to Fv HOB consumer phase, i.e. DXE phase\r |
909 | // based on its parent Fvimage is informed or not.\r | |
910 | // If FvHob of its parent fvimage is built, the extracted FvImage will be built also. \r | |
911 | // Or, the extracted FvImage will not be built.\r | |
288f9b38 | 912 | //\r |
6d2e8727 | 913 | HobPtr.Raw = GetHobList ();\r |
914 | while ((HobPtr.Raw = GetNextHob (EFI_HOB_TYPE_FV, HobPtr.Raw)) != NULL) {\r | |
915 | if (((EFI_PHYSICAL_ADDRESS) (UINTN)FvFileHandle > HobPtr.FirmwareVolume->BaseAddress) && \r | |
916 | ((EFI_PHYSICAL_ADDRESS) (UINTN)FvFileHandle < HobPtr.FirmwareVolume->BaseAddress + HobPtr.FirmwareVolume->Length)) {\r | |
917 | BuildFvHob (\r | |
918 | (EFI_PHYSICAL_ADDRESS) (UINTN) FvImageInfo.FvStart,\r | |
919 | FvImageInfo.FvSize\r | |
920 | );\r | |
921 | break;\r | |
922 | }\r | |
923 | HobPtr.Raw = GET_NEXT_HOB (HobPtr);\r | |
924 | }\r | |
925 | \r | |
288f9b38 LG |
926 | //\r |
927 | // Makes the encapsulated volume show up in DXE phase to skip processing of\r | |
928 | // encapsulated file again.\r | |
929 | //\r | |
930 | BuildFv2Hob (\r | |
931 | (EFI_PHYSICAL_ADDRESS) (UINTN) FvImageInfo.FvStart,\r | |
932 | FvImageInfo.FvSize,\r | |
933 | &FvImageInfo.FvName,\r | |
934 | &(((EFI_FFS_FILE_HEADER *)FvFileHandle)->Name)\r | |
935 | );\r | |
58dcdada | 936 | \r |
288f9b38 LG |
937 | return EFI_SUCCESS;\r |
938 | }\r |