[PATCH] v4l2: vb2: use dma_get_sgtable
Subash Patel
subash.ramaswamy at linaro.org
Thu Jun 7 07:19:10 PDT 2012
This is patch to remove vb2_dc_kaddr_to_pages() function with dma_get_sgtable()
in the patch set posted by Tomasz. It was observed that the former function
fails to get the pages, as follow_pfn() can fail for remapped kernel va provided
by the dma-mapping sub-system.
As Tomasz mentioned, the later call was temporary patch until dma-mapping author
finalizes the implementation of dma_get_sgtable(). One can use this patch to use
this vb2 patch-set for his/her work in the meantime.
Signed-off-by: Subash Patel <subash.ramaswamy at linaro.org>
---
drivers/media/video/videobuf2-dma-contig.c | 53 ++-------------------------
1 files changed, 4 insertions(+), 49 deletions(-)
diff --git a/drivers/media/video/videobuf2-dma-contig.c b/drivers/media/video/videobuf2-dma-contig.c
index e8da7f1..1b9023a 100644
--- a/drivers/media/video/videobuf2-dma-contig.c
+++ b/drivers/media/video/videobuf2-dma-contig.c
@@ -143,32 +143,11 @@ static void vb2_dc_put(void *buf_priv)
kfree(buf);
}
-static int vb2_dc_kaddr_to_pages(unsigned long kaddr,
- struct page **pages, unsigned int n_pages)
-{
- unsigned int i;
- unsigned long pfn;
- struct vm_area_struct vma = {
- .vm_flags = VM_IO | VM_PFNMAP,
- .vm_mm = current->mm,
- };
-
- for (i = 0; i < n_pages; ++i, kaddr += PAGE_SIZE) {
- if (follow_pfn(&vma, kaddr, &pfn))
- break;
- pages[i] = pfn_to_page(pfn);
- }
-
- return i;
-}
-
static void *vb2_dc_alloc(void *alloc_ctx, unsigned long size)
{
struct device *dev = alloc_ctx;
struct vb2_dc_buf *buf;
int ret = -ENOMEM;
- int n_pages;
- struct page **pages = NULL;
buf = kzalloc(sizeof *buf, GFP_KERNEL);
if (!buf)
@@ -183,35 +162,14 @@ static void *vb2_dc_alloc(void *alloc_ctx, unsigned long size)
WARN_ON((unsigned long)buf->vaddr & ~PAGE_MASK);
WARN_ON(buf->dma_addr & ~PAGE_MASK);
- n_pages = PAGE_ALIGN(size) >> PAGE_SHIFT;
+ ret = dma_get_sgtable(dev, &buf->sgt_base, buf->vaddr,
+ buf->dma_addr, size, NULL);
- pages = kmalloc(n_pages * sizeof pages[0], GFP_KERNEL);
- if (!pages) {
- dev_err(dev, "failed to alloc page table\n");
- goto fail_dma;
- }
-
- ret = vb2_dc_kaddr_to_pages((unsigned long)buf->vaddr, pages, n_pages);
if (ret < 0) {
- dev_err(dev, "failed to get buffer pages from DMA API\n");
- goto fail_pages;
- }
- if (ret != n_pages) {
- ret = -EFAULT;
- dev_err(dev, "failed to get all pages from DMA API\n");
- goto fail_pages;
- }
-
- ret = sg_alloc_table_from_pages(&buf->sgt_base,
- pages, n_pages, 0, size, GFP_KERNEL);
- if (ret) {
- dev_err(dev, "failed to prepare sg table\n");
- goto fail_pages;
+ dev_err(dev, "failed to get the SGT for the allocated pages\n");
+ goto fail_dma;
}
- /* pages are no longer needed */
- kfree(pages);
-
buf->dev = dev;
buf->size = size;
@@ -223,9 +181,6 @@ static void *vb2_dc_alloc(void *alloc_ctx, unsigned long size)
return buf;
-fail_pages:
- kfree(pages);
-
fail_dma:
dma_free_coherent(dev, size, buf->vaddr, buf->dma_addr);
--
1.7.5.4
--------------080106050707070506020705--
More information about the dri-devel
mailing list