source: trunk/hal/tsar_mips32/drivers/soclib_bdv.c @ 622

Last change on this file since 622 was 622, checked in by viala@…, 5 years ago

Fix compilation warning about not defined function.

`
hal/tsar_mips32/drivers/soclib_bdv.c: In function 'soclib_bdv_cmd':
hal/tsar_mips32/drivers/soclib_bdv.c:161:9: warning:
implicit declaration of function 'hal_disable_irq';

did you mean 'dev_pic_disable_irq'? [-Wimplicit-function-declaration]

hal_disable_irq( &save_sr );

dev_pic_disable_irq

almos-mkh/hal/tsar_mips32/drivers/soclib_bdv.c:184:9: warning:
implicit declaration of function 'hal_restore_irq';
did you mean 'hal_remote_lpt'? [-Wimplicit-function-declaration]

hal_restore_irq( save_sr );

hal_remote_lpt

`

File size: 10.2 KB
RevLine 
[75]1/*
2 * soclib_bdv.c - soclib simple block device driver implementation.
3 *
[437]4 * Author     Alain Greiner (2016,2017,2018)
[75]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
[451]24#include <soclib_bdv.h>
25#include <hal_kernel_types.h>
[75]26#include <chdev.h>
27#include <dev_ioc.h>
[265]28#include <printk.h>
[75]29#include <thread.h>
[622]30#include <hal_irqmask.h>
[75]31
32///////////////////////////////////////
33void soclib_bdv_init( chdev_t * chdev )
34{
[610]35    // get extended pointer on SOCLIB_BDV peripheral base
[75]36        xptr_t  bdv_xp = chdev->base;
37
[211]38    // set driver specific fields
39    chdev->cmd = &soclib_bdv_cmd;
40    chdev->isr = &soclib_bdv_isr;
41
[75]42    // get hardware device cluster and local pointer
43    cxy_t      bdv_cxy  = GET_CXY( bdv_xp );
44    uint32_t * bdv_ptr  = (uint32_t *)GET_PTR( bdv_xp );
45
46    // get block_size and block_count 
[570]47        uint32_t block_size = hal_remote_l32( XPTR( bdv_cxy , bdv_ptr + BDV_BLOCK_SIZE_REG ) );
48        uint32_t block_count = hal_remote_l32( XPTR( bdv_cxy , bdv_ptr + BDV_SIZE_REG ) );
[75]49
50    // set IOC device descriptor extension
51    chdev->ext.ioc.size  = block_size;
52    chdev->ext.ioc.count = block_count;
53
54} // end soclib_bdv_init()
55
56
57//////////////////////////////////////////////////////////////
58void __attribute__ ((noinline)) soclib_bdv_cmd( xptr_t th_xp )
59{
[279]60    uint32_t   cmd_type;    // IOC_READ / IOC_WRITE / IOC_SYNC_READ
61    uint32_t   lba;
62    uint32_t   count;
63    xptr_t     buf_xp;
64    xptr_t     ioc_xp;
[610]65    uint32_t   status;      // I/0 operation status (from BDV)
66    reg_t      save_sr;     // for critical section
67    uint32_t   op;          // BDV_OP_READ / BDV_OP_WRITE
[75]68
69    // get client thread cluster and local pointer
70    cxy_t      th_cxy = GET_CXY( th_xp );
[440]71    thread_t * th_ptr = GET_PTR( th_xp );
[75]72
[610]73#if (DEBUG_HAL_IOC_RX || DEBUG_HAL_IOC_TX)
74uint32_t    cycle        = (uint32_t)hal_get_cycles();
75thread_t  * this         = CURRENT_THREAD;
76process_t * process      = hal_remote_lpt( XPTR( th_cxy , &th_ptr->process ) );
77pid_t       client_pid   = hal_remote_l32( XPTR( th_cxy , &process->pid ) );
78trdid_t     client_trdid = hal_remote_l32( XPTR( th_cxy , &th_ptr->trdid ) );
79#endif
80
[75]81    // get command arguments and extended pointer on IOC device
[610]82    cmd_type =         hal_remote_l32( XPTR( th_cxy , &th_ptr->ioc_cmd.type   ) );
83    lba      =         hal_remote_l32( XPTR( th_cxy , &th_ptr->ioc_cmd.lba    ) );
84    count    =         hal_remote_l32( XPTR( th_cxy , &th_ptr->ioc_cmd.count  ) );
[570]85    buf_xp   = (xptr_t)hal_remote_l64( XPTR( th_cxy , &th_ptr->ioc_cmd.buf_xp ) );
86    ioc_xp   = (xptr_t)hal_remote_l64( XPTR( th_cxy , &th_ptr->ioc_cmd.dev_xp ) );
[75]87
[438]88#if DEBUG_HAL_IOC_RX
89if( (DEBUG_HAL_IOC_RX < cycle) && (cmd_type != IOC_WRITE ) )
[610]90printk("\n[%s] thread[%x,%x] enters for client thread[%x,%x] / RX / cycle %d\n",
91__FUNCTION__ , this->process->pid, this->trdid, client_pid, client_trdid, cycle );
[437]92#endif
93
[438]94#if DEBUG_HAL_IOC_TX
95if( (DEBUG_HAL_IOC_TX < cycle) && (cmd_type == IOC_WRITE) )
[610]96printk("\n[%s] thread[%x,%x] enters for client thread[%x,%x] / TX / cycle %d\n",
97__FUNCTION__ , this->process->pid, this->trdid, client_pid, client_trdid, cycle );
[437]98#endif
99
[75]100    // get IOC device cluster and local pointer
[279]101    cxy_t      ioc_cxy = GET_CXY( ioc_xp );
[440]102    chdev_t  * ioc_ptr = GET_PTR( ioc_xp );
[75]103
[440]104    // get cluster and pointers for SOCLIB-BDV peripheral segment base
[570]105    xptr_t     seg_xp  = (xptr_t)hal_remote_l64( XPTR( ioc_cxy , &ioc_ptr->base ) );
[440]106    cxy_t      seg_cxy = GET_CXY( seg_xp );
107    uint32_t * seg_ptr = GET_PTR( seg_xp );
[75]108
109    // split buffer address in two 32 bits words
110    uint32_t   buf_lsb = (uint32_t)(buf_xp);
111    uint32_t   buf_msb = (uint32_t)(buf_xp>>32);
112
[610]113    // select operation
[615]114    if( (cmd_type == IOC_READ) || (cmd_type == IOC_SYNC_READ) ) op = BDV_OP_READ; 
115    else                                                        op = BDV_OP_WRITE;
[75]116
[610]117    // set SOCLIB_BDV registers to configure the I/O operation
[570]118    hal_remote_s32( XPTR( seg_cxy , seg_ptr + BDV_IRQ_ENABLE_REG ) , 1       );
119    hal_remote_s32( XPTR( seg_cxy , seg_ptr + BDV_BUFFER_REG     ) , buf_lsb ); 
120    hal_remote_s32( XPTR( seg_cxy , seg_ptr + BDV_BUFFER_EXT_REG ) , buf_msb ); 
121    hal_remote_s32( XPTR( seg_cxy , seg_ptr + BDV_LBA_REG        ) , lba     );
122    hal_remote_s32( XPTR( seg_cxy , seg_ptr + BDV_COUNT_REG      ) , count   );
[75]123
124    // waiting policy  depends on the command type
[407]125    // - for IOC_READ / IOC_WRITE commands, this function is called by the server thread
[610]126    //   that blocks and deschedules after launching the I/O transfer.
127    //   The I/O operation status is reported in the command by the ISR.
[615]128    // - for IOC_SYNC_READ / IOC_SYNC_WRITE command, this function is called by the client
129    //   thread that polls the BDV status register until I/O transfer completion.
[75]130
[615]131    if( (cmd_type == IOC_SYNC_READ) || (cmd_type == IOC_SYNC_WRITE) )  // polling policy
[75]132    {
[610]133        // launch I/O operation on BDV device
134        hal_remote_s32( XPTR( seg_cxy , seg_ptr + BDV_OP_REG ) , op );
135       
136        // wait completion
[75]137        while (1)
138        {
[570]139            status = hal_remote_l32( XPTR( seg_cxy , seg_ptr + BDV_STATUS_REG ) );
[75]140
[615]141            if( (status == BDV_READ_SUCCESS) ||
142                (status == BDV_WRITE_SUCCESS) ) // successfully completed
[75]143            {
[570]144                hal_remote_s32( XPTR( th_cxy , &th_ptr->ioc_cmd.error ) , 0 );
[75]145                break;
146            }
147            else if( status == BDV_BUSY )   // non completed
148            {
149                continue;
150            }
151            else                            // error reported
152            {
[570]153                hal_remote_s32( XPTR( th_cxy , &th_ptr->ioc_cmd.error ) , 1 );
[75]154                break;
155            }
156        }
157    }
[615]158    else                                                     // descheduling + IRQ policy
[75]159    { 
[610]160        // enter critical section to atomically
161        // lauch I/O operation and deschedule 
162        hal_disable_irq( &save_sr );
163
164        // launch I/O operation on BDV device
165        hal_remote_s32( XPTR( seg_cxy , seg_ptr + BDV_OP_REG ) , op );
166       
167        // server thread blocks on ISR
[436]168        thread_block( XPTR( local_cxy , CURRENT_THREAD ) , THREAD_BLOCKED_ISR );
[610]169
170#if DEBUG_HAL_IOC_RX
171if( (DEBUG_HAL_IOC_RX < cycle) && (cmd_type != IOC_WRITE ) )
172printk("\n[%s] thread[%x,%x] blocks & deschedules after lauching RX transfer\n",
173__FUNCTION__ , this->process->pid, this->trdid );
174#endif
175
176#if DEBUG_HAL_IOC_TX
177if( (DEBUG_HAL_IOC_TX < cycle) && (cmd_type == IOC_WRITE) )
178printk("\n[%s] thread[%x,%x] blocks & deschedules after lauching TX transfer\n",
179__FUNCTION__ , this->process->pid, this->trdid );
180#endif
181        // server thread deschedules
[408]182        sched_yield("blocked on ISR");
[407]183
[610]184        // exit critical section
185        hal_restore_irq( save_sr );
[75]186    }
187   
[438]188#if DEBUG_HAL_IOC_RX
[437]189cycle = (uint32_t)hal_get_cycles();
[610]190if( (DEBUG_HAL_IOC_RX < cycle) && (cmd_type != IOC_WRITE) )
191printk("\n[%s] thread[%x,%x] exit after RX for client thread[%x,%x] / cycle %d\n",
192__FUNCTION__, this->process->pid, this->trdid, client_pid, client_trdid, cycle );
[437]193#endif
194
[438]195#if DEBUG_HAL_IOC_TX
[437]196cycle = (uint32_t)hal_get_cycles();
[610]197if( (DEBUG_HAL_IOC_TX < cycle) && (cmd_type == IOC_WRITE) )
198printk("\n[%s] thread[%x,%x] exit after TX for client thread[%x,%x] / cycle %d\n",
199__FUNCTION__, this->process->pid, this->trdid, client_pid, client_trdid, cycle );
[437]200#endif
201
[75]202} // end soclib_bdv_cmd()
203
204
205/////////////////////////////////////////////////////////////////
206void __attribute__ ((noinline)) soclib_bdv_isr( chdev_t * chdev )
207{
[437]208    error_t  error = 0;
209
[610]210    // get extended pointer on server thread
211    xptr_t server_xp = XPTR( local_cxy , chdev->server );
212
[75]213    // get extended pointer on client thread
[610]214    xptr_t root      = XPTR( local_cxy , &chdev->wait_root );
[570]215    xptr_t client_xp = XLIST_FIRST( root , thread_t , wait_list );
[75]216
217    // get client thread cluster and local pointer
218    cxy_t      client_cxy = GET_CXY( client_xp );
[610]219    thread_t * client_ptr = GET_PTR( client_xp );
[75]220
[437]221    // get command type
[570]222    uint32_t   cmd_type = hal_remote_l32( XPTR( client_cxy , &client_ptr->ioc_cmd.type ) );
[437]223   
[610]224#if (DEBUG_HAL_IOC_RX || DEBUG_HAL_IOC_TX)
225uint32_t    cycle        = (uint32_t)hal_get_cycles();
226process_t * process      = hal_remote_lpt( XPTR( client_cxy , &client_ptr->process ) );
227pid_t       client_pid   = hal_remote_l32( XPTR( client_cxy , &process->pid ) );
228trdid_t     client_trdid = hal_remote_l32( XPTR( client_cxy , &client_ptr->trdid ) );
229thread_t  * server       = GET_PTR( server_xp );
230pid_t       server_pid   = server->process->pid;
231trdid_t     server_trdid = server->trdid;
232#endif
233
[75]234    // get SOCLIB_BDV device cluster and local pointer
235    cxy_t      bdv_cxy  = GET_CXY( chdev->base );
[610]236    uint32_t * bdv_ptr  = GET_PTR( chdev->base );
[75]237
238    // get BDV status register and acknowledge IRQ
[570]239        uint32_t status = hal_remote_l32( XPTR( bdv_cxy , bdv_ptr + BDV_STATUS_REG ) );   
[75]240
[437]241    if( cmd_type == IOC_READ )
[75]242    {
[437]243            error = (status != BDV_READ_SUCCESS);
244
[438]245#if DEBUG_HAL_IOC_RX
246if( DEBUG_HAL_IOC_RX < cycle )
[610]247printk("\n[%s] RX transfer completed for client[%x,%x] / server[%x,%x] / cycle %d\n",
248__FUNCTION__, client_pid, client_trdid, server_pid, server_trdid, cycle );
[437]249#endif
250
[75]251    }
[437]252        else if( cmd_type == IOC_WRITE )
[75]253    {
[437]254            error = (status != BDV_WRITE_SUCCESS);
255
[438]256#if DEBUG_HAL_IOC_TX
257if( DEBUG_HAL_IOC_TX < cycle )
[610]258printk("\n[%s] TX transfer completed for client[%x,%x] / server[%x,%x] / cycle %d\n",
259__FUNCTION__, client_pid, client_trdid, server_pid, server_trdid, cycle );
[437]260#endif
261
[75]262    }
[437]263    else
264    {
[492]265        assert( false , "IOC_SYNC_READ should not use IRQ" );
[437]266    } 
[75]267
[437]268    // set operation status in command
[570]269    hal_remote_s32( XPTR( client_cxy , &client_ptr->ioc_cmd.error ) , error );
[437]270
[75]271    // unblock server thread
[436]272    thread_unblock( server_xp , THREAD_BLOCKED_ISR );
[75]273
274} // end soclib_bdv_isr()
275
276
277
Note: See TracBrowser for help on using the repository browser.