Accessing device memory from user-land application process

John-Mark Gurney gurney_j at resnet.uoregon.edu
Mon Sep 3 18:46:13 PDT 2007


Prahar Shah wrote this message on Fri, Aug 31, 2007 at 10:30 +0530:
> I am writing a device driver in user-land process. I do a contigmalloc() to
> allocate the descriptor memory, do a vtophys() on it and mmap that memory in
> the user-land application process. I allocate buffers again using

You should be using bus_dma(9) instead of vtophys...  With bus_dma, you
won't have to restrict your driver to i386 and other platforms that
provide vtophys...

> contigmalloc(), and mmap it within the same process. I pass on a buffer each
> to the device descriptor. And my packet reception works fine.
> While processing packets, once i reset the device (all device registers and
> related memory), and repopulate buffers into the  descriptors, I
> occasionally find that while receiving a packet after reset, the buffer
> address that I read from the first descriptor is not the one that I gave to
> the descriptor after the reset. Instead, it turns out to be an older buffer
> address which as allocated to a descriptor which was supposed to be read
> next, prior to the reset.
> My doubt is, could this be a cache-coherency issue? Or could there be a
> chance that the device might be caching the buffer address available with
> the descriptors, and re-writing back to the descriptor after receiving the
> packet, and somehow these cached address are not flushed during a device
> reset?

Probably a cache issue...  If you use bus_dma, you can call
bus_dmamap_sync to deal w/ the cache issue...

> If i've missed any details, kindly let me know.
> Any help would be greatly appriciated

Good luck!

Hope this helps...

-- 
  John-Mark Gurney				Voice: +1 415 225 5579

     "All that I will do, has been done, All that I have, has not."


More information about the freebsd-net mailing list