]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/UefiLib/UefiNotTiano.c
33a14522a9edc933cc1b073ab3367240447fae2c
[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 - 2007, 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 STATIC
29 VOID
30 EFIAPI
31 InternalEmptyFuntion (
32 IN EFI_EVENT Event,
33 IN VOID *Context
34 )
35 {
36 return;
37 }
38
39 /**
40 Create a Legacy Boot Event.
41
42 Tiano extended the CreateEvent Type enum to add a legacy boot event type.
43 This was bad as Tiano did not own the enum. In UEFI 2.0 CreateEventEx was
44 added and now it's possible to not voilate the UEFI specification by
45 declaring a GUID for the legacy boot event class. This library supports
46 the EDK/EFI 1.10 form and EDK II/UEFI 2.0 form and allows common code to
47 work both ways.
48
49 @param LegacyBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex).
50
51 @retval EFI_SUCCESS Event was created.
52 @retval Other Event was not created.
53
54 **/
55 EFI_STATUS
56 EFIAPI
57 EfiCreateEventLegacyBoot (
58 OUT EFI_EVENT *LegacyBootEvent
59 )
60 {
61 return EfiCreateEventLegacyBootEx (
62 EFI_TPL_CALLBACK,
63 InternalEmptyFuntion,
64 NULL,
65 LegacyBootEvent
66 );
67 }
68
69 /**
70 Create an EFI event in the Legacy Boot Event Group and allows
71 the caller to specify a notification function.
72
73 This function abstracts the creation of the Legacy Boot Event.
74 The Framework moved from a proprietary to UEFI 2.0 based mechanism.
75 This library abstracts the caller from how this event is created to prevent
76 to code form having to change with the version of the specification supported.
77 If LegacyBootEvent is NULL, then ASSERT().
78
79 @param NotifyTpl The task priority level of the event.
80 @param NotifyFunction The notification function to call when the event is signaled.
81 @param NotifyContext The content to pass to NotifyFunction when the event is signaled.
82 @param LegacyBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex).
83
84 @retval EFI_SUCCESS Event was created.
85 @retval Other Event was not created.
86
87 **/
88 EFI_STATUS
89 EFIAPI
90 EfiCreateEventLegacyBootEx (
91 IN EFI_TPL NotifyTpl,
92 IN EFI_EVENT_NOTIFY NotifyFunction, OPTIONAL
93 IN VOID *NotifyContext, OPTIONAL
94 OUT EFI_EVENT *LegacyBootEvent
95 )
96 {
97 EFI_STATUS Status;
98
99 ASSERT (LegacyBootEvent != NULL);
100
101 if (gST->Hdr.Revision < 0x00020000) {
102 //
103 // prior to UEFI 2.0 use Tiano extension to EFI
104 //
105 Status = gBS->CreateEvent (
106 EFI_EVENT_SIGNAL_LEGACY_BOOT | EFI_EVENT_NOTIFY_SIGNAL_ALL,
107 NotifyTpl,
108 NotifyFunction,
109 NotifyContext,
110 LegacyBootEvent
111 );
112 } else if (gST->Hdr.Revision >= 0x00020000 ) {
113 //
114 // For UEFI 2.0 and the future use an Event Group
115 //
116 Status = gBS->CreateEventEx (
117 EVENT_NOTIFY_SIGNAL,
118 NotifyTpl,
119 NotifyFunction,
120 NotifyContext,
121 &gEfiEventLegacyBootGuid,
122 LegacyBootEvent
123 );
124 } else {
125 //
126 // For EFI 1.10 with no Tiano extensions return unsupported
127 //
128 Status = EFI_UNSUPPORTED;
129 }
130
131 return Status;
132 }
133
134 /**
135 Create a Read to Boot Event.
136
137 Tiano extended the CreateEvent Type enum to add a ready to boot event type.
138 This was bad as Tiano did not own the enum. In UEFI 2.0 CreateEventEx was
139 added and now it's possible to not voilate the UEFI specification and use
140 the ready to boot event class defined in UEFI 2.0. This library supports
141 the EDK/EFI 1.10 form and EDK II/UEFI 2.0 form and allows common code to
142 work both ways.
143
144 @param LegacyBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex).
145
146 @retval EFI_SUCCESS Event was created.
147 @retval Other Event was not created.
148
149 **/
150 EFI_STATUS
151 EFIAPI
152 EfiCreateEventReadyToBoot (
153 OUT EFI_EVENT *ReadyToBootEvent
154 )
155 {
156 return EfiCreateEventReadyToBootEx (
157 EFI_TPL_CALLBACK,
158 InternalEmptyFuntion,
159 NULL,
160 ReadyToBootEvent
161 );
162 }
163
164 /**
165 Create an EFI event in the Ready To Boot Event Group and allows
166 the caller to specify a notification function.
167
168 This function abstracts the creation of the Ready to Boot Event.
169 The Framework moved from a proprietary to UEFI 2.0 based mechanism.
170 This library abstracts the caller from how this event is created to prevent
171 to code form having to change with the version of the specification supported.
172 If ReadyToBootEvent is NULL, then ASSERT().
173
174 @param NotifyTpl The task priority level of the event.
175 @param NotifyFunction The notification function to call when the event is signaled.
176 @param NotifyContext The content to pass to NotifyFunction when the event is signaled.
177 @param LegacyBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex).
178
179 @retval EFI_SUCCESS Event was created.
180 @retval Other Event was not created.
181
182 **/
183 EFI_STATUS
184 EFIAPI
185 EfiCreateEventReadyToBootEx (
186 IN EFI_TPL NotifyTpl,
187 IN EFI_EVENT_NOTIFY NotifyFunction, OPTIONAL
188 IN VOID *NotifyContext, OPTIONAL
189 OUT EFI_EVENT *ReadyToBootEvent
190 )
191 {
192 EFI_STATUS Status;
193
194 ASSERT (ReadyToBootEvent != NULL);
195
196 if (gST->Hdr.Revision < 0x00020000) {
197 //
198 // prior to UEFI 2.0 use Tiano extension to EFI
199 //
200 Status = gBS->CreateEvent (
201 EFI_EVENT_SIGNAL_READY_TO_BOOT | EFI_EVENT_NOTIFY_SIGNAL_ALL,
202 NotifyTpl,
203 NotifyFunction,
204 NotifyContext,
205 ReadyToBootEvent
206 );
207 } else if (gST->Hdr.Revision >= 0x00020000) {
208 //
209 // For UEFI 2.0 and the future use an Event Group
210 //
211 Status = gBS->CreateEventEx (
212 EVENT_NOTIFY_SIGNAL,
213 NotifyTpl,
214 NotifyFunction,
215 NotifyContext,
216 &gEfiEventReadyToBootGuid,
217 ReadyToBootEvent
218 );
219 } else {
220 //
221 // For EFI 1.10 with no Tiano extensions return unsupported
222 //
223 Status = EFI_UNSUPPORTED;
224 }
225
226 return Status;
227 }
228
229
230 /**
231 Signal a Ready to Boot Event.
232
233 Create a Ready to Boot Event. Signal it and close it. This causes other
234 events of the same event group to be signaled in other modules.
235
236 **/
237 VOID
238 EFIAPI
239 EfiSignalEventReadyToBoot (
240 VOID
241 )
242 {
243 EFI_STATUS Status;
244 EFI_EVENT ReadyToBootEvent;
245
246 Status = EfiCreateEventReadyToBoot (&ReadyToBootEvent);
247 if (!EFI_ERROR (Status)) {
248 gBS->SignalEvent (ReadyToBootEvent);
249 gBS->CloseEvent (ReadyToBootEvent);
250 }
251 }
252
253 /**
254 Signal a Legacy Boot Event.
255
256 Create a legacy Boot Event. Signal it and close it. This causes other
257 events of the same event group to be signaled in other modules.
258
259 **/
260 VOID
261 EFIAPI
262 EfiSignalEventLegacyBoot (
263 VOID
264 )
265 {
266 EFI_STATUS Status;
267 EFI_EVENT LegacyBootEvent;
268
269 Status = EfiCreateEventLegacyBoot (&LegacyBootEvent);
270 if (!EFI_ERROR (Status)) {
271 gBS->SignalEvent (LegacyBootEvent);
272 gBS->CloseEvent (LegacyBootEvent);
273 }
274 }
275
276
277 /**
278 Check to see if the Firmware Volume (FV) Media Device Path is valid
279
280 Tiano extended the EFI 1.10 device path nodes. Tiano does not own this enum
281 so as we move to UEFI 2.0 support we must use a mechanism that conforms with
282 the UEFI 2.0 specification to define the FV device path. An UEFI GUIDed
283 device path is defined for Tiano extensions of device path. If the code
284 is compiled to conform with the UEFI 2.0 specification use the new device path
285 else use the old form for backwards compatability. The return value to this
286 function points to a location in FvDevicePathNode and it does not allocate
287 new memory for the GUID pointer that is returned.
288
289 @param FvDevicePathNode Pointer to FV device path to check.
290
291 @retval NULL FvDevicePathNode is not valid.
292 @retval Other FvDevicePathNode is valid and pointer to NameGuid was returned.
293
294 **/
295 EFI_GUID *
296 EFIAPI
297 EfiGetNameGuidFromFwVolDevicePathNode (
298 IN CONST MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvDevicePathNode
299 )
300 {
301 ASSERT (FvDevicePathNode != NULL);
302
303 //
304 // Use the new Device path that does not conflict with the UEFI
305 //
306 if (FvDevicePathNode->Tiano.Header.Type == MEDIA_DEVICE_PATH ||
307 FvDevicePathNode->Tiano.Header.SubType == MEDIA_VENDOR_DP) {
308 if (CompareGuid (&gEfiFrameworkDevicePathGuid, &FvDevicePathNode->Tiano.TianoSpecificDevicePath)) {
309 if (FvDevicePathNode->Tiano.Type == TIANO_MEDIA_FW_VOL_FILEPATH_DEVICE_PATH_TYPE) {
310 return (EFI_GUID *) &FvDevicePathNode->NameGuid;
311 }
312 }
313 }
314
315 return NULL;
316 }
317
318
319 /**
320 Initialize a Firmware Volume (FV) Media Device Path node.
321
322 Tiano extended the EFI 1.10 device path nodes. Tiano does not own this enum
323 so as we move to UEFI 2.0 support we must use a mechanism that conforms with
324 the UEFI 2.0 specification to define the FV device path. An UEFI GUIDed
325 device path is defined for Tiano extensions of device path. If the code
326 is compiled to conform with the UEFI 2.0 specification use the new device path
327 else use the old form for backwards compatability.
328
329 @param FvDevicePathNode Pointer to a FV device path node to initialize
330 @param NameGuid FV file name to use in FvDevicePathNode
331
332 **/
333 VOID
334 EFIAPI
335 EfiInitializeFwVolDevicepathNode (
336 IN OUT MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvDevicePathNode,
337 IN CONST EFI_GUID *NameGuid
338 )
339 {
340 ASSERT (FvDevicePathNode != NULL);
341 ASSERT (NameGuid != NULL);
342
343 //
344 // Use the new Device path that does not conflict with the UEFI
345 //
346 FvDevicePathNode->Tiano.Header.Type = MEDIA_DEVICE_PATH;
347 FvDevicePathNode->Tiano.Header.SubType = MEDIA_VENDOR_DP;
348 SetDevicePathNodeLength (&FvDevicePathNode->Tiano.Header, sizeof (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH));
349
350 //
351 // Add the GUID for generic Tiano device paths
352 //
353 CopyGuid (&FvDevicePathNode->Tiano.TianoSpecificDevicePath, &gEfiFrameworkDevicePathGuid);
354
355 //
356 // Add in the FW Vol File Path Tiano defined information
357 //
358 FvDevicePathNode->Tiano.Type = TIANO_MEDIA_FW_VOL_FILEPATH_DEVICE_PATH_TYPE;
359
360 CopyGuid (&FvDevicePathNode->NameGuid, NameGuid);
361 }
362