]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg UsbKbDxe: Execute key notify func at TPL_CALLBACK
authorStar Zeng <star.zeng@intel.com>
Fri, 16 Dec 2016 09:16:22 +0000 (17:16 +0800)
committerStar Zeng <star.zeng@intel.com>
Mon, 26 Dec 2016 10:16:58 +0000 (18:16 +0800)
Current implementation executes key notify function in TimerHandler
at TPL_NOTIFY. The code change is to make key notify function
executed at TPL_CALLBACK to reduce the time occupied at TPL_NOTIFY.

The code will signal KeyNotify process event if the key pressed
matches any key registered and insert the KeyData to the EFI Key
queue for notify, then the KeyNotify process handler will invoke
key notify functions at TPL_CALLBACK.

Cc: Ruiyu Ni <Ruiyu.ni@intel.com>
Cc: Michael Kinney <michael.d.kinney@intel.com>
Cc: Feng Tian <feng.tian@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Ruiyu Ni <Ruiyu.ni@intel.com>
MdeModulePkg/Bus/Usb/UsbKbDxe/EfiKey.c
MdeModulePkg/Bus/Usb/UsbKbDxe/EfiKey.h
MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c

index fb7558b730705b44d6a76536447b845a4fa79f3b..cdd1684277e0daa6556fc36eaddd05caad49e163 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
-Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 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
@@ -312,6 +312,17 @@ USBKeyboardDriverBindingStart (
     goto ErrorExit;\r
   }\r
 \r
+  Status = gBS->CreateEvent (\r
+                  EVT_NOTIFY_SIGNAL,\r
+                  TPL_CALLBACK,\r
+                  KeyNotifyProcessHandler,\r
+                  UsbKeyboardDevice,\r
+                  &UsbKeyboardDevice->KeyNotifyProcessEvent\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    goto ErrorExit;\r
+  }\r
+\r
   //\r
   // Install Simple Text Input Protocol and Simple Text Input Ex Protocol\r
   // for the USB keyboard device.\r
@@ -427,6 +438,9 @@ ErrorExit:
     if (UsbKeyboardDevice->SimpleInputEx.WaitForKeyEx != NULL) {\r
       gBS->CloseEvent (UsbKeyboardDevice->SimpleInputEx.WaitForKeyEx);\r
     }\r
