]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Fix the USB keyboard driver to call hotkey callback even no one is calling ReadKeyStroke
authorniruiyu <niruiyu@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 19 Apr 2011 06:52:20 +0000 (06:52 +0000)
committerniruiyu <niruiyu@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 19 Apr 2011 06:52:20 +0000 (06:52 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11563 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Bus/Usb/UsbKbDxe/EfiKey.c
MdeModulePkg/Bus/Usb/UsbKbDxe/EfiKey.h
MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c
MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.h

index 278c2da19a474d1b3c8dd39b3d9c51c9afa5347d..fa1c7e076b9886d8c092fa5ec26c46ddc0a5df0a 100644 (file)
@@ -2,7 +2,7 @@
   USB Keyboard Driver that manages USB keyboard and produces Simple Text Input\r
   Protocol and Simple Text Input Ex Protocol.\r
 \r
   USB Keyboard Driver that manages USB keyboard and produces Simple Text Input\r
   Protocol and Simple Text Input Ex Protocol.\r
 \r
-Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -262,6 +262,20 @@ USBKeyboardDriverBindingStart (
   \r
   InitializeListHead (&UsbKeyboardDevice->NotifyList);\r
   \r
   \r
   InitializeListHead (&UsbKeyboardDevice->NotifyList);\r
   \r
+  Status = gBS->CreateEvent (\r
+                  EVT_TIMER | EVT_NOTIFY_SIGNAL,\r
+                  TPL_NOTIFY,\r
+                  USBKeyboardTimerHandler,\r
+                  UsbKeyboardDevice,\r
+                  &UsbKeyboardDevice->TimerEvent\r
+                  );\r
+  if (!EFI_ERROR (Status)) {\r
+    Status = gBS->SetTimer (UsbKeyboardDevice->TimerEvent, TimerPeriodic, KEYBOARD_TIMER_INTERVAL);\r
+  }\r
+  if (EFI_ERROR (Status)) {\r
+    goto ErrorExit;\r
+  }\r
+\r
   Status = gBS->CreateEvent (\r
                   EVT_NOTIFY_WAIT,\r
                   TPL_NOTIFY,\r
   Status = gBS->CreateEvent (\r
                   EVT_NOTIFY_WAIT,\r
                   TPL_NOTIFY,\r
@@ -391,6 +405,9 @@ USBKeyboardDriverBindingStart (
 //\r
 ErrorExit:\r
   if (UsbKeyboardDevice != NULL) {\r
 //\r
 ErrorExit:\r
   if (UsbKeyboardDevice != NULL) {\r
+    if (UsbKeyboardDevice->TimerEvent != NULL) {\r
+      gBS->CloseEvent (UsbKeyboardDevice->TimerEvent);\r
+    }\r
     if (UsbKeyboardDevice->SimpleInput.WaitForKey != NULL) {\r
       gBS->CloseEvent (UsbKeyboardDevice->SimpleInput.WaitForKey);\r
     }\r
     if (UsbKeyboardDevice->SimpleInput.WaitForKey != NULL) {\r
       gBS->CloseEvent (UsbKeyboardDevice->SimpleInput.WaitForKey);\r
     }\r
@@ -513,11 +530,12 @@ USBKeyboardDriverBindingStop (
   //\r
   // Free all resources.\r
   //\r
   //\r
   // Free all resources.\r
   //\r
+  gBS->CloseEvent (UsbKeyboardDevice->TimerEvent);\r
   gBS->CloseEvent (UsbKeyboardDevice->RepeatTimer);\r
   gBS->CloseEvent (UsbKeyboardDevice->DelayedRecoveryEvent);\r
   gBS->CloseEvent (UsbKeyboardDevice->RepeatTimer);\r
   gBS->CloseEvent (UsbKeyboardDevice->DelayedRecoveryEvent);\r
-  gBS->CloseEvent ((UsbKeyboardDevice->SimpleInput).WaitForKey);\r
-  gBS->CloseEvent (UsbKeyboardDevice->SimpleInputEx.WaitForKeyEx);  \r
-  KbdFreeNotifyList (&UsbKeyboardDevice->NotifyList);    \r
+  gBS->CloseEvent (UsbKeyboardDevice->SimpleInput.WaitForKey);\r
+  gBS->CloseEvent (UsbKeyboardDevice->SimpleInputEx.WaitForKeyEx);\r
+  KbdFreeNotifyList (&UsbKeyboardDevice->NotifyList);\r
 \r
   ReleaseKeyboardLayoutResources (UsbKeyboardDevice);\r
   gBS->CloseEvent (UsbKeyboardDevice->KeyboardLayoutEvent);\r
 \r
   ReleaseKeyboardLayoutResources (UsbKeyboardDevice);\r
   gBS->CloseEvent (UsbKeyboardDevice->KeyboardLayoutEvent);\r
@@ -526,6 +544,9 @@ USBKeyboardDriverBindingStop (
     FreeUnicodeStringTable (UsbKeyboardDevice->ControllerNameTable);\r
   }\r
 \r
     FreeUnicodeStringTable (UsbKeyboardDevice->ControllerNameTable);\r
   }\r
 \r
+  DestroyQueue (&UsbKeyboardDevice->UsbKeyQueue);\r
+  DestroyQueue (&UsbKeyboardDevice->EfiKeyQueue);\r
+  \r
   FreePool (UsbKeyboardDevice);\r
 \r
   return Status;\r
   FreePool (UsbKeyboardDevice);\r
 \r
   return Status;\r
@@ -547,89 +568,20 @@ USBKeyboardDriverBindingStop (
 \r
 **/\r
 EFI_STATUS\r
 \r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 USBKeyboardReadKeyStrokeWorker (\r
   IN OUT USB_KB_DEV                 *UsbKeyboardDevice,\r
      OUT EFI_KEY_DATA               *KeyData\r
   )\r
 {\r
 USBKeyboardReadKeyStrokeWorker (\r
   IN OUT USB_KB_DEV                 *UsbKeyboardDevice,\r
      OUT EFI_KEY_DATA               *KeyData\r
   )\r
 {\r
-  EFI_STATUS                        Status;\r
-  UINT8                             KeyCode;  \r
-  LIST_ENTRY                        *Link;\r
-  LIST_ENTRY                        *NotifyList;\r
-  KEYBOARD_CONSOLE_IN_EX_NOTIFY     *CurrentNotify;  \r
-  EFI_KEY_DATA                      OriginalKeyData;\r
-\r
   if (KeyData == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
   if (KeyData == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  //\r
-  // If there is no saved USB keycode, fetch it\r
-  // by calling USBKeyboardCheckForKey().\r
-  //\r
-  if (UsbKeyboardDevice->CurKeyCode == 0) {\r
-    Status = USBKeyboardCheckForKey (UsbKeyboardDevice);\r
-    if (EFI_ERROR (Status)) {\r
-      return EFI_NOT_READY;\r
-    }\r
-  }\r
-\r
-  KeyData->Key.UnicodeChar = 0;\r
-  KeyData->Key.ScanCode    = SCAN_NULL;\r
-\r
-  //\r
-  // Store the current keycode and clear it.\r
-  //\r
-  KeyCode = UsbKeyboardDevice->CurKeyCode;\r
-  UsbKeyboardDevice->CurKeyCode = 0;\r
-\r
-  //\r
-  // Translate saved USB keycode into EFI_INPUT_KEY\r
-  //\r
-  Status = UsbKeyCodeToEfiInputKey (UsbKeyboardDevice, KeyCode, &KeyData->Key);\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
+  if (IsQueueEmpty (&UsbKeyboardDevice->EfiKeyQueue)) {\r
+    return EFI_NOT_READY;\r
   }\r
 \r
   }\r
 \r
-  //\r
-  // Get current state of various toggled attributes as well as input modifier values,\r
-  // and set them as valid.\r
-  //\r
-  CopyMem (&KeyData->KeyState, &UsbKeyboardDevice->KeyState, sizeof (KeyData->KeyState));\r
-  \r
-  UsbKeyboardDevice->KeyState.KeyShiftState  = EFI_SHIFT_STATE_VALID;\r
-  UsbKeyboardDevice->KeyState.KeyToggleState = EFI_TOGGLE_STATE_VALID;\r
-\r
-  //\r
-  // Switch the control value to their original characters.\r
-  // In UsbKeyCodeToEfiInputKey() the  CTRL-Alpha characters have been switched to \r
-  // their corresponding control value (ctrl-a = 0x0001 through ctrl-Z = 0x001A),\r
-  // here switch them back for notification function.\r
-  //\r
-  CopyMem (&OriginalKeyData, KeyData, sizeof (EFI_KEY_DATA));\r
-  if (UsbKeyboardDevice->CtrlOn) {\r
-    if (OriginalKeyData.Key.UnicodeChar >= 0x01 && OriginalKeyData.Key.UnicodeChar <= 0x1A) {\r
-      if (UsbKeyboardDevice->CapsOn) {\r
-        OriginalKeyData.Key.UnicodeChar = (CHAR16)(OriginalKeyData.Key.UnicodeChar + 'A' - 1);\r
-      } else {\r
-        OriginalKeyData.Key.UnicodeChar = (CHAR16)(OriginalKeyData.Key.UnicodeChar + 'a' - 1);\r
-      } \r
-    }\r
-  }\r
-  \r
-  //\r
-  // Invoke notification functions if the key is registered.\r
-  //\r
-  NotifyList = &UsbKeyboardDevice->NotifyList;\r
-  for (Link = GetFirstNode (NotifyList);\r
-       !IsNull (NotifyList, Link);\r
-       Link = GetNextNode (NotifyList, Link)) {\r
-    CurrentNotify = CR (Link, KEYBOARD_CONSOLE_IN_EX_NOTIFY, NotifyEntry, USB_KB_CONSOLE_IN_EX_NOTIFY_SIGNATURE);\r
-    if (IsKeyRegistered (&CurrentNotify->KeyData, &OriginalKeyData)) { \r
-      CurrentNotify->KeyNotificationFn (&OriginalKeyData);\r
-    }\r
-  }\r
+  Dequeue (&UsbKeyboardDevice->EfiKeyQueue, KeyData, sizeof (*KeyData));\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
   return EFI_SUCCESS;\r
 }\r
@@ -680,8 +632,8 @@ USBKeyboardReset (
     //\r
     // Clear the key buffer of this USB keyboard\r
     //\r
     //\r
     // Clear the key buffer of this USB keyboard\r
     //\r
-    InitUSBKeyBuffer (&(UsbKeyboardDevice->KeyboardBuffer));\r
-    UsbKeyboardDevice->CurKeyCode = 0;\r
+    InitQueue (&UsbKeyboardDevice->UsbKeyQueue, sizeof (USB_KEY));\r
+    InitQueue (&UsbKeyboardDevice->EfiKeyQueue, sizeof (EFI_KEY_DATA));\r
 \r
     return EFI_SUCCESS;\r
   }\r
 \r
     return EFI_SUCCESS;\r
   }\r
@@ -690,7 +642,6 @@ USBKeyboardReset (
   // Exhaustive reset\r
   //\r
   Status = InitUSBKeyboard (UsbKeyboardDevice);\r
   // Exhaustive reset\r
   //\r
   Status = InitUSBKeyboard (UsbKeyboardDevice);\r
-  UsbKeyboardDevice->CurKeyCode = 0;\r
   if (EFI_ERROR (Status)) {\r
     return EFI_DEVICE_ERROR;\r
   }\r
   if (EFI_ERROR (Status)) {\r
     return EFI_DEVICE_ERROR;\r
   }\r
@@ -755,50 +706,55 @@ USBKeyboardWaitForKey (
 \r
   UsbKeyboardDevice = (USB_KB_DEV *) Context;\r
 \r
 \r
   UsbKeyboardDevice = (USB_KB_DEV *) Context;\r
 \r
-  if (UsbKeyboardDevice->CurKeyCode == 0) {\r
-    if (EFI_ERROR (USBKeyboardCheckForKey (UsbKeyboardDevice))) {\r
-      //\r
-      // If no pending key, simply return.\r
-      //\r
-      return ;\r
-    }\r
+  if (!IsQueueEmpty (&UsbKeyboardDevice->EfiKeyQueue)) {\r
+    //\r
+    // If there is pending key, signal the event.\r
+    //\r
+    gBS->SignalEvent (Event);\r
   }\r
   }\r
-  //\r
-  // If there is pending key, signal the event.\r
-  //\r
-  gBS->SignalEvent (Event);\r
 }\r
 \r
 }\r
 \r
-\r
 /**\r
 /**\r
-  Check whether there is key pending in the keyboard buffer.\r
-\r
-  @param  UsbKeyboardDevice    The USB_KB_DEV instance.\r
-\r
-  @retval EFI_SUCCESS          There is pending key to read.\r
-  @retval EFI_NOT_READY        No pending key to read.\r
+  Timer handler to convert the key from USB.\r
 \r
 \r
+  @param  Event                    Indicates the event that invoke this function.\r
+  @param  Context                  Indicates the calling context.\r
 **/\r
 **/\r
-EFI_STATUS\r
+VOID\r
 EFIAPI\r
 EFIAPI\r
-USBKeyboardCheckForKey (\r
-  IN OUT  USB_KB_DEV    *UsbKeyboardDevice\r
+USBKeyboardTimerHandler (\r
+  IN  EFI_EVENT                 Event,\r
+  IN  VOID                      *Context\r
   )\r
 {\r
   )\r
 {\r
-  EFI_STATUS  Status;\r
-  UINT8       KeyCode;\r
+  EFI_STATUS                    Status;\r
+  USB_KB_DEV                    *UsbKeyboardDevice;\r
+  UINT8                         KeyCode;\r
+  EFI_KEY_DATA                  KeyData;\r
 \r
 \r
+  UsbKeyboardDevice = (USB_KB_DEV *) Context;\r
+  \r
   //\r
   // Fetch raw data from the USB keyboard buffer,\r
   // and translate it into USB keycode.\r
   //\r
   Status = USBParseKey (UsbKeyboardDevice, &KeyCode);\r
   if (EFI_ERROR (Status)) {\r
   //\r
   // Fetch raw data from the USB keyboard buffer,\r
   // and translate it into USB keycode.\r
   //\r
   Status = USBParseKey (UsbKeyboardDevice, &KeyCode);\r
   if (EFI_ERROR (Status)) {\r
-    return EFI_NOT_READY;\r
+    return ;\r
   }\r
 \r
   }\r
 \r
-  UsbKeyboardDevice->CurKeyCode = KeyCode;\r
-  return EFI_SUCCESS;\r
+  //\r
+  // Translate saved USB keycode into EFI_INPUT_KEY\r
+  //\r
+  Status = UsbKeyCodeToEfiInputKey (UsbKeyboardDevice, KeyCode, &KeyData);\r
+  if (EFI_ERROR (Status)) {\r
+    return ;\r
+  }\r
+\r
+  //\r
+  // Insert to the EFI Key queue\r
+  //\r
+  Enqueue (&UsbKeyboardDevice->EfiKeyQueue, &KeyData, sizeof (KeyData));\r
 }\r
 \r
 /**\r
 }\r
 \r
 /**\r
@@ -811,7 +767,6 @@ USBKeyboardCheckForKey (
 \r
 **/\r
 EFI_STATUS\r
 \r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 KbdFreeNotifyList (\r
   IN OUT LIST_ENTRY           *NotifyList\r
   )\r
 KbdFreeNotifyList (\r
   IN OUT LIST_ENTRY           *NotifyList\r
   )\r
@@ -843,7 +798,6 @@ KbdFreeNotifyList (
 \r
 **/\r
 BOOLEAN\r
 \r
 **/\r
 BOOLEAN\r
-EFIAPI\r
 IsKeyRegistered (\r
   IN EFI_KEY_DATA  *RegsiteredData,\r
   IN EFI_KEY_DATA  *InputData\r
 IsKeyRegistered (\r
   IN EFI_KEY_DATA  *RegsiteredData,\r
   IN EFI_KEY_DATA  *InputData\r
@@ -905,8 +859,6 @@ USBKeyboardResetEx (
 {\r
   EFI_STATUS                Status;\r
   USB_KB_DEV                *UsbKeyboardDevice;\r
 {\r
   EFI_STATUS                Status;\r
   USB_KB_DEV                *UsbKeyboardDevice;\r
-  EFI_TPL                   OldTpl;\r
-  \r
 \r
   UsbKeyboardDevice = TEXT_INPUT_EX_USB_KB_DEV_FROM_THIS (This);\r
 \r
 \r
   UsbKeyboardDevice = TEXT_INPUT_EX_USB_KB_DEV_FROM_THIS (This);\r
 \r
@@ -915,11 +867,6 @@ USBKeyboardResetEx (
     return EFI_DEVICE_ERROR;\r
   }\r
 \r
     return EFI_DEVICE_ERROR;\r
   }\r
 \r
-  OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
-  UsbKeyboardDevice->KeyState.KeyShiftState  = EFI_SHIFT_STATE_VALID;\r
-  UsbKeyboardDevice->KeyState.KeyToggleState = EFI_TOGGLE_STATE_VALID;\r
-  gBS->RestoreTPL (OldTpl);\r
-\r
   return EFI_SUCCESS;\r
 \r
 }\r
   return EFI_SUCCESS;\r
 \r
 }\r
@@ -986,8 +933,7 @@ USBKeyboardSetState (
 \r
   UsbKeyboardDevice = TEXT_INPUT_EX_USB_KB_DEV_FROM_THIS (This);\r
 \r
 \r
   UsbKeyboardDevice = TEXT_INPUT_EX_USB_KB_DEV_FROM_THIS (This);\r
 \r
-  if (((UsbKeyboardDevice->KeyState.KeyToggleState & EFI_TOGGLE_STATE_VALID) != EFI_TOGGLE_STATE_VALID) ||\r
-      ((*KeyToggleState & EFI_TOGGLE_STATE_VALID) != EFI_TOGGLE_STATE_VALID)) {\r
+  if ((*KeyToggleState & EFI_TOGGLE_STATE_VALID) != EFI_TOGGLE_STATE_VALID) {\r
     return EFI_UNSUPPORTED;\r
   }\r
 \r
     return EFI_UNSUPPORTED;\r
   }\r
 \r
@@ -1011,8 +957,6 @@ USBKeyboardSetState (
 \r
   SetKeyLED (UsbKeyboardDevice);\r
 \r
 \r
   SetKeyLED (UsbKeyboardDevice);\r
 \r
-  UsbKeyboardDevice->KeyState.KeyToggleState = *KeyToggleState;\r
-\r
   return EFI_SUCCESS;\r
   \r
 }\r
   return EFI_SUCCESS;\r
   \r
 }\r
index 99fbbcdab32270ca6df0ccec5942ea4925a57fcf..8a12d0fa3f43abffde817ffd8484c0f1885904cc 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Header file for USB Keyboard Driver's Data Structures.\r
 \r
 /** @file\r
   Header file for USB Keyboard Driver's Data Structures.\r
 \r
-Copyright (c) 2004 - 2008, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -39,6 +39,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include <IndustryStandard/Usb.h>\r
 \r
 \r
 #include <IndustryStandard/Usb.h>\r
 \r
+#define KEYBOARD_TIMER_INTERVAL         200000  // 0.02s\r
+\r
 #define MAX_KEY_ALLOWED     32\r
 \r
 #define HZ                  1000 * 1000 * 10\r
 #define MAX_KEY_ALLOWED     32\r
 \r
 #define HZ                  1000 * 1000 * 10\r
@@ -58,10 +60,11 @@ typedef struct {
 } USB_KEY;\r
 \r
 typedef struct {\r
 } USB_KEY;\r
 \r
 typedef struct {\r
-  USB_KEY Buffer[MAX_KEY_ALLOWED + 1];\r
-  UINT8   BufferHead;\r
-  UINT8   BufferTail;\r
-} USB_KB_BUFFER;\r
+  VOID          *Buffer[MAX_KEY_ALLOWED + 1];\r
+  UINTN         Head;\r
+  UINTN         Tail;\r
+  UINTN         ItemSize;\r
+} USB_SIMPLE_QUEUE;\r
 \r
 #define USB_KB_DEV_SIGNATURE  SIGNATURE_32 ('u', 'k', 'b', 'd')\r
 #define USB_KB_CONSOLE_IN_EX_NOTIFY_SIGNATURE SIGNATURE_32 ('u', 'k', 'b', 'x')\r
 \r
 #define USB_KB_DEV_SIGNATURE  SIGNATURE_32 ('u', 'k', 'b', 'd')\r
 #define USB_KB_CONSOLE_IN_EX_NOTIFY_SIGNATURE SIGNATURE_32 ('u', 'k', 'b', 'x')\r
@@ -109,7 +112,8 @@ typedef struct {
   EFI_USB_INTERFACE_DESCRIPTOR      InterfaceDescriptor;\r
   EFI_USB_ENDPOINT_DESCRIPTOR       IntEndpointDescriptor;\r
 \r
   EFI_USB_INTERFACE_DESCRIPTOR      InterfaceDescriptor;\r
   EFI_USB_ENDPOINT_DESCRIPTOR       IntEndpointDescriptor;\r
 \r
-  USB_KB_BUFFER                     KeyboardBuffer;\r
+  USB_SIMPLE_QUEUE                  UsbKeyQueue;\r
+  USB_SIMPLE_QUEUE                  EfiKeyQueue;\r
   BOOLEAN                           CtrlOn;\r
   BOOLEAN                           AltOn;\r
   BOOLEAN                           ShiftOn;\r
   BOOLEAN                           CtrlOn;\r
   BOOLEAN                           AltOn;\r
   BOOLEAN                           ShiftOn;\r
@@ -119,6 +123,8 @@ typedef struct {
   UINT8                             LastKeyCodeArray[8];\r
   UINT8                             CurKeyCode;\r
 \r
   UINT8                             LastKeyCodeArray[8];\r
   UINT8                             CurKeyCode;\r
 \r
+  EFI_EVENT                         TimerEvent;\r
+\r
   UINT8                             RepeatKey;\r
   EFI_EVENT                         RepeatTimer;\r
 \r
   UINT8                             RepeatKey;\r
   EFI_EVENT                         RepeatTimer;\r
 \r
@@ -135,8 +141,6 @@ typedef struct {
   BOOLEAN                           MenuKeyOn;\r
   BOOLEAN                           SysReqOn;\r
   BOOLEAN                           AltGrOn;\r
   BOOLEAN                           MenuKeyOn;\r
   BOOLEAN                           SysReqOn;\r
   BOOLEAN                           AltGrOn;\r
-\r
-  EFI_KEY_STATE                     KeyState;\r
   //\r
   // Notification function list\r
   //\r
   //\r
   // Notification function list\r
   //\r
@@ -555,26 +559,10 @@ USBKeyboardWaitForKey (
 \r
 **/\r
 EFI_STATUS\r
 \r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 KbdFreeNotifyList (\r
   IN OUT LIST_ENTRY           *NotifyList\r
   );\r
 \r
 KbdFreeNotifyList (\r
   IN OUT LIST_ENTRY           *NotifyList\r
   );\r
 \r
-/**\r
-  Check whether there is key pending in the keyboard buffer.\r
-\r
-  @param  UsbKeyboardDevice    The USB_KB_DEV instance.\r
-\r
-  @retval EFI_SUCCESS          There is pending key to read.\r
-  @retval EFI_NOT_READY        No pending key to read.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-USBKeyboardCheckForKey (\r
-  IN OUT  USB_KB_DEV    *UsbKeyboardDevice\r
-  );\r
-\r
 /**\r
   Check whether the pressed key matches a registered key or not.\r
 \r
 /**\r
   Check whether the pressed key matches a registered key or not.\r
 \r
@@ -586,11 +574,23 @@ USBKeyboardCheckForKey (
 \r
 **/\r
 BOOLEAN\r
 \r
 **/\r
 BOOLEAN\r
-EFIAPI\r
 IsKeyRegistered (\r
   IN EFI_KEY_DATA  *RegsiteredData,\r
   IN EFI_KEY_DATA  *InputData\r
   );\r
 \r
 IsKeyRegistered (\r
   IN EFI_KEY_DATA  *RegsiteredData,\r
   IN EFI_KEY_DATA  *InputData\r
   );\r
 \r
+/**\r
+  Timer handler to convert the key from USB.\r
+\r
+  @param  Event                    Indicates the event that invoke this function.\r
+  @param  Context                  Indicates the calling context.\r
+**/\r
+VOID\r
+EFIAPI\r
+USBKeyboardTimerHandler (\r
+  IN  EFI_EVENT                 Event,\r
+  IN  VOID                      *Context\r
+  );\r
+\r
 #endif\r
 \r
 #endif\r
 \r
index ad39b2e52e4a0c68a6901701316fedb110cb4852..a205da09a3493279905e24a36fb5a398fff17b37 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Helper functions for USB Keyboard Driver.\r
 \r
 /** @file\r
   Helper functions for USB Keyboard Driver.\r
 \r
-Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -310,7 +310,6 @@ UINT8 ModifierValueToEfiScanCodeConvertionTable[] = {
   @retval Others               Failure to install default keyboard layout.\r
 **/\r
 EFI_STATUS\r
   @retval Others               Failure to install default keyboard layout.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 InstallDefaultKeyboardLayout (\r
    IN OUT USB_KB_DEV           *UsbKeyboardDevice\r
   )\r
 InstallDefaultKeyboardLayout (\r
    IN OUT USB_KB_DEV           *UsbKeyboardDevice\r
   )\r
@@ -363,7 +362,6 @@ InstallDefaultKeyboardLayout (
 \r
 **/\r
 BOOLEAN\r
 \r
 **/\r
 BOOLEAN\r
-EFIAPI\r
 IsUSBKeyboard (\r
   IN  EFI_USB_IO_PROTOCOL       *UsbIo\r
   )\r
 IsUSBKeyboard (\r
   IN  EFI_USB_IO_PROTOCOL       *UsbIo\r
   )\r
@@ -401,7 +399,6 @@ IsUSBKeyboard (
 \r
 **/\r
 EFI_HII_KEYBOARD_LAYOUT *\r
 \r
 **/\r
 EFI_HII_KEYBOARD_LAYOUT *\r
-EFIAPI\r
 GetCurrentKeyboardLayout (\r
   VOID\r
   )\r
 GetCurrentKeyboardLayout (\r
   VOID\r
   )\r
@@ -464,7 +461,6 @@ GetCurrentKeyboardLayout (
 \r
 **/\r
 EFI_KEY_DESCRIPTOR *\r
 \r
 **/\r
 EFI_KEY_DESCRIPTOR *\r
-EFIAPI\r
 GetKeyDescriptor (\r
   IN USB_KB_DEV        *UsbKeyboardDevice,\r
   IN UINT8             KeyCode\r
 GetKeyDescriptor (\r
   IN USB_KB_DEV        *UsbKeyboardDevice,\r
   IN UINT8             KeyCode\r
@@ -502,7 +498,6 @@ GetKeyDescriptor (
 \r
 **/\r
 USB_NS_KEY *\r
 \r
 **/\r
 USB_NS_KEY *\r
-EFIAPI\r
 FindUsbNsKey (\r
   IN USB_KB_DEV          *UsbKeyboardDevice,\r
   IN EFI_KEY_DESCRIPTOR  *KeyDescriptor\r
 FindUsbNsKey (\r
   IN USB_KB_DEV          *UsbKeyboardDevice,\r
   IN EFI_KEY_DESCRIPTOR  *KeyDescriptor\r
@@ -543,7 +538,6 @@ FindUsbNsKey (
 \r
 **/\r
 EFI_KEY_DESCRIPTOR *\r
 \r
 **/\r
 EFI_KEY_DESCRIPTOR *\r
-EFIAPI\r
 FindPhysicalKey (\r
   IN USB_NS_KEY          *UsbNsKey,\r
   IN EFI_KEY_DESCRIPTOR  *KeyDescriptor\r
 FindPhysicalKey (\r
   IN USB_NS_KEY          *UsbNsKey,\r
   IN EFI_KEY_DESCRIPTOR  *KeyDescriptor\r
@@ -646,7 +640,7 @@ SetKeyboardLayoutEvent (
       //\r
       KeyCount = 0;\r
       NsKey = KeyDescriptor + 1;\r
       //\r
       KeyCount = 0;\r
       NsKey = KeyDescriptor + 1;\r
-      for (Index2 = Index + 1; Index2 < KeyboardLayout->DescriptorCount; Index2++) {\r
+      for (Index2 = (UINT8) Index + 1; Index2 < KeyboardLayout->DescriptorCount; Index2++) {\r
         CopyMem (&TempKey, NsKey, sizeof (EFI_KEY_DESCRIPTOR));\r
         if (TempKey.Modifier == EFI_NS_KEY_DEPENDENCY_MODIFIER) {\r
           KeyCount++;\r
         CopyMem (&TempKey, NsKey, sizeof (EFI_KEY_DESCRIPTOR));\r
         if (TempKey.Modifier == EFI_NS_KEY_DEPENDENCY_MODIFIER) {\r
           KeyCount++;\r
@@ -691,7 +685,6 @@ SetKeyboardLayoutEvent (
 \r
 **/\r
 VOID\r
 \r
 **/\r
 VOID\r
-EFIAPI\r
 ReleaseKeyboardLayoutResources (\r
   IN OUT USB_KB_DEV              *UsbKeyboardDevice\r
   )\r
 ReleaseKeyboardLayoutResources (\r
   IN OUT USB_KB_DEV              *UsbKeyboardDevice\r
   )\r
@@ -730,7 +723,6 @@ ReleaseKeyboardLayoutResources (
 \r
 **/\r
 EFI_STATUS\r
 \r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 InitKeyboardLayout (\r
   OUT USB_KB_DEV   *UsbKeyboardDevice\r
   )\r
 InitKeyboardLayout (\r
   OUT USB_KB_DEV   *UsbKeyboardDevice\r
   )\r
@@ -797,7 +789,6 @@ InitKeyboardLayout (
 \r
 **/\r
 EFI_STATUS\r
 \r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 InitUSBKeyboard (\r
   IN OUT USB_KB_DEV   *UsbKeyboardDevice\r
   )\r
 InitUSBKeyboard (\r
   IN OUT USB_KB_DEV   *UsbKeyboardDevice\r
   )\r
@@ -815,7 +806,8 @@ InitUSBKeyboard (
     UsbKeyboardDevice->DevicePath\r
     );\r
 \r
     UsbKeyboardDevice->DevicePath\r
     );\r
 \r
-  InitUSBKeyBuffer (&(UsbKeyboardDevice->KeyboardBuffer));\r
+  InitQueue (&UsbKeyboardDevice->UsbKeyQueue, sizeof (USB_KEY));\r
+  InitQueue (&UsbKeyboardDevice->EfiKeyQueue, sizeof (EFI_KEY_DATA));\r
 \r
   //\r
   // Use the config out of the descriptor\r
 \r
   //\r
   // Use the config out of the descriptor\r
@@ -986,12 +978,10 @@ KeyboardHandler (
   UINT8               CurModifierMap;\r
   UINT8               OldModifierMap;\r
   UINT8               Mask;\r
   UINT8               CurModifierMap;\r
   UINT8               OldModifierMap;\r
   UINT8               Mask;\r
-  UINT8               Index;\r
+  UINTN               Index;\r
   UINT8               Index2;\r
   UINT8               Index2;\r
-  BOOLEAN             Down;\r
   BOOLEAN             KeyRelease;\r
   BOOLEAN             KeyPress;\r
   BOOLEAN             KeyRelease;\r
   BOOLEAN             KeyPress;\r
-  UINT8               SavedTail;\r
   USB_KEY             UsbKey;\r
   UINT8               NewRepeatKey;\r
   UINT32              UsbStatus;\r
   USB_KEY             UsbKey;\r
   UINT8               NewRepeatKey;\r
   UINT32              UsbStatus;\r
@@ -1119,8 +1109,9 @@ KeyboardHandler (
       // otherwise it is a non-zero value.\r
       // Insert the changed modifier key into key buffer.\r
       //\r
       // otherwise it is a non-zero value.\r
       // Insert the changed modifier key into key buffer.\r
       //\r
-      Down = (BOOLEAN) ((CurModifierMap & Mask) != 0);\r
-      InsertKeyCode (&(UsbKeyboardDevice->KeyboardBuffer), (UINT8) (0xe0 + Index), Down);\r
+      UsbKey.KeyCode = (UINT8) (0xe0 + Index);\r
+      UsbKey.Down    = (BOOLEAN) ((CurModifierMap & Mask) != 0);\r
+      Enqueue (&UsbKeyboardDevice->UsbKeyQueue, &UsbKey, sizeof (UsbKey));\r
     }\r
   }\r
 \r
     }\r
   }\r
 \r
@@ -1152,11 +1143,9 @@ KeyboardHandler (
     }\r
 \r
     if (KeyRelease) {\r
     }\r
 \r
     if (KeyRelease) {\r
-      InsertKeyCode (\r
-        &(UsbKeyboardDevice->KeyboardBuffer),\r
-        OldKeyCodeBuffer[Index],\r
-        FALSE\r
-        );\r
+      UsbKey.KeyCode = OldKeyCodeBuffer[Index];\r
+      UsbKey.Down    = FALSE;\r
+      Enqueue (&UsbKeyboardDevice->UsbKeyQueue, &UsbKey, sizeof (UsbKey));\r
       //\r
       // The original repeat key is released.\r
       //\r
       //\r
       // The original repeat key is released.\r
       //\r
@@ -1204,7 +1193,9 @@ KeyboardHandler (
     }\r
 \r
     if (KeyPress) {\r
     }\r
 \r
     if (KeyPress) {\r
-      InsertKeyCode (&(UsbKeyboardDevice->KeyboardBuffer), CurKeyCodeBuffer[Index], TRUE);\r
+      UsbKey.KeyCode = CurKeyCodeBuffer[Index];\r
+      UsbKey.Down    = TRUE;\r
+      Enqueue (&UsbKeyboardDevice->UsbKeyQueue, &UsbKey, sizeof (UsbKey));\r
 \r
       //\r
       // Handle repeat key\r
 \r
       //\r
       // Handle repeat key\r
@@ -1234,72 +1225,6 @@ KeyboardHandler (
     UsbKeyboardDevice->LastKeyCodeArray[Index] = CurKeyCodeBuffer[Index];\r
   }\r
 \r
     UsbKeyboardDevice->LastKeyCodeArray[Index] = CurKeyCodeBuffer[Index];\r
   }\r
 \r
-  //\r
-  // Pre-process KeyboardBuffer to check if Ctrl + Alt + Del is pressed.\r
-  //\r
-  SavedTail = UsbKeyboardDevice->KeyboardBuffer.BufferTail;\r
-  Index     = UsbKeyboardDevice->KeyboardBuffer.BufferHead;\r
-  while (Index != SavedTail) {\r
-    RemoveKeyCode (&(UsbKeyboardDevice->KeyboardBuffer), &UsbKey);\r
-\r
-    KeyDescriptor = GetKeyDescriptor (UsbKeyboardDevice, UsbKey.KeyCode);\r
-    ASSERT (KeyDescriptor != NULL);\r
-\r
-    switch (KeyDescriptor->Modifier) {\r
-\r
-    case EFI_LEFT_CONTROL_MODIFIER:\r
-    case EFI_RIGHT_CONTROL_MODIFIER:\r
-      if (UsbKey.Down) {\r
-        UsbKeyboardDevice->CtrlOn = TRUE;\r
-      } else {\r
-        UsbKeyboardDevice->CtrlOn = FALSE;\r
-      }\r
-      break;\r
-\r
-    case EFI_LEFT_ALT_MODIFIER:\r
-    case EFI_RIGHT_ALT_MODIFIER:\r
-      if (UsbKey.Down) {\r
-        UsbKeyboardDevice->AltOn = TRUE;\r
-      } else {\r
-        UsbKeyboardDevice->AltOn = FALSE;\r
-      }\r
-      break;\r
-\r
-    case EFI_ALT_GR_MODIFIER:\r
-      if (UsbKey.Down) {\r
-        UsbKeyboardDevice->AltGrOn = TRUE;\r
-      } else {\r
-        UsbKeyboardDevice->AltGrOn = FALSE;\r
-      }\r
-      break;\r
-\r
-    //\r
-    // For Del Key, check if Ctrl + Alt + Del occurs for reset.\r
-    //\r
-    case EFI_DELETE_MODIFIER:\r
-      if (UsbKey.Down) {\r
-        if ((UsbKeyboardDevice->CtrlOn) && (UsbKeyboardDevice->AltOn)) {\r
-          gRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL);\r
-        }\r
-      }\r
-      break;\r
-\r
-    default:\r
-      break;\r
-    }\r
-\r
-    //\r
-    // Insert the key back to the buffer,\r
-    // so the key sequence will not be destroyed.\r
-    //\r
-    InsertKeyCode (\r
-      &(UsbKeyboardDevice->KeyboardBuffer),\r
-      UsbKey.KeyCode,\r
-      UsbKey.Down\r
-      );\r
-    Index = UsbKeyboardDevice->KeyboardBuffer.BufferHead;\r
-\r
-  }\r
   //\r
   // If there is new key pressed, update the RepeatKey value, and set the\r
   // timer to repeate delay timer\r
   //\r
   // If there is new key pressed, update the RepeatKey value, and set the\r
   // timer to repeate delay timer\r
@@ -1336,7 +1261,6 @@ KeyboardHandler (
 \r
 **/\r
 EFI_STATUS\r
 \r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 USBParseKey (\r
   IN OUT  USB_KB_DEV  *UsbKeyboardDevice,\r
      OUT  UINT8       *KeyCode\r
 USBParseKey (\r
   IN OUT  USB_KB_DEV  *UsbKeyboardDevice,\r
      OUT  UINT8       *KeyCode\r
@@ -1347,11 +1271,11 @@ USBParseKey (
 \r
   *KeyCode = 0;\r
 \r
 \r
   *KeyCode = 0;\r
 \r
-  while (!IsUSBKeyboardBufferEmpty (&UsbKeyboardDevice->KeyboardBuffer)) {\r
+  while (!IsQueueEmpty (&UsbKeyboardDevice->UsbKeyQueue)) {\r
     //\r
     // Pops one raw data off.\r
     //\r
     //\r
     // Pops one raw data off.\r
     //\r
-    RemoveKeyCode (&(UsbKeyboardDevice->KeyboardBuffer), &UsbKey);\r
+    Dequeue (&UsbKeyboardDevice->UsbKeyQueue, &UsbKey, sizeof (UsbKey));\r
 \r
     KeyDescriptor = GetKeyDescriptor (UsbKeyboardDevice, UsbKey.KeyCode);\r
     ASSERT (KeyDescriptor != NULL);\r
 \r
     KeyDescriptor = GetKeyDescriptor (UsbKeyboardDevice, UsbKey.KeyCode);\r
     ASSERT (KeyDescriptor != NULL);\r
@@ -1589,7 +1513,7 @@ USBParseKey (
 \r
   @param  UsbKeyboardDevice     The USB_KB_DEV instance.\r
   @param  KeyCode               Indicates the key code that will be interpreted.\r
 \r
   @param  UsbKeyboardDevice     The USB_KB_DEV instance.\r
   @param  KeyCode               Indicates the key code that will be interpreted.\r
-  @param  Key                   A pointer to a buffer that is filled in with\r
+  @param  KeyData               A pointer to a buffer that is filled in with\r
                                 the keystroke information for the key that\r
                                 was pressed.\r
 \r
                                 the keystroke information for the key that\r
                                 was pressed.\r
 \r
@@ -1601,14 +1525,16 @@ USBParseKey (
 \r
 **/\r
 EFI_STATUS\r
 \r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 UsbKeyCodeToEfiInputKey (\r
 UsbKeyCodeToEfiInputKey (\r
-  IN  USB_KB_DEV      *UsbKeyboardDevice,\r
-  IN  UINT8           KeyCode,\r
-  OUT EFI_INPUT_KEY   *Key\r
+  IN  USB_KB_DEV                *UsbKeyboardDevice,\r
+  IN  UINT8                     KeyCode,\r
+  OUT EFI_KEY_DATA              *KeyData\r
   )\r
 {\r
   )\r
 {\r
-  EFI_KEY_DESCRIPTOR  *KeyDescriptor;\r
+  EFI_KEY_DESCRIPTOR            *KeyDescriptor;\r
+  LIST_ENTRY                    *Link;\r
+  LIST_ENTRY                    *NotifyList;\r
+  KEYBOARD_CONSOLE_IN_EX_NOTIFY *CurrentNotify;  \r
 \r
   //\r
   // KeyCode must in the range of 0x4 to 0x65\r
 \r
   //\r
   // KeyCode must in the range of 0x4 to 0x65\r
@@ -1647,12 +1573,12 @@ UsbKeyCodeToEfiInputKey (
     return EFI_DEVICE_ERROR;\r
   }\r
 \r
     return EFI_DEVICE_ERROR;\r
   }\r
 \r
-  Key->ScanCode = ModifierValueToEfiScanCodeConvertionTable[KeyDescriptor->Modifier];\r
-  Key->UnicodeChar = KeyDescriptor->Unicode;\r
+  KeyData->Key.ScanCode    = ModifierValueToEfiScanCodeConvertionTable[KeyDescriptor->Modifier];\r
+  KeyData->Key.UnicodeChar = KeyDescriptor->Unicode;\r
 \r
   if ((KeyDescriptor->AffectedAttribute & EFI_AFFECTED_BY_STANDARD_SHIFT)!= 0) {\r
     if (UsbKeyboardDevice->ShiftOn) {\r
 \r
   if ((KeyDescriptor->AffectedAttribute & EFI_AFFECTED_BY_STANDARD_SHIFT)!= 0) {\r
     if (UsbKeyboardDevice->ShiftOn) {\r
-      Key->UnicodeChar = KeyDescriptor->ShiftedUnicode;\r
+      KeyData->Key.UnicodeChar = KeyDescriptor->ShiftedUnicode;\r
 \r
       //\r
       // Need not return associated shift state if a class of printable characters that\r
 \r
       //\r
       // Need not return associated shift state if a class of printable characters that\r
@@ -1664,42 +1590,30 @@ UsbKeyCodeToEfiInputKey (
       }\r
 \r
       if (UsbKeyboardDevice->AltGrOn) {\r
       }\r
 \r
       if (UsbKeyboardDevice->AltGrOn) {\r
-        Key->UnicodeChar = KeyDescriptor->ShiftedAltGrUnicode;\r
+        KeyData->Key.UnicodeChar = KeyDescriptor->ShiftedAltGrUnicode;\r
       }\r
     } else {\r
       //\r
       // Shift off\r
       //\r
       }\r
     } else {\r
       //\r
       // Shift off\r
       //\r
-      Key->UnicodeChar = KeyDescriptor->Unicode;\r
+      KeyData->Key.UnicodeChar = KeyDescriptor->Unicode;\r
 \r
       if (UsbKeyboardDevice->AltGrOn) {\r
 \r
       if (UsbKeyboardDevice->AltGrOn) {\r
-        Key->UnicodeChar = KeyDescriptor->AltGrUnicode;\r
+        KeyData->Key.UnicodeChar = KeyDescriptor->AltGrUnicode;\r
       }\r
     }\r
   }\r
 \r
   if ((KeyDescriptor->AffectedAttribute & EFI_AFFECTED_BY_CAPS_LOCK) != 0) {\r
     if (UsbKeyboardDevice->CapsOn) {\r
       }\r
     }\r
   }\r
 \r
   if ((KeyDescriptor->AffectedAttribute & EFI_AFFECTED_BY_CAPS_LOCK) != 0) {\r
     if (UsbKeyboardDevice->CapsOn) {\r
-      if (Key->UnicodeChar == KeyDescriptor->Unicode) {\r
-        Key->UnicodeChar = KeyDescriptor->ShiftedUnicode;\r
-      } else if (Key->UnicodeChar == KeyDescriptor->ShiftedUnicode) {\r
-        Key->UnicodeChar = KeyDescriptor->Unicode;\r
+      if (KeyData->Key.UnicodeChar == KeyDescriptor->Unicode) {\r
+        KeyData->Key.UnicodeChar = KeyDescriptor->ShiftedUnicode;\r
+      } else if (KeyData->Key.UnicodeChar == KeyDescriptor->ShiftedUnicode) {\r
+        KeyData->Key.UnicodeChar = KeyDescriptor->Unicode;\r
       }\r
     }\r
   }\r
 \r
       }\r
     }\r
   }\r
 \r
-  //\r
-  // Translate the CTRL-Alpha characters to their corresponding control value\r
-  // (ctrl-a = 0x0001 through ctrl-Z = 0x001A)\r
-  //\r
-  if (UsbKeyboardDevice->CtrlOn) {\r
-    if (Key->UnicodeChar >= 'a' && Key->UnicodeChar <= 'z') {\r
-      Key->UnicodeChar = (UINT8) (Key->UnicodeChar - 'a' + 1);\r
-    } else if (Key->UnicodeChar >= 'A' && Key->UnicodeChar <= 'Z') {\r
-      Key->UnicodeChar = (UINT8) (Key->UnicodeChar - 'A' + 1);\r
-    }\r
-  }\r
-\r
   if ((KeyDescriptor->AffectedAttribute & EFI_AFFECTED_BY_NUM_LOCK) != 0) {\r
     //\r
     // For key affected by NumLock, if NumLock is on and Shift is not pressed, then it means\r
   if ((KeyDescriptor->AffectedAttribute & EFI_AFFECTED_BY_NUM_LOCK) != 0) {\r
     //\r
     // For key affected by NumLock, if NumLock is on and Shift is not pressed, then it means\r
@@ -1707,205 +1621,247 @@ UsbKeyCodeToEfiInputKey (
     // Otherwise, it means control key, so preserve the EFI Scan Code and clear the unicode keycode.\r
     //\r
     if ((UsbKeyboardDevice->NumLockOn) && (!(UsbKeyboardDevice->ShiftOn))) {\r
     // Otherwise, it means control key, so preserve the EFI Scan Code and clear the unicode keycode.\r
     //\r
     if ((UsbKeyboardDevice->NumLockOn) && (!(UsbKeyboardDevice->ShiftOn))) {\r
-      Key->ScanCode = SCAN_NULL;\r
+      KeyData->Key.ScanCode = SCAN_NULL;\r
     } else {\r
     } else {\r
-      Key->UnicodeChar = 0x00;\r
+      KeyData->Key.UnicodeChar = 0x00;\r
     }\r
   }\r
 \r
   //\r
   // Translate Unicode 0x1B (ESC) to EFI Scan Code\r
   //\r
     }\r
   }\r
 \r
   //\r
   // Translate Unicode 0x1B (ESC) to EFI Scan Code\r
   //\r
-  if (Key->UnicodeChar == 0x1B && Key->ScanCode == SCAN_NULL) {\r
-    Key->ScanCode = SCAN_ESC;\r
-    Key->UnicodeChar = 0x00;\r
+  if (KeyData->Key.UnicodeChar == 0x1B && KeyData->Key.ScanCode == SCAN_NULL) {\r
+    KeyData->Key.ScanCode = SCAN_ESC;\r
+    KeyData->Key.UnicodeChar = 0x00;\r
   }\r
 \r
   //\r
   // Not valid for key without both unicode key code and EFI Scan Code.\r
   //\r
   }\r
 \r
   //\r
   // Not valid for key without both unicode key code and EFI Scan Code.\r
   //\r
-  if (Key->UnicodeChar == 0 && Key->ScanCode == SCAN_NULL) {\r
+  if (KeyData->Key.UnicodeChar == 0 && KeyData->Key.ScanCode == SCAN_NULL) {\r
     return EFI_NOT_READY;\r
   }\r
 \r
     return EFI_NOT_READY;\r
   }\r
 \r
-\r
   //\r
   // Save Shift/Toggle state\r
   //\r
   //\r
   // Save Shift/Toggle state\r
   //\r
+  KeyData->KeyState.KeyShiftState  = EFI_SHIFT_STATE_VALID;\r
+  KeyData->KeyState.KeyToggleState = EFI_TOGGLE_STATE_VALID;\r
+\r
   if (UsbKeyboardDevice->LeftCtrlOn) {\r
   if (UsbKeyboardDevice->LeftCtrlOn) {\r
-    UsbKeyboardDevice->KeyState.KeyShiftState |= EFI_LEFT_CONTROL_PRESSED;\r
+    KeyData->KeyState.KeyShiftState |= EFI_LEFT_CONTROL_PRESSED;\r
   }\r
   if (UsbKeyboardDevice->RightCtrlOn) {\r
   }\r
   if (UsbKeyboardDevice->RightCtrlOn) {\r
-    UsbKeyboardDevice->KeyState.KeyShiftState |= EFI_RIGHT_CONTROL_PRESSED;\r
+    KeyData->KeyState.KeyShiftState |= EFI_RIGHT_CONTROL_PRESSED;\r
   }\r
   if (UsbKeyboardDevice->LeftAltOn) {\r
   }\r
   if (UsbKeyboardDevice->LeftAltOn) {\r
-    UsbKeyboardDevice->KeyState.KeyShiftState |= EFI_LEFT_ALT_PRESSED;\r
+    KeyData->KeyState.KeyShiftState |= EFI_LEFT_ALT_PRESSED;\r
   }\r
   if (UsbKeyboardDevice->RightAltOn) {\r
   }\r
   if (UsbKeyboardDevice->RightAltOn) {\r
-    UsbKeyboardDevice->KeyState.KeyShiftState |= EFI_RIGHT_ALT_PRESSED;\r
+    KeyData->KeyState.KeyShiftState |= EFI_RIGHT_ALT_PRESSED;\r
   }\r
   if (UsbKeyboardDevice->LeftShiftOn) {\r
   }\r
   if (UsbKeyboardDevice->LeftShiftOn) {\r
-    UsbKeyboardDevice->KeyState.KeyShiftState |= EFI_LEFT_SHIFT_PRESSED;\r
+    KeyData->KeyState.KeyShiftState |= EFI_LEFT_SHIFT_PRESSED;\r
   }\r
   if (UsbKeyboardDevice->RightShiftOn) {\r
   }\r
   if (UsbKeyboardDevice->RightShiftOn) {\r
-    UsbKeyboardDevice->KeyState.KeyShiftState |= EFI_RIGHT_SHIFT_PRESSED;\r
+    KeyData->KeyState.KeyShiftState |= EFI_RIGHT_SHIFT_PRESSED;\r
   }\r
   if (UsbKeyboardDevice->LeftLogoOn) {\r
   }\r
   if (UsbKeyboardDevice->LeftLogoOn) {\r
-    UsbKeyboardDevice->KeyState.KeyShiftState |= EFI_LEFT_LOGO_PRESSED;\r
+    KeyData->KeyState.KeyShiftState |= EFI_LEFT_LOGO_PRESSED;\r
   }\r
   if (UsbKeyboardDevice->RightLogoOn) {\r
   }\r
   if (UsbKeyboardDevice->RightLogoOn) {\r
-    UsbKeyboardDevice->KeyState.KeyShiftState |= EFI_RIGHT_LOGO_PRESSED;\r
+    KeyData->KeyState.KeyShiftState |= EFI_RIGHT_LOGO_PRESSED;\r
   }\r
   if (UsbKeyboardDevice->MenuKeyOn) {\r
   }\r
   if (UsbKeyboardDevice->MenuKeyOn) {\r
-    UsbKeyboardDevice->KeyState.KeyShiftState |= EFI_MENU_KEY_PRESSED;\r
+    KeyData->KeyState.KeyShiftState |= EFI_MENU_KEY_PRESSED;\r
   }\r
   if (UsbKeyboardDevice->SysReqOn) {\r
   }\r
   if (UsbKeyboardDevice->SysReqOn) {\r
-    UsbKeyboardDevice->KeyState.KeyShiftState |= EFI_SYS_REQ_PRESSED;\r
+    KeyData->KeyState.KeyShiftState |= EFI_SYS_REQ_PRESSED;\r
   }\r
 \r
   if (UsbKeyboardDevice->ScrollOn) {\r
   }\r
 \r
   if (UsbKeyboardDevice->ScrollOn) {\r
-    UsbKeyboardDevice->KeyState.KeyToggleState |= EFI_SCROLL_LOCK_ACTIVE;\r
+    KeyData->KeyState.KeyToggleState |= EFI_SCROLL_LOCK_ACTIVE;\r
   }\r
   if (UsbKeyboardDevice->NumLockOn) {\r
   }\r
   if (UsbKeyboardDevice->NumLockOn) {\r
-    UsbKeyboardDevice->KeyState.KeyToggleState |= EFI_NUM_LOCK_ACTIVE;\r
+    KeyData->KeyState.KeyToggleState |= EFI_NUM_LOCK_ACTIVE;\r
   }\r
   if (UsbKeyboardDevice->CapsOn) {\r
   }\r
   if (UsbKeyboardDevice->CapsOn) {\r
-    UsbKeyboardDevice->KeyState.KeyToggleState |= EFI_CAPS_LOCK_ACTIVE;\r
+    KeyData->KeyState.KeyToggleState |= EFI_CAPS_LOCK_ACTIVE;\r
   }\r
 \r
   }\r
 \r
-  return EFI_SUCCESS;\r
+  //\r
+  // Invoke notification functions if the key is registered.\r
+  //\r
+  NotifyList = &UsbKeyboardDevice->NotifyList;\r
+  for (Link = GetFirstNode (NotifyList); !IsNull (NotifyList, Link); Link = GetNextNode (NotifyList, Link)) {\r
+    CurrentNotify = CR (Link, KEYBOARD_CONSOLE_IN_EX_NOTIFY, NotifyEntry, USB_KB_CONSOLE_IN_EX_NOTIFY_SIGNATURE);\r
+    if (IsKeyRegistered (&CurrentNotify->KeyData, KeyData)) { \r
+      CurrentNotify->KeyNotificationFn (KeyData);\r
+    }\r
+  }\r
+\r
+  //\r
+  // Translate the CTRL-Alpha characters to their corresponding control value\r
+  // (ctrl-a = 0x0001 through ctrl-Z = 0x001A)\r
+  //\r
+  if (UsbKeyboardDevice->CtrlOn) {\r
+    if (KeyData->Key.UnicodeChar >= 'a' && KeyData->Key.UnicodeChar <= 'z') {\r
+      KeyData->Key.UnicodeChar = (UINT8) (KeyData->Key.UnicodeChar - 'a' + 1);\r
+    } else if (KeyData->Key.UnicodeChar >= 'A' && KeyData->Key.UnicodeChar <= 'Z') {\r
+      KeyData->Key.UnicodeChar = (UINT8) (KeyData->Key.UnicodeChar - 'A' + 1);\r
+    }\r
+  }\r
 \r
 \r
+  return EFI_SUCCESS;\r
 }\r
 \r
 \r
 /**\r
 }\r
 \r
 \r
 /**\r
-  Resets USB keyboard buffer.\r
+  Create the queue.\r
 \r
 \r
-  @param  KeyboardBuffer     Points to the USB keyboard buffer.\r
+  @param  Queue     Points to the queue.\r
+  @param  ItemSize  Size of the single item.\r
 \r
 **/\r
 VOID\r
 \r
 **/\r
 VOID\r
-EFIAPI\r
-InitUSBKeyBuffer (\r
-  OUT  USB_KB_BUFFER   *KeyboardBuffer\r
+InitQueue (\r
+  IN OUT  USB_SIMPLE_QUEUE   *Queue,\r
+  IN      UINTN              ItemSize\r
   )\r
 {\r
   )\r
 {\r
-  ZeroMem (KeyboardBuffer, sizeof (USB_KB_BUFFER));\r
+  UINTN                      Index;\r
 \r
 \r
-  KeyboardBuffer->BufferHead = KeyboardBuffer->BufferTail;\r
+  Queue->ItemSize  = ItemSize;\r
+  Queue->Head      = 0;\r
+  Queue->Tail      = 0;\r
+\r
+  if (Queue->Buffer[0] != NULL) {\r
+    FreePool (Queue->Buffer[0]);\r
+  }\r
+\r
+  Queue->Buffer[0] = AllocatePool (sizeof (Queue->Buffer) / sizeof (Queue->Buffer[0]) * ItemSize);\r
+  ASSERT (Queue->Buffer[0] != NULL);\r
+\r
+  for (Index = 1; Index < sizeof (Queue->Buffer) / sizeof (Queue->Buffer[0]); Index++) {\r
+    Queue->Buffer[Index] = ((UINT8 *) Queue->Buffer[Index - 1]) + ItemSize;\r
+  }\r
+}\r
+\r
+/**\r
+  Destroy the queue\r
+\r
+  @param Queue    Points to the queue.\r
+**/\r
+VOID\r
+DestroyQueue (\r
+  IN OUT USB_SIMPLE_QUEUE   *Queue\r
+  )\r
+{\r
+  FreePool (Queue->Buffer[0]);\r
 }\r
 \r
 \r
 /**\r
 }\r
 \r
 \r
 /**\r
-  Check whether USB keyboard buffer is empty.\r
+  Check whether the queue is empty.\r
 \r
 \r
-  @param  KeyboardBuffer     USB keyboard buffer\r
+  @param  Queue     Points to the queue.\r
 \r
 \r
-  @retval TRUE               Keyboard buffer is empty.\r
-  @retval FALSE              Keyboard buffer is not empty.\r
+  @retval TRUE      Queue is empty.\r
+  @retval FALSE     Queue is not empty.\r
 \r
 **/\r
 BOOLEAN\r
 \r
 **/\r
 BOOLEAN\r
-EFIAPI\r
-IsUSBKeyboardBufferEmpty (\r
-  IN  USB_KB_BUFFER   *KeyboardBuffer\r
+IsQueueEmpty (\r
+  IN  USB_SIMPLE_QUEUE   *Queue\r
   )\r
 {\r
   //\r
   // Meet FIFO empty condition\r
   //\r
   )\r
 {\r
   //\r
   // Meet FIFO empty condition\r
   //\r
-  return (BOOLEAN) (KeyboardBuffer->BufferHead == KeyboardBuffer->BufferTail);\r
+  return (BOOLEAN) (Queue->Head == Queue->Tail);\r
 }\r
 \r
 \r
 /**\r
 }\r
 \r
 \r
 /**\r
-  Check whether USB keyboard buffer is full.\r
+  Check whether the queue is full.\r
 \r
 \r
-  @param  KeyboardBuffer     USB keyboard buffer\r
+  @param  Queue     Points to the queue.\r
 \r
 \r
-  @retval TRUE               Keyboard buffer is full.\r
-  @retval FALSE              Keyboard buffer is not full.\r
+  @retval TRUE      Queue is full.\r
+  @retval FALSE     Queue is not full.\r
 \r
 **/\r
 BOOLEAN\r
 \r
 **/\r
 BOOLEAN\r
-EFIAPI\r
-IsUSBKeyboardBufferFull (\r
-  IN  USB_KB_BUFFER   *KeyboardBuffer\r
+IsQueueFull (\r
+  IN  USB_SIMPLE_QUEUE   *Queue\r
   )\r
 {\r
   )\r
 {\r
-  return (BOOLEAN)(((KeyboardBuffer->BufferTail + 1) % (MAX_KEY_ALLOWED + 1)) == KeyboardBuffer->BufferHead);\r
+  return (BOOLEAN) (((Queue->Tail + 1) % (MAX_KEY_ALLOWED + 1)) == Queue->Head);\r
 }\r
 \r
 \r
 /**\r
 }\r
 \r
 \r
 /**\r
-  Inserts a keycode into keyboard buffer.\r
-\r
-  @param  KeyboardBuffer     Points to the USB keyboard buffer.\r
-  @param  Key                Keycode to insert.\r
-  @param  Down               TRUE means key is pressed.\r
-                             FALSE means key is released.\r
+  Enqueue the item to the queue.\r
 \r
 \r
+  @param  Queue     Points to the queue.\r
+  @param  Item      Points to the item to be enqueued.\r
+  @param  ItemSize  Size of the item.\r
 **/\r
 VOID\r
 **/\r
 VOID\r
-EFIAPI\r
-InsertKeyCode (\r
-  IN OUT  USB_KB_BUFFER *KeyboardBuffer,\r
-  IN      UINT8         Key,\r
-  IN      BOOLEAN       Down\r
+Enqueue (\r
+  IN OUT  USB_SIMPLE_QUEUE *Queue,\r
+  IN      VOID             *Item,\r
+  IN      UINTN            ItemSize\r
   )\r
 {\r
   )\r
 {\r
-  USB_KEY UsbKey;\r
-\r
+  ASSERT (ItemSize == Queue->ItemSize);\r
   //\r
   // If keyboard buffer is full, throw the\r
   // first key out of the keyboard buffer.\r
   //\r
   //\r
   // If keyboard buffer is full, throw the\r
   // first key out of the keyboard buffer.\r
   //\r
-  if (IsUSBKeyboardBufferFull (KeyboardBuffer)) {\r
-    RemoveKeyCode (KeyboardBuffer, &UsbKey);\r
+  if (IsQueueFull (Queue)) {\r
+    Queue->Head = (Queue->Head + 1) % (MAX_KEY_ALLOWED + 1);\r
   }\r
 \r
   }\r
 \r
-  ASSERT (KeyboardBuffer->BufferTail <= MAX_KEY_ALLOWED);\r
-\r
-  KeyboardBuffer->Buffer[KeyboardBuffer->BufferTail].KeyCode = Key;\r
-  KeyboardBuffer->Buffer[KeyboardBuffer->BufferTail].Down    = Down;\r
+  CopyMem (Queue->Buffer[Queue->Tail], Item, ItemSize);\r
 \r
   //\r
   // Adjust the tail pointer of the FIFO keyboard buffer.\r
   //\r
 \r
   //\r
   // Adjust the tail pointer of the FIFO keyboard buffer.\r
   //\r
-  KeyboardBuffer->BufferTail = (UINT8) ((KeyboardBuffer->BufferTail + 1) % (MAX_KEY_ALLOWED + 1));\r
+  Queue->Tail = (Queue->Tail + 1) % (MAX_KEY_ALLOWED + 1);\r
 }\r
 \r
 \r
 /**\r
 }\r
 \r
 \r
 /**\r
-  Remove a keycode from keyboard buffer and return it.\r
+  Dequeue a item from the queue.\r
 \r
 \r
-  @param  KeyboardBuffer     Points to the USB keyboard buffer.\r
-  @param  UsbKey             Points to the buffer that contains keycode for output.\r
+  @param  Queue     Points to the queue.\r
+  @param  Item      Receives the item.\r
+  @param  ItemSize  Size of the item.\r
 \r
 \r
-  @retval EFI_SUCCESS        Keycode successfully removed from keyboard buffer.\r
-  @retval EFI_DEVICE_ERROR   Keyboard buffer is empty.\r
+  @retval EFI_SUCCESS        Item was successfully dequeued.\r
+  @retval EFI_DEVICE_ERROR   The queue is empty.\r
 \r
 **/\r
 EFI_STATUS\r
 \r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
-RemoveKeyCode (\r
-  IN OUT  USB_KB_BUFFER *KeyboardBuffer,\r
-     OUT  USB_KEY       *UsbKey\r
+Dequeue (\r
+  IN OUT  USB_SIMPLE_QUEUE *Queue,\r
+     OUT  VOID             *Item,\r
+  IN      UINTN            ItemSize\r
   )\r
 {\r
   )\r
 {\r
-  if (IsUSBKeyboardBufferEmpty (KeyboardBuffer)) {\r
+  ASSERT (Queue->ItemSize == ItemSize);\r
+\r
+  if (IsQueueEmpty (Queue)) {\r
     return EFI_DEVICE_ERROR;\r
   }\r
 \r
     return EFI_DEVICE_ERROR;\r
   }\r
 \r
-  ASSERT (KeyboardBuffer->BufferHead <= MAX_KEY_ALLOWED);\r
-\r
-  UsbKey->KeyCode = KeyboardBuffer->Buffer[KeyboardBuffer->BufferHead].KeyCode;\r
-  UsbKey->Down    = KeyboardBuffer->Buffer[KeyboardBuffer->BufferHead].Down;\r
+  CopyMem (Item, Queue->Buffer[Queue->Head], ItemSize);\r
 \r
   //\r
   // Adjust the head pointer of the FIFO keyboard buffer.\r
   //\r
 \r
   //\r
   // Adjust the head pointer of the FIFO keyboard buffer.\r
   //\r
-  KeyboardBuffer->BufferHead = (UINT8) ((KeyboardBuffer->BufferHead + 1) % (MAX_KEY_ALLOWED + 1));\r
+  Queue->Head = (Queue->Head + 1) % (MAX_KEY_ALLOWED + 1);\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
   return EFI_SUCCESS;\r
 }\r
@@ -1918,7 +1874,6 @@ RemoveKeyCode (
 \r
 **/\r
 VOID\r
 \r
 **/\r
 VOID\r
-EFIAPI\r
 SetKeyLED (\r
   IN  USB_KB_DEV    *UsbKeyboardDevice\r
   )\r
 SetKeyLED (\r
   IN  USB_KB_DEV    *UsbKeyboardDevice\r
   )\r
@@ -1970,6 +1925,7 @@ USBKeyboardRepeatHandler (
   )\r
 {\r
   USB_KB_DEV  *UsbKeyboardDevice;\r
   )\r
 {\r
   USB_KB_DEV  *UsbKeyboardDevice;\r
+  USB_KEY     UsbKey;\r
 \r
   UsbKeyboardDevice = (USB_KB_DEV *) Context;\r
 \r
 \r
   UsbKeyboardDevice = (USB_KB_DEV *) Context;\r
 \r
@@ -1980,11 +1936,9 @@ USBKeyboardRepeatHandler (
     //\r
     // Inserts the repeat key into keyboard buffer,\r
     //\r
     //\r
     // Inserts the repeat key into keyboard buffer,\r
     //\r
-    InsertKeyCode (\r
-      &(UsbKeyboardDevice->KeyboardBuffer),\r
-      UsbKeyboardDevice->RepeatKey,\r
-      TRUE\r
-      );\r
+    UsbKey.KeyCode = UsbKeyboardDevice->RepeatKey;\r
+    UsbKey.Down    = TRUE;\r
+    Enqueue (&UsbKeyboardDevice->UsbKeyQueue, &UsbKey, sizeof (UsbKey));\r
 \r
     //\r
     // Set repeat rate for next repeat key generation.\r
 \r
     //\r
     // Set repeat rate for next repeat key generation.\r
index cc0fd51e83cf8cb76ed67e49c90dc2435f206226..73efef8f62c2e1ca4f6429e45c3024cf44a4d66c 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Function prototype for USB Keyboard Driver.\r
 \r
 /** @file\r
   Function prototype for USB Keyboard Driver.\r
 \r
-Copyright (c) 2004 - 2008, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -70,7 +70,6 @@ typedef struct {
 \r
 **/\r
 BOOLEAN\r
 \r
 **/\r
 BOOLEAN\r
-EFIAPI\r
 IsUSBKeyboard (\r
   IN  EFI_USB_IO_PROTOCOL       *UsbIo\r
   );\r
 IsUSBKeyboard (\r
   IN  EFI_USB_IO_PROTOCOL       *UsbIo\r
   );\r
@@ -85,7 +84,6 @@ IsUSBKeyboard (
 \r
 **/\r
 EFI_STATUS\r
 \r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 InitUSBKeyboard (\r
   IN OUT USB_KB_DEV   *UsbKeyboardDevice\r
   );\r
 InitUSBKeyboard (\r
   IN OUT USB_KB_DEV   *UsbKeyboardDevice\r
   );\r
@@ -106,7 +104,6 @@ InitUSBKeyboard (
 \r
 **/\r
 EFI_STATUS\r
 \r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 InitKeyboardLayout (\r
   OUT USB_KB_DEV   *UsbKeyboardDevice\r
   );\r
 InitKeyboardLayout (\r
   OUT USB_KB_DEV   *UsbKeyboardDevice\r
   );\r
@@ -118,7 +115,6 @@ InitKeyboardLayout (
 \r
 **/\r
 VOID\r
 \r
 **/\r
 VOID\r
-EFIAPI\r
 ReleaseKeyboardLayoutResources (\r
   IN OUT USB_KB_DEV              *UsbKeyboardDevice\r
   );\r
 ReleaseKeyboardLayoutResources (\r
   IN OUT USB_KB_DEV              *UsbKeyboardDevice\r
   );\r
@@ -184,7 +180,6 @@ USBKeyboardRecoveryHandler (
 \r
 **/\r
 EFI_STATUS\r
 \r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 USBParseKey (\r
   IN OUT  USB_KB_DEV  *UsbKeyboardDevice,\r
   OUT     UINT8       *KeyCode\r
 USBParseKey (\r
   IN OUT  USB_KB_DEV  *UsbKeyboardDevice,\r
   OUT     UINT8       *KeyCode\r
@@ -195,7 +190,7 @@ USBParseKey (
 \r
   @param  UsbKeyboardDevice     The USB_KB_DEV instance.\r
   @param  KeyCode               Indicates the key code that will be interpreted.\r
 \r
   @param  UsbKeyboardDevice     The USB_KB_DEV instance.\r
   @param  KeyCode               Indicates the key code that will be interpreted.\r
-  @param  Key                   A pointer to a buffer that is filled in with\r
+  @param  KeyData               A pointer to a buffer that is filled in with\r
                                 the keystroke information for the key that\r
                                 was pressed.\r
 \r
                                 the keystroke information for the key that\r
                                 was pressed.\r
 \r
@@ -207,87 +202,98 @@ USBParseKey (
 \r
 **/\r
 EFI_STATUS\r
 \r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 UsbKeyCodeToEfiInputKey (\r
   IN  USB_KB_DEV      *UsbKeyboardDevice,\r
   IN  UINT8           KeyCode,\r
 UsbKeyCodeToEfiInputKey (\r
   IN  USB_KB_DEV      *UsbKeyboardDevice,\r
   IN  UINT8           KeyCode,\r
-  OUT EFI_INPUT_KEY   *Key\r
+  OUT EFI_KEY_DATA    *KeyData\r
   );\r
 \r
   );\r
 \r
+\r
 /**\r
 /**\r
-  Resets USB keyboard buffer.\r
+  Create the queue.\r
 \r
 \r
-  @param  KeyboardBuffer     Points to the USB keyboard buffer.\r
+  @param  Queue     Points to the queue.\r
+  @param  ItemSize  Size of the single item.\r
 \r
 **/\r
 VOID\r
 \r
 **/\r
 VOID\r
-EFIAPI\r
-InitUSBKeyBuffer (\r
-  OUT  USB_KB_BUFFER   *KeyboardBuffer\r
+InitQueue (\r
+  IN OUT  USB_SIMPLE_QUEUE   *Queue,\r
+  IN      UINTN              ItemSize\r
+  );\r
+\r
+/**\r
+  Destroy the queue\r
+\r
+  @param Queue    Points to the queue.\r
+**/\r
+VOID\r
+DestroyQueue (\r
+  IN OUT USB_SIMPLE_QUEUE   *Queue\r
   );\r
 \r
   );\r
 \r
+\r
 /**\r
 /**\r
-  Check whether USB keyboard buffer is empty.\r
+  Check whether the queue is empty.\r
 \r
 \r
-  @param  KeyboardBuffer     USB keyboard buffer\r
+  @param  Queue     Points to the queue.\r
 \r
 \r
-  @retval TRUE               Keyboard buffer is empty.\r
-  @retval FALSE              Keyboard buffer is not empty.\r
+  @retval TRUE      Queue is empty.\r
+  @retval FALSE     Queue is not empty.\r
 \r
 **/\r
 BOOLEAN\r
 \r
 **/\r
 BOOLEAN\r
-EFIAPI\r
-IsUSBKeyboardBufferEmpty (\r
-  IN  USB_KB_BUFFER   *KeyboardBuffer\r
+IsQueueEmpty (\r
+  IN  USB_SIMPLE_QUEUE   *Queue\r
   );\r
 \r
   );\r
 \r
+\r
 /**\r
 /**\r
-  Check whether USB keyboard buffer is full.\r
+  Check whether the queue is full.\r
 \r
 \r
-  @param  KeyboardBuffer     USB keyboard buffer\r
+  @param  Queue     Points to the queue.\r
 \r
 \r
-  @retval TRUE               Keyboard buffer is full.\r
-  @retval FALSE              Keyboard buffer is not full.\r
+  @retval TRUE      Queue is full.\r
+  @retval FALSE     Queue is not full.\r
 \r
 **/\r
 BOOLEAN\r
 \r
 **/\r
 BOOLEAN\r
-EFIAPI\r
-IsUSBKeyboardBufferFull (\r
-  IN  USB_KB_BUFFER   *KeyboardBuffer\r
+IsQueueFull (\r
+  IN  USB_SIMPLE_QUEUE   *Queue\r
   );\r
 \r
   );\r
 \r
-/**\r
-  Inserts a keycode into keyboard buffer.\r
 \r
 \r
-  @param  KeyboardBuffer     Points to the USB keyboard buffer.\r
-  @param  Key                Keycode to insert.\r
-  @param  Down               TRUE means key is pressed.\r
-                             FALSE means key is released.\r
+/**\r
+  Enqueue the item to the queue.\r
 \r
 \r
+  @param  Queue     Points to the queue.\r
+  @param  Item      Points to the item to be enqueued.\r
+  @param  ItemSize  Size of the item.\r
 **/\r
 VOID\r
 **/\r
 VOID\r
-EFIAPI\r
-InsertKeyCode (\r
-  IN OUT  USB_KB_BUFFER *KeyboardBuffer,\r
-  IN      UINT8         Key,\r
-  IN      BOOLEAN       Down\r
+Enqueue (\r
+  IN OUT  USB_SIMPLE_QUEUE *Queue,\r
+  IN      VOID             *Item,\r
+  IN      UINTN            ItemSize\r
   );\r
 \r
   );\r
 \r
+\r
 /**\r
 /**\r
-  Remove a keycode from keyboard buffer and return it.\r
+  Dequeue a item from the queue.\r
 \r
 \r
-  @param  KeyboardBuffer     Points to the USB keyboard buffer.\r
-  @param  UsbKey             Points to the buffer that contains keycode for output.\r
+  @param  Queue     Points to the queue.\r
+  @param  Item      Receives the item.\r
+  @param  ItemSize  Size of the item.\r
 \r
 \r
-  @retval EFI_SUCCESS        Keycode successfully removed from keyboard buffer.\r
-  @retval EFI_DEVICE_ERROR   Keyboard buffer is empty.\r
+  @retval EFI_SUCCESS        Item was successfully dequeued.\r
+  @retval EFI_DEVICE_ERROR   The queue is empty.\r
 \r
 **/\r
 EFI_STATUS\r
 \r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
-RemoveKeyCode (\r
-  IN OUT  USB_KB_BUFFER *KeyboardBuffer,\r
-     OUT  USB_KEY       *UsbKey\r
+Dequeue (\r
+  IN OUT  USB_SIMPLE_QUEUE *Queue,\r
+     OUT  VOID             *Item,\r
+  IN      UINTN            ItemSize\r
   );\r
 \r
 /**\r
   );\r
 \r
 /**\r
@@ -317,7 +323,6 @@ USBKeyboardRepeatHandler (
 \r
 **/\r
 VOID\r
 \r
 **/\r
 VOID\r
-EFIAPI\r
 SetKeyLED (\r
   IN  USB_KB_DEV    *UsbKeyboardDevice\r
   );\r
 SetKeyLED (\r
   IN  USB_KB_DEV    *UsbKeyboardDevice\r
   );\r