From owner-svn-src-all@freebsd.org Tue Jan 19 23:34:29 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 52CC9A88A87; Tue, 19 Jan 2016 23:34:29 +0000 (UTC) (envelope-from marius@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 2FBEC1337; Tue, 19 Jan 2016 23:34:29 +0000 (UTC) (envelope-from marius@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u0JNYSjn080957; Tue, 19 Jan 2016 23:34:28 GMT (envelope-from marius@FreeBSD.org) Received: (from marius@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u0JNYST5080954; Tue, 19 Jan 2016 23:34:28 GMT (envelope-from marius@FreeBSD.org) Message-Id: <201601192334.u0JNYST5080954@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: marius set sender to marius@FreeBSD.org using -f From: Marius Strobl Date: Tue, 19 Jan 2016 23:34:28 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r294362 - in head/sys: dev/uart kern sys X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 Jan 2016 23:34:29 -0000 Author: marius Date: Tue Jan 19 23:34:27 2016 New Revision: 294362 URL: https://svnweb.freebsd.org/changeset/base/294362 Log: 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 Modified: head/sys/dev/uart/uart_tty.c head/sys/kern/tty.c head/sys/sys/ttydevsw.h Modified: head/sys/dev/uart/uart_tty.c ============================================================================== --- head/sys/dev/uart/uart_tty.c Tue Jan 19 23:28:18 2016 (r294361) +++ head/sys/dev/uart/uart_tty.c Tue Jan 19 23:34:27 2016 (r294362) @@ -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 Modified: head/sys/kern/tty.c ============================================================================== --- head/sys/kern/tty.c Tue Jan 19 23:28:18 2016 (r294361) +++ head/sys/kern/tty.c Tue Jan 19 23:34:27 2016 (r294362) @@ -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, vo 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); Modified: head/sys/sys/ttydevsw.h ============================================================================== --- head/sys/sys/ttydevsw.h Tue Jan 19 23:28:18 2016 (r294361) +++ head/sys/sys/ttydevsw.h Tue Jan 19 23:34:27 2016 (r294362) @@ -54,6 +54,7 @@ typedef int tsw_mmap_t(struct tty *tp, v 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_ */