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

Last change on this file since 615 was 601, checked in by alain, 6 years ago

Improve the FAT32 file system to support cat, rm, cp commands.

File size: 22.2 KB
RevLine 
[5]1/*
2 * chdev.c - channel device descriptor operations implementation.
3 *
4 * Authors  Alain Greiner   (2016)
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    kmem_req_t   req;
90
91    // allocate memory for chdev
92    req.type   = KMEM_DEVICE;
93    req.flags  = AF_ZERO;
94    chdev      = (chdev_t *)kmem_alloc( &req );
95
96    if( chdev == NULL ) return NULL;
97
[564]98    // initialize lock
99    remote_busylock_init( XPTR( local_cxy , &chdev->wait_lock ), LOCK_CHDEV_QUEUE );
100
101    // initialise waiting queue
[5]102    xlist_root_init( XPTR( local_cxy , &chdev->wait_root ) );
103
104    // initialize attributes
105    chdev->func    =  func;
106    chdev->impl    =  impl;
107    chdev->channel =  channel;
108    chdev->is_rx   =  is_rx;
109    chdev->base    =  base; 
110
111    return chdev;
112
113}  // end chdev_create()
114
115///////////////////////////////////
116void chdev_print( chdev_t * chdev )
117{
118    printk("\n - func      = %s"
119           "\n - channel   = %d"
120           "\n - base      = %l"
121           "\n - cmd       = %x"
122           "\n - isr       = %x"
123           "\n - chdev     = %x\n",
124           chdev_func_str(chdev->func),
125           chdev->channel,
126           chdev->base,
127           chdev->cmd,
128           chdev->isr,
129           chdev );
130}
131
[407]132//////////////////////////////////////////////////
133void chdev_register_command( xptr_t     chdev_xp )
[5]134{
[407]135    thread_t * server_ptr;    // local pointer on server thread associated to chdev
[440]136    xptr_t     server_xp;     // extended pointer on server thread
[407]137    core_t   * core_ptr;      // local pointer on core running the server thread
[457]138    uint32_t   server_lid;    // core running the server thread local index
[564]139    xptr_t     lock_xp;       // extended pointer on lock protecting the chdev state
[407]140    uint32_t   save_sr;       // for critical section
[5]141
[438]142#if (DEBUG_SYS_READ & 1)
[435]143enter_chdev_cmd_read = (uint32_t)hal_get_cycles();
[418]144#endif
145
[438]146#if (DEBUG_SYS_WRITE & 1)
[435]147enter_chdev_cmd_write = (uint32_t)hal_get_cycles();
148#endif
149
[407]150    thread_t * this = CURRENT_THREAD;
151
[440]152    // get chdev cluster and local pointer
[5]153    cxy_t     chdev_cxy = GET_CXY( chdev_xp );
[440]154    chdev_t * chdev_ptr = GET_PTR( chdev_xp );
[5]155
[581]156    // check calling thread can yield
157    thread_assert_can_yield( this , __FUNCTION__ );
[564]158
[440]159    // get local and extended pointers on server thread
160    server_ptr = (thread_t *)hal_remote_lpt( XPTR( chdev_cxy , &chdev_ptr->server) );
161    server_xp  = XPTR( chdev_cxy , server_ptr );
162
163    // get local pointer on core running the server thread
164    core_ptr   = (core_t *)hal_remote_lpt( XPTR( chdev_cxy , &server_ptr->core ) );
165
166    // get server core local index
[564]167    server_lid = hal_remote_l32( XPTR( chdev_cxy , &core_ptr->lid ) );
[440]168
[438]169#if (DEBUG_CHDEV_CMD_RX || DEBUG_CHDEV_CMD_TX)
[564]170bool_t is_rx = hal_remote_l32( XPTR( chdev_cxy , &chdev_ptr->is_rx ) );
[437]171#endif
172   
[438]173#if DEBUG_CHDEV_CMD_RX
[437]174uint32_t rx_cycle = (uint32_t)hal_get_cycles();
[438]175if( (is_rx) && (DEBUG_CHDEV_CMD_RX < rx_cycle) )
[593]176printk("\n[%s] client[%x,%x] enter for RX / server[%x,%x] / cycle %d\n",
[601]177__FUNCTION__, this->process->pid, this->trdid, 
178server_ptr->process->pid, server_ptr->trdid, rx_cycle );
[437]179#endif
180
[438]181#if DEBUG_CHDEV_CMD_TX
[437]182uint32_t tx_cycle = (uint32_t)hal_get_cycles();
[438]183if( (is_rx == 0) && (DEBUG_CHDEV_CMD_TX < tx_cycle) )
[593]184printk("\n[%s] client[%x,%x] enter for TX / server[%x,%x] / cycle %d\n",
[601]185__FUNCTION__, this->process->pid, this->trdid, 
186server_ptr->process->pid, server_ptr->trdid, tx_cycle );
[437]187#endif
188
[440]189    // build extended pointer on client thread xlist
190    xptr_t  list_xp    = XPTR( local_cxy , &this->wait_list );
[5]191
[440]192    // build extended pointer on chdev waiting queue root
193    xptr_t  root_xp    = XPTR( chdev_cxy , &chdev_ptr->wait_root );
[5]194
[440]195    // build extended pointer on server thread blocked state
196    xptr_t  blocked_xp = XPTR( chdev_cxy , &server_ptr->blocked );
197
198    // build extended pointer on lock protecting chdev waiting queue
[564]199    lock_xp            = XPTR( chdev_cxy , &chdev_ptr->wait_lock );
[407]200
[581]201    // TODO the hal_disable_irq() / hal_restore_irq()
202    // in the sequence below is probably useless, as it is
203    // already done by the busylock_acquire() / busylock_release()
204    // => remove it [AG] october 2018
205
[450]206    // critical section for the following sequence:
[564]207    // (1) take the lock protecting the chdev state
[440]208    // (2) block the client thread
209    // (3) unblock the server thread if required
210    // (4) register client thread in server queue
211    // (5) send IPI to force server scheduling
212    // (6) release the lock protecting waiting queue
213    // (7) deschedule
[407]214
[440]215    // enter critical section
216    hal_disable_irq( &save_sr );
[407]217
[564]218    // take the lock protecting chdev queue
219    remote_busylock_acquire( lock_xp );
[408]220
221    // block current thread
[436]222    thread_block( XPTR( local_cxy , CURRENT_THREAD ) , THREAD_BLOCKED_IO );
[408]223
[450]224#if (DEBUG_CHDEV_CMD_TX & 1)
225if( (is_rx == 0) && (DEBUG_CHDEV_CMD_TX < tx_cycle) )
[593]226printk("\n[%s] client thread[%x,%x] blocked\n",
[601]227__FUNCTION__, this->process->pid, this->trdid );
[450]228#endif
229
[457]230#if (DEBUG_CHDEV_CMD_RX & 1)
231if( (is_rx) && (DEBUG_CHDEV_CMD_RX < rx_cycle) )
[593]232printk("\n[%s] client thread[%x,%x] blocked\n",
233__FUNCTION__, this->process_pid, this->trdid );
[457]234#endif
235
[446]236    // unblock server thread if required
[564]237    if( hal_remote_l32( blocked_xp ) & THREAD_BLOCKED_IDLE )
[440]238    thread_unblock( server_xp , THREAD_BLOCKED_IDLE );
239
[450]240#if (DEBUG_CHDEV_CMD_TX & 1)
241if( (is_rx == 0) && (DEBUG_CHDEV_CMD_TX < tx_cycle) )
[593]242printk("\n[%s] TX server thread[%x,%x] unblocked\n",
243__FUNCTION__, server_ptr->process->pid, server_ptr->trdid );
[450]244#endif
245
[457]246#if (DEBUG_CHDEV_CMD_RX & 1)
247if( (is_rx) && (DEBUG_CHDEV_CMD_RX < rx_cycle) )
[593]248printk("\n[%s] RX server thread[%x,%x] unblocked\n",
249__FUNCTION__, server_ptr->process->pid, server_ptr->trdid );
[457]250#endif
251
[5]252    // register client thread in waiting queue
[407]253    xlist_add_last( root_xp , list_xp );
[5]254
[450]255#if (DEBUG_CHDEV_CMD_TX & 1)
256if( (is_rx == 0)  && (DEBUG_CHDEV_CMD_TX < tx_cycle) )
[593]257printk("\n[%s] client thread[%x,%x] registered write request in chdev\n",
258__FUNCTION__, this->process->pid, this->trdid );
[450]259#endif
260 
[457]261#if (DEBUG_CHDEV_CMD_RX & 1)
262if( (is_rx)  && (DEBUG_CHDEV_CMD_RX < rx_cycle) )
[593]263printk("\n[%s] client thread[%x,%x] registered read request in chdev\n",
264__FUNCTION__, this->process->pid, this->trdid );
[457]265#endif
266 
[564]267    // send IPI to core running the server thread when server core != client core
[457]268    if( (server_lid != this->core->lid) || (local_cxy != chdev_cxy) )
[450]269    {
[457]270        dev_pic_send_ipi( chdev_cxy , server_lid ); 
271
[450]272#if (DEBUG_CHDEV_CMD_TX & 1)
273if( (is_rx == 0)  && (DEBUG_CHDEV_CMD_TX < tx_cycle) )
[593]274printk("\n[%s] client thread[%x,%x] sent IPI to TX server thread[%x,%x]\n",
275__FUNCTION__, this->process->pid, this->trdid, server_ptr->process->pid, server_ptr->trdid );
[450]276#endif
277
[457]278#if (DEBUG_CHDEV_CMD_RX & 1)
279if( (is_rx)  && (DEBUG_CHDEV_CMD_RX < rx_cycle) )
[593]280printk("\n[%s] client thread[%x,%x] sent IPI to RX server thread[%x,%x]\n",
281__FUNCTION__, this->process->pid, this->trdid, server_ptr->process->pid, server_ptr->trdid );
[457]282#endif
283
[450]284    }
285 
[564]286    // release lock protecting chdev queue
287    remote_busylock_release( lock_xp );
[440]288
[408]289    // deschedule
290    sched_yield("blocked on I/O");
[407]291
292    // exit critical section
293    hal_restore_irq( save_sr );
294
[438]295#if DEBUG_CHDEV_CMD_RX
[437]296rx_cycle = (uint32_t)hal_get_cycles();
[438]297if( (is_rx) && (DEBUG_CHDEV_CMD_RX < rx_cycle) )
[593]298printk("\n[%s] client_thread[%x,%x] exit for RX / cycle %d\n",
299__FUNCTION__, this->process->pid, this->trdid, rx_cycle );
[433]300#endif
301
[438]302#if DEBUG_CHDEV_CMD_TX
[437]303tx_cycle = (uint32_t)hal_get_cycles();
[438]304if( (is_rx == 0) && (DEBUG_CHDEV_CMD_TX < tx_cycle) )
[593]305printk("\n[%s] client_thread[%x,%x] exit for TX / cycle %d\n",
306__FUNCTION__, this->process->pid, this->trdid, tx_cycle );
[437]307#endif
308
[438]309#if (DEBUG_SYS_READ & 1)
[435]310exit_chdev_cmd_read = (uint32_t)hal_get_cycles();
[418]311#endif
312
[438]313#if (DEBUG_SYS_WRITE & 1)
[435]314exit_chdev_cmd_write = (uint32_t)hal_get_cycles();
315#endif
316
[5]317}  // end chdev_register_command()
318
319///////////////////////////////////////////////
320void chdev_sequencial_server( chdev_t * chdev )
321{
322    xptr_t          client_xp;    // extended pointer on waiting thread
323    cxy_t           client_cxy;   // cluster of client thread
324    thread_t      * client_ptr;   // local pointer on client thread
[407]325    thread_t      * server;       // local pointer on server thread
[5]326    xptr_t          root_xp;      // extended pointer on device waiting queue root
[407]327    xptr_t          lock_xp;      // extended pointer on lock ptotecting chdev queue
[5]328
329    server = CURRENT_THREAD;
330
[564]331    // build extended pointer on root of client threads queue
[5]332    root_xp = XPTR( local_cxy , &chdev->wait_root );
[564]333
334    // build extended pointer on lock protecting client threads queue
[407]335    lock_xp = XPTR( local_cxy , &chdev->wait_lock );
[5]336
[407]337        // This infinite loop is executed by the DEV thread
338    // to handle commands registered in the chdev queue.
[5]339    while( 1 )
340    {
[564]341
342#if DEBUG_CHDEV_SERVER_RX
343uint32_t rx_cycle = (uint32_t)hal_get_cycles();
344if( (chdev->is_rx) && (DEBUG_CHDEV_SERVER_RX < rx_cycle) )
[601]345printk("\n[%s] thread[%x,%x] start RX / cycle %d\n",
[593]346__FUNCTION__ , server->process->pid, server->trdid, rx_cycle );
[564]347#endif
348
349#if DEBUG_CHDEV_SERVER_TX
350uint32_t tx_cycle = (uint32_t)hal_get_cycles();
351if( (chdev->is_rx == 0) && (DEBUG_CHDEV_SERVER_TX < tx_cycle) )
[601]352printk("\n[%s] thread[%x,%x] start TX / cycle %d\n",
[593]353__FUNCTION__ , server->process->pid, server->trdid, tx_cycle );
[564]354#endif
355
[601]356        // check server thread can yield
357        thread_assert_can_yield( server , __FUNCTION__ );
358
[407]359        // get the lock protecting the waiting queue
[564]360        remote_busylock_acquire( lock_xp );
[407]361
[5]362        // check waiting queue state
[407]363        if( xlist_is_empty( root_xp ) ) // waiting queue empty
[5]364        {
[601]365            // release lock protecting the waiting queue
366            remote_busylock_release( lock_xp );
[564]367
368#if DEBUG_CHDEV_SERVER_RX
369rx_cycle = (uint32_t)hal_get_cycles();
370if( (chdev->is_rx) && (DEBUG_CHDEV_SERVER_RX < rx_cycle) )
[601]371printk("\n[%s] thread[%x,%x] found RX queue empty => blocks / cycle %d\n",
[593]372__FUNCTION__ , server->process->pid, server->trdid, rx_cycle );
[564]373#endif
374
375#if DEBUG_CHDEV_SERVER_TX
376tx_cycle = (uint32_t)hal_get_cycles();
377if( (chdev->is_rx == 0) && (DEBUG_CHDEV_SERVER_TX < tx_cycle) )
[601]378printk("\n[%s] thread[%x,%x] found TX queue empty => blocks / cycle %d\n",
[593]379__FUNCTION__ , server->process->pid, server->trdid, tx_cycle );
[564]380#endif
[440]381            // block
382            thread_block( XPTR( local_cxy , server ) , THREAD_BLOCKED_IDLE ); 
383
[408]384            // deschedule
385            sched_yield("I/O queue empty");
[5]386        } 
[407]387        else                            // waiting queue not empty
[5]388        {
[601]389            // release lock protecting the waiting queue
390            remote_busylock_release( lock_xp );
391
[407]392            // get extended pointer on first client thread
[564]393            client_xp = XLIST_FIRST( root_xp , thread_t , wait_list );
[5]394
[440]395            // get client thread cluster and local pointer
[407]396            client_cxy = GET_CXY( client_xp );
[440]397            client_ptr = GET_PTR( client_xp );
[407]398
[601]399#if( DDEBUG_CHDEV_SERVER_TX || DEBUG_CHDEV_SERVER_RX )
400process_t * process      = hal_remote_lpt( XPTR( client_cxy , &client_ptr->process ) );
401pid_t       client_pid   = hal_remote_l32( XPTR( client_cxy , &process->pid ) );
402process_t   client_trdid = hal_remote_l32( XPTR( client_cxy , &client_ptr->trdid ) );
403#endif
[440]404
[438]405#if DEBUG_CHDEV_SERVER_RX
[564]406rx_cycle = (uint32_t)hal_get_cycles();
[438]407if( (chdev->is_rx) && (DEBUG_CHDEV_SERVER_RX < rx_cycle) )
[601]408printk("\n[%s] thread[%x,%x] for RX get client thread[%x,%x] / cycle %d\n",
409__FUNCTION__, server->process->pid, server->trdid, client_pid, client_trdid, cycle );
[437]410#endif
411
[438]412#if DEBUG_CHDEV_SERVER_TX
[564]413tx_cycle = (uint32_t)hal_get_cycles();
[438]414if( (chdev->is_rx == 0) && (DEBUG_CHDEV_SERVER_TX < tx_cycle) )
[601]415printk("\n[%s] thread[%x,%x] for TX get client thread[%x,%x] / cycle %d\n",
416__FUNCTION__, server->process->pid, server->trdid, client_pid, client_trdid, cycle );
[437]417#endif
418
[438]419#if (DEBUG_SYS_READ & 1)
[437]420enter_chdev_server_read = (uint32_t)hal_get_cycles();
421#endif
422
[438]423#if (DEBUG_SYS_WRITE & 1)
[437]424enter_chdev_server_write = (uint32_t)hal_get_cycles();
425#endif
426
[601]427            // call the (blocking) driver command function
428            // to launch I/O operation AND wait completion
[407]429            chdev->cmd( client_xp );
[5]430       
[601]431            // unblock client thread when driver returns
[418]432            thread_unblock( client_xp , THREAD_BLOCKED_IO );
433
[601]434            // get the lock protecting the waiting queue
435            remote_busylock_acquire( lock_xp );
436
437            // remove this client thread from chdev waiting queue
438            xlist_unlink( XPTR( client_cxy , &client_ptr->wait_list ) );
439
440            // release lock protecting the waiting queue
441            remote_busylock_release( lock_xp );
442
[438]443#if DEBUG_CHDEV_SERVER_RX
[437]444rx_cycle = (uint32_t)hal_get_cycles();
[438]445if( (chdev->is_rx) && (DEBUG_CHDEV_SERVER_RX < rx_cycle) )
[601]446printk("\n[%s] thread[%x,%x] completes RX for client thread[%x,%x] / cycle %d\n",
447__FUNCTION__, server->process->pid, server->trdid, client_pid, client_trdid, cycle );
[433]448#endif
[5]449
[438]450#if DEBUG_CHDEV_SERVER_TX
[437]451tx_cycle = (uint32_t)hal_get_cycles();
[438]452if( (chdev->is_rx == 0) && (DEBUG_CHDEV_SERVER_TX < tx_cycle) )
[601]453printk("\n[%s] thread[%x,%x] completes TX for client thread[%x,%x] / cycle %d\n",
454__FUNCTION__, server->process->pid, server->trdid, client_pid, client_trdid, cycle );
[437]455#endif
456
[438]457#if (DEBUG_SYS_READ & 1)
[435]458exit_chdev_server_read = (uint32_t)hal_get_cycles();
[407]459#endif
460
[438]461#if (DEBUG_SYS_WRITE & 1)
[435]462exit_chdev_server_write = (uint32_t)hal_get_cycles();
463#endif
464
[407]465        }
[5]466    }  // end while
467}  // end chdev_sequencial_server()
468
[428]469////////////////////////////////////////
470xptr_t chdev_from_file( xptr_t file_xp )
471{
472    cxy_t         file_cxy;
473    vfs_file_t  * file_ptr;
474    uint32_t      inode_type;
475    vfs_inode_t * inode_ptr;
476    chdev_t     * chdev_ptr;
477
[492]478    assert( (file_xp != XPTR_NULL) ,
[440]479    "file_xp == XPTR_NULL\n" );
480
[428]481    // get cluster and local pointer on remote file descriptor
482    // associated inode and chdev are stored in same cluster as the file desc.
483    file_cxy  = GET_CXY( file_xp );
484    file_ptr  = (vfs_file_t *)GET_PTR( file_xp );
485
486    // get inode type from file descriptor
[564]487    inode_type = hal_remote_l32( XPTR( file_cxy , &file_ptr->type ) );
[428]488    inode_ptr  = (vfs_inode_t *)hal_remote_lpt( XPTR( file_cxy , &file_ptr->inode ) );
489
[492]490    assert( (inode_type == INODE_TYPE_DEV) ,
[440]491    "inode type %d is not INODE_TYPE_DEV\n", inode_type );
[428]492
493    // get chdev local pointer from inode extension
494    chdev_ptr = (chdev_t *)hal_remote_lpt( XPTR( file_cxy , &inode_ptr->extend ) );
495
496    return XPTR( file_cxy , chdev_ptr );
497
498}  // end chdev_from_file()
499
[564]500//////////////////////////////
[485]501void chdev_dir_display( void )
[317]502{
[428]503    uint32_t  i;
504    cxy_t     cxy;
505    chdev_t * ptr;
506    uint32_t  base;
[317]507
[428]508    // get pointers on TXT0 chdev
509    xptr_t    txt0_xp  = chdev_dir.txt_tx[0];
510    cxy_t     txt0_cxy = GET_CXY( txt0_xp );
511    chdev_t * txt0_ptr = GET_PTR( txt0_xp );
[317]512
[564]513    // get extended pointer on TXT0 lock
[428]514    xptr_t  lock_xp = XPTR( txt0_cxy , &txt0_ptr->wait_lock );
[317]515
[564]516    // get TXT0 lock
517    remote_busylock_acquire( lock_xp );
[317]518
[428]519    // header
520    nolock_printk("\n***** external chdevs directory *****\n");
[317]521
[428]522    // IOB
[564]523    if (chdev_dir.iob != XPTR_NULL )
[545]524    {
525        cxy  = GET_CXY( chdev_dir.iob );
526        ptr  = GET_PTR( chdev_dir.iob );
[564]527        base = (uint32_t)hal_remote_l64( XPTR( cxy , &ptr->base ) );
[545]528        nolock_printk("  - iob       : cxy = %X / ptr = %X / base = %X\n", cxy, ptr, base);
529    }
[407]530
[428]531    // PIC
532    cxy  = GET_CXY( chdev_dir.pic );
533    ptr  = GET_PTR( chdev_dir.pic );
[564]534    base = (uint32_t)hal_remote_l64( XPTR( cxy , &ptr->base ) );
[428]535    nolock_printk("  - pic       : cxy = %X / ptr = %X / base = %X\n", cxy, ptr, base);
[407]536
[428]537    // TXT
538    for( i = 0 ; i < LOCAL_CLUSTER->nb_txt_channels ; i++ )
539    {
540        cxy = GET_CXY( chdev_dir.txt_rx[i] );
541        ptr = GET_PTR( chdev_dir.txt_rx[i] );
[564]542        base = (uint32_t)hal_remote_l64( XPTR( cxy , &ptr->base ) );
[428]543        nolock_printk("  - txt_rx[%d] : cxy = %X / ptr = %X / base = %X\n", i, cxy, ptr, base);
[407]544
[428]545        cxy = GET_CXY( chdev_dir.txt_tx[i] );
546        ptr = GET_PTR( chdev_dir.txt_tx[i] );
[564]547        base = (uint32_t)hal_remote_l64( XPTR( cxy , &ptr->base ) );
[428]548        nolock_printk("  - txt_tx[%d] : cxy = %X / ptr = %X / base = %X\n", i, cxy, ptr, base);
549    }
[317]550
[428]551    // IOC
552    for( i = 0 ; i < LOCAL_CLUSTER->nb_ioc_channels ; i++ )
553    {
554        cxy = GET_CXY( chdev_dir.ioc[i] );
555        ptr = GET_PTR( chdev_dir.ioc[i] );
[564]556        base = (uint32_t)hal_remote_l64( XPTR( cxy , &ptr->base ) );
[428]557        nolock_printk("  - ioc[%d]    : cxy = %X / ptr = %X / base = %X\n", i, cxy, ptr, base);
558    }
[317]559
[428]560    // FBF
561    for( i = 0 ; i < LOCAL_CLUSTER->nb_fbf_channels ; i++ )
562    {
563        cxy  = GET_CXY( chdev_dir.fbf[i] );
564        ptr  = GET_PTR( chdev_dir.fbf[i] );
[564]565        base = (uint32_t)hal_remote_l64( XPTR( cxy , &ptr->base ) );
[428]566        nolock_printk("  - fbf[%d]    : cxy = %X / ptr = %X / base = %X\n", i, cxy, ptr, base);
567    }
[317]568
[428]569    // NIC
570    for( i = 0 ; i < LOCAL_CLUSTER->nb_nic_channels ; i++ )
571    {
572        cxy = GET_CXY( chdev_dir.nic_rx[i] );
573        ptr = GET_PTR( chdev_dir.nic_rx[i] );
[564]574        base = (uint32_t)hal_remote_l64( XPTR( cxy , &ptr->base ) );
[428]575        nolock_printk("  - nic_rx[%d] : cxy = %X / ptr = %X / base = %X\n", i, cxy, ptr, base);
[317]576
[428]577        cxy = GET_CXY( chdev_dir.nic_tx[i] );
578        ptr = GET_PTR( chdev_dir.nic_tx[i] );
[564]579        base = (uint32_t)hal_remote_l64( XPTR( cxy , &ptr->base ) );
[428]580        nolock_printk("  - nic_tx[%d] : cxy = %X / ptr = %X / base = %X\n", i, cxy, ptr, base);
581    }
[317]582
[428]583    // release lock
[564]584    remote_busylock_release( lock_xp );
[428]585
[317]586}  // end chdev_dir_display()
587
[447]588///////////////////////////////////////////
589void chdev_queue_display( xptr_t chdev_xp )
590{
591    cxy_t       chdev_cxy;          // chdev cluster
592    chdev_t   * chdev_ptr;          // chdev local pointer
593    xptr_t      root_xp;            // extended pointer on waiting queuue root
594    char        name[16];           // local copie of chdev name
595    xptr_t      iter_xp;            // extended pointer on xlist_t field in waiting thread
596    xptr_t      thread_xp;          // extended pointer on thread registered in queue
597    cxy_t       thread_cxy;         // cluster identifier for waiting thread
598    thread_t  * thread_ptr;         // local pointer on waiting thread
599    trdid_t     trdid;              // waiting thread identifier
600    process_t * process;            // waiting thread process descriptor
601    pid_t       pid;                // waiting thread process identifier
602
603    // get cluster and local pointer on chdev
604    chdev_cxy = GET_CXY( chdev_xp );
605    chdev_ptr = GET_PTR( chdev_xp );
606
607    // get extended pointer on root of requests queue
[450]608    root_xp = XPTR( chdev_cxy , &chdev_ptr->wait_root );
[447]609
610    // get chdev name
611    hal_remote_strcpy( XPTR( local_cxy , name ), XPTR( chdev_cxy , chdev_ptr->name ) );
612
[564]613    // get pointers on TXT0 chdev
614    xptr_t    txt0_xp  = chdev_dir.txt_tx[0];
615    cxy_t     txt0_cxy = GET_CXY( txt0_xp );
616    chdev_t * txt0_ptr = GET_PTR( txt0_xp );
617
618    // get extended pointer on TXT0 lock
619    xptr_t  lock_xp = XPTR( txt0_cxy , &txt0_ptr->wait_lock );
620
621    // get TXT0 lock
622    remote_busylock_acquire( lock_xp );
623
[447]624    // check queue empty
625    if( xlist_is_empty( root_xp ) )
626    {
[564]627        nolock_printk("\n***** Waiting queue empty for chdev %s\n", name ); 
[447]628    }
629    else
630    {
[564]631        nolock_printk("\n***** Waiting queue for chdev %s\n", name ); 
[447]632
633        // scan the waiting queue
634        XLIST_FOREACH( root_xp , iter_xp )
635        {
636            thread_xp  = XLIST_ELEMENT( iter_xp , thread_t , wait_list );
637            thread_cxy = GET_CXY( thread_xp );
638            thread_ptr = GET_PTR( thread_xp );
[564]639            trdid      = hal_remote_l32 ( XPTR( thread_cxy , &thread_ptr->trdid   ) );
[447]640            process    = hal_remote_lpt( XPTR( thread_cxy , &thread_ptr->process ) );
[564]641                        pid        = hal_remote_l32 ( XPTR( thread_cxy , &process->pid        ) );
[447]642
[601]643            nolock_printk("- thread[%x,%x]\n", pid, trdid );
[447]644        }
645    }
[564]646
647    // release TXT0 lock
648    remote_busylock_release( lock_xp );
649
[447]650}  // end chdev_queue_display()
651
Note: See TracBrowser for help on using the repository browser.