source: trunk/kernel/devices/dev_iox.c @ 1

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

First import

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