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

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

Introduce syscalls.

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