Changeset 529 for soft/giet_vm/giet_drivers/dma_driver.c
- Timestamp:
- Mar 27, 2015, 11:51:33 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/giet_drivers/dma_driver.c
r496 r529 88 88 89 89 //////////////////////////////////////////////// 90 unsigned int _dma_init( unsigned int cluster_xy,91 92 { 93 #if NB_DMA_CHANNELS > 0 94 95 // parameters checking90 void _dma_disable_irq( unsigned int cluster_xy, 91 unsigned int channel_id ) 92 { 93 #if NB_DMA_CHANNELS > 0 94 95 // check DMA channel parameters 96 96 unsigned int x = cluster_xy >> Y_WIDTH; 97 97 unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); 98 if (x >= X_SIZE) return 1; 99 if (y >= Y_SIZE) return 1; 100 if (channel_id >= NB_DMA_CHANNELS) return 1; 98 if ( (x >= X_SIZE) || (y >= Y_SIZE) || (channel_id >= NB_DMA_CHANNELS) ) 99 { 100 _puts("\n[DMA ERROR] in _dma_disable_irq() : illegal DMA channel "); 101 _exit(); 102 } 101 103 102 104 // disable interrupt for selected channel 103 105 _dma_set_register(cluster_xy, channel_id, DMA_IRQ_DISABLE, 1); 104 return 0; 105 #else 106 return 1; 107 #endif 108 } 109 110 ////////////////////////////////////////////////// 111 unsigned int _dma_reset( unsigned int cluster_xy, 106 107 #endif 108 } 109 110 ///////////////////////////////////////////////// 111 void _dma_reset_channel( unsigned int cluster_xy, 112 112 unsigned int channel_id ) 113 113 { 114 114 #if NB_DMA_CHANNELS > 0 115 115 116 // parameters checking116 // check DMA channel parameters 117 117 unsigned int x = cluster_xy >> Y_WIDTH; 118 118 unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); 119 if (x >= X_SIZE) return 1; 120 if (y >= Y_SIZE) return 1; 121 if (channel_id >= NB_DMA_CHANNELS) return 1; 119 if ( (x >= X_SIZE) || (y >= Y_SIZE) || (channel_id >= NB_DMA_CHANNELS) ) 120 { 121 _puts("\n[DMA ERROR] in _dma_reset_channel() : illegal DMA channel "); 122 _exit(); 123 } 122 124 123 125 // reset selected channel 124 126 _dma_set_register(cluster_xy, channel_id, DMA_RESET, 0); 125 return 0; 126 #else 127 return 1; 128 #endif 129 } 130 131 ////////////////////////////////////////////////////// 132 unsigned int _dma_get_status( unsigned int cluster_xy, 133 unsigned int channel_id ) 134 { 135 #if NB_DMA_CHANNELS > 0 136 137 // parameters checking 127 128 #endif 129 } 130 131 /////////////////////////////////////////////////////// 132 void _dma_get_status( unsigned int cluster_xy, 133 unsigned int channel_id, 134 unsigned int* status ) 135 { 136 #if NB_DMA_CHANNELS > 0 137 138 // check DMA channel parameters 138 139 unsigned int x = cluster_xy >> Y_WIDTH; 139 140 unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); 140 if (x >= X_SIZE) return 1; 141 if (y >= Y_SIZE) return 1; 142 if (channel_id >= NB_DMA_CHANNELS) return 1; 143 144 // get selected channel status 145 return _dma_get_register(cluster_xy, channel_id, DMA_LEN); 146 #else 147 return DMA_IDLE; 141 if ( (x >= X_SIZE) || (y >= Y_SIZE) || (channel_id >= NB_DMA_CHANNELS) ) 142 { 143 _puts("\n[DMA ERROR] in _dma_get_status() : illegal DMA channel "); 144 _exit(); 145 } 146 147 // returns selected channel status 148 *status = _dma_get_register(cluster_xy, channel_id, DMA_LEN); 149 148 150 #endif 149 151 } … … 157 159 { 158 160 #if NB_DMA_CHANNELS > 0 161 162 // check DMA channel parameters 163 unsigned int x = cluster_xy >> Y_WIDTH; 164 unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); 165 if ( (x >= X_SIZE) || (y >= Y_SIZE) || (channel_id >= NB_DMA_CHANNELS) ) 166 { 167 _puts("\n[DMA ERROR] in _dma_start_transfer() : illegal DMA channel "); 168 _exit(); 169 } 159 170 160 171 // selected channel configuration and lauching … … 169 180 _dma_set_register(cluster_xy, channel_id, DMA_LEN, 170 181 (unsigned int)size); 171 172 182 #endif 173 183 } … … 176 186 void _dma_physical_copy( unsigned int cluster_xy, // DMA cluster 177 187 unsigned int channel_id, // DMA channel 178 unsigned long long dst_paddr, // dest inationphysical address179 unsigned long long src_paddr, // s ourcephysical address188 unsigned long long dst_paddr, // dest physical address 189 unsigned long long src_paddr, // src physical address 180 190 unsigned int size ) // bytes 181 191 { 182 192 #if NB_DMA_CHANNELS > 0 183 184 // check DMA channel parameters185 unsigned int x = cluster_xy >> Y_WIDTH;186 unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1);187 if ( (x >= X_SIZE) || (y >= Y_SIZE) || (channel_id >= NB_DMA_CHANNELS) )188 {189 _puts("\n[DMA ERROR] in _dma_physical_copy() : illegal DMA channel ");190 _exit();191 }192 193 193 194 // check buffers alignment constraints … … 199 200 200 201 #if GIET_DEBUG_DMA_DRIVER 202 unsigned int x = cluster_xy >> Y_WIDTH; 203 unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); 201 204 _puts("\n[DMA DEBUG] enter _dma_physical_copy() for channel["); 202 205 _putd( x ); … … 212 215 _putl( dst_paddr ); 213 216 _puts("\n - bytes = "); 214 _putd( size ); 215 _puts("\n"); 216 #endif 217 218 // dma channel configuration & lauching 217 _putx( size ); 218 _puts("\n"); 219 #endif 220 221 // dma channel configuration 222 _dma_disable_irq( cluster_xy, channel_id ); 223 224 // dma transfer lauching 219 225 _dma_start_transfer( cluster_xy, channel_id, dst_paddr, src_paddr, size ); 220 226 221 227 // scan dma channel status 222 unsigned int status = _dma_get_status( cluster_xy, channel_id ); 228 unsigned int status; 229 do 230 { 231 _dma_get_status( cluster_xy, channel_id , &status ); 232 233 #if GIET_DEBUG_DMA_DRIVER 234 _puts("\n[DMA DEBUG] _dma_physical_copy() : ... waiting on DMA_STATUS\n"); 235 #endif 236 237 } 223 238 while( (status != DMA_SUCCESS) && 224 239 (status != DMA_READ_ERROR) && 225 (status != DMA_WRITE_ERROR) ) 226 { 227 status = _dma_get_status( cluster_xy, channel_id ); 228 229 #if GIET_DEBUG_DMA_DRIVER 230 _puts("\n[DMA DEBUG] _dma_physical_copy() : ... waiting on DMA_STATUS register\n"); 231 #endif 232 233 } 240 (status != DMA_WRITE_ERROR) ); 234 241 235 242 // analyse status 236 243 if( status != DMA_SUCCESS ) 237 244 { 238 _puts("\n[DMA ERROR] in _dma_physical_copy() : bad DMA_STATUS");245 _puts("\n[DMA ERROR] in _dma_physical_copy() : ERROR_STATUS"); 239 246 _exit(); 240 247 } 241 248 242 249 // reset dma channel 243 _dma_reset ( cluster_xy, channel_id );250 _dma_reset_channel( cluster_xy , channel_id ); 244 251 245 252 #if GIET_DEBUG_DMA_DRIVER … … 261 268 void _dma_copy( unsigned int cluster_xy, // DMA cluster 262 269 unsigned int channel_id, // DMA channel 263 unsigned int vspace_id, // vspace index for v2p translation264 270 unsigned int dst_vaddr, // dst_vaddr buffer vbase 265 271 unsigned int src_vaddr, // src_vaddr buffer vbase … … 268 274 #if NB_DMA_CHANNELS > 0 269 275 270 // check DMA channel parameters271 unsigned int x = cluster_xy >> Y_WIDTH;272 unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1);273 if ( (x >= X_SIZE) || (y >= Y_SIZE) || (channel_id >= NB_DMA_CHANNELS) )274 {275 _puts("\n[DMA ERROR] in _dma_copy() : illegal DMA channel ");276 _exit();277 }278 279 276 // check buffers alignment constraints 280 277 if ( (dst_vaddr & 0x3) || (src_vaddr & 0x3) || (size & 0x3) ) … … 284 281 } 285 282 286 unsigned int ppn; 283 unsigned long long src_paddr; 284 unsigned long long dst_paddr; 287 285 unsigned int flags; 288 286 289 287 #if GIET_DEBUG_DMA_DRIVER 288 unsigned int x = cluster_xy >> Y_WIDTH; 289 unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); 290 290 _puts("\n[DMA DEBUG] enter _dma_copy() for channel["); 291 291 _putd( x ); … … 305 305 #endif 306 306 307 // checking alignment constraints308 if ( (((unsigned int)dst_vaddr) & 0x3) ||309 (((unsigned int)src_vaddr) & 0x3) ||310 (size & 0x3) )311 {312 _puts("\n[DMA ERROR] in _dma_copy() : buffer unaligned\n");313 _exit();314 }315 316 // get vspace page table pointer317 unsigned int pt = _ptabs_vaddr[vspace_id];318 319 307 // get src_paddr buffer physical addresse 320 _v2p_translate( (page_table_t*)pt, // page table pointer 321 src_vaddr>>12, // vpn 322 &ppn, // ppn 323 &flags ); // flags 324 unsigned long long src_paddr = (((unsigned long long)ppn) << 12) | 325 (unsigned long long)(src_vaddr & 0x00000FFF); 308 src_paddr = _v2p_translate( src_vaddr , &flags ); 326 309 327 310 // get dst_paddr buffer physical addresse 328 _v2p_translate( (page_table_t*)pt, // page table pointer 329 dst_vaddr>>12, // vpn 330 &ppn, // ppn 331 &flags ); // flags 332 unsigned long long dst_paddr = (((unsigned long long)ppn) << 12) | 333 (unsigned long long)(dst_vaddr & 0x00000FFF); 311 dst_paddr = _v2p_translate( dst_vaddr , &flags ); 334 312 335 313 #if GIET_DEBUG_DMA_DRIVER … … 345 323 346 324 // scan dma channel status 347 unsigned int status = _dma_get_status( cluster_xy, channel_id ); 325 unsigned int status; 326 do 327 { 328 _dma_get_status( cluster_xy, channel_id , &status ); 329 330 #if GIET_DEBUG_DMA_DRIVER 331 _puts("\n[DMA DEBUG] _dma_physical_copy() : ... waiting on DMA_STATUS\n"); 332 #endif 333 334 } 348 335 while( (status != DMA_SUCCESS) && 349 336 (status != DMA_READ_ERROR) && 350 (status != DMA_WRITE_ERROR) ) 351 { 352 status = _dma_get_status( cluster_xy, channel_id ); 353 354 #if GIET_DEBUG_DMA_DRIVER 355 _puts("\n[DMA DEBUG] _dma_copy() : ... waiting on DMA_STATUS register\n"); 356 #endif 357 358 } 337 (status != DMA_WRITE_ERROR) ); 359 338 360 339 // analyse status … … 365 344 } 366 345 // reset dma channel 367 _dma_reset ( cluster_xy, channel_id );346 _dma_reset_channel( cluster_xy, channel_id ); 368 347 369 348 #if GIET_DEBUG_DMA_DRIVER … … 380 359 #endif 381 360 } // end _dma_copy 361 382 362 383 363 /////////////////////////////////////
Note: See TracChangeset
for help on using the changeset viewer.