]>
Commit | Line | Data |
---|---|---|
3eb9473e | 1 | /*++\r |
2 | \r | |
8598a1ed | 3 | Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>\r |
4ea9375a | 4 | This program and the accompanying materials\r |
3eb9473e | 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 "EfiRuntimeLib.h"\r | |
24 | \r | |
25 | EFI_EVENT\r | |
26 | RtEfiLibCreateProtocolNotifyEvent (\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 | Status = gBS->CreateEvent (\r | |
65 | EFI_EVENT_NOTIFY_SIGNAL,\r | |
66 | NotifyTpl,\r | |
67 | NotifyFunction,\r | |
68 | NotifyContext,\r | |
69 | &Event\r | |
70 | );\r | |
71 | ASSERT (!EFI_ERROR (Status));\r | |
72 | \r | |
73 | //\r | |
74 | // Register for protocol notifactions on this event\r | |
75 | //\r | |
76 | Status = gBS->RegisterProtocolNotify (\r | |
77 | ProtocolGuid,\r | |
78 | Event,\r | |
79 | Registration\r | |
80 | );\r | |
81 | \r | |
82 | ASSERT (!EFI_ERROR (Status));\r | |
83 | \r | |
84 | //\r | |
85 | // Kick the event so we will perform an initial pass of\r | |
86 | // current installed drivers\r | |
87 | //\r | |
88 | gBS->SignalEvent (Event);\r | |
89 | return Event;\r | |
90 | }\r | |
91 | \r | |
92 | EFI_STATUS\r | |
93 | EfiLibGetSystemConfigurationTable (\r | |
94 | IN EFI_GUID *TableGuid,\r | |
95 | IN OUT VOID **Table\r | |
96 | )\r | |
97 | /*++\r | |
98 | \r | |
99 | Routine Description:\r | |
100 | \r | |
101 | Return the EFI 1.0 System Tabl entry with TableGuid\r | |
102 | \r | |
103 | Arguments:\r | |
104 | \r | |
105 | TableGuid - Name of entry to return in the system table\r | |
106 | Table - Pointer in EFI system table associated with TableGuid\r | |
107 | \r | |
108 | Returns:\r | |
109 | \r | |
110 | EFI_SUCCESS - Table returned;\r | |
111 | EFI_NOT_FOUND - TableGuid not in EFI system table\r | |
112 | \r | |
113 | --*/\r | |
114 | {\r | |
115 | UINTN Index;\r | |
116 | \r | |
117 | for (Index = 0; Index < gST->NumberOfTableEntries; Index++) {\r | |
118 | if (EfiCompareGuid (TableGuid, &(gST->ConfigurationTable[Index].VendorGuid))) {\r | |
119 | *Table = gST->ConfigurationTable[Index].VendorTable;\r | |
120 | return EFI_SUCCESS;\r | |
121 | }\r | |
122 | }\r | |
123 | \r | |
124 | return EFI_NOT_FOUND;\r | |
125 | }\r | |
126 | \r | |
127 | EFI_STATUS\r | |
128 | EfiConvertList (\r | |
129 | IN UINTN DebugDisposition,\r | |
130 | IN OUT EFI_LIST_ENTRY *ListHead\r | |
131 | )\r | |
132 | /*++\r | |
133 | \r | |
134 | Routine Description:\r | |
135 | \r | |
136 | Conver the standard Lib double linked list to a virtual mapping.\r | |
137 | \r | |
138 | Arguments:\r | |
139 | \r | |
140 | DebugDisposition - Argument to EfiConvertPointer (EFI 1.0 API)\r | |
141 | \r | |
142 | ListHead - Head of linked list to convert\r | |
143 | \r | |
144 | Returns:\r | |
145 | \r | |
146 | EFI_SUCCESS\r | |
147 | \r | |
148 | --*/\r | |
149 | {\r | |
150 | EFI_LIST_ENTRY *Link;\r | |
151 | EFI_LIST_ENTRY *NextLink;\r | |
152 | \r | |
153 | //\r | |
154 | // Convert all the ForwardLink & BackLink pointers in the list\r | |
155 | //\r | |
156 | Link = ListHead;\r | |
157 | do {\r | |
158 | NextLink = Link->ForwardLink;\r | |
159 | \r | |
160 | EfiConvertPointer (\r | |
161 | Link->ForwardLink == ListHead ? DebugDisposition : 0,\r | |
162 | (VOID **) &Link->ForwardLink\r | |
163 | );\r | |
164 | \r | |
165 | EfiConvertPointer (\r | |
166 | Link->BackLink == ListHead ? DebugDisposition : 0,\r | |
167 | (VOID **) &Link->BackLink\r | |
168 | );\r | |
169 | \r | |
170 | Link = NextLink;\r | |
171 | } while (Link != ListHead);\r | |
172 | return EFI_SUCCESS;\r | |
173 | }\r | |
174 | \r | |
175 | #if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r | |
176 | \r | |
177 | STATIC\r | |
178 | VOID\r | |
179 | EFIAPI\r | |
180 | EventNotifySignalAllNullEvent (\r | |
181 | IN EFI_EVENT Event,\r | |
182 | IN VOID *Context\r | |
183 | )\r | |
184 | {\r | |
185 | //\r | |
186 | // This null event is a size efficent way to enusre that \r | |
187 | // EFI_EVENT_NOTIFY_SIGNAL_ALL is error checked correctly.\r | |
188 | // EFI_EVENT_NOTIFY_SIGNAL_ALL is now mapped into \r | |
189 | // CreateEventEx() and this function is used to make the\r | |
190 | // old error checking in CreateEvent() for Tiano extensions\r | |
191 | // function.\r | |
192 | //\r | |
193 | return;\r | |
194 | }\r | |
195 | \r | |
196 | #endif\r | |
197 | \r | |
198 | EFI_STATUS\r | |
199 | EFIAPI\r | |
200 | RtEfiCreateEventLegacyBoot (\r | |
201 | IN EFI_TPL NotifyTpl,\r | |
202 | IN EFI_EVENT_NOTIFY NotifyFunction,\r | |
203 | IN VOID *NotifyContext,\r | |
204 | OUT EFI_EVENT *LegacyBootEvent\r | |
205 | )\r | |
206 | /*++\r | |
207 | \r | |
208 | Routine Description:\r | |
209 | Create a Legacy Boot Event. \r | |
210 | Tiano extended the CreateEvent Type enum to add a legacy boot event type. \r | |
211 | This was bad as Tiano did not own the enum. In UEFI 2.0 CreateEventEx was\r | |
212 | added and now it's possible to not voilate the UEFI specification by \r | |
213 | declaring a GUID for the legacy boot event class. This library supports\r | |
8598a1ed | 214 | the EFI 1.10 form and UEFI 2.0 form and allows common code to work both ways.\r |
3eb9473e | 215 | \r |
216 | Arguments:\r | |
217 | LegacyBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex)\r | |
218 | \r | |
219 | Returns:\r | |
220 | EFI_SUCCESS Event was created.\r | |
221 | Other Event was not created.\r | |
222 | \r | |
223 | --*/\r | |
224 | {\r | |
225 | EFI_STATUS Status;\r | |
226 | UINT32 EventType;\r | |
227 | EFI_EVENT_NOTIFY WorkerNotifyFunction;\r | |
228 | \r | |
229 | #if (EFI_SPECIFICATION_VERSION < 0x00020000)\r | |
230 | \r | |
231 | if (NotifyFunction == NULL) {\r | |
232 | EventType = EFI_EVENT_SIGNAL_LEGACY_BOOT | EFI_EVENT_NOTIFY_SIGNAL_ALL;\r | |
233 | } else {\r | |
234 | EventType = EFI_EVENT_SIGNAL_LEGACY_BOOT;\r | |
235 | }\r | |
236 | WorkerNotifyFunction = NotifyFunction;\r | |
237 | \r | |
238 | //\r | |
239 | // prior to UEFI 2.0 use Tiano extension to EFI\r | |
240 | //\r | |
241 | Status = gBS->CreateEvent (\r | |
242 | EventType,\r | |
243 | NotifyTpl,\r | |
244 | WorkerNotifyFunction,\r | |
245 | NotifyContext,\r | |
246 | LegacyBootEvent\r | |
247 | );\r | |
248 | #else\r | |
249 | \r | |
250 | EventType = EFI_EVENT_NOTIFY_SIGNAL;\r | |
251 | if (NotifyFunction == NULL) {\r | |
252 | //\r | |
253 | // CreatEventEx will check NotifyFunction is NULL or not\r | |
254 | //\r | |
255 | WorkerNotifyFunction = EventNotifySignalAllNullEvent;\r | |
256 | } else {\r | |
257 | WorkerNotifyFunction = NotifyFunction;\r | |
258 | }\r | |
259 | \r | |
260 | //\r | |
261 | // For UEFI 2.0 and the future use an Event Group\r | |
262 | //\r | |
263 | Status = gBS->CreateEventEx (\r | |
264 | EventType,\r | |
265 | NotifyTpl,\r | |
266 | WorkerNotifyFunction,\r | |
267 | NotifyContext,\r | |
268 | &gEfiEventLegacyBootGuid,\r | |
269 | LegacyBootEvent\r | |
270 | );\r | |
271 | #endif\r | |
272 | return Status;\r | |
273 | }\r | |
274 | \r | |
275 | EFI_STATUS\r | |
276 | EFIAPI\r | |
277 | RtEfiCreateEventReadyToBoot (\r | |
278 | IN EFI_TPL NotifyTpl,\r | |
279 | IN EFI_EVENT_NOTIFY NotifyFunction,\r | |
280 | IN VOID *NotifyContext,\r | |
281 | OUT EFI_EVENT *ReadyToBootEvent\r | |
282 | )\r | |
283 | /*++\r | |
284 | \r | |
285 | Routine Description:\r | |
286 | Create a Read to Boot Event. \r | |
287 | \r | |
288 | Tiano extended the CreateEvent Type enum to add a ready to boot event type. \r | |
289 | This was bad as Tiano did not own the enum. In UEFI 2.0 CreateEventEx was\r | |
290 | added and now it's possible to not voilate the UEFI specification and use \r | |
291 | the ready to boot event class defined in UEFI 2.0. This library supports\r | |
8598a1ed | 292 | the EFI 1.10 form and UEFI 2.0 form and allows common code to work both ways.\r |
3eb9473e | 293 | \r |
294 | Arguments:\r | |
295 | ReadyToBootEvent Returns the EFI event returned from gBS->CreateEvent(Ex)\r | |
296 | \r | |
297 | Return:\r | |
298 | EFI_SUCCESS - Event was created.\r | |
299 | Other - Event was not created.\r | |
300 | \r | |
301 | --*/\r | |
302 | {\r | |
303 | EFI_STATUS Status;\r | |
304 | UINT32 EventType;\r | |
305 | EFI_EVENT_NOTIFY WorkerNotifyFunction;\r | |
306 | \r | |
307 | #if (EFI_SPECIFICATION_VERSION < 0x00020000)\r | |
308 | \r | |
309 | if (NotifyFunction == NULL) {\r | |
310 | EventType = EFI_EVENT_SIGNAL_READY_TO_BOOT | EFI_EVENT_NOTIFY_SIGNAL_ALL;\r | |
311 | } else {\r | |
312 | EventType = EFI_EVENT_SIGNAL_READY_TO_BOOT;\r | |
313 | }\r | |
314 | WorkerNotifyFunction = NotifyFunction;\r | |
315 | \r | |
316 | //\r | |
317 | // prior to UEFI 2.0 use Tiano extension to EFI\r | |
318 | //\r | |
319 | Status = gBS->CreateEvent (\r | |
320 | EventType,\r | |
321 | NotifyTpl,\r | |
322 | WorkerNotifyFunction,\r | |
323 | NotifyContext,\r | |
324 | ReadyToBootEvent\r | |
325 | );\r | |
326 | #else\r | |
327 | \r | |
328 | EventType = EFI_EVENT_NOTIFY_SIGNAL;\r | |
329 | if (NotifyFunction == NULL) {\r | |
330 | //\r | |
331 | // CreatEventEx will check NotifyFunction is NULL or not\r | |
332 | //\r | |
333 | WorkerNotifyFunction = EventNotifySignalAllNullEvent;\r | |
334 | } else {\r | |
335 | WorkerNotifyFunction = NotifyFunction;\r | |
336 | }\r | |
337 | \r | |
338 | //\r | |
339 | // For UEFI 2.0 and the future use an Event Group\r | |
340 | //\r | |
341 | Status = gBS->CreateEventEx (\r | |
342 | EventType,\r | |
343 | NotifyTpl,\r | |
344 | WorkerNotifyFunction,\r | |
345 | NotifyContext,\r | |
346 | &gEfiEventReadyToBootGuid,\r | |
347 | ReadyToBootEvent\r | |
348 | );\r | |
349 | #endif\r | |
350 | return Status;\r | |
7ccf38a3 | 351 | }\r |