Index: trunk/platforms/tsar_generic_leti/top.cpp
===================================================================
--- trunk/platforms/tsar_generic_leti/top.cpp	(revision 951)
+++ trunk/platforms/tsar_generic_leti/top.cpp	(revision 967)
@@ -1,4 +1,4 @@
 /////////////////////////////////////////////////////////////////////////
-// File: top.cpp (for tsar_generic_leti)
+// File: top.cpp (for tsar_generic_leti platform)
 // Author: Alain Greiner
 // Copyright: UPMC/LIP6
@@ -11,18 +11,22 @@
 //
 // The processor is a MIPS32 processor wrapped in a GDB server
-// (this is defined in the tsar_xbar_cluster).
+// (this is defined in the tsar_leti_cluster).
 //
 // The main hardware parameters are the mesh size (X_SIZE & Y_SIZE),
 // and the number of processors per cluster (NB_PROCS_MAX).
 // The NB_PROCS_MAX parameter cannot be larger than 4.
+// Others parameters are the frame buffer size, the disk controller type
+// (BDV or HBA), the number of TTY channels, the number of NIC channels,
+// and the number of CMA channels. 
 //
 // All external peripherals are located in cluster[X_SIZE-1][Y_SIZE-1],
 // and are connected to an IO bus (implemented as a vci_local_crossbar):
-// - one disk controller
-// - one multi-channel ethernet controller
-// - one multi-channel chained buffer dma controller
-// - one multi-channel tty controller
-// - one frame buffer controller
-// - one iopic controller
+// - DISK : block device controller (BDV / HBA)
+// - MNIC : multi-channel ethernet controller
+// - CDMA : multi-channel chained buffer dma controller
+// - MTTY : multi-channel tty controller
+// - FBUF : frame buffer controller
+// - IOPI : HWI to SWI translator 
+//
 // This IO bus is directly connected to the north ports of the CMD/RSP
 // routers in cluster[X_SIZE-1][y_SIZE-2] through VCI/DSPIN wrappers.
@@ -47,10 +51,9 @@
 //
 // Each processor receives 4 consecutive IRQ lines from the local XICU.
+// The number of PTI and WTI IRQs is bounded to 16.
 //
 // In all clusters, the MEMC IRQ line (signaling a late write error)
 // is connected to XICU HWI[8]
 //
-// This IOBUS is connected to the north  port of the DIR_CMD
-// and DIR_RSP routers, in cluster(X_SIZE-1, Y_SIZE-1).
 // For all external peripherals, the hardware interrupts (HWI) are
 // translated to write interrupts (WTI) by the iopic component:
@@ -58,5 +61,5 @@
 // - IOPIC HWI[3:2]     connected to IRQ_NIC_TX[1:0]
 // - IOPIC HWI[7:4]     connected to IRQ_CMA_TX[3:0]]
-// - IOPIC HWI[8]       connected to IRQ_BDEV
+// - IOPIC HWI[8]       connected to IRQ_DISK
 // - IOPIC HWI[15:9]    unused       (grounded)
 // - IOPIC HWI[23:16]   connected to IRQ_TTY_RX[7:0]]
@@ -69,4 +72,5 @@
 // - X_WIDTH          : number of bits for x coordinate (must be 4)
 // - Y_WIDTH          : number of bits for y coordinate (must be 4)
+// - P_WIDTH          : number of bits for local processor coordinate
 // - X_SIZE           : number of clusters in a row (1,2,4,8,16)
 // - Y_SIZE           : number of clusters in a column (1,2,4,8)
@@ -77,4 +81,9 @@
 // - FBUF_X_SIZE      : number of pixels per line for frame buffer
 // - FBUF_Y_SIZE      : number of lines for frame buffer
+// - XCU_NB_HWI       : number of XCU HWIs (must be 16)
+// - XCU_NB_PTI       : number of XCU PTIs (must be 16)
+// - XCU_NB_WTI       : number of XCU WTIs (must be 16)
+// - XCU_NB_OUT       : number of XCU output (must be 16)
+// - USE_IOC_XYZ      : IOC type (XYZ in HBA / BDV / SDC / RDK)
 //
 // Some other hardware parameters are not used when compiling the OS,
@@ -85,5 +94,5 @@
 // - L1_DWAYS         : L1 cache data number of ways
 // - L1_DSETS         : L1 cache data number of sets
-// - BDEV_IMAGE_NAME  : pathname for block device disk image
+// - DISK_IMAGE_NAME  : pathname for block device disk image
 /////////////////////////////////////////////////////////////////////////
 // General policy for 40 bits physical address decoding:
