forked from ZipCPU/wb2axip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
axixbar.v
2541 lines (2332 loc) · 68.6 KB
/
axixbar.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: axixbar.v
// {{{
// Project: WB2AXIPSP: bus bridges and other odds and ends
//
// Purpose: Create a full crossbar between NM AXI sources (masters), and NS
// AXI 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.
//
// Note that this arbiter only forwards AxID fields. It does not use
// them in arbitration. As a result, only one master may ever make
// requests of any given slave at a time. All responses from a slave
// will be returned to that known master. This is a known limitation in
// this implementation which will be fixed (in time) with funding and
// interest. Until that time, in order for a second master to access
// a given slave, the first master must receive all of its acknowledgments.
//
// 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-2021, 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 axixbar #(
// {{{
parameter integer C_AXI_DATA_WIDTH = 32,
parameter integer C_AXI_ADDR_WIDTH = 32,
parameter integer C_AXI_ID_WIDTH = 2,
//
// NM is the number of masters driving incoming slave channels
parameter NM = 4,
//
// NS is the number of slaves connected to the crossbar
parameter NS = 8,
//
// IW, AW, and DW, are short-hand abbreviations used locally.
localparam IW = C_AXI_ID_WIDTH,
localparam AW = C_AXI_ADDR_WIDTH,
localparam DW = C_AXI_DATA_WIDTH,
//
// SLAVE_ADDR is an array of addresses, describing each of
// {{{
// the slave channels. It works tightly with SLAVE_MASK,
// so that when (ADDR & MASK == ADDR), the channel in question
// has been requested.
//
// It is an internal in the setup of this core to doubly map
// an address, such that (addr & SLAVE_MASK[k])==SLAVE_ADDR[k]
// for two separate values of k.
//
// Any attempt to access an address that is a hole in this
// address list will result in a returned xRESP value of
// INTERCONNECT_ERROR (2'b11)
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: is an array, much like SLAVE_ADDR, describing
// {{{
// which of the bits in SLAVE_ADDR are relevant. It is
// important to maintain for every slave that
// (~SLAVE_MASK[i] & SLAVE_ADDR[i]) == 0.
// 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
// }}}
//
// OPT_LOWPOWER: If set, it forces all unused values to zero,
// {{{
// preventing them from unnecessarily toggling. This will
// raise the logic count of the core, but might also lower
// the power used by the interconnect and the bus driven wires
// which (in my experience) tend to have a high fan out.
parameter [0:0] OPT_LOWPOWER = 0,
// }}}
//
// OPT_LINGER: Set this to the number of clocks an idle
// {{{
// channel shall be left open before being closed. Once
// closed, it will take a minimum of two clocks before the
// channel can be opened and data transmitted through it again.
parameter OPT_LINGER = 4,
// }}}
//
// [EXPERIMENTAL] OPT_QOS: If set, the QOS transmission values
// {{{
// will be honored when determining who wins arbitration for
// accessing a given slave. (This feature has not yet been
// verified)
parameter [0:0] OPT_QOS = 0,
// }}}
//
// LGMAXBURST: Specifies the log based two of the maximum
// {{{
// number of bursts transactions that may be outstanding at any
// given time. This is different from the maximum number of
// outstanding beats.
parameter LGMAXBURST = 3
// }}}
// }}}
) (
// {{{
input wire S_AXI_ACLK,
input wire S_AXI_ARESETN,
// Write slave channels from the controlling AXI masters
// {{{
input wire [NM*C_AXI_ID_WIDTH-1:0] S_AXI_AWID,
input wire [NM*C_AXI_ADDR_WIDTH-1:0] S_AXI_AWADDR,
input wire [NM*8-1:0] S_AXI_AWLEN,
input wire [NM*3-1:0] S_AXI_AWSIZE,
input wire [NM*2-1:0] S_AXI_AWBURST,
input wire [NM-1:0] S_AXI_AWLOCK,
input wire [NM*4-1:0] S_AXI_AWCACHE,
input wire [NM*3-1:0] S_AXI_AWPROT,
input wire [NM*4-1:0] S_AXI_AWQOS,
input wire [NM-1:0] S_AXI_AWVALID,
output wire [NM-1:0] S_AXI_AWREADY,
//
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,
input wire [NM-1:0] S_AXI_WLAST,
input wire [NM-1:0] S_AXI_WVALID,
output wire [NM-1:0] S_AXI_WREADY,
//
output wire [NM*C_AXI_ID_WIDTH-1:0] S_AXI_BID,
output wire [NM*2-1:0] S_AXI_BRESP,
output wire [NM-1:0] S_AXI_BVALID,
input wire [NM-1:0] S_AXI_BREADY,
// }}}
// Read slave channels from the controlling AXI masters
// {{{
input wire [NM*C_AXI_ID_WIDTH-1:0] S_AXI_ARID,
input wire [NM*C_AXI_ADDR_WIDTH-1:0] S_AXI_ARADDR,
input wire [NM*8-1:0] S_AXI_ARLEN,
input wire [NM*3-1:0] S_AXI_ARSIZE,
input wire [NM*2-1:0] S_AXI_ARBURST,
input wire [NM-1:0] S_AXI_ARLOCK,
input wire [NM*4-1:0] S_AXI_ARCACHE,
input wire [NM*3-1:0] S_AXI_ARPROT,
input wire [NM*4-1:0] S_AXI_ARQOS,
input wire [NM-1:0] S_AXI_ARVALID,
output wire [NM-1:0] S_AXI_ARREADY,
//
output wire [NM*C_AXI_ID_WIDTH-1:0] S_AXI_RID,
output wire [NM*C_AXI_DATA_WIDTH-1:0] S_AXI_RDATA,
output wire [NM*2-1:0] S_AXI_RRESP,
output wire [NM-1:0] S_AXI_RLAST,
output wire [NM-1:0] S_AXI_RVALID,
input wire [NM-1:0] S_AXI_RREADY,
// }}}
// Write channel master outputs to the connected AXI slaves
// {{{
output wire [NS*C_AXI_ID_WIDTH-1:0] M_AXI_AWID,
output wire [NS*C_AXI_ADDR_WIDTH-1:0] M_AXI_AWADDR,
output wire [NS*8-1:0] M_AXI_AWLEN,
output wire [NS*3-1:0] M_AXI_AWSIZE,
output wire [NS*2-1:0] M_AXI_AWBURST,
output wire [NS-1:0] M_AXI_AWLOCK,
output wire [NS*4-1:0] M_AXI_AWCACHE,
output wire [NS*3-1:0] M_AXI_AWPROT,
output wire [NS*4-1:0] M_AXI_AWQOS,
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_WLAST,
output wire [NS-1:0] M_AXI_WVALID,
input wire [NS-1:0] M_AXI_WREADY,
//
input wire [NS*C_AXI_ID_WIDTH-1:0] M_AXI_BID,
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,
// }}}
// Read channel master outputs to the connected AXI slaves
// {{{
output wire [NS*C_AXI_ID_WIDTH-1:0] M_AXI_ARID,
output wire [NS*C_AXI_ADDR_WIDTH-1:0] M_AXI_ARADDR,
output wire [NS*8-1:0] M_AXI_ARLEN,
output wire [NS*3-1:0] M_AXI_ARSIZE,
output wire [NS*2-1:0] M_AXI_ARBURST,
output wire [NS-1:0] M_AXI_ARLOCK,
output wire [NS*4-1:0] M_AXI_ARCACHE,
output wire [NS*4-1:0] M_AXI_ARQOS,
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_ID_WIDTH-1:0] M_AXI_RID,
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_RLAST,
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;
//
// OPT_SKID_INPUT controls whether the input skid buffers register
// their outputs or not. If set, all skid buffers will cost one more
// clock of latency. It's not clear that there's a performance gain
// to be had by setting this.
localparam [0:0] OPT_SKID_INPUT = 0;
//
// OPT_BUFFER_DECODER determines whether or not the outputs of the
// address decoder will be buffered or not. If buffered, there will
// be an extra (registered) clock delay on each of the A* channels from
// VALID to issue.
localparam [0:0] OPT_BUFFER_DECODER = 1;
//
// OPT_AWW controls whether or not a W* beat may be issued to a slave
// at the same time as the first AW* beat gets sent to the slave. Set
// to 1'b1 for lower latency, at the potential cost of a greater
// combinatorial path length
localparam OPT_AWW = 1'b1;
// }}}
////////////////////////////////////////////////////////////////////////
//
// Internal signal declarations and definitions
// {{{
////////////////////////////////////////////////////////////////////////
//
//
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] mwgrant;
reg [NM-1:0] mrgrant;
reg [NS-1:0] swgrant;
reg [NS-1:0] srgrant;
// verilator lint_off UNUSED
wire [LGMAXBURST-1:0] w_mawpending [0:NM-1];
wire [LGMAXBURST-1:0] wlasts_pending [0:NM-1];
wire [LGMAXBURST-1:0] w_mrpending [0:NM-1];
// verilator lint_on UNUSED
reg [NM-1:0] mwfull;
reg [NM-1:0] mrfull;
reg [NM-1:0] mwempty;
reg [NM-1:0] mrempty;
//
wire [LGNS-1:0] mwindex [0:NMFULL-1];
wire [LGNS-1:0] mrindex [0:NMFULL-1];
wire [LGNM-1:0] swindex [0:NSFULL-1];
wire [LGNM-1:0] srindex [0:NSFULL-1];
(* keep *) reg [NM-1:0] wdata_expected;
// The shadow buffers
wire [NMFULL-1:0] m_awvalid, m_arvalid;
wire [NMFULL-1:0] m_wvalid;
wire [NM-1:0] dcd_awvalid, dcd_arvalid;
wire [C_AXI_ID_WIDTH-1:0] m_awid [0:NMFULL-1];
wire [C_AXI_ADDR_WIDTH-1:0] m_awaddr [0:NMFULL-1];
wire [7:0] m_awlen [0:NMFULL-1];
wire [2:0] m_awsize [0:NMFULL-1];
wire [1:0] m_awburst [0:NMFULL-1];
wire [NMFULL-1:0] m_awlock;
wire [3:0] m_awcache [0:NMFULL-1];
wire [2:0] m_awprot [0:NMFULL-1];
wire [3:0] m_awqos [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 [NMFULL-1:0] m_wlast;
wire [C_AXI_ID_WIDTH-1:0] m_arid [0:NMFULL-1];
wire [C_AXI_ADDR_WIDTH-1:0] m_araddr [0:NMFULL-1];
wire [8-1:0] m_arlen [0:NMFULL-1];
wire [3-1:0] m_arsize [0:NMFULL-1];
wire [2-1:0] m_arburst [0:NMFULL-1];
wire [NMFULL-1:0] m_arlock;
wire [4-1:0] m_arcache [0:NMFULL-1];
wire [2:0] m_arprot [0:NMFULL-1];
wire [3:0] m_arqos [0:NMFULL-1];
//
//
reg [NM-1:0] berr_valid;
reg [IW-1:0] berr_id [0:NM-1];
//
reg [NM-1:0] rerr_none;
reg [NM-1:0] rerr_last;
reg [8:0] rerr_outstanding [0:NM-1];
reg [IW-1:0] rerr_id [0:NM-1];
wire [NM-1:0] skd_awvalid, skd_awstall;
wire [NM-1:0] skd_arvalid, skd_arstall;
wire [IW-1:0] skd_awid [0:NM-1];
wire [AW-1:0] skd_awaddr [0:NM-1];
wire [8-1:0] skd_awlen [0:NM-1];
wire [3-1:0] skd_awsize [0:NM-1];
wire [2-1:0] skd_awburst [0:NM-1];
wire [NM-1:0] skd_awlock;
wire [4-1:0] skd_awcache [0:NM-1];
wire [3-1:0] skd_awprot [0:NM-1];
wire [4-1:0] skd_awqos [0:NM-1];
//
wire [IW-1:0] skd_arid [0:NM-1];
wire [AW-1:0] skd_araddr [0:NM-1];
wire [8-1:0] skd_arlen [0:NM-1];
wire [3-1:0] skd_arsize [0:NM-1];
wire [2-1:0] skd_arburst [0:NM-1];
wire [NM-1:0] skd_arlock;
wire [4-1:0] skd_arcache [0:NM-1];
wire [3-1:0] skd_arprot [0:NM-1];
wire [4-1:0] skd_arqos [0:NM-1];
// Verilator lint_off UNUSED
reg [NSFULL-1:0] m_axi_awvalid;
reg [NSFULL-1:0] m_axi_awready;
reg [IW-1:0] m_axi_awid [0:NSFULL-1];
reg [7:0] m_axi_awlen [0:NSFULL-1];
reg [NSFULL-1:0] m_axi_wvalid;
reg [NSFULL-1:0] m_axi_wready;
reg [NSFULL-1:0] m_axi_bvalid;
reg [NSFULL-1:0] m_axi_bready;
// Verilator lint_on UNUSED
reg [1:0] m_axi_bresp [0:NSFULL-1];
reg [IW-1:0] m_axi_bid [0:NSFULL-1];
// Verilator lint_off UNUSED
reg [NSFULL-1:0] m_axi_arvalid;
reg [7:0] m_axi_arlen [0:NSFULL-1];
reg [IW-1:0] m_axi_arid [0:NSFULL-1];
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 [IW-1:0] m_axi_rid [0:NSFULL-1];
reg [DW-1:0] m_axi_rdata [0:NSFULL-1];
reg [NSFULL-1:0] m_axi_rlast;
reg [2-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;
reg [NM-1:0] bskd_valid;
reg [NM-1:0] rskd_valid, rskd_rlast;
wire [NM-1:0] bskd_ready;
wire [NM-1:0] rskd_ready;
wire [NMFULL-1:0] write_qos_lockout,
read_qos_lockout;
reg [NSFULL-1:0] slave_awready, slave_wready, slave_arready;
// }}}
// m_axi_* convenience signals (write side)
// {{{
always @(*)
begin
m_axi_awvalid = -1;
m_axi_awready = -1;
m_axi_wvalid = -1;
m_axi_wready = -1;
m_axi_bvalid = 0;
m_axi_bready = -1;
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;
m_axi_bready[NS-1:0] = M_AXI_BREADY;
for(iM=0; iM<NS; iM=iM+1)
begin
m_axi_awid[iM] = M_AXI_AWID[ iM*IW +: IW];
m_axi_awlen[iM] = M_AXI_AWLEN[ iM* 8 +: 8];
m_axi_bid[iM] = M_AXI_BID[iM* IW +: IW];
m_axi_bresp[iM] = M_AXI_BRESP[iM* 2 +: 2];
m_axi_rid[iM] = M_AXI_RID[ iM*IW +: IW];
m_axi_rdata[iM] = M_AXI_RDATA[iM*DW +: DW];
m_axi_rresp[iM] = M_AXI_RRESP[iM* 2 +: 2];
m_axi_rlast[iM] = M_AXI_RLAST[iM];
end
for(iM=NS; iM<NSFULL; iM=iM+1)
begin
m_axi_awid[iM] = 0;
m_axi_awlen[iM] = 0;
m_axi_bresp[iM] = INTERCONNECT_ERROR;
m_axi_bid[iM] = 0;
m_axi_rid[iM] = 0;
m_axi_rdata[iM] = 0;
m_axi_rresp[iM] = INTERCONNECT_ERROR;
m_axi_rlast[iM] = 1;
end
end
// }}}
// m_axi_* convenience signals (read side)
// {{{
always @(*)
begin
m_axi_arvalid = 0;
m_axi_arready = 0;
m_axi_rvalid = 0;
m_axi_rready = 0;
for(iM=0; iM<NS; iM=iM+1)
begin
m_axi_arlen[iM] = M_AXI_ARLEN[iM* 8 +: 8];
m_axi_arid[iM] = M_AXI_ARID[ iM*IW +: IW];
end
for(iM=NS; iM<NSFULL; iM=iM+1)
begin
m_axi_arlen[iM] = 0;
m_axi_arid[iM] = 0;
end
m_axi_arvalid[NS-1:0] = M_AXI_ARVALID;
m_axi_arready[NS-1:0] = M_AXI_ARREADY;
m_axi_rvalid[NS-1:0] = M_AXI_RVALID;
m_axi_rready[NS-1:0] = M_AXI_RREADY;
end
// }}}
// slave_*ready convenience signals
// {{{
always @(*)
begin
// These are designed to keep us from doing things like
// m_axi_*[m?index[N]] && m_axi_*[m?index[N]] && .. etc
//
// First, we'll set bits for all slaves--to include those that
// are undefined (but required by our static analysis tools).
slave_awready = -1;
slave_wready = -1;
slave_arready = -1;
//
// Here we do all of the combinatoric calculations, so the
// master only needs to reference one bit of this signal
slave_awready[NS-1:0] = (~M_AXI_AWVALID | M_AXI_AWREADY);
slave_wready[NS-1:0] = (~M_AXI_WVALID | M_AXI_WREADY);
slave_arready[NS-1:0] = (~M_AXI_ARVALID | M_AXI_ARREADY);
end
// }}}
////////////////////////////////////////////////////////////////////////
//
// Process our incoming signals: AW*, W*, and AR*
// {{{
////////////////////////////////////////////////////////////////////////
//
//
generate for(N=0; N<NM; N=N+1)
begin : W1_DECODE_WRITE_REQUEST
// {{{
wire [NS:0] wdecode;
// awskid, the skidbuffer for the incoming AW* channel
// {{{
skidbuffer #(
// {{{
.DW(IW+AW+8+3+2+1+4+3+4),
.OPT_OUTREG(OPT_SKID_INPUT)
// }}}
) awskid(
// {{{
S_AXI_ACLK, !S_AXI_ARESETN,
S_AXI_AWVALID[N], S_AXI_AWREADY[N],
{ S_AXI_AWID[N*IW +: IW], S_AXI_AWADDR[N*AW +: AW],
S_AXI_AWLEN[N*8 +: 8], S_AXI_AWSIZE[N*3 +: 3],
S_AXI_AWBURST[N*2 +: 2], S_AXI_AWLOCK[N],
S_AXI_AWCACHE[N*4 +: 4], S_AXI_AWPROT[N*3 +: 3],
S_AXI_AWQOS[N*4 +: 4] },
skd_awvalid[N], !skd_awstall[N],
{ skd_awid[N], skd_awaddr[N], skd_awlen[N],
skd_awsize[N], skd_awburst[N], skd_awlock[N],
skd_awcache[N], skd_awprot[N], skd_awqos[N] }
// }}}
);
// }}}
// wraddr, decode the write channel's address request to a
// particular slave index
// {{{
addrdecode #(
// {{{
.AW(AW), .DW(IW+8+3+2+1+4+3+4), .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_awid[N],
skd_awlen[N], skd_awsize[N], skd_awburst[N],
skd_awlock[N], skd_awcache[N], skd_awprot[N],
skd_awqos[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_awid[N], m_awlen[N], m_awsize[N],
m_awburst[N], m_awlock[N], m_awcache[N],
m_awprot[N], m_awqos[N]})
// }}}
);
// }}}
// wskid, the skid buffer for the incoming W* channel
// {{{
skidbuffer #(
// {{{
.DW(DW+DW/8+1),
.OPT_OUTREG(OPT_SKID_INPUT || OPT_BUFFER_DECODER)
// }}}
) wskid(
// {{{
S_AXI_ACLK, !S_AXI_ARESETN,
S_AXI_WVALID[N], S_AXI_WREADY[N],
{ S_AXI_WDATA[N*DW +: DW], S_AXI_WSTRB[N*DW/8 +: DW/8],
S_AXI_WLAST[N] },
m_wvalid[N], slave_waccepts[N],
{ m_wdata[N], m_wstrb[N], m_wlast[N] }
// }}}
);
// }}}
// slave_awaccepts
// {{{
always @(*)
begin
slave_awaccepts[N] = 1'b1;
// Cannot accept/forward a packet without a bus grant
// This handles whether or not write data is still
// pending.
if (!mwgrant[N])
slave_awaccepts[N] = 1'b0;
if (write_qos_lockout[N])
slave_awaccepts[N] = 1'b0;
if (mwfull[N])
slave_awaccepts[N] = 1'b0;
// Don't accept a packet unless its to the same slave
// the grant is issued for
if (!wrequest[N][mwindex[N]])
slave_awaccepts[N] = 1'b0;
if (!wgrant[N][NS])
begin
if (!slave_awready[mwindex[N]])
slave_awaccepts[N] = 1'b0;
end else if (berr_valid[N] && !bskd_ready[N])
begin
// Can't accept an write address channel request
// for the no-address-mapped channel if the
// B* channel is stalled, lest we lose the ID
// of the transaction
//
// !berr_valid[N] => we have to accept more
// write data before we can issue BVALID
slave_awaccepts[N] = 1'b0;
end
end
// }}}
// slave_waccepts
// {{{
always @(*)
begin
slave_waccepts[N] = 1'b1;
if (!mwgrant[N])
slave_waccepts[N] = 1'b0;
if (!wdata_expected[N] && (!OPT_AWW || !slave_awaccepts[N]))
slave_waccepts[N] = 1'b0;
if (!wgrant[N][NS])
begin
if (!slave_wready[mwindex[N]])
slave_waccepts[N] = 1'b0;
end else if (berr_valid[N] && !bskd_ready[N])
slave_waccepts[N] = 1'b0;
end
// }}}
reg r_awvalid;
always @(*)
begin
r_awvalid = dcd_awvalid[N] && !mwfull[N];
wrequest[N]= 0;
if (!mwfull[N])
wrequest[N][NS:0] = wdecode;
end
assign m_awvalid[N] = r_awvalid;
// QOS handling via write_qos_lockout
// {{{
if (!OPT_QOS || NM == 1)
begin : WRITE_NO_QOS
// If we aren't using QOS, then never lock any packets
// out from arbitration
assign write_qos_lockout[N] = 0;
end else begin : WRITE_QOS
// Lock out a master based upon a second master having
// a higher QOS request level
// {{{
reg r_write_qos_lockout;
initial r_write_qos_lockout = 0;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN)
r_write_qos_lockout <= 0;
else begin
r_write_qos_lockout <= 0;
for(iN=0; iN<NM; iN=iN+1)
if (iN != N)
begin
if (m_awvalid[N]
&&(|(wrequest[iN][NS-1:0]
& wdecode[NS-1:0]))
&&(m_awqos[N] < m_awqos[iN]))
r_write_qos_lockout <= 1;
end
end
assign write_qos_lockout[N] = r_write_qos_lockout;
// }}}
end
// }}}
end for (N=NM; N<NMFULL; N=N+1)
begin : UNUSED_WSKID_BUFFERS
// {{{
// The following values are unused. They need to be defined
// so that our indexing scheme will work, but indexes should
// never actually reference them
assign m_awid[N] = 0;
assign m_awaddr[N] = 0;
assign m_awlen[N] = 0;
assign m_awsize[N] = 0;
assign m_awburst[N] = 0;
assign m_awlock[N] = 0;
assign m_awcache[N] = 0;
assign m_awprot[N] = 0;
assign m_awqos[N] = 0;
assign m_awvalid[N] = 0;
assign m_wvalid[N] = 0;
//
assign m_wdata[N] = 0;
assign m_wstrb[N] = 0;
assign m_wlast[N] = 0;
assign write_qos_lockout[N] = 0;
// }}}
// }}}
end endgenerate
// Read skid buffers and address decoding, slave_araccepts logic
generate for(N=0; N<NM; N=N+1)
begin : R1_DECODE_READ_REQUEST
// {{{
reg r_arvalid;
wire [NS:0] rdecode;
// arskid
// {{{
skidbuffer #(
// {{{
.DW(IW+AW+8+3+2+1+4+3+4),
.OPT_OUTREG(OPT_SKID_INPUT)
// }}}
) arskid(
// {{{
S_AXI_ACLK, !S_AXI_ARESETN,
S_AXI_ARVALID[N], S_AXI_ARREADY[N],
{ S_AXI_ARID[N*IW +: IW], S_AXI_ARADDR[N*AW +: AW],
S_AXI_ARLEN[N*8 +: 8], S_AXI_ARSIZE[N*3 +: 3],
S_AXI_ARBURST[N*2 +: 2], S_AXI_ARLOCK[N],
S_AXI_ARCACHE[N*4 +: 4], S_AXI_ARPROT[N*3 +: 3],
S_AXI_ARQOS[N*4 +: 4] },
skd_arvalid[N], !skd_arstall[N],
{ skd_arid[N], skd_araddr[N], skd_arlen[N],
skd_arsize[N], skd_arburst[N], skd_arlock[N],
skd_arcache[N], skd_arprot[N], skd_arqos[N] }
// }}}
);
// }}}
// Read address decoder
// {{{
addrdecode #(
// {{{
.AW(AW), .DW(IW+8+3+2+1+4+3+4), .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_arid[N],
skd_arlen[N], skd_arsize[N], skd_arburst[N],
skd_arlock[N], skd_arcache[N], skd_arprot[N],
skd_arqos[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_arid[N], m_arlen[N], m_arsize[N],
m_arburst[N], m_arlock[N], m_arcache[N],
m_arprot[N], m_arqos[N]})
// }}}
);
// }}}
always @(*)
begin
r_arvalid = dcd_arvalid[N] && !mrfull[N];
rrequest[N] = 0;
if (!mrfull[N])
rrequest[N][NS:0] = rdecode;
end
assign m_arvalid[N] = r_arvalid;
// slave_raccepts decoding
// {{{
always @(*)
begin
slave_raccepts[N] = 1'b1;
if (!mrgrant[N])
slave_raccepts[N] = 1'b0;
if (read_qos_lockout[N])
slave_raccepts[N] = 1'b0;
if (mrfull[N])
slave_raccepts[N] = 1'b0;
// If we aren't requesting access to the channel we've
// been granted access to, then we can't accept this
// verilator lint_off WIDTH
if (!rrequest[N][mrindex[N]])
slave_raccepts[N] = 1'b0;
// verilator lint_on WIDTH
if (!rgrant[N][NS])
begin
if (!slave_arready[mrindex[N]])
slave_raccepts[N] = 1'b0;
end else if (!mrempty[N] || !rerr_none[N] || rskd_valid[N])
slave_raccepts[N] = 1'b0;
end
// }}}
// Read QOS logic
// {{{
// read_qos_lockout will get set if a master with a higher
// QOS number is requesting a given slave. It will not
// affect existing outstanding packets, but will be used to
// prevent further packets from being sent to a given slave.
if (!OPT_QOS || NM == 1)
begin : READ_NO_QOS
// If we aren't implementing QOS, then the lockout
// signal is never set
assign read_qos_lockout[N] = 0;
end else begin : READ_QOS
// {{{
// We set lockout if another master (with a higher
// QOS) is requesting this slave *and* the slave
// channel is currently stalled.
reg r_read_qos_lockout;
initial r_read_qos_lockout = 0;
always @(posedge S_AXI_ACLK)
if (!S_AXI_ARESETN)
r_read_qos_lockout <= 0;
else begin
r_read_qos_lockout <= 0;
for(iN=0; iN<NM; iN=iN+1)
if (iN != N)
begin
if (m_arvalid[iN]
&& !slave_raccepts[N]
&&(|(rrequest[iN][NS-1:0]
& rdecode[NS-1:0]))
&&(m_arqos[N] < m_arqos[iN]))
r_read_qos_lockout <= 1;
end
end
assign read_qos_lockout[N] = 0;
// }}}
end
// }}}
end for (N=NM; N<NMFULL; N=N+1)
begin : UNUSED_RSKID_BUFFERS
// {{{
assign m_arvalid[N] = 0;
assign m_arid[N] = 0;
assign m_araddr[N] = 0;
assign m_arlen[N] = 0;
assign m_arsize[N] = 0;
assign m_arburst[N] = 0;
assign m_arlock[N] = 0;
assign m_arcache[N] = 0;
assign m_arprot[N] = 0;
assign m_arqos[N] = 0;
assign read_qos_lockout[N] = 0;
// }}}
// }}}
end endgenerate
// }}}
////////////////////////////////////////////////////////////////////////
//
// Channel arbitration
// {{{
////////////////////////////////////////////////////////////////////////
//
//
// wrequested
// {{{
always @(*)
begin : W2_DECONFLICT_WRITE_REQUESTS
for(iN=0; iN<=NM; iN=iN+1)
wrequested[iN] = 0;
// Vivado may complain about too many bits for wrequested.
// This is (currrently) expected. mwindex is used to index
// into wrequested, and mwindex 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 they are defined.
// Therefore, no matter what mwindex 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] && (!mwgrant[iN-1]||mwempty[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 : R2_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] && (!mrgrant[iN-1] || mrempty[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];