]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Clean up the Ps2keyboardDxe module
authorklu2 <klu2@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 19 Jun 2009 06:18:09 +0000 (06:18 +0000)
committerklu2 <klu2@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 19 Jun 2009 06:18:09 +0000 (06:18 +0000)
1) Use MicroSecondDelay() produced by TimerLib to replace gBS->Stall
2) Add more command/register/status definition for 8042/8048 chipset and remove hard code value used in driver's source code;
3) Remove some unused function declaration before function implementation.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@8604 6f19259b-4bc3-4df7-8a09-765794883524

IntelFrameworkModulePkg/Bus/Isa/Ps2KeyboardDxe/Ps2KbdCtrller.c
IntelFrameworkModulePkg/Bus/Isa/Ps2KeyboardDxe/Ps2KbdTextIn.c
IntelFrameworkModulePkg/Bus/Isa/Ps2KeyboardDxe/Ps2Keyboard.c
IntelFrameworkModulePkg/Bus/Isa/Ps2KeyboardDxe/Ps2Keyboard.h
IntelFrameworkModulePkg/Bus/Isa/Ps2KeyboardDxe/Ps2keyboardDxe.inf

index 04571c2f95452d686aaf87b40e0e767f6fca0c19..eb03c0c836614f90940c8660683f8acb639d0e18 100644 (file)
@@ -1,5 +1,4 @@
 /**@file\r
-  PS/2 Keyboard driver\r
   Routines that access 8042 keyboard controller\r
 \r
 Copyright (c) 2006 - 2007, Intel Corporation\r
@@ -567,64 +566,6 @@ UINTN  mWaitForValueTimeOut = KEYBOARD_WAITFORVALUE_TIMEOUT;
 \r
 BOOLEAN          mEnableMouseInterface;\r
 \r
-//\r
-// Function declarations\r
-//\r
-UINT8\r
-KeyReadDataRegister (\r
-  IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn\r
-  );\r
-\r
-VOID\r
-KeyWriteDataRegister (\r
-  IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn,\r
-  IN UINT8                   Data\r
-  );\r
-\r
-VOID\r
-KeyWriteCommandRegister (\r
-  IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn,\r
-  IN UINT8                   Data\r
-  );\r
-\r
-VOID\r
-KeyboardError (\r
-  IN KEYBOARD_CONSOLE_IN_DEV*ConsoleIn,\r
-  IN CHAR16                 *ErrMsg // should be a unicode string\r
-  );\r
-\r
-EFI_STATUS\r
-GetScancodeBufHead (\r
-  KEYBOARD_CONSOLE_IN_DEV  *ConsoleIn,\r
-  IN UINT32                Count,\r
-  OUT UINT8                *Buf\r
-  );\r
-\r
-EFI_STATUS\r
-PopScancodeBufHead (\r
-  KEYBOARD_CONSOLE_IN_DEV  *ConsoleIn,\r
-  IN UINT32                Count,\r
-  OUT UINT8                *Buf\r
-  );\r
-\r
-EFI_STATUS\r
-KeyboardWrite (\r
-  IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn,\r
-  IN UINT8                   Data\r
-  );\r
-\r
-EFI_STATUS\r
-KeyboardCommand (\r
-  IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn,\r
-  IN UINT8                   Data\r
-  );\r
-\r
-EFI_STATUS\r
-KeyboardWaitForValue (\r
-  IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn,\r
-  IN UINT8                   Value\r
-  );\r
-\r
 /**\r
   Read data register \r
 \r
@@ -687,9 +628,6 @@ KeyWriteDataRegister (
               &Data\r
               );\r
 \r
-  //\r
-  // outp(ConsoleIn->DataRegisterAddress, Data);\r
-  //\r
 }\r
 \r
 /**\r
@@ -770,11 +708,6 @@ KeyboardError (
   )\r
 {\r
   ConsoleIn->KeyboardErr = TRUE;\r
-\r
-  //\r
-  // gST -> ConOut -> OutputString (gST -> ConOut, L"Keyboard Driver: ");\r
-  // gST -> ConOut -> OutputString (gST -> ConOut, ErrMsg);\r
-  //\r
 }\r
 \r
 /**\r
@@ -784,8 +717,8 @@ KeyboardError (
   the memory buffer or empty the keyboard buffer.\r
   It is registered as running under TPL_NOTIFY\r
 \r
-  @param Event - The timer event\r
-  @param Context - A KEYBOARD_CONSOLE_IN_DEV pointer\r
+  @param Event       The timer event\r
+  @param Context     A KEYBOARD_CONSOLE_IN_DEV pointer\r
 \r
 **/\r
 VOID\r
