PERFORCE change 151826 for review
Ed Schouten
ed at FreeBSD.org
Thu Oct 23 19:41:18 UTC 2008
http://perforce.freebsd.org/chv.cgi?CH=151826
Change 151826 by ed at 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 <sys/systm.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
+#include <sys/clist.h>
#include <sys/conf.h>
#include <sys/fcntl.h>
#include <sys/poll.h>
@@ -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 <sys/param.h>
#include <sys/systm.h>
+#include <sys/clist.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/module.h>
@@ -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 <sys/param.h>
#include <sys/systm.h>
+#include <sys/clist.h>
#include <sys/kernel.h>
#include <sys/lock.h>
#include <sys/malloc.h>
@@ -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);
More information about the p4-projects
mailing list