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