@@ -814,6 +747,7 @@ KeyboardTimerHandler (
     gBS->RestoreTPL (OldTpl);\r
     return ;\r
   }\r
+\r
   //\r
   // To let KB driver support Hot plug, here should skip the 'resend' command  for the case that\r
   // KB is not connected to system. If KB is not connected to system, driver will find there's  something\r
@@ -827,7 +761,7 @@ KeyboardTimerHandler (
   //\r
   // if there is no key present, just return\r
   //\r
-  if ((KeyReadStatusRegister (Context) & 0x21) != 0x1) {\r
+  if ((KeyReadStatusRegister (Context) & (KEYBOARD_STATUS_REGISTER_TRANSMIT_TIMEOUT|KEYBOARD_STATUS_REGISTER_HAS_OUTPUT_DATA)) != KEYBOARD_STATUS_REGISTER_HAS_OUTPUT_DATA) {\r
     //\r
     // Leave critical section and return\r
     //\r
@@ -1019,13 +953,13 @@ KeyboardRead (
   // wait till output buffer full then perform the read\r
   //\r
   for (TimeOut = 0; TimeOut < KEYBOARD_TIMEOUT; TimeOut += 30) {\r
-    if (KeyReadStatusRegister (ConsoleIn) & 0x01) {\r
+    if (KeyReadStatusRegister (ConsoleIn) & KEYBOARD_STATUS_REGISTER_HAS_OUTPUT_DATA) {\r
       RegFilled = 1;\r
       *Data     = KeyReadDataRegister (ConsoleIn);\r
       break;\r
     }\r
 \r
-    gBS->Stall (30);\r
+    MicroSecondDelay (30);\r
   }\r
 \r
   if (!RegFilled) {\r
@@ -1041,8 +975,8 @@ KeyboardRead (
   @param ConsoleIn Pointer to instance of KEYBOARD_CONSOLE_IN_DEV\r
   @param Data      value wanted to be written\r
 \r
-  @retval EFI_TIMEOUT - GC_TODO: Add description for return value\r
-  @retval EFI_SUCCESS - GC_TODO: Add description for return value\r
+  @retval EFI_TIMEOUT   The input buffer register is full for putting new value util timeout\r
+  @retval EFI_SUCCESS   The new value is sucess put into input buffer register.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -1066,7 +1000,7 @@ KeyboardWrite (
       break;\r
     }\r
 \r
-    gBS->Stall (30);\r
+    MicroSecondDelay (30);\r
   }\r
 \r
   if (!RegEmptied) {\r
@@ -1111,7 +1045,7 @@ KeyboardCommand (
       break;\r
     }\r
 \r
-    gBS->Stall (30);\r
+    MicroSecondDelay (30);\r
   }\r
 \r
   if (!RegEmptied) {\r
@@ -1132,7 +1066,7 @@ KeyboardCommand (
       break;\r
     }\r
 \r
-    gBS->Stall (30);\r
+    MicroSecondDelay (30);\r
   }\r
 \r
   if (!RegEmptied) {\r
@@ -1191,7 +1125,7 @@ KeyboardWaitForValue (
         break;\r
       }\r
 \r
-      gBS->Stall (30);\r
+      MicroSecondDelay (30);\r
     }\r
 \r
     SumTimeOut += TimeOut;\r
@@ -1208,7 +1142,7 @@ KeyboardWaitForValue (
   //\r
   // Check results\r
   //\r
-  if (GotIt) {\r
+  if (GotIt == 1) {\r
     return EFI_SUCCESS;\r
   } else {\r
     return EFI_TIMEOUT;\r
@@ -1222,7 +1156,7 @@ KeyboardWaitForValue (
 \r
   @param ConsoleIn Pointer to instance of KEYBOARD_CONSOLE_IN_DEV\r
   \r
-  @return status\r
+  @return status of updating keyboard register\r
 \r
 **/\r
 EFI_STATUS\r
@@ -1276,8 +1210,8 @@ UpdateStatusLights (
 \r
   @param ConsoleIn KEYBOARD_CONSOLE_IN_DEV instance pointer\r
 \r
-  @retval EFI_NOT_READY - Input from console not ready yet.\r
-  @retval EFI_SUCCESS   - Function executed successfully.\r
+  @retval EFI_NOT_READY  Input from console not ready yet.\r
+  @retval EFI_SUCCESS    Function executed successfully.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -1365,7 +1299,7 @@ KeyGetchar (
   // Check if there are enough bytes of scancode representing a single key\r
   // available in the buffer\r
   //\r
-  while (1) {\r
+  while (TRUE) {\r
 \r
     Status          = GetScancodeBufHead (ConsoleIn, 1, ScancodeArr);\r
     ScancodeArrPos  = 0;\r
@@ -1516,7 +1450,7 @@ KeyGetchar (
   //\r
   if (Extended && ScanCode == 0x35) {\r
     ConsoleIn->Key.ScanCode     = SCAN_NULL;\r
-    ConsoleIn->Key.UnicodeChar  = '/';\r
+    ConsoleIn->Key.UnicodeChar  = L'/';\r
     return EFI_SUCCESS;\r
   }\r
   //\r
@@ -1531,7 +1465,7 @@ KeyGetchar (
         // Need not return associated shift state if a class of printable characters that\r
         // are normally adjusted by shift modifiers. e.g. Shift Key + 'f' key = 'F'\r
         //\r
-        if (ConsoleIn->Key.UnicodeChar >= 'A' && ConsoleIn->Key.UnicodeChar <= 'Z') {\r
+        if (ConsoleIn->Key.UnicodeChar >= L'A' && ConsoleIn->Key.UnicodeChar <= L'Z') {\r
           ConsoleIn->LeftShift  = FALSE;\r
           ConsoleIn->RightShift = FALSE;\r
         }\r
@@ -1542,9 +1476,9 @@ KeyGetchar (
       // alphabetic key is affected by CapsLock State\r
       //\r
       if (ConsoleIn->CapsLock) {\r
-        if (ConsoleIn->Key.UnicodeChar >= 'a' && ConsoleIn->Key.UnicodeChar <= 'z') {\r
+        if (ConsoleIn->Key.UnicodeChar >= L'a' && ConsoleIn->Key.UnicodeChar <= L'z') {\r
           ConsoleIn->Key.UnicodeChar = ConvertKeyboardScanCodeToEfiKey[Index].ShiftUnicodeChar;\r
-        } else if (ConsoleIn->Key.UnicodeChar >= 'A' && ConsoleIn->Key.UnicodeChar <= 'Z') {\r
+        } else if (ConsoleIn->Key.UnicodeChar >= L'A' && ConsoleIn->Key.UnicodeChar <= L'Z') {\r
           ConsoleIn->Key.UnicodeChar = ConvertKeyboardScanCodeToEfiKey[Index].UnicodeChar;\r
         }\r
       }\r
@@ -1552,10 +1486,10 @@ KeyGetchar (
       // Translate the CTRL-Alpha characters to their corresponding control value (ctrl-a = 0x0001 through ctrl-Z = 0x001A)\r
       //\r
       if (ConsoleIn->Ctrled) {\r
-        if (ConsoleIn->Key.UnicodeChar >= 'a' && ConsoleIn->Key.UnicodeChar <= 'z') {\r
-          ConsoleIn->Key.UnicodeChar = (UINT16) (ConsoleIn->Key.UnicodeChar - 'a' + 1);\r
-        } else if (ConsoleIn->Key.UnicodeChar >= 'A' && ConsoleIn->Key.UnicodeChar <= 'Z') {\r
-          ConsoleIn->Key.UnicodeChar = (UINT16) (ConsoleIn->Key.UnicodeChar - 'A' + 1);\r
+        if (ConsoleIn->Key.UnicodeChar >= L'a' && ConsoleIn->Key.UnicodeChar <= L'z') {\r
+          ConsoleIn->Key.UnicodeChar = (UINT16) (ConsoleIn->Key.UnicodeChar - L'a' + 1);\r
+        } else if (ConsoleIn->Key.UnicodeChar >= L'A' && ConsoleIn->Key.UnicodeChar <= L'Z') {\r
+          ConsoleIn->Key.UnicodeChar = (UINT16) (ConsoleIn->Key.UnicodeChar - L'A' + 1);\r
         }\r
       }\r
 \r
@@ -1571,13 +1505,13 @@ KeyGetchar (
     if (ConsoleIn->NumLock && !ConsoleIn->Shift && !Extended) {\r
       ConsoleIn->Key.ScanCode = SCAN_NULL;\r
     } else if (ScanCode != 0x4a && ScanCode != 0x4e) {\r
-      ConsoleIn->Key.UnicodeChar = 0x00;\r
+      ConsoleIn->Key.UnicodeChar = 0x0000;\r
     }\r
   }\r
   //\r
   // If the key can not be converted then just return.\r
   //\r
-  if (ConsoleIn->Key.ScanCode == SCAN_NULL && ConsoleIn->Key.UnicodeChar == 0x00) {\r
+  if (ConsoleIn->Key.ScanCode == SCAN_NULL && ConsoleIn->Key.UnicodeChar == 0x0000) {\r
     return EFI_NOT_READY;\r
   }\r
 \r
@@ -1690,7 +1624,7 @@ InitKeyboard (
   // Test the system flag in to determine whether this is the first\r
   // time initialization\r
   //\r
-  if ((KeyReadStatusRegister (ConsoleIn) & 0x04)) {\r
+  if ((KeyReadStatusRegister (ConsoleIn) & KEYBOARD_STATUS_REGISTER_SYSTEM_FLAG)) {\r
     //\r
     // 8042 controller is already setup (by myself or by mouse driver):\r
     //   See whether mouse interface is already enabled\r
@@ -1699,7 +1633,7 @@ InitKeyboard (
     //\r
     // Read the command byte of 8042 controller\r
     //\r
-    Status = KeyboardCommand (ConsoleIn, 0x20);\r
+    Status = KeyboardCommand (ConsoleIn, KEYBOARD_8042_COMMAND_READ);\r
     if (EFI_ERROR (Status)) {\r
       KeyboardError (ConsoleIn, L"\n\r");\r
       goto Done;\r
@@ -1728,13 +1662,13 @@ InitKeyboard (
     //\r
     // Disable keyboard and mouse interfaces\r
     //\r
-    Status = KeyboardCommand (ConsoleIn, 0xad);\r
+    Status = KeyboardCommand (ConsoleIn, KEYBOARD_8042_COMMAND_DISABLE_KEYBOARD_INTERFACE);\r
     if (EFI_ERROR (Status)) {\r
       KeyboardError (ConsoleIn, L"\n\r");\r
       goto Done;\r
     }\r
 \r
-    Status = KeyboardCommand (ConsoleIn, 0xa7);\r
+    Status = KeyboardCommand (ConsoleIn, KEYBOARD_8042_COMMAND_DISABLE_MOUSE_INTERFACE);\r
     if (EFI_ERROR (Status)) {\r
       KeyboardError (ConsoleIn, L"\n\r");\r
       goto Done;\r
@@ -1748,7 +1682,7 @@ InitKeyboard (
     //\r
     // 8042 Controller Self Test\r
     //\r
-    Status = KeyboardCommand (ConsoleIn, 0xaa);\r
+    Status = KeyboardCommand (ConsoleIn, KEYBOARD_8042_COMMAND_CONTROLLER_SELF_TEST);\r
     if (EFI_ERROR (Status)) {\r
       KeyboardError (ConsoleIn, L"8042 controller command write error!\n\r");\r
       goto Done;\r
@@ -1787,7 +1721,7 @@ InitKeyboard (
   //  1: Enable Auxiliary device interrupt\r
   //  0: Enable Keyboard interrupt )\r
   //\r
-  Status = KeyboardCommand (ConsoleIn, 0x60);\r
+  Status = KeyboardCommand (ConsoleIn, KEYBOARD_8042_COMMAND_WRITE);\r
   if (EFI_ERROR (Status)) {\r
     KeyboardError (ConsoleIn, L"8042 controller command write error!\n\r");\r
     goto Done;\r
@@ -1837,7 +1771,7 @@ InitKeyboard (
     //\r
     // Keyboard Interface Test\r
     //\r
-    Status = KeyboardCommand (ConsoleIn, 0xab);\r
+    Status = KeyboardCommand (ConsoleIn, KEYBOARD_8042_COMMAND_KEYBOARD_INTERFACE_SELF_TEST);\r
     if (EFI_ERROR (Status)) {\r
       KeyboardError (ConsoleIn, L"8042 controller command write error!\n\r");\r
       goto Done;\r
@@ -1854,13 +1788,13 @@ InitKeyboard (
     //\r
     // Keyboard reset with a BAT(Basic Assurance Test)\r
     //\r
-    Status = KeyboardWrite (ConsoleIn, 0xff);\r
+    Status = KeyboardWrite (ConsoleIn, KEYBOARD_8048_COMMAND_RESET);\r
     if (EFI_ERROR (Status)) {\r
       KeyboardError (ConsoleIn, L"8042 controller data write error!\n\r");\r
       goto Done;\r
     }\r
 \r
-    Status = KeyboardWaitForValue (ConsoleIn, 0xfa);\r
+    Status = KeyboardWaitForValue (ConsoleIn, KEYBOARD_8048_RETURN_8042_ACK);\r
     if (EFI_ERROR (Status)) {\r
       KeyboardError (ConsoleIn, L"Some specific value not aquired from 8042 controller!\n\r");\r
       goto Done;\r
@@ -1870,7 +1804,7 @@ InitKeyboard (
     //\r
     mWaitForValueTimeOut  = KEYBOARD_BAT_TIMEOUT;\r
 \r
-    Status                = KeyboardWaitForValue (ConsoleIn, 0xaa);\r
+    Status                = KeyboardWaitForValue (ConsoleIn, KEYBOARD_8048_RETURN_8042_BAT_SUCCESS);\r
     if (EFI_ERROR (Status)) {\r
       KeyboardError (ConsoleIn, L"Keyboard self test failed!\n\r");\r
       goto Done;\r
@@ -1881,13 +1815,13 @@ InitKeyboard (
     //\r
     // Set Keyboard to use Scan Code Set 2\r
     //\r
-    Status = KeyboardWrite (ConsoleIn, 0xf0);\r
+    Status = KeyboardWrite (ConsoleIn, KEYBOARD_8048_COMMAND_SELECT_SCAN_CODE_SET);\r
     if (EFI_ERROR (Status)) {\r
       KeyboardError (ConsoleIn, L"8042 controller data write error!\n\r");\r
       goto Done;\r
     }\r
 \r
-    Status = KeyboardWaitForValue (ConsoleIn, 0xfa);\r
+    Status = KeyboardWaitForValue (ConsoleIn, KEYBOARD_8048_RETURN_8042_ACK);\r
     if (EFI_ERROR (Status)) {\r
       KeyboardError (ConsoleIn, L"Some specific value not aquired from 8042 controller!\n\r");\r
       goto Done;\r
@@ -1899,7 +1833,7 @@ InitKeyboard (
       goto Done;\r
     }\r
 \r
-    Status = KeyboardWaitForValue (ConsoleIn, 0xfa);\r
+    Status = KeyboardWaitForValue (ConsoleIn, KEYBOARD_8048_RETURN_8042_ACK);\r
     if (EFI_ERROR (Status)) {\r
       KeyboardError (ConsoleIn, L"Some specific value not aquired from 8042 controller!\n\r");\r
       goto Done;\r
@@ -1908,13 +1842,13 @@ InitKeyboard (
   //\r
   // Clear Keyboard Scancode Buffer\r
   //\r
-  Status = KeyboardWrite (ConsoleIn, 0xf4);\r
+  Status = KeyboardWrite (ConsoleIn, KEYBOARD_8048_COMMAND_CLEAR_OUTPUT_DATA);\r
   if (EFI_ERROR (Status)) {\r
     KeyboardError (ConsoleIn, L"8042 controller data write error!\n\r");\r
     goto Done;\r
   }\r
 \r
-  Status = KeyboardWaitForValue (ConsoleIn, 0xfa);\r
+  Status = KeyboardWaitForValue (ConsoleIn, KEYBOARD_8048_RETURN_8042_ACK);\r
   if (EFI_ERROR (Status)) {\r
     KeyboardError (ConsoleIn, L"Some specific value not aquired from 8042 controller!\n\r");\r
     goto Done;\r
@@ -1951,7 +1885,7 @@ Done:
     //\r
     // Enable mouse interface\r
     //\r
-    Status1 = KeyboardCommand (ConsoleIn, 0xa8);\r
+    Status1 = KeyboardCommand (ConsoleIn, KEYBOARD_8042_COMMAND_ENABLE_MOUSE_INTERFACE);\r
     if (EFI_ERROR (Status1)) {\r
       KeyboardError (ConsoleIn, L"8042 controller command write error!\n\r");\r
       return EFI_DEVICE_ERROR;\r
@@ -1984,7 +1918,7 @@ DisableKeyboard (
   //\r
   // Disable keyboard interface\r
   //\r
-  Status = KeyboardCommand (ConsoleIn, 0xad);\r
+  Status = KeyboardCommand (ConsoleIn, KEYBOARD_8042_COMMAND_DISABLE_KEYBOARD_INTERFACE);\r
   if (EFI_ERROR (Status)) {\r
     KeyboardError (ConsoleIn, L"\n\r");\r
     return EFI_DEVICE_ERROR;\r
index cc4ce812f111935bb5df2ab56a00be495b6b359b..49245c6496834a94f35615f954e4e41292df78c4 100644 (file)
@@ -1,6 +1,6 @@
 /**@file\r
-  PS/2 Keyboard  driver\r
-  Routines that support SIMPLE_TEXT_IN protocol\r
+  Routines implements SIMPLE_TEXT_IN protocol's interfaces based on 8042 interfaces\r
+  provided by Ps2KbdCtrller.c.\r
 \r
 Copyright (c) 2006 - 2007, Intel Corporation\r
 All rights reserved. This program and the accompanying materials\r
@@ -16,66 +16,89 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include "Ps2Keyboard.h"\r
 \r
-//\r
-// function declarations\r
-//\r
+/**\r
+  Check keyboard for given key value\r
+  \r
+  @param  This  Point to instance of EFI_SIMPLE_TEXT_INPUT_PROTOCOL\r
+  \r
+  @retval EFI_SUCCESS   success check keyboard value\r
+  @retval !EFI_SUCCESS  Fail to get char from keyboard\r
+**/\r
 EFI_STATUS\r
-EFIAPI\r
-KeyboardEfiReset (\r
-  IN  EFI_SIMPLE_TEXT_INPUT_PROTOCOL  *This,\r
-  IN  BOOLEAN                         ExtendedVerification\r
-  );\r
+KeyboardCheckForKey (\r
+  IN  EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This\r
+  )\r
+{\r
+  KEYBOARD_CONSOLE_IN_DEV *ConsoleIn;\r
 \r
-EFI_STATUS\r
-EFIAPI\r
-KeyboardReadKeyStroke (\r
-  IN  EFI_SIMPLE_TEXT_INPUT_PROTOCOL  *This,\r
-  OUT EFI_INPUT_KEY                   *Key\r
-  );\r
+  ConsoleIn = KEYBOARD_CONSOLE_IN_DEV_FROM_THIS (This);\r
 \r
-VOID\r
-EFIAPI\r
-KeyboardWaitForKey (\r
-  IN  EFI_EVENT               Event,\r
-  IN  VOID                    *Context\r
-  );\r
+  //\r
+  // If ready to read next key, check it\r
+  //\r
+  if (ConsoleIn->Key.ScanCode == SCAN_NULL && ConsoleIn->Key.UnicodeChar == 0x00) {\r
+    return KeyGetchar (ConsoleIn);\r
+  }\r
 \r
-EFI_STATUS\r
-KeyboardCheckForKey (\r
-  IN  EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This\r
-  );\r
+  return EFI_SUCCESS;\r
+}\r
 \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
+  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 FALSE             - Match failed. \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
+{\r
+  ASSERT (RegsiteredData != NULL && InputData != NULL);\r
+  \r
+  if ((RegsiteredData->Key.ScanCode    != InputData->Key.ScanCode) ||\r
+      (RegsiteredData->Key.UnicodeChar != InputData->Key.UnicodeChar)) {\r
+    return FALSE;  \r
+  }      \r
+  \r
+  //\r
+  // Assume KeyShiftState/KeyToggleState = 0 in Registered key data means these state could be ignored.\r
+  //\r
+  if (RegsiteredData->KeyState.KeyShiftState != 0 &&\r
+      RegsiteredData->KeyState.KeyShiftState != InputData->KeyState.KeyShiftState) {\r
+    return FALSE;    \r
+  }   \r
+  if (RegsiteredData->KeyState.KeyToggleState != 0 &&\r
+      RegsiteredData->KeyState.KeyToggleState != InputData->KeyState.KeyToggleState) {\r
+    return FALSE;    \r
+  }     \r
+  \r
+  return TRUE;\r
+\r
+}\r
 \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
   \r
-    @param ConsoleInDev          Ps2 Keyboard private structure\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
+    @param ConsoleInDev          Ps2 Keyboard private structure\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
-    @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
+    @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
@@ -90,6 +113,7 @@ KeyboardReadKeyStrokeWorker (
   LIST_ENTRY                            *Link;\r
   KEYBOARD_CONSOLE_IN_EX_NOTIFY         *CurrentNotify;\r
   EFI_KEY_DATA                          OriginalKeyData;\r
+  \r
   if (KeyData == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
@@ -111,6 +135,7 @@ KeyboardReadKeyStrokeWorker (
     gBS->RestoreTPL (OldTpl);\r
     return EFI_NOT_READY;\r
   }\r
+  \r
   CopyMem (&KeyData->Key, &ConsoleInDev->Key, sizeof (EFI_INPUT_KEY));\r
 \r
   ConsoleInDev->Key.ScanCode    = SCAN_NULL;          \r
@@ -128,9 +153,9 @@ KeyboardReadKeyStrokeWorker (
   if (ConsoleInDev->Ctrled) {\r
     if (OriginalKeyData.Key.UnicodeChar >= 0x01 && OriginalKeyData.Key.UnicodeChar <= 0x1A) {\r
       if (ConsoleInDev->CapsLock) {\r
-        OriginalKeyData.Key.UnicodeChar = (CHAR16)(OriginalKeyData.Key.UnicodeChar + 'A' - 1);\r
+        OriginalKeyData.Key.UnicodeChar = (CHAR16)(OriginalKeyData.Key.UnicodeChar + L'A' - 1);\r
       } else {\r
-        OriginalKeyData.Key.UnicodeChar = (CHAR16)(OriginalKeyData.Key.UnicodeChar + 'a' - 1);\r
+        OriginalKeyData.Key.UnicodeChar = (CHAR16)(OriginalKeyData.Key.UnicodeChar + L'a' - 1);\r
       } \r
     }\r
   }\r
@@ -153,11 +178,9 @@ KeyboardReadKeyStrokeWorker (
 }\r
 \r
 /**\r
-  logic reset keyboard\r
-  Implement SIMPLE_TEXT_IN.Reset()\r
-  Perform 8042 controller and keyboard initialization\r
+  Perform 8042 controller and keyboard initialization which implement SIMPLE_TEXT_IN.Reset()\r
 \r
-  @param This    Pointer to instance of EFI_SIMPLE_TEXT_INPUT_PROTOCOL\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
@@ -237,8 +260,7 @@ KeyboardEfiReset (
 }\r
 \r
 /**\r
-  Implement SIMPLE_TEXT_IN.ReadKeyStroke().\r
-  Retrieve key values for driver user.\r
+  Retrieve key values for driver user which implement SIMPLE_TEXT_IN.ReadKeyStroke().\r
 \r
   @param This    Pointer to instance of EFI_SIMPLE_TEXT_INPUT_PROTOCOL\r
   @param Key     The output buffer for key value \r
@@ -314,74 +336,6 @@ KeyboardWaitForKey (
   return ;\r
 }\r
 \r
-/**\r
-  Check keyboard for given key value\r
-  \r
-  @param  This  Point to instance of EFI_SIMPLE_TEXT_INPUT_PROTOCOL\r
-  \r
-  @retval EFI_SUCCESS success check keyboard value\r
-**/\r
-EFI_STATUS\r
-KeyboardCheckForKey (\r
-  IN  EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This\r
-  )\r
-{\r
-  KEYBOARD_CONSOLE_IN_DEV *ConsoleIn;\r
-\r
-  ConsoleIn = KEYBOARD_CONSOLE_IN_DEV_FROM_THIS (This);\r
-\r
-  //\r
-  // If ready to read next key, check it\r
-  //\r
-  if (ConsoleIn->Key.ScanCode == SCAN_NULL && ConsoleIn->Key.UnicodeChar == 0x00) {\r
-    return KeyGetchar (ConsoleIn);\r
-  }\r
-\r
-  return EFI_SUCCESS;\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
-  ASSERT (RegsiteredData != NULL && InputData != NULL);\r
-  \r
-  if ((RegsiteredData->Key.ScanCode    != InputData->Key.ScanCode) ||\r
-      (RegsiteredData->Key.UnicodeChar != InputData->Key.UnicodeChar)) {\r
-    return FALSE;  \r
-  }      \r
-  \r
-  //\r
-  // Assume KeyShiftState/KeyToggleState = 0 in Registered key data means these state could be ignored.\r
-  //\r
-  if (RegsiteredData->KeyState.KeyShiftState != 0 &&\r
-      RegsiteredData->KeyState.KeyShiftState != InputData->KeyState.KeyShiftState) {\r
-    return FALSE;    \r
-  }   \r
-  if (RegsiteredData->KeyState.KeyToggleState != 0 &&\r
-      RegsiteredData->KeyState.KeyToggleState != InputData->KeyState.KeyToggleState) {\r
-    return FALSE;    \r
-  }     \r
-  \r
-  return TRUE;\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
@@ -408,11 +362,11 @@ KeyboardWaitForKeyEx (
 /**\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
+  @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
+  @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
@@ -456,15 +410,15 @@ KeyboardEfiResetEx (
     be used to test for existance of a keystroke via WaitForEvent () call.\r
 \r
 \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
+    @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
-    @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
+    @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
@@ -489,15 +443,15 @@ KeyboardReadKeyStrokeEx (
 /**\r
   Set certain state for the input device.\r
 \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
+  @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
-  @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
+  @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
@@ -571,16 +525,16 @@ Exit:
 /**\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.\r
-    @param KeyNotificationFunction - Points to the function to be called when the key \r
-                              sequence is typed specified by KeyData.                        \r
-    @param NotifyHandle            - Points to the unique handle assigned to the registered notification.                          \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.\r
+    @param KeyNotificationFunction    Points to the function to be called when the key \r
+                                      sequence is typed specified by KeyData.                        \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
+    @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 or KeyNotificationFunction is NULL.                       \r
                               \r
 **/   \r
 EFI_STATUS\r
@@ -659,12 +613,12 @@ Exit:
 /**\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
+    @param This                       Protocol instance pointer.    \r
+    @param NotificationHandle         The handle of the notification function being unregistered.\r
 \r
   \r
-    @retval EFI_SUCCESS             - The notification function was unregistered successfully.\r
-    @retval EFI_INVALID_PARAMETER   - The NotificationHandle is invalid.\r
+    @retval EFI_SUCCESS               The notification function was unregistered successfully.\r
+    @retval EFI_INVALID_PARAMETER     The NotificationHandle is invalid.\r
                               \r
 **/   \r
 EFI_STATUS\r
index 7c7c0bf27a1bf6c1f38f253fa58167732c8ad814..060a172ddf9c359bfd0add1f57bd52574c29d03b 100644 (file)
@@ -555,7 +555,7 @@ KbdFreeNotifyList (
 }\r
 \r
 /**\r
-  The user Entry Point for module Ps2Keyboard. The user code starts with this function.\r
+  The module Entry Point for module Ps2Keyboard. \r
 \r
   @param[in] ImageHandle    The firmware allocated handle for the EFI image.  \r
   @param[in] SystemTable    A pointer to the EFI System Table.\r
index fd97f28d2e3f2037f483c20411b4c0c04e584c33..5bf3a6eefc36a19653ec1ada209af6a760ed01f0 100644 (file)
@@ -33,6 +33,7 @@ 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
 \r
 //\r
 // Global Variables\r
@@ -180,6 +181,32 @@ InstallPs2KeyboardDriver (
 #define SCANCODE_SYS_REQ_MAKE           0x37\r
 #define SCANCODE_MAX_MAKE               0x60\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
index 01d01df48d3bd738d028e1bd1ce447599c4e6f8a..2f0b46b6f6fc8ca4702f2076b191f52e637b94f2 100644 (file)
@@ -54,7 +54,8 @@
   UefiDriverEntryPoint\r
   BaseLib\r
   BaseMemoryLib\r
-\r
+  TimerLib\r
+  \r
 [Protocols]\r
   gEfiPs2PolicyProtocolGuid                     # PROTOCOL TO_START\r
   gEfiIsaIoProtocolGuid                         # PROTOCOL TO_START\r