From 63746b5ff12a9ac64bd88a45b01b36e86f068d51 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Thu, 2 Jan 2014 09:47:32 -0300 Subject: [media] omap3isp: stat: Rename IS_COHERENT_BUF to ISP_STAT_USES_DMAENGINE The macro is meant to test whether the statistics engine uses an external DMA engine to transfer data or supports DMA directly. As both cases will be supported by DMA coherent buffers rename the macro to ISP_STAT_USES_DMAENGINE for improved clarity. Signed-off-by: Laurent Pinchart Acked-by: Sakari Ailus Signed-off-by: Mauro Carvalho Chehab --- drivers/media/platform/omap3isp/ispstat.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'drivers/media/platform/omap3isp/ispstat.c') diff --git a/drivers/media/platform/omap3isp/ispstat.c b/drivers/media/platform/omap3isp/ispstat.c index 5707f85c4cc4..48b702a568e3 100644 --- a/drivers/media/platform/omap3isp/ispstat.c +++ b/drivers/media/platform/omap3isp/ispstat.c @@ -32,7 +32,7 @@ #include "isp.h" -#define IS_COHERENT_BUF(stat) ((stat)->dma_ch >= 0) +#define ISP_STAT_USES_DMAENGINE(stat) ((stat)->dma_ch >= 0) /* * MAGIC_SIZE must always be the greatest common divisor of @@ -99,7 +99,7 @@ static void isp_stat_buf_sync_magic_for_device(struct ispstat *stat, u32 buf_size, enum dma_data_direction dir) { - if (IS_COHERENT_BUF(stat)) + if (ISP_STAT_USES_DMAENGINE(stat)) return; __isp_stat_buf_sync_magic(stat, buf, buf_size, dir, @@ -111,7 +111,7 @@ static void isp_stat_buf_sync_magic_for_cpu(struct ispstat *stat, u32 buf_size, enum dma_data_direction dir) { - if (IS_COHERENT_BUF(stat)) + if (ISP_STAT_USES_DMAENGINE(stat)) return; __isp_stat_buf_sync_magic(stat, buf, buf_size, dir, @@ -180,7 +180,7 @@ static void isp_stat_buf_insert_magic(struct ispstat *stat, static void isp_stat_buf_sync_for_device(struct ispstat *stat, struct ispstat_buffer *buf) { - if (IS_COHERENT_BUF(stat)) + if (ISP_STAT_USES_DMAENGINE(stat)) return; dma_sync_sg_for_device(stat->isp->dev, buf->iovm->sgt->sgl, @@ -190,7 +190,7 @@ static void isp_stat_buf_sync_for_device(struct ispstat *stat, static void isp_stat_buf_sync_for_cpu(struct ispstat *stat, struct ispstat_buffer *buf) { - if (IS_COHERENT_BUF(stat)) + if (ISP_STAT_USES_DMAENGINE(stat)) return; dma_sync_sg_for_cpu(stat->isp->dev, buf->iovm->sgt->sgl, @@ -360,7 +360,7 @@ static void isp_stat_bufs_free(struct ispstat *stat) for (i = 0; i < STAT_MAX_BUFS; i++) { struct ispstat_buffer *buf = &stat->buf[i]; - if (!IS_COHERENT_BUF(stat)) { + if (!ISP_STAT_USES_DMAENGINE(stat)) { if (IS_ERR_OR_NULL((void *)buf->iommu_addr)) continue; if (buf->iovm) @@ -489,7 +489,7 @@ static int isp_stat_bufs_alloc(struct ispstat *stat, u32 size) isp_stat_bufs_free(stat); - if (IS_COHERENT_BUF(stat)) + if (ISP_STAT_USES_DMAENGINE(stat)) return isp_stat_bufs_alloc_dma(stat, size); else return isp_stat_bufs_alloc_iommu(stat, size); -- cgit v1.2.3-70-g09d2 From 512698605dac47f1745dee435f2e3b9bc3346c2d Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Thu, 2 Jan 2014 10:10:28 -0300 Subject: [media] omap3isp: stat: Remove impossible WARN_ON The WARN_ON statements in the buffer allocation functions try to catch conditions where buffers would have already been allocated. As the buffers are explicitly freed right before being allocated this can't happen. Signed-off-by: Laurent Pinchart Acked-by: Sakari Ailus Signed-off-by: Mauro Carvalho Chehab --- drivers/media/platform/omap3isp/ispstat.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'drivers/media/platform/omap3isp/ispstat.c') diff --git a/drivers/media/platform/omap3isp/ispstat.c b/drivers/media/platform/omap3isp/ispstat.c index 48b702a568e3..c6c1290e738d 100644 --- a/drivers/media/platform/omap3isp/ispstat.c +++ b/drivers/media/platform/omap3isp/ispstat.c @@ -400,7 +400,6 @@ static int isp_stat_bufs_alloc_iommu(struct ispstat *stat, unsigned int size) struct ispstat_buffer *buf = &stat->buf[i]; struct iovm_struct *iovm; - WARN_ON(buf->dma_addr); buf->iommu_addr = omap_iommu_vmalloc(isp->domain, isp->dev, 0, size, IOMMU_FLAG); if (IS_ERR((void *)buf->iommu_addr)) { @@ -441,7 +440,6 @@ static int isp_stat_bufs_alloc_dma(struct ispstat *stat, unsigned int size) for (i = 0; i < STAT_MAX_BUFS; i++) { struct ispstat_buffer *buf = &stat->buf[i]; - WARN_ON(buf->iommu_addr); buf->virt_addr = dma_alloc_coherent(stat->isp->dev, size, &buf->dma_addr, GFP_KERNEL | GFP_DMA); -- cgit v1.2.3-70-g09d2 From 4d4c00d4fd7fa49f9105c3543c06a3990eb9094f Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Thu, 2 Jan 2014 10:09:00 -0300 Subject: [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 Acked-by: Sakari Ailus Signed-off-by: Mauro Carvalho Chehab --- drivers/media/platform/omap3isp/ispstat.c | 114 ++++++++++++++---------------- 1 file changed, 54 insertions(+), 60 deletions(-) (limited to 'drivers/media/platform/omap3isp/ispstat.c') 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) stat->active_buf = NULL; } -static int isp_stat_bufs_alloc_iommu(struct ispstat *stat, unsigned int size) +static int isp_stat_bufs_alloc_iommu(struct ispstat *stat, + struct ispstat_buffer *buf, + unsigned int size) { struct isp_device *isp = stat->isp; - int i; + struct iovm_struct *iovm; - stat->buf_alloc_size = size; + buf->iommu_addr = omap_iommu_vmalloc(isp->domain, isp->dev, 0, + size, IOMMU_FLAG); + if (IS_ERR((void *)buf->iommu_addr)) + return -ENOMEM; - for (i = 0; i < STAT_MAX_BUFS; i++) { - struct ispstat_buffer *buf = &stat->buf[i]; - struct iovm_struct *iovm; + iovm = omap_find_iovm_area(isp->dev, buf->iommu_addr); + if (!iovm) + return -ENOMEM; - buf->iommu_addr = omap_iommu_vmalloc(isp->domain, isp->dev, 0, - size, IOMMU_FLAG); - if (IS_ERR((void *)buf->iommu_addr)) { - dev_err(stat->isp->dev, - "%s: Can't acquire memory for " - "buffer %d\n", stat->subdev.name, i); - isp_stat_bufs_free(stat); - return -ENOMEM; - } + if (!dma_map_sg(isp->dev, iovm->sgt->sgl, iovm->sgt->nents, + DMA_FROM_DEVICE)) + return -ENOMEM; - iovm = omap_find_iovm_area(isp->dev, buf->iommu_addr); - if (!iovm || - !dma_map_sg(isp->dev, iovm->sgt->sgl, iovm->sgt->nents, - DMA_FROM_DEVICE)) { - isp_stat_bufs_free(stat); - return -ENOMEM; - } - buf->iovm = iovm; - - buf->virt_addr = omap_da_to_va(stat->isp->dev, - (u32)buf->iommu_addr); - buf->empty = 1; - dev_dbg(stat->isp->dev, "%s: buffer[%d] allocated." - "iommu_addr=0x%08lx virt_addr=0x%08lx", - stat->subdev.name, i, buf->iommu_addr, - (unsigned long)buf->virt_addr); - } + buf->iovm = iovm; + buf->virt_addr = omap_da_to_va(stat->isp->dev, + (u32)buf->iommu_addr); return 0; } -static int isp_stat_bufs_alloc_dma(struct ispstat *stat, unsigned int size) +static int isp_stat_bufs_alloc_dma(struct ispstat *stat, + struct ispstat_buffer *buf, + unsigned int size) { - int i; - - stat->buf_alloc_size = size; - - for (i = 0; i < STAT_MAX_BUFS; i++) { - struct ispstat_buffer *buf = &stat->buf[i]; - - buf->virt_addr = dma_alloc_coherent(stat->isp->dev, size, - &buf->dma_addr, GFP_KERNEL | GFP_DMA); - - if (!buf->virt_addr || !buf->dma_addr) { - dev_info(stat->isp->dev, - "%s: Can't acquire memory for " - "DMA buffer %d\n", stat->subdev.name, i); - isp_stat_bufs_free(stat); - return -ENOMEM; - } - buf->empty = 1; + buf->virt_addr = dma_alloc_coherent(stat->isp->dev, size, + &buf->dma_addr, GFP_KERNEL | GFP_DMA); - dev_dbg(stat->isp->dev, "%s: buffer[%d] allocated." - "dma_addr=0x%08lx virt_addr=0x%08lx\n", - stat->subdev.name, i, (unsigned long)buf->dma_addr, - (unsigned long)buf->virt_addr); - } + if (!buf->virt_addr || !buf->dma_addr) + return -ENOMEM; return 0; } @@ -464,6 +432,7 @@ static int isp_stat_bufs_alloc_dma(struct ispstat *stat, unsigned int size) static int isp_stat_bufs_alloc(struct ispstat *stat, u32 size) { unsigned long flags; + unsigned int i; spin_lock_irqsave(&stat->isp->stat_lock, flags); @@ -487,10 +456,35 @@ static int isp_stat_bufs_alloc(struct ispstat *stat, u32 size) isp_stat_bufs_free(stat); - if (ISP_STAT_USES_DMAENGINE(stat)) - return isp_stat_bufs_alloc_dma(stat, size); - else - return isp_stat_bufs_alloc_iommu(stat, size); + stat->buf_alloc_size = size; + + for (i = 0; i < STAT_MAX_BUFS; i++) { + struct ispstat_buffer *buf = &stat->buf[i]; + int ret; + + if (ISP_STAT_USES_DMAENGINE(stat)) + ret = isp_stat_bufs_alloc_dma(stat, buf, size); + else + ret = isp_stat_bufs_alloc_iommu(stat, buf, size); + + if (ret < 0) { + dev_err(stat->isp->dev, + "%s: Failed to allocate DMA buffer %u\n", + stat->subdev.name, i); + isp_stat_bufs_free(stat); + return ret; + } + + buf->empty = 1; + + dev_dbg(stat->isp->dev, + "%s: buffer[%u] allocated. iommu=0x%08lx dma=0x%08lx virt=0x%08lx", + stat->subdev.name, i, buf->iommu_addr, + (unsigned long)buf->dma_addr, + (unsigned long)buf->virt_addr); + } + + return 0; } static void isp_stat_queue_event(struct ispstat *stat, int err) -- cgit v1.2.3-70-g09d2 From cbde9e9d7f2ad0eb9c61563540ef1427e380c5e1 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Thu, 2 Jan 2014 10:27:12 -0300 Subject: [media] omap3isp: stat: Merge dma_addr and iommu_addr fields The fields store buffer addresses as seen from the device. The first one is used with an external DMA engine while the second one is used with the ISP DMA engine. As they're never used together, merge them. Signed-off-by: Laurent Pinchart Acked-by: Sakari Ailus Signed-off-by: Mauro Carvalho Chehab --- drivers/media/platform/omap3isp/isph3a_aewb.c | 2 +- drivers/media/platform/omap3isp/isph3a_af.c | 2 +- drivers/media/platform/omap3isp/ispstat.c | 21 +++++++++------------ drivers/media/platform/omap3isp/ispstat.h | 1 - 4 files changed, 11 insertions(+), 15 deletions(-) (limited to 'drivers/media/platform/omap3isp/ispstat.c') diff --git a/drivers/media/platform/omap3isp/isph3a_aewb.c b/drivers/media/platform/omap3isp/isph3a_aewb.c index 75fd82b152ba..d6811ce263eb 100644 --- a/drivers/media/platform/omap3isp/isph3a_aewb.c +++ b/drivers/media/platform/omap3isp/isph3a_aewb.c @@ -47,7 +47,7 @@ static void h3a_aewb_setup_regs(struct ispstat *aewb, void *priv) if (aewb->state == ISPSTAT_DISABLED) return; - isp_reg_writel(aewb->isp, aewb->active_buf->iommu_addr, + isp_reg_writel(aewb->isp, aewb->active_buf->dma_addr, OMAP3_ISP_IOMEM_H3A, ISPH3A_AEWBUFST); if (!aewb->update) diff --git a/drivers/media/platform/omap3isp/isph3a_af.c b/drivers/media/platform/omap3isp/isph3a_af.c index a0bf5af32438..6fc960cd30f5 100644 --- a/drivers/media/platform/omap3isp/isph3a_af.c +++ b/drivers/media/platform/omap3isp/isph3a_af.c @@ -51,7 +51,7 @@ static void h3a_af_setup_regs(struct ispstat *af, void *priv) if (af->state == ISPSTAT_DISABLED) return; - isp_reg_writel(af->isp, af->active_buf->iommu_addr, OMAP3_ISP_IOMEM_H3A, + isp_reg_writel(af->isp, af->active_buf->dma_addr, OMAP3_ISP_IOMEM_H3A, ISPH3A_AFBUFST); if (!af->update) diff --git a/drivers/media/platform/omap3isp/ispstat.c b/drivers/media/platform/omap3isp/ispstat.c index b1eb90210388..dba713f2a0d0 100644 --- a/drivers/media/platform/omap3isp/ispstat.c +++ b/drivers/media/platform/omap3isp/ispstat.c @@ -361,21 +361,19 @@ static void isp_stat_bufs_free(struct ispstat *stat) struct ispstat_buffer *buf = &stat->buf[i]; if (!ISP_STAT_USES_DMAENGINE(stat)) { - if (IS_ERR_OR_NULL((void *)buf->iommu_addr)) + if (IS_ERR_OR_NULL((void *)buf->dma_addr)) continue; if (buf->iovm) dma_unmap_sg(isp->dev, buf->iovm->sgt->sgl, buf->iovm->sgt->nents, DMA_FROM_DEVICE); - omap_iommu_vfree(isp->domain, isp->dev, - buf->iommu_addr); + omap_iommu_vfree(isp->domain, isp->dev, buf->dma_addr); } else { if (!buf->virt_addr) continue; dma_free_coherent(stat->isp->dev, stat->buf_alloc_size, buf->virt_addr, buf->dma_addr); } - buf->iommu_addr = 0; buf->iovm = NULL; buf->dma_addr = 0; buf->virt_addr = NULL; @@ -396,12 +394,12 @@ static int isp_stat_bufs_alloc_iommu(struct ispstat *stat, struct isp_device *isp = stat->isp; struct iovm_struct *iovm; - buf->iommu_addr = omap_iommu_vmalloc(isp->domain, isp->dev, 0, - size, IOMMU_FLAG); - if (IS_ERR((void *)buf->iommu_addr)) + buf->dma_addr = omap_iommu_vmalloc(isp->domain, isp->dev, 0, + size, IOMMU_FLAG); + if (IS_ERR_VALUE(buf->dma_addr)) return -ENOMEM; - iovm = omap_find_iovm_area(isp->dev, buf->iommu_addr); + iovm = omap_find_iovm_area(isp->dev, buf->dma_addr); if (!iovm) return -ENOMEM; @@ -410,8 +408,7 @@ static int isp_stat_bufs_alloc_iommu(struct ispstat *stat, return -ENOMEM; buf->iovm = iovm; - buf->virt_addr = omap_da_to_va(stat->isp->dev, - (u32)buf->iommu_addr); + buf->virt_addr = omap_da_to_va(stat->isp->dev, buf->dma_addr); return 0; } @@ -478,8 +475,8 @@ static int isp_stat_bufs_alloc(struct ispstat *stat, u32 size) buf->empty = 1; dev_dbg(stat->isp->dev, - "%s: buffer[%u] allocated. iommu=0x%08lx dma=0x%08lx virt=0x%08lx", - stat->subdev.name, i, buf->iommu_addr, + "%s: buffer[%u] allocated. dma=0x%08lx virt=0x%08lx", + stat->subdev.name, i, (unsigned long)buf->dma_addr, (unsigned long)buf->virt_addr); } diff --git a/drivers/media/platform/omap3isp/ispstat.h b/drivers/media/platform/omap3isp/ispstat.h index 9a047c929b9f..8e76846da8d6 100644 --- a/drivers/media/platform/omap3isp/ispstat.h +++ b/drivers/media/platform/omap3isp/ispstat.h @@ -46,7 +46,6 @@ struct ispstat; struct ispstat_buffer { - unsigned long iommu_addr; struct iovm_struct *iovm; void *virt_addr; dma_addr_t dma_addr; -- cgit v1.2.3-70-g09d2 From 84ac0f09aee6c534a86ba8e2598f5e022772f0eb Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Thu, 2 Jan 2014 10:48:07 -0300 Subject: [media] omap3isp: stat: Store sg table in ispstat_buffer The driver stores the IOMMU mapped iovm struct pointer in the buffer structure but only needs the iovm sg table. Store the sg table instead to prepare the migration to the DMA API. Signed-off-by: Laurent Pinchart Acked-by: Sakari Ailus Signed-off-by: Mauro Carvalho Chehab --- drivers/media/platform/omap3isp/ispstat.c | 19 +++++++++---------- drivers/media/platform/omap3isp/ispstat.h | 2 +- 2 files changed, 10 insertions(+), 11 deletions(-) (limited to 'drivers/media/platform/omap3isp/ispstat.c') diff --git a/drivers/media/platform/omap3isp/ispstat.c b/drivers/media/platform/omap3isp/ispstat.c index dba713f2a0d0..4cf7eb1866cd 100644 --- a/drivers/media/platform/omap3isp/ispstat.c +++ b/drivers/media/platform/omap3isp/ispstat.c @@ -183,8 +183,8 @@ static void isp_stat_buf_sync_for_device(struct ispstat *stat, if (ISP_STAT_USES_DMAENGINE(stat)) return; - dma_sync_sg_for_device(stat->isp->dev, buf->iovm->sgt->sgl, - buf->iovm->sgt->nents, DMA_FROM_DEVICE); + dma_sync_sg_for_device(stat->isp->dev, buf->sgt->sgl, + buf->sgt->nents, DMA_FROM_DEVICE); } static void isp_stat_buf_sync_for_cpu(struct ispstat *stat, @@ -193,8 +193,8 @@ static void isp_stat_buf_sync_for_cpu(struct ispstat *stat, if (ISP_STAT_USES_DMAENGINE(stat)) return; - dma_sync_sg_for_cpu(stat->isp->dev, buf->iovm->sgt->sgl, - buf->iovm->sgt->nents, DMA_FROM_DEVICE); + dma_sync_sg_for_cpu(stat->isp->dev, buf->sgt->sgl, + buf->sgt->nents, DMA_FROM_DEVICE); } static void isp_stat_buf_clear(struct ispstat *stat) @@ -363,10 +363,9 @@ static void isp_stat_bufs_free(struct ispstat *stat) if (!ISP_STAT_USES_DMAENGINE(stat)) { if (IS_ERR_OR_NULL((void *)buf->dma_addr)) continue; - if (buf->iovm) - dma_unmap_sg(isp->dev, buf->iovm->sgt->sgl, - buf->iovm->sgt->nents, - DMA_FROM_DEVICE); + if (buf->sgt) + dma_unmap_sg(isp->dev, buf->sgt->sgl, + buf->sgt->nents, DMA_FROM_DEVICE); omap_iommu_vfree(isp->domain, isp->dev, buf->dma_addr); } else { if (!buf->virt_addr) @@ -374,7 +373,7 @@ static void isp_stat_bufs_free(struct ispstat *stat) dma_free_coherent(stat->isp->dev, stat->buf_alloc_size, buf->virt_addr, buf->dma_addr); } - buf->iovm = NULL; + buf->sgt = NULL; buf->dma_addr = 0; buf->virt_addr = NULL; buf->empty = 1; @@ -407,7 +406,7 @@ static int isp_stat_bufs_alloc_iommu(struct ispstat *stat, DMA_FROM_DEVICE)) return -ENOMEM; - buf->iovm = iovm; + buf->sgt = iovm->sgt; buf->virt_addr = omap_da_to_va(stat->isp->dev, buf->dma_addr); return 0; diff --git a/drivers/media/platform/omap3isp/ispstat.h b/drivers/media/platform/omap3isp/ispstat.h index 8e76846da8d6..857f45edc755 100644 --- a/drivers/media/platform/omap3isp/ispstat.h +++ b/drivers/media/platform/omap3isp/ispstat.h @@ -46,7 +46,7 @@ struct ispstat; struct ispstat_buffer { - struct iovm_struct *iovm; + const struct sg_table *sgt; void *virt_addr; dma_addr_t dma_addr; struct timespec ts; -- cgit v1.2.3-70-g09d2 From 0e24e90f2ca72f7e68e41f3e99fc2838909c36e9 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Thu, 2 Jan 2014 20:06:08 -0300 Subject: [media] omap3isp: stat: Use the DMA API Replace the OMAP-specific IOMMU API usage by the DMA API. All buffers are now allocated using dma_alloc_coherent() and the related sg table is retrieved using dma_get_sgtable() for sync operations. Signed-off-by: Laurent Pinchart Acked-by: Sakari Ailus Signed-off-by: Mauro Carvalho Chehab --- drivers/media/platform/omap3isp/ispstat.c | 123 +++++++++++++----------------- drivers/media/platform/omap3isp/ispstat.h | 2 +- 2 files changed, 53 insertions(+), 72 deletions(-) (limited to 'drivers/media/platform/omap3isp/ispstat.c') diff --git a/drivers/media/platform/omap3isp/ispstat.c b/drivers/media/platform/omap3isp/ispstat.c index 4cf7eb1866cd..e6cbc1eaf4ca 100644 --- a/drivers/media/platform/omap3isp/ispstat.c +++ b/drivers/media/platform/omap3isp/ispstat.c @@ -26,7 +26,6 @@ */ #include -#include #include #include @@ -77,21 +76,10 @@ static void __isp_stat_buf_sync_magic(struct ispstat *stat, dma_addr_t, unsigned long, size_t, enum dma_data_direction)) { - struct device *dev = stat->isp->dev; - struct page *pg; - dma_addr_t dma_addr; - u32 offset; - - /* Initial magic words */ - pg = vmalloc_to_page(buf->virt_addr); - dma_addr = pfn_to_dma(dev, page_to_pfn(pg)); - dma_sync(dev, dma_addr, 0, MAGIC_SIZE, dir); - - /* Final magic words */ - pg = vmalloc_to_page(buf->virt_addr + buf_size); - dma_addr = pfn_to_dma(dev, page_to_pfn(pg)); - offset = ((u32)buf->virt_addr + buf_size) & ~PAGE_MASK; - dma_sync(dev, dma_addr, offset, MAGIC_SIZE, dir); + /* Sync the initial and final magic words. */ + dma_sync(stat->isp->dev, buf->dma_addr, 0, MAGIC_SIZE, dir); + dma_sync(stat->isp->dev, buf->dma_addr + (buf_size & PAGE_MASK), + buf_size & ~PAGE_MASK, MAGIC_SIZE, dir); } static void isp_stat_buf_sync_magic_for_device(struct ispstat *stat, @@ -183,8 +171,8 @@ static void isp_stat_buf_sync_for_device(struct ispstat *stat, if (ISP_STAT_USES_DMAENGINE(stat)) return; - dma_sync_sg_for_device(stat->isp->dev, buf->sgt->sgl, - buf->sgt->nents, DMA_FROM_DEVICE); + dma_sync_sg_for_device(stat->isp->dev, buf->sgt.sgl, + buf->sgt.nents, DMA_FROM_DEVICE); } static void isp_stat_buf_sync_for_cpu(struct ispstat *stat, @@ -193,8 +181,8 @@ static void isp_stat_buf_sync_for_cpu(struct ispstat *stat, if (ISP_STAT_USES_DMAENGINE(stat)) return; - dma_sync_sg_for_cpu(stat->isp->dev, buf->sgt->sgl, - buf->sgt->nents, DMA_FROM_DEVICE); + dma_sync_sg_for_cpu(stat->isp->dev, buf->sgt.sgl, + buf->sgt.nents, DMA_FROM_DEVICE); } static void isp_stat_buf_clear(struct ispstat *stat) @@ -354,26 +342,21 @@ static struct ispstat_buffer *isp_stat_buf_get(struct ispstat *stat, static void isp_stat_bufs_free(struct ispstat *stat) { - struct isp_device *isp = stat->isp; - int i; + struct device *dev = ISP_STAT_USES_DMAENGINE(stat) + ? NULL : stat->isp->dev; + unsigned int i; for (i = 0; i < STAT_MAX_BUFS; i++) { struct ispstat_buffer *buf = &stat->buf[i]; - if (!ISP_STAT_USES_DMAENGINE(stat)) { - if (IS_ERR_OR_NULL((void *)buf->dma_addr)) - continue; - if (buf->sgt) - dma_unmap_sg(isp->dev, buf->sgt->sgl, - buf->sgt->nents, DMA_FROM_DEVICE); - omap_iommu_vfree(isp->domain, isp->dev, buf->dma_addr); - } else { - if (!buf->virt_addr) - continue; - dma_free_coherent(stat->isp->dev, stat->buf_alloc_size, - buf->virt_addr, buf->dma_addr); - } - buf->sgt = NULL; + if (!buf->virt_addr) + continue; + + sg_free_table(&buf->sgt); + + dma_free_coherent(dev, stat->buf_alloc_size, buf->virt_addr, + buf->dma_addr); + buf->dma_addr = 0; buf->virt_addr = NULL; buf->empty = 1; @@ -386,47 +369,49 @@ static void isp_stat_bufs_free(struct ispstat *stat) stat->active_buf = NULL; } -static int isp_stat_bufs_alloc_iommu(struct ispstat *stat, - struct ispstat_buffer *buf, - unsigned int size) -{ - struct isp_device *isp = stat->isp; - struct iovm_struct *iovm; - - buf->dma_addr = omap_iommu_vmalloc(isp->domain, isp->dev, 0, - size, IOMMU_FLAG); - if (IS_ERR_VALUE(buf->dma_addr)) - return -ENOMEM; - - iovm = omap_find_iovm_area(isp->dev, buf->dma_addr); - if (!iovm) - return -ENOMEM; - - if (!dma_map_sg(isp->dev, iovm->sgt->sgl, iovm->sgt->nents, - DMA_FROM_DEVICE)) - return -ENOMEM; - - buf->sgt = iovm->sgt; - buf->virt_addr = omap_da_to_va(stat->isp->dev, buf->dma_addr); - - return 0; -} - -static int isp_stat_bufs_alloc_dma(struct ispstat *stat, +static int isp_stat_bufs_alloc_one(struct device *dev, struct ispstat_buffer *buf, unsigned int size) { - buf->virt_addr = dma_alloc_coherent(stat->isp->dev, size, - &buf->dma_addr, GFP_KERNEL | GFP_DMA); + int ret; - if (!buf->virt_addr || !buf->dma_addr) + buf->virt_addr = dma_alloc_coherent(dev, size, &buf->dma_addr, + GFP_KERNEL | GFP_DMA); + if (!buf->virt_addr) return -ENOMEM; + ret = dma_get_sgtable(dev, &buf->sgt, buf->virt_addr, buf->dma_addr, + size); + if (ret < 0) { + dma_free_coherent(dev, size, buf->virt_addr, buf->dma_addr); + buf->virt_addr = NULL; + buf->dma_addr = 0; + return ret; + } + return 0; } +/* + * The device passed to the DMA API depends on whether the statistics block uses + * ISP DMA, external DMA or PIO to transfer data. + * + * The first case (for the AEWB and AF engines) passes the ISP device, resulting + * in the DMA buffers being mapped through the ISP IOMMU. + * + * The second case (for the histogram engine) should pass the DMA engine device. + * As that device isn't accessible through the OMAP DMA engine API the driver + * passes NULL instead, resulting in the buffers being mapped directly as + * physical pages. + * + * The third case (for the histogram engine) doesn't require any mapping. The + * buffers could be allocated with kmalloc/vmalloc, but we still use + * dma_alloc_coherent() for consistency purpose. + */ static int isp_stat_bufs_alloc(struct ispstat *stat, u32 size) { + struct device *dev = ISP_STAT_USES_DMAENGINE(stat) + ? NULL : stat->isp->dev; unsigned long flags; unsigned int i; @@ -458,11 +443,7 @@ static int isp_stat_bufs_alloc(struct ispstat *stat, u32 size) struct ispstat_buffer *buf = &stat->buf[i]; int ret; - if (ISP_STAT_USES_DMAENGINE(stat)) - ret = isp_stat_bufs_alloc_dma(stat, buf, size); - else - ret = isp_stat_bufs_alloc_iommu(stat, buf, size); - + ret = isp_stat_bufs_alloc_one(dev, buf, size); if (ret < 0) { dev_err(stat->isp->dev, "%s: Failed to allocate DMA buffer %u\n", diff --git a/drivers/media/platform/omap3isp/ispstat.h b/drivers/media/platform/omap3isp/ispstat.h index 857f45edc755..58d6ac7cb664 100644 --- a/drivers/media/platform/omap3isp/ispstat.h +++ b/drivers/media/platform/omap3isp/ispstat.h @@ -46,7 +46,7 @@ struct ispstat; struct ispstat_buffer { - const struct sg_table *sgt; + struct sg_table sgt; void *virt_addr; dma_addr_t dma_addr; struct timespec ts; -- cgit v1.2.3-70-g09d2