Basics of Linux Device Driver
A Linux device driver is significantly different from its Windows counterpart. Linux drivers are created solely to provide an interface to the hardware. They do not make any assumptions as to how the hardware will be used. Also, they usually do not provide any type of graphical interfaces for the hardware. Most drivers for Linux supported hardware are part of the Linux kernel source tree and are maintained by the Linux development community.
-
Function
-
A device driver's function is to provide access to a piece of hardware. In Windows, this is done through the Application Binary Interface (ABI) calls that Microsoft provides to the driver developer. The device driver for Windows is then provided to the user as a binary application.
In Linux, there is no ABI or Application Programming Interface (API) for device drivers. Instead, the Linux kernel provides a stable userspace interface for applications. Device drivers are created as modules of the Linux Kernel that hide the details of how the device works. These modules conform to a set of standardized calls that are independent of the device drivers themselves.
Features
-
One of the main features of Linux device drivers is that they are modular. They can be and are built separately from the the rest of the kernel. This means that each module (or driver) can be used or removed from the kernel at runtime depending on what hardware is available.
Drivers are also built with the distinction between mechanism and policy. Mechanism is what capabilities are provided, and policy is how the capabilities are to be used. The Linux device driver is policy free. The driver accesses the hardware but does not tell the user how it can or should be used.
-
Device Classes
-
The Linux kernel separates hardware devices into three main types: character devices, block devices, and network interfaces. A Character device can be accessed as a stream of characters or bytes, similar to a file. These devices include the text console, the keyboard and the serial ports.
A block device is a device that can only be accessed in blocks of data (usually a kilobyte or another power of 2) and can host a filesystem, like a disk drive. Linux allows applications to read and write to block devices like a character device, so they are managed in a special way by the kernel.
A network device allows the exchange of data with other hosts. These devices are usually hardware, but can also be purely software. The kernel has a different way to communicate with network devices than with character or block devices. Instead of reading and writing to the device, it handles packet transmission.
Driver Licensing
-
The Linux kernel is licensed under the GNU General Public License (GPL) which means it is open source and freely available for anyone to download, modify and redistribute as long as the redistributed code is also licensed under the GPL. However, this does not apply to Linux device drivers.
Because the kernel is modular, the device driver does not become part of the kernel. Instead, it accesses the kernel through a well defined interface. If the device driver uses only this module interface, it does not have to be licensed under the GPL. However, if the device driver actually uses part of the kernel code in order to work, instead of the interface available, it must be covered under the GPL.
Merging with the Kernel
-
Once a device driver becomes accepted as "working" by the Linux Kernel Development team, it will become part of the mainline Linux kernel source tree. That means that it will be kept up to date through subsequent kernel changes, will work with all central processing units (CPUs) supported by Linux, and will be fixed and enhanced by the Linux development community.
The kernel source tree holds modules for most of the hardware supported by Linux. That is why, as long as you are using Linux supported hardware, you can load the Operating System and have your hardware work without installing any additional driver software.
-