]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | Library functions that abstract areas of conflict between framework and UEFI 2.0.\r | |
3 | \r | |
4 | Help Port Framework code that has conflicts with UEFI 2.0 by hiding the\r | |
5 | old conflicts with library functions and supporting implementations of the old\r | |
6 | (EDK/EFI 1.10) and new (EDK II/UEFI 2.0) way. This module is a DXE driver as\r | |
7 | it contains DXE enum extensions for EFI event services.\r | |
8 | \r | |
9 | Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r | |
10 | SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
11 | \r | |
12 | **/\r | |
13 | \r | |
14 | \r | |
15 | \r | |
16 | #include "UefiLibInternal.h"\r | |
17 | \r | |
18 | /**\r | |
19 | Creates an EFI event in the Legacy Boot Event Group.\r | |
20 | \r | |
21 | Prior to UEFI 2.0 this was done via a non blessed UEFI extensions and this library\r | |
22 | abstracts the implementation mechanism of this event from the caller. This function\r | |
23 | abstracts the creation of the Legacy Boot Event. The Framework moved from a proprietary\r | |
24 | to UEFI 2.0 based mechanism. This library abstracts the caller from how this event\r | |
25 | is created to prevent to code form having to change with the version of the\r | |
26 | specification supported.\r | |
27 | If LegacyBootEvent is NULL, then ASSERT().\r | |
28 | \r | |
29 | @param LegacyBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex).\r | |
30 | \r | |
31 | @retval EFI_SUCCESS Event was created.\r | |
32 | @retval Other Event was not created.\r | |
33 | \r | |
34 | **/\r | |
35 | EFI_STATUS\r | |
36 | EFIAPI\r | |
37 | EfiCreateEventLegacyBoot (\r | |
38 | OUT EFI_EVENT *LegacyBootEvent\r | |
39 | )\r | |
40 | {\r | |
41 | return EfiCreateEventLegacyBootEx (\r | |
42 | TPL_CALLBACK,\r | |
43 | EfiEventEmptyFunction,\r | |
44 | NULL,\r | |
45 | LegacyBootEvent\r | |
46 | );\r | |
47 | }\r | |
48 | \r | |
49 | /**\r | |
50 | Create an EFI event in the Legacy Boot Event Group and allows\r | |
51 | the caller to specify a notification function.\r | |
52 | \r | |
53 | This function abstracts the creation of the Legacy Boot Event.\r | |
54 | The Framework moved from a proprietary to UEFI 2.0 based mechanism.\r | |
55 | This library abstracts the caller from how this event is created to prevent\r | |
56 | to code form having to change with the version of the specification supported.\r | |
57 | If LegacyBootEvent is NULL, then ASSERT().\r | |
58 | \r | |
59 | @param NotifyTpl The task priority level of the event.\r | |
60 | @param NotifyFunction The notification function to call when the event is signaled.\r | |
61 | @param NotifyContext The content to pass to NotifyFunction when the event is signaled.\r | |
62 | @param LegacyBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex).\r | |
63 | \r | |
64 | @retval EFI_SUCCESS Event was created.\r | |
65 | @retval Other Event was not created.\r | |
66 | \r | |
67 | **/\r | |
68 | EFI_STATUS\r | |
69 | EFIAPI\r | |
70 | EfiCreateEventLegacyBootEx (\r | |
71 | IN EFI_TPL NotifyTpl,\r | |
72 | IN EFI_EVENT_NOTIFY NotifyFunction OPTIONAL,\r | |
73 | IN VOID *NotifyContext OPTIONAL,\r | |
74 | OUT EFI_EVENT *LegacyBootEvent\r | |
75 | )\r | |
76 | {\r | |
77 | EFI_STATUS Status;\r | |
78 | EFI_EVENT_NOTIFY WorkerNotifyFunction;\r | |
79 | \r | |
80 | ASSERT (LegacyBootEvent != NULL);\r | |
81 | \r | |
82 | if (gST->Hdr.Revision < EFI_2_00_SYSTEM_TABLE_REVISION) {\r | |
83 | DEBUG ((DEBUG_ERROR, "EFI1.1 can't support LegacyBootEvent!"));\r | |
84 | ASSERT (FALSE);\r | |
85 | \r | |
86 | return EFI_UNSUPPORTED;\r | |
87 | } else {\r | |
88 | //\r | |
89 | // For UEFI 2.0 and the future use an Event Group\r | |
90 | //\r | |
91 | if (NotifyFunction == NULL) {\r | |
92 | //\r | |
93 | // CreateEventEx will check NotifyFunction is NULL or not and return error.\r | |
94 | // Use dummy routine for the case NotifyFunction is NULL.\r | |
95 | //\r | |
96 | WorkerNotifyFunction = EfiEventEmptyFunction;\r | |
97 | } else {\r | |
98 | WorkerNotifyFunction = NotifyFunction;\r | |
99 | }\r | |
100 | Status = gBS->CreateEventEx (\r | |
101 | EVT_NOTIFY_SIGNAL,\r | |
102 | NotifyTpl,\r | |
103 | WorkerNotifyFunction,\r | |
104 | NotifyContext,\r | |
105 | &gEfiEventLegacyBootGuid,\r | |
106 | LegacyBootEvent\r | |
107 | );\r | |
108 | }\r | |
109 | \r | |
110 | return Status;\r | |
111 | }\r | |
112 | \r | |
113 | /**\r | |
114 | Create an EFI event in the Ready To Boot Event Group.\r | |
115 | \r | |
116 | Prior to UEFI 2.0 this was done via a non-standard UEFI extension, and this library\r | |
117 | abstracts the implementation mechanism of this event from the caller.\r | |
118 | This function abstracts the creation of the Ready to Boot Event. The Framework\r | |
119 | moved from a proprietary to UEFI 2.0-based mechanism. This library abstracts\r | |
120 | the caller from how this event is created to prevent the code form having to\r | |
121 | change with the version of the specification supported.\r | |
122 | If ReadyToBootEvent is NULL, then ASSERT().\r | |
123 | \r | |
124 | @param ReadyToBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex).\r | |
125 | \r | |
126 | @retval EFI_SUCCESS Event was created.\r | |
127 | @retval Other Event was not created.\r | |
128 | \r | |
129 | **/\r | |
130 | EFI_STATUS\r | |
131 | EFIAPI\r | |
132 | EfiCreateEventReadyToBoot (\r | |
133 | OUT EFI_EVENT *ReadyToBootEvent\r | |
134 | )\r | |
135 | {\r | |
136 | return EfiCreateEventReadyToBootEx (\r | |
137 | TPL_CALLBACK,\r | |
138 | EfiEventEmptyFunction,\r | |
139 | NULL,\r | |
140 | ReadyToBootEvent\r | |
141 | );\r | |
142 | }\r | |
143 | \r | |
144 | /**\r | |
145 | Create an EFI event in the Ready To Boot Event Group and allows\r | |
146 | the caller to specify a notification function.\r | |
147 | \r | |
148 | This function abstracts the creation of the Ready to Boot Event.\r | |
149 | The Framework moved from a proprietary to UEFI 2.0 based mechanism.\r | |
150 | This library abstracts the caller from how this event is created to prevent\r | |
151 | to code form having to change with the version of the specification supported.\r | |
152 | If ReadyToBootEvent is NULL, then ASSERT().\r | |
153 | \r | |
154 | @param NotifyTpl The task priority level of the event.\r | |
155 | @param NotifyFunction The notification function to call when the event is signaled.\r | |
156 | @param NotifyContext The content to pass to NotifyFunction when the event is signaled.\r | |
157 | @param ReadyToBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex).\r | |
158 | \r | |
159 | @retval EFI_SUCCESS Event was created.\r | |
160 | @retval Other Event was not created.\r | |
161 | \r | |
162 | **/\r | |
163 | EFI_STATUS\r | |
164 | EFIAPI\r | |
165 | EfiCreateEventReadyToBootEx (\r | |
166 | IN EFI_TPL NotifyTpl,\r | |
167 | IN EFI_EVENT_NOTIFY NotifyFunction OPTIONAL,\r | |
168 | IN VOID *NotifyContext OPTIONAL,\r | |
169 | OUT EFI_EVENT *ReadyToBootEvent\r | |
170 | )\r | |
171 | {\r | |
172 | EFI_STATUS Status;\r | |
173 | EFI_EVENT_NOTIFY WorkerNotifyFunction;\r | |
174 | \r | |
175 | ASSERT (ReadyToBootEvent != NULL);\r | |
176 | \r | |
177 | if (gST->Hdr.Revision < EFI_2_00_SYSTEM_TABLE_REVISION) {\r | |
178 | DEBUG ((DEBUG_ERROR, "EFI1.1 can't support ReadyToBootEvent!"));\r | |
179 | ASSERT (FALSE);\r | |
180 | \r | |
181 | return EFI_UNSUPPORTED;\r | |
182 | } else {\r | |
183 | //\r | |
184 | // For UEFI 2.0 and the future use an Event Group\r | |
185 | //\r | |
186 | if (NotifyFunction == NULL) {\r | |
187 | //\r | |
188 | // CreateEventEx will check NotifyFunction is NULL or not and return error.\r | |
189 | // Use dummy routine for the case NotifyFunction is NULL.\r | |
190 | //\r | |
191 | WorkerNotifyFunction = EfiEventEmptyFunction;\r | |
192 | } else {\r | |
193 | WorkerNotifyFunction = NotifyFunction;\r | |
194 | }\r | |
195 | Status = gBS->CreateEventEx (\r | |
196 | EVT_NOTIFY_SIGNAL,\r | |
197 | NotifyTpl,\r | |
198 | WorkerNotifyFunction,\r | |
199 | NotifyContext,\r | |
200 | &gEfiEventReadyToBootGuid,\r | |
201 | ReadyToBootEvent\r | |
202 | );\r | |
203 | }\r | |
204 | \r | |
205 | return Status;\r | |
206 | }\r | |
207 | \r | |
208 | \r | |
209 | /**\r | |
210 | Create, Signal, and Close the Ready to Boot event using EfiSignalEventReadyToBoot().\r | |
211 | \r | |
212 | This function abstracts the signaling of the Ready to Boot Event. The Framework moved\r | |
213 | from a proprietary to UEFI 2.0 based mechanism. This library abstracts the caller\r | |
214 | from how this event is created to prevent to code form having to change with the\r | |
215 | version of the specification supported.\r | |
216 | \r | |
217 | **/\r | |
218 | VOID\r | |
219 | EFIAPI\r | |
220 | EfiSignalEventReadyToBoot (\r | |
221 | VOID\r | |
222 | )\r | |
223 | {\r | |
224 | EFI_STATUS Status;\r | |
225 | EFI_EVENT ReadyToBootEvent;\r | |
226 | \r | |
227 | Status = EfiCreateEventReadyToBoot (&ReadyToBootEvent);\r | |
228 | if (!EFI_ERROR (Status)) {\r | |
229 | gBS->SignalEvent (ReadyToBootEvent);\r | |
230 | gBS->CloseEvent (ReadyToBootEvent);\r | |
231 | }\r | |
232 | }\r | |
233 | \r | |
234 | /**\r | |
235 | Create, Signal, and Close the Ready to Boot event using EfiSignalEventLegacyBoot().\r | |
236 | \r | |
237 | This function abstracts the signaling of the Legacy Boot Event. The Framework moved from\r | |
238 | a proprietary to UEFI 2.0 based mechanism. This library abstracts the caller from how\r | |
239 | this event is created to prevent to code form having to change with the version of the\r | |
240 | specification supported.\r | |
241 | \r | |
242 | **/\r | |
243 | VOID\r | |
244 | EFIAPI\r | |
245 | EfiSignalEventLegacyBoot (\r | |
246 | VOID\r | |
247 | )\r | |
248 | {\r | |
249 | EFI_STATUS Status;\r | |
250 | EFI_EVENT LegacyBootEvent;\r | |
251 | \r | |
252 | Status = EfiCreateEventLegacyBoot (&LegacyBootEvent);\r | |
253 | if (!EFI_ERROR (Status)) {\r | |
254 | gBS->SignalEvent (LegacyBootEvent);\r | |
255 | gBS->CloseEvent (LegacyBootEvent);\r | |
256 | }\r | |
257 | }\r | |
258 | \r | |
259 | \r | |
260 | /**\r | |
261 | Check to see if the Firmware Volume (FV) Media Device Path is valid\r | |
262 | \r | |
263 | The Framework FwVol Device Path changed to conform to the UEFI 2.0 specification.\r | |
264 | This library function abstracts validating a device path node.\r | |
265 | Check the MEDIA_FW_VOL_FILEPATH_DEVICE_PATH data structure to see if it's valid.\r | |
266 | If it is valid, then return the GUID file name from the device path node. Otherwise,\r | |
267 | return NULL. This device path changed in the DXE CIS version 0.92 in a non back ward\r | |
268 | compatible way to not conflict with the UEFI 2.0 specification. This function abstracts\r | |
269 | the differences from the caller.\r | |
270 | If FvDevicePathNode is NULL, then ASSERT().\r | |
271 | \r | |
272 | @param FvDevicePathNode The pointer to FV device path to check.\r | |
273 | \r | |
274 | @retval NULL FvDevicePathNode is not valid.\r | |
275 | @retval Other FvDevicePathNode is valid and pointer to NameGuid was returned.\r | |
276 | \r | |
277 | **/\r | |
278 | EFI_GUID *\r | |
279 | EFIAPI\r | |
280 | EfiGetNameGuidFromFwVolDevicePathNode (\r | |
281 | IN CONST MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvDevicePathNode\r | |
282 | )\r | |
283 | {\r | |
284 | ASSERT (FvDevicePathNode != NULL);\r | |
285 | \r | |
286 | if (DevicePathType (&FvDevicePathNode->Header) == MEDIA_DEVICE_PATH &&\r | |
287 | DevicePathSubType (&FvDevicePathNode->Header) == MEDIA_PIWG_FW_FILE_DP) {\r | |
288 | return (EFI_GUID *) &FvDevicePathNode->FvFileName;\r | |
289 | }\r | |
290 | \r | |
291 | return NULL;\r | |
292 | }\r | |
293 | \r | |
294 | \r | |
295 | /**\r | |
296 | Initialize a Firmware Volume (FV) Media Device Path node.\r | |
297 | \r | |
298 | The Framework FwVol Device Path changed to conform to the UEFI 2.0 specification.\r | |
299 | This library function abstracts initializing a device path node.\r | |
300 | Initialize the MEDIA_FW_VOL_FILEPATH_DEVICE_PATH data structure. This device\r | |
301 | path changed in the DXE CIS version 0.92 in a non back ward compatible way to\r | |
302 | not conflict with the UEFI 2.0 specification. This function abstracts the\r | |
303 | differences from the caller.\r | |
304 | If FvDevicePathNode is NULL, then ASSERT().\r | |
305 | If NameGuid is NULL, then ASSERT().\r | |
306 | \r | |
307 | @param FvDevicePathNode The pointer to a FV device path node to initialize\r | |
308 | @param NameGuid FV file name to use in FvDevicePathNode\r | |
309 | \r | |
310 | **/\r | |
311 | VOID\r | |
312 | EFIAPI\r | |
313 | EfiInitializeFwVolDevicepathNode (\r | |
314 | IN OUT MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvDevicePathNode,\r | |
315 | IN CONST EFI_GUID *NameGuid\r | |
316 | )\r | |
317 | {\r | |
318 | ASSERT (FvDevicePathNode != NULL);\r | |
319 | ASSERT (NameGuid != NULL);\r | |
320 | \r | |
321 | //\r | |
322 | // Use the new Device path that does not conflict with the UEFI\r | |
323 | //\r | |
324 | FvDevicePathNode->Header.Type = MEDIA_DEVICE_PATH;\r | |
325 | FvDevicePathNode->Header.SubType = MEDIA_PIWG_FW_FILE_DP;\r | |
326 | SetDevicePathNodeLength (&FvDevicePathNode->Header, sizeof (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH));\r | |
327 | \r | |
328 | CopyGuid (&FvDevicePathNode->FvFileName, NameGuid);\r | |
329 | }\r |