All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] drm: exynos: fix for mapping non contig dma buffers
@ 2012-11-03 12:21 Rahul Sharma
  2012-11-03 12:21 ` [PATCH 1/1] drm: exynos: fix for mapping contigous " Rahul Sharma
  0 siblings, 1 reply; 3+ messages in thread
From: Rahul Sharma @ 2012-11-03 12:21 UTC (permalink / raw)
  To: dri-devel
  Cc: sw0312.kim, joshi, kyungmin.park, rahul.sharma, prashanth.g, s.shirish

This patch fixes the problem of mapping gem objects which are non-contigous
dma buffers. These buffers are described using SG table and SG lists. Each
valid SG List is pointing to a single page or group of pages which are
physically contigous.

Current implementation just maps the first page of each SG List and leave
the other pages unmapped, leading to a crash.

Given solution finds the page struct for the faulting page through parsing SG
table and map it.

This patch is based on branch exynos-drm-next-iommu at
git://git.kernel.org/pub/scm/linux/kernel/git/daeinki/drm-exynos.git

v1:
1) instead of mapping whole section, mapping single page.

Signed-off-by: Rahul Sharma <rahul.sharma@samsung.com>
---
 drivers/gpu/drm/exynos/exynos_drm_gem.c |   22 ++++++++++++++++++++--
 1 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/exynos/exynos_drm_gem.c b/drivers/gpu/drm/exynos/exynos_drm_gem.c
index 8cb6824..c557ac7 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_gem.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_gem.c
@@ -95,13 +95,31 @@ static int exynos_drm_gem_map_buf(struct drm_gem_object *obj,
 {
 	struct exynos_drm_gem_obj *exynos_gem_obj = to_exynos_gem_obj(obj);
 	struct exynos_drm_gem_buf *buf = exynos_gem_obj->buffer;
+	struct scatterlist *sgl;
 	unsigned long pfn;
+	int i;
 
 	if (exynos_gem_obj->flags & EXYNOS_BO_NONCONTIG) {
-		if (!buf->pages)
+		if (!buf->sgt)
 			return -EINTR;
 
-		pfn = page_to_pfn(buf->pages[page_offset++]);
+		sgl = buf->sgt->sgl;
+		for_each_sg(buf->sgt->sgl, sgl, buf->sgt->nents, i) {
+			if (!sgl) {
+				DRM_ERROR("invalid SG table\n");
+				return -EINTR;
+			}
+			if (page_offset < (sgl->length >> PAGE_SHIFT))
+				break;
+			page_offset -=	(sgl->length >> PAGE_SHIFT);
+		}
+
+		if (i >= buf->sgt->nents) {
+			DRM_ERROR("invalid page offset\n");
+			return -EINVAL;
+		}
+
+		pfn = __phys_to_pfn(sg_phys(sgl)) + page_offset;
 	} else
 		pfn = (buf->dma_addr >> PAGE_SHIFT) + page_offset;
 
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 1/1] drm: exynos: fix for mapping contigous dma buffers
  2012-11-03 12:21 [PATCH v1] drm: exynos: fix for mapping non contig dma buffers Rahul Sharma
@ 2012-11-03 12:21 ` Rahul Sharma
  2012-11-05 14:20   ` Inki Dae
  0 siblings, 1 reply; 3+ messages in thread
From: Rahul Sharma @ 2012-11-03 12:21 UTC (permalink / raw)
  To: dri-devel
  Cc: sw0312.kim, joshi, kyungmin.park, rahul.sharma, prashanth.g, s.shirish

This patch fixes the problem of mapping contigous dma buffers. Currently page
struct is calculated from the buf->dma_addr which is not the physical address.
It is replaced by buf->pages which points to the page struct of the first page
of contigous memory chunk. This gives the correct page frame number for
mapping.

Signed-off-by: Rahul Sharma <rahul.sharma@samsung.com>
---
 drivers/gpu/drm/exynos/exynos_drm_gem.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/exynos/exynos_drm_gem.c b/drivers/gpu/drm/exynos/exynos_drm_gem.c
index c557ac7..50d73f1 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_gem.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_gem.c
@@ -120,8 +120,12 @@ static int exynos_drm_gem_map_buf(struct drm_gem_object *obj,
 		}
 
 		pfn = __phys_to_pfn(sg_phys(sgl)) + page_offset;
-	} else
-		pfn = (buf->dma_addr >> PAGE_SHIFT) + page_offset;
+	} else {
+		if (!buf->pages)
+			return -EINTR;
+
+		pfn = page_to_pfn(buf->pages[0]) + page_offset;
+	}
 
 	return vm_insert_mixed(vma, f_vaddr, pfn);
 }
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/1] drm: exynos: fix for mapping contigous dma buffers
  2012-11-03 12:21 ` [PATCH 1/1] drm: exynos: fix for mapping contigous " Rahul Sharma
@ 2012-11-05 14:20   ` Inki Dae
  0 siblings, 0 replies; 3+ messages in thread
From: Inki Dae @ 2012-11-05 14:20 UTC (permalink / raw)
  Cc: s.shirish, sw0312.kim, joshi, dri-devel, kyungmin.park,
	prashanth.g, rahul.sharma





2012. 11. 3. 오후 9:21 Rahul Sharma <rahul.sharma@samsung.com> 작성:

> This patch fixes the problem of mapping contigous dma buffers. Currently page
> struct is calculated from the buf->dma_addr which is not the physical address.
> It is replaced by buf->pages which points to the page struct of the first page
> of contigous memory chunk. This gives the correct page frame number for
> mapping.
> 
> Signed-off-by: Rahul Sharma <rahul.sharma@samsung.com>
> ---
> drivers/gpu/drm/exynos/exynos_drm_gem.c |    8 ++++++--
> 1 files changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/exynos/exynos_drm_gem.c b/drivers/gpu/drm/exynos/exynos_drm_gem.c
> index c557ac7..50d73f1 100644
> --- a/drivers/gpu/drm/exynos/exynos_drm_gem.c
> +++ b/drivers/gpu/drm/exynos/exynos_drm_gem.c
> @@ -120,8 +120,12 @@ static int exynos_drm_gem_map_buf(struct drm_gem_object *obj,
>        }
> 
>        pfn = __phys_to_pfn(sg_phys(sgl)) + page_offset;
> -    } else
> -        pfn = (buf->dma_addr >> PAGE_SHIFT) + page_offset;
> +    } else {
> +        if (!buf->pages)
> +            return -EINTR;
> +
> +        pfn = page_to_pfn(buf->pages[0]) + page_offset;
> +    }

Is there any reason you are sending patches respectively? It's better to combine them.

Thanks,
Inki Dae

> 
>    return vm_insert_mixed(vma, f_vaddr, pfn);
> }
> -- 
> 1.7.0.4
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-11-05 14:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-03 12:21 [PATCH v1] drm: exynos: fix for mapping non contig dma buffers Rahul Sharma
2012-11-03 12:21 ` [PATCH 1/1] drm: exynos: fix for mapping contigous " Rahul Sharma
2012-11-05 14:20   ` Inki Dae

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.