From owner-p4-projects@FreeBSD.ORG Thu Oct 23 19:41:18 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id A1CA11065675; Thu, 23 Oct 2008 19:41:18 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4D2A51065671 for ; Thu, 23 Oct 2008 19:41:18 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 3B0828FC16 for ; Thu, 23 Oct 2008 19:41:18 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id m9NJfIu7088138 for ; Thu, 23 Oct 2008 19:41:18 GMT (envelope-from ed@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id m9NJfIx5088136 for perforce@freebsd.org; Thu, 23 Oct 2008 19:41:18 GMT (envelope-from ed@FreeBSD.org) Date: Thu, 23 Oct 2008 19:41:18 GMT Message-Id: <200810231941.m9NJfIx5088136@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to ed@FreeBSD.org using -f From: Ed Schouten To: Perforce Change Reviews Cc: Subject: PERFORCE change 151826 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Oct 2008 19:41:18 -0000 http://perforce.freebsd.org/chv.cgi?CH=151826 Change 151826 by ed@ed_dull on 2008/10/23 19:40:40 Add a mockup for a replacement clist interface. Affected files ... .. //depot/projects/mpsafetty/sys/dev/kbd/kbd.c#5 edit .. //depot/projects/mpsafetty/sys/dev/usb/ugen.c#5 edit .. //depot/projects/mpsafetty/sys/dev/usb/uhid.c#5 edit .. //depot/projects/mpsafetty/sys/sys/clist.h#6 add Differences ... ==== //depot/projects/mpsafetty/sys/dev/kbd/kbd.c#5 (text+ko) ==== @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -557,7 +558,7 @@ #if 0 bzero(&sc->gkb_q, sizeof(sc->gkb_q)); #endif - clist_alloc_cblocks(&sc->gkb_q, KB_QSIZE, KB_QSIZE/2); /* XXX */ + clist_alloc(&sc->gkb_q, KB_QSIZE); splx(s); return (0); @@ -607,7 +608,7 @@ splx(s); return (ENXIO); } - while (sc->gkb_q.c_cc == 0) { + while (clist_usage(&sc->gkb_q) == 0) { if (flag & O_NONBLOCK) { splx(s); return (EWOULDBLOCK); @@ -631,7 +632,7 @@ error = 0; while (uio->uio_resid > 0) { len = imin(uio->uio_resid, sizeof(buffer)); - len = q_to_b(&sc->gkb_q, buffer, len); + len = clist_read(&sc->gkb_q, buffer, len); if (len <= 0) break; error = uiomove(buffer, len, uio); @@ -683,7 +684,7 @@ if ((sc == NULL) || (kbd == NULL) || !KBD_IS_VALID(kbd)) { revents = POLLHUP; /* the keyboard has gone */ } else if (events & (POLLIN | POLLRDNORM)) { - if (sc->gkb_q.c_cc > 0) + if (clist_usage(&sc->gkb_q) > 0) revents = events & (POLLIN | POLLRDNORM); else selrecord(td, &sc->gkb_rsel); @@ -700,6 +701,7 @@ u_char *cp; int mode; int c; + char cq[3]; /* assert(KBD_IS_VALID(kbd)) */ sc = (genkbd_softc_t *)arg; @@ -737,7 +739,8 @@ /* store the byte as is for K_RAW and K_CODE modes */ if (mode != K_XLATE) { - putc(KEYCHAR(c), &sc->gkb_q); + cq[0] = KEYCHAR(c); + clist_write(&sc->gkb_q, cq, 1); continue; } @@ -752,9 +755,10 @@ /* ignore them... */ continue; case BTAB: /* a backtab: ESC [ Z */ - putc(0x1b, &sc->gkb_q); - putc('[', &sc->gkb_q); - putc('Z', &sc->gkb_q); + cq[0] = 0x1b; + cq[1] = '['; + cq[2] = 'Z'; + clist_write(&sc->gkb_q, cq, 3); continue; } } @@ -762,24 +766,24 @@ /* normal chars, normal chars with the META, function keys */ switch (KEYFLAGS(c)) { case 0: /* a normal char */ - putc(KEYCHAR(c), &sc->gkb_q); + cq[0] = KEYCHAR(c); + clist_write(&sc->gkb_q, cq, 1); break; case MKEY: /* the META flag: prepend ESC */ - putc(0x1b, &sc->gkb_q); - putc(KEYCHAR(c), &sc->gkb_q); + cq[0] = 0x1b; + cq[1] = KEYCHAR(c); + clist_write(&sc->gkb_q, cq, 2); break; case FKEY | SPCLKEY: /* a function key, return string */ cp = kbdd_get_fkeystr(kbd, KEYCHAR(c), &len); - if (cp != NULL) { - while (len-- > 0) - putc(*cp++, &sc->gkb_q); - } + if (cp != NULL) + clist_write(&sc->gkb_q, cp, len); break; } } /* wake up sleeping/polling processes */ - if (sc->gkb_q.c_cc > 0) { + if (clist_usage(&sc->gkb_q) > 0) { if (sc->gkb_flags & KB_ASLEEP) { sc->gkb_flags &= ~KB_ASLEEP; wakeup(sc); ==== //depot/projects/mpsafetty/sys/dev/usb/ugen.c#5 (text+ko) ==== @@ -50,6 +50,7 @@ #include #include +#include #include #include #include @@ -528,9 +529,7 @@ sce->ibuf = malloc(isize, M_USBDEV, M_WAITOK); DPRINTFN(5, ("ugenopen: intr endpt=%d,isize=%d\n", endpt, isize)); - if ((clist_alloc_cblocks(&sce->q, UGEN_IBSIZE, - UGEN_IBSIZE), 0) == -1) - return (ENOMEM); + clist_alloc(&sce->q, UGEN_IBSIZE); err = usbd_open_pipe_intr(sce->iface, edesc->bEndpointAddress, USBD_SHORT_XFER_OK, &sce->pipeh, sce, @@ -538,7 +537,7 @@ USBD_DEFAULT_INTERVAL); if (err) { free(sce->ibuf, M_USBDEV); - clist_free_cblocks(&sce->q); + clist_free(&sce->q); return (EIO); } DPRINTFN(5, ("ugenopen: interrupt open done\n")); @@ -648,8 +647,7 @@ switch (sce->edesc->bmAttributes & UE_XFERTYPE) { case UE_INTERRUPT: - ndflush(&sce->q, sce->q.c_cc); - clist_free_cblocks(&sce->q); + clist_free(&sce->q); break; case UE_ISOCHRONOUS: for (i = 0; i < UGEN_NISOREQS; ++i) @@ -662,7 +660,7 @@ if (sce->ibuf != NULL) { free(sce->ibuf, M_USBDEV); sce->ibuf = NULL; - clist_free_cblocks(&sce->q); + clist_free(&sce->q); } } sc->sc_is_open[endpt] = 0; @@ -706,7 +704,7 @@ case UE_INTERRUPT: /* Block until activity occurred. */ s = splusb(); - while (sce->q.c_cc == 0) { + while (clist_usage(&sce->q) == 0) { if (flag & O_NONBLOCK) { splx(s); return (EWOULDBLOCK); @@ -729,13 +727,14 @@ splx(s); /* Transfer as many chunks as possible. */ - while (sce->q.c_cc > 0 && uio->uio_resid > 0 && !error) { - n = min(sce->q.c_cc, uio->uio_resid); + while ((n = clist_usage(&sce->q)) > 0 && + uio->uio_resid > 0 && !error) { + n = min(n, uio->uio_resid); if (n > sizeof(buffer)) n = sizeof(buffer); /* Remove a small chunk from the input queue. */ - q_to_b(&sce->q, buffer, n); + clist_read(&sce->q, buffer, n); DPRINTFN(5, ("ugenread: got %d chars\n", n)); /* Copy the data to the user process. */ @@ -1026,7 +1025,7 @@ DPRINTFN(5, (" data = %02x %02x %02x\n", ibuf[0], ibuf[1], ibuf[2])); - (void)b_to_q(ibuf, count, &sce->q); + clist_write(&sce->q, ibuf, count); if (sce->state & UGEN_ASLP) { sce->state &= ~UGEN_ASLP; @@ -1540,13 +1539,13 @@ switch (edesc->bmAttributes & UE_XFERTYPE) { case UE_INTERRUPT: if (sce_in != NULL && (events & (POLLIN | POLLRDNORM))) { - if (sce_in->q.c_cc > 0) + if (clist_usage(&sce_in->q) > 0) revents |= events & (POLLIN | POLLRDNORM); else selrecord(p, &sce_in->rsel); } if (sce_out != NULL && (events & (POLLOUT | POLLWRNORM))) { - if (sce_out->q.c_cc > 0) + if (clist_usage(&sce_out->q) > 0) revents |= events & (POLLOUT | POLLWRNORM); else selrecord(p, &sce_out->rsel); ==== //depot/projects/mpsafetty/sys/dev/usb/uhid.c#5 (text+ko) ==== @@ -55,6 +55,7 @@ #include #include +#include #include #include #include @@ -389,7 +390,7 @@ return; } - (void) b_to_q(sc->sc_ibuf, sc->sc_isize, &sc->sc_q); + clist_write(&sc->sc_q, sc->sc_ibuf, sc->sc_isize); if (sc->sc_state & UHID_ASLP) { sc->sc_state &= ~UHID_ASLP; @@ -424,7 +425,7 @@ return (EBUSY); sc->sc_state |= UHID_OPEN; - clist_alloc_cblocks(&sc->sc_q, UHID_BSIZE, UHID_BSIZE); + clist_alloc(&sc->sc_q, UHID_BSIZE); sc->sc_ibuf = malloc(sc->sc_isize, M_USBDEV, M_WAITOK); sc->sc_obuf = malloc(sc->sc_osize, M_USBDEV, M_WAITOK); @@ -464,8 +465,7 @@ usbd_close_pipe(sc->sc_intrpipe); sc->sc_intrpipe = 0; - ndflush(&sc->sc_q, sc->sc_q.c_cc); - clist_free_cblocks(&sc->sc_q); + clist_free(&sc->sc_q); free(sc->sc_ibuf, M_USBDEV); free(sc->sc_obuf, M_USBDEV); @@ -499,7 +499,7 @@ } s = splusb(); - while (sc->sc_q.c_cc == 0) { + while (clist_usage(&sc->sc_q) == 0) { if (flag & O_NONBLOCK) { splx(s); return (EWOULDBLOCK); @@ -523,13 +523,14 @@ splx(s); /* Transfer as many chunks as possible. */ - while (sc->sc_q.c_cc > 0 && uio->uio_resid > 0 && !error) { - length = min(sc->sc_q.c_cc, uio->uio_resid); + while ((length = clist_usage(&sc->sc_q)) > 0 && + uio->uio_resid > 0 && !error) { + length = min(length, uio->uio_resid); if (length > sizeof(buffer)) length = sizeof(buffer); /* Remove a small chunk from the input queue. */ - (void) q_to_b(&sc->sc_q, buffer, length); + clist_read(&sc->sc_q, buffer, length); DPRINTFN(5, ("uhidread: got %lu chars\n", (u_long)length)); /* Copy the data to the user process. */ @@ -743,7 +744,7 @@ if (events & (POLLOUT | POLLWRNORM)) revents |= events & (POLLOUT | POLLWRNORM); if (events & (POLLIN | POLLRDNORM)) { - if (sc->sc_q.c_cc > 0) + if (clist_usage(&sc->sc_q) > 0) revents |= events & (POLLIN | POLLRDNORM); else selrecord(p, &sc->sc_rsel);