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 <almos_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 | //////////////////////////////////// |
---|
34 | void dev_iob_init( chdev_t * chdev ) |
---|
35 | { |
---|
36 | // get implementation |
---|
37 | uint32_t impl = chdev->impl; |
---|
38 | |
---|
39 | // call driver init function |
---|
40 | if( impl == IMPL_IOB_TSR ) |
---|
41 | { |
---|
42 | soclib_iob_init( chdev ); |
---|
43 | } |
---|
44 | else |
---|
45 | { |
---|
46 | assert( false , __FUNCTION__ , "undefined IOB device implementation\n" ); |
---|
47 | } |
---|
48 | } |
---|
49 | |
---|
50 | ////////////////////////////////////////// |
---|
51 | void dev_iob_iommu_enable( xptr_t dev_xp ) |
---|
52 | { |
---|
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 ); |
---|
56 | |
---|
57 | // get implementation from chdev descriptor |
---|
58 | uint32_t impl = hal_remote_lw( XPTR( dev_cxy , &dev_ptr->impl ) ); |
---|
59 | |
---|
60 | // call driver function |
---|
61 | if( impl == IMPL_IOB_TSR ) |
---|
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 | { |
---|
69 | printk("\n[PANIC] in %s: undefined IOB device implementation\n", __FUNCTION__ ); |
---|
70 | hal_core_sleep(); |
---|
71 | } |
---|
72 | } |
---|
73 | |
---|
74 | /////////////////////////////////////////// |
---|
75 | void dev_iob_iommu_disable( xptr_t dev_xp ) |
---|
76 | { |
---|
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 ); |
---|
80 | |
---|
81 | // get implementation from chdev descriptor |
---|
82 | uint32_t impl = hal_remote_lw( XPTR( dev_cxy , &dev_ptr->impl ) ); |
---|
83 | |
---|
84 | // call driver function |
---|
85 | if( impl == IMPL_IOB_TSR ) |
---|
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 | { |
---|
93 | printk("\n[PANIC] in %s: undefined IOB device implementation\n", __FUNCTION__ ); |
---|
94 | hal_core_sleep(); |
---|
95 | } |
---|
96 | } |
---|
97 | |
---|
98 | //////////////////////////////////////// |
---|
99 | void dev_iob_set_ptpr( xptr_t dev_xp, |
---|
100 | uint32_t wdata ) |
---|
101 | { |
---|
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 ); |
---|
105 | |
---|
106 | // get implementation from chdev descriptor |
---|
107 | uint32_t impl = hal_remote_lw( XPTR( dev_cxy , &dev_ptr->impl ) ); |
---|
108 | |
---|
109 | // call driver function |
---|
110 | if( impl == IMPL_IOB_TSR ) |
---|
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 | { |
---|
118 | printk("\n[PANIC] in %s: undefined IOB device implementation\n", __FUNCTION__ ); |
---|
119 | hal_core_sleep(); |
---|
120 | } |
---|
121 | } |
---|
122 | |
---|
123 | //////////////////////////////////////// |
---|
124 | void dev_iob_inval_page( xptr_t dev_xp, |
---|
125 | vpn_t vpn ) |
---|
126 | { |
---|
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 ); |
---|
130 | |
---|
131 | // get implementation from chdev descriptor |
---|
132 | uint32_t impl = hal_remote_lw( XPTR( dev_cxy , &dev_ptr->impl ) ); |
---|
133 | |
---|
134 | // call driver function |
---|
135 | if( impl == IMPL_IOB_TSR ) |
---|
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 | { |
---|
143 | printk("\n[PANIC] in %s: undefined IOB device implementation\n", __FUNCTION__ ); |
---|
144 | hal_core_sleep(); |
---|
145 | } |
---|
146 | } |
---|
147 | |
---|
148 | /////////////////////////////////////////// |
---|
149 | void dev_iob_get_status( xptr_t dev_xp, |
---|
150 | uint32_t * error, |
---|
151 | uint32_t * bvar, |
---|
152 | uint32_t * srcid ) |
---|
153 | { |
---|
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 ); |
---|
157 | |
---|
158 | // get implementation from chdev descriptor |
---|
159 | uint32_t impl = hal_remote_lw( XPTR( dev_cxy , &dev_ptr->impl ) ); |
---|
160 | |
---|
161 | // call driver function |
---|
162 | if( impl == IMPL_IOB_TSR ) |
---|
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 | { |
---|
172 | printk("\n[PANIC] in %s: undefined IOB device implementation\n", __FUNCTION__ ); |
---|
173 | hal_core_sleep(); |
---|
174 | } |
---|
175 | } |
---|
176 | |
---|