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