source: trunk/kernel/drivers/soclib/soclib_bdv.c @ 2

Last change on this file since 2 was 1, checked in by alain, 8 years ago

First import

File size: 5.5 KB
Line 
1/*
2 * soclib_bdv.c - soclib simple block device driver implementation.
3 *
4 * Author     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
24#include <device.h>
25#include <dev_ioc.h>
26#include <soclib_bdv.h>
27#include <thread.h>
28#include <spinlock.h>
29
30
31/////////////////////////////////////
32void soclib_bdv_init( xptr_t dev_xp )
33{
34    // get IOC device descriptor cluster and local pointer
35    cxy_t      dev_cxy  = GET_CXY( dev_xp );
36    device_t * dev_ptr  = (device_t *)GET_PTR( dev_xp );
37 
38    // get extended pointer on SOCLIB_BDV peripheral base address
39        xptr_t  bdv_xp = hal_remote_lwd( XPTR( dev_cxy , &dev_ptr->base ) );
40
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 
46        uint32_t block_size = hal_remote_lw( XPTR( bdv_cxy , bdv_ptr + BDV_BLOCK_SIZE_REG ) );
47        uint32_t block_count = hal_remote_lw( XPTR( bdv_cxy , bdv_ptr + BDV_SIZE_REG ) );
48
49    // set IOC device descriptor extension
50    hal_remote_sw( XPTR( dev_cxy , &dev_ptr->ext.ioc.size  ) , block_size );
51    hal_remote_sw( XPTR( dev_cxy , &dev_ptr->ext.ioc.count ) , block_count );
52
53} // end soclib_bdv_init()
54
55
56//////////////////////////////////////////////////////////////////
57void __attribute__ ((noinline)) soclib_bdv_command( xptr_t th_xp )
58{
59    uint32_t   to_mem;       // command argument
60    uint32_t   lba;          // command argument
61    uint32_t   count;        // command argument
62    xptr_t     buf_xp;       // command argument
63    xptr_t     dev_xp;       // command argument
64
65    // get client thread cluster and local pointer
66    cxy_t      th_cxy = GET_CXY( th_xp );
67    thread_t * th_ptr = (thread_t *)GET_PTR( th_xp );
68
69    // get command arguments and extended pointer on IOC device
70    to_mem =         hal_remote_lw ( XPTR( th_cxy , &th_ptr->dev.ioc.to_mem ) );
71    lba    =         hal_remote_lw ( XPTR( th_cxy , &th_ptr->dev.ioc.lba    ) );
72    count  =         hal_remote_lw ( XPTR( th_cxy , &th_ptr->dev.ioc.count  ) );
73    buf_xp = (xptr_t)hal_remote_lwd( XPTR( th_cxy , &th_ptr->dev.ioc.buf_xp ) );
74    dev_xp = (xptr_t)hal_remote_lwd( XPTR( th_cxy , &th_ptr->dev.ioc.dev_xp ) );
75
76    // get IOC device cluster and local pointer
77    cxy_t      dev_cxy = GET_CXY( dev_xp );
78    device_t * dev_ptr = (device_t *)GET_PTR( dev_xp );
79
80    // get extended pointer on SOCLIB-BDV peripheral
81    xptr_t     bdv_xp = hal_remote_lw( XPTR( dev_cxy , &dev_ptr->base ) );
82
83    // get SOCLIB_BDV device cluster and local pointer
84    cxy_t      bdv_cxy = GET_CXY( bdv_xp );
85    uint32_t * bdv_ptr = (uint32_t *)GET_PTR( bdv_xp );
86
87    // split buffer address in two 32 bits words
88    uint32_t   buf_lsb = (uint32_t)(buf_xp);
89    uint32_t   buf_msb = (uint32_t)(buf_xp>>32);
90
91    // get access type
92    uint32_t   type =  to_mem ? BDV_OP_READ : BDV_OP_WRITE; 
93
94    // set SOCLIB_BDV registers to start one I/O operation
95    hal_remote_sw( XPTR( bdv_cxy , bdv_ptr + BDV_IRQ_ENABLE_REG ) , 1       );
96    hal_remote_sw( XPTR( bdv_cxy , bdv_ptr + BDV_BUFFER_REG     ) , buf_lsb ); 
97    hal_remote_sw( XPTR( bdv_cxy , bdv_ptr + BDV_BUFFER_EXT_REG ) , buf_msb ); 
98    hal_remote_sw( XPTR( bdv_cxy , bdv_ptr + BDV_LBA_REG        ) , lba     );
99    hal_remote_sw( XPTR( bdv_cxy , bdv_ptr + BDV_COUNT_REG      ) , count   );
100    hal_remote_sw( XPTR( bdv_cxy , bdv_ptr + BDV_OP_REG         ) , type    );
101
102    // Block and deschedule server thread
103    thread_block( CURRENT_THREAD , THREAD_BLOCKED_DEV_ISR );
104    sched_yield();
105   
106} // end soclib_bdv_cmd()
107
108
109////////////////////////////////////////////////////////////////
110void __attribute__ ((noinline)) soclib_bdv_isr( device_t * dev )
111{
112    // get extended pointer on client thread
113    xptr_t root = XPTR( local_cxy , &dev->wait_root );
114    xptr_t client_xp = XLIST_FIRST_ELEMENT( root , thread_t , wait_list );
115
116    // get extended pointer on server thread
117    xptr_t server_xp = XPTR( local_cxy , &dev->server );
118
119    // get client thread cluster and local pointer
120    cxy_t      client_cxy = GET_CXY( client_xp );
121    thread_t * client_ptr = (thread_t *)GET_PTR( client_xp );
122
123    // get SOCLIB_BDV device cluster and local pointer
124    cxy_t      bdv_cxy  = GET_CXY( dev->base );
125    uint32_t * bdv_ptr  = (uint32_t *)GET_PTR( dev->base );
126
127    // get BDV status register and acknowledge IRQ
128        uint32_t status = hal_remote_lw( XPTR( bdv_cxy , bdv_ptr + BDV_STATUS_REG ) );   
129
130    // set operation status in command
131        if((status != BDV_READ_SUCCESS) && (status != BDV_WRITE_SUCCESS)) 
132    {
133        hal_remote_sw( XPTR( client_cxy , &client_ptr->dev.ioc.error ) , 1 );
134    }
135        else
136    {
137        hal_remote_sw( XPTR( client_cxy , &client_ptr->dev.ioc.error ) , 0 );
138    }
139
140    // unblock server thread
141    thread_unblock( server_xp , THREAD_BLOCKED_DEV_ISR );
142
143    // unblock client thread
144    thread_unblock( client_xp , THREAD_BLOCKED_IO );
145
146} // end soclib_bdv_isr()
147
148
149
Note: See TracBrowser for help on using the repository browser.