]> git.proxmox.com Git - mirror_edk2.git/blob - EmulatorPkg/EmuGopDxe/GopInput.c
EmulatorPkg/EmuGopDxe: Fix TxtInEx.SetState SCT conformance failure
[mirror_edk2.git] / EmulatorPkg / EmuGopDxe / GopInput.c
1 /*++ @file
2
3 Copyright (c) 2006 - 2018, 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 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 **/
120 EFI_STATUS
121 EFIAPI
122 EmuGopSimpleTextInReset (
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 **/
169 EFI_STATUS
170 EFIAPI
171 EmuGopSimpleTextInReadKeyStroke (
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);
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 }
200
201 //
202 // Leave critical section and return
203 //
204 gBS->RestoreTPL (OldTpl);
205
206 return Status;
207 }
208
209
210
211 /**
212 SimpleTextIn and SimpleTextInEx Notify Wait Event
213
214 @param Event Event whose notification function is being invoked.
215 @param Context Pointer to GOP_PRIVATE_DATA.
216
217 **/
218 VOID
219 EFIAPI
220 EmuGopSimpleTextInWaitForKey (
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.
278
279 @retval EFI_DEVICE_ERROR The device is not functioning
280 correctly and could not be reset.
281
282 **/
283 EFI_STATUS
284 EFIAPI
285 EmuGopSimpleTextInExResetEx (
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 return EFI_SUCCESS;
304 }
305
306
307
308 /**
309 The function reads the next keystroke from the input device. If
310 there is no pending keystroke the function returns
311 EFI_NOT_READY. If there is a pending keystroke, then
312 KeyData.Key.ScanCode is the EFI scan code defined in Error!
313 Reference source not found. The KeyData.Key.UnicodeChar is the
314 actual printable character or is zero if the key does not
315 represent a printable character (control key, function key,
316 etc.). The KeyData.KeyState is shift state for the character
317 reflected in KeyData.Key.UnicodeChar or KeyData.Key.ScanCode .
318 When interpreting the data from this function, it should be
319 noted that if a class of printable characters that are
320 normally adjusted by shift modifiers (e.g. Shift Key + "f"
321 key) would be presented solely as a KeyData.Key.UnicodeChar
322 without the associated shift state. So in the previous example
323 of a Shift Key + "f" key being pressed, the only pertinent
324 data returned would be KeyData.Key.UnicodeChar with the value
325 of "F". This of course would not typically be the case for
326 non-printable characters such as the pressing of the Right
327 Shift Key + F10 key since the corresponding returned data
328 would be reflected both in the KeyData.KeyState.KeyShiftState
329 and KeyData.Key.ScanCode values. UEFI drivers which implement
330 the EFI_SIMPLE_TEXT_INPUT_EX protocol are required to return
331 KeyData.Key and KeyData.KeyState values. These drivers must
332 always return the most current state of
333 KeyData.KeyState.KeyShiftState and
334 KeyData.KeyState.KeyToggleState. It should also be noted that
335 certain input devices may not be able to produce shift or toggle
336 state information, and in those cases the high order bit in the
337 respective Toggle and Shift state fields should not be active.
338
339
340 @param This A pointer to the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL instance.
341
342 @param KeyData A pointer to a buffer that is filled in with
343 the keystroke state data for the key that was
344 pressed.
345
346
347 @retval EFI_SUCCESS The keystroke information was
348 returned.
349
350 @retval EFI_NOT_READY There was no keystroke data available.
351 EFI_DEVICE_ERROR The keystroke
352 information was not returned due to
353 hardware errors.
354
355
356 **/
357 EFI_STATUS
358 EFIAPI
359 EmuGopSimpleTextInExReadKeyStrokeEx (
360 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
361 OUT EFI_KEY_DATA *KeyData
362 )
363 /*++
364
365 Routine Description:
366 Reads the next keystroke from the input device. The WaitForKey Event can
367 be used to test for existance of a keystroke via WaitForEvent () call.
368
369 Arguments:
370 This - Protocol instance pointer.
371 KeyData - A pointer to a buffer that is filled in with the keystroke
372 state data for the key that was pressed.
373
374 Returns:
375 EFI_SUCCESS - The keystroke information was returned.
376 EFI_NOT_READY - There was no keystroke data availiable.
377 EFI_DEVICE_ERROR - The keystroke information was not returned due to
378 hardware errors.
379 EFI_INVALID_PARAMETER - KeyData is NULL.
380
381 **/
382 {
383 EFI_STATUS Status;
384 GOP_PRIVATE_DATA *Private;
385 EFI_TPL OldTpl;
386
387
388 if (KeyData == NULL) {
389 return EFI_INVALID_PARAMETER;
390 }
391
392 Private = GOP_PRIVATE_DATA_FROM_TEXT_IN_EX_THIS (This);
393 if (Private->EmuGraphicsWindow == NULL) {
394 return EFI_NOT_READY;
395 }
396
397 //
398 // Enter critical section
399 //
400 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
401
402 Status = Private->EmuGraphicsWindow->GetKey(Private->EmuGraphicsWindow, KeyData);
403
404 //
405 // Leave critical section and return
406 //
407 gBS->RestoreTPL (OldTpl);
408
409 return Status;
410 }
411
412
413
414 /**
415 The SetState() function allows the input device hardware to
416 have state settings adjusted.
417
418 @param This A pointer to the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL instance.
419
420 @param KeyToggleState Pointer to the EFI_KEY_TOGGLE_STATE to
421 set the state for the input device.
422
423
424 @retval EFI_SUCCESS The device state was set appropriately.
425
426 @retval EFI_DEVICE_ERROR The device is not functioning
427 correctly and could not have the
428 setting adjusted.
429
430 @retval EFI_UNSUPPORTED The device does not support the
431 ability to have its state set.
432
433 **/
434 EFI_STATUS
435 EFIAPI
436 EmuGopSimpleTextInExSetState (
437 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
438 IN EFI_KEY_TOGGLE_STATE *KeyToggleState
439 )
440 {
441 GOP_PRIVATE_DATA *Private;
442 EFI_STATUS Status;
443 EFI_TPL OldTpl;
444
445 if (KeyToggleState == NULL) {
446 return EFI_INVALID_PARAMETER;
447 }
448
449 Private = GOP_PRIVATE_DATA_FROM_TEXT_IN_EX_THIS (This);
450 if (Private->EmuGraphicsWindow == NULL) {
451 return EFI_NOT_READY;
452 }
453
454 if (((Private->KeyState.KeyToggleState & EFI_TOGGLE_STATE_VALID) != EFI_TOGGLE_STATE_VALID) ||
455 ((*KeyToggleState & EFI_TOGGLE_STATE_VALID) != EFI_TOGGLE_STATE_VALID)) {
456 return EFI_UNSUPPORTED;
457 }
458
459 //
460 // Enter critical section
461 //
462 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
463
464 Status = Private->EmuGraphicsWindow->KeySetState (Private->EmuGraphicsWindow, KeyToggleState);
465 //
466 // Leave critical section and return
467 //
468 gBS->RestoreTPL (OldTpl);
469
470 return Status;
471 }
472
473
474 /**
475 SimpleTextIn and SimpleTextInEx Notify Wait Event
476
477 @param Event Event whose notification function is being invoked.
478 @param Context Pointer to GOP_PRIVATE_DATA.
479
480 **/
481 VOID
482 EFIAPI
483 EmuGopRegisterKeyCallback (
484 IN EFI_EVENT Event,
485 IN VOID *Context
486 )
487 {
488 EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY *ExNotify = (EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY *)Context;
489
490 ExNotify->KeyNotificationFn (&ExNotify->KeyData);
491 }
492
493
494
495 /**
496 The RegisterKeystrokeNotify() function registers a function
497 which will be called when a specified keystroke will occur.
498
499 @param This A pointer to the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL instance.
500
501 @param KeyData A pointer to a buffer that is filled in with
502 the keystroke information for the key that was
503 pressed.
504
505 @param KeyNotificationFunction Points to the function to be
506 called when the key sequence
507 is typed specified by KeyData.
508
509
510 @param NotifyHandle Points to the unique handle assigned to
511 the registered notification.
512
513 @retval EFI_SUCCESS The device state was set
514 appropriately.
515
516 @retval EFI_OUT_OF_RESOURCES Unable to allocate necessary
517 data structures.
518
519 **/
520 EFI_STATUS
521 EFIAPI
522 EmuGopSimpleTextInExRegisterKeyNotify (
523 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
524 IN EFI_KEY_DATA *KeyData,
525 IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction,
526 OUT EFI_HANDLE *NotifyHandle
527 )
528 {
529 EFI_STATUS Status;
530 GOP_PRIVATE_DATA *Private;
531 EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY *CurrentNotify;
532 LIST_ENTRY *Link;
533 EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY *NewNotify;
534
535 if (KeyData == NULL || KeyNotificationFunction == NULL || NotifyHandle == NULL) {
536 return EFI_INVALID_PARAMETER;
537 }
538
539 Private = GOP_PRIVATE_DATA_FROM_TEXT_IN_EX_THIS (This);
540
541 //
542 // Return EFI_SUCCESS if the (KeyData, NotificationFunction) is already registered.
543 //
544 for (Link = Private->NotifyList.ForwardLink; Link != &Private->NotifyList; Link = Link->ForwardLink) {
545 CurrentNotify = CR (
546 Link,
547 EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY,
548 NotifyEntry,
549 EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY_SIGNATURE
550 );
551 if (GopPrivateIsKeyRegistered (&CurrentNotify->KeyData, KeyData)) {
552 if (CurrentNotify->KeyNotificationFn == KeyNotificationFunction) {
553 *NotifyHandle = CurrentNotify->NotifyHandle;
554 return EFI_SUCCESS;
555 }
556 }
557 }
558
559 //
560 // Allocate resource to save the notification function
561 //
562 NewNotify = (EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY *) AllocateZeroPool (sizeof (EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY));
563 if (NewNotify == NULL) {
564 return EFI_OUT_OF_RESOURCES;
565 }
566
567 NewNotify->Signature = EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY_SIGNATURE;
568 NewNotify->KeyNotificationFn = KeyNotificationFunction;
569 NewNotify->NotifyHandle = (EFI_HANDLE) NewNotify;
570 CopyMem (&NewNotify->KeyData, KeyData, sizeof (KeyData));
571 InsertTailList (&Private->NotifyList, &NewNotify->NotifyEntry);
572
573 Status = gBS->CreateEvent (
574 EVT_NOTIFY_SIGNAL,
575 TPL_NOTIFY,
576 EmuGopRegisterKeyCallback,
577 NewNotify,
578 &NewNotify->Event
579 );
580 ASSERT_EFI_ERROR (Status);
581
582
583 *NotifyHandle = NewNotify->NotifyHandle;
584
585 return EFI_SUCCESS;
586
587 }
588
589
590 /**
591 The UnregisterKeystrokeNotify() function removes the
592 notification which was previously registered.
593
594 @param This A pointer to the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL instance.
595
596 @param NotificationHandle The handle of the notification
597 function being unregistered.
598
599 @retval EFI_SUCCESS The device state was set appropriately.
600
601 @retval EFI_INVALID_PARAMETER The NotificationHandle is
602 invalid.
603
604 **/
605 EFI_STATUS
606 EFIAPI
607 EmuGopSimpleTextInExUnregisterKeyNotify (
608 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
609 IN EFI_HANDLE NotificationHandle
610 )
611 /*++
612
613 Routine Description:
614 Remove a registered notification function from a particular keystroke.
615
616 Arguments:
617 This - Protocol instance pointer.
618 NotificationHandle - The handle of the notification function being unregistered.
619
620 Returns:
621 EFI_SUCCESS - The notification function was unregistered successfully.
622 EFI_INVALID_PARAMETER - The NotificationHandle is invalid.
623
624 **/
625 {
626 GOP_PRIVATE_DATA *Private;
627 LIST_ENTRY *Link;
628 EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY *CurrentNotify;
629
630 if (NotificationHandle == NULL) {
631 return EFI_INVALID_PARAMETER;
632 }
633
634 if (((EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY *) NotificationHandle)->Signature != EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY_SIGNATURE) {
635 return EFI_INVALID_PARAMETER;
636 }
637
638 Private = GOP_PRIVATE_DATA_FROM_TEXT_IN_EX_THIS (This);
639
640 for (Link = Private->NotifyList.ForwardLink; Link != &Private->NotifyList; Link = Link->ForwardLink) {
641 CurrentNotify = CR (
642 Link,
643 EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY,
644 NotifyEntry,
645 EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY_SIGNATURE
646 );
647 if (CurrentNotify->NotifyHandle == NotificationHandle) {
648 //
649 // Remove the notification function from NotifyList and free resources
650 //
651 RemoveEntryList (&CurrentNotify->NotifyEntry);
652
653 gBS->CloseEvent (CurrentNotify->Event);
654
655 gBS->FreePool (CurrentNotify);
656 return EFI_SUCCESS;
657 }
658 }
659
660 //
661 // Can not find the specified Notification Handle
662 //
663 return EFI_INVALID_PARAMETER;
664 }
665
666
667
668 /**
669 Initialize SimplelTextIn and SimpleTextInEx protocols in the Private
670 context structure.
671
672 @param Private Context structure to fill in.
673
674 @return EFI_SUCCESS Initialization was a success
675
676 **/
677 EFI_STATUS
678 EmuGopInitializeSimpleTextInForWindow (
679 IN GOP_PRIVATE_DATA *Private
680 )
681 {
682 EFI_STATUS Status;
683
684 //
685 // Initialize Simple Text In protoocol
686 //
687 Private->SimpleTextIn.Reset = EmuGopSimpleTextInReset;
688 Private->SimpleTextIn.ReadKeyStroke = EmuGopSimpleTextInReadKeyStroke;
689
690 Status = gBS->CreateEvent (
691 EVT_NOTIFY_WAIT,
692 TPL_NOTIFY,
693 EmuGopSimpleTextInWaitForKey,
694 Private,
695 &Private->SimpleTextIn.WaitForKey
696 );
697 ASSERT_EFI_ERROR (Status);
698
699
700 //
701 // Initialize Simple Text In Ex
702 //
703
704 Private->SimpleTextInEx.Reset = EmuGopSimpleTextInExResetEx;
705 Private->SimpleTextInEx.ReadKeyStrokeEx = EmuGopSimpleTextInExReadKeyStrokeEx;
706 Private->SimpleTextInEx.SetState = EmuGopSimpleTextInExSetState;
707 Private->SimpleTextInEx.RegisterKeyNotify = EmuGopSimpleTextInExRegisterKeyNotify;
708 Private->SimpleTextInEx.UnregisterKeyNotify = EmuGopSimpleTextInExUnregisterKeyNotify;
709
710 Private->SimpleTextInEx.Reset (&Private->SimpleTextInEx, FALSE);
711
712 InitializeListHead (&Private->NotifyList);
713
714 Status = gBS->CreateEvent (
715 EVT_NOTIFY_WAIT,
716 TPL_NOTIFY,
717 EmuGopSimpleTextInWaitForKey,
718 Private,
719 &Private->SimpleTextInEx.WaitForKeyEx
720 );
721 ASSERT_EFI_ERROR (Status);
722
723
724 return Status;
725 }
726
727
728
729
730
731
732
733 //
734 // Simple Pointer implementation.
735 //
736
737
738 /**
739 Resets the pointer device hardware.
740
741 @param This A pointer to the EFI_SIMPLE_POINTER_PROTOCOL
742 instance.
743 @param ExtendedVerification Indicates that the driver may perform a more exhaustive
744 verification operation of the device during reset.
745
746 @retval EFI_SUCCESS The device was reset.
747 @retval EFI_DEVICE_ERROR The device is not functioning correctly and could not be reset.
748
749 **/
750 EFI_STATUS
751 EFIAPI
752 EmuGopSimplePointerReset (
753 IN EFI_SIMPLE_POINTER_PROTOCOL *This,
754 IN BOOLEAN ExtendedVerification
755 )
756 {
757 GOP_PRIVATE_DATA *Private;
758 EFI_SIMPLE_POINTER_STATE State;
759 EFI_TPL OldTpl;
760
761 Private = GOP_PRIVATE_DATA_FROM_POINTER_MODE_THIS (This);
762 if (Private->EmuGraphicsWindow == NULL) {
763 return EFI_SUCCESS;
764 }
765
766 //
767 // Enter critical section
768 //
769 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
770
771 //
772 // A reset is draining the Queue
773 //
774 while (Private->EmuGraphicsWindow->GetPointerState (Private->EmuGraphicsWindow, &State) == EFI_SUCCESS)
775 ;
776
777 //
778 // Leave critical section and return
779 //
780 gBS->RestoreTPL (OldTpl);
781 return EFI_SUCCESS;
782 }
783
784
785 /**
786 Retrieves the current state of a pointer device.
787
788 @param This A pointer to the EFI_SIMPLE_POINTER_PROTOCOL
789 instance.
790 @param State A pointer to the state information on the pointer device.
791
792 @retval EFI_SUCCESS The state of the pointer device was returned in State.
793 @retval EFI_NOT_READY The state of the pointer device has not changed since the last call to
794 GetState().
795 @retval EFI_DEVICE_ERROR A device error occurred while attempting to retrieve the pointer device's
796 current state.
797
798 **/
799 EFI_STATUS
800 EFIAPI
801 EmuGopSimplePointerGetState (
802 IN EFI_SIMPLE_POINTER_PROTOCOL *This,
803 IN OUT EFI_SIMPLE_POINTER_STATE *State
804 )
805 {
806 GOP_PRIVATE_DATA *Private;
807 EFI_STATUS Status;
808 EFI_TPL OldTpl;
809
810 Private = GOP_PRIVATE_DATA_FROM_POINTER_MODE_THIS (This);
811 if (Private->EmuGraphicsWindow == NULL) {
812 return EFI_NOT_READY;
813 }
814
815 //
816 // Enter critical section
817 //
818 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
819
820 Status = Private->EmuGraphicsWindow->GetPointerState (Private->EmuGraphicsWindow, State);
821 //
822 // Leave critical section and return
823 //
824 gBS->RestoreTPL (OldTpl);
825
826 return Status;
827 }
828
829
830 /**
831 SimplePointer Notify Wait Event
832
833 @param Event Event whose notification function is being invoked.
834 @param Context Pointer to GOP_PRIVATE_DATA.
835
836 **/
837 VOID
838 EFIAPI
839 EmuGopSimplePointerWaitForInput (
840 IN EFI_EVENT Event,
841 IN VOID *Context
842 )
843 {
844 GOP_PRIVATE_DATA *Private;
845 EFI_STATUS Status;
846 EFI_TPL OldTpl;
847
848 Private = (GOP_PRIVATE_DATA *) Context;
849 if (Private->EmuGraphicsWindow == NULL) {
850 return;
851 }
852
853 //
854 // Enter critical section
855 //
856 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
857
858 Status = Private->EmuGraphicsWindow->CheckPointer (Private->EmuGraphicsWindow);
859 if (!EFI_ERROR (Status)) {
860 //
861 // If the pointer state has changed, signal our event.
862 //
863 gBS->SignalEvent (Event);
864 }
865 //
866 // Leave critical section and return
867 //
868 gBS->RestoreTPL (OldTpl);
869 }
870
871
872 /**
873 SimplePointer constructor
874
875 @param Private Context structure to fill in.
876
877 @retval EFI_SUCCESS Constructor had success
878
879 **/
880 EFI_STATUS
881 EmuGopInitializeSimplePointerForWindow (
882 IN GOP_PRIVATE_DATA *Private
883 )
884 {
885 EFI_STATUS Status;
886
887 //
888 // Initialize Simple Pointer protoocol
889 //
890 Private->PointerMode.ResolutionX = 1;
891 Private->PointerMode.ResolutionY = 1;
892 Private->PointerMode.ResolutionZ = 1;
893 Private->PointerMode.LeftButton = TRUE;
894 Private->PointerMode.RightButton = TRUE;
895
896 Private->SimplePointer.Reset = EmuGopSimplePointerReset;
897 Private->SimplePointer.GetState = EmuGopSimplePointerGetState;
898 Private->SimplePointer.Mode = &Private->PointerMode;
899
900 Status = gBS->CreateEvent (
901 EVT_NOTIFY_WAIT,
902 TPL_NOTIFY,
903 EmuGopSimplePointerWaitForInput,
904 Private,
905 &Private->SimplePointer.WaitForInput
906 );
907
908 return Status;
909 }