Notes on Writing Device Drivers
what is role of a device driver ?
- device drivers are distinct "black boxes" that makes a particular piece of hardware responds to a well defined internal programming interface
- from another perspective the device driver is software layer that lies between the application and the actual device
the policy and the mechanism :
- the mechanism: "what capabilities are to be provided by the driver ? " .
- the policy : " how those capabilities can be used .? "
it`s very important to be as policy free as possible , because different environment usually need to use the hardware in different ways .
Example to distinguish between the policy and the mechanism :
1) floppy disk driver is policy free
it`s role is only show the Diskette as a continuous array of data blocks
while higher levels of the system provides policies like :
- who may access the floppy driver ?
- whether the drive is accessed directly or via a file system ?
- whether users may mount file systems on the drive ?
When writing drivers, a programmer should pay particular attention to this fundamental concept: write kernel code to access the hardware, but don’t force particular policies on the user, since different users have different needs.
The driver should deal with making the hardware available, leaving all the issues about how to use the hardware to the applications.
A driver, then, is flexible if it offers access to the hardware capabilities without adding constraints.
Policy-free drivers have a number of typical characteristics. These include :
- support for both synchronous and asynchronous operation,
- the ability to be opened multiple times,
- the ability to exploit the full capabilities of the hardware,
Drivers of this sort not only work better for their end users, but also turn out to be easier to write and maintain
as well Being policy-free is actually a common target for software designers.