Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 14: Kernel Activities


Figure 14-7 shows the code flow diagram forrequest_irq.

Create irqaction instance

IRQF_SAMPLE_RANDOM set?

Place irqaction at the end of the queue

Non-shared IRQ?

Register in proc file system

handler->startup

request_irq

setup_irq

rand_initialize_irq

Figure 14-7: Code flow diagram forrequest_irq.

The kernel first generates a new instance ofirqactionthat is then supplied with the function parameters.
Of special importance is, of course, the handler functionhandler. All further work is delegated to the
setup_irqfunction that performs the following steps:


  1. IfIRQF_SAMPLE_RANDOMis set, the interrupt contributes to the kernel entropy source used for
    the random number generator in/dev/random.rand_initialize_irqadds the IRQ to the
    corresponding data structures.

  2. Theirqactioninstance generated byrequest_irqis added to the end of the list of routines
    for a specific IRQ number; this list is headed byirq_desc[NUM]->action.Thisishowthe
    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, thehandler->startupini-
    tialization function is invoked.^10 This is not necessary if handlers for the IRQ have already
    been installed.

  4. register_irq_procgenerates the directory/proc/irq/NUMin theprocfilesystem.
    register_handler_procgeneratesproc/irq/NUM/name. The system is then able to see that
    the corresponding IRQ channel is in use.


Freeing IRQs


The reverse scheme is adopted in order to free interrupts. First, the interrupt controller is informed
that the IRQ has been removed by means of a hardware-specific (chip->shutdown)function,^11 and then
the relevant entries are removed from the general data structures of the kernel. The auxiliary function
free_irqassumes these tasks. While it has been an architecture-dependent function before the genirq
rework, it can today be found inkernel/irq/manage.c.

When an IRQ handler is required to remove a shared interrupt, the number alone is not sufficient to
identify the IRQ. In this case, it is necessary to also use thedev_iddiscussed above for purposes of

(^10) If no explicitstartupfunction is available, the IRQ is simply enabled by callingchip->enableinstead.
(^11) If no explicitshutdownfunction is available, the interrupt is simply disabled bychip->disableinstead.

Free download pdf