[dv/otp_ctrl] reconnecting dut signals to otp_ctrl_if instead of constants

Signed-off-by: Dror Kabely <dror.kabely@opentitan.org>
diff --git a/hw/ip/otp_ctrl/dv/env/otp_ctrl_ast_inputs_cfg.sv b/hw/ip/otp_ctrl/dv/env/otp_ctrl_ast_inputs_cfg.sv
new file mode 100644
index 0000000..d403d8c
--- /dev/null
+++ b/hw/ip/otp_ctrl/dv/env/otp_ctrl_ast_inputs_cfg.sv
@@ -0,0 +1,35 @@
+// Copyright lowRISC contributors.
+// Licensed under the Apache License, Version 2.0, see LICENSE for details.
+// SPDX-License-Identifier: Apache-2.0
+//
+//
+// Configuration values for DUT input signals
+//
+//
+// This class randomizes values for DUT signal inputs
+// and sets constraints on these values.
+//
+// This class will be instantiated inside otp_ctrl_env_cfg object, and will connect
+// to it's otp_ctrl_vif signals and drive them each reset event
+//
+// The constraints can be hardened and softened as needed in
+// closed-source environment.
+// In order to override these constraints, please inherit this class
+// and set a type override in the closed source environment
+
+class otp_ctrl_ast_inputs_cfg extends uvm_object;
+  `uvm_object_utils(otp_ctrl_ast_inputs_cfg);
+  `uvm_object_new
+
+  //  Group: Variables
+  rand otp_ast_rsp_t        otp_ast_pwr_seq_h;
+  rand logic [otp_ctrl_pkg::OtpTestCtrlWidth-1:0] otp_test_ctrl;
+  rand lc_ctrl_pkg::lc_tx_t scanmode;
+  rand logic                scan_en, scan_rst_n;
+
+  //  Group: Constraints
+  constraint dut_values_c {
+    otp_test_ctrl            == 8'h0;
+  }
+
+endclass: otp_ctrl_ast_inputs_cfg
diff --git a/hw/ip/otp_ctrl/dv/env/otp_ctrl_env.core b/hw/ip/otp_ctrl/dv/env/otp_ctrl_env.core
index de31175..72b3fdd 100644
--- a/hw/ip/otp_ctrl/dv/env/otp_ctrl_env.core
+++ b/hw/ip/otp_ctrl/dv/env/otp_ctrl_env.core
@@ -15,6 +15,7 @@
     files:
       - otp_ctrl_env_pkg.sv
       - otp_ctrl_if.sv
+      - otp_ctrl_ast_inputs_cfg.sv: {is_include_file: true}
       - otp_ctrl_env_cfg.sv: {is_include_file: true}
       - otp_ctrl_env_cov.sv: {is_include_file: true}
       - otp_ctrl_virtual_sequencer.sv: {is_include_file: true}
