APB Versions and Compatibility
Connect an APB requester to a completer of another version. Pick each tie-off from the specification's tables, and predict what the missing signals cost.
You Will Be Able To
- Name the signals APB2, APB3, APB4 and APB5 each add, and the default of each optional one.
- Choose the tie-off for a missing PSTRB, PPROT or PNSE from the compatibility tables.
- Predict what a byte write does to a completer without PSTRB.
- Explain why tying PPROT to its default can open a security hole.
- Lesson
- P3.11
- Time
- 30 min
- Runs on
- Your browser
- Check
- 5 questions
A team moved a key store from an old APB3 bridge to a new APB4 one, and kept the old wiring. Its PPROT input stayed tied to 000, the specification's default. But 000 means a Secure access. From then on, every Non-secure write to the Secure key register was accepted.
- Manager
- Subordinate
PPROT[1] = 1 is Non-secure. pprot_seen is what each completer receives.
- Cycle 0
Setup of a Non-secure write to the Secure register of key store A. A sees PPROT 000: a Secure access.
- Cycle 1
A completes it with OKAY. The key is overwritten.
- Cycle 3
The same write to key store B, whose PPROT is wired. B sees 010 and refuses with PSLVERR.
A tie-off is a claim about every access that will ever arrive.
Four Versions, One Transfer
Every version keeps the setup and access phases of the one before. Each adds optional signals, and Appendix B gives each optional signal a default for an input nobody drives.
| Version | Adds | Default of a missing input |
|---|---|---|
| APB2 (AMBA 2) | PSEL, PENABLE, PADDR, PWRITE, PWDATA, PRDATA | — |
| APB3 | PREADY, PSLVERR | PREADY 1, PSLVERR 0 |
| APB4 | PPROT, PSTRB | PPROT 000; PSTRB has a table instead |
| APB5 | PWAKEUP, user signals, parity check signals, PNSE (issue E) | PNSE 0 |
IHI 0024E Preface and Table B-1. An APB2 completer looks like an APB3 completer that is always ready and never fails.
The example runs one APB4 requester against an APB2 completer, an APB3 completer with one wait state, and two APB4 completers. Each gets the same byte write, an unmapped offset and a Non-secure write to its Secure register SREG.
- Manager
- Subordinate
The APB3 completer has no strobe input, so the strobes stop at its edge.
- Cycle 0
Setup of the byte write. PSTRB says only lane 1 is valid.
- Cycle 2
After one wait state the write completes. The completer writes all four lanes.
- Cycle 5
The read back returns 0000aa00: the three 11 bytes are gone.
Compatible, says Table 3-1, but sparse writes are not supported.
The Compatibility Tables
Three tables in the specification decide what a missing signal means. Read each row as requester on the left, completer on the top.
| Signal | Requester has it, completer does not | Completer has it, requester does not |
|---|---|---|
| PSTRB | Compatible. Sparse writes are not supported, and the documentation must say so. | Compatible. Tie the completer's PSTRB inputs to the requester's PWRITE. |
| PPROT | Compatible. The completer has no protection, so PPROT is ignored. | Not compatible, unless one fixed protection value is functionally correct. |
| PNSE | Not compatible. | Compatible. Tie the completer's PNSE input LOW. |
IHI 0024E Tables 3-1, 3-3 and 3-6.
The PPROT row is the opening story. Tying PPROT to 000 does not leave protection out: it claims every access is normal, Secure and data. That is functionally correct only if Secure software is the only thing that can reach the completer.
With RME, the address space comes from PNSE and PPROT[1] together: Secure, Non-secure, Root or Realm. Lesson P3.12 builds on that.
Data Width
PRDATA and PWDATA can each be 8, 16 or 32 bits wide, but both must have the same width. PADDR is always a byte address. A 32-bit register on an 8-bit APB therefore takes four transfers, one byte each.
Two interfaces of different widths do not connect directly. A bridge between them splits or joins the transfers, the way an AXI width converter does.
Asked in interviews: APB versions
What does an APB2 completer drive on PREADY?
Nothing: APB2 has no PREADY. The requester's input takes the default, 1, so every transfer ends after one access cycle.
An APB4 completer meets an APB3 requester. What about PPROT?
Not compatible, unless one fixed value is correct for every access. Tying it to 000 makes every access Secure.
Can you mix an 8-bit and a 32-bit APB interface?
Not directly. Read and write data are the same width on one interface; a bridge must convert.
Try It
APB2 and APB3 have no PSTRB, so the byte write replaces the whole word. APB2 has no PSLVERR, so the unmapped write ends OKAY and its error is lost. Neither has PPROT, so neither can protect SREG.
The wired APB4 completer keeps its neighbours, reports the unmapped offset and refuses the Non-secure write. The tied one does all of that except the last. Change its tie-off to 3'b010 and it refuses every write to SREG, Secure ones included.
APB2: byte write leaves 0000aa00, unmapped OKAY, Non-secure write to SREG OKAY, SREG = 5a APB3: byte write leaves 0000aa00, unmapped PSLVERR, Non-secure write to SREG OKAY, SREG = 5a APB4: byte write leaves 1111aa11, unmapped PSLVERR, Non-secure write to SREG PSLVERR, SREG = 00 APB4, PPROT tied 000: byte write leaves 1111aa11, unmapped PSLVERR, Non-secure write to SREG OKAY, SREG = 5aRead included file: apb_ver.sv
`timescale 1ns/1ns
// apb_ver.sv: a small APB completer built as APB2, APB3, APB4 or APB5 (read-only).
// It has 16 bytes of RAM at offset 0x00 to 0x0f and a Secure-only register SREG at 0x10.
// VERSION decides which signals the completer has; its port list keeps them all, so a version that
// lacks a signal simply ignores the input or drives the output to the specification default.
// APB2 no PREADY (driven 1), no PSLVERR (driven 0), no PSTRB (writes every lane), no PPROT
// APB3 adds PREADY (WAITS wait states) and PSLVERR (unmapped offsets and refused writes)
// APB4 adds PSTRB (writes only strobed lanes) and PPROT: SREG refuses a Non-secure write (PPROT[1] = 1)
// APB5 the same transfer as APB4 here (its additions are optional sideband signals)
// DATA_W is 8, 16 or 32; a transfer moves DATA_W/8 bytes at the aligned address.
// Without PPROT an APB2 or APB3 completer cannot tell Secure from Non-secure, so SREG takes any write.
module apb_ver #(parameter int VERSION = 4, parameter int DATA_W = 32, parameter int WAITS = 0) (
input logic pclk,
input logic presetn,
input logic psel,
input logic penable,
input logic pwrite,
input logic [31:0] paddr,
input logic [DATA_W-1:0] pwdata,
input logic [DATA_W/8-1:0] pstrb,
input logic [2:0] pprot,
output logic pready,
output logic [DATA_W-1:0] prdata,
output logic pslverr);
localparam int B = DATA_W / 8;
logic [7:0] mem [0:16]; // bytes 0 to 15 are the RAM, byte 16 is SREG
int wcnt = 0;
initial for (int i = 0; i <= 16; i++) mem[i] = 0;
wire [7:0] off = paddr[7:0];
wire mapped = (off < 8'h10) || (off == 8'h10 && B == 1) || (off[7:2] == 6'h04 && B > 1);
wire refused = (VERSION >= 4) && pwrite && (off >= 8'h10) && pprot[1];
wire access = psel && penable;
assign pready = (VERSION == 2) ? 1'b1 : (access ? (wcnt >= WAITS) : 1'b0);
assign pslverr = (VERSION == 2) ? 1'b0 : (access && pready && (!mapped || refused));
wire [7:0] base = off & ~8'(B - 1);
for (genvar l = 0; l < B; l++) begin : g_rd
assign prdata[8*l +: 8] = (base + l <= 16) ? mem[base + l] : 8'h00;
end
always @(posedge pclk or negedge presetn) begin
if (!presetn) wcnt <= 0;
else begin
wcnt <= (access && !pready) ? wcnt + 1 : 0;
if (access && pready && pwrite && mapped && !refused)
for (int l = 0; l < B; l++)
if ((VERSION < 4 || pstrb[l]) && base + l <= 16) mem[base + l] <= pwdata[8*l +: 8];
end
end
endmodule
Check Yourself
Common Mistakes
Wrong Tie a completer's PPROT input to 3'b000 because 000 is the default.
PPROT 000 means normal, Secure and data, so every access gets Secure rights.
Fix Tie PPROT only to a value that is correct for every access, or treat the pair as not compatible.
.pprot(3'b000) // default, so it must be safe.pprot(3'b010) // this requester is Non-secure onlyWrong Tie the PSTRB inputs of an APB4 completer high when the requester has no PSTRB.
Reads would then carry strobes, and the protocol requires every strobe low during a read.
Fix Tie every PSTRB bit to the requester's PWRITE.
.pstrb(4'b1111).pstrb({4{pwrite}})Wrong Trust byte stores to a register block because the bridge sends PSTRB.
An APB2 or APB3 block has no strobe input and writes every lane of the word.
Fix Check the block's version. Without PSTRB, do read-modify-write in software or put an adapter in front.
Remember
- APB3 added PREADY and PSLVERR, APB4 PPROT and PSTRB, APB5 wake-up, user, parity and PNSE.
- A missing PREADY reads as 1 and a missing PSLVERR as 0, so an APB2 completer never waits or fails.
- A completer without PSTRB writes whole words; a completer with PSTRB behind a requester without it gets PSTRB tied to PWRITE.
- PPROT tied to 000 claims every access is Secure; PNSE behind a requester without it is tied low.
- Both data buses of one interface have the same width: 8, 16 or 32 bits.