Fixed the bug that the PPI descriptor number defined in PeiCore.h is not enough to...
[mirror_edk2.git] / MdeModulePkg / Core / Pei / PeiMain.h
1 /*++
2
3 Copyright (c) 2006 - 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 PeiMain.h
15
16 Abstract:
17
18 Definition of Pei Core Structures and Services
19
20 Revision History
21
22 --*/
23
24 #ifndef _PEI_MAIN_H_
25 #define _PEI_MAIN_H_
26
27 #include <PiPei.h>
28 #include <Ppi/DxeIpl.h>
29 #include <Ppi/MemoryDiscovered.h>
30 #include <Ppi/StatusCode.h>
31 #include <Ppi/Reset.h>
32 #include <Ppi/FirmwareVolume.h>
33 #include <Ppi/FirmwareVolumeInfo.h>
34 #include <Ppi/Decompress.h>
35 #include <Ppi/GuidedSectionExtraction.h>
36 #include <Ppi/LoadFile.h>
37 #include <Ppi/Security2.h>
38 #include <Library/DebugLib.h>
39 #include <Library/PeiCoreEntryPoint.h>
40 #include <Library/BaseLib.h>
41 #include <Library/HobLib.h>
42 #include <Library/PerformanceLib.h>
43 #include <Library/PeiServicesLib.h>
44 #include <Library/ReportStatusCodeLib.h>
45 #include <Library/PeCoffLib.h>
46 #include <Library/PeCoffGetEntryPointLib.h>
47 #include <Library/BaseMemoryLib.h>
48 #include <Library/CacheMaintenanceLib.h>
49 #include <Library/TimerLib.h>
50 #include <Library/PcdLib.h>
51 #include <IndustryStandard/PeImage.h>
52 #include <Library/PeiServicesTablePointerLib.h>
53 #include <Library/MemoryAllocationLib.h>
54 #include <Library/PeiPiLib.h>
55 #include <Guid/FirmwareFileSystem2.h>
56 #include <Guid/AprioriFileName.h>
57
58 #define PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE 0xff
59
60 //
61 // Pei Core private data structures
62 //
63 typedef union {
64 EFI_PEI_PPI_DESCRIPTOR *Ppi;
65 EFI_PEI_NOTIFY_DESCRIPTOR *Notify;
66 VOID *Raw;
67 } PEI_PPI_LIST_POINTERS;
68
69 #define PEI_STACK_SIZE 0x20000
70
71 #define MAX_PPI_DESCRIPTORS 128
72
73 typedef struct {
74 INTN PpiListEnd;
75 INTN NotifyListEnd;
76 INTN DispatchListEnd;
77 INTN LastDispatchedInstall;
78 INTN LastDispatchedNotify;
79 PEI_PPI_LIST_POINTERS PpiListPtrs[MAX_PPI_DESCRIPTORS];
80 } PEI_PPI_DATABASE;
81
82
83 //
84 // PEI_CORE_FV_HANDE.PeimState
85 // Do not change these values as there is code doing math to change states.
86 // Look for Private->Fv[FvCount].PeimState[PeimCount]++;
87 //
88 #define PEIM_STATE_NOT_DISPATCHED 0x00
89 #define PEIM_STATE_DISPATCHED 0x01
90 #define PEIM_STATE_REGISITER_FOR_SHADOW 0x02
91 #define PEIM_STATE_DONE 0x03
92
93 typedef struct {
94 EFI_FIRMWARE_VOLUME_HEADER *FvHeader;
95 UINT8 PeimState[FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv)];
96 EFI_PEI_FILE_HANDLE FvFileHandles[FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv)];
97 BOOLEAN ScanFv;
98 } PEI_CORE_FV_HANDLE;
99
100 #define CACHE_SETION_MAX_NUMBER 0x10
101 typedef struct {
102 EFI_COMMON_SECTION_HEADER* Section[CACHE_SETION_MAX_NUMBER];
103 VOID* SectionData[CACHE_SETION_MAX_NUMBER];
104 UINTN SectionSize[CACHE_SETION_MAX_NUMBER];
105 UINTN AllSectionCount;
106 UINTN SectionIndex;
107 } CACHE_SECTION_DATA;
108
109 //
110 // Pei Core private data structure instance
111 //
112
113 #define PEI_CORE_HANDLE_SIGNATURE EFI_SIGNATURE_32('P','e','i','C')
114
115 typedef struct{
116 UINTN Signature;
117 EFI_PEI_SERVICES *PS; // Point to ServiceTableShadow
118 PEI_PPI_DATABASE PpiData;
119 UINTN FvCount;
120 PEI_CORE_FV_HANDLE Fv[FixedPcdGet32 (PcdPeiCoreMaxFvSupported)];
121 EFI_PEI_FILE_HANDLE CurrentFvFileHandles[FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv)];
122 UINTN AprioriCount;
123 UINTN CurrentPeimFvCount;
124 UINTN CurrentPeimCount;
125 EFI_PEI_FILE_HANDLE CurrentFileHandle;
126 UINTN AllFvCount;
127 EFI_PEI_FV_HANDLE AllFv[FixedPcdGet32 (PcdPeiCoreMaxFvSupported)];
128 EFI_PEI_HOB_POINTERS HobList;
129 BOOLEAN SwitchStackSignal;
130 BOOLEAN PeiMemoryInstalled;
131 EFI_PHYSICAL_ADDRESS StackBase;
132 UINT64 StackSize;
133 VOID *BottomOfCarHeap;
134 VOID *TopOfCarHeap;
135 VOID *CpuIo;
136 EFI_PEI_SECURITY2_PPI *PrivateSecurityPpi;
137 EFI_PEI_SERVICES ServiceTableShadow;
138 UINTN SizeOfCacheAsRam;
139 VOID *MaxTopOfCarHeap;
140 EFI_PEI_PPI_DESCRIPTOR *XipLoadFile;
141 CACHE_SECTION_DATA CacheSection;
142 } PEI_CORE_INSTANCE;
143
144 //
145 // Pei Core Instance Data Macros
146 //
147
148 #define PEI_CORE_INSTANCE_FROM_PS_THIS(a) \
149 CR(a, PEI_CORE_INSTANCE, PS, PEI_CORE_HANDLE_SIGNATURE)
150
151 //
152 // BUGBUG: Where does this go really?
153 //
154 typedef
155 EFI_STATUS
156 (EFIAPI *PEI_CORE_ENTRY_POINT)(
157 IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData,
158 IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList,
159 IN PEI_CORE_INSTANCE *OldCoreData
160 );
161
162 //
163 // Union of temporarily used function pointers (to save stack space)
164 //
165 typedef union {
166 PEI_CORE_ENTRY_POINT PeiCore;
167 EFI_PEIM_ENTRY_POINT2 PeimEntry;
168 EFI_PEIM_NOTIFY_ENTRY_POINT PeimNotifyEntry;
169 EFI_DXE_IPL_PPI *DxeIpl;
170 EFI_PEI_PPI_DESCRIPTOR *PpiDescriptor;
171 EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor;
172 VOID *Raw;
173 } PEI_CORE_TEMP_POINTERS;
174
175
176
177 typedef struct {
178 CONST EFI_SEC_PEI_HAND_OFF *SecCoreData;
179 EFI_PEI_PPI_DESCRIPTOR *PpiList;
180 VOID *Data;
181 } PEI_CORE_PARAMETERS;
182
183 //
184 // PeiCore function
185 //
186 EFI_STATUS
187 EFIAPI
188 PeiCore (
189 IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData,
190 IN CONST EFI_PEI_PPI_DESCRIPTOR *PpList,
191 IN VOID *Data
192 )
193 /*++
194
195 Routine Description:
196
197 The entry routine to Pei Core, invoked by PeiMain during transition
198 from SEC to PEI. After switching stack in the PEI core, it will restart
199 with the old core data.
200
201 Arguments:
202
203 PeiStartupDescriptor - Information and services provided by SEC phase.
204 OldCoreData - Pointer to old core data that is used to initialize the
205 core's data areas.
206
207 Returns:
208
209 This function never returns
210 EFI_NOT_FOUND - Never reach
211
212 --*/
213 ;
214
215 //
216 // Dispatcher support functions
217 //
218
219 BOOLEAN
220 PeimDispatchReadiness (
221 IN EFI_PEI_SERVICES **PeiServices,
222 IN VOID *DependencyExpression
223 )
224 /*++
225
226 Routine Description:
227
228 This is the POSTFIX version of the dependency evaluator. When a
229 PUSH [PPI GUID] is encountered, a pointer to the GUID is stored on
230 the evaluation stack. When that entry is poped from the evaluation
231 stack, the PPI is checked if it is installed. This method allows
232 some time savings as not all PPIs must be checked for certain
233 operation types (AND, OR).
234
235 Arguments:
236
237 PeiServices - Calling context.
238
239 DependencyExpression - Pointer to a dependency expression. The Grammar adheres to
240 the BNF described above and is stored in postfix notation.
241
242 Returns:
243
244 Status = EFI_SUCCESS if it is a well-formed Grammar
245 EFI_INVALID_PARAMETER if the dependency expression overflows
246 the evaluation stack
247 EFI_INVALID_PARAMETER if the dependency expression underflows
248 the evaluation stack
249 EFI_INVALID_PARAMETER if the dependency expression is not a
250 well-formed Grammar.
251 --*/
252 ;
253
254
255 VOID
256 PeiDispatcher (
257 IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData,
258 IN PEI_CORE_INSTANCE *PrivateData
259 )
260
261 /*++
262
263 Routine Description:
264
265 Conduct PEIM dispatch.
266
267 Arguments:
268
269 PeiStartupDescriptor - Pointer to IN EFI_PEI_STARTUP_DESCRIPTOR
270 PrivateData - Pointer to the private data passed in from caller
271 DispatchData - Pointer to PEI_CORE_DISPATCH_DATA data.
272
273 Returns:
274
275 EFI_SUCCESS - Successfully dispatched PEIM.
276 EFI_NOT_FOUND - The dispatch failed.
277
278 --*/
279 ;
280
281
282 VOID
283 InitializeDispatcherData (
284 IN PEI_CORE_INSTANCE *PrivateData,
285 IN PEI_CORE_INSTANCE *OldCoreData,
286 IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData
287 )
288 /*++
289
290 Routine Description:
291
292 Initialize the Dispatcher's data members
293
294 Arguments:
295
296 PeiServices - The PEI core services table.
297 OldCoreData - Pointer to old core data (before switching stack).
298 NULL if being run in non-permament memory mode.
299 PeiStartupDescriptor - Information and services provided by SEC phase.
300
301
302 Returns:
303
304 None
305
306 --*/
307 ;
308
309
310 BOOLEAN
311 Dispatched (
312 IN UINT8 CurrentPeim,
313 IN UINT32 DispatchedPeimBitMap
314 )
315 /*++
316
317 Routine Description:
318
319 This routine checks to see if a particular PEIM has been dispatched during
320 the PEI core dispatch.
321
322 Arguments:
323 CurrentPeim - The PEIM/FV in the bit array to check.
324 DispatchedPeimBitMap - Bit array, each bit corresponds to a PEIM/FV.
325
326 Returns:
327 TRUE if PEIM already dispatched
328 FALSE if not
329
330 --*/
331 ;
332
333 VOID
334 SetDispatched (
335 IN EFI_PEI_SERVICES **PeiServices,
336 IN UINT8 CurrentPeim,
337 OUT UINT32 *DispatchedPeimBitMap
338 )
339 /*++
340
341 Routine Description:
342
343 This routine sets a PEIM as having been dispatched once its entry
344 point has been invoked.
345
346 Arguments:
347
348 PeiServices - The PEI core services table.
349 CurrentPeim - The PEIM/FV in the bit array to check.
350 DispatchedPeimBitMap - Bit array, each bit corresponds to a PEIM/FV.
351
352 Returns:
353 None
354
355 --*/
356 ;
357
358 BOOLEAN
359 DepexSatisfied (
360 IN PEI_CORE_INSTANCE *Private,
361 IN EFI_PEI_FILE_HANDLE FileHandle,
362 IN UINTN PeimCount
363 )
364 /*++
365
366 Routine Description:
367
368 This routine parses the Dependency Expression, if available, and
369 decides if the module can be executed.
370
371 Arguments:
372 PeiServices - The PEI Service Table
373 CurrentPeimAddress - Address of the PEIM Firmware File under investigation
374
375 Returns:
376 TRUE - Can be dispatched
377 FALSE - Cannot be dispatched
378
379 --*/
380 ;
381
382 #if defined (MDE_CPU_IPF)
383 //
384 // In Ipf we should make special changes for the PHIT pointers to support
385 // recovery boot in cache mode.
386 //
387 #define SWITCH_TO_CACHE_MODE(CoreData) SwitchToCacheMode(CoreData)
388 #define CACHE_MODE_ADDRESS_MASK 0x7FFFFFFFFFFFFFFFULL
389 VOID
390 SwitchToCacheMode (
391 IN PEI_CORE_INSTANCE *CoreData
392 )
393 /*++
394
395 Routine Description:
396
397 Switch the PHIT pointers to cache mode after InstallPeiMemory in CAR.
398
399 Arguments:
400
401 CoreData - The PEI core Private Data
402
403 Returns:
404
405 --*/
406 ;
407
408 #else
409
410 #define SWITCH_TO_CACHE_MODE(CoreData)
411
412 #endif
413
414 //
415 // PPI support functions
416 //
417 VOID
418 InitializePpiServices (
419 IN PEI_CORE_INSTANCE *PrivateData,
420 IN PEI_CORE_INSTANCE *OldCoreData
421 )
422 /*++
423
424 Routine Description:
425
426 Initialize PPI services.
427
428 Arguments:
429
430 PeiServices - The PEI core services table.
431 OldCoreData - Pointer to the PEI Core data.
432 NULL if being run in non-permament memory mode.
433
434 Returns:
435 Nothing
436
437 --*/
438 ;
439
440 VOID
441 ConvertPpiPointers (
442 IN CONST EFI_PEI_SERVICES **PeiServices,
443 IN EFI_HOB_HANDOFF_INFO_TABLE *OldHandOffHob,
444 IN EFI_HOB_HANDOFF_INFO_TABLE *NewHandOffHob
445 )
446 /*++
447
448 Routine Description:
449
450 Migrate the Hob list from the CAR stack to PEI installed memory.
451
452 Arguments:
453
454 PeiServices - The PEI core services table.
455 OldHandOffHob - The old handoff HOB list.
456 NewHandOffHob - The new handoff HOB list.
457
458 Returns:
459
460 --*/
461 ;
462
463 EFI_STATUS
464 EFIAPI
465 PeiInstallPpi (
466 IN CONST EFI_PEI_SERVICES **PeiServices,
467 IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList
468 )
469 /*++
470
471 Routine Description:
472
473 Install PPI services.
474
475 Arguments:
476
477 PeiServices - Pointer to the PEI Service Table
478 PpiList - Pointer to a list of PEI PPI Descriptors.
479
480 Returns:
481
482 EFI_SUCCESS - if all PPIs in PpiList are successfully installed.
483 EFI_INVALID_PARAMETER - if PpiList is NULL pointer
484 EFI_INVALID_PARAMETER - if any PPI in PpiList is not valid
485 EFI_OUT_OF_RESOURCES - if there is no more memory resource to install PPI
486
487 --*/
488 ;
489
490 EFI_STATUS
491 EFIAPI
492 PeiReInstallPpi (
493 IN CONST EFI_PEI_SERVICES **PeiServices,
494 IN CONST EFI_PEI_PPI_DESCRIPTOR *OldPpi,
495 IN CONST EFI_PEI_PPI_DESCRIPTOR *NewPpi
496 )
497 /*++
498
499 Routine Description:
500
501 Re-Install PPI services.
502
503 Arguments:
504
505 PeiServices - Pointer to the PEI Service Table
506 OldPpi - Pointer to the old PEI PPI Descriptors.
507 NewPpi - Pointer to the new PEI PPI Descriptors.
508
509 Returns:
510
511 EFI_SUCCESS - if the operation was successful
512 EFI_INVALID_PARAMETER - if OldPpi or NewPpi is NULL
513 EFI_INVALID_PARAMETER - if NewPpi is not valid
514 EFI_NOT_FOUND - if the PPI was not in the database
515
516 --*/
517 ;
518
519 EFI_STATUS
520 EFIAPI
521 PeiLocatePpi (
522 IN CONST EFI_PEI_SERVICES **PeiServices,
523 IN CONST EFI_GUID *Guid,
524 IN UINTN Instance,
525 IN OUT EFI_PEI_PPI_DESCRIPTOR **PpiDescriptor,
526 IN OUT VOID **Ppi
527 )
528 /*++
529
530 Routine Description:
531
532 Locate a given named PPI.
533
534 Arguments:
535
536 PeiServices - Pointer to the PEI Service Table
537 Guid - Pointer to GUID of the PPI.
538 Instance - Instance Number to discover.
539 PpiDescriptor - Pointer to reference the found descriptor. If not NULL,
540 returns a pointer to the descriptor (includes flags, etc)
541 Ppi - Pointer to reference the found PPI
542
543 Returns:
544
545 Status - EFI_SUCCESS if the PPI is in the database
546 EFI_NOT_FOUND if the PPI is not in the database
547 --*/
548 ;
549
550 EFI_STATUS
551 EFIAPI
552 PeiNotifyPpi (
553 IN CONST EFI_PEI_SERVICES **PeiServices,
554 IN CONST EFI_PEI_NOTIFY_DESCRIPTOR *NotifyList
555 )
556 /*++
557
558 Routine Description:
559
560 Install a notification for a given PPI.
561
562 Arguments:
563
564 PeiServices - Pointer to the PEI Service Table
565 NotifyList - Pointer to list of Descriptors to notify upon.
566
567 Returns:
568
569 Status - EFI_SUCCESS if successful
570 EFI_OUT_OF_RESOURCES if no space in the database
571 EFI_INVALID_PARAMETER if not a good decriptor
572
573 --*/
574 ;
575
576 VOID
577 ProcessNotifyList (
578 IN PEI_CORE_INSTANCE *PrivateData
579 )
580 /*++
581
582 Routine Description:
583
584 Process the Notify List at dispatch level.
585
586 Arguments:
587
588 PeiServices - Pointer to the PEI Service Table
589
590 Returns:
591
592 --*/
593 ;
594
595 VOID
596 DispatchNotify (
597 IN PEI_CORE_INSTANCE *PrivateData,
598 IN UINTN NotifyType,
599 IN INTN InstallStartIndex,
600 IN INTN InstallStopIndex,
601 IN INTN NotifyStartIndex,
602 IN INTN NotifyStopIndex
603 )
604 /*++
605
606 Routine Description:
607
608 Dispatch notifications.
609
610 Arguments:
611
612 PeiServices - Pointer to the PEI Service Table
613 NotifyType - Type of notify to fire.
614 InstallStartIndex - Install Beginning index.
615 InstallStopIndex - Install Ending index.
616 NotifyStartIndex - Notify Beginning index.
617 NotifyStopIndex - Notify Ending index.
618
619 Returns: None
620
621 --*/
622 ;
623
624 //
625 // Boot mode support functions
626 //
627 EFI_STATUS
628 EFIAPI
629 PeiGetBootMode (
630 IN CONST EFI_PEI_SERVICES **PeiServices,
631 IN OUT EFI_BOOT_MODE *BootMode
632 )
633 /*++
634
635 Routine Description:
636
637 This service enables PEIMs to ascertain the present value of the boot mode.
638
639 Arguments:
640
641 PeiServices - The PEI core services table.
642 BootMode - A pointer to contain the value of the boot mode.
643
644 Returns:
645
646 EFI_SUCCESS - The boot mode was returned successfully.
647 EFI_INVALID_PARAMETER - BootMode is NULL.
648
649 --*/
650 ;
651
652 EFI_STATUS
653 EFIAPI
654 PeiSetBootMode (
655 IN CONST EFI_PEI_SERVICES **PeiServices,
656 IN EFI_BOOT_MODE BootMode
657 )
658 /*++
659
660 Routine Description:
661
662 This service enables PEIMs to update the boot mode variable.
663
664 Arguments:
665
666 PeiServices - The PEI core services table.
667 BootMode - The value of the boot mode to set.
668
669 Returns:
670
671 EFI_SUCCESS - The value was successfully updated
672
673 --*/
674 ;
675
676 //
677 // Security support functions
678 //
679 VOID
680 InitializeSecurityServices (
681 IN EFI_PEI_SERVICES **PeiServices,
682 IN PEI_CORE_INSTANCE *OldCoreData
683 )
684 /*++
685
686 Routine Description:
687
688 Initialize the security services.
689
690 Arguments:
691
692 PeiServices - The PEI core services table.
693 OldCoreData - Pointer to the old core data.
694 NULL if being run in non-permament memory mode.
695 Returns:
696
697 None
698
699 --*/
700 ;
701
702 EFI_STATUS
703 VerifyFv (
704 IN EFI_FIRMWARE_VOLUME_HEADER *CurrentFvAddress
705 )
706 /*++
707
708 Routine Description:
709
710 Provide a callout to the OEM FV verification service.
711
712 Arguments:
713
714 CurrentFvAddress - Pointer to the FV under investigation.
715
716 Returns:
717
718 Status - EFI_SUCCESS
719
720 --*/
721 ;
722
723
724 EFI_STATUS
725 VerifyPeim (
726 IN PEI_CORE_INSTANCE *PrivateData,
727 IN EFI_PEI_FV_HANDLE VolumeHandle,
728 IN EFI_PEI_FILE_HANDLE FileHandle
729 )
730 /*++
731
732 Routine Description:
733
734 Provide a callout to the security verification service.
735
736 Arguments:
737
738 PeiServices - The PEI core services table.
739 CurrentPeimAddress - Pointer to the Firmware File under investigation.
740
741 Returns:
742
743 EFI_SUCCESS - Image is OK
744 EFI_SECURITY_VIOLATION - Image is illegal
745
746 --*/
747 ;
748
749
750 EFI_STATUS
751 EFIAPI
752 PeiGetHobList (
753 IN CONST EFI_PEI_SERVICES **PeiServices,
754 IN OUT VOID **HobList
755 )
756 /*++
757
758 Routine Description:
759
760 Gets the pointer to the HOB List.
761
762 Arguments:
763
764 PeiServices - The PEI core services table.
765 HobList - Pointer to the HOB List.
766
767 Returns:
768
769 EFI_SUCCESS - Get the pointer of HOB List
770 EFI_NOT_AVAILABLE_YET - the HOB List is not yet published
771 EFI_INVALID_PARAMETER - HobList is NULL (in debug mode)
772
773 --*/
774 ;
775
776 EFI_STATUS
777 EFIAPI
778 PeiCreateHob (
779 IN CONST EFI_PEI_SERVICES **PeiServices,
780 IN UINT16 Type,
781 IN UINT16 Length,
782 IN OUT VOID **Hob
783 )
784 /*++
785
786 Routine Description:
787
788 Add a new HOB to the HOB List.
789
790 Arguments:
791
792 PeiServices - The PEI core services table.
793 Type - Type of the new HOB.
794 Length - Length of the new HOB to allocate.
795 Hob - Pointer to the new HOB.
796
797 Returns:
798
799 Status - EFI_SUCCESS
800 - EFI_INVALID_PARAMETER if Hob is NULL
801 - EFI_NOT_AVAILABLE_YET if HobList is still not available.
802 - EFI_OUT_OF_RESOURCES if there is no more memory to grow the Hoblist.
803
804 --*/
805 ;
806
807 EFI_STATUS
808 PeiCoreBuildHobHandoffInfoTable (
809 IN EFI_BOOT_MODE BootMode,
810 IN EFI_PHYSICAL_ADDRESS MemoryBegin,
811 IN UINT64 MemoryLength
812 )
813 /*++
814
815 Routine Description:
816
817 Builds a Handoff Information Table HOB
818
819 Arguments:
820
821 BootMode - Current Bootmode
822 MemoryBegin - Start Memory Address.
823 MemoryLength - Length of Memory.
824
825 Returns:
826
827 EFI_SUCCESS
828
829 --*/
830 ;
831
832
833 //
834 // FFS Fw Volume support functions
835 //
836 EFI_STATUS
837 EFIAPI
838 PeiFfsFindNextFile (
839 IN CONST EFI_PEI_SERVICES **PeiServices,
840 IN UINT8 SearchType,
841 IN EFI_PEI_FV_HANDLE FwVolHeader,
842 IN OUT EFI_PEI_FILE_HANDLE *FileHeader
843 )
844 /*++
845
846 Routine Description:
847 Given the input file pointer, search for the next matching file in the
848 FFS volume as defined by SearchType. The search starts from FileHeader inside
849 the Firmware Volume defined by FwVolHeader.
850
851 Arguments:
852 PeiServices - Pointer to the PEI Core Services Table.
853
854 SearchType - Filter to find only files of this type.
855 Type EFI_FV_FILETYPE_ALL causes no filtering to be done.
856
857 FwVolHeader - Pointer to the FV header of the volume to search.
858 This parameter must point to a valid FFS volume.
859
860 FileHeader - Pointer to the current file from which to begin searching.
861 This pointer will be updated upon return to reflect the file found.
862
863 Returns:
864 EFI_NOT_FOUND - No files matching the search criteria were found
865 EFI_SUCCESS
866
867 --*/
868 ;
869
870 EFI_STATUS
871 EFIAPI
872 PeiFfsFindSectionData (
873 IN CONST EFI_PEI_SERVICES **PeiServices,
874 IN EFI_SECTION_TYPE SectionType,
875 IN EFI_PEI_FILE_HANDLE FfsFileHeader,
876 IN OUT VOID **SectionData
877 )
878 /*++
879
880 Routine Description:
881 Given the input file pointer, search for the next matching section in the
882 FFS volume.
883
884 Arguments:
885 PeiServices - Pointer to the PEI Core Services Table.
886 SearchType - Filter to find only sections of this type.
887 FfsFileHeader - Pointer to the current file to search.
888 SectionData - Pointer to the Section matching SectionType in FfsFileHeader.
889 - NULL if section not found
890
891 Returns:
892 EFI_NOT_FOUND - No files matching the search criteria were found
893 EFI_SUCCESS
894
895 --*/
896 ;
897
898 EFI_STATUS
899 EFIAPI
900 PeiFvFindNextVolume (
901 IN CONST EFI_PEI_SERVICES **PeiServices,
902 IN UINTN Instance,
903 IN OUT EFI_PEI_FV_HANDLE *FwVolHeader
904 )
905 /*++
906
907 Routine Description:
908
909 Return the BFV location
910
911 BugBug -- Move this to the location of this code to where the
912 other FV and FFS support code lives.
913 Also, update to use FindFV for instances #'s >= 1.
914
915 Arguments:
916
917 PeiServices - The PEI core services table.
918 Instance - Instance of FV to find
919 FwVolHeader - Pointer to contain the data to return
920
921 Returns:
922 Pointer to the Firmware Volume instance requested
923
924 EFI_INVALID_PARAMETER - FwVolHeader is NULL
925
926 EFI_SUCCESS - Firmware volume instance successfully found.
927
928 --*/
929 ;
930
931 //
932 // Memory support functions
933 //
934 VOID
935 InitializeMemoryServices (
936 IN PEI_CORE_INSTANCE *PrivateData,
937 IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData,
938 IN PEI_CORE_INSTANCE *OldCoreData
939 )
940 /*++
941
942 Routine Description:
943
944 Initialize the memory services.
945
946 Arguments:
947
948 PeiServices - The PEI core services table.
949 PeiStartupDescriptor - Information and services provided by SEC phase.
950 OldCoreData - Pointer to the PEI Core data.
951 NULL if being run in non-permament memory mode.
952
953 Returns:
954
955 None
956
957 --*/
958 ;
959
960 EFI_STATUS
961 EFIAPI
962 PeiInstallPeiMemory (
963 IN CONST EFI_PEI_SERVICES **PeiServices,
964 IN EFI_PHYSICAL_ADDRESS MemoryBegin,
965 IN UINT64 MemoryLength
966 )
967 /*++
968
969 Routine Description:
970
971 Install the permanent memory is now available.
972 Creates HOB (PHIT and Stack).
973
974 Arguments:
975
976 PeiServices - The PEI core services table.
977 MemoryBegin - Start of memory address.
978 MemoryLength - Length of memory.
979
980 Returns:
981
982 Status - EFI_SUCCESS
983
984 --*/
985 ;
986
987 EFI_STATUS
988 EFIAPI
989 PeiAllocatePages (
990 IN CONST EFI_PEI_SERVICES **PeiServices,
991 IN EFI_MEMORY_TYPE MemoryType,
992 IN UINTN Pages,
993 OUT EFI_PHYSICAL_ADDRESS *Memory
994 )
995 /*++
996
997 Routine Description:
998
999 Memory allocation service on permanent memory,
1000 not usable prior to the memory installation.
1001
1002 Arguments:
1003
1004 PeiServices - The PEI core services table.
1005 Type - Type of allocation.
1006 MemoryType - Type of memory to allocate.
1007 Pages - Number of pages to allocate.
1008 Memory - Pointer of memory allocated.
1009
1010 Returns:
1011
1012 Status - EFI_SUCCESS The allocation was successful
1013 EFI_INVALID_PARAMETER Only AllocateAnyAddress is supported.
1014 EFI_NOT_AVAILABLE_YET Called with permanent memory not available
1015 EFI_OUT_OF_RESOURCES There is not enough HOB heap to satisfy the requirement
1016 to allocate the number of pages.
1017
1018 --*/
1019 ;
1020
1021 EFI_STATUS
1022 EFIAPI
1023 PeiAllocatePool (
1024 IN CONST EFI_PEI_SERVICES **PeiServices,
1025 IN UINTN Size,
1026 OUT VOID **Buffer
1027 )
1028 /*++
1029
1030 Routine Description:
1031
1032 Memory allocation service on the CAR.
1033
1034 Arguments:
1035
1036 PeiServices - The PEI core services table.
1037
1038 Size - Amount of memory required
1039
1040 Buffer - Address of pointer to the buffer
1041
1042 Returns:
1043
1044 Status - EFI_SUCCESS The allocation was successful
1045 EFI_OUT_OF_RESOURCES There is not enough heap to satisfy the requirement
1046 to allocate the requested size.
1047
1048 --*/
1049 ;
1050
1051 EFI_STATUS
1052 PeiLoadImage (
1053 IN EFI_PEI_SERVICES **PeiServices,
1054 IN EFI_PEI_FILE_HANDLE FileHandle,
1055 OUT EFI_PHYSICAL_ADDRESS *EntryPoint,
1056 OUT UINT32 *AuthenticationState
1057 )
1058 /*++
1059
1060 Routine Description:
1061
1062 Get entry point of a Peim file.
1063
1064 Arguments:
1065
1066 PeiServices - Calling context.
1067
1068 PeimFileHeader - Peim file's header.
1069
1070 EntryPoint - Entry point of that Peim file.
1071
1072 Returns:
1073
1074 Status code.
1075
1076 --*/
1077 ;
1078
1079
1080 EFI_STATUS
1081 EFIAPI
1082 PeiReportStatusCode (
1083 IN CONST EFI_PEI_SERVICES **PeiServices,
1084 IN EFI_STATUS_CODE_TYPE CodeType,
1085 IN EFI_STATUS_CODE_VALUE Value,
1086 IN UINT32 Instance,
1087 IN CONST EFI_GUID *CallerId,
1088 IN CONST EFI_STATUS_CODE_DATA *Data OPTIONAL
1089 )
1090 /*++
1091
1092 Routine Description:
1093
1094 Core version of the Status Code reporter
1095
1096 Arguments:
1097
1098 PeiServices - The PEI core services table.
1099
1100 CodeType - Type of Status Code.
1101
1102 Value - Value to output for Status Code.
1103
1104 Instance - Instance Number of this status code.
1105
1106 CallerId - ID of the caller of this status code.
1107
1108 Data - Optional data associated with this status code.
1109
1110 Returns:
1111
1112 Status - EFI_SUCCESS if status code is successfully reported
1113 - EFI_NOT_AVAILABLE_YET if StatusCodePpi has not been installed
1114
1115 --*/
1116 ;
1117
1118
1119 EFI_STATUS
1120 EFIAPI
1121 PeiResetSystem (
1122 IN CONST EFI_PEI_SERVICES **PeiServices
1123 )
1124 /*++
1125
1126 Routine Description:
1127
1128 Core version of the Reset System
1129
1130 Arguments:
1131
1132 PeiServices - The PEI core services table.
1133
1134 Returns:
1135
1136 Status - EFI_NOT_AVAILABLE_YET. PPI not available yet.
1137 - EFI_DEVICE_ERROR. Did not reset system.
1138
1139 Otherwise, resets the system.
1140
1141 --*/
1142 ;
1143
1144 VOID
1145 PeiInitializeFv (
1146 IN PEI_CORE_INSTANCE *PrivateData,
1147 IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData
1148 )
1149 /*++
1150
1151 Routine Description:
1152
1153 Initialize PeiCore Fv List.
1154
1155 Arguments:
1156 PrivateData - Pointer to PEI_CORE_INSTANCE.
1157 SecCoreData - Pointer to EFI_SEC_PEI_HAND_OFF.
1158
1159 Returns:
1160 NONE
1161
1162 --*/
1163 ;
1164
1165 EFI_STATUS
1166 EFIAPI
1167 FirmwareVolmeInfoPpiNotifyCallback (
1168 IN EFI_PEI_SERVICES **PeiServices,
1169 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
1170 IN VOID *Ppi
1171 )
1172 /*++
1173
1174 Routine Description:
1175
1176 Process Firmware Volum Information once FvInfoPPI install.
1177
1178 Arguments:
1179
1180 PeiServices - General purpose services available to every PEIM.
1181
1182 Returns:
1183
1184 Status - EFI_SUCCESS if the interface could be successfully
1185 installed
1186
1187 --*/
1188 ;
1189
1190
1191 EFI_STATUS
1192 EFIAPI
1193 PeiFfsFindFileByName (
1194 IN CONST EFI_GUID *FileName,
1195 IN EFI_PEI_FV_HANDLE VolumeHandle,
1196 OUT EFI_PEI_FILE_HANDLE *FileHandle
1197 )
1198 /*++
1199
1200 Routine Description:
1201
1202 Given the input VolumeHandle, search for the next matching name file.
1203
1204 Arguments:
1205
1206 FileName - File name to search.
1207 VolumeHandle - The current FV to search.
1208 FileHandle - Pointer to the file matching name in VolumeHandle.
1209 - NULL if file not found
1210 Returns:
1211 EFI_STATUS
1212
1213 --*/
1214 ;
1215
1216
1217 EFI_STATUS
1218 EFIAPI
1219 PeiFfsGetFileInfo (
1220 IN EFI_PEI_FILE_HANDLE FileHandle,
1221 OUT EFI_FV_FILE_INFO *FileInfo
1222 )
1223 /*++
1224
1225 Routine Description:
1226
1227 Collect information of given file.
1228
1229 Arguments:
1230 FileHandle - The handle to file.
1231 FileInfo - Pointer to the file information.
1232
1233 Returns:
1234 EFI_STATUS
1235
1236 --*/
1237 ;
1238
1239 EFI_STATUS
1240 EFIAPI
1241 PeiFfsGetVolumeInfo (
1242 IN EFI_PEI_FV_HANDLE VolumeHandle,
1243 OUT EFI_FV_INFO *VolumeInfo
1244 )
1245 /*++
1246
1247 Routine Description:
1248
1249 Collect information of given Fv Volume.
1250
1251 Arguments:
1252 VolumeHandle - The handle to Fv Volume.
1253 VolumeInfo - The pointer to volume information.
1254
1255 Returns:
1256 EFI_STATUS
1257
1258 --*/
1259 ;
1260
1261
1262 EFI_STATUS
1263 EFIAPI
1264 PeiRegisterForShadow (
1265 IN EFI_PEI_FILE_HANDLE FileHandle
1266 )
1267 /*++
1268
1269 Routine Description:
1270
1271 This routine enable a PEIM to register itself to shadow when PEI Foundation
1272 discovery permanent memory.
1273
1274 Arguments:
1275 FileHandle - File handle of a PEIM.
1276
1277 Returns:
1278 EFI_NOT_FOUND - The file handle doesn't point to PEIM itself.
1279 EFI_ALREADY_STARTED - Indicate that the PEIM has been registered itself.
1280 EFI_SUCCESS - Successfully to register itself.
1281
1282 --*/
1283 ;
1284
1285
1286 /**
1287 This routine enable a PEIM to register itself to shadow when PEI Foundation
1288 discovery permanent memory.
1289
1290 @param FileHandle File handle of a PEIM.
1291
1292 @retval EFI_NOT_FOUND The file handle doesn't point to PEIM itself.
1293 @retval EFI_ALREADY_STARTED Indicate that the PEIM has been registered itself.
1294 @retval EFI_SUCCESS Successfully to register itself.
1295
1296 **/
1297 EFI_STATUS
1298 EFIAPI
1299 PeiRegisterForShadow (
1300 IN EFI_PEI_FILE_HANDLE FileHandle
1301 )
1302 ;
1303
1304 /**
1305 Transfers control to a function starting with a new stack.
1306
1307 Transfers control to the function specified by EntryPoint using the new stack
1308 specified by NewStack and passing in the parameters specified by Context1 and
1309 Context2. Context1 and Context2 are optional and may be NULL. The function
1310 EntryPoint must never return.
1311
1312 If EntryPoint is NULL, then ASSERT().
1313 If NewStack is NULL, then ASSERT().
1314
1315 @param EntryPoint A pointer to function to call with the new stack.
1316 @param Context1 A pointer to the context to pass into the EntryPoint
1317 function.
1318 @param Context2 A pointer to the context to pass into the EntryPoint
1319 function.
1320 @param NewStack A pointer to the new stack to use for the EntryPoint
1321 function.
1322 @param NewBsp A pointer to the new BSP for the EntryPoint on IPF. It's
1323 Reserved on other architectures.
1324
1325 **/
1326 VOID
1327 EFIAPI
1328 PeiSwitchStacks (
1329 IN SWITCH_STACK_ENTRY_POINT EntryPoint,
1330 IN VOID *Context1, OPTIONAL
1331 IN VOID *Context2, OPTIONAL
1332 IN VOID *NewStack,
1333 IN VOID *NewBsp
1334 );
1335
1336 EFI_STATUS
1337 PeiFindFileEx (
1338 IN CONST EFI_PEI_FV_HANDLE FvHandle,
1339 IN CONST EFI_GUID *FileName, OPTIONAL
1340 IN EFI_FV_FILETYPE SearchType,
1341 IN OUT EFI_PEI_FILE_HANDLE *FileHandle,
1342 IN OUT EFI_PEI_FV_HANDLE *AprioriFile OPTIONAL
1343 )
1344 /*++
1345
1346 Routine Description:
1347 Given the input file pointer, search for the next matching file in the
1348 FFS volume as defined by SearchType. The search starts from FileHeader inside
1349 the Firmware Volume defined by FwVolHeader.
1350
1351 Arguments:
1352 PeiServices - Pointer to the PEI Core Services Table.
1353 SearchType - Filter to find only files of this type.
1354 Type EFI_FV_FILETYPE_ALL causes no filtering to be done.
1355 FwVolHeader - Pointer to the FV header of the volume to search.
1356 This parameter must point to a valid FFS volume.
1357 FileHeader - Pointer to the current file from which to begin searching.
1358 This pointer will be updated upon return to reflect the file found.
1359 Flag - Indicator for if this is for PEI Dispath search
1360
1361 Returns:
1362 EFI_NOT_FOUND - No files matching the search criteria were found
1363 EFI_SUCCESS
1364
1365 --*/
1366 ;
1367
1368 VOID
1369 InitializeImageServices (
1370 IN PEI_CORE_INSTANCE *PrivateData,
1371 IN PEI_CORE_INSTANCE *OldCoreData
1372 )
1373 /*++
1374
1375 Routine Description:
1376
1377 Install Pei Load File PPI.
1378
1379 Arguments:
1380
1381 PrivateData - Pointer to PEI_CORE_INSTANCE.
1382 OldCoreData - Pointer to PEI_CORE_INSTANCE.
1383
1384 Returns:
1385
1386 NONE.
1387
1388 --*/
1389 ;
1390
1391 /**
1392 Get Fv image from the FV type file, then install FV INFO ppi, Build FV hob.
1393
1394 @param PeiServices Pointer to the PEI Core Services Table.
1395 @param FileHandle File handle of a Fv type file.
1396 @param AuthenticationState Pointer to attestation authentication state of image.
1397
1398
1399 @retval EFI_NOT_FOUND FV image can't be found.
1400 @retval EFI_SUCCESS Successfully to process it.
1401
1402 **/
1403 EFI_STATUS
1404 ProcessFvFile (
1405 IN EFI_PEI_SERVICES **PeiServices,
1406 IN EFI_PEI_FILE_HANDLE FvFileHandle,
1407 OUT UINT32 *AuthenticationState
1408 );
1409
1410 #endif