Specifications

Introduction
1.2 Driver Components
1.2.2 Driver Routines
In addition to any FDT routines it might contain, a device driver generally
contains both a start-I/O routine and an interrupt service routine (ISR).
The start-I/O routine performs such additional device-dependent tasks as
translating the I/O function code into a device-specific command, storing the
details of the user request in the device’s unit control block (UCB) in the I/O
database and, if necessary, obtaining access to controller and adapter resources.
Whenever the start-I/O routine must wait for these resources to become available,
the operating system suspends the routine, reactivating it when the resources
become free.
The start-I/O routine ultimately activates the device by suitably loading the
device’s registers. At this stage, the start-I/O routine invokes a system macro
that causes its execution to be suspended until the device completes the I/O
operation and posts an interrupt to the processor. The start-I/O routine remains
suspended until the drivers interrupt service routine handles the interrupt.
When a device posts an interrupt, its drivers interrupt service routine determines
whether the interrupt is expected or unexpected, and takes appropriate action.
If the interrupt is expected, the interrupt service routine reactivates the driver’s
start-I/O routine at the point of suspension. The general course of action of driver
mainline code at this time is to perform device-dependent I/O postprocessing
and to transfer control to the operating system for device-independent I/O
postprocessing.
Details on writing a start-I/O routine appear in Chapter 6. A description of a
driver interrupt service routine appears in Chapter 7.
You can also include any of the following routines in a device driver:
The unit initialization routine and controller initialization routine prepare
a device or controller for operation when the driver-loading procedure loads
the driver into memory and when the system recovers from a power failure. The
amount and type of initialization needed by devices and controllers vary according
to the device type and the I/O bus to which the device or controller is attached.
additional information about device driver initialization routines.
A timeout handling routine retries I/O operations and performs other error
handling when a device fails to complete a request in a reasonable period of time.
Once every second, the system timer checks all devices in the system for device
timeout. When it locates a device that has timed out, because it is off line or
some error has occurred, the system timer calls the drivers timeout handling
routine.
Depending upon the reason for the timeout, the timeout handling routine may
call a system error-logging routine to allocate and fill an error message buffer
with information about the error. In turn, the error-logging routine can call a
register-dumping routine in the driver that also loads into the buffer the
contents of device registers at the time of the error.
The operating system calls a driver’s cancel-I/O routine when a user process
issues a Cancel I/O on Channel ($CANCEL) system service for the device. It may
also call the routine when the device’s reference count goes to zero, which occurs
when all users with assigned channels to the device have deassigned them.
1–3