event.c revision 1.1.1.2 1 /* $NetBSD: event.c,v 1.1.1.2 2018/08/16 18:17:47 jmcneill Exp $ */
2
3 /*++
4
5 Copyright (c) 1998 Intel Corporation
6
7 Module Name:
8
9 event.c
10
11 Abstract:
12
13
14
15
16 Revision History
17
18 --*/
19
20 #include "lib.h"
21
22
23 EFI_EVENT
24 LibCreateProtocolNotifyEvent (
25 IN EFI_GUID *ProtocolGuid,
26 IN EFI_TPL NotifyTpl,
27 IN EFI_EVENT_NOTIFY NotifyFunction,
28 IN VOID *NotifyContext,
29 OUT VOID *Registration
30 )
31 {
32 EFI_STATUS Status;
33 EFI_EVENT Event;
34
35 //
36 // Create the event
37 //
38
39 Status = uefi_call_wrapper(
40 BS->CreateEvent,
41 5,
42 EVT_NOTIFY_SIGNAL,
43 NotifyTpl,
44 NotifyFunction,
45 NotifyContext,
46 &Event
47 );
48 if ( EFI_ERROR( Status ) ) return NULL ;
49 ASSERT (!EFI_ERROR(Status));
50
51 //
52 // Register for protocol notifactions on this event
53 //
54
55 Status = uefi_call_wrapper(
56 BS->RegisterProtocolNotify,
57 3,
58 ProtocolGuid,
59 Event,
60 Registration
61 );
62 if ( EFI_ERROR( Status ) ) return NULL ;
63 ASSERT (!EFI_ERROR(Status));
64
65 //
66 // Kick the event so we will perform an initial pass of
67 // current installed drivers
68 //
69
70 uefi_call_wrapper(BS->SignalEvent, 1, Event);
71 return Event;
72 }
73
74
75 EFI_STATUS
76 WaitForSingleEvent (
77 IN EFI_EVENT Event,
78 IN UINT64 Timeout OPTIONAL
79 )
80 {
81 EFI_STATUS Status;
82 UINTN Index;
83 EFI_EVENT TimerEvent;
84 EFI_EVENT WaitList[2];
85
86 if (Timeout) {
87 //
88 // Create a timer event
89 //
90
91 Status = uefi_call_wrapper(BS->CreateEvent, 5, EVT_TIMER, 0, NULL, NULL, &TimerEvent);
92 if (!EFI_ERROR(Status)) {
93
94 //
95 // Set the timer event
96 //
97
98 uefi_call_wrapper(BS->SetTimer, 3, TimerEvent, TimerRelative, Timeout);
99
100 //
101 // Wait for the original event or the timer
102 //
103
104 WaitList[0] = Event;
105 WaitList[1] = TimerEvent;
106 Status = uefi_call_wrapper(BS->WaitForEvent, 3, 2, WaitList, &Index);
107 uefi_call_wrapper(BS->CloseEvent, 1, TimerEvent);
108
109 //
110 // If the timer expired, change the return to timed out
111 //
112
113 if (!EFI_ERROR(Status) && Index == 1) {
114 Status = EFI_TIMEOUT;
115 }
116 }
117
118 } else {
119
120 //
121 // No timeout... just wait on the event
122 //
123
124 Status = uefi_call_wrapper(BS->WaitForEvent, 3, 1, &Event, &Index);
125 ASSERT (!EFI_ERROR(Status));
126 ASSERT (Index == 0);
127 }
128
129 return Status;
130 }
131
132 VOID
133 WaitForEventWithTimeout (
134 IN EFI_EVENT Event,
135 IN UINTN Timeout,
136 IN UINTN Row,
137 IN UINTN Column,
138 IN CHAR16 *String,
139 IN EFI_INPUT_KEY TimeoutKey,
140 OUT EFI_INPUT_KEY *Key
141 )
142 {
143 EFI_STATUS Status;
144
145 do {
146 PrintAt (Column, Row, String, Timeout);
147 Status = WaitForSingleEvent (Event, 10000000);
148 if (Status == EFI_SUCCESS) {
149 if (!EFI_ERROR(uefi_call_wrapper(ST->ConIn->ReadKeyStroke, 2, ST->ConIn, Key))) {
150 return;
151 }
152 }
153 } while (Timeout > 0);
154 CopyMem(Key, &TimeoutKey, sizeof(EFI_INPUT_KEY));
155 }
156
157