buffer allocation for DMA transfers


I am writing a driver for a PCI card supporting DMA transfers.

I allocate a buffer (contiguous in physical memory) for the DMA with the following instruction :


Then I get the physical address paddr and pass it to the DMA controller :

mem_offset(vaddr ,NOFD,16*1024,&phys_addr,0);

It Works fine, but my problem is that the driver’s client
already allocate the buffer with a simple variable declaration :

long MyBuff[16*1024]

Is there any way to know if MyBuff is contiguous in physical memory ?
If MyBuff is not contiguous in Physical memory, is it possible
to know the physical address and length of each block ?
(My idea is to implement the DMA scatter/gather mode)

Thank You All for your help.


I’m not sure I understand when you say the client already allocated the buffer with “long MyBuff”.

That being said, the only way to get contiguous memory is via mmap, anything else is undefined. Hence long MyBuff is undefined, I’m not sure it’s a good idea to try to obtain that information (I think it’s possible but rather heavy). Best is to create your own API for the driver and have a function allocated memory contiguously.

Tanks for your answer.

Actually, i am tryng to write a QNX driver which is “API-compatible”
with an existing Windows driver.
My idea was to switch from a Windows driver to a QNX driver
without changing the main application using this driver.

But I will follow your advice, and I decided to make the necessary
changes in the main application so that it works under Windows and QNX.

Thank you again