Io Device Management
Io Device Management
management
Introduction
• The two main jobs of a computer are I/O and
processing. In many cases, the main job is I/O and
the processing is merely incidental. For instance,
when we browse a web page or edit a file, our
immediate interest is to read or enter some
information, not to compute an answer.
• It must issue commands to the devices, catch
interrupts, and handle errors. It should also provide
an interface between the devices and the rest of the
system that is simple and easy to use. To the extent
possible, the interface should be the same for all
devices. The I/O code represents a significant
fraction of the total operating system.
Principles of I/O hardware
• Different people look at I/O hardware in different
ways. Electrical engineers look at in terms of chips,
wires, power supplies, motors, and all the other
physical components that make up the hardware.
• Programmers look at the interface presented to the
software- the commands the hardware accepts, the
functions it carries out, and the errors that can be
reported back.
• Here we are concerned with programming I/O
devices, not designing, building, or maintaining
them.
1. I/O Devices
• I/O devices can be roughly divided into two categories:
block devices and character devices.
• A block device is one that stores information in fixed- size
blocks, each one with its own address. Common block sizes
range from 512 bytes to 32,768 bytes. All transfers are in
units of one or more entire blocks. The essential property
of a block device is that it is possible to read or write each
block independently of all the other ones. Hard disks, CD-
Roms, and USB sticks are common block devices.
• A character device delivers or accepts a stream of
characters, without regard to any block structure. It is not
addressable and does not have any seek operation.
Printers, network interfaces, mice and most other devices
that are not disk- like can be seen as character device.
2. Device Controllers
• I/O units typically consist of a mechanical component and an
electronic component. The electronic component is called the
device controller or adapter. On personal computers, it often
takes the form of a chip on the parent board or a printed circuit
card that can be inserted into a (PCI) expansion slot.
• The controller card usually has a connector on it, into which a
cable leading to the device itself can be plugged. Many
controllers can handle two, four, or even eight identical devices.
• The interface between the controller and device is often a very
low-level interface. What actually comes off the drive, however,
is a serial bit stream and finally a checksum. The controller’s job
is to convert the serial bit stream into a block of bytes and
perform any error correction necessary. The block of bytes is
typically first assembled, bit by bit, in a buffer inside the
controller. After its checksum has been verified and the block
has been declared to be error free, it can be copied to main
memory.
3. Memory –Mapped I/O
• Each controller has a few registers that are used for
communicating with the CPU. By writing into these
registers, the operating system can command the device to
deliver data, accept data, switch itself on or off, or
otherwise perform some action. By reading from these
registers, the operating system can learn what the device
state is, whether it is prepared to accept a new command,
and so on.
• The issue thus arises of how the CPU communicates with
the control registers and the device data buffers. For this
we map all the control registers into memory space. Each
control register is assigned a unique memory address to
which no memory is assigned. This system is called
memory-mapped I/O. Usually, the assigned address are at
the top of the address space.
4. DMA(Direct Memory Access)
• No matter whether a CPU does or does not have
memory-mapped I/O, it needs to address the device
controllers to exchange data with them. The CPU can
request data from an I/O controller one byte at a time,
but doing so wastes the CPU’s time, so a different
scheme, called DMA (Direct Memory Access) is often
used.
• Direct Memory Access (DMA) is a feature in computer
systems that allows peripherals to transfer data to and
from the system's memory without involving the central
processing unit (CPU). DMA is used to improve overall
system performance by offloading data transfer tasks from
the CPU, which can then focus on other processing
activities.
• First the CPU programs the DMA controller by setting its
registers so it knows what to transfer where (step 1 in Fig. 5-4).
It also issues a command to the disk controller telling it to read
data from the disk into its internal buffer and verify the
checksum. When valid data are in the disk controller’s buffer,
DMA can begin.
• The DMA controller initiates the transfer by issuing a read
request over the bus to the disk controller (step 2). This read
request looks like any other read request, and the disk controller
does not know (or care) whether it came from the CPU or from a
DMA controller.
• Typically, the memory address to write to is on the bus’ address
lines, so when the disk controller fetches the next word from its
internal buffer, it knows where to write it. The write to memory
is another standard bus cycle (step 3).
• When the write is complete, the disk controller sends
an acknowledgement signal to the DMA controller, also
over the bus (step 4). The DMA controller then
increments the memory address to use and
decrements the byte count.
• If the byte count is still greater than 0, steps 2 through
4 are repeated until the count reaches 0. At that time,
the DMA controller interrupts the CPU to let it know
that the transfer is now complete. When the operating
system starts up, it does not have to copy the disk
block to memory; it is already there.
PRINCIPLES OF I/O SOFTWARE