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

Last change on this file since 570 was 570, checked in by alain, 5 years ago

Introduction of the soclib_mty driver for the TSAR-LETI architecture.

File size: 7.9 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>
30
31///////////////////////////////////////
32void soclib_bdv_init( chdev_t * chdev )
33{
34    // get extended pointer on SOCLIB_BDV peripheral base address
35        xptr_t  bdv_xp = chdev->base;
36
[211]37    // set driver specific fields
38    chdev->cmd = &soclib_bdv_cmd;
39    chdev->isr = &soclib_bdv_isr;
40
[75]41    // get hardware device cluster and local pointer
42    cxy_t      bdv_cxy  = GET_CXY( bdv_xp );
43    uint32_t * bdv_ptr  = (uint32_t *)GET_PTR( bdv_xp );
44
45    // get block_size and block_count 
[570]46        uint32_t block_size = hal_remote_l32( XPTR( bdv_cxy , bdv_ptr + BDV_BLOCK_SIZE_REG ) );
47        uint32_t block_count = hal_remote_l32( XPTR( bdv_cxy , bdv_ptr + BDV_SIZE_REG ) );
[75]48
49    // set IOC device descriptor extension
50    chdev->ext.ioc.size  = block_size;
51    chdev->ext.ioc.count = block_count;
52
53} // end soclib_bdv_init()
54
55
56//////////////////////////////////////////////////////////////
57void __attribute__ ((noinline)) soclib_bdv_cmd( xptr_t th_xp )
58{
[279]59    uint32_t   cmd_type;    // IOC_READ / IOC_WRITE / IOC_SYNC_READ
60    uint32_t   lba;
61    uint32_t   count;
62    xptr_t     buf_xp;
63    xptr_t     ioc_xp;
[75]64
65    // get client thread cluster and local pointer
66    cxy_t      th_cxy = GET_CXY( th_xp );
[440]67    thread_t * th_ptr = GET_PTR( th_xp );
[75]68
69    // get command arguments and extended pointer on IOC device
[570]70    cmd_type =         hal_remote_l32 ( XPTR( th_cxy , &th_ptr->ioc_cmd.type   ) );
71    lba      =         hal_remote_l32 ( XPTR( th_cxy , &th_ptr->ioc_cmd.lba    ) );
72    count    =         hal_remote_l32 ( XPTR( th_cxy , &th_ptr->ioc_cmd.count  ) );
73    buf_xp   = (xptr_t)hal_remote_l64( XPTR( th_cxy , &th_ptr->ioc_cmd.buf_xp ) );
74    ioc_xp   = (xptr_t)hal_remote_l64( XPTR( th_cxy , &th_ptr->ioc_cmd.dev_xp ) );
[75]75
[438]76#if DEBUG_HAL_IOC_RX
[437]77uint32_t cycle = (uint32_t)hal_get_cycles();
[438]78if( (DEBUG_HAL_IOC_RX < cycle) && (cmd_type != IOC_WRITE ) )
[437]79printk("\n[DBG] %s : thread %x enter for RX / cycle %d\n",
80__FUNCTION__ , CURRENT_THREAD , cycle );
81#endif
82
[438]83#if DEBUG_HAL_IOC_TX
[437]84uint32_t cycle = (uint32_t)hal_get_cycles();
[438]85if( (DEBUG_HAL_IOC_TX < cycle) && (cmd_type == IOC_WRITE) )
[437]86printk("\n[DBG] %s : thread %x enter for TX / cycle %d\n",
87__FUNCTION__ , CURRENT_THREAD , cycle );
88#endif
89
[75]90    // get IOC device cluster and local pointer
[279]91    cxy_t      ioc_cxy = GET_CXY( ioc_xp );
[440]92    chdev_t  * ioc_ptr = GET_PTR( ioc_xp );
[75]93
[440]94    // get cluster and pointers for SOCLIB-BDV peripheral segment base
[570]95    xptr_t     seg_xp  = (xptr_t)hal_remote_l64( XPTR( ioc_cxy , &ioc_ptr->base ) );
[440]96    cxy_t      seg_cxy = GET_CXY( seg_xp );
97    uint32_t * seg_ptr = GET_PTR( seg_xp );
[75]98
99    // split buffer address in two 32 bits words
100    uint32_t   buf_lsb = (uint32_t)(buf_xp);
101    uint32_t   buf_msb = (uint32_t)(buf_xp>>32);
102
103    // set operation
104    uint32_t   op;
105    if( cmd_type == IOC_WRITE ) op = BDV_OP_WRITE; 
106    else                        op = BDV_OP_READ;
107
108    // set SOCLIB_BDV registers to start one I/O operation
[570]109    hal_remote_s32( XPTR( seg_cxy , seg_ptr + BDV_IRQ_ENABLE_REG ) , 1       );
110    hal_remote_s32( XPTR( seg_cxy , seg_ptr + BDV_BUFFER_REG     ) , buf_lsb ); 
111    hal_remote_s32( XPTR( seg_cxy , seg_ptr + BDV_BUFFER_EXT_REG ) , buf_msb ); 
112    hal_remote_s32( XPTR( seg_cxy , seg_ptr + BDV_LBA_REG        ) , lba     );
113    hal_remote_s32( XPTR( seg_cxy , seg_ptr + BDV_COUNT_REG      ) , count   );
114    hal_remote_s32( XPTR( seg_cxy , seg_ptr + BDV_OP_REG         ) , op      );
[75]115
116    // waiting policy  depends on the command type
[407]117    // - for IOC_READ / IOC_WRITE commands, this function is called by the server thread
118    // - for IOC_SYNC_READ command, this function is directly called by the client thread
[75]119
[407]120    if( cmd_type == IOC_SYNC_READ )                   // status polling policy
[75]121    {
122        uint32_t status;
123        while (1)
124        {
[570]125            status = hal_remote_l32( XPTR( seg_cxy , seg_ptr + BDV_STATUS_REG ) );
[75]126
127            if( status == BDV_READ_SUCCESS ) // successfully completed
128            {
[570]129                hal_remote_s32( XPTR( th_cxy , &th_ptr->ioc_cmd.error ) , 0 );
[75]130                break;
131            }
132            else if( status == BDV_BUSY )   // non completed
133            {
134                continue;
135            }
136            else                            // error reported
137            {
[570]138                hal_remote_s32( XPTR( th_cxy , &th_ptr->ioc_cmd.error ) , 1 );
[75]139                break;
140            }
141        }
142    }
143    else                                            // descheduling + IRQ policy
144    { 
[436]145        thread_block( XPTR( local_cxy , CURRENT_THREAD ) , THREAD_BLOCKED_ISR );
[408]146        sched_yield("blocked on ISR");
[407]147
148        // the IO operation status is reported in the command by the ISR
[75]149    }
150   
[438]151#if DEBUG_HAL_IOC_RX
[437]152cycle = (uint32_t)hal_get_cycles();
[438]153if( (DEBUG_HAL_IOC_RX < cycle) && (cmd_type != TXT_WRITE) )
[437]154printk("\n[DBG] %s : thread %x exit after RX / cycle %d\n",
155__FUNCTION__ , CURRENT_THREAD , cycle );
156#endif
157
[438]158#if DEBUG_HAL_IOC_TX
[437]159cycle = (uint32_t)hal_get_cycles();
[438]160if( (DEBUG_HAL_IOC_TX < cycle) && (cmd_type == TXT_WRITE) )
[437]161printk("\n[DBG] %s : thread %x exit after TX / cycle %d\n",
162__FUNCTION__ , CURRENT_THREAD , cycle );
163#endif
164
[75]165} // end soclib_bdv_cmd()
166
167
168/////////////////////////////////////////////////////////////////
169void __attribute__ ((noinline)) soclib_bdv_isr( chdev_t * chdev )
170{
[437]171    error_t  error = 0;
172
[75]173    // get extended pointer on client thread
174    xptr_t root = XPTR( local_cxy , &chdev->wait_root );
[570]175    xptr_t client_xp = XLIST_FIRST( root , thread_t , wait_list );
[75]176
177    // get extended pointer on server thread
178    xptr_t server_xp = XPTR( local_cxy , &chdev->server );
179
180    // get client thread cluster and local pointer
181    cxy_t      client_cxy = GET_CXY( client_xp );
182    thread_t * client_ptr = (thread_t *)GET_PTR( client_xp );
183
[437]184    // get command type
[570]185    uint32_t   cmd_type = hal_remote_l32( XPTR( client_cxy , &client_ptr->ioc_cmd.type ) );
[437]186   
[75]187    // get SOCLIB_BDV device cluster and local pointer
188    cxy_t      bdv_cxy  = GET_CXY( chdev->base );
189    uint32_t * bdv_ptr  = (uint32_t *)GET_PTR( chdev->base );
190
191    // get BDV status register and acknowledge IRQ
[570]192        uint32_t status = hal_remote_l32( XPTR( bdv_cxy , bdv_ptr + BDV_STATUS_REG ) );   
[75]193
[437]194    if( cmd_type == IOC_READ )
[75]195    {
[437]196            error = (status != BDV_READ_SUCCESS);
197
[438]198#if DEBUG_HAL_IOC_RX
[437]199uint32_t cycle = (uint32_t)hal_get_cycles();
[438]200if( DEBUG_HAL_IOC_RX < cycle )
[437]201printk("\n[DBG] %s : IOC_IRQ / RX transfer / client %x / server %x / cycle %d\n",
202__FUNCTION__, client_ptr , chdev->server , cycle );
203#endif
204
[75]205    }
[437]206        else if( cmd_type == IOC_WRITE )
[75]207    {
[437]208            error = (status != BDV_WRITE_SUCCESS);
209
[438]210#if DEBUG_HAL_IOC_TX
[437]211uint32_t cycle = (uint32_t)hal_get_cycles();
[438]212if( DEBUG_HAL_IOC_TX < cycle )
[437]213printk("\n[DBG] %s : IOC_IRQ / RX transfer / client %x / server %x / cycle %d\n",
214__FUNCTION__, client_ptr , chdev->server , cycle );
215#endif
216
[75]217    }
[437]218    else
219    {
[492]220        assert( false , "IOC_SYNC_READ should not use IRQ" );
[437]221    } 
[75]222
[437]223    // set operation status in command
[570]224    hal_remote_s32( XPTR( client_cxy , &client_ptr->ioc_cmd.error ) , error );
[437]225
[75]226    // unblock server thread
[436]227    thread_unblock( server_xp , THREAD_BLOCKED_ISR );
[75]228
229} // end soclib_bdv_isr()
230
231
232
Note: See TracBrowser for help on using the repository browser.