summaryrefslogtreecommitdiff
path: root/sys/dev/isa/com.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/dev/isa/com.c')
-rw-r--r--sys/dev/isa/com.c51
1 files changed, 38 insertions, 13 deletions
diff --git a/sys/dev/isa/com.c b/sys/dev/isa/com.c
index ffbdb55bc7d..2f0aa29facf 100644
--- a/sys/dev/isa/com.c
+++ b/sys/dev/isa/com.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: com.c,v 1.20 1996/07/02 09:47:46 downsj Exp $ */
+/* $OpenBSD: com.c,v 1.21 1996/08/29 12:58:30 deraadt Exp $ */
/* $NetBSD: com.c,v 1.82.4.1 1996/06/02 09:08:00 mrg Exp $ */
/*-
@@ -111,6 +111,8 @@ struct com_softc {
u_char sc_msr, sc_mcr, sc_lcr, sc_ier;
u_char sc_dtr;
+ u_char sc_cua;
+
u_char *sc_ibuf, *sc_ibufp, *sc_ibufhigh, *sc_ibufend;
u_char sc_ibufs[2][COM_IBUFSIZE];
};
@@ -191,7 +193,8 @@ extern int kgdb_rate;
extern int kgdb_debug_init;
#endif
-#define COMUNIT(x) (minor(x))
+#define DEVUNIT(x) (minor(x) & 0x7f)
+#define DEVCUA(x) (minor(x) & 0x80)
/* Macros to clear/set/test flags. */
#define SET(t, f) (t) |= (f)
@@ -743,7 +746,7 @@ comopen(dev, flag, mode, p)
int flag, mode;
struct proc *p;
{
- int unit = COMUNIT(dev);
+ int unit = DEVUNIT(dev);
struct com_softc *sc;
bus_chipset_tag_t bc;
bus_io_handle_t ioh;
@@ -757,11 +760,13 @@ comopen(dev, flag, mode, p)
if (!sc || ISSET(sc->sc_hwflags, COM_HW_ABSENT|COM_HW_ABSENT_PENDING))
return ENXIO;
+ s = spltty();
if (!sc->sc_tty) {
tp = sc->sc_tty = ttymalloc();
tty_attach(tp);
} else
tp = sc->sc_tty;
+ splx(s);
tp->t_oproc = comstart;
tp->t_param = comparam;
@@ -869,7 +874,7 @@ comopen(dev, flag, mode, p)
bus_io_write_1(bc, ioh, com_ier, sc->sc_ier);
sc->sc_msr = bus_io_read_1(bc, ioh, com_msr);
- if (ISSET(sc->sc_swflags, COM_SW_SOFTCAR) ||
+ if (ISSET(sc->sc_swflags, COM_SW_SOFTCAR) || DEVCUA(dev) ||
ISSET(sc->sc_msr, MSR_DCD) || ISSET(tp->t_cflag, MDMBUF))
SET(tp->t_state, TS_CARR_ON);
else
@@ -879,9 +884,25 @@ comopen(dev, flag, mode, p)
else
s = spltty();
+ if (DEVCUA(dev)) {
+ if (ISSET(tp->t_state, TS_ISOPEN)) {
+ /* Ah, but someone already is dialed in... */
+ splx(s);
+ return EBUSY;
+ }
+ sc->sc_cua = 1; /* We go into CUA mode */
+ }
+
/* wait for carrier if necessary */
- if (!ISSET(flag, O_NONBLOCK))
- while (!ISSET(tp->t_cflag, CLOCAL) &&
+ if (ISSET(flag, O_NONBLOCK)) {
+ if (!DEVCUA(dev) && sc->sc_cua) {
+ /* Opening TTY non-blocking... but the CUA is busy */
+ splx(s);
+ return EBUSY;
+ }
+ } else {
+ while (!(DEVCUA(dev) && sc->sc_cua) &&
+ !ISSET(tp->t_cflag, CLOCAL) &&
!ISSET(tp->t_state, TS_CARR_ON)) {
SET(tp->t_state, TS_WOPEN);
error = ttysleep(tp, &tp->t_rawq, TTIPRI | PCATCH,
@@ -889,10 +910,13 @@ comopen(dev, flag, mode, p)
if (error) {
/* XXX should turn off chip if we're the
only waiter */
+ if (DEVCUA(dev))
+ sc->sc_cua = 0;
splx(s);
return error;
}
}
+ }
splx(s);
return (*linesw[tp->t_line].l_open)(dev, tp);
@@ -904,7 +928,7 @@ comclose(dev, flag, mode, p)
int flag, mode;
struct proc *p;
{
- int unit = COMUNIT(dev);
+ int unit = DEVUNIT(dev);
struct com_softc *sc = com_cd.cd_devs[unit];
struct tty *tp = sc->sc_tty;
bus_chipset_tag_t bc = sc->sc_bc;
@@ -931,6 +955,7 @@ comclose(dev, flag, mode, p)
CLR(tp->t_state, TS_BUSY | TS_FLUSH);
if (--comsopen == 0)
untimeout(compoll, NULL);
+ sc->sc_cua = 0;
splx(s);
ttyclose(tp);
#ifdef COM_DEBUG
@@ -956,7 +981,7 @@ comread(dev, uio, flag)
struct uio *uio;
int flag;
{
- struct com_softc *sc = com_cd.cd_devs[COMUNIT(dev)];
+ struct com_softc *sc = com_cd.cd_devs[DEVUNIT(dev)];
struct tty *tp = sc->sc_tty;
if (ISSET(sc->sc_hwflags, COM_HW_ABSENT|COM_HW_ABSENT_PENDING)) {
@@ -975,7 +1000,7 @@ comwrite(dev, uio, flag)
struct uio *uio;
int flag;
{
- struct com_softc *sc = com_cd.cd_devs[COMUNIT(dev)];
+ struct com_softc *sc = com_cd.cd_devs[DEVUNIT(dev)];
struct tty *tp = sc->sc_tty;
if (ISSET(sc->sc_hwflags, COM_HW_ABSENT|COM_HW_ABSENT_PENDING)) {
@@ -992,7 +1017,7 @@ struct tty *
comtty(dev)
dev_t dev;
{
- struct com_softc *sc = com_cd.cd_devs[COMUNIT(dev)];
+ struct com_softc *sc = com_cd.cd_devs[DEVUNIT(dev)];
struct tty *tp = sc->sc_tty;
return (tp);
@@ -1019,7 +1044,7 @@ comioctl(dev, cmd, data, flag, p)
int flag;
struct proc *p;
{
- int unit = COMUNIT(dev);
+ int unit = DEVUNIT(dev);
struct com_softc *sc = com_cd.cd_devs[unit];
struct tty *tp = sc->sc_tty;
bus_chipset_tag_t bc = sc->sc_bc;
@@ -1139,7 +1164,7 @@ comparam(tp, t)
struct tty *tp;
struct termios *t;
{
- struct com_softc *sc = com_cd.cd_devs[COMUNIT(tp->t_dev)];
+ struct com_softc *sc = com_cd.cd_devs[DEVUNIT(tp->t_dev)];
bus_chipset_tag_t bc = sc->sc_bc;
bus_io_handle_t ioh = sc->sc_ioh;
int ospeed = comspeed(t->c_ospeed);
@@ -1297,7 +1322,7 @@ void
comstart(tp)
struct tty *tp;
{
- struct com_softc *sc = com_cd.cd_devs[COMUNIT(tp->t_dev)];
+ struct com_softc *sc = com_cd.cd_devs[DEVUNIT(tp->t_dev)];
bus_chipset_tag_t bc = sc->sc_bc;
bus_io_handle_t ioh = sc->sc_ioh;
int s;