3 Copyright (c) 2006, 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
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.
18 Helper functions for USB Keyboard Driver
27 // USB Key Code to Efi key mapping table
28 // Format:<efi scan code>, <unicode without shift>, <unicode with shift>
31 UINT8 KeyConvertionTable
[USB_KEYCODE_MAX_MAKE
][3] = {
32 { SCAN_NULL
, 'a', 'A' }, // 0x04
33 { SCAN_NULL
, 'b', 'B' }, // 0x05
34 { SCAN_NULL
, 'c', 'C' }, // 0x06
35 { SCAN_NULL
, 'd', 'D' }, // 0x07
36 { SCAN_NULL
, 'e', 'E' }, // 0x08
37 { SCAN_NULL
, 'f', 'F' }, // 0x09
38 { SCAN_NULL
, 'g', 'G' }, // 0x0A
39 { SCAN_NULL
, 'h', 'H' }, // 0x0B
40 { SCAN_NULL
, 'i', 'I' }, // 0x0C
41 { SCAN_NULL
, 'j', 'J' }, // 0x0D
42 { SCAN_NULL
, 'k', 'K' }, // 0x0E
43 { SCAN_NULL
, 'l', 'L' }, // 0x0F
44 { SCAN_NULL
, 'm', 'M' }, // 0x10
45 { SCAN_NULL
, 'n', 'N' }, // 0x11
46 { SCAN_NULL
, 'o', 'O' }, // 0x12
47 { SCAN_NULL
, 'p', 'P' }, // 0x13
48 { SCAN_NULL
, 'q', 'Q' }, // 0x14
49 { SCAN_NULL
, 'r', 'R' }, // 0x15
50 { SCAN_NULL
, 's', 'S' }, // 0x16
51 { SCAN_NULL
, 't', 'T' }, // 0x17
52 { SCAN_NULL
, 'u', 'U' }, // 0x18
53 { SCAN_NULL
, 'v', 'V' }, // 0x19
54 { SCAN_NULL
, 'w', 'W' }, // 0x1A
55 { SCAN_NULL
, 'x', 'X' }, // 0x1B
56 { SCAN_NULL
, 'y', 'Y' }, // 0x1C
57 { SCAN_NULL
, 'z', 'Z' }, // 0x1D
58 { SCAN_NULL
, '1', '!' }, // 0x1E
59 { SCAN_NULL
, '2', '@' }, // 0x1F
60 { SCAN_NULL
, '3', '#' }, // 0x20
61 { SCAN_NULL
, '4', '$' }, // 0x21
62 { SCAN_NULL
, '5', '%' }, // 0x22
63 { SCAN_NULL
, '6', '^' }, // 0x23
64 { SCAN_NULL
, '7', '&' }, // 0x24
65 { SCAN_NULL
, '8', '*' }, // 0x25
66 { SCAN_NULL
, '9', '(' }, // 0x26
67 { SCAN_NULL
, '0', ')' }, // 0x27
68 { SCAN_NULL
, 0x0d, 0x0d }, // 0x28 Enter
69 { SCAN_ESC
, 0x00, 0x00 }, // 0x29 Esc
70 { SCAN_NULL
, 0x08, 0x08 }, // 0x2A Backspace
71 { SCAN_NULL
, 0x09, 0x09 }, // 0x2B Tab
72 { SCAN_NULL
, ' ', ' ' }, // 0x2C Spacebar
73 { SCAN_NULL
, '-', '_' }, // 0x2D
74 { SCAN_NULL
, '=', '+' }, // 0x2E
75 { SCAN_NULL
, '[', '{' }, // 0x2F
76 { SCAN_NULL
, ']', '}' }, // 0x30
77 { SCAN_NULL
, '\\', '|' }, // 0x31
78 { SCAN_NULL
, '\\', '|' }, // 0x32 Keyboard US \ and |
79 { SCAN_NULL
, ';', ':' }, // 0x33
80 { SCAN_NULL
, '\'', '"' }, // 0x34
81 { SCAN_NULL
, '`', '~' }, // 0x35 Keyboard Grave Accent and Tlide
82 { SCAN_NULL
, ',', '<' }, // 0x36
83 { SCAN_NULL
, '.', '>' }, // 0x37
84 { SCAN_NULL
, '/', '?' }, // 0x38
85 { SCAN_NULL
, 0x00, 0x00 }, // 0x39 CapsLock
86 { SCAN_F1
, 0x00, 0x00 }, // 0x3A
87 { SCAN_F2
, 0x00, 0x00 }, // 0x3B
88 { SCAN_F3
, 0x00, 0x00 }, // 0x3C
89 { SCAN_F4
, 0x00, 0x00 }, // 0x3D
90 { SCAN_F5
, 0x00, 0x00 }, // 0x3E
91 { SCAN_F6
, 0x00, 0x00 }, // 0x3F
92 { SCAN_F7
, 0x00, 0x00 }, // 0x40
93 { SCAN_F8
, 0x00, 0x00 }, // 0x41
94 { SCAN_F9
, 0x00, 0x00 }, // 0x42
95 { SCAN_F10
, 0x00, 0x00 }, // 0x43
96 { SCAN_NULL
, 0x00, 0x00 }, // 0x44 F11
97 { SCAN_NULL
, 0x00, 0x00 }, // 0x45 F12
98 { SCAN_NULL
, 0x00, 0x00 }, // 0x46 PrintScreen
99 { SCAN_NULL
, 0x00, 0x00 }, // 0x47 Scroll Lock
100 { SCAN_NULL
, 0x00, 0x00 }, // 0x48 Pause
101 { SCAN_INSERT
, 0x00, 0x00 }, // 0x49
102 { SCAN_HOME
, 0x00, 0x00 }, // 0x4A
103 { SCAN_PAGE_UP
, 0x00, 0x00 }, // 0x4B
104 { SCAN_DELETE
, 0x00, 0x00 }, // 0x4C
105 { SCAN_END
, 0x00, 0x00 }, // 0x4D
106 { SCAN_PAGE_DOWN
, 0x00, 0x00 }, // 0x4E
107 { SCAN_RIGHT
, 0x00, 0x00 }, // 0x4F
108 { SCAN_LEFT
, 0x00, 0x00 }, // 0x50
109 { SCAN_DOWN
, 0x00, 0x00 }, // 0x51
110 { SCAN_UP
, 0x00, 0x00 }, // 0x52
111 { SCAN_NULL
, 0x00, 0x00 }, // 0x53 NumLock
112 { SCAN_NULL
, '/', '/' }, // 0x54
113 { SCAN_NULL
, '*', '*' }, // 0x55
114 { SCAN_NULL
, '-', '-' }, // 0x56
115 { SCAN_NULL
, '+', '+' }, // 0x57
116 { SCAN_NULL
, 0x0d, 0x0d }, // 0x58
117 { SCAN_END
, '1', '1' }, // 0x59
118 { SCAN_DOWN
, '2', '2' }, // 0x5A
119 { SCAN_PAGE_DOWN
, '3', '3' }, // 0x5B
120 { SCAN_LEFT
, '4', '4' }, // 0x5C
121 { SCAN_NULL
, '5', '5' }, // 0x5D
122 { SCAN_RIGHT
, '6', '6' }, // 0x5E
123 { SCAN_HOME
, '7', '7' }, // 0x5F
124 { SCAN_UP
, '8', '8' }, // 0x60
125 { SCAN_PAGE_UP
, '9', '9' }, // 0x61
126 { SCAN_INSERT
, '0', '0' }, // 0x62
127 { SCAN_DELETE
, '.', '.' }, // 0x63
128 { SCAN_NULL
, '\\', '|' }, // 0x64 Keyboard Non-US \ and |
129 { SCAN_NULL
, 0x00, 0x00 }, // 0x65 Keyboard Application
130 { SCAN_NULL
, 0x00, 0x00 }, // 0x66 Keyboard Power
131 { SCAN_NULL
, '=' , '=' } // 0x67 Keypad =
134 STATIC KB_MODIFIER KB_Mod
[8] = {
135 { MOD_CONTROL_L
, 0xe0 }, // 11100000
136 { MOD_CONTROL_R
, 0xe4 }, // 11100100
137 { MOD_SHIFT_L
, 0xe1 }, // 11100001
138 { MOD_SHIFT_R
, 0xe5 }, // 11100101
139 { MOD_ALT_L
, 0xe2 }, // 11100010
140 { MOD_ALT_R
, 0xe6 }, // 11100110
141 { MOD_WIN_L
, 0xe3 }, // 11100011
142 { MOD_WIN_R
, 0xe7 } // 11100111
148 IN EFI_USB_IO_PROTOCOL
*UsbIo
153 Uses USB I/O to check whether the device is a USB Keyboard device.
156 UsbIo: Points to a USB I/O protocol instance.
163 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor
;
166 // Get the Default interface descriptor, currently we
167 // assume it is interface 1
169 Status
= UsbIo
->UsbGetInterfaceDescriptor (
174 if (EFI_ERROR (Status
)) {
178 if (InterfaceDescriptor
.InterfaceClass
== CLASS_HID
&&
179 InterfaceDescriptor
.InterfaceSubClass
== SUBCLASS_BOOT
&&
180 InterfaceDescriptor
.InterfaceProtocol
== PROTOCOL_KEYBOARD
192 IN USB_KB_DEV
*UsbKeyboardDevice
197 Initialize USB Keyboard device and all private data structures.
200 UsbKeyboardDevice The USB_KB_DEV instance.
203 EFI_SUCCESS - Success
204 EFI_DEVICE_ERROR - Hardware Error
212 UINT32 TransferResult
;
214 KbdReportStatusCode (
215 UsbKeyboardDevice
->DevicePath
,
217 (EFI_PERIPHERAL_KEYBOARD
| EFI_P_KEYBOARD_PC_SELF_TEST
)
220 InitUSBKeyBuffer (&(UsbKeyboardDevice
->KeyboardBuffer
));
223 // default configurations
228 // Uses default configuration to configure the USB Keyboard device.
230 Status
= UsbSetDeviceConfiguration (
231 UsbKeyboardDevice
->UsbIo
,
232 (UINT16
) ConfigValue
,
235 if (EFI_ERROR (Status
)) {
237 // If configuration could not be set here, it means
238 // the keyboard interface has some errors and could
239 // not be initialized
241 KbdReportStatusCode (
242 UsbKeyboardDevice
->DevicePath
,
243 EFI_ERROR_CODE
| EFI_ERROR_MINOR
,
244 (EFI_PERIPHERAL_KEYBOARD
| EFI_P_EC_INTERFACE_ERROR
)
247 return EFI_DEVICE_ERROR
;
250 UsbGetProtocolRequest (
251 UsbKeyboardDevice
->UsbIo
,
252 UsbKeyboardDevice
->InterfaceDescriptor
.InterfaceNumber
,
256 // Sets boot protocol for the USB Keyboard.
257 // This driver only supports boot protocol.
258 // !!BugBug: How about the device that does not support boot protocol?
260 if (Protocol
!= BOOT_PROTOCOL
) {
261 UsbSetProtocolRequest (
262 UsbKeyboardDevice
->UsbIo
,
263 UsbKeyboardDevice
->InterfaceDescriptor
.InterfaceNumber
,
268 // the duration is indefinite, so the endpoint will inhibit reporting forever,
269 // and only reporting when a change is detected in the report data.
273 // idle value for all report ID
277 // idle forever until there is a key pressed and released.
281 UsbKeyboardDevice
->UsbIo
,
282 UsbKeyboardDevice
->InterfaceDescriptor
.InterfaceNumber
,
287 UsbKeyboardDevice
->CtrlOn
= 0;
288 UsbKeyboardDevice
->AltOn
= 0;
289 UsbKeyboardDevice
->ShiftOn
= 0;
290 UsbKeyboardDevice
->NumLockOn
= 0;
291 UsbKeyboardDevice
->CapsOn
= 0;
292 ZeroMem (UsbKeyboardDevice
->LastKeyCodeArray
, sizeof (UINT8
) * 8);
295 // Set a timer for repeat keys' generation.
297 if (UsbKeyboardDevice
->RepeatTimer
) {
298 gBS
->CloseEvent (UsbKeyboardDevice
->RepeatTimer
);
299 UsbKeyboardDevice
->RepeatTimer
= 0;
302 Status
= gBS
->CreateEvent (
303 EFI_EVENT_TIMER
| EFI_EVENT_NOTIFY_SIGNAL
,
305 USBKeyboardRepeatHandler
,
307 &UsbKeyboardDevice
->RepeatTimer
310 if (UsbKeyboardDevice
->DelayedRecoveryEvent
) {
311 gBS
->CloseEvent (UsbKeyboardDevice
->DelayedRecoveryEvent
);
312 UsbKeyboardDevice
->DelayedRecoveryEvent
= 0;
315 Status
= gBS
->CreateEvent (
316 EFI_EVENT_TIMER
| EFI_EVENT_NOTIFY_SIGNAL
,
318 USBKeyboardRecoveryHandler
,
320 &UsbKeyboardDevice
->DelayedRecoveryEvent
337 Handler function for USB Keyboard's asynchronous interrupt transfer.
340 Data A pointer to a buffer that is filled with key data which is
341 retrieved via asynchronous interrupt transfer.
342 DataLength Indicates the size of the data buffer.
343 Context Pointing to USB_KB_DEV instance.
344 Result Indicates the result of the asynchronous interrupt transfer.
347 EFI_SUCCESS - Success
348 EFI_DEVICE_ERROR - Hardware Error
351 USB_KB_DEV
*UsbKeyboardDevice
;
352 EFI_USB_IO_PROTOCOL
*UsbIo
;
353 UINT8
*CurKeyCodeBuffer
;
354 UINT8
*OldKeyCodeBuffer
;
355 UINT8 CurModifierMap
;
356 UINT8 OldModifierMap
;
370 UsbKeyboardDevice
= (USB_KB_DEV
*) Context
;
371 UsbIo
= UsbKeyboardDevice
->UsbIo
;
374 // Analyzes the Result and performs corresponding action.
376 if (Result
!= EFI_USB_NOERROR
) {
378 // Some errors happen during the process
380 KbdReportStatusCode (
381 UsbKeyboardDevice
->DevicePath
,
382 EFI_ERROR_CODE
| EFI_ERROR_MINOR
,
383 (EFI_PERIPHERAL_KEYBOARD
| EFI_P_EC_INPUT_ERROR
)
387 // stop the repeat key generation if any
389 UsbKeyboardDevice
->RepeatKey
= 0;
392 UsbKeyboardDevice
->RepeatTimer
,
397 if ((Result
& EFI_USB_ERR_STALL
) == EFI_USB_ERR_STALL
) {
398 UsbClearEndpointHalt (
400 UsbKeyboardDevice
->IntEndpointDescriptor
.EndpointAddress
,
406 // Delete & Submit this interrupt again
409 UsbIo
->UsbAsyncInterruptTransfer (
411 UsbKeyboardDevice
->IntEndpointDescriptor
.EndpointAddress
,
420 UsbKeyboardDevice
->DelayedRecoveryEvent
,
422 EFI_USB_INTERRUPT_DELAY
425 return EFI_DEVICE_ERROR
;
428 if (DataLength
== 0 || Data
== NULL
) {
432 CurKeyCodeBuffer
= (UINT8
*) Data
;
433 OldKeyCodeBuffer
= UsbKeyboardDevice
->LastKeyCodeArray
;
436 // checks for new key stroke.
437 // if no new key got, return immediately.
439 for (Index
= 0; Index
< 8; Index
++) {
440 if (OldKeyCodeBuffer
[Index
] != CurKeyCodeBuffer
[Index
]) {
450 // Parse the modifier key
452 CurModifierMap
= CurKeyCodeBuffer
[0];
453 OldModifierMap
= OldKeyCodeBuffer
[0];
456 // handle modifier key's pressing or releasing situation.
458 for (Index
= 0; Index
< 8; Index
++) {
460 if ((CurModifierMap
& KB_Mod
[Index
].Mask
) != (OldModifierMap
& KB_Mod
[Index
].Mask
)) {
462 // if current modifier key is up, then
463 // CurModifierMap & KB_Mod[Index].Mask = 0;
464 // otherwize it is a non-zero value.
465 // Inserts the pressed modifier key into key buffer.
467 Down
= (UINT8
) (CurModifierMap
& KB_Mod
[Index
].Mask
);
468 InsertKeyCode (&(UsbKeyboardDevice
->KeyboardBuffer
), KB_Mod
[Index
].Key
, Down
);
473 // handle normal key's releasing situation
476 for (Index
= 2; Index
< 8; Index
++) {
478 if (!USBKBD_VALID_KEYCODE (OldKeyCodeBuffer
[Index
])) {
483 for (Index2
= 2; Index2
< 8; Index2
++) {
485 if (!USBKBD_VALID_KEYCODE (CurKeyCodeBuffer
[Index2
])) {
489 if (OldKeyCodeBuffer
[Index
] == CurKeyCodeBuffer
[Index2
]) {
497 &(UsbKeyboardDevice
->KeyboardBuffer
),
498 OldKeyCodeBuffer
[Index
],
502 // the original reapeat key is released.
504 if (OldKeyCodeBuffer
[Index
] == UsbKeyboardDevice
->RepeatKey
) {
505 UsbKeyboardDevice
->RepeatKey
= 0;
511 // original repeat key is released, cancel the repeat timer
513 if (UsbKeyboardDevice
->RepeatKey
== 0) {
515 UsbKeyboardDevice
->RepeatTimer
,
522 // handle normal key's pressing situation
525 for (Index
= 2; Index
< 8; Index
++) {
527 if (!USBKBD_VALID_KEYCODE (CurKeyCodeBuffer
[Index
])) {
532 for (Index2
= 2; Index2
< 8; Index2
++) {
534 if (!USBKBD_VALID_KEYCODE (OldKeyCodeBuffer
[Index2
])) {
538 if (CurKeyCodeBuffer
[Index
] == OldKeyCodeBuffer
[Index2
]) {
545 InsertKeyCode (&(UsbKeyboardDevice
->KeyboardBuffer
), CurKeyCodeBuffer
[Index
], 1);
547 // NumLock pressed or CapsLock pressed
549 if (CurKeyCodeBuffer
[Index
] == 0x53 || CurKeyCodeBuffer
[Index
] == 0x39) {
550 UsbKeyboardDevice
->RepeatKey
= 0;
552 NewRepeatKey
= CurKeyCodeBuffer
[Index
];
554 // do not repeat the original repeated key
556 UsbKeyboardDevice
->RepeatKey
= 0;
562 // Update LastKeycodeArray[] buffer in the
563 // Usb Keyboard Device data structure.
565 for (Index
= 0; Index
< 8; Index
++) {
566 UsbKeyboardDevice
->LastKeyCodeArray
[Index
] = CurKeyCodeBuffer
[Index
];
570 // pre-process KeyboardBuffer, pop out the ctrl,alt,del key in sequence
571 // and judge whether it will invoke reset event.
573 SavedTail
= UsbKeyboardDevice
->KeyboardBuffer
.bTail
;
574 Index
= UsbKeyboardDevice
->KeyboardBuffer
.bHead
;
575 while (Index
!= SavedTail
) {
576 RemoveKeyCode (&(UsbKeyboardDevice
->KeyboardBuffer
), &UsbKey
);
578 switch (UsbKey
.KeyCode
) {
583 UsbKeyboardDevice
->CtrlOn
= 1;
585 UsbKeyboardDevice
->CtrlOn
= 0;
592 UsbKeyboardDevice
->AltOn
= 1;
594 UsbKeyboardDevice
->AltOn
= 0;
604 if (UsbKeyboardDevice
->CtrlOn
&& UsbKeyboardDevice
->AltOn
) {
605 gRT
->ResetSystem (EfiResetWarm
, EFI_SUCCESS
, 0, NULL
);
615 // insert the key back to the buffer.
616 // so the key sequence will not be destroyed.
619 &(UsbKeyboardDevice
->KeyboardBuffer
),
623 Index
= UsbKeyboardDevice
->KeyboardBuffer
.bHead
;
627 // If have new key pressed, update the RepeatKey value, and set the
628 // timer to repeate delay timer
630 if (NewRepeatKey
!= 0) {
632 // sets trigger time to "Repeat Delay Time",
633 // to trigger the repeat timer when the key is hold long
637 UsbKeyboardDevice
->RepeatTimer
,
641 UsbKeyboardDevice
->RepeatKey
= NewRepeatKey
;
649 IN OUT USB_KB_DEV
*UsbKeyboardDevice
,
655 Retrieves a key character after parsing the raw data in keyboard buffer.
658 UsbKeyboardDevice The USB_KB_DEV instance.
659 KeyChar Points to the Key character after key parsing.
662 EFI_SUCCESS - Success
663 EFI_NOT_READY - Device is not ready
670 while (!IsUSBKeyboardBufferEmpty (&UsbKeyboardDevice
->KeyboardBuffer
)) {
672 // pops one raw data off.
674 RemoveKeyCode (&(UsbKeyboardDevice
->KeyboardBuffer
), &UsbKey
);
677 switch (UsbKey
.KeyCode
) {
681 UsbKeyboardDevice
->CtrlOn
= 0;
686 UsbKeyboardDevice
->ShiftOn
= 0;
691 UsbKeyboardDevice
->AltOn
= 0;
702 // Analyzes key pressing situation
704 switch (UsbKey
.KeyCode
) {
708 UsbKeyboardDevice
->CtrlOn
= 1;
714 UsbKeyboardDevice
->ShiftOn
= 1;
720 UsbKeyboardDevice
->AltOn
= 1;
730 UsbKeyboardDevice
->NumLockOn
^= 1;
731 SetKeyLED (UsbKeyboardDevice
);
736 UsbKeyboardDevice
->CapsOn
^= 1;
737 SetKeyLED (UsbKeyboardDevice
);
742 // F11,F12,PrintScreen,ScrollLock,Pause,Application,Power
743 // keys are not valid EFI key
759 // Turn on the ScrollLock light on KB
761 UsbKeyboardDevice
->ScrollOn
^= 1;
762 SetKeyLED (UsbKeyboardDevice
);
779 // When encountered Del Key...
781 if (UsbKey
.KeyCode
== 0x4c || UsbKey
.KeyCode
== 0x63) {
782 if (UsbKeyboardDevice
->CtrlOn
&& UsbKeyboardDevice
->AltOn
) {
783 gRT
->ResetSystem (EfiResetWarm
, EFI_SUCCESS
, 0, NULL
);
787 *KeyChar
= UsbKey
.KeyCode
;
791 return EFI_NOT_READY
;
797 USBKeyCodeToEFIScanCode (
798 IN USB_KB_DEV
*UsbKeyboardDevice
,
800 OUT EFI_INPUT_KEY
*Key
805 Converts USB Keyboard code to EFI Scan Code.
808 UsbKeyboardDevice The USB_KB_DEV instance.
809 KeyChar Indicates the key code that will be interpreted.
810 Key A pointer to a buffer that is filled in with
811 the keystroke information for the key that
814 EFI_NOT_READY - Device is not ready
815 EFI_SUCCESS - Success
820 if (!USBKBD_VALID_KEYCODE (KeyChar
)) {
821 return EFI_NOT_READY
;
825 // valid USB Key Code starts from 4
827 Index
= (UINT8
) (KeyChar
- 4);
829 if (Index
>= USB_KEYCODE_MAX_MAKE
) {
830 return EFI_NOT_READY
;
833 Key
->ScanCode
= KeyConvertionTable
[Index
][0];
835 if (UsbKeyboardDevice
->ShiftOn
) {
837 Key
->UnicodeChar
= KeyConvertionTable
[Index
][2];
841 Key
->UnicodeChar
= KeyConvertionTable
[Index
][1];
844 if (UsbKeyboardDevice
->CapsOn
) {
846 if (Key
->UnicodeChar
>= 'a' && Key
->UnicodeChar
<= 'z') {
848 Key
->UnicodeChar
= KeyConvertionTable
[Index
][2];
850 } else if (Key
->UnicodeChar
>= 'A' && Key
->UnicodeChar
<= 'Z') {
852 Key
->UnicodeChar
= KeyConvertionTable
[Index
][1];
857 if (KeyChar
>= 0x59 && KeyChar
<= 0x63) {
859 if (UsbKeyboardDevice
->NumLockOn
&& !UsbKeyboardDevice
->ShiftOn
) {
861 Key
->ScanCode
= SCAN_NULL
;
865 Key
->UnicodeChar
= 0x00;
869 if (Key
->UnicodeChar
== 0 && Key
->ScanCode
== SCAN_NULL
) {
870 return EFI_NOT_READY
;
880 IN OUT USB_KB_BUFFER
*KeyboardBuffer
885 Resets USB Keyboard Buffer.
888 KeyboardBuffer - Points to the USB Keyboard Buffer.
891 EFI_SUCCESS - Success
894 ZeroMem (KeyboardBuffer
, sizeof (USB_KB_BUFFER
));
896 KeyboardBuffer
->bHead
= KeyboardBuffer
->bTail
;
902 IsUSBKeyboardBufferEmpty (
903 IN USB_KB_BUFFER
*KeyboardBuffer
908 Check whether USB Keyboard buffer is empty.
911 KeyboardBuffer - USB Keyboard Buffer.
918 // meet FIFO empty condition
920 return (BOOLEAN
) (KeyboardBuffer
->bHead
== KeyboardBuffer
->bTail
);
925 IsUSBKeyboardBufferFull (
926 IN USB_KB_BUFFER
*KeyboardBuffer
931 Check whether USB Keyboard buffer is full.
934 KeyboardBuffer - USB Keyboard Buffer.
940 return (BOOLEAN
)(((KeyboardBuffer
->bTail
+ 1) % (MAX_KEY_ALLOWED
+ 1)) ==
941 KeyboardBuffer
->bHead
);
947 IN OUT USB_KB_BUFFER
*KeyboardBuffer
,
954 Inserts a key code into keyboard buffer.
957 KeyboardBuffer - Points to the USB Keyboard Buffer.
961 EFI_SUCCESS - Success
967 // if keyboard buffer is full, throw the
968 // first key out of the keyboard buffer.
970 if (IsUSBKeyboardBufferFull (KeyboardBuffer
)) {
971 RemoveKeyCode (KeyboardBuffer
, &UsbKey
);
974 KeyboardBuffer
->buffer
[KeyboardBuffer
->bTail
].KeyCode
= Key
;
975 KeyboardBuffer
->buffer
[KeyboardBuffer
->bTail
].Down
= Down
;
978 // adjust the tail pointer of the FIFO keyboard buffer.
980 KeyboardBuffer
->bTail
= (UINT8
) ((KeyboardBuffer
->bTail
+ 1) % (MAX_KEY_ALLOWED
+ 1));
987 IN OUT USB_KB_BUFFER
*KeyboardBuffer
,
993 Pops a key code off from keyboard buffer.
996 KeyboardBuffer - Points to the USB Keyboard Buffer.
997 UsbKey - Points to the buffer that contains a usb key code.
1000 EFI_SUCCESS - Success
1001 EFI_DEVICE_ERROR - Hardware Error
1004 if (IsUSBKeyboardBufferEmpty (KeyboardBuffer
)) {
1005 return EFI_DEVICE_ERROR
;
1008 UsbKey
->KeyCode
= KeyboardBuffer
->buffer
[KeyboardBuffer
->bHead
].KeyCode
;
1009 UsbKey
->Down
= KeyboardBuffer
->buffer
[KeyboardBuffer
->bHead
].Down
;
1012 // adjust the head pointer of the FIFO keyboard buffer.
1014 KeyboardBuffer
->bHead
= (UINT8
) ((KeyboardBuffer
->bHead
+ 1) % (MAX_KEY_ALLOWED
+ 1));
1021 IN USB_KB_DEV
*UsbKeyboardDevice
1025 Routine Description:
1026 Sets USB Keyboard LED state.
1029 UsbKeyboardDevice - The USB_KB_DEV instance.
1032 EFI_SUCCESS - Success
1039 // Set each field in Led map.
1041 Led
.NumLock
= (UINT8
) UsbKeyboardDevice
->NumLockOn
;
1042 Led
.CapsLock
= (UINT8
) UsbKeyboardDevice
->CapsOn
;
1043 Led
.ScrollLock
= (UINT8
) UsbKeyboardDevice
->ScrollOn
;
1048 // call Set Report Request to lighten the LED.
1050 UsbSetReportRequest (
1051 UsbKeyboardDevice
->UsbIo
,
1052 UsbKeyboardDevice
->InterfaceDescriptor
.InterfaceNumber
,
1064 USBKeyboardRepeatHandler (
1070 Routine Description:
1071 Timer handler for Repeat Key timer.
1074 Event - The Repeat Key event.
1075 Context - Points to the USB_KB_DEV instance.
1081 USB_KB_DEV
*UsbKeyboardDevice
;
1083 UsbKeyboardDevice
= (USB_KB_DEV
*) Context
;
1086 // Do nothing when there is no repeat key.
1088 if (UsbKeyboardDevice
->RepeatKey
!= 0) {
1090 // Inserts one Repeat key into keyboard buffer,
1093 &(UsbKeyboardDevice
->KeyboardBuffer
),
1094 UsbKeyboardDevice
->RepeatKey
,
1099 // set repeate rate for repeat key generation.
1102 UsbKeyboardDevice
->RepeatTimer
,
1112 USBKeyboardRecoveryHandler (
1118 Routine Description:
1119 Timer handler for Delayed Recovery timer.
1122 Event - The Delayed Recovery event.
1123 Context - Points to the USB_KB_DEV instance.
1130 USB_KB_DEV
*UsbKeyboardDevice
;
1131 EFI_USB_IO_PROTOCOL
*UsbIo
;
1134 UsbKeyboardDevice
= (USB_KB_DEV
*) Context
;
1136 UsbIo
= UsbKeyboardDevice
->UsbIo
;
1138 PacketSize
= (UINT8
) (UsbKeyboardDevice
->IntEndpointDescriptor
.MaxPacketSize
);
1140 UsbIo
->UsbAsyncInterruptTransfer (
1142 UsbKeyboardDevice
->IntEndpointDescriptor
.EndpointAddress
,
1144 UsbKeyboardDevice
->IntEndpointDescriptor
.Interval
,