2 Library functions that abstract areas of conflict between framework and UEFI 2.0.
4 Help Port Framework code that has conflicts with UEFI 2.0 by hiding the
5 old conflicts 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.
9 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
10 SPDX-License-Identifier: BSD-2-Clause-Patent
14 #include "UefiLibInternal.h"
17 Creates an EFI event in the Legacy Boot Event Group.
19 Prior to UEFI 2.0 this was done via a non blessed UEFI extensions and this library
20 abstracts the implementation mechanism of this event from the caller. This function
21 abstracts the creation of the Legacy Boot Event. The Framework moved from a proprietary
22 to UEFI 2.0 based mechanism. This library abstracts the caller from how this event
23 is created to prevent to code form having to change with the version of the
24 specification supported.
25 If LegacyBootEvent is NULL, then ASSERT().
27 @param LegacyBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex).
29 @retval EFI_SUCCESS Event was created.
30 @retval Other Event was not created.
35 EfiCreateEventLegacyBoot (
36 OUT EFI_EVENT
*LegacyBootEvent
39 return EfiCreateEventLegacyBootEx (
41 EfiEventEmptyFunction
,
48 Create an EFI event in the Legacy Boot Event Group and allows
49 the caller to specify a notification function.
51 This function abstracts the creation of the Legacy Boot Event.
52 The Framework moved from a proprietary to UEFI 2.0 based mechanism.
53 This library abstracts the caller from how this event is created to prevent
54 to code form having to change with the version of the specification supported.
55 If LegacyBootEvent is NULL, then ASSERT().
57 @param NotifyTpl The task priority level of the event.
58 @param NotifyFunction The notification function to call when the event is signaled.
59 @param NotifyContext The content to pass to NotifyFunction when the event is signaled.
60 @param LegacyBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex).
62 @retval EFI_SUCCESS Event was created.
63 @retval Other Event was not created.
68 EfiCreateEventLegacyBootEx (
70 IN EFI_EVENT_NOTIFY NotifyFunction OPTIONAL
,
71 IN VOID
*NotifyContext OPTIONAL
,
72 OUT EFI_EVENT
*LegacyBootEvent
76 EFI_EVENT_NOTIFY WorkerNotifyFunction
;
78 ASSERT (LegacyBootEvent
!= NULL
);
80 if (gST
->Hdr
.Revision
< EFI_2_00_SYSTEM_TABLE_REVISION
) {
81 DEBUG ((DEBUG_ERROR
, "EFI1.1 can't support LegacyBootEvent!"));
84 return EFI_UNSUPPORTED
;
87 // For UEFI 2.0 and the future use an Event Group
89 if (NotifyFunction
== NULL
) {
91 // CreateEventEx will check NotifyFunction is NULL or not and return error.
92 // Use dummy routine for the case NotifyFunction is NULL.
94 WorkerNotifyFunction
= EfiEventEmptyFunction
;
96 WorkerNotifyFunction
= NotifyFunction
;
99 Status
= gBS
->CreateEventEx (
102 WorkerNotifyFunction
,
104 &gEfiEventLegacyBootGuid
,
113 Create an EFI event in the Ready To Boot Event Group.
115 Prior to UEFI 2.0 this was done via a non-standard UEFI extension, and this library
116 abstracts the implementation mechanism of this event from the caller.
117 This function abstracts the creation of the Ready to Boot Event. The Framework
118 moved from a proprietary to UEFI 2.0-based mechanism. This library abstracts
119 the caller from how this event is created to prevent the code form having to
120 change with the version of the specification supported.
121 If ReadyToBootEvent is NULL, then ASSERT().
123 @param ReadyToBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex).
125 @retval EFI_SUCCESS Event was created.
126 @retval Other Event was not created.
131 EfiCreateEventReadyToBoot (
132 OUT EFI_EVENT
*ReadyToBootEvent
135 return EfiCreateEventReadyToBootEx (
137 EfiEventEmptyFunction
,
144 Create an EFI event in the Ready To Boot Event Group and allows
145 the caller to specify a notification function.
147 This function abstracts the creation of the Ready to Boot Event.
148 The Framework moved from a proprietary to UEFI 2.0 based mechanism.
149 This library abstracts the caller from how this event is created to prevent
150 to code form having to change with the version of the specification supported.
151 If ReadyToBootEvent is NULL, then ASSERT().
153 @param NotifyTpl The task priority level of the event.
154 @param NotifyFunction The notification function to call when the event is signaled.
155 @param NotifyContext The content to pass to NotifyFunction when the event is signaled.
156 @param ReadyToBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex).
158 @retval EFI_SUCCESS Event was created.
159 @retval Other Event was not created.
164 EfiCreateEventReadyToBootEx (
165 IN EFI_TPL NotifyTpl
,
166 IN EFI_EVENT_NOTIFY NotifyFunction OPTIONAL
,
167 IN VOID
*NotifyContext OPTIONAL
,
168 OUT EFI_EVENT
*ReadyToBootEvent
172 EFI_EVENT_NOTIFY WorkerNotifyFunction
;
174 ASSERT (ReadyToBootEvent
!= NULL
);
176 if (gST
->Hdr
.Revision
< EFI_2_00_SYSTEM_TABLE_REVISION
) {
177 DEBUG ((DEBUG_ERROR
, "EFI1.1 can't support ReadyToBootEvent!"));
180 return EFI_UNSUPPORTED
;
183 // For UEFI 2.0 and the future use an Event Group
185 if (NotifyFunction
== NULL
) {
187 // CreateEventEx will check NotifyFunction is NULL or not and return error.
188 // Use dummy routine for the case NotifyFunction is NULL.
190 WorkerNotifyFunction
= EfiEventEmptyFunction
;
192 WorkerNotifyFunction
= NotifyFunction
;
195 Status
= gBS
->CreateEventEx (
198 WorkerNotifyFunction
,
200 &gEfiEventReadyToBootGuid
,
209 Create, Signal, and Close the Ready to Boot event using EfiSignalEventReadyToBoot().
211 This function abstracts the signaling of the Ready to Boot Event. The Framework moved
212 from a proprietary to UEFI 2.0 based mechanism. This library abstracts the caller
213 from how this event is created to prevent to code form having to change with the
214 version of the specification supported.
219 EfiSignalEventReadyToBoot (
224 EFI_EVENT ReadyToBootEvent
;
225 EFI_EVENT AfterReadyToBootEvent
;
227 Status
= EfiCreateEventReadyToBoot (&ReadyToBootEvent
);
228 if (!EFI_ERROR (Status
)) {
229 gBS
->SignalEvent (ReadyToBootEvent
);
230 gBS
->CloseEvent (ReadyToBootEvent
);
233 Status
= gBS
->CreateEventEx (
236 EfiEventEmptyFunction
,
238 &gEfiEventAfterReadyToBootGuid
,
239 &AfterReadyToBootEvent
241 if (!EFI_ERROR (Status
)) {
242 gBS
->SignalEvent (AfterReadyToBootEvent
);
243 gBS
->CloseEvent (AfterReadyToBootEvent
);
248 Create, Signal, and Close the Ready to Boot event using EfiSignalEventLegacyBoot().
250 This function abstracts the signaling of the Legacy Boot Event. The Framework moved from
251 a proprietary to UEFI 2.0 based mechanism. This library abstracts the caller from how
252 this event is created to prevent to code form having to change with the version of the
253 specification supported.
258 EfiSignalEventLegacyBoot (
263 EFI_EVENT LegacyBootEvent
;
265 Status
= EfiCreateEventLegacyBoot (&LegacyBootEvent
);
266 if (!EFI_ERROR (Status
)) {
267 gBS
->SignalEvent (LegacyBootEvent
);
268 gBS
->CloseEvent (LegacyBootEvent
);
273 Check to see if the Firmware Volume (FV) Media Device Path is valid
275 The Framework FwVol Device Path changed to conform to the UEFI 2.0 specification.
276 This library function abstracts validating a device path node.
277 Check the MEDIA_FW_VOL_FILEPATH_DEVICE_PATH data structure to see if it's valid.
278 If it is valid, then return the GUID file name from the device path node. Otherwise,
279 return NULL. This device path changed in the DXE CIS version 0.92 in a non back ward
280 compatible way to not conflict with the UEFI 2.0 specification. This function abstracts
281 the differences from the caller.
282 If FvDevicePathNode is NULL, then ASSERT().
284 @param FvDevicePathNode The pointer to FV device path to check.
286 @retval NULL FvDevicePathNode is not valid.
287 @retval Other FvDevicePathNode is valid and pointer to NameGuid was returned.
292 EfiGetNameGuidFromFwVolDevicePathNode (
293 IN CONST MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*FvDevicePathNode
296 ASSERT (FvDevicePathNode
!= NULL
);
298 if ((DevicePathType (&FvDevicePathNode
->Header
) == MEDIA_DEVICE_PATH
) &&
299 (DevicePathSubType (&FvDevicePathNode
->Header
) == MEDIA_PIWG_FW_FILE_DP
))
301 return (EFI_GUID
*)&FvDevicePathNode
->FvFileName
;
308 Initialize a Firmware Volume (FV) Media Device Path node.
310 The Framework FwVol Device Path changed to conform to the UEFI 2.0 specification.
311 This library function abstracts initializing a device path node.
312 Initialize the MEDIA_FW_VOL_FILEPATH_DEVICE_PATH data structure. This device
313 path changed in the DXE CIS version 0.92 in a non back ward compatible way to
314 not conflict with the UEFI 2.0 specification. This function abstracts the
315 differences from the caller.
316 If FvDevicePathNode is NULL, then ASSERT().
317 If NameGuid is NULL, then ASSERT().
319 @param FvDevicePathNode The pointer to a FV device path node to initialize
320 @param NameGuid FV file name to use in FvDevicePathNode
325 EfiInitializeFwVolDevicepathNode (
326 IN OUT MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*FvDevicePathNode
,
327 IN CONST EFI_GUID
*NameGuid
330 ASSERT (FvDevicePathNode
!= NULL
);
331 ASSERT (NameGuid
!= NULL
);
334 // Use the new Device path that does not conflict with the UEFI
336 FvDevicePathNode
->Header
.Type
= MEDIA_DEVICE_PATH
;
337 FvDevicePathNode
->Header
.SubType
= MEDIA_PIWG_FW_FILE_DP
;
338 SetDevicePathNodeLength (&FvDevicePathNode
->Header
, sizeof (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
));
340 CopyGuid (&FvDevicePathNode
->FvFileName
, NameGuid
);