Author: araujo
Date: Sun Dec  9 06:42:06 2018
New Revision: 341758
URL: https://svnweb.freebsd.org/changeset/base/341758

Log:
  MFC r340046, r340050
  
  r340046:
  Add support ps/2 scancodes for NumLock, ScrollLock and numerical keypad
  keys.
  
  PR:           213835
  Submitted by: Vasily Postnicov <ivan.zhm...@gmail.com>
  Relnotes:     Yes
  Sponsored by: iXsystems Inc.
  
  r340050:
  Remove printf for debug purpose forgotten on r340046.
  
  Reported by:  Dmitry Luhtionov <dmitryluhtio...@gmail.com>

Modified:
  stable/11/usr.sbin/bhyve/ps2kbd.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/usr.sbin/bhyve/ps2kbd.c
==============================================================================
--- stable/11/usr.sbin/bhyve/ps2kbd.c   Sun Dec  9 06:41:57 2018        
(r341757)
+++ stable/11/usr.sbin/bhyve/ps2kbd.c   Sun Dec  9 06:42:06 2018        
(r341758)
@@ -76,6 +76,107 @@ struct ps2kbd_softc {
        uint8_t                 curcmd; /* current command for next byte */
 };
 
+#define SCANCODE_E0_PREFIX 1
+struct extended_translation {
+       uint32_t keysym;
+       uint8_t scancode;
+       int flags;
+};
+
+/*
+ * FIXME: Pause/break and Print Screen/SysRq require special handling.
+ */
+static const struct extended_translation extended_translations[] = {
+               {0xff08, 0x66},         /* Back space */
+               {0xff09, 0x0d},         /* Tab */
+               {0xff0d, 0x5a},         /* Return */
+               {0xff1b, 0x76},         /* Escape */
+               {0xff50, 0x6c, SCANCODE_E0_PREFIX},     /* Home */
+               {0xff51, 0x6b, SCANCODE_E0_PREFIX},     /* Left arrow */
+               {0xff52, 0x75, SCANCODE_E0_PREFIX},     /* Up arrow */
+               {0xff53, 0x74, SCANCODE_E0_PREFIX},     /* Right arrow */
+               {0xff54, 0x72, SCANCODE_E0_PREFIX},     /* Down arrow */
+               {0xff55, 0x7d, SCANCODE_E0_PREFIX},     /* PgUp */
+               {0xff56, 0x7a, SCANCODE_E0_PREFIX},     /* PgDown */
+               {0xff57, 0x69, SCANCODE_E0_PREFIX},     /* End */
+               {0xff63, 0x70, SCANCODE_E0_PREFIX},     /* Ins */
+               {0xff8d, 0x5a, SCANCODE_E0_PREFIX},     /* Keypad Enter */
+               {0xffe1, 0x12},         /* Left shift */
+               {0xffe2, 0x59},         /* Right shift */
+               {0xffe3, 0x14},         /* Left control */
+               {0xffe4, 0x14, SCANCODE_E0_PREFIX},     /* Right control */
+               /* {0xffe7, XXX}, Left meta */
+               /* {0xffe8, XXX}, Right meta */
+               {0xffe9, 0x11},         /* Left alt */
+               {0xfe03, 0x11, SCANCODE_E0_PREFIX},     /* AltGr */
+               {0xffea, 0x11, SCANCODE_E0_PREFIX},     /* Right alt */
+               {0xffeb, 0x1f, SCANCODE_E0_PREFIX},     /* Left Windows */
+               {0xffec, 0x27, SCANCODE_E0_PREFIX},     /* Right Windows */
+               {0xffbe, 0x05},         /* F1 */
+               {0xffbf, 0x06},         /* F2 */
+               {0xffc0, 0x04},         /* F3 */
+               {0xffc1, 0x0c},         /* F4 */
+               {0xffc2, 0x03},         /* F5 */
+               {0xffc3, 0x0b},         /* F6 */
+               {0xffc4, 0x83},         /* F7 */
+               {0xffc5, 0x0a},         /* F8 */
+               {0xffc6, 0x01},         /* F9 */
+               {0xffc7, 0x09},         /* F10 */
+               {0xffc8, 0x78},         /* F11 */
+               {0xffc9, 0x07},         /* F12 */
+               {0xffff, 0x71, SCANCODE_E0_PREFIX},     /* Del */
+               {0xff14, 0x7e},         /* ScrollLock */
+               /* NumLock and Keypads*/
+               {0xff7f, 0x77},         /* NumLock */
+               {0xffaf, 0x4a, SCANCODE_E0_PREFIX},     /* Keypad slash */
+               {0xffaa, 0x7c},         /* Keypad asterisk */
+               {0xffad, 0x7b},         /* Keypad minus */
+               {0xffab, 0x79},         /* Keypad plus */
+               {0xffb7, 0x6c},         /* Keypad 7 */
+               {0xff95, 0x6c},         /* Keypad home */
+               {0xffb8, 0x75},         /* Keypad 8 */
+               {0xff97, 0x75},         /* Keypad up arrow */
+               {0xffb9, 0x7d},         /* Keypad 9 */
+               {0xff9a, 0x7d},         /* Keypad PgUp */
+               {0xffb4, 0x6b},         /* Keypad 4 */
+               {0xff96, 0x6b},         /* Keypad left arrow */
+               {0xffb5, 0x73},         /* Keypad 5 */
+               {0xff9d, 0x73},         /* Keypad empty */
+               {0xffb6, 0x74},         /* Keypad 6 */
+               {0xff98, 0x74},         /* Keypad right arrow */
+               {0xffb1, 0x69},         /* Keypad 1 */
+               {0xff9c, 0x69},         /* Keypad end */
+               {0xffb2, 0x72},         /* Keypad 2 */
+               {0xff99, 0x72},         /* Keypad down arrow */
+               {0xffb3, 0x7a},         /* Keypad 3 */
+               {0xff9b, 0x7a},         /* Keypad PgDown */
+               {0xffb0, 0x70},         /* Keypad 0 */
+               {0xff9e, 0x70},         /* Keypad ins */
+               {0xffae, 0x71},         /* Keypad . */
+               {0xff9f, 0x71},         /* Keypad del */
+               {0, 0, 0}               /* Terminator */
+};
+
+/* ASCII to type 2 scancode lookup table */
+static const uint8_t ascii_translations[128] = {
+               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+               0x29, 0x16, 0x52, 0x26, 0x25, 0x2e, 0x3d, 0x52,
+               0x46, 0x45, 0x3e, 0x55, 0x41, 0x4e, 0x49, 0x4a,
+               0x45, 0x16, 0x1e, 0x26, 0x25, 0x2e, 0x36, 0x3d,
+               0x3e, 0x46, 0x4c, 0x4c, 0x41, 0x55, 0x49, 0x4a,
+               0x1e, 0x1c, 0x32, 0x21, 0x23, 0x24, 0x2b, 0x34,
+               0x33, 0x43, 0x3b, 0x42, 0x4b, 0x3a, 0x31, 0x44,
+               0x4d, 0x15, 0x2d, 0x1b, 0x2c, 0x3c, 0x2a, 0x1d,
+               0x22, 0x35, 0x1a, 0x54, 0x5d, 0x5b, 0x36, 0x4e,
+               0x0e, 0x1c, 0x32, 0x21, 0x23, 0x24, 0x2b, 0x34,
+               0x33, 0x43, 0x3b, 0x42, 0x4b, 0x3a, 0x31, 0x44,
+               0x4d, 0x15, 0x2d, 0x1b, 0x2c, 0x3c, 0x2a, 0x1d,
+               0x22, 0x35, 0x1a, 0x54, 0x5d, 0x5b, 0x0e, 0x00,
+};
+
 static void
 fifo_init(struct ps2kbd_softc *sc)
 {
@@ -212,236 +313,38 @@ static void
 ps2kbd_keysym_queue(struct ps2kbd_softc *sc,
     int down, uint32_t keysym)
 {
-       /* ASCII to type 2 scancode lookup table */
-       const uint8_t translation[128] = {
-               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-               0x29, 0x16, 0x52, 0x26, 0x25, 0x2e, 0x3d, 0x52,
-               0x46, 0x45, 0x3e, 0x55, 0x41, 0x4e, 0x49, 0x4a,
-               0x45, 0x16, 0x1e, 0x26, 0x25, 0x2e, 0x36, 0x3d,
-               0x3e, 0x46, 0x4c, 0x4c, 0x41, 0x55, 0x49, 0x4a,
-               0x1e, 0x1c, 0x32, 0x21, 0x23, 0x24, 0x2b, 0x34,
-               0x33, 0x43, 0x3b, 0x42, 0x4b, 0x3a, 0x31, 0x44,
-               0x4d, 0x15, 0x2d, 0x1b, 0x2c, 0x3c, 0x2a, 0x1d,
-               0x22, 0x35, 0x1a, 0x54, 0x5d, 0x5b, 0x36, 0x4e,
-               0x0e, 0x1c, 0x32, 0x21, 0x23, 0x24, 0x2b, 0x34,
-               0x33, 0x43, 0x3b, 0x42, 0x4b, 0x3a, 0x31, 0x44,
-               0x4d, 0x15, 0x2d, 0x1b, 0x2c, 0x3c, 0x2a, 0x1d,
-               0x22, 0x35, 0x1a, 0x54, 0x5d, 0x5b, 0x0e, 0x00,
-       };
-
        assert(pthread_mutex_isowned_np(&sc->mtx));
+       int e0_prefix, found;
+       uint8_t code;
+       const struct extended_translation *trans;
 
-       switch (keysym) {
-       case 0x0 ... 0x7f:
-               if (!down)
-                       fifo_put(sc, 0xf0);
-               fifo_put(sc, translation[keysym]);
-               break;
-       case 0xff08:    /* Back space */
-               if (!down)
-                       fifo_put(sc, 0xf0);
-               fifo_put(sc, 0x66);
-               break;
-       case 0xff09:    /* Tab */
-               if (!down)
-                       fifo_put(sc, 0xf0);
-               fifo_put(sc, 0x0d);
-               break;
-       case 0xff0d:    /* Return  */
-               if (!down)
-                       fifo_put(sc, 0xf0);
-               fifo_put(sc, 0x5a);
-               break;
-       case 0xff1b:    /* Escape */
-               if (!down)
-                       fifo_put(sc, 0xf0);
-               fifo_put(sc, 0x76);
-               break;
-       case 0xff50:    /* Home */
-               fifo_put(sc, 0xe0);
-               if (!down)
-                       fifo_put(sc, 0xf0);
-               fifo_put(sc, 0x6c);
-               break;
-       case 0xff51:    /* Left arrow */
-               fifo_put(sc, 0xe0);
-               if (!down)
-                       fifo_put(sc, 0xf0);
-               fifo_put(sc, 0x6b);
-               break;
-       case 0xff52:    /* Up arrow */
-               fifo_put(sc, 0xe0);
-               if (!down)
-                       fifo_put(sc, 0xf0);
-               fifo_put(sc, 0x75);
-               break;
-       case 0xff53:    /* Right arrow */
-               fifo_put(sc, 0xe0);
-               if (!down)
-                       fifo_put(sc, 0xf0);
-               fifo_put(sc, 0x74);
-               break;
-       case 0xff54:    /* Down arrow */
-               fifo_put(sc, 0xe0);
-               if (!down)
-                       fifo_put(sc, 0xf0);
-               fifo_put(sc, 0x72);
-               break;
-       case 0xff55:    /* PgUp */
-               fifo_put(sc, 0xe0);
-               if (!down)
-                       fifo_put(sc, 0xf0);     
-               fifo_put(sc, 0x7d);
-               break;
-       case 0xff56:    /* PgDwn */
-               fifo_put(sc, 0xe0);
-               if (!down)
-                       fifo_put(sc, 0xf0);     
-               fifo_put(sc, 0x7a);
-               break;
-       case 0xff57:    /* End */
-               fifo_put(sc, 0xe0);
-               if (!down)
-                       fifo_put(sc, 0xf0);     
-               fifo_put(sc, 0x69);
-               break;
-       case 0xff63:    /* Ins */
-               fifo_put(sc, 0xe0);
-               if (!down)
-                       fifo_put(sc, 0xf0);     
-               fifo_put(sc, 0x70);
-               break;
-       case 0xff8d:    /* Keypad Enter */
-               fifo_put(sc, 0xe0);
-               if (!down)
-                       fifo_put(sc, 0xf0);
-               fifo_put(sc, 0x5a);
-               break;
-       case 0xffe1:    /* Left shift */
-               if (!down)
-                       fifo_put(sc, 0xf0);
-               fifo_put(sc, 0x12);
-               break;
-       case 0xffe2:    /* Right shift */
-               if (!down)
-                       fifo_put(sc, 0xf0);
-               fifo_put(sc, 0x59);
-               break;
-       case 0xffe3:    /* Left control */
-               if (!down)
-                       fifo_put(sc, 0xf0);
-               fifo_put(sc, 0x14);
-               break;
-       case 0xffe4:    /* Right control */
-               fifo_put(sc, 0xe0);
-               if (!down)
-                       fifo_put(sc, 0xf0);
-               fifo_put(sc, 0x14);
-               break;
-       case 0xffe7:    /* Left meta */
-               /* XXX */
-               break;
-       case 0xffe8:    /* Right meta */
-               /* XXX */
-               break;
-       case 0xffe9:    /* Left alt */
-               if (!down)
-                       fifo_put(sc, 0xf0);
-               fifo_put(sc, 0x11);
-               break;
-       case 0xfe03:    /* AltGr */
-       case 0xffea:    /* Right alt */
-               fifo_put(sc, 0xe0);
-               if (!down)
-                       fifo_put(sc, 0xf0);
-               fifo_put(sc, 0x11);
-               break;
-       case 0xffeb:    /* Left Windows */
-               fifo_put(sc, 0xe0);
-               if (!down)
-                       fifo_put(sc, 0xf0);
-               fifo_put(sc, 0x1f);
-               break;
-       case 0xffec:    /* Right Windows */
-               fifo_put(sc, 0xe0);
-               if (!down)
-                       fifo_put(sc, 0xf0);
-               fifo_put(sc, 0x27);
-               break;
-       case 0xffbe:    /* F1 */
-               if (!down)
-                       fifo_put(sc, 0xf0);
-               fifo_put(sc, 0x05);
-               break;
-       case 0xffbf:    /* F2 */
-               if (!down)
-                       fifo_put(sc, 0xf0);
-               fifo_put(sc, 0x06);
-               break;
-       case 0xffc0:    /* F3 */
-               if (!down)
-                       fifo_put(sc, 0xf0);
-               fifo_put(sc, 0x04);
-               break;
-       case 0xffc1:    /* F4 */
-               if (!down)
-                       fifo_put(sc, 0xf0);
-               fifo_put(sc, 0x0C);
-               break;
-       case 0xffc2:    /* F5 */
-               if (!down)
-                       fifo_put(sc, 0xf0);
-               fifo_put(sc, 0x03);
-               break;
-       case 0xffc3:    /* F6 */
-               if (!down)
-                       fifo_put(sc, 0xf0);
-               fifo_put(sc, 0x0B);
-               break;
-       case 0xffc4:    /* F7 */
-               if (!down)
-                       fifo_put(sc, 0xf0);
-               fifo_put(sc, 0x83);
-               break;
-       case 0xffc5:    /* F8 */
-               if (!down)
-                       fifo_put(sc, 0xf0);
-               fifo_put(sc, 0x0A);
-               break;
-       case 0xffc6:    /* F9 */
-               if (!down)
-                       fifo_put(sc, 0xf0);
-               fifo_put(sc, 0x01);
-               break;
-       case 0xffc7:    /* F10 */
-               if (!down)
-                       fifo_put(sc, 0xf0);
-               fifo_put(sc, 0x09);
-               break;
-       case 0xffc8:    /* F11 */
-               if (!down)
-                       fifo_put(sc, 0xf0);
-               fifo_put(sc, 0x78);
-               break;
-       case 0xffc9:    /* F12 */
-               if (!down)
-                       fifo_put(sc, 0xf0);
-               fifo_put(sc, 0x07);
-               break;
-       case 0xffff:    /* Del */
-               fifo_put(sc, 0xe0);
-               if (!down)
-                       fifo_put(sc, 0xf0);
-               fifo_put(sc, 0x71);
-               break;
-       default:
-               fprintf(stderr, "Unhandled ps2 keyboard keysym 0x%x\n",
-                    keysym);
-               break;
+       found = 0;
+       if (keysym < 0x80) {
+               code = ascii_translations[keysym];
+               e0_prefix = 0;
+               found = 1;
+       } else {
+               for (trans = &(extended_translations[0]); trans->keysym != 0;
+                   trans++) {
+                       if (keysym == trans->keysym) {
+                               code = trans->scancode;
+                               e0_prefix = trans->flags & SCANCODE_E0_PREFIX;
+                               found = 1;
+                               break;
+                       }
+               }
        }
+
+       if (!found) {
+               fprintf(stderr, "Unhandled ps2 keyboard keysym 0x%x\n", keysym);
+               return;
+       }
+
+       if (e0_prefix)
+               fifo_put(sc, 0xe0);
+       if (!down)
+               fifo_put(sc, 0xf0);
+       fifo_put(sc, code);
 }
 
 static void
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to