Specifications

Developing a Device Drive
r
10-21
The Intr Routine 10
Specification
void
xx
intr(ivec)
int
ivec
;
Return Values
None.
The ivec argument specifies a driver-defined number that identifies the device that gener-
ated the interrupt.
This entry point is required only if the driver provides support for interrupts generated by
a device it controls.
This entry point is called by the kernel when the processor services a hardware interrupt
request from the device. The device interrupts when data are available, a device buffer is
empty, or an I/O error has occurred.
The typical steps that can be taken to handle a device interrupt are described as follows.
First, the interrupt handler is responsible for validating the interrupt request. The driver
performs the following types of tasks during this validation:
Keeps a record of interrupt occurrences
Interprets the interrupt routine argument ivec
Processes interrupts that happen without cause (called spurious interrupts)
Second, when the driver has validated the interrupt request, it must then perform
device-dependent functions to service the request.
If the interrupt signals that an error has occurred, the interrupt handler must update the
device I/O status structures or flags. It can also send a signal to the associated process(es);
for example, if the device has been disconnected, the driver might need to send a SIGHUP
signal to the associated process(es).
If the interrupt signals that the device is now available to be read from or written to, then
the interrupt handler is responsible for initiating and scheduling the data transfers. For all
non-DMA data transfers, then the driver must first transfer device data to driver internal
buffers. The interrupt handler cannot transfer the device data directly between the device
and the user process’s address space. Typically, the driver performs the following types of
tasks during this phase:
The driver updates the I/O status of the device.
If the driver’s write() routine has buffered data to be written to the
device, the interrupt handler initiates the transfer of data. The transfer can
be performed using DMA or polled I/O. Refer to Chapter 12 (“Supporting
Direct Memory Access (DMA)”) for details on DMA programming. For
polled I/O, the interrupt handler formats commands and data as necessary
and writes the appropriate commands to the device control registers along
with the data. The interrupt handler notifies any user level processes