summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormarius <marius@FreeBSD.org>2016-01-19 23:34:27 +0000
committermarius <marius@FreeBSD.org>2016-01-19 23:34:27 +0000
commitc9d9d68baea4279c304cbaf81d85d4f33b6a6ddb (patch)
tree317f9c0bd52607efdfd2f6c62f25b5b2aa3842e2
parent4298849ab05ffb3fad1bbaf9c59bfa455c4b7565 (diff)
downloadFreeBSD-src-c9d9d68baea4279c304cbaf81d85d4f33b6a6ddb.zip
FreeBSD-src-c9d9d68baea4279c304cbaf81d85d4f33b6a6ddb.tar.gz
Fix tty_drain() and, thus, TIOCDRAIN of the current tty(4) incarnation
to actually wait until the TX FIFOs of UARTs have be drained before returning. This is done by bringing the equivalent of the TS_BUSY flag found in the previous implementation back in an ABI-preserving way. Reported and tested by: Patrick Powell Most likely, drivers for USB-serial-adapters likewise incorporating TX FIFOs as well as other terminal devices that buffer output in some form should also provide implementations of tsw_busy. MFC after: 3 days
-rw-r--r--sys/dev/uart/uart_tty.c13
-rw-r--r--sys/kern/tty.c12
-rw-r--r--sys/sys/ttydevsw.h14
3 files changed, 36 insertions, 3 deletions
diff --git a/sys/dev/uart/uart_tty.c b/sys/dev/uart/uart_tty.c
index ada4927..6b526ae 100644
--- a/sys/dev/uart/uart_tty.c
+++ b/sys/dev/uart/uart_tty.c
@@ -355,6 +355,18 @@ uart_tty_free(void *arg)
*/
}
+static bool
+uart_tty_busy(struct tty *tp)
+{
+ struct uart_softc *sc;
+
+ sc = tty_softc(tp);
+ if (sc == NULL || sc->sc_leaving)
+ return (FALSE);
+
+ return (sc->sc_txbusy);
+}
+
static struct ttydevsw uart_tty_class = {
.tsw_flags = TF_INITLOCK|TF_CALLOUT,
.tsw_open = uart_tty_open,
@@ -365,6 +377,7 @@ static struct ttydevsw uart_tty_class = {
.tsw_param = uart_tty_param,
.tsw_modem = uart_tty_modem,
.tsw_free = uart_tty_free,
+ .tsw_busy = uart_tty_busy,
};
int
diff --git a/sys/kern/tty.c b/sys/kern/tty.c
index 9695312..1dc6af2 100644
--- a/sys/kern/tty.c
+++ b/sys/kern/tty.c
@@ -132,11 +132,11 @@ tty_drain(struct tty *tp, int leaving)
/* buffer is inaccessible */
return (0);
- while (ttyoutq_bytesused(&tp->t_outq) > 0) {
+ while (ttyoutq_bytesused(&tp->t_outq) > 0 || ttydevsw_busy(tp)) {
ttydevsw_outwakeup(tp);
/* Could be handled synchronously. */
bytesused = ttyoutq_bytesused(&tp->t_outq);
- if (bytesused == 0)
+ if (bytesused == 0 && !ttydevsw_busy(tp))
return (0);
/* Wait for data to be drained. */
@@ -955,6 +955,13 @@ ttydevsw_deffree(void *softc)
panic("Terminal device freed without a free-handler");
}
+static bool
+ttydevsw_defbusy(struct tty *tp __unused)
+{
+
+ return (FALSE);
+}
+
/*
* TTY allocation and deallocation. TTY devices can be deallocated when
* the driver doesn't use it anymore, when the TTY isn't a session's
@@ -989,6 +996,7 @@ tty_alloc_mutex(struct ttydevsw *tsw, void *sc, struct mtx *mutex)
PATCH_FUNC(mmap);
PATCH_FUNC(pktnotify);
PATCH_FUNC(free);
+ PATCH_FUNC(busy);
#undef PATCH_FUNC
tp = malloc(sizeof(struct tty), M_TTY, M_WAITOK|M_ZERO);
diff --git a/sys/sys/ttydevsw.h b/sys/sys/ttydevsw.h
index 748ae0b..ae70613 100644
--- a/sys/sys/ttydevsw.h
+++ b/sys/sys/ttydevsw.h
@@ -54,6 +54,7 @@ typedef int tsw_mmap_t(struct tty *tp, vm_ooffset_t offset,
vm_paddr_t * paddr, int nprot, vm_memattr_t *memattr);
typedef void tsw_pktnotify_t(struct tty *tp, char event);
typedef void tsw_free_t(void *softc);
+typedef bool tsw_busy_t(struct tty *tp);
struct ttydevsw {
unsigned int tsw_flags; /* Default TTY flags. */
@@ -74,7 +75,9 @@ struct ttydevsw {
tsw_free_t *tsw_free; /* Destructor. */
- void *tsw_spare[4]; /* For future use. */
+ tsw_busy_t *tsw_busy; /* Draining output. */
+
+ void *tsw_spare[3]; /* For future use. */
};
static __inline int
@@ -181,4 +184,13 @@ ttydevsw_free(struct tty *tp)
tp->t_devsw->tsw_free(tty_softc(tp));
}
+static __inline bool
+ttydevsw_busy(struct tty *tp)
+{
+
+ MPASS(tty_gone(tp));
+
+ return (tp->t_devsw->tsw_busy(tp));
+}
+
#endif /* !_SYS_TTYDEVSW_H_ */
OpenPOWER on IntegriCloud