Principles of I/O Hardware

Filter Course


Principles of I/O Hardware

Published by: Zaya

Published date: 22 Jun 2021

Principles of I/O Hardware Photo

Principles of I/O Hardware

• Different people look at I/O hardware differently
• Electrical engineers look in terms of chips, wires, motors, power supplies, and other physical components that make up the hardware
• Programmers look at the interface presented to the software (the commands the hardware accepts, the function it carries out, and the errors that can be reported back)
• We are concerned with programming I/O devices, not designing, building, or maintaining them.
• Our interest is restricted to how the hardware is programmed not, how it works inside.

I/O devices

I/O devices are the pieces of hardware used by a human (or another system) to communicate with a computer. For instance, a keyboard or computer mouse is an input device for a computer, while monitors and printers are output devices. Devices for communication between computers, such as modems and network cards, typically perform both input and output operations.

I/O devices can be roughly divided into:

i. Block devices

  • stores information in a fixed-sized block, each one with its own address.
  • common block size ranges from 512 bytes to 32,768 bytes
  • the data transfer takes place in blocks
  • block addressable not byte addressable
  • e.g. Hard disks, CD-ROMs, USB sticks, etc.

ii. Character devices

  • delivers or accepts a stream of characters, without regard to any block structure
  • they are not addressable
  • e.g. printers, network interfaces, mice, etc.

DEVICE CONTROLLERS

• A device controller is a piece of hardware that receives commands from the system bus, translates them into device actions, and reads/writes the data onto the system bus.
• I/O devices typically consist of two components: electrical and mechanical
• The electronic component is called the device controller or the adapter
• A device controller is a part of a computer system that makes sense of the signals going to, and coming from the CPU
• There are many device controllers in a computer system
• Any device connected to the computer is connected by a plug and socket, and the socket is connected to a device controller
• In a personal computer, device controller usually takes the form of a chip on the parent board
• Many controllers can handle two, four, or even eight identical devices

device controllers

Memory-mapped I/O

  • Memory-mapped I/O uses the same address bus to address both memory and I/O devices
  • The memory and registers of the I/O devices are mapped to (associate with) address values.
  • When an address is accessed by the CPU, it may refer to a portion of physical RAM, but it can also refer to the memory of the I/O device.
  • The CPU instructions used to access the memory can also be used for accessing devices.
  •  Each I/O device monitors the CPU's address bus and responds to any CPU access of an address assigned to that device, connecting the data bus to the desired device's hardware register.
  • To accommodate the I/O devices, areas of the addresses used by the CPU must be reserved for I/O and must not be available for normal physical memory.

DMA – Direct memory access

Direct Memory Access (DMA) is a method that allows an input/output (I/O) device to send or receive data directly to or from the main memory, bypassing the CPU to speed up memory operations. CPU is only involved at the beginning and end of the transfer and interrupted only after the entire block has been transferred. Slow devices like keyboards will generate an interrupt to the main CPU after each byte is
transferred. If a fast device such as a disk generated an interrupt for each byte, the operating system would spend most of its time handling these interrupts. So a typical computer uses direct memory access (DMA) hardware to reduce this overhead.
Direct Memory Access needs special hardware called DMA controller (DMAC) that manages the data transfers and arbitrates access to the system bus. The controllers are programmed with source and destination pointers (where to read/write the data), counters to track the number of transferred bytes, and settings, which include I/O and memory types, interrupts, and states for the CPU cycles.

Advantage

  • Free up CPU
  • high transfer rates
  • fewer CPU cycles for each transfer

Disadvantages

  • DMA transfer requires a DMA controller to carry out the operation, hence more expensive system
  • synchronization mechanisms must be provided in order to avoid accessing non-updated information from RAM

Use CPU over DMA if

  • device speed is fast
  • CPU has nothing to do (if CPU is free)

Working of DMA

DMA