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.

Sixteen Wires and Their ID Numbers
IDSourceClockHow it reaches ap_plic
1UART0 (u_uart.irq)clk_sysdirectly
2GPIO (u_gpio.irq)clk_sysdirectly
3Timer and PWM (u_timer.irq)clk_sysdirectly
4SPI (u_spi.irq)clk_sysdirectly
5DMA (u_dma.irq)clk_sysdirectly
6Watchdog (early warning) (u_watchdog.irq)clk_aontwo flip-flops into clk_sys
7reservedconsttied to 0
8reservedconsttied to 0
9ap_pwrctl (u_pwrctl.irq)clk_aontwo flip-flops into clk_sys
10spareconsttied to 0
11spareconsttied to 0
12spareconsttied to 0
13spareconsttied to 0
14spareconsttied to 0
15spareconsttied to 0
16spareconsttied 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.

Five questions this page answers
Question
1What are the two symptoms of a crossed request wire?
2Why must a test raise one source at a time?
3Why read the whole pending word and not the source's own bit?
4What does a proof of irq.csv check that a test does not, and the other way round?
5Which 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.

From a Block's Request to an IDEach request travels from its block through the generated interrupt map to one input of ap_plic. Two start on clk_aon and pass two flip-flops. ap_plic tells the core only "external interrupt"; the ID comes from the claim.
  • Peripheral
  • Control / FSM
  • Bus
  • Processor
  • Interrupt
From a Block's Request to an IDEach request travels from its block through the generated interrupt map to one input of ap_plic. Two start on clk_aon and pass two flip-flops. ap_plic tells the core only "external interrupt"; the ID comes from the claim. peripheral UART0, GPIO,Timer, SPI, DMA requests on clk_sys peripheral Watchdog,ap_pwrctl requests on clk_aon control Two flip-flops into clk_sys bus ap_soc_irq generated fromirq.csv control ap_plic PENDING bit n,CLAIM returns n processor Core or seat one external pin IDs 1 to 5IDs 6 and 9a clean edgesixteen inputsexternal interrupt
  1. peripheral UART0, GPIO, Timer, SPI, DMArequests on clk_sys
    • IDs 1 to 5 → ap_soc_irq
  2. bus ap_soc_irqgenerated from irq.csv
    • sixteen inputs → ap_plic
  3. peripheral Watchdog, ap_pwrctlrequests on clk_aon
    • IDs 6 and 9 → Two flip-flops
  4. control Two flip-flopsinto clk_sys
    • a clean edge → ap_soc_irq
  5. control ap_plicPENDING bit n, CLAIM returns n
    • external interrupt → Core or seat
  6. processor Core or seatone external pin
  1. Direct sources

    Five requests on clk_sys go straight to their inputs.

  2. Crossing sources

    Two requests start on clk_aon and pass two flip-flops first.

  3. 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

New words on this page
WordMeaning
Interrupt sourceA block output that asks for attention; ap_plic gives each one an ID number from 1 to 16.
Pending wordap_plic's PENDING register: bit n is 1 while source n is waiting to be claimed.
Claim and completeReading CLAIM takes the highest pending source and returns its ID; writing the ID back ends it.
Crossed requestA request wired to the wrong input, so it raises another source's ID.
DMA requestA line from a peripheral that tells the DMA it may move the next byte.
OpenA 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?

One crossed wire, two checks
Source raisedPending bits"Is my bit set?""Is it the only one?"
1, 2, 4, 5, 7, 8its ownpasspass
33 and 6passfail
6nonefailfail

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

  1. Rule 1: Raise one source at a time.

    Two at once cannot tell a crossed pair from two healthy wires.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. 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.

The GPIO table, part 1: priority, enable, an empty word, then the pulse on IO8.
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 1
Part 2: PENDING must read 0x0000_0004, bit 2 alone; then claim, clear, complete, and an empty word.
core 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 1

On 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:

The first failing row of each table on chip Q072.
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.

connect.csv: the open row. The generator refuses an output that is neither used nor listed as open.
u_uart.dma_req,open,1,clk_sys,PD_MAIN,,the DMA of v1.5 waits on rx_ready and tx_room

The 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

ap_soc~12 blocks
Phone-class SoChundreds of blocks

This section looks ahead. ap_soc has sixteen interrupt inputs and two DMA request lines.

  1. Hundreds of sources

    Large chips route hundreds of interrupts through several controllers and bridges; the map is generated from a table.

  2. Request handshakes

    Larger DMA engines use request and acknowledge pairs per channel; each pair is a wire to prove and a handshake to test.

  3. 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?

RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: checks of one bit that failed: 1 checks of the whole word that failed: 2

Check Yourself

Predict the outputThe toy controller now has no crossed wire. What is the last line printed?
// A toy controller of 8 sources. Source 6's input is wired to request 0 by mistake (0: none).
module tb;
  logic [8:1] request, pending;
  always @* begin
    pending = request;
    // no crossed wire
  end
  int loose = 0, exact = 0;
  initial begin
    for (int s = 1; s <= 8; s++) begin
      request = '0;
      request[s] = 1'b1;
      #1;
      if (!pending[s]) loose++;               // "is my bit set?"
      if (pending !== request) exact++;       // "is my bit the only one set?"
    end
    $display("checks of one bit that failed: %0d", loose);
    $display("checks of the whole word that failed: %0d", exact);
  end
endmodule
ConceptWhat are the two symptoms of a crossed request wire?
ConceptIn the lab on Q072, what did raising SPI give in the pending word?
ConceptWhy does a test of source 9 poll for its bit before checking the word?
ConceptWhat does the DMA of ap_soc v1.5 use as its UART requests?

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.

Practice

Report a problem with this page