aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/drm_gem_cma_helper.c
diff options
context:
space:
mode:
authorJoonyoung Shim <jy0922.shim@samsung.com>2013-06-28 01:24:54 -0400
committerDave Airlie <airlied@redhat.com>2013-07-05 01:44:49 -0400
commit78467dc5f70fb9bee4a32c0c3714c99b0b5465c7 (patch)
treefe5b399e17578e2a819083df5d7e0fee11df4027 /drivers/gpu/drm/drm_gem_cma_helper.c
parent7c397cd97b8f46659698396b420bd48c3e6703e6 (diff)
drm/cma: add low-level hook functions to use prime helpers
Instead of using the dma_buf functionality for GEM CMA, we can use prime helpers if we can provide low-level hook functions for GEM CMA. Signed-off-by: Joonyoung Shim <jy0922.shim@samsung.com> Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Dave Airlie <airlied@redhat.com>
Diffstat (limited to 'drivers/gpu/drm/drm_gem_cma_helper.c')
-rw-r--r--drivers/gpu/drm/drm_gem_cma_helper.c79
1 files changed, 79 insertions, 0 deletions
diff --git a/drivers/gpu/drm/drm_gem_cma_helper.c b/drivers/gpu/drm/drm_gem_cma_helper.c
index ce063970d68c..83a45e5cf04e 100644
--- a/drivers/gpu/drm/drm_gem_cma_helper.c
+++ b/drivers/gpu/drm/drm_gem_cma_helper.c
@@ -602,3 +602,82 @@ error_gem_free:
602 return ERR_PTR(ret); 602 return ERR_PTR(ret);
603} 603}
604EXPORT_SYMBOL_GPL(drm_gem_cma_dmabuf_import); 604EXPORT_SYMBOL_GPL(drm_gem_cma_dmabuf_import);
605
606/* low-level interface prime helpers */
607struct sg_table *drm_gem_cma_prime_get_sg_table(struct drm_gem_object *obj)
608{
609 struct drm_gem_cma_object *cma_obj = to_drm_gem_cma_obj(obj);
610 struct sg_table *sgt;
611 int ret;
612
613 sgt = kzalloc(sizeof(*sgt), GFP_KERNEL);
614 if (!sgt)
615 return NULL;
616
617 ret = dma_get_sgtable(obj->dev->dev, sgt, cma_obj->vaddr,
618 cma_obj->paddr, obj->size);
619 if (ret < 0)
620 goto out;
621
622 return sgt;
623
624out:
625 kfree(sgt);
626 return NULL;
627}
628EXPORT_SYMBOL_GPL(drm_gem_cma_prime_get_sg_table);
629
630struct drm_gem_object *
631drm_gem_cma_prime_import_sg_table(struct drm_device *dev, size_t size,
632 struct sg_table *sgt)
633{
634 struct drm_gem_cma_object *cma_obj;
635
636 if (sgt->nents != 1)
637 return ERR_PTR(-EINVAL);
638
639 /* Create a CMA GEM buffer. */
640 cma_obj = __drm_gem_cma_create(dev, size);
641 if (IS_ERR(cma_obj))
642 return ERR_PTR(PTR_ERR(cma_obj));
643
644 cma_obj->paddr = sg_dma_address(sgt->sgl);
645 cma_obj->sgt = sgt;
646
647 DRM_DEBUG_PRIME("dma_addr = 0x%x, size = %zu\n", cma_obj->paddr, size);
648
649 return &cma_obj->base;
650}
651EXPORT_SYMBOL_GPL(drm_gem_cma_prime_import_sg_table);
652
653int drm_gem_cma_prime_mmap(struct drm_gem_object *obj,
654 struct vm_area_struct *vma)
655{
656 struct drm_gem_cma_object *cma_obj;
657 struct drm_device *dev = obj->dev;
658 int ret;
659
660 mutex_lock(&dev->struct_mutex);
661 ret = drm_gem_mmap_obj(obj, obj->size, vma);
662 mutex_unlock(&dev->struct_mutex);
663 if (ret < 0)
664 return ret;
665
666 cma_obj = to_drm_gem_cma_obj(obj);
667 return drm_gem_cma_mmap_obj(cma_obj, vma);
668}
669EXPORT_SYMBOL_GPL(drm_gem_cma_prime_mmap);
670
671void *drm_gem_cma_prime_vmap(struct drm_gem_object *obj)
672{
673 struct drm_gem_cma_object *cma_obj = to_drm_gem_cma_obj(obj);
674
675 return cma_obj->vaddr;
676}
677EXPORT_SYMBOL_GPL(drm_gem_cma_prime_vmap);
678
679void drm_gem_cma_prime_vunmap(struct drm_gem_object *obj, void *vaddr)
680{
681 /* Nothing to do */
682}
683EXPORT_SYMBOL_GPL(drm_gem_cma_prime_vunmap);