Device driver

Device driver is a program for managing each I/O device connected to a computer. The controller of each device has a set of registers to give the command being controlled to the device and to read its state. For example, a disk management program should know about sectors, tracks, cylinders, heads, their movement and installation time.

Device driver is a program for managing each I/O device connected to a computer

The driver is usually written by the manufacturer and distributed with the device. Since special drivers are required for each operating system, device manufacturers usually supply drivers for several of the most popular operating systems. Each device driver supports one type or, at most, a class of nearby devices.

To access the hardware of the device, i.e. to controller registers, the device driver must be part of the operating system kernel. But it is possible to create a driver that works in user space. This would isolate the kernel from the drivers, and the drivers from each other.

The operating system usually classifies the drivers into several categories according to the types of devices they serve. The most common categories are block, for example, disks containing data blocks to which independent addressing is possible, and symbolic devices such as keyboards and printers that form or receive a stream of characters.

In most operating systems, two standard interfaces are defined, one of which must support all block drivers and the second one all symbolic interfaces.

The device driver performs several functions:

  1. handling abstract read requests and writing independent of devices and software located above them;
  2. initializing the device;
  3. power management and event logging
  4. check input parameters. If they do not meet certain criteria, the driver returns an error.
  5. Check the device usage at the moment. If the device is busy, the request can be queued. If it is free, its condition is checked. Once the device is ready, the actual control can start - issuing a series of commands to it. It is in the driver and the sequence of commands is determined depending on what needs to be done. After defining the commands, the driver starts to write them to the controller registers of the device.

After the driver passed all commands to the controller, the situation can develop in two scenarios. In many cases, it must wait until the controller does some work for it, so it is blocked until the interrupt from the device unlocks it. In other cases, the operation completes without delay and the driver does not need to be blocked.

When the operation is completed, the driver must check whether the operation has completed without errors. If everything is ok, the device driver may need to transfer data to the software. Then it returns some information to the calling program about the completion of the operation.

Drivers are not allowed to access system calls, but they often need to interact with the rest of the kernel. To do this, they can be called by some system procedures, for example, to allocate them to fixed memory pages as buffers, and also to return these pages back to the core of the operating system.