19 EFI_HII_PACKAGE_KEYBOARD_LAYOUT
23 USB_KEYBOARD_LAYOUT_KEY_GUID,
24 sizeof (UINT16) +
sizeof (
EFI_GUID) +
sizeof (UINT32) +
sizeof (UINT8) + (USB_KEYBOARD_KEY_COUNT *
sizeof (
EFI_KEY_DESCRIPTOR)),
25 USB_KEYBOARD_KEY_COUNT,
66 { EfiKeyEnter, 0x0d, 0x0d, 0, 0, EFI_NULL_MODIFIER, 0 },
67 { EfiKeyEsc, 0x1b, 0x1b, 0, 0, EFI_NULL_MODIFIER, 0 },
68 { EfiKeyBackSpace, 0x08, 0x08, 0, 0, EFI_NULL_MODIFIER, 0 },
69 { EfiKeyTab, 0x09, 0x09, 0, 0, EFI_NULL_MODIFIER, 0 },
70 { EfiKeySpaceBar,
' ',
' ', 0, 0, EFI_NULL_MODIFIER, 0 },
83 { EfiKeyCapsLock, 0x00, 0x00, 0, 0, EFI_CAPS_LOCK_MODIFIER, 0 },
84 { EfiKeyF1, 0x00, 0x00, 0, 0, EFI_FUNCTION_KEY_ONE_MODIFIER, 0 },
85 { EfiKeyF2, 0x00, 0x00, 0, 0, EFI_FUNCTION_KEY_TWO_MODIFIER, 0 },
86 { EfiKeyF3, 0x00, 0x00, 0, 0, EFI_FUNCTION_KEY_THREE_MODIFIER, 0 },
87 { EfiKeyF4, 0x00, 0x00, 0, 0, EFI_FUNCTION_KEY_FOUR_MODIFIER, 0 },
88 { EfiKeyF5, 0x00, 0x00, 0, 0, EFI_FUNCTION_KEY_FIVE_MODIFIER, 0 },
89 { EfiKeyF6, 0x00, 0x00, 0, 0, EFI_FUNCTION_KEY_SIX_MODIFIER, 0 },
90 { EfiKeyF7, 0x00, 0x00, 0, 0, EFI_FUNCTION_KEY_SEVEN_MODIFIER, 0 },
91 { EfiKeyF8, 0x00, 0x00, 0, 0, EFI_FUNCTION_KEY_EIGHT_MODIFIER, 0 },
92 { EfiKeyF9, 0x00, 0x00, 0, 0, EFI_FUNCTION_KEY_NINE_MODIFIER, 0 },
93 { EfiKeyF10, 0x00, 0x00, 0, 0, EFI_FUNCTION_KEY_TEN_MODIFIER, 0 },
94 { EfiKeyF11, 0x00, 0x00, 0, 0, EFI_FUNCTION_KEY_ELEVEN_MODIFIER, 0 },
95 { EfiKeyF12, 0x00, 0x00, 0, 0, EFI_FUNCTION_KEY_TWELVE_MODIFIER, 0 },
96 { EfiKeyPrint, 0x00, 0x00, 0, 0, EFI_PRINT_MODIFIER, 0 },
97 { EfiKeySLck, 0x00, 0x00, 0, 0, EFI_SCROLL_LOCK_MODIFIER, 0 },
98 { EfiKeyPause, 0x00, 0x00, 0, 0, EFI_PAUSE_MODIFIER, 0 },
99 { EfiKeyIns, 0x00, 0x00, 0, 0, EFI_INSERT_MODIFIER, 0 },
100 { EfiKeyHome, 0x00, 0x00, 0, 0, EFI_HOME_MODIFIER, 0 },
101 { EfiKeyPgUp, 0x00, 0x00, 0, 0, EFI_PAGE_UP_MODIFIER, 0 },
102 { EfiKeyDel, 0x00, 0x00, 0, 0, EFI_DELETE_MODIFIER, 0 },
103 { EfiKeyEnd, 0x00, 0x00, 0, 0, EFI_END_MODIFIER, 0 },
104 { EfiKeyPgDn, 0x00, 0x00, 0, 0, EFI_PAGE_DOWN_MODIFIER, 0 },
105 { EfiKeyRightArrow, 0x00, 0x00, 0, 0, EFI_RIGHT_ARROW_MODIFIER, 0 },
106 { EfiKeyLeftArrow, 0x00, 0x00, 0, 0, EFI_LEFT_ARROW_MODIFIER, 0 },
107 { EfiKeyDownArrow, 0x00, 0x00, 0, 0, EFI_DOWN_ARROW_MODIFIER, 0 },
108 { EfiKeyUpArrow, 0x00, 0x00, 0, 0, EFI_UP_ARROW_MODIFIER, 0 },
109 { EfiKeyNLck, 0x00, 0x00, 0, 0, EFI_NUM_LOCK_MODIFIER, 0 },
110 { EfiKeySlash,
'/',
'/', 0, 0, EFI_NULL_MODIFIER, 0 },
111 { EfiKeyAsterisk,
'*',
'*', 0, 0, EFI_NULL_MODIFIER, 0 },
112 { EfiKeyMinus,
'-',
'-', 0, 0, EFI_NULL_MODIFIER, 0 },
113 { EfiKeyPlus,
'+',
'+', 0, 0, EFI_NULL_MODIFIER, 0 },
114 { EfiKeyEnter, 0x0d, 0x0d, 0, 0, EFI_NULL_MODIFIER, 0 },
126 { EfiKeyA4, 0x00, 0x00, 0, 0, EFI_MENU_MODIFIER, 0 },
127 { EfiKeyLCtrl, 0, 0, 0, 0, EFI_LEFT_CONTROL_MODIFIER, 0 },
128 { EfiKeyLShift, 0, 0, 0, 0, EFI_LEFT_SHIFT_MODIFIER, 0 },
129 { EfiKeyLAlt, 0, 0, 0, 0, EFI_LEFT_ALT_MODIFIER, 0 },
130 { EfiKeyA0, 0, 0, 0, 0, EFI_LEFT_LOGO_MODIFIER, 0 },
131 { EfiKeyRCtrl, 0, 0, 0, 0, EFI_RIGHT_CONTROL_MODIFIER, 0 },
132 { EfiKeyRShift, 0, 0, 0, 0, EFI_RIGHT_SHIFT_MODIFIER, 0 },
133 { EfiKeyA2, 0, 0, 0, 0, EFI_RIGHT_ALT_MODIFIER, 0 },
134 { EfiKeyA3, 0, 0, 0, 0, EFI_RIGHT_LOGO_MODIFIER, 0 },
137 {
'e',
'n',
'-',
'U',
'S' },
139 {
'E',
'n',
'g',
'l',
'i',
's',
'h',
' ',
'K',
'e',
'y',
'b',
'o',
'a',
'r',
'd',
'\0' },
147UINT8 EfiKeyToUsbKeyCodeConvertionTable[] = {
259UINT8 ModifierValueToEfiScanCodeConvertionTable[] = {
327 Status =
gBS->LocateProtocol (
328 &gEfiHiiDatabaseProtocolGuid,
330 (VOID **)&HiiDatabase
332 if (EFI_ERROR (Status)) {
340 &gUsbKeyboardLayoutPackageGuid,
341 UsbKeyboardDevice->ControllerHandle,
342 &mUsbKeyboardLayoutBin,
345 if (HiiHandle ==
NULL) {
346 return EFI_OUT_OF_RESOURCES;
352 Status = HiiDatabase->SetKeyboardLayout (HiiDatabase, &gUsbKeyboardLayoutKeyGuid);
377 Status = UsbIo->UsbGetInterfaceDescriptor (
382 if (EFI_ERROR (Status)) {
386 if ((InterfaceDescriptor.InterfaceClass == CLASS_HID) &&
387 (InterfaceDescriptor.InterfaceSubClass == SUBCLASS_BOOT) &&
388 (InterfaceDescriptor.InterfaceProtocol == PROTOCOL_KEYBOARD)
417 Status =
gBS->LocateProtocol (
418 &gEfiHiiDatabaseProtocolGuid,
420 (VOID **)&HiiDatabase
422 if (EFI_ERROR (Status)) {
430 KeyboardLayout =
NULL;
431 Status = HiiDatabase->GetKeyboardLayout (
437 if (Status == EFI_BUFFER_TOO_SMALL) {
439 ASSERT (KeyboardLayout !=
NULL);
441 Status = HiiDatabase->GetKeyboardLayout (
447 if (EFI_ERROR (Status)) {
449 KeyboardLayout =
NULL;
453 return KeyboardLayout;
477 if ((!USBKBD_VALID_KEYCODE (KeyCode)) || ((KeyCode > 0x65) && (KeyCode < 0xe0)) || (KeyCode > 0xe7)) {
484 if (KeyCode <= 0x65) {
485 Index = (UINT8)(KeyCode - 4);
487 Index = (UINT8)(KeyCode - 0xe0 + NUMBER_OF_VALID_NON_MODIFIER_USB_KEYCODE);
490 return &UsbKeyboardDevice->KeyConvertionTable[Index];
513 NsKeyList = &UsbKeyboardDevice->NsKeyList;
515 while (!
IsNull (NsKeyList, Link)) {
516 UsbNsKey = USB_NS_KEY_FORM_FROM_LINK (Link);
518 if (UsbNsKey->NsKey[0].
Key == KeyDescriptor->Key) {
552 PhysicalKey = &UsbNsKey->NsKey[1];
553 for (Index = 0; Index < UsbNsKey->KeyCount; Index++) {
554 if (KeyDescriptor->Key == PhysicalKey->
Key) {
564 return KeyDescriptor;
598 if (UsbKeyboardDevice->Signature != USB_KB_DEV_SIGNATURE) {
606 if (KeyboardLayout ==
NULL) {
615 ASSERT (UsbKeyboardDevice->KeyConvertionTable !=
NULL);
621 for (Index = 0; Index < KeyboardLayout->DescriptorCount; Index++) {
630 KeyCode = EfiKeyToUsbKeyCodeConvertionTable[(UINT8)(TempKey.
Key)];
632 if (TableEntry ==
NULL) {
643 if (TempKey.
Modifier == EFI_NS_KEY_MODIFIER) {
645 ASSERT (UsbNsKey !=
NULL);
651 NsKey = KeyDescriptor + 1;
652 for (Index2 = (UINT8)Index + 1; Index2 < KeyboardLayout->DescriptorCount; Index2++) {
654 if (TempKey.
Modifier == EFI_NS_KEY_DEPENDENCY_MODIFIER) {
663 UsbNsKey->Signature = USB_NS_KEY_SIGNATURE;
664 UsbNsKey->KeyCount = KeyCount;
675 KeyDescriptor += KeyCount;
705 if (UsbKeyboardDevice->KeyConvertionTable !=
NULL) {
706 FreePool (UsbKeyboardDevice->KeyConvertionTable);
709 UsbKeyboardDevice->KeyConvertionTable =
NULL;
711 while (!
IsListEmpty (&UsbKeyboardDevice->NsKeyList)) {
713 UsbNsKey = USB_NS_KEY_FORM_FROM_LINK (Link);
745 ASSERT (UsbKeyboardDevice->KeyConvertionTable !=
NULL);
748 UsbKeyboardDevice->CurrentNsKey =
NULL;
749 UsbKeyboardDevice->KeyboardLayoutEvent =
NULL;
755 Status =
gBS->CreateEventEx (
760 &gEfiHiiKeyBoardLayoutGuid,
761 &UsbKeyboardDevice->KeyboardLayoutEvent
763 if (EFI_ERROR (Status)) {
768 if (KeyboardLayout !=
NULL) {
773 gBS->SignalEvent (UsbKeyboardDevice->KeyboardLayoutEvent);
775 if (
FeaturePcdGet (PcdDisableDefaultKeyboardLayoutInUsbKbDriver)) {
780 return EFI_NOT_READY;
809 UINT32 TransferResult;
813 (EFI_PERIPHERAL_KEYBOARD | EFI_P_KEYBOARD_PC_SELF_TEST),
814 UsbKeyboardDevice->DevicePath
826 UsbKeyboardDevice->UsbIo,
830 if (EFI_ERROR (Status)) {
836 UsbKeyboardDevice->UsbIo,
840 if (EFI_ERROR (Status)) {
848 (EFI_PERIPHERAL_KEYBOARD | EFI_P_EC_INTERFACE_ERROR),
849 UsbKeyboardDevice->DevicePath
852 return EFI_DEVICE_ERROR;
861 UsbKeyboardDevice->UsbIo,
862 UsbKeyboardDevice->InterfaceDescriptor.InterfaceNumber,
866 UsbKeyboardDevice->CtrlOn =
FALSE;
867 UsbKeyboardDevice->AltOn =
FALSE;
868 UsbKeyboardDevice->ShiftOn =
FALSE;
869 UsbKeyboardDevice->NumLockOn =
FALSE;
870 UsbKeyboardDevice->CapsOn =
FALSE;
871 UsbKeyboardDevice->ScrollOn =
FALSE;
873 UsbKeyboardDevice->LeftCtrlOn =
FALSE;
874 UsbKeyboardDevice->LeftAltOn =
FALSE;
875 UsbKeyboardDevice->LeftShiftOn =
FALSE;
876 UsbKeyboardDevice->LeftLogoOn =
FALSE;
877 UsbKeyboardDevice->RightCtrlOn =
FALSE;
878 UsbKeyboardDevice->RightAltOn =
FALSE;
879 UsbKeyboardDevice->RightShiftOn =
FALSE;
880 UsbKeyboardDevice->RightLogoOn =
FALSE;
881 UsbKeyboardDevice->MenuKeyOn =
FALSE;
882 UsbKeyboardDevice->SysReqOn =
FALSE;
884 UsbKeyboardDevice->AltGrOn =
FALSE;
886 UsbKeyboardDevice->CurrentNsKey =
NULL;
893 ZeroMem (UsbKeyboardDevice->LastKeyCodeArray, sizeof (UINT8) * 8);
898 if (UsbKeyboardDevice->RepeatTimer !=
NULL) {
899 gBS->CloseEvent (UsbKeyboardDevice->RepeatTimer);
900 UsbKeyboardDevice->RepeatTimer =
NULL;
904 EVT_TIMER | EVT_NOTIFY_SIGNAL,
908 &UsbKeyboardDevice->RepeatTimer
914 if (UsbKeyboardDevice->DelayedRecoveryEvent !=
NULL) {
915 gBS->CloseEvent (UsbKeyboardDevice->DelayedRecoveryEvent);
916 UsbKeyboardDevice->DelayedRecoveryEvent =
NULL;
920 EVT_TIMER | EVT_NOTIFY_SIGNAL,
924 &UsbKeyboardDevice->DelayedRecoveryEvent
959 UINT8 *CurKeyCodeBuffer;
960 UINT8 *OldKeyCodeBuffer;
961 UINT8 CurModifierMap;
962 UINT8 OldModifierMap;
973 ASSERT (Context !=
NULL);
977 UsbIo = UsbKeyboardDevice->UsbIo;
982 if (Result != EFI_USB_NOERROR) {
988 (EFI_PERIPHERAL_KEYBOARD | EFI_P_EC_INPUT_ERROR),
989 UsbKeyboardDevice->DevicePath
995 UsbKeyboardDevice->RepeatKey = 0;
998 UsbKeyboardDevice->RepeatTimer,
1003 if ((Result & EFI_USB_ERR_STALL) == EFI_USB_ERR_STALL) {
1006 UsbKeyboardDevice->IntEndpointDescriptor.EndpointAddress,
1015 UsbIo->UsbAsyncInterruptTransfer (
1017 UsbKeyboardDevice->IntEndpointDescriptor.EndpointAddress,
1028 UsbKeyboardDevice->DelayedRecoveryEvent,
1030 EFI_USB_INTERRUPT_DELAY
1033 return EFI_DEVICE_ERROR;
1039 if ((DataLength == 0) || (Data ==
NULL)) {
1050 if (DataLength < 8) {
1051 return EFI_DEVICE_ERROR;
1054 CurKeyCodeBuffer = (UINT8 *)Data;
1055 OldKeyCodeBuffer = UsbKeyboardDevice->LastKeyCodeArray;
1060 for (Index = 0; Index < 8; Index++) {
1061 if (OldKeyCodeBuffer[Index] != CurKeyCodeBuffer[Index]) {
1076 CurModifierMap = CurKeyCodeBuffer[0];
1077 OldModifierMap = OldKeyCodeBuffer[0];
1091 for (Index = 0; Index < 8; Index++) {
1092 Mask = (UINT8)(1 << Index);
1093 if ((CurModifierMap & Mask) != (OldModifierMap & Mask)) {
1099 UsbKey.KeyCode = (UINT8)(0xe0 + Index);
1100 UsbKey.Down = (BOOLEAN)((CurModifierMap & Mask) != 0);
1101 Enqueue (&UsbKeyboardDevice->UsbKeyQueue, &UsbKey, sizeof (UsbKey));
1110 for (Index = 2; Index < 8; Index++) {
1111 if (!USBKBD_VALID_KEYCODE (OldKeyCodeBuffer[Index])) {
1120 for (Index2 = 2; Index2 < 8; Index2++) {
1121 if (!USBKBD_VALID_KEYCODE (CurKeyCodeBuffer[Index2])) {
1125 if (OldKeyCodeBuffer[Index] == CurKeyCodeBuffer[Index2]) {
1132 UsbKey.KeyCode = OldKeyCodeBuffer[Index];
1133 UsbKey.Down =
FALSE;
1134 Enqueue (&UsbKeyboardDevice->UsbKeyQueue, &UsbKey, sizeof (UsbKey));
1138 if (OldKeyCodeBuffer[Index] == UsbKeyboardDevice->RepeatKey) {
1139 UsbKeyboardDevice->RepeatKey = 0;
1147 if (UsbKeyboardDevice->RepeatKey == 0) {
1149 UsbKeyboardDevice->RepeatTimer,
1159 for (Index = 2; Index < 8; Index++) {
1160 if (!USBKBD_VALID_KEYCODE (CurKeyCodeBuffer[Index])) {
1169 for (Index2 = 2; Index2 < 8; Index2++) {
1170 if (!USBKBD_VALID_KEYCODE (OldKeyCodeBuffer[Index2])) {
1174 if (CurKeyCodeBuffer[Index] == OldKeyCodeBuffer[Index2]) {
1181 UsbKey.KeyCode = CurKeyCodeBuffer[Index];
1183 Enqueue (&UsbKeyboardDevice->UsbKeyQueue, &UsbKey, sizeof (UsbKey));
1188 KeyDescriptor =
GetKeyDescriptor (UsbKeyboardDevice, CurKeyCodeBuffer[Index]);
1189 if (KeyDescriptor ==
NULL) {
1193 if ((KeyDescriptor->
Modifier == EFI_NUM_LOCK_MODIFIER) || (KeyDescriptor->
Modifier == EFI_CAPS_LOCK_MODIFIER)) {
1197 UsbKeyboardDevice->RepeatKey = 0;
1202 NewRepeatKey = CurKeyCodeBuffer[Index];
1203 UsbKeyboardDevice->RepeatKey = 0;
1211 for (Index = 0; Index < 8; Index++) {
1212 UsbKeyboardDevice->LastKeyCodeArray[Index] = CurKeyCodeBuffer[Index];
1219 if (NewRepeatKey != 0) {
1226 UsbKeyboardDevice->RepeatTimer,
1230 UsbKeyboardDevice->RepeatKey = NewRepeatKey;
1260 while (!
IsQueueEmpty (&UsbKeyboardDevice->UsbKeyQueue)) {
1264 Dequeue (&UsbKeyboardDevice->UsbKeyQueue, &UsbKey, sizeof (UsbKey));
1267 if (KeyDescriptor ==
NULL) {
1279 case EFI_LEFT_CONTROL_MODIFIER:
1280 UsbKeyboardDevice->LeftCtrlOn =
FALSE;
1281 UsbKeyboardDevice->CtrlOn =
FALSE;
1283 case EFI_RIGHT_CONTROL_MODIFIER:
1284 UsbKeyboardDevice->RightCtrlOn =
FALSE;
1285 UsbKeyboardDevice->CtrlOn =
FALSE;
1291 case EFI_LEFT_SHIFT_MODIFIER:
1292 UsbKeyboardDevice->LeftShiftOn =
FALSE;
1293 UsbKeyboardDevice->ShiftOn =
FALSE;
1295 case EFI_RIGHT_SHIFT_MODIFIER:
1296 UsbKeyboardDevice->RightShiftOn =
FALSE;
1297 UsbKeyboardDevice->ShiftOn =
FALSE;
1303 case EFI_LEFT_ALT_MODIFIER:
1304 UsbKeyboardDevice->LeftAltOn =
FALSE;
1305 UsbKeyboardDevice->AltOn =
FALSE;
1307 case EFI_RIGHT_ALT_MODIFIER:
1308 UsbKeyboardDevice->RightAltOn =
FALSE;
1309 UsbKeyboardDevice->AltOn =
FALSE;
1315 case EFI_LEFT_LOGO_MODIFIER:
1316 UsbKeyboardDevice->LeftLogoOn =
FALSE;
1322 case EFI_RIGHT_LOGO_MODIFIER:
1323 UsbKeyboardDevice->RightLogoOn =
FALSE;
1329 case EFI_MENU_MODIFIER:
1330 UsbKeyboardDevice->MenuKeyOn =
FALSE;
1336 case EFI_PRINT_MODIFIER:
1337 case EFI_SYS_REQUEST_MODIFIER:
1338 UsbKeyboardDevice->SysReqOn =
FALSE;
1344 case EFI_ALT_GR_MODIFIER:
1345 UsbKeyboardDevice->AltGrOn =
FALSE;
1362 case EFI_LEFT_CONTROL_MODIFIER:
1363 UsbKeyboardDevice->LeftCtrlOn =
TRUE;
1364 UsbKeyboardDevice->CtrlOn =
TRUE;
1366 case EFI_RIGHT_CONTROL_MODIFIER:
1367 UsbKeyboardDevice->RightCtrlOn =
TRUE;
1368 UsbKeyboardDevice->CtrlOn =
TRUE;
1374 case EFI_LEFT_SHIFT_MODIFIER:
1375 UsbKeyboardDevice->LeftShiftOn =
TRUE;
1376 UsbKeyboardDevice->ShiftOn =
TRUE;
1378 case EFI_RIGHT_SHIFT_MODIFIER:
1379 UsbKeyboardDevice->RightShiftOn =
TRUE;
1380 UsbKeyboardDevice->ShiftOn =
TRUE;
1386 case EFI_LEFT_ALT_MODIFIER:
1387 UsbKeyboardDevice->LeftAltOn =
TRUE;
1388 UsbKeyboardDevice->AltOn =
TRUE;
1390 case EFI_RIGHT_ALT_MODIFIER:
1391 UsbKeyboardDevice->RightAltOn =
TRUE;
1392 UsbKeyboardDevice->AltOn =
TRUE;
1398 case EFI_LEFT_LOGO_MODIFIER:
1399 UsbKeyboardDevice->LeftLogoOn =
TRUE;
1405 case EFI_RIGHT_LOGO_MODIFIER:
1406 UsbKeyboardDevice->RightLogoOn =
TRUE;
1412 case EFI_MENU_MODIFIER:
1413 UsbKeyboardDevice->MenuKeyOn =
TRUE;
1419 case EFI_PRINT_MODIFIER:
1420 case EFI_SYS_REQUEST_MODIFIER:
1421 UsbKeyboardDevice->SysReqOn =
TRUE;
1427 case EFI_ALT_GR_MODIFIER:
1428 UsbKeyboardDevice->AltGrOn =
TRUE;
1431 case EFI_NUM_LOCK_MODIFIER:
1435 UsbKeyboardDevice->NumLockOn = (BOOLEAN)(!(UsbKeyboardDevice->NumLockOn));
1439 case EFI_CAPS_LOCK_MODIFIER:
1443 UsbKeyboardDevice->CapsOn = (BOOLEAN)(!(UsbKeyboardDevice->CapsOn));
1447 case EFI_SCROLL_LOCK_MODIFIER:
1451 UsbKeyboardDevice->ScrollOn = (BOOLEAN)(!(UsbKeyboardDevice->ScrollOn));
1462 if (KeyDescriptor->
Modifier == EFI_DELETE_MODIFIER) {
1463 if ((UsbKeyboardDevice->CtrlOn) && (UsbKeyboardDevice->AltOn)) {
1468 *KeyCode = UsbKey.KeyCode;
1472 return EFI_NOT_READY;
1487 KeyState->KeyShiftState = EFI_SHIFT_STATE_VALID;
1488 KeyState->KeyToggleState = EFI_TOGGLE_STATE_VALID;
1490 if (UsbKeyboardDevice->LeftCtrlOn) {
1491 KeyState->KeyShiftState |= EFI_LEFT_CONTROL_PRESSED;
1494 if (UsbKeyboardDevice->RightCtrlOn) {
1495 KeyState->KeyShiftState |= EFI_RIGHT_CONTROL_PRESSED;
1498 if (UsbKeyboardDevice->LeftAltOn) {
1499 KeyState->KeyShiftState |= EFI_LEFT_ALT_PRESSED;
1502 if (UsbKeyboardDevice->RightAltOn) {
1503 KeyState->KeyShiftState |= EFI_RIGHT_ALT_PRESSED;
1506 if (UsbKeyboardDevice->LeftShiftOn) {
1507 KeyState->KeyShiftState |= EFI_LEFT_SHIFT_PRESSED;
1510 if (UsbKeyboardDevice->RightShiftOn) {
1511 KeyState->KeyShiftState |= EFI_RIGHT_SHIFT_PRESSED;
1514 if (UsbKeyboardDevice->LeftLogoOn) {
1515 KeyState->KeyShiftState |= EFI_LEFT_LOGO_PRESSED;
1518 if (UsbKeyboardDevice->RightLogoOn) {
1519 KeyState->KeyShiftState |= EFI_RIGHT_LOGO_PRESSED;
1522 if (UsbKeyboardDevice->MenuKeyOn) {
1523 KeyState->KeyShiftState |= EFI_MENU_KEY_PRESSED;
1526 if (UsbKeyboardDevice->SysReqOn) {
1527 KeyState->KeyShiftState |= EFI_SYS_REQ_PRESSED;
1530 if (UsbKeyboardDevice->ScrollOn) {
1531 KeyState->KeyToggleState |= EFI_SCROLL_LOCK_ACTIVE;
1534 if (UsbKeyboardDevice->NumLockOn) {
1535 KeyState->KeyToggleState |= EFI_NUM_LOCK_ACTIVE;
1538 if (UsbKeyboardDevice->CapsOn) {
1539 KeyState->KeyToggleState |= EFI_CAPS_LOCK_ACTIVE;
1542 if (UsbKeyboardDevice->IsSupportPartialKey) {
1543 KeyState->KeyToggleState |= EFI_KEY_STATE_EXPOSED;
1579 if (KeyDescriptor ==
NULL) {
1580 return EFI_DEVICE_ERROR;
1583 if (KeyDescriptor->
Modifier == EFI_NS_KEY_MODIFIER) {
1587 UsbKeyboardDevice->CurrentNsKey =
FindUsbNsKey (UsbKeyboardDevice, KeyDescriptor);
1588 return EFI_NOT_READY;
1591 if (UsbKeyboardDevice->CurrentNsKey !=
NULL) {
1596 KeyDescriptor =
FindPhysicalKey (UsbKeyboardDevice->CurrentNsKey, KeyDescriptor);
1597 UsbKeyboardDevice->CurrentNsKey =
NULL;
1603 if (KeyDescriptor->
Modifier >= (sizeof (ModifierValueToEfiScanCodeConvertionTable) /
sizeof (UINT8))) {
1604 return EFI_DEVICE_ERROR;
1607 KeyData->Key.ScanCode = ModifierValueToEfiScanCodeConvertionTable[KeyDescriptor->
Modifier];
1608 KeyData->Key.UnicodeChar = KeyDescriptor->
Unicode;
1611 if (UsbKeyboardDevice->ShiftOn) {
1621 UsbKeyboardDevice->LeftShiftOn =
FALSE;
1622 UsbKeyboardDevice->RightShiftOn =
FALSE;
1625 if (UsbKeyboardDevice->AltGrOn) {
1632 KeyData->Key.UnicodeChar = KeyDescriptor->
Unicode;
1634 if (UsbKeyboardDevice->AltGrOn) {
1635 KeyData->Key.UnicodeChar = KeyDescriptor->
AltGrUnicode;
1641 if (UsbKeyboardDevice->CapsOn) {
1642 if (KeyData->Key.UnicodeChar == KeyDescriptor->
Unicode) {
1644 }
else if (KeyData->Key.UnicodeChar == KeyDescriptor->
ShiftedUnicode) {
1645 KeyData->Key.UnicodeChar = KeyDescriptor->
Unicode;
1656 if ((UsbKeyboardDevice->NumLockOn) && (!(UsbKeyboardDevice->ShiftOn))) {
1657 KeyData->Key.ScanCode = SCAN_NULL;
1659 KeyData->Key.UnicodeChar = CHAR_NULL;
1666 if ((KeyData->Key.UnicodeChar == 0x1B) && (KeyData->Key.ScanCode == SCAN_NULL)) {
1667 KeyData->Key.ScanCode = SCAN_ESC;
1668 KeyData->Key.UnicodeChar = CHAR_NULL;
1674 if ((KeyData->Key.UnicodeChar == 0) && (KeyData->Key.ScanCode == SCAN_NULL)) {
1675 if (!UsbKeyboardDevice->IsSupportPartialKey) {
1676 return EFI_NOT_READY;
1688 NotifyList = &UsbKeyboardDevice->NotifyList;
1697 Enqueue (&UsbKeyboardDevice->EfiKeyQueueForNotify, KeyData, sizeof (*KeyData));
1698 gBS->SignalEvent (UsbKeyboardDevice->KeyNotifyProcessEvent);
1721 Queue->ItemSize = ItemSize;
1725 if (Queue->Buffer[0] !=
NULL) {
1729 Queue->Buffer[0] =
AllocatePool (
sizeof (Queue->Buffer) / sizeof (Queue->Buffer[0]) * ItemSize);
1730 ASSERT (Queue->Buffer[0] !=
NULL);
1732 for (Index = 1; Index <
sizeof (Queue->Buffer) /
sizeof (Queue->Buffer[0]); Index++) {
1733 Queue->Buffer[Index] = ((UINT8 *)Queue->Buffer[Index - 1]) + ItemSize;
1767 return (BOOLEAN)(Queue->Head == Queue->Tail);
1784 return (BOOLEAN)(((Queue->Tail + 1) % (MAX_KEY_ALLOWED + 1)) == Queue->Head);
1801 ASSERT (ItemSize == Queue->ItemSize);
1807 Queue->Head = (Queue->Head + 1) % (MAX_KEY_ALLOWED + 1);
1810 CopyMem (Queue->Buffer[Queue->Tail], Item, ItemSize);
1815 Queue->Tail = (Queue->Tail + 1) % (MAX_KEY_ALLOWED + 1);
1836 ASSERT (Queue->ItemSize == ItemSize);
1839 return EFI_DEVICE_ERROR;
1842 CopyMem (Item, Queue->Buffer[Queue->Head], ItemSize);
1847 Queue->Head = (Queue->Head + 1) % (MAX_KEY_ALLOWED + 1);
1869 Led.NumLock = (UINT8)((UsbKeyboardDevice->NumLockOn) ? 1 : 0);
1870 Led.CapsLock = (UINT8)((UsbKeyboardDevice->CapsOn) ? 1 : 0);
1871 Led.ScrollLock = (UINT8)((UsbKeyboardDevice->ScrollOn) ? 1 : 0);
1879 UsbKeyboardDevice->UsbIo,
1880 UsbKeyboardDevice->InterfaceDescriptor.InterfaceNumber,
1916 if (UsbKeyboardDevice->RepeatKey != 0) {
1920 UsbKey.KeyCode = UsbKeyboardDevice->RepeatKey;
1922 Enqueue (&UsbKeyboardDevice->UsbKeyQueue, &UsbKey, sizeof (UsbKey));
1928 UsbKeyboardDevice->RepeatTimer,
1961 UsbIo = UsbKeyboardDevice->UsbIo;
1963 PacketSize = (UINT8)(UsbKeyboardDevice->IntEndpointDescriptor.MaxPacketSize);
1968 UsbIo->UsbAsyncInterruptTransfer (
1970 UsbKeyboardDevice->IntEndpointDescriptor.EndpointAddress,
1972 UsbKeyboardDevice->IntEndpointDescriptor.Interval,
BOOLEAN EFIAPI IsNull(IN CONST LIST_ENTRY *List, IN CONST LIST_ENTRY *Node)
BOOLEAN EFIAPI IsListEmpty(IN CONST LIST_ENTRY *ListHead)
LIST_ENTRY *EFIAPI GetNextNode(IN CONST LIST_ENTRY *List, IN CONST LIST_ENTRY *Node)
LIST_ENTRY *EFIAPI GetFirstNode(IN CONST LIST_ENTRY *List)
LIST_ENTRY *EFIAPI RemoveEntryList(IN CONST LIST_ENTRY *Entry)
LIST_ENTRY *EFIAPI InitializeListHead(IN OUT LIST_ENTRY *ListHead)
LIST_ENTRY *EFIAPI InsertTailList(IN OUT LIST_ENTRY *ListHead, IN OUT LIST_ENTRY *Entry)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
VOID *EFIAPI AllocateCopyPool(IN UINTN AllocationSize, IN CONST VOID *Buffer)
EFI_HII_HANDLE EFIAPI HiiAddPackages(IN CONST EFI_GUID *PackageListGuid, IN EFI_HANDLE DeviceHandle OPTIONAL,...)
VOID EFIAPI USBKeyboardRepeatHandler(IN EFI_EVENT Event, IN VOID *Context)
EFI_STATUS EFIAPI KeyboardHandler(IN VOID *Data, IN UINTN DataLength, IN VOID *Context, IN UINT32 Result)
EFI_KEY_DESCRIPTOR * GetKeyDescriptor(IN USB_KB_DEV *UsbKeyboardDevice, IN UINT8 KeyCode)
VOID SetKeyLED(IN USB_KB_DEV *UsbKeyboardDevice)
VOID EFIAPI SetKeyboardLayoutEvent(IN EFI_EVENT Event, IN VOID *Context)
EFI_KEY_DESCRIPTOR * FindPhysicalKey(IN USB_NS_KEY *UsbNsKey, IN EFI_KEY_DESCRIPTOR *KeyDescriptor)
VOID EFIAPI USBKeyboardRecoveryHandler(IN EFI_EVENT Event, IN VOID *Context)
VOID DestroyQueue(IN OUT USB_SIMPLE_QUEUE *Queue)
EFI_STATUS InitUSBKeyboard(IN OUT USB_KB_DEV *UsbKeyboardDevice)
EFI_STATUS Dequeue(IN OUT USB_SIMPLE_QUEUE *Queue, OUT VOID *Item, IN UINTN ItemSize)
EFI_HII_KEYBOARD_LAYOUT * GetCurrentKeyboardLayout(VOID)
VOID ReleaseKeyboardLayoutResources(IN OUT USB_KB_DEV *UsbKeyboardDevice)
EFI_STATUS USBParseKey(IN OUT USB_KB_DEV *UsbKeyboardDevice, OUT UINT8 *KeyCode)
USB_NS_KEY * FindUsbNsKey(IN USB_KB_DEV *UsbKeyboardDevice, IN EFI_KEY_DESCRIPTOR *KeyDescriptor)
VOID InitQueue(IN OUT USB_SIMPLE_QUEUE *Queue, IN UINTN ItemSize)
VOID Enqueue(IN OUT USB_SIMPLE_QUEUE *Queue, IN VOID *Item, IN UINTN ItemSize)
VOID InitializeKeyState(IN USB_KB_DEV *UsbKeyboardDevice, OUT EFI_KEY_STATE *KeyState)
BOOLEAN IsQueueFull(IN USB_SIMPLE_QUEUE *Queue)
BOOLEAN IsUSBKeyboard(IN EFI_USB_IO_PROTOCOL *UsbIo)
EFI_STATUS InstallDefaultKeyboardLayout(IN OUT USB_KB_DEV *UsbKeyboardDevice)
EFI_STATUS UsbKeyCodeToEfiInputKey(IN USB_KB_DEV *UsbKeyboardDevice, IN UINT8 KeyCode, OUT EFI_KEY_DATA *KeyData)
EFI_STATUS InitKeyboardLayout(OUT USB_KB_DEV *UsbKeyboardDevice)
BOOLEAN IsQueueEmpty(IN USB_SIMPLE_QUEUE *Queue)
EFI_RUNTIME_SERVICES * gRT
#define CR(Record, TYPE, Field, TestSignature)
#define REPORT_STATUS_CODE_WITH_DEVICE_PATH(Type, Value, DevicePathParameter)
#define FeaturePcdGet(TokenName)
#define EFI_PROGRESS_CODE
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
EFI_STATUS EFIAPI UsbSetReportRequest(IN EFI_USB_IO_PROTOCOL *UsbIo, IN UINT8 Interface, IN UINT8 ReportId, IN UINT8 ReportType, IN UINT16 ReportLen, IN UINT8 *Report)
EFI_STATUS EFIAPI UsbGetConfiguration(IN EFI_USB_IO_PROTOCOL *UsbIo, OUT UINT16 *ConfigurationValue, OUT UINT32 *Status)
EFI_STATUS EFIAPI UsbSetProtocolRequest(IN EFI_USB_IO_PROTOCOL *UsbIo, IN UINT8 Interface, IN UINT8 Protocol)
EFI_STATUS EFIAPI UsbClearEndpointHalt(IN EFI_USB_IO_PROTOCOL *UsbIo, IN UINT8 Endpoint, OUT UINT32 *Status)
EFI_STATUS EFIAPI UsbSetConfiguration(IN EFI_USB_IO_PROTOCOL *UsbIo, IN UINT16 ConfigurationValue, OUT UINT32 *Status)
BOOLEAN IsKeyRegistered(IN EFI_KEY_DATA *RegsiteredData, IN EFI_KEY_DATA *InputData)
CHAR16 ShiftedAltGrUnicode