From owner-svn-src-head@FreeBSD.ORG Sun Aug 23 08:04:40 2009 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 863541065692; Sun, 23 Aug 2009 08:04:40 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 756C98FC1D; Sun, 23 Aug 2009 08:04:40 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n7N84eZY051322; Sun, 23 Aug 2009 08:04:40 GMT (envelope-from ed@svn.freebsd.org) Received: (from ed@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n7N84efJ051317; Sun, 23 Aug 2009 08:04:40 GMT (envelope-from ed@svn.freebsd.org) Message-Id: <200908230804.n7N84efJ051317@svn.freebsd.org> From: Ed Schouten Date: Sun, 23 Aug 2009 08:04:40 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r196452 - in head/sys: dev/snp kern sys X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 23 Aug 2009 08:04:40 -0000 Author: ed Date: Sun Aug 23 08:04:40 2009 New Revision: 196452 URL: http://svn.freebsd.org/changeset/base/196452 Log: Add ttydisc_rint_simple(). I noticed several drivers in our tree don't actually care about parity and framing, such as pts(4), snp(4) (and my partially finished console driver). Instead of duplicating a lot of code, I think we'd better add a utility function for those drivers to quickly process a buffer of input. Also change pts(4) and snp(4) to use this function. Modified: head/sys/dev/snp/snp.c head/sys/kern/tty_pts.c head/sys/kern/tty_ttydisc.c head/sys/sys/ttydisc.h Modified: head/sys/dev/snp/snp.c ============================================================================== --- head/sys/dev/snp/snp.c Sun Aug 23 07:59:28 2009 (r196451) +++ head/sys/dev/snp/snp.c Sun Aug 23 08:04:40 2009 (r196452) @@ -192,7 +192,7 @@ snp_write(struct cdev *dev, struct uio * { struct snp_softc *ss; struct tty *tp; - int error, len, i; + int error, len; char in[SNP_INPUT_BUFSIZE]; error = devfs_get_cdevpriv((void **)&ss); @@ -223,14 +223,9 @@ snp_write(struct cdev *dev, struct uio * * because we shouldn't bail out when we're running * close to the watermarks. */ - if (ttydisc_can_bypass(tp)) { - ttydisc_rint_bypass(tp, in, len); - } else { - for (i = 0; i < len; i++) - ttydisc_rint(tp, in[i], 0); - } - + ttydisc_rint_simple(tp, in, len); ttydisc_rint_done(tp); + tty_unlock(tp); } Modified: head/sys/kern/tty_pts.c ============================================================================== --- head/sys/kern/tty_pts.c Sun Aug 23 07:59:28 2009 (r196451) +++ head/sys/kern/tty_pts.c Sun Aug 23 08:04:40 2009 (r196452) @@ -215,25 +215,12 @@ ptsdev_write(struct file *fp, struct uio */ MPASS(iblen > 0); do { - if (ttydisc_can_bypass(tp)) { - /* Store data at once. */ - rintlen = ttydisc_rint_bypass(tp, - ibstart, iblen); - ibstart += rintlen; - iblen -= rintlen; - - if (iblen == 0) { - /* All data written. */ - break; - } - } else { - error = ttydisc_rint(tp, *ibstart, 0); - if (error == 0) { - /* Character stored successfully. */ - ibstart++; - iblen--; - continue; - } + rintlen = ttydisc_rint_simple(tp, ibstart, iblen); + ibstart += rintlen; + iblen -= rintlen; + if (iblen == 0) { + /* All data written. */ + break; } /* Maybe the device isn't used anyway. */ Modified: head/sys/kern/tty_ttydisc.c ============================================================================== --- head/sys/kern/tty_ttydisc.c Sun Aug 23 07:59:28 2009 (r196451) +++ head/sys/kern/tty_ttydisc.c Sun Aug 23 08:04:40 2009 (r196452) @@ -1045,6 +1045,22 @@ print: } size_t +ttydisc_rint_simple(struct tty *tp, const void *buf, size_t len) +{ + const char *cbuf; + + if (ttydisc_can_bypass(tp)) + return (ttydisc_rint_bypass(tp, buf, len)); + + for (cbuf = buf; len-- > 0; cbuf++) { + if (ttydisc_rint(tp, *cbuf, 0) != 0) + break; + } + + return (cbuf - (const char *)buf); +} + +size_t ttydisc_rint_bypass(struct tty *tp, const void *buf, size_t len) { size_t ret; Modified: head/sys/sys/ttydisc.h ============================================================================== --- head/sys/sys/ttydisc.h Sun Aug 23 07:59:28 2009 (r196451) +++ head/sys/sys/ttydisc.h Sun Aug 23 08:04:40 2009 (r196452) @@ -52,6 +52,7 @@ void ttydisc_optimize(struct tty *tp); void ttydisc_modem(struct tty *tp, int open); #define ttydisc_can_bypass(tp) ((tp)->t_flags & TF_BYPASS) int ttydisc_rint(struct tty *tp, char c, int flags); +size_t ttydisc_rint_simple(struct tty *tp, const void *buf, size_t len); size_t ttydisc_rint_bypass(struct tty *tp, const void *buf, size_t len); void ttydisc_rint_done(struct tty *tp); size_t ttydisc_rint_poll(struct tty *tp);