aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2014-01-02 08:09:00 -0500
committerMauro Carvalho Chehab <m.chehab@samsung.com>2014-05-25 10:07:45 -0400
commit4d4c00d4fd7fa49f9105c3543c06a3990eb9094f (patch)
treec364ddadc885004444dd50c01429b0a034180bcd
parent512698605dac47f1745dee435f2e3b9bc3346c2d (diff)
[media] omap3isp: stat: Share common code for buffer allocation
Move code common between the isp_stat_bufs_alloc_dma() and isp_stat_bufs_alloc_iommu() functions to isp_stat_bufs_alloc(). Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Acked-by: Sakari Ailus <sakari.ailus@iki.fi> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
-rw-r--r--drivers/media/platform/omap3isp/ispstat.c114
1 files changed, 54 insertions, 60 deletions
diff --git a/drivers/media/platform/omap3isp/ispstat.c b/drivers/media/platform/omap3isp/ispstat.c
index c6c1290e738d..b1eb90210388 100644
--- a/drivers/media/platform/omap3isp/ispstat.c
+++ b/drivers/media/platform/omap3isp/ispstat.c
@@ -389,74 +389,42 @@ static void isp_stat_bufs_free(struct ispstat *stat)
389 stat->active_buf = NULL; 389 stat->active_buf = NULL;
390} 390}
391 391
392static int isp_stat_bufs_alloc_iommu(struct ispstat *stat, unsigned int size) 392static int isp_stat_bufs_alloc_iommu(struct ispstat *stat,
393 struct ispstat_buffer *buf,
394 unsigned int size)
393{ 395{
394 struct isp_device *isp = stat->isp; 396 struct isp_device *isp = stat->isp;
395 int i; 397 struct iovm_struct *iovm;
396 398
397 stat->buf_alloc_size = size; 399 buf->iommu_addr = omap_iommu_vmalloc(isp->domain, isp->dev, 0,
400 size, IOMMU_FLAG);
401 if (IS_ERR((void *)buf->iommu_addr))
402 return -ENOMEM;
398 403
399 for (i = 0; i < STAT_MAX_BUFS; i++) { 404 iovm = omap_find_iovm_area(isp->dev, buf->iommu_addr);
400 struct ispstat_buffer *buf = &stat->buf[i]; 405 if (!iovm)
401 struct iovm_struct *iovm; 406 return -ENOMEM;
402 407
403 buf->iommu_addr = omap_iommu_vmalloc(isp->domain, isp->dev, 0, 408 if (!dma_map_sg(isp->dev, iovm->sgt->sgl, iovm->sgt->nents,
404 size, IOMMU_FLAG); 409 DMA_FROM_DEVICE))
405 if (IS_ERR((void *)buf->iommu_addr)) { 410 return -ENOMEM;
406 dev_err(stat->isp->dev,
407 "%s: Can't acquire memory for "
408 "buffer %d\n", stat->subdev.name, i);
409 isp_stat_bufs_free(stat);
410 return -ENOMEM;
411 }
412 411
413 iovm = omap_find_iovm_area(isp->dev, buf->iommu_addr); 412 buf->iovm = iovm;
414 if (!iovm || 413 buf->virt_addr = omap_da_to_va(stat->isp->dev,
415 !dma_map_sg(isp->dev, iovm->sgt->sgl, iovm->sgt->nents, 414 (u32)buf->iommu_addr);
416 DMA_FROM_DEVICE)) {
417 isp_stat_bufs_free(stat);
418 return -ENOMEM;
419 }
420 buf->iovm = iovm;
421
422 buf->virt_addr = omap_da_to_va(stat->isp->dev,
423 (u32)buf->iommu_addr);
424 buf->empty = 1;
425 dev_dbg(stat->isp->dev, "%s: buffer[%d] allocated."
426 "iommu_addr=0x%08lx virt_addr=0x%08lx",
427 stat->subdev.name, i, buf->iommu_addr,
428 (unsigned long)buf->virt_addr);
429 }
430 415
431 return 0; 416 return 0;
432} 417}
433 418
434static int isp_stat_bufs_alloc_dma(struct ispstat *stat, unsigned int size) 419static int isp_stat_bufs_alloc_dma(struct ispstat *stat,
420 struct ispstat_buffer *buf,
421 unsigned int size)
435{ 422{
436 int i; 423 buf->virt_addr = dma_alloc_coherent(stat->isp->dev, size,
437 424 &buf->dma_addr, GFP_KERNEL | GFP_DMA);
438 stat->buf_alloc_size = size;
439
440 for (i = 0; i < STAT_MAX_BUFS; i++) {
441 struct ispstat_buffer *buf = &stat->buf[i];
442
443 buf->virt_addr = dma_alloc_coherent(stat->isp->dev, size,
444 &buf->dma_addr, GFP_KERNEL | GFP_DMA);
445
446 if (!buf->virt_addr || !buf->dma_addr) {
447 dev_info(stat->isp->dev,
448 "%s: Can't acquire memory for "
449 "DMA buffer %d\n", stat->subdev.name, i);
450 isp_stat_bufs_free(stat);
451 return -ENOMEM;
452 }
453 buf->empty = 1;
454 425
455 dev_dbg(stat->isp->dev, "%s: buffer[%d] allocated." 426 if (!buf->virt_addr || !buf->dma_addr)
456 "dma_addr=0x%08lx virt_addr=0x%08lx\n", 427 return -ENOMEM;
457 stat->subdev.name, i, (unsigned long)buf->dma_addr,
458 (unsigned long)buf->virt_addr);
459 }
460 428
461 return 0; 429 return 0;
462} 430}
@@ -464,6 +432,7 @@ static int isp_stat_bufs_alloc_dma(struct ispstat *stat, unsigned int size)
464static int isp_stat_bufs_alloc(struct ispstat *stat, u32 size) 432static int isp_stat_bufs_alloc(struct ispstat *stat, u32 size)
465{ 433{
466 unsigned long flags; 434 unsigned long flags;
435 unsigned int i;
467 436
468 spin_lock_irqsave(&stat->isp->stat_lock, flags); 437 spin_lock_irqsave(&stat->isp->stat_lock, flags);
469 438
@@ -487,10 +456,35 @@ static int isp_stat_bufs_alloc(struct ispstat *stat, u32 size)
487 456
488 isp_stat_bufs_free(stat); 457 isp_stat_bufs_free(stat);
489 458
490 if (ISP_STAT_USES_DMAENGINE(stat)) 459 stat->buf_alloc_size = size;
491 return isp_stat_bufs_alloc_dma(stat, size); 460
492 else 461 for (i = 0; i < STAT_MAX_BUFS; i++) {
493 return isp_stat_bufs_alloc_iommu(stat, size); 462 struct ispstat_buffer *buf = &stat->buf[i];
463 int ret;
464
465 if (ISP_STAT_USES_DMAENGINE(stat))
466 ret = isp_stat_bufs_alloc_dma(stat, buf, size);
467 else
468 ret = isp_stat_bufs_alloc_iommu(stat, buf, size);
469
470 if (ret < 0) {
471 dev_err(stat->isp->dev,
472 "%s: Failed to allocate DMA buffer %u\n",
473 stat->subdev.name, i);
474 isp_stat_bufs_free(stat);
475 return ret;
476 }
477
478 buf->empty = 1;
479
480 dev_dbg(stat->isp->dev,
481 "%s: buffer[%u] allocated. iommu=0x%08lx dma=0x%08lx virt=0x%08lx",
482 stat->subdev.name, i, buf->iommu_addr,
483 (unsigned long)buf->dma_addr,
484 (unsigned long)buf->virt_addr);
485 }
486
487 return 0;
494} 488}
495 489
496static void isp_stat_queue_event(struct ispstat *stat, int err) 490static void isp_stat_queue_event(struct ispstat *stat, int err)