Ignore:
Timestamp:
Jun 18, 2017, 10:06:41 PM (5 years ago)
Author:
alain
Message:

Introduce syscalls.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/devices/dev_mmc.c

    r14 r23  
    4343    // get implementation from device descriptor
    4444    uint32_t  impl = chdev->impl;
     45
     46    // set chdev name
     47    snprintf( chdev->name , 16 , "mmc_%x" , local_cxy );
    4548
    4649    // set driver specific fields in device descriptor and call driver init function
     
    6568
    6669/////////////////////////////////////////////////////////////////////////////
    67 // This static function makes some checking, takes the lock granting
    68 // exclusive access to MMC peripheral, call the driver to execute the command
     70// This static function is called by all MMC device functions.
     71// It makes some checking, takes the lock granting exclusive
     72// access to MMC peripheral, call the driver to execute the command
    6973// registered in the calling thread descriptor, and releases the lock.
    7074/////////////////////////////////////////////////////////////////////////////
    71 static void dev_mmc_access( thread_t * this )
    72 {
    73     mmc_dmsg("\n[INFO] %s enters for thread %x in process %x : command = %d\n",
    74                  __FUNCTION__ , this->trdid , this->process->pid , this->command.mmc.type );
    75 
    76     // get extended pointer on MMC device
    77     xptr_t  dev_xp  = this->command.mmc.dev_xp;
    78 
    79     assert( (dev_xp != XPTR_NULL) , __FUNCTION__ , "undefined MMC device descriptor" );
     75static error_t dev_mmc_access( thread_t * this )
     76{
     77    // get extended pointer on MMC device descriptor
     78    xptr_t  dev_xp = this->command.mmc.dev_xp;
     79
     80    assert( (dev_xp != XPTR_NULL) , __FUNCTION__ , "target MMC device undefined" );
    8081
    8182    // get MMC device cluster identifier & local pointer
     
    9596    remote_spinlock_unlock( XPTR( dev_cxy , &dev_ptr->wait_lock ) ); 
    9697
    97     mmc_dmsg("\n[INFO] %s completes for thread %x in process %x / error = %d\n",
    98                  __FUNCTION__ , this->trdid , this->process->pid , this->dev.ioc.error );
     98    // return operation status
     99    return this->command.mmc.error; 
    99100
    100101}  // end dev_mmc_access()
    101102
    102 ////////////////////////////////////////////
    103 error_t dev_mmc_inval( paddr_t    buf_paddr,
     103/////////////////////////////////////////
     104error_t dev_mmc_inval( xptr_t     buf_xp,
    104105                       uint32_t   buf_size )
    105106{
    106     // get calling thread local pointer
    107     thread_t * this = CURRENT_THREAD;
    108 
    109     // get target cluster from paddr
    110     cxy_t cxy = CXY_FROM_PADDR( buf_paddr );
    111 
    112     assert( ((buf_paddr & (CONFIG_CACHE_LINE_SIZE -1)) == 0) , __FUNCTION__ ,
     107    error_t error;
     108
     109    // get calling thread local pointer
     110    thread_t * this = CURRENT_THREAD;
     111
     112    mmc_dmsg("\n[INFO] %s enters for thread %x in process %x / buf_xp = %l\n",
     113                 __FUNCTION__ , this->trdid , this->process->pid , buf_xp );
     114
     115    // get buffer cluster and local pointer
     116    cxy_t  buf_cxy = GET_CXY( buf_xp );
     117    void * buf_ptr = GET_PTR( buf_xp );
     118   
     119    assert( (((intptr_t)buf_ptr & (CONFIG_CACHE_LINE_SIZE -1)) == 0) , __FUNCTION__ ,
    113120             "buffer not aligned on cache line" );
    114121
    115     // get extended pointer on MMC device descriptor
    116     xptr_t  dev_xp = chdev_dir.mmc[cxy];
    117 
    118     // store command arguments in thread descriptor
    119     this->command.mmc.dev_xp    = dev_xp;
     122    // get buffer physical address
     123    paddr_t  buf_paddr;
     124    error = vmm_v2p_translate( CONFIG_KERNEL_IDENTITY_MAP , buf_ptr , &buf_paddr );
     125
     126    assert( (error == 0) , __FUNCTION__ , "cannot get buffer paddr" );
     127
     128    // store command arguments in thread descriptor
     129    this->command.mmc.dev_xp    = chdev_dir.mmc[buf_cxy];
    120130    this->command.mmc.type      = MMC_CC_INVAL;
    121131    this->command.mmc.buf_paddr = buf_paddr;
    122132    this->command.mmc.buf_size  = buf_size;
    123133
    124     // execute operation
    125     dev_mmc_access( this );
    126 
    127     // return operation status
    128     return this->command.mmc.error; 
    129 
    130 
    131 /////////////////////////////////////
    132 error_t dev_mmc_sync( paddr_t    buf_paddr,
     134    // call MMC driver
     135    error = dev_mmc_access( this );
     136
     137    mmc_dmsg("\n[INFO] %s completes for thread %x in process %x / error = %d\n",
     138             __FUNCTION__ , this->trdid , this->process->pid , error );
     139
     140    return error;
     141}
     142
     143////////////////////////////////////////
     144error_t dev_mmc_sync( xptr_t     buf_xp,
    133145                      uint32_t   buf_size )
    134146{
    135     // get calling thread local pointer
    136     thread_t * this = CURRENT_THREAD;
    137 
    138     // get target cluster from paddr
    139     cxy_t cxy = CXY_FROM_PADDR( buf_paddr );
    140 
    141     assert( ((buf_paddr & (CONFIG_CACHE_LINE_SIZE -1)) == 0) , __FUNCTION__ ,
     147    error_t error;
     148
     149    // get calling thread local pointer
     150    thread_t * this = CURRENT_THREAD;
     151
     152    mmc_dmsg("\n[INFO] %s enters for thread %x in process %x / buf_xp = %l\n",
     153                 __FUNCTION__ , this->trdid , this->process->pid , buf_xp );
     154
     155    // get buffer cluster and local pointer
     156    cxy_t  buf_cxy = GET_CXY( buf_xp );
     157    void * buf_ptr = GET_PTR( buf_xp );
     158   
     159    assert( (((intptr_t)buf_ptr & (CONFIG_CACHE_LINE_SIZE -1)) == 0) , __FUNCTION__ ,
    142160             "buffer not aligned on cache line" );
    143161
    144     // store command arguments in thread descriptor
    145     this->command.mmc.dev_xp    = chdev_dir.mmc[cxy];
     162    // get  buffer physical address
     163    paddr_t  buf_paddr;
     164    error = vmm_v2p_translate( CONFIG_KERNEL_IDENTITY_MAP , buf_ptr , &buf_paddr );
     165
     166    assert( (error == 0) , __FUNCTION__ , "cannot get buffer paddr" );
     167
     168    // store command arguments in thread descriptor
     169    this->command.mmc.dev_xp    = chdev_dir.mmc[buf_cxy];
    146170    this->command.mmc.type      = MMC_CC_SYNC;
    147171    this->command.mmc.buf_paddr = buf_paddr;
    148172    this->command.mmc.buf_size  = buf_size;
    149173
    150     // execute operation
    151     dev_mmc_access( this );
    152 
    153     // return operation status
    154     return this->command.mmc.error; 
    155 
     174    // call MMC driver
     175    error = dev_mmc_access( this );
     176
     177    mmc_dmsg("\n[INFO] %s completes for thread %x in process %x / error = %d\n",
     178                 __FUNCTION__ , this->trdid , this->process->pid , error );
     179
     180    return error;
     181}
    156182
    157183/////////////////////////////////////////
     
    170196
    171197    // execute operation
    172     dev_mmc_access( this );
    173 
    174     // return operation status
    175     return this->command.mmc.error; 
     198    return dev_mmc_access( this );
    176199}
    177200                       
     
    191214
    192215    // execute operation
    193     dev_mmc_access( this );
    194 
    195     // return operation status
    196     return this->command.mmc.error; 
     216    return dev_mmc_access( this );
    197217}
    198218                       
     
    212232
    213233    // execute operation
    214     dev_mmc_access( this );
    215 
    216     // return operation status
    217     return this->command.mmc.error; 
    218 }
    219 
     234    return dev_mmc_access( this );
     235}
     236
Note: See TracChangeset for help on using the changeset viewer.