svn commit: r192143 - head/sys/dev/syscons

Ed Schouten ed at FreeBSD.org
Fri May 15 14:30:38 UTC 2009


Author: ed
Date: Fri May 15 14:30:37 2009
New Revision: 192143
URL: http://svn.freebsd.org/changeset/base/192143

Log:
  Turn consolectl into a simple device node, not a TTY.
  
  Apart from the 16 virtual terminals, Syscons allocates two device nodes
  that should not really be TTYs, even though they are. One of them is
  consolectl. In RELENG_7 and before, these device nodes are used in
  single user mode. After I simplified input path, we only use this device
  node to call ioctl() on (moused, Xorg, vidcontrol).
  
  When you call ioctl() on consolectl, it will behave the same as being
  called on the first window.

Modified:
  head/sys/dev/syscons/syscons.c

Modified: head/sys/dev/syscons/syscons.c
==============================================================================
--- head/sys/dev/syscons/syscons.c	Fri May 15 13:58:45 2009	(r192142)
+++ head/sys/dev/syscons/syscons.c	Fri May 15 14:30:37 2009	(r192143)
@@ -207,7 +207,7 @@ static int save_kbd_state(scr_stat *scp)
 static int update_kbd_state(scr_stat *scp, int state, int mask);
 static int update_kbd_leds(scr_stat *scp, int which);
 static timeout_t blink_screen;
-static struct tty *sc_alloc_tty(int, const char *, ...) __printflike(2, 3);
+static struct tty *sc_alloc_tty(int, int);
 
 static cn_probe_t	sc_cnprobe;
 static cn_init_t	sc_cninit;
@@ -224,11 +224,6 @@ static	tsw_ioctl_t	sctty_ioctl;
 static	tsw_mmap_t	sctty_mmap;
 
 static struct ttydevsw sc_ttydevsw = {
-	/*
-	 * XXX: we should use the prefix, but this doesn't work for
-	 * consolectl.
-	 */
-	.tsw_flags	= TF_NOPREFIX,
 	.tsw_open	= sctty_open,
 	.tsw_close	= sctty_close,
 	.tsw_outwakeup	= sctty_outwakeup,
@@ -236,6 +231,15 @@ static struct ttydevsw sc_ttydevsw = {
 	.tsw_mmap	= sctty_mmap,
 };
 
+static d_ioctl_t	consolectl_ioctl;
+
+static struct cdevsw consolectl_devsw = {
+	.d_version	= D_VERSION,
+	.d_flags	= D_NEEDGIANT,
+	.d_ioctl	= consolectl_ioctl,
+	.d_name		= "consolectl",
+};
+
 int
 sc_probe_unit(int unit, int flags)
 {
@@ -321,14 +325,10 @@ sctty_outwakeup(struct tty *tp)
 }
 
 static struct tty *
-sc_alloc_tty(int index, const char *fmt, ...)
+sc_alloc_tty(int index, int devnum)
 {
-	va_list ap;
 	struct sc_ttysoftc *stc;
 	struct tty *tp;
-	char name[11]; /* "consolectl" */
-
-	va_start(ap, fmt);
 
 	/* Allocate TTY object and softc to store unit number. */
 	stc = malloc(sizeof(struct sc_ttysoftc), M_DEVBUF, M_WAITOK);
@@ -337,10 +337,7 @@ sc_alloc_tty(int index, const char *fmt,
 	tp = tty_alloc(&sc_ttydevsw, stc, &Giant);
 
 	/* Create device node. */
-	va_start(ap, fmt);
-	vsnrprintf(name, sizeof name, 32, fmt, ap);
-	va_end(ap);
-	tty_makedev(tp, NULL, "%s", name);
+	tty_makedev(tp, NULL, "v%r", devnum);
 
 	return (tp);
 }
@@ -354,7 +351,7 @@ sc_attach_unit(int unit, int flags)
     video_info_t info;
 #endif
     int vc;
-    struct tty *tp;
+    struct cdev *dev;
 
     flags &= ~SC_KERNEL_CONSOLE;
 
@@ -425,7 +422,7 @@ sc_attach_unit(int unit, int flags)
 
     for (vc = 0; vc < sc->vtys; vc++) {
 	if (sc->dev[vc] == NULL) {
-		sc->dev[vc] = sc_alloc_tty(vc, "ttyv%r", vc + unit * MAXCONS);
+		sc->dev[vc] = sc_alloc_tty(vc, vc + unit * MAXCONS);
 		if (vc == 0 && sc->dev == main_devs)
 			SC_STAT(sc->dev[0]) = &main_console;
 	}
@@ -436,8 +433,9 @@ sc_attach_unit(int unit, int flags)
 	 */
     }
 
-    tp = sc_alloc_tty(0, "consolectl");
-    SC_STAT(tp) = sc_console;
+    dev = make_dev(&consolectl_devsw, 0, UID_ROOT, GID_WHEEL, 0600,
+        "consolectl");
+    dev->si_drv1 = sc->dev[0];
 
     return 0;
 }
@@ -1428,6 +1426,14 @@ sctty_ioctl(struct tty *tp, u_long cmd, 
     return (ENOIOCTL);
 }
 
+static int
+consolectl_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag,
+    struct thread *td)
+{
+
+	return sctty_ioctl(dev->si_drv1, cmd, data, td);
+}
+
 static void
 sc_cnprobe(struct consdev *cp)
 {
@@ -2728,7 +2734,7 @@ scinit(int unit, int flags)
 	    /* assert(sc_malloc) */
 	    sc->dev = malloc(sizeof(struct tty *)*sc->vtys, M_DEVBUF,
 	        M_WAITOK|M_ZERO);
-	    sc->dev[0] = sc_alloc_tty(0, "ttyv%r", unit * MAXCONS);
+	    sc->dev[0] = sc_alloc_tty(0, unit * MAXCONS);
 	    scp = alloc_scp(sc, sc->first_vty);
 	    SC_STAT(sc->dev[0]) = scp;
 	}


More information about the svn-src-all mailing list