Direct Memory Access (DMA)
Definition (DMA). Data from a peripheral often have to go into memory; a massive transfer from a fast device (a disk) keeps the CPU busy for a long time (Programmed I-O and InterruptsIn programmed I/O the CPU polls the device in a busy-wait loop and wastes most cycles; with interrupts the interface raises a signal when data are ready, the CPU suspends its work, runs a service routine and returns. Interrupts can be vectored (the device supplies the address of its routine) or non-vectored; with several devices a priority scheme is needed, by software polling, by hardware daisy chain (priority = position in the chain, no parallel handling) or by parallel priority with a priority encoder and a mask register.Programmed I-O and Interrupts →). If the device is allowed to transfer data to memory without involving the CPU, the system is far more efficient: this is DMA. The DMA controller takes control of the buses and directly manages the transfer from the I/O device to memory.
The CPU supports the controller with two signals:
- Bus Request (BR): the DMA controller asks permission to use the bus;
- Bus Granted (BG): the CPU grants the bus and commits not to use it.
The controller contains an address register (the memory address to read or write, incremented after every word transferred) and a word counter. The CPU sees the DMA controller as a peripheral (it programs it with the address and the amount of data); the controller requests or releases the bus depending on the amount of data and the speed of the device; at the end it raises an interrupt to signal that the transfer is over.
Example. To transfer words the controller's address register is incremented times and a single interrupt is raised at the end.
Common mistakes
- Forgetting the final interrupt of the DMA.
- Thinking the CPU takes part in each word transferred: it only programs the controller and grants the bus.
Versione ripasso
- DMA: the controller takes the buses and moves data device to memory without the CPU; suited to fast devices and large blocks.
- Handshake with the CPU: BR (Bus Request) from the controller, BG (Bus Granted) from the CPU.
- Controller: address register incremented after every word, word counter; programmed by the CPU as a peripheral; raises an interrupt at the end. Example: words, address register incremented times, one interrupt.
- Mistakes: final interrupt forgotten; CPU believed to take part in each word.