2 Helper functions for USB Keyboard Driver.
4 Copyright (c) 2004 - 2008, Intel Corporation
5 All rights reserved. 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
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.
18 // Default English keyboard layout
19 // Format:<efi key>, <unicode without shift>, <unicode with shift>, <Modifier>, <AffectedAttribute>
21 // According to Universal Serial Bus HID Usage Tables document ver 1.12,
22 // a Boot Keyboard should support the keycode range from 0x0 to 0x65 and 0xE0 to 0xE7.
23 // 0x0 to 0x3 are reserved for typical keyboard status or keyboard errors, so they are excluded.
25 UINT8 KeyboardLayoutTable
[NUMBER_OF_VALID_USB_KEYCODE
][5] = {
26 {EfiKeyC1
, 'a', 'A', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
| EFI_AFFECTED_BY_CAPS_LOCK
}, // 0x04
27 {EfiKeyB5
, 'b', 'B', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
| EFI_AFFECTED_BY_CAPS_LOCK
}, // 0x05
28 {EfiKeyB3
, 'c', 'C', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
| EFI_AFFECTED_BY_CAPS_LOCK
}, // 0x06
29 {EfiKeyC3
, 'd', 'D', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
| EFI_AFFECTED_BY_CAPS_LOCK
}, // 0x07
30 {EfiKeyD3
, 'e', 'E', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
| EFI_AFFECTED_BY_CAPS_LOCK
}, // 0x08
31 {EfiKeyC4
, 'f', 'F', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
| EFI_AFFECTED_BY_CAPS_LOCK
}, // 0x09
32 {EfiKeyC5
, 'g', 'G', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
| EFI_AFFECTED_BY_CAPS_LOCK
}, // 0x0A
33 {EfiKeyC6
, 'h', 'H', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
| EFI_AFFECTED_BY_CAPS_LOCK
}, // 0x0B
34 {EfiKeyD8
, 'i', 'I', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
| EFI_AFFECTED_BY_CAPS_LOCK
}, // 0x0C
35 {EfiKeyC7
, 'j', 'J', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
| EFI_AFFECTED_BY_CAPS_LOCK
}, // 0x0D
36 {EfiKeyC8
, 'k', 'K', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
| EFI_AFFECTED_BY_CAPS_LOCK
}, // 0x0E
37 {EfiKeyC9
, 'l', 'L', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
| EFI_AFFECTED_BY_CAPS_LOCK
}, // 0x0F
38 {EfiKeyB7
, 'm', 'M', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
| EFI_AFFECTED_BY_CAPS_LOCK
}, // 0x10
39 {EfiKeyB6
, 'n', 'N', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
| EFI_AFFECTED_BY_CAPS_LOCK
}, // 0x11
40 {EfiKeyD9
, 'o', 'O', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
| EFI_AFFECTED_BY_CAPS_LOCK
}, // 0x12
41 {EfiKeyD10
, 'p', 'P', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
| EFI_AFFECTED_BY_CAPS_LOCK
}, // 0x13
42 {EfiKeyD1
, 'q', 'Q', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
| EFI_AFFECTED_BY_CAPS_LOCK
}, // 0x14
43 {EfiKeyD4
, 'r', 'R', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
| EFI_AFFECTED_BY_CAPS_LOCK
}, // 0x15
44 {EfiKeyC2
, 's', 'S', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
| EFI_AFFECTED_BY_CAPS_LOCK
}, // 0x16
45 {EfiKeyD5
, 't', 'T', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
| EFI_AFFECTED_BY_CAPS_LOCK
}, // 0x17
46 {EfiKeyD7
, 'u', 'U', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
| EFI_AFFECTED_BY_CAPS_LOCK
}, // 0x18
47 {EfiKeyB4
, 'v', 'V', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
| EFI_AFFECTED_BY_CAPS_LOCK
}, // 0x19
48 {EfiKeyD2
, 'w', 'W', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
| EFI_AFFECTED_BY_CAPS_LOCK
}, // 0x1A
49 {EfiKeyB2
, 'x', 'X', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
| EFI_AFFECTED_BY_CAPS_LOCK
}, // 0x1B
50 {EfiKeyD6
, 'y', 'Y', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
| EFI_AFFECTED_BY_CAPS_LOCK
}, // 0x1C
51 {EfiKeyB1
, 'z', 'Z', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
| EFI_AFFECTED_BY_CAPS_LOCK
}, // 0x1D
52 {EfiKeyE1
, '1', '!', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
}, // 0x1E
53 {EfiKeyE2
, '2', '@', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
}, // 0x1F
54 {EfiKeyE3
, '3', '#', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
}, // 0x20
55 {EfiKeyE4
, '4', '$', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
}, // 0x21
56 {EfiKeyE5
, '5', '%', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
}, // 0x22
57 {EfiKeyE6
, '6', '^', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
}, // 0x23
58 {EfiKeyE7
, '7', '&', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
}, // 0x24
59 {EfiKeyE8
, '8', '*', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
}, // 0x25
60 {EfiKeyE9
, '9', '(', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
}, // 0x26
61 {EfiKeyE10
, '0', ')', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
}, // 0x27
62 {EfiKeyEnter
, 0x0d, 0x0d, EFI_NULL_MODIFIER
, 0}, // 0x28 Enter
63 {EfiKeyEsc
, 0x1b, 0x1b, EFI_NULL_MODIFIER
, 0}, // 0x29 Esc
64 {EfiKeyBackSpace
, 0x08, 0x08, EFI_NULL_MODIFIER
, 0}, // 0x2A Backspace
65 {EfiKeyTab
, 0x09, 0x09, EFI_NULL_MODIFIER
, 0}, // 0x2B Tab
66 {EfiKeySpaceBar
, ' ', ' ', EFI_NULL_MODIFIER
, 0}, // 0x2C Spacebar
67 {EfiKeyE11
, '-', '_', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
}, // 0x2D
68 {EfiKeyE12
, '=', '+', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
}, // 0x2E
69 {EfiKeyD11
, '[', '{', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
}, // 0x2F
70 {EfiKeyD12
, ']', '}', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
}, // 0x30
71 {EfiKeyD13
, '\\', '|', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
}, // 0x31
72 {EfiKeyC12
, '\\', '|', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
}, // 0x32 Keyboard Non-US # and ~
73 {EfiKeyC10
, ';', ':', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
}, // 0x33
74 {EfiKeyC11
, '\'', '"', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
}, // 0x34
75 {EfiKeyE0
, '`', '~', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
}, // 0x35 Keyboard Grave Accent and Tlide
76 {EfiKeyB8
, ',', '<', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
}, // 0x36
77 {EfiKeyB9
, '.', '>', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
}, // 0x37
78 {EfiKeyB10
, '/', '?', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
}, // 0x38
79 {EfiKeyCapsLock
, 0x00, 0x00, EFI_CAPS_LOCK_MODIFIER
, 0}, // 0x39 CapsLock
80 {EfiKeyF1
, 0x00, 0x00, EFI_FUNCTION_KEY_ONE_MODIFIER
, 0}, // 0x3A
81 {EfiKeyF2
, 0x00, 0x00, EFI_FUNCTION_KEY_TWO_MODIFIER
, 0}, // 0x3B
82 {EfiKeyF3
, 0x00, 0x00, EFI_FUNCTION_KEY_THREE_MODIFIER
, 0}, // 0x3C
83 {EfiKeyF4
, 0x00, 0x00, EFI_FUNCTION_KEY_FOUR_MODIFIER
, 0}, // 0x3D
84 {EfiKeyF5
, 0x00, 0x00, EFI_FUNCTION_KEY_FIVE_MODIFIER
, 0}, // 0x3E
85 {EfiKeyF6
, 0x00, 0x00, EFI_FUNCTION_KEY_SIX_MODIFIER
, 0}, // 0x3F
86 {EfiKeyF7
, 0x00, 0x00, EFI_FUNCTION_KEY_SEVEN_MODIFIER
, 0}, // 0x40
87 {EfiKeyF8
, 0x00, 0x00, EFI_FUNCTION_KEY_EIGHT_MODIFIER
, 0}, // 0x41
88 {EfiKeyF9
, 0x00, 0x00, EFI_FUNCTION_KEY_NINE_MODIFIER
, 0}, // 0x42
89 {EfiKeyF10
, 0x00, 0x00, EFI_FUNCTION_KEY_TEN_MODIFIER
, 0}, // 0x43
90 {EfiKeyF11
, 0x00, 0x00, EFI_FUNCTION_KEY_ELEVEN_MODIFIER
, 0}, // 0x44 F11
91 {EfiKeyF12
, 0x00, 0x00, EFI_FUNCTION_KEY_TWELVE_MODIFIER
, 0}, // 0x45 F12
92 {EfiKeyPrint
, 0x00, 0x00, EFI_PRINT_MODIFIER
, 0}, // 0x46 PrintScreen
93 {EfiKeySLck
, 0x00, 0x00, EFI_SCROLL_LOCK_MODIFIER
, 0}, // 0x47 Scroll Lock
94 {EfiKeyPause
, 0x00, 0x00, EFI_PAUSE_MODIFIER
, 0}, // 0x48 Pause
95 {EfiKeyIns
, 0x00, 0x00, EFI_INSERT_MODIFIER
, 0}, // 0x49
96 {EfiKeyHome
, 0x00, 0x00, EFI_HOME_MODIFIER
, 0}, // 0x4A
97 {EfiKeyPgUp
, 0x00, 0x00, EFI_PAGE_UP_MODIFIER
, 0}, // 0x4B
98 {EfiKeyDel
, 0x00, 0x00, EFI_DELETE_MODIFIER
, 0}, // 0x4C
99 {EfiKeyEnd
, 0x00, 0x00, EFI_END_MODIFIER
, 0}, // 0x4D
100 {EfiKeyPgDn
, 0x00, 0x00, EFI_PAGE_DOWN_MODIFIER
, 0}, // 0x4E
101 {EfiKeyRightArrow
, 0x00, 0x00, EFI_RIGHT_ARROW_MODIFIER
, 0}, // 0x4F
102 {EfiKeyLeftArrow
, 0x00, 0x00, EFI_LEFT_ARROW_MODIFIER
, 0}, // 0x50
103 {EfiKeyDownArrow
, 0x00, 0x00, EFI_DOWN_ARROW_MODIFIER
, 0}, // 0x51
104 {EfiKeyUpArrow
, 0x00, 0x00, EFI_UP_ARROW_MODIFIER
, 0}, // 0x52
105 {EfiKeyNLck
, 0x00, 0x00, EFI_NUM_LOCK_MODIFIER
, 0}, // 0x53 NumLock
106 {EfiKeySlash
, '/', '/', EFI_NULL_MODIFIER
, 0}, // 0x54
107 {EfiKeyAsterisk
, '*', '*', EFI_NULL_MODIFIER
, 0}, // 0x55
108 {EfiKeyMinus
, '-', '-', EFI_NULL_MODIFIER
, 0}, // 0x56
109 {EfiKeyPlus
, '+', '+', EFI_NULL_MODIFIER
, 0}, // 0x57
110 {EfiKeyEnter
, 0x0d, 0x0d, EFI_NULL_MODIFIER
, 0}, // 0x58
111 {EfiKeyOne
, '1', '1', EFI_END_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
| EFI_AFFECTED_BY_NUM_LOCK
}, // 0x59
112 {EfiKeyTwo
, '2', '2', EFI_DOWN_ARROW_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
| EFI_AFFECTED_BY_NUM_LOCK
}, // 0x5A
113 {EfiKeyThree
, '3', '3', EFI_PAGE_DOWN_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
| EFI_AFFECTED_BY_NUM_LOCK
}, // 0x5B
114 {EfiKeyFour
, '4', '4', EFI_LEFT_ARROW_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
| EFI_AFFECTED_BY_NUM_LOCK
}, // 0x5C
115 {EfiKeyFive
, '5', '5', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
| EFI_AFFECTED_BY_NUM_LOCK
}, // 0x5D
116 {EfiKeySix
, '6', '6', EFI_RIGHT_ARROW_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
| EFI_AFFECTED_BY_NUM_LOCK
}, // 0x5E
117 {EfiKeySeven
, '7', '7', EFI_HOME_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
| EFI_AFFECTED_BY_NUM_LOCK
}, // 0x5F
118 {EfiKeyEight
, '8', '8', EFI_UP_ARROW_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
| EFI_AFFECTED_BY_NUM_LOCK
}, // 0x60
119 {EfiKeyNine
, '9', '9', EFI_PAGE_UP_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
| EFI_AFFECTED_BY_NUM_LOCK
}, // 0x61
120 {EfiKeyZero
, '0', '0', EFI_INSERT_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
| EFI_AFFECTED_BY_NUM_LOCK
}, // 0x62
121 {EfiKeyPeriod
, '.', '.', EFI_DELETE_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
| EFI_AFFECTED_BY_NUM_LOCK
}, // 0x63
122 {EfiKeyB0
, '\\', '|', EFI_NULL_MODIFIER
, EFI_AFFECTED_BY_STANDARD_SHIFT
}, // 0x64 Keyboard Non-US \ and |
123 {EfiKeyA4
, 0x00, 0x00, EFI_MENU_MODIFIER
, 0}, // 0x65 Keyboard Application
125 {EfiKeyLCtrl
, 0, 0, EFI_LEFT_CONTROL_MODIFIER
, 0}, // 0xe0
126 {EfiKeyLShift
, 0, 0, EFI_LEFT_SHIFT_MODIFIER
, 0}, // 0xe1
127 {EfiKeyLAlt
, 0, 0, EFI_LEFT_ALT_MODIFIER
, 0}, // 0xe2
128 {EfiKeyA0
, 0, 0, EFI_LEFT_LOGO_MODIFIER
, 0}, // 0xe3
129 {EfiKeyRCtrl
, 0, 0, EFI_RIGHT_CONTROL_MODIFIER
, 0}, // 0xe4
130 {EfiKeyRShift
, 0, 0, EFI_RIGHT_SHIFT_MODIFIER
, 0}, // 0xe5
131 {EfiKeyA2
, 0, 0, EFI_RIGHT_ALT_MODIFIER
, 0}, // 0xe6
132 {EfiKeyA3
, 0, 0, EFI_RIGHT_LOGO_MODIFIER
, 0}, // 0xe7
136 // EFI_KEY to USB Keycode convertion table
137 // EFI_KEY is defined in UEFI spec.
138 // USB Keycode is defined in USB HID Firmware spec.
140 UINT8 EfiKeyToUsbKeyCodeConvertionTable
[] = {
144 0x2c, // EfiKeySpaceBar
149 0x50, // EfiKeyLeftArrow
150 0x51, // EfiKeyDownArrow
151 0x4F, // EfiKeyRightArrow
153 0x63, // EfiKeyPeriod
155 0xe1, // EfiKeyLShift
167 0xe5, // EfiKeyRShift
168 0x52, // EfiKeyUpArrow
172 0x39, // EfiKeyCapsLock
222 0x2A, // EfiKeyBackSpace
228 0x55, // EfiKeyAsterisk
249 // Keyboard modifier value to EFI Scan Code convertion table
250 // EFI Scan Code and the modifier values are defined in UEFI spec.
252 UINT8 ModifierValueToEfiScanCodeConvertionTable
[] = {
253 SCAN_NULL
, // EFI_NULL_MODIFIER
254 SCAN_NULL
, // EFI_LEFT_CONTROL_MODIFIER
255 SCAN_NULL
, // EFI_RIGHT_CONTROL_MODIFIER
256 SCAN_NULL
, // EFI_LEFT_ALT_MODIFIER
257 SCAN_NULL
, // EFI_RIGHT_ALT_MODIFIER
258 SCAN_NULL
, // EFI_ALT_GR_MODIFIER
259 SCAN_INSERT
, // EFI_INSERT_MODIFIER
260 SCAN_DELETE
, // EFI_DELETE_MODIFIER
261 SCAN_PAGE_DOWN
, // EFI_PAGE_DOWN_MODIFIER
262 SCAN_PAGE_UP
, // EFI_PAGE_UP_MODIFIER
263 SCAN_HOME
, // EFI_HOME_MODIFIER
264 SCAN_END
, // EFI_END_MODIFIER
265 SCAN_NULL
, // EFI_LEFT_SHIFT_MODIFIER
266 SCAN_NULL
, // EFI_RIGHT_SHIFT_MODIFIER
267 SCAN_NULL
, // EFI_CAPS_LOCK_MODIFIER
268 SCAN_NULL
, // EFI_NUM_LOCK_MODIFIER
269 SCAN_LEFT
, // EFI_LEFT_ARROW_MODIFIER
270 SCAN_RIGHT
, // EFI_RIGHT_ARROW_MODIFIER
271 SCAN_DOWN
, // EFI_DOWN_ARROW_MODIFIER
272 SCAN_UP
, // EFI_UP_ARROW_MODIFIER
273 SCAN_NULL
, // EFI_NS_KEY_MODIFIER
274 SCAN_NULL
, // EFI_NS_KEY_DEPENDENCY_MODIFIER
275 SCAN_F1
, // EFI_FUNCTION_KEY_ONE_MODIFIER
276 SCAN_F2
, // EFI_FUNCTION_KEY_TWO_MODIFIER
277 SCAN_F3
, // EFI_FUNCTION_KEY_THREE_MODIFIER
278 SCAN_F4
, // EFI_FUNCTION_KEY_FOUR_MODIFIER
279 SCAN_F5
, // EFI_FUNCTION_KEY_FIVE_MODIFIER
280 SCAN_F6
, // EFI_FUNCTION_KEY_SIX_MODIFIER
281 SCAN_F7
, // EFI_FUNCTION_KEY_SEVEN_MODIFIER
282 SCAN_F8
, // EFI_FUNCTION_KEY_EIGHT_MODIFIER
283 SCAN_F9
, // EFI_FUNCTION_KEY_NINE_MODIFIER
284 SCAN_F10
, // EFI_FUNCTION_KEY_TEN_MODIFIER
285 SCAN_F11
, // EFI_FUNCTION_KEY_ELEVEN_MODIFIER
286 SCAN_F12
, // EFI_FUNCTION_KEY_TWELVE_MODIFIER
289 EFI_GUID mKeyboardLayoutEventGuid
= EFI_HII_SET_KEYBOARD_LAYOUT_EVENT_GUID
;
292 Initialize Key Convertion Table by using default keyboard layout.
294 @param UsbKeyboardDevice The USB_KB_DEV instance.
299 LoadDefaultKeyboardLayout (
300 IN OUT USB_KB_DEV
*UsbKeyboardDevice
304 EFI_KEY_DESCRIPTOR
*KeyDescriptor
;
307 // Construct KeyConvertionTable by default keyboard layout
309 KeyDescriptor
= &UsbKeyboardDevice
->KeyConvertionTable
[0];
311 for (Index
= 0; Index
< (NUMBER_OF_VALID_USB_KEYCODE
); Index
++) {
312 KeyDescriptor
->Key
= (EFI_KEY
) KeyboardLayoutTable
[Index
][0];
313 KeyDescriptor
->Unicode
= KeyboardLayoutTable
[Index
][1];
314 KeyDescriptor
->ShiftedUnicode
= KeyboardLayoutTable
[Index
][2];
315 KeyDescriptor
->AltGrUnicode
= 0;
316 KeyDescriptor
->ShiftedAltGrUnicode
= 0;
317 KeyDescriptor
->Modifier
= KeyboardLayoutTable
[Index
][3];
318 KeyDescriptor
->AffectedAttribute
= KeyboardLayoutTable
[Index
][4];
325 Uses USB I/O to check whether the device is a USB keyboard device.
327 @param UsbIo Pointer to a USB I/O protocol instance.
329 @retval TRUE Device is a USB keyboard device.
330 @retval FALSE Device is a not USB keyboard device.
336 IN EFI_USB_IO_PROTOCOL
*UsbIo
340 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor
;
343 // Get the default interface descriptor
345 Status
= UsbIo
->UsbGetInterfaceDescriptor (
350 if (EFI_ERROR (Status
)) {
354 if (InterfaceDescriptor
.InterfaceClass
== CLASS_HID
&&
355 InterfaceDescriptor
.InterfaceSubClass
== SUBCLASS_BOOT
&&
356 InterfaceDescriptor
.InterfaceProtocol
== PROTOCOL_KEYBOARD
365 Get current keyboard layout from HII database.
367 @return Pointer to HII Keyboard Layout.
368 NULL means failure occurred while trying to get keyboard layout.
371 EFI_HII_KEYBOARD_LAYOUT
*
373 GetCurrentKeyboardLayout (
378 EFI_HII_DATABASE_PROTOCOL
*HiiDatabase
;
379 EFI_HII_KEYBOARD_LAYOUT
*KeyboardLayout
;
383 // Locate HII Database Protocol
385 Status
= gBS
->LocateProtocol (
386 &gEfiHiiDatabaseProtocolGuid
,
388 (VOID
**) &HiiDatabase
390 if (EFI_ERROR (Status
)) {
395 // Get current keyboard layout from HII database
398 KeyboardLayout
= NULL
;
399 Status
= HiiDatabase
->GetKeyboardLayout (
405 if (Status
== EFI_BUFFER_TOO_SMALL
) {
406 KeyboardLayout
= AllocatePool (Length
);
407 ASSERT (KeyboardLayout
!= NULL
);
409 Status
= HiiDatabase
->GetKeyboardLayout (
415 if (EFI_ERROR (Status
)) {
416 gBS
->FreePool (KeyboardLayout
);
417 KeyboardLayout
= NULL
;
421 return KeyboardLayout
;
425 Find Key Descriptor in Key Convertion Table given its USB keycode.
427 @param UsbKeyboardDevice The USB_KB_DEV instance.
428 @param KeyCode USB Keycode.
430 @return The Key Descriptor in Key Convertion Table.
431 NULL means not found.
437 IN USB_KB_DEV
*UsbKeyboardDevice
,
444 // Make sure KeyCode is in the range of [0x4, 0x65] or [0xe0, 0xe7]
446 if ((!USBKBD_VALID_KEYCODE (KeyCode
)) || ((KeyCode
> 0x65) && (KeyCode
< 0xe0)) || (KeyCode
> 0xe7)) {
451 // Calculate the index of Key Descriptor in Key Convertion Table
453 if (KeyCode
<= 0x65) {
454 Index
= (UINT8
) (KeyCode
- 4);
456 Index
= (UINT8
) (KeyCode
- 0xe0 + NUMBER_OF_VALID_NON_MODIFIER_USB_KEYCODE
);
459 return &UsbKeyboardDevice
->KeyConvertionTable
[Index
];
463 Find Non-Spacing key for given Key descriptor.
465 @param UsbKeyboardDevice The USB_KB_DEV instance.
466 @param KeyDescriptor Key descriptor.
468 @return The Non-Spacing key corresponding to KeyDescriptor
469 NULL means not found.
475 IN USB_KB_DEV
*UsbKeyboardDevice
,
476 IN EFI_KEY_DESCRIPTOR
*KeyDescriptor
480 LIST_ENTRY
*NsKeyList
;
481 USB_NS_KEY
*UsbNsKey
;
483 NsKeyList
= &UsbKeyboardDevice
->NsKeyList
;
484 Link
= GetFirstNode (NsKeyList
);
485 while (!IsNull (NsKeyList
, Link
)) {
486 UsbNsKey
= USB_NS_KEY_FORM_FROM_LINK (Link
);
488 if (UsbNsKey
->NsKey
[0].Key
== KeyDescriptor
->Key
) {
492 Link
= GetNextNode (NsKeyList
, Link
);
499 Find physical key definition for a given key descriptor.
501 For a specified non-spacing key, there are a list of physical
502 keys following it. This function traverses the list of
503 physical keys and tries to find the physical key matching
506 @param UsbNsKey The non-spacing key information.
507 @param KeyDescriptor The key descriptor.
509 @return The physical key definition.
510 If no physical key is found, parameter KeyDescriptor is returned.
516 IN USB_NS_KEY
*UsbNsKey
,
517 IN EFI_KEY_DESCRIPTOR
*KeyDescriptor
521 EFI_KEY_DESCRIPTOR
*PhysicalKey
;
523 PhysicalKey
= &UsbNsKey
->NsKey
[1];
524 for (Index
= 0; Index
< UsbNsKey
->KeyCount
; Index
++) {
525 if (KeyDescriptor
->Key
== PhysicalKey
->Key
) {
533 // No children definition matched, return original key
535 return KeyDescriptor
;
539 The notification function for EFI_HII_SET_KEYBOARD_LAYOUT_EVENT_GUID.
541 This function is registered to event of EFI_HII_SET_KEYBOARD_LAYOUT_EVENT_GUID
542 group type, which will be triggered by EFI_HII_DATABASE_PROTOCOL.SetKeyboardLayout().
543 It tries to get curent keyboard layout from HII database.
545 @param Event Event being signaled.
546 @param Context Points to USB_KB_DEV instance.
551 SetKeyboardLayoutEvent (
556 USB_KB_DEV
*UsbKeyboardDevice
;
557 EFI_HII_KEYBOARD_LAYOUT
*KeyboardLayout
;
558 EFI_KEY_DESCRIPTOR TempKey
;
559 EFI_KEY_DESCRIPTOR
*KeyDescriptor
;
560 EFI_KEY_DESCRIPTOR
*TableEntry
;
561 EFI_KEY_DESCRIPTOR
*NsKey
;
562 USB_NS_KEY
*UsbNsKey
;
568 UsbKeyboardDevice
= (USB_KB_DEV
*) Context
;
571 // Try to get current keyboard layout from HII database
573 KeyboardLayout
= GetCurrentKeyboardLayout ();
574 if (KeyboardLayout
== NULL
) {
579 // Re-allocate resource for KeyConvertionTable
581 ReleaseKeyboardLayoutResources (UsbKeyboardDevice
);
582 UsbKeyboardDevice
->KeyConvertionTable
= AllocateZeroPool ((NUMBER_OF_VALID_USB_KEYCODE
) * sizeof (EFI_KEY_DESCRIPTOR
));
583 ASSERT (UsbKeyboardDevice
->KeyConvertionTable
!= NULL
);
586 // Traverse the list of key descriptors following the header of EFI_HII_KEYBOARD_LAYOUT
588 KeyDescriptor
= (EFI_KEY_DESCRIPTOR
*) (((UINT8
*) KeyboardLayout
) + sizeof (EFI_HII_KEYBOARD_LAYOUT
));
589 for (Index
= 0; Index
< KeyboardLayout
->DescriptorCount
; Index
++) {
591 // Copy from HII keyboard layout package binary for alignment
593 CopyMem (&TempKey
, KeyDescriptor
, sizeof (EFI_KEY_DESCRIPTOR
));
596 // Fill the key into KeyConvertionTable, whose index is calculated from USB keycode.
598 KeyCode
= EfiKeyToUsbKeyCodeConvertionTable
[(UINT8
) (TempKey
.Key
)];
599 TableEntry
= GetKeyDescriptor (UsbKeyboardDevice
, KeyCode
);
600 CopyMem (TableEntry
, KeyDescriptor
, sizeof (EFI_KEY_DESCRIPTOR
));
603 // For non-spacing key, create the list with a non-spacing key followed by physical keys.
605 if (TempKey
.Modifier
== EFI_NS_KEY_MODIFIER
) {
606 UsbNsKey
= AllocatePool (sizeof (USB_NS_KEY
));
607 ASSERT (UsbNsKey
!= NULL
);
610 // Search for sequential children physical key definitions
613 NsKey
= KeyDescriptor
+ 1;
614 for (Index2
= Index
+ 1; Index2
< KeyboardLayout
->DescriptorCount
; Index2
++) {
615 CopyMem (&TempKey
, NsKey
, sizeof (EFI_KEY_DESCRIPTOR
));
616 if (TempKey
.Modifier
& EFI_NS_KEY_DEPENDENCY_MODIFIER
) {
624 UsbNsKey
->Signature
= USB_NS_KEY_SIGNATURE
;
625 UsbNsKey
->KeyCount
= KeyCount
;
626 UsbNsKey
->NsKey
= AllocateCopyPool (
627 (KeyCount
+ 1) * sizeof (EFI_KEY_DESCRIPTOR
),
630 InsertTailList (&UsbKeyboardDevice
->NsKeyList
, &UsbNsKey
->Link
);
633 // Skip over the child physical keys
636 KeyDescriptor
+= KeyCount
;
643 // There are two EfiKeyEnter, duplicate its key descriptor
645 TableEntry
= GetKeyDescriptor (UsbKeyboardDevice
, 0x58);
646 KeyDescriptor
= GetKeyDescriptor (UsbKeyboardDevice
, 0x28);
647 CopyMem (TableEntry
, KeyDescriptor
, sizeof (EFI_KEY_DESCRIPTOR
));
649 FreePool (KeyboardLayout
);
653 Destroy resources for keyboard layout.
655 @param UsbKeyboardDevice The USB_KB_DEV instance.
660 ReleaseKeyboardLayoutResources (
661 IN OUT USB_KB_DEV
*UsbKeyboardDevice
664 USB_NS_KEY
*UsbNsKey
;
667 if (UsbKeyboardDevice
->KeyConvertionTable
!= NULL
) {
668 FreePool (UsbKeyboardDevice
->KeyConvertionTable
);
670 UsbKeyboardDevice
->KeyConvertionTable
= NULL
;
672 while (!IsListEmpty (&UsbKeyboardDevice
->NsKeyList
)) {
673 Link
= GetFirstNode (&UsbKeyboardDevice
->NsKeyList
);
674 UsbNsKey
= USB_NS_KEY_FORM_FROM_LINK (Link
);
675 RemoveEntryList (&UsbNsKey
->Link
);
677 FreePool (UsbNsKey
->NsKey
);
683 Initialize USB keyboard layout.
685 This function initializes Key Convertion Table for the USB keyboard device.
686 It first tries to retrieve layout from HII database. If failed and default
687 layout is enabled, then it just uses the default layout.
689 @param UsbKeyboardDevice The USB_KB_DEV instance.
691 @retval EFI_SUCCESS Initialization succeeded.
692 @retval EFI_NOT_READY Keyboard layout cannot be retrieve from HII
693 database, and default layout is disabled.
694 @retval Other Fail to register event to EFI_HII_SET_KEYBOARD_LAYOUT_EVENT_GUID group.
700 OUT USB_KB_DEV
*UsbKeyboardDevice
703 EFI_HII_KEYBOARD_LAYOUT
*KeyboardLayout
;
706 UsbKeyboardDevice
->KeyConvertionTable
= AllocateZeroPool ((NUMBER_OF_VALID_USB_KEYCODE
) * sizeof (EFI_KEY_DESCRIPTOR
));
707 ASSERT (UsbKeyboardDevice
->KeyConvertionTable
!= NULL
);
709 InitializeListHead (&UsbKeyboardDevice
->NsKeyList
);
710 UsbKeyboardDevice
->CurrentNsKey
= NULL
;
711 UsbKeyboardDevice
->KeyboardLayoutEvent
= NULL
;
714 // Register event to EFI_HII_SET_KEYBOARD_LAYOUT_EVENT_GUID group,
715 // which will be triggered by EFI_HII_DATABASE_PROTOCOL.SetKeyboardLayout().
717 Status
= gBS
->CreateEventEx (
720 SetKeyboardLayoutEvent
,
722 &mKeyboardLayoutEventGuid
,
723 &UsbKeyboardDevice
->KeyboardLayoutEvent
725 if (EFI_ERROR (Status
)) {
729 KeyboardLayout
= GetCurrentKeyboardLayout ();
730 if (KeyboardLayout
!= NULL
) {
732 // If current keyboard layout is successfully retrieved from HII database,
733 // force to initialize the keyboard layout.
735 gBS
->SignalEvent (UsbKeyboardDevice
->KeyboardLayoutEvent
);
737 if (FeaturePcdGet (PcdDisableDefaultKeyboardLayoutInUsbKbDriver
)) {
739 // If no keyboard layout can be retrieved from HII database, and default layout
740 // is disabled, then return EFI_NOT_READY.
742 return EFI_NOT_READY
;
745 // If no keyboard layout can be retrieved from HII database, and default layout
746 // is enabled, then load the default keyboard layout.
748 LoadDefaultKeyboardLayout (UsbKeyboardDevice
);
756 Initialize USB keyboard device and all private data structures.
758 @param UsbKeyboardDevice The USB_KB_DEV instance.
760 @retval EFI_SUCCESS Initialization is successful.
761 @retval EFI_DEVICE_ERROR Keyboard initialization failed.
767 IN OUT USB_KB_DEV
*UsbKeyboardDevice
775 UINT32 TransferResult
;
777 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
779 PcdGet32 (PcdStatusCodeValueKeyboardSelfTest
),
780 UsbKeyboardDevice
->DevicePath
783 InitUSBKeyBuffer (&(UsbKeyboardDevice
->KeyboardBuffer
));
786 // Uses default configuration to configure the USB keyboard device.
789 Status
= UsbSetConfiguration (
790 UsbKeyboardDevice
->UsbIo
,
791 (UINT16
) ConfigValue
,
794 if (EFI_ERROR (Status
)) {
796 // If configuration could not be set here, it means
797 // the keyboard interface has some errors and could
798 // not be initialized
800 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
801 EFI_ERROR_CODE
| EFI_ERROR_MINOR
,
802 PcdGet32 (PcdStatusCodeValueKeyboardInterfaceError
),
803 UsbKeyboardDevice
->DevicePath
806 return EFI_DEVICE_ERROR
;
809 UsbGetProtocolRequest (
810 UsbKeyboardDevice
->UsbIo
,
811 UsbKeyboardDevice
->InterfaceDescriptor
.InterfaceNumber
,
815 // Set boot protocol for the USB Keyboard.
816 // This driver only supports boot protocol.
817 // The device that does not support boot protocol is not supported.
819 if (Protocol
!= BOOT_PROTOCOL
) {
820 UsbSetProtocolRequest (
821 UsbKeyboardDevice
->UsbIo
,
822 UsbKeyboardDevice
->InterfaceDescriptor
.InterfaceNumber
,
828 // ReportId is zero, which means the idle rate applies to all input reports.
832 // Duration is zero, which means the duration is infinite.
833 // so the endpoint will inhibit reporting forever,
834 // and only reporting when a change is detected in the report data.
838 UsbKeyboardDevice
->UsbIo
,
839 UsbKeyboardDevice
->InterfaceDescriptor
.InterfaceNumber
,
844 UsbKeyboardDevice
->CtrlOn
= FALSE
;
845 UsbKeyboardDevice
->AltOn
= FALSE
;
846 UsbKeyboardDevice
->ShiftOn
= FALSE
;
847 UsbKeyboardDevice
->NumLockOn
= FALSE
;
848 UsbKeyboardDevice
->CapsOn
= FALSE
;
849 UsbKeyboardDevice
->ScrollOn
= FALSE
;
851 UsbKeyboardDevice
->LeftCtrlOn
= FALSE
;
852 UsbKeyboardDevice
->LeftAltOn
= FALSE
;
853 UsbKeyboardDevice
->LeftShiftOn
= FALSE
;
854 UsbKeyboardDevice
->LeftLogoOn
= FALSE
;
855 UsbKeyboardDevice
->RightCtrlOn
= FALSE
;
856 UsbKeyboardDevice
->RightAltOn
= FALSE
;
857 UsbKeyboardDevice
->RightShiftOn
= FALSE
;
858 UsbKeyboardDevice
->RightLogoOn
= FALSE
;
859 UsbKeyboardDevice
->MenuKeyOn
= FALSE
;
860 UsbKeyboardDevice
->SysReqOn
= FALSE
;
862 UsbKeyboardDevice
->AltGrOn
= FALSE
;
864 UsbKeyboardDevice
->CurrentNsKey
= NULL
;
867 // Sync the initial state of lights on keyboard.
869 SetKeyLED (UsbKeyboardDevice
);
871 ZeroMem (UsbKeyboardDevice
->LastKeyCodeArray
, sizeof (UINT8
) * 8);
874 // Set a timer for repeat keys' generation.
876 if (UsbKeyboardDevice
->RepeatTimer
!= NULL
) {
877 gBS
->CloseEvent (UsbKeyboardDevice
->RepeatTimer
);
878 UsbKeyboardDevice
->RepeatTimer
= NULL
;
881 Status
= gBS
->CreateEvent (
882 EVT_TIMER
| EVT_NOTIFY_SIGNAL
,
884 USBKeyboardRepeatHandler
,
886 &UsbKeyboardDevice
->RepeatTimer
889 if (UsbKeyboardDevice
->DelayedRecoveryEvent
!= NULL
) {
890 gBS
->CloseEvent (UsbKeyboardDevice
->DelayedRecoveryEvent
);
891 UsbKeyboardDevice
->DelayedRecoveryEvent
= NULL
;
894 Status
= gBS
->CreateEvent (
895 EVT_TIMER
| EVT_NOTIFY_SIGNAL
,
897 USBKeyboardRecoveryHandler
,
899 &UsbKeyboardDevice
->DelayedRecoveryEvent
907 Handler function for USB keyboard's asynchronous interrupt transfer.
909 This function is the handler function for USB keyboard's asynchronous interrupt transfer
910 to manage the keyboard. It parses the USB keyboard input report, and inserts data to
911 keyboard buffer according to state of modifer keys and normal keys. Timer for repeat key
912 is also set accordingly.
914 @param Data A pointer to a buffer that is filled with key data which is
915 retrieved via asynchronous interrupt transfer.
916 @param DataLength Indicates the size of the data buffer.
917 @param Context Pointing to USB_KB_DEV instance.
918 @param Result Indicates the result of the asynchronous interrupt transfer.
920 @retval EFI_SUCCESS Asynchronous interrupt transfer is handled successfully.
921 @retval EFI_DEVICE_ERROR Hardware error occurs.
933 USB_KB_DEV
*UsbKeyboardDevice
;
934 EFI_USB_IO_PROTOCOL
*UsbIo
;
935 UINT8
*CurKeyCodeBuffer
;
936 UINT8
*OldKeyCodeBuffer
;
937 UINT8 CurModifierMap
;
938 UINT8 OldModifierMap
;
949 EFI_KEY_DESCRIPTOR
*KeyDescriptor
;
951 ASSERT (Context
!= NULL
);
954 UsbKeyboardDevice
= (USB_KB_DEV
*) Context
;
955 UsbIo
= UsbKeyboardDevice
->UsbIo
;
958 // Analyzes Result and performs corresponding action.
960 if (Result
!= EFI_USB_NOERROR
) {
962 // Some errors happen during the process
964 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
965 EFI_ERROR_CODE
| EFI_ERROR_MINOR
,
966 PcdGet32 (PcdStatusCodeValueKeyboardInputError
),
967 UsbKeyboardDevice
->DevicePath
971 // Stop the repeat key generation if any
973 UsbKeyboardDevice
->RepeatKey
= 0;
976 UsbKeyboardDevice
->RepeatTimer
,
981 if ((Result
& EFI_USB_ERR_STALL
) == EFI_USB_ERR_STALL
) {
982 UsbClearEndpointHalt (
984 UsbKeyboardDevice
->IntEndpointDescriptor
.EndpointAddress
,
990 // Delete & Submit this interrupt again
991 // Handler of DelayedRecoveryEvent triggered by timer will re-submit the interrupt.
993 UsbIo
->UsbAsyncInterruptTransfer (
995 UsbKeyboardDevice
->IntEndpointDescriptor
.EndpointAddress
,
1003 // EFI_USB_INTERRUPT_DELAY is defined in USB standard for error handling.
1006 UsbKeyboardDevice
->DelayedRecoveryEvent
,
1008 EFI_USB_INTERRUPT_DELAY
1011 return EFI_DEVICE_ERROR
;
1015 // If no error and no data, just return EFI_SUCCESS.
1017 if (DataLength
== 0 || Data
== NULL
) {
1022 // Following code checks current keyboard input report against old key code buffer.
1023 // According to USB HID Firmware Specification, the report consists of 8 bytes.
1024 // Byte 0 is map of Modifier keys.
1025 // Byte 1 is reserved.
1026 // Bytes 2 to 7 are keycodes.
1028 CurKeyCodeBuffer
= (UINT8
*) Data
;
1029 OldKeyCodeBuffer
= UsbKeyboardDevice
->LastKeyCodeArray
;
1032 // Checks for new key stroke.
1034 for (Index
= 0; Index
< 8; Index
++) {
1035 if (OldKeyCodeBuffer
[Index
] != CurKeyCodeBuffer
[Index
]) {
1041 // If no new key, return EFI_SUCCESS immediately.
1048 // Parse the modifier key, which is the first byte of keyboard input report.
1050 CurModifierMap
= CurKeyCodeBuffer
[0];
1051 OldModifierMap
= OldKeyCodeBuffer
[0];
1054 // Handle modifier key's pressing or releasing situation.
1055 // According to USB HID Firmware spec, Byte 0 uses folloing map of Modifier keys:
1056 // Bit0: Left Control, Keycode: 0xe0
1057 // Bit1: Left Shift, Keycode: 0xe1
1058 // Bit2: Left Alt, Keycode: 0xe2
1059 // Bit3: Left GUI, Keycode: 0xe3
1060 // Bit4: Right Control, Keycode: 0xe4
1061 // Bit5: Right Shift, Keycode: 0xe5
1062 // Bit6: Right Alt, Keycode: 0xe6
1063 // Bit7: Right GUI, Keycode: 0xe7
1065 for (Index
= 0; Index
< 8; Index
++) {
1066 Mask
= (UINT8
) (1 << Index
);
1067 if ((CurModifierMap
& Mask
) != (OldModifierMap
& Mask
)) {
1069 // If current modifier key is up, then CurModifierMap & Mask = 0;
1070 // otherwise it is a non-zero value.
1071 // Insert the changed modifier key into key buffer.
1073 Down
= (BOOLEAN
) ((CurModifierMap
& Mask
) != 0);
1074 InsertKeyCode (&(UsbKeyboardDevice
->KeyboardBuffer
), (UINT8
) (0xe0 + Index
), Down
);
1079 // Handle normal key's releasing situation
1080 // Bytes 2 to 7 are for normal keycodes
1083 for (Index
= 2; Index
< 8; Index
++) {
1085 if (!USBKBD_VALID_KEYCODE (OldKeyCodeBuffer
[Index
])) {
1089 // For any key in old keycode buffer, if it is not in current keycode buffer,
1090 // then it is released. Otherwise, it is not released.
1093 for (Index2
= 2; Index2
< 8; Index2
++) {
1095 if (!USBKBD_VALID_KEYCODE (CurKeyCodeBuffer
[Index2
])) {
1099 if (OldKeyCodeBuffer
[Index
] == CurKeyCodeBuffer
[Index2
]) {
1107 &(UsbKeyboardDevice
->KeyboardBuffer
),
1108 OldKeyCodeBuffer
[Index
],
1112 // The original repeat key is released.
1114 if (OldKeyCodeBuffer
[Index
] == UsbKeyboardDevice
->RepeatKey
) {
1115 UsbKeyboardDevice
->RepeatKey
= 0;
1121 // If original repeat key is released, cancel the repeat timer
1123 if (UsbKeyboardDevice
->RepeatKey
== 0) {
1125 UsbKeyboardDevice
->RepeatTimer
,
1132 // Handle normal key's pressing situation
1135 for (Index
= 2; Index
< 8; Index
++) {
1137 if (!USBKBD_VALID_KEYCODE (CurKeyCodeBuffer
[Index
])) {
1141 // For any key in current keycode buffer, if it is not in old keycode buffer,
1142 // then it is pressed. Otherwise, it is not pressed.
1145 for (Index2
= 2; Index2
< 8; Index2
++) {
1147 if (!USBKBD_VALID_KEYCODE (OldKeyCodeBuffer
[Index2
])) {
1151 if (CurKeyCodeBuffer
[Index
] == OldKeyCodeBuffer
[Index2
]) {
1158 InsertKeyCode (&(UsbKeyboardDevice
->KeyboardBuffer
), CurKeyCodeBuffer
[Index
], TRUE
);
1161 // Handle repeat key
1163 KeyDescriptor
= GetKeyDescriptor (UsbKeyboardDevice
, CurKeyCodeBuffer
[Index
]);
1164 if (KeyDescriptor
->Modifier
== EFI_NUM_LOCK_MODIFIER
|| KeyDescriptor
->Modifier
== EFI_CAPS_LOCK_MODIFIER
) {
1166 // For NumLock or CapsLock pressed, there is no need to handle repeat key for them.
1168 UsbKeyboardDevice
->RepeatKey
= 0;
1171 // Prepare new repeat key, and clear the original one.
1173 NewRepeatKey
= CurKeyCodeBuffer
[Index
];
1174 UsbKeyboardDevice
->RepeatKey
= 0;
1180 // Update LastKeycodeArray buffer in the UsbKeyboardDevice data structure.
1182 for (Index
= 0; Index
< 8; Index
++) {
1183 UsbKeyboardDevice
->LastKeyCodeArray
[Index
] = CurKeyCodeBuffer
[Index
];
1187 // Pre-process KeyboardBuffer to check if Ctrl + Alt + Del is pressed.
1189 SavedTail
= UsbKeyboardDevice
->KeyboardBuffer
.BufferTail
;
1190 Index
= UsbKeyboardDevice
->KeyboardBuffer
.BufferHead
;
1191 while (Index
!= SavedTail
) {
1192 RemoveKeyCode (&(UsbKeyboardDevice
->KeyboardBuffer
), &UsbKey
);
1194 KeyDescriptor
= GetKeyDescriptor (UsbKeyboardDevice
, UsbKey
.KeyCode
);
1196 switch (KeyDescriptor
->Modifier
) {
1198 case EFI_LEFT_CONTROL_MODIFIER
:
1199 case EFI_RIGHT_CONTROL_MODIFIER
:
1201 UsbKeyboardDevice
->CtrlOn
= TRUE
;
1203 UsbKeyboardDevice
->CtrlOn
= FALSE
;
1207 case EFI_LEFT_ALT_MODIFIER
:
1208 case EFI_RIGHT_ALT_MODIFIER
:
1210 UsbKeyboardDevice
->AltOn
= TRUE
;
1212 UsbKeyboardDevice
->AltOn
= FALSE
;
1216 case EFI_ALT_GR_MODIFIER
:
1218 UsbKeyboardDevice
->AltGrOn
= TRUE
;
1220 UsbKeyboardDevice
->AltGrOn
= FALSE
;
1225 // For Del Key, check if Ctrl + Alt + Del occurs for reset.
1227 case EFI_DELETE_MODIFIER
:
1229 if ((UsbKeyboardDevice
->CtrlOn
) && (UsbKeyboardDevice
->AltOn
)) {
1230 gRT
->ResetSystem (EfiResetWarm
, EFI_SUCCESS
, 0, NULL
);
1240 // Insert the key back to the buffer,
1241 // so the key sequence will not be destroyed.
1244 &(UsbKeyboardDevice
->KeyboardBuffer
),
1248 Index
= UsbKeyboardDevice
->KeyboardBuffer
.BufferHead
;
1252 // If there is new key pressed, update the RepeatKey value, and set the
1253 // timer to repeate delay timer
1255 if (NewRepeatKey
!= 0) {
1257 // Sets trigger time to "Repeat Delay Time",
1258 // to trigger the repeat timer when the key is hold long
1262 UsbKeyboardDevice
->RepeatTimer
,
1266 UsbKeyboardDevice
->RepeatKey
= NewRepeatKey
;
1274 Retrieves a USB keycode after parsing the raw data in keyboard buffer.
1276 This function parses keyboard buffer. It updates state of modifier key for
1277 USB_KB_DEV instancem, and returns keycode for output.
1279 @param UsbKeyboardDevice The USB_KB_DEV instance.
1280 @param KeyCode Pointer to the USB keycode for output.
1282 @retval EFI_SUCCESS Keycode successfully parsed.
1283 @retval EFI_NOT_READY Keyboard buffer is not ready for a valid keycode
1289 IN OUT USB_KB_DEV
*UsbKeyboardDevice
,
1294 EFI_KEY_DESCRIPTOR
*KeyDescriptor
;
1298 while (!IsUSBKeyboardBufferEmpty (&UsbKeyboardDevice
->KeyboardBuffer
)) {
1300 // Pops one raw data off.
1302 RemoveKeyCode (&(UsbKeyboardDevice
->KeyboardBuffer
), &UsbKey
);
1304 KeyDescriptor
= GetKeyDescriptor (UsbKeyboardDevice
, UsbKey
.KeyCode
);
1309 switch (KeyDescriptor
->Modifier
) {
1314 case EFI_LEFT_CONTROL_MODIFIER
:
1315 UsbKeyboardDevice
->LeftCtrlOn
= FALSE
;
1316 UsbKeyboardDevice
->CtrlOn
= FALSE
;
1318 case EFI_RIGHT_CONTROL_MODIFIER
:
1319 UsbKeyboardDevice
->RightCtrlOn
= FALSE
;
1320 UsbKeyboardDevice
->CtrlOn
= FALSE
;
1326 case EFI_LEFT_SHIFT_MODIFIER
:
1327 UsbKeyboardDevice
->LeftShiftOn
= FALSE
;
1328 UsbKeyboardDevice
->ShiftOn
= FALSE
;
1330 case EFI_RIGHT_SHIFT_MODIFIER
:
1331 UsbKeyboardDevice
->RightShiftOn
= FALSE
;
1332 UsbKeyboardDevice
->ShiftOn
= FALSE
;
1338 case EFI_LEFT_ALT_MODIFIER
:
1339 UsbKeyboardDevice
->LeftAltOn
= FALSE
;
1340 UsbKeyboardDevice
->AltOn
= FALSE
;
1342 case EFI_RIGHT_ALT_MODIFIER
:
1343 UsbKeyboardDevice
->RightAltOn
= FALSE
;
1344 UsbKeyboardDevice
->AltOn
= FALSE
;
1348 // Left Logo release
1350 case EFI_LEFT_LOGO_MODIFIER
:
1351 UsbKeyboardDevice
->LeftLogoOn
= FALSE
;
1355 // Right Logo release
1357 case EFI_RIGHT_LOGO_MODIFIER
:
1358 UsbKeyboardDevice
->RightLogoOn
= FALSE
;
1364 case EFI_MENU_MODIFIER
:
1365 UsbKeyboardDevice
->MenuKeyOn
= FALSE
;
1371 case EFI_PRINT_MODIFIER
:
1372 case EFI_SYS_REQUEST_MODIFIER
:
1373 UsbKeyboardDevice
->SysReqOn
= FALSE
;
1379 case EFI_ALT_GR_MODIFIER
:
1380 UsbKeyboardDevice
->AltGrOn
= FALSE
;
1391 // Analyzes key pressing situation
1393 switch (KeyDescriptor
->Modifier
) {
1398 case EFI_LEFT_CONTROL_MODIFIER
:
1399 UsbKeyboardDevice
->LeftCtrlOn
= TRUE
;
1400 UsbKeyboardDevice
->CtrlOn
= TRUE
;
1403 case EFI_RIGHT_CONTROL_MODIFIER
:
1404 UsbKeyboardDevice
->RightCtrlOn
= TRUE
;
1405 UsbKeyboardDevice
->CtrlOn
= TRUE
;
1412 case EFI_LEFT_SHIFT_MODIFIER
:
1413 UsbKeyboardDevice
->LeftShiftOn
= TRUE
;
1414 UsbKeyboardDevice
->ShiftOn
= TRUE
;
1417 case EFI_RIGHT_SHIFT_MODIFIER
:
1418 UsbKeyboardDevice
->RightShiftOn
= TRUE
;
1419 UsbKeyboardDevice
->ShiftOn
= TRUE
;
1426 case EFI_LEFT_ALT_MODIFIER
:
1427 UsbKeyboardDevice
->LeftAltOn
= TRUE
;
1428 UsbKeyboardDevice
->AltOn
= TRUE
;
1431 case EFI_RIGHT_ALT_MODIFIER
:
1432 UsbKeyboardDevice
->RightAltOn
= TRUE
;
1433 UsbKeyboardDevice
->AltOn
= TRUE
;
1440 case EFI_LEFT_LOGO_MODIFIER
:
1441 UsbKeyboardDevice
->LeftLogoOn
= TRUE
;
1447 case EFI_RIGHT_LOGO_MODIFIER
:
1448 UsbKeyboardDevice
->RightLogoOn
= TRUE
;
1454 case EFI_MENU_MODIFIER
:
1455 UsbKeyboardDevice
->MenuKeyOn
= TRUE
;
1461 case EFI_PRINT_MODIFIER
:
1462 case EFI_SYS_REQUEST_MODIFIER
:
1463 UsbKeyboardDevice
->SysReqOn
= TRUE
;
1470 case EFI_ALT_GR_MODIFIER
:
1471 UsbKeyboardDevice
->AltGrOn
= TRUE
;
1474 case EFI_NUM_LOCK_MODIFIER
:
1478 UsbKeyboardDevice
->NumLockOn
= (BOOLEAN
) (!(UsbKeyboardDevice
->NumLockOn
));
1479 SetKeyLED (UsbKeyboardDevice
);
1483 case EFI_CAPS_LOCK_MODIFIER
:
1487 UsbKeyboardDevice
->CapsOn
= (BOOLEAN
) (!(UsbKeyboardDevice
->CapsOn
));
1488 SetKeyLED (UsbKeyboardDevice
);
1492 case EFI_SCROLL_LOCK_MODIFIER
:
1494 // Toggle ScrollLock
1496 UsbKeyboardDevice
->ScrollOn
= (BOOLEAN
) (!(UsbKeyboardDevice
->ScrollOn
));
1497 SetKeyLED (UsbKeyboardDevice
);
1502 // F11, F12, PrintScreen, Pause/Break
1503 // could not be retrieved via SimpleTextInEx protocol
1505 case EFI_FUNCTION_KEY_ELEVEN_MODIFIER
:
1506 case EFI_FUNCTION_KEY_TWELVE_MODIFIER
:
1507 case EFI_PAUSE_MODIFIER
:
1508 case EFI_BREAK_MODIFIER
:
1520 // When encountering Ctrl + Alt + Del, then warm reset.
1522 if (KeyDescriptor
->Modifier
== EFI_DELETE_MODIFIER
) {
1523 if ((UsbKeyboardDevice
->CtrlOn
) && (UsbKeyboardDevice
->AltOn
)) {
1524 gRT
->ResetSystem (EfiResetWarm
, EFI_SUCCESS
, 0, NULL
);
1528 *KeyCode
= UsbKey
.KeyCode
;
1532 return EFI_NOT_READY
;
1537 Converts USB Keycode ranging from 0x4 to 0x65 to EFI_INPUT_KEY.
1539 @param UsbKeyboardDevice The USB_KB_DEV instance.
1540 @param KeyCode Indicates the key code that will be interpreted.
1541 @param Key A pointer to a buffer that is filled in with
1542 the keystroke information for the key that
1545 @retval EFI_SUCCESS Success.
1546 @retval EFI_INVALID_PARAMETER KeyCode is not in the range of 0x4 to 0x65.
1547 @retval EFI_INVALID_PARAMETER Translated EFI_INPUT_KEY has zero for both ScanCode and UnicodeChar.
1548 @retval EFI_NOT_READY KeyCode represents a dead key with EFI_NS_KEY_MODIFIER
1553 UsbKeyCodeToEfiInputKey (
1554 IN USB_KB_DEV
*UsbKeyboardDevice
,
1556 OUT EFI_INPUT_KEY
*Key
1559 EFI_KEY_DESCRIPTOR
*KeyDescriptor
;
1562 // KeyCode must in the range of 0x4 to 0x65
1564 if (!USBKBD_VALID_KEYCODE (KeyCode
)) {
1565 return EFI_INVALID_PARAMETER
;
1567 if ((KeyCode
- 4) >= NUMBER_OF_VALID_NON_MODIFIER_USB_KEYCODE
) {
1568 return EFI_INVALID_PARAMETER
;
1571 KeyDescriptor
= GetKeyDescriptor (UsbKeyboardDevice
, KeyCode
);
1573 if (KeyDescriptor
->Modifier
== EFI_NS_KEY_MODIFIER
) {
1575 // If this is a dead key with EFI_NS_KEY_MODIFIER, then record it and return.
1577 UsbKeyboardDevice
->CurrentNsKey
= FindUsbNsKey (UsbKeyboardDevice
, KeyDescriptor
);
1578 return EFI_NOT_READY
;
1581 if (UsbKeyboardDevice
->CurrentNsKey
!= NULL
) {
1583 // If this keystroke follows a non-spacing key, then find the descriptor for corresponding
1586 KeyDescriptor
= FindPhysicalKey (UsbKeyboardDevice
->CurrentNsKey
, KeyDescriptor
);
1587 UsbKeyboardDevice
->CurrentNsKey
= NULL
;
1590 Key
->ScanCode
= ModifierValueToEfiScanCodeConvertionTable
[KeyDescriptor
->Modifier
];
1591 Key
->UnicodeChar
= KeyDescriptor
->Unicode
;
1593 if ((KeyDescriptor
->AffectedAttribute
& EFI_AFFECTED_BY_STANDARD_SHIFT
)!= 0) {
1594 if (UsbKeyboardDevice
->ShiftOn
) {
1595 Key
->UnicodeChar
= KeyDescriptor
->ShiftedUnicode
;
1598 // Need not return associated shift state if a class of printable characters that
1599 // are normally adjusted by shift modifiers. e.g. Shift Key + 'f' key = 'F'
1601 if ((KeyDescriptor
->AffectedAttribute
& EFI_AFFECTED_BY_CAPS_LOCK
) != 0) {
1602 UsbKeyboardDevice
->LeftShiftOn
= FALSE
;
1603 UsbKeyboardDevice
->RightShiftOn
= FALSE
;
1606 if (UsbKeyboardDevice
->AltGrOn
) {
1607 Key
->UnicodeChar
= KeyDescriptor
->ShiftedAltGrUnicode
;
1613 Key
->UnicodeChar
= KeyDescriptor
->Unicode
;
1615 if (UsbKeyboardDevice
->AltGrOn
) {
1616 Key
->UnicodeChar
= KeyDescriptor
->AltGrUnicode
;
1621 if ((KeyDescriptor
->AffectedAttribute
& EFI_AFFECTED_BY_CAPS_LOCK
) != 0) {
1622 if (UsbKeyboardDevice
->CapsOn
) {
1623 if (Key
->UnicodeChar
== KeyDescriptor
->Unicode
) {
1624 Key
->UnicodeChar
= KeyDescriptor
->ShiftedUnicode
;
1625 } else if (Key
->UnicodeChar
== KeyDescriptor
->ShiftedUnicode
) {
1626 Key
->UnicodeChar
= KeyDescriptor
->Unicode
;
1632 // Translate the CTRL-Alpha characters to their corresponding control value
1633 // (ctrl-a = 0x0001 through ctrl-Z = 0x001A)
1635 if (UsbKeyboardDevice
->CtrlOn
) {
1636 if (Key
->UnicodeChar
>= 'a' && Key
->UnicodeChar
<= 'z') {
1637 Key
->UnicodeChar
= (UINT8
) (Key
->UnicodeChar
- 'a' + 1);
1638 } else if (Key
->UnicodeChar
>= 'A' && Key
->UnicodeChar
<= 'Z') {
1639 Key
->UnicodeChar
= (UINT8
) (Key
->UnicodeChar
- 'A' + 1);
1643 if (KeyDescriptor
->AffectedAttribute
& EFI_AFFECTED_BY_NUM_LOCK
) {
1645 // For key affected by NumLock, if NumLock is on and Shift is not pressed, then it means
1646 // normal key, instead of original control key. So the ScanCode should be cleaned.
1647 // Otherwise, it means control key, so preserve the EFI Scan Code and clear the unicode keycode.
1649 if ((UsbKeyboardDevice
->NumLockOn
) && (!(UsbKeyboardDevice
->ShiftOn
))) {
1650 Key
->ScanCode
= SCAN_NULL
;
1652 Key
->UnicodeChar
= 0x00;
1657 // Translate Unicode 0x1B (ESC) to EFI Scan Code
1659 if (Key
->UnicodeChar
== 0x1B && Key
->ScanCode
== SCAN_NULL
) {
1660 Key
->ScanCode
= SCAN_ESC
;
1661 Key
->UnicodeChar
= 0x00;
1665 // Not valid for key without both unicode key code and EFI Scan Code.
1667 if (Key
->UnicodeChar
== 0 && Key
->ScanCode
== SCAN_NULL
) {
1668 return EFI_NOT_READY
;
1673 // Save Shift/Toggle state
1675 if (UsbKeyboardDevice
->LeftCtrlOn
) {
1676 UsbKeyboardDevice
->KeyState
.KeyShiftState
|= EFI_LEFT_CONTROL_PRESSED
;
1678 if (UsbKeyboardDevice
->RightCtrlOn
) {
1679 UsbKeyboardDevice
->KeyState
.KeyShiftState
|= EFI_RIGHT_CONTROL_PRESSED
;
1681 if (UsbKeyboardDevice
->LeftAltOn
) {
1682 UsbKeyboardDevice
->KeyState
.KeyShiftState
|= EFI_LEFT_ALT_PRESSED
;
1684 if (UsbKeyboardDevice
->RightAltOn
) {
1685 UsbKeyboardDevice
->KeyState
.KeyShiftState
|= EFI_RIGHT_ALT_PRESSED
;
1687 if (UsbKeyboardDevice
->LeftShiftOn
) {
1688 UsbKeyboardDevice
->KeyState
.KeyShiftState
|= EFI_LEFT_SHIFT_PRESSED
;
1690 if (UsbKeyboardDevice
->RightShiftOn
) {
1691 UsbKeyboardDevice
->KeyState
.KeyShiftState
|= EFI_RIGHT_SHIFT_PRESSED
;
1693 if (UsbKeyboardDevice
->LeftLogoOn
) {
1694 UsbKeyboardDevice
->KeyState
.KeyShiftState
|= EFI_LEFT_LOGO_PRESSED
;
1696 if (UsbKeyboardDevice
->RightLogoOn
) {
1697 UsbKeyboardDevice
->KeyState
.KeyShiftState
|= EFI_RIGHT_LOGO_PRESSED
;
1699 if (UsbKeyboardDevice
->MenuKeyOn
) {
1700 UsbKeyboardDevice
->KeyState
.KeyShiftState
|= EFI_MENU_KEY_PRESSED
;
1702 if (UsbKeyboardDevice
->SysReqOn
) {
1703 UsbKeyboardDevice
->KeyState
.KeyShiftState
|= EFI_SYS_REQ_PRESSED
;
1706 if (UsbKeyboardDevice
->ScrollOn
) {
1707 UsbKeyboardDevice
->KeyState
.KeyToggleState
|= EFI_SCROLL_LOCK_ACTIVE
;
1709 if (UsbKeyboardDevice
->NumLockOn
) {
1710 UsbKeyboardDevice
->KeyState
.KeyToggleState
|= EFI_NUM_LOCK_ACTIVE
;
1712 if (UsbKeyboardDevice
->CapsOn
) {
1713 UsbKeyboardDevice
->KeyState
.KeyToggleState
|= EFI_CAPS_LOCK_ACTIVE
;
1722 Resets USB keyboard buffer.
1724 @param KeyboardBuffer Points to the USB keyboard buffer.
1730 OUT USB_KB_BUFFER
*KeyboardBuffer
1733 ZeroMem (KeyboardBuffer
, sizeof (USB_KB_BUFFER
));
1735 KeyboardBuffer
->BufferHead
= KeyboardBuffer
->BufferTail
;
1740 Check whether USB keyboard buffer is empty.
1742 @param KeyboardBuffer USB keyboard buffer
1744 @retval TRUE Keyboard buffer is empty.
1745 @retval FALSE Keyboard buffer is not empty.
1750 IsUSBKeyboardBufferEmpty (
1751 IN USB_KB_BUFFER
*KeyboardBuffer
1755 // Meet FIFO empty condition
1757 return (BOOLEAN
) (KeyboardBuffer
->BufferHead
== KeyboardBuffer
->BufferTail
);
1762 Check whether USB keyboard buffer is full.
1764 @param KeyboardBuffer USB keyboard buffer
1766 @retval TRUE Keyboard buffer is full.
1767 @retval FALSE Keyboard buffer is not full.
1772 IsUSBKeyboardBufferFull (
1773 IN USB_KB_BUFFER
*KeyboardBuffer
1776 return (BOOLEAN
)(((KeyboardBuffer
->BufferTail
+ 1) % (MAX_KEY_ALLOWED
+ 1)) == KeyboardBuffer
->BufferHead
);
1781 Inserts a keycode into keyboard buffer.
1783 @param KeyboardBuffer Points to the USB keyboard buffer.
1784 @param Key Keycode to insert.
1785 @param Down TRUE means key is pressed.
1786 FALSE means key is released.
1792 IN OUT USB_KB_BUFFER
*KeyboardBuffer
,
1800 // If keyboard buffer is full, throw the
1801 // first key out of the keyboard buffer.
1803 if (IsUSBKeyboardBufferFull (KeyboardBuffer
)) {
1804 RemoveKeyCode (KeyboardBuffer
, &UsbKey
);
1807 KeyboardBuffer
->Buffer
[KeyboardBuffer
->BufferTail
].KeyCode
= Key
;
1808 KeyboardBuffer
->Buffer
[KeyboardBuffer
->BufferTail
].Down
= Down
;
1811 // Adjust the tail pointer of the FIFO keyboard buffer.
1813 KeyboardBuffer
->BufferTail
= (UINT8
) ((KeyboardBuffer
->BufferTail
+ 1) % (MAX_KEY_ALLOWED
+ 1));
1818 Remove a keycode from keyboard buffer and return it.
1820 @param KeyboardBuffer Points to the USB keyboard buffer.
1821 @param UsbKey Points to the buffer that contains keycode for output.
1823 @retval EFI_SUCCESS Keycode successfully removed from keyboard buffer.
1824 @retval EFI_DEVICE_ERROR Keyboard buffer is empty.
1830 IN OUT USB_KB_BUFFER
*KeyboardBuffer
,
1834 if (IsUSBKeyboardBufferEmpty (KeyboardBuffer
)) {
1835 return EFI_DEVICE_ERROR
;
1838 UsbKey
->KeyCode
= KeyboardBuffer
->Buffer
[KeyboardBuffer
->BufferHead
].KeyCode
;
1839 UsbKey
->Down
= KeyboardBuffer
->Buffer
[KeyboardBuffer
->BufferHead
].Down
;
1842 // Adjust the head pointer of the FIFO keyboard buffer.
1844 KeyboardBuffer
->BufferHead
= (UINT8
) ((KeyboardBuffer
->BufferHead
+ 1) % (MAX_KEY_ALLOWED
+ 1));
1851 Sets USB keyboard LED state.
1853 @param UsbKeyboardDevice The USB_KB_DEV instance.
1859 IN USB_KB_DEV
*UsbKeyboardDevice
1866 // Set each field in Led map.
1868 Led
.NumLock
= (UINT8
) ((UsbKeyboardDevice
->NumLockOn
) ? 1 : 0);
1869 Led
.CapsLock
= (UINT8
) ((UsbKeyboardDevice
->CapsOn
) ? 1 : 0);
1870 Led
.ScrollLock
= (UINT8
) ((UsbKeyboardDevice
->ScrollOn
) ? 1 : 0);
1875 // Call Set_Report Request to lighten the LED.
1877 UsbSetReportRequest (
1878 UsbKeyboardDevice
->UsbIo
,
1879 UsbKeyboardDevice
->InterfaceDescriptor
.InterfaceNumber
,
1889 Handler for Repeat Key event.
1891 This function is the handler for Repeat Key event triggered
1893 After a repeatable key is pressed, the event would be triggered
1894 with interval of USBKBD_REPEAT_DELAY. Once the event is triggered,
1895 following trigger will come with interval of USBKBD_REPEAT_RATE.
1897 @param Event The Repeat Key event.
1898 @param Context Points to the USB_KB_DEV instance.
1903 USBKeyboardRepeatHandler (
1908 USB_KB_DEV
*UsbKeyboardDevice
;
1910 UsbKeyboardDevice
= (USB_KB_DEV
*) Context
;
1913 // Do nothing when there is no repeat key.
1915 if (UsbKeyboardDevice
->RepeatKey
!= 0) {
1917 // Inserts the repeat key into keyboard buffer,
1920 &(UsbKeyboardDevice
->KeyboardBuffer
),
1921 UsbKeyboardDevice
->RepeatKey
,
1926 // Set repeat rate for next repeat key generation.
1929 UsbKeyboardDevice
->RepeatTimer
,
1938 Handler for Delayed Recovery event.
1940 This function is the handler for Delayed Recovery event triggered
1942 After a device error occurs, the event would be triggered
1943 with interval of EFI_USB_INTERRUPT_DELAY. EFI_USB_INTERRUPT_DELAY
1944 is defined in USB standard for error handling.
1946 @param Event The Delayed Recovery event.
1947 @param Context Points to the USB_KB_DEV instance.
1952 USBKeyboardRecoveryHandler (
1958 USB_KB_DEV
*UsbKeyboardDevice
;
1959 EFI_USB_IO_PROTOCOL
*UsbIo
;
1962 UsbKeyboardDevice
= (USB_KB_DEV
*) Context
;
1964 UsbIo
= UsbKeyboardDevice
->UsbIo
;
1966 PacketSize
= (UINT8
) (UsbKeyboardDevice
->IntEndpointDescriptor
.MaxPacketSize
);
1969 // Re-submit Asynchronous Interrupt Transfer for recovery.
1971 UsbIo
->UsbAsyncInterruptTransfer (
1973 UsbKeyboardDevice
->IntEndpointDescriptor
.EndpointAddress
,
1975 UsbKeyboardDevice
->IntEndpointDescriptor
.Interval
,