source: trunk/kernel/devices/dev_iob.c @ 14

Last change on this file since 14 was 14, checked in by alain, 7 years ago

Bugs fix.

File size: 5.4 KB
RevLine 
[1]1/*
[3]2 * dev_iob.c - IOB (bridge to external I/O) generic device API implementation.
[1]3 *
4 * Authors   Alain Greiner  (2017)
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
[3]16 * MERCHANTABILITY or FITNESS FOR A PARTIOBLAR PURPOSE.  See the GNU
[1]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>
[1]25#include <hal_types.h>
26#include <hal_special.h>
27#include <remote_spinlock.h>
[3]28#include <chdev.h>
[1]29#include <printk.h>
30#include <soclib_iob.h>
[3]31#include <dev_iob.h>
[1]32
[3]33////////////////////////////////////
34void dev_iob_init( chdev_t * chdev )
[1]35{
[3]36    // get implementation
37    uint32_t  impl = chdev->impl;
[1]38
39    // call driver init function
[3]40    if( impl == IMPL_IOB_TSR )
[1]41    {
[3]42        soclib_iob_init( chdev );
[1]43    }
44    else
45    {
[3]46        assert( false , __FUNCTION__ , "undefined IOB device implementation\n" );
[1]47    }
48}
49
50//////////////////////////////////////////
[3]51void dev_iob_iommu_enable( xptr_t dev_xp )
[1]52{
[3]53    // get IOB chdev descriptor cluster and local pointer
54    cxy_t     dev_cxy = GET_CXY( dev_xp );
55    chdev_t * dev_ptr = (chdev_t *)GET_PTR( dev_xp );
[1]56
[3]57    // get implementation from chdev descriptor
[1]58    uint32_t  impl = hal_remote_lw( XPTR( dev_cxy , &dev_ptr->impl ) );
59
60    // call driver function
[3]61    if( impl == IMPL_IOB_TSR )
[1]62    {
63        remote_spinlock_lock( XPTR( dev_cxy , &dev_ptr->wait_lock ) );
64        soclib_iob_set_active( dev_xp , 1 );
65        remote_spinlock_unlock( XPTR( dev_cxy , &dev_ptr->wait_lock ) );
66    }
67    else
68    {
[3]69        printk("\n[PANIC] in %s: undefined IOB device implementation\n", __FUNCTION__ );
[1]70        hal_core_sleep();
71    }
72}
73
74///////////////////////////////////////////
[3]75void dev_iob_iommu_disable( xptr_t dev_xp )
[1]76{
[3]77    // get IOB chdev descriptor cluster and local pointer
78    cxy_t     dev_cxy = GET_CXY( dev_xp );
79    chdev_t * dev_ptr = (chdev_t *)GET_PTR( dev_xp );
[1]80
[3]81    // get implementation from chdev descriptor
[1]82    uint32_t  impl = hal_remote_lw( XPTR( dev_cxy , &dev_ptr->impl ) );
83
84    // call driver function
[3]85    if( impl == IMPL_IOB_TSR )
[1]86    {
87        remote_spinlock_lock( XPTR( dev_cxy , &dev_ptr->wait_lock ) );
88        soclib_iob_set_active( dev_xp , 0 );
89        remote_spinlock_unlock( XPTR( dev_cxy , &dev_ptr->wait_lock ) );
90    }
91    else
92    {
[3]93        printk("\n[PANIC] in %s: undefined IOB device implementation\n", __FUNCTION__ );
[1]94        hal_core_sleep();
95    }
96}
97
98////////////////////////////////////////
[3]99void dev_iob_set_ptpr( xptr_t    dev_xp,
[1]100                       uint32_t  wdata )
101{
[3]102    // get IOB chdev descriptor cluster and local pointer
103    cxy_t     dev_cxy = GET_CXY( dev_xp );
104    chdev_t * dev_ptr = (chdev_t *)GET_PTR( dev_xp );
[1]105
[3]106    // get implementation from chdev descriptor
[1]107    uint32_t  impl = hal_remote_lw( XPTR( dev_cxy , &dev_ptr->impl ) );
108
109    // call driver function
[3]110    if( impl == IMPL_IOB_TSR )
[1]111    {
112        remote_spinlock_lock( XPTR( dev_cxy , &dev_ptr->wait_lock ) );
113        soclib_iob_set_ptpr( dev_xp , wdata );
114        remote_spinlock_unlock( XPTR( dev_cxy , &dev_ptr->wait_lock ) );
115    }
116    else
117    {
[3]118        printk("\n[PANIC] in %s: undefined IOB device implementation\n", __FUNCTION__ );
[1]119        hal_core_sleep();
120    }
121}
122                       
123////////////////////////////////////////
[3]124void dev_iob_inval_page( xptr_t  dev_xp,
[1]125                         vpn_t   vpn )
126{
[3]127    // get IOB chdev descriptor cluster and local pointer
128    cxy_t     dev_cxy = GET_CXY( dev_xp );
129    chdev_t * dev_ptr = (chdev_t *)GET_PTR( dev_xp );
[1]130
[3]131    // get implementation from chdev descriptor
[1]132    uint32_t  impl = hal_remote_lw( XPTR( dev_cxy , &dev_ptr->impl ) );
133
134    // call driver function
[3]135    if( impl == IMPL_IOB_TSR )
[1]136    {
137        remote_spinlock_lock( XPTR( dev_cxy , &dev_ptr->wait_lock ) );
138        soclib_iob_inval_page( dev_xp , vpn );
139        remote_spinlock_unlock( XPTR( dev_cxy , &dev_ptr->wait_lock ) );
140    }
141    else
142    {
[3]143        printk("\n[PANIC] in %s: undefined IOB device implementation\n", __FUNCTION__ );
[1]144        hal_core_sleep();
145    }
146}
147
148///////////////////////////////////////////
[3]149void dev_iob_get_status( xptr_t     dev_xp,
[1]150                         uint32_t * error,
151                         uint32_t * bvar,
152                         uint32_t * srcid )
153{
[3]154    // get IOB chdev descriptor cluster and local pointer
155    cxy_t     dev_cxy = GET_CXY( dev_xp );
156    chdev_t * dev_ptr = (chdev_t *)GET_PTR( dev_xp );
[1]157
[3]158    // get implementation from chdev descriptor
[1]159    uint32_t  impl = hal_remote_lw( XPTR( dev_cxy , &dev_ptr->impl ) );
160
161    // call driver function
[3]162    if( impl == IMPL_IOB_TSR )
[1]163    {
164        remote_spinlock_lock( XPTR( dev_cxy , &dev_ptr->wait_lock ) );
165        *error = soclib_iob_get_error( dev_xp );
166        *srcid = soclib_iob_get_srcid( dev_xp );
167        *bvar  = soclib_iob_get_bvar( dev_xp );
168        remote_spinlock_unlock( XPTR( dev_cxy , &dev_ptr->wait_lock ) );
169    }
170    else
171    {
[3]172        printk("\n[PANIC] in %s: undefined IOB device implementation\n", __FUNCTION__ );
[1]173        hal_core_sleep();
174    }
175}
176
Note: See TracBrowser for help on using the repository browser.