]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/UefiLib/UefiNotTiano.c
Add check before use to make code run more safer.
[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 - 2008, Intel Corporation. All rights reserved.<BR>
10 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
21
22 #include "UefiLibInternal.h"
23
24 /**
25 An empty function to pass error checking of CreateEventEx ().
26
27 This empty function ensures that EVT_NOTIFY_SIGNAL_ALL is error
28 checked correctly since it is now mapped into CreateEventEx() in UEFI 2.0.
29
30 @param Event Event whose notification function is being invoked.
31 @param Context The pointer to the notification function's context,
32 which is implementation-dependent.
33
34 **/
35 VOID
36 EFIAPI
37 InternalEmptyFuntion (
38 IN EFI_EVENT Event,
39 IN VOID *Context
40 )
41 {
42 return;
43 }
44
45 /**
46 Creates an EFI event in the Legacy Boot Event Group.
47
48 Prior to UEFI 2.0 this was done via a non blessed UEFI extensions and this library
49 abstracts the implementation mechanism of this event from the caller. This function
50 abstracts the creation of the Legacy Boot Event. The Framework moved from a proprietary
51 to UEFI 2.0 based mechanism. This library abstracts the caller from how this event
52 is created to prevent to code form having to change with the version of the
53 specification supported.
54 If LegacyBootEvent is NULL, then ASSERT().
55
56 @param LegacyBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex).
57
58 @retval EFI_SUCCESS Event was created.
59 @retval Other Event was not created.
60
61 **/
62 EFI_STATUS
63 EFIAPI
64 EfiCreateEventLegacyBoot (
65 OUT EFI_EVENT *LegacyBootEvent
66 )
67 {
68 return EfiCreateEventLegacyBootEx (
69 TPL_CALLBACK,
70 InternalEmptyFuntion,
71 NULL,
72 LegacyBootEvent
73 );
74 }
75
76 /**
77 Create an EFI event in the Legacy Boot Event Group and allows
78 the caller to specify a notification function.
79
80 This function abstracts the creation of the Legacy Boot Event.
81 The Framework moved from a proprietary to UEFI 2.0 based mechanism.
82 This library abstracts the caller from how this event is created to prevent
83 to code form having to change with the version of the specification supported.
84 If LegacyBootEvent is NULL, then ASSERT().
85
86 @param NotifyTpl The task priority level of the event.
87 @param NotifyFunction The notification function to call when the event is signaled.
88 @param NotifyContext The content to pass to NotifyFunction when the event is signaled.
89 @param LegacyBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex).
90
91 @retval EFI_SUCCESS Event was created.
92 @retval Other Event was not created.
93
94 **/
95 EFI_STATUS
96 EFIAPI
97 EfiCreateEventLegacyBootEx (
98 IN EFI_TPL NotifyTpl,
99 IN EFI_EVENT_NOTIFY NotifyFunction, OPTIONAL
100 IN VOID *NotifyContext, OPTIONAL
101 OUT EFI_EVENT *LegacyBootEvent
102 )
103 {
104 EFI_STATUS Status;
105
106 ASSERT (LegacyBootEvent != NULL);
107
108 if (gST->Hdr.Revision < EFI_2_00_SYSTEM_TABLE_REVISION) {
109 DEBUG ((EFI_D_ERROR, "EFI1.1 can't support LegacyBootEvent!"));
110 ASSERT (FALSE);
111
112 return EFI_UNSUPPORTED;
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 an EFI event in the Ready To Boot Event Group.
132
133 Prior to UEFI 2.0 this was done via a non-standard UEFI extension, and this library
134 abstracts the implementation mechanism of this event from the caller.
135 This function abstracts the creation of the Ready to Boot Event. The Framework
136 moved from a proprietary to UEFI 2.0-based mechanism. This library abstracts
137 the caller from how this event is created to prevent the code form having to
138 change with the version of the specification supported.
139 If ReadyToBootEvent is NULL, then ASSERT().
140
141 @param ReadyToBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex).
142
143 @retval EFI_SUCCESS Event was created.
144 @retval Other Event was not created.
145
146 **/
147 EFI_STATUS
148 EFIAPI
149 EfiCreateEventReadyToBoot (
150 OUT EFI_EVENT *ReadyToBootEvent
151 )
152 {
153 return EfiCreateEventReadyToBootEx (
154 TPL_CALLBACK,
155 InternalEmptyFuntion,
156 NULL,
157 ReadyToBootEvent
158 );
159 }
160
161 /**
162 Create an EFI event in the Ready To Boot Event Group and allows
163 the caller to specify a notification function.
164
165 This function abstracts the creation of the Ready to Boot Event.
166 The Framework moved from a proprietary to UEFI 2.0 based mechanism.
167 This library abstracts the caller from how this event is created to prevent
168 to code form having to change with the version of the specification supported.
169 If ReadyToBootEvent is NULL, then ASSERT().
170
171 @param NotifyTpl The task priority level of the event.
172 @param NotifyFunction The notification function to call when the event is signaled.
173 @param NotifyContext The content to pass to NotifyFunction when the event is signaled.
174 @param ReadyToBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex).
175
176 @retval EFI_SUCCESS Event was created.
177 @retval Other Event was not created.
178
179 **/
180 EFI_STATUS
181 EFIAPI
182 EfiCreateEventReadyToBootEx (
183 IN EFI_TPL NotifyTpl,
184 IN EFI_EVENT_NOTIFY NotifyFunction, OPTIONAL
185 IN VOID *NotifyContext, OPTIONAL
186 OUT EFI_EVENT *ReadyToBootEvent
187 )
188 {
189 EFI_STATUS Status;
190
191 ASSERT (ReadyToBootEvent != NULL);
192
193 if (gST->Hdr.Revision < EFI_2_00_SYSTEM_TABLE_REVISION) {
194 DEBUG ((EFI_D_ERROR, "EFI1.1 can't support ReadyToBootEvent!"));
195 ASSERT (FALSE);
196
197 return EFI_UNSUPPORTED;
198 } else {
199 //
200 // For UEFI 2.0 and the future use an Event Group
201 //
202 Status = gBS->CreateEventEx (
203 EVT_NOTIFY_SIGNAL,
204 NotifyTpl,
205 NotifyFunction,
206 NotifyContext,
207 &gEfiEventReadyToBootGuid,
208 ReadyToBootEvent
209 );
210 }
211
212 return Status;
213 }
214
215
216 /**
217 Create, Signal, and Close the Ready to Boot event using EfiSignalEventReadyToBoot().
218
219 This function abstracts the signaling of the Ready to Boot Event. The Framework moved
220 from a proprietary to UEFI 2.0 based mechanism. This library abstracts the caller
221 from how this event is created to prevent to code form having to change with the
222 version of the specification supported.
223
224 **/
225 VOID
226 EFIAPI
227 EfiSignalEventReadyToBoot (
228 VOID
229 )
230 {
231 EFI_STATUS Status;
232 EFI_EVENT ReadyToBootEvent;
233
234 Status = EfiCreateEventReadyToBoot (&ReadyToBootEvent);
235 if (!EFI_ERROR (Status)) {
236 gBS->SignalEvent (ReadyToBootEvent);
237 gBS->CloseEvent (ReadyToBootEvent);
238 }
239 }
240
241 /**
242 Create, Signal, and Close the Ready to Boot event using EfiSignalEventLegacyBoot().
243
244 This function abstracts the signaling of the Legacy Boot Event. The Framework moved from
245 a proprietary to UEFI 2.0 based mechanism. This library abstracts the caller from how
246 this event is created to prevent to code form having to change with the version of the
247 specification supported.
248
249 **/
250 VOID
251 EFIAPI
252 EfiSignalEventLegacyBoot (
253 VOID
254 )
255 {
256 EFI_STATUS Status;
257 EFI_EVENT LegacyBootEvent;
258
259 Status = EfiCreateEventLegacyBoot (&LegacyBootEvent);
260 if (!EFI_ERROR (Status)) {
261 gBS->SignalEvent (LegacyBootEvent);
262 gBS->CloseEvent (LegacyBootEvent);
263 }
264 }
265
266
267 /**
268 Check to see if the Firmware Volume (FV) Media Device Path is valid
269
270 The Framework FwVol Device Path changed to conform to the UEFI 2.0 specification.
271 This library function abstracts validating a device path node.
272 Check the MEDIA_FW_VOL_FILEPATH_DEVICE_PATH data structure to see if it's valid.
273 If it is valid, then return the GUID file name from the device path node. Otherwise,
274 return NULL. This device path changed in the DXE CIS version 0.92 in a non back ward
275 compatible way to not conflict with the UEFI 2.0 specification. This function abstracts
276 the differences from the caller.
277 If FvDevicePathNode is NULL, then ASSERT().
278
279 @param FvDevicePathNode The pointer to FV device path to check.
280
281 @retval NULL FvDevicePathNode is not valid.
282 @retval Other FvDevicePathNode is valid and pointer to NameGuid was returned.
283
284 **/
285 EFI_GUID *
286 EFIAPI
287 EfiGetNameGuidFromFwVolDevicePathNode (
288 IN CONST MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvDevicePathNode
289 )
290 {
291 ASSERT (FvDevicePathNode != NULL);
292
293 if (DevicePathType (&FvDevicePathNode->Header) == MEDIA_DEVICE_PATH &&
294 DevicePathSubType (&FvDevicePathNode->Header) == MEDIA_PIWG_FW_FILE_DP) {
295 return (EFI_GUID *) &FvDevicePathNode->FvFileName;
296 }
297
298 return NULL;
299 }
300
301
302 /**
303 Initialize a Firmware Volume (FV) Media Device Path node.
304
305 The Framework FwVol Device Path changed to conform to the UEFI 2.0 specification.
306 This library function abstracts initializing a device path node.
307 Initialize the MEDIA_FW_VOL_FILEPATH_DEVICE_PATH data structure. This device
308 path changed in the DXE CIS version 0.92 in a non back ward compatible way to
309 not conflict with the UEFI 2.0 specification. This function abstracts the
310 differences from the caller.
311 If FvDevicePathNode is NULL, then ASSERT().
312 If NameGuid is NULL, then ASSERT().
313
314 @param FvDevicePathNode The pointer to a FV device path node to initialize
315 @param NameGuid FV file name to use in FvDevicePathNode
316
317 **/
318 VOID
319 EFIAPI
320 EfiInitializeFwVolDevicepathNode (
321 IN OUT MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvDevicePathNode,
322 IN CONST EFI_GUID *NameGuid
323 )
324 {
325 ASSERT (FvDevicePathNode != NULL);
326 ASSERT (NameGuid != NULL);
327
328 //
329 // Use the new Device path that does not conflict with the UEFI
330 //
331 FvDevicePathNode->Header.Type = MEDIA_DEVICE_PATH;
332 FvDevicePathNode->Header.SubType = MEDIA_PIWG_FW_FILE_DP;
333 SetDevicePathNodeLength (&FvDevicePathNode->Header, sizeof (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH));
334
335 CopyGuid (&FvDevicePathNode->FvFileName, NameGuid);
336 }
337