staging/ion: decrease gem reference count in release of dma-buf
authorJoonyoung Shim <jy0922.shim@samsung.com>
Tue, 12 Jan 2016 02:03:42 +0000 (11:03 +0900)
committerJoonyoung Shim <jy0922.shim@samsung.com>
Wed, 13 Jan 2016 01:29:27 +0000 (10:29 +0900)
Gem reference count is increased hen dma-buf is exported, so release
of dma-buf should decrease gem reference count.

Change-Id: Id298ea79aa14908860e5d87527813994dfdb790d
Signed-off-by: Joonyoung Shim <jy0922.shim@samsung.com>
Signed-off-by: Rohit kumar <rohit.kr@samsung.com>
drivers/gpu/drm/sprd/sprd_drm_buf.c
drivers/gpu/drm/sprd/sprd_drm_gem.c
drivers/gpu/drm/sprd/sprd_drm_gem.h
drivers/staging/android/ion/ion.c
drivers/staging/android/ion/ion.h
drivers/staging/android/ion/ion_priv.h

index b7ad00b..f1b35c8 100644 (file)
@@ -67,8 +67,8 @@ static int lowlevel_buffer_allocate(struct drm_device *dev,
        if (IS_CACHABLE_BUFFER(flags))
                mem_flags = ION_FLAG_CACHED;
 
-       buf->ion_handle = ion_alloc(private->sprd_drm_ion_client, buf->size,
-                       SZ_4K, heap_id_mask, mem_flags);
+       buf->ion_handle = ion_alloc_with_gem(private->sprd_drm_ion_client,
+                       buf->size, SZ_4K, heap_id_mask, mem_flags, buf->obj);
 
        if (IS_ERR((void *)buf->ion_handle)) {
                DRM_ERROR("%s Could not allocate\n", __func__);
index cb555b2..fc8b833 100755 (executable)
@@ -376,6 +376,8 @@ struct sprd_drm_gem_obj *sprd_drm_gem_create(struct drm_device *dev,
        /* set memory type and cache attribute from user side. */
        sprd_gem_obj->flags = args->flags;
 
+       buf->obj = &sprd_gem_obj->base;
+
        ret = sprd_drm_alloc_buf(dev, buf, args->flags);
        if (ret < 0)
                goto err_gem_fini;
index 750bdf0..9e0de42 100644 (file)
@@ -55,6 +55,8 @@ struct sprd_drm_gem_buf {
        bool                    pfnmap;
        unsigned int            bufcount;
        dma_addr_t              idx_addr[SPRD_DRM_GEM_MAX_INDEX_ADDR];
+
+       struct drm_gem_object *obj;
 };
 
 struct drm_sprd_gem_object_wait_list_entry {
index fea70ba..7258486 100644 (file)
@@ -36,6 +36,9 @@
 #include <linux/dma-buf.h>
 #include <linux/idr.h>
 #include <linux/time.h>
+#ifdef CONFIG_DRM_SPRD
+#include <drm/drmP.h>
+#endif
 
 #include "ion.h"
 #include "ion_priv.h"
@@ -558,6 +561,23 @@ struct ion_handle *ion_alloc(struct ion_client *client, size_t len,
 }
 EXPORT_SYMBOL(ion_alloc);
 
+#ifdef CONFIG_DRM_SPRD
+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 ion_handle *handle;
+
+       handle = ion_alloc(client, len, align, heap_id_mask, flags);
+       if (!IS_ERR(handle))
+               handle->buffer->obj = obj;
+
+       return handle;
+}
+EXPORT_SYMBOL(ion_alloc_with_gem);
+#endif
+
 void ion_free(struct ion_client *client, struct ion_handle *handle)
 {
        bool valid_handle;
@@ -1194,6 +1214,11 @@ static void ion_dma_buf_release(struct dma_buf *dmabuf)
 {
        struct ion_buffer *buffer = dmabuf->priv;
        ion_buffer_put(buffer);
+
+#ifdef CONFIG_DRM_SPRD
+       if (buffer->obj)
+               drm_gem_object_unreference_unlocked(buffer->obj);
+#endif
 }
 
 static void *ion_dma_buf_kmap(struct dma_buf *dmabuf, unsigned long offset)
index 9559b4f..0158a66 100644 (file)
@@ -119,6 +119,12 @@ struct ion_handle *ion_alloc(struct ion_client *client, size_t len,
                             size_t align, unsigned int heap_id_mask,
                             unsigned int flags);
 
+#ifdef CONFIG_DRM_SPRD
+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);
+#endif
 /**
  * ion_free - free a handle
  * @client:    the client
@@ -249,5 +255,4 @@ struct ion_handle *ion_import_dma_buf(struct ion_client *client, int fd);
 
 int ion_handle_get_size(struct ion_client *client, struct ion_handle *handle,
                        unsigned long *size, unsigned int *heap_id);
-
 #endif /* _LINUX_ION_H */
index aa0e0b2..4b8745f 100644 (file)
@@ -89,6 +89,9 @@ struct ion_buffer {
        pid_t pid;
        pid_t tid;
        struct timeval alloc_time;
+#ifdef CONFIG_DRM_SPRD
+       struct drm_gem_object *obj;
+#endif
 };
 void ion_buffer_destroy(struct ion_buffer *buffer);