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