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