A DMA engine is a master like any other on the fabric, but it's programmed differently, and that difference creates its own class of bugs. A CPU issues one transaction at a time. A DMA channel is usually handed a list of transfers to run on its own, and keeps running that list long after the CPU that set it up has moved on to something else. Verifying it means verifying the list, the channels that run several lists at once, and what happens to memory the CPU still cares about while the list runs.
9 min read | Intermediate Level
What You'll Learn
- Why a DMA's descriptor chain is itself something that needs verifying, not just the data it eventually moves
- How to verify multiple DMA channels arbitrate fairly for the bus they share
- Why a non-coherent DMA path is a real hazard between DMA writes and CPU cache, not a theoretical one
- What has to be true when a transfer is aborted partway through
What Makes DMA Verification Different From a Generic Master
Proving a DMA transaction's data survives the trip from source to destination is the same problem the scoreboarding article in this series already covered - tag the data, correlate it at both ends, done.
What's specific to DMA is everything around that one transfer: software hands the engine a program, not a single request, and the engine executes that program autonomously, across possibly many channels, for possibly a long time, without the CPU watching each step.
DMA isn't the only master built this way. A graphics engine's command processor, a display controller reading framebuffer data, or a network engine moving packets all follow the same pattern - an autonomous master programmed with a list of work rather than one CPU-issued transaction at a time. Everything in this article - descriptor-chain integrity, multi-channel arbitration, coherency with the CPU's cache, clean aborts - applies to any of them. DMA is just the clearest, most universal example to learn it on.
Descriptor Chains and Scatter-Gather: When the Transaction Is a List
Most real DMA engines don't take one source address and one destination address. They take a descriptor - a small structure in memory describing one chunk of the transfer - and a pointer to the next descriptor, so a single DMA request can walk an entire chain and move data scattered across many non-contiguous regions in one program:
typedef struct packed {
bit [31:0] src_addr;
bit [31:0] dst_addr;
bit [15:0] length;
bit [31:0] next_desc_ptr;
bit last;
} dma_descriptor_t;
Verifying a scatter-gather engine means verifying the chain-walking logic, not just any one descriptor's transfer.
That includes a chain long enough to matter, a chain where descriptors are scattered non-sequentially through memory rather than laid out back to back, and - just as important - the malformed cases: a chain that never sets last, which should be caught rather than let the engine wander into whatever memory happens to follow, and a chain whose next_desc_ptr loops back on itself, which should be detected as a circular chain rather than let the DMA spin forever fetching the same descriptors.
Mistake: Only testing descriptor chains that were built correctly.
A real firmware bug can hand the DMA a chain missing its terminator or pointing back on itself. An engine that only handles well-formed chains, verified only against well-formed test chains, has an entire failure mode - what happens when the list itself is broken - that's never been exercised.
Multiple Channels Contending for the Same Bus
A DMA controller with several channels is really several independent transfer programs that can run at once, each wanting the shared bus port the DMA engine presents to the interconnect. That's the same arbitration problem the interconnect itself has to solve, just one level down - inside the DMA engine, between its own channels, before any of them even reach the fabric.
A high-priority channel moving audio data with a real-time deadline and a low-priority channel doing a bulk memory copy in the background need the same two checks arbitration always needs: the low-priority channel isn't starved indefinitely, and the priority setting actually changes which channel wins contention, measurably, not just in name.
Running one channel at a time is a fine first pass for basic functional correctness, but it proves nothing about channel arbitration. That only shows up with two or more channels actively contending for the same shared resource at once.
Cache Coherency: The Bug That Only Shows Up When Software Reads the Result
A DMA channel writing to memory often does so without going through the CPU's cache at all - it writes straight to memory over the bus. If the CPU had already cached that same address, the CPU's cache now holds stale data, and a C test reading that address afterward can get the old value back, even though the DMA transfer itself completed perfectly and the correct new data is sitting in memory the whole time.
This isn't a corner case; it's a well-known hazard in any SoC where the DMA path isn't hardware-coherent with the CPU's caches, and it's exactly why real software has to explicitly invalidate the relevant cache lines before reading DMA-written memory, or flush them before a DMA read of CPU-written memory.
Verifying this means running the realistic sequence on purpose: CPU writes data, CPU reads it once to warm the cache, DMA overwrites the same memory, then CPU reads it again - once without the cache maintenance operation, confirming the stale read actually happens and is a real, reproducible bug class rather than a hypothetical, and once with the correct invalidate in place, confirming the CPU now sees the DMA's data.
On an SoC where the DMA path genuinely is coherent - snooped into the cache hierarchy by hardware - the equivalent test confirms the CPU sees fresh data without any software maintenance at all, since claiming hardware coherency and then never actually testing it leaves that claim unverified.
Whether a given DMA path is coherent or not is an SoC-level architectural decision, not something to assume from the DMA IP alone - the same DMA engine can be wired coherent in one chip and non-coherent in another, depending on what it's connected to.
Aborting a Transfer Midway
Software needs to be able to stop a DMA transfer before it finishes - a channel reprogrammed for something more urgent, or a transfer that needs to be cancelled because whatever asked for it went away.
An abort partway through a transfer has to leave the engine in a state software can actually recover from: the status or count register needs to reflect how much data genuinely moved before the stop, not the full requested length and not zero, and any in-flight bus transaction the abort caught mid-flight needs to be brought to a clean close on the interconnect rather than left as the kind of hanging request the interconnect chapter's watchdog is built to catch. A channel that reports it aborted cleanly while a transaction it started is still outstanding on the bus hasn't actually aborted anything.
Common Mistakes
Mistake: Verifying scatter-gather with descriptors laid out sequentially in memory.
A chain built as tidy, back-to-back descriptors never actually forces the engine to follow its next_desc_ptr logic across a real jump in the address space. Scattering the descriptors themselves, not just the data they describe, is what exercises the chain-walking hardware.
Mistake: Assuming coherency without ever running a test that would catch a missed cache-maintenance step.
A stale-cache bug is invisible to any test that doesn't specifically read DMA-written memory back through the CPU's cache afterward. Most functional tests never do, which is exactly why this class of bug reaches silicon more often than it should.
Mistake: Treating an abort as complete the moment the DMA engine acknowledges the stop command.
The DMA's own state machine reaching an idle state doesn't guarantee the bus transaction it last issued has actually completed or been cleanly terminated on the interconnect. Both need checking independently.
Summary
In this article, you learned:
- A DMA channel executes a program, not a single transaction, so verifying it means verifying the descriptor chain itself - including malformed and circular chains - not just the data one descriptor moves
- Multiple DMA channels arbitrate for a shared bus port the same way masters arbitrate for the interconnect, and need the same fairness and priority checks with real contention from more than one channel at once
- A non-coherent DMA path can leave the CPU's cache holding stale data after a DMA write, and this needs a deliberate test that reads DMA-written memory back through the cache, both with and without the software cache-maintenance step
- An aborted transfer needs an accurate partial-progress count and a cleanly terminated bus transaction, not just an idle DMA state machine