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