Module Name:    src
Committed By:   dholland
Date:           Thu May 22 16:31:19 UTC 2014

Modified Files:
        src/sys/arch/hp300/dev: dcm.c
        src/sys/compat/common: tty_43.c
        src/sys/kern: tty.c
        src/sys/net: ppp_tty.c
        src/sys/sys: tty.h

Log Message:
Use accessor functions for the tty's table of control characters.
(at least from outside the core tty sources)

Move some xon/xoff code from net/ppp_tty.c to kern/tty.c.


To generate a diff of this commit:
cvs rdiff -u -r1.85 -r1.86 src/sys/arch/hp300/dev/dcm.c
cvs rdiff -u -r1.29 -r1.30 src/sys/compat/common/tty_43.c
cvs rdiff -u -r1.260 -r1.261 src/sys/kern/tty.c
cvs rdiff -u -r1.57 -r1.58 src/sys/net/ppp_tty.c
cvs rdiff -u -r1.91 -r1.92 src/sys/sys/tty.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/hp300/dev/dcm.c
diff -u src/sys/arch/hp300/dev/dcm.c:1.85 src/sys/arch/hp300/dev/dcm.c:1.86
--- src/sys/arch/hp300/dev/dcm.c:1.85	Mon Mar 24 19:42:58 2014
+++ src/sys/arch/hp300/dev/dcm.c	Thu May 22 16:31:19 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: dcm.c,v 1.85 2014/03/24 19:42:58 christos Exp $	*/
+/*	$NetBSD: dcm.c,v 1.86 2014/05/22 16:31:19 dholland Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
@@ -78,7 +78,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dcm.c,v 1.85 2014/03/24 19:42:58 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dcm.c,v 1.86 2014/05/22 16:31:19 dholland Exp $");
 
 #include "opt_kgdb.h"
 
@@ -1394,9 +1394,11 @@ dcmsetischeme(int brd, int flags)
 		for (i = 0; i < NDCMPORT; i++) {
 			tp = sc->sc_tty[i];
 
-			if ((c = tp->t_cc[VSTART]) != _POSIX_VDISABLE)
+			c = tty_getctrlchar(tp, VSTART);
+			if (c != _POSIX_VDISABLE)
 				dcm->dcm_bmap[c].data_data |= (1 << i);
-			if ((c = tp->t_cc[VSTOP]) != _POSIX_VDISABLE)
+			c = tty_getctrlchar(tp, VSTOP);
+			if (c != _POSIX_VDISABLE)
 				dcm->dcm_bmap[c].data_data |= (1 << i);
 		}
 	}

Index: src/sys/compat/common/tty_43.c
diff -u src/sys/compat/common/tty_43.c:1.29 src/sys/compat/common/tty_43.c:1.30
--- src/sys/compat/common/tty_43.c:1.29	Wed Nov 19 18:36:02 2008
+++ src/sys/compat/common/tty_43.c	Thu May 22 16:31:19 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: tty_43.c,v 1.29 2008/11/19 18:36:02 ad Exp $	*/
+/*	$NetBSD: tty_43.c,v 1.30 2014/05/22 16:31:19 dholland Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tty_43.c,v 1.29 2008/11/19 18:36:02 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tty_43.c,v 1.30 2014/05/22 16:31:19 dholland Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -118,11 +118,9 @@ ttcompat(struct tty *tp, u_long com, voi
 	switch (com) {
 	case TIOCGETP: {
 		struct sgttyb *sg = (struct sgttyb *)data;
-		u_char *cc;
 		int speed;
 
 		mutex_spin_enter(&tty_lock);
-		cc = tp->t_cc;
 		speed = ttspeedtab(tp->t_ospeed, compatspeeds);
 		sg->sg_ospeed = (speed == -1) ? MAX_SPEED : speed;
 		if (tp->t_ispeed == 0)
@@ -131,8 +129,8 @@ ttcompat(struct tty *tp, u_long com, voi
 			speed = ttspeedtab(tp->t_ispeed, compatspeeds);
 			sg->sg_ispeed = (speed == -1) ? MAX_SPEED : speed;
 		}
-		sg->sg_erase = cc[VERASE];
-		sg->sg_kill = cc[VKILL];
+		sg->sg_erase = tty_getctrlchar(tp, VERASE);
+		sg->sg_kill = tty_getctrlchar(tp, VKILL);
 		sg->sg_flags = ttcompatgetflags(tp);
 		mutex_spin_exit(&tty_lock);
 		break;
@@ -165,52 +163,48 @@ ttcompat(struct tty *tp, u_long com, voi
 
 	case TIOCGETC: {
 		struct tchars *tc = (struct tchars *)data;
-		u_char *cc = tp->t_cc;
 
-		tc->t_intrc = cc[VINTR];
-		tc->t_quitc = cc[VQUIT];
-		tc->t_startc = cc[VSTART];
-		tc->t_stopc = cc[VSTOP];
-		tc->t_eofc = cc[VEOF];
-		tc->t_brkc = cc[VEOL];
+		tc->t_intrc = tty_getctrlchar(tp, VINTR);
+		tc->t_quitc = tty_getctrlchar(tp, VQUIT);
+		tc->t_startc = tty_getctrlchar(tp, VSTART);
+		tc->t_stopc = tty_getctrlchar(tp, VSTOP);
+		tc->t_eofc = tty_getctrlchar(tp, VEOF);
+		tc->t_brkc = tty_getctrlchar(tp, VEOL);
 		break;
 	}
 	case TIOCSETC: {
 		struct tchars *tc = (struct tchars *)data;
-		u_char *cc = tp->t_cc;
 
-		cc[VINTR] = tc->t_intrc;
-		cc[VQUIT] = tc->t_quitc;
-		cc[VSTART] = tc->t_startc;
-		cc[VSTOP] = tc->t_stopc;
-		cc[VEOF] = tc->t_eofc;
-		cc[VEOL] = tc->t_brkc;
+		tty_setctrlchar(tp, VINTR, tc->t_intrc);
+		tty_setctrlchar(tp, VQUIT, tc->t_quitc);
+		tty_setctrlchar(tp, VSTART, tc->t_startc);
+		tty_setctrlchar(tp, VSTOP, tc->t_stopc);
+		tty_setctrlchar(tp, VEOF, tc->t_eofc);
+		tty_setctrlchar(tp, VEOL, tc->t_brkc);
 		if (tc->t_brkc == (char)-1)
-			cc[VEOL2] = _POSIX_VDISABLE;
+			tty_setctrlchar(tp, VEOL2, _POSIX_VDISABLE);
 		break;
 	}
 	case TIOCSLTC: {
 		struct ltchars *ltc = (struct ltchars *)data;
-		u_char *cc = tp->t_cc;
 
-		cc[VSUSP] = ltc->t_suspc;
-		cc[VDSUSP] = ltc->t_dsuspc;
-		cc[VREPRINT] = ltc->t_rprntc;
-		cc[VDISCARD] = ltc->t_flushc;
-		cc[VWERASE] = ltc->t_werasc;
-		cc[VLNEXT] = ltc->t_lnextc;
+		tty_setctrlchar(tp, VSUSP, ltc->t_suspc);
+		tty_setctrlchar(tp, VDSUSP, ltc->t_dsuspc);
+		tty_setctrlchar(tp, VREPRINT, ltc->t_rprntc);
+		tty_setctrlchar(tp, VDISCARD, ltc->t_flushc);
+		tty_setctrlchar(tp, VWERASE, ltc->t_werasc);
+		tty_setctrlchar(tp, VLNEXT, ltc->t_lnextc);
 		break;
 	}
 	case TIOCGLTC: {
 		struct ltchars *ltc = (struct ltchars *)data;
-		u_char *cc = tp->t_cc;
 
-		ltc->t_suspc = cc[VSUSP];
-		ltc->t_dsuspc = cc[VDSUSP];
-		ltc->t_rprntc = cc[VREPRINT];
-		ltc->t_flushc = cc[VDISCARD];
-		ltc->t_werasc = cc[VWERASE];
-		ltc->t_lnextc = cc[VLNEXT];
+		ltc->t_suspc = tty_getctrlchar(tp, VSUSP);
+		ltc->t_dsuspc = tty_getctrlchar(tp, VDSUSP);
+		ltc->t_rprntc = tty_getctrlchar(tp, VREPRINT);
+		ltc->t_flushc = tty_getctrlchar(tp, VDISCARD);
+		ltc->t_werasc = tty_getctrlchar(tp, VWERASE);
+		ltc->t_lnextc = tty_getctrlchar(tp, VLNEXT);
 		break;
 	}
 	case TIOCLBIS:

Index: src/sys/kern/tty.c
diff -u src/sys/kern/tty.c:1.260 src/sys/kern/tty.c:1.261
--- src/sys/kern/tty.c:1.260	Thu May 22 16:28:06 2014
+++ src/sys/kern/tty.c	Thu May 22 16:31:19 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: tty.c,v 1.260 2014/05/22 16:28:06 dholland Exp $	*/
+/*	$NetBSD: tty.c,v 1.261 2014/05/22 16:31:19 dholland Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -63,7 +63,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tty.c,v 1.260 2014/05/22 16:28:06 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tty.c,v 1.261 2014/05/22 16:31:19 dholland Exp $");
 
 #include "opt_compat_netbsd.h"
 
@@ -2967,3 +2967,45 @@ ttysigintr(void *cookie)
 	mutex_spin_exit(&tty_lock);
 	mutex_exit(proc_lock);
 }
+
+unsigned char
+tty_getctrlchar(struct tty *tp, unsigned which)
+{
+	KASSERT(which < NCCS);
+	return tp->t_cc[which];
+}
+
+void
+tty_setctrlchar(struct tty *tp, unsigned which, unsigned char val)
+{
+	KASSERT(which < NCCS);
+	tp->t_cc[which] = val;
+}
+
+int
+tty_try_xonxoff(struct tty *tp, unsigned char c)
+{
+    const struct cdevsw *cdev;
+
+    if (tp->t_iflag & IXON) {
+	if (c == tp->t_cc[VSTOP] && tp->t_cc[VSTOP] != _POSIX_VDISABLE) {
+	    if ((tp->t_state & TS_TTSTOP) == 0) {
+		tp->t_state |= TS_TTSTOP;
+		cdev = cdevsw_lookup(tp->t_dev);
+		if (cdev != NULL)
+			(*cdev->d_stop)(tp, 0);
+	    }
+	    return 0;
+	}
+	if (c == tp->t_cc[VSTART] && tp->t_cc[VSTART] != _POSIX_VDISABLE) {
+	    tp->t_state &= ~TS_TTSTOP;
+	    if (tp->t_oproc != NULL) {
+	        mutex_spin_enter(&tty_lock);	/* XXX */
+		(*tp->t_oproc)(tp);
+	        mutex_spin_exit(&tty_lock);	/* XXX */
+	    }
+	    return 0;
+	}
+    }
+    return EAGAIN;
+}

