Update IntelFspPkg according to FSP1.1.
[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
4 Copyright (c) 2014, 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
9\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
12\r
13**/\r
14\r
15#include <PiDxe.h>\r
16\r
17#include <Protocol/PciEnumerationComplete.h>\r
18\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/FspApiLib.h>\r
25\r
26FSP_INFO_HEADER *mFspHeader = NULL;\r
27\r
28/**\r
29 PciEnumerationComplete Protocol notification event handler.\r
30\r
31 @param[in] Event Event whose notification function is being invoked.\r
32 @param[in] Context Pointer to the notification function's context.\r
33**/\r
34VOID\r
35EFIAPI\r
36OnPciEnumerationComplete (\r
37 IN EFI_EVENT Event,\r
38 IN VOID *Context\r
39 )\r
40{\r
41 NOTIFY_PHASE_PARAMS NotifyPhaseParams;\r
42 EFI_STATUS Status;\r
43 FSP_STATUS FspStatus;\r
44 VOID *Interface;\r
45\r
46 //\r
47 // Try to locate it because gEfiPciEnumerationCompleteProtocolGuid will trigger it once when registration.\r
48 // Just return if it is not found.\r
49 //\r
50 Status = gBS->LocateProtocol (\r
51 &gEfiPciEnumerationCompleteProtocolGuid,\r
52 NULL,\r
53 &Interface\r
54 );\r
55 if (EFI_ERROR (Status)) {\r
56 return ;\r
57 }\r
58\r
59 NotifyPhaseParams.Phase = EnumInitPhaseAfterPciEnumeration;\r
60 FspStatus = CallFspNotifyPhase (mFspHeader, &NotifyPhaseParams);\r
61 if (FspStatus != FSP_SUCCESS) {\r
62 DEBUG((DEBUG_ERROR, "FSP NotifyPhase AfterPciEnumeration failed, status: 0x%x\n", FspStatus));\r
63 } else {\r
64 DEBUG((DEBUG_INFO, "FSP NotifyPhase AfterPciEnumeration Success.\n"));\r
65 }\r
66}\r
67\r
68/**\r
69 Notification function of EVT_GROUP_READY_TO_BOOT event group.\r
70\r
71 This is a notification function registered on EVT_GROUP_READY_TO_BOOT event group.\r
72 When the Boot Manager is about to load and execute a boot option, it reclaims variable\r
73 storage if free size is below the threshold.\r
74\r
75 @param[in] Event Event whose notification function is being invoked.\r
76 @param[in] Context Pointer to the notification function's context.\r
77\r
78**/\r
79VOID\r
80EFIAPI\r
81OnReadyToBoot (\r
82 IN EFI_EVENT Event,\r
83 IN VOID *Context\r
84 )\r
85{\r
86 NOTIFY_PHASE_PARAMS NotifyPhaseParams;\r
87 FSP_STATUS FspStatus;\r
88\r
89 gBS->CloseEvent (Event);\r
90\r
91 NotifyPhaseParams.Phase = EnumInitPhaseReadyToBoot;\r
92 FspStatus = CallFspNotifyPhase (mFspHeader, &NotifyPhaseParams);\r
93 if (FspStatus != FSP_SUCCESS) {\r
94 DEBUG((DEBUG_ERROR, "FSP NotifyPhase ReadyToBoot failed, status: 0x%x\n", FspStatus));\r
95 } else {\r
96 DEBUG((DEBUG_INFO, "FSP NotifyPhase ReadyToBoot Success.\n"));\r
97 }\r
98}\r
99\r
100/**\r
101 Main entry for the FSP DXE module.\r
102\r
103 This routine registers two callbacks to call fsp's notifies.\r
104\r
105 @param[in] ImageHandle The firmware allocated handle for the EFI image.\r
106 @param[in] SystemTable A pointer to the EFI System Table.\r
107\r
108 @retval EFI_SUCCESS The entry point is executed successfully.\r
109 @retval other Some error occurs when executing this entry point.\r
110\r
111**/\r
112EFI_STATUS\r
113EFIAPI\r
114FspDxeEntryPoint (\r
115 IN EFI_HANDLE ImageHandle,\r
116 IN EFI_SYSTEM_TABLE *SystemTable\r
117 )\r
118{\r
119 EFI_STATUS Status;\r
120 EFI_EVENT ReadyToBootEvent;\r
121 VOID *Registration;\r
122 EFI_EVENT ProtocolNotifyEvent;\r
123\r
124 mFspHeader = FspFindFspHeader (PcdGet32 (PcdFlashFvFspBase));\r
125 DEBUG ((DEBUG_INFO, "FspHeader - 0x%x\n", mFspHeader));\r
126 if (mFspHeader == NULL) {\r
127 return EFI_DEVICE_ERROR;\r
128 }\r
129\r
130 ProtocolNotifyEvent = EfiCreateProtocolNotifyEvent (\r
131 &gEfiPciEnumerationCompleteProtocolGuid,\r
132 TPL_CALLBACK,\r
133 OnPciEnumerationComplete,\r
134 NULL,\r
135 &Registration\r
136 );\r
137 ASSERT (ProtocolNotifyEvent != NULL);\r
138\r
139 Status = EfiCreateEventReadyToBootEx (\r
140 TPL_CALLBACK,\r
141 OnReadyToBoot,\r
142 NULL,\r
143 &ReadyToBootEvent\r
144 );\r
145 ASSERT_EFI_ERROR (Status);\r
146\r
147 return EFI_SUCCESS;\r
148}\r
149\r