]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/UefiLib/UefiNotTiano.c
Removed CommonHeader.h generated file from the MdePkg.
[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 (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 - 2007, Intel Corporation<BR>
10 All rights reserved. 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 common header file for this module.
23 //
24 #include "UefiLibInternal.h"
25
26 /**
27 An empty function to pass error checking of CreateEventEx ().
28
29 This empty function ensures that EFI_EVENT_NOTIFY_SIGNAL_ALL is error
30 checked correctly since it is now mapped into CreateEventEx() in UEFI 2.0.
31
32 **/
33 STATIC
34 VOID
35 EFIAPI
36 InternalEmptyFuntion (
37 IN EFI_EVENT Event,
38 IN VOID *Context
39 )
40 {
41 return;
42 }
43
44 /**
45 Create a Legacy Boot Event.
46
47 Tiano extended the CreateEvent Type enum to add a legacy boot event type.
48 This was bad as Tiano did not own the enum. In UEFI 2.0 CreateEventEx was
49 added and now it's possible to not voilate the UEFI specification by
50 declaring a GUID for the legacy boot event class. This library supports
51 the EDK/EFI 1.10 form and EDK II/UEFI 2.0 form and allows common code to
52 work both ways.
53
54 @param LegacyBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex).
55
56 @retval EFI_SUCCESS Event was created.
57 @retval Other Event was not created.
58
59 **/
60 EFI_STATUS
61 EFIAPI
62 EfiCreateEventLegacyBoot (
63 OUT EFI_EVENT *LegacyBootEvent
64 )
65 {
66 return EfiCreateEventLegacyBootEx (
67 TPL_CALLBACK,
68 InternalEmptyFuntion,
69 NULL,
70 LegacyBootEvent
71 );
72 }
73
74 /**
75 Create an EFI event in the Legacy Boot Event Group and allows
76 the caller to specify a notification function.
77
78 This function abstracts the creation of the Legacy Boot Event.
79 The Framework moved from a proprietary to UEFI 2.0 based mechanism.
80 This library abstracts the caller from how this event is created to prevent
81 to code form having to change with the version of the specification supported.
82 If LegacyBootEvent is NULL, then ASSERT().
83
84 @param NotifyTpl The task priority level of the event.
85 @param NotifyFunction The notification function to call when the event is signaled.
86 @param NotifyContext The content to pass to NotifyFunction when the event is signaled.
87 @param LegacyBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex).
88
89 @retval EFI_SUCCESS Event was created.
90 @retval Other Event was not created.
91
92 **/
93 EFI_STATUS
94 EFIAPI
95 EfiCreateEventLegacyBootEx (
96 IN EFI_TPL NotifyTpl,
97 IN EFI_EVENT_NOTIFY NotifyFunction, OPTIONAL
98 IN VOID *NotifyContext, OPTIONAL
99 OUT EFI_EVENT *LegacyBootEvent
100 )
101 {
102 EFI_STATUS Status;
103
104 ASSERT (LegacyBootEvent != NULL);
105
106 if (gST->Hdr.Revision < EFI_2_00_SYSTEM_TABLE_REVISION) {
107 DEBUG ((EFI_D_ERROR, "EFI1.1 can't support LegacyBootEvent!"));
108 ASSERT (FALSE);
109
110 return EFI_UNSUPPORTED;
111 } else {
112 //
113 // For UEFI 2.0 and the future use an Event Group
114 //
115 Status = gBS->CreateEventEx (
116 EVT_NOTIFY_SIGNAL,
117 NotifyTpl,
118 NotifyFunction,
119 NotifyContext,
120 &gEfiEventLegacyBootGuid,
121 LegacyBootEvent
122 );
123 }
124
125 return Status;
126 }
127
128 /**
129 Create a Read to Boot Event.
130
131 Tiano extended the CreateEvent Type enum to add a ready to boot event type.
132 This was bad as Tiano did not own the enum. In UEFI 2.0 CreateEventEx was
133 added and now it's possible to not voilate the UEFI specification and use
134 the ready to boot event class defined in UEFI 2.0. This library supports
135 the EDK/EFI 1.10 form and EDK II/UEFI 2.0 form and allows common code to
136 work both ways.
137
138 @param LegacyBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex).
139
140 @retval EFI_SUCCESS Event was created.
141 @retval Other Event was not created.
142
143 **/
144 EFI_STATUS
145 EFIAPI
146 EfiCreateEventReadyToBoot (
147 OUT EFI_EVENT *ReadyToBootEvent
148 )
149 {
150 return EfiCreateEventReadyToBootEx (
151 TPL_CALLBACK,
152 InternalEmptyFuntion,
153 NULL,
154 ReadyToBootEvent
155 );
156 }
157
158 /**
159 Create an EFI event in the Ready To Boot Event Group and allows
160 the caller to specify a notification function.
161
162 This function abstracts the creation of the Ready to Boot Event.
163 The Framework moved from a proprietary to UEFI 2.0 based mechanism.
164 This library abstracts the caller from how this event is created to prevent
165 to code form having to change with the version of the specification supported.
166 If ReadyToBootEvent is NULL, then ASSERT().
167
168 @param NotifyTpl The task priority level of the event.
169 @param NotifyFunction The notification function to call when the event is signaled.
170 @param NotifyContext The content to pass to NotifyFunction when the event is signaled.
171 @param LegacyBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex).
172
173 @retval EFI_SUCCESS Event was created.
174 @retval Other Event was not created.
175
176 **/
177 EFI_STATUS
178 EFIAPI
179 EfiCreateEventReadyToBootEx (
180 IN EFI_TPL NotifyTpl,
181 IN EFI_EVENT_NOTIFY NotifyFunction, OPTIONAL
182 IN VOID *NotifyContext, OPTIONAL
183 OUT EFI_EVENT *ReadyToBootEvent
184 )
185 {
186 EFI_STATUS Status;
187
188 ASSERT (ReadyToBootEvent != NULL);
189
190 if (gST->Hdr.Revision < EFI_2_00_SYSTEM_TABLE_REVISION) {
191 DEBUG ((EFI_D_ERROR, "EFI1.1 can't support ReadyToBootEvent!"));
192 ASSERT (FALSE);
193
194 return EFI_UNSUPPORTED;
195 } else {
196 //
197 // For UEFI 2.0 and the future use an Event Group
198 //
199 Status = gBS->CreateEventEx (
200 EVT_NOTIFY_SIGNAL,
201 NotifyTpl,
202 NotifyFunction,
203 NotifyContext,
204 &gEfiEventReadyToBootGuid,
205 ReadyToBootEvent
206 );
207 }
208
209 return Status;
210 }
211
212
213 /**
214 Signal a Ready to Boot Event.
215
216 Create a Ready to Boot Event. Signal it and close it. This causes other
217 events of the same event group to be signaled in other modules.
218
219 **/
220 VOID
221 EFIAPI
222 EfiSignalEventReadyToBoot (
223 VOID
224 )
225 {
226 EFI_STATUS Status;
227 EFI_EVENT ReadyToBootEvent;
228
229 Status = EfiCreateEventReadyToBoot (&ReadyToBootEvent);
230 if (!EFI_ERROR (Status)) {
231 gBS->SignalEvent (ReadyToBootEvent);
232 gBS->CloseEvent (ReadyToBootEvent);
233 }
234 }
235
236 /**
237 Signal a Legacy Boot Event.
238
239 Create a legacy Boot Event. Signal it and close it. This causes other
240 events of the same event group to be signaled in other modules.
241
242 **/
243 VOID
244 EFIAPI
245 EfiSignalEventLegacyBoot (
246 VOID
247 )
248 {
249 EFI_STATUS Status;
250 EFI_EVENT LegacyBootEvent;
251
252 Status = EfiCreateEventLegacyBoot (&LegacyBootEvent);
253 if (!EFI_ERROR (Status)) {
254 gBS->SignalEvent (LegacyBootEvent);
255 gBS->CloseEvent (LegacyBootEvent);
256 }
257 }
258
259
260 /**
261 Check to see if the Firmware Volume (FV) Media Device Path is valid
262
263 Tiano extended the EFI 1.10 device path nodes. Tiano does not own this enum
264 so as we move to UEFI 2.0 support we must use a mechanism that conforms with
265 the UEFI 2.0 specification to define the FV device path. An UEFI GUIDed
266 device path is defined for Tiano extensions of device path. If the code
267 is compiled to conform with the UEFI 2.0 specification use the new device path
268 else use the old form for backwards compatability. The return value to this
269 function points to a location in FvDevicePathNode and it does not allocate
270 new memory for the GUID pointer that is returned.
271
272 @param FvDevicePathNode Pointer to FV device path to check.
273
274 @retval NULL FvDevicePathNode is not valid.
275 @retval Other FvDevicePathNode is valid and pointer to NameGuid was returned.
276
277 **/
278 EFI_GUID*
279 EFIAPI
280 EfiGetNameGuidFromFwVolDevicePathNode (
281 IN CONST MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvFileDevicePathNode
282 )
283 {
284 ASSERT (FvFileDevicePathNode != NULL);
285
286 if (FvFileDevicePathNode->Header.Type == MEDIA_DEVICE_PATH &&
287 FvFileDevicePathNode->Header.SubType == MEDIA_PIWG_FW_FILE_DP
288 ) {
289 return (EFI_GUID *) &FvFileDevicePathNode->FvFileName;
290 }
291
292 return NULL;
293 }
294
295
296 /**
297 Initialize a Firmware Volume (FV) Media Device Path node.
298
299 Tiano extended the EFI 1.10 device path nodes. Tiano does not own this enum
300 so as we move to UEFI 2.0 support we must use a mechanism that conforms with
301 the UEFI 2.0 specification to define the FV device path. An UEFI GUIDed
302 device path is defined for Tiano extensions of device path. If the code
303 is compiled to conform with the UEFI 2.0 specification use the new device path
304 else use the old form for backwards compatability.
305
306 @param FvDevicePathNode Pointer to a FV device path node to initialize
307 @param NameGuid FV file name to use in FvDevicePathNode
308
309 **/
310 VOID
311 EFIAPI
312 EfiInitializeFwVolDevicepathNode (
313 IN OUT MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvFileDevicePathNode,
314 IN CONST EFI_GUID *NameGuid
315 )
316 {
317 ASSERT (FvFileDevicePathNode != NULL);
318 ASSERT (NameGuid != NULL);
319
320 //
321 // Use the new Device path that does not conflict with the UEFI
322 //
323 FvFileDevicePathNode->Header.Type = MEDIA_DEVICE_PATH;
324 FvFileDevicePathNode->Header.SubType = MEDIA_PIWG_FW_FILE_DP;
325 SetDevicePathNodeLength (&FvFileDevicePathNode->Header, sizeof (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH));
326
327 CopyGuid (&FvFileDevicePathNode->FvFileName, NameGuid);
328 }
329