Re: buffer stuff (+ DMA)

On Mon, Jul 15, 2002 at 09:24:29AM -0700, Dan Christian wrote:
> On Tuesday 09 July 2002 12:04, David Schleef wrote:
> > pcidas-4020 uses DMA, correct?  Then it should be allocating chunks
> > using comedi_buf_write_alloc(), DMAing to them, and then freeing
> > them using comedi_buf_write_free().  This will get all the
> > bookkeeping correct and also be zero-copy.  I haven't implemented
> > this correctly yet on any driver.
> 
> I'm just starting to look at DMA support, and this confuses me.
> 
> Does this assume that the total transfer is smaller than the buffer 
> size?

This "allocation" is within the existing allocated buffer.  It's
essentially just a check to make sure there won't be a buffer
overflow.

> It seems like you can only do a zero copy transfer if no conversion 
> operations are needed.  In my case, any channels with bipolar ADC 
> inputs have to have 2048 added to them before they can be put in the 
> buffer.

Then you can't do zero-copy.  However, someone will shortly be
screaming for CMDF_RAWDATA support.

(And remember that you need to use cpu_to_le32() and le32_to_cpu()
when reading and writing from memory that is shared with the DMA
controller, otherwise your driver won't work on big-endian machines.)

(Yes, this means that on big-endian machines, using the CMDF_RAWDATA
flag will give you data that is incorrectly byte-swapped.)

> I was planning to:
> allocate two transfer buffers (each buffer is 1/2 FIFO in length)
> lock them in physical memory
> setup a continuous, two buffer DMA transfer
> interrupt after each transfer
>   convert to comedi samples within the transfer buffer
>   pass the data to comedi (using comedi_buf_put_array?)
> 
> Is this the right approach?  Is there a way to do this without the 
> transfer buffers?

Assuming you have a decent DMA controller, you should be able to
do DMA transfers directly into the Comedi buffer, with a DMA link
for each page in the buffer.  You should set up your own buffer
allocation function by setting buf_alloc in the subdevice structure,
and get any information you need about the buffer, such as the
physical addresses of all the pages and creating the links.

If you want to be really advanced, you can keep a separate list of
the physical addresses of the pages in the buffer, and generate the
link structures on the fly.  Eventually, I'll convert the ni_pcimio
driver to do this, since it's probably the easiest way to get
end-of-scan events with DMA (with the MITE controller).

If your board has a less-than-great DMA controller, do whatever
you need to do. =)



dave...

Received on 2002-07-15Z18:02:34