Changeset 494 for soft/giet_vm/giet_kernel/sys_handler.c
- Timestamp:
- Feb 8, 2015, 12:50:23 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/giet_kernel/sys_handler.c
r489 r494 65 65 //////////////////////////////////////////////////////////////////////////// 66 66 67 __attribute__((section(".kdata"))) 67 68 unsigned int _tty_channel_allocator = 1; 69 70 __attribute__((section(".kdata"))) 68 71 unsigned int _tim_channel_allocator = 0; 72 73 __attribute__((section(".kdata"))) 69 74 unsigned int _cma_channel_allocator = 0; 75 76 __attribute__((section(".kdata"))) 70 77 unsigned int _nic_rx_channel_allocator = 0; 78 79 __attribute__((section(".kdata"))) 71 80 unsigned int _nic_tx_channel_allocator = 0; 81 82 //////////////////////////////////////////////////////////////////////////// 83 // These global variables is defined in tty0.c and tty_driver.c files. 84 //////////////////////////////////////////////////////////////////////////// 85 86 extern sqt_lock_t _tty0_sqt_lock; 87 88 extern unsigned int _tty_rx_full[NB_TTY_CHANNELS]; 89 90 extern unsigned int _tty_rx_buf[NB_TTY_CHANNELS]; 72 91 73 92 //////////////////////////////////////////////////////////////////////////// … … 75 94 //////////////////////////////////////////////////////////////////////////// 76 95 96 __attribute__((section(".kdata"))) 77 97 nic_chbuf_t _nic_rx_chbuf[NB_NIC_CHANNELS] __attribute__((aligned(64))); 78 98 99 __attribute__((section(".kdata"))) 79 100 nic_chbuf_t _nic_tx_chbuf[NB_NIC_CHANNELS] __attribute__((aligned(64))); 80 101 … … 84 105 //////////////////////////////////////////////////////////////////////////// 85 106 107 __attribute__((section(".kdata"))) 86 108 fbf_chbuf_t _fbf_chbuf[NB_CMA_CHANNELS] __attribute__((aligned(64))); 87 109 110 __attribute__((section(".kdata"))) 88 111 unsigned long long _fbf_chbuf_paddr[NB_CMA_CHANNELS]; 89 112 … … 92 115 // Note: This array must be synchronised with the define in file stdio.h 93 116 //////////////////////////////////////////////////////////////////////////// 117 118 __attribute__((section(".kdata"))) 94 119 const void * _syscall_vector[64] = 95 120 { … … 241 266 242 267 /////////////////////////////////////////// 243 int _sys_tty_get_lock( unsigned int channel, 268 int _sys_tty_get_lock( unsigned int channel, // unused 244 269 unsigned int * save_sr_ptr ) 245 270 { 246 // compute and check tty channel 247 if( channel == 0xFFFFFFFF ) channel = _get_context_slot(CTX_TTY_ID); 248 if( channel >= NB_TTY_CHANNELS ) return -1; 271 // check tty channel 272 if( channel != 0 ) return 1; 249 273 250 274 _it_disable( save_sr_ptr ); 251 _s bt_lock_acquire( &_tty_tx_lock[channel]);275 _sqt_lock_acquire( &_tty0_sqt_lock ); 252 276 return 0; 253 277 } … … 257 281 unsigned int * save_sr_ptr ) 258 282 { 259 // compute and check tty channel 260 if( channel == 0xFFFFFFFF ) channel = _get_context_slot(CTX_TTY_ID); 261 if( channel >= NB_TTY_CHANNELS ) return -1; 262 263 _sbt_lock_release( &_tty_tx_lock[channel] ); 283 // check tty channel 284 if( channel != 0 ) return 1; 285 286 _sqt_lock_release( &_tty0_sqt_lock ); 264 287 _it_restore( save_sr_ptr ); 265 288 return 0; … … 332 355 #define NIC_CONTAINER_SIZE 4096 333 356 334 /////////////////////////////////////////// 335 int _sys_nic_alloc( unsigned int is_rx ) 336 { 357 //////////////////////////////////////// 358 int _sys_nic_alloc( unsigned int is_rx, 359 unsigned int xmax, 360 unsigned int ymax ) 361 { 362 // check xmax / ymax parameters 363 if ( xmax > X_SIZE ) 364 { 365 _printf("\n[GIET_ERROR] in _sys_nic_alloc() xmax argument too large\n"); 366 return -1; 367 } 368 if ( ymax > Y_SIZE ) 369 { 370 _printf("\n[GIET_ERROR] in _sys_nic_alloc() ymax argument too large\n"); 371 return -1; 372 } 373 374 // get a NIC_RX or NIC_TX channel index 375 unsigned int nic_channel; 376 unsigned int cma_channel; 377 378 if ( is_rx ) nic_channel = _atomic_increment( &_nic_rx_channel_allocator, 1 ); 379 else nic_channel = _atomic_increment( &_nic_tx_channel_allocator, 1 ); 380 381 if ( (nic_channel >= NB_NIC_CHANNELS) ) 382 { 383 _printf("\n[GIET_ERROR] in _sys_nic_alloc() not enough NIC channels\n"); 384 return -1; 385 } 386 387 // get a CMA channel index 388 cma_channel = _atomic_increment( &_cma_channel_allocator, 1 ); 389 390 if ( cma_channel >= NB_CMA_CHANNELS ) 391 { 392 _printf("\n[GIET_ERROR] in _sys_nic_alloc() not enough CMA channels\n"); 393 return -1; 394 } 337 395 338 396 #if GIET_DEBUG_NIC 339 397 unsigned int thread = _get_context_slot( CTX_TRDID_ID ); 340 _printf("\n[GIET DEBUG NIC] Task %d enters sys_nic_alloc() at cycle %d\n", 341 thread, _get_proctime() ); 342 #endif 343 344 unsigned int nic_channel; 345 unsigned int cma_channel; 346 347 // get a NIC_RX or NIC_TX channel index 348 if ( is_rx ) nic_channel = _atomic_increment( &_nic_rx_channel_allocator, 1 ); 349 else nic_channel = _atomic_increment( &_nic_tx_channel_allocator, 1 ); 350 351 if ( (nic_channel >= NB_NIC_CHANNELS) ) 352 { 353 _printf("\n[GIET_ERROR] in _sys_nic_alloc() not enough NIC channels\n"); 354 return -1; 355 } 356 357 // get a CMA channel index 358 cma_channel = _atomic_increment( &_cma_channel_allocator, 1 ); 359 360 if ( cma_channel >= NB_CMA_CHANNELS ) 361 { 362 _printf("\n[GIET_ERROR] in _sys_nic_alloc() not enough CMA channels\n"); 363 return -1; 364 } 398 _printf("\n[GIET DEBUG NIC] Task %d enters sys_nic_alloc() at cycle %d\n" 399 " nic_channel = %d / cma_channel = %d\n" 400 thread , _get_proctime() , nic_channel , cma_channel ); 401 #endif 365 402 366 403 // register nic_index and cma_index in task context … … 376 413 } 377 414 378 #if GIET_DEBUG_NIC 379 _printf("\n[GIET DEBUG NIC] Task %d exit _sys_nic_alloc() at cycle %d : " 380 "NIC channel = %d / CMA channel = %d\n", 381 thread, _get_proctime(), nic_channel, cma_channel ); 382 #endif 383 384 return nic_channel; 385 } // end _sys_nic_alloc() 386 387 //////////////////////////////////////// 388 int _sys_nic_start( unsigned int is_rx, 389 unsigned int channel ) 390 { 391 392 #if GIET_DEBUG_NIC 393 unsigned int thread = _get_context_slot( CTX_TRDID_ID ); 394 _printf("\n[GIET DEBUG NIC] Task %d enters _sys_nic_start() at cycle %d\n", 395 thread , _get_proctime() ); 396 #endif 397 398 unsigned int nic_channel; 399 unsigned int cma_channel; 400 401 // get NIC channel index and CMA channel index 402 if ( is_rx ) 403 { 404 nic_channel = _get_context_slot( CTX_NIC_RX_ID ); 405 cma_channel = _get_context_slot( CTX_CMA_RX_ID ); 406 } 407 else 408 { 409 nic_channel = _get_context_slot( CTX_NIC_TX_ID ); 410 cma_channel = _get_context_slot( CTX_CMA_TX_ID ); 411 } 412 413 #if GIET_DEBUG_NIC 414 _printf("\n[GIET DEBUG NIC] Task %d in _sys_nic_start() at cycle %d" 415 " get NIC channel = %d / CMA channel = %d\n", 416 thread, _get_proctime(), nic_channel, cma_channel ); 417 #endif 418 419 if ( nic_channel != channel ) 420 { 421 _printf("\n[GIET_ERROR] in _sys_nic_start(): illegal NIC channel\n"); 422 return -1; 423 } 424 if ( cma_channel >= NB_CMA_CHANNELS ) 425 { 426 _printf("\n[GIET_ERROR] in _sys_nic_start(): illegal CMA channel\n"); 427 return -1; 428 } 429 415 // physical addresses to be registered in the CMA registers 430 416 unsigned long long nic_chbuf_pbase; // NIC chbuf physical address 431 417 unsigned long long ker_chbuf_pbase; // kernel chbuf physical address … … 437 423 unsigned int vaddr; 438 424 439 // allocate two containers per cluster440 unsigned int cx; // container X coordinate441 unsigned int cy; // container Y coordinate442 unsigned int index; // container index in chbuf443 unsigned long long cont_paddr; // container physical address444 445 for ( cx = 0 ; cx < X_SIZE; cx++ )446 { 447 for ( cy = 0 ; cy < Y_SIZE; cy++ )425 // allocate one kernel container per cluster in the (xmax / ymax) mesh 426 unsigned int cx; // cluster X coordinate 427 unsigned int cy; // cluster Y coordinate 428 unsigned int index; // container index in chbuf 429 unsigned long long cont_paddr; // container physical address 430 431 for ( cx = 0 ; cx < xmax ; cx++ ) 432 { 433 for ( cy = 0 ; cy < ymax ; cy++ ) 448 434 { 449 435 // compute index in chbuf 450 index = (cx * Y_SIZE) + cy;451 452 // allocate the container436 index = (cx * ymax) + cy; 437 438 // allocate the kernel container 453 439 vaddr = (unsigned int)_remote_malloc( NIC_CONTAINER_SIZE, cx, cy ); 440 441 if ( vaddr == 0 ) // not enough kernel heap memory in cluster[cx,cy] 442 { 443 _printf("\n[GIET_ERROR] in _sys_nic_alloc() not enough kenel heap" 444 " in cluster[%d,%d]\n", cx, cy ); 445 return -1; 446 } 454 447 455 448 // compute container physical address … … 460 453 cont_paddr = (((unsigned long long)ppn) << 12) | (vaddr & 0x00000FFF); 461 454 462 // initialize chbuf 455 // initialize chbuf entry 463 456 if ( is_rx ) _nic_rx_chbuf[nic_channel].buffer[index].desc = cont_paddr; 464 457 else _nic_tx_chbuf[nic_channel].buffer[index].desc = cont_paddr; … … 470 463 #endif 471 464 } 465 } 466 467 // complete kernel chbuf initialisation 468 if ( is_rx ) 469 { 470 _nic_rx_chbuf[nic_channel].xmax = xmax; 471 _nic_rx_chbuf[nic_channel].ymax = ymax; 472 } 473 else 474 { 475 _nic_tx_chbuf[nic_channel].xmax = xmax; 476 _nic_tx_chbuf[nic_channel].ymax = ymax; 472 477 } 473 478 … … 511 516 _cma_set_register( cma_channel, CHBUF_DST_DESC , (unsigned int)(ker_chbuf_pbase) ); 512 517 _cma_set_register( cma_channel, CHBUF_DST_EXT , (unsigned int)(ker_chbuf_pbase>>32) ); 513 _cma_set_register( cma_channel, CHBUF_DST_NBUFS, X_SIZE*Y_SIZE);518 _cma_set_register( cma_channel, CHBUF_DST_NBUFS, xmax * ymax ); 514 519 } 515 520 else // kernel to NIC … … 517 522 _cma_set_register( cma_channel, CHBUF_SRC_DESC , (unsigned int)(ker_chbuf_pbase) ); 518 523 _cma_set_register( cma_channel, CHBUF_SRC_EXT , (unsigned int)(ker_chbuf_pbase>>32) ); 519 _cma_set_register( cma_channel, CHBUF_SRC_NBUFS, X_SIZE*Y_SIZE);524 _cma_set_register( cma_channel, CHBUF_SRC_NBUFS, xmax * ymax ); 520 525 _cma_set_register( cma_channel, CHBUF_DST_DESC , (unsigned int)(nic_chbuf_pbase) ); 521 526 _cma_set_register( cma_channel, CHBUF_DST_EXT , (unsigned int)(nic_chbuf_pbase>>32) ); 522 527 _cma_set_register( cma_channel, CHBUF_DST_NBUFS, 2 ); 528 } 529 530 #if GIET_DEBUG_NIC 531 _printf("\n[GIET DEBUG NIC] Task %d exit _sys_nic_alloc() at cycle %d\n", 532 thread, _get_proctime() ); 533 #endif 534 535 return nic_channel; 536 } // end _sys_nic_alloc() 537 538 539 //////////////////////////////////////// 540 int _sys_nic_start( unsigned int is_rx, 541 unsigned int channel ) 542 { 543 unsigned int nic_channel; 544 unsigned int cma_channel; 545 546 // get NIC channel index and CMA channel index from task context 547 if ( is_rx ) 548 { 549 nic_channel = _get_context_slot( CTX_NIC_RX_ID ); 550 cma_channel = _get_context_slot( CTX_CMA_RX_ID ); 551 } 552 else 553 { 554 nic_channel = _get_context_slot( CTX_NIC_TX_ID ); 555 cma_channel = _get_context_slot( CTX_CMA_TX_ID ); 556 } 557 558 #if GIET_DEBUG_NIC 559 unsigned int thread = _get_context_slot( CTX_TRDID_ID ); 560 _printf("\n[GIET DEBUG NIC] Task %d in _sys_nic_start() at cycle %d" 561 " get NIC channel = %d / CMA channel = %d\n", 562 thread, _get_proctime(), nic_channel, cma_channel ); 563 #endif 564 565 // check NIC and CMA channels index 566 if ( nic_channel != channel ) 567 { 568 _printf("\n[GIET_ERROR] in _sys_nic_start(): illegal NIC channel\n"); 569 return -1; 570 } 571 if ( cma_channel >= NB_CMA_CHANNELS ) 572 { 573 _printf("\n[GIET_ERROR] in _sys_nic_start(): illegal CMA channel\n"); 574 return -1; 523 575 } 524 576 … … 539 591 } // end sys_nic_start() 540 592 593 541 594 ////////////////////////////////////// 542 595 int _sys_nic_move( unsigned int is_rx, … … 551 604 #endif 552 605 606 // check NIC channel index 607 if ( channel >= NB_NIC_CHANNELS ) 608 { 609 _printf("\n[GIET_ERROR] in _sys_nic_move() : illegal NIC channel index\n"); 610 return -1; 611 } 612 613 // get kernel chbuf virtual address 614 nic_chbuf_t* chbuf; 615 if ( is_rx ) chbuf = &_nic_rx_chbuf[channel]; 616 else chbuf = &_nic_tx_chbuf[channel]; 617 618 // get xmax / ymax parameters 619 unsigned int xmax = chbuf->xmax; 620 unsigned int ymax = chbuf->ymax; 621 553 622 // get cluster coordinates for the processor running the calling task 554 623 unsigned int procid = _get_procid(); 555 624 unsigned int cx = procid >> (Y_WIDTH + P_WIDTH); 556 625 unsigned int cy = (procid >> P_WIDTH) & ((1<<Y_WIDTH)-1); 626 627 // check processor coordinates / (xmax,ymax) 628 if ( cx >= xmax ) 629 { 630 _printf("\n[GIET_ERROR] in _sys_nic_move() : processor X coordinate = %d" 631 " / xmax = %d\n", cx , xmax ); 632 return -1; 633 } 634 if ( cy >= ymax ) 635 { 636 _printf("\n[GIET_ERROR] in _sys_nic_move() : processor Y coordinate = %d" 637 " / ymax = %d\n", cy , ymax ); 638 return -1; 639 } 557 640 558 641 unsigned long long user_buffer_paddr; // user buffer physical address … … 588 671 #endif 589 672 590 // check NIC channel index591 if ( channel >= NB_NIC_CHANNELS )592 {593 _printf("\n[GIET_ERROR] in _sys_nic_move() : illegal NIC channel index\n");594 return -1;595 }596 597 // get kernel chbuf virtual address598 nic_chbuf_t* chbuf;599 if ( is_rx ) chbuf = &_nic_rx_chbuf[channel];600 else chbuf = &_nic_tx_chbuf[channel];601 602 673 // compute kernel chbuf physical address (required for sync) 603 674 vaddr = (unsigned int)chbuf; … … 608 679 kernel_chbuf_paddr = ((unsigned long long)ppn << 12) | (vaddr & 0x00000FFF); 609 680 610 // poll chbufuntil success681 // poll local kernel container status until success 611 682 while ( 1 ) 612 683 { 613 684 // compute buffer index and buffer descriptor paddr 614 index = ( Y_SIZE* cx) + cy;685 index = (ymax * cx) + cy; 615 686 buffer_desc_paddr = kernel_chbuf_paddr + (index<<6); 616 687 … … 633 704 kernel_buffer_paddr = buffer_desc & 0x0000FFFFFFFFFFFFULL; 634 705 635 // move one container , using a physical_memcpy636 if ( is_rx ) 706 // move one container 707 if ( is_rx ) // RX transfer 637 708 { 638 709 // inval kernel buffer in L2 before read in L2 … … 650 721 651 722 } 652 else 723 else // TX transfer 653 724 { 654 725 // transfer data from user buffer to kernel buffer … … 683 754 } // end _sys_nic_move() 684 755 756 685 757 //////////////////////////////////////// 686 758 int _sys_nic_stop( unsigned int is_rx, … … 702 774 } 703 775 776 // check NIC and CMA channels index 704 777 if ( nic_channel != channel ) 705 778 { 706 _printf("\n[GIET_ERROR] in _sys_nic_stop(): illegal NIC channel\n" 707 " allocated channel = %d / requested channel = %d\n", 708 nic_channel , channel ); 779 _printf("\n[GIET_ERROR] in _sys_nic_stop(): illegal NIC channel\n"); 709 780 return -1; 710 781 } … … 722 793 723 794 return 0; 724 } 795 } // end _sys_nic_stop() 725 796 726 797 //////////////////////////////////////// … … 763 834 } 764 835 return 0; 765 } 836 } // en _sys_nic_clear() 766 837 767 838 //////////////////////////////////////// … … 834 905 } 835 906 return 0; 836 } 907 } // end _sys_nic_stats() 837 908 838 909 ///////////////////////////////////////////////////////////////////////////////////////// … … 1231 1302 } 1232 1303 1233 ////////////////////////////////////// 1234 int _sys_procs_number( unsigned int x,1235 unsigned int y,1236 unsigned int* n umber)1237 { 1238 mapping_header_t * header = (mapping_header_t *)SEG_BOOT_MAPPING_BASE;1304 //////////////////////////////////////////// 1305 int _sys_procs_number( unsigned int* x_size, 1306 unsigned int* y_size, 1307 unsigned int* nprocs ) 1308 { 1309 mapping_header_t * header = (mapping_header_t *)SEG_BOOT_MAPPING_BASE; 1239 1310 mapping_cluster_t * cluster = _get_cluster_base(header); 1240 1311 1241 if ( (x < X_SIZE) && (y < Y_SIZE) ) 1242 { 1243 *number = cluster[(x*Y_SIZE)+y].procs; 1244 return 0; 1245 } 1246 else 1247 { 1248 _printf("\n[GIET ERROR] in _sys_procs_number() : illegal (x,y) coordinates\n" ); 1249 return -1; 1250 } 1312 unsigned int x; 1313 unsigned int y; 1314 unsigned int okmin = 1; 1315 unsigned int okmax = 1; 1316 1317 // compute max values 1318 unsigned int xmax = header->x_size; 1319 unsigned int ymax = header->y_size; 1320 unsigned int procs = cluster[0].procs; 1321 1322 // check the (ymax-1) lower rows 1323 for ( y = 0 ; y < ymax-1 ; y++ ) 1324 { 1325 for ( x = 0 ; x < xmax ; x++ ) 1326 { 1327 if (cluster[x*ymax+y].procs != procs ) okmin = 0; 1328 } 1329 } 1330 1331 // check the upper row 1332 for ( x = 0 ; x < xmax ; x++ ) 1333 { 1334 if (cluster[x*ymax+ymax-1].procs != procs ) okmax = 0; 1335 } 1336 1337 // return values 1338 if ( okmin && okmax ) 1339 { 1340 *x_size = xmax; 1341 *y_size = ymax; 1342 *nprocs = procs; 1343 } 1344 else if ( okmin ) 1345 { 1346 *x_size = xmax; 1347 *y_size = ymax-1; 1348 *nprocs = procs; 1349 } 1350 else 1351 { 1352 *x_size = 0; 1353 *y_size = 0; 1354 *nprocs = 0; 1355 } 1356 return 0; 1251 1357 } 1252 1358
Note: See TracChangeset
for help on using the changeset viewer.