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