]>
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 |
d1d89e86 LG |
276 | if (GetFirstGuidHob ((CONST EFI_GUID *)&gEfiMemoryTypeInformationGuid) == NULL) {\r |
277 | //\r | |
278 | // Don't build GuidHob if GuidHob has been installed.\r | |
279 | //\r | |
280 | Status = PeiServicesLocatePpi (\r | |
281 | &gEfiPeiReadOnlyVariable2PpiGuid,\r | |
282 | 0,\r | |
283 | NULL,\r | |
284 | (VOID **)&Variable\r | |
285 | );\r | |
286 | if (!EFI_ERROR (Status)) {\r | |
287 | DataSize = sizeof (MemoryData);\r | |
288 | Status = Variable->GetVariable ( \r | |
289 | Variable, \r | |
290 | EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME,\r | |
291 | &gEfiMemoryTypeInformationGuid,\r | |
292 | NULL,\r | |
293 | &DataSize,\r | |
294 | &MemoryData\r | |
295 | );\r | |
296 | if (!EFI_ERROR (Status) && ValidateMemoryTypeInfoVariable(MemoryData, DataSize)) {\r | |
297 | //\r | |
298 | // Build the GUID'd HOB for DXE\r | |
299 | //\r | |
300 | BuildGuidDataHob (\r | |
301 | &gEfiMemoryTypeInformationGuid,\r | |
302 | MemoryData,\r | |
303 | DataSize\r | |
304 | );\r | |
305 | }\r | |
1ad76c34 | 306 | }\r |
b74350e9 | 307 | }\r |
288f9b38 | 308 | \r |
95276127 | 309 | //\r |
b6b98e91 | 310 | // Look in all the FVs present in PEI and find the DXE Core FileHandle\r |
95276127 | 311 | //\r |
b6b98e91 | 312 | FileHandle = DxeIplFindDxeCore ();\r |
b0d803fe | 313 | \r |
95276127 | 314 | //\r |
28efc722 | 315 | // Load the DXE Core from a Firmware Volume.\r |
95276127 | 316 | //\r |
28efc722 | 317 | Instance = 0;\r |
318 | do {\r | |
319 | Status = PeiServicesLocatePpi (&gEfiPeiLoadFilePpiGuid, Instance++, NULL, (VOID **) &LoadFile);\r | |
320 | //\r | |
321 | // These must exist an instance of EFI_PEI_LOAD_FILE_PPI to support to load DxeCore file handle successfully.\r | |
322 | //\r | |
323 | ASSERT_EFI_ERROR (Status);\r | |
324 | \r | |
325 | Status = LoadFile->LoadFile (\r | |
326 | LoadFile,\r | |
327 | FileHandle,\r | |
328 | &DxeCoreAddress,\r | |
329 | &DxeCoreSize,\r | |
330 | &DxeCoreEntryPoint,\r | |
331 | &AuthenticationState\r | |
332 | );\r | |
333 | } while (EFI_ERROR (Status));\r | |
95276127 | 334 | \r |
b6b98e91 | 335 | //\r |
336 | // Get the DxeCore File Info from the FileHandle for the DxeCore GUID file name.\r | |
337 | //\r | |
338 | Status = PeiServicesFfsGetFileInfo (FileHandle, &DxeCoreFileInfo);\r | |
339 | ASSERT_EFI_ERROR (Status);\r | |
340 | \r | |
95276127 | 341 | //\r |
342 | // Add HOB for the DXE Core\r | |
343 | //\r | |
344 | BuildModuleHob (\r | |
b6b98e91 | 345 | &DxeCoreFileInfo.FileName,\r |
95276127 | 346 | DxeCoreAddress,\r |
48557c65 | 347 | ALIGN_VALUE (DxeCoreSize, EFI_PAGE_SIZE),\r |
95276127 | 348 | DxeCoreEntryPoint\r |
349 | );\r | |
350 | \r | |
351 | //\r | |
352 | // Report Status Code EFI_SW_PEI_PC_HANDOFF_TO_NEXT\r | |
353 | //\r | |
f9876ecf | 354 | REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_PEI_CORE | EFI_SW_PEI_CORE_PC_HANDOFF_TO_NEXT));\r |
95276127 | 355 | \r |
4e2dd553 | 356 | DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Loading DXE CORE at 0x%11p EntryPoint=0x%11p\n", (VOID *)(UINTN)DxeCoreAddress, FUNCTION_ENTRY_POINT (DxeCoreEntryPoint)));\r |
e98cd821 | 357 | \r |
95276127 | 358 | //\r |
359 | // Transfer control to the DXE Core\r | |
48557c65 | 360 | // The hand off state is simply a pointer to the HOB list\r |
95276127 | 361 | //\r |
9b937a73 | 362 | HandOffToDxeCore (DxeCoreEntryPoint, HobList);\r |
95276127 | 363 | //\r |
364 | // If we get here, then the DXE Core returned. This is an error\r | |
48557c65 | 365 | // DxeCore should not return.\r |
95276127 | 366 | //\r |
367 | ASSERT (FALSE);\r | |
368 | CpuDeadLoop ();\r | |
369 | \r | |
370 | return EFI_OUT_OF_RESOURCES;\r | |
371 | }\r | |
372 | \r | |
91d92e25 | 373 | \r |
b0d803fe | 374 | /**\r |
9b937a73 | 375 | Searches DxeCore in all firmware Volumes and loads the first\r |
376 | instance that contains DxeCore.\r | |
b0d803fe | 377 | \r |
9b937a73 | 378 | @return FileHandle of DxeCore to load DxeCore.\r |
379 | \r | |
91d92e25 | 380 | **/\r |
9b937a73 | 381 | EFI_PEI_FILE_HANDLE\r |
288f9b38 | 382 | DxeIplFindDxeCore (\r |
b6b98e91 | 383 | VOID\r |
b0d803fe | 384 | )\r |
95276127 | 385 | {\r |
9b937a73 | 386 | EFI_STATUS Status;\r |
387 | UINTN Instance;\r | |
388 | EFI_PEI_FV_HANDLE VolumeHandle;\r | |
389 | EFI_PEI_FILE_HANDLE FileHandle;\r | |
288f9b38 LG |
390 | \r |
391 | Instance = 0;\r | |
9b937a73 | 392 | while (TRUE) {\r |
393 | //\r | |
394 | // Traverse all firmware volume instances\r | |
395 | //\r | |
396 | Status = PeiServicesFfsFindNextVolume (Instance, &VolumeHandle);\r | |
397 | //\r | |
398 | // If some error occurs here, then we cannot find any firmware\r | |
399 | // volume that may contain DxeCore.\r | |
400 | //\r | |
3d0a2385 | 401 | if (EFI_ERROR (Status)) {\r |
402 | REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_CORE_EC_DXE_CORRUPT));\r | |
403 | }\r | |
9b937a73 | 404 | ASSERT_EFI_ERROR (Status);\r |
405 | \r | |
406 | //\r | |
407 | // Find the DxeCore file type from the beginning in this firmware volume.\r | |
408 | //\r | |
409 | FileHandle = NULL;\r | |
410 | Status = PeiServicesFfsFindNextFile (EFI_FV_FILETYPE_DXE_CORE, VolumeHandle, &FileHandle);\r | |
288f9b38 | 411 | if (!EFI_ERROR (Status)) {\r |
9b937a73 | 412 | //\r |
b6b98e91 | 413 | // Find DxeCore FileHandle in this volume, then we skip other firmware volume and\r |
414 | // return the FileHandle.\r | |
9b937a73 | 415 | //\r |
b6b98e91 | 416 | return FileHandle;\r |
95276127 | 417 | }\r |
9b937a73 | 418 | //\r |
419 | // We cannot find DxeCore in this firmware volume, then search the next volume.\r | |
420 | //\r | |
421 | Instance++;\r | |
422 | }\r | |
95276127 | 423 | }\r |
424 | \r | |
91d92e25 | 425 | \r |
91d92e25 | 426 | \r |
d8c79a81 LG |
427 | /**\r |
428 | The ExtractSection() function processes the input section and\r | |
429 | returns a pointer to the section contents. If the section being\r | |
430 | extracted does not require processing (if the section\r | |
431 | GuidedSectionHeader.Attributes has the\r | |
432 | EFI_GUIDED_SECTION_PROCESSING_REQUIRED field cleared), then\r | |
433 | OutputBuffer is just updated to point to the start of the\r | |
434 | section's contents. Otherwise, *Buffer must be allocated\r | |
435 | from PEI permanent memory.\r | |
436 | \r | |
437 | @param This Indicates the\r | |
438 | EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI instance.\r | |
439 | Buffer containing the input GUIDed section to be\r | |
440 | processed. OutputBuffer OutputBuffer is\r | |
441 | allocated from PEI permanent memory and contains\r | |
442 | the new section stream.\r | |
91d92e25 | 443 | @param InputSection A pointer to the input buffer, which contains\r |
444 | the input section to be processed.\r | |
445 | @param OutputBuffer A pointer to a caller-allocated buffer, whose\r | |
446 | size is specified by the contents of OutputSize.\r | |
d8c79a81 LG |
447 | @param OutputSize A pointer to a caller-allocated\r |
448 | UINTN in which the size of *OutputBuffer\r | |
449 | allocation is stored. If the function\r | |
450 | returns anything other than EFI_SUCCESS,\r | |
451 | the value of OutputSize is undefined.\r | |
d8c79a81 LG |
452 | @param AuthenticationStatus A pointer to a caller-allocated\r |
453 | UINT32 that indicates the\r | |
454 | authentication status of the\r | |
455 | output buffer. If the input\r | |
456 | section's GuidedSectionHeader.\r | |
457 | Attributes field has the\r | |
458 | EFI_GUIDED_SECTION_AUTH_STATUS_VALID \r | |
459 | bit as clear,\r | |
460 | AuthenticationStatus must return\r | |
461 | zero. These bits reflect the\r | |
462 | status of the extraction\r | |
463 | operation. If the function\r | |
464 | returns anything other than\r | |
465 | EFI_SUCCESS, the value of\r | |
466 | AuthenticationStatus is\r | |
467 | undefined.\r | |
468 | \r | |
469 | @retval EFI_SUCCESS The InputSection was\r | |
470 | successfully processed and the\r | |
471 | section contents were returned.\r | |
472 | \r | |
473 | @retval EFI_OUT_OF_RESOURCES The system has insufficient\r | |
474 | resources to process the request.\r | |
475 | \r | |
708919be | 476 | @retval EFI_INVALID_PARAMETER The GUID in InputSection does\r |
d8c79a81 LG |
477 | not match this instance of the\r |
478 | GUIDed Section Extraction PPI.\r | |
91d92e25 | 479 | \r |
d8c79a81 LG |
480 | **/\r |
481 | EFI_STATUS\r | |
6d3ea23f | 482 | EFIAPI\r |
18fd8d65 | 483 | CustomGuidedSectionExtract (\r |
d8c79a81 LG |
484 | IN CONST EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI *This,\r |
485 | IN CONST VOID *InputSection,\r | |
486 | OUT VOID **OutputBuffer,\r | |
487 | OUT UINTN *OutputSize,\r | |
488 | OUT UINT32 *AuthenticationStatus\r | |
489 | )\r | |
490 | {\r | |
491 | EFI_STATUS Status;\r | |
492 | UINT8 *ScratchBuffer;\r | |
18fd8d65 LG |
493 | UINT32 ScratchBufferSize;\r |
494 | UINT32 OutputBufferSize;\r | |
495 | UINT16 SectionAttribute;\r | |
d8c79a81 LG |
496 | \r |
497 | //\r | |
18fd8d65 | 498 | // Init local variable\r |
d8c79a81 | 499 | //\r |
18fd8d65 LG |
500 | ScratchBuffer = NULL;\r |
501 | \r | |
d8c79a81 | 502 | //\r |
18fd8d65 | 503 | // Call GetInfo to get the size and attribute of input guided section data.\r |
d8c79a81 | 504 | //\r |
18fd8d65 | 505 | Status = ExtractGuidedSectionGetInfo (\r |
b6b98e91 | 506 | InputSection,\r |
507 | &OutputBufferSize,\r | |
508 | &ScratchBufferSize,\r | |
509 | &SectionAttribute\r | |
510 | );\r | |
18fd8d65 | 511 | \r |
d8c79a81 | 512 | if (EFI_ERROR (Status)) {\r |
91d92e25 | 513 | DEBUG ((DEBUG_ERROR, "GetInfo from guided section Failed - %r\n", Status));\r |
18fd8d65 LG |
514 | return Status;\r |
515 | }\r | |
516 | \r | |
517 | if (ScratchBufferSize != 0) {\r | |
95276127 | 518 | //\r |
18fd8d65 | 519 | // Allocate scratch buffer\r |
95276127 | 520 | //\r |
18fd8d65 LG |
521 | ScratchBuffer = AllocatePages (EFI_SIZE_TO_PAGES (ScratchBufferSize));\r |
522 | if (ScratchBuffer == NULL) {\r | |
523 | return EFI_OUT_OF_RESOURCES;\r | |
524 | }\r | |
d8c79a81 | 525 | }\r |
95276127 | 526 | \r |
708919be | 527 | if (((SectionAttribute & EFI_GUIDED_SECTION_PROCESSING_REQUIRED) != 0) && OutputBufferSize > 0) { \r |
18fd8d65 LG |
528 | //\r |
529 | // Allocate output buffer\r | |
530 | //\r | |
288f9b38 | 531 | *OutputBuffer = AllocatePages (EFI_SIZE_TO_PAGES (OutputBufferSize) + 1);\r |
18fd8d65 LG |
532 | if (*OutputBuffer == NULL) {\r |
533 | return EFI_OUT_OF_RESOURCES;\r | |
534 | }\r | |
48557c65 | 535 | DEBUG ((DEBUG_INFO, "Customized Guided section Memory Size required is 0x%x and address is 0x%p\n", OutputBufferSize, *OutputBuffer));\r |
288f9b38 LG |
536 | //\r |
537 | // *OutputBuffer still is one section. Adjust *OutputBuffer offset, \r | |
538 | // skip EFI section header to make section data at page alignment.\r | |
539 | //\r | |
540 | *OutputBuffer = (VOID *)((UINT8 *) *OutputBuffer + EFI_PAGE_SIZE - sizeof (EFI_COMMON_SECTION_HEADER));\r | |
95276127 | 541 | }\r |
18fd8d65 LG |
542 | \r |
543 | Status = ExtractGuidedSectionDecode (\r | |
544 | InputSection, \r | |
545 | OutputBuffer,\r | |
546 | ScratchBuffer,\r | |
547 | AuthenticationStatus\r | |
48557c65 | 548 | );\r |
d8c79a81 LG |
549 | if (EFI_ERROR (Status)) {\r |
550 | //\r | |
18fd8d65 | 551 | // Decode failed\r |
d8c79a81 | 552 | //\r |
91d92e25 | 553 | DEBUG ((DEBUG_ERROR, "Extract guided section Failed - %r\n", Status));\r |
d8c79a81 LG |
554 | return Status;\r |
555 | }\r | |
556 | \r | |
18fd8d65 LG |
557 | *OutputSize = (UINTN) OutputBufferSize;\r |
558 | \r | |
95276127 | 559 | return EFI_SUCCESS;\r |
560 | }\r | |
b0d803fe | 561 | \r |
91d92e25 | 562 | \r |
563 | \r | |
564 | /**\r | |
565 | Decompresses a section to the output buffer.\r | |
566 | \r | |
48557c65 | 567 | This function looks up the compression type field in the input section and\r |
91d92e25 | 568 | applies the appropriate compression algorithm to compress the section to a\r |
569 | callee allocated buffer.\r | |
570 | \r | |
571 | @param This Points to this instance of the\r | |
572 | EFI_PEI_DECOMPRESS_PEI PPI.\r | |
573 | @param CompressionSection Points to the compressed section.\r | |
574 | @param OutputBuffer Holds the returned pointer to the decompressed\r | |
575 | sections.\r | |
576 | @param OutputSize Holds the returned size of the decompress\r | |
577 | section streams.\r | |
578 | \r | |
579 | @retval EFI_SUCCESS The section was decompressed successfully.\r | |
580 | OutputBuffer contains the resulting data and\r | |
581 | OutputSize contains the resulting size.\r | |
582 | \r | |
583 | **/\r | |
b0d803fe | 584 | EFI_STATUS\r |
585 | EFIAPI \r | |
586 | Decompress (\r | |
587 | IN CONST EFI_PEI_DECOMPRESS_PPI *This,\r | |
588 | IN CONST EFI_COMPRESSION_SECTION *CompressionSection,\r | |
589 | OUT VOID **OutputBuffer,\r | |
590 | OUT UINTN *OutputSize\r | |
591 | )\r | |
592 | {\r | |
593 | EFI_STATUS Status;\r | |
594 | UINT8 *DstBuffer;\r | |
595 | UINT8 *ScratchBuffer;\r | |
635021c5 | 596 | UINT32 DstBufferSize;\r |
b0d803fe | 597 | UINT32 ScratchBufferSize;\r |
890e5417 SZ |
598 | VOID *CompressionSource;\r |
599 | UINT32 CompressionSourceSize;\r | |
600 | UINT32 UncompressedLength;\r | |
601 | UINT8 CompressionType;\r | |
b0d803fe | 602 | \r |
603 | if (CompressionSection->CommonHeader.Type != EFI_SECTION_COMPRESSION) {\r | |
604 | ASSERT (FALSE);\r | |
605 | return EFI_INVALID_PARAMETER;\r | |
606 | }\r | |
607 | \r | |
890e5417 SZ |
608 | if (IS_SECTION2 (CompressionSection)) {\r |
609 | CompressionSource = (VOID *) ((UINT8 *) CompressionSection + sizeof (EFI_COMPRESSION_SECTION2));\r | |
610 | CompressionSourceSize = (UINT32) (SECTION2_SIZE (CompressionSection) - sizeof (EFI_COMPRESSION_SECTION2));\r | |
611 | UncompressedLength = ((EFI_COMPRESSION_SECTION2 *) CompressionSection)->UncompressedLength;\r | |
612 | CompressionType = ((EFI_COMPRESSION_SECTION2 *) CompressionSection)->CompressionType;\r | |
613 | } else {\r | |
614 | CompressionSource = (VOID *) ((UINT8 *) CompressionSection + sizeof (EFI_COMPRESSION_SECTION));\r | |
615 | CompressionSourceSize = (UINT32) (SECTION_SIZE (CompressionSection) - sizeof (EFI_COMPRESSION_SECTION));\r | |
616 | UncompressedLength = CompressionSection->UncompressedLength;\r | |
617 | CompressionType = CompressionSection->CompressionType;\r | |
618 | }\r | |
b0d803fe | 619 | \r |
620 | //\r | |
621 | // This is a compression set, expand it\r | |
622 | //\r | |
890e5417 | 623 | switch (CompressionType) {\r |
b0d803fe | 624 | case EFI_STANDARD_COMPRESSION:\r |
873b7997 | 625 | if (FeaturePcdGet(PcdDxeIplSupportUefiDecompress)) {\r |
b0d803fe | 626 | //\r |
873b7997 | 627 | // Load EFI standard compression.\r |
628 | // For compressed data, decompress them to destination buffer.\r | |
b0d803fe | 629 | //\r |
873b7997 | 630 | Status = UefiDecompressGetInfo (\r |
890e5417 SZ |
631 | CompressionSource,\r |
632 | CompressionSourceSize,\r | |
635021c5 | 633 | &DstBufferSize,\r |
873b7997 | 634 | &ScratchBufferSize\r |
635 | );\r | |
636 | if (EFI_ERROR (Status)) {\r | |
637 | //\r | |
638 | // GetInfo failed\r | |
639 | //\r | |
640 | DEBUG ((DEBUG_ERROR, "Decompress GetInfo Failed - %r\n", Status));\r | |
641 | return EFI_NOT_FOUND;\r | |
642 | }\r | |
643 | //\r | |
644 | // Allocate scratch buffer\r | |
b0d803fe | 645 | //\r |
873b7997 | 646 | ScratchBuffer = AllocatePages (EFI_SIZE_TO_PAGES (ScratchBufferSize));\r |
647 | if (ScratchBuffer == NULL) {\r | |
648 | return EFI_OUT_OF_RESOURCES;\r | |
649 | }\r | |
650 | //\r | |
651 | // Allocate destination buffer, extra one page for adjustment \r | |
652 | //\r | |
653 | DstBuffer = AllocatePages (EFI_SIZE_TO_PAGES (DstBufferSize) + 1);\r | |
654 | if (DstBuffer == NULL) {\r | |
655 | return EFI_OUT_OF_RESOURCES;\r | |
656 | }\r | |
b0d803fe | 657 | //\r |
873b7997 | 658 | // DstBuffer still is one section. Adjust DstBuffer offset, skip EFI section header\r |
659 | // to make section data at page alignment.\r | |
660 | //\r | |
661 | DstBuffer = DstBuffer + EFI_PAGE_SIZE - sizeof (EFI_COMMON_SECTION_HEADER);\r | |
662 | //\r | |
663 | // Call decompress function\r | |
664 | //\r | |
665 | Status = UefiDecompress (\r | |
890e5417 | 666 | CompressionSource,\r |
873b7997 | 667 | DstBuffer,\r |
668 | ScratchBuffer\r | |
669 | );\r | |
670 | if (EFI_ERROR (Status)) {\r | |
671 | //\r | |
672 | // Decompress failed\r | |
673 | //\r | |
674 | DEBUG ((DEBUG_ERROR, "Decompress Failed - %r\n", Status));\r | |
675 | return EFI_NOT_FOUND;\r | |
676 | }\r | |
677 | break;\r | |
678 | } else {\r | |
12b3e61e LG |
679 | //\r |
680 | // PcdDxeIplSupportUefiDecompress is FALSE\r | |
681 | // Don't support UEFI decompression algorithm.\r | |
682 | //\r | |
683 | ASSERT (FALSE);\r | |
b0d803fe | 684 | return EFI_NOT_FOUND;\r |
685 | }\r | |
b0d803fe | 686 | \r |
b0d803fe | 687 | case EFI_NOT_COMPRESSED:\r |
688 | //\r | |
689 | // Allocate destination buffer\r | |
690 | //\r | |
890e5417 | 691 | DstBufferSize = UncompressedLength;\r |
288f9b38 | 692 | DstBuffer = AllocatePages (EFI_SIZE_TO_PAGES (DstBufferSize) + 1);\r |
b0d803fe | 693 | if (DstBuffer == NULL) {\r |
694 | return EFI_OUT_OF_RESOURCES;\r | |
695 | }\r | |
696 | //\r | |
288f9b38 LG |
697 | // Adjust DstBuffer offset, skip EFI section header\r |
698 | // to make section data at page alignment.\r | |
699 | //\r | |
700 | DstBuffer = DstBuffer + EFI_PAGE_SIZE - sizeof (EFI_COMMON_SECTION_HEADER);\r | |
701 | //\r | |
b0d803fe | 702 | // stream is not actually compressed, just encapsulated. So just copy it.\r |
703 | //\r | |
890e5417 | 704 | CopyMem (DstBuffer, CompressionSource, DstBufferSize);\r |
b0d803fe | 705 | break;\r |
706 | \r | |
707 | default:\r | |
708 | //\r | |
709 | // Don't support other unknown compression type.\r | |
710 | //\r | |
711 | ASSERT (FALSE);\r | |
712 | return EFI_NOT_FOUND;\r | |
713 | }\r | |
714 | \r | |
715 | *OutputSize = DstBufferSize;\r | |
716 | *OutputBuffer = DstBuffer;\r | |
717 | \r | |
718 | return EFI_SUCCESS;\r | |
719 | }\r | |
720 | \r | |
91d92e25 | 721 | \r |
91d92e25 | 722 | /**\r |
723 | Updates the Stack HOB passed to DXE phase.\r | |
724 | \r | |
725 | This function traverses the whole HOB list and update the stack HOB to\r | |
726 | reflect the real stack that is used by DXE core.\r | |
727 | \r | |
728 | @param BaseAddress The lower address of stack used by DxeCore.\r | |
729 | @param Length The length of stack used by DxeCore.\r | |
730 | \r | |
731 | **/\r | |
30c8f861 | 732 | VOID\r |
733 | UpdateStackHob (\r | |
734 | IN EFI_PHYSICAL_ADDRESS BaseAddress,\r | |
735 | IN UINT64 Length\r | |
736 | )\r | |
737 | {\r | |
738 | EFI_PEI_HOB_POINTERS Hob;\r | |
739 | \r | |
740 | Hob.Raw = GetHobList ();\r | |
741 | while ((Hob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, Hob.Raw)) != NULL) {\r | |
742 | if (CompareGuid (&gEfiHobMemoryAllocStackGuid, &(Hob.MemoryAllocationStack->AllocDescriptor.Name))) {\r | |
743 | //\r | |
9a43bc39 | 744 | // Build a new memory allocation HOB with old stack info with EfiBootServicesData type. Need to \r |
745 | // avoid this region be reclaimed by DXE core as the IDT built in SEC might be on stack, and some \r | |
746 | // PEIMs may also keep key information on stack\r | |
30c8f861 | 747 | //\r |
748 | BuildMemoryAllocationHob (\r | |
749 | Hob.MemoryAllocationStack->AllocDescriptor.MemoryBaseAddress,\r | |
750 | Hob.MemoryAllocationStack->AllocDescriptor.MemoryLength,\r | |
9a43bc39 | 751 | EfiBootServicesData\r |
30c8f861 | 752 | );\r |
753 | //\r | |
754 | // Update the BSP Stack Hob to reflect the new stack info.\r | |
755 | //\r | |
756 | Hob.MemoryAllocationStack->AllocDescriptor.MemoryBaseAddress = BaseAddress;\r | |
757 | Hob.MemoryAllocationStack->AllocDescriptor.MemoryLength = Length;\r | |
758 | break;\r | |
759 | }\r | |
760 | Hob.Raw = GET_NEXT_HOB (Hob);\r | |
761 | }\r | |
762 | }\r |