-
Notifications
You must be signed in to change notification settings - Fork 101
/
axilxbar.v
2421 lines (2203 loc) · 59.4 KB
/
axilxbar.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
////////////////////////////////////////////////////////////////////////////////
//
// Filename: axilxbar.v
// {{{
// Project: WB2AXIPSP: bus bridges and other odds and ends
//
// Purpose: Create a full crossbar between NM AXI-lite sources (masters),
// and NS AXI-lite slaves. Every master can talk to any slave,
// provided it isn't already busy.
//
// Performance: This core has been designed with the goal of being able to push
// one transaction through the interconnect, from any master to
// any slave, per clock cycle. This may perhaps be its most unique
// feature. While throughput is good, latency is something else.
//
// The arbiter requires a clock to switch, then another clock to send data
// downstream. This creates a minimum two clock latency up front. The
// return path suffers another clock of latency as well, placing the
// minimum latency at four clocks. The minimum write latency is at
// least one clock longer, since the write data must wait for the write
// address before proceeeding.
//
// Usage: To use, you must first set NM and NS to the number of masters
// and the number of slaves you wish to connect to. You then need to
// adjust the addresses of the slaves, found SLAVE_ADDR array. Those
// bits that are relevant in SLAVE_ADDR to then also be set in SLAVE_MASK.
// Adjusting the data and address widths go without saying.
//
// Lower numbered masters are given priority in any "fight".
//
// Channel grants are given on the condition that 1) they are requested,
// 2) no other channel has a grant, 3) all of the responses have been
// received from the current channel, and 4) the internal counters are
// not overflowing.
//
// The core limits the number of outstanding transactions on any channel to
// 1<<LGMAXBURST-1.
//
// Channel grants are lost 1) after OPT_LINGER clocks of being idle, or
// 2) when another master requests an idle (but still lingering) channel
// assignment, or 3) once all the responses have been returned to the
// current channel, and the current master is requesting another channel.
//
// A special slave is allocated for the case of no valid address.
//
// Since the write channel has no address information, the write data
// channel always be delayed by at least one clock from the write address
// channel.
//
// If OPT_LOWPOWER is set, then unused values will be set to zero.
// This can also be used to help identify relevant values within any
// trace.
//
//
// Creator: Dan Gisselquist, Ph.D.
// Gisselquist Technology, LLC
//
////////////////////////////////////////////////////////////////////////////////
// }}}
// Copyright (C) 2019-2024, Gisselquist Technology, LLC
// {{{
// This file is part of the WB2AXIP project.
//
// The WB2AXIP project contains free software and gateware, licensed under the
// Apache License, Version 2.0 (the "License"). You may not use this project,
// or this file, except in compliance with the License. You may obtain a copy
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
//
////////////////////////////////////////////////////////////////////////////////
//
`default_nettype none
// }}}
module axilxbar #(
// {{{
parameter integer C_AXI_DATA_WIDTH = 32,
parameter integer C_AXI_ADDR_WIDTH = 32,
//
// NM is the number of master interfaces this core supports
parameter NM = 4,
//
// NS is the number of slave interfaces
parameter NS = 8,
//
// AW, and DW, are short-hand abbreviations used locally.
localparam AW = C_AXI_ADDR_WIDTH,
localparam DW = C_AXI_DATA_WIDTH,
// SLAVE_ADDR is a bit vector containing AW bits for each of the
// slaves indicating the base address of the slave. This
// goes with SLAVE_MASK below.
parameter [NS*AW-1:0] SLAVE_ADDR = {
3'b111, {(AW-3){1'b0}},
3'b110, {(AW-3){1'b0}},
3'b101, {(AW-3){1'b0}},
3'b100, {(AW-3){1'b0}},
3'b011, {(AW-3){1'b0}},
3'b010, {(AW-3){1'b0}},
4'b0001, {(AW-4){1'b0}},
4'b0000, {(AW-4){1'b0}} },
//
// SLAVE_MASK indicates which bits in the SLAVE_ADDR bit vector
// need to be checked to determine if a given address request
// maps to the given slave or not
// Verilator lint_off WIDTH
parameter [NS*AW-1:0] SLAVE_MASK =
(NS <= 1) ? { 4'b1111, {(AW-4){1'b0}} }
: { {(NS-2){ 3'b111, {(AW-3){1'b0}} }},
{(2){ 4'b1111, {(AW-4){1'b0}} }} },
// Verilator lint_on WIDTH
//
// If set, OPT_LOWPOWER will set all unused registers, both
// internal and external, to zero anytime their corresponding
// *VALID bit is clear
parameter [0:0] OPT_LOWPOWER = 1,
//
// OPT_LINGER is the number of cycles to wait, following a
// transaction, before tearing down the bus grant.
parameter OPT_LINGER = 4,
//
// LGMAXBURST is the log (base two) of the maximum number of
// requests that can be outstanding on any given channel at any
// given time. It is used within this core to control the
// counters that are used to determine if a particular channel
// grant must stay open, or if it may be closed.
parameter LGMAXBURST = 5
// }}}
) (
// {{{
input wire S_AXI_ACLK,
input wire S_AXI_ARESETN,
// Incoming AXI4-lite slave port(s)
// {{{
input wire [NM-1:0] S_AXI_AWVALID,
output wire [NM-1:0] S_AXI_AWREADY,
input wire [NM*C_AXI_ADDR_WIDTH-1:0] S_AXI_AWADDR,
// Verilator coverage_off
input wire [NM*3-1:0] S_AXI_AWPROT,
// Verilator coverage_on
//
input wire [NM-1:0] S_AXI_WVALID,
output wire [NM-1:0] S_AXI_WREADY,
input wire [NM*C_AXI_DATA_WIDTH-1:0] S_AXI_WDATA,
input wire [NM*C_AXI_DATA_WIDTH/8-1:0] S_AXI_WSTRB,
//
output wire [NM-1:0] S_AXI_BVALID,
input wire [NM-1:0] S_AXI_BREADY,
output wire [NM*2-1:0] S_AXI_BRESP,
//
input wire [NM-1:0] S_AXI_ARVALID,
output wire [NM-1:0] S_AXI_ARREADY,
input wire [NM*C_AXI_ADDR_WIDTH-1:0] S_AXI_ARADDR,
// Verilator coverage_off
input wire [NM*3-1:0] S_AXI_ARPROT,
// Verilator coverage_on
//
output wire [NM-1:0] S_AXI_RVALID,
input wire [NM-1:0] S_AXI_RREADY,
output wire [NM*C_AXI_DATA_WIDTH-1:0] S_AXI_RDATA,
output wire [NM*2-1:0] S_AXI_RRESP,
// }}}
// Outgoing AXI4-lite master port(s)
// {{{
output wire [NS*C_AXI_ADDR_WIDTH-1:0] M_AXI_AWADDR,
output wire [NS*3-1:0] M_AXI_AWPROT,
output wire [NS-1:0] M_AXI_AWVALID,
input wire [NS-1:0] M_AXI_AWREADY,
//
output wire [NS*C_AXI_DATA_WIDTH-1:0] M_AXI_WDATA,
output wire [NS*C_AXI_DATA_WIDTH/8-1:0] M_AXI_WSTRB,
output wire [NS-1:0] M_AXI_WVALID,
input wire [NS-1:0] M_AXI_WREADY,
//
input wire [NS*2-1:0] M_AXI_BRESP,
input wire [NS-1:0] M_AXI_BVALID,
output wire [NS-1:0] M_AXI_BREADY,
//
output wire [NS*C_AXI_ADDR_WIDTH-1:0] M_AXI_ARADDR,
output wire [NS*3-1:0] M_AXI_ARPROT,
output wire [NS-1:0] M_AXI_ARVALID,
input wire [NS-1:0] M_AXI_ARREADY,
//
input wire [NS*C_AXI_DATA_WIDTH-1:0] M_AXI_RDATA,
input wire [NS*2-1:0] M_AXI_RRESP,
input wire [NS-1:0] M_AXI_RVALID,
output wire [NS-1:0] M_AXI_RREADY
// }}}
// }}}
);
//
// Local parameters, derived from those above
// {{{
localparam LGLINGER = (OPT_LINGER>1) ? $clog2(OPT_LINGER+1) : 1;
//
localparam LGNM = (NM>1) ? $clog2(NM) : 1;
localparam LGNS = (NS>1) ? $clog2(NS+1) : 1;
//
// In order to use indexes, and hence fully balanced mux trees, it helps
// to make certain that we have a power of two based lookup. NMFULL
// is the number of masters in this lookup, with potentially some
// unused extra ones. NSFULL is defined similarly.
localparam NMFULL = (NM>1) ? (1<<LGNM) : 1;
localparam NSFULL = (NS>1) ? (1<<LGNS) : 2;
//
localparam [1:0] INTERCONNECT_ERROR = 2'b11;
localparam [0:0] OPT_SKID_INPUT = 0;
localparam [0:0] OPT_BUFFER_DECODER = 1;
genvar N,M;
integer iN, iM;
// }}}
// {{{
reg [NSFULL-1:0] wrequest [0:NM-1];
reg [NSFULL-1:0] rrequest [0:NM-1];
reg [NSFULL-1:0] wrequested [0:NM];
reg [NSFULL-1:0] rrequested [0:NM];
reg [NS:0] wgrant [0:NM-1];
reg [NS:0] rgrant [0:NM-1];
reg [NM-1:0] swgrant;
reg [NM-1:0] srgrant;
reg [NS-1:0] mwgrant;
reg [NS-1:0] mrgrant;
// verilator lint_off UNUSED
wire [LGMAXBURST-1:0] w_sawpending [0:NM-1];
`ifdef FORMAL
wire [LGMAXBURST-1:0] w_swpending [0:NM-1];
`endif
wire [LGMAXBURST-1:0] w_srpending [0:NM-1];
// verilator lint_on UNUSED
reg [NM-1:0] swfull;
reg [NM-1:0] srfull;
reg [NM-1:0] swempty;
reg [NM-1:0] srempty;
//
wire [LGNS-1:0] swindex [0:NMFULL-1];
wire [LGNS-1:0] srindex [0:NMFULL-1];
wire [LGNM-1:0] mwindex [0:NSFULL-1];
wire [LGNM-1:0] mrindex [0:NSFULL-1];
wire [NM-1:0] wdata_expected;
// The shadow buffers
wire [NMFULL-1:0] m_awvalid, m_wvalid, m_arvalid;
wire [NM-1:0] dcd_awvalid, dcd_arvalid;
wire [C_AXI_ADDR_WIDTH-1:0] m_awaddr [0:NMFULL-1];
wire [2:0] m_awprot [0:NMFULL-1];
wire [C_AXI_DATA_WIDTH-1:0] m_wdata [0:NMFULL-1];
wire [C_AXI_DATA_WIDTH/8-1:0] m_wstrb [0:NMFULL-1];
wire [C_AXI_ADDR_WIDTH-1:0] m_araddr [0:NMFULL-1];
wire [2:0] m_arprot [0:NMFULL-1];
//
wire [NM-1:0] skd_awvalid, skd_awstall, skd_wvalid;
wire [NM-1:0] skd_arvalid, skd_arstall;
wire [AW-1:0] skd_awaddr [0:NM-1];
wire [3-1:0] skd_awprot [0:NM-1];
wire [AW-1:0] skd_araddr [0:NM-1];
wire [3-1:0] skd_arprot [0:NM-1];
reg [NM-1:0] r_bvalid;
reg [1:0] r_bresp [0:NM-1];
reg [NSFULL-1:0] m_axi_awvalid;
reg [NSFULL-1:0] m_axi_awready;
reg [NSFULL-1:0] m_axi_wvalid;
reg [NSFULL-1:0] m_axi_wready;
reg [NSFULL-1:0] m_axi_bvalid;
`ifdef FORMAL
reg [NSFULL-1:0] m_axi_bready;
`endif
reg [1:0] m_axi_bresp [0:NSFULL-1];
reg [NSFULL-1:0] m_axi_arvalid;
// Verilator lint_off UNUSED
reg [NSFULL-1:0] m_axi_arready;
// Verilator lint_on UNUSED
reg [NSFULL-1:0] m_axi_rvalid;
// Verilator lint_off UNUSED
reg [NSFULL-1:0] m_axi_rready;
// Verilator lint_on UNUSED
reg [NM-1:0] r_rvalid;
reg [1:0] r_rresp [0:NM-1];
reg [DW-1:0] r_rdata [0:NM-1];
reg [DW-1:0] m_axi_rdata [0:NSFULL-1];
reg [1:0] m_axi_rresp [0:NSFULL-1];
reg [NM-1:0] slave_awaccepts;
reg [NM-1:0] slave_waccepts;
reg [NM-1:0] slave_raccepts;
// }}}
// m_axi_[aw|w|b]*
// {{{
always @(*)
begin
m_axi_awvalid = -1;
m_axi_awready = -1;
m_axi_wvalid = -1;
m_axi_wready = -1;
m_axi_bvalid = 0;
m_axi_awvalid[NS-1:0] = M_AXI_AWVALID;
m_axi_awready[NS-1:0] = M_AXI_AWREADY;
m_axi_wvalid[NS-1:0] = M_AXI_WVALID;
m_axi_wready[NS-1:0] = M_AXI_WREADY;
m_axi_bvalid[NS-1:0] = M_AXI_BVALID;
for(iM=0; iM<NS; iM=iM+1)
begin
m_axi_bresp[iM] = M_AXI_BRESP[iM* 2 +: 2];
m_axi_rdata[iM] = M_AXI_RDATA[iM*DW +: DW];
m_axi_rresp[iM] = M_AXI_RRESP[iM* 2 +: 2];
end
for(iM=NS; iM<NSFULL; iM=iM+1)
begin
m_axi_bresp[iM] = INTERCONNECT_ERROR;
m_axi_rdata[iM] = 0;
m_axi_rresp[iM] = INTERCONNECT_ERROR;
end
`ifdef FORMAL
m_axi_bready = -1;
m_axi_bready[NS-1:0] = M_AXI_BREADY;
`endif
end
// }}}
generate for(N=0; N<NM; N=N+1)
begin : DECODE_WRITE_REQUEST
// {{{
wire [NS:0] wdecode;
reg r_mawvalid, r_mwvalid;
// awskid
// {{{
skidbuffer #(
// {{{
.DW(AW+3), .OPT_OUTREG(OPT_SKID_INPUT)
// }}}
) awskid(
// {{{
.i_clk(S_AXI_ACLK), .i_reset(!S_AXI_ARESETN),
.i_valid(S_AXI_AWVALID[N]), .o_ready(S_AXI_AWREADY[N]),
.i_data({ S_AXI_AWADDR[N*AW +: AW], S_AXI_AWPROT[N*3 +: 3] }),
.o_valid(skd_awvalid[N]), .i_ready(!skd_awstall[N]),
.o_data({ skd_awaddr[N], skd_awprot[N] })
// }}}
);
// }}}
// write address decoding
// {{{
addrdecode #(
// {{{
.AW(AW), .DW(3), .NS(NS),
.SLAVE_ADDR(SLAVE_ADDR),
.SLAVE_MASK(SLAVE_MASK),
.OPT_REGISTERED(OPT_BUFFER_DECODER)
// }}}
) wraddr(
// {{{
.i_clk(S_AXI_ACLK), .i_reset(!S_AXI_ARESETN),
.i_valid(skd_awvalid[N]), .o_stall(skd_awstall[N]),
.i_addr(skd_awaddr[N]), .i_data(skd_awprot[N]),
.o_valid(dcd_awvalid[N]),
.i_stall(!dcd_awvalid[N]||!slave_awaccepts[N]),
.o_decode(wdecode), .o_addr(m_awaddr[N]),
.o_data(m_awprot[N])
// }}}
);
// }}}
// wskid
// {{{
skidbuffer #(
// {{{
.DW(DW+DW/8), .OPT_OUTREG(OPT_SKID_INPUT)
// }}}
) wskid (
// {{{
.i_clk(S_AXI_ACLK), .i_reset(!S_AXI_ARESETN),
.i_valid(S_AXI_WVALID[N]), .o_ready(S_AXI_WREADY[N]),
.i_data({ S_AXI_WDATA[N*DW +: DW],
S_AXI_WSTRB[N*DW/8 +: DW/8]}),
.o_valid(skd_wvalid[N]),
.i_ready(m_wvalid[N] && slave_waccepts[N]),
.o_data({ m_wdata[N], m_wstrb[N] })
// }}}
);
// }}}
// slave_awaccepts
// {{{
always @(*)
begin
slave_awaccepts[N] = 1'b1;
if (!swgrant[N])
slave_awaccepts[N] = 1'b0;
if (swfull[N])
slave_awaccepts[N] = 1'b0;
if (!wrequest[N][swindex[N]])
slave_awaccepts[N] = 1'b0;
if (!wgrant[N][NS]&&(m_axi_awvalid[swindex[N]] && !m_axi_awready[swindex[N]]))
slave_awaccepts[N] = 1'b0;
// ERRORs are always accepted
// back pressure is handled in the write side
end
// }}}
// slave_waccepts
// {{{
always @(*)
begin
slave_waccepts[N] = 1'b1;
if (!swgrant[N])
slave_waccepts[N] = 1'b0;
if (!wdata_expected[N])
slave_waccepts[N] = 1'b0;
if (!wgrant[N][NS] &&(m_axi_wvalid[swindex[N]]
&& !m_axi_wready[swindex[N]]))
slave_waccepts[N] = 1'b0;
if (wgrant[N][NS]&&(S_AXI_BVALID[N]&& !S_AXI_BREADY[N]))
slave_waccepts[N] = 1'b0;
end
// }}}
// r_mawvalid, r_mwvalid
// {{{
always @(*)
begin
r_mawvalid= dcd_awvalid[N] && !swfull[N];
r_mwvalid = skd_wvalid[N];
wrequest[N]= 0;
if (!swfull[N])
wrequest[N][NS:0] = wdecode;
end
assign m_awvalid[N] = r_mawvalid;
assign m_wvalid[N] = r_mwvalid;
// }}}
// }}}
end for (N=NM; N<NMFULL; N=N+1)
begin : UNUSED_WSKID_BUFFERS
// {{{
assign m_awvalid[N] = 0;
assign m_awaddr[N] = 0;
assign m_awprot[N] = 0;
assign m_wdata[N] = 0;
assign m_wstrb[N] = 0;
// }}}
end endgenerate
generate for(N=0; N<NM; N=N+1)
begin : DECODE_READ_REQUEST
// {{{
wire [NS:0] rdecode;
reg r_marvalid;
// arskid
// {{{
skidbuffer #(
// {{{
.DW(AW+3), .OPT_OUTREG(OPT_SKID_INPUT)
// }}}
) arskid(
// {{{
.i_clk(S_AXI_ACLK), .i_reset(!S_AXI_ARESETN),
.i_valid(S_AXI_ARVALID[N]), .o_ready(S_AXI_ARREADY[N]),
.i_data({ S_AXI_ARADDR[N*AW +: AW], S_AXI_ARPROT[N*3 +: 3] }),
.o_valid(skd_arvalid[N]), .i_ready(!skd_arstall[N]),
.o_data({ skd_araddr[N], skd_arprot[N] })
// }}}
);
// }}}
// Read address decoding
// {{{
addrdecode #(
// {{{
.AW(AW), .DW(3), .NS(NS),
.SLAVE_ADDR(SLAVE_ADDR), .SLAVE_MASK(SLAVE_MASK),
.OPT_REGISTERED(OPT_BUFFER_DECODER)
// }}}
) rdaddr(
// {{{
.i_clk(S_AXI_ACLK), .i_reset(!S_AXI_ARESETN),
.i_valid(skd_arvalid[N]), .o_stall(skd_arstall[N]),
.i_addr(skd_araddr[N]), .i_data(skd_arprot[N]),
.o_valid(dcd_arvalid[N]),
.i_stall(!m_arvalid[N] || !slave_raccepts[N]),
.o_decode(rdecode), .o_addr(m_araddr[N]),
.o_data(m_arprot[N])
// }}}
);
// }}}
// r_marvalid -> m_arvalid[N]
// {{{
always @(*)
begin
r_marvalid = dcd_arvalid[N] && !srfull[N];
rrequest[N] = 0;
if (!srfull[N])
rrequest[N][NS:0] = rdecode;
end
assign m_arvalid[N] = r_marvalid;
// }}}
// slave_raccepts
// {{{
always @(*)
begin
slave_raccepts[N] = 1'b1;
if (!srgrant[N])
slave_raccepts[N] = 1'b0;
if (srfull[N])
slave_raccepts[N] = 1'b0;
// verilator lint_off WIDTH
if (!rrequest[N][srindex[N]])
slave_raccepts[N] = 1'b0;
// verilator lint_on WIDTH
if (!rgrant[N][NS])
begin
if (m_axi_arvalid[srindex[N]] && !m_axi_arready[srindex[N]])
slave_raccepts[N] = 1'b0;
end else if (S_AXI_RVALID[N] && !S_AXI_RREADY[N])
slave_raccepts[N] = 1'b0;
end
// }}}
// }}}
end for (N=NM; N<NMFULL; N=N+1)
begin : UNUSED_RSKID_BUFFERS
// {{{
assign m_arvalid[N] = 0;
assign m_araddr[N] = 0;
assign m_arprot[N] = 0;
// }}}
end endgenerate
// wrequested
// {{{
always @(*)
begin : DECONFLICT_WRITE_REQUESTS
for(iN=1; iN<NM ; iN=iN+1)
wrequested[iN] = 0;
// Vivado may complain about too many bits for wrequested.
// This is (currrently) expected. swindex is used to index
// into wrequested, and swindex has LGNS bits, where LGNS
// is $clog2(NS+1) rather than $clog2(NS). The extra bits
// are defined to be zeros, but the point is there are defined.
// Therefore, no matter what swindex is, it will always
// reference something valid.
wrequested[NM] = 0;
for(iM=0; iM<NS; iM=iM+1)
begin
wrequested[0][iM] = 1'b0;
for(iN=1; iN<NM ; iN=iN+1)
begin
// Continue to request any channel with
// a grant and pending operations
if (wrequest[iN-1][iM] && wgrant[iN-1][iM])
wrequested[iN][iM] = 1;
if (wrequest[iN-1][iM] && (!swgrant[iN-1]||swempty[iN-1]))
wrequested[iN][iM] = 1;
// Otherwise, if it's already claimed, then
// it can't be claimed again
if (wrequested[iN-1][iM])
wrequested[iN][iM] = 1;
end
wrequested[NM][iM] = wrequest[NM-1][iM] || wrequested[NM-1][iM];
end
end
// }}}
// rrequested
// {{{
always @(*)
begin : DECONFLICT_READ_REQUESTS
for(iN=0; iN<NM ; iN=iN+1)
rrequested[iN] = 0;
// See the note above for wrequested. This applies to
// rrequested as well.
rrequested[NM] = 0;
for(iM=0; iM<NS; iM=iM+1)
begin
rrequested[0][iM] = 0;
for(iN=1; iN<NM ; iN=iN+1)
begin
// Continue to request any channel with
// a grant and pending operations
if (rrequest[iN-1][iM] && rgrant[iN-1][iM])
rrequested[iN][iM] = 1;
if (rrequest[iN-1][iM] && (!srgrant[iN-1] || srempty[iN-1]))
rrequested[iN][iM] = 1;
// Otherwise, if it's already claimed, then
// it can't be claimed again
if (rrequested[iN-1][iM])
rrequested[iN][iM] = 1;
end
rrequested[NM][iM] = rrequest[NM-1][iM] || rrequested[NM-1][iM];
end
end
// }}}
// mwgrant, mrgrant
// {{{
generate for(M=0; M<NS; M=M+1)
begin : GEN_GRANT
// {{{
initial mwgrant[M] = 0;
always @(*)
begin
mwgrant[M] = 0;
for(iN=0; iN<NM; iN=iN+1)
if (wgrant[iN][M])
mwgrant[M] = 1;
end
always @(*)
begin
mrgrant[M] = 0;
for(iN=0; iN<NM; iN=iN+1)
if (rgrant[iN][M])
mrgrant[M] = 1;
end
// }}}
end endgenerate
// }}}
generate for(N=0; N<NM; N=N+1)
begin : ARBITRATE_WRITE_REQUESTS
// {{{
// Declarations
// {{{
reg stay_on_channel;
reg requested_channel_is_available;
reg leave_channel;
reg [LGNS-1:0] requested_index;
wire linger;
// }}}
// stay_on_channel
// {{{
always @(*)
begin
stay_on_channel = |(wrequest[N][NS:0] & wgrant[N]);
if (swgrant[N] && !swempty[N])
stay_on_channel = 1;
end
// }}}
// requested_channel_is_available
// {{{
always @(*)
begin
requested_channel_is_available =
|(wrequest[N][NS-1:0] & ~mwgrant
& ~wrequested[N][NS-1:0]);
if (wrequest[N][NS])
requested_channel_is_available = 1;
if (NM < 2)
requested_channel_is_available = m_awvalid[N];
end
// }}}
if (OPT_LINGER == 0)
begin : NO_LINGER
// {{{
assign linger = 0;
// }}}
end else begin : WRITE_LINGER
// {{{
reg [LGLINGER-1:0] linger_counter;
reg r_linger;
initial r_linger = 0;
initial linger_counter = 0;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN || wgrant[N][NS])
begin
r_linger <= 0;
linger_counter <= 0;
end else if (!swempty[N] || S_AXI_BVALID[N])
begin
linger_counter <= OPT_LINGER;
r_linger <= 1;
end else if (linger_counter > 0)
begin
r_linger <= (linger_counter > 1);
linger_counter <= linger_counter - 1;
end else
r_linger <= 0;
assign linger = r_linger;
`ifdef FORMAL
// {{{
always @(*)
assert(linger == (linger_counter != 0));
// }}}
`endif
// }}}
end
// leave_channel
// {{{
always @(*)
begin
leave_channel = 0;
if (!m_awvalid[N]
&& (!linger || wrequested[NM][swindex[N]]))
// Leave the channel after OPT_LINGER counts
// of the channel being idle, or when someone
// else asks for the channel
leave_channel = 1;
if (m_awvalid[N] && !wrequest[N][swindex[N]])
// Need to leave this channel to connect
// to any other channel
leave_channel = 1;
end
// }}}
// wgrant, swgrant
// {{{
initial wgrant[N] = 0;
initial swgrant[N] = 0;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN)
begin
wgrant[N] <= 0;
swgrant[N] <= 0;
end else if (!stay_on_channel)
begin
if (requested_channel_is_available)
begin
// Switching channels
swgrant[N] <= 1'b1;
wgrant[N] <= wrequest[N][NS:0];
end else if (leave_channel)
begin
swgrant[N] <= 1'b0;
wgrant[N] <= 0;
end
end
// }}}
// requested_index
// {{{
always @(wrequest[N])
begin
requested_index = 0;
for(iM=0; iM<=NS; iM=iM+1)
if (wrequest[N][iM])
requested_index= requested_index | iM[LGNS-1:0];
end
// }}}
// Now for swindex
// {{{
reg [LGNS-1:0] r_swindex;
initial r_swindex = 0;
always @(posedge S_AXI_ACLK)
if (!stay_on_channel && requested_channel_is_available)
r_swindex <= requested_index;
assign swindex[N] = r_swindex;
// }}}
// }}}
end for (N=NM; N<NMFULL; N=N+1)
begin : EMPTY_WRITE_REQUEST
// {{{
assign swindex[N] = 0;
// }}}
end endgenerate
generate for(N=0; N<NM; N=N+1)
begin : ARBITRATE_READ_REQUESTS
// {{{
// Declarations
// {{{
reg stay_on_channel;
reg requested_channel_is_available;
reg leave_channel;
reg [LGNS-1:0] requested_index;
wire linger;
// }}}
// stay_on_channel
// {{{
always @(*)
begin
stay_on_channel = |(rrequest[N][NS:0] & rgrant[N]);
if (srgrant[N] && !srempty[N])
stay_on_channel = 1;
end
// }}}
// requested_channel_is_available
// {{{
always @(*)
begin
requested_channel_is_available =
|(rrequest[N][NS-1:0] & ~mrgrant
& ~rrequested[N][NS-1:0]);
if (rrequest[N][NS])
requested_channel_is_available = 1;
if (NM < 2)
requested_channel_is_available = m_arvalid[N];
end
// }}}
if (OPT_LINGER == 0)
begin : NO_LINGER
// {{{
assign linger = 0;
// }}}
end else begin : READ_LINGER
// {{{
reg [LGLINGER-1:0] linger_counter;
reg r_linger;
initial r_linger = 0;
initial linger_counter = 0;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN || rgrant[N][NS])
begin
r_linger <= 0;
linger_counter <= 0;
end else if (!srempty[N] || S_AXI_RVALID[N])
begin
linger_counter <= OPT_LINGER;
r_linger <= 1;
end else if (linger_counter > 0)
begin
r_linger <= (linger_counter > 1);
linger_counter <= linger_counter - 1;
end else
r_linger <= 0;
assign linger = r_linger;
`ifdef FORMAL
// {{{
always @(*)
assert(linger == (linger_counter != 0));
// }}}
`endif
// }}}
end
// leave_channel
// {{{
always @(*)
begin
leave_channel = 0;
if (!m_arvalid[N]
&& (!linger || rrequested[NM][srindex[N]]))
// Leave the channel after OPT_LINGER counts
// of the channel being idle, or when someone
// else asks for the channel
leave_channel = 1;
if (m_arvalid[N] && !rrequest[N][srindex[N]])
// Need to leave this channel to connect
// to any other channel
leave_channel = 1;
end
// }}}
// rgrant, srgrant
// {{{
initial rgrant[N] = 0;
initial srgrant[N] = 0;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN)
begin
rgrant[N] <= 0;
srgrant[N] <= 0;
end else if (!stay_on_channel)
begin
if (requested_channel_is_available)
begin
// Switching channels
srgrant[N] <= 1'b1;
rgrant[N] <= rrequest[N][NS:0];
end else if (leave_channel)
begin
srgrant[N] <= 1'b0;
rgrant[N] <= 0;
end
end
// }}}
// requested_index
// {{{
always @(rrequest[N])
begin
requested_index = 0;
for(iM=0; iM<=NS; iM=iM+1)
if (rrequest[N][iM])
requested_index = requested_index|iM[LGNS-1:0];
end
// }}}
// Now for srindex
// {{{
reg [LGNS-1:0] r_srindex;
initial r_srindex = 0;
always @(posedge S_AXI_ACLK)
if (!stay_on_channel && requested_channel_is_available)
r_srindex <= requested_index;
assign srindex[N] = r_srindex;
// }}}
// }}}
end for (N=NM; N<NMFULL; N=N+1)
begin : EMPTY_READ_REQUEST
// {{{
assign srindex[N] = 0;
// }}}
end endgenerate
// Calculate mwindex
generate for (M=0; M<NS; M=M+1)
begin : SLAVE_WRITE_INDEX
// {{{
if (NM <= 1)
begin : ONE_MASTER
// {{{
assign mwindex[M] = 0;
// }}}
end else begin : MULTIPLE_MASTERS
// {{{
reg [LGNM-1:0] reswindex;
reg [LGNM-1:0] r_mwindex;
always @(*)
begin
reswindex = 0;
for(iN=0; iN<NM; iN=iN+1)
if ((!swgrant[iN] || swempty[iN])
&&(wrequest[iN][M] && !wrequested[iN][M]))
reswindex = reswindex | iN[LGNM-1:0];
end
always @(posedge S_AXI_ACLK)
if (!mwgrant[M])
r_mwindex <= reswindex;
assign mwindex[M] = r_mwindex;
// }}}
end
// }}}
end for (M=NS; M<NSFULL; M=M+1)
begin : NO_WRITE_INDEX
// {{{
assign mwindex[M] = 0;
// }}}
end endgenerate
// Calculate mrindex
generate for (M=0; M<NS; M=M+1)
begin : SLAVE_READ_INDEX
// {{{
if (NM <= 1)
begin : ONE_MASTER
// {{{
assign mrindex[M] = 0;
// }}}
end else begin : MULTIPLE_MASTERS
// {{{
reg [LGNM-1:0] resrindex;
reg [LGNM-1:0] r_mrindex;