From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (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 E62D381895 for ; Mon, 26 Dec 2016 00:49:06 -0800 (PST) Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga104.jf.intel.com with ESMTP; 26 Dec 2016 00:49:06 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,404,1477983600"; d="scan'208";a="43366100" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by orsmga004.jf.intel.com with ESMTP; 26 Dec 2016 00:49:00 -0800 Received: from shsmsx151.ccr.corp.intel.com (10.239.6.50) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.248.2; Mon, 26 Dec 2016 00:49:00 -0800 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.59]) by SHSMSX151.ccr.corp.intel.com ([169.254.3.204]) with mapi id 14.03.0248.002; Mon, 26 Dec 2016 16:48:56 +0800 From: "Ni, Ruiyu" To: "Zeng, Star" , "edk2-devel@lists.01.org" CC: "Kinney, Michael D" , "Tian, Feng" Thread-Topic: [PATCH V2] MdeModulePkg ConSplitterDxe: Support toggle state sync Thread-Index: AQHSX0kOfWRZ5SqCIEuXUKaghXqlq6EZ6thA Date: Mon, 26 Dec 2016 08:48:56 +0000 Deferred-Delivery: Mon, 26 Dec 2016 08:48:00 +0000 Message-ID: <734D49CCEBEEF84792F5B80ED585239D5B8656AB@SHSMSX104.ccr.corp.intel.com> References: <1482737035-58136-1-git-send-email-star.zeng@intel.com> In-Reply-To: <1482737035-58136-1-git-send-email-star.zeng@intel.com> Accept-Language: en-US, zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH V2] MdeModulePkg ConSplitterDxe: Support toggle state sync 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: Mon, 26 Dec 2016 08:49:07 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Ruiyu Ni Thanks/Ray > -----Original Message----- > From: Zeng, Star > Sent: Monday, December 26, 2016 3:24 PM > To: edk2-devel@lists.01.org > Cc: Zeng, Star ; Ni, Ruiyu ; > Kinney, Michael D ; Tian, Feng > > Subject: [PATCH V2] MdeModulePkg ConSplitterDxe: Support toggle state > sync >=20 > Register key notify for toggle state (CapsLock, NumLock and ScrollLock) s= ync > between multiple keyboards. > The implementation for this feature requires keyboard driver supports > EFI_KEY_STATE_EXPOSED, and turns on physical TextInEx partial key report > for toggle state sync. > The virtual TextInEx will report the partial key after it is required by = calling > SetState(X | KEY_STATE_VALID_EXPOSED) explicitly. >=20 > V2: > Based on the comments from Ruiyu, Ni, > refine the logic in ConSplitterTextInPrivateReadKeyStroke() and > ConSplitterTextInReadKeyStrokeEx(), make the code in > ToggleStateSyncHookSetState() and ToggleStateSyncToNewConInDev() to > be in-line of the caller, add more comments to make the code more clear. >=20 > Cc: Ruiyu Ni > Cc: Michael Kinney > Cc: Feng Tian > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Star Zeng > --- > .../Universal/Console/ConSplitterDxe/ConSplitter.c | 190 > ++++++++++++++++++++- > .../Universal/Console/ConSplitterDxe/ConSplitter.h | 13 +- > 2 files changed, 194 insertions(+), 9 deletions(-) >=20 > diff --git a/MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitter.c > b/MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitter.c > index 493bcbafdf39..7ef141facf36 100644 > --- a/MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitter.c > +++ b/MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitter.c > @@ -67,6 +67,8 @@ GLOBAL_REMOVE_IF_UNREFERENCED > TEXT_IN_SPLITTER_PRIVATE_DATA mConIn =3D { > (LIST_ENTRY *) NULL, > (LIST_ENTRY *) NULL > }, > + 0, > + FALSE, >=20 > { > ConSplitterSimplePointerReset, > @@ -301,6 +303,122 @@ EFI_DRIVER_BINDING_PROTOCOL > gConSplitterAbsolutePointerDriverBinding =3D > }; >=20 > /** > + Key notify for toggle state sync. > + > + @param KeyData A pointer to a buffer that is filled in with > + the keystroke information for the key that was > + pressed. > + > + @retval EFI_SUCCESS Toggle state sync successfully. > + > +**/ > +EFI_STATUS > +EFIAPI > +ToggleStateSyncKeyNotify ( > + IN EFI_KEY_DATA *KeyData > + ) > +{ > + UINTN Index; > + > + if (((KeyData->KeyState.KeyToggleState & KEY_STATE_VALID_EXPOSED) > =3D=3D KEY_STATE_VALID_EXPOSED) && > + (KeyData->KeyState.KeyToggleState !=3D mConIn.PhysicalKeyToggleSta= te)) > { > + // > + // There is toggle state change, sync to other console input devices= . > + // > + for (Index =3D 0; Index < mConIn.CurrentNumberOfExConsoles; Index++)= { > + mConIn.TextInExList[Index]->SetState ( > + mConIn.TextInExList[Index], > + &KeyData->KeyState.KeyToggleState > + ); > + } > + mConIn.PhysicalKeyToggleState =3D KeyData->KeyState.KeyToggleState; > + DEBUG ((EFI_D_INFO, "Current toggle state is 0x%02x\n", > + mConIn.PhysicalKeyToggleState)); } > + > + return EFI_SUCCESS; > +} > + > +/** > + Initialization for toggle state sync. > + > + @param Private Text In Splitter pointer. > + > +**/ > +VOID > +ToggleStateSyncInitialization ( > + IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private > + ) > +{ > + EFI_KEY_DATA KeyData; > + VOID *NotifyHandle; > + > + // > + // Initialize PhysicalKeyToggleState that will be synced to new > + console // input device to turn on physical TextInEx partial key > + report for // toggle state sync. > + // > + Private->PhysicalKeyToggleState =3D KEY_STATE_VALID_EXPOSED; > + > + // > + // Initialize VirtualKeyStateExported to let the virtual TextInEx not > + report // the partial key even though the physical TextInEx turns on > + the partial // key report. The virtual TextInEx will report the > + partial key after it is // required by calling SetState(X | > KEY_STATE_VALID_EXPOSED) explicitly. > + // > + Private->VirtualKeyStateExported =3D FALSE; > + > + // > + // Register key notify for toggle state sync. > + // > + KeyData.Key.ScanCode =3D SCAN_NULL; > + KeyData.Key.UnicodeChar =3D CHAR_NULL; > + KeyData.KeyState.KeyShiftState =3D 0; > + KeyData.KeyState.KeyToggleState =3D 0; > + Private->TextInEx.RegisterKeyNotify ( > + &Private->TextInEx, > + &KeyData, > + ToggleStateSyncKeyNotify, > + &NotifyHandle > + ); > +} > + > +/** > + Reinitialization for toggle state sync. > + > + @param Private Text In Splitter pointer. > + > +**/ > +VOID > +ToggleStateSyncReInitialization ( > + IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private > + ) > +{ > + UINTN Index; > + > + // > + // Reinitialize PhysicalKeyToggleState that will be synced to new > + console // input device to turn on physical TextInEx partial key > + report for // toggle state sync. > + // > + Private->PhysicalKeyToggleState =3D KEY_STATE_VALID_EXPOSED; > + > + // > + // Reinitialize VirtualKeyStateExported to let the virtual TextInEx > + not report // the partial key even though the physical TextInEx turns > + on the partial // key report. The virtual TextInEx will report the > + partial key after it is // required by calling SetState(X | > KEY_STATE_VALID_EXPOSED) explicitly. > + // > + Private->VirtualKeyStateExported =3D FALSE; > + > + for (Index =3D 0; Index < Private->CurrentNumberOfExConsoles; Index++)= { > + Private->TextInExList[Index]->SetState ( > + Private->TextInExList[Index], > + &Private->PhysicalKeyToggleState > + ); > + } > +} > + > +/** > The Entry Point for module ConSplitter. The user code starts with this > function. >=20 > Installs driver module protocols and. Creates virtual device handles f= or > ConIn, @@ -538,6 +656,8 @@ ConSplitterTextInConstructor ( >=20 > InitializeListHead (&ConInPrivate->NotifyList); >=20 > + ToggleStateSyncInitialization (ConInPrivate); > + > ConInPrivate->AbsolutePointer.Mode =3D &ConInPrivate- > >AbsolutePointerMode; > // > // Allocate buffer for Absolute Pointer device @@ -1891,6 +2011,11 @@ > ConSplitterTextInExAddDevice ( > Private->CurrentNumberOfExConsoles++; >=20 > // > + // Sync current toggle state to this new console input device. > + // > + TextInEx->SetState (TextInEx, &Private->PhysicalKeyToggleState); > + > + // > // Extra CheckEvent added to reduce the double CheckEvent(). > // > gBS->CheckEvent (TextInEx->WaitForKeyEx); @@ -3321,6 +3446,10 @@ > ConSplitterTextInReset ( > } > } >=20 > + if (!EFI_ERROR (ReturnStatus)) { > + ToggleStateSyncReInitialization (Private); } > + > return ReturnStatus; > } >=20 > @@ -3357,14 +3486,25 @@ ConSplitterTextInPrivateReadKeyStroke ( > // if any physical console input device has key input, > // return the key and EFI_SUCCESS. > // > - for (Index =3D 0; Index < Private->CurrentNumberOfConsoles; Index++) { > + for (Index =3D 0; Index < Private->CurrentNumberOfConsoles;) { > Status =3D Private->TextInList[Index]->ReadKeyStroke ( > Private->TextInList[Index], > &CurrentKey > ); > if (!EFI_ERROR (Status)) { > - *Key =3D CurrentKey; > - return Status; > + // > + // If it is not partial keystorke, return the key. Otherwise, cont= inue > + // to read key from THIS physical console input device. > + // > + if ((CurrentKey.ScanCode !=3D CHAR_NULL) || > (CurrentKey.UnicodeChar !=3D SCAN_NULL)) { > + *Key =3D CurrentKey; > + return Status; > + } > + } else { > + // > + // Continue to read key from NEXT physical console input device. > + // > + Index++; > } > } >=20 > @@ -3542,6 +3682,10 @@ ConSplitterTextInResetEx ( > } > } >=20 > + if (!EFI_ERROR (ReturnStatus)) { > + ToggleStateSyncReInitialization (Private); } > + > return ReturnStatus; >=20 > } > @@ -3601,14 +3745,28 @@ ConSplitterTextInReadKeyStrokeEx ( > // if any physical console input device has key input, > // return the key and EFI_SUCCESS. > // > - for (Index =3D 0; Index < Private->CurrentNumberOfExConsoles; Index++)= { > + for (Index =3D 0; Index < Private->CurrentNumberOfExConsoles;) { > Status =3D Private->TextInExList[Index]->ReadKeyStrokeEx ( > Private->TextInExList[Index], > &CurrentKeyData > ); > if (!EFI_ERROR (Status)) { > - CopyMem (KeyData, &CurrentKeyData, sizeof (CurrentKeyData)); > - return Status; > + // > + // If virtual KeyState has been required to be exposed, or it is n= ot > + // partial keystorke, return the key. Otherwise, continue to read = key > + // from THIS physical console input device. > + // > + if ((Private->VirtualKeyStateExported) || > + (CurrentKeyData.Key.ScanCode !=3D CHAR_NULL) || > + (CurrentKeyData.Key.UnicodeChar !=3D SCAN_NULL)) { > + CopyMem (KeyData, &CurrentKeyData, sizeof (CurrentKeyData)); > + return Status; > + } > + } else { > + // > + // Continue to read key from NEXT physical console input device. > + // > + Index++; > } > } >=20 > @@ -3641,6 +3799,7 @@ ConSplitterTextInSetState ( > TEXT_IN_SPLITTER_PRIVATE_DATA *Private; > EFI_STATUS Status; > UINTN Index; > + EFI_KEY_TOGGLE_STATE PhysicalKeyToggleState; >=20 > if (KeyToggleState =3D=3D NULL) { > return EFI_INVALID_PARAMETER; > @@ -3649,19 +3808,34 @@ ConSplitterTextInSetState ( > Private =3D TEXT_IN_EX_SPLITTER_PRIVATE_DATA_FROM_THIS (This); >=20 > // > + // Always turn on physical TextInEx partial key report for // toggle > + state sync. > + // > + PhysicalKeyToggleState =3D *KeyToggleState | EFI_KEY_STATE_EXPOSED; > + > + // > // if no physical console input device exists, return EFI_SUCCESS; > // otherwise return the status of setting state of physical console in= put > device > // > for (Index =3D 0; Index < Private->CurrentNumberOfExConsoles; Index++)= { > Status =3D Private->TextInExList[Index]->SetState ( > Private->TextInExList[Index= ], > - KeyToggleState > + &PhysicalKeyToggleState > ); > if (EFI_ERROR (Status)) { > return Status; > } > } >=20 > + // > + // Record the physical KeyToggleState. > + // > + Private->PhysicalKeyToggleState =3D PhysicalKeyToggleState; // // Ge= t > + if virtual KeyState has been required to be exposed. > + // > + Private->VirtualKeyStateExported =3D (((*KeyToggleState) & > + EFI_KEY_STATE_EXPOSED) !=3D 0); > + > return EFI_SUCCESS; >=20 > } > @@ -3765,7 +3939,7 @@ ConSplitterTextInRegisterKeyNotify ( > } > } >=20 > - InsertTailList (&mConIn.NotifyList, &NewNotify->NotifyEntry); > + InsertTailList (&Private->NotifyList, &NewNotify->NotifyEntry); >=20 > *NotifyHandle =3D NewNotify; >=20 > diff --git a/MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitter.h > b/MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitter.h > index e32abbaea133..e6ef40d00c23 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 - 2012, Intel Corporation. All rights reserved.
> +Copyright (c) 2006 - 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 > @@ -88,6 +88,7 @@ typedef struct { > UINTN Rows; > } TEXT_OUT_SPLITTER_QUERY_DATA; >=20 > +#define KEY_STATE_VALID_EXPOSED (EFI_TOGGLE_STATE_VALID | > +EFI_KEY_STATE_EXPOSED) >=20 > #define TEXT_IN_EX_SPLITTER_NOTIFY_SIGNATURE SIGNATURE_32 ('T', 'i', > 'S', 'n') >=20 > @@ -128,6 +129,16 @@ typedef struct { > EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL **TextInExList; > UINTN TextInExListCount; > LIST_ENTRY NotifyList; > + // > + // It will be initialized and synced between console input devices > + // for toggle state sync. > + // > + EFI_KEY_TOGGLE_STATE PhysicalKeyToggleState; > + // > + // It will be initialized and used to record if virtual KeyState // > + has been required to be exposed. > + // > + BOOLEAN VirtualKeyStateExported; >=20 >=20 > EFI_SIMPLE_POINTER_PROTOCOL SimplePointer; > -- > 2.7.0.windows.1