Received: from eggs.gnu.org ([2001:4830:134:3::10]:46079) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bZycO-0008GW-MN for qemu-devel@nongnu.org; Wed, 17 Aug 2016 07:02:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bZycL-0003oL-ES for qemu-devel@nongnu.org; Wed, 17 Aug 2016 07:02:44 -0400 Date: Wed, 17 Aug 2016 21:01:29 +1000 From: David Gibson Message-ID: <20160817110129.GB3091@voom.fritz.box> References: <1471047003-1502-1-git-send-email-programmingkidx@gmail.com> <1471047003-1502-6-git-send-email-programmingkidx@gmail.com> <20160815121942.GG27484@voom.fritz.box> <20160816035505.GE14530@voom.fritz.box> <49F90BF3-F744-4ED0-911D-DF4F4C57B817@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="nVMJ2NtxeReIH9PS" Content-Disposition: inline In-Reply-To: <49F90BF3-F744-4ED0-911D-DF4F4C57B817@gmail.com> Subject: Re: [Qemu-devel] [PATCH v4 5/5] adb.c: add power key support List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Programmingkid Cc: qemu-devel qemu-devel , "list@suse.de:PowerPC list:PowerPC" --nVMJ2NtxeReIH9PS Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Aug 16, 2016 at 10:06:14AM -0400, Programmingkid wrote: >=20 > On Aug 15, 2016, at 11:55 PM, David Gibson wrote: >=20 > > On Mon, Aug 15, 2016 at 03:53:02PM -0400, Programmingkid wrote: > >>=20 > >> On Aug 15, 2016, at 8:19 AM, David Gibson wrote: > >>=20 > >>> On Fri, Aug 12, 2016 at 08:10:03PM -0400, John Arbuckle wrote: > >>>> Add support for the power key. > >>>>=20 > >>>> Signed-off-by: John Arbuckle > >>>> Reviewed-by: Peter Maydell > >>>> --- > >>>> v4 changes > >>>> Removed double-quote from end of comment. > >>>> Removed debug printf statement. > >>>>=20 > >>>> v3 change > >>>> Add several suggested comments. > >>>> Moved the location of an else statement in the adb_keyboard_event() = function. > >>>>=20 > >>>> hw/input/adb.c | 43 +++++++++++++++++++++++++++++++++---------- > >>>> 1 file changed, 33 insertions(+), 10 deletions(-) > >>>>=20 > >>>> diff --git a/hw/input/adb.c b/hw/input/adb.c > >>>> index 2042903..3998490 100644 > >>>> --- a/hw/input/adb.c > >>>> +++ b/hw/input/adb.c > >>>> @@ -340,10 +340,25 @@ static int adb_kbd_poll(ADBDevice *d, uint8_t = *obuf) > >>>> s->rptr =3D 0; > >>>> } > >>>> s->count--; > >>>> - obuf[0] =3D keycode; > >>>> - /* NOTE: could put a second keycode if needed */ > >>>> - obuf[1] =3D 0xff; > >>>> - olen =3D 2; > >>>> + /* > >>>> + * The power key is the only two byte value key, so it is a spe= cial case. > >>>> + * Since 0x7f is not a used keycode for ADB we overload it to i= ndicate the > >>>> + * power button when we're storing keycodes in our internal buf= fer, and > >>>> + * expand it out to two bytes when we send to the guest. > >>>> + */ > >>>> + if (keycode =3D=3D 0x7f) { > >>>> + obuf[0] =3D 0x7f; > >>>> + obuf[1] =3D 0x7f; > >>>> + olen =3D 2; > >>>> + } else { > >>>> + obuf[0] =3D keycode; > >>>> + /* NOTE: the power key key-up is the two byte sequence 0xff= 0xff; > >>>> + * otherwise we could in theory send a second keycode in th= e second > >>>> + * byte, but choose not to bother. > >>>> + */ > >>>> + obuf[1] =3D 0xff; > >>>> + olen =3D 2; > >>>> + } > >>>>=20 > >>>> return olen; > >>>> } > >>>> @@ -421,14 +436,22 @@ static void adb_keyboard_event(DeviceState *de= v, QemuConsole *src, > >>>> return; > >>>> } > >>>> keycode =3D qcode_to_adb_keycode[qcode]; > >>>> - if (keycode =3D=3D NO_KEY) { /* We don't want to send this to = the guest */ > >>>> + > >>>> + /* The power button is a special case because it is a 16-bit va= lue */ > >>>> + if (qcode =3D=3D Q_KEY_CODE_POWER) { > >>>> + if (evt->u.key.data->down =3D=3D true) { /* Power button pu= shed keycode */ > >>>> + adb_kbd_put_keycode(s, 0x7f); > >>>> + } else { /* Power button released= keycode */ > >>>> + adb_kbd_put_keycode(s, 0xff); > >>>> + } > >>>> + } else if (keycode =3D=3D NO_KEY) { /* NO_KEY shouldn't be sent= to guest */ > >>>> return; > >>>> + } else { /* For all non-power keys - safe for 8-bit keycodes = */ > >>>> + if (evt->u.key.data->down =3D=3D false) { /* if key release= event */ > >>>> + keycode =3D keycode | 0x80; /* create keyboard break = code */ > >>>> + } > >>>> + adb_kbd_put_keycode(s, keycode); > >>>=20 > >>> The logic in the CODE_POWER and else cases doesn't actually seem to be > >>> different AFAICT. > >>=20 > >> The power key is a 16 bit value. > >=20 > > I assume you're meaning the adb code here, rather than the qkey code, > > yes? >=20 > Yes. >=20 > > Oh.. btw.. your initial adb-keys.h commit has ADB_KEY_POWER commented > > out, and I didn't see that removed in any of the intervening patches. >=20 > I completely forgot about that. >=20 > It does look like I can use the else case in the adb_keyboard_event() for= the Power key. >=20 > >=20 > >> It needs its own special case or the operating > >> system would not see it. After disabling the "if (qcode =3D=3D Q_KEY_C= ODE_POWER)" condition > >> so the power key would go thru the else statement, the guest stopped d= etecting the > >> power key. > >=20 > > Well.. I don't think your earlier patches actually put a mapping in > > the table for Q_KEY_CODE_POWER, so I guess it would map to NO_KEY, > > which would explain that. But I don't see a reason you need special > > logic here rather than just adding the mapping to the table. > >=20 > > The Q_KEY_CODE_POWER case here still only invokes a single > > adb_kbd_put_keycode() with an 8-bit value. So I'm not really seeing > > where the 16-bit value comes into play. > >=20 > >>>> } > >>>> - if (evt->u.key.data->down =3D=3D false) { /* if key release eve= nt */ > >>>> - keycode =3D keycode | 0x80; /* create keyboard break code= */ > >>>> - } > >>>> - > >>>> - adb_kbd_put_keycode(s, keycode); > >>>> } > >>>>=20 > >>>> static const VMStateDescription vmstate_adb_kbd =3D { >=20 > Ok I think I have a plan for my next set of patches: >=20 > patch 1: adb-keys.h initial commit=20 > - with Power key uncommented >=20 > patch 2: add support for QKeyCode > - minus the Power key if-condition in adb_keyboard_event() > - with NO_KEY mapping added to beginning of the qcode_to_adb_keycode arr= ay > - with NO_KEY if-condition added to the adb_keyboard_event() function > - with the ADB_DPRINTF() code added to the adb_keyboard_event() (see bel= ow) > if (keycode =3D=3D NO_KEY) { /* NO_KEY shouldn't be sent to guest */ > ADB_DPRINTF("Ignoring NO_KEY\n"); > return; Actually I think the NO_KEY handling would still be clearer in a separate patch. > - with added commit message that states "just a mechanical substitution,= which > a number of broken mappings left in." This comment wouldn't be entirely accurate if you include the NO_KEY changes, which is another reason to keep it separate. Something like this should definitely go in the message though - this is basically a signal to reviewers that they should just be checking the new code has the same effect as the old, not that it makes sense in absolute terms. > - with qemu_input_handler_register() call moved to the realized() functi= on > - code from power key patch merged with this patch That change should definitely be folded in though. >=20 > patch 3: correct several key assignments > - Will still fix the broken mappings left in >=20 > If this looks right I will make my next set of patches. --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --nVMJ2NtxeReIH9PS Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJXtEQJAAoJEGw4ysog2bOS8vQQAMBLhAtHWxEoVxay/KN8hlUW HonQCdmbWBRQdU12XuN01P7/qyYG1Gy1nNTZuGf8Sr1b6/6fmyulwwrr8OMBKN3r /JOD3Xt3bInZbStiUG1ewXQmJao9RIjnIdsuHb9XghL+WjW0eFl5z8iO+7bZ7C1Y JSfrsV1tXM7lqQa7W80TwOp+IpnadBD7P8wlPxim3Aqmu4KKatMOYwvn0u4uDr6s hMMVdROICRSYdr1APpXiykvkaBbhxhAHQv7sH+Mm6xLai98CF9zFnprIzc8eBwDF 2ZUaz5awE17yEgzakWQFnPvUjjN1qLyQsuDD+u1+wdM6RD/kYaDjpe0aSUOTE6Lr AQk6c6m/7zvB3o1gl+moWdTJ2muW7gd/ZxhOORRQIEHD9ncx4jLP5utud1K4SkwK WCNiLR85VNM3R/U3/KG9MGxtdpLgeC/LVjpN+qoqR4ucU0nejtmKLhCPfCHcPLxy ym/tre5QOCmi031AbO48IWajtOJCfm5AGm1whAwzGstWJHVl5nUj6kkvTgBBBCFZ xt7RKmcq+yJu87HPxBZBoAk4iOerrRa+BBAsnl1ALJzsTiNvjamm9gud8ja9Njkf SccOY5UhNySXcafE8Mi6gryoiSBLw/UYDj04O5guP1DKKnJFJ3KTt/o08qkPAWpD C6zT2W9r6nOhTPvcv171 =L7io -----END PGP SIGNATURE----- --nVMJ2NtxeReIH9PS--