correct use of bus_dmamap_sync

John Baldwin jhb at
Tue Oct 25 10:31:24 PDT 2005

On Tuesday 25 October 2005 09:15 am, Dinesh Nair wrote:
> i came across this message
> and while it explains the use of bus_dmamap_sync, i'm still a little
> confused on it's usage. i'm trying to port over a driver from freebsd 5.x
> to freebsd 4.x, and it uses dma mapped addresses extensively.
> i've been trying to figure out the best places to use bus_dmamap_sync when
> reading/writing to a dma mapped address space. however, i cant seem to get
> the gist of this, either from the mailing list discussions or the man page.
> i've got two buffers, one for read, and one for write. both have been set
> up with calls to bus_dma_tag_create, bus_dmamem_alloc and bus_dmamap_load.
> the buffers, which are used in the calls to bus_dmamem_alloc and
> bus_dmamap_load are,
> int *readbuf;
> int *writebuf;
> (must i malloc space for them before passing them into those functions, or
> will the call to bus_dmamem_alloc do it for me ?)

bus_dmamem_alloc() will do it for you.

> also, i'm on FreeBSD 4.11 right now, and i notice the definitions of
> BUS_DMASYNC_* has changed from an enum (0-3) in 4.x to a typedef in 5.x in
> machine/bus_dma.h
> the pseudo code for the read and write, called during an interrupt cycle,
> are:
> rx_func()
> {


> 	while(there_is_some_data) {
> 		memcpy(somebuf, readbuf)
> 	}


> }
> tx_func()
> {


> 	while(there_is_some_data) {
> 		memcpy(writebuf, somebuf)
> 	}


> }
> the question is, what op should i use for bus_dmamap_sync in positions A,
> B, C and D ?
> any assistance would be gladly appreciated, as i'm seeing some really weird
> symptoms on this device, where data written out is being immediately read
> in. i'm guessing this has to do with my wrong usage of bus_dmamap_sync().

Probably not as the sync()'s don't really do anything with memory allocated 
via bus_dmamem_alloc().  The operations are named from the CPU's perspective, 
thus when you send data to your device, that is a WRITE operation (even 
though your device is doing a DMA to read data), and when you get data back 
from your device, that is a READ operation (even though your device is doing 
a DMA to write the data into the buffer).

John Baldwin <jhb at>  <><
"Power Users Use the Power to Serve"  =

More information about the freebsd-hackers mailing list