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