From owner-svn-src-all@freebsd.org Mon Aug 22 16:39:52 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 1A871BC2F5D; Mon, 22 Aug 2016 16:39:52 +0000 (UTC) (envelope-from bde@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id ECA971803; Mon, 22 Aug 2016 16:39:51 +0000 (UTC) (envelope-from bde@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u7MGdpGa014381; Mon, 22 Aug 2016 16:39:51 GMT (envelope-from bde@FreeBSD.org) Received: (from bde@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u7MGdpaD014380; Mon, 22 Aug 2016 16:39:51 GMT (envelope-from bde@FreeBSD.org) Message-Id: <201608221639.u7MGdpaD014380@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: bde set sender to bde@FreeBSD.org using -f From: Bruce Evans Date: Mon, 22 Aug 2016 16:39:51 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r304612 - head/sys/dev/usb/input X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Aug 2016 16:39:52 -0000 Author: bde Date: Mon Aug 22 16:39:51 2016 New Revision: 304612 URL: https://svnweb.freebsd.org/changeset/base/304612 Log: Further fixes for translation of PrintScreen/SysRq. The previous fix was tested mainly on 3 AT keyboards with USB adaptors where it works. 1 USB keyboard doesn't translate Alt-PrintScreen, so the software has to do it. Reorganize a little to share some code and to not translate the unusual usb scan code0x8a unless an Alt modified is set. Remove redundant check of Alt modifiers. Translation now more clearly filters out Alt-PrintScreen before the check. The table of errors fixed in the previous commit had many bugs. Correct table: K_RAW Ctl-PrintScreen: E0-2A-E0-37 -> E0-37 K_RAW Alt-PrintScreen (with 4 comb. of Ctl/Shift): 79 -> 54 K_RAW Pause/Break (with 4 comb. of Alt/Shift): E0-46 -> E1-1D-45 K_CODE PrintScreen (with 4 comb. of Ctl/Shift): 54 -> 5c K_CODE Alt-PrintScreen (with 4 comb. of Ctl/Shift): 7e -> 54 K_CODE Pause/Break (with 8 comb. of Ctl/Alt/Shift): 6c -> 68 That is 25 of 32 shift combinations for 2 keys fixed. All 16 combinations were broken for K_CODE and thus also for K_XLATE. Modified: head/sys/dev/usb/input/ukbd.c Modified: head/sys/dev/usb/input/ukbd.c ============================================================================== --- head/sys/dev/usb/input/ukbd.c Mon Aug 22 16:35:50 2016 (r304611) +++ head/sys/dev/usb/input/ukbd.c Mon Aug 22 16:39:51 2016 (r304612) @@ -324,7 +324,7 @@ static const uint8_t ukbd_trtab[256] = { NN, NN, NN, NN, 115, 108, 111, 113, /* 70 - 77 */ 109, 110, 112, 118, 114, 116, 117, 119, /* 78 - 7F */ 121, 120, NN, NN, NN, NN, NN, 123, /* 80 - 87 */ - 124, 125, 84, 127, 128, NN, NN, NN, /* 88 - 8F */ + 124, 125, 126, 127, 128, NN, NN, NN, /* 88 - 8F */ 129, 130, NN, NN, NN, NN, NN, NN, /* 90 - 97 */ NN, NN, NN, NN, NN, NN, NN, NN, /* 98 - 9F */ NN, NN, NN, NN, NN, NN, NN, NN, /* A0 - A7 */ @@ -362,6 +362,7 @@ static void ukbd_timeout(void *); static void ukbd_set_leds(struct ukbd_softc *, uint8_t); static int ukbd_set_typematic(keyboard_t *, int); #ifdef UKBD_EMULATE_ATSCANCODE +static uint32_t ukbd_atkeycode(int, int); static int ukbd_key2scan(struct ukbd_softc *, int, int, int); #endif static uint32_t ukbd_read_char(keyboard_t *, int); @@ -1580,7 +1581,7 @@ ukbd_read(keyboard_t *kbd, int wait) ++(kbd->kb_count); #ifdef UKBD_EMULATE_ATSCANCODE - keycode = ukbd_trtab[KEY_INDEX(usbcode)]; + keycode = ukbd_atkeycode(usbcode, sc->sc_ndata.modifiers); if (keycode == NN) { return -1; } @@ -1651,7 +1652,7 @@ next_code: #ifdef UKBD_EMULATE_ATSCANCODE /* USB key index -> key code -> AT scan code */ - keycode = ukbd_trtab[KEY_INDEX(usbcode)]; + keycode = ukbd_atkeycode(usbcode, sc->sc_ndata.modifiers); if (keycode == NN) { return (NOKEY); } @@ -2060,6 +2061,31 @@ ukbd_set_typematic(keyboard_t *kbd, int } #ifdef UKBD_EMULATE_ATSCANCODE +static uint32_t +ukbd_atkeycode(int usbcode, int shift) +{ + uint32_t keycode; + + keycode = ukbd_trtab[KEY_INDEX(usbcode)]; + /* + * Translate Alt-PrintScreen to SysRq. + * + * Some or all AT keyboards connected through USB have already + * mapped Alted PrintScreens to an unusual usbcode (0x8a). + * ukbd_trtab translates this to 0x7e, and key2scan() would + * translate that to 0x79 (Intl' 4). Assume that if we have + * an Alted 0x7e here then it actually is an Alted PrintScreen. + * + * The usual usbcode for all PrintScreens is 0x46. ukbd_trtab + * translates this to 0x5c, so the Alt check to classify 0x5c + * is routine. + */ + if ((keycode == 0x5c || keycode == 0x7e) && + shift & (MOD_ALT_L | MOD_ALT_R)) + return (0x54); + return (keycode); +} + static int ukbd_key2scan(struct ukbd_softc *sc, int code, int shift, int up) { @@ -2082,7 +2108,7 @@ ukbd_key2scan(struct ukbd_softc *sc, int 0x151, /* PageDown */ 0x152, /* Insert */ 0x153, /* Delete */ - 0x146, /* XXX Pause/Break */ + 0x146, /* Pause/Break */ 0x15b, /* Win_L(Super_L) */ 0x15c, /* Win_R(Super_R) */ 0x15d, /* Application(Menu) */ @@ -2122,7 +2148,7 @@ ukbd_key2scan(struct ukbd_softc *sc, int } /* PrintScreen */ if (code == 0x137 && (!(shift & (MOD_CONTROL_L | MOD_CONTROL_R | - MOD_ALT_L | MOD_ALT_R | MOD_SHIFT_L | MOD_SHIFT_R)))) { + MOD_SHIFT_L | MOD_SHIFT_R)))) { code |= SCAN_PREFIX_SHIFT; } /* Pause/Break */