gpu: ion: Add support for sharing buffers with dma buf kernel handles

Currently ion can only share buffers with dma buf fd's. Fd's can not be
used inside the kernel as they are process specific so support for
sharing buffers with dma buf kernel handles is needed to support kernel
only use cases. An example use case could be a GPU driver using ion
that wants to share its output buffers with a 3d party display
controller driver supporting dma buf.

Change-Id: I74388160ad65ee5380b87dbb20521a97ddf6727a
Signed-off-by: Johan Mossberg <johan.mossberg@stericsson.com>
Git-commit: 1a6c74e0d58f6ca028f36c3d794fecff8543bbfb
Git-repo: https://android.googlesource.com/kernel/common
[lauraa@codeaurora.org: update callers of function]
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
This commit is contained in:
Johan Mossberg 2013-01-11 13:38:13 +01:00 committed by Artem Borisov
parent d5f76e2f05
commit def8244404
3 changed files with 32 additions and 9 deletions

View File

@ -1320,19 +1320,19 @@ static int ion_share_set_flags(struct ion_client *client,
}
int ion_share_dma_buf(struct ion_client *client, struct ion_handle *handle)
struct dma_buf *ion_share_dma_buf(struct ion_client *client,
struct ion_handle *handle)
{
struct ion_buffer *buffer;
struct dma_buf *dmabuf;
bool valid_handle;
int fd;
mutex_lock(&client->lock);
valid_handle = ion_handle_validate(client, handle);
mutex_unlock(&client->lock);
if (!valid_handle) {
WARN(1, "%s: invalid handle passed to share.\n", __func__);
return -EINVAL;
return ERR_PTR(-EINVAL);
}
buffer = handle->buffer;
@ -1340,15 +1340,29 @@ int ion_share_dma_buf(struct ion_client *client, struct ion_handle *handle)
dmabuf = dma_buf_export(buffer, &dma_buf_ops, buffer->size, O_RDWR);
if (IS_ERR(dmabuf)) {
ion_buffer_put(buffer);
return PTR_ERR(dmabuf);
return dmabuf;
}
return dmabuf;
}
EXPORT_SYMBOL(ion_share_dma_buf);
int ion_share_dma_buf_fd(struct ion_client *client, struct ion_handle *handle)
{
struct dma_buf *dmabuf;
int fd;
dmabuf = ion_share_dma_buf(client, handle);
if (IS_ERR(dmabuf))
return PTR_ERR(dmabuf);
fd = dma_buf_fd(dmabuf, O_CLOEXEC);
if (fd < 0)
dma_buf_put(dmabuf);
return fd;
}
EXPORT_SYMBOL(ion_share_dma_buf);
EXPORT_SYMBOL(ion_share_dma_buf_fd);
struct ion_handle *ion_import_dma_buf(struct ion_client *client, int fd)
{
@ -1439,7 +1453,8 @@ static long ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
if (ret)
return ret;
data.fd = ion_share_dma_buf(client, data.handle);
data.fd = ion_share_dma_buf_fd(client, data.handle);
if (copy_to_user((void __user *)arg, &data, sizeof(data)))
return -EFAULT;
if (data.fd < 0)

View File

@ -1323,7 +1323,7 @@ static int mpq_dmx_init_internal_buffers(
feed_data->buffer_desc.desc[0].read_ptr = 0;
feed_data->buffer_desc.desc[0].write_ptr = 0;
feed_data->buffer_desc.desc[0].handle =
ion_share_dma_buf(client, temp_handle);
ion_share_dma_buf_fd(client, temp_handle);
if (IS_ERR_VALUE(feed_data->buffer_desc.desc[0].handle)) {
MPQ_DVB_ERR_PRINT(
"%s: FAILED to share payload buffer %d\n",

View File

@ -243,11 +243,19 @@ void *ion_map_kernel(struct ion_client *client, struct ion_handle *handle);
void ion_unmap_kernel(struct ion_client *client, struct ion_handle *handle);
/**
* ion_share_dma_buf() - given an ion client, create a dma-buf fd
* ion_share_dma_buf() - share buffer as dma-buf
* @client: the client
* @handle: the handle
*/
int ion_share_dma_buf(struct ion_client *client, struct ion_handle *handle);
struct dma_buf *ion_share_dma_buf(struct ion_client *client,
struct ion_handle *handle);
/**
* ion_share_dma_buf_fd() - given an ion client, create a dma-buf fd
* @client: the client
* @handle: the handle
*/
int ion_share_dma_buf_fd(struct ion_client *client, struct ion_handle *handle);
/**
* ion_import_dma_buf() - given an dma-buf fd from the ion exporter get handle