1. Overview
In this tutorial, we’ll discuss direct memory access (DMA) in detail. We’ll talk about the working procedure of DMA.
Additionally, we’ll explore some advantages and disadvantages of DMA.
2. Introduction
Data is continuously transferred between computers and devices in the modern digital world. However, computer systems are limited to a specific data rate at which they can process data. Therefore, data processing has become a bottleneck with the proliferation of various devices, such as sensors, printers, and high-speed modems.
If the CPU is in charge of all data transfers, it’ll not be able to perform any other operations simultaneously. To solve this problem, direct memory access (DMA) controllers were developed. It enables data transfer between two devices without involving the CPU.
DMA is a feature in computers and devices with microprocessors that transfer data directly from main memory to an auxiliary device or vice versa. Additionally, a DMA controller facilitates direct data transfer between computer components operating at different speeds.
The primary function of a DMA controller is to transfer data between memory and an auxiliary device directly, without involving the CPU. Some typical operations include reading data from a sensor and storage device. Sending the processed data to a printer or the network is also an example of an operation carried out by a DMA controller.
A DMA controller transfers data between memory and an auxiliary device via special data channels. There’re two types of channels: data and control. Data channels transfer the actual data. On the other hand, we use control channels to regulate the operation of the DMA controller.
3. Types of DMA
Let’s talk about different types of DMA controllers. There’re four popular types of DMA: single-ended, dual-ended, arbitrated-ended, and interleaved DMA controllers.
Single-ended DMA controllers are simple DMA controllers that operate by reading from and writing to a single memory address. On the other hand, dual-ended DMA controllers are more advanced DMA controllers. They can read and write from two memory addresses simultaneously.
An even more advanced version of the DMA controller is the arbitrated-ended DMA controller. It operates by reading from and writing to several memory addresses. Finally, interleaved DMA controllers are fancy DMA controllers that read from one memory address while writing to another different memory address.
4. Working Procedure
DMA controllers work under the CPU, although data transfer via DMA happens without the involvement of the CPU. It facilitates an interface between the I/O devices and the bus. We can connect more than one external device with DMA:
DMA controllers also contain three registers: address, word count, and control registers. In order to find the target location in the memory, we use the address register. The word count register counts the number of words in the input data that needs to be transferred. Finally, the transfer mode is specified by the control register.
A DMA controller regulates the data flow between memory and an auxiliary device. The controller is plugged into the computer system’s motherboard and connected to the devices that need data transfer via connectors. Once the data flow is established, the computer system temporarily suspends its operation, and the DMA controller takes over. Additionally, we initialize DMA when the CPU transfer data through a data bus.
The controller temporarily takes control of the system bus and sends the data directly to the device without any assistance from the CPU. When we complete the transfer operation, the DMA controller relinquishes control to the CPU. Therefore, the system resumes its normal operations.
Now, let’s take a look at the block diagram of the DMA controller in order to explore the working procedure in more detail:
In order to make a successful data transfer, DMA must share the bus (data and address) with the CPU. Now let’s assume we’re about to transfer data from an I/O device to memory. In this situation, the CPU forces the current program to stop. Additionally, the CPU increments the value of the program counter by one.
Furthermore, the CPU generates a single and sends it to the DMA controller over the address bus. Now, if the DMA controller accepts the signal, it generates a bus request signal. Additionally, a request is sent from the DMA controller to the CPU in order to control the bus. The DMA controller becomes the bus master if the CPU grants the request.
Furthermore, the CPU sends the addresses in the memory, the direction of the data transfer, and the number of blocks in the data. After initializing the data transfer task to the DMA controller, the CPU resumes execution.
We can divide the operations of DMA controllers into two categories: single-channel and multi-channel. In single-channel operation, data is transferred from memory to one device and from that device to memory. In multi-channel operation, data is simultaneously transmitted from the memory to multiple devices. Additionally, we can also transfer data from multiple devices to memory.
In general, there’re two kinds of memory on a computer: system memory and I/O memory. System memory stores the operating system and program data, while I/O memory stores data related to peripheral devices. If a computer wants to send data to a printer without user intervention, it must do so through I/O memory.
The separation of memory types is vital since system memory operates at a higher speed than I/O memory. The DMA controller directs data between devices and system memory, making the operation between the two devices look like a single operation.
For example, if a computer wants to send data from system memory to a printer, it issues a DMA transfer request to the printer’s DMA controller. The printer’s DMA controller then begins the data transfer operation, reading data from system memory at one end and sending it to the printer.
5. Advantages and Disadvantages
The main advantage of DMA is to speed up data transfer and memory operations. Hence, it assists the operating system in distributing the load properly.
On the other hand, a computer system connected to a network computer (NC) can’t use a DMA controller to transfer data. When connected to an NC, the computer system must rely on the CPU to help in data transfer. Additionally, while using DMA for data transfer, we can encounter the cache coherence problem.
Let’s talk a look at the core advantages and disadvantages of DMA:
Advantages
Disadvantages
Speed up data transfer and memory operations
Requires to carry out the additional operations, which increases the cost
Don’t involve CPU during data transfer
The added complexity of the software
The workload is appropriately distributed
Additional cost of the hardware
Helps in decreasing the load on the CPU
Suffers from cache coherence problem
Needs only a few numbers of clock cycles while transferring data
The device initiating the transfer must be able to communicate with other devices
Efficient in facilitating direct data transfer between two devices operating at different speeds
Both devices must be able to initiate the data transfer independently
Allows efficient use of interrupts
A computer system connected to a network computer (NC) can’t use a DMA controller
6. Conclusion
In this tutorial, we discussed direct memory access (DMA) in detail. We talked about the working procedure of DMA.
Additionally, we explored several advantages and disadvantages of DMA.