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