]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Bus/Isa/Ps2KeyboardDxe/Ps2Keyboard.h
IntelFrameworkModule/Ps2Kb: ReadKeyStrokeEx always return key state
[mirror_edk2.git] / IntelFrameworkModulePkg / Bus / Isa / Ps2KeyboardDxe / Ps2Keyboard.h
index 1eb2c5491c6d0edadffef05a0fa769a3a4575411..613f176401ec6b09bb5a25e5506245e1556c5708 100644 (file)
@@ -1,8 +1,8 @@
-/**@file\r
+/** @file\r
   PS/2 keyboard driver header file\r
 \r
-Copyright (c) 2006 - 2007, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2006 - 2018, 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
 http://opensource.org/licenses/bsd-license.php\r
@@ -12,11 +12,10 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 **/\r
 \r
-#ifndef _PS2KEYBOARD_H\r
-#define _PS2KEYBOARD_H\r
+#ifndef _PS2KEYBOARD_H_\r
+#define _PS2KEYBOARD_H_\r
 \r
-#include <PiDxe.h>\r
-#include <Framework/StatusCode.h>\r
+#include <Uefi.h>\r
 \r
 #include <Protocol/SimpleTextIn.h>\r
 #include <Protocol/SimpleTextInEx.h>\r
@@ -33,22 +32,42 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Library/MemoryAllocationLib.h>\r
 #include <Library/BaseLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
+#include <Library/TimerLib.h>\r
+#include <Library/PcdLib.h>\r
+\r
+//\r
+// Global Variables\r
+//\r
+extern EFI_DRIVER_BINDING_PROTOCOL   gKeyboardControllerDriver;\r
+extern EFI_COMPONENT_NAME_PROTOCOL   gPs2KeyboardComponentName;\r
+extern EFI_COMPONENT_NAME2_PROTOCOL  gPs2KeyboardComponentName2;\r
 \r
 //\r
 // Driver Private Data\r
 //\r
-#define KEYBOARD_BUFFER_MAX_COUNT         32\r
-#define KEYBOARD_CONSOLE_IN_DEV_SIGNATURE EFI_SIGNATURE_32 ('k', 'k', 'e', 'y')\r
-#define KEYBOARD_CONSOLE_IN_EX_NOTIFY_SIGNATURE EFI_SIGNATURE_32 ('k', 'c', 'e', 'n')\r
+#define KEYBOARD_CONSOLE_IN_DEV_SIGNATURE       SIGNATURE_32 ('k', 'k', 'e', 'y')\r
+#define KEYBOARD_CONSOLE_IN_EX_NOTIFY_SIGNATURE SIGNATURE_32 ('k', 'c', 'e', 'n')\r
 \r
 typedef struct _KEYBOARD_CONSOLE_IN_EX_NOTIFY {\r
-  UINTN                                 Signature;\r
-  EFI_HANDLE                            NotifyHandle;\r
-  EFI_KEY_DATA                          KeyData;\r
-  EFI_KEY_NOTIFY_FUNCTION               KeyNotificationFn;\r
-  LIST_ENTRY                            NotifyEntry;\r
+  UINTN                               Signature;\r
+  EFI_KEY_DATA                        KeyData;\r
+  EFI_KEY_NOTIFY_FUNCTION             KeyNotificationFn;\r
+  LIST_ENTRY                          NotifyEntry;\r
 } KEYBOARD_CONSOLE_IN_EX_NOTIFY;\r
 \r
