Add new function ttyinitmode() which sets our systemwide default

modes on a tty structure.

Both the ".init" and the current settings are initialized allowing
the function to be used both at attach and open time.

The function takes an argument to decide if echoing should be enabled.
Echoing should not be enabled for regular physical serial ports
unless they are consoles, in which case they should be configured
by ttyconsolemode() instead.

Use the new function throughout.
This commit is contained in:
Poul-Henning Kamp 2004-10-18 21:51:27 +00:00
parent 2b0448ba0c
commit 95bc568977
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=136680
14 changed files with 62 additions and 118 deletions

View File

@ -107,12 +107,7 @@ promopen(dev, flag, mode, td)
tp->t_dev = dev;
if ((tp->t_state & TS_ISOPEN) == 0) {
tp->t_state |= TS_CARR_ON;
ttychars(tp);
tp->t_iflag = TTYDEF_IFLAG;
tp->t_oflag = TTYDEF_OFLAG;
tp->t_cflag = TTYDEF_CFLAG|CLOCAL;
tp->t_lflag = TTYDEF_LFLAG;
tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
ttyconsmode(tp, 0);
ttsetwater(tp);
setuptimeout = 1;

View File

@ -283,12 +283,7 @@ zsopen(struct cdev *dev, int flag, int mode, struct thread *td)
tp = dev->si_tty;
if ((tp->t_state & TS_ISOPEN) == 0) {
tp->t_state |= TS_CARR_ON;
ttychars(tp);
tp->t_iflag = TTYDEF_IFLAG;
tp->t_oflag = TTYDEF_OFLAG;
tp->t_cflag = TTYDEF_CFLAG|CLOCAL;
tp->t_lflag = TTYDEF_LFLAG;
tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
ttyconsolemode(tp, 0);
ttsetwater(tp);
setuptimeout = 1;
} else if ((tp->t_state & TS_XCLUDE) && suser(td)) {

View File

@ -294,12 +294,7 @@ dcons_open(DEV dev, int flag, int mode, THREAD *td)
s = spltty();
if ((tp->t_state & TS_ISOPEN) == 0) {
tp->t_state |= TS_CARR_ON;
ttychars(tp);
tp->t_iflag = TTYDEF_IFLAG;
tp->t_oflag = TTYDEF_OFLAG;
tp->t_cflag = TTYDEF_CFLAG|CLOCAL;
tp->t_lflag = TTYDEF_LFLAG;
tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
ttyconsolemode(tp, 0);
ttsetwater(tp);
} else if ((tp->t_state & TS_XCLUDE) && suser(td)) {
splx(s);

View File

@ -85,9 +85,6 @@ static void digi_free_state(struct digi_softc *);
fepcmd(port, cmd, (op2 << 8) | op1, ncmds)
#define fepcmd_w fepcmd
static speed_t digidefaultrate = TTYDEF_SPEED;
struct con_bios {
struct con_bios *next;
u_char *bios;
@ -589,19 +586,7 @@ digi_init(struct digi_softc *sc)
bc->edelay = 100;
/*
* We don't use all the flags from <sys/ttydefaults.h> since
* they are only relevant for logins. It's important to have
* echo off initially so that the line doesn't start blathering
* before the echo flag can be turned off.
*/
tp->t_init_in.c_iflag = 0;
tp->t_init_in.c_oflag = 0;
tp->t_init_in.c_cflag = TTYDEF_CFLAG;
tp->t_init_in.c_lflag = 0;
termioschars(&tp->t_init_in);
tp->t_init_in.c_ispeed = tp->t_init_in.c_ospeed = digidefaultrate;
tp->t_init_out = tp->t_init_in;
ttyinitmode(tp, 0, 0);
port->send_ring = 1; /* Default action on signal RI */
ttycreate(tp, NULL, 0, MINOR_CALLOUT, "D%r%r", sc->res.unit, i);
}

View File

@ -247,13 +247,7 @@ nmdmopen(struct cdev *dev, int flag, int devtype, struct thread *td)
tp2 = sp->other->nm_tty;
if ((tp->t_state & TS_ISOPEN) == 0) {
ttychars(tp); /* Set up default chars */
tp->t_iflag = TTYDEF_IFLAG;
tp->t_oflag = TTYDEF_OFLAG;
tp->t_lflag = TTYDEF_LFLAG;
tp->t_lflag = 0;
tp->t_cflag = TTYDEF_CFLAG;
tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
ttyinitmode(tp, 0, 0);
ttsetwater(tp); /* XXX ? */
} else if (tp->t_state & TS_XCLUDE && suser(td)) {
return (EBUSY);

View File

@ -138,12 +138,7 @@ ofw_dev_open(struct cdev *dev, int flag, int mode, struct thread *td)
if ((tp->t_state & TS_ISOPEN) == 0) {
tp->t_state |= TS_CARR_ON;
ttychars(tp);
tp->t_iflag = TTYDEF_IFLAG;
tp->t_oflag = TTYDEF_OFLAG;
tp->t_cflag = TTYDEF_CFLAG | CLOCAL;
tp->t_lflag = TTYDEF_LFLAG;
tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
ttyconsolemode(tp, 0);
ttsetwater(tp);
setuptimeout = 1;

View File

@ -145,6 +145,7 @@ SYSCTL_INT(_machdep, OID_AUTO, enable_panic_key, CTLFLAG_RW, &enable_panic_key,
static int debugger;
/* prototypes */
static struct tty *sc_alloc_tty(struct cdev *dev);
static int scvidprobe(int unit, int flags, int cons);
static int sckbdprobe(int unit, int flags, int cons);
static void scmeminit(void *arg);
@ -288,10 +289,23 @@ static char
return names[i].name[(adp->va_flags & V_ADP_COLOR) ? 0 : 1];
}
static struct tty *
sc_alloc_tty(struct cdev *dev)
{
struct tty *tp;
tp = dev->si_tty = ttyalloc();
ttyinitmode(tp, 1, 0);
tp->t_oproc = scstart;
tp->t_param = scparam;
tp->t_stop = nottystop;
tp->t_dev = dev;
return (tp);
}
int
sc_attach_unit(int unit, int flags)
{
struct tty *tp;
sc_softc_t *sc;
scr_stat *scp;
#ifdef SC_PIXEL_MODE
@ -383,14 +397,9 @@ sc_attach_unit(int unit, int flags)
for (vc = 0; vc < sc->vtys; vc++) {
if (sc->dev[vc] == NULL) {
dev = make_dev(&sc_cdevsw, vc + unit * MAXCONS,
sc->dev[vc] = make_dev(&sc_cdevsw, vc + unit * MAXCONS,
UID_ROOT, GID_WHEEL, 0600, "ttyv%r", vc + unit * MAXCONS);
sc->dev[vc] = dev;
tp = sc->dev[vc]->si_tty = ttyalloc();
tp->t_oproc = scstart;
tp->t_param = scparam;
tp->t_stop = nottystop;
tp->t_dev = sc->dev[vc];
sc_alloc_tty(sc->dev[vc]);
if (vc == 0 && sc->dev == main_devs)
SC_STAT(sc->dev[0]) = &main_console;
}
@ -403,12 +412,8 @@ sc_attach_unit(int unit, int flags)
dev = make_dev(&sc_cdevsw, SC_CONSOLECTL,
UID_ROOT, GID_WHEEL, 0600, "consolectl");
tp = dev->si_tty = sc_console_tty = ttyalloc();
ttyconsolemode(tp, 0);
tp->t_oproc = scstart;
tp->t_param = scparam;
tp->t_stop = nottystop;
tp->t_dev = dev;
sc_console_tty = sc_alloc_tty(dev);
ttyconsolemode(sc_console_tty, 0);
SC_STAT(dev) = sc_console;
return 0;
@ -2581,7 +2586,6 @@ sc_change_cursor_shape(scr_stat *scp, int flags, int base, int height)
static void
scinit(int unit, int flags)
{
struct tty *tp;
/*
* When syscons is being initialized as the kernel console, malloc()
@ -2692,11 +2696,7 @@ scinit(int unit, int flags)
sc->dev = malloc(sizeof(struct cdev *)*sc->vtys, M_DEVBUF, M_WAITOK|M_ZERO);
sc->dev[0] = make_dev(&sc_cdevsw, unit * MAXCONS,
UID_ROOT, GID_WHEEL, 0600, "ttyv%r", unit * MAXCONS);
tp = sc->dev[0]->si_tty = ttyalloc();
tp->t_oproc = scstart;
tp->t_param = scparam;
tp->t_stop = nottystop;
tp->t_dev = sc->dev[0];
sc_alloc_tty(sc->dev[0]);
scp = alloc_scp(sc, sc->first_vty);
SC_STAT(sc->dev[0]) = scp;
}

View File

@ -80,12 +80,7 @@ smopen(struct cdev *dev, int flag, int mode, struct thread *td)
tp = dev->si_tty;
if (!(tp->t_state & TS_ISOPEN)) {
ttychars(tp);
tp->t_iflag = TTYDEF_IFLAG;
tp->t_oflag = TTYDEF_OFLAG;
tp->t_cflag = TTYDEF_CFLAG;
tp->t_lflag = TTYDEF_LFLAG;
tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
ttyinitmode(tp, 0, 0);
smparam(tp, &tp->t_termios);
ttyld_modem(tp, 1);
} else if (tp->t_state & TS_XCLUDE && suser(td)) {

View File

@ -276,12 +276,8 @@ zstty_attach(device_t dev)
tp->t_modem = zsttymodem;
tp->t_break = zsttybreak;
tp->t_stop = zsttystop;
tp->t_iflag = TTYDEF_IFLAG;
tp->t_oflag = TTYDEF_OFLAG;
tp->t_lflag = TTYDEF_LFLAG;
ttyinitmode(tp, 0, 0);
tp->t_cflag = CREAD | CLOCAL | CS8;
tp->t_ospeed = TTYDEF_SPEED;
tp->t_ispeed = TTYDEF_SPEED;
if (zstty_console(dev, mode, sizeof(mode))) {
ttychars(tp);
@ -472,19 +468,10 @@ zsttyopen(struct cdev *dev, int flags, int mode, struct thread *td)
sc->sc_preg[1] |= ZSWR1_RIE | ZSWR1_SIE;
sc->sc_iput = sc->sc_iget = sc->sc_ibuf;
/*
* Initialize the termios status to the defaults. Add in the
* sticky bits from TIOCSFLAGS.
*/
t.c_ispeed = 0;
t.c_ospeed = tp->t_ospeed;
t.c_cflag = TTYDEF_CFLAG;
ttyconsolemode(t, 0);
/* Make sure zstty_param() will do something. */
tp->t_ospeed = 0;
(void)zstty_param(sc, tp, &t);
tp->t_iflag = TTYDEF_IFLAG;
tp->t_oflag = TTYDEF_OFLAG;
tp->t_lflag = TTYDEF_LFLAG;
ttychars(tp);
ttsetwater(tp);

View File

@ -297,12 +297,7 @@ pcvt_open(struct cdev *dev, int flag, int mode, struct thread *td)
if ((tp->t_state & TS_ISOPEN) == 0)
{
ttychars(tp);
tp->t_iflag = TTYDEF_IFLAG;
tp->t_oflag = TTYDEF_OFLAG;
tp->t_cflag = TTYDEF_CFLAG;
tp->t_lflag = TTYDEF_LFLAG;
tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
ttyinitmode(tp, 1, 0);
pcvt_param(tp, &tp->t_termios);
ttyld_modem(tp, 1); /* fake connection */
winsz = 1; /* set winsize later */

View File

@ -148,12 +148,7 @@ sscopen(struct cdev *dev, int flag, int mode, struct thread *td)
tp->t_dev = dev;
if ((tp->t_state & TS_ISOPEN) == 0) {
tp->t_state |= TS_CARR_ON;
ttychars(tp);
tp->t_iflag = TTYDEF_IFLAG;
tp->t_oflag = TTYDEF_OFLAG;
tp->t_cflag = TTYDEF_CFLAG|CLOCAL;
tp->t_lflag = TTYDEF_LFLAG;
tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
ttyconsolemode(tp, 0);
ttsetwater(tp);
setuptimeout = 1;

View File

@ -2845,11 +2845,7 @@ ttymalloc(struct tty *tp)
tp->t_timeout = -1;
tp->t_dtr_wait = 3 * hz;
tp->t_init_in.c_iflag = TTYDEF_IFLAG;
tp->t_init_in.c_oflag = TTYDEF_OFLAG;
tp->t_init_in.c_cflag = TTYDEF_CFLAG;
tp->t_init_in.c_lflag = TTYDEF_LFLAG;
tp->t_init_in.c_ispeed = tp->t_init_in.c_ospeed = TTYDEF_SPEED;
ttyinitmode(tp, 0, 0);
bcopy(ttydefchars, tp->t_init_in.c_cc, sizeof tp->t_init_in.c_cc);
/* Make callout the same as callin */
@ -3364,6 +3360,29 @@ ttysioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *t
}
}
/*
* Initialize a tty to sane modes.
*/
void
ttyinitmode(struct tty *tp, int echo, int speed)
{
if (speed == 0)
speed = TTYDEF_SPEED;
tp->t_init_in.c_iflag = TTYDEF_IFLAG;
tp->t_init_in.c_oflag = TTYDEF_OFLAG;
tp->t_init_in.c_cflag = TTYDEF_CFLAG;
if (echo)
tp->t_init_in.c_lflag = TTYDEF_LFLAG_ECHO;
else
tp->t_init_in.c_lflag = TTYDEF_LFLAG;
tp->t_init_in.c_ispeed = tp->t_init_in.c_ospeed = speed;
termioschars(&tp->t_init_in);
tp->t_init_out = tp->t_init_in;
tp->t_termios = tp->t_init_in;
}
/*
* Use more "normal" termios paramters for consoles.
*/
@ -3371,17 +3390,15 @@ void
ttyconsolemode(struct tty *tp, int speed)
{
tp->t_init_in.c_iflag = TTYDEF_IFLAG;
tp->t_init_in.c_oflag = TTYDEF_OFLAG;
tp->t_init_in.c_cflag = TTYDEF_CFLAG | CLOCAL;
tp->t_init_in.c_lflag = TTYDEF_LFLAG_ECHO;
tp->t_lock_out.c_cflag = tp->t_lock_in.c_cflag = CLOCAL;
if (speed == 0)
speed = TTYDEF_SPEED;
ttyinitmode(tp, 1, speed);
tp->t_init_in.c_cflag |= CLOCAL;
tp->t_lock_out.c_cflag = tp->t_lock_in.c_cflag = CLOCAL;
tp->t_lock_out.c_ispeed = tp->t_lock_out.c_ospeed =
tp->t_lock_in.c_ispeed = tp->t_lock_in.c_ospeed =
tp->t_init_in.c_ispeed = tp->t_init_in.c_ospeed = speed;
tp->t_lock_in.c_ispeed = tp->t_lock_in.c_ospeed = speed;
tp->t_init_out = tp->t_init_in;
tp->t_termios = tp->t_init_in;
}
/*

View File

@ -175,12 +175,7 @@ ptsopen(struct cdev *dev, int flag, int devtype, struct thread *td)
pt = dev->si_drv1;
tp = dev->si_tty;
if ((tp->t_state & TS_ISOPEN) == 0) {
ttychars(tp); /* Set up default chars */
tp->t_iflag = TTYDEF_IFLAG;
tp->t_oflag = TTYDEF_OFLAG;
tp->t_lflag = TTYDEF_LFLAG_ECHO;
tp->t_cflag = TTYDEF_CFLAG;
tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
ttyinitmode(tp, 1, 0);
} else if (tp->t_state & TS_XCLUDE && suser(td))
return (EBUSY);
else if (pt->pt_prison != td->td_ucred->cr_prison)

View File

@ -357,6 +357,7 @@ void ttyflush(struct tty *tp, int rw);
void ttyfree(struct tty *tp);
void ttygone(struct tty *tp);
void ttyinfo(struct tty *tp);
void ttyinitmode(struct tty *tp, int echo, int speed);
int ttyinput(int c, struct tty *tp);
int ttylclose(struct tty *tp, int flag);
void ttyldoptim(struct tty *tp);