@@ -111,4 +120,5 @@
 #include "gdbserver.h"
 #include "mapping_table.h"
+
 #include "tsar_leti_cluster.h"
 #include "vci_local_crossbar.h"
@@ -119,13 +129,47 @@
 #include "vci_chbuf_dma.h"
 #include "vci_block_device_tsar.h"
+#include "vci_multi_ahci.h"
 #include "vci_framebuffer.h"
 #include "vci_iopic.h"
+
 #include "alloc_elems.h"
 
+///////////////////////////////////////////////////
+// Main hardware parameters values
+///////////////////////////////////////////////////
+
 #include "hard_config.h"
+
+///////////////////////////////////////////////////////////////////////////////////////
+//    Secondary Hardware Parameters
+///////////////////////////////////////////////////////////////////////////////////////
+
+#define XMAX                  X_SIZE         // actual number of columns in 2D mesh
+#define YMAX                  (Y_SIZE - 1)   // actual number of rows in 2D mesh
+
+#define XRAM_LATENCY          0
+
+#define MEMC_WAYS             16
+#define MEMC_SETS             256
+
+#define L1_IWAYS              4
+#define L1_ISETS              64
+
+#define L1_DWAYS              4
+#define L1_DSETS              64
+
+#define DISK_IMAGE_NAME       "../../../giet_vm/hdd/virt_hdd.dmg"
+
+#define ROM_SOFT_NAME         "../../softs/tsar_boot/preloader.elf"
+
+#define NORTH                 0
+#define SOUTH                 1
+#define EAST                  2
+#define WEST                  3
 
 ///////////////////////////////////////////////////
 //               Parallelisation
 ///////////////////////////////////////////////////
+
 #define USE_OPENMP _OPENMP
 
@@ -164,30 +208,4 @@
 
 
-///////////////////////////////////////////////////////////////////////////////////////
-//    Secondary Hardware Parameters
-///////////////////////////////////////////////////////////////////////////////////////
-
-#define XMAX                  X_SIZE         // actual number of columns in 2D mesh
-#define YMAX                  (Y_SIZE - 1)   // actual number of rows in 2D mesh
-
-#define XRAM_LATENCY          0
-
-#define MEMC_WAYS             16
-#define MEMC_SETS             256
-
-#define L1_IWAYS              4
-#define L1_ISETS              64
-
-#define L1_DWAYS              4
-#define L1_DSETS              64
-
-#define BDEV_IMAGE_NAME       "../../../giet_vm/hdd/virt_hdd.dmg"
-
-#define ROM_SOFT_NAME         "../../softs/tsar_boot/preloader.elf"
-
-#define NORTH                 0
-#define SOUTH                 1
-#define EAST                  2
-#define WEST                  3
 
 ///////////////////////////////////////////////////////////////////////////////////////
@@ -205,5 +223,5 @@
 #define XICU_TGTID            1
 #define MTTY_TGTID            2
-#define BDEV_TGTID            3
+#define DISK_TGTID            3
 #define FBUF_TGTID            4
 #define MNIC_TGTID            5
@@ -211,5 +229,5 @@
 #define IOPI_TGTID            7
 
-#define BDEV_SRCID            NB_PROCS_MAX
+#define DISK_SRCID            NB_PROCS_MAX
 #define CDMA_SRCID            NB_PROCS_MAX + 1
 #define IOPI_SRCID            NB_PROCS_MAX + 2
@@ -233,5 +251,5 @@
    size_t   trace_proc_id     = 0;                  // index of proc to be traced
    char     soft_name[256]    = ROM_SOFT_NAME;      // pathname for ROM binary code
-   char     disk_name[256]    = BDEV_IMAGE_NAME;    // pathname for DISK image
+   char     disk_name[256]    = DISK_IMAGE_NAME;    // pathname for DISK image
    uint32_t frozen_cycles     = MAX_FROZEN_CYCLES;  // for debug
    struct   timeval t1,t2;
@@ -260,5 +278,5 @@
 
             assert( (x < XMAX) and (y < (YMAX)) and
-                  "MEMCID parameter refers a not valid memory cache");
+                  "MEMCID parameter doesxn't fit valid XMAX/YMAX");
          }
          else if ((strcmp(argv[n], "-PROCID") == 0) && (n + 1 < argc))
@@ -273,12 +291,4 @@
             assert( (x < XMAX) and (y < YMAX) and (l < NB_PROCS_MAX) and
                   "PROCID parameter refers a not valid processor");
