Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IRQ Handling from User Space Linux

I'm writting a driver for a synthesized device in an FPGA. The device has several IRQs and have requested them on my driver:

irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
rc = request_irq(irq, &Custom_driver_handler,IRQF_TRIGGER_RISING , DRIVER_NAME, base_addr);

My problem is that i want that the irq_handler calls a function of an user space application. Is there any way to call my user space application from the irq_handler of the driver on kernel space??

I know i could save a flag from the driver and mmap its direction from the user application to polling it, but what i want to know is if there is any faster/more correct way.

Thank you in advance

like image 615
eps_712 Avatar asked Mar 13 '17 14:03

eps_712


People also ask

What is IRQ handler Linux?

The generic interrupt handling layer is designed to provide a complete abstraction of interrupt handling for device drivers. It is able to handle all the different types of interrupt controller hardware. Device drivers use generic API functions to request, enable, disable and free interrupts.

How are interrupts handled in Linux?

An interrupt is simply a signal that the hardware can send when it wants the processor's attention. Linux handles interrupts in much the same way that it handles signals in user space. For the most part, a driver need only register a handler for its device's interrupts, and handle them properly when they arrive.

How do you check interrupts in Linux?

To see the interrupts occurring on your system, run the command: # watch -n1 "cat /proc/interrupts" CPU0 CPU1 0: 330 0 IO-APIC-edge timer 1: 11336 0 IO-APIC-edge i8042 4: 2 0 IO-APIC-edge 6: 3 0 IO-APIC-edge floppy ... NMI: 0 0 Non-maskable interrupts LOC: 5806923 6239132 Local timer interrupts ...


1 Answers

There are several ways of invoking user-space functions from kernel, usually named upcalls: http://lkml.iu.edu/hypermail/linux/kernel/9809.3/0922.html; check also https://lwn.net/Articles/127698/ "Handling interrupts in user space" and the http://wiki.tldp.org/kernel_user_space_howto overview from 2008, part "Sending Signals from the Kernel to the User Space".

To make writing drivers easier, there is UIO framework in the kernel now: https://unix.stackexchange.com/questions/136274/can-i-achieve-functionality-similar-to-interrupts-in-linux-userspace https://lwn.net/Articles/232575/ https://yurovsky.github.io/2014/10/10/linux-uio-gpio-interrupt/ https://www.osadl.org/fileadmin/dam/rtlws/12/Koch.pdf http://www.hep.by/gnu/kernel/uio-howto/

With UIO you can block or poll special file descriptor to wait for interrupt (block by using read() syscall; poll with poll syscall): https://lwn.net/Articles/232575/

On the user space side, the first UIO-handled device will show up as /dev/uio0 (assuming a normal udev setup). The user-space driver will open the device. Reading the device returns an int value which is the event count (number of interrupts) seen by the device; if no interrupts have come in since the last read, the operation will block until an interrupt happens (though non-blocking operation is supported in the usual way as well). The file descriptor can be passed to poll().

include/linux/uio_driver.h is available in linux kernel for many years, it is here for 3. and 4. versions of kernel.

like image 79
osgx Avatar answered Sep 28 '22 08:09

osgx