3 Copyright (c) 2006, 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
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.
18 Definition of Pei Core Structures and Services
32 //Build private HOB to PEI core to transfer old NEM-range data to new NEM-range
34 #define EFI_PEI_CORE_PRIVATE_GUID \
35 {0xd641a0f5, 0xcb7c, 0x4846, { 0xa3, 0x80, 0x1d, 0x01, 0xb4, 0xd9, 0xe3, 0xb9 } }
38 // Pei Core private data structures
41 EFI_PEI_PPI_DESCRIPTOR
*Ppi
;
42 EFI_PEI_NOTIFY_DESCRIPTOR
*Notify
;
44 } PEI_PPI_LIST_POINTERS
;
46 #define PEI_STACK_SIZE 0x20000
48 #define MAX_PPI_DESCRIPTORS 64
54 INTN LastDispatchedInstall
;
55 INTN LastDispatchedNotify
;
56 PEI_PPI_LIST_POINTERS PpiListPtrs
[MAX_PPI_DESCRIPTORS
];
62 UINT32 DispatchedPeimBitMap
;
63 UINT32 PreviousPeimBitMap
;
64 EFI_FFS_FILE_HEADER
*CurrentPeimAddress
;
65 EFI_FIRMWARE_VOLUME_HEADER
*CurrentFvAddress
;
66 EFI_FIRMWARE_VOLUME_HEADER
*BootFvAddress
;
67 EFI_PEI_FIND_FV_PPI
*FindFv
;
68 } PEI_CORE_DISPATCH_DATA
;
72 // Pei Core private data structure instance
75 #define PEI_CORE_HANDLE_SIGNATURE EFI_SIGNATURE_32('P','e','i','C')
79 EFI_PEI_SERVICES
*PS
; // Point to ServiceTableShadow
80 PEI_PPI_DATABASE PpiData
;
81 PEI_CORE_DISPATCH_DATA DispatchData
;
82 EFI_PEI_HOB_POINTERS HobList
;
83 BOOLEAN SwitchStackSignal
;
84 BOOLEAN PeiMemoryInstalled
;
85 EFI_PHYSICAL_ADDRESS StackBase
;
87 VOID
*BottomOfCarHeap
;
90 EFI_PEI_SECURITY_PPI
*PrivateSecurityPpi
;
91 EFI_PEI_SERVICES ServiceTableShadow
;
92 UINTN SizeOfCacheAsRam
;
93 VOID
*MaxTopOfCarHeap
;
97 // Pei Core Instance Data Macros
100 #define PEI_CORE_INSTANCE_FROM_PS_THIS(a) \
101 CR(a, PEI_CORE_INSTANCE, PS, PEI_CORE_HANDLE_SIGNATURE)
104 // BUGBUG: Where does this go really?
108 (EFIAPI
*PEI_CORE_ENTRY_POINT
)(
109 IN EFI_PEI_STARTUP_DESCRIPTOR
*PeiStartupDescriptor
,
110 IN PEI_CORE_INSTANCE
*OldCoreData
114 // Union of temporarily used function pointers (to save stack space)
117 PEI_CORE_ENTRY_POINT PeiCore
;
118 EFI_PEIM_ENTRY_POINT PeimEntry
;
119 EFI_PEIM_NOTIFY_ENTRY_POINT PeimNotifyEntry
;
120 EFI_DXE_IPL_PPI
*DxeIpl
;
121 EFI_PEI_PPI_DESCRIPTOR
*PpiDescriptor
;
122 EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
;
124 } PEI_CORE_TEMP_POINTERS
;
133 IN EFI_PEI_STARTUP_DESCRIPTOR
*PeiStartupDescriptor
139 Main entry point to Pei Core.
143 PeiStartupDescriptor - Information and services provided by SEC phase.
147 This function never returns
156 IN EFI_PEI_STARTUP_DESCRIPTOR
*PeiStartupDescriptor
,
157 IN PEI_CORE_INSTANCE
*OldCoreData
163 The entry routine to Pei Core, invoked by PeiMain during transition
164 from SEC to PEI. After switching stack in the PEI core, it will restart
165 with the old core data.
169 PeiStartupDescriptor - Information and services provided by SEC phase.
170 OldCoreData - Pointer to old core data that is used to initialize the
175 This function never returns
182 // Dispatcher support functions
186 PeimDispatchReadiness (
187 IN EFI_PEI_SERVICES
**PeiServices
,
188 IN VOID
*DependencyExpression
,
189 IN OUT BOOLEAN
*Runnable
195 This is the POSTFIX version of the dependency evaluator. When a
196 PUSH [PPI GUID] is encountered, a pointer to the GUID is stored on
197 the evaluation stack. When that entry is poped from the evaluation
198 stack, the PPI is checked if it is installed. This method allows
199 some time savings as not all PPIs must be checked for certain
200 operation types (AND, OR).
204 PeiServices - Calling context.
206 DependencyExpression - Pointer to a dependency expression. The Grammar adheres to
207 the BNF described above and is stored in postfix notation.
208 Runnable - is True if the driver can be scheduled and False if the driver
209 cannot be scheduled. This is the value that the schedulers
210 should use for deciding the state of the driver.
214 Status = EFI_SUCCESS if it is a well-formed Grammar
215 EFI_INVALID_PARAMETER if the dependency expression overflows
217 EFI_INVALID_PARAMETER if the dependency expression underflows
219 EFI_INVALID_PARAMETER if the dependency expression is not a
227 IN EFI_PEI_STARTUP_DESCRIPTOR
*PeiStartupDescriptor
,
228 IN PEI_CORE_INSTANCE
*PrivateData
,
229 IN PEI_CORE_DISPATCH_DATA
*DispatchData
236 Conduct PEIM dispatch.
240 PeiStartupDescriptor - Pointer to IN EFI_PEI_STARTUP_DESCRIPTOR
241 PrivateData - Pointer to the private data passed in from caller
242 DispatchData - Pointer to PEI_CORE_DISPATCH_DATA data.
246 EFI_SUCCESS - Successfully dispatched PEIM.
247 EFI_NOT_FOUND - The dispatch failed.
254 InitializeDispatcherData (
255 IN EFI_PEI_SERVICES
**PeiServices
,
256 IN PEI_CORE_INSTANCE
*OldCoreData
,
257 IN EFI_PEI_STARTUP_DESCRIPTOR
*PeiStartupDescriptor
263 Initialize the Dispatcher's data members
267 PeiServices - The PEI core services table.
268 OldCoreData - Pointer to old core data (before switching stack).
269 NULL if being run in non-permament memory mode.
270 PeiStartupDescriptor - Information and services provided by SEC phase.
283 IN EFI_PEI_SERVICES
**PeiServices
,
284 IN EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
,
285 IN OUT EFI_FFS_FILE_HEADER
**PeimFileHeader
290 Given the input file pointer, search for the next matching file in the
291 FFS volume. The search starts from FileHeader inside
292 the Firmware Volume defined by FwVolHeader.
295 PeiServices - Pointer to the PEI Core Services Table.
297 FwVolHeader - Pointer to the FV header of the volume to search.
298 This parameter must point to a valid FFS volume.
300 PeimFileHeader - Pointer to the current file from which to begin searching.
301 This pointer will be updated upon return to reflect the file found.
304 EFI_NOT_FOUND - No files matching the search criteria were found
312 IN UINT8 CurrentPeim
,
313 IN UINT32 DispatchedPeimBitMap
319 This routine checks to see if a particular PEIM has been dispatched during
320 the PEI core dispatch.
323 CurrentPeim - The PEIM/FV in the bit array to check.
324 DispatchedPeimBitMap - Bit array, each bit corresponds to a PEIM/FV.
327 TRUE if PEIM already dispatched
335 IN EFI_PEI_SERVICES
**PeiServices
,
336 IN UINT8 CurrentPeim
,
337 OUT UINT32
*DispatchedPeimBitMap
343 This routine sets a PEIM as having been dispatched once its entry
344 point has been invoked.
348 PeiServices - The PEI core services table.
349 CurrentPeim - The PEIM/FV in the bit array to check.
350 DispatchedPeimBitMap - Bit array, each bit corresponds to a PEIM/FV.
360 IN EFI_PEI_SERVICES
**PeiServices
,
361 IN VOID
*CurrentPeimAddress
367 This routine parses the Dependency Expression, if available, and
368 decides if the module can be executed.
371 PeiServices - The PEI Service Table
372 CurrentPeimAddress - Address of the PEIM Firmware File under investigation
375 TRUE - Can be dispatched
376 FALSE - Cannot be dispatched
383 // In Ipf we should make special changes for the PHIT pointers to support
384 // recovery boot in cache mode.
386 #define SWITCH_TO_CACHE_MODE(CoreData) SwitchToCacheMode(CoreData)
387 #define CACHE_MODE_ADDRESS_MASK 0x7FFFFFFFFFFFFFFFULL
390 IN PEI_CORE_INSTANCE
*CoreData
396 Switch the PHIT pointers to cache mode after InstallPeiMemory in CAR.
400 CoreData - The PEI core Private Data
409 #define SWITCH_TO_CACHE_MODE(CoreData)
414 // PPI support functions
417 InitializePpiServices (
418 IN EFI_PEI_SERVICES
**PeiServices
,
419 IN PEI_CORE_INSTANCE
*OldCoreData
425 Initialize PPI services.
429 PeiServices - The PEI core services table.
430 OldCoreData - Pointer to the PEI Core data.
431 NULL if being run in non-permament memory mode.
441 IN EFI_PEI_SERVICES
**PeiServices
,
442 IN EFI_HOB_HANDOFF_INFO_TABLE
*OldHandOffHob
,
443 IN EFI_HOB_HANDOFF_INFO_TABLE
*NewHandOffHob
449 Migrate the Hob list from the CAR stack to PEI installed memory.
453 PeiServices - The PEI core services table.
454 OldHandOffHob - The old handoff HOB list.
455 NewHandOffHob - The new handoff HOB list.
465 IN EFI_PEI_SERVICES
**PeiServices
,
466 IN EFI_PEI_PPI_DESCRIPTOR
*PpiList
472 Install PPI services.
476 PeiServices - Pointer to the PEI Service Table
477 PpiList - Pointer to a list of PEI PPI Descriptors.
481 EFI_SUCCESS - if all PPIs in PpiList are successfully installed.
482 EFI_INVALID_PARAMETER - if PpiList is NULL pointer
483 EFI_INVALID_PARAMETER - if any PPI in PpiList is not valid
484 EFI_OUT_OF_RESOURCES - if there is no more memory resource to install PPI
492 IN EFI_PEI_SERVICES
**PeiServices
,
493 IN EFI_PEI_PPI_DESCRIPTOR
*OldPpi
,
494 IN EFI_PEI_PPI_DESCRIPTOR
*NewPpi
500 Re-Install PPI services.
504 PeiServices - Pointer to the PEI Service Table
505 OldPpi - Pointer to the old PEI PPI Descriptors.
506 NewPpi - Pointer to the new PEI PPI Descriptors.
510 EFI_SUCCESS - if the operation was successful
511 EFI_INVALID_PARAMETER - if OldPpi or NewPpi is NULL
512 EFI_INVALID_PARAMETER - if NewPpi is not valid
513 EFI_NOT_FOUND - if the PPI was not in the database
521 IN EFI_PEI_SERVICES
**PeiServices
,
524 IN OUT EFI_PEI_PPI_DESCRIPTOR
**PpiDescriptor
,
531 Locate a given named PPI.
535 PeiServices - Pointer to the PEI Service Table
536 Guid - Pointer to GUID of the PPI.
537 Instance - Instance Number to discover.
538 PpiDescriptor - Pointer to reference the found descriptor. If not NULL,
539 returns a pointer to the descriptor (includes flags, etc)
540 Ppi - Pointer to reference the found PPI
544 Status - EFI_SUCCESS if the PPI is in the database
545 EFI_NOT_FOUND if the PPI is not in the database
552 IN EFI_PEI_SERVICES
**PeiServices
,
553 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyList
559 Install a notification for a given PPI.
563 PeiServices - Pointer to the PEI Service Table
564 NotifyList - Pointer to list of Descriptors to notify upon.
568 Status - EFI_SUCCESS if successful
569 EFI_OUT_OF_RESOURCES if no space in the database
570 EFI_INVALID_PARAMETER if not a good decriptor
577 IN EFI_PEI_SERVICES
**PeiServices
583 Process the Notify List at dispatch level.
587 PeiServices - Pointer to the PEI Service Table
596 IN EFI_PEI_SERVICES
**PeiServices
,
598 IN INTN InstallStartIndex
,
599 IN INTN InstallStopIndex
,
600 IN INTN NotifyStartIndex
,
601 IN INTN NotifyStopIndex
607 Dispatch notifications.
611 PeiServices - Pointer to the PEI Service Table
612 NotifyType - Type of notify to fire.
613 InstallStartIndex - Install Beginning index.
614 InstallStopIndex - Install Ending index.
615 NotifyStartIndex - Notify Beginning index.
616 NotifyStopIndex - Notify Ending index.
624 // Boot mode support functions
629 IN EFI_PEI_SERVICES
**PeiServices
,
630 IN OUT EFI_BOOT_MODE
*BootMode
636 This service enables PEIMs to ascertain the present value of the boot mode.
640 PeiServices - The PEI core services table.
641 BootMode - A pointer to contain the value of the boot mode.
645 EFI_SUCCESS - The boot mode was returned successfully.
646 EFI_INVALID_PARAMETER - BootMode is NULL.
654 IN EFI_PEI_SERVICES
**PeiServices
,
655 IN EFI_BOOT_MODE BootMode
661 This service enables PEIMs to update the boot mode variable.
665 PeiServices - The PEI core services table.
666 BootMode - The value of the boot mode to set.
670 EFI_SUCCESS - The value was successfully updated
676 // Security support functions
679 InitializeSecurityServices (
680 IN EFI_PEI_SERVICES
**PeiServices
,
681 IN PEI_CORE_INSTANCE
*OldCoreData
687 Initialize the security services.
691 PeiServices - The PEI core services table.
692 OldCoreData - Pointer to the old core data.
693 NULL if being run in non-permament memory mode.
703 IN EFI_FIRMWARE_VOLUME_HEADER
*CurrentFvAddress
709 Provide a callout to the OEM FV verification service.
713 CurrentFvAddress - Pointer to the FV under investigation.
725 IN EFI_PEI_SERVICES
**PeiServices
,
726 IN EFI_FFS_FILE_HEADER
*CurrentPeimAddress
732 Provide a callout to the security verification service.
736 PeiServices - The PEI core services table.
737 CurrentPeimAddress - Pointer to the Firmware File under investigation.
741 EFI_SUCCESS - Image is OK
742 EFI_SECURITY_VIOLATION - Image is illegal
751 IN EFI_PEI_SERVICES
**PeiServices
,
752 IN OUT VOID
**HobList
758 Gets the pointer to the HOB List.
762 PeiServices - The PEI core services table.
763 HobList - Pointer to the HOB List.
767 EFI_SUCCESS - Get the pointer of HOB List
768 EFI_NOT_AVAILABLE_YET - the HOB List is not yet published
769 EFI_INVALID_PARAMETER - HobList is NULL (in debug mode)
777 IN EFI_PEI_SERVICES
**PeiServices
,
786 Add a new HOB to the HOB List.
790 PeiServices - The PEI core services table.
791 Type - Type of the new HOB.
792 Length - Length of the new HOB to allocate.
793 Hob - Pointer to the new HOB.
798 - EFI_INVALID_PARAMETER if Hob is NULL
799 - EFI_NOT_AVAILABLE_YET if HobList is still not available.
800 - EFI_OUT_OF_RESOURCES if there is no more memory to grow the Hoblist.
806 PeiCoreBuildHobHandoffInfoTable (
807 IN EFI_BOOT_MODE BootMode
,
808 IN EFI_PHYSICAL_ADDRESS MemoryBegin
,
809 IN UINT64 MemoryLength
815 Builds a Handoff Information Table HOB
819 BootMode - Current Bootmode
820 MemoryBegin - Start Memory Address.
821 MemoryLength - Length of Memory.
832 // FFS Fw Volume support functions
837 IN EFI_PEI_SERVICES
**PeiServices
,
839 IN EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
,
840 IN OUT EFI_FFS_FILE_HEADER
**FileHeader
845 Given the input file pointer, search for the next matching file in the
846 FFS volume as defined by SearchType. The search starts from FileHeader inside
847 the Firmware Volume defined by FwVolHeader.
850 PeiServices - Pointer to the PEI Core Services Table.
852 SearchType - Filter to find only files of this type.
853 Type EFI_FV_FILETYPE_ALL causes no filtering to be done.
855 FwVolHeader - Pointer to the FV header of the volume to search.
856 This parameter must point to a valid FFS volume.
858 FileHeader - Pointer to the current file from which to begin searching.
859 This pointer will be updated upon return to reflect the file found.
862 EFI_NOT_FOUND - No files matching the search criteria were found
870 PeiFfsFindSectionData (
871 IN EFI_PEI_SERVICES
**PeiServices
,
872 IN EFI_SECTION_TYPE SectionType
,
873 IN EFI_FFS_FILE_HEADER
*FfsFileHeader
,
874 IN OUT VOID
**SectionData
879 Given the input file pointer, search for the next matching section in the
883 PeiServices - Pointer to the PEI Core Services Table.
884 SearchType - Filter to find only sections of this type.
885 FfsFileHeader - Pointer to the current file to search.
886 SectionData - Pointer to the Section matching SectionType in FfsFileHeader.
887 - NULL if section not found
890 EFI_NOT_FOUND - No files matching the search criteria were found
898 PeiFvFindNextVolume (
899 IN EFI_PEI_SERVICES
**PeiServices
,
901 IN OUT EFI_FIRMWARE_VOLUME_HEADER
**FwVolHeader
907 Return the BFV location
909 BugBug -- Move this to the location of this code to where the
910 other FV and FFS support code lives.
911 Also, update to use FindFV for instances #'s >= 1.
915 PeiServices - The PEI core services table.
916 Instance - Instance of FV to find
917 FwVolHeader - Pointer to contain the data to return
920 Pointer to the Firmware Volume instance requested
922 EFI_INVALID_PARAMETER - FwVolHeader is NULL
924 EFI_SUCCESS - Firmware volume instance successfully found.
930 // Memory support functions
933 InitializeMemoryServices (
934 IN EFI_PEI_SERVICES
**PeiServices
,
935 IN EFI_PEI_STARTUP_DESCRIPTOR
*PeiStartupDescriptor
,
936 IN PEI_CORE_INSTANCE
*OldCoreData
942 Initialize the memory services.
946 PeiServices - The PEI core services table.
947 PeiStartupDescriptor - Information and services provided by SEC phase.
948 OldCoreData - Pointer to the PEI Core data.
949 NULL if being run in non-permament memory mode.
960 PeiInstallPeiMemory (
961 IN EFI_PEI_SERVICES
**PeiServices
,
962 IN EFI_PHYSICAL_ADDRESS MemoryBegin
,
963 IN UINT64 MemoryLength
969 Install the permanent memory is now available.
970 Creates HOB (PHIT and Stack).
974 PeiServices - The PEI core services table.
975 MemoryBegin - Start of memory address.
976 MemoryLength - Length of memory.
988 IN EFI_PEI_SERVICES
**PeiServices
,
989 IN EFI_MEMORY_TYPE MemoryType
,
991 OUT EFI_PHYSICAL_ADDRESS
*Memory
997 Memory allocation service on permanent memory,
998 not usable prior to the memory installation.
1002 PeiServices - The PEI core services table.
1003 Type - Type of allocation.
1004 MemoryType - Type of memory to allocate.
1005 Pages - Number of pages to allocate.
1006 Memory - Pointer of memory allocated.
1010 Status - EFI_SUCCESS The allocation was successful
1011 EFI_INVALID_PARAMETER Only AllocateAnyAddress is supported.
1012 EFI_NOT_AVAILABLE_YET Called with permanent memory not available
1013 EFI_OUT_OF_RESOURCES There is not enough HOB heap to satisfy the requirement
1014 to allocate the number of pages.
1022 IN EFI_PEI_SERVICES
**PeiServices
,
1028 Routine Description:
1030 Memory allocation service on the CAR.
1034 PeiServices - The PEI core services table.
1036 Size - Amount of memory required
1038 Buffer - Address of pointer to the buffer
1042 Status - EFI_SUCCESS The allocation was successful
1043 EFI_OUT_OF_RESOURCES There is not enough heap to satisfy the requirement
1044 to allocate the requested size.
1051 IN EFI_PEI_SERVICES
**PeiServices
,
1052 IN EFI_FFS_FILE_HEADER
*PeimFileHeader
,
1053 OUT VOID
**EntryPoint
1057 Routine Description:
1059 Get entry point of a Peim file.
1063 PeiServices - Calling context.
1065 PeimFileHeader - Peim file's header.
1067 EntryPoint - Entry point of that Peim file.
1079 PeiReportStatusCode (
1080 IN EFI_PEI_SERVICES
**PeiServices
,
1081 IN EFI_STATUS_CODE_TYPE CodeType
,
1082 IN EFI_STATUS_CODE_VALUE Value
,
1084 IN EFI_GUID
*CallerId
,
1085 IN EFI_STATUS_CODE_DATA
*Data OPTIONAL
1089 Routine Description:
1091 Core version of the Status Code reporter
1095 PeiServices - The PEI core services table.
1097 CodeType - Type of Status Code.
1099 Value - Value to output for Status Code.
1101 Instance - Instance Number of this status code.
1103 CallerId - ID of the caller of this status code.
1105 Data - Optional data associated with this status code.
1109 Status - EFI_SUCCESS if status code is successfully reported
1110 - EFI_NOT_AVAILABLE_YET if StatusCodePpi has not been installed
1119 IN EFI_PEI_SERVICES
**PeiServices
1123 Routine Description:
1125 Core version of the Reset System
1129 PeiServices - The PEI core services table.
1133 Status - EFI_NOT_AVAILABLE_YET. PPI not available yet.
1134 - EFI_DEVICE_ERROR. Did not reset system.
1136 Otherwise, resets the system.