U18.7.1 A Register That Locks Itself

HardImplementUVM · serverReview the topic

Make a locked control register refuse writes, and the memory it guards refuse every access, before the bus. Count the memory reads that happened, and list what is attached to a register.

Hardware context: APB register slice with a lock bit, a guarded memory and a read-only and a write-only register at one address. Refuse writes to a locked register and accesses to the memory it guards, and count the callbacks on a register.

The register slice's CTRL has a lock bit. Once it is 1, the design ignores writes to CTRL and to MEM until reset, and MEM reads return 00. The model does not know that. A write still goes out on the bus, and the mirror takes a value the design never took.

Install callbacks so that every access the locked design would ignore makes no bus transfer and returns UVM_NOT_OK. CTRL must stay readable. A security audit counts the MEM reads that really reached the design. A debug helper counts the callbacks attached to a register and to its fields.

Full specification
What you write
// Refuses the accesses a locked design would ignore: no bus transfer, UVM_NOT_OK.
class lock_guard extends uvm_reg_cbs;
  `uvm_object_utils(lock_guard)
  ctrl_reg ctrl;
  function new(string name = "lock_guard"); super.new(name); endfunction
endclass

// Counts the MEM reads that really reached the design.
class read_audit extends uvm_reg_cbs;
  `uvm_object_utils(read_audit)
  int reads;
  function new(string name = "read_audit"); super.new(name); endfunction
endclass

// Called once per model in connect_phase. Returns the audit attached to MEM.
function automatic read_audit protect(slice_regs regs);
  read_audit a = new("read_audit");
  return a;
endfunction

// How many callbacks are attached to r and to its fields.
function automatic int hooks_on(uvm_reg r);
  return 0;
endfunction
AccessWhat must happen
ctrl.write while the design's lock bit is 1No bus transfer, status UVM_NOT_OK, mirror unchanged
mem.write or mem.read while lockedNo bus transfer, status UVM_NOT_OK
status.writeNo bus transfer, UVM_NOT_OK, the library's UVM/REG/READONLY error
cmd.readNo bus transfer, UVM_NOT_OK, the library's UVM/REG/WRTEONLY error
Anything else, including ctrl.readUnchanged: one bus transfer
You also returnMeaning
read_audit.readsMEM reads that completed on the bus (refused ones do not count)
hooks_on(r)Callbacks attached to register r plus those attached to each of its fields

Auto prediction is on. The bench expects the READONLY and WRTEONLY errors and does not let them fail the run. It counts CBPREG warnings, which must stay at 0. Some cases add do-nothing bench callbacks to STATUS, CMD, CFG or CFG_A, or their fields, before protect runs. At the end the bench calls hooks_on for those four registers.

Examples

Example 1

Lock, Then Try to Change the Mode
Input
ctrl.write(03); ctrl.write(13); ctrl.write(05); ctrl.read
Output
transfers = 3, refused = 1, ctrl_mirror = 0x13, ctrl_in_design = 0x13, commands_taken = 0, mem_reads_audited = 0, readonly_errors = 0, writeonly_errors = 0, cbpreg_warnings = 0, hooks_on_status = 2, hooks_on_cmd = 2, hooks_on_cfg = 0, hooks_on_cfg_a = 0

The second write locks CTRL. The third is refused before the bus; the read still goes out. Three transfers, one refusal, mirror and design both 13. STATUS and CMD each carry two callbacks: the map's, on the register and on its field.

Example 2

Write STATUS, Read CMD
Input
status.write(1); cmd.read; cmd.write(9); status.read
Output
transfers = 2, refused = 2, ctrl_mirror = 0x0, ctrl_in_design = 0x0, commands_taken = 1, mem_reads_audited = 0, readonly_errors = 1, writeonly_errors = 1, cbpreg_warnings = 0, hooks_on_status = 2, hooks_on_cmd = 2, hooks_on_cfg = 0, hooks_on_cfg_a = 0

Both wrong-way accesses are refused with no transfer, each with its library error. The CMD write and the STATUS read go out.

Example 3

MEM Before and After the Lock
Input
mem.write(2, 5a); mem.read(2); ctrl.write(11); mem.write(3, 77); mem.read(2); mem.read(3)
Output
transfers = 3, refused = 3, ctrl_mirror = 0x11, ctrl_in_design = 0x11, commands_taken = 0, mem_reads_audited = 1, readonly_errors = 0, writeonly_errors = 0, cbpreg_warnings = 0, hooks_on_status = 2, hooks_on_cmd = 2, hooks_on_cfg = 0, hooks_on_cfg_a = 0

The first write and read go out, so the audit counts 1. After the lock, the MEM write and both reads are refused: four transfers, three refusals.

Constraints and Contract

  • Keep the class names and the signatures of protect and hooks_on; protect is called once per model.
  • Decide from what the model knows about the design, before any transfer.

Hints

Hint 1

Which hook runs before the bus transfer, and what does a status other than UVM_IS_OK do there? Memories have the same hooks, through their own pool.

Hint 2

uvm_reg::write sets the desired value to the new value before any hook runs. Which value still says what the design holds?

Hint 3

One callback object attached to CTRL and to MEM sees both kinds of access. What in the item tells them apart?

Hint 4

Only one of a read's hooks knows that the read really happened. Callbacks added before the guard run before it.

Hint 5

Before you add anything to STATUS or CMD, read what uvm_reg_map::add_reg does when two such registers share an address. What does that add attach?

What the grader checks: Your callbacks protect six real register models, each on its own design and bus, through hidden access sequences. The checks count bus transfers and refusals and read the mirror, the design and the library's error counts. They read your audit, and call hooks_on after the bench added callbacks of its own.

6 checks on UVM · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain public samples only. A passing result establishes the tested cases, not a proof for all possible inputs.

See all 1 problem on this path

Report a problem with this page

Your code SystemVerilogSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

Lock, Then Try to Change the Mode

Input
ctrl.write(03); ctrl.write(13); ctrl.write(05); ctrl.read
Expected output
transfers = 3, refused = 1, ctrl_mirror = 0x13, ctrl_in_design = 0x13, commands_taken = 0, mem_reads_audited = 0, readonly_errors = 0, writeonly_errors = 0, cbpreg_warnings = 0, hooks_on_status = 2, hooks_on_cmd = 2, hooks_on_cfg = 0, hooks_on_cfg_a = 0

The second write locks CTRL. The third is refused before the bus; the read still goes out. Three transfers, one refusal, mirror and design both 13. STATUS and CMD each carry two callbacks: the map's, on the register and on its field.

Run samples executes all 3 public checks. Check all tests runs 6 checks on the server.

UVM · server