source: branches/reconfiguration/platforms/tsar_generic_iob/top.cpp @ 1007

Last change on this file since 1007 was 1007, checked in by cfuguet, 9 years ago

reconf: update the reconfiguration/tsar_generic_iob to comply with new
constructor parameters of the NIC and CHBUF_DMA peripherals.

File size: 74.6 KB
Line 
1///////////////////////////////////////////////////////////////////////////////
2// File: top.cpp  (for tsar_generic_iob platform)
3// Author: Alain Greiner
4// Copyright: UPMC/LIP6
5// Date : august 2013
6// This program is released under the GNU public license
7//
8// Modified by: Cesar Fuguet
9///////////////////////////////////////////////////////////////////////////////
10// This file define a generic TSAR architecture with an IO network emulating
11// an external bus (i.e. Hypertransport) to access 7 external peripherals:
12//
13// - FBUF : Frame Buffer
14// - MTTY : multi TTY (one channel)
15// - MNIC : Network controller (up to 2 channels)
16// - CDMA : Chained Buffer DMA controller (up to 4 channels)
17// - BDEV : Dlock Device controler (one channel)
18// - IOPI : HWI to SWI translator.
19// - SIMH : Simulation Helper
20//
21// The internal physical address space is 40 bits, and the cluster index
22// is defined by the 8 MSB bits, using a fixed format: X is encoded on 4 bits,
23// Y is encodes on 4 bits, whatever the actual mesh size.
24// => at most 16 * 16 clusters. Each cluster contains up to 4 processors.
25//
26// It contains 3 networks:
27//
28// 1) the "INT" network supports Read/Write transactions
29//    between processors and L2 caches or peripherals.
30//    (VCI ADDDRESS = 40 bits / VCI DATA width = 32 bits)
31//    It supports also coherence transactions between L1 & L2 caches.
32// 3) the "RAM" network emulates the 3D network between L2 caches
33//    and L3 caches, and is implemented as a 2D mesh between the L2 caches,
34//    the two IO bridges and the physical RAMs disributed in all clusters.
35//    (VCI ADDRESS = 40 bits / VCI DATA = 64 bits)
36// 4) the IOX network connects the two IO bridge components to the
37//    7 external peripheral controllers.
38//    (VCI ADDDRESS = 40 bits / VCI DATA width = 64 bits)
39//
40// The external peripherals HWI IRQs are translated to WTI IRQs by the
41// external IOPIC component, that must be configured by the OS to route
42// these WTI IRQS to one or several internal XICU components.
43// - IOPIC HWI[1:0]     connected to IRQ_NIC_RX[1:0]
44// - IOPIC HWI[3:2]     connected to IRQ_NIC_TX[1:0]
45// - IOPIC HWI[7:4]     connected to IRQ_CMA_TX[3:0]]
46// - IOPIC HWI[8]       connected to IRQ_BDEV
47// - IOPIC HWI[31:16]   connected to IRQ_TTY_RX[15:0]
48//
49// Besides the external peripherals, each cluster contains one XICU component,
50// and one multi channels DMA component.
51// The XICU component is mainly used to handle WTI IRQs, as only 5 HWI IRQs
52// are connected to XICU in each cluster:
53// - IRQ_IN[0] : MMC
54// - IRQ_IN[1] : DMA channel 0
55// - IRQ_IN[2] : DMA channel 1
56// - IRQ_IN[3] : DMA channel 2
57// - IRQ_IN[4] : DMA channel 3
58//
59// All clusters are identical, but cluster(0, 0) and cluster(X_SIZE-1, Y_SIZE-1)
60// contain an extra IO bridge component. These IOB0 & IOB1 components are
61// connected to the three networks (INT, RAM, IOX).
62//
63// - It uses two dspin_local_crossbar per cluster to implement the
64//   local interconnect correponding to the INT network.
65// - It uses three dspin_local_crossbar per cluster to implement the
66//   local interconnect correponding to the coherence INT network.
67// - It uses two virtual_dspin_router per cluster to implement
68//   the INT network (routing both the direct and coherence trafic).
69// - It uses two dspin_router per cluster to implement the RAM network.
70// - It uses the vci_cc_vcache_wrapper.
71// - It uses the vci_mem_cache.
72// - It contains one vci_xicu and one vci_multi_dma per cluster.
73// - It contains one vci_simple ram per cluster to model the L3 cache.
74//
75// The TsarIobCluster component is defined in files
76// tsar_iob_cluster.* (with * = cpp, h, sd)
77//
78// The main hardware parameters must be defined in the hard_config.h file :
79// - X_SIZE           : number of clusters in a row
80// - Y_SIZE           : number of clusters in a column
81// - NB_PROCS_MAX     : number of processors per cluster (power of 2)
82// - NB_TTY_CHANNELS  : number of TTY channels in I/O network (up to 16)
83// - NB_NIC_CHANNELS  : number of NIC channels in I/O network (up to 2)
84// - NB_CMA_CHANNELS  : number of CMA channels in I/O network (up to 4)
85// - FBUF_X_SIZE      : width of frame buffer (pixels)
86// - FBUF_Y_SIZE      : heigth of frame buffer (lines)
87// - XCU_NB_HWI       : number of HWIs
88// - XCU_NB_PTI       : number of PTIs
89// - XCU_NB_WTI       : number of WTIs
90// - XCU_NB_OUT       : number of OUTs
91//
92// Some secondary hardware parameters must be defined in this top.cpp file:
93// - XRAM_LATENCY     : external ram latency
94// - MEMC_WAYS        : L2 cache number of ways
95// - MEMC_SETS        : L2 cache number of sets
96// - L1_IWAYS
97// - L1_ISETS
98// - L1_DWAYS
99// - L1_DSETS
100// - BDEV_IMAGE_NAME  : file pathname for block device
101// - NIC_TIMEOUT      : max number of cycles before closing a container
102//
103// General policy for 40 bits physical address decoding:
104// All physical segments base addresses are multiple of 1 Mbytes
105// (=> the 24 LSB bits = 0, and the 16 MSB bits define the target)
106// The (X_WIDTH + Y_WIDTH) MSB bits (left aligned) define
107// the cluster index, and the LADR bits define the local index:
108//      |X_ID|Y_ID|  LADR  |     OFFSET          |
109//      |  4 |  4 |   8    |       24            |
110//
111// General policy for 14 bits SRCID decoding:
112// Each component is identified by (x_id, y_id, l_id) tuple.
113//      |X_ID|Y_ID| L_ID |
114//      |  4 |  4 |  6   |
115/////////////////////////////////////////////////////////////////////////
116
117#include <systemc>
118#include <sys/time.h>
119#include <iostream>
120#include <sstream>
121#include <cstdlib>
122#include <cstdarg>
123#include <climits>
124#include <stdint.h>
125#include <vector>
126
127#include "gdbserver.h"
128#include "mapping_table.h"
129
130#include "tsar_iob_cluster.h"
131#include "vci_chbuf_dma.h"
132#include "vci_multi_tty.h"
133#include "vci_multi_nic.h"
134#include "vci_target_error.h"
135#include "vci_simple_rom.h"
136#include "vci_block_device_tsar.h"
137#include "vci_framebuffer.h"
138#include "vci_iox_network.h"
139#include "vci_iopic.h"
140#include "vci_simhelper.h"
141
142#include "alloc_elems.h"
143
144///////////////////////////////////////////////////
145//      OS
146///////////////////////////////////////////////////
147#define USE_ALMOS 0
148
149#define almos_bootloader_pathname "bootloader.bin"
150#define almos_kernel_pathname     "kernel-soclib.bin@0xbfc10000:D"
151#define almos_archinfo_pathname   "arch-info.bin@0xBFC08000:D"
152
153///////////////////////////////////////////////////////////
154//               Parallelisation
155//
156// The _OPENMP flag is defined automatically by the
157// compilation environment when compiling with the OpenMP
158// support
159///////////////////////////////////////////////////////////
160#if _OPENMP
161#include <omp.h>
162#endif
163
164///////////////////////////////////////////////////////////
165//          DSPIN parameters
166///////////////////////////////////////////////////////////
167
168#define dspin_int_cmd_width   39
169#define dspin_int_rsp_width   32
170
171#define dspin_ram_cmd_width   64
172#define dspin_ram_rsp_width   64
173
174///////////////////////////////////////////////////////////
175//         VCI fields width  for the 3 VCI networks
176///////////////////////////////////////////////////////////
177
178#define vci_cell_width_int    4
179#define vci_cell_width_ext    8
180
181#define vci_plen_width        8
182#define vci_address_width     40
183#define vci_rerror_width      1
184#define vci_clen_width        1
185#define vci_rflag_width       1
186#define vci_srcid_width       14
187#define vci_pktid_width       4
188#define vci_trdid_width       4
189#define vci_wrplen_width      1
190
191////////////////////////////////////////////////////////////
192//    Main Hardware Parameters values
193//////////////////////i/////////////////////////////////////
194
195#include "hard_config.h"
196
197////////////////////////////////////////////////////////////
198//    Secondary Hardware Parameters values
199//////////////////////i/////////////////////////////////////
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 BDEV_IMAGE_NAME       "../../../giet_vm/hdd/virt_hdd.dmg"
213
214#define NIC_TIMEOUT           10000
215
216#define NORTH                 0
217#define SOUTH                 1
218#define EAST                  2
219#define WEST                  3
220
221#define cluster(x, y)   ((y) + ((x) << Y_WIDTH))
222
223////////////////////////////////////////////////////////////
224//     DEBUG Parameters default values
225//////////////////////i/////////////////////////////////////
226
227#define MAX_FROZEN_CYCLES     200000
228
229/////////////////////////////////////////////////////////
230//    Physical segments definition
231/////////////////////////////////////////////////////////
232
233// All physical segments base addresses and sizes are defined
234// in the hard_config.h file. For replicated segments, the
235// base address is incremented by a cluster offset:
236// offset  = cluster(x, y) << (address_width-X_WIDTH-Y_WIDTH);
237
238////////////////////////////////////////////////////////////////////////
239//          SRCID definition
240////////////////////////////////////////////////////////////////////////
241// All initiators are in the same indexing space (14 bits).
242// The SRCID is structured in two fields:
243// - The 8 MSB bits define the cluster index (left aligned)
244// - The 6 LSB bits define the local index.
245// Two different initiators cannot have the same SRCID, but a given
246// initiator can have two alias SRCIDs:
247// - Internal initiators (procs, mdma) are replicated in all clusters,
248//   and each initiator has one single SRCID.
249// - External initiators (bdev, cdma) are not replicated, but can be
250//   accessed in 2 clusters : cluster_iob0 and cluster_iob1.
251//   They have the same local index, but two different cluster indexes.
252//
253// As cluster_iob0 and cluster_iob1 contain both internal initiators
254// and external initiators, they must have different local indexes.
255// Consequence: For a local interconnect, the INI_ID port index
256// is NOT equal to the SRCID local index, and the local interconnect
257// must make a translation: SRCID => INI_ID
258////////////////////////////////////////////////////////////////////////
259
260#define PROC_LOCAL_SRCID             0x0    // from 0 to 7
261#define MDMA_LOCAL_SRCID             0x8
262#define IOBX_LOCAL_SRCID             0x9
263#define MEMC_LOCAL_SRCID             0xA
264#define CDMA_LOCAL_SRCID             0xB
265#define BDEV_LOCAL_SRCID             0xC
266#define IOPI_LOCAL_SRCID             0xD
267
268///////////////////////////////////////////////////////////////////////
269//     TGT_ID and INI_ID port indexing for INT local interconnect
270///////////////////////////////////////////////////////////////////////
271
272#define INT_MEMC_TGT_ID              0
273#define INT_XICU_TGT_ID              1
274#define INT_MDMA_TGT_ID              2
275#define INT_DROM_TGT_ID              3
276#define INT_IOBX_TGT_ID              4
277
278#define INT_PROC_INI_ID              0   // from 0 to (NB_PROCS_MAX-1)
279#define INT_MDMA_INI_ID              (NB_PROCS_MAX)
280#define INT_IOBX_INI_ID              (NB_PROCS_MAX+1)
281
282///////////////////////////////////////////////////////////////////////
283//     TGT_ID and INI_ID port indexing for RAM local interconnect
284///////////////////////////////////////////////////////////////////////
285
286#define RAM_XRAM_TGT_ID              0
287
288#define RAM_MEMC_INI_ID              0
289#define RAM_IOBX_INI_ID              1
290
291///////////////////////////////////////////////////////////////////////
292//     TGT_ID and INI_ID port indexing for I0X local interconnect
293///////////////////////////////////////////////////////////////////////
294
295#define IOX_FBUF_TGT_ID              0
296#define IOX_BDEV_TGT_ID              1
297#define IOX_MNIC_TGT_ID              2
298#define IOX_CDMA_TGT_ID              3
299#define IOX_MTTY_TGT_ID              4
300#define IOX_IOPI_TGT_ID              5
301#define IOX_SIMH_TGT_ID              6
302#define IOX_ROM_TGT_ID               7
303#define IOX_IOB0_TGT_ID              8
304#define IOX_IOB1_TGT_ID              9
305
306#define IOX_BDEV_INI_ID              0
307#define IOX_CDMA_INI_ID              1
308#define IOX_IOPI_INI_ID              2
309#define IOX_IOB0_INI_ID              3
310#define IOX_IOB1_INI_ID              4
311
312////////////////////////////////////////////////////////////////////////
313int _main(int argc, char *argv[])
314////////////////////////////////////////////////////////////////////////
315{
316   using namespace sc_core;
317   using namespace soclib::caba;
318   using namespace soclib::common;
319
320
321   char     dsoft_name[256]  = "";                // pathname: binary code
322   char     soft_name[256]   = "";                // pathname: binary code
323   size_t   ncycles          = UINT_MAX;          // simulated cycles
324   char     disk_name[256]   = BDEV_IMAGE_NAME;   // pathname: disk image
325   ssize_t  threads_nr       = 1;                 // simulator's threads number
326   size_t   faulty_mask      = 0x1F;              // interface mask for the faulty router
327   bool     debug_ok         = false;             // trace activated
328   size_t   debug_period     = 1;                 // trace period
329   size_t   debug_memc_id    = 0xFFFFFFFF;        // index of traced memc
330   size_t   debug_proc_id    = 0xFFFFFFFF;        // index of traced proc
331   size_t   debug_xram_id    = 0xFFFFFFFF;        // index of traced xram
332   bool     debug_iob        = false;             // trace iob0 & iob1 when true
333   uint32_t debug_from       = 0;                 // trace start cycle
334   uint32_t frozen_cycles    = MAX_FROZEN_CYCLES; // monitoring frozen processor
335
336   std::vector<size_t> faulty_routers;
337
338   assert( (X_WIDTH == 4) and (Y_WIDTH == 4) and
339   "ERROR: we must have X_WIDTH == Y_WIDTH == 4");
340
341   ////////////// command line arguments //////////////////////
342   if (argc > 1)
343   {
344      for (int n = 1; n < argc; n = n + 2)
345      {
346         if ((strcmp(argv[n], "-NCYCLES") == 0) && (n+1<argc))
347         {
348            ncycles = strtol(argv[n+1], NULL, 0);
349         }
350         else if ((strcmp(argv[n], "-SOFT") == 0) && (n+1<argc) )
351         {
352            strcpy(soft_name, argv[n+1]);
353         }
354         else if ((strcmp(argv[n], "-DSOFT") == 0) && (n+1<argc) )
355         {
356            strcpy(dsoft_name, argv[n+1]);
357         }
358         else if ((strcmp(argv[n], "-DEBUG") == 0) && (n+1<argc) )
359         {
360            debug_ok = true;
361            debug_from = strtol(argv[n+1], NULL, 0);
362         }
363         else if ((strcmp(argv[n], "-DISK") == 0) && (n+1<argc) )
364         {
365            strcpy(disk_name, argv[n+1]);
366         }
367         else if ((strcmp(argv[n], "-MEMCID") == 0) && (n+1<argc) )
368         {
369            debug_memc_id = strtol(argv[n+1], NULL, 0);
370            size_t x = debug_memc_id >> Y_WIDTH;
371            size_t y = debug_memc_id & ((1 << Y_WIDTH) - 1);
372            if( (x>=X_SIZE) || (y>=Y_SIZE) )
373            {
374                std::cout << "MEMCID parameter does'nt fit X_SIZE/Y_SIZE" << std::endl;
375                exit(0);
376            }
377         }
378         else if ((strcmp(argv[n], "-XRAMID") == 0) && (n+1<argc) )
379         {
380            debug_xram_id = strtol(argv[n+1], NULL, 0);
381            size_t x = debug_xram_id >> Y_WIDTH;
382            size_t y = debug_xram_id & ((1 << Y_WIDTH) - 1);
383            if( (x>=X_SIZE) || (y>=Y_SIZE) )
384            {
385                std::cout << "XRAMID parameter does'nt fit X_SIZE/Y_SIZE" << std::endl;
386                exit(0);
387            }
388         }
389         else if ((strcmp(argv[n], "-IOB") == 0) && (n+1<argc) )
390         {
391            debug_iob = strtol(argv[n+1], NULL, 0);
392         }
393         else if ((strcmp(argv[n], "-PROCID") == 0) && (n+1<argc) )
394         {
395            debug_proc_id     = strtol(argv[n+1], NULL, 0);
396            size_t cluster_xy = debug_proc_id >> P_WIDTH;
397            size_t x          = cluster_xy >> Y_WIDTH;
398            size_t y          = cluster_xy & ((1 << Y_WIDTH) - 1);
399            if( (x>=X_SIZE) || (y>=Y_SIZE) )
400            {
401                std::cout << "PROCID parameter does'nt fit X_SIZE/Y_SIZE" << std::endl;
402                exit(0);
403            }
404         }
405         else if ((strcmp(argv[n], "-THREADS") == 0) && ((n+1) < argc))
406         {
407            threads_nr = strtol(argv[n+1], NULL, 0);
408            threads_nr = (threads_nr < 1) ? 1 : threads_nr;
409         }
410         else if ((strcmp(argv[n], "-FROZEN") == 0) && (n+1 < argc))
411         {
412            frozen_cycles = strtol(argv[n+1], NULL, 0);
413         }
414         else if ((strcmp(argv[n], "-PERIOD") == 0) && (n+1 < argc))
415         {
416            debug_period = strtol(argv[n+1], NULL, 0);
417         }
418         else if ((strcmp(argv[n], "-FAULTY_ROUTER") == 0) && (n+3 < argc) )
419         {
420            size_t t = strtol(argv[n+1], NULL, 0);
421            size_t x = strtol(argv[n+2], NULL, 0);
422            size_t y = strtol(argv[n+3], NULL, 0);
423            n+=2;
424            if( (t > 4) )
425            {
426                std::cout << "FAULTY_ROUTER NoC index is too big (index > 4)" << std::endl;
427                exit(0);
428            }
429            if( (x>=X_SIZE) || (y>=Y_SIZE) )
430            {
431                std::cout << "FAULTY_ROUTER parameter doesn't fit X_SIZE/Y_SIZE" << std::endl;
432                exit(0);
433            }
434            faulty_routers.push_back((t << (X_WIDTH + Y_WIDTH)) |
435                                     (x << (Y_WIDTH)) |
436                                     (y));
437         }
438         else if ((strcmp(argv[n], "-FAULTY_MASK") == 0) && (n+1 < argc) )
439         {
440            faulty_mask = strtol(argv[n+1], NULL, 0);
441            if( faulty_mask > 0x1F )
442            {
443                std::cout << "FAULTY_MASK parameter max value is 0x1F" << std::endl;
444                exit(0);
445            }
446         }
447         else
448         {
449            std::cout << "   Arguments are (key, value) couples." << std::endl;
450            std::cout << "   The order is not important." << std::endl;
451            std::cout << "   Accepted arguments are :" << std::endl << std::endl;
452            std::cout << "     -SOFT pathname_for_embedded_soft" << std::endl;
453            std::cout << "     -DSOFT pathname_for_distributed_embedded_soft" << std::endl;
454            std::cout << "     -DISK pathname_for_disk_image" << std::endl;
455            std::cout << "     -NCYCLES number_of_simulated_cycles" << std::endl;
456            std::cout << "     -DEBUG debug_start_cycle" << std::endl;
457            std::cout << "     -THREADS simulator's threads number" << std::endl;
458            std::cout << "     -FROZEN max_number_of_lines" << std::endl;
459            std::cout << "     -PERIOD number_of_cycles between trace" << std::endl;
460            std::cout << "     -MEMCID index_memc_to_be_traced" << std::endl;
461            std::cout << "     -XRAMID index_xram_to_be_traced" << std::endl;
462            std::cout << "     -PROCID index_proc_to_be_traced" << std::endl;
463            std::cout << "     -IOB    non_zero_value" << std::endl;
464            exit(0);
465         }
466      }
467   }
468
469   // Activate Distributed Boot (set by environment variable)
470   // When this is activated, every processor boots with its instruction and data
471   // physical address extension register initialized to its cluster index
472   // (X_LOCAL, Y_LOCAL). To support this feature, a distributed ROM is
473   // implemented in each cluster.
474
475   const bool distributed_boot = (getenv("DISTRIBUTED_BOOT") != NULL);
476
477   // checking hardware parameters
478   assert( (X_SIZE <= (1 << X_WIDTH)) and
479           "The X_SIZE parameter cannot be larger than 16" );
480
481   assert( (Y_SIZE <= (1 << Y_WIDTH)) and
482           "The Y_SIZE parameter cannot be larger than 16" );
483
484   assert( (NB_PROCS_MAX <= (1 << P_WIDTH)) and
485           "NB_PROCS_MAX parameter cannot be larger than 2^P_WIDTH" );
486
487   assert( (NB_DMA_CHANNELS <= 4) and
488           "The NB_DMA_CHANNELS parameter cannot be larger than 4" );
489
490   assert( (NB_TTY_CHANNELS >= 1) and (NB_TTY_CHANNELS <= 16) and
491           "The NB_TTY_CHANNELS parameter cannot be larger than 16" );
492
493#if USE_NIC
494   assert( (NB_NIC_CHANNELS == 2) and
495           "The NB_NIC_CHANNELS parameter must be 2" );
496#endif
497
498   std::cout << std::endl << std::dec
499             << " - X_SIZE          = " << X_SIZE << std::endl
500             << " - Y_SIZE          = " << Y_SIZE << std::endl
501             << " - NB_PROCS_MAX    = " << NB_PROCS_MAX <<  std::endl
502             << " - NB_TTY_CHANNELS = " << NB_TTY_CHANNELS <<  std::endl
503             << " - NB_DMA_CHANNELS = " << NB_DMA_CHANNELS <<  std::endl
504             << " - NB_NIC_CHANNELS = " << NB_NIC_CHANNELS <<  std::endl
505             << " - MEMC_WAYS       = " << MEMC_WAYS << std::endl
506             << " - MEMC_SETS       = " << MEMC_SETS << std::endl
507             << " - RAM_LATENCY     = " << XRAM_LATENCY << std::endl
508             << " - MAX_FROZEN      = " << frozen_cycles << std::endl
509             << " - DIST_BOOT       = " << distributed_boot << std::endl
510             << " - DEBUG_PROCID    = " << debug_proc_id << std::endl
511             << " - DEBUG_MEMCID    = " << debug_memc_id << std::endl
512             << " - DEBUG_XRAMID    = " << debug_xram_id << std::endl;
513
514   std::cout << std::endl;
515
516#if _OPENMP
517   omp_set_dynamic(false);
518   omp_set_num_threads(threads_nr);
519   std::cerr << "Built with openmp version " << _OPENMP
520             << " / numthreads = " << threads_nr << std::endl;
521#endif
522
523   // Define VciParams objects
524   typedef soclib::caba::VciParams<vci_cell_width_int,
525                                   vci_plen_width,
526                                   vci_address_width,
527                                   vci_rerror_width,
528                                   vci_clen_width,
529                                   vci_rflag_width,
530                                   vci_srcid_width,
531                                   vci_pktid_width,
532                                   vci_trdid_width,
533                                   vci_wrplen_width> vci_param_int;
534
535   typedef soclib::caba::VciParams<vci_cell_width_ext,
536                                   vci_plen_width,
537                                   vci_address_width,
538                                   vci_rerror_width,
539                                   vci_clen_width,
540                                   vci_rflag_width,
541                                   vci_srcid_width,
542                                   vci_pktid_width,
543                                   vci_trdid_width,
544                                   vci_wrplen_width> vci_param_ext;
545
546   const size_t cluster_iob0 = cluster(0, 0);               // cluster containing IOB0
547   const size_t cluster_iob1 = cluster(X_SIZE-1, Y_SIZE-1); // cluster containing IOB1
548
549   /////////////////////////////////////////////////////////////////////
550   // INT network mapping table
551   // - two levels address decoding for commands
552   // - two levels srcid decoding for responses
553   // - NB_PROCS_MAX + 2 (MDMA, IOBX) local initiators per cluster
554   // - 4 local targets (MEMC, XICU, MDMA, IOBX) per cluster
555   /////////////////////////////////////////////////////////////////////
556   MappingTable maptab_int( vci_address_width,
557                            IntTab(X_WIDTH + Y_WIDTH, 16 - X_WIDTH - Y_WIDTH),
558                            IntTab(X_WIDTH + Y_WIDTH, vci_srcid_width - X_WIDTH - Y_WIDTH),
559                            0x00FF000000);
560
561   for (size_t x = 0; x < X_SIZE; x++)
562   {
563      for (size_t y = 0; y < Y_SIZE; y++)
564      {
565         uint64_t offset = ((uint64_t)cluster(x, y))
566                              << (vci_address_width-X_WIDTH-Y_WIDTH);
567         bool config    = true;
568         bool cacheable = true;
569
570         // the four following segments are defined in all clusters
571
572         std::ostringstream    smemc_conf;
573         smemc_conf << "int_seg_memc_conf_" << x << "_" << y;
574         maptab_int.add(Segment(smemc_conf.str(), SEG_MMC_BASE+offset, SEG_MMC_SIZE,
575                     IntTab(cluster(x, y), INT_MEMC_TGT_ID), not cacheable, config ));
576
577         std::ostringstream    smemc_xram;
578         smemc_xram << "int_seg_memc_xram_" << x << "_" << y;
579         maptab_int.add(Segment(smemc_xram.str(), SEG_RAM_BASE+offset, SEG_RAM_SIZE,
580                     IntTab(cluster(x, y), INT_MEMC_TGT_ID), cacheable));
581
582         std::ostringstream    sxicu;
583         sxicu << "int_seg_xicu_" << x << "_" << y;
584         maptab_int.add(Segment(sxicu.str(), SEG_XCU_BASE+offset, SEG_XCU_SIZE,
585                     IntTab(cluster(x, y), INT_XICU_TGT_ID), not cacheable));
586
587         std::ostringstream    smdma;
588         smdma << "int_seg_mdma_" << x << "_" << y;
589         maptab_int.add(Segment(smdma.str(), SEG_DMA_BASE+offset, SEG_DMA_SIZE,
590                     IntTab(cluster(x, y), INT_MDMA_TGT_ID), not cacheable));
591
592         std::ostringstream    sdrom;
593         sdrom << "int_seg_drom_" << x << "_" << y;
594         maptab_int.add(Segment(sdrom.str(), SEG_DROM_BASE+offset, SEG_DROM_SIZE,
595                     IntTab(cluster(x, y), INT_DROM_TGT_ID), cacheable));
596
597         // the following segments are only defined in cluster_iob0 or in cluster_iob1
598
599         if ( (cluster(x, y) == cluster_iob0) or (cluster(x, y) == cluster_iob1) )
600         {
601            std::ostringstream    siobx;
602            siobx << "int_seg_iobx_" << x << "_" << y;
603            maptab_int.add(Segment(siobx.str(), SEG_IOB_BASE+offset, SEG_IOB_SIZE,
604                        IntTab(cluster(x, y), INT_IOBX_TGT_ID), not cacheable, config ));
605
606            std::ostringstream    stty;
607            stty << "int_seg_mtty_" << x << "_" << y;
608            maptab_int.add(Segment(stty.str(), SEG_TTY_BASE+offset, SEG_TTY_SIZE,
609                        IntTab(cluster(x, y), INT_IOBX_TGT_ID), not cacheable));
610
611            std::ostringstream    sfbf;
612            sfbf << "int_seg_fbuf_" << x << "_" << y;
613            maptab_int.add(Segment(sfbf.str(), SEG_FBF_BASE+offset, SEG_FBF_SIZE,
614                        IntTab(cluster(x, y), INT_IOBX_TGT_ID), not cacheable));
615
616            std::ostringstream    sbdv;
617            sbdv << "int_seg_bdev_" << x << "_" << y;
618            maptab_int.add(Segment(sbdv.str(), SEG_IOC_BASE+offset, SEG_IOC_SIZE,
619                        IntTab(cluster(x, y), INT_IOBX_TGT_ID), not cacheable));
620
621            std::ostringstream    snic;
622            snic << "int_seg_mnic_" << x << "_" << y;
623            maptab_int.add(Segment(snic.str(), SEG_NIC_BASE+offset, SEG_NIC_SIZE,
624                        IntTab(cluster(x, y), INT_IOBX_TGT_ID), not cacheable));
625
626            std::ostringstream    sdma;
627            sdma << "int_seg_cdma_" << x << "_" << y;
628            maptab_int.add(Segment(sdma.str(), SEG_CMA_BASE+offset, SEG_CMA_SIZE,
629                        IntTab(cluster(x, y), INT_IOBX_TGT_ID), not cacheable));
630
631            std::ostringstream    spic;
632            spic << "int_seg_iopi_" << x << "_" << y;
633            maptab_int.add(Segment(spic.str(), SEG_PIC_BASE+offset, SEG_PIC_SIZE,
634                        IntTab(cluster(x, y), INT_IOBX_TGT_ID), not cacheable));
635
636            std::ostringstream    ssim;
637            ssim << "int_seg_simh_" << x << "_" << y;
638            maptab_int.add(Segment(ssim.str(), SEG_SIM_BASE+offset, SEG_SIM_SIZE,
639                        IntTab(cluster(x, y), INT_IOBX_TGT_ID), not cacheable));
640
641            std::ostringstream    srom;
642            srom << "int_seg_rom_" << x << "_" << y;
643            maptab_int.add(Segment(srom.str(), SEG_ROM_BASE+offset, SEG_ROM_SIZE,
644                        IntTab(cluster(x, y), INT_IOBX_TGT_ID), cacheable));
645         }
646
647         // This define the mapping between the SRCIDs
648         // and the port index on the local interconnect.
649
650         maptab_int.srcid_map( IntTab( cluster(x, y), MDMA_LOCAL_SRCID ),
651                               IntTab( cluster(x, y), INT_MDMA_INI_ID ) );
652
653         maptab_int.srcid_map( IntTab( cluster(x, y), IOBX_LOCAL_SRCID ),
654                               IntTab( cluster(x, y), INT_IOBX_INI_ID ) );
655
656         maptab_int.srcid_map( IntTab( cluster(x, y), IOPI_LOCAL_SRCID ),
657                               IntTab( cluster(x, y), INT_IOBX_INI_ID ) );
658
659         for ( size_t p = 0 ; p < NB_PROCS_MAX ; p++ )
660         maptab_int.srcid_map( IntTab( cluster(x, y), PROC_LOCAL_SRCID+p ),
661                               IntTab( cluster(x, y), INT_PROC_INI_ID+p ) );
662      }
663   }
664   std::cout << "INT network " << maptab_int << std::endl;
665
666    /////////////////////////////////////////////////////////////////////////
667    // RAM network mapping table
668    // - two levels address decoding for commands
669    // - two levels srcid decoding for responses
670    // - 2 local initiators (MEMC, IOBX) per cluster
671    //   (IOBX component only in cluster_iob0 and cluster_iob1)
672    // - 1 local target (XRAM) per cluster
673    ////////////////////////////////////////////////////////////////////////
674    MappingTable maptab_ram( vci_address_width,
675                             IntTab(X_WIDTH+Y_WIDTH, 0),
676                             IntTab(X_WIDTH+Y_WIDTH, vci_srcid_width - X_WIDTH - Y_WIDTH),
677                             0x00FF000000);
678
679    for (size_t x = 0; x < X_SIZE; x++)
680    {
681        for (size_t y = 0; y < Y_SIZE ; y++)
682        {
683            uint64_t offset = ((uint64_t)cluster(x, y))
684                                << (vci_address_width-X_WIDTH-Y_WIDTH);
685
686            std::ostringstream sxram;
687            sxram << "ext_seg_xram_" << x << "_" << y;
688            maptab_ram.add(Segment(sxram.str(), SEG_RAM_BASE+offset,
689                           SEG_RAM_SIZE, IntTab(cluster(x, y), RAM_XRAM_TGT_ID), false));
690        }
691    }
692
693    // This define the mapping between the initiators SRCID
694    // and the port index on the RAM local interconnect.
695    // External initiator have two alias SRCID (iob0 / iob1)
696
697    maptab_ram.srcid_map( IntTab( cluster_iob0, CDMA_LOCAL_SRCID ),
698                          IntTab( cluster_iob0, RAM_IOBX_INI_ID ) );
699
700    maptab_ram.srcid_map( IntTab( cluster_iob1, CDMA_LOCAL_SRCID ),
701                          IntTab( cluster_iob1, RAM_IOBX_INI_ID ) );
702
703    maptab_ram.srcid_map( IntTab( cluster_iob0, BDEV_LOCAL_SRCID ),
704                          IntTab( cluster_iob0, RAM_IOBX_INI_ID ) );
705
706    maptab_ram.srcid_map( IntTab( cluster_iob1, BDEV_LOCAL_SRCID ),
707                          IntTab( cluster_iob1, RAM_IOBX_INI_ID ) );
708
709    maptab_ram.srcid_map( IntTab( cluster_iob0, IOPI_LOCAL_SRCID ),
710                          IntTab( cluster_iob0, RAM_IOBX_INI_ID ) );
711
712    maptab_ram.srcid_map( IntTab( cluster_iob1, IOPI_LOCAL_SRCID ),
713                          IntTab( cluster_iob1, RAM_IOBX_INI_ID ) );
714
715    maptab_ram.srcid_map( IntTab( cluster_iob0, MEMC_LOCAL_SRCID ),
716                          IntTab( cluster_iob0, RAM_MEMC_INI_ID ) );
717
718    maptab_ram.srcid_map( IntTab( cluster_iob1, MEMC_LOCAL_SRCID ),
719                          IntTab( cluster_iob1, RAM_MEMC_INI_ID ) );
720
721    std::cout << "RAM network " << maptab_ram << std::endl;
722
723    ///////////////////////////////////////////////////////////////////////
724    // IOX network mapping table
725    // - two levels address decoding for commands (9, 7) bits
726    // - two levels srcid decoding for responses
727    // - 5 initiators (IOB0, IOB1, BDEV, CDMA, IOPI)
728    // - 9 targets (IOB0, IOB1, BDEV, CDMA, MTTY, FBUF, ROM, MNIC, IOPI)
729    //
730    // Address bit 32 is used to determine if a command must be routed to
731    // IOB0 or IOB1.
732    ///////////////////////////////////////////////////////////////////////
733    MappingTable maptab_iox(
734          vci_address_width,
735          IntTab(X_WIDTH + Y_WIDTH - 1, 16 - X_WIDTH - Y_WIDTH + 1),
736          IntTab(X_WIDTH + Y_WIDTH    , vci_param_ext::S - X_WIDTH - Y_WIDTH),
737          0x00FF000000);
738
739    // External peripherals segments
740    // When there is more than one cluster, external peripherals can be accessed
741    // through two segments, depending on the used IOB (IOB0 or IOB1).
742
743    const uint64_t iob0_base = ((uint64_t)cluster_iob0)
744       << (vci_address_width - X_WIDTH - Y_WIDTH);
745
746    maptab_iox.add(Segment("iox_seg_mtty_0", SEG_TTY_BASE + iob0_base, SEG_TTY_SIZE,
747                   IntTab(0, IOX_MTTY_TGT_ID), false));
748    maptab_iox.add(Segment("iox_seg_fbuf_0", SEG_FBF_BASE + iob0_base, SEG_FBF_SIZE,
749                   IntTab(0, IOX_FBUF_TGT_ID), false));
750    maptab_iox.add(Segment("iox_seg_bdev_0", SEG_IOC_BASE + iob0_base, SEG_IOC_SIZE,
751                   IntTab(0, IOX_BDEV_TGT_ID), false));
752    maptab_iox.add(Segment("iox_seg_mnic_0", SEG_NIC_BASE + iob0_base, SEG_NIC_SIZE,
753                   IntTab(0, IOX_MNIC_TGT_ID), false));
754    maptab_iox.add(Segment("iox_seg_cdma_0", SEG_CMA_BASE + iob0_base, SEG_CMA_SIZE,
755                   IntTab(0, IOX_CDMA_TGT_ID), false));
756    maptab_iox.add(Segment("iox_seg_iopi_0", SEG_PIC_BASE + iob0_base, SEG_PIC_SIZE,
757                   IntTab(0, IOX_IOPI_TGT_ID), false));
758    maptab_iox.add(Segment("iox_seg_simh_0", SEG_SIM_BASE + iob0_base, SEG_SIM_SIZE,
759                   IntTab(0, IOX_SIMH_TGT_ID), false));
760    maptab_iox.add(Segment("iox_seg_rom_0", SEG_ROM_BASE + iob0_base, SEG_ROM_SIZE,
761                   IntTab(0, IOX_ROM_TGT_ID), false));
762
763    if ( cluster_iob0 != cluster_iob1 )
764    {
765       const uint64_t iob1_base = ((uint64_t)cluster_iob1)
766          << (vci_address_width - X_WIDTH - Y_WIDTH);
767
768        maptab_iox.add(Segment("iox_seg_mtty_1", SEG_TTY_BASE + iob1_base, SEG_TTY_SIZE,
769                   IntTab(0, IOX_MTTY_TGT_ID), false));
770        maptab_iox.add(Segment("iox_seg_fbuf_1", SEG_FBF_BASE + iob1_base, SEG_FBF_SIZE,
771                   IntTab(0, IOX_FBUF_TGT_ID), false));
772        maptab_iox.add(Segment("iox_seg_bdev_1", SEG_IOC_BASE + iob1_base, SEG_IOC_SIZE,
773                   IntTab(0, IOX_BDEV_TGT_ID), false));
774        maptab_iox.add(Segment("iox_seg_mnic_1", SEG_NIC_BASE + iob1_base, SEG_NIC_SIZE,
775                   IntTab(0, IOX_MNIC_TGT_ID), false));
776        maptab_iox.add(Segment("iox_seg_cdma_1", SEG_CMA_BASE + iob1_base, SEG_CMA_SIZE,
777                   IntTab(0, IOX_CDMA_TGT_ID), false));
778        maptab_iox.add(Segment("iox_seg_iopi_1", SEG_PIC_BASE + iob1_base, SEG_PIC_SIZE,
779                   IntTab(0, IOX_IOPI_TGT_ID), false));
780        maptab_iox.add(Segment("iox_seg_simh_1", SEG_SIM_BASE + iob1_base, SEG_SIM_SIZE,
781                   IntTab(0, IOX_SIMH_TGT_ID), false));
782        maptab_iox.add(Segment("iox_seg_rom_1", SEG_ROM_BASE + iob1_base, SEG_ROM_SIZE,
783                   IntTab(0, IOX_ROM_TGT_ID), false));
784    }
785
786    // If there is more than one cluster, external peripherals
787    // can access RAM through two segments (IOB0 / IOB1).
788    // As IOMMU is not activated, addresses are 40 bits (physical addresses),
789    // and the choice depends on address bit A[32].
790    for (size_t x = 0; x < X_SIZE; x++)
791    {
792        for (size_t y = 0; y < Y_SIZE ; y++)
793        {
794            const bool wti       = true;
795            const bool cacheable = true;
796
797            const uint64_t offset = ((uint64_t)cluster(x, y))
798                << (vci_address_width-X_WIDTH-Y_WIDTH);
799
800            const uint64_t xicu_base = SEG_XCU_BASE + offset;
801
802            if ( (y & 0x1) == 0 ) // use IOB0
803            {
804                std::ostringstream sxcu0;
805                sxcu0 << "iox_seg_xcu0_" << x << "_" << y;
806                maptab_iox.add(Segment(sxcu0.str(), xicu_base, SEG_XCU_SIZE,
807                            IntTab(0, IOX_IOB0_TGT_ID), not cacheable, wti));
808
809                std::ostringstream siob0;
810                siob0 << "iox_seg_ram0_" << x << "_" << y;
811                maptab_iox.add(Segment(siob0.str(), offset, SEG_XCU_BASE,
812                            IntTab(0, IOX_IOB0_TGT_ID), not cacheable, not wti));
813            }
814            else                  // USE IOB1
815            {
816                std::ostringstream sxcu1;
817                sxcu1 << "iox_seg_xcu1_" << x << "_" << y;
818                maptab_iox.add(Segment(sxcu1.str(), xicu_base, SEG_XCU_SIZE,
819                            IntTab(0, IOX_IOB1_TGT_ID), not cacheable, wti));
820
821                std::ostringstream siob1;
822                siob1 << "iox_seg_ram1_" << x << "_" << y;
823                maptab_iox.add(Segment(siob1.str(), offset, SEG_XCU_BASE,
824                            IntTab(0, IOX_IOB1_TGT_ID), not cacheable, not wti));
825            }
826        }
827    }
828
829    // This define the mapping between the external initiators (SRCID)
830    // and the port index on the IOX local interconnect.
831
832    maptab_iox.srcid_map( IntTab( 0, CDMA_LOCAL_SRCID ) ,
833                          IntTab( 0, IOX_CDMA_INI_ID  ) );
834    maptab_iox.srcid_map( IntTab( 0, BDEV_LOCAL_SRCID ) ,
835                          IntTab( 0, IOX_BDEV_INI_ID  ) );
836    maptab_iox.srcid_map( IntTab( 0, IOPI_LOCAL_SRCID ) ,
837                          IntTab( 0, IOX_IOPI_INI_ID  ) );
838    maptab_iox.srcid_map( IntTab( 0, IOX_IOB0_INI_ID  ) ,
839                          IntTab( 0, IOX_IOB0_INI_ID  ) );
840
841    if ( cluster_iob0 != cluster_iob1 )
842    {
843        maptab_iox.srcid_map( IntTab( 0, IOX_IOB1_INI_ID ) ,
844                              IntTab( 0, IOX_IOB1_INI_ID ) );
845    }
846
847    std::cout << "IOX network " << maptab_iox << std::endl;
848
849    ////////////////////
850    // Signals
851    ///////////////////
852
853    sc_clock                          signal_clk("clk");
854    sc_signal<bool>                   signal_resetn("resetn");
855
856    sc_signal<bool>                   signal_false;
857
858    sc_signal<bool>                   signal_irq_bdev;
859    sc_signal<bool>                   signal_irq_mtty_rx[NB_TTY_CHANNELS];
860    sc_signal<bool>                   signal_irq_mnic_rx[NB_NIC_CHANNELS];
861    sc_signal<bool>                   signal_irq_mnic_tx[NB_NIC_CHANNELS];
862    sc_signal<bool>                   signal_irq_cdma[NB_CMA_CHANNELS];
863
864    // VCI signals for IOX network
865    VciSignals<vci_param_ext>         signal_vci_ini_iob0("signal_vci_ini_iob0");
866    VciSignals<vci_param_ext>         signal_vci_ini_iob1("signal_vci_ini_iob1");
867    VciSignals<vci_param_ext>         signal_vci_ini_bdev("signal_vci_ini_bdev");
868    VciSignals<vci_param_ext>         signal_vci_ini_cdma("signal_vci_ini_cdma");
869    VciSignals<vci_param_ext>         signal_vci_ini_iopi("signal_vci_ini_iopi");
870
871    VciSignals<vci_param_ext>         signal_vci_tgt_iob0("signal_vci_tgt_iob0");
872    VciSignals<vci_param_ext>         signal_vci_tgt_iob1("signal_vci_tgt_iob1");
873    VciSignals<vci_param_ext>         signal_vci_tgt_mtty("signal_vci_tgt_mtty");
874    VciSignals<vci_param_ext>         signal_vci_tgt_fbuf("signal_vci_tgt_fbuf");
875    VciSignals<vci_param_ext>         signal_vci_tgt_mnic("signal_vci_tgt_mnic");
876    VciSignals<vci_param_ext>         signal_vci_tgt_bdev("signal_vci_tgt_bdev");
877    VciSignals<vci_param_ext>         signal_vci_tgt_cdma("signal_vci_tgt_cdma");
878    VciSignals<vci_param_ext>         signal_vci_tgt_iopi("signal_vci_tgt_iopi");
879    VciSignals<vci_param_ext>         signal_vci_tgt_simh("signal_vci_tgt_simh");
880    VciSignals<vci_param_ext>         signal_vci_tgt_rom("signal_vci_tgt_rom");
881
882   // Horizontal inter-clusters INT network DSPIN
883   DspinSignals<dspin_int_cmd_width>*** signal_dspin_int_cmd_h_inc =
884      alloc_elems<DspinSignals<dspin_int_cmd_width> >("signal_dspin_int_cmd_h_inc", X_SIZE-1, Y_SIZE, 3);
885   DspinSignals<dspin_int_cmd_width>*** signal_dspin_int_cmd_h_dec =
886      alloc_elems<DspinSignals<dspin_int_cmd_width> >("signal_dspin_int_cmd_h_dec", X_SIZE-1, Y_SIZE, 3);
887   DspinSignals<dspin_int_rsp_width>*** signal_dspin_int_rsp_h_inc =
888      alloc_elems<DspinSignals<dspin_int_rsp_width> >("signal_dspin_int_rsp_h_inc", X_SIZE-1, Y_SIZE, 2);
889   DspinSignals<dspin_int_rsp_width>*** signal_dspin_int_rsp_h_dec =
890      alloc_elems<DspinSignals<dspin_int_rsp_width> >("signal_dspin_int_rsp_h_dec", X_SIZE-1, Y_SIZE, 2);
891
892   // Vertical inter-clusters INT network DSPIN
893   DspinSignals<dspin_int_cmd_width>*** signal_dspin_int_cmd_v_inc =
894      alloc_elems<DspinSignals<dspin_int_cmd_width> >("signal_dspin_int_cmd_v_inc", X_SIZE, Y_SIZE-1, 3);
895   DspinSignals<dspin_int_cmd_width>*** signal_dspin_int_cmd_v_dec =
896      alloc_elems<DspinSignals<dspin_int_cmd_width> >("signal_dspin_int_cmd_v_dec", X_SIZE, Y_SIZE-1, 3);
897   DspinSignals<dspin_int_rsp_width>*** signal_dspin_int_rsp_v_inc =
898      alloc_elems<DspinSignals<dspin_int_rsp_width> >("signal_dspin_int_rsp_v_inc", X_SIZE, Y_SIZE-1, 2);
899   DspinSignals<dspin_int_rsp_width>*** signal_dspin_int_rsp_v_dec =
900      alloc_elems<DspinSignals<dspin_int_rsp_width> >("signal_dspin_int_rsp_v_dec", X_SIZE, Y_SIZE-1, 2);
901
902   // Mesh boundaries INT network DSPIN
903   DspinSignals<dspin_int_cmd_width>**** signal_dspin_false_int_cmd_in =
904      alloc_elems<DspinSignals<dspin_int_cmd_width> >("signal_dspin_false_int_cmd_in", X_SIZE, Y_SIZE, 4, 3);
905   DspinSignals<dspin_int_cmd_width>**** signal_dspin_false_int_cmd_out =
906      alloc_elems<DspinSignals<dspin_int_cmd_width> >("signal_dspin_false_int_cmd_out", X_SIZE, Y_SIZE, 4, 3);
907   DspinSignals<dspin_int_rsp_width>**** signal_dspin_false_int_rsp_in =
908      alloc_elems<DspinSignals<dspin_int_rsp_width> >("signal_dspin_false_int_rsp_in", X_SIZE, Y_SIZE, 4, 2);
909   DspinSignals<dspin_int_rsp_width>**** signal_dspin_false_int_rsp_out =
910      alloc_elems<DspinSignals<dspin_int_rsp_width> >("signal_dspin_false_int_rsp_out", X_SIZE, Y_SIZE, 4, 2);
911
912
913   // Horizontal inter-clusters RAM network DSPIN
914   DspinSignals<dspin_ram_cmd_width>** signal_dspin_ram_cmd_h_inc =
915      alloc_elems<DspinSignals<dspin_ram_cmd_width> >("signal_dspin_ram_cmd_h_inc", X_SIZE-1, Y_SIZE);
916   DspinSignals<dspin_ram_cmd_width>** signal_dspin_ram_cmd_h_dec =
917      alloc_elems<DspinSignals<dspin_ram_cmd_width> >("signal_dspin_ram_cmd_h_dec", X_SIZE-1, Y_SIZE);
918   DspinSignals<dspin_ram_rsp_width>** signal_dspin_ram_rsp_h_inc =
919      alloc_elems<DspinSignals<dspin_ram_rsp_width> >("signal_dspin_ram_rsp_h_inc", X_SIZE-1, Y_SIZE);
920   DspinSignals<dspin_ram_rsp_width>** signal_dspin_ram_rsp_h_dec =
921      alloc_elems<DspinSignals<dspin_ram_rsp_width> >("signal_dspin_ram_rsp_h_dec", X_SIZE-1, Y_SIZE);
922
923   // Vertical inter-clusters RAM network DSPIN
924   DspinSignals<dspin_ram_cmd_width>** signal_dspin_ram_cmd_v_inc =
925      alloc_elems<DspinSignals<dspin_ram_cmd_width> >("signal_dspin_ram_cmd_v_inc", X_SIZE, Y_SIZE-1);
926   DspinSignals<dspin_ram_cmd_width>** signal_dspin_ram_cmd_v_dec =
927      alloc_elems<DspinSignals<dspin_ram_cmd_width> >("signal_dspin_ram_cmd_v_dec", X_SIZE, Y_SIZE-1);
928   DspinSignals<dspin_ram_rsp_width>** signal_dspin_ram_rsp_v_inc =
929      alloc_elems<DspinSignals<dspin_ram_rsp_width> >("signal_dspin_ram_rsp_v_inc", X_SIZE, Y_SIZE-1);
930   DspinSignals<dspin_ram_rsp_width>** signal_dspin_ram_rsp_v_dec =
931      alloc_elems<DspinSignals<dspin_ram_rsp_width> >("signal_dspin_ram_rsp_v_dec", X_SIZE, Y_SIZE-1);
932
933   // Mesh boundaries RAM network DSPIN
934   DspinSignals<dspin_ram_cmd_width>*** signal_dspin_false_ram_cmd_in =
935      alloc_elems<DspinSignals<dspin_ram_cmd_width> >("signal_dspin_false_ram_cmd_in", X_SIZE, Y_SIZE, 4);
936   DspinSignals<dspin_ram_cmd_width>*** signal_dspin_false_ram_cmd_out =
937      alloc_elems<DspinSignals<dspin_ram_cmd_width> >("signal_dspin_false_ram_cmd_out", X_SIZE, Y_SIZE, 4);
938   DspinSignals<dspin_ram_rsp_width>*** signal_dspin_false_ram_rsp_in =
939      alloc_elems<DspinSignals<dspin_ram_rsp_width> >("signal_dspin_false_ram_rsp_in", X_SIZE, Y_SIZE, 4);
940   DspinSignals<dspin_ram_rsp_width>*** signal_dspin_false_ram_rsp_out =
941      alloc_elems<DspinSignals<dspin_ram_rsp_width> >("signal_dspin_false_ram_rsp_out", X_SIZE, Y_SIZE, 4);
942
943   ////////////////////////////
944   //      Loader
945   ////////////////////////////
946   soclib::common::Loader *loader;
947
948#if USE_ALMOS
949   loader = new soclib::common::Loader (almos_bootloader_pathname,
950                                        almos_archinfo_pathname,
951                                        almos_kernel_pathname);
952#else
953   if (strcmp(soft_name, "") == 0)
954   {
955      loader = new soclib::common::Loader (dsoft_name);
956   }
957   else
958   {
959      loader = new soclib::common::Loader (soft_name, dsoft_name);
960   }
961#endif
962
963   // initialize memory with a value different than 0 (expose software errors
964   // dues to uninitialized data)
965   loader->memory_default(0xA0);
966
967   typedef soclib::common::GdbServer<soclib::common::Mips32ElIss> proc_iss;
968   proc_iss::set_loader(loader);
969
970   ////////////////////////////////////////
971   //  Instanciated Hardware Components
972   ////////////////////////////////////////
973
974   std::cout << std::endl << "External Bus and Peripherals" << std::endl << std::endl;
975
976   const size_t nb_iox_initiators = (cluster_iob0 != cluster_iob1) ? 5 : 4;
977   const size_t nb_iox_targets = (cluster_iob0 != cluster_iob1) ? 10 : 9;
978
979   // IOX network
980   VciIoxNetwork<vci_param_ext>* iox_network;
981   iox_network = new VciIoxNetwork<vci_param_ext>( "iox_network",
982                                                   maptab_iox,
983                                                   nb_iox_targets,
984                                                   nb_iox_initiators );
985
986   // Network Controller
987#if USE_NIC
988   VciMultiNic<vci_param_ext>*  mnic;
989   int nicMode = VciMultiNic<vci_param_ext>::NIC_MODE_SYNTHESIS;
990   mnic = new VciMultiNic<vci_param_ext>( "mnic",
991                                          IntTab(0, IOX_MNIC_TGT_ID),
992                                          maptab_iox,
993                                          NB_NIC_CHANNELS,
994                                          0,           // mac_4 address
995                                          0,           // mac_2 address
996                                          nicMode,
997                                          12 );        // Inter Frame Gap
998
999   // Chained Buffer DMA controller
1000   VciChbufDma<vci_param_ext>*  cdma;
1001   cdma = new VciChbufDma<vci_param_ext>( "cdma",
1002                                          maptab_iox,
1003                                          IntTab(0, CDMA_LOCAL_SRCID),
1004                                          IntTab(0, IOX_CDMA_TGT_ID),
1005                                          64,          // burst size (bytes)
1006                                          NB_CMA_CHANNELS,
1007                                          4 );         // # pipelined burst
1008#else
1009   VciTargetError<vci_param_ext> merror_nic( "merror_nic",
1010                                             IntTab(0, IOX_MNIC_TGT_ID),
1011                                             maptab_iox );
1012
1013   VciTargetError<vci_param_ext> merror_dma( "merror_dma",
1014                                             IntTab(0, IOX_CDMA_TGT_ID),
1015                                             maptab_iox );
1016#endif
1017
1018   // Frame Buffer
1019   VciFrameBuffer<vci_param_ext>*  fbuf;
1020   fbuf = new VciFrameBuffer<vci_param_ext>( "fbuf",
1021                                             IntTab(0, IOX_FBUF_TGT_ID),
1022                                             maptab_iox,
1023                                             FBUF_X_SIZE, FBUF_Y_SIZE );
1024
1025   // Block Device
1026   // for AHCI
1027   // std::vector<std::string> filenames;
1028   // filenames.push_back(disk_name);            // one single disk
1029   VciBlockDeviceTsar<vci_param_ext>*  bdev;
1030   bdev = new VciBlockDeviceTsar<vci_param_ext>( "bdev",
1031                                                  maptab_iox,
1032                                                  IntTab(0, BDEV_LOCAL_SRCID),
1033                                                  IntTab(0, IOX_BDEV_TGT_ID),
1034                                                  disk_name,
1035                                                  512,        // block size
1036                                                  64,         // burst size (bytes)
1037                                                  0 );        // disk latency
1038
1039   // Multi-TTY controller
1040   std::vector<std::string> vect_names;
1041   for( size_t tid = 0 ; tid < NB_TTY_CHANNELS ; tid++ )
1042   {
1043      std::ostringstream term_name;
1044      term_name <<  "term" << tid;
1045      vect_names.push_back(term_name.str().c_str());
1046   }
1047   VciMultiTty<vci_param_ext>*  mtty;
1048   mtty = new VciMultiTty<vci_param_ext>( "mtty",
1049         IntTab(0, IOX_MTTY_TGT_ID),
1050         maptab_iox,
1051         vect_names);
1052
1053   // IOPIC
1054   VciIopic<vci_param_ext>* iopi;
1055   iopi = new VciIopic<vci_param_ext>( "iopi",
1056                                       maptab_iox,
1057                                       IntTab(0, IOPI_LOCAL_SRCID),
1058                                       IntTab(0, IOX_IOPI_TGT_ID),
1059                                       32 );        // number of input HWI
1060
1061   // Simhelper
1062   VciSimhelper<vci_param_ext>* simh;
1063   simh = new VciSimhelper<vci_param_ext>("simh",
1064                                          IntTab(0, IOX_SIMH_TGT_ID),
1065                                          maptab_iox );
1066
1067   // External ROM
1068   VciSimpleRom<vci_param_ext>* rom;
1069   rom = new VciSimpleRom<vci_param_ext>("rom",
1070                                          IntTab(0, IOX_ROM_TGT_ID),
1071                                          maptab_iox,
1072                                          *loader,
1073                                          X_WIDTH + Y_WIDTH );
1074
1075   // Clusters
1076   typedef TsarIobCluster<
1077      vci_param_int, vci_param_ext,
1078      dspin_int_cmd_width, dspin_int_rsp_width,
1079      dspin_ram_cmd_width, dspin_ram_rsp_width> TsarCluster;
1080
1081   TsarCluster* clusters[X_SIZE][Y_SIZE];
1082
1083#if _OPENMP
1084#pragma omp parallel
1085    {
1086#pragma omp for
1087#endif
1088        for(size_t i = 0; i  < (X_SIZE * Y_SIZE); i++)
1089        {
1090            size_t x = i / Y_SIZE;
1091            size_t y = i % Y_SIZE;
1092
1093#if _OPENMP
1094#pragma omp critical
1095            {
1096#endif
1097            std::cout << std::endl;
1098            std::cout << "Cluster_" << std::dec << x << "_" << y << std::endl;
1099            std::cout << std::endl;
1100
1101            const bool is_iob0 = (cluster(x, y) == cluster_iob0);
1102            const bool is_iob1 = (cluster(x, y) == cluster_iob1);
1103            const bool is_io_cluster = is_iob0 || is_iob1;
1104
1105            const int iox_iob_ini_id = is_iob0 ?
1106                IOX_IOB0_INI_ID :
1107                IOX_IOB1_INI_ID ;
1108            const int iox_iob_tgt_id = is_iob0 ?
1109                IOX_IOB0_TGT_ID :
1110                IOX_IOB1_TGT_ID ;
1111
1112            std::ostringstream sc;
1113            sc << "cluster_" << x << "_" << y;
1114            clusters[x][y] = new TsarCluster (
1115                sc.str().c_str(),
1116                NB_PROCS_MAX,
1117                NB_DMA_CHANNELS,
1118                x,
1119                y,
1120                X_SIZE,
1121                Y_SIZE,
1122
1123                P_WIDTH,
1124
1125                maptab_int,
1126                maptab_ram,
1127                maptab_iox,
1128
1129                X_WIDTH,
1130                Y_WIDTH,
1131                vci_srcid_width - X_WIDTH - Y_WIDTH,            // l_id width,
1132
1133                INT_MEMC_TGT_ID,
1134                INT_XICU_TGT_ID,
1135                INT_MDMA_TGT_ID,
1136                INT_DROM_TGT_ID,
1137                INT_IOBX_TGT_ID,
1138
1139                INT_PROC_INI_ID,
1140                INT_MDMA_INI_ID,
1141                INT_IOBX_INI_ID,
1142
1143                RAM_XRAM_TGT_ID,
1144
1145                RAM_MEMC_INI_ID,
1146                RAM_IOBX_INI_ID,
1147
1148                is_io_cluster,
1149                iox_iob_tgt_id,
1150                iox_iob_ini_id,
1151
1152                MEMC_WAYS,
1153                MEMC_SETS,
1154                L1_IWAYS,
1155                L1_ISETS,
1156                L1_DWAYS,
1157                L1_DSETS,
1158                XRAM_LATENCY,
1159                XCU_NB_HWI,
1160                XCU_NB_PTI,
1161                XCU_NB_WTI,
1162                XCU_NB_OUT,
1163                IRQ_PER_PROCESSOR,
1164
1165                distributed_boot,
1166
1167                *loader,
1168
1169                frozen_cycles,
1170                debug_from,
1171                debug_ok and (cluster(x, y) == debug_memc_id),
1172                debug_ok and (cluster(x, y) == (debug_proc_id >> P_WIDTH)),
1173                debug_ok and debug_iob
1174            );
1175
1176#if _OPENMP
1177            } // end critical
1178#endif
1179        } // end for
1180#if _OPENMP
1181    }
1182#endif
1183
1184    // disable all interfaces of the faulty CMD routers
1185    std::cout << "\n*** List of deactivated routers ***\n";
1186    for (std::vector<size_t>::iterator it = faulty_routers.begin();
1187         it != faulty_routers.end();
1188         ++it)
1189    {
1190       int ry = (*it) & ((1 << Y_WIDTH) - 1);
1191       int rx = (*it >> Y_WIDTH) & ((1 << X_WIDTH) - 1);
1192       int rt = (*it) >> (X_WIDTH + Y_WIDTH);
1193
1194       if (rt == 0)
1195       {
1196          std::cout << "Deactivate CMD router (" << rx << "," << ry << ")"
1197                    << std::endl;
1198          clusters[rx][ry]->int_router_cmd[0]->set_disable_mask(faulty_mask);
1199          continue;
1200       }
1201       if (rt == 1)
1202       {
1203          std::cout << "Deactivate RSP router (" << rx << "," << ry << ")"
1204                    << std::endl;
1205          clusters[rx][ry]->int_router_rsp[0]->set_disable_mask(faulty_mask);
1206          continue;
1207       }
1208       if (rt == 2)
1209       {
1210          std::cout << "Deactivate M2P router (" << rx << "," << ry << ")"
1211                    << std::endl;
1212          clusters[rx][ry]->int_router_cmd[1]->set_disable_mask(faulty_mask);
1213          continue;
1214       }
1215       if (rt == 3)
1216       {
1217          std::cout << "Deactivate P2M router (" << rx << "," << ry << ")"
1218                    << std::endl;
1219          clusters[rx][ry]->int_router_rsp[1]->set_disable_mask(faulty_mask);
1220          continue;
1221       }
1222       if (rt == 4)
1223       {
1224          std::cout << "Deactivate CLACK router (" << rx << "," << ry << ")"
1225                    << std::endl;
1226          clusters[rx][ry]->int_router_cmd[2]->set_disable_mask(faulty_mask);
1227          continue;
1228       }
1229    }
1230
1231    std::cout << std::endl;
1232
1233    //clusters[0][0]->xicu->set_faulty_wti(4, 0);
1234
1235    ///////////////////////////////////////////////////////////////////////////////
1236    //     Net-list
1237    ///////////////////////////////////////////////////////////////////////////////
1238
1239    // IOX network connexion
1240    iox_network->p_clk                                   (signal_clk);
1241    iox_network->p_resetn                                (signal_resetn);
1242    iox_network->p_to_ini[IOX_IOB0_INI_ID]               (signal_vci_ini_iob0);
1243    iox_network->p_to_ini[IOX_BDEV_INI_ID]               (signal_vci_ini_bdev);
1244    iox_network->p_to_ini[IOX_CDMA_INI_ID]               (signal_vci_ini_cdma);
1245    iox_network->p_to_ini[IOX_IOPI_INI_ID]               (signal_vci_ini_iopi);
1246
1247    iox_network->p_to_tgt[IOX_IOB0_TGT_ID]               (signal_vci_tgt_iob0);
1248    iox_network->p_to_tgt[IOX_MTTY_TGT_ID]               (signal_vci_tgt_mtty);
1249    iox_network->p_to_tgt[IOX_FBUF_TGT_ID]               (signal_vci_tgt_fbuf);
1250    iox_network->p_to_tgt[IOX_MNIC_TGT_ID]               (signal_vci_tgt_mnic);
1251    iox_network->p_to_tgt[IOX_BDEV_TGT_ID]               (signal_vci_tgt_bdev);
1252    iox_network->p_to_tgt[IOX_CDMA_TGT_ID]               (signal_vci_tgt_cdma);
1253    iox_network->p_to_tgt[IOX_IOPI_TGT_ID]               (signal_vci_tgt_iopi);
1254    iox_network->p_to_tgt[IOX_SIMH_TGT_ID]               (signal_vci_tgt_simh);
1255    iox_network->p_to_tgt[IOX_ROM_TGT_ID]                (signal_vci_tgt_rom);
1256
1257    if (cluster_iob0 != cluster_iob1)
1258    {
1259        iox_network->p_to_ini[IOX_IOB1_INI_ID]           (signal_vci_ini_iob1);
1260        iox_network->p_to_tgt[IOX_IOB1_TGT_ID]           (signal_vci_tgt_iob1);
1261    }
1262
1263    // BDEV connexion
1264    bdev->p_clk                                          (signal_clk);
1265    bdev->p_resetn                                       (signal_resetn);
1266    bdev->p_irq                                          (signal_irq_bdev);
1267    bdev->p_vci_target                                   (signal_vci_tgt_bdev);
1268    bdev->p_vci_initiator                                (signal_vci_ini_bdev);
1269
1270    std::cout << "  - BDEV connected" << std::endl;
1271
1272    // FBUF connexion
1273    fbuf->p_clk                                          (signal_clk);
1274    fbuf->p_resetn                                       (signal_resetn);
1275    fbuf->p_vci                                          (signal_vci_tgt_fbuf);
1276
1277    std::cout << "  - FBUF connected" << std::endl;
1278
1279#if USE_NIC
1280    // MNIC connexion
1281    mnic->p_clk                                          (signal_clk);
1282    mnic->p_resetn                                       (signal_resetn);
1283    mnic->p_vci                                          (signal_vci_tgt_mnic);
1284    for ( size_t i=0 ; i<NB_NIC_CHANNELS ; i++ )
1285    {
1286         mnic->p_rx_irq[i]                               (signal_irq_mnic_rx[i]);
1287         mnic->p_tx_irq[i]                               (signal_irq_mnic_tx[i]);
1288    }
1289    std::cout << "  - MNIC connected" << std::endl;
1290
1291    // CDMA connexion
1292    cdma->p_clk                                          (signal_clk);
1293    cdma->p_resetn                                       (signal_resetn);
1294    cdma->p_vci_target                                   (signal_vci_tgt_cdma);
1295    cdma->p_vci_initiator                                (signal_vci_ini_cdma);
1296    for ( size_t i=0 ; i<(NB_NIC_CHANNELS*2) ; i++)
1297    {
1298        cdma->p_irq[i]                                   (signal_irq_cdma[i]);
1299    }
1300    std::cout << "  - CDMA connected" << std::endl;
1301
1302#else
1303    merror_nic.p_clk                                     (signal_clk);
1304    merror_nic.p_resetn                                  (signal_resetn);
1305    merror_nic.p_vci                                     (signal_vci_tgt_mnic);
1306
1307    merror_dma.p_clk                                     (signal_clk);
1308    merror_dma.p_resetn                                  (signal_resetn);
1309    merror_dma.p_vci                                     (signal_vci_tgt_cdma);
1310#endif
1311
1312    // MTTY connexion
1313    mtty->p_clk                                          (signal_clk);
1314    mtty->p_resetn                                       (signal_resetn);
1315    mtty->p_vci                                          (signal_vci_tgt_mtty);
1316    for ( size_t i=0 ; i<NB_TTY_CHANNELS ; i++ )
1317    {
1318        mtty->p_irq[i]                                   (signal_irq_mtty_rx[i]);
1319    }
1320    std::cout << "  - MTTY connected" << std::endl;
1321
1322    // IOPI connexion
1323    iopi->p_clk                                          (signal_clk);
1324    iopi->p_resetn                                       (signal_resetn);
1325    iopi->p_vci_target                                   (signal_vci_tgt_iopi);
1326    iopi->p_vci_initiator                                (signal_vci_ini_iopi);
1327    for ( size_t i=0 ; i<32 ; i++)
1328    {
1329       if     (i < NB_NIC_CHANNELS)    iopi->p_hwi[i] (signal_irq_mnic_rx[i]);
1330       else if(i < 2 )                 iopi->p_hwi[i] (signal_false);
1331       else if(i < 2+NB_NIC_CHANNELS)  iopi->p_hwi[i] (signal_irq_mnic_tx[i-2]);
1332       else if(i < 4 )                 iopi->p_hwi[i] (signal_false);
1333       else if(i < 4+NB_CMA_CHANNELS)  iopi->p_hwi[i] (signal_irq_cdma[i-4]);
1334       else if(i < 8)                  iopi->p_hwi[i] (signal_false);
1335       else if(i < 9)                  iopi->p_hwi[i] (signal_irq_bdev);
1336       else if(i < 16)                 iopi->p_hwi[i] (signal_false);
1337       else if(i < 16+NB_TTY_CHANNELS) iopi->p_hwi[i] (signal_irq_mtty_rx[i-16]);
1338       else                            iopi->p_hwi[i] (signal_false);
1339    }
1340
1341    std::cout << "  - IOPIC connected" << std::endl;
1342
1343    // Simhelper connexion
1344    simh->p_clk(signal_clk);
1345    simh->p_resetn(signal_resetn);
1346    simh->p_vci(signal_vci_tgt_simh);
1347
1348    // External ROM connexion
1349    rom->p_clk(signal_clk);
1350    rom->p_resetn(signal_resetn);
1351    rom->p_vci(signal_vci_tgt_rom);
1352
1353    // IOB0 cluster connexion to IOX network
1354    (*clusters[0][0]->p_vci_iob_iox_ini) (signal_vci_ini_iob0);
1355    (*clusters[0][0]->p_vci_iob_iox_tgt) (signal_vci_tgt_iob0);
1356
1357    // IOB1 cluster connexion to IOX network
1358    // (only when there is more than 1 cluster)
1359    if ( cluster_iob0 != cluster_iob1 )
1360    {
1361        (*clusters[X_SIZE-1][Y_SIZE-1]->p_vci_iob_iox_ini) (signal_vci_ini_iob1);
1362        (*clusters[X_SIZE-1][Y_SIZE-1]->p_vci_iob_iox_tgt) (signal_vci_tgt_iob1);
1363    }
1364
1365    // All clusters Clock & RESET connexions
1366    for ( size_t x = 0; x < (X_SIZE); x++ )
1367    {
1368        for (size_t y = 0; y < Y_SIZE; y++)
1369        {
1370            clusters[x][y]->p_clk     (signal_clk);
1371            clusters[x][y]->p_resetn  (signal_resetn);
1372            clusters[x][y]->p_false   (signal_false);
1373        }
1374    }
1375
1376   // Inter Clusters horizontal connections
1377   if (X_SIZE > 1)
1378   {
1379      for (size_t x = 0; x < (X_SIZE-1); x++)
1380      {
1381         for (size_t y = 0; y < Y_SIZE; y++)
1382         {
1383            for (size_t k = 0; k < 3; k++)
1384            {
1385               clusters[x][y]->p_dspin_int_cmd_out[EAST][k]      (signal_dspin_int_cmd_h_inc[x][y][k]);
1386               clusters[x+1][y]->p_dspin_int_cmd_in[WEST][k]     (signal_dspin_int_cmd_h_inc[x][y][k]);
1387               clusters[x][y]->p_dspin_int_cmd_in[EAST][k]       (signal_dspin_int_cmd_h_dec[x][y][k]);
1388               clusters[x+1][y]->p_dspin_int_cmd_out[WEST][k]    (signal_dspin_int_cmd_h_dec[x][y][k]);
1389            }
1390
1391            for (size_t k = 0; k < 2; k++)
1392            {
1393               clusters[x][y]->p_dspin_int_rsp_out[EAST][k]      (signal_dspin_int_rsp_h_inc[x][y][k]);
1394               clusters[x+1][y]->p_dspin_int_rsp_in[WEST][k]     (signal_dspin_int_rsp_h_inc[x][y][k]);
1395               clusters[x][y]->p_dspin_int_rsp_in[EAST][k]       (signal_dspin_int_rsp_h_dec[x][y][k]);
1396               clusters[x+1][y]->p_dspin_int_rsp_out[WEST][k]    (signal_dspin_int_rsp_h_dec[x][y][k]);
1397            }
1398
1399            clusters[x][y]->p_dspin_ram_cmd_out[EAST]      (signal_dspin_ram_cmd_h_inc[x][y]);
1400            clusters[x+1][y]->p_dspin_ram_cmd_in[WEST]     (signal_dspin_ram_cmd_h_inc[x][y]);
1401            clusters[x][y]->p_dspin_ram_cmd_in[EAST]       (signal_dspin_ram_cmd_h_dec[x][y]);
1402            clusters[x+1][y]->p_dspin_ram_cmd_out[WEST]    (signal_dspin_ram_cmd_h_dec[x][y]);
1403            clusters[x][y]->p_dspin_ram_rsp_out[EAST]      (signal_dspin_ram_rsp_h_inc[x][y]);
1404            clusters[x+1][y]->p_dspin_ram_rsp_in[WEST]     (signal_dspin_ram_rsp_h_inc[x][y]);
1405            clusters[x][y]->p_dspin_ram_rsp_in[EAST]       (signal_dspin_ram_rsp_h_dec[x][y]);
1406            clusters[x+1][y]->p_dspin_ram_rsp_out[WEST]    (signal_dspin_ram_rsp_h_dec[x][y]);
1407         }
1408      }
1409   }
1410
1411   std::cout << std::endl << "Horizontal connections established" << std::endl;
1412
1413   // Inter Clusters vertical connections
1414   if (Y_SIZE > 1)
1415   {
1416      for (size_t y = 0; y < (Y_SIZE-1); y++)
1417      {
1418         for (size_t x = 0; x < X_SIZE; x++)
1419         {
1420            for (size_t k = 0; k < 3; k++)
1421            {
1422               clusters[x][y]->p_dspin_int_cmd_out[NORTH][k]     (signal_dspin_int_cmd_v_inc[x][y][k]);
1423               clusters[x][y+1]->p_dspin_int_cmd_in[SOUTH][k]    (signal_dspin_int_cmd_v_inc[x][y][k]);
1424               clusters[x][y]->p_dspin_int_cmd_in[NORTH][k]      (signal_dspin_int_cmd_v_dec[x][y][k]);
1425               clusters[x][y+1]->p_dspin_int_cmd_out[SOUTH][k]   (signal_dspin_int_cmd_v_dec[x][y][k]);
1426            }
1427
1428            for (size_t k = 0; k < 2; k++)
1429            {
1430               clusters[x][y]->p_dspin_int_rsp_out[NORTH][k]     (signal_dspin_int_rsp_v_inc[x][y][k]);
1431               clusters[x][y+1]->p_dspin_int_rsp_in[SOUTH][k]    (signal_dspin_int_rsp_v_inc[x][y][k]);
1432               clusters[x][y]->p_dspin_int_rsp_in[NORTH][k]      (signal_dspin_int_rsp_v_dec[x][y][k]);
1433               clusters[x][y+1]->p_dspin_int_rsp_out[SOUTH][k]   (signal_dspin_int_rsp_v_dec[x][y][k]);
1434            }
1435
1436            clusters[x][y]->p_dspin_ram_cmd_out[NORTH]     (signal_dspin_ram_cmd_v_inc[x][y]);
1437            clusters[x][y+1]->p_dspin_ram_cmd_in[SOUTH]    (signal_dspin_ram_cmd_v_inc[x][y]);
1438            clusters[x][y]->p_dspin_ram_cmd_in[NORTH]      (signal_dspin_ram_cmd_v_dec[x][y]);
1439            clusters[x][y+1]->p_dspin_ram_cmd_out[SOUTH]   (signal_dspin_ram_cmd_v_dec[x][y]);
1440            clusters[x][y]->p_dspin_ram_rsp_out[NORTH]     (signal_dspin_ram_rsp_v_inc[x][y]);
1441            clusters[x][y+1]->p_dspin_ram_rsp_in[SOUTH]    (signal_dspin_ram_rsp_v_inc[x][y]);
1442            clusters[x][y]->p_dspin_ram_rsp_in[NORTH]      (signal_dspin_ram_rsp_v_dec[x][y]);
1443            clusters[x][y+1]->p_dspin_ram_rsp_out[SOUTH]   (signal_dspin_ram_rsp_v_dec[x][y]);
1444         }
1445      }
1446   }
1447
1448   std::cout << "Vertical connections established" << std::endl;
1449
1450   // East & West boundary cluster connections
1451   for (size_t y = 0; y < Y_SIZE; y++)
1452   {
1453      for (size_t k = 0; k < 3; k++)
1454      {
1455         clusters[0][y]->p_dspin_int_cmd_in[WEST][k]          (signal_dspin_false_int_cmd_in[0][y][WEST][k]);
1456         clusters[0][y]->p_dspin_int_cmd_out[WEST][k]         (signal_dspin_false_int_cmd_out[0][y][WEST][k]);
1457         clusters[X_SIZE-1][y]->p_dspin_int_cmd_in[EAST][k]   (signal_dspin_false_int_cmd_in[X_SIZE-1][y][EAST][k]);
1458         clusters[X_SIZE-1][y]->p_dspin_int_cmd_out[EAST][k]  (signal_dspin_false_int_cmd_out[X_SIZE-1][y][EAST][k]);
1459      }
1460
1461      for (size_t k = 0; k < 2; k++)
1462      {
1463         clusters[0][y]->p_dspin_int_rsp_in[WEST][k]          (signal_dspin_false_int_rsp_in[0][y][WEST][k]);
1464         clusters[0][y]->p_dspin_int_rsp_out[WEST][k]         (signal_dspin_false_int_rsp_out[0][y][WEST][k]);
1465         clusters[X_SIZE-1][y]->p_dspin_int_rsp_in[EAST][k]   (signal_dspin_false_int_rsp_in[X_SIZE-1][y][EAST][k]);
1466         clusters[X_SIZE-1][y]->p_dspin_int_rsp_out[EAST][k]  (signal_dspin_false_int_rsp_out[X_SIZE-1][y][EAST][k]);
1467      }
1468
1469     clusters[0][y]->p_dspin_ram_cmd_in[WEST]       (signal_dspin_false_ram_cmd_in[0][y][WEST]);
1470     clusters[0][y]->p_dspin_ram_cmd_out[WEST]      (signal_dspin_false_ram_cmd_out[0][y][WEST]);
1471     clusters[0][y]->p_dspin_ram_rsp_in[WEST]       (signal_dspin_false_ram_rsp_in[0][y][WEST]);
1472     clusters[0][y]->p_dspin_ram_rsp_out[WEST]      (signal_dspin_false_ram_rsp_out[0][y][WEST]);
1473
1474     clusters[X_SIZE-1][y]->p_dspin_ram_cmd_in[EAST]  (signal_dspin_false_ram_cmd_in[X_SIZE-1][y][EAST]);
1475     clusters[X_SIZE-1][y]->p_dspin_ram_cmd_out[EAST] (signal_dspin_false_ram_cmd_out[X_SIZE-1][y][EAST]);
1476     clusters[X_SIZE-1][y]->p_dspin_ram_rsp_in[EAST]  (signal_dspin_false_ram_rsp_in[X_SIZE-1][y][EAST]);
1477     clusters[X_SIZE-1][y]->p_dspin_ram_rsp_out[EAST] (signal_dspin_false_ram_rsp_out[X_SIZE-1][y][EAST]);
1478   }
1479
1480   std::cout << "East & West boundaries established" << std::endl;
1481
1482   // North & South boundary clusters connections
1483   for (size_t x = 0; x < X_SIZE; x++)
1484   {
1485      for (size_t k = 0; k < 3; k++)
1486      {
1487         clusters[x][0]->p_dspin_int_cmd_in[SOUTH][k]         (signal_dspin_false_int_cmd_in[x][0][SOUTH][k]);
1488         clusters[x][0]->p_dspin_int_cmd_out[SOUTH][k]        (signal_dspin_false_int_cmd_out[x][0][SOUTH][k]);
1489         clusters[x][Y_SIZE-1]->p_dspin_int_cmd_in[NORTH][k]  (signal_dspin_false_int_cmd_in[x][Y_SIZE-1][NORTH][k]);
1490         clusters[x][Y_SIZE-1]->p_dspin_int_cmd_out[NORTH][k] (signal_dspin_false_int_cmd_out[x][Y_SIZE-1][NORTH][k]);
1491      }
1492
1493      for (size_t k = 0; k < 2; k++)
1494      {
1495         clusters[x][0]->p_dspin_int_rsp_in[SOUTH][k]         (signal_dspin_false_int_rsp_in[x][0][SOUTH][k]);
1496         clusters[x][0]->p_dspin_int_rsp_out[SOUTH][k]        (signal_dspin_false_int_rsp_out[x][0][SOUTH][k]);
1497         clusters[x][Y_SIZE-1]->p_dspin_int_rsp_in[NORTH][k]  (signal_dspin_false_int_rsp_in[x][Y_SIZE-1][NORTH][k]);
1498         clusters[x][Y_SIZE-1]->p_dspin_int_rsp_out[NORTH][k] (signal_dspin_false_int_rsp_out[x][Y_SIZE-1][NORTH][k]);
1499      }
1500
1501      clusters[x][0]->p_dspin_ram_cmd_in[SOUTH]       (signal_dspin_false_ram_cmd_in[x][0][SOUTH]);
1502      clusters[x][0]->p_dspin_ram_cmd_out[SOUTH]      (signal_dspin_false_ram_cmd_out[x][0][SOUTH]);
1503      clusters[x][0]->p_dspin_ram_rsp_in[SOUTH]       (signal_dspin_false_ram_rsp_in[x][0][SOUTH]);
1504      clusters[x][0]->p_dspin_ram_rsp_out[SOUTH]      (signal_dspin_false_ram_rsp_out[x][0][SOUTH]);
1505
1506      clusters[x][Y_SIZE-1]->p_dspin_ram_cmd_in[NORTH]  (signal_dspin_false_ram_cmd_in[x][Y_SIZE-1][NORTH]);
1507      clusters[x][Y_SIZE-1]->p_dspin_ram_cmd_out[NORTH] (signal_dspin_false_ram_cmd_out[x][Y_SIZE-1][NORTH]);
1508      clusters[x][Y_SIZE-1]->p_dspin_ram_rsp_in[NORTH]  (signal_dspin_false_ram_rsp_in[x][Y_SIZE-1][NORTH]);
1509      clusters[x][Y_SIZE-1]->p_dspin_ram_rsp_out[NORTH] (signal_dspin_false_ram_rsp_out[x][Y_SIZE-1][NORTH]);
1510   }
1511
1512   std::cout << "North & South boundaries established" << std::endl << std::endl;
1513
1514   ////////////////////////////////////////////////////////
1515   //   Simulation
1516   ///////////////////////////////////////////////////////
1517
1518   sc_start(sc_core::sc_time(0, SC_NS));
1519
1520   signal_resetn = false;
1521   signal_false  = false;
1522
1523   // network boundaries signals
1524   for (size_t x = 0; x < X_SIZE ; x++)
1525   {
1526      for (size_t y = 0; y < Y_SIZE ; y++)
1527      {
1528         for (size_t a = 0; a < 4; a++)
1529         {
1530            for (size_t k = 0; k < 3; k++)
1531            {
1532               signal_dspin_false_int_cmd_in[x][y][a][k].write = false;
1533               signal_dspin_false_int_cmd_in[x][y][a][k].read = true;
1534               signal_dspin_false_int_cmd_out[x][y][a][k].write = false;
1535               signal_dspin_false_int_cmd_out[x][y][a][k].read = true;
1536            }
1537
1538            for (size_t k = 0; k < 2; k++)
1539            {
1540               signal_dspin_false_int_rsp_in[x][y][a][k].write = false;
1541               signal_dspin_false_int_rsp_in[x][y][a][k].read = true;
1542               signal_dspin_false_int_rsp_out[x][y][a][k].write = false;
1543               signal_dspin_false_int_rsp_out[x][y][a][k].read = true;
1544            }
1545
1546            signal_dspin_false_ram_cmd_in[x][y][a].write = false;
1547            signal_dspin_false_ram_cmd_in[x][y][a].read = true;
1548            signal_dspin_false_ram_cmd_out[x][y][a].write = false;
1549            signal_dspin_false_ram_cmd_out[x][y][a].read = true;
1550
1551            signal_dspin_false_ram_rsp_in[x][y][a].write = false;
1552            signal_dspin_false_ram_rsp_in[x][y][a].read = true;
1553            signal_dspin_false_ram_rsp_out[x][y][a].write = false;
1554            signal_dspin_false_ram_rsp_out[x][y][a].read = true;
1555         }
1556      }
1557   }
1558
1559#if !USE_NIC
1560   for (int i = 0; i < NB_NIC_CHANNELS; i++)
1561   {
1562       signal_irq_mnic_rx[i].write(false);
1563       signal_irq_mnic_tx[i].write(false);
1564   }
1565
1566   signal_vci_ini_cdma.cmdval.write(false);
1567   signal_vci_ini_cdma.rspack.write(true);
1568   for (int i = 0; i < (NB_NIC_CHANNELS*2); i++)
1569   {
1570       signal_irq_cdma[i].write(false);
1571   }
1572#endif
1573
1574   sc_start(sc_core::sc_time(1, SC_NS));
1575   signal_resetn = true;
1576
1577   // simulation loop
1578   struct timeval t1, t2;
1579
1580   // cycles between stats
1581   const size_t stats_period = 500000;
1582   const size_t simul_period = debug_ok ? debug_period : stats_period;
1583
1584   for (size_t n = 0; n < ncycles; n += simul_period)
1585   {
1586      // stats display
1587      if((n % stats_period) == 0)
1588      {
1589         if (n > 0)
1590         {
1591            gettimeofday(&t2, NULL);
1592
1593            uint64_t ms1 = (uint64_t) t1.tv_sec  * 1000ULL +
1594               (uint64_t) t1.tv_usec / 1000;
1595            uint64_t ms2 = (uint64_t) t2.tv_sec  * 1000ULL +
1596               (uint64_t) t2.tv_usec / 1000;
1597            std::cerr << "### cycle = " << std::dec << n << " / frequency (Khz) = "
1598               << (double) stats_period / (double) (ms2 - ms1) << std::endl;
1599         }
1600
1601         gettimeofday(&t1, NULL);
1602      }
1603
1604      if (debug_ok and (n > debug_from) and (n % debug_period == 0))
1605      {
1606         std::cout << "****************** cycle " << std::dec << n ;
1607         std::cout << " ************************************************" << std::endl;
1608
1609         // trace proc[debug_proc_id]
1610         if ( debug_proc_id != 0xFFFFFFFF )
1611         {
1612            size_t l          = debug_proc_id & ((1 << P_WIDTH) - 1);
1613            size_t cluster_xy = debug_proc_id >> P_WIDTH ;
1614            size_t x          = cluster_xy >> Y_WIDTH;
1615            size_t y          = cluster_xy & ((1 << Y_WIDTH) - 1);
1616
1617            TsarCluster *c = clusters[x][y];
1618
1619            c->proc[l]->print_trace(1);
1620            std::ostringstream proc_signame;
1621            proc_signame << "[SIG]PROC_" << x << "_" << y << "_" << l ;
1622            c->signal_int_vci_ini_proc[l].print_trace(proc_signame.str());
1623
1624            c->xicu->print_trace(l);
1625            std::ostringstream xicu_signame;
1626            xicu_signame << "[SIG]XICU_" << x << "_" << y;
1627            c->signal_int_vci_tgt_xicu.print_trace(xicu_signame.str());
1628
1629            if( c->signal_proc_it[l].read() )
1630               std::cout << "### IRQ_PROC_" << std::dec
1631                  << x << "_" << y << "_" << l << " ACTIVE" << std::endl;
1632
1633            c->int_xbar_d->print_trace();
1634         }
1635
1636         // trace memc[debug_memc_id]
1637         if ( debug_memc_id != 0xFFFFFFFF )
1638         {
1639            size_t x = debug_memc_id >> Y_WIDTH;
1640            size_t y = debug_memc_id & ((1 << Y_WIDTH) - 1);
1641
1642            TsarCluster *c = clusters[x][y];
1643
1644            c->memc->print_trace(0);
1645            std::ostringstream smemc_tgt;
1646            smemc_tgt << "[SIG]MEMC_TGT_" << x << "_" << y;
1647            c->signal_int_vci_tgt_memc.print_trace(smemc_tgt.str());
1648            std::ostringstream smemc_ini;
1649            smemc_ini << "[SIG]MEMC_INI_" << x << "_" << y;
1650            c->signal_ram_vci_ini_memc.print_trace(smemc_ini.str());
1651
1652            c->drom->print_trace();
1653            std::ostringstream sdrom_tgt;
1654            sdrom_tgt << "[SIG]DROM_TGT_" << x << "_" << y;
1655            c->signal_int_vci_tgt_drom.print_trace(sdrom_tgt.str());
1656
1657            c->xram->print_trace();
1658            std::ostringstream sxram_tgt;
1659            sxram_tgt << "[SIG]XRAM_TGT_" << x << "_" << y;
1660            c->signal_ram_vci_tgt_xram.print_trace(sxram_tgt.str());
1661         }
1662
1663
1664         // trace XRAM and XRAM network routers in cluster[debug_xram_id]
1665         if ( debug_xram_id != 0xFFFFFFFF )
1666         {
1667            size_t x = debug_xram_id >> Y_WIDTH;
1668            size_t y = debug_xram_id & ((1 << Y_WIDTH) - 1);
1669
1670            TsarCluster *c = clusters[x][y];
1671
1672            c->xram->print_trace();
1673            std::ostringstream sxram_tgt;
1674            sxram_tgt << "[SIG]XRAM_TGT_" << x << "_" << y;
1675            c->signal_ram_vci_tgt_xram.print_trace(sxram_tgt.str());
1676
1677            c->ram_router_cmd->print_trace();
1678            c->ram_router_rsp->print_trace();
1679         }
1680
1681         // trace iob, iox and external peripherals
1682         if ( debug_iob )
1683         {
1684            TsarCluster* c;
1685
1686            c = clusters[0][0];
1687            c->iob->print_trace();
1688            c->signal_int_vci_tgt_iobx.print_trace("[SIG]IOB0_INT_TGT");
1689            c->signal_int_vci_ini_iobx.print_trace("[SIG]IOB0_INT_INI");
1690            c->signal_ram_vci_ini_iobx.print_trace("[SIG]IOB0_RAM_INI");
1691            signal_vci_ini_iob0.print_trace("[SIG]IOB0_IOX_INI");
1692            signal_vci_tgt_iob0.print_trace("[SIG]IOB0_IOX_TGT");
1693
1694            c = clusters[X_SIZE-1][Y_SIZE-1];
1695            c->iob->print_trace();
1696            c->signal_int_vci_tgt_iobx.print_trace("[SIG]IOB1_INT_TGT");
1697            c->signal_int_vci_ini_iobx.print_trace("[SIG]IOB1_INT_INI");
1698            c->signal_ram_vci_ini_iobx.print_trace("[SIG]IOB1_RAM_INI");
1699            signal_vci_ini_iob1.print_trace("[SIG]IOB1_IOX_INI");
1700            signal_vci_tgt_iob1.print_trace("[SIG]IOB1_IOX_TGT");
1701
1702            mtty->print_trace();
1703            signal_vci_tgt_mtty.print_trace("[SIG]IOX_MTTY_TGT");
1704
1705            bdev->print_trace();
1706            signal_vci_tgt_bdev.print_trace("[SIG]BDEV_TGT");
1707            signal_vci_ini_bdev.print_trace("[SIG]BDEV_INI");
1708
1709            iopi->print_trace();
1710            signal_vci_ini_iopi.print_trace("[SIG]IOPI_INI");
1711            signal_vci_tgt_iopi.print_trace("[SIG]IOPI_TGT");
1712
1713            // interrupts
1714            if (signal_irq_bdev)
1715               std::cout << "### IRQ_BDEV ACTIVE" << std::endl;
1716            if (signal_irq_mtty_rx[0])
1717               std::cout << "### IRQ_MTTY ACTIVE" << std::endl;
1718
1719#if USE_NIC
1720            for ( size_t i=0 ; i<NB_NIC_CHANNELS ; ++i )
1721               if (signal_irq_mnic_rx[i])
1722                  std::cout << "### IRQ_MNIC_RX[" << i << "] ACTIVE" << std::endl;
1723               if (signal_irq_mnic_tx[i])
1724                  std::cout << "### IRQ_MNIC_TX[" << i << "] ACTIVE" << std::endl;
1725#endif
1726         }
1727      }
1728
1729      sc_start(sc_core::sc_time(simul_period, SC_NS));
1730   }
1731   return EXIT_SUCCESS;
1732}
1733
1734int sc_main (int argc, char *argv[])
1735{
1736   try {
1737      return _main(argc, argv);
1738   } catch (soclib::exception::RunTimeError &e) {
1739      std::cout << "RunTimeError: " << e.what() << std::endl;
1740   } catch (std::exception &e) {
1741      std::cout << e.what() << std::endl;
1742   } catch (...) {
1743      std::cout << "Unknown exception occured" << std::endl;
1744      throw;
1745   }
1746   return 1;
1747}
1748
1749
1750// Local Variables:
1751// tab-width: 3
1752// c-basic-offset: 3
1753// c-file-offsets:((innamespace . 0)(inline-open . 0))
1754// indent-tabs-mode: nil
1755// End:
1756
1757// vim: filetype=cpp:expandtab:shiftwidth=3:tabstop=3:softtabstop=3
Note: See TracBrowser for help on using the repository browser.