+#define KEYBOARD_SCAN_CODE_MAX_COUNT  32\r
+typedef struct {\r
+  UINT8                               Buffer[KEYBOARD_SCAN_CODE_MAX_COUNT];\r
+  UINTN                               Head;\r
+  UINTN                               Tail;\r
+} SCAN_CODE_QUEUE;\r
+\r
+#define KEYBOARD_EFI_KEY_MAX_COUNT    256\r
+typedef struct {\r
+  EFI_KEY_DATA                        Buffer[KEYBOARD_EFI_KEY_MAX_COUNT];\r
+  UINTN                               Head;\r
+  UINTN                               Tail;\r
+} EFI_KEY_QUEUE;\r
 \r
 typedef struct {\r
   UINTN                               Signature;\r
@@ -64,36 +83,28 @@ typedef struct {
   UINT32                              StatusRegisterAddress;\r
   UINT32                              CommandRegisterAddress;\r
 \r
-  EFI_INPUT_KEY                       Key;\r
-  EFI_KEY_STATE                       KeyState;\r
-\r
+  BOOLEAN                             LeftCtrl;\r
+  BOOLEAN                             RightCtrl;\r
+  BOOLEAN                             LeftAlt;\r
+  BOOLEAN                             RightAlt;\r
   BOOLEAN                             LeftShift;\r
-  BOOLEAN                             RightShift;  \r
+  BOOLEAN                             RightShift;\r
   BOOLEAN                             LeftLogo;\r
   BOOLEAN                             RightLogo;\r
   BOOLEAN                             Menu;\r
   BOOLEAN                             SysReq;\r
 \r
-  BOOLEAN                             Ctrl;\r
-  BOOLEAN                             Alt;\r
-  BOOLEAN                             Shift;\r
   BOOLEAN                             CapsLock;\r
   BOOLEAN                             NumLock;\r
   BOOLEAN                             ScrollLock;\r
 \r
+  BOOLEAN                             IsSupportPartialKey;\r
   //\r
-  // Buffer storing key scancodes\r
-  //\r
-  UINT8                               ScancodeBuf[KEYBOARD_BUFFER_MAX_COUNT];\r
-  UINT32                              ScancodeBufStartPos;\r
-  UINT32                              ScancodeBufEndPos;\r
-  UINT32                              ScancodeBufCount;\r
-\r
-  //\r
-  // Indicators of the key pressing state, used in detecting Alt+Ctrl+Del\r
+  // Queue storing key scancodes\r
   //\r
-  BOOLEAN                             Ctrled;\r
-  BOOLEAN                             Alted;\r
+  SCAN_CODE_QUEUE                     ScancodeQueue;\r
+  EFI_KEY_QUEUE                       EfiKeyQueue;\r
+  EFI_KEY_QUEUE                       EfiKeyQueueForNotify;\r
 \r
   //\r
   // Error state\r
@@ -107,6 +118,7 @@ typedef struct {
   // Notification Function List\r
   //\r
   LIST_ENTRY                          NotifyList;\r
+  EFI_EVENT                           KeyNotifyProcessEvent;\r
 } KEYBOARD_CONSOLE_IN_DEV;\r
 \r
 #define KEYBOARD_CONSOLE_IN_DEV_FROM_THIS(a)  CR (a, KEYBOARD_CONSOLE_IN_DEV, ConIn, KEYBOARD_CONSOLE_IN_DEV_SIGNATURE)\r
@@ -120,40 +132,24 @@ typedef struct {
 #define TABLE_END 0x0\r
 \r
 //\r
-// Global Variables\r
+// Driver entry point\r
 //\r
-extern EFI_DRIVER_BINDING_PROTOCOL   gKeyboardControllerDriver;\r
-extern EFI_COMPONENT_NAME_PROTOCOL   gPs2KeyboardComponentName;\r
-extern EFI_COMPONENT_NAME2_PROTOCOL  gPs2KeyboardComponentName2;\r
+/**\r
+  The user Entry Point for module Ps2Keyboard. The user code starts with this function.\r
 \r
-extern EFI_GUID                      gSimpleTextInExNotifyGuid;\r
+  @param[in] ImageHandle    The firmware allocated handle for the EFI image.\r
+  @param[in] SystemTable    A pointer to the EFI System Table.\r
 \r
-//\r
-// Driver entry point\r
-//\r
+  @retval EFI_SUCCESS       The entry point is executed successfully.\r
+  @retval other             Some error occurs when executing this entry point.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 InstallPs2KeyboardDriver (\r
   IN EFI_HANDLE           ImageHandle,\r
   IN EFI_SYSTEM_TABLE     *SystemTable\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
-  ImageHandle - GC_TODO: add argument description\r
-  SystemTable - GC_TODO: add argument description\r
-\r
-Returns:\r
-\r
-  GC_TODO: add return values\r
-\r
---*/\r
-;\r
+  );\r
 \r
 #define KEYBOARD_8042_DATA_REGISTER     0x60\r
 #define KEYBOARD_8042_STATUS_REGISTER   0x64\r
@@ -162,11 +158,12 @@ Returns:
 #define KEYBOARD_KBEN                   0xF4\r
 #define KEYBOARD_CMDECHO_ACK            0xFA\r
 \r
+#define KEYBOARD_MAX_TRY                256     // 256\r
 #define KEYBOARD_TIMEOUT                65536   // 0.07s\r
 #define KEYBOARD_WAITFORVALUE_TIMEOUT   1000000 // 1s\r
 #define KEYBOARD_BAT_TIMEOUT            4000000 // 4s\r
 #define KEYBOARD_TIMER_INTERVAL         200000  // 0.02s\r
-#define SCANCODE_EXTENDED               0xE0\r
+#define SCANCODE_EXTENDED0              0xE0\r
 #define SCANCODE_EXTENDED1              0xE1\r
 #define SCANCODE_CTRL_MAKE              0x1D\r
 #define SCANCODE_CTRL_BREAK             0x9D\r
@@ -179,253 +176,228 @@ Returns:
 #define SCANCODE_CAPS_LOCK_MAKE         0x3A\r
 #define SCANCODE_NUM_LOCK_MAKE          0x45\r
 #define SCANCODE_SCROLL_LOCK_MAKE       0x46\r
+#define SCANCODE_DELETE_MAKE            0x53\r
 #define SCANCODE_LEFT_LOGO_MAKE         0x5B //GUI key defined in Keyboard scan code\r
 #define SCANCODE_LEFT_LOGO_BREAK        0xDB\r
 #define SCANCODE_RIGHT_LOGO_MAKE        0x5C\r
 #define SCANCODE_RIGHT_LOGO_BREAK       0xDC\r
-#define SCANCODE_MENU_MAKE              0x5D //APPS key defined in Keyboard scan code \r
+#define SCANCODE_MENU_MAKE              0x5D //APPS key defined in Keyboard scan code\r
 #define SCANCODE_MENU_BREAK             0xDD\r
 #define SCANCODE_SYS_REQ_MAKE           0x37\r
+#define SCANCODE_SYS_REQ_BREAK          0xB7\r
+#define SCANCODE_SYS_REQ_MAKE_WITH_ALT  0x54\r
+#define SCANCODE_SYS_REQ_BREAK_WITH_ALT 0xD4\r
+\r
 #define SCANCODE_MAX_MAKE               0x60\r
 \r
+\r
+#define KEYBOARD_STATUS_REGISTER_HAS_OUTPUT_DATA     BIT0        ///< 0 - Output register has no data; 1 - Output register has data\r
+#define KEYBOARD_STATUS_REGISTER_HAS_INPUT_DATA      BIT1        ///< 0 - Input register has no data;  1 - Input register has data\r
+#define KEYBOARD_STATUS_REGISTER_SYSTEM_FLAG         BIT2        ///< Set to 0 after power on reset\r
+#define KEYBOARD_STATUS_REGISTER_INPUT_DATA_TYPE     BIT3        ///< 0 - Data in input register is data; 1 - Data in input register is command\r
+#define KEYBOARD_STATUS_REGISTER_ENABLE_FLAG         BIT4        ///< 0 - Keyboard is disable; 1 - Keyboard is enable\r
+#define KEYBOARD_STATUS_REGISTER_TRANSMIT_TIMEOUT    BIT5        ///< 0 - Transmit is complete without timeout; 1 - Transmit is timeout without complete\r
+#define KEYBOARD_STATUS_REGISTER_RECEIVE_TIMEOUT     BIT6        ///< 0 - Receive is complete without timeout; 1 - Receive is timeout without complete\r
+#define KEYBOARD_STATUS_REGISTER_PARITY              BIT7        ///< 0 - Odd parity; 1 - Even parity\r
+\r
+#define KEYBOARD_8042_COMMAND_READ                          0x20\r
+#define KEYBOARD_8042_COMMAND_WRITE                         0x60\r
+#define KEYBOARD_8042_COMMAND_DISABLE_MOUSE_INTERFACE       0xA7\r
+#define KEYBOARD_8042_COMMAND_ENABLE_MOUSE_INTERFACE        0xA8\r
+#define KEYBOARD_8042_COMMAND_CONTROLLER_SELF_TEST          0xAA\r
+#define KEYBOARD_8042_COMMAND_KEYBOARD_INTERFACE_SELF_TEST  0xAB\r
+#define KEYBOARD_8042_COMMAND_DISABLE_KEYBOARD_INTERFACE    0xAD\r
+\r
+#define KEYBOARD_8048_COMMAND_CLEAR_OUTPUT_DATA             0xF4\r
+#define KEYBOARD_8048_COMMAND_RESET                         0xFF\r
+#define KEYBOARD_8048_COMMAND_SELECT_SCAN_CODE_SET          0xF0\r
+\r
+#define KEYBOARD_8048_RETURN_8042_BAT_SUCCESS               0xAA\r
+#define KEYBOARD_8048_RETURN_8042_BAT_ERROR                 0xFC\r
+#define KEYBOARD_8048_RETURN_8042_ACK                       0xFA\r
+\r
+\r
+//\r
+// Keyboard Controller Status\r
+//\r
+#define KBC_PARE  0x80  // Parity Error\r
+#define KBC_TIM   0x40  // General Time Out\r
+\r
 //\r
 // Other functions that are used among .c files\r
 //\r
+/**\r
+  Show keyboard status lights according to\r
+  indicators in ConsoleIn.\r
 \r
+  @param ConsoleIn Pointer to instance of KEYBOARD_CONSOLE_IN_DEV\r
+\r
+  @return status\r
+\r
+**/\r
 EFI_STATUS\r
 UpdateStatusLights (\r
   IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Show keyboard status light for ScrollLock, NumLock and CapsLock\r
-  according to indicators in ConsoleIn.\r
-\r
-Arguments:\r
+  );\r
 \r
-  ConsoleIn   - driver private structure\r
-\r
-Returns:\r
+/**\r
+  write key to keyboard.\r
 \r
-  EFI_SUCCESS - Show the status light successfully.\r
-  EFI_TIMEOUT - Timeout when operating read/write on registers.\r
+  @param ConsoleIn Pointer to instance of KEYBOARD_CONSOLE_IN_DEV\r
+  @param Data      value wanted to be written\r
 \r
---*/  \r
-;\r
+  @retval EFI_TIMEOUT - GC_TODO: Add description for return value\r
+  @retval EFI_SUCCESS - GC_TODO: Add description for return value\r
 \r
+**/\r
 EFI_STATUS\r
 KeyboardRead (\r
   IN KEYBOARD_CONSOLE_IN_DEV  *ConsoleIn,\r
   OUT UINT8                   *Data\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  GC_TODO: Add function description\r
+  );\r
 \r
-Arguments:\r
-\r
-  ConsoleIn - GC_TODO: add argument description\r
-  Data      - GC_TODO: add argument description\r
-\r
-Returns:\r
+/**\r
+  Get scancode from scancode buffer and translate into EFI-scancode and unicode defined by EFI spec.\r
 \r
-  GC_TODO: add return values\r
+  The function is always called in TPL_NOTIFY.\r
 \r
---*/\r
-;\r
+  @param ConsoleIn KEYBOARD_CONSOLE_IN_DEV instance pointer\r
 \r
-EFI_STATUS\r
+**/\r
+VOID\r
 KeyGetchar (\r
   IN OUT KEYBOARD_CONSOLE_IN_DEV *ConsoleIn\r
-  )\r
-/*++\r
+  );\r
 \r
-Routine Description:\r
-\r
-  GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
-  ConsoleIn - GC_TODO: add argument description\r
+/**\r
+  Process key notify.\r
 \r
-Returns:\r
+  @param  Event                 Indicates the event that invoke this function.\r
+  @param  Context               Indicates the calling context.\r
+**/\r
+VOID\r
+EFIAPI\r
+KeyNotifyProcessHandler (\r
+  IN  EFI_EVENT                 Event,\r
+  IN  VOID                      *Context\r
+  );\r
 \r
-  GC_TODO: add return values\r
+/**\r
+  Perform 8042 controller and keyboard Initialization.\r
+  If ExtendedVerification is TRUE, do additional test for\r
+  the keyboard interface\r
 \r
---*/\r
-;\r
+  @param ConsoleIn - KEYBOARD_CONSOLE_IN_DEV instance pointer\r
+  @param ExtendedVerification - indicates a thorough initialization\r
 \r
+  @retval EFI_DEVICE_ERROR Fail to init keyboard\r
+  @retval EFI_SUCCESS      Success to init keyboard\r
+**/\r
 EFI_STATUS\r
 InitKeyboard (\r
   IN OUT KEYBOARD_CONSOLE_IN_DEV *ConsoleIn,\r
   IN BOOLEAN                     ExtendedVerification\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  GC_TODO: Add function description\r
+  );\r
 \r
-Arguments:\r
-\r
-  ConsoleIn             - GC_TODO: add argument description\r
-  ExtendedVerification  - GC_TODO: add argument description\r
-\r
-Returns:\r
+/**\r
+  Disable the keyboard interface of the 8042 controller.\r
 \r
-  GC_TODO: add return values\r
+  @param ConsoleIn   - the device instance\r
 \r
---*/\r
-;\r
+  @return status of issuing disable command\r
 \r
+**/\r
 EFI_STATUS\r
 DisableKeyboard (\r
   IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
+  );\r
 \r
-  GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
-  ConsoleIn - GC_TODO: add argument description\r
-\r
-Returns:\r
-\r
-  GC_TODO: add return values\r
+/**\r
+  Timer event handler: read a series of scancodes from 8042\r
+  and put them into memory scancode buffer.\r
+  it read as much scancodes to either fill\r
+  the memory buffer or empty the keyboard buffer.\r
+  It is registered as running under TPL_NOTIFY\r
 \r
---*/\r
-;\r
+  @param Event - The timer event\r
+  @param Context - A KEYBOARD_CONSOLE_IN_DEV pointer\r
 \r
+**/\r
 VOID\r
 EFIAPI\r
 KeyboardTimerHandler (\r
   IN EFI_EVENT    Event,\r
   IN VOID         *Context\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
-  Event   - GC_TODO: add argument description\r
-  Context - GC_TODO: add argument description\r
-\r
-Returns:\r
+  );\r
 \r
-  GC_TODO: add return values\r
+/**\r
+  logic reset keyboard\r
+  Implement SIMPLE_TEXT_IN.Reset()\r
+  Perform 8042 controller and keyboard initialization\r
 \r
---*/\r
-;\r
+  @param This    Pointer to instance of EFI_SIMPLE_TEXT_INPUT_PROTOCOL\r
+  @param ExtendedVerification Indicate that the driver may perform a more\r
+                              exhaustive verification operation of the device during\r
+                              reset, now this par is ignored in this driver\r
 \r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 KeyboardEfiReset (\r
   IN  EFI_SIMPLE_TEXT_INPUT_PROTOCOL  *This,\r
   IN  BOOLEAN                         ExtendedVerification\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
-  This                  - GC_TODO: add argument description\r
-  ExtendedVerification  - GC_TODO: add argument description\r
+  );\r
 \r
-Returns:\r
-\r
-  GC_TODO: add return values\r
+/**\r
+  Implement SIMPLE_TEXT_IN.ReadKeyStroke().\r
+  Retrieve key values for driver user.\r
 \r
---*/\r
-;\r
+  @param This    Pointer to instance of EFI_SIMPLE_TEXT_INPUT_PROTOCOL\r
+  @param Key     The output buffer for key value\r
 \r
+  @retval EFI_SUCCESS success to read key stroke\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 KeyboardReadKeyStroke (\r
   IN  EFI_SIMPLE_TEXT_INPUT_PROTOCOL  *This,\r
   OUT EFI_INPUT_KEY                   *Key\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  GC_TODO: Add function description\r
+  );\r
 \r
-Arguments:\r
-\r
-  This  - GC_TODO: add argument description\r
-  Key   - GC_TODO: add argument description\r
-\r
-Returns:\r
-\r
-  GC_TODO: add return values\r
+/**\r
+  Event notification function for SIMPLE_TEXT_IN.WaitForKey event\r
+  Signal the event if there is key available\r
 \r
---*/\r
-;\r
+  @param Event    the event object\r
+  @param Context  waitting context\r
 \r
+**/\r
 VOID\r
 EFIAPI\r
 KeyboardWaitForKey (\r
   IN  EFI_EVENT               Event,\r
   IN  VOID                    *Context\r
-  )\r
-/*++\r
+  );\r
 \r
-Routine Description:\r
-\r
-  GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
-  Event   - GC_TODO: add argument description\r
-  Context - GC_TODO: add argument description\r
-\r
-Returns:\r
+/**\r
+  Read status register.\r
 \r
-  GC_TODO: add return values\r
+  @param ConsoleIn  Pointer to instance of KEYBOARD_CONSOLE_IN_DEV\r
 \r
---*/\r
-;\r
+  @return value in status register\r
 \r
+**/\r
 UINT8\r
 KeyReadStatusRegister (\r
   IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
-  ConsoleIn - GC_TODO: add argument description\r
-\r
-Returns:\r
-\r
-  GC_TODO: add return values\r
-\r
---*/\r
-;\r
+  );\r
 \r
 /**\r
   Check whether there is Ps/2 Keyboard device in system by 0xF4 Keyboard Command\r
   If Keyboard receives 0xF4, it will respond with 'ACK'. If it doesn't respond, the device\r
   should not be in system.\r
 \r
-  @param[in]  BiosKeyboardPrivate   Keyboard Private Data Structure\r
+  @param[in]  ConsoleIn   Pointer to instance of KEYBOARD_CONSOLE_IN_DEV\r
 \r
   @retval     TRUE                  Keyboard in System.\r
   @retval     FALSE                 Keyboard not in System.\r
@@ -434,159 +406,176 @@ BOOLEAN
 EFIAPI\r
 CheckKeyboardConnect (\r
   IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn\r
-  )\r
-;\r
+  );\r
+\r
+/**\r
+  Event notification function for SIMPLE_TEXT_INPUT_EX_PROTOCOL.WaitForKeyEx event\r
+  Signal the event if there is key available\r
+\r
+  @param Event    event object\r
+  @param Context  waiting context\r
 \r
+**/\r
 VOID\r
 EFIAPI\r
 KeyboardWaitForKeyEx (\r
   IN  EFI_EVENT               Event,\r
   IN  VOID                    *Context\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Event notification function for SIMPLE_TEXT_INPUT_EX_PROTOCOL.WaitForKeyEx event\r
-  Signal the event if there is key available\r
-\r
-Arguments:\r
-\r
-Returns:\r
-\r
---*/    \r
-;  \r
+  );\r
 \r
 //\r
 // Simple Text Input Ex protocol function prototypes\r
 //\r
 \r
+/**\r
+  Reset the input device and optionaly run diagnostics\r
+\r
+  @param This                 - Protocol instance pointer.\r
+  @param ExtendedVerification - Driver may perform diagnostics on reset.\r
+\r
+  @retval EFI_SUCCESS           - The device was reset.\r
+  @retval EFI_DEVICE_ERROR      - The device is not functioning properly and could\r
+                                  not be reset.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 KeyboardEfiResetEx (\r
   IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL  *This,\r
   IN BOOLEAN                            ExtendedVerification\r
-  )\r
-/*++\r
+  );\r
 \r
-  Routine Description:\r
-    Reset the input device and optionaly run diagnostics\r
+/**\r
+    Reads the next keystroke from the input device. The WaitForKey Event can\r
+    be used to test for existance of a keystroke via WaitForEvent () call.\r
 \r
-  Arguments:\r
-    This                 - Protocol instance pointer.\r
-    ExtendedVerification - Driver may perform diagnostics on reset.\r
 \r
-  Returns:\r
-    EFI_SUCCESS           - The device was reset.\r
-    EFI_DEVICE_ERROR      - The device is not functioning properly and could \r
-                            not be reset.\r
+    @param This       - Protocol instance pointer.\r
+    @param KeyData    - A pointer to a buffer that is filled in with the keystroke\r
+                 state data for the key that was pressed.\r
 \r
---*/\r
-;\r
+    @retval EFI_SUCCESS           - The keystroke information was returned.\r
+    @retval EFI_NOT_READY         - There was no keystroke data availiable.\r
+    @retval EFI_DEVICE_ERROR      - The keystroke information was not returned due to\r
+                            hardware errors.\r
+    @retval EFI_INVALID_PARAMETER - KeyData is NULL.\r
 \r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 KeyboardReadKeyStrokeEx (\r
   IN  EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,\r
   OUT EFI_KEY_DATA                      *KeyData\r
-  )\r
-/*++\r
-\r
-  Routine Description:\r
-    Reads the next keystroke from the input device. The WaitForKey Event can \r
-    be used to test for existance of a keystroke via WaitForEvent () call.\r
+  );\r
 \r
-  Arguments:\r
-    This       - Protocol instance pointer.\r
-    KeyData    - A pointer to a buffer that is filled in with the keystroke \r
-                 state data for the key that was pressed.\r
+/**\r
+  Set certain state for the input device.\r
 \r
-  Returns:\r
-    EFI_SUCCESS           - The keystroke information was returned.\r
-    EFI_NOT_READY         - There was no keystroke data availiable.\r
-    EFI_DEVICE_ERROR      - The keystroke information was not returned due to \r
-                            hardware errors.\r
-    EFI_INVALID_PARAMETER - KeyData is NULL.                        \r
+  @param This              - Protocol instance pointer.\r
+  @param KeyToggleState    - A pointer to the EFI_KEY_TOGGLE_STATE to set the\r
+                        state for the input device.\r
 \r
---*/\r
-;\r
+  @retval EFI_SUCCESS           - The device state was set successfully.\r
+  @retval EFI_DEVICE_ERROR      - The device is not functioning correctly and could\r
+                            not have the setting adjusted.\r
+  @retval EFI_UNSUPPORTED       - The device does not have the ability to set its state.\r
+  @retval EFI_INVALID_PARAMETER - KeyToggleState is NULL.\r
 \r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 KeyboardSetState (\r
   IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL  *This,\r
   IN EFI_KEY_TOGGLE_STATE               *KeyToggleState\r
-  )\r
-/*++\r
-\r
-  Routine Description:\r
-    Set certain state for the input device.\r
-\r
-  Arguments:\r
-    This                  - Protocol instance pointer.\r
-    KeyToggleState        - A pointer to the EFI_KEY_TOGGLE_STATE to set the \r
-                            state for the input device.\r
-                          \r
-  Returns:                \r
-    EFI_SUCCESS           - The device state was set successfully.\r
-    EFI_DEVICE_ERROR      - The device is not functioning correctly and could \r
-                            not have the setting adjusted.\r
-    EFI_UNSUPPORTED       - The device does not have the ability to set its state.\r
-    EFI_INVALID_PARAMETER - KeyToggleState is NULL.                       \r
+  );\r
 \r
---*/   \r
-;\r
+/**\r
+    Register a notification function for a particular keystroke for the input device.\r
+\r
+    @param This                    - Protocol instance pointer.\r
+    @param KeyData                 - A pointer to a buffer that is filled in with the keystroke\r
+                                     information data for the key that was pressed. If KeyData.Key,\r
+                                     KeyData.KeyState.KeyToggleState and KeyData.KeyState.KeyShiftState\r
+                                     are 0, then any incomplete keystroke will trigger a notification of\r
+                                     the KeyNotificationFunction.\r
+    @param KeyNotificationFunction - Points to the function to be called when the key\r
+                                     sequence is typed specified by KeyData. This notification function\r
+                                     should be called at <=TPL_CALLBACK.\r
+    @param NotifyHandle            - Points to the unique handle assigned to the registered notification.\r
+\r
+    @retval EFI_SUCCESS             - The notification function was registered successfully.\r
+    @retval EFI_OUT_OF_RESOURCES    - Unable to allocate resources for necesssary data structures.\r
+    @retval EFI_INVALID_PARAMETER   - KeyData or NotifyHandle is NULL.\r
 \r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 KeyboardRegisterKeyNotify (\r
   IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL  *This,\r
   IN EFI_KEY_DATA                       *KeyData,\r
   IN EFI_KEY_NOTIFY_FUNCTION            KeyNotificationFunction,\r
-  OUT EFI_HANDLE                        *NotifyHandle\r
-  )\r
-/*++\r
+  OUT VOID                              **NotifyHandle\r
+  );\r
 \r
-  Routine Description:\r
-    Register a notification function for a particular keystroke for the input device.\r
+/**\r
+    Remove a registered notification function from a particular keystroke.\r
+\r
+    @param This                    - Protocol instance pointer.\r
+    @param NotificationHandle      - The handle of the notification function being unregistered.\r
 \r
-  Arguments:\r
-    This                    - Protocol instance pointer.\r
-    KeyData                 - A pointer to a buffer that is filled in with the keystroke \r
-                              information data for the key that was pressed.\r
-    KeyNotificationFunction - Points to the function to be called when the key \r
-                              sequence is typed specified by KeyData.                        \r
-    NotifyHandle            - Points to the unique handle assigned to the registered notification.                          \r
-\r
-  Returns:\r
-    EFI_SUCCESS             - The notification function was registered successfully.\r
-    EFI_OUT_OF_RESOURCES    - Unable to allocate resources for necesssary data structures.\r
-    EFI_INVALID_PARAMETER   - KeyData or NotifyHandle is NULL.                       \r
-                              \r
---*/   \r
-;\r
 \r
+    @retval EFI_SUCCESS             - The notification function was unregistered successfully.\r
+    @retval EFI_INVALID_PARAMETER   - The NotificationHandle is invalid.\r
+    @retval EFI_NOT_FOUND           - Can not find the matching entry in database.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 KeyboardUnregisterKeyNotify (\r
   IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL  *This,\r
-  IN EFI_HANDLE                         NotificationHandle\r
-  )\r
-/*++\r
+  IN VOID                               *NotificationHandle\r
+  );\r
 \r
-  Routine Description:\r
-    Remove a registered notification function from a particular keystroke.\r
+/**\r
+  Push one key data to the EFI key buffer.\r
 \r
-  Arguments:\r
-    This                    - Protocol instance pointer.    \r
-    NotificationHandle      - The handle of the notification function being unregistered.\r
-\r
-  Returns:\r
-    EFI_SUCCESS             - The notification function was unregistered successfully.\r
-    EFI_INVALID_PARAMETER   - The NotificationHandle is invalid.\r
-    EFI_NOT_FOUND           - Can not find the matching entry in database.  \r
-                              \r
---*/   \r
-;\r
+  @param Queue     Pointer to instance of EFI_KEY_QUEUE.\r
+  @param KeyData   The key data to push.\r
+**/\r
+VOID\r
+PushEfikeyBufTail (\r
+  IN  EFI_KEY_QUEUE         *Queue,\r
+  IN  EFI_KEY_DATA          *KeyData\r
+  );\r
+\r
+/**\r
+  Judge whether is a registed key\r
+\r
+  @param RegsiteredData       A pointer to a buffer that is filled in with the keystroke\r
+                              state data for the key that was registered.\r
+  @param InputData            A pointer to a buffer that is filled in with the keystroke\r
+                              state data for the key that was pressed.\r
+\r
+  @retval TRUE                Key be pressed matches a registered key.\r
+  @retval FLASE               Match failed.\r
+\r
+**/\r
+BOOLEAN\r
+IsKeyRegistered (\r
+  IN EFI_KEY_DATA  *RegsiteredData,\r
+  IN EFI_KEY_DATA  *InputData\r
+  );\r
+\r
+/**\r
+  Initialize the key state.\r
+\r
+  @param  ConsoleIn     The KEYBOARD_CONSOLE_IN_DEV instance.\r
+  @param  KeyState      A pointer to receive the key state information.\r
+**/\r
+VOID\r
+InitializeKeyState (\r
+  IN  KEYBOARD_CONSOLE_IN_DEV *ConsoleIn,\r
+  OUT EFI_KEY_STATE           *KeyState\r
+  );\r
 \r
 #endif\r