From mboxrd@z Thu Jan 1 00:00:00 1970 From: arvid.brodin@enea.com (Arvid Brodin) Date: Fri, 26 Aug 2011 23:35:31 +0200 Subject: (struct spi_transfer)->rx_buf == (struct spi_transfer)->tx_buf? Message-ID: <4E5811A3.9040403@enea.com> To: kernelnewbies@lists.kernelnewbies.org List-Id: kernelnewbies.lists.kernelnewbies.org I was tracing calls to dma_map_single() and noticed that spi drivers call this function repeatedly on the same buffer address (with no dma_unmap_single() between). Is this really OK? Looking into it I saw that the spi drivers' tx_buf and rx_buf were equal (same address), and these are "dma mapped" simultaneously in many spi drivers (tx_buf as DMA_TO_DEVICE; rx_buf as DMA_FROM_DEVICE). If this buffer (tx_buf === rx_buf) is both read from and written to using DMA, then shouldn't they use DMA_BIDIRECTIONAL? Also, DMA_TO_DEVICE mappings should be done before starting the transfer to the device, while DMA_FROM_DEVICE mappings should be done after the device has finished its transfer, if I understand dma_map_single() correctly (because this is just a cache synchronization thing, right?) This whole thing just seemed strange to me and I'm hoping someone can explain what's going on! BTW, the declaration of struct spi_transfer (http://lxr.linux.no/linux+*/include/linux/spi/spi.h#L430) has this comment: /* it's ok if tx_buf == rx_buf (right?) */ Since spi is always full duplex, I'm guessing that the idea with using only one buffer is that incoming bytes overwrites queued bytes? -- Arvid Brodin Enea Services Stockholm AB