diff mbox

[PATCHv2] gpu: ion: Add ion_share_dma_buf_kernel

Message ID 1355394294-4721-1-git-send-email-johan.mossberg@stericsson.com
State New
Headers show

Commit Message

Johan Mossberg Dec. 13, 2012, 10:24 a.m. UTC
ion_share_dma_buf_kernel enables you to share ion buffers via dma buf
for kernel only use cases. Useful for example when a GPU driver using
ion wants to share its output buffers with a 3d party display
controller driver supporting dma buf.

Signed-off-by: Johan Mossberg <johan.mossberg@stericsson.com>
---
 drivers/gpu/ion/ion.c | 22 ++++++++++++++++++----
 include/linux/ion.h   |  8 ++++++++
 2 files changed, 26 insertions(+), 4 deletions(-)

Comments

Johan Mossberg Jan. 7, 2013, 1:38 p.m. UTC | #1
Hi Rebecca,

Is this patch accepted for ion mainline or do you have more comments/questions?

/Johan Mossberg

On 12/13/2012 10:24 AM, Johan Mossberg wrote:
> ion_share_dma_buf_kernel enables you to share ion buffers via dma buf
> for kernel only use cases. Useful for example when a GPU driver using
> ion wants to share its output buffers with a 3d party display
> controller driver supporting dma buf.
> 
> Signed-off-by: Johan Mossberg <johan.mossberg@stericsson.com>
> ---
>  drivers/gpu/ion/ion.c | 22 ++++++++++++++++++----
>  include/linux/ion.h   |  8 ++++++++
>  2 files changed, 26 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/gpu/ion/ion.c b/drivers/gpu/ion/ion.c
> index 3872095..e7b0d0b 100644
> --- a/drivers/gpu/ion/ion.c
> +++ b/drivers/gpu/ion/ion.c
> @@ -955,19 +955,19 @@ struct dma_buf_ops dma_buf_ops = {
>  	.kunmap = ion_dma_buf_kunmap,
>  };
>  
> -int ion_share_dma_buf(struct ion_client *client, struct ion_handle *handle)
> +struct dma_buf *ion_share_dma_buf_kernel(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;
> @@ -975,8 +975,22 @@ 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_kernel);
> +
> +int ion_share_dma_buf(struct ion_client *client, struct ion_handle *handle)
> +{
> +	struct dma_buf *dmabuf;
> +	int fd;
> +
> +	dmabuf = ion_share_dma_buf_kernel(client, handle);
> +	if (IS_ERR(dmabuf))
> +		return PTR_ERR(dmabuf);
> +
>  	fd = dma_buf_fd(dmabuf, O_CLOEXEC);
>  	if (fd < 0)
>  		dma_buf_put(dmabuf);
> diff --git a/include/linux/ion.h b/include/linux/ion.h
> index a7d399c..8720e9b 100644
> --- a/include/linux/ion.h
> +++ b/include/linux/ion.h
> @@ -205,6 +205,14 @@ 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_kernel() - share buffer as dma-buf
> + * @client:	the client
> + * @handle:	the handle
> + */
> +struct dma_buf *ion_share_dma_buf_kernel(struct ion_client *client,
> +							struct ion_handle *buf);
> +
> +/**
>   * ion_share_dma_buf() - given an ion client, create a dma-buf fd
>   * @client:	the client
>   * @handle:	the handle
> -- 
> 1.8.0
> 
> 
> _______________________________________________
> Linaro-mm-sig mailing list
> Linaro-mm-sig@lists.linaro.org
> http://lists.linaro.org/mailman/listinfo/linaro-mm-sig
> 
>
Rebecca Schultz Zavin Jan. 8, 2013, 9:12 p.m. UTC | #2
I'm tempted to call this new api ion_share_dma_buf and rename the old one
to ion_share_dma_buf_fd while the number of users is still small.  I think
it's clearer.  Otherwise this patch looks good.

Thoughts?

Rebecca

On Mon, Jan 7, 2013 at 5:38 AM, Johan Mossberg <
johan.mossberg@stericsson.com> wrote:

> Hi Rebecca,
>
> Is this patch accepted for ion mainline or do you have more
> comments/questions?
>
> /Johan Mossberg
>
> On 12/13/2012 10:24 AM, Johan Mossberg wrote:
> > ion_share_dma_buf_kernel enables you to share ion buffers via dma buf
> > for kernel only use cases. Useful for example when a GPU driver using
> > ion wants to share its output buffers with a 3d party display
> > controller driver supporting dma buf.
> >
> > Signed-off-by: Johan Mossberg <johan.mossberg@stericsson.com>
> > ---
> >  drivers/gpu/ion/ion.c | 22 ++++++++++++++++++----
> >  include/linux/ion.h   |  8 ++++++++
> >  2 files changed, 26 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/gpu/ion/ion.c b/drivers/gpu/ion/ion.c
> > index 3872095..e7b0d0b 100644
> > --- a/drivers/gpu/ion/ion.c
> > +++ b/drivers/gpu/ion/ion.c
> > @@ -955,19 +955,19 @@ struct dma_buf_ops dma_buf_ops = {
> >       .kunmap = ion_dma_buf_kunmap,
> >  };
> >
> > -int ion_share_dma_buf(struct ion_client *client, struct ion_handle
> *handle)
> > +struct dma_buf *ion_share_dma_buf_kernel(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;
> > @@ -975,8 +975,22 @@ 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_kernel);
> > +
> > +int ion_share_dma_buf(struct ion_client *client, struct ion_handle
> *handle)
> > +{
> > +     struct dma_buf *dmabuf;
> > +     int fd;
> > +
> > +     dmabuf = ion_share_dma_buf_kernel(client, handle);
> > +     if (IS_ERR(dmabuf))
> > +             return PTR_ERR(dmabuf);
> > +
> >       fd = dma_buf_fd(dmabuf, O_CLOEXEC);
> >       if (fd < 0)
> >               dma_buf_put(dmabuf);
> > diff --git a/include/linux/ion.h b/include/linux/ion.h
> > index a7d399c..8720e9b 100644
> > --- a/include/linux/ion.h
> > +++ b/include/linux/ion.h
> > @@ -205,6 +205,14 @@ 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_kernel() - share buffer as dma-buf
> > + * @client:  the client
> > + * @handle:  the handle
> > + */
> > +struct dma_buf *ion_share_dma_buf_kernel(struct ion_client *client,
> > +                                                     struct ion_handle
> *buf);
> > +
> > +/**
> >   * ion_share_dma_buf() - given an ion client, create a dma-buf fd
> >   * @client:  the client
> >   * @handle:  the handle
> > --
> > 1.8.0
> >
> >
> > _______________________________________________
> > Linaro-mm-sig mailing list
> > Linaro-mm-sig@lists.linaro.org
> > http://lists.linaro.org/mailman/listinfo/linaro-mm-sig
> >
> >
>
>
diff mbox

Patch

diff --git a/drivers/gpu/ion/ion.c b/drivers/gpu/ion/ion.c
index 3872095..e7b0d0b 100644
--- a/drivers/gpu/ion/ion.c
+++ b/drivers/gpu/ion/ion.c
@@ -955,19 +955,19 @@  struct dma_buf_ops dma_buf_ops = {
 	.kunmap = ion_dma_buf_kunmap,
 };
 
-int ion_share_dma_buf(struct ion_client *client, struct ion_handle *handle)
+struct dma_buf *ion_share_dma_buf_kernel(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;
@@ -975,8 +975,22 @@  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_kernel);
+
+int ion_share_dma_buf(struct ion_client *client, struct ion_handle *handle)
+{
+	struct dma_buf *dmabuf;
+	int fd;
+
+	dmabuf = ion_share_dma_buf_kernel(client, handle);
+	if (IS_ERR(dmabuf))
+		return PTR_ERR(dmabuf);
+
 	fd = dma_buf_fd(dmabuf, O_CLOEXEC);
 	if (fd < 0)
 		dma_buf_put(dmabuf);
diff --git a/include/linux/ion.h b/include/linux/ion.h
index a7d399c..8720e9b 100644
--- a/include/linux/ion.h
+++ b/include/linux/ion.h
@@ -205,6 +205,14 @@  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_kernel() - share buffer as dma-buf
+ * @client:	the client
+ * @handle:	the handle
+ */
+struct dma_buf *ion_share_dma_buf_kernel(struct ion_client *client,
+							struct ion_handle *buf);
+
+/**
  * ion_share_dma_buf() - given an ion client, create a dma-buf fd
  * @client:	the client
  * @handle:	the handle