Inside an AXI Crossbar
A crossbar is the bus matrix again, built for AXI. On AXI the address, the data and the reply travel apart. So the crossbar must remember where each one belongs.
You Will Be Able To
- Say what a crossbar must do that the bus matrix of AHB did not: remember routes.
- Work out the tag a subordinate sees when two managers use the same ID, and how the reply gets home.
- Explain why write data follows the address that was taken, and not the address now on the wires.
- Lesson
- S4.6
- Time
- 28 min
- Runs on
- Your browser
- Check
- 5 questions
Two managers write at the same moment. Both writes succeed, and every handshake is legal. Yet a byte meant for the console is now in memory. The block between them looked at an address at the wrong time.
Before You Start
This is a senior page. It stands on three lessons of the Protocols track, and does not teach them again. They are AXI in one picture, the handshake and a write on three channels. For reads, add a read on two channels.
From this module you need the decoder of Address Decode and the bus matrix of Many Managers.
| Question | |
|---|---|
| 1 | What must a crossbar do that the bus matrix of AHB did not have to do? |
| 2 | Two managers both use ID 01. How do their requests stay apart on the subordinate side? |
| 3 | A reply carries no address. How does it find the manager that asked? |
| 4 | Write data carries no address either. How does the crossbar know where it goes? |
| 5 | Which order does the crossbar still owe a manager after it has changed the IDs? |
The Idea: A Crossbar Remembers Routes
In the bus matrix, each manager had its own way in, and each subordinate had its own arbiter. An AXI crossbar is the same grid. Two managers with different destinations are served in the same cycles.
AHB made the way back easy. A manager had one transfer in its data phase, so the answer on the wires was the answer to that transfer. AXI gives this up on purpose. A request and its reply are separate handshakes, and many cycles can lie between them. A manager may send a second request while the first is still outstanding: sent, and not yet answered.
So the crossbar has a new job. It must remember a route for everything that travels without an address. A reply has no address on it. Write data has no address on it either.
The crossbar can learn a route at one moment only: the handshake of the address. Whatever it does not store at that edge is gone.
New Words
| Word | Meaning |
|---|---|
| Entrance | The port of one manager on the crossbar. It decodes the addresses of that manager. |
| Crossbar | A bus matrix for AXI: an entrance for each manager, an arbiter at each subordinate, and a store of routes. |
| Stored route | The remembered answer to "which subordinate?" or "which manager?" for one request. |
| Outstanding | Sent, and not yet answered. |
| Tag | The ID as a subordinate sees it: the number of the entrance, placed in front of the manager's own ID. |
The five channels of AXI are taught in the Protocols lessons listed above. This table is a reminder of their names, and of the three signal names this page uses.
| Name | What it is |
|---|---|
| AW | the channel for a write address, from manager to subordinate |
| W | the channel for write data |
| B | the channel for the reply to a write |
| AR | the channel for a read address |
| R | the channel for read data, which is also the reply to a read |
| AWADDR | the address wires of the AW channel |
| ARID | the ID that a manager puts on a read address |
| RID | the ID that comes back with the read data |
A handshake is one clock edge with two wires of a channel at 1. They are VALID, the wire of the sender, and READY, the wire of the receiver.
One Picture: Entrances, Routes and Tags
- Processor
- Peripheral
- Bus
- Memory
- An entrance for each manager
Each manager has its own entrance, with its own decoder. Nothing is shared up to this point, so both can send an address at the same edge.
- Four possible routes
Each entrance can reach each subordinate. The address picks one route at the handshake, and the entrance stores that choice.
- The same ID twice
Both managers chose ID 01. The crossbar puts the entrance number in front: 0 and 01 give 001, 1 and 01 give 101.
- The way back
A reply carries its tag and no address. The first bit names the entrance. The crossbar removes that bit, and each manager sees ID 01 again.
- Write data
Write data carries no address and no ID. It goes down the route its entrance stored when the address was taken.
Read the diagram as text
- Manager 0: the processor: labels its request with ID 01
- Manager 1: DMA: also labels its request with ID 01
- Entrance 0: decodes the addresses of manager 0, and stores its routes
- Entrance 1: decodes the addresses of manager 1, and stores its routes
- Console register: a subordinate: one register at 0x1000_0000
- SRAM word: a subordinate: one word at 0x8000_0000
- Manager 0 → Entrance 0: request, ID 01
- Manager 1 → Entrance 1: request, ID 01
- Entrance 0 → Console register: tag 001
- Entrance 1 → SRAM word: tag 101
- Entrance 0 → SRAM word: the other route
- Entrance 1 → Console register: the other route
- Console register → Entrance 0: reply, tag 001
- SRAM word → Entrance 1: reply, tag 101
Each arrow stands for a group of wires. The arbiters at the two subordinates are the subject of the next lesson and are not drawn.
Read the picture from left to right for a request, and from right to left for its reply. The two directions use different knowledge. The request is steered by its address. The reply is steered by its tag.
The Smallest Example, Worked by Hand: Tags and a Stored Route
Each manager has two bits of ID. The crossbar has two entrances, so one more bit is enough to tell them apart. That bit goes in front.
| Entrance | ID from the manager | Tag at the subordinate | Reply tag | Goes to entrance | ID given back |
|---|---|---|---|---|---|
| 0 | 01 | 001 | 001 | 0 | 01 |
| 1 | 01 | 101 | 101 | 1 | 01 |
| 1 | 10 | 110 | 110 | 1 | 10 |
The first two rows are the point. Both managers chose 01, and the subordinates still see two different tags. So the ID is always wider on the subordinate side than on the manager side.
Now the write. Manager 0 writes the byte 68 to the console. As soon as its address is taken, it shows its next address, which is in SRAM.
| Cycle | Handshake on AW | AWADDR on the wires | Handshake on W | Route stored in entrance 0 |
|---|---|---|---|---|
| 1 | yes | the console | no | console (stored at this edge) |
| 2 | no | SRAM: the next address, shown early | yes: data 68 | console |
The data of cycle 2 belongs to the address of cycle 1. A crossbar that decodes the wires in cycle 2 sends 68 to SRAM. A crossbar that uses its stored route sends it to the console.
The Rules
Rule 1: An entrance decodes an address at its handshake, and stores the route.
The AW handshake fixes where the write data will go. The AR handshake fixes who must get the reply.
Rule 2: The crossbar puts the entrance number in front of the ID.
Managers need not know each other. Two of them can use the same ID, and their requests still differ at the subordinate.
Rule 3: A reply goes to the entrance its tag names, and the added bits are removed.
The manager gets back exactly the ID it sent.
Rule 4: Write data follows the stored route of the oldest address that still waits for data.
The W channel has no address and, since AXI4, no ID. Only the order of the addresses says whose data it is.
Rule 5: Replies with one ID reach a manager in the order of its requests.
This holds even when the requests went to different subordinates. Changing the IDs inside the crossbar does not remove this duty.
Sources for These Rules
Arm AMBA AXI Protocol Specification, document IHI 0022, issue L. The handshake: section A2.3. Transaction IDs, and order within one ID: sections A5.1 and A5.3. The bits an interconnect adds to an ID, and their removal on the way back: section A5.4. Write data in the order of the write addresses: section A5.5. Replies with one ID from different subordinates in request order: sections A5.5 and A5.6. Any change to an ID must keep the order of the original ID: section A5.3.6.
The ID on write data existed in AXI3 only. See the Arm AMBA AXI and ACE Protocol Specification, IHI 0022, issue H.c, sections A2.3 and A5.1.
The specification says that bits are added and removed. Where they sit, and how many, is the choice of each crossbar. This lab puts one bit in front of two.
Now Run It
The lab at the end of this page has two managers, both test code, and two subordinates of one word each. In its output, m0 and m1 are the two managers. Each row is one handshake: the edge, the channel, the manager and what crossed.
e0 AW m0 addr=10000000
e0 AW m1 addr=80000000
e1 W m0 data=00000068
e1 W m1 data=000000d1
e3 B m0 resp=00
e3 B m1 resp=00
e4 AR m0 addr=10000000
e4 AR m1 addr=80000000
e6 R m0 target_tag=001 rid=01 data=00000068 resp=00
e6 R m1 target_tag=101 rid=01 data=000000d1 resp=00Rule 1 at work: e0 has two AW rows. Both entrances take an address at the same edge, and each stores its own route.
Rule 4 at work: right after e0 the test code changes the AW address of m0 to SRAM. At e1 it sends the data 68. The read of the console at e4 comes back at e6 with 68. The byte went down the stored route, not to the address on the wires.
Rules 2 and 3 at work: both managers send ID 01 at e4. The two e6 rows show the tags 001 and 101 at the subordinates. Both managers get rid=01 back.
The run goes on after e6. Those rows show two managers that want the same subordinate. They belong to the next lesson.
This lab leaves things out. Each entrance allows one read and one write at a time, so rule 5 is never put to the test here. Every request is a single transfer. The managers are test code, which a later track replaces with real blocks.
Why It Is Built This Way
| Design choice | The alternative | What the choice buys, and costs |
|---|---|---|
| Store the route at the address handshake | Decode the address wires whenever data arrives | A manager is free to show its next address early. It costs a small store in each entrance. |
| Entrance number in front of the ID | Make all managers agree on different IDs | Each manager is designed alone and can be reused in another chip. The ID grows wider toward the subordinates. |
| No ID on write data | An ID on every piece of write data, as AXI3 had | Fewer wires and simpler subordinates. Data must come in the order of its addresses, so one stalled write holds up the next. |
The second row has a limit worth knowing. The tag must fit through the narrowest port on its way. A subordinate with too few ID bits cannot sit behind this crossbar without a converter.
The Trap: The Address on the Wires
Back to the byte in the wrong device. The crossbar worked for months. In every test, the manager kept its address still until the data had gone. Decoding the wires at the data handshake gave the right answer every time.
Then a faster manager arrived. It showed its next address as soon as the first was taken, which the rules allow. The data of the first write now met the address of the second. One byte for the console landed in memory, and nothing reported an error.
When a write lands in the wrong place on AXI, do not start at the data. Find the edge where its address was taken, and ask what the crossbar stored there.
At Scale
This section looks ahead. Two entrances and one write at a time are easy to follow. A large crossbar has many entrances, and several requests outstanding at each.
Count every entrance
A debug port is an entrance too. Each one adds to the bits in front of the ID. Check the narrowest ID port on the whole way.
A queue of routes
With two addresses taken and no data yet, the entrance needs both routes, in order. The debug problem of this lesson starts from such a queue.
Order across subordinates
Rule 5 is the hard one at scale. The Protocols track takes it in three steps: one ID, different IDs and reads against writes.
The hardware
The return path is a wide multiplexer steered by the tag. A later track builds it in muxes and crossbars at scale.
Try It
Run the lab. For each of the first ten rows, say which entrance and which subordinate it involves.
In the test code, give the second manager another ID: change arid[1]=1 to arid[1]=2. Predict both e6 rows, then run.
Find the line of the test code that changes the write address of m0 after e0. Say why the byte 68 still reaches the console.
e0 AW m0 addr=10000000 e0 AW m1 addr=80000000 e1 W m0 data=00000068 e1 W m1 data=000000d1 e3 B m0 resp=00 e3 B m1 resp=00 e4 AR m0 addr=10000000 e4 AR m1 addr=80000000 e6 R m0 target_tag=001 rid=01 data=00000068 resp=00 e6 R m1 target_tag=101 rid=01 data=000000d1 resp=00 e7 AR m0 addr=80000000 e7 AR m1 addr=80000000 e9 R m0 target_tag=001 rid=01 data=000000d1 resp=00 e11 R m1 target_tag=101 rid=01 data=000000d1 resp=00 e12 AR m0 addr=10007000 e14 R m0 target_tag=001 rid=01 data=00000000 resp=11Read included file: axi_pair.sv
// Two AXI4-Lite manager ports, two one-word register targets and a default.
// Protection is fixed by the BFM. TAG_READ adds a single-beat AXI read-ID path.
// Each port admits one read and one write at a time. Each target arbitrates
// locally. Its read response register holds the payload until the owner takes it.
module axi_pair #(parameter bit TAG_READ = 0) (
input logic clk, reset_n,
input logic [1:0] awvalid, wvalid, bready, arvalid, rready,
output logic [1:0] awready, wready, bvalid, arready, rvalid,
input logic [31:0] awaddr[0:1],
input logic [31:0] wdata[0:1],
input logic [31:0] araddr[0:1],
input logic [3:0] wstrb[2],
input logic [1:0] arid[2],
output logic [1:0] rid[0:1],
output logic [1:0] rresp[0:1],
output logic [1:0] bresp[0:1],
output logic [31:0] rdata[2]
);
function automatic logic [1:0] decode(input logic [31:0] address);
case (address)
32'h10000000: return 0; // console scratch word in this experiment
32'h80000000: return 1; // first SRAM word
default: return 2;
endcase
endfunction
logic [1:0] have_aw, have_w, queued, reading;
logic [1:0] write_target[2], read_target[2], local_id[2];
logic [31:0] payload[2], word_q[2];
logic [3:0] lanes[2];
logic [2:0] occupied;
logic lite_owner[3];
logic [2:0] tag[3];
logic [31:0] reply[3];
wire owner[3];
for (genvar t=0; t<3; t++)
assign owner[t] = TAG_READ ? tag[t][2] : lite_owner[t];
assign awready = ~have_aw & ~bvalid;
assign wready = ~have_w & ~bvalid;
assign arready = ~reading;
always_comb begin
rvalid = 0;
for (int m=0; m<2; m++) begin
rid[m] = 0;
rresp[m] = 0;
rdata[m] = 0;
end
for (int t=0; t<3; t++) begin
if (occupied[t]) begin
rvalid[owner[t]] = 1;
rdata[owner[t]] = reply[t];
rid[owner[t]] = TAG_READ ? tag[t][1:0] : 0;
rresp[owner[t]] = t == 2 ? 2'b11 : 0;
end
end
end
always_ff @(posedge clk) begin
if (!reset_n) begin
have_aw <= 0;
have_w <= 0;
bvalid <= 0;
queued <= 0;
reading <= 0;
occupied <= 0;
word_q[0] <= 0;
word_q[1] <= 0;
end else begin
for (int m=0; m<2; m++) begin
if (awvalid[m] && awready[m]) begin
write_target[m] <= decode(awaddr[m]);
have_aw[m] <= 1;
end
if (wvalid[m] && wready[m]) begin
payload[m] <= wdata[m];
lanes[m] <= wstrb[m];
have_w[m] <= 1;
end
if (bvalid[m] && bready[m]) bvalid[m] <= 0;
if (arvalid[m] && arready[m]) begin
read_target[m] <= decode(araddr[m]);
local_id[m] <= arid[m];
queued[m] <= 1;
reading[m] <= 1;
end
end
for (int t=0; t<3; t++) begin
logic wrote, issued;
wrote = 0;
issued = 0;
if (occupied[t] && rready[owner[t]]) begin
occupied[t] <= 0;
reading[owner[t]] <= 0;
end
// Fixed port order resolves ties independently at each target.
for (int m=0; m<2; m++) begin
if (!wrote && have_aw[m] && have_w[m] && write_target[m] == t) begin
wrote = 1;
if (t < 2)
for (int b=0; b<4; b++)
if (lanes[m][b]) word_q[t][8*b+:8] <= payload[m][8*b+:8];
bresp[m] <= t == 2 ? 2'b11 : 0;
bvalid[m] <= 1;
have_aw[m] <= 0;
have_w[m] <= 0;
end
if (!occupied[t] && !issued && queued[m] && read_target[m] == t) begin
issued = 1;
occupied[t] <= 1;
queued[m] <= 0;
lite_owner[t] <= m[0];
tag[t] <= {m[0],local_id[m]};
reply[t] <= t < 2 ? word_q[t] : 0;
end
end
end
end
end
endmodule
Check Yourself
Common Mistakes
Wrong Pick the subordinate from the address wires when the write data arrives.
By then the wires may show the next address.
Fix Use the route stored at the handshake of the write address.
Wrong Treat an ID as a name that is unique in the whole chip.
Two managers may choose the same ID.
Fix Keep the entrance number with the ID until the reply is home.
Wrong Assume that new IDs inside the crossbar free it from the order of replies.
The manager still expects the order of its own ID.
Fix Return replies with one original ID in the order of their requests.
Remember
- A crossbar is a bus matrix for AXI, and its new job is to remember routes.
- An entrance decodes an address at its handshake and stores the route.
- The entrance number goes in front of the ID, so equal IDs from two managers stay apart.
- A reply is steered by its tag, and the manager gets its own ID back.
- Write data has no address and no ID: it follows the stored route of the oldest waiting address.