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