Changeset 246 for trunk/kernel
- Timestamp:
- Jul 20, 2017, 12:55:23 PM (7 years ago)
- Location:
- trunk/kernel
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/devices/dev_ioc.h
r188 r246 166 166 * from the block device to a memory buffer. 167 167 * It does not uses the IOC device waiting queue and server thread, and does not use 168 * the IOC IRQ, but call directly the relevant OIC driver, implementing a busy-waiting168 * the IOC IRQ, but call directly the relevant IOC driver, implementing a busy-waiting 169 169 * policy for the calling thread. 170 170 * It must be called in the client cluster. -
trunk/kernel/kern/kernel_init.c
r204 r246 100 100 // This variable contains the input IRQ indexes for the IOPIC controller 101 101 __attribute__((section(".kdata"))) 102 iopic_input_t 102 iopic_input_t iopic_input CONFIG_CACHE_LINE_ALIGNED; 103 103 104 104 // This variable contains the input IRQ indexes for the LAPIC controller … … 862 862 // 1. create FATFS context in cluster 0 863 863 fatfs_ctx_t * fatfs_ctx = fatfs_ctx_alloc(); 864 865 printk("\n@@@ %s extend = %x\n", __FUNCTION__ , fatfs_ctx ); 864 866 865 867 nolock_assert( (fatfs_ctx != NULL) , __FUNCTION__ , … … 902 904 hal_core_sleep(); 903 905 } 906 907 ///////////////////////////////@@@ 908 fatfs_ctx_display(); 909 ///////////////////////////////@@@ 904 910 905 911 // register VFS root inode in process_zero -
trunk/kernel/kern/printk.c
r188 r246 129 129 case ('l'): // 64 bits hexadecimal 130 130 { 131 uint32_t 131 uint32_t imax; 132 132 uint64_t val; 133 133 … … 153 153 len = i + 1; 154 154 pbuf = &buf[(imax-1) - i]; 155 break; 156 } 157 case ('X'): // 32 bits hexadecimal on 8 characters 158 { 159 uint32_t val = va_arg( args , uint32_t ); 160 for(i = 0; i < 8; i++) 161 { 162 buf[7 - i] = HexaTab[val % 16]; 163 val = (val>>4); 164 } 165 len = 8; 166 pbuf = buf; 155 167 break; 156 168 } -
trunk/kernel/mm/mapper.c
r238 r246 40 40 #include <mapper.h> 41 41 42 ////////////////////////// 43 mapper_t * mapper_create( )42 ////////////////////////////////////////////// 43 mapper_t * mapper_create( vfs_fs_type_t type ) 44 44 { 45 45 mapper_t * mapper; … … 78 78 } 79 79 80 // initialize mapper type 81 mapper->type = type; 82 80 83 // initialize mapper lock 81 84 rwlock_init( &mapper->lock ); … … 139 142 error_t error; 140 143 141 mapper_dmsg("\n[INFO] %s : enter for page %d / mapper =%x\n",144 mapper_dmsg("\n[INFO] %s : enters for page %d in mapper %x\n", 142 145 __FUNCTION__ , index , mapper ); 143 146 … … 254 257 } 255 258 256 mapper_dmsg("\n[INFO] %s : exit for page %d / pagedesc = %x\n",257 __FUNCTION__ , index , page );259 mapper_dmsg("\n[INFO] %s : exit for page %d in mapper %x / page_desc = %x\n", 260 __FUNCTION__ , index , mapper , page ); 258 261 259 262 return page; -
trunk/kernel/mm/mapper.h
r238 r246 49 49 * - The mapper is protected by a blocking "rwlock", to support several simultaneous 50 50 * readers, and only one writer. This lock implement a busy waiting policy. 51 * - The vfs_mapper_move_page() and vfs_mapper_load_all() functions are used to move 52 * pages to or from the file system on device. 51 * - The mapper_get_page() function that return a page descriptor pointer from a page 52 * index in file is in charge of handling the miss on the mapper cache. 53 * - The vfs_mapper_move_page() function is used to handle miss on one specific page, 54 * or update a dirty page on device. 55 * - The vfs_mapper_load_all() functions is used to load all pages of a given directory 56 * into the mapper. 53 57 * - the mapper_move() function is used to move data to or from an user buffer. 54 58 * This user space buffer can be physically distributed in several clusters. 55 * - The mapper_get_page() function that return a page descriptor pointer from a page 56 * index in file is in charge of handling the miss on the mapper cache. 57 * - In the present implementation the cache size increases on demand, and the 58 * allocated memory is only released when the mapper/inode is destroyed. 59 * - In the present implementation the cache size for a given file increases on demand, 60 * and the allocated memory is only released when the mapper/inode is destroyed. 59 61 ******************************************************************************************/ 60 62 … … 67 69 { 68 70 struct vfs_inode_s * inode; /*! owner inode */ 71 uint32_t type; /*! file system type */ 69 72 grdxt_t radix; /*! pages cache implemented as a radix tree */ 70 73 rwlock_t lock; /*! several readers / only one writer */ -
trunk/kernel/vfs/fatfs.c
r238 r246 73 73 } 74 74 75 ////////////////////////////////////////////////////////////////////////////////////////// 76 // This function display the content of the FATFS context. 77 ////////////////////////////////////////////////////////////////////////////////////////// 78 void fatfs_ctx_display() 79 { 80 uint32_t type = FS_TYPE_FATFS; 81 vfs_ctx_t * vfs_ctx = &fs_context[FS_TYPE_FATFS]; 82 fatfs_ctx_t * fatfs_ctx = (fatfs_ctx_t *)vfs_ctx->extend; 83 84 printk("\n*** FAT context ***\n" 85 "- fat_sectors = %d\n" 86 "- sector size = %d\n" 87 "- cluster size = %d\n" 88 "- fat_first_lba = %d\n" 89 "- data_first_lba = %d\n" 90 "- root_dir_cluster = %d\n" 91 "- mapper_xp = %l\n", 92 fatfs_ctx->fat_sectors_count, 93 fatfs_ctx->bytes_per_sector, 94 fatfs_ctx->sectors_per_cluster * fatfs_ctx->bytes_per_sector, 95 fatfs_ctx->fat_begin_lba, 96 fatfs_ctx->cluster_begin_lba, 97 fatfs_ctx->root_dir_cluster, 98 fatfs_ctx->fat_mapper_xp ); 99 } 75 100 76 101 ////////////////////////////////////////////////////////////////////////////////////////// … … 280 305 281 306 ////////////////////////////////////////////////////////////////////////////////////////// 282 // FATFS specific but public functions(used by RPC_FATFS_GET_CLUSTER)307 // FATFS specific but extern function (used by RPC_FATFS_GET_CLUSTER) 283 308 ////////////////////////////////////////////////////////////////////////////////////////// 284 309 … … 296 321 uint32_t current_cluster; // content of current FAT slot 297 322 298 // compute number of FAT slots per PPM page 323 fatfs_dmsg("\n[INFO] %s : enters / first_cluster_id = %d / searched_page = %d\n", 324 __FUNCTION__ , first_cluster , searched_page ); 325 326 #if CONFIG_FATFS_DEBUG 327 uint32_t * buf = (uint32_t *)ppm_page2vaddr( mapper_get_page ( mapper , 0 ) ); 328 uint32_t line , word; 329 printk("\n*** FAT content for first 128 entries ***\n"); 330 for( line = 0 ; line < 8 ; line++ ) 331 { 332 printk("%d : "); 333 for( word = 0 ; word < 16 ; word++ ) printk("%X ", buf[(line<<4) + word] ); 334 printk("\n"); 335 } 336 #endif 337 338 // compute number of FAT slots per page 299 339 uint32_t slots_per_page = CONFIG_PPM_PAGE_SIZE >> 2; 300 340 … … 307 347 while( page_count_in_file <= searched_page ) 308 348 { 349 350 fatfs_dmsg("\n[INFO] %s : page_index = %d / page_offset = %d / count = %d\n", 351 __FUNCTION__ , current_page_index , current_page_offset , page_count_in_file ); 352 309 353 // get pointer on current page descriptor 310 354 current_page_desc = mapper_get_page( mapper , current_page_index ); … … 324 368 } 325 369 326 // return success 370 fatfs_dmsg("\n[INFO] %s : exit / cluster_id = %d\n", 371 __FUNCTION__ , current_cluster ); 372 327 373 *cluster = current_cluster; 328 374 return 0; … … 355 401 uint8_t * buffer; 356 402 357 fatfs_dmsg("\n[INFO] %s : enters at cycle %d\n", 358 __FUNCTION__ , hal_get_cycles() ); 359 360 // allocate memory for FATFS context 361 req.type = KMEM_FATFS_CTX; 362 req.size = sizeof(fatfs_ctx_t); 363 req.flags = AF_KERNEL | AF_ZERO; 364 365 fatfs_ctx = (fatfs_ctx_t *)kmem_alloc( &req ); 366 367 nolock_assert( (fatfs_ctx != NULL) , __FUNCTION__ , 403 fatfs_dmsg("\n[INFO] %s : enters for fatfs_ctx = %x\n", 404 __FUNCTION__ , fatfs_ctx ); 405 406 assert( (fatfs_ctx != NULL) , __FUNCTION__ , 368 407 "cannot allocate memory for FATFS context\n" ); 369 408 … … 373 412 buffer = (uint8_t *)kmem_alloc( &req ); 374 413 375 nolock_assert( (buffer != NULL) , __FUNCTION__ ,414 assert( (buffer != NULL) , __FUNCTION__ , 376 415 "cannot allocate memory for 512 bytes buffer\n" ); 377 416 … … 380 419 error = dev_ioc_sync_read( buffer , 0 , 1 ); 381 420 382 nolock_assert( (error == 0) , __FUNCTION__ ,421 assert( (error == 0) , __FUNCTION__ , 383 422 "cannot access boot record\n" ); 384 423 385 #if CONFIG_FATFS_DEBUG424 #if (CONFIG_FATFS_DEBUG > 1) 386 425 uint32_t line; 387 426 uint32_t byte = 0; … … 439 478 440 479 // allocate a mapper for the FAT itself 441 mapper_t * fat_mapper = mapper_create( );480 mapper_t * fat_mapper = mapper_create( FS_TYPE_FATFS ); 442 481 443 482 assert( (fat_mapper != NULL) , __FUNCTION__ , "no memory for FAT mapper" ); 483 484 // WARNING : the inode field MUST be NULL for the FAT mapper 485 fat_mapper->inode = NULL; 444 486 445 487 // initialize the FATFS context … … 454 496 fatfs_ctx->fat_mapper_xp = XPTR( local_cxy , fat_mapper ); 455 497 456 fatfs_dmsg("\n*** FAT context ***\n"457 "- fat_sectors = %d\n"458 "- sector size = %d\n"459 "- cluster size = %d\n"460 "- fat_first_lba = %d\n"461 "- data_first_lba = %d\n"462 "- mapper = %l\n",463 fatfs_ctx->fat_sectors_count,464 fatfs_ctx->bytes_per_sector,465 fatfs_ctx->bytes_per_cluster,466 fatfs_ctx->fat_begin_lba,467 fatfs_ctx->cluster_begin_lba,468 fatfs_ctx->fat_mapper_xp );469 470 498 } // end fatfs_ctx_init() 471 499 … … 479 507 } 480 508 481 /////////////////////////////////////// 482 error_t fatfs_move_page( page_t * page, 483 bool_t to_mapper ) 484 { 509 ////////////////////////////////////////////// 510 error_t fatfs_mapper_move_page( page_t * page, 511 bool_t to_mapper ) 512 { 513 error_t error; 514 515 // get pointer on source mapper and page index from page descriptor 516 mapper_t * mapper = page->mapper; 517 uint32_t index = page->index; 518 519 // get VFS inode pointer from mapper 520 vfs_inode_t * inode = mapper->inode; 521 522 fatfs_dmsg("\n[INFO] %s : enter for inode %x / page_index = %d / mapper = %x\n", 523 __FUNCTION__ , inode , index , mapper ); 524 485 525 // get memory buffer base address 486 526 uint8_t * buffer = (uint8_t *)ppm_page2vaddr( page ); 487 527 488 // get pointer on source mapper and page index from page descriptor 489 mapper_t * mapper = page->mapper; 490 uint32_t page_index = page->index; 491 492 // get VFS inode pointer from mapper 493 vfs_inode_t * vfs_inode = mapper->inode; 494 495 // get first cluster index from VFS inode 496 uint32_t first_cluster = (uint32_t)(intptr_t)vfs_inode->extend; 497 498 // get FATFS context pointer from VFS context 528 // get number of sectors from FATFS context 499 529 fatfs_ctx_t * fatfs_ctx = (fatfs_ctx_t *)fs_context[FS_TYPE_FATFS].extend; 500 501 // get number of sectors502 530 uint32_t count = fatfs_ctx->sectors_per_cluster; 503 531 504 // compute FATFS_cluster index for the accessed page 505 uint32_t cluster = 0; 506 error_t error = fatfs_cluster_from_index( fatfs_ctx, 507 first_cluster, 508 page_index, 509 &cluster ); 510 if( error ) return EIO; 511 512 // get lba from cluster 513 uint32_t lba = fatfs_lba_from_cluster( fatfs_ctx , cluster ); 514 515 // access device 516 if( to_mapper ) error = dev_ioc_read ( buffer , lba , count ); 517 else error = dev_ioc_write( buffer , lba , count ); 518 519 if( error ) 520 { 521 printk("\n[ERROR] in %s : cannot access IOC device\n", __FUNCTION__ ); 522 return error; 523 } 524 525 // successful access 532 // analyse the mapper type : FAT or normal inode 533 if( inode == NULL ) // it is the FAT mapper 534 { 535 // get lba from page index 536 uint32_t lba = fatfs_ctx->fat_begin_lba + (count * index); 537 538 fatfs_dmsg("\n[INFO] %s : for FAT / lba = %d\n", 539 __FUNCTION__ , lba ); 540 541 // access device 542 if( to_mapper ) error = dev_ioc_sync_read ( buffer , lba , count ); 543 else error = dev_ioc_write( buffer , lba , count ); 544 545 if( error ) return EIO; 546 547 fatfs_dmsg("\n[INFO] %s : exit for FAT / page_index = %d / mapper = %x\n", 548 __FUNCTION__ , index , mapper ); 549 } 550 else // it is a normal inode mapper 551 { 552 // get first cluster index from inode extension 553 uint32_t first_cluster = (uint32_t)(intptr_t)inode->extend; 554 555 fatfs_dmsg("\n[INFO] %s : for inode %x / first cluster_id = %d\n", 556 __FUNCTION__ , inode , first_cluster ); 557 558 // compute FATFS_cluster index for the accessed page 559 uint32_t cluster = 0; 560 error_t error = fatfs_cluster_from_index( fatfs_ctx, 561 first_cluster, 562 index, 563 &cluster ); 564 if( error ) return EIO; 565 566 // get lba from cluster 567 uint32_t lba = fatfs_lba_from_cluster( fatfs_ctx , cluster ); 568 569 fatfs_dmsg("\n[INFO] %s : for inode %x / page = %d / cluster_id = %d / lba = %x\n", 570 __FUNCTION__ , inode , index , cluster , lba ); 571 572 // access device 573 if( to_mapper ) error = dev_ioc_sync_read ( buffer , lba , count ); 574 else error = dev_ioc_write( buffer , lba , count ); 575 576 if( error ) return EIO; 577 578 fatfs_dmsg("\n[INFO] %s : exit for inode %x / page = %x / mapper = %x\n", 579 __FUNCTION__ , inode , page , mapper ); 580 } 581 526 582 return 0; 527 } 583 584 } // end fatfs_mapper_move_page() 528 585 529 586 ///////////////////////////////////////////////////////////////// … … 537 594 538 595 fatfs_dmsg("\n[INFO] %s : enter for child <%s> in parent inode %l\n", 539 __FUNCTION__ , name , child_inode_xp);596 __FUNCTION__ , name , XPTR( local_cxy , parent_inode ) ); 540 597 541 598 mapper_t * mapper = parent_inode->mapper; … … 641 698 if ( found == -1 ) // found end of directory => failure 642 699 { 643 fatfs_dmsg("\n[INFO] %s : child <%s> not found in parent inode %l\n",644 __FUNCTION__ , name , parent_inode_xp);700 fatfs_dmsg("\n[INFO] %s : exit / child <%s> not found in parent inode %l\n", 701 __FUNCTION__ , name , XPTR( local_cxy , parent_inode ) ); 645 702 646 703 return ENOENT; … … 648 705 else // found searched child name 649 706 { 650 fatfs_dmsg("\n[INFO] %s : child <%s> found in parent inode %l\n",651 __FUNCTION__ , name , parent_inode_xp );652 653 707 // get child inode cluster and local pointer 654 708 cxy_t child_cxy = GET_CXY( child_inode_xp ); … … 662 716 hal_remote_sw( XPTR( child_cxy , &child_ptr->extend ) , cluster ); 663 717 718 fatfs_dmsg("\n[INFO] %s : exit / child <%s> found in parent inode %l\n", 719 __FUNCTION__ , name , XPTR( local_cxy , parent_inode ) ); 720 664 721 return 0; 665 722 } -
trunk/kernel/vfs/fatfs.h
r238 r246 243 243 * It must be called by a thread running in cluster containing the mapper. 244 244 * The pointer on the mapper and the page index in file are registered 245 * in the page descriptor. 245 * in the page descriptor. 246 * WARNING : The inode field in the mapper must be NULL for the FAT mapper. 247 * This is used to implement a specific behaviour to access the FAT zone on device. 246 248 ***************************************************************************************** 247 249 * @ page : local pointer on page descriptor. … … 249 251 * @ return 0 if success / return EIO if error. 250 252 ****************************************************************************************/ 251 error_t fatfs_m ove_page( struct page_s * page,252 bool_t to_mapper );253 error_t fatfs_mapper_move_page( struct page_s * page, 254 bool_t to_mapper ); 253 255 254 256 -
trunk/kernel/vfs/vfs.c
r238 r246 161 161 { 162 162 ctx = NULL; 163 printk("\n[PANIC] in %s : undefined file system type\n", __FUNCTION__);163 printk("\n[PANIC] in %s : illegal file system type = %d\n", __FUNCTION__ , fs_type ); 164 164 hal_core_sleep(); 165 165 } … … 175 175 176 176 // allocate memory for mapper 177 mapper = mapper_create( );177 mapper = mapper_create( fs_type ); 178 178 179 179 if( mapper == NULL ) … … 209 209 inode->parent_xp = dentry_xp; 210 210 inode->ctx = ctx; 211 inode->mapper = NULL;211 inode->mapper = mapper; 212 212 inode->extend = extend; 213 213 214 // initialise inode field in mapper 215 mapper->inode = inode; 216 214 217 // initialise threads waiting queue 215 218 xlist_root_init( XPTR( local_cxy , &inode->wait_root ) ); … … 253 256 xptr_t child_xp ) 254 257 { 258 vfs_dmsg("\n[INFO] %s : enter for child <%s>\n", 259 __FUNCTION__ , name ); 260 255 261 error_t error = 0; 256 262 … … 279 285 assert( false , __FUNCTION__ , "undefined file system type\n" ); 280 286 } 287 288 vfs_dmsg("\n[INFO] %s : exit for child <%s>\n", 289 __FUNCTION__ , name ); 281 290 282 291 return error; … … 1253 1262 // for the last name, the behaviour depends on the "mode" argument: 1254 1263 1255 if (found == false ) // directorynode not found in inode tree1264 if (found == false ) // child node not found in inode tree 1256 1265 { 1257 1266 vfs_dmsg("\n[INFO] %s : <%s> not found, try to load it\n", … … 1559 1568 assert( (page != NULL) , __FUNCTION__ , "page pointer is NULL\n" ); 1560 1569 1561 mapper_t * mapper = page->mapper; 1570 mapper_t * mapper = page->mapper; 1571 1562 1572 1563 1573 assert( (mapper != NULL) , __FUNCTION__ , "no mapper for page\n" ); 1564 1574 1575 vfs_dmsg("\n[INFO] %s : enters for page = %d in mapper = %x\n", 1576 __FUNCTION__ , page->index , mapper ); 1577 1565 1578 // get FS type 1566 vfs_fs_type_t fs_type = mapper-> inode->ctx->type;1579 vfs_fs_type_t fs_type = mapper->type; 1567 1580 1568 1581 // call relevant FS function … … 1570 1583 { 1571 1584 rwlock_wr_lock( &mapper->lock ); 1572 error = fatfs_m ove_page( page , to_mapper );1585 error = fatfs_mapper_move_page( page , to_mapper ); 1573 1586 rwlock_wr_unlock( &mapper->lock ); 1574 1587 } … … 1585 1598 assert( false , __FUNCTION__ , "undefined file system type\n" ); 1586 1599 } 1600 1601 vfs_dmsg("\n[INFO] %s : exit for page = %d in mapper = %x\n", 1602 __FUNCTION__ , page->index , mapper ); 1587 1603 1588 1604 return error;
Note: See TracChangeset
for help on using the changeset viewer.