]>
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 |
22a69a5e | 10 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
79964ac8 | 11 | \r |
12 | **/\r | |
13 | \r | |
bf428cb3 | 14 | \r |
15 | \r | |
16 | #include "UefiLibInternal.h"\r | |
79964ac8 | 17 | \r |
79964ac8 | 18 | /**\r |
19 | Create a Legacy Boot Event.\r | |
20 | \r | |
21 | Tiano extended the CreateEvent Type enum to add a legacy boot event type.\r | |
22 | This was bad as Tiano did not own the enum. In UEFI 2.0 CreateEventEx was\r | |
23 | added and now it's possible to not voilate the UEFI specification by\r | |
24 | declaring a GUID for the legacy boot event class. This library supports\r | |
25 | the EDK/EFI 1.10 form and EDK II/UEFI 2.0 form and allows common code to\r | |
26 | work both ways.\r | |
27 | \r | |
28 | @param LegacyBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex).\r | |
29 | \r | |
30 | @retval EFI_SUCCESS Event was created.\r | |
31 | @retval Other Event was not created.\r | |
32 | \r | |
33 | **/\r | |
34 | EFI_STATUS\r | |
35 | EFIAPI\r | |
36 | EfiCreateEventLegacyBoot (\r | |
37 | OUT EFI_EVENT *LegacyBootEvent\r | |
38 | )\r | |
39 | {\r | |
40 | return EfiCreateEventLegacyBootEx (\r | |
93b0fbc8 | 41 | TPL_CALLBACK,\r |
eb58a023 | 42 | EfiEventEmptyFunction,\r |
79964ac8 | 43 | NULL,\r |
44 | LegacyBootEvent\r | |
45 | );\r | |
46 | }\r | |
47 | \r | |
48 | /**\r | |
49 | Create an EFI event in the Legacy Boot Event Group and allows\r | |
50 | the caller to specify a notification function.\r | |
51 | \r | |
52 | This function abstracts the creation of the Legacy Boot Event.\r | |
53 | The Framework moved from a proprietary to UEFI 2.0 based mechanism.\r | |
54 | This library abstracts the caller from how this event is created to prevent\r | |
55 | to code form having to change with the version of the specification supported.\r | |
56 | If LegacyBootEvent is NULL, then ASSERT().\r | |
57 | \r | |
58 | @param NotifyTpl The task priority level of the event.\r | |
59 | @param NotifyFunction The notification function to call when the event is signaled.\r | |
60 | @param NotifyContext The content to pass to NotifyFunction when the event is signaled.\r | |
61 | @param LegacyBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex).\r | |
62 | \r | |
63 | @retval EFI_SUCCESS Event was created.\r | |
64 | @retval Other Event was not created.\r | |
65 | \r | |
66 | **/\r | |
67 | EFI_STATUS\r | |
68 | EFIAPI\r | |
69 | EfiCreateEventLegacyBootEx (\r | |
70 | IN EFI_TPL NotifyTpl,\r | |
71 | IN EFI_EVENT_NOTIFY NotifyFunction, OPTIONAL\r | |
72 | IN VOID *NotifyContext, OPTIONAL\r | |
73 | OUT EFI_EVENT *LegacyBootEvent\r | |
74 | )\r | |
75 | {\r | |
76 | EFI_STATUS Status;\r | |
77 | \r | |
78 | ASSERT (LegacyBootEvent != NULL);\r | |
79 | \r | |
80 | if (gST->Hdr.Revision < 0x00020000) {\r | |
81 | //\r | |
82 | // prior to UEFI 2.0 use Tiano extension to EFI\r | |
83 | //\r | |
84 | Status = gBS->CreateEvent (\r | |
39e0ae3b | 85 | EFI_EVENT_SIGNAL_LEGACY_BOOT | EVT_NOTIFY_SIGNAL,\r |
79964ac8 | 86 | NotifyTpl,\r |
87 | NotifyFunction,\r | |
88 | NotifyContext,\r | |
89 | LegacyBootEvent\r | |
90 | );\r | |
91 | } else {\r | |
92 | //\r | |
93 | // For UEFI 2.0 and the future use an Event Group\r | |
94 | //\r | |
95 | Status = gBS->CreateEventEx (\r | |
93b0fbc8 | 96 | EVT_NOTIFY_SIGNAL,\r |
79964ac8 | 97 | NotifyTpl,\r |
98 | NotifyFunction,\r | |
99 | NotifyContext,\r | |
100 | &gEfiEventLegacyBootGuid,\r | |
101 | LegacyBootEvent\r | |
102 | );\r | |
103 | }\r | |
104 | \r | |
105 | return Status;\r | |
106 | }\r | |
107 | \r | |
108 | /**\r | |
109 | Create a Read to Boot Event.\r | |
110 | \r | |
111 | Tiano extended the CreateEvent Type enum to add a ready to boot event type.\r | |
112 | This was bad as Tiano did not own the enum. In UEFI 2.0 CreateEventEx was\r | |
113 | added and now it's possible to not voilate the UEFI specification and use\r | |
114 | the ready to boot event class defined in UEFI 2.0. This library supports\r | |
115 | the EDK/EFI 1.10 form and EDK II/UEFI 2.0 form and allows common code to\r | |
116 | work both ways.\r | |
117 | \r | |
7459094d | 118 | @param ReadyToBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex).\r |
79964ac8 | 119 | \r |
120 | @retval EFI_SUCCESS Event was created.\r | |
121 | @retval Other Event was not created.\r | |
122 | \r | |
123 | **/\r | |
124 | EFI_STATUS\r | |
125 | EFIAPI\r | |
126 | EfiCreateEventReadyToBoot (\r | |
127 | OUT EFI_EVENT *ReadyToBootEvent\r | |
128 | )\r | |
129 | {\r | |
130 | return EfiCreateEventReadyToBootEx (\r | |
93b0fbc8 | 131 | TPL_CALLBACK,\r |
eb58a023 | 132 | EfiEventEmptyFunction,\r |
79964ac8 | 133 | NULL,\r |
134 | ReadyToBootEvent\r | |
135 | );\r | |
136 | }\r | |
137 | \r | |
138 | /**\r | |
139 | Create an EFI event in the Ready To Boot Event Group and allows\r | |
140 | the caller to specify a notification function.\r | |
141 | \r | |
142 | This function abstracts the creation of the Ready to Boot Event.\r | |
143 | The Framework moved from a proprietary to UEFI 2.0 based mechanism.\r | |
144 | This library abstracts the caller from how this event is created to prevent\r | |
145 | to code form having to change with the version of the specification supported.\r | |
146 | If ReadyToBootEvent is NULL, then ASSERT().\r | |
147 | \r | |
148 | @param NotifyTpl The task priority level of the event.\r | |
149 | @param NotifyFunction The notification function to call when the event is signaled.\r | |
150 | @param NotifyContext The content to pass to NotifyFunction when the event is signaled.\r | |
7459094d | 151 | @param ReadyToBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex).\r |
79964ac8 | 152 | \r |
153 | @retval EFI_SUCCESS Event was created.\r | |
154 | @retval Other Event was not created.\r | |
155 | \r | |
156 | **/\r | |
157 | EFI_STATUS\r | |
158 | EFIAPI\r | |
159 | EfiCreateEventReadyToBootEx (\r | |
160 | IN EFI_TPL NotifyTpl,\r | |
161 | IN EFI_EVENT_NOTIFY NotifyFunction, OPTIONAL\r | |
162 | IN VOID *NotifyContext, OPTIONAL\r | |
163 | OUT EFI_EVENT *ReadyToBootEvent\r | |
164 | )\r | |
165 | {\r | |
166 | EFI_STATUS Status;\r | |
167 | \r | |
168 | ASSERT (ReadyToBootEvent != NULL);\r | |
169 | \r | |
170 | if (gST->Hdr.Revision < 0x00020000) {\r | |
171 | //\r | |
172 | // prior to UEFI 2.0 use Tiano extension to EFI\r | |
173 | //\r | |
174 | Status = gBS->CreateEvent (\r | |
39e0ae3b | 175 | EFI_EVENT_SIGNAL_READY_TO_BOOT | EFI_EVENT_NOTIFY_SIGNAL_ALL,\r |
79964ac8 | 176 | NotifyTpl,\r |
177 | NotifyFunction,\r | |
178 | NotifyContext,\r | |
179 | ReadyToBootEvent\r | |
180 | );\r | |
181 | } else {\r | |
182 | //\r | |
183 | // For UEFI 2.0 and the future use an Event Group\r | |
184 | //\r | |
185 | Status = gBS->CreateEventEx (\r | |
93b0fbc8 | 186 | EVT_NOTIFY_SIGNAL,\r |
79964ac8 | 187 | NotifyTpl,\r |
188 | NotifyFunction,\r | |
189 | NotifyContext,\r | |
190 | &gEfiEventReadyToBootGuid,\r | |
191 | ReadyToBootEvent\r | |
192 | );\r | |
193 | }\r | |
194 | \r | |
195 | return Status;\r | |
196 | }\r | |
197 | \r | |
198 | \r | |
199 | /**\r | |
200 | Signal a Ready to Boot Event.\r | |
201 | \r | |
202 | Create a Ready to Boot Event. Signal it and close it. This causes other\r | |
203 | events of the same event group to be signaled in other modules.\r | |
204 | \r | |
205 | **/\r | |
206 | VOID\r | |
207 | EFIAPI\r | |
208 | EfiSignalEventReadyToBoot (\r | |
209 | VOID\r | |
210 | )\r | |
211 | {\r | |
212 | EFI_STATUS Status;\r | |
213 | EFI_EVENT ReadyToBootEvent;\r | |
214 | \r | |
215 | Status = EfiCreateEventReadyToBoot (&ReadyToBootEvent);\r | |
216 | if (!EFI_ERROR (Status)) {\r | |
217 | gBS->SignalEvent (ReadyToBootEvent);\r | |
218 | gBS->CloseEvent (ReadyToBootEvent);\r | |
219 | }\r | |
220 | }\r | |
221 | \r | |
222 | /**\r | |
223 | Signal a Legacy Boot Event.\r | |
224 | \r | |
225 | Create a legacy Boot Event. Signal it and close it. This causes other\r | |
226 | events of the same event group to be signaled in other modules.\r | |
227 | \r | |
228 | **/\r | |
229 | VOID\r | |
230 | EFIAPI\r | |
231 | EfiSignalEventLegacyBoot (\r | |
232 | VOID\r | |
233 | )\r | |
234 | {\r | |
235 | EFI_STATUS Status;\r | |
236 | EFI_EVENT LegacyBootEvent;\r | |
237 | \r | |
238 | Status = EfiCreateEventLegacyBoot (&LegacyBootEvent);\r | |
239 | if (!EFI_ERROR (Status)) {\r | |
240 | gBS->SignalEvent (LegacyBootEvent);\r | |
241 | gBS->CloseEvent (LegacyBootEvent);\r | |
242 | }\r | |
243 | }\r | |
244 | \r | |
245 | \r | |
246 | /**\r | |
247 | Check to see if the Firmware Volume (FV) Media Device Path is valid\r | |
248 | \r | |
249 | Tiano extended the EFI 1.10 device path nodes. Tiano does not own this enum\r | |
250 | so as we move to UEFI 2.0 support we must use a mechanism that conforms with\r | |
251 | the UEFI 2.0 specification to define the FV device path. An UEFI GUIDed\r | |
252 | device path is defined for Tiano extensions of device path. If the code\r | |
253 | is compiled to conform with the UEFI 2.0 specification use the new device path\r | |
254 | else use the old form for backwards compatability. The return value to this\r | |
255 | function points to a location in FvDevicePathNode and it does not allocate\r | |
256 | new memory for the GUID pointer that is returned.\r | |
257 | \r | |
258 | @param FvDevicePathNode Pointer to FV device path to check.\r | |
259 | \r | |
260 | @retval NULL FvDevicePathNode is not valid.\r | |
261 | @retval Other FvDevicePathNode is valid and pointer to NameGuid was returned.\r | |
262 | \r | |
263 | **/\r | |
264 | EFI_GUID *\r | |
265 | EFIAPI\r | |
266 | EfiGetNameGuidFromFwVolDevicePathNode (\r | |
267 | IN CONST MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvDevicePathNode\r | |
268 | )\r | |
269 | {\r | |
270 | ASSERT (FvDevicePathNode != NULL);\r | |
271 | \r | |
272 | //\r | |
1c2f052d | 273 | // 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 |
274 | // In EdkCompatibility Package, we only support MEDIA_FW_VOL_FILEPATH_DEVICE_PATH that complies with\r |
275 | // EFI 1.10 and UEFI 2.10.\r | |
79964ac8 | 276 | //\r |
84dcd70d LG |
277 | if (DevicePathType (&FvDevicePathNode->Header) == MEDIA_DEVICE_PATH &&\r |
278 | DevicePathSubType (&FvDevicePathNode->Header) == MEDIA_PIWG_FW_FILE_DP) {\r | |
279 | return (EFI_GUID *) &FvDevicePathNode->FvFileName;\r | |
79964ac8 | 280 | }\r |
281 | \r | |
282 | return NULL;\r | |
283 | }\r | |
284 | \r | |
285 | \r | |
286 | /**\r | |
287 | Initialize a Firmware Volume (FV) Media Device Path node.\r | |
288 | \r | |
289 | Tiano extended the EFI 1.10 device path nodes. Tiano does not own this enum\r | |
290 | so as we move to UEFI 2.0 support we must use a mechanism that conforms with\r | |
291 | the UEFI 2.0 specification to define the FV device path. An UEFI GUIDed\r | |
292 | device path is defined for Tiano extensions of device path. If the code\r | |
293 | is compiled to conform with the UEFI 2.0 specification use the new device path\r | |
294 | else use the old form for backwards compatability.\r | |
295 | \r | |
296 | @param FvDevicePathNode Pointer to a FV device path node to initialize\r | |
297 | @param NameGuid FV file name to use in FvDevicePathNode\r | |
298 | \r | |
299 | **/\r | |
300 | VOID\r | |
301 | EFIAPI\r | |
302 | EfiInitializeFwVolDevicepathNode (\r | |
303 | IN OUT MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvDevicePathNode,\r | |
3d6f81d7 | 304 | IN CONST EFI_GUID *NameGuid\r |
79964ac8 | 305 | )\r |
306 | {\r | |
307 | ASSERT (FvDevicePathNode != NULL);\r | |
308 | ASSERT (NameGuid != NULL);\r | |
309 | \r | |
79964ac8 | 310 | //\r |
1c2f052d | 311 | // 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 |
312 | // In EdkCompatibility Package, we only support MEDIA_FW_VOL_FILEPATH_DEVICE_PATH that complies with\r |
313 | // EFI 1.10 and UEFI 2.10.\r | |
79964ac8 | 314 | //\r |
84dcd70d LG |
315 | FvDevicePathNode->Header.Type = MEDIA_DEVICE_PATH;\r |
316 | FvDevicePathNode->Header.SubType = MEDIA_PIWG_FW_FILE_DP;\r | |
317 | SetDevicePathNodeLength (&FvDevicePathNode->Header, sizeof (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH));\r | |
1c2f052d | 318 | \r |
84dcd70d | 319 | CopyGuid (&FvDevicePathNode->FvFileName, NameGuid);\r |
79964ac8 | 320 | }\r |
321 | \r |