]>
Commit | Line | Data |
---|---|---|
79964ac8 | 1 | /** @file\r |
bf428cb3 | 2 | Library functions that abstract areas of conflict between framework and UEFI 2.0.\r |
79964ac8 | 3 | \r |
bf428cb3 | 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 | |
79964ac8 | 7 | it contains DXE enum extensions for EFI event services.\r |
8 | \r | |
1c2f052d | 9 | Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r |
2b3687db | 10 | This program and the accompanying materials\r |
79964ac8 | 11 | are licensed and made available under the terms and conditions of the BSD License\r |
12 | which accompanies this distribution. The full text of the license may be found at\r | |
13 | http://opensource.org/licenses/bsd-license.php\r | |
14 | \r | |
15 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
16 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
17 | \r | |
18 | **/\r | |
19 | \r | |
bf428cb3 | 20 | \r |
21 | \r | |
22 | #include "UefiLibInternal.h"\r | |
79964ac8 | 23 | \r |
79964ac8 | 24 | /**\r |
25 | Create a Legacy Boot Event.\r | |
26 | \r | |
27 | Tiano extended the CreateEvent Type enum to add a legacy boot event type.\r | |
28 | This was bad as Tiano did not own the enum. In UEFI 2.0 CreateEventEx was\r | |
29 | added and now it's possible to not voilate the UEFI specification by\r | |
30 | declaring a GUID for the legacy boot event class. This library supports\r | |
31 | the EDK/EFI 1.10 form and EDK II/UEFI 2.0 form and allows common code to\r | |
32 | work both ways.\r | |
33 | \r | |
34 | @param LegacyBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex).\r | |
35 | \r | |
36 | @retval EFI_SUCCESS Event was created.\r | |
37 | @retval Other Event was not created.\r | |
38 | \r | |
39 | **/\r | |
40 | EFI_STATUS\r | |
41 | EFIAPI\r | |
42 | EfiCreateEventLegacyBoot (\r | |
43 | OUT EFI_EVENT *LegacyBootEvent\r | |
44 | )\r | |
45 | {\r | |
46 | return EfiCreateEventLegacyBootEx (\r | |
93b0fbc8 | 47 | TPL_CALLBACK,\r |
eb58a023 | 48 | EfiEventEmptyFunction,\r |
79964ac8 | 49 | NULL,\r |
50 | LegacyBootEvent\r | |
51 | );\r | |
52 | }\r | |
53 | \r | |
54 | /**\r | |
55 | Create an EFI event in the Legacy Boot Event Group and allows\r | |
56 | the caller to specify a notification function.\r | |
57 | \r | |
58 | This function abstracts the creation of the Legacy Boot Event.\r | |
59 | The Framework moved from a proprietary to UEFI 2.0 based mechanism.\r | |
60 | This library abstracts the caller from how this event is created to prevent\r | |
61 | to code form having to change with the version of the specification supported.\r | |
62 | If LegacyBootEvent is NULL, then ASSERT().\r | |
63 | \r | |
64 | @param NotifyTpl The task priority level of the event.\r | |
65 | @param NotifyFunction The notification function to call when the event is signaled.\r | |
66 | @param NotifyContext The content to pass to NotifyFunction when the event is signaled.\r | |
67 | @param LegacyBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex).\r | |
68 | \r | |
69 | @retval EFI_SUCCESS Event was created.\r | |
70 | @retval Other Event was not created.\r | |
71 | \r | |
72 | **/\r | |
73 | EFI_STATUS\r | |
74 | EFIAPI\r | |
75 | EfiCreateEventLegacyBootEx (\r | |
76 | IN EFI_TPL NotifyTpl,\r | |
77 | IN EFI_EVENT_NOTIFY NotifyFunction, OPTIONAL\r | |
78 | IN VOID *NotifyContext, OPTIONAL\r | |
79 | OUT EFI_EVENT *LegacyBootEvent\r | |
80 | )\r | |
81 | {\r | |
82 | EFI_STATUS Status;\r | |
83 | \r | |
84 | ASSERT (LegacyBootEvent != NULL);\r | |
85 | \r | |
86 | if (gST->Hdr.Revision < 0x00020000) {\r | |
87 | //\r | |
88 | // prior to UEFI 2.0 use Tiano extension to EFI\r | |
89 | //\r | |
90 | Status = gBS->CreateEvent (\r | |
39e0ae3b | 91 | EFI_EVENT_SIGNAL_LEGACY_BOOT | EVT_NOTIFY_SIGNAL,\r |
79964ac8 | 92 | NotifyTpl,\r |
93 | NotifyFunction,\r | |
94 | NotifyContext,\r | |
95 | LegacyBootEvent\r | |
96 | );\r | |
97 | } else {\r | |
98 | //\r | |
99 | // For UEFI 2.0 and the future use an Event Group\r | |
100 | //\r | |
101 | Status = gBS->CreateEventEx (\r | |
93b0fbc8 | 102 | EVT_NOTIFY_SIGNAL,\r |
79964ac8 | 103 | NotifyTpl,\r |
104 | NotifyFunction,\r | |
105 | NotifyContext,\r | |
106 | &gEfiEventLegacyBootGuid,\r | |
107 | LegacyBootEvent\r | |
108 | );\r | |
109 | }\r | |
110 | \r | |
111 | return Status;\r | |
112 | }\r | |
113 | \r | |
114 | /**\r | |
115 | Create a Read to Boot Event.\r | |
116 | \r | |
117 | Tiano extended the CreateEvent Type enum to add a ready to boot event type.\r | |
118 | This was bad as Tiano did not own the enum. In UEFI 2.0 CreateEventEx was\r | |
119 | added and now it's possible to not voilate the UEFI specification and use\r | |
120 | the ready to boot event class defined in UEFI 2.0. This library supports\r | |
121 | the EDK/EFI 1.10 form and EDK II/UEFI 2.0 form and allows common code to\r | |
122 | work both ways.\r | |
123 | \r | |
7459094d | 124 | @param ReadyToBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex).\r |
79964ac8 | 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 | |
93b0fbc8 | 137 | TPL_CALLBACK,\r |
eb58a023 | 138 | EfiEventEmptyFunction,\r |
79964ac8 | 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 | |
7459094d | 157 | @param ReadyToBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex).\r |
79964ac8 | 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 | \r | |
174 | ASSERT (ReadyToBootEvent != NULL);\r | |
175 | \r | |
176 | if (gST->Hdr.Revision < 0x00020000) {\r | |
177 | //\r | |
178 | // prior to UEFI 2.0 use Tiano extension to EFI\r | |
179 | //\r | |
180 | Status = gBS->CreateEvent (\r | |
39e0ae3b | 181 | EFI_EVENT_SIGNAL_READY_TO_BOOT | EFI_EVENT_NOTIFY_SIGNAL_ALL,\r |
79964ac8 | 182 | NotifyTpl,\r |
183 | NotifyFunction,\r | |
184 | NotifyContext,\r | |
185 | ReadyToBootEvent\r | |
186 | );\r | |
187 | } else {\r | |
188 | //\r | |
189 | // For UEFI 2.0 and the future use an Event Group\r | |
190 | //\r | |
191 | Status = gBS->CreateEventEx (\r | |
93b0fbc8 | 192 | EVT_NOTIFY_SIGNAL,\r |
79964ac8 | 193 | NotifyTpl,\r |
194 | NotifyFunction,\r | |
195 | NotifyContext,\r | |
196 | &gEfiEventReadyToBootGuid,\r | |
197 | ReadyToBootEvent\r | |
198 | );\r | |
199 | }\r | |
200 | \r | |
201 | return Status;\r | |
202 | }\r | |
203 | \r | |
204 | \r | |
205 | /**\r | |
206 | Signal a Ready to Boot Event.\r | |
207 | \r | |
208 | Create a Ready to Boot Event. Signal it and close it. This causes other\r | |
209 | events of the same event group to be signaled in other modules.\r | |
210 | \r | |
211 | **/\r | |
212 | VOID\r | |
213 | EFIAPI\r | |
214 | EfiSignalEventReadyToBoot (\r | |
215 | VOID\r | |
216 | )\r | |
217 | {\r | |
218 | EFI_STATUS Status;\r | |
219 | EFI_EVENT ReadyToBootEvent;\r | |
220 | \r | |
221 | Status = EfiCreateEventReadyToBoot (&ReadyToBootEvent);\r | |
222 | if (!EFI_ERROR (Status)) {\r | |
223 | gBS->SignalEvent (ReadyToBootEvent);\r | |
224 | gBS->CloseEvent (ReadyToBootEvent);\r | |
225 | }\r | |
226 | }\r | |
227 | \r | |
228 | /**\r | |
229 | Signal a Legacy Boot Event.\r | |
230 | \r | |
231 | Create a legacy Boot Event. Signal it and close it. This causes other\r | |
232 | events of the same event group to be signaled in other modules.\r | |
233 | \r | |
234 | **/\r | |
235 | VOID\r | |
236 | EFIAPI\r | |
237 | EfiSignalEventLegacyBoot (\r | |
238 | VOID\r | |
239 | )\r | |
240 | {\r | |
241 | EFI_STATUS Status;\r | |
242 | EFI_EVENT LegacyBootEvent;\r | |
243 | \r | |
244 | Status = EfiCreateEventLegacyBoot (&LegacyBootEvent);\r | |
245 | if (!EFI_ERROR (Status)) {\r | |
246 | gBS->SignalEvent (LegacyBootEvent);\r | |
247 | gBS->CloseEvent (LegacyBootEvent);\r | |
248 | }\r | |
249 | }\r | |
250 | \r | |
251 | \r | |
252 | /**\r | |
253 | Check to see if the Firmware Volume (FV) Media Device Path is valid\r | |
254 | \r | |
255 | Tiano extended the EFI 1.10 device path nodes. Tiano does not own this enum\r | |
256 | so as we move to UEFI 2.0 support we must use a mechanism that conforms with\r | |
257 | the UEFI 2.0 specification to define the FV device path. An UEFI GUIDed\r | |
258 | device path is defined for Tiano extensions of device path. If the code\r | |
259 | is compiled to conform with the UEFI 2.0 specification use the new device path\r | |
260 | else use the old form for backwards compatability. The return value to this\r | |
261 | function points to a location in FvDevicePathNode and it does not allocate\r | |
262 | new memory for the GUID pointer that is returned.\r | |
263 | \r | |
264 | @param FvDevicePathNode Pointer to FV device path to check.\r | |
265 | \r | |
266 | @retval NULL FvDevicePathNode is not valid.\r | |
267 | @retval Other FvDevicePathNode is valid and pointer to NameGuid was returned.\r | |
268 | \r | |
269 | **/\r | |
270 | EFI_GUID *\r | |
271 | EFIAPI\r | |
272 | EfiGetNameGuidFromFwVolDevicePathNode (\r | |
273 | IN CONST MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvDevicePathNode\r | |
274 | )\r | |
275 | {\r | |
276 | ASSERT (FvDevicePathNode != NULL);\r | |
277 | \r | |
278 | //\r | |
1c2f052d | 279 | // EFI Specification extension on Media Device Path. MEDIA_FW_VOL_FILEPATH_DEVICE_PATH is adopted by UEFI later and added in UEFI2.10.\r |
84dcd70d LG |
280 | // In EdkCompatibility Package, we only support MEDIA_FW_VOL_FILEPATH_DEVICE_PATH that complies with\r |
281 | // EFI 1.10 and UEFI 2.10.\r | |
79964ac8 | 282 | //\r |
84dcd70d LG |
283 | if (DevicePathType (&FvDevicePathNode->Header) == MEDIA_DEVICE_PATH &&\r |
284 | DevicePathSubType (&FvDevicePathNode->Header) == MEDIA_PIWG_FW_FILE_DP) {\r | |
285 | return (EFI_GUID *) &FvDevicePathNode->FvFileName;\r | |
79964ac8 | 286 | }\r |
287 | \r | |
288 | return NULL;\r | |
289 | }\r | |
290 | \r | |
291 | \r | |
292 | /**\r | |
293 | Initialize a Firmware Volume (FV) Media Device Path node.\r | |
294 | \r | |
295 | Tiano extended the EFI 1.10 device path nodes. Tiano does not own this enum\r | |
296 | so as we move to UEFI 2.0 support we must use a mechanism that conforms with\r | |
297 | the UEFI 2.0 specification to define the FV device path. An UEFI GUIDed\r | |
298 | device path is defined for Tiano extensions of device path. If the code\r | |
299 | is compiled to conform with the UEFI 2.0 specification use the new device path\r | |
300 | else use the old form for backwards compatability.\r | |
301 | \r | |
302 | @param FvDevicePathNode Pointer to a FV device path node to initialize\r | |
303 | @param NameGuid FV file name to use in FvDevicePathNode\r | |
304 | \r | |
305 | **/\r | |
306 | VOID\r | |
307 | EFIAPI\r | |
308 | EfiInitializeFwVolDevicepathNode (\r | |
309 | IN OUT MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvDevicePathNode,\r | |
3d6f81d7 | 310 | IN CONST EFI_GUID *NameGuid\r |
79964ac8 | 311 | )\r |
312 | {\r | |
313 | ASSERT (FvDevicePathNode != NULL);\r | |
314 | ASSERT (NameGuid != NULL);\r | |
315 | \r | |
79964ac8 | 316 | //\r |
1c2f052d | 317 | // EFI Specification extension on Media Device Path. MEDIA_FW_VOL_FILEPATH_DEVICE_PATH is adopted by UEFI later and added in UEFI2.10.\r |
84dcd70d LG |
318 | // In EdkCompatibility Package, we only support MEDIA_FW_VOL_FILEPATH_DEVICE_PATH that complies with\r |
319 | // EFI 1.10 and UEFI 2.10.\r | |
79964ac8 | 320 | //\r |
84dcd70d LG |
321 | FvDevicePathNode->Header.Type = MEDIA_DEVICE_PATH;\r |
322 | FvDevicePathNode->Header.SubType = MEDIA_PIWG_FW_FILE_DP;\r | |
323 | SetDevicePathNodeLength (&FvDevicePathNode->Header, sizeof (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH));\r | |
1c2f052d | 324 | \r |
84dcd70d | 325 | CopyGuid (&FvDevicePathNode->FvFileName, NameGuid);\r |
79964ac8 | 326 | }\r |
327 | \r |