diff --git a/drivers/gpu/ion/ion.c b/drivers/gpu/ion/ion.c index ab5c74558b3..8e26a7bb1bc 100644 --- a/drivers/gpu/ion/ion.c +++ b/drivers/gpu/ion/ion.c @@ -14,6 +14,7 @@ * */ +#include #include #include #include @@ -699,6 +700,28 @@ void ion_client_destroy(struct ion_client *client) kfree(client); } +int ion_handle_get_flags(struct ion_client *client, struct ion_handle *handle, + unsigned long *flags) +{ + struct ion_buffer *buffer; + + mutex_lock(&client->lock); + if (!ion_handle_validate(client, handle)) { + pr_err("%s: invalid handle passed to %s.\n", + __func__, __func__); + mutex_unlock(&client->lock); + return -EINVAL; + } + buffer = handle->buffer; + mutex_lock(&buffer->lock); + *flags = buffer->flags; + mutex_unlock(&buffer->lock); + mutex_unlock(&client->lock); + + return 0; +} +EXPORT_SYMBOL(ion_handle_get_flags); + struct sg_table *ion_sg_table(struct ion_client *client, struct ion_handle *handle) { @@ -1014,6 +1037,22 @@ static long ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) data.offset, data.length, cmd); } + case ION_IOC_GET_FLAGS: + { + struct ion_flag_data data; + int ret; + if (copy_from_user(&data, (void __user *)arg, + sizeof(struct ion_flag_data))) + return -EFAULT; + + ret = ion_handle_get_flags(client, data.handle, &data.flags); + if (ret < 0) + return ret; + if (copy_to_user((void __user *)arg, &data, + sizeof(struct ion_flag_data))) + return -EFAULT; + break; + } default: return -ENOTTY; } diff --git a/include/linux/ion.h b/include/linux/ion.h index 977d7fdabfd..d48c5f35f5c 100644 --- a/include/linux/ion.h +++ b/include/linux/ion.h @@ -249,6 +249,20 @@ int ion_share_dma_buf(struct ion_client *client, struct ion_handle *handle); */ struct ion_handle *ion_import_dma_buf(struct ion_client *client, int fd); + +/** + * ion_handle_get_flags - get the flags for a given handle + * + * @client - client who allocated the handle + * @handle - handle to get the flags + * @flags - pointer to store the flags + * + * Gets the current flags for a handle. These flags indicate various options + * of the buffer (caching, security, etc.) + */ +int ion_handle_get_flags(struct ion_client *client, struct ion_handle *handle, + unsigned long *flags); + #endif /* __KERNEL__ */ /** @@ -330,6 +344,20 @@ struct ion_flush_data { unsigned int offset; unsigned int length; }; + +/* struct ion_flag_data - information about flags for this buffer + * + * @handle: handle to get flags from + * @flags: flags of this handle + * + * Takes handle as an input and outputs the flags from the handle + * in the flag field. + */ +struct ion_flag_data { + struct ion_handle *handle; + unsigned long flags; +}; + #define ION_IOC_MAGIC 'I' /** @@ -408,4 +436,13 @@ struct ion_flush_data { */ #define ION_IOC_CLEAN_INV_CACHES _IOWR(ION_IOC_MAGIC, 9, \ struct ion_flush_data) + +/** + * DOC: ION_IOC_GET_FLAGS - get the flags of the handle + * + * Gets the flags of the current handle which indicate cachability, + * secure state etc. + */ +#define ION_IOC_GET_FLAGS _IOWR(ION_IOC_MAGIC, 10, \ + struct ion_flag_data) #endif /* _LINUX_ION_H */