source: trunk/kernel/kern/chdev.c @ 690

Last change on this file since 690 was 683, checked in by alain, 3 years ago

All modifications required to support the <tcp_chat> application
including error recovery in case of packet loss.A

File size: 22.2 KB
RevLine 
[5]1/*
[657]2 * chdev.c - channel device API implementation.
[5]3 *
[657]4 * Authors  Alain Greiner   (2016,2017,2018,2019,2020)
[5]5 *
6 * Copyright (c) UPMC Sorbonne Universites
7 *
8 * This file is part of ALMOS-MKH.
9 *
10 * ALMOS-MKH.is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 2.0 of the License.
13 *
14 * ALMOS-MKH.is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with ALMOS-MKH.; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
[14]24#include <kernel_config.h>
[457]25#include <hal_kernel_types.h>
[5]26#include <hal_special.h>
[447]27#include <hal_remote.h>
[407]28#include <hal_irqmask.h>
[16]29#include <printk.h>
[5]30#include <boot_info.h>
31#include <xlist.h>
32#include <kmem.h>
[407]33#include <scheduler.h>
[5]34#include <thread.h>
35#include <rpc.h>
36#include <chdev.h>
[23]37#include <devfs.h>
[5]38
[564]39//////////////////////////////////////////////////////////////////////////////////////
40// Extern global variables
41//////////////////////////////////////////////////////////////////////////////////////
[317]42
[564]43extern chdev_directory_t    chdev_dir;         // allocated in kernel_init.c
[317]44
[564]45
[438]46#if (DEBUG_SYS_READ & 1)
[435]47extern uint32_t enter_chdev_cmd_read;
48extern uint32_t exit_chdev_cmd_read;
49extern uint32_t enter_chdev_server_read;
50extern uint32_t exit_chdev_server_read;
[407]51#endif
[317]52
[438]53#if (DEBUG_SYS_WRITE & 1)
[435]54extern uint32_t enter_chdev_cmd_write;
55extern uint32_t exit_chdev_cmd_write;
56extern uint32_t enter_chdev_server_write;
57extern uint32_t exit_chdev_server_write;
58#endif
59
[5]60////////////////////////////////////////////
61char * chdev_func_str( uint32_t func_type ) 
62{
[564]63    switch ( func_type ) 
64    {
[583]65        case DEV_FUNC_RAM: return "RAM";
66        case DEV_FUNC_ROM: return "ROM";
67        case DEV_FUNC_FBF: return "FBF";
68        case DEV_FUNC_IOB: return "IOB";
69        case DEV_FUNC_IOC: return "IOC";
70        case DEV_FUNC_MMC: return "MMC";
71        case DEV_FUNC_DMA: return "DMA";
72        case DEV_FUNC_NIC: return "NIC";
73        case DEV_FUNC_TIM: return "TIM";
74        case DEV_FUNC_TXT: return "TXT";
75        case DEV_FUNC_ICU: return "ICU";
76        case DEV_FUNC_PIC: return "PIC";
77        default:           return "undefined";
[527]78    }
[5]79}
80
81/////////////////////////////////////////
82chdev_t * chdev_create( uint32_t    func,
83                        uint32_t    impl,
84                        uint32_t    channel,
85                        uint32_t    is_rx,
86                        xptr_t      base )
87{
88    chdev_t    * chdev;
89
90    // allocate memory for chdev
[683]91    chdev = kmem_alloc( bits_log2(sizeof(chdev_t)) , AF_ZERO | AF_KERNEL );
[5]92
93    if( chdev == NULL ) return NULL;
94
[564]95    // initialize lock
96    remote_busylock_init( XPTR( local_cxy , &chdev->wait_lock ), LOCK_CHDEV_QUEUE );
97
98    // initialise waiting queue
[5]99    xlist_root_init( XPTR( local_cxy , &chdev->wait_root ) );
100
101    // initialize attributes
102    chdev->func    =  func;
103    chdev->impl    =  impl;
104    chdev->channel =  channel;
105    chdev->is_rx   =  is_rx;
106    chdev->base    =  base; 
107
108    return chdev;
109
110}  // end chdev_create()
111
[683]112/////////////////////////////////////
113void chdev_display( xptr_t chdev_xp )
[5]114{
[683]115    chdev_t * chdev = GET_PTR( chdev_xp );
116    cxy_t     cxy   = GET_CXY( chdev_xp );
117
118    char      name[16];
119
120    hal_remote_memcpy( XPTR( local_cxy, name ),
121                       XPTR( cxy , &chdev->name ), 16 );
122
123    printk("\n - chdev     = [%x,%x]"
124           "\n - name      = %s"
125           "\n - base      = [%x,%x]"
[5]126           "\n - cmd       = %x"
[683]127           "\n - isr       = %x\n",
128           cxy,
129           chdev,
130           name,
131           GET_CXY( hal_remote_l64( XPTR( cxy , &chdev->base ))),
132           GET_PTR( hal_remote_l64( XPTR( cxy , &chdev->base ))),
133           hal_remote_lpt( XPTR( cxy , &chdev->cmd )),
134           hal_remote_lpt( XPTR( cxy , &chdev->isr )) );
[5]135
[683]136}  // end chdev_display()
137
[407]138//////////////////////////////////////////////////
139void chdev_register_command( xptr_t     chdev_xp )
[5]140{
[407]141    thread_t * server_ptr;    // local pointer on server thread associated to chdev
[440]142    xptr_t     server_xp;     // extended pointer on server thread
[407]143    core_t   * core_ptr;      // local pointer on core running the server thread
[457]144    uint32_t   server_lid;    // core running the server thread local index
[564]145    xptr_t     lock_xp;       // extended pointer on lock protecting the chdev state
[5]146
[438]147#if (DEBUG_SYS_READ & 1)
[435]148enter_chdev_cmd_read = (uint32_t)hal_get_cycles();
[418]149#endif
150
[438]151#if (DEBUG_SYS_WRITE & 1)
[435]152enter_chdev_cmd_write = (uint32_t)hal_get_cycles();
153#endif
154
[657]155    thread_t * this      = CURRENT_THREAD;
156    xptr_t     client_xp = XPTR( local_cxy , this );
[407]157
[440]158    // get chdev cluster and local pointer
[5]159    cxy_t     chdev_cxy = GET_CXY( chdev_xp );
[440]160    chdev_t * chdev_ptr = GET_PTR( chdev_xp );
[5]161
[581]162    // check calling thread can yield
163    thread_assert_can_yield( this , __FUNCTION__ );
[564]164
[440]165    // get local and extended pointers on server thread
166    server_ptr = (thread_t *)hal_remote_lpt( XPTR( chdev_cxy , &chdev_ptr->server) );
167    server_xp  = XPTR( chdev_cxy , server_ptr );
168
169    // get local pointer on core running the server thread
170    core_ptr   = (core_t *)hal_remote_lpt( XPTR( chdev_cxy , &server_ptr->core ) );
171
172    // get server core local index
[564]173    server_lid = hal_remote_l32( XPTR( chdev_cxy , &core_ptr->lid ) );
[440]174
[438]175#if (DEBUG_CHDEV_CMD_RX || DEBUG_CHDEV_CMD_TX)
[619]176bool_t      is_rx        = hal_remote_l32( XPTR( chdev_cxy , &chdev_ptr->is_rx ) );
177trdid_t     server_trdid = hal_remote_l32( XPTR( chdev_cxy , &server_ptr->trdid ) ); 
178process_t * process_ptr  = hal_remote_lpt( XPTR( chdev_cxy , &server_ptr->process ) );
179pid_t       server_pid   = hal_remote_l32( XPTR( chdev_cxy , &process_ptr->pid ) );
[437]180#endif
181   
[438]182#if DEBUG_CHDEV_CMD_RX
[437]183uint32_t rx_cycle = (uint32_t)hal_get_cycles();
[438]184if( (is_rx) && (DEBUG_CHDEV_CMD_RX < rx_cycle) )
[625]185printk("\n[%s] client thread[%x,%x] enter for RX / server[%x,%x] / cycle %d\n",
[619]186__FUNCTION__, this->process->pid, this->trdid, server_pid, server_trdid, rx_cycle );
[437]187#endif
188
[438]189#if DEBUG_CHDEV_CMD_TX
[437]190uint32_t tx_cycle = (uint32_t)hal_get_cycles();
[438]191if( (is_rx == 0) && (DEBUG_CHDEV_CMD_TX < tx_cycle) )
[625]192printk("\n[%s] client thread[%x,%x] enter for TX / server[%x,%x] / cycle %d\n",
[619]193__FUNCTION__, this->process->pid, this->trdid, server_pid, server_trdid, tx_cycle );
[437]194#endif
195
[440]196    // build extended pointer on client thread xlist
197    xptr_t  list_xp    = XPTR( local_cxy , &this->wait_list );
[5]198
[440]199    // build extended pointer on chdev waiting queue root
200    xptr_t  root_xp    = XPTR( chdev_cxy , &chdev_ptr->wait_root );
[5]201
[440]202    // build extended pointer on lock protecting chdev waiting queue
[564]203    lock_xp            = XPTR( chdev_cxy , &chdev_ptr->wait_lock );
[407]204
[657]205    // The following actions are executed in critical section,
206    // (because the busylock_acquire / busylock_release)
207    // (1) take the lock protecting the waiting queue
[625]208    // (2) register client thread in server queue
209    // (3) unblock the server thread and block client thread
210    // (4) send IPI to force server scheduling
211    // (5) release the lock protecting waiting queue
[407]212
[625]213    // 1. take the lock protecting chdev queue
[564]214    remote_busylock_acquire( lock_xp );
[408]215
[625]216    // 2. register client thread in waiting queue
217    xlist_add_last( root_xp , list_xp );
[408]218
[450]219#if (DEBUG_CHDEV_CMD_TX & 1)
[625]220if( (is_rx == 0)  && (DEBUG_CHDEV_CMD_TX < tx_cycle) )
221printk("\n[%s] client thread[%x,%x] registered write request in chdev\n",
[601]222__FUNCTION__, this->process->pid, this->trdid );
[450]223#endif
[625]224 
[457]225#if (DEBUG_CHDEV_CMD_RX & 1)
[625]226if( (is_rx)  && (DEBUG_CHDEV_CMD_RX < rx_cycle) )
227printk("\n[%s] client thread[%x,%x] registered read request in chdev\n",
228__FUNCTION__, this->process->pid, this->trdid );
[457]229#endif
[625]230 
231    // 3. client thread unblocks server thread and blocks itself
[657]232    thread_unblock( server_xp , THREAD_BLOCKED_CLIENT );
233    thread_block( client_xp , THREAD_BLOCKED_IO );
[440]234
[450]235#if (DEBUG_CHDEV_CMD_TX & 1)
236if( (is_rx == 0) && (DEBUG_CHDEV_CMD_TX < tx_cycle) )
[625]237printk("\n[%s] client thread[%x,%x] unblock server thread[%x,%x] and block itsef\n",
238__FUNCTION__, this->process->pid, this->trdid, server_pid, server_trdid );
[450]239#endif
240
[457]241#if (DEBUG_CHDEV_CMD_RX & 1)
242if( (is_rx) && (DEBUG_CHDEV_CMD_RX < rx_cycle) )
[625]243printk("\n[%s] client thread[%x,%x] unblock server thread[%x,%x] and block itsef\n",
244__FUNCTION__, this->process->pid, this->trdid, server_pid, server_trdid );
[457]245#endif
246
[625]247    // 4. send IPI to core running the server thread when server core != client core
[457]248    if( (server_lid != this->core->lid) || (local_cxy != chdev_cxy) )
[450]249    {
[457]250        dev_pic_send_ipi( chdev_cxy , server_lid ); 
251
[450]252#if (DEBUG_CHDEV_CMD_TX & 1)
253if( (is_rx == 0)  && (DEBUG_CHDEV_CMD_TX < tx_cycle) )
[593]254printk("\n[%s] client thread[%x,%x] sent IPI to TX server thread[%x,%x]\n",
[619]255__FUNCTION__, this->process->pid, this->trdid, server_pid, server_trdid );
[450]256#endif
257
[457]258#if (DEBUG_CHDEV_CMD_RX & 1)
259if( (is_rx)  && (DEBUG_CHDEV_CMD_RX < rx_cycle) )
[593]260printk("\n[%s] client thread[%x,%x] sent IPI to RX server thread[%x,%x]\n",
[619]261__FUNCTION__, this->process->pid, this->trdid, server_pid, server_trdid );
[457]262#endif
263
[450]264    }
265 
[625]266    // 5. release lock protecting chdev queue
[564]267    remote_busylock_release( lock_xp );
[440]268
[408]269    // deschedule
270    sched_yield("blocked on I/O");
[407]271
[438]272#if DEBUG_CHDEV_CMD_RX
[437]273rx_cycle = (uint32_t)hal_get_cycles();
[438]274if( (is_rx) && (DEBUG_CHDEV_CMD_RX < rx_cycle) )
[625]275printk("\n[%s] client thread[%x,%x] exit for RX / cycle %d\n",
[593]276__FUNCTION__, this->process->pid, this->trdid, rx_cycle );
[433]277#endif
278
[438]279#if DEBUG_CHDEV_CMD_TX
[437]280tx_cycle = (uint32_t)hal_get_cycles();
[438]281if( (is_rx == 0) && (DEBUG_CHDEV_CMD_TX < tx_cycle) )
[625]282printk("\n[%s] client thread[%x,%x] exit for TX / cycle %d\n",
[593]283__FUNCTION__, this->process->pid, this->trdid, tx_cycle );
[437]284#endif
285
[438]286#if (DEBUG_SYS_READ & 1)
[435]287exit_chdev_cmd_read = (uint32_t)hal_get_cycles();
[418]288#endif
289
[438]290#if (DEBUG_SYS_WRITE & 1)
[435]291exit_chdev_cmd_write = (uint32_t)hal_get_cycles();
292#endif
293
[5]294}  // end chdev_register_command()
295
[619]296/////////////////////////////////////////
297void chdev_server_func( chdev_t * chdev )
[5]298{
299    xptr_t          client_xp;    // extended pointer on waiting thread
300    cxy_t           client_cxy;   // cluster of client thread
301    thread_t      * client_ptr;   // local pointer on client thread
[407]302    thread_t      * server;       // local pointer on server thread
[5]303    xptr_t          root_xp;      // extended pointer on device waiting queue root
[407]304    xptr_t          lock_xp;      // extended pointer on lock ptotecting chdev queue
[5]305
306    server = CURRENT_THREAD;
307
[619]308#if( DEBUG_CHDEV_SERVER_RX || DEBUG_CHDEV_SERVER_TX )
[564]309uint32_t rx_cycle = (uint32_t)hal_get_cycles();
310if( (chdev->is_rx) && (DEBUG_CHDEV_SERVER_RX < rx_cycle) )
[662]311printk("\n[%s] RX server thread[%x,%x] enter / channel %d / cycle %d\n",
[619]312__FUNCTION__ , server->process->pid, server->trdid, chdev->channel, rx_cycle );
[564]313#endif
314
315#if DEBUG_CHDEV_SERVER_TX
316uint32_t tx_cycle = (uint32_t)hal_get_cycles();
317if( (chdev->is_rx == 0) && (DEBUG_CHDEV_SERVER_TX < tx_cycle) )
[662]318printk("\n[%s] TX server thread[%x,%x] enter / channel %d / cycle %d\n",
[619]319__FUNCTION__ , server->process->pid, server->trdid, chdev->channel, tx_cycle );
[564]320#endif
321
[662]322    // build extended pointer on root & lock of client threads queue
323    root_xp = XPTR( local_cxy , &chdev->wait_root );
324    lock_xp = XPTR( local_cxy , &chdev->wait_lock );
325
326        // This infinite loop is executed by the DEV thread
327    // to handle commands registered in the chdev queue.
328    while( 1 )
329    {
[601]330        // check server thread can yield
331        thread_assert_can_yield( server , __FUNCTION__ );
332
[407]333        // get the lock protecting the waiting queue
[564]334        remote_busylock_acquire( lock_xp );
[407]335
[5]336        // check waiting queue state
[662]337        if( xlist_is_empty( root_xp ) )                      // waiting queue empty
[5]338        {
[601]339            // release lock protecting the waiting queue
340            remote_busylock_release( lock_xp );
[564]341
342#if DEBUG_CHDEV_SERVER_RX
343rx_cycle = (uint32_t)hal_get_cycles();
344if( (chdev->is_rx) && (DEBUG_CHDEV_SERVER_RX < rx_cycle) )
[662]345printk("\n[%s] RX server thread[%x,%x] blocks & deschedules / cycle %d\n",
[593]346__FUNCTION__ , server->process->pid, server->trdid, rx_cycle );
[564]347#endif
348
349#if DEBUG_CHDEV_SERVER_TX
350tx_cycle = (uint32_t)hal_get_cycles();
351if( (chdev->is_rx == 0) && (DEBUG_CHDEV_SERVER_TX < tx_cycle) )
[662]352printk("\n[%s] TX server thread[%x,%x] blocks & deschedules / cycle %d\n",
[593]353__FUNCTION__ , server->process->pid, server->trdid, tx_cycle );
[564]354#endif
[662]355            // block and deschedule
[657]356            thread_block( XPTR( local_cxy , server ) , THREAD_BLOCKED_CLIENT ); 
[662]357            sched_yield("clients queue empty");
[440]358
[662]359#if DEBUG_CHDEV_SERVER_RX
360rx_cycle = (uint32_t)hal_get_cycles();
361if( (chdev->is_rx) && (DEBUG_CHDEV_SERVER_RX < rx_cycle) )
362printk("\n[%s] RX server thread[%x,%x] resumes / cycle %d\n",
363__FUNCTION__ , server->process->pid, server->trdid, rx_cycle );
364#endif
365
366#if DEBUG_CHDEV_SERVER_TX
367tx_cycle = (uint32_t)hal_get_cycles();
368if( (chdev->is_rx == 0) && (DEBUG_CHDEV_SERVER_TX < tx_cycle) )
369printk("\n[%s] TX server thread[%x,%x] resumes / cycle %d\n",
370__FUNCTION__ , server->process->pid, server->trdid, tx_cycle );
371#endif
372
[5]373        } 
[662]374        else                                               // waiting queue not empty
[5]375        {
[657]376            // get pointers on first client thread
377            client_xp  = XLIST_FIRST( root_xp , thread_t , wait_list );
378            client_cxy = GET_CXY( client_xp );
379            client_ptr = GET_PTR( client_xp );
380
381            // remove this client thread from chdev waiting queue
382            xlist_unlink( XPTR( client_cxy , &client_ptr->wait_list ) );
383
[601]384            // release lock protecting the waiting queue
385            remote_busylock_release( lock_xp );
386
[619]387#if( DEBUG_CHDEV_SERVER_TX || DEBUG_CHDEV_SERVER_RX )
[601]388process_t * process      = hal_remote_lpt( XPTR( client_cxy , &client_ptr->process ) );
389pid_t       client_pid   = hal_remote_l32( XPTR( client_cxy , &process->pid ) );
[619]390trdid_t     client_trdid = hal_remote_l32( XPTR( client_cxy , &client_ptr->trdid ) );
[601]391#endif
[440]392
[438]393#if DEBUG_CHDEV_SERVER_RX
[564]394rx_cycle = (uint32_t)hal_get_cycles();
[438]395if( (chdev->is_rx) && (DEBUG_CHDEV_SERVER_RX < rx_cycle) )
[625]396printk("\n[%s] server thread[%x,%x] get command from client thread[%x,%x] / cycle %d\n",
[619]397__FUNCTION__, server->process->pid, server->trdid, client_pid, client_trdid, rx_cycle );
[437]398#endif
399
[438]400#if DEBUG_CHDEV_SERVER_TX
[564]401tx_cycle = (uint32_t)hal_get_cycles();
[438]402if( (chdev->is_rx == 0) && (DEBUG_CHDEV_SERVER_TX < tx_cycle) )
[625]403printk("\n[%s] server thread[%x,%x] get command from client thread[%x,%x] / cycle %d\n",
[619]404__FUNCTION__, server->process->pid, server->trdid, client_pid, client_trdid, tx_cycle );
[437]405#endif
406
[438]407#if (DEBUG_SYS_READ & 1)
[437]408enter_chdev_server_read = (uint32_t)hal_get_cycles();
409#endif
410
[438]411#if (DEBUG_SYS_WRITE & 1)
[437]412enter_chdev_server_write = (uint32_t)hal_get_cycles();
413#endif
414
[601]415            // call the (blocking) driver command function
416            // to launch I/O operation AND wait completion
[407]417            chdev->cmd( client_xp );
[5]418       
[601]419            // unblock client thread when driver returns
[418]420            thread_unblock( client_xp , THREAD_BLOCKED_IO );
421
[438]422#if DEBUG_CHDEV_SERVER_RX
[437]423rx_cycle = (uint32_t)hal_get_cycles();
[438]424if( (chdev->is_rx) && (DEBUG_CHDEV_SERVER_RX < rx_cycle) )
[625]425printk("\n[%s] thread[%x,%x] completes command for client thread[%x,%x] / cycle %d\n",
[619]426__FUNCTION__, server->process->pid, server->trdid, client_pid, client_trdid, rx_cycle );
[433]427#endif
[5]428
[438]429#if DEBUG_CHDEV_SERVER_TX
[437]430tx_cycle = (uint32_t)hal_get_cycles();
[438]431if( (chdev->is_rx == 0) && (DEBUG_CHDEV_SERVER_TX < tx_cycle) )
[625]432printk("\n[%s] thread[%x,%x] completes command for client thread[%x,%x] / cycle %d\n",
[662]433__FUNCTION__, server->process->pid, server->trdid, client_pid, client_trdid, tx_cycle );
[437]434#endif
435
[438]436#if (DEBUG_SYS_READ & 1)
[435]437exit_chdev_server_read = (uint32_t)hal_get_cycles();
[407]438#endif
439
[438]440#if (DEBUG_SYS_WRITE & 1)
[435]441exit_chdev_server_write = (uint32_t)hal_get_cycles();
442#endif
443
[407]444        }
[5]445    }  // end while
[619]446}  // end chdev_server_func()
[5]447
[428]448////////////////////////////////////////
449xptr_t chdev_from_file( xptr_t file_xp )
450{
451    cxy_t         file_cxy;
452    vfs_file_t  * file_ptr;
453    uint32_t      inode_type;
454    vfs_inode_t * inode_ptr;
455    chdev_t     * chdev_ptr;
456
[683]457assert( __FUNCTION__, (file_xp != XPTR_NULL) ,
458"file_xp == XPTR_NULL" );
[440]459
[428]460    // get cluster and local pointer on remote file descriptor
461    // associated inode and chdev are stored in same cluster as the file desc.
462    file_cxy  = GET_CXY( file_xp );
463    file_ptr  = (vfs_file_t *)GET_PTR( file_xp );
464
465    // get inode type from file descriptor
[564]466    inode_type = hal_remote_l32( XPTR( file_cxy , &file_ptr->type ) );
[428]467    inode_ptr  = (vfs_inode_t *)hal_remote_lpt( XPTR( file_cxy , &file_ptr->inode ) );
468
[683]469assert( __FUNCTION__, (inode_type == FILE_TYPE_DEV) ,
470"inode type %d is not FILE_TYPE_DEV", inode_type );
[428]471
472    // get chdev local pointer from inode extension
473    chdev_ptr = (chdev_t *)hal_remote_lpt( XPTR( file_cxy , &inode_ptr->extend ) );
474
475    return XPTR( file_cxy , chdev_ptr );
476
477}  // end chdev_from_file()
478
[564]479//////////////////////////////
[485]480void chdev_dir_display( void )
[317]481{
[428]482    uint32_t  i;
483    cxy_t     cxy;
484    chdev_t * ptr;
485    uint32_t  base;
[317]486
[428]487    // get pointers on TXT0 chdev
488    xptr_t    txt0_xp  = chdev_dir.txt_tx[0];
489    cxy_t     txt0_cxy = GET_CXY( txt0_xp );
490    chdev_t * txt0_ptr = GET_PTR( txt0_xp );
[317]491
[564]492    // get extended pointer on TXT0 lock
[428]493    xptr_t  lock_xp = XPTR( txt0_cxy , &txt0_ptr->wait_lock );
[317]494
[564]495    // get TXT0 lock
496    remote_busylock_acquire( lock_xp );
[317]497
[428]498    // header
499    nolock_printk("\n***** external chdevs directory *****\n");
[317]500
[428]501    // IOB
[564]502    if (chdev_dir.iob != XPTR_NULL )
[545]503    {
504        cxy  = GET_CXY( chdev_dir.iob );
505        ptr  = GET_PTR( chdev_dir.iob );
[564]506        base = (uint32_t)hal_remote_l64( XPTR( cxy , &ptr->base ) );
[545]507        nolock_printk("  - iob       : cxy = %X / ptr = %X / base = %X\n", cxy, ptr, base);
508    }
[407]509
[428]510    // PIC
511    cxy  = GET_CXY( chdev_dir.pic );
512    ptr  = GET_PTR( chdev_dir.pic );
[564]513    base = (uint32_t)hal_remote_l64( XPTR( cxy , &ptr->base ) );
[428]514    nolock_printk("  - pic       : cxy = %X / ptr = %X / base = %X\n", cxy, ptr, base);
[407]515
[428]516    // TXT
517    for( i = 0 ; i < LOCAL_CLUSTER->nb_txt_channels ; i++ )
518    {
519        cxy = GET_CXY( chdev_dir.txt_rx[i] );
520        ptr = GET_PTR( chdev_dir.txt_rx[i] );
[564]521        base = (uint32_t)hal_remote_l64( XPTR( cxy , &ptr->base ) );
[428]522        nolock_printk("  - txt_rx[%d] : cxy = %X / ptr = %X / base = %X\n", i, cxy, ptr, base);
[407]523
[428]524        cxy = GET_CXY( chdev_dir.txt_tx[i] );
525        ptr = GET_PTR( chdev_dir.txt_tx[i] );
[564]526        base = (uint32_t)hal_remote_l64( XPTR( cxy , &ptr->base ) );
[428]527        nolock_printk("  - txt_tx[%d] : cxy = %X / ptr = %X / base = %X\n", i, cxy, ptr, base);
528    }
[317]529
[428]530    // IOC
531    for( i = 0 ; i < LOCAL_CLUSTER->nb_ioc_channels ; i++ )
532    {
533        cxy = GET_CXY( chdev_dir.ioc[i] );
534        ptr = GET_PTR( chdev_dir.ioc[i] );
[564]535        base = (uint32_t)hal_remote_l64( XPTR( cxy , &ptr->base ) );
[428]536        nolock_printk("  - ioc[%d]    : cxy = %X / ptr = %X / base = %X\n", i, cxy, ptr, base);
537    }
[317]538
[428]539    // FBF
540    for( i = 0 ; i < LOCAL_CLUSTER->nb_fbf_channels ; i++ )
541    {
542        cxy  = GET_CXY( chdev_dir.fbf[i] );
543        ptr  = GET_PTR( chdev_dir.fbf[i] );
[564]544        base = (uint32_t)hal_remote_l64( XPTR( cxy , &ptr->base ) );
[428]545        nolock_printk("  - fbf[%d]    : cxy = %X / ptr = %X / base = %X\n", i, cxy, ptr, base);
546    }
[317]547
[428]548    // NIC
549    for( i = 0 ; i < LOCAL_CLUSTER->nb_nic_channels ; i++ )
550    {
551        cxy = GET_CXY( chdev_dir.nic_rx[i] );
552        ptr = GET_PTR( chdev_dir.nic_rx[i] );
[564]553        base = (uint32_t)hal_remote_l64( XPTR( cxy , &ptr->base ) );
[428]554        nolock_printk("  - nic_rx[%d] : cxy = %X / ptr = %X / base = %X\n", i, cxy, ptr, base);
[317]555
[428]556        cxy = GET_CXY( chdev_dir.nic_tx[i] );
557        ptr = GET_PTR( chdev_dir.nic_tx[i] );
[564]558        base = (uint32_t)hal_remote_l64( XPTR( cxy , &ptr->base ) );
[428]559        nolock_printk("  - nic_tx[%d] : cxy = %X / ptr = %X / base = %X\n", i, cxy, ptr, base);
560    }
[317]561
[428]562    // release lock
[564]563    remote_busylock_release( lock_xp );
[428]564
[317]565}  // end chdev_dir_display()
566
[447]567///////////////////////////////////////////
568void chdev_queue_display( xptr_t chdev_xp )
569{
570    cxy_t       chdev_cxy;          // chdev cluster
571    chdev_t   * chdev_ptr;          // chdev local pointer
572    xptr_t      root_xp;            // extended pointer on waiting queuue root
573    char        name[16];           // local copie of chdev name
574    xptr_t      iter_xp;            // extended pointer on xlist_t field in waiting thread
575    xptr_t      thread_xp;          // extended pointer on thread registered in queue
576    cxy_t       thread_cxy;         // cluster identifier for waiting thread
577    thread_t  * thread_ptr;         // local pointer on waiting thread
578    trdid_t     trdid;              // waiting thread identifier
579    process_t * process;            // waiting thread process descriptor
580    pid_t       pid;                // waiting thread process identifier
581
582    // get cluster and local pointer on chdev
583    chdev_cxy = GET_CXY( chdev_xp );
584    chdev_ptr = GET_PTR( chdev_xp );
585
586    // get extended pointer on root of requests queue
[450]587    root_xp = XPTR( chdev_cxy , &chdev_ptr->wait_root );
[447]588
589    // get chdev name
590    hal_remote_strcpy( XPTR( local_cxy , name ), XPTR( chdev_cxy , chdev_ptr->name ) );
591
[564]592    // get pointers on TXT0 chdev
593    xptr_t    txt0_xp  = chdev_dir.txt_tx[0];
594    cxy_t     txt0_cxy = GET_CXY( txt0_xp );
595    chdev_t * txt0_ptr = GET_PTR( txt0_xp );
596
597    // get extended pointer on TXT0 lock
598    xptr_t  lock_xp = XPTR( txt0_cxy , &txt0_ptr->wait_lock );
599
600    // get TXT0 lock
601    remote_busylock_acquire( lock_xp );
602
[447]603    // check queue empty
604    if( xlist_is_empty( root_xp ) )
605    {
[564]606        nolock_printk("\n***** Waiting queue empty for chdev %s\n", name ); 
[447]607    }
608    else
609    {
[564]610        nolock_printk("\n***** Waiting queue for chdev %s\n", name ); 
[447]611
612        // scan the waiting queue
613        XLIST_FOREACH( root_xp , iter_xp )
614        {
615            thread_xp  = XLIST_ELEMENT( iter_xp , thread_t , wait_list );
616            thread_cxy = GET_CXY( thread_xp );
617            thread_ptr = GET_PTR( thread_xp );
[564]618            trdid      = hal_remote_l32 ( XPTR( thread_cxy , &thread_ptr->trdid   ) );
[447]619            process    = hal_remote_lpt( XPTR( thread_cxy , &thread_ptr->process ) );
[564]620                        pid        = hal_remote_l32 ( XPTR( thread_cxy , &process->pid        ) );
[447]621
[601]622            nolock_printk("- thread[%x,%x]\n", pid, trdid );
[447]623        }
624    }
[564]625
626    // release TXT0 lock
627    remote_busylock_release( lock_xp );
628
[447]629}  // end chdev_queue_display()
630
Note: See TracBrowser for help on using the repository browser.