/alps/pcitool

To get this branch, use:
bzr branch http://suren.me/webbzr/alps/pcitool

« back to all changes in this revision

Viewing changes to dma/nwl_engine.c

  • Committer: Suren A. Chilingaryan
  • Date: 2011-10-26 05:12:31 UTC
  • Revision ID: csa@dside.dyndns.org-20111026051231-5ntkozz31hvjzvb5
Improvements of DMA engine

Show diffs side-by-side

added added

removed removed

Lines of Context:
77
77
    if (info->reused) {
78
78
        info->preserve = 1;
79
79
 
80
 
        dma_nwl_acknowledge_irq(ctx, PCILIB_DMA_IRQ, dma);
 
80
        dma_nwl_acknowledge_irq((pcilib_dma_context_t*)ctx, PCILIB_DMA_IRQ, dma);
81
81
 
82
82
#ifdef NWL_GENERATE_DMA_IRQ
83
83
        dma_nwl_enable_engine_irq(ctx, dma);
126
126
            return PCILIB_ERROR_TIMEOUT;
127
127
        }
128
128
    
129
 
        dma_nwl_acknowledge_irq(ctx, PCILIB_DMA_IRQ, dma);
 
129
        dma_nwl_acknowledge_irq((pcilib_dma_context_t*)ctx, PCILIB_DMA_IRQ, dma);
130
130
 
131
131
        ring_pa = pcilib_kmem_get_pa(ctx->pcilib, info->ring);
132
132
        nwl_write_register(ring_pa, ctx, info->base_addr, REG_DMA_ENG_NEXT_BD);
198
198
        }
199
199
    }
200
200
    
201
 
    dma_nwl_acknowledge_irq(ctx, PCILIB_DMA_IRQ, dma);
 
201
    dma_nwl_acknowledge_irq((pcilib_dma_context_t*)ctx, PCILIB_DMA_IRQ, dma);
202
202
 
203
203
    if (info->preserve) {
204
204
        flags = PCILIB_KMEM_FLAG_REUSE;
228
228
 
229
229
    pcilib_nwl_engine_description_t *info = ctx->engines + dma;
230
230
 
231
 
    err = dma_nwl_start(ctx, dma, PCILIB_DMA_FLAGS_DEFAULT);
 
231
    err = dma_nwl_start(vctx, dma, PCILIB_DMA_FLAGS_DEFAULT);
232
232
    if (err) return err;
233
233
 
234
234
    if (data) {
266
266
}
267
267
 
268
268
int dma_nwl_stream_read(pcilib_dma_context_t *vctx, pcilib_dma_engine_t dma, uintptr_t addr, size_t size, pcilib_dma_flags_t flags, pcilib_timeout_t timeout, pcilib_dma_callback_t cb, void *cbattr) {
269
 
    int err, ret;
 
269
    int err, ret = 1;
270
270
    size_t res = 0;
271
271
    size_t bufnum;
272
272
    size_t bufsize;
277
277
 
278
278
    pcilib_nwl_engine_description_t *info = ctx->engines + dma;
279
279
 
280
 
    err = dma_nwl_start(ctx, dma, PCILIB_DMA_FLAGS_DEFAULT);
 
280
    err = dma_nwl_start(vctx, dma, PCILIB_DMA_FLAGS_DEFAULT);
281
281
    if (err) return err;
282
 
 
 
282
    
283
283
    do {
284
 
        bufnum = dma_nwl_wait_buffer(ctx, info, &bufsize, &eop, timeout);
285
 
        if (bufnum == PCILIB_DMA_BUFFER_INVALID) return PCILIB_ERROR_TIMEOUT;
 
284
        if (ret > 2) {
 
285
            bufnum = dma_nwl_wait_buffer(ctx, info, &bufsize, &eop, 0);
 
286
            if (bufnum == PCILIB_DMA_BUFFER_INVALID) return 0;
 
287
        } else {
 
288
            bufnum = dma_nwl_wait_buffer(ctx, info, &bufsize, &eop, timeout);
 
289
            if (bufnum == PCILIB_DMA_BUFFER_INVALID) {
 
290
                if (ret == 1) return PCILIB_ERROR_TIMEOUT;
 
291
                return 0;
 
292
            }
 
293
        }
286
294
 
287
 
#ifdef NWL_FIX_EOP_FOR_BIG_PACKETS
288
 
        if (size > 65536) {
289
 
//          printf("%i %i\n", res + bufsize, size);
290
 
            if ((res+bufsize) < size) eop = 0;
291
 
            else if ((res+bufsize) == size) eop = 1;
292
 
        }
293
 
#endif /*  NWL_FIX_EOP_FOR_BIG_PACKETS */
 
295
            // EOP is not respected in IPE Camera
 
296
        if (ctx->dmactx.ignore_eop) eop = 1;
294
297
        
295
298
        pcilib_kmem_sync_block(ctx->pcilib, info->pages, PCILIB_KMEM_SYNC_FROMDEVICE, bufnum);
296
299
        void *buf = pcilib_kmem_get_block_ua(ctx->pcilib, info->pages, bufnum);
297
 
        ret = cb(cbattr, eop?PCILIB_DMA_FLAG_EOP:0, bufsize, buf);
 
300
        ret = cb(cbattr, (eop?PCILIB_DMA_FLAG_EOP:0), bufsize, buf);
298
301
//      DS: Fixme, it looks like we can avoid calling this for the sake of performance
299
302
//      pcilib_kmem_sync_block(ctx->pcilib, info->pages, PCILIB_KMEM_SYNC_TODEVICE, bufnum);
 
303
        if (ret < 0) return -ret;
300
304
        dma_nwl_return_buffer(ctx, info);
301
 
 
302
305
        
303
306
        res += bufsize;
304
307
 
306
309
    
307
310
    return 0;
308
311
}
 
312
 
 
313
int dma_nwl_wait_completion(nwl_dma_t * ctx, pcilib_dma_engine_t dma, pcilib_timeout_t timeout) {
 
314
    if (dma_nwl_get_next_buffer(ctx, ctx->engines + dma, PCILIB_NWL_DMA_PAGES - 1, PCILIB_DMA_TIMEOUT) == (PCILIB_NWL_DMA_PAGES - 1)) return 0;
 
315
    else return PCILIB_ERROR_TIMEOUT;
 
316
}
 
317