Specifications
D
evice Driver Programming
10-8
You might also want to declare other structures for your device driver. The definitions for
such structures should be in the device driver’s header file (the .h file) or in the device
driver’s source file (the
.c
file). If the structures are internal to the device driver and not
part of a user interface or if they are shared by other kernel files, they can be declared in
the driver’s
.c
file.
There are three methods for actually declaring and allocating memory for your structures:
• Allocate memory for them by using the driver’s init() routine if they are
dependent on the number of devices configured. With this method, waste of
system memory is minimized.
• Declare them statically in your device driver if their size is independent of
the number of devices configured or if their size is minimal.
• Declare memory in the driver’s space.c file. This allows you to declare
memory on a per installed/configured controller basis.
Most device structures are allocated in arrays, with the device minor number used as the
index into the array.
Developing the Driver Source File 10
This section describes the different types of driver routines. It describes the driver’s initial-
ization routines. It describes the driver’s I/O service routines. It describes the driver’s
interrupt service routines and provides supporting information about interrupt priorities
and interrupt vectors. It explains the use of local routines in the driver. It points out the
need for adequate error-handling procedures. It describes the properties of blocking primi-
tives and signals.
Initialization Routines 10
The following is a brief overview of the kernel initialization routines for device drivers.
The kernel specifies two types of interfaces: one for statically linked drivers, the other for
dynamically linked drivers.
To initialize statically linked device drivers, the system specifies two optional entry points,
init(D2) and start(D2). The purpose of these routines and the driver configuration
files is to initialize the driver and its associated devices. (Refer to Chapter 14 (“Driver
Installation and Tuning”) for a detailed description). As a part of the system start up, the
kernel calls the initialization routines of all device drivers statically linked with the kernel.
These are called before any other driver points are called.
The kernel calls the driver’s init() routine before system services such as the interrupt
subsystem are initialized—that is, before device interrupts are enabled. The kernel calls a
driver’s start() routine after system services are initialized and interrupts are enabled.