Dynamic registration of an ISR by a device driver can be performed very simply using the data structures described. The function had been implemented by platform-specific code before the interrupt rework in 2.6. Naturally, the prototype was identical on all architectures as this is an absolute prerequisite for programming platform-independent drivers. Nowadays, the function is implemented by common code:
kernel/irq/manage.c int request_irq(unsigned int irq, irqreturn_t handler, unsigned long irqflags, const char *devname, void *dev_id)
Figure 14-7 shows the code flow diagram for request_irq.
The kernel first generates a new instance of irqaction that is then supplied with the function parameters. Of special importance is, of course, the handler function handler. All further work is delegated to the setup_irq function that performs the following steps:
1. If irqf_sample_random is set, the interrupt contributes to the kernel entropy source used for the random number generator in /dev/random. rand_initialize_irq adds the IRQ to the corresponding data structures.
2. The irqaction instance generated by request_irq is added to the end of the list of routines for a specific IRQ number; this list is headed by irq_desc[NUM]->action. This is how the kernel ensures that — in the case of shared interrupts — handlers are invoked in the same sequence in which they were registered when an interrupt occurs.
3. If the installed handler is the first in the list for the IRQ number, the handler->startup initialization function is invoked.10 This is not necessary if handlers for the IRQ have already been installed.
4. register irq proc generates the directory /proc/irq/NUM in the proc filesystem. register_handler_proc generates proc/irq/NUM/name. The system is then able to see that the corresponding IRQ channel is in use.
Continue reading here: Freeing IRQs
Was this article helpful?