]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - drivers/staging/android/ion/ion.c
Merge remote-tracking branch 'staging/staging-next'
[karo-tx-linux.git] / drivers / staging / android / ion / ion.c
index e237e9f3312d6b99e5d2eac4a07f534ce03690c2..c97e82bb4c2a34ae0e409f847a97ad4ffc7ee84a 100644 (file)
@@ -251,8 +251,10 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap,
         * memory coming from the heaps is ready for dma, ie if it has a
         * cached mapping that mapping has been invalidated
         */
-       for_each_sg(buffer->sg_table->sgl, sg, buffer->sg_table->nents, i)
+       for_each_sg(buffer->sg_table->sgl, sg, buffer->sg_table->nents, i) {
                sg_dma_address(sg) = sg_phys(sg);
+               sg_dma_len(sg) = sg->length;
+       }
        mutex_lock(&dev->buffer_lock);
        ion_buffer_add(dev, buffer);
        mutex_unlock(&dev->buffer_lock);
@@ -675,6 +677,34 @@ void ion_unmap_kernel(struct ion_client *client, struct ion_handle *handle)
 }
 EXPORT_SYMBOL(ion_unmap_kernel);
 
+static struct mutex debugfs_mutex;
+static struct rb_root *ion_root_client;
+static int is_client_alive(struct ion_client *client)
+{
+       struct rb_node *node;
+       struct ion_client *tmp;
+       struct ion_device *dev;
+
+       node = ion_root_client->rb_node;
+       dev = container_of(ion_root_client, struct ion_device, clients);
+
+       down_read(&dev->lock);
+       while (node) {
+               tmp = rb_entry(node, struct ion_client, node);
+               if (client < tmp) {
+                       node = node->rb_left;
+               } else if (client > tmp) {
+                       node = node->rb_right;
+               } else {
+                       up_read(&dev->lock);
+                       return 1;
+               }
+       }
+
+       up_read(&dev->lock);
+       return 0;
+}
+
 static int ion_debug_client_show(struct seq_file *s, void *unused)
 {
        struct ion_client *client = s->private;
@@ -683,6 +713,14 @@ static int ion_debug_client_show(struct seq_file *s, void *unused)
        const char *names[ION_NUM_HEAP_IDS] = {NULL};
        int i;
 
+       mutex_lock(&debugfs_mutex);
+       if (!is_client_alive(client)) {
+               seq_printf(s, "ion_client 0x%p dead, can't dump its buffers\n",
+                          client);
+               mutex_unlock(&debugfs_mutex);
+               return 0;
+       }
+
        mutex_lock(&client->lock);
        for (n = rb_first(&client->handles); n; n = rb_next(n)) {
                struct ion_handle *handle = rb_entry(n, struct ion_handle,
@@ -694,6 +732,7 @@ static int ion_debug_client_show(struct seq_file *s, void *unused)
                sizes[id] += handle->buffer->size;
        }
        mutex_unlock(&client->lock);
+       mutex_unlock(&debugfs_mutex);
 
        seq_printf(s, "%16.16s: %16.16s\n", "heap_name", "size_in_bytes");
        for (i = 0; i < ION_NUM_HEAP_IDS; i++) {
@@ -830,6 +869,7 @@ void ion_client_destroy(struct ion_client *client)
        struct rb_node *n;
 
        pr_debug("%s: %d\n", __func__, __LINE__);
+       mutex_lock(&debugfs_mutex);
        while ((n = rb_first(&client->handles))) {
                struct ion_handle *handle = rb_entry(n, struct ion_handle,
                                                     node);
@@ -848,6 +888,7 @@ void ion_client_destroy(struct ion_client *client)
        kfree(client->display_name);
        kfree(client->name);
        kfree(client);
+       mutex_unlock(&debugfs_mutex);
 }
 EXPORT_SYMBOL(ion_client_destroy);
 
@@ -1057,8 +1098,7 @@ static void ion_dma_buf_kunmap(struct dma_buf *dmabuf, unsigned long offset,
 {
 }
 
-static int ion_dma_buf_begin_cpu_access(struct dma_buf *dmabuf, size_t start,
-                                       size_t len,
+static int ion_dma_buf_begin_cpu_access(struct dma_buf *dmabuf,
                                        enum dma_data_direction direction)
 {
        struct ion_buffer *buffer = dmabuf->priv;
@@ -1076,8 +1116,7 @@ static int ion_dma_buf_begin_cpu_access(struct dma_buf *dmabuf, size_t start,
        return PTR_ERR_OR_ZERO(vaddr);
 }
 
-static void ion_dma_buf_end_cpu_access(struct dma_buf *dmabuf, size_t start,
-                                      size_t len,
+static void ion_dma_buf_end_cpu_access(struct dma_buf *dmabuf,
                                       enum dma_data_direction direction)
 {
        struct ion_buffer *buffer = dmabuf->priv;
@@ -1151,22 +1190,18 @@ int ion_share_dma_buf_fd(struct ion_client *client, struct ion_handle *handle)
 }
 EXPORT_SYMBOL(ion_share_dma_buf_fd);
 
-struct ion_handle *ion_import_dma_buf(struct ion_client *client, int fd)
+struct ion_handle *ion_import_dma_buf(struct ion_client *client,
+                                     struct dma_buf *dmabuf)
 {
-       struct dma_buf *dmabuf;
        struct ion_buffer *buffer;
        struct ion_handle *handle;
        int ret;
 
-       dmabuf = dma_buf_get(fd);
-       if (IS_ERR(dmabuf))
-               return ERR_CAST(dmabuf);
        /* if this memory came from ion */
 
        if (dmabuf->ops != &dma_buf_ops) {
                pr_err("%s: can not import dmabuf from another exporter\n",
                       __func__);
-               dma_buf_put(dmabuf);
                return ERR_PTR(-EINVAL);
        }
        buffer = dmabuf->priv;
@@ -1194,11 +1229,25 @@ struct ion_handle *ion_import_dma_buf(struct ion_client *client, int fd)
        }
 
 end:
-       dma_buf_put(dmabuf);
        return handle;
 }
 EXPORT_SYMBOL(ion_import_dma_buf);
 
+struct ion_handle *ion_import_dma_buf_fd(struct ion_client *client, int fd)
+{
+       struct dma_buf *dmabuf;
+       struct ion_handle *handle;
+
+       dmabuf = dma_buf_get(fd);
+       if (IS_ERR(dmabuf))
+               return ERR_CAST(dmabuf);
+
+       handle = ion_import_dma_buf(client, dmabuf);
+       dma_buf_put(dmabuf);
+       return handle;
+}
+EXPORT_SYMBOL(ion_import_dma_buf_fd);
+
 static int ion_sync_for_device(struct ion_client *client, int fd)
 {
        struct dma_buf *dmabuf;
@@ -1306,7 +1355,7 @@ static long ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
        {
                struct ion_handle *handle;
 
-               handle = ion_import_dma_buf(client, data.fd.fd);
+               handle = ion_import_dma_buf_fd(client, data.fd.fd);
                if (IS_ERR(handle))
                        ret = PTR_ERR(handle);
                else
@@ -1403,6 +1452,7 @@ static int ion_debug_heap_show(struct seq_file *s, void *unused)
        seq_printf(s, "%16s %16s %16s\n", "client", "pid", "size");
        seq_puts(s, "----------------------------------------------------\n");
 
+       mutex_lock(&debugfs_mutex);
        for (n = rb_first(&dev->clients); n; n = rb_next(n)) {
                struct ion_client *client = rb_entry(n, struct ion_client,
                                                     node);
@@ -1421,6 +1471,8 @@ static int ion_debug_heap_show(struct seq_file *s, void *unused)
                                   client->pid, size);
                }
        }
+       mutex_unlock(&debugfs_mutex);
+
        seq_puts(s, "----------------------------------------------------\n");
        seq_puts(s, "orphaned allocations (info is from last known client):\n");
        mutex_lock(&dev->buffer_lock);
@@ -1605,6 +1657,8 @@ debugfs_done:
        init_rwsem(&idev->lock);
        plist_head_init(&idev->heaps);
        idev->clients = RB_ROOT;
+       ion_root_client = &idev->clients;
+       mutex_init(&debugfs_mutex);
        return idev;
 }
 EXPORT_SYMBOL(ion_device_create);