[dv] reg.randomize doesn't work for some regs
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.
- 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 IMO I prefer method 1) because it is clear way of coding
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().
@weicaiyang, please check if #5113 fixes the problem (pretty sure it should).
Reopening in case some more discussion is warranted.
I'd like to hear what Accellera says so please post updates from your uvm issue.
with the fix, either csr.randomize(); or csr.set($urandom); can work. Free feel to chime in your thought. Or we can close this.
I'd like to hear what Accellera says so please post updates from your uvm issue.
sure, will report back if any update.
@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!
Thanks everyone's input. close it via #5113