[dv/lc_tx_t] Simplify mubi4 and lc_tx_t randomization

Signed-off-by: Guillermo Maturana <maturana@google.com>
diff --git a/hw/ip/clkmgr/dv/env/seq_lib/clkmgr_base_vseq.sv b/hw/ip/clkmgr/dv/env/seq_lib/clkmgr_base_vseq.sv
index 559e9c9..9692a2c 100644
--- a/hw/ip/clkmgr/dv/env/seq_lib/clkmgr_base_vseq.sv
+++ b/hw/ip/clkmgr/dv/env/seq_lib/clkmgr_base_vseq.sv
@@ -8,8 +8,14 @@
   .COV_T              (clkmgr_env_cov),
   .VIRTUAL_SEQUENCER_T(clkmgr_virtual_sequencer)
 );
+  import prim_mubi_pkg::mubi4_t;
+  import prim_mubi_pkg::MuBi4False;
+  import prim_mubi_pkg::MuBi4True;
+
   `uvm_object_utils(clkmgr_base_vseq)
 
+  `uvm_object_new
+
   // The extra cycles to wait after reset before starting any test, required so some CSRs (notably
   // hints_status) are properly set when inputs go through synchronizers.
   localparam int POST_APPLY_RESET_CYCLES = 10;
@@ -18,91 +24,35 @@
   // synchronizers.
   localparam int IO_DIV4_SYNC_CYCLES = 8;
 
-  // Use this to hold a lc_tx_t.
-  typedef bit [$bits(lc_tx_t)-1:0] lc_tx_t_as_vec;
-
-  typedef enum {
-    LcTxTSelOn,
-    LcTxTSelOff,
-    LcTxTSelOther
-  } lc_tx_t_sel_e;
-
-  // This simplifies the constraint blocks.
-  // This function is used for 2 enum mubi4_t and lc_tx_t. Use lc_tx_t_as_vec, so that we can skip
-  // type casting when using this function
-  function lc_tx_t_as_vec get_lc_tx_t_from_sel(lc_tx_t_sel_e sel, lc_tx_t_as_vec other);
-    case (sel)
-      LcTxTSelOn: return On;
-      LcTxTSelOff: return Off;
-      LcTxTSelOther: return other;
-    endcase
-  endfunction
-
   rand bit                 io_ip_clk_en;
   rand bit                 main_ip_clk_en;
   rand bit                 usb_ip_clk_en;
 
   rand bit [NUM_TRANS-1:0] idle;
 
-  // scanmode is set according to sel_scanmode, which is randomized with weights.
-  prim_mubi_pkg::mubi4_t   scanmode;
-  rand lc_tx_t_as_vec      scanmode_other;
-  rand lc_tx_t_sel_e       sel_scanmode;
-  int                      scanmode_on_weight = 8;
+  mubi4_t                  scanmode;
+  int                      scanmode_on_weight         = 8;
 
