Installing an Interrupt Handler
If you want to actually “see” interrupts being generated, writing to the hardware device isn’t enough; a software handler must be configured in the system. If the Linux kernel hasn’t been told to expect your interrupt, it will simply acknowledge and ignore it.
Interrupt lines are a precious and often limited resource,
particularly when there are only 15 or 16 of them. The kernel keeps a
registry of interrupt lines, similar to the registry of I/O ports. A
module is expected to request an interrupt channel (or IRQ, for
interrupt request) before using it, and to release it when it’s done.
In many situations, modules are also expected to be able to share
interrupt lines with other drivers, as we will see. The following
functions, declared in <linux/sched.h>,
implement the interface:
int request_irq(unsigned int irq, void (*handler)(int, void *, struct pt_regs *), unsigned long flags, const char *dev_name, void *dev_id); void free_irq(unsigned int irq, void *dev_id);
The value returned from request_irq to the
requesting function is either 0 to indicate success or a negative
error code, as usual. It’s not uncommon for the function to return
-EBUSY to signal that another driver is already
using the requested interrupt line. The arguments to the functions
are as follows:
-
unsigned int irq This is the interrupt number being requested.
-
void (*handler)(int, void *, struct pt_regs *) The pointer to the handling function being installed. We’ll ...