TianoCore EDK2 master
Loading...
Searching...
No Matches
FspWrapperNotifyDxe.c
Go to the documentation of this file.
1
9#include <PiDxe.h>
10
12
15#include <Library/DebugLib.h>
17#include <Library/UefiLib.h>
21#include <Library/HobLib.h>
22#include <FspStatusCode.h>
23
24#define FSP_API_NOTIFY_PHASE_AFTER_PCI_ENUMERATION BIT16
25
26typedef
28(EFIAPI *ADD_PERFORMANCE_RECORDS)(
29 IN CONST VOID *HobStart
30 );
31
33 ADD_PERFORMANCE_RECORDS AddPerformanceRecords;
34};
35
37
38extern EFI_GUID gAddPerfRecordProtocolGuid;
39extern EFI_GUID gFspHobGuid;
40extern EFI_GUID gFspApiPerformanceGuid;
41
42static EFI_EVENT mExitBootServicesEvent = NULL;
43
56 IN EFI_HANDLE ImageHandle,
57 IN EFI_SYSTEM_TABLE *SystemTable
58 );
59
66VOID
67EFIAPI
69 IN EFI_EVENT Event,
70 IN VOID *Context
71 )
72{
73 NOTIFY_PHASE_PARAMS NotifyPhaseParams;
74 EFI_STATUS Status;
75 VOID *Interface;
76
77 //
78 // Try to locate it because gEfiPciEnumerationCompleteProtocolGuid will trigger it once when registration.
79 // Just return if it is not found.
80 //
81 Status = gBS->LocateProtocol (
82 &gEfiPciEnumerationCompleteProtocolGuid,
83 NULL,
84 &Interface
85 );
86 if (EFI_ERROR (Status)) {
87 return;
88 }
89
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);
94
95 //
96 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status
97 //
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));
101 }
102
103 if (Status != EFI_SUCCESS) {
104 DEBUG ((DEBUG_ERROR, "FSP NotifyPhase AfterPciEnumeration failed, status: 0x%x\n", Status));
105 } else {
106 DEBUG ((DEBUG_INFO, "FSP NotifyPhase AfterPciEnumeration Success.\n"));
107 }
108}
109
121VOID
122EFIAPI
124 IN EFI_EVENT Event,
125 IN VOID *Context
126 )
127{
128 NOTIFY_PHASE_PARAMS NotifyPhaseParams;
129 EFI_STATUS Status;
130
131 gBS->CloseEvent (Event);
132
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);
137
138 //
139 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status
140 //
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));
144 }
145
146 if (Status != EFI_SUCCESS) {
147 DEBUG ((DEBUG_ERROR, "FSP NotifyPhase ReadyToBoot failed, status: 0x%x\n", Status));
148 } else {
149 DEBUG ((DEBUG_INFO, "FSP NotifyPhase ReadyToBoot Success.\n"));
150 }
151}
152
162VOID
163EFIAPI
165 IN EFI_EVENT Event,
166 IN VOID *Context
167 )
168{
169 NOTIFY_PHASE_PARAMS NotifyPhaseParams;
170 EFI_STATUS Status;
171 ADD_PERFORMANCE_RECORD_PROTOCOL *AddPerfRecordInterface;
173 VOID **FspHobListPtr;
174
175 gBS->CloseEvent (Event);
176
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);
181
182 //
183 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status
184 //
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));
188 }
189
190 if (Status != EFI_SUCCESS) {
191 DEBUG ((DEBUG_ERROR, "FSP NotifyPhase EndOfFirmware failed, status: 0x%x\n", Status));
192 } else {
193 DEBUG ((DEBUG_INFO, "FSP NotifyPhase EndOfFirmware Success.\n"));
194 }
195
196 Status = gBS->LocateProtocol (
197 &gAddPerfRecordProtocolGuid,
198 NULL,
199 (VOID **)&AddPerfRecordInterface
200 );
201 if (EFI_ERROR (Status)) {
202 DEBUG ((DEBUG_INFO, "gAddPerfRecordProtocolGuid - Locate protocol failed\n"));
203 return;
204 } else {
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));
209 }
210 }
211}
212
226EFIAPI
228 IN EFI_HANDLE ImageHandle,
229 IN EFI_SYSTEM_TABLE *SystemTable
230 )
231{
232 EFI_STATUS Status;
233 EFI_EVENT ReadyToBootEvent;
234 VOID *Registration;
235 EFI_EVENT ProtocolNotifyEvent;
236 UINT32 FspApiMask;
237
238 //
239 // Load this driver's image to memory
240 //
241 Status = RelocateImageUnder4GIfNeeded (ImageHandle, SystemTable);
242 if (EFI_ERROR (Status)) {
243 return EFI_SUCCESS;
244 }
245
246 FspApiMask = PcdGet32 (PcdSkipFspApi);
247 if ((FspApiMask & FSP_API_NOTIFY_PHASE_AFTER_PCI_ENUMERATION) == 0) {
248 ProtocolNotifyEvent = EfiCreateProtocolNotifyEvent (
249 &gEfiPciEnumerationCompleteProtocolGuid,
250 TPL_CALLBACK,
252 NULL,
253 &Registration
254 );
255 ASSERT (ProtocolNotifyEvent != NULL);
256 }
257
259 TPL_CALLBACK,
261 NULL,
262 &ReadyToBootEvent
263 );
264 ASSERT_EFI_ERROR (Status);
265
266 Status = gBS->CreateEventEx (
267 EVT_NOTIFY_SIGNAL,
268 TPL_NOTIFY,
270 NULL,
271 &gEfiEventExitBootServicesGuid,
272 &mExitBootServicesEvent
273 );
274 ASSERT_EFI_ERROR (Status);
275
276 return EFI_SUCCESS;
277}
UINT64 UINTN
VOID *EFIAPI GetFirstGuidHob(IN CONST EFI_GUID *Guid)
Definition: HobLib.c:215
@ EnumInitPhaseAfterPciEnumeration
Definition: FspApi.h:470
@ EnumInitPhaseReadyToBoot
Definition: FspApi.h:475
@ EnumInitPhaseEndOfFirmware
Definition: FspApi.h:481
EFI_STATUS EFIAPI CallFspNotifyPhase(IN NOTIFY_PHASE_PARAMS *NotifyPhaseParams)
VOID EFIAPI OnEndOfFirmware(IN EFI_EVENT Event, IN VOID *Context)
EFI_STATUS EFIAPI FspWrapperNotifyDxeEntryPoint(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
VOID EFIAPI OnReadyToBoot(IN EFI_EVENT Event, IN VOID *Context)
EFI_STATUS RelocateImageUnder4GIfNeeded(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: LoadBelow4G.c:31
VOID EFIAPI OnPciEnumerationComplete(IN EFI_EVENT Event, IN VOID *Context)
VOID EFIAPI CallFspWrapperResetSystem(IN EFI_STATUS FspStatusResetType)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define IN
Definition: Base.h:279
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define DEBUG(Expression)
Definition: DebugLib.h:434
#define PcdGet32(TokenName)
Definition: PcdLib.h:362
#define PERF_START_EX(Handle, Token, Module, TimeStamp, Identifier)
#define PERF_END_EX(Handle, Token, Module, TimeStamp, Identifier)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_EVENT
Definition: UefiBaseType.h:37
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
EFI_STATUS EFIAPI EfiCreateEventReadyToBootEx(IN EFI_TPL NotifyTpl, IN EFI_EVENT_NOTIFY NotifyFunction OPTIONAL, IN VOID *NotifyContext OPTIONAL, OUT EFI_EVENT *ReadyToBootEvent)
Definition: UefiNotTiano.c:164
EFI_EVENT EFIAPI EfiCreateProtocolNotifyEvent(IN EFI_GUID *ProtocolGuid, IN EFI_TPL NotifyTpl, IN EFI_EVENT_NOTIFY NotifyFunction, IN VOID *NotifyContext OPTIONAL, OUT VOID **Registration)
Definition: UefiLib.c:134
Definition: Base.h:213
FSP_INIT_PHASE Phase
Definition: FspApi.h:491