From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 5ED0282422 for ; Fri, 23 Dec 2016 00:13:21 -0800 (PST) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP; 23 Dec 2016 00:13:21 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,392,1477983600"; d="scan'208";a="915466547" Received: from shwdeopenpsi068.ccr.corp.intel.com ([10.239.9.9]) by orsmga003.jf.intel.com with ESMTP; 23 Dec 2016 00:13:19 -0800 From: Star Zeng To: edk2-devel@lists.01.org Cc: Star Zeng , Ruiyu Ni , Michael Kinney , Feng Tian Date: Fri, 23 Dec 2016 16:13:08 +0800 Message-Id: <1482480792-35264-2-git-send-email-star.zeng@intel.com> X-Mailer: git-send-email 2.7.0.windows.1 In-Reply-To: <1482480792-35264-1-git-send-email-star.zeng@intel.com> References: <1482480792-35264-1-git-send-email-star.zeng@intel.com> Subject: [PATCH V2 1/5] MdeModulePkg UsbKbDxe: Execute key notify func at TPL_CALLBACK X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 23 Dec 2016 08:13:21 -0000 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 Cc: Michael Kinney Cc: Feng Tian Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Star Zeng --- MdeModulePkg/Bus/Usb/UsbKbDxe/EfiKey.c | 68 +++++++++++++++++++++++++++++++- MdeModulePkg/Bus/Usb/UsbKbDxe/EfiKey.h | 17 +++++++- MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c | 12 ++++-- 3 files changed, 92 insertions(+), 5 deletions(-) diff --git a/MdeModulePkg/Bus/Usb/UsbKbDxe/EfiKey.c b/MdeModulePkg/Bus/Usb/UsbKbDxe/EfiKey.c index fb7558b73070..cdd1684277e0 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.
+Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.
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); + } + } + } +} + diff --git a/MdeModulePkg/Bus/Usb/UsbKbDxe/EfiKey.h b/MdeModulePkg/Bus/Usb/UsbKbDxe/EfiKey.h index 58edb3f65f2b..089f113d5fd4 100644 --- a/MdeModulePkg/Bus/Usb/UsbKbDxe/EfiKey.h +++ b/MdeModulePkg/Bus/Usb/UsbKbDxe/EfiKey.h @@ -1,7 +1,7 @@ /** @file Header file for USB Keyboard Driver's Data Structures. -Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.
+Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.
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 @@ -114,6 +114,7 @@ typedef struct { USB_SIMPLE_QUEUE UsbKeyQueue; USB_SIMPLE_QUEUE EfiKeyQueue; + USB_SIMPLE_QUEUE EfiKeyQueueForNotify; BOOLEAN CtrlOn; BOOLEAN AltOn; BOOLEAN ShiftOn; @@ -149,6 +150,7 @@ typedef struct { // Notification function list // LIST_ENTRY NotifyList; + EFI_EVENT KeyNotifyProcessEvent; // // Non-spacing key list @@ -596,5 +598,18 @@ USBKeyboardTimerHandler ( IN VOID *Context ); +/** + 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 + ); + #endif diff --git a/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c b/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c index fef1449e3c35..91913d4e54e7 100644 --- a/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c +++ b/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c @@ -820,6 +820,7 @@ InitUSBKeyboard ( InitQueue (&UsbKeyboardDevice->UsbKeyQueue, sizeof (USB_KEY)); InitQueue (&UsbKeyboardDevice->EfiKeyQueue, sizeof (EFI_KEY_DATA)); + InitQueue (&UsbKeyboardDevice->EfiKeyQueueForNotify, sizeof (EFI_KEY_DATA)); // // Use the config out of the descriptor @@ -1665,20 +1666,25 @@ UsbKeyCodeToEfiInputKey ( KeyData->KeyState.KeyToggleState |= EFI_KEY_STATE_EXPOSED; } // - // Invoke notification functions if the key is registered. + // Signal KeyNotify process event if this key pressed matches any key registered. // NotifyList = &UsbKeyboardDevice->NotifyList; 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); + // + // The key notification function needs to run at TPL_CALLBACK + // while current TPL is TPL_NOTIFY. It will be invoked in + // KeyNotifyProcessHandler() which runs at TPL_CALLBACK. + // + Enqueue (&UsbKeyboardDevice->EfiKeyQueueForNotify, KeyData, sizeof (*KeyData)); + gBS->SignalEvent (UsbKeyboardDevice->KeyNotifyProcessEvent); } } return EFI_SUCCESS; } - /** Create the queue. -- 2.7.0.windows.1