diff --git a/hw/ip/otp_ctrl/dv/env/otp_ctrl_env.sv b/hw/ip/otp_ctrl/dv/env/otp_ctrl_env.sv
index 922b176..5dba354 100644
--- a/hw/ip/otp_ctrl/dv/env/otp_ctrl_env.sv
+++ b/hw/ip/otp_ctrl/dv/env/otp_ctrl_env.sv
@@ -18,6 +18,7 @@
 
   `uvm_component_new
 
+
   push_pull_agent#(.DeviceDataWidth(SRAM_DATA_SIZE))  m_sram_pull_agent[NumSramKeyReqSlots];
   push_pull_agent#(.DeviceDataWidth(OTBN_DATA_SIZE))  m_otbn_pull_agent;
   push_pull_agent#(.DeviceDataWidth(FLASH_DATA_SIZE)) m_flash_addr_pull_agent;
@@ -67,6 +68,7 @@
     if (!uvm_config_db#(otp_ctrl_vif)::get(this, "", "otp_ctrl_vif", cfg.otp_ctrl_vif)) begin
       `uvm_fatal(`gfn, "failed to get otp_ctrl_vif from uvm_config_db")
     end
+
   endfunction
 
   function void connect_phase(uvm_phase phase);
@@ -93,6 +95,9 @@
           scoreboard.flash_data_fifo.analysis_export);
       m_lc_prog_pull_agent.monitor.analysis_port.connect(scoreboard.lc_prog_fifo.analysis_export);
     end
+
+    // connect the DUT cfg instance to the handle in the otp_ctrl_vif
+    this.cfg.otp_ctrl_vif.dut_cfg = this.cfg.dut_cfg;
   endfunction
 
 endclass
diff --git a/hw/ip/otp_ctrl/dv/env/otp_ctrl_env_cfg.sv b/hw/ip/otp_ctrl/dv/env/otp_ctrl_env_cfg.sv
index 5d304e8..fe99008 100644
--- a/hw/ip/otp_ctrl/dv/env/otp_ctrl_env_cfg.sv
+++ b/hw/ip/otp_ctrl/dv/env/otp_ctrl_env_cfg.sv
@@ -18,7 +18,6 @@
 
   // ext interfaces
   otp_ctrl_vif otp_ctrl_vif;
-
   bit backdoor_clear_mem;
 
   // This value is updated in sequence when backdoor inject ECC error
@@ -27,6 +26,9 @@
   // Check ECC errors
   otp_ecc_err_e ecc_chk_err [NumPart] = '{default:OtpNoEccErr};
 
+  // values for otp_ctrl_if signals connected to DUT
+  rand otp_ctrl_ast_inputs_cfg dut_cfg;
+
   `uvm_object_utils_begin(otp_ctrl_env_cfg)
   `uvm_object_utils_end
 
@@ -74,6 +76,9 @@
 
     // only support 1 outstanding TL items in tlul_adapter
     m_tl_agent_cfg.max_outstanding_req = 1;
+
+    // create the inputs cfg instance
+    dut_cfg = otp_ctrl_ast_inputs_cfg::type_id::create("dut_cfg");
   endfunction
 
 endclass
diff --git a/hw/ip/otp_ctrl/dv/env/otp_ctrl_env_pkg.sv b/hw/ip/otp_ctrl/dv/env/otp_ctrl_env_pkg.sv
index b3906f7..2bae6b6 100644
--- a/hw/ip/otp_ctrl/dv/env/otp_ctrl_env_pkg.sv
+++ b/hw/ip/otp_ctrl/dv/env/otp_ctrl_env_pkg.sv
@@ -238,6 +238,7 @@
   endfunction
 
   // package sources
+  `include "otp_ctrl_ast_inputs_cfg.sv"
   `include "otp_ctrl_env_cfg.sv"
   `include "otp_ctrl_env_cov.sv"
   `include "otp_ctrl_virtual_sequencer.sv"
diff --git a/hw/ip/otp_ctrl/dv/env/otp_ctrl_if.sv b/hw/ip/otp_ctrl/dv/env/otp_ctrl_if.sv
index 0ce939a..5ee1232 100644
--- a/hw/ip/otp_ctrl/dv/env/otp_ctrl_if.sv
+++ b/hw/ip/otp_ctrl/dv/env/otp_ctrl_if.sv
@@ -63,6 +63,12 @@
   // Internal veriable to track which sw partitions have ECC reg error.
   bit [1:0] force_sw_parts_ecc_reg;
 
+  // DUT configuration object
+  otp_ctrl_ast_inputs_cfg dut_cfg;
+
+  // for DV macros ID
+  string msg_id = "otp_ctrl_if";
+
   // Lc_err could trigger during LC program, so check intr and status after lc_req is finished.
   // Lc_err takes one clock cycle to propogate to intr signal. So avoid intr check if it happens
   // during the transition.
@@ -94,12 +100,16 @@
     lc_dft_en_i                = lc_ctrl_pkg::Off;    // drive it in specific task
     lc_escalate_en_i           = lc_ctrl_pkg::Off;    // drive it in specific task
     pwr_otp_init_i             = 0;
-    // Unused signals in open sourced OTP memory
-    otp_ast_pwr_seq_h_i        = $urandom();
-    scan_en_i                  = $urandom();
-    scan_rst_ni                = $urandom();
-    scanmode_i                 = $urandom();
-    otp_test_ctrl_i            = 0;
+
+    // `DV_CHECK_RANDOMIZE_FATAL won't work inside an interface as an interface doesn't
+    // have a `get_full_name` method
+    `DV_CHECK_RANDOMIZE_FATAL(dut_cfg, ,msg_id)
+    //Unused signals in open sourced OTP memory
+    otp_ast_pwr_seq_h_i        = dut_cfg.otp_ast_pwr_seq_h;
+    scan_en_i                  = dut_cfg.scan_en;
+    scan_rst_ni                = dut_cfg.scan_rst_n;
+    scanmode_i                 = dut_cfg.scanmode;
+    otp_test_ctrl_i            = dut_cfg.otp_test_ctrl;
   endtask
 
   task automatic drive_pwr_otp_init(logic val);
diff --git a/hw/ip/otp_ctrl/dv/tb.sv b/hw/ip/otp_ctrl/dv/tb.sv
index d06519d..34fc3e2 100644
--- a/hw/ip/otp_ctrl/dv/tb.sv
+++ b/hw/ip/otp_ctrl/dv/tb.sv
@@ -101,7 +101,7 @@
     .alert_tx_o                 (alert_tx   ),
     // ast
     .otp_ast_pwr_seq_o          (ast_req),
-    .otp_ast_pwr_seq_h_i        (ast_req),
+    .otp_ast_pwr_seq_h_i        (otp_ctrl_if.otp_ast_pwr_seq_h_i),
     .otp_alert_o                (otp_ctrl_if.otp_alert_o),
     // pwrmgr
     .pwr_otp_i                  (otp_ctrl_if.pwr_otp_init_i),
@@ -133,7 +133,7 @@
     //scan
     .scan_en_i                  (otp_ctrl_if.scan_en_i),
     .scan_rst_ni                (otp_ctrl_if.scan_rst_ni),
-    .scanmode_i                 (lc_ctrl_pkg::Off),
+    .scanmode_i                 (otp_ctrl_if.scanmode_i),
 
     // Test-related GPIO output
     .cio_test_o                 (),