Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 14 Mar 2018 02:45:42 +0000 (UTC)
From:      Eitan Adler <eadler@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r330892 - stable/11/sys/dev/syscons
Message-ID:  <201803140245.w2E2jgpG019644@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: eadler
Date: Wed Mar 14 02:45:42 2018
New Revision: 330892
URL: https://svnweb.freebsd.org/changeset/base/330892

Log:
  MFC r304173,r304181,r304186:
  
  Fix restoring the kbd_mode part of the keyboard state in grab/ungrab.
  Simply change the mode to K_XLATE using a local variable and use the
  grab level as a flag to tell screen switches not to change it again,
  so that we don't need to switch scp->kbd_mode.  We did the latter,
  but didn't have the complications to update the keyboard mode switch
  for every screen switch.  sc->kbd_mode remains at its user setting
  for all scp's and ungrabbing restores to it.
  
  Restructure the grabbing functions into mere wrappers of new open and
  close functions.  Scattered calls to sc_cnputc() and sc_cngetc() were
  broken by turning the semi-reentrant inline context-switching code in
  these functions into the grabbing functions.  cncheckc() calls for
  panic dumps are the main broken case.  The grabbing functions have
  special behaviour (mainly screen switching in sc_cngrab()) which makes
  them unsuitable as replacements for the inline code.
  
  Clean up the new sc cn open and close functions (old sc cn grab and ungrab
  functions).  Mainly, spell sc as itself instead of as scp->sc.

Modified:
  stable/11/sys/dev/syscons/syscons.c
  stable/11/sys/dev/syscons/syscons.h
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/dev/syscons/syscons.c
==============================================================================
--- stable/11/sys/dev/syscons/syscons.c	Wed Mar 14 02:35:49 2018	(r330891)
+++ stable/11/sys/dev/syscons/syscons.c	Wed Mar 14 02:45:42 2018	(r330892)
@@ -1645,59 +1645,70 @@ sc_cnterm(struct consdev *cp)
     sc_console = NULL;
 }
 
+struct sc_cnstate;		/* not used yet */
+static void sccnclose(sc_softc_t *sc, struct sc_cnstate *sp);
+static void sccnopen(sc_softc_t *sc, struct sc_cnstate *sp, int flags);
+
 static void
-sc_cngrab(struct consdev *cp)
+sccnopen(sc_softc_t *sc, struct sc_cnstate *sp, int flags)
 {
-    scr_stat *scp;
+    int kbd_mode;
 
     if (!cold &&
-	sc_console->sc->cur_scp->index != sc_console->index &&
-	sc_console->sc->cur_scp->smode.mode == VT_AUTO &&
+	sc->cur_scp->index != sc_console->index &&
+	sc->cur_scp->smode.mode == VT_AUTO &&
 	sc_console->smode.mode == VT_AUTO)
-	    sc_switch_scr(sc_console->sc, sc_console->index);
+	    sc_switch_scr(sc, sc_console->index);
 
-    scp = sc_console->sc->cur_scp;
-
-    if (scp->sc->kbd == NULL)
+    if (sc->kbd == NULL)
 	return;
 
-    if (scp->sc->grab_level++ > 0)
-	return;
-
     /*
      * Make sure the keyboard is accessible even when the kbd device
      * driver is disabled.
      */
-    kbdd_enable(scp->sc->kbd);
+    kbdd_enable(sc->kbd);
 
-    /* we shall always use the keyboard in the XLATE mode here */
-    scp->kbd_prev_mode = scp->kbd_mode;
-    scp->kbd_mode = K_XLATE;
-    (void)kbdd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
-
-    kbdd_poll(scp->sc->kbd, TRUE);
+    /* Switch the keyboard to console mode (K_XLATE, polled) on all scp's. */
+    kbd_mode = K_XLATE;
+    (void)kbdd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&kbd_mode);
+    kbdd_poll(sc->kbd, TRUE);
 }
 
 static void
-sc_cnungrab(struct consdev *cp)
+sccnclose(sc_softc_t *sc, struct sc_cnstate *sp)
 {
-    scr_stat *scp;
-
-    scp = sc_console->sc->cur_scp;	/* XXX */
-    if (scp->sc->kbd == NULL)
+    if (sc->kbd == NULL)
 	return;
 
-    if (--scp->sc->grab_level > 0)
-	return;
+    /* Restore keyboard mode (for the current, possibly-changed scp). */
+    kbdd_poll(sc->kbd, FALSE);
+    (void)kbdd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&sc->cur_scp->kbd_mode);
 
-    kbdd_poll(scp->sc->kbd, FALSE);
+    kbdd_disable(sc->kbd);
+}
 
-    scp->kbd_mode = scp->kbd_prev_mode;
-    (void)kbdd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
-    kbdd_disable(scp->sc->kbd);
+static void
+sc_cngrab(struct consdev *cp)
+{
+    sc_softc_t *sc;
+
+    sc = sc_console->sc;
+    if (sc->grab_level++ == 0)
+	sccnopen(sc, NULL, 0);
 }
 
 static void
+sc_cnungrab(struct consdev *cp)
+{
+    sc_softc_t *sc;
+
+    sc = sc_console->sc;
+    if (--sc->grab_level == 0)
+	sccnclose(sc, NULL);
+}
+
+static void
 sc_cnputc(struct consdev *cd, int c)
 {
     u_char buf[1];
@@ -2667,7 +2678,7 @@ exchange_scr(sc_softc_t *sc)
     sc_set_border(scp, scp->border);
 
     /* set up the keyboard for the new screen */
-    if (sc->old_scp->kbd_mode != scp->kbd_mode)
+    if (sc->grab_level == 0 && sc->old_scp->kbd_mode != scp->kbd_mode)
 	(void)kbdd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
     update_kbd_state(scp, scp->status, LOCK_MASK);
 
@@ -3412,7 +3423,7 @@ next_code:
     if (!(flags & SCGETC_CN))
 	random_harvest_queue(&c, sizeof(c), 1, RANDOM_KEYBOARD);
 
-    if (scp->kbd_mode != K_XLATE)
+    if (sc->grab_level == 0 && scp->kbd_mode != K_XLATE)
 	return KEYCHAR(c);
 
     /* if scroll-lock pressed allow history browsing */

Modified: stable/11/sys/dev/syscons/syscons.h
==============================================================================
--- stable/11/sys/dev/syscons/syscons.h	Wed Mar 14 02:35:49 2018	(r330891)
+++ stable/11/sys/dev/syscons/syscons.h	Wed Mar 14 02:45:42 2018	(r330892)
@@ -306,7 +306,6 @@ typedef struct scr_stat {
 
 	int	 	status;			/* status (bitfield) */
 	int		kbd_mode;		/* keyboard I/O mode */
-	int		kbd_prev_mode;		/* keyboard I/O mode */
 
 	int		cursor_pos;		/* cursor buffer position */
 	int		cursor_oldpos;		/* cursor old buffer position */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201803140245.w2E2jgpG019644>