Date: Sat, 7 Oct 2006 07:20:06 GMT From: Warner Losh <imp@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 107400 for review Message-ID: <200610070720.k977K6HQ076999@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=107400 Change 107400 by imp@imp_lighthouse on 2006/10/07 07:19:43 Handle case where only cmd is specified, but no data. Affected files ... .. //depot/projects/arm/src/sys/arm/at91/at91_spi.c#10 edit Differences ... ==== //depot/projects/arm/src/sys/arm/at91/at91_spi.c#10 (text+ko) ==== @@ -205,7 +205,7 @@ at91_spi_transfer(device_t dev, device_t child, struct spi_command *cmd) { struct at91_spi_softc *sc; - int i, rxdone, err; + int i, j, rxdone, err, mode[4]; bus_addr_t addr; sc = device_get_softc(dev); @@ -217,28 +217,32 @@ WR4(sc, PDC_TPR, addr); WR4(sc, PDC_TCR, cmd->tx_cmd_sz); bus_dmamap_sync(sc->dmatag, sc->map[i], BUS_DMASYNC_PREWRITE); - i++; - if (bus_dmamap_load(sc->dmatag, sc->map[i], cmd->tx_data, - cmd->tx_data_sz, at91_getaddr, &addr, 0) != 0) - goto out; - WR4(sc, PDC_TNPR, addr); - WR4(sc, PDC_TNCR, cmd->tx_cmd_sz); - bus_dmamap_sync(sc->dmatag, sc->map[i], BUS_DMASYNC_PREWRITE); - i++; + mode[i++] = BUS_DMASYNC_POSTWRITE; + if (cmd->tx_data_sz > 0) { + if (bus_dmamap_load(sc->dmatag, sc->map[i], cmd->tx_data, + cmd->tx_data_sz, at91_getaddr, &addr, 0) != 0) + goto out; + WR4(sc, PDC_TNPR, addr); + WR4(sc, PDC_TNCR, cmd->tx_cmd_sz); + bus_dmamap_sync(sc->dmatag, sc->map[i], BUS_DMASYNC_PREWRITE); + mode[i++] = BUS_DMASYNC_POSTWRITE; + } if (bus_dmamap_load(sc->dmatag, sc->map[i], cmd->rx_cmd, cmd->tx_cmd_sz, at91_getaddr, &addr, 0) != 0) goto out; WR4(sc, PDC_RPR, addr); WR4(sc, PDC_RCR, cmd->tx_cmd_sz); bus_dmamap_sync(sc->dmatag, sc->map[i], BUS_DMASYNC_PREREAD); - i++; - if (bus_dmamap_load(sc->dmatag, sc->map[i], cmd->rx_data, - cmd->tx_data_sz, at91_getaddr, &addr, 0) != 0) - goto out; - WR4(sc, PDC_RNPR, addr); - WR4(sc, PDC_RNCR, cmd->tx_data_sz); - bus_dmamap_sync(sc->dmatag, sc->map[i], BUS_DMASYNC_PREREAD); - + mode[i++] = BUS_DMASYNC_POSTREAD; + if (cmd->tx_data_sz > 0) { + if (bus_dmamap_load(sc->dmatag, sc->map[i], cmd->rx_data, + cmd->tx_data_sz, at91_getaddr, &addr, 0) != 0) + goto out; + WR4(sc, PDC_RNPR, addr); + WR4(sc, PDC_RNCR, cmd->tx_data_sz); + bus_dmamap_sync(sc->dmatag, sc->map[i], BUS_DMASYNC_PREREAD); + mode[i++] = BUS_DMASYNC_POSTREAD; + } WR4(sc, SPI_IER, SPI_SR_ENDRX); WR4(sc, PDC_PTCR, PDC_PTCR_TXTEN | PDC_PTCR_RXTEN); @@ -248,18 +252,15 @@ } while (rxdone == sc->rxdone && err != EINTR); WR4(sc, PDC_PTCR, PDC_PTCR_TXTDIS | PDC_PTCR_RXTDIS); if (err == 0) { - // Sync the buffers after the DMA is done, and unload them. - bus_dmamap_sync(sc->dmatag, sc->map[0], BUS_DMASYNC_POSTWRITE); - bus_dmamap_sync(sc->dmatag, sc->map[1], BUS_DMASYNC_POSTWRITE); - bus_dmamap_sync(sc->dmatag, sc->map[2], BUS_DMASYNC_POSTREAD); - bus_dmamap_sync(sc->dmatag, sc->map[3], BUS_DMASYNC_POSTREAD); + for (j = 0; j < i; j++) + bus_dmamap_sync(sc->dmatag, sc->map[j], mode[j]); } - for (i = 0; i < 4; i++) - bus_dmamap_unload(sc->dmatag, sc->map[i]); + for (j = 0; j < i; j++) + bus_dmamap_unload(sc->dmatag, sc->map[j]); return (err); out:; - while (i-- > 0) - bus_dmamap_unload(sc->dmatag, sc->map[i]); + for (j = 0; j < i; j++) + bus_dmamap_unload(sc->dmatag, sc->map[j]); return (EIO); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200610070720.k977K6HQ076999>