Re: [PCI Driver]Physical address being returned as 0 in mmap

From: newton mailinglist
Date: Tue Jul 12 2011 - 07:48:33 EST


Hi Kyle,

Thanks so

> First of all, you need to make sure you have all of the cache and DMA
> flushes correct.  *ALL* memory that the FPGA might access while running
> the user code must be cache flushed and appropriately dma_sync_*()ed.
> Otherwise your FPGA will read old data.
> This means in particular that you can't really read arbitrary data from the
> program memory, you need to enumerate everything that the hardware
> needs in advance from the kernel, or be able to flush it on demand, which
> is somewhat of a performance killer.

Well yes, I actually do know exactly the data which I have to send to
the fpga in advance.
Its a fixed set of data(about 1 MB) and the CPU will not change it or
access it in any way once its inside the DMA buffer i.e. the
C program will not modify the data anymore. All I need to do is send
this fixed data to the fpga.

I was able to solve the issue finally.

Thanks so much for all the help.

So the way I do it using the DMA API is , I allocate the a buffer in
kernel space when the driver starts up :

//Allocate PCI consistent memory
cpu_addr_virt = (unsigned long)pci_alloc_consistent(htex_dev->dev,
BS_SIZE, &dma_handle);

Then whenever I need to use the buffer, I simply copy the data to it :
memset((void*)cpu_addr_virt, 0, BS_SIZE);
memcpy((void*)cpu_addr_virt, (void*)arg, BS_SIZE);

The physical addresses are known beforehand as the buffer is allocated
at startup and are valid for the entire lifetime of the driver
so no address translations are needed afterwards.

Thanks,
Abhi
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/