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.

One Root Write to S_KEY, Two CompletersEdges 3 to 6 of a measured run. Both writes carry PNSE 1 and PPROT 001: Root, privileged. The first completer supports RME; the second does not.
  • Manager
  • Subordinate
PSELPSELPSLVERRRequesterRoot worldRME completersees PNSEOld completerno PNSE input
PSEL→ RME completerPSEL→ Old completerPSLVERR→ RequesterRequesterRoot worldRME completersees PNSEOld completerno PNSE input

S_KEY belongs to the Secure address space.

0123clkpsel_rmepsel_oldpenablepnsepprot001pslverr
Scroll horizontally ↔
  1. Cycle 0

    A Root write to S_KEY, at offset 0x04.

  2. Cycle 1

    The RME completer decodes Root and refuses with PSLVERR.

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

BitLowHighUse
PPROT[0]normalprivilegedProcessing mode; a privileged mode has more access.
PPROT[1]SecureNon-secureThe main use of PPROT.
PPROT[2]datainstructionA 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.

PNSEPPROT[1]Address space
00Secure
01Non-secure
10Root
11Realm

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_SupportCompleter FalseCompleter True
Requester FalseCompatible.Compatible: tie the completer's PNSE input LOW.
Requester TrueNot 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
  1. What does PPROT = 3'b011 mean?

    Privileged (bit 0), Non-secure (bit 1), data access (bit 2 low).

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

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

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

RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: 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 OKAY
Read 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

Predict the outputOn the RME completer, Realm writes 77 to RL_KEY and Root writes 99 to it. Then Realm reads RL_KEY. It prints RL_KEY = and the value in hex. What is the line?
`timescale 1ns/1ps
module tb;
  logic pclk = 0, presetn = 0;
  always #5 pclk = ~pclk;                 // rising edges at 5, 15, 25, ...
  logic        penable = 0, pwrite = 0, pnse = 0;
  logic [31:0] paddr = 0, pwdata = 0;
  logic [2:0]  pprot = 0;
  logic [1:0]  pselx = 0;
  wire  [1:0]  rdy, err;
  wire  [31:0] rd [0:1];
  // Completer 0 supports RME and sees PNSE. Completer 1 does not (RME = 0): it sees only PPROT.
  apb_rme_regs #(.RME(1)) rme (.pclk(pclk), .presetn(presetn), .psel(pselx[0]), .penable(penable), .pwrite(pwrite), .paddr(paddr),
                               .pwdata(pwdata), .pprot(pprot), .pnse(pnse), .pready(rdy[0]), .prdata(rd[0]), .pslverr(err[0]));
  apb_rme_regs #(.RME(0)) old (.pclk(pclk), .presetn(presetn), .psel(pselx[1]), .penable(penable), .pwrite(pwrite), .paddr(paddr),
                               .pwdata(pwdata), .pprot(pprot), .pnse(1'b0), .pready(rdy[1]), .prdata(rd[1]), .pslverr(err[1]));
  int cycle = -1;
  always @(posedge pclk) begin
    cycle++;
    if (0) $display("wave e%0d: psel=%b penable=%b pwrite=%b paddr=%h pprot=%b pnse=%b pready=%b pslverr=%b", cycle, pselx, penable, pwrite, paddr, pprot, pnse, rdy, err);
  end
  logic [31:0] rdata;
  bit          rerr;
  // The address space as {PNSE, PPROT[1]}: 0 Secure, 1 Non-secure, 2 Root, 3 Realm.
  function automatic string space(input int s);
    case (s) 0: return "Secure"; 1: return "Non-secure"; 2: return "Root"; default: return "Realm"; endcase
  endfunction
  // One transfer to completer k in address space s; priv is PPROT[0].
  task automatic xfer(input int k, input bit wr, input logic [31:0] a, input logic [31:0] d, input int s, input bit priv = 1);
    paddr = a; pwrite = wr; pwdata = wr ? d : 0; pnse = s[1]; pprot = {1'b0, s[0], priv};
    pselx = 2'b1 << k; penable = 0;
    @(posedge pclk); #1 penable = 1;
    @(posedge pclk); while (rdy[k] !== 1'b1) @(posedge pclk);
    rdata = rd[k]; rerr = err[k];
    #1 pselx = 0; penable = 0; pwrite = 0;
  endtask
  // One write to each of the four address-space registers; one line of responses.
  task automatic sweep(input int k, input int s, input string who);
    string line;
    line = who;
    for (int i = 0; i < 4; i++) begin
      xfer(k, 1, 4 * i, 32'h100 + i, s);
      line = {line, $sformatf("%0s%0s %0s", i ? ", " : "", i == 0 ? "NS_DATA" : i == 1 ? "S_KEY" : i == 2 ? "RT_CFG" : "RL_KEY", rerr ? "PSLVERR" : "OKAY")};
    end
    $display("%0s", line);
  endtask
  initial begin
    repeat (2) @(posedge pclk); #1 presetn = 1;   // reset released after edge 1
    @(posedge pclk); #1;
    xfer(0, 1, 32'h0c, 32'h77, 3);
    xfer(0, 1, 32'h0c, 32'h99, 2);
    xfer(0, 0, 32'h0c, 0, 3);
    $display("RL_KEY = %h", rdata);
    $finish;
  end
endmodule
Read 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
Spot the bugEach option is one write to S_KEY (offset 0x04) on the completer without RME (k = 1). Which one is refused?
Read 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
ConceptWhich pair names the Realm physical address space?
ConceptA completer supports RME. The requester in front of it does not. What does the integrator do with the completer's PNSE input?
ConceptA peripheral wants to refuse instruction fetches from its data buffer. Its designer proposes to check PPROT[2]. What is the problem?

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.

Before
wire secure = !pprot[1];
After
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.

Practice

Report a problem with this page