public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Star Zeng <star.zeng@intel.com>
To: edk2-devel@lists.01.org
Cc: Star Zeng <star.zeng@intel.com>, Ruiyu Ni <Ruiyu.ni@intel.com>,
	Michael Kinney <michael.d.kinney@intel.com>,
	Feng Tian <feng.tian@intel.com>, Jeff Fan <jeff.fan@intel.com>
Subject: [PATCH 5/5] IntelFrameworkModulePkg KbDxe: Execute key notify func at TPL_CALLBACK
Date: Thu, 22 Dec 2016 21:45:10 +0800	[thread overview]
Message-ID: <1482414310-33036-6-git-send-email-star.zeng@intel.com> (raw)
In-Reply-To: <1482414310-33036-1-git-send-email-star.zeng@intel.com>

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>
Cc: Jeff Fan <jeff.fan@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Star Zeng <star.zeng@intel.com>
---
 .../Csm/BiosThunk/KeyboardDxe/BiosKeyboard.c       | 75 ++++++++++++++++++++--
 .../Csm/BiosThunk/KeyboardDxe/BiosKeyboard.h       | 17 ++++-
 2 files changed, 87 insertions(+), 5 deletions(-)

diff --git a/IntelFrameworkModulePkg/Csm/BiosThunk/KeyboardDxe/BiosKeyboard.c b/IntelFrameworkModulePkg/Csm/BiosThunk/KeyboardDxe/BiosKeyboard.c
index 8dcb13177881..640079fa299a 100644
--- a/IntelFrameworkModulePkg/Csm/BiosThunk/KeyboardDxe/BiosKeyboard.c
+++ b/IntelFrameworkModulePkg/Csm/BiosThunk/KeyboardDxe/BiosKeyboard.c
@@ -1,7 +1,7 @@
 /** @file
   ConsoleOut Routines that speak VGA.
 
-Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
 
 This program and the accompanying materials
 are licensed and made available under the terms and conditions
@@ -272,6 +272,8 @@ BiosKeyboardDriverBindingStart (
   
   BiosKeyboardPrivate->Queue.Front                = 0;
   BiosKeyboardPrivate->Queue.Rear                 = 0;
+  BiosKeyboardPrivate->QueueForNotify.Front       = 0;
+  BiosKeyboardPrivate->QueueForNotify.Rear        = 0;
   BiosKeyboardPrivate->SimpleTextInputEx.Reset               = BiosKeyboardResetEx;
   BiosKeyboardPrivate->SimpleTextInputEx.ReadKeyStrokeEx     = BiosKeyboardReadKeyStrokeEx;
   BiosKeyboardPrivate->SimpleTextInputEx.SetState            = BiosKeyboardSetState;
@@ -339,7 +341,20 @@ BiosKeyboardDriverBindingStart (
     StatusCode  = EFI_PERIPHERAL_KEYBOARD | EFI_P_EC_CONTROLLER_ERROR;
     goto Done;
   }
-  
+
+  Status = gBS->CreateEvent (
+                  EVT_NOTIFY_SIGNAL,
+                  TPL_CALLBACK,
+                  KeyNotifyProcessHandler,
+                  BiosKeyboardPrivate,
+                  &BiosKeyboardPrivate->KeyNotifyProcessEvent
+                  );
+  if (EFI_ERROR (Status)) {
+    Status      = EFI_OUT_OF_RESOURCES;
+    StatusCode  = EFI_PERIPHERAL_KEYBOARD | EFI_P_EC_CONTROLLER_ERROR;
+    goto Done;
+  }
+
   //
   // Report a Progress Code for an attempt to detect the precense of the keyboard device in the system
   //
@@ -462,6 +477,11 @@ Done:
       if ((BiosKeyboardPrivate->SimpleTextInputEx).WaitForKeyEx != NULL) {
         gBS->CloseEvent ((BiosKeyboardPrivate->SimpleTextInputEx).WaitForKeyEx);    
       }
+
+      if (BiosKeyboardPrivate->KeyNotifyProcessEvent != NULL) {
+        gBS->CloseEvent (BiosKeyboardPrivate->KeyNotifyProcessEvent);
+      }
+
       BiosKeyboardFreeNotifyList (&BiosKeyboardPrivate->NotifyList);
 
       if (BiosKeyboardPrivate->TimerEvent != NULL) {
@@ -566,6 +586,7 @@ BiosKeyboardDriverBindingStop (
   gBS->CloseEvent ((BiosKeyboardPrivate->SimpleTextIn).WaitForKey);
   gBS->CloseEvent (BiosKeyboardPrivate->TimerEvent);
   gBS->CloseEvent (BiosKeyboardPrivate->SimpleTextInputEx.WaitForKeyEx);
+  gBS->CloseEvent (BiosKeyboardPrivate->KeyNotifyProcessEvent);
   BiosKeyboardFreeNotifyList (&BiosKeyboardPrivate->NotifyList);
 
   FreePool (BiosKeyboardPrivate);
@@ -1941,7 +1962,7 @@ BiosKeyboardTimerHandler (
   }
 
   //
-  // Invoke notification functions if exist
+  // Signal KeyNotify process event if this key pressed matches any key registered.
   //
   for (Link = BiosKeyboardPrivate->NotifyList.ForwardLink; Link != &BiosKeyboardPrivate->NotifyList; Link = Link->ForwardLink) {
     CurrentNotify = CR (
@@ -1951,7 +1972,8 @@ BiosKeyboardTimerHandler (
                       BIOS_KEYBOARD_CONSOLE_IN_EX_NOTIFY_SIGNATURE
                       );
     if (IsKeyRegistered (&CurrentNotify->KeyData, &KeyData)) { 
-      CurrentNotify->KeyNotificationFn (&KeyData);
+      Enqueue (&BiosKeyboardPrivate->QueueForNotify, &KeyData);
+      gBS->SignalEvent (BiosKeyboardPrivate->KeyNotifyProcessEvent);
     }
   }
 
@@ -1965,6 +1987,51 @@ BiosKeyboardTimerHandler (
 }
 
 /**
+  Process key notify.
+
+  @param  Event                 Indicates the event that invoke this function.
+  @param  Context               Indicates the calling context.
+**/
+VOID
+EFIAPI
+KeyNotifyProcessHandler (
+  IN  EFI_EVENT                 Event,
+  IN  VOID                      *Context
+  )
+{
+  BIOS_KEYBOARD_DEV                     *BiosKeyboardPrivate;
+  EFI_KEY_DATA                          KeyData;
+  LIST_ENTRY                            *Link;
+  LIST_ENTRY                            *NotifyList;
+  BIOS_KEYBOARD_CONSOLE_IN_EX_NOTIFY    *CurrentNotify;
+  EFI_TPL                               OldTpl;
+
+  BiosKeyboardPrivate = (BIOS_KEYBOARD_DEV *) Context;
+
+  //
+  // Invoke notification functions.
+  //
+  NotifyList = &BiosKeyboardPrivate->NotifyList;
+  while (!EFI_ERROR (CheckQueue (&BiosKeyboardPrivate->QueueForNotify))) {
+    //
+    // Enter critical section
+    //  
+    OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
+    Dequeue (&BiosKeyboardPrivate->QueueForNotify, &KeyData);
+    //
+    // Leave critical section
+    //
+    gBS->RestoreTPL (OldTpl);
+    for (Link = GetFirstNode (NotifyList); !IsNull (NotifyList, Link); Link = GetNextNode (NotifyList, Link)) {
+      CurrentNotify = CR (Link, BIOS_KEYBOARD_CONSOLE_IN_EX_NOTIFY, NotifyEntry, BIOS_KEYBOARD_CONSOLE_IN_EX_NOTIFY_SIGNATURE);
+      if (IsKeyRegistered (&CurrentNotify->KeyData, &KeyData)) {
+        CurrentNotify->KeyNotificationFn (&KeyData);
+      }
+    }
+  }
+}
+
+/**
   Free keyboard notify list.
 
   @param  ListHead   The list head
diff --git a/IntelFrameworkModulePkg/Csm/BiosThunk/KeyboardDxe/BiosKeyboard.h b/IntelFrameworkModulePkg/Csm/BiosThunk/KeyboardDxe/BiosKeyboard.h
index e83608659bc1..f38411aaa645 100644
--- a/IntelFrameworkModulePkg/Csm/BiosThunk/KeyboardDxe/BiosKeyboard.h
+++ b/IntelFrameworkModulePkg/Csm/BiosThunk/KeyboardDxe/BiosKeyboard.h
@@ -1,6 +1,6 @@
 /** @file
 
-Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
 
 This program and the accompanying materials
 are licensed and made available under the terms and conditions
@@ -223,11 +223,13 @@ typedef struct {
   // Buffer storing EFI_KEY_DATA
   //
   SIMPLE_QUEUE                                Queue;
+  SIMPLE_QUEUE                                QueueForNotify;
 
   //
   // Notification Function List
   //
   LIST_ENTRY                                  NotifyList;
+  EFI_EVENT                                   KeyNotifyProcessEvent;
   EFI_EVENT                                   TimerEvent;
   
 } BIOS_KEYBOARD_DEV;
@@ -555,6 +557,19 @@ BiosKeyboardTimerHandler (
   );
 
 /**
+  Process key notify.
+
+  @param  Event                 Indicates the event that invoke this function.
+  @param  Context               Indicates the calling context.
+**/
+VOID
+EFIAPI
+KeyNotifyProcessHandler (
+  IN  EFI_EVENT                 Event,
+  IN  VOID                      *Context
+  );
+
+/**
   Reset the input device and optionaly run diagnostics
  
   @param  This                  Protocol instance pointer.
-- 
2.7.0.windows.1



  parent reply	other threads:[~2016-12-22 13:45 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-22 13:45 [PATCH 0/5] Execute key notify function at TPL_CALLBACK Star Zeng
2016-12-22 13:45 ` [PATCH 1/5] MdeModulePkg UsbKbDxe: Execute key notify func " Star Zeng
2016-12-23  7:01   ` Ni, Ruiyu
2016-12-23  7:05     ` Zeng, Star
2016-12-23  7:09       ` Ni, Ruiyu
2016-12-23  7:28         ` Zeng, Star
2016-12-22 13:45 ` [PATCH 2/5] MdeModulePkg TerminalDxe: " Star Zeng
2016-12-22 13:45 ` [PATCH 3/5] MdeModulePkg Ps2KbDxe: " Star Zeng
2016-12-22 13:45 ` [PATCH 4/5] IntelFrameworkModulePkg " Star Zeng
2016-12-23  2:16   ` Fan, Jeff
2016-12-22 13:45 ` Star Zeng [this message]
2016-12-23  2:16   ` [PATCH 5/5] IntelFrameworkModulePkg KbDxe: " Fan, Jeff
2016-12-23  7:11 ` [PATCH 0/5] Execute key notify function " Ni, Ruiyu
2016-12-23  8:14   ` Zeng, Star

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1482414310-33036-6-git-send-email-star.zeng@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox