2 This driver will register two callbacks to call fsp's notifies.
\r
4 Copyright (c) 2014 - 2016, Intel Corporation. All rights reserved.<BR>
\r
5 This program and the accompanying materials
\r
6 are licensed and made available under the terms and conditions of the BSD License
\r
7 which accompanies this distribution. The full text of the license may be found at
\r
8 http://opensource.org/licenses/bsd-license.php.
\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
\r
17 #include <Protocol/PciEnumerationComplete.h>
\r
19 #include <Library/UefiDriverEntryPoint.h>
\r
20 #include <Library/UefiBootServicesTableLib.h>
\r
21 #include <Library/DebugLib.h>
\r
22 #include <Library/BaseMemoryLib.h>
\r
23 #include <Library/UefiLib.h>
\r
24 #include <Library/FspWrapperApiLib.h>
\r
25 #include <Library/FspWrapperPlatformLib.h>
\r
26 #include <Library/PerformanceLib.h>
\r
27 #include <Library/HobLib.h>
\r
28 #include <FspStatusCode.h>
\r
32 (EFIAPI * ADD_PERFORMANCE_RECORDS)(
\r
33 IN CONST VOID *HobStart
\r
36 struct _ADD_PERFORMANCE_RECORD_PROTOCOL {
\r
37 ADD_PERFORMANCE_RECORDS AddPerformanceRecords;
\r
40 typedef struct _ADD_PERFORMANCE_RECORD_PROTOCOL ADD_PERFORMANCE_RECORD_PROTOCOL;
\r
42 extern EFI_GUID gAddPerfRecordProtocolGuid;
\r
43 extern EFI_GUID gFspHobGuid;
\r
44 extern EFI_GUID gFspApiPerformanceGuid;
\r
46 EFI_EVENT mExitBootServicesEvent = NULL;
\r
49 Relocate this image under 4G memory.
\r
51 @param ImageHandle Handle of driver image.
\r
52 @param SystemTable Pointer to system table.
\r
54 @retval EFI_SUCCESS Image successfully relocated.
\r
55 @retval EFI_ABORTED Failed to relocate image.
\r
59 RelocateImageUnder4GIfNeeded (
\r
60 IN EFI_HANDLE ImageHandle,
\r
61 IN EFI_SYSTEM_TABLE *SystemTable
\r
65 PciEnumerationComplete Protocol notification event handler.
\r
67 @param[in] Event Event whose notification function is being invoked.
\r
68 @param[in] Context Pointer to the notification function's context.
\r
72 OnPciEnumerationComplete (
\r
77 NOTIFY_PHASE_PARAMS NotifyPhaseParams;
\r
82 // Try to locate it because gEfiPciEnumerationCompleteProtocolGuid will trigger it once when registration.
\r
83 // Just return if it is not found.
\r
85 Status = gBS->LocateProtocol (
\r
86 &gEfiPciEnumerationCompleteProtocolGuid,
\r
90 if (EFI_ERROR (Status)) {
\r
94 NotifyPhaseParams.Phase = EnumInitPhaseAfterPciEnumeration;
\r
95 PERF_START_EX(&gFspApiPerformanceGuid, "EventRec", NULL, 0, FSP_STATUS_CODE_POST_PCIE_ENUM_NOTIFICATION | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_ENTRY);
\r
96 Status = CallFspNotifyPhase (&NotifyPhaseParams);
\r
97 PERF_END_EX(&gFspApiPerformanceGuid, "EventRec", NULL, 0, FSP_STATUS_CODE_POST_PCIE_ENUM_NOTIFICATION | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_EXIT);
\r
100 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status
\r
102 if ((Status >= FSP_STATUS_RESET_REQUIRED_COLD) && (Status <= FSP_STATUS_RESET_REQUIRED_8)) {
\r
103 DEBUG((DEBUG_INFO, "FSP NotifyPhase AfterPciEnumeration requested reset 0x%x\n", Status));
\r
104 CallFspWrapperResetSystem ((UINT32)Status);
\r
107 if (Status != EFI_SUCCESS) {
\r
108 DEBUG((DEBUG_ERROR, "FSP NotifyPhase AfterPciEnumeration failed, status: 0x%x\n", Status));
\r
110 DEBUG((DEBUG_INFO, "FSP NotifyPhase AfterPciEnumeration Success.\n"));
\r
115 Notification function of EVT_GROUP_READY_TO_BOOT event group.
\r
117 This is a notification function registered on EVT_GROUP_READY_TO_BOOT event group.
\r
118 When the Boot Manager is about to load and execute a boot option, it reclaims variable
\r
119 storage if free size is below the threshold.
\r
121 @param[in] Event Event whose notification function is being invoked.
\r
122 @param[in] Context Pointer to the notification function's context.
\r
128 IN EFI_EVENT Event,
\r
132 NOTIFY_PHASE_PARAMS NotifyPhaseParams;
\r
135 gBS->CloseEvent (Event);
\r
137 NotifyPhaseParams.Phase = EnumInitPhaseReadyToBoot;
\r
138 PERF_START_EX(&gFspApiPerformanceGuid, "EventRec", NULL, 0, FSP_STATUS_CODE_READY_TO_BOOT_NOTIFICATION | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_ENTRY);
\r
139 Status = CallFspNotifyPhase (&NotifyPhaseParams);
\r
140 PERF_END_EX(&gFspApiPerformanceGuid, "EventRec", NULL, 0, FSP_STATUS_CODE_READY_TO_BOOT_NOTIFICATION | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_EXIT);
\r
143 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status
\r
145 if ((Status >= FSP_STATUS_RESET_REQUIRED_COLD) && (Status <= FSP_STATUS_RESET_REQUIRED_8)) {
\r
146 DEBUG((DEBUG_INFO, "FSP NotifyPhase ReadyToBoot requested reset 0x%x\n", Status));
\r
147 CallFspWrapperResetSystem ((UINT32)Status);
\r
150 if (Status != EFI_SUCCESS) {
\r
151 DEBUG((DEBUG_ERROR, "FSP NotifyPhase ReadyToBoot failed, status: 0x%x\n", Status));
\r
153 DEBUG((DEBUG_INFO, "FSP NotifyPhase ReadyToBoot Success.\n"));
\r
158 This stage is notified just before the firmware/Preboot environment transfers
\r
159 management of all system resources to the OS or next level execution environment.
\r
161 @param Event Event whose notification function is being invoked.
\r
162 @param Context Pointer to the notification function's context, which is
\r
163 always zero in current implementation.
\r
169 IN EFI_EVENT Event,
\r
173 NOTIFY_PHASE_PARAMS NotifyPhaseParams;
\r
175 ADD_PERFORMANCE_RECORD_PROTOCOL *AddPerfRecordInterface;
\r
176 EFI_PEI_HOB_POINTERS Hob;
\r
177 VOID **FspHobListPtr;
\r
179 gBS->CloseEvent (Event);
\r
181 NotifyPhaseParams.Phase = EnumInitPhaseEndOfFirmware;
\r
182 PERF_START_EX(&gFspApiPerformanceGuid, "EventRec", NULL, 0, FSP_STATUS_CODE_END_OF_FIRMWARE_NOTIFICATION | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_ENTRY);
\r
183 Status = CallFspNotifyPhase (&NotifyPhaseParams);
\r
184 PERF_END_EX(&gFspApiPerformanceGuid, "EventRec", NULL, 0, FSP_STATUS_CODE_END_OF_FIRMWARE_NOTIFICATION | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_EXIT);
\r
187 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status
\r
189 if ((Status >= FSP_STATUS_RESET_REQUIRED_COLD) && (Status <= FSP_STATUS_RESET_REQUIRED_8)) {
\r
190 DEBUG((DEBUG_INFO, "FSP NotifyPhase EndOfFirmware requested reset 0x%x\n", Status));
\r
191 CallFspWrapperResetSystem ((UINT32)Status);
\r
194 if (Status != EFI_SUCCESS) {
\r
195 DEBUG((DEBUG_ERROR, "FSP NotifyPhase EndOfFirmware failed, status: 0x%x\n", Status));
\r
197 DEBUG((DEBUG_INFO, "FSP NotifyPhase EndOfFirmware Success.\n"));
\r
199 Status = gBS->LocateProtocol (
\r
200 &gAddPerfRecordProtocolGuid,
\r
202 (VOID**) &AddPerfRecordInterface
\r
204 if (EFI_ERROR (Status)) {
\r
205 DEBUG((DEBUG_INFO, "gAddPerfRecordProtocolGuid - Locate protocol failed\n"));
\r
208 Hob.Raw = GetFirstGuidHob (&gFspHobGuid);
\r
209 if (Hob.Raw != NULL) {
\r
210 FspHobListPtr = GET_GUID_HOB_DATA (Hob.Raw);
\r
211 AddPerfRecordInterface->AddPerformanceRecords ((VOID *)(UINTN)(((UINT32)(UINTN)*FspHobListPtr) & 0xFFFFFFFF));
\r
217 Main entry for the FSP DXE module.
\r
219 This routine registers two callbacks to call fsp's notifies.
\r
221 @param[in] ImageHandle The firmware allocated handle for the EFI image.
\r
222 @param[in] SystemTable A pointer to the EFI System Table.
\r
224 @retval EFI_SUCCESS The entry point is executed successfully.
\r
225 @retval other Some error occurs when executing this entry point.
\r
230 FspWrapperNotifyDxeEntryPoint (
\r
231 IN EFI_HANDLE ImageHandle,
\r
232 IN EFI_SYSTEM_TABLE *SystemTable
\r
236 EFI_EVENT ReadyToBootEvent;
\r
237 VOID *Registration;
\r
238 EFI_EVENT ProtocolNotifyEvent;
\r
241 // Load this driver's image to memory
\r
243 Status = RelocateImageUnder4GIfNeeded (ImageHandle, SystemTable);
\r
244 if (EFI_ERROR (Status)) {
\r
245 return EFI_SUCCESS;
\r
248 ProtocolNotifyEvent = EfiCreateProtocolNotifyEvent (
\r
249 &gEfiPciEnumerationCompleteProtocolGuid,
\r
251 OnPciEnumerationComplete,
\r
255 ASSERT (ProtocolNotifyEvent != NULL);
\r
257 Status = EfiCreateEventReadyToBootEx (
\r
263 ASSERT_EFI_ERROR (Status);
\r
265 Status = gBS->CreateEventEx (
\r
270 &gEfiEventExitBootServicesGuid,
\r
271 &mExitBootServicesEvent
\r
273 ASSERT_EFI_ERROR (Status);
\r
275 return EFI_SUCCESS;
\r