1 | /////////////////////////////////////////////////////////////////////////////////// |
---|
2 | // File : xcu_driver.c |
---|
3 | // Date : 23/05/2013 |
---|
4 | // Author : alain greiner |
---|
5 | // Copyright (c) UPMC-LIP6 |
---|
6 | /////////////////////////////////////////////////////////////////////////////////// |
---|
7 | |
---|
8 | #include <hard_config.h> |
---|
9 | #include <giet_config.h> |
---|
10 | #include <xcu_driver.h> |
---|
11 | #include <tty0.h> |
---|
12 | #include <mapping_info.h> |
---|
13 | #include <utils.h> |
---|
14 | #include <io.h> |
---|
15 | |
---|
16 | #if !defined(X_SIZE) |
---|
17 | # error: You must define X_SIZE in the hard_config.h file |
---|
18 | #endif |
---|
19 | |
---|
20 | #if !defined(Y_SIZE) |
---|
21 | # error: You must define X_SIZE in the hard_config.h file |
---|
22 | #endif |
---|
23 | |
---|
24 | #if !defined(X_WIDTH) |
---|
25 | # error: You must define X_WIDTH in the hard_config.h file |
---|
26 | #endif |
---|
27 | |
---|
28 | #if !defined(Y_WIDTH) |
---|
29 | # error: You must define X_WIDTH in the hard_config.h file |
---|
30 | #endif |
---|
31 | |
---|
32 | #if !defined(NB_PROCS_MAX) |
---|
33 | # error: You must define NB_PROCS_MAX in the hard_config.h file |
---|
34 | #endif |
---|
35 | |
---|
36 | #if !defined( USE_XCU ) |
---|
37 | # error: You must define USE_XCU in the hard_config.h file |
---|
38 | #endif |
---|
39 | |
---|
40 | #if !defined( SEG_XCU_BASE ) |
---|
41 | # error: You must define SEG_XCU_BASE in the hard_config.h file |
---|
42 | #endif |
---|
43 | |
---|
44 | #if !defined( PERI_CLUSTER_INCREMENT ) |
---|
45 | # error: You must define PERI_CLUSTER_INCREMENT in the hard_config.h file |
---|
46 | #endif |
---|
47 | |
---|
48 | /////////////////////////////////////////////////////////////////////////////// |
---|
49 | // This low level function returns the value contained in register "index" |
---|
50 | // in the XCU component contained in cluster "cluster_xy" |
---|
51 | /////////////////////////////////////////////////////////////////////////////// |
---|
52 | static |
---|
53 | unsigned int _xcu_get_register( unsigned int cluster_xy, // cluster index |
---|
54 | unsigned int func, // function index |
---|
55 | unsigned int index ) // register index |
---|
56 | { |
---|
57 | unsigned int vaddr = |
---|
58 | SEG_XCU_BASE + |
---|
59 | (cluster_xy * PERI_CLUSTER_INCREMENT) + |
---|
60 | (XCU_REG(func, index) << 2); |
---|
61 | |
---|
62 | return ioread32( (void*)vaddr ); |
---|
63 | } |
---|
64 | |
---|
65 | /////////////////////////////////////////////////////////////////////////////// |
---|
66 | // This low level function sets a new value in register "index" |
---|
67 | // in the XCU component contained in cluster "cluster_xy" |
---|
68 | /////////////////////////////////////////////////////////////////////////////// |
---|
69 | static |
---|
70 | void _xcu_set_register( unsigned int cluster_xy, // cluster index |
---|
71 | unsigned int func, // func index |
---|
72 | unsigned int index, // register index |
---|
73 | unsigned int value ) // value to be written |
---|
74 | { |
---|
75 | unsigned int vaddr = |
---|
76 | SEG_XCU_BASE + |
---|
77 | (cluster_xy * PERI_CLUSTER_INCREMENT) + |
---|
78 | (XCU_REG(func, index) << 2); |
---|
79 | |
---|
80 | iowrite32( (void*)vaddr, value ); |
---|
81 | } |
---|
82 | |
---|
83 | //////////////////////////////////////////// |
---|
84 | void _xcu_set_mask( unsigned int cluster_xy, |
---|
85 | unsigned int channel, |
---|
86 | unsigned int value, |
---|
87 | unsigned int irq_type ) |
---|
88 | { |
---|
89 | #if USE_XCU |
---|
90 | // parameters checking |
---|
91 | unsigned int x = cluster_xy >> Y_WIDTH; |
---|
92 | unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); |
---|
93 | if (x >= X_SIZE) _exit(); |
---|
94 | if (y >= Y_SIZE) _exit(); |
---|
95 | if (channel >= (NB_PROCS_MAX * IRQ_PER_PROCESSOR)) _exit(); |
---|
96 | |
---|
97 | unsigned int func = 0; |
---|
98 | if (irq_type == IRQ_TYPE_PTI) func = XCU_MSK_PTI_ENABLE; |
---|
99 | else if (irq_type == IRQ_TYPE_WTI) func = XCU_MSK_WTI_ENABLE; |
---|
100 | else if (irq_type == IRQ_TYPE_HWI) func = XCU_MSK_HWI_ENABLE; |
---|
101 | else |
---|
102 | { |
---|
103 | _printf("[GIET ERROR] _xcu_set_mask() receives illegal IRQ type\n"); |
---|
104 | _exit(); |
---|
105 | } |
---|
106 | |
---|
107 | _xcu_set_register(cluster_xy, func, channel, value); |
---|
108 | |
---|
109 | #else |
---|
110 | _printf("[GIET ERROR] _xcu_set_mask() should not be used if USE_XCU not set\n"); |
---|
111 | _exit(); |
---|
112 | #endif |
---|
113 | } |
---|
114 | |
---|
115 | ///////////////////////////////////////////// |
---|
116 | void _xcu_get_index( unsigned int cluster_xy, |
---|
117 | unsigned int channel, |
---|
118 | unsigned int * index, |
---|
119 | unsigned int * irq_type ) |
---|
120 | { |
---|
121 | #if USE_XCU |
---|
122 | // parameters checking |
---|
123 | unsigned int x = cluster_xy >> Y_WIDTH; |
---|
124 | unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); |
---|
125 | if (x >= X_SIZE) _exit(); |
---|
126 | if (y >= Y_SIZE) _exit(); |
---|
127 | if (channel >= (NB_PROCS_MAX * IRQ_PER_PROCESSOR)) _exit(); |
---|
128 | |
---|
129 | unsigned int prio = _xcu_get_register(cluster_xy, XCU_PRIO, channel); |
---|
130 | unsigned int pti_ok = (prio & 0x00000001); |
---|
131 | unsigned int hwi_ok = (prio & 0x00000002); |
---|
132 | unsigned int wti_ok = (prio & 0x00000004); |
---|
133 | unsigned int pti_id = (prio & 0x00001F00) >> 8; |
---|
134 | unsigned int hwi_id = (prio & 0x001F0000) >> 16; |
---|
135 | unsigned int wti_id = (prio & 0x1F000000) >> 24; |
---|
136 | if (pti_ok) |
---|
137 | { |
---|
138 | *index = pti_id; |
---|
139 | *irq_type = IRQ_TYPE_PTI; |
---|
140 | } |
---|
141 | else if (hwi_ok) |
---|
142 | { |
---|
143 | *index = hwi_id; |
---|
144 | *irq_type = IRQ_TYPE_HWI; |
---|
145 | } |
---|
146 | else if (wti_ok) |
---|
147 | { |
---|
148 | *index = wti_id; |
---|
149 | *irq_type = IRQ_TYPE_WTI; |
---|
150 | } |
---|
151 | else |
---|
152 | { |
---|
153 | *index = 32; |
---|
154 | } |
---|
155 | |
---|
156 | #else |
---|
157 | _printf("[GIET ERROR] _xcu_get_index should not be used if USE_XCU is not set\n"); |
---|
158 | _exit(); |
---|
159 | #endif |
---|
160 | } |
---|
161 | |
---|
162 | //////////////////////////////////////////// |
---|
163 | void _xcu_send_wti( unsigned int cluster_xy, |
---|
164 | unsigned int wti_index, |
---|
165 | unsigned int wdata ) |
---|
166 | { |
---|
167 | #if USE_XCU |
---|
168 | // parameters checking |
---|
169 | unsigned int x = cluster_xy >> Y_WIDTH; |
---|
170 | unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); |
---|
171 | if (x >= X_SIZE) _exit(); |
---|
172 | if (y >= Y_SIZE) _exit(); |
---|
173 | if (wti_index >= 32) _exit(); |
---|
174 | |
---|
175 | _xcu_set_register(cluster_xy, XCU_WTI_REG, wti_index, wdata); |
---|
176 | |
---|
177 | #else |
---|
178 | _printf("[GIET ERROR] _xcu_send_wti() should not be used if USE_XCU is not set\n"); |
---|
179 | _exit(); |
---|
180 | #endif |
---|
181 | } |
---|
182 | |
---|
183 | //////////////////////////////////////////// |
---|
184 | void _xcu_send_wti_paddr( unsigned int cluster_xy, |
---|
185 | unsigned int wti_index, |
---|
186 | unsigned int wdata ) |
---|
187 | { |
---|
188 | #if USE_XCU |
---|
189 | // parameters checking |
---|
190 | unsigned int x = cluster_xy >> Y_WIDTH; |
---|
191 | unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); |
---|
192 | if (x >= X_SIZE) _exit(); |
---|
193 | if (y >= Y_SIZE) _exit(); |
---|
194 | if (wti_index >= 32) _exit(); |
---|
195 | |
---|
196 | paddr_t paddr = |
---|
197 | SEG_XCU_BASE + ((paddr_t)cluster_xy << 32) + |
---|
198 | (XCU_REG(XCU_WTI_REG, wti_index) << 2); |
---|
199 | |
---|
200 | _physical_write(paddr, wdata); |
---|
201 | |
---|
202 | #else |
---|
203 | _puts("[GIET ERROR] _xcu_send_wti() should not be used if USE_XCU is not set\n"); |
---|
204 | _exit(); |
---|
205 | #endif |
---|
206 | } |
---|
207 | /////////////////////////////////////////////////// |
---|
208 | void _xcu_get_wti_value( unsigned int cluster_xy, |
---|
209 | unsigned int wti_index, |
---|
210 | unsigned int * value ) |
---|
211 | { |
---|
212 | #if USE_XCU |
---|
213 | // parameters checking |
---|
214 | unsigned int x = cluster_xy >> Y_WIDTH; |
---|
215 | unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); |
---|
216 | if (x >= X_SIZE) _exit(); |
---|
217 | if (y >= Y_SIZE) _exit(); |
---|
218 | if (wti_index >= 32) _exit(); |
---|
219 | |
---|
220 | *value = _xcu_get_register(cluster_xy, XCU_WTI_REG, wti_index); |
---|
221 | |
---|
222 | #else |
---|
223 | _printf("[GIET ERROR] in _xcu_get_wti_value() USE_XCU is not set\n"); |
---|
224 | _exit(); |
---|
225 | #endif |
---|
226 | } |
---|
227 | |
---|
228 | //////////////////////////////////////////////////// |
---|
229 | void _xcu_get_wti_address( unsigned int wti_index, |
---|
230 | unsigned int * address ) |
---|
231 | { |
---|
232 | #if USE_XCU |
---|
233 | if (wti_index >= 32) _exit(); |
---|
234 | |
---|
235 | *address = SEG_XCU_BASE + (XCU_REG(XCU_WTI_REG, wti_index)<<2); |
---|
236 | |
---|
237 | #else |
---|
238 | _printf("[GIET ERROR] in _xcu_get_wti_address() USE_XCU is not set\n"); |
---|
239 | _exit(); |
---|
240 | #endif |
---|
241 | } |
---|
242 | |
---|
243 | /////////////////////////////////////////////// |
---|
244 | void _xcu_timer_start( unsigned int cluster_xy, |
---|
245 | unsigned int pti_index, |
---|
246 | unsigned int period ) |
---|
247 | { |
---|
248 | #if USE_XCU |
---|
249 | // parameters checking |
---|
250 | unsigned int x = cluster_xy >> Y_WIDTH; |
---|
251 | unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); |
---|
252 | if (x >= X_SIZE) _exit(); |
---|
253 | if (y >= Y_SIZE) _exit(); |
---|
254 | |
---|
255 | _xcu_set_register(cluster_xy, XCU_PTI_PER, pti_index, period); |
---|
256 | |
---|
257 | #else |
---|
258 | _printf("[GIET ERROR] in _xcu_timer_start() USE_XCU is not set\n"); |
---|
259 | _exit(); |
---|
260 | #endif |
---|
261 | } |
---|
262 | |
---|
263 | ////////////////////////////////////////////// |
---|
264 | void _xcu_timer_stop( unsigned int cluster_xy, |
---|
265 | unsigned int pti_index) |
---|
266 | { |
---|
267 | #if USE_XCU |
---|
268 | // parameters checking |
---|
269 | unsigned int x = cluster_xy >> Y_WIDTH; |
---|
270 | unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); |
---|
271 | if (x >= X_SIZE) _exit(); |
---|
272 | if (y >= Y_SIZE) _exit(); |
---|
273 | |
---|
274 | _xcu_set_register(cluster_xy, XCU_PTI_PER, pti_index, 0); |
---|
275 | |
---|
276 | #else |
---|
277 | _printf("[GIET ERROR] in _xcu_timer_stop() USE_XCU is not set\n"); |
---|
278 | _exit(); |
---|
279 | #endif |
---|
280 | } |
---|
281 | |
---|
282 | /////////////////////////////////////////////////////////// |
---|
283 | unsigned int _xcu_timer_reset_irq( unsigned int cluster_xy, |
---|
284 | unsigned int pti_index ) |
---|
285 | { |
---|
286 | #if USE_XCU |
---|
287 | // parameters checking |
---|
288 | unsigned int x = cluster_xy >> Y_WIDTH; |
---|
289 | unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); |
---|
290 | if (x >= X_SIZE) _exit(); |
---|
291 | if (y >= Y_SIZE) _exit(); |
---|
292 | |
---|
293 | // This return value is not used / avoid a compilation warning. |
---|
294 | return _xcu_get_register(cluster_xy, XCU_PTI_ACK, pti_index); |
---|
295 | |
---|
296 | #else |
---|
297 | _puts("[GIET ERROR] in _xcu_timer_reset_irq() USE_XCU is not set\n"); |
---|
298 | _exit(); |
---|
299 | return 0; |
---|
300 | #endif |
---|
301 | } |
---|
302 | |
---|
303 | /////////////////////////////////////////////////// |
---|
304 | void _xcu_timer_reset_cpt( unsigned int cluster_xy, |
---|
305 | unsigned int pti_index ) |
---|
306 | { |
---|
307 | #if USE_XCU |
---|
308 | // parameters checking |
---|
309 | unsigned int x = cluster_xy >> Y_WIDTH; |
---|
310 | unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); |
---|
311 | if (x >= X_SIZE) _exit(); |
---|
312 | if (y >= Y_SIZE) _exit(); |
---|
313 | |
---|
314 | unsigned int per = _xcu_get_register(cluster_xy, XCU_PTI_PER, pti_index); |
---|
315 | |
---|
316 | // we write 0 first because if the timer is currently running, |
---|
317 | // the corresponding timer counter is not reset |
---|
318 | _xcu_set_register(cluster_xy, XCU_PTI_PER, pti_index, 0); |
---|
319 | _xcu_set_register(cluster_xy, XCU_PTI_PER, pti_index, per); |
---|
320 | |
---|
321 | #else |
---|
322 | _puts("[GIET ERROR] in _xcu_timer_reset_cpt() USE_XCU is not set\n"); |
---|
323 | _exit(); |
---|
324 | #endif |
---|
325 | } |
---|
326 | |
---|
327 | |
---|
328 | // Local Variables: |
---|
329 | // tab-width: 4 |
---|
330 | // c-basic-offset: 4 |
---|
331 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
332 | // indent-tabs-mode: nil |
---|
333 | // End: |
---|
334 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
335 | |
---|