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

Introduce syscalls.

File:
1 edited

Legend:

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

    r14 r23  
    5555    uint32_t  channel = chdev->channel;
    5656
     57    // set chdev name
     58    strcpy( chdev->name , "ioc" );
     59
    5760    // set driver specific fields in chdev descriptor and call driver init function
    5861    if( impl == IMPL_IOC_BDV )
     
    6467    else if( impl == IMPL_IOC_HBA )
    6568    {
    66         chdev->cmd = &soclib_hba_command;
     69        chdev->cmd = &soclib_hba_cmd;
    6770        chdev->isr = &soclib_hba_isr;
    6871        soclib_hba_init( chdev );
     
    109112//////////////////////////////////////////////////////////////////////////////////
    110113// This static function is called by dev_ioc_read() & dev_ioc_write() functions.
    111 // It builds and registers the command in the calling thread descriptor, after
    112 // translation of buffer virtual address to physical address.
     114// It builds and registers the command in the calling thread descriptor.
    113115// Then, it registers the calling thead in chdev waiting queue.
    114116// Finally it blocks on the THREAD_BLOCKED_DEV condition and deschedule.
    115117////////////////////////////////////i/////////////////////////////////////////////
    116 static error_t dev_ioc_access( bool_t    to_mem,
    117                                char    * buffer,
    118                                uint32_t  lba,
    119                                uint32_t  count )
     118static error_t dev_ioc_access( uint32_t   cmd_type,
     119                               uint8_t  * buffer,
     120                               uint32_t   lba,
     121                               uint32_t   count )
    120122{
    121123    thread_t * this = CURRENT_THREAD;              // pointer on client thread
    122124
    123     error_t     error;
    124     paddr_t     buf_paddr;
    125 
    126     // Get buffer physical address
    127     error = vmm_v2p_translate( CONFIG_KERNEL_IDENTITY , buffer , &buf_paddr );
    128  
    129     if( error )  return EINVAL;
    130 
    131125    ioc_dmsg("\n[INFO] in %s : thread %x in process %x"
    132              " for lba = %x / vaddr = %x / paddr = %l / at cycle %d\n",
     126             " for lba = %x / buffer = %x / at cycle %d\n",
    133127             __FUNCTION__ , this->trdid , this->process->pid ,
    134              lba , (uint32_t)buffer , buf_paddr , hal_time_stamp() );
     128             lba , (intptr_t)buffer , hal_time_stamp() );
    135129
    136130#if USE_IOB    // software L2/L3 cache coherence for memory buffer
    137131
    138     if ( to_mem )  dev_mmc_inval( buf_paddr, count<<9 );
    139     else           dev_mmc_sync( buf_paddr, count<<9 );
     132    if ( type == IOC_READ )  dev_mmc_inval( XPTR( local_cxy , buffer ) , count<<9 );
     133    else                     dev_mmc_sync ( XPTR( local_cxy , buffer ) , count<<9 );
    140134
    141135#endif     // end software L2/L3 cache coherence
     
    148142    // register command in calling thread descriptor
    149143    this->command.ioc.dev_xp    = dev_xp;
    150     this->command.ioc.to_mem    = to_mem;
     144    this->command.ioc.type      = cmd_type;
    151145    this->command.ioc.buf_xp    = XPTR( local_cxy , buffer );
    152146    this->command.ioc.lba       = lba;
     
    169163
    170164////////////////////////////////////////////
    171 error_t dev_ioc_read( char         * buffer,
     165error_t dev_ioc_read( uint8_t      * buffer,
    172166                      uint32_t       lba,
    173167                      uint32_t       count )
    174168{
    175     return dev_ioc_access( true , buffer , lba , count );
     169    return dev_ioc_access( IOC_READ , buffer , lba , count );
    176170
    177171
    178172////////////////////////////////////////////
    179 error_t dev_ioc_write( char         * buffer,
    180                        uint32_t       lba,
    181                        uint32_t       count )
    182 {
    183     return dev_ioc_access( false , buffer , lba , count );
     173error_t dev_ioc_write( uint8_t     * buffer,
     174                       uint32_t      lba,
     175                       uint32_t      count )
     176{
     177    return dev_ioc_access( IOC_WRITE , buffer , lba , count );
    184178}
     179
     180/////////////////////////////////////////////
     181error_t dev_ioc_sync_read( uint8_t  * buffer,
     182                           uint32_t   lba,
     183                           uint32_t   count )
     184{
     185    // get pointer on calling thread
     186    thread_t * this = CURRENT_THREAD;
     187
     188#if USE_IOB    // software L2/L3 cache coherence for memory buffer
     189
     190    dev_mmc_inval( XPTR( local_cxy , buffer ) , count<<9 );
     191
     192#endif         // end software L2/L3 cache coherence
     193
     194    // get extended pointer on IOC[0] chdev
     195    xptr_t  dev_xp = chdev_dir.ioc[0];
     196
     197    assert( (dev_xp != XPTR_NULL) , __FUNCTION__ , "undefined IOC chdev descriptor" );
     198
     199    // register command in calling thread descriptor
     200    this->command.ioc.dev_xp    = dev_xp;
     201    this->command.ioc.type      = IOC_SYNC_READ;
     202    this->command.ioc.buf_xp    = XPTR( local_cxy , buffer );
     203    this->command.ioc.lba       = lba;
     204    this->command.ioc.count     = count;
     205
     206    // get driver command function
     207    cxy_t       dev_cxy = GET_CXY( dev_xp );
     208    chdev_t   * dev_ptr = (chdev_t *)GET_PTR( dev_xp );
     209    dev_cmd_t * cmd = (dev_cmd_t *)hal_remote_lpt( XPTR( dev_cxy , &dev_ptr->cmd ) );
     210
     211    // call directly driver command
     212    cmd( XPTR( local_cxy , this ) );
     213
     214    // return I/O operation status from calling thread descriptor
     215    return this->command.ioc.error;
     216}
     217
Note: See TracChangeset for help on using the changeset viewer.