+    if (UsbKeyboardDevice->KeyNotifyProcessEvent != NULL) {\r
+      gBS->CloseEvent (UsbKeyboardDevice->KeyNotifyProcessEvent);\r
+    }\r
     if (UsbKeyboardDevice->KeyboardLayoutEvent != NULL) {\r
       ReleaseKeyboardLayoutResources (UsbKeyboardDevice);\r
       gBS->CloseEvent (UsbKeyboardDevice->KeyboardLayoutEvent);\r
@@ -548,6 +562,7 @@ USBKeyboardDriverBindingStop (
   gBS->CloseEvent (UsbKeyboardDevice->DelayedRecoveryEvent);\r
   gBS->CloseEvent (UsbKeyboardDevice->SimpleInput.WaitForKey);\r
   gBS->CloseEvent (UsbKeyboardDevice->SimpleInputEx.WaitForKeyEx);\r
+  gBS->CloseEvent (UsbKeyboardDevice->KeyNotifyProcessEvent);\r
   KbdFreeNotifyList (&UsbKeyboardDevice->NotifyList);\r
 \r
   ReleaseKeyboardLayoutResources (UsbKeyboardDevice);\r
@@ -559,6 +574,7 @@ USBKeyboardDriverBindingStop (
 \r
   DestroyQueue (&UsbKeyboardDevice->UsbKeyQueue);\r
   DestroyQueue (&UsbKeyboardDevice->EfiKeyQueue);\r
+  DestroyQueue (&UsbKeyboardDevice->EfiKeyQueueForNotify);\r
 \r
   FreePool (UsbKeyboardDevice);\r
 \r
@@ -647,6 +663,7 @@ USBKeyboardReset (
     //\r
     InitQueue (&UsbKeyboardDevice->UsbKeyQueue, sizeof (USB_KEY));\r
     InitQueue (&UsbKeyboardDevice->EfiKeyQueue, sizeof (EFI_KEY_DATA));\r
+    InitQueue (&UsbKeyboardDevice->EfiKeyQueueForNotify, sizeof (EFI_KEY_DATA));\r
 \r
     return EFI_SUCCESS;\r
   }\r
@@ -1170,3 +1187,52 @@ USBKeyboardUnregisterKeyNotify (
   return EFI_INVALID_PARAMETER;\r
 }\r
 \r
+/**\r
+  Process key notify.\r
+\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
+  EFI_STATUS                    Status;\r
+  USB_KB_DEV                    *UsbKeyboardDevice;\r
+  EFI_KEY_DATA                  KeyData;\r
+  LIST_ENTRY                    *Link;\r
+  LIST_ENTRY                    *NotifyList;\r
+  KEYBOARD_CONSOLE_IN_EX_NOTIFY *CurrentNotify;\r
+  EFI_TPL                       OldTpl;\r
+\r
+  UsbKeyboardDevice = (USB_KB_DEV *) Context;\r
+\r
+  //\r
+  // Invoke notification functions.\r
+  //\r
+  NotifyList = &UsbKeyboardDevice->NotifyList;\r
+  while (TRUE) {\r
+    //\r
+    // Enter critical section\r
+    //  \r
+    OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
+    Status = Dequeue (&UsbKeyboardDevice->EfiKeyQueueForNotify, &KeyData, sizeof (KeyData));\r
+    //\r
+    // Leave critical section\r
+    //\r
+    gBS->RestoreTPL (OldTpl);\r
+    if (EFI_ERROR (Status)) {\r
+      break;\r
+    }\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
+\r
index 58edb3f65f2b7d17ff2a9e37eb216b45e9e566f8..089f113d5fd4f4bde9c1bbf8fd075a0df4b43c64 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Header file for USB Keyboard Driver's Data Structures.\r
 \r
-Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 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
@@ -114,6 +114,7 @@ typedef struct {
 \r
   USB_SIMPLE_QUEUE                  UsbKeyQueue;\r
   USB_SIMPLE_QUEUE                  EfiKeyQueue;\r
+  USB_SIMPLE_QUEUE                  EfiKeyQueueForNotify;\r
   BOOLEAN                           CtrlOn;\r
   BOOLEAN                           AltOn;\r
   BOOLEAN                           ShiftOn;\r
@@ -149,6 +150,7 @@ typedef struct {
   // Notification function list\r
   //\r
   LIST_ENTRY                        NotifyList;\r
+  EFI_EVENT                         KeyNotifyProcessEvent;\r
 \r
   //\r
   // Non-spacing key list\r
@@ -596,5 +598,18 @@ USBKeyboardTimerHandler (
   IN  VOID                      *Context\r
   );\r
 \r
+/**\r
+  Process key notify.\r
+\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
 #endif\r
 \r
index fef1449e3c3593664c87eaeff91c30f2f84ef9b7..91913d4e54e75ac9f76be0585134c4f9e4d62c07 100644 (file)
@@ -820,6 +820,7 @@ InitUSBKeyboard (
 \r
   InitQueue (&UsbKeyboardDevice->UsbKeyQueue, sizeof (USB_KEY));\r
   InitQueue (&UsbKeyboardDevice->EfiKeyQueue, sizeof (EFI_KEY_DATA));\r
+  InitQueue (&UsbKeyboardDevice->EfiKeyQueueForNotify, sizeof (EFI_KEY_DATA));\r
 \r
   //\r
   // Use the config out of the descriptor\r
@@ -1665,20 +1666,25 @@ UsbKeyCodeToEfiInputKey (
     KeyData->KeyState.KeyToggleState |= EFI_KEY_STATE_EXPOSED;\r
   }\r
   //\r
-  // Invoke notification functions if the key is registered.\r
+  // Signal KeyNotify process event if this key pressed matches any key 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
+      // 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
+      Enqueue (&UsbKeyboardDevice->EfiKeyQueueForNotify, KeyData, sizeof (*KeyData));\r
+      gBS->SignalEvent (UsbKeyboardDevice->KeyNotifyProcessEvent);\r
     }\r
   }\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
-\r
 /**\r
   Create the queue.\r
 \r