[PATCH 2/3] drm/exynos: add dmabuf mmap function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



implement mmap function of dma_buf_ops.

Signed-off-by: Cooper Yuan <cooperyuan@xxxxxxxxx>
---
 drivers/gpu/drm/exynos/exynos_drm_dmabuf.c |   38 ++++++++++++++++++++++++++++
 1 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/drivers/gpu/drm/exynos/exynos_drm_dmabuf.c
b/drivers/gpu/drm/exynos/exynos_drm_dmabuf.c
index e4eeb0b..913a23e 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_dmabuf.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_dmabuf.c
@@ -164,6 +164,43 @@ static void exynos_gem_dmabuf_kunmap(struct
dma_buf *dma_buf,
 	/* TODO */
 }

+static int exynos_gem_dmabuf_mmap(struct dma_buf *dma_buf, struct
vm_area_struct *vma)
+{
+	struct exynos_drm_gem_obj *exynos_gem_obj = dma_buf->priv;
+	struct drm_device *dev = exynos_gem_obj->base.dev;
+	struct exynos_drm_gem_buf *buf = exynos_gem_obj->buffer;
+	int ret = 0;
+	if (WARN_ON(!exynos_gem_obj->base.filp))
+		return -EINVAL;
+
+	/* Check for valid size. */
+	if (buf->size < vma->vm_end - vma->vm_start) {
+		ret = -EINVAL;
+		goto out_unlock;
+	}
+
+	if (!dev->driver->gem_vm_ops) {
+		ret = -EINVAL;
+		goto out_unlock;
+	}
+
+	vma->vm_flags |= VM_RESERVED | VM_IO | VM_MIXEDMAP | VM_DONTEXPAND;
+	vma->vm_ops = dev->driver->gem_vm_ops;
+	vma->vm_private_data = exynos_gem_obj;
+	vma->vm_page_prot =  pgprot_writecombine(vm_get_page_prot(vma->vm_flags));
+
+	/* Take a ref for this mapping of the object, so that the fault
+	 * handler can dereference the mmap offset's pointer to the object.
+	 * This reference is cleaned up by the corresponding vm_close
+	 * (which should happen whether the vma was created by this call, or
+	 * by a vm_open due to mremap or partial unmap or whatever).
+	 */
+	vma->vm_ops->open(vma);
+
+out_unlock:
+	return ret;
+}
+
 static struct dma_buf_ops exynos_dmabuf_ops = {
 	.map_dma_buf		= exynos_gem_map_dma_buf,
 	.unmap_dma_buf		= exynos_gem_unmap_dma_buf,
@@ -172,6 +209,7 @@ static struct dma_buf_ops exynos_dmabuf_ops = {
 	.kunmap			= exynos_gem_dmabuf_kunmap,
 	.kunmap_atomic		= exynos_gem_dmabuf_kunmap_atomic,
 	.release		= exynos_dmabuf_release,
+	.mmap			= exynos_gem_dmabuf_mmap,
 };

 struct dma_buf *exynos_dmabuf_prime_export(struct drm_device *drm_dev,
-- 
1.7.0.4
_______________________________________________
dri-devel mailing list
dri-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/dri-devel


[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux