Sunteți pe pagina 1din 14

Device Driver

One of the purposes of an operating system is to hide the characteristic of the system's hardware devices from its users. every physical device has its own hardware controller. Each hardware controller has its own control and status registers (CSRs) and these differ between devices. The software that handles or manages a hardware controller is known as a device driver. A device driver or software driver is a computer program allowing higher-level computer programs to interact with a hardware device.

Ramanuj Chouksey

Purpose of a Device Driver


A device driver simplifies programming by acting as translator between a hardware device and the applications or operating systems that use it. Programmers can write the higher-level application code independently of whatever specific hardware device.

Ramanuj Chouksey

Overall Architecture
System Call Interface VFS File Systems Buffer Cache Block Character Device Driver Device Driver Network Protocol Socket

Network Device Driver

Hardware

Device Types
Linux supports three types of hardware devices: Character block Network Character devices are read and written directly without buffering. character devices provide only a serial stream of input or output; Examples include printers, scanners, sound boards, keyboard.

Device Types
Block devices can only be written to and read from in multiples of the block size, typically 512 or 1024 bytes. Block devices are accessed via the buffer cache and may be randomly accessed. Block devices can be accessed via their device special file but more commonly they are accessed via the file system. Only a block device can support a mounted file system. For example, disks are commonly implemented as block devices. Network devices are accessed via the BSD socket interface a

Ramanuj Chouksey

device file
A device file or special file is an interface for a device driver that appears in a file system as if it were an ordinary file. They allow software to interact with a device driver using standard input/output system calls, which simplifies many tasks and unifies user-space I/O mechanisms. There are two general kinds of device files in Unix-like operating systems, known as
character special files block special files

The difference between them lies in how data written to them and read from them is processed by the operating system and hardware

device file
device file is a special type of file. A device file points to an inode that contains some associated information: a major device number and a minor device number. When you carry out a file operation on a device file, the system uses the major number to determine which device driver to use to read data from or write data to the device. (The minor number is used internally by the device driver.) Device file allows transparent communication between user space applications and computer hardware.

Major and Minor Numbers


Major number
Each device driver is identified by a unique major number. This number is assigned by the Linux Device Registrar (This number is the index into an array that contains the information about the driver (the device_struct)

Minor number
This uniquely identifies a particular instance of a device. For example, a system may have multiple IDE hard disks each would have a major number of 3, but a different minor number.

Interfacing Device Drivers with the Kernel


Each class of device driver, character, block and network, provides common interfaces that the kernel uses when requesting services from them. These common interfaces mean that the kernel can treat often very different devices and their device drivers absolutely the same.

Ramanuj Chouksey

Interfacing Device Drivers with the Kernel


Linux allows you to include device drivers at kernel build time via its configuration scripts. Other drivers can be loaded as kernel modules when they are needed. To cope with this dynamic nature of device drivers, device drivers register themselves with the kernel as they are initialized. Linux maintains tables of registered device drivers as part of its interfaces with them. These tables include pointers to routines and information that supports the interface with the device class.

Ramanuj Chouksey

Character Devices
Character devices, the simplest of Linux's devices, are accessed as files, applications use standard system calls to open them, read from them, write to them and close them exactly as if the device were a file. As a character device is initialized its device driver registers itself with the Linux kernel by adding an entry into the chrdevs vector of device_struct data structures. The device's major device identifier is used as an index into this vector

Ramanuj Chouksey

Character Devices
Each entry in the chrdevs vector, a device_struct data structure contains two elements: pointer to the name of the registered device driver pointer to a block of file operations. The block of file operations is itself the addresses of routines within the character device driver, each of which handles specific file operations such as open, read, write and close.

Ramanuj Chouksey

Example of reading a character


A read request is made to the device driver (C-1 to C-3). The character is captured by the hardware (I-4 and I-5). The interrupt is generated (I-6). The interrupt handler services the interrupt (I-7 to I-9). The character is returned (C-10 to C-13).

S-ar putea să vă placă și