Input-Output Modules and Programmed Input-Output
In questa pagina 5
In questa pagina 4
Why an I/O module
Peripherals differ greatly (formats, speeds from a few bytes/s for a keyboard to GB/s for an SSD) and almost all are slower than the CPU. Connecting them directly to the bus would be impossible: the I/O module (controller, interface) acts as an intermediary between the system bus and one or more devices.
Functions:
- control and timing of the data flow;
- communication with the CPU: command decoding, data exchange, status reporting, recognition of its own address;
- communication with the device: commands, status, data;
- buffer: absorbs the speed difference;
- error detection (mechanical, transmission).
The device performs transduction: it converts between binary data and physical quantities (movement, light, sound, magnetisation).
The module presents the CPU with registers: data, status (for example "ready" bit, "error" bit) and control (commands).
Addressing of devices
Definition (memory-mapped I/O and isolated I/O)
Memory-mapped I/O Isolated I/O address space single: the module registers occupy memory addresses separate for I/O instructions the same load/store as memory dedicated instructions ( IN,OUTin x86)pros no special instructions; all addressing modes available the memory space stays entirely for memory cons uses up memory addresses limited set of I/O instructions
Example. In ARM (memory-mapped I/O) the data register of the UART at 0x101F1000 is written with STRB r0, [r1], the same instruction as a store to memory.
ARM uses memory-mapped I/O. Example: the status register of a UART at 0x101F1018, bit 5 = "transmit buffer full", data register at 0x101F1000.
Programmed I/O
Definition (programmed I/O with polling). The CPU does everything: it gives the command, then repeatedly interrogates the status register (polling) until the device is ready, then transfers the datum.
Example. With a printer of characters/s and a CPU of instructions/s, about polling instructions are wasted for each character.
LDR r1, =0x101F1000 @ base of the UART
wait: LDR r2, [r1, #0x18] @ reads the status register
TST r2, #0x20 @ bit 5: buffer full?
BNE wait @ yes: wait (busy waiting)
STRB r0, [r1] @ no: writes the character to the data registerProblem: busy waiting. If the CPU executes instructions per second and a printer accepts 1000 characters per second, for each character the CPU wastes about a million instructions checking the status.
The three techniques
Definition (programmed I/O, interrupt-driven I/O and DMA)
Data transfer Who waits Programmed I/O CPU the CPU, busy waiting Interrupt-driven I/O (see Interrupts and ExceptionsClasses of interrupts; interrupt-driven I/O; hardware and software handling sequence with context saving on the stack; identifying the source (multiple lines, polling, daisy chain, vector); priorities and nested interrupts; exceptions and modes in ARM.Interrupts and Exceptions →) CPU nobody: the module warns the CPU when ready DMA (see Direct Memory AccessThe DMA module and the information it receives from the CPU; block transfer with a single final interrupt; cycle stealing and burst mode, points where the CPU may be suspended; bus configurations; channels and I/O processors; quantitative comparison with interrupt-driven I/O.Direct Memory Access →) DMA module, directly with memory nobody: the CPU is warned only at the end of the block
Example. For a block of words interrupt-driven I/O requires interrupts, DMA only one, at the end of the block.
Typical mistakes
- Thinking that with memory-mapped I/O the data pass through the cache: device registers must be marked non-cacheable, otherwise the CPU would read stale values.
- Confusing isolated I/O (separate address space) with "peripheral not connected to the bus".
Versione ripasso
Module
Intermediary between system bus and devices (very different formats and speeds, mostly slower than the CPU). Functions: control and timing, communication with CPU and device, buffer, error detection. Device does transduction. Registers: data, status (ready, error), control.
Addressing
- Memory-mapped: registers in the memory space, ordinary load/store, all addressing modes; uses addresses. ARM uses this: UART data
0x101F1000, status0x101F1018(bit 5 = transmit buffer full), written withSTRB r0,[r1]. - Isolated: separate space, dedicated instructions (
IN,OUTon x86), memory space kept whole.
Programmed I/O
CPU gives the command and polls the status register: LDR r2,[r1,#0x18]; TST r2,#0x20; BNE wait; STRB r0,[r1]. Busy waiting: printer 1000 char/s on a instr/s CPU wastes about instructions per character.
Three techniques
1024 words: 1024 interrupts against 1 with DMA.
Typical mistakes: device registers must be non-cacheable; isolated I/O means a separate address space, not a device off the bus.