Ignore:
Timestamp:
Nov 7, 2017, 3:08:12 PM (6 years ago)
Author:
alain
Message:

First implementation of fork/exec.

Location:
trunk/kernel/fs
Files:
1 copied
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/kernel/fs/devfs.c

    r406 r407  
    2525#include <hal_types.h>
    2626#include <hal_special.h>
     27#include <hal_uspace.h>
    2728#include <printk.h>
    2829#include <chdev.h>
     30#include <dev_txt.h>
    2931#include <cluster.h>
    3032#include <vfs.h>
     
    3941extern chdev_directory_t    chdev_dir;      // allocated in kernel_init.c
    4042
     43#if CONFIG_READ_DEBUG
     44extern uint32_t  enter_devfs_move;
     45extern uint32_t  exit_devfs_move;
     46#endif
     47
    4148///////////////////////////////
    4249devfs_ctx_t * devfs_ctx_alloc()
     
    7986    error_t  error;
    8087
    81     devfs_dmsg("\n[DMSG] %s : enter in cluster %x\n",
     88    devfs_dmsg("\n[DBG] %s : enter in cluster %x\n",
    8289               __FUNCTION__ , local_cxy );
    8390
     
    93100    assert( (error == 0) , __FUNCTION__ , "cannot create <dev>\n" );
    94101
    95     devfs_dmsg("\n[DMSG] %s : <dev> created in cluster %x\n",
     102    devfs_dmsg("\n[DBG] %s : <dev> created in cluster %x\n",
    96103               __FUNCTION__ , local_cxy );
    97104
     
    107114    assert( (error == 0) , __FUNCTION__ , "cannot create <external>\n" );
    108115
    109     devfs_dmsg("\n[DMSG] %s : <external> created in cluster %x\n",
     116    devfs_dmsg("\n[DBG] %s : <external> created in cluster %x\n",
    110117               __FUNCTION__ , local_cxy );
    111118}
     
    119126    xptr_t        chdev_xp;
    120127    cxy_t         chdev_cxy;
     128    chdev_t     * chdev_ptr;
    121129    xptr_t        inode_xp;
    122130    uint32_t      channel;
     
    132140                             devfs_internal_inode_xp );
    133141
     142devfs_dmsg("\n[DBG] %s : created <%s> inode in cluster %x\n",
     143__FUNCTION__ , node_name , local_cxy );
     144
    134145    // create MMC chdev inode
    135     chdev_xp = chdev_dir.mmc[local_cxy];
     146    chdev_xp  = chdev_dir.mmc[local_cxy];
    136147    if( chdev_xp != XPTR_NULL)
    137148    {
     149        chdev_ptr = (chdev_t *)GET_PTR( chdev_xp );
    138150        vfs_add_child_in_parent( local_cxy,
    139151                                 INODE_TYPE_DEV,
    140152                                 FS_TYPE_DEVFS,
    141153                                 *devfs_internal_inode_xp,
    142                                  "mmc",
     154                                 chdev_ptr->name,
    143155                                 GET_PTR( chdev_xp ),
    144156                                 &inode_xp );
     157
     158devfs_dmsg("\n[DBG] %s : created <%s> inode in cluster %x\n",
     159__FUNCTION__ , chdev_ptr->name , local_cxy );
     160
    145161    }
    146162
     
    151167        if( chdev_xp != XPTR_NULL)
    152168        {
    153             snprintf( node_name , 16 , "dma_%d" , channel );
     169            chdev_ptr = (chdev_t *)GET_PTR( chdev_xp );
    154170            vfs_add_child_in_parent( local_cxy,
    155171                                     INODE_TYPE_DEV,
    156172                                     FS_TYPE_DEVFS,
    157173                                     *devfs_internal_inode_xp,
    158                                      node_name,
     174                                     chdev_ptr->name,
    159175                                     GET_PTR( chdev_xp ),
    160176                                     &inode_xp );
     177
     178devfs_dmsg("\n[DBG] %s : created <%s> inode in cluster %x\n",
     179__FUNCTION__ , chdev_ptr->name , local_cxy );
     180
    161181        }
    162182    }
     
    167187    {
    168188        chdev_cxy = GET_CXY( chdev_xp );
     189        chdev_ptr = (chdev_t *)GET_PTR( chdev_xp );
    169190        if( chdev_cxy == local_cxy )
    170191        {
     
    173194                                     FS_TYPE_DEVFS,
    174195                                     devfs_external_inode_xp,
    175                                      "iob",
     196                                     chdev_ptr->name,
    176197                                     GET_PTR( chdev_xp ),
    177198                                     &inode_xp );
     199
     200devfs_dmsg("\n[DBG] %s : created <%s> inode in cluster %x\n",
     201__FUNCTION__ , chdev_ptr->name , local_cxy );
     202
    178203        }
    179204    }
     
    184209    {
    185210        chdev_cxy = GET_CXY( chdev_xp );
     211        chdev_ptr = (chdev_t *)GET_PTR( chdev_xp );
    186212        if( chdev_cxy == local_cxy )
    187213        {
     
    190216                                     FS_TYPE_DEVFS,
    191217                                     devfs_external_inode_xp,
    192                                      "pic",
     218                                     chdev_ptr->name,
    193219                                     GET_PTR( chdev_xp ),
    194220                                     &inode_xp );
    195         }
    196     }
    197 
    198     // create a TXT inode in each cluster containing a TXT chdev
     221
     222devfs_dmsg("\n[DBG] %s : created <%s> inode in cluster %x\n",
     223__FUNCTION__ , chdev_ptr->name , local_cxy );
     224
     225        }
     226    }
     227
     228    // create a TXT_RX inode in each cluster containing a TXT_RX chdev
    199229    for( channel = 0 ; channel < CONFIG_MAX_TXT_CHANNELS ; channel++ )
    200230    {
    201         chdev_xp = chdev_dir.txt[channel];
    202         if( chdev_xp != XPTR_NULL )
    203         {
    204             chdev_cxy = GET_CXY( chdev_xp );
    205             if( chdev_cxy == local_cxy )
    206             {
    207                 snprintf( node_name , 16 , "txt_%d" , channel );
    208                 vfs_add_child_in_parent( local_cxy,
    209                                          INODE_TYPE_DEV,
    210                                          FS_TYPE_DEVFS,
    211                                          devfs_external_inode_xp,
    212                                          node_name,
    213                                          GET_PTR( chdev_xp ),
    214                                          &inode_xp );
     231        chdev_xp = chdev_dir.txt_rx[channel];
     232        if( chdev_xp != XPTR_NULL )
     233        {
     234            chdev_cxy = GET_CXY( chdev_xp );
     235            chdev_ptr = (chdev_t *)GET_PTR( chdev_xp );
     236            if( chdev_cxy == local_cxy )
     237            {
     238                vfs_add_child_in_parent( local_cxy,
     239                                         INODE_TYPE_DEV,
     240                                         FS_TYPE_DEVFS,
     241                                         devfs_external_inode_xp,
     242                                         chdev_ptr->name,
     243                                         GET_PTR( chdev_xp ),
     244                                         &inode_xp );
     245
     246devfs_dmsg("\n[DBG] %s : created <%s> inode in cluster %x\n",
     247__FUNCTION__ , chdev_ptr->name , local_cxy );
     248
     249            }
     250        }
     251    }
     252
     253    // create a TXT_TX inode in each cluster containing a TXT_TX chdev
     254    for( channel = 0 ; channel < CONFIG_MAX_TXT_CHANNELS ; channel++ )
     255    {
     256        chdev_xp = chdev_dir.txt_tx[channel];
     257        if( chdev_xp != XPTR_NULL )
     258        {
     259            chdev_cxy = GET_CXY( chdev_xp );
     260            chdev_ptr = (chdev_t *)GET_PTR( chdev_xp );
     261            if( chdev_cxy == local_cxy )
     262            {
     263                vfs_add_child_in_parent( local_cxy,
     264                                         INODE_TYPE_DEV,
     265                                         FS_TYPE_DEVFS,
     266                                         devfs_external_inode_xp,
     267                                         chdev_ptr->name,
     268                                         GET_PTR( chdev_xp ),
     269                                         &inode_xp );
     270
     271devfs_dmsg("\n[DBG] %s : created <%s> inode in cluster %x\n",
     272__FUNCTION__ , chdev_ptr->name , local_cxy );
     273
    215274            }
    216275        }
     
    224283        {
    225284            chdev_cxy = GET_CXY( chdev_xp );
    226             if( chdev_cxy == local_cxy )
    227             {
    228                 snprintf( node_name , 16 , "ioc_%d" , channel );
    229                 vfs_add_child_in_parent( local_cxy,
    230                                          INODE_TYPE_DEV,
    231                                          FS_TYPE_DEVFS,
    232                                          devfs_external_inode_xp,
    233                                          node_name,
    234                                          GET_PTR( chdev_xp ),
    235                                          &inode_xp );
     285            chdev_ptr = (chdev_t *)GET_PTR( chdev_xp );
     286            if( chdev_cxy == local_cxy )
     287            {
     288                vfs_add_child_in_parent( local_cxy,
     289                                         INODE_TYPE_DEV,
     290                                         FS_TYPE_DEVFS,
     291                                         devfs_external_inode_xp,
     292                                         chdev_ptr->name,
     293                                         GET_PTR( chdev_xp ),
     294                                         &inode_xp );
     295
     296devfs_dmsg("\n[DBG] %s : created <%s> inode in cluster %x\n",
     297__FUNCTION__ , chdev_ptr->name , local_cxy );
     298
    236299            }
    237300        }
     
    245308        {
    246309            chdev_cxy = GET_CXY( chdev_xp );
    247             if( chdev_cxy == local_cxy )
    248             {
    249                 snprintf( node_name , 16 , "fbf_%d" , channel );
    250                 vfs_add_child_in_parent( local_cxy,
    251                                          INODE_TYPE_DEV,
    252                                          FS_TYPE_DEVFS,
    253                                          devfs_external_inode_xp,
    254                                          node_name,
    255                                          GET_PTR( chdev_xp ),
    256                                          &inode_xp );
     310            chdev_ptr = (chdev_t *)GET_PTR( chdev_xp );
     311            if( chdev_cxy == local_cxy )
     312            {
     313                vfs_add_child_in_parent( local_cxy,
     314                                         INODE_TYPE_DEV,
     315                                         FS_TYPE_DEVFS,
     316                                         devfs_external_inode_xp,
     317                                         chdev_ptr->name,
     318                                         GET_PTR( chdev_xp ),
     319                                         &inode_xp );
     320
     321devfs_dmsg("\n[DBG] %s : created <%s> inode in cluster %x\n",
     322__FUNCTION__ , chdev_ptr->name , local_cxy );
     323
    257324            }
    258325        }
     
    266333        {
    267334            chdev_cxy = GET_CXY( chdev_xp );
    268             if( chdev_cxy == local_cxy )
    269             {
    270                 snprintf( node_name , 16 , "nic_rx_%d" , channel );
    271                 vfs_add_child_in_parent( local_cxy,
    272                                          INODE_TYPE_DEV,
    273                                          FS_TYPE_DEVFS,
    274                                          devfs_external_inode_xp,
    275                                          node_name,
    276                                          GET_PTR( chdev_xp ),
    277                                          &inode_xp );
     335            chdev_ptr = (chdev_t *)GET_PTR( chdev_xp );
     336            if( chdev_cxy == local_cxy )
     337            {
     338                vfs_add_child_in_parent( local_cxy,
     339                                         INODE_TYPE_DEV,
     340                                         FS_TYPE_DEVFS,
     341                                         devfs_external_inode_xp,
     342                                         chdev_ptr->name,
     343                                         GET_PTR( chdev_xp ),
     344                                         &inode_xp );
     345
     346devfs_dmsg("\n[DBG] %s : created <%s> inode in cluster %x\n",
     347__FUNCTION__ , chdev_ptr->name , local_cxy );
     348
    278349            }
    279350        }
     
    287358        {
    288359            chdev_cxy = GET_CXY( chdev_xp );
    289             if( chdev_cxy == local_cxy )
    290             {
    291                 snprintf( node_name , 16 , "nic_tx_%d" , channel );
    292                 vfs_add_child_in_parent( local_cxy,
    293                                          INODE_TYPE_DEV,
    294                                          FS_TYPE_DEVFS,
    295                                          devfs_external_inode_xp,
    296                                          node_name,
    297                                          GET_PTR( chdev_xp ),
    298                                          &inode_xp );
     360            chdev_ptr = (chdev_t *)GET_PTR( chdev_xp );
     361            if( chdev_cxy == local_cxy )
     362            {
     363                vfs_add_child_in_parent( local_cxy,
     364                                         INODE_TYPE_DEV,
     365                                         FS_TYPE_DEVFS,
     366                                         devfs_external_inode_xp,
     367                                         chdev_ptr->name,
     368                                         GET_PTR( chdev_xp ),
     369                                         &inode_xp );
     370
     371devfs_dmsg("\n[DBG] %s : created <%s> inode in cluster %x\n",
     372__FUNCTION__ , chdev_ptr->name , local_cxy );
     373
    299374            }
    300375        }
     
    302377}  // end devfs_local_init()
    303378
     379//////////////////////////////////////////
     380int devfs_user_move( bool_t     to_buffer,
     381                     xptr_t     file_xp,
     382                     void     * u_buf,
     383                     uint32_t   size )
     384{
     385    assert( ( file_xp != XPTR_NULL ) , __FUNCTION__ , "file_xp == XPTR_NULL" );
     386
     387    assert( ( size < CONFIG_TXT_KBUF_SIZE ) , __FUNCTION__ , "string size too large" );
     388
     389    cxy_t              file_cxy;     // remote file descriptor cluster
     390    vfs_file_t       * file_ptr;     // remote file descriptor local pointer
     391    vfs_inode_type_t   inode_type;   // associated inode type
     392    vfs_inode_t      * inode_ptr;    // associated inode local pointer
     393    chdev_t          * chdev_ptr;    // associated chdev type
     394    uint32_t           func;         // chdev functionnal type
     395    uint32_t           channel;      // chdev channel index
     396    error_t            error;
     397
     398    char               k_buf[CONFIG_TXT_KBUF_SIZE];  // local kernel buffer
     399
     400devfs_dmsg("\n[DBG] %s enter / cycle %d\n",
     401__FUNCTION__ , hal_time_stamp() );
     402
     403#if CONFIG_READ_DEBUG
     404enter_devfs_move = hal_time_stamp();
     405#endif
     406
     407    // get cluster and local pointer on remote file descriptor
     408    // associated inode and chdev are stored in same cluster as the file desc.
     409    file_cxy  = GET_CXY( file_xp );
     410    file_ptr  = (vfs_file_t *)GET_PTR( file_xp );
     411
     412    // get inode type from remote file descriptor
     413    inode_type = hal_remote_lw( XPTR( file_cxy , &file_ptr->type ) );
     414    inode_ptr  = (vfs_inode_t *)hal_remote_lpt( XPTR( file_cxy , &file_ptr->inode ) );
     415
     416    assert( (inode_type == INODE_TYPE_DEV) , __FUNCTION__ ,
     417    "inode type is not INODE_TYPE_DEV" );
     418
     419    // get chdev local pointer from remote inode extension
     420    chdev_ptr = (chdev_t *)hal_remote_lpt( XPTR( file_cxy , &inode_ptr->extend ) );
     421 
     422    // get chdev functionnal type and channel
     423    func    = hal_remote_lw( XPTR( file_cxy , &chdev_ptr->func ) );
     424    channel = hal_remote_lw( XPTR( file_cxy , &chdev_ptr->channel ) );
     425
     426    // action depends on "func" and "to_buffer"
     427    if( func == DEV_FUNC_TXT )
     428    {
     429        if( to_buffer )     // TXT read
     430        {
     431            uint32_t i;
     432            for( i = 0 ; i < size ; i++ )
     433            {
     434                error = dev_txt_read( channel , &k_buf[i] );
     435
     436                if( error )
     437                {
     438
     439devfs_dmsg("\n[DBG] %s exit error / cycle %d\n",
     440__FUNCTION__ , hal_time_stamp() );
     441
     442                    return -1;
     443                }
     444                else
     445                {
     446                    hal_strcpy_to_uspace( u_buf , k_buf , size );
     447                }
     448             }
     449
     450#if CONFIG_READ_DEBUG
     451exit_devfs_move = hal_time_stamp();
     452#endif
     453
     454devfs_dmsg("\n[DBG] %s exit success / size = %d / cycle %d\n",
     455__FUNCTION__ , size , hal_time_stamp() );
     456
     457            return size;
     458        }
     459        else                // TXT write 
     460        {
     461            hal_strcpy_from_uspace( k_buf , u_buf , size );
     462
     463            error = dev_txt_write( channel , k_buf , size );
     464            if( error )
     465            {
     466
     467devfs_dmsg("\n[DBG] %s exit error / cycle %d\n",
     468__FUNCTION__ , hal_time_stamp() );
     469
     470                return -1;
     471            }
     472            else
     473            {
     474
     475devfs_dmsg("\n[DBG] %s exit success / size = %d / cycle %d\n",
     476__FUNCTION__ , size , hal_time_stamp() );
     477
     478                return size;
     479            }
     480        }
     481    }
     482    else
     483    {
     484        panic("device type %s does not support direct user access", chdev_func_str(func) );
     485
     486        return -1;
     487    }
     488}  // end devfs_user_move()
     489
     490
Note: See TracChangeset for help on using the changeset viewer.