Ignore:
Timestamp:
Apr 13, 2015, 5:23:12 PM (9 years ago)
Author:
alain
Message:

Introducing support for the coprocessor related system calls.

Location:
soft/giet_vm/giet_kernel
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/giet_kernel/ctx_handler.h

    r528 r556  
    1919// allocated to the task (private peripheral channel)
    2020/////////////////////////////////////////////////////////////////////////////////
    21 // ctx[0] <- ***   |ctx[8] <- $8     |ctx[16]<- $16   |ctx[24]<- $24
    22 // ctx[1] <- $1    |ctx[9] <- $9     |ctx[17]<- $17   |ctx[25]<- $25
    23 // ctx[2] <- $2    |ctx[10]<- $10    |ctx[18]<- $18   |ctx[26]<- LO
    24 // ctx[3] <- $3    |ctx[11]<- $11    |ctx[19]<- $19   |ctx[27]<- HI
    25 // ctx[4] <- $4    |ctx[12]<- $12    |ctx[20]<- $20   |ctx[28]<- $28
    26 // ctx[5] <- $5    |ctx[13]<- $13    |ctx[21]<- $21   |ctx[29]<- SP
    27 // ctx[6] <- $6    |ctx[14]<- $14    |ctx[22]<- $22   |ctx[30]<- $30
    28 // ctx[7] <- $7    |ctx[15]<- $15    |ctx[23]<- $23   |ctx[31]<- RA
     21// ctx[0] <- ***   |ctx[8] <- $8     |ctx[16]<- $16    |ctx[24]<- $24
     22// ctx[1] <- $1    |ctx[9] <- $9     |ctx[17]<- $17    |ctx[25]<- $25
     23// ctx[2] <- $2    |ctx[10]<- $10    |ctx[18]<- $18    |ctx[26]<- LO
     24// ctx[3] <- $3    |ctx[11]<- $11    |ctx[19]<- $19    |ctx[27]<- HI
     25// ctx[4] <- $4    |ctx[12]<- $12    |ctx[20]<- $20    |ctx[28]<- $28
     26// ctx[5] <- $5    |ctx[13]<- $13    |ctx[21]<- $21    |ctx[29]<- SP
     27// ctx[6] <- $6    |ctx[14]<- $14    |ctx[22]<- $22    |ctx[30]<- $30
     28// ctx[7] <- $7    |ctx[15]<- $15    |ctx[23]<- $23    |ctx[31]<- RA
    2929//
    30 // ctx[32]<- EPC   |ctx[40]<- TTY    |ctx[48]<- TRDID |ctx[56]<- ***
    31 // ctx[33]<- CR    |ctx[41]<- CMA_FB |ctx[49]<- GTID  |ctx[57]<- ***
    32 // ctx[34]<- SR    |ctx[42]<- CMA_RX |ctx[50]<- RUN   |ctx[58]<- ***
    33 // ctx[35]<- BVAR  |ctx[43]<- CMA_TX |ctx[51]<- ***  |ctx[59]<- ***
    34 // ctx[36]<- PTAB  |ctx[44]<- NIC_RX |ctx[52]<- ***   |ctx[60]<- ***
    35 // ctx[37]<- LTID  |ctx[45]<- NIC_TX |ctx[53]<- ***   |ctx[61]<- ***
    36 // ctx[38]<- VSID  |ctx[46]<- TIM    |ctx[54]<- ***   |ctx[62]<- ***
    37 // ctx[39]<- PTPR  |ctx[47]<- HBA    |ctx[55]<- ***   |ctx[63]<- ***
     30// ctx[32]<- EPC   |ctx[40]<- TTY    |ctx[48]<- TRDID  |ctx[56]<- ***
     31// ctx[33]<- CR    |ctx[41]<- CMA_FB |ctx[49]<- GTID   |ctx[57]<- ***
     32// ctx[34]<- SR    |ctx[42]<- CMA_RX |ctx[50]<- RUN    |ctx[58]<- ***
     33// ctx[35]<- BVAR  |ctx[43]<- CMA_TX |ctx[51]<- COPROC |ctx[59]<- ***
     34// ctx[36]<- PTAB  |ctx[44]<- NIC_RX |ctx[52]<- ***    |ctx[60]<- ***
     35// ctx[37]<- LTID  |ctx[45]<- NIC_TX |ctx[53]<- ***    |ctx[61]<- ***
     36// ctx[38]<- VSID  |ctx[46]<- TIM    |ctx[54]<- ***    |ctx[62]<- ***
     37// ctx[39]<- PTPR  |ctx[47]<- HBA    |ctx[55]<- ***    |ctx[63]<- ***
    3838/////////////////////////////////////////////////////////////////////////////////
    3939
     
    7171#define CTX_GTID_ID      49  // Global Task Index in all system
    7272#define CTX_RUN_ID       50  // Boolean: task runable
     73#define CTX_COPROC_ID    51  // cluster_xy : coprocessor coordinates
    7374
    7475/////////////////////////////////////////////////////////////////////////////////
  • soft/giet_vm/giet_kernel/sys_handler.c

    r547 r556  
    7070// allocated in mwr_driver.c file.
    7171extern simple_lock_t  _coproc_lock[X_SIZE*Y_SIZE];
    72 extern unsigned int   _coproc_done[X_SIZE*Y_SIZE];
     72extern unsigned int   _coproc_type[X_SIZE*Y_SIZE];
     73extern unsigned int   _coproc_info[X_SIZE*Y_SIZE];
     74extern unsigned int   _coproc_mode[X_SIZE*Y_SIZE];
     75extern unsigned int   _coproc_error[X_SIZE*Y_SIZE];
     76extern unsigned int   _coproc_gtid[X_SIZE*Y_SIZE];
     77
    7378
    7479// allocated in tty_driver.c file.
     
    125130const void * _syscall_vector[64] =
    126131{
    127     &_sys_proc_xyp,             /* 0x00 */
    128     &_get_proctime,             /* 0x01 */
    129     &_sys_tty_write,            /* 0x02 */
    130     &_sys_tty_read,             /* 0x03 */
    131     &_sys_tty_alloc,            /* 0x04 */
    132     &_sys_tty_get_lock,         /* 0x05 */
    133     &_sys_tty_release_lock,     /* 0x06 */
    134     &_sys_heap_info,            /* 0x07 */
    135     &_sys_local_task_id,        /* 0x08 */
    136     &_sys_global_task_id,       /* 0x09 */
    137     &_sys_fbf_cma_alloc,        /* 0x0A */
    138     &_sys_fbf_cma_start,        /* 0x0B */
    139     &_sys_fbf_cma_display,      /* 0x0C */
    140     &_sys_fbf_cma_stop,         /* 0x0D */
    141     &_sys_task_exit,            /* 0x0E */
    142     &_sys_procs_number,         /* 0x0F */
    143 
    144     &_sys_fbf_sync_write,       /* 0x10 */
    145     &_sys_fbf_sync_read,        /* 0x11 */
    146     &_sys_thread_id,            /* 0x12 */
    147     &_sys_ukn,                  /* 0x13 */
    148     &_sys_tim_alloc,            /* 0x14 */
    149     &_sys_tim_start,            /* 0x15 */
    150     &_sys_tim_stop,             /* 0x16 */
    151     &_sys_ukn,                  /* 0x17 */
    152     &_sys_ukn,                  /* 0x18 */   
    153     &_sys_context_switch,       /* 0x19 */
    154     &_sys_vseg_get_vbase,       /* 0x1A */
    155     &_sys_vseg_get_length,      /* 0x1B */
    156     &_sys_xy_from_ptr,          /* 0x1C */
    157     &_sys_ukn,                  /* 0x1D */
    158     &_sys_ukn,                  /* 0x1E */
    159     &_sys_ukn,                  /* 0x1F */
    160 
    161     &_fat_user_open,            /* 0x20 */
    162     &_fat_user_read,            /* 0x21 */
    163     &_fat_user_write,           /* 0x22 */
    164     &_fat_user_lseek,           /* 0x23 */
    165     &_fat_fstat,                /* 0x24 */
    166     &_fat_close,                /* 0x25 */
    167     &_sys_ukn,                  /* 0x26 */
    168     &_sys_ukn,                  /* 0x27 */
    169     &_sys_ukn,                  /* 0x28 */
    170     &_sys_ukn,                  /* 0x29 */
    171     &_sys_ukn,                  /* 0x2A */
    172     &_sys_ukn,                  /* 0x2B */
    173     &_sys_ukn,                  /* 0x2C */
    174     &_sys_ukn,                  /* 0x2D */
    175     &_sys_ukn,                  /* 0x2E */
    176     &_sys_ukn,                  /* 0x2F */
    177 
    178     &_sys_nic_alloc,            /* 0x30 */
    179     &_sys_nic_start,            /* 0x31 */
    180     &_sys_nic_move,             /* 0x32 */
    181     &_sys_nic_stop,             /* 0x33 */
    182     &_sys_nic_stats,            /* 0x34 */
    183     &_sys_nic_clear,            /* 0x35 */
    184     &_sys_ukn,                  /* 0x36 */
    185     &_sys_ukn,                  /* 0x37 */
    186     &_sys_coproc_register_get,  /* 0x38 */   
    187     &_sys_coproc_register_set,  /* 0x39 */
    188     &_sys_coproc_release,       /* 0x3A */
    189     &_sys_coproc_completed,     /* 0x3B */
    190     &_sys_coproc_alloc,         /* 0x3C */
    191     &_sys_coproc_channel_init,  /* 0x3D */
    192     &_sys_coproc_channel_start, /* 0x3E */
    193     &_sys_coproc_channel_stop,  /* 0x3F */
     132    &_sys_proc_xyp,                  /* 0x00 */
     133    &_get_proctime,                  /* 0x01 */
     134    &_sys_tty_write,                 /* 0x02 */
     135    &_sys_tty_read,                  /* 0x03 */
     136    &_sys_tty_alloc,                 /* 0x04 */
     137    &_sys_tty_get_lock,              /* 0x05 */
     138    &_sys_tty_release_lock,          /* 0x06 */
     139    &_sys_heap_info,                 /* 0x07 */
     140    &_sys_local_task_id,             /* 0x08 */
     141    &_sys_global_task_id,            /* 0x09 */
     142    &_sys_fbf_cma_alloc,             /* 0x0A */
     143    &_sys_fbf_cma_start,             /* 0x0B */
     144    &_sys_fbf_cma_display,           /* 0x0C */
     145    &_sys_fbf_cma_stop,              /* 0x0D */
     146    &_sys_task_exit,                 /* 0x0E */
     147    &_sys_procs_number,              /* 0x0F */
     148
     149    &_sys_fbf_sync_write,            /* 0x10 */
     150    &_sys_fbf_sync_read,             /* 0x11 */
     151    &_sys_thread_id,                 /* 0x12 */
     152    &_sys_ukn,                       /* 0x13 */
     153    &_sys_tim_alloc,                 /* 0x14 */
     154    &_sys_tim_start,                 /* 0x15 */
     155    &_sys_tim_stop,                  /* 0x16 */
     156    &_sys_ukn,                       /* 0x17 */
     157    &_sys_ukn,                       /* 0x18 */   
     158    &_sys_context_switch,            /* 0x19 */
     159    &_sys_vseg_get_vbase,            /* 0x1A */
     160    &_sys_vseg_get_length,           /* 0x1B */
     161    &_sys_xy_from_ptr,               /* 0x1C */
     162    &_sys_ukn,                       /* 0x1D */
     163    &_sys_ukn,                       /* 0x1E */
     164    &_sys_ukn,                       /* 0x1F */
     165
     166    &_fat_user_open,                 /* 0x20 */
     167    &_fat_user_read,                 /* 0x21 */
     168    &_fat_user_write,                /* 0x22 */
     169    &_fat_user_lseek,                /* 0x23 */
     170    &_fat_fstat,                     /* 0x24 */
     171    &_fat_close,                     /* 0x25 */
     172    &_sys_ukn,                       /* 0x26 */
     173    &_sys_ukn,                       /* 0x27 */
     174    &_sys_ukn,                       /* 0x28 */
     175    &_sys_ukn,                       /* 0x29 */
     176    &_sys_ukn,                       /* 0x2A */
     177    &_sys_ukn,                       /* 0x2B */
     178    &_sys_ukn,                       /* 0x2C */
     179    &_sys_ukn,                       /* 0x2D */
     180    &_sys_ukn,                       /* 0x2E */
     181    &_sys_ukn,                       /* 0x2F */
     182
     183    &_sys_nic_alloc,                 /* 0x30 */
     184    &_sys_nic_start,                 /* 0x31 */
     185    &_sys_nic_move,                  /* 0x32 */
     186    &_sys_nic_stop,                  /* 0x33 */
     187    &_sys_nic_stats,                 /* 0x34 */
     188    &_sys_nic_clear,                 /* 0x35 */
     189    &_sys_ukn,                       /* 0x36 */
     190    &_sys_ukn,                       /* 0x37 */
     191    &_sys_ukn,                       /* 0x38 */   
     192    &_sys_ukn,                       /* 0x39 */
     193    &_sys_ukn,                       /* 0x3A */
     194    &_sys_coproc_completed,          /* 0x3B */
     195    &_sys_coproc_alloc,              /* 0x3C */
     196    &_sys_coproc_channel_init,       /* 0x3D */
     197    &_sys_coproc_run,                /* 0x3E */
     198    &_sys_coproc_release,            /* 0x3F */
    194199};
    195200
     
    199204//////////////////////////////////////////////////////////////////////////////
    200205
    201 ///////////////////////////////////////////////////////
    202 int _sys_coproc_register_set( unsigned int  cluster_xy,
    203                               unsigned int  reg_index,
    204                               unsigned int  value )
    205 {
    206     // TODO checking coprocessor ownership...
    207 
    208     _mwr_set_coproc_register( cluster_xy , reg_index , value );
    209     return 0;
    210 
    211 
    212 ///////////////////////////////////////////////////////
    213 int _sys_coproc_register_get( unsigned int   cluster_xy,
    214                               unsigned int   reg_index,
    215                               unsigned int*  buffer )
    216 {
    217     // TODO checking coprocessor ownership...
    218 
    219     *buffer = _mwr_get_coproc_register( cluster_xy , reg_index );
    220     return 0;
    221 
    222 
    223206//////////////////////////////////////////////////
    224207int _sys_coproc_alloc( unsigned int   coproc_type,
    225                        unsigned int*  coproc_info,
    226                        unsigned int*  cluster_xy )
     208                       unsigned int*  coproc_info )
    227209{
    228210    // In this implementation, the allocation policy is constrained:
    229211    // the coprocessor must be in the same cluster as the calling task,
    230     // and ther is at most one coprocessor per cluster
     212    // and there is at most one coprocessor per cluster
    231213
    232214    mapping_header_t  * header  = (mapping_header_t *)SEG_BOOT_MAPPING_BASE;
     
    238220    unsigned int x          = procid >> (Y_WIDTH + P_WIDTH);
    239221    unsigned int y          = (procid >> P_WIDTH) & ((1<<Y_WIDTH)-1);
    240     unsigned int cluster_id = x*Y_SIZE + y;
     222    unsigned int cluster_id = x * Y_SIZE + y;
    241223 
    242224    // search coprocessor in cluster
     
    259241        // get the lock (at most one coproc per cluster)
    260242        _simple_lock_acquire( &_coproc_lock[cluster_id] );
    261  
     243
     244        // register coproc characteristics in kernel arrays
     245        _coproc_type[cluster_id] = coproc_type;
     246        _coproc_info[cluster_id] = (found->arg0 & 0xFF)     |
     247                                   (found->arg1 & 0xFF)<<8  |
     248                                   (found->arg2 & 0xFF)<<16 |
     249                                   (found->arg3 & 0xFF)<<24 ;
     250
    262251        // returns coprocessor info
    263         *coproc_info = (found->arg0 & 0xFF)     |
    264                        (found->arg1 & 0xFF)<<8  |
    265                        (found->arg2 & 0xFF)<<16 |
    266                        (found->arg3 & 0xFF)<<24 ;
    267         *cluster_xy = (x<<Y_WIDTH) + y;
     252        *coproc_info = _coproc_info[cluster_id];
     253
     254        // register coprocessor coordinates in task context
     255        unsigned int cluster_xy = (x<<Y_WIDTH) + y;
     256        _set_context_slot( CTX_COPROC_ID , cluster_xy );
    268257
    269258#if GIET_DEBUG_COPROC
    270259_printf("\n[GIET DEBUG COPROC] _sys_coproc_alloc() in cluster[%d,%d]\n"
    271260        "  coproc_info = %x / cluster_xy = %x\n",
    272         x , y , *coproc_info , *cluster_xy );
     261        x , y , *coproc_info , cluster_xy );
    273262#endif
    274263        return 0;
     
    283272}  // end _sys_coproc_alloc()
    284273
    285 //////////////////////////////////////////////////
    286 int _sys_coproc_release( unsigned int cluster_xy )
    287 {
    288     // TODO checking coprocessor ownership...
    289 
    290     // check cluster coordinates
    291     unsigned int cx     = cluster_xy >> Y_WIDTH;
    292     unsigned int cy     = cluster_xy & ((1<<Y_WIDTH)-1);
     274////////////////////////////////////////////////////////
     275int _sys_coproc_release( unsigned int coproc_reg_index )
     276{
     277    // processor coordinates
    293278    unsigned int procid = _get_procid();
    294279    unsigned int x      = procid >> (Y_WIDTH + P_WIDTH);
    295280    unsigned int y      = (procid >> P_WIDTH) & ((1<<Y_WIDTH)-1);
    296     if ( (x != cx) || (y != cy) )
    297     {
    298          _printf("\n[GIET_ERROR] in _sys_coproc_channel_init(): "
    299                  "wrong cluster coordinates\n");
     281    unsigned int p      = procid & ((1<<P_WIDTH)-1);
     282   
     283    // get coprocessor coordinates
     284    unsigned int cluster_xy = _get_context_slot( CTX_COPROC_ID );
     285    if ( cluster_xy > 0xFF )
     286    {
     287         _printf("\n[GIET_ERROR] in _sys_coproc_release(): "
     288                 "no coprocessor allocated to task running on P[%d,%d,%d]\n",
     289                 x , y , p );
    300290         return -1;
    301291    }
    302292
    303     // compute coprocessor global index
    304     unsigned int coproc_id = x * Y_SIZE + y;
    305 
    306     // release coprocessor
    307     _simple_lock_release( &_coproc_lock[coproc_id] );
     293    unsigned int cx         = cluster_xy >> Y_WIDTH;
     294    unsigned int cy         = cluster_xy & ((1<<Y_WIDTH)-1);
     295    unsigned int cluster_id = cx * Y_SIZE + cy;
     296    unsigned int info       = _coproc_info[cluster_id];
     297    unsigned int nb_to      = info & 0xFF;
     298    unsigned int nb_from    = (info>>8) & 0xFF;
     299    unsigned int channel;
     300
     301    // stops coprocessor and communication channels
     302    _mwr_set_coproc_register( cluster_xy , coproc_reg_index , 0 );
     303    for ( channel = 0 ; channel < (nb_from + nb_to) ; channel++ )
     304    {
     305        _mwr_set_channel_register( cluster_xy , channel , MWR_CHANNEL_RUNNING , 0 );
     306    }
     307
     308    // deallocates coprocessor coordinates in task context
     309    _set_context_slot( CTX_COPROC_ID , 0xFFFFFFFF );
     310
     311    // release coprocessor lock
     312    _simple_lock_release( &_coproc_lock[cluster_id] );
    308313
    309314#if GIET_DEBUG_COPROC
    310315_printf("\n[GIET DEBUG COPROC] _sys_coproc_release() in cluster[%d,%d]\n",
    311         x, y );
     316        cx, cy );
    312317#endif
    313318
     
    315320}  // end _sys_coproc_release()
    316321
    317 /////////////////////////////////////////////////////////////////
    318 int _sys_coproc_channel_init( unsigned int            cluster_xy,
    319                               unsigned int            channel,
     322//////////////////////////////////////////////////////////////
     323int _sys_coproc_channel_init( unsigned int            channel,
    320324                              giet_coproc_channel_t*  desc )
    321325{
    322     // TODO checking coprocessor ownership...
    323 
    324     // check cluster coordinates
    325     unsigned int cx     = cluster_xy >> Y_WIDTH;
    326     unsigned int cy     = cluster_xy & ((1<<Y_WIDTH)-1);
     326    // processor coordinates
    327327    unsigned int procid = _get_procid();
    328328    unsigned int x      = procid >> (Y_WIDTH + P_WIDTH);
    329329    unsigned int y      = (procid >> P_WIDTH) & ((1<<Y_WIDTH)-1);
    330     if ( (x != cx) || (y != cy) )
     330    unsigned int p      = procid & ((1<<P_WIDTH)-1);
     331   
     332    // get coprocessor coordinates
     333    unsigned int cluster_xy = _get_context_slot( CTX_COPROC_ID );
     334    if ( cluster_xy > 0xFF )
    331335    {
    332336         _printf("\n[GIET_ERROR] in _sys_coproc_channel_init(): "
    333                  "wrong cluster coordinates\n");
     337                 "no coprocessor allocated to task running on P[%d,%d,%d]\n",
     338                 x , y , p );
    334339         return -1;
    335340    }
     
    341346         (mode != MODE_DMA_NO_IRQ) )
    342347    {
    343          _printf("\n[GIET_ERROR] in _sys_coproc_channel_init():"
     348         _printf("\n[GIET_ERROR] in _sys_coproc_channel_init(): "
    344349                 " illegal mode\n");
    345350         return -1;
     
    353358    unsigned int       buffer_lsb;
    354359    unsigned int       buffer_msb;
    355     unsigned long long mwmr_paddr;
     360    unsigned long long mwmr_paddr = 0;
    356361    unsigned int       mwmr_lsb;
    357362    unsigned int       mwmr_msb;
    358     unsigned long long lock_paddr;
     363    unsigned long long lock_paddr = 0;
    359364    unsigned int       lock_lsb;
    360365    unsigned int       lock_msb;
     
    368373
    369374    // call MWMR_DMA driver
    370     _mwr_set_channel_register( cluster_xy, channel, CHANNEL_MODE, mode );
    371     _mwr_set_channel_register( cluster_xy, channel, CHANNEL_SIZE, size );
    372     _mwr_set_channel_register( cluster_xy, channel, CHANNEL_BUFFER_LSB, buffer_lsb );
    373     _mwr_set_channel_register( cluster_xy, channel, CHANNEL_BUFFER_MSB, buffer_msb );
     375    _mwr_set_channel_register( cluster_xy, channel, MWR_CHANNEL_MODE, mode );
     376    _mwr_set_channel_register( cluster_xy, channel, MWR_CHANNEL_SIZE, size );
     377    _mwr_set_channel_register( cluster_xy, channel, MWR_CHANNEL_BUFFER_LSB, buffer_lsb );
     378    _mwr_set_channel_register( cluster_xy, channel, MWR_CHANNEL_BUFFER_MSB, buffer_msb );
    374379                       
    375380    if ( mode == MODE_MWMR )
     
    381386
    382387        // call MWMR_DMA driver
    383         _mwr_set_channel_register( cluster_xy, channel, CHANNEL_MWMR_LSB, mwmr_lsb );
    384         _mwr_set_channel_register( cluster_xy, channel, CHANNEL_MWMR_MSB, mwmr_msb );
     388        _mwr_set_channel_register( cluster_xy, channel, MWR_CHANNEL_MWMR_LSB, mwmr_lsb );
     389        _mwr_set_channel_register( cluster_xy, channel, MWR_CHANNEL_MWMR_MSB, mwmr_msb );
    385390
    386391        // compute lock physical address
     
    390395
    391396        // call MWMR_DMA driver
    392         _mwr_set_channel_register( cluster_xy, channel, CHANNEL_LOCK_LSB, lock_lsb );
    393         _mwr_set_channel_register( cluster_xy, channel, CHANNEL_LOCK_MSB, lock_msb );
     397        _mwr_set_channel_register( cluster_xy, channel, MWR_CHANNEL_LOCK_LSB, lock_lsb );
     398        _mwr_set_channel_register( cluster_xy, channel, MWR_CHANNEL_LOCK_MSB, lock_msb );
    394399    }
    395400
    396401#if GIET_DEBUG_COPROC
    397 _printf("\n[GIET DEBUG COPROC] _sys_coproc_channel_init() in cluster[%d,%d]\n"
     402_printf("\n[GIET DEBUG COPROC] _sys_coproc_channel_init() for coproc[%d,%d]\n"
    398403        " channel =  %d / mode = %d / buffer_size = %d\n"
    399404        " buffer_paddr = %l / mwmr_paddr = %l / lock_paddr = %l\n",
     
    405410} // end _sys_coproc_channel_init()
    406411
    407 ////////////////////////////////////////////////////////
    408 int _sys_coproc_channel_start( unsigned int  cluster_xy,
    409                                unsigned int  channel )
    410 {
    411     // TODO checking coprocessor ownership...
    412 
    413     // check cluster coordinates
    414     unsigned int cx     = cluster_xy >> Y_WIDTH;
    415     unsigned int cy     = cluster_xy & ((1<<Y_WIDTH)-1);
     412////////////////////////////////////////////////////
     413int _sys_coproc_run( unsigned int coproc_reg_index )
     414{
     415    // processor coordinates
    416416    unsigned int procid = _get_procid();
    417417    unsigned int x      = procid >> (Y_WIDTH + P_WIDTH);
    418418    unsigned int y      = (procid >> P_WIDTH) & ((1<<Y_WIDTH)-1);
    419     if ( (x != cx) || (y != cy) )
    420     {
    421          _printf("\n[GIET_ERROR] in _sys_coproc_channel_start():"
    422                  " wrong coordinates\n");
     419    unsigned int p      = procid & ((1<<P_WIDTH)-1);
     420   
     421    // get coprocessor coordinates
     422    unsigned int cluster_xy = _get_context_slot( CTX_COPROC_ID );
     423    if ( cluster_xy > 0xFF )
     424    {
     425         _printf("\n[GIET_ERROR] in _sys_coproc_run(): "
     426                 "no coprocessor allocated to task running on P[%d,%d,%d]\n",
     427                 x , y , p );
    423428         return -1;
    424429    }
    425  
    426     // reset synchronisation variable
    427     unsigned int coproc_id = (x * Y_SIZE) + y;
    428     _coproc_done[coproc_id] = 0;
    429 
    430     // call MWMR_DMA driver
    431     _mwr_set_channel_register( cluster_xy, channel, CHANNEL_RUNNING, 1 );
     430
     431    unsigned int cx         = cluster_xy >> Y_WIDTH;
     432    unsigned int cy         = cluster_xy & ((1<<Y_WIDTH)-1);
     433    unsigned int cluster_id = cx * Y_SIZE + cy;
     434    unsigned int info       = _coproc_info[cluster_id];
     435    unsigned int nb_to      = info & 0xFF;
     436    unsigned int nb_from    = (info>>8) & 0xFF;
     437    unsigned int mode       = 0xFFFFFFFF;
     438    unsigned int channel;
     439
     440    // register coprocessor running mode
     441    for ( channel = 0 ; channel < (nb_from + nb_to) ; channel++ )
     442    {
     443        unsigned int temp;
     444        temp = _mwr_get_channel_register( cluster_xy , channel , MWR_CHANNEL_MODE );
     445
     446        if ( mode == 0xFFFFFFFF )
     447        {
     448            mode = temp;
     449        }
     450        else if ( temp != mode )
     451        {
     452            _printf("\n[GIET_ERROR] P[%d,%d,%d] in _sys_coproc_run() for coprocessor[%d,%d]\n"
     453                    "  all channels don't have the same mode\n", x , y , p , cx , cy );
     454            return -1;
     455        }
     456    }
     457    _coproc_mode[cluster_id] = mode;
     458
     459    // start all communication channels
     460    for ( channel = 0 ; channel < (nb_from + nb_to) ; channel++ )
     461    {
     462        _mwr_set_channel_register( cluster_xy , channel , MWR_CHANNEL_RUNNING , 1 );
     463    }
     464
     465    //////////////////////////////////////////////////////////////////////////
     466    if ( (mode == MODE_MWMR) || (mode == MODE_DMA_NO_IRQ) )  // no descheduling
     467    {
     468        // start coprocessor
     469        _mwr_set_coproc_register( cluster_xy , coproc_reg_index , 1 );
    432470
    433471#if GIET_DEBUG_COPROC
    434 _printf("\n[GIET DEBUG COPROC] _sys_coproc_channel_start() in cluster[%d,%d]"
    435         " / channel = %d\n", x , y , channel );
    436 #endif
    437 
    438     return 0;
    439 } // end _sys_coproc_channel_start()
    440 
    441 ///////////////////////////////////////////////////////
    442 int _sys_coproc_channel_stop( unsigned int  cluster_xy,
    443                               unsigned int  channel )
    444 {
    445     // TODO checking coprocessor ownership...
    446 
    447     // check cluster coordinates
    448     unsigned int cx     = cluster_xy >> Y_WIDTH;
    449     unsigned int cy     = cluster_xy & ((1<<Y_WIDTH)-1);
     472if ( mode == MODE_MWMR )
     473_printf("\n[GIET DEBUG COPROC] _sys_coproc_run() P[%d,%d,%d] starts coprocessor[%d,%d]\n"
     474        "   MODE_MWMR at cycle %d\n", x , y , p , cx , cy , _get_proctime() );
     475else
     476_printf("\n[GIET DEBUG COPROC] _sys_coproc_run() P[%d,%d,%d] starts coprocessor[%d,%d]\n"
     477        "   MODE_DMA_NO_IRQ at cycle %d\n", x , y , p , cx , cy , _get_proctime() );
     478#endif
     479
     480        return 0;
     481    }
     482    ///////////////////////////////////////////////////////////////////////////
     483    else                                // mode == MODE_DMA_IRQ => descheduling
     484    {
     485        // set _coproc_gtid
     486        unsigned int ltid = _get_current_task_id();
     487        _coproc_gtid[cluster_id] = (procid<<16) + ltid;
     488
     489        // enters critical section
     490        unsigned int save_sr;
     491        _it_disable( &save_sr );
     492
     493        // reset runnable
     494        _set_task_slot( x, y, p, ltid, CTX_RUN_ID, 0 ); 
     495
     496        // start coprocessor
     497        _mwr_set_coproc_register( cluster_xy , coproc_reg_index , 1 );
     498
     499#if GIET_DEBUG_COPROC
     500_printf("\n[GIET DEBUG COPROC] _sys_coproc_run() P[%d,%d,%d] starts coprocessor[%d,%d]\n"
     501        "   MODE_DMA_IRQ at cycle %d\n", x , y , p , cx , cy , _get_proctime() );
     502#endif
     503
     504        // deschedule task
     505        _ctx_switch();
     506
     507#if GIET_DEBUG_COPROC
     508_printf("\n[GIET DEBUG COPROC] _sys_coproc_run() P[%d,%d,%d] resume\n"
     509        "  coprocessor[%d,%d] completion at cycle %d\n",
     510        x , y , p , cx , cy , _get_proctime() );
     511#endif
     512
     513        // restore SR
     514        _it_restore( &save_sr );
     515
     516        // return error computed by mwr_isr()
     517        return _coproc_error[cluster_id];
     518    }
     519} // end _sys_coproc_run()
     520
     521///////////////////////////
     522int _sys_coproc_completed()
     523{
     524    // processor coordinates
    450525    unsigned int procid = _get_procid();
    451526    unsigned int x      = procid >> (Y_WIDTH + P_WIDTH);
    452527    unsigned int y      = (procid >> P_WIDTH) & ((1<<Y_WIDTH)-1);
    453     if ( (x != cx) || (y != cy) )
    454     {
    455          _printf("\n[GIET_ERROR] in _sys_coproc_channel_stop(): wrong coordinates\n");
     528    unsigned int p      = procid & ((1<<P_WIDTH)-1);
     529   
     530    // get coprocessor coordinates
     531    unsigned int cluster_xy = _get_context_slot( CTX_COPROC_ID );
     532    if ( cluster_xy > 0xFF )
     533    {
     534         _printf("\n[GIET_ERROR] in _sys_coproc_completed(): "
     535                 "no coprocessor allocated to task running on P[%d,%d,%d]\n",
     536                 x , y , p );
    456537         return -1;
    457538    }
    458  
    459     // call MWMR_DMA driver
    460     _mwr_set_channel_register( cluster_xy, channel, CHANNEL_RUNNING, 0 );
     539
     540    unsigned int cx         = cluster_xy >> Y_WIDTH;
     541    unsigned int cy         = cluster_xy & ((1<<Y_WIDTH)-1);
     542    unsigned int cluster_id = cx * Y_SIZE + cy;
     543    unsigned int mode       = _coproc_mode[cluster_id];
     544
     545    // analyse possible errors
     546    if ( mode == MODE_DMA_NO_IRQ )
     547    {
     548        unsigned int info       = _coproc_info[cluster_id];
     549        unsigned int nb_to      = info & 0xFF;
     550        unsigned int nb_from    = (info>>8) & 0xFF;
     551        unsigned int error      = 0;
     552        unsigned int channel;
     553        unsigned int status;
     554
     555        // get status for all channels, and signal all reported errors
     556        for ( channel = 0 ; channel < (nb_to +nb_from) ; channel++ )
     557        {
     558            do
     559            {
     560                status = _mwr_get_channel_register( cluster_xy , channel , MWR_CHANNEL_STATUS );
     561                if ( status == MWR_CHANNEL_ERROR_DATA )
     562                {
     563                    _printf("\n[GIET_ERROR] in _sys_coproc_completed()"
     564                            " / channel %d / DATA_ERROR\n", channel );
     565                    error = 1;
     566                    break;
     567                }
     568                else if ( status == MWR_CHANNEL_ERROR_LOCK )
     569                {
     570                    _printf("\n[GIET_ERROR] in _sys_coproc_completed()"
     571                            " / channel %d / LOCK_ERROR\n", channel );
     572                    error = 1;
     573                    break;
     574                }
     575                else if ( status == MWR_CHANNEL_ERROR_DESC )
     576                {
     577                    _printf("\n[GIET_ERROR] in _sys_coproc_completed()"
     578                            " / channel %d / DESC_ERROR\n", channel );
     579                    error = 1;
     580                    break;
     581                }
     582            } while ( status == MWR_CHANNEL_BUSY );
     583
     584            // reset channel
     585            _mwr_set_channel_register( cluster_xy , channel , MWR_CHANNEL_RUNNING , 0 );
     586
     587        }  // end for channels
    461588
    462589#if GIET_DEBUG_COPROC
    463 _printf("\n[GIET DEBUG COPROC] _sys_coproc_channel_stop() in cluster[%d,%d]"
    464         " / channel = %d\n", x , y , channel );
    465 #endif
    466 
    467     return 0;
    468 } // end _sys_coproc_channel_stop()
    469 
    470 /////////////////////////////////////////////////////
    471 int _sys_coproc_completed( unsigned int  cluster_xy )
    472 {
    473     // TODO checking coprocessor ownership...
    474 
    475     // check cluster coordinates
    476     unsigned int cx     = cluster_xy >> Y_WIDTH;
    477     unsigned int cy     = cluster_xy & ((1<<Y_WIDTH)-1);
    478     unsigned int procid = _get_procid();
    479     unsigned int x      = procid >> (Y_WIDTH + P_WIDTH);
    480     unsigned int y      = (procid >> P_WIDTH) & ((1<<Y_WIDTH)-1);
    481     if ( (x != cx) || (y != cy) )
    482     {
    483          _printf("\n[GIET_ERROR] in _sys_coproc_completed(): "
    484                  "wrong cluster coordinates\n");
    485          return -1;
    486     }
    487  
    488     // polling the synchronisation variable
    489     unsigned int coproc_id = (x * Y_SIZE) + y;
    490     while ( ioread32( &_coproc_done[coproc_id]) == 0 ) asm volatile("nop");
    491 
    492     _coproc_done[coproc_id] = 0;
    493 
    494 #if GIET_DEBUG_COPROC
    495 _printf("\n[GIET DEBUG COPROC] _sys_coproc_completed() in cluster[%d,%d]\n",
    496         x, y );
    497 #endif
    498 
    499     return 0;
     590_printf("\n[GIET DEBUG COPROC] _sys_coproc_completed() for coprocessor[%d,%d] error = %d\n",
     591        cx , cy , error );
     592#endif
     593
     594        return error;
     595    }
     596    else  // mode == MODE_MWMR or MODE_DMA_IRQ
     597    {
     598        _printf("\n[GIET ERROR] sys_coproc_completed() should not be called for "
     599                "coprocessor[%d,%d] running in MODE_MWMR or MODE_DMA_IRQ\n", cx , cy );
     600        return 1;
     601    }
    500602} // end _sys_coproc_completed()
    501603
  • soft/giet_vm/giet_kernel/sys_handler.h

    r528 r556  
    8383
    8484int _sys_coproc_alloc( unsigned int   coproc_type,
    85                        unsigned int*  coproc_info,
    86                        unsigned int*  cluster_xy );
    87 
    88 int _sys_coproc_release( unsigned int cluster_xy );
    89 
    90 int _sys_coproc_channel_init( unsigned int            cluster_xy,
    91                               unsigned int            channel,
     85                       unsigned int*  coproc_info );
     86
     87int _sys_coproc_release( unsigned int coproc_reg_index );
     88
     89int _sys_coproc_channel_init( unsigned int            channel,
    9290                              giet_coproc_channel_t*  desc );
    9391
    94 int _sys_coproc_channel_start( unsigned int  cluster_xy,
    95                                unsigned int  channel );
    96 
    97 int _sys_coproc_channel_stop( unsigned int  cluster_xy,
    98                               unsigned int  channel );
    99 
    100 int _sys_coproc_completed( unsigned int cluster_xy );
     92int _sys_coproc_run( unsigned int coproc_reg_index );
     93
     94int _sys_coproc_completed();
    10195
    10296///////////////////////////////////////////////////////////////////////////////
Note: See TracChangeset for help on using the changeset viewer.