Changeset 449 for soft/giet_vm/giet_kernel
- Timestamp:
- Nov 11, 2014, 4:14:55 PM (10 years ago)
- Location:
- soft/giet_vm/giet_kernel
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/giet_kernel/ctx_handler.h
r440 r449 19 19 // allocated to the task (private peripheral channel for multi-channels peripherals). 20 20 ///////////////////////////////////////////////////////////////////////////////////////// 21 // ctx[0] <- *** |ctx[8] <- $8 |ctx[16]<- $16 |ctx[24]<- $2422 // ctx[1] <- $1 |ctx[9] <- $9 |ctx[17]<- $17 |ctx[25]<- $2523 // ctx[2] <- $2 |ctx[10]<- $10 |ctx[18]<- $18 |ctx[26]<- LO24 // ctx[3] <- $3 |ctx[11]<- $11 |ctx[19]<- $19 |ctx[27]<- HI25 // ctx[4] <- $4 |ctx[12]<- $12 |ctx[20]<- $20 |ctx[28]<- $2826 // ctx[5] <- $5 |ctx[13]<- $13 |ctx[21]<- $21 |ctx[29]<- SP27 // ctx[6] <- $6 |ctx[14]<- $14 |ctx[22]<- $22 |ctx[30]<- $3028 // ctx[7] <- $7 |ctx[15]<- $15 |ctx[23]<- $23 |ctx[31]<- RA21 // ctx[0] <- *** |ctx[8] <- $8 |ctx[16]<- $16 |ctx[24]<- $24 22 // ctx[1] <- $1 |ctx[9] <- $9 |ctx[17]<- $17 |ctx[25]<- $25 23 // ctx[2] <- $2 |ctx[10]<- $10 |ctx[18]<- $18 |ctx[26]<- LO 24 // ctx[3] <- $3 |ctx[11]<- $11 |ctx[19]<- $19 |ctx[27]<- HI 25 // ctx[4] <- $4 |ctx[12]<- $12 |ctx[20]<- $20 |ctx[28]<- $28 26 // ctx[5] <- $5 |ctx[13]<- $13 |ctx[21]<- $21 |ctx[29]<- SP 27 // ctx[6] <- $6 |ctx[14]<- $14 |ctx[22]<- $22 |ctx[30]<- $30 28 // ctx[7] <- $7 |ctx[15]<- $15 |ctx[23]<- $23 |ctx[31]<- RA 29 29 // 30 // ctx[32]<- EPC |ctx[40]<- TTY |ctx[48]<- TRDID |ctx[56]<- ***31 // ctx[33]<- CR |ctx[41]<- FBCMA|ctx[49]<- GTID |ctx[57]<- ***32 // ctx[34]<- SR |ctx[42]<- TXCMA |ctx[50]<- ***|ctx[58]<- ***33 // ctx[35]<- BVAR |ctx[43]<- RXCMA|ctx[51]<- *** |ctx[59]<- ***34 // ctx[36]<- PTAB |ctx[44]<- NIC 35 // ctx[37]<- LTID |ctx[45]<- HBA|ctx[53]<- *** |ctx[61]<- ***36 // ctx[38]<- VSID |ctx[46]<- TIM |ctx[54]<- *** |ctx[62]<- ***37 // ctx[39]<- PTPR |ctx[47]<- RUN|ctx[55]<- *** |ctx[63]<- ***30 // ctx[32]<- EPC |ctx[40]<- TTY |ctx[48]<- TRDID |ctx[56]<- *** 31 // ctx[33]<- CR |ctx[41]<- CMA_FB |ctx[49]<- GTID |ctx[57]<- *** 32 // ctx[34]<- SR |ctx[42]<- CMA_RX |ctx[50]<- RUN |ctx[58]<- *** 33 // ctx[35]<- BVAR |ctx[43]<- CMA_TX |ctx[51]<- *** |ctx[59]<- *** 34 // ctx[36]<- PTAB |ctx[44]<- NIC_RX |ctx[52]<- *** |ctx[60]<- *** 35 // ctx[37]<- LTID |ctx[45]<- NIC_TX |ctx[53]<- *** |ctx[61]<- *** 36 // ctx[38]<- VSID |ctx[46]<- TIM |ctx[54]<- *** |ctx[62]<- *** 37 // ctx[39]<- PTPR |ctx[47]<- HBA |ctx[55]<- *** |ctx[63]<- *** 38 38 ///////////////////////////////////////////////////////////////////////////////////////// 39 39 … … 60 60 61 61 #define CTX_TTY_ID 40 // private TTY channel index 62 #define CTX_ FBCMA_ID41 // private CMA channel index for FBF write63 #define CTX_ TXCMA_ID 42 // private CMA channel index for NICTX64 #define CTX_ RXCMA_ID 43 // private CMA channel index for NICRX65 #define CTX_NIC_ ID 44 // private NIC channel index66 #define CTX_ HBA_ID 45 // private HBA channel index62 #define CTX_CMA_FB_ID 41 // private CMA channel index for FBF write 63 #define CTX_CMA_RX_ID 42 // private CMA channel index for NIC_TX 64 #define CTX_CMA_TX_ID 43 // private CMA channel index for NIC_RX 65 #define CTX_NIC_RX_ID 44 // private NIC channel index RX transfer 66 #define CTX_NIC_TX_ID 45 // private NIC channel index TX transfer 67 67 #define CTX_TIM_ID 46 // ptivate TIM channel index 68 #define CTX_ RUN_ID 47 // Boolean: task runable68 #define CTX_HBA_ID 47 // private HBA channel index 69 69 70 70 #define CTX_TRDID_ID 48 // Thread Task Index in vspace 71 71 #define CTX_GTID_ID 49 // Global Task Index in all system 72 #define CTX_RUN_ID 50 // Boolean: task runable 72 73 73 74 ///////////////////////////////////////////////////////////////////////////////// -
soft/giet_vm/giet_kernel/kernel_init.c
r440 r449 173 173 } // end for tasks 174 174 175 // step 4: compute and set XCU masks175 // step 3 : compute and set XCU masks 176 176 177 177 unsigned int isr_switch_index = 0xFFFFFFFF; … … 211 211 _xcu_set_mask( cluster_xy, channel, pti_mask, IRQ_TYPE_PTI ); 212 212 213 // step 5: start TICK timer if at least one task213 // step 4 : start TICK timer if at least one task 214 214 if (tasks > 0) 215 215 { … … 232 232 #endif 233 233 234 // step 6: each processor updates the idle_task context:234 // step 5 : each processor updates the idle_task context: 235 235 // (CTX_SP, CTX_RA, CTX_EPC). 236 236 // The 4 Kbytes idle stack is implemented in the scheduler. … … 251 251 #endif 252 252 253 // step 7: when all processors reach the synchronisation barrier,253 // step 6 : when all processors reach the synchronisation barrier, 254 254 // each processor set registers SP, SR, PTPR, EPC, 255 255 // with the values corresponding to the first allocated task, -
soft/giet_vm/giet_kernel/kernel_utils.c
r446 r449 162 162 } // end _printf() 163 163 164 /////////////////////////////////////////////////// 165 unsigned int _atomic_increment( unsigned int* ptr ) 166 { 167 unsigned int value; 168 169 asm volatile ( 170 "_atomic_increment_try: \n" 171 "ll $3, 0(%1) \n" 172 "move %0, $3 \n" 173 "addi $3, $3, 1 \n" 174 "sc $3, 0(%1) \n" 175 "beqz $3, _atomic_increment_try \n" 176 : "=r" (value) 177 : "r" (ptr) 178 : "$3", "memory" ); 179 180 return value; 181 } 182 164 183 // Local Variables: 165 184 // tab-width: 4 -
soft/giet_vm/giet_kernel/kernel_utils.h
r446 r449 14 14 extern void _printf( char* format, ... ); 15 15 16 /////////////////////////////////////////////////////////// 17 extern unsigned int _atomic_increment( unsigned int* ptr ); 18 16 19 #endif 17 20 -
soft/giet_vm/giet_kernel/sys_handler.c
r440 r449 26 26 #endif 27 27 28 #if !defined(NB_TTY_CHANNELS) 29 # error: You must define NB_TTY_CHANNELS in the hard_config.h file 30 #endif 31 32 #if !defined(NB_TIM_CHANNELS) 33 # error: You must define NB_TIM_CHANNELS in the hard_config.h file 34 #endif 35 36 #if !defined(NB_NIC_CHANNELS) 37 # error: You must define NB_NIC_CHANNELS in the hard_config.h file 38 #endif 39 40 #if !defined(NB_CMA_CHANNELS) 41 # error: You must define NB_CMA_CHANNELS in the hard_config.h file 42 #endif 43 44 #if !defined(GIET_NIC_CHBUF_NBUFS) 45 # error: You must define GIET_NIC_CHBUF_NBUFS in the giet_config.h file 46 #endif 47 48 #if !defined(GIET_NIC_CHBUF_SIZE) 49 # error: You must define GIET_NIC_CHBUF_SIZE in the giet_config.h file 50 #endif 51 52 #if !defined(GIET_NIC_CHBUF_TIMEOUT) 53 # error: You must define GIET_NIC_CHBUF_TIMEOUT in the giet_config.h file 54 #endif 55 56 28 57 //////////////////////////////////////////////////////////////////////////// 29 58 // Channel allocators for peripherals … … 34 63 unsigned int _tim_channel_allocator = 0; 35 64 unsigned int _cma_channel_allocator = 0; 36 unsigned int _nic_channel_allocator = 0; 65 unsigned int _nic_rx_channel_allocator = 0; 66 unsigned int _nic_tx_channel_allocator = 0; 67 68 69 //////////////////////////////////////////////////////////////////////////// 70 // NIC_RX and NIC_TX chbuf arrays 71 //////////////////////////////////////////////////////////////////////////// 72 73 nic_chbuf_t _nic_rx_chbuf[NB_NIC_CHANNELS] __attribute__((aligned(8))); 74 nic_chbuf_t _nic_tx_chbuf[NB_NIC_CHANNELS] __attribute__((aligned(8))); 75 37 76 38 77 //////////////////////////////////////////////////////////////////////////// … … 72 111 &_sys_vobj_get_length, /* 0x1B */ 73 112 &_sys_xy_from_ptr, /* 0x1C */ 74 &_sys_ nic_alloc,/* 0x1D */75 &_sys_ nic_sync_send,/* 0x1E */76 &_sys_ nic_sync_receive,/* 0x1F */113 &_sys_ukn, /* 0x1D */ 114 &_sys_ukn, /* 0x1E */ 115 &_sys_ukn, /* 0x1F */ 77 116 78 117 &_fat_user_open, /* 0x20 */ … … 93 132 &_sys_ukn, /* 0x2F */ 94 133 95 &_sys_ ukn,/* 0x30 */96 &_sys_ ukn,/* 0x31 */97 &_sys_ ukn,/* 0x32 */98 &_sys_ ukn,/* 0x33 */99 &_sys_ ukn,/* 0x34 */100 &_sys_ ukn,/* 0x35 */101 &_sys_ ukn,/* 0x36 */102 &_sys_ ukn,/* 0x37 */134 &_sys_nic_alloc, /* 0x30 */ 135 &_sys_nic_alloc, /* 0x31 */ 136 &_sys_nic_start, /* 0x32 */ 137 &_sys_nic_start, /* 0x33 */ 138 &_sys_nic_move, /* 0x34 */ 139 &_sys_nic_move, /* 0x35 */ 140 &_sys_nic_stop, /* 0x36 */ 141 &_sys_nic_stop, /* 0x37 */ 103 142 &_sys_ukn, /* 0x38 */ 104 143 &_sys_ukn, /* 0x39 */ … … 119 158 { 120 159 // get a new TTY terminal index 121 unsigned int channel = _ tty_channel_allocator;160 unsigned int channel = _atomic_increment( &_tty_channel_allocator ); 122 161 unsigned int thread = _get_context_slot( CTX_TRDID_ID ); 123 162 unsigned int vspace = _get_context_slot( CTX_VSID_ID ); … … 132 171 _printf("\n[GIET WARNING] TTY channel %d allocated " 133 172 " to thread %d in vspace %d\n", channel, thread, vspace ); 134 } 135 136 // register timer index in task context 137 _set_context_slot( CTX_TTY_ID, _tty_channel_allocator ); 138 139 // update timer allocator 140 _tty_channel_allocator++; 141 142 return 0; 173 _set_context_slot( CTX_TTY_ID, channel ); 174 return 0; 175 } 143 176 } 144 177 … … 227 260 { 228 261 // get a new timer index 229 unsigned int channel = _ tim_channel_allocator;262 unsigned int channel = _atomic_increment(&_tim_channel_allocator); 230 263 unsigned int thread = _get_context_slot( CTX_TRDID_ID ); 231 264 unsigned int vspace = _get_context_slot( CTX_VSID_ID ); … … 240 273 _printf("\n[GIET WARNING] TIM channel %d allocated " 241 274 " to thread %d in vspace %d\n", channel, thread, vspace ); 242 } 243 244 // register timer index in task context 245 _set_context_slot( CTX_TIM_ID, channel ); 246 247 // update timer allocator 248 _tim_channel_allocator++; 249 250 return 0; 275 _set_context_slot( CTX_TIM_ID, channel ); 276 return 0; 277 } 251 278 } 252 279 … … 289 316 ////////////////////////////////////////////////////////////////////////////// 290 317 291 //////////////////// 292 int _sys_nic_alloc() 293 { 294 // get a new NIC channel index 295 unsigned int channel = _nic_channel_allocator; 296 unsigned int thread = _get_context_slot( CTX_TRDID_ID ); 297 unsigned int vspace = _get_context_slot( CTX_VSID_ID ); 298 299 if ( channel >= NB_NIC_CHANNELS ) 300 { 301 _printf("\n[GIET_ERROR] in _sys_nic_alloc() : not enough NIC channels\n"); 302 return -1; 318 /////////////////////////////////////////// 319 int _sys_nic_alloc( unsigned int is_rx ) 320 { 321 unsigned int nic_channel; 322 unsigned int cma_channel; 323 324 // get a NIC_RX or NIC_TX channel index 325 if ( is_rx ) nic_channel = _atomic_increment(&_nic_rx_channel_allocator); 326 else nic_channel = _atomic_increment(&_nic_tx_channel_allocator); 327 328 if ( (nic_channel >= NB_NIC_CHANNELS) ) 329 { 330 _printf("\n[GIET_ERROR] in _sys_nic_alloc() not enough NIC channels\n"); 331 return -1; 332 } 333 334 // get a CMA channel index 335 cma_channel = _atomic_increment(&_cma_channel_allocator); 336 337 if ( cma_channel >= NB_CMA_CHANNELS ) 338 { 339 _printf("\n[GIET_ERROR] in _sys_nic_alloc() not enough CMA channels\n"); 340 return -1; 341 } 342 343 // register nic_index and cma_index in task context 344 if ( is_rx ) 345 { 346 _set_context_slot( CTX_NIC_RX_ID, nic_channel ); 347 _set_context_slot( CTX_CMA_RX_ID, cma_channel ); 303 348 } 304 349 else 305 350 { 306 _printf("\n[GIET WARNING] NIC channel %d allocated " 307 " to thread %d in vspace %d\n", channel, thread, vspace ); 308 } 309 310 // register channel index in task context 311 _set_context_slot( CTX_NIC_ID, channel ); 312 313 // update NIC channel allocator 314 _nic_channel_allocator++; 315 316 return 0; 317 } 318 319 //////////////////////////////////// 320 int _sys_nic_sync_send( void* vbuf ) 321 { 351 _set_context_slot( CTX_NIC_TX_ID, nic_channel ); 352 _set_context_slot( CTX_CMA_TX_ID, cma_channel ); 353 } 354 355 #if GIET_DEBUG_NIC 356 unsigned int thread = _get_context_slot( CTX_TRDID_ID ); 357 unsigned int vspace = _get_context_slot( CTX_VSID_ID ); 358 _printf("\n[GIET DEBUG_NIC] NIC channel %d and CMA channel %d" 359 " allocated to task %d in vspace %d\n", 360 nic_channel, cma_channel, thread, vspace ); 361 #endif 362 363 return 0; 364 } 365 366 //////////////////////////////////////// 367 int _sys_nic_start( unsigned int is_rx, 368 unsigned int mac4, 369 unsigned int mac2 ) 370 { 371 unsigned int nic_channel; 372 unsigned int cma_channel; 373 374 // get NIC channel index and CMA channel index 375 if ( is_rx ) 376 { 377 nic_channel = _get_context_slot( CTX_NIC_RX_ID ); 378 cma_channel = _get_context_slot( CTX_CMA_RX_ID ); 379 } 380 else 381 { 382 nic_channel = _get_context_slot( CTX_NIC_TX_ID ); 383 cma_channel = _get_context_slot( CTX_CMA_TX_ID ); 384 } 385 386 if ( nic_channel >= NB_NIC_CHANNELS ) 387 { 388 _printf("\n[GIET_ERROR] in _sys_nic_start(): NIC channel not allocated\n"); 389 return -1; 390 } 391 if ( cma_channel >= NB_CMA_CHANNELS ) 392 { 393 _printf("\n[GIET_ERROR] in _sys_nic_start(): CMA channel not allocated\n"); 394 return -1; 395 } 396 397 unsigned int nic_chbuf_lsb; // 32 LSB bits of the NIC chbuf physical address 398 unsigned int nic_chbuf_msb; // 16 MSB bits of the NIC chbuf physical address 399 unsigned int ker_chbuf_lsb; // 32 LSB bits of the kernel chbuf physical address 400 unsigned int ker_chbuf_msb; // 16 MSB bits of the kernel chbuf physical address 401 402 // get the NIC chbuf descriptor physical address 403 unsigned int offset; 404 if ( is_rx ) offset = 0x1000; 405 else offset = 0x1010; 406 nic_chbuf_lsb = SEG_NIC_BASE + (nic_channel * NIC_CHANNEL_SPAN) + offset; 407 nic_chbuf_msb = (X_IO << Y_WIDTH) + Y_IO; 408 409 // get the kernel chbuf descriptor physical address 410 unsigned int ker_chbuf_vaddr; 411 if ( is_rx ) ker_chbuf_vaddr = (unsigned int)( &_nic_rx_chbuf[nic_channel] ); 412 else ker_chbuf_vaddr = (unsigned int)( &_nic_tx_chbuf[nic_channel] ); 413 414 // compute the kernel chbuf descriptor physical address 322 415 unsigned int ppn; 323 416 unsigned int flags; 324 unsigned int vaddr = (unsigned int)vbuf; 325 326 // get NIC channel index 327 unsigned int channel = _get_context_slot( CTX_NIC_ID ); 328 if ( channel >= NB_NIC_CHANNELS ) 329 { 330 _printf("\n[GIET_ERROR] in _sys_nic_sync_send() : illegal NIC channel index\n"); 331 return -1; 332 } 333 334 // get page table pointer 335 unsigned int user_ptab = _get_context_slot( CTX_PTAB_ID ); 417 unsigned int ptab = _get_context_slot(CTX_PTAB_ID); 418 unsigned int ko = _v2p_translate( (page_table_t*)ptab, 419 ker_chbuf_vaddr, 420 &ppn, 421 &flags ); 422 if ( ko ) 423 { 424 _puts("\n[GIET ERROR] in _nic_cma_start_receive() : kernel buffer unmapped\n"); 425 return -1; 426 } 427 428 ker_chbuf_lsb = (ppn << 12) | (ker_chbuf_vaddr & 0x00000FFF); 429 ker_chbuf_msb = ppn >> 20; 430 431 // initializes CMA registers defining the source chbuf (NIc) 432 _cma_set_register( cma_channel, CHBUF_SRC_DESC , nic_chbuf_lsb ); 433 _cma_set_register( cma_channel, CHBUF_DST_EXT , nic_chbuf_msb ); 434 _cma_set_register( cma_channel, CHBUF_SRC_NBUFS, 2 ); 435 436 // initializes CMA registers defining the destination chbuf (kernel) 437 _cma_set_register( cma_channel, CHBUF_DST_DESC , ker_chbuf_lsb ); 438 _cma_set_register( cma_channel, CHBUF_DST_EXT , ker_chbuf_msb ); 439 _cma_set_register( cma_channel, CHBUF_DST_NBUFS, GIET_NIC_CHBUF_NBUFS ); 440 441 // start CMA transfer 442 _cma_set_register( cma_channel, CHBUF_BUF_SIZE , 4096 ); 443 _cma_set_register( cma_channel, CHBUF_PERIOD , 300 ); 444 _cma_set_register( cma_channel, CHBUF_RUN , 1 ); 445 446 // activates NIC channel 447 _nic_channel_start( nic_channel, is_rx, mac4, mac2 ); 448 return 0; 449 } 450 451 ////////////////////////////////////// 452 int _sys_nic_move( unsigned int is_rx, 453 void* buffer ) 454 { 455 unsigned long long user_paddr; // user buffer physical address 456 unsigned long long kernel_paddr; // kernel buffer physical address 336 457 337 458 // Compute user buffer physical address and check access rights 338 unsigned int ko = _v2p_translate( (page_table_t*)user_ptab,339 vaddr,340 &ppn,341 &flags );342 if ( ko )343 {344 _printf("\n[GIET ERROR] in _sys_nic_sync_send() : user buffer unmapped\n");345 return -1;346 }347 if ( (flags & PTE_U) == 0 )348 {349 _printf("\n[GIET ERROR] in _sys_nic_sync_send() : illegal buffer address\n");350 return -1;351 }352 unsigned long long pbuf = ((unsigned long long)ppn << 12) | (vaddr & 0x00000FFF);353 354 _nic_sync_send( channel, pbuf );355 356 return 0;357 }358 359 ///////////////////////////////////////360 int _sys_nic_sync_receive( void* vbuf )361 {362 459 unsigned int ppn; 363 460 unsigned int flags; 364 unsigned int vaddr = (unsigned int)vbuf; 365 366 // get NIC channel index 367 unsigned int channel = _get_context_slot( CTX_NIC_ID ); 461 unsigned int vaddr = (unsigned int)buffer; 462 unsigned int user_ptab = _get_context_slot( CTX_PTAB_ID ); 463 unsigned int ko = _v2p_translate( (page_table_t*)user_ptab, 464 vaddr, 465 &ppn, 466 &flags ); 467 if ( ko ) 468 { 469 _printf("\n[GIET ERROR] in _sys_nic_tx_move() : user buffer unmapped\n"); 470 return -1; 471 } 472 if ( (flags & PTE_U) == 0 ) 473 { 474 _printf("\n[GIET ERROR] in _sys_nic_tx_move() : illegal buffer address\n"); 475 return -1; 476 } 477 user_paddr = ((unsigned long long)ppn << 12) | (vaddr & 0x00000FFF); 478 479 // get NIC channel index, to get pointer on NIC_TX chbuf pointer 480 unsigned int channel; 481 if ( is_rx ) channel = _get_context_slot( CTX_NIC_RX_ID ); 482 else channel = _get_context_slot( CTX_NIC_TX_ID ); 483 368 484 if ( channel >= NB_NIC_CHANNELS ) 369 485 { 370 _printf("\n[GIET_ERROR] in _sys_nic_sync_send() : illegal NIC channel index\n"); 371 return -1; 372 } 373 374 // get page table pointer 375 unsigned int user_ptab = _get_context_slot( CTX_PTAB_ID ); 376 377 // Compute user buffer physical address and check access rights 378 unsigned int ko = _v2p_translate( (page_table_t*)user_ptab, 379 vaddr, 380 &ppn, 381 &flags ); 382 if ( ko ) 383 { 384 _printf("\n[GIET ERROR] in _sys_nic_sync_send() : user buffer unmapped\n"); 385 return -1; 386 } 387 if ( (flags & PTE_U) == 0 ) 388 { 389 _printf("\n[GIET ERROR] in _sys_nic_sync_send() : illegal buffer address\n"); 390 return -1; 391 } 392 unsigned long long pbuf = ((unsigned long long)ppn << 12) | (vaddr & 0x00000FFF); 393 394 _nic_sync_receive( channel, pbuf ); 486 _printf("\n[GIET_ERROR] in _sys_nic_move() : illegal NIC channel index\n"); 487 return -1; 488 } 489 490 nic_chbuf_t* chbuf; 491 if ( is_rx ) chbuf = &_nic_rx_chbuf[channel]; 492 else chbuf = &_nic_tx_chbuf[channel]; 493 494 // polling on the chbuf status 495 volatile unsigned long long desc; 496 unsigned int full; 497 unsigned int ok = 0; 498 unsigned int index = chbuf->index; 499 unsigned int timeout = GIET_NIC_CHBUF_TIMEOUT; 500 while( ok == 0 ) 501 { 502 desc = chbuf->buffer[index]; 503 full = desc >> 63; 504 if ( (is_rx && full) || ((is_rx == 0) && (full == 0)) ) // success 505 { 506 ok = 1; 507 } 508 else // retry 509 { 510 timeout--; 511 } 512 if ( timeout == 0 ) 513 { 514 _printf("\n[GIET_ERROR] in _sys_ni_move() : timeout\n"); 515 return -1; 516 } 517 } 518 kernel_paddr = desc & 0x0000FFFFFFFFFFFFULL; 519 520 // move one container using, a physical_memcpy 521 if ( is_rx ) _physical_memcpy( user_paddr, 522 kernel_paddr, 523 GIET_NIC_CHBUF_SIZE ); 524 525 else _physical_memcpy( kernel_paddr, 526 user_paddr, 527 GIET_NIC_CHBUF_SIZE ); 528 529 // update chbuf status and index 530 if ( is_rx ) chbuf->buffer[index] = desc & 0x0000FFFFFFFFFFFFULL; 531 else chbuf->buffer[index] = desc | 0x8000000000000000ULL; 532 if ( index == (GIET_NIC_CHBUF_NBUFS - 1) ) chbuf->index = 0; 533 else chbuf->index = index + 1; 534 535 return 0; 536 } // end _sys_nic_move() 537 538 //////////////////////////////////////// 539 int _sys_nic_stop( unsigned int is_rx ) 540 { 541 unsigned int nic_channel; 542 unsigned int cma_channel; 543 544 // get NIC channel index and CMA channel index 545 if ( is_rx ) 546 { 547 nic_channel = _get_context_slot( CTX_NIC_RX_ID ); 548 cma_channel = _get_context_slot( CTX_CMA_RX_ID ); 549 } 550 else 551 { 552 nic_channel = _get_context_slot( CTX_NIC_TX_ID ); 553 cma_channel = _get_context_slot( CTX_CMA_TX_ID ); 554 } 555 556 if ( nic_channel >= NB_NIC_CHANNELS ) 557 { 558 _printf("\n[GIET_ERROR] in _sys_nic_start(): NIC channel not allocated\n"); 559 return -1; 560 } 561 if ( cma_channel >= NB_CMA_CHANNELS ) 562 { 563 _printf("\n[GIET_ERROR] in _sys_nic_start(): CMA channel not allocated\n"); 564 return -1; 565 } 566 567 // desactivates the NIC channel 568 _nic_channel_stop( nic_channel, is_rx ); 569 570 // desactivates the CMA channel 571 _cma_channel_stop( cma_channel ); 395 572 396 573 return 0; … … 434 611 int _sys_fbf_cma_alloc() 435 612 { 436 #if NB_CMA_CHANNELS > 0437 438 613 // get a new CMA channel index 439 unsigned int channel = _ cma_channel_allocator;614 unsigned int channel = _atomic_increment( &_cma_channel_allocator ); 440 615 unsigned int thread = _get_context_slot( CTX_TRDID_ID ); 441 616 unsigned int vspace = _get_context_slot( CTX_VSID_ID ); … … 450 625 _printf("\n[GIET WARNING] FBF_CMA channel %d allocated " 451 626 " to thread %d in vspace %d\n", channel, thread, vspace ); 452 } 453 454 // register channel index in task context 455 _set_context_slot( CTX_FBCMA_ID, channel ); 456 457 // update CMA channel allocator 458 _cma_channel_allocator++; 459 460 return 0; 461 462 #else 463 464 _printf("\n[GIET ERROR] in _fb_cma_start() : NB_CMA_CHANNELS = 0\n"); 465 return -1; 466 467 #endif 627 _set_context_slot( CTX_CMA_FB_ID, channel ); 628 return 0; 629 } 468 630 } // end sys_fbf_cma_alloc() 469 631 … … 483 645 484 646 // get channel index 485 unsigned int channel = _get_context_slot( CTX_ FBCMA_ID );647 unsigned int channel = _get_context_slot( CTX_CMA_FB_ID ); 486 648 487 649 if ( channel >= NB_CMA_CHANNELS ) … … 603 765 604 766 // call CMA driver to start transfer 605 _cma_ start_channel( channel,767 _cma_channel_start( channel, 606 768 chbuf_paddr, 607 769 2, … … 628 790 629 791 // get channel index 630 unsigned int channel = _get_context_slot( CTX_ FBCMA_ID );792 unsigned int channel = _get_context_slot( CTX_CMA_FB_ID ); 631 793 632 794 if ( channel >= NB_CMA_CHANNELS ) … … 709 871 710 872 // get channel index 711 unsigned int channel = _get_context_slot( CTX_ FBCMA_ID );873 unsigned int channel = _get_context_slot( CTX_CMA_FB_ID ); 712 874 713 875 if ( channel >= NB_CMA_CHANNELS ) … … 718 880 719 881 // Desactivate CMA channel 720 _cma_ stop_channel( channel );882 _cma_channel_stop( channel ); 721 883 722 884 return 0; -
soft/giet_vm/giet_kernel/sys_handler.h
r440 r449 14 14 15 15 #include <mapping_info.h> 16 #include <giet_config.h> 16 17 17 18 /////////////////////////////////////////////////////////////////////////////////// … … 22 23 23 24 /////////////////////////////////////////////////////////////////////////////////// 24 // This structure can beused by the vci_chbuf_dma component to transfer a stream25 // This structure is used by the vci_chbuf_dma component to transfer a stream 25 26 // of images from two buffers in user space to the frame buffer in kernel space. 26 27 // It contains two chbuf descriptors … … 35 36 unsigned long long fbf; // physical address + status for user buffer 0 36 37 unsigned int length; // buffer length (bytes) 37 unsigned int padding; // for 32bytes alignment38 unsigned int padding; // 8 bytes alignment 38 39 } fbf_chbuf_t; 40 41 ////////////////////////////////////////////////////////////////////////////////// 42 // This structure define the generic chained buffer used by the vci_chbuf_dma 43 // component to move a stream of containers to or from the vci_multi_nic component. 44 // The same structure is used for both TX or RX transfers. 45 // The single buffer size and the number of buffers must be defined by the 46 // GIET_NIC_CHBUF_SIZE and GIET_NIC_CHBUF_NBUFS parameters in giet_config.h. 47 // - The buffer array is the chbuf descriptor, shared by the vci_chbuf_dma, 48 // and by the kernel. 49 // - The index field is only used by the kernel. It define the currently pointed 50 // buffer for read (RX transfer) or write (TX transfer). 51 ////////////////////////////////////////////////////////////////////////////////// 52 53 typedef struct nic_chbuf_s 54 { 55 unsigned long long buffer[GIET_NIC_CHBUF_NBUFS]; // chbuf descriptor 56 unsigned int index; // current buffer index 57 unsigned int padding; // 8 bytes alignment 58 } nic_chbuf_t; 59 39 60 40 61 ////////////////////////////////////////////////////////////////////////////////// … … 72 93 ////////////////////////////////////////////////////////////////////////////// 73 94 74 int _sys_nic_alloc( );95 int _sys_nic_alloc( unsigned int is_rx ); 75 96 76 int _sys_nic_sync_send( void* vbuf ); 97 int _sys_nic_start( unsigned int is_rx, 98 unsigned int mac4, 99 unsigned int mac2 ); 77 100 78 int _sys_nic_sync_receive( void* vbuf ); 101 int _sys_nic_move( unsigned int is_rx, 102 void* buffer ); 103 104 int _sys_nic_stop( unsigned int is_rx ); 79 105 80 106 //////////////////////////////////////////////////////////////////////////////
Note: See TracChangeset
for help on using the changeset viewer.