DMA to userspace and flush

Submitted by debrupam
on June 19, 2009 - 8:48am

I am writing a user space MAC driver in Linux 2.6.23 hosted on a Arm11 mpcore. A contiguous block of physical memory is allocated and mmap'd to userspace.

/dev/mem with O_SYNC flag is used to mmap so that the user virtual memory is uncached (with no much benefit).

Kernel
------
kptr = kmalloc(sz, GFP_DMA|GFP_KERNEL);
pptr = __pa(kptr);

User
----
fd = open("/dev/mem", O_RDWR|O_SYNC);
uptr = mmap(0, sz, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_LOCKED,fd, pptr);

The map'd user virtual memory is carved into network buffers and used for DMA ( no struct page/vm_area_struct information is retained).The MAC is successfully able to DMA ethernet frames to the physical memory. From the Rx interrupt handler bh (kernel logical memory) the frames received could be viewed and the cache functions also work fine. However, the mmap'd memory in user space does not reflect the changes.

How could one flush the kernel memory contents to userspace ? "msync" does not help. Could it help if flush_dcache_page() is used ? Since the struct page info is not retained flush_dcache_page() could not be used. Is there a known way to implement flush_dcache_range() for the arm platform ?

Or any suggestions on what could be going wrong here ?

thanks,
Deb Rupam Banerjee

P.S: Please note that all buffer alignment's are taken care of.