-  constraint scanmode_c {
-    sel_scanmode dist {
-      LcTxTSelOn    := scanmode_on_weight,
-      LcTxTSelOff   := 4,
-      LcTxTSelOther := 4
-    };
-    !(scanmode_other inside {prim_mubi_pkg::MuBi4True, prim_mubi_pkg::MuBi4False});
-  }
-
-  // extclk_ctrl_sel is set according to sel_extclk_ctrl_sel, which is randomized with weights.
-  lc_tx_t             extclk_ctrl_sel;
-  rand lc_tx_t_as_vec extclk_ctrl_sel_other;
-  rand lc_tx_t_sel_e  sel_extclk_ctrl_sel;
-
-  // TODO, consider to use macro DV_MUBI4_DIST
-  constraint extclk_ctrl_sel_c {
-    sel_extclk_ctrl_sel dist {
-      LcTxTSelOn    := 6,
-      LcTxTSelOff   := 2,
-      LcTxTSelOther := 2
-    };
-    !(extclk_ctrl_sel_other inside {On, Off});
-  }
-
-  // extclk_ctrl_low_speed_sel is set according to sel_extclk_ctrl_low_speed_sel, which is randomized with weights.
-  lc_tx_t             extclk_ctrl_low_speed_sel;
-  rand lc_tx_t_as_vec extclk_ctrl_low_speed_sel_other;
-  rand lc_tx_t_sel_e  sel_extclk_ctrl_low_speed_sel;
-
-  constraint extclk_ctrl_low_speed_sel_c {
-    sel_extclk_ctrl_low_speed_sel dist {
-      LcTxTSelOn    := 6,
-      LcTxTSelOff   := 2,
-      LcTxTSelOther := 2
-    };
-    !(extclk_ctrl_low_speed_sel_other inside {On, Off});
-  }
-
-  `uvm_object_new
-
-  function void post_randomize();
-    super.post_randomize();
-    scanmode = get_lc_tx_t_from_sel(sel_scanmode, scanmode_other);
-    extclk_ctrl_sel = get_lc_tx_t_from_sel(sel_extclk_ctrl_sel, extclk_ctrl_sel_other);
-    extclk_ctrl_low_speed_sel = get_lc_tx_t_from_sel(
-        sel_extclk_ctrl_low_speed_sel, extclk_ctrl_low_speed_sel_other
-    );
-  endfunction
+  lc_tx_t                  extclk_ctrl_low_speed_sel;
+  lc_tx_t                  extclk_ctrl_sel;
 
   virtual function void set_scanmode_on_low_weight();
     scanmode_on_weight = 2;
   endfunction
 
+  function void post_randomize();
+    extclk_ctrl_low_speed_sel = get_rand_lc_tx_val(6, 2, 2);
+    extclk_ctrl_sel = get_rand_lc_tx_val(4, 2, 2);
+    scanmode = get_rand_mubi4_val(scanmode_on_weight, 4, 4);
+    `uvm_info(`gfn, $sformatf(
+              "randomize gives extclk_ctrl_sel=0x%x, extclk_ctrl_low_speed_sel=0x%x, scanmode=0x%x",
+              extclk_ctrl_sel,
+              extclk_ctrl_low_speed_sel,
+              scanmode
+              ), UVM_MEDIUM)
+    super.post_randomize();
+  endfunction
+
   task initialize_on_start();
     `uvm_info(`gfn, "In clkmgr_if initialize_on_start", UVM_MEDIUM)
     idle = '1;
diff --git a/hw/ip/clkmgr/dv/env/seq_lib/clkmgr_clk_status_vseq.sv b/hw/ip/clkmgr/dv/env/seq_lib/clkmgr_clk_status_vseq.sv
index e3b41d5..b0a98c8 100644
--- a/hw/ip/clkmgr/dv/env/seq_lib/clkmgr_clk_status_vseq.sv
+++ b/hw/ip/clkmgr/dv/env/seq_lib/clkmgr_clk_status_vseq.sv
@@ -14,7 +14,7 @@
   `uvm_object_new
 
   // And disable scanmode since it is not interesting.
-  constraint scanmode_off_c {sel_scanmode == LcTxTSelOff;}
+  constraint scanmode_c {scanmode == lc_ctrl_pkg::Off;}
 
   task body();
     update_csrs_with_reset_values();
diff --git a/hw/ip/clkmgr/dv/env/seq_lib/clkmgr_extclk_vseq.sv b/hw/ip/clkmgr/dv/env/seq_lib/clkmgr_extclk_vseq.sv
index 6153db7..e7978a9 100644
--- a/hw/ip/clkmgr/dv/env/seq_lib/clkmgr_extclk_vseq.sv
+++ b/hw/ip/clkmgr/dv/env/seq_lib/clkmgr_extclk_vseq.sv
@@ -12,34 +12,6 @@
   // When extclk_ctrl_regwen is clear it is not possible to select external clocks.
   // This is tested in regular csr_rw, so here this register is simply set to 1.
 
-  // lc_debug_en is set according to sel_lc_debug_en, which is randomized with weights.
-  lc_tx_t            lc_debug_en;
-  rand lc_tx_t       lc_debug_en_other;
-  rand lc_tx_t_sel_e sel_lc_debug_en;
-
-  constraint lc_debug_en_c {
-    sel_lc_debug_en dist {
-      LcTxTSelOn    := 8,
-      LcTxTSelOff   := 2,
-      LcTxTSelOther := 2
-    };
-    !(lc_debug_en_other inside {On, Off});
-  }
-
-  // lc_clk_byp_req is set according to sel_lc_clk_byp_req, which is randomized with weights.
-  lc_tx_t            lc_clk_byp_req;
-  rand lc_tx_t       lc_clk_byp_req_other;
-  rand lc_tx_t_sel_e sel_lc_clk_byp_req;
-
-  constraint lc_clk_byp_req_c {
-    sel_lc_clk_byp_req dist {
-      LcTxTSelOn    := 8,
-      LcTxTSelOff   := 2,
-      LcTxTSelOther := 2
-    };
-    !(lc_clk_byp_req_other inside {On, Off});
-  }
-
   // The extclk cannot be manipulated in low power mode.
   constraint io_ip_clk_en_on_c {io_ip_clk_en == 1'b1;}
   constraint main_ip_clk_en_on_c {main_ip_clk_en == 1'b1;}
@@ -64,10 +36,16 @@
     cycles_before_next_trans inside {[15 : 25]};
   }
 
+  lc_tx_t lc_clk_byp_req;
+  lc_tx_t lc_debug_en;
+
   function void post_randomize();
+    lc_clk_byp_req = get_rand_lc_tx_val(8, 2, 2);
+    lc_debug_en = get_rand_lc_tx_val(8, 2, 2);
+    `uvm_info(`gfn, $sformatf(
+              "randomize gives lc_clk_byp_req=0x%x, lc_debug_en=0x%x",
+              lc_clk_byp_req, lc_debug_en), UVM_MEDIUM)
     super.post_randomize();
-    lc_debug_en = get_lc_tx_t_from_sel(sel_lc_debug_en, lc_debug_en_other);
-    lc_clk_byp_req = get_lc_tx_t_from_sel(sel_lc_clk_byp_req, lc_clk_byp_req_other);
   endfunction
 
   task body();
diff --git a/hw/ip/rstmgr/dv/env/seq_lib/rstmgr_base_vseq.sv b/hw/ip/rstmgr/dv/env/seq_lib/rstmgr_base_vseq.sv
index aeb6a82..e3e6e08 100644
--- a/hw/ip/rstmgr/dv/env/seq_lib/rstmgr_base_vseq.sv
+++ b/hw/ip/rstmgr/dv/env/seq_lib/rstmgr_base_vseq.sv
@@ -8,6 +8,10 @@
   .COV_T              (rstmgr_env_cov),
   .VIRTUAL_SEQUENCER_T(rstmgr_virtual_sequencer)
 );
+  import prim_mubi_pkg::mubi4_t;
+  import prim_mubi_pkg::MuBi4False;
+  import prim_mubi_pkg::MuBi4True;
+
   `uvm_object_utils(rstmgr_base_vseq)
 
   // Set clock frequencies per spec, except the aon is 200kHZ, which is
@@ -29,47 +33,16 @@
   // Some extra cycles from reset going inactive before the CPU's reset goes inactive.
   localparam int CPU_RESET_CLK_CYCLES = 10;
 
-  typedef enum {
-    LcTxTSelOn,
-    LcTxTSelOff,
-    LcTxTSelOther
-  } lc_tx_t_sel_e;
-
-  // This simplifies the constraint blocks.
-  function lc_ctrl_pkg::lc_tx_t get_lc_tx_t_from_sel(lc_tx_t_sel_e sel, lc_ctrl_pkg::lc_tx_t other);
-    case (sel)
-      LcTxTSelOn: return lc_ctrl_pkg::On;
-      LcTxTSelOff: return lc_ctrl_pkg::Off;
-      LcTxTSelOther: return other;
-    endcase
-  endfunction
-
-  rand bit [3:0]            scanmode_other;
-  rand lc_tx_t_sel_e        sel_scanmode;
-  int                       scanmode_on_weight = 8;
-
-  // TODO, consider to use macro DV_MUBI4_DIST
-  constraint scanmode_c {
-    sel_scanmode dist {
-      LcTxTSelOn    := scanmode_on_weight,
-      LcTxTSelOff   := 4,
-      LcTxTSelOther := 4
-    };
-    !(scanmode_other inside {prim_mubi_pkg::MuBi4True, prim_mubi_pkg::MuBi4False});
-  }
-
   rand logic [NumSwResets-1:0] sw_rst_regwen;
   rand logic [NumSwResets-1:0] sw_rst_ctrl_n;
 
-  bit reset_once;
+  bit                          reset_once;
 
-  pwrmgr_pkg::pwr_rst_req_t pwr_i;
+  pwrmgr_pkg::pwr_rst_req_t    pwr_i;
 
-  rand logic scan_rst_ni;
+  rand logic                   scan_rst_ni;
   constraint scan_rst_ni_c {scan_rst_ni == 1;}
 
-  lc_ctrl_pkg::lc_tx_t scanmode;
-
   rand int ndm_reset_cycles;
   constraint ndm_reset_cycles_c {ndm_reset_cycles inside {[4 : 16]};}
 
@@ -77,10 +50,17 @@
   constraint non_ndm_reset_cycles_c {non_ndm_reset_cycles inside {[4 : 16]};}
 
   // various knobs to enable certain routines
-  bit do_rstmgr_init = 1'b1;
+  bit     do_rstmgr_init     = 1'b1;
+
+  mubi4_t scanmode;
+  int     scanmode_on_weight = 8;
 
   `uvm_object_new
 
+  function void post_randomize();
+    scanmode = get_rand_mubi4_val(scanmode_on_weight, 4, 4);
+  endfunction
+
   function void set_pwrmgr_rst_reqs(logic rst_lc_req, logic rst_sys_req);
     cfg.rstmgr_vif.pwr_i.rst_lc_req  = {rstmgr_pkg::PowerDomains{rst_lc_req}};
     cfg.rstmgr_vif.pwr_i.rst_sys_req = {rstmgr_pkg::PowerDomains{rst_sys_req}};
diff --git a/hw/ip/rstmgr/dv/env/seq_lib/rstmgr_smoke_vseq.sv b/hw/ip/rstmgr/dv/env/seq_lib/rstmgr_smoke_vseq.sv
index f185135..32c2cea 100644
--- a/hw/ip/rstmgr/dv/env/seq_lib/rstmgr_smoke_vseq.sv
+++ b/hw/ip/rstmgr/dv/env/seq_lib/rstmgr_smoke_vseq.sv
@@ -42,8 +42,7 @@
 
     // Send HwReq.
     // Enable alert_info and cpu_info capture.
-    `DV_CHECK_MEMBER_RANDOMIZE_FATAL(alert_dump);
-    `DV_CHECK_MEMBER_RANDOMIZE_FATAL(cpu_dump);
+    `DV_CHECK_RANDOMIZE_FATAL(this)
     set_alert_and_cpu_info_for_capture(alert_dump, cpu_dump);
 
     send_reset(pwrmgr_pkg::HwReq, rstreqs);
@@ -53,9 +52,8 @@
 
     // Clear reset_info register.
     csr_wr(.ptr(ral.reset_info), .value('1));
+    `DV_CHECK_RANDOMIZE_FATAL(this)
 
-    `DV_CHECK_MEMBER_RANDOMIZE_FATAL(alert_dump);
-    `DV_CHECK_MEMBER_RANDOMIZE_FATAL(cpu_dump);
     set_alert_and_cpu_info_for_capture(alert_dump, cpu_dump);
 
     // Send debug reset.