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
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
28 // Include common header file for this module.
30 #include "CommonHeader.h"
32 extern EFI_GUID gEfiPeiCorePrivateGuid
;
35 // Pei Core private data structures
38 EFI_PEI_PPI_DESCRIPTOR
*Ppi
;
39 EFI_PEI_NOTIFY_DESCRIPTOR
*Notify
;
41 } PEI_PPI_LIST_POINTERS
;
43 #define PEI_STACK_SIZE 0x20000
45 #define MAX_PPI_DESCRIPTORS 64
51 INTN LastDispatchedInstall
;
52 INTN LastDispatchedNotify
;
53 PEI_PPI_LIST_POINTERS PpiListPtrs
[MAX_PPI_DESCRIPTORS
];
59 UINT32 DispatchedPeimBitMap
;
60 UINT32 PreviousPeimBitMap
;
61 EFI_FFS_FILE_HEADER
*CurrentPeimAddress
;
62 EFI_FIRMWARE_VOLUME_HEADER
*CurrentFvAddress
;
63 EFI_FIRMWARE_VOLUME_HEADER
*BootFvAddress
;
64 EFI_PEI_FIND_FV_PPI
*FindFv
;
65 } PEI_CORE_DISPATCH_DATA
;
69 // Pei Core private data structure instance
72 #define PEI_CORE_HANDLE_SIGNATURE EFI_SIGNATURE_32('P','e','i','C')
76 EFI_PEI_SERVICES
*PS
; // Point to ServiceTableShadow
77 PEI_PPI_DATABASE PpiData
;
78 PEI_CORE_DISPATCH_DATA DispatchData
;
79 EFI_PEI_HOB_POINTERS HobList
;
80 BOOLEAN SwitchStackSignal
;
81 BOOLEAN PeiMemoryInstalled
;
82 EFI_PHYSICAL_ADDRESS StackBase
;
84 VOID
*BottomOfCarHeap
;
87 EFI_PEI_SECURITY_PPI
*PrivateSecurityPpi
;
88 EFI_PEI_SERVICES ServiceTableShadow
;
89 UINTN SizeOfCacheAsRam
;
90 VOID
*MaxTopOfCarHeap
;
94 // Pei Core Instance Data Macros
97 #define PEI_CORE_INSTANCE_FROM_PS_THIS(a) \
98 CR(a, PEI_CORE_INSTANCE, PS, PEI_CORE_HANDLE_SIGNATURE)
101 // BUGBUG: Where does this go really?
105 (EFIAPI
*PEI_CORE_ENTRY_POINT
)(
106 IN EFI_PEI_STARTUP_DESCRIPTOR
*PeiStartupDescriptor
,
107 IN PEI_CORE_INSTANCE
*OldCoreData
111 // Union of temporarily used function pointers (to save stack space)
114 PEI_CORE_ENTRY_POINT PeiCore
;
115 EFI_PEIM_ENTRY_POINT PeimEntry
;
116 EFI_PEIM_NOTIFY_ENTRY_POINT PeimNotifyEntry
;
117 EFI_DXE_IPL_PPI
*DxeIpl
;
118 EFI_PEI_PPI_DESCRIPTOR
*PpiDescriptor
;
119 EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
;
121 } PEI_CORE_TEMP_POINTERS
;
130 IN EFI_PEI_STARTUP_DESCRIPTOR
*PeiStartupDescriptor
,
137 The entry routine to Pei Core, invoked by PeiMain during transition
138 from SEC to PEI. After switching stack in the PEI core, it will restart
139 with the old core data.
143 PeiStartupDescriptor - Information and services provided by SEC phase.
144 OldCoreData - Pointer to old core data that is used to initialize the
149 This function never returns
150 EFI_NOT_FOUND - Never reach
156 // Dispatcher support functions
160 PeimDispatchReadiness (
161 IN EFI_PEI_SERVICES
**PeiServices
,
162 IN VOID
*DependencyExpression
,
163 IN OUT BOOLEAN
*Runnable
169 This is the POSTFIX version of the dependency evaluator. When a
170 PUSH [PPI GUID] is encountered, a pointer to the GUID is stored on
171 the evaluation stack. When that entry is poped from the evaluation
172 stack, the PPI is checked if it is installed. This method allows
173 some time savings as not all PPIs must be checked for certain
174 operation types (AND, OR).
178 PeiServices - Calling context.
180 DependencyExpression - Pointer to a dependency expression. The Grammar adheres to
181 the BNF described above and is stored in postfix notation.
182 Runnable - is True if the driver can be scheduled and False if the driver
183 cannot be scheduled. This is the value that the schedulers
184 should use for deciding the state of the driver.
188 Status = EFI_SUCCESS if it is a well-formed Grammar
189 EFI_INVALID_PARAMETER if the dependency expression overflows
191 EFI_INVALID_PARAMETER if the dependency expression underflows
193 EFI_INVALID_PARAMETER if the dependency expression is not a
201 IN EFI_PEI_STARTUP_DESCRIPTOR
*PeiStartupDescriptor
,
202 IN PEI_CORE_INSTANCE
*PrivateData
,
203 IN PEI_CORE_DISPATCH_DATA
*DispatchData
210 Conduct PEIM dispatch.
214 PeiStartupDescriptor - Pointer to IN EFI_PEI_STARTUP_DESCRIPTOR
215 PrivateData - Pointer to the private data passed in from caller
216 DispatchData - Pointer to PEI_CORE_DISPATCH_DATA data.
220 EFI_SUCCESS - Successfully dispatched PEIM.
221 EFI_NOT_FOUND - The dispatch failed.
228 InitializeDispatcherData (
229 IN EFI_PEI_SERVICES
**PeiServices
,
230 IN PEI_CORE_INSTANCE
*OldCoreData
,
231 IN EFI_PEI_STARTUP_DESCRIPTOR
*PeiStartupDescriptor
237 Initialize the Dispatcher's data members
241 PeiServices - The PEI core services table.
242 OldCoreData - Pointer to old core data (before switching stack).
243 NULL if being run in non-permament memory mode.
244 PeiStartupDescriptor - Information and services provided by SEC phase.
257 IN EFI_PEI_SERVICES
**PeiServices
,
258 IN EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
,
259 IN OUT EFI_FFS_FILE_HEADER
**PeimFileHeader
264 Given the input file pointer, search for the next matching file in the
265 FFS volume. The search starts from FileHeader inside
266 the Firmware Volume defined by FwVolHeader.
269 PeiServices - Pointer to the PEI Core Services Table.
271 FwVolHeader - Pointer to the FV header of the volume to search.
272 This parameter must point to a valid FFS volume.
274 PeimFileHeader - Pointer to the current file from which to begin searching.
275 This pointer will be updated upon return to reflect the file found.
278 EFI_NOT_FOUND - No files matching the search criteria were found
286 IN UINT8 CurrentPeim
,
287 IN UINT32 DispatchedPeimBitMap
293 This routine checks to see if a particular PEIM has been dispatched during
294 the PEI core dispatch.
297 CurrentPeim - The PEIM/FV in the bit array to check.
298 DispatchedPeimBitMap - Bit array, each bit corresponds to a PEIM/FV.
301 TRUE if PEIM already dispatched
309 IN EFI_PEI_SERVICES
**PeiServices
,
310 IN UINT8 CurrentPeim
,
311 OUT UINT32
*DispatchedPeimBitMap
317 This routine sets a PEIM as having been dispatched once its entry
318 point has been invoked.
322 PeiServices - The PEI core services table.
323 CurrentPeim - The PEIM/FV in the bit array to check.
324 DispatchedPeimBitMap - Bit array, each bit corresponds to a PEIM/FV.
334 IN EFI_PEI_SERVICES
**PeiServices
,
335 IN VOID
*CurrentPeimAddress
341 This routine parses the Dependency Expression, if available, and
342 decides if the module can be executed.
345 PeiServices - The PEI Service Table
346 CurrentPeimAddress - Address of the PEIM Firmware File under investigation
349 TRUE - Can be dispatched
350 FALSE - Cannot be dispatched
355 #if defined (MDE_CPU_IPF)
357 // In Ipf we should make special changes for the PHIT pointers to support
358 // recovery boot in cache mode.
360 #define SWITCH_TO_CACHE_MODE(CoreData) SwitchToCacheMode(CoreData)
361 #define CACHE_MODE_ADDRESS_MASK 0x7FFFFFFFFFFFFFFFULL
364 IN PEI_CORE_INSTANCE
*CoreData
370 Switch the PHIT pointers to cache mode after InstallPeiMemory in CAR.
374 CoreData - The PEI core Private Data
383 #define SWITCH_TO_CACHE_MODE(CoreData)
388 // PPI support functions
391 InitializePpiServices (
392 IN EFI_PEI_SERVICES
**PeiServices
,
393 IN PEI_CORE_INSTANCE
*OldCoreData
399 Initialize PPI services.
403 PeiServices - The PEI core services table.
404 OldCoreData - Pointer to the PEI Core data.
405 NULL if being run in non-permament memory mode.
415 IN EFI_PEI_SERVICES
**PeiServices
,
416 IN EFI_HOB_HANDOFF_INFO_TABLE
*OldHandOffHob
,
417 IN EFI_HOB_HANDOFF_INFO_TABLE
*NewHandOffHob
423 Migrate the Hob list from the CAR stack to PEI installed memory.
427 PeiServices - The PEI core services table.
428 OldHandOffHob - The old handoff HOB list.
429 NewHandOffHob - The new handoff HOB list.
439 IN EFI_PEI_SERVICES
**PeiServices
,
440 IN EFI_PEI_PPI_DESCRIPTOR
*PpiList
446 Install PPI services.
450 PeiServices - Pointer to the PEI Service Table
451 PpiList - Pointer to a list of PEI PPI Descriptors.
455 EFI_SUCCESS - if all PPIs in PpiList are successfully installed.
456 EFI_INVALID_PARAMETER - if PpiList is NULL pointer
457 EFI_INVALID_PARAMETER - if any PPI in PpiList is not valid
458 EFI_OUT_OF_RESOURCES - if there is no more memory resource to install PPI
466 IN EFI_PEI_SERVICES
**PeiServices
,
467 IN EFI_PEI_PPI_DESCRIPTOR
*OldPpi
,
468 IN EFI_PEI_PPI_DESCRIPTOR
*NewPpi
474 Re-Install PPI services.
478 PeiServices - Pointer to the PEI Service Table
479 OldPpi - Pointer to the old PEI PPI Descriptors.
480 NewPpi - Pointer to the new PEI PPI Descriptors.
484 EFI_SUCCESS - if the operation was successful
485 EFI_INVALID_PARAMETER - if OldPpi or NewPpi is NULL
486 EFI_INVALID_PARAMETER - if NewPpi is not valid
487 EFI_NOT_FOUND - if the PPI was not in the database
495 IN EFI_PEI_SERVICES
**PeiServices
,
498 IN OUT EFI_PEI_PPI_DESCRIPTOR
**PpiDescriptor
,
505 Locate a given named PPI.
509 PeiServices - Pointer to the PEI Service Table
510 Guid - Pointer to GUID of the PPI.
511 Instance - Instance Number to discover.
512 PpiDescriptor - Pointer to reference the found descriptor. If not NULL,
513 returns a pointer to the descriptor (includes flags, etc)
514 Ppi - Pointer to reference the found PPI
518 Status - EFI_SUCCESS if the PPI is in the database
519 EFI_NOT_FOUND if the PPI is not in the database
526 IN EFI_PEI_SERVICES
**PeiServices
,
527 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyList
533 Install a notification for a given PPI.
537 PeiServices - Pointer to the PEI Service Table
538 NotifyList - Pointer to list of Descriptors to notify upon.
542 Status - EFI_SUCCESS if successful
543 EFI_OUT_OF_RESOURCES if no space in the database
544 EFI_INVALID_PARAMETER if not a good decriptor
551 IN EFI_PEI_SERVICES
**PeiServices
557 Process the Notify List at dispatch level.
561 PeiServices - Pointer to the PEI Service Table
570 IN EFI_PEI_SERVICES
**PeiServices
,
572 IN INTN InstallStartIndex
,
573 IN INTN InstallStopIndex
,
574 IN INTN NotifyStartIndex
,
575 IN INTN NotifyStopIndex
581 Dispatch notifications.
585 PeiServices - Pointer to the PEI Service Table
586 NotifyType - Type of notify to fire.
587 InstallStartIndex - Install Beginning index.
588 InstallStopIndex - Install Ending index.
589 NotifyStartIndex - Notify Beginning index.
590 NotifyStopIndex - Notify Ending index.
598 // Boot mode support functions
603 IN EFI_PEI_SERVICES
**PeiServices
,
604 IN OUT EFI_BOOT_MODE
*BootMode
610 This service enables PEIMs to ascertain the present value of the boot mode.
614 PeiServices - The PEI core services table.
615 BootMode - A pointer to contain the value of the boot mode.
619 EFI_SUCCESS - The boot mode was returned successfully.
620 EFI_INVALID_PARAMETER - BootMode is NULL.
628 IN EFI_PEI_SERVICES
**PeiServices
,
629 IN EFI_BOOT_MODE BootMode
635 This service enables PEIMs to update the boot mode variable.
639 PeiServices - The PEI core services table.
640 BootMode - The value of the boot mode to set.
644 EFI_SUCCESS - The value was successfully updated
650 // Security support functions
653 InitializeSecurityServices (
654 IN EFI_PEI_SERVICES
**PeiServices
,
655 IN PEI_CORE_INSTANCE
*OldCoreData
661 Initialize the security services.
665 PeiServices - The PEI core services table.
666 OldCoreData - Pointer to the old core data.
667 NULL if being run in non-permament memory mode.
677 IN EFI_FIRMWARE_VOLUME_HEADER
*CurrentFvAddress
683 Provide a callout to the OEM FV verification service.
687 CurrentFvAddress - Pointer to the FV under investigation.
699 IN EFI_PEI_SERVICES
**PeiServices
,
700 IN EFI_FFS_FILE_HEADER
*CurrentPeimAddress
706 Provide a callout to the security verification service.
710 PeiServices - The PEI core services table.
711 CurrentPeimAddress - Pointer to the Firmware File under investigation.
715 EFI_SUCCESS - Image is OK
716 EFI_SECURITY_VIOLATION - Image is illegal
725 IN EFI_PEI_SERVICES
**PeiServices
,
726 IN OUT VOID
**HobList
732 Gets the pointer to the HOB List.
736 PeiServices - The PEI core services table.
737 HobList - Pointer to the HOB List.
741 EFI_SUCCESS - Get the pointer of HOB List
742 EFI_NOT_AVAILABLE_YET - the HOB List is not yet published
743 EFI_INVALID_PARAMETER - HobList is NULL (in debug mode)
751 IN EFI_PEI_SERVICES
**PeiServices
,
760 Add a new HOB to the HOB List.
764 PeiServices - The PEI core services table.
765 Type - Type of the new HOB.
766 Length - Length of the new HOB to allocate.
767 Hob - Pointer to the new HOB.
772 - EFI_INVALID_PARAMETER if Hob is NULL
773 - EFI_NOT_AVAILABLE_YET if HobList is still not available.
774 - EFI_OUT_OF_RESOURCES if there is no more memory to grow the Hoblist.
780 PeiCoreBuildHobHandoffInfoTable (
781 IN EFI_BOOT_MODE BootMode
,
782 IN EFI_PHYSICAL_ADDRESS MemoryBegin
,
783 IN UINT64 MemoryLength
789 Builds a Handoff Information Table HOB
793 BootMode - Current Bootmode
794 MemoryBegin - Start Memory Address.
795 MemoryLength - Length of Memory.
806 // FFS Fw Volume support functions
811 IN EFI_PEI_SERVICES
**PeiServices
,
813 IN EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
,
814 IN OUT EFI_FFS_FILE_HEADER
**FileHeader
819 Given the input file pointer, search for the next matching file in the
820 FFS volume as defined by SearchType. The search starts from FileHeader inside
821 the Firmware Volume defined by FwVolHeader.
824 PeiServices - Pointer to the PEI Core Services Table.
826 SearchType - Filter to find only files of this type.
827 Type EFI_FV_FILETYPE_ALL causes no filtering to be done.
829 FwVolHeader - Pointer to the FV header of the volume to search.
830 This parameter must point to a valid FFS volume.
832 FileHeader - Pointer to the current file from which to begin searching.
833 This pointer will be updated upon return to reflect the file found.
836 EFI_NOT_FOUND - No files matching the search criteria were found
844 PeiFfsFindSectionData (
845 IN EFI_PEI_SERVICES
**PeiServices
,
846 IN EFI_SECTION_TYPE SectionType
,
847 IN EFI_FFS_FILE_HEADER
*FfsFileHeader
,
848 IN OUT VOID
**SectionData
853 Given the input file pointer, search for the next matching section in the
857 PeiServices - Pointer to the PEI Core Services Table.
858 SearchType - Filter to find only sections of this type.
859 FfsFileHeader - Pointer to the current file to search.
860 SectionData - Pointer to the Section matching SectionType in FfsFileHeader.
861 - NULL if section not found
864 EFI_NOT_FOUND - No files matching the search criteria were found
872 PeiFvFindNextVolume (
873 IN EFI_PEI_SERVICES
**PeiServices
,
875 IN OUT EFI_FIRMWARE_VOLUME_HEADER
**FwVolHeader
881 Return the BFV location
883 BugBug -- Move this to the location of this code to where the
884 other FV and FFS support code lives.
885 Also, update to use FindFV for instances #'s >= 1.
889 PeiServices - The PEI core services table.
890 Instance - Instance of FV to find
891 FwVolHeader - Pointer to contain the data to return
894 Pointer to the Firmware Volume instance requested
896 EFI_INVALID_PARAMETER - FwVolHeader is NULL
898 EFI_SUCCESS - Firmware volume instance successfully found.
904 // Memory support functions
907 InitializeMemoryServices (
908 IN EFI_PEI_SERVICES
**PeiServices
,
909 IN EFI_PEI_STARTUP_DESCRIPTOR
*PeiStartupDescriptor
,
910 IN PEI_CORE_INSTANCE
*OldCoreData
916 Initialize the memory services.
920 PeiServices - The PEI core services table.
921 PeiStartupDescriptor - Information and services provided by SEC phase.
922 OldCoreData - Pointer to the PEI Core data.
923 NULL if being run in non-permament memory mode.
934 PeiInstallPeiMemory (
935 IN EFI_PEI_SERVICES
**PeiServices
,
936 IN EFI_PHYSICAL_ADDRESS MemoryBegin
,
937 IN UINT64 MemoryLength
943 Install the permanent memory is now available.
944 Creates HOB (PHIT and Stack).
948 PeiServices - The PEI core services table.
949 MemoryBegin - Start of memory address.
950 MemoryLength - Length of memory.
962 IN EFI_PEI_SERVICES
**PeiServices
,
963 IN EFI_MEMORY_TYPE MemoryType
,
965 OUT EFI_PHYSICAL_ADDRESS
*Memory
971 Memory allocation service on permanent memory,
972 not usable prior to the memory installation.
976 PeiServices - The PEI core services table.
977 Type - Type of allocation.
978 MemoryType - Type of memory to allocate.
979 Pages - Number of pages to allocate.
980 Memory - Pointer of memory allocated.
984 Status - EFI_SUCCESS The allocation was successful
985 EFI_INVALID_PARAMETER Only AllocateAnyAddress is supported.
986 EFI_NOT_AVAILABLE_YET Called with permanent memory not available
987 EFI_OUT_OF_RESOURCES There is not enough HOB heap to satisfy the requirement
988 to allocate the number of pages.
996 IN EFI_PEI_SERVICES
**PeiServices
,
1002 Routine Description:
1004 Memory allocation service on the CAR.
1008 PeiServices - The PEI core services table.
1010 Size - Amount of memory required
1012 Buffer - Address of pointer to the buffer
1016 Status - EFI_SUCCESS The allocation was successful
1017 EFI_OUT_OF_RESOURCES There is not enough heap to satisfy the requirement
1018 to allocate the requested size.
1025 IN EFI_PEI_SERVICES
**PeiServices
,
1026 IN EFI_FFS_FILE_HEADER
*PeimFileHeader
,
1027 OUT VOID
**EntryPoint
1031 Routine Description:
1033 Get entry point of a Peim file.
1037 PeiServices - Calling context.
1039 PeimFileHeader - Peim file's header.
1041 EntryPoint - Entry point of that Peim file.
1053 PeiReportStatusCode (
1054 IN EFI_PEI_SERVICES
**PeiServices
,
1055 IN EFI_STATUS_CODE_TYPE CodeType
,
1056 IN EFI_STATUS_CODE_VALUE Value
,
1058 IN EFI_GUID
*CallerId
,
1059 IN EFI_STATUS_CODE_DATA
*Data OPTIONAL
1063 Routine Description:
1065 Core version of the Status Code reporter
1069 PeiServices - The PEI core services table.
1071 CodeType - Type of Status Code.
1073 Value - Value to output for Status Code.
1075 Instance - Instance Number of this status code.
1077 CallerId - ID of the caller of this status code.
1079 Data - Optional data associated with this status code.
1083 Status - EFI_SUCCESS if status code is successfully reported
1084 - EFI_NOT_AVAILABLE_YET if StatusCodePpi has not been installed
1093 IN EFI_PEI_SERVICES
**PeiServices
1097 Routine Description:
1099 Core version of the Reset System
1103 PeiServices - The PEI core services table.
1107 Status - EFI_NOT_AVAILABLE_YET. PPI not available yet.
1108 - EFI_DEVICE_ERROR. Did not reset system.
1110 Otherwise, resets the system.
1116 Transfers control to a function starting with a new stack.
1118 Transfers control to the function specified by EntryPoint using the new stack
1119 specified by NewStack and passing in the parameters specified by Context1 and
1120 Context2. Context1 and Context2 are optional and may be NULL. The function
1121 EntryPoint must never return.
1123 If EntryPoint is NULL, then ASSERT().
1124 If NewStack is NULL, then ASSERT().
1126 @param EntryPoint A pointer to function to call with the new stack.
1127 @param Context1 A pointer to the context to pass into the EntryPoint
1129 @param Context2 A pointer to the context to pass into the EntryPoint
1131 @param NewStack A pointer to the new stack to use for the EntryPoint
1133 @param NewBsp A pointer to the new BSP for the EntryPoint on IPF. It's
1134 Reserved on other architectures.
1140 IN SWITCH_STACK_ENTRY_POINT EntryPoint
,
1141 IN VOID
*Context1
, OPTIONAL
1142 IN VOID
*Context2
, OPTIONAL