Use generic tty code instead of local stuff.
NB: device names are now consistent: {cua,tty}d$(port)[.lock,.init]
This commit is contained in:
parent
440eb923d0
commit
9cb9afbd68
@ -88,16 +88,6 @@ __FBSDID("$FreeBSD$");
|
||||
|
||||
#define LOTS_OF_EVENTS 64 /* helps separate urgent events from input */
|
||||
|
||||
#define CALLOUT_MASK 0x80
|
||||
#define CONTROL_MASK 0x60
|
||||
#define CONTROL_INIT_STATE 0x20
|
||||
#define CONTROL_LOCK_STATE 0x40
|
||||
#define DEV_TO_UNIT(dev) (MINOR_TO_UNIT(minor(dev)))
|
||||
#define MINOR_TO_UNIT(mynor) ((((mynor) & ~0xffffU) >> (8 + 3)) \
|
||||
| ((mynor) & 0x1f))
|
||||
#define UNIT_TO_MINOR(unit) ((((unit) & ~0x1fU) << (8 + 3)) \
|
||||
| ((unit) & 0x1f))
|
||||
|
||||
#ifdef COM_MULTIPORT
|
||||
/* checks in flags for multiport and which is multiport "master chip"
|
||||
* for a given card
|
||||
@ -181,7 +171,6 @@ struct lbq {
|
||||
/* com device structure */
|
||||
struct com_s {
|
||||
u_char state; /* miscellaneous flag bits */
|
||||
bool_t active_out; /* nonzero if the callout device is open */
|
||||
u_char cfcr_image; /* copy of value written to CFCR */
|
||||
#ifdef COM_ESP
|
||||
bool_t esp; /* is this unit a hayes esp board? */
|
||||
@ -202,7 +191,6 @@ struct com_s {
|
||||
int unit; /* unit number */
|
||||
u_int flags; /* copy of device flags */
|
||||
u_int tx_fifo_size;
|
||||
u_int wopeners; /* # processes waiting for DCD in open() */
|
||||
|
||||
/*
|
||||
* The high level of the driver never reads status registers directly
|
||||
@ -239,8 +227,6 @@ struct com_s {
|
||||
|
||||
struct tty *tp; /* cross reference */
|
||||
|
||||
bool_t do_timestamp;
|
||||
struct timeval timestamp;
|
||||
struct pps_state pps;
|
||||
int pps_bit;
|
||||
#ifdef ALT_BREAK_TO_DEBUGGER
|
||||
@ -258,7 +244,6 @@ struct com_s {
|
||||
struct resource *ioportres;
|
||||
int ioportrid;
|
||||
void *cookie;
|
||||
struct cdev *devs[6];
|
||||
|
||||
/*
|
||||
* Data area for output buffers. Someday we should build the output
|
||||
@ -275,7 +260,8 @@ static int espattach(struct com_s *com, Port_t esp_port);
|
||||
static void combreak(struct tty *tp, int sig);
|
||||
static timeout_t siobusycheck;
|
||||
static u_int siodivisor(u_long rclk, speed_t speed);
|
||||
static void comhardclose(struct com_s *com);
|
||||
static void comclose(struct tty *tp);
|
||||
static int comopen(struct tty *tp, struct cdev *dev);
|
||||
static void sioinput(struct com_s *com);
|
||||
static void siointr1(struct com_s *com);
|
||||
static void siointr(void *arg);
|
||||
@ -297,39 +283,6 @@ devclass_t sio_devclass;
|
||||
#define com_addr(unit) ((struct com_s *) \
|
||||
devclass_get_softc(sio_devclass, unit)) /* XXX */
|
||||
|
||||
static d_open_t sioopen;
|
||||
static d_close_t sioclose;
|
||||
static d_read_t sioread;
|
||||
static d_write_t siowrite;
|
||||
static d_ioctl_t sioioctl;
|
||||
|
||||
static struct cdevsw sio_cdevsw = {
|
||||
.d_version = D_VERSION,
|
||||
.d_open = sioopen,
|
||||
.d_close = sioclose,
|
||||
.d_read = sioread,
|
||||
.d_write = siowrite,
|
||||
.d_ioctl = sioioctl,
|
||||
.d_name = sio_driver_name,
|
||||
.d_flags = D_TTY | D_NEEDGIANT,
|
||||
};
|
||||
|
||||
static d_open_t siocopen;
|
||||
static d_close_t siocclose;
|
||||
static d_read_t siocrdwr;
|
||||
static d_ioctl_t siocioctl;
|
||||
|
||||
static struct cdevsw sioc_cdevsw = {
|
||||
.d_version = D_VERSION,
|
||||
.d_open = siocopen,
|
||||
.d_close = siocclose,
|
||||
.d_read = siocrdwr,
|
||||
.d_write = siocrdwr,
|
||||
.d_ioctl = siocioctl,
|
||||
.d_name = sio_driver_name,
|
||||
.d_flags = D_TTY | D_NEEDGIANT,
|
||||
};
|
||||
|
||||
int comconsole = -1;
|
||||
static volatile speed_t comdefaultrate = CONSPEED;
|
||||
static u_long comdefaultrclk = DEFAULT_RCLK;
|
||||
@ -406,9 +359,6 @@ sysctl_machdep_comdefaultrate(SYSCTL_HANDLER_ARGS)
|
||||
tp->t_init_out.c_ispeed = tp->t_init_out.c_ospeed =
|
||||
tp->t_lock_out.c_ispeed = tp->t_lock_out.c_ospeed = comdefaultrate;
|
||||
|
||||
/*
|
||||
* if we're open, change the running rate too
|
||||
*/
|
||||
if (tp->t_state & TS_ISOPEN) {
|
||||
tp->t_termios.c_ispeed =
|
||||
tp->t_termios.c_ospeed = comdefaultrate;
|
||||
@ -437,11 +387,9 @@ SYSCTL_PROC(_machdep, OID_AUTO, conspeed, CTLTYPE_INT | CTLFLAG_RW,
|
||||
* read and write do not hang.
|
||||
*/
|
||||
int
|
||||
siodetach(dev)
|
||||
device_t dev;
|
||||
siodetach(device_t dev)
|
||||
{
|
||||
struct com_s *com;
|
||||
int i;
|
||||
|
||||
com = (struct com_s *) device_get_softc(dev);
|
||||
if (com == NULL) {
|
||||
@ -450,9 +398,7 @@ siodetach(dev)
|
||||
}
|
||||
com->gone = TRUE;
|
||||
if (com->tp)
|
||||
ttygone(com->tp);
|
||||
for (i = 0 ; i < 6; i++)
|
||||
destroy_dev(com->devs[i]);
|
||||
ttyfree(com->tp);
|
||||
if (com->irqres) {
|
||||
bus_teardown_intr(dev, com->irqres, com->cookie);
|
||||
bus_release_resource(dev, SYS_RES_IRQ, 0, com->irqres);
|
||||
@ -460,16 +406,11 @@ siodetach(dev)
|
||||
if (com->ioportres)
|
||||
bus_release_resource(dev, SYS_RES_IOPORT, com->ioportrid,
|
||||
com->ioportres);
|
||||
if (com->tp && (com->tp->t_state & TS_ISOPEN)) {
|
||||
device_printf(dev, "still open, forcing close\n");
|
||||
ttyld_close(com->tp, 0);
|
||||
tty_close(com->tp);
|
||||
} else {
|
||||
if (com->ibuf != NULL)
|
||||
free(com->ibuf, M_DEVBUF);
|
||||
|
||||
device_set_softc(dev, NULL);
|
||||
free(com, M_DEVBUF);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
@ -916,12 +857,12 @@ sioattach(dev, xrid, rclk)
|
||||
Port_t *espp;
|
||||
#endif
|
||||
Port_t iobase;
|
||||
int minorbase;
|
||||
int unit;
|
||||
u_int flags;
|
||||
int rid;
|
||||
struct resource *port;
|
||||
int ret;
|
||||
int error;
|
||||
struct tty *tp;
|
||||
|
||||
rid = xrid;
|
||||
@ -976,28 +917,19 @@ sioattach(dev, xrid, rclk)
|
||||
tp->t_stop = comstop;
|
||||
tp->t_modem = commodem;
|
||||
tp->t_break = combreak;
|
||||
tp->t_close = comclose;
|
||||
tp->t_open = comopen;
|
||||
tp->t_sc = com;
|
||||
|
||||
if (rclk == 0)
|
||||
rclk = DEFAULT_RCLK;
|
||||
com->rclk = rclk;
|
||||
|
||||
/*
|
||||
* 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;
|
||||
if (unit == comconsole) {
|
||||
if (unit == comconsole)
|
||||
ttyconsolemode(tp, comdefaultrate);
|
||||
} else
|
||||
tp->t_init_in.c_ispeed = tp->t_init_in.c_ospeed = TTYDEF_SPEED;
|
||||
if (siosetwater(com, tp->t_init_in.c_ispeed) != 0) {
|
||||
error = siosetwater(com, tp->t_init_in.c_ispeed);
|
||||
mtx_unlock_spin(&sio_lock);
|
||||
if (error) {
|
||||
/*
|
||||
* Leave i/o resources allocated if this is a `cn'-level
|
||||
* console, so that other devices can't snarf them.
|
||||
@ -1006,14 +938,10 @@ sioattach(dev, xrid, rclk)
|
||||
bus_release_resource(dev, SYS_RES_IOPORT, rid, port);
|
||||
return (ENOMEM);
|
||||
}
|
||||
mtx_unlock_spin(&sio_lock);
|
||||
termioschars(&tp->t_init_in);
|
||||
tp->t_init_out = tp->t_init_in;
|
||||
|
||||
/* attempt to determine UART type */
|
||||
printf("sio%d: type", unit);
|
||||
|
||||
|
||||
if (!COM_ISMULTIPORT(flags) &&
|
||||
!COM_IIR_TXRDYBUG(flags) && !COM_NOSCR(flags)) {
|
||||
u_char scr;
|
||||
@ -1133,27 +1061,10 @@ determined_type: ;
|
||||
swi_add(&clk_ithd, "sio", siopoll, NULL, SWI_CLOCK, 0,
|
||||
&sio_slow_ih);
|
||||
}
|
||||
minorbase = UNIT_TO_MINOR(unit);
|
||||
com->devs[0] = make_dev(&sio_cdevsw, minorbase,
|
||||
UID_ROOT, GID_WHEEL, 0600, "ttyd%r", unit);
|
||||
com->devs[1] = make_dev(&sioc_cdevsw, minorbase | CONTROL_INIT_STATE,
|
||||
UID_ROOT, GID_WHEEL, 0600, "ttyid%r", unit);
|
||||
com->devs[2] = make_dev(&sioc_cdevsw, minorbase | CONTROL_LOCK_STATE,
|
||||
UID_ROOT, GID_WHEEL, 0600, "ttyld%r", unit);
|
||||
com->devs[3] = make_dev(&sio_cdevsw, minorbase | CALLOUT_MASK,
|
||||
UID_UUCP, GID_DIALER, 0660, "cuaa%r", unit);
|
||||
com->devs[4] = make_dev(&sioc_cdevsw,
|
||||
minorbase | CALLOUT_MASK | CONTROL_INIT_STATE,
|
||||
UID_UUCP, GID_DIALER, 0660, "cuaia%r", unit);
|
||||
com->devs[5] = make_dev(&sioc_cdevsw,
|
||||
minorbase | CALLOUT_MASK | CONTROL_LOCK_STATE,
|
||||
UID_UUCP, GID_DIALER, 0660, "cuala%r", unit);
|
||||
for (rid = 0; rid < 6; rid++) {
|
||||
com->devs[rid]->si_drv1 = com;
|
||||
com->devs[rid]->si_tty = tp;
|
||||
}
|
||||
|
||||
com->flags = flags;
|
||||
com->pps.ppscap = PPS_CAPTUREASSERT | PPS_CAPTURECLEAR;
|
||||
tp->t_pps = &com->pps;
|
||||
|
||||
if (COM_PPSCTS(flags))
|
||||
com->pps_bit = MSR_CTS;
|
||||
@ -1188,110 +1099,22 @@ determined_type: ;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* We're ready, open the doors... */
|
||||
ttycreate(tp, NULL, unit, MINOR_CALLOUT, "d%r", unit);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
siocopen(dev, flag, mode, td)
|
||||
struct cdev *dev;
|
||||
int flag;
|
||||
int mode;
|
||||
struct thread *td;
|
||||
comopen(struct tty *tp, struct cdev *dev)
|
||||
{
|
||||
struct com_s *com;
|
||||
int i;
|
||||
|
||||
com = dev->si_drv1;
|
||||
if (com == NULL)
|
||||
return (ENXIO);
|
||||
if (com->gone)
|
||||
return (ENXIO);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
sioopen(dev, flag, mode, td)
|
||||
struct cdev *dev;
|
||||
int flag;
|
||||
int mode;
|
||||
struct thread *td;
|
||||
{
|
||||
struct com_s *com;
|
||||
int error;
|
||||
int mynor;
|
||||
int s;
|
||||
struct tty *tp;
|
||||
int unit;
|
||||
|
||||
mynor = minor(dev);
|
||||
unit = MINOR_TO_UNIT(mynor);
|
||||
com = dev->si_drv1;
|
||||
if (com == NULL)
|
||||
return (ENXIO);
|
||||
if (com->gone)
|
||||
return (ENXIO);
|
||||
tp = dev->si_tty = com->tp;
|
||||
s = spltty();
|
||||
/*
|
||||
* We jump to this label after all non-interrupted sleeps to pick
|
||||
* up any changes of the device state.
|
||||
*/
|
||||
open_top:
|
||||
error = ttydtrwaitsleep(tp);
|
||||
if (error != 0)
|
||||
goto out;
|
||||
if (tp->t_state & TS_ISOPEN) {
|
||||
/*
|
||||
* The device is open, so everything has been initialized.
|
||||
* Handle conflicts.
|
||||
*/
|
||||
if (mynor & CALLOUT_MASK) {
|
||||
if (!com->active_out) {
|
||||
error = EBUSY;
|
||||
goto out;
|
||||
}
|
||||
} else {
|
||||
if (com->active_out) {
|
||||
if (flag & O_NONBLOCK) {
|
||||
error = EBUSY;
|
||||
goto out;
|
||||
}
|
||||
error = tsleep(&com->active_out,
|
||||
TTIPRI | PCATCH, "siobi", 0);
|
||||
if (com_addr(unit) == NULL)
|
||||
return (ENXIO);
|
||||
if (error != 0 || com->gone)
|
||||
goto out;
|
||||
goto open_top;
|
||||
}
|
||||
}
|
||||
if (tp->t_state & TS_XCLUDE &&
|
||||
suser(td)) {
|
||||
error = EBUSY;
|
||||
goto out;
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* The device isn't open, so there are no conflicts.
|
||||
* Initialize it. Initialization is done twice in many
|
||||
* cases: to preempt sleeping callin opens if we are
|
||||
* callout, and to complete a callin open after DCD rises.
|
||||
*/
|
||||
tp->t_dev = dev;
|
||||
tp->t_termios = mynor & CALLOUT_MASK
|
||||
? tp->t_init_out : tp->t_init_in;
|
||||
(void)commodem(tp, SER_DTR | SER_RTS, 0);
|
||||
com = tp->t_sc;
|
||||
com->poll = com->no_irq;
|
||||
com->poll_output = com->loses_outints;
|
||||
++com->wopeners;
|
||||
error = comparam(tp, &tp->t_termios);
|
||||
--com->wopeners;
|
||||
if (error != 0)
|
||||
goto out;
|
||||
/*
|
||||
* XXX we should goto open_top if comparam() slept.
|
||||
*/
|
||||
if (com->hasfifo) {
|
||||
int i;
|
||||
/*
|
||||
* (Re)enable and drain fifos.
|
||||
*
|
||||
@ -1325,10 +1148,8 @@ sioopen(dev, flag, mode, td)
|
||||
DELAY(50);
|
||||
(void) inb(com->data_port);
|
||||
}
|
||||
if (i == 500) {
|
||||
error = EIO;
|
||||
goto out;
|
||||
}
|
||||
if (i == 500)
|
||||
return (EIO);
|
||||
}
|
||||
|
||||
mtx_lock_spin(&sio_lock);
|
||||
@ -1340,106 +1161,25 @@ sioopen(dev, flag, mode, td)
|
||||
IER_ERXRDY | IER_ERLS | IER_EMSC
|
||||
| (COM_IIR_TXRDYBUG(com->flags) ? 0 : IER_ETXRDY));
|
||||
mtx_unlock_spin(&sio_lock);
|
||||
/*
|
||||
* Handle initial DCD. Callout devices get a fake initial
|
||||
* DCD (trapdoor DCD). If we are callout, then any sleeping
|
||||
* callin opens get woken up and resume sleeping on "siobi"
|
||||
* instead of "siodcd".
|
||||
*/
|
||||
/*
|
||||
* XXX `mynor & CALLOUT_MASK' should be
|
||||
* `tp->t_cflag & (SOFT_CARRIER | TRAPDOOR_CARRIER) where
|
||||
* TRAPDOOR_CARRIER is the default initial state for callout
|
||||
* devices and SOFT_CARRIER is like CLOCAL except it hides
|
||||
* the true carrier.
|
||||
*/
|
||||
if (com->prev_modem_status & MSR_DCD || mynor & CALLOUT_MASK)
|
||||
siosettimeout();
|
||||
/* XXX: should be generic ? */
|
||||
if (com->prev_modem_status & MSR_DCD || ISCALLOUT(dev))
|
||||
ttyld_modem(tp, 1);
|
||||
}
|
||||
/*
|
||||
* Wait for DCD if necessary.
|
||||
*/
|
||||
if (!(tp->t_state & TS_CARR_ON) && !(mynor & CALLOUT_MASK)
|
||||
&& !(tp->t_cflag & CLOCAL) && !(flag & O_NONBLOCK)) {
|
||||
++com->wopeners;
|
||||
error = tsleep(TSA_CARR_ON(tp), TTIPRI | PCATCH, "siodcd", 0);
|
||||
if (com_addr(unit) == NULL)
|
||||
return (ENXIO);
|
||||
--com->wopeners;
|
||||
if (error != 0 || com->gone)
|
||||
goto out;
|
||||
goto open_top;
|
||||
}
|
||||
error = ttyld_open(tp, dev);
|
||||
ttyldoptim(tp);
|
||||
if (tp->t_state & TS_ISOPEN && mynor & CALLOUT_MASK)
|
||||
com->active_out = TRUE;
|
||||
siosettimeout();
|
||||
out:
|
||||
splx(s);
|
||||
if (!(tp->t_state & TS_ISOPEN) && com->wopeners == 0)
|
||||
comhardclose(com);
|
||||
return (error);
|
||||
}
|
||||
|
||||
static int
|
||||
siocclose(dev, flag, mode, td)
|
||||
struct cdev *dev;
|
||||
int flag;
|
||||
int mode;
|
||||
struct thread *td;
|
||||
{
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
sioclose(dev, flag, mode, td)
|
||||
struct cdev *dev;
|
||||
int flag;
|
||||
int mode;
|
||||
struct thread *td;
|
||||
{
|
||||
struct com_s *com;
|
||||
int s;
|
||||
struct tty *tp;
|
||||
|
||||
com = dev->si_drv1;
|
||||
if (com == NULL)
|
||||
return (ENODEV);
|
||||
tp = com->tp;
|
||||
s = spltty();
|
||||
ttyld_close(tp, flag);
|
||||
ttyldoptim(tp);
|
||||
comhardclose(com);
|
||||
tty_close(tp);
|
||||
siosettimeout();
|
||||
splx(s);
|
||||
if (com->gone) {
|
||||
printf("sio%d: gone\n", com->unit);
|
||||
s = spltty();
|
||||
if (com->ibuf != NULL)
|
||||
free(com->ibuf, M_DEVBUF);
|
||||
bzero(tp, sizeof *tp);
|
||||
splx(s);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
comhardclose(com)
|
||||
struct com_s *com;
|
||||
comclose(tp)
|
||||
struct tty *tp;
|
||||
{
|
||||
int s;
|
||||
struct tty *tp;
|
||||
struct com_s *com;
|
||||
|
||||
s = spltty();
|
||||
com = tp->t_sc;
|
||||
com->poll = FALSE;
|
||||
com->poll_output = FALSE;
|
||||
com->do_timestamp = FALSE;
|
||||
com->pps.ppsparam.mode = 0;
|
||||
sio_setreg(com, com_cfcr, com->cfcr_image &= ~CFCR_SBREAK);
|
||||
tp = com->tp;
|
||||
|
||||
#if defined(KDB) && (defined(BREAK_TO_DEBUGGER) || \
|
||||
defined(ALT_BREAK_TO_DEBUGGER))
|
||||
@ -1460,7 +1200,7 @@ comhardclose(com)
|
||||
* the next open because it might go up and down while
|
||||
* we're not watching.
|
||||
*/
|
||||
|| (!com->active_out
|
||||
|| (!tp->t_actout
|
||||
&& !(com->prev_modem_status & MSR_DCD)
|
||||
&& !(tp->t_init_in.c_cflag & CLOCAL))
|
||||
|| !(tp->t_state & TS_ISOPEN)) {
|
||||
@ -1476,63 +1216,13 @@ comhardclose(com)
|
||||
*/
|
||||
sio_setreg(com, com_fifo, 0);
|
||||
}
|
||||
com->active_out = FALSE;
|
||||
wakeup(&com->active_out);
|
||||
tp->t_actout = FALSE;
|
||||
wakeup(&tp->t_actout);
|
||||
wakeup(TSA_CARR_ON(tp)); /* restart any wopeners */
|
||||
siosettimeout();
|
||||
splx(s);
|
||||
}
|
||||
|
||||
static int
|
||||
siocrdwr(dev, uio, flag)
|
||||
struct cdev *dev;
|
||||
struct uio *uio;
|
||||
int flag;
|
||||
{
|
||||
|
||||
return (ENODEV);
|
||||
}
|
||||
|
||||
static int
|
||||
sioread(dev, uio, flag)
|
||||
struct cdev *dev;
|
||||
struct uio *uio;
|
||||
int flag;
|
||||
{
|
||||
struct com_s *com;
|
||||
|
||||
com = dev->si_drv1;
|
||||
if (com == NULL || com->gone)
|
||||
return (ENODEV);
|
||||
return (ttyld_read(com->tp, uio, flag));
|
||||
}
|
||||
|
||||
static int
|
||||
siowrite(dev, uio, flag)
|
||||
struct cdev *dev;
|
||||
struct uio *uio;
|
||||
int flag;
|
||||
{
|
||||
int mynor;
|
||||
struct com_s *com;
|
||||
int unit;
|
||||
|
||||
mynor = minor(dev);
|
||||
|
||||
unit = MINOR_TO_UNIT(mynor);
|
||||
com = dev->si_drv1;
|
||||
if (com == NULL || com->gone)
|
||||
return (ENODEV);
|
||||
/*
|
||||
* (XXX) We disallow virtual consoles if the physical console is
|
||||
* a serial port. This is in case there is a display attached that
|
||||
* is not the console. In that situation we don't need/want the X
|
||||
* server taking over the console.
|
||||
*/
|
||||
if (constty != NULL && unit == comconsole)
|
||||
constty = NULL;
|
||||
return (ttyld_write(com->tp, uio, flag));
|
||||
}
|
||||
|
||||
static void
|
||||
siobusycheck(chan)
|
||||
void *chan;
|
||||
@ -1855,8 +1545,8 @@ siointr1(com)
|
||||
if (ioptr >= com->ibufend)
|
||||
CE_RECORD(com, CE_INTERRUPT_BUF_OVERFLOW);
|
||||
else {
|
||||
if (com->do_timestamp)
|
||||
microtime(&com->timestamp);
|
||||
if (com->tp != NULL && com->tp->t_do_timestamp)
|
||||
microtime(&com->tp->t_timestamp);
|
||||
++com_events;
|
||||
swi_sched(sio_slow_ih, SWI_DELAY);
|
||||
#if 0 /* for testing input latency vs efficiency */
|
||||
@ -1972,136 +1662,6 @@ if (com->iptr - com->ibuf == 8)
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
siocioctl(dev, cmd, data, flag, td)
|
||||
struct cdev *dev;
|
||||
u_long cmd;
|
||||
caddr_t data;
|
||||
int flag;
|
||||
struct thread *td;
|
||||
{
|
||||
struct com_s *com;
|
||||
struct tty *tp;
|
||||
int error;
|
||||
int mynor;
|
||||
struct termios *ct;
|
||||
|
||||
mynor = minor(dev);
|
||||
com = dev->si_drv1;
|
||||
if (com == NULL || com->gone)
|
||||
return (ENODEV);
|
||||
tp = com->tp;
|
||||
|
||||
switch (mynor & CONTROL_MASK) {
|
||||
case CONTROL_INIT_STATE:
|
||||
ct = mynor & CALLOUT_MASK ? &tp->t_init_out : &tp->t_init_in;
|
||||
break;
|
||||
case CONTROL_LOCK_STATE:
|
||||
ct = mynor & CALLOUT_MASK ? &tp->t_lock_out : &tp->t_lock_in;
|
||||
break;
|
||||
default:
|
||||
return (ENODEV); /* /dev/nodev */
|
||||
}
|
||||
switch (cmd) {
|
||||
case TIOCSETA:
|
||||
error = suser(td);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
*ct = *(struct termios *)data;
|
||||
return (0);
|
||||
case TIOCGETA:
|
||||
*(struct termios *)data = *ct;
|
||||
return (0);
|
||||
case TIOCGETD:
|
||||
*(int *)data = TTYDISC;
|
||||
return (0);
|
||||
case TIOCGWINSZ:
|
||||
bzero(data, sizeof(struct winsize));
|
||||
return (0);
|
||||
default:
|
||||
return (ENOTTY);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
sioioctl(dev, cmd, data, flag, td)
|
||||
struct cdev *dev;
|
||||
u_long cmd;
|
||||
caddr_t data;
|
||||
int flag;
|
||||
struct thread *td;
|
||||
{
|
||||
struct com_s *com;
|
||||
int error;
|
||||
int mynor;
|
||||
int s;
|
||||
struct tty *tp;
|
||||
#ifndef BURN_BRIDGES
|
||||
#if defined(COMPAT_43)
|
||||
u_long oldcmd;
|
||||
struct termios term;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
mynor = minor(dev);
|
||||
com = dev->si_drv1;
|
||||
if (com == NULL || com->gone)
|
||||
return (ENODEV);
|
||||
tp = com->tp;
|
||||
#ifndef BURN_BRIDGES
|
||||
#if defined(COMPAT_43)
|
||||
term = tp->t_termios;
|
||||
oldcmd = cmd;
|
||||
error = ttsetcompat(tp, &cmd, data, &term);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
if (cmd != oldcmd)
|
||||
data = (caddr_t)&term;
|
||||
#endif
|
||||
#endif
|
||||
if (cmd == TIOCSETA || cmd == TIOCSETAW || cmd == TIOCSETAF) {
|
||||
int cc;
|
||||
struct termios *dt = (struct termios *)data;
|
||||
struct termios *lt = mynor & CALLOUT_MASK
|
||||
? &tp->t_lock_out : &tp->t_lock_in;
|
||||
|
||||
dt->c_iflag = (tp->t_iflag & lt->c_iflag)
|
||||
| (dt->c_iflag & ~lt->c_iflag);
|
||||
dt->c_oflag = (tp->t_oflag & lt->c_oflag)
|
||||
| (dt->c_oflag & ~lt->c_oflag);
|
||||
dt->c_cflag = (tp->t_cflag & lt->c_cflag)
|
||||
| (dt->c_cflag & ~lt->c_cflag);
|
||||
dt->c_lflag = (tp->t_lflag & lt->c_lflag)
|
||||
| (dt->c_lflag & ~lt->c_lflag);
|
||||
for (cc = 0; cc < NCCS; ++cc)
|
||||
if (lt->c_cc[cc] != 0)
|
||||
dt->c_cc[cc] = tp->t_cc[cc];
|
||||
if (lt->c_ispeed != 0)
|
||||
dt->c_ispeed = tp->t_ispeed;
|
||||
if (lt->c_ospeed != 0)
|
||||
dt->c_ospeed = tp->t_ospeed;
|
||||
}
|
||||
error = ttyioctl(dev, cmd, data, flag, td);
|
||||
ttyldoptim(tp);
|
||||
if (error != ENOTTY)
|
||||
return (error);
|
||||
s = spltty();
|
||||
switch (cmd) {
|
||||
case TIOCTIMESTAMP:
|
||||
com->do_timestamp = TRUE;
|
||||
*(struct timeval *)data = com->timestamp;
|
||||
break;
|
||||
default:
|
||||
splx(s);
|
||||
error = pps_ioctl(cmd, data, &com->pps);
|
||||
if (error == ENODEV)
|
||||
error = ENOTTY;
|
||||
return (error);
|
||||
}
|
||||
splx(s);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* software interrupt handler for SWI_TTY */
|
||||
static void
|
||||
siopoll(void *dummy)
|
||||
@ -2547,9 +2107,7 @@ comstop(tp, rw)
|
||||
}
|
||||
|
||||
static int
|
||||
commodem(tp, sigon, sigoff)
|
||||
struct tty *tp;
|
||||
int sigon, sigoff;
|
||||
commodem(struct tty *tp, int sigon, int sigoff)
|
||||
{
|
||||
struct com_s *com;
|
||||
int bitand, bitor, msr;
|
||||
|
@ -126,15 +126,6 @@
|
||||
|
||||
#define LOTS_OF_EVENTS 64 /* helps separate urgent events from input */
|
||||
|
||||
#define CALLOUT_MASK 0x80
|
||||
#define CONTROL_MASK 0x60
|
||||
#define CONTROL_INIT_STATE 0x20
|
||||
#define CONTROL_LOCK_STATE 0x40
|
||||
#define DEV_TO_UNIT(dev) (MINOR_TO_UNIT(minor(dev)))
|
||||
#define MINOR_TO_UNIT(mynor) ((((mynor) & ~0xffffU) >> (8 + 3)) \
|
||||
| ((mynor) & 0x1f))
|
||||
#define UNIT_TO_MINOR(unit) ((((unit) & ~0x1fU) << (8 + 3)) \
|
||||
| ((unit) & 0x1f))
|
||||
|
||||
/*
|
||||
* Meaning of flags:
|
||||
@ -243,7 +234,6 @@ struct lbq {
|
||||
/* com device structure */
|
||||
struct com_s {
|
||||
u_char state; /* miscellaneous flag bits */
|
||||
bool_t active_out; /* nonzero if the callout device is open */
|
||||
u_char cfcr_image; /* copy of value written to CFCR */
|
||||
#ifdef COM_ESP
|
||||
bool_t esp; /* is this unit a hayes esp board? */
|
||||
@ -264,7 +254,6 @@ struct com_s {
|
||||
int unit; /* unit number */
|
||||
u_int flags; /* copy of device flags */
|
||||
u_int tx_fifo_size;
|
||||
u_int wopeners; /* # processes waiting for DCD in open() */
|
||||
|
||||
/*
|
||||
* The high level of the driver never reads status registers directly
|
||||
@ -338,7 +327,6 @@ struct com_s {
|
||||
struct resource *ioportres;
|
||||
int ioportrid;
|
||||
void *cookie;
|
||||
struct cdev *devs[6];
|
||||
|
||||
/*
|
||||
* Data area for output buffers. Someday we should build the output
|
||||
@ -361,7 +349,6 @@ static int espattach(struct com_s *com, Port_t esp_port);
|
||||
static void combreak(struct tty *tp, int sig);
|
||||
static timeout_t siobusycheck;
|
||||
static u_int siodivisor(u_long rclk, speed_t speed);
|
||||
static void comhardclose(struct com_s *com);
|
||||
static void sioinput(struct com_s *com);
|
||||
static void siointr1(struct com_s *com);
|
||||
static void siointr(void *arg);
|
||||
@ -383,38 +370,8 @@ devclass_t sio_devclass;
|
||||
#define com_addr(unit) ((struct com_s *) \
|
||||
devclass_get_softc(sio_devclass, unit)) /* XXX */
|
||||
|
||||
static d_open_t sioopen;
|
||||
static d_close_t sioclose;
|
||||
static d_read_t sioread;
|
||||
static d_write_t siowrite;
|
||||
static d_ioctl_t sioioctl;
|
||||
|
||||
static struct cdevsw sio_cdevsw = {
|
||||
.d_version = D_VERSION,
|
||||
.d_open = sioopen,
|
||||
.d_close = sioclose,
|
||||
.d_read = sioread,
|
||||
.d_write = siowrite,
|
||||
.d_ioctl = sioioctl,
|
||||
.d_name = sio_driver_name,
|
||||
.d_flags = D_TTY | D_NEEDGIANT,
|
||||
};
|
||||
|
||||
static d_open_t siocopen;
|
||||
static d_close_t siocclose;
|
||||
static d_read_t siocrdwr;
|
||||
static d_ioctl_t siocioctl;
|
||||
|
||||
static struct cdevsw sioc_cdevsw = {
|
||||
.d_version = D_VERSION,
|
||||
.d_open = siocopen,
|
||||
.d_close = siocclose,
|
||||
.d_read = siocrdwr,
|
||||
.d_write = siocrdwr,
|
||||
.d_ioctl = siocioctl,
|
||||
.d_name = sio_driver_name,
|
||||
.d_flags = D_TTY | D_NEEDGIANT,
|
||||
};
|
||||
static t_close_t sioclose;
|
||||
static t_open_t sioopen;
|
||||
|
||||
int comconsole = -1;
|
||||
static volatile speed_t comdefaultrate = CONSPEED;
|
||||
@ -731,6 +688,10 @@ sysctl_machdep_comdefaultrate(SYSCTL_HANDLER_ARGS)
|
||||
if (tp == NULL)
|
||||
return (ENXIO);
|
||||
|
||||
tp = com->tp;
|
||||
if (tp == NULL)
|
||||
return (ENXIO);
|
||||
|
||||
/*
|
||||
* set the initial and lock rates for /dev/ttydXX and /dev/cuaXX
|
||||
* (note, the lock rates really are boolean -- if non-zero, disallow
|
||||
@ -741,9 +702,6 @@ sysctl_machdep_comdefaultrate(SYSCTL_HANDLER_ARGS)
|
||||
tp->t_init_out.c_ispeed = tp->t_init_out.c_ospeed =
|
||||
tp->t_lock_out.c_ispeed = tp->t_lock_out.c_ospeed = comdefaultrate;
|
||||
|
||||
/*
|
||||
* if we're open, change the running rate too
|
||||
*/
|
||||
if (tp->t_state & TS_ISOPEN) {
|
||||
tp->t_termios.c_ispeed =
|
||||
tp->t_termios.c_ospeed = comdefaultrate;
|
||||
@ -772,7 +730,6 @@ siodetach(dev)
|
||||
device_t dev;
|
||||
{
|
||||
struct com_s *com;
|
||||
int i;
|
||||
|
||||
com = (struct com_s *) device_get_softc(dev);
|
||||
if (com == NULL) {
|
||||
@ -782,8 +739,6 @@ siodetach(dev)
|
||||
com->gone = TRUE;
|
||||
if (com->tp)
|
||||
ttygone(com->tp);
|
||||
for (i = 0 ; i < 6; i++)
|
||||
destroy_dev(com->devs[i]);
|
||||
if (com->irqres) {
|
||||
bus_teardown_intr(dev, com->irqres, com->cookie);
|
||||
bus_release_resource(dev, SYS_RES_IRQ, 0, com->irqres);
|
||||
@ -793,8 +748,7 @@ siodetach(dev)
|
||||
com->ioportres);
|
||||
if (com->tp && (com->tp->t_state & TS_ISOPEN)) {
|
||||
device_printf(dev, "still open, forcing close\n");
|
||||
ttyld_close(com->tp, 0);
|
||||
tty_close(com->tp);
|
||||
ttyfree(com->tp);
|
||||
} else {
|
||||
if (com->ibuf != NULL)
|
||||
free(com->ibuf, M_DEVBUF);
|
||||
@ -803,6 +757,8 @@ siodetach(dev)
|
||||
free(com->obuf1, M_DEVBUF);
|
||||
#endif
|
||||
device_set_softc(dev, NULL);
|
||||
if (com->tp)
|
||||
ttyfree(com->tp);
|
||||
free(com, M_DEVBUF);
|
||||
}
|
||||
return (0);
|
||||
@ -1548,8 +1504,9 @@ sioattach(dev, xrid, rclk)
|
||||
com->line_status_port = iobase + com_lsr;
|
||||
com->modem_status_port = iobase + com_msr;
|
||||
#endif
|
||||
|
||||
tp = com->tp = ttyalloc();
|
||||
tp->t_open = sioopen;
|
||||
tp->t_close = sioclose;
|
||||
tp->t_oproc = comstart;
|
||||
tp->t_param = comparam;
|
||||
tp->t_stop = comstop;
|
||||
@ -1809,25 +1766,8 @@ determined_type: ;
|
||||
swi_add(&clk_ithd, "sio", siopoll, NULL, SWI_CLOCK, 0,
|
||||
&sio_slow_ih);
|
||||
}
|
||||
minorbase = UNIT_TO_MINOR(unit);
|
||||
com->devs[0] = make_dev(&sio_cdevsw, minorbase,
|
||||
UID_ROOT, GID_WHEEL, 0600, "ttyd%r", unit);
|
||||
com->devs[1] = make_dev(&sioc_cdevsw, minorbase | CONTROL_INIT_STATE,
|
||||
UID_ROOT, GID_WHEEL, 0600, "ttyid%r", unit);
|
||||
com->devs[2] = make_dev(&sioc_cdevsw, minorbase | CONTROL_LOCK_STATE,
|
||||
UID_ROOT, GID_WHEEL, 0600, "ttyld%r", unit);
|
||||
com->devs[3] = make_dev(&sio_cdevsw, minorbase | CALLOUT_MASK,
|
||||
UID_UUCP, GID_DIALER, 0660, "cuaa%r", unit);
|
||||
com->devs[4] = make_dev(&sioc_cdevsw,
|
||||
minorbase | CALLOUT_MASK | CONTROL_INIT_STATE,
|
||||
UID_UUCP, GID_DIALER, 0660, "cuaia%r", unit);
|
||||
com->devs[5] = make_dev(&sioc_cdevsw,
|
||||
minorbase | CALLOUT_MASK | CONTROL_LOCK_STATE,
|
||||
UID_UUCP, GID_DIALER, 0660, "cuala%r", unit);
|
||||
for (rid = 0; rid < 6; rid++) {
|
||||
com->devs[rid]->si_drv1 = com;
|
||||
com->devs[rid]->si_tty = tp;
|
||||
}
|
||||
minorbase = unit2minor(unit);
|
||||
ttycreate(tp, NULL, 0, MINOR_CALLOUT, "d%r", unit);
|
||||
com->flags = flags;
|
||||
com->pps.ppscap = PPS_CAPTUREASSERT | PPS_CAPTURECLEAR;
|
||||
|
||||
@ -1868,104 +1808,16 @@ determined_type: ;
|
||||
}
|
||||
|
||||
static int
|
||||
siocopen(dev, flag, mode, td)
|
||||
struct cdev *dev;
|
||||
int flag;
|
||||
int mode;
|
||||
struct thread *td;
|
||||
sioopen(struct tty *tp, struct cdev *dev)
|
||||
{
|
||||
struct com_s *com;
|
||||
|
||||
com = dev->si_drv1;
|
||||
if (com == NULL)
|
||||
return (ENXIO);
|
||||
if (com->gone)
|
||||
return (ENXIO);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
sioopen(dev, flag, mode, td)
|
||||
struct cdev *dev;
|
||||
int flag;
|
||||
int mode;
|
||||
struct thread *td;
|
||||
{
|
||||
struct com_s *com;
|
||||
int error;
|
||||
int mynor;
|
||||
int s;
|
||||
struct tty *tp;
|
||||
int unit;
|
||||
|
||||
mynor = minor(dev);
|
||||
unit = MINOR_TO_UNIT(mynor);
|
||||
com = dev->si_drv1;
|
||||
if (com == NULL)
|
||||
return (ENXIO);
|
||||
if (com->gone)
|
||||
return (ENXIO);
|
||||
tp = dev->si_tty = com->tp;
|
||||
s = spltty();
|
||||
/*
|
||||
* We jump to this label after all non-interrupted sleeps to pick
|
||||
* up any changes of the device state.
|
||||
*/
|
||||
open_top:
|
||||
error = ttydtrwaitsleep(tp);
|
||||
if (error != 0)
|
||||
goto out;
|
||||
if (tp->t_state & TS_ISOPEN) {
|
||||
/*
|
||||
* The device is open, so everything has been initialized.
|
||||
* Handle conflicts.
|
||||
*/
|
||||
if (mynor & CALLOUT_MASK) {
|
||||
if (!com->active_out) {
|
||||
error = EBUSY;
|
||||
goto out;
|
||||
}
|
||||
} else {
|
||||
if (com->active_out) {
|
||||
if (flag & O_NONBLOCK) {
|
||||
error = EBUSY;
|
||||
goto out;
|
||||
}
|
||||
error = tsleep(&com->active_out,
|
||||
TTIPRI | PCATCH, "siobi", 0);
|
||||
if (com_addr(unit) == NULL)
|
||||
return (ENXIO);
|
||||
if (error != 0 || com->gone)
|
||||
goto out;
|
||||
goto open_top;
|
||||
}
|
||||
}
|
||||
if (tp->t_state & TS_XCLUDE &&
|
||||
suser(td)) {
|
||||
error = EBUSY;
|
||||
goto out;
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* The device isn't open, so there are no conflicts.
|
||||
* Initialize it. Initialization is done twice in many
|
||||
* cases: to preempt sleeping callin opens if we are
|
||||
* callout, and to complete a callin open after DCD rises.
|
||||
*/
|
||||
tp->t_dev = dev;
|
||||
tp->t_termios = mynor & CALLOUT_MASK
|
||||
? tp->t_init_out : tp->t_init_in;
|
||||
com = tp->t_sc;
|
||||
#ifdef PC98
|
||||
if (!IS_8251(com->pc98_if_type))
|
||||
#endif
|
||||
(void)commodem(tp, SER_DTR | SER_RTS, 0);
|
||||
com->poll = com->no_irq;
|
||||
com->poll_output = com->loses_outints;
|
||||
++com->wopeners;
|
||||
error = comparam(tp, &tp->t_termios);
|
||||
--com->wopeners;
|
||||
if (error != 0)
|
||||
goto out;
|
||||
#ifdef PC98
|
||||
if (IS_8251(com->pc98_if_type)) {
|
||||
com_tiocm_bis(com, TIOCM_DTR|TIOCM_RTS);
|
||||
@ -2027,8 +1879,7 @@ sioopen(dev, flag, mode, td)
|
||||
(void) inb(com->data_port);
|
||||
}
|
||||
if (i == 500) {
|
||||
error = EIO;
|
||||
goto out;
|
||||
return (EIO);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2057,111 +1908,28 @@ sioopen(dev, flag, mode, td)
|
||||
}
|
||||
#endif
|
||||
mtx_unlock_spin(&sio_lock);
|
||||
/*
|
||||
* Handle initial DCD. Callout devices get a fake initial
|
||||
* DCD (trapdoor DCD). If we are callout, then any sleeping
|
||||
* callin opens get woken up and resume sleeping on "siobi"
|
||||
* instead of "siodcd".
|
||||
*/
|
||||
/*
|
||||
* XXX `mynor & CALLOUT_MASK' should be
|
||||
* `tp->t_cflag & (SOFT_CARRIER | TRAPDOOR_CARRIER) where
|
||||
* TRAPDOOR_CARRIER is the default initial state for callout
|
||||
* devices and SOFT_CARRIER is like CLOCAL except it hides
|
||||
* the true carrier.
|
||||
*/
|
||||
siosettimeout();
|
||||
#ifdef PC98
|
||||
if ((IS_8251(com->pc98_if_type) &&
|
||||
(pc98_get_modem_status(com) & TIOCM_CAR)) ||
|
||||
(!IS_8251(com->pc98_if_type) &&
|
||||
(com->prev_modem_status & MSR_DCD)) ||
|
||||
mynor & CALLOUT_MASK)
|
||||
ISCALLOUT(dev))
|
||||
ttyld_modem(tp, 1);
|
||||
#else
|
||||
if (com->prev_modem_status & MSR_DCD || mynor & CALLOUT_MASK)
|
||||
if (com->prev_modem_status & MSR_DCD || ISCALLOUT(dev))
|
||||
ttyld_modem(tp, 1);
|
||||
#endif
|
||||
}
|
||||
/*
|
||||
* Wait for DCD if necessary.
|
||||
*/
|
||||
if (!(tp->t_state & TS_CARR_ON) && !(mynor & CALLOUT_MASK)
|
||||
&& !(tp->t_cflag & CLOCAL) && !(flag & O_NONBLOCK)) {
|
||||
++com->wopeners;
|
||||
error = tsleep(TSA_CARR_ON(tp), TTIPRI | PCATCH, "siodcd", 0);
|
||||
if (com_addr(unit) == NULL)
|
||||
return (ENXIO);
|
||||
--com->wopeners;
|
||||
if (error != 0 || com->gone)
|
||||
goto out;
|
||||
goto open_top;
|
||||
}
|
||||
error = ttyld_open(tp, dev);
|
||||
ttyldoptim(tp);
|
||||
if (tp->t_state & TS_ISOPEN && mynor & CALLOUT_MASK)
|
||||
com->active_out = TRUE;
|
||||
siosettimeout();
|
||||
out:
|
||||
splx(s);
|
||||
if (!(tp->t_state & TS_ISOPEN) && com->wopeners == 0)
|
||||
comhardclose(com);
|
||||
return (error);
|
||||
}
|
||||
|
||||
static int
|
||||
siocclose(dev, flag, mode, td)
|
||||
struct cdev *dev;
|
||||
int flag;
|
||||
int mode;
|
||||
struct thread *td;
|
||||
{
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
sioclose(dev, flag, mode, td)
|
||||
struct cdev *dev;
|
||||
int flag;
|
||||
int mode;
|
||||
struct thread *td;
|
||||
{
|
||||
struct com_s *com;
|
||||
int s;
|
||||
struct tty *tp;
|
||||
|
||||
com = dev->si_drv1;
|
||||
if (com == NULL)
|
||||
return (ENODEV);
|
||||
tp = com->tp;
|
||||
s = spltty();
|
||||
ttyld_close(tp, flag);
|
||||
#ifdef PC98
|
||||
com->modem_checking = 0;
|
||||
#endif
|
||||
ttyldoptim(tp);
|
||||
comhardclose(com);
|
||||
tty_close(tp);
|
||||
siosettimeout();
|
||||
splx(s);
|
||||
if (com->gone) {
|
||||
printf("sio%d: gone\n", com->unit);
|
||||
s = spltty();
|
||||
if (com->ibuf != NULL)
|
||||
free(com->ibuf, M_DEVBUF);
|
||||
bzero(tp, sizeof *tp);
|
||||
splx(s);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
comhardclose(com)
|
||||
struct com_s *com;
|
||||
sioclose(struct tty *tp)
|
||||
{
|
||||
struct com_s *com;
|
||||
int s;
|
||||
struct tty *tp;
|
||||
|
||||
com = tp->t_sc;
|
||||
s = spltty();
|
||||
com->poll = FALSE;
|
||||
com->poll_output = FALSE;
|
||||
@ -2172,7 +1940,6 @@ comhardclose(com)
|
||||
#else
|
||||
sio_setreg(com, com_cfcr, com->cfcr_image &= ~CFCR_SBREAK);
|
||||
#endif
|
||||
tp = com->tp;
|
||||
|
||||
#if defined(KDB) && (defined(BREAK_TO_DEBUGGER) || \
|
||||
defined(ALT_BREAK_TO_DEBUGGER))
|
||||
@ -2207,7 +1974,7 @@ comhardclose(com)
|
||||
* the next open because it might go up and down while
|
||||
* we're not watching.
|
||||
*/
|
||||
|| (!com->active_out
|
||||
|| (!tp->t_actout
|
||||
#ifdef PC98
|
||||
&& !(tmp)
|
||||
#else
|
||||
@ -2245,63 +2012,12 @@ comhardclose(com)
|
||||
*/
|
||||
sio_setreg(com, com_fifo, 0);
|
||||
}
|
||||
com->active_out = FALSE;
|
||||
wakeup(&com->active_out);
|
||||
tp->t_actout = FALSE;
|
||||
wakeup(&tp->t_actout);
|
||||
wakeup(TSA_CARR_ON(tp)); /* restart any wopeners */
|
||||
splx(s);
|
||||
}
|
||||
|
||||
static int
|
||||
siocrdwr(dev, uio, flag)
|
||||
struct cdev *dev;
|
||||
struct uio *uio;
|
||||
int flag;
|
||||
{
|
||||
|
||||
return (ENODEV);
|
||||
}
|
||||
|
||||
static int
|
||||
sioread(dev, uio, flag)
|
||||
struct cdev *dev;
|
||||
struct uio *uio;
|
||||
int flag;
|
||||
{
|
||||
struct com_s *com;
|
||||
|
||||
com = dev->si_drv1;
|
||||
if (com == NULL || com->gone)
|
||||
return (ENODEV);
|
||||
return (ttyld_read(com->tp, uio, flag));
|
||||
}
|
||||
|
||||
static int
|
||||
siowrite(dev, uio, flag)
|
||||
struct cdev *dev;
|
||||
struct uio *uio;
|
||||
int flag;
|
||||
{
|
||||
int mynor;
|
||||
struct com_s *com;
|
||||
int unit;
|
||||
|
||||
mynor = minor(dev);
|
||||
|
||||
unit = MINOR_TO_UNIT(mynor);
|
||||
com = dev->si_drv1;
|
||||
if (com == NULL || com->gone)
|
||||
return (ENODEV);
|
||||
/*
|
||||
* (XXX) We disallow virtual consoles if the physical console is
|
||||
* a serial port. This is in case there is a display attached that
|
||||
* is not the console. In that situation we don't need/want the X
|
||||
* server taking over the console.
|
||||
*/
|
||||
if (constty != NULL && unit == comconsole)
|
||||
constty = NULL;
|
||||
return (ttyld_write(com->tp, uio, flag));
|
||||
}
|
||||
|
||||
static void
|
||||
siobusycheck(chan)
|
||||
void *chan;
|
||||
@ -2953,136 +2669,6 @@ if (com->iptr - com->ibuf == 8)
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
siocioctl(dev, cmd, data, flag, td)
|
||||
struct cdev *dev;
|
||||
u_long cmd;
|
||||
caddr_t data;
|
||||
int flag;
|
||||
struct thread *td;
|
||||
{
|
||||
struct com_s *com;
|
||||
struct tty *tp;
|
||||
int error;
|
||||
int mynor;
|
||||
struct termios *ct;
|
||||
|
||||
mynor = minor(dev);
|
||||
com = dev->si_drv1;
|
||||
if (com == NULL || com->gone)
|
||||
return (ENODEV);
|
||||
tp = com->tp;
|
||||
|
||||
switch (mynor & CONTROL_MASK) {
|
||||
case CONTROL_INIT_STATE:
|
||||
ct = mynor & CALLOUT_MASK ? &tp->t_init_out : &tp->t_init_in;
|
||||
break;
|
||||
case CONTROL_LOCK_STATE:
|
||||
ct = mynor & CALLOUT_MASK ? &tp->t_lock_out : &tp->t_lock_in;
|
||||
break;
|
||||
default:
|
||||
return (ENODEV); /* /dev/nodev */
|
||||
}
|
||||
switch (cmd) {
|
||||
case TIOCSETA:
|
||||
error = suser(td);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
*ct = *(struct termios *)data;
|
||||
return (0);
|
||||
case TIOCGETA:
|
||||
*(struct termios *)data = *ct;
|
||||
return (0);
|
||||
case TIOCGETD:
|
||||
*(int *)data = TTYDISC;
|
||||
return (0);
|
||||
case TIOCGWINSZ:
|
||||
bzero(data, sizeof(struct winsize));
|
||||
return (0);
|
||||
default:
|
||||
return (ENOTTY);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
sioioctl(dev, cmd, data, flag, td)
|
||||
struct cdev *dev;
|
||||
u_long cmd;
|
||||
caddr_t data;
|
||||
int flag;
|
||||
struct thread *td;
|
||||
{
|
||||
struct com_s *com;
|
||||
int error;
|
||||
int mynor;
|
||||
int s;
|
||||
struct tty *tp;
|
||||
#ifndef BURN_BRIDGES
|
||||
#if defined(COMPAT_43)
|
||||
u_long oldcmd;
|
||||
struct termios term;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
mynor = minor(dev);
|
||||
com = dev->si_drv1;
|
||||
if (com == NULL || com->gone)
|
||||
return (ENODEV);
|
||||
tp = com->tp;
|
||||
#ifndef BURN_BRIDGES
|
||||
#if defined(COMPAT_43)
|
||||
term = tp->t_termios;
|
||||
oldcmd = cmd;
|
||||
error = ttsetcompat(tp, &cmd, data, &term);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
if (cmd != oldcmd)
|
||||
data = (caddr_t)&term;
|
||||
#endif
|
||||
#endif
|
||||
if (cmd == TIOCSETA || cmd == TIOCSETAW || cmd == TIOCSETAF) {
|
||||
int cc;
|
||||
struct termios *dt = (struct termios *)data;
|
||||
struct termios *lt = mynor & CALLOUT_MASK
|
||||
? &tp->t_lock_out : &tp->t_lock_in;
|
||||
|
||||
dt->c_iflag = (tp->t_iflag & lt->c_iflag)
|
||||
| (dt->c_iflag & ~lt->c_iflag);
|
||||
dt->c_oflag = (tp->t_oflag & lt->c_oflag)
|
||||
| (dt->c_oflag & ~lt->c_oflag);
|
||||
dt->c_cflag = (tp->t_cflag & lt->c_cflag)
|
||||
| (dt->c_cflag & ~lt->c_cflag);
|
||||
dt->c_lflag = (tp->t_lflag & lt->c_lflag)
|
||||
| (dt->c_lflag & ~lt->c_lflag);
|
||||
for (cc = 0; cc < NCCS; ++cc)
|
||||
if (lt->c_cc[cc] != 0)
|
||||
dt->c_cc[cc] = tp->t_cc[cc];
|
||||
if (lt->c_ispeed != 0)
|
||||
dt->c_ispeed = tp->t_ispeed;
|
||||
if (lt->c_ospeed != 0)
|
||||
dt->c_ospeed = tp->t_ospeed;
|
||||
}
|
||||
error = ttyioctl(dev, cmd, data, flag, td);
|
||||
ttyldoptim(tp);
|
||||
if (error != ENOTTY)
|
||||
return (error);
|
||||
s = spltty();
|
||||
switch (cmd) {
|
||||
case TIOCTIMESTAMP:
|
||||
com->do_timestamp = TRUE;
|
||||
*(struct timeval *)data = com->timestamp;
|
||||
break;
|
||||
default:
|
||||
splx(s);
|
||||
error = pps_ioctl(cmd, data, &com->pps);
|
||||
if (error == ENODEV)
|
||||
error = ENOTTY;
|
||||
return (error);
|
||||
}
|
||||
splx(s);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* software interrupt handler for SWI_TTY */
|
||||
static void
|
||||
siopoll(void *dummy)
|
||||
@ -3858,9 +3444,7 @@ commint(struct cdev *dev)
|
||||
register struct tty *tp;
|
||||
int stat,delta;
|
||||
struct com_s *com;
|
||||
int mynor;
|
||||
|
||||
mynor = minor(dev);
|
||||
com = dev->si_drv1;
|
||||
tp = com->tp;
|
||||
|
||||
@ -3873,7 +3457,7 @@ commint(struct cdev *dev)
|
||||
else
|
||||
com->state &= ~CS_ODEVREADY;
|
||||
}
|
||||
if ((delta & TIOCM_CAR) && (mynor & CALLOUT_MASK) == 0) {
|
||||
if ((delta & TIOCM_CAR) && (ISCALLOUT(dev)) == 0) {
|
||||
if (stat & TIOCM_CAR )
|
||||
(void)ttyld_modem(tp, 1);
|
||||
else if (ttyld_modem(tp, 0) == 0) {
|
||||
|
@ -126,15 +126,6 @@
|
||||
|
||||
#define LOTS_OF_EVENTS 64 /* helps separate urgent events from input */
|
||||
|
||||
#define CALLOUT_MASK 0x80
|
||||
#define CONTROL_MASK 0x60
|
||||
#define CONTROL_INIT_STATE 0x20
|
||||
#define CONTROL_LOCK_STATE 0x40
|
||||
#define DEV_TO_UNIT(dev) (MINOR_TO_UNIT(minor(dev)))
|
||||
#define MINOR_TO_UNIT(mynor) ((((mynor) & ~0xffffU) >> (8 + 3)) \
|
||||
| ((mynor) & 0x1f))
|
||||
#define UNIT_TO_MINOR(unit) ((((unit) & ~0x1fU) << (8 + 3)) \
|
||||
| ((unit) & 0x1f))
|
||||
|
||||
/*
|
||||
* Meaning of flags:
|
||||
@ -243,7 +234,6 @@ struct lbq {
|
||||
/* com device structure */
|
||||
struct com_s {
|
||||
u_char state; /* miscellaneous flag bits */
|
||||
bool_t active_out; /* nonzero if the callout device is open */
|
||||
u_char cfcr_image; /* copy of value written to CFCR */
|
||||
#ifdef COM_ESP
|
||||
bool_t esp; /* is this unit a hayes esp board? */
|
||||
@ -264,7 +254,6 @@ struct com_s {
|
||||
int unit; /* unit number */
|
||||
u_int flags; /* copy of device flags */
|
||||
u_int tx_fifo_size;
|
||||
u_int wopeners; /* # processes waiting for DCD in open() */
|
||||
|
||||
/*
|
||||
* The high level of the driver never reads status registers directly
|
||||
@ -338,7 +327,6 @@ struct com_s {
|
||||
struct resource *ioportres;
|
||||
int ioportrid;
|
||||
void *cookie;
|
||||
struct cdev *devs[6];
|
||||
|
||||
/*
|
||||
* Data area for output buffers. Someday we should build the output
|
||||
@ -361,7 +349,6 @@ static int espattach(struct com_s *com, Port_t esp_port);
|
||||
static void combreak(struct tty *tp, int sig);
|
||||
static timeout_t siobusycheck;
|
||||
static u_int siodivisor(u_long rclk, speed_t speed);
|
||||
static void comhardclose(struct com_s *com);
|
||||
static void sioinput(struct com_s *com);
|
||||
static void siointr1(struct com_s *com);
|
||||
static void siointr(void *arg);
|
||||
@ -383,38 +370,8 @@ devclass_t sio_devclass;
|
||||
#define com_addr(unit) ((struct com_s *) \
|
||||
devclass_get_softc(sio_devclass, unit)) /* XXX */
|
||||
|
||||
static d_open_t sioopen;
|
||||
static d_close_t sioclose;
|
||||
static d_read_t sioread;
|
||||
static d_write_t siowrite;
|
||||
static d_ioctl_t sioioctl;
|
||||
|
||||
static struct cdevsw sio_cdevsw = {
|
||||
.d_version = D_VERSION,
|
||||
.d_open = sioopen,
|
||||
.d_close = sioclose,
|
||||
.d_read = sioread,
|
||||
.d_write = siowrite,
|
||||
.d_ioctl = sioioctl,
|
||||
.d_name = sio_driver_name,
|
||||
.d_flags = D_TTY | D_NEEDGIANT,
|
||||
};
|
||||
|
||||
static d_open_t siocopen;
|
||||
static d_close_t siocclose;
|
||||
static d_read_t siocrdwr;
|
||||
static d_ioctl_t siocioctl;
|
||||
|
||||
static struct cdevsw sioc_cdevsw = {
|
||||
.d_version = D_VERSION,
|
||||
.d_open = siocopen,
|
||||
.d_close = siocclose,
|
||||
.d_read = siocrdwr,
|
||||
.d_write = siocrdwr,
|
||||
.d_ioctl = siocioctl,
|
||||
.d_name = sio_driver_name,
|
||||
.d_flags = D_TTY | D_NEEDGIANT,
|
||||
};
|
||||
static t_close_t sioclose;
|
||||
static t_open_t sioopen;
|
||||
|
||||
int comconsole = -1;
|
||||
static volatile speed_t comdefaultrate = CONSPEED;
|
||||
@ -731,6 +688,10 @@ sysctl_machdep_comdefaultrate(SYSCTL_HANDLER_ARGS)
|
||||
if (tp == NULL)
|
||||
return (ENXIO);
|
||||
|
||||
tp = com->tp;
|
||||
if (tp == NULL)
|
||||
return (ENXIO);
|
||||
|
||||
/*
|
||||
* set the initial and lock rates for /dev/ttydXX and /dev/cuaXX
|
||||
* (note, the lock rates really are boolean -- if non-zero, disallow
|
||||
@ -741,9 +702,6 @@ sysctl_machdep_comdefaultrate(SYSCTL_HANDLER_ARGS)
|
||||
tp->t_init_out.c_ispeed = tp->t_init_out.c_ospeed =
|
||||
tp->t_lock_out.c_ispeed = tp->t_lock_out.c_ospeed = comdefaultrate;
|
||||
|
||||
/*
|
||||
* if we're open, change the running rate too
|
||||
*/
|
||||
if (tp->t_state & TS_ISOPEN) {
|
||||
tp->t_termios.c_ispeed =
|
||||
tp->t_termios.c_ospeed = comdefaultrate;
|
||||
@ -772,7 +730,6 @@ siodetach(dev)
|
||||
device_t dev;
|
||||
{
|
||||
struct com_s *com;
|
||||
int i;
|
||||
|
||||
com = (struct com_s *) device_get_softc(dev);
|
||||
if (com == NULL) {
|
||||
@ -782,8 +739,6 @@ siodetach(dev)
|
||||
com->gone = TRUE;
|
||||
if (com->tp)
|
||||
ttygone(com->tp);
|
||||
for (i = 0 ; i < 6; i++)
|
||||
destroy_dev(com->devs[i]);
|
||||
if (com->irqres) {
|
||||
bus_teardown_intr(dev, com->irqres, com->cookie);
|
||||
bus_release_resource(dev, SYS_RES_IRQ, 0, com->irqres);
|
||||
@ -793,8 +748,7 @@ siodetach(dev)
|
||||
com->ioportres);
|
||||
if (com->tp && (com->tp->t_state & TS_ISOPEN)) {
|
||||
device_printf(dev, "still open, forcing close\n");
|
||||
ttyld_close(com->tp, 0);
|
||||
tty_close(com->tp);
|
||||
ttyfree(com->tp);
|
||||
} else {
|
||||
if (com->ibuf != NULL)
|
||||
free(com->ibuf, M_DEVBUF);
|
||||
@ -803,6 +757,8 @@ siodetach(dev)
|
||||
free(com->obuf1, M_DEVBUF);
|
||||
#endif
|
||||
device_set_softc(dev, NULL);
|
||||
if (com->tp)
|
||||
ttyfree(com->tp);
|
||||
free(com, M_DEVBUF);
|
||||
}
|
||||
return (0);
|
||||
@ -1548,8 +1504,9 @@ sioattach(dev, xrid, rclk)
|
||||
com->line_status_port = iobase + com_lsr;
|
||||
com->modem_status_port = iobase + com_msr;
|
||||
#endif
|
||||
|
||||
tp = com->tp = ttyalloc();
|
||||
tp->t_open = sioopen;
|
||||
tp->t_close = sioclose;
|
||||
tp->t_oproc = comstart;
|
||||
tp->t_param = comparam;
|
||||
tp->t_stop = comstop;
|
||||
@ -1809,25 +1766,8 @@ determined_type: ;
|
||||
swi_add(&clk_ithd, "sio", siopoll, NULL, SWI_CLOCK, 0,
|
||||
&sio_slow_ih);
|
||||
}
|
||||
minorbase = UNIT_TO_MINOR(unit);
|
||||
com->devs[0] = make_dev(&sio_cdevsw, minorbase,
|
||||
UID_ROOT, GID_WHEEL, 0600, "ttyd%r", unit);
|
||||
com->devs[1] = make_dev(&sioc_cdevsw, minorbase | CONTROL_INIT_STATE,
|
||||
UID_ROOT, GID_WHEEL, 0600, "ttyid%r", unit);
|
||||
com->devs[2] = make_dev(&sioc_cdevsw, minorbase | CONTROL_LOCK_STATE,
|
||||
UID_ROOT, GID_WHEEL, 0600, "ttyld%r", unit);
|
||||
com->devs[3] = make_dev(&sio_cdevsw, minorbase | CALLOUT_MASK,
|
||||
UID_UUCP, GID_DIALER, 0660, "cuaa%r", unit);
|
||||
com->devs[4] = make_dev(&sioc_cdevsw,
|
||||
minorbase | CALLOUT_MASK | CONTROL_INIT_STATE,
|
||||
UID_UUCP, GID_DIALER, 0660, "cuaia%r", unit);
|
||||
com->devs[5] = make_dev(&sioc_cdevsw,
|
||||
minorbase | CALLOUT_MASK | CONTROL_LOCK_STATE,
|
||||
UID_UUCP, GID_DIALER, 0660, "cuala%r", unit);
|
||||
for (rid = 0; rid < 6; rid++) {
|
||||
com->devs[rid]->si_drv1 = com;
|
||||
com->devs[rid]->si_tty = tp;
|
||||
}
|
||||
minorbase = unit2minor(unit);
|
||||
ttycreate(tp, NULL, 0, MINOR_CALLOUT, "d%r", unit);
|
||||
com->flags = flags;
|
||||
com->pps.ppscap = PPS_CAPTUREASSERT | PPS_CAPTURECLEAR;
|
||||
|
||||
@ -1868,104 +1808,16 @@ determined_type: ;
|
||||
}
|
||||
|
||||
static int
|
||||
siocopen(dev, flag, mode, td)
|
||||
struct cdev *dev;
|
||||
int flag;
|
||||
int mode;
|
||||
struct thread *td;
|
||||
sioopen(struct tty *tp, struct cdev *dev)
|
||||
{
|
||||
struct com_s *com;
|
||||
|
||||
com = dev->si_drv1;
|
||||
if (com == NULL)
|
||||
return (ENXIO);
|
||||
if (com->gone)
|
||||
return (ENXIO);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
sioopen(dev, flag, mode, td)
|
||||
struct cdev *dev;
|
||||
int flag;
|
||||
int mode;
|
||||
struct thread *td;
|
||||
{
|
||||
struct com_s *com;
|
||||
int error;
|
||||
int mynor;
|
||||
int s;
|
||||
struct tty *tp;
|
||||
int unit;
|
||||
|
||||
mynor = minor(dev);
|
||||
unit = MINOR_TO_UNIT(mynor);
|
||||
com = dev->si_drv1;
|
||||
if (com == NULL)
|
||||
return (ENXIO);
|
||||
if (com->gone)
|
||||
return (ENXIO);
|
||||
tp = dev->si_tty = com->tp;
|
||||
s = spltty();
|
||||
/*
|
||||
* We jump to this label after all non-interrupted sleeps to pick
|
||||
* up any changes of the device state.
|
||||
*/
|
||||
open_top:
|
||||
error = ttydtrwaitsleep(tp);
|
||||
if (error != 0)
|
||||
goto out;
|
||||
if (tp->t_state & TS_ISOPEN) {
|
||||
/*
|
||||
* The device is open, so everything has been initialized.
|
||||
* Handle conflicts.
|
||||
*/
|
||||
if (mynor & CALLOUT_MASK) {
|
||||
if (!com->active_out) {
|
||||
error = EBUSY;
|
||||
goto out;
|
||||
}
|
||||
} else {
|
||||
if (com->active_out) {
|
||||
if (flag & O_NONBLOCK) {
|
||||
error = EBUSY;
|
||||
goto out;
|
||||
}
|
||||
error = tsleep(&com->active_out,
|
||||
TTIPRI | PCATCH, "siobi", 0);
|
||||
if (com_addr(unit) == NULL)
|
||||
return (ENXIO);
|
||||
if (error != 0 || com->gone)
|
||||
goto out;
|
||||
goto open_top;
|
||||
}
|
||||
}
|
||||
if (tp->t_state & TS_XCLUDE &&
|
||||
suser(td)) {
|
||||
error = EBUSY;
|
||||
goto out;
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* The device isn't open, so there are no conflicts.
|
||||
* Initialize it. Initialization is done twice in many
|
||||
* cases: to preempt sleeping callin opens if we are
|
||||
* callout, and to complete a callin open after DCD rises.
|
||||
*/
|
||||
tp->t_dev = dev;
|
||||
tp->t_termios = mynor & CALLOUT_MASK
|
||||
? tp->t_init_out : tp->t_init_in;
|
||||
com = tp->t_sc;
|
||||
#ifdef PC98
|
||||
if (!IS_8251(com->pc98_if_type))
|
||||
#endif
|
||||
(void)commodem(tp, SER_DTR | SER_RTS, 0);
|
||||
com->poll = com->no_irq;
|
||||
com->poll_output = com->loses_outints;
|
||||
++com->wopeners;
|
||||
error = comparam(tp, &tp->t_termios);
|
||||
--com->wopeners;
|
||||
if (error != 0)
|
||||
goto out;
|
||||
#ifdef PC98
|
||||
if (IS_8251(com->pc98_if_type)) {
|
||||
com_tiocm_bis(com, TIOCM_DTR|TIOCM_RTS);
|
||||
@ -2027,8 +1879,7 @@ sioopen(dev, flag, mode, td)
|
||||
(void) inb(com->data_port);
|
||||
}
|
||||
if (i == 500) {
|
||||
error = EIO;
|
||||
goto out;
|
||||
return (EIO);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2057,111 +1908,28 @@ sioopen(dev, flag, mode, td)
|
||||
}
|
||||
#endif
|
||||
mtx_unlock_spin(&sio_lock);
|
||||
/*
|
||||
* Handle initial DCD. Callout devices get a fake initial
|
||||
* DCD (trapdoor DCD). If we are callout, then any sleeping
|
||||
* callin opens get woken up and resume sleeping on "siobi"
|
||||
* instead of "siodcd".
|
||||
*/
|
||||
/*
|
||||
* XXX `mynor & CALLOUT_MASK' should be
|
||||
* `tp->t_cflag & (SOFT_CARRIER | TRAPDOOR_CARRIER) where
|
||||
* TRAPDOOR_CARRIER is the default initial state for callout
|
||||
* devices and SOFT_CARRIER is like CLOCAL except it hides
|
||||
* the true carrier.
|
||||
*/
|
||||
siosettimeout();
|
||||
#ifdef PC98
|
||||
if ((IS_8251(com->pc98_if_type) &&
|
||||
(pc98_get_modem_status(com) & TIOCM_CAR)) ||
|
||||
(!IS_8251(com->pc98_if_type) &&
|
||||
(com->prev_modem_status & MSR_DCD)) ||
|
||||
mynor & CALLOUT_MASK)
|
||||
ISCALLOUT(dev))
|
||||
ttyld_modem(tp, 1);
|
||||
#else
|
||||
if (com->prev_modem_status & MSR_DCD || mynor & CALLOUT_MASK)
|
||||
if (com->prev_modem_status & MSR_DCD || ISCALLOUT(dev))
|
||||
ttyld_modem(tp, 1);
|
||||
#endif
|
||||
}
|
||||
/*
|
||||
* Wait for DCD if necessary.
|
||||
*/
|
||||
if (!(tp->t_state & TS_CARR_ON) && !(mynor & CALLOUT_MASK)
|
||||
&& !(tp->t_cflag & CLOCAL) && !(flag & O_NONBLOCK)) {
|
||||
++com->wopeners;
|
||||
error = tsleep(TSA_CARR_ON(tp), TTIPRI | PCATCH, "siodcd", 0);
|
||||
if (com_addr(unit) == NULL)
|
||||
return (ENXIO);
|
||||
--com->wopeners;
|
||||
if (error != 0 || com->gone)
|
||||
goto out;
|
||||
goto open_top;
|
||||
}
|
||||
error = ttyld_open(tp, dev);
|
||||
ttyldoptim(tp);
|
||||
if (tp->t_state & TS_ISOPEN && mynor & CALLOUT_MASK)
|
||||
com->active_out = TRUE;
|
||||
siosettimeout();
|
||||
out:
|
||||
splx(s);
|
||||
if (!(tp->t_state & TS_ISOPEN) && com->wopeners == 0)
|
||||
comhardclose(com);
|
||||
return (error);
|
||||
}
|
||||
|
||||
static int
|
||||
siocclose(dev, flag, mode, td)
|
||||
struct cdev *dev;
|
||||
int flag;
|
||||
int mode;
|
||||
struct thread *td;
|
||||
{
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
sioclose(dev, flag, mode, td)
|
||||
struct cdev *dev;
|
||||
int flag;
|
||||
int mode;
|
||||
struct thread *td;
|
||||
{
|
||||
struct com_s *com;
|
||||
int s;
|
||||
struct tty *tp;
|
||||
|
||||
com = dev->si_drv1;
|
||||
if (com == NULL)
|
||||
return (ENODEV);
|
||||
tp = com->tp;
|
||||
s = spltty();
|
||||
ttyld_close(tp, flag);
|
||||
#ifdef PC98
|
||||
com->modem_checking = 0;
|
||||
#endif
|
||||
ttyldoptim(tp);
|
||||
comhardclose(com);
|
||||
tty_close(tp);
|
||||
siosettimeout();
|
||||
splx(s);
|
||||
if (com->gone) {
|
||||
printf("sio%d: gone\n", com->unit);
|
||||
s = spltty();
|
||||
if (com->ibuf != NULL)
|
||||
free(com->ibuf, M_DEVBUF);
|
||||
bzero(tp, sizeof *tp);
|
||||
splx(s);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
comhardclose(com)
|
||||
struct com_s *com;
|
||||
sioclose(struct tty *tp)
|
||||
{
|
||||
struct com_s *com;
|
||||
int s;
|
||||
struct tty *tp;
|
||||
|
||||
com = tp->t_sc;
|
||||
s = spltty();
|
||||
com->poll = FALSE;
|
||||
com->poll_output = FALSE;
|
||||
@ -2172,7 +1940,6 @@ comhardclose(com)
|
||||
#else
|
||||
sio_setreg(com, com_cfcr, com->cfcr_image &= ~CFCR_SBREAK);
|
||||
#endif
|
||||
tp = com->tp;
|
||||
|
||||
#if defined(KDB) && (defined(BREAK_TO_DEBUGGER) || \
|
||||
defined(ALT_BREAK_TO_DEBUGGER))
|
||||
@ -2207,7 +1974,7 @@ comhardclose(com)
|
||||
* the next open because it might go up and down while
|
||||
* we're not watching.
|
||||
*/
|
||||
|| (!com->active_out
|
||||
|| (!tp->t_actout
|
||||
#ifdef PC98
|
||||
&& !(tmp)
|
||||
#else
|
||||
@ -2245,63 +2012,12 @@ comhardclose(com)
|
||||
*/
|
||||
sio_setreg(com, com_fifo, 0);
|
||||
}
|
||||
com->active_out = FALSE;
|
||||
wakeup(&com->active_out);
|
||||
tp->t_actout = FALSE;
|
||||
wakeup(&tp->t_actout);
|
||||
wakeup(TSA_CARR_ON(tp)); /* restart any wopeners */
|
||||
splx(s);
|
||||
}
|
||||
|
||||
static int
|
||||
siocrdwr(dev, uio, flag)
|
||||
struct cdev *dev;
|
||||
struct uio *uio;
|
||||
int flag;
|
||||
{
|
||||
|
||||
return (ENODEV);
|
||||
}
|
||||
|
||||
static int
|
||||
sioread(dev, uio, flag)
|
||||
struct cdev *dev;
|
||||
struct uio *uio;
|
||||
int flag;
|
||||
{
|
||||
struct com_s *com;
|
||||
|
||||
com = dev->si_drv1;
|
||||
if (com == NULL || com->gone)
|
||||
return (ENODEV);
|
||||
return (ttyld_read(com->tp, uio, flag));
|
||||
}
|
||||
|
||||
static int
|
||||
siowrite(dev, uio, flag)
|
||||
struct cdev *dev;
|
||||
struct uio *uio;
|
||||
int flag;
|
||||
{
|
||||
int mynor;
|
||||
struct com_s *com;
|
||||
int unit;
|
||||
|
||||
mynor = minor(dev);
|
||||
|
||||
unit = MINOR_TO_UNIT(mynor);
|
||||
com = dev->si_drv1;
|
||||
if (com == NULL || com->gone)
|
||||
return (ENODEV);
|
||||
/*
|
||||
* (XXX) We disallow virtual consoles if the physical console is
|
||||
* a serial port. This is in case there is a display attached that
|
||||
* is not the console. In that situation we don't need/want the X
|
||||
* server taking over the console.
|
||||
*/
|
||||
if (constty != NULL && unit == comconsole)
|
||||
constty = NULL;
|
||||
return (ttyld_write(com->tp, uio, flag));
|
||||
}
|
||||
|
||||
static void
|
||||
siobusycheck(chan)
|
||||
void *chan;
|
||||
@ -2953,136 +2669,6 @@ if (com->iptr - com->ibuf == 8)
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
siocioctl(dev, cmd, data, flag, td)
|
||||
struct cdev *dev;
|
||||
u_long cmd;
|
||||
caddr_t data;
|
||||
int flag;
|
||||
struct thread *td;
|
||||
{
|
||||
struct com_s *com;
|
||||
struct tty *tp;
|
||||
int error;
|
||||
int mynor;
|
||||
struct termios *ct;
|
||||
|
||||
mynor = minor(dev);
|
||||
com = dev->si_drv1;
|
||||
if (com == NULL || com->gone)
|
||||
return (ENODEV);
|
||||
tp = com->tp;
|
||||
|
||||
switch (mynor & CONTROL_MASK) {
|
||||
case CONTROL_INIT_STATE:
|
||||
ct = mynor & CALLOUT_MASK ? &tp->t_init_out : &tp->t_init_in;
|
||||
break;
|
||||
case CONTROL_LOCK_STATE:
|
||||
ct = mynor & CALLOUT_MASK ? &tp->t_lock_out : &tp->t_lock_in;
|
||||
break;
|
||||
default:
|
||||
return (ENODEV); /* /dev/nodev */
|
||||
}
|
||||
switch (cmd) {
|
||||
case TIOCSETA:
|
||||
error = suser(td);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
*ct = *(struct termios *)data;
|
||||
return (0);
|
||||
case TIOCGETA:
|
||||
*(struct termios *)data = *ct;
|
||||
return (0);
|
||||
case TIOCGETD:
|
||||
*(int *)data = TTYDISC;
|
||||
return (0);
|
||||
case TIOCGWINSZ:
|
||||
bzero(data, sizeof(struct winsize));
|
||||
return (0);
|
||||
default:
|
||||
return (ENOTTY);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
sioioctl(dev, cmd, data, flag, td)
|
||||
struct cdev *dev;
|
||||
u_long cmd;
|
||||
caddr_t data;
|
||||
int flag;
|
||||
struct thread *td;
|
||||
{
|
||||
struct com_s *com;
|
||||
int error;
|
||||
int mynor;
|
||||
int s;
|
||||
struct tty *tp;
|
||||
#ifndef BURN_BRIDGES
|
||||
#if defined(COMPAT_43)
|
||||
u_long oldcmd;
|
||||
struct termios term;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
mynor = minor(dev);
|
||||
com = dev->si_drv1;
|
||||
if (com == NULL || com->gone)
|
||||
return (ENODEV);
|
||||
tp = com->tp;
|
||||
#ifndef BURN_BRIDGES
|
||||
#if defined(COMPAT_43)
|
||||
term = tp->t_termios;
|
||||
oldcmd = cmd;
|
||||
error = ttsetcompat(tp, &cmd, data, &term);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
if (cmd != oldcmd)
|
||||
data = (caddr_t)&term;
|
||||
#endif
|
||||
#endif
|
||||
if (cmd == TIOCSETA || cmd == TIOCSETAW || cmd == TIOCSETAF) {
|
||||
int cc;
|
||||
struct termios *dt = (struct termios *)data;
|
||||
struct termios *lt = mynor & CALLOUT_MASK
|
||||
? &tp->t_lock_out : &tp->t_lock_in;
|
||||
|
||||
dt->c_iflag = (tp->t_iflag & lt->c_iflag)
|
||||
| (dt->c_iflag & ~lt->c_iflag);
|
||||
dt->c_oflag = (tp->t_oflag & lt->c_oflag)
|
||||
| (dt->c_oflag & ~lt->c_oflag);
|
||||
dt->c_cflag = (tp->t_cflag & lt->c_cflag)
|
||||
| (dt->c_cflag & ~lt->c_cflag);
|
||||
dt->c_lflag = (tp->t_lflag & lt->c_lflag)
|
||||
| (dt->c_lflag & ~lt->c_lflag);
|
||||
for (cc = 0; cc < NCCS; ++cc)
|
||||
if (lt->c_cc[cc] != 0)
|
||||
dt->c_cc[cc] = tp->t_cc[cc];
|
||||
if (lt->c_ispeed != 0)
|
||||
dt->c_ispeed = tp->t_ispeed;
|
||||
if (lt->c_ospeed != 0)
|
||||
dt->c_ospeed = tp->t_ospeed;
|
||||
}
|
||||
error = ttyioctl(dev, cmd, data, flag, td);
|
||||
ttyldoptim(tp);
|
||||
if (error != ENOTTY)
|
||||
return (error);
|
||||
s = spltty();
|
||||
switch (cmd) {
|
||||
case TIOCTIMESTAMP:
|
||||
com->do_timestamp = TRUE;
|
||||
*(struct timeval *)data = com->timestamp;
|
||||
break;
|
||||
default:
|
||||
splx(s);
|
||||
error = pps_ioctl(cmd, data, &com->pps);
|
||||
if (error == ENODEV)
|
||||
error = ENOTTY;
|
||||
return (error);
|
||||
}
|
||||
splx(s);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* software interrupt handler for SWI_TTY */
|
||||
static void
|
||||
siopoll(void *dummy)
|
||||
@ -3858,9 +3444,7 @@ commint(struct cdev *dev)
|
||||
register struct tty *tp;
|
||||
int stat,delta;
|
||||
struct com_s *com;
|
||||
int mynor;
|
||||
|
||||
mynor = minor(dev);
|
||||
com = dev->si_drv1;
|
||||
tp = com->tp;
|
||||
|
||||
@ -3873,7 +3457,7 @@ commint(struct cdev *dev)
|
||||
else
|
||||
com->state &= ~CS_ODEVREADY;
|
||||
}
|
||||
if ((delta & TIOCM_CAR) && (mynor & CALLOUT_MASK) == 0) {
|
||||
if ((delta & TIOCM_CAR) && (ISCALLOUT(dev)) == 0) {
|
||||
if (stat & TIOCM_CAR )
|
||||
(void)ttyld_modem(tp, 1);
|
||||
else if (ttyld_modem(tp, 0) == 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user