Interrupt and DMA Request Wiring
Each interrupt source must reach the interrupt controller as its own ID, and no other. Each DMA request must reach the DMA. Check both by test, one source at a time, and by proof.
You Will Be Able To
- Raise one interrupt source at a time and check the whole pending word, not one bit.
- Explain the two symptoms of a crossed request wire.
- Say what the proof of the interrupt map covers and what only a test covers.
- Read the DMA request wiring of ap_soc, including the request line it leaves open.
- Lesson
- V8.4
- Time
- 24 min
- Runs on
- Your browser
- Check
- 5 questions
A driver team reports that the SPI handler runs whenever someone presses a button. The interrupt test had pressed the button, and an interrupt came. Nobody had checked which one.
Interrupt wires are easy to cross and hard to notice, since a crossed wire still raises one.
| ID | Source | Clock | How it reaches ap_plic |
|---|---|---|---|
| 1 | UART0 (u_uart.irq) | clk_sys | directly |
| 2 | GPIO (u_gpio.irq) | clk_sys | directly |
| 3 | Timer and PWM (u_timer.irq) | clk_sys | directly |
| 4 | SPI (u_spi.irq) | clk_sys | directly |
| 5 | DMA (u_dma.irq) | clk_sys | directly |
| 6 | Watchdog (early warning) (u_watchdog.irq) | clk_aon | two flip-flops into clk_sys |
| 7 | reserved | const | tied to 0 |
| 8 | reserved | const | tied to 0 |
| 9 | ap_pwrctl (u_pwrctl.irq) | clk_aon | two flip-flops into clk_sys |
| 10 | spare | const | tied to 0 |
| 11 | spare | const | tied to 0 |
| 12 | spare | const | tied to 0 |
| 13 | spare | const | tied to 0 |
| 14 | spare | const | tied to 0 |
| 15 | spare | const | tied to 0 |
| 16 | spare | const | tied to 0 |
irq.csv of ap_soc v1.5, read when this page is built. The generated ap_soc_irq.sv makes these sixteen wires; each one is a claim a test or a proof must check.
Before You Start
Read Interrupt Tests End to End and Connectivity Proofs From connect.csv first.
| Question | |
|---|---|
| 1 | What are the two symptoms of a crossed request wire? |
| 2 | Why must a test raise one source at a time? |
| 3 | Why read the whole pending word and not the source's own bit? |
| 4 | What does a proof of irq.csv check that a test does not, and the other way round? |
| 5 | Which DMA request line of ap_soc is open, and what does the DMA use instead? |
The Idea: Every Source, Its Own Number
An interrupt controller knows sources only by number. ap_plic has sixteen inputs; irq.csv says what drives each one. Firmware then trusts that number completely: the handler for ID 4 is the SPI handler. If the SPI request is wired to input 2, the GPIO handler runs for every SPI frame.
A crossed wire has two symptoms at once. The right input stays quiet, and a wrong input rises. A test that asks "did my bit rise?" sees only the first symptom, and only for the source it raised. A test that raises one source and reads the whole pending word sees both.
DMA requests are wires of the same kind. A peripheral raises a line when it has data or room, and the DMA moves a byte. A crossed request line moves bytes at the wrong time, or never. On ap_soc the DMA watches two flags of UART0 directly.
- Peripheral
- Control / FSM
- Bus
- Processor
- Interrupt
- Direct sources
Five requests on clk_sys go straight to their inputs.
- Crossing sources
Two requests start on clk_aon and pass two flip-flops first.
- The number
ap_plic marks input n pending and returns n on a claim. The number is all firmware sees.
Read the diagram as text
- UART0, GPIO, Timer, SPI, DMA: requests on clk_sys
- Watchdog, ap_pwrctl: requests on clk_aon
- Two flip-flops: into clk_sys
- ap_soc_irq: generated from irq.csv
- ap_plic: PENDING bit n, CLAIM returns n
- Core or seat: one external pin
- UART0, GPIO, Timer, SPI, DMA → ap_soc_irq: IDs 1 to 5
- Watchdog, ap_pwrctl → Two flip-flops: IDs 6 and 9
- Two flip-flops → ap_soc_irq: a clean edge
- ap_soc_irq → ap_plic: sixteen inputs
- ap_plic → Core or seat: external interrupt
irq.csv and the generated ap_soc_irq.sv of ap_soc v1.5 (facts §27.11).
New Words
| Word | Meaning |
|---|---|
| Interrupt source | A block output that asks for attention; ap_plic gives each one an ID number from 1 to 16. |
| Pending word | ap_plic's PENDING register: bit n is 1 while source n is waiting to be claimed. |
| Claim and complete | Reading CLAIM takes the highest pending source and returns its ID; writing the ID back ends it. |
| Crossed request | A request wired to the wrong input, so it raises another source's ID. |
| DMA request | A line from a peripheral that tells the DMA it may move the next byte. |
| Open | A block output with no load, listed in connect.csv so the generator knows it is meant. |
The Smallest Example: Two Ways to Check
Take a toy controller of eight sources in which input 6 is wired to request 3. Raise each source alone and check it two ways. Is its own bit set? Is it the only bit set?
| Source raised | Pending bits | "Is my bit set?" | "Is it the only one?" |
|---|---|---|---|
| 1, 2, 4, 5, 7, 8 | its own | pass | pass |
| 3 | 3 and 6 | pass | fail |
| 6 | none | fail | fail |
Worked by hand; the runnable example below runs the toy and counts the failures.
The own-bit check fails once, for source 6. The whole-word check fails twice and also names source 3 as the culprit. Had source 6 been a spare that no test can raise, only the whole-word check would see anything.
The Rules
Rule 1: Raise one source at a time.
Two at once cannot tell a crossed pair from two healthy wires.
Rule 2: Read the whole pending word.
A crossed wire shows as a missing bit and an extra bit; only the whole word shows both.
Rule 3: Claim, clear at the block, then complete.
Completing first lets the still-high request rise again and pollute the next source's check.
Rule 4: Wait for a crossing before you look.
Sources 6 and 9 start on clk_aon and pass through two flip-flops; poll for the bit, then check the word.
Rule 5: A proof checks every wire; a test checks that blocks ask.
The proof of irq.csv needs no stimulus but treats each block's request as free. Only a test shows the block really raises it.
Rule 6: Spares are destinations too.
A tied input that moves is a wiring bug even if no firmware enables it.
Sources for These Rules
The interrupt map and its generated logic: tools/soc/ap_soc/irq.csv, gen/rtl/ap_soc_irq.sv (facts §27.11); ap_plic's registers in the generated header.
The DMA request lines: connect.csv rows for u_dma.rx_ready, u_dma.tx_room and the open u_uart.dma_req; bench manual, "E16 chip sequence, connectivity and gate-level forms".
Connectivity proofs from a table: MEHTA-DV 10.9. The site's proof checks crossings to and from the synchronizer only (facts §27.21).
The Lab: One Source, the Whole Word
The bus-manager seat gives GPIO priority 1 and enables it at ap_plic. Then the board pulses IO8, and the seat reads PENDING with the full mask. It claims, clears GPIO's status, completes, and checks the word is empty again.
core w 0c000008 00000001 ffffffff 00000000 0 1
core w 0c002000 00000004 ffffffff 00000000 0 1
core r 0c001000 00000000 ffffffff 00000000 0 1
core w 10001018 00000100 ffffffff 00000000 0 1
tb gpio_pulse 00000008 00000003 ffffffff 00000000 0 1
core poll 10001024 00000064 00000100 00000100 0 1core r 0c001000 00000000 ffffffff 00000004 2 1
core r 0c200004 00000000 ffffffff 00000002 0 1
core w 10001024 00000100 ffffffff 00000000 0 1
core w 0c200004 00000002 ffffffff 00000000 0 1
core r 0c001000 00000000 ffffffff 00000000 2 1On the good chip the table passes in 52 cycles, and an SPI table of the same shape passes in 175. Q072, met earlier in the track, is the chip where ap_plic's source 2 samples the SPI request. Here are both tables on it:
BENCH 30: seat: read 0c001000 = 00000000, expected 00000004 (mask ffffffff)
BENCH 153: seat: read 0c001000 = 00000014, expected 00000010 (mask ffffffff)Rule 2 at work, twice. Raising GPIO leaves the word at 00000000: GPIO's bit never rose. Raising SPI gives 00000014: bits 2 and 4 together. An own-bit check of SPI would have passed, because bit 4 was set.
The DMA's request wiring is in the same table of the chip. Its two inputs are UART0's "byte ready" and "room to send". The DMA has no separate request line in this revision. The UART's dma_req output is listed as open.
u_uart.dma_req,open,1,clk_sys,PD_MAIN,,the DMA of v1.5 waits on rx_ready and tx_roomThe proof of those two rows, part dma-requests, held on the good wiring and failed on both altered chips. The graded problems raise every source the seat can make ask, and prove the whole interrupt map with its two crossings.
Why It Is Built This Way
Why both a proof and a test? They see different halves. The proof of irq.csv treats each block's request as a free signal. So it says nothing about whether the timer ever asks. The test shows the timer asks and ap_plic hears it, but only for the sources it can raise. Together they cover the wire and the asking.
Why do sources 6 and 9 pass through flip-flops? They start on clk_aon, a clock unrelated to clk_sys. Two flip-flops on clk_sys give the request a clean edge in the controller's domain. The test must wait for that, and the proof checks the wires on either side.
Traps
The first trap is the hook's test. It raises a source, waits for "an interrupt", and passes. A crossed wire raises an interrupt too. Read the claimed ID, and the whole pending word.
The second trap is completing too early. The handler writes the ID back to complete the source before it clears the block's status. The request is still high, so the same source is pending again at once. In a test of many sources, the next whole-word read sees it. It fails for a reason that has nothing to do with wiring.
The third trap is the forgotten spare. Inputs 7, 8 and 10 to 16 are tied to 0. No test enables them, so nobody looks. A spare wired to a real request by a later edit fires nowhere visible until a firmware update enables it. A whole-word read, or the proof, sees it the day it happens.
At Scale
This section looks ahead. ap_soc has sixteen interrupt inputs and two DMA request lines.
Hundreds of sources
Large chips route hundreds of interrupts through several controllers and bridges; the map is generated from a table.
Request handshakes
Larger DMA engines use request and acknowledge pairs per channel; each pair is a wire to prove and a handshake to test.
One test per source, generated
Teams generate the raise-one-check-all test from the same table that generates the map.
Try It
Run it: the own-bit check fails once, the whole-word check twice.
Remove the crossed wire (the predict question below). What do both checks print?
Cross request 3 into input 8, a spare. Which check still sees it?
checks of one bit that failed: 1 checks of the whole word that failed: 2Check Yourself
Common Mistakes
Wrong Raise a source and accept any interrupt.
A crossed wire still raises one, with the wrong ID.
Fix Check the claimed ID and the whole pending word.
Wrong Complete a source before clearing it at the block.
The request is still high, so the source is pending again at once.
Fix Claim, clear at the block, then complete.
Wrong Skip the spares because nothing enables them.
A spare wired to a real request is a latent bug.
Fix Check that every spare stays 0 in every pending read, and prove its tie-off.
Remember
- Raise one source at a time and read the whole pending word.
- A crossed wire shows as a missing bit and an extra bit.
- Claim, clear at the block, then complete.
- A proof checks every wire; a test checks that each block asks.