]>
Commit | Line | Data |
---|---|---|
96226baa | 1 | /** @file\r |
b0d803fe | 2 | Last PEIM.\r |
3 | Responsibility of this module is to load the DXE Core from a Firmware Volume.\r | |
95276127 | 4 | \r |
37623a5c | 5 | Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r |
cd5ebaa0 | 6 | This program and the accompanying materials\r |
95276127 | 7 | are licensed and made available under the terms and conditions of the BSD License\r |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | \r | |
b0d803fe | 14 | **/\r |
95276127 | 15 | \r |
95276127 | 16 | #include "DxeIpl.h"\r |
b0d803fe | 17 | \r |
95276127 | 18 | \r |
19 | //\r | |
48557c65 | 20 | // Module Globals used in the DXE to PEI hand off\r |
95276127 | 21 | // These must be module globals, so the stack can be switched\r |
22 | //\r | |
9b937a73 | 23 | CONST EFI_DXE_IPL_PPI mDxeIplPpi = {\r |
95276127 | 24 | DxeLoadCore\r |
25 | };\r | |
26 | \r | |
9b937a73 | 27 | CONST EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI mCustomGuidedSectionExtractionPpi = {\r |
18fd8d65 | 28 | CustomGuidedSectionExtract\r |
95276127 | 29 | };\r |
30 | \r | |
9b937a73 | 31 | CONST EFI_PEI_DECOMPRESS_PPI mDecompressPpi = {\r |
b0d803fe | 32 | Decompress\r |
d8c79a81 LG |
33 | };\r |
34 | \r | |
48557c65 | 35 | CONST EFI_PEI_PPI_DESCRIPTOR mPpiList[] = {\r |
95276127 | 36 | {\r |
b0d803fe | 37 | EFI_PEI_PPI_DESCRIPTOR_PPI,\r |
38 | &gEfiDxeIplPpiGuid,\r | |
9b937a73 | 39 | (VOID *) &mDxeIplPpi\r |
95276127 | 40 | },\r |
41 | {\r | |
b0d803fe | 42 | (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r |
43 | &gEfiPeiDecompressPpiGuid,\r | |
9b937a73 | 44 | (VOID *) &mDecompressPpi\r |
95276127 | 45 | }\r |
46 | };\r | |
47 | \r | |
48557c65 | 48 | CONST EFI_PEI_PPI_DESCRIPTOR gEndOfPeiSignalPpi = {\r |
95276127 | 49 | (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r |
50 | &gEfiEndOfPeiSignalPpiGuid,\r | |
51 | NULL\r | |
52 | };\r | |
53 | \r | |
b0d803fe | 54 | /**\r |
48557c65 | 55 | Entry point of DXE IPL PEIM.\r |
56 | \r | |
57 | This function installs DXE IPL PPI and Decompress PPI. It also reloads\r | |
58 | itself to memory on non-S3 resume boot path.\r | |
b0d803fe | 59 | \r |
a55caa53 LG |
60 | @param FileHandle Handle of the file being invoked.\r |
61 | @param PeiServices Describes the list of possible PEI Services.\r | |
91d92e25 | 62 | \r |
48557c65 | 63 | @retval EFI_SUCESS The entry point of DXE IPL PEIM executes successfully.\r |
64 | @retval Others Some error occurs during the execution of this function. \r | |
65 | \r | |
91d92e25 | 66 | **/\r |
95276127 | 67 | EFI_STATUS\r |
68 | EFIAPI\r | |
69 | PeimInitializeDxeIpl (\r | |
a55caa53 LG |
70 | IN EFI_PEI_FILE_HANDLE FileHandle,\r |
71 | IN CONST EFI_PEI_SERVICES **PeiServices\r | |
95276127 | 72 | )\r |
95276127 | 73 | {\r |
74 | EFI_STATUS Status;\r | |
95276127 | 75 | EFI_BOOT_MODE BootMode;\r |
18fd8d65 LG |
76 | EFI_GUID *ExtractHandlerGuidTable;\r |
77 | UINTN ExtractHandlerNumber;\r | |
d8c79a81 LG |
78 | EFI_PEI_PPI_DESCRIPTOR *GuidPpi;\r |
79 | \r | |
b98da1b1 | 80 | BootMode = GetBootModeHob ();\r |
95276127 | 81 | \r |
b0d803fe | 82 | if (BootMode != BOOT_ON_S3_RESUME) {\r |
a55caa53 | 83 | Status = PeiServicesRegisterForShadow (FileHandle);\r |
b0d803fe | 84 | if (Status == EFI_SUCCESS) {\r |
b0d803fe | 85 | //\r |
48557c65 | 86 | // EFI_SUCESS means it is the first time to call register for shadow. \r |
b0d803fe | 87 | // \r |
88 | return Status;\r | |
48557c65 | 89 | }\r |
90 | \r | |
91 | //\r | |
92 | // Ensure that DXE IPL is shadowed to permanent memory.\r | |
93 | //\r | |
94 | ASSERT (Status == EFI_ALREADY_STARTED);\r | |
25bc8326 | 95 | }\r |
b98da1b1 | 96 | \r |
25bc8326 LG |
97 | //\r |
98 | // Get custom extract guided section method guid list \r | |
99 | //\r | |
100 | ExtractHandlerNumber = ExtractGuidedSectionGetGuidList (&ExtractHandlerGuidTable);\r | |
101 | \r | |
102 | //\r | |
103 | // Install custom extraction guid PPI\r | |
104 | //\r | |
105 | if (ExtractHandlerNumber > 0) {\r | |
106 | GuidPpi = (EFI_PEI_PPI_DESCRIPTOR *) AllocatePool (ExtractHandlerNumber * sizeof (EFI_PEI_PPI_DESCRIPTOR));\r | |
107 | ASSERT (GuidPpi != NULL);\r | |
108 | while (ExtractHandlerNumber-- > 0) {\r | |
109 | GuidPpi->Flags = EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;\r | |
110 | GuidPpi->Ppi = (VOID *) &mCustomGuidedSectionExtractionPpi;\r | |
111 | GuidPpi->Guid = &ExtractHandlerGuidTable[ExtractHandlerNumber];\r | |
112 | Status = PeiServicesInstallPpi (GuidPpi++);\r | |
113 | ASSERT_EFI_ERROR(Status);\r | |
d8c79a81 | 114 | }\r |
95276127 | 115 | }\r |
116 | \r | |
b0d803fe | 117 | //\r |
288f9b38 | 118 | // Install DxeIpl and Decompress PPIs.\r |
b0d803fe | 119 | //\r |
120 | Status = PeiServicesInstallPpi (mPpiList);\r | |
288f9b38 LG |
121 | ASSERT_EFI_ERROR(Status);\r |
122 | \r | |
95276127 | 123 | return Status;\r |
124 | }\r | |
125 | \r | |
a95b6045 ED |
126 | /**\r |
127 | Validate variable data for the MemoryTypeInformation. \r | |
128 | \r | |
129 | @param MemoryData Variable data.\r | |
130 | @param MemoryDataSize Variable data length.\r | |
131 | \r | |
132 | @return TRUE The variable data is valid.\r | |
133 | @return FALSE The variable data is invalid.\r | |
134 | \r | |
135 | **/\r | |
136 | BOOLEAN\r | |
137 | ValidateMemoryTypeInfoVariable (\r | |
138 | IN EFI_MEMORY_TYPE_INFORMATION *MemoryData,\r | |
139 | IN UINTN MemoryDataSize\r | |
140 | )\r | |
141 | {\r | |
142 | UINTN Count;\r | |
143 | UINTN Index;\r | |
144 | \r | |
145 | // Check the input parameter.\r | |
146 | if (MemoryData == NULL) {\r | |
147 | return FALSE;\r | |
148 | }\r | |
149 | \r | |
150 | // Get Count\r | |
151 | Count = MemoryDataSize / sizeof (*MemoryData);\r | |
152 | \r | |
153 | // Check Size\r | |
154 | if (Count * sizeof(*MemoryData) != MemoryDataSize) {\r | |
155 | return FALSE;\r | |
156 | }\r | |
157 | \r | |
158 | // Check last entry type filed.\r | |
159 | if (MemoryData[Count - 1].Type != EfiMaxMemoryType) {\r | |
160 | return FALSE;\r | |
161 | }\r | |
162 | \r | |
163 | // Check the type filed.\r | |
164 | for (Index = 0; Index < Count - 1; Index++) {\r | |
165 | if (MemoryData[Index].Type >= EfiMaxMemoryType) {\r | |
166 | return FALSE;\r | |
167 | }\r | |
168 | }\r | |
169 | \r | |
170 | return TRUE;\r | |
171 | }\r | |
172 | \r | |
b0d803fe | 173 | /**\r |
b98da1b1 | 174 | Main entry point to last PEIM. \r |
48557c65 | 175 | \r |
176 | This function finds DXE Core in the firmware volume and transfer the control to\r | |
177 | DXE core.\r | |
b0d803fe | 178 | \r |
b98da1b1 | 179 | @param This Entry point for DXE IPL PPI.\r |
b0d803fe | 180 | @param PeiServices General purpose services available to every PEIM.\r |
b98da1b1 | 181 | @param HobList Address to the Pei HOB list.\r |
b0d803fe | 182 | \r |
183 | @return EFI_SUCCESS DXE core was successfully loaded. \r | |
184 | @return EFI_OUT_OF_RESOURCES There are not enough resources to load DXE core.\r | |
91d92e25 | 185 | \r |
b0d803fe | 186 | **/\r |
95276127 | 187 | EFI_STATUS\r |
188 | EFIAPI\r | |
189 | DxeLoadCore (\r | |
1f3a753e | 190 | IN CONST EFI_DXE_IPL_PPI *This,\r |
95276127 | 191 | IN EFI_PEI_SERVICES **PeiServices,\r |
192 | IN EFI_PEI_HOB_POINTERS HobList\r | |
193 | )\r | |
95276127 | 194 | {\r |
195 | EFI_STATUS Status;\r | |
b6b98e91 | 196 | EFI_FV_FILE_INFO DxeCoreFileInfo;\r |
95276127 | 197 | EFI_PHYSICAL_ADDRESS DxeCoreAddress;\r |
198 | UINT64 DxeCoreSize;\r | |
199 | EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint;\r | |
95276127 | 200 | EFI_BOOT_MODE BootMode;\r |
b0d803fe | 201 | EFI_PEI_FILE_HANDLE FileHandle;\r |
b74350e9 | 202 | EFI_PEI_READ_ONLY_VARIABLE2_PPI *Variable;\r |
28efc722 | 203 | EFI_PEI_LOAD_FILE_PPI *LoadFile;\r |
204 | UINTN Instance;\r | |
205 | UINT32 AuthenticationState;\r | |
b74350e9 | 206 | UINTN DataSize;\r |
77215d10 | 207 | EFI_PEI_S3_RESUME2_PPI *S3Resume;\r |
28efc722 | 208 | EFI_PEI_RECOVERY_MODULE_PPI *PeiRecovery;\r |
708919be | 209 | EFI_MEMORY_TYPE_INFORMATION MemoryData[EfiMaxMemoryType + 1];\r |
95276127 | 210 | \r |
211 | //\r | |
212 | // if in S3 Resume, restore configure\r | |
213 | //\r | |
b98da1b1 | 214 | BootMode = GetBootModeHob ();\r |
95276127 | 215 | \r |
216 | if (BootMode == BOOT_ON_S3_RESUME) {\r | |
28efc722 | 217 | Status = PeiServicesLocatePpi (\r |
77215d10 | 218 | &gEfiPeiS3Resume2PpiGuid,\r |
28efc722 | 219 | 0,\r |
220 | NULL,\r | |
221 | (VOID **) &S3Resume\r | |
222 | );\r | |
37623a5c | 223 | if (EFI_ERROR (Status)) {\r |
224 | //\r | |
225 | // Report Status code that S3Resume PPI can not be found\r | |
226 | //\r | |
227 | REPORT_STATUS_CODE (\r | |
228 | EFI_ERROR_CODE | EFI_ERROR_MAJOR,\r | |
229 | (EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_EC_S3_RESUME_PPI_NOT_FOUND)\r | |
230 | );\r | |
231 | }\r | |
28efc722 | 232 | ASSERT_EFI_ERROR (Status);\r |
233 | \r | |
77215d10 | 234 | Status = S3Resume->S3RestoreConfig2 (S3Resume);\r |
95276127 | 235 | ASSERT_EFI_ERROR (Status);\r |
236 | } else if (BootMode == BOOT_IN_RECOVERY_MODE) {\r | |
37623a5c | 237 | REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_PC_RECOVERY_BEGIN));\r |
28efc722 | 238 | Status = PeiServicesLocatePpi (\r |
239 | &gEfiPeiRecoveryModulePpiGuid,\r | |
240 | 0,\r | |
241 | NULL,\r | |
242 | (VOID **) &PeiRecovery\r | |
243 | );\r | |
83d06ed9 | 244 | \r |
245 | if (EFI_ERROR (Status)) {\r | |
246 | DEBUG ((DEBUG_ERROR, "Locate Recovery PPI Failed.(Status = %r)\n", Status));\r | |
247 | //\r | |
248 | // Report Status code the failure of locating Recovery PPI \r | |
249 | //\r | |
250 | REPORT_STATUS_CODE (\r | |
251 | EFI_ERROR_CODE | EFI_ERROR_MAJOR,\r | |
252 | (EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_EC_RECOVERY_PPI_NOT_FOUND)\r | |
253 | );\r | |
254 | CpuDeadLoop ();\r | |
255 | }\r | |
256 | \r | |
37623a5c | 257 | REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_PC_CAPSULE_LOAD));\r |
28efc722 | 258 | Status = PeiRecovery->LoadRecoveryCapsule (PeiServices, PeiRecovery);\r |
95276127 | 259 | if (EFI_ERROR (Status)) {\r |
91d92e25 | 260 | DEBUG ((DEBUG_ERROR, "Load Recovery Capsule Failed.(Status = %r)\n", Status));\r |
37623a5c | 261 | //\r |
83d06ed9 | 262 | // Report Status code that recovery image can not be found\r |
37623a5c | 263 | //\r |
264 | REPORT_STATUS_CODE (\r | |
265 | EFI_ERROR_CODE | EFI_ERROR_MAJOR,\r | |
266 | (EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_EC_NO_RECOVERY_CAPSULE)\r | |
267 | );\r | |
95276127 | 268 | CpuDeadLoop ();\r |
269 | }\r | |
37623a5c | 270 | REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_PC_CAPSULE_START));\r |
95276127 | 271 | //\r |
48557c65 | 272 | // Now should have a HOB with the DXE core\r |
95276127 | 273 | //\r |
274 | }\r | |
288f9b38 | 275 | \r |
b74350e9 | 276 | Status = PeiServicesLocatePpi (\r |
277 | &gEfiPeiReadOnlyVariable2PpiGuid,\r | |
278 | 0,\r | |
279 | NULL,\r | |
280 | (VOID **)&Variable\r | |
281 | );\r | |
b74350e9 | 282 | if (!EFI_ERROR (Status)) {\r |
1ad76c34 | 283 | DataSize = sizeof (MemoryData);\r |
284 | Status = Variable->GetVariable ( \r | |
285 | Variable, \r | |
286 | EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME,\r | |
287 | &gEfiMemoryTypeInformationGuid,\r | |
288 | NULL,\r | |
289 | &DataSize,\r | |
290 | &MemoryData\r | |
291 | );\r | |
a95b6045 | 292 | if (!EFI_ERROR (Status) && ValidateMemoryTypeInfoVariable(MemoryData, DataSize)) {\r |
1ad76c34 | 293 | //\r |
294 | // Build the GUID'd HOB for DXE\r | |
295 | //\r | |
296 | BuildGuidDataHob (\r | |
297 | &gEfiMemoryTypeInformationGuid,\r | |
298 | MemoryData,\r | |
299 | DataSize\r | |
300 | );\r | |
301 | }\r | |
b74350e9 | 302 | }\r |
288f9b38 | 303 | \r |
95276127 | 304 | //\r |
b6b98e91 | 305 | // Look in all the FVs present in PEI and find the DXE Core FileHandle\r |
95276127 | 306 | //\r |
b6b98e91 | 307 | FileHandle = DxeIplFindDxeCore ();\r |
b0d803fe | 308 | \r |
95276127 | 309 | //\r |
28efc722 | 310 | // Load the DXE Core from a Firmware Volume.\r |
95276127 | 311 | //\r |
28efc722 | 312 | Instance = 0;\r |
313 | do {\r | |
314 | Status = PeiServicesLocatePpi (&gEfiPeiLoadFilePpiGuid, Instance++, NULL, (VOID **) &LoadFile);\r | |
315 | //\r | |
316 | // These must exist an instance of EFI_PEI_LOAD_FILE_PPI to support to load DxeCore file handle successfully.\r | |
317 | //\r | |
318 | ASSERT_EFI_ERROR (Status);\r | |
319 | \r | |
320 | Status = LoadFile->LoadFile (\r | |
321 | LoadFile,\r | |
322 | FileHandle,\r | |
323 | &DxeCoreAddress,\r | |
324 | &DxeCoreSize,\r | |
325 | &DxeCoreEntryPoint,\r | |
326 | &AuthenticationState\r | |
327 | );\r | |
328 | } while (EFI_ERROR (Status));\r | |
95276127 | 329 | \r |
b6b98e91 | 330 | //\r |
331 | // Get the DxeCore File Info from the FileHandle for the DxeCore GUID file name.\r | |
332 | //\r | |
333 | Status = PeiServicesFfsGetFileInfo (FileHandle, &DxeCoreFileInfo);\r | |
334 | ASSERT_EFI_ERROR (Status);\r | |
335 | \r | |
95276127 | 336 | //\r |
337 | // Add HOB for the DXE Core\r | |
338 | //\r | |
339 | BuildModuleHob (\r | |
b6b98e91 | 340 | &DxeCoreFileInfo.FileName,\r |
95276127 | 341 | DxeCoreAddress,\r |
48557c65 | 342 | ALIGN_VALUE (DxeCoreSize, EFI_PAGE_SIZE),\r |
95276127 | 343 | DxeCoreEntryPoint\r |
344 | );\r | |
345 | \r | |
346 | //\r | |
347 | // Report Status Code EFI_SW_PEI_PC_HANDOFF_TO_NEXT\r | |
348 | //\r | |
f9876ecf | 349 | REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_PEI_CORE | EFI_SW_PEI_CORE_PC_HANDOFF_TO_NEXT));\r |
95276127 | 350 | \r |
4e2dd553 | 351 | DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Loading DXE CORE at 0x%11p EntryPoint=0x%11p\n", (VOID *)(UINTN)DxeCoreAddress, FUNCTION_ENTRY_POINT (DxeCoreEntryPoint)));\r |
e98cd821 | 352 | \r |
95276127 | 353 | //\r |
354 | // Transfer control to the DXE Core\r | |
48557c65 | 355 | // The hand off state is simply a pointer to the HOB list\r |
95276127 | 356 | //\r |
9b937a73 | 357 | HandOffToDxeCore (DxeCoreEntryPoint, HobList);\r |
95276127 | 358 | //\r |
359 | // If we get here, then the DXE Core returned. This is an error\r | |
48557c65 | 360 | // DxeCore should not return.\r |
95276127 | 361 | //\r |
362 | ASSERT (FALSE);\r | |
363 | CpuDeadLoop ();\r | |
364 | \r | |
365 | return EFI_OUT_OF_RESOURCES;\r | |
366 | }\r | |
367 | \r | |
91d92e25 | 368 | \r |
b0d803fe | 369 | /**\r |
9b937a73 | 370 | Searches DxeCore in all firmware Volumes and loads the first\r |
371 | instance that contains DxeCore.\r | |
b0d803fe | 372 | \r |
9b937a73 | 373 | @return FileHandle of DxeCore to load DxeCore.\r |
374 | \r | |
91d92e25 | 375 | **/\r |
9b937a73 | 376 | EFI_PEI_FILE_HANDLE\r |
288f9b38 | 377 | DxeIplFindDxeCore (\r |
b6b98e91 | 378 | VOID\r |
b0d803fe | 379 | )\r |
95276127 | 380 | {\r |
9b937a73 | 381 | EFI_STATUS Status;\r |
382 | UINTN Instance;\r | |
383 | EFI_PEI_FV_HANDLE VolumeHandle;\r | |
384 | EFI_PEI_FILE_HANDLE FileHandle;\r | |
288f9b38 LG |
385 | \r |
386 | Instance = 0;\r | |
9b937a73 | 387 | while (TRUE) {\r |
388 | //\r | |
389 | // Traverse all firmware volume instances\r | |
390 | //\r | |
391 | Status = PeiServicesFfsFindNextVolume (Instance, &VolumeHandle);\r | |
392 | //\r | |
393 | // If some error occurs here, then we cannot find any firmware\r | |
394 | // volume that may contain DxeCore.\r | |
395 | //\r | |
3d0a2385 | 396 | if (EFI_ERROR (Status)) {\r |
397 | REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_CORE_EC_DXE_CORRUPT));\r | |
398 | }\r | |
9b937a73 | 399 | ASSERT_EFI_ERROR (Status);\r |
400 | \r | |
401 | //\r | |
402 | // Find the DxeCore file type from the beginning in this firmware volume.\r | |
403 | //\r | |
404 | FileHandle = NULL;\r | |
405 | Status = PeiServicesFfsFindNextFile (EFI_FV_FILETYPE_DXE_CORE, VolumeHandle, &FileHandle);\r | |
288f9b38 | 406 | if (!EFI_ERROR (Status)) {\r |
9b937a73 | 407 | //\r |
b6b98e91 | 408 | // Find DxeCore FileHandle in this volume, then we skip other firmware volume and\r |
409 | // return the FileHandle.\r | |
9b937a73 | 410 | //\r |
b6b98e91 | 411 | return FileHandle;\r |
95276127 | 412 | }\r |
9b937a73 | 413 | //\r |
414 | // We cannot find DxeCore in this firmware volume, then search the next volume.\r | |
415 | //\r | |
416 | Instance++;\r | |
417 | }\r | |
95276127 | 418 | }\r |
419 | \r | |
91d92e25 | 420 | \r |
91d92e25 | 421 | \r |
d8c79a81 LG |
422 | /**\r |
423 | The ExtractSection() function processes the input section and\r | |
424 | returns a pointer to the section contents. If the section being\r | |
425 | extracted does not require processing (if the section\r | |
426 | GuidedSectionHeader.Attributes has the\r | |
427 | EFI_GUIDED_SECTION_PROCESSING_REQUIRED field cleared), then\r | |
428 | OutputBuffer is just updated to point to the start of the\r | |
429 | section's contents. Otherwise, *Buffer must be allocated\r | |
430 | from PEI permanent memory.\r | |
431 | \r | |
432 | @param This Indicates the\r | |
433 | EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI instance.\r | |
434 | Buffer containing the input GUIDed section to be\r | |
435 | processed. OutputBuffer OutputBuffer is\r | |
436 | allocated from PEI permanent memory and contains\r | |
437 | the new section stream.\r | |
91d92e25 | 438 | @param InputSection A pointer to the input buffer, which contains\r |
439 | the input section to be processed.\r | |
440 | @param OutputBuffer A pointer to a caller-allocated buffer, whose\r | |
441 | size is specified by the contents of OutputSize.\r | |
d8c79a81 LG |
442 | @param OutputSize A pointer to a caller-allocated\r |
443 | UINTN in which the size of *OutputBuffer\r | |
444 | allocation is stored. If the function\r | |
445 | returns anything other than EFI_SUCCESS,\r | |
446 | the value of OutputSize is undefined.\r | |
d8c79a81 LG |
447 | @param AuthenticationStatus A pointer to a caller-allocated\r |
448 | UINT32 that indicates the\r | |
449 | authentication status of the\r | |
450 | output buffer. If the input\r | |
451 | section's GuidedSectionHeader.\r | |
452 | Attributes field has the\r | |
453 | EFI_GUIDED_SECTION_AUTH_STATUS_VALID \r | |
454 | bit as clear,\r | |
455 | AuthenticationStatus must return\r | |
456 | zero. These bits reflect the\r | |
457 | status of the extraction\r | |
458 | operation. If the function\r | |
459 | returns anything other than\r | |
460 | EFI_SUCCESS, the value of\r | |
461 | AuthenticationStatus is\r | |
462 | undefined.\r | |
463 | \r | |
464 | @retval EFI_SUCCESS The InputSection was\r | |
465 | successfully processed and the\r | |
466 | section contents were returned.\r | |
467 | \r | |
468 | @retval EFI_OUT_OF_RESOURCES The system has insufficient\r | |
469 | resources to process the request.\r | |
470 | \r | |
708919be | 471 | @retval EFI_INVALID_PARAMETER The GUID in InputSection does\r |
d8c79a81 LG |
472 | not match this instance of the\r |
473 | GUIDed Section Extraction PPI.\r | |
91d92e25 | 474 | \r |
d8c79a81 LG |
475 | **/\r |
476 | EFI_STATUS\r | |
6d3ea23f | 477 | EFIAPI\r |
18fd8d65 | 478 | CustomGuidedSectionExtract (\r |
d8c79a81 LG |
479 | IN CONST EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI *This,\r |
480 | IN CONST VOID *InputSection,\r | |
481 | OUT VOID **OutputBuffer,\r | |
482 | OUT UINTN *OutputSize,\r | |
483 | OUT UINT32 *AuthenticationStatus\r | |
484 | )\r | |
485 | {\r | |
486 | EFI_STATUS Status;\r | |
487 | UINT8 *ScratchBuffer;\r | |
18fd8d65 LG |
488 | UINT32 ScratchBufferSize;\r |
489 | UINT32 OutputBufferSize;\r | |
490 | UINT16 SectionAttribute;\r | |
d8c79a81 LG |
491 | \r |
492 | //\r | |
18fd8d65 | 493 | // Init local variable\r |
d8c79a81 | 494 | //\r |
18fd8d65 LG |
495 | ScratchBuffer = NULL;\r |
496 | \r | |
d8c79a81 | 497 | //\r |
18fd8d65 | 498 | // Call GetInfo to get the size and attribute of input guided section data.\r |
d8c79a81 | 499 | //\r |
18fd8d65 | 500 | Status = ExtractGuidedSectionGetInfo (\r |
b6b98e91 | 501 | InputSection,\r |
502 | &OutputBufferSize,\r | |
503 | &ScratchBufferSize,\r | |
504 | &SectionAttribute\r | |
505 | );\r | |
18fd8d65 | 506 | \r |
d8c79a81 | 507 | if (EFI_ERROR (Status)) {\r |
91d92e25 | 508 | DEBUG ((DEBUG_ERROR, "GetInfo from guided section Failed - %r\n", Status));\r |
18fd8d65 LG |
509 | return Status;\r |
510 | }\r | |
511 | \r | |
512 | if (ScratchBufferSize != 0) {\r | |
95276127 | 513 | //\r |
18fd8d65 | 514 | // Allocate scratch buffer\r |
95276127 | 515 | //\r |
18fd8d65 LG |
516 | ScratchBuffer = AllocatePages (EFI_SIZE_TO_PAGES (ScratchBufferSize));\r |
517 | if (ScratchBuffer == NULL) {\r | |
518 | return EFI_OUT_OF_RESOURCES;\r | |
519 | }\r | |
d8c79a81 | 520 | }\r |
95276127 | 521 | \r |
708919be | 522 | if (((SectionAttribute & EFI_GUIDED_SECTION_PROCESSING_REQUIRED) != 0) && OutputBufferSize > 0) { \r |
18fd8d65 LG |
523 | //\r |
524 | // Allocate output buffer\r | |
525 | //\r | |
288f9b38 | 526 | *OutputBuffer = AllocatePages (EFI_SIZE_TO_PAGES (OutputBufferSize) + 1);\r |
18fd8d65 LG |
527 | if (*OutputBuffer == NULL) {\r |
528 | return EFI_OUT_OF_RESOURCES;\r | |
529 | }\r | |
48557c65 | 530 | DEBUG ((DEBUG_INFO, "Customized Guided section Memory Size required is 0x%x and address is 0x%p\n", OutputBufferSize, *OutputBuffer));\r |
288f9b38 LG |
531 | //\r |
532 | // *OutputBuffer still is one section. Adjust *OutputBuffer offset, \r | |
533 | // skip EFI section header to make section data at page alignment.\r | |
534 | //\r | |
535 | *OutputBuffer = (VOID *)((UINT8 *) *OutputBuffer + EFI_PAGE_SIZE - sizeof (EFI_COMMON_SECTION_HEADER));\r | |
95276127 | 536 | }\r |
18fd8d65 LG |
537 | \r |
538 | Status = ExtractGuidedSectionDecode (\r | |
539 | InputSection, \r | |
540 | OutputBuffer,\r | |
541 | ScratchBuffer,\r | |
542 | AuthenticationStatus\r | |
48557c65 | 543 | );\r |
d8c79a81 LG |
544 | if (EFI_ERROR (Status)) {\r |
545 | //\r | |
18fd8d65 | 546 | // Decode failed\r |
d8c79a81 | 547 | //\r |
91d92e25 | 548 | DEBUG ((DEBUG_ERROR, "Extract guided section Failed - %r\n", Status));\r |
d8c79a81 LG |
549 | return Status;\r |
550 | }\r | |
551 | \r | |
18fd8d65 LG |
552 | *OutputSize = (UINTN) OutputBufferSize;\r |
553 | \r | |
95276127 | 554 | return EFI_SUCCESS;\r |
555 | }\r | |
b0d803fe | 556 | \r |
91d92e25 | 557 | \r |
558 | \r | |
559 | /**\r | |
560 | Decompresses a section to the output buffer.\r | |
561 | \r | |
48557c65 | 562 | This function looks up the compression type field in the input section and\r |
91d92e25 | 563 | applies the appropriate compression algorithm to compress the section to a\r |
564 | callee allocated buffer.\r | |
565 | \r | |
566 | @param This Points to this instance of the\r | |
567 | EFI_PEI_DECOMPRESS_PEI PPI.\r | |
568 | @param CompressionSection Points to the compressed section.\r | |
569 | @param OutputBuffer Holds the returned pointer to the decompressed\r | |
570 | sections.\r | |
571 | @param OutputSize Holds the returned size of the decompress\r | |
572 | section streams.\r | |
573 | \r | |
574 | @retval EFI_SUCCESS The section was decompressed successfully.\r | |
575 | OutputBuffer contains the resulting data and\r | |
576 | OutputSize contains the resulting size.\r | |
577 | \r | |
578 | **/\r | |
b0d803fe | 579 | EFI_STATUS\r |
580 | EFIAPI \r | |
581 | Decompress (\r | |
582 | IN CONST EFI_PEI_DECOMPRESS_PPI *This,\r | |
583 | IN CONST EFI_COMPRESSION_SECTION *CompressionSection,\r | |
584 | OUT VOID **OutputBuffer,\r | |
585 | OUT UINTN *OutputSize\r | |
586 | )\r | |
587 | {\r | |
588 | EFI_STATUS Status;\r | |
589 | UINT8 *DstBuffer;\r | |
590 | UINT8 *ScratchBuffer;\r | |
635021c5 | 591 | UINT32 DstBufferSize;\r |
b0d803fe | 592 | UINT32 ScratchBufferSize;\r |
890e5417 SZ |
593 | VOID *CompressionSource;\r |
594 | UINT32 CompressionSourceSize;\r | |
595 | UINT32 UncompressedLength;\r | |
596 | UINT8 CompressionType;\r | |
b0d803fe | 597 | \r |
598 | if (CompressionSection->CommonHeader.Type != EFI_SECTION_COMPRESSION) {\r | |
599 | ASSERT (FALSE);\r | |
600 | return EFI_INVALID_PARAMETER;\r | |
601 | }\r | |
602 | \r | |
890e5417 SZ |
603 | if (IS_SECTION2 (CompressionSection)) {\r |
604 | CompressionSource = (VOID *) ((UINT8 *) CompressionSection + sizeof (EFI_COMPRESSION_SECTION2));\r | |
605 | CompressionSourceSize = (UINT32) (SECTION2_SIZE (CompressionSection) - sizeof (EFI_COMPRESSION_SECTION2));\r | |
606 | UncompressedLength = ((EFI_COMPRESSION_SECTION2 *) CompressionSection)->UncompressedLength;\r | |
607 | CompressionType = ((EFI_COMPRESSION_SECTION2 *) CompressionSection)->CompressionType;\r | |
608 | } else {\r | |
609 | CompressionSource = (VOID *) ((UINT8 *) CompressionSection + sizeof (EFI_COMPRESSION_SECTION));\r | |
610 | CompressionSourceSize = (UINT32) (SECTION_SIZE (CompressionSection) - sizeof (EFI_COMPRESSION_SECTION));\r | |
611 | UncompressedLength = CompressionSection->UncompressedLength;\r | |
612 | CompressionType = CompressionSection->CompressionType;\r | |
613 | }\r | |
b0d803fe | 614 | \r |
615 | //\r | |
616 | // This is a compression set, expand it\r | |
617 | //\r | |
890e5417 | 618 | switch (CompressionType) {\r |
b0d803fe | 619 | case EFI_STANDARD_COMPRESSION:\r |
873b7997 | 620 | if (FeaturePcdGet(PcdDxeIplSupportUefiDecompress)) {\r |
b0d803fe | 621 | //\r |
873b7997 | 622 | // Load EFI standard compression.\r |
623 | // For compressed data, decompress them to destination buffer.\r | |
b0d803fe | 624 | //\r |
873b7997 | 625 | Status = UefiDecompressGetInfo (\r |
890e5417 SZ |
626 | CompressionSource,\r |
627 | CompressionSourceSize,\r | |
635021c5 | 628 | &DstBufferSize,\r |
873b7997 | 629 | &ScratchBufferSize\r |
630 | );\r | |
631 | if (EFI_ERROR (Status)) {\r | |
632 | //\r | |
633 | // GetInfo failed\r | |
634 | //\r | |
635 | DEBUG ((DEBUG_ERROR, "Decompress GetInfo Failed - %r\n", Status));\r | |
636 | return EFI_NOT_FOUND;\r | |
637 | }\r | |
638 | //\r | |
639 | // Allocate scratch buffer\r | |
b0d803fe | 640 | //\r |
873b7997 | 641 | ScratchBuffer = AllocatePages (EFI_SIZE_TO_PAGES (ScratchBufferSize));\r |
642 | if (ScratchBuffer == NULL) {\r | |
643 | return EFI_OUT_OF_RESOURCES;\r | |
644 | }\r | |
645 | //\r | |
646 | // Allocate destination buffer, extra one page for adjustment \r | |
647 | //\r | |
648 | DstBuffer = AllocatePages (EFI_SIZE_TO_PAGES (DstBufferSize) + 1);\r | |
649 | if (DstBuffer == NULL) {\r | |
650 | return EFI_OUT_OF_RESOURCES;\r | |
651 | }\r | |
b0d803fe | 652 | //\r |
873b7997 | 653 | // DstBuffer still is one section. Adjust DstBuffer offset, skip EFI section header\r |
654 | // to make section data at page alignment.\r | |
655 | //\r | |
656 | DstBuffer = DstBuffer + EFI_PAGE_SIZE - sizeof (EFI_COMMON_SECTION_HEADER);\r | |
657 | //\r | |
658 | // Call decompress function\r | |
659 | //\r | |
660 | Status = UefiDecompress (\r | |
890e5417 | 661 | CompressionSource,\r |
873b7997 | 662 | DstBuffer,\r |
663 | ScratchBuffer\r | |
664 | );\r | |
665 | if (EFI_ERROR (Status)) {\r | |
666 | //\r | |
667 | // Decompress failed\r | |
668 | //\r | |
669 | DEBUG ((DEBUG_ERROR, "Decompress Failed - %r\n", Status));\r | |
670 | return EFI_NOT_FOUND;\r | |
671 | }\r | |
672 | break;\r | |
673 | } else {\r | |
12b3e61e LG |
674 | //\r |
675 | // PcdDxeIplSupportUefiDecompress is FALSE\r | |
676 | // Don't support UEFI decompression algorithm.\r | |
677 | //\r | |
678 | ASSERT (FALSE);\r | |
b0d803fe | 679 | return EFI_NOT_FOUND;\r |
680 | }\r | |
b0d803fe | 681 | \r |
b0d803fe | 682 | case EFI_NOT_COMPRESSED:\r |
683 | //\r | |
684 | // Allocate destination buffer\r | |
685 | //\r | |
890e5417 | 686 | DstBufferSize = UncompressedLength;\r |
288f9b38 | 687 | DstBuffer = AllocatePages (EFI_SIZE_TO_PAGES (DstBufferSize) + 1);\r |
b0d803fe | 688 | if (DstBuffer == NULL) {\r |
689 | return EFI_OUT_OF_RESOURCES;\r | |
690 | }\r | |
691 | //\r | |
288f9b38 LG |
692 | // Adjust DstBuffer offset, skip EFI section header\r |
693 | // to make section data at page alignment.\r | |
694 | //\r | |
695 | DstBuffer = DstBuffer + EFI_PAGE_SIZE - sizeof (EFI_COMMON_SECTION_HEADER);\r | |
696 | //\r | |
b0d803fe | 697 | // stream is not actually compressed, just encapsulated. So just copy it.\r |
698 | //\r | |
890e5417 | 699 | CopyMem (DstBuffer, CompressionSource, DstBufferSize);\r |
b0d803fe | 700 | break;\r |
701 | \r | |
702 | default:\r | |
703 | //\r | |
704 | // Don't support other unknown compression type.\r | |
705 | //\r | |
706 | ASSERT (FALSE);\r | |
707 | return EFI_NOT_FOUND;\r | |
708 | }\r | |
709 | \r | |
710 | *OutputSize = DstBufferSize;\r | |
711 | *OutputBuffer = DstBuffer;\r | |
712 | \r | |
713 | return EFI_SUCCESS;\r | |
714 | }\r | |
715 | \r | |
91d92e25 | 716 | \r |
91d92e25 | 717 | /**\r |
718 | Updates the Stack HOB passed to DXE phase.\r | |
719 | \r | |
720 | This function traverses the whole HOB list and update the stack HOB to\r | |
721 | reflect the real stack that is used by DXE core.\r | |
722 | \r | |
723 | @param BaseAddress The lower address of stack used by DxeCore.\r | |
724 | @param Length The length of stack used by DxeCore.\r | |
725 | \r | |
726 | **/\r | |
30c8f861 | 727 | VOID\r |
728 | UpdateStackHob (\r | |
729 | IN EFI_PHYSICAL_ADDRESS BaseAddress,\r | |
730 | IN UINT64 Length\r | |
731 | )\r | |
732 | {\r | |
733 | EFI_PEI_HOB_POINTERS Hob;\r | |
734 | \r | |
735 | Hob.Raw = GetHobList ();\r | |
736 | while ((Hob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, Hob.Raw)) != NULL) {\r | |
737 | if (CompareGuid (&gEfiHobMemoryAllocStackGuid, &(Hob.MemoryAllocationStack->AllocDescriptor.Name))) {\r | |
738 | //\r | |
9a43bc39 | 739 | // Build a new memory allocation HOB with old stack info with EfiBootServicesData type. Need to \r |
740 | // avoid this region be reclaimed by DXE core as the IDT built in SEC might be on stack, and some \r | |
741 | // PEIMs may also keep key information on stack\r | |
30c8f861 | 742 | //\r |
743 | BuildMemoryAllocationHob (\r | |
744 | Hob.MemoryAllocationStack->AllocDescriptor.MemoryBaseAddress,\r | |
745 | Hob.MemoryAllocationStack->AllocDescriptor.MemoryLength,\r | |
9a43bc39 | 746 | EfiBootServicesData\r |
30c8f861 | 747 | );\r |
748 | //\r | |
749 | // Update the BSP Stack Hob to reflect the new stack info.\r | |
750 | //\r | |
751 | Hob.MemoryAllocationStack->AllocDescriptor.MemoryBaseAddress = BaseAddress;\r | |
752 | Hob.MemoryAllocationStack->AllocDescriptor.MemoryLength = Length;\r | |
753 | break;\r | |
754 | }\r | |
755 | Hob.Raw = GET_NEXT_HOB (Hob);\r | |
756 | }\r | |
757 | }\r |