DMA refers to the ability of an I/O device to transfer data directly to and from memory without going through the CPU. Contrast DMA with programmed I/O where the CPU explicitly copies data using loads & stores.
- Higher transfer bandwidth (one bus op instead of two)
- CPU can do other things during transfer
- Faster, more consistent response times (no interrupt or polling overhead)
- Hardware more complicated: I/O device must know how to become bus master, issue transactions, etc. (all while still acting as a slave too)
- Software more complicated
- DMA transfer takes bus away from CPU (can limit ability of CPU to do other stuff)
- Overhead to set up transfer: need to transfer many bytes to overcome
- Starting address of memory buffer
- Number of bytes to transfer
- Transfer direction (to/from device, read/write on bus)
- device-specific control (e.g., head, cylinder, sector for disk access)
- Program makes I/O request to device
- CPU does initiation routine (usu. part of device driver)
- use programmed I/O (stores) to set up control regs
- device-specific parameters
- DMA parameters (buffer address/length)
- last write: enable (start) bit
- I/O device interface does transfer
- Arbitrate for bus mastership
- Put address on bus, assert control signals to do read/write (looks just like CPU to memory)
- Likely use burst transfer if available
- Size/type may be programmable via control reg
- I/O device supplies/consumes data
- Increment address, decrement byte count
- If byte count > 0, repeat
- Release bus to give other devices a chance
- if byte count == 0, set completion bit in status reg, generate interrupt
- CPU ISR runs completion routine (also part of driver)
- check for errors, retry if necessary
- notify program that transfer is done (e.g., set flag variable in memory)
- set up next transfer if appropriate (call initiation routine)
- Program notices that request is complete