Mapping a network device driver's buffer to user space - Powerpc

This is a discussion on Mapping a network device driver's buffer to user space - Powerpc ; 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 ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: Mapping a network device driver's buffer to user space

  1. Mapping a network device driver's buffer to user space

    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?


  2. Re: Mapping a network device driver's buffer to user space

    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


  3. Re: Mapping a network device driver's buffer to user space

    > 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

  4. Re: Mapping a network device driver's buffer to user space

    you can use waitqueues for this. I have once used them in similar
    context in a usb modem driver.


    shiva


+ Reply to Thread