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

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

Introduce a SocLib? platform implementing the FPGA mono cluster platform

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