Sei sulla pagina 1di 39

Updated July 2015

 Definition:

a) A device driver is a piece of software that


interfaces a particular piece of hardware.
b) A device driver is a program that controls a
particular type of device that is attached to your
computer.

2
3
4
5
 Device driver can be developed separate from OS
because of new functions can be added to the
driver without requiring the operating system to
modified, recompiled and redistributed

 In general, the manufacturer of the device supplies


the device drivers. However, the device drivers may
differ according to the operating system type and
its version.

6
 Operating system does not need to change its code
again and again to incorporate any new device. Its
I/O software (generic device driver) takes care of all
the I/O devices to be interfaced with the system
without changing the OS code

 Each device needs a device-specific code in the


form of device driver for controlling it. Eg device
driver for printers, hard disks etc.

 When you buy an operating system, some device


drivers are already built-in into the product.

7
 Driver responsibilities:
◦ Initialize devices
◦ Interpreting command from OS
◦ Schedule multiple outstanding requests
◦ Manage data transfer
◦ Accept and process interrupts

 Device Drivers manage the complexity and


differences among specific types of devices (disk,
mouse).
 It manages queues and buffers (special storage
holds stream of bits from device and sent them to
the CPU).
8
 divided into two pieces:
◦ Top half: accessed in call path from system calls
 implements a set of standard, cross-device calls
like open(), close(), read(), write(), ioctl(),
strategy()
 This is the kernel’s interface to the device driver
 Top half will start I/O to device.

◦ Bottom half: run as interrupt routine

9
User Program

Kernel I/O
Subsystem

Device Driver

Top Half

Device Driver
Bottom Half

Device Hardware

10
 A device controller, also known as an adapter, is an
electronic device in the form of chip or circuit that
controls the communication between the system
and the I/O device.

 It is inserted into an expansion slot of the mother


board. It functions as a bridge between the device
and the operating system, i.e., the operating
system deals (via device driver) with the device
controller of the device to which it wishes to
communicate.

 . 11
 Device controller takes care of low level operations
such as error checking, data transfer, and location
of data on the device.

 Each device controller is designed specifically to


handle a particular type of device but a single
controller may also handle multiple devices.

 .

12
 The device driver communicates with the device
controllers and thereby with the device with the
help of interrupt-handling mechanism.

 Each device has a device controller that has some


device registers for performing I/O operations on
the device. But the number of device registers and
the nature of commands for performing I/O
operations vary from device to device

 .
13
 For the purpose of communication with the
processor, each device controller has a set of
following device registers :
 Control (Command) Register
 These are used by the processor to configure and control the
device (eg giving commands. )
 Status Register
 These registers provide the status information about an I/O
device to the processor.
 Data Register
 This register is used to read and write data from/to the I/O
device.

14
The operating system performs I/O operations with the
use of these registers only by sending commands to an
appropriate register. The parameters of the commands
are loaded first into the controller’s registers.

15
 When a command has been completed, the
controller triggers an interrupt to inform the
operating system that the desired operation has
been completed.

 The operating system after gaining the control


again gets the result of the operation and checks
device status by reading information from the
controller’s registers.

16
17
 When the device controller interacts with the actual
device, the data are transferred between the actual
device and the controller according to the I/O
operation, i.e., the data from the device are written
to the controller’s register in case of input
operation or the data from the controller’s register
are sent to the device in case of output operation.

 After completion of I/O operation at the level of


device and device controller, the device controller
generates an interrupt to the device driver

18
 Each device has a device controller that has some device
registers for performing I/O operations on the device. But the
number of device registers and the nature of commands for
performing I/O operations vary from device to device.

 Therefore, to communicate with each type of device


controller, a specific code in the form of a device driver is
written, which takes care of the specific device controller
registers and the commands.

 Thus, the device drivers act as a layer that hides the


differences among the device controllers.

19
20
 A device controller is a part of a computer
system that makes sense of the signals going
to, and coming from the CPU.
 Any device connected to the computer is
connected by a plug and socket, and the
socket is connected to a device controller.
 It functions as a bridge between the device
and the operating system.
 The electrical part of an I/O device is known
as a device controller and can take the form
of a chip on personal computers.

21
 The Device Controller receives the data from
a connected device and stores it temporarily
in some special purpose registers (i.e. local
buffer) inside the controller.
 Then it communicates the data with a Device
Driver .
 For each device controller there is an
equivalent device driver which is the standard
interface through which the device controller
communicates with the Operating Systems.

22
Device
Device Interrupt Device Operating
Controller
Handling Driver System
Device Device
Device
Controller
Driver
:
: :
: :
Device :
Device
Device
Driver
Controller
Device I/O System

 Manage the complexity and differences among specific types


