1 | /* |
---|
2 | * soclib_mtty.c - soclib tty 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_mtty.h> |
---|
29 | #include <remote_spinlock.h> |
---|
30 | #include <thread.h> |
---|
31 | #include <printk.h> |
---|
32 | #include <hal_special.h> |
---|
33 | |
---|
34 | #if (DEBUG_SYS_READ & 1) |
---|
35 | extern uint32_t enter_tty_cmd_read; |
---|
36 | extern uint32_t exit_tty_cmd_read; |
---|
37 | |
---|
38 | extern uint32_t enter_tty_isr_read; |
---|
39 | extern uint32_t exit_tty_isr_read; |
---|
40 | #endif |
---|
41 | |
---|
42 | #if (DEBUG_SYS_WRITE & 1) |
---|
43 | extern uint32_t enter_tty_cmd_write; |
---|
44 | extern uint32_t exit_tty_cmd_write; |
---|
45 | |
---|
46 | extern uint32_t enter_tty_isr_write; |
---|
47 | extern uint32_t exit_tty_isr_write; |
---|
48 | #endif |
---|
49 | |
---|
50 | //////////////////////////////////////////////////////////////////////////////////// |
---|
51 | // These global variables implement the MTTY_RX FIFOs (one per channel) |
---|
52 | //////////////////////////////////////////////////////////////////////////////////// |
---|
53 | |
---|
54 | __attribute__((section(".kdata"))) |
---|
55 | mtty_fifo_t mtty_rx_fifo[CONFIG_MAX_TXT_CHANNELS]; |
---|
56 | |
---|
57 | __attribute__((section(".kdata"))) |
---|
58 | mtty_fifo_t mtty_tx_fifo[CONFIG_MAX_TXT_CHANNELS]; |
---|
59 | |
---|
60 | /////////////////////////////////////// |
---|
61 | void soclib_mtty_init( chdev_t * chdev ) |
---|
62 | { |
---|
63 | xptr_t reg_xp; |
---|
64 | |
---|
65 | // initialise function pointers in chdev |
---|
66 | chdev->cmd = &soclib_mtty_cmd; |
---|
67 | chdev->isr = &soclib_mtty_isr; |
---|
68 | chdev->aux = &soclib_mtty_aux; |
---|
69 | |
---|
70 | // get TTY channel and extended pointer on TTY peripheral base address |
---|
71 | xptr_t tty_xp = chdev->base; |
---|
72 | uint32_t channel = chdev->channel; |
---|
73 | bool_t is_rx = chdev->is_rx; |
---|
74 | |
---|
75 | // get SOCLIB_TTY device cluster and local pointer |
---|
76 | cxy_t tty_cxy = GET_CXY( tty_xp ); |
---|
77 | uint32_t * tty_ptr = GET_PTR( tty_xp ); |
---|
78 | |
---|
79 | // enable interruptions for RX but not for TX |
---|
80 | reg_xp = XPTR( tty_cxy , tty_ptr + MTTY_CONFIG ); |
---|
81 | hal_remote_sw( reg_xp , MTTY_CONFIG_RX_ENABLE ); |
---|
82 | |
---|
83 | // reset relevant FIFO |
---|
84 | if( is_rx ) |
---|
85 | { |
---|
86 | mtty_rx_fifo[channel].sts = 0; |
---|
87 | mtty_rx_fifo[channel].ptr = 0; |
---|
88 | mtty_rx_fifo[channel].ptw = 0; |
---|
89 | } |
---|
90 | else |
---|
91 | { |
---|
92 | mtty_tx_fifo[channel].sts = 0; |
---|
93 | mtty_tx_fifo[channel].ptr = 0; |
---|
94 | mtty_tx_fifo[channel].ptw = 0; |
---|
95 | } |
---|
96 | } // end soclib_mtty_init() |
---|
97 | |
---|
98 | ////////////////////////////////////////////////////////////// |
---|
99 | void __attribute__ ((noinline)) soclib_mtty_cmd( xptr_t th_xp ) |
---|
100 | { |
---|
101 | mtty_fifo_t * fifo; // MTTY_RX or MTTY_TX FIFO |
---|
102 | char byte; // byte value |
---|
103 | uint32_t done; // number of bytes moved |
---|
104 | |
---|
105 | // get client thread cluster and local pointer |
---|
106 | cxy_t th_cxy = GET_CXY( th_xp ); |
---|
107 | thread_t * th_ptr = GET_PTR( th_xp ); |
---|
108 | |
---|
109 | // get command arguments |
---|
110 | uint32_t type = hal_remote_lw ( XPTR( th_cxy , &th_ptr->txt_cmd.type ) ); |
---|
111 | xptr_t buf_xp = hal_remote_lwd( XPTR( th_cxy , &th_ptr->txt_cmd.buf_xp ) ); |
---|
112 | uint32_t count = hal_remote_lw ( XPTR( th_cxy , &th_ptr->txt_cmd.count ) ); |
---|
113 | xptr_t error_xp = XPTR( th_cxy , &th_ptr->txt_cmd.error ); |
---|
114 | |
---|
115 | #if (DEBUG_SYS_READ & 1) |
---|
116 | if( type == TXT_READ) enter_tty_cmd_read = (uint32_t)hal_get_cycles(); |
---|
117 | #endif |
---|
118 | |
---|
119 | #if (DEBUG_SYS_WRITE & 1) |
---|
120 | if( type == TXT_WRITE) enter_tty_cmd_write = (uint32_t)hal_get_cycles(); |
---|
121 | #endif |
---|
122 | |
---|
123 | // get TXT device cluster and pointers |
---|
124 | xptr_t dev_xp = (xptr_t)hal_remote_lwd( XPTR( th_cxy , &th_ptr->txt_cmd.dev_xp ) ); |
---|
125 | cxy_t dev_cxy = GET_CXY( dev_xp ); |
---|
126 | chdev_t * dev_ptr = GET_PTR( dev_xp ); |
---|
127 | |
---|
128 | // get cluster and pointers for SOCLIB_TTY peripheral base segment |
---|
129 | xptr_t tty_xp = (xptr_t)hal_remote_lwd( XPTR( dev_cxy , &dev_ptr->base ) ); |
---|
130 | cxy_t tty_cxy = GET_CXY( tty_xp ); |
---|
131 | uint32_t * tty_ptr = GET_PTR( tty_xp ); |
---|
132 | |
---|
133 | // get TTY channel index and channel base address |
---|
134 | uint32_t channel = hal_remote_lw( XPTR( dev_cxy , &dev_ptr->channel ) ); |
---|
135 | uint32_t * base = tty_ptr; |
---|
136 | |
---|
137 | /////////////////////// |
---|
138 | if( type == TXT_WRITE ) // write bytes to MTTY_TX FIFO |
---|
139 | { |
---|
140 | fifo = &mtty_tx_fifo[channel]; |
---|
141 | |
---|
142 | done = 0; |
---|
143 | |
---|
144 | while( done < count ) |
---|
145 | { |
---|
146 | if( fifo->sts < MTTY_FIFO_DEPTH ) // put one byte to FIFO if TX_FIFO not full |
---|
147 | { |
---|
148 | // get one byte from command buffer |
---|
149 | byte = hal_remote_lb( buf_xp + done ); |
---|
150 | |
---|
151 | #if DEBUG_HAL_TXT_TX |
---|
152 | uint32_t tx_cycle = (uint32_t)hal_get_cycles(); |
---|
153 | if( DEBUG_HAL_TXT_TX < tx_cycle ) |
---|
154 | printk("\n[DBG] %s : thread %x put character <%c> to TXT%d_TX fifo / cycle %d\n", |
---|
155 | __FUNCTION__, CURRENT_THREAD, byte, channel, tx_cycle ); |
---|
156 | #endif |
---|
157 | // write byte to FIFO |
---|
158 | fifo->data[fifo->ptw] = byte; |
---|
159 | |
---|
160 | // prevent race |
---|
161 | hal_fence(); |
---|
162 | |
---|
163 | // update FIFO state |
---|
164 | fifo->ptw = (fifo->ptw + 1) % MTTY_FIFO_DEPTH; |
---|
165 | hal_atomic_add( &fifo->sts , 1 ); |
---|
166 | |
---|
167 | // udate number of bytes moved |
---|
168 | done++; |
---|
169 | |
---|
170 | // enable TX_IRQ |
---|
171 | // vci_multi_tty devices never raise TX IRQs |
---|
172 | // so the following instructions are useless |
---|
173 | // and moreover they kernel panic |
---|
174 | // xptr_t config_xp = XPTR( tty_cxy , base + MTTY_CONFIG ); |
---|
175 | // uint32_t old = hal_remote_lw( config_xp ); |
---|
176 | // uint32_t new = old | MTTY_CONFIG_TX_ENABLE; |
---|
177 | // hal_remote_atomic_cas( config_xp , old , new ); |
---|
178 | // hal_remote_sw( XPTR( tty_cxy , base + MTTY_CONFIG ) , MTTY_CONFIG_TX_ENABLE ); |
---|
179 | } |
---|
180 | else // block & deschedule if TX_FIFO full |
---|
181 | { |
---|
182 | // block on ISR |
---|
183 | thread_block( XPTR( local_cxy , CURRENT_THREAD ) , THREAD_BLOCKED_ISR ); |
---|
184 | |
---|
185 | // deschedule |
---|
186 | sched_yield( "MTTY_TX_FIFO full" ); |
---|
187 | } |
---|
188 | } |
---|
189 | |
---|
190 | // set error status in command and return |
---|
191 | hal_remote_sw( error_xp , 0 ); |
---|
192 | } |
---|
193 | /////////////////////////// |
---|
194 | else if( type == TXT_READ ) // read bytes from MTTY_RX FIFO |
---|
195 | { |
---|
196 | fifo = &mtty_rx_fifo[channel]; |
---|
197 | |
---|
198 | done = 0; |
---|
199 | |
---|
200 | while( done < count ) |
---|
201 | { |
---|
202 | if( fifo->sts > 0 ) // get byte from FIFO if not empty |
---|
203 | { |
---|
204 | // get one byte from FIFO |
---|
205 | char byte = fifo->data[fifo->ptr]; |
---|
206 | |
---|
207 | #if DEBUG_HAL_TXT_RX |
---|
208 | uint32_t rx_cycle = (uint32_t)hal_get_cycles(); |
---|
209 | if( DEBUG_HAL_TXT_RX < rx_cycle ) |
---|
210 | printk("\n[DBG] %s : thread %x get character <%c> from TXT%d_RX fifo / cycle %d\n", |
---|
211 | __FUNCTION__, CURRENT_THREAD, byte, channel, rx_cycle ); |
---|
212 | #endif |
---|
213 | // update FIFO state |
---|
214 | fifo->ptr = (fifo->ptr + 1) % MTTY_FIFO_DEPTH; |
---|
215 | hal_atomic_add( &fifo->sts , -1 ); |
---|
216 | |
---|
217 | // set byte to command buffer |
---|
218 | hal_remote_sb( buf_xp + done , byte ); |
---|
219 | |
---|
220 | // udate number of bytes |
---|
221 | done++; |
---|
222 | } |
---|
223 | else // deschedule if FIFO empty |
---|
224 | { |
---|
225 | // block on ISR |
---|
226 | thread_block( XPTR( local_cxy , CURRENT_THREAD ) , THREAD_BLOCKED_ISR ); |
---|
227 | |
---|
228 | // deschedule |
---|
229 | sched_yield( "MTTY_RX_FIFO empty" ); |
---|
230 | } |
---|
231 | } // end while |
---|
232 | |
---|
233 | // set error status in command |
---|
234 | hal_remote_sw( error_xp , 0 ); |
---|
235 | } |
---|
236 | else |
---|
237 | { |
---|
238 | assert( false , __FUNCTION__ , "illegal TXT command\n" ); |
---|
239 | } |
---|
240 | |
---|
241 | #if (DEBUG_SYS_READ & 1) |
---|
242 | if( type == TXT_READ ) exit_tty_cmd_read = (uint32_t)hal_get_cycles(); |
---|
243 | #endif |
---|
244 | |
---|
245 | #if (DEBUG_SYS_WRITE & 1) |
---|
246 | if( type == TXT_WRITE ) exit_tty_cmd_write = (uint32_t)hal_get_cycles(); |
---|
247 | #endif |
---|
248 | |
---|
249 | } // end soclib_mtty_cmd() |
---|
250 | |
---|
251 | ///////////////////////////////////////////////////////////////// |
---|
252 | void __attribute__ ((noinline)) soclib_mtty_isr( chdev_t * chdev ) |
---|
253 | { |
---|
254 | thread_t * server; // pointer on TXT chdev server thread |
---|
255 | lid_t server_lid; // local index of core running the server thread |
---|
256 | uint32_t channel; // TXT chdev channel |
---|
257 | bool_t is_rx; // TXT chdev direction |
---|
258 | char byte; // byte value |
---|
259 | xptr_t owner_xp; // extended pointer on TXT owner process |
---|
260 | cxy_t owner_cxy; // TXT owner process cluster |
---|
261 | process_t * owner_ptr; // local pointer on TXT owner process |
---|
262 | pid_t owner_pid; // TXT owner process identifier |
---|
263 | mtty_fifo_t * fifo; // pointer on MTTY_TX or MTTY_RX FIFO |
---|
264 | cxy_t tty_cxy; // soclib_mtty cluster |
---|
265 | uint32_t * tty_ptr; // soclib_mtty segment base address |
---|
266 | uint32_t * base; // soclib_mtty channel base address |
---|
267 | xptr_t status_xp; // extended pointer on MTTY_STATUS register |
---|
268 | xptr_t write_xp; // extended pointer on MTTY_WRITE register |
---|
269 | xptr_t read_xp; // extended pointer on MTTY_READ register |
---|
270 | xptr_t parent_xp; // extended pointer on parent process |
---|
271 | cxy_t parent_cxy; // parent process cluster |
---|
272 | process_t * parent_ptr; // local pointer on parent process |
---|
273 | xptr_t children_lock_xp; // extended pointer on children processes lock |
---|
274 | thread_t * parent_main_ptr; // extended pointer on parent process main thread |
---|
275 | xptr_t parent_main_xp; // local pointer on parent process main thread |
---|
276 | |
---|
277 | // get TXT chdev channel, direction and server thread |
---|
278 | channel = chdev->channel; |
---|
279 | is_rx = chdev->is_rx; |
---|
280 | server = chdev->server; |
---|
281 | server_lid = server->core->lid; |
---|
282 | |
---|
283 | #if (DEBUG_SYS_READ & 1) |
---|
284 | if( is_rx ) enter_tty_isr_read = (uint32_t)hal_get_cycles(); |
---|
285 | #endif |
---|
286 | |
---|
287 | #if (DEBUG_SYS_WRITE & 1) |
---|
288 | if( is_rx == 0 ) enter_tty_isr_write = (uint32_t)hal_get_cycles(); |
---|
289 | #endif |
---|
290 | |
---|
291 | #if DEBUG_HAL_TXT_RX |
---|
292 | uint32_t rx_cycle = (uint32_t)hal_get_cycles(); |
---|
293 | #endif |
---|
294 | |
---|
295 | #if DEBUG_HAL_TXT_TX |
---|
296 | uint32_t tx_cycle = (uint32_t)hal_get_cycles(); |
---|
297 | #endif |
---|
298 | |
---|
299 | // get SOCLIB_TTY peripheral cluster and local pointer |
---|
300 | tty_cxy = GET_CXY( chdev->base ); |
---|
301 | tty_ptr = GET_PTR( chdev->base ); |
---|
302 | |
---|
303 | // get channel base address |
---|
304 | base = tty_ptr; |
---|
305 | |
---|
306 | // get extended pointer on TTY registers |
---|
307 | status_xp = XPTR( tty_cxy , base + MTTY_STATUS ); |
---|
308 | write_xp = XPTR( tty_cxy , base + MTTY_WRITE ); |
---|
309 | read_xp = XPTR( tty_cxy , base + MTTY_READ ); |
---|
310 | |
---|
311 | /////////////////////////// handle RX ////////////////////// |
---|
312 | if( is_rx ) |
---|
313 | { |
---|
314 | fifo = &mtty_rx_fifo[channel]; |
---|
315 | |
---|
316 | // try to move bytes until MTTY_READ register empty |
---|
317 | while( hal_remote_lw( status_xp ) & MTTY_STATUS_RX_FULL ) |
---|
318 | { |
---|
319 | // get one byte from MTTY_READ register & acknowledge RX_IRQ |
---|
320 | byte = (char)hal_remote_lb( read_xp ); |
---|
321 | |
---|
322 | // filter special character ^Z => block TXT owner process |
---|
323 | if( byte == 0x1A ) |
---|
324 | { |
---|
325 | |
---|
326 | #if DEBUG_HAL_TXT_RX |
---|
327 | if( DEBUG_HAL_TXT_RX < rx_cycle ) |
---|
328 | printk("\n[DBG] %s : read ^Z character from TXT%d\n", __FUNCTION__, channel ); |
---|
329 | #endif |
---|
330 | // get pointers on TXT owner process in owner cluster |
---|
331 | owner_xp = process_txt_get_owner( channel ); |
---|
332 | |
---|
333 | // check process exist |
---|
334 | assert( (owner_xp != XPTR_NULL) , __FUNCTION__, |
---|
335 | "TXT owner process not found\n" ); |
---|
336 | |
---|
337 | // get relevant infos on TXT owner process |
---|
338 | owner_cxy = GET_CXY( owner_xp ); |
---|
339 | owner_ptr = GET_PTR( owner_xp ); |
---|
340 | owner_pid = hal_remote_lw( XPTR( owner_cxy , &owner_ptr->pid ) ); |
---|
341 | |
---|
342 | // block TXT owner process only if it is not the INIT process |
---|
343 | if( owner_pid != 1 ) |
---|
344 | { |
---|
345 | // get parent process descriptor pointers |
---|
346 | parent_xp = hal_remote_lwd( XPTR( owner_cxy , &owner_ptr->parent_xp ) ); |
---|
347 | parent_cxy = GET_CXY( parent_xp ); |
---|
348 | parent_ptr = GET_PTR( parent_xp ); |
---|
349 | |
---|
350 | // get extended pointer on lock protecting children list in parent process |
---|
351 | children_lock_xp = XPTR( parent_cxy , &parent_ptr->children_lock ); |
---|
352 | |
---|
353 | // get pointers on the parent process main thread |
---|
354 | parent_main_ptr = hal_remote_lpt(XPTR(parent_cxy,&parent_ptr->th_tbl[0])); |
---|
355 | parent_main_xp = XPTR( parent_cxy , parent_main_ptr ); |
---|
356 | |
---|
357 | // transfer TXT ownership |
---|
358 | process_txt_transfer_ownership( owner_xp ); |
---|
359 | |
---|
360 | // block all threads in all clusters, but the main thread |
---|
361 | process_sigaction( owner_pid , BLOCK_ALL_THREADS ); |
---|
362 | |
---|
363 | // block the main thread |
---|
364 | xptr_t main_xp = XPTR( owner_cxy , &owner_ptr->th_tbl[0] ); |
---|
365 | thread_block( main_xp , THREAD_BLOCKED_GLOBAL ); |
---|
366 | |
---|
367 | // atomically update owner process termination state |
---|
368 | hal_remote_atomic_or( XPTR( owner_cxy , &owner_ptr->term_state ) , |
---|
369 | PROCESS_TERM_STOP ); |
---|
370 | |
---|
371 | // take the children lock and unblock the parent process main thread |
---|
372 | remote_spinlock_lock( children_lock_xp ); |
---|
373 | thread_unblock( parent_main_xp , THREAD_BLOCKED_WAIT ); |
---|
374 | remote_spinlock_unlock( children_lock_xp ); |
---|
375 | |
---|
376 | return; |
---|
377 | } |
---|
378 | } |
---|
379 | |
---|
380 | // filter special character ^C => kill TXT owner process |
---|
381 | if( byte == 0x03 ) |
---|
382 | { |
---|
383 | |
---|
384 | #if DEBUG_HAL_TXT_RX |
---|
385 | if( DEBUG_HAL_TXT_RX < rx_cycle ) |
---|
386 | printk("\n[DBG] %s : read ^C character from TXT%d\n", __FUNCTION__, channel ); |
---|
387 | #endif |
---|
388 | // get pointer on TXT owner process in owner cluster |
---|
389 | owner_xp = process_txt_get_owner( channel ); |
---|
390 | |
---|
391 | // check process exist |
---|
392 | assert( (owner_xp != XPTR_NULL) , __FUNCTION__, |
---|
393 | "TXT owner process not found\n" ); |
---|
394 | |
---|
395 | // get relevant infos on TXT owner process |
---|
396 | owner_cxy = GET_CXY( owner_xp ); |
---|
397 | owner_ptr = GET_PTR( owner_xp ); |
---|
398 | owner_pid = hal_remote_lw( XPTR( owner_cxy , &owner_ptr->pid ) ); |
---|
399 | |
---|
400 | // kill TXT owner process only if it is not the INIT process |
---|
401 | if( owner_pid != 1 ) |
---|
402 | { |
---|
403 | // get parent process descriptor pointers |
---|
404 | parent_xp = hal_remote_lwd( XPTR( owner_cxy , &owner_ptr->parent_xp ) ); |
---|
405 | parent_cxy = GET_CXY( parent_xp ); |
---|
406 | parent_ptr = GET_PTR( parent_xp ); |
---|
407 | |
---|
408 | // get extended pointer on lock protecting children list in parent process |
---|
409 | children_lock_xp = XPTR( parent_cxy , &parent_ptr->children_lock ); |
---|
410 | |
---|
411 | // get pointers on the parent process main thread |
---|
412 | parent_main_ptr = hal_remote_lpt(XPTR(parent_cxy,&parent_ptr->th_tbl[0])); |
---|
413 | parent_main_xp = XPTR( parent_cxy , parent_main_ptr ); |
---|
414 | |
---|
415 | // remove process from TXT list |
---|
416 | process_txt_detach( owner_xp ); |
---|
417 | |
---|
418 | // mark for delete all thread in all clusters, but the main |
---|
419 | process_sigaction( owner_pid , DELETE_ALL_THREADS ); |
---|
420 | |
---|
421 | // block main thread |
---|
422 | xptr_t main_xp = XPTR( owner_cxy , &owner_ptr->th_tbl[0] ); |
---|
423 | thread_block( main_xp , THREAD_BLOCKED_GLOBAL ); |
---|
424 | |
---|
425 | // atomically update owner process termination state |
---|
426 | hal_remote_atomic_or( XPTR( owner_cxy , &owner_ptr->term_state ) , |
---|
427 | PROCESS_TERM_KILL ); |
---|
428 | |
---|
429 | // take the children lock and unblock the parent process main thread |
---|
430 | remote_spinlock_lock( children_lock_xp ); |
---|
431 | thread_unblock( parent_main_xp , THREAD_BLOCKED_WAIT ); |
---|
432 | remote_spinlock_unlock( children_lock_xp ); |
---|
433 | |
---|
434 | return; |
---|
435 | } |
---|
436 | } |
---|
437 | |
---|
438 | // write byte in MTTY_RX FIFO if not full / discard byte if full |
---|
439 | if ( fifo->sts < MTTY_FIFO_DEPTH ) |
---|
440 | { |
---|
441 | |
---|
442 | #if DEBUG_HAL_TXT_RX |
---|
443 | if( DEBUG_HAL_TXT_RX < rx_cycle ) |
---|
444 | printk("\n[DBG] %s : put character <%c> to TXT%d_RX fifo\n", |
---|
445 | __FUNCTION__, byte, channel ); |
---|
446 | #endif |
---|
447 | // store byte into FIFO |
---|
448 | fifo->data[fifo->ptw] = (char)byte; |
---|
449 | |
---|
450 | // avoid race |
---|
451 | hal_fence(); |
---|
452 | |
---|
453 | // update RX_FIFO state |
---|
454 | fifo->ptw = (fifo->ptw + 1) % MTTY_FIFO_DEPTH; |
---|
455 | hal_atomic_add( &fifo->sts , 1 ); |
---|
456 | |
---|
457 | // unblock TXT_RX server thread |
---|
458 | thread_unblock( XPTR( local_cxy , server ) , THREAD_BLOCKED_ISR ); |
---|
459 | |
---|
460 | // send IPI to core running server thread |
---|
461 | dev_pic_send_ipi( local_cxy , server_lid ); |
---|
462 | } |
---|
463 | else |
---|
464 | { |
---|
465 | printk("\n[WARNING] %s : MTTY_RX_FIFO[%d] full => discard character <%x>\n", |
---|
466 | __FUNCTION__, channel, (uint32_t)byte ); |
---|
467 | } |
---|
468 | } // end while MTTY_READ register full |
---|
469 | |
---|
470 | } // end RX |
---|
471 | |
---|
472 | /////////////////////// handle TX ///////////////////////////// |
---|
473 | else |
---|
474 | { |
---|
475 | fifo = &mtty_tx_fifo[channel]; |
---|
476 | |
---|
477 | // try to move bytes until TX_FIFO empty |
---|
478 | while( fifo->sts > 0 ) |
---|
479 | { |
---|
480 | // write one byte to MTTY_WRITE register if empty / exit loop if full |
---|
481 | if( (hal_remote_lw( status_xp ) & MTTY_STATUS_TX_FULL) == 0 ) |
---|
482 | { |
---|
483 | // get one byte from TX_FIFO |
---|
484 | byte = fifo->data[fifo->ptr]; |
---|
485 | |
---|
486 | #if DEBUG_HAL_TXT_TX |
---|
487 | if( DEBUG_HAL_TXT_TX < tx_cycle ) |
---|
488 | printk("\n[DBG] %s : get character <%c> from TXT%d_TX fifo\n", |
---|
489 | __FUNCTION__, byte, channel ); |
---|
490 | #endif |
---|
491 | // update TX_FIFO state |
---|
492 | fifo->ptr = (fifo->ptr + 1) % MTTY_FIFO_DEPTH; |
---|
493 | hal_atomic_add( &fifo->sts , -1 ); |
---|
494 | |
---|
495 | // write byte to MTTY_WRITE register & acknowledge TX_IRQ |
---|
496 | hal_remote_sb( write_xp , byte ); |
---|
497 | } |
---|
498 | } |
---|
499 | |
---|
500 | // disable TX_IRQ |
---|
501 | // vci_multi_tty devices never raise TX IRQs |
---|
502 | // so the following instructions are useless |
---|
503 | // and moreover they kernel panic |
---|
504 | // xptr_t config_xp = XPTR( tty_cxy , base + MTTY_CONFIG ); |
---|
505 | // uint32_t old = hal_remote_lw( config_xp ); |
---|
506 | // uint32_t new = old & ~(MTTY_CONFIG_TX_ENABLE); |
---|
507 | // hal_remote_atomic_cas( config_xp , old , new ); |
---|
508 | // hal_remote_sw( XPTR( tty_cxy , base + MTTY_CONFIG ) , 0 ); |
---|
509 | |
---|
510 | // unblock TXT_TX server thread |
---|
511 | thread_unblock( XPTR( local_cxy , server ) , THREAD_BLOCKED_ISR ); |
---|
512 | |
---|
513 | // send IPI to core running server thread |
---|
514 | dev_pic_send_ipi( local_cxy , server_lid ); |
---|
515 | |
---|
516 | } // end TX |
---|
517 | |
---|
518 | hal_fence(); |
---|
519 | |
---|
520 | #if (DEBUG_SYS_READ & 1) |
---|
521 | if( is_rx ) exit_tty_isr_read = (uint32_t)hal_get_cycles(); |
---|
522 | #endif |
---|
523 | |
---|
524 | #if (DEBUG_SYS_WRITE & 1) |
---|
525 | if( is_rx == 0 ) exit_tty_isr_write = (uint32_t)hal_get_cycles(); |
---|
526 | #endif |
---|
527 | |
---|
528 | } // end soclib_mtty_isr() |
---|
529 | |
---|
530 | ///////////////////////////////////////////////////////////// |
---|
531 | void __attribute__ ((noinline)) soclib_mtty_aux( void * args ) |
---|
532 | { |
---|
533 | uint32_t status; |
---|
534 | bool_t empty; |
---|
535 | uint32_t i; |
---|
536 | |
---|
537 | xptr_t dev_xp = ((txt_sync_args_t *)args)->dev_xp; |
---|
538 | char * buffer = ((txt_sync_args_t *)args)->buffer; |
---|
539 | uint32_t count = ((txt_sync_args_t *)args)->count; |
---|
540 | |
---|
541 | // get TXT0 chdev cluster and local pointer |
---|
542 | cxy_t dev_cxy = GET_CXY( dev_xp ); |
---|
543 | chdev_t * dev_ptr = (chdev_t *)GET_PTR( dev_xp ); |
---|
544 | |
---|
545 | // get extended pointer on TTY channel base address |
---|
546 | xptr_t tty_xp = (xptr_t)hal_remote_lwd( XPTR( dev_cxy , &dev_ptr->base ) ); |
---|
547 | |
---|
548 | // get TTY channel segment cluster and local pointer |
---|
549 | cxy_t tty_cxy = GET_CXY( tty_xp ); |
---|
550 | uint32_t * tty_ptr = (uint32_t *)GET_PTR( tty_xp ); |
---|
551 | |
---|
552 | // get extended pointers on MTTY_WRITE & MTTY_STATUS registers |
---|
553 | xptr_t write_xp = XPTR( tty_cxy , tty_ptr + MTTY_WRITE ); |
---|
554 | xptr_t status_xp = XPTR( tty_cxy , tty_ptr + MTTY_STATUS ); |
---|
555 | |
---|
556 | // loop on characters (busy waiting policy) |
---|
557 | for( i = 0 ; i < count ; i++ ) |
---|
558 | { |
---|
559 | do |
---|
560 | { |
---|
561 | // get MTTY_STATUS |
---|
562 | status = hal_remote_lw( status_xp ); |
---|
563 | empty = ( (status & MTTY_STATUS_TX_FULL) == 0 ); |
---|
564 | |
---|
565 | // transfer one byte if TX buffer empty |
---|
566 | if ( empty ) hal_remote_sb( write_xp , buffer[i] ); |
---|
567 | } |
---|
568 | while ( empty == false ); |
---|
569 | } |
---|
570 | } // end soclib_mtty_aux() |
---|
571 | |
---|
572 | |
---|
573 | |
---|