[PATCH 2/3] drm/exynos: add dmabuf mmap function
Rob Clark
rob.clark at linaro.org
Sat Jul 21 05:53:47 PDT 2012
On Tue, Jul 10, 2012 at 8:32 AM, Cooper Yuan <cooperyuan at gmail.com> wrote:
> implement mmap function of dma_buf_ops.
>
> Signed-off-by: Cooper Yuan <cooperyuan at gmail.com>
> ---
> 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)
btw, both this function and the omap version are similar to
drm_gem_mmap().. probably there is some room here to extract a common
helper fxn
BR,
-R
> +{
> + 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 at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dri-devel
More information about the dri-devel
mailing list