Changeset 478 for soft/giet_vm
- Timestamp:
- Jan 1, 2015, 7:58:56 PM (10 years ago)
- Location:
- soft/giet_vm/giet_kernel
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/giet_kernel/kernel_init.c
r467 r478 16 16 #include <xcu_driver.h> 17 17 #include <ioc_driver.h> 18 #include <mmc_driver.h> 18 19 #include <ctx_handler.h> 19 20 #include <irq_handler.h> … … 106 107 //////////////////////////////////////////////////////////////////////////////////// 107 108 108 sbt_lock_t _tty_tx_lock[NB_TTY_CHANNELS] __attribute__((aligned(64)));109 110 109 unsigned int _tty_rx_buf[NB_TTY_CHANNELS]; 111 110 unsigned int _tty_rx_full[NB_TTY_CHANNELS]; 112 111 113 114 115 112 //////////////////////////////////////////////////////////////////////////////////// 113 // Distributed locks protecting TTY terminals 114 //////////////////////////////////////////////////////////////////////////////////// 115 116 sbt_lock_t _tty_tx_lock[NB_TTY_CHANNELS] __attribute__((aligned(64))); 116 117 117 118 /////////////////////////////////////////////////////////////////////////////////// … … 142 143 while( cpid != kernel_init_barrier ) asm volatile ( "nop" ); 143 144 144 // Step 0 : P[0,0,0] initialises the kernel FAT 145 // and the distributed kernel_heap descriptors array. 145 // Step 0 : P[0,0,0] initialises various complex structures 146 // - kernel FAT 147 // - distributed kernel heaps 148 // - distributed locks protecting TTY channels 149 // - distributed locks protecting MMC components 146 150 if ( gpid == 0 ) 147 151 { … … 155 159 { 156 160 _sbt_lock_init( &_tty_tx_lock[channel] ); 161 162 #if GIET_DEBUG_INIT 163 _nolock_printf("\n[DEBUG KERNEL_INIT] P[%d,%d,%d] completes TTY[%d] lock init\n", 164 x , y , p , channel ); 165 #endif 157 166 } 158 167 159 #if GIET_DEBUG_INIT 160 _nolock_printf("\n[DEBUG KERNEL_INIT] P[%d,%d,%d] completes TTY locks init\n", x, y, p ); 161 #endif 162 168 /* 169 unsigned int cx, cy; 170 for ( cx = 0 ; cx < X_SIZE ; cx++ ) 171 { 172 for ( cy = 0 ; cy < X_SIZE ; cy++ ) 173 { 174 _sbt_lock_init( &_mmc_lock[cx][cy] ); 175 176 #if GIET_DEBUG_INIT 177 _nolock_printf("\n[DEBUG KERNEL_INIT] P[%d,%d,%d] completes MMC[%d][%d] lock init\n", 178 x , y , p , cx , cy ); 179 #endif 180 } 181 } 182 */ 163 183 _fat_init( IOC_BOOT_MODE ); 164 184 -
soft/giet_vm/giet_kernel/sys_handler.c
r467 r478 16 16 #include <fat32.h> 17 17 #include <utils.h> 18 #include <kernel_malloc.h> 18 19 #include <tty0.h> 19 20 #include <vmem.h> … … 46 47 #endif 47 48 48 #if !defined(GIET_NIC_NBUFS)49 # error: You must define GIET_NIC_NBUFS in the giet_config.h file50 #endif51 52 #if !defined(GIET_NIC_BUFSIZE)53 # error: You must define GIET_NIC_BUFSIZE in the giet_config.h file54 #endif55 56 #if !defined(GIET_NIC_TIMEOUT)57 # error: You must define GIET_NIC_TIMEOUT in the giet_config.h file58 #endif59 60 49 #if !defined(GIET_NO_HARD_CC) 61 50 # error: You must define GIET_NO_HARD_CC in the giet_config.h file 51 #endif 52 53 #if !defined ( GIET_NIC_MAC4 ) 54 # error: You must define GIET_NIC_MAC4 in the giet_config.h file 55 #endif 56 57 #if !defined ( GIET_NIC_MAC2 ) 58 # error: You must define GIET_NIC_MAC2 in the giet_config.h file 62 59 #endif 63 60 … … 68 65 //////////////////////////////////////////////////////////////////////////// 69 66 70 unsigned int _tty_channel_allocator = 1;71 unsigned int _tim_channel_allocator = 0;72 unsigned int _cma_channel_allocator = 0;67 unsigned int _tty_channel_allocator = 1; 68 unsigned int _tim_channel_allocator = 0; 69 unsigned int _cma_channel_allocator = 0; 73 70 unsigned int _nic_rx_channel_allocator = 0; 74 71 unsigned int _nic_tx_channel_allocator = 0; 75 72 76 73 //////////////////////////////////////////////////////////////////////////// 77 // NIC_RX and NIC_TX chbuf arrays and associated containers arrays74 // NIC_RX and NIC_TX chbuf arrays 78 75 //////////////////////////////////////////////////////////////////////////// 79 76 80 spin_lock_t _nic_rx_lock[NB_NIC_CHANNELS] __attribute__((aligned(64)));81 82 spin_lock_t _nic_tx_lock[NB_NIC_CHANNELS] __attribute__((aligned(64)));83 84 77 nic_chbuf_t _nic_rx_chbuf[NB_NIC_CHANNELS] __attribute__((aligned(64))); 85 78 86 79 nic_chbuf_t _nic_tx_chbuf[NB_NIC_CHANNELS] __attribute__((aligned(64))); 87 80 88 unsigned char _nic_rx_cont[GIET_NIC_BUFSIZE] 89 [GIET_NIC_NBUFS] 90 [NB_NIC_CHANNELS] __attribute__((aligned(64))); 91 92 unsigned char _nic_tx_cont[GIET_NIC_BUFSIZE] 93 [GIET_NIC_NBUFS] 94 [NB_NIC_CHANNELS] __attribute__((aligned(64))); 81 //////////////////////////////////////////////////////////////////////////// 82 // FBF related chbuf descriptors array, indexed by the CMA channel index. 83 // Physical addresses of these chbuf descriptors required for L2 cache sync. 84 //////////////////////////////////////////////////////////////////////////// 85 86 fbf_chbuf_t _fbf_chbuf[NB_CMA_CHANNELS] __attribute__((aligned(64))); 87 88 unsigned long long _fbf_chbuf_paddr[NB_CMA_CHANNELS]; 95 89 96 90 //////////////////////////////////////////////////////////////////////////// … … 336 330 ////////////////////////////////////////////////////////////////////////////// 337 331 332 #define NIC_CONTAINER_SIZE 4096 333 338 334 /////////////////////////////////////////// 339 335 int _sys_nic_alloc( unsigned int is_rx ) … … 342 338 #if GIET_DEBUG_NIC 343 339 unsigned int thread = _get_context_slot( CTX_TRDID_ID ); 344 unsigned int vspace = _get_context_slot( CTX_VSID_ID ); 345 _printf("\n[GIET DEBUG NIC] Task %d in vspace %d enters sys_nic_alloc()\n", 346 thread, vspace ); 340 _printf("\n[GIET DEBUG NIC] Task %d enters sys_nic_alloc() at cycle %d\n", 341 thread, _get_proctime() ); 347 342 #endif 348 343 … … 382 377 383 378 #if GIET_DEBUG_NIC 384 _printf("\n[GIET DEBUG NIC] Task %d in vspace %d exit _sys_nic_alloc(): "379 _printf("\n[GIET DEBUG NIC] Task %d exit _sys_nic_alloc() at cycle %d : " 385 380 "NIC channel = %d / CMA channel = %d\n", 386 thread, vspace, nic_channel, cma_channel );381 thread, _get_proctime(), nic_channel, cma_channel ); 387 382 #endif 388 383 … … 396 391 #if GIET_DEBUG_NIC 397 392 unsigned int thread = _get_context_slot( CTX_TRDID_ID ); 398 unsigned int vspace = _get_context_slot( CTX_VSID_ID ); 399 _printf("\n[GIET DEBUG NIC] Task %d of vspace %d enters _sys_nic_start()\n", 400 thread, vspace ); 393 _printf("\n[GIET DEBUG NIC] Task %d enters _sys_nic_start() at cycle %d\n", 394 thread , _get_proctime() ); 401 395 #endif 402 396 … … 417 411 418 412 #if GIET_DEBUG_NIC 419 _printf("\n[GIET DEBUG NIC] Task %d of vspace %d in _sys_nic_start()"413 _printf("\n[GIET DEBUG NIC] Task %d in _sys_nic_start() at cycle %d" 420 414 " get NIC channel = %d / CMA channel = %d\n", 421 thread, vspace, nic_channel, cma_channel );415 thread, _get_proctime(), nic_channel, cma_channel ); 422 416 #endif 423 417 … … 435 429 unsigned long long nic_chbuf_pbase; // NIC chbuf physical address 436 430 unsigned long long ker_chbuf_pbase; // kernel chbuf physical address 437 unsigned long long ker_cont_pbase; // kernel container array physical address 438 439 // These variables are used for V2P translation 431 432 // These variables are used for the various V2P translation 440 433 unsigned int ptab = _get_context_slot(CTX_PTAB_ID); 441 434 unsigned int ppn; 442 435 unsigned int flags; 443 unsigned int ko;444 436 unsigned int vaddr; 445 437 446 // get the NIC chbuf descriptor physical address 438 // allocate two containers per cluster 439 unsigned int cx; // container X coordinate 440 unsigned int cy; // container Y coordinate 441 unsigned int index; // container index in chbuf 442 unsigned long long cont_paddr; // container physical address 443 444 for ( cx = 0 ; cx < X_SIZE ; cx++ ) 445 { 446 for ( cy = 0 ; cy < Y_SIZE ; cy++ ) 447 { 448 // compute index in chbuf 449 index = (cx * Y_SIZE) + cy; 450 451 // allocate the container 452 vaddr = (unsigned int)_remote_malloc( NIC_CONTAINER_SIZE, cx, cy ); 453 454 // compute container physical address 455 _v2p_translate( (page_table_t*)ptab, 456 vaddr>>12, 457 &ppn, 458 &flags ); 459 cont_paddr = (((unsigned long long)ppn) << 12) | (vaddr & 0x00000FFF); 460 461 // initialize chbuf 462 if ( is_rx ) _nic_rx_chbuf[nic_channel].buffer[index].desc = cont_paddr; 463 else _nic_tx_chbuf[nic_channel].buffer[index].desc = cont_paddr; 464 465 #if GIET_DEBUG_NIC 466 _printf("\n[GIET DEBUG NIC] Task %d in _sys_nic_start()" 467 " allocates container in cluster[%d,%d] : vaddr = %x / paddr = %l\n", 468 thread , cx , cy , vaddr , cont_paddr ); 469 #endif 470 } 471 } 472 473 // compute the NIC chbuf descriptor physical address 447 474 unsigned int offset; 448 475 if ( is_rx ) offset = 0x4000; … … 452 479 453 480 #if GIET_DEBUG_NIC 454 _printf("\n[GIET DEBUG NIC] Task %d of vspace %din _sys_nic_start()"455 " get NIC chbuf paddr = %l\n",456 thread , vspace, nic_chbuf_pbase );481 _printf("\n[GIET DEBUG NIC] Task %d in _sys_nic_start()" 482 " get NIC chbuf : paddr = %l\n", 483 thread , nic_chbuf_pbase ); 457 484 #endif 458 485 … … 460 487 if ( is_rx ) vaddr = (unsigned int)( &_nic_rx_chbuf[nic_channel] ); 461 488 else vaddr = (unsigned int)( &_nic_tx_chbuf[nic_channel] ); 462 ko = _v2p_translate( (page_table_t*)ptab, 463 vaddr>>12, 464 &ppn, 465 &flags ); 466 if ( ko ) 467 { 468 _puts("\n[GIET ERROR] in _sys_nic_start() : kernel chbuf unmapped\n"); 469 return -1; 470 } 489 _v2p_translate( (page_table_t*)ptab, 490 vaddr>>12, 491 &ppn, 492 &flags ); 471 493 ker_chbuf_pbase = (((unsigned long long)ppn) << 12) | (vaddr & 0x00000FFF); 472 494 473 495 #if GIET_DEBUG_NIC 474 _printf("\n[GIET DEBUG NIC] Task %d of vspace %d in _sys_nic_start()" 475 " get kernel chbuf paddr = %l\n", 476 thread, vspace, ker_chbuf_pbase ); 477 #endif 478 479 // compute the container array physical address 480 if ( is_rx ) vaddr = ((unsigned int)&_nic_rx_cont[0][0][nic_channel]); 481 else vaddr = ((unsigned int)&_nic_tx_cont[0][0][nic_channel]); 482 ko = _v2p_translate( (page_table_t*)ptab, 483 vaddr>>12, 484 &ppn, 485 &flags ); 486 if ( ko ) 487 { 488 _puts("\n[GIET ERROR] in _sys_nic_start() : containers array unmapped\n"); 489 return -1; 490 } 491 ker_cont_pbase = (((unsigned long long)ppn) << 12) | (vaddr & 0x00000FFF); 492 493 #if GIET_DEBUG_NIC 494 _printf("\n[GIET DEBUG NIC] Task %d of vspace %d in _sys_nic_start()" 495 " get kernel containers array paddr = %l\n", 496 thread, vspace, ker_cont_pbase ); 497 #endif 498 499 // initializes the kernel chbuf descriptor 500 unsigned int index; 501 if ( is_rx ) 502 { 503 _spin_lock_init( &_nic_rx_lock[nic_channel] ); 504 _nic_rx_chbuf[nic_channel].index = 0; 505 for( index = 0 ; index < GIET_NIC_NBUFS ; index++ ) 506 { 507 _nic_rx_chbuf[nic_channel].buffer[index] = ker_cont_pbase + (index<<12); 508 } 509 } 510 else 511 { 512 _spin_lock_init( &_nic_tx_lock[nic_channel] ); 513 _nic_tx_chbuf[nic_channel].index = 0; 514 for( index = 0 ; index < GIET_NIC_NBUFS ; index++ ) 515 { 516 _nic_tx_chbuf[nic_channel].buffer[index] = ker_cont_pbase + (index<<12); 517 } 518 } 496 _printf("\n[GIET DEBUG NIC] Task %d in _sys_nic_start()" 497 " get kernel chbuf : vaddr = %x / paddr = %l\n", 498 thread , vaddr , ker_chbuf_pbase ); 499 #endif 519 500 520 501 // sync the kernel chbuf in L2 after write in L2 … … 529 510 _cma_set_register( cma_channel, CHBUF_DST_DESC , (unsigned int)(ker_chbuf_pbase) ); 530 511 _cma_set_register( cma_channel, CHBUF_DST_EXT , (unsigned int)(ker_chbuf_pbase>>32) ); 531 _cma_set_register( cma_channel, CHBUF_DST_NBUFS, GIET_NIC_NBUFS);512 _cma_set_register( cma_channel, CHBUF_DST_NBUFS, X_SIZE*Y_SIZE ); 532 513 } 533 514 else // kernel to NIC … … 535 516 _cma_set_register( cma_channel, CHBUF_SRC_DESC , (unsigned int)(ker_chbuf_pbase) ); 536 517 _cma_set_register( cma_channel, CHBUF_SRC_EXT , (unsigned int)(ker_chbuf_pbase>>32) ); 537 _cma_set_register( cma_channel, CHBUF_SRC_NBUFS, GIET_NIC_NBUFS);518 _cma_set_register( cma_channel, CHBUF_SRC_NBUFS, X_SIZE*Y_SIZE ); 538 519 _cma_set_register( cma_channel, CHBUF_DST_DESC , (unsigned int)(nic_chbuf_pbase) ); 539 520 _cma_set_register( cma_channel, CHBUF_DST_EXT , (unsigned int)(nic_chbuf_pbase>>32) ); … … 542 523 543 524 // start CMA transfer 544 _cma_set_register( cma_channel, CHBUF_BUF_SIZE , 4096);545 _cma_set_register( cma_channel, CHBUF_PERIOD , 300 );525 _cma_set_register( cma_channel, CHBUF_BUF_SIZE , NIC_CONTAINER_SIZE ); 526 _cma_set_register( cma_channel, CHBUF_PERIOD , 0 ); // OUT_OF_ORDER mode 546 527 _cma_set_register( cma_channel, CHBUF_RUN , 1 ); 547 528 … … 550 531 551 532 #if GIET_DEBUG_NIC 552 _printf("\n[GIET DEBUG NIC] Task %d of vspace %d exit _sys_nic_start()\n",553 thread , vspace);533 _printf("\n[GIET DEBUG NIC] Task %d exit _sys_nic_start() at cycle %d\n", 534 thread , _get_proctime() ); 554 535 #endif 555 536 … … 565 546 #if GIET_DEBUG_NIC 566 547 unsigned int thread = _get_context_slot( CTX_TRDID_ID ); 567 unsigned int vspace = _get_context_slot( CTX_VSID_ID ); 568 _printf("\n[GIET DEBUG NIC] Task %d of vspace %d enters _sys_nic_move()\n", 569 thread, vspace ); 570 #endif 571 548 _printf("\n[GIET DEBUG NIC] Task %d enters _sys_nic_move() at cycle %d\n", 549 thread , _get_proctime() ); 550 #endif 551 552 // get cluster coordinates for the processor running the calling task 553 unsigned int procid = _get_procid(); 554 unsigned int cx = procid >> (Y_WIDTH + P_WIDTH); 555 unsigned int cy = (procid >> P_WIDTH) & ((1<<Y_WIDTH)-1); 556 572 557 unsigned long long user_buffer_paddr; // user buffer physical address 573 558 unsigned long long kernel_buffer_paddr; // kernel buffer physical address 574 559 unsigned long long kernel_chbuf_paddr; // kernel chbuf physical address 575 unsigned long long kernel_buffer_desc; // kernel buffer descriptor 560 unsigned long long buffer_desc; // kernel buffer descriptor 561 unsigned long long buffer_desc_paddr; // kernel buffer descriptor physical address 562 unsigned int index; // kernel buffer index in chbuf 576 563 577 564 // The following variables are used for V2P translation … … 580 567 unsigned int flags; 581 568 unsigned int vaddr; 582 unsigned int ko;583 569 584 570 // Compute user buffer physical address and check access rights 585 571 vaddr = (unsigned int)buffer; 586 ko = _v2p_translate( (page_table_t*)ptab, 587 vaddr>>12, 588 &ppn, 589 &flags ); 590 if ( ko ) 591 { 592 _printf("\n[GIET ERROR] in _sys_nic_move() : user buffer unmapped\n"); 593 return -1; 594 } 572 _v2p_translate( (page_table_t*)ptab, 573 vaddr>>12, 574 &ppn, 575 &flags ); 576 595 577 if ( (flags & PTE_U) == 0 ) 596 578 { … … 601 583 602 584 #if GIET_DEBUG_NIC 603 _printf("\n[GIET DEBUG NIC] Task %d of vspace %d in _sys_nic_move()" 604 " get user buffer paddr = %l\n", 605 thread, vspace, user_buffer_paddr ); 585 _printf("\n[GIET DEBUG NIC] Task %d in _sys_nic_move() get user buffer : paddr = %l\n", 586 thread, user_buffer_paddr ); 606 587 #endif 607 588 … … 613 594 } 614 595 615 // get kernel chbuf and lock addresses596 // get kernel chbuf virtual address 616 597 nic_chbuf_t* chbuf; 617 spin_lock_t* lock; 618 619 if ( is_rx ) 620 { 621 chbuf = &_nic_rx_chbuf[channel]; 622 lock = &_nic_rx_lock[channel]; 623 } 624 else 625 { 626 chbuf = &_nic_tx_chbuf[channel]; 627 lock = &_nic_tx_lock[channel]; 628 } 598 if ( is_rx ) chbuf = &_nic_rx_chbuf[channel]; 599 else chbuf = &_nic_tx_chbuf[channel]; 629 600 630 601 // compute kernel chbuf physical address (required for sync) 631 602 vaddr = (unsigned int)chbuf; 632 ko = _v2p_translate( (page_table_t*)ptab, 633 vaddr>>12, 634 &ppn, 635 &flags ); 636 if ( ko ) 637 { 638 _printf("\n[GIET ERROR] in _sys_nic_move() : kernel chbuf unmapped\n"); 639 return -1; 640 } 603 _v2p_translate( (page_table_t*)ptab, 604 vaddr>>12, 605 &ppn, 606 &flags ); 641 607 kernel_chbuf_paddr = ((unsigned long long)ppn << 12) | (vaddr & 0x00000FFF); 642 608 643 // get the lock protecting the chbuf 644 _spin_lock_acquire( lock ); 645 646 // polling on the kernel chbuf status 647 unsigned int full; 648 unsigned int ok = 0; 649 unsigned int index = chbuf->index; 650 unsigned int timeout = GIET_NIC_TIMEOUT; 651 while( ok == 0 ) 652 { 653 // inval kernel chbuf in L2 before read in L2 654 _mmc_inval( kernel_chbuf_paddr, sizeof( nic_chbuf_t ) ); 655 656 // get kernel buffer descriptor 657 kernel_buffer_desc = chbuf->buffer[index]; 609 // poll chbuf until success 610 while ( 1 ) 611 { 612 // compute buffer index and buffer descriptor paddr 613 index = (Y_SIZE * cx) + cy; 614 buffer_desc_paddr = kernel_chbuf_paddr + (index<<6); 615 616 // inval buffer descriptor in L2 before read in L2 617 _mmc_inval( buffer_desc_paddr , 8 ); 618 buffer_desc = chbuf->buffer[index].desc; 658 619 659 620 #if GIET_DEBUG_NIC 660 _printf("\n[GIET DEBUG NIC] Task %d of vspace %d in _sys_nic_move()" 661 " poll kernel container descriptor = %l\n", 662 thread, vspace, kernel_buffer_desc ); 663 #endif 664 665 full = kernel_buffer_desc >> 63; 666 if ( (is_rx && full) || ((is_rx == 0) && (full == 0)) ) ok = 1; 667 else timeout--; 668 669 if ( timeout == 0 ) 670 { 671 _printf("\n[GIET_ERROR] in _sys_nic_move() : timeout\n"); 672 return -1; 673 } 621 _printf("\n[GIET DEBUG NIC] Task %d in _sys_nic_move() read buffer descriptor %d\n" 622 " at cycle = %d / paddr = %l / buffer descriptor = %l\n", 623 thread, index, _get_proctime(), buffer_desc_paddr, buffer_desc ); 624 #endif 625 626 // test buffer status and break if found 627 if ( ( is_rx != 0 ) && (buffer_desc >> 63) == 1 ) break; 628 if ( ( is_rx == 0 ) && (buffer_desc >> 63) == 0 ) break; 674 629 } 675 630 676 631 // compute kernel buffer physical address 677 kernel_buffer_paddr = kernel_buffer_desc & 0x0000FFFFFFFFFFFFULL;632 kernel_buffer_paddr = buffer_desc & 0x0000FFFFFFFFFFFFULL; 678 633 679 634 // move one container, using a physical_memcpy 680 // We must maintain L2/L3 cache coherence681 635 if ( is_rx ) 682 636 { 683 637 // inval kernel buffer in L2 before read in L2 684 _mmc_inval( kernel_buffer_paddr, GIET_NIC_BUFSIZE );638 _mmc_inval( kernel_buffer_paddr, NIC_CONTAINER_SIZE ); 685 639 686 640 // transfer data from kernel buffer to user buffer 687 641 _physical_memcpy( user_buffer_paddr, 688 642 kernel_buffer_paddr, 689 GIET_NIC_BUFSIZE ); 643 NIC_CONTAINER_SIZE ); 644 #if GIET_DEBUG_NIC 645 _printf("\n[GIET DEBUG NIC] Task %d in _sys_nic_move() transfer " 646 "kernel buffer %l to user buffer %l at cycle %d\n", 647 thread , kernel_buffer_paddr , user_buffer_paddr , _get_proctime() ); 648 #endif 690 649 691 650 } … … 695 654 _physical_memcpy( kernel_buffer_paddr, 696 655 user_buffer_paddr, 697 GIET_NIC_BUFSIZE );656 NIC_CONTAINER_SIZE ); 698 657 699 658 // sync kernel buffer in L2 after write in L2 700 _mmc_sync( kernel_buffer_paddr, GIET_NIC_BUFSIZE ); 701 } 702 703 // update kernel chbuf status and index 704 if ( is_rx ) chbuf->buffer[index] = kernel_buffer_paddr & 0x0000FFFFFFFFFFFFULL; 705 else chbuf->buffer[index] = kernel_buffer_paddr | 0x8000000000000000ULL; 706 707 if ( index == (GIET_NIC_NBUFS - 1) ) chbuf->index = 0; 708 else chbuf->index = index + 1; 659 _mmc_sync( kernel_buffer_paddr, NIC_CONTAINER_SIZE ); 660 661 #if GIET_DEBUG_NIC 662 _printf("\n[GIET DEBUG NIC] Task %d in _sys_nic_move() transfer " 663 "user buffer %l to kernel buffer %l at cycle %d\n", 664 thread , user_buffer_paddr , kernel_buffer_paddr , _get_proctime() ); 665 #endif 666 667 } 668 669 // update kernel chbuf status 670 if ( is_rx ) chbuf->buffer[index].desc = kernel_buffer_paddr & 0x0000FFFFFFFFFFFFULL; 671 else chbuf->buffer[index].desc = kernel_buffer_paddr | 0x8000000000000000ULL; 709 672 710 673 // sync kernel chbuf in L2 after write in L2 711 _mmc_sync( kernel_chbuf_paddr, sizeof( nic_chbuf_t ) ); 712 713 // release the lock protecting the chbuf 714 _spin_lock_release( lock ); 715 674 _mmc_sync( kernel_chbuf_paddr + (index<<6) , 8 ); 675 716 676 #if GIET_DEBUG_NIC 717 _printf("\n[GIET DEBUG NIC] Task %d of vspace %d exit _sys_nic_move()\n",718 thread , vspace);677 _printf("\n[GIET DEBUG NIC] Task %d get buffer %d and exit _sys_nic_move() at cycle %d\n", 678 thread , index , _get_proctime() ); 719 679 #endif 720 680 … … 822 782 unsigned int fifo_full = _nic_get_global_register( NIC_G_NPKT_RX_DES_MFIFO_FULL ); 823 783 unsigned int crc_fail = _nic_get_global_register( NIC_G_NPKT_RX_DES_CRC_FAIL ); 824 unsigned int transmit = _nic_get_global_register( NIC_G_NPKT_RX_DISPATCH_RECEIVED );825 784 unsigned int broadcast = _nic_get_global_register( NIC_G_NPKT_RX_DISPATCH_BROADCAST ); 826 785 unsigned int dst_fail = _nic_get_global_register( NIC_G_NPKT_RX_DISPATCH_DST_FAIL ); … … 829 788 _printf("\n### Network Controller RX Statistics ###\n" 830 789 "- packets received : %d\n" 831 "- packets transmit : %d\n"832 790 "- too small : %d\n" 833 791 "- too big : %d\n" … … 838 796 "- broadcast : %d\n", 839 797 received, 840 transmit,841 798 too_small, 842 799 too_big, … … 850 807 { 851 808 unsigned int received = _nic_get_global_register( NIC_G_NPKT_TX_DISPATCH_RECEIVED ); 852 unsigned int transmit = _nic_get_global_register( NIC_G_NPKT_TX_DISPATCH_TRANSMIT );853 809 unsigned int too_big = _nic_get_global_register( NIC_G_NPKT_TX_DISPATCH_TOO_BIG ); 854 810 unsigned int too_small = _nic_get_global_register( NIC_G_NPKT_TX_DISPATCH_TOO_SMALL ); … … 859 815 _printf("\n### Network Controller TX Statistics ###\n" 860 816 "- packets received : %d\n" 861 "- packets transmit : %d\n"862 817 "- too small : %d\n" 863 818 "- too big : %d\n" … … 866 821 "- broadcast : %d\n", 867 822 received, 868 transmit,869 823 too_big, 870 824 too_small, … … 880 834 ///////////////////////////////////////////////////////////////////////////////////////// 881 835 882 // Array of fbf_chbuf descriptors, indexed by the CMA channel index.883 __attribute__((section (".unckdata")))884 volatile fbf_chbuf_t _fbf_chbuf[NB_CMA_CHANNELS] __attribute__((aligned(32)));885 886 // Physical addresses of these fbf_chbuf descriptors (required for L2 cache sync)887 __attribute__((section (".unckdata")))888 unsigned long long _fbf_chbuf_paddr[NB_CMA_CHANNELS];889 890 836 ///////////////////////////////////////////// 891 837 int _sys_fbf_sync_write( unsigned int offset, … … 940 886 941 887 unsigned int ptab; // page table virtual address 942 unsigned int ko; // unsuccessfull V2P translation943 888 unsigned int vaddr; // virtual address 944 889 unsigned int flags; // protection flags … … 979 924 // compute frame buffer physical address and initialize _fbf_chbuf[channel] 980 925 vaddr = ((unsigned int)SEG_FBF_BASE); 981 ko = _v2p_translate( (page_table_t*) ptab, 982 (vaddr >> 12), 983 &ppn, 984 &flags ); 985 if (ko) 986 { 987 _printf("\n[GIET ERROR] in _fb_cma_start() : frame buffer unmapped\n"); 988 return -1; 989 } 990 991 _fbf_chbuf[channel].fbf = ((paddr_t)ppn << 12) | (vaddr & 0x00000FFF); 926 _v2p_translate( (page_table_t*) ptab, 927 (vaddr >> 12), 928 &ppn, 929 &flags ); 930 931 _fbf_chbuf[channel].fbf.desc = ((paddr_t)ppn << 12) | (vaddr & 0x00000FFF); 992 932 993 933 // Compute user buffer 0 physical addresses and intialize _fbf_chbuf[channel] 994 934 vaddr = (unsigned int)vbase0; 995 ko = _v2p_translate( (page_table_t*) ptab, 996 (vaddr >> 12), 997 &ppn, 998 &flags ); 999 if (ko) 1000 { 1001 _printf("\n[GIET ERROR] in _fbf_cma_start() : user buffer 0 unmapped\n"); 1002 return -1; 1003 } 935 _v2p_translate( (page_table_t*) ptab, 936 (vaddr >> 12), 937 &ppn, 938 &flags ); 1004 939 if ((flags & PTE_U) == 0) 1005 940 { … … 1008 943 } 1009 944 1010 _fbf_chbuf[channel].buf0 = ((paddr_t)ppn << 12) | (vaddr & 0x00000FFF);945 _fbf_chbuf[channel].buf0.desc = ((paddr_t)ppn << 12) | (vaddr & 0x00000FFF); 1011 946 1012 947 // Compute user buffer 1 physical addresses and intialize _fbf_chbuf[channel] 1013 948 vaddr = (unsigned int)vbase1; 1014 ko = _v2p_translate( (page_table_t*) ptab, 1015 (vaddr >> 12), 1016 &ppn, 1017 &flags ); 1018 if (ko) 1019 { 1020 _printf("\n[GIET ERROR] in _fbf_cma_start() : user buffer 1 unmapped\n"); 1021 return -1; 1022 } 949 _v2p_translate( (page_table_t*) ptab, 950 (vaddr >> 12), 951 &ppn, 952 &flags ); 1023 953 if ((flags & PTE_U) == 0) 1024 954 { … … 1027 957 } 1028 958 1029 _fbf_chbuf[channel].buf1 = ((paddr_t)ppn << 12) | (vaddr & 0x00000FFF);959 _fbf_chbuf[channel].buf1.desc = ((paddr_t)ppn << 12) | (vaddr & 0x00000FFF); 1030 960 1031 961 // initializes buffer length … … 1034 964 // Compute and register physical adress of the chbuf descriptor 1035 965 vaddr = (unsigned int)(&_fbf_chbuf[channel]); 1036 ko = _v2p_translate( (page_table_t*) ptab, 1037 (vaddr >> 12), 1038 &ppn, 1039 &flags ); 1040 if (ko) 1041 { 1042 _printf("\n[GIET ERROR] in _fbf_cma_start() : chbuf descriptor unmapped\n"); 1043 return -1; 1044 } 966 _v2p_translate( (page_table_t*) ptab, 967 (vaddr >> 12), 968 &ppn, 969 &flags ); 1045 970 1046 971 chbuf_paddr = (((paddr_t)ppn) << 12) | (vaddr & 0x00000FFF); … … 1060 985 " - buf1 pbase = %l\n" 1061 986 " - chbuf pbase = %l\n", 1062 _fbf_chbuf[channel].fbf ,1063 _fbf_chbuf[channel].buf0 ,1064 _fbf_chbuf[channel].buf1 ,987 _fbf_chbuf[channel].fbf.desc, 988 _fbf_chbuf[channel].buf0.desc, 989 _fbf_chbuf[channel].buf1.desc, 1065 990 chbuf_paddr ); 1066 991 #endif … … 1070 995 chbuf_paddr, 1071 996 2, 1072 chbuf_paddr + 1 6,997 chbuf_paddr + 128, 1073 998 1, 1074 999 length ); … … 1088 1013 #if NB_CMA_CHANNELS > 0 1089 1014 1090 volatile paddr_t buf_paddr;1091 unsigned intfull = 1;1015 volatile unsigned int long long user_buffer_desc; 1016 volatile unsigned int full = 1; 1092 1017 1093 1018 // get channel index … … 1107 1032 #endif 1108 1033 1109 // waiting user buffer empty 1110 while ( full ) 1111 { 1112 if ( USE_IOB ) 1113 { 1114 // INVAL L1 cache for the chbuf descriptor, 1115 _dcache_buf_invalidate( (unsigned int)&_fbf_chbuf[channel], 32 ); 1116 1117 // INVAL L2 cache for the chbuf descriptor, 1118 _mmc_inval( _fbf_chbuf_paddr[channel], 32 ); 1034 if ( buffer_index == 0 ) // user buffer 0 1035 { 1036 // waiting user buffer released by the CMA component) 1037 while ( full ) 1038 { 1039 // INVAL L1 and L2 cache copies of user buffer descriptor, because 1040 // it has been modified in RAM by the CMA component 1041 _dcache_buf_invalidate( (unsigned int)&_fbf_chbuf[channel].buf0.desc , 8 ); 1042 _mmc_inval( _fbf_chbuf_paddr[channel] , 8 ); 1043 1044 // get user buffer descriptor 1045 user_buffer_desc = _fbf_chbuf[channel].buf0.desc; 1046 1047 // get user buffer descriptor status 1048 full = ( (unsigned int)(user_buffer_desc>>63) ); 1119 1049 } 1120 1050 1121 // read user buffer descriptor1122 if ( buffer_index == 0 ) buf_paddr = _fbf_chbuf[channel].buf0;1123 else buf_paddr = _fbf_chbuf[channel].buf1;1124 1125 full = ( (unsigned int)(buf_paddr>>63) );1126 }1127 1128 if ( USE_IOB )1129 {1130 1051 // SYNC request for the user buffer, because 1131 1052 // it will be read from XRAM by the CMA component 1132 _mmc_sync( buf_paddr, _fbf_chbuf[channel].length ); 1133 } 1134 1135 // set user buffer status 1136 if ( buffer_index == 0 ) _fbf_chbuf[channel].buf0 = buf_paddr | 0x8000000000000000ULL; 1137 else _fbf_chbuf[channel].buf1 = buf_paddr | 0x8000000000000000ULL; 1138 1139 // reset fbf buffer status 1140 _fbf_chbuf[channel].fbf = _fbf_chbuf[channel].fbf & 0x7FFFFFFFFFFFFFFFULL; 1141 1142 if ( USE_IOB ) 1143 { 1144 // SYNC request for the channel descriptor, because 1053 _mmc_sync( user_buffer_desc, _fbf_chbuf[channel].length ); 1054 1055 // set user buffer status, and SYNC request, because this buffer 1056 // descriptor will be read from XRAM by the CMA component 1057 _fbf_chbuf[channel].buf0.desc = user_buffer_desc | 0x8000000000000000ULL; 1058 _mmc_sync( _fbf_chbuf_paddr[channel] , 8 ); 1059 1060 // reset fbf buffer status, and SYNC request, because this buffer 1061 // descriptor will be read from XRAM by the CMA component 1062 _fbf_chbuf[channel].fbf.desc = _fbf_chbuf[channel].fbf.desc & 0x7FFFFFFFFFFFFFFFULL; 1063 _mmc_sync( _fbf_chbuf_paddr[channel] + 128 , 8 ); 1064 } 1065 else // user buffer 1 1066 { 1067 // waiting user buffer released by the CMA component) 1068 while ( full ) 1069 { 1070 // INVAL L1 and L2 cache copies of user buffer descriptor, because 1071 // it has been modified in RAM by the CMA component 1072 _dcache_buf_invalidate( (unsigned int)&_fbf_chbuf[channel].buf1.desc , 8 ); 1073 _mmc_inval( _fbf_chbuf_paddr[channel] + 64 , 8 ); 1074 1075 // get user buffer descriptor 1076 user_buffer_desc = _fbf_chbuf[channel].buf1.desc; 1077 1078 // get user buffer descriptor status 1079 full = ( (unsigned int)(user_buffer_desc>>63) ); 1080 } 1081 1082 // SYNC request for the user buffer, because 1145 1083 // it will be read from XRAM by the CMA component 1146 _mmc_sync( _fbf_chbuf_paddr[channel], 32 ); 1084 _mmc_sync( user_buffer_desc, _fbf_chbuf[channel].length ); 1085 1086 // set user buffer status, and SYNC request, because this buffer 1087 // descriptor will be read from XRAM by the CMA component 1088 _fbf_chbuf[channel].buf1.desc = user_buffer_desc | 0x8000000000000000ULL; 1089 _mmc_sync( _fbf_chbuf_paddr[channel] , 8 ); 1090 1091 // reset fbf buffer status, and SYNC request, because this buffer 1092 // descriptor will be read from XRAM by the CMA component 1093 _fbf_chbuf[channel].fbf.desc = _fbf_chbuf[channel].fbf.desc & 0x7FFFFFFFFFFFFFFFULL; 1094 _mmc_sync( _fbf_chbuf_paddr[channel] + 128 , 8 ); 1147 1095 } 1148 1096 1149 1097 #if GIET_DEBUG_FBF_CMA 1150 _printf(" - fbf pbase = %l\n" 1151 " - buf0 pbase = %l\n" 1152 " - buf1 pbase = %l\n", 1153 _fbf_chbuf[channel].fbf, 1154 _fbf_chbuf[channel].buf0, 1155 _fbf_chbuf[channel].buf1 ); 1156 #endif 1157 1098 _printf(" - fbf desc = %l\n" 1099 " - buf0 desc = %l\n" 1100 " - buf1 desc = %l\n", 1101 _fbf_chbuf[channel].fbf.desc, 1102 _fbf_chbuf[channel].buf0.desc, 1103 _fbf_chbuf[channel].buf1.desc ); 1104 #endif 1158 1105 1159 1106 return 0; … … 1166 1113 #endif 1167 1114 } // end _sys_fbf_cma_display() 1115 1168 1116 1169 1117 /////////////////////// … … 1368 1316 unsigned int* y ) 1369 1317 { 1370 unsigned int ret;1371 1318 unsigned int ppn; 1372 1319 unsigned int flags; … … 1377 1324 1378 1325 // compute the physical address 1379 if ( (ret = _v2p_translate( pt, vpn, &ppn, &flags )) ) return -1;1326 _v2p_translate( pt, vpn, &ppn, &flags ); 1380 1327 1381 1328 *x = (ppn>>24) & 0xF; -
soft/giet_vm/giet_kernel/sys_handler.h
r467 r478 16 16 #include "locks.h" 17 17 18 #if !defined ( GIET_NIC_NBUFS )19 # error: You must define GIET_NIC_NBUFS in the giet_config.h file20 #endif21 22 #if !defined ( GIET_NIC_NFAKE )23 # error: You must define GIET_NIC_NFAKE in the giet_config.h file24 #endif25 26 #if !defined ( GIET_NIC_BUFSIZE )27 # error: You must define GIET_NIC_BUFSIZE in the giet_config.h file28 #endif29 30 #if !defined ( GIET_NIC_TIMEOUT )31 # error: You must define GIET_NIC_TIMEOUT in the giet_config.h file32 #endif33 34 #if !defined ( GIET_NIC_MAC4 )35 # error: You must define GIET_NIC_MAC4 in the giet_config.h file36 #endif37 38 #if !defined ( GIET_NIC_MAC2 )39 # error: You must define GIET_NIC_MAC2 in the giet_config.h file40 #endif41 42 #if ( (GIET_NIC_NBUFS + GIET_NIC_NFAKE) % 8 )43 #error: GIET_NIC_NBUFS + GIET_NIC_NFAKE must be multiple of 8 for alignment44 #endif45 46 18 /////////////////////////////////////////////////////////////////////////////////// 47 19 // Syscall Vector Table (indexed by syscall index) … … 51 23 52 24 /////////////////////////////////////////////////////////////////////////////////// 25 // This structure is used by the nic_chbuf_t and fbf_chbuf_t structures. 26 // It describes a single buffer descriptor. The useful information is contained 27 // in one single 64 bits word (desc field): 28 // - the 48 LSB bits contain the buffer physical address 29 // - the MSB bit 63 indicates the buffer state (empty if 0) 30 // This descriptor must be aligned on a cache line (64 bytes) to simplify 31 // the software L2/L3 cache coherence when the IO bridge is used. 32 /////////////////////////////////////////////////////////////////////////////////// 33 34 typedef struct buffer_descriptor_s 35 { 36 unsigned long long desc; 37 unsigned int padding[14]; 38 } buffer_descriptor_t; 39 40 /////////////////////////////////////////////////////////////////////////////////// 53 41 // This structure is used by the CMA component to move a stream 54 // of images from two buffers in user spaceto the frame buffer in kernel space.42 // of images from two user buffers to the frame buffer in kernel space. 55 43 // it must be 64 bytes aligned. 56 44 // It contains two chbuf arrays: 57 // - The SRC chbuf contains two buffers (buf0 & buf1), that can bein user space.45 // - The SRC chbuf contains two buffers (buf0 & buf1), in user space. 58 46 // - The DST cbuf contains one single buffer (fbf), that is the frame buffer. 59 47 // - The length field define the buffer size (bytes) … … 62 50 typedef struct fbf_chbuf_s 63 51 { 64 unsigned long long buf0; // physical address + status for user buffer 065 unsigned long long buf1; // physical address + status for user buffer 166 unsigned long long fbf; // physical address + status for user buffer 067 unsigned int length;// buffer length (bytes)68 unsigned int padding[9]; // padding for 64 bytes alignment52 buffer_descriptor_t buf0; // first user buffer descriptor 53 buffer_descriptor_t buf1; // second user buffer descriptor 54 buffer_descriptor_t fbf; // frame buffer descriptor 55 unsigned int length; // buffer length (bytes) 56 unsigned int padding[15]; // padding for 64 bytes alignment 69 57 } fbf_chbuf_t; 70 58 71 59 ////////////////////////////////////////////////////////////////////////////////// 72 // This structure is used by the CMA component to move a stream 73 // of packet containers between the NIC component an a chbuf containing74 // a variable number of buffers in kernel space.60 // This structure is used by the CMA component to move a stream of containers 61 // between the NIC chbuf containing 2 buffers, and a kernel chbuf 62 // containing (X_SIZE * Y_SIZE) buffers (one buffer per cluster). 75 63 // The same structure is used for both TX or RX transfers. 76 64 // It must be 64 bytes aligned. 77 // The single buffer size and the number of buffers must be defined by the78 // GIET_NIC_BUFSIZE and GIET_NIC_NBUFS parameters in giet_config.h.79 // - The buffer array implements the chbuf, and is concurently accessed80 // by the CMA component and by the kernel code.81 // - The lock must be taken by the kernel code, because several user tasks82 // can concurently try to consume buffers in the chbuf.83 // - The index is only used by the kernel, and define the currently pointed84 // buffer for read (RX transfer) or write (TX transfer).85 65 ////////////////////////////////////////////////////////////////////////////////// 86 66 87 67 typedef struct nic_chbuf_s 88 68 { 89 unsigned long long buffer[GIET_NIC_NBUFS]; // Kernel chbuf 90 unsigned long long unused[GIET_NIC_NFAKE]; // padding for 64 bytes alignment 91 unsigned int index; // current buffer index 92 unsigned int padding[15]; // padding for 64 bytes alignment 69 buffer_descriptor_t buffer[X_SIZE*Y_SIZE]; // kernel chbuf 93 70 } nic_chbuf_t; 94 95 71 96 72 //////////////////////////////////////////////////////////////////////////////////
Note: See TracChangeset
for help on using the changeset viewer.