summaryrefslogtreecommitdiffstats
path: root/MdeModulePkg/Bus/Usb/UsbKbDxe/EfiKey.c
diff options
context:
space:
mode:
authorStar Zeng <star.zeng@intel.com>2016-12-16 17:16:22 +0800
committerStar Zeng <star.zeng@intel.com>2016-12-26 18:16:58 +0800
commit4ae46dbacd8b049c66714c3578a88ecc09dcec95 (patch)
tree8b1bd92847dbeb87c3c8cb6ba86d1ce0aceb847a /MdeModulePkg/Bus/Usb/UsbKbDxe/EfiKey.c
parentcf88579c10f05554c25b1dd0318625f26d10097c (diff)
downloadedk2-4ae46dbacd8b049c66714c3578a88ecc09dcec95.tar.gz
edk2-4ae46dbacd8b049c66714c3578a88ecc09dcec95.tar.bz2
edk2-4ae46dbacd8b049c66714c3578a88ecc09dcec95.zip
MdeModulePkg UsbKbDxe: Execute key notify func at TPL_CALLBACK
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>
Diffstat (limited to 'MdeModulePkg/Bus/Usb/UsbKbDxe/EfiKey.c')
-rw-r--r--MdeModulePkg/Bus/Usb/UsbKbDxe/EfiKey.c68
1 files changed, 67 insertions, 1 deletions
diff --git a/MdeModulePkg/Bus/Usb/UsbKbDxe/EfiKey.c b/MdeModulePkg/Bus/Usb/UsbKbDxe/EfiKey.c
index fb7558b730..cdd1684277 100644
--- a/MdeModulePkg/Bus/Usb/UsbKbDxe/EfiKey.c
+++ b/MdeModulePkg/Bus/Usb/UsbKbDxe/EfiKey.c
@@ -2,7 +2,7 @@
USB Keyboard Driver that manages USB keyboard and produces Simple Text Input
Protocol and Simple Text Input Ex Protocol.
-Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -312,6 +312,17 @@ USBKeyboardDriverBindingStart (
goto ErrorExit;
}
+ Status = gBS->CreateEvent (
+ EVT_NOTIFY_SIGNAL,
+ TPL_CALLBACK,
+ KeyNotifyProcessHandler,
+ UsbKeyboardDevice,
+ &UsbKeyboardDevice->KeyNotifyProcessEvent
+ );
+ if (EFI_ERROR (Status)) {
+ goto ErrorExit;
+ }
+
//
// Install Simple Text Input Protocol and Simple Text Input Ex Protocol
// for the USB keyboard device.
@@ -427,6 +438,9 @@ ErrorExit:
if (UsbKeyboardDevice->SimpleInputEx.WaitForKeyEx != NULL) {
gBS->CloseEvent (UsbKeyboardDevice->SimpleInputEx.WaitForKeyEx);
}
+ if (UsbKeyboardDevice->KeyNotifyProcessEvent != NULL) {
+ gBS->CloseEvent (UsbKeyboardDevice->KeyNotifyProcessEvent);
+ }
if (UsbKeyboardDevice->KeyboardLayoutEvent != NULL) {
ReleaseKeyboardLayoutResources (UsbKeyboardDevice);
gBS->CloseEvent (UsbKeyboardDevice->KeyboardLayoutEvent);
@@ -548,6 +562,7 @@ USBKeyboardDriverBindingStop (
gBS->CloseEvent (UsbKeyboardDevice->DelayedRecoveryEvent);
gBS->CloseEvent (UsbKeyboardDevice->SimpleInput.WaitForKey);
gBS->CloseEvent (UsbKeyboardDevice->SimpleInputEx.WaitForKeyEx);
+ gBS->CloseEvent (UsbKeyboardDevice->KeyNotifyProcessEvent);
KbdFreeNotifyList (&UsbKeyboardDevice->NotifyList);
ReleaseKeyboardLayoutResources (UsbKeyboardDevice);
@@ -559,6 +574,7 @@ USBKeyboardDriverBindingStop (
DestroyQueue (&UsbKeyboardDevice->UsbKeyQueue);
DestroyQueue (&UsbKeyboardDevice->EfiKeyQueue);
+ DestroyQueue (&UsbKeyboardDevice->EfiKeyQueueForNotify);
FreePool (UsbKeyboardDevice);
@@ -647,6 +663,7 @@ USBKeyboardReset (
//
InitQueue (&UsbKeyboardDevice->UsbKeyQueue, sizeof (USB_KEY));
InitQueue (&UsbKeyboardDevice->EfiKeyQueue, sizeof (EFI_KEY_DATA));
+ InitQueue (&UsbKeyboardDevice->EfiKeyQueueForNotify, sizeof (EFI_KEY_DATA));
return EFI_SUCCESS;
}
@@ -1170,3 +1187,52 @@ USBKeyboardUnregisterKeyNotify (
return EFI_INVALID_PARAMETER;
}
+/**
+ 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
+ )
+{
+ EFI_STATUS Status;
+ USB_KB_DEV *UsbKeyboardDevice;
+ EFI_KEY_DATA KeyData;
+ LIST_ENTRY *Link;
+ LIST_ENTRY *NotifyList;
+ KEYBOARD_CONSOLE_IN_EX_NOTIFY *CurrentNotify;
+ EFI_TPL OldTpl;
+
+ UsbKeyboardDevice = (USB_KB_DEV *) Context;
+
+ //
+ // Invoke notification functions.
+ //
+ NotifyList = &UsbKeyboardDevice->NotifyList;
+ while (TRUE) {
+ //
+ // Enter critical section
+ //
+ OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
+ Status = Dequeue (&UsbKeyboardDevice->EfiKeyQueueForNotify, &KeyData, sizeof (KeyData));
+ //
+ // Leave critical section
+ //
+ gBS->RestoreTPL (OldTpl);
+ if (EFI_ERROR (Status)) {
+ break;
+ }
+ for (Link = GetFirstNode (NotifyList); !IsNull (NotifyList, Link); Link = GetNextNode (NotifyList, Link)) {
+ CurrentNotify = CR (Link, KEYBOARD_CONSOLE_IN_EX_NOTIFY, NotifyEntry, USB_KB_CONSOLE_IN_EX_NOTIFY_SIGNATURE);
+ if (IsKeyRegistered (&CurrentNotify->KeyData, &KeyData)) {
+ CurrentNotify->KeyNotificationFn (&KeyData);
+ }
+ }
+ }
+}
+