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

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

reconf: any router in any NoC can be faulty. Moreover, each NoC has its
own config register in the XICU.

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