From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (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 BAE43823E9 for ; Thu, 22 Dec 2016 18:16:53 -0800 (PST) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga101.jf.intel.com with ESMTP; 22 Dec 2016 18:16:53 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,391,1477983600"; d="scan'208";a="46275482" Received: from fmsmsx108.amr.corp.intel.com ([10.18.124.206]) by fmsmga006.fm.intel.com with ESMTP; 22 Dec 2016 18:16:53 -0800 Received: from fmsmsx124.amr.corp.intel.com (10.18.125.39) by FMSMSX108.amr.corp.intel.com (10.18.124.206) with Microsoft SMTP Server (TLS) id 14.3.248.2; Thu, 22 Dec 2016 18:16:53 -0800 Received: from shsmsx152.ccr.corp.intel.com (10.239.6.52) by fmsmsx124.amr.corp.intel.com (10.18.125.39) with Microsoft SMTP Server (TLS) id 14.3.248.2; Thu, 22 Dec 2016 18:16:52 -0800 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.88]) by SHSMSX152.ccr.corp.intel.com ([169.254.6.132]) with mapi id 14.03.0248.002; Fri, 23 Dec 2016 10:16:50 +0800 From: "Fan, Jeff" To: "Zeng, Star" , "edk2-devel@lists.01.org" CC: "Ni, Ruiyu" , "Kinney, Michael D" , "Tian, Feng" Thread-Topic: [PATCH 5/5] IntelFrameworkModulePkg KbDxe: Execute key notify func at TPL_CALLBACK Thread-Index: AQHSXFmuTl/G+l6NNkCx+W0bauc756EUzH4g Date: Fri, 23 Dec 2016 02:16:50 +0000 Message-ID: <542CF652F8836A4AB8DBFAAD40ED192A4C50347F@shsmsx102.ccr.corp.intel.com> References: <1482414310-33036-1-git-send-email-star.zeng@intel.com> <1482414310-33036-6-git-send-email-star.zeng@intel.com> In-Reply-To: <1482414310-33036-6-git-send-email-star.zeng@intel.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiZjBjNjcwNmYtNDViMC00ZDM1LTlkMjUtMTJiNzQ0YzY5OTM4IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX0lDIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE1LjkuNi42IiwiVHJ1c3RlZExhYmVsSGFzaCI6IjBNTUkySDNTcjhQREtMRHVyU3RBWVhQRVFiQlNcL2J1QStjYlJnZDVMZ0ZjPSJ9 x-ctpclassification: CTP_IC x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH 5/5] IntelFrameworkModulePkg KbDxe: 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 02:16:53 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Jeff Fan -----Original Message----- From: Zeng, Star=20 Sent: Thursday, December 22, 2016 9:45 PM To: edk2-devel@lists.01.org Cc: Zeng, Star; Ni, Ruiyu; Kinney, Michael D; Tian, Feng; Fan, Jeff Subject: [PATCH 5/5] IntelFrameworkModulePkg KbDxe: 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_CALL= BACK 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, the= n the KeyNotify process handler will invoke key notify functions at TPL_CAL= LBACK. Cc: Ruiyu Ni Cc: Michael Kinney Cc: Feng Tian Cc: Jeff Fan Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Star Zeng --- .../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. =20 -Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.
=20 This program and the accompanying materials are licensed and made availab= le under the terms and conditions @@ -272,6 +272,8 @@ BiosKeyboardDriverBin= dingStart ( =20 BiosKeyboardPrivate->Queue.Front =3D 0; BiosKeyboardPrivate->Queue.Rear =3D 0; + BiosKeyboardPrivate->QueueForNotify.Front =3D 0; + BiosKeyboardPrivate->QueueForNotify.Rear =3D 0; BiosKeyboardPrivate->SimpleTextInputEx.Reset =3D BiosKeybo= ardResetEx; BiosKeyboardPrivate->SimpleTextInputEx.ReadKeyStrokeEx =3D BiosKeybo= ardReadKeyStrokeEx; BiosKeyboardPrivate->SimpleTextInputEx.SetState =3D BiosKeybo= ardSetState; @@ -339,7 +341,20 @@ BiosKeyboardDriverBindingStart ( StatusCode =3D EFI_PERIPHERAL_KEYBOARD | EFI_P_EC_CONTROLLER_ERROR; goto Done; } - =20 + + Status =3D gBS->CreateEvent ( + EVT_NOTIFY_SIGNAL, + TPL_CALLBACK, + KeyNotifyProcessHandler, + BiosKeyboardPrivate, + &BiosKeyboardPrivate->KeyNotifyProcessEvent + ); + if (EFI_ERROR (Status)) { + Status =3D EFI_OUT_OF_RESOURCES; + StatusCode =3D EFI_PERIPHERAL_KEYBOARD | EFI_P_EC_CONTROLLER_ERROR; + goto Done; + } + // // Report a Progress Code for an attempt to detect the precense of the k= eyboard device in the system // @@ -462,6 +477,11 @@ Done: if ((BiosKeyboardPrivate->SimpleTextInputEx).WaitForKeyEx !=3D NULL)= { gBS->CloseEvent ((BiosKeyboardPrivate->SimpleTextInputEx).WaitForK= eyEx); =20 } + + if (BiosKeyboardPrivate->KeyNotifyProcessEvent !=3D NULL) { + gBS->CloseEvent (BiosKeyboardPrivate->KeyNotifyProcessEvent); + } + BiosKeyboardFreeNotifyList (&BiosKeyboardPrivate->NotifyList); =20 if (BiosKeyboardPrivate->TimerEvent !=3D 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); =20 FreePool (BiosKeyboardPrivate); @@ -1941,7 +1962,7 @@ BiosKeyboardTimerHandler ( } =20 // - // Invoke notification functions if exist + // Signal KeyNotify process event if this key pressed matches any key re= gistered. // for (Link =3D BiosKeyboardPrivate->NotifyList.ForwardLink; Link !=3D &Bi= osKeyboardPrivate->NotifyList; Link =3D Link->ForwardLink) { CurrentNotify =3D CR ( @@ -1951,7 +1972,8 @@ BiosKeyboardTimerHandler ( BIOS_KEYBOARD_CONSOLE_IN_EX_NOTIFY_SIGNATURE ); if (IsKeyRegistered (&CurrentNotify->KeyData, &KeyData)) {=20 - CurrentNotify->KeyNotificationFn (&KeyData); + Enqueue (&BiosKeyboardPrivate->QueueForNotify, &KeyData); + gBS->SignalEvent (BiosKeyboardPrivate->KeyNotifyProcessEvent); } } =20 @@ -1965,6 +1987,51 @@ BiosKeyboardTimerHandler ( } =20 /** + Process key notify. + + @param Event Indicates the event that invoke this funct= ion. + @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 =3D (BIOS_KEYBOARD_DEV *) Context; + + // + // Invoke notification functions. + // + NotifyList =3D &BiosKeyboardPrivate->NotifyList; + while (!EFI_ERROR (CheckQueue (&BiosKeyboardPrivate->QueueForNotify))) { + // + // Enter critical section + // =20 + OldTpl =3D gBS->RaiseTPL (TPL_NOTIFY); + Dequeue (&BiosKeyboardPrivate->QueueForNotify, &KeyData); + // + // Leave critical section + // + gBS->RestoreTPL (OldTpl); + for (Link =3D GetFirstNode (NotifyList); !IsNull (NotifyList, Link); L= ink =3D GetNextNode (NotifyList, Link)) { + CurrentNotify =3D CR (Link, BIOS_KEYBOARD_CONSOLE_IN_EX_NOTIFY, Noti= fyEntry, BIOS_KEYBOARD_CONSOLE_IN_EX_NOTIFY_SIGNATURE); + if (IsKeyRegistered (&CurrentNotify->KeyData, &KeyData)) { + CurrentNotify->KeyNotificationFn (&KeyData); + } + } + } +} + +/** Free keyboard notify list. =20 @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 =20 -Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.
=20 This program and the accompanying materials are licensed and made availab= le under the terms and conditions @@ -223,11 +223,13 @@ typedef struct { // Buffer storing EFI_KEY_DATA // SIMPLE_QUEUE Queue; + SIMPLE_QUEUE QueueForNotify; =20 // // Notification Function List // LIST_ENTRY NotifyList; + EFI_EVENT KeyNotifyProcessEvent; EFI_EVENT TimerEvent; =20 } BIOS_KEYBOARD_DEV; @@ -555,6 +557,19 @@ BiosKeyboardTimerHandler ( ); =20 /** + Process key notify. + + @param Event Indicates the event that invoke this funct= ion. + @param Context Indicates the calling context. +**/ +VOID +EFIAPI +KeyNotifyProcessHandler ( + IN EFI_EVENT Event, + IN VOID *Context + ); + +/** Reset the input device and optionaly run diagnostics =20 @param This Protocol instance pointer. -- 2.7.0.windows.1