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