-
Notifications
You must be signed in to change notification settings - Fork 792
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[prim_fifo_sync,rtl] Specialize for Depth == 1
This case is pretty simple to reason about, and avoids needing proper read and write addresses (because there is only one element). Unfortunately, it's quite a big commit! This is because we end up changing some of the duplicated counters inside the fifo. Items in the commit: - Update the RTL in prim_fifo_sync.sv to specialize as you'd expect. - Add an interface that can be bound in to prim_fifo_sync.sv and will register a way for sec_cm tests to use forced signals to simulate fault injections. - Bind that interface into the prim_fifo_sync instances - Wrap up the ASSERT_PRIM_COUNT_ERROR_TRIGGER_ALERT calls that are used for prim_fifo_sync instances. After the change, the two macro calls that were previously used (for the read and write pointer) are now handled by a single macro. In instances with Depth >= 2, this turns into ASSERT_PRIM_FIFO_SYNC_ERROR_TRIGGERS_ALERT. For singleton instances, it's ASSERT_PRIM_FIFO_SYNC_ERROR_TRIGGERS_ALERT1. I don't *think* you can make the dispatch between the two options automatic (because the pre-processor can't know the values of the Depth parameter). - Use these new macros in the various blocks that were using prim_fifo_sync in secure mode with Depth = 1. This is CSRNG, OTBN and flash_ctrl. Signed-off-by: Rupert Swarbrick <[email protected]>
- Loading branch information
1 parent
16b5876
commit 2461469
Showing
15 changed files
with
315 additions
and
218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright lowRISC contributors (OpenTitan project). | ||
// Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// Countermeasure interface for the hardened 1-bit counter in prim_fifo_sync if Depth=1. | ||
// | ||
// This interface can be bound into a prim_fifo_sync instance. Many instances of the interface will | ||
// not do anything, because Depth > 1 or or Secure = 0. However if Depth = 1 and Secure = 1, the | ||
// nested prim_singleton_fifo_if_proxy class will register the instance in sec_cm_pkg and can | ||
// inject/restore faults. | ||
interface prim_singleton_fifo_if #( | ||
parameter int Depth = 1, | ||
parameter bit Secure = 1'b1 | ||
) ( | ||
input clk_i, | ||
input rst_ni | ||
); | ||
|
||
`include "dv_macros.svh" | ||
`include "uvm_macros.svh" | ||
import uvm_pkg::*; | ||
|
||
string msg_id = $sformatf("%m"); | ||
|
||
string path = dv_utils_pkg::get_parent_hier($sformatf("%m")); | ||
string signal_forced; | ||
|
||
class prim_singleton_fifo_if_proxy extends sec_cm_pkg::sec_cm_base_if_proxy; | ||
logic orig_value; | ||
|
||
function new(string name=""); | ||
super.new(name); | ||
endfunction | ||
|
||
virtual task automatic inject_fault(); | ||
logic force_value; | ||
|
||
@(negedge clk_i); | ||
`DV_CHECK(uvm_hdl_read(signal_forced, orig_value)) | ||
`DV_CHECK(uvm_hdl_force(signal_forced, ~orig_value)) | ||
`uvm_info(msg_id, | ||
$sformatf("Forcing %s from %0d to %0d", signal_forced, orig_value, ~orig_value), | ||
UVM_LOW) | ||
|
||
@(negedge clk_i); | ||
`DV_CHECK(uvm_hdl_release(signal_forced)) | ||
endtask | ||
|
||
virtual task automatic restore_fault(); | ||
`DV_CHECK(uvm_hdl_deposit(signal_forced, orig_value)) | ||
`uvm_info(msg_id, $sformatf("Forcing %s to original value %0d", signal_forced, orig_value), | ||
UVM_LOW) | ||
endtask | ||
endclass | ||
|
||
if (Depth == 1 && Secure) begin : gen_secure_singleton | ||
prim_singleton_fifo_if_proxy if_proxy; | ||
initial begin | ||
string local_signal; | ||
local_signal = $urandom_range(0, 1) ? "inv_full" : "full_q"; | ||
signal_forced = $sformatf("%s.%s", path, local_signal); | ||
`DV_CHECK_FATAL(uvm_hdl_check_path(signal_forced),, msg_id) | ||
|
||
// Store the proxy object for TB to use | ||
if_proxy = new("if_proxy"); | ||
if_proxy.sec_cm_type = sec_cm_pkg::SecCmSingletonFifo; | ||
if_proxy.path = path; | ||
sec_cm_pkg::sec_cm_if_proxy_q.push_back(if_proxy); | ||
|
||
`uvm_info(msg_id, $sformatf("Interface proxy class is added for %s", path), UVM_HIGH) | ||
end | ||
end | ||
|
||
endinterface |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright lowRISC contributors (OpenTitan project). | ||
// Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
module sec_cm_prim_singleton_fifo_bind (); | ||
// Bind prim_singleton_fifo_if into each instance of prim_fifo_sync. This will have no effect | ||
// unless the fifo has Depth=1 and Secure=1. | ||
bind | ||
prim_fifo_sync | ||
prim_singleton_fifo_if #(.Depth(Depth), .Secure(Secure)) u_prim_singleton_fifo_if (.*); | ||
endmodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright lowRISC contributors (OpenTitan project). | ||
// Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Macros that define assertions that relate to FIFO implementations | ||
|
||
`ifndef PRIM_FIFO_ASSERT_SV | ||
`define PRIM_FIFO_ASSERT_SV | ||
|
||
// Use PRIM_COUNT_ERROR_TRIGGER_ALERT appropriately to check that the three prim_counts generated by | ||
// a prim_fifo_sync with depth at least two do indeed generate an alert if they detect an error. | ||
// | ||
// - NAME_ is used as the root of the names of the generated assertions. | ||
// - HIER_ is a hierarchical path to the prim_fifo_sync in question. | ||
// - ALERT_ is the name of the alert that should be generated. | ||
// - GATE_ is a signal that, if true, will cause an error to be ignored. | ||
// - MAX_CYCLES_ is the number of cycles allowed until the alert must be generated. | ||
`define ASSERT_PRIM_FIFO_SYNC_ERROR_TRIGGERS_ALERT(NAME_, HIER_, ALERT_, GATE_ = 0, MAX_CYCLES_ = `_SEC_CM_ALERT_MAX_CYC) \ | ||
`ASSERT_PRIM_COUNT_ERROR_TRIGGER_ALERT(``NAME_``WptrCheck_A, \ | ||
HIER_.gen_normal_fifo.u_fifo_cnt.gen_secure_ptrs.u_wptr, \ | ||
ALERT_, \ | ||
GATE_, \ | ||
MAX_CYCLES_) \ | ||
`ASSERT_PRIM_COUNT_ERROR_TRIGGER_ALERT(``NAME_``RptrCheck_A, \ | ||
HIER_.gen_normal_fifo.u_fifo_cnt.gen_secure_ptrs.u_rptr, \ | ||
ALERT_, \ | ||
GATE_, \ | ||
MAX_CYCLES_) | ||
|
||
// An analagous assertion to PRIM_COUNT_ERROR_TRIGGER_ALERT, but specialised for the case where the | ||
// fifo has depth 1, which means there aren't actually three prim_count instances but instead there | ||
// is just a single error signal. | ||
// | ||
// - NAME_ is used as a root for the name of the generated assertion. | ||
// - HIER_ is a hierarchical path to the prim_fifo_sync in question. | ||
// - ALERT_ is the name of the alert that should be generated. | ||
// - GATE_ is a signal that, if true, will cause an error to be ignored. | ||
// - MAX_CYCLES_ is the number of cycles allowed until the alert must be generated. | ||
`define ASSERT_PRIM_FIFO_SYNC_ERROR_TRIGGERS_ALERT1(NAME_, HIER_, ALERT_, GATE_ = 0, MAX_CYCLES_ = `_SEC_CM_ALERT_MAX_CYC) \ | ||
`ASSERT_ERROR_TRIGGER_ALERT(``NAME_``FullCheck_A, \ | ||
HIER_, \ | ||
ALERT_, \ | ||
GATE_, \ | ||
MAX_CYCLES_, \ | ||
err_o) | ||
|
||
`endif // PRIM_FIFO_ASSERT_SV |
Oops, something went wrong.