]>
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 | |
14 | \r | |
1efcc4ae | 15 | \r |
f734a10a | 16 | #include "UefiLibInternal.h"\r |
e386b444 | 17 | \r |
e386b444 | 18 | /**\r |
cf8ae2f6 | 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 | |
7f1eba7b | 27 | If LegacyBootEvent is NULL, then ASSERT().\r |
cf8ae2f6 | 28 | \r |
e386b444 | 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 | |
1b197063 | 43 | EfiEventEmptyFunction,\r |
e386b444 | 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 | |
9095d37b LG |
51 | the caller to specify a notification function.\r |
52 | \r | |
e386b444 | 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 | |
e8326a00 ML |
77 | EFI_STATUS Status;\r |
78 | EFI_EVENT_NOTIFY WorkerNotifyFunction;\r | |
e386b444 | 79 | \r |
80 | ASSERT (LegacyBootEvent != NULL);\r | |
81 | \r | |
c7d265a9 | 82 | if (gST->Hdr.Revision < EFI_2_00_SYSTEM_TABLE_REVISION) {\r |
83 | DEBUG ((EFI_D_ERROR, "EFI1.1 can't support LegacyBootEvent!"));\r | |
84 | ASSERT (FALSE);\r | |
85 | \r | |
e386b444 | 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 | |
e8326a00 ML |
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 | |
1b197063 | 96 | WorkerNotifyFunction = EfiEventEmptyFunction;\r |
e8326a00 ML |
97 | } else {\r |
98 | WorkerNotifyFunction = NotifyFunction;\r | |
99 | }\r | |
e386b444 | 100 | Status = gBS->CreateEventEx (\r |
101 | EVT_NOTIFY_SIGNAL,\r | |
102 | NotifyTpl,\r | |
e8326a00 | 103 | WorkerNotifyFunction,\r |
e386b444 | 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 | |
cf8ae2f6 | 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 | |
9095d37b LG |
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 | |
7f1eba7b | 121 | change with the version of the specification supported.\r |
122 | If ReadyToBootEvent is NULL, then ASSERT().\r | |
e386b444 | 123 | \r |
58380e9c | 124 | @param ReadyToBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex).\r |
e386b444 | 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 | |
c7d265a9 | 137 | TPL_CALLBACK,\r |
1b197063 | 138 | EfiEventEmptyFunction,\r |
e386b444 | 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 | |
9095d37b LG |
146 | the caller to specify a notification function.\r |
147 | \r | |
e386b444 | 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 | |
42eedea9 | 157 | @param ReadyToBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex).\r |
e386b444 | 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 | |
e8326a00 ML |
172 | EFI_STATUS Status;\r |
173 | EFI_EVENT_NOTIFY WorkerNotifyFunction;\r | |
e386b444 | 174 | \r |
175 | ASSERT (ReadyToBootEvent != NULL);\r | |
176 | \r | |
c7d265a9 | 177 | if (gST->Hdr.Revision < EFI_2_00_SYSTEM_TABLE_REVISION) {\r |
178 | DEBUG ((EFI_D_ERROR, "EFI1.1 can't support ReadyToBootEvent!"));\r | |
179 | ASSERT (FALSE);\r | |
180 | \r | |
e386b444 | 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 | |
e8326a00 ML |
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 | |
1b197063 | 191 | WorkerNotifyFunction = EfiEventEmptyFunction;\r |
e8326a00 ML |
192 | } else {\r |
193 | WorkerNotifyFunction = NotifyFunction;\r | |
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 | |
208 | \r | |
209 | /**\r | |
1d37ab9f | 210 | Create, Signal, and Close the Ready to Boot event using EfiSignalEventReadyToBoot().\r |
9095d37b | 211 | \r |
1d37ab9f | 212 | This function abstracts the signaling of the Ready to Boot Event. The Framework moved\r |
cf8ae2f6 | 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 | |
e386b444 | 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 | |
1d37ab9f | 235 | Create, Signal, and Close the Ready to Boot event using EfiSignalEventLegacyBoot().\r |
e386b444 | 236 | \r |
1d37ab9f | 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 | |
e386b444 | 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 | |
9095d37b LG |
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 | |
7f1eba7b | 264 | This library function abstracts validating a device path node.\r |
9095d37b LG |
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 | |
1d37ab9f | 269 | the differences from the caller.\r |
9edc73ad | 270 | If FvDevicePathNode is NULL, then ASSERT().\r |
1d37ab9f | 271 | \r |
2fc59a00 | 272 | @param FvDevicePathNode The pointer to FV device path to check.\r |
e386b444 | 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 | |
070a76b1 | 278 | EFI_GUID *\r |
e386b444 | 279 | EFIAPI\r |
280 | EfiGetNameGuidFromFwVolDevicePathNode (\r | |
070a76b1 | 281 | IN CONST MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvDevicePathNode\r |
e386b444 | 282 | )\r |
283 | {\r | |
070a76b1 | 284 | ASSERT (FvDevicePathNode != NULL);\r |
c7d265a9 | 285 | \r |
070a76b1 | 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 | |
c7d265a9 | 289 | }\r |
290 | \r | |
e386b444 | 291 | return NULL;\r |
292 | }\r | |
293 | \r | |
294 | \r | |
295 | /**\r | |
1d37ab9f | 296 | Initialize a Firmware Volume (FV) Media Device Path node.\r |
9095d37b LG |
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 | |
7f1eba7b | 303 | differences from the caller.\r |
9edc73ad | 304 | If FvDevicePathNode is NULL, then ASSERT().\r |
305 | If NameGuid is NULL, then ASSERT().\r | |
9095d37b | 306 | \r |
2fc59a00 | 307 | @param FvDevicePathNode The pointer to a FV device path node to initialize\r |
e386b444 | 308 | @param NameGuid FV file name to use in FvDevicePathNode\r |
309 | \r | |
310 | **/\r | |
311 | VOID\r | |
312 | EFIAPI\r | |
313 | EfiInitializeFwVolDevicepathNode (\r | |
070a76b1 | 314 | IN OUT MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvDevicePathNode,\r |
315 | IN CONST EFI_GUID *NameGuid\r | |
e386b444 | 316 | )\r |
317 | {\r | |
070a76b1 | 318 | ASSERT (FvDevicePathNode != NULL);\r |
e386b444 | 319 | ASSERT (NameGuid != NULL);\r |
c7d265a9 | 320 | \r |
e386b444 | 321 | //\r |
c7d265a9 | 322 | // Use the new Device path that does not conflict with the UEFI\r |
e386b444 | 323 | //\r |
070a76b1 | 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 | |
c7d265a9 | 327 | \r |
070a76b1 | 328 | CopyGuid (&FvDevicePathNode->FvFileName, NameGuid);\r |
e386b444 | 329 | }\r |
330 | \r |