STREAMS-UX Programmer's Guide (February 2007)

Modules and Drivers
STREAMS Driver
Chapter 4
96
STREAMS Driver
A STREAMS device driver as mentioned earlier is similar to a regular UNIX character device driver. A
STREAMS driver is a necessary part of the stream constituting the stream end. A stream is created when a
STREAMS driver is opened. A STREAMS driver can also have multiple streams connected to it. Multiple
connections could be a result when more than one minor device of the same driver are opened and in case of
multiplexors.
Overview of Drivers
A driver is the software that provides an interface between a device and the operating system. User level
programs interact with these devices through system calls. Drivers manage the data going in and out of the
the devices and also manage the interrupts generated by the devices.
Based on the type of device the driver controls they can be classified as hardware or software drivers. A
hardware driver controls a physical device. A software driver, also known as the pseudo-device driver controls
the software, which in turn may be associated with a hardware device or a pseudo device — that has no
associated physical device.
In UNIX, the devices are represented as files. Implying that the drivers can support the character-type or
block-type access methods.
Finally, depending on the interface used between the drivers and devices, the drivers could be
STREAMS-based or non-STREAMS-based.
NOTE STREAMS drivers are always accessed through character special files, so are character based
drivers.
Writing Drivers
A driver is different from the regular C applications, in that it executes in the kernel and does not have a
main() function associated with it. The following general rules apply to all driver development:
A driver may need a start routine for initialization. This applies more to drivers that control real
hardware devices.
A driver must define open() and close() routines.
A driver must have an interrupt handling routine if it controls a hardware device.
A driver cannot use archive or shared libraries or floating point arithmetic.
All drivers must define specific entry points for initialization, switch table entry and interrupt handlers.
Major and Minor Numbers
In HP-UX device numbers (data type dev_t) formed by concatenating the major and the minor numbers is
used to identify the particular driver and device that is being accessed. The major number for a device maps
to a driver controlling the device and the minor number uniquely identifies the device.
A special device file is created for every device installed on the system, allowing user processes to view the
individual devices as files. Major and minor numbers are associated with the special device files and are used
by the operating system to determine the actual driver and device to be accessed by the user-level request for
the special device file.