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