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