Device Drivers
Operating System interacts with the hardware through the interface given by device driver. Device driver exports a set of functions to the Operting System. Usually drivers run in Kernel mode, but user space drivers also available. But we will concentrate only on Kernel mode drivers.
So without a driver, OS may not recognize the hardware.
Linux Device Drivers
In Linux everything is treated as files (as Unix). So device is also treated as file. A file (called device node) is created (with specific major number) for each device, so that system calls (like open(),read(),write()) on that file, actually invokes device driver methods through Linux VFS Virtual File System
This is achieved through obtaining the major number for each driver (not true for all). Each driver gets a major number. And operations on a device node with the same major number, invokes the driver's method.
For example, a driver (Lets call it as test driver) can get 254 as major number for its device. So a device node with major number 254 and minor number 0 (will be explained later) is created as
$mknod test c 254 0
where
mknod - command
test - device node name
c - character device
254 - Major number
0 - Minor number
Now operations on the special file test invokes test driver's method.
We will see more on this later.
Types of Devices
Devices are classified into the following two types in all Unix systems.
Block devices are those which are accessed through a cache. Block devices must be random access, Filesystems can only be mounted if they are on block devices.
Character devices are those for which no buffering is performed. They are not required to be random access, though some are.
Both the drivers have the same interface, but block drivers does not have the read/write routine, instead it has 'strategy routine(request)' to accomplish read/write operations.
Features
In Linux, drivers can be
Static Linking
Static linking means that the driver module is linked with the kernel. So it can not be unloaded.
Dynamic Linking
This means that, whenever needed the required driver
module can be loaded. And also the driver can be unloaded provided no other
module is using it.
This has the advantage of reduced kernel size.
In the next chapter, we will see how to write a basic driver.
This site has been visited
free hit counter
times
Last modified on: