]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg Ps2KbDxe: Execute key notify func at TPL_CALLBACK
authorStar Zeng <star.zeng@intel.com>
Fri, 16 Dec 2016 10:08:18 +0000 (18:08 +0800)
committerStar Zeng <star.zeng@intel.com>
Mon, 26 Dec 2016 10:17:00 +0000 (18:17 +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/Isa/Ps2KeyboardDxe/Ps2KbdCtrller.c
MdeModulePkg/Bus/Isa/Ps2KeyboardDxe/Ps2KbdTextIn.c
MdeModulePkg/Bus/Isa/Ps2KeyboardDxe/Ps2Keyboard.c
MdeModulePkg/Bus/Isa/Ps2KeyboardDxe/Ps2Keyboard.h

index eeb7de34abc8f3e233b8b82cf926562036541887..f92521046f5b51ac64f7065f53fdfc41eb424622 100644 (file)
@@ -1420,7 +1420,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 +1430,13 @@ 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
     }\r
   }\r
 \r
@@ -1629,6 +1635,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
index f6ccd9598fb0b0e7d98043c85f4a59b891f9d8e8..bc58fe2f8c7cde09aed7a39759ff66a50d16c6db 100644 (file)
@@ -681,3 +681,52 @@ Exit:
   return Status;\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
+  KEYBOARD_CONSOLE_IN_DEV       *ConsoleIn;\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
+  ConsoleIn = (KEYBOARD_CONSOLE_IN_DEV *) Context;\r
+\r
+  //\r
+  // Invoke notification functions.\r
+  //\r
+  NotifyList = &ConsoleIn->NotifyList;\r
+  while (TRUE) {\r
+    //\r
+    // Enter critical section\r
+    //  \r
+    OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
+    Status = PopEfikeyBufHead (&ConsoleIn->EfiKeyQueueForNotify, &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, KEYBOARD_CONSOLE_IN_EX_NOTIFY_SIGNATURE);\r
+      if (IsKeyRegistered (&CurrentNotify->KeyData, &KeyData)) {\r
+        CurrentNotify->KeyNotificationFn (&KeyData);\r
+      }\r
+    }\r
+  }\r
+}\r
+\r
index 4df1b890e62fdc089ec547d9ce996abe15f0652e..6121d29fb791b0a13dbe75e0e739dfea46417a2c 100644 (file)
@@ -351,6 +351,19 @@ KbdControllerDriverStart (
     goto ErrorExit;\r
   }\r
 \r
+  Status = gBS->CreateEvent (\r
+                  EVT_NOTIFY_SIGNAL,\r
+                  TPL_CALLBACK,\r
+                  KeyNotifyProcessHandler,\r
+                  ConsoleIn,\r
+                  &ConsoleIn->KeyNotifyProcessEvent\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    Status      = EFI_OUT_OF_RESOURCES;\r
+    StatusCode  = EFI_PERIPHERAL_KEYBOARD | EFI_P_EC_CONTROLLER_ERROR;\r
+    goto ErrorExit;\r
+  }\r
+\r
   REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
     EFI_PROGRESS_CODE,\r
     EFI_PERIPHERAL_KEYBOARD | EFI_P_PC_PRESENCE_DETECT,\r
@@ -430,6 +443,9 @@ ErrorExit:
   if ((ConsoleIn != NULL) && (ConsoleIn->ConInEx.WaitForKeyEx != NULL)) {\r
     gBS->CloseEvent (ConsoleIn->ConInEx.WaitForKeyEx);\r
   }\r
+  if ((ConsoleIn != NULL) && (ConsoleIn->KeyNotifyProcessEvent != NULL)) {\r
+    gBS->CloseEvent (ConsoleIn->KeyNotifyProcessEvent);\r
+  }\r
   KbdFreeNotifyList (&ConsoleIn->NotifyList);\r
   if ((ConsoleIn != NULL) && (ConsoleIn->ControllerNameTable != NULL)) {\r
     FreeUnicodeStringTable (ConsoleIn->ControllerNameTable);\r
@@ -570,6 +586,10 @@ KbdControllerDriverStop (
     gBS->CloseEvent (ConsoleIn->ConInEx.WaitForKeyEx);\r
     ConsoleIn->ConInEx.WaitForKeyEx = NULL;\r
   }\r
+  if (ConsoleIn->KeyNotifyProcessEvent != NULL) {\r
+    gBS->CloseEvent (ConsoleIn->KeyNotifyProcessEvent);\r
+    ConsoleIn->KeyNotifyProcessEvent = NULL;\r
+  }\r
   KbdFreeNotifyList (&ConsoleIn->NotifyList);\r
   FreeUnicodeStringTable (ConsoleIn->ControllerNameTable);\r
   gBS->FreePool (ConsoleIn);\r
index d0aecfb087880ba0e522975657cf7fcc9b9be2d0..e41c1980fc6f3086c6c516f9a797049c207212b6 100644 (file)
@@ -105,6 +105,7 @@ typedef struct {
   //\r
   SCAN_CODE_QUEUE                     ScancodeQueue;\r
   EFI_KEY_QUEUE                       EfiKeyQueue;\r
+  EFI_KEY_QUEUE                       EfiKeyQueueForNotify;\r
 \r
   //\r
   // Error state\r
@@ -118,6 +119,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
@@ -268,6 +270,19 @@ KeyGetchar (
   IN OUT KEYBOARD_CONSOLE_IN_DEV *ConsoleIn\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
 /**\r
   Perform 8042 controller and keyboard Initialization.\r
   If ExtendedVerification is TRUE, do additional test for\r