blob: fc78418e4da9543fb4a9de6f1a6563d25f8ad14d [file] [log] [blame]
lowRISC Contributors802543a2019-08-31 12:12:56 +01001// Copyright lowRISC contributors.
2// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3// SPDX-License-Identifier: Apache-2.0
4//
5// xbar_${xbar.name} module generated by `tlgen.py` tool
6// all reset signals should be generated from one reset signal to not make any deadlock
7//
8// Interconnect
Eunchan Kimc7452942019-12-19 17:04:37 -08009<%
10 import tlgen.lib as lib
11%>\
lowRISC Contributors802543a2019-08-31 12:12:56 +010012% for host in xbar.hosts:
13${xbar.repr_tree(host, 0)}
14% endfor
15
16module xbar_${xbar.name} (
Timothy Chen09d859b2019-11-08 14:01:12 -080017% for c in xbar.clocks:
18 input ${c},
19% endfor
20% for r in xbar.resets:
21 input ${r},
lowRISC Contributors802543a2019-08-31 12:12:56 +010022% endfor
23
24 // Host interfaces
25% for node in xbar.hosts:
Rupert Swarbricka5e687f2021-03-01 11:51:41 +000026 input tlul_pkg::tl_h2d_t tl_${node.name.replace('.', '__')}_i,
27 output tlul_pkg::tl_d2h_t tl_${node.name.replace('.', '__')}_o,
lowRISC Contributors802543a2019-08-31 12:12:56 +010028% endfor
29
30 // Device interfaces
31% for node in xbar.devices:
Rupert Swarbricka5e687f2021-03-01 11:51:41 +000032 output tlul_pkg::tl_h2d_t tl_${node.name.replace('.', '__')}_o,
33 input tlul_pkg::tl_d2h_t tl_${node.name.replace('.', '__')}_i,
lowRISC Contributors802543a2019-08-31 12:12:56 +010034% endfor
35
Timothy Chenf4d5e9a2021-11-09 13:41:04 -080036 input prim_mubi_pkg::mubi4_t scanmode_i
lowRISC Contributors802543a2019-08-31 12:12:56 +010037);
38
39 import tlul_pkg::*;
40 import tl_${xbar.name}_pkg::*;
41
Michael Schaffner1ba89b82019-11-03 14:25:54 -080042 // scanmode_i is currently not used, but provisioned for future use
43 // this assignment prevents lint warnings
Timothy Chenf4d5e9a2021-11-09 13:41:04 -080044 logic unused_scanmode;
45 assign unused_scanmode = ^scanmode_i;
Michael Schaffner1ba89b82019-11-03 14:25:54 -080046
lowRISC Contributors802543a2019-08-31 12:12:56 +010047% for block in xbar.nodes:
48 ## Create enum type for Upstream and Downstream ports connection
49 % if block.node_type.name == "ASYNC_FIFO":
50 ## One US, one DS
51 tl_h2d_t tl_${block.name}_us_h2d ;
52 tl_d2h_t tl_${block.name}_us_d2h ;
53 tl_h2d_t tl_${block.name}_ds_h2d ;
54 tl_d2h_t tl_${block.name}_ds_d2h ;
55
56 % elif block.node_type.name == "SOCKET_1N":
57 ## One US, multiple DS
58 tl_h2d_t tl_${block.name}_us_h2d ;
59 tl_d2h_t tl_${block.name}_us_d2h ;
60
61 ##typedef enum int {
62 ## % for port in block.ds:
63 ## % if loop.last:
64 ## % else:
65 ## % endif
66 ## % endfor
67 ##} socket_${block.name}_ds_e;
68
69 tl_h2d_t tl_${block.name}_ds_h2d [${len(block.ds)}];
70 tl_d2h_t tl_${block.name}_ds_d2h [${len(block.ds)}];
71
72 // Create steering signal
73 logic [${len(block.ds).bit_length()-1}:0] dev_sel_${block.name};
74
75 % elif block.node_type.name == "SOCKET_M1":
76 ## Multiple US, one DS
77 ## typedef enum int {
78 ## % for port in block.us:
79 ## % if loop.last:
80 ## % else:
81 ## % endif
82 ## % endfor
83 ## } socket_${block.name}_us_e;
84
85 tl_h2d_t tl_${block.name}_us_h2d [${len(block.us)}];
86 tl_d2h_t tl_${block.name}_us_d2h [${len(block.us)}];
87
88 tl_h2d_t tl_${block.name}_ds_h2d ;
89 tl_d2h_t tl_${block.name}_ds_d2h ;
90
91 % else:
92 ## block is either HOST or DEVICE. Ignore
93 % endif
94% endfor
95
96% for conn in xbar.edges:
97 ## sweep each entry of edges and find each end (us, ds) then connect between
98 ## Connect upstream
99<%
Rupert Swarbricka5e687f2021-03-01 11:51:41 +0000100 ds_name = conn.ds.name.replace('.', '__')
101 us_name = conn.us.name.replace('.', '__')
102
lowRISC Contributors802543a2019-08-31 12:12:56 +0100103 if conn.ds.node_type.name == "ASYNC_FIFO":
Rupert Swarbricka5e687f2021-03-01 11:51:41 +0000104 ds_h2d_name = 'tl_' + ds_name + '_us_h2d'
105 ds_d2h_name = 'tl_' + ds_name + '_us_d2h'
lowRISC Contributors802543a2019-08-31 12:12:56 +0100106 ds_index = -1
107 elif conn.ds.node_type.name == "SOCKET_1N":
Rupert Swarbricka5e687f2021-03-01 11:51:41 +0000108 ds_h2d_name = 'tl_' + ds_name + '_us_h2d'
109 ds_d2h_name = 'tl_' + ds_name + '_us_d2h'
lowRISC Contributors802543a2019-08-31 12:12:56 +0100110 ds_index = -1
111 elif conn.ds.node_type.name == "SOCKET_M1":
Rupert Swarbricka5e687f2021-03-01 11:51:41 +0000112 ds_h2d_name = 'tl_' + ds_name + '_us_h2d'
113 ds_d2h_name = 'tl_' + ds_name + '_us_d2h'
lowRISC Contributors802543a2019-08-31 12:12:56 +0100114 ds_index = conn.ds.us.index(conn)
115 elif conn.ds.node_type.name == "DEVICE":
Rupert Swarbricka5e687f2021-03-01 11:51:41 +0000116 ds_h2d_name = 'tl_' + ds_name + '_o'
117 ds_d2h_name = 'tl_' + ds_name + '_i'
lowRISC Contributors802543a2019-08-31 12:12:56 +0100118 ds_index = -1
119
120 if conn.us.node_type.name == "ASYNC_FIFO":
Rupert Swarbricka5e687f2021-03-01 11:51:41 +0000121 us_h2d_name = 'tl_' + us_name + '_ds_h2d'
122 us_d2h_name = 'tl_' + us_name + '_ds_d2h'
lowRISC Contributors802543a2019-08-31 12:12:56 +0100123 us_index = -1
124 elif conn.us.node_type.name == "SOCKET_1N":
Rupert Swarbricka5e687f2021-03-01 11:51:41 +0000125 us_h2d_name = 'tl_' + us_name + '_ds_h2d'
126 us_d2h_name = 'tl_' + us_name + '_ds_d2h'
lowRISC Contributors802543a2019-08-31 12:12:56 +0100127 us_index = conn.us.ds.index(conn)
128 elif conn.us.node_type.name == "SOCKET_M1":
Rupert Swarbricka5e687f2021-03-01 11:51:41 +0000129 us_h2d_name = 'tl_' + us_name + '_ds_h2d'
130 us_d2h_name = 'tl_' + us_name + '_ds_d2h'
lowRISC Contributors802543a2019-08-31 12:12:56 +0100131 us_index = -1
132 elif conn.us.node_type.name == "HOST":
Rupert Swarbricka5e687f2021-03-01 11:51:41 +0000133 us_h2d_name = 'tl_' + us_name + '_i'
134 us_d2h_name = 'tl_' + us_name + '_o'
lowRISC Contributors802543a2019-08-31 12:12:56 +0100135 us_index = -1
136%>\
137
138% if us_index == -1 and ds_index == -1:
139 assign ${ds_h2d_name} = ${us_h2d_name};
140 assign ${us_d2h_name} = ${ds_d2h_name};
141% elif us_index == -1 and ds_index != -1:
142 assign ${ds_h2d_name}[${ds_index}] = ${us_h2d_name};
143 assign ${us_d2h_name} = ${ds_d2h_name}[${ds_index}];
144% elif us_index != -1 and ds_index == -1:
145 assign ${ds_h2d_name} = ${us_h2d_name}[${us_index}];
146 assign ${us_d2h_name}[${us_index}] = ${ds_d2h_name};
147% else:
148 assign ${ds_h2d_name}[${ds_index}] = ${us_h2d_name}[${us_index}];
149 assign ${us_d2h_name}[${us_index}] = ${ds_d2h_name}[${ds_index}];
150% endif
151% endfor
152
153% for block in xbar.socket_1ns:
154<%
155 addr_sig = "tl_" + block.name + "_us_h2d.a_address"
156 sel_len = len(block.ds).bit_length()
157%>\
158 always_comb begin
159 // default steering to generate error response if address is not within the range
160 dev_sel_${block.name} = ${"%d'd%d" % (sel_len, len(block.ds))};
161% for i in block.ds:
162<%
163 leaf = xbar.get_leaf_from_s1n(block, loop.index);
Rupert Swarbricka5e687f2021-03-01 11:51:41 +0000164 leaf_name = leaf.name.upper().replace('.', '__')
165
166 name_space = "ADDR_SPACE_" + leaf_name;
167 name_mask = "ADDR_MASK_" + leaf_name;
Eunchan Kimc7452942019-12-19 17:04:37 -0800168 prefix = "if (" if loop.first else "end else if ("
lowRISC Contributors802543a2019-08-31 12:12:56 +0100169%>\
Eunchan Kimc7452942019-12-19 17:04:37 -0800170 % if len(leaf.addr_range) == 1:
171 % if lib.is_pow2((leaf.addr_range[0][1]-leaf.addr_range[0][0])+1):
Michael Schaffnerdcb0de12021-03-08 10:58:29 -0800172 ${prefix}(${addr_sig} &
173 ${" " * len(prefix)} ~(${name_mask})) == ${name_space}) begin
Eunchan Kimc7452942019-12-19 17:04:37 -0800174 % else:
Timothy Chen3b812842020-01-09 10:38:02 -0800175 ${prefix}((${addr_sig} <= (${name_mask} + ${name_space})) &&
176 (${addr_sig} >= ${name_space}))) begin
Eunchan Kimc7452942019-12-19 17:04:37 -0800177 % endif
Timothy Chen3b812842020-01-09 10:38:02 -0800178 dev_sel_${block.name} = ${"%d'd%d" % (sel_len, loop.index)};
Michael Schaffnerd4d5d2f2020-04-17 15:45:55 -0700179${"end" if loop.last else ""}
Eunchan Kimc7452942019-12-19 17:04:37 -0800180 % else:
181 ## Xbar device port
182<%
183 num_range = len(leaf.addr_range)
184%>\
185 ${prefix}
186 % for i in range(num_range):
187 % if lib.is_pow2(leaf.addr_range[i][1]-leaf.addr_range[0][0]+1):
188 ((${addr_sig} & ~(${name_mask}[${i}])) == ${name_space}[${i}])${" ||" if not loop.last else ""}
189 % else:
190 ((${addr_sig} <= (${name_mask}[${i}] + ${name_space}[${i}])) &&
191 (${addr_sig} >= ${name_space}[${i}]))${" ||" if not loop.last else ""}
192 % endif
193 % endfor
194 ) begin
195 dev_sel_${block.name} = ${"%d'd%d" % (sel_len, loop.index)};
Michael Schaffnerd4d5d2f2020-04-17 15:45:55 -0700196${"end" if loop.last else ""}
lowRISC Contributors802543a2019-08-31 12:12:56 +0100197 % endif
198% endfor
199 end
200
201% endfor
202
203 // Instantiation phase
204% for block in xbar.nodes:
Rupert Swarbricka5e687f2021-03-01 11:51:41 +0000205<%
206 stripped_name = block.name.replace('.', '__')
207%>\
lowRISC Contributors802543a2019-08-31 12:12:56 +0100208 % if block.node_type.name == "ASYNC_FIFO":
209 tlul_fifo_async #(
Tom Robertsa8bbb2e2021-01-22 15:19:14 +0000210 .ReqDepth (4),// At least 4 to make async work
211 .RspDepth (4) // At least 4 to make async work
Rupert Swarbricka5e687f2021-03-01 11:51:41 +0000212 ) u_${stripped_name} (
Timothy Chen09d859b2019-11-08 14:01:12 -0800213 .clk_h_i (${block.clocks[0]}),
214 .rst_h_ni (${block.resets[0]}),
215 .clk_d_i (${block.clocks[1]}),
216 .rst_d_ni (${block.resets[1]}),
Rupert Swarbricka5e687f2021-03-01 11:51:41 +0000217 .tl_h_i (tl_${stripped_name}_us_h2d),
218 .tl_h_o (tl_${stripped_name}_us_d2h),
219 .tl_d_o (tl_${stripped_name}_ds_h2d),
220 .tl_d_i (tl_${stripped_name}_ds_d2h)
lowRISC Contributors802543a2019-08-31 12:12:56 +0100221 );
222 % elif block.node_type.name == "SOCKET_1N":
223 tlul_socket_1n #(
Timothy Chen1299fa12022-03-22 18:21:02 -0700224 % if block.hreq_pass != 1:
225 .HReqPass (1'b${block.hreq_pass}),
226 % endif
227 % if block.hrsp_pass != 1:
228 .HRspPass (1'b${block.hrsp_pass}),
Timothy Chen61e25e82019-09-13 14:04:10 -0700229 % endif
230 % if block.hdepth != 2:
231 .HReqDepth (4'h${block.hdepth}),
232 .HRspDepth (4'h${block.hdepth}),
lowRISC Contributors802543a2019-08-31 12:12:56 +0100233 % endif
Timothy Chen1299fa12022-03-22 18:21:02 -0700234 % if block.dreq_pass != 2**(len(block.ds)) -1:
235 .DReqPass (${len(block.ds)}'h${"%x" % block.dreq_pass}),
236 % endif
237 % if block.drsp_pass != 2**(len(block.ds)) -1:
238 .DRspPass (${len(block.ds)}'h${"%x" % block.drsp_pass}),
lowRISC Contributors802543a2019-08-31 12:12:56 +0100239 % endif
Timothy Chena37d6e42020-06-18 11:43:20 -0700240 % if block.ddepth != 2:
241 .DReqDepth (${len(block.ds)*4}'h${"%x" % block.ddepth}),
242 .DRspDepth (${len(block.ds)*4}'h${"%x" % block.ddepth}),
Timothy Chen61e25e82019-09-13 14:04:10 -0700243 % endif
244 .N (${len(block.ds)})
Rupert Swarbricka5e687f2021-03-01 11:51:41 +0000245 ) u_${stripped_name} (
Timothy Chen09d859b2019-11-08 14:01:12 -0800246 .clk_i (${block.clocks[0]}),
247 .rst_ni (${block.resets[0]}),
Rupert Swarbricka5e687f2021-03-01 11:51:41 +0000248 .tl_h_i (tl_${stripped_name}_us_h2d),
249 .tl_h_o (tl_${stripped_name}_us_d2h),
250 .tl_d_o (tl_${stripped_name}_ds_h2d),
251 .tl_d_i (tl_${stripped_name}_ds_d2h),
252 .dev_select_i (dev_sel_${stripped_name})
lowRISC Contributors802543a2019-08-31 12:12:56 +0100253 );
254 % elif block.node_type.name == "SOCKET_M1":
255 tlul_socket_m1 #(
Timothy Chen1299fa12022-03-22 18:21:02 -0700256 % if block.hreq_pass != 2**(len(block.us)) - 1:
257 .HReqPass (${len(block.us)}'h${"%x" % block.hreq_pass}),
258 % endif
259 % if block.hrsp_pass != 2**(len(block.us)) - 1:
260 .HRspPass (${len(block.us)}'h${"%x" % block.hrsp_pass}),
lowRISC Contributors802543a2019-08-31 12:12:56 +0100261 % endif
Timothy Chen61e25e82019-09-13 14:04:10 -0700262 % if block.hdepth != 2:
Timothy Chena37d6e42020-06-18 11:43:20 -0700263 .HReqDepth (${len(block.us)*4}'h${"%x" % block.hdepth}),
264 .HRspDepth (${len(block.us)*4}'h${"%x" % block.hdepth}),
Timothy Chen61e25e82019-09-13 14:04:10 -0700265 % endif
Timothy Chen1299fa12022-03-22 18:21:02 -0700266 % if block.dreq_pass != 1:
267 .DReqPass (1'b${block.dreq_pass}),
268 % endif
269 % if block.drsp_pass != 1:
270 .DRspPass (1'b${block.drsp_pass}),
lowRISC Contributors802543a2019-08-31 12:12:56 +0100271 % endif
Timothy Chena37d6e42020-06-18 11:43:20 -0700272 % if block.ddepth != 2:
273 .DReqDepth (4'h${block.ddepth}),
274 .DRspDepth (4'h${block.ddepth}),
275 % endif
Timothy Chen61e25e82019-09-13 14:04:10 -0700276 .M (${len(block.us)})
Rupert Swarbricka5e687f2021-03-01 11:51:41 +0000277 ) u_${stripped_name} (
Timothy Chen09d859b2019-11-08 14:01:12 -0800278 .clk_i (${block.clocks[0]}),
279 .rst_ni (${block.resets[0]}),
Rupert Swarbricka5e687f2021-03-01 11:51:41 +0000280 .tl_h_i (tl_${stripped_name}_us_h2d),
281 .tl_h_o (tl_${stripped_name}_us_d2h),
282 .tl_d_o (tl_${stripped_name}_ds_h2d),
283 .tl_d_i (tl_${stripped_name}_ds_d2h)
lowRISC Contributors802543a2019-08-31 12:12:56 +0100284 );
285 % endif
286% endfor
287
288endmodule