Writing Device Drivers

Interrupt Handler Overview

An interrupt is a hardware signal from a device to a CPU. It tells the CPU that the device needs attention and that the CPU should stop performing what it is doing and respond to the device. If a CPU is available (it is not performing a task with higher priority), it suspends the current thread and eventually invokes the interrupt handler for that device. The job of the interrupt handler is to service the device and stop it from interrupting. Once the handler returns, the CPU resumes what it was doing before the interrupt occurred.

The DDI/DKI provides interfaces for registering and servicing interrupts.

Interrupt Specification

The interrupt specification is information the system uses to bind a device interrupt source with a specific device interrupt handler. The specification describes the information provided by the hardware to the system when making an interrupt request. Because an interrupt specification is bus specific, the information it contains varies from bus to bus.

Interrupt specifications typically include a bus-interrupt level. For vectored interrupts the specifications include an interrupt vector. On IA platforms the interrupt specification defines the relative interrupt priority of the device. Because interrupt specifications are bus specific, see the man pages for isa(4), eisa(4), sbus(4), and pci(4) for information on interrupt specifications for these buses.

Interrupt Number

When registering interrupts the driver must provide the system with an interrupt number. This interrupt number identifies the interrupt specification for which the driver is registering a handler. Most devices have one interrupt: interrupt number 0. However, there are devices that have different interrupts for different events. A communications controller may have one interrupt for receive ready and one for transmit ready. The device driver normally knows how many interrupts the device has, but if the driver has to support several variations of a controller, it can call ddi_dev_nintrs(9F) to find out the number of device interrupts.

Interrupt Block Cookies

An iblock cookie is an opaque data structure that represents the information the system needs to block interrupts and is returned from ddi_get_iblock_cookie(9F) or ddi_get_soft_iblock_cookie(9F). This interface uses an interrupt number to return the iblock cookie associated with a specific interrupt source. The value of the iblock cookie (not the address) must be passed to mutex_init(9F) when initializing driver mutexes that will be used in the interrupt routine. The value of the iblock cookie is obtained by passing the address of the cookie to ddi_get_iblock_cookie() or ddi_get_soft_iblock_cookie(). For example:


       ddi_get_soft_iblock_cookie(dip, DDI_SOFTINT_HI,
               &xsp->low_iblock_cookie)
       mutex_init(&xsp->low_mu, NULL, MUTEX_DRIVER,
               (void *)xsp->low_iblock_cookie);