Writing Linux Device Drivers
Arthur Donkers
Figure 1 | Listing
1
One of the early design advantages of UNIX subsequently copied by other operating
systems, such as MS-DOS, was the manner in which UNIX treats devices. UNIX essentially
abstracts devices out of the kernel proper and deals with them as files through
code called device drivers. The device drivers needed for a particular system
are then linked back into the kernel, either dynamically in some UNIX implementations
or statically at kernel build time. Due to the fact that device drivers need to
deal with complex, low-level hardware issues such as interrupts and synchronization,
device driver code was traditionally written by highly experienced C programmers
who worked for organizations that had access to UNIX source code. Thus, the ability
to write a UNIX device driver was once considered a measure of a UNIX programmer's
guru-hood.
However, things have changed. Since the rise of Linux many more people have the oppportunity to play with the source code of an inexpensive version of Unix. A primary benefit of Linux has been, and hopefully will continue to be, the availability of the source code. The source code provides numerous examples of how to write your own device driver for that gizmo you bought at your local surplus store.
This article offers pointers for writing your own device driver. However, there is no generic way of doing this, as the functionality of each device dictates the requirements of the associated driver.
Tip #1: Study examples of drivers written by others for similar devices. Solutions for one device can often be adapted to other purposes.
In the most basic sense, device drivers are those pieces of Unix code that provide the connection between the operating system, applications, and the hardware (the device itself). Thus, device drivers have to, among other things, deal with the asynchronous character of the hardware.
|