[alsa-devel] USB transfer_buffer allocations on 64bit systems
stern at rowland.harvard.edu
Fri Apr 9 16:41:48 CEST 2010
On Fri, 9 Apr 2010, Oliver Neukum wrote:
> Am Freitag, 9. April 2010 00:20:36 schrieb Alan Stern:
> > > > That would work, but it doesn't match the way existing drivers use the
> > > > interface. For example, the audio driver allocates a 16-byte coherent
> > > > buffer and then uses four bytes from it for each of four different
> > > > URBs.
> > >
> > > That will not work with any fallback that does not yield a coherent buffer.
> > What you mean isn't entirely clear. But it certainly does work in
> > various circumstances that don't yield coherent buffers. For example,
> > it works if the controller uses PIO instead of DMA. It also works if
> > the controller uses DMA and the URBs have to be bounced.
> It'll work on x86. On incoherent architectures this violates the cacheline
> rules for DMA-mapping if you have to bounce.
Not true. Consider: The driver allocates a 16-byte buffer (xbuf)
divided up into four sets of four bytes, and sets
urb[i].transfer_buffer_dma = xbuf_dma + 4*i;
Then usb_submit_urb(urb[i]) will copy the appropriate four bytes to a
bounce buffer and map the bounce buffer. Accesses to the other parts
of xbuf won't violate the cacheline rules, because xbuf isn't mapped
for DMA -- only the bounce buffer is. When urb[i] completes, the
bounce buffer contents will be copied back to the original four bytes
in xbuf. Again, there is no violation of cacheline rules.
> So it seems to me that
> if you want to share a buffer between URBs, it must be coherent.
No. But it must be allocated via usb_alloc_buffer() (or whatever that
routine gets renamed to).
More information about the Alsa-devel