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