Linux Device Drivers
Linux Device Drivers
Linux Device Drivers
software
hardware
A device driver must provide the following features:
● A set of routines that communicate with a hardware device
and provide a uniform interface to the operating system
kernel.
● A self-contained component that can be added to, or removed
from, the operating system dynamically.
● Management of data flow and control between user programs
and a peripheral device.
● Most device drivers are accessed through the file system. In
Linux, “/dev” directory is populated with the device special
files, and its contents look like any other directory.
$ls –l /dev
brw-rw---- 1 root disk 22, 1 Aug 5 2007 hda1
crw-rw---- 1 root lp 6, 0 Aug 5 2007 lp0
Device Driver- user,kernel & hardware interface:
Kernel
The kernel is the central component of most computer
operating systems; it is a bridge between applications and the
actual data processing done at the hardware level. The kernel's
responsibilities include managing the system's resources (the
communication between hardware and software components).
Kernels
.
int init_module(void)
{
printk(KERN_DEBUG “Hello, Kernel!\n”);
return 0;
}
void cleanup_module(void)
{
printk(KERNEL_DEBUG ”Good-bye, kernel!\n”);
}
MODULE_LICENSE(“GPL”);
The kernel equivalent of printf is printk. They are similar usage, but the latter
does not support printing of floating point. The KERN_DEBUG define given to
printk sets the priority of the printed message.
The possible values of priority of the printed message are defined by
linux/kernel.h as follows:
#define KERN_EMERG “<0>” /* system is unusable */
#define KERN_ALERT “<1>” /* action must be taken immediately*/
#define KERN_CRIT “<2>” /* critical conditions */
#define KERN_ERR “<3>” /* error conditions */
#define KERN_WARNING “<4>” /* warning conditions */
#define KERN_NOTICE “<5>” /* normal but significant condition */
#define KERN_INFO “<6>” /* informational */
#define KERN_DEBUG “<7>” /* debug-level message */
mknod /dev/MyCharDevice c 22 0
The init function sets up the queue, and associates the driver's
request function with the queue.