]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Core/Pei/PeiMain.h
updated Alias, Map, and Env functions per errata.
[mirror_edk2.git] / MdeModulePkg / Core / Pei / PeiMain.h
1 /** @file
2 Definition of Pei Core Structures and Services
3
4 Copyright (c) 2006 - 2008, Intel Corporation
5 All rights reserved. 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 #ifndef _PEI_MAIN_H_
16 #define _PEI_MAIN_H_
17
18 #include <PiPei.h>
19 #include <Ppi/DxeIpl.h>
20 #include <Ppi/MemoryDiscovered.h>
21 #include <Ppi/StatusCode.h>
22 #include <Ppi/Reset.h>
23 #include <Ppi/FirmwareVolume.h>
24 #include <Ppi/FirmwareVolumeInfo.h>
25 #include <Ppi/Decompress.h>
26 #include <Ppi/GuidedSectionExtraction.h>
27 #include <Ppi/LoadFile.h>
28 #include <Ppi/Security2.h>
29 #include <Ppi/TemporaryRamSupport.h>
30 #include <Library/DebugLib.h>
31 #include <Library/PeiCoreEntryPoint.h>
32 #include <Library/BaseLib.h>
33 #include <Library/HobLib.h>
34 #include <Library/PerformanceLib.h>
35 #include <Library/PeiServicesLib.h>
36 #include <Library/ReportStatusCodeLib.h>
37 #include <Library/PeCoffLib.h>
38 #include <Library/PeCoffGetEntryPointLib.h>
39 #include <Library/BaseMemoryLib.h>
40 #include <Library/CacheMaintenanceLib.h>
41 #include <Library/TimerLib.h>
42 #include <Library/PcdLib.h>
43 #include <IndustryStandard/PeImage.h>
44 #include <Library/PeiServicesTablePointerLib.h>
45 #include <Library/MemoryAllocationLib.h>
46 #include <Guid/FirmwareFileSystem2.h>
47 #include <Guid/AprioriFileName.h>
48
49 ///
50 /// It is an FFS type extension used for PeiFindFileEx. It indicates current
51 /// Ffs searching is for all PEIMs can be dispatched by PeiCore.
52 ///
53 #define PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE 0xff
54
55 ///
56 /// Pei Core private data structures
57 ///
58 typedef union {
59 EFI_PEI_PPI_DESCRIPTOR *Ppi;
60 EFI_PEI_NOTIFY_DESCRIPTOR *Notify;
61 VOID *Raw;
62 } PEI_PPI_LIST_POINTERS;
63
64 ///
65 /// PPI database structure which contains two link: PpiList and NotifyList. PpiList
66 /// is in head of PpiListPtrs array and notify is in end of PpiListPtrs.
67 ///
68 typedef struct {
69 ///
70 /// index of end of PpiList link list.
71 ///
72 INTN PpiListEnd;
73 ///
74 /// index of end of notify link list.
75 ///
76 INTN NotifyListEnd;
77 ///
78 /// index of the dispatched notify list.
79 ///
80 INTN DispatchListEnd;
81 ///
82 /// index of last installed Ppi description in PpiList link list.
83 ///
84 INTN LastDispatchedInstall;
85 ///
86 /// index of last dispatched notify in Notify link list.
87 ///
88 INTN LastDispatchedNotify;
89 ///
90 /// Ppi database.
91 ///
92 PEI_PPI_LIST_POINTERS PpiListPtrs[FixedPcdGet32 (PcdPeiCoreMaxPpiSupported)];
93 } PEI_PPI_DATABASE;
94
95
96 //
97 // PEI_CORE_FV_HANDE.PeimState
98 // Do not change these values as there is code doing math to change states.
99 // Look for Private->Fv[FvCount].PeimState[PeimCount]++;
100 //
101 #define PEIM_STATE_NOT_DISPATCHED 0x00
102 #define PEIM_STATE_DISPATCHED 0x01
103 #define PEIM_STATE_REGISITER_FOR_SHADOW 0x02
104 #define PEIM_STATE_DONE 0x03
105
106 typedef struct {
107 EFI_FIRMWARE_VOLUME_HEADER *FvHeader;
108 UINT8 PeimState[FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv)];
109 EFI_PEI_FILE_HANDLE FvFileHandles[FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv)];
110 BOOLEAN ScanFv;
111 } PEI_CORE_FV_HANDLE;
112
113 #define CACHE_SETION_MAX_NUMBER 0x10
114 typedef struct {
115 EFI_COMMON_SECTION_HEADER* Section[CACHE_SETION_MAX_NUMBER];
116 VOID* SectionData[CACHE_SETION_MAX_NUMBER];
117 UINTN SectionSize[CACHE_SETION_MAX_NUMBER];
118 UINTN AllSectionCount;
119 UINTN SectionIndex;
120 } CACHE_SECTION_DATA;
121
122
123 #define PEI_CORE_HANDLE_SIGNATURE SIGNATURE_32('P','e','i','C')
124
125 ///
126 /// Pei Core private data structure instance
127 ///
128 typedef struct{
129 UINTN Signature;
130 EFI_PEI_SERVICES *PS; // Point to ServiceTableShadow
131 PEI_PPI_DATABASE PpiData;
132 UINTN FvCount;
133 PEI_CORE_FV_HANDLE Fv[FixedPcdGet32 (PcdPeiCoreMaxFvSupported)];
134 EFI_PEI_FILE_HANDLE CurrentFvFileHandles[FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv)];
135 UINTN AprioriCount;
136 UINTN CurrentPeimFvCount;
137 UINTN CurrentPeimCount;
138 EFI_PEI_FILE_HANDLE CurrentFileHandle;
139 BOOLEAN PeimNeedingDispatch;
140 BOOLEAN PeimDispatchOnThisPass;
141 BOOLEAN PeimDispatcherReenter;
142 UINTN AllFvCount;
143 EFI_PEI_FV_HANDLE AllFv[FixedPcdGet32 (PcdPeiCoreMaxFvSupported)];
144 EFI_PEI_HOB_POINTERS HobList;
145 BOOLEAN SwitchStackSignal;
146 BOOLEAN PeiMemoryInstalled;
147 EFI_PHYSICAL_ADDRESS StackBase;
148 UINT64 StackSize;
149 VOID *CpuIo;
150 EFI_PEI_SECURITY2_PPI *PrivateSecurityPpi;
151 EFI_PEI_SERVICES ServiceTableShadow;
152 EFI_PEI_PPI_DESCRIPTOR *XipLoadFile;
153 EFI_PHYSICAL_ADDRESS PhysicalMemoryBegin;
154 UINT64 PhysicalMemoryLength;
155 EFI_PHYSICAL_ADDRESS FreePhysicalMemoryTop;
156 VOID* ShadowedPeiCore;
157 CACHE_SECTION_DATA CacheSection;
158 } PEI_CORE_INSTANCE;
159
160 ///
161 /// Pei Core Instance Data Macros
162 ///
163 #define PEI_CORE_INSTANCE_FROM_PS_THIS(a) \
164 CR(a, PEI_CORE_INSTANCE, PS, PEI_CORE_HANDLE_SIGNATURE)
165
166 /**
167 Function Pointer type for PeiCore function.
168 @param SecCoreData Points to a data structure containing SEC to PEI handoff data, such as the size
169 and location of temporary RAM, the stack location and the BFV location.
170 @param PpiList Points to a list of one or more PPI descriptors to be installed initially by the PEI core.
171 An empty PPI list consists of a single descriptor with the end-tag
172 EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST. As part of its initialization
173 phase, the PEI Foundation will add these SEC-hosted PPIs to its PPI database such
174 that both the PEI Foundation and any modules can leverage the associated service
175 calls and/or code in these early PPIs
176 @param OldCoreData Pointer to old core data that is used to initialize the
177 core's data areas.
178 **/
179 typedef
180 EFI_STATUS
181 (EFIAPI *PEICORE_FUNCTION_POINTER)(
182 IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData,
183 IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList,
184 IN PEI_CORE_INSTANCE *OldCoreData
185 );
186
187 ///
188 /// Union of temporarily used function pointers (to save stack space)
189 ///
190 typedef union {
191 PEICORE_FUNCTION_POINTER PeiCore;
192 EFI_PEIM_ENTRY_POINT2 PeimEntry;
193 EFI_PEIM_NOTIFY_ENTRY_POINT PeimNotifyEntry;
194 EFI_DXE_IPL_PPI *DxeIpl;
195 EFI_PEI_PPI_DESCRIPTOR *PpiDescriptor;
196 EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor;
197 VOID *Raw;
198 } PEI_CORE_TEMP_POINTERS;
199
200 typedef struct {
201 CONST EFI_SEC_PEI_HAND_OFF *SecCoreData;
202 EFI_PEI_PPI_DESCRIPTOR *PpiList;
203 VOID *Data;
204 } PEI_CORE_PARAMETERS;
205
206 //
207 // PeiCore function
208 //
209 /**
210
211 The entry routine to Pei Core, invoked by PeiMain during transition
212 from SEC to PEI. After switching stack in the PEI core, it will restart
213 with the old core data.
214
215
216 @param SecCoreData Points to a data structure containing SEC to PEI handoff data, such as the size
217 and location of temporary RAM, the stack location and the BFV location.
218 @param PpiList Points to a list of one or more PPI descriptors to be installed initially by the PEI core.
219 An empty PPI list consists of a single descriptor with the end-tag
220 EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST. As part of its initialization
221 phase, the PEI Foundation will add these SEC-hosted PPIs to its PPI database such
222 that both the PEI Foundation and any modules can leverage the associated service
223 calls and/or code in these early PPIs
224 @param Data Pointer to old core data that is used to initialize the
225 core's data areas.
226
227 **/
228 VOID
229 EFIAPI
230 PeiCore (
231 IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData,
232 IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList,
233 IN VOID *Data
234 );
235
236 //
237 // Dispatcher support functions
238 //
239
240 /**
241
242 This is the POSTFIX version of the dependency evaluator. When a
243 PUSH [PPI GUID] is encountered, a pointer to the GUID is stored on
244 the evaluation stack. When that entry is poped from the evaluation
245 stack, the PPI is checked if it is installed. This method allows
246 some time savings as not all PPIs must be checked for certain
247 operation types (AND, OR).
248
249
250 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
251 @param DependencyExpression Pointer to a dependency expression. The Grammar adheres to
252 the BNF described above and is stored in postfix notation.
253
254 @retval TRUE if it is a well-formed Grammar
255 @retval FALSE if the dependency expression overflows the evaluation stack
256 if the dependency expression underflows the evaluation stack
257 if the dependency expression is not a well-formed Grammar.
258
259 **/
260 BOOLEAN
261 PeimDispatchReadiness (
262 IN EFI_PEI_SERVICES **PeiServices,
263 IN VOID *DependencyExpression
264 );
265
266 /**
267 Conduct PEIM dispatch.
268
269 @param SecCoreData Pointer to the data structure containing SEC to PEI handoff data
270 @param PrivateData Pointer to the private data passed in from caller
271
272 **/
273 VOID
274 PeiDispatcher (
275 IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData,
276 IN PEI_CORE_INSTANCE *PrivateData
277 );
278
279 /**
280 Initialize the Dispatcher's data members
281
282 @param PrivateData PeiCore's private data structure
283 @param OldCoreData Old data from SecCore
284 NULL if being run in non-permament memory mode.
285 @param SecCoreData Points to a data structure containing SEC to PEI handoff data, such as the size
286 and location of temporary RAM, the stack location and the BFV location.
287
288 **/
289 VOID
290 InitializeDispatcherData (
291 IN PEI_CORE_INSTANCE *PrivateData,
292 IN PEI_CORE_INSTANCE *OldCoreData,
293 IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData
294 );
295
296 /**
297 This routine parses the Dependency Expression, if available, and
298 decides if the module can be executed.
299
300
301 @param Private PeiCore's private data structure
302 @param FileHandle PEIM's file handle
303 @param PeimCount The index of last dispatched PEIM.
304
305 @retval TRUE Can be dispatched
306 @retval FALSE Cannot be dispatched
307
308 **/
309 BOOLEAN
310 DepexSatisfied (
311 IN PEI_CORE_INSTANCE *Private,
312 IN EFI_PEI_FILE_HANDLE FileHandle,
313 IN UINTN PeimCount
314 );
315
316 //
317 // PPI support functions
318 //
319 /**
320
321 Initialize PPI services.
322
323 @param PrivateData Pointer to the PEI Core data.
324 @param OldCoreData Pointer to old PEI Core data.
325 NULL if being run in non-permament memory mode.
326
327 **/
328 VOID
329 InitializePpiServices (
330 IN PEI_CORE_INSTANCE *PrivateData,
331 IN PEI_CORE_INSTANCE *OldCoreData
332 );
333
334 /**
335
336 Migrate the Hob list from the temporary memory stack to PEI installed memory.
337
338 @param PrivateData Pointer to PeiCore's private data structure.
339 @param OldCheckingBottom Bottom of temporary memory range. All Ppi in this range
340 will be fixup for PpiData and PpiDescriptor pointer.
341 @param OldCheckingTop Top of temporary memory range. All Ppi in this range
342 will be fixup for PpiData and PpiDescriptor.
343 @param Fixup The address difference between
344 the new Hob list and old Hob list.
345
346 **/
347 VOID
348 ConvertPpiPointers (
349 IN PEI_CORE_INSTANCE *PrivateData,
350 IN UINTN OldCheckingBottom,
351 IN UINTN OldCheckingTop,
352 IN INTN Fixup
353 );
354
355 /**
356
357 Install PPI services. It is implementation of EFI_PEI_SERVICE.InstallPpi.
358
359 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
360 @param PpiList Pointer to ppi array that want to be installed.
361
362 @retval EFI_SUCCESS if all PPIs in PpiList are successfully installed.
363 @retval EFI_INVALID_PARAMETER if PpiList is NULL pointer
364 if any PPI in PpiList is not valid
365 @retval EFI_OUT_OF_RESOURCES if there is no more memory resource to install PPI
366
367 **/
368 EFI_STATUS
369 EFIAPI
370 PeiInstallPpi (
371 IN CONST EFI_PEI_SERVICES **PeiServices,
372 IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList
373 );
374
375 /**
376
377 Re-Install PPI services.
378
379 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
380 @param OldPpi Pointer to the old PEI PPI Descriptors.
381 @param NewPpi Pointer to the new PEI PPI Descriptors.
382
383 @retval EFI_SUCCESS if the operation was successful
384 @retval EFI_INVALID_PARAMETER if OldPpi or NewPpi is NULL
385 if NewPpi is not valid
386 @retval EFI_NOT_FOUND if the PPI was not in the database
387
388 **/
389 EFI_STATUS
390 EFIAPI
391 PeiReInstallPpi (
392 IN CONST EFI_PEI_SERVICES **PeiServices,
393 IN CONST EFI_PEI_PPI_DESCRIPTOR *OldPpi,
394 IN CONST EFI_PEI_PPI_DESCRIPTOR *NewPpi
395 );
396
397 /**
398
399 Locate a given named PPI.
400
401
402 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
403 @param Guid Pointer to GUID of the PPI.
404 @param Instance Instance Number to discover.
405 @param PpiDescriptor Pointer to reference the found descriptor. If not NULL,
406 returns a pointer to the descriptor (includes flags, etc)
407 @param Ppi Pointer to reference the found PPI
408
409 @retval EFI_SUCCESS if the PPI is in the database
410 @retval EFI_NOT_FOUND if the PPI is not in the database
411
412 **/
413 EFI_STATUS
414 EFIAPI
415 PeiLocatePpi (
416 IN CONST EFI_PEI_SERVICES **PeiServices,
417 IN CONST EFI_GUID *Guid,
418 IN UINTN Instance,
419 IN OUT EFI_PEI_PPI_DESCRIPTOR **PpiDescriptor,
420 IN OUT VOID **Ppi
421 );
422
423 /**
424
425 Install a notification for a given PPI.
426
427
428 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
429 @param NotifyList Pointer to list of Descriptors to notify upon.
430
431 @retval EFI_SUCCESS if successful
432 @retval EFI_OUT_OF_RESOURCES if no space in the database
433 @retval EFI_INVALID_PARAMETER if not a good decriptor
434
435 **/
436 EFI_STATUS
437 EFIAPI
438 PeiNotifyPpi (
439 IN CONST EFI_PEI_SERVICES **PeiServices,
440 IN CONST EFI_PEI_NOTIFY_DESCRIPTOR *NotifyList
441 );
442
443 /**
444
445 Process the Notify List at dispatch level.
446
447 @param PrivateData PeiCore's private data structure.
448
449 **/
450 VOID
451 ProcessNotifyList (
452 IN PEI_CORE_INSTANCE *PrivateData
453 );
454
455 /**
456
457 Dispatch notifications.
458
459 @param PrivateData PeiCore's private data structure
460 @param NotifyType Type of notify to fire.
461 @param InstallStartIndex Install Beginning index.
462 @param InstallStopIndex Install Ending index.
463 @param NotifyStartIndex Notify Beginning index.
464 @param NotifyStopIndex Notify Ending index.
465
466 **/
467 VOID
468 DispatchNotify (
469 IN PEI_CORE_INSTANCE *PrivateData,
470 IN UINTN NotifyType,
471 IN INTN InstallStartIndex,
472 IN INTN InstallStopIndex,
473 IN INTN NotifyStartIndex,
474 IN INTN NotifyStopIndex
475 );
476
477 //
478 // Boot mode support functions
479 //
480 /**
481 This service enables PEIMs to ascertain the present value of the boot mode.
482
483 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
484 @param BootMode A pointer to contain the value of the boot mode.
485
486 @retval EFI_SUCCESS The boot mode was returned successfully.
487 @retval EFI_INVALID_PARAMETER BootMode is NULL.
488
489 **/
490 EFI_STATUS
491 EFIAPI
492 PeiGetBootMode (
493 IN CONST EFI_PEI_SERVICES **PeiServices,
494 IN OUT EFI_BOOT_MODE *BootMode
495 );
496
497 /**
498 This service enables PEIMs to update the boot mode variable.
499
500
501 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
502 @param BootMode The value of the boot mode to set.
503
504 @return EFI_SUCCESS The value was successfully updated
505
506 **/
507 EFI_STATUS
508 EFIAPI
509 PeiSetBootMode (
510 IN CONST EFI_PEI_SERVICES **PeiServices,
511 IN EFI_BOOT_MODE BootMode
512 );
513
514 //
515 // Security support functions
516 //
517 /**
518
519 Initialize the security services.
520
521 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
522 @param OldCoreData Pointer to the old core data.
523 NULL if being run in non-permament memory mode.
524
525 **/
526 VOID
527 InitializeSecurityServices (
528 IN EFI_PEI_SERVICES **PeiServices,
529 IN PEI_CORE_INSTANCE *OldCoreData
530 );
531
532 /**
533 Verify a Firmware volume.
534
535 @param CurrentFvAddress Pointer to the current Firmware Volume under consideration
536
537 @retval EFI_SUCCESS Firmware Volume is legal
538 @retval EFI_SECURITY_VIOLATION Firmware Volume fails integrity test
539
540 **/
541 EFI_STATUS
542 VerifyFv (
543 IN EFI_FIRMWARE_VOLUME_HEADER *CurrentFvAddress
544 );
545
546 /**
547
548 Provide a callout to the security verification service.
549
550
551 @param PrivateData PeiCore's private data structure
552 @param VolumeHandle Handle of FV
553 @param FileHandle Handle of PEIM's ffs
554
555 @retval EFI_SUCCESS Image is OK
556 @retval EFI_SECURITY_VIOLATION Image is illegal
557
558 **/
559 EFI_STATUS
560 VerifyPeim (
561 IN PEI_CORE_INSTANCE *PrivateData,
562 IN EFI_PEI_FV_HANDLE VolumeHandle,
563 IN EFI_PEI_FILE_HANDLE FileHandle
564 );
565
566 /**
567
568 Gets the pointer to the HOB List.
569
570
571 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
572 @param HobList Pointer to the HOB List.
573
574 @retval EFI_SUCCESS Get the pointer of HOB List
575 @retval EFI_NOT_AVAILABLE_YET the HOB List is not yet published
576 @retval EFI_INVALID_PARAMETER HobList is NULL (in debug mode)
577
578 **/
579 EFI_STATUS
580 EFIAPI
581 PeiGetHobList (
582 IN CONST EFI_PEI_SERVICES **PeiServices,
583 IN OUT VOID **HobList
584 );
585
586 /**
587 Add a new HOB to the HOB List.
588
589 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
590 @param Type Type of the new HOB.
591 @param Length Length of the new HOB to allocate.
592 @param Hob Pointer to the new HOB.
593
594 @return EFI_SUCCESS Success to create hob.
595 @retval EFI_INVALID_PARAMETER if Hob is NULL
596 @retval EFI_NOT_AVAILABLE_YET if HobList is still not available.
597 @retval EFI_OUT_OF_RESOURCES if there is no more memory to grow the Hoblist.
598
599 **/
600 EFI_STATUS
601 EFIAPI
602 PeiCreateHob (
603 IN CONST EFI_PEI_SERVICES **PeiServices,
604 IN UINT16 Type,
605 IN UINT16 Length,
606 IN OUT VOID **Hob
607 );
608
609 /**
610
611 Builds a Handoff Information Table HOB
612
613 @param BootMode - Current Bootmode
614 @param MemoryBegin - Start Memory Address.
615 @param MemoryLength - Length of Memory.
616
617 @return EFI_SUCCESS Always success to initialize HOB.
618
619 **/
620 EFI_STATUS
621 PeiCoreBuildHobHandoffInfoTable (
622 IN EFI_BOOT_MODE BootMode,
623 IN EFI_PHYSICAL_ADDRESS MemoryBegin,
624 IN UINT64 MemoryLength
625 );
626
627
628 //
629 // FFS Fw Volume support functions
630 //
631 /**
632 Given the input file pointer, search for the next matching file in the
633 FFS volume as defined by SearchType. The search starts from FileHeader inside
634 the Firmware Volume defined by FwVolHeader.
635
636
637 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
638 @param SearchType Filter to find only files of this type.
639 Type EFI_FV_FILETYPE_ALL causes no filtering to be done.
640 @param FwVolHeader Pointer to the FV header of the volume to search.
641 @param FileHeader Pointer to the current file from which to begin searching.
642 This pointer will be updated upon return to reflect the file found.
643 @retval EFI_NOT_FOUND No files matching the search criteria were found
644 @retval EFI_SUCCESS Success to find next file in given volume
645
646 **/
647 EFI_STATUS
648 EFIAPI
649 PeiFfsFindNextFile (
650 IN CONST EFI_PEI_SERVICES **PeiServices,
651 IN UINT8 SearchType,
652 IN EFI_PEI_FV_HANDLE FwVolHeader,
653 IN OUT EFI_PEI_FILE_HANDLE *FileHeader
654 );
655
656 /**
657 Given the input file pointer, search for the next matching section in the
658 FFS volume.
659
660 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
661 @param SectionType Filter to find only sections of this type.
662 @param FfsFileHeader Pointer to the current file to search.
663 @param SectionData Pointer to the Section matching SectionType in FfsFileHeader.
664 NULL if section not found
665
666 @retval EFI_NOT_FOUND No files matching the search criteria were found
667 @retval EFI_SUCCESS Success to find section data in given file
668
669 **/
670 EFI_STATUS
671 EFIAPI
672 PeiFfsFindSectionData (
673 IN CONST EFI_PEI_SERVICES **PeiServices,
674 IN EFI_SECTION_TYPE SectionType,
675 IN EFI_PEI_FILE_HANDLE FfsFileHeader,
676 IN OUT VOID **SectionData
677 );
678
679 /**
680 search the firmware volumes by index
681
682 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
683 @param Instance Instance of FV to find
684 @param FwVolHeader Pointer to found Volume.
685
686 @retval EFI_INVALID_PARAMETER FwVolHeader is NULL
687 @retval EFI_SUCCESS Firmware volume instance successfully found.
688
689 **/
690 EFI_STATUS
691 EFIAPI
692 PeiFvFindNextVolume (
693 IN CONST EFI_PEI_SERVICES **PeiServices,
694 IN UINTN Instance,
695 IN OUT EFI_PEI_FV_HANDLE *FwVolHeader
696 );
697
698 //
699 // Memory support functions
700 //
701 /**
702
703 Initialize the memory services.
704
705 @param PrivateData PeiCore's private data structure
706 @param SecCoreData Points to a data structure containing SEC to PEI handoff data, such as the size
707 and location of temporary RAM, the stack location and the BFV location.
708 @param OldCoreData Pointer to the PEI Core data.
709 NULL if being run in non-permament memory mode.
710
711 **/
712 VOID
713 InitializeMemoryServices (
714 IN PEI_CORE_INSTANCE *PrivateData,
715 IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData,
716 IN PEI_CORE_INSTANCE *OldCoreData
717 );
718
719 /**
720
721 Install the permanent memory is now available.
722 Creates HOB (PHIT and Stack).
723
724 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
725 @param MemoryBegin Start of memory address.
726 @param MemoryLength Length of memory.
727
728 @return EFI_SUCCESS Always success.
729
730 **/
731 EFI_STATUS
732 EFIAPI
733 PeiInstallPeiMemory (
734 IN CONST EFI_PEI_SERVICES **PeiServices,
735 IN EFI_PHYSICAL_ADDRESS MemoryBegin,
736 IN UINT64 MemoryLength
737 );
738
739 /**
740
741 Memory allocation service on permanent memory,
742 not usable prior to the memory installation.
743
744
745 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
746 @param MemoryType Type of memory to allocate.
747 @param Pages Number of pages to allocate.
748 @param Memory Pointer of memory allocated.
749
750 @retval EFI_SUCCESS The allocation was successful
751 @retval EFI_INVALID_PARAMETER Only AllocateAnyAddress is supported.
752 @retval EFI_NOT_AVAILABLE_YET Called with permanent memory not available
753 @retval EFI_OUT_OF_RESOURCES There is not enough HOB heap to satisfy the requirement
754 to allocate the number of pages.
755
756 **/
757 EFI_STATUS
758 EFIAPI
759 PeiAllocatePages (
760 IN CONST EFI_PEI_SERVICES **PeiServices,
761 IN EFI_MEMORY_TYPE MemoryType,
762 IN UINTN Pages,
763 OUT EFI_PHYSICAL_ADDRESS *Memory
764 );
765
766 /**
767
768 Memory allocation service on the temporary memory.
769
770
771 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
772 @param Size Amount of memory required
773 @param Buffer Address of pointer to the buffer
774
775 @retval EFI_SUCCESS The allocation was successful
776 @retval EFI_OUT_OF_RESOURCES There is not enough heap to satisfy the requirement
777 to allocate the requested size.
778
779 **/
780 EFI_STATUS
781 EFIAPI
782 PeiAllocatePool (
783 IN CONST EFI_PEI_SERVICES **PeiServices,
784 IN UINTN Size,
785 OUT VOID **Buffer
786 );
787
788 /**
789
790 Routine for load image file.
791
792
793 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
794 @param FileHandle Pointer to the FFS file header of the image.
795 @param EntryPoint Pointer to entry point of specified image file for output.
796 @param AuthenticationState Pointer to attestation authentication state of image.
797
798 @retval EFI_SUCCESS Image is successfully loaded.
799 @retval EFI_NOT_FOUND Fail to locate necessary PPI
800 @retval Others Fail to load file.
801
802 **/
803 EFI_STATUS
804 PeiLoadImage (
805 IN CONST EFI_PEI_SERVICES **PeiServices,
806 IN EFI_PEI_FILE_HANDLE FileHandle,
807 OUT EFI_PHYSICAL_ADDRESS *EntryPoint,
808 OUT UINT32 *AuthenticationState
809 );
810
811 /**
812
813 Core version of the Status Code reporter
814
815
816 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
817 @param CodeType Type of Status Code.
818 @param Value Value to output for Status Code.
819 @param Instance Instance Number of this status code.
820 @param CallerId ID of the caller of this status code.
821 @param Data Optional data associated with this status code.
822
823 @retval EFI_SUCCESS if status code is successfully reported
824 @retval EFI_NOT_AVAILABLE_YET if StatusCodePpi has not been installed
825
826 **/
827 EFI_STATUS
828 EFIAPI
829 PeiReportStatusCode (
830 IN CONST EFI_PEI_SERVICES **PeiServices,
831 IN EFI_STATUS_CODE_TYPE CodeType,
832 IN EFI_STATUS_CODE_VALUE Value,
833 IN UINT32 Instance,
834 IN CONST EFI_GUID *CallerId,
835 IN CONST EFI_STATUS_CODE_DATA *Data OPTIONAL
836 );
837
838 /**
839
840 Core version of the Reset System
841
842
843 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
844
845 @retval EFI_NOT_AVAILABLE_YET PPI not available yet.
846 @retval EFI_DEVICE_ERROR Did not reset system.
847 Otherwise, resets the system.
848
849 **/
850 EFI_STATUS
851 EFIAPI
852 PeiResetSystem (
853 IN CONST EFI_PEI_SERVICES **PeiServices
854 );
855
856 /**
857
858 Initialize PeiCore Fv List.
859
860
861 @param PrivateData - Pointer to PEI_CORE_INSTANCE.
862 @param SecCoreData - Pointer to EFI_SEC_PEI_HAND_OFF.
863
864 **/
865 VOID
866 PeiInitializeFv (
867 IN PEI_CORE_INSTANCE *PrivateData,
868 IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData
869 );
870
871 /**
872 Process Firmware Volum Information once FvInfoPPI install.
873
874 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
875 @param NotifyDescriptor Address of the notification descriptor data structure.
876 @param Ppi Address of the PPI that was installed.
877
878 @retval EFI_SUCCESS if the interface could be successfully installed
879
880 **/
881 EFI_STATUS
882 EFIAPI
883 FirmwareVolmeInfoPpiNotifyCallback (
884 IN EFI_PEI_SERVICES **PeiServices,
885 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
886 IN VOID *Ppi
887 );
888
889 /**
890
891 Given the input VolumeHandle, search for the next matching name file.
892
893 @param FileName File name to search.
894 @param VolumeHandle The current FV to search.
895 @param FileHandle Pointer to the file matching name in VolumeHandle.
896 NULL if file not found
897
898 @retval EFI_NOT_FOUND No files matching the search criteria were found
899 @retval EFI_SUCCESS Success to search given file
900
901 **/
902 EFI_STATUS
903 EFIAPI
904 PeiFfsFindFileByName (
905 IN CONST EFI_GUID *FileName,
906 IN EFI_PEI_FV_HANDLE VolumeHandle,
907 OUT EFI_PEI_FILE_HANDLE *FileHandle
908 );
909
910 /**
911
912 Returns information about a specific file.
913
914
915 @param FileHandle The handle to file.
916 @param FileInfo Pointer to the file information.
917
918 @retval EFI_INVALID_PARAMETER Invalid FileHandle or FileInfo.
919 @retval EFI_SUCCESS Success to collect file info.
920
921 **/
922 EFI_STATUS
923 EFIAPI
924 PeiFfsGetFileInfo (
925 IN EFI_PEI_FILE_HANDLE FileHandle,
926 OUT EFI_FV_FILE_INFO *FileInfo
927 );
928
929 /**
930
931 Collect information of given Fv Volume.
932
933 @param VolumeHandle The handle to Fv Volume.
934 @param VolumeInfo The pointer to volume information.
935
936 @retval EFI_INVALID_PARAMETER VolumeInfo is NULL
937 @retval EFI_SUCCESS Success to collect fv info.
938 **/
939 EFI_STATUS
940 EFIAPI
941 PeiFfsGetVolumeInfo (
942 IN EFI_PEI_FV_HANDLE VolumeHandle,
943 OUT EFI_FV_INFO *VolumeInfo
944 );
945
946 /**
947 This routine enable a PEIM to register itself to shadow when PEI Foundation
948 discovery permanent memory.
949
950 @param FileHandle File handle of a PEIM.
951
952 @retval EFI_NOT_FOUND The file handle doesn't point to PEIM itself.
953 @retval EFI_ALREADY_STARTED Indicate that the PEIM has been registered itself.
954 @retval EFI_SUCCESS Successfully to register itself.
955
956 **/
957 EFI_STATUS
958 EFIAPI
959 PeiRegisterForShadow (
960 IN EFI_PEI_FILE_HANDLE FileHandle
961 );
962
963 /**
964 Given the input file pointer, search for the next matching file in the
965 FFS volume as defined by SearchType. The search starts from FileHeader inside
966 the Firmware Volume defined by FwVolHeader.
967
968
969 @param FvHandle Pointer to the FV header of the volume to search
970 @param FileName File name
971 @param SearchType Filter to find only files of this type.
972 Type EFI_FV_FILETYPE_ALL causes no filtering to be done.
973 @param FileHandle This parameter must point to a valid FFS volume.
974 @param AprioriFile Pointer to AprioriFile image in this FV if has
975
976 @return EFI_NOT_FOUND No files matching the search criteria were found
977 @retval EFI_SUCCESS Success to search given file
978
979 **/
980 EFI_STATUS
981 PeiFindFileEx (
982 IN CONST EFI_PEI_FV_HANDLE FvHandle,
983 IN CONST EFI_GUID *FileName, OPTIONAL
984 IN EFI_FV_FILETYPE SearchType,
985 IN OUT EFI_PEI_FILE_HANDLE *FileHandle,
986 IN OUT EFI_PEI_FV_HANDLE *AprioriFile OPTIONAL
987 );
988
989 /**
990 Initialize image service that install PeiLoadFilePpi.
991
992 @param PrivateData Pointer to PeiCore's private data structure PEI_CORE_INSTANCE.
993 @param OldCoreData Pointer to Old PeiCore's private data.
994 If NULL, PeiCore is entered at first time, stack/heap in temporary memory.
995 If not NULL, PeiCore is entered at second time, stack/heap has been moved
996 to permenent memory.
997
998 **/
999 VOID
1000 InitializeImageServices (
1001 IN PEI_CORE_INSTANCE *PrivateData,
1002 IN PEI_CORE_INSTANCE *OldCoreData
1003 );
1004
1005 /**
1006 Get Fv image from the FV type file, then install FV INFO ppi, Build FV hob.
1007
1008 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
1009 @param ParentFvHandle Fv handle to parent Fv image that contain this Fv file.
1010 @param ParentFvFileHandle File handle of a Fv type file that contain this Fv image.
1011 @param AuthenticationState Pointer to attestation authentication state of image.
1012 If return 0, means pass security checking.
1013
1014 @retval EFI_NOT_FOUND FV image can't be found.
1015 @retval EFI_SUCCESS Successfully to process it.
1016
1017 **/
1018 EFI_STATUS
1019 ProcessFvFile (
1020 IN CONST EFI_PEI_SERVICES **PeiServices,
1021 IN EFI_PEI_FV_HANDLE ParentFvHandle,
1022 IN EFI_PEI_FILE_HANDLE ParentFvFileHandle,
1023 OUT UINT32 *AuthenticationState
1024 );
1025
1026 /**
1027 The wrapper function of PeiLoadImageLoadImage().
1028
1029 @param This Pointer to EFI_PEI_LOAD_FILE_PPI.
1030 @param FileHandle Pointer to the FFS file header of the image.
1031 @param ImageAddressArg Pointer to PE/TE image.
1032 @param ImageSizeArg Size of PE/TE image.
1033 @param EntryPoint Pointer to entry point of specified image file for output.
1034 @param AuthenticationState Pointer to attestation authentication state of image.
1035
1036 @return Status of PeiLoadImageLoadImage().
1037
1038 **/
1039 EFI_STATUS
1040 EFIAPI
1041 PeiLoadImageLoadImageWrapper (
1042 IN CONST EFI_PEI_LOAD_FILE_PPI *This,
1043 IN EFI_PEI_FILE_HANDLE FileHandle,
1044 OUT EFI_PHYSICAL_ADDRESS *ImageAddressArg, OPTIONAL
1045 OUT UINT64 *ImageSizeArg, OPTIONAL
1046 OUT EFI_PHYSICAL_ADDRESS *EntryPoint,
1047 OUT UINT32 *AuthenticationState
1048 );
1049
1050 /**
1051
1052 Provide a callback for when the security PPI is installed.
1053
1054 @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.
1055 @param NotifyDescriptor The descriptor for the notification event.
1056 @param Ppi Pointer to the PPI in question.
1057
1058 @return Always success
1059
1060 **/
1061 EFI_STATUS
1062 EFIAPI
1063 SecurityPpiNotifyCallback (
1064 IN EFI_PEI_SERVICES **PeiServices,
1065 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
1066 IN VOID *Ppi
1067 );
1068
1069 #endif