]> git.proxmox.com Git - mirror_edk2.git/blame - EmulatorPkg/EmuGopDxe/GopInput.c
Fix a typo when check the return value
[mirror_edk2.git] / EmulatorPkg / EmuGopDxe / GopInput.c
CommitLineData
949f388f 1/*++ @file
2
224e1333 3Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
949f388f 4Portions copyright (c) 2010 0 2011,Apple Inc. All rights reserved.<BR>
5This program and the accompanying materials
6are licensed and made available under the terms and conditions of the BSD License
7which accompanies this distribution. The full text of the license may be found at
8http://opensource.org/licenses/bsd-license.php
9
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13
14**/
15
16#include "Gop.h"
17
18
19BOOLEAN
20GopPrivateIsKeyRegistered (
21 IN EFI_KEY_DATA *RegsiteredData,
22 IN EFI_KEY_DATA *InputData
23 )
24/*++
25
26Routine Description:
27
28Arguments:
29
d18d8a1d 30 RegsiteredData - A pointer to a buffer that is filled in with the keystroke
949f388f 31 state data for the key that was registered.
d18d8a1d 32 InputData - A pointer to a buffer that is filled in with the keystroke
949f388f 33 state data for the key that was pressed.
34
35Returns:
36 TRUE - Key be pressed matches a registered key.
d18d8a1d 37 FLASE - Match failed.
38
949f388f 39**/
40{
41 ASSERT (RegsiteredData != NULL && InputData != NULL);
d18d8a1d 42
949f388f 43 if ((RegsiteredData->Key.ScanCode != InputData->Key.ScanCode) ||
44 (RegsiteredData->Key.UnicodeChar != InputData->Key.UnicodeChar)) {
d18d8a1d 45 return FALSE;
46 }
47
949f388f 48 //
49 // Assume KeyShiftState/KeyToggleState = 0 in Registered key data means these state could be ignored.
50 //
51 if (RegsiteredData->KeyState.KeyShiftState != 0 &&
52 RegsiteredData->KeyState.KeyShiftState != InputData->KeyState.KeyShiftState) {
d18d8a1d 53 return FALSE;
54 }
949f388f 55 if (RegsiteredData->KeyState.KeyToggleState != 0 &&
56 RegsiteredData->KeyState.KeyToggleState != InputData->KeyState.KeyToggleState) {
d18d8a1d 57 return FALSE;
58 }
59
949f388f 60 return TRUE;
61
62}
63
64
65VOID
66EFIAPI
67GopPrivateMakeCallbackFunction (
68 IN VOID *Context,
69 IN EFI_KEY_DATA *KeyData
70 )
d18d8a1d 71{
949f388f 72 LIST_ENTRY *Link;
73 EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY *CurrentNotify;
74 GOP_PRIVATE_DATA *Private = (GOP_PRIVATE_DATA *)Context;
d18d8a1d 75
949f388f 76 KeyMapMake (KeyData);
77
78 for (Link = Private->NotifyList.ForwardLink; Link != &Private->NotifyList; Link = Link->ForwardLink) {
79 CurrentNotify = CR (
d18d8a1d 80 Link,
81 EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY,
82 NotifyEntry,
949f388f 83 EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY_SIGNATURE
84 );
d18d8a1d 85 if (GopPrivateIsKeyRegistered (&CurrentNotify->KeyData, KeyData)) {
86 // We could be called at a high TPL so signal an event to call the registered function
949f388f 87 // at a lower TPL.
88 gBS->SignalEvent (CurrentNotify->Event);
89 }
d18d8a1d 90 }
949f388f 91}
92
93
94VOID
95EFIAPI
96GopPrivateBreakCallbackFunction (
97 IN VOID *Context,
98 IN EFI_KEY_DATA *KeyData
99 )
d18d8a1d 100{
949f388f 101 KeyMapBreak (KeyData);
102}
103
104
105
106//
107// Simple Text In implementation.
108//
109
110/**
111 Reset the input device and optionally run diagnostics
112
113 @param This Protocol instance pointer.
114 @param ExtendedVerification Driver may perform diagnostics on reset.
115
116 @retval EFI_SUCCESS The device was reset.
117 @retval EFI_DEVICE_ERROR The device is not functioning properly and could not be reset.
118
119**/
120EFI_STATUS
121EFIAPI
122EmuGopSimpleTextInReset (
123 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,
124 IN BOOLEAN ExtendedVerification
125 )
126{
127 GOP_PRIVATE_DATA *Private;
128 EFI_KEY_DATA KeyData;
129 EFI_TPL OldTpl;
130
131 Private = GOP_PRIVATE_DATA_FROM_TEXT_IN_THIS (This);
132 if (Private->EmuGraphicsWindow == NULL) {
133 return EFI_SUCCESS;
134 }
135
136 //
137 // Enter critical section
138 //
139 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
140
141 //
142 // A reset is draining the Queue
143 //
144 while (Private->EmuGraphicsWindow->GetKey (Private->EmuGraphicsWindow, &KeyData) == EFI_SUCCESS)
145 ;
146
147 //
148 // Leave critical section and return
149 //
150 gBS->RestoreTPL (OldTpl);
151 return EFI_SUCCESS;
152}
153
154
155/**
156 Reads the next keystroke from the input device. The WaitForKey Event can
157 be used to test for existence of a keystroke via WaitForEvent () call.
158
159 @param This Protocol instance pointer.
160 @param Key A pointer to a buffer that is filled in with the keystroke
161 information for the key that was pressed.
162
163 @retval EFI_SUCCESS The keystroke information was returned.
164 @retval EFI_NOT_READY There was no keystroke data available.
165 @retval EFI_DEVICE_ERROR The keystroke information was not returned due to
166 hardware errors.
167
168**/
169EFI_STATUS
170EFIAPI
171EmuGopSimpleTextInReadKeyStroke (
172 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,
173 OUT EFI_INPUT_KEY *Key
174 )
175{
176 GOP_PRIVATE_DATA *Private;
177 EFI_STATUS Status;
178 EFI_TPL OldTpl;
179 EFI_KEY_DATA KeyData;
180
181 Private = GOP_PRIVATE_DATA_FROM_TEXT_IN_THIS (This);
182 if (Private->EmuGraphicsWindow == NULL) {
183 return EFI_NOT_READY;
184 }
185
186 //
187 // Enter critical section
188 //
189 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
190
191 Status = Private->EmuGraphicsWindow->GetKey (Private->EmuGraphicsWindow, &KeyData);
2fbfd3f9 192 if (!EFI_ERROR (Status)) {
193 if ((KeyData.Key.ScanCode == 0) && (KeyData.Key.UnicodeChar == 0)) {
194 // Modifier key was pressed
195 Status = EFI_NOT_READY;
196 } else {
197 CopyMem (Key, &KeyData.Key, sizeof (EFI_INPUT_KEY));
198 }
199 }
949f388f 200
201 //
202 // Leave critical section and return
203 //
204 gBS->RestoreTPL (OldTpl);
205
206 return Status;
207}
208
209
210
211/**
d18d8a1d 212 SimpleTextIn and SimpleTextInEx Notify Wait Event
949f388f 213
214 @param Event Event whose notification function is being invoked.
215 @param Context Pointer to GOP_PRIVATE_DATA.
216
217**/
218VOID
219EFIAPI
220EmuGopSimpleTextInWaitForKey (
221 IN EFI_EVENT Event,
222 IN VOID *Context
223 )
224{
225 GOP_PRIVATE_DATA *Private;
226 EFI_STATUS Status;
227 EFI_TPL OldTpl;
228
229 Private = (GOP_PRIVATE_DATA *) Context;
230 if (Private->EmuGraphicsWindow == NULL) {
231 return;
232 }
233
234 //
235 // Enter critical section
236 //
237 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
238
239 Status = Private->EmuGraphicsWindow->CheckKey (Private->EmuGraphicsWindow);
240 if (!EFI_ERROR (Status)) {
241 //
242 // If a there is a key in the queue signal our event.
243 //
244 gBS->SignalEvent (Event);
245 }
246 //
247 // Leave critical section and return
248 //
249 gBS->RestoreTPL (OldTpl);
250}
251
252
253//
254// Simple Text Input Ex protocol functions
255//
256
257
258/**
259 The Reset() function resets the input device hardware. As part
260 of initialization process, the firmware/device will make a quick
261 but reasonable attempt to verify that the device is functioning.
262 If the ExtendedVerification flag is TRUE the firmware may take
263 an extended amount of time to verify the device is operating on
264 reset. Otherwise the reset operation is to occur as quickly as
265 possible. The hardware verification process is not defined by
266 this specification and is left up to the platform firmware or
267 driver to implement.
268
269 @param This A pointer to the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL instance.
270
271 @param ExtendedVerification Indicates that the driver may
272 perform a more exhaustive
273 verification operation of the
274 device during reset.
275
276
277 @retval EFI_SUCCESS The device was reset.
d18d8a1d 278
949f388f 279 @retval EFI_DEVICE_ERROR The device is not functioning
280 correctly and could not be reset.
281
282**/
283EFI_STATUS
284EFIAPI
285EmuGopSimpleTextInExResetEx (
286 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
287 IN BOOLEAN ExtendedVerification
288 )
289/*++
290
291 Routine Description:
292 Reset the input device and optionaly run diagnostics
293
294 Arguments:
295 This - Protocol instance pointer.
296 ExtendedVerification - Driver may perform diagnostics on reset.
297
298 Returns:
299 EFI_SUCCESS - The device was reset.
300
301**/
302{
303 GOP_PRIVATE_DATA *Private;
304
305 Private = GOP_PRIVATE_DATA_FROM_TEXT_IN_EX_THIS (This);
d18d8a1d 306
949f388f 307 return EFI_SUCCESS;
308}
309
310
311
312/**
313 The function reads the next keystroke from the input device. If
314 there is no pending keystroke the function returns
315 EFI_NOT_READY. If there is a pending keystroke, then
316 KeyData.Key.ScanCode is the EFI scan code defined in Error!
317 Reference source not found. The KeyData.Key.UnicodeChar is the
318 actual printable character or is zero if the key does not
319 represent a printable character (control key, function key,
320 etc.). The KeyData.KeyState is shift state for the character
321 reflected in KeyData.Key.UnicodeChar or KeyData.Key.ScanCode .
322 When interpreting the data from this function, it should be
323 noted that if a class of printable characters that are
324 normally adjusted by shift modifiers (e.g. Shift Key + "f"
325 key) would be presented solely as a KeyData.Key.UnicodeChar
326 without the associated shift state. So in the previous example
327 of a Shift Key + "f" key being pressed, the only pertinent
328 data returned would be KeyData.Key.UnicodeChar with the value
329 of "F". This of course would not typically be the case for
330 non-printable characters such as the pressing of the Right
331 Shift Key + F10 key since the corresponding returned data
332 would be reflected both in the KeyData.KeyState.KeyShiftState
333 and KeyData.Key.ScanCode values. UEFI drivers which implement
334 the EFI_SIMPLE_TEXT_INPUT_EX protocol are required to return
335 KeyData.Key and KeyData.KeyState values. These drivers must
336 always return the most current state of
337 KeyData.KeyState.KeyShiftState and
338 KeyData.KeyState.KeyToggleState. It should also be noted that
339 certain input devices may not be able to produce shift or toggle
340 state information, and in those cases the high order bit in the
341 respective Toggle and Shift state fields should not be active.
342
d18d8a1d 343
949f388f 344 @param This A pointer to the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL instance.
345
346 @param KeyData A pointer to a buffer that is filled in with
347 the keystroke state data for the key that was
348 pressed.
349
d18d8a1d 350
949f388f 351 @retval EFI_SUCCESS The keystroke information was
352 returned.
d18d8a1d 353
949f388f 354 @retval EFI_NOT_READY There was no keystroke data available.
355 EFI_DEVICE_ERROR The keystroke
356 information was not returned due to
357 hardware errors.
358
359
360**/
361EFI_STATUS
362EFIAPI
363EmuGopSimpleTextInExReadKeyStrokeEx (
364 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
365 OUT EFI_KEY_DATA *KeyData
366 )
367/*++
368
369 Routine Description:
d18d8a1d 370 Reads the next keystroke from the input device. The WaitForKey Event can
949f388f 371 be used to test for existance of a keystroke via WaitForEvent () call.
372
373 Arguments:
374 This - Protocol instance pointer.
d18d8a1d 375 KeyData - A pointer to a buffer that is filled in with the keystroke
949f388f 376 state data for the key that was pressed.
377
378 Returns:
379 EFI_SUCCESS - The keystroke information was returned.
380 EFI_NOT_READY - There was no keystroke data availiable.
d18d8a1d 381 EFI_DEVICE_ERROR - The keystroke information was not returned due to
949f388f 382 hardware errors.
d18d8a1d 383 EFI_INVALID_PARAMETER - KeyData is NULL.
949f388f 384
385**/
386{
387 EFI_STATUS Status;
388 GOP_PRIVATE_DATA *Private;
389 EFI_TPL OldTpl;
390
391
392 if (KeyData == NULL) {
393 return EFI_INVALID_PARAMETER;
394 }
395
396 Private = GOP_PRIVATE_DATA_FROM_TEXT_IN_THIS (This);
397 if (Private->EmuGraphicsWindow == NULL) {
398 return EFI_NOT_READY;
399 }
400
401 //
402 // Enter critical section
403 //
404 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
405
406 Status = Private->EmuGraphicsWindow->GetKey(Private->EmuGraphicsWindow, KeyData);
407
408 //
409 // Leave critical section and return
410 //
411 gBS->RestoreTPL (OldTpl);
412
413 return Status;
414}
415
416
417
418/**
419 The SetState() function allows the input device hardware to
420 have state settings adjusted.
d18d8a1d 421
949f388f 422 @param This A pointer to the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL instance.
d18d8a1d 423
949f388f 424 @param KeyToggleState Pointer to the EFI_KEY_TOGGLE_STATE to
425 set the state for the input device.
d18d8a1d 426
427
949f388f 428 @retval EFI_SUCCESS The device state was set appropriately.
429
430 @retval EFI_DEVICE_ERROR The device is not functioning
431 correctly and could not have the
432 setting adjusted.
433
434 @retval EFI_UNSUPPORTED The device does not support the
435 ability to have its state set.
436
437**/
438EFI_STATUS
439EFIAPI
440EmuGopSimpleTextInExSetState (
441 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
442 IN EFI_KEY_TOGGLE_STATE *KeyToggleState
443 )
444{
445 GOP_PRIVATE_DATA *Private;
446 EFI_STATUS Status;
447 EFI_TPL OldTpl;
448
449 Private = GOP_PRIVATE_DATA_FROM_TEXT_IN_THIS (This);
450 if (Private->EmuGraphicsWindow == NULL) {
451 return EFI_NOT_READY;
452 }
453
454 //
455 // Enter critical section
456 //
457 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
458
459 Status = Private->EmuGraphicsWindow->KeySetState (Private->EmuGraphicsWindow, KeyToggleState);
460 //
461 // Leave critical section and return
462 //
463 gBS->RestoreTPL (OldTpl);
464
465 return Status;
466}
467
468
469/**
d18d8a1d 470 SimpleTextIn and SimpleTextInEx Notify Wait Event
949f388f 471
472 @param Event Event whose notification function is being invoked.
473 @param Context Pointer to GOP_PRIVATE_DATA.
474
475**/
476VOID
477EFIAPI
478EmuGopRegisterKeyCallback (
479 IN EFI_EVENT Event,
480 IN VOID *Context
481 )
482{
483 EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY *ExNotify = (EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY *)Context;
d18d8a1d 484
949f388f 485 ExNotify->KeyNotificationFn (&ExNotify->KeyData);
486}
487
488
489
490/**
491 The RegisterKeystrokeNotify() function registers a function
492 which will be called when a specified keystroke will occur.
d18d8a1d 493
949f388f 494 @param This A pointer to the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL instance.
d18d8a1d 495
949f388f 496 @param KeyData A pointer to a buffer that is filled in with
497 the keystroke information for the key that was
498 pressed.
d18d8a1d 499
949f388f 500 @param KeyNotificationFunction Points to the function to be
501 called when the key sequence
502 is typed specified by KeyData.
d18d8a1d 503
504
949f388f 505 @param NotifyHandle Points to the unique handle assigned to
506 the registered notification.
d18d8a1d 507
949f388f 508 @retval EFI_SUCCESS The device state was set
509 appropriately.
510
511 @retval EFI_OUT_OF_RESOURCES Unable to allocate necessary
512 data structures.
513
514**/
515EFI_STATUS
516EFIAPI
517EmuGopSimpleTextInExRegisterKeyNotify (
518 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
519 IN EFI_KEY_DATA *KeyData,
520 IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction,
521 OUT EFI_HANDLE *NotifyHandle
522 )
523{
524 EFI_STATUS Status;
525 GOP_PRIVATE_DATA *Private;
526 EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY *CurrentNotify;
527 LIST_ENTRY *Link;
528 EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY *NewNotify;
529
530 if (KeyData == NULL || KeyNotificationFunction == NULL || NotifyHandle == NULL) {
531 return EFI_INVALID_PARAMETER;
532 }
533
534 Private = GOP_PRIVATE_DATA_FROM_TEXT_IN_EX_THIS (This);
535
536 //
537 // Return EFI_SUCCESS if the (KeyData, NotificationFunction) is already registered.
538 //
539 for (Link = Private->NotifyList.ForwardLink; Link != &Private->NotifyList; Link = Link->ForwardLink) {
540 CurrentNotify = CR (
d18d8a1d 541 Link,
542 EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY,
543 NotifyEntry,
949f388f 544 EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY_SIGNATURE
545 );
d18d8a1d 546 if (GopPrivateIsKeyRegistered (&CurrentNotify->KeyData, KeyData)) {
949f388f 547 if (CurrentNotify->KeyNotificationFn == KeyNotificationFunction) {
548 *NotifyHandle = CurrentNotify->NotifyHandle;
549 return EFI_SUCCESS;
550 }
551 }
d18d8a1d 552 }
553
949f388f 554 //
555 // Allocate resource to save the notification function
d18d8a1d 556 //
949f388f 557 NewNotify = (EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY *) AllocateZeroPool (sizeof (EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY));
558 if (NewNotify == NULL) {
559 return EFI_OUT_OF_RESOURCES;
560 }
561
d18d8a1d 562 NewNotify->Signature = EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY_SIGNATURE;
949f388f 563 NewNotify->KeyNotificationFn = KeyNotificationFunction;
564 NewNotify->NotifyHandle = (EFI_HANDLE) NewNotify;
565 CopyMem (&NewNotify->KeyData, KeyData, sizeof (KeyData));
566 InsertTailList (&Private->NotifyList, &NewNotify->NotifyEntry);
d18d8a1d 567
949f388f 568 Status = gBS->CreateEvent (
569 EVT_NOTIFY_SIGNAL,
570 TPL_NOTIFY,
571 EmuGopRegisterKeyCallback,
572 NewNotify,
573 &NewNotify->Event
574 );
575 ASSERT_EFI_ERROR (Status);
576
577
d18d8a1d 578 *NotifyHandle = NewNotify->NotifyHandle;
579
949f388f 580 return EFI_SUCCESS;
d18d8a1d 581
949f388f 582}
583
584
585/**
586 The UnregisterKeystrokeNotify() function removes the
587 notification which was previously registered.
d18d8a1d 588
949f388f 589 @param This A pointer to the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL instance.
d18d8a1d 590
949f388f 591 @param NotificationHandle The handle of the notification
592 function being unregistered.
d18d8a1d 593
949f388f 594 @retval EFI_SUCCESS The device state was set appropriately.
d18d8a1d 595
949f388f 596 @retval EFI_INVALID_PARAMETER The NotificationHandle is
597 invalid.
598
599**/
600EFI_STATUS
601EFIAPI
602EmuGopSimpleTextInExUnregisterKeyNotify (
603 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
604 IN EFI_HANDLE NotificationHandle
605 )
606/*++
607
608 Routine Description:
609 Remove a registered notification function from a particular keystroke.
610
611 Arguments:
d18d8a1d 612 This - Protocol instance pointer.
949f388f 613 NotificationHandle - The handle of the notification function being unregistered.
614
615 Returns:
616 EFI_SUCCESS - The notification function was unregistered successfully.
617 EFI_INVALID_PARAMETER - The NotificationHandle is invalid.
d18d8a1d 618
619**/
949f388f 620{
621 GOP_PRIVATE_DATA *Private;
622 LIST_ENTRY *Link;
623 EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY *CurrentNotify;
624
625 if (NotificationHandle == NULL) {
626 return EFI_INVALID_PARAMETER;
d18d8a1d 627 }
949f388f 628
629 if (((EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY *) NotificationHandle)->Signature != EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY_SIGNATURE) {
630 return EFI_INVALID_PARAMETER;
d18d8a1d 631 }
949f388f 632
633 Private = GOP_PRIVATE_DATA_FROM_TEXT_IN_EX_THIS (This);
634
635 for (Link = Private->NotifyList.ForwardLink; Link != &Private->NotifyList; Link = Link->ForwardLink) {
636 CurrentNotify = CR (
d18d8a1d 637 Link,
638 EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY,
639 NotifyEntry,
949f388f 640 EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY_SIGNATURE
d18d8a1d 641 );
949f388f 642 if (CurrentNotify->NotifyHandle == NotificationHandle) {
643 //
644 // Remove the notification function from NotifyList and free resources
645 //
d18d8a1d 646 RemoveEntryList (&CurrentNotify->NotifyEntry);
647
949f388f 648 gBS->CloseEvent (CurrentNotify->Event);
649
d18d8a1d 650 gBS->FreePool (CurrentNotify);
949f388f 651 return EFI_SUCCESS;
652 }
653 }
654
655 //
656 // Can not find the specified Notification Handle
657 //
658 return EFI_INVALID_PARAMETER;
659}
660
661
662
663/**
664 Initialize SimplelTextIn and SimpleTextInEx protocols in the Private
665 context structure.
666
d18d8a1d 667 @param Private Context structure to fill in.
949f388f 668
669 @return EFI_SUCCESS Initialization was a success
670
671**/
672EFI_STATUS
673EmuGopInitializeSimpleTextInForWindow (
674 IN GOP_PRIVATE_DATA *Private
675 )
676{
677 EFI_STATUS Status;
678
679 //
680 // Initialize Simple Text In protoocol
681 //
682 Private->SimpleTextIn.Reset = EmuGopSimpleTextInReset;
683 Private->SimpleTextIn.ReadKeyStroke = EmuGopSimpleTextInReadKeyStroke;
684
685 Status = gBS->CreateEvent (
686 EVT_NOTIFY_WAIT,
687 TPL_NOTIFY,
688 EmuGopSimpleTextInWaitForKey,
689 Private,
690 &Private->SimpleTextIn.WaitForKey
691 );
692 ASSERT_EFI_ERROR (Status);
d18d8a1d 693
694
949f388f 695 //
696 // Initialize Simple Text In Ex
697 //
d18d8a1d 698
949f388f 699 Private->SimpleTextInEx.Reset = EmuGopSimpleTextInExResetEx;
700 Private->SimpleTextInEx.ReadKeyStrokeEx = EmuGopSimpleTextInExReadKeyStrokeEx;
701 Private->SimpleTextInEx.SetState = EmuGopSimpleTextInExSetState;
702 Private->SimpleTextInEx.RegisterKeyNotify = EmuGopSimpleTextInExRegisterKeyNotify;
703 Private->SimpleTextInEx.UnregisterKeyNotify = EmuGopSimpleTextInExUnregisterKeyNotify;
704
705 Private->SimpleTextInEx.Reset (&Private->SimpleTextInEx, FALSE);
d18d8a1d 706
949f388f 707 InitializeListHead (&Private->NotifyList);
708
709 Status = gBS->CreateEvent (
710 EVT_NOTIFY_WAIT,
711 TPL_NOTIFY,
712 EmuGopSimpleTextInWaitForKey,
713 Private,
714 &Private->SimpleTextInEx.WaitForKeyEx
715 );
716 ASSERT_EFI_ERROR (Status);
717
718
719 return Status;
720}
721
722
723
724
725
726
727
728//
729// Simple Pointer implementation.
730//
731
732
d18d8a1d 733/**
949f388f 734 Resets the pointer device hardware.
d18d8a1d 735
949f388f 736 @param This A pointer to the EFI_SIMPLE_POINTER_PROTOCOL
d18d8a1d 737 instance.
949f388f 738 @param ExtendedVerification Indicates that the driver may perform a more exhaustive
d18d8a1d 739 verification operation of the device during reset.
740
949f388f 741 @retval EFI_SUCCESS The device was reset.
d18d8a1d 742 @retval EFI_DEVICE_ERROR The device is not functioning correctly and could not be reset.
743
949f388f 744**/
745EFI_STATUS
746EFIAPI
747EmuGopSimplePointerReset (
748 IN EFI_SIMPLE_POINTER_PROTOCOL *This,
749 IN BOOLEAN ExtendedVerification
750 )
751{
752 GOP_PRIVATE_DATA *Private;
753 EFI_SIMPLE_POINTER_STATE State;
754 EFI_TPL OldTpl;
755
756 Private = GOP_PRIVATE_DATA_FROM_POINTER_MODE_THIS (This);
757 if (Private->EmuGraphicsWindow == NULL) {
758 return EFI_SUCCESS;
759 }
760
761 //
762 // Enter critical section
763 //
764 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
765
766 //
767 // A reset is draining the Queue
768 //
769 while (Private->EmuGraphicsWindow->GetPointerState (Private->EmuGraphicsWindow, &State) == EFI_SUCCESS)
770 ;
771
772 //
773 // Leave critical section and return
774 //
775 gBS->RestoreTPL (OldTpl);
776 return EFI_SUCCESS;
777}
778
779
d18d8a1d 780/**
949f388f 781 Retrieves the current state of a pointer device.
d18d8a1d 782
949f388f 783 @param This A pointer to the EFI_SIMPLE_POINTER_PROTOCOL
d18d8a1d 784 instance.
949f388f 785 @param State A pointer to the state information on the pointer device.
d18d8a1d 786
949f388f 787 @retval EFI_SUCCESS The state of the pointer device was returned in State.
788 @retval EFI_NOT_READY The state of the pointer device has not changed since the last call to
d18d8a1d 789 GetState().
949f388f 790 @retval EFI_DEVICE_ERROR A device error occurred while attempting to retrieve the pointer device's
d18d8a1d 791 current state.
792
949f388f 793**/
794EFI_STATUS
795EFIAPI
796EmuGopSimplePointerGetState (
797 IN EFI_SIMPLE_POINTER_PROTOCOL *This,
798 IN OUT EFI_SIMPLE_POINTER_STATE *State
799 )
800{
801 GOP_PRIVATE_DATA *Private;
802 EFI_STATUS Status;
803 EFI_TPL OldTpl;
804
805 Private = GOP_PRIVATE_DATA_FROM_POINTER_MODE_THIS (This);
806 if (Private->EmuGraphicsWindow == NULL) {
807 return EFI_NOT_READY;
808 }
809
810 //
811 // Enter critical section
812 //
813 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
814
815 Status = Private->EmuGraphicsWindow->GetPointerState (Private->EmuGraphicsWindow, State);
816 //
817 // Leave critical section and return
818 //
819 gBS->RestoreTPL (OldTpl);
820
821 return Status;
822}
823
824
825/**
d18d8a1d 826 SimplePointer Notify Wait Event
949f388f 827
828 @param Event Event whose notification function is being invoked.
829 @param Context Pointer to GOP_PRIVATE_DATA.
830
831**/
832VOID
833EFIAPI
834EmuGopSimplePointerWaitForInput (
835 IN EFI_EVENT Event,
836 IN VOID *Context
837 )
838{
839 GOP_PRIVATE_DATA *Private;
840 EFI_STATUS Status;
841 EFI_TPL OldTpl;
842
843 Private = (GOP_PRIVATE_DATA *) Context;
844 if (Private->EmuGraphicsWindow == NULL) {
845 return;
846 }
847
848 //
849 // Enter critical section
850 //
851 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
852
853 Status = Private->EmuGraphicsWindow->CheckPointer (Private->EmuGraphicsWindow);
854 if (!EFI_ERROR (Status)) {
855 //
856 // If the pointer state has changed, signal our event.
857 //
858 gBS->SignalEvent (Event);
859 }
860 //
861 // Leave critical section and return
862 //
863 gBS->RestoreTPL (OldTpl);
864}
865
866
867/**
d18d8a1d 868 SimplePointer constructor
949f388f 869
d18d8a1d 870 @param Private Context structure to fill in.
949f388f 871
d18d8a1d 872 @retval EFI_SUCCESS Constructor had success
949f388f 873
874**/
875EFI_STATUS
876EmuGopInitializeSimplePointerForWindow (
877 IN GOP_PRIVATE_DATA *Private
878 )
879{
880 EFI_STATUS Status;
881
882 //
883 // Initialize Simple Pointer protoocol
884 //
885 Private->PointerMode.ResolutionX = 1;
886 Private->PointerMode.ResolutionY = 1;
887 Private->PointerMode.ResolutionZ = 1;
888 Private->PointerMode.LeftButton = TRUE;
889 Private->PointerMode.RightButton = TRUE;
890
891 Private->SimplePointer.Reset = EmuGopSimplePointerReset;
892 Private->SimplePointer.GetState = EmuGopSimplePointerGetState;
893 Private->SimplePointer.Mode = &Private->PointerMode;
894
895 Status = gBS->CreateEvent (
896 EVT_NOTIFY_WAIT,
897 TPL_NOTIFY,
898 EmuGopSimplePointerWaitForInput,
899 Private,
900 &Private->SimplePointer.WaitForInput
901 );
902
903 return Status;
904}