DMA
is a method which is used to lift input/output (I/O) handling burden
off the CPU to increase the overall efficiency of a computer in terms
of speed.
- For some jobs, the CPU can delegate I/O handling to another helper hardware called DMA controller while it can continue other jobs requiring CPU processing. The reason for CPU to delegate I/O job is that I/O devices are very slow compared to CPU and performing I/O degrades the overall performance of CPU hugely. There are five main components in DMA:
- 1. CPU
- 2. DMA controller
3. Memory
- 4. I/O device
- 5. System
buses (Data & Address buses etc.)
Prior
to DMA operation, some steps have to be completed:
1. To activate DMA, CPU has to give permission to the DMA controller (DMAC) to take over the bus whenever necessary by setting the DMA Select signal.
2. CPU has to set some registers in the DMAC with necessary information for the I/O operation such as memory address register for DMAC to know what to read, from where to read and where to write.
3. Using the information in its registers, DMAC has to read some data into its internal buffer from the I/O device before DMA takes place.
Assuming
all the prior jobs completed, DMA can be performed by following the
steps below in order:
1. DMA send Bus Request (BR) signal to the CPU to ask permission to take over the bus.
2. CPU lets DMAC to use the bus via the Bus Grant (BG/BGRT) signal after completing some certain steps in its instruction cycle.
3. DMAC writes data from its internal buffer to a certain memory location until all bytes are transferred. In this step, how many bytes are transferred so far is stored in a internal counter called word count register. If CPU takes control away from the DMAC by resetting Bus Grant (BG/BGRT) signal; the next time DMAC takes control, it continues to transfer the rest of the data in the data buffer until word count register shows that there are 0 bytes left to transfer.
4. DMAC sends an interrupt to the CPU to continue using the bus again.
As can be seen, CPU is in the control of DMAC and DMA is a mechanism to lift the I/O burden off the CPU. Hence, DMAC is not a must-to-have hardware component in a computer; but a very important one to have in modern computers to utilize the CPU performance to its full.
We
did not mention disk
controller as
a component of DMA in this post since in modern computers disk or ram
controllers may have built-in DMAs inside them.
However, if one has
to think DMA separately from a disk controller, we can say that
internal buffer that has to be filled before DMA takes action belongs
to the disk controller whereas the registers like memory address
register belong to the DMA controller. Moreover, still, DMA
controller determines which byte to transfer when in this case.