From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.93; helo=mga11.intel.com; envelope-from=star.zeng@intel.com; receiver=edk2-devel@lists.01.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (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 14B602239362A for ; Wed, 31 Jan 2018 21:29:38 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 31 Jan 2018 21:35:14 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,443,1511856000"; d="scan'208";a="14496942" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by fmsmga007.fm.intel.com with ESMTP; 31 Jan 2018 21:35:14 -0800 Received: from fmsmsx126.amr.corp.intel.com (10.18.125.43) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 31 Jan 2018 21:35:14 -0800 Received: from shsmsx104.ccr.corp.intel.com (10.239.4.70) by FMSMSX126.amr.corp.intel.com (10.18.125.43) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 31 Jan 2018 21:35:13 -0800 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.124]) by SHSMSX104.ccr.corp.intel.com ([169.254.5.127]) with mapi id 14.03.0319.002; Thu, 1 Feb 2018 13:35:12 +0800 From: "Zeng, Star" To: "Ni, Ruiyu" , "edk2-devel@lists.01.org" CC: "Kinney, Michael D" , "Zeng, Star" Thread-Topic: [PATCH 2/6] MdeModulePkg/ConSplitter: ReadKeyStrokeEx always return key state Thread-Index: AQHTk1iHjy85dcZ8w0OOp6w2RGW0Z6OPFXRw Date: Thu, 1 Feb 2018 05:35:10 +0000 Message-ID: <0C09AFA07DD0434D9E2A0C6AEB0483103BA1DF91@shsmsx102.ccr.corp.intel.com> References: <20180122081024.283496-1-ruiyu.ni@intel.com> <20180122081024.283496-3-ruiyu.ni@intel.com> In-Reply-To: <20180122081024.283496-3-ruiyu.ni@intel.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH 2/6] MdeModulePkg/ConSplitter: ReadKeyStrokeEx always return key state X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Feb 2018 05:29:38 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi Ruiyu, One comment: ConSplitterTextInPrivateReadKeyStroke() needs filter out partial key from C= onSplitterTextInExDequeueKey(). With the comment above handled, Reviewed-by: Star Zeng to this patch series. Thanks, Star -----Original Message----- From: Ni, Ruiyu=20 Sent: Monday, January 22, 2018 4:10 PM To: edk2-devel@lists.01.org Cc: Zeng, Star ; Kinney, Michael D Subject: [PATCH 2/6] MdeModulePkg/ConSplitter: ReadKeyStrokeEx always retur= n key state Today's implementation only return key state when there is key. But when user doesn't press any key, the key state cannot be returned. The patch changes the ReadKeyStrokeEx() to always return the key state even there is no key pressed. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ruiyu Ni Cc: Star Zeng Cc: Michael D Kinney --- .../Universal/Console/ConSplitterDxe/ConSplitter.c | 164 +++++++++++++++++= +--- .../Universal/Console/ConSplitterDxe/ConSplitter.h | 4 +- 2 files changed, 143 insertions(+), 25 deletions(-) diff --git a/MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitter.c b/= MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitter.c index e70ff6114a..022fca7cbb 100644 --- a/MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitter.c +++ b/MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitter.c @@ -16,7 +16,7 @@ never removed. Such design ensures sytem function well during none conso= le device situation. =20 -Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
(C) Copyright 2016 Hewlett Packard Enterprise Development LP
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD = License @@ -67,6 +67,8 @@ GLOBAL_REMOVE_IF_UNREFERENCED TEXT_IN_SPLITTER_PRIVATE_DA= TA mConIn =3D { (LIST_ENTRY *) NULL, (LIST_ENTRY *) NULL }, + (EFI_KEY_DATA *) NULL, + 0, 0, FALSE, =20 @@ -606,6 +608,7 @@ ConSplitterTextInConstructor ( ) { EFI_STATUS Status; + UINTN TextInExListCount; =20 // // Allocate buffer for Simple Text Input device @@ -631,6 +634,19 @@ ConSplitterTextInConstructor ( ); ASSERT_EFI_ERROR (Status); =20 + // + // Allocate buffer for KeyQueue + // + TextInExListCount =3D ConInPrivate->TextInExListCount; + Status =3D ConSplitterGrowBuffer ( + sizeof (EFI_KEY_DATA), + &TextInExListCount, + (VOID **) &ConInPrivate->KeyQueue + ); + if (EFI_ERROR (Status)) { + return EFI_OUT_OF_RESOURCES; + } + // // Allocate buffer for Simple Text Input Ex device // @@ -1968,6 +1984,17 @@ ConSplitterTextInExAddDevice ( return EFI_OUT_OF_RESOURCES; } } + + TextInExListCount =3D Private->TextInExListCount; + Status =3D ConSplitterGrowBuffer ( + sizeof (EFI_KEY_DATA), + &TextInExListCount, + (VOID **) &Private->KeyQueue + ); + if (EFI_ERROR (Status)) { + return EFI_OUT_OF_RESOURCES; + } + Status =3D ConSplitterGrowBuffer ( sizeof (EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *), &Private->TextInExListCount, @@ -3445,11 +3472,46 @@ ConSplitterTextInReset ( =20 if (!EFI_ERROR (ReturnStatus)) { ToggleStateSyncReInitialization (Private); + // + // Empty the key queue. + // + Private->CurrentNumberOfKeys =3D 0; } =20 return ReturnStatus; } =20 +/** + Dequeue the saved key from internal key queue. + + @param Private Protocol instance pointer. + @param KeyData A pointer to a buffer that is filled in= with the + keystroke state data for the key that w= as + pressed. + @retval EFI_NOT_FOUND Queue is empty. + @retval EFI_SUCCESS First key is dequeued and returned. +**/ +EFI_STATUS +ConSplitterTextInExDequeueKey ( + IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private, + OUT EFI_KEY_DATA *KeyData + ) +{ + if (Private->CurrentNumberOfKeys =3D=3D 0) { + return EFI_NOT_FOUND; + } + // + // Return the first saved key. + // + CopyMem (KeyData, &Private->KeyQueue[0], sizeof (EFI_KEY_DATA)); + Private->CurrentNumberOfKeys--; + CopyMem ( + &Private->KeyQueue[0], + &Private->KeyQueue[1], + Private->CurrentNumberOfKeys * sizeof (EFI_KEY_DATA) + ); + return EFI_SUCCESS; +} =20 /** Reads the next keystroke from the input device. The WaitForKey Event can @@ -3473,7 +3535,13 @@ ConSplitterTextInPrivateReadKeyStroke ( { EFI_STATUS Status; UINTN Index; - EFI_INPUT_KEY CurrentKey; + EFI_KEY_DATA KeyData; + + Status =3D ConSplitterTextInExDequeueKey (Private, &KeyData); + if (!EFI_ERROR (Status)) { + CopyMem (Key, &KeyData.Key, sizeof (EFI_INPUT_KEY)); + return Status; + } =20 Key->UnicodeChar =3D 0; Key->ScanCode =3D SCAN_NULL; @@ -3486,15 +3554,15 @@ ConSplitterTextInPrivateReadKeyStroke ( for (Index =3D 0; Index < Private->CurrentNumberOfConsoles;) { Status =3D Private->TextInList[Index]->ReadKeyStroke ( Private->TextInList[Index], - &CurrentKey + &KeyData.Key ); if (!EFI_ERROR (Status)) { // // If it is not partial keystorke, return the key. Otherwise, contin= ue // to read key from THIS physical console input device. // - if ((CurrentKey.ScanCode !=3D CHAR_NULL) || (CurrentKey.UnicodeChar = !=3D SCAN_NULL)) { - *Key =3D CurrentKey; + if ((KeyData.Key.ScanCode !=3D CHAR_NULL) || (KeyData.Key.UnicodeCha= r !=3D SCAN_NULL)) { + CopyMem (Key, &KeyData.Key, sizeof (EFI_INPUT_KEY)); return Status; } } else { @@ -3681,6 +3749,10 @@ ConSplitterTextInResetEx ( =20 if (!EFI_ERROR (ReturnStatus)) { ToggleStateSyncReInitialization (Private); + // + // Empty the key queue. + // + Private->CurrentNumberOfKeys =3D 0; } =20 return ReturnStatus; @@ -3714,6 +3786,7 @@ ConSplitterTextInReadKeyStrokeEx ( TEXT_IN_SPLITTER_PRIVATE_DATA *Private; EFI_STATUS Status; UINTN Index; + EFI_KEY_STATE KeyState; EFI_KEY_DATA CurrentKeyData; =20 =20 @@ -3725,9 +3798,6 @@ ConSplitterTextInReadKeyStrokeEx ( =20 Private->KeyEventSignalState =3D FALSE; =20 - KeyData->Key.UnicodeChar =3D 0; - KeyData->Key.ScanCode =3D SCAN_NULL; - // // Signal ConnectConIn event on first call in Lazy ConIn mode // @@ -3738,35 +3808,81 @@ ConSplitterTextInReadKeyStrokeEx ( } =20 // - // if no physical console input device exists, return EFI_NOT_READY; - // if any physical console input device has key input, - // return the key and EFI_SUCCESS. + // Return the first saved key. + // + Status =3D ConSplitterTextInExDequeueKey (Private, KeyData); + if (!EFI_ERROR (Status)) { + return Status; + } + ASSERT (Private->CurrentNumberOfKeys =3D=3D 0); + + ZeroMem (&KeyState, sizeof (KeyState)); + + // + // Iterate through all physical consoles to get key state. + // Some physical consoles may return valid key. + // Queue the valid keys. // - for (Index =3D 0; Index < Private->CurrentNumberOfExConsoles;) { + for (Index =3D 0; Index < Private->CurrentNumberOfExConsoles; Index++) { + ZeroMem (&CurrentKeyData, sizeof (EFI_KEY_DATA)); Status =3D Private->TextInExList[Index]->ReadKeyStrokeEx ( - Private->TextInExList[Index], - &CurrentKeyData - ); + Private->TextInExList[Index], + &CurrentKeyData + ); + if (EFI_ERROR (Status) && (Status !=3D EFI_NOT_READY)) { + continue; + } + + // + // Consolidate the key state from all physical consoles. + // + if ((CurrentKeyData.KeyState.KeyShiftState & EFI_SHIFT_STATE_VALID) != =3D 0) { + KeyState.KeyShiftState |=3D CurrentKeyData.KeyState.KeyShiftState; + } + if ((CurrentKeyData.KeyState.KeyToggleState & EFI_TOGGLE_STATE_VALID) = !=3D 0) { + KeyState.KeyToggleState |=3D CurrentKeyData.KeyState.KeyToggleState; + } + if (!EFI_ERROR (Status)) { // // If virtual KeyState has been required to be exposed, or it is not - // partial keystorke, return the key. Otherwise, continue to read ke= y - // from THIS physical console input device. + // partial keystorke, queue the key. + // It's possible that user presses at multiple keyboards at the same= moment, + // Private->KeyQueue[] are the storage to save all the keys. // if ((Private->VirtualKeyStateExported) || (CurrentKeyData.Key.ScanCode !=3D CHAR_NULL) || (CurrentKeyData.Key.UnicodeChar !=3D SCAN_NULL)) { - CopyMem (KeyData, &CurrentKeyData, sizeof (CurrentKeyData)); - return Status; + CopyMem ( + &Private->KeyQueue[Private->CurrentNumberOfKeys], + &CurrentKeyData, + sizeof (EFI_KEY_DATA) + ); + Private->CurrentNumberOfKeys++; } - } else { - // - // Continue to read key from NEXT physical console input device. - // - Index++; } } =20 + // + // Consolidate the key state for all keys in Private->KeyQueue[] + // + for (Index =3D 0; Index < Private->CurrentNumberOfKeys; Index++) { + CopyMem (&Private->KeyQueue[Index].KeyState, &KeyState, sizeof (EFI_KE= Y_STATE)); + } + =20 + // + // Return the first saved key. + // + Status =3D ConSplitterTextInExDequeueKey (Private, KeyData); + if (!EFI_ERROR (Status)) { + return Status; + } + + // + // Always return the key state even there is no key pressed. + // + ZeroMem (&KeyData->Key, sizeof (KeyData->Key)); + CopyMem (&KeyData->KeyState, &KeyState, sizeof (KeyData->KeyState)); return EFI_NOT_READY; } =20 diff --git a/MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitter.h b/= MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitter.h index 9469860bf0..5fde6b0cb4 100644 --- a/MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitter.h +++ b/MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitter.h @@ -1,7 +1,7 @@ /** @file Private data structures for the Console Splitter driver =20 -Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2018, 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 @@ -129,6 +129,8 @@ typedef struct { EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL **TextInExList; UINTN TextInExListCount; LIST_ENTRY NotifyList; + EFI_KEY_DATA *KeyQueue; + UINTN CurrentNumberOfKeys; // // It will be initialized and synced between console input devices // for toggle state sync. --=20 2.15.1.windows.2