Changeset 407 for trunk/kernel/fs/devfs.c
- Timestamp:
- Nov 7, 2017, 3:08:12 PM (6 years ago)
- Location:
- trunk/kernel/fs
- Files:
-
- 1 copied
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/fs/devfs.c
r406 r407 25 25 #include <hal_types.h> 26 26 #include <hal_special.h> 27 #include <hal_uspace.h> 27 28 #include <printk.h> 28 29 #include <chdev.h> 30 #include <dev_txt.h> 29 31 #include <cluster.h> 30 32 #include <vfs.h> … … 39 41 extern chdev_directory_t chdev_dir; // allocated in kernel_init.c 40 42 43 #if CONFIG_READ_DEBUG 44 extern uint32_t enter_devfs_move; 45 extern uint32_t exit_devfs_move; 46 #endif 47 41 48 /////////////////////////////// 42 49 devfs_ctx_t * devfs_ctx_alloc() … … 79 86 error_t error; 80 87 81 devfs_dmsg("\n[D MSG] %s : enter in cluster %x\n",88 devfs_dmsg("\n[DBG] %s : enter in cluster %x\n", 82 89 __FUNCTION__ , local_cxy ); 83 90 … … 93 100 assert( (error == 0) , __FUNCTION__ , "cannot create <dev>\n" ); 94 101 95 devfs_dmsg("\n[D MSG] %s : <dev> created in cluster %x\n",102 devfs_dmsg("\n[DBG] %s : <dev> created in cluster %x\n", 96 103 __FUNCTION__ , local_cxy ); 97 104 … … 107 114 assert( (error == 0) , __FUNCTION__ , "cannot create <external>\n" ); 108 115 109 devfs_dmsg("\n[D MSG] %s : <external> created in cluster %x\n",116 devfs_dmsg("\n[DBG] %s : <external> created in cluster %x\n", 110 117 __FUNCTION__ , local_cxy ); 111 118 } … … 119 126 xptr_t chdev_xp; 120 127 cxy_t chdev_cxy; 128 chdev_t * chdev_ptr; 121 129 xptr_t inode_xp; 122 130 uint32_t channel; … … 132 140 devfs_internal_inode_xp ); 133 141 142 devfs_dmsg("\n[DBG] %s : created <%s> inode in cluster %x\n", 143 __FUNCTION__ , node_name , local_cxy ); 144 134 145 // create MMC chdev inode 135 chdev_xp = chdev_dir.mmc[local_cxy];146 chdev_xp = chdev_dir.mmc[local_cxy]; 136 147 if( chdev_xp != XPTR_NULL) 137 148 { 149 chdev_ptr = (chdev_t *)GET_PTR( chdev_xp ); 138 150 vfs_add_child_in_parent( local_cxy, 139 151 INODE_TYPE_DEV, 140 152 FS_TYPE_DEVFS, 141 153 *devfs_internal_inode_xp, 142 "mmc",154 chdev_ptr->name, 143 155 GET_PTR( chdev_xp ), 144 156 &inode_xp ); 157 158 devfs_dmsg("\n[DBG] %s : created <%s> inode in cluster %x\n", 159 __FUNCTION__ , chdev_ptr->name , local_cxy ); 160 145 161 } 146 162 … … 151 167 if( chdev_xp != XPTR_NULL) 152 168 { 153 snprintf( node_name , 16 , "dma_%d" , channel);169 chdev_ptr = (chdev_t *)GET_PTR( chdev_xp ); 154 170 vfs_add_child_in_parent( local_cxy, 155 171 INODE_TYPE_DEV, 156 172 FS_TYPE_DEVFS, 157 173 *devfs_internal_inode_xp, 158 node_name,174 chdev_ptr->name, 159 175 GET_PTR( chdev_xp ), 160 176 &inode_xp ); 177 178 devfs_dmsg("\n[DBG] %s : created <%s> inode in cluster %x\n", 179 __FUNCTION__ , chdev_ptr->name , local_cxy ); 180 161 181 } 162 182 } … … 167 187 { 168 188 chdev_cxy = GET_CXY( chdev_xp ); 189 chdev_ptr = (chdev_t *)GET_PTR( chdev_xp ); 169 190 if( chdev_cxy == local_cxy ) 170 191 { … … 173 194 FS_TYPE_DEVFS, 174 195 devfs_external_inode_xp, 175 "iob",196 chdev_ptr->name, 176 197 GET_PTR( chdev_xp ), 177 198 &inode_xp ); 199 200 devfs_dmsg("\n[DBG] %s : created <%s> inode in cluster %x\n", 201 __FUNCTION__ , chdev_ptr->name , local_cxy ); 202 178 203 } 179 204 } … … 184 209 { 185 210 chdev_cxy = GET_CXY( chdev_xp ); 211 chdev_ptr = (chdev_t *)GET_PTR( chdev_xp ); 186 212 if( chdev_cxy == local_cxy ) 187 213 { … … 190 216 FS_TYPE_DEVFS, 191 217 devfs_external_inode_xp, 192 "pic",218 chdev_ptr->name, 193 219 GET_PTR( chdev_xp ), 194 220 &inode_xp ); 195 } 196 } 197 198 // create a TXT inode in each cluster containing a TXT chdev 221 222 devfs_dmsg("\n[DBG] %s : created <%s> inode in cluster %x\n", 223 __FUNCTION__ , chdev_ptr->name , local_cxy ); 224 225 } 226 } 227 228 // create a TXT_RX inode in each cluster containing a TXT_RX chdev 199 229 for( channel = 0 ; channel < CONFIG_MAX_TXT_CHANNELS ; channel++ ) 200 230 { 201 chdev_xp = chdev_dir.txt[channel]; 202 if( chdev_xp != XPTR_NULL ) 203 { 204 chdev_cxy = GET_CXY( chdev_xp ); 205 if( chdev_cxy == local_cxy ) 206 { 207 snprintf( node_name , 16 , "txt_%d" , channel ); 208 vfs_add_child_in_parent( local_cxy, 209 INODE_TYPE_DEV, 210 FS_TYPE_DEVFS, 211 devfs_external_inode_xp, 212 node_name, 213 GET_PTR( chdev_xp ), 214 &inode_xp ); 231 chdev_xp = chdev_dir.txt_rx[channel]; 232 if( chdev_xp != XPTR_NULL ) 233 { 234 chdev_cxy = GET_CXY( chdev_xp ); 235 chdev_ptr = (chdev_t *)GET_PTR( chdev_xp ); 236 if( chdev_cxy == local_cxy ) 237 { 238 vfs_add_child_in_parent( local_cxy, 239 INODE_TYPE_DEV, 240 FS_TYPE_DEVFS, 241 devfs_external_inode_xp, 242 chdev_ptr->name, 243 GET_PTR( chdev_xp ), 244 &inode_xp ); 245 246 devfs_dmsg("\n[DBG] %s : created <%s> inode in cluster %x\n", 247 __FUNCTION__ , chdev_ptr->name , local_cxy ); 248 249 } 250 } 251 } 252 253 // create a TXT_TX inode in each cluster containing a TXT_TX chdev 254 for( channel = 0 ; channel < CONFIG_MAX_TXT_CHANNELS ; channel++ ) 255 { 256 chdev_xp = chdev_dir.txt_tx[channel]; 257 if( chdev_xp != XPTR_NULL ) 258 { 259 chdev_cxy = GET_CXY( chdev_xp ); 260 chdev_ptr = (chdev_t *)GET_PTR( chdev_xp ); 261 if( chdev_cxy == local_cxy ) 262 { 263 vfs_add_child_in_parent( local_cxy, 264 INODE_TYPE_DEV, 265 FS_TYPE_DEVFS, 266 devfs_external_inode_xp, 267 chdev_ptr->name, 268 GET_PTR( chdev_xp ), 269 &inode_xp ); 270 271 devfs_dmsg("\n[DBG] %s : created <%s> inode in cluster %x\n", 272 __FUNCTION__ , chdev_ptr->name , local_cxy ); 273 215 274 } 216 275 } … … 224 283 { 225 284 chdev_cxy = GET_CXY( chdev_xp ); 226 if( chdev_cxy == local_cxy ) 227 { 228 snprintf( node_name , 16 , "ioc_%d" , channel ); 229 vfs_add_child_in_parent( local_cxy, 230 INODE_TYPE_DEV, 231 FS_TYPE_DEVFS, 232 devfs_external_inode_xp, 233 node_name, 234 GET_PTR( chdev_xp ), 235 &inode_xp ); 285 chdev_ptr = (chdev_t *)GET_PTR( chdev_xp ); 286 if( chdev_cxy == local_cxy ) 287 { 288 vfs_add_child_in_parent( local_cxy, 289 INODE_TYPE_DEV, 290 FS_TYPE_DEVFS, 291 devfs_external_inode_xp, 292 chdev_ptr->name, 293 GET_PTR( chdev_xp ), 294 &inode_xp ); 295 296 devfs_dmsg("\n[DBG] %s : created <%s> inode in cluster %x\n", 297 __FUNCTION__ , chdev_ptr->name , local_cxy ); 298 236 299 } 237 300 } … … 245 308 { 246 309 chdev_cxy = GET_CXY( chdev_xp ); 247 if( chdev_cxy == local_cxy ) 248 { 249 snprintf( node_name , 16 , "fbf_%d" , channel ); 250 vfs_add_child_in_parent( local_cxy, 251 INODE_TYPE_DEV, 252 FS_TYPE_DEVFS, 253 devfs_external_inode_xp, 254 node_name, 255 GET_PTR( chdev_xp ), 256 &inode_xp ); 310 chdev_ptr = (chdev_t *)GET_PTR( chdev_xp ); 311 if( chdev_cxy == local_cxy ) 312 { 313 vfs_add_child_in_parent( local_cxy, 314 INODE_TYPE_DEV, 315 FS_TYPE_DEVFS, 316 devfs_external_inode_xp, 317 chdev_ptr->name, 318 GET_PTR( chdev_xp ), 319 &inode_xp ); 320 321 devfs_dmsg("\n[DBG] %s : created <%s> inode in cluster %x\n", 322 __FUNCTION__ , chdev_ptr->name , local_cxy ); 323 257 324 } 258 325 } … … 266 333 { 267 334 chdev_cxy = GET_CXY( chdev_xp ); 268 if( chdev_cxy == local_cxy ) 269 { 270 snprintf( node_name , 16 , "nic_rx_%d" , channel ); 271 vfs_add_child_in_parent( local_cxy, 272 INODE_TYPE_DEV, 273 FS_TYPE_DEVFS, 274 devfs_external_inode_xp, 275 node_name, 276 GET_PTR( chdev_xp ), 277 &inode_xp ); 335 chdev_ptr = (chdev_t *)GET_PTR( chdev_xp ); 336 if( chdev_cxy == local_cxy ) 337 { 338 vfs_add_child_in_parent( local_cxy, 339 INODE_TYPE_DEV, 340 FS_TYPE_DEVFS, 341 devfs_external_inode_xp, 342 chdev_ptr->name, 343 GET_PTR( chdev_xp ), 344 &inode_xp ); 345 346 devfs_dmsg("\n[DBG] %s : created <%s> inode in cluster %x\n", 347 __FUNCTION__ , chdev_ptr->name , local_cxy ); 348 278 349 } 279 350 } … … 287 358 { 288 359 chdev_cxy = GET_CXY( chdev_xp ); 289 if( chdev_cxy == local_cxy ) 290 { 291 snprintf( node_name , 16 , "nic_tx_%d" , channel ); 292 vfs_add_child_in_parent( local_cxy, 293 INODE_TYPE_DEV, 294 FS_TYPE_DEVFS, 295 devfs_external_inode_xp, 296 node_name, 297 GET_PTR( chdev_xp ), 298 &inode_xp ); 360 chdev_ptr = (chdev_t *)GET_PTR( chdev_xp ); 361 if( chdev_cxy == local_cxy ) 362 { 363 vfs_add_child_in_parent( local_cxy, 364 INODE_TYPE_DEV, 365 FS_TYPE_DEVFS, 366 devfs_external_inode_xp, 367 chdev_ptr->name, 368 GET_PTR( chdev_xp ), 369 &inode_xp ); 370 371 devfs_dmsg("\n[DBG] %s : created <%s> inode in cluster %x\n", 372 __FUNCTION__ , chdev_ptr->name , local_cxy ); 373 299 374 } 300 375 } … … 302 377 } // end devfs_local_init() 303 378 379 ////////////////////////////////////////// 380 int devfs_user_move( bool_t to_buffer, 381 xptr_t file_xp, 382 void * u_buf, 383 uint32_t size ) 384 { 385 assert( ( file_xp != XPTR_NULL ) , __FUNCTION__ , "file_xp == XPTR_NULL" ); 386 387 assert( ( size < CONFIG_TXT_KBUF_SIZE ) , __FUNCTION__ , "string size too large" ); 388 389 cxy_t file_cxy; // remote file descriptor cluster 390 vfs_file_t * file_ptr; // remote file descriptor local pointer 391 vfs_inode_type_t inode_type; // associated inode type 392 vfs_inode_t * inode_ptr; // associated inode local pointer 393 chdev_t * chdev_ptr; // associated chdev type 394 uint32_t func; // chdev functionnal type 395 uint32_t channel; // chdev channel index 396 error_t error; 397 398 char k_buf[CONFIG_TXT_KBUF_SIZE]; // local kernel buffer 399 400 devfs_dmsg("\n[DBG] %s enter / cycle %d\n", 401 __FUNCTION__ , hal_time_stamp() ); 402 403 #if CONFIG_READ_DEBUG 404 enter_devfs_move = hal_time_stamp(); 405 #endif 406 407 // get cluster and local pointer on remote file descriptor 408 // associated inode and chdev are stored in same cluster as the file desc. 409 file_cxy = GET_CXY( file_xp ); 410 file_ptr = (vfs_file_t *)GET_PTR( file_xp ); 411 412 // get inode type from remote file descriptor 413 inode_type = hal_remote_lw( XPTR( file_cxy , &file_ptr->type ) ); 414 inode_ptr = (vfs_inode_t *)hal_remote_lpt( XPTR( file_cxy , &file_ptr->inode ) ); 415 416 assert( (inode_type == INODE_TYPE_DEV) , __FUNCTION__ , 417 "inode type is not INODE_TYPE_DEV" ); 418 419 // get chdev local pointer from remote inode extension 420 chdev_ptr = (chdev_t *)hal_remote_lpt( XPTR( file_cxy , &inode_ptr->extend ) ); 421 422 // get chdev functionnal type and channel 423 func = hal_remote_lw( XPTR( file_cxy , &chdev_ptr->func ) ); 424 channel = hal_remote_lw( XPTR( file_cxy , &chdev_ptr->channel ) ); 425 426 // action depends on "func" and "to_buffer" 427 if( func == DEV_FUNC_TXT ) 428 { 429 if( to_buffer ) // TXT read 430 { 431 uint32_t i; 432 for( i = 0 ; i < size ; i++ ) 433 { 434 error = dev_txt_read( channel , &k_buf[i] ); 435 436 if( error ) 437 { 438 439 devfs_dmsg("\n[DBG] %s exit error / cycle %d\n", 440 __FUNCTION__ , hal_time_stamp() ); 441 442 return -1; 443 } 444 else 445 { 446 hal_strcpy_to_uspace( u_buf , k_buf , size ); 447 } 448 } 449 450 #if CONFIG_READ_DEBUG 451 exit_devfs_move = hal_time_stamp(); 452 #endif 453 454 devfs_dmsg("\n[DBG] %s exit success / size = %d / cycle %d\n", 455 __FUNCTION__ , size , hal_time_stamp() ); 456 457 return size; 458 } 459 else // TXT write 460 { 461 hal_strcpy_from_uspace( k_buf , u_buf , size ); 462 463 error = dev_txt_write( channel , k_buf , size ); 464 if( error ) 465 { 466 467 devfs_dmsg("\n[DBG] %s exit error / cycle %d\n", 468 __FUNCTION__ , hal_time_stamp() ); 469 470 return -1; 471 } 472 else 473 { 474 475 devfs_dmsg("\n[DBG] %s exit success / size = %d / cycle %d\n", 476 __FUNCTION__ , size , hal_time_stamp() ); 477 478 return size; 479 } 480 } 481 } 482 else 483 { 484 panic("device type %s does not support direct user access", chdev_func_str(func) ); 485 486 return -1; 487 } 488 } // end devfs_user_move() 489 490
Note: See TracChangeset
for help on using the changeset viewer.