-         }
-         else if ((strcmp(argv[n], "-ROM") == 0) && ((n + 1) < argc))
-         {
-            strcpy(soft_name, argv[n + 1]);
-         }
-         else if ((strcmp(argv[n], "-DISK") == 0) && ((n + 1) < argc))
-         {
-            strcpy(disk_name, argv[n + 1]);
          }
          else if ((strcmp(argv[n], "-THREADS") == 0) && ((n + 1) < argc))
@@ -298,9 +308,6 @@
             std::cout << "     - NCYCLES number_of_simulated_cycles" << std::endl;
             std::cout << "     - DEBUG debug_start_cycle" << std::endl;
-            std::cout << "     - ROM path to ROM image" << std::endl;
-            std::cout << "     - DISK path to disk image" << std::endl;
             std::cout << "     - THREADS simulator's threads number" << std::endl;
             std::cout << "     - FROZEN max_number_of_lines" << std::endl;
-            std::cout << "     - PERIOD number_of_cycles between trace" << std::endl;
             std::cout << "     - MEMCID index_memc_to_be_traced" << std::endl;
             std::cout << "     - PROCID index_proc_to_be_traced" << std::endl;
@@ -323,9 +330,21 @@
             "Illegal NB_PROCS_MAX parameter" );
 
+    assert( (XCU_NB_HWI == 16) and
+            "XCU_NB_HWI must be 16" );
+
+    assert( (XCU_NB_PTI == 16) and
+            "XCU_NB_PTI must be 16" );
+
+    assert( (XCU_NB_WTI == 16) and
+            "XCU_NB_WTI must be 16" );
+
+    assert( (XCU_NB_OUT == 16) and
+            "XCU_NB_OUT must be 16" );
+   
     assert( (NB_CMA_CHANNELS <= 4) and
             "The NB_CMA_CHANNELS parameter cannot be larger than 4" );
 
     assert( (NB_TTY_CHANNELS <= 8) and
-            "The NB_TTY_CHANNELS parameter cannot be larger than 16" );
+            "The NB_TTY_CHANNELS parameter cannot be larger than 8" );
 
     assert( (NB_NIC_CHANNELS <= 2) and
@@ -340,19 +359,21 @@
     std::cout << std::endl;
 
-    std::cout << " - XMAX           = " << XMAX << std::endl;
-    std::cout << " - YMAX           = " << YMAX << std::endl;
-    std::cout << " - NB_PROCS_MAX     = " << NB_PROCS_MAX <<  std::endl;
-    std::cout << " - NB_TTY_CHANNELS  = " << NB_TTY_CHANNELS <<  std::endl;
-    std::cout << " - NB_NIC_CHANNELS  = " << NB_NIC_CHANNELS <<  std::endl;
-    std::cout << " - NB_CMA_CHANNELS  = " << NB_CMA_CHANNELS <<  std::endl;
-    std::cout << " - MEMC_WAYS        = " << MEMC_WAYS << std::endl;
-    std::cout << " - MEMC_SETS        = " << MEMC_SETS << std::endl;
-    std::cout << " - RAM_LATENCY      = " << XRAM_LATENCY << std::endl;
-    std::cout << " - MAX_FROZEN       = " << frozen_cycles << std::endl;
-    std::cout << " - MAX_CYCLES       = " << ncycles << std::endl;
-    std::cout << " - RESET_ADDRESS    = " << RESET_ADDRESS << std::endl;
-    std::cout << " - SOFT_FILENAME    = " << soft_name << std::endl;
-    std::cout << " - DISK_IMAGENAME   = " << disk_name << std::endl;
-    std::cout << " - OPENMP THREADS   = " << threads << std::endl;
+    std::cout << " - XMAX             = " << XMAX << std::endl
+              << " - YMAX             = " << YMAX << std::endl
+              << " - NB_PROCS_MAX     = " << NB_PROCS_MAX <<  std::endl
+              << " - NB_TTY_CHANNELS  = " << NB_TTY_CHANNELS <<  std::endl
+              << " - NB_NIC_CHANNELS  = " << NB_NIC_CHANNELS <<  std::endl
+              << " - NB_CMA_CHANNELS  = " << NB_CMA_CHANNELS <<  std::endl
+              << " - MEMC_WAYS        = " << MEMC_WAYS << std::endl
+              << " - MEMC_SETS        = " << MEMC_SETS << std::endl
+              << " - RAM_LATENCY      = " << XRAM_LATENCY << std::endl
+              << " - MAX_FROZEN       = " << frozen_cycles << std::endl
+              << " - MAX_CYCLES       = " << ncycles << std::endl
+              << " - RESET_ADDRESS    = " << RESET_ADDRESS << std::endl
+              << " - SOFT_FILENAME    = " << soft_name << std::endl
+              << " - DISK_IMAGENAME   = " << disk_name << std::endl
+              << " - OPENMP THREADS   = " << threads << std::endl
+              << " - DEBUG_PROCID     = " << trace_proc_id << std::endl
+              << " - DEBUG_MEMCID     = " << trace_memc_id << std::endl;
 
     std::cout << std::endl;
@@ -427,5 +448,5 @@
 
    maptabd.add(Segment("seg_ioc0", SEG_IOC_BASE, SEG_IOC_SIZE,
-               IntTab(cluster(0,0),BDEV_TGTID), false));
+               IntTab(cluster(0,0),DISK_TGTID), false));
 
    // segments for peripherals in cluster_io (XMAX-1,YMAX)
