6.3.8 · D4Interconnects, Buses & SoC

Exercises — DMA controllers

2,428 words11 min readBack to topic

This page is a self-test ladder. Every exercise builds on the parent note DMA controllers and the machinery it defined — the four registers (, , , ), the three transfer modes (burst, cycle-stealing, transparent), and the timing formulas. If a symbol below is unfamiliar, it was defined in the parent; this page uses it, it does not re-derive it.

Before you start, let us pin down the two timing formulas you will lean on the most, so we never write a symbol we did not earn.


Level 1 — Recognition

Exercise 1.1 (L1)

A DMA controller has four per-channel registers. For a transfer that copies 2048 bytes from address 0x2000_0000 to 0x3000_0000, using 32-bit (word) width, state the initial value each register should hold, and say which one the CPU sets last to launch the transfer.

Recall Solution
  • — the source (where to read).
  • — the destination (where to write).
  • — the byte count (the countdown that terminates the transfer). Note it is bytes, not words, so it holds , not .
  • — mode bits (width for word, direction, increment bits). Its EN bit (bit 0) is written last: flipping EN to is the hardware signal that activates the transfer state machine. Set it first and the DMA would fire before the addresses are valid.

Exercise 1.2 (L1)

Given the parent's CSR layout, what value goes in bits 4–5 (Direction) to move data from a peripheral into memory (P2M), and what value in bits 2–3 (Transfer Width) for a halfword?

Recall Solution
  • Direction P2M (binary ).
  • Halfword width (binary ).

Level 2 — Application

Exercise 2.1 (L2)

Transfer 8 KB at 32-bit width on a 200 MHz bus in burst mode. Setup cycles, cycle. Find , total cycles, and total time in microseconds.

Recall Solution

bytes. Width bytes, so Cycles: cycles. One cycle at is . So

Exercise 2.2 (L2)

Same 8 KB, 32-bit, 200 MHz transfer, but in cycle-stealing mode with and cycles. Find total time, and the slowdown factor versus the burst result of Ex 2.1.

Recall Solution

(unchanged). Slowdown (essentially ).


Level 3 — Analysis

Exercise 3.1 (L3)

A CPU shares a 100 MHz bus with a DMA engine. The CPU issues one bus access every cycles (the other are internal/cache work). A transparent-mode DMA sneaks a transfer into each idle bus cycle. Over a -cycle CPU window, how many cycles are free for DMA, and what effective DMA throughput (bytes/s) does this give at 32-bit width?

Recall Solution

In each -cycle window the CPU uses cycle, leaving free cycles for transparent DMA. DMA duty cycle . If a transfer takes cycle, DMA completes transfers per cycle on average. Transfers per second transfers/s. At bytes each:

Exercise 3.2 (L3)

Three DMA masters — Disk, Network, Audio — share a bus under fixed priority Disk > Network > Audio. Disk requests continuously and each of its bursts holds the bus cycles. Explain quantitatively why Audio can starve, and how round-robin rescues it. Assume all three always have work.

Recall Solution

Fixed priority: the grant always goes to the highest requester still asking. Disk asks continuously, so after each -cycle burst it immediately re-requests and wins again. Network and Audio never see a grant → their wait time is unbounded (infinite). Audio starves. Round-robin: after a master uses the bus, its priority drops to the bottom via . So the grant order becomes Disk → Network → Audio → Disk → … Each master waits at most the other two bursts. With masters and -cycle bursts, Audio's worst-case wait is and it is guaranteed the bus once every cycles. Its bus share is , finite and fair.


Level 4 — Synthesis

Exercise 4.1 (L4)

You must stream from an SSD at a sustained 3.0 GB/s into RAM on a 64-bit (8-byte) bus. The DMA can run burst or cycle-stealing; cycle-stealing has , per transfer; burst has and negligible setup. Find the minimum bus frequency needed for each mode to keep up. Which mode is feasible on a bus?

Recall Solution

Required transfer rate in transfers/s (8 bytes each): Burst: cycle per transfer, so we need cycles/s: Cycle-stealing: cycles per transfer: On a bus: burst needs ✓ (feasible, with headroom), cycle-stealing needs ✗ (impossible). Use burst mode.

Exercise 4.2 (L4)

On that same 3 GB/s burst stream (feasible on the bus), a burst holds the bus for 1024 transfers. During each burst, the CPU is fully blocked. If the CPU also needs the bus and can tolerate at most 2 µs of blocking at a time, does a single burst violate this? If so, what maximum burst length keeps blocking under ?

Recall Solution

At , one cycle . A -transfer burst (1 cycle each) . That exceeds — the CPU is blocked too long. Max transfers under : transfers. So set burst length transfers (the parent's CSR burst field holds 0–255, so in practice you would program bursts of and let the engine chain them). Programming e.g. -transfer bursts blocks only , comfortably under the limit.


Level 5 — Mastery

Exercise 5.1 (L5)

Design decision. A system has: (a) a real-time UART UART receiver that drips 1 byte every and cannot tolerate a lost byte, and (b) a bulk PCIe PCIe transfer of that wants maximum throughput. The bus is , 32-bit. Choose a transfer mode for each DMA channel, justify with numbers, and state the priority scheme. Consider the interaction with Interrupts and Cache Coherency.

Recall Solution

UART channel → cycle-stealing (or single-transfer). It needs only byte per — a rate of B/s, trivially met even with per-transfer arbitration ( cycles per byte on a bus). What it cannot tolerate is latency: if a long burst holds the bus, the UART's 1-byte FIFO overflows and a byte is lost. Cycle-stealing releases the bus after each transfer, guaranteeing the UART prompt service.

PCIe channel → burst mode. bytes, transfers. In burst at cycle each, /cycle → . Cycle-stealing ( cycles) would take — 4× worse. Bulk data wants burst.

Priority: give UART higher priority (fixed priority UART > PCIe) so its rare, latency-critical requests preempt bulk bursts. Because the UART requests only every and holds the bus , it steals a negligible of bus time — PCIe barely notices. But limit PCIe burst length (Ex 4.2 logic) so it checks in often enough that a UART request never waits more than one short burst.

Interrupts: the PCIe channel sets so completion of the 16 MB block raises one interrupt (not one per byte) — the whole point of DMA over programmed I/O. The UART channel may use per-buffer completion interrupts.

Cache coherency: DMA writes to RAM behind the CPU's cache. After the PCIe DMA finishes, the CPU's cached copy of those addresses is stale. Either the interconnect must snoop/invalidate (hardware coherency, cf. ARM AMBA AXI ACE) or the driver must invalidate the cache range before reading the DMA'd data. Skip this and the CPU reads old garbage.

Recall Numeric summary
  • UART rate need: B/s; per-byte cost ⇒ effortless.
  • PCIe burst time: ; cycle-steal: (4×).
  • UART bus occupancy at 1 byte/: .

Related: Bus Architecture · Memory-Mapped IO · SDRAM Controllers · DMA controllers