]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Bus/Isa/Ps2MouseDxe/CommPs2.c
mass cleanup inf name
[mirror_edk2.git] / IntelFrameworkModulePkg / Bus / Isa / Ps2MouseDxe / CommPs2.c
1 /*++
2
3 Copyright (c) 2006 - 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Abstract:
13
14 PS2 Mouse Communication Interface
15
16
17 --*/
18
19 #include "Ps2Mouse.h"
20 #include "CommPs2.h"
21
22 UINT8 SampleRateTbl[MAX_SR] = { 0xa, 0x14, 0x28, 0x3c, 0x50, 0x64, 0xc8 };
23
24 UINT8 ResolutionTbl[MAX_CMR] = { 0, 1, 2, 3 };
25
26 EFI_STATUS
27 KbcSelfTest (
28 IN EFI_ISA_IO_PROTOCOL *IsaIo
29 )
30 /*++
31
32 Routine Description:
33
34 GC_TODO: Add function description
35
36 Arguments:
37
38 IsaIo - GC_TODO: add argument description
39
40 Returns:
41
42 EFI_DEVICE_ERROR - GC_TODO: Add description for return value
43 EFI_SUCCESS - GC_TODO: Add description for return value
44
45 --*/
46 {
47 EFI_STATUS Status;
48 UINT8 Data;
49
50 //
51 // Keyboard controller self test
52 //
53 Status = Out8042Command (IsaIo, SELF_TEST);
54 if (EFI_ERROR (Status)) {
55 return Status;
56 }
57 //
58 // Read return code
59 //
60 Status = In8042Data (IsaIo, &Data);
61 if (EFI_ERROR (Status)) {
62 return Status;
63 }
64
65 if (Data != 0x55) {
66 return EFI_DEVICE_ERROR;
67 }
68 //
69 // Set system flag
70 //
71 Status = Out8042Command (IsaIo, READ_CMD_BYTE);
72 if (EFI_ERROR (Status)) {
73 return Status;
74 }
75
76 Status = In8042Data (IsaIo, &Data);
77 if (EFI_ERROR (Status)) {
78 return Status;
79 }
80
81 Status = Out8042Command (IsaIo, WRITE_CMD_BYTE);
82 if (EFI_ERROR (Status)) {
83 return Status;
84 }
85
86 Data |= CMD_SYS_FLAG;
87 Status = Out8042Data (IsaIo, Data);
88 if (EFI_ERROR (Status)) {
89 return Status;
90 }
91
92 return EFI_SUCCESS;
93 }
94
95 EFI_STATUS
96 KbcEnableAux (
97 IN EFI_ISA_IO_PROTOCOL *IsaIo
98 )
99 /*++
100
101 Routine Description:
102
103 GC_TODO: Add function description
104
105 Arguments:
106
107 IsaIo - GC_TODO: add argument description
108
109 Returns:
110
111 GC_TODO: add return values
112
113 --*/
114 {
115 //
116 // Send 8042 enable mouse command
117 //
118 return Out8042Command (IsaIo, ENABLE_AUX);
119 }
120
121 EFI_STATUS
122 KbcDisableAux (
123 IN EFI_ISA_IO_PROTOCOL *IsaIo
124 )
125 /*++
126
127 Routine Description:
128
129 GC_TODO: Add function description
130
131 Arguments:
132
133 IsaIo - GC_TODO: add argument description
134
135 Returns:
136
137 GC_TODO: add return values
138
139 --*/
140 {
141 //
142 // Send 8042 disable mouse command
143 //
144 return Out8042Command (IsaIo, DISABLE_AUX);
145 }
146
147 EFI_STATUS
148 KbcEnableKb (
149 IN EFI_ISA_IO_PROTOCOL *IsaIo
150 )
151 /*++
152
153 Routine Description:
154
155 GC_TODO: Add function description
156
157 Arguments:
158
159 IsaIo - GC_TODO: add argument description
160
161 Returns:
162
163 GC_TODO: add return values
164
165 --*/
166 {
167 //
168 // Send 8042 enable keyboard command
169 //
170 return Out8042Command (IsaIo, ENABLE_KB);
171 }
172
173 EFI_STATUS
174 KbcDisableKb (
175 IN EFI_ISA_IO_PROTOCOL *IsaIo
176 )
177 /*++
178
179 Routine Description:
180
181 GC_TODO: Add function description
182
183 Arguments:
184
185 IsaIo - GC_TODO: add argument description
186
187 Returns:
188
189 GC_TODO: add return values
190
191 --*/
192 {
193 //
194 // Send 8042 disable keyboard command
195 //
196 return Out8042Command (IsaIo, DISABLE_KB);
197 }
198
199 EFI_STATUS
200 CheckKbStatus (
201 IN EFI_ISA_IO_PROTOCOL *IsaIo,
202 OUT BOOLEAN *KeyboardEnable
203 )
204 /*++
205
206 Routine Description:
207
208 GC_TODO: Add function description
209
210 Arguments:
211
212 IsaIo - GC_TODO: add argument description
213 KeyboardEnable - GC_TODO: add argument description
214
215 Returns:
216
217 EFI_SUCCESS - GC_TODO: Add description for return value
218
219 --*/
220 {
221 EFI_STATUS Status;
222 UINT8 Data;
223
224 //
225 // Send command to read KBC command byte
226 //
227 Status = Out8042Command (IsaIo, READ_CMD_BYTE);
228 if (EFI_ERROR (Status)) {
229 return Status;
230 }
231
232 Status = In8042Data (IsaIo, &Data);
233 if (EFI_ERROR (Status)) {
234 return Status;
235 }
236 //
237 // Check keyboard enable or not
238 //
239 if ((Data & CMD_KB_STS) == CMD_KB_DIS) {
240 *KeyboardEnable = FALSE;
241 } else {
242 *KeyboardEnable = TRUE;
243 }
244
245 return EFI_SUCCESS;
246 }
247
248 EFI_STATUS
249 PS2MouseReset (
250 IN EFI_ISA_IO_PROTOCOL *IsaIo
251 )
252 /*++
253
254 Routine Description:
255
256 GC_TODO: Add function description
257
258 Arguments:
259
260 IsaIo - GC_TODO: add argument description
261
262 Returns:
263
264 EFI_DEVICE_ERROR - GC_TODO: Add description for return value
265 EFI_DEVICE_ERROR - GC_TODO: Add description for return value
266 EFI_SUCCESS - GC_TODO: Add description for return value
267
268 --*/
269 {
270 EFI_STATUS Status;
271 UINT8 Data;
272
273 Status = Out8042AuxCommand (IsaIo, RESET_CMD, FALSE);
274 if (EFI_ERROR (Status)) {
275 return Status;
276 }
277
278 Status = In8042AuxData (IsaIo, &Data);
279 if (EFI_ERROR (Status)) {
280 return Status;
281 }
282 //
283 // Check BAT Complete Code
284 //
285 if (Data != PS2MOUSE_BAT1) {
286 return EFI_DEVICE_ERROR;
287 }
288
289 Status = In8042AuxData (IsaIo, &Data);
290 if (EFI_ERROR (Status)) {
291 return Status;
292 }
293 //
294 // Check BAT Complete Code
295 //
296 if (Data != PS2MOUSE_BAT2) {
297 return EFI_DEVICE_ERROR;
298 }
299
300 return EFI_SUCCESS;
301 }
302
303 EFI_STATUS
304 PS2MouseSetSampleRate (
305 IN EFI_ISA_IO_PROTOCOL *IsaIo,
306 IN MOUSE_SR SampleRate
307 )
308 /*++
309
310 Routine Description:
311
312 GC_TODO: Add function description
313
314 Arguments:
315
316 IsaIo - GC_TODO: add argument description
317 SampleRate - GC_TODO: add argument description
318
319 Returns:
320
321 GC_TODO: add return values
322
323 --*/
324 {
325 EFI_STATUS Status;
326
327 //
328 // Send auxiliary command to set mouse sample rate
329 //
330 Status = Out8042AuxCommand (IsaIo, SETSR_CMD, FALSE);
331 if (EFI_ERROR (Status)) {
332 return Status;
333 }
334
335 Status = Out8042AuxData (IsaIo, SampleRateTbl[SampleRate]);
336
337 return Status;
338 }
339
340 EFI_STATUS
341 PS2MouseSetResolution (
342 IN EFI_ISA_IO_PROTOCOL *IsaIo,
343 IN MOUSE_RE Resolution
344 )
345 /*++
346
347 Routine Description:
348
349 GC_TODO: Add function description
350
351 Arguments:
352
353 IsaIo - GC_TODO: add argument description
354 Resolution - GC_TODO: add argument description
355
356 Returns:
357
358 GC_TODO: add return values
359
360 --*/
361 {
362 EFI_STATUS Status;
363
364 //
365 // Send auxiliary command to set mouse resolution
366 //
367 Status = Out8042AuxCommand (IsaIo, SETRE_CMD, FALSE);
368 if (EFI_ERROR (Status)) {
369 return Status;
370 }
371
372 Status = Out8042AuxData (IsaIo, ResolutionTbl[Resolution]);
373
374 return Status;
375 }
376
377 EFI_STATUS
378 PS2MouseSetScaling (
379 IN EFI_ISA_IO_PROTOCOL *IsaIo,
380 IN MOUSE_SF Scaling
381 )
382 /*++
383
384 Routine Description:
385
386 GC_TODO: Add function description
387
388 Arguments:
389
390 IsaIo - GC_TODO: add argument description
391 Scaling - GC_TODO: add argument description
392
393 Returns:
394
395 GC_TODO: add return values
396
397 --*/
398 {
399 UINT8 Command;
400
401 Command = (UINT8) (Scaling == SF1 ? SETSF1_CMD : SETSF2_CMD);
402
403 //
404 // Send auxiliary command to set mouse scaling data
405 //
406 return Out8042AuxCommand (IsaIo, Command, FALSE);
407 }
408
409 EFI_STATUS
410 PS2MouseEnable (
411 IN EFI_ISA_IO_PROTOCOL *IsaIo
412 )
413 /*++
414
415 Routine Description:
416
417 GC_TODO: Add function description
418
419 Arguments:
420
421 IsaIo - GC_TODO: add argument description
422
423 Returns:
424
425 GC_TODO: add return values
426
427 --*/
428 {
429 //
430 // Send auxiliary command to enable mouse
431 //
432 return Out8042AuxCommand (IsaIo, ENABLE_CMD, FALSE);
433 }
434
435 EFI_STATUS
436 PS2MouseGetPacket (
437 PS2_MOUSE_DEV *MouseDev
438 )
439 /*++
440
441 Routine Description:
442
443 Get mouse packet . Only care first 3 bytes
444
445 Arguments:
446
447 MouseDev - Pointer of PS2 Mouse Private Data Structure
448
449 Returns:
450
451 EFI_NOT_READY - Mouse Device not ready to input data packet, or some error happened during getting the packet
452 EFI_SUCCESS - The data packet is gotten successfully.
453
454 --*/
455 {
456 EFI_STATUS Status;
457 BOOLEAN KeyboardEnable;
458 UINT8 Packet[PS2_PACKET_LENGTH];
459 UINT8 Data;
460 UINTN Count;
461 UINTN State;
462 INT16 RelativeMovementX;
463 INT16 RelativeMovementY;
464 BOOLEAN LButton;
465 BOOLEAN RButton;
466
467 KeyboardEnable = FALSE;
468 Count = 1;
469 State = PS2_READ_BYTE_ONE;
470
471 //
472 // State machine to get mouse packet
473 //
474 while (1) {
475
476 switch (State) {
477 case PS2_READ_BYTE_ONE:
478 //
479 // Read mouse first byte data, if failed, immediately return
480 //
481 KbcDisableAux (MouseDev->IsaIo);
482 Status = PS2MouseRead (MouseDev->IsaIo, &Data, &Count, State);
483 if (EFI_ERROR (Status)) {
484 KbcEnableAux (MouseDev->IsaIo);
485 return EFI_NOT_READY;
486 }
487
488 if (Count != 1) {
489 KbcEnableAux (MouseDev->IsaIo);
490 return EFI_NOT_READY;
491 }
492
493 if (IS_PS2_SYNC_BYTE (Data)) {
494 Packet[0] = Data;
495 State = PS2_READ_DATA_BYTE;
496
497 CheckKbStatus (MouseDev->IsaIo, &KeyboardEnable);
498 KbcDisableKb (MouseDev->IsaIo);
499 KbcEnableAux (MouseDev->IsaIo);
500 }
501 break;
502
503 case PS2_READ_DATA_BYTE:
504 Count = 2;
505 Status = PS2MouseRead (MouseDev->IsaIo, (Packet + 1), &Count, State);
506 if (EFI_ERROR (Status)) {
507 if (KeyboardEnable) {
508 KbcEnableKb (MouseDev->IsaIo);
509 }
510
511 return EFI_NOT_READY;
512 }
513
514 if (Count != 2) {
515 if (KeyboardEnable) {
516 KbcEnableKb (MouseDev->IsaIo);
517 }
518
519 return EFI_NOT_READY;
520 }
521
522 State = PS2_PROCESS_PACKET;
523 break;
524
525 case PS2_PROCESS_PACKET:
526 if (KeyboardEnable) {
527 KbcEnableKb (MouseDev->IsaIo);
528 }
529 //
530 // Decode the packet
531 //
532 RelativeMovementX = Packet[1];
533 RelativeMovementY = Packet[2];
534 //
535 // Bit 7 | Bit 6 | Bit 5 | Bit 4 | Bit 3 | Bit 2 | Bit 1 | Bit 0
536 // Byte 0 | Y overflow | X overflow | Y sign bit | X sign bit | Always 1 | Middle Btn | Right Btn | Left Btn
537 // Byte 1 | 8 bit X Movement
538 // Byte 2 | 8 bit Y Movement
539 //
540 // X sign bit + 8 bit X Movement : 9-bit signed twos complement integer that presents the relative displacement of the device in the X direction since the last data transmission.
541 // Y sign bit + 8 bit Y Movement : Same as X sign bit + 8 bit X Movement.
542 //
543 //
544 // First, Clear X and Y high 8 bits
545 //
546 RelativeMovementX = (INT16) (RelativeMovementX & 0xFF);
547 RelativeMovementY = (INT16) (RelativeMovementY & 0xFF);
548 //
549 // Second, if the 9-bit signed twos complement integer is negative, set the high 8 bit 0xff
550 //
551 if ((Packet[0] & 0x10) != 0) {
552 RelativeMovementX = (INT16) (RelativeMovementX | 0xFF00);
553 }
554 if ((Packet[0] & 0x20) != 0) {
555 RelativeMovementY = (INT16) (RelativeMovementY | 0xFF00);
556 }
557
558
559 RButton = (UINT8) (Packet[0] & 0x2);
560 LButton = (UINT8) (Packet[0] & 0x1);
561
562 //
563 // Update mouse state
564 //
565 MouseDev->State.RelativeMovementX += RelativeMovementX;
566 MouseDev->State.RelativeMovementY -= RelativeMovementY;
567 MouseDev->State.RightButton = (UINT8) (RButton ? TRUE : FALSE);
568 MouseDev->State.LeftButton = (UINT8) (LButton ? TRUE : FALSE);
569 MouseDev->StateChanged = TRUE;
570
571 return EFI_SUCCESS;
572 }
573 }
574 }
575
576 EFI_STATUS
577 PS2MouseRead (
578 IN EFI_ISA_IO_PROTOCOL *IsaIo,
579 OUT VOID *Buffer,
580 IN OUT UINTN *BufSize,
581 IN UINTN State
582 )
583 /*++
584
585 Routine Description:
586
587 GC_TODO: Add function description
588
589 Arguments:
590
591 IsaIo - GC_TODO: add argument description
592 Buffer - GC_TODO: add argument description
593 BufSize - GC_TODO: add argument description
594 State - GC_TODO: add argument description
595
596 Returns:
597
598 GC_TODO: add return values
599
600 --*/
601 {
602 EFI_STATUS Status;
603 UINTN BytesRead;
604
605 Status = EFI_SUCCESS;
606 BytesRead = 0;
607
608 if (State == PS2_READ_BYTE_ONE) {
609 //
610 // Check input for mouse
611 //
612 Status = CheckForInput (IsaIo);
613
614 if (EFI_ERROR (Status)) {
615 return Status;
616 }
617 }
618
619 while (BytesRead < *BufSize) {
620
621 Status = WaitOutputFull (IsaIo, TIMEOUT);
622 if (EFI_ERROR (Status)) {
623 break;
624 }
625
626 IsaIo->Io.Read (IsaIo, EfiIsaIoWidthUint8, KBC_DATA_PORT, 1, Buffer);
627
628 BytesRead++;
629 Buffer = (UINT8 *) Buffer + 1;
630 }
631 //
632 // Verify the correct number of bytes read
633 //
634 if (BytesRead == 0 || BytesRead != *BufSize) {
635 Status = EFI_NOT_FOUND;
636 }
637
638 *BufSize = BytesRead;
639 return Status;
640 }
641 //
642 // 8042 I/O function
643 //
644 EFI_STATUS
645 Out8042Command (
646 IN EFI_ISA_IO_PROTOCOL *IsaIo,
647 IN UINT8 Command
648 )
649 /*++
650
651 Routine Description:
652
653 GC_TODO: Add function description
654
655 Arguments:
656
657 IsaIo - GC_TODO: add argument description
658 Command - GC_TODO: add argument description
659
660 Returns:
661
662 EFI_SUCCESS - GC_TODO: Add description for return value
663
664 --*/
665 {
666 EFI_STATUS Status;
667 UINT8 Data;
668
669 //
670 // Wait keyboard controller input buffer empty
671 //
672 Status = WaitInputEmpty (IsaIo, TIMEOUT);
673 if (EFI_ERROR (Status)) {
674 return Status;
675 }
676 //
677 // Send command
678 //
679 Data = Command;
680 IsaIo->Io.Write (IsaIo, EfiIsaIoWidthUint8, KBC_CMD_STS_PORT, 1, &Data);
681
682 Status = WaitInputEmpty (IsaIo, TIMEOUT);
683 if (EFI_ERROR (Status)) {
684 return Status;
685 }
686
687 return EFI_SUCCESS;
688 }
689
690 EFI_STATUS
691 Out8042Data (
692 IN EFI_ISA_IO_PROTOCOL *IsaIo,
693 IN UINT8 Data
694 )
695 /*++
696
697 Routine Description:
698
699 GC_TODO: Add function description
700
701 Arguments:
702
703 IsaIo - GC_TODO: add argument description
704 Data - GC_TODO: add argument description
705
706 Returns:
707
708 EFI_SUCCESS - GC_TODO: Add description for return value
709
710 --*/
711 {
712 EFI_STATUS Status;
713 UINT8 temp;
714 //
715 // Wait keyboard controller input buffer empty
716 //
717 Status = WaitInputEmpty (IsaIo, TIMEOUT);
718 if (EFI_ERROR (Status)) {
719 return Status;
720 }
721
722 temp = Data;
723 IsaIo->Io.Write (IsaIo, EfiIsaIoWidthUint8, KBC_DATA_PORT, 1, &temp);
724
725 Status = WaitInputEmpty (IsaIo, TIMEOUT);
726 if (EFI_ERROR (Status)) {
727 return Status;
728 }
729
730 return EFI_SUCCESS;
731 }
732
733 EFI_STATUS
734 In8042Data (
735 IN EFI_ISA_IO_PROTOCOL *IsaIo,
736 IN OUT UINT8 *Data
737 )
738 /*++
739
740 Routine Description:
741
742 GC_TODO: Add function description
743
744 Arguments:
745
746 IsaIo - GC_TODO: add argument description
747 Data - GC_TODO: add argument description
748
749 Returns:
750
751 EFI_TIMEOUT - GC_TODO: Add description for return value
752 EFI_SUCCESS - GC_TODO: Add description for return value
753
754 --*/
755 {
756 UINTN Delay;
757 UINT8 temp;
758
759 Delay = TIMEOUT / 50;
760
761 do {
762 IsaIo->Io.Read (IsaIo, EfiIsaIoWidthUint8, KBC_CMD_STS_PORT, 1, &temp);
763
764 //
765 // Check keyboard controller status bit 0(output buffer status)
766 //
767 if ((temp & KBC_OUTB) == KBC_OUTB) {
768 break;
769 }
770
771 gBS->Stall (50);
772 Delay--;
773 } while (Delay);
774
775 if (Delay == 0) {
776 return EFI_TIMEOUT;
777 }
778
779 IsaIo->Io.Read (IsaIo, EfiIsaIoWidthUint8, KBC_DATA_PORT, 1, Data);
780
781 return EFI_SUCCESS;
782 }
783
784 EFI_STATUS
785 Out8042AuxCommand (
786 IN EFI_ISA_IO_PROTOCOL *IsaIo,
787 IN UINT8 Command,
788 IN BOOLEAN Resend
789 )
790 /*++
791
792 Routine Description:
793
794 GC_TODO: Add function description
795
796 Arguments:
797
798 IsaIo - GC_TODO: add argument description
799 Command - GC_TODO: add argument description
800 Resend - GC_TODO: add argument description
801
802 Returns:
803
804 EFI_SUCCESS - GC_TODO: Add description for return value
805 EFI_DEVICE_ERROR - GC_TODO: Add description for return value
806 EFI_DEVICE_ERROR - GC_TODO: Add description for return value
807 EFI_SUCCESS - GC_TODO: Add description for return value
808
809 --*/
810 {
811 EFI_STATUS Status;
812 UINT8 Data;
813
814 //
815 // Wait keyboard controller input buffer empty
816 //
817 Status = WaitInputEmpty (IsaIo, TIMEOUT);
818 if (EFI_ERROR (Status)) {
819 return Status;
820 }
821 //
822 // Send write to auxiliary device command
823 //
824 Data = WRITE_AUX_DEV;
825 IsaIo->Io.Write (IsaIo, EfiIsaIoWidthUint8, KBC_CMD_STS_PORT, 1, &Data);
826
827 Status = WaitInputEmpty (IsaIo, TIMEOUT);
828 if (EFI_ERROR (Status)) {
829 return Status;
830 }
831 //
832 // Send auxiliary device command
833 //
834 IsaIo->Io.Write (IsaIo, EfiIsaIoWidthUint8, KBC_DATA_PORT, 1, &Command);
835
836 //
837 // Read return code
838 //
839 Status = In8042AuxData (IsaIo, &Data);
840 if (EFI_ERROR (Status)) {
841 return Status;
842 }
843
844 if (Data == PS2_ACK) {
845 //
846 // Receive mouse acknowledge, command send success
847 //
848 return EFI_SUCCESS;
849
850 } else if (Resend) {
851 //
852 // Resend fail
853 //
854 return EFI_DEVICE_ERROR;
855
856 } else if (Data == PS2_RESEND) {
857 //
858 // Resend command
859 //
860 Status = Out8042AuxCommand (IsaIo, Command, TRUE);
861 if (EFI_ERROR (Status)) {
862 return Status;
863 }
864
865 } else {
866 //
867 // Invalid return code
868 //
869 return EFI_DEVICE_ERROR;
870
871 }
872
873 return EFI_SUCCESS;
874 }
875
876 EFI_STATUS
877 Out8042AuxData (
878 IN EFI_ISA_IO_PROTOCOL *IsaIo,
879 IN UINT8 Data
880 )
881 /*++
882
883 Routine Description:
884
885 GC_TODO: Add function description
886
887 Arguments:
888
889 IsaIo - GC_TODO: add argument description
890 Data - GC_TODO: add argument description
891
892 Returns:
893
894 EFI_SUCCESS - GC_TODO: Add description for return value
895
896 --*/
897 {
898 EFI_STATUS Status;
899 UINT8 Temp;
900 //
901 // Wait keyboard controller input buffer empty
902 //
903 Status = WaitInputEmpty (IsaIo, TIMEOUT);
904 if (EFI_ERROR (Status)) {
905 return Status;
906 }
907 //
908 // Send write to auxiliary device command
909 //
910 Temp = WRITE_AUX_DEV;
911 IsaIo->Io.Write (IsaIo, EfiIsaIoWidthUint8, KBC_CMD_STS_PORT, 1, &Temp);
912
913 Status = WaitInputEmpty (IsaIo, TIMEOUT);
914 if (EFI_ERROR (Status)) {
915 return Status;
916 }
917
918 Temp = Data;
919 IsaIo->Io.Write (IsaIo, EfiIsaIoWidthUint8, KBC_DATA_PORT, 1, &Temp);
920
921 Status = WaitInputEmpty (IsaIo, TIMEOUT);
922 if (EFI_ERROR (Status)) {
923 return Status;
924 }
925
926 return EFI_SUCCESS;
927 }
928
929 EFI_STATUS
930 In8042AuxData (
931 IN EFI_ISA_IO_PROTOCOL *IsaIo,
932 IN OUT UINT8 *Data
933 )
934 /*++
935
936 Routine Description:
937
938 GC_TODO: Add function description
939
940 Arguments:
941
942 IsaIo - GC_TODO: add argument description
943 Data - GC_TODO: add argument description
944
945 Returns:
946
947 EFI_SUCCESS - GC_TODO: Add description for return value
948
949 --*/
950 {
951 EFI_STATUS Status;
952
953 //
954 // wait for output data
955 //
956 Status = WaitOutputFull (IsaIo, BAT_TIMEOUT);
957 if (EFI_ERROR (Status)) {
958 return Status;
959 }
960
961 IsaIo->Io.Read (IsaIo, EfiIsaIoWidthUint8, KBC_DATA_PORT, 1, Data);
962
963 return EFI_SUCCESS;
964 }
965
966 EFI_STATUS
967 CheckForInput (
968 IN EFI_ISA_IO_PROTOCOL *IsaIo
969 )
970 /*++
971
972 Routine Description:
973
974 GC_TODO: Add function description
975
976 Arguments:
977
978 IsaIo - GC_TODO: add argument description
979
980 Returns:
981
982 EFI_NOT_READY - GC_TODO: Add description for return value
983 EFI_SUCCESS - GC_TODO: Add description for return value
984
985 --*/
986 {
987 UINT8 Data;
988
989 IsaIo->Io.Read (IsaIo, EfiIsaIoWidthUint8, KBC_CMD_STS_PORT, 1, &Data);
990
991 //
992 // Check keyboard controller status, if it is output buffer full and for auxiliary device
993 //
994 if ((Data & (KBC_OUTB | KBC_AUXB)) != (KBC_OUTB | KBC_AUXB)) {
995 return EFI_NOT_READY;
996 }
997
998 return EFI_SUCCESS;
999 }
1000
1001 EFI_STATUS
1002 WaitInputEmpty (
1003 IN EFI_ISA_IO_PROTOCOL *IsaIo,
1004 IN UINTN Timeout
1005 )
1006 /*++
1007
1008 Routine Description:
1009
1010 GC_TODO: Add function description
1011
1012 Arguments:
1013
1014 IsaIo - GC_TODO: add argument description
1015 Timeout - GC_TODO: add argument description
1016
1017 Returns:
1018
1019 EFI_TIMEOUT - GC_TODO: Add description for return value
1020 EFI_SUCCESS - GC_TODO: Add description for return value
1021
1022 --*/
1023 {
1024 UINTN Delay;
1025 UINT8 Data;
1026
1027 Delay = Timeout / 50;
1028
1029 do {
1030 IsaIo->Io.Read (IsaIo, EfiIsaIoWidthUint8, KBC_CMD_STS_PORT, 1, &Data);
1031
1032 //
1033 // Check keyboard controller status bit 1(input buffer status)
1034 //
1035 if ((Data & KBC_INPB) == 0) {
1036 break;
1037 }
1038
1039 gBS->Stall (50);
1040 Delay--;
1041 } while (Delay);
1042
1043 if (Delay == 0) {
1044 return EFI_TIMEOUT;
1045 }
1046
1047 return EFI_SUCCESS;
1048 }
1049
1050 EFI_STATUS
1051 WaitOutputFull (
1052 IN EFI_ISA_IO_PROTOCOL *IsaIo,
1053 IN UINTN Timeout
1054 )
1055 /*++
1056
1057 Routine Description:
1058
1059 GC_TODO: Add function description
1060
1061 Arguments:
1062
1063 IsaIo - GC_TODO: add argument description
1064 Timeout - GC_TODO: add argument description
1065
1066 Returns:
1067
1068 EFI_TIMEOUT - GC_TODO: Add description for return value
1069 EFI_SUCCESS - GC_TODO: Add description for return value
1070
1071 --*/
1072 {
1073 UINTN Delay;
1074 UINT8 Data;
1075
1076 Delay = Timeout / 50;
1077
1078 do {
1079 IsaIo->Io.Read (IsaIo, EfiIsaIoWidthUint8, KBC_CMD_STS_PORT, 1, &Data);
1080
1081 //
1082 // Check keyboard controller status bit 0(output buffer status)
1083 // & bit5(output buffer for auxiliary device)
1084 //
1085 if ((Data & (KBC_OUTB | KBC_AUXB)) == (KBC_OUTB | KBC_AUXB)) {
1086 break;
1087 }
1088
1089 gBS->Stall (50);
1090 Delay--;
1091 } while (Delay);
1092
1093 if (Delay == 0) {
1094 return EFI_TIMEOUT;
1095 }
1096
1097 return EFI_SUCCESS;
1098 }