2007-07-12 19:31:28 +02:00
|
|
|
/** @file
|
2008-07-23 08:29:46 +02:00
|
|
|
Helper functions for USB Keyboard Driver.
|
|
|
|
|
2018-01-12 12:29:32 +01:00
|
|
|
Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
|
2010-04-24 11:49:11 +02:00
|
|
|
This program and the accompanying materials
|
2007-07-12 19:31:28 +02:00
|
|
|
are licensed and made available under the terms and conditions of the BSD License
|
|
|
|
which accompanies this distribution. The full text of the license may be found at
|
|
|
|
http://opensource.org/licenses/bsd-license.php
|
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
2008-07-23 08:29:46 +02:00
|
|
|
#include "KeyBoard.h"
|
2008-06-23 11:41:33 +02:00
|
|
|
|
2009-04-10 06:28:13 +02:00
|
|
|
USB_KEYBOARD_LAYOUT_PACK_BIN mUsbKeyboardLayoutBin = {
|
|
|
|
sizeof (USB_KEYBOARD_LAYOUT_PACK_BIN), // Binary size
|
|
|
|
|
|
|
|
//
|
|
|
|
// EFI_HII_PACKAGE_HEADER
|
|
|
|
//
|
|
|
|
{
|
|
|
|
sizeof (USB_KEYBOARD_LAYOUT_PACK_BIN) - sizeof (UINT32),
|
|
|
|
EFI_HII_PACKAGE_KEYBOARD_LAYOUT
|
|
|
|
},
|
|
|
|
1, // LayoutCount
|
|
|
|
sizeof (USB_KEYBOARD_LAYOUT_PACK_BIN) - sizeof (UINT32) - sizeof (EFI_HII_PACKAGE_HEADER) - sizeof (UINT16), // LayoutLength
|
|
|
|
USB_KEYBOARD_LAYOUT_KEY_GUID, // KeyGuid
|
|
|
|
sizeof (UINT16) + sizeof (EFI_GUID) + sizeof (UINT32) + sizeof (UINT8) + (USB_KEYBOARD_KEY_COUNT * sizeof (EFI_KEY_DESCRIPTOR)), // LayoutDescriptorStringOffset
|
|
|
|
USB_KEYBOARD_KEY_COUNT, // DescriptorCount
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// EFI_KEY_DESCRIPTOR (total number is USB_KEYBOARD_KEY_COUNT)
|
|
|
|
//
|
|
|
|
{EfiKeyC1, 'a', 'A', 0, 0, EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},
|
|
|
|
{EfiKeyB5, 'b', 'B', 0, 0, EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},
|
|
|
|
{EfiKeyB3, 'c', 'C', 0, 0, EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},
|
|
|
|
{EfiKeyC3, 'd', 'D', 0, 0, EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},
|
|
|
|
{EfiKeyD3, 'e', 'E', 0, 0, EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},
|
|
|
|
{EfiKeyC4, 'f', 'F', 0, 0, EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},
|
|
|
|
{EfiKeyC5, 'g', 'G', 0, 0, EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},
|
|
|
|
{EfiKeyC6, 'h', 'H', 0, 0, EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},
|
|
|
|
{EfiKeyD8, 'i', 'I', 0, 0, EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},
|
|
|
|
{EfiKeyC7, 'j', 'J', 0, 0, EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},
|
|
|
|
{EfiKeyC8, 'k', 'K', 0, 0, EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},
|
|
|
|
{EfiKeyC9, 'l', 'L', 0, 0, EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},
|
|
|
|
{EfiKeyB7, 'm', 'M', 0, 0, EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},
|
|
|
|
{EfiKeyB6, 'n', 'N', 0, 0, EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},
|
|
|
|
{EfiKeyD9, 'o', 'O', 0, 0, EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},
|
|
|
|
{EfiKeyD10, 'p', 'P', 0, 0, EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},
|
|
|
|
{EfiKeyD1, 'q', 'Q', 0, 0, EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},
|
|
|
|
{EfiKeyD4, 'r', 'R', 0, 0, EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},
|
|
|
|
{EfiKeyC2, 's', 'S', 0, 0, EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},
|
|
|
|
{EfiKeyD5, 't', 'T', 0, 0, EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},
|
|
|
|
{EfiKeyD7, 'u', 'U', 0, 0, EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},
|
|
|
|
{EfiKeyB4, 'v', 'V', 0, 0, EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},
|
|
|
|
{EfiKeyD2, 'w', 'W', 0, 0, EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},
|
|
|
|
{EfiKeyB2, 'x', 'X', 0, 0, EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},
|
|
|
|
{EfiKeyD6, 'y', 'Y', 0, 0, EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},
|
|
|
|
{EfiKeyB1, 'z', 'Z', 0, 0, EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_CAPS_LOCK},
|
|
|
|
{EfiKeyE1, '1', '!', 0, 0, EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT},
|
|
|
|
{EfiKeyE2, '2', '@', 0, 0, EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT},
|
|
|
|
{EfiKeyE3, '3', '#', 0, 0, EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT},
|
|
|
|
{EfiKeyE4, '4', '$', 0, 0, EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT},
|
|
|
|
{EfiKeyE5, '5', '%', 0, 0, EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT},
|
|
|
|
{EfiKeyE6, '6', '^', 0, 0, EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT},
|
|
|
|
{EfiKeyE7, '7', '&', 0, 0, EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT},
|
|
|
|
{EfiKeyE8, '8', '*', 0, 0, EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT},
|
|
|
|
{EfiKeyE9, '9', '(', 0, 0, EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT},
|
|
|
|
{EfiKeyE10, '0', ')', 0, 0, EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT},
|
|
|
|
{EfiKeyEnter, 0x0d, 0x0d, 0, 0, EFI_NULL_MODIFIER, 0},
|
|
|
|
{EfiKeyEsc, 0x1b, 0x1b, 0, 0, EFI_NULL_MODIFIER, 0},
|
|
|
|
{EfiKeyBackSpace, 0x08, 0x08, 0, 0, EFI_NULL_MODIFIER, 0},
|
|
|
|
{EfiKeyTab, 0x09, 0x09, 0, 0, EFI_NULL_MODIFIER, 0},
|
|
|
|
{EfiKeySpaceBar, ' ', ' ', 0, 0, EFI_NULL_MODIFIER, 0},
|
|
|
|
{EfiKeyE11, '-', '_', 0, 0, EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT},
|
|
|
|
{EfiKeyE12, '=', '+', 0, 0, EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT},
|
|
|
|
{EfiKeyD11, '[', '{', 0, 0, EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT},
|
|
|
|
{EfiKeyD12, ']', '}', 0, 0, EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT},
|
|
|
|
{EfiKeyD13, '\\', '|', 0, 0, EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT},
|
2013-03-15 07:48:43 +01:00
|
|
|
{EfiKeyC12, '\\', '|', 0, 0, EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT},
|
2009-04-10 06:28:13 +02:00
|
|
|
{EfiKeyC10, ';', ':', 0, 0, EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT},
|
|
|
|
{EfiKeyC11, '\'', '"', 0, 0, EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT},
|
|
|
|
{EfiKeyE0, '`', '~', 0, 0, EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT},
|
|
|
|
{EfiKeyB8, ',', '<', 0, 0, EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT},
|
|
|
|
{EfiKeyB9, '.', '>', 0, 0, EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT},
|
|
|
|
{EfiKeyB10, '/', '?', 0, 0, EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT},
|
|
|
|
{EfiKeyCapsLock, 0x00, 0x00, 0, 0, EFI_CAPS_LOCK_MODIFIER, 0},
|
|
|
|
{EfiKeyF1, 0x00, 0x00, 0, 0, EFI_FUNCTION_KEY_ONE_MODIFIER, 0},
|
|
|
|
{EfiKeyF2, 0x00, 0x00, 0, 0, EFI_FUNCTION_KEY_TWO_MODIFIER, 0},
|
|
|
|
{EfiKeyF3, 0x00, 0x00, 0, 0, EFI_FUNCTION_KEY_THREE_MODIFIER, 0},
|
|
|
|
{EfiKeyF4, 0x00, 0x00, 0, 0, EFI_FUNCTION_KEY_FOUR_MODIFIER, 0},
|
|
|
|
{EfiKeyF5, 0x00, 0x00, 0, 0, EFI_FUNCTION_KEY_FIVE_MODIFIER, 0},
|
|
|
|
{EfiKeyF6, 0x00, 0x00, 0, 0, EFI_FUNCTION_KEY_SIX_MODIFIER, 0},
|
|
|
|
{EfiKeyF7, 0x00, 0x00, 0, 0, EFI_FUNCTION_KEY_SEVEN_MODIFIER, 0},
|
|
|
|
{EfiKeyF8, 0x00, 0x00, 0, 0, EFI_FUNCTION_KEY_EIGHT_MODIFIER, 0},
|
|
|
|
{EfiKeyF9, 0x00, 0x00, 0, 0, EFI_FUNCTION_KEY_NINE_MODIFIER, 0},
|
|
|
|
{EfiKeyF10, 0x00, 0x00, 0, 0, EFI_FUNCTION_KEY_TEN_MODIFIER, 0},
|
|
|
|
{EfiKeyF11, 0x00, 0x00, 0, 0, EFI_FUNCTION_KEY_ELEVEN_MODIFIER, 0},
|
|
|
|
{EfiKeyF12, 0x00, 0x00, 0, 0, EFI_FUNCTION_KEY_TWELVE_MODIFIER, 0},
|
|
|
|
{EfiKeyPrint, 0x00, 0x00, 0, 0, EFI_PRINT_MODIFIER, 0},
|
|
|
|
{EfiKeySLck, 0x00, 0x00, 0, 0, EFI_SCROLL_LOCK_MODIFIER, 0},
|
|
|
|
{EfiKeyPause, 0x00, 0x00, 0, 0, EFI_PAUSE_MODIFIER, 0},
|
|
|
|
{EfiKeyIns, 0x00, 0x00, 0, 0, EFI_INSERT_MODIFIER, 0},
|
|
|
|
{EfiKeyHome, 0x00, 0x00, 0, 0, EFI_HOME_MODIFIER, 0},
|
|
|
|
{EfiKeyPgUp, 0x00, 0x00, 0, 0, EFI_PAGE_UP_MODIFIER, 0},
|
|
|
|
{EfiKeyDel, 0x00, 0x00, 0, 0, EFI_DELETE_MODIFIER, 0},
|
|
|
|
{EfiKeyEnd, 0x00, 0x00, 0, 0, EFI_END_MODIFIER, 0},
|
|
|
|
{EfiKeyPgDn, 0x00, 0x00, 0, 0, EFI_PAGE_DOWN_MODIFIER, 0},
|
|
|
|
{EfiKeyRightArrow, 0x00, 0x00, 0, 0, EFI_RIGHT_ARROW_MODIFIER, 0},
|
|
|
|
{EfiKeyLeftArrow, 0x00, 0x00, 0, 0, EFI_LEFT_ARROW_MODIFIER, 0},
|
|
|
|
{EfiKeyDownArrow, 0x00, 0x00, 0, 0, EFI_DOWN_ARROW_MODIFIER, 0},
|
|
|
|
{EfiKeyUpArrow, 0x00, 0x00, 0, 0, EFI_UP_ARROW_MODIFIER, 0},
|
|
|
|
{EfiKeyNLck, 0x00, 0x00, 0, 0, EFI_NUM_LOCK_MODIFIER, 0},
|
|
|
|
{EfiKeySlash, '/', '/', 0, 0, EFI_NULL_MODIFIER, 0},
|
|
|
|
{EfiKeyAsterisk, '*', '*', 0, 0, EFI_NULL_MODIFIER, 0},
|
|
|
|
{EfiKeyMinus, '-', '-', 0, 0, EFI_NULL_MODIFIER, 0},
|
|
|
|
{EfiKeyPlus, '+', '+', 0, 0, EFI_NULL_MODIFIER, 0},
|
|
|
|
{EfiKeyEnter, 0x0d, 0x0d, 0, 0, EFI_NULL_MODIFIER, 0},
|
|
|
|
{EfiKeyOne, '1', '1', 0, 0, EFI_END_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_NUM_LOCK},
|
|
|
|
{EfiKeyTwo, '2', '2', 0, 0, EFI_DOWN_ARROW_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_NUM_LOCK},
|
|
|
|
{EfiKeyThree, '3', '3', 0, 0, EFI_PAGE_DOWN_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_NUM_LOCK},
|
|
|
|
{EfiKeyFour, '4', '4', 0, 0, EFI_LEFT_ARROW_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_NUM_LOCK},
|
|
|
|
{EfiKeyFive, '5', '5', 0, 0, EFI_NULL_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_NUM_LOCK},
|
|
|
|
{EfiKeySix, '6', '6', 0, 0, EFI_RIGHT_ARROW_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_NUM_LOCK},
|
|
|
|
{EfiKeySeven, '7', '7', 0, 0, EFI_HOME_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_NUM_LOCK},
|
|
|
|
{EfiKeyEight, '8', '8', 0, 0, EFI_UP_ARROW_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_NUM_LOCK},
|
|
|
|
{EfiKeyNine, '9', '9', 0, 0, EFI_PAGE_UP_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_NUM_LOCK},
|
|
|
|
{EfiKeyZero, '0', '0', 0, 0, EFI_INSERT_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_NUM_LOCK},
|
|
|
|
{EfiKeyPeriod, '.', '.', 0, 0, EFI_DELETE_MODIFIER, EFI_AFFECTED_BY_STANDARD_SHIFT | EFI_AFFECTED_BY_NUM_LOCK},
|
|
|
|
{EfiKeyA4, 0x00, 0x00, 0, 0, EFI_MENU_MODIFIER, 0},
|
|
|
|
{EfiKeyLCtrl, 0, 0, 0, 0, EFI_LEFT_CONTROL_MODIFIER, 0},
|
|
|
|
{EfiKeyLShift, 0, 0, 0, 0, EFI_LEFT_SHIFT_MODIFIER, 0},
|
|
|
|
{EfiKeyLAlt, 0, 0, 0, 0, EFI_LEFT_ALT_MODIFIER, 0},
|
|
|
|
{EfiKeyA0, 0, 0, 0, 0, EFI_LEFT_LOGO_MODIFIER, 0},
|
|
|
|
{EfiKeyRCtrl, 0, 0, 0, 0, EFI_RIGHT_CONTROL_MODIFIER, 0},
|
|
|
|
{EfiKeyRShift, 0, 0, 0, 0, EFI_RIGHT_SHIFT_MODIFIER, 0},
|
|
|
|
{EfiKeyA2, 0, 0, 0, 0, EFI_RIGHT_ALT_MODIFIER, 0},
|
|
|
|
{EfiKeyA3, 0, 0, 0, 0, EFI_RIGHT_LOGO_MODIFIER, 0},
|
|
|
|
},
|
|
|
|
1, // DescriptionCount
|
|
|
|
{'e', 'n', '-', 'U', 'S'}, // RFC4646 language code
|
|
|
|
' ', // Space
|
|
|
|
{'E', 'n', 'g', 'l', 'i', 's', 'h', ' ', 'K', 'e', 'y', 'b', 'o', 'a', 'r', 'd', '\0'}, // DescriptionString[]
|
2008-06-23 11:41:33 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
//
|
2009-04-10 06:28:13 +02:00
|
|
|
// EFI_KEY to USB Keycode conversion table
|
2008-12-15 08:17:47 +01:00
|
|
|
// EFI_KEY is defined in UEFI spec.
|
|
|
|
// USB Keycode is defined in USB HID Firmware spec.
|
2008-06-23 11:41:33 +02:00
|
|
|
//
|
2008-12-15 08:17:47 +01:00
|
|
|
UINT8 EfiKeyToUsbKeyCodeConvertionTable[] = {
|
2008-06-23 11:41:33 +02:00
|
|
|
0xe0, // EfiKeyLCtrl
|
|
|
|
0xe3, // EfiKeyA0
|
|
|
|
0xe2, // EfiKeyLAlt
|
|
|
|
0x2c, // EfiKeySpaceBar
|
|
|
|
0xe6, // EfiKeyA2
|
|
|
|
0xe7, // EfiKeyA3
|
|
|
|
0x65, // EfiKeyA4
|
|
|
|
0xe4, // EfiKeyRCtrl
|
|
|
|
0x50, // EfiKeyLeftArrow
|
|
|
|
0x51, // EfiKeyDownArrow
|
|
|
|
0x4F, // EfiKeyRightArrow
|
|
|
|
0x62, // EfiKeyZero
|
|
|
|
0x63, // EfiKeyPeriod
|
|
|
|
0x28, // EfiKeyEnter
|
|
|
|
0xe1, // EfiKeyLShift
|
|
|
|
0x64, // EfiKeyB0
|
|
|
|
0x1D, // EfiKeyB1
|
|
|
|
0x1B, // EfiKeyB2
|
|
|
|
0x06, // EfiKeyB3
|
|
|
|
0x19, // EfiKeyB4
|
|
|
|
0x05, // EfiKeyB5
|
|
|
|
0x11, // EfiKeyB6
|
|
|
|
0x10, // EfiKeyB7
|
|
|
|
0x36, // EfiKeyB8
|
|
|
|
0x37, // EfiKeyB9
|
|
|
|
0x38, // EfiKeyB10
|
|
|
|
0xe5, // EfiKeyRShift
|
|
|
|
0x52, // EfiKeyUpArrow
|
|
|
|
0x59, // EfiKeyOne
|
|
|
|
0x5A, // EfiKeyTwo
|
|
|
|
0x5B, // EfiKeyThree
|
|
|
|
0x39, // EfiKeyCapsLock
|
|
|
|
0x04, // EfiKeyC1
|
|
|
|
0x16, // EfiKeyC2
|
|
|
|
0x07, // EfiKeyC3
|
|
|
|
0x09, // EfiKeyC4
|
|
|
|
0x0A, // EfiKeyC5
|
|
|
|
0x0B, // EfiKeyC6
|
|
|
|
0x0D, // EfiKeyC7
|
|
|
|
0x0E, // EfiKeyC8
|
|
|
|
0x0F, // EfiKeyC9
|
|
|
|
0x33, // EfiKeyC10
|
|
|
|
0x34, // EfiKeyC11
|
|
|
|
0x32, // EfiKeyC12
|
|
|
|
0x5C, // EfiKeyFour
|
|
|
|
0x5D, // EfiKeyFive
|
|
|
|
0x5E, // EfiKeySix
|
|
|
|
0x57, // EfiKeyPlus
|
|
|
|
0x2B, // EfiKeyTab
|
|
|
|
0x14, // EfiKeyD1
|
|
|
|
0x1A, // EfiKeyD2
|
|
|
|
0x08, // EfiKeyD3
|
|
|
|
0x15, // EfiKeyD4
|
|
|
|
0x17, // EfiKeyD5
|
|
|
|
0x1C, // EfiKeyD6
|
|
|
|
0x18, // EfiKeyD7
|
|
|
|
0x0C, // EfiKeyD8
|
|
|
|
0x12, // EfiKeyD9
|
|
|
|
0x13, // EfiKeyD10
|
|
|
|
0x2F, // EfiKeyD11
|
|
|
|
0x30, // EfiKeyD12
|
|
|
|
0x31, // EfiKeyD13
|
|
|
|
0x4C, // EfiKeyDel
|
|
|
|
0x4D, // EfiKeyEnd
|
|
|
|
0x4E, // EfiKeyPgDn
|
|
|
|
0x5F, // EfiKeySeven
|
|
|
|
0x60, // EfiKeyEight
|
|
|
|
0x61, // EfiKeyNine
|
|
|
|
0x35, // EfiKeyE0
|
|
|
|
0x1E, // EfiKeyE1
|
|
|
|
0x1F, // EfiKeyE2
|
|
|
|
0x20, // EfiKeyE3
|
|
|
|
0x21, // EfiKeyE4
|
|
|
|
0x22, // EfiKeyE5
|
|
|
|
0x23, // EfiKeyE6
|
|
|
|
0x24, // EfiKeyE7
|
|
|
|
0x25, // EfiKeyE8
|
|
|
|
0x26, // EfiKeyE9
|
|
|
|
0x27, // EfiKeyE10
|
|
|
|
0x2D, // EfiKeyE11
|
|
|
|
0x2E, // EfiKeyE12
|
|
|
|
0x2A, // EfiKeyBackSpace
|
|
|
|
0x49, // EfiKeyIns
|
|
|
|
0x4A, // EfiKeyHome
|
|
|
|
0x4B, // EfiKeyPgUp
|
|
|
|
0x53, // EfiKeyNLck
|
|
|
|
0x54, // EfiKeySlash
|
|
|
|
0x55, // EfiKeyAsterisk
|
|
|
|
0x56, // EfiKeyMinus
|
|
|
|
0x29, // EfiKeyEsc
|
|
|
|
0x3A, // EfiKeyF1
|
|
|
|
0x3B, // EfiKeyF2
|
|
|
|
0x3C, // EfiKeyF3
|
|
|
|
0x3D, // EfiKeyF4
|
|
|
|
0x3E, // EfiKeyF5
|
|
|
|
0x3F, // EfiKeyF6
|
|
|
|
0x40, // EfiKeyF7
|
|
|
|
0x41, // EfiKeyF8
|
|
|
|
0x42, // EfiKeyF9
|
|
|
|
0x43, // EfiKeyF10
|
|
|
|
0x44, // EfiKeyF11
|
|
|
|
0x45, // EfiKeyF12
|
|
|
|
0x46, // EfiKeyPrint
|
|
|
|
0x47, // EfiKeySLck
|
|
|
|
0x48 // EfiKeyPause
|
|
|
|
};
|
|
|
|
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
2008-12-15 08:17:47 +01:00
|
|
|
// Keyboard modifier value to EFI Scan Code convertion table
|
|
|
|
// EFI Scan Code and the modifier values are defined in UEFI spec.
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
2008-12-15 08:17:47 +01:00
|
|
|
UINT8 ModifierValueToEfiScanCodeConvertionTable[] = {
|
2008-06-23 11:41:33 +02:00
|
|
|
SCAN_NULL, // EFI_NULL_MODIFIER
|
|
|
|
SCAN_NULL, // EFI_LEFT_CONTROL_MODIFIER
|
|
|
|
SCAN_NULL, // EFI_RIGHT_CONTROL_MODIFIER
|
|
|
|
SCAN_NULL, // EFI_LEFT_ALT_MODIFIER
|
|
|
|
SCAN_NULL, // EFI_RIGHT_ALT_MODIFIER
|
|
|
|
SCAN_NULL, // EFI_ALT_GR_MODIFIER
|
|
|
|
SCAN_INSERT, // EFI_INSERT_MODIFIER
|
|
|
|
SCAN_DELETE, // EFI_DELETE_MODIFIER
|
|
|
|
SCAN_PAGE_DOWN, // EFI_PAGE_DOWN_MODIFIER
|
|
|
|
SCAN_PAGE_UP, // EFI_PAGE_UP_MODIFIER
|
|
|
|
SCAN_HOME, // EFI_HOME_MODIFIER
|
|
|
|
SCAN_END, // EFI_END_MODIFIER
|
|
|
|
SCAN_NULL, // EFI_LEFT_SHIFT_MODIFIER
|
|
|
|
SCAN_NULL, // EFI_RIGHT_SHIFT_MODIFIER
|
|
|
|
SCAN_NULL, // EFI_CAPS_LOCK_MODIFIER
|
|
|
|
SCAN_NULL, // EFI_NUM_LOCK_MODIFIER
|
|
|
|
SCAN_LEFT, // EFI_LEFT_ARROW_MODIFIER
|
|
|
|
SCAN_RIGHT, // EFI_RIGHT_ARROW_MODIFIER
|
|
|
|
SCAN_DOWN, // EFI_DOWN_ARROW_MODIFIER
|
|
|
|
SCAN_UP, // EFI_UP_ARROW_MODIFIER
|
|
|
|
SCAN_NULL, // EFI_NS_KEY_MODIFIER
|
|
|
|
SCAN_NULL, // EFI_NS_KEY_DEPENDENCY_MODIFIER
|
|
|
|
SCAN_F1, // EFI_FUNCTION_KEY_ONE_MODIFIER
|
|
|
|
SCAN_F2, // EFI_FUNCTION_KEY_TWO_MODIFIER
|
|
|
|
SCAN_F3, // EFI_FUNCTION_KEY_THREE_MODIFIER
|
|
|
|
SCAN_F4, // EFI_FUNCTION_KEY_FOUR_MODIFIER
|
|
|
|
SCAN_F5, // EFI_FUNCTION_KEY_FIVE_MODIFIER
|
|
|
|
SCAN_F6, // EFI_FUNCTION_KEY_SIX_MODIFIER
|
|
|
|
SCAN_F7, // EFI_FUNCTION_KEY_SEVEN_MODIFIER
|
|
|
|
SCAN_F8, // EFI_FUNCTION_KEY_EIGHT_MODIFIER
|
|
|
|
SCAN_F9, // EFI_FUNCTION_KEY_NINE_MODIFIER
|
|
|
|
SCAN_F10, // EFI_FUNCTION_KEY_TEN_MODIFIER
|
|
|
|
SCAN_F11, // EFI_FUNCTION_KEY_ELEVEN_MODIFIER
|
|
|
|
SCAN_F12, // EFI_FUNCTION_KEY_TWELVE_MODIFIER
|
2011-09-30 09:28:16 +02:00
|
|
|
//
|
|
|
|
// For Partial Keystroke support
|
|
|
|
//
|
2011-05-16 03:51:53 +02:00
|
|
|
SCAN_NULL, // EFI_PRINT_MODIFIER
|
|
|
|
SCAN_NULL, // EFI_SYS_REQUEST_MODIFIER
|
|
|
|
SCAN_NULL, // EFI_SCROLL_LOCK_MODIFIER
|
2011-09-30 09:28:16 +02:00
|
|
|
SCAN_PAUSE, // EFI_PAUSE_MODIFIER
|
|
|
|
SCAN_NULL, // EFI_BREAK_MODIFIER
|
|
|
|
SCAN_NULL, // EFI_LEFT_LOGO_MODIFIER
|
|
|
|
SCAN_NULL, // EFI_RIGHT_LOGO_MODIFER
|
|
|
|
SCAN_NULL, // EFI_MENU_MODIFER
|
2007-07-12 19:31:28 +02:00
|
|
|
};
|
|
|
|
|
2008-12-03 09:52:39 +01:00
|
|
|
/**
|
2009-04-10 06:28:13 +02:00
|
|
|
Initialize Key Convention Table by using default keyboard layout.
|
2008-12-03 09:52:39 +01:00
|
|
|
|
|
|
|
@param UsbKeyboardDevice The USB_KB_DEV instance.
|
|
|
|
|
2009-04-10 06:28:13 +02:00
|
|
|
@retval EFI_SUCCESS The default keyboard layout was installed successfully
|
|
|
|
@retval Others Failure to install default keyboard layout.
|
2008-12-03 09:52:39 +01:00
|
|
|
**/
|
2009-04-10 06:28:13 +02:00
|
|
|
EFI_STATUS
|
|
|
|
InstallDefaultKeyboardLayout (
|
|
|
|
IN OUT USB_KB_DEV *UsbKeyboardDevice
|
2008-12-03 09:52:39 +01:00
|
|
|
)
|
|
|
|
{
|
2009-04-10 06:28:13 +02:00
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_HII_DATABASE_PROTOCOL *HiiDatabase;
|
|
|
|
EFI_HII_HANDLE HiiHandle;
|
2008-12-03 09:52:39 +01:00
|
|
|
|
|
|
|
//
|
2009-04-10 06:28:13 +02:00
|
|
|
// Locate Hii database protocol
|
2008-12-03 09:52:39 +01:00
|
|
|
//
|
2009-04-10 06:28:13 +02:00
|
|
|
Status = gBS->LocateProtocol (
|
|
|
|
&gEfiHiiDatabaseProtocolGuid,
|
|
|
|
NULL,
|
|
|
|
(VOID **) &HiiDatabase
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
2008-12-03 09:52:39 +01:00
|
|
|
|
2009-04-10 06:28:13 +02:00
|
|
|
//
|
|
|
|
// Install Keyboard Layout package to HII database
|
|
|
|
//
|
2009-04-14 12:47:19 +02:00
|
|
|
HiiHandle = HiiAddPackages (
|
2011-09-18 14:21:01 +02:00
|
|
|
&gUsbKeyboardLayoutPackageGuid,
|
2009-04-14 12:47:19 +02:00
|
|
|
UsbKeyboardDevice->ControllerHandle,
|
|
|
|
&mUsbKeyboardLayoutBin,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
if (HiiHandle == NULL) {
|
|
|
|
return EFI_OUT_OF_RESOURCES;
|
2008-12-03 09:52:39 +01:00
|
|
|
}
|
2009-04-10 06:28:13 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Set current keyboard layout
|
|
|
|
//
|
2011-09-18 14:21:01 +02:00
|
|
|
Status = HiiDatabase->SetKeyboardLayout (HiiDatabase, &gUsbKeyboardLayoutKeyGuid);
|
2009-04-10 06:28:13 +02:00
|
|
|
|
|
|
|
return Status;
|
2008-12-03 09:52:39 +01:00
|
|
|
}
|
|
|
|
|
2009-04-10 06:28:13 +02:00
|
|
|
|
2007-07-12 19:31:28 +02:00
|
|
|
/**
|
2008-12-15 08:17:47 +01:00
|
|
|
Uses USB I/O to check whether the device is a USB keyboard device.
|
|
|
|
|
|
|
|
@param UsbIo Pointer to a USB I/O protocol instance.
|
2007-07-12 19:31:28 +02:00
|
|
|
|
2008-12-15 08:17:47 +01:00
|
|
|
@retval TRUE Device is a USB keyboard device.
|
|
|
|
@retval FALSE Device is a not USB keyboard device.
|
2007-07-12 19:31:28 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
BOOLEAN
|
|
|
|
IsUSBKeyboard (
|
|
|
|
IN EFI_USB_IO_PROTOCOL *UsbIo
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
|
|
|
|
|
|
|
|
//
|
2008-12-15 08:17:47 +01:00
|
|
|
// Get the default interface descriptor
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
|
|
|
Status = UsbIo->UsbGetInterfaceDescriptor (
|
|
|
|
UsbIo,
|
|
|
|
&InterfaceDescriptor
|
|
|
|
);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (InterfaceDescriptor.InterfaceClass == CLASS_HID &&
|
|
|
|
InterfaceDescriptor.InterfaceSubClass == SUBCLASS_BOOT &&
|
|
|
|
InterfaceDescriptor.InterfaceProtocol == PROTOCOL_KEYBOARD
|
|
|
|
) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-07-23 08:29:46 +02:00
|
|
|
/**
|
|
|
|
Get current keyboard layout from HII database.
|
|
|
|
|
2008-12-15 08:17:47 +01:00
|
|
|
@return Pointer to HII Keyboard Layout.
|
|
|
|
NULL means failure occurred while trying to get keyboard layout.
|
2007-07-12 19:31:28 +02:00
|
|
|
|
2008-07-23 08:29:46 +02:00
|
|
|
**/
|
2008-06-23 11:41:33 +02:00
|
|
|
EFI_HII_KEYBOARD_LAYOUT *
|
|
|
|
GetCurrentKeyboardLayout (
|
|
|
|
VOID
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_HII_DATABASE_PROTOCOL *HiiDatabase;
|
|
|
|
EFI_HII_KEYBOARD_LAYOUT *KeyboardLayout;
|
|
|
|
UINT16 Length;
|
|
|
|
|
|
|
|
//
|
2008-12-15 08:17:47 +01:00
|
|
|
// Locate HII Database Protocol
|
2008-06-23 11:41:33 +02:00
|
|
|
//
|
|
|
|
Status = gBS->LocateProtocol (
|
|
|
|
&gEfiHiiDatabaseProtocolGuid,
|
|
|
|
NULL,
|
|
|
|
(VOID **) &HiiDatabase
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Get current keyboard layout from HII database
|
|
|
|
//
|
|
|
|
Length = 0;
|
|
|
|
KeyboardLayout = NULL;
|
|
|
|
Status = HiiDatabase->GetKeyboardLayout (
|
|
|
|
HiiDatabase,
|
|
|
|
NULL,
|
|
|
|
&Length,
|
|
|
|
KeyboardLayout
|
|
|
|
);
|
|
|
|
if (Status == EFI_BUFFER_TOO_SMALL) {
|
|
|
|
KeyboardLayout = AllocatePool (Length);
|
|
|
|
ASSERT (KeyboardLayout != NULL);
|
|
|
|
|
|
|
|
Status = HiiDatabase->GetKeyboardLayout (
|
|
|
|
HiiDatabase,
|
|
|
|
NULL,
|
|
|
|
&Length,
|
|
|
|
KeyboardLayout
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
2009-01-13 09:46:31 +01:00
|
|
|
FreePool (KeyboardLayout);
|
2008-06-23 11:41:33 +02:00
|
|
|
KeyboardLayout = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return KeyboardLayout;
|
|
|
|
}
|
|
|
|
|
2008-07-23 08:29:46 +02:00
|
|
|
/**
|
2008-12-15 08:17:47 +01:00
|
|
|
Find Key Descriptor in Key Convertion Table given its USB keycode.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
|
|
|
@param UsbKeyboardDevice The USB_KB_DEV instance.
|
2008-12-15 08:17:47 +01:00
|
|
|
@param KeyCode USB Keycode.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
2008-12-15 08:17:47 +01:00
|
|
|
@return The Key Descriptor in Key Convertion Table.
|
2008-12-05 10:19:10 +01:00
|
|
|
NULL means not found.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
|
|
|
**/
|
2008-06-23 11:41:33 +02:00
|
|
|
EFI_KEY_DESCRIPTOR *
|
|
|
|
GetKeyDescriptor (
|
|
|
|
IN USB_KB_DEV *UsbKeyboardDevice,
|
2008-12-15 08:17:47 +01:00
|
|
|
IN UINT8 KeyCode
|
2008-06-23 11:41:33 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
UINT8 Index;
|
|
|
|
|
2008-12-15 08:17:47 +01:00
|
|
|
//
|
|
|
|
// Make sure KeyCode is in the range of [0x4, 0x65] or [0xe0, 0xe7]
|
|
|
|
//
|
|
|
|
if ((!USBKBD_VALID_KEYCODE (KeyCode)) || ((KeyCode > 0x65) && (KeyCode < 0xe0)) || (KeyCode > 0xe7)) {
|
2008-06-23 11:41:33 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-12-15 08:17:47 +01:00
|
|
|
//
|
|
|
|
// Calculate the index of Key Descriptor in Key Convertion Table
|
|
|
|
//
|
|
|
|
if (KeyCode <= 0x65) {
|
|
|
|
Index = (UINT8) (KeyCode - 4);
|
2008-06-23 11:41:33 +02:00
|
|
|
} else {
|
2008-12-15 08:17:47 +01:00
|
|
|
Index = (UINT8) (KeyCode - 0xe0 + NUMBER_OF_VALID_NON_MODIFIER_USB_KEYCODE);
|
2008-06-23 11:41:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return &UsbKeyboardDevice->KeyConvertionTable[Index];
|
|
|
|
}
|
|
|
|
|
2008-07-23 08:29:46 +02:00
|
|
|
/**
|
2008-12-15 08:17:47 +01:00
|
|
|
Find Non-Spacing key for given Key descriptor.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
|
|
|
@param UsbKeyboardDevice The USB_KB_DEV instance.
|
|
|
|
@param KeyDescriptor Key descriptor.
|
|
|
|
|
2008-12-05 10:19:10 +01:00
|
|
|
@return The Non-Spacing key corresponding to KeyDescriptor
|
|
|
|
NULL means not found.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
|
|
|
**/
|
2008-06-23 11:41:33 +02:00
|
|
|
USB_NS_KEY *
|
|
|
|
FindUsbNsKey (
|
|
|
|
IN USB_KB_DEV *UsbKeyboardDevice,
|
|
|
|
IN EFI_KEY_DESCRIPTOR *KeyDescriptor
|
|
|
|
)
|
|
|
|
{
|
|
|
|
LIST_ENTRY *Link;
|
2008-12-26 10:18:12 +01:00
|
|
|
LIST_ENTRY *NsKeyList;
|
2008-06-23 11:41:33 +02:00
|
|
|
USB_NS_KEY *UsbNsKey;
|
2011-09-30 09:28:16 +02:00
|
|
|
|
2008-12-26 10:18:12 +01:00
|
|
|
NsKeyList = &UsbKeyboardDevice->NsKeyList;
|
|
|
|
Link = GetFirstNode (NsKeyList);
|
|
|
|
while (!IsNull (NsKeyList, Link)) {
|
2008-06-23 11:41:33 +02:00
|
|
|
UsbNsKey = USB_NS_KEY_FORM_FROM_LINK (Link);
|
|
|
|
|
|
|
|
if (UsbNsKey->NsKey[0].Key == KeyDescriptor->Key) {
|
|
|
|
return UsbNsKey;
|
|
|
|
}
|
|
|
|
|
2008-12-26 10:18:12 +01:00
|
|
|
Link = GetNextNode (NsKeyList, Link);
|
2008-06-23 11:41:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-07-23 08:29:46 +02:00
|
|
|
/**
|
2008-12-15 08:17:47 +01:00
|
|
|
Find physical key definition for a given key descriptor.
|
|
|
|
|
|
|
|
For a specified non-spacing key, there are a list of physical
|
|
|
|
keys following it. This function traverses the list of
|
|
|
|
physical keys and tries to find the physical key matching
|
|
|
|
the KeyDescriptor.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
2008-12-15 08:17:47 +01:00
|
|
|
@param UsbNsKey The non-spacing key information.
|
|
|
|
@param KeyDescriptor The key descriptor.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
|
|
|
@return The physical key definition.
|
2008-12-15 08:17:47 +01:00
|
|
|
If no physical key is found, parameter KeyDescriptor is returned.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
|
|
|
**/
|
2008-06-23 11:41:33 +02:00
|
|
|
EFI_KEY_DESCRIPTOR *
|
|
|
|
FindPhysicalKey (
|
|
|
|
IN USB_NS_KEY *UsbNsKey,
|
|
|
|
IN EFI_KEY_DESCRIPTOR *KeyDescriptor
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UINTN Index;
|
|
|
|
EFI_KEY_DESCRIPTOR *PhysicalKey;
|
|
|
|
|
|
|
|
PhysicalKey = &UsbNsKey->NsKey[1];
|
|
|
|
for (Index = 0; Index < UsbNsKey->KeyCount; Index++) {
|
|
|
|
if (KeyDescriptor->Key == PhysicalKey->Key) {
|
|
|
|
return PhysicalKey;
|
|
|
|
}
|
|
|
|
|
|
|
|
PhysicalKey++;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// No children definition matched, return original key
|
|
|
|
//
|
|
|
|
return KeyDescriptor;
|
|
|
|
}
|
|
|
|
|
2008-07-23 08:29:46 +02:00
|
|
|
/**
|
2008-12-15 08:17:47 +01:00
|
|
|
The notification function for EFI_HII_SET_KEYBOARD_LAYOUT_EVENT_GUID.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
2008-12-15 08:17:47 +01:00
|
|
|
This function is registered to event of EFI_HII_SET_KEYBOARD_LAYOUT_EVENT_GUID
|
|
|
|
group type, which will be triggered by EFI_HII_DATABASE_PROTOCOL.SetKeyboardLayout().
|
|
|
|
It tries to get curent keyboard layout from HII database.
|
|
|
|
|
|
|
|
@param Event Event being signaled.
|
|
|
|
@param Context Points to USB_KB_DEV instance.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
|
|
|
**/
|
2008-06-23 11:41:33 +02:00
|
|
|
VOID
|
|
|
|
EFIAPI
|
|
|
|
SetKeyboardLayoutEvent (
|
2008-12-15 08:17:47 +01:00
|
|
|
IN EFI_EVENT Event,
|
|
|
|
IN VOID *Context
|
2008-06-23 11:41:33 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
USB_KB_DEV *UsbKeyboardDevice;
|
|
|
|
EFI_HII_KEYBOARD_LAYOUT *KeyboardLayout;
|
|
|
|
EFI_KEY_DESCRIPTOR TempKey;
|
|
|
|
EFI_KEY_DESCRIPTOR *KeyDescriptor;
|
|
|
|
EFI_KEY_DESCRIPTOR *TableEntry;
|
|
|
|
EFI_KEY_DESCRIPTOR *NsKey;
|
|
|
|
USB_NS_KEY *UsbNsKey;
|
|
|
|
UINTN Index;
|
|
|
|
UINTN Index2;
|
|
|
|
UINTN KeyCount;
|
2008-12-15 08:17:47 +01:00
|
|
|
UINT8 KeyCode;
|
2008-06-23 11:41:33 +02:00
|
|
|
|
|
|
|
UsbKeyboardDevice = (USB_KB_DEV *) Context;
|
2009-08-24 08:24:24 +02:00
|
|
|
if (UsbKeyboardDevice->Signature != USB_KB_DEV_SIGNATURE) {
|
|
|
|
return;
|
|
|
|
}
|
2008-06-23 11:41:33 +02:00
|
|
|
|
|
|
|
//
|
2008-12-15 08:17:47 +01:00
|
|
|
// Try to get current keyboard layout from HII database
|
2008-06-23 11:41:33 +02:00
|
|
|
//
|
|
|
|
KeyboardLayout = GetCurrentKeyboardLayout ();
|
|
|
|
if (KeyboardLayout == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2008-12-05 10:19:10 +01:00
|
|
|
// Re-allocate resource for KeyConvertionTable
|
2008-06-23 11:41:33 +02:00
|
|
|
//
|
|
|
|
ReleaseKeyboardLayoutResources (UsbKeyboardDevice);
|
2008-12-15 08:17:47 +01:00
|
|
|
UsbKeyboardDevice->KeyConvertionTable = AllocateZeroPool ((NUMBER_OF_VALID_USB_KEYCODE) * sizeof (EFI_KEY_DESCRIPTOR));
|
2008-06-23 11:41:33 +02:00
|
|
|
ASSERT (UsbKeyboardDevice->KeyConvertionTable != NULL);
|
|
|
|
|
2008-12-05 10:19:10 +01:00
|
|
|
//
|
|
|
|
// Traverse the list of key descriptors following the header of EFI_HII_KEYBOARD_LAYOUT
|
|
|
|
//
|
2008-06-23 11:41:33 +02:00
|
|
|
KeyDescriptor = (EFI_KEY_DESCRIPTOR *) (((UINT8 *) KeyboardLayout) + sizeof (EFI_HII_KEYBOARD_LAYOUT));
|
|
|
|
for (Index = 0; Index < KeyboardLayout->DescriptorCount; Index++) {
|
|
|
|
//
|
|
|
|
// Copy from HII keyboard layout package binary for alignment
|
|
|
|
//
|
|
|
|
CopyMem (&TempKey, KeyDescriptor, sizeof (EFI_KEY_DESCRIPTOR));
|
|
|
|
|
|
|
|
//
|
2008-12-15 08:17:47 +01:00
|
|
|
// Fill the key into KeyConvertionTable, whose index is calculated from USB keycode.
|
2008-06-23 11:41:33 +02:00
|
|
|
//
|
2008-12-15 08:17:47 +01:00
|
|
|
KeyCode = EfiKeyToUsbKeyCodeConvertionTable [(UINT8) (TempKey.Key)];
|
|
|
|
TableEntry = GetKeyDescriptor (UsbKeyboardDevice, KeyCode);
|
2011-09-23 09:44:49 +02:00
|
|
|
if (TableEntry == NULL) {
|
|
|
|
ReleaseKeyboardLayoutResources (UsbKeyboardDevice);
|
|
|
|
FreePool (KeyboardLayout);
|
|
|
|
return;
|
|
|
|
}
|
2008-06-23 11:41:33 +02:00
|
|
|
CopyMem (TableEntry, KeyDescriptor, sizeof (EFI_KEY_DESCRIPTOR));
|
|
|
|
|
2008-12-15 08:17:47 +01:00
|
|
|
//
|
|
|
|
// For non-spacing key, create the list with a non-spacing key followed by physical keys.
|
|
|
|
//
|
2008-06-23 11:41:33 +02:00
|
|
|
if (TempKey.Modifier == EFI_NS_KEY_MODIFIER) {
|
2011-09-23 09:44:49 +02:00
|
|
|
UsbNsKey = AllocateZeroPool (sizeof (USB_NS_KEY));
|
2008-06-23 11:41:33 +02:00
|
|
|
ASSERT (UsbNsKey != NULL);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Search for sequential children physical key definitions
|
|
|
|
//
|
|
|
|
KeyCount = 0;
|
|
|
|
NsKey = KeyDescriptor + 1;
|
2011-04-19 08:52:20 +02:00
|
|
|
for (Index2 = (UINT8) Index + 1; Index2 < KeyboardLayout->DescriptorCount; Index2++) {
|
2008-06-23 11:41:33 +02:00
|
|
|
CopyMem (&TempKey, NsKey, sizeof (EFI_KEY_DESCRIPTOR));
|
2009-02-06 06:34:53 +01:00
|
|
|
if (TempKey.Modifier == EFI_NS_KEY_DEPENDENCY_MODIFIER) {
|
2008-06-23 11:41:33 +02:00
|
|
|
KeyCount++;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
NsKey++;
|
|
|
|
}
|
|
|
|
|
|
|
|
UsbNsKey->Signature = USB_NS_KEY_SIGNATURE;
|
|
|
|
UsbNsKey->KeyCount = KeyCount;
|
|
|
|
UsbNsKey->NsKey = AllocateCopyPool (
|
|
|
|
(KeyCount + 1) * sizeof (EFI_KEY_DESCRIPTOR),
|
|
|
|
KeyDescriptor
|
|
|
|
);
|
|
|
|
InsertTailList (&UsbKeyboardDevice->NsKeyList, &UsbNsKey->Link);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Skip over the child physical keys
|
|
|
|
//
|
|
|
|
Index += KeyCount;
|
|
|
|
KeyDescriptor += KeyCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
KeyDescriptor++;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2008-12-15 08:17:47 +01:00
|
|
|
// There are two EfiKeyEnter, duplicate its key descriptor
|
2008-06-23 11:41:33 +02:00
|
|
|
//
|
|
|
|
TableEntry = GetKeyDescriptor (UsbKeyboardDevice, 0x58);
|
|
|
|
KeyDescriptor = GetKeyDescriptor (UsbKeyboardDevice, 0x28);
|
|
|
|
CopyMem (TableEntry, KeyDescriptor, sizeof (EFI_KEY_DESCRIPTOR));
|
|
|
|
|
2008-12-26 10:18:12 +01:00
|
|
|
FreePool (KeyboardLayout);
|
2008-06-23 11:41:33 +02:00
|
|
|
}
|
|
|
|
|
2008-07-23 08:29:46 +02:00
|
|
|
/**
|
2008-12-15 08:17:47 +01:00
|
|
|
Destroy resources for keyboard layout.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
|
|
|
@param UsbKeyboardDevice The USB_KB_DEV instance.
|
|
|
|
|
|
|
|
**/
|
2008-06-23 11:41:33 +02:00
|
|
|
VOID
|
|
|
|
ReleaseKeyboardLayoutResources (
|
2008-12-15 08:17:47 +01:00
|
|
|
IN OUT USB_KB_DEV *UsbKeyboardDevice
|
2008-06-23 11:41:33 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
USB_NS_KEY *UsbNsKey;
|
|
|
|
LIST_ENTRY *Link;
|
|
|
|
|
2008-10-30 08:32:46 +01:00
|
|
|
if (UsbKeyboardDevice->KeyConvertionTable != NULL) {
|
|
|
|
FreePool (UsbKeyboardDevice->KeyConvertionTable);
|
|
|
|
}
|
2008-06-23 11:41:33 +02:00
|
|
|
UsbKeyboardDevice->KeyConvertionTable = NULL;
|
|
|
|
|
|
|
|
while (!IsListEmpty (&UsbKeyboardDevice->NsKeyList)) {
|
|
|
|
Link = GetFirstNode (&UsbKeyboardDevice->NsKeyList);
|
|
|
|
UsbNsKey = USB_NS_KEY_FORM_FROM_LINK (Link);
|
|
|
|
RemoveEntryList (&UsbNsKey->Link);
|
|
|
|
|
2008-10-30 08:32:46 +01:00
|
|
|
FreePool (UsbNsKey->NsKey);
|
|
|
|
FreePool (UsbNsKey);
|
2008-06-23 11:41:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-23 08:29:46 +02:00
|
|
|
/**
|
2008-12-15 08:17:47 +01:00
|
|
|
Initialize USB keyboard layout.
|
|
|
|
|
|
|
|
This function initializes Key Convertion Table for the USB keyboard device.
|
|
|
|
It first tries to retrieve layout from HII database. If failed and default
|
|
|
|
layout is enabled, then it just uses the default layout.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
|
|
|
@param UsbKeyboardDevice The USB_KB_DEV instance.
|
|
|
|
|
2008-12-15 08:17:47 +01:00
|
|
|
@retval EFI_SUCCESS Initialization succeeded.
|
|
|
|
@retval EFI_NOT_READY Keyboard layout cannot be retrieve from HII
|
|
|
|
database, and default layout is disabled.
|
|
|
|
@retval Other Fail to register event to EFI_HII_SET_KEYBOARD_LAYOUT_EVENT_GUID group.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
|
|
|
**/
|
2008-06-23 11:41:33 +02:00
|
|
|
EFI_STATUS
|
|
|
|
InitKeyboardLayout (
|
2008-12-15 08:17:47 +01:00
|
|
|
OUT USB_KB_DEV *UsbKeyboardDevice
|
2008-06-23 11:41:33 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_HII_KEYBOARD_LAYOUT *KeyboardLayout;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
2008-12-15 08:17:47 +01:00
|
|
|
UsbKeyboardDevice->KeyConvertionTable = AllocateZeroPool ((NUMBER_OF_VALID_USB_KEYCODE) * sizeof (EFI_KEY_DESCRIPTOR));
|
2008-06-23 11:41:33 +02:00
|
|
|
ASSERT (UsbKeyboardDevice->KeyConvertionTable != NULL);
|
|
|
|
|
|
|
|
InitializeListHead (&UsbKeyboardDevice->NsKeyList);
|
|
|
|
UsbKeyboardDevice->CurrentNsKey = NULL;
|
|
|
|
UsbKeyboardDevice->KeyboardLayoutEvent = NULL;
|
|
|
|
|
|
|
|
//
|
2008-12-05 10:19:10 +01:00
|
|
|
// Register event to EFI_HII_SET_KEYBOARD_LAYOUT_EVENT_GUID group,
|
2008-12-15 08:17:47 +01:00
|
|
|
// which will be triggered by EFI_HII_DATABASE_PROTOCOL.SetKeyboardLayout().
|
2008-06-23 11:41:33 +02:00
|
|
|
//
|
|
|
|
Status = gBS->CreateEventEx (
|
2008-09-04 09:42:38 +02:00
|
|
|
EVT_NOTIFY_SIGNAL,
|
2008-06-23 11:41:33 +02:00
|
|
|
TPL_NOTIFY,
|
|
|
|
SetKeyboardLayoutEvent,
|
|
|
|
UsbKeyboardDevice,
|
2009-01-23 11:01:51 +01:00
|
|
|
&gEfiHiiKeyBoardLayoutGuid,
|
2008-06-23 11:41:33 +02:00
|
|
|
&UsbKeyboardDevice->KeyboardLayoutEvent
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
KeyboardLayout = GetCurrentKeyboardLayout ();
|
|
|
|
if (KeyboardLayout != NULL) {
|
|
|
|
//
|
2008-12-05 10:19:10 +01:00
|
|
|
// If current keyboard layout is successfully retrieved from HII database,
|
|
|
|
// force to initialize the keyboard layout.
|
2008-06-23 11:41:33 +02:00
|
|
|
//
|
|
|
|
gBS->SignalEvent (UsbKeyboardDevice->KeyboardLayoutEvent);
|
|
|
|
} else {
|
|
|
|
if (FeaturePcdGet (PcdDisableDefaultKeyboardLayoutInUsbKbDriver)) {
|
|
|
|
//
|
2008-12-05 10:19:10 +01:00
|
|
|
// If no keyboard layout can be retrieved from HII database, and default layout
|
|
|
|
// is disabled, then return EFI_NOT_READY.
|
2008-06-23 11:41:33 +02:00
|
|
|
//
|
2008-12-05 10:19:10 +01:00
|
|
|
return EFI_NOT_READY;
|
2008-06-23 11:41:33 +02:00
|
|
|
}
|
2008-12-05 10:19:10 +01:00
|
|
|
//
|
|
|
|
// If no keyboard layout can be retrieved from HII database, and default layout
|
|
|
|
// is enabled, then load the default keyboard layout.
|
|
|
|
//
|
2009-04-10 06:28:13 +02:00
|
|
|
InstallDefaultKeyboardLayout (UsbKeyboardDevice);
|
2008-06-23 11:41:33 +02:00
|
|
|
}
|
2011-09-30 09:28:16 +02:00
|
|
|
|
2008-06-23 11:41:33 +02:00
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2007-07-12 19:31:28 +02:00
|
|
|
|
|
|
|
/**
|
2008-12-15 08:17:47 +01:00
|
|
|
Initialize USB keyboard device and all private data structures.
|
2007-07-12 19:31:28 +02:00
|
|
|
|
2008-07-23 08:29:46 +02:00
|
|
|
@param UsbKeyboardDevice The USB_KB_DEV instance.
|
2007-07-12 19:31:28 +02:00
|
|
|
|
2008-07-23 08:29:46 +02:00
|
|
|
@retval EFI_SUCCESS Initialization is successful.
|
2008-12-15 08:17:47 +01:00
|
|
|
@retval EFI_DEVICE_ERROR Keyboard initialization failed.
|
2007-07-12 19:31:28 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
InitUSBKeyboard (
|
2008-12-15 08:17:47 +01:00
|
|
|
IN OUT USB_KB_DEV *UsbKeyboardDevice
|
2007-07-12 19:31:28 +02:00
|
|
|
)
|
|
|
|
{
|
2009-12-16 01:58:46 +01:00
|
|
|
UINT16 ConfigValue;
|
2007-07-12 19:31:28 +02:00
|
|
|
UINT8 Protocol;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINT32 TransferResult;
|
|
|
|
|
2008-12-05 10:19:10 +01:00
|
|
|
REPORT_STATUS_CODE_WITH_DEVICE_PATH (
|
2007-07-12 19:31:28 +02:00
|
|
|
EFI_PROGRESS_CODE,
|
2010-01-27 05:00:58 +01:00
|
|
|
(EFI_PERIPHERAL_KEYBOARD | EFI_P_KEYBOARD_PC_SELF_TEST),
|
2008-12-05 10:19:10 +01:00
|
|
|
UsbKeyboardDevice->DevicePath
|
2007-07-12 19:31:28 +02:00
|
|
|
);
|
|
|
|
|
2011-04-19 08:52:20 +02:00
|
|
|
InitQueue (&UsbKeyboardDevice->UsbKeyQueue, sizeof (USB_KEY));
|
|
|
|
InitQueue (&UsbKeyboardDevice->EfiKeyQueue, sizeof (EFI_KEY_DATA));
|
2016-12-16 10:16:22 +01:00
|
|
|
InitQueue (&UsbKeyboardDevice->EfiKeyQueueForNotify, sizeof (EFI_KEY_DATA));
|
2007-07-12 19:31:28 +02:00
|
|
|
|
|
|
|
//
|
2009-12-16 01:58:46 +01:00
|
|
|
// Use the config out of the descriptor
|
|
|
|
// Assumed the first config is the correct one and this is not always the case
|
|
|
|
//
|
|
|
|
Status = UsbGetConfiguration (
|
2011-09-30 09:28:16 +02:00
|
|
|
UsbKeyboardDevice->UsbIo,
|
|
|
|
&ConfigValue,
|
2009-12-16 01:58:46 +01:00
|
|
|
&TransferResult
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
ConfigValue = 0x01;
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
2012-03-07 09:39:35 +01:00
|
|
|
// Uses default configuration to configure the USB Keyboard device.
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
2012-03-07 09:39:35 +01:00
|
|
|
Status = UsbSetConfiguration (
|
|
|
|
UsbKeyboardDevice->UsbIo,
|
|
|
|
ConfigValue,
|
|
|
|
&TransferResult
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
//
|
|
|
|
// If configuration could not be set here, it means
|
|
|
|
// the keyboard interface has some errors and could
|
|
|
|
// not be initialized
|
|
|
|
//
|
|
|
|
REPORT_STATUS_CODE_WITH_DEVICE_PATH (
|
|
|
|
EFI_ERROR_CODE | EFI_ERROR_MINOR,
|
|
|
|
(EFI_PERIPHERAL_KEYBOARD | EFI_P_EC_INTERFACE_ERROR),
|
|
|
|
UsbKeyboardDevice->DevicePath
|
|
|
|
);
|
2007-07-12 19:31:28 +02:00
|
|
|
|
2012-03-07 09:39:35 +01:00
|
|
|
return EFI_DEVICE_ERROR;
|
|
|
|
}
|
2007-07-12 19:31:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
UsbGetProtocolRequest (
|
|
|
|
UsbKeyboardDevice->UsbIo,
|
|
|
|
UsbKeyboardDevice->InterfaceDescriptor.InterfaceNumber,
|
|
|
|
&Protocol
|
|
|
|
);
|
|
|
|
//
|
2008-12-05 10:19:10 +01:00
|
|
|
// Set boot protocol for the USB Keyboard.
|
2007-07-12 19:31:28 +02:00
|
|
|
// This driver only supports boot protocol.
|
|
|
|
//
|
|
|
|
if (Protocol != BOOT_PROTOCOL) {
|
|
|
|
UsbSetProtocolRequest (
|
|
|
|
UsbKeyboardDevice->UsbIo,
|
|
|
|
UsbKeyboardDevice->InterfaceDescriptor.InterfaceNumber,
|
|
|
|
BOOT_PROTOCOL
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2008-12-15 08:17:47 +01:00
|
|
|
UsbKeyboardDevice->CtrlOn = FALSE;
|
|
|
|
UsbKeyboardDevice->AltOn = FALSE;
|
|
|
|
UsbKeyboardDevice->ShiftOn = FALSE;
|
|
|
|
UsbKeyboardDevice->NumLockOn = FALSE;
|
|
|
|
UsbKeyboardDevice->CapsOn = FALSE;
|
|
|
|
UsbKeyboardDevice->ScrollOn = FALSE;
|
2011-09-30 09:28:16 +02:00
|
|
|
|
2008-12-15 08:17:47 +01:00
|
|
|
UsbKeyboardDevice->LeftCtrlOn = FALSE;
|
|
|
|
UsbKeyboardDevice->LeftAltOn = FALSE;
|
|
|
|
UsbKeyboardDevice->LeftShiftOn = FALSE;
|
|
|
|
UsbKeyboardDevice->LeftLogoOn = FALSE;
|
|
|
|
UsbKeyboardDevice->RightCtrlOn = FALSE;
|
|
|
|
UsbKeyboardDevice->RightAltOn = FALSE;
|
|
|
|
UsbKeyboardDevice->RightShiftOn = FALSE;
|
|
|
|
UsbKeyboardDevice->RightLogoOn = FALSE;
|
|
|
|
UsbKeyboardDevice->MenuKeyOn = FALSE;
|
|
|
|
UsbKeyboardDevice->SysReqOn = FALSE;
|
|
|
|
|
|
|
|
UsbKeyboardDevice->AltGrOn = FALSE;
|
2008-06-23 11:41:33 +02:00
|
|
|
|
|
|
|
UsbKeyboardDevice->CurrentNsKey = NULL;
|
2007-07-12 19:31:28 +02:00
|
|
|
|
|
|
|
//
|
2008-12-15 08:17:47 +01:00
|
|
|
// Sync the initial state of lights on keyboard.
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
|
|
|
SetKeyLED (UsbKeyboardDevice);
|
|
|
|
|
|
|
|
ZeroMem (UsbKeyboardDevice->LastKeyCodeArray, sizeof (UINT8) * 8);
|
|
|
|
|
|
|
|
//
|
2009-01-13 09:46:31 +01:00
|
|
|
// Create event for repeat keys' generation.
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
2008-07-23 08:29:46 +02:00
|
|
|
if (UsbKeyboardDevice->RepeatTimer != NULL) {
|
2007-07-12 19:31:28 +02:00
|
|
|
gBS->CloseEvent (UsbKeyboardDevice->RepeatTimer);
|
2008-12-05 10:19:10 +01:00
|
|
|
UsbKeyboardDevice->RepeatTimer = NULL;
|
2007-07-12 19:31:28 +02:00
|
|
|
}
|
|
|
|
|
2009-01-13 09:46:31 +01:00
|
|
|
gBS->CreateEvent (
|
|
|
|
EVT_TIMER | EVT_NOTIFY_SIGNAL,
|
2009-06-11 08:25:30 +02:00
|
|
|
TPL_CALLBACK,
|
2009-01-13 09:46:31 +01:00
|
|
|
USBKeyboardRepeatHandler,
|
|
|
|
UsbKeyboardDevice,
|
|
|
|
&UsbKeyboardDevice->RepeatTimer
|
|
|
|
);
|
2007-07-12 19:31:28 +02:00
|
|
|
|
2009-01-13 09:46:31 +01:00
|
|
|
//
|
|
|
|
// Create event for delayed recovery, which deals with device error.
|
|
|
|
//
|
2008-07-23 08:29:46 +02:00
|
|
|
if (UsbKeyboardDevice->DelayedRecoveryEvent != NULL) {
|
2007-07-12 19:31:28 +02:00
|
|
|
gBS->CloseEvent (UsbKeyboardDevice->DelayedRecoveryEvent);
|
2008-12-05 10:19:10 +01:00
|
|
|
UsbKeyboardDevice->DelayedRecoveryEvent = NULL;
|
2007-07-12 19:31:28 +02:00
|
|
|
}
|
|
|
|
|
2009-01-13 09:46:31 +01:00
|
|
|
gBS->CreateEvent (
|
|
|
|
EVT_TIMER | EVT_NOTIFY_SIGNAL,
|
|
|
|
TPL_NOTIFY,
|
|
|
|
USBKeyboardRecoveryHandler,
|
|
|
|
UsbKeyboardDevice,
|
|
|
|
&UsbKeyboardDevice->DelayedRecoveryEvent
|
|
|
|
);
|
2007-07-12 19:31:28 +02:00
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-12-15 08:17:47 +01:00
|
|
|
Handler function for USB keyboard's asynchronous interrupt transfer.
|
|
|
|
|
|
|
|
This function is the handler function for USB keyboard's asynchronous interrupt transfer
|
|
|
|
to manage the keyboard. It parses the USB keyboard input report, and inserts data to
|
|
|
|
keyboard buffer according to state of modifer keys and normal keys. Timer for repeat key
|
|
|
|
is also set accordingly.
|
2007-07-12 19:31:28 +02:00
|
|
|
|
2008-07-23 08:29:46 +02:00
|
|
|
@param Data A pointer to a buffer that is filled with key data which is
|
|
|
|
retrieved via asynchronous interrupt transfer.
|
|
|
|
@param DataLength Indicates the size of the data buffer.
|
|
|
|
@param Context Pointing to USB_KB_DEV instance.
|
|
|
|
@param Result Indicates the result of the asynchronous interrupt transfer.
|
2007-07-12 19:31:28 +02:00
|
|
|
|
2008-12-15 08:17:47 +01:00
|
|
|
@retval EFI_SUCCESS Asynchronous interrupt transfer is handled successfully.
|
|
|
|
@retval EFI_DEVICE_ERROR Hardware error occurs.
|
2007-07-12 19:31:28 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
KeyboardHandler (
|
|
|
|
IN VOID *Data,
|
|
|
|
IN UINTN DataLength,
|
|
|
|
IN VOID *Context,
|
|
|
|
IN UINT32 Result
|
|
|
|
)
|
|
|
|
{
|
|
|
|
USB_KB_DEV *UsbKeyboardDevice;
|
|
|
|
EFI_USB_IO_PROTOCOL *UsbIo;
|
|
|
|
UINT8 *CurKeyCodeBuffer;
|
|
|
|
UINT8 *OldKeyCodeBuffer;
|
|
|
|
UINT8 CurModifierMap;
|
|
|
|
UINT8 OldModifierMap;
|
2008-12-15 08:17:47 +01:00
|
|
|
UINT8 Mask;
|
2011-04-19 08:52:20 +02:00
|
|
|
UINTN Index;
|
2007-07-12 19:31:28 +02:00
|
|
|
UINT8 Index2;
|
|
|
|
BOOLEAN KeyRelease;
|
|
|
|
BOOLEAN KeyPress;
|
|
|
|
USB_KEY UsbKey;
|
|
|
|
UINT8 NewRepeatKey;
|
|
|
|
UINT32 UsbStatus;
|
2008-06-23 11:41:33 +02:00
|
|
|
EFI_KEY_DESCRIPTOR *KeyDescriptor;
|
2007-07-12 19:31:28 +02:00
|
|
|
|
2008-12-05 10:19:10 +01:00
|
|
|
ASSERT (Context != NULL);
|
2007-07-12 19:31:28 +02:00
|
|
|
|
|
|
|
NewRepeatKey = 0;
|
|
|
|
UsbKeyboardDevice = (USB_KB_DEV *) Context;
|
|
|
|
UsbIo = UsbKeyboardDevice->UsbIo;
|
|
|
|
|
|
|
|
//
|
2008-12-15 08:17:47 +01:00
|
|
|
// Analyzes Result and performs corresponding action.
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
|
|
|
if (Result != EFI_USB_NOERROR) {
|
|
|
|
//
|
|
|
|
// Some errors happen during the process
|
|
|
|
//
|
2008-12-05 10:19:10 +01:00
|
|
|
REPORT_STATUS_CODE_WITH_DEVICE_PATH (
|
2007-07-12 19:31:28 +02:00
|
|
|
EFI_ERROR_CODE | EFI_ERROR_MINOR,
|
2010-01-27 05:00:58 +01:00
|
|
|
(EFI_PERIPHERAL_KEYBOARD | EFI_P_EC_INPUT_ERROR),
|
2008-12-05 10:19:10 +01:00
|
|
|
UsbKeyboardDevice->DevicePath
|
2007-07-12 19:31:28 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
//
|
2008-12-15 08:17:47 +01:00
|
|
|
// Stop the repeat key generation if any
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
|
|
|
UsbKeyboardDevice->RepeatKey = 0;
|
|
|
|
|
|
|
|
gBS->SetTimer (
|
|
|
|
UsbKeyboardDevice->RepeatTimer,
|
|
|
|
TimerCancel,
|
|
|
|
USBKBD_REPEAT_RATE
|
|
|
|
);
|
|
|
|
|
|
|
|
if ((Result & EFI_USB_ERR_STALL) == EFI_USB_ERR_STALL) {
|
|
|
|
UsbClearEndpointHalt (
|
|
|
|
UsbIo,
|
|
|
|
UsbKeyboardDevice->IntEndpointDescriptor.EndpointAddress,
|
|
|
|
&UsbStatus
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Delete & Submit this interrupt again
|
2011-09-30 09:28:16 +02:00
|
|
|
// Handler of DelayedRecoveryEvent triggered by timer will re-submit the interrupt.
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
2007-07-17 03:48:09 +02:00
|
|
|
UsbIo->UsbAsyncInterruptTransfer (
|
2008-12-05 10:19:10 +01:00
|
|
|
UsbIo,
|
|
|
|
UsbKeyboardDevice->IntEndpointDescriptor.EndpointAddress,
|
|
|
|
FALSE,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
//
|
2008-12-15 08:17:47 +01:00
|
|
|
// EFI_USB_INTERRUPT_DELAY is defined in USB standard for error handling.
|
2008-12-05 10:19:10 +01:00
|
|
|
//
|
2007-07-12 19:31:28 +02:00
|
|
|
gBS->SetTimer (
|
2008-12-05 10:19:10 +01:00
|
|
|
UsbKeyboardDevice->DelayedRecoveryEvent,
|
|
|
|
TimerRelative,
|
|
|
|
EFI_USB_INTERRUPT_DELAY
|
|
|
|
);
|
2007-07-12 19:31:28 +02:00
|
|
|
|
|
|
|
return EFI_DEVICE_ERROR;
|
|
|
|
}
|
|
|
|
|
2008-12-05 10:19:10 +01:00
|
|
|
//
|
|
|
|
// If no error and no data, just return EFI_SUCCESS.
|
|
|
|
//
|
2007-07-12 19:31:28 +02:00
|
|
|
if (DataLength == 0 || Data == NULL) {
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2008-12-05 10:19:10 +01:00
|
|
|
//
|
|
|
|
// Following code checks current keyboard input report against old key code buffer.
|
|
|
|
// According to USB HID Firmware Specification, the report consists of 8 bytes.
|
|
|
|
// Byte 0 is map of Modifier keys.
|
|
|
|
// Byte 1 is reserved.
|
|
|
|
// Bytes 2 to 7 are keycodes.
|
|
|
|
//
|
2018-09-13 09:49:23 +02:00
|
|
|
if (DataLength < 8) {
|
|
|
|
return EFI_DEVICE_ERROR;
|
|
|
|
}
|
|
|
|
|
2007-07-12 19:31:28 +02:00
|
|
|
CurKeyCodeBuffer = (UINT8 *) Data;
|
|
|
|
OldKeyCodeBuffer = UsbKeyboardDevice->LastKeyCodeArray;
|
|
|
|
|
|
|
|
//
|
2008-12-05 10:19:10 +01:00
|
|
|
// Checks for new key stroke.
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
|
|
|
for (Index = 0; Index < 8; Index++) {
|
|
|
|
if (OldKeyCodeBuffer[Index] != CurKeyCodeBuffer[Index]) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-05 10:19:10 +01:00
|
|
|
//
|
|
|
|
// If no new key, return EFI_SUCCESS immediately.
|
|
|
|
//
|
2007-07-12 19:31:28 +02:00
|
|
|
if (Index == 8) {
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2008-12-05 10:19:10 +01:00
|
|
|
// Parse the modifier key, which is the first byte of keyboard input report.
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
|
|
|
CurModifierMap = CurKeyCodeBuffer[0];
|
|
|
|
OldModifierMap = OldKeyCodeBuffer[0];
|
|
|
|
|
|
|
|
//
|
2008-12-05 10:19:10 +01:00
|
|
|
// Handle modifier key's pressing or releasing situation.
|
2008-12-15 08:17:47 +01:00
|
|
|
// According to USB HID Firmware spec, Byte 0 uses folloing map of Modifier keys:
|
|
|
|
// Bit0: Left Control, Keycode: 0xe0
|
|
|
|
// Bit1: Left Shift, Keycode: 0xe1
|
|
|
|
// Bit2: Left Alt, Keycode: 0xe2
|
|
|
|
// Bit3: Left GUI, Keycode: 0xe3
|
|
|
|
// Bit4: Right Control, Keycode: 0xe4
|
|
|
|
// Bit5: Right Shift, Keycode: 0xe5
|
|
|
|
// Bit6: Right Alt, Keycode: 0xe6
|
|
|
|
// Bit7: Right GUI, Keycode: 0xe7
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
|
|
|
for (Index = 0; Index < 8; Index++) {
|
2008-12-15 08:17:47 +01:00
|
|
|
Mask = (UINT8) (1 << Index);
|
|
|
|
if ((CurModifierMap & Mask) != (OldModifierMap & Mask)) {
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
2008-12-15 08:17:47 +01:00
|
|
|
// If current modifier key is up, then CurModifierMap & Mask = 0;
|
2008-12-05 10:19:10 +01:00
|
|
|
// otherwise it is a non-zero value.
|
2008-12-15 08:17:47 +01:00
|
|
|
// Insert the changed modifier key into key buffer.
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
2011-04-19 08:52:20 +02:00
|
|
|
UsbKey.KeyCode = (UINT8) (0xe0 + Index);
|
|
|
|
UsbKey.Down = (BOOLEAN) ((CurModifierMap & Mask) != 0);
|
|
|
|
Enqueue (&UsbKeyboardDevice->UsbKeyQueue, &UsbKey, sizeof (UsbKey));
|
2007-07-12 19:31:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2008-12-05 10:19:10 +01:00
|
|
|
// Handle normal key's releasing situation
|
2008-12-15 08:17:47 +01:00
|
|
|
// Bytes 2 to 7 are for normal keycodes
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
|
|
|
KeyRelease = FALSE;
|
|
|
|
for (Index = 2; Index < 8; Index++) {
|
|
|
|
|
|
|
|
if (!USBKBD_VALID_KEYCODE (OldKeyCodeBuffer[Index])) {
|
|
|
|
continue;
|
|
|
|
}
|
2008-12-05 10:19:10 +01:00
|
|
|
//
|
|
|
|
// For any key in old keycode buffer, if it is not in current keycode buffer,
|
|
|
|
// then it is released. Otherwise, it is not released.
|
|
|
|
//
|
2007-07-12 19:31:28 +02:00
|
|
|
KeyRelease = TRUE;
|
|
|
|
for (Index2 = 2; Index2 < 8; Index2++) {
|
|
|
|
|
|
|
|
if (!USBKBD_VALID_KEYCODE (CurKeyCodeBuffer[Index2])) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (OldKeyCodeBuffer[Index] == CurKeyCodeBuffer[Index2]) {
|
|
|
|
KeyRelease = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (KeyRelease) {
|
2011-04-19 08:52:20 +02:00
|
|
|
UsbKey.KeyCode = OldKeyCodeBuffer[Index];
|
|
|
|
UsbKey.Down = FALSE;
|
|
|
|
Enqueue (&UsbKeyboardDevice->UsbKeyQueue, &UsbKey, sizeof (UsbKey));
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
2008-12-05 10:19:10 +01:00
|
|
|
// The original repeat key is released.
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
|
|
|
if (OldKeyCodeBuffer[Index] == UsbKeyboardDevice->RepeatKey) {
|
|
|
|
UsbKeyboardDevice->RepeatKey = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2008-12-05 10:19:10 +01:00
|
|
|
// If original repeat key is released, cancel the repeat timer
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
|
|
|
if (UsbKeyboardDevice->RepeatKey == 0) {
|
|
|
|
gBS->SetTimer (
|
2008-12-05 10:19:10 +01:00
|
|
|
UsbKeyboardDevice->RepeatTimer,
|
|
|
|
TimerCancel,
|
|
|
|
USBKBD_REPEAT_RATE
|
|
|
|
);
|
2007-07-12 19:31:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2008-12-05 10:19:10 +01:00
|
|
|
// Handle normal key's pressing situation
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
|
|
|
KeyPress = FALSE;
|
|
|
|
for (Index = 2; Index < 8; Index++) {
|
|
|
|
|
|
|
|
if (!USBKBD_VALID_KEYCODE (CurKeyCodeBuffer[Index])) {
|
|
|
|
continue;
|
|
|
|
}
|
2008-12-05 10:19:10 +01:00
|
|
|
//
|
|
|
|
// For any key in current keycode buffer, if it is not in old keycode buffer,
|
|
|
|
// then it is pressed. Otherwise, it is not pressed.
|
|
|
|
//
|
2007-07-12 19:31:28 +02:00
|
|
|
KeyPress = TRUE;
|
|
|
|
for (Index2 = 2; Index2 < 8; Index2++) {
|
|
|
|
|
|
|
|
if (!USBKBD_VALID_KEYCODE (OldKeyCodeBuffer[Index2])) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CurKeyCodeBuffer[Index] == OldKeyCodeBuffer[Index2]) {
|
|
|
|
KeyPress = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (KeyPress) {
|
2011-04-19 08:52:20 +02:00
|
|
|
UsbKey.KeyCode = CurKeyCodeBuffer[Index];
|
|
|
|
UsbKey.Down = TRUE;
|
|
|
|
Enqueue (&UsbKeyboardDevice->UsbKeyQueue, &UsbKey, sizeof (UsbKey));
|
2008-12-05 10:19:10 +01:00
|
|
|
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
2008-12-05 10:19:10 +01:00
|
|
|
// Handle repeat key
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
2008-06-23 11:41:33 +02:00
|
|
|
KeyDescriptor = GetKeyDescriptor (UsbKeyboardDevice, CurKeyCodeBuffer[Index]);
|
2016-04-01 10:37:53 +02:00
|
|
|
if (KeyDescriptor == NULL) {
|
|
|
|
continue;
|
|
|
|
}
|
2009-01-13 09:29:55 +01:00
|
|
|
|
2008-06-23 11:41:33 +02:00
|
|
|
if (KeyDescriptor->Modifier == EFI_NUM_LOCK_MODIFIER || KeyDescriptor->Modifier == EFI_CAPS_LOCK_MODIFIER) {
|
2008-12-05 10:19:10 +01:00
|
|
|
//
|
|
|
|
// For NumLock or CapsLock pressed, there is no need to handle repeat key for them.
|
|
|
|
//
|
2007-07-12 19:31:28 +02:00
|
|
|
UsbKeyboardDevice->RepeatKey = 0;
|
|
|
|
} else {
|
|
|
|
//
|
2008-12-05 10:19:10 +01:00
|
|
|
// Prepare new repeat key, and clear the original one.
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
2008-12-05 10:19:10 +01:00
|
|
|
NewRepeatKey = CurKeyCodeBuffer[Index];
|
2007-07-12 19:31:28 +02:00
|
|
|
UsbKeyboardDevice->RepeatKey = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2008-12-15 08:17:47 +01:00
|
|
|
// Update LastKeycodeArray buffer in the UsbKeyboardDevice data structure.
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
|
|
|
for (Index = 0; Index < 8; Index++) {
|
|
|
|
UsbKeyboardDevice->LastKeyCodeArray[Index] = CurKeyCodeBuffer[Index];
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2008-12-15 08:17:47 +01:00
|
|
|
// If there is new key pressed, update the RepeatKey value, and set the
|
2007-07-12 19:31:28 +02:00
|
|
|
// timer to repeate delay timer
|
|
|
|
//
|
|
|
|
if (NewRepeatKey != 0) {
|
|
|
|
//
|
2008-12-05 10:19:10 +01:00
|
|
|
// Sets trigger time to "Repeat Delay Time",
|
2007-07-12 19:31:28 +02:00
|
|
|
// to trigger the repeat timer when the key is hold long
|
|
|
|
// enough time.
|
|
|
|
//
|
|
|
|
gBS->SetTimer (
|
2008-12-15 08:17:47 +01:00
|
|
|
UsbKeyboardDevice->RepeatTimer,
|
|
|
|
TimerRelative,
|
|
|
|
USBKBD_REPEAT_DELAY
|
|
|
|
);
|
2007-07-12 19:31:28 +02:00
|
|
|
UsbKeyboardDevice->RepeatKey = NewRepeatKey;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-12-15 08:17:47 +01:00
|
|
|
Retrieves a USB keycode after parsing the raw data in keyboard buffer.
|
|
|
|
|
|
|
|
This function parses keyboard buffer. It updates state of modifier key for
|
|
|
|
USB_KB_DEV instancem, and returns keycode for output.
|
2007-07-12 19:31:28 +02:00
|
|
|
|
2008-07-23 08:29:46 +02:00
|
|
|
@param UsbKeyboardDevice The USB_KB_DEV instance.
|
2008-12-15 08:17:47 +01:00
|
|
|
@param KeyCode Pointer to the USB keycode for output.
|
2007-07-12 19:31:28 +02:00
|
|
|
|
2008-12-15 08:17:47 +01:00
|
|
|
@retval EFI_SUCCESS Keycode successfully parsed.
|
|
|
|
@retval EFI_NOT_READY Keyboard buffer is not ready for a valid keycode
|
2007-07-12 19:31:28 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
USBParseKey (
|
|
|
|
IN OUT USB_KB_DEV *UsbKeyboardDevice,
|
2008-12-15 08:17:47 +01:00
|
|
|
OUT UINT8 *KeyCode
|
2007-07-12 19:31:28 +02:00
|
|
|
)
|
|
|
|
{
|
2008-06-23 11:41:33 +02:00
|
|
|
USB_KEY UsbKey;
|
|
|
|
EFI_KEY_DESCRIPTOR *KeyDescriptor;
|
2007-07-12 19:31:28 +02:00
|
|
|
|
2008-12-15 08:17:47 +01:00
|
|
|
*KeyCode = 0;
|
2007-07-12 19:31:28 +02:00
|
|
|
|
2011-04-19 08:52:20 +02:00
|
|
|
while (!IsQueueEmpty (&UsbKeyboardDevice->UsbKeyQueue)) {
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
2008-12-05 10:19:10 +01:00
|
|
|
// Pops one raw data off.
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
2011-04-19 08:52:20 +02:00
|
|
|
Dequeue (&UsbKeyboardDevice->UsbKeyQueue, &UsbKey, sizeof (UsbKey));
|
2007-07-12 19:31:28 +02:00
|
|
|
|
2008-06-23 11:41:33 +02:00
|
|
|
KeyDescriptor = GetKeyDescriptor (UsbKeyboardDevice, UsbKey.KeyCode);
|
2016-04-01 10:37:53 +02:00
|
|
|
if (KeyDescriptor == NULL) {
|
|
|
|
continue;
|
|
|
|
}
|
2008-12-15 08:17:47 +01:00
|
|
|
if (!UsbKey.Down) {
|
2008-12-05 10:19:10 +01:00
|
|
|
//
|
|
|
|
// Key is released.
|
|
|
|
//
|
2008-06-23 11:41:33 +02:00
|
|
|
switch (KeyDescriptor->Modifier) {
|
2007-07-12 19:31:28 +02:00
|
|
|
|
2007-10-19 04:35:29 +02:00
|
|
|
//
|
2008-12-15 08:17:47 +01:00
|
|
|
// Ctrl release
|
2007-10-19 04:35:29 +02:00
|
|
|
//
|
2008-06-23 11:41:33 +02:00
|
|
|
case EFI_LEFT_CONTROL_MODIFIER:
|
2008-12-15 08:17:47 +01:00
|
|
|
UsbKeyboardDevice->LeftCtrlOn = FALSE;
|
|
|
|
UsbKeyboardDevice->CtrlOn = FALSE;
|
2007-10-19 04:35:29 +02:00
|
|
|
break;
|
2008-06-23 11:41:33 +02:00
|
|
|
case EFI_RIGHT_CONTROL_MODIFIER:
|
2008-12-15 08:17:47 +01:00
|
|
|
UsbKeyboardDevice->RightCtrlOn = FALSE;
|
|
|
|
UsbKeyboardDevice->CtrlOn = FALSE;
|
2007-07-12 19:31:28 +02:00
|
|
|
break;
|
|
|
|
|
2007-10-19 04:35:29 +02:00
|
|
|
//
|
|
|
|
// Shift release
|
|
|
|
//
|
2008-06-23 11:41:33 +02:00
|
|
|
case EFI_LEFT_SHIFT_MODIFIER:
|
2008-12-15 08:17:47 +01:00
|
|
|
UsbKeyboardDevice->LeftShiftOn = FALSE;
|
|
|
|
UsbKeyboardDevice->ShiftOn = FALSE;
|
2007-10-19 04:35:29 +02:00
|
|
|
break;
|
2008-06-23 11:41:33 +02:00
|
|
|
case EFI_RIGHT_SHIFT_MODIFIER:
|
2008-12-15 08:17:47 +01:00
|
|
|
UsbKeyboardDevice->RightShiftOn = FALSE;
|
|
|
|
UsbKeyboardDevice->ShiftOn = FALSE;
|
2007-07-12 19:31:28 +02:00
|
|
|
break;
|
|
|
|
|
2007-10-19 04:35:29 +02:00
|
|
|
//
|
|
|
|
// Alt release
|
|
|
|
//
|
2008-06-23 11:41:33 +02:00
|
|
|
case EFI_LEFT_ALT_MODIFIER:
|
2008-12-15 08:17:47 +01:00
|
|
|
UsbKeyboardDevice->LeftAltOn = FALSE;
|
|
|
|
UsbKeyboardDevice->AltOn = FALSE;
|
2007-10-19 04:35:29 +02:00
|
|
|
break;
|
2008-06-23 11:41:33 +02:00
|
|
|
case EFI_RIGHT_ALT_MODIFIER:
|
2008-12-15 08:17:47 +01:00
|
|
|
UsbKeyboardDevice->RightAltOn = FALSE;
|
|
|
|
UsbKeyboardDevice->AltOn = FALSE;
|
2007-07-12 19:31:28 +02:00
|
|
|
break;
|
|
|
|
|
2007-10-19 04:35:29 +02:00
|
|
|
//
|
2008-06-23 11:41:33 +02:00
|
|
|
// Left Logo release
|
2007-10-19 04:35:29 +02:00
|
|
|
//
|
2008-06-23 11:41:33 +02:00
|
|
|
case EFI_LEFT_LOGO_MODIFIER:
|
2008-12-15 08:17:47 +01:00
|
|
|
UsbKeyboardDevice->LeftLogoOn = FALSE;
|
2007-10-19 04:35:29 +02:00
|
|
|
break;
|
2008-06-23 11:41:33 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Right Logo release
|
|
|
|
//
|
|
|
|
case EFI_RIGHT_LOGO_MODIFIER:
|
2008-12-15 08:17:47 +01:00
|
|
|
UsbKeyboardDevice->RightLogoOn = FALSE;
|
2007-10-19 04:35:29 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
//
|
2008-06-23 11:41:33 +02:00
|
|
|
// Menu key release
|
2007-10-19 04:35:29 +02:00
|
|
|
//
|
2008-06-23 11:41:33 +02:00
|
|
|
case EFI_MENU_MODIFIER:
|
2008-12-15 08:17:47 +01:00
|
|
|
UsbKeyboardDevice->MenuKeyOn = FALSE;
|
2007-10-19 04:35:29 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
//
|
|
|
|
// SysReq release
|
|
|
|
//
|
2008-06-25 11:05:56 +02:00
|
|
|
case EFI_PRINT_MODIFIER:
|
2008-06-23 11:41:33 +02:00
|
|
|
case EFI_SYS_REQUEST_MODIFIER:
|
2008-12-15 08:17:47 +01:00
|
|
|
UsbKeyboardDevice->SysReqOn = FALSE;
|
2007-10-19 04:35:29 +02:00
|
|
|
break;
|
2008-06-23 11:41:33 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// AltGr release
|
|
|
|
//
|
|
|
|
case EFI_ALT_GR_MODIFIER:
|
2008-12-15 08:17:47 +01:00
|
|
|
UsbKeyboardDevice->AltGrOn = FALSE;
|
2008-06-23 11:41:33 +02:00
|
|
|
break;
|
|
|
|
|
2007-07-12 19:31:28 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Analyzes key pressing situation
|
|
|
|
//
|
2008-06-23 11:41:33 +02:00
|
|
|
switch (KeyDescriptor->Modifier) {
|
2007-07-12 19:31:28 +02:00
|
|
|
|
2008-06-23 11:41:33 +02:00
|
|
|
//
|
2008-12-15 08:17:47 +01:00
|
|
|
// Ctrl press
|
2008-06-23 11:41:33 +02:00
|
|
|
//
|
|
|
|
case EFI_LEFT_CONTROL_MODIFIER:
|
2008-12-15 08:17:47 +01:00
|
|
|
UsbKeyboardDevice->LeftCtrlOn = TRUE;
|
|
|
|
UsbKeyboardDevice->CtrlOn = TRUE;
|
2007-10-19 04:35:29 +02:00
|
|
|
break;
|
2008-06-23 11:41:33 +02:00
|
|
|
case EFI_RIGHT_CONTROL_MODIFIER:
|
2008-12-15 08:17:47 +01:00
|
|
|
UsbKeyboardDevice->RightCtrlOn = TRUE;
|
|
|
|
UsbKeyboardDevice->CtrlOn = TRUE;
|
2007-07-12 19:31:28 +02:00
|
|
|
break;
|
|
|
|
|
2007-10-19 04:35:29 +02:00
|
|
|
//
|
|
|
|
// Shift press
|
|
|
|
//
|
2008-06-23 11:41:33 +02:00
|
|
|
case EFI_LEFT_SHIFT_MODIFIER:
|
2008-12-15 08:17:47 +01:00
|
|
|
UsbKeyboardDevice->LeftShiftOn = TRUE;
|
|
|
|
UsbKeyboardDevice->ShiftOn = TRUE;
|
2007-10-19 04:35:29 +02:00
|
|
|
break;
|
2008-06-23 11:41:33 +02:00
|
|
|
case EFI_RIGHT_SHIFT_MODIFIER:
|
2008-12-15 08:17:47 +01:00
|
|
|
UsbKeyboardDevice->RightShiftOn = TRUE;
|
|
|
|
UsbKeyboardDevice->ShiftOn = TRUE;
|
2007-07-12 19:31:28 +02:00
|
|
|
break;
|
|
|
|
|
2007-10-19 04:35:29 +02:00
|
|
|
//
|
|
|
|
// Alt press
|
|
|
|
//
|
2008-06-23 11:41:33 +02:00
|
|
|
case EFI_LEFT_ALT_MODIFIER:
|
2008-12-15 08:17:47 +01:00
|
|
|
UsbKeyboardDevice->LeftAltOn = TRUE;
|
|
|
|
UsbKeyboardDevice->AltOn = TRUE;
|
2007-10-19 04:35:29 +02:00
|
|
|
break;
|
2008-06-23 11:41:33 +02:00
|
|
|
case EFI_RIGHT_ALT_MODIFIER:
|
2008-12-15 08:17:47 +01:00
|
|
|
UsbKeyboardDevice->RightAltOn = TRUE;
|
|
|
|
UsbKeyboardDevice->AltOn = TRUE;
|
2007-07-12 19:31:28 +02:00
|
|
|
break;
|
|
|
|
|
2007-10-19 04:35:29 +02:00
|
|
|
//
|
2008-06-23 11:41:33 +02:00
|
|
|
// Left Logo press
|
2007-10-19 04:35:29 +02:00
|
|
|
//
|
2008-06-23 11:41:33 +02:00
|
|
|
case EFI_LEFT_LOGO_MODIFIER:
|
2008-12-15 08:17:47 +01:00
|
|
|
UsbKeyboardDevice->LeftLogoOn = TRUE;
|
2007-10-19 04:35:29 +02:00
|
|
|
break;
|
2008-06-23 11:41:33 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Right Logo press
|
|
|
|
//
|
|
|
|
case EFI_RIGHT_LOGO_MODIFIER:
|
2008-12-15 08:17:47 +01:00
|
|
|
UsbKeyboardDevice->RightLogoOn = TRUE;
|
2007-07-12 19:31:28 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
//
|
2008-06-23 11:41:33 +02:00
|
|
|
// Menu key press
|
2007-10-19 04:35:29 +02:00
|
|
|
//
|
2008-06-23 11:41:33 +02:00
|
|
|
case EFI_MENU_MODIFIER:
|
2008-12-15 08:17:47 +01:00
|
|
|
UsbKeyboardDevice->MenuKeyOn = TRUE;
|
2007-10-19 04:35:29 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
//
|
|
|
|
// SysReq press
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
2008-06-25 11:05:56 +02:00
|
|
|
case EFI_PRINT_MODIFIER:
|
2008-06-23 11:41:33 +02:00
|
|
|
case EFI_SYS_REQUEST_MODIFIER:
|
2008-12-15 08:17:47 +01:00
|
|
|
UsbKeyboardDevice->SysReqOn = TRUE;
|
2007-10-19 04:35:29 +02:00
|
|
|
break;
|
|
|
|
|
2008-06-23 11:41:33 +02:00
|
|
|
//
|
|
|
|
// AltGr press
|
|
|
|
//
|
|
|
|
case EFI_ALT_GR_MODIFIER:
|
2008-12-15 08:17:47 +01:00
|
|
|
UsbKeyboardDevice->AltGrOn = TRUE;
|
2008-06-23 11:41:33 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EFI_NUM_LOCK_MODIFIER:
|
2007-10-19 04:35:29 +02:00
|
|
|
//
|
2008-12-15 08:17:47 +01:00
|
|
|
// Toggle NumLock
|
2007-10-19 04:35:29 +02:00
|
|
|
//
|
2008-12-15 08:17:47 +01:00
|
|
|
UsbKeyboardDevice->NumLockOn = (BOOLEAN) (!(UsbKeyboardDevice->NumLockOn));
|
2007-07-12 19:31:28 +02:00
|
|
|
SetKeyLED (UsbKeyboardDevice);
|
|
|
|
break;
|
|
|
|
|
2008-06-23 11:41:33 +02:00
|
|
|
case EFI_CAPS_LOCK_MODIFIER:
|
2007-10-19 04:35:29 +02:00
|
|
|
//
|
2008-12-15 08:17:47 +01:00
|
|
|
// Toggle CapsLock
|
2007-10-19 04:35:29 +02:00
|
|
|
//
|
2008-12-15 08:17:47 +01:00
|
|
|
UsbKeyboardDevice->CapsOn = (BOOLEAN) (!(UsbKeyboardDevice->CapsOn));
|
2007-07-12 19:31:28 +02:00
|
|
|
SetKeyLED (UsbKeyboardDevice);
|
|
|
|
break;
|
|
|
|
|
2008-06-23 11:41:33 +02:00
|
|
|
case EFI_SCROLL_LOCK_MODIFIER:
|
2007-10-19 04:35:29 +02:00
|
|
|
//
|
2008-12-15 08:17:47 +01:00
|
|
|
// Toggle ScrollLock
|
2007-10-19 04:35:29 +02:00
|
|
|
//
|
2008-12-15 08:17:47 +01:00
|
|
|
UsbKeyboardDevice->ScrollOn = (BOOLEAN) (!(UsbKeyboardDevice->ScrollOn));
|
2007-07-12 19:31:28 +02:00
|
|
|
SetKeyLED (UsbKeyboardDevice);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2008-12-05 10:19:10 +01:00
|
|
|
// When encountering Ctrl + Alt + Del, then warm reset.
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
2008-06-23 11:41:33 +02:00
|
|
|
if (KeyDescriptor->Modifier == EFI_DELETE_MODIFIER) {
|
2008-12-15 08:17:47 +01:00
|
|
|
if ((UsbKeyboardDevice->CtrlOn) && (UsbKeyboardDevice->AltOn)) {
|
2007-07-12 19:31:28 +02:00
|
|
|
gRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-15 08:17:47 +01:00
|
|
|
*KeyCode = UsbKey.KeyCode;
|
2007-07-12 19:31:28 +02:00
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EFI_NOT_READY;
|
|
|
|
}
|
|
|
|
|
2018-01-12 12:29:32 +01:00
|
|
|
/**
|
|
|
|
Initialize the key state.
|
|
|
|
|
|
|
|
@param UsbKeyboardDevice The USB_KB_DEV instance.
|
|
|
|
@param KeyState A pointer to receive the key state information.
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
InitializeKeyState (
|
|
|
|
IN USB_KB_DEV *UsbKeyboardDevice,
|
|
|
|
OUT EFI_KEY_STATE *KeyState
|
|
|
|
)
|
|
|
|
{
|
|
|
|
KeyState->KeyShiftState = EFI_SHIFT_STATE_VALID;
|
|
|
|
KeyState->KeyToggleState = EFI_TOGGLE_STATE_VALID;
|
|
|
|
|
|
|
|
if (UsbKeyboardDevice->LeftCtrlOn) {
|
|
|
|
KeyState->KeyShiftState |= EFI_LEFT_CONTROL_PRESSED;
|
|
|
|
}
|
|
|
|
if (UsbKeyboardDevice->RightCtrlOn) {
|
|
|
|
KeyState->KeyShiftState |= EFI_RIGHT_CONTROL_PRESSED;
|
|
|
|
}
|
|
|
|
if (UsbKeyboardDevice->LeftAltOn) {
|
|
|
|
KeyState->KeyShiftState |= EFI_LEFT_ALT_PRESSED;
|
|
|
|
}
|
|
|
|
if (UsbKeyboardDevice->RightAltOn) {
|
|
|
|
KeyState->KeyShiftState |= EFI_RIGHT_ALT_PRESSED;
|
|
|
|
}
|
|
|
|
if (UsbKeyboardDevice->LeftShiftOn) {
|
|
|
|
KeyState->KeyShiftState |= EFI_LEFT_SHIFT_PRESSED;
|
|
|
|
}
|
|
|
|
if (UsbKeyboardDevice->RightShiftOn) {
|
|
|
|
KeyState->KeyShiftState |= EFI_RIGHT_SHIFT_PRESSED;
|
|
|
|
}
|
|
|
|
if (UsbKeyboardDevice->LeftLogoOn) {
|
|
|
|
KeyState->KeyShiftState |= EFI_LEFT_LOGO_PRESSED;
|
|
|
|
}
|
|
|
|
if (UsbKeyboardDevice->RightLogoOn) {
|
|
|
|
KeyState->KeyShiftState |= EFI_RIGHT_LOGO_PRESSED;
|
|
|
|
}
|
|
|
|
if (UsbKeyboardDevice->MenuKeyOn) {
|
|
|
|
KeyState->KeyShiftState |= EFI_MENU_KEY_PRESSED;
|
|
|
|
}
|
|
|
|
if (UsbKeyboardDevice->SysReqOn) {
|
|
|
|
KeyState->KeyShiftState |= EFI_SYS_REQ_PRESSED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (UsbKeyboardDevice->ScrollOn) {
|
|
|
|
KeyState->KeyToggleState |= EFI_SCROLL_LOCK_ACTIVE;
|
|
|
|
}
|
|
|
|
if (UsbKeyboardDevice->NumLockOn) {
|
|
|
|
KeyState->KeyToggleState |= EFI_NUM_LOCK_ACTIVE;
|
|
|
|
}
|
|
|
|
if (UsbKeyboardDevice->CapsOn) {
|
|
|
|
KeyState->KeyToggleState |= EFI_CAPS_LOCK_ACTIVE;
|
|
|
|
}
|
|
|
|
if (UsbKeyboardDevice->IsSupportPartialKey) {
|
|
|
|
KeyState->KeyToggleState |= EFI_KEY_STATE_EXPOSED;
|
|
|
|
}
|
|
|
|
}
|
2007-07-12 19:31:28 +02:00
|
|
|
|
|
|
|
/**
|
2008-12-15 08:17:47 +01:00
|
|
|
Converts USB Keycode ranging from 0x4 to 0x65 to EFI_INPUT_KEY.
|
2007-07-12 19:31:28 +02:00
|
|
|
|
2008-12-15 08:17:47 +01:00
|
|
|
@param UsbKeyboardDevice The USB_KB_DEV instance.
|
|
|
|
@param KeyCode Indicates the key code that will be interpreted.
|
2011-04-19 08:52:20 +02:00
|
|
|
@param KeyData A pointer to a buffer that is filled in with
|
2008-12-15 08:17:47 +01:00
|
|
|
the keystroke information for the key that
|
|
|
|
was pressed.
|
2007-07-12 19:31:28 +02:00
|
|
|
|
2008-12-15 08:17:47 +01:00
|
|
|
@retval EFI_SUCCESS Success.
|
|
|
|
@retval EFI_INVALID_PARAMETER KeyCode is not in the range of 0x4 to 0x65.
|
|
|
|
@retval EFI_INVALID_PARAMETER Translated EFI_INPUT_KEY has zero for both ScanCode and UnicodeChar.
|
|
|
|
@retval EFI_NOT_READY KeyCode represents a dead key with EFI_NS_KEY_MODIFIER
|
2009-01-13 09:29:55 +01:00
|
|
|
@retval EFI_DEVICE_ERROR Keyboard layout is invalid.
|
2007-07-12 19:31:28 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
2008-12-05 10:19:10 +01:00
|
|
|
UsbKeyCodeToEfiInputKey (
|
2011-04-19 08:52:20 +02:00
|
|
|
IN USB_KB_DEV *UsbKeyboardDevice,
|
|
|
|
IN UINT8 KeyCode,
|
|
|
|
OUT EFI_KEY_DATA *KeyData
|
2007-07-12 19:31:28 +02:00
|
|
|
)
|
|
|
|
{
|
2011-04-19 08:52:20 +02:00
|
|
|
EFI_KEY_DESCRIPTOR *KeyDescriptor;
|
|
|
|
LIST_ENTRY *Link;
|
|
|
|
LIST_ENTRY *NotifyList;
|
2011-09-30 09:28:16 +02:00
|
|
|
KEYBOARD_CONSOLE_IN_EX_NOTIFY *CurrentNotify;
|
2007-07-12 19:31:28 +02:00
|
|
|
|
|
|
|
//
|
2011-09-30 09:28:16 +02:00
|
|
|
// KeyCode must in the range of [0x4, 0x65] or [0xe0, 0xe7].
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
2008-12-15 08:17:47 +01:00
|
|
|
KeyDescriptor = GetKeyDescriptor (UsbKeyboardDevice, KeyCode);
|
2016-04-01 10:37:53 +02:00
|
|
|
if (KeyDescriptor == NULL) {
|
|
|
|
return EFI_DEVICE_ERROR;
|
|
|
|
}
|
2008-06-23 11:41:33 +02:00
|
|
|
|
|
|
|
if (KeyDescriptor->Modifier == EFI_NS_KEY_MODIFIER) {
|
2008-12-05 10:19:10 +01:00
|
|
|
//
|
|
|
|
// If this is a dead key with EFI_NS_KEY_MODIFIER, then record it and return.
|
|
|
|
//
|
2008-06-23 11:41:33 +02:00
|
|
|
UsbKeyboardDevice->CurrentNsKey = FindUsbNsKey (UsbKeyboardDevice, KeyDescriptor);
|
|
|
|
return EFI_NOT_READY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (UsbKeyboardDevice->CurrentNsKey != NULL) {
|
2008-12-05 10:19:10 +01:00
|
|
|
//
|
|
|
|
// If this keystroke follows a non-spacing key, then find the descriptor for corresponding
|
|
|
|
// physical key.
|
|
|
|
//
|
2008-06-23 11:41:33 +02:00
|
|
|
KeyDescriptor = FindPhysicalKey (UsbKeyboardDevice->CurrentNsKey, KeyDescriptor);
|
|
|
|
UsbKeyboardDevice->CurrentNsKey = NULL;
|
2007-10-19 04:35:29 +02:00
|
|
|
}
|
|
|
|
|
2009-01-13 09:29:55 +01:00
|
|
|
//
|
|
|
|
// Make sure modifier of Key Descriptor is in the valid range according to UEFI spec.
|
|
|
|
//
|
2011-06-02 08:51:59 +02:00
|
|
|
if (KeyDescriptor->Modifier >= (sizeof (ModifierValueToEfiScanCodeConvertionTable) / sizeof (UINT8))) {
|
2009-01-13 09:29:55 +01:00
|
|
|
return EFI_DEVICE_ERROR;
|
|
|
|
}
|
|
|
|
|
2011-04-19 08:52:20 +02:00
|
|
|
KeyData->Key.ScanCode = ModifierValueToEfiScanCodeConvertionTable[KeyDescriptor->Modifier];
|
|
|
|
KeyData->Key.UnicodeChar = KeyDescriptor->Unicode;
|
2007-07-12 19:31:28 +02:00
|
|
|
|
2008-12-05 10:19:10 +01:00
|
|
|
if ((KeyDescriptor->AffectedAttribute & EFI_AFFECTED_BY_STANDARD_SHIFT)!= 0) {
|
2008-12-15 08:17:47 +01:00
|
|
|
if (UsbKeyboardDevice->ShiftOn) {
|
2011-04-19 08:52:20 +02:00
|
|
|
KeyData->Key.UnicodeChar = KeyDescriptor->ShiftedUnicode;
|
2007-07-12 19:31:28 +02:00
|
|
|
|
2008-06-23 11:41:33 +02:00
|
|
|
//
|
|
|
|
// Need not return associated shift state if a class of printable characters that
|
|
|
|
// are normally adjusted by shift modifiers. e.g. Shift Key + 'f' key = 'F'
|
|
|
|
//
|
2018-03-23 05:45:14 +01:00
|
|
|
if ((KeyDescriptor->Unicode != CHAR_NULL) && (KeyDescriptor->ShiftedUnicode != CHAR_NULL) &&
|
|
|
|
(KeyDescriptor->Unicode != KeyDescriptor->ShiftedUnicode)) {
|
2008-12-15 08:17:47 +01:00
|
|
|
UsbKeyboardDevice->LeftShiftOn = FALSE;
|
|
|
|
UsbKeyboardDevice->RightShiftOn = FALSE;
|
2008-06-23 11:41:33 +02:00
|
|
|
}
|
2007-07-12 19:31:28 +02:00
|
|
|
|
2008-12-15 08:17:47 +01:00
|
|
|
if (UsbKeyboardDevice->AltGrOn) {
|
2011-04-19 08:52:20 +02:00
|
|
|
KeyData->Key.UnicodeChar = KeyDescriptor->ShiftedAltGrUnicode;
|
2008-06-23 11:41:33 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// Shift off
|
|
|
|
//
|
2011-04-19 08:52:20 +02:00
|
|
|
KeyData->Key.UnicodeChar = KeyDescriptor->Unicode;
|
2007-07-12 19:31:28 +02:00
|
|
|
|
2008-12-15 08:17:47 +01:00
|
|
|
if (UsbKeyboardDevice->AltGrOn) {
|
2011-04-19 08:52:20 +02:00
|
|
|
KeyData->Key.UnicodeChar = KeyDescriptor->AltGrUnicode;
|
2008-06-23 11:41:33 +02:00
|
|
|
}
|
|
|
|
}
|
2007-07-12 19:31:28 +02:00
|
|
|
}
|
|
|
|
|
2008-12-05 10:19:10 +01:00
|
|
|
if ((KeyDescriptor->AffectedAttribute & EFI_AFFECTED_BY_CAPS_LOCK) != 0) {
|
2008-12-15 08:17:47 +01:00
|
|
|
if (UsbKeyboardDevice->CapsOn) {
|
2011-04-19 08:52:20 +02:00
|
|
|
if (KeyData->Key.UnicodeChar == KeyDescriptor->Unicode) {
|
|
|
|
KeyData->Key.UnicodeChar = KeyDescriptor->ShiftedUnicode;
|
|
|
|
} else if (KeyData->Key.UnicodeChar == KeyDescriptor->ShiftedUnicode) {
|
|
|
|
KeyData->Key.UnicodeChar = KeyDescriptor->Unicode;
|
2008-06-23 11:41:33 +02:00
|
|
|
}
|
2007-07-12 19:31:28 +02:00
|
|
|
}
|
|
|
|
}
|
2008-06-23 11:41:33 +02:00
|
|
|
|
2009-02-06 06:34:53 +01:00
|
|
|
if ((KeyDescriptor->AffectedAttribute & EFI_AFFECTED_BY_NUM_LOCK) != 0) {
|
2008-12-05 10:19:10 +01:00
|
|
|
//
|
|
|
|
// For key affected by NumLock, if NumLock is on and Shift is not pressed, then it means
|
|
|
|
// normal key, instead of original control key. So the ScanCode should be cleaned.
|
|
|
|
// Otherwise, it means control key, so preserve the EFI Scan Code and clear the unicode keycode.
|
|
|
|
//
|
2008-12-15 08:17:47 +01:00
|
|
|
if ((UsbKeyboardDevice->NumLockOn) && (!(UsbKeyboardDevice->ShiftOn))) {
|
2011-04-19 08:52:20 +02:00
|
|
|
KeyData->Key.ScanCode = SCAN_NULL;
|
2007-07-12 19:31:28 +02:00
|
|
|
} else {
|
2011-09-30 09:28:16 +02:00
|
|
|
KeyData->Key.UnicodeChar = CHAR_NULL;
|
2007-07-12 19:31:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-23 11:41:33 +02:00
|
|
|
//
|
|
|
|
// Translate Unicode 0x1B (ESC) to EFI Scan Code
|
|
|
|
//
|
2011-04-19 08:52:20 +02:00
|
|
|
if (KeyData->Key.UnicodeChar == 0x1B && KeyData->Key.ScanCode == SCAN_NULL) {
|
|
|
|
KeyData->Key.ScanCode = SCAN_ESC;
|
2011-09-30 09:28:16 +02:00
|
|
|
KeyData->Key.UnicodeChar = CHAR_NULL;
|
2008-06-23 11:41:33 +02:00
|
|
|
}
|
|
|
|
|
2008-12-05 10:19:10 +01:00
|
|
|
//
|
|
|
|
// Not valid for key without both unicode key code and EFI Scan Code.
|
|
|
|
//
|
2011-04-19 08:52:20 +02:00
|
|
|
if (KeyData->Key.UnicodeChar == 0 && KeyData->Key.ScanCode == SCAN_NULL) {
|
2011-09-30 09:28:16 +02:00
|
|
|
if (!UsbKeyboardDevice->IsSupportPartialKey) {
|
2007-07-12 19:31:28 +02:00
|
|
|
return EFI_NOT_READY;
|
2011-09-30 09:28:16 +02:00
|
|
|
}
|
2007-07-12 19:31:28 +02:00
|
|
|
}
|
|
|
|
|
2007-10-19 04:35:29 +02:00
|
|
|
//
|
|
|
|
// Save Shift/Toggle state
|
|
|
|
//
|
2018-01-12 12:29:32 +01:00
|
|
|
InitializeKeyState (UsbKeyboardDevice, &KeyData->KeyState);
|
2011-04-19 08:52:20 +02:00
|
|
|
|
|
|
|
//
|
2016-12-16 10:16:22 +01:00
|
|
|
// Signal KeyNotify process event if this key pressed matches any key registered.
|
2011-04-19 08:52:20 +02:00
|
|
|
//
|
|
|
|
NotifyList = &UsbKeyboardDevice->NotifyList;
|
|
|
|
for (Link = GetFirstNode (NotifyList); !IsNull (NotifyList, Link); Link = GetNextNode (NotifyList, Link)) {
|
|
|
|
CurrentNotify = CR (Link, KEYBOARD_CONSOLE_IN_EX_NOTIFY, NotifyEntry, USB_KB_CONSOLE_IN_EX_NOTIFY_SIGNATURE);
|
2011-09-30 09:28:16 +02:00
|
|
|
if (IsKeyRegistered (&CurrentNotify->KeyData, KeyData)) {
|
2016-12-16 10:16:22 +01:00
|
|
|
//
|
|
|
|
// The key notification function needs to run at TPL_CALLBACK
|
|
|
|
// while current TPL is TPL_NOTIFY. It will be invoked in
|
|
|
|
// KeyNotifyProcessHandler() which runs at TPL_CALLBACK.
|
|
|
|
//
|
|
|
|
Enqueue (&UsbKeyboardDevice->EfiKeyQueueForNotify, KeyData, sizeof (*KeyData));
|
|
|
|
gBS->SignalEvent (UsbKeyboardDevice->KeyNotifyProcessEvent);
|
2018-09-09 16:34:57 +02:00
|
|
|
break;
|
2011-04-19 08:52:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
2007-07-12 19:31:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-04-19 08:52:20 +02:00
|
|
|
Create the queue.
|
2007-07-12 19:31:28 +02:00
|
|
|
|
2011-04-19 08:52:20 +02:00
|
|
|
@param Queue Points to the queue.
|
|
|
|
@param ItemSize Size of the single item.
|
2007-07-12 19:31:28 +02:00
|
|
|
|
|
|
|
**/
|
2008-12-05 10:19:10 +01:00
|
|
|
VOID
|
2011-04-19 08:52:20 +02:00
|
|
|
InitQueue (
|
|
|
|
IN OUT USB_SIMPLE_QUEUE *Queue,
|
|
|
|
IN UINTN ItemSize
|
2007-07-12 19:31:28 +02:00
|
|
|
)
|
|
|
|
{
|
2011-04-19 08:52:20 +02:00
|
|
|
UINTN Index;
|
2007-07-12 19:31:28 +02:00
|
|
|
|
2011-04-19 08:52:20 +02:00
|
|
|
Queue->ItemSize = ItemSize;
|
|
|
|
Queue->Head = 0;
|
|
|
|
Queue->Tail = 0;
|
|
|
|
|
|
|
|
if (Queue->Buffer[0] != NULL) {
|
|
|
|
FreePool (Queue->Buffer[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
Queue->Buffer[0] = AllocatePool (sizeof (Queue->Buffer) / sizeof (Queue->Buffer[0]) * ItemSize);
|
|
|
|
ASSERT (Queue->Buffer[0] != NULL);
|
|
|
|
|
|
|
|
for (Index = 1; Index < sizeof (Queue->Buffer) / sizeof (Queue->Buffer[0]); Index++) {
|
|
|
|
Queue->Buffer[Index] = ((UINT8 *) Queue->Buffer[Index - 1]) + ItemSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Destroy the queue
|
|
|
|
|
|
|
|
@param Queue Points to the queue.
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
DestroyQueue (
|
|
|
|
IN OUT USB_SIMPLE_QUEUE *Queue
|
|
|
|
)
|
|
|
|
{
|
|
|
|
FreePool (Queue->Buffer[0]);
|
2007-07-12 19:31:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2011-04-19 08:52:20 +02:00
|
|
|
Check whether the queue is empty.
|
2007-07-12 19:31:28 +02:00
|
|
|
|
2011-04-19 08:52:20 +02:00
|
|
|
@param Queue Points to the queue.
|
2007-07-12 19:31:28 +02:00
|
|
|
|
2011-04-19 08:52:20 +02:00
|
|
|
@retval TRUE Queue is empty.
|
|
|
|
@retval FALSE Queue is not empty.
|
2007-07-12 19:31:28 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
BOOLEAN
|
2011-04-19 08:52:20 +02:00
|
|
|
IsQueueEmpty (
|
|
|
|
IN USB_SIMPLE_QUEUE *Queue
|
2007-07-12 19:31:28 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
//
|
2008-12-15 08:17:47 +01:00
|
|
|
// Meet FIFO empty condition
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
2011-04-19 08:52:20 +02:00
|
|
|
return (BOOLEAN) (Queue->Head == Queue->Tail);
|
2007-07-12 19:31:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2011-04-19 08:52:20 +02:00
|
|
|
Check whether the queue is full.
|
2007-07-12 19:31:28 +02:00
|
|
|
|
2011-04-19 08:52:20 +02:00
|
|
|
@param Queue Points to the queue.
|
2007-07-12 19:31:28 +02:00
|
|
|
|
2011-04-19 08:52:20 +02:00
|
|
|
@retval TRUE Queue is full.
|
|
|
|
@retval FALSE Queue is not full.
|
2007-07-12 19:31:28 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
BOOLEAN
|
2011-04-19 08:52:20 +02:00
|
|
|
IsQueueFull (
|
|
|
|
IN USB_SIMPLE_QUEUE *Queue
|
2007-07-12 19:31:28 +02:00
|
|
|
)
|
|
|
|
{
|
2011-04-19 08:52:20 +02:00
|
|
|
return (BOOLEAN) (((Queue->Tail + 1) % (MAX_KEY_ALLOWED + 1)) == Queue->Head);
|
2007-07-12 19:31:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2011-04-19 08:52:20 +02:00
|
|
|
Enqueue the item to the queue.
|
2007-07-12 19:31:28 +02:00
|
|
|
|
2011-04-19 08:52:20 +02:00
|
|
|
@param Queue Points to the queue.
|
|
|
|
@param Item Points to the item to be enqueued.
|
|
|
|
@param ItemSize Size of the item.
|
2007-07-12 19:31:28 +02:00
|
|
|
**/
|
2008-12-05 10:19:10 +01:00
|
|
|
VOID
|
2011-04-19 08:52:20 +02:00
|
|
|
Enqueue (
|
|
|
|
IN OUT USB_SIMPLE_QUEUE *Queue,
|
|
|
|
IN VOID *Item,
|
|
|
|
IN UINTN ItemSize
|
2007-07-12 19:31:28 +02:00
|
|
|
)
|
|
|
|
{
|
2011-04-19 08:52:20 +02:00
|
|
|
ASSERT (ItemSize == Queue->ItemSize);
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
2008-12-15 08:17:47 +01:00
|
|
|
// If keyboard buffer is full, throw the
|
2007-07-12 19:31:28 +02:00
|
|
|
// first key out of the keyboard buffer.
|
|
|
|
//
|
2011-04-19 08:52:20 +02:00
|
|
|
if (IsQueueFull (Queue)) {
|
|
|
|
Queue->Head = (Queue->Head + 1) % (MAX_KEY_ALLOWED + 1);
|
2007-07-12 19:31:28 +02:00
|
|
|
}
|
|
|
|
|
2011-04-19 08:52:20 +02:00
|
|
|
CopyMem (Queue->Buffer[Queue->Tail], Item, ItemSize);
|
2007-07-12 19:31:28 +02:00
|
|
|
|
|
|
|
//
|
2008-12-05 10:19:10 +01:00
|
|
|
// Adjust the tail pointer of the FIFO keyboard buffer.
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
2011-04-19 08:52:20 +02:00
|
|
|
Queue->Tail = (Queue->Tail + 1) % (MAX_KEY_ALLOWED + 1);
|
2007-07-12 19:31:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2011-04-19 08:52:20 +02:00
|
|
|
Dequeue a item from the queue.
|
2007-07-12 19:31:28 +02:00
|
|
|
|
2011-04-19 08:52:20 +02:00
|
|
|
@param Queue Points to the queue.
|
|
|
|
@param Item Receives the item.
|
|
|
|
@param ItemSize Size of the item.
|
2007-07-12 19:31:28 +02:00
|
|
|
|
2011-04-19 08:52:20 +02:00
|
|
|
@retval EFI_SUCCESS Item was successfully dequeued.
|
|
|
|
@retval EFI_DEVICE_ERROR The queue is empty.
|
2007-07-12 19:31:28 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
2011-04-19 08:52:20 +02:00
|
|
|
Dequeue (
|
|
|
|
IN OUT USB_SIMPLE_QUEUE *Queue,
|
|
|
|
OUT VOID *Item,
|
|
|
|
IN UINTN ItemSize
|
2007-07-12 19:31:28 +02:00
|
|
|
)
|
|
|
|
{
|
2011-04-19 08:52:20 +02:00
|
|
|
ASSERT (Queue->ItemSize == ItemSize);
|
|
|
|
|
|
|
|
if (IsQueueEmpty (Queue)) {
|
2007-07-12 19:31:28 +02:00
|
|
|
return EFI_DEVICE_ERROR;
|
|
|
|
}
|
|
|
|
|
2011-04-19 08:52:20 +02:00
|
|
|
CopyMem (Item, Queue->Buffer[Queue->Head], ItemSize);
|
2007-07-12 19:31:28 +02:00
|
|
|
|
|
|
|
//
|
2008-12-05 10:19:10 +01:00
|
|
|
// Adjust the head pointer of the FIFO keyboard buffer.
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
2011-04-19 08:52:20 +02:00
|
|
|
Queue->Head = (Queue->Head + 1) % (MAX_KEY_ALLOWED + 1);
|
2007-07-12 19:31:28 +02:00
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-12-15 08:17:47 +01:00
|
|
|
Sets USB keyboard LED state.
|
2007-07-12 19:31:28 +02:00
|
|
|
|
|
|
|
@param UsbKeyboardDevice The USB_KB_DEV instance.
|
|
|
|
|
|
|
|
**/
|
2008-12-05 10:19:10 +01:00
|
|
|
VOID
|
2007-07-12 19:31:28 +02:00
|
|
|
SetKeyLED (
|
|
|
|
IN USB_KB_DEV *UsbKeyboardDevice
|
|
|
|
)
|
|
|
|
{
|
|
|
|
LED_MAP Led;
|
|
|
|
UINT8 ReportId;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Set each field in Led map.
|
|
|
|
//
|
2008-12-15 08:17:47 +01:00
|
|
|
Led.NumLock = (UINT8) ((UsbKeyboardDevice->NumLockOn) ? 1 : 0);
|
|
|
|
Led.CapsLock = (UINT8) ((UsbKeyboardDevice->CapsOn) ? 1 : 0);
|
|
|
|
Led.ScrollLock = (UINT8) ((UsbKeyboardDevice->ScrollOn) ? 1 : 0);
|
2007-07-12 19:31:28 +02:00
|
|
|
Led.Resrvd = 0;
|
|
|
|
|
|
|
|
ReportId = 0;
|
|
|
|
//
|
2008-12-05 10:19:10 +01:00
|
|
|
// Call Set_Report Request to lighten the LED.
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
|
|
|
UsbSetReportRequest (
|
|
|
|
UsbKeyboardDevice->UsbIo,
|
|
|
|
UsbKeyboardDevice->InterfaceDescriptor.InterfaceNumber,
|
|
|
|
ReportId,
|
|
|
|
HID_OUTPUT_REPORT,
|
|
|
|
1,
|
|
|
|
(UINT8 *) &Led
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-12-15 08:17:47 +01:00
|
|
|
Handler for Repeat Key event.
|
|
|
|
|
|
|
|
This function is the handler for Repeat Key event triggered
|
|
|
|
by timer.
|
|
|
|
After a repeatable key is pressed, the event would be triggered
|
|
|
|
with interval of USBKBD_REPEAT_DELAY. Once the event is triggered,
|
|
|
|
following trigger will come with interval of USBKBD_REPEAT_RATE.
|
2007-07-12 19:31:28 +02:00
|
|
|
|
|
|
|
@param Event The Repeat Key event.
|
|
|
|
@param Context Points to the USB_KB_DEV instance.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
EFIAPI
|
|
|
|
USBKeyboardRepeatHandler (
|
|
|
|
IN EFI_EVENT Event,
|
|
|
|
IN VOID *Context
|
|
|
|
)
|
|
|
|
{
|
|
|
|
USB_KB_DEV *UsbKeyboardDevice;
|
2011-04-19 08:52:20 +02:00
|
|
|
USB_KEY UsbKey;
|
2007-07-12 19:31:28 +02:00
|
|
|
|
|
|
|
UsbKeyboardDevice = (USB_KB_DEV *) Context;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Do nothing when there is no repeat key.
|
|
|
|
//
|
|
|
|
if (UsbKeyboardDevice->RepeatKey != 0) {
|
|
|
|
//
|
2008-12-15 08:17:47 +01:00
|
|
|
// Inserts the repeat key into keyboard buffer,
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
2011-04-19 08:52:20 +02:00
|
|
|
UsbKey.KeyCode = UsbKeyboardDevice->RepeatKey;
|
|
|
|
UsbKey.Down = TRUE;
|
|
|
|
Enqueue (&UsbKeyboardDevice->UsbKeyQueue, &UsbKey, sizeof (UsbKey));
|
2007-07-12 19:31:28 +02:00
|
|
|
|
|
|
|
//
|
2008-12-26 10:18:12 +01:00
|
|
|
// Set repeat rate for next repeat key generation.
|
2007-07-12 19:31:28 +02:00
|
|
|
//
|
|
|
|
gBS->SetTimer (
|
2008-12-05 10:19:10 +01:00
|
|
|
UsbKeyboardDevice->RepeatTimer,
|
|
|
|
TimerRelative,
|
|
|
|
USBKBD_REPEAT_RATE
|
|
|
|
);
|
2007-07-12 19:31:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-12-15 08:17:47 +01:00
|
|
|
Handler for Delayed Recovery event.
|
|
|
|
|
|
|
|
This function is the handler for Delayed Recovery event triggered
|
|
|
|
by timer.
|
|
|
|
After a device error occurs, the event would be triggered
|
|
|
|
with interval of EFI_USB_INTERRUPT_DELAY. EFI_USB_INTERRUPT_DELAY
|
|
|
|
is defined in USB standard for error handling.
|
2007-07-12 19:31:28 +02:00
|
|
|
|
|
|
|
@param Event The Delayed Recovery event.
|
|
|
|
@param Context Points to the USB_KB_DEV instance.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
EFIAPI
|
|
|
|
USBKeyboardRecoveryHandler (
|
|
|
|
IN EFI_EVENT Event,
|
|
|
|
IN VOID *Context
|
|
|
|
)
|
|
|
|
{
|
|
|
|
|
|
|
|
USB_KB_DEV *UsbKeyboardDevice;
|
|
|
|
EFI_USB_IO_PROTOCOL *UsbIo;
|
|
|
|
UINT8 PacketSize;
|
|
|
|
|
|
|
|
UsbKeyboardDevice = (USB_KB_DEV *) Context;
|
|
|
|
|
|
|
|
UsbIo = UsbKeyboardDevice->UsbIo;
|
|
|
|
|
|
|
|
PacketSize = (UINT8) (UsbKeyboardDevice->IntEndpointDescriptor.MaxPacketSize);
|
|
|
|
|
2008-12-05 10:19:10 +01:00
|
|
|
//
|
|
|
|
// Re-submit Asynchronous Interrupt Transfer for recovery.
|
|
|
|
//
|
2007-07-12 19:31:28 +02:00
|
|
|
UsbIo->UsbAsyncInterruptTransfer (
|
2008-12-05 10:19:10 +01:00
|
|
|
UsbIo,
|
|
|
|
UsbKeyboardDevice->IntEndpointDescriptor.EndpointAddress,
|
|
|
|
TRUE,
|
|
|
|
UsbKeyboardDevice->IntEndpointDescriptor.Interval,
|
|
|
|
PacketSize,
|
|
|
|
KeyboardHandler,
|
|
|
|
UsbKeyboardDevice
|
|
|
|
);
|
2007-07-12 19:31:28 +02:00
|
|
|
}
|