of devices (disk vs. mouse, different types of disks …)
 Each handles one type of device or small class of them (eg
SCSI)

23
 Function:
◦ To provide a standard interface.
◦ responsible for moving data between the peripheral device
it controls and its local buffer storage.

User level User Applications

Various OS components
OS level
Device Drivers

Device Controllers
Hardware
I/O Devices

24
 3 register in device controller :
◦ Command: a command register to which the device driver
can write device commands to start an operation on the
device.
◦ Status : the device driver can read to determine if the I/O
operation completed successfully, or if the most recent
device operation resulted in an error, the status register will
report the nature of the error.
◦ Data : that is to be written to the device is store before
starting the write operation, or where the result of a read
operation is retrieved when the device finishes the read
operation.

25
 Device driver loads the register within the device
controller. Device Driver gives an instruction to
devices to perform the operation.
 Device controller examines the contents of the
command register.
E.g. Read request from the keyboard
 Controller starts transfer data from the device to its
local buffer (data reg).
 Data complete transfer → device controller informs
device driver that is has finished its operation via
an interrupt.

26
 Transfer a block of data (bytes) directly to/ from
its own buffer storage to memory.
 DMA saves CPU time by controlling data transfer
between I/O device and memory.

Direct memory
access (DMA)
is a feature of computer
systems that allows certain
hardware subsystems to
access main system memory
(RAM) independently of the
central processing unit
(CPU).

27
 Device Management is the part of the OS that
manages hardware devices. Each operating system
defines architecture for its Device Management
system
 Device Management notifies all applications and
system features of changes that may affect their
operation or access to resources.
 Provide a uniform interface to ease the access to
devices with different physical characteristics
 It is implemented through the interaction of a
Device Driver and Interrupt routine.

28
 Responsibilities:
◦ Must track the state of the device: when it is idle,
when is being used and by which process
◦ Must maintain the information in the device
status table
◦ May maintain a device descriptor to store other
information about the device
◦ Choose the most efficient way to allocate all of
the system’s device, printers, terminals, disk
drives.
◦ Makes the allocation starts its operation
◦ Deallocates the device

29
Application
process
API(Device Driver API)

File Manager

Device Driver
Hardware

Interface (Device Driver Interface)

Command Status Data

Device Controller

30
31
 Device driver types(Unit of transfer)
◦ Block : fixed sized block data transfer (eg disk)
Character ; variable sized data transfer (device accepts and
delivers the data as a stream of characters
/bytes)
Network : need special I/O interfaces (eg sockets) to send
or receive data on a network. Streams for
networking
 Character :
◦ Read - Reads “size” bytes from a byte stream device to
“bufferAdd”
◦ Write - Write “size” bytes from “bufferAdd” to a byte stream
device.
◦ Implements at least the open, close, read, and write system
calls.
◦ USB serial port for printer, terminal 32
 Block device interface
◦ Read - Transfer a block of data from “deviceAddr”
to “bufferAdd”
◦ Write - Transfer a block of data from “bufferAdd”
to “deviceAddr”.
◦ USB memory card reader, hardisk, pendrive
 Network interface:
◦ Able to exchange data with other hosts.
◦ Sending and receiving data packets, driven by the
network subsystem of the kernel
◦ Designed around the transmission and receipt of
packets.
◦ USB Ethernet interface
33
 API (Application Programming Interfaces) is
an application method that can be used to
access a certain function.

 System API provides the Interface between


applications and system resources through
System Calls.

34
 Provides a set of functions that an
programmer can call to manage a device
 open/close functions to allow
initiate/terminate of the device’s use
◦ open – allocates the device and initializes the
tables and the device for use
◦ close – releases dynamic tables entries and
releases the device
 read/write functions to allow the
programmer to read/write from/to the
device
35
◦ A consistent way to do these operations across all
the devices is not possible; so a concession by
dividing the devices into classes is made:
 such as character devices or block devices
 Sequential devices or randomly accessed
devices
 ioctl function to allow programmers to
implement device specific functions.

36
 Device-specific code in the kernel interacts
(via device driver) with the device hardware.
◦ Supports a standard and internal interface
◦ Same kernel I/O system can interact easily with
different device drivers
◦ Special device-specific configuration supported
with the ioctl() system call

37
 The primary purpose of the Kernel is to manage
system resources, and provide an interface so
other programs can access these resources

38
Application Application Application User Space

System Call Interface (Device Driver API)

Kernel Space
Kernel Subsystem (Driver-Kernel Interface)

Device Drivers

Disk Controller USB Controller Disk Controller

Hardware
disks
printer disks

39

Potrebbero piacerti anche