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