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
27 extern EFI_GUID gEfiPeiCorePrivateGuid
;
30 // Pei Core private data structures
33 EFI_PEI_PPI_DESCRIPTOR
*Ppi
;
34 EFI_PEI_NOTIFY_DESCRIPTOR
*Notify
;
36 } PEI_PPI_LIST_POINTERS
;
38 #define PEI_STACK_SIZE 0x20000
40 #define MAX_PPI_DESCRIPTORS 64
46 INTN LastDispatchedInstall
;
47 INTN LastDispatchedNotify
;
48 PEI_PPI_LIST_POINTERS PpiListPtrs
[MAX_PPI_DESCRIPTORS
];
54 UINT32 DispatchedPeimBitMap
;
55 UINT32 PreviousPeimBitMap
;
56 EFI_FFS_FILE_HEADER
*CurrentPeimAddress
;
57 EFI_FIRMWARE_VOLUME_HEADER
*CurrentFvAddress
;
58 EFI_FIRMWARE_VOLUME_HEADER
*BootFvAddress
;
59 EFI_PEI_FIND_FV_PPI
*FindFv
;
60 } PEI_CORE_DISPATCH_DATA
;
64 // Pei Core private data structure instance
67 #define PEI_CORE_HANDLE_SIGNATURE EFI_SIGNATURE_32('P','e','i','C')
71 EFI_PEI_SERVICES
*PS
; // Point to ServiceTableShadow
72 PEI_PPI_DATABASE PpiData
;
73 PEI_CORE_DISPATCH_DATA DispatchData
;
74 EFI_PEI_HOB_POINTERS HobList
;
75 BOOLEAN SwitchStackSignal
;
76 BOOLEAN PeiMemoryInstalled
;
77 EFI_PHYSICAL_ADDRESS StackBase
;
79 VOID
*BottomOfCarHeap
;
82 EFI_PEI_SECURITY_PPI
*PrivateSecurityPpi
;
83 EFI_PEI_SERVICES ServiceTableShadow
;
84 UINTN SizeOfCacheAsRam
;
85 VOID
*MaxTopOfCarHeap
;
89 // Pei Core Instance Data Macros
92 #define PEI_CORE_INSTANCE_FROM_PS_THIS(a) \
93 CR(a, PEI_CORE_INSTANCE, PS, PEI_CORE_HANDLE_SIGNATURE)
96 // BUGBUG: Where does this go really?
100 (EFIAPI
*PEI_CORE_ENTRY_POINT
)(
101 IN EFI_PEI_STARTUP_DESCRIPTOR
*PeiStartupDescriptor
,
102 IN PEI_CORE_INSTANCE
*OldCoreData
106 // Union of temporarily used function pointers (to save stack space)
109 PEI_CORE_ENTRY_POINT PeiCore
;
110 EFI_PEIM_ENTRY_POINT PeimEntry
;
111 EFI_PEIM_NOTIFY_ENTRY_POINT PeimNotifyEntry
;
112 EFI_DXE_IPL_PPI
*DxeIpl
;
113 EFI_PEI_PPI_DESCRIPTOR
*PpiDescriptor
;
114 EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
;
116 } PEI_CORE_TEMP_POINTERS
;
125 IN EFI_PEI_STARTUP_DESCRIPTOR
*PeiStartupDescriptor
,
132 The entry routine to Pei Core, invoked by PeiMain during transition
133 from SEC to PEI. After switching stack in the PEI core, it will restart
134 with the old core data.
138 PeiStartupDescriptor - Information and services provided by SEC phase.
139 OldCoreData - Pointer to old core data that is used to initialize the
144 This function never returns
145 EFI_NOT_FOUND - Never reach
151 // Dispatcher support functions
155 PeimDispatchReadiness (
156 IN EFI_PEI_SERVICES
**PeiServices
,
157 IN VOID
*DependencyExpression
,
158 IN OUT BOOLEAN
*Runnable
164 This is the POSTFIX version of the dependency evaluator. When a
165 PUSH [PPI GUID] is encountered, a pointer to the GUID is stored on
166 the evaluation stack. When that entry is poped from the evaluation
167 stack, the PPI is checked if it is installed. This method allows
168 some time savings as not all PPIs must be checked for certain
169 operation types (AND, OR).
173 PeiServices - Calling context.
175 DependencyExpression - Pointer to a dependency expression. The Grammar adheres to
176 the BNF described above and is stored in postfix notation.
177 Runnable - is True if the driver can be scheduled and False if the driver
178 cannot be scheduled. This is the value that the schedulers
179 should use for deciding the state of the driver.
183 Status = EFI_SUCCESS if it is a well-formed Grammar
184 EFI_INVALID_PARAMETER if the dependency expression overflows
186 EFI_INVALID_PARAMETER if the dependency expression underflows
188 EFI_INVALID_PARAMETER if the dependency expression is not a
196 IN EFI_PEI_STARTUP_DESCRIPTOR
*PeiStartupDescriptor
,
197 IN PEI_CORE_INSTANCE
*PrivateData
,
198 IN PEI_CORE_DISPATCH_DATA
*DispatchData
205 Conduct PEIM dispatch.
209 PeiStartupDescriptor - Pointer to IN EFI_PEI_STARTUP_DESCRIPTOR
210 PrivateData - Pointer to the private data passed in from caller
211 DispatchData - Pointer to PEI_CORE_DISPATCH_DATA data.
215 EFI_SUCCESS - Successfully dispatched PEIM.
216 EFI_NOT_FOUND - The dispatch failed.
223 InitializeDispatcherData (
224 IN EFI_PEI_SERVICES
**PeiServices
,
225 IN PEI_CORE_INSTANCE
*OldCoreData
,
226 IN EFI_PEI_STARTUP_DESCRIPTOR
*PeiStartupDescriptor
232 Initialize the Dispatcher's data members
236 PeiServices - The PEI core services table.
237 OldCoreData - Pointer to old core data (before switching stack).
238 NULL if being run in non-permament memory mode.
239 PeiStartupDescriptor - Information and services provided by SEC phase.
252 IN EFI_PEI_SERVICES
**PeiServices
,
253 IN EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
,
254 IN OUT EFI_FFS_FILE_HEADER
**PeimFileHeader
259 Given the input file pointer, search for the next matching file in the
260 FFS volume. The search starts from FileHeader inside
261 the Firmware Volume defined by FwVolHeader.
264 PeiServices - Pointer to the PEI Core Services Table.
266 FwVolHeader - Pointer to the FV header of the volume to search.
267 This parameter must point to a valid FFS volume.
269 PeimFileHeader - Pointer to the current file from which to begin searching.
270 This pointer will be updated upon return to reflect the file found.
273 EFI_NOT_FOUND - No files matching the search criteria were found
281 IN UINT8 CurrentPeim
,
282 IN UINT32 DispatchedPeimBitMap
288 This routine checks to see if a particular PEIM has been dispatched during
289 the PEI core dispatch.
292 CurrentPeim - The PEIM/FV in the bit array to check.
293 DispatchedPeimBitMap - Bit array, each bit corresponds to a PEIM/FV.
296 TRUE if PEIM already dispatched
304 IN EFI_PEI_SERVICES
**PeiServices
,
305 IN UINT8 CurrentPeim
,
306 OUT UINT32
*DispatchedPeimBitMap
312 This routine sets a PEIM as having been dispatched once its entry
313 point has been invoked.
317 PeiServices - The PEI core services table.
318 CurrentPeim - The PEIM/FV in the bit array to check.
319 DispatchedPeimBitMap - Bit array, each bit corresponds to a PEIM/FV.
329 IN EFI_PEI_SERVICES
**PeiServices
,
330 IN VOID
*CurrentPeimAddress
336 This routine parses the Dependency Expression, if available, and
337 decides if the module can be executed.
340 PeiServices - The PEI Service Table
341 CurrentPeimAddress - Address of the PEIM Firmware File under investigation
344 TRUE - Can be dispatched
345 FALSE - Cannot be dispatched
350 #if defined (MDE_CPU_IPF)
352 // In Ipf we should make special changes for the PHIT pointers to support
353 // recovery boot in cache mode.
355 #define SWITCH_TO_CACHE_MODE(CoreData) SwitchToCacheMode(CoreData)
356 #define CACHE_MODE_ADDRESS_MASK 0x7FFFFFFFFFFFFFFFULL
359 IN PEI_CORE_INSTANCE
*CoreData
365 Switch the PHIT pointers to cache mode after InstallPeiMemory in CAR.
369 CoreData - The PEI core Private Data
378 #define SWITCH_TO_CACHE_MODE(CoreData)
383 // PPI support functions
386 InitializePpiServices (
387 IN EFI_PEI_SERVICES
**PeiServices
,
388 IN PEI_CORE_INSTANCE
*OldCoreData
394 Initialize PPI services.
398 PeiServices - The PEI core services table.
399 OldCoreData - Pointer to the PEI Core data.
400 NULL if being run in non-permament memory mode.
410 IN EFI_PEI_SERVICES
**PeiServices
,
411 IN EFI_HOB_HANDOFF_INFO_TABLE
*OldHandOffHob
,
412 IN EFI_HOB_HANDOFF_INFO_TABLE
*NewHandOffHob
418 Migrate the Hob list from the CAR stack to PEI installed memory.
422 PeiServices - The PEI core services table.
423 OldHandOffHob - The old handoff HOB list.
424 NewHandOffHob - The new handoff HOB list.
434 IN EFI_PEI_SERVICES
**PeiServices
,
435 IN EFI_PEI_PPI_DESCRIPTOR
*PpiList
441 Install PPI services.
445 PeiServices - Pointer to the PEI Service Table
446 PpiList - Pointer to a list of PEI PPI Descriptors.
450 EFI_SUCCESS - if all PPIs in PpiList are successfully installed.
451 EFI_INVALID_PARAMETER - if PpiList is NULL pointer
452 EFI_INVALID_PARAMETER - if any PPI in PpiList is not valid
453 EFI_OUT_OF_RESOURCES - if there is no more memory resource to install PPI
461 IN EFI_PEI_SERVICES
**PeiServices
,
462 IN EFI_PEI_PPI_DESCRIPTOR
*OldPpi
,
463 IN EFI_PEI_PPI_DESCRIPTOR
*NewPpi
469 Re-Install PPI services.
473 PeiServices - Pointer to the PEI Service Table
474 OldPpi - Pointer to the old PEI PPI Descriptors.
475 NewPpi - Pointer to the new PEI PPI Descriptors.
479 EFI_SUCCESS - if the operation was successful
480 EFI_INVALID_PARAMETER - if OldPpi or NewPpi is NULL
481 EFI_INVALID_PARAMETER - if NewPpi is not valid
482 EFI_NOT_FOUND - if the PPI was not in the database
490 IN EFI_PEI_SERVICES
**PeiServices
,
493 IN OUT EFI_PEI_PPI_DESCRIPTOR
**PpiDescriptor
,
500 Locate a given named PPI.
504 PeiServices - Pointer to the PEI Service Table
505 Guid - Pointer to GUID of the PPI.
506 Instance - Instance Number to discover.
507 PpiDescriptor - Pointer to reference the found descriptor. If not NULL,
508 returns a pointer to the descriptor (includes flags, etc)
509 Ppi - Pointer to reference the found PPI
513 Status - EFI_SUCCESS if the PPI is in the database
514 EFI_NOT_FOUND if the PPI is not in the database
521 IN EFI_PEI_SERVICES
**PeiServices
,
522 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyList
528 Install a notification for a given PPI.
532 PeiServices - Pointer to the PEI Service Table
533 NotifyList - Pointer to list of Descriptors to notify upon.
537 Status - EFI_SUCCESS if successful
538 EFI_OUT_OF_RESOURCES if no space in the database
539 EFI_INVALID_PARAMETER if not a good decriptor
546 IN EFI_PEI_SERVICES
**PeiServices
552 Process the Notify List at dispatch level.
556 PeiServices - Pointer to the PEI Service Table
565 IN EFI_PEI_SERVICES
**PeiServices
,
567 IN INTN InstallStartIndex
,
568 IN INTN InstallStopIndex
,
569 IN INTN NotifyStartIndex
,
570 IN INTN NotifyStopIndex
576 Dispatch notifications.
580 PeiServices - Pointer to the PEI Service Table
581 NotifyType - Type of notify to fire.
582 InstallStartIndex - Install Beginning index.
583 InstallStopIndex - Install Ending index.
584 NotifyStartIndex - Notify Beginning index.
585 NotifyStopIndex - Notify Ending index.
593 // Boot mode support functions
598 IN EFI_PEI_SERVICES
**PeiServices
,
599 IN OUT EFI_BOOT_MODE
*BootMode
605 This service enables PEIMs to ascertain the present value of the boot mode.
609 PeiServices - The PEI core services table.
610 BootMode - A pointer to contain the value of the boot mode.
614 EFI_SUCCESS - The boot mode was returned successfully.
615 EFI_INVALID_PARAMETER - BootMode is NULL.
623 IN EFI_PEI_SERVICES
**PeiServices
,
624 IN EFI_BOOT_MODE BootMode
630 This service enables PEIMs to update the boot mode variable.
634 PeiServices - The PEI core services table.
635 BootMode - The value of the boot mode to set.
639 EFI_SUCCESS - The value was successfully updated
645 // Security support functions
648 InitializeSecurityServices (
649 IN EFI_PEI_SERVICES
**PeiServices
,
650 IN PEI_CORE_INSTANCE
*OldCoreData
656 Initialize the security services.
660 PeiServices - The PEI core services table.
661 OldCoreData - Pointer to the old core data.
662 NULL if being run in non-permament memory mode.
672 IN EFI_FIRMWARE_VOLUME_HEADER
*CurrentFvAddress
678 Provide a callout to the OEM FV verification service.
682 CurrentFvAddress - Pointer to the FV under investigation.
694 IN EFI_PEI_SERVICES
**PeiServices
,
695 IN EFI_FFS_FILE_HEADER
*CurrentPeimAddress
701 Provide a callout to the security verification service.
705 PeiServices - The PEI core services table.
706 CurrentPeimAddress - Pointer to the Firmware File under investigation.
710 EFI_SUCCESS - Image is OK
711 EFI_SECURITY_VIOLATION - Image is illegal
720 IN EFI_PEI_SERVICES
**PeiServices
,
721 IN OUT VOID
**HobList
727 Gets the pointer to the HOB List.
731 PeiServices - The PEI core services table.
732 HobList - Pointer to the HOB List.
736 EFI_SUCCESS - Get the pointer of HOB List
737 EFI_NOT_AVAILABLE_YET - the HOB List is not yet published
738 EFI_INVALID_PARAMETER - HobList is NULL (in debug mode)
746 IN EFI_PEI_SERVICES
**PeiServices
,
755 Add a new HOB to the HOB List.
759 PeiServices - The PEI core services table.
760 Type - Type of the new HOB.
761 Length - Length of the new HOB to allocate.
762 Hob - Pointer to the new HOB.
767 - EFI_INVALID_PARAMETER if Hob is NULL
768 - EFI_NOT_AVAILABLE_YET if HobList is still not available.
769 - EFI_OUT_OF_RESOURCES if there is no more memory to grow the Hoblist.
775 PeiCoreBuildHobHandoffInfoTable (
776 IN EFI_BOOT_MODE BootMode
,
777 IN EFI_PHYSICAL_ADDRESS MemoryBegin
,
778 IN UINT64 MemoryLength
784 Builds a Handoff Information Table HOB
788 BootMode - Current Bootmode
789 MemoryBegin - Start Memory Address.
790 MemoryLength - Length of Memory.
801 // FFS Fw Volume support functions
806 IN EFI_PEI_SERVICES
**PeiServices
,
808 IN EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
,
809 IN OUT EFI_FFS_FILE_HEADER
**FileHeader
814 Given the input file pointer, search for the next matching file in the
815 FFS volume as defined by SearchType. The search starts from FileHeader inside
816 the Firmware Volume defined by FwVolHeader.
819 PeiServices - Pointer to the PEI Core Services Table.
821 SearchType - Filter to find only files of this type.
822 Type EFI_FV_FILETYPE_ALL causes no filtering to be done.
824 FwVolHeader - Pointer to the FV header of the volume to search.
825 This parameter must point to a valid FFS volume.
827 FileHeader - Pointer to the current file from which to begin searching.
828 This pointer will be updated upon return to reflect the file found.
831 EFI_NOT_FOUND - No files matching the search criteria were found
839 PeiFfsFindSectionData (
840 IN EFI_PEI_SERVICES
**PeiServices
,
841 IN EFI_SECTION_TYPE SectionType
,
842 IN EFI_FFS_FILE_HEADER
*FfsFileHeader
,
843 IN OUT VOID
**SectionData
848 Given the input file pointer, search for the next matching section in the
852 PeiServices - Pointer to the PEI Core Services Table.
853 SearchType - Filter to find only sections of this type.
854 FfsFileHeader - Pointer to the current file to search.
855 SectionData - Pointer to the Section matching SectionType in FfsFileHeader.
856 - NULL if section not found
859 EFI_NOT_FOUND - No files matching the search criteria were found
867 PeiFvFindNextVolume (
868 IN EFI_PEI_SERVICES
**PeiServices
,
870 IN OUT EFI_FIRMWARE_VOLUME_HEADER
**FwVolHeader
876 Return the BFV location
878 BugBug -- Move this to the location of this code to where the
879 other FV and FFS support code lives.
880 Also, update to use FindFV for instances #'s >= 1.
884 PeiServices - The PEI core services table.
885 Instance - Instance of FV to find
886 FwVolHeader - Pointer to contain the data to return
889 Pointer to the Firmware Volume instance requested
891 EFI_INVALID_PARAMETER - FwVolHeader is NULL
893 EFI_SUCCESS - Firmware volume instance successfully found.
899 // Memory support functions
902 InitializeMemoryServices (
903 IN EFI_PEI_SERVICES
**PeiServices
,
904 IN EFI_PEI_STARTUP_DESCRIPTOR
*PeiStartupDescriptor
,
905 IN PEI_CORE_INSTANCE
*OldCoreData
911 Initialize the memory services.
915 PeiServices - The PEI core services table.
916 PeiStartupDescriptor - Information and services provided by SEC phase.
917 OldCoreData - Pointer to the PEI Core data.
918 NULL if being run in non-permament memory mode.
929 PeiInstallPeiMemory (
930 IN EFI_PEI_SERVICES
**PeiServices
,
931 IN EFI_PHYSICAL_ADDRESS MemoryBegin
,
932 IN UINT64 MemoryLength
938 Install the permanent memory is now available.
939 Creates HOB (PHIT and Stack).
943 PeiServices - The PEI core services table.
944 MemoryBegin - Start of memory address.
945 MemoryLength - Length of memory.
957 IN EFI_PEI_SERVICES
**PeiServices
,
958 IN EFI_MEMORY_TYPE MemoryType
,
960 OUT EFI_PHYSICAL_ADDRESS
*Memory
966 Memory allocation service on permanent memory,
967 not usable prior to the memory installation.
971 PeiServices - The PEI core services table.
972 Type - Type of allocation.
973 MemoryType - Type of memory to allocate.
974 Pages - Number of pages to allocate.
975 Memory - Pointer of memory allocated.
979 Status - EFI_SUCCESS The allocation was successful
980 EFI_INVALID_PARAMETER Only AllocateAnyAddress is supported.
981 EFI_NOT_AVAILABLE_YET Called with permanent memory not available
982 EFI_OUT_OF_RESOURCES There is not enough HOB heap to satisfy the requirement
983 to allocate the number of pages.
991 IN EFI_PEI_SERVICES
**PeiServices
,
999 Memory allocation service on the CAR.
1003 PeiServices - The PEI core services table.
1005 Size - Amount of memory required
1007 Buffer - Address of pointer to the buffer
1011 Status - EFI_SUCCESS The allocation was successful
1012 EFI_OUT_OF_RESOURCES There is not enough heap to satisfy the requirement
1013 to allocate the requested size.
1020 IN EFI_PEI_SERVICES
**PeiServices
,
1021 IN EFI_FFS_FILE_HEADER
*PeimFileHeader
,
1022 OUT VOID
**EntryPoint
1026 Routine Description:
1028 Get entry point of a Peim file.
1032 PeiServices - Calling context.
1034 PeimFileHeader - Peim file's header.
1036 EntryPoint - Entry point of that Peim file.
1048 PeiReportStatusCode (
1049 IN EFI_PEI_SERVICES
**PeiServices
,
1050 IN EFI_STATUS_CODE_TYPE CodeType
,
1051 IN EFI_STATUS_CODE_VALUE Value
,
1053 IN EFI_GUID
*CallerId
,
1054 IN EFI_STATUS_CODE_DATA
*Data OPTIONAL
1058 Routine Description:
1060 Core version of the Status Code reporter
1064 PeiServices - The PEI core services table.
1066 CodeType - Type of Status Code.
1068 Value - Value to output for Status Code.
1070 Instance - Instance Number of this status code.
1072 CallerId - ID of the caller of this status code.
1074 Data - Optional data associated with this status code.
1078 Status - EFI_SUCCESS if status code is successfully reported
1079 - EFI_NOT_AVAILABLE_YET if StatusCodePpi has not been installed
1088 IN EFI_PEI_SERVICES
**PeiServices
1092 Routine Description:
1094 Core version of the Reset System
1098 PeiServices - The PEI core services table.
1102 Status - EFI_NOT_AVAILABLE_YET. PPI not available yet.
1103 - EFI_DEVICE_ERROR. Did not reset system.
1105 Otherwise, resets the system.
1111 Transfers control to a function starting with a new stack.
1113 Transfers control to the function specified by EntryPoint using the new stack
1114 specified by NewStack and passing in the parameters specified by Context1 and
1115 Context2. Context1 and Context2 are optional and may be NULL. The function
1116 EntryPoint must never return.
1118 If EntryPoint is NULL, then ASSERT().
1119 If NewStack is NULL, then ASSERT().
1121 @param EntryPoint A pointer to function to call with the new stack.
1122 @param Context1 A pointer to the context to pass into the EntryPoint
1124 @param Context2 A pointer to the context to pass into the EntryPoint
1126 @param NewStack A pointer to the new stack to use for the EntryPoint
1128 @param NewBsp A pointer to the new BSP for the EntryPoint on IPF. It's
1129 Reserved on other architectures.
1135 IN SWITCH_STACK_ENTRY_POINT EntryPoint
,
1136 IN VOID
*Context1
, OPTIONAL
1137 IN VOID
*Context2
, OPTIONAL