Discussion:
Mapping a network device driver's buffer to user space
(too old to reply)
Bill
2006-04-26 17:19:33 UTC
Permalink
I am writing a linux network device driver and have discovered I cannot
use copy_to_user in an interrupt handler. As a workaround, I have seen
an old posting that suggested mapping a kernel buffer into user space
and passing the data that way rather than using copy_to_user. ("In
your user space application, open /dev/kmem (which is a character
driver, which supports mmap), and memory map the kernel address
retrieved into the user space process.")

But, how exactly does one do this? I can kmalloc a buffer in the
network driver and send the address kmalloc returns in the driver to
the user application. Now what? I know I have to call mmap but with
what arguments? What about user addressing vs driver addressing?

Does anyone know where there is driver and user application code
showing how this is done?
Amit Limaye
2006-04-28 15:39:01 UTC
Permalink
Bill if ur problem is posting data to userspace this is not the way u
want to go
instead try setting up a queue of buffers and let the interrupt keep on
adding to it. You can the copy_to_user from the read entry point in ur
driver to the user.
U cannot use copy_to_user from an interupt for a simpe reason tht the
interrupt doesnt have any context so it does not know whcih processes
memory space to write to?

The approach i described is not as easy as it looks but then it is one
of the ways u will have to dispatch data to the right app from ur
driver once u get it from the interrupt if ur device can be used and
opened by multiple apps simultaneouly

-SIGTERM
amit
Andrew Klossner
2006-04-28 16:06:28 UTC
Permalink
You cannot use copy_to_user from an interrupt for the simple reason
that the interrupt doesn't have any context so it does not know
which process's memory space to write to.
Also because, if that memory space is not resident, the interrupt
handler cannot wait for it to be paged in. In addition, some
architectures have issues with allocation of TLBs, precluding
user-space access from an interrupt handler.

-=- Andrew Klossner
shiva
2006-05-01 06:30:21 UTC
Permalink
you can use waitqueues for this. I have once used them in similar
context in a usb modem driver.


shiva

Loading...