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