1 | /* |
---|
2 | * chdev.c - channel device descriptor operations implementation. |
---|
3 | * |
---|
4 | * Authors Alain Greiner (2016) |
---|
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 | #include <kernel_config.h> |
---|
25 | #include <hal_kernel_types.h> |
---|
26 | #include <hal_special.h> |
---|
27 | #include <hal_remote.h> |
---|
28 | #include <hal_irqmask.h> |
---|
29 | #include <printk.h> |
---|
30 | #include <boot_info.h> |
---|
31 | #include <xlist.h> |
---|
32 | #include <kmem.h> |
---|
33 | #include <scheduler.h> |
---|
34 | #include <thread.h> |
---|
35 | #include <rpc.h> |
---|
36 | #include <chdev.h> |
---|
37 | #include <devfs.h> |
---|
38 | |
---|
39 | |
---|
40 | extern chdev_directory_t chdev_dir; // allocated in kernel_init.c |
---|
41 | |
---|
42 | #if (DEBUG_SYS_READ & 1) |
---|
43 | extern uint32_t enter_chdev_cmd_read; |
---|
44 | extern uint32_t exit_chdev_cmd_read; |
---|
45 | extern uint32_t enter_chdev_server_read; |
---|
46 | extern uint32_t exit_chdev_server_read; |
---|
47 | #endif |
---|
48 | |
---|
49 | #if (DEBUG_SYS_WRITE & 1) |
---|
50 | extern uint32_t enter_chdev_cmd_write; |
---|
51 | extern uint32_t exit_chdev_cmd_write; |
---|
52 | extern uint32_t enter_chdev_server_write; |
---|
53 | extern uint32_t exit_chdev_server_write; |
---|
54 | #endif |
---|
55 | |
---|
56 | //////////////////////////////////////////// |
---|
57 | char * chdev_func_str( uint32_t func_type ) |
---|
58 | { |
---|
59 | switch ( func_type ) { |
---|
60 | case DEV_FUNC_RAM: return "RAM"; |
---|
61 | case DEV_FUNC_ROM: return "ROM"; |
---|
62 | case DEV_FUNC_FBF: return "FBF"; |
---|
63 | case DEV_FUNC_IOB: return "IOB"; |
---|
64 | case DEV_FUNC_IOC: return "IOC"; |
---|
65 | case DEV_FUNC_MMC: return "MMC"; |
---|
66 | case DEV_FUNC_DMA: return "DMA"; |
---|
67 | case DEV_FUNC_NIC: return "NIC"; |
---|
68 | case DEV_FUNC_TIM: return "TIM"; |
---|
69 | case DEV_FUNC_TXT: return "TXT"; |
---|
70 | case DEV_FUNC_ICU: return "ICU"; |
---|
71 | case DEV_FUNC_PIC: return "PIC"; |
---|
72 | default: return "undefined"; |
---|
73 | } |
---|
74 | } |
---|
75 | |
---|
76 | ///////////////////////////////////////// |
---|
77 | chdev_t * chdev_create( uint32_t func, |
---|
78 | uint32_t impl, |
---|
79 | uint32_t channel, |
---|
80 | uint32_t is_rx, |
---|
81 | xptr_t base ) |
---|
82 | { |
---|
83 | chdev_t * chdev; |
---|
84 | kmem_req_t req; |
---|
85 | |
---|
86 | // allocate memory for chdev |
---|
87 | req.type = KMEM_DEVICE; |
---|
88 | req.flags = AF_ZERO; |
---|
89 | chdev = (chdev_t *)kmem_alloc( &req ); |
---|
90 | |
---|
91 | if( chdev == NULL ) return NULL; |
---|
92 | |
---|
93 | // initialize waiting threads queue and associated lock |
---|
94 | remote_spinlock_init( XPTR( local_cxy , &chdev->wait_lock ) ); |
---|
95 | xlist_root_init( XPTR( local_cxy , &chdev->wait_root ) ); |
---|
96 | |
---|
97 | // initialize attributes |
---|
98 | chdev->func = func; |
---|
99 | chdev->impl = impl; |
---|
100 | chdev->channel = channel; |
---|
101 | chdev->is_rx = is_rx; |
---|
102 | chdev->base = base; |
---|
103 | |
---|
104 | return chdev; |
---|
105 | |
---|
106 | } // end chdev_create() |
---|
107 | |
---|
108 | /////////////////////////////////// |
---|
109 | void chdev_print( chdev_t * chdev ) |
---|
110 | { |
---|
111 | printk("\n - func = %s" |
---|
112 | "\n - channel = %d" |
---|
113 | "\n - base = %l" |
---|
114 | "\n - cmd = %x" |
---|
115 | "\n - isr = %x" |
---|
116 | "\n - chdev = %x\n", |
---|
117 | chdev_func_str(chdev->func), |
---|
118 | chdev->channel, |
---|
119 | chdev->base, |
---|
120 | chdev->cmd, |
---|
121 | chdev->isr, |
---|
122 | chdev ); |
---|
123 | } |
---|
124 | |
---|
125 | ////////////////////////////////////////////////// |
---|
126 | void chdev_register_command( xptr_t chdev_xp ) |
---|
127 | { |
---|
128 | thread_t * server_ptr; // local pointer on server thread associated to chdev |
---|
129 | xptr_t server_xp; // extended pointer on server thread |
---|
130 | core_t * core_ptr; // local pointer on core running the server thread |
---|
131 | uint32_t server_lid; // core running the server thread local index |
---|
132 | xptr_t lock_xp; // extended pointer on lock protecting the chdev queue |
---|
133 | uint32_t save_sr; // for critical section |
---|
134 | |
---|
135 | #if (DEBUG_SYS_READ & 1) |
---|
136 | enter_chdev_cmd_read = (uint32_t)hal_get_cycles(); |
---|
137 | #endif |
---|
138 | |
---|
139 | #if (DEBUG_SYS_WRITE & 1) |
---|
140 | enter_chdev_cmd_write = (uint32_t)hal_get_cycles(); |
---|
141 | #endif |
---|
142 | |
---|
143 | thread_t * this = CURRENT_THREAD; |
---|
144 | |
---|
145 | // get chdev cluster and local pointer |
---|
146 | cxy_t chdev_cxy = GET_CXY( chdev_xp ); |
---|
147 | chdev_t * chdev_ptr = GET_PTR( chdev_xp ); |
---|
148 | |
---|
149 | // get local and extended pointers on server thread |
---|
150 | server_ptr = (thread_t *)hal_remote_lpt( XPTR( chdev_cxy , &chdev_ptr->server) ); |
---|
151 | server_xp = XPTR( chdev_cxy , server_ptr ); |
---|
152 | |
---|
153 | // get local pointer on core running the server thread |
---|
154 | core_ptr = (core_t *)hal_remote_lpt( XPTR( chdev_cxy , &server_ptr->core ) ); |
---|
155 | |
---|
156 | // get server core local index |
---|
157 | server_lid = hal_remote_lw( XPTR( chdev_cxy , &core_ptr->lid ) ); |
---|
158 | |
---|
159 | #if (DEBUG_CHDEV_CMD_RX || DEBUG_CHDEV_CMD_TX) |
---|
160 | bool_t is_rx = hal_remote_lw( XPTR( chdev_cxy , &chdev_ptr->is_rx ) ); |
---|
161 | #endif |
---|
162 | |
---|
163 | #if DEBUG_CHDEV_CMD_RX |
---|
164 | uint32_t rx_cycle = (uint32_t)hal_get_cycles(); |
---|
165 | if( (is_rx) && (DEBUG_CHDEV_CMD_RX < rx_cycle) ) |
---|
166 | printk("\n[DBG] %s : client_thread %x (%s) enter for RX / server = %x / cycle %d\n", |
---|
167 | __FUNCTION__, this, thread_type_str(this->type) , server_ptr, rx_cycle ); |
---|
168 | #endif |
---|
169 | |
---|
170 | #if DEBUG_CHDEV_CMD_TX |
---|
171 | uint32_t tx_cycle = (uint32_t)hal_get_cycles(); |
---|
172 | if( (is_rx == 0) && (DEBUG_CHDEV_CMD_TX < tx_cycle) ) |
---|
173 | printk("\n[DBG] %s : client_thread %x (%s) enter for TX / server = %x / cycle %d\n", |
---|
174 | __FUNCTION__, this, thread_type_str(this->type) , server_ptr, tx_cycle ); |
---|
175 | #endif |
---|
176 | |
---|
177 | // build extended pointer on client thread xlist |
---|
178 | xptr_t list_xp = XPTR( local_cxy , &this->wait_list ); |
---|
179 | |
---|
180 | // build extended pointer on chdev waiting queue root |
---|
181 | xptr_t root_xp = XPTR( chdev_cxy , &chdev_ptr->wait_root ); |
---|
182 | |
---|
183 | // build extended pointer on server thread blocked state |
---|
184 | xptr_t blocked_xp = XPTR( chdev_cxy , &server_ptr->blocked ); |
---|
185 | |
---|
186 | // build extended pointer on lock protecting chdev waiting queue |
---|
187 | lock_xp = XPTR( chdev_cxy , &chdev_ptr->wait_lock ); |
---|
188 | |
---|
189 | // critical section for the following sequence: |
---|
190 | // (1) take the lock protecting waiting queue |
---|
191 | // (2) block the client thread |
---|
192 | // (3) unblock the server thread if required |
---|
193 | // (4) register client thread in server queue |
---|
194 | // (5) send IPI to force server scheduling |
---|
195 | // (6) release the lock protecting waiting queue |
---|
196 | // (7) deschedule |
---|
197 | // ... in this order |
---|
198 | |
---|
199 | // enter critical section |
---|
200 | hal_disable_irq( &save_sr ); |
---|
201 | |
---|
202 | // take the lock protecting chdev waiting queue |
---|
203 | remote_spinlock_lock( lock_xp ); |
---|
204 | |
---|
205 | // block current thread |
---|
206 | thread_block( XPTR( local_cxy , CURRENT_THREAD ) , THREAD_BLOCKED_IO ); |
---|
207 | |
---|
208 | #if (DEBUG_CHDEV_CMD_TX & 1) |
---|
209 | if( (is_rx == 0) && (DEBUG_CHDEV_CMD_TX < tx_cycle) ) |
---|
210 | printk("\n[DBG] in %s : client thread %x blocked\n", __FUNCTION__, this ); |
---|
211 | #endif |
---|
212 | |
---|
213 | #if (DEBUG_CHDEV_CMD_RX & 1) |
---|
214 | if( (is_rx) && (DEBUG_CHDEV_CMD_RX < rx_cycle) ) |
---|
215 | printk("\n[DBG] in %s : client thread %x blocked\n", __FUNCTION__, this ); |
---|
216 | #endif |
---|
217 | |
---|
218 | // unblock server thread if required |
---|
219 | if( hal_remote_lw( blocked_xp ) & THREAD_BLOCKED_IDLE ) |
---|
220 | thread_unblock( server_xp , THREAD_BLOCKED_IDLE ); |
---|
221 | |
---|
222 | #if (DEBUG_CHDEV_CMD_TX & 1) |
---|
223 | if( (is_rx == 0) && (DEBUG_CHDEV_CMD_TX < tx_cycle) ) |
---|
224 | printk("\n[DBG] in %s : TX server thread %x unblocked\n", __FUNCTION__, server_ptr ); |
---|
225 | #endif |
---|
226 | |
---|
227 | #if (DEBUG_CHDEV_CMD_RX & 1) |
---|
228 | if( (is_rx) && (DEBUG_CHDEV_CMD_RX < rx_cycle) ) |
---|
229 | printk("\n[DBG] in %s : RX server thread %x unblocked\n", __FUNCTION__, server_ptr ); |
---|
230 | #endif |
---|
231 | |
---|
232 | // register client thread in waiting queue |
---|
233 | xlist_add_last( root_xp , list_xp ); |
---|
234 | |
---|
235 | #if (DEBUG_CHDEV_CMD_TX & 1) |
---|
236 | if( (is_rx == 0) && (DEBUG_CHDEV_CMD_TX < tx_cycle) ) |
---|
237 | printk("\n[DBG] in %s : thread %x registered write request in chdev\n", __FUNCTION__, this ); |
---|
238 | #endif |
---|
239 | |
---|
240 | #if (DEBUG_CHDEV_CMD_RX & 1) |
---|
241 | if( (is_rx) && (DEBUG_CHDEV_CMD_RX < rx_cycle) ) |
---|
242 | printk("\n[DBG] in %s : thread %x registered read request in chdev\n", __FUNCTION__, this ); |
---|
243 | #endif |
---|
244 | |
---|
245 | // send IPI to core running the server thread when server != client |
---|
246 | if( (server_lid != this->core->lid) || (local_cxy != chdev_cxy) ) |
---|
247 | { |
---|
248 | dev_pic_send_ipi( chdev_cxy , server_lid ); |
---|
249 | |
---|
250 | #if (DEBUG_CHDEV_CMD_TX & 1) |
---|
251 | if( (is_rx == 0) && (DEBUG_CHDEV_CMD_TX < tx_cycle) ) |
---|
252 | printk("\n[DBG] in %s : client thread %x sent IPI to TX server thread %x\n", |
---|
253 | __FUNCTION__, this, server_ptr ); |
---|
254 | #endif |
---|
255 | |
---|
256 | #if (DEBUG_CHDEV_CMD_RX & 1) |
---|
257 | if( (is_rx) && (DEBUG_CHDEV_CMD_RX < rx_cycle) ) |
---|
258 | printk("\n[DBG] in %s : client thread %x sent IPI to RX server thread %x\n", |
---|
259 | __FUNCTION__, this, server_ptr ); |
---|
260 | #endif |
---|
261 | |
---|
262 | } |
---|
263 | |
---|
264 | // release lock |
---|
265 | remote_spinlock_unlock( lock_xp ); |
---|
266 | |
---|
267 | // deschedule |
---|
268 | assert( thread_can_yield() , "illegal sched_yield\n" ); |
---|
269 | sched_yield("blocked on I/O"); |
---|
270 | |
---|
271 | // exit critical section |
---|
272 | hal_restore_irq( save_sr ); |
---|
273 | |
---|
274 | #if DEBUG_CHDEV_CMD_RX |
---|
275 | rx_cycle = (uint32_t)hal_get_cycles(); |
---|
276 | if( (is_rx) && (DEBUG_CHDEV_CMD_RX < rx_cycle) ) |
---|
277 | printk("\n[DBG] %s : client_thread %x (%s) exit for RX / cycle %d\n", |
---|
278 | __FUNCTION__, this, thread_type_str(this->type) , rx_cycle ); |
---|
279 | #endif |
---|
280 | |
---|
281 | #if DEBUG_CHDEV_CMD_TX |
---|
282 | tx_cycle = (uint32_t)hal_get_cycles(); |
---|
283 | if( (is_rx == 0) && (DEBUG_CHDEV_CMD_TX < tx_cycle) ) |
---|
284 | printk("\n[DBG] %s : client_thread %x (%s) exit for TX / cycle %d\n", |
---|
285 | __FUNCTION__, this, thread_type_str(this->type) , tx_cycle ); |
---|
286 | #endif |
---|
287 | |
---|
288 | #if (DEBUG_SYS_READ & 1) |
---|
289 | exit_chdev_cmd_read = (uint32_t)hal_get_cycles(); |
---|
290 | #endif |
---|
291 | |
---|
292 | #if (DEBUG_SYS_WRITE & 1) |
---|
293 | exit_chdev_cmd_write = (uint32_t)hal_get_cycles(); |
---|
294 | #endif |
---|
295 | |
---|
296 | } // end chdev_register_command() |
---|
297 | |
---|
298 | /////////////////////////////////////////////// |
---|
299 | void chdev_sequencial_server( chdev_t * chdev ) |
---|
300 | { |
---|
301 | xptr_t client_xp; // extended pointer on waiting thread |
---|
302 | cxy_t client_cxy; // cluster of client thread |
---|
303 | thread_t * client_ptr; // local pointer on client thread |
---|
304 | thread_t * server; // local pointer on server thread |
---|
305 | xptr_t root_xp; // extended pointer on device waiting queue root |
---|
306 | xptr_t lock_xp; // extended pointer on lock ptotecting chdev queue |
---|
307 | |
---|
308 | server = CURRENT_THREAD; |
---|
309 | |
---|
310 | // get root and lock on command queue |
---|
311 | root_xp = XPTR( local_cxy , &chdev->wait_root ); |
---|
312 | lock_xp = XPTR( local_cxy , &chdev->wait_lock ); |
---|
313 | |
---|
314 | // This infinite loop is executed by the DEV thread |
---|
315 | // to handle commands registered in the chdev queue. |
---|
316 | while( 1 ) |
---|
317 | { |
---|
318 | // get the lock protecting the waiting queue |
---|
319 | remote_spinlock_lock( lock_xp ); |
---|
320 | |
---|
321 | // check waiting queue state |
---|
322 | if( xlist_is_empty( root_xp ) ) // waiting queue empty |
---|
323 | { |
---|
324 | // release lock |
---|
325 | remote_spinlock_unlock( lock_xp ); |
---|
326 | |
---|
327 | // block |
---|
328 | thread_block( XPTR( local_cxy , server ) , THREAD_BLOCKED_IDLE ); |
---|
329 | |
---|
330 | // deschedule |
---|
331 | assert( thread_can_yield() , "illegal sched_yield\n" ); |
---|
332 | sched_yield("I/O queue empty"); |
---|
333 | } |
---|
334 | else // waiting queue not empty |
---|
335 | { |
---|
336 | // get extended pointer on first client thread |
---|
337 | client_xp = XLIST_FIRST_ELEMENT( root_xp , thread_t , wait_list ); |
---|
338 | |
---|
339 | // get client thread cluster and local pointer |
---|
340 | client_cxy = GET_CXY( client_xp ); |
---|
341 | client_ptr = GET_PTR( client_xp ); |
---|
342 | |
---|
343 | // remove this first client thread from waiting queue |
---|
344 | xlist_unlink( XPTR( client_cxy , &client_ptr->wait_list ) ); |
---|
345 | |
---|
346 | // release lock |
---|
347 | remote_spinlock_unlock( lock_xp ); |
---|
348 | |
---|
349 | #if DEBUG_CHDEV_SERVER_RX |
---|
350 | uint32_t rx_cycle = (uint32_t)hal_get_cycles(); |
---|
351 | if( (chdev->is_rx) && (DEBUG_CHDEV_SERVER_RX < rx_cycle) ) |
---|
352 | printk("\n[DBG] %s : server_thread %x start RX / client %x / cycle %d\n", |
---|
353 | __FUNCTION__ , server , client_ptr , rx_cycle ); |
---|
354 | #endif |
---|
355 | |
---|
356 | #if DEBUG_CHDEV_SERVER_TX |
---|
357 | uint32_t tx_cycle = (uint32_t)hal_get_cycles(); |
---|
358 | if( (chdev->is_rx == 0) && (DEBUG_CHDEV_SERVER_TX < tx_cycle) ) |
---|
359 | printk("\n[DBG] %s : server_thread %x start TX / client %x / cycle %d\n", |
---|
360 | __FUNCTION__ , server , client_ptr , tx_cycle ); |
---|
361 | #endif |
---|
362 | |
---|
363 | #if (DEBUG_SYS_READ & 1) |
---|
364 | enter_chdev_server_read = (uint32_t)hal_get_cycles(); |
---|
365 | #endif |
---|
366 | |
---|
367 | #if (DEBUG_SYS_WRITE & 1) |
---|
368 | enter_chdev_server_write = (uint32_t)hal_get_cycles(); |
---|
369 | #endif |
---|
370 | |
---|
371 | // call driver command function to execute I/O operation |
---|
372 | chdev->cmd( client_xp ); |
---|
373 | |
---|
374 | // unblock client thread |
---|
375 | thread_unblock( client_xp , THREAD_BLOCKED_IO ); |
---|
376 | |
---|
377 | #if DEBUG_CHDEV_SERVER_RX |
---|
378 | rx_cycle = (uint32_t)hal_get_cycles(); |
---|
379 | if( (chdev->is_rx) && (DEBUG_CHDEV_SERVER_RX < rx_cycle) ) |
---|
380 | printk("\n[DBG] %s : server_thread %x completes RX / client %x / cycle %d\n", |
---|
381 | __FUNCTION__ , server , client_ptr , rx_cycle ); |
---|
382 | #endif |
---|
383 | |
---|
384 | #if DEBUG_CHDEV_SERVER_TX |
---|
385 | tx_cycle = (uint32_t)hal_get_cycles(); |
---|
386 | if( (chdev->is_rx == 0) && (DEBUG_CHDEV_SERVER_TX < tx_cycle) ) |
---|
387 | printk("\n[DBG] %s : server_thread %x completes TX / client %x / cycle %d\n", |
---|
388 | __FUNCTION__ , server , client_ptr , tx_cycle ); |
---|
389 | #endif |
---|
390 | |
---|
391 | #if (DEBUG_SYS_READ & 1) |
---|
392 | exit_chdev_server_read = (uint32_t)hal_get_cycles(); |
---|
393 | #endif |
---|
394 | |
---|
395 | #if (DEBUG_SYS_WRITE & 1) |
---|
396 | exit_chdev_server_write = (uint32_t)hal_get_cycles(); |
---|
397 | #endif |
---|
398 | |
---|
399 | } |
---|
400 | } // end while |
---|
401 | } // end chdev_sequencial_server() |
---|
402 | |
---|
403 | //////////////////////////////////////// |
---|
404 | xptr_t chdev_from_file( xptr_t file_xp ) |
---|
405 | { |
---|
406 | cxy_t file_cxy; |
---|
407 | vfs_file_t * file_ptr; |
---|
408 | uint32_t inode_type; |
---|
409 | vfs_inode_t * inode_ptr; |
---|
410 | chdev_t * chdev_ptr; |
---|
411 | |
---|
412 | assert( (file_xp != XPTR_NULL) , |
---|
413 | "file_xp == XPTR_NULL\n" ); |
---|
414 | |
---|
415 | // get cluster and local pointer on remote file descriptor |
---|
416 | // associated inode and chdev are stored in same cluster as the file desc. |
---|
417 | file_cxy = GET_CXY( file_xp ); |
---|
418 | file_ptr = (vfs_file_t *)GET_PTR( file_xp ); |
---|
419 | |
---|
420 | // get inode type from file descriptor |
---|
421 | inode_type = hal_remote_lw( XPTR( file_cxy , &file_ptr->type ) ); |
---|
422 | inode_ptr = (vfs_inode_t *)hal_remote_lpt( XPTR( file_cxy , &file_ptr->inode ) ); |
---|
423 | |
---|
424 | assert( (inode_type == INODE_TYPE_DEV) , |
---|
425 | "inode type %d is not INODE_TYPE_DEV\n", inode_type ); |
---|
426 | |
---|
427 | // get chdev local pointer from inode extension |
---|
428 | chdev_ptr = (chdev_t *)hal_remote_lpt( XPTR( file_cxy , &inode_ptr->extend ) ); |
---|
429 | |
---|
430 | return XPTR( file_cxy , chdev_ptr ); |
---|
431 | |
---|
432 | } // end chdev_from_file() |
---|
433 | |
---|
434 | //////////////////////// |
---|
435 | void chdev_dir_display( void ) |
---|
436 | { |
---|
437 | uint32_t i; |
---|
438 | cxy_t cxy; |
---|
439 | chdev_t * ptr; |
---|
440 | uint32_t base; |
---|
441 | reg_t save_sr; |
---|
442 | |
---|
443 | // get pointers on TXT0 chdev |
---|
444 | xptr_t txt0_xp = chdev_dir.txt_tx[0]; |
---|
445 | cxy_t txt0_cxy = GET_CXY( txt0_xp ); |
---|
446 | chdev_t * txt0_ptr = GET_PTR( txt0_xp ); |
---|
447 | |
---|
448 | // get extended pointer on remote TXT0 chdev lock |
---|
449 | xptr_t lock_xp = XPTR( txt0_cxy , &txt0_ptr->wait_lock ); |
---|
450 | |
---|
451 | // get TXT0 lock in busy waiting mode |
---|
452 | remote_spinlock_lock_busy( lock_xp , &save_sr ); |
---|
453 | |
---|
454 | // header |
---|
455 | nolock_printk("\n***** external chdevs directory *****\n"); |
---|
456 | |
---|
457 | // IOB |
---|
458 | cxy = GET_CXY( chdev_dir.iob ); |
---|
459 | ptr = GET_PTR( chdev_dir.iob ); |
---|
460 | base = (uint32_t)hal_remote_lwd( XPTR( cxy , &ptr->base ) ); |
---|
461 | nolock_printk(" - iob : cxy = %X / ptr = %X / base = %X\n", cxy, ptr, base); |
---|
462 | |
---|
463 | // PIC |
---|
464 | cxy = GET_CXY( chdev_dir.pic ); |
---|
465 | ptr = GET_PTR( chdev_dir.pic ); |
---|
466 | base = (uint32_t)hal_remote_lwd( XPTR( cxy , &ptr->base ) ); |
---|
467 | nolock_printk(" - pic : cxy = %X / ptr = %X / base = %X\n", cxy, ptr, base); |
---|
468 | |
---|
469 | // TXT |
---|
470 | for( i = 0 ; i < LOCAL_CLUSTER->nb_txt_channels ; i++ ) |
---|
471 | { |
---|
472 | cxy = GET_CXY( chdev_dir.txt_rx[i] ); |
---|
473 | ptr = GET_PTR( chdev_dir.txt_rx[i] ); |
---|
474 | base = (uint32_t)hal_remote_lwd( XPTR( cxy , &ptr->base ) ); |
---|
475 | nolock_printk(" - txt_rx[%d] : cxy = %X / ptr = %X / base = %X\n", i, cxy, ptr, base); |
---|
476 | |
---|
477 | cxy = GET_CXY( chdev_dir.txt_tx[i] ); |
---|
478 | ptr = GET_PTR( chdev_dir.txt_tx[i] ); |
---|
479 | base = (uint32_t)hal_remote_lwd( XPTR( cxy , &ptr->base ) ); |
---|
480 | nolock_printk(" - txt_tx[%d] : cxy = %X / ptr = %X / base = %X\n", i, cxy, ptr, base); |
---|
481 | } |
---|
482 | |
---|
483 | // IOC |
---|
484 | for( i = 0 ; i < LOCAL_CLUSTER->nb_ioc_channels ; i++ ) |
---|
485 | { |
---|
486 | cxy = GET_CXY( chdev_dir.ioc[i] ); |
---|
487 | ptr = GET_PTR( chdev_dir.ioc[i] ); |
---|
488 | base = (uint32_t)hal_remote_lwd( XPTR( cxy , &ptr->base ) ); |
---|
489 | nolock_printk(" - ioc[%d] : cxy = %X / ptr = %X / base = %X\n", i, cxy, ptr, base); |
---|
490 | } |
---|
491 | |
---|
492 | // FBF |
---|
493 | for( i = 0 ; i < LOCAL_CLUSTER->nb_fbf_channels ; i++ ) |
---|
494 | { |
---|
495 | cxy = GET_CXY( chdev_dir.fbf[i] ); |
---|
496 | ptr = GET_PTR( chdev_dir.fbf[i] ); |
---|
497 | base = (uint32_t)hal_remote_lwd( XPTR( cxy , &ptr->base ) ); |
---|
498 | nolock_printk(" - fbf[%d] : cxy = %X / ptr = %X / base = %X\n", i, cxy, ptr, base); |
---|
499 | } |
---|
500 | |
---|
501 | // NIC |
---|
502 | for( i = 0 ; i < LOCAL_CLUSTER->nb_nic_channels ; i++ ) |
---|
503 | { |
---|
504 | cxy = GET_CXY( chdev_dir.nic_rx[i] ); |
---|
505 | ptr = GET_PTR( chdev_dir.nic_rx[i] ); |
---|
506 | base = (uint32_t)hal_remote_lwd( XPTR( cxy , &ptr->base ) ); |
---|
507 | nolock_printk(" - nic_rx[%d] : cxy = %X / ptr = %X / base = %X\n", i, cxy, ptr, base); |
---|
508 | |
---|
509 | cxy = GET_CXY( chdev_dir.nic_tx[i] ); |
---|
510 | ptr = GET_PTR( chdev_dir.nic_tx[i] ); |
---|
511 | base = (uint32_t)hal_remote_lwd( XPTR( cxy , &ptr->base ) ); |
---|
512 | nolock_printk(" - nic_tx[%d] : cxy = %X / ptr = %X / base = %X\n", i, cxy, ptr, base); |
---|
513 | } |
---|
514 | |
---|
515 | // release lock |
---|
516 | remote_spinlock_unlock_busy( lock_xp , save_sr ); |
---|
517 | |
---|
518 | } // end chdev_dir_display() |
---|
519 | |
---|
520 | /////////////////////////////////////////// |
---|
521 | void chdev_queue_display( xptr_t chdev_xp ) |
---|
522 | { |
---|
523 | cxy_t chdev_cxy; // chdev cluster |
---|
524 | chdev_t * chdev_ptr; // chdev local pointer |
---|
525 | xptr_t root_xp; // extended pointer on waiting queuue root |
---|
526 | char name[16]; // local copie of chdev name |
---|
527 | xptr_t iter_xp; // extended pointer on xlist_t field in waiting thread |
---|
528 | xptr_t thread_xp; // extended pointer on thread registered in queue |
---|
529 | cxy_t thread_cxy; // cluster identifier for waiting thread |
---|
530 | thread_t * thread_ptr; // local pointer on waiting thread |
---|
531 | trdid_t trdid; // waiting thread identifier |
---|
532 | process_t * process; // waiting thread process descriptor |
---|
533 | pid_t pid; // waiting thread process identifier |
---|
534 | |
---|
535 | // get cluster and local pointer on chdev |
---|
536 | chdev_cxy = GET_CXY( chdev_xp ); |
---|
537 | chdev_ptr = GET_PTR( chdev_xp ); |
---|
538 | |
---|
539 | // get extended pointer on root of requests queue |
---|
540 | root_xp = XPTR( chdev_cxy , &chdev_ptr->wait_root ); |
---|
541 | |
---|
542 | // get chdev name |
---|
543 | hal_remote_strcpy( XPTR( local_cxy , name ), XPTR( chdev_cxy , chdev_ptr->name ) ); |
---|
544 | |
---|
545 | // check queue empty |
---|
546 | if( xlist_is_empty( root_xp ) ) |
---|
547 | { |
---|
548 | printk("\n***** Waiting queue empty for chdev %s\n", name ); |
---|
549 | } |
---|
550 | else |
---|
551 | { |
---|
552 | printk("\n***** Waiting queue for chdev %s\n", name ); |
---|
553 | |
---|
554 | // scan the waiting queue |
---|
555 | XLIST_FOREACH( root_xp , iter_xp ) |
---|
556 | { |
---|
557 | thread_xp = XLIST_ELEMENT( iter_xp , thread_t , wait_list ); |
---|
558 | thread_cxy = GET_CXY( thread_xp ); |
---|
559 | thread_ptr = GET_PTR( thread_xp ); |
---|
560 | trdid = hal_remote_lw ( XPTR( thread_cxy , &thread_ptr->trdid ) ); |
---|
561 | process = hal_remote_lpt( XPTR( thread_cxy , &thread_ptr->process ) ); |
---|
562 | pid = hal_remote_lw ( XPTR( thread_cxy , &process->pid ) ); |
---|
563 | |
---|
564 | printk("- thread %X / cluster %X / trdid %X / pid %X\n", |
---|
565 | thread_ptr, thread_cxy, trdid, pid ); |
---|
566 | } |
---|
567 | } |
---|
568 | } // end chdev_queue_display() |
---|
569 | |
---|