Direct Memory Access (DMA)
While Interrupt-Driven I/O is far better than Polling, it still has a significant bottleneck for large data transfers. For every few bytes moved, the CPU must stop, save its state, execute an ISR, and then restore its state.
For a high-speed disk or network card, this 'Interrupt Overhead' would overwhelm the CPU. Direct Memory Access (DMA) solves this by allowing hardware to move data directly into RAM without the CPU touching a single byte.
The DMA Controller (DMAC)
DMA is implemented using a specialized piece of hardware called the DMA Controller. Think of it as a secondary, 'miniature CPU' whose only job is to manage data transfers.
The DMA Controller has several internal registers that the main CPU must configure before a transfer begins:
| Register | Purpose |
|---|---|
| Address Register | Stores the starting memory address in RAM where data should be moved. |
| Word Count Register | Stores the total number of bytes or words to be transferred. |
| Control Register | Specifies the transfer direction (Read or Write) and the transfer mode. |
The DMA Transfer Process
A typical DMA operation follows these five steps:
- Initialization: The CPU programs the DMA Controller with the RAM address, word count, and I/O device ID.
- DMA Request: When the I/O device is ready, it sends a request to the DMA Controller.
- Bus Request: The DMA Controller asks the CPU for permission to take over the system bus (Address and Data buses).
- Data Transfer: Once the CPU grants permission, the DMA Controller moves data directly from the device to RAM (or vice versa).
- Interrupt: After the *entire* block of data is moved, the DMA Controller sends one single interrupt to the CPU to signal completion.
DMA Modes: Sharing the Bus
Since the CPU and the DMA Controller share the same system bus, they must take turns. There are two primary ways they coordinate:
- Burst Mode (Block Mode): The DMA Controller takes total control of the bus and moves the entire block of data in one go. The CPU is effectively paused during this time. This is fastest for the transfer but blocks the CPU.
- Cycle Stealing Mode: The DMA Controller 'steals' the bus for only one clock cycle at a time to move a single byte, then gives it back to the CPU. This allows the CPU to keep running (albeit slightly slower) during the transfer.
Why DMA is Essential
Without DMA, modern computing would be impossible. High-bandwidth devices like Gigabit Ethernet cards, NVMe SSDs, and Graphics Cards generate far too much data for the CPU to handle manually.
By offloading the 'grunt work' of moving bits to the DMA Controller, the CPU is free to focus on complex calculations, leading to a much smoother multitasking experience.
DMA Concepts
Question 1 of 1Test your knowledge on how DMA interacts with the system.
