]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/PeiServicesLib/PeiServicesLib.c
MdePkg: Clean up source files
[mirror_edk2.git] / MdePkg / Library / PeiServicesLib / PeiServicesLib.c
1 /** @file
2 Implementation for PEI Services Library.
3
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php.
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15
16 #include <PiPei.h>
17
18 #include <Ppi/FirmwareVolumeInfo.h>
19 #include <Ppi/FirmwareVolumeInfo2.h>
20 #include <Guid/FirmwareFileSystem2.h>
21
22 #include <Library/PeiServicesLib.h>
23 #include <Library/PeiServicesTablePointerLib.h>
24 #include <Library/DebugLib.h>
25 #include <Library/MemoryAllocationLib.h>
26 #include <Library/BaseMemoryLib.h>
27
28 /**
29 This service enables a given PEIM to register an interface into the PEI Foundation.
30
31 @param PpiList A pointer to the list of interfaces that the caller shall install.
32
33 @retval EFI_SUCCESS The interface was successfully installed.
34 @retval EFI_INVALID_PARAMETER The PpiList pointer is NULL.
35 @retval EFI_INVALID_PARAMETER Any of the PEI PPI descriptors in the list do not have the
36 EFI_PEI_PPI_DESCRIPTOR_PPI bit set in the Flags field.
37 @retval EFI_OUT_OF_RESOURCES There is no additional space in the PPI database.
38
39 **/
40 EFI_STATUS
41 EFIAPI
42 PeiServicesInstallPpi (
43 IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList
44 )
45 {
46 CONST EFI_PEI_SERVICES **PeiServices;
47
48 PeiServices = GetPeiServicesTablePointer ();
49 return (*PeiServices)->InstallPpi (PeiServices, PpiList);
50 }
51
52 /**
53 This service enables PEIMs to replace an entry in the PPI database with an alternate entry.
54
55 @param OldPpi The pointer to the old PEI PPI Descriptors.
56 @param NewPpi The pointer to the new PEI PPI Descriptors.
57
58 @retval EFI_SUCCESS The interface was successfully installed.
59 @retval EFI_INVALID_PARAMETER The OldPpi or NewPpi is NULL.
60 @retval EFI_INVALID_PARAMETER Any of the PEI PPI descriptors in the list do not have the
61 EFI_PEI_PPI_DESCRIPTOR_PPI bit set in the Flags field.
62 @retval EFI_OUT_OF_RESOURCES There is no additional space in the PPI database.
63 @retval EFI_NOT_FOUND The PPI for which the reinstallation was requested has not been
64 installed.
65
66 **/
67 EFI_STATUS
68 EFIAPI
69 PeiServicesReInstallPpi (
70 IN CONST EFI_PEI_PPI_DESCRIPTOR *OldPpi,
71 IN CONST EFI_PEI_PPI_DESCRIPTOR *NewPpi
72 )
73 {
74 CONST EFI_PEI_SERVICES **PeiServices;
75
76 PeiServices = GetPeiServicesTablePointer ();
77 return (*PeiServices)->ReInstallPpi (PeiServices, OldPpi, NewPpi);
78 }
79
80 /**
81 This service enables PEIMs to discover a given instance of an interface.
82
83 @param Guid A pointer to the GUID whose corresponding interface needs to be
84 found.
85 @param Instance The N-th instance of the interface that is required.
86 @param PpiDescriptor A pointer to instance of the EFI_PEI_PPI_DESCRIPTOR.
87 @param Ppi A pointer to the instance of the interface.
88
89 @retval EFI_SUCCESS The interface was successfully returned.
90 @retval EFI_NOT_FOUND The PPI descriptor is not found in the database.
91
92 **/
93 EFI_STATUS
94 EFIAPI
95 PeiServicesLocatePpi (
96 IN CONST EFI_GUID *Guid,
97 IN UINTN Instance,
98 IN OUT EFI_PEI_PPI_DESCRIPTOR **PpiDescriptor, OPTIONAL
99 IN OUT VOID **Ppi
100 )
101 {
102 CONST EFI_PEI_SERVICES **PeiServices;
103
104 PeiServices = GetPeiServicesTablePointer ();
105 return (*PeiServices)->LocatePpi (PeiServices, Guid, Instance, PpiDescriptor, Ppi);
106 }
107
108 /**
109 This service enables PEIMs to register a given service to be invoked when another service is
110 installed or reinstalled.
111
112 @param NotifyList A pointer to the list of notification interfaces
113 that the caller shall install.
114
115 @retval EFI_SUCCESS The interface was successfully installed.
116 @retval EFI_INVALID_PARAMETER The NotifyList pointer is NULL.
117 @retval EFI_INVALID_PARAMETER Any of the PEI notify descriptors in the list do
118 not have the EFI_PEI_PPI_DESCRIPTOR_NOTIFY_TYPES
119 bit set in the Flags field.
120 @retval EFI_OUT_OF_RESOURCES There is no additional space in the PPI database.
121
122 **/
123 EFI_STATUS
124 EFIAPI
125 PeiServicesNotifyPpi (
126 IN CONST EFI_PEI_NOTIFY_DESCRIPTOR *NotifyList
127 )
128 {
129 CONST EFI_PEI_SERVICES **PeiServices;
130
131 PeiServices = GetPeiServicesTablePointer ();
132 return (*PeiServices)->NotifyPpi (PeiServices, NotifyList);
133 }
134
135 /**
136 This service enables PEIMs to ascertain the present value of the boot mode.
137
138 @param BootMode A pointer to contain the value of the boot mode.
139
140 @retval EFI_SUCCESS The boot mode was returned successfully.
141 @retval EFI_INVALID_PARAMETER BootMode is NULL.
142
143 **/
144 EFI_STATUS
145 EFIAPI
146 PeiServicesGetBootMode (
147 OUT EFI_BOOT_MODE *BootMode
148 )
149 {
150 CONST EFI_PEI_SERVICES **PeiServices;
151
152 PeiServices = GetPeiServicesTablePointer ();
153 return (*PeiServices)->GetBootMode (PeiServices, BootMode);
154 }
155
156 /**
157 This service enables PEIMs to update the boot mode variable.
158
159 @param BootMode The value of the boot mode to set.
160
161 @retval EFI_SUCCESS The value was successfully updated
162
163 **/
164 EFI_STATUS
165 EFIAPI
166 PeiServicesSetBootMode (
167 IN EFI_BOOT_MODE BootMode
168 )
169 {
170 CONST EFI_PEI_SERVICES **PeiServices;
171
172 PeiServices = GetPeiServicesTablePointer ();
173 return (*PeiServices)->SetBootMode (PeiServices, BootMode);
174 }
175
176 /**
177 This service enables a PEIM to ascertain the address of the list of HOBs in memory.
178
179 @param HobList A pointer to the list of HOBs that the PEI Foundation
180 will initialize.
181
182 @retval EFI_SUCCESS The list was successfully returned.
183 @retval EFI_NOT_AVAILABLE_YET The HOB list is not yet published.
184
185 **/
186 EFI_STATUS
187 EFIAPI
188 PeiServicesGetHobList (
189 OUT VOID **HobList
190 )
191 {
192 CONST EFI_PEI_SERVICES **PeiServices;
193
194 PeiServices = GetPeiServicesTablePointer ();
195 return (*PeiServices)->GetHobList (PeiServices, HobList);
196 }
197
198 /**
199 This service enables PEIMs to create various types of HOBs.
200
201 @param Type The type of HOB to be installed.
202 @param Length The length of the HOB to be added.
203 @param Hob The address of a pointer that will contain the
204 HOB header.
205
206 @retval EFI_SUCCESS The HOB was successfully created.
207 @retval EFI_OUT_OF_RESOURCES There is no additional space for HOB creation.
208
209 **/
210 EFI_STATUS
211 EFIAPI
212 PeiServicesCreateHob (
213 IN UINT16 Type,
214 IN UINT16 Length,
215 OUT VOID **Hob
216 )
217 {
218 CONST EFI_PEI_SERVICES **PeiServices;
219
220 PeiServices = GetPeiServicesTablePointer ();
221 return (*PeiServices)->CreateHob (PeiServices, Type, Length, Hob);
222 }
223
224 /**
225 This service enables PEIMs to discover additional firmware volumes.
226
227 @param Instance This instance of the firmware volume to find. The
228 value 0 is the Boot Firmware Volume (BFV).
229 @param VolumeHandle Handle of the firmware volume header of the volume
230 to return.
231
232 @retval EFI_SUCCESS The volume was found.
233 @retval EFI_NOT_FOUND The volume was not found.
234 @retval EFI_INVALID_PARAMETER FwVolHeader is NULL.
235
236 **/
237 EFI_STATUS
238 EFIAPI
239 PeiServicesFfsFindNextVolume (
240 IN UINTN Instance,
241 IN OUT EFI_PEI_FV_HANDLE *VolumeHandle
242 )
243 {
244 CONST EFI_PEI_SERVICES **PeiServices;
245
246 PeiServices = GetPeiServicesTablePointer ();
247 return (*PeiServices)->FfsFindNextVolume (PeiServices, Instance, VolumeHandle);
248 }
249
250 /**
251 This service enables PEIMs to discover additional firmware files.
252
253 @param SearchType A filter to find files only of this type.
254 @param VolumeHandle The pointer to the firmware volume header of the
255 volume to search. This parameter must point to a
256 valid FFS volume.
257 @param FileHandle Handle of the current file from which to begin searching.
258
259 @retval EFI_SUCCESS The file was found.
260 @retval EFI_NOT_FOUND The file was not found.
261 @retval EFI_NOT_FOUND The header checksum was not zero.
262
263 **/
264 EFI_STATUS
265 EFIAPI
266 PeiServicesFfsFindNextFile (
267 IN EFI_FV_FILETYPE SearchType,
268 IN EFI_PEI_FV_HANDLE VolumeHandle,
269 IN OUT EFI_PEI_FILE_HANDLE *FileHandle
270 )
271 {
272 CONST EFI_PEI_SERVICES **PeiServices;
273
274 PeiServices = GetPeiServicesTablePointer ();
275 return (*PeiServices)->FfsFindNextFile (PeiServices, SearchType, VolumeHandle, FileHandle);
276 }
277
278 /**
279 This service enables PEIMs to discover sections of a given type within a valid FFS file.
280
281 @param SectionType The value of the section type to find.
282 @param FileHandle A pointer to the file header that contains the set
283 of sections to be searched.
284 @param SectionData A pointer to the discovered section, if successful.
285
286 @retval EFI_SUCCESS The section was found.
287 @retval EFI_NOT_FOUND The section was not found.
288
289 **/
290 EFI_STATUS
291 EFIAPI
292 PeiServicesFfsFindSectionData (
293 IN EFI_SECTION_TYPE SectionType,
294 IN EFI_PEI_FILE_HANDLE FileHandle,
295 OUT VOID **SectionData
296 )
297 {
298 CONST EFI_PEI_SERVICES **PeiServices;
299
300 PeiServices = GetPeiServicesTablePointer ();
301 return (*PeiServices)->FfsFindSectionData (PeiServices, SectionType, FileHandle, SectionData);
302 }
303
304 /**
305 This service enables PEIMs to discover sections of a given instance and type within a valid FFS file.
306
307 @param SectionType The value of the section type to find.
308 @param SectionInstance Section instance to find.
309 @param FileHandle A pointer to the file header that contains the set
310 of sections to be searched.
311 @param SectionData A pointer to the discovered section, if successful.
312 @param AuthenticationStatus A pointer to the authentication status for this section.
313
314 @retval EFI_SUCCESS The section was found.
315 @retval EFI_NOT_FOUND The section was not found.
316
317 **/
318 EFI_STATUS
319 EFIAPI
320 PeiServicesFfsFindSectionData3 (
321 IN EFI_SECTION_TYPE SectionType,
322 IN UINTN SectionInstance,
323 IN EFI_PEI_FILE_HANDLE FileHandle,
324 OUT VOID **SectionData,
325 OUT UINT32 *AuthenticationStatus
326 )
327 {
328 CONST EFI_PEI_SERVICES **PeiServices;
329
330 PeiServices = GetPeiServicesTablePointer ();
331 return (*PeiServices)->FindSectionData3 (PeiServices, SectionType, SectionInstance, FileHandle, SectionData, AuthenticationStatus);
332 }
333
334 /**
335 This service enables PEIMs to register the permanent memory configuration
336 that has been initialized with the PEI Foundation.
337
338 @param MemoryBegin The value of a region of installed memory.
339 @param MemoryLength The corresponding length of a region of installed memory.
340
341 @retval EFI_SUCCESS The region was successfully installed in a HOB.
342 @retval EFI_INVALID_PARAMETER MemoryBegin and MemoryLength are illegal for this system.
343 @retval EFI_OUT_OF_RESOURCES There is no additional space for HOB creation.
344
345 **/
346 EFI_STATUS
347 EFIAPI
348 PeiServicesInstallPeiMemory (
349 IN EFI_PHYSICAL_ADDRESS MemoryBegin,
350 IN UINT64 MemoryLength
351 )
352 {
353 CONST EFI_PEI_SERVICES **PeiServices;
354
355 PeiServices = GetPeiServicesTablePointer ();
356 return (*PeiServices)->InstallPeiMemory (PeiServices, MemoryBegin, MemoryLength);
357 }
358
359 /**
360 This service enables PEIMs to allocate memory.
361
362 @param MemoryType Type of memory to allocate.
363 @param Pages The number of pages to allocate.
364 @param Memory Pointer of memory allocated.
365
366 @retval EFI_SUCCESS The memory range was successfully allocated.
367 @retval EFI_INVALID_PARAMETER Type is not equal to EfiLoaderCode, EfiLoaderData, EfiRuntimeServicesCode,
368 EfiRuntimeServicesData, EfiBootServicesCode, EfiBootServicesData,
369 EfiACPIReclaimMemory, EfiReservedMemoryType, or EfiACPIMemoryNVS.
370 @retval EFI_OUT_OF_RESOURCES The pages could not be allocated.
371
372 **/
373 EFI_STATUS
374 EFIAPI
375 PeiServicesAllocatePages (
376 IN EFI_MEMORY_TYPE MemoryType,
377 IN UINTN Pages,
378 OUT EFI_PHYSICAL_ADDRESS *Memory
379 )
380 {
381 CONST EFI_PEI_SERVICES **PeiServices;
382
383 PeiServices = GetPeiServicesTablePointer ();
384 return (*PeiServices)->AllocatePages (PeiServices, MemoryType, Pages, Memory);
385 }
386
387 /**
388 This service enables PEIMs to free memory.
389
390 @param Memory Memory to be freed.
391 @param Pages The number of pages to free.
392
393 @retval EFI_SUCCESS The requested pages were freed.
394 @retval EFI_INVALID_PARAMETER Memory is not a page-aligned address or Pages is invalid.
395 @retval EFI_NOT_FOUND The requested memory pages were not allocated with
396 AllocatePages().
397
398 **/
399 EFI_STATUS
400 EFIAPI
401 PeiServicesFreePages (
402 IN EFI_PHYSICAL_ADDRESS Memory,
403 IN UINTN Pages
404 )
405 {
406 CONST EFI_PEI_SERVICES **PeiServices;
407
408 PeiServices = GetPeiServicesTablePointer ();
409 return (*PeiServices)->FreePages (PeiServices, Memory, Pages);
410 }
411
412 /**
413 This service allocates memory from the Hand-Off Block (HOB) heap.
414
415 @param Size The number of bytes to allocate from the pool.
416 @param Buffer If the call succeeds, a pointer to a pointer to
417 the allocate buffer; otherwise, undefined.
418
419 @retval EFI_SUCCESS The allocation was successful
420 @retval EFI_OUT_OF_RESOURCES There is not enough heap to allocate the requested size.
421
422 **/
423 EFI_STATUS
424 EFIAPI
425 PeiServicesAllocatePool (
426 IN UINTN Size,
427 OUT VOID **Buffer
428 )
429 {
430 CONST EFI_PEI_SERVICES **PeiServices;
431
432 PeiServices = GetPeiServicesTablePointer ();
433 return (*PeiServices)->AllocatePool (PeiServices, Size, Buffer);
434 }
435
436 /**
437 Resets the entire platform.
438
439 @retval EFI_SUCCESS The function completed successfully.
440 @retval EFI_NOT_AVAILABLE_YET The service has not been installed yet.
441
442 **/
443 EFI_STATUS
444 EFIAPI
445 PeiServicesResetSystem (
446 VOID
447 )
448 {
449 CONST EFI_PEI_SERVICES **PeiServices;
450
451 PeiServices = GetPeiServicesTablePointer ();
452 return (*PeiServices)->ResetSystem (PeiServices);
453 }
454
455 /**
456 This service is a wrapper for the PEI Service RegisterForShadow(), except the
457 pointer to the PEI Services Table has been removed. See the Platform
458 Initialization Pre-EFI Initialization Core Interface Specification for details.
459
460 @param FileHandle PEIM's file handle. Must be the currently
461 executing PEIM.
462
463 @retval EFI_SUCCESS The PEIM was successfully registered for
464 shadowing.
465
466 @retval EFI_ALREADY_STARTED The PEIM was previously
467 registered for shadowing.
468
469 @retval EFI_NOT_FOUND The FileHandle does not refer to a
470 valid file handle.
471 **/
472 EFI_STATUS
473 EFIAPI
474 PeiServicesRegisterForShadow (
475 IN EFI_PEI_FILE_HANDLE FileHandle
476 )
477 {
478 return (*GetPeiServicesTablePointer())->RegisterForShadow (FileHandle);
479 }
480
481 /**
482 This service is a wrapper for the PEI Service FfsGetFileInfo(), except the pointer to the PEI Services
483 Table has been removed. See the Platform Initialization Pre-EFI Initialization Core Interface
484 Specification for details.
485
486 @param FileHandle The handle of the file.
487
488 @param FileInfo Upon exit, points to the file's
489 information.
490
491 @retval EFI_SUCCESS File information returned.
492
493 @retval EFI_INVALID_PARAMETER If FileHandle does not
494 represent a valid file.
495
496 @retval EFI_INVALID_PARAMETER FileInfo is NULL.
497
498 **/
499 EFI_STATUS
500 EFIAPI
501 PeiServicesFfsGetFileInfo (
502 IN CONST EFI_PEI_FILE_HANDLE FileHandle,
503 OUT EFI_FV_FILE_INFO *FileInfo
504 )
505 {
506 return (*GetPeiServicesTablePointer())->FfsGetFileInfo (FileHandle, FileInfo);
507 }
508
509 /**
510 This service is a wrapper for the PEI Service FfsGetFileInfo2(), except the pointer to the PEI Services
511 Table has been removed. See the Platform Initialization Pre-EFI Initialization Core Interface
512 Specification for details.
513
514 @param FileHandle The handle of the file.
515 @param FileInfo Upon exit, points to the file's
516 information.
517
518 @retval EFI_SUCCESS File information returned.
519 @retval EFI_INVALID_PARAMETER If FileHandle does not
520 represent a valid file.
521 @retval EFI_INVALID_PARAMETER FileInfo is NULL.
522
523 **/
524 EFI_STATUS
525 EFIAPI
526 PeiServicesFfsGetFileInfo2 (
527 IN CONST EFI_PEI_FILE_HANDLE FileHandle,
528 OUT EFI_FV_FILE_INFO2 *FileInfo
529 )
530 {
531 return (*GetPeiServicesTablePointer())->FfsGetFileInfo2 (FileHandle, FileInfo);
532 }
533
534 /**
535 This service is a wrapper for the PEI Service FfsFindByName(), except the pointer to the PEI Services
536 Table has been removed. See the Platform Initialization Pre-EFI Initialization Core Interface
537 Specification for details.
538
539 @param FileName A pointer to the name of the file to
540 find within the firmware volume.
541
542 @param VolumeHandle The firmware volume to search FileHandle
543 Upon exit, points to the found file's
544 handle or NULL if it could not be found.
545 @param FileHandle The pointer to found file handle
546
547 @retval EFI_SUCCESS File was found.
548
549 @retval EFI_NOT_FOUND File was not found.
550
551 @retval EFI_INVALID_PARAMETER VolumeHandle or FileHandle or
552 FileName was NULL.
553
554 **/
555 EFI_STATUS
556 EFIAPI
557 PeiServicesFfsFindFileByName (
558 IN CONST EFI_GUID *FileName,
559 IN CONST EFI_PEI_FV_HANDLE VolumeHandle,
560 OUT EFI_PEI_FILE_HANDLE *FileHandle
561 )
562 {
563 return (*GetPeiServicesTablePointer())->FfsFindFileByName (FileName, VolumeHandle, FileHandle);
564 }
565
566
567 /**
568 This service is a wrapper for the PEI Service FfsGetVolumeInfo(), except the pointer to the PEI Services
569 Table has been removed. See the Platform Initialization Pre-EFI Initialization Core Interface
570 Specification for details.
571
572 @param VolumeHandle Handle of the volume.
573
574 @param VolumeInfo Upon exit, points to the volume's
575 information.
576
577 @retval EFI_SUCCESS File information returned.
578
579 @retval EFI_INVALID_PARAMETER If FileHandle does not
580 represent a valid file.
581
582 @retval EFI_INVALID_PARAMETER If FileInfo is NULL.
583
584 **/
585 EFI_STATUS
586 EFIAPI
587 PeiServicesFfsGetVolumeInfo (
588 IN EFI_PEI_FV_HANDLE VolumeHandle,
589 OUT EFI_FV_INFO *VolumeInfo
590 )
591 {
592 return (*GetPeiServicesTablePointer())->FfsGetVolumeInfo (VolumeHandle, VolumeInfo);
593 }
594
595 /**
596 Install a EFI_PEI_FIRMWARE_VOLUME_INFO(2)_PPI instance so the PEI Core will be notified about a new firmware volume.
597
598 This function allocates, initializes, and installs a new EFI_PEI_FIRMWARE_VOLUME_INFO(2)_PPI using
599 the parameters passed in to initialize the fields of the EFI_PEI_FIRMWARE_VOLUME_INFO(2)_PPI instance.
600 If the resources can not be allocated for EFI_PEI_FIRMWARE_VOLUME_INFO(2)_PPI, then ASSERT().
601 If the EFI_PEI_FIRMWARE_VOLUME_INFO(2)_PPI can not be installed, then ASSERT().
602 If NULL is specified for FvFormat, but FvInfo does not have the firmware file system 2 format, then ASSERT.
603
604 @param InstallFvInfoPpi Install FvInfo Ppi if it is TRUE. Otherwise, install FvInfo2 Ppi.
605 @param FvFormat Unique identifier of the format of the memory-mapped
606 firmware volume. This parameter is optional and
607 may be NULL. If NULL is specified, the
608 EFI_FIRMWARE_FILE_SYSTEM2_GUID format is assumed.
609 @param FvInfo Points to a buffer which allows the
610 EFI_PEI_FIRMWARE_VOLUME_PPI to process the volume.
611 The format of this buffer is specific to the FvFormat.
612 For memory-mapped firmware volumes, this typically
613 points to the first byte of the firmware volume.
614 @param FvInfoSize The size, in bytes, of FvInfo. For memory-mapped
615 firmware volumes, this is typically the size of
616 the firmware volume.
617 @param ParentFvName If the new firmware volume originated from a file
618 in a different firmware volume, then this parameter
619 specifies the GUID name of the originating firmware
620 volume. Otherwise, this parameter must be NULL.
621 @param ParentFileName If the new firmware volume originated from a file
622 in a different firmware volume, then this parameter
623 specifies the GUID file name of the originating
624 firmware file. Otherwise, this parameter must be NULL.
625 @param AuthenticationStatus Authentication Status, it will be ignored if InstallFvInfoPpi is TRUE.
626 **/
627 VOID
628 EFIAPI
629 InternalPeiServicesInstallFvInfoPpi (
630 IN BOOLEAN InstallFvInfoPpi,
631 IN CONST EFI_GUID *FvFormat, OPTIONAL
632 IN CONST VOID *FvInfo,
633 IN UINT32 FvInfoSize,
634 IN CONST EFI_GUID *ParentFvName, OPTIONAL
635 IN CONST EFI_GUID *ParentFileName, OPTIONAL
636 IN UINT32 AuthenticationStatus
637 )
638 {
639 EFI_STATUS Status;
640 EFI_PEI_FIRMWARE_VOLUME_INFO_PPI *FvInfoPpi;
641 EFI_PEI_PPI_DESCRIPTOR *FvInfoPpiDescriptor;
642 EFI_GUID *ParentFvNameValue;
643 EFI_GUID *ParentFileNameValue;
644 EFI_GUID *PpiGuid;
645
646 ParentFvNameValue = NULL;
647 ParentFileNameValue = NULL;
648 if (InstallFvInfoPpi) {
649 //
650 // To install FvInfo Ppi.
651 //
652 FvInfoPpi = AllocateZeroPool (sizeof (EFI_PEI_FIRMWARE_VOLUME_INFO_PPI));
653 ASSERT (FvInfoPpi != NULL);
654 PpiGuid = &gEfiPeiFirmwareVolumeInfoPpiGuid;
655 } else {
656 //
657 // To install FvInfo2 Ppi.
658 //
659 FvInfoPpi = AllocateZeroPool (sizeof (EFI_PEI_FIRMWARE_VOLUME_INFO2_PPI));
660 ASSERT (FvInfoPpi != NULL);
661 ((EFI_PEI_FIRMWARE_VOLUME_INFO2_PPI *) FvInfoPpi)->AuthenticationStatus = AuthenticationStatus;
662 PpiGuid = &gEfiPeiFirmwareVolumeInfo2PpiGuid;
663 }
664
665 if (FvFormat != NULL) {
666 CopyGuid (&FvInfoPpi->FvFormat, FvFormat);
667 } else {
668 CopyGuid (&FvInfoPpi->FvFormat, &gEfiFirmwareFileSystem2Guid);
669 //
670 // Since the EFI_FIRMWARE_FILE_SYSTEM2_GUID format is assumed if NULL is specified for FvFormat,
671 // check the FileSystemGuid pointed by FvInfo against EFI_FIRMWARE_FILE_SYSTEM2_GUID to make sure
672 // FvInfo has the firmware file system 2 format.
673 // If the ASSERT really appears, FvFormat needs to be specified correctly, for example,
674 // EFI_FIRMWARE_FILE_SYSTEM3_GUID can be used for firmware file system 3 format, or
675 // ((EFI_FIRMWARE_VOLUME_HEADER *) FvInfo)->FileSystemGuid can be just used for both
676 // firmware file system 2 and 3 format.
677 //
678 ASSERT (CompareGuid (&(((EFI_FIRMWARE_VOLUME_HEADER *) FvInfo)->FileSystemGuid), &gEfiFirmwareFileSystem2Guid));
679 }
680 FvInfoPpi->FvInfo = (VOID *) FvInfo;
681 FvInfoPpi->FvInfoSize = FvInfoSize;
682 if (ParentFvName != NULL) {
683 ParentFvNameValue = AllocateCopyPool (sizeof (EFI_GUID), ParentFvName);
684 ASSERT (ParentFvNameValue != NULL);
685 FvInfoPpi->ParentFvName = ParentFvNameValue;
686 }
687 if (ParentFileName != NULL) {
688 ParentFileNameValue = AllocateCopyPool (sizeof (EFI_GUID), ParentFileName);
689 ASSERT (ParentFileNameValue != NULL);
690 FvInfoPpi->ParentFileName = ParentFileNameValue;
691 }
692
693 FvInfoPpiDescriptor = AllocatePool (sizeof (EFI_PEI_PPI_DESCRIPTOR));
694 ASSERT (FvInfoPpiDescriptor != NULL);
695
696 FvInfoPpiDescriptor->Guid = PpiGuid;
697 FvInfoPpiDescriptor->Flags = EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;
698 FvInfoPpiDescriptor->Ppi = (VOID *) FvInfoPpi;
699 Status = PeiServicesInstallPpi (FvInfoPpiDescriptor);
700 ASSERT_EFI_ERROR (Status);
701
702 }
703
704 /**
705 Install a EFI_PEI_FIRMWARE_VOLUME_INFO_PPI instance so the PEI Core will be notified about a new firmware volume.
706
707 This function allocates, initializes, and installs a new EFI_PEI_FIRMWARE_VOLUME_INFO_PPI using
708 the parameters passed in to initialize the fields of the EFI_PEI_FIRMWARE_VOLUME_INFO_PPI instance.
709 If the resources can not be allocated for EFI_PEI_FIRMWARE_VOLUME_INFO_PPI, then ASSERT().
710 If the EFI_PEI_FIRMWARE_VOLUME_INFO_PPI can not be installed, then ASSERT().
711 If NULL is specified for FvFormat, but FvInfo does not have the firmware file system 2 format, then ASSERT.
712
713 @param FvFormat Unique identifier of the format of the memory-mapped
714 firmware volume. This parameter is optional and
715 may be NULL. If NULL is specified, the
716 EFI_FIRMWARE_FILE_SYSTEM2_GUID format is assumed.
717 @param FvInfo Points to a buffer which allows the
718 EFI_PEI_FIRMWARE_VOLUME_PPI to process the volume.
719 The format of this buffer is specific to the FvFormat.
720 For memory-mapped firmware volumes, this typically
721 points to the first byte of the firmware volume.
722 @param FvInfoSize The size, in bytes, of FvInfo. For memory-mapped
723 firmware volumes, this is typically the size of
724 the firmware volume.
725 @param ParentFvName If the new firmware volume originated from a file
726 in a different firmware volume, then this parameter
727 specifies the GUID name of the originating firmware
728 volume. Otherwise, this parameter must be NULL.
729 @param ParentFileName If the new firmware volume originated from a file
730 in a different firmware volume, then this parameter
731 specifies the GUID file name of the originating
732 firmware file. Otherwise, this parameter must be NULL.
733 **/
734 VOID
735 EFIAPI
736 PeiServicesInstallFvInfoPpi (
737 IN CONST EFI_GUID *FvFormat, OPTIONAL
738 IN CONST VOID *FvInfo,
739 IN UINT32 FvInfoSize,
740 IN CONST EFI_GUID *ParentFvName, OPTIONAL
741 IN CONST EFI_GUID *ParentFileName OPTIONAL
742 )
743 {
744 InternalPeiServicesInstallFvInfoPpi (TRUE, FvFormat, FvInfo, FvInfoSize, ParentFvName, ParentFileName, 0);
745 }
746
747 /**
748 Install a EFI_PEI_FIRMWARE_VOLUME_INFO2_PPI instance so the PEI Core will be notified about a new firmware volume.
749
750 This function allocates, initializes, and installs a new EFI_PEI_FIRMWARE_VOLUME_INFO2_PPI using
751 the parameters passed in to initialize the fields of the EFI_PEI_FIRMWARE_VOLUME_INFO2_PPI instance.
752 If the resources can not be allocated for EFI_PEI_FIRMWARE_VOLUME_INFO2_PPI, then ASSERT().
753 If the EFI_PEI_FIRMWARE_VOLUME_INFO2_PPI can not be installed, then ASSERT().
754 If NULL is specified for FvFormat, but FvInfo does not have the firmware file system 2 format, then ASSERT.
755
756 @param FvFormat Unique identifier of the format of the memory-mapped
757 firmware volume. This parameter is optional and
758 may be NULL. If NULL is specified, the
759 EFI_FIRMWARE_FILE_SYSTEM2_GUID format is assumed.
760 @param FvInfo Points to a buffer which allows the
761 EFI_PEI_FIRMWARE_VOLUME_PPI to process the volume.
762 The format of this buffer is specific to the FvFormat.
763 For memory-mapped firmware volumes, this typically
764 points to the first byte of the firmware volume.
765 @param FvInfoSize The size, in bytes, of FvInfo. For memory-mapped
766 firmware volumes, this is typically the size of
767 the firmware volume.
768 @param ParentFvName If the new firmware volume originated from a file
769 in a different firmware volume, then this parameter
770 specifies the GUID name of the originating firmware
771 volume. Otherwise, this parameter must be NULL.
772 @param ParentFileName If the new firmware volume originated from a file
773 in a different firmware volume, then this parameter
774 specifies the GUID file name of the originating
775 firmware file. Otherwise, this parameter must be NULL.
776 @param AuthenticationStatus Authentication Status
777 **/
778 VOID
779 EFIAPI
780 PeiServicesInstallFvInfo2Ppi (
781 IN CONST EFI_GUID *FvFormat, OPTIONAL
782 IN CONST VOID *FvInfo,
783 IN UINT32 FvInfoSize,
784 IN CONST EFI_GUID *ParentFvName, OPTIONAL
785 IN CONST EFI_GUID *ParentFileName, OPTIONAL
786 IN UINT32 AuthenticationStatus
787 )
788 {
789 InternalPeiServicesInstallFvInfoPpi (FALSE, FvFormat, FvInfo, FvInfoSize, ParentFvName, ParentFileName, AuthenticationStatus);
790 }
791
792 /**
793 Resets the entire platform.
794
795 @param[in] ResetType The type of reset to perform.
796 @param[in] ResetStatus The status code for the reset.
797 @param[in] DataSize The size, in bytes, of ResetData.
798 @param[in] ResetData For a ResetType of EfiResetCold, EfiResetWarm, or EfiResetShutdown
799 the data buffer starts with a Null-terminated string, optionally
800 followed by additional binary data. The string is a description
801 that the caller may use to further indicate the reason for the
802 system reset. ResetData is only valid if ResetStatus is something
803 other than EFI_SUCCESS unless the ResetType is EfiResetPlatformSpecific
804 where a minimum amount of ResetData is always required.
805
806 **/
807 VOID
808 EFIAPI
809 PeiServicesResetSystem2 (
810 IN EFI_RESET_TYPE ResetType,
811 IN EFI_STATUS ResetStatus,
812 IN UINTN DataSize,
813 IN VOID *ResetData OPTIONAL
814 )
815 {
816 (*GetPeiServicesTablePointer())->ResetSystem2 (ResetType, ResetStatus, DataSize, ResetData);
817 }