2 This driver will register two callbacks to call fsp's notifies.
4 Copyright (c) 2014 - 2015, 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/FspApiLib.h>
27 Relocate this image under 4G memory.
29 @param ImageHandle Handle of driver image.
30 @param SystemTable Pointer to system table.
32 @retval EFI_SUCCESS Image successfully relocated.
33 @retval EFI_ABORTED Failed to relocate image.
37 RelocateImageUnder4GIfNeeded (
38 IN EFI_HANDLE ImageHandle
,
39 IN EFI_SYSTEM_TABLE
*SystemTable
42 FSP_INFO_HEADER
*mFspHeader
= NULL
;
45 PciEnumerationComplete Protocol notification event handler.
47 @param[in] Event Event whose notification function is being invoked.
48 @param[in] Context Pointer to the notification function's context.
52 OnPciEnumerationComplete (
57 NOTIFY_PHASE_PARAMS NotifyPhaseParams
;
62 // Try to locate it because gEfiPciEnumerationCompleteProtocolGuid will trigger it once when registration.
63 // Just return if it is not found.
65 Status
= gBS
->LocateProtocol (
66 &gEfiPciEnumerationCompleteProtocolGuid
,
70 if (EFI_ERROR (Status
)) {
74 NotifyPhaseParams
.Phase
= EnumInitPhaseAfterPciEnumeration
;
75 Status
= CallFspNotifyPhase (mFspHeader
, &NotifyPhaseParams
);
76 if (Status
!= EFI_SUCCESS
) {
77 DEBUG((DEBUG_ERROR
, "FSP NotifyPhase AfterPciEnumeration failed, status: 0x%x\n", Status
));
79 DEBUG((DEBUG_INFO
, "FSP NotifyPhase AfterPciEnumeration Success.\n"));
84 Notification function of EVT_GROUP_READY_TO_BOOT event group.
86 This is a notification function registered on EVT_GROUP_READY_TO_BOOT event group.
87 When the Boot Manager is about to load and execute a boot option, it reclaims variable
88 storage if free size is below the threshold.
90 @param[in] Event Event whose notification function is being invoked.
91 @param[in] Context Pointer to the notification function's context.
101 NOTIFY_PHASE_PARAMS NotifyPhaseParams
;
104 gBS
->CloseEvent (Event
);
106 NotifyPhaseParams
.Phase
= EnumInitPhaseReadyToBoot
;
107 Status
= CallFspNotifyPhase (mFspHeader
, &NotifyPhaseParams
);
108 if (Status
!= EFI_SUCCESS
) {
109 DEBUG((DEBUG_ERROR
, "FSP NotifyPhase ReadyToBoot failed, status: 0x%x\n", Status
));
111 DEBUG((DEBUG_INFO
, "FSP NotifyPhase ReadyToBoot Success.\n"));
116 Main entry for the FSP DXE module.
118 This routine registers two callbacks to call fsp's notifies.
120 @param[in] ImageHandle The firmware allocated handle for the EFI image.
121 @param[in] SystemTable A pointer to the EFI System Table.
123 @retval EFI_SUCCESS The entry point is executed successfully.
124 @retval other Some error occurs when executing this entry point.
130 IN EFI_HANDLE ImageHandle
,
131 IN EFI_SYSTEM_TABLE
*SystemTable
135 EFI_EVENT ReadyToBootEvent
;
137 EFI_EVENT ProtocolNotifyEvent
;
140 // Load this driver's image to memory
142 Status
= RelocateImageUnder4GIfNeeded (ImageHandle
, SystemTable
);
143 if (EFI_ERROR (Status
)) {
147 if (PcdGet32 (PcdFlashFvSecondFspBase
) == 0) {
148 mFspHeader
= FspFindFspHeader (PcdGet32 (PcdFlashFvFspBase
));
150 mFspHeader
= FspFindFspHeader (PcdGet32 (PcdFlashFvSecondFspBase
));
152 DEBUG ((DEBUG_INFO
, "FspHeader - 0x%x\n", mFspHeader
));
153 if (mFspHeader
== NULL
) {
154 return EFI_DEVICE_ERROR
;
157 ProtocolNotifyEvent
= EfiCreateProtocolNotifyEvent (
158 &gEfiPciEnumerationCompleteProtocolGuid
,
160 OnPciEnumerationComplete
,
164 ASSERT (ProtocolNotifyEvent
!= NULL
);
166 Status
= EfiCreateEventReadyToBootEx (
172 ASSERT_EFI_ERROR (Status
);