]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/UefiLib/UefiNotTiano.c
MdePkg: Apply uncrustify changes
[mirror_edk2.git] / MdePkg / Library / UefiLib / UefiNotTiano.c
1 /** @file
2 Library functions that abstract areas of conflict between framework and UEFI 2.0.
3
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.
8
9 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
10 SPDX-License-Identifier: BSD-2-Clause-Patent
11
12 **/
13
14 #include "UefiLibInternal.h"
15
16 /**
17 Creates an EFI event in the Legacy Boot Event Group.
18
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().
26
27 @param LegacyBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex).
28
29 @retval EFI_SUCCESS Event was created.
30 @retval Other Event was not created.
31
32 **/
33 EFI_STATUS
34 EFIAPI
35 EfiCreateEventLegacyBoot (
36 OUT EFI_EVENT *LegacyBootEvent
37 )
38 {
39 return EfiCreateEventLegacyBootEx (
40 TPL_CALLBACK,
41 EfiEventEmptyFunction,
42 NULL,
43 LegacyBootEvent
44 );
45 }
46
47 /**
48 Create an EFI event in the Legacy Boot Event Group and allows
49 the caller to specify a notification function.
50
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().
56
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).
61
62 @retval EFI_SUCCESS Event was created.
63 @retval Other Event was not created.
64
65 **/
66 EFI_STATUS
67 EFIAPI
68 EfiCreateEventLegacyBootEx (
69 IN EFI_TPL NotifyTpl,
70 IN EFI_EVENT_NOTIFY NotifyFunction OPTIONAL,
71 IN VOID *NotifyContext OPTIONAL,
72 OUT EFI_EVENT *LegacyBootEvent
73 )
74 {
75 EFI_STATUS Status;
76 EFI_EVENT_NOTIFY WorkerNotifyFunction;
77
78 ASSERT (LegacyBootEvent != NULL);
79
80 if (gST->Hdr.Revision < EFI_2_00_SYSTEM_TABLE_REVISION) {
81 DEBUG ((DEBUG_ERROR, "EFI1.1 can't support LegacyBootEvent!"));
82 ASSERT (FALSE);
83
84 return EFI_UNSUPPORTED;
85 } else {
86 //
87 // For UEFI 2.0 and the future use an Event Group
88 //
89 if (NotifyFunction == NULL) {
90 //
91 // CreateEventEx will check NotifyFunction is NULL or not and return error.
92 // Use dummy routine for the case NotifyFunction is NULL.
93 //
94 WorkerNotifyFunction = EfiEventEmptyFunction;
95 } else {
96 WorkerNotifyFunction = NotifyFunction;
97 }
98
99 Status = gBS->CreateEventEx (
100 EVT_NOTIFY_SIGNAL,
101 NotifyTpl,
102 WorkerNotifyFunction,
103 NotifyContext,
104 &gEfiEventLegacyBootGuid,
105 LegacyBootEvent
106 );
107 }
108
109 return Status;
110 }
111
112 /**
113 Create an EFI event in the Ready To Boot Event Group.
114
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().
122
123 @param ReadyToBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex).
124
125 @retval EFI_SUCCESS Event was created.
126 @retval Other Event was not created.
127
128 **/
129 EFI_STATUS
130 EFIAPI
131 EfiCreateEventReadyToBoot (
132 OUT EFI_EVENT *ReadyToBootEvent
133 )
134 {
135 return EfiCreateEventReadyToBootEx (
136 TPL_CALLBACK,
137 EfiEventEmptyFunction,
138 NULL,
139 ReadyToBootEvent
140 );
141 }
142
143 /**
144 Create an EFI event in the Ready To Boot Event Group and allows
145 the caller to specify a notification function.
146
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().
152
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).
157
158 @retval EFI_SUCCESS Event was created.
159 @retval Other Event was not created.
160
161 **/
162 EFI_STATUS
163 EFIAPI
164 EfiCreateEventReadyToBootEx (
165 IN EFI_TPL NotifyTpl,
166 IN EFI_EVENT_NOTIFY NotifyFunction OPTIONAL,
167 IN VOID *NotifyContext OPTIONAL,
168 OUT EFI_EVENT *ReadyToBootEvent
169 )
170 {
171 EFI_STATUS Status;
172 EFI_EVENT_NOTIFY WorkerNotifyFunction;
173
174 ASSERT (ReadyToBootEvent != NULL);
175
176 if (gST->Hdr.Revision < EFI_2_00_SYSTEM_TABLE_REVISION) {
177 DEBUG ((DEBUG_ERROR, "EFI1.1 can't support ReadyToBootEvent!"));
178 ASSERT (FALSE);
179
180 return EFI_UNSUPPORTED;
181 } else {
182 //
183 // For UEFI 2.0 and the future use an Event Group
184 //
185 if (NotifyFunction == NULL) {
186 //
187 // CreateEventEx will check NotifyFunction is NULL or not and return error.
188 // Use dummy routine for the case NotifyFunction is NULL.
189 //
190 WorkerNotifyFunction = EfiEventEmptyFunction;
191 } else {
192 WorkerNotifyFunction = NotifyFunction;
193 }
194
195 Status = gBS->CreateEventEx (
196 EVT_NOTIFY_SIGNAL,
197 NotifyTpl,
198 WorkerNotifyFunction,
199 NotifyContext,
200 &gEfiEventReadyToBootGuid,
201 ReadyToBootEvent
202 );
203 }
204
205 return Status;
206 }
207
208 /**
209 Create, Signal, and Close the Ready to Boot event using EfiSignalEventReadyToBoot().
210
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.
215
216 **/
217 VOID
218 EFIAPI
219 EfiSignalEventReadyToBoot (
220 VOID
221 )
222 {
223 EFI_STATUS Status;
224 EFI_EVENT ReadyToBootEvent;
225
226 Status = EfiCreateEventReadyToBoot (&ReadyToBootEvent);
227 if (!EFI_ERROR (Status)) {
228 gBS->SignalEvent (ReadyToBootEvent);
229 gBS->CloseEvent (ReadyToBootEvent);
230 }
231 }
232
233 /**
234 Create, Signal, and Close the Ready to Boot event using EfiSignalEventLegacyBoot().
235
236 This function abstracts the signaling of the Legacy Boot Event. The Framework moved from
237 a proprietary to UEFI 2.0 based mechanism. This library abstracts the caller from how
238 this event is created to prevent to code form having to change with the version of the
239 specification supported.
240
241 **/
242 VOID
243 EFIAPI
244 EfiSignalEventLegacyBoot (
245 VOID
246 )
247 {
248 EFI_STATUS Status;
249 EFI_EVENT LegacyBootEvent;
250
251 Status = EfiCreateEventLegacyBoot (&LegacyBootEvent);
252 if (!EFI_ERROR (Status)) {
253 gBS->SignalEvent (LegacyBootEvent);
254 gBS->CloseEvent (LegacyBootEvent);
255 }
256 }
257
258 /**
259 Check to see if the Firmware Volume (FV) Media Device Path is valid
260
261 The Framework FwVol Device Path changed to conform to the UEFI 2.0 specification.
262 This library function abstracts validating a device path node.
263 Check the MEDIA_FW_VOL_FILEPATH_DEVICE_PATH data structure to see if it's valid.
264 If it is valid, then return the GUID file name from the device path node. Otherwise,
265 return NULL. This device path changed in the DXE CIS version 0.92 in a non back ward
266 compatible way to not conflict with the UEFI 2.0 specification. This function abstracts
267 the differences from the caller.
268 If FvDevicePathNode is NULL, then ASSERT().
269
270 @param FvDevicePathNode The pointer to FV device path to check.
271
272 @retval NULL FvDevicePathNode is not valid.
273 @retval Other FvDevicePathNode is valid and pointer to NameGuid was returned.
274
275 **/
276 EFI_GUID *
277 EFIAPI
278 EfiGetNameGuidFromFwVolDevicePathNode (
279 IN CONST MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvDevicePathNode
280 )
281 {
282 ASSERT (FvDevicePathNode != NULL);
283
284 if ((DevicePathType (&FvDevicePathNode->Header) == MEDIA_DEVICE_PATH) &&
285 (DevicePathSubType (&FvDevicePathNode->Header) == MEDIA_PIWG_FW_FILE_DP))
286 {
287 return (EFI_GUID *)&FvDevicePathNode->FvFileName;
288 }
289
290 return NULL;
291 }
292
293 /**
294 Initialize a Firmware Volume (FV) Media Device Path node.
295
296 The Framework FwVol Device Path changed to conform to the UEFI 2.0 specification.
297 This library function abstracts initializing a device path node.
298 Initialize the MEDIA_FW_VOL_FILEPATH_DEVICE_PATH data structure. This device
299 path changed in the DXE CIS version 0.92 in a non back ward compatible way to
300 not conflict with the UEFI 2.0 specification. This function abstracts the
301 differences from the caller.
302 If FvDevicePathNode is NULL, then ASSERT().
303 If NameGuid is NULL, then ASSERT().
304
305 @param FvDevicePathNode The pointer to a FV device path node to initialize
306 @param NameGuid FV file name to use in FvDevicePathNode
307
308 **/
309 VOID
310 EFIAPI
311 EfiInitializeFwVolDevicepathNode (
312 IN OUT MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvDevicePathNode,
313 IN CONST EFI_GUID *NameGuid
314 )
315 {
316 ASSERT (FvDevicePathNode != NULL);
317 ASSERT (NameGuid != NULL);
318
319 //
320 // Use the new Device path that does not conflict with the UEFI
321 //
322 FvDevicePathNode->Header.Type = MEDIA_DEVICE_PATH;
323 FvDevicePathNode->Header.SubType = MEDIA_PIWG_FW_FILE_DP;
324 SetDevicePathNodeLength (&FvDevicePathNode->Header, sizeof (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH));
325
326 CopyGuid (&FvDevicePathNode->FvFileName, NameGuid);
327 }