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