]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/UefiLib/UefiNotTiano.c
Make MDE package pass intel IPF compiler with /W4 /WX switched on.
[mirror_edk2.git] / MdePkg / Library / UefiLib / UefiNotTiano.c
CommitLineData
878ddf1f 1/** @file\r
2 Library functions that abstract areas of conflict between Tiano an UEFI 2.0.\r
3\r
4 Help Port Framework/Tinao code that has conflicts with UEFI 2.0 by hiding the\r
5 oldconflicts with library functions and supporting implementations of the old \r
a537f148 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
878ddf1f 8\r
9Copyright (c) 2006, Intel Corporation<BR>\r
10All rights reserved. This program and the accompanying materials\r
11are licensed and made available under the terms and conditions of the BSD License\r
12which accompanies this distribution. The full text of the license may be found at\r
13http://opensource.org/licenses/bsd-license.php\r
14\r
15THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
16WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
17\r
18**/\r
19\r
a537f148 20\r
9a462b41 21/**\r
22 An empty function to pass error checking of CreateEventEx (). \r
23 \r
511710d6 24 This empty function ensures that EFI_EVENT_NOTIFY_SIGNAL_ALL is error\r
25 checked correctly since it is now mapped into CreateEventEx() in UEFI 2.0.\r
9a462b41 26 \r
27**/\r
58251024 28STATIC\r
511710d6 29VOID\r
30EFIAPI\r
31InternalEmptyFuntion (\r
32 IN EFI_EVENT Event,\r
33 IN VOID *Context\r
34 )\r
35{\r
36 return;\r
9a462b41 37}\r
878ddf1f 38\r
39/**\r
40 Create a Legacy Boot Event. \r
41 \r
42 Tiano extended the CreateEvent Type enum to add a legacy boot event type. \r
43 This was bad as Tiano did not own the enum. In UEFI 2.0 CreateEventEx was\r
44 added and now it's possible to not voilate the UEFI specification by \r
45 declaring a GUID for the legacy boot event class. This library supports\r
a537f148 46 the EDK/EFI 1.10 form and EDK II/UEFI 2.0 form and allows common code to \r
878ddf1f 47 work both ways.\r
48\r
49 @param LegacyBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex).\r
50\r
51 @retval EFI_SUCCESS Event was created.\r
52 @retval Other Event was not created.\r
53\r
54**/\r
55EFI_STATUS\r
56EFIAPI\r
57EfiCreateEventLegacyBoot (\r
abea19db 58 OUT EFI_EVENT *LegacyBootEvent\r
878ddf1f 59 )\r
9a462b41 60{\r
61 return EfiCreateEventLegacyBootEx (\r
62 EFI_TPL_CALLBACK,\r
63 InternalEmptyFuntion,\r
64 NULL,\r
65 LegacyBootEvent\r
66 );\r
67}\r
68\r
69/**\r
70 Create an EFI event in the Legacy Boot Event Group and allows\r
71 the caller to specify a notification function. \r
72 \r
73 This function abstracts the creation of the Legacy Boot Event.\r
74 The Framework moved from a proprietary to UEFI 2.0 based mechanism.\r
75 This library abstracts the caller from how this event is created to prevent\r
76 to code form having to change with the version of the specification supported.\r
77 If LegacyBootEvent is NULL, then ASSERT().\r
78\r
79 @param NotifyTpl The task priority level of the event.\r
80 @param NotifyFunction The notification function to call when the event is signaled.\r
81 @param NotifyContext The content to pass to NotifyFunction when the event is signaled.\r
82 @param LegacyBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex).\r
83\r
84 @retval EFI_SUCCESS Event was created.\r
85 @retval Other Event was not created.\r
86\r
87**/\r
88EFI_STATUS\r
89EFIAPI\r
90EfiCreateEventLegacyBootEx (\r
91 IN EFI_TPL NotifyTpl,\r
92 IN EFI_EVENT_NOTIFY NotifyFunction, OPTIONAL\r
93 IN VOID *NotifyContext, OPTIONAL\r
94 OUT EFI_EVENT *LegacyBootEvent\r
95 )\r
878ddf1f 96{\r
97 EFI_STATUS Status;\r
98\r
99 ASSERT (LegacyBootEvent != NULL);\r
100\r
a537f148 101#if ((EDK_RELEASE_VERSION != 0) && (EFI_SPECIFICATION_VERSION < 0x00020000))\r
878ddf1f 102 //\r
103 // prior to UEFI 2.0 use Tiano extension to EFI\r
104 //\r
105 Status = gBS->CreateEvent (\r
106 EFI_EVENT_SIGNAL_LEGACY_BOOT | EFI_EVENT_NOTIFY_SIGNAL_ALL,\r
9a462b41 107 NotifyTpl,\r
108 NotifyFunction,\r
109 NotifyContext,\r
878ddf1f 110 LegacyBootEvent\r
111 );\r
a537f148 112#elif (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
878ddf1f 113 //\r
114 // For UEFI 2.0 and the future use an Event Group\r
115 //\r
116 Status = gBS->CreateEventEx (\r
117 EVENT_NOTIFY_SIGNAL,\r
9a462b41 118 NotifyTpl,\r
119 NotifyFunction,\r
120 NotifyContext,\r
878ddf1f 121 &gEfiEventLegacyBootGuid,\r
122 LegacyBootEvent\r
123 );\r
a537f148 124#else\r
125 //\r
126 // For EFI 1.10 with no Tiano extensions return unsupported\r
127 //\r
128 Status = EFI_UNSUPORTED;\r
878ddf1f 129#endif\r
9a462b41 130\r
878ddf1f 131 return Status;\r
132}\r
133\r
878ddf1f 134/**\r
135 Create a Read to Boot Event. \r
136 \r
137 Tiano extended the CreateEvent Type enum to add a ready to boot event type. \r
138 This was bad as Tiano did not own the enum. In UEFI 2.0 CreateEventEx was\r
139 added and now it's possible to not voilate the UEFI specification and use \r
140 the ready to boot event class defined in UEFI 2.0. This library supports\r
a537f148 141 the EDK/EFI 1.10 form and EDK II/UEFI 2.0 form and allows common code to \r
878ddf1f 142 work both ways.\r
143\r
144 @param LegacyBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex).\r
145\r
146 @retval EFI_SUCCESS Event was created.\r
147 @retval Other Event was not created.\r
148\r
149**/\r
150EFI_STATUS\r
151EFIAPI\r
152EfiCreateEventReadyToBoot (\r
abea19db 153 OUT EFI_EVENT *ReadyToBootEvent\r
878ddf1f 154 )\r
9a462b41 155{\r
156 return EfiCreateEventReadyToBootEx (\r
157 EFI_TPL_CALLBACK,\r
158 InternalEmptyFuntion,\r
159 NULL,\r
160 ReadyToBootEvent\r
161 );\r
162}\r
163\r
164/**\r
165 Create an EFI event in the Ready To Boot Event Group and allows\r
166 the caller to specify a notification function. \r
167 \r
168 This function abstracts the creation of the Ready to Boot Event.\r
169 The Framework moved from a proprietary to UEFI 2.0 based mechanism.\r
170 This library abstracts the caller from how this event is created to prevent\r
171 to code form having to change with the version of the specification supported.\r
172 If ReadyToBootEvent is NULL, then ASSERT().\r
173\r
174 @param NotifyTpl The task priority level of the event.\r
175 @param NotifyFunction The notification function to call when the event is signaled.\r
176 @param NotifyContext The content to pass to NotifyFunction when the event is signaled.\r
177 @param LegacyBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex).\r
178\r
179 @retval EFI_SUCCESS Event was created.\r
180 @retval Other Event was not created.\r
181\r
182**/\r
183EFI_STATUS\r
184EFIAPI\r
185EfiCreateEventReadyToBootEx (\r
186 IN EFI_TPL NotifyTpl,\r
187 IN EFI_EVENT_NOTIFY NotifyFunction, OPTIONAL\r
188 IN VOID *NotifyContext, OPTIONAL\r
189 OUT EFI_EVENT *ReadyToBootEvent\r
190 )\r
878ddf1f 191{\r
192 EFI_STATUS Status;\r
193\r
194 ASSERT (ReadyToBootEvent != NULL);\r
195\r
a537f148 196#if ((EDK_RELEASE_VERSION != 0) && (EFI_SPECIFICATION_VERSION < 0x00020000))\r
878ddf1f 197 //\r
198 // prior to UEFI 2.0 use Tiano extension to EFI\r
199 //\r
200 Status = gBS->CreateEvent (\r
201 EFI_EVENT_SIGNAL_READY_TO_BOOT | EFI_EVENT_NOTIFY_SIGNAL_ALL,\r
9a462b41 202 NotifyTpl,\r
203 NotifyFunction,\r
204 NotifyContext,\r
878ddf1f 205 ReadyToBootEvent\r
206 );\r
a537f148 207#elif (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
878ddf1f 208 //\r
209 // For UEFI 2.0 and the future use an Event Group\r
210 //\r
211 Status = gBS->CreateEventEx (\r
212 EVENT_NOTIFY_SIGNAL,\r
9a462b41 213 NotifyTpl,\r
214 NotifyFunction,\r
215 NotifyContext,\r
878ddf1f 216 &gEfiEventReadyToBootGuid,\r
217 ReadyToBootEvent\r
218 );\r
a537f148 219#else\r
220 //\r
221 // For EFI 1.10 with no Tiano extensions return unsupported\r
222 //\r
223 Status = EFI_UNSUPORTED;\r
878ddf1f 224#endif\r
225\r
226 return Status;\r
227}\r
228\r
229\r
230/**\r
231 Signal a Ready to Boot Event. \r
232 \r
233 Create a Ready to Boot Event. Signal it and close it. This causes other \r
234 events of the same event group to be signaled in other modules. \r
235\r
236**/\r
237VOID\r
238EFIAPI\r
239EfiSignalEventReadyToBoot (\r
240 VOID\r
241 )\r
242{\r
243 EFI_STATUS Status;\r
244 EFI_EVENT ReadyToBootEvent;\r
245\r
246 Status = EfiCreateEventReadyToBoot (&ReadyToBootEvent);\r
247 if (!EFI_ERROR (Status)) {\r
248 gBS->SignalEvent (ReadyToBootEvent);\r
249 gBS->CloseEvent (ReadyToBootEvent);\r
250 }\r
251}\r
252\r
253/**\r
254 Signal a Legacy Boot Event. \r
255 \r
256 Create a legacy Boot Event. Signal it and close it. This causes other \r
257 events of the same event group to be signaled in other modules. \r
258\r
259**/\r
260VOID\r
261EFIAPI\r
262EfiSignalEventLegacyBoot (\r
263 VOID\r
264 )\r
265{\r
266 EFI_STATUS Status;\r
267 EFI_EVENT LegacyBootEvent;\r
268\r
269 Status = EfiCreateEventLegacyBoot (&LegacyBootEvent);\r
270 if (!EFI_ERROR (Status)) {\r
271 gBS->SignalEvent (LegacyBootEvent);\r
272 gBS->CloseEvent (LegacyBootEvent);\r
273 }\r
274}\r
275\r
276\r
277/**\r
278 Check to see if the Firmware Volume (FV) Media Device Path is valid \r
279 \r
280 Tiano extended the EFI 1.10 device path nodes. Tiano does not own this enum\r
281 so as we move to UEFI 2.0 support we must use a mechanism that conforms with\r
282 the UEFI 2.0 specification to define the FV device path. An UEFI GUIDed \r
a537f148 283 device path is defined for Tiano extensions of device path. If the code \r
878ddf1f 284 is compiled to conform with the UEFI 2.0 specification use the new device path\r
285 else use the old form for backwards compatability. The return value to this\r
286 function points to a location in FvDevicePathNode and it does not allocate\r
287 new memory for the GUID pointer that is returned.\r
288\r
289 @param FvDevicePathNode Pointer to FV device path to check.\r
290\r
291 @retval NULL FvDevicePathNode is not valid.\r
292 @retval Other FvDevicePathNode is valid and pointer to NameGuid was returned.\r
293\r
294**/\r
295EFI_GUID *\r
296EFIAPI\r
297EfiGetNameGuidFromFwVolDevicePathNode (\r
abea19db 298 IN CONST MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvDevicePathNode\r
878ddf1f 299 )\r
300{\r
301 ASSERT (FvDevicePathNode != NULL);\r
302\r
a537f148 303#if ((EDK_RELEASE_VERSION != 0) && (EFI_SPECIFICATION_VERSION < 0x00020000))\r
878ddf1f 304 //\r
305 // Use old Device Path that conflicts with UEFI\r
306 //\r
307 if (DevicePathType (&FvDevicePathNode->Header) == MEDIA_DEVICE_PATH ||\r
308 DevicePathSubType (&FvDevicePathNode->Header) == MEDIA_FV_FILEPATH_DP) {\r
abea19db 309 return (EFI_GUID *) &FvDevicePathNode->NameGuid;\r
878ddf1f 310 }\r
311\r
a537f148 312#elif ((EDK_RELEASE_VERSION != 0) && (EFI_SPECIFICATION_VERSION >= 0x00020000))\r
878ddf1f 313 //\r
314 // Use the new Device path that does not conflict with the UEFI\r
315 //\r
a537f148 316 if (FvDevicePathNode->Tiano.Header.Type == MEDIA_DEVICE_PATH ||\r
317 FvDevicePathNode->Tiano.Header.SubType == MEDIA_VENDOR_DP) {\r
318 if (CompareGuid (&gEfiFrameworkDevicePathGuid, &FvDevicePathNode->Tiano.TianoSpecificDevicePath)) {\r
319 if (FvDevicePathNode->Tiano.Type == TIANO_MEDIA_FW_VOL_FILEPATH_DEVICE_PATH_TYPE) {\r
abea19db 320 return (EFI_GUID *) &FvDevicePathNode->NameGuid;\r
878ddf1f 321 }\r
322 }\r
323 }\r
324#endif \r
325 return NULL;\r
326}\r
327\r
328\r
329/**\r
330 Initialize a Firmware Volume (FV) Media Device Path node.\r
331 \r
332 Tiano extended the EFI 1.10 device path nodes. Tiano does not own this enum\r
333 so as we move to UEFI 2.0 support we must use a mechanism that conforms with\r
334 the UEFI 2.0 specification to define the FV device path. An UEFI GUIDed \r
a537f148 335 device path is defined for Tiano extensions of device path. If the code \r
878ddf1f 336 is compiled to conform with the UEFI 2.0 specification use the new device path\r
337 else use the old form for backwards compatability.\r
338\r
abea19db 339 @param FvDevicePathNode Pointer to a FV device path node to initialize\r
340 @param NameGuid FV file name to use in FvDevicePathNode\r
878ddf1f 341\r
342**/\r
343VOID\r
344EFIAPI\r
345EfiInitializeFwVolDevicepathNode (\r
abea19db 346 IN OUT MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvDevicePathNode,\r
347 IN CONST EFI_GUID *NameGuid\r
878ddf1f 348 )\r
349{\r
350 ASSERT (FvDevicePathNode != NULL);\r
351 ASSERT (NameGuid != NULL);\r
352\r
353#if (EFI_SPECIFICATION_VERSION < 0x00020000) \r
354 //\r
355 // Use old Device Path that conflicts with UEFI\r
356 //\r
357 FvDevicePathNode->Header.Type = MEDIA_DEVICE_PATH;\r
358 FvDevicePathNode->Header.SubType = MEDIA_FV_FILEPATH_DP;\r
359 SetDevicePathNodeLength (&FvDevicePathNode->Header, sizeof (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH));\r
360 \r
361#else\r
362 //\r
363 // Use the new Device path that does not conflict with the UEFI\r
364 //\r
a537f148 365 FvDevicePathNode->Tiano.Header.Type = MEDIA_DEVICE_PATH;\r
366 FvDevicePathNode->Tiano.Header.SubType = MEDIA_VENDOR_DP;\r
367 SetDevicePathNodeLength (&FvDevicePathNode->Tiano.Header, sizeof (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH));\r
878ddf1f 368\r
369 //\r
a537f148 370 // Add the GUID for generic Tiano device paths\r
878ddf1f 371 //\r
a537f148 372 CopyGuid (&FvDevicePathNode->Tiano.TianoSpecificDevicePath, &gEfiFrameworkDevicePathGuid);\r
878ddf1f 373\r
374 //\r
a537f148 375 // Add in the FW Vol File Path Tiano defined information\r
878ddf1f 376 //\r
a537f148 377 FvDevicePathNode->Tiano.Type = TIANO_MEDIA_FW_VOL_FILEPATH_DEVICE_PATH_TYPE;\r
878ddf1f 378\r
379#endif\r
380\r
381 CopyGuid (&FvDevicePathNode->NameGuid, NameGuid);\r
382\r
383}\r
384\r