source: trunk/platforms/tsar_generic_leti/top.cpp @ 628

Last change on this file since 628 was 628, checked in by alain, 10 years ago

Introducing the vci_iopic component in the tsar_generic_leti plat-form.
This platform has been tested wit three distributed applications
running on top of the giet_tsar:

  • soft_hello_giet
  • soft_transpose_giet
  • soft_sort_giet
File size: 53.1 KB
Line 
1/////////////////////////////////////////////////////////////////////////
2// File: top.cpp
3// Author: Alain Greiner
4// Copyright: UPMC/LIP6
5// Date : february 2014
6// This program is released under the GNU public license
7/////////////////////////////////////////////////////////////////////////
8// This file define a generic TSAR architecture.
9// The processor is a MIPS32 processor wrapped in a GDB server
10// (this is defined in the tsar_xbar_cluster).
11//
12// The seg_reset_base and seg_kcode_base addresses are not constrained
13// to be 0xBFC00000 and 0x80000000.
14//
15// It does not use an external ROM, as the boot code must be (pre)loaded
16// in cluster (0,0) memory.
17//
18// The physical address space is 40 bits.
19// The 8 address MSB bits define the cluster index.
20//
21// The main hardware parameters are the mesh size (X_SIZE / Y_SIZE),
22// and the number of ptocessors per cluster (NB_PROCS_MAX).
23// The number of clusters cannot be larger than 256.
24// The number of processors per cluster cannot be larger than 4.
25//
26// Each cluster contains:
27// - 5 dspin_local_crossbar (local interconnect)
28// - 5 dspin_router (global interconnect)
29// - up to 4 vci_cc_vcache wrapping a MIPS32 processor
30// - 1 vci_mem_cache
31// - 1 vci_xicu
32// - 1 vci_simple_ram (to model the L3 cache).
33//
34// Each processor receive 4 consecutive IRQ lines from the local XICU.
35// In all clusters, the MEMC IRQ line (signaling a late write error)
36// is connected to XICU HWI[8]
37//
38// The cluster 0 contains two more peripherals:
39// - one block device controller, whose IRQ is connected to XICU HWI[9].
40// - one single channel TTY controller, whose IRQ is connected to XICU HWI[10].
41//
42// The cluster internal architecture is defined in file tsar_leti_cluster,
43// that must be considered as an extension of this top.cpp file.
44//
45// Besides the hardware components contained in clusters, external peripherals
46// are connected to an external IO bus (implemented as a vci_local_crossbar):
47// - one disk controller
48// - one multi-channel ethernet controller
49// - one multi-channel chained buffer dma controller
50// - one multi-channel tty controller
51// - one frame buffer controller
52// - one 16 channels iopic controller
53//
54// This IOBUS is connected to the north  port of the DIR_CMD
55// and DIR_RSP routers, in cluster(X_SIZE-1, Y_SIZE-1).
56// For all external peripherals, the hardware interrupts (HWI) are
57// translated to software interrupts (SWI) by the iopic component:
58// - IRQ_MNIC_RX[1:0]   connected to IOPIC HWI[1:0]
59// - IRQ_MNIC_TX[1:0]   connected to IOPIC HWI[3:2]
60// - IRQ_CDMA[3:0]      connected to IOPIC HWI[7:4]
61// - IRQ_BDEV           connected to IOPIC HWI[9]
62// - IRQ_MTTY[3:0]      connected to IOPIC HWI[15:12]
63////////////////////////////////////////////////////////////////////////////
64// The following parameters must be defined in the hard_config.h file :
65// - X_WIDTH          : number of bits for x coordinate (must be 4)
66// - Y_WIDTH          : number of bits for y coordinate (must be 4)
67// - X_SIZE           : number of clusters in a row
68// - Y_SIZE           : number of clusters in a column
69// - NB_PROCS_MAX     : number of processors per cluster (1, 2 or 4)
70// - NB_CMA_CHANNELS  : number of CMA channels in I/0 cluster (8 max)
71// - NB_TTY_CHANNELS  : number of TTY channels in I/O cluster (16 max)
72// - NB_NIC_CHANNELS  : number of NIC channels in I/O cluster (2 max)
73// - USE_EXT_IO       : use external peripherals if non zero
74//
75// Some other hardware parameters are not used when compiling the OS,
76// and are only defined in this top.cpp file:
77// - XRAM_LATENCY     : external ram latency
78// - MEMC_WAYS        : L2 cache number of ways
79// - MEMC_SETS        : L2 cache number of sets
80// - L1_IWAYS         : L1 cache instruction number of ways
81// - L1_ISETS         : L1 cache instruction number of sets
82// - L1_DWAYS         : L1 cache data number of ways
83// - L1_DSETS         : L1 cache data number of sets
84// - FBUF_X_SIZE      : width of frame buffer (pixels)
85// - FBUF_Y_SIZE      : heigth of frame buffer (lines)
86// - BDEV_IMAGE_NAME  : file pathname for block device
87// - NIC_RX_NAME      : file pathname for NIC received packets
88// - NIC_TX_NAME      : file pathname for NIC transmited packets
89// - NIC_MAC4         : MAC address
90// - NIC_MAC2         : MAC address
91/////////////////////////////////////////////////////////////////////////
92// General policy for 40 bits physical address decoding:
93// All physical segments base addresses are multiple of 1 Mbytes
94// (=> the 24 LSB bits = 0, and the 16 MSB bits define the target)
95// The (X_WIDTH + Y_WIDTH) MSB bits (left aligned) define
96// the cluster index, and the LADR bits define the local index:
97//      |X_ID|Y_ID|  LADR |     OFFSET          |
98//      |  4 |  4 |   8   |       24            |
99/////////////////////////////////////////////////////////////////////////
100// General policy for 14 bits SRCID decoding:
101// Each component is identified by (x_id, y_id, l_id) tuple.
102//      |X_ID|Y_ID| L_ID |
103//      |  4 |  4 |  6   |
104/////////////////////////////////////////////////////////////////////////
105
106#include <systemc>
107#include <sys/time.h>
108#include <iostream>
109#include <sstream>
110#include <cstdlib>
111#include <cstdarg>
112#include <stdint.h>
113
114#include "gdbserver.h"
115#include "mapping_table.h"
116#include "tsar_leti_cluster.h"
117#include "vci_local_crossbar.h"
118#include "vci_dspin_initiator_wrapper.h"
119#include "vci_dspin_target_wrapper.h"
120#include "vci_multi_tty.h"
121#include "vci_multi_nic.h"
122#include "vci_chbuf_dma.h"
123#include "vci_block_device_tsar.h"
124#include "vci_framebuffer.h"
125#include "vci_iopic.h"
126#include "alloc_elems.h"
127
128///////////////////////////////////////////////////
129//      OS
130///////////////////////////////////////////////////
131
132#define USE_GIET_VM     0
133#define USE_GIET_TSAR   1
134
135#if ( USE_GIET_VM and USE_GIET_TSAR )
136#error "Can't use Two different OS"
137#endif
138
139#if ( (not USE_GIET_VM) and (not USE_GIET_TSAR) )
140#error "You need to specify one OS"
141#endif
142
143///////////////////////////////////////////////////
144//               Parallelisation
145///////////////////////////////////////////////////
146#define USE_OPENMP 0
147
148#if USE_OPENMP
149#include <omp.h>
150#endif
151
152///////////////////////////////////////////////////
153//  cluster index (from x,y coordinates)
154///////////////////////////////////////////////////
155
156#define cluster(x,y)   (y + (x << Y_WIDTH))
157
158#define min(a, b) (a < b ? a : b)
159
160///////////////////////////////////////////////////////////
161//          DSPIN parameters           
162///////////////////////////////////////////////////////////
163
164#define dspin_cmd_width      39
165#define dspin_rsp_width      32
166
167///////////////////////////////////////////////////////////
168//          VCI parameters           
169///////////////////////////////////////////////////////////
170
171#define vci_cell_width_int    4
172#define vci_cell_width_ext    8
173#define vci_address_width     40
174#define vci_plen_width        8
175#define vci_rerror_width      1
176#define vci_clen_width        1
177#define vci_rflag_width       1
178#define vci_srcid_width       14
179#define vci_pktid_width       4
180#define vci_trdid_width       4
181#define vci_wrplen_width      1
182
183////////////////////////////////////////////////////////////
184//    Main Hardware Parameters values         
185//////////////////////i/////////////////////////////////////
186
187#if USE_GIET_VM
188#include "giet_vm/hard_config.h"
189#endif
190
191#if USE_GIET_TSAR
192#include "../../softs/soft_transpose_giet/hard_config.h"
193#endif
194
195////////////////////////////////////////////////////////////
196//    Secondary Hardware Parameters         
197//////////////////////i/////////////////////////////////////
198
199#define RESET_ADDRESS         0x0
200
201#define XRAM_LATENCY          0
202
203#define MEMC_WAYS             16
204#define MEMC_SETS             256
205
206#define L1_IWAYS              4
207#define L1_ISETS              64
208
209#define L1_DWAYS              4
210#define L1_DSETS              64
211
212#define FBUF_X_SIZE           128
213#define FBUF_Y_SIZE           128
214
215#define BDEV_IMAGE_NAME       "../../softs/soft_transpose_giet/images.raw"
216
217#define NIC_MAC4              0XBABEF00D
218#define NIC_MAC2              0xBEEF
219#define NIC_RX_NAME           "../../softs/soft_hello_giet/fake"
220#define NIC_TX_NAME           "../../softs/soft_hello_giet/fake"
221
222#define NORTH                 0
223#define SOUTH                 1
224#define EAST                  2
225#define WEST                  3
226
227////////////////////////////////////////////////////////////
228//    Arguments for the SoCLib loader         
229//////////////////////i/////////////////////////////////////
230
231#if USE_GIET_VM
232#define loader_args          "TBD"
233#endif
234
235#if USE_GIET_TSAR
236#define loader_args          "../../softs/soft_transpose_giet/bin.soft"
237#endif
238
239////////////////////////////////////////////////////////////
240//     DEBUG Parameters default values         
241//////////////////////i/////////////////////////////////////
242
243#define MAX_FROZEN_CYCLES     10000
244
245////////////////////////////////////////////////////////////////////
246//     LOCAL TGTID & SRCID definition
247// For all components:  global TGTID = global SRCID = cluster_index
248////////////////////////////////////////////////////////////////////
249
250#define MEMC_TGTID      0
251#define XICU_TGTID      1
252#define MTTY_TGTID      2
253#define BDEV_TGTID      3
254#define FBUF_TGTID      4
255#define MNIC_TGTID      5
256#define CDMA_TGTID      6
257#define IOPI_TGTID      7
258
259#define BDEV_SRCID      NB_PROCS_MAX
260#define CDMA_SRCID      NB_PROCS_MAX + 1
261#define IOPI_SRCID      NB_PROCS_MAX + 2
262
263/////////////////////////////////////////////////////////////////////
264//    Physical segments definition
265/////////////////////////////////////////////////////////////////////
266// - 3 segments are replicated in all clusters
267// - 2 segments are replicated in cluster[0,0] & [X_SIZE-1,Y_SIZE-1]
268// - 4 segments are only in cluster [X_SIZE-1,Y_SIZE]
269// The following values are for segments in cluster 0,
270// and these 32 bits values must be concatenate with the cluster
271// index (on 8 bits) to obtain the 40 bits address.
272/////////////////////////////////////////////////////////////////////
273
274   // in cluster [0,0] & [X_SIZE-1,Y_SIZE]
275
276   #define MTTY_BASE    0xF4000000
277   #define MTTY_SIZE    0x00001000   // 4 Kbytes
278
279   #define BDEV_BASE    0xF2000000
280   #define BDEV_SIZE    0x00001000   // 4 Kbytes
281
282   // in cluster [X_SIZE-1,Y_SIZE]
283
284   #define FBUF_BASE    0xF3000000
285   #define FBUF_SIZE    (FBUF_X_SIZE * FBUF_Y_SIZE * 2)
286
287   #define MNIC_BASE    0xF7000000
288   #define MNIC_SIZE    0x00800000   // 512 Kbytes (for 8 channels)
289
290   #define CDMA_BASE    0xF8000000
291   #define CDMA_SIZE    0x00004000 * NB_CMA_CHANNELS
292
293   #define IOPI_BASE    0xF9000000
294   #define IOPI_SIZE    0x00001000   // 4 Kbytes
295   
296   // replicated segments : address is extended to 40 bits by cluster_xy
297
298   #define MEMC_BASE    0x00000000
299   #define MEMC_SIZE    0x01000000   // 16 Mbytes per cluster
300
301   #define MCFG_BASE    0xE0000000
302   #define MCFG_SIZE    0x00001000   // 4 Kbytes per cluster
303
304   #define XICU_BASE    0xF0000000
305   #define XICU_SIZE    0x00001000   // 4 Kbytes per cluster
306
307bool stop_called = false;
308
309/////////////////////////////////
310int _main(int argc, char *argv[])
311{
312   using namespace sc_core;
313   using namespace soclib::caba;
314   using namespace soclib::common;
315
316   uint32_t ncycles          = 0xFFFFFFFF;         // max simulated cycles
317   size_t   threads          = 1;                  // simulator's threads number
318   bool     trace_ok         = false;              // trace activated
319   uint32_t trace_from       = 0;                  // trace start cycle
320   bool     trace_proc_ok    = false;              // detailed proc trace activated
321   size_t   trace_memc_ok    = false;              // detailed memc trace activated
322   size_t   trace_memc_id    = 0;                  // index of memc to be traced
323   size_t   trace_proc_id    = 0;                  // index of proc to be traced
324   uint32_t frozen_cycles    = MAX_FROZEN_CYCLES;  // monitoring frozen processor
325   struct   timeval t1,t2;
326   uint64_t ms1,ms2;
327
328   ////////////// command line arguments //////////////////////
329   if (argc > 1)
330   {
331      for (int n = 1; n < argc; n = n + 2)
332      {
333         if ((strcmp(argv[n], "-NCYCLES") == 0) && (n + 1 < argc))
334         {
335            ncycles = (uint64_t) strtol(argv[n + 1], NULL, 0);
336         }
337         else if ((strcmp(argv[n],"-DEBUG") == 0) && (n + 1 < argc))
338         {
339            trace_ok = true;
340            trace_from = (uint32_t) strtol(argv[n + 1], NULL, 0);
341         }
342         else if ((strcmp(argv[n], "-MEMCID") == 0) && (n + 1 < argc))
343         {
344            trace_memc_ok = true;
345            trace_memc_id = (size_t) strtol(argv[n + 1], NULL, 0);
346            size_t x = trace_memc_id >> Y_WIDTH;
347            size_t y = trace_memc_id & ((1<<Y_WIDTH)-1);
348
349            assert( (x <= X_SIZE) and (y <= Y_SIZE) &&
350                  "MEMCID parameter refers a not valid memory cache");
351         }
352         else if ((strcmp(argv[n], "-PROCID") == 0) && (n + 1 < argc))
353         {
354            trace_proc_ok = true;
355            trace_proc_id = (size_t) strtol(argv[n + 1], NULL, 0);
356            size_t cluster_xy = trace_proc_id / NB_PROCS_MAX ;
357            size_t x          = cluster_xy >> Y_WIDTH;
358            size_t y          = cluster_xy & ((1<<Y_WIDTH)-1);
359
360            assert( (x <= X_SIZE) and (y <= Y_SIZE) &&
361                  "PROCID parameter refers a not valid processor");
362         }
363         else if ((strcmp(argv[n], "-THREADS") == 0) && ((n + 1) < argc))
364         {
365            threads = (size_t) strtol(argv[n + 1], NULL, 0);
366            threads = (threads < 1) ? 1 : threads;
367         }
368         else if ((strcmp(argv[n], "-FROZEN") == 0) && (n + 1 < argc))
369         {
370            frozen_cycles = (uint32_t) strtol(argv[n + 1], NULL, 0);
371         }
372         else
373         {
374            std::cout << "   Arguments are (key,value) couples." << std::endl;
375            std::cout << "   The order is not important." << std::endl;
376            std::cout << "   Accepted arguments are :" << std::endl << std::endl;
377            std::cout << "     -NCYCLES number_of_simulated_cycles" << std::endl;
378            std::cout << "     -DEBUG debug_start_cycle" << std::endl;
379            std::cout << "     -THREADS simulator's threads number" << std::endl;
380            std::cout << "     -FROZEN max_number_of_lines" << std::endl;
381            std::cout << "     -PERIOD number_of_cycles between trace" << std::endl;
382            std::cout << "     -MEMCID index_memc_to_be_traced" << std::endl;
383            std::cout << "     -PROCID index_proc_to_be_traced" << std::endl;
384            exit(0);
385         }
386      }
387   }
388
389    // checking hardware parameters
390    assert( (X_SIZE <= 16) and
391            "The X_SIZE parameter cannot be larger than 16" );
392
393    assert( (Y_SIZE <= 16) and
394            "The Y_SIZE parameter cannot be larger than 16" );
395
396    assert( (NB_PROCS_MAX <= 8) and
397            "The NB_PROCS_MAX parameter cannot be larger than 4" );
398
399    assert( (NB_CMA_CHANNELS <= 4) and
400            "The NB_CMA_CHANNELS parameter cannot be larger than 4" );
401
402    assert( (NB_TTY_CHANNELS <= 4) and
403            "The NB_TTY_CHANNELS parameter cannot be larger than 4" );
404
405    assert( (NB_NIC_CHANNELS <= 2) and
406            "The NB_NIC_CHANNELS parameter cannot be larger than 2" );
407
408    assert( (vci_address_width == 40) and
409            "VCI address width with the GIET must be 40 bits" );
410
411    assert( (X_WIDTH == 4) and (Y_WIDTH == 4) and
412            "ERROR: you must have X_WIDTH == Y_WIDTH == 4");
413 
414    std::cout << std::endl;
415
416    std::cout << " - X_SIZE           = " << X_SIZE << std::endl;
417    std::cout << " - Y_SIZE           = " << Y_SIZE << std::endl;
418    std::cout << " - NB_PROCS_MAX     = " << NB_PROCS_MAX <<  std::endl;
419    std::cout << " - NB_DMA_CHANNELS  = " << NB_DMA_CHANNELS <<  std::endl;
420    std::cout << " - NB_TTY_CHANNELS  = " << NB_TTY_CHANNELS <<  std::endl;
421    std::cout << " - NB_NIC_CHANNELS  = " << NB_NIC_CHANNELS <<  std::endl;
422    std::cout << " - MEMC_WAYS        = " << MEMC_WAYS << std::endl;
423    std::cout << " - MEMC_SETS        = " << MEMC_SETS << std::endl;
424    std::cout << " - RAM_LATENCY      = " << XRAM_LATENCY << std::endl;
425    std::cout << " - MAX_FROZEN       = " << frozen_cycles << std::endl;
426    std::cout << " - MAX_CYCLES       = " << ncycles << std::endl;
427    std::cout << " - RESET_ADDRESS    = " << RESET_ADDRESS << std::endl;
428    std::cout << " - SOFT_FILENAME    = " << loader_args << std::endl;
429
430    std::cout << std::endl;
431
432    // Internal and External VCI parameters definition
433    typedef soclib::caba::VciParams<vci_cell_width_int,
434                                    vci_plen_width,
435                                    vci_address_width,
436                                    vci_rerror_width,
437                                    vci_clen_width,
438                                    vci_rflag_width,
439                                    vci_srcid_width,
440                                    vci_pktid_width,
441                                    vci_trdid_width,
442                                    vci_wrplen_width> vci_param_int;
443
444    typedef soclib::caba::VciParams<vci_cell_width_ext,
445                                    vci_plen_width,
446                                    vci_address_width,
447                                    vci_rerror_width,
448                                    vci_clen_width,
449                                    vci_rflag_width,
450                                    vci_srcid_width,
451                                    vci_pktid_width,
452                                    vci_trdid_width,
453                                    vci_wrplen_width> vci_param_ext;
454
455#if USE_OPENMP
456   omp_set_dynamic(false);
457   omp_set_num_threads(threads);
458   std::cerr << "Built with openmp version " << _OPENMP << std::endl;
459#endif
460
461
462   ///////////////////////////////////////
463   //  Direct Network Mapping Table
464   ///////////////////////////////////////
465
466   MappingTable maptabd(vci_address_width, 
467                        IntTab(X_WIDTH + Y_WIDTH, 16 - X_WIDTH - Y_WIDTH), 
468                        IntTab(X_WIDTH + Y_WIDTH, vci_srcid_width - X_WIDTH - Y_WIDTH), 
469                        0x00FF000000ULL);
470
471   // replicated segments
472   for (size_t x = 0; x < X_SIZE; x++)
473   {
474      for (size_t y = 0; y < Y_SIZE; y++)
475      {
476         sc_uint<vci_address_width> offset;
477         offset = ((sc_uint<vci_address_width>)cluster(x,y)) << 32;
478
479         std::ostringstream    si;
480         si << "seg_xicu_" << x << "_" << y;
481         maptabd.add(Segment(si.str(), XICU_BASE + offset, XICU_SIZE, 
482                  IntTab(cluster(x,y),XICU_TGTID), false));
483
484         std::ostringstream    sd;
485         sd << "seg_mcfg_" << x << "_" << y;
486         maptabd.add(Segment(sd.str(), MCFG_BASE + offset, MCFG_SIZE, 
487                  IntTab(cluster(x,y),MEMC_TGTID), false));
488
489         std::ostringstream    sh;
490         sh << "seg_memc_" << x << "_" << y;
491         maptabd.add(Segment(sh.str(), MEMC_BASE + offset, MEMC_SIZE, 
492                  IntTab(cluster(x,y),MEMC_TGTID), true));
493      }
494   }
495
496   // segments in cluster(0,0)
497   maptabd.add(Segment("seg_tty0", MTTY_BASE, MTTY_SIZE, 
498               IntTab(cluster(0,0),MTTY_TGTID), false));
499
500   maptabd.add(Segment("seg_ioc0", BDEV_BASE, BDEV_SIZE, 
501               IntTab(cluster(0,0),BDEV_TGTID), false));
502
503   // segments in cluster_io (X_SIZE-1,Y_SIZE)
504   sc_uint<vci_address_width> offset;
505   offset = ((sc_uint<vci_address_width>)cluster(X_SIZE-1,Y_SIZE)) << 32;
506
507   maptabd.add(Segment("seg_mtty", MTTY_BASE + offset, MTTY_SIZE, 
508               IntTab(cluster(X_SIZE-1, Y_SIZE),MTTY_TGTID), false));
509
510   maptabd.add(Segment("seg_fbuf", FBUF_BASE + offset, FBUF_SIZE, 
511               IntTab(cluster(X_SIZE-1, Y_SIZE),FBUF_TGTID), false));
512
513   maptabd.add(Segment("seg_bdev", BDEV_BASE + offset, BDEV_SIZE, 
514               IntTab(cluster(X_SIZE-1, Y_SIZE),BDEV_TGTID), false));
515
516   maptabd.add(Segment("seg_mnic", MNIC_BASE + offset, MNIC_SIZE, 
517               IntTab(cluster(X_SIZE-1, Y_SIZE),MNIC_TGTID), false));
518
519   maptabd.add(Segment("seg_cdma", CDMA_BASE + offset, CDMA_SIZE, 
520               IntTab(cluster(X_SIZE-1, Y_SIZE),CDMA_TGTID), false));
521
522   maptabd.add(Segment("seg_iopi", IOPI_BASE + offset, IOPI_SIZE, 
523               IntTab(cluster(X_SIZE-1, Y_SIZE),IOPI_TGTID), false));
524
525   std::cout << maptabd << std::endl;
526
527    /////////////////////////////////////////////////
528    // Ram network mapping table
529    /////////////////////////////////////////////////
530
531    MappingTable maptabx(vci_address_width, 
532                         IntTab(X_WIDTH+Y_WIDTH), 
533                         IntTab(X_WIDTH+Y_WIDTH), 
534                         0x00FF000000ULL);
535
536    for (size_t x = 0; x < X_SIZE; x++)
537    {
538        for (size_t y = 0; y < Y_SIZE ; y++)
539        { 
540            sc_uint<vci_address_width> offset;
541            offset = (sc_uint<vci_address_width>)cluster(x,y) 
542                      << (vci_address_width-X_WIDTH-Y_WIDTH);
543
544            std::ostringstream sh;
545            sh << "x_seg_memc_" << x << "_" << y;
546
547            maptabx.add(Segment(sh.str(), MEMC_BASE + offset, 
548                     MEMC_SIZE, IntTab(cluster(x,y)), false));
549        }
550    }
551    std::cout << maptabx << std::endl;
552
553    ////////////////////
554    // Signals
555    ///////////////////
556
557    sc_clock                          signal_clk("clk");
558    sc_signal<bool>                   signal_resetn("resetn");
559
560    // IRQs from external peripherals
561    sc_signal<bool>                   signal_irq_bdev;
562    sc_signal<bool>                   signal_irq_mnic_rx[NB_NIC_CHANNELS];
563    sc_signal<bool>                   signal_irq_mnic_tx[NB_NIC_CHANNELS];
564    sc_signal<bool>                   signal_irq_mtty[NB_TTY_CHANNELS];
565    sc_signal<bool>                   signal_irq_cdma[NB_CMA_CHANNELS];
566    sc_signal<bool>                   signal_irq_false;
567
568   // Horizontal inter-clusters DSPIN signals
569   DspinSignals<dspin_cmd_width>** signal_dspin_h_cmd_inc =
570      alloc_elems<DspinSignals<dspin_cmd_width> >("signal_dspin_h_cmd_inc", X_SIZE-1, Y_SIZE);
571   DspinSignals<dspin_cmd_width>** signal_dspin_h_cmd_dec =
572      alloc_elems<DspinSignals<dspin_cmd_width> >("signal_dspin_h_cmd_dec", X_SIZE-1, Y_SIZE);
573
574   DspinSignals<dspin_rsp_width>** signal_dspin_h_rsp_inc =
575      alloc_elems<DspinSignals<dspin_rsp_width> >("signal_dspin_h_rsp_inc", X_SIZE-1, Y_SIZE);
576   DspinSignals<dspin_rsp_width>** signal_dspin_h_rsp_dec =
577      alloc_elems<DspinSignals<dspin_rsp_width> >("signal_dspin_h_rsp_dec", X_SIZE-1, Y_SIZE);
578
579   DspinSignals<dspin_cmd_width>** signal_dspin_h_m2p_inc =
580      alloc_elems<DspinSignals<dspin_cmd_width> >("signal_dspin_h_m2p_inc", X_SIZE-1, Y_SIZE);
581   DspinSignals<dspin_cmd_width>** signal_dspin_h_m2p_dec =
582      alloc_elems<DspinSignals<dspin_cmd_width> >("signal_dspin_h_m2p_dec", X_SIZE-1, Y_SIZE);
583
584   DspinSignals<dspin_rsp_width>** signal_dspin_h_p2m_inc =
585      alloc_elems<DspinSignals<dspin_rsp_width> >("signal_dspin_h_p2m_inc", X_SIZE-1, Y_SIZE);
586   DspinSignals<dspin_rsp_width>** signal_dspin_h_p2m_dec =
587      alloc_elems<DspinSignals<dspin_rsp_width> >("signal_dspin_h_p2m_dec", X_SIZE-1, Y_SIZE);
588
589   DspinSignals<dspin_cmd_width>** signal_dspin_h_cla_inc =
590      alloc_elems<DspinSignals<dspin_cmd_width> >("signal_dspin_h_cla_inc", X_SIZE-1, Y_SIZE);
591   DspinSignals<dspin_cmd_width>** signal_dspin_h_cla_dec =
592      alloc_elems<DspinSignals<dspin_cmd_width> >("signal_dspin_h_cla_dec", X_SIZE-1, Y_SIZE);
593
594   // Vertical inter-clusters DSPIN signals
595   DspinSignals<dspin_cmd_width>** signal_dspin_v_cmd_inc =
596      alloc_elems<DspinSignals<dspin_cmd_width> >("signal_dspin_v_cmd_inc", X_SIZE, Y_SIZE-1);
597   DspinSignals<dspin_cmd_width>** signal_dspin_v_cmd_dec =
598      alloc_elems<DspinSignals<dspin_cmd_width> >("signal_dspin_v_cmd_dec", X_SIZE, Y_SIZE-1);
599
600   DspinSignals<dspin_rsp_width>** signal_dspin_v_rsp_inc =
601      alloc_elems<DspinSignals<dspin_rsp_width> >("signal_dspin_v_rsp_inc", X_SIZE, Y_SIZE-1);
602   DspinSignals<dspin_rsp_width>** signal_dspin_v_rsp_dec =
603      alloc_elems<DspinSignals<dspin_rsp_width> >("signal_dspin_v_rsp_dec", X_SIZE, Y_SIZE-1);
604
605   DspinSignals<dspin_cmd_width>** signal_dspin_v_m2p_inc =
606      alloc_elems<DspinSignals<dspin_cmd_width> >("signal_dspin_v_m2p_inc", X_SIZE, Y_SIZE-1);
607   DspinSignals<dspin_cmd_width>** signal_dspin_v_m2p_dec =
608      alloc_elems<DspinSignals<dspin_cmd_width> >("signal_dspin_v_m2p_dec", X_SIZE, Y_SIZE-1);
609
610   DspinSignals<dspin_rsp_width>** signal_dspin_v_p2m_inc =
611      alloc_elems<DspinSignals<dspin_rsp_width> >("signal_dspin_v_p2m_inc", X_SIZE, Y_SIZE-1);
612   DspinSignals<dspin_rsp_width>** signal_dspin_v_p2m_dec =
613      alloc_elems<DspinSignals<dspin_rsp_width> >("signal_dspin_v_p2m_dec", X_SIZE, Y_SIZE-1);
614
615   DspinSignals<dspin_cmd_width>** signal_dspin_v_cla_inc =
616      alloc_elems<DspinSignals<dspin_cmd_width> >("signal_dspin_v_cla_inc", X_SIZE, Y_SIZE-1);
617   DspinSignals<dspin_cmd_width>** signal_dspin_v_cla_dec =
618      alloc_elems<DspinSignals<dspin_cmd_width> >("signal_dspin_v_cla_dec", X_SIZE, Y_SIZE-1);
619
620   // Mesh boundaries DSPIN signals (Most of those signals are not used...)
621   DspinSignals<dspin_cmd_width>*** signal_dspin_bound_cmd_in =
622      alloc_elems<DspinSignals<dspin_cmd_width> >("signal_dspin_bound_cmd_in" , X_SIZE, Y_SIZE, 4);
623   DspinSignals<dspin_cmd_width>*** signal_dspin_bound_cmd_out =
624      alloc_elems<DspinSignals<dspin_cmd_width> >("signal_dspin_bound_cmd_out", X_SIZE, Y_SIZE, 4);
625
626   DspinSignals<dspin_rsp_width>*** signal_dspin_bound_rsp_in =
627      alloc_elems<DspinSignals<dspin_rsp_width> >("signal_dspin_bound_rsp_in" , X_SIZE, Y_SIZE, 4);
628   DspinSignals<dspin_rsp_width>*** signal_dspin_bound_rsp_out =
629      alloc_elems<DspinSignals<dspin_rsp_width> >("signal_dspin_bound_rsp_out", X_SIZE, Y_SIZE, 4);
630
631   DspinSignals<dspin_cmd_width>*** signal_dspin_bound_m2p_in =
632      alloc_elems<DspinSignals<dspin_cmd_width> >("signal_dspin_bound_m2p_in" , X_SIZE, Y_SIZE, 4);
633   DspinSignals<dspin_cmd_width>*** signal_dspin_bound_m2p_out =
634      alloc_elems<DspinSignals<dspin_cmd_width> >("signal_dspin_bound_m2p_out", X_SIZE, Y_SIZE, 4);
635
636   DspinSignals<dspin_rsp_width>*** signal_dspin_bound_p2m_in =
637      alloc_elems<DspinSignals<dspin_rsp_width> >("signal_dspin_bound_p2m_in" , X_SIZE, Y_SIZE, 4);
638   DspinSignals<dspin_rsp_width>*** signal_dspin_bound_p2m_out =
639      alloc_elems<DspinSignals<dspin_rsp_width> >("signal_dspin_bound_p2m_out", X_SIZE, Y_SIZE, 4);
640
641   DspinSignals<dspin_cmd_width>*** signal_dspin_bound_cla_in =
642      alloc_elems<DspinSignals<dspin_cmd_width> >("signal_dspin_bound_cla_in" , X_SIZE, Y_SIZE, 4);
643   DspinSignals<dspin_cmd_width>*** signal_dspin_bound_cla_out =
644      alloc_elems<DspinSignals<dspin_cmd_width> >("signal_dspin_bound_cla_out", X_SIZE, Y_SIZE, 4);
645
646   // VCI signals for iobus and peripherals
647   VciSignals<vci_param_int>    signal_vci_ini_bdev("signal_vci_ini_bdev");
648   VciSignals<vci_param_int>    signal_vci_ini_cdma("signal_vci_ini_cdma");
649   VciSignals<vci_param_int>    signal_vci_ini_iopi("signal_vci_ini_iopi");
650
651   VciSignals<vci_param_int>*   signal_vci_ini_proc = 
652       alloc_elems<VciSignals<vci_param_int> >("signal_vci_ini_proc", NB_PROCS_MAX );
653
654   VciSignals<vci_param_int>    signal_vci_tgt_memc("signal_vci_tgt_memc");
655   VciSignals<vci_param_int>    signal_vci_tgt_xicu("signal_vci_tgt_xicu");
656   VciSignals<vci_param_int>    signal_vci_tgt_bdev("signal_vci_tgt_bdev");
657   VciSignals<vci_param_int>    signal_vci_tgt_mtty("signal_vci_tgt_mtty");
658   VciSignals<vci_param_int>    signal_vci_tgt_fbuf("signal_vci_tgt_fbuf");
659   VciSignals<vci_param_int>    signal_vci_tgt_mnic("signal_vci_tgt_mnic");
660   VciSignals<vci_param_int>    signal_vci_tgt_cdma("signal_vci_tgt_cdma");
661   VciSignals<vci_param_int>    signal_vci_tgt_iopi("signal_vci_tgt_iopi");
662
663   VciSignals<vci_param_int>    signal_vci_cmd_to_noc("signal_vci_cmd_to_noc");
664   VciSignals<vci_param_int>    signal_vci_cmd_from_noc("signal_vci_cmd_from_noc");
665   
666   ////////////////////////////
667   //      Loader   
668   ////////////////////////////
669
670   soclib::common::Loader loader( loader_args );
671
672   typedef soclib::common::GdbServer<soclib::common::Mips32ElIss> proc_iss;
673   proc_iss::set_loader(loader);
674
675   ////////////////////////////
676   // Clusters construction
677   ////////////////////////////
678
679   TsarLetiCluster<dspin_cmd_width,
680                   dspin_rsp_width,
681                   vci_param_int,
682                   vci_param_ext>*          clusters[X_SIZE][Y_SIZE];
683
684#if USE_OPENMP
685#pragma omp parallel
686    {
687#pragma omp for
688#endif
689        for (size_t i = 0; i  < (X_SIZE * Y_SIZE); i++)
690        {
691            size_t x = i / Y_SIZE;
692            size_t y = i % Y_SIZE;
693
694#if USE_OPENMP
695#pragma omp critical
696            {
697#endif
698            std::cout << std::endl;
699            std::cout << "Cluster_" << std::dec << x << "_" << y
700                      << " with cluster_xy = " << std::hex << cluster(x,y) << std::endl;
701            std::cout << std::endl;
702
703            clusters[x][y] = new TsarLetiCluster<dspin_cmd_width,
704                                                 dspin_rsp_width,
705                                                 vci_param_int,
706                                                 vci_param_ext>
707            (
708                "cluster",
709                NB_PROCS_MAX,
710                x,
711                y,
712                cluster(x,y),
713                maptabd,
714                maptabx,
715                RESET_ADDRESS,
716                X_WIDTH,
717                Y_WIDTH,
718                vci_srcid_width - X_WIDTH - Y_WIDTH,   // l_id width,
719                MEMC_TGTID,
720                XICU_TGTID,
721                MTTY_TGTID,
722                BDEV_TGTID,
723                BDEV_IMAGE_NAME,
724                MEMC_WAYS,
725                MEMC_SETS,
726                L1_IWAYS,
727                L1_ISETS,
728                L1_DWAYS,
729                L1_DSETS,
730                XRAM_LATENCY,
731                loader,
732                frozen_cycles,
733                trace_from,
734                trace_proc_ok, 
735                trace_proc_id,
736                trace_memc_ok, 
737                trace_memc_id
738            );
739
740#if USE_OPENMP
741            } // end critical
742#endif
743        } // end for
744#if USE_OPENMP
745    }
746#endif
747
748    //////////////////////////////////////////////////////////////////
749    // IO bus and external peripherals in cluster[X_SIZE-1,Y_SIZE]
750    //////////////////////////////////////////////////////////////////
751
752    size_t cluster_io = cluster(X_SIZE-1, Y_SIZE);
753
754    //////////// vci_local_crossbar 
755    VciLocalCrossbar<vci_param_int>*
756    iobus = new VciLocalCrossbar<vci_param_int>(
757                "iobus",
758                maptabd,                      // mapping table
759                cluster_io,                   // cluster_xy
760                NB_PROCS_MAX + 3,             // number of local initiators
761                8,                            // number of local targets
762                BDEV_TGTID );                 // default target index
763
764    //////////// vci_framebuffer                       
765    VciFrameBuffer<vci_param_int>*
766    fbuf = new VciFrameBuffer<vci_param_int>(
767                "fbuf",
768                IntTab(cluster_io, FBUF_TGTID),
769                maptabd,
770                FBUF_X_SIZE, FBUF_Y_SIZE );
771
772    ////////////  vci_block_device               
773    VciBlockDeviceTsar<vci_param_int>*
774    bdev = new VciBlockDeviceTsar<vci_param_int>(
775                "bdev",
776                maptabd,
777                IntTab(cluster_io, BDEV_SRCID),
778                IntTab(cluster_io, BDEV_TGTID),
779                BDEV_IMAGE_NAME,
780                512,                          // block size
781                64 );                         // burst size
782
783    //////////// vci_multi_nic               
784    VciMultiNic<vci_param_int>*
785    mnic = new VciMultiNic<vci_param_int>(
786                "mnic",
787                IntTab(cluster_io, MNIC_TGTID),
788                maptabd,
789                NB_NIC_CHANNELS,
790                NIC_MAC4,
791                NIC_MAC2,
792                NIC_RX_NAME,
793                NIC_TX_NAME );
794
795    ///////////// vci_chbuf_dma                   
796    VciChbufDma<vci_param_int>*
797    cdma = new VciChbufDma<vci_param_int>(
798                "cdma",
799                maptabd,
800                IntTab(cluster_io, CDMA_SRCID),
801                IntTab(cluster_io, CDMA_TGTID),
802                64,                          // burst size
803                NB_CMA_CHANNELS ); 
804
805    ////////////// vci_multi_tty
806    std::vector<std::string> vect_names;
807    for (size_t id = 0; id < NB_TTY_CHANNELS; id++)
808    {
809        std::ostringstream term_name;
810        term_name <<  "ext_" << id;
811        vect_names.push_back(term_name.str().c_str());
812    }
813
814    VciMultiTty<vci_param_int>* 
815    mtty = new VciMultiTty<vci_param_int>(
816                "mtty",
817                IntTab(cluster_io, MTTY_TGTID),
818                maptabd,
819                vect_names );
820
821    ///////////// vci_iopic
822    VciIopic<vci_param_int>*
823    iopic = new VciIopic<vci_param_int>(
824                "iopic",
825                maptabd,
826                IntTab(cluster_io, IOPI_SRCID),
827                IntTab(cluster_io, IOPI_TGTID),
828                16 );
829
830    ////////////// vci_dspin wrappers
831    VciDspinTargetWrapper<vci_param_int, dspin_cmd_width, dspin_rsp_width>*
832    wt_iobus = new VciDspinTargetWrapper<vci_param_int, dspin_cmd_width, dspin_rsp_width>(
833                "wt_bdev",
834                vci_srcid_width );
835
836    VciDspinInitiatorWrapper<vci_param_int, dspin_cmd_width, dspin_rsp_width>*
837    wi_iobus = new VciDspinInitiatorWrapper<vci_param_int, dspin_cmd_width, dspin_rsp_width>(
838                "wi_bdev",
839                vci_srcid_width );
840
841    ///////////////////////////////////////////////////////////////
842    //     Net-list
843    ///////////////////////////////////////////////////////////////
844
845    // iobus
846    iobus->p_clk                       (signal_clk); 
847    iobus->p_resetn                    (signal_resetn);
848
849    iobus->p_target_to_up              (signal_vci_cmd_from_noc);
850    iobus->p_initiator_to_up           (signal_vci_cmd_to_noc);
851
852    iobus->p_to_target[MEMC_TGTID]     (signal_vci_tgt_memc);
853    iobus->p_to_target[XICU_TGTID]     (signal_vci_tgt_xicu);
854    iobus->p_to_target[MTTY_TGTID]     (signal_vci_tgt_mtty);
855    iobus->p_to_target[FBUF_TGTID]     (signal_vci_tgt_fbuf);
856    iobus->p_to_target[MNIC_TGTID]     (signal_vci_tgt_mnic);
857    iobus->p_to_target[BDEV_TGTID]     (signal_vci_tgt_bdev);
858    iobus->p_to_target[CDMA_TGTID]     (signal_vci_tgt_cdma);
859    iobus->p_to_target[IOPI_TGTID]     (signal_vci_tgt_iopi);
860
861    for( size_t p=0 ; p<NB_PROCS_MAX ; p++ )
862    {
863        iobus->p_to_initiator[p]       (signal_vci_ini_proc[p]);
864    }
865    iobus->p_to_initiator[BDEV_SRCID]  (signal_vci_ini_bdev);
866    iobus->p_to_initiator[CDMA_SRCID]  (signal_vci_ini_cdma);
867    iobus->p_to_initiator[IOPI_SRCID]  (signal_vci_ini_iopi);
868
869    std::cout << "  - IOBUS connected" << std::endl;
870
871    // block_device
872    bdev->p_clk                        (signal_clk);
873    bdev->p_resetn                     (signal_resetn);
874    bdev->p_vci_target                 (signal_vci_tgt_bdev);
875    bdev->p_vci_initiator              (signal_vci_ini_bdev);
876    bdev->p_irq                        (signal_irq_bdev);
877
878    std::cout << "  - BDEV connected" << std::endl;
879
880    // frame_buffer
881    fbuf->p_clk                        (signal_clk);
882    fbuf->p_resetn                     (signal_resetn);
883    fbuf->p_vci                        (signal_vci_tgt_fbuf);
884
885    std::cout << "  - FBUF connected" << std::endl;
886
887    // multi_nic
888    mnic->p_clk                        (signal_clk);
889    mnic->p_resetn                     (signal_resetn);
890    mnic->p_vci                        (signal_vci_tgt_mnic);
891    for ( size_t i=0 ; i<NB_NIC_CHANNELS ; i++ )
892    {
893         mnic->p_rx_irq[i]             (signal_irq_mnic_rx[i]);
894         mnic->p_tx_irq[i]             (signal_irq_mnic_tx[i]);
895    }
896
897    std::cout << "  - MNIC connected" << std::endl;
898
899    // chbuf_dma
900    cdma->p_clk                        (signal_clk);
901    cdma->p_resetn                     (signal_resetn);
902    cdma->p_vci_target                 (signal_vci_tgt_cdma);
903    cdma->p_vci_initiator              (signal_vci_ini_cdma);
904    for ( size_t i=0 ; i<NB_CMA_CHANNELS ; i++)
905    {
906        cdma->p_irq[i]                 (signal_irq_cdma[i]);
907    }
908
909    std::cout << "  - CDMA connected" << std::endl;
910
911    // multi_tty
912    mtty->p_clk                        (signal_clk);
913    mtty->p_resetn                     (signal_resetn);
914    mtty->p_vci                        (signal_vci_tgt_mtty);
915    for ( size_t i=0 ; i<NB_TTY_CHANNELS ; i++ )
916    {
917        mtty->p_irq[i]                  (signal_irq_mtty[i]);
918    }
919
920    std::cout << "  - MTTY connected" << std::endl;
921
922    // iopic
923    iopic->p_clk                       (signal_clk);
924    iopic->p_resetn                    (signal_resetn);
925    iopic->p_vci_target                (signal_vci_tgt_iopi);
926    iopic->p_vci_initiator             (signal_vci_ini_iopi);
927    for ( size_t i=0 ; i<16 ; i++)
928    {
929       if     (i < NB_NIC_CHANNELS)    iopic->p_hwi[i] (signal_irq_mnic_rx[i]);
930       else if(i < 2 )                 iopic->p_hwi[i] (signal_irq_false);
931       else if(i < 2+NB_NIC_CHANNELS)  iopic->p_hwi[i] (signal_irq_mnic_tx[i-2]);
932       else if(i < 4 )                 iopic->p_hwi[i] (signal_irq_false);
933       else if(i < 4+NB_CMA_CHANNELS)  iopic->p_hwi[i] (signal_irq_cdma[i-4]);
934       else if(i < 9)                  iopic->p_hwi[i] (signal_irq_false);
935       else if(i == 9)                 iopic->p_hwi[i] (signal_irq_bdev);
936       else if(i < 12)                 iopic->p_hwi[i] (signal_irq_false);
937       else if(i < 12+NB_TTY_CHANNELS) iopic->p_hwi[i] (signal_irq_mtty[i-12]);
938       else                            iopic->p_hwi[i] (signal_irq_false);
939    }
940
941    // vci/dspin wrappers
942    wi_iobus->p_clk                    (signal_clk);
943    wi_iobus->p_resetn                 (signal_resetn);
944    wi_iobus->p_vci                    (signal_vci_cmd_to_noc);
945    wi_iobus->p_dspin_cmd              (signal_dspin_bound_cmd_in[X_SIZE-1][Y_SIZE-1][NORTH]);
946    wi_iobus->p_dspin_rsp              (signal_dspin_bound_rsp_out[X_SIZE-1][Y_SIZE-1][NORTH]);
947
948    // vci/dspin wrappers
949    wt_iobus->p_clk                    (signal_clk);
950    wt_iobus->p_resetn                 (signal_resetn);
951    wt_iobus->p_vci                    (signal_vci_cmd_from_noc);
952    wt_iobus->p_dspin_cmd              (signal_dspin_bound_cmd_out[X_SIZE-1][Y_SIZE-1][NORTH]);
953    wt_iobus->p_dspin_rsp              (signal_dspin_bound_rsp_in[X_SIZE-1][Y_SIZE-1][NORTH]);
954
955    // Clock & RESET for clusters
956    for (size_t x = 0; x < (X_SIZE); x++)
957    {
958        for (size_t y = 0; y < Y_SIZE; y++)
959        {
960            clusters[x][y]->p_clk                    (signal_clk);
961            clusters[x][y]->p_resetn                 (signal_resetn);
962        }
963    }
964
965    // Inter Clusters horizontal connections
966    if (X_SIZE > 1)
967    {
968        for (size_t x = 0; x < (X_SIZE-1); x++)
969        {
970            for (size_t y = 0; y < Y_SIZE; y++)
971            {
972                clusters[x][y]->p_cmd_out[EAST]      (signal_dspin_h_cmd_inc[x][y]);
973                clusters[x+1][y]->p_cmd_in[WEST]     (signal_dspin_h_cmd_inc[x][y]);
974                clusters[x][y]->p_cmd_in[EAST]       (signal_dspin_h_cmd_dec[x][y]);
975                clusters[x+1][y]->p_cmd_out[WEST]    (signal_dspin_h_cmd_dec[x][y]);
976
977                clusters[x][y]->p_rsp_out[EAST]      (signal_dspin_h_rsp_inc[x][y]);
978                clusters[x+1][y]->p_rsp_in[WEST]     (signal_dspin_h_rsp_inc[x][y]);
979                clusters[x][y]->p_rsp_in[EAST]       (signal_dspin_h_rsp_dec[x][y]);
980                clusters[x+1][y]->p_rsp_out[WEST]    (signal_dspin_h_rsp_dec[x][y]);
981
982                clusters[x][y]->p_m2p_out[EAST]      (signal_dspin_h_m2p_inc[x][y]);
983                clusters[x+1][y]->p_m2p_in[WEST]     (signal_dspin_h_m2p_inc[x][y]);
984                clusters[x][y]->p_m2p_in[EAST]       (signal_dspin_h_m2p_dec[x][y]);
985                clusters[x+1][y]->p_m2p_out[WEST]    (signal_dspin_h_m2p_dec[x][y]);
986
987                clusters[x][y]->p_p2m_out[EAST]      (signal_dspin_h_p2m_inc[x][y]);
988                clusters[x+1][y]->p_p2m_in[WEST]     (signal_dspin_h_p2m_inc[x][y]);
989                clusters[x][y]->p_p2m_in[EAST]       (signal_dspin_h_p2m_dec[x][y]);
990                clusters[x+1][y]->p_p2m_out[WEST]    (signal_dspin_h_p2m_dec[x][y]);
991
992                clusters[x][y]->p_cla_out[EAST]      (signal_dspin_h_cla_inc[x][y]);
993                clusters[x+1][y]->p_cla_in[WEST]     (signal_dspin_h_cla_inc[x][y]);
994                clusters[x][y]->p_cla_in[EAST]       (signal_dspin_h_cla_dec[x][y]);
995                clusters[x+1][y]->p_cla_out[WEST]    (signal_dspin_h_cla_dec[x][y]);
996            }
997        }
998    }
999    std::cout << std::endl << "Horizontal connections done" << std::endl;   
1000
1001    // Inter Clusters vertical connections
1002    if (Y_SIZE > 1) 
1003    {
1004        for (size_t y = 0; y < (Y_SIZE-1); y++)
1005        {
1006            for (size_t x = 0; x < X_SIZE; x++)
1007            {
1008                clusters[x][y]->p_cmd_out[NORTH]     (signal_dspin_v_cmd_inc[x][y]);
1009                clusters[x][y+1]->p_cmd_in[SOUTH]    (signal_dspin_v_cmd_inc[x][y]);
1010                clusters[x][y]->p_cmd_in[NORTH]      (signal_dspin_v_cmd_dec[x][y]);
1011                clusters[x][y+1]->p_cmd_out[SOUTH]   (signal_dspin_v_cmd_dec[x][y]);
1012
1013                clusters[x][y]->p_rsp_out[NORTH]     (signal_dspin_v_rsp_inc[x][y]);
1014                clusters[x][y+1]->p_rsp_in[SOUTH]    (signal_dspin_v_rsp_inc[x][y]);
1015                clusters[x][y]->p_rsp_in[NORTH]      (signal_dspin_v_rsp_dec[x][y]);
1016                clusters[x][y+1]->p_rsp_out[SOUTH]   (signal_dspin_v_rsp_dec[x][y]);
1017
1018                clusters[x][y]->p_m2p_out[NORTH]     (signal_dspin_v_m2p_inc[x][y]);
1019                clusters[x][y+1]->p_m2p_in[SOUTH]    (signal_dspin_v_m2p_inc[x][y]);
1020                clusters[x][y]->p_m2p_in[NORTH]      (signal_dspin_v_m2p_dec[x][y]);
1021                clusters[x][y+1]->p_m2p_out[SOUTH]   (signal_dspin_v_m2p_dec[x][y]);
1022
1023                clusters[x][y]->p_p2m_out[NORTH]     (signal_dspin_v_p2m_inc[x][y]);
1024                clusters[x][y+1]->p_p2m_in[SOUTH]    (signal_dspin_v_p2m_inc[x][y]);
1025                clusters[x][y]->p_p2m_in[NORTH]      (signal_dspin_v_p2m_dec[x][y]);
1026                clusters[x][y+1]->p_p2m_out[SOUTH]   (signal_dspin_v_p2m_dec[x][y]);
1027
1028                clusters[x][y]->p_cla_out[NORTH]     (signal_dspin_v_cla_inc[x][y]);
1029                clusters[x][y+1]->p_cla_in[SOUTH]    (signal_dspin_v_cla_inc[x][y]);
1030                clusters[x][y]->p_cla_in[NORTH]      (signal_dspin_v_cla_dec[x][y]);
1031                clusters[x][y+1]->p_cla_out[SOUTH]   (signal_dspin_v_cla_dec[x][y]);
1032            }
1033        }
1034    }
1035    std::cout << std::endl << "Vertical connections done" << std::endl;
1036
1037    // East & West boundary cluster connections
1038    for (size_t y = 0; y < Y_SIZE; y++)
1039    {
1040        clusters[0][y]->p_cmd_in[WEST]           (signal_dspin_bound_cmd_in[0][y][WEST]);
1041        clusters[0][y]->p_cmd_out[WEST]          (signal_dspin_bound_cmd_out[0][y][WEST]);
1042        clusters[X_SIZE-1][y]->p_cmd_in[EAST]    (signal_dspin_bound_cmd_in[X_SIZE-1][y][EAST]);
1043        clusters[X_SIZE-1][y]->p_cmd_out[EAST]   (signal_dspin_bound_cmd_out[X_SIZE-1][y][EAST]);
1044
1045        clusters[0][y]->p_rsp_in[WEST]           (signal_dspin_bound_rsp_in[0][y][WEST]);
1046        clusters[0][y]->p_rsp_out[WEST]          (signal_dspin_bound_rsp_out[0][y][WEST]);
1047        clusters[X_SIZE-1][y]->p_rsp_in[EAST]    (signal_dspin_bound_rsp_in[X_SIZE-1][y][EAST]);
1048        clusters[X_SIZE-1][y]->p_rsp_out[EAST]   (signal_dspin_bound_rsp_out[X_SIZE-1][y][EAST]);
1049
1050        clusters[0][y]->p_m2p_in[WEST]           (signal_dspin_bound_m2p_in[0][y][WEST]);
1051        clusters[0][y]->p_m2p_out[WEST]          (signal_dspin_bound_m2p_out[0][y][WEST]);
1052        clusters[X_SIZE-1][y]->p_m2p_in[EAST]    (signal_dspin_bound_m2p_in[X_SIZE-1][y][EAST]);
1053        clusters[X_SIZE-1][y]->p_m2p_out[EAST]   (signal_dspin_bound_m2p_out[X_SIZE-1][y][EAST]);
1054
1055        clusters[0][y]->p_p2m_in[WEST]           (signal_dspin_bound_p2m_in[0][y][WEST]);
1056        clusters[0][y]->p_p2m_out[WEST]          (signal_dspin_bound_p2m_out[0][y][WEST]);
1057        clusters[X_SIZE-1][y]->p_p2m_in[EAST]    (signal_dspin_bound_p2m_in[X_SIZE-1][y][EAST]);
1058        clusters[X_SIZE-1][y]->p_p2m_out[EAST]   (signal_dspin_bound_p2m_out[X_SIZE-1][y][EAST]);
1059
1060        clusters[0][y]->p_cla_in[WEST]           (signal_dspin_bound_cla_in[0][y][WEST]);
1061        clusters[0][y]->p_cla_out[WEST]          (signal_dspin_bound_cla_out[0][y][WEST]);
1062        clusters[X_SIZE-1][y]->p_cla_in[EAST]    (signal_dspin_bound_cla_in[X_SIZE-1][y][EAST]);
1063        clusters[X_SIZE-1][y]->p_cla_out[EAST]   (signal_dspin_bound_cla_out[X_SIZE-1][y][EAST]);
1064    }
1065
1066    // North & South boundary clusters connections
1067    for (size_t x = 0; x < X_SIZE; x++)
1068    {
1069        clusters[x][0]->p_cmd_in[SOUTH]          (signal_dspin_bound_cmd_in[x][0][SOUTH]);
1070        clusters[x][0]->p_cmd_out[SOUTH]         (signal_dspin_bound_cmd_out[x][0][SOUTH]);
1071        clusters[x][Y_SIZE-1]->p_cmd_in[NORTH]   (signal_dspin_bound_cmd_in[x][Y_SIZE-1][NORTH]);
1072        clusters[x][Y_SIZE-1]->p_cmd_out[NORTH]  (signal_dspin_bound_cmd_out[x][Y_SIZE-1][NORTH]);
1073
1074        clusters[x][0]->p_rsp_in[SOUTH]          (signal_dspin_bound_rsp_in[x][0][SOUTH]);
1075        clusters[x][0]->p_rsp_out[SOUTH]         (signal_dspin_bound_rsp_out[x][0][SOUTH]);
1076        clusters[x][Y_SIZE-1]->p_rsp_in[NORTH]   (signal_dspin_bound_rsp_in[x][Y_SIZE-1][NORTH]);
1077        clusters[x][Y_SIZE-1]->p_rsp_out[NORTH]  (signal_dspin_bound_rsp_out[x][Y_SIZE-1][NORTH]);
1078
1079        clusters[x][0]->p_m2p_in[SOUTH]          (signal_dspin_bound_m2p_in[x][0][SOUTH]);
1080        clusters[x][0]->p_m2p_out[SOUTH]         (signal_dspin_bound_m2p_out[x][0][SOUTH]);
1081        clusters[x][Y_SIZE-1]->p_m2p_in[NORTH]   (signal_dspin_bound_m2p_in[x][Y_SIZE-1][NORTH]);
1082        clusters[x][Y_SIZE-1]->p_m2p_out[NORTH]  (signal_dspin_bound_m2p_out[x][Y_SIZE-1][NORTH]);
1083
1084        clusters[x][0]->p_p2m_in[SOUTH]          (signal_dspin_bound_p2m_in[x][0][SOUTH]);
1085        clusters[x][0]->p_p2m_out[SOUTH]         (signal_dspin_bound_p2m_out[x][0][SOUTH]);
1086        clusters[x][Y_SIZE-1]->p_p2m_in[NORTH]   (signal_dspin_bound_p2m_in[x][Y_SIZE-1][NORTH]);
1087        clusters[x][Y_SIZE-1]->p_p2m_out[NORTH]  (signal_dspin_bound_p2m_out[x][Y_SIZE-1][NORTH]);
1088
1089        clusters[x][0]->p_cla_in[SOUTH]          (signal_dspin_bound_cla_in[x][0][SOUTH]);
1090        clusters[x][0]->p_cla_out[SOUTH]         (signal_dspin_bound_cla_out[x][0][SOUTH]);
1091        clusters[x][Y_SIZE-1]->p_cla_in[NORTH]   (signal_dspin_bound_cla_in[x][Y_SIZE-1][NORTH]);
1092        clusters[x][Y_SIZE-1]->p_cla_out[NORTH]  (signal_dspin_bound_cla_out[x][Y_SIZE-1][NORTH]);
1093    }
1094
1095    std::cout << std::endl << "North, South, West, East connections done" << std::endl;
1096    std::cout << std::endl;
1097
1098    ////////////////////////////////////////////////////////
1099    //   Simulation
1100    ///////////////////////////////////////////////////////
1101
1102    sc_start(sc_core::sc_time(0, SC_NS));
1103    signal_resetn    = false;
1104    signal_irq_false = false;
1105
1106    // set network boundaries signals default values
1107    // for all boundary clusters but the IO cluster
1108    for (size_t x = 0; x < X_SIZE ; x++)
1109    {
1110        for (size_t y = 0; y < Y_SIZE ; y++)
1111        {
1112            for (size_t face = 0; face < 4; face++)
1113            {
1114                if ( (x != X_SIZE-1) or (y != Y_SIZE-1) or (face != NORTH) )
1115                {
1116                    signal_dspin_bound_cmd_in [x][y][face].write = false;
1117                    signal_dspin_bound_cmd_in [x][y][face].read  = true;
1118                    signal_dspin_bound_cmd_out[x][y][face].write = false;
1119                    signal_dspin_bound_cmd_out[x][y][face].read  = true;
1120
1121                    signal_dspin_bound_rsp_in [x][y][face].write = false;
1122                    signal_dspin_bound_rsp_in [x][y][face].read  = true;
1123                    signal_dspin_bound_rsp_out[x][y][face].write = false;
1124                    signal_dspin_bound_rsp_out[x][y][face].read  = true;
1125                }
1126
1127                signal_dspin_bound_m2p_in [x][y][face].write = false;
1128                signal_dspin_bound_m2p_in [x][y][face].read  = true;
1129                signal_dspin_bound_m2p_out[x][y][face].write = false;
1130                signal_dspin_bound_m2p_out[x][y][face].read  = true;
1131
1132                signal_dspin_bound_p2m_in [x][y][face].write = false;
1133                signal_dspin_bound_p2m_in [x][y][face].read  = true;
1134                signal_dspin_bound_p2m_out[x][y][face].write = false;
1135                signal_dspin_bound_p2m_out[x][y][face].read  = true;
1136
1137                signal_dspin_bound_cla_in [x][y][face].write = false;
1138                signal_dspin_bound_cla_in [x][y][face].read  = true;
1139                signal_dspin_bound_cla_out[x][y][face].write = false;
1140                signal_dspin_bound_cla_out[x][y][face].read  = true;
1141            }
1142        }
1143    }
1144
1145    sc_start(sc_core::sc_time(1, SC_NS));
1146    signal_resetn = true;
1147
1148    if (gettimeofday(&t1, NULL) != 0) 
1149    {
1150        perror("gettimeofday");
1151        return EXIT_FAILURE;
1152    }
1153
1154   for (uint64_t n = 1; n < ncycles && !stop_called; n++)
1155   {
1156      // Monitor a specific address for L1 & L2 caches
1157      // clusters[0][0]->proc[0]->cache_monitor(0x0000010000ULL);
1158      // clusters[0][0]->memc->cache_monitor(0x0000030000ULL);
1159
1160      if( (n % 5000000) == 0)
1161      {
1162
1163         if (gettimeofday(&t2, NULL) != 0) 
1164         {
1165            perror("gettimeofday");
1166            return EXIT_FAILURE;
1167         }
1168
1169         ms1 = (uint64_t) t1.tv_sec * 1000ULL + (uint64_t) t1.tv_usec / 1000;
1170         ms2 = (uint64_t) t2.tv_sec * 1000ULL + (uint64_t) t2.tv_usec / 1000;
1171         std::cerr << "platform clock frequency " 
1172                   << (double) 5000000 / (double) (ms2 - ms1) << "Khz" << std::endl;
1173
1174         if (gettimeofday(&t1, NULL) != 0) 
1175         {
1176            perror("gettimeofday");
1177            return EXIT_FAILURE;
1178         }
1179      }
1180
1181      if ( trace_ok and (n > trace_from) )
1182      {
1183         std::cout << "****************** cycle " << std::dec << n ;
1184         std::cout << " ************************************************" << std::endl;
1185
1186        // trace proc[trace_proc_id]
1187        size_t l = trace_proc_id % NB_PROCS_MAX ;
1188        size_t x = (trace_proc_id / NB_PROCS_MAX) >> Y_WIDTH ;
1189        size_t y = (trace_proc_id / NB_PROCS_MAX) & ((1<<Y_WIDTH) - 1);
1190
1191        std::ostringstream proc_signame;
1192        proc_signame << "[SIG]PROC_" << x << "_" << y << "_" << l ;
1193        std::ostringstream xicu_signame;
1194        xicu_signame << "[SIG]XICU_" << x << "_" << y ;
1195
1196        clusters[x][y]->proc[l]->print_trace(0x1);
1197        clusters[x][y]->signal_vci_ini_proc[l].print_trace(proc_signame.str());
1198
1199        clusters[x][y]->xicu->print_trace(0);
1200        clusters[x][y]->signal_vci_tgt_xicu.print_trace(xicu_signame.str());
1201     
1202        if ( clusters[x][y]->signal_proc_irq[0].read() ) 
1203            std::cout << " IRQ_PROC active in cluster " << cluster(x,y) << std::endl;
1204     
1205        if ( signal_irq_bdev.read() ) 
1206            std::cout << " IRQ_BDEV in cluster_io active" << std::endl;
1207     
1208        // trace memc[trace_memc_id] and xram[trace_memc_id]
1209        x = trace_memc_id >> Y_WIDTH;
1210        y = trace_memc_id & ((1<<Y_WIDTH) - 1);
1211
1212        std::ostringstream smemc;
1213        smemc << "[SIG]MEMC_" << x << "_" << y;
1214        std::ostringstream sxram;
1215        sxram << "[SIG]XRAM_" << x << "_" << y;
1216
1217        clusters[x][y]->memc->print_trace();
1218        clusters[x][y]->signal_vci_tgt_memc.print_trace(smemc.str());
1219        clusters[x][y]->signal_vci_xram.print_trace(sxram.str());
1220       
1221        // trace coherence signals
1222        // clusters[0][0]->signal_dspin_m2p_proc[0].print_trace("[CC_M2P_0_0]");
1223        // clusters[0][1]->signal_dspin_m2p_proc[0].print_trace("[CC_M2P_0_1]");
1224        // clusters[1][0]->signal_dspin_m2p_proc[0].print_trace("[CC_M2P_1_0]");
1225        // clusters[1][1]->signal_dspin_m2p_proc[0].print_trace("[CC_M2P_1_1]");
1226
1227        // clusters[0][0]->signal_dspin_p2m_proc[0].print_trace("[CC_P2M_0_0]");
1228        // clusters[0][1]->signal_dspin_p2m_proc[0].print_trace("[CC_P2M_0_1]");
1229        // clusters[1][0]->signal_dspin_p2m_proc[0].print_trace("[CC_P2M_1_0]");
1230        // clusters[1][1]->signal_dspin_p2m_proc[0].print_trace("[CC_P2M_1_1]");
1231
1232        // trace xbar(s) m2p
1233        // clusters[0][0]->xbar_m2p->print_trace();
1234        // clusters[1][0]->xbar_m2p->print_trace();
1235        // clusters[0][1]->xbar_m2p->print_trace();
1236        // clusters[1][1]->xbar_m2p->print_trace();
1237       
1238        // trace router(s) m2p
1239        // clusters[0][0]->router_m2p->print_trace();
1240        // clusters[1][0]->router_m2p->print_trace();
1241        // clusters[0][1]->router_m2p->print_trace();
1242        // clusters[1][1]->router_m2p->print_trace();
1243       
1244        // trace external peripherals
1245        bdev->print_trace();
1246        signal_vci_tgt_bdev.print_trace("[SIG]BDEV_TGT");
1247        signal_vci_ini_bdev.print_trace("[SIG]BDEV_INI");
1248
1249        iopic->print_trace();
1250        signal_vci_tgt_iopi.print_trace("[SIG]IOPI_TGT");
1251        signal_vci_ini_iopi.print_trace("[SIG]IOPI_INI");
1252
1253        clusters[0][0]->mtty->print_trace();
1254        clusters[0][0]->signal_vci_tgt_mtty.print_trace("[SIG]MTTY");
1255      }  // end trace
1256
1257      sc_start(sc_core::sc_time(1, SC_NS));
1258   }
1259
1260   
1261   // Free memory
1262   for (size_t i = 0; i  < (X_SIZE * Y_SIZE); i++)
1263   {
1264      size_t x = i / Y_SIZE;
1265      size_t y = i % Y_SIZE;
1266      delete clusters[x][y];
1267   }
1268
1269   return EXIT_SUCCESS;
1270}
1271
1272
1273void handler(int dummy = 0) 
1274{
1275   stop_called = true;
1276   sc_stop();
1277}
1278
1279void voidhandler(int dummy = 0) {}
1280
1281int sc_main (int argc, char *argv[])
1282{
1283   signal(SIGINT, handler);
1284   signal(SIGPIPE, voidhandler);
1285
1286   try {
1287      return _main(argc, argv);
1288   } catch (std::exception &e) {
1289      std::cout << e.what() << std::endl;
1290   } catch (...) {
1291      std::cout << "Unknown exception occured" << std::endl;
1292      throw;
1293   }
1294   return 1;
1295}
1296
1297
1298// Local Variables:
1299// tab-width: 3
1300// c-basic-offset: 3
1301// c-file-offsets:((innamespace . 0)(inline-open . 0))
1302// indent-tabs-mode: nil
1303// End:
1304
1305// vim: filetype=cpp:expandtab:shiftwidth=3:tabstop=3:softtabstop=3
Note: See TracBrowser for help on using the repository browser.