Changeset 430 for soft/giet_vm/giet_common
- Timestamp:
- Oct 4, 2014, 3:21:56 PM (10 years ago)
- Location:
- soft/giet_vm/giet_common
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/giet_common/utils.c
r408 r430 20 20 21 21 // This global variable is allocated in the boot.c file or in kernel_init.c file 22 extern static_scheduler_t* _schedulers[ NB_PROCS_MAX<<(X_WIDTH+Y_WIDTH)];22 extern static_scheduler_t* _schedulers[X_SIZE][Y_SIZE][NB_PROCS_MAX]; 23 23 24 24 /////////////////////////////////////////////////////////////////////////////////// … … 72 72 asm volatile ( "mfc0 %0, $15, 1 \n" 73 73 :"=r" (ret) ); 74 return (ret & 0x 3FF);74 return (ret & 0xFFF); 75 75 } 76 76 //////////////////////////// … … 173 173 174 174 //////////////////////////////////////////////////////////////////////////// 175 // This function makes a physical read access to a 32 bits word in memory,176 // after a temporary DTLB de-activation and paddr extension.177 ////////////////////////////////////////////////////////////////////////////178 175 unsigned int _physical_read( unsigned long long paddr ) 179 176 { … … 202 199 } 203 200 //////////////////////////////////////////////////////////////////////////// 204 // This function makes a physical write access to a 32 bits word in memory,205 // after a temporary DTLB de-activation and paddr extension.206 ////////////////////////////////////////////////////////////////////////////207 201 void _physical_write( unsigned long long paddr, 208 202 unsigned int value ) 209 203 { 210 204 unsigned int lsb = (unsigned int)paddr; … … 212 206 unsigned int sr; 213 207 214 208 _it_disable(&sr); 215 209 216 210 asm volatile( "mfc2 $2, $1 \n" /* $2 <= MMU_MODE */ … … 232 226 233 227 //////////////////////////////////////////////////////////////////////////// 234 // This function makes a physical read access to a 64 bits word in memory,235 // after a temporary DTLB de-activation and paddr extension.236 ////////////////////////////////////////////////////////////////////////////237 228 unsigned long long _physical_read_ull( unsigned long long paddr ) 238 229 { … … 266 257 267 258 //////////////////////////////////////////////////////////////////////////// 268 // This function makes a physical write access to a 64 bits word in memory,269 // after a temporary DTLB de-activation and paddr extension.270 ////////////////////////////////////////////////////////////////////////////271 259 void _physical_write_ull( unsigned long long paddr, 272 260 unsigned long long value ) … … 304 292 // multiple of 4 bytes. 305 293 /////////////////////////////////////////////////////////////////////////////////// 306 void _physical_memcpy( unsigned long long dst_paddr, // dest buffer paddr294 void _physical_memcpy( unsigned long long dst_paddr, // destination buffer paddr 307 295 unsigned long long src_paddr, // source buffer paddr 308 296 unsigned int size ) // bytes … … 352 340 353 341 _it_restore(&sr); 354 } 355 356 /////////////////////////////////////////////////////////////////////////////////// 357 // This function is used by several drivers (_xxx_set_register() function) 358 // If the MMU is not activated, the virtual address is extended using 359 // X_IO and Y_IO to reach the cluster_io. 342 } // end _physical_memcpy() 343 344 ///////////////////////////////////////////////////////////////////////////////// 345 void _physical_memset( unsigned long long paddr, // destination buffer paddr 346 unsigned int size, // bytes 347 unsigned int data ) // written value 348 { 349 // check alignment constraints 350 if ( (paddr & 3) || (size & 3) ) 351 { 352 _printf("\n[GIET ERROR] in _physical_memset() : buffer unaligned\n"); 353 _exit(); 354 } 355 356 unsigned int lsb = (unsigned int)paddr; 357 unsigned int msb = (unsigned int)(paddr >> 32); 358 unsigned int sr; 359 360 _it_disable(&sr); 361 362 asm volatile( "move $4, %0 \n" /* $4 < lsb */ 363 "move $5, %1 \n" /* $5 < msb */ 364 "move $6, %2 \n" /* $6 < size */ 365 "move $7, %3 \n" /* $7 < data */ 366 367 "mfc2 $2, $1 \n" /* $2 <= current MMU_MODE */ 368 "andi $3, $2, 0xb \n" /* $3 <= new MMU_MODE */ 369 "mtc2 $3, $1 \n" /* DTLB off */ 370 "mtc2 $5, $24 \n" /* PADDR_EXT <= msb */ 371 372 "ph_memset_loop: \n" 373 "sw $7, 0($4) \n" /* data <= *src_paddr */ 374 "addi $4, $4, 4 \n" /* iter = iter - 1 */ 375 "bne $4, $6, ph_memcpy_loop \n" 376 "nop \n" 377 378 "mtc2 $0, $24 \n" /* PADDR_EXT <= 0 */ 379 "mtc2 $2, $1 \n" /* restore MMU_MODE */ 380 : "=r" (data) 381 : "r" (lsb), "r" (msb), "r" (size), "r"(data) 382 : "$2", "$3", "$4", "$5", "$6", "$7" ); 383 384 _it_restore(&sr); 385 } // _pysical_memset() 386 360 387 /////////////////////////////////////////////////////////////////////////////////// 361 388 void _io_extended_write( unsigned int* vaddr, … … 378 405 379 406 /////////////////////////////////////////////////////////////////////////////////// 380 // This function is used by all drivers (_xxx_get_register() function)381 // If the MMU is not activated, the virtual address is extended using382 // X_IO and Y_IO to reach the cluster_io.383 ///////////////////////////////////////////////////////////////////////////////////384 407 unsigned int _io_extended_read( unsigned int* vaddr ) 385 408 { … … 402 425 /////////////////////////////////////////////////////////////////////////////////// 403 426 404 ///////////////////////////////////////////////////////////////////////////////////405 // Takes a lock with a blocking ll/sc atomic access.406 // When the cache coherence is granted by the hardware,407 // the first read is a standard (cacheable) lw, as the local copy408 // can be polled when the lock is already taken by another task, reducing409 // trafic on the interconnect. When the lock is released by the owner task,410 // the local copy is updated or invalidated by the coherence protocol.411 // If there is no hardware cache coherence a random delay is introduced412 // betwween two successive retry.413 427 /////////////////////////////////////////////////////////////////////////////////// 414 428 void _get_lock(giet_lock_t* lock) … … 460 474 } 461 475 462 ///////////////////////////////////////////////////////////////////////////////////463 // Release a previouly taken lock.464 476 /////////////////////////////////////////////////////////////////////////////////// 465 477 void _release_lock(giet_lock_t* lock) … … 711 723 { 712 724 unsigned int procid = _get_procid(); 713 unsigned int lpid = procid % NB_PROCS_MAX; 714 unsigned int cluster_xy = procid / NB_PROCS_MAX; 715 unsigned int x = cluster_xy >> Y_WIDTH; 716 unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); 725 unsigned int x = (procid >> (Y_WIDTH + P_WIDTH)) & ((1<<X_WIDTH)-1); 726 unsigned int y = (procid >> P_WIDTH) & ((1<<Y_WIDTH)-1); 727 unsigned int lpid = procid & ((1<<P_WIDTH)-1); 717 728 718 729 _puts("\n\n[GIET ERROR] in _printf() for processor["); … … 744 755 745 756 746 ////////////////////////////////////////////////////////////////////////////// 757 //////////////////////////////////////////////////////////////////////////////////// 747 758 // Scheduler and tasks context access functions 748 ////////////////////////////////////////////////////////////////////////////// 749 750 ////////////////////////////////////////////////////////////////////////////// 751 // Returns index of the currently running task from the processor scheduler. 752 ////////////////////////////////////////////////////////////////////////////// 759 //////////////////////////////////////////////////////////////////////////////////// 760 761 762 //////////////////////////////////////////////////////////////////////////////////// 753 763 unsigned int _get_current_task_id() 754 764 { … … 757 767 } 758 768 //////////////////////////////////////////////////////////////////////////////////// 759 // This function returns the content of a context slot 760 // for a task identified by the ltid argument (local task index), 761 // and the gpid argument (global processor index) 762 //////////////////////////////////////////////////////////////////////////////////// 763 unsigned int _get_task_slot( unsigned int gpid, 769 unsigned int _get_task_slot( unsigned int x, 770 unsigned int y, 771 unsigned int p, 764 772 unsigned int ltid, 765 773 unsigned int slot ) 766 774 { 767 static_scheduler_t* psched = (static_scheduler_t*)_schedulers[ gpid];775 static_scheduler_t* psched = (static_scheduler_t*)_schedulers[x][y][p]; 768 776 return psched->context[ltid][slot]; 769 777 } 770 778 //////////////////////////////////////////////////////////////////////////////////// 771 // This function updates the content of a context slot 772 // for any task identified by the ltid argument (local task index), 773 // and the gpid argument (global processor index) 774 //////////////////////////////////////////////////////////////////////////////////// 775 void _set_task_slot( unsigned int gpid, 779 void _set_task_slot( unsigned int x, 780 unsigned int y, 781 unsigned int p, 776 782 unsigned int ltid, 777 783 unsigned int slot, 778 784 unsigned int value ) 779 785 { 780 static_scheduler_t* psched = (static_scheduler_t*)_schedulers[ gpid];786 static_scheduler_t* psched = (static_scheduler_t*)_schedulers[x][y][p]; 781 787 psched->context[ltid][slot] = value; 782 788 } 783 ////////////////////////////////////////////////////////////////////////////////////784 // This function returns the content of a context slot785 // for the running task (defined by the scheduler current field).786 789 //////////////////////////////////////////////////////////////////////////////////// 787 790 unsigned int _get_context_slot( unsigned int slot ) … … 791 794 return psched->context[task_id][slot]; 792 795 } 793 ////////////////////////////////////////////////////////////////////////////////////794 // This function updates the content of a context slot for the running task.795 796 //////////////////////////////////////////////////////////////////////////////////// 796 797 void _set_context_slot( unsigned int slot, … … 968 969 { 969 970 unsigned int procid = _get_procid(); 970 unsigned int lpid = procid % NB_PROCS_MAX; 971 unsigned int cluster_xy = procid / NB_PROCS_MAX; 972 unsigned int x = cluster_xy >> Y_WIDTH; 973 unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); 971 unsigned int x = (procid >> (Y_WIDTH + P_WIDTH)) & ((1<<X_WIDTH)-1); 972 unsigned int y = (procid >> P_WIDTH) & ((1<<Y_WIDTH)-1); 973 unsigned int lpid = procid & ((1<<P_WIDTH)-1); 974 974 975 975 -
soft/giet_vm/giet_common/utils.h
r408 r430 8 8 // They define more or less the GIET-VM Hardware Abstraction Layer, 9 9 // and contains various utility functions, that can be used by both the 10 // boot code and the kernel code .10 // boot code and the kernel code (but not by the user applications). 11 11 /////////////////////////////////////////////////////////////////////////////////// 12 12 … … 150 150 /////////////////////////////////////////////////////////////////////////////////// 151 151 /////////////////////////////////////////////////////////////////////////////////// 152 // Physical addressing related functions 153 /////////////////////////////////////////////////////////////////////////////////// 154 /////////////////////////////////////////////////////////////////////////////////// 155 152 // Physical addressing functions 153 /////////////////////////////////////////////////////////////////////////////////// 154 /////////////////////////////////////////////////////////////////////////////////// 155 156 //////////////////////////////////////////////////////////////////////////// 157 // This function makes a physical read access to a 32 bits word in memory, 158 // after a temporary DTLB de-activation and paddr extension. 159 //////////////////////////////////////////////////////////////////////////// 156 160 extern unsigned int _physical_read( unsigned long long paddr ); 161 162 //////////////////////////////////////////////////////////////////////////// 163 // This function makes a physical write access to a 32 bits word in memory, 164 // after a temporary DTLB de-activation and paddr extension. 165 //////////////////////////////////////////////////////////////////////////// 157 166 extern void _physical_write( unsigned long long paddr, 158 167 unsigned int value ); 159 168 169 //////////////////////////////////////////////////////////////////////////// 170 // This function makes a physical read access to a 64 bits word in memory, 171 // after a temporary DTLB de-activation and paddr extension. 172 //////////////////////////////////////////////////////////////////////////// 160 173 extern unsigned long long _physical_read_ull( unsigned long long paddr ); 174 175 //////////////////////////////////////////////////////////////////////////// 176 // This function makes a physical write access to a 64 bits word in memory, 177 // after a temporary DTLB de-activation and paddr extension. 178 //////////////////////////////////////////////////////////////////////////// 161 179 extern void _physical_write_ull( unsigned long long paddr, 162 180 unsigned long long value ); 163 181 182 /////////////////////////////////////////////////////////////////////////////////// 183 // This function makes a memcpy from a source buffer to a destination buffer, 184 // using physical addresses, after a temporary DTLB de-activation. 185 // The source and destination buffers must be word aligned, and size must be 186 // multiple of 4 bytes. 187 /////////////////////////////////////////////////////////////////////////////////// 164 188 extern void _physical_memcpy( unsigned long long dst_paddr, 165 189 unsigned long long src_paddr, 166 190 unsigned int size ); 167 191 192 /////////////////////////////////////////////////////////////////////////////////// 193 // This function set a data value in all words of a destination buffer, 194 // using physical addresses, after a temporary DTLB de-activation. 195 // The destination buffer must be word aligned, and size multiple of 4 bytes. 196 /////////////////////////////////////////////////////////////////////////////////// 197 extern void _physical_memset( unsigned long long buf_paddr, 198 unsigned int size, 199 unsigned int data ); 200 201 /////////////////////////////////////////////////////////////////////////////////// 202 // This function is used by several drivers (_xxx_get_register() function). 203 // If the MMU is not activated, the virtual address is extended using 204 // X_IO and Y_IO to reach the cluster_io. 205 /////////////////////////////////////////////////////////////////////////////////// 168 206 extern unsigned int _io_extended_read( unsigned int* vaddr ); 207 208 /////////////////////////////////////////////////////////////////////////////////// 209 // This function is used by all drivers (_xxx_set_register() function) 210 // If the MMU is not activated, the virtual address is extended using 211 // X_IO and Y_IO to reach the cluster_io. 212 /////////////////////////////////////////////////////////////////////////////////// 169 213 extern void _io_extended_write( unsigned int* vaddr, 170 214 unsigned int value ); … … 174 218 /////////////////////////////////////////////////////////////////////////////////// 175 219 220 221 /////////////////////////////////////////////////////////////////////////////////// 222 // Takes a lock with a blocking ll/sc atomic access. 223 // - When the cache coherence is granted by the hardware, 224 // the first read is a standard (cacheable) lw, as the local copy 225 // can be polled when the lock is already taken by another task, reducing 226 // trafic on the interconnect. When the lock is released by the owner task, 227 // the local copy is updated or invalidated by the coherence protocol. 228 // - If there is no hardware cache coherence a random delay is introduced 229 // between two successive retry. 230 /////////////////////////////////////////////////////////////////////////////////// 176 231 extern void _get_lock(giet_lock_t* lock); 232 233 /////////////////////////////////////////////////////////////////////////////////// 234 // Release a previouly taken lock. 235 /////////////////////////////////////////////////////////////////////////////////// 177 236 extern void _release_lock(giet_lock_t* lock); 237 178 238 179 239 /////////////////////////////////////////////////////////////////////////////////// … … 190 250 extern void _getc( char* byte ); 191 251 252 192 253 /////////////////////////////////////////////////////////////////////////////////// 193 254 // Scheduler and task context access functions 194 255 /////////////////////////////////////////////////////////////////////////////////// 195 256 257 258 /////////////////////////////////////////////////////////////////////////////////// 259 // Returns index of the currently running task from the processor scheduler. 260 /////////////////////////////////////////////////////////////////////////////////// 196 261 extern unsigned int _get_current_task_id(void); 197 262 198 extern unsigned int _get_task_slot( unsigned int gpid, 263 //////////////////////////////////////////////////////////////////////////////////// 264 // This function returns the content of a context slot 265 // for a task identified by the ltid argument (local task index), 266 // and a processor identified by the (x,y,p) arguments. 267 //////////////////////////////////////////////////////////////////////////////////// 268 extern unsigned int _get_task_slot( unsigned int x, 269 unsigned int y, 270 unsigned int p, 199 271 unsigned int ltid, 200 272 unsigned int slot ); 201 extern void _set_task_slot( unsigned int gpid, 273 274 //////////////////////////////////////////////////////////////////////////////////// 275 // This function updates the content of a context slot 276 // for any task identified by the ltid argument (local task index), 277 // and a processor identified by the (x,y,p) arguments. 278 //////////////////////////////////////////////////////////////////////////////////// 279 extern void _set_task_slot( unsigned int x, 280 unsigned int y, 281 unsigned int p, 202 282 unsigned int ltid, 203 283 unsigned int slot, 204 284 unsigned int value ); 205 285 286 //////////////////////////////////////////////////////////////////////////////////// 287 // This function returns the content of a context slot for the running task. 288 //////////////////////////////////////////////////////////////////////////////////// 206 289 extern unsigned int _get_context_slot( unsigned int slot ); 290 291 //////////////////////////////////////////////////////////////////////////////////// 292 // This function updates the content of a context slot for the running task. 293 //////////////////////////////////////////////////////////////////////////////////// 207 294 extern void _set_context_slot( unsigned int slot, 208 295 unsigned int value );
Note: See TracChangeset
for help on using the changeset viewer.