static inline int is_dma_buf_file(struct file *);
+struct dma_buf_callback {
+ struct list_head list;
+ void (*callback)(void *);
+ void *data;
+};
+
struct dma_buf_list {
struct list_head head;
struct mutex lock;
static int dma_buf_release(struct inode *inode, struct file *file)
{
struct dma_buf *dmabuf;
+ struct dma_buf_callback *cb, *tmp;
if (!is_dma_buf_file(file))
return -EINVAL;
*/
BUG_ON(dmabuf->cb_shared.active || dmabuf->cb_excl.active);
+ list_for_each_entry_safe(cb, tmp, &dmabuf->release_callbacks, list) {
+ if (cb->callback)
+ cb->callback(cb->data);
+ list_del(&cb->list);
+ kfree(cb);
+ }
+
dmabuf->ops->release(dmabuf);
mutex_lock(&db_list.lock);
return file->f_op == &dma_buf_fops;
}
+int dma_buf_set_release_callback(struct dma_buf *dmabuf,
+ void (*callback)(void *), void *data)
+{
+ struct dma_buf_callback *cb;
+
+ if (WARN_ON(dma_buf_get_release_callback_data(dmabuf, callback)))
+ return -EINVAL;
+
+ cb = kzalloc(sizeof(*cb), GFP_KERNEL);
+ if (!cb)
+ return -ENOMEM;
+ cb->callback = callback;
+ cb->data = data;
+ list_add_tail(&cb->list, &dmabuf->release_callbacks);
+
+ return 0;
+}
+
+void *dma_buf_get_release_callback_data(struct dma_buf *dmabuf,
+ void (*callback)(void *))
+{
+ struct dma_buf_callback *cb, *tmp;
+
+ list_for_each_entry_safe(cb, tmp, &dmabuf->release_callbacks, list) {
+ if (cb->callback == callback)
+ return cb->data;
+ }
+
+ return NULL;
+}
+
/**
* dma_buf_export - Creates a new dma_buf, and associates an anon file
* with this buffer, so it can be exported.
mutex_init(&dmabuf->lock);
INIT_LIST_HEAD(&dmabuf->attachments);
+ INIT_LIST_HEAD(&dmabuf->release_callbacks);
mutex_lock(&db_list.lock);
list_add(&dmabuf->list_node, &db_list.head);
* if the call would block.
*/
+ int (*set_release_callback)(void (*release_callback)(void *data),
+ void *data);
+ void *(*get_release_callback_data)(void *callback);
/* after final dma_buf_put() */
void (*release)(struct dma_buf *);
size_t size;
struct file *file;
struct list_head attachments;
+ struct list_head release_callbacks;
const struct dma_buf_ops *ops;
/* mutex to serialize list manipulation, attach/detach and vmap/unmap */
struct mutex lock;
get_file(dmabuf->file);
}
+int dma_buf_set_release_callback(struct dma_buf *dmabuf,
+ void (*callback)(void *), void *data);
+
+void *dma_buf_get_release_callback_data(struct dma_buf *dmabuf,
+ void (*callback)(void *));
+
struct dma_buf_attachment *dma_buf_attach(struct dma_buf *dmabuf,
struct device *dev);
void dma_buf_detach(struct dma_buf *dmabuf,