]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Isa/Ps2KeyboardDxe/Ps2KbdCtrller.c
IntelFsp2WrapperPkg: Apply uncrustify changes
[mirror_edk2.git] / MdeModulePkg / Bus / Isa / Ps2KeyboardDxe / Ps2KbdCtrller.c
index eeb7de34abc8f3e233b8b82cf926562036541887..d8d050b0a92a6f414f43f5f7ef96a08399ccff63 100644 (file)
@@ -1,14 +1,8 @@
 /** @file\r
   Routines that access 8042 keyboard controller\r
 \r
-Copyright (c) 2006 - 2016, 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
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -805,7 +799,7 @@ KeyboardTimerHandler (
   //\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
-  // error in the following code and wait for the input buffer empty, this waiting time shoulb be short enough since\r
+  // error in the following code and wait for the input buffer empty, this waiting time should be short enough since\r
   // this is a NOTIFY TPL period function, or the system performance will degrade hardly when KB is not connected.\r
   // Just skip the 'resend' process simply.\r
   //\r
@@ -833,7 +827,7 @@ KeyboardTimerHandler (
   @param ConsoleIn - Pointer to instance of KEYBOARD_CONSOLE_IN_DEV\r
   @param Data      - Pointer to outof buffer for keeping key value\r
 \r
-  @retval EFI_TIMEOUT Status resigter time out\r
+  @retval EFI_TIMEOUT Status register time out\r
   @retval EFI_SUCCESS Success to read keyboard\r
 \r
 **/\r
@@ -877,7 +871,7 @@ KeyboardRead (
   @param Data      value wanted to be written\r
 \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
+  @retval EFI_SUCCESS   The new value is success put into input buffer register.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -1104,6 +1098,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
@@ -1316,27 +1342,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
@@ -1420,7 +1428,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
@@ -1430,7 +1438,14 @@ KeyGetchar (
                       KEYBOARD_CONSOLE_IN_EX_NOTIFY_SIGNATURE\r
                       );\r
     if (IsKeyRegistered (&CurrentNotify->KeyData, &KeyData)) {\r
-      CurrentNotify->KeyNotificationFn (&KeyData);\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
+      break;\r
     }\r
   }\r
 \r
@@ -1629,6 +1644,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
@@ -1671,7 +1688,7 @@ InitKeyboard (
     if (EFI_ERROR (Status)) {\r
       KeyboardError (\r
         ConsoleIn,\r
-        L"Some specific value not aquired from 8042 controller!\n\r"\r
+        L"Some specific value not acquired from 8042 controller!\n\r"\r
         );\r
       goto Done;\r
     }\r
@@ -1686,7 +1703,7 @@ InitKeyboard (
 \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
+      KeyboardError (ConsoleIn, L"Some specific value not acquired from 8042 controller!\n\r");\r
       goto Done;\r
     }\r
     //\r
@@ -1713,7 +1730,7 @@ InitKeyboard (
 \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
+      KeyboardError (ConsoleIn, L"Some specific value not acquired from 8042 controller!\n\r");\r
       goto Done;\r
     }\r
 \r
@@ -1725,7 +1742,7 @@ InitKeyboard (
 \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
+      KeyboardError (ConsoleIn, L"Some specific value not acquired from 8042 controller!\n\r");\r
       goto Done;\r
     }\r
 \r
@@ -1740,7 +1757,7 @@ InitKeyboard (
 \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
+    KeyboardError (ConsoleIn, L"Some specific value not acquired from 8042 controller!\n\r");\r
     goto Done;\r
   }\r
   //\r
@@ -1790,32 +1807,6 @@ Done:
 \r
 }\r
 \r
-/**\r
-  Disable the keyboard interface of the 8042 controller.\r
-\r
-  @param ConsoleIn   The device instance\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
-  EFI_STATUS  Status;\r
-\r
-  //\r
-  // Disable keyboard interface\r
-  //\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
-  }\r
-\r
-  return Status;\r
-}\r
 \r
 /**\r
   Check whether there is Ps/2 Keyboard device in system by 0xF4 Keyboard Command\r