Changeset 228 for soft/giet_vm/sys


Ignore:
Timestamp:
Feb 12, 2013, 6:33:31 PM (11 years ago)
Author:
meunier
Message:

Added support for memspaces and const.
Added an interrupt masking to the "giet_context_switch" syscall
Corrected two bugs in boot/boot_init.c (one minor and one regarding barriers initialization)
Reformatted the code in all files.

Location:
soft/giet_vm/sys
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/sys/common.c

    r221 r228  
    1717
    1818///////////////////////////////////////////////////////////////////////////////////
    19 //      Global variables
     19//    Global variables
    2020///////////////////////////////////////////////////////////////////////////////////
    2121
     
    2323
    2424// SR save (used by _it_mask() / it_restore()
    25 unsigned int    _status_register_save;
    26 
    27 ///////////////////////////////////////////////////////////////////////////////////
    28 //        _get_sched()
     25unsigned int _status_register_save;
     26
     27///////////////////////////////////////////////////////////////////////////////////
     28//       _get_sched()
    2929// Access CP0 and returns scheduler physical address.
    3030///////////////////////////////////////////////////////////////////////////////////
    31 inline unsigned int _get_sched()
    32 {
    33     unsigned int ret;
    34     asm volatile (      "mfc0   %0,             $22"
    35                                         : "=r"(ret) );
    36     return ret;
    37 }
    38 ///////////////////////////////////////////////////////////////////////////////////
    39 //        _get_ptpr()
     31inline unsigned int _get_sched() {
     32    unsigned int ret;
     33    asm volatile(
     34            "mfc0    %0,        $22"
     35            : "=r"(ret));
     36    return ret;
     37}
     38
     39
     40///////////////////////////////////////////////////////////////////////////////////
     41//       _get_ptpr()
    4042// Access CP2 and returns PTPR register.
    4143///////////////////////////////////////////////////////////////////////////////////
    42 inline unsigned int _get_ptpr()
    43 {
    44     unsigned int ret;
    45     asm volatile (      "mfc2   %0,             $0"
    46                                         : "=r"(ret) );
    47     return ret;
    48 }
    49 ///////////////////////////////////////////////////////////////////////////////////
    50 //        _get_epc()
     44inline unsigned int _get_ptpr() {
     45    unsigned int ret;
     46    asm volatile(
     47            "mfc2    %0,        $0"
     48            : "=r"(ret));
     49    return ret;
     50}
     51
     52
     53///////////////////////////////////////////////////////////////////////////////////
     54//       _get_epc()
    5155// Access CP0 and returns EPC register.
    5256///////////////////////////////////////////////////////////////////////////////////
    53 inline unsigned int _get_epc()
    54 {
    55     unsigned int ret;
    56     asm volatile (      "mfc0   %0,             $14"
    57                                         : "=r"(ret) );
    58     return ret;
    59 }
    60 ///////////////////////////////////////////////////////////////////////////////////
    61 //        _get_bar()
     57inline unsigned int _get_epc() {
     58    unsigned int ret;
     59    asm volatile("mfc0    %0,        $14"
     60            : "=r"(ret));
     61    return ret;
     62}
     63
     64
     65///////////////////////////////////////////////////////////////////////////////////
     66//       _get_bar()
    6267// Access CP0 and returns BAR register.
    6368///////////////////////////////////////////////////////////////////////////////////
    64 inline unsigned int _get_bvar()
    65 {
    66     unsigned int ret;
    67     asm volatile (      "mfc0   %0,             $8"
    68                                         : "=r"(ret) );
    69     return ret;
    70 }
    71 ///////////////////////////////////////////////////////////////////////////////////
    72 //        _get_cr()
     69inline unsigned int _get_bvar() {
     70    unsigned int ret;
     71    asm volatile(
     72            "mfc0    %0,        $8"
     73            : "=r"(ret));
     74    return ret;
     75}
     76
     77
     78///////////////////////////////////////////////////////////////////////////////////
     79//       _get_cr()
    7380// Access CP0 and returns CR register.
    7481///////////////////////////////////////////////////////////////////////////////////
    75 inline unsigned int _get_cause()
    76 {
    77     unsigned int ret;
    78     asm volatile (      "mfc0   %0,             $13"
    79                                         : "=r"(ret) );
    80     return ret;
    81 }
    82 ///////////////////////////////////////////////////////////////////////////////////
    83 //        _get_sr()
     82inline unsigned int _get_cause() {
     83    unsigned int ret;
     84    asm volatile("mfc0    %0,        $13"
     85            : "=r"(ret));
     86    return ret;
     87}
     88
     89
     90///////////////////////////////////////////////////////////////////////////////////
     91//       _get_sr()
    8492// Access CP0 and returns SR register.
    8593///////////////////////////////////////////////////////////////////////////////////
    86 inline unsigned int _get_sr()
    87 {
    88     unsigned int ret;
    89     asm volatile (      "mfc0   %0,             $12"
    90                                         : "=r"(ret) );
    91     return ret;
    92 }
     94inline unsigned int _get_sr() {
     95    unsigned int ret;
     96    asm volatile(
     97            "mfc0    %0,        $12"
     98            : "=r"(ret));
     99    return ret;
     100}
     101
    93102///////////////////////////////////////////////////////////////////////////////////
    94103//    _it_mask()
    95104// Access CP0 and mask IRQs
    96105///////////////////////////////////////////////////////////////////////////////////
    97 inline void _it_mask()
    98 {
    99     unsigned int        sr_value;
    100     asm volatile(       "li             $3,             0xFFFFFFFE      \n"
    101                                         "mfc0   %0,             $12                     \n"
    102                                         "and    $3,             $3, %0          \n"
    103                                         "mtc0   $3,             $12                     \n"
    104                                         : "=r"(sr_value) : : "$3" );
     106inline void _it_mask() {
     107    unsigned int sr_value;
     108    asm volatile(
     109            "li      $3,        0xFFFFFFFE    \n"
     110            "mfc0    %0,        $12           \n"
     111            "and     $3,        $3, %0        \n"
     112            "mtc0    $3,        $12           \n"
     113            : "=r"(sr_value)
     114            :
     115            : "$3");
    105116    _status_register_save = sr_value;
    106117}
    107 ///////////////////////////////////////////////////////////////////////////////////
    108 //    _it_enable()
     118
     119
     120///////////////////////////////////////////////////////////////////////////////////
     121//    _it_restore()
    109122// Access CP0 and enable IRQs
    110123///////////////////////////////////////////////////////////////////////////////////
    111 inline void _it_restore()
    112 {
    113     unsigned int        sr_value = _status_register_save;
    114     asm volatile(       "mtc0  %0,              $12                     \n"
    115                                         : : "r"(sr_value) );
    116 }
     124inline void _it_restore() {
     125    unsigned int sr_value = _status_register_save;
     126    asm volatile(
     127            "mtc0  %0,        $12            \n"
     128            :
     129            : "r"(sr_value));
     130}
     131
     132
    117133////////////////////////////////////////////////////////////////////////////
    118134//    _get_lock()
     
    121137// (delay average value = 100 cycles)
    122138////////////////////////////////////////////////////////////////////////////
    123 inline void _get_lock( unsigned int* plock )
    124 {
    125     register unsigned int  delay = ( _proctime() ^ _procid()<<4 ) & 0xFF;
     139inline void _get_lock(unsigned int * plock) {
     140    register unsigned int delay = ( _proctime() ^ _procid() << 4) & 0xFF;
    126141
    127142    asm volatile (
     
    144159}
    145160
     161
    146162////////////////////////////////////////////////////////////////////////////
    147163// _release_lock()
    148164////////////////////////////////////////////////////////////////////////////
    149 inline void _release_lock( unsigned int* plock )
    150 {
     165inline void _release_lock(unsigned int * plock) {
    151166    asm volatile (
    152           "sync\n" /* necessary because of the consistency model in tsar */
    153     );
     167            "sync\n" /* necessary because of the consistency model in tsar */
     168            );
    154169    *plock = 0;
    155170}
     171
    156172
    157173////////////////////////////////////////////////////////////////////////////
     
    159175// display a string on TTY0 / used for system code debug and log
    160176////////////////////////////////////////////////////////////////////////////
    161 void _puts(char* buffer)
    162 {
    163     unsigned int* tty_address = (unsigned int*) &seg_tty_base;
     177void _puts(char * buffer) {
     178    unsigned int * tty_address = (unsigned int *) &seg_tty_base;
    164179    unsigned int n;
    165180
    166     for ( n=0; n<100; n++)
    167     {
    168         if (buffer[n] == 0) break;
    169         tty_address[TTY_WRITE] = (unsigned int)buffer[n];
     181    for (n = 0; n < 100; n++) {
     182        if (buffer[n] == 0) {
     183            break;
     184        }
     185        tty_address[TTY_WRITE] = (unsigned int) buffer[n];
    170186    }
    171187}
     188
     189
    172190////////////////////////////////////////////////////////////////////////////
    173191//    _putx()
    174192// display an int (hexa) on TTY0 / used for system code debug and log
    175193////////////////////////////////////////////////////////////////////////////
    176 void _putx(unsigned int val)
    177 {
    178     static const char   HexaTab[] = "0123456789ABCDEF";
    179     char                buf[11];
    180     unsigned int        c;
    181 
    182     buf[0]  = '0';
    183     buf[1]  = 'x';
     194void _putx(unsigned int val) {
     195    static const char HexaTab[] = "0123456789ABCDEF";
     196    char buf[11];
     197    unsigned int c;
     198
     199    buf[0] = '0';
     200    buf[1] = 'x';
    184201    buf[10] = 0;
    185202
    186     for ( c = 0 ; c < 8 ; c++ )
    187     {
    188         buf[9-c] = HexaTab[val&0xF];
     203    for (c = 0; c < 8; c++) {
     204        buf[9 - c] = HexaTab[val & 0xF];
    189205        val = val >> 4;
    190206    }
    191207    _puts(buf);
    192208}
     209
     210
    193211////////////////////////////////////////////////////////////////////////////
    194212//    _putd()
    195213// display an int (decimal) on TTY0 / used for system code debug and log
    196214////////////////////////////////////////////////////////////////////////////
    197 void _putd(unsigned int val)
    198 {
    199     static const char   DecTab[] = "0123456789";
    200     char                                buf[11];
    201     unsigned int                i;
    202     unsigned int                first;
     215void _putd(unsigned int val) {
     216    static const char DecTab[] = "0123456789";
     217    char buf[11];
     218    unsigned int i;
     219    unsigned int first;
    203220
    204221    buf[10] = 0;
    205222
    206     for (i = 0; i < 10; i++)
    207     {
    208         if ((val != 0) || (i == 0))
    209         {
    210             buf[9-i] = DecTab[val % 10];
    211             first    = 9-i;
     223    for (i = 0; i < 10; i++) {
     224        if ((val != 0) || (i == 0)) {
     225            buf[9 - i] = DecTab[val % 10];
     226            first = 9 - i;
    212227        }
    213         else
    214         {
     228        else {
    215229            break;
    216230        }
    217231        val /= 10;
    218232    }
    219     _puts( &buf[first] );
    220 }
     233    _puts(&buf[first]);
     234}
     235
     236
    221237////////////////////////////////////////////////////////////////////////////
    222238//    _strncmp()
    223239// compare two strings s1 & s2 (no more than n characters)
    224240////////////////////////////////////////////////////////////////////////////
    225 unsigned int _strncmp(const char* s1,
    226                       const char* s2,
    227                       unsigned int n)
    228 {
     241unsigned int _strncmp(const char * s1, const char * s2, unsigned int n) {
    229242    unsigned int i;
    230     for ( i=0 ; i<n ; i++)
    231     {
    232         if ( s1[i] != s2[i] ) return 1;
    233         if ( s1[i] == 0 )     break;
     243    for (i = 0; i < n; i++) {
     244        if (s1[i] != s2[i]) {
     245            return 1;
     246        }
     247        if (s1[i] == 0) {
     248            break;
     249        }
    234250    }
    235251    return 0;
    236252}
    237 ////////////////////////////////////////////////////////////////////////////
    238 //         _dcache_buf_invalidate()
     253
     254
     255////////////////////////////////////////////////////////////////////////////
     256//        _dcache_buf_invalidate()
    239257// Invalidate all data cache lines corresponding to a memory
    240258// buffer (identified by an address and a size).
    241259////////////////////////////////////////////////////////////////////////////
    242 void _dcache_buf_invalidate(const void *buffer,
    243                             unsigned int size)
    244 {
     260void _dcache_buf_invalidate(const void * buffer, unsigned int size) {
    245261    unsigned int i;
    246262    unsigned int tmp;
     
    248264
    249265    // compute data cache line size based on config register (bits 12:10)
    250     asm volatile("mfc0 %0, $16, 1" : "=r"(tmp));
    251     tmp = ((tmp>>10) & 0x7);
     266    asm volatile("mfc0 %0, $16, 1" : "=r" (tmp));
     267    tmp = ((tmp >> 10) & 0x7);
    252268    line_size = 2 << tmp;
    253269
    254270    // iterate on cache lines
    255     for (i = 0; i < size; i += line_size)
    256     {
     271    for (i = 0; i < size; i += line_size) {
    257272        asm volatile(
    258273                " cache %0, %1"
    259                 ::"i" (0x11), "R" (*((unsigned char*)buffer+i))
     274                :
     275                :"i" (0x11), "R" (*((unsigned char *) buffer + i))
    260276                );
    261277    }
    262278}
     279
     280
    263281////////////////////////////////////////////////////////////////////////////
    264282//    _physical_read_access()
     
    266284// after a temporary DTLB desactivation.
    267285////////////////////////////////////////////////////////////////////////////
    268 unsigned int _physical_read_access(unsigned int* paddr)
    269 {
     286unsigned int _physical_read_access(unsigned int * paddr) {
    270287    unsigned int value;
    271288
    272     asm volatile(   "li     $3,     0xFFFFFFFE          \n"
    273                     "mfc0   $2,     $12                         \n"             /* $2 <= SR        */
    274                     "and    $3,     $3,         $2              \n"
    275                     "mtc0   $3,     $12                         \n"             /* interrupt masked */
    276                     "li         $3,             0xB                             \n"
    277                     "mtc2       $3,             $1                              \n"             /* DTLB off                     */     
    278 
    279                     "lw         %0,             0(%1)                   \n"             /* entry <= *pslot      */
    280 
    281                     "li         $3,             0xF                             \n"
    282                     "mtc2       $3,             $1                              \n"             /* DTLB on                      */     
    283                     "mtc0       $2,             $12                             \n"             /* restore SR           */
    284                     : "=r"(value)
    285                     : "r"(paddr)
    286                     : "$2", "$3" );
     289    asm volatile(
     290            "li     $3,     0xFFFFFFFE         \n"
     291            "mfc0   $2,     $12                \n"        /* $2 <= SR        */
     292            "and    $3,     $3,        $2      \n"
     293            "mtc0   $3,     $12                \n"        /* interrupt masked */
     294            "li     $3,     0xB                \n"
     295            "mtc2   $3,     $1                 \n"        /* DTLB off            */   
     296
     297            "lw     %0,     0(%1)              \n"        /* entry <= *pslot    */
     298
     299            "li     $3,     0xF                \n"
     300            "mtc2   $3,     $1                 \n"        /* DTLB on             */   
     301            "mtc0   $2,     $12                \n"        /* restore SR        */
     302            : "=r" (value)
     303            : "r" (paddr)
     304            : "$2", "$3");
    287305    return value;
    288306}
     307
     308
    289309////////////////////////////////////////////////////////////////////////////
    290310//    _physical_write_access()
     
    292312// after a temporary DTLB desactivation.
    293313////////////////////////////////////////////////////////////////////////////
    294 void _physical_write_access(unsigned int* paddr, unsigned int value)
    295 {
    296     asm volatile(   "li     $3,     0xFFFFFFFE          \n"
    297                     "mfc0   $2,     $12                         \n"             /* $26 <= SR        */
    298                     "and    $3,     $3,         $2              \n"
    299                     "mtc0   $3,     $12                         \n"             /* interrupt masked */
    300                     "li         $3,             0xB                             \n"
    301                     "mtc2       $3,             $1                              \n"             /* DTLB off                     */
    302        
    303                     "sw         %0,             0(%1)                   \n"             /* entry <= *pslot      */
    304 
    305                     "li         $3,             0xF                             \n"
    306                     "mtc2       $3,             $1                              \n"             /* DTLB on                      */     
    307                     "mtc0       $2,             $12                             \n"             /* restore SR           */
    308                     :
    309                     : "r"(value), "r"(paddr)
    310                     : "$2", "$3" );
    311 }
     314void _physical_write_access(unsigned int * paddr, unsigned int value) {
     315    asm volatile(
     316            "li     $3,     0xFFFFFFFE         \n"
     317            "mfc0   $2,     $12                \n"        /* $26 <= SR        */
     318            "and    $3,     $3,        $2      \n"
     319            "mtc0   $3,     $12                \n"        /* interrupt masked */
     320            "li     $3,     0xB                \n"
     321            "mtc2   $3,     $1                 \n"        /* DTLB off            */
     322
     323            "sw     %0,     0(%1)              \n"        /* entry <= *pslot    */
     324
     325            "li     $3,     0xF                \n"
     326            "mtc2   $3,     $1                 \n"        /* DTLB on             */   
     327            "mtc0   $2,     $12                \n"        /* restore SR        */
     328            :
     329            : "r" (value), "r" (paddr)
     330            : "$2", "$3");
     331}
     332
     333
    312334////////////////////////////////////////////////////////////////////////////
    313335//    _get_tasks_number()
    314336// This function returns the number of tasks allocated to processor.
    315337////////////////////////////////////////////////////////////////////////////
    316 unsigned int _get_tasks_number()
    317 {
    318     static_scheduler_t*         psched = (static_scheduler_t*)_get_sched();
    319     return _physical_read_access( &(psched->tasks) );
    320 }
     338unsigned int _get_tasks_number() {
     339    static_scheduler_t * psched = (static_scheduler_t *) _get_sched();
     340    return _physical_read_access(&(psched->tasks));
     341}
     342
     343
    321344////////////////////////////////////////////////////////////////////////////
    322345//    _get_current_task_id()
    323346// This function returns the index of the currently running task.
    324347////////////////////////////////////////////////////////////////////////////
    325 unsigned int _get_current_task_id()
    326 {
    327     static_scheduler_t*         psched = (static_scheduler_t*)_get_sched();
    328     return _physical_read_access( &(psched->current) );
    329 }
     348unsigned int _get_current_task_id() {
     349    static_scheduler_t * psched = (static_scheduler_t *) _get_sched();
     350    return _physical_read_access(&(psched->current));
     351}
     352
     353
    330354////////////////////////////////////////////////////////////////////////////
    331355//    _set_current_task_id()
    332356// This function returns the index of the currently running task.
    333357////////////////////////////////////////////////////////////////////////////
    334 void _set_current_task_id( unsigned int value )
    335 {
    336     static_scheduler_t*         psched = (static_scheduler_t*)_get_sched();
    337     _physical_write_access( &(psched->current), value );
    338 }
     358void _set_current_task_id(unsigned int value) {
     359    static_scheduler_t * psched = (static_scheduler_t *) _get_sched();
     360    _physical_write_access(&(psched->current), value);
     361}
     362
     363
    339364///////////////////////////////////////////////////////////////////////////////
    340365//    _get_context_slot()
    341366// This function returns a slot content for the task defined by task_id.
    342367///////////////////////////////////////////////////////////////////////////////
    343 unsigned int _get_context_slot( unsigned int task_id,
    344                                 unsigned int slot_id )
    345 {
    346     static_scheduler_t*         psched = (static_scheduler_t*)_get_sched();
    347     return _physical_read_access( &(psched->context[task_id][slot_id]) );
    348 }
     368unsigned int _get_context_slot(unsigned int task_id, unsigned int slot_id) {
     369    static_scheduler_t * psched = (static_scheduler_t *) _get_sched();
     370    return _physical_read_access(&(psched->context[task_id][slot_id]));
     371}
     372
     373
    349374///////////////////////////////////////////////////////////////////////////////
    350375//    _set_context_slot()
     
    352377///////////////////////////////////////////////////////////////////////////////
    353378void _set_context_slot( unsigned int task_id,
    354                         unsigned int slot_id,
    355                         unsigned int value )
    356 {
    357     static_scheduler_t*         psched = (static_scheduler_t*)_get_sched();
    358     _physical_write_access( &(psched->context[task_id][slot_id]), value );
    359 }
     379        unsigned int slot_id,
     380        unsigned int value) {
     381    static_scheduler_t * psched = (static_scheduler_t *) _get_sched();
     382    _physical_write_access(&(psched->context[task_id][slot_id]), value);
     383}
     384
     385
    360386////////////////////////////////////////////////////////////////////////////////
    361387//    _get_interrupt_vector_entry()
    362388// This function returns the interrupt_vector entry defined by argument index.
    363389////////////////////////////////////////////////////////////////////////////////
    364 unsigned int _get_interrupt_vector_entry( unsigned int index )
     390unsigned int _get_interrupt_vector_entry(unsigned int index) {
     391    static_scheduler_t * psched = (static_scheduler_t *) _get_sched();
     392    return _physical_read_access( &(psched->interrupt_vector[index]));
     393}
     394
     395
     396/////////////////////////////////////////////////////////////////////////////
     397//      access functions to mapping_info data structure
     398/////////////////////////////////////////////////////////////////////////////
     399mapping_cluster_t * _get_cluster_base(mapping_header_t * header) {
     400    return (mapping_cluster_t *) ((char *) header +
     401            MAPPING_HEADER_SIZE);
     402}
     403
     404
     405/////////////////////////////////////////////////////////////////////////////
     406mapping_pseg_t * _get_pseg_base(mapping_header_t * header) {
     407    return (mapping_pseg_t *) ((char *) header +
     408            MAPPING_HEADER_SIZE +
     409            MAPPING_CLUSTER_SIZE * header->clusters);
     410}
     411/////////////////////////////////////////////////////////////////////////////
     412mapping_vspace_t * _get_vspace_base(mapping_header_t * header) {
     413    return (mapping_vspace_t *)  ((char *) header +
     414            MAPPING_HEADER_SIZE +
     415            MAPPING_CLUSTER_SIZE * header->clusters +
     416            MAPPING_PSEG_SIZE * header->psegs);
     417}
     418
     419
     420/////////////////////////////////////////////////////////////////////////////
     421mapping_vseg_t * _get_vseg_base(mapping_header_t * header)
    365422{
    366     static_scheduler_t*         psched = (static_scheduler_t*)_get_sched();
    367     return _physical_read_access( &(psched->interrupt_vector[index]) );
    368 }
    369 
    370 /////////////////////////////////////////////////////////////////////////////
    371 //      access functions to mapping_info data structure
    372 /////////////////////////////////////////////////////////////////////////////
    373 mapping_cluster_t* _get_cluster_base( mapping_header_t* header )
    374 {
    375     return   (mapping_cluster_t*) ((char*)header +
    376                                   MAPPING_HEADER_SIZE);
    377 }
    378 /////////////////////////////////////////////////////////////////////////////
    379 mapping_pseg_t* _get_pseg_base( mapping_header_t* header )
    380 {
    381     return   (mapping_pseg_t*)    ((char*)header +
    382                                   MAPPING_HEADER_SIZE +
    383                                   MAPPING_CLUSTER_SIZE*header->clusters);
    384 }
    385 /////////////////////////////////////////////////////////////////////////////
    386 mapping_vspace_t* _get_vspace_base( mapping_header_t* header )
    387 {
    388     return   (mapping_vspace_t*)  ((char*)header +
    389                                   MAPPING_HEADER_SIZE +
    390                                   MAPPING_CLUSTER_SIZE*header->clusters +
    391                                   MAPPING_PSEG_SIZE*header->psegs);
    392 }
    393 /////////////////////////////////////////////////////////////////////////////
    394 mapping_vseg_t* _get_vseg_base( mapping_header_t* header )
    395 {
    396     return   (mapping_vseg_t*)    ((char*)header +
    397                                   MAPPING_HEADER_SIZE +
    398                                   MAPPING_CLUSTER_SIZE*header->clusters +
    399                                   MAPPING_PSEG_SIZE*header->psegs +
    400                                   MAPPING_VSPACE_SIZE*header->vspaces);
    401 }
    402 /////////////////////////////////////////////////////////////////////////////
    403 mapping_vobj_t* _get_vobj_base( mapping_header_t* header )
    404 {
    405     return   (mapping_vobj_t*)   ((char*)header +
    406                                   MAPPING_HEADER_SIZE +
    407                                   MAPPING_CLUSTER_SIZE*header->clusters +
    408                                   MAPPING_PSEG_SIZE*header->psegs +
    409                                   MAPPING_VSPACE_SIZE*header->vspaces +
    410                                   MAPPING_VSEG_SIZE*header->vsegs );
    411 }
    412 /////////////////////////////////////////////////////////////////////////////
    413 mapping_task_t* _get_task_base( mapping_header_t* header )
    414 {
    415     return   (mapping_task_t*)    ((char*)header +
    416                                   MAPPING_HEADER_SIZE +
    417                                   MAPPING_CLUSTER_SIZE*header->clusters +
    418                                   MAPPING_PSEG_SIZE*header->psegs +
    419                                   MAPPING_VSPACE_SIZE*header->vspaces +
    420                                   MAPPING_VOBJ_SIZE*header->vobjs +
    421                                   MAPPING_VSEG_SIZE*header->vsegs);
    422 }
    423 
     423    return (mapping_vseg_t *) ((char *) header +
     424            MAPPING_HEADER_SIZE +
     425            MAPPING_CLUSTER_SIZE * header->clusters +
     426            MAPPING_PSEG_SIZE * header->psegs +
     427            MAPPING_VSPACE_SIZE * header->vspaces);
     428}
     429
     430
     431/////////////////////////////////////////////////////////////////////////////
     432mapping_vobj_t * _get_vobj_base(mapping_header_t * header) {
     433    return (mapping_vobj_t *) ((char *) header +
     434            MAPPING_HEADER_SIZE +
     435            MAPPING_CLUSTER_SIZE * header->clusters +
     436            MAPPING_PSEG_SIZE * header->psegs +
     437            MAPPING_VSPACE_SIZE * header->vspaces +
     438            MAPPING_VSEG_SIZE * header->vsegs );
     439}
     440
     441
     442/////////////////////////////////////////////////////////////////////////////
     443mapping_task_t * _get_task_base(mapping_header_t * header) {
     444    return (mapping_task_t *) ((char *) header +
     445            MAPPING_HEADER_SIZE +
     446            MAPPING_CLUSTER_SIZE * header->clusters +
     447            MAPPING_PSEG_SIZE * header->psegs +
     448            MAPPING_VSPACE_SIZE * header->vspaces +
     449            MAPPING_VOBJ_SIZE * header->vobjs +
     450            MAPPING_VSEG_SIZE * header->vsegs);
     451}
     452
     453
     454// Local Variables:
     455// tab-width: 4
     456// c-basic-offset: 4
     457// c-file-offsets:((innamespace . 0)(inline-open . 0))
     458// indent-tabs-mode: nil
     459// End:
     460// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
     461
  • soft/giet_vm/sys/common.h

    r218 r228  
    3030
    3131///////////////////////////////////////////////////////////////////////////////////
    32 //      Prototypes of common functions
     32//     Prototypes of common functions
    3333///////////////////////////////////////////////////////////////////////////////////
    3434
    35 void                            _puts(char *string);
    36 void                            _putx(unsigned int val);
    37 void                            _putd(unsigned int val);
     35void _puts(char *string);
     36void _putx(unsigned int val);
     37void _putd(unsigned int val);
    3838
    39 unsigned int            _strncmp( const char* s1,
    40                               const char* s2,
    41                               unsigned int n );
     39unsigned int _strncmp(const char * s1, const char * s2, unsigned int n);
     40void _dcache_buf_invalidate(const void * buffer, unsigned int size);
    4241
    43 void                            _dcache_buf_invalidate( const void *buffer,
    44                                             unsigned int size );
     42void _dtlb_off(void);
     43void _dtlb_on(void);
    4544
    46 void                            _dtlb_off(void);
    47 void                            _dtlb_on(void);
     45void _it_mask(void);
     46void _it_restore(void);
    4847
    49 void                            _it_mask(void);
    50 void                            _it_enable(void);
     48unsigned int _get_epc(void);
     49unsigned int _get_ptpr(void);
     50unsigned int _get_bvar(void);
     51unsigned int _get_cr(void);
     52unsigned int _get_sched(void);
    5153
    52 unsigned int            _get_epc(void);
    53 unsigned int            _get_ptpr(void);
    54 unsigned int            _get_bvar(void);
    55 unsigned int            _get_cr(void);
    56 unsigned int            _get_sched(void);
     54unsigned int _get_context_slot(unsigned int task_id, unsigned int slot_id);
     55void _set_context_slot(unsigned int task_id, unsigned int slot_id, unsigned int value);
    5756
    58 unsigned int            _get_context_slot( unsigned int task_id,
    59                                        unsigned int slot_id );
     57unsigned int _get_interrupt_vector_entry(unsigned int index);
    6058
    61 void                            _set_context_slot( unsigned int task_id,
    62                                        unsigned int slot_id,
    63                                        unsigned int value );
     59unsigned int _get_current_task_id(void);
     60void _set_current_task_id(unsigned int value);
    6461
    65 unsigned int            _get_interrupt_vector_entry(unsigned int index);
     62unsigned int _get_tasks_number(void);
    6663
    67 unsigned int            _get_current_task_id( void );
    68 void                            _set_current_task_id( unsigned int value );
     64void _get_lock(unsigned int * lock);
     65void _release_lock(unsigned int * lock);
    6966
    70 unsigned int            _get_tasks_number(void);
    71 
    72 
    73 void                            _get_lock(unsigned int* lock);
    74 void                            _release_lock(unsigned int* lock);
    75 
    76 mapping_cluster_t*  _get_cluster_base( mapping_header_t* header );
    77 mapping_pseg_t*     _get_pseg_base( mapping_header_t* header );
    78 mapping_vspace_t*   _get_vspace_base( mapping_header_t* header );
    79 mapping_vseg_t*     _get_vseg_base( mapping_header_t* header );
    80 mapping_vobj_t*     _get_vobj_base( mapping_header_t* header );
    81 mapping_task_t*     _get_task_base( mapping_header_t* header );
     67mapping_cluster_t * _get_cluster_base(mapping_header_t* header);
     68mapping_pseg_t * _get_pseg_base(mapping_header_t* header);
     69mapping_vspace_t * _get_vspace_base(mapping_header_t* header);
     70mapping_vseg_t * _get_vseg_base(mapping_header_t* header);
     71mapping_vobj_t * _get_vobj_base(mapping_header_t* header);
     72mapping_task_t * _get_task_base(mapping_header_t* header);
    8273
    8374
     
    8980// Code taken from MutekH.
    9081///////////////////////////////////////////////////////////////////////////////////
    91 static inline void *memcpy(void *_dst, const void *_src, unsigned int size)
    92 {
    93     unsigned int *dst = _dst;
    94     const unsigned int *src = _src;
     82static inline void * memcpy(void * _dst, const void * _src, unsigned int size) {
     83    unsigned int * dst = _dst;
     84    const unsigned int * src = _src;
    9585
    9686    /* if source and destination buffer are word-aligned,
    9787     * then copy word-by-word */
    98     if (!((unsigned int)dst & 3) && !((unsigned int)src & 3))
     88    if (!((unsigned int) dst & 3) && !((unsigned int) src & 3)) {
    9989        while (size > 3) {
    10090            *dst++ = *src++;
    10191            size -= 4;
    10292        }
     93    }
    10394
    104     unsigned char *cdst = (unsigned char*)dst;
    105     unsigned char *csrc = (unsigned char*)src;
     95    unsigned char * cdst = (unsigned char *) dst;
     96    unsigned char * csrc = (unsigned char *) src;
    10697
    10798    /* byte-by-byte copy */
     
    113104
    114105#endif
     106
     107// Local Variables:
     108// tab-width: 4
     109// c-basic-offset: 4
     110// c-file-offsets:((innamespace . 0)(inline-open . 0))
     111// indent-tabs-mode: nil
     112// End:
     113// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
     114
  • soft/giet_vm/sys/ctx_handler.c

    r218 r228  
    3030// - CP2 registers : PTPR
    3131// It contains some general informations associated to the task:
    32 // - TTY        : terminal global index
    33 // - FBDMA      : DMA channel global index
    34 // - NIC        : NIC channel global index
     32// - TTY    : terminal global index
     33// - FBDMA    : DMA channel global index
     34// - NIC    : NIC channel global index
    3535// - TIMER  : Timer global index
    3636// - PTAB   : page table virtual base address
    37 // - LTID       : Task local index (in scheduler)
     37// - LTID    : Task local index (in scheduler)
    3838// - VSID   : Virtual space index
    39 // - RUN        : Task state (0 => sleeping / 1 => runable )
     39// - RUN    : Task state (0 => sleeping / 1 => runable )
    4040//
    4141// ctx[0]<- ***|ctx[8] <- $8 |ctx[16]<- $16|ctx[24]<- $24|ctx[32]<- EPC  |ctx[40]<- TTY
     
    4949//////////////////////////////////////////////////////////////////////////////////////////
    5050
    51 extern void _task_switch(unsigned int*, unsigned int*);
     51extern void _task_switch(unsigned int *, unsigned int *);
    5252
    5353/////////////////////////////////////////////////////////////////////////////////
    54 //      _ctx_switch()
     54//    _ctx_switch()
    5555// This function performs a context switch between the running task
    5656// and  another task, using a round-robin sheduling policy between all
     
    6868//   contained in the ctx[31] slot of the next task context.
    6969/////////////////////////////////////////////////////////////////////////////////
    70 void _ctx_switch()
    71 {
     70void _ctx_switch() {
    7271    // get scheduler physical address
    73     static_scheduler_t* psched = (static_scheduler_t*)_get_sched();
     72    static_scheduler_t * psched = (static_scheduler_t *) _get_sched();
    7473
    7574    // get number of tasks allocated to scheduler
    76     unsigned int        tasks = _get_tasks_number();
     75    unsigned int tasks = _get_tasks_number();
    7776
    7877    // get current task index
    79     unsigned int        curr_task_id = _get_current_task_id();
     78    unsigned int curr_task_id = _get_current_task_id();
    8079
    8180    // select the next task using a round-robin policy
    82     unsigned int        next_task_id;
    83     unsigned int        tid;
    84     unsigned int        found = 0;
     81    unsigned int next_task_id;
     82    unsigned int tid;
     83    unsigned int found = 0;
    8584
    86     for ( tid = curr_task_id + 1 ;
    87           tid < curr_task_id + 1 + tasks ;
    88           tid++ )
    89     {
     85    for (tid = curr_task_id + 1; tid < curr_task_id + 1 + tasks; tid++) {
    9086        next_task_id = tid % tasks;
    9187
    9288        // test if the task is runable
    93         if ( _get_context_slot( next_task_id, CTX_RUN_ID ) )   
    94         {
     89        if (_get_context_slot(next_task_id, CTX_RUN_ID)) {
    9590            found = 1;
    96                 break;
     91            break;
    9792        }
    9893    }
    9994
    10095    // launch "idle" task if no runable task
    101     if ( found == 0 )
    102     {
     96    if (found == 0) {
    10397        next_task_id = IDLE_TASK_INDEX;
    10498    }
    10599
    106100    // no switch if no change
    107     if ( curr_task_id != next_task_id )
    108     {
    109         unsigned int*   curr_ctx_paddr = &(psched->context[curr_task_id][0]);
    110         unsigned int*   next_ctx_paddr = &(psched->context[next_task_id][0]);
     101    if (curr_task_id != next_task_id) {
     102        unsigned int * curr_ctx_paddr = &(psched->context[curr_task_id][0]);
     103        unsigned int * next_ctx_paddr = &(psched->context[next_task_id][0]);
    111104
    112         _set_current_task_id( next_task_id );
    113         _task_switch( curr_ctx_paddr, next_ctx_paddr );
     105        _set_current_task_id(next_task_id);
     106        //_timer_reset_irq_cpt(cluster_id, local_id); // commented until not properly supported in soclib
     107        // (the function is not yet present in drivers.c)
     108        _task_switch(curr_ctx_paddr, next_ctx_paddr);
    114109
    115110#if GIET_DEBUG_SWITCH
    116 _get_lock( &_tty_put_lock );
    117 _puts( "\n[GIET DEBUG] Context switch for processor ");
    118 _putd( _procid() );
    119 _puts( " at cycle ");
    120 _putd( _proctime() );
    121 _puts("\n");
    122 _puts( " - tasks        = ");
    123 _putd( tasks );
    124 _puts("\n");
    125 _puts( " - curr_task_id = ");
    126 _putd( curr_task_id );
    127 _puts("\n");
    128 _puts( " - next_task_id = ");
    129 _putd( next_task_id );
    130 _puts("\n");
    131 _release_lock( &_tty_put_lock );
     111        _get_lock(&_tty_put_lock);
     112        _puts("\n[GIET DEBUG] Context switch for processor ");
     113        _putd(_procid());
     114        _puts(" at cycle ");
     115        _putd(_proctime());
     116        _puts("\n");
     117        _puts(" - tasks        = ");
     118        _putd(tasks);
     119        _puts("\n");
     120        _puts(" - curr_task_id = ");
     121        _putd( curr_task_id );
     122        _puts("\n");
     123        _puts(" - next_task_id = ");
     124        _putd(next_task_id);
     125        _puts("\n");
     126        _release_lock( &_tty_put_lock);
    132127#endif
    133128
     
    138133// This function is executed as the"idle" task when no other task can be executed
    139134/////////////////////////////////////////////////////////////////////////////////////
    140 void _ctx_idle()
    141 {
     135void _ctx_idle() {
    142136    unsigned int delay = 1000000;
    143137
    144     while(1)
    145     {
    146         asm volatile("move  $3,   %0            \n"
    147                      "loop:                                     \n"
    148                      "addi      $3, $3, -1              \n"
    149                      "bnez  $3, loop            \n"
    150                      "nop                                       \n"
    151                      :
    152                      : "r"(delay)
    153                      : "$3" );
     138    while (1) {
     139        asm volatile(
     140                "move   $3,   %0          \n"
     141                "loop:                    \n"
     142                "addi   $3,   $3,   -1    \n"
     143                "bnez   $3,   loop        \n"
     144                "nop                      \n"
     145                :
     146                : "r"(delay)
     147                : "$3" );
    154148
    155         _get_lock( &_tty_put_lock );
    156         _puts( "\n[GIET WARNING] Processor ");
    157         _putd( _procid() );
    158         _puts( " still idle at cycle ");
    159         _putd( _proctime() );
     149        _get_lock(&_tty_put_lock);
     150        _puts("\n[GIET WARNING] Processor ");
     151        _putd(_procid());
     152        _puts(" still idle at cycle ");
     153        _putd(_proctime());
    160154        _puts("\n");
    161         _release_lock( &_tty_put_lock );
    162    
     155        _release_lock(&_tty_put_lock);
     156
    163157    }
    164158} // end ctx_idle()
     159
    165160
    166161/////////////////////////////////////////////////////////////////////////////////
     
    168163// in the "idle" task context.
    169164/////////////////////////////////////////////////////////////////////////////////
    170 void _ctx_eret()
    171 {
     165void _ctx_eret() {
    172166    asm volatile("eret");
    173167}
    174168
    175169
     170// Local Variables:
     171// tab-width: 4
     172// c-basic-offset: 4
     173// c-file-offsets:((innamespace . 0)(inline-open . 0))
     174// indent-tabs-mode: nil
     175// End:
     176// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
     177
  • soft/giet_vm/sys/drivers.c

    r226 r228  
    103103
    104104//////////////////////////////////////////////////////////////////////////////
    105 //      Timers driver
     105//     Timers driver
    106106//////////////////////////////////////////////////////////////////////////////
    107107// The timers can be implemented in a vci_timer component or in a vci_xicu
     
    119119
    120120#if (NB_TIMERS_MAX > 0)
    121 in_unckdata volatile unsigned char _user_timer_event[NB_CLUSTERS*NB_TIMERS_MAX]
    122          = { [0 ... ((NB_CLUSTERS*NB_TIMERS_MAX)-1)] = 0 };
     121in_unckdata volatile unsigned char _user_timer_event[NB_CLUSTERS * NB_TIMERS_MAX]
     122= { [0 ... ((NB_CLUSTERS * NB_TIMERS_MAX) - 1)] = 0 };
    123123#endif
    124124
     
    131131// Returns 0 if success, > 0 if error.
    132132//////////////////////////////////////////////////////////////////////////////
    133 unsigned int _timer_start( unsigned int cluster_id,
    134                            unsigned int local_id,
    135                            unsigned int period )
    136 {
     133unsigned int _timer_start(unsigned int cluster_id, unsigned int local_id, unsigned int period) {
    137134    // parameters checking
    138     if ( cluster_id >= NB_CLUSTERS)     return 1;
    139     if ( local_id >= NB_TIMERS_MAX) return 2;
     135    if (cluster_id >= NB_CLUSTERS) {
     136        return 1;
     137    }
     138    if (local_id >= NB_TIMERS_MAX) {
     139        return 2;
     140    }
    140141
    141142#if USE_XICU
    142     unsigned int* timer_address = (unsigned int*)((char*)&seg_icu_base +
    143                                   (cluster_id * CLUSTER_SIZE) );
     143    unsigned int * timer_address = (unsigned int *) ((char *) &seg_icu_base + (cluster_id * CLUSTER_SIZE));
    144144
    145145    timer_address[XICU_REG(XICU_PTI_PER, local_id)] = period;
    146146#else
    147     unsigned int* timer_address = (unsigned int*)((char*)&seg_tim_base +
    148                                   (cluster_id * CLUSTER_SIZE) );
     147    unsigned int* timer_address = (unsigned int *) ((char *) &seg_tim_base + (cluster_id * CLUSTER_SIZE));
    149148
    150149    timer_address[local_id * TIMER_SPAN + TIMER_PERIOD] = period;
    151     timer_address[local_id * TIMER_SPAN + TIMER_MODE]   = 0x3;
    152 #endif
    153 
    154     return 0;
    155 }
     150    timer_address[local_id * TIMER_SPAN + TIMER_MODE] = 0x3;
     151#endif
     152    return 0;
     153}
     154
     155
    156156//////////////////////////////////////////////////////////////////////////////
    157157//     _timer_stop()
     
    160160// Returns 0 if success, > 0 if error.
    161161//////////////////////////////////////////////////////////////////////////////
    162 unsigned int _timer_stop( unsigned int  cluster_id,
    163                           unsigned int  local_id )
    164 {
     162unsigned int _timer_stop(unsigned int cluster_id, unsigned int local_id) {
    165163    // parameters checking
    166     if ( cluster_id >= NB_CLUSTERS)      return 1;
    167     if ( local_id >= NB_TIMERS_MAX ) return 2;
     164    if (cluster_id >= NB_CLUSTERS) {
     165        return 1;
     166    }
     167    if (local_id >= NB_TIMERS_MAX) {
     168        return 2;
     169    }
    168170
    169171#if USE_XICU
    170     unsigned int* timer_address = (unsigned int*)((char*)&seg_icu_base +
    171                                   (cluster_id * CLUSTER_SIZE) );
     172    unsigned int * timer_address = (unsigned int *) ((char *) &seg_icu_base + (cluster_id * CLUSTER_SIZE));
    172173
    173174    timer_address[XICU_REG(XICU_PTI_PER, local_id)] = 0;
    174175#else
    175     unsigned int* timer_address = (unsigned int*)((char*)&seg_tim_base +
    176                                   (cluster_id * CLUSTER_SIZE) );
    177 
     176    unsigned int* timer_address = (unsigned int *) ((char *) &seg_tim_base + (cluster_id * CLUSTER_SIZE));
    178177    timer_address[local_id * TIMER_SPAN + TIMER_MODE] = 0;
    179178#endif
    180 
    181     return 0;
    182 }
     179    return 0;
     180}
     181
     182
    183183//////////////////////////////////////////////////////////////////////////////
    184184//     _timer_reset_irq()
     
    189189// Returns 0 if success, > 0 if error.
    190190//////////////////////////////////////////////////////////////////////////////
    191 unsigned int _timer_reset_irq( unsigned int     cluster_id,
    192                                unsigned int     local_id )
    193 {
     191unsigned int _timer_reset_irq(unsigned int cluster_id, unsigned int local_id) {
    194192    // parameters checking
    195     if ( cluster_id >= NB_CLUSTERS)      return 1;
    196     if ( local_id >= NB_TIMERS_MAX ) return 2;
     193    if (cluster_id >= NB_CLUSTERS) {
     194        return 1;
     195    }
     196    if (local_id >= NB_TIMERS_MAX) {
     197        return 2;
     198    }
    197199
    198200#if USE_XICU
    199     unsigned int* timer_address = (unsigned int*)((char*)&seg_icu_base +
    200                                   (cluster_id * (unsigned)CLUSTER_SIZE) );
     201    unsigned int * timer_address = (unsigned int *) ((char *) &seg_icu_base +
     202            (cluster_id * (unsigned) CLUSTER_SIZE));
    201203
    202204    unsigned int bloup = timer_address[XICU_REG(XICU_PTI_ACK, local_id)];
    203     bloup++;    // to avoid a warning
     205    bloup++; // to avoid a warning
    204206#else
    205     unsigned int* timer_address = (unsigned int*)((char*)&seg_tim_base +
    206                                   (cluster_id * CLUSTER_SIZE) );
     207    unsigned int * timer_address = (unsigned int *)((char *) &seg_tim_base +
     208            (cluster_id * CLUSTER_SIZE));
    207209
    208210    timer_address[local_id * TIMER_SPAN + TIMER_RESETIRQ] = 0;
     
    212214}
    213215
     216
    214217/////////////////////////////////////////////////////////////////////////////////
    215 //      VciMultiTty driver
     218//     VciMultiTty driver
    216219/////////////////////////////////////////////////////////////////////////////////
    217220// There is only one multi_tty controler in the architecture.
     
    226229// TTY variables
    227230in_unckdata volatile unsigned char _tty_get_buf[NB_TTYS];
    228 in_unckdata volatile unsigned char _tty_get_full[NB_TTYS] = { [0 ... NB_TTYS-1] = 0 };
    229 in_unckdata unsigned int           _tty_put_lock = 0;  // protect kernel TTY[0]
     231in_unckdata volatile unsigned char _tty_get_full[NB_TTYS] = { [0 ... NB_TTYS - 1] = 0 };
     232in_unckdata unsigned int _tty_put_lock = 0;  // protect kernel TTY[0]
    230233
    231234////////////////////////////////////////////////////////////////////////////////
    232235//      _tty_error()
    233236////////////////////////////////////////////////////////////////////////////////
    234 void _tty_error( unsigned int tty_id, unsigned int task_id )
    235 {
     237void _tty_error(unsigned int tty_id, unsigned int task_id) {
    236238    unsigned int proc_id = _procid();
    237239
    238240    _get_lock(&_tty_put_lock);
    239     if( tty_id == 0xFFFFFFFF )
     241    if (tty_id == 0xFFFFFFFF) {
    240242        _puts("\n[GIET ERROR] no TTY assigned to the task ");
    241     else
     243    }
     244    else {
    242245        _puts("\n[GIET ERROR] TTY index too large for task ");
    243     _putd( task_id );
     246    }
     247    _putd(task_id);
    244248    _puts(" on processor ");
    245     _putd( proc_id );
     249    _putd(proc_id);
    246250    _puts("\n");
    247251    _release_lock(&_tty_put_lock);
    248252}
     253
     254
    249255/////////////////////////////////////////////////////////////////////////////////
    250256//      _tty_write()
     
    256262// The function returns  the number of characters that have been written.
    257263/////////////////////////////////////////////////////////////////////////////////
    258 unsigned int _tty_write( const char             *buffer,
    259                          unsigned int   length)
    260 {
    261     unsigned int        nwritten;
    262 
    263     unsigned int task_id  = _get_current_task_id();
    264     unsigned int tty_id   = _get_context_slot(task_id, CTX_TTY_ID);
    265 
    266     if ( tty_id >= NB_TTYS )
    267     {
    268         _tty_error( tty_id , task_id );
     264unsigned int _tty_write(const char * buffer, unsigned int length) {
     265    unsigned int nwritten;
     266    unsigned int task_id = _get_current_task_id();
     267    unsigned int tty_id = _get_context_slot(task_id, CTX_TTY_ID);
     268
     269    if (tty_id >= NB_TTYS) {
     270        _tty_error(tty_id , task_id);
    269271        return 0;
    270272    }
    271273
    272     unsigned int*       tty_address = (unsigned int*) &seg_tty_base;
    273 
    274     for (nwritten = 0; nwritten < length; nwritten++)
    275     {
     274    unsigned int * tty_address = (unsigned int *) &seg_tty_base;
     275
     276    for (nwritten = 0; nwritten < length; nwritten++) {
    276277        // check tty's status
    277         if ((tty_address[tty_id*TTY_SPAN + TTY_STATUS] & 0x2) == 0x2)
     278        if ((tty_address[tty_id * TTY_SPAN + TTY_STATUS] & 0x2) == 0x2) {
    278279            break;
    279         else
     280        }
     281        else {
    280282            // write character
    281             tty_address[tty_id*TTY_SPAN + TTY_WRITE] = (unsigned int)buffer[nwritten];
     283            tty_address[tty_id * TTY_SPAN + TTY_WRITE] = (unsigned int) buffer[nwritten];
     284        }
    282285    }
    283286    return nwritten;
    284287}
     288
     289
    285290//////////////////////////////////////////////////////////////////////////////
    286291//      _tty_read()
     
    294299// Returns 0 if the kernel buffer is empty, 1 if the buffer is full.
    295300//////////////////////////////////////////////////////////////////////////////
    296 unsigned int _tty_read( char                    *buffer,
    297                         unsigned int    length)
    298 {
    299     unsigned int task_id  = _get_current_task_id();
    300     unsigned int tty_id   = _get_context_slot(task_id, CTX_TTY_ID);
    301 
    302     if ( tty_id >= NB_TTYS )
    303     {
    304         _tty_error( tty_id, task_id );
     301unsigned int _tty_read(char * buffer, unsigned int length) {
     302    unsigned int task_id = _get_current_task_id();
     303    unsigned int tty_id = _get_context_slot(task_id, CTX_TTY_ID);
     304
     305    if (tty_id >= NB_TTYS) {
     306        _tty_error(tty_id, task_id);
    305307        return 0;
    306308    }
    307309
    308     if (_tty_get_full[tty_id] == 0)
    309     {
     310    if (_tty_get_full[tty_id] == 0) {
    310311        return 0;
    311312    }
    312     else
    313     {
     313    else {
    314314        *buffer = _tty_get_buf[tty_id];
    315315        _tty_get_full[tty_id] = 0;
    316316        return 1;
    317317    }
    318 }
     318}
     319
     320
    319321////////////////////////////////////////////////////////////////////////////////
    320322//     _tty_get_char()
     
    324326// Returns 0 if success, 1 if tty_id too large.
    325327////////////////////////////////////////////////////////////////////////////////
    326 unsigned int _tty_get_char( unsigned int        tty_id,
    327                             unsigned char*  buffer )
    328 {
     328unsigned int _tty_get_char(unsigned int tty_id, unsigned char * buffer) {
    329329    // checking argument
    330     if ( tty_id >= NB_TTYS ) return 1;
     330    if (tty_id >= NB_TTYS) {
     331        return 1;
     332    }
    331333
    332334    // compute terminal base address
    333     unsigned int *tty_address = (unsigned int*) &seg_tty_base;
    334 
    335     *buffer = (unsigned char)tty_address[tty_id*TTY_SPAN + TTY_READ];
    336     return 0;
    337 }
    338 
    339 ////////////////////////////////////////////////////////////////////////////////
    340 //      VciMultiIcu and VciXicu drivers
     335    unsigned int * tty_address = (unsigned int *) &seg_tty_base;
     336
     337    *buffer = (unsigned char) tty_address[tty_id * TTY_SPAN + TTY_READ];
     338    return 0;
     339}
     340
     341
     342////////////////////////////////////////////////////////////////////////////////
     343//     VciMultiIcu and VciXicu drivers
    341344////////////////////////////////////////////////////////////////////////////////
    342345// There is one vci_multi_icu (or vci_xicu) component per cluster,
     
    352355// Returns 0 if success, > 0 if error.
    353356////////////////////////////////////////////////////////////////////////////////
    354 unsigned int _icu_set_mask( unsigned int cluster_id,
    355                             unsigned int proc_id,
    356                             unsigned int value,
    357                             unsigned int is_timer )
    358 {
     357unsigned int _icu_set_mask(
     358        unsigned int cluster_id,
     359        unsigned int proc_id,
     360        unsigned int value,
     361        unsigned int is_timer) {
    359362    // parameters checking
    360     if ( cluster_id >= NB_CLUSTERS)             return 1;
    361     if ( proc_id    >= NB_PROCS_MAX )   return 1;
    362 
    363     unsigned int* icu_address = (unsigned int*)( (char*)&seg_icu_base +
    364                                 (cluster_id * (unsigned)CLUSTER_SIZE) );
     363    if (cluster_id >= NB_CLUSTERS) {
     364        return 1;
     365    }
     366    if (proc_id >= NB_PROCS_MAX) {
     367        return 1;
     368    }
     369
     370    unsigned int * icu_address = (unsigned int *) ((char *) &seg_icu_base +
     371            (cluster_id * (unsigned) CLUSTER_SIZE));
    365372#if USE_XICU
    366     if ( is_timer ) icu_address[XICU_REG(XICU_MSK_PTI_ENABLE, proc_id)] = value;
    367     else            icu_address[XICU_REG(XICU_MSK_HWI_ENABLE, proc_id)] = value;
     373    if (is_timer) {
     374        icu_address[XICU_REG(XICU_MSK_PTI_ENABLE, proc_id)] = value;
     375    }
     376    else {
     377        icu_address[XICU_REG(XICU_MSK_HWI_ENABLE, proc_id)] = value;
     378    }
    368379#else
    369380    icu_address[proc_id * ICU_SPAN + ICU_MASK_SET] = value;
     
    372383    return 0;
    373384}
     385
     386
    374387////////////////////////////////////////////////////////////////////////////////
    375388//     _icu_get_index()
     
    379392// Returns 0 if success, > 0 if error.
    380393////////////////////////////////////////////////////////////////////////////////
    381 unsigned int _icu_get_index(  unsigned int cluster_id,
    382                               unsigned int proc_id,
    383                               unsigned int* buffer )
    384 {
     394unsigned int _icu_get_index(unsigned int cluster_id, unsigned int proc_id, unsigned int * buffer) {
    385395    // parameters checking
    386     if ( cluster_id >= NB_CLUSTERS)             return 1;
    387     if ( proc_id    >= NB_PROCS_MAX )   return 1;
    388 
    389     unsigned int* icu_address = (unsigned int*)( (char*)&seg_icu_base +
    390                                 (cluster_id * (unsigned)CLUSTER_SIZE) );
     396    if (cluster_id >= NB_CLUSTERS) {
     397        return 1;
     398    }
     399    if (proc_id >= NB_PROCS_MAX) {
     400        return 1;
     401    }
     402
     403    unsigned int * icu_address = (unsigned int *) ((char *) &seg_icu_base +
     404            (cluster_id * (unsigned) CLUSTER_SIZE));
    391405#if USE_XICU
    392     unsigned int prio   = icu_address[XICU_REG(XICU_PRIO, proc_id)];
     406    unsigned int prio = icu_address[XICU_REG(XICU_PRIO, proc_id)];
    393407    unsigned int pti_ok = (prio & 0x00000001);
    394408    unsigned int hwi_ok = (prio & 0x00000002);
     
    397411    unsigned int hwi_id = (prio & 0x001F0000) >> 16;
    398412    unsigned int swi_id = (prio & 0x1F000000) >> 24;
    399     if      (pti_ok)    *buffer = pti_id;
    400     else if (hwi_ok)    *buffer = hwi_id;
    401     else if (swi_ok)    *buffer = swi_id;
    402     else                *buffer = 32;
     413    if (pti_ok) {
     414        *buffer = pti_id;
     415    }
     416    else if (hwi_ok) {
     417        *buffer = hwi_id;
     418    }
     419    else if (swi_ok) {
     420        *buffer = swi_id;
     421    }
     422    else {
     423        *buffer = 32;
     424    }
    403425#else
    404426    *buffer = icu_address[proc_id * ICU_SPAN + ICU_IT_VECTOR];
     
    408430}
    409431
    410 ////////////////////////////////////////////////////////////////////////////////
    411 //      VciGcd driver
     432
     433////////////////////////////////////////////////////////////////////////////////
     434//     VciGcd driver
    412435////////////////////////////////////////////////////////////////////////////////
    413436// The Greater Dommon Divider is a -very- simple hardware coprocessor
     
    421444// Returns 0 if success, > 0 if error.
    422445////////////////////////////////////////////////////////////////////////////////
    423 unsigned int _gcd_write( unsigned int register_index,
    424                          unsigned int value)
    425 {
     446unsigned int _gcd_write(unsigned int register_index, unsigned int value) {
    426447    // parameters checking
    427     if (register_index >= GCD_END)
    428         return 1;
    429 
    430     unsigned int* gcd_address = (unsigned int*) &seg_gcd_base;
     448    if (register_index >= GCD_END) {
     449        return 1;
     450    }
     451
     452    unsigned int * gcd_address = (unsigned int *) &seg_gcd_base;
    431453
    432454    gcd_address[register_index] = value; // write word
    433455    return 0;
    434456}
     457
     458
    435459////////////////////////////////////////////////////////////////////////////////
    436460//     _gcd_read()
     
    438462// Returns 0 if success, > 0 if error.
    439463////////////////////////////////////////////////////////////////////////////////
    440 unsigned int _gcd_read( unsigned int register_index,
    441                         unsigned int *buffer)
    442 {
     464unsigned int _gcd_read(unsigned int register_index, unsigned int * buffer) {
    443465    // parameters checking
    444     if (register_index >= GCD_END)
    445         return 1;
    446 
    447     unsigned int* gcd_address = (unsigned int*) &seg_gcd_base;
     466    if (register_index >= GCD_END) {
     467        return 1;
     468    }
     469
     470    unsigned int * gcd_address = (unsigned int *) &seg_gcd_base;
    448471
    449472    *buffer = gcd_address[register_index]; // read word
     
    502525
    503526// IOC global variables
    504 in_unckdata volatile unsigned int       _ioc_status       = 0;
    505 in_unckdata volatile unsigned int       _ioc_done        = 0;
    506 in_unckdata unsigned int                        _ioc_lock        = 0;
    507 in_unckdata unsigned int                        _ioc_iommu_ix1    = 0;
    508 in_unckdata unsigned int                        _ioc_iommu_npages;
     527in_unckdata volatile unsigned int _ioc_status= 0;
     528in_unckdata volatile unsigned int _ioc_done = 0;
     529in_unckdata unsigned int _ioc_lock = 0;
     530in_unckdata unsigned int _ioc_iommu_ix1 = 0;
     531in_unckdata unsigned int _ioc_iommu_npages;
    509532
    510533///////////////////////////////////////////////////////////////////////////////
     
    519542// Returns 0 if success, > 0 if error.
    520543///////////////////////////////////////////////////////////////////////////////
    521 unsigned int _ioc_access( unsigned int  to_mem,
    522                           unsigned int  lba,
    523                           unsigned int  user_vaddr,
    524                           unsigned int  count )
    525 {
    526     unsigned int                user_vpn_min;   // first virtuel page index in user space
    527     unsigned int                user_vpn_max;   // last virtual page index in user space
    528     unsigned int                vpn;                    // current virtual page index in user space
    529     unsigned int                ppn;                    // physical page number
    530     unsigned int                flags;                  // page protection flags
    531     unsigned int                ix2;                    // page index in IOMMU PT1 page table
    532     unsigned int                addr;                   // buffer address for IOC peripheral
    533     unsigned int                ppn_first;              // first physical page number for user buffer
    534        
     544unsigned int _ioc_access(
     545        unsigned int to_mem,
     546        unsigned int lba,
     547        unsigned int user_vaddr,
     548        unsigned int count) {
     549    unsigned int user_vpn_min; // first virtuel page index in user space
     550    unsigned int user_vpn_max; // last virtual page index in user space
     551    unsigned int vpn;          // current virtual page index in user space
     552    unsigned int ppn;          // physical page number
     553    unsigned int flags;        // page protection flags
     554    unsigned int ix2;          // page index in IOMMU PT1 page table
     555    unsigned int addr;         // buffer address for IOC peripheral
     556    unsigned int ppn_first;    // first physical page number for user buffer
     557
    535558    // check buffer alignment
    536     if ( (unsigned int)user_vaddr & 0x3 ) return 1;
    537 
    538     unsigned int*       ioc_address = (unsigned int*) &seg_ioc_base ;
    539 
    540     unsigned int        block_size   = ioc_address[BLOCK_DEVICE_BLOCK_SIZE];
    541     unsigned int        length       = count*block_size;
     559    if ((unsigned int) user_vaddr & 0x3) {
     560        return 1;
     561    }
     562
     563    unsigned int * ioc_address = (unsigned int *) &seg_ioc_base ;
     564
     565    unsigned int block_size = ioc_address[BLOCK_DEVICE_BLOCK_SIZE];
     566    unsigned int length = count * block_size;
    542567
    543568    // get user space page table virtual address
    544     unsigned int task_id       = _get_current_task_id();
    545     unsigned int user_pt_vbase = _get_context_slot( task_id, CTX_PTAB_ID );
    546    
     569    unsigned int task_id = _get_current_task_id();
     570    unsigned int user_pt_vbase = _get_context_slot(task_id, CTX_PTAB_ID);
     571
    547572    user_vpn_min = user_vaddr >> 12;
    548573    user_vpn_max = (user_vaddr + length - 1) >> 12;
    549     ix2          = 0;
     574    ix2 = 0;
    550575
    551576    // loop on all virtual pages covering the user buffer
    552     for ( vpn = user_vpn_min ; vpn <= user_vpn_max ; vpn++ )
    553     {
     577    for (vpn = user_vpn_min; vpn <= user_vpn_max; vpn++) {
    554578        // get ppn and flags for each vpn
    555         unsigned int ko = _v2p_translate( (page_table_t*)user_pt_vbase,
    556                                            vpn,
    557                                            &ppn,
    558                                            &flags );
     579        unsigned int ko = _v2p_translate((page_table_t *) user_pt_vbase, vpn, &ppn, &flags);
    559580
    560581        // check access rights
    561         if ( ko )                                                                 return 2;             // unmapped
    562         if ( (flags & PTE_U) == 0 )                               return 3;             // not in user space
    563         if ( ( (flags & PTE_W) == 0 ) && to_mem ) return 4;             // not writable
     582        if (ko) {
     583            return 2; // unmapped
     584        }
     585        if ((flags & PTE_U) == 0) {
     586            return 3; // not in user space
     587        }
     588        if (((flags & PTE_W) == 0 ) && to_mem) {
     589            return 4; // not writable
     590        }
    564591
    565592        // save first ppn value
    566         if ( ix2 == 0 ) ppn_first = ppn;
    567 
    568         if ( IOMMU_ACTIVE )    // the user buffer must be remapped in the I/0 space
    569         {
     593        if (ix2 == 0) {
     594            ppn_first = ppn;
     595        }
     596
     597        if (IOMMU_ACTIVE) {
     598            // the user buffer must be remapped in the I/0 space
    570599            // check buffer length < 2 Mbytes
    571             if ( ix2 > 511 ) return 2;
     600            if (ix2 > 511) {
     601                return 2;
     602            }
    572603
    573604            // map the physical page in IOMMU page table
    574             _iommu_add_pte2( _ioc_iommu_ix1,    // PT1 index
    575                              ix2,                               // PT2 index
    576                                                  ppn,                           // Physical page number
    577                              flags );                   // Protection flags
     605            _iommu_add_pte2(
     606                    _ioc_iommu_ix1,    // PT1 index
     607                    ix2,               // PT2 index
     608                    ppn,               // Physical page number   
     609                    flags);            // Protection flags
    578610        }
    579         else                    // no IOMMU : check that physical pages are contiguous
    580         {
    581             if ( (ppn - ppn_first) != ix2 )           return 5;         // split physical buffer 
     611        else {
     612            // no IOMMU : check that physical pages are contiguous
     613            if ((ppn - ppn_first) != ix2) {
     614                return 5; // split physical buffer
     615            }
    582616        }
    583        
     617
    584618        // increment page index
    585619        ix2++;
     
    590624
    591625    // invalidate data cache in case of memory write
    592     if ( to_mem ) _dcache_buf_invalidate( (void*)user_vaddr, length );
     626    if (to_mem) {
     627        _dcache_buf_invalidate((void *) user_vaddr, length);
     628    }
    593629
    594630    // compute buffer base address for IOC depending on IOMMU activation
    595     if ( IOMMU_ACTIVE ) addr = (_ioc_iommu_ix1) << 21 | (user_vaddr & 0xFFF);
    596     else                     addr = (ppn_first << 12) | (user_vaddr & 0xFFF);
     631    if (IOMMU_ACTIVE) {
     632        addr = (_ioc_iommu_ix1) << 21 | (user_vaddr & 0xFFF);
     633    }
     634    else {
     635        addr = (ppn_first << 12) | (user_vaddr & 0xFFF);
     636    }
    597637
    598638    // get the lock on ioc device
    599     _get_lock( &_ioc_lock );
     639    _get_lock(&_ioc_lock);
    600640
    601641    // peripheral configuration 
    602     ioc_address[BLOCK_DEVICE_BUFFER]     = addr;
    603     ioc_address[BLOCK_DEVICE_COUNT]      = count;
    604     ioc_address[BLOCK_DEVICE_LBA]        = lba;
    605     if ( to_mem == 0 ) ioc_address[BLOCK_DEVICE_OP] = BLOCK_DEVICE_WRITE;
    606     else               ioc_address[BLOCK_DEVICE_OP] = BLOCK_DEVICE_READ;
    607 
    608     return 0;
    609 }
     642    ioc_address[BLOCK_DEVICE_BUFFER] = addr;
     643    ioc_address[BLOCK_DEVICE_COUNT] = count;
     644    ioc_address[BLOCK_DEVICE_LBA] = lba;
     645    if (to_mem == 0) {
     646        ioc_address[BLOCK_DEVICE_OP] = BLOCK_DEVICE_WRITE;
     647    }
     648    else {
     649        ioc_address[BLOCK_DEVICE_OP] = BLOCK_DEVICE_READ;
     650    }
     651
     652    return 0;
     653}
     654
     655
    610656/////////////////////////////////////////////////////////////////////////////////
    611657// _ioc_completed()
     
    617663// Returns 0 if success, > 0 if error.
    618664/////////////////////////////////////////////////////////////////////////////////
    619 unsigned int _ioc_completed()
    620 {
    621     unsigned int        ret;
    622     unsigned int        ix2;
     665unsigned int _ioc_completed() {
     666    unsigned int ret;
     667    unsigned int ix2;
    623668
    624669    // busy waiting
    625     while (_ioc_done == 0)
     670    while (_ioc_done == 0) {
    626671        asm volatile("nop");
     672    }
    627673
    628674    // unmap the buffer from IOMMU page table if IOMMU is activated
    629     if ( IOMMU_ACTIVE )
    630     {
    631         unsigned int* iob_address = (unsigned int*) &seg_iob_base;
    632 
    633         for ( ix2 = 0 ; ix2 < _ioc_iommu_npages ; ix2++ )
    634         {
     675    if (IOMMU_ACTIVE) {
     676        unsigned int * iob_address = (unsigned int *) &seg_iob_base;
     677
     678        for (ix2 = 0; ix2 < _ioc_iommu_npages; ix2++) {
    635679            // unmap the page in IOMMU page table
    636             _iommu_inval_pte2( _ioc_iommu_ix1,  // PT1 index
    637                               ix2 );                    // PT2 index
     680            _iommu_inval_pte2(
     681                    _ioc_iommu_ix1, // PT1 index
     682                    ix2 );          // PT2 index
    638683
    639684            // clear IOMMU TLB
     
    644689    // test IOC status
    645690    if ((_ioc_status != BLOCK_DEVICE_READ_SUCCESS)
    646             && (_ioc_status != BLOCK_DEVICE_WRITE_SUCCESS)) ret = 1;    // error
    647     else                                                    ret = 0;    // success
     691            && (_ioc_status != BLOCK_DEVICE_WRITE_SUCCESS)) {
     692        ret = 1; // error
     693    }
     694    else {
     695        ret = 0; // success
     696    }
    648697
    649698    // reset synchronization variables
    650699    _ioc_done = 0;
    651     asm volatile ("sync");
     700    asm volatile("sync");
    652701    _ioc_lock = 0;
    653702
    654703    return ret;
    655704}
     705
     706
    656707///////////////////////////////////////////////////////////////////////////////
    657708//     _ioc_read()
     
    662713// Returns 0 if success, > 0 if error.
    663714///////////////////////////////////////////////////////////////////////////////
    664 unsigned int _ioc_read( unsigned int    lba,
    665                         void*               buffer,
    666                         unsigned int    count )
    667 {
    668     return _ioc_access( 1,              // read access
    669                         lba,
    670                         (unsigned int)buffer,
    671                         count );
    672 }
     715unsigned int _ioc_read(unsigned int lba, void * buffer, unsigned int count) {
     716    return _ioc_access(
     717            1,        // read access
     718            lba,
     719            (unsigned int) buffer,
     720            count);
     721}
     722
     723
    673724///////////////////////////////////////////////////////////////////////////////
    674725//     _ioc_write()
     
    679730// Returns 0 if success, > 0 if error.
    680731///////////////////////////////////////////////////////////////////////////////
    681 unsigned int _ioc_write( unsigned int   lba,
    682                          const void*    buffer,
    683                          unsigned int   count )
    684 {
    685     return _ioc_access( 0,              // write access
    686                         lba,
    687                         (unsigned int)buffer,
    688                         count );
    689 }
     732unsigned int _ioc_write(unsigned int lba, const void * buffer, unsigned int count) {
     733    return _ioc_access(
     734            0, // write access
     735            lba,
     736            (unsigned int) buffer,
     737            count);
     738}
     739
     740
    690741///////////////////////////////////////////////////////////////////////////////
    691742//     _ioc_get_status()
     
    693744// Returns 0 if success, > 0 if error.
    694745///////////////////////////////////////////////////////////////////////////////
    695 unsigned int _ioc_get_status(unsigned int* status)
    696 {
     746unsigned int _ioc_get_status(unsigned int * status) {
    697747    // get IOC base address
    698     unsigned int* ioc_address = (unsigned int*) &seg_ioc_base;
     748    unsigned int * ioc_address = (unsigned int *) &seg_ioc_base;
    699749
    700750    *status = ioc_address[BLOCK_DEVICE_STATUS]; // read status & reset IRQ
    701751    return 0;
    702752}
     753
    703754
    704755//////////////////////////////////////////////////////////////////////////////////
     
    719770
    720771#if NB_DMAS_MAX > 0
    721 in_unckdata unsigned int                        _dma_lock[NB_DMAS_MAX * NB_CLUSTERS]
    722                                        = { [0 ... (NB_DMAS_MAX * NB_CLUSTERS)-1] = 0 };
    723 
    724 in_unckdata volatile unsigned int       _dma_done[NB_DMAS_MAX * NB_CLUSTERS]
    725                                        = { [0 ... (NB_DMAS_MAX * NB_CLUSTERS)-1] = 0 };
    726 
    727 in_unckdata volatile unsigned int       _dma_status[NB_DMAS_MAX * NB_CLUSTERS];
    728 
    729 in_unckdata unsigned int                        _dma_iommu_ix1 = 1;
    730 
    731 in_unckdata unsigned int            _dma_iommu_npages[NB_DMAS_MAX * NB_CLUSTERS];
     772in_unckdata unsigned int            _dma_lock[NB_DMAS_MAX * NB_CLUSTERS] = {
     773    [0 ... (NB_DMAS_MAX * NB_CLUSTERS) - 1] = 0
     774};
     775
     776in_unckdata volatile unsigned int    _dma_done[NB_DMAS_MAX * NB_CLUSTERS] = {
     777    [0 ... (NB_DMAS_MAX * NB_CLUSTERS) - 1] = 0
     778};
     779
     780in_unckdata volatile unsigned int _dma_status[NB_DMAS_MAX * NB_CLUSTERS];
     781in_unckdata unsigned int _dma_iommu_ix1 = 1;
     782in_unckdata unsigned int _dma_iommu_npages[NB_DMAS_MAX * NB_CLUSTERS];
    732783#endif
    733784
     
    735786// _dma_reset_irq()
    736787//////////////////////////////////////////////////////////////////////////////////
    737 unsigned int _dma_reset_irq( unsigned int       cluster_id,
    738                              unsigned int       channel_id )
    739 {
     788unsigned int _dma_reset_irq(unsigned int cluster_id, unsigned int channel_id) {
    740789#if NB_DMAS_MAX > 0
    741790    // parameters checking
    742     if ( cluster_id >= NB_CLUSTERS ) return 1;
    743     if ( channel_id >= NB_DMAS_MAX ) return 1;
     791    if (cluster_id >= NB_CLUSTERS) {
     792        return 1;
     793    }
     794    if (channel_id >= NB_DMAS_MAX) {
     795        return 1;
     796    }
    744797
    745798    // compute DMA base address
    746     unsigned int*       dma_address = (unsigned int*)( (char*)&seg_dma_base +
    747                                   (cluster_id * (unsigned)CLUSTER_SIZE) );
    748 
    749     dma_address[channel_id*DMA_SPAN + DMA_RESET] = 0;                   
     799    unsigned int * dma_address = (unsigned int *) ((char *) &seg_dma_base +
     800            (cluster_id * (unsigned) CLUSTER_SIZE));
     801
     802    dma_address[channel_id * DMA_SPAN + DMA_RESET] = 0;           
    750803    return 0;
    751804#else
     
    754807}
    755808
     809
    756810//////////////////////////////////////////////////////////////////////////////////
    757811// _dma_get_status()
    758812//////////////////////////////////////////////////////////////////////////////////
    759 unsigned int _dma_get_status( unsigned int      cluster_id,
    760                               unsigned int      channel_id,
    761                               unsigned int* status )
    762 {
     813unsigned int _dma_get_status(unsigned int cluster_id, unsigned int channel_id, unsigned int * status) {
    763814#if NB_DMAS_MAX > 0
    764815    // parameters checking
    765     if ( cluster_id >= NB_CLUSTERS ) return 1;
    766     if ( channel_id >= NB_DMAS_MAX ) return 1;
     816    if (cluster_id >= NB_CLUSTERS) {
     817        return 1;
     818    }
     819    if (channel_id >= NB_DMAS_MAX) {
     820        return 1;
     821    }
    767822
    768823    // compute DMA base address
    769     unsigned int*       dma_address = (unsigned int*)( (char*)&seg_dma_base +
    770                                   (cluster_id * (unsigned)CLUSTER_SIZE) );
    771 
    772     *status = dma_address[channel_id*DMA_SPAN + DMA_LEN];
     824    unsigned int * dma_address = (unsigned int *) ((char *) &seg_dma_base +
     825            (cluster_id * (unsigned) CLUSTER_SIZE));
     826
     827    *status = dma_address[channel_id * DMA_SPAN + DMA_LEN];
    773828    return 0;
    774829#else
     
    776831#endif
    777832}
     833
    778834
    779835//////////////////////////////////////////////////////////////////////////////////
     
    798854// Returns 0 if success, > 0 if error.
    799855//////////////////////////////////////////////////////////////////////////////////
    800 unsigned int _dma_transfer(  unsigned int   dev_type,
    801                              unsigned int   to_user,
    802                              unsigned int   offset,
    803                              unsigned int   user_vaddr,
    804                              unsigned int   length )
    805 {
     856unsigned int _dma_transfer(
     857        unsigned int dev_type,
     858        unsigned int to_user,
     859        unsigned int offset,
     860        unsigned int user_vaddr,
     861        unsigned int length) {
    806862#if NB_DMAS_MAX > 0
    807     unsigned int        ko;                                     // unsuccessfull V2P translation
    808     unsigned int        flags;                          // protection flags
    809     unsigned int        ppn;                            // physical page number
    810     unsigned int    user_pbase;                 // user buffer pbase address
    811     unsigned int    device_pbase;                       // frame buffer pbase address
    812     unsigned int        device_vaddr;                   // device buffer vbase address
     863    unsigned int ko;           // unsuccessfull V2P translation
     864    unsigned int flags;        // protection flags
     865    unsigned int ppn;          // physical page number
     866    unsigned int user_pbase;   // user buffer pbase address
     867    unsigned int device_pbase; // frame buffer pbase address
     868    unsigned int device_vaddr; // device buffer vbase address
    813869
    814870    // check user buffer address and length alignment
    815     if ( (user_vaddr & 0x3) || (length & 0x3) )
    816     {
     871    if ((user_vaddr & 0x3) || (length & 0x3)) {
    817872        _get_lock(&_tty_put_lock);
    818873        _puts("\n[GIET ERROR] in _dma_transfer : user buffer not word aligned\n");
     
    822877
    823878    // get DMA channel and compute DMA vbase address
    824     unsigned int        task_id    = _get_current_task_id();
    825     unsigned int    dma_id     = _get_context_slot( task_id, CTX_DMA_ID );
    826     unsigned int    cluster_id = dma_id / NB_DMAS_MAX;
    827     unsigned int    loc_id     = dma_id % NB_DMAS_MAX;
    828     unsigned int*       dma_base   = (unsigned int*)( (char*)&seg_dma_base +
    829                                     (cluster_id * (unsigned)CLUSTER_SIZE) );
     879    unsigned int task_id    = _get_current_task_id();
     880    unsigned int dma_id     = _get_context_slot(task_id, CTX_DMA_ID);
     881    unsigned int cluster_id = dma_id / NB_DMAS_MAX;
     882    unsigned int loc_id     = dma_id % NB_DMAS_MAX;
     883    unsigned int * dma_base = (unsigned int *) ((char *) &seg_dma_base +
     884            (cluster_id * (unsigned) CLUSTER_SIZE));
    830885
    831886    // get page table address
    832     unsigned int        user_ptab = _get_context_slot( task_id, CTX_PTAB_ID );
     887    unsigned int user_ptab = _get_context_slot( task_id, CTX_PTAB_ID);
    833888
    834889    // get peripheral buffer virtual address
    835     if ( dev_type)  device_vaddr = (unsigned int)&seg_nic_base + offset;
    836     else            device_vaddr = (unsigned int)&seg_fbf_base + offset;
     890    if ( dev_type) {
     891        device_vaddr = (unsigned int) &seg_nic_base + offset;
     892    }
     893    else {
     894        device_vaddr = (unsigned int) &seg_fbf_base + offset;
     895    }
    837896
    838897    // get device buffer physical address
    839     ko = _v2p_translate( (page_table_t*)user_ptab,
    840                          (device_vaddr >> 12),
    841                          &ppn,
    842                          &flags );
    843     if ( ko )
    844     {
     898    ko = _v2p_translate((page_table_t *) user_ptab, (device_vaddr >> 12), &ppn, &flags);
     899    if (ko) {
    845900        _get_lock(&_tty_put_lock);
    846901        _puts("\n[GIET ERROR] in _dma_transfer : device buffer unmapped\n");
     
    851906
    852907    // Compute user buffer physical address
    853     ko = _v2p_translate( (page_table_t*)user_ptab,
    854                          (user_vaddr >> 12),
    855                          &ppn,
    856                          &flags );
    857     if ( ko )
    858     {
     908    ko = _v2p_translate( (page_table_t*)user_ptab, (user_vaddr >> 12), &ppn, &flags);
     909    if (ko) {
    859910        _get_lock(&_tty_put_lock);
    860911        _puts("\n[GIET ERROR] in _dma_transfer() : user buffer unmapped\n");
     
    862913        return 3;
    863914    }
    864     if ( (flags & PTE_U) == 0 )
    865     {
     915    if ((flags & PTE_U) == 0) {
    866916        _get_lock(&_tty_put_lock);
    867917        _puts("[GIET ERROR] in _dma_transfer() : user buffer not in user space\n");
     
    869919        return 4;
    870920    }
    871     if ( ( (flags & PTE_W) == 0 ) && to_user )
    872     {
     921    if (((flags & PTE_W) == 0 ) && to_user) {
    873922        _get_lock(&_tty_put_lock);
    874923        _puts("\n[GIET ERROR] in _dma_transfer() : user buffer not writable\n");
     
    878927    user_pbase = (ppn << 12) | (user_vaddr & 0x00000FFF);
    879928
    880 /*  This is a draft for IOMMU support
    881    
     929    /*  This is a draft for IOMMU support
     930
    882931    // loop on all virtual pages covering the user buffer
    883932    unsigned int user_vpn_min = user_vaddr >> 12;
     
    888937    for ( vpn = user_vpn_min ; vpn <= user_vpn_max ; vpn++ )
    889938    {
    890         // get ppn and flags for each vpn
    891         unsigned int ko = _v2p_translate( (page_table_t*)user_pt_vbase,
    892                                           vpn,
    893                                           &ppn,
    894                                           &flags );
    895 
    896         // check access rights
    897         if ( ko )                                 return 3;     // unmapped
    898         if ( (flags & PTE_U) == 0 )               return 4;     // not in user space
    899         if ( ( (flags & PTE_W) == 0 ) && to_user ) return 5;     // not writable
    900 
    901         // save first ppn value
    902         if ( ix2 == 0 ) ppn_first = ppn;
    903 
    904         if ( IOMMU_ACTIVE )    // the user buffer must be remapped in the I/0 space
    905         {
    906             // check buffer length < 2 Mbytes
    907             if ( ix2 > 511 ) return 2;
    908 
    909             // map the physical page in IOMMU page table
    910             _iommu_add_pte2( ix1,               // PT1 index
    911                              ix2,               // PT2 index
    912                              ppn,               // physical page number
    913                              flags );   // protection flags
    914         }
    915         else            // no IOMMU : check that physical pages are contiguous
    916         {
    917             if ( (ppn - ppn_first) != ix2 )       return 6;     // split physical buffer 
    918         }
    919 
    920         // increment page index
    921         ix2++;
     939    // get ppn and flags for each vpn
     940    unsigned int ko = _v2p_translate( (page_table_t*)user_pt_vbase,
     941    vpn,
     942    &ppn,
     943    &flags );
     944
     945    // check access rights
     946    if ( ko )                                 return 3;     // unmapped
     947    if ( (flags & PTE_U) == 0 )               return 4;     // not in user space
     948    if ( ( (flags & PTE_W) == 0 ) && to_user ) return 5;     // not writable
     949
     950    // save first ppn value
     951    if ( ix2 == 0 ) ppn_first = ppn;
     952
     953    if ( IOMMU_ACTIVE )    // the user buffer must be remapped in the I/0 space
     954    {
     955    // check buffer length < 2 Mbytes
     956    if ( ix2 > 511 ) return 2;
     957
     958    // map the physical page in IOMMU page table
     959    _iommu_add_pte2( ix1,        // PT1 index
     960    ix2,        // PT2 index
     961    ppn,        // physical page number
     962    flags );    // protection flags
     963    }
     964    else            // no IOMMU : check that physical pages are contiguous
     965    {
     966    if ( (ppn - ppn_first) != ix2 )       return 6;     // split physical buffer 
     967    }
     968
     969    // increment page index
     970    ix2++;
    922971    } // end for vpn
    923972
     
    928977
    929978    // invalidate data cache in case of memory write
    930     if ( to_user ) _dcache_buf_invalidate( (void*)user_vaddr, length );
    931    
     979    if (to_user) {
     980        _dcache_buf_invalidate((void *) user_vaddr, length);
     981    }
     982
    932983    // get the lock
    933     _get_lock( &_dma_lock[dma_id] );
     984    _get_lock(&_dma_lock[dma_id]);
    934985
    935986    // DMA configuration
    936     if ( to_user )
    937     {
    938         dma_base[loc_id*DMA_SPAN + DMA_SRC] = (unsigned int)device_pbase;
    939         dma_base[loc_id*DMA_SPAN + DMA_DST] = (unsigned int)user_pbase;
    940     }
    941     else
    942     {
    943         dma_base[loc_id*DMA_SPAN + DMA_SRC] = (unsigned int)user_pbase;
    944         dma_base[loc_id*DMA_SPAN + DMA_DST] = (unsigned int)device_pbase;
    945     }
    946     dma_base[loc_id*DMA_SPAN + DMA_LEN] = (unsigned int)length;
    947    
    948     return 0;
    949 
     987    if (to_user) {
     988        dma_base[loc_id * DMA_SPAN + DMA_SRC] = (unsigned int) device_pbase;
     989        dma_base[loc_id * DMA_SPAN + DMA_DST] = (unsigned int) user_pbase;
     990    }
     991    else {
     992        dma_base[loc_id * DMA_SPAN + DMA_SRC] = (unsigned int) user_pbase;
     993        dma_base[loc_id * DMA_SPAN + DMA_DST] = (unsigned int) device_pbase;
     994    }
     995    dma_base[loc_id * DMA_SPAN + DMA_LEN] = (unsigned int) length;
     996
     997    return 0;
    950998#else //NB_DMAS_MAX == 0
    951 
    952999    return -1;
    953 
    9541000#endif
    9551001}  // end _dma_transfer() 
     1002
    9561003
    9571004//////////////////////////////////////////////////////////////////////////////////
     
    9631010// (1 == read error / 2 == DMA idle error / 3 == write error)
    9641011//////////////////////////////////////////////////////////////////////////////////
    965 unsigned int _dma_completed()
    966 {
     1012unsigned int _dma_completed() {
    9671013#if NB_DMAS_MAX > 0
    968     unsigned int    task_id = _get_current_task_id();
    969     unsigned int    dma_id  = _get_context_slot( task_id, CTX_DMA_ID );
    970     unsigned int    dma_ret;
     1014    unsigned int task_id = _get_current_task_id();
     1015    unsigned int dma_id  = _get_context_slot(task_id, CTX_DMA_ID);
     1016    unsigned int dma_ret;
    9711017
    9721018    // busy waiting with a pseudo random delay between bus access
    973     while (_dma_done[dma_id] == 0)
    974     {
    975         unsigned int delay = (( _proctime() ^ _procid()<<4 ) & 0x3F) + 1;
    976         asm volatile("move  $3,   %0                    \n"
    977                      "loop_nic_completed:               \n"
    978                      "addi  $3, $3, -1              \n"
    979                      "bnez  $3, loop_nic_completed      \n"
    980                      "nop                                       \n"
    981                      :
    982                      : "r"(delay)
    983                      : "$3" );
    984     }
    985    
    986 /* draft support for IOMMU
     1019    while (_dma_done[dma_id] == 0) {
     1020        unsigned int delay = (( _proctime() ^ _procid() << 4) & 0x3F) + 1;
     1021        asm volatile(
     1022                "move  $3,   %0                 \n"
     1023                "loop_nic_completed:            \n"
     1024                "addi  $3,   $3, -1             \n"
     1025                "bnez  $3,   loop_nic_completed \n"
     1026                "nop                            \n"
     1027                :
     1028                : "r" (delay)
     1029                : "$3");
     1030    }
     1031
     1032    /* draft support for IOMMU
    9871033    // unmap the buffer from IOMMU page table if IOMMU is activated
    9881034    if ( GIET_IOMMU_ACTIVE )
    9891035    {
    990         unsigned int* iob_address = (unsigned int*)&seg_iob_base;
    991 
    992         unsigned int  ix1         = _dma_iommu_ix1 + dma_id;
    993         unsigned int  ix2;
    994 
    995         for ( ix2 = 0 ; ix2 < _dma_iommu_npages[dma_id] ; ix2++ )
    996         {
    997             // unmap the page in IOMMU page table
    998             _iommu_inval_pte2( ix1,             // PT1 index
    999                                ix2 );   // PT2 index
    1000 
    1001             // clear IOMMU TLB
    1002             iob_address[IOB_INVAL_PTE] = (ix1 << 21) | (ix2 << 12);
    1003         }
    1004     }
    1005 */
     1036    unsigned int* iob_address = (unsigned int*)&seg_iob_base;
     1037
     1038    unsigned int  ix1         = _dma_iommu_ix1 + dma_id;
     1039    unsigned int  ix2;
     1040
     1041    for ( ix2 = 0 ; ix2 < _dma_iommu_npages[dma_id] ; ix2++ )
     1042    {
     1043    // unmap the page in IOMMU page table
     1044    _iommu_inval_pte2( ix1,        // PT1 index
     1045    ix2 );   // PT2 index
     1046
     1047    // clear IOMMU TLB
     1048    iob_address[IOB_INVAL_PTE] = (ix1 << 21) | (ix2 << 12);
     1049    }
     1050    }
     1051    */
    10061052
    10071053    // reset synchronization variables
     
    10191065
    10201066//////////////////////////////////////////////////////////////////////////////////
    1021 //      VciFrameBuffer driver
     1067//     VciFrameBuffer driver
    10221068//////////////////////////////////////////////////////////////////////////////////
    10231069// The vci_frame_buffer device can be accessed directly by software with memcpy(),
     
    10411087// - length : number of bytes to be transfered.
    10421088//////////////////////////////////////////////////////////////////////////////////
    1043 unsigned int _fb_sync_write( unsigned int       offset,
    1044                              const void*        buffer,
    1045                              unsigned int       length )
    1046 {
    1047     unsigned char *fb_address = (unsigned char*)&seg_fbf_base + offset;
    1048     memcpy((void*)fb_address, (void*)buffer, length);
    1049     return 0;
    1050 }
     1089unsigned int _fb_sync_write(unsigned int offset, const void * buffer, unsigned int length) {
     1090    unsigned char * fb_address = (unsigned char *) &seg_fbf_base + offset;
     1091    memcpy((void *) fb_address, (void *) buffer, length);
     1092    return 0;
     1093}
     1094
    10511095
    10521096//////////////////////////////////////////////////////////////////////////////////
     
    10571101// - length : number of bytes to be transfered.
    10581102//////////////////////////////////////////////////////////////////////////////////
    1059 unsigned int _fb_sync_read( unsigned int        offset,
    1060                             const void*         buffer,
    1061                             unsigned int        length )
    1062 {
    1063     unsigned char *fb_address = (unsigned char*)&seg_fbf_base + offset;
    1064     memcpy((void*)buffer, (void*)fb_address, length);
    1065     return 0;
    1066 }
     1103unsigned int _fb_sync_read(unsigned int offset, const void * buffer, unsigned int length) {
     1104    unsigned char * fb_address = (unsigned char *) &seg_fbf_base + offset;
     1105    memcpy((void *) buffer, (void *) fb_address, length);
     1106    return 0;
     1107}
     1108
    10671109
    10681110//////////////////////////////////////////////////////////////////////////////////
     
    10741116// Returns 0 if success, > 0 if error.
    10751117//////////////////////////////////////////////////////////////////////////////////
    1076 unsigned int _fb_write( unsigned int    offset,
    1077                         const    void*  buffer,
    1078                         unsigned int    length )
    1079 {
    1080     return _dma_transfer( 0,                                            // frame buffer
    1081                           0,                                            // write
    1082                                   offset,
    1083                                   (unsigned int)buffer,
    1084                                   length );     
    1085 }
     1118unsigned int _fb_write(unsigned int offset, const void * buffer, unsigned int length) {
     1119    return _dma_transfer(
     1120            0,             // frame buffer
     1121            0,             // write
     1122            offset,
     1123            (unsigned int) buffer,
     1124            length);
     1125}
     1126
    10861127
    10871128//////////////////////////////////////////////////////////////////////////////////
     
    10931134// Returns 0 if success, > 0 if error.
    10941135//////////////////////////////////////////////////////////////////////////////////
    1095 unsigned int _fb_read( unsigned int     offset,
    1096                        const void*              buffer,
    1097                        unsigned int     length )
    1098 {
    1099     return _dma_transfer( 0,                                            // frame buffer
    1100                           1,                                            // read
    1101                                   offset,
    1102                                   (unsigned int)buffer,
    1103                                   length );     
    1104 }
     1136unsigned int _fb_read(unsigned int offset, const void * buffer, unsigned int length) {
     1137    return _dma_transfer(
     1138            0,    // frame buffer
     1139            1,    // read
     1140            offset,
     1141            (unsigned int) buffer,
     1142            length);
     1143}
     1144
    11051145
    11061146//////////////////////////////////////////////////////////////////////////////////
     
    11111151// (1 == read error / 2 == DMA idle error / 3 == write error)
    11121152//////////////////////////////////////////////////////////////////////////////////
    1113 unsigned int _fb_completed()
    1114 {
     1153unsigned int _fb_completed() {
    11151154    return _dma_completed();
    11161155}
    11171156
    11181157//////////////////////////////////////////////////////////////////////////////////
    1119 //      VciMultiNic driver
     1158//     VciMultiNic driver
    11201159//////////////////////////////////////////////////////////////////////////////////
    11211160// The VciMultiNic device can be accessed directly by software with memcpy(),
     
    11391178// - length : number of bytes to be transfered.
    11401179//////////////////////////////////////////////////////////////////////////////////
    1141 unsigned int _nic_sync_write( unsigned int      offset,
    1142                               const void*       buffer,
    1143                               unsigned int      length )
    1144 {
    1145     unsigned char *nic_address = (unsigned char*)&seg_nic_base + offset;
    1146     memcpy((void*)nic_address, (void*)buffer, length);
    1147     return 0;
    1148 }
     1180unsigned int _nic_sync_write(unsigned int offset, const void * buffer, unsigned int length) {
     1181    unsigned char * nic_address = (unsigned char *) &seg_nic_base + offset;
     1182    memcpy((void *) nic_address, (void *) buffer, length);
     1183    return 0;
     1184}
     1185
    11491186
    11501187//////////////////////////////////////////////////////////////////////////////////
     
    11551192// - length : number of bytes to be transfered.
    11561193//////////////////////////////////////////////////////////////////////////////////
    1157 unsigned int _nic_sync_read( unsigned int       offset,
    1158                              const void*        buffer,
    1159                              unsigned int       length )
    1160 {
    1161     unsigned char *nic_address = (unsigned char*)&seg_nic_base + offset;
    1162     memcpy((void*)buffer, (void*)nic_address, length);
    1163     return 0;
    1164 }
     1194unsigned int _nic_sync_read(unsigned int offset, const void * buffer, unsigned int length) {
     1195    unsigned char *nic_address = (unsigned char *) &seg_nic_base + offset;
     1196    memcpy((void *) buffer, (void *) nic_address, length);
     1197    return 0;
     1198}
     1199
    11651200
    11661201//////////////////////////////////////////////////////////////////////////////////
     
    11721207// Returns 0 if success, > 0 if error.
    11731208//////////////////////////////////////////////////////////////////////////////////
    1174 unsigned int _nic_write( unsigned int   offset,
    1175                          const void*    buffer,
    1176                          unsigned int   length )
    1177 {
    1178     return _dma_transfer( 1,            // NIC
    1179                           0,                    // write
    1180                                       offset,
    1181                                       (unsigned int)buffer,
    1182                                       length );
    1183 }
     1209unsigned int _nic_write(unsigned int offset, const void * buffer, unsigned int length) {
     1210    return _dma_transfer(
     1211            1,            // NIC
     1212            0,            // write
     1213            offset,
     1214            (unsigned int) buffer,
     1215            length );   
     1216}
     1217
    11841218
    11851219//////////////////////////////////////////////////////////////////////////////////
     
    11911225// Returns 0 if success, > 0 if error.
    11921226//////////////////////////////////////////////////////////////////////////////////
    1193 unsigned int _nic_read( unsigned int    offset,
    1194                         const void*             buffer,
    1195                         unsigned int    length )
    1196 {
    1197     return _dma_transfer( 1,            // NIC
    1198                           1,                    // read
    1199                           offset,
    1200                                       (unsigned int)buffer,
    1201                                       length );
    1202 }
     1227unsigned int _nic_read(unsigned int offset, const void * buffer, unsigned int length) {
     1228    return _dma_transfer(
     1229            1,            // NIC
     1230            1,            // read
     1231            offset,
     1232            (unsigned int) buffer,
     1233            length );   
     1234}
     1235
    12031236
    12041237//////////////////////////////////////////////////////////////////////////////////
     
    12091242// (1 == read error / 2 == DMA idle error / 3 == write error)
    12101243//////////////////////////////////////////////////////////////////////////////////
    1211 unsigned int _nic_completed()
    1212 {
     1244unsigned int _nic_completed() {
    12131245    return _dma_completed();
    12141246}
    12151247
     1248// Local Variables:
     1249// tab-width: 4
     1250// c-basic-offset: 4
     1251// c-file-offsets:((innamespace . 0)(inline-open . 0))
     1252// indent-tabs-mode: nil
     1253// End:
     1254// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
     1255
  • soft/giet_vm/sys/drivers.h

    r218 r228  
    1616extern volatile unsigned char _timer_event[];
    1717
    18 unsigned int _timer_start( unsigned int cluster_id,
    19                            unsigned int local_id,
    20                            unsigned int period );
     18unsigned int _timer_start(unsigned int cluster_id, unsigned int local_id, unsigned int period);
     19unsigned int _timer_stop(unsigned int cluster_id, unsigned int local_id);
     20unsigned int _timer_reset_irq(unsigned int cluster_id, unsigned int local_id);
     21unsigned int _timer_reset_irq_cpt(unsigned int cluster_id, unsigned int local_id);
    2122
    22 unsigned int _timer_stop(  unsigned int cluster_id,
    23                            unsigned int local_id );
    24 
    25 
    26 unsigned int _timer_reset_irq( unsigned int     cluster_id,
    27                                unsigned int local_id );
    2823
    2924///////////////////////////////////////////////////////////////////////////////////
     
    3328extern volatile unsigned char _tty_get_buf[];
    3429extern volatile unsigned char _tty_get_full[];
    35 extern unsigned int           _tty_put_lock;
     30extern unsigned int _tty_put_lock;
    3631
    37 unsigned int _tty_write(    const char*         buffer,
    38                             unsigned int        length);
    39 
    40 unsigned int _tty_read(     char*                       buffer,
    41                             unsigned int        length);
    42 
    43 unsigned int _tty_get_char( unsigned int        tty_id,
    44                             unsigned char*      buffer);
     32unsigned int _tty_write(const char * buffer, unsigned int length);
     33unsigned int _tty_read(char * buffer, unsigned int length);
     34unsigned int _tty_get_char(unsigned int tty_id, unsigned char * buffer);
    4535
    4636///////////////////////////////////////////////////////////////////////////////////
     
    4838///////////////////////////////////////////////////////////////////////////////////
    4939
    50 unsigned int _icu_get_index(unsigned int        cluster_id,
    51                             unsigned int        proc_id,
    52                             unsigned int*       buffer );
    53 
    54 unsigned int _icu_set_mask( unsigned int        cluster_id,
    55                                                         unsigned int    proc_id,
    56                                                         unsigned int    mask,
    57                                                         unsigned int    is_timer );
     40unsigned int _icu_get_index(unsigned int cluster_id, unsigned int proc_id, unsigned int * buffer);
     41unsigned int _icu_set_mask(
     42        unsigned int cluster_id,
     43        unsigned int proc_id,
     44        unsigned int mask,
     45        unsigned int is_timer);
    5846
    5947///////////////////////////////////////////////////////////////////////////////////
     
    6149///////////////////////////////////////////////////////////////////////////////////
    6250
    63 extern volatile unsigned int    _ioc_status;
    64 extern volatile unsigned int    _ioc_done;
    65 extern unsigned int                             _ioc_lock;
    66 extern unsigned int                             _ioc_iommu_ix1;
    67 extern unsigned int                             _ioc_iommu_npages;
     51extern volatile unsigned int _ioc_status;
     52extern volatile unsigned int _ioc_done;
     53extern unsigned int _ioc_lock;
     54extern unsigned int _ioc_iommu_ix1;
     55extern unsigned int _ioc_iommu_npages;
    6856
    6957
    70 unsigned int _ioc_write(    unsigned int        lba,
    71                             const void*         buffer,
    72                             unsigned int        count);
    73 
    74 unsigned int _ioc_read(     unsigned int        lba,
    75                             void*                       buffer,
    76                             unsigned int        count);
    77 
     58unsigned int _ioc_write(unsigned int lba, const void * buffer, unsigned int count);
     59unsigned int _ioc_read(unsigned int lba, void * buffer, unsigned int count);
    7860unsigned int _ioc_completed();
    79 
    80 unsigned int _ioc_get_status( unsigned int* status);
     61unsigned int _ioc_get_status(unsigned int * status);
    8162
    8263///////////////////////////////////////////////////////////////////////////////////
    83 // Multi DMA variables                  (vci_multi_dma)
     64// Multi DMA variables            (vci_multi_dma)
    8465///////////////////////////////////////////////////////////////////////////////////
    85  
    86 extern volatile unsigned int    _dma_status[];
    87 extern volatile unsigned int    _dma_done[];
    88 extern unsigned int                             _dma_lock[];
    89 extern unsigned int                             _dma_iommu_ix1;
    90 extern unsigned int                             _dma_iommu_npages[];
    9166
    92 unsigned int _dma_reset_irq( unsigned int       cluster_id,
    93                              unsigned int       local_id );
     67extern volatile unsigned int _dma_status[];
     68extern volatile unsigned int _dma_done[];
     69extern unsigned int _dma_lock[];
     70extern unsigned int _dma_iommu_ix1;
     71extern unsigned int _dma_iommu_npages[];
    9472
    95 unsigned int _dma_get_status( unsigned int      cluster_id,
    96                               unsigned int      local_id,
    97                               unsigned int*     status );
     73unsigned int _dma_reset_irq(unsigned int cluster_id, unsigned int local_id);
     74unsigned int _dma_get_status(unsigned int cluster_id, unsigned int local_id, unsigned int * status);
    9875
    99 unsigned int _dma_transfer(   unsigned int  dev_type,
    100                               unsigned int  to_user,
    101                               unsigned int  offset,
    102                               unsigned int  user_vaddr,
    103                               unsigned int  length );
     76unsigned int _dma_transfer(
     77        unsigned int dev_type,
     78        unsigned int to_user,
     79        unsigned int offset,
     80        unsigned int user_vaddr,
     81        unsigned int length);
    10482
    10583unsigned int _dma_completed();
     
    10886// Frame Buffer access functions  (vci_frame_buffer)
    10987///////////////////////////////////////////////////////////////////////////////////
    110  
    111 unsigned int _fb_sync_write(unsigned int        offset,
    112                             const void*         buffer,
    113                             unsigned int        length);
    11488
    115 unsigned int _fb_sync_read( unsigned int        offset,
    116                             const void*         buffer,
    117                             unsigned int        length);
    118 
    119 unsigned int _fb_write(     unsigned int        offset,
    120                             const void*         buffer,
    121                             unsigned int        length);
    122 
    123 unsigned int _fb_read(      unsigned int        offset,
    124                             const void*         buffer,
    125                             unsigned int        length);
     89unsigned int _fb_sync_write(unsigned int offset, const void * buffer, unsigned int length);
     90unsigned int _fb_sync_read( unsigned int offset, const void * buffer, unsigned int length);
     91unsigned int _fb_write(     unsigned int offset, const void * buffer, unsigned int length);
     92unsigned int _fb_read(      unsigned int offset, const void * buffer, unsigned int length);
    12693
    12794unsigned int _fb_completed();
     
    13198///////////////////////////////////////////////////////////////////////////////////
    13299
    133 unsigned int _nic_sync_write(unsigned int       offset,
    134                             const void*         buffer,
    135                             unsigned int        length);
    136 
    137 unsigned int _nic_sync_read( unsigned int       offset,
    138                             const void*         buffer,
    139                             unsigned int        length);
    140 
    141 
    142 unsigned int _nic_write(    unsigned int        offset,
    143                                         const void*             buffer,
    144                                         unsigned int    length);
    145 
    146 unsigned int _nic_read(     unsigned int        offset,
    147                                         const void*             buffer,
    148                                         unsigned int    length);
     100unsigned int _nic_sync_write(unsigned int offset, const void * buffer, unsigned int length);
     101unsigned int _nic_sync_read( unsigned int offset, const void * buffer, unsigned int length);
     102unsigned int _nic_write(     unsigned int offset, const void * buffer, unsigned int length);
     103unsigned int _nic_read(      unsigned int offset, const void * buffer, unsigned int length);
    149104
    150105unsigned int _nic_completed();
     
    154109///////////////////////////////////////////////////////////////////////////////////
    155110
    156 unsigned int _gcd_write(    unsigned int        register_index,
    157                             unsigned int        value);
    158 
    159 unsigned int _gcd_read(     unsigned int        register_index,
    160                             unsigned int*       buffer);
     111unsigned int _gcd_write(unsigned int register_index, unsigned int   value);
     112unsigned int _gcd_read( unsigned int register_index, unsigned int * buffer);
    161113
    162114
    163115#endif
    164116
     117// Local Variables:
     118// tab-width: 4
     119// c-basic-offset: 4
     120// c-file-offsets:((innamespace . 0)(inline-open . 0))
     121// indent-tabs-mode: nil
     122// End:
     123// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
     124
  • soft/giet_vm/sys/exc_handler.c

    r218 r228  
    5454};
    5555
    56 static const char* exc_type[] = {
     56static const char * exc_type[] = {
    5757    "strange unknown cause",
    5858    "illegal read address",
     
    6262    "breakpoint",
    6363    "reserved instruction",
    64     "illegal coproc access"
     64    "illegal coproc access",
    6565    "arithmetic overflow",
    6666};
    6767
    68 static void _display_cause(unsigned int type)
    69 {
     68
     69static void _display_cause(unsigned int type) {
    7070    _get_lock(&_tty_put_lock);
    7171    _puts("\n[GIET] Exception for task ");
    72     _putd( _get_current_task_id() );
     72    _putd(_get_current_task_id());
    7373    _puts(" on processor ");
    74     _putd( _procid() );
     74    _putd(_procid());
    7575    _puts(" at cycle ");
    76     _putd( _proctime() );
     76    _putd(_proctime());
    7777    _puts("\n - type      : ");
    78     _puts( (char*)exc_type[type] );
     78    _puts((char *) exc_type[type]);
    7979    _puts("\n - EPC       : ");
    80     _putx( _get_epc() );
     80    _putx(_get_epc());
    8181    _puts("\n - BVAR      : ");
    82     _putx( _get_bvar() );
     82    _putx(_get_bvar());
    8383    _puts("\n");
    8484    _puts("...Task desactivated\n");
     
    8787    // goes to sleeping state
    8888    unsigned int task_id = _get_current_task_id();
    89     _set_context_slot( task_id, CTX_RUN_ID, 0 );
    90    
     89    _set_context_slot( task_id, CTX_RUN_ID, 0);
     90
    9191    // deschedule
    9292    _ctx_switch();
     
    103103static void _cause_ovf()  { _display_cause(8); }
    104104
     105// Local Variables:
     106// tab-width: 4
     107// c-basic-offset: 4
     108// c-file-offsets:((innamespace . 0)(inline-open . 0))
     109// indent-tabs-mode: nil
     110// End:
     111// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
     112
  • soft/giet_vm/sys/hwr_mapping.h

    r209 r228  
    9090
    9191#define XICU_REG(func, index) (((func)<<5)|(index))
    92        
     92
    9393/* TIMER */
    9494enum TIMER_registers {
     
    113113/* IOB */
    114114enum IOB_registers {
    115     IOB_IOMMU_PTPR       = 0,   /* R/W : Page Table Pointer Register */
    116     IOB_IOMMU_ACTIVE     = 1,   /* R/W : IOMMU activated if not 0 */
    117     IOB_IOMMU_BVAR       = 2,   /* R   : Bad Virtual Address (unmapped) */
    118     IOB_IOMMU_ETR        = 3,   /* R   : Error Type */
    119     IOB_IOMMU_BAD_ID     = 4,   /* R   : Faulty Peripheral Index */
    120     IOB_INVAL_PTE        = 5,   /* W   : Invalidate a PTE (virtual address) */
    121     IOB_IT_ADDR_IOMMU_LO = 6,   /* W/R : 32 LSB bits for IOMMU IT*/
    122     IOB_IT_ADDR_IOMMU_HI = 7,   /* W/R : 32 MSB bits for IOMMU IT */
    123     IOB_IT_ADDRESS_BEGIN = 8,   /* R/W : Peripheral IT address (2 32 bits registers) */
     115    IOB_IOMMU_PTPR       = 0, /* R/W : Page Table Pointer Register */
     116    IOB_IOMMU_ACTIVE     = 1, /* R/W : IOMMU activated if not 0 */
     117    IOB_IOMMU_BVAR       = 2, /* R   : Bad Virtual Address (unmapped) */
     118    IOB_IOMMU_ETR        = 3, /* R   : Error Type */
     119    IOB_IOMMU_BAD_ID     = 4, /* R   : Faulty Peripheral Index */
     120    IOB_INVAL_PTE        = 5, /* W   : Invalidate a PTE (virtual address) */
     121    IOB_IT_ADDR_IOMMU_LO = 6, /* W/R : 32 LSB bits for IOMMU IT*/
     122    IOB_IT_ADDR_IOMMU_HI = 7, /* W/R : 32 MSB bits for IOMMU IT */
     123    IOB_IT_ADDRESS_BEGIN = 8, /* R/W : Peripheral IT address (2 32 bits registers) */
    124124};
    125125
     
    145145#endif
    146146
     147// Local Variables:
     148// tab-width: 4
     149// c-basic-offset: 4
     150// c-file-offsets:((innamespace . 0)(inline-open . 0))
     151// indent-tabs-mode: nil
     152// End:
     153// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
     154
  • soft/giet_vm/sys/irq_handler.c

    r216 r228  
    2020
    2121#if NB_TIMERS_MAX
    22 extern volatile unsigned char _user_timer_event[NB_CLUSTERS*NB_TIMERS_MAX] ;
     22extern volatile unsigned char _user_timer_event[NB_CLUSTERS * NB_TIMERS_MAX] ;
    2323#endif
    2424
    2525///////////////////////////////////////////////////////////////////////////////////
    26 //      _irq_demux()
     26//     _irq_demux()
    2727// This function uses the ICU or XICU component (Interrupt Controler Unit)
    2828// to get the interrupt vector entry. There is one ICU or XICU component per
     
    4040// a global index : channel_id = cluster_id * NB_CHANNELS_MAX + loc_id   
    4141///////////////////////////////////////////////////////////////////////////////////
    42 void _irq_demux()
    43 {
    44     unsigned int    pid = _procid();
    45     unsigned int        irq_id;
     42void _irq_demux() {
     43    unsigned int pid = _procid();
     44    unsigned int irq_id;
    4645
    4746
    4847    // get the highest priority active IRQ index
    49     if ( _icu_get_index( pid / NB_PROCS_MAX,
    50                          pid % NB_PROCS_MAX,
    51                          &irq_id ) )
    52     {
     48    if (_icu_get_index( pid / NB_PROCS_MAX, pid % NB_PROCS_MAX, &irq_id)) {
    5349        _get_lock(&_tty_put_lock);
    5450        _puts("\n[GIET ERROR] Strange... Wrong _icu_read in _irq_demux()\n");
     
    5753
    5854
    59     if ( irq_id < 32 )  // do nothing if no interrupt active
    60     {
    61         unsigned int entry      = _get_interrupt_vector_entry(irq_id);
    62         unsigned int isr_id     = entry & 0x000000FF;
    63         unsigned int channel_id = (entry>>16) & 0x0000FFFF;
    64         if      ( isr_id == ISR_SWITCH  ) _isr_switch( channel_id );
    65         else if ( isr_id == ISR_IOC     ) _isr_ioc();
    66         else if ( isr_id == ISR_DMA     ) _isr_dma( channel_id );
    67         else if ( isr_id == ISR_TTY     ) _isr_tty( channel_id );
    68         else if ( isr_id == ISR_TIMER   ) _isr_timer( channel_id );
    69         else                              _isr_default();
    70     }
    71 }
    72 ///////////////////////////////////////////////////////////////////////////////////
    73 //      _isr_default()
     55    if (irq_id < 32) {
     56        // do nothing if no interrupt active
     57        unsigned int entry = _get_interrupt_vector_entry(irq_id);
     58        unsigned int isr_id = entry & 0x000000FF;
     59        unsigned int channel_id = (entry >> 16) & 0x0000FFFF;
     60        if      ( isr_id == ISR_SWITCH) _isr_switch( channel_id);
     61        else if ( isr_id == ISR_IOC   ) _isr_ioc();
     62        else if ( isr_id == ISR_DMA   ) _isr_dma(channel_id);
     63        else if ( isr_id == ISR_TTY   ) _isr_tty(channel_id);
     64        else if ( isr_id == ISR_TIMER ) _isr_timer(channel_id);
     65        else                            _isr_default();
     66    }
     67}
     68
     69
     70///////////////////////////////////////////////////////////////////////////////////
     71//     _isr_default()
    7472// The default ISR is called when no specific ISR has been installed in the
    7573// interrupt vector. It simply displays an error message on kernel TTY[0].
    7674///////////////////////////////////////////////////////////////////////////////////
    77 void _isr_default()
    78 {
     75void _isr_default() {
    7976    _get_lock(&_tty_put_lock);
    8077    _puts("\n[GIET ERROR] Strange... Default ISR activated for processor ");
     
    8481}
    8582
    86 ///////////////////////////////////////////////////////////////////////////////////
    87 //      _isr_dma()
     83
     84///////////////////////////////////////////////////////////////////////////////////
     85//     _isr_dma()
    8886// This ISR handles all IRQs generated by the multi-channels DMA controlers.
    8987// The multi_dma components can be distributed in the clusters.
     
    9492// - it resets the synchronisation variable _dma_busy[dma_global_id].
    9593///////////////////////////////////////////////////////////////////////////////////
    96 void _isr_dma( unsigned int channel_id )
    97 {
     94void _isr_dma(unsigned int channel_id) {
    9895#if NB_DMAS_MAX > 0
    9996    // compute cluster_id
    100     unsigned int cluster_id = _procid()/NB_PROCS_MAX;
     97    unsigned int cluster_id = _procid() / NB_PROCS_MAX;
    10198
    10299    // compute dma_global_id
    103     unsigned int dma_global_id = cluster_id*NB_DMAS_MAX + channel_id;
     100    unsigned int dma_global_id = cluster_id * NB_DMAS_MAX + channel_id;
    104101
    105102    // save DMA channel status 
    106     if ( _dma_get_status(cluster_id,
    107                          channel_id,
    108                          (unsigned int*)&_dma_status[dma_global_id] ) )
    109     {
     103    if (_dma_get_status(cluster_id, channel_id,
     104            (unsigned int *) &_dma_status[dma_global_id])) {
    110105        _get_lock(&_tty_put_lock);
    111106        _puts("[GIET ERROR] illegal DMA channel detected by _isr_dma\n");
     
    115110
    116111    // reset DMA channel irq
    117     if ( _dma_reset_irq( cluster_id,
    118                          channel_id) )
    119     {
     112    if (_dma_reset_irq(cluster_id, channel_id)) {
    120113        _get_lock(&_tty_put_lock);
    121114        _puts("[GIET ERROR] illegal DMA channel detected by _isr_dma\n");
     
    133126
    134127///////////////////////////////////////////////////////////////////////////////////
    135 //      _isr_ioc()
     128//     _isr_ioc()
    136129// There is only one IOC controler shared by all tasks.
    137130// - The ISR save the status and acknowledge the IRQ.
    138131// - It sets the _ioc_done variable to signal completion.
    139132///////////////////////////////////////////////////////////////////////////////////
    140 void _isr_ioc()
    141 {
    142      // save status & reset IRQ
    143     if ( _ioc_get_status( (unsigned int*)&_ioc_status ) )
    144     {
     133void _isr_ioc() {
     134    // save status & reset IRQ
     135    if (_ioc_get_status((unsigned int *) &_ioc_status )) {
    145136        _get_lock(&_tty_put_lock);
    146137        _puts("[GIET ERROR] bad access to IOC status detected by _isr_ioc\n");
     
    150141
    151142    // signals completion
    152     _ioc_done   = 1;
    153 }
    154 
    155 ///////////////////////////////////////////////////////////////////////////////////
    156 //         _isr_timer()
     143    _ioc_done = 1;
     144}
     145
     146
     147///////////////////////////////////////////////////////////////////////////////////
     148//        _isr_timer()
    157149// This ISR handles the IRQs generated by the "user" timers (the IRQs generated
    158150// by the "system" timers should be handled by the _isr_switch().
     
    164156// of the _timer_event[] array, and a log message is displayed on kernel terminal.
    165157///////////////////////////////////////////////////////////////////////////////////
    166 void _isr_timer(unsigned int timer_id)
    167 {
     158void _isr_timer(unsigned int timer_id) {
    168159    // compute cluster_id
    169     unsigned int cluster_id = _procid()/NB_PROCS_MAX;
     160    unsigned int cluster_id = _procid() / NB_PROCS_MAX;
    170161
    171162    // aknowledge IRQ
    172     if ( _timer_reset_irq( cluster_id,
    173                            timer_id ) )
    174     {
     163    if (_timer_reset_irq( cluster_id, timer_id)) {
    175164        _get_lock(&_tty_put_lock);
    176165        _puts("[GIET ERROR] illegal timer index detected by _isr_timer\n");
     
    181170#if NB_TIMERS_MAX
    182171    // register the event
    183     unsigned int timer_global_id = cluster_id*NB_TIMERS_MAX + timer_id;
     172    unsigned int timer_global_id = cluster_id * NB_TIMERS_MAX + timer_id;
    184173    _user_timer_event[timer_global_id] = 1;
    185174#endif
     
    188177    _get_lock(&_tty_put_lock);
    189178    _puts("\n[GIET] User Timer IRQ at cycle ");
    190     _putd( _proctime() );
     179    _putd(_proctime());
    191180    _puts("\n - cluster_id = ");
    192     _putd( cluster_id );
     181    _putd(cluster_id);
    193182    _puts("\n - timer_id   = ");
    194     _putd( timer_id );
     183    _putd(timer_id);
    195184    _puts("\n");
    196185    _release_lock(&_tty_put_lock);
    197186}
     187
    198188
    199189///////////////////////////////////////////////////////////////////////////////////
     
    208198// A character is lost if the buffer is full when the ISR is executed.
    209199///////////////////////////////////////////////////////////////////////////////////
    210 void _isr_tty(unsigned int tty_id)
    211 {
     200void _isr_tty(unsigned int tty_id) {
    212201    // save character and reset IRQ
    213     if ( _tty_get_char( tty_id,
    214                         (unsigned char*)&_tty_get_buf[tty_id] ) )
    215     {
     202    if (_tty_get_char( tty_id, (unsigned char *) &_tty_get_buf[tty_id])) {
    216203        _get_lock(&_tty_put_lock);
    217204        _puts("[GIET ERROR] illegal tty index detected by _isr_tty\n");
     
    223210    _tty_get_full[tty_id] = 1;
    224211}
     212
    225213
    226214/////////////////////////////////////////////////////////////////////////////////////
     
    232220// The ISR acknowledges the IRQ and calls the _ctx_switch() function.
    233221/////////////////////////////////////////////////////////////////////////////////////
    234 void _isr_switch( unsigned int timer_id)
    235 {
     222void _isr_switch( unsigned int timer_id) {
    236223    // get cluster index and proc local index
    237224    unsigned int cluster_id = _procid() / NB_PROCS_MAX;
    238225
    239226    // acknowledge IRQ
    240     if ( _timer_reset_irq( cluster_id, timer_id ) )
    241     {
     227    if (_timer_reset_irq(cluster_id, timer_id)) {
    242228        _get_lock(&_tty_put_lock);
    243229        _puts("[GIET ERROR] illegal proc index detected by _isr_switch\n");
     
    250236}
    251237
     238
     239// Local Variables:
     240// tab-width: 4
     241// c-basic-offset: 4
     242// c-file-offsets:((innamespace . 0)(inline-open . 0))
     243// indent-tabs-mode: nil
     244// End:
     245// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
     246
  • soft/giet_vm/sys/irq_handler.h

    r189 r228  
    2121void _isr_default();
    2222void _isr_ioc();
    23 void _isr_timer( unsigned int channel );
    24 void _isr_dma( unsigned int channel );
    25 void _isr_tty( unsigned int channel );
     23void _isr_timer(unsigned int channel);
     24void _isr_dma(unsigned int channel);
     25void _isr_tty(unsigned int channel);
    2626void _isr_switch();
    2727
    2828#endif
     29
     30// Local Variables:
     31// tab-width: 4
     32// c-basic-offset: 4
     33// c-file-offsets:((innamespace . 0)(inline-open . 0))
     34// indent-tabs-mode: nil
     35// End:
     36// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
     37
  • soft/giet_vm/sys/kernel_init.c

    r220 r228  
    3737
    3838__attribute__((section (".kdata")))
    39 unsigned int                    _ptabs_paddr[GIET_NB_VSPACE_MAX];
    40 
    41 __attribute__((section (".kdata")))
    42 unsigned int                    _ptabs_vaddr[GIET_NB_VSPACE_MAX];
     39unsigned int _ptabs_paddr[GIET_NB_VSPACE_MAX];
     40
     41__attribute__((section (".kdata")))
     42unsigned int _ptabs_vaddr[GIET_NB_VSPACE_MAX];
    4343
    4444///////////////////////////////////////////////////////////////////////////////////
     
    4747
    4848__attribute__((section (".kdata")))
    49 static_scheduler_t*             _schedulers_paddr[NB_CLUSTERS*NB_PROCS_MAX];
     49static_scheduler_t * _schedulers_paddr[NB_CLUSTERS * NB_PROCS_MAX];
    5050
    5151///////////////////////////////////////////////////////////////////////////////////
     
    5454
    5555__attribute__((section (".kdata")))
    56 unsigned int                    _idle_stack[NB_CLUSTERS*NB_PROCS_MAX*64];
    57 
    58 void _sys_exit()
    59 {
    60     while(1);
     56unsigned int _idle_stack[NB_CLUSTERS*NB_PROCS_MAX * 64];
     57
     58void _sys_exit() {
     59    while (1);
    6160}
     61
    6262
    6363//////////////////////////////////////////////////////////////////////////////////
    6464// This function is the entry point for the last step of the boot sequence.
    6565//////////////////////////////////////////////////////////////////////////////////
    66 __attribute__((section (".kinit"))) void _kernel_init()
    67 {
     66__attribute__((section (".kinit"))) void _kernel_init() {
    6867    // compute cluster and local processor index
    69     unsigned int        global_pid = _procid();
    70     unsigned int    cluster_id = global_pid / NB_PROCS_MAX;
    71     unsigned int    proc_id    = global_pid % NB_PROCS_MAX;
     68    unsigned int global_pid = _procid();
     69    unsigned int cluster_id = global_pid / NB_PROCS_MAX;
     70    unsigned int proc_id = global_pid % NB_PROCS_MAX;
    7271
    7372    // Step 0 : Compute number of tasks allocated to proc
     
    7675
    7776#if GIET_DEBUG_INIT
    78 _get_lock(&_tty_put_lock);
    79 _puts("\n[GIET DEBUG] step 0 for processor ");
    80 _putd( global_pid );
    81 _puts(" : tasks = ");
    82 _putd( tasks );
    83 _puts("\n");
    84 _release_lock(&_tty_put_lock);
     77    _get_lock(&_tty_put_lock);
     78    _puts("\n[GIET DEBUG] step 0 for processor ");
     79    _putd(global_pid);
     80    _puts(" : tasks = ");
     81    _putd(tasks);
     82    _puts("\n");
     83    _release_lock(&_tty_put_lock);
    8584#endif
    8685
     
    8887    //          get scheduler physical address (from CP0 register)
    8988
    90     static_scheduler_t*         psched = (static_scheduler_t*)_get_sched();
    91     _schedulers_paddr[global_pid]  = psched;
    92 
    93 #if GIET_DEBUG_INIT
    94 _get_lock(&_tty_put_lock);
    95 _puts("\n[GIET DEBUG] step 1 for processor ");
    96 _putd( global_pid );
    97 _puts(" / scheduler pbase = ");
    98 _putx( (unsigned int)psched );
    99 _puts("\n");
    100 _release_lock(&_tty_put_lock);
     89    static_scheduler_t * psched = (static_scheduler_t *) _get_sched();
     90    _schedulers_paddr[global_pid] = psched;
     91
     92#if GIET_DEBUG_INIT
     93    _get_lock(&_tty_put_lock);
     94    _puts("\n[GIET DEBUG] step 1 for processor ");
     95    _putd(global_pid);
     96    _puts(" / scheduler pbase = ");
     97    _putx((unsigned int) psched);
     98    _puts("\n");
     99    _release_lock(&_tty_put_lock);
    101100#endif
    102101
     
    107106    unsigned int ltid;
    108107
    109     for ( ltid = 0 ; ltid < tasks ; ltid++ )
    110     {
    111         unsigned int vspace_id  = _get_context_slot( ltid , CTX_VSID_ID );
    112         unsigned int ptab_vaddr = _get_context_slot( ltid , CTX_PTAB_ID );
    113         unsigned int ptab_paddr = _get_context_slot( ltid , CTX_PTPR_ID ) << 13;
     108    for (ltid = 0; ltid < tasks; ltid++) {
     109        unsigned int vspace_id = _get_context_slot(ltid , CTX_VSID_ID);
     110        unsigned int ptab_vaddr = _get_context_slot(ltid , CTX_PTAB_ID);
     111        unsigned int ptab_paddr = _get_context_slot(ltid , CTX_PTPR_ID) << 13;
    114112
    115113        _ptabs_vaddr[vspace_id] = ptab_vaddr;
     
    117115
    118116#if GIET_DEBUG_INIT
    119 _get_lock(&_tty_put_lock);
    120 _puts("\n[GIET DEBUG] step 2 for processor ");
    121 _putd( global_pid );
    122 _puts(" / vspace ");
    123 _putd( vspace_id );
    124 _puts("\n- ptab vbase = ");
    125 _putx( ptab_vaddr );
    126 _puts("\n- ptab pbase = ");
    127 _putx( ptab_paddr );
    128 _puts("\n");
    129 _release_lock(&_tty_put_lock);
    130 #endif
    131 
    132     }
    133  
     117        _get_lock(&_tty_put_lock);
     118        _puts("\n[GIET DEBUG] step 2 for processor ");
     119        _putd(global_pid);
     120        _puts(" / vspace ");
     121        _putd(vspace_id);
     122        _puts("\n- ptab vbase = ");
     123        _putx(ptab_vaddr);
     124        _puts("\n- ptab pbase = ");
     125        _putx(ptab_paddr);
     126        _puts("\n");
     127        _release_lock(&_tty_put_lock);
     128#endif
     129
     130    }
     131
    134132    unsigned int isr_switch_channel = 0xFFFFFFFF;
    135133
     
    142140    unsigned int pti_mask = 0;
    143141
    144     for ( irq_id = 0 ; irq_id < 32 ; irq_id++ )
    145     {
    146         unsigned int entry  = _get_interrupt_vector_entry(irq_id);
    147         unsigned int isr    = entry & 0x000000FF;
    148 
    149         if ( (isr == ISR_DMA) || (isr == ISR_IOC) || (isr == ISR_TTY) )
    150         {
    151              hwi_mask = hwi_mask | 0x1<< irq_id;
    152         }
    153         else if ( (isr == ISR_SWITCH) )
    154         {
    155             pti_mask = pti_mask | 0x1<< irq_id;
     142    for (irq_id = 0; irq_id < 32; irq_id++) {
     143        unsigned int entry = _get_interrupt_vector_entry(irq_id);
     144        unsigned int isr = entry & 0x000000FF;
     145
     146        if ((isr == ISR_DMA) || (isr == ISR_IOC) || (isr == ISR_TTY)) {
     147            hwi_mask = hwi_mask | 0x1 << irq_id;
     148        }
     149        else if ((isr == ISR_SWITCH)) {
     150            pti_mask = pti_mask | 0x1 << irq_id;
    156151            isr_switch_channel = irq_id;
    157152        }
    158         else if ( (isr == ISR_TIMER) )
    159         {
    160             pti_mask = pti_mask | 0x1<< irq_id;
    161         }
    162     }
    163     _icu_set_mask( cluster_id, proc_id, hwi_mask, 0 ); // set HWI_MASK
    164     _icu_set_mask( cluster_id, proc_id, pti_mask, 1 );  // set PTI_MASK
    165    
    166 #if GIET_DEBUG_INIT
    167 _get_lock(&_tty_put_lock);
    168 _puts("\n[GIET DEBUG] step 3 for processor ");
    169 _putd( global_pid );
    170 _puts("\n - ICU HWI_MASK = ");
    171 _putx( hwi_mask );
    172 _puts("\n - ICU PTI_MASK = ");
    173 _putx( pti_mask );
    174 _puts("\n");
    175 _release_lock(&_tty_put_lock);
     153        else if ((isr == ISR_TIMER)) {
     154            pti_mask = pti_mask | 0x1 << irq_id;
     155        }
     156    }
     157    _icu_set_mask(cluster_id, proc_id, hwi_mask, 0); // set HWI_MASK
     158    _icu_set_mask(cluster_id, proc_id, pti_mask, 1); // set PTI_MASK
     159
     160#if GIET_DEBUG_INIT
     161    _get_lock(&_tty_put_lock);
     162    _puts("\n[GIET DEBUG] step 3 for processor ");
     163    _putd(global_pid);
     164    _puts("\n - ICU HWI_MASK = ");
     165    _putx(hwi_mask);
     166    _puts("\n - ICU PTI_MASK = ");
     167    _putx(pti_mask);
     168    _puts("\n");
     169    _release_lock(&_tty_put_lock);
    176170#endif
    177171
    178172    // step 4 : start TICK timer if more than one task
    179     if ( tasks > 1 )
    180     {
    181         if(isr_switch_channel == 0xFFFFFFFF)
    182         {
     173    if (tasks > 1) {
     174        if (isr_switch_channel == 0xFFFFFFFF) {
    183175            _get_lock(&_tty_put_lock);
    184176            _puts("\n[GIET ERROR] ISR_SWITCH not found on proc ");
    185             _putd( proc_id);
     177            _putd(proc_id);
    186178            _puts("\n");
    187179            _release_lock(&_tty_put_lock);
     
    189181        }
    190182
    191         if(_timer_start( cluster_id, isr_switch_channel, GIET_TICK_VALUE ))
    192         {
     183        if (_timer_start( cluster_id, isr_switch_channel, GIET_TICK_VALUE)) {
    193184            _get_lock(&_tty_put_lock);
    194185            _puts("\n[GIET ERROR] ISR_SWITCH init error for proc ");
    195             _putd( proc_id);
     186            _putd(proc_id);
    196187            _puts("\n");
    197188            _release_lock(&_tty_put_lock);
    198189            _sys_exit();
    199190        }
    200        
    201 #if GIET_DEBUG_INIT
    202 _get_lock(&_tty_put_lock);
    203 _puts("\n[GIET DEBUG] Step 4 for processor ");
    204 _putd( global_pid );
    205 _puts(" / context switch activated\n");
    206 _release_lock(&_tty_put_lock);
    207 #endif
    208    
     191
     192#if GIET_DEBUG_INIT
     193        _get_lock(&_tty_put_lock);
     194        _puts("\n[GIET DEBUG] Step 4 for processor ");
     195        _putd(global_pid);
     196        _puts(" / context switch activated\n");
     197        _release_lock(&_tty_put_lock);
     198#endif
     199
    209200    }
    210201
     
    214205    //          it uses the page table of vspace[0]
    215206    //          the stack size is 256 bytes
    216  
    217     _set_context_slot( IDLE_TASK_INDEX, CTX_RUN_ID,  1 );
    218     _set_context_slot( IDLE_TASK_INDEX, CTX_SR_ID,   0xFF03 );
    219     _set_context_slot( IDLE_TASK_INDEX, CTX_SP_ID,   (unsigned int)_idle_stack + ((global_pid+1)<<8) );
    220     _set_context_slot( IDLE_TASK_INDEX, CTX_RA_ID,   (unsigned int)&_ctx_eret );
    221     _set_context_slot( IDLE_TASK_INDEX, CTX_EPC_ID,  (unsigned int)&_ctx_idle );
    222     _set_context_slot( IDLE_TASK_INDEX, CTX_LTID_ID, IDLE_TASK_INDEX );
    223     _set_context_slot( IDLE_TASK_INDEX, CTX_PTPR_ID, _ptabs_paddr[0] >> 13 );
    224 
    225 #if GIET_DEBUG_INIT
    226 _get_lock(&_tty_put_lock);
    227 _puts("\n[GIET DEBUG] Step 5 for processor ");
    228 _putd( global_pid );
    229 _puts(" / idle task context set\n");
    230 _release_lock(&_tty_put_lock);
    231 #endif
    232    
     207
     208    _set_context_slot( IDLE_TASK_INDEX, CTX_RUN_ID, 1);
     209    _set_context_slot( IDLE_TASK_INDEX, CTX_SR_ID,  0xFF03);
     210    _set_context_slot( IDLE_TASK_INDEX, CTX_SP_ID,  (unsigned int) _idle_stack + ((global_pid + 1) << 8));
     211    _set_context_slot( IDLE_TASK_INDEX, CTX_RA_ID,  (unsigned int) &_ctx_eret);
     212    _set_context_slot( IDLE_TASK_INDEX, CTX_EPC_ID, (unsigned int) &_ctx_idle);
     213    _set_context_slot( IDLE_TASK_INDEX, CTX_LTID_ID, IDLE_TASK_INDEX);
     214    _set_context_slot( IDLE_TASK_INDEX, CTX_PTPR_ID, _ptabs_paddr[0] >> 13);
     215
     216#if GIET_DEBUG_INIT
     217    _get_lock(&_tty_put_lock);
     218    _puts("\n[GIET DEBUG] Step 5 for processor ");
     219    _putd(global_pid);
     220    _puts(" / idle task context set\n");
     221    _release_lock(&_tty_put_lock);
     222#endif
     223
    233224    // step 6 : each processor initialises SP, SR, PTPR, EPC, registers
    234225    //          with the values corresponding to the first allocated task,
     
    237228    unsigned int task_id;
    238229
    239     if ( tasks == 0 )
    240     {
     230    if (tasks == 0) {
    241231        task_id = IDLE_TASK_INDEX;
    242232
    243         _get_lock( &_tty_put_lock );
     233        _get_lock(&_tty_put_lock);
    244234        _puts("\n[GIET WARNING] No task allocated to processor ");
    245         _putd( global_pid );
     235        _putd(global_pid);
    246236        _puts(" => idle\n");
    247         _release_lock ( &_tty_put_lock );
    248     }
    249     else
    250     {
    251         task_id = 0;
    252     }
    253        
    254     unsigned int    sp_value   = _get_context_slot( task_id, CTX_SP_ID );
    255     unsigned int    sr_value   = _get_context_slot( task_id, CTX_SR_ID );
    256     unsigned int    ptpr_value = _get_context_slot( task_id, CTX_PTPR_ID );
    257     unsigned int    epc_value  = _get_context_slot( task_id, CTX_EPC_ID );
    258 
    259 #if GIET_DEBUG_INIT
    260 _get_lock(&_tty_put_lock);
    261 _puts("\n[GIET DEBUG] step 6 for processor ");
    262 _putd( global_pid );
    263 _puts(" / registers initialised \n");
    264 _puts("- sp   = ");
    265 _putx( sp_value );
    266 _puts("\n");
    267 _puts("- sr   = ");
    268 _putx( sr_value );
    269 _puts("\n");
    270 _puts("- ptpr = ");
    271 _putx( ptpr_value<<13 );
    272 _puts("\n");
    273 _puts("- epc  = ");
    274 _putx( epc_value );
    275 _puts("\n");
    276 _release_lock(&_tty_put_lock);
     237        _release_lock (&_tty_put_lock);
     238    }
     239    else {
     240        task_id = 0;
     241    }
     242
     243    unsigned int sp_value = _get_context_slot(task_id, CTX_SP_ID);
     244    unsigned int sr_value = _get_context_slot(task_id, CTX_SR_ID);
     245    unsigned int ptpr_value = _get_context_slot(task_id, CTX_PTPR_ID);
     246    unsigned int epc_value = _get_context_slot(task_id, CTX_EPC_ID);
     247
     248#if GIET_DEBUG_INIT
     249    _get_lock(&_tty_put_lock);
     250    _puts("\n[GIET DEBUG] step 6 for processor ");
     251    _putd(global_pid);
     252    _puts(" / registers initialised \n");
     253    _puts("- sp   = ");
     254    _putx(sp_value);
     255    _puts("\n");
     256    _puts("- sr   = ");
     257    _putx(sr_value);
     258    _puts("\n");
     259    _puts("- ptpr = ");
     260    _putx(ptpr_value << 13);
     261    _puts("\n");
     262    _puts("- epc  = ");
     263    _putx(epc_value);
     264    _puts("\n");
     265    _release_lock(&_tty_put_lock);
    277266#endif
    278267
    279268    // set  registers and jump to user code
    280     asm volatile ( "move        $29,    %0              \n"             /* SP <= ctx[CTX_SP_ID] */
    281                    "mtc0        %1,             $12             \n"             /* SR <= ctx[CTX_SR_ID] */
    282                    "mtc2        %2,             $0              \n"             /* PTPR <= ctx[CTX_PTPR_ID] */
    283                    "mtc0        %3,             $14             \n"             /* EPC <= ctx[CTX_EPC_ID] */
    284                    "eret                                        \n"             /* jump to user code */
    285                    "nop                                         \n"
    286                    :
    287                    : "r"(sp_value), "r"(sr_value), "r"(ptpr_value), "r"(epc_value) );
     269    asm volatile (
     270            "move    $29,       %0    \n"        /* SP <= ctx[CTX_SP_ID] */
     271            "mtc0    %1,        $12   \n"        /* SR <= ctx[CTX_SR_ID] */
     272            "mtc2    %2,        $0    \n"        /* PTPR <= ctx[CTX_PTPR_ID] */
     273            "mtc0    %3,        $14   \n"        /* EPC <= ctx[CTX_EPC_ID] */
     274            "eret                     \n"        /* jump to user code */
     275            "nop                      \n"
     276            :
     277            : "r" (sp_value), "r" (sr_value), "r" (ptpr_value), "r" (epc_value));
    288278
    289279} // end _kernel_init()
     280
     281// Local Variables:
     282// tab-width: 4
     283// c-basic-offset: 4
     284// c-file-offsets:((innamespace . 0)(inline-open . 0))
     285// indent-tabs-mode: nil
     286// End:
     287// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
     288
  • soft/giet_vm/sys/mips32_registers.h

    r199 r228  
    11/********************************************************************************/
    2 /*      File : mips32_registers.h                                               */
    3 /*      Author : Alain Greiner                                                  */
    4 /*      Date : 26/03/2012                                                       */
     2/*    File : mips32_registers.h                        */
     3/*    Author : Alain Greiner                            */
     4/*    Date : 26/03/2012                            */
    55/********************************************************************************/
    6 /*      We define mnemonics for MIPS32 registers                                */
     6/*     We define mnemonics for MIPS32 registers                          */
    77/********************************************************************************/
    8                
     8
    99#ifndef _MIPS32_REGISTER_H
    1010#define _MIPS32_REGISTER_H
     
    1212/* processor registers */
    1313
    14 #define zero                    $0
    15 #define at                      $1
    16 #define v0                      $2
    17 #define v1                      $3
    18 #define a0                      $4
    19 #define a1                      $5
    20 #define a2                      $6
    21 #define a3                      $7
    22 #define t0                      $8
    23 #define t1                      $9
    24 #define t2                      $10
    25 #define t3                      $11
    26 #define t4                      $12
    27 #define t5                      $13
    28 #define t6                      $14
    29 #define t7                      $15
    30 #define s0                      $16
    31 #define s1                      $17
    32 #define s2                      $18
    33 #define s3                      $19
    34 #define s4                      $20
    35 #define s5                      $21
    36 #define s6                      $22
    37 #define s7                      $23
    38 #define t8                      $24
    39 #define t9                      $25
    40 #define k0                      $26
    41 #define k1                      $27
    42 #define gp                      $28
    43 #define sp                      $29
    44 #define fp                      $30
    45 #define ra                      $31
     14#define zero  $0
     15#define at    $1
     16#define v0    $2
     17#define v1    $3
     18#define a0    $4
     19#define a1    $5
     20#define a2    $6
     21#define a3    $7
     22#define t0    $8
     23#define t1    $9
     24#define t2    $10
     25#define t3    $11
     26#define t4    $12
     27#define t5    $13
     28#define t6    $14
     29#define t7    $15
     30#define s0    $16
     31#define s1    $17
     32#define s2    $18
     33#define s3    $19
     34#define s4    $20
     35#define s5    $21
     36#define s6    $22
     37#define s7    $23
     38#define t8    $24
     39#define t9    $25
     40#define k0    $26
     41#define k1    $27
     42#define gp    $28
     43#define sp    $29
     44#define fp    $30
     45#define ra    $31
    4646
    4747/* CP0 registers */
    4848
    49 #define CP0_BVAR                $8
    50 #define CP0_TIME                $9
    51 #define CP0_SR                  $12
    52 #define CP0_CR                  $13
    53 #define CP0_EPC                 $14
    54 #define CP0_PROCID              $15,1
    55 #define CP0_SCHED               $22
     49#define CP0_BVAR     $8
     50#define CP0_TIME     $9
     51#define CP0_SR       $12
     52#define CP0_CR       $13
     53#define CP0_EPC      $14
     54#define CP0_PROCID   $15,1
     55#define CP0_SCHED    $22
    5656
    5757/* CP2 registers */
    5858
    59 #define CP2_PTPR                $0
    60 #define CP2_MODE                $1
    61 #define CP2_ICACHE_FLUSH        $2
    62 #define CP2_DCACHE_FLUSH        $3
    63 #define CP2_ITLB_INVAL          $4
    64 #define CP2_DTLB_INVAL          $5
    65 #define CP2_ICACHE_INVAL        $6
    66 #define CP2_DCACHE_INVAL        $7
    67 #define CP2_ICACHE_PREFETCH     $8
    68 #define CP2_DCACHE_PREFETCH     $9
    69 #define CP2_SYNC                $10
    70 #define CP2_IETR                $11
    71 #define CP2_DETR                $12
    72 #define CP2_IBVAR               $13
    73 #define CP2_DBVAR               $14
    74 #define CP2_PARAMS              $15
    75 #define CP2_RELEASE             $16
    76 #define CP2_DATA_LO                             $17     
    77 #define CP2_DATA_HI                             $18             
    78 #define CP2_ICACHE_INVAL_PA     $19             
    79 #define CP2_DCACHE_INVAL_PA     $20
     59#define CP2_PTPR             $0
     60#define CP2_MODE             $1
     61#define CP2_ICACHE_FLUSH     $2
     62#define CP2_DCACHE_FLUSH     $3
     63#define CP2_ITLB_INVAL       $4
     64#define CP2_DTLB_INVAL       $5
     65#define CP2_ICACHE_INVAL     $6
     66#define CP2_DCACHE_INVAL     $7
     67#define CP2_ICACHE_PREFETCH  $8
     68#define CP2_DCACHE_PREFETCH  $9
     69#define CP2_SYNC             $10
     70#define CP2_IETR             $11
     71#define CP2_DETR             $12
     72#define CP2_IBVAR            $13
     73#define CP2_DBVAR            $14
     74#define CP2_PARAMS           $15
     75#define CP2_RELEASE          $16
     76#define CP2_DATA_LO          $17     
     77#define CP2_DATA_HI          $18         
     78#define CP2_ICACHE_INVAL_PA  $19         
     79#define CP2_DCACHE_INVAL_PA  $20
    8080
    8181#endif
     82
     83// Local Variables:
     84// tab-width: 4
     85// c-basic-offset: 4
     86// c-file-offsets:((innamespace . 0)(inline-open . 0))
     87// indent-tabs-mode: nil
     88// End:
     89// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
     90
  • soft/giet_vm/sys/sys_handler.c

    r218 r228  
    1717#include <giet_config.h>
    1818#include <mapping_info.h>
    19 
    20 ////////////////////////////////////////////////////////////////////////////
    21 //      Initialize the syscall vector with syscall handlers
    22 ////////////////////////////////////////////////////////////////////////////
    23 const void *_syscall_vector[32] = {
    24     &_procid,           /* 0x00 */
    25     &_proctime,         /* 0x01 */
    26     &_tty_write,        /* 0x02 */
    27     &_tty_read,         /* 0x03 */
    28     &_timer_start,      /* 0x04 */
    29     &_timer_stop,       /* 0x05 */
    30     &_gcd_write,        /* 0x06 */
    31     &_gcd_read,         /* 0x07 */
    32     &_sys_ukn,          /* 0x08 */
    33     &_sys_ukn,          /* 0x09 */
    34     &_sys_ukn,          /* 0x0A */
    35     &_sys_ukn,          /* 0x0B */
    36     &_sys_ukn,          /* 0x0C */
    37     &_ctx_switch,       /* 0x0D */
    38     &_exit,             /* 0x0E */
    39     &_procs_number,     /* 0x0F */
    40     &_fb_sync_write,    /* 0x10 */
    41     &_fb_sync_read,     /* 0x11 */
    42     &_fb_write,         /* 0x12 */
    43     &_fb_read,          /* 0x13 */
    44     &_fb_completed,     /* 0x14 */
    45     &_ioc_write,        /* 0x15 */
    46     &_ioc_read,         /* 0x16 */
    47     &_ioc_completed,    /* 0x17 */
    48     &_sys_ukn,          /* 0x18 */
    49     &_sys_ukn,          /* 0x19 */
    50     &_vobj_get_vbase,   /* 0x1A */
    51     &_nic_write,        /* 0x1B */
    52     &_nic_read,         /* 0x1C */
    53     &_nic_completed,    /* 0x1D */
    54     &_sys_ukn,          /* 0x1E */
    55     &_sys_ukn,          /* 0x1F */
     19#include <srl_memspace.h>
     20
     21////////////////////////////////////////////////////////////////////////////
     22//    Initialize the syscall vector with syscall handlers
     23////////////////////////////////////////////////////////////////////////////
     24const void * _syscall_vector[32] = {
     25    &_procid,              /* 0x00 */
     26    &_proctime,            /* 0x01 */
     27    &_tty_write,           /* 0x02 */
     28    &_tty_read,            /* 0x03 */
     29    &_timer_start,         /* 0x04 */
     30    &_timer_stop,          /* 0x05 */
     31    &_gcd_write,           /* 0x06 */
     32    &_gcd_read,            /* 0x07 */
     33    &_sys_ukn,             /* 0x08 */
     34    &_get_current_task_id, /* 0x09 */
     35    &_sys_ukn,             /* 0x0A */
     36    &_sys_ukn,             /* 0x0B */
     37    &_sys_ukn,             /* 0x0C */
     38    &_context_switch,      /* 0x0D */
     39    &_exit,                /* 0x0E */
     40    &_procs_number,        /* 0x0F */
     41    &_fb_sync_write,       /* 0x10 */
     42    &_fb_sync_read,        /* 0x11 */
     43    &_fb_write,            /* 0x12 */
     44    &_fb_read,             /* 0x13 */
     45    &_fb_completed,        /* 0x14 */
     46    &_ioc_write,           /* 0x15 */
     47    &_ioc_read,            /* 0x16 */
     48    &_ioc_completed,       /* 0x17 */
     49    &_sys_ukn,             /* 0x18 */
     50    &_sys_ukn,             /* 0x19 */
     51    &_vobj_get_vbase,      /* 0x1A */
     52    &_nic_write,           /* 0x1B */
     53    &_nic_read,            /* 0x1C */
     54    &_nic_completed,       /* 0x1D */
     55    &_sys_ukn,             /* 0x1E */
     56    &_sys_ukn,             /* 0x1F */
    5657};
    5758
     
    5960// function executed in case of undefined syscall
    6061//////////////////////////////////////////////////////////////////////////////
    61 void _sys_ukn()
    62 {
    63     unsigned int        epc;
    64     asm volatile("mfc0 %0, $14" : "=r"(epc));
     62void _sys_ukn() {
     63    unsigned int epc;
     64    asm volatile("mfc0 %0, $14" : "=r" (epc));
    6565
    6666    _puts("\n\n!!! Undefined System Call !!!\n");
    6767    _puts("\nEPC = ");
    68     _putx( epc );
     68    _putx(epc);
    6969    _exit();
    7070}
     71
     72
    7173////////////////////////////////////////////////////////////////////////////
    7274// _exit()
    7375// Task suicide... after printing a death message.
    7476////////////////////////////////////////////////////////////////////////////
    75 void _exit()
    76 {
    77     unsigned int date    = _proctime();
     77void _exit() {
     78    unsigned int date = _proctime();
    7879    unsigned int proc_id = _procid();
    7980    unsigned int task_id = _get_current_task_id();
    8081
    81      // print death message
     82    // print death message
    8283    _get_lock(&_tty_put_lock);
    8384    _puts("\n[GIET] Exit task ");
    84     _putd( task_id );
     85    _putd(task_id);
    8586    _puts(" on processor ");
    86     _putd( proc_id );
     87    _putd(proc_id);
    8788    _puts(" at cycle ");
    88     _putd( date );
     89    _putd(date);
    8990    _puts("\n\n");
    9091    _release_lock(&_tty_put_lock);
    91    
     92
    9293    // goes to sleeping state
    93     _set_context_slot( task_id, CTX_RUN_ID, 0 );
    94    
     94    _set_context_slot( task_id, CTX_RUN_ID, 0);
     95
    9596    // deschedule
    9697    _ctx_switch();
    9798}
     99
     100
    98101//////////////////////////////////////////////////////////////////////////////
    99102// _procid()
     
    101104// Max number or processors is 1024.
    102105//////////////////////////////////////////////////////////////////////////////
    103 unsigned int _procid()
    104 {
    105     unsigned int ret;
    106     asm volatile("mfc0 %0, $15, 1" : "=r"(ret));
     106unsigned int _procid() {
     107    unsigned int ret;
     108    asm volatile("mfc0 %0, $15, 1" : "=r" (ret));
    107109    return (ret & 0xFFF);
    108110}
     111
     112
    109113//////////////////////////////////////////////////////////////////////////////
    110114// _proctime()
    111115// Access CP0 and returns current processor's elapsed clock cycles since boot.
    112116//////////////////////////////////////////////////////////////////////////////
    113 unsigned int _proctime()
    114 {
    115     unsigned int ret;
    116     asm volatile("mfc0 %0, $9" : "=r"(ret));
     117unsigned int _proctime() {
     118    unsigned int ret;
     119    asm volatile("mfc0 %0, $9" : "=r" (ret));
    117120    return ret;
    118121}
     122
     123
    119124//////////////////////////////////////////////////////////////////////////////
    120125// _procnumber()
     
    122127// specified by the cluster_id argument.
    123128//////////////////////////////////////////////////////////////////////////////
    124 unsigned int _procs_number( unsigned int        cluster_id,
    125                             unsigned int*       buffer)
    126 {
    127     mapping_header_t*   header  = (mapping_header_t*)&seg_mapping_base;
    128     mapping_cluster_t*  cluster = _get_cluster_base( header );
    129 
    130     if ( cluster_id < header->clusters )
    131     {
     129unsigned int _procs_number(unsigned int cluster_id, unsigned int * buffer) {
     130    mapping_header_t * header  = (mapping_header_t *) &seg_mapping_base;
     131    mapping_cluster_t * cluster = _get_cluster_base(header);
     132
     133    if (cluster_id < header->clusters) {
    132134        *buffer = cluster[cluster_id].procs;
    133135        return 0;
    134136    }
    135     else
    136     {
    137          return 1;
    138     }
    139 }
    140 
    141 int _get_vobj( char* vspace_name, char* vobj_name, unsigned int vobj_type, mapping_vobj_t** res_vobj)
    142 {
    143     mapping_header_t* header = (mapping_header_t*)&seg_mapping_base;
    144     mapping_vspace_t* vspace = _get_vspace_base( header );
    145     mapping_vobj_t*    vobj  = _get_vobj_base( header );
    146 
    147     unsigned int    vspace_id;
    148     unsigned int    vobj_id;
    149        
     137    else {
     138        return 1;
     139    }
     140}
     141
     142
     143int _get_vobj(char * vspace_name, char * vobj_name, unsigned int vobj_type, mapping_vobj_t ** res_vobj) {
     144    mapping_header_t * header = (mapping_header_t *) &seg_mapping_base;
     145    mapping_vspace_t * vspace = _get_vspace_base(header);
     146    mapping_vobj_t * vobj  = _get_vobj_base(header);
     147
     148    unsigned int vspace_id;
     149    unsigned int vobj_id;
     150
    150151
    151152    // scan vspaces
    152     for ( vspace_id = 0 ; vspace_id < header->vspaces ; vspace_id++ )
    153     {
    154         if ( _strncmp( vspace[vspace_id].name, vspace_name, 31) == 0 )
    155         {
     153    for (vspace_id = 0; vspace_id < header->vspaces; vspace_id++) {
     154        if (_strncmp( vspace[vspace_id].name, vspace_name, 31) == 0) {
    156155            // scan vobjs
    157             for( vobj_id = vspace[vspace_id].vobj_offset;
     156            for (vobj_id = vspace[vspace_id].vobj_offset;
    158157                 vobj_id < (vspace[vspace_id].vobj_offset + vspace[vspace_id].vobjs);
    159                  vobj_id++)
    160             {
    161 
    162                 if ( _strncmp( vobj[vobj_id].name, vobj_name, 31) == 0 )
    163                 {
    164                     if(vobj[vobj_id].type != vobj_type)
    165                         return -1;                                                      //wrong type
    166 
     158                 vobj_id++) {
     159
     160                if (_strncmp(vobj[vobj_id].name, vobj_name, 31) == 0) {
     161                    if (vobj[vobj_id].type != vobj_type) {
     162                        _get_lock(&_tty_put_lock);
     163                        _puts("*** Error in _get_obj: wrong type\n");
     164                        _release_lock(&_tty_put_lock);
     165                        return -1; //wrong type
     166                    }
    167167                    *res_vobj = &vobj[vobj_id];
    168 
    169168                    return 0;
    170169                }
     
    172171        }
    173172    }
    174     return -2;          //not found
    175 
    176 }
     173    _get_lock(&_tty_put_lock);
     174    _puts("*** Error in _get_obj: object not found\n");
     175    _release_lock(&_tty_put_lock);
     176
     177    return -2; //not found
     178}
     179
     180
    177181/////////////////////////////////////////////////////////////////////////////
    178182// _vobj_get_vbase()
     
    182186// returns 0: success, else: failed.
    183187/////////////////////////////////////////////////////////////////////////////
    184 unsigned int _vobj_get_vbase( char*                     vspace_name,
    185                               char*                     vobj_name,
    186                               unsigned int      vobj_type,
    187                               unsigned int* vobj_vaddr )
    188 {
    189     mapping_vobj_t*   res_vobj;
    190     unsigned int ret;
    191     if( (ret = _get_vobj(vspace_name, vobj_name, vobj_type, &res_vobj)) )
    192     {
     188unsigned int _vobj_get_vbase(
     189        char * vspace_name,
     190        char * vobj_name,
     191        unsigned int vobj_type,
     192        unsigned int * vobj_vaddr) {
     193    mapping_vobj_t * res_vobj;
     194    unsigned int ret;
     195    if ((ret = _get_vobj(vspace_name, vobj_name, vobj_type, &res_vobj))) {
    193196        return ret;
    194197    }
    195    
     198
    196199    *vobj_vaddr = res_vobj->vaddr;
    197 
    198200    return 0;
    199201}
     202
    200203
    201204/////////////////////////////////////////////////////////////////////////////
     
    206209// returns 0: success, else: failed.
    207210/////////////////////////////////////////////////////////////////////////////
    208 unsigned int _vobj_get_length(char*                     vspace_name,
    209                               char*                     vobj_name,
    210                               unsigned int      vobj_type,
    211                               unsigned int* vobj_length )
    212 {
    213 
    214     mapping_vobj_t*   res_vobj;
    215     unsigned int ret;
    216     if( (ret = _get_vobj(vspace_name, vobj_name, vobj_type, &res_vobj)) )
    217     {
     211unsigned int _vobj_get_length(
     212        char * vspace_name,
     213        char * vobj_name,
     214        unsigned int vobj_type,
     215        unsigned int * vobj_length) {
     216
     217    mapping_vobj_t * res_vobj;
     218    unsigned int ret;
     219    if ((ret = _get_vobj(vspace_name, vobj_name, vobj_type, &res_vobj))) {
    218220        return ret;
    219221    }
    220    
     222
    221223    *vobj_length = res_vobj->length;
    222224
    223225    return 0;
    224226}
     227
     228
     229////////////////////////////////////////////////////////////////
     230// _context_switch()
     231// This functions masks interruptions before calling _ctx_switch
     232// (They are usually masked when we receive a isr_switch interrupt
     233// because we execute isrs with interrupt masked)
     234////////////////////////////////////////////////////////////////
     235void _context_switch() {
     236    _it_mask();
     237    _ctx_switch();
     238    _it_restore();
     239}
     240
     241
     242// Local Variables:
     243// tab-width: 4
     244// c-basic-offset: 4
     245// c-file-offsets:((innamespace . 0)(inline-open . 0))
     246// indent-tabs-mode: nil
     247// End:
     248// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
     249
  • soft/giet_vm/sys/sys_handler.h

    r160 r228  
    1010
    1111//////////////////////////////////////////////////////////////////////////////////
    12 //      Syscall Vector Table (indexed by syscall index)
     12//     Syscall Vector Table (indexed by syscall index)
    1313//////////////////////////////////////////////////////////////////////////////////
    1414
    15 extern const void *_syscall_vector[32];
     15extern const void * _syscall_vector[32];
    1616
    1717//////////////////////////////////////////////////////////////////////////////////
     
    1919//////////////////////////////////////////////////////////////////////////////////
    2020
    21 void            _sys_ukn();
     21void _sys_ukn();
     22void _exit();
     23void _context_switch();
     24unsigned int _procid();
     25unsigned int _proctime();
     26unsigned int _procs_number(unsigned int cluster_id, unsigned int * buffer );
     27unsigned int _vobj_get_vbase(char * vspace_name, char * vobj_name, unsigned vobj_type, unsigned int * vobj_buffer);
    2228
    23 void            _exit();
     29#endif
    2430
    25 unsigned int    _procid();
     31// Local Variables:
     32// tab-width: 4
     33// c-basic-offset: 4
     34// c-file-offsets:((innamespace . 0)(inline-open . 0))
     35// indent-tabs-mode: nil
     36// End:
     37// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
    2638
    27 unsigned int    _proctime();
    28 
    29 unsigned int    _procs_number( unsigned int cluster_id,
    30                                unsigned int* buffer );
    31 
    32 unsigned int _vobj_get_vbase( char* vspace_name, char* vobj_name,
    33                         unsigned vobj_type, unsigned int* vobj_buffer);
    34 #endif
  • soft/giet_vm/sys/vm_handler.c

    r207 r228  
    2020
    2121/////////////////////////////////////////////////////////////////////////////
    22 //      Global variable : IOMMU page table
     22//     Global variable : IOMMU page table
    2323/////////////////////////////////////////////////////////////////////////////
    2424
    25 __attribute__((section (".iommu"))) page_table_t        _iommu_ptab;
     25__attribute__((section (".iommu"))) page_table_t _iommu_ptab;
    2626
    2727//////////////////////////////////////////////////////////////////////////////
    2828// _iommu_add_pte2()
    2929//////////////////////////////////////////////////////////////////////////////
    30 void _iommu_add_pte2( unsigned int      ix1,
    31                       unsigned int      ix2,
    32                       unsigned int      ppn,
    33                       unsigned int      flags )
    34 {
    35     unsigned int        ptba;
    36     unsigned int*       pt_ppn;
    37     unsigned int*       pt_flags;
     30void _iommu_add_pte2(
     31        unsigned int ix1,
     32        unsigned int ix2,
     33        unsigned int ppn,
     34        unsigned int flags) {
     35    unsigned int ptba;
     36    unsigned int * pt_ppn;
     37    unsigned int * pt_flags;
    3838
    3939    // get pointer on iommu page table
    40     page_table_t* pt = &_iommu_ptab;
     40    page_table_t * pt = &_iommu_ptab;
    4141
    4242    // get ptba and update PT2
    43     if ( (pt->pt1[ix1] & PTE_V) == 0 )
    44     {
     43    if ((pt->pt1[ix1] & PTE_V) == 0) {
    4544        _puts("\n[GIET ERROR] in iommu_add_pte2 function\n");
    4645        _puts("the IOMMU PT1 entry is not mapped / ix1 = ");
     
    4948        _exit();
    5049    }
    51     else
    52     {
    53         ptba      = pt->pt1[ix1] << 12;
    54         pt_flags  = (unsigned int*)(ptba + 8*ix2);
    55         pt_ppn    = (unsigned int*)(ptba + 8*ix2 + 4);
     50    else {
     51        ptba = pt->pt1[ix1] << 12;
     52        pt_flags = (unsigned int *) (ptba + 8 * ix2);
     53        pt_ppn = (unsigned int *) (ptba + 8 * ix2 + 4);
    5654        *pt_flags = flags;
    57         *pt_ppn   = ppn;
     55        *pt_ppn = ppn;
    5856    }
    5957} // end _iommu_add_pte2()
     58
    6059
    6160//////////////////////////////////////////////////////////////////////////////
    6261// _iommu_inval_pte2()
    6362//////////////////////////////////////////////////////////////////////////////
    64 void _iommu_inval_pte2( unsigned int    ix1,
    65                         unsigned int    ix2 )
    66 {
    67     unsigned int        ptba;
    68     unsigned int*       pt_flags;
     63void _iommu_inval_pte2(unsigned int ix1, unsigned int ix2) {
     64    unsigned int ptba;
     65    unsigned int * pt_flags;
    6966
    7067    // get pointer on iommu page table
    71     page_table_t* pt = &_iommu_ptab;
     68    page_table_t * pt = &_iommu_ptab;
    7269
    7370    // get ptba and inval PTE2
    74     if ( (pt->pt1[ix1] & PTE_V) == 0 )
    75     {
     71    if ((pt->pt1[ix1] & PTE_V) == 0) {
    7672        _puts("\n[GIET ERROR] in iommu_inval_pte2 function\n");
    7773        _puts("the IOMMU PT1 entry is not mapped / ix1 = ");
     
    8076        _exit();
    8177    }
    82     else
    83     {
    84         ptba      = pt->pt1[ix1] << 12;
    85         pt_flags  = (unsigned int*)(ptba + 8*ix2);
     78    else {
     79        ptba = pt->pt1[ix1] << 12;
     80        pt_flags = (unsigned int *) (ptba + 8 * ix2);
    8681        *pt_flags = 0;
    8782    }   
    8883} // end _iommu_inval_pte2()
     84
    8985
    9086//////////////////////////////////////////////////////////////////////////////
     
    9288// Returns 0 if success, 1 if PTE1 or PTE2 unmapped
    9389//////////////////////////////////////////////////////////////////////////////
    94 unsigned int _v2p_translate( page_table_t*      pt,
    95                              unsigned int       vpn,
    96                              unsigned int*      ppn,           
    97                              unsigned int*      flags ) 
    98 {
    99     unsigned int    ptba;
     90unsigned int _v2p_translate(
     91        page_table_t * pt,
     92        unsigned int vpn,
     93        unsigned int * ppn,       
     94        unsigned int * flags) {
     95    unsigned int ptba;
     96    register unsigned int * pte2;
     97    register unsigned int flags_value;
     98    register unsigned int ppn_value;
    10099
    101     register unsigned int*   pte2;
    102     register unsigned int    flags_value;
    103     register unsigned int    ppn_value;
    104 
    105     unsigned int    ix1 = vpn >> 9;
    106     unsigned int    ix2 = vpn & 0x1FF;
    107 /*
    108 _puts("\n\n********************** entering v2p_translate");
    109 _puts("\n - pt    = ");
    110 _putx( (unsigned int)pt );
    111 _puts("\n - vpn   = ");
    112 _putx( vpn << 12 );
    113 _puts("\n - ptba  = ");
    114 _putx( pt->pt1[ix1] << 12 ) ;
    115 _puts("\n - &pte2 = ");
    116 _putx( (pt->pt1[ix1] << 12) + 8*ix2 );
    117 _puts("\n - flags = ");
    118 _putx( *(unsigned int*)((pt->pt1[ix1] << 12) + 8*ix2) );
    119 _puts("\n");
    120 */
     100    unsigned int ix1 = vpn >> 9;
     101    unsigned int ix2 = vpn & 0x1FF;
     102    /*
     103       _puts("\n\n********************** entering v2p_translate");
     104       _puts("\n - pt    = ");
     105       _putx( (unsigned int)pt );
     106       _puts("\n - vpn   = ");
     107       _putx( vpn << 12 );
     108       _puts("\n - ptba  = ");
     109       _putx( pt->pt1[ix1] << 12 ) ;
     110       _puts("\n - &pte2 = ");
     111       _putx( (pt->pt1[ix1] << 12) + 8*ix2 );
     112       _puts("\n - flags = ");
     113       _putx( *(unsigned int*)((pt->pt1[ix1] << 12) + 8*ix2) );
     114       _puts("\n");
     115       */
    121116    // check PTE1 mapping
    122     if ( (pt->pt1[ix1] & PTE_V) == 0 )
    123     {
     117    if ((pt->pt1[ix1] & PTE_V) == 0) {
    124118        return 1;
    125119    }
    126     else
    127     {
     120    else {
    128121        // get physical addresses of pte2
    129122        ptba = pt->pt1[ix1] << 12;
    130         pte2 = (unsigned int*)(ptba + 8*ix2);
     123        pte2 = (unsigned int *) (ptba + 8 * ix2);
    131124
    132125        // gets ppn_value and flags_value, after temporary DTLB desactivation
    133         asm volatile ( "li      $27,    0xFFFFFFFE  \n"     /* Mask for IE bits     */
    134                        "mfc0    $26,    $12         \n"     /* save SR              */
    135                        "and     $27,    $26,    $27 \n"
    136                        "mtc0    $27,    $12         \n"     /* disable Interrupts   */
     126        asm volatile (
     127                "li      $27,    0xFFFFFFFE  \n"     /* Mask for IE bits     */
     128                "mfc0    $26,    $12         \n"     /* save SR              */
     129                "and     $27,    $26,    $27 \n"
     130                "mtc0    $27,    $12         \n"     /* disable Interrupts   */
    137131
    138                        "li      $27,    0xB         \n"     
    139                        "mtc2    $27,    $1          \n"     /* DTLB unactivated     */
     132                "li      $27,    0xB         \n"     
     133                "mtc2    $27,    $1          \n"     /* DTLB unactivated     */
    140134
    141                        "move    $27,    %2          \n"     /* $27 <= pte2          */
    142                        "lw      %0,     0($27)      \n"     /* read flags           */
    143                        "lw      %1,     4($27)      \n"     /* read ppn             */
     135                "move    $27,    %2          \n"     /* $27 <= pte2          */
     136                "lw      %0,     0($27)      \n"     /* read flags           */
     137                "lw      %1,     4($27)      \n"     /* read ppn             */
    144138
    145                        "li      $27,    0xF         \n"
    146                        "mtc2    $27,    $1          \n"     /* DTLB activated       */
     139                "li      $27,    0xF         \n"
     140                "mtc2    $27,    $1          \n"     /* DTLB activated       */
    147141
    148                        "mtc0    $26,    $12         \n"     /* restore SR           */
    149                         :"=r"(flags_value), "=r"(ppn_value)
    150                         :"r"(pte2)
    151                         :"$26","$27","$8" );
     142                "mtc0    $26,    $12         \n"     /* restore SR           */
     143                : "=r" (flags_value), "=r" (ppn_value)
     144                : "r" (pte2)
     145                : "$26","$27","$8");
    152146
    153147        // check PTE2 mapping
    154         if ( (flags_value & PTE_V) == 0 )
    155         {
     148        if ((flags_value & PTE_V) == 0) {
    156149            return 1;
    157150        }
    158151
    159152        // set return values
    160         *ppn      = ppn_value;
    161         *flags    = flags_value;
     153        *ppn = ppn_value;
     154        *flags = flags_value;
    162155    }
    163156    return 0;
    164 }       // end _v2p_translate()
     157} // end _v2p_translate()
    165158
    166159// Local Variables:
     
    170163// indent-tabs-mode: nil
    171164// End:
     165// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
    172166
    173 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
    174167
  • soft/giet_vm/sys/vm_handler.h

    r195 r228  
    66///////////////////////////////////////////////////////////////////////////////////
    77
    8 #ifndef     _VM_HANDLER_H_
    9 #define     _VM_HANDLER_H_
     8#ifndef _VM_HANDLER_H_
     9#define _VM_HANDLER_H_
    1010
    11 #include    <giet_config.h>
    12 #include    <mapping_info.h>
     11#include <giet_config.h>
     12#include <mapping_info.h>
    1313
    1414/////////////////////////////////////////////////////////////////////////////////////
     
    1616/////////////////////////////////////////////////////////////////////////////////////
    1717
    18 #define     PT1_SIZE    8192
    19 #define     PT2_SIZE    4096
     18#define PT1_SIZE    8192
     19#define PT2_SIZE    4096
    2020
    2121/////////////////////////////////////////////////////////////////////////////////////
     
    2323/////////////////////////////////////////////////////////////////////////////////////
    2424
    25 #define     PTE_V       0x80000000
    26 #define     PTE_T       0x40000000
    27 #define     PTE_L       0x20000000
    28 #define     PTE_R       0x10000000
    29 #define     PTE_C       0x08000000
    30 #define     PTE_W       0x04000000
    31 #define     PTE_X       0x02000000
    32 #define     PTE_U       0x01000000
    33 #define     PTE_G       0x00800000
    34 #define     PTE_D       0x00400000
     25#define PTE_V  0x80000000
     26#define PTE_T  0x40000000
     27#define PTE_L  0x20000000
     28#define PTE_R  0x10000000
     29#define PTE_C  0x08000000
     30#define PTE_W  0x04000000
     31#define PTE_X  0x02000000
     32#define PTE_U  0x01000000
     33#define PTE_G  0x00800000
     34#define PTE_D  0x00400000
    3535
    3636/////////////////////////////////////////////////////////////////////////////////////
     
    3838/////////////////////////////////////////////////////////////////////////////////////
    3939
    40 #define MMU_ERR_PT1_UNMAPPED         0x001      // Page fault on Table1 (invalid PTE)
    41 #define MMU_ERR_PT2_UNMAPPED         0x002      // Page fault on Table 2 (invalid PTE)
    42 #define MMU_ERR_PRIVILEGE_VIOLATION  0x004      // Protected access in user mode
    43 #define MMU_ERR_WRITE_VIOLATION      0x008      // Write access to a non write page
    44 #define MMU_ERR_EXEC_VIOLATION       0x010      // Exec access to a non exec page
    45 #define MMU_ERR_UNDEFINED_XTN        0x020      // Undefined external access address
    46 #define MMU_ERR_PT1_ILLEGAL_ACCESS   0x040      // Bus Error in Table1 access
    47 #define MMU_ERR_PT2_ILLEGAL_ACCESS   0x080      // Bus Error in Table2 access
    48 #define MMU_ERR_CACHE_ILLEGAL_ACCESS 0x100      // Bus Error during the cache access
     40#define MMU_ERR_PT1_UNMAPPED         0x001 // Page fault on Table1 (invalid PTE)
     41#define MMU_ERR_PT2_UNMAPPED         0x002 // Page fault on Table 2 (invalid PTE)
     42#define MMU_ERR_PRIVILEGE_VIOLATION  0x004 // Protected access in user mode
     43#define MMU_ERR_WRITE_VIOLATION      0x008 // Write access to a non write page
     44#define MMU_ERR_EXEC_VIOLATION       0x010 // Exec access to a non exec page
     45#define MMU_ERR_UNDEFINED_XTN        0x020 // Undefined external access address
     46#define MMU_ERR_PT1_ILLEGAL_ACCESS   0x040 // Bus Error in Table1 access
     47#define MMU_ERR_PT2_ILLEGAL_ACCESS   0x080 // Bus Error in Table2 access
     48#define MMU_ERR_CACHE_ILLEGAL_ACCESS 0x100 // Bus Error during the cache access
    4949
    5050/////////////////////////////////////////////////////////////////////////////////////
    5151// Page table structure definition
    5252/////////////////////////////////////////////////////////////////////////////////////
    53 typedef struct PageTable
    54 {
    55         unsigned int    pt1[PT1_SIZE/4];                    // PT1 (index is ix1)
    56         unsigned int    pt2[1][PT2_SIZE/4];                 // PT2s (index is 2*ix2)
     53typedef struct PageTable {
     54    unsigned int pt1[PT1_SIZE / 4];    // PT1 (index is ix1)
     55    unsigned int pt2[1][PT2_SIZE / 4]; // PT2s (index is 2*ix2)
    5756} page_table_t;
    5857
     
    6867////////////////////////////////////////////////////////////////////////////////////
    6968
    70 void _iommu_add_pte2( unsigned int      ix1,
    71                       unsigned int      ix2,
    72                       unsigned int      ppn,
    73                       unsigned int      flags );
    74 
    75 void _iommu_inval_pte2( unsigned int    ix1,
    76                         unsigned int    ix2 );
    77 
    78 unsigned int _v2p_translate( page_table_t*      pt,
    79                              unsigned int       vpn,
    80                              unsigned int*      ppn,   
    81                              unsigned int*      flags );
     69void _iommu_add_pte2(unsigned int ix1, unsigned int ix2, unsigned int ppn, unsigned int flags);
     70void _iommu_inval_pte2(unsigned int ix1, unsigned int ix2);
     71unsigned int _v2p_translate(page_table_t * pt, unsigned int vpn, unsigned int * ppn, unsigned int * flags);
    8272
    8373#endif
     
    8979// indent-tabs-mode: nil
    9080// End:
     81// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
    9182
    92 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
Note: See TracChangeset for help on using the changeset viewer.