]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Foundation/Library/Dxe/EfiDriverLib/Event.c
c4fd2afbbde39ee351b8460c09b9e102c66277c2
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / Dxe / EfiDriverLib / Event.c
1 /*++
2
3 Copyright (c) 2004 - 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 Event.c
15
16 Abstract:
17
18 Support for Event lib fucntions.
19
20 --*/
21
22 #include "Tiano.h"
23 #include "EfiDriverLib.h"
24
25 EFI_EVENT
26 EfiLibCreateProtocolNotifyEvent (
27 IN EFI_GUID *ProtocolGuid,
28 IN EFI_TPL NotifyTpl,
29 IN EFI_EVENT_NOTIFY NotifyFunction,
30 IN VOID *NotifyContext,
31 OUT VOID **Registration
32 )
33 /*++
34
35 Routine Description:
36
37 Create a protocol notification event and return it.
38
39 Arguments:
40
41 ProtocolGuid - Protocol to register notification event on.
42
43 NotifyTpl - Maximum TPL to single the NotifyFunction.
44
45 NotifyFunction - EFI notification routine.
46
47 NotifyContext - Context passed into Event when it is created.
48
49 Registration - Registration key returned from RegisterProtocolNotify().
50
51 Returns:
52
53 The EFI_EVENT that has been registered to be signaled when a ProtocolGuid
54 is added to the system.
55
56 --*/
57 {
58 EFI_STATUS Status;
59 EFI_EVENT Event;
60
61 //
62 // Create the event
63 //
64
65 Status = gBS->CreateEvent (
66 EFI_EVENT_NOTIFY_SIGNAL,
67 NotifyTpl,
68 NotifyFunction,
69 NotifyContext,
70 &Event
71 );
72 ASSERT (!EFI_ERROR (Status));
73
74 //
75 // Register for protocol notifactions on this event
76 //
77
78 Status = gBS->RegisterProtocolNotify (
79 ProtocolGuid,
80 Event,
81 Registration
82 );
83
84 ASSERT (!EFI_ERROR (Status));
85
86 //
87 // Kick the event so we will perform an initial pass of
88 // current installed drivers
89 //
90
91 gBS->SignalEvent (Event);
92 return Event;
93 }
94
95 EFI_STATUS
96 EfiLibNamedEventListen (
97 IN EFI_GUID * Name,
98 IN EFI_TPL NotifyTpl,
99 IN EFI_EVENT_NOTIFY NotifyFunction,
100 IN VOID *NotifyContext
101 )
102 /*++
103
104 Routine Description:
105 Listenes to signals on the name.
106 EfiLibNamedEventSignal() signals the event.
107
108 NOTE: For now, the named listening/signalling is implemented
109 on a protocol interface being installed and uninstalled.
110 In the future, this maybe implemented based on a dedicated mechanism.
111
112 Arguments:
113 Name - Name to register the listener on.
114 NotifyTpl - Maximum TPL to singnal the NotifyFunction.
115 NotifyFunction - The listener routine.
116 NotifyContext - Context passed into the listener routine.
117
118 Returns:
119 EFI_SUCCESS if successful.
120
121 --*/
122 {
123 EFI_STATUS Status;
124 EFI_EVENT Event;
125 VOID *RegistrationLocal;
126
127 //
128 // Create event
129 //
130 Status = gBS->CreateEvent (
131 EFI_EVENT_NOTIFY_SIGNAL,
132 NotifyTpl,
133 NotifyFunction,
134 NotifyContext,
135 &Event
136 );
137 ASSERT_EFI_ERROR (Status);
138
139 Status = gBS->RegisterProtocolNotify (
140 Name,
141 Event,
142 &RegistrationLocal
143 );
144 ASSERT_EFI_ERROR (Status);
145
146 return EFI_SUCCESS;
147 }
148
149 EFI_STATUS
150 EfiLibNamedEventSignal (
151 IN EFI_GUID *Name
152 )
153 /*++
154
155 Routine Description:
156 Signals a named event. All registered listeners will run.
157 The listeners should register using EfiLibNamedEventListen() function.
158
159 NOTE: For now, the named listening/signalling is implemented
160 on a protocol interface being installed and uninstalled.
161 In the future, this maybe implemented based on a dedicated mechanism.
162
163 Arguments:
164 Name - Name to perform the signaling on. The name is a GUID.
165
166 Returns:
167 EFI_SUCCESS if successfull.
168
169 --*/
170 {
171 EFI_STATUS Status;
172 EFI_HANDLE Handle;
173
174 Handle = NULL;
175 Status = gBS->InstallProtocolInterface (
176 &Handle,
177 Name,
178 EFI_NATIVE_INTERFACE,
179 NULL
180 );
181 ASSERT_EFI_ERROR (Status);
182
183 Status = gBS->UninstallProtocolInterface (
184 Handle,
185 Name,
186 NULL
187 );
188 ASSERT_EFI_ERROR (Status);
189
190 return EFI_SUCCESS;
191 }
192
193 static
194 VOID
195 EFIAPI
196 EventNotifySignalAllNullEvent (
197 IN EFI_EVENT Event,
198 IN VOID *Context
199 )
200 {
201 //
202 // This null event is a size efficent way to enusre that
203 // EFI_EVENT_NOTIFY_SIGNAL_ALL is error checked correctly.
204 // EFI_EVENT_NOTIFY_SIGNAL_ALL is now mapped into
205 // CreateEventEx() and this function is used to make the
206 // old error checking in CreateEvent() for Tiano extensions
207 // function.
208 //
209 return;
210 }
211
212
213
214 EFI_STATUS
215 EFIAPI
216 EfiCreateEventLegacyBoot (
217 IN EFI_TPL NotifyTpl,
218 IN EFI_EVENT_NOTIFY NotifyFunction,
219 IN VOID *NotifyContext,
220 OUT EFI_EVENT *LegacyBootEvent
221 )
222 /*++
223
224 Routine Description:
225 Create a Legacy Boot Event.
226 Tiano extended the CreateEvent Type enum to add a legacy boot event type.
227 This was bad as Tiano did not own the enum. In UEFI 2.0 CreateEventEx was
228 added and now it's possible to not voilate the UEFI specification by
229 declaring a GUID for the legacy boot event class. This library supports
230 the R8.5/EFI 1.10 form and R8.6/UEFI 2.0 form and allows common code to
231 work both ways.
232
233 Arguments:
234 LegacyBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex)
235
236 Returns:
237 EFI_SUCCESS Event was created.
238 Other Event was not created.
239
240 --*/
241 {
242 EFI_STATUS Status;
243 UINT32 EventType;
244 EFI_EVENT_NOTIFY WorkerNotifyFunction;
245
246 if (gST->Hdr.Revision < 0x00020000) {
247
248 if (NotifyFunction == NULL) {
249 EventType = EFI_EVENT_SIGNAL_LEGACY_BOOT | EFI_EVENT_NOTIFY_SIGNAL_ALL;
250 } else {
251 EventType = EFI_EVENT_SIGNAL_LEGACY_BOOT;
252 }
253 WorkerNotifyFunction = NotifyFunction;
254
255 //
256 // prior to UEFI 2.0 use Tiano extension to EFI
257 //
258 Status = gBS->CreateEvent (
259 EventType,
260 NotifyTpl,
261 WorkerNotifyFunction,
262 NotifyContext,
263 LegacyBootEvent
264 );
265 } else {
266
267 EventType = EFI_EVENT_NOTIFY_SIGNAL;
268 if (NotifyFunction == NULL) {
269 //
270 // CreatEventEx will check NotifyFunction is NULL or not
271 //
272 WorkerNotifyFunction = EventNotifySignalAllNullEvent;
273 } else {
274 WorkerNotifyFunction = NotifyFunction;
275 }
276
277 //
278 // For UEFI 2.0 and the future use an Event Group
279 //
280 Status = gBS->CreateEventEx (
281 EventType,
282 NotifyTpl,
283 WorkerNotifyFunction,
284 NotifyContext,
285 &gEfiEventLegacyBootGuid,
286 LegacyBootEvent
287 );
288 }
289
290 return Status;
291 }
292
293 EFI_STATUS
294 EFIAPI
295 EfiCreateEventReadyToBoot (
296 IN EFI_TPL NotifyTpl,
297 IN EFI_EVENT_NOTIFY NotifyFunction,
298 IN VOID *NotifyContext,
299 OUT EFI_EVENT *ReadyToBootEvent
300 )
301 /*++
302
303 Routine Description:
304 Create a Read to Boot Event.
305
306 Tiano extended the CreateEvent Type enum to add a ready to boot event type.
307 This was bad as Tiano did not own the enum. In UEFI 2.0 CreateEventEx was
308 added and now it's possible to not voilate the UEFI specification and use
309 the ready to boot event class defined in UEFI 2.0. This library supports
310 the R8.5/EFI 1.10 form and R8.6/UEFI 2.0 form and allows common code to
311 work both ways.
312
313 Arguments:
314 @param LegacyBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex)
315
316 Return:
317 EFI_SUCCESS - Event was created.
318 Other - Event was not created.
319
320 --*/
321 {
322 EFI_STATUS Status;
323 UINT32 EventType;
324 EFI_EVENT_NOTIFY WorkerNotifyFunction;
325
326 if (gST->Hdr.Revision < 0x00020000) {
327
328 if (NotifyFunction == NULL) {
329 EventType = EFI_EVENT_SIGNAL_READY_TO_BOOT | EFI_EVENT_NOTIFY_SIGNAL_ALL;
330 } else {
331 EventType = EFI_EVENT_SIGNAL_READY_TO_BOOT;
332 }
333 WorkerNotifyFunction = NotifyFunction;
334
335 //
336 // prior to UEFI 2.0 use Tiano extension to EFI
337 //
338 Status = gBS->CreateEvent (
339 EventType,
340 NotifyTpl,
341 WorkerNotifyFunction,
342 NotifyContext,
343 ReadyToBootEvent
344 );
345 } else {
346
347 EventType = EFI_EVENT_NOTIFY_SIGNAL;
348 if (NotifyFunction == NULL) {
349 //
350 // CreatEventEx will check NotifyFunction is NULL or not
351 //
352 WorkerNotifyFunction = EventNotifySignalAllNullEvent;
353 } else {
354 WorkerNotifyFunction = NotifyFunction;
355 }
356
357 //
358 // For UEFI 2.0 and the future use an Event Group
359 //
360 Status = gBS->CreateEventEx (
361 EventType,
362 NotifyTpl,
363 WorkerNotifyFunction,
364 NotifyContext,
365 &gEfiEventReadyToBootGuid,
366 ReadyToBootEvent
367 );
368 }
369 return Status;
370 }