Changeset 313 for trunk/kernel/mm/mapper.c
- Timestamp:
- Aug 2, 2017, 3:24:57 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/mm/mapper.c
r296 r313 299 299 } // end mapper_release_page() 300 300 301 //////////////////////////////////////////////// 302 error_t mapper_move_buffer( mapper_t * mapper, 303 bool_t to_buffer, 304 bool_t is_user, 305 uint32_t file_offset, 306 void * buffer, 307 uint32_t size ) 301 /////////////////////////////////////////////////// 302 error_t mapper_move_user( mapper_t * mapper, 303 bool_t to_buffer, 304 uint32_t file_offset, 305 void * buffer, 306 uint32_t size ) 308 307 { 309 308 uint32_t page_offset; // first byte to move to/from a mapper page … … 335 334 else page_offset = 0; 336 335 337 // compute page_count336 // compute number of bytes in page 338 337 if ( first == last ) page_count = size; 339 338 else if ( index == first ) page_count = CONFIG_PPM_PAGE_SIZE - page_offset; … … 359 358 360 359 // move fragment 361 if( to_buffer ) 362 { 363 if( is_user ) hal_copy_to_uspace( buf_ptr , map_ptr , page_count ); 364 else memcpy( buf_ptr , map_ptr , page_count ); 360 if( to_buffer ) 361 { 362 hal_copy_to_uspace( buf_ptr , map_ptr , page_count ); 365 363 } 366 364 else 367 365 { 368 366 page_do_dirty( page ); 369 if( is_user ) hal_copy_from_uspace( map_ptr , buf_ptr , page_count ); 370 else memcpy( map_ptr , buf_ptr , page_count ); 367 hal_copy_from_uspace( map_ptr , buf_ptr , page_count ); 371 368 } 372 369 … … 379 376 return 0; 380 377 381 } // end mapper_move_buffer() 382 378 } // end mapper_move_user() 379 380 //////////////////////////////////////////////// 381 error_t mapper_move_kernel( mapper_t * mapper, 382 bool_t to_buffer, 383 uint32_t file_offset, 384 xptr_t buffer_xp, 385 uint32_t size ) 386 { 387 uint32_t page_offset; // first byte to move to/from a mapper page 388 uint32_t page_count; // number of bytes to move to/from a mapper page 389 uint32_t index; // current mapper page index 390 uint32_t done; // number of moved bytes 391 page_t * page; // current mapper page descriptor 392 393 uint8_t * src_ptr; // source buffer local pointer 394 cxy_t src_cxy; // source cluster 395 uint8_t * dst_ptr; // destination buffer local pointer 396 cxy_t dst_cxy; // destination cluster 397 398 mapper_dmsg("\n[INFO] %s : enters / to_buf = %d / buffer = %l / size = %x / cycle %d\n", 399 __FUNCTION__ , to_buffer , buffer_xp , size , hal_time_stamp() ); 400 401 // compute offsets of first and last bytes in file 402 uint32_t min_byte = file_offset; 403 uint32_t max_byte = file_offset + size -1; 404 405 // compute indexes for first and last pages in mapper 406 uint32_t first = min_byte >> CONFIG_PPM_PAGE_SHIFT; 407 uint32_t last = max_byte >> CONFIG_PPM_PAGE_SHIFT; 408 409 // get buffer cluster and local pointer 410 cxy_t buffer_cxy = GET_CXY( buffer_xp ); 411 uint8_t * buffer_ptr = (uint8_t *)GET_PTR( buffer_xp ); 412 413 // compute source and destination clusters 414 if( to_buffer ) 415 { 416 dst_cxy = buffer_cxy; 417 src_cxy = local_cxy; 418 } 419 else 420 { 421 src_cxy = buffer_cxy; 422 dst_cxy = local_cxy; 423 } 424 425 done = 0; 426 427 // loop on pages in mapper 428 for( index = first ; index <= last ; index++ ) 429 { 430 // compute page_offset 431 if( index == first ) page_offset = min_byte & CONFIG_PPM_PAGE_MASK; 432 else page_offset = 0; 433 434 // compute number of bytes to move in page 435 if ( first == last ) page_count = size; 436 else if ( index == first ) page_count = CONFIG_PPM_PAGE_SIZE - page_offset; 437 else if ( index == last ) page_count = (max_byte & CONFIG_PPM_PAGE_MASK) + 1; 438 else page_count = CONFIG_PPM_PAGE_SIZE; 439 440 mapper_dmsg("\n[INFO] %s : page_index = %d / offset = %d / count = %d\n", 441 __FUNCTION__ , index , page_offset , page_count ); 442 443 // get page descriptor 444 page = mapper_get_page( mapper , index ); 445 446 if ( page == NULL ) return EINVAL; 447 448 // compute source and destination pointers 449 if( to_buffer ) 450 { 451 dst_ptr = buf_ptr + done; 452 src_ptr = (uint8_t *)ppm_page2vaddr( page ) + page_offset; 453 } 454 else 455 { 456 src_ptr = buf_ptr + done; 457 dst_ptr = (uint8_t *)ppm_page2vaddr( page ) + page_offset; 458 459 page_do_dirty( page ); 460 } 461 462 mapper_dmsg("\n[INFO] %s : index = %d / buf_ptr = %x / map_ptr = %x\n", 463 __FUNCTION__ , index , buf_ptr , map_ptr ); 464 465 // move fragment 466 hal_remote_memcpy( XPTR( dst_cxy , dst_ptr ), XPTR( src_cxy , src_ptr ), page_count ); 467 468 done += page_count; 469 } 470 471 mapper_dmsg("\n[INFO] %s : exit for buffer %l / size = %x / cycle %d\n", 472 __FUNCTION__ , buffer_xp , size , hal_time_stamp() ); 473 474 return 0; 475 476 } // end mapper_move_kernel_buffer() 477
Note: See TracChangeset
for help on using the changeset viewer.