]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFspWrapperPkg/FspNotifyDxe/FspNotifyDxe.c
IntelFspWrapperPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / IntelFspWrapperPkg / FspNotifyDxe / FspNotifyDxe.c
CommitLineData
a33a2f62
JY
1/** @file\r
2 This driver will register two callbacks to call fsp's notifies.\r
3\r
d8043ce9 4 Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.<BR>\r
19486360 5 SPDX-License-Identifier: BSD-2-Clause-Patent\r
a33a2f62
JY
6\r
7**/\r
8\r
9#include <PiDxe.h>\r
10\r
11#include <Protocol/PciEnumerationComplete.h>\r
12\r
13#include <Library/UefiDriverEntryPoint.h>\r
14#include <Library/UefiBootServicesTableLib.h>\r
15#include <Library/DebugLib.h>\r
16#include <Library/BaseMemoryLib.h>\r
17#include <Library/UefiLib.h>\r
18#include <Library/FspApiLib.h>\r
19\r
00899456
JY
20/**\r
21 Relocate this image under 4G memory.\r
22\r
23 @param ImageHandle Handle of driver image.\r
24 @param SystemTable Pointer to system table.\r
25\r
26 @retval EFI_SUCCESS Image successfully relocated.\r
27 @retval EFI_ABORTED Failed to relocate image.\r
28\r
29**/\r
30EFI_STATUS\r
31RelocateImageUnder4GIfNeeded (\r
32 IN EFI_HANDLE ImageHandle,\r
33 IN EFI_SYSTEM_TABLE *SystemTable\r
34 );\r
35\r
a33a2f62
JY
36FSP_INFO_HEADER *mFspHeader = NULL;\r
37\r
38/**\r
39 PciEnumerationComplete Protocol notification event handler.\r
40\r
41 @param[in] Event Event whose notification function is being invoked.\r
42 @param[in] Context Pointer to the notification function's context.\r
43**/\r
44VOID\r
45EFIAPI\r
46OnPciEnumerationComplete (\r
47 IN EFI_EVENT Event,\r
48 IN VOID *Context\r
49 )\r
50{\r
51 NOTIFY_PHASE_PARAMS NotifyPhaseParams;\r
52 EFI_STATUS Status;\r
a33a2f62
JY
53 VOID *Interface;\r
54\r
55 //\r
56 // Try to locate it because gEfiPciEnumerationCompleteProtocolGuid will trigger it once when registration.\r
57 // Just return if it is not found.\r
58 //\r
59 Status = gBS->LocateProtocol (\r
60 &gEfiPciEnumerationCompleteProtocolGuid,\r
61 NULL,\r
62 &Interface\r
63 );\r
64 if (EFI_ERROR (Status)) {\r
65 return ;\r
66 }\r
67\r
68 NotifyPhaseParams.Phase = EnumInitPhaseAfterPciEnumeration;\r
d8043ce9
JY
69 Status = CallFspNotifyPhase (mFspHeader, &NotifyPhaseParams);\r
70 if (Status != EFI_SUCCESS) {\r
71 DEBUG((DEBUG_ERROR, "FSP NotifyPhase AfterPciEnumeration failed, status: 0x%x\n", Status));\r
a33a2f62
JY
72 } else {\r
73 DEBUG((DEBUG_INFO, "FSP NotifyPhase AfterPciEnumeration Success.\n"));\r
74 }\r
75}\r
76\r
77/**\r
78 Notification function of EVT_GROUP_READY_TO_BOOT event group.\r
79\r
80 This is a notification function registered on EVT_GROUP_READY_TO_BOOT event group.\r
81 When the Boot Manager is about to load and execute a boot option, it reclaims variable\r
82 storage if free size is below the threshold.\r
83\r
84 @param[in] Event Event whose notification function is being invoked.\r
85 @param[in] Context Pointer to the notification function's context.\r
86\r
87**/\r
88VOID\r
89EFIAPI\r
90OnReadyToBoot (\r
91 IN EFI_EVENT Event,\r
92 IN VOID *Context\r
93 )\r
94{\r
95 NOTIFY_PHASE_PARAMS NotifyPhaseParams;\r
d8043ce9 96 EFI_STATUS Status;\r
a33a2f62
JY
97\r
98 gBS->CloseEvent (Event);\r
99\r
100 NotifyPhaseParams.Phase = EnumInitPhaseReadyToBoot;\r
d8043ce9
JY
101 Status = CallFspNotifyPhase (mFspHeader, &NotifyPhaseParams);\r
102 if (Status != EFI_SUCCESS) {\r
103 DEBUG((DEBUG_ERROR, "FSP NotifyPhase ReadyToBoot failed, status: 0x%x\n", Status));\r
a33a2f62
JY
104 } else {\r
105 DEBUG((DEBUG_INFO, "FSP NotifyPhase ReadyToBoot Success.\n"));\r
106 }\r
107}\r
108\r
109/**\r
110 Main entry for the FSP DXE module.\r
111\r
112 This routine registers two callbacks to call fsp's notifies.\r
113\r
114 @param[in] ImageHandle The firmware allocated handle for the EFI image.\r
115 @param[in] SystemTable A pointer to the EFI System Table.\r
116\r
117 @retval EFI_SUCCESS The entry point is executed successfully.\r
118 @retval other Some error occurs when executing this entry point.\r
119\r
120**/\r
121EFI_STATUS\r
122EFIAPI\r
123FspDxeEntryPoint (\r
124 IN EFI_HANDLE ImageHandle,\r
125 IN EFI_SYSTEM_TABLE *SystemTable\r
126 )\r
127{\r
128 EFI_STATUS Status;\r
129 EFI_EVENT ReadyToBootEvent;\r
130 VOID *Registration;\r
131 EFI_EVENT ProtocolNotifyEvent;\r
132\r
00899456
JY
133 //\r
134 // Load this driver's image to memory\r
135 //\r
136 Status = RelocateImageUnder4GIfNeeded (ImageHandle, SystemTable);\r
137 if (EFI_ERROR (Status)) {\r
138 return EFI_SUCCESS;\r
139 }\r
140\r
5c7c41f8
MM
141 if (PcdGet32 (PcdFlashFvSecondFspBase) == 0) {\r
142 mFspHeader = FspFindFspHeader (PcdGet32 (PcdFlashFvFspBase));\r
143 } else {\r
144 mFspHeader = FspFindFspHeader (PcdGet32 (PcdFlashFvSecondFspBase));\r
145 }\r
a33a2f62
JY
146 DEBUG ((DEBUG_INFO, "FspHeader - 0x%x\n", mFspHeader));\r
147 if (mFspHeader == NULL) {\r
148 return EFI_DEVICE_ERROR;\r
149 }\r
150\r
151 ProtocolNotifyEvent = EfiCreateProtocolNotifyEvent (\r
152 &gEfiPciEnumerationCompleteProtocolGuid,\r
153 TPL_CALLBACK,\r
154 OnPciEnumerationComplete,\r
155 NULL,\r
156 &Registration\r
157 );\r
158 ASSERT (ProtocolNotifyEvent != NULL);\r
159\r
160 Status = EfiCreateEventReadyToBootEx (\r
161 TPL_CALLBACK,\r
162 OnReadyToBoot,\r
163 NULL,\r
164 &ReadyToBootEvent\r
165 );\r
166 ASSERT_EFI_ERROR (Status);\r
167\r
168 return EFI_SUCCESS;\r
169}\r
170\r