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