[top] Various top level fixes corresponding to bus updates

- Add ast bus i/o to all top level files
- Update top_earlgrey for ast bus export
- Update xbar_peri to add ast bus stub
- Update for tb__xbar_connect is incomplete.  stub modules are skipped for now.

Signed-off-by: Timothy Chen <timothytim@google.com>

[dv] define support for external devices

- Add connection for external device by directly driving ports

Signed-off-by: Timothy Chen <timothytim@google.com>

[dv] fix typo

Signed-off-by: Timothy Chen <timothytim@google.com>
diff --git a/hw/top_earlgrey/data/tb__xbar_connect.sv.tpl b/hw/top_earlgrey/data/tb__xbar_connect.sv.tpl
index ac635e1..896b14b 100644
--- a/hw/top_earlgrey/data/tb__xbar_connect.sv.tpl
+++ b/hw/top_earlgrey/data/tb__xbar_connect.sv.tpl
@@ -41,6 +41,12 @@
      force dut.top_earlgrey.u_``inst_name``.``sig_name``_o = ``tl_name``_tl_if.d2h; \
      uvm_config_db#(virtual tl_if)::set(null, $sformatf("*%0s*", `"tl_name`"), "vif", \
                                         ``tl_name``_tl_if);
+
+`define DRIVE_TL_EXT_DEVICE_IF(tl_name, port_name) \
+     force ``tl_name``_tl_if.h2d = dut.top_earlgrey.``port_name``_req_o; \
+     force dut.top_earlgrey.``port_name``_rsp_i = ``tl_name``_tl_if.d2h; \
+     uvm_config_db#(virtual tl_if)::set(null, $sformatf("*%0s*", `"tl_name`"), "vif", \
+                                        ``tl_name``_tl_if);
 </%text>\
 
 % for c in clk_freq.keys():
@@ -96,6 +102,8 @@
 %>\
     % if node["type"] == "host" and not node["xbar"]:
     `DRIVE_TL_HOST_IF(${node["name"]}, ${inst_name}, ${sig_name})
+    % elif node["type"] == "device" and not node["xbar"] and node["stub"]:
+    `DRIVE_TL_EXT_DEVICE_IF(${node["name"]}, ${inst_name}_${sig_name})
     % elif node["type"] == "device" and not node["xbar"]:
     `DRIVE_TL_DEVICE_IF(${node["name"]}, ${inst_name}, ${sig_name})
     % endif
diff --git a/hw/top_earlgrey/data/top_earlgrey.hjson b/hw/top_earlgrey/data/top_earlgrey.hjson
index d46f822..dbca431 100644
--- a/hw/top_earlgrey/data/top_earlgrey.hjson
+++ b/hw/top_earlgrey/data/top_earlgrey.hjson
@@ -406,6 +406,7 @@
 
         // Xbars
         'main.tl_corei', 'main.tl_cored', 'main.tl_dm_sba', 'main.tl_debug_mem'
+
     ],
 
     // ext is to create port in the top.
@@ -420,6 +421,7 @@
         'sensor_ctrl.ast_status': '',
         'usbdev.usb_ref_val': '',
         'usbdev.usb_ref_pulse': '',
+        'peri.tl_ast_wrapper': 'ast_tl'
     },
   },
 
diff --git a/hw/top_earlgrey/data/xbar_peri.hjson b/hw/top_earlgrey/data/xbar_peri.hjson
index 26e342e..fc67990 100644
--- a/hw/top_earlgrey/data/xbar_peri.hjson
+++ b/hw/top_earlgrey/data/xbar_peri.hjson
@@ -75,9 +75,23 @@
       reset:     "rst_peri_ni",
       pipeline:  "false",
     },
+    { name:      "ast_wrapper",
+      type:      "device",
+      clock:     "clk_peri_i",
+      reset:     "rst_peri_ni",
+      pipeline:  "false",
+      stub:      true,
+      addr_range:
+      [
+        {
+          base_addr: 0x40180000
+          size_byte: 0x1000
+        }
+      ]
+    },
   ],
   connections: {
     main:  ["uart", "gpio", "spi_device", "rv_timer", "usbdev", "pwrmgr", "rstmgr", "clkmgr",
-            "ram_ret", "sensor_ctrl"],
+            "ram_ret", "sensor_ctrl", "ast_wrapper"],
   },
 }
diff --git a/hw/top_earlgrey/rtl/top_earlgrey_asic.sv b/hw/top_earlgrey/rtl/top_earlgrey_asic.sv
index dc596ff..8607d73 100644
--- a/hw/top_earlgrey/rtl/top_earlgrey_asic.sv
+++ b/hw/top_earlgrey/rtl/top_earlgrey_asic.sv
@@ -253,6 +253,8 @@
     .sensor_ctrl_ast_status_i    ( ast_base_status       ),
     .usbdev_usb_ref_val_o        ( usb_ref_pulse         ),
     .usbdev_usb_ref_pulse_o      ( usb_ref_val           ),
+    .ast_tl_req_o                ( base_ast_bus          ),
+    .ast_tl_rsp_i                ( ast_base_bus          ),
 
     // JTAG
     .jtag_tck_i      ( jtag_tck      ),
diff --git a/hw/top_earlgrey/rtl/top_earlgrey_cw305.sv b/hw/top_earlgrey/rtl/top_earlgrey_cw305.sv
index 7d5384e..4eb3b9a 100644
--- a/hw/top_earlgrey/rtl/top_earlgrey_cw305.sv
+++ b/hw/top_earlgrey/rtl/top_earlgrey_cw305.sv
@@ -239,6 +239,8 @@
     .sensor_ctrl_ast_status_i    ( ast_base_status ),
     .usbdev_usb_ref_val_o        (                 ),
     .usbdev_usb_ref_pulse_o      (                 ),
+    .ast_tl_req_o                (                 ),
+    .ast_tl_rsp_i                ('0               ),
 
     // JTAG
     .jtag_tck_i      ( jtag_tck      ),
diff --git a/hw/top_earlgrey/rtl/top_earlgrey_nexysvideo.sv b/hw/top_earlgrey/rtl/top_earlgrey_nexysvideo.sv
index dcb2f52..a881aa7 100644
--- a/hw/top_earlgrey/rtl/top_earlgrey_nexysvideo.sv
+++ b/hw/top_earlgrey/rtl/top_earlgrey_nexysvideo.sv
@@ -240,6 +240,8 @@
     .sensor_ctrl_ast_status_i    ( ast_base_status ),
     .usbdev_usb_ref_val_o        (                 ),
     .usbdev_usb_ref_pulse_o      (                 ),
+    .ast_tl_req_o                (                 ),
+    .ast_tl_rsp_i                ( '0              ),
 
     // JTAG
     .jtag_tck_i      ( jtag_tck      ),
diff --git a/hw/top_earlgrey/rtl/top_earlgrey_verilator.sv b/hw/top_earlgrey/rtl/top_earlgrey_verilator.sv
index 3fd808a..8642694 100644
--- a/hw/top_earlgrey/rtl/top_earlgrey_verilator.sv
+++ b/hw/top_earlgrey/rtl/top_earlgrey_verilator.sv
@@ -107,6 +107,8 @@
     .sensor_ctrl_ast_status_i     (ast_base_status),
     .usbdev_usb_ref_val_o         (),
     .usbdev_usb_ref_pulse_o       (),
+    .ast_tl_req_o                 (),
+    .ast_tl_rsp_i                 ('0),
 
     .jtag_tck_i                 (cio_jtag_tck),
     .jtag_tms_i                 (cio_jtag_tms),