Friday, March 14, 2008

device drivers

an essential part of the operating system..

a very interesting and challenging subject for system programmers..
device drivers are the programs which allow high-level programs to interact with the hardware..
now all that am going to talk about is device drivers in unix and unix-like os.

in a programmer's point of view there are four types of drivers..
* char drivers(read/write char by char eg..floppy,mouse)
* block drivers(block by block.eg.filesystems..hard drivers)
* terminal drivers(ttys)
* stream drivers(don knw much abt these.neva worked..must be related to stream interface functions)

in unix/linux device drivers can be part of the kernel or can be loadable modules..
modules are the programs which can be loaded into the kernel during run-time..these are generally called

kernel-modules..(refer d book kernel-module programming

u can find many books on linux kernel module programming(lkmp)..but make sure that they deal with kernel 2.6 and above..
cos lkmp slightly differs from 2.4.* to 2.6.*.

after writing the kernel module we can load them into the kernel using the insmod..
if ur module name is hello.c
then u gotta load its .ko
bit4054@VITLINUX$ insmod ./hello.ko


to check whether ur module is loaded or not u can check the name of the loaded module in /proc/modules
just give
bit4054@VITLINUX$ cat /proc/modules

and also u can check for the symbol table in

bit4054@VITLINUX# cat /proc/kallsyms

the above file contains the kernel symbol table..

and to remove the module

bit4054@VITLINUX$ rmmod ./hello.ko

in this way a module is written and loaded into the kernel..

like wise u can write a device driver..
there are few basic operations which are essential in a driver programming..

open()

read()

write()

ioctl()

poll()

close()

but its a very painful task cos u gotta knw about the h/w at the bit-level

there are many APIs that wil help u in writing a driver..and u need good testing environments..
few of the APIs are:


  • Advanced Linux Sound Architecture (ALSA) - The standard modern Linux sound driver interface
  • I/O Kit - an open-source framework from Apple for developing Mac OS X device drivers
  • Installable File System (IFS) - a filesystem API for IBM OS/2 and Microsoft Windows NT
  • Network Driver Interface Specification (NDIS) - a standard network card driver API
  • Open Data-Link Interface (ODI) - a network card API similar to NDIS
  • Scanner Access Now Easy (SANE) - a public domain interface to raster image scanner hardware
  • Uniform Driver Interface (UDI) - a cross platform driver interface project
  • Windows Display Driver Model (WDDM) - the new graphic display driver architecture for Windows Vista
  • Windows Driver Foundation (WDF)
  • Windows Driver Model (WDM)



i have tried writing and running few basic kernel modules but still learning to write device drivers..

u can refer many books linux device drivers alessandro rubini 3rd edition..(note:2nd edition deals only with kernel 2.4.*)

writing unix device drivers.(don remember the author name)..

and am sure this post wil give u a very very basic knowledge on drivers..

No comments: