From a05932da07ecc0a214bd24322ffbcec79be5d5e0 Mon Sep 17 00:00:00 2001 From: Mark Yao Date: Fri, 26 Jun 2015 09:27:18 +0800 Subject: [PATCH] drm/rockchip: gem: import dma_buf to gem We want to display a buffer allocated by other driver, need import the buffer to gem. Change-Id: Ifd5fef3fbf2b4daea6d624ed2a250c2fe626309d Signed-off-by: Mark Yao Signed-off-by: Yakir Yang --- drivers/gpu/drm/rockchip/rockchip_drm_drv.c | 1 + drivers/gpu/drm/rockchip/rockchip_drm_gem.c | 32 +++++++++++++++++++-- drivers/gpu/drm/rockchip/rockchip_drm_gem.h | 4 ++- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_drv.c b/drivers/gpu/drm/rockchip/rockchip_drm_drv.c index a651162dbf18..d0cb8b62afea 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_drv.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_drv.c @@ -474,6 +474,7 @@ static struct drm_driver rockchip_drm_driver = { .prime_handle_to_fd = drm_gem_prime_handle_to_fd, .prime_fd_to_handle = drm_gem_prime_fd_to_handle, .gem_prime_import = drm_gem_prime_import, + .gem_prime_import_sg_table = rockchip_gem_prime_import_sg_table, .gem_prime_export = drm_gem_prime_export, .gem_prime_get_sg_table = rockchip_gem_prime_get_sg_table, .gem_prime_vmap = rockchip_gem_prime_vmap, diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_gem.c b/drivers/gpu/drm/rockchip/rockchip_drm_gem.c index b215dc890adb..92dc967d71f3 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_gem.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_gem.c @@ -109,6 +109,29 @@ int rockchip_gem_mmap(struct file *filp, struct vm_area_struct *vma) return rockchip_drm_gem_object_mmap(obj, vma); } +struct drm_gem_object * +rockchip_gem_prime_import_sg_table(struct drm_device *drm, + struct dma_buf_attachment *attach, + struct sg_table *sgt) +{ + struct rockchip_gem_object *rk_obj; + struct drm_gem_object *obj; + + rk_obj = kzalloc(sizeof(*rk_obj), GFP_KERNEL); + if (!rk_obj) + return ERR_PTR(-ENOMEM); + + obj = &rk_obj->base; + + drm_gem_private_object_init(drm, obj, attach->dmabuf->size); + + rk_obj->dma_addr = sg_dma_address(sgt->sgl); + rk_obj->sgt = sgt; + sg_dma_len(sgt->sgl) = obj->size; + + return obj; +} + struct rockchip_gem_object * rockchip_gem_create_object(struct drm_device *drm, unsigned int size, bool alloc_kmap) @@ -146,11 +169,14 @@ void rockchip_gem_free_object(struct drm_gem_object *obj) { struct rockchip_gem_object *rk_obj; - drm_gem_free_mmap_offset(obj); - rk_obj = to_rockchip_obj(obj); - rockchip_gem_free_buf(rk_obj); + if (obj->import_attach) { + drm_prime_gem_destroy(obj, rk_obj->sgt); + } else { + drm_gem_free_mmap_offset(obj); + rockchip_gem_free_buf(rk_obj); + } #ifdef CONFIG_DRM_DMA_SYNC drm_fence_signal_and_put(&rk_obj->acquire_fence); diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_gem.h b/drivers/gpu/drm/rockchip/rockchip_drm_gem.h index 0cbe8606e4d1..c10582ec0b59 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_gem.h +++ b/drivers/gpu/drm/rockchip/rockchip_drm_gem.h @@ -21,6 +21,7 @@ struct rockchip_gem_object { struct drm_gem_object base; unsigned int flags; + struct sg_table *sgt; void *kvaddr; dma_addr_t dma_addr; struct dma_attrs dma_attrs; @@ -45,7 +46,8 @@ struct rockchip_gem_object_node { struct sg_table *rockchip_gem_prime_get_sg_table(struct drm_gem_object *obj); struct drm_gem_object * -rockchip_gem_prime_import_sg_table(struct drm_device *dev, size_t size, +rockchip_gem_prime_import_sg_table(struct drm_device *dev, + struct dma_buf_attachment *attach, struct sg_table *sgt); void *rockchip_gem_prime_vmap(struct drm_gem_object *obj); void rockchip_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr); -- 2.34.1