Before you start
Objectives: Learn what is DMA, how many DMA channels are there, and why are they used.
Prerequisites: no prerequisites.
Key terms: dma, devices, channels, chip, controller, system, assigned, cpu, directly, memory
DMA channels are used by high speed devices and they allow them to communicate directly with the main memory (RAM) on our system. When DMA channels are used, CPU is not involved in the communication. Communication without the CPU is a benefit since CPU is busy with all sorts of different processing tasks. Sometimes we don’t want to wait the CPU, so we enable other devices on the system to access RAM directly. DMA channels can be used by sound cards, hard disk drives, CD/DVD-ROM drives, tape drives, etc.
DMA is managed by DMA controller chip (8237). The DMA controller has four wires which are connected to certain devices on the system. On the other end, the DMA chip is connected to the Memory Controller Chip (MMC) that allows access to RAM. That way, devices that are connected to the DMA chip are able to read and write data to RAM trough the DMA chip, without involving the CPU.
Similar to IRQs, we actually use two cascaded DMA controllers. Each chip has 4 DMA channels. Since chips are cascaded, we actually get 7 working DMA channels. One wire on the first controller is used to connect to the second DMA controller. Channel 0 (zero) is used to do just that, so it can’t be used to connect other devices. Actually, channels 0 (on the first DMA chip), and 4 (on the second DMA chip) are actually the same channel.
Simplified DMA Scheme
By default, only one DMA channel can be assigned to one device on the system. If devices share the same DMA channel, memory errors can occur. For example, Floppy disk controller is assigned to DMA channel 2. Channel 1 is assigned to sound card. Channels 3, 4, 5, 6, and 7 are usually available to be assigned by other devices on the system. Since DMA channel 0 is used to cascade two DMA chips, it is not assigned to devices.
There is also a newer type of DMA called Ultra DMA, or sometimes called Bus Mastering. This new type of DMA allows devices to bypass DMA controller all together. This way devices can access system bus directly. Ultra DMA supports burst mode data transfer rates, which provides twice the speed of standard DMA performance. This is usually implemented on hard disks. Ultra ATA hard disks use ultra DMA.