Subject: Re: USB stack needs early review (Re: Someone should fix our USB stack...)
To: ITOH Yasufumi <itohy@netbsd.org>
From: Jachym Holecek <freza@dspfpga.com>
List: tech-kern
Date: 03/22/2007 17:27:03
# ITOH Yasufumi 2007-03-22:
> In article <etu7iu$qpk$1@serpens.de>
> mlelstv@serpens.de writes:
> > itohy@NetBSD.org (ITOH Yasufumi) writes:
> > 
> > > - volatiles in DMA structure, since it should not be needed
> > >   with proper bus_dma_sync(9)s
> > 
> > Can you explain?
> 
> Sure.
> 
> Our HCI drivers didn't have bus_dmamap_sync(9) at all.
> (Yeah, bus_dma_sync is a typo of bus_dmamap_sync.)
> I wonder why it worked.
> 
> bus_dmamap_sync() commonly has two functions:
>  1. buffer bouncing, and
>  2. providing proper barrier to ensure the data will not be cached.

Right.

> Declaring as "volatile" may have similar function as 2. and
> may make it work on some platforms.
> It is, however, useless if bus_dmamap_sync()s are present.

Nope, AFAIU "volatile" tells the compiler the value shouldn't get cached
in a register (ie. should be refetched on each use) because it's expected
to be updated asynchronously (by another bus-master or from interrupt/signal
handler).

So you want both -- "volatile" to make sure your code doesn't keep outdated
value in CPU registers and bus_dmamap_sync() to make sure outdated value
gets purged from CPU cache (or any kind of bus cache along the way), as you
noted above.

	-- Jachym