2 This driver will register two callbacks to call fsp's notifies.
4 Copyright (c) 2014 - 2019, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include <Protocol/PciEnumerationComplete.h>
13 #include <Library/UefiDriverEntryPoint.h>
14 #include <Library/UefiBootServicesTableLib.h>
15 #include <Library/DebugLib.h>
16 #include <Library/BaseMemoryLib.h>
17 #include <Library/UefiLib.h>
18 #include <Library/FspWrapperApiLib.h>
19 #include <Library/FspWrapperPlatformLib.h>
20 #include <Library/PerformanceLib.h>
21 #include <Library/HobLib.h>
22 #include <FspStatusCode.h>
24 #define FSP_API_NOTIFY_PHASE_AFTER_PCI_ENUMERATION BIT16
28 (EFIAPI
*ADD_PERFORMANCE_RECORDS
)(
29 IN CONST VOID
*HobStart
32 struct _ADD_PERFORMANCE_RECORD_PROTOCOL
{
33 ADD_PERFORMANCE_RECORDS AddPerformanceRecords
;
36 typedef struct _ADD_PERFORMANCE_RECORD_PROTOCOL ADD_PERFORMANCE_RECORD_PROTOCOL
;
38 extern EFI_GUID gAddPerfRecordProtocolGuid
;
39 extern EFI_GUID gFspHobGuid
;
40 extern EFI_GUID gFspApiPerformanceGuid
;
42 static EFI_EVENT mExitBootServicesEvent
= NULL
;
45 Relocate this image under 4G memory.
47 @param ImageHandle Handle of driver image.
48 @param SystemTable Pointer to system table.
50 @retval EFI_SUCCESS Image successfully relocated.
51 @retval EFI_ABORTED Failed to relocate image.
55 RelocateImageUnder4GIfNeeded (
56 IN EFI_HANDLE ImageHandle
,
57 IN EFI_SYSTEM_TABLE
*SystemTable
61 PciEnumerationComplete Protocol notification event handler.
63 @param[in] Event Event whose notification function is being invoked.
64 @param[in] Context Pointer to the notification function's context.
68 OnPciEnumerationComplete (
73 NOTIFY_PHASE_PARAMS NotifyPhaseParams
;
78 // Try to locate it because gEfiPciEnumerationCompleteProtocolGuid will trigger it once when registration.
79 // Just return if it is not found.
81 Status
= gBS
->LocateProtocol (
82 &gEfiPciEnumerationCompleteProtocolGuid
,
86 if (EFI_ERROR (Status
)) {
90 NotifyPhaseParams
.Phase
= EnumInitPhaseAfterPciEnumeration
;
91 PERF_START_EX (&gFspApiPerformanceGuid
, "EventRec", NULL
, 0, FSP_STATUS_CODE_POST_PCIE_ENUM_NOTIFICATION
| FSP_STATUS_CODE_COMMON_CODE
| FSP_STATUS_CODE_API_ENTRY
);
92 Status
= CallFspNotifyPhase (&NotifyPhaseParams
);
93 PERF_END_EX (&gFspApiPerformanceGuid
, "EventRec", NULL
, 0, FSP_STATUS_CODE_POST_PCIE_ENUM_NOTIFICATION
| FSP_STATUS_CODE_COMMON_CODE
| FSP_STATUS_CODE_API_EXIT
);
96 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status
98 if ((Status
>= FSP_STATUS_RESET_REQUIRED_COLD
) && (Status
<= FSP_STATUS_RESET_REQUIRED_8
)) {
99 DEBUG ((DEBUG_INFO
, "FSP NotifyPhase AfterPciEnumeration requested reset 0x%x\n", Status
));
100 CallFspWrapperResetSystem (Status
);
103 if (Status
!= EFI_SUCCESS
) {
104 DEBUG ((DEBUG_ERROR
, "FSP NotifyPhase AfterPciEnumeration failed, status: 0x%x\n", Status
));
106 DEBUG ((DEBUG_INFO
, "FSP NotifyPhase AfterPciEnumeration Success.\n"));
111 Notification function of EVT_GROUP_READY_TO_BOOT event group.
113 This is a notification function registered on EVT_GROUP_READY_TO_BOOT event group.
114 When the Boot Manager is about to load and execute a boot option, it reclaims variable
115 storage if free size is below the threshold.
117 @param[in] Event Event whose notification function is being invoked.
118 @param[in] Context Pointer to the notification function's context.
128 NOTIFY_PHASE_PARAMS NotifyPhaseParams
;
131 gBS
->CloseEvent (Event
);
133 NotifyPhaseParams
.Phase
= EnumInitPhaseReadyToBoot
;
134 PERF_START_EX (&gFspApiPerformanceGuid
, "EventRec", NULL
, 0, FSP_STATUS_CODE_READY_TO_BOOT_NOTIFICATION
| FSP_STATUS_CODE_COMMON_CODE
| FSP_STATUS_CODE_API_ENTRY
);
135 Status
= CallFspNotifyPhase (&NotifyPhaseParams
);
136 PERF_END_EX (&gFspApiPerformanceGuid
, "EventRec", NULL
, 0, FSP_STATUS_CODE_READY_TO_BOOT_NOTIFICATION
| FSP_STATUS_CODE_COMMON_CODE
| FSP_STATUS_CODE_API_EXIT
);
139 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status
141 if ((Status
>= FSP_STATUS_RESET_REQUIRED_COLD
) && (Status
<= FSP_STATUS_RESET_REQUIRED_8
)) {
142 DEBUG ((DEBUG_INFO
, "FSP NotifyPhase ReadyToBoot requested reset 0x%x\n", Status
));
143 CallFspWrapperResetSystem (Status
);
146 if (Status
!= EFI_SUCCESS
) {
147 DEBUG ((DEBUG_ERROR
, "FSP NotifyPhase ReadyToBoot failed, status: 0x%x\n", Status
));
149 DEBUG ((DEBUG_INFO
, "FSP NotifyPhase ReadyToBoot Success.\n"));
154 This stage is notified just before the firmware/Preboot environment transfers
155 management of all system resources to the OS or next level execution environment.
157 @param Event Event whose notification function is being invoked.
158 @param Context Pointer to the notification function's context, which is
159 always zero in current implementation.
169 NOTIFY_PHASE_PARAMS NotifyPhaseParams
;
171 ADD_PERFORMANCE_RECORD_PROTOCOL
*AddPerfRecordInterface
;
172 EFI_PEI_HOB_POINTERS Hob
;
173 VOID
**FspHobListPtr
;
175 gBS
->CloseEvent (Event
);
177 NotifyPhaseParams
.Phase
= EnumInitPhaseEndOfFirmware
;
178 PERF_START_EX (&gFspApiPerformanceGuid
, "EventRec", NULL
, 0, FSP_STATUS_CODE_END_OF_FIRMWARE_NOTIFICATION
| FSP_STATUS_CODE_COMMON_CODE
| FSP_STATUS_CODE_API_ENTRY
);
179 Status
= CallFspNotifyPhase (&NotifyPhaseParams
);
180 PERF_END_EX (&gFspApiPerformanceGuid
, "EventRec", NULL
, 0, FSP_STATUS_CODE_END_OF_FIRMWARE_NOTIFICATION
| FSP_STATUS_CODE_COMMON_CODE
| FSP_STATUS_CODE_API_EXIT
);
183 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status
185 if ((Status
>= FSP_STATUS_RESET_REQUIRED_COLD
) && (Status
<= FSP_STATUS_RESET_REQUIRED_8
)) {
186 DEBUG ((DEBUG_INFO
, "FSP NotifyPhase EndOfFirmware requested reset 0x%x\n", Status
));
187 CallFspWrapperResetSystem (Status
);
190 if (Status
!= EFI_SUCCESS
) {
191 DEBUG ((DEBUG_ERROR
, "FSP NotifyPhase EndOfFirmware failed, status: 0x%x\n", Status
));
193 DEBUG ((DEBUG_INFO
, "FSP NotifyPhase EndOfFirmware Success.\n"));
196 Status
= gBS
->LocateProtocol (
197 &gAddPerfRecordProtocolGuid
,
199 (VOID
**)&AddPerfRecordInterface
201 if (EFI_ERROR (Status
)) {
202 DEBUG ((DEBUG_INFO
, "gAddPerfRecordProtocolGuid - Locate protocol failed\n"));
205 Hob
.Raw
= GetFirstGuidHob (&gFspHobGuid
);
206 if (Hob
.Raw
!= NULL
) {
207 FspHobListPtr
= GET_GUID_HOB_DATA (Hob
.Raw
);
208 AddPerfRecordInterface
->AddPerformanceRecords ((VOID
*)(UINTN
)(((UINT32
)(UINTN
)*FspHobListPtr
) & 0xFFFFFFFF));
214 Main entry for the FSP DXE module.
216 This routine registers two callbacks to call fsp's notifies.
218 @param[in] ImageHandle The firmware allocated handle for the EFI image.
219 @param[in] SystemTable A pointer to the EFI System Table.
221 @retval EFI_SUCCESS The entry point is executed successfully.
222 @retval other Some error occurs when executing this entry point.
227 FspWrapperNotifyDxeEntryPoint (
228 IN EFI_HANDLE ImageHandle
,
229 IN EFI_SYSTEM_TABLE
*SystemTable
233 EFI_EVENT ReadyToBootEvent
;
235 EFI_EVENT ProtocolNotifyEvent
;
239 // Load this driver's image to memory
241 Status
= RelocateImageUnder4GIfNeeded (ImageHandle
, SystemTable
);
242 if (EFI_ERROR (Status
)) {
246 FspApiMask
= PcdGet32 (PcdSkipFspApi
);
247 if ((FspApiMask
& FSP_API_NOTIFY_PHASE_AFTER_PCI_ENUMERATION
) == 0) {
248 ProtocolNotifyEvent
= EfiCreateProtocolNotifyEvent (
249 &gEfiPciEnumerationCompleteProtocolGuid
,
251 OnPciEnumerationComplete
,
255 ASSERT (ProtocolNotifyEvent
!= NULL
);
258 Status
= EfiCreateEventReadyToBootEx (
264 ASSERT_EFI_ERROR (Status
);
266 Status
= gBS
->CreateEventEx (
271 &gEfiEventExitBootServicesGuid
,
272 &mExitBootServicesEvent
274 ASSERT_EFI_ERROR (Status
);