[kmac] Expose multi-array app intf to top

This commit exposes app intf array to the top-level.

Signed-off-by: Eunchan Kim <eunchan@opentitan.org>
diff --git a/hw/ip/kmac/data/kmac.hjson b/hw/ip/kmac/data/kmac.hjson
index 00eaebe..b7ffe83 100644
--- a/hw/ip/kmac/data/kmac.hjson
+++ b/hw/ip/kmac/data/kmac.hjson
@@ -73,6 +73,7 @@
       name:    "app"
       act:     "rsp"
       package: "kmac_pkg"
+      width:   "3"
     }
     { struct:  "edn"
       type:    "req_rsp"
diff --git a/hw/ip/kmac/dv/tb.sv b/hw/ip/kmac/dv/tb.sv
index 78d075d..8716a4a 100644
--- a/hw/ip/kmac/dv/tb.sv
+++ b/hw/ip/kmac/dv/tb.sv
@@ -41,6 +41,16 @@
   `DV_EDN_IF_CONNECT
 
   // dut
+  // TODO: Make TB to support arb array of application interface
+  kmac_pkg::app_req_t [kmac_pkg::NumAppIntf-1:0] app_req;
+  kmac_pkg::app_rsp_t [kmac_pkg::NumAppIntf-1:0] app_rsp;
+
+  assign app_req[0] = keymgr_kmac_if.kmac_data_req;
+  assign app_req[1] = kmac_pkg::APP_REQ_DEFAULT;
+  assign app_req[2] = kmac_pkg::APP_REQ_DEFAULT;
+
+  assign keymgr_kmac_if.kmac_data_rsp = app_rsp[0];
+
   kmac #(.EnMasking(`EN_MASKING), .ReuseShare(`REUSE_SHARE)) dut (
     .clk_i              (clk                          ),
     .rst_ni             (rst_n                        ),
@@ -56,8 +66,8 @@
     //
     // TODO: this is set to 0 for the time being to get the csr tests passing.
     //       this will eventually be hooked up to the kmac<->keymgr agent.
-    .app_i       (keymgr_kmac_if.kmac_data_req ),
-    .app_o       (keymgr_kmac_if.kmac_data_rsp ),
+    .app_i       (app_req ),
+    .app_o       (app_rsp ),
 
     // Interrupts
     .intr_kmac_done_o   (interrupts[KmacDone]         ),
diff --git a/hw/ip/kmac/rtl/kmac.sv b/hw/ip/kmac/rtl/kmac.sv
index e091139..d0d14a3 100644
--- a/hw/ip/kmac/rtl/kmac.sv
+++ b/hw/ip/kmac/rtl/kmac.sv
@@ -32,8 +32,8 @@
   input keymgr_pkg::hw_key_req_t keymgr_key_i,
 
   // KeyMgr KDF data path
-  input  app_req_t app_i,
-  output app_rsp_t app_o,
+  input  app_req_t [NumAppIntf-1:0] app_i,
+  output app_rsp_t [NumAppIntf-1:0] app_o,
 
   // EDN interface
   output edn_pkg::edn_req_t entropy_o,
@@ -680,15 +680,6 @@
   logic unused_tlram_addr;
   assign unused_tlram_addr = &{1'b0, tlram_addr};
 
-  // Temporary app intf connect
-  app_req_t app_req_temp [NumAppIntf];
-  app_rsp_t app_rsp_temp [NumAppIntf];
-
-  assign app_req_temp[0] = app_i;
-  assign app_req_temp[1] = APP_REQ_DEFAULT;
-  assign app_req_temp[2] = APP_REQ_DEFAULT;
-
-  assign app_o = app_rsp_temp[0];
   // Application interface Mux/Demux
   kmac_app #(
     .EnMasking(EnMasking)
@@ -715,8 +706,8 @@
     .keymgr_key_i,
 
     // Application data in / digest out interface
-    .app_i (app_req_temp),
-    .app_o (app_rsp_temp),
+    .app_i,
+    .app_o,
 
     // Secret Key output to KMAC Core
     .key_data_o (key_data),
diff --git a/hw/ip/kmac/rtl/kmac_app.sv b/hw/ip/kmac/rtl/kmac_app.sv
index 7f06d46..2ed855e 100644
--- a/hw/ip/kmac/rtl/kmac_app.sv
+++ b/hw/ip/kmac/rtl/kmac_app.sv
@@ -38,8 +38,8 @@
   input keymgr_pkg::hw_key_req_t keymgr_key_i,
 
   // Application Message in/ Digest out interface + control signals
-  input  app_req_t app_i [NumAppIntf],
-  output app_rsp_t app_o [NumAppIntf],
+  input  app_req_t [NumAppIntf-1:0] app_i,
+  output app_rsp_t [NumAppIntf-1:0] app_o,
 
   // to KMAC Core: Secret key
   output [MaxKeyLen-1:0] key_data_o [Share],
diff --git a/hw/ip/kmac/rtl/kmac_pkg.sv b/hw/ip/kmac/rtl/kmac_pkg.sv
index ef27260..deb9576 100644
--- a/hw/ip/kmac/rtl/kmac_pkg.sv
+++ b/hw/ip/kmac/rtl/kmac_pkg.sv
@@ -99,6 +99,8 @@
   // 0: KeyMgr
   // 1: OTP_CTRL
   // 2: ROM_CTRL
+  // Make sure to change `width` of app inter-module signal definition
+  // if this value is changed.
   parameter int unsigned NumAppIntf = 3;
 
   // Application Algorithm
diff --git a/hw/top_earlgrey/data/autogen/top_earlgrey.gen.hjson b/hw/top_earlgrey/data/autogen/top_earlgrey.gen.hjson
index 6e8f865..68e981f 100644
--- a/hw/top_earlgrey/data/autogen/top_earlgrey.gen.hjson
+++ b/hw/top_earlgrey/data/autogen/top_earlgrey.gen.hjson
@@ -3882,10 +3882,11 @@
           package: kmac_pkg
           type: req_rsp
           act: rsp
-          width: 1
+          width: 3
           inst_name: kmac
           default: ""
-          end_idx: -1
+          end_idx: 1
+          top_type: partial-one-to-N
           top_signame: kmac_app
           index: -1
         }
@@ -4143,7 +4144,7 @@
           inst_name: keymgr
           default: ""
           top_signame: kmac_app
-          index: -1
+          index: 0
         }
         {
           name: otp_key
@@ -11397,10 +11398,11 @@
         package: kmac_pkg
         type: req_rsp
         act: rsp
-        width: 1
+        width: 3
         inst_name: kmac
         default: ""
-        end_idx: -1
+        end_idx: 1
+        top_type: partial-one-to-N
         top_signame: kmac_app
         index: -1
       }
@@ -11497,7 +11499,7 @@
         inst_name: keymgr
         default: ""
         top_signame: kmac_app
-        index: -1
+        index: 0
       }
       {
         name: otp_key
@@ -14059,9 +14061,9 @@
         package: kmac_pkg
         struct: app_req
         signame: kmac_app_req
-        width: 1
+        width: 3
         type: req_rsp
-        end_idx: -1
+        end_idx: 1
         act: rsp
         suffix: req
         default: ""
@@ -14070,9 +14072,9 @@
         package: kmac_pkg
         struct: app_rsp
         signame: kmac_app_rsp
-        width: 1
+        width: 3
         type: req_rsp
-        end_idx: -1
+        end_idx: 1
         act: rsp
         suffix: rsp
         default: ""
diff --git a/hw/top_earlgrey/rtl/autogen/top_earlgrey.sv b/hw/top_earlgrey/rtl/autogen/top_earlgrey.sv
index 6e0e087..027753e 100644
--- a/hw/top_earlgrey/rtl/autogen/top_earlgrey.sv
+++ b/hw/top_earlgrey/rtl/autogen/top_earlgrey.sv
@@ -471,8 +471,8 @@
   edn_pkg::edn_rsp_t [6:0] edn1_edn_rsp;
   otp_ctrl_pkg::otp_keymgr_key_t       otp_ctrl_otp_keymgr_key;
   keymgr_pkg::hw_key_req_t       keymgr_kmac_key;
-  kmac_pkg::app_req_t       kmac_app_req;
-  kmac_pkg::app_rsp_t       kmac_app_rsp;
+  kmac_pkg::app_req_t [2:0] kmac_app_req;
+  kmac_pkg::app_rsp_t [2:0] kmac_app_rsp;
   logic [3:0] clkmgr_aon_idle;
   jtag_pkg::jtag_req_t       pinmux_aon_lc_jtag_req;
   jtag_pkg::jtag_rsp_t       pinmux_aon_lc_jtag_rsp;
@@ -615,6 +615,8 @@
   edn_pkg::edn_rsp_t unused_edn1_edn_rsp4;
   edn_pkg::edn_rsp_t unused_edn1_edn_rsp5;
   edn_pkg::edn_rsp_t unused_edn1_edn_rsp6;
+  kmac_pkg::app_rsp_t unused_kmac_app_rsp1;
+  kmac_pkg::app_rsp_t unused_kmac_app_rsp2;
 
   // assign partial inter-module tie-off
   assign unused_edn1_edn_rsp1 = edn1_edn_rsp[1];
@@ -623,12 +625,16 @@
   assign unused_edn1_edn_rsp4 = edn1_edn_rsp[4];
   assign unused_edn1_edn_rsp5 = edn1_edn_rsp[5];
   assign unused_edn1_edn_rsp6 = edn1_edn_rsp[6];
+  assign unused_kmac_app_rsp1 = kmac_app_rsp[1];
+  assign unused_kmac_app_rsp2 = kmac_app_rsp[2];
   assign edn1_edn_req[1] = '0;
   assign edn1_edn_req[2] = '0;
   assign edn1_edn_req[3] = '0;
   assign edn1_edn_req[4] = '0;
   assign edn1_edn_req[5] = '0;
   assign edn1_edn_req[6] = '0;
+  assign kmac_app_req[1] = kmac_pkg::APP_REQ_DEFAULT;
+  assign kmac_app_req[2] = kmac_pkg::APP_REQ_DEFAULT;
 
 
   // Unused reset signals
@@ -1969,8 +1975,8 @@
       .aes_key_o(),
       .hmac_key_o(),
       .kmac_key_o(keymgr_kmac_key),
-      .kmac_data_o(kmac_app_req),
-      .kmac_data_i(kmac_app_rsp),
+      .kmac_data_o(kmac_app_req[0]),
+      .kmac_data_i(kmac_app_rsp[0]),
       .otp_key_i(otp_ctrl_otp_keymgr_key),
       .otp_hw_cfg_i(otp_ctrl_otp_hw_cfg),
       .flash_i(flash_ctrl_keymgr),
diff --git a/util/topgen/intermodule.py b/util/topgen/intermodule.py
index f36806b..56bb01f 100644
--- a/util/topgen/intermodule.py
+++ b/util/topgen/intermodule.py
@@ -880,7 +880,9 @@
             if obj.get("package") == "tlul_pkg" and obj["struct"] == "tl":
                 return "{package}::{struct}_H2D_DEFAULT".format(
                     package=obj["package"], struct=obj["struct"].upper())
-            return "{package}::{struct}_REQ_DEFAULT".format(
+            # default is used for dangling ports in definitions.
+            # the struct name already has `_req` suffix
+            return "{package}::{struct}_DEFAULT".format(
                 package=obj.get("package", ''), struct=obj["struct"].upper())
         if obj["act"] == "rcv" and suffix == "" and obj["struct"] == "logic":
             # custom default has been specified