What is DMA (Direct Memory Access) Controller?

In this course, we will study What is DMA (direct memory access), the modes of transferring information, the direct memory access (DMA) controller, the working of the DMA controller, advantages and disadvantages of the DMA controller.

What is DMA (Direct Memory Access)?

Whenever we have to access memory we have to first go to the CPU and then the CPU goes to memory. But in DMA (direct memory access) we can directly access the memory from the input/output device.

We can define it as Direct Memory Access (DMA) transfers the block of data between the memory and peripheral devices of the system, without the participation of the processor. There is a unit that controls the activity of accessing memory directly and is called a DMA controller.

The DMA controller takes over the buses by the following two commands:

  • Bus Request: It is used by the DMA controller to request the CPU to give control of the buses.
  • Bus Grant: It is activated by the CPU. This is to inform the external DMA controller that the buses are in a high impedance state and that the requesting DMA can take control of the buses. Once the DMA takes control of the buses it transfers the data. This transfer can take place in many ways.

What is DMA?

What are the modes of transferring the information?

There are three possible ways in which the information can be transferred from the CPU to the external devices.

  1. Programmed i/o
  2. Interrupt initiated i/o
  3. Direct memory access (DMA)

What is Programmed i/o?

It is due to the result of the I/O instructions that are written in the program. The transfer of each data item is initiated by an instruction in the program. The CPU register and memory do the transfer. In this case, constant monitoring is required by the CPU of the peripheral devices.

What is Interrupt Initiated i/o?

The situation where the CPU is kept busy unnecessarily can very well be avoided by using an interrupt-driven method for data transfer. We can use the interrupt feature and special commands to inform the interface to issue an interrupt request signal whenever data is available from any device.

The CPU can proceed with any other program execution in the meantime. The device is monitored by the interface. Whenever the device is ready to transfer data, it sends an interrupt request signal to the computer. Upon detection of an interrupt signal, the CPU stops the task that it was already performing. And branches to the service program to process the I/O transfer and then returns to the task it was originally doing.

What is a DMA Controller?

DMA provides an interface between the controller bus and input-output devices. Although it transfers data without the intervention of the processor, it is controlled by the processor. The processor initializes the DMA controller by sending the starting address, the number of words in the data block, and the direction of transfer of data. That is, from I/O device to memory or from main memory to I/O device. More than one external device can be connected to a DMA controller.

There are three modes in which the DMA controller transfers the data:

Burst Mode

In this, when the DMA controller gains the charge of the system bus, it releases the system bus only when there is a complete data transfer. Until then the CPU will have to wait for the system buses.

Cycle Stealing Mode

In this mode, the DMA controller forces the CPU to stop its operation and relinquish control over the bus for a short term to the DMA controller. After the transfer of every byte has been done, the DMA controller releases the bus and then again sends a request for the system bus. In this way, the DMA controller takes the clock cycle for transferring every byte.

Transparent Mode

In this case, the DMA controller takes the charge of system bus only if the processor does not require the system bus.

How does the DMA Controller Work?

The bus is to be shared between the DMA controller and the processor to make the data transfer. The device which keeps the bus at a fixed time is called bus master. When a transfer from the I/O device to the memory or vice versa has to be made, the processor stops the execution of the current program, increments the program counter moves data over the stack, and then a select signal is sent to the DMA controller over the address bus.

If DMA controller is free, it requests control of the bus from the processor by raising the bus request signal. The processor provides the bus to the controller by amplifying the bus grant signal, now the DMA controller is the bus master. The processor initializes the DMA controller by sending the memory address, the number of blocks of data to be transferred, and the direction of the data transfer. After delegating the data transfer task to the DMA controller, the processor resumes execution of the program after receiving instructions from the stack, rather than ideally waiting until the data transfer is complete.

DMA controller has full control of the buses and can interact directly with memory and I/O devices independent of the CPU. The DMA controller transfers data according to the control instructions received by the processor. After the data transfer is complete, it disables the bus request signal and disables the CPU bus grant signal thereby passing control of the buses to the CPU.

Advantages of DMA Controller

  1. DMA speeds up memory operations by bypassing the involvement of the CPU.
  2. The work overload on the CPU decreases.
  3. There are only a few numbers of clock cycles needed for each transfer.

Disadvantages of DMA Controller

  1. The cache coherence problem can be seen when DMA is used for data transfer.
  2. Increases the price of the system.