Changeset 528 for soft/giet_vm/giet_kernel/sys_handler.c
- Timestamp:
- Mar 27, 2015, 11:43:48 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/giet_kernel/sys_handler.c
r519 r528 61 61 #endif 62 62 63 64 63 //////////////////////////////////////////////////////////////////////////// 65 // Coprocessors loks and synchronisation variables64 // Extern variables 66 65 //////////////////////////////////////////////////////////////////////////// 67 66 68 __attribute__((section(".kdata"))) 69 simple_lock_t _coproc_lock[X_SIZE*Y_SIZE]; 70 71 __attribute__((section(".kdata"))) 72 unsigned int _coproc_done[X_SIZE*Y_SIZE]; 67 // allocated in tty0.c file. 68 extern sqt_lock_t _tty0_sqt_lock; 69 70 // allocated in mwr_driver.c file. 71 extern simple_lock_t _coproc_lock[X_SIZE*Y_SIZE]; 72 extern unsigned int _coproc_done[X_SIZE*Y_SIZE]; 73 74 // allocated in tty_driver.c file. 75 extern unsigned int _tty_rx_full[NB_TTY_CHANNELS]; 76 extern unsigned int _tty_rx_buf[NB_TTY_CHANNELS]; 73 77 74 78 //////////////////////////////////////////////////////////////////////////// … … 91 95 __attribute__((section(".kdata"))) 92 96 unsigned int _nic_tx_channel_allocator = 0; 93 94 ////////////////////////////////////////////////////////////////////////////95 // These global variables are allocated in tty0.c and tty_driver.c files.96 ////////////////////////////////////////////////////////////////////////////97 98 extern sqt_lock_t _tty0_sqt_lock;99 100 extern unsigned int _tty_rx_full[NB_TTY_CHANNELS];101 102 extern unsigned int _tty_rx_buf[NB_TTY_CHANNELS];103 97 104 98 //////////////////////////////////////////////////////////////////////////// … … 157 151 &_sys_ukn, /* 0x17 */ 158 152 &_sys_ukn, /* 0x18 */ 159 &_ context_switch,/* 0x19 */153 &_sys_context_switch, /* 0x19 */ 160 154 &_sys_vseg_get_vbase, /* 0x1A */ 161 155 &_sys_vseg_get_length, /* 0x1B */ … … 355 349 unsigned int size = desc->buffer_size; 356 350 357 // these variables are used for the v2p translations 358 unsigned int ptab = _get_context_slot(CTX_PTAB_ID); 359 unsigned int ppn; 360 unsigned int flags; 351 // physical addresses 361 352 unsigned long long buffer_paddr; 362 353 unsigned int buffer_lsb; … … 369 360 unsigned int lock_msb; 370 361 362 unsigned int flags; // unused 363 371 364 // compute memory buffer physical address 372 _v2p_translate( (page_table_t*)ptab, 373 desc->buffer_vaddr>>12, 374 &ppn, 375 &flags ); 376 buffer_paddr = (((unsigned long long)ppn) << 12) | 377 (desc->buffer_vaddr & 0x00000FFF); 378 buffer_lsb = (unsigned int)buffer_paddr; 379 buffer_msb = (unsigned int)(buffer_paddr>>32); 365 buffer_paddr = _v2p_translate( desc->buffer_vaddr , &flags ); 366 buffer_lsb = (unsigned int)buffer_paddr; 367 buffer_msb = (unsigned int)(buffer_paddr>>32); 380 368 381 369 // call MWMR_DMA driver … … 385 373 _mwr_set_channel_register( cluster_xy, channel, CHANNEL_BUFFER_MSB, buffer_msb ); 386 374 387 // compute MWMR descriptor and lock physical addresses (if required)388 375 if ( mode == MODE_MWMR ) 389 376 { 390 _v2p_translate( (page_table_t*)ptab, 391 desc->mwmr_vaddr>>12, 392 &ppn, 393 &flags ); 394 mwmr_paddr = (((unsigned long long)ppn) << 12) | 395 (desc->mwmr_vaddr & 0x00000FFF); 377 // compute MWMR descriptor physical address 378 mwmr_paddr = _v2p_translate( desc->mwmr_vaddr , &flags ); 396 379 mwmr_lsb = (unsigned int)mwmr_paddr; 397 380 mwmr_msb = (unsigned int)(mwmr_paddr>>32); 398 399 _v2p_translate( (page_table_t*)ptab,400 desc->lock_vaddr>>12,401 &ppn,402 &flags );403 lock_paddr = (((unsigned long long)ppn) << 12) |404 (desc->lock_vaddr & 0x00000FFF);405 lock_lsb = (unsigned int)lock_paddr;406 lock_msb = (unsigned int)(lock_paddr>>32);407 381 408 382 // call MWMR_DMA driver 409 383 _mwr_set_channel_register( cluster_xy, channel, CHANNEL_MWMR_LSB, mwmr_lsb ); 410 384 _mwr_set_channel_register( cluster_xy, channel, CHANNEL_MWMR_MSB, mwmr_msb ); 385 386 // compute lock physical address 387 lock_paddr = _v2p_translate( desc->lock_vaddr , &flags ); 388 lock_lsb = (unsigned int)lock_paddr; 389 lock_msb = (unsigned int)(lock_paddr>>32); 390 391 // call MWMR_DMA driver 411 392 _mwr_set_channel_register( cluster_xy, channel, CHANNEL_LOCK_LSB, lock_lsb ); 412 393 _mwr_set_channel_register( cluster_xy, channel, CHANNEL_LOCK_MSB, lock_msb ); … … 740 721 unsigned long long ker_chbuf_pbase; // kernel chbuf physical address 741 722 742 // These variables are used for the various V2P translation743 unsigned int ptab = _get_context_slot(CTX_PTAB_ID);744 unsigned int ppn;745 unsigned int flags;746 unsigned int vaddr;747 748 723 // allocate one kernel container per cluster in the (xmax / ymax) mesh 749 unsigned int cx; // cluster X coordinate 750 unsigned int cy; // cluster Y coordinate 751 unsigned int index; // container index in chbuf 752 unsigned long long cont_paddr; // container physical address 724 unsigned int cx; // cluster X coordinate 725 unsigned int cy; // cluster Y coordinate 726 unsigned int index; // container index in chbuf 727 unsigned int vaddr; // virtual address 728 unsigned long long cont_paddr; // container physical address 729 730 unsigned int flags; // for _v2p_translate() 753 731 754 732 for ( cx = 0 ; cx < xmax ; cx++ ) … … 770 748 771 749 // compute container physical address 772 _v2p_translate( (page_table_t*)ptab, 773 vaddr>>12, 774 &ppn, 775 &flags ); 776 cont_paddr = (((unsigned long long)ppn) << 12) | (vaddr & 0x00000FFF); 750 cont_paddr = _v2p_translate( vaddr , &flags ); 777 751 778 752 // initialize chbuf entry … … 816 790 if ( is_rx ) vaddr = (unsigned int)( &_nic_rx_chbuf[nic_channel] ); 817 791 else vaddr = (unsigned int)( &_nic_tx_chbuf[nic_channel] ); 818 _v2p_translate( (page_table_t*)ptab, 819 vaddr>>12, 820 &ppn, 821 &flags ); 822 ker_chbuf_pbase = (((unsigned long long)ppn) << 12) | (vaddr & 0x00000FFF); 792 793 ker_chbuf_pbase = _v2p_translate( vaddr , &flags ); 823 794 824 795 #if GIET_DEBUG_NIC … … 965 936 unsigned long long kernel_buffer_paddr; // kernel buffer physical address 966 937 unsigned long long kernel_chbuf_paddr; // kernel chbuf physical address 967 unsigned long long buffer_desc ;// kernel buffer descriptor968 unsigned long long buffer_desc_paddr; // kernel buffer descriptor p hysical address938 unsigned long long buffer_descriptor; // kernel buffer descriptor 939 unsigned long long buffer_desc_paddr; // kernel buffer descriptor paddr 969 940 unsigned int index; // kernel buffer index in chbuf 970 971 // The following variables are used for V2P translation 972 unsigned int ptab = _get_context_slot( CTX_PTAB_ID ); 973 unsigned int ppn; 974 unsigned int flags; 975 unsigned int vaddr; 941 unsigned int flags; // for _v2P_translate 976 942 977 943 // Compute user buffer physical address and check access rights 978 vaddr = (unsigned int)buffer; 979 _v2p_translate( (page_table_t*)ptab, 980 vaddr>>12, 981 &ppn, 982 &flags ); 944 user_buffer_paddr = _v2p_translate( (unsigned int)buffer , &flags ); 983 945 984 946 if ( (flags & PTE_U) == 0 ) … … 987 949 return -1; 988 950 } 989 user_buffer_paddr = ((unsigned long long)ppn << 12) | (vaddr & 0x00000FFF);990 951 991 952 #if GIET_DEBUG_NIC … … 995 956 996 957 // compute kernel chbuf physical address (required for sync) 997 vaddr = (unsigned int)chbuf; 998 _v2p_translate( (page_table_t*)ptab, 999 vaddr>>12, 1000 &ppn, 1001 &flags ); 1002 kernel_chbuf_paddr = ((unsigned long long)ppn << 12) | (vaddr & 0x00000FFF); 958 kernel_chbuf_paddr = _v2p_translate( (unsigned int)chbuf , &flags ); 1003 959 1004 960 // poll local kernel container status until success … … 1011 967 // inval buffer descriptor in L2 before read in L2 1012 968 _mmc_inval( buffer_desc_paddr , 8 ); 1013 buffer_desc = chbuf->buffer[index].desc;969 buffer_descriptor = chbuf->buffer[index].desc; 1014 970 1015 971 #if GIET_DEBUG_NIC 1016 972 _printf("\n[GIET DEBUG NIC] Task %d in _sys_nic_move() read buffer descriptor %d\n" 1017 973 " at cycle = %d / paddr = %l / buffer descriptor = %l\n", 1018 thread, index, _get_proctime(), buffer_desc_paddr, buffer_desc );974 thread, index, _get_proctime(), buffer_desc_paddr, buffer_descriptor ); 1019 975 #endif 1020 976 1021 977 // test buffer status and break if found 1022 if ( ( is_rx != 0 ) && (buffer_desc >> 63) == 1 ) break;1023 if ( ( is_rx == 0 ) && (buffer_desc >> 63) == 0 ) break;978 if ( ( is_rx != 0 ) && (buffer_descriptor >> 63) == 1 ) break; 979 if ( ( is_rx == 0 ) && (buffer_descriptor >> 63) == 0 ) break; 1024 980 } 1025 981 1026 982 // compute kernel buffer physical address 1027 kernel_buffer_paddr = buffer_desc & 0x0000FFFFFFFFFFFFULL;983 kernel_buffer_paddr = buffer_descriptor & 0x0000FFFFFFFFFFFFULL; 1028 984 1029 985 // move one container … … 1281 1237 #if NB_CMA_CHANNELS > 0 1282 1238 1283 unsigned int ptab; // page table virtual address1284 1239 unsigned int vaddr; // virtual address 1285 unsigned int flags; // protection flags 1286 unsigned int ppn; // physical page number 1240 unsigned int flags; // for _v2p_translate() 1287 1241 1288 1242 // get channel index … … 1308 1262 1309 1263 // checking user buffers virtual addresses and length alignment 1310 if ( ((unsigned int)vbase0 & 0x3) || ((unsigned int)vbase1 & 0x3) || (length & 0x3) ) 1311 { 1312 _printf("\n[GIET ERROR] in _fbf_cma_start() : user buffer not word aligned\n"); 1313 return -1; 1314 } 1315 1316 // get page table virtual address 1317 ptab = _get_context_slot(CTX_PTAB_ID); 1264 if ( ((unsigned int)vbase0 & 0x3) || 1265 ((unsigned int)vbase1 & 0x3) || 1266 (length & 0x3) ) 1267 { 1268 _printf("\n[GIET ERROR] in _fbf_cma_start() : user buffer not aligned\n"); 1269 return -1; 1270 } 1318 1271 1319 1272 // compute frame buffer physical address and initialize _fbf_chbuf[channel] 1320 vaddr = ((unsigned int)SEG_FBF_BASE); 1321 _v2p_translate( (page_table_t*) ptab, 1322 (vaddr >> 12), 1323 &ppn, 1324 &flags ); 1325 1326 _fbf_chbuf[channel].fbf.desc = ((paddr_t)ppn << 12) | (vaddr & 0x00000FFF); 1273 vaddr = (unsigned int)SEG_FBF_BASE; 1274 _fbf_chbuf[channel].fbf.desc = _v2p_translate( vaddr , &flags ); 1327 1275 1328 1276 // Compute user buffer 0 physical addresses and intialize _fbf_chbuf[channel] 1329 vaddr = (unsigned int)vbase0; 1330 _v2p_translate( (page_table_t*) ptab, 1331 (vaddr >> 12), 1332 &ppn, 1333 &flags ); 1277 vaddr = (unsigned int)vbase0; 1278 _fbf_chbuf[channel].buf0.desc = _v2p_translate( vaddr , &flags ); 1279 1334 1280 if ((flags & PTE_U) == 0) 1335 1281 { 1336 _printf("\n[GIET ERROR] in _fbf_cma_start() : user buffer 0 not in user space\n"); 1337 return -1; 1338 } 1339 1340 _fbf_chbuf[channel].buf0.desc = ((paddr_t)ppn << 12) | (vaddr & 0x00000FFF); 1282 _printf("\n[GIET ERROR] in _fbf_cma_start() : buf0 not in user space\n"); 1283 return -1; 1284 } 1341 1285 1342 1286 // Compute user buffer 1 physical addresses and intialize _fbf_chbuf[channel] 1343 vaddr = (unsigned int)vbase1; 1344 _v2p_translate( (page_table_t*) ptab, 1345 (vaddr >> 12), 1346 &ppn, 1347 &flags ); 1287 vaddr = (unsigned int)vbase1; 1288 _fbf_chbuf[channel].buf1.desc = _v2p_translate( vaddr , &flags ); 1289 1348 1290 if ((flags & PTE_U) == 0) 1349 1291 { 1350 _printf("\n[GIET ERROR] in _fbf_cma_start() : user buffer 1 not in user space\n"); 1351 return -1; 1352 } 1353 1354 _fbf_chbuf[channel].buf1.desc = ((paddr_t)ppn << 12) | (vaddr & 0x00000FFF); 1292 _printf("\n[GIET ERROR] in _fbf_cma_start() : buf1 not in user space\n"); 1293 return -1; 1294 } 1355 1295 1356 1296 // initializes buffer length … … 1358 1298 1359 1299 // Compute and register physical adress of the fbf_chbuf descriptor 1360 vaddr = (unsigned int)(&_fbf_chbuf[channel]); 1361 _v2p_translate( (page_table_t*) ptab, 1362 (vaddr >> 12), 1363 &ppn, 1364 &flags ); 1300 vaddr = (unsigned int)&_fbf_chbuf[channel]; 1301 _fbf_chbuf_paddr[channel] = _v2p_translate( vaddr , &flags ); 1365 1302 1366 _fbf_chbuf_paddr[channel] = (((paddr_t)ppn) << 12) | (vaddr & 0x00000FFF);1367 1368 1303 if ( USE_IOB ) 1369 1304 { … … 1594 1529 1595 1530 // deschedule 1596 _ context_switch();1531 _sys_context_switch(); 1597 1532 1598 1533 return 0; 1599 1534 } 1600 1535 1601 ////////////////////// 1602 int _ context_switch()1536 ///////////////////////// 1537 int _sys_context_switch() 1603 1538 { 1604 1539 unsigned int save_sr; … … 1755 1690 unsigned int* y ) 1756 1691 { 1757 unsigned int ppn;1758 1692 unsigned int flags; 1759 unsigned int vpn = (((unsigned int)ptr)>>12);1693 unsigned long long paddr = _v2p_translate( (unsigned int)ptr , &flags ); 1760 1694 1761 // get the page table pointer 1762 page_table_t* pt = (page_table_t*)_get_context_slot( CTX_PTAB_ID ); 1763 1764 // compute the physical address 1765 _v2p_translate( pt, vpn, &ppn, &flags ); 1766 1767 *x = (ppn>>24) & 0xF; 1768 *y = (ppn>>20) & 0xF; 1695 *x = (paddr>>36) & 0xF; 1696 *y = (paddr>>32) & 0xF; 1697 1769 1698 return 0; 1770 1699 }
Note: See TracChangeset
for help on using the changeset viewer.