@@ -439,6 +460,6 @@
                IntTab(cluster(XMAX-1, YMAX),FBUF_TGTID), false));
 
-   maptabd.add(Segment("seg_bdev", SEG_IOC_BASE + offset, SEG_IOC_SIZE,
-               IntTab(cluster(XMAX-1, YMAX),BDEV_TGTID), false));
+   maptabd.add(Segment("seg_disk", SEG_IOC_BASE + offset, SEG_IOC_SIZE,
+               IntTab(cluster(XMAX-1, YMAX),DISK_TGTID), false));
 
    maptabd.add(Segment("seg_mnic", SEG_NIC_BASE + offset, SEG_NIC_SIZE,
@@ -487,5 +508,5 @@
 
     // IRQs from external peripherals
-    sc_signal<bool>                   signal_irq_bdev;
+    sc_signal<bool>                   signal_irq_disk;
     sc_signal<bool>                   signal_irq_mnic_rx[NB_NIC_CHANNELS];
     sc_signal<bool>                   signal_irq_mnic_tx[NB_NIC_CHANNELS];
@@ -573,5 +594,5 @@
 
    // VCI signals for iobus and peripherals
-   VciSignals<vci_param_int>    signal_vci_ini_bdev("signal_vci_ini_bdev");
+   VciSignals<vci_param_int>    signal_vci_ini_disk("signal_vci_ini_disk");
    VciSignals<vci_param_int>    signal_vci_ini_cdma("signal_vci_ini_cdma");
    VciSignals<vci_param_int>    signal_vci_ini_iopi("signal_vci_ini_iopi");
@@ -582,5 +603,5 @@
    VciSignals<vci_param_int>    signal_vci_tgt_memc("signal_vci_tgt_memc");
    VciSignals<vci_param_int>    signal_vci_tgt_xicu("signal_vci_tgt_xicu");
-   VciSignals<vci_param_int>    signal_vci_tgt_bdev("signal_vci_tgt_bdev");
+   VciSignals<vci_param_int>    signal_vci_tgt_disk("signal_vci_tgt_disk");
    VciSignals<vci_param_int>    signal_vci_tgt_mtty("signal_vci_tgt_mtty");
    VciSignals<vci_param_int>    signal_vci_tgt_fbuf("signal_vci_tgt_fbuf");
@@ -660,5 +681,5 @@
                 XICU_TGTID,
                 MTTY_TGTID,
-                BDEV_TGTID,
+                DISK_TGTID,
                 disk_name,
                 MEMC_WAYS,
@@ -713,5 +734,5 @@
                 NB_PROCS_MAX + 3,             // number of local initiators
                 8,                            // number of local targets
-                BDEV_TGTID );                 // default target index
+                DISK_TGTID );                 // default target index
 
     //////////// vci_framebuffer
@@ -723,14 +744,34 @@
                 FBUF_X_SIZE, FBUF_Y_SIZE );
 
+#if ( USE_IOC_HBA )
+
+    ////////////  vci_multi_ahci
+    std::vector<std::string> filenames;
+    filenames.push_back(disk_name);           // one single disk
+    VciMultiAhci<vci_param_int>*  
+    disk = new VciMultiAhci<vci_param_int>( 
+                "disk",
+                maptabd,
+                IntTab(cluster_io, DISK_SRCID),
+                IntTab(cluster_io, DISK_TGTID),
+                filenames,
+                512,                          // block size
+                64,                           // burst size (bytes)
+                0 );                          // disk latency
+
+#elif ( USE_IOC_BDV or USE_IOC_SDC )
+
     ////////////  vci_block_device
     VciBlockDeviceTsar<vci_param_int>*
