Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 27 Oct 2006 06:58:07 GMT
From:      Warner Losh <imp@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 108551 for review
Message-ID:  <200610270658.k9R6w7u6051752@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=108551

Change 108551 by imp@imp_lighthouse on 2006/10/27 06:57:28

	read side lower half.

Affected files ...

.. //depot/projects/arm/src/sys/arm/at91/at91_ssc.c#17 edit

Differences ...

==== //depot/projects/arm/src/sys/arm/at91/at91_ssc.c#17 (text+ko) ====

@@ -373,7 +373,42 @@
 static int
 at91_ssc_read(struct cdev *dev, struct uio *uio, int flag)
 {
-	return EIO;
+	struct at91_ssc_softc *sc;
+	int err, ret, len;
+
+	sc = CDEV2SOFTC(dev);
+	// must read a multiple of 4 bytes
+	if ((uio->uio_resid & 0x3) != 0)
+		return (EINVAL);
+	err = 0;
+	ret = 0;
+	while (uio->uio_resid) {
+		// If there's no buffered data, but we've already copied
+		// some data, then go ahead and return what we have now.
+		if (sc->rd_end == sc->rd_buf && ret != 0)
+			break;
+		err = msleep(&sc->rxdone, &sc->sc_mtx, PCATCH | PZERO,
+		    "sscrd", 0);
+		if (err != 0)
+			break;
+		if (sc->rd_end == sc->rd_buf)
+			continue;
+		len = MIN(sc->rd_end - sc->rd_buf, uio->uio_resid);
+		err = uiomove(sc->rd_buf, len, uio);
+		if (err != 0)
+			break;
+		// If we read the whole thing, no datacopy is needed,
+		// otherwise we move the data down.
+		ret += len;
+		if (len == sc->rd_end - sc->rd_buf)
+			sc->rd_end = sc->rd_buf;
+		else {
+			bcopy(sc->rd_buf + len, sc->rd_buf,
+			    sc->rd_end - sc->rd_buf - len);
+			sc->rd_end -= len;
+		}
+	}
+	return (err);
 }
 
 static int



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200610270658.k9R6w7u6051752>