PPROT, PNSE and the Four Address Spaces
Decode PPROT and PNSE into a privilege level and one of four physical address spaces. Then predict what a completer without RME does with Root and Realm accesses.
You Will Be Able To
- Decode PPROT[2:0] into privileged, Non-secure and instruction.
- Name the address space of any {PNSE, PPROT[1]} pair.
- Predict which register a Root or Realm access reaches on a completer with and without RME.
- Explain why a requester with RME and a completer without it are not compatible.
- Lesson
- P3.12
- Time
- 30 min
- Runs on
- Your browser
- Check
- 5 questions
A firmware update tool ran in the Root world and used a debug window to probe peripherals. One old peripheral had no PNSE input. It saw the Root accesses as Secure ones, so the tool could write the Secure world's key register. Nobody had broken a rule on the wires.
- Manager
- Subordinate
S_KEY belongs to the Secure address space.
- Cycle 0
A Root write to S_KEY, at offset 0x04.
- Cycle 1
The RME completer decodes Root and refuses with PSLVERR.
- Cycle 3
The same write to the old completer. It sees only PPROT[1] = 0, which means Secure, and accepts it.
Root is not Secure, but a completer without PNSE cannot tell.
PPROT: Three Bits About the Access
PPROT describes who asks and why, never the data. A completer with protection checks reads it, and one without them ignores it.
| Bit | Low | High | Use |
|---|---|---|---|
| PPROT[0] | normal | privileged | Processing mode; a privileged mode has more access. |
| PPROT[1] | Secure | Non-secure | The main use of PPROT. |
| PPROT[2] | data | instruction | A hint only: it might not be accurate. |
IHI 0024E Table 3-2. Systems may interpret PPROT[0] and PPROT[2] in their own way.
Because PPROT[2] is only a hint, a completer must not base a security decision on it. The example's PRIV_CTL register checks PPROT[0]: an unprivileged write gets PSLVERR and a privileged one is OKAY.
Four Address Spaces from Two Bits
The Arm Realm Management Extension adds two physical address spaces, Root and Realm, to Secure and Non-secure. APB5 carries them with one more signal, PNSE. Together with PPROT[1] it names the space.
| PNSE | PPROT[1] | Address space |
|---|---|---|
| 0 | 0 | Secure |
| 0 | 1 | Non-secure |
| 1 | 0 | Root |
| 1 | 1 | Realm |
IHI 0024E Table 3-5. PNSE must be valid whenever PSEL is high.
The example writes each of four registers from each address space. Every register except NS_DATA belongs to one space, and the RME completer follows the table exactly. Root reaches RT_CFG, Realm reaches RL_KEY, and neither reaches S_KEY.
A Completer Without RME
A completer without RME has no PNSE input, so it sees only PPROT[1]. A Root access arrives as Secure, and a Realm access as Non-secure. That is why the specification calls a requester with RME and a completer without it not compatible.
The example shows both effects. Root, seen as Secure, reaches every register the old completer keeps for Secure software. Realm, seen as Non-secure, reaches only NS_DATA.
| RME_Support | Completer False | Completer True |
|---|---|---|
| Requester False | Compatible. | Compatible: tie the completer's PNSE input LOW. |
| Requester True | Not compatible. | Compatible. |
IHI 0024E 3.6.2, Table 3-6. PNSE needs PPROT on the same interface, only exists on APB5, and is covered by PCTRLCHK.
Asked in interviews: protection and RME
What does PPROT = 3'b011 mean?
Privileged (bit 0), Non-secure (bit 1), data access (bit 2 low).
Can a completer use PPROT[2] to block code fetches?
It should not rely on it. The specification calls the bit a hint that might not be accurate.
How does APB name the Root and Realm spaces?
With PNSE and PPROT[1]: PNSE 1 and PPROT[1] 0 is Root; both 1 is Realm.
A requester has RME but the completer does not. Why not just leave PNSE open?
The completer would treat Root as Secure and Realm as Non-secure. The specification calls that pair not compatible.
Try It
The first four lines are Table 3-5 at work: each register answers only its own address space. The next two are the old completer. It keeps its Root and Realm registers for Secure software. So Root, seen as Secure, gets in everywhere, and Realm gets nowhere but NS_DATA.
Try sweep(1, 0, "Secure, no RME: "); and compare it with the Root line: the old completer cannot tell them apart.
Secure: NS_DATA OKAY, S_KEY OKAY, RT_CFG PSLVERR, RL_KEY PSLVERR Non-secure: NS_DATA OKAY, S_KEY PSLVERR, RT_CFG PSLVERR, RL_KEY PSLVERR Root: NS_DATA OKAY, S_KEY PSLVERR, RT_CFG OKAY, RL_KEY PSLVERR Realm: NS_DATA OKAY, S_KEY PSLVERR, RT_CFG PSLVERR, RL_KEY OKAY Root, no RME: NS_DATA OKAY, S_KEY OKAY, RT_CFG OKAY, RL_KEY OKAY Realm, no RME: NS_DATA OKAY, S_KEY PSLVERR, RT_CFG PSLVERR, RL_KEY PSLVERR PRIV_CTL: unprivileged PSLVERR, privileged OKAYRead included file: apb_rme_regs.sv
`timescale 1ns/1ns
// apb_rme_regs.sv: five 32-bit registers, each owned by one physical address space (read-only).
// 0x00 NS_DATA any address space 0x0c RL_KEY Realm only
// 0x04 S_KEY Secure only 0x10 PRIV_CTL any address space, privileged only
// 0x08 RT_CFG Root only
// With RME = 1 the address space comes from {PNSE, PPROT[1]}: 00 Secure, 01 Non-secure, 10 Root,
// 11 Realm (Table 3-5). With RME = 0 the block has no PNSE input and sees only PPROT[1]: an access is
// Secure or Non-secure, and its Root and Realm registers are treated as Secure-only.
// A refused access ends with PSLVERR and changes nothing; a refused read returns 0.
// PPROT[2] (instruction) is a hint and is not used for any decision here.
module apb_rme_regs #(parameter bit RME = 1) (
input logic pclk,
input logic presetn,
input logic psel,
input logic penable,
input logic pwrite,
input logic [31:0] paddr,
input logic [31:0] pwdata,
input logic [2:0] pprot,
input logic pnse,
output logic pready,
output logic [31:0] prdata,
output logic pslverr);
localparam int SEC = 0, NSEC = 1, ROOT = 2, REALM = 3;
logic [31:0] r [0:4];
initial for (int i = 0; i < 5; i++) r[i] = 0;
wire [1:0] pas = RME ? {pnse, pprot[1]} : {1'b0, pprot[1]};
wire [2:0] idx = paddr[4:2];
function automatic bit allowed(input logic [2:0] i, input logic [1:0] space, input logic priv);
case (i)
3'd0: return 1;
3'd1: return space == SEC;
3'd2: return RME ? space == ROOT : space == SEC;
3'd3: return RME ? space == REALM : space == SEC;
3'd4: return priv;
default: return 0;
endcase
endfunction
wire ok = (paddr[1:0] == 0) && (idx <= 4) && allowed(idx, pas, pprot[0]);
assign pready = 1'b1;
assign pslverr = psel && penable && !ok;
assign prdata = (psel && ok && idx <= 4) ? r[idx] : 32'h0;
always @(posedge pclk) if (psel && penable && pwrite && ok) r[idx] <= pwdata;
endmodule
Check Yourself
Common Mistakes
Wrong Read PPROT[1] = 1 as Secure.
PPROT[1] low is Secure and high is Non-secure.
Fix Treat PPROT[1] as the Non-secure bit, the same sense as AxPROT[1] on AXI.
Wrong Leave out PNSE on a completer and decode the space from PPROT[1] alone in an RME system.
Root accesses then look Secure and Realm accesses look Non-secure.
Fix Decode the space from {PNSE, PPROT[1]}, or keep the completer away from RME requesters.
wire secure = !pprot[1];wire [1:0] pas = {pnse, pprot[1]};
wire secure = (pas == 2'b00);Wrong Block instruction fetches by checking PPROT[2].
The specification calls PPROT[2] a hint that might not be accurate.
Fix Enforce execute permissions where the access is made, for example in the MMU or MPU of the processor.
Remember
- PPROT[0] is privileged, PPROT[1] is Non-secure, and PPROT[2] is an instruction hint.
- With RME, {PNSE, PPROT[1]} names the space: 00 Secure, 01 Non-secure, 10 Root, 11 Realm.
- A completer without PNSE sees Root as Secure and Realm as Non-secure, so the pair is not compatible.
- A completer with RME behind a requester without it gets PNSE tied LOW.
- PNSE needs PPROT on the same APB5 interface and must be valid while PSEL is high.