-
Notifications
You must be signed in to change notification settings - Fork 1
/
writeup.tex
2095 lines (1652 loc) · 87.9 KB
/
writeup.tex
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
\documentclass[10pt]{report}
\usepackage{fullpage}
\usepackage{times}
\usepackage{amsmath,proof,amsthm,amssymb,color}
%\usepackage{multicol}
\usepackage{float}
\usepackage{graphicx}
\usepackage{parskip}
\floatstyle{boxed}
\restylefloat{figure}
\usepackage{hyperref}
\usepackage{listings}
%\usepackage[all]{hypcap}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{1}
\title{{\Huge virtexsquared:}\\an ARM-like System-on-Chip on an FPGA}
\author{Joshua Wise\\
\texttt{$<$jwise@andrew.cmu.edu$>$} \and
Josiah Boning\\
\texttt{$<$jboning@andrew.cmu.edu$>$} \and
Bradley Yoo\\
\texttt{$<$bjy@andrew.cmu.edu$>$}}
\begin{document}
\maketitle
\begin{abstract}
The authors provide a report on the completed development of an ARM-like
System-on-Chip built on a Xilinx Virtex-5 FPGA. A high-level overview of
the design is provided, as well as detailed examinations of various
submodules within the system. An examination of both the hardware and
software stack is provided, and the authors take a moment to reflect.
\end{abstract}
\tableofcontents
\chapter{Introduction}
In fulfillment of the 18-545 Advanced Digital Design Capstone, this group
designed and implemented a System on a Chip on an FPGA, based around a small
ARM-like core. The system is built around two memory buses, and contains
I/O cores to interface with a smattering of peripherals, including:
\begin{itemize}
\item{DVI/VGA output from Chrontel CH7301C, for which video is cached in a
framebuffer in main memory;}
\item{RS-232 serial output;}
\item{AC'97 audio with Analog AD1981B, for which audio to be output is cached in a
a simple main memory buffer;}
\item{PS/2 keyboard input;}
\item{CompactFlash via the Xilinx SystemACE controller;}
\item{and main memory via a DDR2 SODIMM, for which interface glue is
provided using Xilinx's predesigned Memory Interface Generator (MIG) IP.}
\end{itemize}
The system contains various non-I/O cores to provide additional functionality,
including:
\begin{itemize}
\item{a cycle counter for precise application timing;}
\item{a preloader to load the initial bootstrap into RAM;}
\item{and memory set and image blit accelerators.}
\end{itemize}
A primary goal of this peripheral layer is to be reused in 18-447; the system
is designed to be simple to interface with from a core perspective, and
hence usable for students in an introductory computer architecture class.
The core, in particular, has a moderate \textit{anti}-goal of high
performance.
The system has been implemented over the course of the Fall 2010 semester to
the point of successfully executing a small rhythm game that shows off the
system's ability to render video in real time and the capability to
synchronize keyboard input with video and audio output; this completes the
original goal.
\chapter{Hardware Design}
\label{par:hardware}
In this part, we provide an overview of the design and implementation
decisions involved in the \textit{hardware} part of the system. As a whole,
this section corresponds to the \texttt{rtl/} directory in the top level
source repository; the astute reader may follow along within.
\section{Memory Architecture}
\label{sec:memory}
The system, as a whole, is partitioned into two major access paths -- the
FSAB (\textit{Fast System Access Bus}), and the SPAM Bus (\textit{Slow
Peripheral Access Memory} Bus). These two buses were designed to meet
wildly differing goals; the FSAB is designed for high-bandwidth, cachable
transactions, whereas the SPAMBus is designed for configuration space
register (CSR) accesses. Ideally, most of the system's traffic will occur
over the FSAB.
\begin{figure}
\centering
\includegraphics[width=.8\textwidth]{block_diagram.pdf}
\caption{High-level system diagram. A red square in the corner of a module
indicates a module where a ChipScope ILA is present and can easily
be enabled.}
\label{system_diagram}
\end{figure}
\subsection{Fast System Access Bus}
\label{sec:fsab}
The FSAB is a transaction-oriented bus designed primarily for accessing high-
latency memories such as DRAMs. The vast majority of the memory accesses on
the system during normal operation (i.e., not at boot/ configuration time)
will happen via the FSAB.
\subsubsection{Terminology}
The FSAB works in terms of `transactions'. A read transaction shall consist
of the `read request', and `read data' phases. A write transaction shall
consist only of the `write data' phase.
Devices attached to the FSAB are classified as `masters' and `slaves'; a
device that initiates transactions (reads and writes to main memory) is a
master, and a device that completes transactions is a slave.
At times, it may be useful to discuss directions on the FSAB. For the purposes
of this discussion, data that is traveling from a master to a slave is
considered `outbound' (and so signals for that purpose will begin with fsabo);
similarly, data that initiates at the slave and returns to a master is
considered `inbound' (and so signals for that purpose will begin with fsabi).
\subsubsection{Conceptual Overview}
virtexsquared, in its first incarnation, will only have a single memory
controller. For that reason, the FSAB will be defined to have only one slave
device - but since many peripherals may wish to do DMA access to or from main
memory, the FSAB will be defined to potentially have many masters. The fact
that only one slave device exists shall not be extensively exploited in either
the design or implementation of the FSAB, since at a later time, a second
memory controller may be interesting.
Since many memory controllers are capable of handling multiple pipelined
requests, the FSAB supports multiple transactions in flight at a time. The
slave will arbitrate these requests with a debit-credit system. Similarly,
contention between masters will be resolved with an arbiter module that also
performs queueing and debit-credit arbitration. In this regard, the bus
arbiter should be ``invisible'' to a master; the debit-credit system should be
interface-identical as if the master were talking directly to the slave.
Most operations that peripherals on the FSAB will perform will be in similar
sizes. For instance, the I\$ and D\$ will always read sizes of a single cache
line; the TLB will generally read page directory entries at a time; and the
framebuffer will generally load half a FIFO's worth or so at a time. The
general case, anyway, will not be a read of a single word. Similarly, writes
will often be localized to each other. To facilitate this, each FSAB
transaction will have a count of words up to a defined maximum of 8 along with
the command and address. Inside each transaction, the address being written to
shall autoincrement with each datum sent. Since not every datum may be
interesting for a write, a ``write mask'' is also sent with every word written.
Since masters are isolated from each other by one or more arbiters, it is
generally not possible for one master to know what another master is doing.
Lacking any other form of cache coherency protocols (such as MOESI), a
system based around the FSAB is not cache-coherent! This means that the
applications programmer must take extra care to make sure that all data is
synchronized to main memory before allowing another peripheral to access
said data. (For instance, if the programmer wishes to write new data to the
frame buffer before flipping pages, he must cause the CPU to clean that
cache line by some mechanism first. In the current implementation, the data
cache is implemented as being write-through, so no such synchronization
issue takes place.)
The bus protocol is designed to be easy to implement by a DRAM-based slave.
For that reason, the length of a read or write request is limited not just by
the maximum, but by the alignment of the request. That is to say, if a request
is only aligned to a four-qword boundary, but not to an eight-qword boundary,
then the maximum size of the request is four qwords; a request of five or more
qwords results in undefined behavior. (On the current DRAM-backed
implementation, the resulting data comes from wrapping around the row buffer;
on the current simulation-backed implementation, the resulting data comes from
subsequent linear addresses.)
\subsubsection{Design Overview: Portlist}
A FSAB master has the following ports outbound:
\begin{lstlisting}[basicstyle=\footnotesize,language=Verilog]
output fsabo_valid;
output [FSAB_REQ_HI:0] fsabo_mode;
output [FSAB_DID_HI:0] fsabo_did;
output [FSAB_DID_HI:0] fsabo_subdid;
output [FSAB_ADDR_HI:0] fsabo_addr;
output [FSAB_LEN_HI:0] fsabo_len;
output [FSAB_DATA_HI:0] fsabo_data;
output [FSAB_MASK_HI:0] fsabo_mask;
input fsabo_credit;
\end{lstlisting}
A FSAB master has the following ports inbound:
\begin{lstlisting}[basicstyle=\footnotesize,language=Verilog]
input fsabi_valid;
input [FSAB_DID_HI:0] fsabi_did;
input [FSAB_DID_HI:0] fsabi_subdid;
input [FSAB_DATA_HI:0] fsabi_data;
\end{lstlisting}
No debit output (or input) is needed; a debit occurs implicitly when a new
FSAB transaction is begun. The credit input is always considered valid, even
if the inbound valid flag is not set.
\subsubsection{Design Overview: Transaction Specifics}
Transactions are defined by a start packet (and potentially additional data
packets) being sent to a slave, and the slave responding with any necessary
data packets. The slave may pipeline transactions as much as it is able
(credits can be returned before the slave has responded), but the slave
shall never reorder transactions. (Doing so would result in indeterminate
behavior with reads after writes, among other things.)
A start packet shall consist of the valid bit being set, the mode flag being
set to either FSAB\_READ or FSAB\_WRITE, the did/subdid set to the appropriate
values, an address, a length, and the first word of data and mask, should
they be valid for the current operation. Once a transaction is being sent
outbound, it shall not be interrupted by another transaction; the next data
packets are always part of this transaction. (For this reason, a master
should attempt to send packets as quickly as possible; excessive delay
between subsequent assertion of the valid flag may result in poor bus
performance.) In subsequent data packets, all control flags (i.e., all but
valid, data, and mask) are ignored.
The debit/credit system shall count each transaction as a debit, not each
word. Another transaction may be sent immediately after the credit flag is
asserted (or the credit may be queued).
The did field of each transaction shall be set as per each master's DID
assignment. The subdid may be set according to any internal state that the
master needs to track.
Some attention should be given to the mechanisms of clock distribution. In
particular, it is permissible (and indeed often the case) that the inbound FSAB
and outbound FSAB buses may be on different clock domains; usually the inbound
FSAB clock comes directly from the slave, but the outbound FSAB clock is
synchronous with the logic from the driving module. The outbound FSAB interface
is then synchronized to the slave's clock in the arbiter. \footnote{This may be
considered a bug, as it departs from the conceptual goal that the bus arbiter
is invisible to the master. From this perspective, it is preferable to have all
portions of the FSAB on the same clock domain, i.e. the slave's.}
\subsubsection{Known implementations}
The following are known implementations of the FSAB specification:
\begin{figure}
\centering
\includegraphics[width=0.85\textwidth]{FSAB-IxFIF.pdf}
\caption{Clocking for memory controller.} \label{fsabixfif}
\end{figure}
\begin{itemize}
\item{Caches}
\item{Memory Controller}
\item{Arbiter}
\item{DMA Controller}
\end{itemize}
\subsection{Slow Peripheral Access Memory}
\label{sec:spam}
The SPAM bus is a word-oriented one-access-at-a-time bus designed primarily
for accessing configuration space registers (CSRs) on peripherals.
\subsubsection{Conceptual Overview}
In theory, all peripherals on the system will be matching and decoding on
the SPAM bus; when the processor does a SPAM-bus access, it is almost
certainly the case that a device will respond. So, the bus should be
optimized for the common case in which a device responds shortly after a
request is sent. Similarly, it should be the case that only one device ever
matches, so the bus need not be arbitrated between them; a simple OR'ing of
responses should work.
No peripheral should need to access any other peripheral's CSRs; any such
accesses from a debug interface should be multiplexed in between the CPU and
the SPAM-bus. As such, the master-slave relationship in the SPAM-bus is
exactly the opposite of what it is on the FSAB; there is only one SPAM-bus
master, and there can be many SPAM-bus slaves. Again, this property should
not be extensively exploited, but it is the case in the current
implementation.
Requests on the SPAM-bus should ordinarily be low latency, but there may be
need for wait states for various reasons. For instance, if the other
peripheral is far away on the die, it may take an extra clock to compute the
appropriate response for a read. A write, perhaps, may block until some
(short) action is complete. There may also be a need to block because the
target peripheral is in a different clock domain, and a synchronizer needs
to shift the data over.
If no peripheral answers by deasserting busy\_b within a reasonable number
of cycles (usually 256), the request is deemed to have timed out, and a read
should return a value indicating that (usually something along the lines of
0xDEADDEAD).
\subsubsection{Design Overview: Portlist}
The processor has the following ports outbound:
\begin{lstlisting}[basicstyle=\footnotesize,language=Verilog]
output spamo_valid;
output spamo_r_nw;
output [SPAM_DID_HI:0] spamo_did;
output [SPAM_ADDR_HI:0] spamo_addr;
output [SPAM_DATA_HI:0] spamo_data;
\end{lstlisting}
The processor has the following ports inbound:
\begin{lstlisting}[basicstyle=\footnotesize,language=Verilog]
input cio__spami_busy_b;
input [SPAM_DATA_HI:0] cio__spami_data;
\end{lstlisting}
\subsubsection{Design Overview: Lifecycle of a request}
A request begins by the processor asserting the valid flag and specifying
the rest of the fields. This happens for exactly one cycle. Some time later
(potentially even on the same cycle), a device may assert the busy\_b flag
for one cycle to indicate that the request has been filled. Inbound data
shall be valid on the same cycle.
No new request shall be specified until either a previous request has returned,
or a previous request has timed out. A request shall time out after no fewer
than 128 cycles; the current DCache implementation times out after 256 cycles.
When a device is not specifying data inbound, it shall drive its output port to
zero; this allows the bus to simply OR together all responses.
Since the SPAM bus is always on the core's clock domain, some synchronization
may be needed for CSRs on a different clock domain. Standard modules have been
provided to synchronize reads and writes; for more information on those, see
the documentation for the CSRAsync modules in section \ref{sec:csrasync}.
\section{Core Microarchitecture}
As part of the virtexsquared system, the core must conform to the defined
bus protocols on the external interface (see section \ref{sec:memory}); but
within the core itself, anything goes. Although the ARM core will not be
reused in future projects, the caches and global interface will be, and
hence potentially merit discussion.
\subsection{ARM Core}
The ARM core consists of the register file, fetch, decode, issue, execute,
memory, and the writeback units based off of Joshua's early FireARM core.
None of them are any good, and hence no more of them will be mentioned.
\subsection{Caches}
The caches each have a latency of one cycle. Upon missing, they send
requests for fills to the FSAB arbiter, which in turn propagates up to the
main memory. The caches have a zero-cycle latency for whether they have
missed; that is to say, the lookup takes place on the same cycle. In
addition to the standard FSAB connections, the Icache's port list is as
such:
\begin{lstlisting}[basicstyle=\footnotesize,language=Verilog]
input [31:0] ic__rd_addr_0a;
input ic__rd_req_0a;
output ic__rd_wait_0a;
output [31:0] ic__rd_data_1a;
\end{lstlisting}
and the Dcache's port list is as such: (excluding SPAM and FSAB connections)
\begin{lstlisting}[basicstyle=\footnotesize,language=Verilog]
input [31:0] dc__addr_3a;
input dc__rd_req_3a;
input dc__wr_req_3a;
output dc__rw_wait_3a;
input [31:0] dc__wr_data_3a;
output [31:0] dc__rd_data_4a;
\end{lstlisting}
The Icache and Dcache differ in two important ways. To wit:
\begin{itemize}
\item{The Icache is multi-way set associative. The number of ways is
controlled through a parameter. With the current Dcache architecture, this
is not feasible (due to the nature of writes).}
\item{The Dcache has a SPAM interface. The Icache cannot, because the SPAM
is single-master.}
\end{itemize}
Beyond these differences, though, the Icache and Dcache are very similar
internally. Both modules have two clock domains (the core clock and the FSAB
clock); data is received back inbound on the FSAB clock, and the core is
serviced on the core clock. Synchronization is performed internally in the
form of a read and write request service flag, similar to the internals of
the synchronizers.
\section{FSAB Internal Mechanisms}
\label{sec:fsabinternal}
Although the FSAB (described in the high level memory system overview; see
section \ref{sec:memory}) is conceptually simple, there are a few specific
portions of it that merit further explanation. In particular, the system's
instruction cache is capable of reading only from the FSAB, leaving the
problem of how to bootstrap the system; and the FSAB specification makes no
mention of the mechanics of multiplexing multiple FSAB masters onto one bus.
These issues are solved, respectively, by the FSAB Preloader and the FSAB
Arbiter.
\subsection{Preloader}
\label{sec:preloader}
In order to boot the system, instructions must first be somehow loaded into
memory, since the instruction cache is not capable of fetching from an
alternative non-volatile source. A few alternative options for this were
considered, and ultimately rejected. In brief, we considered:
\begin{itemize}
\item{adding an alternate path to the instruction cache during boot. This
was rejected, since it would add a potentially substantial amount of logic
to the critical path.}
\item{adding a SPAM interface to the instruction cache. This was rejected,
since the SPAM bus is not nominally capable of multi-master support, and
adding an arbitration mechanism would be necessary, which the protocol does
not easily support.}
\item{modifying the reset value for the instruction cache. This was rejected
since the code size available would be very limited, and support within
synthesis tools would be likely to be poor.}
\item{adding a second, non-volatile, slave to the FSAB. This was rejected
since the bus's architecture was mostly in place already, and a redesign to
support that would prove difficult in light of the requirement that
transactions return in order.}
\item{adding a preloader as an FSAB master. This was ultimately accepted.}
\end{itemize}
The preloader loads boot0, which is the first running software on the
system, into main memory. (For more details about the boot sequence, see
section \ref{sec:boot}.) It acts as a simple FSAB master, with one
additional output - it has a mechanism to hold the CPU core in reset. Since
it never does any reads, it has no fsabi interface; it only does size-8
writes to incrementing addresses. Once DRAM has successfully been loaded,
the preloader has no function. The data that it loads is stored in a ROM
that is implemented as a BRAM on an FPGA and as a simple ROM in simulation;
it is both synthesizable and simulatable.
The ROM for the preloader is compiled in from a \texttt{\$readmemh}
statement. In synthesis, it is copied in during the build process (see
section \ref{sec:build}) from \texttt{sw/boot0/boot0.pad.hex64}; in
simulation, it is copied in from \texttt{tests/testbench.pad.hex64}. These
are generated by a combination of \texttt{xxd} and \texttt{dd} during
software build.
\subsection{Arbiter}
\label{sec:arbiter}
Since the FSAB is a multimaster system, but the slave memory module has only
one master memory interface, there must be a multiplexing module to issue
requests in sequence to the slave memory. In the system, this module is
called the FSABArbiter; it has a parameterizable number of fsabo ports as
inputs, and a single fsabo port as an output. Given the debit/credit
system, not every request needs to be immediately dispatched to the slave
memory; indeed, each fsabo virtual-slave in the arbiter has a built in FIFO
(see section \ref{sec:fifo}) to buffer requests.
The buffer on the receiving end of each fsabo master also functions as a
clock domain synchronizer; by using the asynchronous FIFO, fsabo packets can
be safely transitioned from any system clock domain to the DRAM's clock
domain. Each buffer has, as a basic interface, a signal from the main
arbiter to begin outputting a transaction to the slave (if one is
available), and a signal to the main arbiter reporting completion of the
current transaction. (This may take zero cycles, if no transaction was
available, or it may take up to eight cycles, in the case of a
maximum-length write.)
The top-level arbiter makes no attempt at providing fairness between
peripherals. The original goal was to include support for fairness, but it
was later discovered that doing so would require adding substantial logic to
the system, and potentially for \textit{negative} benefit; guaranteeing
bandwidth to the framebuffer and AC'97 proves to be invaluable in the face
of a high-bandwidth fill component that could potentially cause the
framebuffer's DMA engine to underrun.
\subsubsection{Interface}
Some mention should be given to the portlist, and how that is managed. Since
arrays of bitfields (i.e., two-dimensional bitfields) cannot be passed in
through a portlist in Verilog, all signals from the masters are concatenated
together into inputs of parameterized width. Internally, this looks somewhat
like this:
\begin{lstlisting}[basicstyle=\footnotesize,language=Verilog]
...
input [(FSAB_DEVICES*(FSAB_DATA_HI+1))-1:0]
fsabo_datas;
...
\end{lstlisting}
Keeping all of the input signals synchronized and ordered, though,
especially in the face of the need for adding and removing new types of
modules quickly, sometimes proved difficult. To maintain our sanity in the
top-level module, we employed verilog-mode's \texttt{AUTOLISP} extensions along with
a small chunk of code provided to us by Michael Arntzenius. This prefixer
module is used as part of an \texttt{AUTO\_TEMPLATE}, as shown:
\begin{lstlisting}[basicstyle=\footnotesize,language=Verilog]
/*AUTO_LISP(setq list-of-prefixes '("pre" "fb"
"audio" "ic" "dc" "accel_clear"))*/
...
/* FSABArbiter AUTO_TEMPLATE (
...
.fsabo_valids(@"(template
\"__fsabo_valid\")"),
.fsabo_modes(@"(template
\"__fsabo_mode[FSAB_REQ_HI:0]\")"),
.fsabo_dids(@"(template
\"__fsabo_did[FSAB_DID_HI:0]\")"),
\end{lstlisting}
When verilog-mode re-templates when \texttt{make auto} is run, all
instantiated ports in the arbiter will be automatically updated. It is
important to note that the wire arrays \texttt{fsabo\_clks} and
\texttt{fsabo\_rst\_bs} must also be updated when a new device is added to the
\texttt{list-of-prefixes}; failing to do so will result in five hour long
debug sessions. The arbiter assigns priority to incoming transactions based
on the order of the \texttt{list-of-prefixes}; that is to say, in the above
example, the preloader takes all available bandwidth before the framebuffer,
which takes remaining bandwidth before the AC'97 controller, etc. The
screen-clear accelerator takes bandwidth \textit{last}, because it would otherwise
starve the rest of the system for bandwidth.
\section{Memory Controller}
\label{sec:memorycontroller}
In the virtexsquared memory system (see section \ref{sec:memory}), the
memory controller is the sole client on the FSAB. The memory controller
acts as an intermediary between the FSAB and the coregen-produced Memory
Interface Generator (MIG).
\subsection{Interfaces}
On the side facing the FSAB and the rest of the virtexsquared system, the
memory controller behaves as a slave as specified in the FSAB specification
(see section \ref{sec:fsab}).
On the side facing the MIG, the memory controller behaves as specified in
the Xilinx Memory Interface Generator documentation.
\subsection{Implementation}
\begin{figure}
\centering
\includegraphics[width=0.85\textwidth]{FSABMemory.pdf}
\caption{Internals of the memory controller.} \label{fig:fsabmemory}
\end{figure}
The memory controller is best described by tracing the lifetime of a request
as it is made on the FSAB, passes through the memory controller and MIG, and
is returned to the requesting device. At the first packet of the request,
the device identifiers, address, and length are stored in the request info
FIFO. If the request is a write request, the controller reads packets of
data into the data FIFO until the entire request is stored in the FIFO. Each
entry in the data FIFO is two packets wide; the MIG requires data to be
double-wide to facilitate DDR memory. If a write request is not aligned, the
controller inserts a packet's worth of masked data at the front of the
request.
Once the entire transaction has been stored in the FIFOs, the controller
sends it to the MIG. The MIG performs burst operations of a standard length
(in the current implementation, 8 words of 64 bits each; because the memory
is DDR, it takes four clock cycles to transmit or receive a burst). The
request begins with a write to the MIG address and command FIFOs. On a write
request, the first write to the data and mask FIFOs is in the same clock
cycle, and the rest of the burst follows on consecutive cycles. If the
actual request is shorter than the burst length, masked data is written for
the remainder of the burst. On a read request, the device identifier and
request length are stored in the output request info FIFO.
On a read request, some time after sending the request to the MIG, the MIG
will send data back. This data is read into the output data FIFO. When the
data FIFO becomes not empty, the controller reads the device identifier and
length from the request FIFO and the first row from the data FIFO. Data is
returned to the device, with reads from the double-width FIFO every two
packets, until the full length has been transmitted.
\subsection{Known Bugs}
\begin{itemize}
\item{Reads not aligned to whatever boundary the MIG wants are incorrect
(the address is not stored in the output-side request info FIFO, so the
output side has no way to know that the first data the MIG returns is not
the requested data).}
\item{Reads not of the full burst length may mess everything up, since I
don't think we discard the rest of the data the MIG returns in its burst.}
\end{itemize}
\section{Synchronization Mechanisms}
\label{sec:sync}
Within virtexsquared, there are two ``utility'' modules that are commonly
used for synchronizing across clock domain boundaries -- the CSR
synchronizers, and the async FIFO.
\subsection{CSR Synchronizers}
\label{sec:csrasync}
\subsubsection{Motivation and Design Overview}
Since the virtexsquared system has many peripherals on different clock
domains, it only makes sense to have a unified mechanism of synchronizing
SPAM accesses between those domains and the core. Synchronization logic is
not only difficult to write, but it is also difficult to verify the
correctness of; to that end, by encapsulating the synchronization mechanisms
as much as possible, we stand a much better chance of writing correct code.
The Configuration Space Register (CSR) synchronizers are one of two primary
mechanisms for synchronization; for the other, see the AsyncFifo
implementation in section \ref{sec:fifo}.
It was decided early on that CSRAsyncRead and CSRAsyncWrite should be two
different modules, and that there should be no CSRAsyncReadWrite module.
Since the registers that the CSR interfaces mirror are usually primarily
controlled by the peripheral's internal logic, holding register state inside
a ReadWrite module would result in vastly unnecessary complexity, and would
substantially obscure the intent of the logic in the peripheral. (Indeed,
often the resulting state of the register after a write operation is not the
same as the data that was written.)
The CSRAsyncRead and CSRAsyncWrite modules are designed to closely mirror
the SPAM bus protocol; for many uses, the CPU side (on the cclk domain) can
be directly or'ed in on the SPAM bus to implement a peripheral's CSR space.
The target side (on the tclk domain) was designed to produce single cycle
strobes that can be effectively used by a target's internal logic to trigger
updates.
\subsubsection{Interface}
The CSRAsyncRead and CSRAsyncWrite modules are parameterized across the
width of the register that they are synchronizing; the CSRAsyncWrite module
is also parameterized for its reset value. Both modules have two clock
inputs, and their corresponding negated resets -- \texttt{cclk} is the clock
corresponding to the CPU core that initiates a request, and \texttt{tclk} is
the clock corresponding to the target peripheral. All ports are suffixed
with the clock domain on which they live (i.e., \texttt{rst\_b\_cclk} and
\texttt{rst\_b\_tclk}).
Both modules have the same core port structure for synchronizing between the
two domains; the only difference in their portlist is in direction on the
data port. The portlist for the read module is as such:
\begin{lstlisting}[basicstyle=\footnotesize,language=Verilog]
input rd_strobe_cclk;
output [(WIDTH-1):0] rd_data_cclk;
output rd_wait_cclk;
output rd_done_strobe_cclk;
output rd_strobe_tclk;
input [(WIDTH-1):0] rd_data_tclk;
\end{lstlisting}
This provides for a relatively straightforward mechanism for interfacing
with the SPAM bus. For example, the following code for reading a counter was
taken from the blit accelerator:
\begin{lstlisting}[basicstyle=\footnotesize,language=Verilog]
wire [30:0] rd_data_WRDONE;
wire rd_done_strobe_WRDONE;
CSRAsyncRead #(.WIDTH(31))
CSR_WRDONE_READ(/* NOT AUTOINST */
// Outputs
.rd_data_cclk (rd_data_WRDONE),
.rd_wait_cclk (),
.rd_done_strobe_cclk(rd_done_strobe_WRDONE),
.rd_strobe_tclk (),
// Inputs
.cclk (cclk),
.tclk (fsabi_clk),
.rst_b_cclk (cclk_rst_b),
.rst_b_tclk (fsabi_rst_b),
.rd_strobe_cclk (rd_decode &&
(spamo_addr[4:0] == 5'b10100)),
.rd_data_tclk (wrdone[30:0]));
assign accel_blit__spami_busy_b =
/* ... */ | rd_done_strobe_WRDONE;
assign accel_blit__spami_data =
{32{rd_done_strobe_WRDONE}} & {1'b0, rd_data_WRDONE};
\end{lstlisting}
The instantiation mechanism is somewhat bulky, but it is certainly better
than reimplementing the synchronizer each time! Future work may be possible
to extend verilog-mode to be able to automatically instantiate CSR
synchronizers.
\subsubsection{Implementation}
The synchronizers are based around sound two-flop principles for
synchronizing between clock domains. In order to transmit a value between
the two clock domains, the ``hold-and-sample'' technique is used; once a
flag is seen indicating that new data is ready to be transferred, the
synchronizers wait a cycle before sampling the data and transmitting it to
the recipient clock domain. Building on this principle, the synchronizers
can be trivially implemented with a small amount of internal state to
generate strobes and output data.
All internal signals are named according to the clock domain on which they
live; signals named \texttt{...\_tclk} are on the target clock, and signals
named \texttt{...\_cclk} are on the core clock. To synchronize a signal,
the progression of naming \texttt{foosig\_cclk}, \texttt{foosig\_cclk\_s1},
and \texttt{foosig\_cclk\_tclk} is used to represent the signal after no
flops, one flop, and two flops, respectively.
\subsection{Synchronous FIFO}
\label{sec:syncfifo}
Although the synchronous FIFO is not strictly a clock synchronization
mechanism, it is presented in this section as a means to understanding the
asynchronous FIFO, and since it is a fundamental building block of the
system.
\subsubsection{Motivation}
There are a number of reasons to have a packaged-up FIFO utility. One is
cleanliness and readability of code; an instantiation of a FIFO module is
immediately apparent to a reader, while an implementation mixed in with
other code is less so. Another reason for the Fifo module is the reduction
of opportunities for bugs; every implementations of FIFOs scattered through
the RTL is another opportunity for a mistake to appear, costing valuable
debug time (around 20 minutes per synthesis run).
\subsubsection{Implementation}
The Fifo module is implemented as a block RAM with read and write pointers.
Both pointers are initialize to zero; after a read or write, the appropriate
pointer increments. If the pointers are equal, the FIFO is empty. (Each
pointer is one bit wider than required to index into the RAM so that a full
FIFO does not appear identical to an empty FIFO.)
\subsubsection{Implementation: Parameters}
\begin{itemize}
\item{\textbf{DEPTH}: how many entries the FIFO can store}
\item{\textbf{WIDTH}: how many bits each entry has, and the width of the input and
output data ports}
\item{\textbf{ALMOST}: how few entries away from full or empty the FIFO must be to be
considered almost full or almost empty}
\end{itemize}
\subsubsection{Implementation: Portlist}
\begin{lstlisting}[basicstyle=\footnotesize,language=Verilog]
input clk;
input rst_b;
input wr_en;
input rd_en;
input [WIDTH-1:0] wr_dat;
output [WIDTH-1:0] rd_dat;
output empty;
output full;
output [`ADDR_WIDTH:0] available;
output afull;
output aempty;
\end{lstlisting}
At a positive clock edge, when wr\_en is high, the data at wr\_dat is stored
in the FIFO, and when rd\_en is high, the next entry in the FIFO is presented
at rd\_dat.
Interesting outputs:
\begin{itemize}
\item{\textbf{empty}: is high when the FIFO is empty}
\item{\textbf{full}: is high when the FIFO is full}
\item{\textbf{afull}: is high when there are ALMOST or fewer empty spaces left in the
FIFO. \footnote{\Huge{\textbf{I'M ALMOST FULL!!!}}} }
\item{\textbf{aempty}: is high when there are ALMOST or fewer entries in the FIFO}
\item{\textbf{available}: the number of entries in the FIFO; the width of this port is
log${}_2$ DEPTH + 1}
\end{itemize}
\subsection{Asynchronous FIFO}
\label{sec:fifo}
\subsubsection{Motivation}
As with a simple FIFO, there are a number of motivations for a packaged
cross-clock-domain FIFO utility: code reuse, clarity, and reduction of bugs.
This last motivation carries significant additional weight for a
cross-clock-domain FIFO: hardware crossing multiple clock domains is tricky,
so the less of it that needs to be written, the better.
\subsubsection{Implementation}
The core fifo implementation is similar to that to that of the Fifo module
(see section \ref{sec:syncfifo}): a block RAM with read and write
pointers. Reads from and writes to the block RAM occur on the different
clock domains. To accommodate empty and full outputs, the pointers must be
converted into grey code and passed across the clock domain boundary. The
empty output is on the read clock domain (so that the module using the FIFO
can avoid reading when empty), and the full output is on the write clock
domain (so that the module using the FIFO can avoid writing when full). To
accomplish this, both pointers are converted to grey code, passed through a
register, and passed across the clock domain boundary, and passed through
two more registers (to avoid metastability).
Because of the delay associated with crossing the clock domain boundary, it
is possible that the module may incorrectly indicate an empty or full FIFO.
However, it will be incorrect in the other direction (with a false
negative). This is guaranteed for the empty output because it is the write
index which is late: there can be \textit{more} data in the FIFO than the
reader knows about, but since the read index is not delayed, there is never
\textit{less}. (Similar reasoning holds for the full output.)
\subsubsection{Implementation: Parameters}
\begin{itemize}
\item{\textbf{DEPTH}: how many entries the FIFO can store}
\item{\textbf{WIDTH}: how many bits each entry has, and the width of the input and
output data ports}
\end{itemize}
\subsubsection{Implementation: Portlist}
\begin{lstlisting}[basicstyle=\footnotesize,language=Verilog]
input iclk;
input oclk;
input iclk_rst_b;
input oclk_rst_b;
input wr_en;
input rd_en;
input [WIDTH-1:0] wr_dat;
output [WIDTH-1:0] rd_dat;
output empty;
output full;
\end{lstlisting}
\section{Simple DMA Read Controller}
\label{sec:dmac}
The Simple DMA (Direct Memory Access) Read Controller provides a FIFO-like
interface for a target peripheral to read from memory.
\subsection{Motivation}
Since many devices require memory read access in a linear pattern, it only
made sense to support such access pattern in a simple way.
\subsection{Conceptual Overview}
After providing a start address, length, and a trigger command through the
SPAM bus (see section \ref{sec:spam}), data\_ready will be asserted high and
the master will be able to get the next 8 bytes of data one cycle after
request is asserted high as long as the FIFO (queue) is not empty (no
underflow). Once the DMA is done reading through the entire length, it may
be triggered again to read from a new start address and different length.
\subsection{Design Overview}
\subsubsection{Portlist}
Simple DMA Read Controller has the following ports that the master should
not directly interact with:
\begin{itemize}
\item{the default FSAB portlist (prefixed by dmac\_\_ for outbound)}
\item{SPAM portlist (prefixed by dmac\_\_)}
\end{itemize}
For the master, it has the following ports:
\begin{lstlisting}[basicstyle=\footnotesize,language=Verilog]
input request;
input target_clk; /* clk that the master is running in */
input target_rst_b;
output [63:0] data; /* 8 bytes of new data */
output data_ready;
output fifo_empty;
/* asserted when the fifo is empty. This may be the case when there is an
* underflow or when the DMA didn't start reading */
\end{lstlisting}
\subsubsection{Parameters}
\begin{lstlisting}[basicstyle=\footnotesize,language=Verilog]
parameter FIFO_DEPTH = 128; /* must be a power of 2 */
parameter FIFO_HI = clog2(FIFO_DEPTH) - 2;
parameter FSAB_DID = 4'hF;
parameter FSAB_SUBDID = 4'hF;
parameter SPAM_DID = 4'hx;
parameter SPAM_ADDRPFX = 24'h000000;
parameter SPAM_ADDRMASK = 24'hFFFFE0;
parameter DEFAULT_ADDR = 31'h00000000;
parameter DEFAULT_LEN = 31'h00000000;
\end{lstlisting}
The parameters are defined as follows:
\begin{itemize}
\item{\textbf{FIFO\_DEPTH}: Depth of the internal FIFO. DMA Controller will
try to keep this FIFO as full as possible. This value must be a power of 2
and 8 or greater to be functional.}
\item{\textbf{FIFO\_HI}: Highest bit needed to represent FIFO\_DEPTH space.
(log${}_2$(FIFO\_DEPTH) - 2) if FIFO\_DEPTH is power of 2.}
\item{\textbf{FSAB\_DID}: FSAB device id of the master. (if the master
doesn't have one, give the master one by setting it in
\texttt{rtl/fsab/fsab\_defines.vh})}
\item{\textbf{FSAB\_SUBDID}: FSAB sub device id of the master. (if the
master doesn't have one, give the master one by setting it in
\texttt{rtl/fsab/fsab\_defines.vh})}
\item{\textbf{SPAM\_DID}: SPAM device id of the master. (if the master
doesn't have one, give the master one by setting it in
\texttt{rtl/spam/spam\_defines.vh})}
\item{\textbf{SPAM\_ADDRPFX} and \textbf{SPAM\_ADDRMASK}: To write/read from
the SPAM bus, it must be the case that \texttt{((spamo\_addr \& SPAM\_ADDRMASK) ==
SPAM\_ADDRPFX)}. (Note: Always set the last 5 bits of the SPAM\_ADDRMASK to
0.)}
\item{\textbf{DEFAULT\_ADDR}: Default starting address for the DMA.}
\item{\textbf{DEFAULT\_LEN}: Default length that the DMA will read. The DMA will
provide values starting from address up to the length.}
\end{itemize}
\subsubsection{Config Registers (SPAM)}
The following values come from \texttt{rtl/fsab/dma\_config\_defines.vh};
these addresses correspond to the last 5 bits that the spamo\_addr needs to
be set to refer to these registers.
\begin{lstlisting}[basicstyle=\footnotesize,language=Verilog]
parameter NEXT_START_REG_ADDR = 5'h000;
parameter NEXT_LEN_REG_ADDR = 5'h004;
parameter COMMAND_REG_ADDR = 5'h008;
parameter FIFO_BYTES_READ_REG_ADDR = 5'h00c;
parameter TOTAL_BYTES_DELIVERED_REG_ADDR = 5'h010;
parameter CURR_START_REG_ADDR = 5'h014;
parameter DMA_STOP = 2'b00;
parameter DMA_TRIGGER_ONCE = 2'b01;
parameter DMA_AUTOTRIGGER = 2'b10;
\end{lstlisting}
The registers are defined as follows:
\begin{itemize}
\item{\textbf{NEXT\_START\_REG (write only)}: sets the starting address of
the DMA for the \textbf{next time} it is triggered.}
\item{\textbf{NEXT\_LEN\_REG (write only)}: sets the length that the DMA has
to read for the \textbf{next time} it is triggered.}
\item{\textbf{COMMAND\_REG (write only)}: sets the next command for the DMA
engine to execute, from one of:}
\begin{itemize}
\item{\textbf{DMA\_STOP}: DMA does not trigger again.}
\item{\textbf{DMA\_TRIGGER\_ONCE}: Triggers the DMA once.}
\item{\textbf{DMA\_AUTOTRIGGER}: Everytime, the DMA is done reading, it is
triggered again.}
\end{itemize}
\item{\textbf{FIFO\_BYTES\_READ\_REG (read only)}: the number of bytes that
the \textit{internal FIFO} has read so far since it was last triggered.}
\item{\textbf{TOTAL\_BYTES\_DELIVERED\_REG (read only)}: the total number of
bytes that was delivered to the master since the \textit{last reset}. (note:
it is not ``last triggered'')}
\item{\textbf{CURR\_START\_REG (read only)}: the address that the DMA
started reading from. (It provides the value of NEXT\_START\_REG before it was
triggered)}
\end{itemize}
\subsubsection{Implementation}
The internal queue for DMA is represented in the following way:
\begin{lstlisting}[basicstyle=\footnotesize,language=Verilog]
reg [FSAB_DATA_HI:0] fifo [(FIFO_DEPTH-1):0];
/* Clock domain: fsabi_clk */
reg [FIFO_HI:0] fifo_wpos;