Skip to content

Commit

Permalink
[otp_ctrl/lint] Update range comparisons
Browse files Browse the repository at this point in the history
This ensures we are not inserting range comparisons that can
never be false (which the linter complained about).

Signed-off-by: Michael Schaffner <[email protected]>
  • Loading branch information
msfschaffner committed Jan 25, 2024
1 parent c470b98 commit 37cbc50
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
8 changes: 6 additions & 2 deletions hw/ip/otp_ctrl/rtl/otp_ctrl.sv
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,12 @@ module otp_ctrl
for (genvar k = 0; k < NumPart; k++) begin : gen_part_sel
localparam logic [OtpByteAddrWidth:0] PartEnd = (OtpByteAddrWidth+1)'(PartInfo[k].offset) +
(OtpByteAddrWidth+1)'(PartInfo[k].size);
assign tlul_part_sel_oh[k] = ({tlul_addr, 2'b00} >= PartInfo[k].offset) &
({1'b0, {tlul_addr, 2'b00}} < PartEnd);
if (PartInfo[k].offset == 0) begin : gen_zero_offset
assign tlul_part_sel_oh[k] = ({1'b0, {tlul_addr, 2'b00}} < PartEnd);
end else begin : gen_nonzero_offset
assign tlul_part_sel_oh[k] = ({tlul_addr, 2'b00} >= PartInfo[k].offset) &
({1'b0, {tlul_addr, 2'b00}} < PartEnd);
end
end

`ASSERT(PartSelMustBeOnehot_A, $onehot0(tlul_part_sel_oh))
Expand Down
9 changes: 7 additions & 2 deletions hw/ip/otp_ctrl/rtl/otp_ctrl_dai.sv
Original file line number Diff line number Diff line change
Expand Up @@ -702,8 +702,13 @@ module otp_ctrl_dai
// between OtpAddrWidth and OtpByteAddrWidth, so we know that we can slice safely here.
localparam bit [OtpAddrWidth-1:0] DigestAddrLut = DigestAddrLutInt[OtpAddrWidth-1:0];

assign part_sel_oh[k] = (dai_addr_i >= PartInfo[k].offset) &
({1'b0, dai_addr_i} < PartEndInt[OtpByteAddrWidth:0]);
if (PartInfo[k].offset == 0) begin : gen_zero_offset
assign part_sel_oh[k] = ({1'b0, dai_addr_i} < PartEndInt[OtpByteAddrWidth:0]);

end else begin : gen_nonzero_offset
assign part_sel_oh[k] = (dai_addr_i >= PartInfo[k].offset) &
({1'b0, dai_addr_i} < PartEndInt[OtpByteAddrWidth:0]);
end
assign digest_addr_lut[k] = DigestAddrLut;
end

Expand Down
13 changes: 10 additions & 3 deletions hw/ip/otp_ctrl/rtl/otp_ctrl_part_unbuf.sv
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ module otp_ctrl_part_unbuf
logic digest_reg_en;
logic ecc_err;

logic tlul_addr_in_range;
logic [SwWindowAddrWidth-1:0] tlul_addr_d, tlul_addr_q;

// This is only used to return bus errors when the FSM is in ErrorSt.
Expand Down Expand Up @@ -233,9 +234,7 @@ module otp_ctrl_part_unbuf
ReadSt: begin
init_done_o = 1'b1;
// Double check the address range.
if ({tlul_addr_q, 2'b00} >= Info.offset &&
{1'b0, tlul_addr_q, 2'b00} < PartEnd &&
mubi8_test_false_strict(access_o.read_lock)) begin
if (tlul_addr_in_range && mubi8_test_false_strict(access_o.read_lock)) begin
otp_req_o = 1'b1;
otp_addr_sel = DataAddrSel;
if (otp_gnt_i) begin
Expand Down Expand Up @@ -325,6 +324,14 @@ module otp_ctrl_part_unbuf
// Do not forward data in case of an error.
assign tlul_rdata_o = (tlul_rvalid_o && tlul_rerror_o == '0) ? otp_rdata_i[31:0] : '0;

if (Info.offset == 0) begin : gen_zero_offset
assign tlul_addr_in_range = {1'b0, tlul_addr_q, 2'b00} < PartEnd;

end else begin : gen_nonzero_offset
assign tlul_addr_in_range = {tlul_addr_q, 2'b00} >= Info.offset &&
{1'b0, tlul_addr_q, 2'b00} < PartEnd;
end

// Note that OTP works on halfword (16bit) addresses, hence need to
// shift the addresses appropriately.
logic [OtpByteAddrWidth-1:0] addr_calc;
Expand Down
3 changes: 2 additions & 1 deletion hw/ip/otp_ctrl/rtl/otp_ctrl_scrmbl.sv
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,12 @@ module otp_ctrl_scrmbl
digest_iv_lut = '0;

for (int k = 0; k < NumScrmblKeys; k++) begin
localparam logic [4:0] NumRounds = 5'(unsigned'(NumPresentRounds));
otp_enc_key_lut[k] = rnd_cnst_key_anchor[k];
// Due to the PRESENT key schedule, we have to step the key schedule function by
// NumPresentRounds forwards to get the decryption key.
otp_dec_key_lut[k] =
prim_cipher_pkg::present_get_dec_key128(rnd_cnst_key_anchor[k], 5'(NumPresentRounds));
prim_cipher_pkg::present_get_dec_key128(rnd_cnst_key_anchor[k], NumRounds);
end

for (int k = 0; k < NumDigestSets; k++) begin
Expand Down

0 comments on commit 37cbc50

Please sign in to comment.