-    bdev = new VciBlockDeviceTsar<vci_param_int>(
-                "bdev",
+    disk = new VciBlockDeviceTsar<vci_param_int>(
+                "disk",
                 maptabd,
-                IntTab(cluster_io, BDEV_SRCID),
-                IntTab(cluster_io, BDEV_TGTID),
+                IntTab(cluster_io, DISK_SRCID),
+                IntTab(cluster_io, DISK_TGTID),
                 disk_name,
                 512,                          // block size
-                64 );                         // burst size
+                64,                           // burst size (bytes)
+                0 );                          // disk latency
+#endif
 
     //////////// vci_multi_nic
@@ -807,5 +848,5 @@
     iobus->p_to_target[FBUF_TGTID]     (signal_vci_tgt_fbuf);
     iobus->p_to_target[MNIC_TGTID]     (signal_vci_tgt_mnic);
-    iobus->p_to_target[BDEV_TGTID]     (signal_vci_tgt_bdev);
+    iobus->p_to_target[DISK_TGTID]     (signal_vci_tgt_disk);
     iobus->p_to_target[CDMA_TGTID]     (signal_vci_tgt_cdma);
     iobus->p_to_target[IOPI_TGTID]     (signal_vci_tgt_iopi);
@@ -815,5 +856,5 @@
         iobus->p_to_initiator[p]       (signal_vci_ini_proc[p]);
     }
-    iobus->p_to_initiator[BDEV_SRCID]  (signal_vci_ini_bdev);
+    iobus->p_to_initiator[DISK_SRCID]  (signal_vci_ini_disk);
     iobus->p_to_initiator[CDMA_SRCID]  (signal_vci_ini_cdma);
     iobus->p_to_initiator[IOPI_SRCID]  (signal_vci_ini_iopi);
@@ -821,12 +862,16 @@
     std::cout << "  - IOBUS connected" << std::endl;
 
-    // block_device
-    bdev->p_clk                        (signal_clk);
-    bdev->p_resetn                     (signal_resetn);
-    bdev->p_vci_target                 (signal_vci_tgt_bdev);
-    bdev->p_vci_initiator              (signal_vci_ini_bdev);
-    bdev->p_irq                        (signal_irq_bdev);
-
-    std::cout << "  - BDEV connected" << std::endl;
+    // disk
+    disk->p_clk                        (signal_clk);
+    disk->p_resetn                     (signal_resetn);
+    disk->p_vci_target                 (signal_vci_tgt_disk);
+    disk->p_vci_initiator              (signal_vci_ini_disk);
+#if USE_IOC_HBA
+    disk->p_channel_irq[0]             (signal_irq_disk);
+#else
+    disk->p_irq                        (signal_irq_disk);
+#endif
+
+    std::cout << "  - DISK connected" << std::endl;
 
     // frame_buffer
@@ -888,5 +933,5 @@
        else if(i < 4+NB_CMA_CHANNELS)  iopic->p_hwi[i] (signal_irq_cdma[i-4]);
        else if(i < 8)                  iopic->p_hwi[i] (signal_irq_false);
-       else if(i == 8)                 iopic->p_hwi[i] (signal_irq_bdev);
+       else if(i == 8)                 iopic->p_hwi[i] (signal_irq_disk);
        else if(i < 16)                 iopic->p_hwi[i] (signal_irq_false);
        else if(i < 16+NB_TTY_CHANNELS) iopic->p_hwi[i] (signal_irq_mtty_rx[i-16]);
@@ -1236,7 +1281,7 @@
 #if USE_PIC
             // trace external ioc
-            bdev->print_trace();
-            signal_vci_tgt_bdev.print_trace("[SIG]BDEV_TGT");
-            signal_vci_ini_bdev.print_trace("[SIG]BDEV_INI");
+            disk->print_trace();
+            signal_vci_tgt_disk.print_trace("[SIG]DISK_TGT");
+            signal_vci_ini_disk.print_trace("[SIG]DISK_INI");
 
             // trace external iopic
@@ -1246,9 +1291,9 @@
 
             // trace external interrupts
-            if (signal_irq_bdev)   std::cout << "### IRQ_BDEV" << std::endl;
+            if (signal_irq_disk)   std::cout << "### IRQ_DISK" << std::endl;
 #else
-            clusters[0][0]->bdev->print_trace();
-            clusters[0][0]->signal_vci_tgt_bdev.print_trace("[SIG]BDEV_0_0");
-            clusters[0][0]->signal_vci_ini_bdev.print_trace("[SIG]BDEV_0_0");
+            clusters[0][0]->disk->print_trace();
+            clusters[0][0]->signal_vci_tgt_disk.print_trace("[SIG]DISK_0_0");
+            clusters[0][0]->signal_vci_ini_disk.print_trace("[SIG]DISK_0_0");
 #endif
 
