]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/UefiLib/UefiNotTiano.c
PeiSmbusLib & DxeSmbusLib
[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 (R8.5/EFI 1.10) and new (R9/UEFI 2.0) way.
7
8 Copyright (c) 2006, Intel Corporation<BR>
9 All rights reserved. This program and the accompanying materials
10 are licensed and made available under the terms and conditions of the BSD License
11 which accompanies this distribution. The full text of the license may be found at
12 http://opensource.org/licenses/bsd-license.php
13
14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
15 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16
17 **/
18
19
20
21 /**
22 Create a Legacy Boot Event.
23
24 Tiano extended the CreateEvent Type enum to add a legacy boot event type.
25 This was bad as Tiano did not own the enum. In UEFI 2.0 CreateEventEx was
26 added and now it's possible to not voilate the UEFI specification by
27 declaring a GUID for the legacy boot event class. This library supports
28 the R8.5/EFI 1.10 form and R9/UEFI 2.0 form and allows common code to
29 work both ways.
30
31 @param LegacyBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex).
32
33 @retval EFI_SUCCESS Event was created.
34 @retval Other Event was not created.
35
36 **/
37 EFI_STATUS
38 EFIAPI
39 EfiCreateEventLegacyBoot (
40 OUT EFI_EVENT *LegacyBootEvent
41 )
42 {
43 EFI_STATUS Status;
44
45 ASSERT (LegacyBootEvent != NULL);
46
47 #if (EFI_SPECIFICATION_VERSION < 0x00020000)
48 //
49 // prior to UEFI 2.0 use Tiano extension to EFI
50 //
51 Status = gBS->CreateEvent (
52 EFI_EVENT_SIGNAL_LEGACY_BOOT | EFI_EVENT_NOTIFY_SIGNAL_ALL,
53 EFI_TPL_CALLBACK,
54 NULL,
55 NULL,
56 LegacyBootEvent
57 );
58 #else
59 //
60 // For UEFI 2.0 and the future use an Event Group
61 //
62 Status = gBS->CreateEventEx (
63 EVENT_NOTIFY_SIGNAL,
64 EFI_TPL_CALLBACK,
65 NULL,
66 NULL,
67 &gEfiEventLegacyBootGuid,
68 LegacyBootEvent
69 );
70 #endif
71 return Status;
72 }
73
74
75
76 /**
77 Create a Read to Boot Event.
78
79 Tiano extended the CreateEvent Type enum to add a ready to boot event type.
80 This was bad as Tiano did not own the enum. In UEFI 2.0 CreateEventEx was
81 added and now it's possible to not voilate the UEFI specification and use
82 the ready to boot event class defined in UEFI 2.0. This library supports
83 the R8.5/EFI 1.10 form and R9/UEFI 2.0 form and allows common code to
84 work both ways.
85
86 @param LegacyBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex).
87
88 @retval EFI_SUCCESS Event was created.
89 @retval Other Event was not created.
90
91 **/
92 EFI_STATUS
93 EFIAPI
94 EfiCreateEventReadyToBoot (
95 OUT EFI_EVENT *ReadyToBootEvent
96 )
97 {
98 EFI_STATUS Status;
99
100 ASSERT (ReadyToBootEvent != NULL);
101
102 #if (EFI_SPECIFICATION_VERSION < 0x00020000)
103 //
104 // prior to UEFI 2.0 use Tiano extension to EFI
105 //
106 Status = gBS->CreateEvent (
107 EFI_EVENT_SIGNAL_READY_TO_BOOT | EFI_EVENT_NOTIFY_SIGNAL_ALL,
108 EFI_TPL_CALLBACK,
109 NULL,
110 NULL,
111 ReadyToBootEvent
112 );
113 #else
114 //
115 // For UEFI 2.0 and the future use an Event Group
116 //
117 Status = gBS->CreateEventEx (
118 EVENT_NOTIFY_SIGNAL,
119 EFI_TPL_CALLBACK,
120 NULL,
121 NULL,
122 &gEfiEventReadyToBootGuid,
123 ReadyToBootEvent
124 );
125 #endif
126
127 return Status;
128 }
129
130
131 /**
132 Signal a Ready to Boot Event.
133
134 Create a Ready to Boot Event. Signal it and close it. This causes other
135 events of the same event group to be signaled in other modules.
136
137 **/
138 VOID
139 EFIAPI
140 EfiSignalEventReadyToBoot (
141 VOID
142 )
143 {
144 EFI_STATUS Status;
145 EFI_EVENT ReadyToBootEvent;
146
147 Status = EfiCreateEventReadyToBoot (&ReadyToBootEvent);
148 if (!EFI_ERROR (Status)) {
149 gBS->SignalEvent (ReadyToBootEvent);
150 gBS->CloseEvent (ReadyToBootEvent);
151 }
152 }
153
154 /**
155 Signal a Legacy Boot Event.
156
157 Create a legacy Boot Event. Signal it and close it. This causes other
158 events of the same event group to be signaled in other modules.
159
160 **/
161 VOID
162 EFIAPI
163 EfiSignalEventLegacyBoot (
164 VOID
165 )
166 {
167 EFI_STATUS Status;
168 EFI_EVENT LegacyBootEvent;
169
170 Status = EfiCreateEventLegacyBoot (&LegacyBootEvent);
171 if (!EFI_ERROR (Status)) {
172 gBS->SignalEvent (LegacyBootEvent);
173 gBS->CloseEvent (LegacyBootEvent);
174 }
175 }
176
177
178 /**
179 Check to see if the Firmware Volume (FV) Media Device Path is valid
180
181 Tiano extended the EFI 1.10 device path nodes. Tiano does not own this enum
182 so as we move to UEFI 2.0 support we must use a mechanism that conforms with
183 the UEFI 2.0 specification to define the FV device path. An UEFI GUIDed
184 device path is defined for PIWG extensions of device path. If the code
185 is compiled to conform with the UEFI 2.0 specification use the new device path
186 else use the old form for backwards compatability. The return value to this
187 function points to a location in FvDevicePathNode and it does not allocate
188 new memory for the GUID pointer that is returned.
189
190 @param FvDevicePathNode Pointer to FV device path to check.
191
192 @retval NULL FvDevicePathNode is not valid.
193 @retval Other FvDevicePathNode is valid and pointer to NameGuid was returned.
194
195 **/
196 EFI_GUID *
197 EFIAPI
198 EfiGetNameGuidFromFwVolDevicePathNode (
199 IN CONST MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvDevicePathNode
200 )
201 {
202 ASSERT (FvDevicePathNode != NULL);
203
204 #if (EFI_SPECIFICATION_VERSION < 0x00020000)
205 //
206 // Use old Device Path that conflicts with UEFI
207 //
208 if (DevicePathType (&FvDevicePathNode->Header) == MEDIA_DEVICE_PATH ||
209 DevicePathSubType (&FvDevicePathNode->Header) == MEDIA_FV_FILEPATH_DP) {
210 return (EFI_GUID *) &FvDevicePathNode->NameGuid;
211 }
212
213 #else
214 //
215 // Use the new Device path that does not conflict with the UEFI
216 //
217 if (FvDevicePathNode->Piwg.Header.Type == MEDIA_DEVICE_PATH ||
218 FvDevicePathNode->Piwg.Header.SubType == MEDIA_VENDOR_DP) {
219 if (CompareGuid (&gEfiFrameworkDevicePathGuid, &FvDevicePathNode->Piwg.PiwgSpecificDevicePath)) {
220 if (FvDevicePathNode->Piwg.Type == PIWG_MEDIA_FW_VOL_FILEPATH_DEVICE_PATH_TYPE) {
221 return (EFI_GUID *) &FvDevicePathNode->NameGuid;
222 }
223 }
224 }
225 #endif
226 return NULL;
227 }
228
229
230 /**
231 Initialize a Firmware Volume (FV) Media Device Path node.
232
233 Tiano extended the EFI 1.10 device path nodes. Tiano does not own this enum
234 so as we move to UEFI 2.0 support we must use a mechanism that conforms with
235 the UEFI 2.0 specification to define the FV device path. An UEFI GUIDed
236 device path is defined for PIWG extensions of device path. If the code
237 is compiled to conform with the UEFI 2.0 specification use the new device path
238 else use the old form for backwards compatability.
239
240 @param FvDevicePathNode Pointer to a FV device path node to initialize
241 @param NameGuid FV file name to use in FvDevicePathNode
242
243 **/
244 VOID
245 EFIAPI
246 EfiInitializeFwVolDevicepathNode (
247 IN OUT MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvDevicePathNode,
248 IN CONST EFI_GUID *NameGuid
249 )
250 {
251 ASSERT (FvDevicePathNode != NULL);
252 ASSERT (NameGuid != NULL);
253
254 #if (EFI_SPECIFICATION_VERSION < 0x00020000)
255 //
256 // Use old Device Path that conflicts with UEFI
257 //
258 FvDevicePathNode->Header.Type = MEDIA_DEVICE_PATH;
259 FvDevicePathNode->Header.SubType = MEDIA_FV_FILEPATH_DP;
260 SetDevicePathNodeLength (&FvDevicePathNode->Header, sizeof (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH));
261
262 #else
263 //
264 // Use the new Device path that does not conflict with the UEFI
265 //
266 FvDevicePathNode->Piwg.Header.Type = MEDIA_DEVICE_PATH;
267 FvDevicePathNode->Piwg.Header.SubType = MEDIA_VENDOR_DP;
268 SetDevicePathNodeLength (&FvDevicePathNode->Piwg.Header, sizeof (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH));
269
270 //
271 // Add the GUID for generic PIWG device paths
272 //
273 CopyGuid (&FvDevicePathNode->Piwg.PiwgSpecificDevicePath, &gEfiFrameworkDevicePathGuid);
274
275 //
276 // Add in the FW Vol File Path PIWG defined inforation
277 //
278 FvDevicePathNode->Piwg.Type = PIWG_MEDIA_FW_VOL_FILEPATH_DEVICE_PATH_TYPE;
279
280 #endif
281
282 CopyGuid (&FvDevicePathNode->NameGuid, NameGuid);
283
284 }
285