Changeset 437 for soft/giet_vm/giet_drivers/dma_driver.c
- Timestamp:
- Nov 3, 2014, 10:53:00 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/giet_drivers/dma_driver.c
r345 r437 5 5 // Copyright (c) UPMC-LIP6 6 6 /////////////////////////////////////////////////////////////////////////////////// 7 // The dma_driver.c and dma_driver.h files are part ot the GIET-VM nano-kernel.8 // This driver supports the SoCLib vci_multi_dma component.9 //10 // It can exist several DMA controlers in the architecture (one per cluster),11 // and each controller can contain several channels.12 //13 // There is (NB_CLUSTERS * NB_DMA_CHANNELS) channels, indexed by a global index:14 // dma_id = cluster_xy * NB_DMA_CHANNELS + loc_id15 //16 // A DMA channel is a private ressource allocated to a given processor.17 // It is exclusively used by the kernet to speedup data transfers, and18 // there is no lock protecting exclusive access to the channel.19 // As the kernel uses a polling policy on the DMA_STATUS register to detect20 // transfer completion, the DMA IRQ is not used.21 //22 // The virtual base address of the segment associated to a channel is:23 // SEG_DMA_BASE + cluster_xy * PERI_CLUSTER_INCREMENT + DMA_SPAN * channel_id24 //25 // The SEG_DMA_BASE virtual address mus be defined in the hard_config.h file.26 ////////////////////////////////////////////////////////////////////////////////////27 7 28 8 #include <giet_config.h> … … 101 81 } 102 82 103 ////////////////////////////////////////////////////////////////////////////////// 104 // AS the GIET-VM uses a polling policy to detect transfer completion, 105 // The DMA component initialisation must disable interrupts. 106 // This function disables interrupts for one DMA channel in one cluster. 107 // Returns 0 if success, returns > 0 if error. 108 ////////////////////////////////////////////////////////////////////////////////// 83 //////////////////////////////////////////////// 109 84 unsigned int _dma_init( unsigned int cluster_xy, 110 85 unsigned int channel_id ) … … 127 102 } 128 103 129 ////////////////////////////////////////////////////////////////////////////////// 130 // This function re-initialises one DMA channel in one cluster after a transfer 131 // completion. It actually forces the channel to return in iDLE state. 132 ////////////////////////////////////////////////////////////////////////////////// 104 ////////////////////////////////////////////////// 133 105 unsigned int _dma_reset( unsigned int cluster_xy, 134 106 unsigned int channel_id ) … … 151 123 } 152 124 153 ////////////////////////////////////////////////////////////////////////////////// 154 // This function returns the status of a DMA channel in a given cluster 155 ////////////////////////////////////////////////////////////////////////////////// 125 ////////////////////////////////////////////////////// 156 126 unsigned int _dma_get_status( unsigned int cluster_xy, 157 127 unsigned int channel_id ) … … 173 143 } 174 144 175 ////////////////////////////////////////////////////////////////////////////////// 176 // This function sets the physical address (including 64 bits extension) 177 // for the source and destination buffers in a DMA channel in a given cluster 178 // and sets the transfer size to lauch the transfer. 179 ////////////////////////////////////////////////////////////////////////////////// 145 //////////////////////////////////////////////////////// 180 146 void _dma_start_transfer( unsigned int cluster_xy, // DMA cluster 181 147 unsigned int channel_id, // DMA channel … … 201 167 } 202 168 203 /////////////////////////////////////////////////////////////////////////////////// 204 // This function copies a source memory buffer to a destination memory buffer, 205 // using directly physical addresses. 206 // This blocking function is supposed to be used by the kernel only, 207 // and uses a polling policy on DMA_STATUS register to detect completion. 208 // Therefore, the DMA_IRQ is NOT used. 209 // The source and destination buffers base addresses must be word aligned, 210 // and the buffer's size must be multiple of 4. 211 // In case of error (buffer unmapped, unaligned, or DMA_STATUS error), an error 212 // message is displayed on TTY0, and the system crash. 213 /////////////////////////////////////////////////////////////////////////////////// 169 /////////////////////////////////////////////////////// 214 170 void _dma_physical_copy( unsigned int cluster_xy, // DMA cluster 215 171 unsigned int channel_id, // DMA channel … … 225 181 if ( (x >= X_SIZE) || (y >= Y_SIZE) || (channel_id >= NB_DMA_CHANNELS) ) 226 182 { 227 _p rintf("\n[GIETERROR] in _dma_physical_copy() : illegal DMA channel ");183 _puts("\n[DMA ERROR] in _dma_physical_copy() : illegal DMA channel "); 228 184 _exit(); 229 185 } … … 232 188 if ( (dst_paddr & 0x3) || (src_paddr & 0x3) || (size & 0x3) ) 233 189 { 234 _printf("\n[GIET ERROR] in _dma_physical_copy() : buffer unaligned\n"); 235 _exit(); 236 } 237 238 #if GIET_DEBUG_DMA_DRIVER 239 _printf("\n[DMA DEBUG] Start a dma_physical_copy on channel[%d,%d,%d] at cycle %d\n" 240 " - src_paddr = %l\n" 241 " - dst_paddr = %l\n" 242 " - bytes = %x\n", 243 x, y, channel_id, _get_proctime(), src_paddr, dst_paddr, size ); 190 _puts("\n[DMA ERROR] in _dma_physical_copy() : buffer unaligned\n"); 191 _exit(); 192 } 193 194 #if GIET_DEBUG_DMA_DRIVER 195 _puts("\n[DMA DEBUG] enter _dma_physical_copy() for channel["); 196 _putd( x ); 197 _puts(","); 198 _putd( y ); 199 _puts(","); 200 _putd( channel_id ); 201 _puts("] at cycle "); 202 _putd( _get_proctime() ); 203 _puts("\n - src_paddr = "); 204 _putl( src_paddr ); 205 _puts("\n - dst_paddr = "); 206 _putl( dst_paddr ); 207 _puts("\n - bytes = "); 208 _putd( size ); 209 _puts("\n"); 244 210 #endif 245 211 … … 256 222 257 223 #if GIET_DEBUG_DMA_DRIVER 258 _p rintf("\n[DMA DEBUG] _dma_physical_copy() : ... waiting on DMA_STATUS register\n");224 _puts("\n[DMA DEBUG] _dma_physical_copy() : ... waiting on DMA_STATUS register\n"); 259 225 #endif 260 226 … … 264 230 if( status != DMA_SUCCESS ) 265 231 { 266 _printf("\n[GIET ERROR] in _dma_physical_copy() : DMA_STATUS = %x\n", status ); 267 _exit(); 268 } 232 _puts("\n[DMA ERROR] in _dma_physical_copy() : bad DMA_STATUS"); 233 _exit(); 234 } 235 269 236 // reset dma channel 270 237 _dma_reset( cluster_xy, channel_id ); 271 238 272 239 #if GIET_DEBUG_DMA_DRIVER 273 _printf("\n[DMA DEBUG] _dma_physical_copy() completed at cycle %d\n", _get_proctime() ); 240 _puts("\n[DMA DEBUG] exit _dma_physical_copy() at cycle "); 241 _putd( _get_proctime() ); 242 _puts("\n"); 274 243 #endif 275 244 276 245 #else // NB_DMA_CHANNELS == 0 277 _printf("\n[GIET ERROR] in _dma_physical_copy() : NB_DMA_CHANNELS == 0 / cycle %d\n", 278 _get_proctime);246 247 _puts("\n[DMA ERROR] in _dma_physical_copy() : NB_DMA_CHANNELS == 0\n"); 279 248 _exit(); 280 #endif 281 } 282 283 /////////////////////////////////////////////////////////////////////////////////// 284 // This function copies a source memory buffer to a destination memory buffer, 285 // making virtual to physical address translation: the MMU should be activated. 286 // This blocking function is supposed to be used by the kernel only, 287 // and uses a polling policy on DMA_STATUS register to detect completion. 288 // Therefore, the DMA_IRQ is NOT used. 289 // The source and destination buffers base addresses must be word aligned, 290 // and the buffer's size must be multiple of 4. 291 // In case of error (buffer unmapped, unaligned, or DMA_STATUS error), an error 292 // message is displayed on TTY0, and the system crash. 293 /////////////////////////////////////////////////////////////////////////////////// 249 250 #endif 251 } 252 253 254 //////////////////////////////////////// 294 255 void _dma_copy( unsigned int cluster_xy, // DMA cluster 295 256 unsigned int channel_id, // DMA channel … … 306 267 if ( (x >= X_SIZE) || (y >= Y_SIZE) || (channel_id >= NB_DMA_CHANNELS) ) 307 268 { 308 _p rintf("\n[GIETERROR] in _dma_copy() : illegal DMA channel ");269 _puts("\n[DMA ERROR] in _dma_copy() : illegal DMA channel "); 309 270 _exit(); 310 271 } … … 313 274 if ( (dst_vaddr & 0x3) || (src_vaddr & 0x3) || (size & 0x3) ) 314 275 { 315 _p rintf("\n[GIETERROR] in _dma_copy() : buffer unaligned\n");276 _puts("\n[DMA ERROR] in _dma_copy() : buffer unaligned\n"); 316 277 _exit(); 317 278 } … … 322 283 323 284 #if GIET_DEBUG_DMA_DRIVER 324 _printf("\n[DMA DEBUG] Start a dma_copy on channel[%d,%d,%d] at cycle %d\n" 325 " - src_vaddr = %x\n" 326 " - dst_vaddr = %x\n" 327 " - bytes = %x\n", 328 x, y, channel_id, _get_proctime(), src_vaddr, dst_vaddr, size ); 285 _puts("\n[DMA DEBUG] enter _dma_copy() for channel["); 286 _putd( x ); 287 _puts(","); 288 _putd( y ); 289 _puts(","); 290 _putd( channel_id ); 291 _puts("] at cycle "); 292 _putd( _get_proctime() ); 293 _puts("\n - src_vaddr = "); 294 _putx( src_vaddr ); 295 _puts("\n - dst_vaddr = "); 296 _putx( dst_vaddr ); 297 _puts("\n - bytes = "); 298 _putd( size ); 299 _puts("\n"); 329 300 #endif 330 301 … … 334 305 (size & 0x3) ) 335 306 { 336 _p rintf("\n[GIETERROR] in _dma_copy() : buffer unaligned\n");307 _puts("\n[DMA ERROR] in _dma_copy() : buffer unaligned\n"); 337 308 _exit(); 338 309 } … … 348 319 if ( ko ) 349 320 { 350 _p rintf("\n[GIETERROR] in _dma_copy() : source buffer unmapped\n");321 _puts("\n[DMA ERROR] in _dma_copy() : source buffer unmapped\n"); 351 322 _exit(); 352 323 } … … 361 332 if ( ko ) 362 333 { 363 _p rintf("\n[GIETERROR] in _dma_copy() : dest buffer unmapped\n");334 _puts("\n[DMA ERROR] in _dma_copy() : dest buffer unmapped\n"); 364 335 _exit(); 365 336 } … … 368 339 369 340 #if GIET_DEBUG_DMA_DRIVER 370 _printf(" - src_paddr = %l\n" 371 " - dst_paddr = %l\n", 372 src_paddr, dst_paddr ); 341 _puts("\n - src_paddr = "); 342 _putl( src_paddr ); 343 _puts("\n - dst_paddr = "); 344 _putl( dst_paddr ); 345 _puts("\n"); 373 346 #endif 374 347 … … 385 358 386 359 #if GIET_DEBUG_DMA_DRIVER 387 _p rintf("\n[DMA DEBUG] _dma_copy() : ... waiting on DMA_STATUS register\n");360 _puts("\n[DMA DEBUG] _dma_copy() : ... waiting on DMA_STATUS register\n"); 388 361 #endif 389 362 … … 393 366 if( status != DMA_SUCCESS ) 394 367 { 395 _p rintf("\n[GIET ERROR] in _dma_copy() : DMA_STATUS = %x\n", status);368 _puts("\n[DMA ERROR] in _dma_copy() : bad DMA_STATUS\n"); 396 369 _exit(); 397 370 } … … 400 373 401 374 #if GIET_DEBUG_DMA_DRIVER 402 _printf("\n[DMA DEBUG] _dma_copy() completed at cycle %d\n", _get_proctime() ); 375 _puts("\n[DMA DEBUG] exit _dma_copy() at cycle "); 376 _putd( _get_proctime() ); 377 _puts("\n"); 403 378 #endif 404 379 405 380 #else // NB_DMA_CHANNELS == 0 406 _printf("\n[GIET ERROR] in _dma_copy() : NB_DMA_CHANNELS == 0 / cycle %d\n", 407 _get_proctime);381 382 _puts("\n[DMA ERROR] in _dma_copy() : NB_DMA_CHANNELS == 0\n"); 408 383 _exit(); 384 409 385 #endif 410 386 } // end _dma_copy 411 387 412 /////////////////////////////////////////////////////////////////////////////// 413 // This ISR handles the IRQ generated by a DMA channel. 414 /////////////////////////////////////////////////////////////////////////////// 388 ///////////////////////////////////// 415 389 void _dma_isr( unsigned int irq_type, 416 390 unsigned int irq_id, 417 391 unsigned int channel ) 418 392 { 419 _printf("\n[GIET ERROR] _dma_isr() not implemented / cycle %d\n", 420 _get_proctime() ); 393 _puts("\n[DMA ERROR] _dma_isr() not implemented\n"); 421 394 _exit(); 422 395 }
Note: See TracChangeset
for help on using the changeset viewer.