opentitan icon indicating copy to clipboard operation
opentitan copied to clipboard

[dv] reg.randomize doesn't work for some regs

Open weicaiyang opened this issue 5 years ago • 10 comments

In uvm_reg_field::configure, UVM turns off rand_mode for some regs.

   // Ignore is_rand if the field is known not to be writeable
   // i.e. not "RW", "WRC", "WRS", "WO", "W1", "WO1"
   case (access)
    "RO", "RC", "RS", "WC", "WS",
      "W1C", "W1S", "W1T", "W0C", "W0S", "W0T",
      "W1SRC", "W1CRS", "W0SRC", "W0CRS", "WSRC", "WCRS",
      "WOC", "WOS": is_rand = 0;
   endcase

   if (!is_rand)
     value.rand_mode(0);

https://verificationacademy.com/verification-methodology-reference/uvm/src/reg/uvm_reg_field.svh

We have a W0C reg in keymgr. I use this to randomize and update it. And it always writes 1 to the reg, which took me a while to figure it out.

csr.randomize();
csr.update();

I don't agree with the comment in UVM. "RO" isn't writeable, but it's good to write some value and test it. "W1C", "W0C" and some others are writeable. I feel it's not right to set rand_mode=0 for these types of regs. I'm thinking we may need a better approach for this.

  1. avoid using csr randomize and update. Below can serve the propose easily.
csr.set($urandom);
csr.update();

This is also what we do in csr_seq. https://github.com/lowRISC/opentitan/blob/b588e46e1a89326f130a68ada969fae535849d33/hw/dv/sv/csr_utils/csr_seq_lib.sv#L408-L410 2. since configure is not a virtual function, we can't override it. We may set the rand_mode back to 1 in generated ral_pkg. 3. any other suggestion? Thanks

weicaiyang avatar Feb 04 '21 22:02 weicaiyang

@weicaiyang IMO I prefer method 1) because it is clear way of coding

tunghoang290780 avatar Feb 05 '21 03:02 tunghoang290780

Great find! I also disagree with UVM - we should be able to randomize and write CSR with whatever we want regardless of the access policies. I will recommend filing a bug with UVM and understanding their motivation (may need to figure out how).

Though I agree option 1 is safer in terms of avoiding a pitfall like this, we should also set value.rand_mode(1); to the build() method in the UVM RAL template to enforce it to be randomizable again. We invoke it after invoking configure().

sriyerg avatar Feb 05 '21 04:02 sriyerg

@weicaiyang, please check if #5113 fixes the problem (pretty sure it should).

sriyerg avatar Feb 05 '21 07:02 sriyerg

Thanks everyone's input. I filed an issue with UVM here

#5113 should fix the issue. Thanks @sriyerg

weicaiyang avatar Feb 05 '21 19:02 weicaiyang

Reopening in case some more discussion is warranted.

sriyerg avatar Feb 05 '21 19:02 sriyerg

I'd like to hear what Accellera says so please post updates from your uvm issue.

senelson7 avatar Feb 05 '21 19:02 senelson7

with the fix, either csr.randomize(); or csr.set($urandom); can work. Free feel to chime in your thought. Or we can close this.

weicaiyang avatar Feb 05 '21 19:02 weicaiyang

I'd like to hear what Accellera says so please post updates from your uvm issue.

sure, will report back if any update.

weicaiyang avatar Feb 05 '21 19:02 weicaiyang

@weicaiyang this is a great discovery. seems like a very "software ish" approach to say - RO is not writeable - there for should not be tested! IMO RO means you should not write - but designer should expect someone will try to do just that. So I agree with need this tested. either option is ok with me!

rasmus-madsen avatar Feb 08 '21 09:02 rasmus-madsen

Thanks everyone's input. close it via #5113

weicaiyang avatar Feb 09 '21 23:02 weicaiyang