I/O Systems & Device Management

a device controller

Think of a busy restaurant kitchen. The head chef (the CPU) does not personally fry every egg; each station has its own cook who knows that one job intimately. The chef just calls out an order and gets a plate back when it is ready. A device controller is that station cook. It is a small specialised electronic circuit — often with its own little processor and memory — whose entire job is to operate one kind of device and shield the CPU from its grubby physical details.

Concretely, a controller sits between the system bus and the actual device. It exposes a small set of registers to the CPU: a status register the CPU reads to learn whether the device is idle, busy, done, or in error; a control (command) register the CPU writes to say start a read, start a write, or reset; and one or more data registers through which bytes pass. A typical exchange goes: the CPU writes the command and parameters into the registers, the controller carries out the slow physical operation on its own (moving a disk arm, clocking bits onto a wire), and then it signals back — by setting a status bit the CPU can poll, or by raising an interrupt. Many controllers also have an on-board buffer so they can absorb a whole sector or packet before bothering the CPU.

Why it matters: the controller is the boundary where one specific, weird piece of hardware meets the rest of the computer. Because every device family has its own controller with its own registers and quirks, each needs its own software helper in the OS — the device driver — which knows exactly how to drive that controller. Crucially, a controller is not the device itself: one SATA controller may manage several disks, and a controller can be at fault even when the disk is fine.

A USB keyboard controller watches the key matrix, detects that you pressed the letter g, places its scan code into a data register, and raises an interrupt. The CPU, busy with other work the whole time, is only disturbed for the microseconds it takes to grab that one byte.

The controller does the watching and the waiting so the CPU does not have to.

Do not confuse the controller with the device. The registers the OS reads and writes belong to the controller; the platter, wire, or screen behind it is something only the controller actually touches.

Also called
I/O controllerhost controller控制器