BIT204 ยท 2078 ยท 5 marks
What is DMA? Explain how it works in brief with suitable diagram.
What is DMA? Explain how it works in brief with suitable diagram. [5]
Quick answer
DMA (Direct Memory Access) is a feature of computer systems that allows certain hardware subsystems (such as disk controllers, network cards, or sound cards) to access main memory (RAM) independently of the CPU. It enables data transfer between I/O devices and memory without continuous CPU involvement, freeing the CPU to perform other tasks during the transfer.
Direct Memory Access (DMA)
Definition
Why DMA is Needed
Without DMA, the CPU must supervise every byte transferred between an I/O device and memory (programmed I/O), which wastes CPU cycles. DMA offloads this work to a dedicated DMA Controller (DMAC).
Key Components
| Component | Role |
|---|---|
| DMA Controller (DMAC) | Manages the data transfer independently |
| Source Address Register | Holds the source memory/device address |
| Destination Address Register | Holds the destination memory address |
| Count Register | Holds the number of bytes/words to transfer |
| Control Register | Specifies direction and mode of transfer |
How DMA Works (Step-by-Step)
Step 1: CPU Initialization
- The CPU programs the DMA controller by providing:
- Source address
- Destination address
- Number of bytes to transfer
- Direction of transfer (read/write)
- The CPU then continues its own tasks.
Step 2: DMA Request
- The I/O device signals the DMAC that it is ready to transfer data (via DMA Request line - DREQ).
Step 3: Bus Request
- The DMAC requests control of the system bus from the CPU by asserting the Bus Request (BR) signal.
Step 4: Bus Grant
- The CPU completes its current bus cycle and grants the bus to the DMAC by asserting Bus Grant (BG). The CPU is now temporarily disconnected from the bus (CPU is in a "hold" state).
Step 5: Data Transfer
- The DMAC takes control of the address bus, data bus, and control bus.
- Data is transferred directly between the I/O device and memory, one block at a time, without CPU involvement.
- The address and count registers are updated after each transfer.
Step 6: Transfer Complete
- When the count reaches zero (all data transferred), the DMAC sends an interrupt to the CPU to notify it that the transfer is complete.
- The CPU resumes control of the bus.
Diagram
+------------------+
| CPU |
+--------+---------+
| BR / BG (Bus Request / Bus Grant)
|
+--------+---------+
| DMA Controller |<-------- DREQ (from I/O Device)
| (Source Addr Reg)|
| (Dest Addr Reg) |
| (Count Reg) |
+---+----------+---+
| |
Address/Data/Control Bus
| |
+-------+--+ +--+--------+
| Main | | I/O Device|
| Memory | | (Disk,NIC)|
+----------+ +-----------+
Data Flow:
I/O Device ----[DMA Controller]----> Main Memory
(No CPU needed
during transfer)
Advantages of DMA
- CPU is free to execute other instructions during data transfer.
- Faster data transfer compared to programmed I/O or interrupt-driven I/O.
- Suitable for high-speed, bulk data transfers (e.g., disk to memory).
Summary
DMA allows I/O devices to transfer data directly to/from memory by temporarily taking control of the system bus, with the CPU only involved at the start (initialization) and end (interrupt) of the transfer.
Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.