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

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

Introduce syscalls.

File size: 5.5 KB
Line 
1/*
2 * dev_iob.c - IOB (bridge to external I/O) generic device API implementation.
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
16 * MERCHANTABILITY or FITNESS FOR A PARTIOBLAR 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 <kernel_config.h>
25#include <hal_types.h>
26#include <hal_special.h>
27#include <remote_spinlock.h>
28#include <chdev.h>
29#include <printk.h>
30#include <soclib_iob.h>
31#include <dev_iob.h>
32
33////////////////////////////////////
34void dev_iob_init( chdev_t * chdev )
35{
36    // get implementation
37    uint32_t  impl = chdev->impl;
38
39    // set chdev name
40    strcpy( chdev->name , "iob" );
41
42    // call driver init function
43    if( impl == IMPL_IOB_TSR )
44    {
45        soclib_iob_init( chdev );
46    }
47    else
48    {
49        assert( false , __FUNCTION__ , "undefined IOB device implementation\n" );
50    }
51}
52
53//////////////////////////////////////////
54void dev_iob_iommu_enable( xptr_t dev_xp )
55{
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 );
59
60    // get implementation from chdev descriptor
61    uint32_t  impl = hal_remote_lw( XPTR( dev_cxy , &dev_ptr->impl ) );
62
63    // call driver function
64    if( impl == IMPL_IOB_TSR )
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    {
72        printk("\n[PANIC] in %s: undefined IOB device implementation\n", __FUNCTION__ );
73        hal_core_sleep();
74    }
75}
76
77///////////////////////////////////////////
78void dev_iob_iommu_disable( xptr_t dev_xp )
79{
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 );
83
84    // get implementation from chdev descriptor
85    uint32_t  impl = hal_remote_lw( XPTR( dev_cxy , &dev_ptr->impl ) );
86
87    // call driver function
88    if( impl == IMPL_IOB_TSR )
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    {
96        printk("\n[PANIC] in %s: undefined IOB device implementation\n", __FUNCTION__ );
97        hal_core_sleep();
98    }
99}
100
101////////////////////////////////////////
102void dev_iob_set_ptpr( xptr_t    dev_xp,
103                       uint32_t  wdata )
104{
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 );
108
109    // get implementation from chdev descriptor
110    uint32_t  impl = hal_remote_lw( XPTR( dev_cxy , &dev_ptr->impl ) );
111
112    // call driver function
113    if( impl == IMPL_IOB_TSR )
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    {
121        printk("\n[PANIC] in %s: undefined IOB device implementation\n", __FUNCTION__ );
122        hal_core_sleep();
123    }
124}
125                       
126////////////////////////////////////////
127void dev_iob_inval_page( xptr_t  dev_xp,
128                         vpn_t   vpn )
129{
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 );
133
134    // get implementation from chdev descriptor
135    uint32_t  impl = hal_remote_lw( XPTR( dev_cxy , &dev_ptr->impl ) );
136
137    // call driver function
138    if( impl == IMPL_IOB_TSR )
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    {
146        printk("\n[PANIC] in %s: undefined IOB device implementation\n", __FUNCTION__ );
147        hal_core_sleep();
148    }
149}
150
151///////////////////////////////////////////
152void dev_iob_get_status( xptr_t     dev_xp,
153                         uint32_t * error,
154                         uint32_t * bvar,
155                         uint32_t * srcid )
156{
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 );
160
161    // get implementation from chdev descriptor
162    uint32_t  impl = hal_remote_lw( XPTR( dev_cxy , &dev_ptr->impl ) );
163
164    // call driver function
165    if( impl == IMPL_IOB_TSR )
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    {
175        printk("\n[PANIC] in %s: undefined IOB device implementation\n", __FUNCTION__ );
176        hal_core_sleep();
177    }
178}
179
Note: See TracBrowser for help on using the repository browser.