]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Bus/Isa/Ps2KeyboardDxe/Ps2KbdCtrller.c
FatPkg: Clean up source files
[mirror_edk2.git] / IntelFrameworkModulePkg / Bus / Isa / Ps2KeyboardDxe / Ps2KbdCtrller.c
index e8f474a3268b43f4c36f5c51cd0da77f5909bc0f..48d8efd516089228d8f304c5efa625d67cb96220 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Routines that access 8042 keyboard controller\r
 \r
-Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\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
@@ -1140,6 +1140,38 @@ UpdateStatusLights (
   return Status;\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
+  KeyState->KeyShiftState  = EFI_SHIFT_STATE_VALID\r
+                           | (ConsoleIn->LeftCtrl   ? EFI_LEFT_CONTROL_PRESSED  : 0)\r
+                           | (ConsoleIn->RightCtrl  ? EFI_RIGHT_CONTROL_PRESSED : 0)\r
+                           | (ConsoleIn->LeftAlt    ? EFI_LEFT_ALT_PRESSED      : 0)\r
+                           | (ConsoleIn->RightAlt   ? EFI_RIGHT_ALT_PRESSED     : 0)\r
+                           | (ConsoleIn->LeftShift  ? EFI_LEFT_SHIFT_PRESSED    : 0)\r
+                           | (ConsoleIn->RightShift ? EFI_RIGHT_SHIFT_PRESSED   : 0)\r
+                           | (ConsoleIn->LeftLogo   ? EFI_LEFT_LOGO_PRESSED     : 0)\r
+                           | (ConsoleIn->RightLogo  ? EFI_RIGHT_LOGO_PRESSED    : 0)\r
+                           | (ConsoleIn->Menu       ? EFI_MENU_KEY_PRESSED      : 0)\r
+                           | (ConsoleIn->SysReq     ? EFI_SYS_REQ_PRESSED       : 0)\r
+                           ;\r
+  KeyState->KeyToggleState = EFI_TOGGLE_STATE_VALID\r
+                           | (ConsoleIn->CapsLock   ? EFI_CAPS_LOCK_ACTIVE :   0)\r
+                           | (ConsoleIn->NumLock    ? EFI_NUM_LOCK_ACTIVE :    0)\r
+                           | (ConsoleIn->ScrollLock ? EFI_SCROLL_LOCK_ACTIVE : 0)\r
+                           | (ConsoleIn->IsSupportPartialKey ? EFI_KEY_STATE_EXPOSED : 0)\r
+                           ;\r
+}\r
+\r
 /**\r
   Get scancode from scancode buffer and translate into EFI-scancode and unicode defined by EFI spec.\r
 \r
@@ -1352,27 +1384,9 @@ KeyGetchar (
   //\r
   // Save the Shift/Toggle state\r
   //\r
-  KeyData.KeyState.KeyShiftState = (UINT32) (EFI_SHIFT_STATE_VALID\r
-                                 | (ConsoleIn->LeftCtrl   ? EFI_LEFT_CONTROL_PRESSED  : 0)\r
-                                 | (ConsoleIn->RightCtrl  ? EFI_RIGHT_CONTROL_PRESSED : 0)\r
-                                 | (ConsoleIn->LeftAlt    ? EFI_LEFT_ALT_PRESSED      : 0)\r
-                                 | (ConsoleIn->RightAlt   ? EFI_RIGHT_ALT_PRESSED     : 0)\r
-                                 | (ConsoleIn->LeftShift  ? EFI_LEFT_SHIFT_PRESSED    : 0)\r
-                                 | (ConsoleIn->RightShift ? EFI_RIGHT_SHIFT_PRESSED   : 0)\r
-                                 | (ConsoleIn->LeftLogo   ? EFI_LEFT_LOGO_PRESSED     : 0)\r
-                                 | (ConsoleIn->RightLogo  ? EFI_RIGHT_LOGO_PRESSED    : 0)\r
-                                 | (ConsoleIn->Menu       ? EFI_MENU_KEY_PRESSED      : 0)\r
-                                 | (ConsoleIn->SysReq     ? EFI_SYS_REQ_PRESSED       : 0)\r
-                                 );\r
-  KeyData.KeyState.KeyToggleState = (EFI_KEY_TOGGLE_STATE) (EFI_TOGGLE_STATE_VALID\r
-                                  | (ConsoleIn->CapsLock   ? EFI_CAPS_LOCK_ACTIVE :   0)\r
-                                  | (ConsoleIn->NumLock    ? EFI_NUM_LOCK_ACTIVE :    0)\r
-                                  | (ConsoleIn->ScrollLock ? EFI_SCROLL_LOCK_ACTIVE : 0)\r
-                                  | (ConsoleIn->IsSupportPartialKey ? EFI_KEY_STATE_EXPOSED : 0)\r
-                                  );\r
-\r
-  KeyData.Key.ScanCode            = SCAN_NULL;\r
-  KeyData.Key.UnicodeChar         = CHAR_NULL;\r
+  InitializeKeyState (ConsoleIn, &KeyData.KeyState);\r
+  KeyData.Key.ScanCode    = SCAN_NULL;\r
+  KeyData.Key.UnicodeChar = CHAR_NULL;\r
 \r
   //\r
   // Key Pad "/" shares the same scancode as that of "/" except Key Pad "/" has E0 prefix\r
@@ -1456,7 +1470,7 @@ KeyGetchar (
   }\r
 \r
   //\r
-  // Invoke notification functions if exist\r
+  // Signal KeyNotify process event if this key pressed matches any key registered.\r
   //\r
   for (Link = GetFirstNode (&ConsoleIn->NotifyList); !IsNull (&ConsoleIn->NotifyList, Link); Link = GetNextNode (&ConsoleIn->NotifyList, Link)) {\r
     CurrentNotify = CR (\r
@@ -1466,18 +1480,13 @@ KeyGetchar (
                       KEYBOARD_CONSOLE_IN_EX_NOTIFY_SIGNATURE\r
                       );\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 (ctrl-a = 0x0001 through ctrl-Z = 0x001A)\r
-  //\r
-  if (ConsoleIn->LeftCtrl || ConsoleIn->RightCtrl) {\r
-    if (KeyData.Key.UnicodeChar >= L'a' && KeyData.Key.UnicodeChar <= L'z') {\r
-      KeyData.Key.UnicodeChar = (UINT16) (KeyData.Key.UnicodeChar - L'a' + 1);\r
-    } else if (KeyData.Key.UnicodeChar >= L'A' && KeyData.Key.UnicodeChar <= L'Z') {\r
-      KeyData.Key.UnicodeChar = (UINT16) (KeyData.Key.UnicodeChar - L'A' + 1);\r
+      //\r
+      // The key notification function needs to run at TPL_CALLBACK\r
+      // while current TPL is TPL_NOTIFY. It will be invoked in\r
+      // KeyNotifyProcessHandler() which runs at TPL_CALLBACK.\r
+      //\r
+      PushEfikeyBufTail (&ConsoleIn->EfiKeyQueueForNotify, &KeyData);\r
+      gBS->SignalEvent (ConsoleIn->KeyNotifyProcessEvent);\r
     }\r
   }\r
 \r
@@ -1530,16 +1539,18 @@ InitKeyboard (
   // Perform a read to cleanup the Status Register's\r
   // output buffer full bits within MAX TRY times\r
   //\r
-  while (!EFI_ERROR (Status) && TryTime < KEYBOARD_MAX_TRY) {\r
-    Status = KeyboardRead (ConsoleIn, &CommandByte);\r
-    TryTime ++;\r
-  }\r
-  //\r
-  // Exceed the max try times. The device may be error.\r
-  //\r
-  if (TryTime == KEYBOARD_MAX_TRY) {\r
-       Status = EFI_DEVICE_ERROR;\r
-       goto Done;\r
+  if ((KeyReadStatusRegister (ConsoleIn) & KEYBOARD_STATUS_REGISTER_HAS_OUTPUT_DATA) != 0) {\r
+    while (!EFI_ERROR (Status) && TryTime < KEYBOARD_MAX_TRY) {\r
+      Status = KeyboardRead (ConsoleIn, &CommandByte);\r
+      TryTime ++;\r
+    }\r
+    //\r
+    // Exceed the max try times. The device may be error.\r
+    //\r
+    if (TryTime == KEYBOARD_MAX_TRY) {\r
+       Status = EFI_DEVICE_ERROR;\r
+       goto Done;\r
+    }\r
   }\r
   //\r
   // We should disable mouse interface during the initialization process\r
@@ -1554,34 +1565,37 @@ InitKeyboard (
   // time initialization\r
   //\r
   if ((KeyReadStatusRegister (ConsoleIn) & KEYBOARD_STATUS_REGISTER_SYSTEM_FLAG) != 0) {\r
-    //\r
-    // 8042 controller is already setup (by myself or by mouse driver):\r
-    //   See whether mouse interface is already enabled\r
-    //   which determines whether we should enable it later\r
-    //\r
-    //\r
-    // Read the command byte of 8042 controller\r
-    //\r
-    Status = KeyboardCommand (ConsoleIn, KEYBOARD_8042_COMMAND_READ);\r
-    if (EFI_ERROR (Status)) {\r
-      KeyboardError (ConsoleIn, L"\n\r");\r
-      goto Done;\r
-    }\r
-\r
-    Status = KeyboardRead (ConsoleIn, &CommandByte);\r
-    if (EFI_ERROR (Status)) {\r
-      KeyboardError (ConsoleIn, L"\n\r");\r
-      goto Done;\r
-    }\r
-    //\r
-    // Test the mouse enabling bit\r
-    //\r
-    if ((CommandByte & 0x20) != 0) {\r
-      mEnableMouseInterface = FALSE;\r
+    if (!PcdGetBool (PcdFastPS2Detection)) {\r
+      //\r
+      // 8042 controller is already setup (by myself or by mouse driver):\r
+      //   See whether mouse interface is already enabled\r
+      //   which determines whether we should enable it later\r
+      //\r
+      //\r
+      // Read the command byte of 8042 controller\r
+      //\r
+      Status = KeyboardCommand (ConsoleIn, KEYBOARD_8042_COMMAND_READ);\r
+      if (EFI_ERROR (Status)) {\r
+        KeyboardError (ConsoleIn, L"\n\r");\r
+        goto Done;\r
+      }\r
+      \r
+      Status = KeyboardRead (ConsoleIn, &CommandByte);\r
+      if (EFI_ERROR (Status)) {\r
+        KeyboardError (ConsoleIn, L"\n\r");\r
+        goto Done;\r
+      }\r
+      //\r
+      // Test the mouse enabling bit\r
+      //\r
+      if ((CommandByte & 0x20) != 0) {\r
+        mEnableMouseInterface = FALSE;\r
+      } else {\r
+        mEnableMouseInterface = TRUE;\r
+      }\r
     } else {\r
-      mEnableMouseInterface = TRUE;\r
-    }\r
-\r
+      mEnableMouseInterface = FALSE;\r
+    } \r
   } else {\r
     //\r
     // 8042 controller is not setup yet:\r
@@ -1591,36 +1605,38 @@ InitKeyboard (
     //\r
     // Disable keyboard and mouse interfaces\r
     //\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, KEYBOARD_8042_COMMAND_DISABLE_MOUSE_INTERFACE);\r
-    if (EFI_ERROR (Status)) {\r
-      KeyboardError (ConsoleIn, L"\n\r");\r
-      goto Done;\r
-    }\r
-\r
-    REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
-      EFI_PROGRESS_CODE,\r
-      EFI_PERIPHERAL_KEYBOARD | EFI_P_KEYBOARD_PC_SELF_TEST,\r
-      ConsoleIn->DevicePath\r
-      );\r
-    //\r
-    // 8042 Controller Self Test\r
-    //\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
-    }\r
-\r
-    Status = KeyboardWaitForValue (ConsoleIn, 0x55);\r
-    if (EFI_ERROR (Status)) {\r
-      KeyboardError (ConsoleIn, L"8042 controller self test failed!\n\r");\r
-      goto Done;\r
+    if (!PcdGetBool (PcdFastPS2Detection)) {\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, KEYBOARD_8042_COMMAND_DISABLE_MOUSE_INTERFACE);\r
+      if (EFI_ERROR (Status)) {\r
+        KeyboardError (ConsoleIn, L"\n\r");\r
+        goto Done;\r
+      }\r
+      \r
+      REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
+        EFI_PROGRESS_CODE,\r
+        EFI_PERIPHERAL_KEYBOARD | EFI_P_KEYBOARD_PC_SELF_TEST,\r
+        ConsoleIn->DevicePath\r
+        );\r
+      //\r
+      // 8042 Controller Self Test\r
+      //\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
+      }\r
+      \r
+      Status = KeyboardWaitForValue (ConsoleIn, 0x55);\r
+      if (EFI_ERROR (Status)) {\r
+        KeyboardError (ConsoleIn, L"8042 controller self test failed!\n\r");\r
+        goto Done;\r
+      }\r
     }\r
     //\r
     // Don't enable mouse interface later\r
@@ -1669,6 +1685,8 @@ InitKeyboard (
   ConsoleIn->ScancodeQueue.Tail = 0;\r
   ConsoleIn->EfiKeyQueue.Head   = 0;\r
   ConsoleIn->EfiKeyQueue.Tail   = 0;\r
+  ConsoleIn->EfiKeyQueueForNotify.Head = 0;\r
+  ConsoleIn->EfiKeyQueueForNotify.Tail = 0;\r
 \r
   //\r
   // Reset the status indicators\r
@@ -1689,9 +1707,9 @@ InitKeyboard (
 \r
   ConsoleIn->IsSupportPartialKey = FALSE;\r
   //\r
-  // For reseting keyboard is not mandatory before booting OS and sometimes keyboard responses very slow,\r
+  // For resetting keyboard is not mandatory before booting OS and sometimes keyboard responses very slow,\r
   // and to support KB hot plug, we need to let the InitKB succeed no matter whether there is a KB device connected\r
-  // to system. So we only do the real reseting for keyboard when user asks and there is a real KB connected t system,\r
+  // to system. So we only do the real resetting for keyboard when user asks and there is a real KB connected t system,\r
   // and normally during booting an OS, it's skipped.\r
   //\r
   if (ExtendedVerification && CheckKeyboardConnect (ConsoleIn)) {\r
@@ -1876,34 +1894,37 @@ CheckKeyboardConnect (
   EFI_STATUS     Status;\r
   UINTN          WaitForValueTimeOutBcakup;\r
 \r
-  Status = EFI_SUCCESS;\r
   //\r
   // enable keyboard itself and wait for its ack\r
   // If can't receive ack, Keyboard should not be connected.\r
   //\r
-  Status = KeyboardWrite (\r
-             ConsoleIn,\r
-             KEYBOARD_KBEN\r
-             );\r
-\r
-  if (EFI_ERROR (Status)) {\r
-    return FALSE;\r
-  }\r
-  //\r
-  // wait for 1s\r
-  //\r
-  WaitForValueTimeOutBcakup = mWaitForValueTimeOut;\r
-  mWaitForValueTimeOut = KEYBOARD_WAITFORVALUE_TIMEOUT;\r
-  Status = KeyboardWaitForValue (\r
-             ConsoleIn,\r
-             KEYBOARD_CMDECHO_ACK\r
-             );\r
-  mWaitForValueTimeOut = WaitForValueTimeOutBcakup;\r
-\r
-  if (EFI_ERROR (Status)) {\r
-    return FALSE;\r
+  if (!PcdGetBool (PcdFastPS2Detection)) {\r
+    Status = KeyboardWrite (\r
+               ConsoleIn,\r
+               KEYBOARD_KBEN\r
+               );\r
+    \r
+    if (EFI_ERROR (Status)) {\r
+      return FALSE;\r
+    }\r
+    //\r
+    // wait for 1s\r
+    //\r
+    WaitForValueTimeOutBcakup = mWaitForValueTimeOut;\r
+    mWaitForValueTimeOut = KEYBOARD_WAITFORVALUE_TIMEOUT;\r
+    Status = KeyboardWaitForValue (\r
+               ConsoleIn,\r
+               KEYBOARD_CMDECHO_ACK\r
+               );\r
+    mWaitForValueTimeOut = WaitForValueTimeOutBcakup;\r
+    \r
+    if (EFI_ERROR (Status)) {\r
+      return FALSE;\r
+    }\r
+    \r
+    return TRUE;\r
+  } else {\r
+    return TRUE;\r
   }\r
-\r
-  return TRUE;\r
 }\r
 \r