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