Index: src/sys/net/ppp_tty.c
diff -u src/sys/net/ppp_tty.c:1.57 src/sys/net/ppp_tty.c:1.58
--- src/sys/net/ppp_tty.c:1.57	Mon Apr  5 07:22:24 2010
+++ src/sys/net/ppp_tty.c	Thu May 22 16:31:19 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: ppp_tty.c,v 1.57 2010/04/05 07:22:24 joerg Exp $	*/
+/*	$NetBSD: ppp_tty.c,v 1.58 2014/05/22 16:31:19 dholland Exp $	*/
 /*	Id: ppp_tty.c,v 1.3 1996/07/01 01:04:11 paulus Exp 	*/
 
 /*
@@ -93,7 +93,7 @@
 /* from NetBSD: if_ppp.c,v 1.15.2.2 1994/07/28 05:17:58 cgd Exp */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ppp_tty.c,v 1.57 2010/04/05 07:22:24 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ppp_tty.c,v 1.58 2014/05/22 16:31:19 dholland Exp $");
 
 #include "ppp.h"
 
@@ -978,8 +978,8 @@ pppinput(int c, struct tty *tp)
 {
     struct ppp_softc *sc;
     struct mbuf *m;
-    const struct cdevsw *cdev;
     int ilen, s;
+    int result;
 
     sc = (struct ppp_softc *) tp->t_sc;
     if (sc == NULL || tp != (struct tty *) sc->sc_devp)
@@ -1000,26 +1000,12 @@ pppinput(int c, struct tty *tp)
     /*
      * Handle software flow control of output.
      */
-    if (tp->t_iflag & IXON) {
-	if (c == tp->t_cc[VSTOP] && tp->t_cc[VSTOP] != _POSIX_VDISABLE) {
-	    if ((tp->t_state & TS_TTSTOP) == 0) {
-		tp->t_state |= TS_TTSTOP;
-		cdev = cdevsw_lookup(tp->t_dev);
-		if (cdev != NULL)
-			(*cdev->d_stop)(tp, 0);
-	    }
-	    return 0;
-	}
-	if (c == tp->t_cc[VSTART] && tp->t_cc[VSTART] != _POSIX_VDISABLE) {
-	    tp->t_state &= ~TS_TTSTOP;
-	    if (tp->t_oproc != NULL) {
-	        mutex_spin_enter(&tty_lock);	/* XXX */
-		(*tp->t_oproc)(tp);
-	        mutex_spin_exit(&tty_lock);	/* XXX */
-	    }
+    result = tty_try_xonxoff(tp, c);
+    if (result == 0) {
+	    /* Character was recognized and consumed. */
 	    return 0;
-	}
     }
+    /* Character wasn't consumed, continue processing it. */
 
     s = spltty();
     if (c & 0x80)

Index: src/sys/sys/tty.h
diff -u src/sys/sys/tty.h:1.91 src/sys/sys/tty.h:1.92
--- src/sys/sys/tty.h:1.91	Sun Feb 24 06:20:24 2013
+++ src/sys/sys/tty.h	Thu May 22 16:31:19 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: tty.h,v 1.91 2013/02/24 06:20:24 matt Exp $	*/
+/*	$NetBSD: tty.h,v 1.92 2014/05/22 16:31:19 dholland Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -151,7 +151,9 @@ struct tty {
 	void	*t_softc;		/* pointer to driver's softc. */
 };
 
+#ifdef TTY_ALLOW_PRIVATE
 #define	t_cc		t_termios.c_cc
+#endif
 #define	t_cflag		t_termios.c_cflag
 #define	t_iflag		t_termios.c_iflag
 #define	t_ispeed	t_termios.c_ispeed
@@ -303,6 +305,10 @@ void	clfree(struct clist *);
 
 extern int (*ttcompatvec)(struct tty *, u_long, void *, int, struct lwp *);
 
+unsigned char tty_getctrlchar(struct tty *, unsigned /*which*/);
+void tty_setctrlchar(struct tty *, unsigned /*which*/, unsigned char /*val*/);
+int tty_try_xonxoff(struct tty *, unsigned char /*c*/);
+
 #endif /* _KERNEL */
 
 #endif /* !_SYS_TTY_H_ */

Reply via email to