Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Use accessor functions for the tty's table of control ch...
details: https://anonhg.NetBSD.org/src/rev/63281794bd5c
branches: trunk
changeset: 796152:63281794bd5c
user: dholland <dholland%NetBSD.org@localhost>
date: Thu May 22 16:31:19 2014 +0000
description:
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.
diffstat:
sys/arch/hp300/dev/dcm.c | 10 ++++--
sys/compat/common/tty_43.c | 64 ++++++++++++++++++++-------------------------
sys/kern/tty.c | 46 +++++++++++++++++++++++++++++++-
sys/net/ppp_tty.c | 28 +++++---------------
sys/sys/tty.h | 8 +++++-
5 files changed, 93 insertions(+), 63 deletions(-)
diffs (truncated from 304 to 300 lines):
diff -r 2bb1f1a5204d -r 63281794bd5c sys/arch/hp300/dev/dcm.c
--- a/sys/arch/hp300/dev/dcm.c Thu May 22 16:30:40 2014 +0000
+++ b/sys/arch/hp300/dev/dcm.c Thu May 22 16:31:19 2014 +0000
@@ -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 @@
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);
}
}
diff -r 2bb1f1a5204d -r 63281794bd5c sys/compat/common/tty_43.c
--- a/sys/compat/common/tty_43.c Thu May 22 16:30:40 2014 +0000
+++ b/sys/compat/common/tty_43.c Thu May 22 16:31:19 2014 +0000
@@ -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 @@
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 @@
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 @@
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:
diff -r 2bb1f1a5204d -r 63281794bd5c sys/kern/tty.c
--- a/sys/kern/tty.c Thu May 22 16:30:40 2014 +0000
+++ b/sys/kern/tty.c Thu May 22 16:31:19 2014 +0000
@@ -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 @@
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;
+}
diff -r 2bb1f1a5204d -r 63281794bd5c sys/net/ppp_tty.c
--- a/sys/net/ppp_tty.c Thu May 22 16:30:40 2014 +0000
+++ b/sys/net/ppp_tty.c Thu May 22 16:31:19 2014 +0000
@@ -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 @@
{
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 @@
/*
* 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);
- }
+ result = tty_try_xonxoff(tp, c);
+ if (result == 0) {
+ /* Character was recognized and consumed. */
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;
- }
}
+ /* Character wasn't consumed, continue processing it. */
s = spltty();
if (c & 0x80)
diff -r 2bb1f1a5204d -r 63281794bd5c sys/sys/tty.h
--- a/sys/sys/tty.h Thu May 22 16:30:40 2014 +0000
+++ b/sys/sys/tty.h Thu May 22 16:31:19 2014 +0000
@@ -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 @@
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 @@
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*/);
Home |
Main Index |
Thread Index |
Old Index