1 | /* |
---|
2 | * soclib_mty.c - soclib mty driver implementation. |
---|
3 | * |
---|
4 | * Author Alain Greiner (2016,2017,2018) |
---|
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 PARTICULAR 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 | |
---|
25 | #include <hal_kernel_types.h> |
---|
26 | #include <dev_txt.h> |
---|
27 | #include <chdev.h> |
---|
28 | #include <soclib_mty.h> |
---|
29 | #include <thread.h> |
---|
30 | #include <printk.h> |
---|
31 | #include <hal_special.h> |
---|
32 | |
---|
33 | extern chdev_directory_t chdev_dir; // allocated in the kernel_init.c file. |
---|
34 | |
---|
35 | //////////////////////////////////////////////////////////////////////////////////// |
---|
36 | // These global variables implement the MTY_RX FIFOs (one per channel) |
---|
37 | //////////////////////////////////////////////////////////////////////////////////// |
---|
38 | // Implementation note: |
---|
39 | // We allocate - in each cluster - two arrays of FIFOs containing as many entries |
---|
40 | // as the total number of TXT channels, but all entries are not used in all |
---|
41 | // clusters: for a given cluster K, a given entry corresponding to a given channel |
---|
42 | // and a given direction is only used if the associated chdev is in cluster K. |
---|
43 | // With this policy, the driver can ignore the actual placement of chdevs. |
---|
44 | //////////////////////////////////////////////////////////////////////////////////// |
---|
45 | |
---|
46 | __attribute__((section(".kdata"))) |
---|
47 | mty_fifo_t mty_rx_fifo[CONFIG_MAX_TXT_CHANNELS]; |
---|
48 | |
---|
49 | __attribute__((section(".kdata"))) |
---|
50 | mty_fifo_t mty_tx_fifo[CONFIG_MAX_TXT_CHANNELS]; |
---|
51 | |
---|
52 | //////////////////////////////////////////////////////////////////////////////////// |
---|
53 | // These global variables define the physical channel RX and TX state, |
---|
54 | // as required by the virtual channels handling. |
---|
55 | //////////////////////////////////////////////////////////////////////////////////// |
---|
56 | // Implementation note: |
---|
57 | // These state variables are required, because the ISR is called twice for each |
---|
58 | // character on the physical channel (for index and value), and does not the same |
---|
59 | // actions for index and value. They are also used to implement the round-robin |
---|
60 | // policy between TX_FIFOs. |
---|
61 | //////////////////////////////////////////////////////////////////////////////////// |
---|
62 | |
---|
63 | __attribute__((section(".kdata"))) |
---|
64 | bool_t mty_rx_not_new; // RX first byte if false |
---|
65 | |
---|
66 | __attribute__((section(".kdata"))) |
---|
67 | uint32_t mty_rx_channel; // RX virtual channel index |
---|
68 | |
---|
69 | __attribute__((section(".kdata"))) |
---|
70 | bool_t mty_tx_not_new; // TX first byte if false |
---|
71 | |
---|
72 | __attribute__((section(".kdata"))) |
---|
73 | uint32_t mty_tx_value; // TX character ascii value |
---|
74 | |
---|
75 | __attribute__((section(".kdata"))) |
---|
76 | uint32_t mty_tx_last; // TX last selected virtual channel |
---|
77 | |
---|
78 | /////////////////////////////////////// |
---|
79 | void soclib_mty_init( chdev_t * chdev ) |
---|
80 | { |
---|
81 | xptr_t reg_xp; |
---|
82 | |
---|
83 | // initialise function pointers in chdev |
---|
84 | chdev->cmd = &soclib_mty_cmd; |
---|
85 | chdev->isr = &soclib_mty_isr; |
---|
86 | chdev->aux = &soclib_mty_aux; |
---|
87 | |
---|
88 | // get MTY channel and extended pointer on MTY peripheral base address |
---|
89 | xptr_t mty_xp = chdev->base; |
---|
90 | uint32_t channel = chdev->channel; |
---|
91 | bool_t is_rx = chdev->is_rx; |
---|
92 | |
---|
93 | // get SOCLIB_MTY device cluster and local pointer |
---|
94 | cxy_t mty_cxy = GET_CXY( mty_xp ); |
---|
95 | uint32_t * mty_ptr = GET_PTR( mty_xp ); |
---|
96 | |
---|
97 | // enable interruptions for RX |
---|
98 | reg_xp = XPTR( mty_cxy , mty_ptr + MTY_CONFIG ); |
---|
99 | hal_remote_s32( reg_xp , MTY_CONFIG_RX_ENABLE ); |
---|
100 | |
---|
101 | // reset relevant FIFO |
---|
102 | if( is_rx ) |
---|
103 | { |
---|
104 | mty_rx_fifo[channel].sts = 0; |
---|
105 | mty_rx_fifo[channel].ptr = 0; |
---|
106 | mty_rx_fifo[channel].ptw = 0; |
---|
107 | } |
---|
108 | else |
---|
109 | { |
---|
110 | mty_tx_fifo[channel].sts = 0; |
---|
111 | mty_tx_fifo[channel].ptr = 0; |
---|
112 | mty_tx_fifo[channel].ptw = 0; |
---|
113 | } |
---|
114 | } // end soclib_mty_init() |
---|
115 | |
---|
116 | ////////////////////////////////////////////////////////////// |
---|
117 | void __attribute__ ((noinline)) soclib_mty_cmd( xptr_t th_xp ) |
---|
118 | { |
---|
119 | mty_fifo_t * fifo; // MTY_RX or MTY_TX FIFO |
---|
120 | char byte; // byte value |
---|
121 | uint32_t done; // number of bytes moved |
---|
122 | |
---|
123 | // get client thread cluster and local pointer |
---|
124 | cxy_t th_cxy = GET_CXY( th_xp ); |
---|
125 | thread_t * th_ptr = GET_PTR( th_xp ); |
---|
126 | |
---|
127 | // get command arguments |
---|
128 | uint32_t type = hal_remote_l32 ( XPTR( th_cxy , &th_ptr->txt_cmd.type ) ); |
---|
129 | xptr_t buf_xp = hal_remote_l64( XPTR( th_cxy , &th_ptr->txt_cmd.buf_xp ) ); |
---|
130 | uint32_t count = hal_remote_l32 ( XPTR( th_cxy , &th_ptr->txt_cmd.count ) ); |
---|
131 | xptr_t error_xp = XPTR( th_cxy , &th_ptr->txt_cmd.error ); |
---|
132 | |
---|
133 | // get TXT device cluster and pointers |
---|
134 | xptr_t dev_xp = (xptr_t)hal_remote_l64( XPTR( th_cxy , &th_ptr->txt_cmd.dev_xp ) ); |
---|
135 | cxy_t dev_cxy = GET_CXY( dev_xp ); |
---|
136 | chdev_t * dev_ptr = GET_PTR( dev_xp ); |
---|
137 | |
---|
138 | // get MTY channel index and channel base address |
---|
139 | uint32_t channel = hal_remote_l32( XPTR( dev_cxy , &dev_ptr->channel ) ); |
---|
140 | |
---|
141 | /////////////////////// |
---|
142 | if( type == TXT_WRITE ) // write bytes to MTY_TX FIFO |
---|
143 | { |
---|
144 | fifo = &mty_tx_fifo[channel]; |
---|
145 | |
---|
146 | done = 0; |
---|
147 | |
---|
148 | while( done < count ) |
---|
149 | { |
---|
150 | if( fifo->sts < MTY_FIFO_DEPTH ) // put one byte to FIFO if TX_FIFO not full |
---|
151 | { |
---|
152 | // get one byte from command buffer |
---|
153 | byte = hal_remote_lb( buf_xp + done ); |
---|
154 | |
---|
155 | #if DEBUG_HAL_TXT_TX |
---|
156 | uint32_t tx_cycle = (uint32_t)hal_get_cycles(); |
---|
157 | if( DEBUG_HAL_TXT_TX < tx_cycle ) |
---|
158 | printk("\n[DBG] %s : thread %x put character <%c> to TXT%d_TX fifo / cycle %d\n", |
---|
159 | __FUNCTION__, CURRENT_THREAD, byte, channel, tx_cycle ); |
---|
160 | #endif |
---|
161 | // write byte to FIFO |
---|
162 | fifo->data[fifo->ptw] = byte; |
---|
163 | |
---|
164 | // prevent race |
---|
165 | hal_fence(); |
---|
166 | |
---|
167 | // update FIFO state |
---|
168 | fifo->ptw = (fifo->ptw + 1) % MTY_FIFO_DEPTH; |
---|
169 | hal_atomic_add( &fifo->sts , 1 ); |
---|
170 | |
---|
171 | // udate number of bytes moved |
---|
172 | done++; |
---|
173 | } |
---|
174 | else // block & deschedule if TX_FIFO full |
---|
175 | { |
---|
176 | // block on ISR |
---|
177 | thread_block( XPTR( local_cxy , CURRENT_THREAD ) , THREAD_BLOCKED_ISR ); |
---|
178 | |
---|
179 | // deschedule |
---|
180 | sched_yield( "MTY_TX_FIFO full" ); |
---|
181 | } |
---|
182 | } |
---|
183 | |
---|
184 | // set error status in command and return |
---|
185 | hal_remote_s32( error_xp , 0 ); |
---|
186 | } |
---|
187 | /////////////////////////// |
---|
188 | else if( type == TXT_READ ) // read bytes from MTY_RX FIFO |
---|
189 | { |
---|
190 | fifo = &mty_rx_fifo[channel]; |
---|
191 | |
---|
192 | done = 0; |
---|
193 | |
---|
194 | while( done < count ) |
---|
195 | { |
---|
196 | if( fifo->sts > 0 ) // get byte from FIFO if not empty |
---|
197 | { |
---|
198 | // get one byte from FIFO |
---|
199 | char byte = fifo->data[fifo->ptr]; |
---|
200 | |
---|
201 | #if DEBUG_HAL_TXT_RX |
---|
202 | uint32_t rx_cycle = (uint32_t)hal_get_cycles(); |
---|
203 | if( DEBUG_HAL_TXT_RX < rx_cycle ) |
---|
204 | printk("\n[DBG] %s : thread %x get character <%c> from TXT%d_RX fifo / cycle %d\n", |
---|
205 | __FUNCTION__, CURRENT_THREAD, byte, channel, rx_cycle ); |
---|
206 | #endif |
---|
207 | // update FIFO state |
---|
208 | fifo->ptr = (fifo->ptr + 1) % MTY_FIFO_DEPTH; |
---|
209 | hal_atomic_add( &fifo->sts , -1 ); |
---|
210 | |
---|
211 | // set byte to command buffer |
---|
212 | hal_remote_sb( buf_xp + done , byte ); |
---|
213 | |
---|
214 | // udate number of bytes |
---|
215 | done++; |
---|
216 | } |
---|
217 | else // deschedule if FIFO empty |
---|
218 | { |
---|
219 | // block on ISR |
---|
220 | thread_block( XPTR( local_cxy , CURRENT_THREAD ) , THREAD_BLOCKED_ISR ); |
---|
221 | |
---|
222 | // deschedule |
---|
223 | sched_yield( "MTY_RX_FIFO empty" ); |
---|
224 | } |
---|
225 | } // end while |
---|
226 | |
---|
227 | // set error status in command |
---|
228 | hal_remote_s32( error_xp , 0 ); |
---|
229 | } |
---|
230 | else |
---|
231 | { |
---|
232 | assert( __FUNCTION__, false , "illegal TXT command\n" ); |
---|
233 | } |
---|
234 | |
---|
235 | } // end soclib_mty_cmd() |
---|
236 | |
---|
237 | ///////////////////////////////////////////////////////////////// |
---|
238 | void __attribute__ ((noinline)) soclib_mty_isr( chdev_t * chdev ) |
---|
239 | { |
---|
240 | thread_t * server; // pointer on TXT chdev server thread |
---|
241 | lid_t server_lid; // local index of core running the server thread |
---|
242 | uint32_t channel; // TXT chdev channel (virtual channel index) |
---|
243 | bool_t is_rx; // TXT chdev direction |
---|
244 | char byte; // byte value |
---|
245 | xptr_t owner_xp; // extended pointer on TXT owner process |
---|
246 | cxy_t owner_cxy; // TXT owner process cluster |
---|
247 | process_t * owner_ptr; // local pointer on TXT owner process |
---|
248 | pid_t owner_pid; // TXT owner process identifier |
---|
249 | mty_fifo_t * fifo; // pointer on MTY_TX or MTY_RX FIFO |
---|
250 | cxy_t mty_cxy; // soclib_mty cluster |
---|
251 | uint32_t * mty_ptr; // soclib_mty segment base address |
---|
252 | xptr_t status_xp; // extended pointer on MTY_STATUS register |
---|
253 | xptr_t write_xp; // extended pointer on MTY_WRITE register |
---|
254 | xptr_t read_xp; // extended pointer on MTY_READ register |
---|
255 | xptr_t parent_xp; // extended pointer on parent process |
---|
256 | cxy_t parent_cxy; // parent process cluster |
---|
257 | process_t * parent_ptr; // local pointer on parent process |
---|
258 | thread_t * parent_main_ptr; // extended pointer on parent process main thread |
---|
259 | xptr_t parent_main_xp; // local pointer on parent process main thread |
---|
260 | uint32_t n; // index in loop |
---|
261 | bool_t found; |
---|
262 | |
---|
263 | #if DEBUG_HAL_TXT_RX |
---|
264 | uint32_t rx_cycle = (uint32_t)hal_get_cycles(); |
---|
265 | #endif |
---|
266 | |
---|
267 | #if DEBUG_HAL_TXT_TX |
---|
268 | uint32_t tx_cycle = (uint32_t)hal_get_cycles(); |
---|
269 | #endif |
---|
270 | |
---|
271 | // get TXT chdev channel, direction and server thread |
---|
272 | is_rx = chdev->is_rx; |
---|
273 | server = chdev->server; |
---|
274 | server_lid = server->core->lid; |
---|
275 | |
---|
276 | // get SOCLIB_MTY peripheral cluster and local pointer |
---|
277 | mty_cxy = GET_CXY( chdev->base ); |
---|
278 | mty_ptr = GET_PTR( chdev->base ); |
---|
279 | |
---|
280 | // get extended pointer on MTY registers |
---|
281 | status_xp = XPTR( mty_cxy , mty_ptr + MTY_STATUS ); |
---|
282 | write_xp = XPTR( mty_cxy , mty_ptr + MTY_WRITE ); |
---|
283 | read_xp = XPTR( mty_cxy , mty_ptr + MTY_READ ); |
---|
284 | |
---|
285 | /////////////////////////// handle RX ////////////////////// |
---|
286 | if( is_rx ) |
---|
287 | { |
---|
288 | // check one byte available in MTY_READ register |
---|
289 | if( hal_remote_l32( status_xp ) & MTY_STATUS_RX_FULL ) |
---|
290 | { |
---|
291 | // get one byte from MTY_READ register & acknowledge RX_IRQ |
---|
292 | byte = (char)hal_remote_lb( read_xp ); |
---|
293 | |
---|
294 | // test physical RX channel state |
---|
295 | if( mty_rx_not_new == false ) // get first byte (virtual channel index) |
---|
296 | { |
---|
297 | // register virtual channel index |
---|
298 | mty_rx_channel = (uint32_t)byte; |
---|
299 | |
---|
300 | // update physical RX channel state |
---|
301 | mty_rx_not_new = true; |
---|
302 | } |
---|
303 | else // get second byte (character value) |
---|
304 | { |
---|
305 | // get virtual channel index registered |
---|
306 | channel = mty_rx_channel; |
---|
307 | |
---|
308 | // get destination TX_FIFO |
---|
309 | fifo = &mty_rx_fifo[channel]; |
---|
310 | |
---|
311 | // filter special character ^Z => block TXT owner process |
---|
312 | if( byte == 0x1A ) |
---|
313 | { |
---|
314 | |
---|
315 | #if DEBUG_HAL_TXT_RX |
---|
316 | if( DEBUG_HAL_TXT_RX < rx_cycle ) |
---|
317 | printk("\n[DBG] %s : read ^Z character from TXT%d\n", __FUNCTION__, channel ); |
---|
318 | #endif |
---|
319 | // get pointers on TXT owner process in owner cluster |
---|
320 | owner_xp = process_txt_get_owner( channel ); |
---|
321 | |
---|
322 | // check process exist |
---|
323 | assert( __FUNCTION__, (owner_xp != XPTR_NULL) , "TXT owner process not found\n" ); |
---|
324 | |
---|
325 | // get relevant infos on TXT owner process |
---|
326 | owner_cxy = GET_CXY( owner_xp ); |
---|
327 | owner_ptr = GET_PTR( owner_xp ); |
---|
328 | owner_pid = hal_remote_l32( XPTR( owner_cxy , &owner_ptr->pid ) ); |
---|
329 | |
---|
330 | // block TXT owner process only if it is not the INIT process |
---|
331 | if( owner_pid != 1 ) |
---|
332 | { |
---|
333 | // get parent process descriptor pointers |
---|
334 | parent_xp = hal_remote_l64( XPTR( owner_cxy , |
---|
335 | &owner_ptr->parent_xp ) ); |
---|
336 | parent_cxy = GET_CXY( parent_xp ); |
---|
337 | parent_ptr = GET_PTR( parent_xp ); |
---|
338 | |
---|
339 | // get pointers on the parent process main thread |
---|
340 | parent_main_ptr = hal_remote_lpt( XPTR(parent_cxy, |
---|
341 | &parent_ptr->th_tbl[0])); |
---|
342 | parent_main_xp = XPTR( parent_cxy , parent_main_ptr ); |
---|
343 | |
---|
344 | // transfer TXT ownership |
---|
345 | process_txt_transfer_ownership( owner_xp ); |
---|
346 | |
---|
347 | // block all threads in all clusters, but the main thread |
---|
348 | process_sigaction( owner_pid , BLOCK_ALL_THREADS ); |
---|
349 | |
---|
350 | // block the main thread |
---|
351 | xptr_t main_xp = XPTR( owner_cxy , &owner_ptr->th_tbl[0] ); |
---|
352 | thread_block( main_xp , THREAD_BLOCKED_GLOBAL ); |
---|
353 | |
---|
354 | // atomically update owner process termination state |
---|
355 | hal_remote_atomic_or( XPTR( owner_cxy , &owner_ptr->term_state ) , |
---|
356 | PROCESS_TERM_STOP ); |
---|
357 | |
---|
358 | // take the children lock and unblock the parent process main thread |
---|
359 | thread_unblock( parent_main_xp , THREAD_BLOCKED_WAIT ); |
---|
360 | |
---|
361 | return; |
---|
362 | } |
---|
363 | } |
---|
364 | |
---|
365 | // filter special character ^C => kill TXT owner process |
---|
366 | if( byte == 0x03 ) |
---|
367 | { |
---|
368 | |
---|
369 | #if DEBUG_HAL_TXT_RX |
---|
370 | if( DEBUG_HAL_TXT_RX < rx_cycle ) |
---|
371 | printk("\n[DBG] %s : read ^C character from TXT%d\n", __FUNCTION__, channel ); |
---|
372 | #endif |
---|
373 | // get pointer on TXT owner process in owner cluster |
---|
374 | owner_xp = process_txt_get_owner( channel ); |
---|
375 | |
---|
376 | // check process exist |
---|
377 | assert( __FUNCTION__, (owner_xp != XPTR_NULL) , "TXT owner process not found\n" ); |
---|
378 | |
---|
379 | // get relevant infos on TXT owner process |
---|
380 | owner_cxy = GET_CXY( owner_xp ); |
---|
381 | owner_ptr = GET_PTR( owner_xp ); |
---|
382 | owner_pid = hal_remote_l32( XPTR( owner_cxy , &owner_ptr->pid ) ); |
---|
383 | |
---|
384 | // kill TXT owner process only if it is not the INIT process |
---|
385 | if( owner_pid != 1 ) |
---|
386 | { |
---|
387 | // get parent process descriptor pointers |
---|
388 | parent_xp = hal_remote_l64( XPTR( owner_cxy, |
---|
389 | &owner_ptr->parent_xp ) ); |
---|
390 | parent_cxy = GET_CXY( parent_xp ); |
---|
391 | parent_ptr = GET_PTR( parent_xp ); |
---|
392 | |
---|
393 | // get pointers on the parent process main thread |
---|
394 | parent_main_ptr = hal_remote_lpt( XPTR( parent_cxy, |
---|
395 | &parent_ptr->th_tbl[0])); |
---|
396 | parent_main_xp = XPTR( parent_cxy , parent_main_ptr ); |
---|
397 | |
---|
398 | // remove process from TXT list |
---|
399 | process_txt_detach( owner_xp ); |
---|
400 | |
---|
401 | // mark for delete all thread in all clusters, but the main |
---|
402 | process_sigaction( owner_pid , DELETE_ALL_THREADS ); |
---|
403 | |
---|
404 | // block main thread |
---|
405 | xptr_t main_xp = XPTR( owner_cxy , &owner_ptr->th_tbl[0] ); |
---|
406 | thread_block( main_xp , THREAD_BLOCKED_GLOBAL ); |
---|
407 | |
---|
408 | // atomically update owner process termination state |
---|
409 | hal_remote_atomic_or( XPTR( owner_cxy , &owner_ptr->term_state ) , |
---|
410 | PROCESS_TERM_KILL ); |
---|
411 | |
---|
412 | // take the children lock and unblock the parent process main thread |
---|
413 | thread_unblock( parent_main_xp , THREAD_BLOCKED_WAIT ); |
---|
414 | |
---|
415 | return; |
---|
416 | } |
---|
417 | } |
---|
418 | |
---|
419 | // write byte in RX FIFO if not full / discard byte if full |
---|
420 | if ( fifo->sts < MTY_FIFO_DEPTH ) |
---|
421 | { |
---|
422 | |
---|
423 | #if DEBUG_HAL_TXT_RX |
---|
424 | if( DEBUG_HAL_TXT_RX < rx_cycle ) |
---|
425 | printk("\n[DBG] %s : put character <%c> to TXT%d_RX fifo\n", |
---|
426 | __FUNCTION__, byte, channel ); |
---|
427 | #endif |
---|
428 | // store byte into FIFO |
---|
429 | fifo->data[fifo->ptw] = (char)byte; |
---|
430 | |
---|
431 | // avoid race |
---|
432 | hal_fence(); |
---|
433 | |
---|
434 | // update RX_FIFO state |
---|
435 | fifo->ptw = (fifo->ptw + 1) % MTY_FIFO_DEPTH; |
---|
436 | hal_atomic_add( &fifo->sts , 1 ); |
---|
437 | |
---|
438 | // unblock TXT_RX server thread |
---|
439 | thread_unblock( XPTR( local_cxy , server ) , THREAD_BLOCKED_ISR ); |
---|
440 | |
---|
441 | // send IPI to core running server thread |
---|
442 | dev_pic_send_ipi( local_cxy , server_lid ); |
---|
443 | } |
---|
444 | else |
---|
445 | { |
---|
446 | printk("\n[WARNING] %s : MTY_RX_FIFO[%d] full => discard char <%x>\n", |
---|
447 | __FUNCTION__, channel, (uint32_t)byte ); |
---|
448 | } |
---|
449 | |
---|
450 | // update physical RX channel state |
---|
451 | mty_rx_not_new = true; |
---|
452 | |
---|
453 | } // end get character value |
---|
454 | } // end if byte available in MTY_READ register |
---|
455 | } // end RX |
---|
456 | |
---|
457 | /////////////////////// handle TX ///////////////////////////// |
---|
458 | else |
---|
459 | { |
---|
460 | // test physical TX channel state |
---|
461 | if( mty_tx_not_new == false ) // send first byte (virtual channel index) |
---|
462 | { |
---|
463 | // scan the set of the TX_FIFO |
---|
464 | for( n = 0 , found = false ; n < CONFIG_MAX_TXT_CHANNELS ; n++ ) |
---|
465 | { |
---|
466 | // implement round-robin policy |
---|
467 | channel = (n + mty_tx_last + 1) % CONFIG_MAX_TXT_CHANNELS; |
---|
468 | |
---|
469 | // get pointer on TX_FIFO[channel] |
---|
470 | fifo = &mty_tx_fifo[channel]; |
---|
471 | |
---|
472 | if( fifo->sts > 0 ) |
---|
473 | { |
---|
474 | found = true; |
---|
475 | break; |
---|
476 | } |
---|
477 | } |
---|
478 | |
---|
479 | // get one byte from TX_FIFO if found and send channel index |
---|
480 | if( found ) |
---|
481 | { |
---|
482 | // get one byte from selected TX_FIFO |
---|
483 | byte = fifo->data[fifo->ptr]; |
---|
484 | |
---|
485 | #if DEBUG_HAL_TXT_TX |
---|
486 | if( DEBUG_HAL_TXT_TX < tx_cycle ) |
---|
487 | printk("\n[DBG] %s : get character <%c> from TXT%d_TX fifo\n", |
---|
488 | __FUNCTION__, byte, channel ); |
---|
489 | #endif |
---|
490 | // update TX_FIFO state |
---|
491 | fifo->ptr = (fifo->ptr + 1) % MTY_FIFO_DEPTH; |
---|
492 | hal_atomic_add( &fifo->sts , -1 ); |
---|
493 | |
---|
494 | // update TX physical channel state |
---|
495 | mty_tx_value = (uint32_t)byte; |
---|
496 | mty_tx_not_new = true; |
---|
497 | mty_tx_last = channel; |
---|
498 | |
---|
499 | // write virtual channel index to TX_WRITE register |
---|
500 | hal_remote_sb( write_xp , (uint8_t)channel ); |
---|
501 | |
---|
502 | // unblock TXT_TX server thread |
---|
503 | thread_unblock( XPTR( local_cxy , server ) , THREAD_BLOCKED_ISR ); |
---|
504 | |
---|
505 | // send IPI to core running server thread |
---|
506 | dev_pic_send_ipi( local_cxy , server_lid ); |
---|
507 | } |
---|
508 | } |
---|
509 | else // send second byte (character value) |
---|
510 | { |
---|
511 | // write registered character value to TX_WRITE register |
---|
512 | hal_remote_sb( write_xp , (uint8_t)mty_tx_value ); |
---|
513 | |
---|
514 | // update TX physical channel state |
---|
515 | mty_tx_not_new = false; |
---|
516 | } // end if MTY_WRITE register empty |
---|
517 | } // end TX |
---|
518 | |
---|
519 | hal_fence(); |
---|
520 | |
---|
521 | } // end soclib_mty_isr() |
---|
522 | |
---|
523 | ///////////////////////////////////////////////////////////// |
---|
524 | void __attribute__ ((noinline)) soclib_mty_aux( void * args ) |
---|
525 | { |
---|
526 | uint32_t i; |
---|
527 | |
---|
528 | xptr_t dev_xp = ((txt_sync_args_t *)args)->dev_xp; |
---|
529 | const char * buffer = ((txt_sync_args_t *)args)->buffer; |
---|
530 | uint32_t count = ((txt_sync_args_t *)args)->count; |
---|
531 | uint32_t channel = ((txt_sync_args_t *)args)->channel; |
---|
532 | |
---|
533 | // get chdev cluster and local pointer |
---|
534 | cxy_t dev_cxy = GET_CXY( dev_xp ); |
---|
535 | chdev_t * dev_ptr = GET_PTR( dev_xp ); |
---|
536 | |
---|
537 | // get extended pointer on MTY channel base address |
---|
538 | xptr_t mty_xp = (xptr_t)hal_remote_l64( XPTR( dev_cxy , &dev_ptr->base ) ); |
---|
539 | |
---|
540 | // get MTY channel segment cluster and local pointer |
---|
541 | cxy_t mty_cxy = GET_CXY( mty_xp ); |
---|
542 | uint32_t * mty_ptr = GET_PTR( mty_xp ); |
---|
543 | |
---|
544 | // get extended pointers on MTY_WRITE & MTY_STATUS registers |
---|
545 | xptr_t write_xp = XPTR( mty_cxy , mty_ptr + MTY_WRITE ); |
---|
546 | |
---|
547 | // loop on characters (two bytes per character) |
---|
548 | for( i = 0 ; i < count ; i++ ) |
---|
549 | { |
---|
550 | // write virtual channel index to MTY_WRITE register |
---|
551 | hal_remote_sb( write_xp , (uint8_t)channel ); |
---|
552 | |
---|
553 | // write character value to MTY_WRITE register |
---|
554 | hal_remote_sb( write_xp , buffer[i] ); |
---|
555 | } |
---|
556 | } // end soclib_mty_aux() |
---|
557 | |
---|
558 | |
---|
559 | |
---|