2 This driver will register two callbacks to call fsp's notifies.
4 Copyright (c) 2014 - 2016, Intel Corporation. All rights reserved.<BR>
5 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.
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.
17 #include <Protocol/PciEnumerationComplete.h>
19 #include <Library/UefiDriverEntryPoint.h>
20 #include <Library/UefiBootServicesTableLib.h>
21 #include <Library/DebugLib.h>
22 #include <Library/BaseMemoryLib.h>
23 #include <Library/UefiLib.h>
24 #include <Library/FspWrapperApiLib.h>
25 #include <Library/FspWrapperPlatformLib.h>
26 #include <Library/PerformanceLib.h>
27 #include <Library/HobLib.h>
31 (EFIAPI
* ADD_PERFORMANCE_RECORDS
)(
32 IN CONST VOID
*HobStart
35 struct _ADD_PERFORMANCE_RECORD_PROTOCOL
{
36 ADD_PERFORMANCE_RECORDS AddPerformanceRecords
;
39 typedef struct _ADD_PERFORMANCE_RECORD_PROTOCOL ADD_PERFORMANCE_RECORD_PROTOCOL
;
41 extern EFI_GUID gAddPerfRecordProtocolGuid
;
42 extern EFI_GUID gFspHobGuid
;
43 extern EFI_GUID gFspApiPerformanceGuid
;
45 EFI_EVENT mExitBootServicesEvent
= NULL
;
48 Relocate this image under 4G memory.
50 @param ImageHandle Handle of driver image.
51 @param SystemTable Pointer to system table.
53 @retval EFI_SUCCESS Image successfully relocated.
54 @retval EFI_ABORTED Failed to relocate image.
58 RelocateImageUnder4GIfNeeded (
59 IN EFI_HANDLE ImageHandle
,
60 IN EFI_SYSTEM_TABLE
*SystemTable
64 PciEnumerationComplete Protocol notification event handler.
66 @param[in] Event Event whose notification function is being invoked.
67 @param[in] Context Pointer to the notification function's context.
71 OnPciEnumerationComplete (
76 NOTIFY_PHASE_PARAMS NotifyPhaseParams
;
81 // Try to locate it because gEfiPciEnumerationCompleteProtocolGuid will trigger it once when registration.
82 // Just return if it is not found.
84 Status
= gBS
->LocateProtocol (
85 &gEfiPciEnumerationCompleteProtocolGuid
,
89 if (EFI_ERROR (Status
)) {
93 NotifyPhaseParams
.Phase
= EnumInitPhaseAfterPciEnumeration
;
94 PERF_START_EX(&gFspApiPerformanceGuid
, "EventRec", NULL
, 0, 0x6000);
95 Status
= CallFspNotifyPhase (&NotifyPhaseParams
);
96 PERF_END_EX(&gFspApiPerformanceGuid
, "EventRec", NULL
, 0, 0x607F);
99 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status
101 if ((Status
>= FSP_STATUS_RESET_REQUIRED_COLD
) && (Status
<= FSP_STATUS_RESET_REQUIRED_8
)) {
102 DEBUG((DEBUG_INFO
, "FSP NotifyPhase AfterPciEnumeration requested reset 0x%x\n", Status
));
103 CallFspWrapperResetSystem ((UINT32
)Status
);
106 if (Status
!= EFI_SUCCESS
) {
107 DEBUG((DEBUG_ERROR
, "FSP NotifyPhase AfterPciEnumeration failed, status: 0x%x\n", Status
));
109 DEBUG((DEBUG_INFO
, "FSP NotifyPhase AfterPciEnumeration Success.\n"));
114 Notification function of EVT_GROUP_READY_TO_BOOT event group.
116 This is a notification function registered on EVT_GROUP_READY_TO_BOOT event group.
117 When the Boot Manager is about to load and execute a boot option, it reclaims variable
118 storage if free size is below the threshold.
120 @param[in] Event Event whose notification function is being invoked.
121 @param[in] Context Pointer to the notification function's context.
131 NOTIFY_PHASE_PARAMS NotifyPhaseParams
;
133 ADD_PERFORMANCE_RECORD_PROTOCOL
*AddPerfRecordInterface
;
134 EFI_PEI_HOB_POINTERS Hob
;
135 VOID
**FspHobListPtr
;
137 gBS
->CloseEvent (Event
);
139 NotifyPhaseParams
.Phase
= EnumInitPhaseReadyToBoot
;
140 PERF_START_EX(&gFspApiPerformanceGuid
, "EventRec", NULL
, 0, 0x4000);
141 Status
= CallFspNotifyPhase (&NotifyPhaseParams
);
142 PERF_END_EX(&gFspApiPerformanceGuid
, "EventRec", NULL
, 0, 0x407F);
145 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status
147 if ((Status
>= FSP_STATUS_RESET_REQUIRED_COLD
) && (Status
<= FSP_STATUS_RESET_REQUIRED_8
)) {
148 DEBUG((DEBUG_INFO
, "FSP NotifyPhase ReadyToBoot requested reset 0x%x\n", Status
));
149 CallFspWrapperResetSystem ((UINT32
)Status
);
152 if (Status
!= EFI_SUCCESS
) {
153 DEBUG((DEBUG_ERROR
, "FSP NotifyPhase ReadyToBoot failed, status: 0x%x\n", Status
));
155 DEBUG((DEBUG_INFO
, "FSP NotifyPhase ReadyToBoot Success.\n"));
158 Status
= gBS
->LocateProtocol (
159 &gAddPerfRecordProtocolGuid
,
161 (VOID
**) &AddPerfRecordInterface
163 if (EFI_ERROR (Status
)) {
164 DEBUG((DEBUG_INFO
, "gAddPerfRecordProtocolGuid - Locate protocol failed\n"));
167 Hob
.Raw
= GetHobList ();
168 if (Hob
.Raw
!= NULL
) {
169 Hob
.Raw
= GetNextGuidHob (&gFspHobGuid
, Hob
.Raw
);
170 FspHobListPtr
= GET_GUID_HOB_DATA(Hob
.Raw
);
171 AddPerfRecordInterface
->AddPerformanceRecords((VOID
*)(UINTN
)(((UINT32
)(UINTN
)*FspHobListPtr
) & 0xFFFFFFFF));
177 This stage is notified just before the firmware/Preboot environment transfers
178 management of all system resources to the OS or next level execution environment.
180 @param Event Event whose notification function is being invoked.
181 @param Context Pointer to the notification function's context, which is
182 always zero in current implementation.
192 NOTIFY_PHASE_PARAMS NotifyPhaseParams
;
195 gBS
->CloseEvent (Event
);
197 NotifyPhaseParams
.Phase
= EnumInitPhaseEndOfFirmware
;
198 PERF_START_EX(&gFspApiPerformanceGuid
, "EventRec", NULL
, 0, 0x2000);
199 Status
= CallFspNotifyPhase (&NotifyPhaseParams
);
200 PERF_END_EX(&gFspApiPerformanceGuid
, "EventRec", NULL
, 0, 0x207F);
203 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status
205 if ((Status
>= FSP_STATUS_RESET_REQUIRED_COLD
) && (Status
<= FSP_STATUS_RESET_REQUIRED_8
)) {
206 DEBUG((DEBUG_INFO
, "FSP NotifyPhase EndOfFirmware requested reset 0x%x\n", Status
));
207 CallFspWrapperResetSystem ((UINT32
)Status
);
210 if (Status
!= EFI_SUCCESS
) {
211 DEBUG((DEBUG_ERROR
, "FSP NotifyPhase EndOfFirmware failed, status: 0x%x\n", Status
));
213 DEBUG((DEBUG_INFO
, "FSP NotifyPhase EndOfFirmware Success.\n"));
218 Main entry for the FSP DXE module.
220 This routine registers two callbacks to call fsp's notifies.
222 @param[in] ImageHandle The firmware allocated handle for the EFI image.
223 @param[in] SystemTable A pointer to the EFI System Table.
225 @retval EFI_SUCCESS The entry point is executed successfully.
226 @retval other Some error occurs when executing this entry point.
231 FspWrapperNotifyDxeEntryPoint (
232 IN EFI_HANDLE ImageHandle
,
233 IN EFI_SYSTEM_TABLE
*SystemTable
237 EFI_EVENT ReadyToBootEvent
;
239 EFI_EVENT ProtocolNotifyEvent
;
242 // Load this driver's image to memory
244 Status
= RelocateImageUnder4GIfNeeded (ImageHandle
, SystemTable
);
245 if (EFI_ERROR (Status
)) {
249 ProtocolNotifyEvent
= EfiCreateProtocolNotifyEvent (
250 &gEfiPciEnumerationCompleteProtocolGuid
,
252 OnPciEnumerationComplete
,
256 ASSERT (ProtocolNotifyEvent
!= NULL
);
258 Status
= EfiCreateEventReadyToBootEx (
264 ASSERT_EFI_ERROR (Status
);
266 Status
= gBS
->CreateEventEx (
271 &gEfiEventExitBootServicesGuid
,
272 &mExitBootServicesEvent
274 ASSERT_EFI_ERROR (Status
);