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/PerformanceLib.h>
26 #include <Library/HobLib.h>
30 (EFIAPI
* ADD_PERFORMANCE_RECORDS
)(
31 IN CONST VOID
*HobStart
34 struct _ADD_PERFORMANCE_RECORD_PROTOCOL
{
35 ADD_PERFORMANCE_RECORDS AddPerformanceRecords
;
38 typedef struct _ADD_PERFORMANCE_RECORD_PROTOCOL ADD_PERFORMANCE_RECORD_PROTOCOL
;
40 extern EFI_GUID gAddPerfRecordProtocolGuid
;
41 extern EFI_GUID gFspHobGuid
;
42 extern EFI_GUID gFspApiPerformanceGuid
;
44 EFI_EVENT mExitBootServicesEvent
= NULL
;
47 Relocate this image under 4G memory.
49 @param ImageHandle Handle of driver image.
50 @param SystemTable Pointer to system table.
52 @retval EFI_SUCCESS Image successfully relocated.
53 @retval EFI_ABORTED Failed to relocate image.
57 RelocateImageUnder4GIfNeeded (
58 IN EFI_HANDLE ImageHandle
,
59 IN EFI_SYSTEM_TABLE
*SystemTable
63 PciEnumerationComplete Protocol notification event handler.
65 @param[in] Event Event whose notification function is being invoked.
66 @param[in] Context Pointer to the notification function's context.
70 OnPciEnumerationComplete (
75 NOTIFY_PHASE_PARAMS NotifyPhaseParams
;
80 // Try to locate it because gEfiPciEnumerationCompleteProtocolGuid will trigger it once when registration.
81 // Just return if it is not found.
83 Status
= gBS
->LocateProtocol (
84 &gEfiPciEnumerationCompleteProtocolGuid
,
88 if (EFI_ERROR (Status
)) {
92 NotifyPhaseParams
.Phase
= EnumInitPhaseAfterPciEnumeration
;
93 PERF_START_EX(&gFspApiPerformanceGuid
, "EventRec", NULL
, 0, 0x6000);
94 Status
= CallFspNotifyPhase (&NotifyPhaseParams
);
95 PERF_END_EX(&gFspApiPerformanceGuid
, "EventRec", NULL
, 0, 0x607F);
96 if (Status
!= EFI_SUCCESS
) {
97 DEBUG((DEBUG_ERROR
, "FSP NotifyPhase AfterPciEnumeration failed, status: 0x%x\n", Status
));
99 DEBUG((DEBUG_INFO
, "FSP NotifyPhase AfterPciEnumeration Success.\n"));
104 Notification function of EVT_GROUP_READY_TO_BOOT event group.
106 This is a notification function registered on EVT_GROUP_READY_TO_BOOT event group.
107 When the Boot Manager is about to load and execute a boot option, it reclaims variable
108 storage if free size is below the threshold.
110 @param[in] Event Event whose notification function is being invoked.
111 @param[in] Context Pointer to the notification function's context.
121 NOTIFY_PHASE_PARAMS NotifyPhaseParams
;
123 ADD_PERFORMANCE_RECORD_PROTOCOL
*AddPerfRecordInterface
;
124 EFI_PEI_HOB_POINTERS Hob
;
125 VOID
**FspHobListPtr
;
127 gBS
->CloseEvent (Event
);
129 NotifyPhaseParams
.Phase
= EnumInitPhaseReadyToBoot
;
130 PERF_START_EX(&gFspApiPerformanceGuid
, "EventRec", NULL
, 0, 0x4000);
131 Status
= CallFspNotifyPhase (&NotifyPhaseParams
);
132 PERF_END_EX(&gFspApiPerformanceGuid
, "EventRec", NULL
, 0, 0x407F);
133 if (Status
!= EFI_SUCCESS
) {
134 DEBUG((DEBUG_ERROR
, "FSP NotifyPhase ReadyToBoot failed, status: 0x%x\n", Status
));
136 DEBUG((DEBUG_INFO
, "FSP NotifyPhase ReadyToBoot Success.\n"));
139 Status
= gBS
->LocateProtocol (
140 &gAddPerfRecordProtocolGuid
,
142 (VOID
**) &AddPerfRecordInterface
144 if (EFI_ERROR (Status
)) {
145 DEBUG((DEBUG_INFO
, "gAddPerfRecordProtocolGuid - Locate protocol failed\n"));
148 Hob
.Raw
= GetHobList ();
149 if (Hob
.Raw
!= NULL
) {
150 Hob
.Raw
= GetNextGuidHob (&gFspHobGuid
, Hob
.Raw
);
151 FspHobListPtr
= GET_GUID_HOB_DATA(Hob
.Raw
);
152 AddPerfRecordInterface
->AddPerformanceRecords((VOID
*)(UINTN
)(((UINT32
)(UINTN
)*FspHobListPtr
) & 0xFFFFFFFF));
158 This stage is notified just before the firmware/Preboot environment transfers
159 management of all system resources to the OS or next level execution environment.
161 @param Event Event whose notification function is being invoked.
162 @param Context Pointer to the notification function's context, which is
163 always zero in current implementation.
173 NOTIFY_PHASE_PARAMS NotifyPhaseParams
;
176 gBS
->CloseEvent (Event
);
178 NotifyPhaseParams
.Phase
= EnumInitPhaseEndOfFirmware
;
179 PERF_START_EX(&gFspApiPerformanceGuid
, "EventRec", NULL
, 0, 0x2000);
180 Status
= CallFspNotifyPhase (&NotifyPhaseParams
);
181 PERF_END_EX(&gFspApiPerformanceGuid
, "EventRec", NULL
, 0, 0x207F);
182 if (Status
!= EFI_SUCCESS
) {
183 DEBUG((DEBUG_ERROR
, "FSP NotifyPhase EndOfFirmware failed, status: 0x%x\n", Status
));
185 DEBUG((DEBUG_INFO
, "FSP NotifyPhase EndOfFirmware Success.\n"));
190 Main entry for the FSP DXE module.
192 This routine registers two callbacks to call fsp's notifies.
194 @param[in] ImageHandle The firmware allocated handle for the EFI image.
195 @param[in] SystemTable A pointer to the EFI System Table.
197 @retval EFI_SUCCESS The entry point is executed successfully.
198 @retval other Some error occurs when executing this entry point.
203 FspWrapperNotifyDxeEntryPoint (
204 IN EFI_HANDLE ImageHandle
,
205 IN EFI_SYSTEM_TABLE
*SystemTable
209 EFI_EVENT ReadyToBootEvent
;
211 EFI_EVENT ProtocolNotifyEvent
;
214 // Load this driver's image to memory
216 Status
= RelocateImageUnder4GIfNeeded (ImageHandle
, SystemTable
);
217 if (EFI_ERROR (Status
)) {
221 ProtocolNotifyEvent
= EfiCreateProtocolNotifyEvent (
222 &gEfiPciEnumerationCompleteProtocolGuid
,
224 OnPciEnumerationComplete
,
228 ASSERT (ProtocolNotifyEvent
!= NULL
);
230 Status
= EfiCreateEventReadyToBootEx (
236 ASSERT_EFI_ERROR (Status
);
238 Status
= gBS
->CreateEventEx (
243 &gEfiEventExitBootServicesGuid
,
244 &mExitBootServicesEvent
246 ASSERT_EFI_ERROR (Status
);