Subject: Re: bus_dma(9) - q WRT bus_dmamap_load()
To: =?iso-8859-1?Q?=22Jarom=EDr=22?= Dolecek <jdolecek@netbsd.org>
From: Matt Thomas <matt@3am-software.com>
List: tech-kern
Date: 04/13/2001 08:39:07
At 02:10 PM 4/13/2001 +0200, Jarom=EDr" Dolecek wrote:
>Hi,
>I'm trying to write a MCA disk device driver. The device uses DMA.
>I know how to setup the DMA controller for DMA transfer. Only remaining
>is feeding it with DMA safe memory. The controller seems to only
>support one piece of phys memory, so I have to feed it buffer as
>single segment.
>
>I use a dmamap created by bus_dmamap_create() in driver's attach
>function, like:
>         error =3D bus_dmamap_create(dmat, 65536, 1, 65536, 0,
>                         BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW, &dmamap);

Do you really want just one segment?  You probably want more than
that since that forces all the pages to physicallly contiguous
which they most likely won't be.  I'd suggest using a minimum of
(65536 / PAGE_SIZE) + 1 segments.  You then iterate through the
map's dm_segs and transfer them one by one.

>Then, then data are to be transferred to/from device, I use
>bus_dmamem_load() to arrange for the DMA to happen directly to the
>i/o buf, like this:
>
>         error =3D bus_dmamap_load(dmat, dmamap, bp->b_data, bp->b_bcount,
>                         NULL, BUS_DMA_STREAMING);
>
>This sometimes works, but sometimes the bus_dmamap_load() doesn't
>find suitable segment. If I try to raise nsegments for bus_dmamap_create(),
>bus_dmamap_load() then returns two segments, split like
>94 bytes and 418 bytes. Of course, this is not particularily useful
>for me, since the MCA DMA controller can accept only one dma
>address.

So you transfer the first one, and then return.  when the dma completes
and you get an interrupt, you xfer the 2nd segment, and then when you
get the interrupt for the final segment you can then signal you are
done with the buffer.
--
Matt Thomas               Internet:   matt@3am-software.com
3am Software Foundry      WWW URL:    http://www.3am-software.com/bio/matt/
Cupertino, CA             Disclaimer: I avow all knowledge of this message