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 | EFI_EVENT AfterReadyToBootEvent;
|
---|
226 |
|
---|
227 | Status = EfiCreateEventReadyToBoot (&ReadyToBootEvent);
|
---|
228 | if (!EFI_ERROR (Status)) {
|
---|
229 | gBS->SignalEvent (ReadyToBootEvent);
|
---|
230 | gBS->CloseEvent (ReadyToBootEvent);
|
---|
231 | }
|
---|
232 |
|
---|
233 | Status = gBS->CreateEventEx (
|
---|
234 | EVT_NOTIFY_SIGNAL,
|
---|
235 | TPL_CALLBACK,
|
---|
236 | EfiEventEmptyFunction,
|
---|
237 | NULL,
|
---|
238 | &gEfiEventAfterReadyToBootGuid,
|
---|
239 | &AfterReadyToBootEvent
|
---|
240 | );
|
---|
241 | if (!EFI_ERROR (Status)) {
|
---|
242 | gBS->SignalEvent (AfterReadyToBootEvent);
|
---|
243 | gBS->CloseEvent (AfterReadyToBootEvent);
|
---|
244 | }
|
---|
245 | }
|
---|
246 |
|
---|
247 | /**
|
---|
248 | Create, Signal, and Close the Ready to Boot event using EfiSignalEventLegacyBoot().
|
---|
249 |
|
---|
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.
|
---|
254 |
|
---|
255 | **/
|
---|
256 | VOID
|
---|
257 | EFIAPI
|
---|
258 | EfiSignalEventLegacyBoot (
|
---|
259 | VOID
|
---|
260 | )
|
---|
261 | {
|
---|
262 | EFI_STATUS Status;
|
---|
263 | EFI_EVENT LegacyBootEvent;
|
---|
264 |
|
---|
265 | Status = EfiCreateEventLegacyBoot (&LegacyBootEvent);
|
---|
266 | if (!EFI_ERROR (Status)) {
|
---|
267 | gBS->SignalEvent (LegacyBootEvent);
|
---|
268 | gBS->CloseEvent (LegacyBootEvent);
|
---|
269 | }
|
---|
270 | }
|
---|
271 |
|
---|
272 | /**
|
---|
273 | Check to see if the Firmware Volume (FV) Media Device Path is valid
|
---|
274 |
|
---|
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().
|
---|
283 |
|
---|
284 | @param FvDevicePathNode The pointer to FV device path to check.
|
---|
285 |
|
---|
286 | @retval NULL FvDevicePathNode is not valid.
|
---|
287 | @retval Other FvDevicePathNode is valid and pointer to NameGuid was returned.
|
---|
288 |
|
---|
289 | **/
|
---|
290 | EFI_GUID *
|
---|
291 | EFIAPI
|
---|
292 | EfiGetNameGuidFromFwVolDevicePathNode (
|
---|
293 | IN CONST MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvDevicePathNode
|
---|
294 | )
|
---|
295 | {
|
---|
296 | ASSERT (FvDevicePathNode != NULL);
|
---|
297 |
|
---|
298 | if ((DevicePathType (&FvDevicePathNode->Header) == MEDIA_DEVICE_PATH) &&
|
---|
299 | (DevicePathSubType (&FvDevicePathNode->Header) == MEDIA_PIWG_FW_FILE_DP))
|
---|
300 | {
|
---|
301 | return (EFI_GUID *)&FvDevicePathNode->FvFileName;
|
---|
302 | }
|
---|
303 |
|
---|
304 | return NULL;
|
---|
305 | }
|
---|
306 |
|
---|
307 | /**
|
---|
308 | Initialize a Firmware Volume (FV) Media Device Path node.
|
---|
309 |
|
---|
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().
|
---|
318 |
|
---|
319 | @param FvDevicePathNode The pointer to a FV device path node to initialize
|
---|
320 | @param NameGuid FV file name to use in FvDevicePathNode
|
---|
321 |
|
---|
322 | **/
|
---|
323 | VOID
|
---|
324 | EFIAPI
|
---|
325 | EfiInitializeFwVolDevicepathNode (
|
---|
326 | IN OUT MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvDevicePathNode,
|
---|
327 | IN CONST EFI_GUID *NameGuid
|
---|
328 | )
|
---|
329 | {
|
---|
330 | ASSERT (FvDevicePathNode != NULL);
|
---|
331 | ASSERT (NameGuid != NULL);
|
---|
332 |
|
---|
333 | //
|
---|
334 | // Use the new Device path that does not conflict with the UEFI
|
---|
335 | //
|
---|
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));
|
---|
339 |
|
---|
340 | CopyGuid (&FvDevicePathNode->FvFileName, NameGuid);
|
---|
341 | }
|
---|