drm/sprd: fix always gem creation of imported dma-buf 45/61145/4
authorJoonyoung Shim <jy0922.shim@samsung.com>
Thu, 11 Feb 2016 02:01:03 +0000 (11:01 +0900)
committerInki Dae <inki.dae@samsung.com>
Thu, 17 Mar 2016 23:56:28 +0000 (16:56 -0700)
The sprd_prime_import() creates gem object always even though there is
existing gem object that refers memory of imported dma-buf. This patch
will make to reuse existing gem object on this case.

Change-Id: I4aa31bd2a41a511774b9e1aaf150ddbf45728c22
Signed-off-by: Joonyoung Shim <jy0922.shim@samsung.com>
drivers/gpu/drm/sprd/sprd_drm_gem.c
drivers/staging/android/ion/ion.c
drivers/staging/android/ion/ion.h

index f92a3f1..1fe2363 100755 (executable)
@@ -537,6 +537,21 @@ struct drm_gem_object *sprd_prime_import(struct drm_device *dev,
                goto err;
        }
 
+       obj = ion_get_gem(ion_handle);
+       if (obj) {
+               sprd_gem_obj = to_sprd_gem_obj(obj);
+               if (sprd_gem_obj->buffer->ion_handle != ion_handle) {
+                       DRM_ERROR("Unable get GEM object from ion\n");
+                       ret = -EINVAL;
+                       goto err;
+               }
+
+               drm_gem_object_reference(obj);
+               ion_free(private->sprd_drm_ion_client, ion_handle);
+
+               return obj;
+       }
+
        buf = sprd_drm_init_buf(dev, size);
        if (!buf) {
                DRM_ERROR("Unable to allocate the GEM buffer\n");
index 7258486..4bbc600 100644 (file)
@@ -576,6 +576,15 @@ struct ion_handle *ion_alloc_with_gem(struct ion_client *client, size_t len,
        return handle;
 }
 EXPORT_SYMBOL(ion_alloc_with_gem);
+
+struct drm_gem_object *ion_get_gem(struct ion_handle *handle)
+{
+       if (handle && handle->buffer)
+               return handle->buffer->obj;
+
+       return NULL;
+}
+EXPORT_SYMBOL(ion_get_gem);
 #endif
 
 void ion_free(struct ion_client *client, struct ion_handle *handle)
@@ -1216,8 +1225,10 @@ static void ion_dma_buf_release(struct dma_buf *dmabuf)
        ion_buffer_put(buffer);
 
 #ifdef CONFIG_DRM_SPRD
-       if (buffer->obj)
+       if (buffer->obj) {
                drm_gem_object_unreference_unlocked(buffer->obj);
+               buffer->obj = NULL;
+       }
 #endif
 }
 
index 6be45c2..b489564 100644 (file)
@@ -127,6 +127,7 @@ struct ion_handle *ion_alloc_with_gem(struct ion_client *client, size_t len,
                                        size_t align, unsigned int heap_id_mask,
                                        unsigned int flags,
                                        struct drm_gem_object *obj);
+struct drm_gem_object *ion_get_gem(struct ion_handle *handle);
 #endif
 /**
  * ion_free - free a handle