]> git.proxmox.com Git - mirror_edk2.git/blob - EdkNt32Pkg/Dxe/WinNtThunk/Bus/Uga/WinNtUgaInput.c
Add some definitions for efi event in Uefi/UefiSpec.h to follow spec.
[mirror_edk2.git] / EdkNt32Pkg / Dxe / WinNtThunk / Bus / Uga / WinNtUgaInput.c
1 /*++
2
3 Copyright (c) 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 WinNtUgaInput.c
15
16 Abstract:
17
18 This file produces the Simple Text In for an Uga window.
19
20 This stuff is linked at the hip to the Window, since the window
21 processing is done in a thread kicked off in WinNtUgaImplementation.c
22
23 Since the window information is processed in an other thread we need
24 a keyboard Queue to pass data about. The Simple Text In code just
25 takes data off the Queue. The WinProc message loop takes keyboard input
26 and places it in the Queue.
27
28 --*/
29
30 #include "WinNtUga.h"
31
32 EFI_STATUS
33 UgaPrivateCreateQ (
34 IN UGA_PRIVATE_DATA *Private
35 )
36 /*++
37
38 Routine Description:
39
40 TODO: Add function description
41
42 Arguments:
43
44 Private - TODO: add argument description
45
46 Returns:
47
48 EFI_SUCCESS - TODO: Add description for return value
49
50 --*/
51 {
52 Private->WinNtThunk->InitializeCriticalSection (&Private->QCriticalSection);
53
54 Private->Queue.Front = 0;
55 Private->Queue.Rear = MAX_Q - 1;
56 Private->Queue.Count = 0;
57 return EFI_SUCCESS;
58 }
59
60 EFI_STATUS
61 UgaPrivateDestroyQ (
62 IN UGA_PRIVATE_DATA *Private
63 )
64 /*++
65
66 Routine Description:
67
68 TODO: Add function description
69
70 Arguments:
71
72 Private - TODO: add argument description
73
74 Returns:
75
76 EFI_SUCCESS - TODO: Add description for return value
77
78 --*/
79 {
80 Private->Queue.Count = 0;
81 Private->WinNtThunk->DeleteCriticalSection (&Private->QCriticalSection);
82 return EFI_SUCCESS;
83 }
84
85 EFI_STATUS
86 UgaPrivateAddQ (
87 IN UGA_PRIVATE_DATA *Private,
88 IN EFI_INPUT_KEY Key
89 )
90 /*++
91
92 Routine Description:
93
94 TODO: Add function description
95
96 Arguments:
97
98 Private - TODO: add argument description
99 Key - TODO: add argument description
100
101 Returns:
102
103 EFI_NOT_READY - TODO: Add description for return value
104 EFI_SUCCESS - TODO: Add description for return value
105
106 --*/
107 {
108 Private->WinNtThunk->EnterCriticalSection (&Private->QCriticalSection);
109
110 if (Private->Queue.Count == MAX_Q) {
111 Private->WinNtThunk->LeaveCriticalSection (&Private->QCriticalSection);
112 return EFI_NOT_READY;
113 }
114
115 Private->Queue.Rear = (Private->Queue.Rear + 1) % MAX_Q;
116 Private->Queue.Q[Private->Queue.Rear] = Key;
117 Private->Queue.Count++;
118
119 Private->WinNtThunk->LeaveCriticalSection (&Private->QCriticalSection);
120 return EFI_SUCCESS;
121 }
122
123 EFI_STATUS
124 UgaPrivateDeleteQ (
125 IN UGA_PRIVATE_DATA *Private,
126 OUT EFI_INPUT_KEY *Key
127 )
128 /*++
129
130 Routine Description:
131
132 TODO: Add function description
133
134 Arguments:
135
136 Private - TODO: add argument description
137 Key - TODO: add argument description
138
139 Returns:
140
141 EFI_NOT_READY - TODO: Add description for return value
142 EFI_SUCCESS - TODO: Add description for return value
143
144 --*/
145 {
146 Private->WinNtThunk->EnterCriticalSection (&Private->QCriticalSection);
147
148 if (Private->Queue.Count == 0) {
149 Private->WinNtThunk->LeaveCriticalSection (&Private->QCriticalSection);
150 return EFI_NOT_READY;
151 }
152
153 *Key = Private->Queue.Q[Private->Queue.Front];
154 Private->Queue.Front = (Private->Queue.Front + 1) % MAX_Q;
155 Private->Queue.Count--;
156
157 Private->WinNtThunk->LeaveCriticalSection (&Private->QCriticalSection);
158 return EFI_SUCCESS;
159 }
160
161 EFI_STATUS
162 UgaPrivateCheckQ (
163 IN UGA_PRIVATE_DATA *Private
164 )
165 /*++
166
167 Routine Description:
168
169 TODO: Add function description
170
171 Arguments:
172
173 Private - TODO: add argument description
174
175 Returns:
176
177 EFI_NOT_READY - TODO: Add description for return value
178 EFI_SUCCESS - TODO: Add description for return value
179
180 --*/
181 {
182 if (Private->Queue.Count == 0) {
183 return EFI_NOT_READY;
184 }
185
186 return EFI_SUCCESS;
187 }
188
189 //
190 // Simple Text In implementation.
191 //
192
193 EFI_STATUS
194 EFIAPI
195 WinNtUgaSimpleTextInReset (
196 IN EFI_SIMPLE_TEXT_IN_PROTOCOL *This,
197 IN BOOLEAN ExtendedVerification
198 )
199 /*++
200
201 Routine Description:
202
203 TODO: Add function description
204
205 Arguments:
206
207 This - TODO: add argument description
208 ExtendedVerification - TODO: add argument description
209
210 Returns:
211
212 EFI_SUCCESS - TODO: Add description for return value
213
214 --*/
215 {
216 UGA_PRIVATE_DATA *Private;
217 EFI_INPUT_KEY Key;
218 EFI_TPL OldTpl;
219
220 Private = UGA_PRIVATE_DATA_FROM_TEXT_IN_THIS (This);
221
222 //
223 // Enter critical section
224 //
225 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
226
227 //
228 // A reset is draining the Queue
229 //
230 while (UgaPrivateDeleteQ (Private, &Key) == EFI_SUCCESS)
231 ;
232
233 //
234 // Leave critical section and return
235 //
236 gBS->RestoreTPL (OldTpl);
237 return EFI_SUCCESS;
238 }
239
240 STATIC
241 EFI_STATUS
242 EFIAPI
243 WinNtUgaSimpleTextInReadKeyStroke (
244 IN EFI_SIMPLE_TEXT_IN_PROTOCOL *This,
245 OUT EFI_INPUT_KEY *Key
246 )
247 /*++
248
249 Routine Description:
250
251 TODO: Add function description
252
253 Arguments:
254
255 This - TODO: add argument description
256 Key - TODO: add argument description
257
258 Returns:
259
260 TODO: add return values
261
262 --*/
263 {
264 UGA_PRIVATE_DATA *Private;
265 EFI_STATUS Status;
266 EFI_TPL OldTpl;
267
268 Private = UGA_PRIVATE_DATA_FROM_TEXT_IN_THIS (This);
269
270 //
271 // Enter critical section
272 //
273 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
274
275 Status = UgaPrivateCheckQ (Private);
276 if (!EFI_ERROR (Status)) {
277 //
278 // If a Key press exists try and read it.
279 //
280 Status = UgaPrivateDeleteQ (Private, Key);
281 }
282
283 //
284 // Leave critical section and return
285 //
286 gBS->RestoreTPL (OldTpl);
287
288 return Status;
289 }
290
291 STATIC
292 VOID
293 EFIAPI
294 WinNtUgaSimpleTextInWaitForKey (
295 IN EFI_EVENT Event,
296 IN VOID *Context
297 )
298 /*++
299
300 Routine Description:
301
302 TODO: Add function description
303
304 Arguments:
305
306 Event - TODO: add argument description
307 Context - TODO: add argument description
308
309 Returns:
310
311 TODO: add return values
312
313 --*/
314 {
315 UGA_PRIVATE_DATA *Private;
316 EFI_STATUS Status;
317 EFI_TPL OldTpl;
318
319 Private = (UGA_PRIVATE_DATA *) Context;
320
321 //
322 // Enter critical section
323 //
324 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
325
326 Status = UgaPrivateCheckQ (Private);
327 if (!EFI_ERROR (Status)) {
328 //
329 // If a there is a key in the queue signal our event.
330 //
331 gBS->SignalEvent (Event);
332 } else {
333 //
334 // We need to sleep or NT will schedule this thread with such high
335 // priority that WinProc thread will never run and we will not see
336 // keyboard input. This Sleep makes the syste run 10x faster, so don't
337 // remove it.
338 //
339 Private->WinNtThunk->Sleep (1);
340 }
341
342 //
343 // Leave critical section and return
344 //
345 gBS->RestoreTPL (OldTpl);
346 }
347
348 EFI_STATUS
349 WinNtUgaInitializeSimpleTextInForWindow (
350 IN UGA_PRIVATE_DATA *Private
351 )
352 /*++
353
354 Routine Description:
355
356 TODO: Add function description
357
358 Arguments:
359
360 Private - TODO: add argument description
361
362 Returns:
363
364 TODO: add return values
365
366 --*/
367 {
368 EFI_STATUS Status;
369
370 UgaPrivateCreateQ (Private);
371
372 //
373 // Initialize Simple Text In protoocol
374 //
375 Private->SimpleTextIn.Reset = WinNtUgaSimpleTextInReset;
376 Private->SimpleTextIn.ReadKeyStroke = WinNtUgaSimpleTextInReadKeyStroke;
377
378 Status = gBS->CreateEvent (
379 EVT_NOTIFY_WAIT,
380 TPL_NOTIFY,
381 WinNtUgaSimpleTextInWaitForKey,
382 Private,
383 &Private->SimpleTextIn.WaitForKey
384 );
385
386 return Status;
387 }
388
389 EFI_STATUS
390 WinNtUgaDestroySimpleTextInForWindow (
391 IN UGA_PRIVATE_DATA *Private
392 )
393 /*++
394
395 Routine Description:
396
397 TODO: Add function description
398
399 Arguments:
400
401 Private - TODO: add argument description
402
403 Returns:
404
405 EFI_SUCCESS - TODO: Add description for return value
406
407 --*/
408 {
409 UgaPrivateDestroyQ (Private);
410 return EFI_SUCCESS;
411 }